| Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
|
| diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
|
| index a4ae2ca6d5983e6ae939cbe9113e2c609578dde9..be32aef152e80e05feed810d415f5718ca04a869 100644
|
| --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
|
| +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
|
| @@ -47,6 +47,11 @@
|
| constexpr int kOpusBitrateNbBps = 12000;
|
| constexpr int kOpusBitrateWbBps = 20000;
|
| constexpr int kOpusBitrateFbBps = 32000;
|
| +
|
| +// Opus API allows a min bitrate of 500bps, but Opus documentation suggests
|
| +// bitrate should be in the range of 6000 to 510000, inclusive.
|
| +constexpr int kOpusMinBitrateBps = 6000;
|
| +constexpr int kOpusMaxBitrateBps = 510000;
|
|
|
| constexpr int kSampleRateHz = 48000;
|
| constexpr int kDefaultMaxPlaybackRate = 48000;
|
| @@ -128,8 +133,8 @@
|
| return kOpusBitrateFbBps * rtc::dchecked_cast<int>(num_channels);
|
| }
|
| }();
|
| - RTC_DCHECK_GE(bitrate, AudioEncoderOpusConfig::kMinBitrateBps);
|
| - RTC_DCHECK_LE(bitrate, AudioEncoderOpusConfig::kMaxBitrateBps);
|
| + RTC_DCHECK_GE(bitrate, kOpusMinBitrateBps);
|
| + RTC_DCHECK_LE(bitrate, kOpusMaxBitrateBps);
|
| return bitrate;
|
| }
|
|
|
| @@ -145,8 +150,7 @@
|
| const auto bitrate = rtc::StringToNumber<int>(*bitrate_param);
|
| if (bitrate) {
|
| const int chosen_bitrate =
|
| - std::max(AudioEncoderOpusConfig::kMinBitrateBps,
|
| - std::min(*bitrate, AudioEncoderOpusConfig::kMaxBitrateBps));
|
| + std::max(kOpusMinBitrateBps, std::min(*bitrate, kOpusMaxBitrateBps));
|
| if (bitrate != chosen_bitrate) {
|
| LOG(LS_WARNING) << "Invalid maxaveragebitrate " << *bitrate
|
| << " clamped to " << chosen_bitrate;
|
| @@ -191,7 +195,7 @@
|
| return *(std::end(kOpusSupportedFrameLengths) - 1);
|
| }
|
|
|
| - return AudioEncoderOpusConfig::kDefaultFrameSizeMs;
|
| + return AudioEncoderOpus::Config::kDefaultFrameSizeMs;
|
| }
|
|
|
| void FindSupportedFrameLengths(int min_frame_length_ms,
|
| @@ -207,14 +211,9 @@
|
| RTC_DCHECK(std::is_sorted(out->begin(), out->end()));
|
| }
|
|
|
| -int GetBitrateBps(const AudioEncoderOpusConfig& config) {
|
| - RTC_DCHECK(config.IsOk());
|
| - return config.bitrate_bps;
|
| -}
|
| -
|
| } // namespace
|
|
|
| -rtc::Optional<AudioCodecInfo> AudioEncoderOpusImpl::QueryAudioEncoder(
|
| +rtc::Optional<AudioCodecInfo> AudioEncoderOpus::QueryAudioEncoder(
|
| const SdpAudioFormat& format) {
|
| if (STR_CASE_CMP(format.name.c_str(), GetPayloadName()) == 0 &&
|
| format.clockrate_hz == 48000 && format.num_channels == 2) {
|
| @@ -222,9 +221,8 @@
|
| const int bitrate =
|
| CalculateBitrate(GetMaxPlaybackRate(format), num_channels,
|
| GetFormatParameter(format, "maxaveragebitrate"));
|
| - AudioCodecInfo info(48000, num_channels, bitrate,
|
| - AudioEncoderOpusConfig::kMinBitrateBps,
|
| - AudioEncoderOpusConfig::kMaxBitrateBps);
|
| + AudioCodecInfo info(48000, num_channels, bitrate, kOpusMinBitrateBps,
|
| + kOpusMaxBitrateBps);
|
| info.allow_comfort_noise = false;
|
| info.supports_network_adaption = true;
|
|
|
| @@ -233,44 +231,46 @@
|
| return rtc::Optional<AudioCodecInfo>();
|
| }
|
|
|
| -AudioEncoderOpusConfig AudioEncoderOpusImpl::CreateConfig(
|
| +AudioEncoderOpus::Config AudioEncoderOpus::CreateConfig(
|
| const CodecInst& codec_inst) {
|
| - AudioEncoderOpusConfig config;
|
| + AudioEncoderOpus::Config config;
|
| config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48);
|
| config.num_channels = codec_inst.channels;
|
| - config.bitrate_bps = codec_inst.rate;
|
| - config.application = config.num_channels == 1
|
| - ? AudioEncoderOpusConfig::ApplicationMode::kVoip
|
| - : AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
| + config.bitrate_bps = rtc::Optional<int>(codec_inst.rate);
|
| + config.payload_type = codec_inst.pltype;
|
| + config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip
|
| + : AudioEncoderOpus::kAudio;
|
| config.supported_frame_lengths_ms.push_back(config.frame_size_ms);
|
| +#if WEBRTC_OPUS_VARIABLE_COMPLEXITY
|
| + config.low_rate_complexity = 9;
|
| +#endif
|
| return config;
|
| }
|
|
|
| -rtc::Optional<AudioEncoderOpusConfig> AudioEncoderOpusImpl::SdpToConfig(
|
| +AudioEncoderOpus::Config AudioEncoderOpus::CreateConfig(
|
| + int payload_type,
|
| const SdpAudioFormat& format) {
|
| - if (STR_CASE_CMP(format.name.c_str(), "opus") != 0 ||
|
| - format.clockrate_hz != 48000 || format.num_channels != 2) {
|
| - return rtc::Optional<AudioEncoderOpusConfig>();
|
| - }
|
| -
|
| - AudioEncoderOpusConfig config;
|
| + AudioEncoderOpus::Config config;
|
| +
|
| config.num_channels = GetChannelCount(format);
|
| config.frame_size_ms = GetFrameSizeMs(format);
|
| config.max_playback_rate_hz = GetMaxPlaybackRate(format);
|
| config.fec_enabled = (GetFormatParameter(format, "useinbandfec") == "1");
|
| config.dtx_enabled = (GetFormatParameter(format, "usedtx") == "1");
|
| config.cbr_enabled = (GetFormatParameter(format, "cbr") == "1");
|
| - config.bitrate_bps =
|
| + config.bitrate_bps = rtc::Optional<int>(
|
| CalculateBitrate(config.max_playback_rate_hz, config.num_channels,
|
| - GetFormatParameter(format, "maxaveragebitrate"));
|
| - config.application = config.num_channels == 1
|
| - ? AudioEncoderOpusConfig::ApplicationMode::kVoip
|
| - : AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
| + GetFormatParameter(format, "maxaveragebitrate")));
|
| + config.payload_type = payload_type;
|
| + config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip
|
| + : AudioEncoderOpus::kAudio;
|
| +#if WEBRTC_OPUS_VARIABLE_COMPLEXITY
|
| + config.low_rate_complexity = 9;
|
| +#endif
|
|
|
| constexpr int kMinANAFrameLength = kANASupportedFrameLengths[0];
|
| constexpr int kMaxANAFrameLength =
|
| kANASupportedFrameLengths[arraysize(kANASupportedFrameLengths) - 1];
|
| -
|
| // For now, minptime and maxptime are only used with ANA. If ptime is outside
|
| // of this range, it will get adjusted once ANA takes hold. Ideally, we'd know
|
| // if ANA was to be used when setting up the config, and adjust accordingly.
|
| @@ -281,28 +281,10 @@
|
|
|
| FindSupportedFrameLengths(min_frame_length_ms, max_frame_length_ms,
|
| &config.supported_frame_lengths_ms);
|
| - RTC_DCHECK(config.IsOk());
|
| - return rtc::Optional<AudioEncoderOpusConfig>(config);
|
| -}
|
| -
|
| -rtc::Optional<int> AudioEncoderOpusImpl::GetNewComplexity(
|
| - const AudioEncoderOpusConfig& config) {
|
| - RTC_DCHECK(config.IsOk());
|
| - const int bitrate_bps = GetBitrateBps(config);
|
| - if (bitrate_bps >= config.complexity_threshold_bps -
|
| - config.complexity_threshold_window_bps &&
|
| - bitrate_bps <= config.complexity_threshold_bps +
|
| - config.complexity_threshold_window_bps) {
|
| - // Within the hysteresis window; make no change.
|
| - return rtc::Optional<int>();
|
| - } else {
|
| - return rtc::Optional<int>(bitrate_bps <= config.complexity_threshold_bps
|
| - ? config.low_rate_complexity
|
| - : config.complexity);
|
| - }
|
| -}
|
| -
|
| -class AudioEncoderOpusImpl::PacketLossFractionSmoother {
|
| + return config;
|
| +}
|
| +
|
| +class AudioEncoderOpus::PacketLossFractionSmoother {
|
| public:
|
| explicit PacketLossFractionSmoother()
|
| : last_sample_time_ms_(rtc::TimeMillis()),
|
| @@ -329,13 +311,58 @@
|
| rtc::ExpFilter smoother_;
|
| };
|
|
|
| -AudioEncoderOpusImpl::AudioEncoderOpusImpl(
|
| - const AudioEncoderOpusConfig& config,
|
| - int payload_type,
|
| +AudioEncoderOpus::Config::Config() {
|
| +#if WEBRTC_OPUS_VARIABLE_COMPLEXITY
|
| + low_rate_complexity = 9;
|
| +#endif
|
| +}
|
| +AudioEncoderOpus::Config::Config(const Config&) = default;
|
| +AudioEncoderOpus::Config::~Config() = default;
|
| +auto AudioEncoderOpus::Config::operator=(const Config&) -> Config& = default;
|
| +
|
| +bool AudioEncoderOpus::Config::IsOk() const {
|
| + if (frame_size_ms <= 0 || frame_size_ms % 10 != 0)
|
| + return false;
|
| + if (num_channels != 1 && num_channels != 2)
|
| + return false;
|
| + if (bitrate_bps &&
|
| + (*bitrate_bps < kOpusMinBitrateBps || *bitrate_bps > kOpusMaxBitrateBps))
|
| + return false;
|
| + if (complexity < 0 || complexity > 10)
|
| + return false;
|
| + if (low_rate_complexity < 0 || low_rate_complexity > 10)
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| +int AudioEncoderOpus::Config::GetBitrateBps() const {
|
| + RTC_DCHECK(IsOk());
|
| + if (bitrate_bps)
|
| + return *bitrate_bps; // Explicitly set value.
|
| + else
|
| + return num_channels == 1 ? 32000 : 64000; // Default value.
|
| +}
|
| +
|
| +rtc::Optional<int> AudioEncoderOpus::Config::GetNewComplexity() const {
|
| + RTC_DCHECK(IsOk());
|
| + const int bitrate_bps = GetBitrateBps();
|
| + if (bitrate_bps >=
|
| + complexity_threshold_bps - complexity_threshold_window_bps &&
|
| + bitrate_bps <=
|
| + complexity_threshold_bps + complexity_threshold_window_bps) {
|
| + // Within the hysteresis window; make no change.
|
| + return rtc::Optional<int>();
|
| + }
|
| + return bitrate_bps <= complexity_threshold_bps
|
| + ? rtc::Optional<int>(low_rate_complexity)
|
| + : rtc::Optional<int>(complexity);
|
| +}
|
| +
|
| +AudioEncoderOpus::AudioEncoderOpus(
|
| + const Config& config,
|
| AudioNetworkAdaptorCreator&& audio_network_adaptor_creator,
|
| std::unique_ptr<SmoothingFilter> bitrate_smoother)
|
| - : payload_type_(payload_type),
|
| - send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled(
|
| + : send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled(
|
| "WebRTC-SendSideBwe-WithOverhead")),
|
| packet_loss_rate_(0.0),
|
| inst_(nullptr),
|
| @@ -355,42 +382,42 @@
|
| RTC_CHECK(RecreateEncoderInstance(config));
|
| }
|
|
|
| -AudioEncoderOpusImpl::AudioEncoderOpusImpl(const CodecInst& codec_inst)
|
| - : AudioEncoderOpusImpl(CreateConfig(codec_inst), codec_inst.pltype) {}
|
| -
|
| -AudioEncoderOpusImpl::AudioEncoderOpusImpl(int payload_type,
|
| - const SdpAudioFormat& format)
|
| - : AudioEncoderOpusImpl(*SdpToConfig(format), payload_type) {}
|
| -
|
| -AudioEncoderOpusImpl::~AudioEncoderOpusImpl() {
|
| +AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst)
|
| + : AudioEncoderOpus(CreateConfig(codec_inst), nullptr) {}
|
| +
|
| +AudioEncoderOpus::AudioEncoderOpus(int payload_type,
|
| + const SdpAudioFormat& format)
|
| + : AudioEncoderOpus(CreateConfig(payload_type, format), nullptr) {}
|
| +
|
| +AudioEncoderOpus::~AudioEncoderOpus() {
|
| RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
| }
|
|
|
| -int AudioEncoderOpusImpl::SampleRateHz() const {
|
| +int AudioEncoderOpus::SampleRateHz() const {
|
| return kSampleRateHz;
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::NumChannels() const {
|
| +size_t AudioEncoderOpus::NumChannels() const {
|
| return config_.num_channels;
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::Num10MsFramesInNextPacket() const {
|
| +size_t AudioEncoderOpus::Num10MsFramesInNextPacket() const {
|
| return Num10msFramesPerPacket();
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::Max10MsFramesInAPacket() const {
|
| +size_t AudioEncoderOpus::Max10MsFramesInAPacket() const {
|
| return Num10msFramesPerPacket();
|
| }
|
|
|
| -int AudioEncoderOpusImpl::GetTargetBitrate() const {
|
| - return GetBitrateBps(config_);
|
| -}
|
| -
|
| -void AudioEncoderOpusImpl::Reset() {
|
| +int AudioEncoderOpus::GetTargetBitrate() const {
|
| + return config_.GetBitrateBps();
|
| +}
|
| +
|
| +void AudioEncoderOpus::Reset() {
|
| RTC_CHECK(RecreateEncoderInstance(config_));
|
| }
|
|
|
| -bool AudioEncoderOpusImpl::SetFec(bool enable) {
|
| +bool AudioEncoderOpus::SetFec(bool enable) {
|
| if (enable) {
|
| RTC_CHECK_EQ(0, WebRtcOpus_EnableFec(inst_));
|
| } else {
|
| @@ -400,7 +427,7 @@
|
| return true;
|
| }
|
|
|
| -bool AudioEncoderOpusImpl::SetDtx(bool enable) {
|
| +bool AudioEncoderOpus::SetDtx(bool enable) {
|
| if (enable) {
|
| RTC_CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_));
|
| } else {
|
| @@ -410,30 +437,30 @@
|
| return true;
|
| }
|
|
|
| -bool AudioEncoderOpusImpl::GetDtx() const {
|
| +bool AudioEncoderOpus::GetDtx() const {
|
| return config_.dtx_enabled;
|
| }
|
|
|
| -bool AudioEncoderOpusImpl::SetApplication(Application application) {
|
| +bool AudioEncoderOpus::SetApplication(Application application) {
|
| auto conf = config_;
|
| switch (application) {
|
| case Application::kSpeech:
|
| - conf.application = AudioEncoderOpusConfig::ApplicationMode::kVoip;
|
| + conf.application = AudioEncoderOpus::kVoip;
|
| break;
|
| case Application::kAudio:
|
| - conf.application = AudioEncoderOpusConfig::ApplicationMode::kAudio;
|
| + conf.application = AudioEncoderOpus::kAudio;
|
| break;
|
| }
|
| return RecreateEncoderInstance(conf);
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetMaxPlaybackRate(int frequency_hz) {
|
| +void AudioEncoderOpus::SetMaxPlaybackRate(int frequency_hz) {
|
| auto conf = config_;
|
| conf.max_playback_rate_hz = frequency_hz;
|
| RTC_CHECK(RecreateEncoderInstance(conf));
|
| }
|
|
|
| -bool AudioEncoderOpusImpl::EnableAudioNetworkAdaptor(
|
| +bool AudioEncoderOpus::EnableAudioNetworkAdaptor(
|
| const std::string& config_string,
|
| RtcEventLog* event_log) {
|
| audio_network_adaptor_ =
|
| @@ -441,11 +468,11 @@
|
| return audio_network_adaptor_.get() != nullptr;
|
| }
|
|
|
| -void AudioEncoderOpusImpl::DisableAudioNetworkAdaptor() {
|
| +void AudioEncoderOpus::DisableAudioNetworkAdaptor() {
|
| audio_network_adaptor_.reset(nullptr);
|
| }
|
|
|
| -void AudioEncoderOpusImpl::OnReceivedUplinkPacketLossFraction(
|
| +void AudioEncoderOpus::OnReceivedUplinkPacketLossFraction(
|
| float uplink_packet_loss_fraction) {
|
| if (!audio_network_adaptor_) {
|
| packet_loss_fraction_smoother_->AddSample(uplink_packet_loss_fraction);
|
| @@ -457,7 +484,7 @@
|
| ApplyAudioNetworkAdaptor();
|
| }
|
|
|
| -void AudioEncoderOpusImpl::OnReceivedUplinkRecoverablePacketLossFraction(
|
| +void AudioEncoderOpus::OnReceivedUplinkRecoverablePacketLossFraction(
|
| float uplink_recoverable_packet_loss_fraction) {
|
| if (!audio_network_adaptor_)
|
| return;
|
| @@ -466,7 +493,7 @@
|
| ApplyAudioNetworkAdaptor();
|
| }
|
|
|
| -void AudioEncoderOpusImpl::OnReceivedUplinkBandwidth(
|
| +void AudioEncoderOpus::OnReceivedUplinkBandwidth(
|
| int target_audio_bitrate_bps,
|
| rtc::Optional<int64_t> probing_interval_ms) {
|
| if (audio_network_adaptor_) {
|
| @@ -490,30 +517,28 @@
|
| } else if (send_side_bwe_with_overhead_) {
|
| if (!overhead_bytes_per_packet_) {
|
| LOG(LS_INFO)
|
| - << "AudioEncoderOpusImpl: Overhead unknown, target audio bitrate "
|
| + << "AudioEncoderOpus: Overhead unknown, target audio bitrate "
|
| << target_audio_bitrate_bps << " bps is ignored.";
|
| return;
|
| }
|
| const int overhead_bps = static_cast<int>(
|
| *overhead_bytes_per_packet_ * 8 * 100 / Num10MsFramesInNextPacket());
|
| - SetTargetBitrate(
|
| - std::min(AudioEncoderOpusConfig::kMaxBitrateBps,
|
| - std::max(AudioEncoderOpusConfig::kMinBitrateBps,
|
| - target_audio_bitrate_bps - overhead_bps)));
|
| + SetTargetBitrate(std::min(
|
| + kOpusMaxBitrateBps,
|
| + std::max(kOpusMinBitrateBps, target_audio_bitrate_bps - overhead_bps)));
|
| } else {
|
| SetTargetBitrate(target_audio_bitrate_bps);
|
| }
|
| }
|
|
|
| -void AudioEncoderOpusImpl::OnReceivedRtt(int rtt_ms) {
|
| +void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) {
|
| if (!audio_network_adaptor_)
|
| return;
|
| audio_network_adaptor_->SetRtt(rtt_ms);
|
| ApplyAudioNetworkAdaptor();
|
| }
|
|
|
| -void AudioEncoderOpusImpl::OnReceivedOverhead(
|
| - size_t overhead_bytes_per_packet) {
|
| +void AudioEncoderOpus::OnReceivedOverhead(size_t overhead_bytes_per_packet) {
|
| if (audio_network_adaptor_) {
|
| audio_network_adaptor_->SetOverhead(overhead_bytes_per_packet);
|
| ApplyAudioNetworkAdaptor();
|
| @@ -523,9 +548,8 @@
|
| }
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetReceiverFrameLengthRange(
|
| - int min_frame_length_ms,
|
| - int max_frame_length_ms) {
|
| +void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms,
|
| + int max_frame_length_ms) {
|
| // Ensure that |SetReceiverFrameLengthRange| is called before
|
| // |EnableAudioNetworkAdaptor|, otherwise we need to recreate
|
| // |audio_network_adaptor_|, which is not a needed use case.
|
| @@ -534,7 +558,7 @@
|
| &config_.supported_frame_lengths_ms);
|
| }
|
|
|
| -AudioEncoder::EncodedInfo AudioEncoderOpusImpl::EncodeImpl(
|
| +AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl(
|
| uint32_t rtp_timestamp,
|
| rtc::ArrayView<const int16_t> audio,
|
| rtc::Buffer* encoded) {
|
| @@ -573,26 +597,26 @@
|
| config_.frame_size_ms = next_frame_length_ms_;
|
|
|
| info.encoded_timestamp = first_timestamp_in_buffer_;
|
| - info.payload_type = payload_type_;
|
| + info.payload_type = config_.payload_type;
|
| info.send_even_if_empty = true; // Allows Opus to send empty packets.
|
| info.speech = (info.encoded_bytes > 0);
|
| info.encoder_type = CodecType::kOpus;
|
| return info;
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::Num10msFramesPerPacket() const {
|
| +size_t AudioEncoderOpus::Num10msFramesPerPacket() const {
|
| return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10));
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::SamplesPer10msFrame() const {
|
| +size_t AudioEncoderOpus::SamplesPer10msFrame() const {
|
| return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels;
|
| }
|
|
|
| -size_t AudioEncoderOpusImpl::SufficientOutputBufferSize() const {
|
| +size_t AudioEncoderOpus::SufficientOutputBufferSize() const {
|
| // Calculate the number of bytes we expect the encoder to produce,
|
| // then multiply by two to give a wide margin for error.
|
| const size_t bytes_per_millisecond =
|
| - static_cast<size_t>(GetBitrateBps(config_) / (1000 * 8) + 1);
|
| + static_cast<size_t>(config_.GetBitrateBps() / (1000 * 8) + 1);
|
| const size_t approx_encoded_bytes =
|
| Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
|
| return 2 * approx_encoded_bytes;
|
| @@ -601,8 +625,7 @@
|
| // If the given config is OK, recreate the Opus encoder instance with those
|
| // settings, save the config, and return true. Otherwise, do nothing and return
|
| // false.
|
| -bool AudioEncoderOpusImpl::RecreateEncoderInstance(
|
| - const AudioEncoderOpusConfig& config) {
|
| +bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) {
|
| if (!config.IsOk())
|
| return false;
|
| config_ = config;
|
| @@ -610,13 +633,9 @@
|
| RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
|
| input_buffer_.clear();
|
| input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame());
|
| - RTC_CHECK_EQ(0, WebRtcOpus_EncoderCreate(
|
| - &inst_, config.num_channels,
|
| - config.application ==
|
| - AudioEncoderOpusConfig::ApplicationMode::kVoip
|
| - ? 0
|
| - : 1));
|
| - RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, GetBitrateBps(config)));
|
| + RTC_CHECK_EQ(0, WebRtcOpus_EncoderCreate(&inst_, config.num_channels,
|
| + config.application));
|
| + RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config.GetBitrateBps()));
|
| if (config.fec_enabled) {
|
| RTC_CHECK_EQ(0, WebRtcOpus_EnableFec(inst_));
|
| } else {
|
| @@ -626,7 +645,7 @@
|
| 0, WebRtcOpus_SetMaxPlaybackRate(inst_, config.max_playback_rate_hz));
|
| // Use the default complexity if the start bitrate is within the hysteresis
|
| // window.
|
| - complexity_ = GetNewComplexity(config).value_or(config.complexity);
|
| + complexity_ = config.GetNewComplexity().value_or(config.complexity);
|
| RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_));
|
| if (config.dtx_enabled) {
|
| RTC_CHECK_EQ(0, WebRtcOpus_EnableDtx(inst_));
|
| @@ -646,12 +665,11 @@
|
| return true;
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetFrameLength(int frame_length_ms) {
|
| +void AudioEncoderOpus::SetFrameLength(int frame_length_ms) {
|
| next_frame_length_ms_ = frame_length_ms;
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetNumChannelsToEncode(
|
| - size_t num_channels_to_encode) {
|
| +void AudioEncoderOpus::SetNumChannelsToEncode(size_t num_channels_to_encode) {
|
| RTC_DCHECK_GT(num_channels_to_encode, 0);
|
| RTC_DCHECK_LE(num_channels_to_encode, config_.num_channels);
|
|
|
| @@ -662,7 +680,7 @@
|
| num_channels_to_encode_ = num_channels_to_encode;
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetProjectedPacketLossRate(float fraction) {
|
| +void AudioEncoderOpus::SetProjectedPacketLossRate(float fraction) {
|
| float opt_loss_rate = OptimizePacketLossRate(fraction, packet_loss_rate_);
|
| if (packet_loss_rate_ != opt_loss_rate) {
|
| packet_loss_rate_ = opt_loss_rate;
|
| @@ -672,20 +690,19 @@
|
| }
|
| }
|
|
|
| -void AudioEncoderOpusImpl::SetTargetBitrate(int bits_per_second) {
|
| - config_.bitrate_bps = rtc::SafeClamp<int>(
|
| - bits_per_second, AudioEncoderOpusConfig::kMinBitrateBps,
|
| - AudioEncoderOpusConfig::kMaxBitrateBps);
|
| +void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) {
|
| + config_.bitrate_bps = rtc::Optional<int>(rtc::SafeClamp<int>(
|
| + bits_per_second, kOpusMinBitrateBps, kOpusMaxBitrateBps));
|
| RTC_DCHECK(config_.IsOk());
|
| - RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, GetBitrateBps(config_)));
|
| - const auto new_complexity = GetNewComplexity(config_);
|
| + RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.GetBitrateBps()));
|
| + const auto new_complexity = config_.GetNewComplexity();
|
| if (new_complexity && complexity_ != *new_complexity) {
|
| complexity_ = *new_complexity;
|
| RTC_CHECK_EQ(0, WebRtcOpus_SetComplexity(inst_, complexity_));
|
| }
|
| }
|
|
|
| -void AudioEncoderOpusImpl::ApplyAudioNetworkAdaptor() {
|
| +void AudioEncoderOpus::ApplyAudioNetworkAdaptor() {
|
| auto config = audio_network_adaptor_->GetEncoderRuntimeConfig();
|
| RTC_DCHECK(!config.frame_length_ms || *config.frame_length_ms == 20 ||
|
| *config.frame_length_ms == 60);
|
| @@ -705,20 +722,20 @@
|
| }
|
|
|
| std::unique_ptr<AudioNetworkAdaptor>
|
| -AudioEncoderOpusImpl::DefaultAudioNetworkAdaptorCreator(
|
| +AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator(
|
| const ProtoString& config_string,
|
| RtcEventLog* event_log) const {
|
| AudioNetworkAdaptorImpl::Config config;
|
| config.event_log = event_log;
|
| return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl(
|
| - config, ControllerManagerImpl::Create(
|
| - config_string, NumChannels(), supported_frame_lengths_ms(),
|
| - AudioEncoderOpusConfig::kMinBitrateBps,
|
| - num_channels_to_encode_, next_frame_length_ms_,
|
| - GetTargetBitrate(), config_.fec_enabled, GetDtx())));
|
| -}
|
| -
|
| -void AudioEncoderOpusImpl::MaybeUpdateUplinkBandwidth() {
|
| + config,
|
| + ControllerManagerImpl::Create(
|
| + config_string, NumChannels(), supported_frame_lengths_ms(),
|
| + kOpusMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_,
|
| + GetTargetBitrate(), config_.fec_enabled, GetDtx())));
|
| +}
|
| +
|
| +void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() {
|
| if (audio_network_adaptor_) {
|
| int64_t now_ms = rtc::TimeMillis();
|
| if (!bitrate_smoother_last_update_time_ ||
|
|
|