diff --git a/.gn b/.gn index 4aa7a76345..28e8fad9c2 100644 --- a/.gn +++ b/.gn @@ -22,6 +22,9 @@ secondary_source = "//build/secondary/" check_targets = [ "//webrtc/api:audio_mixer_api", "//webrtc/api:rtc_stats_api", + "//webrtc/modules/audio_coding:audio_decoder_factory_interface", + "//webrtc/modules/audio_coding:audio_format", + "//webrtc/modules/audio_coding:audio_format_conversion", "//webrtc/modules/audio_coding:g711_test", "//webrtc/modules/audio_coding:g722_test", "//webrtc/modules/audio_coding:ilbc_test", diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn index 6c472a399f..0b08e9079e 100644 --- a/webrtc/modules/BUILD.gn +++ b/webrtc/modules/BUILD.gn @@ -63,6 +63,7 @@ if (rtc_include_tests) { "..:webrtc_common", "../common_video", "../modules/audio_coding", + "../modules/audio_coding:audio_format_conversion", "../modules/rtp_rtcp", "../modules/utility", "../modules/video_coding", diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 078fb4bccc..6f47dcce94 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -39,14 +39,36 @@ audio_coding_deps = audio_codec_deps + [ "../../system_wrappers", ] -rtc_static_library("audio_decoder_factory_interface") { +rtc_static_library("audio_format") { sources = [ - "codecs/audio_decoder_factory.h", "codecs/audio_format.cc", "codecs/audio_format.h", ] deps = [ - "../..:webrtc_common", + "//webrtc:webrtc_common", + ] +} + +rtc_static_library("audio_format_conversion") { + sources = [ + "codecs/audio_format_conversion.cc", + "codecs/audio_format_conversion.h", + ] + deps = [ + ":audio_format", + "//webrtc:webrtc_common", + "//webrtc/base:rtc_base_approved", + ] +} + +rtc_source_set("audio_decoder_factory_interface") { + sources = [ + "codecs/audio_decoder_factory.h", + ] + deps = [ + ":audio_decoder_interface", + ":audio_format", + "//webrtc/base:rtc_base_approved", ] } @@ -934,6 +956,7 @@ if (rtc_include_tests) { deps = [ ":audio_coding", + ":audio_format_conversion", "../../:webrtc_common", "../../system_wrappers", "../../system_wrappers:system_wrappers_default", @@ -959,6 +982,7 @@ if (rtc_include_tests) { deps = [ ":audio_coding", + ":audio_format_conversion", "../../:webrtc_common", "../../system_wrappers", "../../system_wrappers:system_wrappers_default", diff --git a/webrtc/modules/audio_coding/acm2/acm_receive_test.cc b/webrtc/modules/audio_coding/acm2/acm_receive_test.cc index 056ff2273c..c2549323c7 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receive_test.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receive_test.cc @@ -15,6 +15,7 @@ #include +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h" @@ -132,7 +133,9 @@ void AcmReceiveTestOldApi::RegisterDefaultCodecs() { for (int n = 0; n < acm_->NumberOfCodecs(); n++) { ASSERT_EQ(0, acm_->Codec(n, &my_codec_param)) << "Failed to get codec."; if (ModifyAndUseThisCodec(&my_codec_param)) { - ASSERT_EQ(0, acm_->RegisterReceiveCodec(my_codec_param)) + ASSERT_EQ(true, + acm_->RegisterReceiveCodec(my_codec_param.pltype, + CodecInstToSdp(my_codec_param))) << "Couldn't register receive codec.\n"; } } @@ -151,22 +154,14 @@ void AcmReceiveTestOldApi::RegisterNetEqTestCodecs() { my_codec_param.plfreq, my_codec_param.channels, &my_codec_param.pltype)) { - ASSERT_EQ(0, acm_->RegisterReceiveCodec(my_codec_param)) + ASSERT_EQ(true, + acm_->RegisterReceiveCodec(my_codec_param.pltype, + CodecInstToSdp(my_codec_param))) << "Couldn't register receive codec.\n"; } } } -int AcmReceiveTestOldApi::RegisterExternalReceiveCodec( - int rtp_payload_type, - AudioDecoder* external_decoder, - int sample_rate_hz, - int num_channels, - const std::string& name) { - return acm_->RegisterExternalReceiveCodec(rtp_payload_type, external_decoder, - sample_rate_hz, num_channels, name); -} - void AcmReceiveTestOldApi::Run() { for (std::unique_ptr packet(packet_source_->NextPacket()); packet; packet = packet_source_->NextPacket()) { diff --git a/webrtc/modules/audio_coding/acm2/acm_receive_test.h b/webrtc/modules/audio_coding/acm2/acm_receive_test.h index 3145ad3812..834fa5626f 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receive_test.h +++ b/webrtc/modules/audio_coding/acm2/acm_receive_test.h @@ -50,12 +50,6 @@ class AcmReceiveTestOldApi { // files. void RegisterNetEqTestCodecs(); - int RegisterExternalReceiveCodec(int rtp_payload_type, - AudioDecoder* external_decoder, - int sample_rate_hz, - int num_channels, - const std::string& name); - // Runs the test and returns true if successful. void Run(); diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest.cc index b6fcd01b63..863dcd1177 100644 --- a/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest.cc +++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest.cc @@ -21,6 +21,7 @@ #include "webrtc/modules/audio_coding/acm2/acm_send_test.h" #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" @@ -777,7 +778,8 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { // Register iSAC codec in ACM, effectively unregistering the PCM16B codec // registered in AudioCodingModuleTestOldApi::SetUp(); // Only register the decoder for now. The encoder is registered later. - ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); + ASSERT_EQ(true, acm_->RegisterReceiveCodec(codec_.pltype, + CodecInstToSdp(codec_))); } void StartThreads() { diff --git a/webrtc/modules/audio_coding/audio_coding.gypi b/webrtc/modules/audio_coding/audio_coding.gypi index 5f9eb2cdad..a9b9e20e63 100644 --- a/webrtc/modules/audio_coding/audio_coding.gypi +++ b/webrtc/modules/audio_coding/audio_coding.gypi @@ -87,6 +87,8 @@ 'codecs/audio_decoder_factory.h', 'codecs/audio_format.cc', 'codecs/audio_format.h', + 'codecs/audio_format_conversion.cc', + 'codecs/audio_format_conversion.h', ], }, { diff --git a/webrtc/modules/audio_coding/codecs/audio_format_conversion.cc b/webrtc/modules/audio_coding/codecs/audio_format_conversion.cc new file mode 100644 index 0000000000..ef9aa4479b --- /dev/null +++ b/webrtc/modules/audio_coding/codecs/audio_format_conversion.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" + +#include "webrtc/base/checks.h" +#include "webrtc/base/safe_conversions.h" + +namespace webrtc { + +SdpAudioFormat CodecInstToSdp(const CodecInst& ci) { + if (STR_CASE_CMP(ci.plname, "g722") == 0 && ci.plfreq == 16000) { + RTC_CHECK(ci.channels == 1 || ci.channels == 2); + return {"g722", 8000, static_cast(ci.channels)}; + } else if (STR_CASE_CMP(ci.plname, "opus") == 0 && ci.plfreq == 48000) { + RTC_CHECK(ci.channels == 1 || ci.channels == 2); + return {"opus", 48000, 2, {{"stereo", ci.channels == 1 ? "0" : "1"}}}; + } else { + return {ci.plname, ci.plfreq, rtc::checked_cast(ci.channels)}; + } +} + +} // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/audio_format_conversion.h b/webrtc/modules/audio_coding/codecs/audio_format_conversion.h new file mode 100644 index 0000000000..ff71282f7e --- /dev/null +++ b/webrtc/modules/audio_coding/codecs/audio_format_conversion.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_FORMAT_CONVERSION_H_ +#define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_FORMAT_CONVERSION_H_ + +#include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format.h" + +namespace webrtc { + +SdpAudioFormat CodecInstToSdp(const CodecInst& codec_inst); + +} // namespace webrtc + +#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_FORMAT_CONVERSION_H_ diff --git a/webrtc/modules/audio_coding/test/APITest.cc b/webrtc/modules/audio_coding/test/APITest.cc index ffa675c0fa..326a303ea3 100644 --- a/webrtc/modules/audio_coding/test/APITest.cc +++ b/webrtc/modules/audio_coding/test/APITest.cc @@ -23,6 +23,7 @@ #include "webrtc/base/timeutils.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" @@ -141,7 +142,8 @@ int16_t APITest::SetUp() { // Check registration with an already occupied payload type int currentPayloadType = dummyCodec.pltype; dummyCodec.pltype = 97; //lastPayloadType; - CHECK_ERROR(_acmB->RegisterReceiveCodec(dummyCodec)); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(dummyCodec.pltype, + CodecInstToSdp(dummyCodec))); dummyCodec.pltype = currentPayloadType; } @@ -152,7 +154,8 @@ int16_t APITest::SetUp() { AudioCodingModule::Codec(n + 1, &nextCodec); dummyCodec.pltype = nextCodec.pltype; if (!FixedPayloadTypeCodec(nextCodec.plname)) { - _acmB->RegisterReceiveCodec(dummyCodec); + _acmB->RegisterReceiveCodec(dummyCodec.pltype, + CodecInstToSdp(dummyCodec)); } dummyCodec.pltype = currentPayloadType; } @@ -163,14 +166,17 @@ int16_t APITest::SetUp() { AudioCodingModule::Codec(n + 1, &nextCodec); nextCodec.pltype = dummyCodec.pltype; if (!FixedPayloadTypeCodec(nextCodec.plname)) { - CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(nextCodec)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(nextCodec.pltype, + CodecInstToSdp(nextCodec))); CHECK_ERROR_MT(_acmA->UnregisterReceiveCodec(nextCodec.pltype)); } } - CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(dummyCodec)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(dummyCodec.pltype, + CodecInstToSdp(dummyCodec))); printf(" side A done!"); - CHECK_ERROR_MT(_acmB->RegisterReceiveCodec(dummyCodec)); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(dummyCodec.pltype, + CodecInstToSdp(dummyCodec))); printf(" side B done!\n"); if (!strcmp(dummyCodec.plname, "CN")) { @@ -871,7 +877,8 @@ void APITest::TestRegisteration(char sendSide) { "Register receive codec with default Payload, AUDIO BACK.\n"); fflush (stdout); } - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + EXPECT_EQ(true, receiveACM->RegisterReceiveCodec( + myCodec->pltype, CodecInstToSdp(*myCodec))); //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); myEvent->Wait(20); { @@ -884,7 +891,8 @@ void APITest::TestRegisteration(char sendSide) { } } if (i == 32) { - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + EXPECT_EQ(true, receiveACM->RegisterReceiveCodec( + myCodec->pltype, CodecInstToSdp(*myCodec))); { WriteLockScoped wl(_apiTestRWLock); *thereIsDecoder = true; @@ -896,7 +904,8 @@ void APITest::TestRegisteration(char sendSide) { "Register receive codec with fixed Payload, AUDIO BACK.\n"); fflush (stdout); } - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + EXPECT_EQ(true, receiveACM->RegisterReceiveCodec(myCodec->pltype, + CodecInstToSdp(*myCodec))); //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); myEvent->Wait(20); diff --git a/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc b/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc index 2bcae5a425..3eada25c8c 100644 --- a/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc +++ b/webrtc/modules/audio_coding/test/EncodeDecodeTest.cc @@ -17,6 +17,7 @@ #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/trace.h" @@ -132,11 +133,13 @@ void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream, for (int i = 0; i < noOfCodecs; i++) { EXPECT_EQ(0, acm->Codec(i, &recvCodec)); if (recvCodec.channels == channels) - EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec)); + EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, + CodecInstToSdp(recvCodec))); // Forces mono/stereo for Opus. if (!strcmp(recvCodec.plname, "opus")) { recvCodec.channels = channels; - EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec)); + EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, + CodecInstToSdp(recvCodec))); } } diff --git a/webrtc/modules/audio_coding/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/test/TestAllCodecs.cc index e5d9784e9c..6753d8e2c7 100644 --- a/webrtc/modules/audio_coding/test/TestAllCodecs.cc +++ b/webrtc/modules/audio_coding/test/TestAllCodecs.cc @@ -15,6 +15,7 @@ #include #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/test/utility.h" @@ -141,7 +142,8 @@ void TestAllCodecs::Perform() { if (!strcmp(my_codec_param.plname, "opus")) { my_codec_param.channels = 1; } - acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->RegisterReceiveCodec(my_codec_param.pltype, + CodecInstToSdp(my_codec_param)); } // Create and connect the channel diff --git a/webrtc/modules/audio_coding/test/TestRedFec.cc b/webrtc/modules/audio_coding/test/TestRedFec.cc index 4e8b123b78..7c252a13d9 100644 --- a/webrtc/modules/audio_coding/test/TestRedFec.cc +++ b/webrtc/modules/audio_coding/test/TestRedFec.cc @@ -13,6 +13,7 @@ #include #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/trace.h" @@ -77,7 +78,8 @@ void TestRedFec::Perform() { if (!strcmp(myCodecParam.plname, "opus")) { myCodecParam.channels = 1; } - EXPECT_EQ(0, _acmB->RegisterReceiveCodec(myCodecParam)); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(myCodecParam.pltype, + CodecInstToSdp(myCodecParam))); } // Create and connect the channel diff --git a/webrtc/modules/audio_coding/test/TestStereo.cc b/webrtc/modules/audio_coding/test/TestStereo.cc index 572a08c21e..57b7a54c87 100644 --- a/webrtc/modules/audio_coding/test/TestStereo.cc +++ b/webrtc/modules/audio_coding/test/TestStereo.cc @@ -15,6 +15,7 @@ #include #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/trace.h" @@ -171,7 +172,8 @@ void TestStereo::Perform() { CodecInst my_codec_param; for (uint8_t n = 0; n < num_encoders; n++) { EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); - EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param)); + EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( + my_codec_param.pltype, CodecInstToSdp(my_codec_param))); } // Test that unregister all receive codecs works. @@ -183,7 +185,8 @@ void TestStereo::Perform() { // Register all available codes as receiving codecs once more. for (uint8_t n = 0; n < num_encoders; n++) { EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); - EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param)); + EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( + my_codec_param.pltype, CodecInstToSdp(my_codec_param))); } // Create and connect the channel. @@ -597,7 +600,9 @@ void TestStereo::Perform() { EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param)); if (!strcmp(opus_codec_param.plname, "opus")) { opus_codec_param.channels = 1; - EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); + EXPECT_EQ(true, + acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, + CodecInstToSdp(opus_codec_param))); break; } } @@ -630,7 +635,9 @@ void TestStereo::Perform() { " Decode: stereo\n", test_cntr_); } opus_codec_param.channels = 2; - EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); + EXPECT_EQ(true, + acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, + CodecInstToSdp(opus_codec_param))); Run(channel_a2b_, audio_channels, 2); out_file_.Close(); // Decode in mono. @@ -642,7 +649,9 @@ void TestStereo::Perform() { " Decode: mono\n", test_cntr_); } opus_codec_param.channels = 1; - EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param)); + EXPECT_EQ(true, + acm_b_->RegisterReceiveCodec(opus_codec_param.pltype, + CodecInstToSdp(opus_codec_param))); Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); diff --git a/webrtc/modules/audio_coding/test/TestVADDTX.cc b/webrtc/modules/audio_coding/test/TestVADDTX.cc index 505eb13285..dd5b3a76e9 100644 --- a/webrtc/modules/audio_coding/test/TestVADDTX.cc +++ b/webrtc/modules/audio_coding/test/TestVADDTX.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/test/PCMFile.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/test/testsupport/fileutils.h" @@ -73,7 +74,8 @@ TestVadDtx::TestVadDtx() void TestVadDtx::RegisterCodec(CodecInst codec_param) { // Set the codec for sending and receiving. EXPECT_EQ(0, acm_send_->RegisterSendCodec(codec_param)); - EXPECT_EQ(0, acm_receive_->RegisterReceiveCodec(codec_param)); + EXPECT_EQ(true, acm_receive_->RegisterReceiveCodec( + codec_param.pltype, CodecInstToSdp(codec_param))); channel_->SetIsStereo(codec_param.channels > 1); } diff --git a/webrtc/modules/audio_coding/test/TwoWayCommunication.cc b/webrtc/modules/audio_coding/test/TwoWayCommunication.cc index ca2a2124ae..7f2af7d716 100644 --- a/webrtc/modules/audio_coding/test/TwoWayCommunication.cc +++ b/webrtc/modules/audio_coding/test/TwoWayCommunication.cc @@ -21,6 +21,7 @@ #endif #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/modules/audio_coding/test/PCMFile.h" #include "webrtc/modules/audio_coding/test/utility.h" @@ -97,18 +98,22 @@ void TwoWayCommunication::SetUp() { //--- Set A codecs EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); - EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(codecInst_B.pltype, + CodecInstToSdp(codecInst_B))); //--- Set ref-A codecs EXPECT_EQ(0, _acmRefA->RegisterSendCodec(codecInst_A)); - EXPECT_EQ(0, _acmRefA->RegisterReceiveCodec(codecInst_B)); + EXPECT_EQ(true, _acmRefA->RegisterReceiveCodec(codecInst_B.pltype, + CodecInstToSdp(codecInst_B))); //--- Set B codecs EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B)); - EXPECT_EQ(0, _acmB->RegisterReceiveCodec(codecInst_A)); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(codecInst_A.pltype, + CodecInstToSdp(codecInst_A))); //--- Set ref-B codecs EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); - EXPECT_EQ(0, _acmRefB->RegisterReceiveCodec(codecInst_A)); + EXPECT_EQ(true, _acmRefB->RegisterReceiveCodec(codecInst_A.pltype, + CodecInstToSdp(codecInst_A))); uint16_t frequencyHz; @@ -174,19 +179,23 @@ void TwoWayCommunication::SetUpAutotest() { //--- Set A codecs EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); - EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(codecInst_B.pltype, + CodecInstToSdp(codecInst_B))); //--- Set ref-A codecs EXPECT_GT(_acmRefA->RegisterSendCodec(codecInst_A), -1); - EXPECT_GT(_acmRefA->RegisterReceiveCodec(codecInst_B), -1); + EXPECT_EQ(true, _acmRefA->RegisterReceiveCodec(codecInst_B.pltype, + CodecInstToSdp(codecInst_B))); //--- Set B codecs EXPECT_GT(_acmB->RegisterSendCodec(codecInst_B), -1); - EXPECT_GT(_acmB->RegisterReceiveCodec(codecInst_A), -1); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(codecInst_A.pltype, + CodecInstToSdp(codecInst_A))); //--- Set ref-B codecs EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); - EXPECT_EQ(0, _acmRefB->RegisterReceiveCodec(codecInst_A)); + EXPECT_EQ(true, _acmRefB->RegisterReceiveCodec(codecInst_A.pltype, + CodecInstToSdp(codecInst_A))); uint16_t frequencyHz; @@ -292,7 +301,8 @@ void TwoWayCommunication::Perform() { EXPECT_EQ(0, _acmA->InitializeReceiver()); // Re-register codec on side A. if (((secPassed % 7) == 6) && (msecPassed >= 990)) { - EXPECT_EQ(0, _acmA->RegisterReceiveCodec(*codecInst_B)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec( + codecInst_B->pltype, CodecInstToSdp(*codecInst_B))); } } } diff --git a/webrtc/modules/audio_coding/test/delay_test.cc b/webrtc/modules/audio_coding/test/delay_test.cc index 99ec0b82ea..9adeca1e5d 100644 --- a/webrtc/modules/audio_coding/test/delay_test.cc +++ b/webrtc/modules/audio_coding/test/delay_test.cc @@ -17,6 +17,7 @@ #include "gflags/gflags.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/test/Channel.h" @@ -107,8 +108,9 @@ class DelayTest { continue; if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0) continue; - ASSERT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param)) << - "Couldn't register receive codec.\n"; + ASSERT_EQ(true, + acm_b_->RegisterReceiveCodec(my_codec_param.pltype, + CodecInstToSdp(my_codec_param))); } // Create and connect the channel diff --git a/webrtc/modules/audio_coding/test/iSACTest.cc b/webrtc/modules/audio_coding/test/iSACTest.cc index 9729cf817a..6ccdf3c3cf 100644 --- a/webrtc/modules/audio_coding/test/iSACTest.cc +++ b/webrtc/modules/audio_coding/test/iSACTest.cc @@ -24,6 +24,7 @@ #endif #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" @@ -94,10 +95,14 @@ void ISACTest::Setup() { } // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. - EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz)); - EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz)); - EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz)); - EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz)); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype, + CodecInstToSdp(_paramISAC16kHz))); + EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype, + CodecInstToSdp(_paramISAC32kHz))); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC16kHz.pltype, + CodecInstToSdp(_paramISAC16kHz))); + EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC32kHz.pltype, + CodecInstToSdp(_paramISAC32kHz))); //--- Set A-to-B channel _channel_A2B.reset(new Channel); diff --git a/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc b/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc index ca0a240aec..44ef9df7d9 100644 --- a/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc +++ b/webrtc/modules/audio_coding/test/insert_packet_with_timing.cc @@ -14,6 +14,7 @@ #include "gflags/gflags.h" #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/test/Channel.h" #include "webrtc/modules/audio_coding/test/PCMFile.h" @@ -94,7 +95,8 @@ class InsertPacketWithTiming { FLAGS_codec_channels)); ASSERT_EQ(0, receive_acm_->InitializeReceiver()); ASSERT_EQ(0, send_acm_->RegisterSendCodec(codec)); - ASSERT_EQ(0, receive_acm_->RegisterReceiveCodec(codec)); + ASSERT_EQ(true, receive_acm_->RegisterReceiveCodec(codec.pltype, + CodecInstToSdp(codec))); // Set codec-dependent parameters. samples_in_1ms_ = codec.plfreq / 1000; diff --git a/webrtc/modules/audio_coding/test/opus_test.cc b/webrtc/modules/audio_coding/test/opus_test.cc index 4b3cb6ba5a..bb595615d8 100644 --- a/webrtc/modules/audio_coding/test/opus_test.cc +++ b/webrtc/modules/audio_coding/test/opus_test.cc @@ -15,6 +15,7 @@ #include #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/test/TestStereo.h" @@ -94,7 +95,9 @@ void OpusTest::Perform() { int codec_id = acm_receiver_->Codec("opus", 48000, 2); EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); payload_type_ = opus_codec_param.pltype; - EXPECT_EQ(0, acm_receiver_->RegisterReceiveCodec(opus_codec_param)); + EXPECT_EQ(true, + acm_receiver_->RegisterReceiveCodec( + opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); // Create and connect the channel. channel_a2b_ = new TestPackStereo; @@ -159,7 +162,9 @@ void OpusTest::Perform() { // Register Opus mono as receiving codec. opus_codec_param.channels = 1; - EXPECT_EQ(0, acm_receiver_->RegisterReceiveCodec(opus_codec_param)); + EXPECT_EQ(true, + acm_receiver_->RegisterReceiveCodec( + opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); // Run Opus with 2.5 ms frame size. Run(channel_a2b_, audio_channels, 32000, 120); diff --git a/webrtc/modules/audio_coding/test/target_delay_unittest.cc b/webrtc/modules/audio_coding/test/target_delay_unittest.cc index 2939453e4f..1b400262ae 100644 --- a/webrtc/modules/audio_coding/test/target_delay_unittest.cc +++ b/webrtc/modules/audio_coding/test/target_delay_unittest.cc @@ -30,12 +30,12 @@ class TargetDelayTest : public ::testing::Test { void SetUp() { EXPECT_TRUE(acm_.get() != NULL); - CodecInst codec; - ASSERT_EQ(0, AudioCodingModule::Codec("L16", &codec, kSampleRateHz, 1)); ASSERT_EQ(0, acm_->InitializeReceiver()); - ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec)); + constexpr int pltype = 108; + ASSERT_EQ(true, + acm_->RegisterReceiveCodec(pltype, {"L16", kSampleRateHz, 1})); - rtp_info_.header.payloadType = codec.pltype; + rtp_info_.header.payloadType = pltype; rtp_info_.header.timestamp = 0; rtp_info_.header.ssrc = 0x12345678; rtp_info_.header.markerBit = false; diff --git a/webrtc/modules/utility/source/coder.cc b/webrtc/modules/utility/source/coder.cc index f72d03b887..71f969097f 100644 --- a/webrtc/modules/utility/source/coder.cc +++ b/webrtc/modules/utility/source/coder.cc @@ -9,6 +9,7 @@ */ #include "webrtc/common_types.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/utility/source/coder.h" @@ -45,9 +46,8 @@ int32_t AudioCoder::SetEncodeCodec(const CodecInst& codec_inst) { } int32_t AudioCoder::SetDecodeCodec(const CodecInst& codec_inst) { - if (acm_->RegisterReceiveCodec(codec_inst, [&] { - return rent_a_codec_.RentIsacDecoder(codec_inst.plfreq); - }) == -1) { + if (!acm_->RegisterReceiveCodec(codec_inst.pltype, + CodecInstToSdp(codec_inst))) { return -1; } memcpy(&receive_codec_, &codec_inst, sizeof(CodecInst)); diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index 2b5d029b2f..9a3894859c 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -93,6 +93,7 @@ rtc_static_library("voice_engine") { "../common_audio", "../logging:rtc_event_log_api", "../modules/audio_coding:audio_decoder_factory_interface", + "../modules/audio_coding:audio_format_conversion", "../modules/audio_coding:builtin_audio_decoder_factory", "../modules/audio_coding:rent_a_codec", "../modules/audio_conference_mixer", diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 6d053323da..deea057727 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -22,6 +22,7 @@ #include "webrtc/base/timeutils.h" #include "webrtc/config.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" +#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/include/module_common_types.h" @@ -48,14 +49,6 @@ namespace { constexpr int64_t kMaxRetransmissionWindowMs = 1000; constexpr int64_t kMinRetransmissionWindowMs = 30; -bool RegisterReceiveCodec(std::unique_ptr* acm, - acm2::RentACodec* rac, - const CodecInst& ci) { - const int result = (*acm)->RegisterReceiveCodec( - ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); - return result == 0; -} - } // namespace const int kTelephoneEventAttenuationdB = 10; @@ -498,7 +491,8 @@ int32_t Channel::OnInitializeDecoder( receiveCodec.pacsize = dummyCodec.pacsize; // Register the new codec to the ACM - if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, receiveCodec)) { + if (!audio_coding_->RegisterReceiveCodec(receiveCodec.pltype, + CodecInstToSdp(receiveCodec))) { WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::OnInitializeDecoder() invalid codec (" "pt=%d, name=%s) received - 1", @@ -1066,7 +1060,8 @@ int32_t Channel::Init() { // Register default PT for outband 'telephone-event' if (!STR_CASE_CMP(codec.plname, "telephone-event")) { if (_rtpRtcpModule->RegisterSendPayload(codec) == -1 || - !RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { + !audio_coding_->RegisterReceiveCodec(codec.pltype, + CodecInstToSdp(codec))) { WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::Init() failed to register outband " "'telephone-event' (%d/%d) correctly", @@ -1077,7 +1072,8 @@ int32_t Channel::Init() { if (!STR_CASE_CMP(codec.plname, "CN")) { if (!codec_manager_.RegisterEncoder(codec) || !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get()) || - !RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec) || + !audio_coding_->RegisterReceiveCodec(codec.pltype, + CodecInstToSdp(codec)) || _rtpRtcpModule->RegisterSendPayload(codec) == -1) { WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::Init() failed to register CN (%d/%d) " @@ -1425,9 +1421,11 @@ int32_t Channel::SetRecPayloadType(const CodecInst& codec) { return -1; } } - if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { + if (!audio_coding_->RegisterReceiveCodec(codec.pltype, + CodecInstToSdp(codec))) { audio_coding_->UnregisterReceiveCodec(codec.pltype); - if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { + if (!audio_coding_->RegisterReceiveCodec(codec.pltype, + CodecInstToSdp(codec))) { _engineStatisticsPtr->SetLastError( VE_AUDIO_CODING_MODULE_ERROR, kTraceError, "SetRecPayloadType() ACM registration failed - 1");