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_