From 3154a1cf9d761f876d3e1baf46481860b59d4da8 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Fri, 30 Jan 2015 12:29:25 +0000 Subject: [PATCH] Reland r8210 "Add a new parameter to ACMGenericCodec constructor"" This effectively reverts r8211. The problem with r8210 was that the change in constructor signature was not done for other codec selections that then default one. That is, some code that was hidden under #ifdef did not get updated. This is now fixed. BUG=4228 COAUTHOR=kwiberg@webrtc.org TBR=minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/37879004 Cr-Commit-Position: refs/heads/master@{#8215} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8215 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_coding/main/acm2/acm_amr.cc | 10 +++-- .../modules/audio_coding/main/acm2/acm_amr.h | 2 +- .../audio_coding/main/acm2/acm_amrwb.cc | 13 +++--- .../audio_coding/main/acm2/acm_amrwb.h | 2 +- .../modules/audio_coding/main/acm2/acm_cng.cc | 3 +- .../modules/audio_coding/main/acm2/acm_cng.h | 2 +- .../main/acm2/acm_codec_database.cc | 42 +++++++++---------- .../main/acm2/acm_dtmf_playout.cc | 9 +++- .../audio_coding/main/acm2/acm_dtmf_playout.h | 2 +- .../audio_coding/main/acm2/acm_g722.cc | 14 ++++--- .../modules/audio_coding/main/acm2/acm_g722.h | 2 +- .../audio_coding/main/acm2/acm_g7221.cc | 10 +++-- .../audio_coding/main/acm2/acm_g7221.h | 2 +- .../audio_coding/main/acm2/acm_g7221c.cc | 10 +++-- .../audio_coding/main/acm2/acm_g7221c.h | 2 +- .../audio_coding/main/acm2/acm_g729.cc | 12 ++++-- .../modules/audio_coding/main/acm2/acm_g729.h | 2 +- .../audio_coding/main/acm2/acm_g7291.cc | 10 +++-- .../audio_coding/main/acm2/acm_g7291.h | 2 +- .../main/acm2/acm_generic_codec.cc | 13 +++++- .../main/acm2/acm_generic_codec.h | 11 ++++- .../audio_coding/main/acm2/acm_gsmfr.cc | 12 ++++-- .../audio_coding/main/acm2/acm_gsmfr.h | 2 +- .../audio_coding/main/acm2/acm_ilbc.cc | 7 +++- .../modules/audio_coding/main/acm2/acm_ilbc.h | 2 +- .../audio_coding/main/acm2/acm_isac.cc | 10 +++-- .../modules/audio_coding/main/acm2/acm_isac.h | 2 +- .../audio_coding/main/acm2/acm_opus.cc | 16 +++---- .../modules/audio_coding/main/acm2/acm_opus.h | 2 +- .../main/acm2/acm_opus_unittest.cc | 3 +- .../audio_coding/main/acm2/acm_pcm16b.cc | 7 +++- .../audio_coding/main/acm2/acm_pcm16b.h | 2 +- .../audio_coding/main/acm2/acm_pcma.cc | 5 ++- .../modules/audio_coding/main/acm2/acm_pcma.h | 2 +- .../audio_coding/main/acm2/acm_pcmu.cc | 5 ++- .../modules/audio_coding/main/acm2/acm_pcmu.h | 2 +- .../modules/audio_coding/main/acm2/acm_red.cc | 5 ++- .../modules/audio_coding/main/acm2/acm_red.h | 2 +- .../audio_coding/main/acm2/acm_speex.cc | 8 ++-- .../audio_coding/main/acm2/acm_speex.h | 2 +- 40 files changed, 170 insertions(+), 101 deletions(-) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_amr.cc b/webrtc/modules/audio_coding/main/acm2/acm_amr.cc index 6c958a545d..b2d733ad5a 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_amr.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_amr.cc @@ -46,8 +46,9 @@ namespace webrtc { namespace acm2 { #ifndef WEBRTC_CODEC_AMR -ACMAMR::ACMAMR(int16_t /* codec_id */) - : encoder_inst_ptr_(NULL), +ACMAMR::ACMAMR(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoding_mode_(-1), // Invalid value. encoding_rate_(0), // Invalid value. encoder_packing_format_(AMRBandwidthEfficient) { @@ -106,8 +107,9 @@ ACMAMRPackingFormat ACMAMR::AMRDecoderPackingFormat() const { #define WEBRTC_AMR_MR102 6 #define WEBRTC_AMR_MR122 7 -ACMAMR::ACMAMR(int16_t codec_id) - : encoder_inst_ptr_(NULL), +ACMAMR::ACMAMR(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoding_mode_(-1), // invalid value encoding_rate_(0) { // invalid value codec_id_ = codec_id; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_amr.h b/webrtc/modules/audio_coding/main/acm2/acm_amr.h index ab22300587..09d9e43269 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_amr.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_amr.h @@ -25,7 +25,7 @@ namespace acm2 { class ACMAMR : public ACMGenericCodec { public: - explicit ACMAMR(int16_t codec_id); + ACMAMR(int16_t codec_id, bool enable_red); ~ACMAMR(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_amrwb.cc b/webrtc/modules/audio_coding/main/acm2/acm_amrwb.cc index 5c9540fd00..5d923fae3f 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_amrwb.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_amrwb.cc @@ -43,11 +43,13 @@ namespace webrtc { namespace acm2 { #ifndef WEBRTC_CODEC_AMRWB -ACMAMRwb::ACMAMRwb(int16_t /* codec_id */) - : encoder_inst_ptr_(NULL), +ACMAMRwb::ACMAMRwb(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoding_mode_(-1), // invalid value encoding_rate_(0), // invalid value - encoder_packing_format_(AMRBandwidthEfficient) {} + encoder_packing_format_(AMRBandwidthEfficient) { +} ACMAMRwb::~ACMAMRwb() {} @@ -103,8 +105,9 @@ ACMAMRPackingFormat ACMAMRwb::AMRwbDecoderPackingFormat() const { #define AMRWB_MODE_23k 7 #define AMRWB_MODE_24k 8 -ACMAMRwb::ACMAMRwb(int16_t codec_id) - : encoder_inst_ptr_(NULL), +ACMAMRwb::ACMAMRwb(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoding_mode_(-1), // invalid value encoding_rate_(0) { // invalid value codec_id_ = codec_id; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_amrwb.h b/webrtc/modules/audio_coding/main/acm2/acm_amrwb.h index 5b90e0be97..9e09b6b88b 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_amrwb.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_amrwb.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMAMRwb : public ACMGenericCodec { public: - explicit ACMAMRwb(int16_t codec_id); + ACMAMRwb(int16_t codec_id, bool enable_red); ~ACMAMRwb(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_cng.cc b/webrtc/modules/audio_coding/main/acm2/acm_cng.cc index 8fef66ea44..acb6a30811 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_cng.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_cng.cc @@ -19,7 +19,8 @@ namespace webrtc { namespace acm2 { -ACMCNG::ACMCNG(int16_t codec_id) { +ACMCNG::ACMCNG(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { encoder_inst_ptr_ = NULL; codec_id_ = codec_id; samp_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_); diff --git a/webrtc/modules/audio_coding/main/acm2/acm_cng.h b/webrtc/modules/audio_coding/main/acm2/acm_cng.h index d3a8bd3d6c..374b0fc5e8 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_cng.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_cng.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMCNG: public ACMGenericCodec { public: - explicit ACMCNG(int16_t codec_id); + ACMCNG(int16_t codec_id, bool enable_red); ~ACMCNG(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc index 1899abb851..18caa61ff2 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_codec_database.cc @@ -572,38 +572,38 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { // All we have support for right now. if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) { #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) - return new ACMISAC(kISAC); + return new ACMISAC(kISAC, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "PCMU")) { if (codec_inst.channels == 1) { - return new ACMPCMU(kPCMU); + return new ACMPCMU(kPCMU, false); } else { - return new ACMPCMU(kPCMU_2ch); + return new ACMPCMU(kPCMU_2ch, false); } } else if (!STR_CASE_CMP(codec_inst.plname, "PCMA")) { if (codec_inst.channels == 1) { - return new ACMPCMA(kPCMA); + return new ACMPCMA(kPCMA, false); } else { - return new ACMPCMA(kPCMA_2ch); + return new ACMPCMA(kPCMA_2ch, false); } } else if (!STR_CASE_CMP(codec_inst.plname, "ILBC")) { #ifdef WEBRTC_CODEC_ILBC - return new ACMILBC(kILBC); + return new ACMILBC(kILBC, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "AMR")) { #ifdef WEBRTC_CODEC_AMR - return new ACMAMR(kGSMAMR); + return new ACMAMR(kGSMAMR, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "AMR-WB")) { #ifdef WEBRTC_CODEC_AMRWB - return new ACMAMRwb(kGSMAMRWB); + return new ACMAMRwb(kGSMAMRWB, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "G722")) { #ifdef WEBRTC_CODEC_G722 if (codec_inst.channels == 1) { - return new ACMG722(kG722); + return new ACMG722(kG722, false); } else { - return new ACMG722(kG722_2ch); + return new ACMG722(kG722_2ch, false); } #endif } else if (!STR_CASE_CMP(codec_inst.plname, "G7221")) { @@ -628,7 +628,7 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { return NULL; } } - return new ACMG722_1(codec_id); + return new ACMG722_1(codec_id, false); #endif FALLTHROUGH(); } @@ -652,7 +652,7 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { return NULL; } } - return new ACMG722_1C(codec_id); + return new ACMG722_1C(codec_id, false); #endif FALLTHROUGH(); } @@ -685,18 +685,18 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { return NULL; } } - return new ACMCNG(codec_id); + return new ACMCNG(codec_id, false); } else if (!STR_CASE_CMP(codec_inst.plname, "G729")) { #ifdef WEBRTC_CODEC_G729 - return new ACMG729(kG729); + return new ACMG729(kG729, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "G7291")) { #ifdef WEBRTC_CODEC_G729_1 - return new ACMG729_1(kG729_1); + return new ACMG729_1(kG729_1, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "opus")) { #ifdef WEBRTC_CODEC_OPUS - return new ACMOpus(kOpus); + return new ACMOpus(kOpus, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "speex")) { #ifdef WEBRTC_CODEC_SPEEX @@ -714,7 +714,7 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { return NULL; } } - return new ACMSPEEX(codec_id); + return new ACMSPEEX(codec_id, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "CN")) { // For CN we need to check sampling frequency to know what codec to create. @@ -742,7 +742,7 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { return NULL; } } - return new ACMCNG(codec_id); + return new ACMCNG(codec_id, false); } else if (!STR_CASE_CMP(codec_inst.plname, "L16")) { #ifdef WEBRTC_CODEC_PCM16 // For L16 we need to check sampling frequency to know what codec to create. @@ -784,15 +784,15 @@ ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst& codec_inst) { } } } - return new ACMPCM16B(codec_id); + return new ACMPCM16B(codec_id, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "telephone-event")) { #ifdef WEBRTC_CODEC_AVT - return new ACMDTMFPlayout(kAVT); + return new ACMDTMFPlayout(kAVT, false); #endif } else if (!STR_CASE_CMP(codec_inst.plname, "red")) { #ifdef WEBRTC_CODEC_RED - return new ACMRED(kRED); + return new ACMRED(kRED, false); #endif } return NULL; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.cc b/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.cc index c9f4dedfe3..39331f218b 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.cc @@ -22,7 +22,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_AVT -ACMDTMFPlayout::ACMDTMFPlayout(int16_t /* codec_id */) { return; } +ACMDTMFPlayout::ACMDTMFPlayout(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red) { +} ACMDTMFPlayout::~ACMDTMFPlayout() { return; } @@ -46,7 +48,10 @@ void ACMDTMFPlayout::DestructEncoderSafe() { #else //===================== Actual Implementation ======================= -ACMDTMFPlayout::ACMDTMFPlayout(int16_t codec_id) { codec_id_ = codec_id; } +ACMDTMFPlayout::ACMDTMFPlayout(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { + codec_id_ = codec_id; +} ACMDTMFPlayout::~ACMDTMFPlayout() { return; } diff --git a/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.h b/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.h index dd87df4eac..72f201be10 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_dtmf_playout.h @@ -19,7 +19,7 @@ namespace acm2 { class ACMDTMFPlayout : public ACMGenericCodec { public: - explicit ACMDTMFPlayout(int16_t codec_id); + ACMDTMFPlayout(int16_t codec_id, bool enable_red); ~ACMDTMFPlayout(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g722.cc b/webrtc/modules/audio_coding/main/acm2/acm_g722.cc index dfe781ef0c..e27b992253 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g722.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_g722.cc @@ -23,10 +23,12 @@ namespace acm2 { #ifndef WEBRTC_CODEC_G722 -ACMG722::ACMG722(int16_t /* codec_id */) - : ptr_enc_str_(NULL), +ACMG722::ACMG722(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + ptr_enc_str_(NULL), encoder_inst_ptr_(NULL), - encoder_inst_ptr_right_(NULL) {} + encoder_inst_ptr_right_(NULL) { +} ACMG722::~ACMG722() {} @@ -64,8 +66,10 @@ struct ACMG722DecStr { G722DecInst* inst_right; // instance for right channel in case of stereo }; -ACMG722::ACMG722(int16_t codec_id) - : encoder_inst_ptr_(NULL), encoder_inst_ptr_right_(NULL) { +ACMG722::ACMG722(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), + encoder_inst_ptr_right_(NULL) { ptr_enc_str_ = new ACMG722EncStr; if (ptr_enc_str_ != NULL) { ptr_enc_str_->inst = NULL; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g722.h b/webrtc/modules/audio_coding/main/acm2/acm_g722.h index dd3b7669c2..79ddf28bcc 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g722.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_g722.h @@ -27,7 +27,7 @@ struct ACMG722DecStr; class ACMG722 : public ACMGenericCodec { public: - explicit ACMG722(int16_t codec_id); + ACMG722(int16_t codec_id, bool enable_red); ~ACMG722(); // For FEC. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7221.cc b/webrtc/modules/audio_coding/main/acm2/acm_g7221.cc index 5739dd3d05..884a189028 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7221.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7221.cc @@ -84,8 +84,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_G722_1 -ACMG722_1::ACMG722_1(int16_t /* codec_id */) - : operational_rate_(-1), +ACMG722_1::ACMG722_1(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + operational_rate_(-1), encoder_inst_ptr_(NULL), encoder_inst_ptr_right_(NULL), encoder_inst16_ptr_(NULL), @@ -116,8 +117,9 @@ int16_t ACMG722_1::InternalCreateEncoder() { return -1; } void ACMG722_1::DestructEncoderSafe() { return; } #else //===================== Actual Implementation ======================= -ACMG722_1::ACMG722_1(int16_t codec_id) - : encoder_inst_ptr_(NULL), +ACMG722_1::ACMG722_1(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoder_inst_ptr_right_(NULL), encoder_inst16_ptr_(NULL), encoder_inst16_ptr_right_(NULL), diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7221.h b/webrtc/modules/audio_coding/main/acm2/acm_g7221.h index 3935798bce..10a49acd81 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7221.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7221.h @@ -28,7 +28,7 @@ namespace acm2 { class ACMG722_1 : public ACMGenericCodec { public: - explicit ACMG722_1(int16_t codec_id); + ACMG722_1(int16_t codec_id, bool enable_red); ~ACMG722_1(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7221c.cc b/webrtc/modules/audio_coding/main/acm2/acm_g7221c.cc index 996eaf8c99..43eb290082 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7221c.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7221c.cc @@ -84,8 +84,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_G722_1C -ACMG722_1C::ACMG722_1C(int16_t /* codec_id */) - : operational_rate_(-1), +ACMG722_1C::ACMG722_1C(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + operational_rate_(-1), encoder_inst_ptr_(NULL), encoder_inst_ptr_right_(NULL), encoder_inst24_ptr_(NULL), @@ -116,8 +117,9 @@ int16_t ACMG722_1C::InternalCreateEncoder() { return -1; } void ACMG722_1C::DestructEncoderSafe() { return; } #else //===================== Actual Implementation ======================= -ACMG722_1C::ACMG722_1C(int16_t codec_id) - : encoder_inst_ptr_(NULL), +ACMG722_1C::ACMG722_1C(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), encoder_inst_ptr_right_(NULL), encoder_inst24_ptr_(NULL), encoder_inst24_ptr_right_(NULL), diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7221c.h b/webrtc/modules/audio_coding/main/acm2/acm_g7221c.h index 52a0db9fab..e22790d788 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7221c.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7221c.h @@ -28,7 +28,7 @@ namespace acm2 { class ACMG722_1C : public ACMGenericCodec { public: - explicit ACMG722_1C(int16_t codec_id); + ACMG722_1C(int16_t codec_id, bool enable_red); ~ACMG722_1C(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g729.cc b/webrtc/modules/audio_coding/main/acm2/acm_g729.cc index de1af6e528..52b0d1a8f7 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g729.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_g729.cc @@ -26,7 +26,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_G729 -ACMG729::ACMG729(int16_t /* codec_id */) : encoder_inst_ptr_(NULL) {} +ACMG729::ACMG729(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) { +} ACMG729::~ACMG729() { return; } @@ -58,10 +60,12 @@ int16_t ACMG729::InternalCreateEncoder() { return -1; } void ACMG729::DestructEncoderSafe() { return; } #else //===================== Actual Implementation ======================= -ACMG729::ACMG729(int16_t codec_id) - : codec_id_(codec_id), +ACMG729::ACMG729(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + codec_id_(codec_id), has_internal_dtx_(), - encoder_inst_ptr_(NULL) {} + encoder_inst_ptr_(NULL) { +} ACMG729::~ACMG729() { if (encoder_inst_ptr_ != NULL) { diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g729.h b/webrtc/modules/audio_coding/main/acm2/acm_g729.h index be48c6e05a..e19ce5a2b8 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g729.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_g729.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMG729 : public ACMGenericCodec { public: - explicit ACMG729(int16_t codec_id); + ACMG729(int16_t codec_id, bool enable_red); ~ACMG729(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7291.cc b/webrtc/modules/audio_coding/main/acm2/acm_g7291.cc index e50d027dc8..bfc653a4cb 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7291.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7291.cc @@ -25,8 +25,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_G729_1 -ACMG729_1::ACMG729_1(int16_t /* codec_id */) - : encoder_inst_ptr_(NULL), +ACMG729_1::ACMG729_1(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), my_rate_(32000), flag_8khz_(0), flag_g729_mode_(0) { @@ -57,8 +58,9 @@ int16_t ACMG729_1::SetBitRateSafe(const int32_t /*rate*/) { return -1; } struct G729_1_inst_t_; -ACMG729_1::ACMG729_1(int16_t codec_id) - : encoder_inst_ptr_(NULL), +ACMG729_1::ACMG729_1(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), my_rate_(32000), // Default rate. flag_8khz_(0), flag_g729_mode_(0) { diff --git a/webrtc/modules/audio_coding/main/acm2/acm_g7291.h b/webrtc/modules/audio_coding/main/acm2/acm_g7291.h index 8387dcfead..908e64f97d 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_g7291.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_g7291.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMG729_1 : public ACMGenericCodec { public: - explicit ACMG729_1(int16_t codec_id); + ACMG729_1(int16_t codec_id, bool enable_red); ~ACMG729_1(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.cc b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.cc index 6b1809566f..209d589c9b 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.cc @@ -37,7 +37,7 @@ enum { // We set some of the variables to invalid values as a check point // if a proper initialization has happened. Another approach is // to initialize to a default codec that we are sure is always included. -ACMGenericCodec::ACMGenericCodec() +ACMGenericCodec::ACMGenericCodec(bool enable_red) : in_audio_ix_write_(0), in_audio_ix_read_(0), in_timestamp_ix_write_(0), @@ -60,6 +60,7 @@ ACMGenericCodec::ACMGenericCodec() sent_cn_previous_(false), prev_frame_cng_(0), has_internal_fec_(false), + copy_red_enabled_(enable_red), codec_wrapper_lock_(*RWLockWrapper::CreateRWLock()), last_timestamp_(0xD87F3F9F), unique_id_(0) { @@ -202,6 +203,16 @@ int ACMGenericCodec::SetFEC(bool enable_fec) { return 0; } +void ACMGenericCodec::EnableCopyRed(bool enable, int /*red_payload_type*/) { + WriteLockScoped lockCodec(codec_wrapper_lock_); + copy_red_enabled_ = enable; +} + +bool ACMGenericCodec::ExternalRedNeeded() { + ReadLockScoped lockCodec(codec_wrapper_lock_); + return copy_red_enabled_; +} + int16_t ACMGenericCodec::Encode(uint8_t* bitstream, int16_t* bitstream_len_byte, uint32_t* timestamp, diff --git a/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h index b13719fb2e..9d045109f7 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_generic_codec.h @@ -40,7 +40,7 @@ class ACMGenericCodec { /////////////////////////////////////////////////////////////////////////// // Constructor of the class // - ACMGenericCodec(); + explicit ACMGenericCodec(bool enable_red); /////////////////////////////////////////////////////////////////////////// // Destructor of the class. @@ -614,6 +614,13 @@ class ACMGenericCodec { // virtual int SetPacketLossRate(int /* loss_rate */) { return 0; } + // Sets if CopyRed should be enabled. + virtual void EnableCopyRed(bool enable, int red_payload_type); + + // Returns true if the caller needs to produce RED data manually (that is, if + // RED has been enabled but the codec isn't able to produce the data itself). + virtual bool ExternalRedNeeded(); + protected: /////////////////////////////////////////////////////////////////////////// // All the functions with FunctionNameSafe(...) contain the actual @@ -953,6 +960,8 @@ class ACMGenericCodec { // FEC. bool has_internal_fec_ GUARDED_BY(codec_wrapper_lock_); + bool copy_red_enabled_ GUARDED_BY(codec_wrapper_lock_); + WebRtcACMCodecParams encoder_params_ GUARDED_BY(codec_wrapper_lock_); // Used to lock wrapper internal data diff --git a/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.cc b/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.cc index 1c37a1eeda..ca28ef4f77 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.cc @@ -25,7 +25,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_GSMFR -ACMGSMFR::ACMGSMFR(int16_t /* codec_id */) : encoder_inst_ptr_(NULL) {} +ACMGSMFR::ACMGSMFR(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) { +} ACMGSMFR::~ACMGSMFR() { return; } @@ -51,10 +53,12 @@ void ACMGSMFR::DestructEncoderSafe() { return; } #else //===================== Actual Implementation ======================= -ACMGSMFR::ACMGSMFR(int16_t codec_id) - : codec_id_(codec_id), +ACMGSMFR::ACMGSMFR(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + codec_id_(codec_id), has_internal_dtx_(true), - encoder_inst_ptr_(NULL) {} + encoder_inst_ptr_(NULL) { +} ACMGSMFR::~ACMGSMFR() { if (encoder_inst_ptr_ != NULL) { diff --git a/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.h b/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.h index 2cf954b5b3..5a84899e00 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_gsmfr.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMGSMFR : public ACMGenericCodec { public: - explicit ACMGSMFR(int16_t codec_id); + ACMGSMFR(int16_t codec_id, bool enable_red); ~ACMGSMFR(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_ilbc.cc b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.cc index 94d655f18c..bd5182bdd5 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_ilbc.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.cc @@ -21,7 +21,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_ILBC -ACMILBC::ACMILBC(int16_t /* codec_id */) : encoder_inst_ptr_(NULL) {} +ACMILBC::ACMILBC(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) { +} ACMILBC::~ACMILBC() { return; } @@ -44,7 +46,8 @@ int16_t ACMILBC::SetBitRateSafe(const int32_t /* rate */) { return -1; } #else //===================== Actual Implementation ======================= -ACMILBC::ACMILBC(int16_t codec_id) : encoder_inst_ptr_(NULL) { +ACMILBC::ACMILBC(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) { codec_id_ = codec_id; return; } diff --git a/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h index 3cf2c73a70..870b7c9993 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_ilbc.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMILBC : public ACMGenericCodec { public: - explicit ACMILBC(int16_t codec_id); + ACMILBC(int16_t codec_id, bool enable_red); ~ACMILBC(); // for FEC diff --git a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc index 8a63410f01..68747fef37 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc @@ -59,8 +59,9 @@ static const int32_t kIsacRatesSwb[NR_ISAC_BANDWIDTHS] = { #if (!defined(WEBRTC_CODEC_ISAC) && !defined(WEBRTC_CODEC_ISACFX)) -ACMISAC::ACMISAC(int16_t /* codec_id */) - : codec_inst_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), +ACMISAC::ACMISAC(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + codec_inst_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), codec_inst_ptr_(NULL), is_enc_initialized_(false), isac_coding_mode_(CHANNEL_INDEPENDENT), @@ -261,8 +262,9 @@ static uint16_t ACMISACFixGetDecSampRate(ACM_ISAC_STRUCT* /* inst */) { #endif -ACMISAC::ACMISAC(int16_t codec_id) - : codec_inst_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), +ACMISAC::ACMISAC(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + codec_inst_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), is_enc_initialized_(false), isac_coding_mode_(CHANNEL_INDEPENDENT), enforce_frame_size_(false), diff --git a/webrtc/modules/audio_coding/main/acm2/acm_isac.h b/webrtc/modules/audio_coding/main/acm2/acm_isac.h index b83d1d3bdb..f614cfea44 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_isac.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.h @@ -31,7 +31,7 @@ enum IsacCodingMode { class ACMISAC : public ACMGenericCodec, AudioDecoder { public: - explicit ACMISAC(int16_t codec_id); + ACMISAC(int16_t codec_id, bool enable_red); ~ACMISAC(); int16_t InternalInitDecoder(WebRtcACMCodecParams* codec_params) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_opus.cc b/webrtc/modules/audio_coding/main/acm2/acm_opus.cc index 005e91046c..1942b00cdb 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_opus.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_opus.cc @@ -23,8 +23,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_OPUS -ACMOpus::ACMOpus(int16_t /* codec_id */) - : encoder_inst_ptr_(NULL), +ACMOpus::ACMOpus(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), sample_freq_(0), bitrate_(0), channels_(1), @@ -63,11 +64,12 @@ int16_t ACMOpus::SetBitRateSafe(const int32_t /*rate*/) { #else //===================== Actual Implementation ======================= -ACMOpus::ACMOpus(int16_t codec_id) - : encoder_inst_ptr_(NULL), - sample_freq_(32000), // Default sampling frequency. - bitrate_(20000), // Default bit-rate. - channels_(1), // Default mono. +ACMOpus::ACMOpus(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), + sample_freq_(32000), // Default sampling frequency. + bitrate_(20000), // Default bit-rate. + channels_(1), // Default mono. packet_loss_rate_(0), // Initial packet loss rate. application_(kVoip) { // Initial application mode. codec_id_ = codec_id; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_opus.h b/webrtc/modules/audio_coding/main/acm2/acm_opus.h index 3c7aea65fb..89f1e1471d 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_opus.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_opus.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMOpus : public ACMGenericCodec { public: - explicit ACMOpus(int16_t codec_id); + ACMOpus(int16_t codec_id, bool enable_red); ~ACMOpus(); ACMGenericCodec* CreateInstance(void); diff --git a/webrtc/modules/audio_coding/main/acm2/acm_opus_unittest.cc b/webrtc/modules/audio_coding/main/acm2/acm_opus_unittest.cc index 421bbe595e..2c4358fc84 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_opus_unittest.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_opus_unittest.cc @@ -31,8 +31,7 @@ namespace { class AcmOpusTest : public ACMOpus { public: - explicit AcmOpusTest(int16_t codec_id) - : ACMOpus(codec_id) {} + explicit AcmOpusTest(int16_t codec_id) : ACMOpus(codec_id, false) {} ~AcmOpusTest() {} int packet_loss_rate() { return packet_loss_rate_; } OpusApplicationMode application() { return application_; } diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.cc b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.cc index 54c7860247..3621b9d372 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.cc @@ -23,7 +23,9 @@ namespace acm2 { #ifndef WEBRTC_CODEC_PCM16 -ACMPCM16B::ACMPCM16B(int16_t /* codec_id */) { return; } +ACMPCM16B::ACMPCM16B(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red) { +} ACMPCM16B::~ACMPCM16B() { return; } @@ -44,7 +46,8 @@ int16_t ACMPCM16B::InternalCreateEncoder() { return -1; } void ACMPCM16B::DestructEncoderSafe() { return; } #else //===================== Actual Implementation ======================= -ACMPCM16B::ACMPCM16B(int16_t codec_id) { +ACMPCM16B::ACMPCM16B(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { codec_id_ = codec_id; sampling_freq_hz_ = ACMCodecDB::CodecFreq(codec_id_); } diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h index 0811a1717d..176dcc974c 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcm16b.h @@ -19,7 +19,7 @@ namespace acm2 { class ACMPCM16B : public ACMGenericCodec { public: - explicit ACMPCM16B(int16_t codec_id); + ACMPCM16B(int16_t codec_id, bool enable_red); ~ACMPCM16B(); // For FEC. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcma.cc b/webrtc/modules/audio_coding/main/acm2/acm_pcma.cc index 41d4d0856a..008b1cf39c 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcma.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcma.cc @@ -20,7 +20,10 @@ namespace webrtc { namespace acm2 { -ACMPCMA::ACMPCMA(int16_t codec_id) { codec_id_ = codec_id; } +ACMPCMA::ACMPCMA(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { + codec_id_ = codec_id; +} ACMPCMA::~ACMPCMA() { return; } diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcma.h b/webrtc/modules/audio_coding/main/acm2/acm_pcma.h index d7d00b4a5f..fa61ed5dce 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcma.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcma.h @@ -19,7 +19,7 @@ namespace acm2 { class ACMPCMA : public ACMGenericCodec { public: - explicit ACMPCMA(int16_t codec_id); + ACMPCMA(int16_t codec_id, bool enable_red); ~ACMPCMA(); // For FEC. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcmu.cc b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.cc index 4f16062f1f..7ccc184165 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcmu.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.cc @@ -20,7 +20,10 @@ namespace webrtc { namespace acm2 { -ACMPCMU::ACMPCMU(int16_t codec_id) { codec_id_ = codec_id; } +ACMPCMU::ACMPCMU(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { + codec_id_ = codec_id; +} ACMPCMU::~ACMPCMU() {} diff --git a/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h index dccfffd5af..88be95b1a1 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_pcmu.h @@ -19,7 +19,7 @@ namespace acm2 { class ACMPCMU : public ACMGenericCodec { public: - explicit ACMPCMU(int16_t codec_id); + ACMPCMU(int16_t codec_id, bool enable_red); ~ACMPCMU(); // For FEC. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_red.cc b/webrtc/modules/audio_coding/main/acm2/acm_red.cc index 05996e51a1..8025c7f31f 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_red.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_red.cc @@ -17,7 +17,10 @@ namespace webrtc { namespace acm2 { -ACMRED::ACMRED(int16_t codec_id) { codec_id_ = codec_id; } +ACMRED::ACMRED(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red) { + codec_id_ = codec_id; +} ACMRED::~ACMRED() {} diff --git a/webrtc/modules/audio_coding/main/acm2/acm_red.h b/webrtc/modules/audio_coding/main/acm2/acm_red.h index 73f904aebf..25cf053b2b 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_red.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_red.h @@ -19,7 +19,7 @@ namespace acm2 { class ACMRED : public ACMGenericCodec { public: - explicit ACMRED(int16_t codec_id); + ACMRED(int16_t codec_id, bool enable_red); ~ACMRED(); // For FEC. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_speex.cc b/webrtc/modules/audio_coding/main/acm2/acm_speex.cc index 85ead390e2..6943079d77 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_speex.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_speex.cc @@ -24,8 +24,9 @@ namespace webrtc { namespace acm2 { #ifndef WEBRTC_CODEC_SPEEX -ACMSPEEX::ACMSPEEX(int16_t /* codec_id */) - : encoder_inst_ptr_(NULL), +ACMSPEEX::ACMSPEEX(int16_t /* codec_id */, bool enable_red) + : ACMGenericCodec(enable_red), + encoder_inst_ptr_(NULL), compl_mode_(0), vbr_enabled_(false), encoding_rate_(-1), @@ -68,7 +69,8 @@ int16_t ACMSPEEX::SetComplMode(int16_t mode) { return -1; } #else //===================== Actual Implementation ======================= -ACMSPEEX::ACMSPEEX(int16_t codec_id) : encoder_inst_ptr_(NULL) { +ACMSPEEX::ACMSPEEX(int16_t codec_id, bool enable_red) + : ACMGenericCodec(enable_red), encoder_inst_ptr_(NULL) { codec_id_ = codec_id; // Set sampling frequency, frame size and rate Speex diff --git a/webrtc/modules/audio_coding/main/acm2/acm_speex.h b/webrtc/modules/audio_coding/main/acm2/acm_speex.h index 931e3a9f4f..c72bdc86f0 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_speex.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_speex.h @@ -23,7 +23,7 @@ namespace acm2 { class ACMSPEEX : public ACMGenericCodec { public: - explicit ACMSPEEX(int16_t codec_id); + ACMSPEEX(int16_t codec_id, bool enable_red); ~ACMSPEEX(); // For FEC.