From 8967183bf79322c5cb3cbd99e9b7aa298228d0a2 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Tue, 22 Sep 2015 14:06:29 -0700 Subject: [PATCH] Simple cleanups of AudioDecoder and AudioEncoder classes * Make sure they're all final and don't allow copying or assignment. * Get rid of the single-channel PCM decoder classes. * Move some includes from .h to .cc files where possible. BUG=webrtc:4557 Review URL: https://codereview.webrtc.org/1353803002 Cr-Commit-Position: refs/heads/master@{#10021} --- .../codecs/cng/include/audio_encoder_cng.h | 3 ++ .../codecs/g711/audio_decoder_pcm.cc | 12 +----- .../codecs/g711/include/audio_decoder_pcm.h | 41 +++++-------------- .../codecs/g711/include/audio_encoder_pcm.h | 3 ++ .../codecs/g722/include/audio_decoder_g722.h | 6 +-- .../codecs/g722/include/audio_encoder_g722.h | 1 + .../ilbc/interface/audio_decoder_ilbc.h | 2 +- .../ilbc/interface/audio_encoder_ilbc.h | 1 + .../codecs/isac/audio_decoder_isac_t.h | 1 + .../codecs/isac/audio_encoder_isac_t.h | 1 + .../opus/audio_encoder_opus_unittest.cc | 1 + .../opus/interface/audio_decoder_opus.h | 2 +- .../opus/interface/audio_encoder_opus.h | 5 ++- .../codecs/pcm16b/audio_decoder_pcm16b.cc | 16 +++----- .../pcm16b/include/audio_decoder_pcm16b.h | 16 ++------ .../pcm16b/include/audio_encoder_pcm16b.h | 4 ++ .../codecs/red/audio_encoder_copy_red.h | 2 + .../audio_coding_module_unittest_oldapi.cc | 2 +- .../audio_coding/neteq/audio_decoder_impl.cc | 14 +++---- .../neteq/audio_decoder_unittest.cc | 6 +-- .../neteq/neteq_network_stats_unittest.cc | 32 +++++++-------- 21 files changed, 74 insertions(+), 97 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h b/webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h index b025bc2e44..3ca9eb60f3 100644 --- a/webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h +++ b/webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h @@ -86,7 +86,10 @@ class AudioEncoderCng final : public AudioEncoder { bool last_frame_active_; rtc::scoped_ptr vad_; rtc::scoped_ptr cng_inst_; + + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCng); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.cc b/webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.cc index b273b18e18..12306d9167 100644 --- a/webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.cc +++ b/webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.cc @@ -17,7 +17,7 @@ namespace webrtc { void AudioDecoderPcmU::Reset() {} size_t AudioDecoderPcmU::Channels() const { - return 1; + return num_channels_; } int AudioDecoderPcmU::DecodeInternal(const uint8_t* encoded, @@ -38,14 +38,10 @@ int AudioDecoderPcmU::PacketDuration(const uint8_t* encoded, return static_cast(encoded_len / Channels()); } -size_t AudioDecoderPcmUMultiCh::Channels() const { - return channels_; -} - void AudioDecoderPcmA::Reset() {} size_t AudioDecoderPcmA::Channels() const { - return 1; + return num_channels_; } int AudioDecoderPcmA::DecodeInternal(const uint8_t* encoded, @@ -66,8 +62,4 @@ int AudioDecoderPcmA::PacketDuration(const uint8_t* encoded, return static_cast(encoded_len / Channels()); } -size_t AudioDecoderPcmAMultiCh::Channels() const { - return channels_; -} - } // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/g711/include/audio_decoder_pcm.h b/webrtc/modules/audio_coding/codecs/g711/include/audio_decoder_pcm.h index 4f82603ba6..7bc37d3b7a 100644 --- a/webrtc/modules/audio_coding/codecs/g711/include/audio_decoder_pcm.h +++ b/webrtc/modules/audio_coding/codecs/g711/include/audio_decoder_pcm.h @@ -16,9 +16,11 @@ namespace webrtc { -class AudioDecoderPcmU : public AudioDecoder { +class AudioDecoderPcmU final : public AudioDecoder { public: - AudioDecoderPcmU() {} + explicit AudioDecoderPcmU(size_t num_channels) : num_channels_(num_channels) { + RTC_DCHECK_GE(num_channels, 1u); + } void Reset() override; int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override; size_t Channels() const override; @@ -31,12 +33,15 @@ class AudioDecoderPcmU : public AudioDecoder { SpeechType* speech_type) override; private: + const size_t num_channels_; RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmU); }; -class AudioDecoderPcmA : public AudioDecoder { +class AudioDecoderPcmA final : public AudioDecoder { public: - AudioDecoderPcmA() {} + explicit AudioDecoderPcmA(size_t num_channels) : num_channels_(num_channels) { + RTC_DCHECK_GE(num_channels, 1u); + } void Reset() override; int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override; size_t Channels() const override; @@ -49,34 +54,10 @@ class AudioDecoderPcmA : public AudioDecoder { SpeechType* speech_type) override; private: + const size_t num_channels_; RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmA); }; -class AudioDecoderPcmUMultiCh : public AudioDecoderPcmU { - public: - explicit AudioDecoderPcmUMultiCh(size_t channels) - : AudioDecoderPcmU(), channels_(channels) { - RTC_DCHECK_GT(channels, 0u); - } - size_t Channels() const override; - - private: - const size_t channels_; - RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmUMultiCh); -}; - -class AudioDecoderPcmAMultiCh : public AudioDecoderPcmA { - public: - explicit AudioDecoderPcmAMultiCh(size_t channels) - : AudioDecoderPcmA(), channels_(channels) { - RTC_DCHECK_GT(channels, 0u); - } - size_t Channels() const override; - - private: - const size_t channels_; - RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcmAMultiCh); -}; - } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_DECODER_PCM_H_ diff --git a/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h b/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h index c2788f14d6..e532f9b1bc 100644 --- a/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h +++ b/webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h @@ -87,6 +87,7 @@ class AudioEncoderPcmA final : public AudioEncoderPcm { private: static const int kSampleRateHz = 8000; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcmA); }; class AudioEncoderPcmU final : public AudioEncoderPcm { @@ -108,7 +109,9 @@ class AudioEncoderPcmU final : public AudioEncoderPcm { private: static const int kSampleRateHz = 8000; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcmU); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ diff --git a/webrtc/modules/audio_coding/codecs/g722/include/audio_decoder_g722.h b/webrtc/modules/audio_coding/codecs/g722/include/audio_decoder_g722.h index 4f0d8eae3a..b9fa68fc48 100644 --- a/webrtc/modules/audio_coding/codecs/g722/include/audio_decoder_g722.h +++ b/webrtc/modules/audio_coding/codecs/g722/include/audio_decoder_g722.h @@ -17,7 +17,7 @@ typedef struct WebRtcG722DecInst G722DecInst; namespace webrtc { -class AudioDecoderG722 : public AudioDecoder { +class AudioDecoderG722 final : public AudioDecoder { public: AudioDecoderG722(); ~AudioDecoderG722() override; @@ -38,7 +38,7 @@ class AudioDecoderG722 : public AudioDecoder { RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722); }; -class AudioDecoderG722Stereo : public AudioDecoder { +class AudioDecoderG722Stereo final : public AudioDecoder { public: AudioDecoderG722Stereo(); ~AudioDecoderG722Stereo() override; @@ -64,9 +64,9 @@ class AudioDecoderG722Stereo : public AudioDecoder { G722DecInst* dec_state_left_; G722DecInst* dec_state_right_; - RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_INCLUDE_AUDIO_DECODER_G722_H_ diff --git a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h index 36f809a9dd..12495c5f48 100644 --- a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h +++ b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h @@ -66,6 +66,7 @@ class AudioEncoderG722 final : public AudioEncoder { uint32_t first_timestamp_in_buffer_; const rtc::scoped_ptr encoders_; rtc::Buffer interleave_buffer_; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderG722); }; } // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h b/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h index ada73e5635..a03a068a39 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_decoder_ilbc.h @@ -17,7 +17,7 @@ typedef struct iLBC_decinst_t_ IlbcDecoderInstance; namespace webrtc { -class AudioDecoderIlbc : public AudioDecoder { +class AudioDecoderIlbc final : public AudioDecoder { public: AudioDecoderIlbc(); ~AudioDecoderIlbc() override; diff --git a/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h b/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h index 7e7e898ddf..0316d2d4c5 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h +++ b/webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h @@ -56,6 +56,7 @@ class AudioEncoderIlbc final : public AudioEncoder { uint32_t first_timestamp_in_buffer_; int16_t input_buffer_[kMaxSamplesPerPacket]; IlbcEncoderInstance* encoder_; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderIlbc); }; } // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t.h b/webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t.h index 714fe2d22a..845af42479 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t.h @@ -50,4 +50,5 @@ class AudioDecoderIsacT final : public AudioDecoder { }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h index 6b361b4146..762757ace7 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h @@ -94,4 +94,5 @@ class AudioEncoderIsacT final : public AudioEncoder { }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc index 4e44b9afec..64742eea4e 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc @@ -9,6 +9,7 @@ */ #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/checks.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h" diff --git a/webrtc/modules/audio_coding/codecs/opus/interface/audio_decoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/interface/audio_decoder_opus.h index 4dd515714d..d28113b778 100644 --- a/webrtc/modules/audio_coding/codecs/opus/interface/audio_decoder_opus.h +++ b/webrtc/modules/audio_coding/codecs/opus/interface/audio_decoder_opus.h @@ -16,7 +16,7 @@ namespace webrtc { -class AudioDecoderOpus : public AudioDecoder { +class AudioDecoderOpus final : public AudioDecoder { public: explicit AudioDecoderOpus(size_t num_channels); ~AudioDecoderOpus() override; diff --git a/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h index 1b7e752694..9659a2bbd3 100644 --- a/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h +++ b/webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h @@ -13,8 +13,7 @@ #include -#include "webrtc/base/checks.h" -#include "webrtc/base/scoped_ptr.h" +#include "webrtc/base/constructormagic.h" #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h" #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" @@ -95,7 +94,9 @@ class AudioEncoderOpus final : public AudioEncoder { std::vector input_buffer_; OpusEncInst* inst_; uint32_t first_timestamp_in_buffer_; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_H_ diff --git a/webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.cc b/webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.cc index 90359a8768..7d07b23a3c 100644 --- a/webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.cc +++ b/webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.cc @@ -15,12 +15,15 @@ namespace webrtc { -AudioDecoderPcm16B::AudioDecoderPcm16B() {} +AudioDecoderPcm16B::AudioDecoderPcm16B(size_t num_channels) + : num_channels_(num_channels) { + RTC_DCHECK_GE(num_channels, 1u); +} void AudioDecoderPcm16B::Reset() {} size_t AudioDecoderPcm16B::Channels() const { - return 1; + return num_channels_; } int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded, @@ -42,13 +45,4 @@ int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded, return static_cast(encoded_len / (2 * Channels())); } -AudioDecoderPcm16BMultiCh::AudioDecoderPcm16BMultiCh(size_t num_channels) - : channels_(num_channels) { - RTC_DCHECK(num_channels > 0); -} - -size_t AudioDecoderPcm16BMultiCh::Channels() const { - return channels_; -} - } // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_decoder_pcm16b.h b/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_decoder_pcm16b.h index 6814c307a9..96131c4d21 100644 --- a/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_decoder_pcm16b.h +++ b/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_decoder_pcm16b.h @@ -16,9 +16,9 @@ namespace webrtc { -class AudioDecoderPcm16B : public AudioDecoder { +class AudioDecoderPcm16B final : public AudioDecoder { public: - AudioDecoderPcm16B(); + explicit AudioDecoderPcm16B(size_t num_channels); void Reset() override; int PacketDuration(const uint8_t* encoded, size_t encoded_len) const override; size_t Channels() const override; @@ -31,18 +31,10 @@ class AudioDecoderPcm16B : public AudioDecoder { SpeechType* speech_type) override; private: + const size_t num_channels_; RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16B); }; -class AudioDecoderPcm16BMultiCh : public AudioDecoderPcm16B { - public: - explicit AudioDecoderPcm16BMultiCh(size_t num_channels); - size_t Channels() const override; - - private: - const size_t channels_; - RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoderPcm16BMultiCh); -}; - } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_PCM16B_INCLUDE_AUDIO_DECODER_PCM16B_H_ diff --git a/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h b/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h index 5d368bce7a..e03da213df 100644 --- a/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h +++ b/webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b.h @@ -38,7 +38,11 @@ class AudioEncoderPcm16B final : public AudioEncoderPcm { uint8_t* encoded) override; int BytesPerSample() const override; + +private: + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcm16B); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_PCM16B_INCLUDE_AUDIO_ENCODER_PCM16B_H_ diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h index 1d35f95877..7837010605 100644 --- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h +++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h @@ -60,7 +60,9 @@ class AudioEncoderCopyRed final : public AudioEncoder { int red_payload_type_; rtc::Buffer secondary_encoded_; EncodedInfoLeaf secondary_info_; + RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCopyRed); }; } // namespace webrtc + #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_RED_AUDIO_ENCODER_COPY_RED_H_ diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc index ca56d452a2..5c3b813830 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc @@ -985,7 +985,7 @@ TEST_F(AcmReceiverBitExactnessOldApi, MAYBE_48kHzOutput) { #define MAYBE_48kHzOutputExternalDecoder 48kHzOutputExternalDecoder #endif TEST_F(AcmReceiverBitExactnessOldApi, MAYBE_48kHzOutputExternalDecoder) { - AudioDecoderPcmU decoder; + AudioDecoderPcmU decoder(1); MockAudioDecoder mock_decoder; // Set expectations on the mock decoder and also delegate the calls to the // real decoder. diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc index 52f327bc61..afad9b1d6b 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc @@ -183,13 +183,13 @@ AudioDecoder* CreateAudioDecoder(NetEqDecoder codec_type) { } switch (codec_type) { case kDecoderPCMu: - return new AudioDecoderPcmU; + return new AudioDecoderPcmU(1); case kDecoderPCMa: - return new AudioDecoderPcmA; + return new AudioDecoderPcmA(1); case kDecoderPCMu_2ch: - return new AudioDecoderPcmUMultiCh(2); + return new AudioDecoderPcmU(2); case kDecoderPCMa_2ch: - return new AudioDecoderPcmAMultiCh(2); + return new AudioDecoderPcmA(2); #ifdef WEBRTC_CODEC_ILBC case kDecoderILBC: return new AudioDecoderIlbc; @@ -207,14 +207,14 @@ AudioDecoder* CreateAudioDecoder(NetEqDecoder codec_type) { case kDecoderPCM16Bwb: case kDecoderPCM16Bswb32kHz: case kDecoderPCM16Bswb48kHz: - return new AudioDecoderPcm16B; + return new AudioDecoderPcm16B(1); case kDecoderPCM16B_2ch: case kDecoderPCM16Bwb_2ch: case kDecoderPCM16Bswb32kHz_2ch: case kDecoderPCM16Bswb48kHz_2ch: - return new AudioDecoderPcm16BMultiCh(2); + return new AudioDecoderPcm16B(2); case kDecoderPCM16B_5ch: - return new AudioDecoderPcm16BMultiCh(5); + return new AudioDecoderPcm16B(5); #ifdef WEBRTC_CODEC_G722 case kDecoderG722: return new AudioDecoderG722; diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc index 537f16cca4..78ebf9f708 100644 --- a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc @@ -286,7 +286,7 @@ class AudioDecoderPcmUTest : public AudioDecoderTest { AudioDecoderPcmUTest() : AudioDecoderTest() { frame_size_ = 160; data_length_ = 10 * frame_size_; - decoder_ = new AudioDecoderPcmU; + decoder_ = new AudioDecoderPcmU(1); AudioEncoderPcmU::Config config; config.frame_size_ms = static_cast(frame_size_ / 8); config.payload_type = payload_type_; @@ -299,7 +299,7 @@ class AudioDecoderPcmATest : public AudioDecoderTest { AudioDecoderPcmATest() : AudioDecoderTest() { frame_size_ = 160; data_length_ = 10 * frame_size_; - decoder_ = new AudioDecoderPcmA; + decoder_ = new AudioDecoderPcmA(1); AudioEncoderPcmA::Config config; config.frame_size_ms = static_cast(frame_size_ / 8); config.payload_type = payload_type_; @@ -313,7 +313,7 @@ class AudioDecoderPcm16BTest : public AudioDecoderTest { codec_input_rate_hz_ = 16000; frame_size_ = 20 * codec_input_rate_hz_ / 1000; data_length_ = 10 * frame_size_; - decoder_ = new AudioDecoderPcm16B; + decoder_ = new AudioDecoderPcm16B(1); assert(decoder_); AudioEncoderPcm16B::Config config; config.sample_rate_hz = codec_input_rate_hz_; diff --git a/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc index e3a0cc17af..e9ebe064eb 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc @@ -10,7 +10,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "webrtc/base/scoped_ptr.h" -#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_decoder_opus.h" #include "webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h" #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h" @@ -21,16 +20,14 @@ using ::testing::_; using ::testing::SetArgPointee; using ::testing::Return; - -class MockAudioDecoderOpus : public AudioDecoderOpus { +class MockAudioDecoder final : public AudioDecoder { public: static const int kPacketDuration = 960; // 48 kHz * 20 ms - explicit MockAudioDecoderOpus(int num_channels) - : AudioDecoderOpus(num_channels), - fec_enabled_(false) { + explicit MockAudioDecoder(size_t num_channels) + : num_channels_(num_channels), fec_enabled_(false) { } - virtual ~MockAudioDecoderOpus() { Die(); } + ~MockAudioDecoder() override { Die(); } MOCK_METHOD0(Die, void()); MOCK_METHOD0(Reset, void()); @@ -49,6 +46,8 @@ class MockAudioDecoderOpus : public AudioDecoderOpus { return fec_enabled_; } + size_t Channels() const override { return num_channels_; } + void set_fec_enabled(bool enable_fec) { fec_enabled_ = enable_fec; } bool fec_enabled() const { return fec_enabled_; } @@ -75,13 +74,14 @@ class MockAudioDecoderOpus : public AudioDecoderOpus { } private: + const size_t num_channels_; bool fec_enabled_; }; class NetEqNetworkStatsTest : public NetEqExternalDecoderTest { public: static const int kPayloadSizeByte = 30; - static const int kFrameSizeMs = 20; // frame size of Opus + static const int kFrameSizeMs = 20; static const int kMaxOutputSize = 960; // 10 ms * 48 kHz * 2 channels. enum logic { @@ -108,7 +108,7 @@ struct NetEqNetworkStatsCheck { }; NetEqNetworkStatsTest(NetEqDecoder codec, - MockAudioDecoderOpus* decoder) + MockAudioDecoder* decoder) : NetEqExternalDecoderTest(codec, decoder), external_decoder_(decoder), samples_per_ms_(CodecSampleRateHz(codec) / 1000), @@ -227,7 +227,7 @@ struct NetEqNetworkStatsCheck { expects.stats_ref.expand_rate = expects.stats_ref.speech_expand_rate = 1065; RunTest(50, expects); - // Next we enable Opus FEC. + // Next we enable FEC. external_decoder_->set_fec_enabled(true); // If FEC fills in the lost packets, no packet loss will be counted. expects.stats_ref.packet_loss_rate = 0; @@ -261,7 +261,7 @@ struct NetEqNetworkStatsCheck { } private: - MockAudioDecoderOpus* external_decoder_; + MockAudioDecoder* external_decoder_; const int samples_per_ms_; const size_t frame_size_samples_; rtc::scoped_ptr rtp_generator_; @@ -272,22 +272,22 @@ struct NetEqNetworkStatsCheck { int16_t output_[kMaxOutputSize]; }; -TEST(NetEqNetworkStatsTest, OpusDecodeFec) { - MockAudioDecoderOpus decoder(1); +TEST(NetEqNetworkStatsTest, DecodeFec) { + MockAudioDecoder decoder(1); NetEqNetworkStatsTest test(kDecoderOpus, &decoder); test.DecodeFecTest(); EXPECT_CALL(decoder, Die()).Times(1); } -TEST(NetEqNetworkStatsTest, StereoOpusDecodeFec) { - MockAudioDecoderOpus decoder(2); +TEST(NetEqNetworkStatsTest, StereoDecodeFec) { + MockAudioDecoder decoder(2); NetEqNetworkStatsTest test(kDecoderOpus, &decoder); test.DecodeFecTest(); EXPECT_CALL(decoder, Die()).Times(1); } TEST(NetEqNetworkStatsTest, NoiseExpansionTest) { - MockAudioDecoderOpus decoder(1); + MockAudioDecoder decoder(1); NetEqNetworkStatsTest test(kDecoderOpus, &decoder); test.NoiseExpansionTest(); EXPECT_CALL(decoder, Die()).Times(1);