Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h |
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h |
index a1a4d7069b7a14cdcf374e14c272cf19ef0c9151..e50441b4c269c96220881e565dfd178e1abe78e8 100644 |
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h |
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h |
@@ -18,6 +18,7 @@ |
#include "webrtc/api/audio_codecs/audio_encoder.h" |
#include "webrtc/api/audio_codecs/audio_format.h" |
+#include "webrtc/api/audio_codecs/opus/audio_encoder_opus_config.h" |
#include "webrtc/base/constructormagic.h" |
#include "webrtc/base/optional.h" |
#include "webrtc/base/protobuf_utils.h" |
@@ -33,62 +34,42 @@ struct CodecInst; |
class AudioEncoderOpus final : public AudioEncoder { |
public: |
- enum ApplicationMode { |
- kVoip = 0, |
- kAudio = 1, |
- }; |
- |
- struct Config { |
- Config(); |
- Config(const Config&); |
- ~Config(); |
- Config& operator=(const Config&); |
- |
- bool IsOk() const; |
- int GetBitrateBps() const; |
- // Returns empty if the current bitrate falls within the hysteresis window, |
- // defined by complexity_threshold_bps +/- complexity_threshold_window_bps. |
- // Otherwise, returns the current complexity depending on whether the |
- // current bitrate is above or below complexity_threshold_bps. |
- rtc::Optional<int> GetNewComplexity() const; |
- |
- static constexpr int kDefaultFrameSizeMs = 20; |
- int frame_size_ms = kDefaultFrameSizeMs; |
- size_t num_channels = 1; |
- int payload_type = 120; |
- ApplicationMode application = kVoip; |
- rtc::Optional<int> bitrate_bps; // Unset means to use default value. |
- bool fec_enabled = false; |
- bool cbr_enabled = false; |
- int max_playback_rate_hz = 48000; |
- int complexity = kDefaultComplexity; |
- // This value may change in the struct's constructor. |
- int low_rate_complexity = kDefaultComplexity; |
- // low_rate_complexity is used when the bitrate is below this threshold. |
- int complexity_threshold_bps = 12500; |
- int complexity_threshold_window_bps = 1500; |
- bool dtx_enabled = false; |
- std::vector<int> supported_frame_lengths_ms; |
- int uplink_bandwidth_update_interval_ms = 200; |
- |
- 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 |
- }; |
- |
+ static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); |
+ static AudioCodecInfo QueryAudioEncoder(const AudioEncoderOpusConfig& config); |
+ static std::unique_ptr<AudioEncoder> MakeAudioEncoder( |
+ const AudioEncoderOpusConfig&, |
+ int payload_type); |
+ |
+ // NOTE: This alias will soon go away. See |
+ // https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 |
+ using Config = AudioEncoderOpusConfig; |
+ |
+ // NOTE: This function will soon go away. See |
+ // https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 |
static Config CreateConfig(int payload_type, const SdpAudioFormat& format); |
- static Config CreateConfig(const CodecInst& codec_inst); |
+ |
+ static AudioEncoderOpusConfig CreateConfig(const CodecInst& codec_inst); |
+ static rtc::Optional<AudioEncoderOpusConfig> SdpToConfig( |
+ const SdpAudioFormat& format); |
+ |
+ // Returns empty if the current bitrate falls within the hysteresis window, |
+ // defined by complexity_threshold_bps +/- complexity_threshold_window_bps. |
+ // Otherwise, returns the current complexity depending on whether the |
+ // current bitrate is above or below complexity_threshold_bps. |
+ static rtc::Optional<int> GetNewComplexity( |
+ const AudioEncoderOpusConfig& config); |
using AudioNetworkAdaptorCreator = |
std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, |
RtcEventLog*)>; |
+ |
+ // NOTE: This constructor will soon go away. See |
+ // https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 |
+ AudioEncoderOpus(const AudioEncoderOpusConfig& config); |
+ |
AudioEncoderOpus( |
- const Config& config, |
+ const AudioEncoderOpusConfig& config, |
+ int payload_type, |
AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr, |
std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr); |
@@ -110,9 +91,9 @@ class AudioEncoderOpus final : public AudioEncoder { |
void Reset() override; |
bool SetFec(bool enable) override; |
- // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice |
- // being inactive. During that, it still sends 2 packets (one for content, one |
- // for signaling) about every 400 ms. |
+ // Set Opus DTX. Once enabled, Opus stops transmission, when it detects |
+ // voice being inactive. During that, it still sends 2 packets (one for |
+ // content, one for signaling) about every 400 ms. |
bool SetDtx(bool enable) override; |
bool GetDtx() const override; |
@@ -138,7 +119,9 @@ class AudioEncoderOpus final : public AudioEncoder { |
// Getters for testing. |
float packet_loss_rate() const { return packet_loss_rate_; } |
- ApplicationMode application() const { return config_.application; } |
+ AudioEncoderOpusConfig::ApplicationMode application() const { |
+ return config_.application; |
+ } |
bool fec_enabled() const { return config_.fec_enabled; } |
size_t num_channels_to_encode() const { return num_channels_to_encode_; } |
int next_frame_length_ms() const { return next_frame_length_ms_; } |
@@ -154,7 +137,7 @@ class AudioEncoderOpus final : public AudioEncoder { |
size_t Num10msFramesPerPacket() const; |
size_t SamplesPer10msFrame() const; |
size_t SufficientOutputBufferSize() const; |
- bool RecreateEncoderInstance(const Config& config); |
+ bool RecreateEncoderInstance(const AudioEncoderOpusConfig& config); |
void SetFrameLength(int frame_length_ms); |
void SetNumChannelsToEncode(size_t num_channels_to_encode); |
void SetProjectedPacketLossRate(float fraction); |
@@ -170,7 +153,8 @@ class AudioEncoderOpus final : public AudioEncoder { |
void MaybeUpdateUplinkBandwidth(); |
- Config config_; |
+ AudioEncoderOpusConfig config_; |
+ const int payload_type_; |
const bool send_side_bwe_with_overhead_; |
float packet_loss_rate_; |
std::vector<int16_t> input_buffer_; |