Fold AudioEncoderMutable into AudioEncoder

It makes more sense to combine the two interfaces, since there wasn't
a clear line separating them. The result is a combined interface with
just over a dozen methods, half of which need to be implemented by
every subclass, while the other half have sensible (and trivial)
default implementations and are implemented only by the few subclasses
that need non-default behavior.

Review URL: https://codereview.webrtc.org/1322973004

Cr-Commit-Position: refs/heads/master@{#9894}
This commit is contained in:
kwiberg
2015-09-08 05:57:53 -07:00
committed by Commit bot
parent cd3c475407
commit 12cfc9b4da
40 changed files with 851 additions and 984 deletions

View File

@ -20,53 +20,57 @@
namespace webrtc {
// Deleter for use with scoped_ptr.
struct CngInstDeleter {
void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); }
};
class Vad;
class AudioEncoderCng final : public AudioEncoder {
public:
struct Config {
Config();
bool IsOk() const;
int num_channels;
int payload_type;
int num_channels = 1;
int payload_type = 13;
// Caller keeps ownership of the AudioEncoder object.
AudioEncoder* speech_encoder;
Vad::Aggressiveness vad_mode;
int sid_frame_interval_ms;
int num_cng_coefficients;
AudioEncoder* speech_encoder = nullptr;
Vad::Aggressiveness vad_mode = Vad::kVadNormal;
int sid_frame_interval_ms = 100;
int num_cng_coefficients = 8;
// The Vad pointer is mainly for testing. If a NULL pointer is passed, the
// AudioEncoderCng creates (and destroys) a Vad object internally. If an
// object is passed, the AudioEncoderCng assumes ownership of the Vad
// object.
Vad* vad;
Vad* vad = nullptr;
};
explicit AudioEncoderCng(const Config& config);
~AudioEncoderCng() override;
size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
int NumChannels() const override;
size_t MaxEncodedBytes() const override;
int RtpTimestampRateHz() const override;
size_t Num10MsFramesInNextPacket() const override;
size_t Max10MsFramesInAPacket() const override;
int GetTargetBitrate() const override;
void SetTargetBitrate(int bits_per_second) override;
void SetProjectedPacketLossRate(double fraction) override;
EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
const int16_t* audio,
size_t max_encoded_bytes,
uint8_t* encoded) override;
void Reset() override;
bool SetFec(bool enable) override;
bool SetDtx(bool enable) override;
bool SetApplication(Application application) override;
bool SetMaxPlaybackRate(int frequency_hz) override;
void SetProjectedPacketLossRate(double fraction) override;
void SetTargetBitrate(int target_bps) override;
void SetMaxBitrate(int max_bps) override;
void SetMaxPayloadSize(int max_payload_size_bytes) override;
private:
// Deleter for use with scoped_ptr. E.g., use as
// rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_;
struct CngInstDeleter {
inline void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); }
};
EncodedInfo EncodePassive(size_t frames_to_encode,
size_t max_encoded_bytes,
uint8_t* encoded);
@ -78,6 +82,7 @@ class AudioEncoderCng final : public AudioEncoder {
AudioEncoder* speech_encoder_;
const int cng_payload_type_;
const int num_cng_coefficients_;
const int sid_frame_interval_ms_;
std::vector<int16_t> speech_buffer_;
std::vector<uint32_t> rtp_timestamps_;
bool last_frame_active_;