OLD | NEW |
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 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <memory> | 13 #include <memory> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
18 #include "webrtc/base/md5digest.h" | 18 #include "webrtc/base/md5digest.h" |
19 #include "webrtc/base/platform_thread.h" | 19 #include "webrtc/base/platform_thread.h" |
20 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
21 #include "webrtc/modules/audio_coding/acm2/acm_receive_test_oldapi.h" | 21 #include "webrtc/modules/audio_coding/acm2/acm_receive_test_oldapi.h" |
22 #include "webrtc/modules/audio_coding/acm2/acm_send_test_oldapi.h" | 22 #include "webrtc/modules/audio_coding/acm2/acm_send_test_oldapi.h" |
| 23 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
23 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 24 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
24 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" | 25 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" |
25 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" | 26 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" |
26 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa
c.h" | 27 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa
c.h" |
27 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" | 28 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
28 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" | 29 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
29 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 30 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
30 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" | 31 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" |
31 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h" | 32 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h" |
32 #include "webrtc/modules/audio_coding/neteq/tools/audio_checksum.h" | 33 #include "webrtc/modules/audio_coding/neteq/tools/audio_checksum.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 0, | 176 0, |
176 input_frame_.samples_per_channel_ * sizeof(input_frame_.data_[0])); | 177 input_frame_.samples_per_channel_ * sizeof(input_frame_.data_[0])); |
177 | 178 |
178 ASSERT_EQ(0, acm_->RegisterTransportCallback(&packet_cb_)); | 179 ASSERT_EQ(0, acm_->RegisterTransportCallback(&packet_cb_)); |
179 | 180 |
180 SetUpL16Codec(); | 181 SetUpL16Codec(); |
181 } | 182 } |
182 | 183 |
183 // Set up L16 codec. | 184 // Set up L16 codec. |
184 virtual void SetUpL16Codec() { | 185 virtual void SetUpL16Codec() { |
| 186 audio_format_ = |
| 187 rtc::Optional<SdpAudioFormat>(SdpAudioFormat("L16", kSampleRateHz, 1)); |
185 ASSERT_EQ(0, AudioCodingModule::Codec("L16", &codec_, kSampleRateHz, 1)); | 188 ASSERT_EQ(0, AudioCodingModule::Codec("L16", &codec_, kSampleRateHz, 1)); |
186 codec_.pltype = kPayloadType; | 189 codec_.pltype = kPayloadType; |
187 } | 190 } |
188 | 191 |
189 virtual void RegisterCodec() { | 192 virtual void RegisterCodec() { |
190 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); | 193 EXPECT_EQ(true, acm_->RegisterReceiveCodec(kPayloadType, *audio_format_)); |
191 ASSERT_EQ(0, acm_->RegisterSendCodec(codec_)); | 194 EXPECT_EQ(0, acm_->RegisterSendCodec(codec_)); |
192 } | 195 } |
193 | 196 |
194 virtual void InsertPacketAndPullAudio() { | 197 virtual void InsertPacketAndPullAudio() { |
195 InsertPacket(); | 198 InsertPacket(); |
196 PullAudio(); | 199 PullAudio(); |
197 } | 200 } |
198 | 201 |
199 virtual void InsertPacket() { | 202 virtual void InsertPacket() { |
200 const uint8_t kPayload[kPayloadSizeBytes] = {0}; | 203 const uint8_t kPayload[kPayloadSizeBytes] = {0}; |
201 ASSERT_EQ(0, | 204 ASSERT_EQ(0, |
(...skipping 23 matching lines...) Expand all Loading... |
225 InsertAudio(); | 228 InsertAudio(); |
226 VerifyEncoding(); | 229 VerifyEncoding(); |
227 } | 230 } |
228 | 231 |
229 const int id_; | 232 const int id_; |
230 std::unique_ptr<RtpUtility> rtp_utility_; | 233 std::unique_ptr<RtpUtility> rtp_utility_; |
231 std::unique_ptr<AudioCodingModule> acm_; | 234 std::unique_ptr<AudioCodingModule> acm_; |
232 PacketizationCallbackStubOldApi packet_cb_; | 235 PacketizationCallbackStubOldApi packet_cb_; |
233 WebRtcRTPHeader rtp_header_; | 236 WebRtcRTPHeader rtp_header_; |
234 AudioFrame input_frame_; | 237 AudioFrame input_frame_; |
| 238 |
| 239 // These two have to be kept in sync for now. In the future, we'll be able to |
| 240 // eliminate the CodecInst and keep only the SdpAudioFormat. |
| 241 rtc::Optional<SdpAudioFormat> audio_format_; |
235 CodecInst codec_; | 242 CodecInst codec_; |
| 243 |
236 Clock* clock_; | 244 Clock* clock_; |
237 }; | 245 }; |
238 | 246 |
239 // Check if the statistics are initialized correctly. Before any call to ACM | 247 // Check if the statistics are initialized correctly. Before any call to ACM |
240 // all fields have to be zero. | 248 // all fields have to be zero. |
241 #if defined(WEBRTC_ANDROID) | 249 #if defined(WEBRTC_ANDROID) |
242 #define MAYBE_InitializedToZero DISABLED_InitializedToZero | 250 #define MAYBE_InitializedToZero DISABLED_InitializedToZero |
243 #else | 251 #else |
244 #define MAYBE_InitializedToZero InitializedToZero | 252 #define MAYBE_InitializedToZero InitializedToZero |
245 #endif | 253 #endif |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 392 |
385 // Introduce this class to set different expectations on the number of encoded | 393 // Introduce this class to set different expectations on the number of encoded |
386 // bytes. This class expects all encoded packets to be 9 bytes (matching one | 394 // bytes. This class expects all encoded packets to be 9 bytes (matching one |
387 // CNG SID frame) or 0 bytes. This test depends on |input_frame_| containing | 395 // CNG SID frame) or 0 bytes. This test depends on |input_frame_| containing |
388 // (near-)zero values. It also introduces a way to register comfort noise with | 396 // (near-)zero values. It also introduces a way to register comfort noise with |
389 // a custom payload type. | 397 // a custom payload type. |
390 class AudioCodingModuleTestWithComfortNoiseOldApi | 398 class AudioCodingModuleTestWithComfortNoiseOldApi |
391 : public AudioCodingModuleTestOldApi { | 399 : public AudioCodingModuleTestOldApi { |
392 protected: | 400 protected: |
393 void RegisterCngCodec(int rtp_payload_type) { | 401 void RegisterCngCodec(int rtp_payload_type) { |
| 402 EXPECT_EQ(true, |
| 403 acm_->RegisterReceiveCodec( |
| 404 rtp_payload_type, SdpAudioFormat("cn", kSampleRateHz, 1))); |
| 405 |
394 CodecInst codec; | 406 CodecInst codec; |
395 AudioCodingModule::Codec("CN", &codec, kSampleRateHz, 1); | 407 EXPECT_EQ(0, AudioCodingModule::Codec("CN", &codec, kSampleRateHz, 1)); |
396 codec.pltype = rtp_payload_type; | 408 codec.pltype = rtp_payload_type; |
397 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec)); | 409 EXPECT_EQ(0, acm_->RegisterSendCodec(codec)); |
398 ASSERT_EQ(0, acm_->RegisterSendCodec(codec)); | |
399 } | 410 } |
400 | 411 |
401 void VerifyEncoding() override { | 412 void VerifyEncoding() override { |
402 int last_length = packet_cb_.last_payload_len_bytes(); | 413 int last_length = packet_cb_.last_payload_len_bytes(); |
403 EXPECT_TRUE(last_length == 9 || last_length == 0) | 414 EXPECT_TRUE(last_length == 9 || last_length == 0) |
404 << "Last encoded packet was " << last_length << " bytes."; | 415 << "Last encoded packet was " << last_length << " bytes."; |
405 } | 416 } |
406 | 417 |
407 void DoTest(int blocks_per_packet, int cng_pt) { | 418 void DoTest(int blocks_per_packet, int cng_pt) { |
408 const int kLoops = 40; | 419 const int kLoops = 40; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 } | 655 } |
645 // Set |last_packet_number_| to one less that |num_calls| so that the packet | 656 // Set |last_packet_number_| to one less that |num_calls| so that the packet |
646 // will be fetched in the next InsertPacket() call. | 657 // will be fetched in the next InsertPacket() call. |
647 last_packet_number_ = packet_cb_.num_calls() - 1; | 658 last_packet_number_ = packet_cb_.num_calls() - 1; |
648 | 659 |
649 StartThreads(); | 660 StartThreads(); |
650 } | 661 } |
651 | 662 |
652 void RegisterCodec() override { | 663 void RegisterCodec() override { |
653 static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz"); | 664 static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz"); |
| 665 audio_format_ = |
| 666 rtc::Optional<SdpAudioFormat>(SdpAudioFormat("isac", kSampleRateHz, 1)); |
654 AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); | 667 AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); |
655 codec_.pltype = kPayloadType; | 668 codec_.pltype = kPayloadType; |
656 | 669 |
657 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec | 670 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec |
658 // registered in AudioCodingModuleTestOldApi::SetUp(); | 671 // registered in AudioCodingModuleTestOldApi::SetUp(); |
659 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); | 672 EXPECT_EQ(true, acm_->RegisterReceiveCodec(kPayloadType, *audio_format_)); |
660 ASSERT_EQ(0, acm_->RegisterSendCodec(codec_)); | 673 EXPECT_EQ(0, acm_->RegisterSendCodec(codec_)); |
661 } | 674 } |
662 | 675 |
663 void InsertPacket() override { | 676 void InsertPacket() override { |
664 int num_calls = packet_cb_.num_calls(); // Store locally for thread safety. | 677 int num_calls = packet_cb_.num_calls(); // Store locally for thread safety. |
665 if (num_calls > last_packet_number_) { | 678 if (num_calls > last_packet_number_) { |
666 // Get the new payload out from the callback handler. | 679 // Get the new payload out from the callback handler. |
667 // Note that since we swap buffers here instead of directly inserting | 680 // Note that since we swap buffers here instead of directly inserting |
668 // a pointer to the data in |packet_cb_|, we avoid locking the callback | 681 // a pointer to the data in |packet_cb_|, we avoid locking the callback |
669 // for the duration of the IncomingPacket() call. | 682 // for the duration of the IncomingPacket() call. |
670 packet_cb_.SwapBuffers(&last_payload_vec_); | 683 packet_cb_.SwapBuffers(&last_payload_vec_); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 920 |
908 protected: | 921 protected: |
909 struct ExternalDecoder { | 922 struct ExternalDecoder { |
910 int rtp_payload_type; | 923 int rtp_payload_type; |
911 AudioDecoder* external_decoder; | 924 AudioDecoder* external_decoder; |
912 int sample_rate_hz; | 925 int sample_rate_hz; |
913 int num_channels; | 926 int num_channels; |
914 std::string name; | 927 std::string name; |
915 }; | 928 }; |
916 | 929 |
| 930 void Run(int output_freq_hz, const std::string& checksum_ref) { |
| 931 Run(output_freq_hz, checksum_ref, CreateBuiltinAudioDecoderFactory(), |
| 932 [](AudioCodingModule*) {}); |
| 933 } |
| 934 |
917 void Run(int output_freq_hz, | 935 void Run(int output_freq_hz, |
918 const std::string& checksum_ref, | 936 const std::string& checksum_ref, |
919 const std::vector<ExternalDecoder>& external_decoders) { | 937 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
| 938 rtc::FunctionView<void(AudioCodingModule*)> decoder_reg) { |
920 const std::string input_file_name = | 939 const std::string input_file_name = |
921 webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); | 940 webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); |
922 std::unique_ptr<test::RtpFileSource> packet_source( | 941 std::unique_ptr<test::RtpFileSource> packet_source( |
923 test::RtpFileSource::Create(input_file_name)); | 942 test::RtpFileSource::Create(input_file_name)); |
924 #ifdef WEBRTC_ANDROID | 943 #ifdef WEBRTC_ANDROID |
925 // Filter out iLBC and iSAC-swb since they are not supported on Android. | 944 // Filter out iLBC and iSAC-swb since they are not supported on Android. |
926 packet_source->FilterOutPayloadType(102); // iLBC. | 945 packet_source->FilterOutPayloadType(102); // iLBC. |
927 packet_source->FilterOutPayloadType(104); // iSAC-swb. | 946 packet_source->FilterOutPayloadType(104); // iSAC-swb. |
928 #endif | 947 #endif |
929 | 948 |
930 test::AudioChecksum checksum; | 949 test::AudioChecksum checksum; |
931 const std::string output_file_name = | 950 const std::string output_file_name = |
932 webrtc::test::OutputPath() + | 951 webrtc::test::OutputPath() + |
933 ::testing::UnitTest::GetInstance() | 952 ::testing::UnitTest::GetInstance() |
934 ->current_test_info() | 953 ->current_test_info() |
935 ->test_case_name() + | 954 ->test_case_name() + |
936 "_" + ::testing::UnitTest::GetInstance()->current_test_info()->name() + | 955 "_" + ::testing::UnitTest::GetInstance()->current_test_info()->name() + |
937 "_output.pcm"; | 956 "_output.pcm"; |
938 test::OutputAudioFile output_file(output_file_name); | 957 test::OutputAudioFile output_file(output_file_name); |
939 test::AudioSinkFork output(&checksum, &output_file); | 958 test::AudioSinkFork output(&checksum, &output_file); |
940 | 959 |
941 test::AcmReceiveTestOldApi test( | 960 test::AcmReceiveTestOldApi test( |
942 packet_source.get(), | 961 packet_source.get(), &output, output_freq_hz, |
943 &output, | 962 test::AcmReceiveTestOldApi::kArbitraryChannels, |
944 output_freq_hz, | 963 std::move(decoder_factory)); |
945 test::AcmReceiveTestOldApi::kArbitraryChannels); | |
946 ASSERT_NO_FATAL_FAILURE(test.RegisterNetEqTestCodecs()); | 964 ASSERT_NO_FATAL_FAILURE(test.RegisterNetEqTestCodecs()); |
947 for (const auto& ed : external_decoders) { | 965 decoder_reg(test.get_acm()); |
948 ASSERT_EQ(0, test.RegisterExternalReceiveCodec( | |
949 ed.rtp_payload_type, ed.external_decoder, | |
950 ed.sample_rate_hz, ed.num_channels, ed.name)); | |
951 } | |
952 test.Run(); | 966 test.Run(); |
953 | 967 |
954 std::string checksum_string = checksum.Finish(); | 968 std::string checksum_string = checksum.Finish(); |
955 EXPECT_EQ(checksum_ref, checksum_string); | 969 EXPECT_EQ(checksum_ref, checksum_string); |
956 | 970 |
957 // Delete the output file. | 971 // Delete the output file. |
958 remove(output_file_name.c_str()); | 972 remove(output_file_name.c_str()); |
959 } | 973 } |
960 }; | 974 }; |
961 | 975 |
962 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ | 976 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ |
963 defined(WEBRTC_CODEC_ILBC) && defined(WEBRTC_CODEC_G722) | 977 defined(WEBRTC_CODEC_ILBC) && defined(WEBRTC_CODEC_G722) |
964 TEST_F(AcmReceiverBitExactnessOldApi, 8kHzOutput) { | 978 TEST_F(AcmReceiverBitExactnessOldApi, 8kHzOutput) { |
965 Run(8000, PlatformChecksum("dce4890259e9ded50f472455aa470a6f", | 979 Run(8000, PlatformChecksum("dce4890259e9ded50f472455aa470a6f", |
966 "1c4ada78b12612147f3026920f8dcc14", | 980 "1c4ada78b12612147f3026920f8dcc14", |
967 "d804791edf2d00be2bc31c81a47368d4", | 981 "d804791edf2d00be2bc31c81a47368d4", |
968 "b2611f7323ab1209d5056399d0babbf5"), | 982 "b2611f7323ab1209d5056399d0babbf5")); |
969 std::vector<ExternalDecoder>()); | |
970 } | 983 } |
971 | 984 |
972 TEST_F(AcmReceiverBitExactnessOldApi, 16kHzOutput) { | 985 TEST_F(AcmReceiverBitExactnessOldApi, 16kHzOutput) { |
973 Run(16000, PlatformChecksum("27356bddffaa42b5c841b49aa3a070c5", | 986 Run(16000, PlatformChecksum("27356bddffaa42b5c841b49aa3a070c5", |
974 "5667d1872fc351244092ae995e5a5b32", | 987 "5667d1872fc351244092ae995e5a5b32", |
975 "53f5dc8088148479ca112c4c6d0e91cb", | 988 "53f5dc8088148479ca112c4c6d0e91cb", |
976 "4061a876d64d6cec5a38450acf4f245d"), | 989 "4061a876d64d6cec5a38450acf4f245d")); |
977 std::vector<ExternalDecoder>()); | |
978 } | 990 } |
979 | 991 |
980 TEST_F(AcmReceiverBitExactnessOldApi, 32kHzOutput) { | 992 TEST_F(AcmReceiverBitExactnessOldApi, 32kHzOutput) { |
981 Run(32000, PlatformChecksum("eb326547e83292305423b0a7ea57fea1", | 993 Run(32000, PlatformChecksum("eb326547e83292305423b0a7ea57fea1", |
982 "be7fc3140e6b5188c2e5fae0a394543b", | 994 "be7fc3140e6b5188c2e5fae0a394543b", |
983 "eab9a0bff17320d6457d04f4c56563c6", | 995 "eab9a0bff17320d6457d04f4c56563c6", |
984 "b60241ef0bac4a75f66eead04e71bb12"), | 996 "b60241ef0bac4a75f66eead04e71bb12")); |
985 std::vector<ExternalDecoder>()); | |
986 } | 997 } |
987 | 998 |
988 TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutput) { | 999 TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutput) { |
989 Run(48000, PlatformChecksum("7eb79ea39b68472a5b04cf9a56e49cda", | 1000 Run(48000, PlatformChecksum("7eb79ea39b68472a5b04cf9a56e49cda", |
990 "f8cdd6e018688b2fff25c9b865bebdbb", | 1001 "f8cdd6e018688b2fff25c9b865bebdbb", |
991 "2d18f0f06e7e2fc63b74d06e3c58067f", | 1002 "2d18f0f06e7e2fc63b74d06e3c58067f", |
992 "81c3e4d24ebec23ca48f42fbaec4aba0"), | 1003 "81c3e4d24ebec23ca48f42fbaec4aba0")); |
993 std::vector<ExternalDecoder>()); | |
994 } | 1004 } |
995 | 1005 |
996 TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) { | 1006 TEST_F(AcmReceiverBitExactnessOldApi, 48kHzOutputExternalDecoder) { |
997 // Class intended to forward a call from a mock DecodeInternal to Decode on | 1007 class ADFactory : public AudioDecoderFactory { |
998 // the real decoder's Decode. DecodeInternal for the real decoder isn't | |
999 // public. | |
1000 class DecodeForwarder { | |
1001 public: | 1008 public: |
1002 DecodeForwarder(AudioDecoder* decoder) : decoder_(decoder) {} | 1009 ADFactory() |
1003 int Decode(const uint8_t* encoded, | 1010 : mock_decoder_(new MockAudioDecoder()), |
1004 size_t encoded_len, | 1011 pcmu_decoder_(1), |
1005 int sample_rate_hz, | 1012 decode_forwarder_(&pcmu_decoder_), |
1006 int16_t* decoded, | 1013 fact_(CreateBuiltinAudioDecoderFactory()) { |
1007 AudioDecoder::SpeechType* speech_type) { | 1014 // Set expectations on the mock decoder and also delegate the calls to |
1008 return decoder_->Decode(encoded, encoded_len, sample_rate_hz, | 1015 // the real decoder. |
1009 decoder_->PacketDuration(encoded, encoded_len) * | 1016 EXPECT_CALL(*mock_decoder_, IncomingPacket(_, _, _, _, _)) |
1010 decoder_->Channels() * sizeof(int16_t), | 1017 .Times(AtLeast(1)) |
1011 decoded, speech_type); | 1018 .WillRepeatedly( |
| 1019 Invoke(&pcmu_decoder_, &AudioDecoderPcmU::IncomingPacket)); |
| 1020 EXPECT_CALL(*mock_decoder_, SampleRateHz()) |
| 1021 .Times(AtLeast(1)) |
| 1022 .WillRepeatedly( |
| 1023 Invoke(&pcmu_decoder_, &AudioDecoderPcmU::SampleRateHz)); |
| 1024 EXPECT_CALL(*mock_decoder_, Channels()) |
| 1025 .Times(AtLeast(1)) |
| 1026 .WillRepeatedly(Invoke(&pcmu_decoder_, &AudioDecoderPcmU::Channels)); |
| 1027 EXPECT_CALL(*mock_decoder_, DecodeInternal(_, _, _, _, _)) |
| 1028 .Times(AtLeast(1)) |
| 1029 .WillRepeatedly(Invoke(&decode_forwarder_, &DecodeForwarder::Decode)); |
| 1030 EXPECT_CALL(*mock_decoder_, HasDecodePlc()) |
| 1031 .Times(AtLeast(1)) |
| 1032 .WillRepeatedly( |
| 1033 Invoke(&pcmu_decoder_, &AudioDecoderPcmU::HasDecodePlc)); |
| 1034 EXPECT_CALL(*mock_decoder_, PacketDuration(_, _)) |
| 1035 .Times(AtLeast(1)) |
| 1036 .WillRepeatedly( |
| 1037 Invoke(&pcmu_decoder_, &AudioDecoderPcmU::PacketDuration)); |
| 1038 EXPECT_CALL(*mock_decoder_, Die()); |
| 1039 } |
| 1040 std::vector<AudioCodecSpec> GetSupportedDecoders() override { |
| 1041 return fact_->GetSupportedDecoders(); |
| 1042 } |
| 1043 std::unique_ptr<AudioDecoder> MakeAudioDecoder( |
| 1044 const SdpAudioFormat& format) override { |
| 1045 return format.name == "MockPCMu" ? std::move(mock_decoder_) |
| 1046 : fact_->MakeAudioDecoder(format); |
1012 } | 1047 } |
1013 | 1048 |
1014 private: | 1049 private: |
1015 AudioDecoder* const decoder_; | 1050 // Class intended to forward a call from a mock DecodeInternal to Decode on |
| 1051 // the real decoder's Decode. DecodeInternal for the real decoder isn't |
| 1052 // public. |
| 1053 class DecodeForwarder { |
| 1054 public: |
| 1055 DecodeForwarder(AudioDecoder* decoder) : decoder_(decoder) {} |
| 1056 int Decode(const uint8_t* encoded, |
| 1057 size_t encoded_len, |
| 1058 int sample_rate_hz, |
| 1059 int16_t* decoded, |
| 1060 AudioDecoder::SpeechType* speech_type) { |
| 1061 return decoder_->Decode(encoded, encoded_len, sample_rate_hz, |
| 1062 decoder_->PacketDuration(encoded, encoded_len) * |
| 1063 decoder_->Channels() * sizeof(int16_t), |
| 1064 decoded, speech_type); |
| 1065 } |
| 1066 |
| 1067 private: |
| 1068 AudioDecoder* const decoder_; |
| 1069 }; |
| 1070 |
| 1071 std::unique_ptr<MockAudioDecoder> mock_decoder_; |
| 1072 AudioDecoderPcmU pcmu_decoder_; |
| 1073 DecodeForwarder decode_forwarder_; |
| 1074 rtc::scoped_refptr<AudioDecoderFactory> fact_; // Fallback factory. |
1016 }; | 1075 }; |
1017 | 1076 |
1018 AudioDecoderPcmU decoder(1); | 1077 rtc::scoped_refptr<rtc::RefCountedObject<ADFactory>> factory( |
1019 DecodeForwarder decode_forwarder(&decoder); | 1078 new rtc::RefCountedObject<ADFactory>); |
1020 MockAudioDecoder mock_decoder; | |
1021 // Set expectations on the mock decoder and also delegate the calls to the | |
1022 // real decoder. | |
1023 EXPECT_CALL(mock_decoder, IncomingPacket(_, _, _, _, _)) | |
1024 .Times(AtLeast(1)) | |
1025 .WillRepeatedly(Invoke(&decoder, &AudioDecoderPcmU::IncomingPacket)); | |
1026 EXPECT_CALL(mock_decoder, SampleRateHz()) | |
1027 .Times(AtLeast(1)) | |
1028 .WillRepeatedly(Invoke(&decoder, &AudioDecoderPcmU::SampleRateHz)); | |
1029 EXPECT_CALL(mock_decoder, Channels()) | |
1030 .Times(AtLeast(1)) | |
1031 .WillRepeatedly(Invoke(&decoder, &AudioDecoderPcmU::Channels)); | |
1032 EXPECT_CALL(mock_decoder, DecodeInternal(_, _, _, _, _)) | |
1033 .Times(AtLeast(1)) | |
1034 .WillRepeatedly(Invoke(&decode_forwarder, &DecodeForwarder::Decode)); | |
1035 EXPECT_CALL(mock_decoder, HasDecodePlc()) | |
1036 .Times(AtLeast(1)) | |
1037 .WillRepeatedly(Invoke(&decoder, &AudioDecoderPcmU::HasDecodePlc)); | |
1038 EXPECT_CALL(mock_decoder, PacketDuration(_, _)) | |
1039 .Times(AtLeast(1)) | |
1040 .WillRepeatedly(Invoke(&decoder, &AudioDecoderPcmU::PacketDuration)); | |
1041 ExternalDecoder ed; | |
1042 ed.rtp_payload_type = 0; | |
1043 ed.external_decoder = &mock_decoder; | |
1044 ed.sample_rate_hz = 8000; | |
1045 ed.num_channels = 1; | |
1046 ed.name = "MockPCMU"; | |
1047 std::vector<ExternalDecoder> external_decoders; | |
1048 external_decoders.push_back(ed); | |
1049 | |
1050 Run(48000, PlatformChecksum("7eb79ea39b68472a5b04cf9a56e49cda", | 1079 Run(48000, PlatformChecksum("7eb79ea39b68472a5b04cf9a56e49cda", |
1051 "f8cdd6e018688b2fff25c9b865bebdbb", | 1080 "f8cdd6e018688b2fff25c9b865bebdbb", |
1052 "2d18f0f06e7e2fc63b74d06e3c58067f", | 1081 "2d18f0f06e7e2fc63b74d06e3c58067f", |
1053 "81c3e4d24ebec23ca48f42fbaec4aba0"), | 1082 "81c3e4d24ebec23ca48f42fbaec4aba0"), |
1054 external_decoders); | 1083 factory, [](AudioCodingModule* acm) { |
1055 | 1084 acm->RegisterReceiveCodec(0, {"MockPCMu", 8000, 1}); |
1056 EXPECT_CALL(mock_decoder, Die()); | 1085 }); |
1057 } | 1086 } |
1058 #endif | 1087 #endif |
1059 | 1088 |
1060 // This test verifies bit exactness for the send-side of ACM. The test setup is | 1089 // This test verifies bit exactness for the send-side of ACM. The test setup is |
1061 // a chain of three different test classes: | 1090 // a chain of three different test classes: |
1062 // | 1091 // |
1063 // test::AcmSendTest -> AcmSenderBitExactness -> test::AcmReceiveTest | 1092 // test::AcmSendTest -> AcmSenderBitExactness -> test::AcmReceiveTest |
1064 // | 1093 // |
1065 // The receiver side is driving the test by requesting new packets from | 1094 // The receiver side is driving the test by requesting new packets from |
1066 // AcmSenderBitExactness::NextPacket(). This method, in turn, asks for the | 1095 // AcmSenderBitExactness::NextPacket(). This method, in turn, asks for the |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 webrtc::test::OutputPath() + | 1163 webrtc::test::OutputPath() + |
1135 ::testing::UnitTest::GetInstance() | 1164 ::testing::UnitTest::GetInstance() |
1136 ->current_test_info() | 1165 ->current_test_info() |
1137 ->test_case_name() + | 1166 ->test_case_name() + |
1138 "_" + ::testing::UnitTest::GetInstance()->current_test_info()->name() + | 1167 "_" + ::testing::UnitTest::GetInstance()->current_test_info()->name() + |
1139 "_output.pcm"; | 1168 "_output.pcm"; |
1140 test::OutputAudioFile output_file(output_file_name); | 1169 test::OutputAudioFile output_file(output_file_name); |
1141 // Have the output audio sent both to file and to the checksum calculator. | 1170 // Have the output audio sent both to file and to the checksum calculator. |
1142 test::AudioSinkFork output(&audio_checksum, &output_file); | 1171 test::AudioSinkFork output(&audio_checksum, &output_file); |
1143 const int kOutputFreqHz = 8000; | 1172 const int kOutputFreqHz = 8000; |
1144 test::AcmReceiveTestOldApi receive_test( | 1173 test::AcmReceiveTestOldApi receive_test(this, &output, kOutputFreqHz, |
1145 this, &output, kOutputFreqHz, expected_channels); | 1174 expected_channels, |
| 1175 CreateBuiltinAudioDecoderFactory()); |
1146 ASSERT_NO_FATAL_FAILURE(receive_test.RegisterDefaultCodecs()); | 1176 ASSERT_NO_FATAL_FAILURE(receive_test.RegisterDefaultCodecs()); |
1147 | 1177 |
1148 // This is where the actual test is executed. | 1178 // This is where the actual test is executed. |
1149 receive_test.Run(); | 1179 receive_test.Run(); |
1150 | 1180 |
1151 // Extract and verify the audio checksum. | 1181 // Extract and verify the audio checksum. |
1152 std::string checksum_string = audio_checksum.Finish(); | 1182 std::string checksum_string = audio_checksum.Finish(); |
1153 EXPECT_EQ(audio_checksum_ref, checksum_string); | 1183 EXPECT_EQ(audio_checksum_ref, checksum_string); |
1154 | 1184 |
1155 // Extract and verify the payload checksum. | 1185 // Extract and verify the payload checksum. |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 Run(16000, 8000, 1000); | 1835 Run(16000, 8000, 1000); |
1806 } | 1836 } |
1807 | 1837 |
1808 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { | 1838 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { |
1809 Run(8000, 16000, 1000); | 1839 Run(8000, 16000, 1000); |
1810 } | 1840 } |
1811 | 1841 |
1812 #endif | 1842 #endif |
1813 | 1843 |
1814 } // namespace webrtc | 1844 } // namespace webrtc |
OLD | NEW |