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:
@ -13,15 +13,14 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder_mutable_impl.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// NOTE: This class has neither ThreadChecker, nor locks. The owner of an
|
||||
// AudioEncoderOpus object must ensure that it is not accessed concurrently.
|
||||
struct CodecInst;
|
||||
|
||||
class AudioEncoderOpus final : public AudioEncoder {
|
||||
public:
|
||||
@ -31,60 +30,44 @@ class AudioEncoderOpus final : public AudioEncoder {
|
||||
};
|
||||
|
||||
struct Config {
|
||||
Config();
|
||||
bool IsOk() const;
|
||||
int frame_size_ms;
|
||||
int num_channels;
|
||||
int payload_type;
|
||||
ApplicationMode application;
|
||||
int bitrate_bps;
|
||||
bool fec_enabled;
|
||||
int max_playback_rate_hz;
|
||||
int complexity;
|
||||
bool dtx_enabled;
|
||||
int frame_size_ms = 20;
|
||||
int num_channels = 1;
|
||||
int payload_type = 120;
|
||||
ApplicationMode application = kVoip;
|
||||
int bitrate_bps = 64000;
|
||||
bool fec_enabled = false;
|
||||
int max_playback_rate_hz = 48000;
|
||||
int complexity = kDefaultComplexity;
|
||||
bool dtx_enabled = false;
|
||||
|
||||
private:
|
||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
|
||||
// If we are on Android, iOS and/or ARM, use a lower complexity setting as
|
||||
// default, to save encoder complexity.
|
||||
static const int kDefaultComplexity = 5;
|
||||
#else
|
||||
static const int kDefaultComplexity = 9;
|
||||
#endif
|
||||
};
|
||||
|
||||
explicit AudioEncoderOpus(const Config& config);
|
||||
explicit AudioEncoderOpus(const CodecInst& codec_inst);
|
||||
~AudioEncoderOpus() override;
|
||||
|
||||
size_t MaxEncodedBytes() const override;
|
||||
int SampleRateHz() const override;
|
||||
int NumChannels() const override;
|
||||
size_t MaxEncodedBytes() 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;
|
||||
|
||||
double packet_loss_rate() const { return packet_loss_rate_; }
|
||||
ApplicationMode application() const { return application_; }
|
||||
bool dtx_enabled() const { return dtx_enabled_; }
|
||||
|
||||
EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) override;
|
||||
|
||||
private:
|
||||
const size_t num_10ms_frames_per_packet_;
|
||||
const int num_channels_;
|
||||
const int payload_type_;
|
||||
const ApplicationMode application_;
|
||||
int bitrate_bps_;
|
||||
const bool dtx_enabled_;
|
||||
const size_t samples_per_10ms_frame_;
|
||||
std::vector<int16_t> input_buffer_;
|
||||
OpusEncInst* inst_;
|
||||
uint32_t first_timestamp_in_buffer_;
|
||||
double packet_loss_rate_;
|
||||
};
|
||||
|
||||
struct CodecInst;
|
||||
|
||||
class AudioEncoderMutableOpus
|
||||
: public AudioEncoderMutableImpl<AudioEncoderOpus> {
|
||||
public:
|
||||
explicit AudioEncoderMutableOpus(const CodecInst& codec_inst);
|
||||
void Reset() override;
|
||||
bool SetFec(bool enable) override;
|
||||
|
||||
// Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice
|
||||
@ -94,18 +77,24 @@ class AudioEncoderMutableOpus
|
||||
|
||||
bool SetApplication(Application application) override;
|
||||
bool SetMaxPlaybackRate(int frequency_hz) override;
|
||||
AudioEncoderOpus::ApplicationMode application() const {
|
||||
CriticalSectionScoped cs(encoder_lock_.get());
|
||||
return encoder()->application();
|
||||
}
|
||||
double packet_loss_rate() const {
|
||||
CriticalSectionScoped cs(encoder_lock_.get());
|
||||
return encoder()->packet_loss_rate();
|
||||
}
|
||||
bool dtx_enabled() const {
|
||||
CriticalSectionScoped cs(encoder_lock_.get());
|
||||
return encoder()->dtx_enabled();
|
||||
}
|
||||
void SetProjectedPacketLossRate(double fraction) override;
|
||||
void SetTargetBitrate(int target_bps) override;
|
||||
|
||||
// Getters for testing.
|
||||
double packet_loss_rate() const { return packet_loss_rate_; }
|
||||
ApplicationMode application() const { return config_.application; }
|
||||
bool dtx_enabled() const { return config_.dtx_enabled; }
|
||||
|
||||
private:
|
||||
int Num10msFramesPerPacket() const;
|
||||
int SamplesPer10msFrame() const;
|
||||
bool RecreateEncoderInstance(const Config& config);
|
||||
|
||||
Config config_;
|
||||
double packet_loss_rate_;
|
||||
std::vector<int16_t> input_buffer_;
|
||||
OpusEncInst* inst_;
|
||||
uint32_t first_timestamp_in_buffer_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user