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

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

Issue 2393873002: Remove old AcmReceiver::AddCodec overload
Patch Set: rebase Created 4 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
11 #include "webrtc/modules/audio_coding/acm2/acm_receiver.h" 11 #include "webrtc/modules/audio_coding/acm2/acm_receiver.h"
12 12
13 #include <algorithm> // std::min 13 #include <algorithm> // std::min
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/safe_conversions.h" 17 #include "webrtc/base/safe_conversions.h"
18 #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
18 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" 19 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
19 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" 20 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
20 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" 21 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
21 #include "webrtc/system_wrappers/include/clock.h" 22 #include "webrtc/system_wrappers/include/clock.h"
22 #include "webrtc/test/gtest.h" 23 #include "webrtc/test/gtest.h"
23 #include "webrtc/test/test_suite.h" 24 #include "webrtc/test/test_suite.h"
24 #include "webrtc/test/testsupport/fileutils.h" 25 #include "webrtc/test/testsupport/fileutils.h"
25 26
26 namespace webrtc { 27 namespace webrtc {
27 28
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 timestamp_ += frame.samples_per_channel_; 113 timestamp_ += frame.samples_per_channel_;
113 ASSERT_GE(acm_->Add10MsData(frame), 0); 114 ASSERT_GE(acm_->Add10MsData(frame), 0);
114 } 115 }
115 } 116 }
116 117
117 template <size_t N> 118 template <size_t N>
118 void AddSetOfCodecs(const RentACodec::CodecId(&ids)[N]) { 119 void AddSetOfCodecs(const RentACodec::CodecId(&ids)[N]) {
119 for (auto id : ids) { 120 for (auto id : ids) {
120 const auto i = RentACodec::CodecIndexFromId(id); 121 const auto i = RentACodec::CodecIndexFromId(id);
121 ASSERT_TRUE(i); 122 ASSERT_TRUE(i);
122 ASSERT_EQ(0, receiver_->AddCodec(*i, codecs_[*i].pltype, 123 ASSERT_EQ(true, receiver_->AddCodec(codecs_[*i].pltype,
123 codecs_[*i].channels, codecs_[*i].plfreq, 124 CodecInstToSdp(codecs_[*i])));
124 nullptr, codecs_[*i].plname));
125 } 125 }
126 } 126 }
127 127
128 int SendData(FrameType frame_type, 128 int SendData(FrameType frame_type,
129 uint8_t payload_type, 129 uint8_t payload_type,
130 uint32_t timestamp, 130 uint32_t timestamp,
131 const uint8_t* payload_data, 131 const uint8_t* payload_data,
132 size_t payload_len_bytes, 132 size_t payload_len_bytes,
133 const RTPFragmentationHeader* fragmentation) override { 133 const RTPFragmentationHeader* fragmentation) override {
134 if (frame_type == kEmptyFrame) 134 if (frame_type == kEmptyFrame)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 #if defined(WEBRTC_ANDROID) 169 #if defined(WEBRTC_ANDROID)
170 #define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec 170 #define MAYBE_AddCodecGetCodec DISABLED_AddCodecGetCodec
171 #else 171 #else
172 #define MAYBE_AddCodecGetCodec AddCodecGetCodec 172 #define MAYBE_AddCodecGetCodec AddCodecGetCodec
173 #endif 173 #endif
174 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) { 174 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) {
175 // Add codec. 175 // Add codec.
176 for (size_t n = 0; n < codecs_.size(); ++n) { 176 for (size_t n = 0; n < codecs_.size(); ++n) {
177 if (n & 0x1) { // Just add codecs with odd index. 177 if (n & 0x1) { // Just add codecs with odd index.
178 EXPECT_EQ( 178 EXPECT_EQ(true, receiver_->AddCodec(codecs_[n].pltype,
179 0, receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, 179 CodecInstToSdp(codecs_[n])));
180 codecs_[n].plfreq, NULL, codecs_[n].plname));
181 } 180 }
182 } 181 }
183 // Get codec and compare. 182 // Get codec and compare.
184 for (size_t n = 0; n < codecs_.size(); ++n) { 183 for (size_t n = 0; n < codecs_.size(); ++n) {
185 CodecInst my_codec; 184 CodecInst my_codec;
186 if (n & 0x1) { 185 if (n & 0x1) {
187 // Codecs with odd index should match the reference. 186 // Codecs with odd index should match the reference.
188 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype, 187 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codecs_[n].pltype,
189 &my_codec)); 188 &my_codec));
190 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec)); 189 EXPECT_TRUE(CodecsEqual(codecs_[n], my_codec));
(...skipping 10 matching lines...) Expand all
201 #else 200 #else
202 #define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType 201 #define MAYBE_AddCodecChangePayloadType AddCodecChangePayloadType
203 #endif 202 #endif
204 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) { 203 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) {
205 const CodecIdInst codec1(RentACodec::CodecId::kPCMA); 204 const CodecIdInst codec1(RentACodec::CodecId::kPCMA);
206 CodecInst codec2 = codec1.inst; 205 CodecInst codec2 = codec1.inst;
207 ++codec2.pltype; 206 ++codec2.pltype;
208 CodecInst test_codec; 207 CodecInst test_codec;
209 208
210 // Register the same codec with different payloads. 209 // Register the same codec with different payloads.
211 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, 210 EXPECT_EQ(true, receiver_->AddCodec(codec1.inst.pltype,
212 codec1.inst.channels, codec1.inst.plfreq, 211 CodecInstToSdp(codec1.inst)));
213 nullptr, codec1.inst.plname)); 212 EXPECT_EQ(true, receiver_->AddCodec(codec2.pltype, CodecInstToSdp(codec2)));
214 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels,
215 codec2.plfreq, NULL, codec2.plname));
216 213
217 // Both payload types should exist. 214 // Both payload types should exist.
218 EXPECT_EQ(0, 215 EXPECT_EQ(0,
219 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec)); 216 receiver_->DecoderByPayloadType(codec1.inst.pltype, &test_codec));
220 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec)); 217 EXPECT_EQ(true, CodecsEqual(codec1.inst, test_codec));
221 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec)); 218 EXPECT_EQ(0, receiver_->DecoderByPayloadType(codec2.pltype, &test_codec));
222 EXPECT_EQ(true, CodecsEqual(codec2, test_codec)); 219 EXPECT_EQ(true, CodecsEqual(codec2, test_codec));
223 } 220 }
224 221
225 #if defined(WEBRTC_ANDROID) 222 #if defined(WEBRTC_ANDROID)
226 #define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId 223 #define MAYBE_AddCodecChangeCodecId DISABLED_AddCodecChangeCodecId
227 #else 224 #else
228 #define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId 225 #define MAYBE_AddCodecChangeCodecId AddCodecChangeCodecId
229 #endif 226 #endif
230 TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) { 227 TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) {
231 const CodecIdInst codec1(RentACodec::CodecId::kPCMU); 228 const CodecIdInst codec1(RentACodec::CodecId::kPCMU);
232 CodecIdInst codec2(RentACodec::CodecId::kPCMA); 229 CodecIdInst codec2(RentACodec::CodecId::kPCMA);
233 codec2.inst.pltype = codec1.inst.pltype; 230 codec2.inst.pltype = codec1.inst.pltype;
234 CodecInst test_codec; 231 CodecInst test_codec;
235 232
236 // Register the same payload type with different codec ID. 233 // Register the same payload type with different codec.
237 EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, 234 EXPECT_EQ(true, receiver_->AddCodec(codec1.inst.pltype,
238 codec1.inst.channels, codec1.inst.plfreq, 235 CodecInstToSdp(codec1.inst)));
239 nullptr, codec1.inst.plname)); 236 EXPECT_EQ(true, receiver_->AddCodec(codec2.inst.pltype,
240 EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, 237 CodecInstToSdp(codec2.inst)));
241 codec2.inst.channels, codec2.inst.plfreq,
242 nullptr, codec2.inst.plname));
243 238
244 // Make sure that the last codec is used. 239 // Make sure that the last codec is used.
245 EXPECT_EQ(0, 240 EXPECT_EQ(0,
246 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec)); 241 receiver_->DecoderByPayloadType(codec2.inst.pltype, &test_codec));
247 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec)); 242 EXPECT_EQ(true, CodecsEqual(codec2.inst, test_codec));
248 } 243 }
249 244
250 #if defined(WEBRTC_ANDROID) 245 #if defined(WEBRTC_ANDROID)
251 #define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec 246 #define MAYBE_AddCodecRemoveCodec DISABLED_AddCodecRemoveCodec
252 #else 247 #else
253 #define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec 248 #define MAYBE_AddCodecRemoveCodec AddCodecRemoveCodec
254 #endif 249 #endif
255 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) { 250 TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) {
256 const CodecIdInst codec(RentACodec::CodecId::kPCMA); 251 const CodecIdInst codec(RentACodec::CodecId::kPCMA);
257 const int payload_type = codec.inst.pltype; 252 const int payload_type = codec.inst.pltype;
258 EXPECT_EQ( 253 EXPECT_EQ(true,
259 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, 254 receiver_->AddCodec(codec.inst.pltype, CodecInstToSdp(codec.inst)));
260 codec.inst.plfreq, nullptr, codec.inst.plname));
261 255
262 // Remove non-existing codec should not fail. ACM1 legacy. 256 // Remove non-existing codec should not fail. ACM1 legacy.
263 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1)); 257 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1));
264 258
265 // Remove an existing codec. 259 // Remove an existing codec.
266 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type)); 260 EXPECT_EQ(0, receiver_->RemoveCodec(payload_type));
267 261
268 // Ask for the removed codec, must fail. 262 // Ask for the removed codec, must fail.
269 CodecInst ci; 263 CodecInst ci;
270 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci)); 264 EXPECT_EQ(-1, receiver_->DecoderByPayloadType(payload_type, &ci));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 373 }
380 374
381 #if defined(WEBRTC_ANDROID) 375 #if defined(WEBRTC_ANDROID)
382 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad 376 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
383 #else 377 #else
384 #define MAYBE_PostdecodingVad PostdecodingVad 378 #define MAYBE_PostdecodingVad PostdecodingVad
385 #endif 379 #endif
386 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) { 380 TEST_F(AcmReceiverTestOldApi, MAYBE_PostdecodingVad) {
387 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad); 381 EXPECT_TRUE(config_.neteq_config.enable_post_decode_vad);
388 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); 382 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
389 ASSERT_EQ( 383 ASSERT_EQ(true,
390 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, 384 receiver_->AddCodec(codec.inst.pltype, CodecInstToSdp(codec.inst)));
391 codec.inst.plfreq, nullptr, ""));
392 const int kNumPackets = 5; 385 const int kNumPackets = 5;
393 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); 386 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
394 AudioFrame frame; 387 AudioFrame frame;
395 for (int n = 0; n < kNumPackets; ++n) { 388 for (int n = 0; n < kNumPackets; ++n) {
396 InsertOnePacketOfSilence(codec.id); 389 InsertOnePacketOfSilence(codec.id);
397 for (int k = 0; k < num_10ms_frames; ++k) { 390 for (int k = 0; k < num_10ms_frames; ++k) {
398 bool muted; 391 bool muted;
399 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted)); 392 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
400 } 393 }
401 } 394 }
402 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_); 395 EXPECT_EQ(AudioFrame::kVadPassive, frame.vad_activity_);
403 } 396 }
404 397
405 class AcmReceiverTestPostDecodeVadPassiveOldApi : public AcmReceiverTestOldApi { 398 class AcmReceiverTestPostDecodeVadPassiveOldApi : public AcmReceiverTestOldApi {
406 protected: 399 protected:
407 AcmReceiverTestPostDecodeVadPassiveOldApi() { 400 AcmReceiverTestPostDecodeVadPassiveOldApi() {
408 config_.neteq_config.enable_post_decode_vad = false; 401 config_.neteq_config.enable_post_decode_vad = false;
409 } 402 }
410 }; 403 };
411 404
412 #if defined(WEBRTC_ANDROID) 405 #if defined(WEBRTC_ANDROID)
413 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad 406 #define MAYBE_PostdecodingVad DISABLED_PostdecodingVad
414 #else 407 #else
415 #define MAYBE_PostdecodingVad PostdecodingVad 408 #define MAYBE_PostdecodingVad PostdecodingVad
416 #endif 409 #endif
417 TEST_F(AcmReceiverTestPostDecodeVadPassiveOldApi, MAYBE_PostdecodingVad) { 410 TEST_F(AcmReceiverTestPostDecodeVadPassiveOldApi, MAYBE_PostdecodingVad) {
418 EXPECT_FALSE(config_.neteq_config.enable_post_decode_vad); 411 EXPECT_FALSE(config_.neteq_config.enable_post_decode_vad);
419 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb); 412 const CodecIdInst codec(RentACodec::CodecId::kPCM16Bwb);
420 ASSERT_EQ( 413 ASSERT_EQ(true,
421 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, 414 receiver_->AddCodec(codec.inst.pltype, CodecInstToSdp(codec.inst)));
422 codec.inst.plfreq, nullptr, ""));
423 const int kNumPackets = 5; 415 const int kNumPackets = 5;
424 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100); 416 const int num_10ms_frames = codec.inst.pacsize / (codec.inst.plfreq / 100);
425 AudioFrame frame; 417 AudioFrame frame;
426 for (int n = 0; n < kNumPackets; ++n) { 418 for (int n = 0; n < kNumPackets; ++n) {
427 InsertOnePacketOfSilence(codec.id); 419 InsertOnePacketOfSilence(codec.id);
428 for (int k = 0; k < num_10ms_frames; ++k) { 420 for (int k = 0; k < num_10ms_frames; ++k) {
429 bool muted; 421 bool muted;
430 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted)); 422 ASSERT_EQ(0, receiver_->GetAudio(codec.inst.plfreq, &frame, &muted));
431 } 423 }
432 } 424 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 receiver_->last_packet_sample_rate_hz()); 492 receiver_->last_packet_sample_rate_hz());
501 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec)); 493 EXPECT_EQ(0, receiver_->LastAudioCodec(&codec));
502 EXPECT_TRUE(CodecsEqual(c.inst, codec)); 494 EXPECT_TRUE(CodecsEqual(c.inst, codec));
503 } 495 }
504 } 496 }
505 #endif 497 #endif
506 498
507 } // namespace acm2 499 } // namespace acm2
508 500
509 } // namespace webrtc 501 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/acm2/acm_receiver.cc ('k') | webrtc/modules/audio_coding/acm2/audio_coding_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698