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

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

Issue 2528933002: Adding OnReceivedOverhead to AudioEncoder. (Closed)
Patch Set: adding static_cast Created 4 years 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 #include <iterator>
15 15
16 #include "webrtc/base/analytics/exp_filter.h" 16 #include "webrtc/base/analytics/exp_filter.h"
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/logging.h"
18 #include "webrtc/base/safe_conversions.h" 19 #include "webrtc/base/safe_conversions.h"
19 #include "webrtc/common_types.h" 20 #include "webrtc/common_types.h"
20 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto r_impl.h" 21 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto r_impl.h"
21 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h " 22 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h "
22 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" 23 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
23 #include "webrtc/system_wrappers/include/clock.h" 24 #include "webrtc/system_wrappers/include/clock.h"
25 #include "webrtc/system_wrappers/include/field_trial.h"
24 26
25 namespace webrtc { 27 namespace webrtc {
26 28
27 namespace { 29 namespace {
28 30
29 constexpr int kSampleRateHz = 48000; 31 constexpr int kSampleRateHz = 48000;
30 constexpr int kMinBitrateBps = 500; 32 constexpr int kMinBitrateBps = 500;
31 constexpr int kMaxBitrateBps = 512000; 33 constexpr int kMaxBitrateBps = 512000;
32 constexpr int kSupportedFrameLengths[] = {20, 60}; 34 constexpr int kSupportedFrameLengths[] = {20, 60};
33 35
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 float average_fraction_loss = packet_loss_fraction_smoother_->GetAverage(); 286 float average_fraction_loss = packet_loss_fraction_smoother_->GetAverage();
285 return SetProjectedPacketLossRate(average_fraction_loss); 287 return SetProjectedPacketLossRate(average_fraction_loss);
286 } 288 }
287 audio_network_adaptor_->SetUplinkPacketLossFraction( 289 audio_network_adaptor_->SetUplinkPacketLossFraction(
288 uplink_packet_loss_fraction); 290 uplink_packet_loss_fraction);
289 ApplyAudioNetworkAdaptor(); 291 ApplyAudioNetworkAdaptor();
290 } 292 }
291 293
292 void AudioEncoderOpus::OnReceivedTargetAudioBitrate( 294 void AudioEncoderOpus::OnReceivedTargetAudioBitrate(
293 int target_audio_bitrate_bps) { 295 int target_audio_bitrate_bps) {
294 if (!audio_network_adaptor_) 296 if (audio_network_adaptor_) {
295 return SetTargetBitrate(target_audio_bitrate_bps); 297 audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps);
296 audio_network_adaptor_->SetTargetAudioBitrate(target_audio_bitrate_bps); 298 ApplyAudioNetworkAdaptor();
297 ApplyAudioNetworkAdaptor(); 299 } else if (webrtc::field_trial::FindFullName(
300 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") {
301 if (!overhead_bytes_per_packet_) {
302 LOG(LS_INFO)
303 << "AudioEncoderOpus: Overhead unknown, target audio bitrate "
304 << target_audio_bitrate_bps << " bps is ignored.";
305 return;
306 }
307 const int overhead_bps = static_cast<int>(
308 *overhead_bytes_per_packet_ * 8 * 100 / Num10MsFramesInNextPacket());
309 SetTargetBitrate(std::min(
310 kMaxBitrateBps,
311 std::max(kMinBitrateBps, target_audio_bitrate_bps - overhead_bps)));
312 } else {
313 SetTargetBitrate(target_audio_bitrate_bps);
314 }
298 } 315 }
299 316
300 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { 317 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) {
301 if (!audio_network_adaptor_) 318 if (!audio_network_adaptor_)
302 return; 319 return;
303 audio_network_adaptor_->SetRtt(rtt_ms); 320 audio_network_adaptor_->SetRtt(rtt_ms);
304 ApplyAudioNetworkAdaptor(); 321 ApplyAudioNetworkAdaptor();
305 } 322 }
306 323
324 void AudioEncoderOpus::OnReceivedOverhead(size_t overhead_bytes_per_packet) {
325 if (audio_network_adaptor_) {
326 audio_network_adaptor_->SetOverhead(overhead_bytes_per_packet);
327 ApplyAudioNetworkAdaptor();
328 } else {
329 overhead_bytes_per_packet_ =
330 rtc::Optional<size_t>(overhead_bytes_per_packet);
331 }
332 }
333
307 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms, 334 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms,
308 int max_frame_length_ms) { 335 int max_frame_length_ms) {
309 // Ensure that |SetReceiverFrameLengthRange| is called before 336 // Ensure that |SetReceiverFrameLengthRange| is called before
310 // |EnableAudioNetworkAdaptor|, otherwise we need to recreate 337 // |EnableAudioNetworkAdaptor|, otherwise we need to recreate
311 // |audio_network_adaptor_|, which is not a needed use case. 338 // |audio_network_adaptor_|, which is not a needed use case.
312 RTC_DCHECK(!audio_network_adaptor_); 339 RTC_DCHECK(!audio_network_adaptor_);
313 340
314 config_.supported_frame_lengths_ms.clear(); 341 config_.supported_frame_lengths_ms.clear();
315 std::copy_if(std::begin(kSupportedFrameLengths), 342 std::copy_if(std::begin(kSupportedFrameLengths),
316 std::end(kSupportedFrameLengths), 343 std::end(kSupportedFrameLengths),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 AudioNetworkAdaptorImpl::Config config; 517 AudioNetworkAdaptorImpl::Config config;
491 config.clock = clock; 518 config.clock = clock;
492 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( 519 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl(
493 config, ControllerManagerImpl::Create( 520 config, ControllerManagerImpl::Create(
494 config_string, NumChannels(), supported_frame_lengths_ms(), 521 config_string, NumChannels(), supported_frame_lengths_ms(),
495 num_channels_to_encode_, next_frame_length_ms_, 522 num_channels_to_encode_, next_frame_length_ms_,
496 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); 523 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock)));
497 } 524 }
498 525
499 } // namespace webrtc 526 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698