Let AudioCodingModule::SendCodec return Maybe<CodecInst>
And deal with the consequences thereof... Review URL: https://codereview.webrtc.org/1406123011 Cr-Commit-Position: refs/heads/master@{#10497}
This commit is contained in:
@ -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;
|
||||
|
@ -206,9 +206,9 @@ void AudioCodingModuleImpl::RegisterExternalSendCodec(
|
||||
}
|
||||
|
||||
// Get current send codec.
|
||||
int AudioCodingModuleImpl::SendCodec(CodecInst* current_codec) const {
|
||||
rtc::Maybe<CodecInst> AudioCodingModuleImpl::SendCodec() const {
|
||||
CriticalSectionScoped lock(acm_crit_sect_.get());
|
||||
return codec_manager_.GetCodecInst(current_codec);
|
||||
return codec_manager_.GetCodecInst();
|
||||
}
|
||||
|
||||
// Get current send frequency.
|
||||
|
@ -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<CodecInst> SendCodec() const override;
|
||||
|
||||
// Get current send frequency.
|
||||
int SendFrequency() const override;
|
||||
|
@ -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<CodecInst> 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<CodecInst>();
|
||||
}
|
||||
*current_codec = send_codec_inst_;
|
||||
return 0;
|
||||
return rtc::Maybe<CodecInst>(send_codec_inst_);
|
||||
}
|
||||
|
||||
bool CodecManager::SetCopyRed(bool enable) {
|
||||
|
@ -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<CodecInst> GetCodecInst() const;
|
||||
|
||||
bool SetCopyRed(bool enable);
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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<CodecInst> SendCodec() const = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// int32_t SendFrequency()
|
||||
|
@ -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<CodecInst>(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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user