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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc

Issue 1412683006: RentACodec: New class that takes over part of ACMCodecDB's job (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 19 matching lines...) Expand all
30 30
31 bool CodecsEqual(const CodecInst& codec_a, const CodecInst& codec_b) { 31 bool CodecsEqual(const CodecInst& codec_a, const CodecInst& codec_b) {
32 if (strcmp(codec_a.plname, codec_b.plname) != 0 || 32 if (strcmp(codec_a.plname, codec_b.plname) != 0 ||
33 codec_a.plfreq != codec_b.plfreq || 33 codec_a.plfreq != codec_b.plfreq ||
34 codec_a.pltype != codec_b.pltype || 34 codec_a.pltype != codec_b.pltype ||
35 codec_b.channels != codec_a.channels) 35 codec_b.channels != codec_a.channels)
36 return false; 36 return false;
37 return true; 37 return true;
38 } 38 }
39 39
40 struct CodecIdInst {
41 explicit CodecIdInst(RentACodec::CodecId codec_id) {
42 const auto codec_ix = RentACodec::CodecIndexFromId(codec_id);
43 EXPECT_TRUE(codec_ix);
44 id = *codec_ix;
45 const auto codec_inst = RentACodec::CodecInstById(codec_id);
46 EXPECT_TRUE(codec_inst);
47 inst = *codec_inst;
48 }
49 int id;
50 CodecInst inst;
51 };
52
40 } // namespace 53 } // namespace
41 54
42 class AcmReceiverTestOldApi : public AudioPacketizationCallback, 55 class AcmReceiverTestOldApi : public AudioPacketizationCallback,
43 public ::testing::Test { 56 public ::testing::Test {
44 protected: 57 protected:
45 AcmReceiverTestOldApi() 58 AcmReceiverTestOldApi()
46 : timestamp_(0), 59 : timestamp_(0),
47 packet_sent_(false), 60 packet_sent_(false),
48 last_packet_send_timestamp_(timestamp_), 61 last_packet_send_timestamp_(timestamp_),
49 last_frame_type_(kEmptyFrame) { 62 last_frame_type_(kEmptyFrame) {
50 AudioCodingModule::Config config; 63 AudioCodingModule::Config config;
51 acm_.reset(new AudioCodingModuleImpl(config)); 64 acm_.reset(new AudioCodingModuleImpl(config));
52 receiver_.reset(new AcmReceiver(config)); 65 receiver_.reset(new AcmReceiver(config));
53 } 66 }
54 67
55 ~AcmReceiverTestOldApi() {} 68 ~AcmReceiverTestOldApi() {}
56 69
57 void SetUp() override { 70 void SetUp() override {
58 ASSERT_TRUE(receiver_.get() != NULL); 71 ASSERT_TRUE(receiver_.get() != NULL);
59 ASSERT_TRUE(acm_.get() != NULL); 72 ASSERT_TRUE(acm_.get() != NULL);
60 for (int n = 0; n < ACMCodecDB::kNumCodecs; n++) { 73 codecs_ = RentACodec::Database();
61 ASSERT_EQ(0, ACMCodecDB::Codec(n, &codecs_[n]));
62 }
63 74
64 acm_->InitializeReceiver(); 75 acm_->InitializeReceiver();
65 acm_->RegisterTransportCallback(this); 76 acm_->RegisterTransportCallback(this);
66 77
67 rtp_header_.header.sequenceNumber = 0; 78 rtp_header_.header.sequenceNumber = 0;
68 rtp_header_.header.timestamp = 0; 79 rtp_header_.header.timestamp = 0;
69 rtp_header_.header.markerBit = false; 80 rtp_header_.header.markerBit = false;
70 rtp_header_.header.ssrc = 0x12345678; // Arbitrary. 81 rtp_header_.header.ssrc = 0x12345678; // Arbitrary.
71 rtp_header_.header.numCSRCs = 0; 82 rtp_header_.header.numCSRCs = 0;
72 rtp_header_.header.payloadType = 0; 83 rtp_header_.header.payloadType = 0;
(...skipping 23 matching lines...) Expand all
96 sizeof(int16_t)); 107 sizeof(int16_t));
97 packet_sent_ = false; 108 packet_sent_ = false;
98 last_packet_send_timestamp_ = timestamp_; 109 last_packet_send_timestamp_ = timestamp_;
99 while (!packet_sent_) { 110 while (!packet_sent_) {
100 frame.timestamp_ = timestamp_; 111 frame.timestamp_ = timestamp_;
101 timestamp_ += frame.samples_per_channel_; 112 timestamp_ += frame.samples_per_channel_;
102 ASSERT_GE(acm_->Add10MsData(frame), 0); 113 ASSERT_GE(acm_->Add10MsData(frame), 0);
103 } 114 }
104 } 115 }
105 116
106 // Last element of id should be negative. 117 template <size_t N>
107 void AddSetOfCodecs(const int* id) { 118 void AddSetOfCodecs(const RentACodec::CodecId(&ids)[N]) {
hlundin-webrtc 2015/10/27 13:52:02 Space between RentACodec::CodecId and (&ids)?
kwiberg-webrtc 2015/10/27 14:43:23 clang-format removes it again when I run it, so un
hlundin-webrtc 2015/10/27 15:31:27 Acknowledged.
108 int n = 0; 119 for (auto id : ids) {
109 while (id[n] >= 0) { 120 const auto i = RentACodec::CodecIndexFromId(id);
110 ASSERT_EQ(0, receiver_->AddCodec(id[n], codecs_[id[n]].pltype, 121 ASSERT_TRUE(i);
111 codecs_[id[n]].channels, 122 ASSERT_EQ(
112 codecs_[id[n]].plfreq, NULL)); 123 0, receiver_->AddCodec(*i, codecs_[*i].pltype, codecs_[*i].channels,
113 ++n; 124 codecs_[*i].plfreq, nullptr));
114 } 125 }
115 } 126 }
116 127
117 int SendData(FrameType frame_type, 128 int SendData(FrameType frame_type,
118 uint8_t payload_type, 129 uint8_t payload_type,
119 uint32_t timestamp, 130 uint32_t timestamp,
120 const uint8_t* payload_data, 131 const uint8_t* payload_data,
121 size_t payload_len_bytes, 132 size_t payload_len_bytes,
122 const RTPFragmentationHeader* fragmentation) override { 133 const RTPFragmentationHeader* fragmentation) override {
123 if (frame_type == kEmptyFrame) 134 if (frame_type == kEmptyFrame)
(...skipping 13 matching lines...) Expand all
137 assert(false); 148 assert(false);
138 return -1; 149 return -1;
139 } 150 }
140 rtp_header_.header.sequenceNumber++; 151 rtp_header_.header.sequenceNumber++;
141 packet_sent_ = true; 152 packet_sent_ = true;
142 last_frame_type_ = frame_type; 153 last_frame_type_ = frame_type;
143 return 0; 154 return 0;
144 } 155 }
145 156
146 rtc::scoped_ptr<AcmReceiver> receiver_; 157 rtc::scoped_ptr<AcmReceiver> receiver_;
147 CodecInst codecs_[ACMCodecDB::kMaxNumCodecs]; 158 rtc::ArrayView<const CodecInst> codecs_;
148 rtc::scoped_ptr<AudioCodingModule> acm_; 159 rtc::scoped_ptr<AudioCodingModule> acm_;
149 WebRtcRTPHeader rtp_header_; 160 WebRtcRTPHeader rtp_header_;
150 uint32_t timestamp_; 161 uint32_t timestamp_;
151 bool packet_sent_; // Set when SendData is called reset when inserting audio. 162 bool packet_sent_; // Set when SendData is called reset when inserting audio.
152 uint32_t last_packet_send_timestamp_; 163 uint32_t last_packet_send_timestamp_;
153 FrameType last_frame_type_; 164 FrameType last_frame_type_;
154 }; 165 };
155 166
156 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecGetCodec)) { 167 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecGetCodec)) {
157 // Add codec. 168 // Add codec.
158 for (int n = 0; n < ACMCodecDB::kNumCodecs; ++n) { 169 for (size_t n = 0; n < codecs_.size(); ++n) {
159 if (n & 0x1) // Just add codecs with odd index. 170 if (n & 0x1) // Just add codecs with odd index.
160 EXPECT_EQ(0, 171 EXPECT_EQ(0,
161 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, 172 receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels,
162 codecs_[n].plfreq, NULL)); 173 codecs_[n].plfreq, NULL));
163 } 174 }
164 // Get codec and compare. 175 // Get codec and compare.
165 for (int n = 0; n < ACMCodecDB::kNumCodecs; ++n) { 176 for (size_t n = 0; n < codecs_.size(); ++n) {
166 CodecInst my_codec; 177 CodecInst my_codec;
167 if (n & 0x1) { 178 if (n & 0x1) {
168 // Codecs with odd index should match the reference. 179 // Codecs with odd index should match the reference.
169 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, 180 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype,
170 &my_codec)); 181 &my_codec));
171 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); 182 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec));
172 } else { 183 } else {
173 // Codecs with even index are not registered. 184 // Codecs with even index are not registered.
174 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype, 185 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(codecs_[n].pltype,
175 &my_codec)); 186 &my_codec));
176 } 187 }
177 } 188 }
178 } 189 }
179 190
180 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangePayloadType)) { 191 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangePayloadType)) {
181 const int codec_id = ACMCodecDB::kPCMA; 192 const CodecIdInst codec1(RentACodec::CodecId::kPCMA);
182 CodecInst ref_codec1; 193 CodecInst ref_codec2 = codec1.inst;
hlundin-webrtc 2015/10/27 13:52:02 Drop ref_ on this one too?
kwiberg-webrtc 2015/10/27 14:43:23 Done.
183 EXPECT_EQ(0, ACMCodecDB::Codec(codec_id, &ref_codec1));
184 CodecInst ref_codec2 = ref_codec1;
185 ++ref_codec2.pltype; 194 ++ref_codec2.pltype;
186 CodecInst test_codec; 195 CodecInst test_codec;
187 196
188 // Register the same codec with different payloads. 197 // Register the same codec with different payloads.
198 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
199 codec1.inst.channels, codec1.inst.plfreq,
200 nullptr));
189 EXPECT_EQ( 201 EXPECT_EQ(
190 0, receiver_->AddCodec(codec_id, ref_codec1.pltype, ref_codec1.channels, 202 0, receiver_->AddCodec(codec1.id, ref_codec2.pltype, ref_codec2.channels,
191 ref_codec1.plfreq, NULL));
192 EXPECT_EQ(
193 0, receiver_->AddCodec(codec_id, ref_codec2.pltype, ref_codec2.channels,
194 ref_codec2.plfreq, NULL)); 203 ref_codec2.plfreq, NULL));
195 204
196 // Both payload types should exist. 205 // Both payload types should exist.
197 EXPECT_EQ(0, receiver_->DecoderByPayloadType(ref_codec1.pltype, &test_codec)); 206 EXPECT_EQ(0,
198 EXPECT_EQ(true, CodecsEqual(ref_codec1, test_codec)); 207 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec));
208 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec));
199 EXPECT_EQ(0, receiver_->DecoderByPayloadType(ref_codec2.pltype, &test_codec)); 209 EXPECT_EQ(0, receiver_->DecoderByPayloadType(ref_codec2.pltype, &test_codec));
200 EXPECT_EQ(true, CodecsEqual(ref_codec2, test_codec)); 210 EXPECT_EQ(true, CodecsEqual(ref_codec2, test_codec));
201 } 211 }
202 212
203 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangeCodecId)) { 213 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecChangeCodecId)) {
204 const int codec_id1 = ACMCodecDB::kPCMU; 214 const CodecIdInst codec1(RentACodec::CodecId::kPCMU);
205 CodecInst ref_codec1; 215 CodecIdInst codec2(RentACodec::CodecId::kPCMA);
206 EXPECT_EQ(0, ACMCodecDB::Codec(codec_id1, &ref_codec1)); 216 codec2.inst.pltype = codec1.inst.pltype;
207 const int codec_id2 = ACMCodecDB::kPCMA;
208 CodecInst ref_codec2;
209 EXPECT_EQ(0, ACMCodecDB::Codec(codec_id2, &ref_codec2));
210 ref_codec2.pltype = ref_codec1.pltype;
211 CodecInst test_codec; 217 CodecInst test_codec;
212 218
213 // Register the same payload type with different codec ID. 219 // Register the same payload type with different codec ID.
214 EXPECT_EQ( 220 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype,
215 0, receiver_->AddCodec(codec_id1, ref_codec1.pltype, ref_codec1.channels, 221 codec1.inst.channels, codec1.inst.plfreq,
216 ref_codec1.plfreq, NULL)); 222 nullptr));
217 EXPECT_EQ( 223 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype,
218 0, receiver_->AddCodec(codec_id2, ref_codec2.pltype, ref_codec2.channels, 224 codec2.inst.channels, codec2.inst.plfreq,
219 ref_codec2.plfreq, NULL)); 225 nullptr));
220 226
221 // Make sure that the last codec is used. 227 // Make sure that the last codec is used.
222 EXPECT_EQ(0, receiver_->DecoderByPayloadType(ref_codec2.pltype, &test_codec)); 228 EXPECT_EQ(0,
223 EXPECT_EQ(true, CodecsEqual(ref_codec2, test_codec)); 229 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec));
230 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec));
224 } 231 }
225 232
226 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecRemoveCodec)) { 233 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(AddCodecRemoveCodec)) {
227 CodecInst codec; 234 const CodecIdInst codec(RentACodec::CodecId::kPCMA);
228 const int codec_id = ACMCodecDB::kPCMA; 235 const int payload_type = codec.inst.pltype;
229 EXPECT_EQ(0, ACMCodecDB::Codec(codec_id, &codec)); 236 EXPECT_EQ(
230 const int payload_type = codec.pltype; 237 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
231 EXPECT_EQ(0, receiver_->AddCodec(codec_id, codec.pltype, codec.channels, 238 codec.inst.plfreq, nullptr));
232 codec.plfreq, NULL));
233 239
234 // Remove non-existing codec should not fail. ACM1 legacy. 240 // Remove non-existing codec should not fail. ACM1 legacy.
235 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); 241 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1));
236 242
237 // Remove an existing codec. 243 // Remove an existing codec.
238 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); 244 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type));
239 245
240 // Ask for the removed codec, must fail. 246 // Ask for the removed codec, must fail.
241 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &codec)); 247 CodecInst ci;
248 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci));
242 } 249 }
243 250
244 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(SampleRate)) { 251 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(SampleRate)) {
245 const int kCodecId[] = { 252 const RentACodec::CodecId kCodecId[] = {RentACodec::CodecId::kISAC,
246 ACMCodecDB::kISAC, ACMCodecDB::kISACSWB, 253 RentACodec::CodecId::kISACSWB};
247 -1 // Terminator.
248 };
249 AddSetOfCodecs(kCodecId); 254 AddSetOfCodecs(kCodecId);
250 255
251 AudioFrame frame; 256 AudioFrame frame;
252 const int kOutSampleRateHz = 8000; // Different than codec sample rate. 257 const int kOutSampleRateHz = 8000; // Different than codec sample rate.
253 int n = 0; 258 for (const auto codec_id : kCodecId) {
254 while (kCodecId[n] >= 0) { 259 const CodecIdInst codec(codec_id);
255 const int num_10ms_frames = codecs_[kCodecId[n]].pacsize / 260 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
256 (codecs_[kCodecId[n]].plfreq / 100); 261 InsertOnePacketOfSilence(codec.id);
257 InsertOnePacketOfSilence(kCodecId[n]);
258 for (int k = 0; k < num_10ms_frames; ++k) { 262 for (int k = 0; k < num_10ms_frames; ++k) {
259 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame)); 263 EXPECT_EQ(0, receiver_->GetAudio(kOutSampleRateHz, &frame));
260 } 264 }
261 EXPECT_EQ(std::min(32000, codecs_[kCodecId[n]].plfreq), 265 EXPECT_EQ(std::min(32000, codec.inst.plfreq),
262 receiver_->current_sample_rate_hz()); 266 receiver_->current_sample_rate_hz());
263 ++n;
264 } 267 }
265 } 268 }
266 269
267 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(PostdecodingVad)) { 270 TEST_F(AcmReceiverTestOldApi, DISABLED_ON_ANDROID(PostdecodingVad)) {
268 receiver_->EnableVad(); 271 receiver_->EnableVad();
269 EXPECT_TRUE(receiver_->vad_enabled()); 272 EXPECT_TRUE(receiver_->vad_enabled());
270 273 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
271 const int id = ACMCodecDB::kPCM16Bwb; 274 ASSERT_EQ(
272 ASSERT_EQ(0, receiver_->AddCodec(id, codecs_[id].pltype, codecs_[id].channels, 275 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels,
273 codecs_[id].plfreq, NULL)); 276 codec.inst.plfreq, nullptr));
274 const int kNumPackets = 5; 277 const int kNumPackets = 5;
275 const int num_10ms_frames = codecs_[id].pacsize / (codecs_[id].plfreq / 100); 278 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
276 AudioFrame frame; 279 AudioFrame frame;
277 for (int n = 0; n < kNumPackets; ++n) { 280 for (int n = 0; n < kNumPackets; ++n) {
278 InsertOnePacketOfSilence(id); 281 InsertOnePacketOfSilence(codec.id);
279 for (int k = 0; k < num_10ms_frames; ++k) 282 for (int k = 0; k < num_10ms_frames; ++k)
280 ASSERT_EQ(0, receiver_->GetAudio(codecs_[id].plfreq, &frame)); 283 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame));
281 } 284 }
282 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_); 285 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_);
283 286
284 receiver_->DisableVad(); 287 receiver_->DisableVad();
285 EXPECT_FALSE(receiver_->vad_enabled()); 288 EXPECT_FALSE(receiver_->vad_enabled());
286 289
287 for (int n = 0; n < kNumPackets; ++n) { 290 for (int n = 0; n < kNumPackets; ++n) {
288 InsertOnePacketOfSilence(id); 291 InsertOnePacketOfSilence(codec.id);
289 for (int k = 0; k < num_10ms_frames; ++k) 292 for (int k = 0; k < num_10ms_frames; ++k)
290 ASSERT_EQ(0, receiver_->GetAudio(codecs_[id].plfreq, &frame)); 293 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame));
291 } 294 }
292 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_); 295 EXPECT_EQ(AudioFrame::kVadUnknown, frame.vad_activity_);
293 } 296 }
294 297
295 #ifdef WEBRTC_CODEC_ISAC 298 #ifdef WEBRTC_CODEC_ISAC
296 #define IF_ISAC_FLOAT(x) x 299 #define IF_ISAC_FLOAT(x) x
297 #else 300 #else
298 #define IF_ISAC_FLOAT(x) DISABLED_##x 301 #define IF_ISAC_FLOAT(x) DISABLED_##x
299 #endif 302 #endif
300 303
301 TEST_F(AcmReceiverTestOldApi, 304 TEST_F(AcmReceiverTestOldApi,
302 DISABLED_ON_ANDROID(IF_ISAC_FLOAT(LastAudioCodec))) { 305 DISABLED_ON_ANDROID(IF_ISAC_FLOAT(LastAudioCodec))) {
303 const int kCodecId[] = { 306 const RentACodec::CodecId kCodecId[] = {
304 ACMCodecDB::kISAC, ACMCodecDB::kPCMA, ACMCodecDB::kISACSWB, 307 RentACodec::CodecId::kISAC, RentACodec::CodecId::kPCMA,
305 ACMCodecDB::kPCM16Bswb32kHz, 308 RentACodec::CodecId::kISACSWB, RentACodec::CodecId::kPCM16Bswb32kHz};
306 -1 // Terminator.
307 };
308 AddSetOfCodecs(kCodecId); 309 AddSetOfCodecs(kCodecId);
309 310
310 const int kCngId[] = { // Not including full-band. 311 const RentACodec::CodecId kCngId[] = {
311 ACMCodecDB::kCNNB, ACMCodecDB::kCNWB, ACMCodecDB::kCNSWB, 312 // Not including full-band.
312 -1 // Terminator. 313 RentACodec::CodecId::kCNNB, RentACodec::CodecId::kCNWB,
313 }; 314 RentACodec::CodecId::kCNSWB};
314 AddSetOfCodecs(kCngId); 315 AddSetOfCodecs(kCngId);
315 316
316 // Register CNG at sender side. 317 // Register CNG at sender side.
317 int n = 0; 318 for (auto id : kCngId)
318 while (kCngId[n] > 0) { 319 ASSERT_EQ(0, acm_->RegisterSendCodec(CodecIdInst(id).inst));
319 ASSERT_EQ(0, acm_->RegisterSendCodec(codecs_[kCngId[n]]));
320 ++n;
321 }
322 320
323 CodecInst codec; 321 CodecInst codec;
324 // No audio payload is received. 322 // No audio payload is received.
325 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec)); 323 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
326 324
327 // Start with sending DTX. 325 // Start with sending DTX.
328 ASSERT_EQ(0, acm_->SetVAD(true, true, VADVeryAggr)); 326 ASSERT_EQ(0, acm_->SetVAD(true, true, VADVeryAggr));
329 packet_sent_ = false; 327 packet_sent_ = false;
330 InsertOnePacketOfSilence(kCodecId[0]); // Enough to test with one codec. 328 InsertOnePacketOfSilence(CodecIdInst(kCodecId[0]).id); // Enough to test
329 // with one codec.
331 ASSERT_TRUE(packet_sent_); 330 ASSERT_TRUE(packet_sent_);
332 EXPECT_EQ(kAudioFrameCN, last_frame_type_); 331 EXPECT_EQ(kAudioFrameCN, last_frame_type_);
333 332
334 // Has received, only, DTX. Last Audio codec is undefined. 333 // Has received, only, DTX. Last Audio codec is undefined.
335 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec)); 334 EXPECT_EQ(-1, receiver_->LastAudioCodec(&codec));
336 EXPECT_EQ(-1, receiver_->last_audio_codec_id()); 335 EXPECT_EQ(-1, receiver_->last_audio_codec_id());
337 336
338 n = 0; 337 for (auto id : kCodecId) {
339 while (kCodecId[n] >= 0) { // Loop over codecs. 338 const CodecIdInst c(id);
339
340 // Set DTX off to send audio payload. 340 // Set DTX off to send audio payload.
341 acm_->SetVAD(false, false, VADAggr); 341 acm_->SetVAD(false, false, VADAggr);
342 packet_sent_ = false; 342 packet_sent_ = false;
343 InsertOnePacketOfSilence(kCodecId[n]); 343 InsertOnePacketOfSilence(c.id);
344 344
345 // Sanity check if Actually an audio payload received, and it should be 345 // Sanity check if Actually an audio payload received, and it should be
346 // of type "speech." 346 // of type "speech."
347 ASSERT_TRUE(packet_sent_); 347 ASSERT_TRUE(packet_sent_);
348 ASSERT_EQ(kAudioFrameSpeech, last_frame_type_); 348 ASSERT_EQ(kAudioFrameSpeech, last_frame_type_);
349 EXPECT_EQ(kCodecId[n], receiver_->last_audio_codec_id()); 349 EXPECT_EQ(c.id, receiver_->last_audio_codec_id());
350 350
351 // Set VAD on to send DTX. Then check if the "Last Audio codec" returns 351 // Set VAD on to send DTX. Then check if the "Last Audio codec" returns
352 // the expected codec. 352 // the expected codec.
353 acm_->SetVAD(true, true, VADAggr); 353 acm_->SetVAD(true, true, VADAggr);
354 354
355 // Do as many encoding until a DTX is sent. 355 // Do as many encoding until a DTX is sent.
356 while (last_frame_type_ != kAudioFrameCN) { 356 while (last_frame_type_ != kAudioFrameCN) {
357 packet_sent_ = false; 357 packet_sent_ = false;
358 InsertOnePacketOfSilence(kCodecId[n]); 358 InsertOnePacketOfSilence(c.id);
359 ASSERT_TRUE(packet_sent_); 359 ASSERT_TRUE(packet_sent_);
360 } 360 }
361 EXPECT_EQ(kCodecId[n], receiver_->last_audio_codec_id()); 361 EXPECT_EQ(c.id, receiver_->last_audio_codec_id());
362 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); 362 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
363 EXPECT_TRUE(CodecsEqual(codecs_[kCodecId[n]], codec)); 363 EXPECT_TRUE(CodecsEqual(c.inst, codec));
364 ++n;
365 } 364 }
366 } 365 }
367 366
368 } // namespace acm2 367 } // namespace acm2
369 368
370 } // namespace webrtc 369 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698