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}
This commit is contained in:
kwiberg
2015-09-22 14:06:29 -07:00
committed by Commit bot
parent c1a1b353ec
commit 8967183bf7
21 changed files with 74 additions and 97 deletions

View File

@ -86,7 +86,10 @@ class AudioEncoderCng final : public AudioEncoder {
bool last_frame_active_;
rtc::scoped_ptr<Vad> vad_;
rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCng);
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_

View File

@ -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<int>(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<int>(encoded_len / Channels());
}
size_t AudioDecoderPcmAMultiCh::Channels() const {
return channels_;
}
} // namespace webrtc

View File

@ -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_

View File

@ -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_

View File

@ -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_

View File

@ -66,6 +66,7 @@ class AudioEncoderG722 final : public AudioEncoder {
uint32_t first_timestamp_in_buffer_;
const rtc::scoped_ptr<EncoderState[]> encoders_;
rtc::Buffer interleave_buffer_;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderG722);
};
} // namespace webrtc

View File

@ -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;

View File

@ -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

View File

@ -50,4 +50,5 @@ class AudioDecoderIsacT final : public AudioDecoder {
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_H_

View File

@ -94,4 +94,5 @@ class AudioEncoderIsacT final : public AudioEncoder {
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_

View File

@ -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"

View File

@ -16,7 +16,7 @@
namespace webrtc {
class AudioDecoderOpus : public AudioDecoder {
class AudioDecoderOpus final : public AudioDecoder {
public:
explicit AudioDecoderOpus(size_t num_channels);
~AudioDecoderOpus() override;

View File

@ -13,8 +13,7 @@
#include <vector>
#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<int16_t> 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_

View File

@ -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<int>(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

View File

@ -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_

View File

@ -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_

View File

@ -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_

View File

@ -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.

View File

@ -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;

View File

@ -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<int>(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<int>(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_;

View File

@ -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<test::RtpGenerator> 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);