diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc index f0caacce10..6434483340 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc @@ -93,9 +93,9 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback, if (timestamp_ == 0) { // This is the first time inserting audio. ASSERT_EQ(0, acm_->RegisterSendCodec(codec)); } else { - CodecInst current_codec; - ASSERT_EQ(0, acm_->SendCodec(¤t_codec)); - if (!CodecsEqual(codec, current_codec)) + auto current_codec = acm_->SendCodec(); + ASSERT_TRUE(current_codec); + if (!CodecsEqual(codec, *current_codec)) ASSERT_EQ(0, acm_->RegisterSendCodec(codec)); } AudioFrame frame; diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc index dfd777c7ad..8f2d6f2a82 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc @@ -206,9 +206,9 @@ void AudioCodingModuleImpl::RegisterExternalSendCodec( } // Get current send codec. -int AudioCodingModuleImpl::SendCodec(CodecInst* current_codec) const { +rtc::Maybe AudioCodingModuleImpl::SendCodec() const { CriticalSectionScoped lock(acm_crit_sect_.get()); - return codec_manager_.GetCodecInst(current_codec); + return codec_manager_.GetCodecInst(); } // Get current send frequency. diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h index a512cc75b2..034211dc59 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h @@ -48,7 +48,7 @@ class AudioCodingModuleImpl final : public AudioCodingModule { AudioEncoder* external_speech_encoder) override; // Get current send codec. - int SendCodec(CodecInst* current_codec) const override; + rtc::Maybe SendCodec() const override; // Get current send frequency. int SendFrequency() const override; diff --git a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc index fce6bd7a08..a1303262cd 100644 --- a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc +++ b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc @@ -343,7 +343,7 @@ void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt); } -int CodecManager::GetCodecInst(CodecInst* current_codec) const { +rtc::Maybe CodecManager::GetCodecInst() const { int dummy_id = 0; WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, "SendCodec()"); @@ -351,10 +351,9 @@ int CodecManager::GetCodecInst(CodecInst* current_codec) const { if (!codec_owner_.Encoder()) { WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, "SendCodec Failed, no codec is registered"); - return -1; + return rtc::Maybe(); } - *current_codec = send_codec_inst_; - return 0; + return rtc::Maybe(send_codec_inst_); } bool CodecManager::SetCopyRed(bool enable) { diff --git a/webrtc/modules/audio_coding/main/acm2/codec_manager.h b/webrtc/modules/audio_coding/main/acm2/codec_manager.h index c6c262ea26..26b5a2802e 100644 --- a/webrtc/modules/audio_coding/main/acm2/codec_manager.h +++ b/webrtc/modules/audio_coding/main/acm2/codec_manager.h @@ -12,6 +12,7 @@ #define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_CODEC_MANAGER_H_ #include "webrtc/base/constructormagic.h" +#include "webrtc/base/maybe.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h" @@ -34,7 +35,7 @@ class CodecManager final { void RegisterEncoder(AudioEncoder* external_speech_encoder); - int GetCodecInst(CodecInst* current_codec) const; + rtc::Maybe GetCodecInst() const; bool SetCopyRed(bool enable); diff --git a/webrtc/modules/audio_coding/main/include/audio_coding_module.h b/webrtc/modules/audio_coding/main/include/audio_coding_module.h index 660fbeed0a..1792a25c1b 100644 --- a/webrtc/modules/audio_coding/main/include/audio_coding_module.h +++ b/webrtc/modules/audio_coding/main/include/audio_coding_module.h @@ -13,6 +13,7 @@ #include +#include "webrtc/base/maybe.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" #include "webrtc/modules/audio_coding/main/include/audio_coding_module_typedefs.h" @@ -210,14 +211,10 @@ class AudioCodingModule { // int32_t SendCodec() // Get parameters for the codec currently registered as send codec. // - // Output: - // -current_send_codec : parameters of the send codec. - // // Return value: - // -1 if failed to get send codec, - // 0 if succeeded. + // The send codec, or nothing if we don't have one // - virtual int32_t SendCodec(CodecInst* current_send_codec) const = 0; + virtual rtc::Maybe SendCodec() const = 0; /////////////////////////////////////////////////////////////////////////// // int32_t SendFrequency() diff --git a/webrtc/modules/audio_coding/main/test/APITest.cc b/webrtc/modules/audio_coding/main/test/APITest.cc index 1313f35332..81880bee1f 100644 --- a/webrtc/modules/audio_coding/main/test/APITest.cc +++ b/webrtc/modules/audio_coding/main/test/APITest.cc @@ -823,9 +823,11 @@ void APITest::TestRegisteration(char sendSide) { exit(-1); } - CodecInst myCodec; - if (sendACM->SendCodec(&myCodec) < 0) { - AudioCodingModule::Codec(_codecCntrA, &myCodec); + auto myCodec = sendACM->SendCodec(); + if (!myCodec) { + CodecInst ci; + AudioCodingModule::Codec(_codecCntrA, &ci); + myCodec = rtc::Maybe(ci); } if (!_randomTest) { @@ -837,12 +839,12 @@ void APITest::TestRegisteration(char sendSide) { *thereIsDecoder = false; } //myEvent->Wait(20); - CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype)); + CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); Wait(1000); - int currentPayload = myCodec.pltype; + int currentPayload = myCodec->pltype; - if (!FixedPayloadTypeCodec(myCodec.plname)) { + if (!FixedPayloadTypeCodec(myCodec->plname)) { int32_t i; for (i = 0; i < 32; i++) { if (!_payloadUsed[i]) { @@ -850,9 +852,9 @@ void APITest::TestRegisteration(char sendSide) { fprintf(stdout, "Register receive codec with new Payload, AUDIO BACK.\n"); } - //myCodec.pltype = i + 96; - //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); - //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec)); + //myCodec->pltype = i + 96; + //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); //myEvent->Wait(20); //{ // WriteLockScoped wl(_apiTestRWLock); @@ -868,17 +870,17 @@ void APITest::TestRegisteration(char sendSide) { // *thereIsDecoder = false; //} //myEvent->Wait(20); - //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype)); + //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); Wait(1000); - myCodec.pltype = currentPayload; + myCodec->pltype = currentPayload; if (!_randomTest) { fprintf(stdout, "Register receive codec with default Payload, AUDIO BACK.\n"); fflush (stdout); } - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); - //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec)); + CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); myEvent->Wait(20); { WriteLockScoped wl(_apiTestRWLock); @@ -890,7 +892,7 @@ void APITest::TestRegisteration(char sendSide) { } } if (i == 32) { - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); + CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); { WriteLockScoped wl(_apiTestRWLock); *thereIsDecoder = true; @@ -902,9 +904,9 @@ void APITest::TestRegisteration(char sendSide) { "Register receive codec with fixed Payload, AUDIO BACK.\n"); fflush (stdout); } - CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); - //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype)); - //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); + CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); + //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); + //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); myEvent->Wait(20); { WriteLockScoped wl(_apiTestRWLock); @@ -1001,22 +1003,17 @@ void APITest::TestSendVAD(char side) { } void APITest::CurrentCodec(char side) { - CodecInst myCodec; - if (side == 'A') { - _acmA->SendCodec(&myCodec); - } else { - _acmB->SendCodec(&myCodec); - } + auto myCodec = (side == 'A' ? _acmA : _acmB)->SendCodec(); if (!_randomTest) { fprintf(stdout, "\n\n"); fprintf(stdout, "Send codec in Side A\n"); fprintf(stdout, "----------------------------\n"); - fprintf(stdout, "Name................. %s\n", myCodec.plname); - fprintf(stdout, "Sampling Frequency... %d\n", myCodec.plfreq); - fprintf(stdout, "Rate................. %d\n", myCodec.rate); - fprintf(stdout, "Payload-type......... %d\n", myCodec.pltype); - fprintf(stdout, "Packet-size.......... %d\n", myCodec.pacsize); + fprintf(stdout, "Name................. %s\n", myCodec->plname); + fprintf(stdout, "Sampling Frequency... %d\n", myCodec->plfreq); + fprintf(stdout, "Rate................. %d\n", myCodec->rate); + fprintf(stdout, "Payload-type......... %d\n", myCodec->pltype); + fprintf(stdout, "Packet-size.......... %d\n", myCodec->pacsize); } Wait(100); diff --git a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc index d062af0fb9..d68e57532e 100644 --- a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc +++ b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc @@ -339,8 +339,7 @@ std::string EncodeDecodeTest::EncodeToFile(int fileType, _sender.codeId = codeId; _sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1); - struct CodecInst sendCodecInst; - if (acm->SendCodec(&sendCodecInst) >= 0) { + if (acm->SendCodec()) { _sender.Run(); } _sender.Teardown(); diff --git a/webrtc/modules/audio_coding/main/test/PacketLossTest.cc b/webrtc/modules/audio_coding/main/test/PacketLossTest.cc index f19d491d2d..f7c96faacd 100644 --- a/webrtc/modules/audio_coding/main/test/PacketLossTest.cc +++ b/webrtc/modules/audio_coding/main/test/PacketLossTest.cc @@ -143,8 +143,7 @@ void PacketLossTest::Perform() { sender_->Setup(acm.get(), &rtpFile, in_file_name_, sample_rate_hz_, channels_, expected_loss_rate_); - struct CodecInst sendCodecInst; - if (acm->SendCodec(&sendCodecInst) >= 0) { + if (acm->SendCodec()) { sender_->Run(); } sender_->Teardown(); diff --git a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc index 19189b6b8f..e9e4f2bcea 100644 --- a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc +++ b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc @@ -477,8 +477,7 @@ void TestAllCodecs::OpenOutFile(int test_number) { void TestAllCodecs::DisplaySendReceiveCodec() { CodecInst my_codec_param; - acm_a_->SendCodec(&my_codec_param); - printf("%s -> ", my_codec_param.plname); + printf("%s -> ", acm_a_->SendCodec()->plname); acm_b_->ReceiveCodec(&my_codec_param); printf("%s\n", my_codec_param.plname); } diff --git a/webrtc/modules/audio_coding/main/test/TestStereo.cc b/webrtc/modules/audio_coding/main/test/TestStereo.cc index 69cc3272bb..bb38fac738 100644 --- a/webrtc/modules/audio_coding/main/test/TestStereo.cc +++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc @@ -823,14 +823,15 @@ void TestStereo::OpenOutFile(int16_t test_number) { } void TestStereo::DisplaySendReceiveCodec() { - CodecInst my_codec_param; - acm_a_->SendCodec(&my_codec_param); + auto send_codec = acm_a_->SendCodec(); if (test_mode_ != 0) { - printf("%s -> ", my_codec_param.plname); + ASSERT_TRUE(send_codec); + printf("%s -> ", send_codec->plname); } - acm_b_->ReceiveCodec(&my_codec_param); + CodecInst receive_codec; + acm_b_->ReceiveCodec(&receive_codec); if (test_mode_ != 0) { - printf("%s\n", my_codec_param.plname); + printf("%s\n", receive_codec.plname); } } diff --git a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc index bd0335a5f3..bba7b91c40 100644 --- a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc +++ b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc @@ -209,9 +209,9 @@ void TestWebRtcVadDtx::SetVAD(bool enable_dtx, bool enable_vad, EXPECT_EQ(0, acm_send_->SetVAD(enable_dtx, enable_vad, vad_mode)); EXPECT_EQ(0, acm_send_->VAD(&dtx_enabled_, &vad_enabled_, &mode)); - CodecInst codec_param; - acm_send_->SendCodec(&codec_param); - if (STR_CASE_CMP(codec_param.plname, "opus") == 0) { + auto codec_param = acm_send_->SendCodec(); + ASSERT_TRUE(codec_param); + if (STR_CASE_CMP(codec_param->plname, "opus") == 0) { // If send codec is Opus, WebRTC VAD/DTX cannot be used. enable_dtx = enable_vad = false; } diff --git a/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc b/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc index 2ff2a85afe..725cbf74d7 100644 --- a/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc +++ b/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc @@ -250,10 +250,8 @@ void TwoWayCommunication::Perform() { AudioFrame audioFrame; - CodecInst codecInst_B; - CodecInst dummy; - - EXPECT_EQ(0, _acmB->SendCodec(&codecInst_B)); + auto codecInst_B = _acmB->SendCodec(); + ASSERT_TRUE(codecInst_B); // In the following loop we tests that the code can handle misuse of the APIs. // In the middle of a session with data flowing between two sides, called A @@ -285,15 +283,15 @@ void TwoWayCommunication::Perform() { } // Re-register send codec on side B. if (((secPassed % 5) == 4) && (msecPassed >= 990)) { - EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B)); - EXPECT_EQ(0, _acmB->SendCodec(&dummy)); + EXPECT_EQ(0, _acmB->RegisterSendCodec(*codecInst_B)); + EXPECT_TRUE(_acmB->SendCodec()); } // Initialize receiver on side A. if (((secPassed % 7) == 6) && (msecPassed == 0)) 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(0, _acmA->RegisterReceiveCodec(*codecInst_B)); } } } diff --git a/webrtc/modules/audio_coding/main/test/iSACTest.cc b/webrtc/modules/audio_coding/main/test/iSACTest.cc index 35c34d5947..203e12b6a2 100644 --- a/webrtc/modules/audio_coding/main/test/iSACTest.cc +++ b/webrtc/modules/audio_coding/main/test/iSACTest.cc @@ -47,21 +47,21 @@ int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm, if ((isacConfig.currentRateBitPerSec != 0) || (isacConfig.currentFrameSizeMsec != 0)) { - CodecInst sendCodec; - EXPECT_EQ(0, acm->SendCodec(&sendCodec)); + auto sendCodec = acm->SendCodec(); + EXPECT_TRUE(sendCodec); if (isacConfig.currentRateBitPerSec < 0) { // Register iSAC in adaptive (channel-dependent) mode. - sendCodec.rate = -1; - EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); + sendCodec->rate = -1; + EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec)); } else { if (isacConfig.currentRateBitPerSec != 0) { - sendCodec.rate = isacConfig.currentRateBitPerSec; + sendCodec->rate = isacConfig.currentRateBitPerSec; } if (isacConfig.currentFrameSizeMsec != 0) { - sendCodec.pacsize = isacConfig.currentFrameSizeMsec - * (sendCodec.plfreq / 1000); + sendCodec->pacsize = isacConfig.currentFrameSizeMsec + * (sendCodec->plfreq / 1000); } - EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); + EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec)); } } @@ -238,7 +238,6 @@ void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig, _channel_B2A->ResetStats(); char currentTime[500]; - CodecInst sendCodec; EventTimerWrapper* myEvent = EventTimerWrapper::Create(); EXPECT_TRUE(myEvent->StartTimer(true, 10)); while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { @@ -248,8 +247,8 @@ void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig, if ((adaptiveMode) && (_testMode != 0)) { myEvent->Wait(5000); - EXPECT_EQ(0, _acmA->SendCodec(&sendCodec)); - EXPECT_EQ(0, _acmB->SendCodec(&sendCodec)); + EXPECT_TRUE(_acmA->SendCodec()); + EXPECT_TRUE(_acmB->SendCodec()); } } diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 65cf7a6910..ed47b57fa8 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -1242,7 +1242,12 @@ Channel::DeRegisterVoiceEngineObserver() int32_t Channel::GetSendCodec(CodecInst& codec) { - return (audio_coding_->SendCodec(&codec)); + auto send_codec = audio_coding_->SendCodec(); + if (send_codec) { + codec = *send_codec; + return 0; + } + return -1; } int32_t