Index: webrtc/modules/audio_coding/main/acm2/codec_owner.cc |
diff --git a/webrtc/modules/audio_coding/main/acm2/codec_owner.cc b/webrtc/modules/audio_coding/main/acm2/codec_owner.cc |
index df9a992dac9fe663e0e1be374663895447c1eae0..43f684ec7f55fd0e86bfca097a43afa13fea4a50 100644 |
--- a/webrtc/modules/audio_coding/main/acm2/codec_owner.cc |
+++ b/webrtc/modules/audio_coding/main/acm2/codec_owner.cc |
@@ -14,25 +14,6 @@ |
#include "webrtc/base/logging.h" |
#include "webrtc/engine_configurations.h" |
#include "webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h" |
-#include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" |
-#ifdef WEBRTC_CODEC_G722 |
-#include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" |
-#endif |
-#ifdef WEBRTC_CODEC_ILBC |
-#include "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h" |
-#endif |
-#ifdef WEBRTC_CODEC_ISACFX |
-#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isacfix.h" |
-#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isacfix.h" |
-#endif |
-#ifdef WEBRTC_CODEC_ISAC |
-#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" |
-#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" |
-#endif |
-#ifdef WEBRTC_CODEC_OPUS |
-#include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h" |
-#endif |
-#include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h" |
#ifdef WEBRTC_CODEC_RED |
#include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h" |
#endif |
@@ -40,60 +21,13 @@ |
namespace webrtc { |
namespace acm2 { |
-CodecOwner::CodecOwner() : external_speech_encoder_(nullptr) { |
+CodecOwner::CodecOwner() : speech_encoder_(nullptr) { |
} |
CodecOwner::~CodecOwner() = default; |
namespace { |
-rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder( |
- LockedIsacBandwidthInfo* bwinfo) { |
-#if defined(WEBRTC_CODEC_ISACFX) |
- return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo)); |
-#elif defined(WEBRTC_CODEC_ISAC) |
- return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo)); |
-#else |
- FATAL() << "iSAC is not supported."; |
- return rtc::scoped_ptr<AudioDecoder>(); |
-#endif |
-} |
- |
-// Returns a new speech encoder, or null on error. |
-// TODO(kwiberg): Don't handle errors here (bug 5033) |
-rtc::scoped_ptr<AudioEncoder> CreateSpeechEncoder( |
- const CodecInst& speech_inst, |
- LockedIsacBandwidthInfo* bwinfo) { |
-#if defined(WEBRTC_CODEC_ISACFX) |
- if (STR_CASE_CMP(speech_inst.plname, "isac") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderIsacFix(speech_inst, bwinfo)); |
-#endif |
-#if defined(WEBRTC_CODEC_ISAC) |
- if (STR_CASE_CMP(speech_inst.plname, "isac") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderIsac(speech_inst, bwinfo)); |
-#endif |
-#ifdef WEBRTC_CODEC_OPUS |
- if (STR_CASE_CMP(speech_inst.plname, "opus") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderOpus(speech_inst)); |
-#endif |
- if (STR_CASE_CMP(speech_inst.plname, "pcmu") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderPcmU(speech_inst)); |
- if (STR_CASE_CMP(speech_inst.plname, "pcma") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderPcmA(speech_inst)); |
- if (STR_CASE_CMP(speech_inst.plname, "l16") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderPcm16B(speech_inst)); |
-#ifdef WEBRTC_CODEC_ILBC |
- if (STR_CASE_CMP(speech_inst.plname, "ilbc") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst)); |
-#endif |
-#ifdef WEBRTC_CODEC_G722 |
- if (STR_CASE_CMP(speech_inst.plname, "g722") == 0) |
- return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst)); |
-#endif |
- LOG_F(LS_ERROR) << "Could not create encoder of type " << speech_inst.plname; |
- return rtc::scoped_ptr<AudioEncoder>(); |
-} |
- |
AudioEncoder* CreateRedEncoder(int red_payload_type, |
AudioEncoder* encoder, |
rtc::scoped_ptr<AudioEncoder>* red_encoder) { |
@@ -147,11 +81,10 @@ bool CodecOwner::SetEncoders(const CodecInst& speech_inst, |
int cng_payload_type, |
ACMVADMode vad_mode, |
int red_payload_type) { |
- speech_encoder_ = CreateSpeechEncoder(speech_inst, &isac_bandwidth_info_); |
- if (!speech_encoder_) |
+ AudioEncoder* speech_encoder = rent_a_codec_.RentEncoder(speech_inst); |
+ if (!speech_encoder) |
return false; |
- external_speech_encoder_ = nullptr; |
- ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
+ SetEncoders(speech_encoder, cng_payload_type, vad_mode, red_payload_type); |
return true; |
} |
@@ -159,30 +92,26 @@ void CodecOwner::SetEncoders(AudioEncoder* external_speech_encoder, |
int cng_payload_type, |
ACMVADMode vad_mode, |
int red_payload_type) { |
- external_speech_encoder_ = external_speech_encoder; |
- speech_encoder_.reset(); |
+ speech_encoder_ = external_speech_encoder; |
ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
} |
void CodecOwner::ChangeCngAndRed(int cng_payload_type, |
ACMVADMode vad_mode, |
int red_payload_type) { |
- AudioEncoder* speech_encoder = SpeechEncoder(); |
+ RTC_DCHECK(speech_encoder_); |
if (cng_payload_type != -1 || red_payload_type != -1) { |
// The RED and CNG encoders need to be in sync with the speech encoder, so |
// reset the latter to ensure its buffer is empty. |
- speech_encoder->Reset(); |
+ speech_encoder_->Reset(); |
} |
- AudioEncoder* encoder = |
- CreateRedEncoder(red_payload_type, speech_encoder, &red_encoder_); |
+ AudioEncoder* encoder = CreateRedEncoder( |
+ red_payload_type, speech_encoder_, &red_encoder_); |
CreateCngEncoder(cng_payload_type, vad_mode, encoder, &cng_encoder_); |
- RTC_DCHECK_EQ(!!speech_encoder_ + !!external_speech_encoder_, 1); |
} |
AudioDecoder* CodecOwner::GetIsacDecoder() { |
- if (!isac_decoder_) |
- isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_); |
- return isac_decoder_.get(); |
+ return rent_a_codec_.RentIsacDecoder(); |
} |
AudioEncoder* CodecOwner::Encoder() { |
@@ -195,18 +124,7 @@ const AudioEncoder* CodecOwner::Encoder() const { |
return cng_encoder_.get(); |
if (red_encoder_) |
return red_encoder_.get(); |
- return SpeechEncoder(); |
-} |
- |
-AudioEncoder* CodecOwner::SpeechEncoder() { |
- const auto* const_this = this; |
- return const_cast<AudioEncoder*>(const_this->SpeechEncoder()); |
-} |
- |
-const AudioEncoder* CodecOwner::SpeechEncoder() const { |
- RTC_DCHECK(!speech_encoder_ || !external_speech_encoder_); |
- return external_speech_encoder_ ? external_speech_encoder_ |
- : speech_encoder_.get(); |
+ return speech_encoder_; |
} |
} // namespace acm2 |