OLD | NEW |
---|---|
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 Loading... | |
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 return; |
300 } | |
301 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == | |
302 "Enabled") { | |
303 if (!overhead_bytes_per_packet_) { | |
304 LOG(LS_INFO) | |
305 << "AudioEncoderOpus: Overhead unknown, target audio bitrate " | |
306 << target_audio_bitrate_bps << " bps is ignored."; | |
307 return; | |
308 } | |
309 int overhead_rate = | |
310 8 * 100 * *overhead_bytes_per_packet_ / Num10MsFramesInNextPacket(); | |
kwiberg-webrtc
2016/12/03 00:30:56
I had a hard time deciphering this calculation. Co
minyue-webrtc
2016/12/06 09:04:19
Done.
| |
311 SetTargetBitrate(std::min( | |
312 kMaxBitrateBps, | |
313 std::max(kMinBitrateBps, target_audio_bitrate_bps - overhead_rate))); | |
314 return; | |
315 } | |
316 SetTargetBitrate(target_audio_bitrate_bps); | |
kwiberg-webrtc
2016/12/03 00:30:56
I'd argue this would be easier to read if you remo
minyue-webrtc
2016/12/06 09:04:19
Done.
| |
298 } | 317 } |
299 | 318 |
300 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { | 319 void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) { |
301 if (!audio_network_adaptor_) | 320 if (!audio_network_adaptor_) |
302 return; | 321 return; |
303 audio_network_adaptor_->SetRtt(rtt_ms); | 322 audio_network_adaptor_->SetRtt(rtt_ms); |
304 ApplyAudioNetworkAdaptor(); | 323 ApplyAudioNetworkAdaptor(); |
305 } | 324 } |
306 | 325 |
326 void AudioEncoderOpus::OnReceivedOverhead(size_t overhead_bytes_per_packet) { | |
327 if (audio_network_adaptor_) { | |
328 audio_network_adaptor_->SetOverhead(overhead_bytes_per_packet); | |
329 ApplyAudioNetworkAdaptor(); | |
330 return; | |
331 } | |
332 overhead_bytes_per_packet_ = rtc::Optional<size_t>(overhead_bytes_per_packet); | |
kwiberg-webrtc
2016/12/03 00:30:56
if ... else ... instead of the explicit return.
minyue-webrtc
2016/12/06 09:04:19
Done.
| |
333 } | |
334 | |
307 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms, | 335 void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms, |
308 int max_frame_length_ms) { | 336 int max_frame_length_ms) { |
309 // Ensure that |SetReceiverFrameLengthRange| is called before | 337 // Ensure that |SetReceiverFrameLengthRange| is called before |
310 // |EnableAudioNetworkAdaptor|, otherwise we need to recreate | 338 // |EnableAudioNetworkAdaptor|, otherwise we need to recreate |
311 // |audio_network_adaptor_|, which is not a needed use case. | 339 // |audio_network_adaptor_|, which is not a needed use case. |
312 RTC_DCHECK(!audio_network_adaptor_); | 340 RTC_DCHECK(!audio_network_adaptor_); |
313 | 341 |
314 config_.supported_frame_lengths_ms.clear(); | 342 config_.supported_frame_lengths_ms.clear(); |
315 std::copy_if(std::begin(kSupportedFrameLengths), | 343 std::copy_if(std::begin(kSupportedFrameLengths), |
316 std::end(kSupportedFrameLengths), | 344 std::end(kSupportedFrameLengths), |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 AudioNetworkAdaptorImpl::Config config; | 518 AudioNetworkAdaptorImpl::Config config; |
491 config.clock = clock; | 519 config.clock = clock; |
492 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( | 520 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
493 config, ControllerManagerImpl::Create( | 521 config, ControllerManagerImpl::Create( |
494 config_string, NumChannels(), supported_frame_lengths_ms(), | 522 config_string, NumChannels(), supported_frame_lengths_ms(), |
495 num_channels_to_encode_, next_frame_length_ms_, | 523 num_channels_to_encode_, next_frame_length_ms_, |
496 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); | 524 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
497 } | 525 } |
498 | 526 |
499 } // namespace webrtc | 527 } // namespace webrtc |
OLD | NEW |