Stop using old AudioCodingModule::RegisterReceiveCodec overloads

BUG=webrtc:5801

Review-Url: https://codereview.webrtc.org/2388153004
Cr-Commit-Position: refs/heads/master@{#14753}
This commit is contained in:
kwiberg 2016-10-24 13:47:09 -07:00 committed by Commit bot
parent 88b7074745
commit da2bf4e150
24 changed files with 202 additions and 78 deletions

3
.gn
View File

@ -22,6 +22,9 @@ secondary_source = "//build/secondary/"
check_targets = [ check_targets = [
"//webrtc/api:audio_mixer_api", "//webrtc/api:audio_mixer_api",
"//webrtc/api:rtc_stats_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:g711_test",
"//webrtc/modules/audio_coding:g722_test", "//webrtc/modules/audio_coding:g722_test",
"//webrtc/modules/audio_coding:ilbc_test", "//webrtc/modules/audio_coding:ilbc_test",

View File

@ -63,6 +63,7 @@ if (rtc_include_tests) {
"..:webrtc_common", "..:webrtc_common",
"../common_video", "../common_video",
"../modules/audio_coding", "../modules/audio_coding",
"../modules/audio_coding:audio_format_conversion",
"../modules/rtp_rtcp", "../modules/rtp_rtcp",
"../modules/utility", "../modules/utility",
"../modules/video_coding", "../modules/video_coding",

View File

@ -39,14 +39,36 @@ audio_coding_deps = audio_codec_deps + [
"../../system_wrappers", "../../system_wrappers",
] ]
rtc_static_library("audio_decoder_factory_interface") { rtc_static_library("audio_format") {
sources = [ sources = [
"codecs/audio_decoder_factory.h",
"codecs/audio_format.cc", "codecs/audio_format.cc",
"codecs/audio_format.h", "codecs/audio_format.h",
] ]
deps = [ 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 = [ deps = [
":audio_coding", ":audio_coding",
":audio_format_conversion",
"../../:webrtc_common", "../../:webrtc_common",
"../../system_wrappers", "../../system_wrappers",
"../../system_wrappers:system_wrappers_default", "../../system_wrappers:system_wrappers_default",
@ -959,6 +982,7 @@ if (rtc_include_tests) {
deps = [ deps = [
":audio_coding", ":audio_coding",
":audio_format_conversion",
"../../:webrtc_common", "../../:webrtc_common",
"../../system_wrappers", "../../system_wrappers",
"../../system_wrappers:system_wrappers_default", "../../system_wrappers:system_wrappers_default",

View File

@ -15,6 +15,7 @@
#include <memory> #include <memory>
#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/codecs/builtin_audio_decoder_factory.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
#include "webrtc/modules/audio_coding/neteq/tools/audio_sink.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++) { for (int n = 0; n < acm_->NumberOfCodecs(); n++) {
ASSERT_EQ(0, acm_->Codec(n, &my_codec_param)) << "Failed to get codec."; ASSERT_EQ(0, acm_->Codec(n, &my_codec_param)) << "Failed to get codec.";
if (ModifyAndUseThisCodec(&my_codec_param)) { 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"; << "Couldn't register receive codec.\n";
} }
} }
@ -151,22 +154,14 @@ void AcmReceiveTestOldApi::RegisterNetEqTestCodecs() {
my_codec_param.plfreq, my_codec_param.plfreq,
my_codec_param.channels, my_codec_param.channels,
&my_codec_param.pltype)) { &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"; << "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() { void AcmReceiveTestOldApi::Run() {
for (std::unique_ptr<Packet> packet(packet_source_->NextPacket()); packet; for (std::unique_ptr<Packet> packet(packet_source_->NextPacket()); packet;
packet = packet_source_->NextPacket()) { packet = packet_source_->NextPacket()) {

View File

@ -50,12 +50,6 @@ class AcmReceiveTestOldApi {
// files. // files.
void RegisterNetEqTestCodecs(); 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. // Runs the test and returns true if successful.
void Run(); void Run();

View File

@ -21,6 +21,7 @@
#include "webrtc/modules/audio_coding/acm2/acm_send_test.h" #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/builtin_audio_decoder_factory.h"
#include "webrtc/modules/audio_coding/codecs/audio_encoder.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_decoder_pcm.h"
#include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_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" #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 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec
// registered in AudioCodingModuleTestOldApi::SetUp(); // registered in AudioCodingModuleTestOldApi::SetUp();
// Only register the decoder for now. The encoder is registered later. // 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() { void StartThreads() {

View File

@ -87,6 +87,8 @@
'codecs/audio_decoder_factory.h', 'codecs/audio_decoder_factory.h',
'codecs/audio_format.cc', 'codecs/audio_format.cc',
'codecs/audio_format.h', 'codecs/audio_format.h',
'codecs/audio_format_conversion.cc',
'codecs/audio_format_conversion.h',
], ],
}, },
{ {

View File

@ -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<int>(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<int>(ci.channels)};
}
}
} // namespace webrtc

View File

@ -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_

View File

@ -23,6 +23,7 @@
#include "webrtc/base/timeutils.h" #include "webrtc/base/timeutils.h"
#include "webrtc/common_types.h" #include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/acm2/acm_common_defs.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/modules/audio_coding/test/utility.h"
#include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/trace.h" #include "webrtc/system_wrappers/include/trace.h"
@ -141,7 +142,8 @@ int16_t APITest::SetUp() {
// Check registration with an already occupied payload type // Check registration with an already occupied payload type
int currentPayloadType = dummyCodec.pltype; int currentPayloadType = dummyCodec.pltype;
dummyCodec.pltype = 97; //lastPayloadType; dummyCodec.pltype = 97; //lastPayloadType;
CHECK_ERROR(_acmB->RegisterReceiveCodec(dummyCodec)); EXPECT_EQ(true, _acmB->RegisterReceiveCodec(dummyCodec.pltype,
CodecInstToSdp(dummyCodec)));
dummyCodec.pltype = currentPayloadType; dummyCodec.pltype = currentPayloadType;
} }
@ -152,7 +154,8 @@ int16_t APITest::SetUp() {
AudioCodingModule::Codec(n + 1, &nextCodec); AudioCodingModule::Codec(n + 1, &nextCodec);
dummyCodec.pltype = nextCodec.pltype; dummyCodec.pltype = nextCodec.pltype;
if (!FixedPayloadTypeCodec(nextCodec.plname)) { if (!FixedPayloadTypeCodec(nextCodec.plname)) {
_acmB->RegisterReceiveCodec(dummyCodec); _acmB->RegisterReceiveCodec(dummyCodec.pltype,
CodecInstToSdp(dummyCodec));
} }
dummyCodec.pltype = currentPayloadType; dummyCodec.pltype = currentPayloadType;
} }
@ -163,14 +166,17 @@ int16_t APITest::SetUp() {
AudioCodingModule::Codec(n + 1, &nextCodec); AudioCodingModule::Codec(n + 1, &nextCodec);
nextCodec.pltype = dummyCodec.pltype; nextCodec.pltype = dummyCodec.pltype;
if (!FixedPayloadTypeCodec(nextCodec.plname)) { 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->UnregisterReceiveCodec(nextCodec.pltype));
} }
} }
CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(dummyCodec)); EXPECT_EQ(true, _acmA->RegisterReceiveCodec(dummyCodec.pltype,
CodecInstToSdp(dummyCodec)));
printf(" side A done!"); printf(" side A done!");
CHECK_ERROR_MT(_acmB->RegisterReceiveCodec(dummyCodec)); EXPECT_EQ(true, _acmB->RegisterReceiveCodec(dummyCodec.pltype,
CodecInstToSdp(dummyCodec)));
printf(" side B done!\n"); printf(" side B done!\n");
if (!strcmp(dummyCodec.plname, "CN")) { if (!strcmp(dummyCodec.plname, "CN")) {
@ -871,7 +877,8 @@ void APITest::TestRegisteration(char sendSide) {
"Register receive codec with default Payload, AUDIO BACK.\n"); "Register receive codec with default Payload, AUDIO BACK.\n");
fflush (stdout); fflush (stdout);
} }
CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); EXPECT_EQ(true, receiveACM->RegisterReceiveCodec(
myCodec->pltype, CodecInstToSdp(*myCodec)));
//CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec));
myEvent->Wait(20); myEvent->Wait(20);
{ {
@ -884,7 +891,8 @@ void APITest::TestRegisteration(char sendSide) {
} }
} }
if (i == 32) { if (i == 32) {
CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); EXPECT_EQ(true, receiveACM->RegisterReceiveCodec(
myCodec->pltype, CodecInstToSdp(*myCodec)));
{ {
WriteLockScoped wl(_apiTestRWLock); WriteLockScoped wl(_apiTestRWLock);
*thereIsDecoder = true; *thereIsDecoder = true;
@ -896,7 +904,8 @@ void APITest::TestRegisteration(char sendSide) {
"Register receive codec with fixed Payload, AUDIO BACK.\n"); "Register receive codec with fixed Payload, AUDIO BACK.\n");
fflush (stdout); 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->UnregisterReceiveCodec(myCodec->pltype));
//CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
myEvent->Wait(20); myEvent->Wait(20);

View File

@ -17,6 +17,7 @@
#include "webrtc/common_types.h" #include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/acm2/acm_common_defs.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.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
#include "webrtc/system_wrappers/include/trace.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++) { for (int i = 0; i < noOfCodecs; i++) {
EXPECT_EQ(0, acm->Codec(i, &recvCodec)); EXPECT_EQ(0, acm->Codec(i, &recvCodec));
if (recvCodec.channels == channels) if (recvCodec.channels == channels)
EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec)); EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype,
CodecInstToSdp(recvCodec)));
// Forces mono/stereo for Opus. // Forces mono/stereo for Opus.
if (!strcmp(recvCodec.plname, "opus")) { if (!strcmp(recvCodec.plname, "opus")) {
recvCodec.channels = channels; recvCodec.channels = channels;
EXPECT_EQ(0, acm->RegisterReceiveCodec(recvCodec)); EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype,
CodecInstToSdp(recvCodec)));
} }
} }

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include "webrtc/common_types.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/include/audio_coding_module.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
@ -141,7 +142,8 @@ void TestAllCodecs::Perform() {
if (!strcmp(my_codec_param.plname, "opus")) { if (!strcmp(my_codec_param.plname, "opus")) {
my_codec_param.channels = 1; 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 // Create and connect the channel

View File

@ -13,6 +13,7 @@
#include <assert.h> #include <assert.h>
#include "webrtc/common_types.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_typedefs.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
#include "webrtc/system_wrappers/include/trace.h" #include "webrtc/system_wrappers/include/trace.h"
@ -77,7 +78,8 @@ void TestRedFec::Perform() {
if (!strcmp(myCodecParam.plname, "opus")) { if (!strcmp(myCodecParam.plname, "opus")) {
myCodecParam.channels = 1; myCodecParam.channels = 1;
} }
EXPECT_EQ(0, _acmB->RegisterReceiveCodec(myCodecParam)); EXPECT_EQ(true, _acmB->RegisterReceiveCodec(myCodecParam.pltype,
CodecInstToSdp(myCodecParam)));
} }
// Create and connect the channel // Create and connect the channel

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include "webrtc/common_types.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_typedefs.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
#include "webrtc/system_wrappers/include/trace.h" #include "webrtc/system_wrappers/include/trace.h"
@ -171,7 +172,8 @@ void TestStereo::Perform() {
CodecInst my_codec_param; CodecInst my_codec_param;
for (uint8_t n = 0; n < num_encoders; n++) { for (uint8_t n = 0; n < num_encoders; n++) {
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); 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. // Test that unregister all receive codecs works.
@ -183,7 +185,8 @@ void TestStereo::Perform() {
// Register all available codes as receiving codecs once more. // Register all available codes as receiving codecs once more.
for (uint8_t n = 0; n < num_encoders; n++) { for (uint8_t n = 0; n < num_encoders; n++) {
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); 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. // Create and connect the channel.
@ -597,7 +600,9 @@ void TestStereo::Perform() {
EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param)); EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
if (!strcmp(opus_codec_param.plname, "opus")) { if (!strcmp(opus_codec_param.plname, "opus")) {
opus_codec_param.channels = 1; 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; break;
} }
} }
@ -630,7 +635,9 @@ void TestStereo::Perform() {
" Decode: stereo\n", test_cntr_); " Decode: stereo\n", test_cntr_);
} }
opus_codec_param.channels = 2; 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); Run(channel_a2b_, audio_channels, 2);
out_file_.Close(); out_file_.Close();
// Decode in mono. // Decode in mono.
@ -642,7 +649,9 @@ void TestStereo::Perform() {
" Decode: mono\n", test_cntr_); " Decode: mono\n", test_cntr_);
} }
opus_codec_param.channels = 1; 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); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();

View File

@ -12,6 +12,7 @@
#include <string> #include <string>
#include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h"
#include "webrtc/modules/audio_coding/test/PCMFile.h" #include "webrtc/modules/audio_coding/test/PCMFile.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
#include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/fileutils.h"
@ -73,7 +74,8 @@ TestVadDtx::TestVadDtx()
void TestVadDtx::RegisterCodec(CodecInst codec_param) { void TestVadDtx::RegisterCodec(CodecInst codec_param) {
// Set the codec for sending and receiving. // Set the codec for sending and receiving.
EXPECT_EQ(0, acm_send_->RegisterSendCodec(codec_param)); 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); channel_->SetIsStereo(codec_param.channels > 1);
} }

View File

@ -21,6 +21,7 @@
#endif #endif
#include "webrtc/common_types.h" #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/codecs/builtin_audio_decoder_factory.h"
#include "webrtc/modules/audio_coding/test/PCMFile.h" #include "webrtc/modules/audio_coding/test/PCMFile.h"
#include "webrtc/modules/audio_coding/test/utility.h" #include "webrtc/modules/audio_coding/test/utility.h"
@ -97,18 +98,22 @@ void TwoWayCommunication::SetUp() {
//--- Set A codecs //--- Set A codecs
EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); 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 //--- Set ref-A codecs
EXPECT_EQ(0, _acmRefA->RegisterSendCodec(codecInst_A)); 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 //--- Set B codecs
EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B)); 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 //--- Set ref-B codecs
EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); 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; uint16_t frequencyHz;
@ -174,19 +179,23 @@ void TwoWayCommunication::SetUpAutotest() {
//--- Set A codecs //--- Set A codecs
EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); 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 //--- Set ref-A codecs
EXPECT_GT(_acmRefA->RegisterSendCodec(codecInst_A), -1); 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 //--- Set B codecs
EXPECT_GT(_acmB->RegisterSendCodec(codecInst_B), -1); 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 //--- Set ref-B codecs
EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); 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; uint16_t frequencyHz;
@ -292,7 +301,8 @@ void TwoWayCommunication::Perform() {
EXPECT_EQ(0, _acmA->InitializeReceiver()); EXPECT_EQ(0, _acmA->InitializeReceiver());
// Re-register codec on side A. // Re-register codec on side A.
if (((secPassed % 7) == 6) && (msecPassed >= 990)) { if (((secPassed % 7) == 6) && (msecPassed >= 990)) {
EXPECT_EQ(0, _acmA->RegisterReceiveCodec(*codecInst_B)); EXPECT_EQ(true, _acmA->RegisterReceiveCodec(
codecInst_B->pltype, CodecInstToSdp(*codecInst_B)));
} }
} }
} }

View File

@ -17,6 +17,7 @@
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "webrtc/common_types.h" #include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/acm2/acm_common_defs.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.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/test/Channel.h" #include "webrtc/modules/audio_coding/test/Channel.h"
@ -107,8 +108,9 @@ class DelayTest {
continue; continue;
if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0) if (STR_CASE_CMP(my_codec_param.plname, "telephone-event") == 0)
continue; continue;
ASSERT_EQ(0, acm_b_->RegisterReceiveCodec(my_codec_param)) << ASSERT_EQ(true,
"Couldn't register receive codec.\n"; acm_b_->RegisterReceiveCodec(my_codec_param.pltype,
CodecInstToSdp(my_codec_param)));
} }
// Create and connect the channel // Create and connect the channel

View File

@ -24,6 +24,7 @@
#endif #endif
#include "webrtc/modules/audio_coding/acm2/acm_common_defs.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/modules/audio_coding/test/utility.h"
#include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/trace.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. // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz)); EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype,
EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz)); CodecInstToSdp(_paramISAC16kHz)));
EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz)); EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype,
EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz)); 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 //--- Set A-to-B channel
_channel_A2B.reset(new Channel); _channel_A2B.reset(new Channel);

View File

@ -14,6 +14,7 @@
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "webrtc/common_types.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/include/audio_coding_module.h"
#include "webrtc/modules/audio_coding/test/Channel.h" #include "webrtc/modules/audio_coding/test/Channel.h"
#include "webrtc/modules/audio_coding/test/PCMFile.h" #include "webrtc/modules/audio_coding/test/PCMFile.h"
@ -94,7 +95,8 @@ class InsertPacketWithTiming {
FLAGS_codec_channels)); FLAGS_codec_channels));
ASSERT_EQ(0, receive_acm_->InitializeReceiver()); ASSERT_EQ(0, receive_acm_->InitializeReceiver());
ASSERT_EQ(0, send_acm_->RegisterSendCodec(codec)); 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. // Set codec-dependent parameters.
samples_in_1ms_ = codec.plfreq / 1000; samples_in_1ms_ = codec.plfreq / 1000;

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include "webrtc/common_types.h" #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/codecs/opus/opus_interface.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/test/TestStereo.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); int codec_id = acm_receiver_->Codec("opus", 48000, 2);
EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param));
payload_type_ = opus_codec_param.pltype; 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. // Create and connect the channel.
channel_a2b_ = new TestPackStereo; channel_a2b_ = new TestPackStereo;
@ -159,7 +162,9 @@ void OpusTest::Perform() {
// Register Opus mono as receiving codec. // Register Opus mono as receiving codec.
opus_codec_param.channels = 1; 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 Opus with 2.5 ms frame size.
Run(channel_a2b_, audio_channels, 32000, 120); Run(channel_a2b_, audio_channels, 32000, 120);

View File

@ -30,12 +30,12 @@ class TargetDelayTest : public ::testing::Test {
void SetUp() { void SetUp() {
EXPECT_TRUE(acm_.get() != NULL); 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_->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.timestamp = 0;
rtp_info_.header.ssrc = 0x12345678; rtp_info_.header.ssrc = 0x12345678;
rtp_info_.header.markerBit = false; rtp_info_.header.markerBit = false;

View File

@ -9,6 +9,7 @@
*/ */
#include "webrtc/common_types.h" #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/codecs/builtin_audio_decoder_factory.h"
#include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/include/module_common_types.h"
#include "webrtc/modules/utility/source/coder.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) { int32_t AudioCoder::SetDecodeCodec(const CodecInst& codec_inst) {
if (acm_->RegisterReceiveCodec(codec_inst, [&] { if (!acm_->RegisterReceiveCodec(codec_inst.pltype,
return rent_a_codec_.RentIsacDecoder(codec_inst.plfreq); CodecInstToSdp(codec_inst))) {
}) == -1) {
return -1; return -1;
} }
memcpy(&receive_codec_, &codec_inst, sizeof(CodecInst)); memcpy(&receive_codec_, &codec_inst, sizeof(CodecInst));

View File

@ -93,6 +93,7 @@ rtc_static_library("voice_engine") {
"../common_audio", "../common_audio",
"../logging:rtc_event_log_api", "../logging:rtc_event_log_api",
"../modules/audio_coding:audio_decoder_factory_interface", "../modules/audio_coding:audio_decoder_factory_interface",
"../modules/audio_coding:audio_format_conversion",
"../modules/audio_coding:builtin_audio_decoder_factory", "../modules/audio_coding:builtin_audio_decoder_factory",
"../modules/audio_coding:rent_a_codec", "../modules/audio_coding:rent_a_codec",
"../modules/audio_conference_mixer", "../modules/audio_conference_mixer",

View File

@ -22,6 +22,7 @@
#include "webrtc/base/timeutils.h" #include "webrtc/base/timeutils.h"
#include "webrtc/config.h" #include "webrtc/config.h"
#include "webrtc/logging/rtc_event_log/rtc_event_log.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_device/include/audio_device.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/include/module_common_types.h"
@ -48,14 +49,6 @@ namespace {
constexpr int64_t kMaxRetransmissionWindowMs = 1000; constexpr int64_t kMaxRetransmissionWindowMs = 1000;
constexpr int64_t kMinRetransmissionWindowMs = 30; constexpr int64_t kMinRetransmissionWindowMs = 30;
bool RegisterReceiveCodec(std::unique_ptr<AudioCodingModule>* acm,
acm2::RentACodec* rac,
const CodecInst& ci) {
const int result = (*acm)->RegisterReceiveCodec(
ci, [&] { return rac->RentIsacDecoder(ci.plfreq); });
return result == 0;
}
} // namespace } // namespace
const int kTelephoneEventAttenuationdB = 10; const int kTelephoneEventAttenuationdB = 10;
@ -498,7 +491,8 @@ int32_t Channel::OnInitializeDecoder(
receiveCodec.pacsize = dummyCodec.pacsize; receiveCodec.pacsize = dummyCodec.pacsize;
// Register the new codec to the ACM // 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), WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::OnInitializeDecoder() invalid codec (" "Channel::OnInitializeDecoder() invalid codec ("
"pt=%d, name=%s) received - 1", "pt=%d, name=%s) received - 1",
@ -1066,7 +1060,8 @@ int32_t Channel::Init() {
// Register default PT for outband 'telephone-event' // Register default PT for outband 'telephone-event'
if (!STR_CASE_CMP(codec.plname, "telephone-event")) { if (!STR_CASE_CMP(codec.plname, "telephone-event")) {
if (_rtpRtcpModule->RegisterSendPayload(codec) == -1 || 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), WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::Init() failed to register outband " "Channel::Init() failed to register outband "
"'telephone-event' (%d/%d) correctly", "'telephone-event' (%d/%d) correctly",
@ -1077,7 +1072,8 @@ int32_t Channel::Init() {
if (!STR_CASE_CMP(codec.plname, "CN")) { if (!STR_CASE_CMP(codec.plname, "CN")) {
if (!codec_manager_.RegisterEncoder(codec) || if (!codec_manager_.RegisterEncoder(codec) ||
!codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get()) || !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) { _rtpRtcpModule->RegisterSendPayload(codec) == -1) {
WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::Init() failed to register CN (%d/%d) " "Channel::Init() failed to register CN (%d/%d) "
@ -1425,9 +1421,11 @@ int32_t Channel::SetRecPayloadType(const CodecInst& codec) {
return -1; return -1;
} }
} }
if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { if (!audio_coding_->RegisterReceiveCodec(codec.pltype,
CodecInstToSdp(codec))) {
audio_coding_->UnregisterReceiveCodec(codec.pltype); audio_coding_->UnregisterReceiveCodec(codec.pltype);
if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { if (!audio_coding_->RegisterReceiveCodec(codec.pltype,
CodecInstToSdp(codec))) {
_engineStatisticsPtr->SetLastError( _engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError, VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetRecPayloadType() ACM registration failed - 1"); "SetRecPayloadType() ACM registration failed - 1");