Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc

Issue 2429503002: Simplifying audio network adaptor by moving receiver frame length range to ctor. (Closed)
Patch Set: nicer solution Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" 11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <iterator>
14 15
15 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
16 #include "webrtc/base/exp_filter.h" 17 #include "webrtc/base/exp_filter.h"
17 #include "webrtc/base/safe_conversions.h" 18 #include "webrtc/base/safe_conversions.h"
18 #include "webrtc/common_types.h" 19 #include "webrtc/common_types.h"
19 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto r_impl.h" 20 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto r_impl.h"
20 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h " 21 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h "
21 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" 22 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
22 #include "webrtc/system_wrappers/include/clock.h" 23 #include "webrtc/system_wrappers/include/clock.h"
23 24
(...skipping 11 matching lines...) Expand all
35 constexpr float kAlphaForPacketLossFractionSmoother = 0.9999f; 36 constexpr float kAlphaForPacketLossFractionSmoother = 0.9999f;
36 37
37 AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) { 38 AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
38 AudioEncoderOpus::Config config; 39 AudioEncoderOpus::Config config;
39 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48); 40 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48);
40 config.num_channels = codec_inst.channels; 41 config.num_channels = codec_inst.channels;
41 config.bitrate_bps = rtc::Optional<int>(codec_inst.rate); 42 config.bitrate_bps = rtc::Optional<int>(codec_inst.rate);
42 config.payload_type = codec_inst.pltype; 43 config.payload_type = codec_inst.pltype;
43 config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip 44 config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip
44 : AudioEncoderOpus::kAudio; 45 : AudioEncoderOpus::kAudio;
46 config.supported_frame_lengths_ms.push_back(config.frame_size_ms);
45 return config; 47 return config;
46 } 48 }
47 49
48 // Optimize the loss rate to configure Opus. Basically, optimized loss rate is 50 // Optimize the loss rate to configure Opus. Basically, optimized loss rate is
49 // the input loss rate rounded down to various levels, because a robustly good 51 // the input loss rate rounded down to various levels, because a robustly good
50 // audio quality is achieved by lowering the packet loss down. 52 // audio quality is achieved by lowering the packet loss down.
51 // Additionally, to prevent toggling, margins are used, i.e., when jumping to 53 // Additionally, to prevent toggling, margins are used, i.e., when jumping to
52 // a loss rate from below, a higher threshold is used than jumping to the same 54 // a loss rate from below, a higher threshold is used than jumping to the same
53 // level from above. 55 // level from above.
54 double OptimizePacketLossRate(double new_loss_rate, double old_loss_rate) { 56 double OptimizePacketLossRate(double new_loss_rate, double old_loss_rate) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 292
291 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { 293 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) {
292 if (!audio_network_adaptor_) 294 if (!audio_network_adaptor_)
293 return; 295 return;
294 audio_network_adaptor_->SetRtt(rtt_ms); 296 audio_network_adaptor_->SetRtt(rtt_ms);
295 ApplyAudioNetworkAdaptor(); 297 ApplyAudioNetworkAdaptor();
296 } 298 }
297 299
298 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms, 300 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms,
299 int max_frame_length_ms) { 301 int max_frame_length_ms) {
300 if (!audio_network_adaptor_) 302 // Ensure that |SetReceiverFrameLengthRange| is called before
301 return; 303 // |EnableAudioNetworkAdaptor|, otherwise we need to recreate
302 audio_network_adaptor_->SetReceiverFrameLengthRange(min_frame_length_ms, 304 // |audio_network_adaptor_|, which is not a needed use case.
303 max_frame_length_ms); 305 RTC_DCHECK(!audio_network_adaptor_);
304 ApplyAudioNetworkAdaptor(); 306
307 config_.supported_frame_lengths_ms.clear();
308 std::copy_if(std::begin(kSupportedFrameLengths),
309 std::end(kSupportedFrameLengths),
310 std::back_inserter(config_.supported_frame_lengths_ms),
311 [&](int frame_length_ms) {
312 return frame_length_ms >= min_frame_length_ms &&
313 frame_length_ms <= max_frame_length_ms;
314 });
315 RTC_DCHECK(std::is_sorted(config_.supported_frame_lengths_ms.begin(),
316 config_.supported_frame_lengths_ms.end()));
305 } 317 }
306 318
307 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl( 319 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl(
308 uint32_t rtp_timestamp, 320 uint32_t rtp_timestamp,
309 rtc::ArrayView<const int16_t> audio, 321 rtc::ArrayView<const int16_t> audio,
310 rtc::Buffer* encoded) { 322 rtc::Buffer* encoded) {
311 323
312 if (input_buffer_.empty()) 324 if (input_buffer_.empty())
313 first_timestamp_in_buffer_ = rtp_timestamp; 325 first_timestamp_in_buffer_ = rtp_timestamp;
314 326
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 452 }
441 453
442 std::unique_ptr<AudioNetworkAdaptor> 454 std::unique_ptr<AudioNetworkAdaptor>
443 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( 455 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator(
444 const std::string& config_string, 456 const std::string& config_string,
445 const Clock* clock) const { 457 const Clock* clock) const {
446 AudioNetworkAdaptorImpl::Config config; 458 AudioNetworkAdaptorImpl::Config config;
447 config.clock = clock; 459 config.clock = clock;
448 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( 460 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl(
449 config, ControllerManagerImpl::Create( 461 config, ControllerManagerImpl::Create(
450 config_string, NumChannels(), kSupportedFrameLengths, 462 config_string, NumChannels(), supported_frame_lengths_ms(),
451 num_channels_to_encode_, next_frame_length_ms_, 463 num_channels_to_encode_, next_frame_length_ms_,
452 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); 464 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock)));
453 } 465 }
454 466
455 } // namespace webrtc 467 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698