Chromium Code Reviews| 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 29f85ac4704647e8d25039d068b0401a37b73851..b09999a6ed622fc25944224dd07e303744e27bf8 100644 |
| --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc |
| @@ -12,6 +12,7 @@ |
| #include <algorithm> |
| +#include "webrtc/base/arraysize.h" |
| #include "webrtc/base/checks.h" |
| #include "webrtc/base/exp_filter.h" |
| #include "webrtc/base/safe_conversions.h" |
| @@ -152,9 +153,13 @@ AudioEncoderOpus::AudioEncoderOpus( |
| audio_network_adaptor_creator_( |
| audio_network_adaptor_creator |
| ? std::move(audio_network_adaptor_creator) |
| - : [this](const std::string& config_string, const Clock* clock) { |
| - return DefaultAudioNetworkAdaptorCreator(config_string, |
| - clock); |
| + : [this](const std::string& config_string, |
| + int min_receiver_frame_length_ms, |
| + int max_receiver_frame_length_ms, |
| + const Clock* clock) { |
| + return DefaultAudioNetworkAdaptorCreator( |
| + config_string, min_receiver_frame_length_ms, |
| + max_receiver_frame_length_ms, clock); |
| }) { |
| RTC_CHECK(RecreateEncoderInstance(config)); |
| } |
| @@ -252,8 +257,12 @@ void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) { |
| bool AudioEncoderOpus::EnableAudioNetworkAdaptor( |
| const std::string& config_string, |
| + int min_receiver_frame_length_ms, |
| + int max_receiver_frame_length_ms, |
| const Clock* clock) { |
| - audio_network_adaptor_ = audio_network_adaptor_creator_(config_string, clock); |
| + audio_network_adaptor_ = audio_network_adaptor_creator_( |
| + config_string, min_receiver_frame_length_ms, max_receiver_frame_length_ms, |
| + clock); |
| return audio_network_adaptor_.get() != nullptr; |
| } |
| @@ -295,15 +304,6 @@ void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { |
| ApplyAudioNetworkAdaptor(); |
| } |
| -void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms, |
| - int max_frame_length_ms) { |
| - if (!audio_network_adaptor_) |
| - return; |
| - audio_network_adaptor_->SetReceiverFrameLengthRange(min_frame_length_ms, |
| - max_frame_length_ms); |
| - ApplyAudioNetworkAdaptor(); |
| -} |
| - |
| AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl( |
| uint32_t rtp_timestamp, |
| rtc::ArrayView<const int16_t> audio, |
| @@ -442,12 +442,24 @@ void AudioEncoderOpus::ApplyAudioNetworkAdaptor() { |
| std::unique_ptr<AudioNetworkAdaptor> |
| AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( |
| const std::string& config_string, |
| + int min_receiver_frame_length_ms, |
| + int max_receiver_frame_length_ms, |
| const Clock* clock) const { |
| AudioNetworkAdaptorImpl::Config config; |
| config.clock = clock; |
| + |
| + std::vector<int> frame_lengths; |
|
michaelt
2016/10/18 08:25:23
Would be nice to have a unit-test for this functio
minyue-webrtc
2016/10/18 13:25:13
I agree. I thought about it but did not find a goo
|
| + std::copy_if(kSupportedFrameLengths, |
| + kSupportedFrameLengths + arraysize(kSupportedFrameLengths), |
| + std::back_inserter(frame_lengths), [&](int frame_length_ms) { |
| + return frame_length_ms >= min_receiver_frame_length_ms && |
| + frame_length_ms <= max_receiver_frame_length_ms; |
| + }); |
| + RTC_DCHECK(std::is_sorted(frame_lengths.begin(), frame_lengths.end())); |
| + |
| return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
| config, ControllerManagerImpl::Create( |
| - config_string, NumChannels(), kSupportedFrameLengths, |
| + config_string, NumChannels(), frame_lengths, |
| num_channels_to_encode_, next_frame_length_ms_, |
| GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
| } |