Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: webrtc/modules/audio_coding/acm2/acm_send_test_oldapi.cc

Issue 2005873002: Let PacketSource::NextPacket() return an std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 bool AcmSendTestOldApi::RegisterExternalCodec( 67 bool AcmSendTestOldApi::RegisterExternalCodec(
68 AudioEncoder* external_speech_encoder) { 68 AudioEncoder* external_speech_encoder) {
69 acm_->RegisterExternalSendCodec(external_speech_encoder); 69 acm_->RegisterExternalSendCodec(external_speech_encoder);
70 input_frame_.num_channels_ = external_speech_encoder->NumChannels(); 70 input_frame_.num_channels_ = external_speech_encoder->NumChannels();
71 assert(input_block_size_samples_ * input_frame_.num_channels_ <= 71 assert(input_block_size_samples_ * input_frame_.num_channels_ <=
72 AudioFrame::kMaxDataSizeSamples); 72 AudioFrame::kMaxDataSizeSamples);
73 return codec_registered_ = true; 73 return codec_registered_ = true;
74 } 74 }
75 75
76 Packet* AcmSendTestOldApi::NextPacket() { 76 std::unique_ptr<Packet> AcmSendTestOldApi::NextPacket() {
77 assert(codec_registered_); 77 assert(codec_registered_);
78 if (filter_.test(static_cast<size_t>(payload_type_))) { 78 if (filter_.test(static_cast<size_t>(payload_type_))) {
79 // This payload type should be filtered out. Since the payload type is the 79 // This payload type should be filtered out. Since the payload type is the
80 // same throughout the whole test run, no packet at all will be delivered. 80 // same throughout the whole test run, no packet at all will be delivered.
81 // We can just as well signal that the test is over by returning NULL. 81 // We can just as well signal that the test is over by returning NULL.
82 return NULL; 82 return nullptr;
83 } 83 }
84 // Insert audio and process until one packet is produced. 84 // Insert audio and process until one packet is produced.
85 while (clock_.TimeInMilliseconds() < test_duration_ms_) { 85 while (clock_.TimeInMilliseconds() < test_duration_ms_) {
86 clock_.AdvanceTimeMilliseconds(kBlockSizeMs); 86 clock_.AdvanceTimeMilliseconds(kBlockSizeMs);
87 RTC_CHECK( 87 RTC_CHECK(
88 audio_source_->Read(input_block_size_samples_, input_frame_.data_)); 88 audio_source_->Read(input_block_size_samples_, input_frame_.data_));
89 if (input_frame_.num_channels_ > 1) { 89 if (input_frame_.num_channels_ > 1) {
90 InputAudioFile::DuplicateInterleaved(input_frame_.data_, 90 InputAudioFile::DuplicateInterleaved(input_frame_.data_,
91 input_block_size_samples_, 91 input_block_size_samples_,
92 input_frame_.num_channels_, 92 input_frame_.num_channels_,
93 input_frame_.data_); 93 input_frame_.data_);
94 } 94 }
95 data_to_send_ = false; 95 data_to_send_ = false;
96 RTC_CHECK_GE(acm_->Add10MsData(input_frame_), 0); 96 RTC_CHECK_GE(acm_->Add10MsData(input_frame_), 0);
97 input_frame_.timestamp_ += static_cast<uint32_t>(input_block_size_samples_); 97 input_frame_.timestamp_ += static_cast<uint32_t>(input_block_size_samples_);
98 if (data_to_send_) { 98 if (data_to_send_) {
99 // Encoded packet received. 99 // Encoded packet received.
100 return CreatePacket(); 100 return CreatePacket();
101 } 101 }
102 } 102 }
103 // Test ended. 103 // Test ended.
104 return NULL; 104 return nullptr;
105 } 105 }
106 106
107 // This method receives the callback from ACM when a new packet is produced. 107 // This method receives the callback from ACM when a new packet is produced.
108 int32_t AcmSendTestOldApi::SendData( 108 int32_t AcmSendTestOldApi::SendData(
109 FrameType frame_type, 109 FrameType frame_type,
110 uint8_t payload_type, 110 uint8_t payload_type,
111 uint32_t timestamp, 111 uint32_t timestamp,
112 const uint8_t* payload_data, 112 const uint8_t* payload_data,
113 size_t payload_len_bytes, 113 size_t payload_len_bytes,
114 const RTPFragmentationHeader* fragmentation) { 114 const RTPFragmentationHeader* fragmentation) {
115 // Store the packet locally. 115 // Store the packet locally.
116 frame_type_ = frame_type; 116 frame_type_ = frame_type;
117 payload_type_ = payload_type; 117 payload_type_ = payload_type;
118 timestamp_ = timestamp; 118 timestamp_ = timestamp;
119 last_payload_vec_.assign(payload_data, payload_data + payload_len_bytes); 119 last_payload_vec_.assign(payload_data, payload_data + payload_len_bytes);
120 assert(last_payload_vec_.size() == payload_len_bytes); 120 assert(last_payload_vec_.size() == payload_len_bytes);
121 data_to_send_ = true; 121 data_to_send_ = true;
122 return 0; 122 return 0;
123 } 123 }
124 124
125 Packet* AcmSendTestOldApi::CreatePacket() { 125 std::unique_ptr<Packet> AcmSendTestOldApi::CreatePacket() {
126 const size_t kRtpHeaderSize = 12; 126 const size_t kRtpHeaderSize = 12;
127 size_t allocated_bytes = last_payload_vec_.size() + kRtpHeaderSize; 127 size_t allocated_bytes = last_payload_vec_.size() + kRtpHeaderSize;
128 uint8_t* packet_memory = new uint8_t[allocated_bytes]; 128 uint8_t* packet_memory = new uint8_t[allocated_bytes];
129 // Populate the header bytes. 129 // Populate the header bytes.
130 packet_memory[0] = 0x80; 130 packet_memory[0] = 0x80;
131 packet_memory[1] = static_cast<uint8_t>(payload_type_); 131 packet_memory[1] = static_cast<uint8_t>(payload_type_);
132 packet_memory[2] = (sequence_number_ >> 8) & 0xFF; 132 packet_memory[2] = (sequence_number_ >> 8) & 0xFF;
133 packet_memory[3] = (sequence_number_) & 0xFF; 133 packet_memory[3] = (sequence_number_) & 0xFF;
134 packet_memory[4] = (timestamp_ >> 24) & 0xFF; 134 packet_memory[4] = (timestamp_ >> 24) & 0xFF;
135 packet_memory[5] = (timestamp_ >> 16) & 0xFF; 135 packet_memory[5] = (timestamp_ >> 16) & 0xFF;
136 packet_memory[6] = (timestamp_ >> 8) & 0xFF; 136 packet_memory[6] = (timestamp_ >> 8) & 0xFF;
137 packet_memory[7] = timestamp_ & 0xFF; 137 packet_memory[7] = timestamp_ & 0xFF;
138 // Set SSRC to 0x12345678. 138 // Set SSRC to 0x12345678.
139 packet_memory[8] = 0x12; 139 packet_memory[8] = 0x12;
140 packet_memory[9] = 0x34; 140 packet_memory[9] = 0x34;
141 packet_memory[10] = 0x56; 141 packet_memory[10] = 0x56;
142 packet_memory[11] = 0x78; 142 packet_memory[11] = 0x78;
143 143
144 ++sequence_number_; 144 ++sequence_number_;
145 145
146 // Copy the payload data. 146 // Copy the payload data.
147 memcpy(packet_memory + kRtpHeaderSize, 147 memcpy(packet_memory + kRtpHeaderSize,
148 &last_payload_vec_[0], 148 &last_payload_vec_[0],
149 last_payload_vec_.size()); 149 last_payload_vec_.size());
150 Packet* packet = 150 std::unique_ptr<Packet> packet(
151 new Packet(packet_memory, allocated_bytes, clock_.TimeInMilliseconds()); 151 new Packet(packet_memory, allocated_bytes, clock_.TimeInMilliseconds()));
152 assert(packet); 152 RTC_DCHECK(packet);
153 assert(packet->valid_header()); 153 RTC_DCHECK(packet->valid_header());
154 return packet; 154 return packet;
155 } 155 }
156 156
157 } // namespace test 157 } // namespace test
158 } // namespace webrtc 158 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698