OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/audio_network_adaptor/bitrate_controller.h
" | 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h
" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/system_wrappers/include/field_trial.h" |
16 | 17 |
17 namespace webrtc { | 18 namespace webrtc { |
18 namespace audio_network_adaptor { | 19 namespace audio_network_adaptor { |
19 | 20 |
20 namespace { | |
21 // TODO(minyue): consider passing this from a higher layer through | |
22 // SetConstraints(). | |
23 // L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits | |
24 constexpr int kPacketOverheadBits = 512; | |
25 } | |
26 | |
27 BitrateController::Config::Config(int initial_bitrate_bps, | 21 BitrateController::Config::Config(int initial_bitrate_bps, |
28 int initial_frame_length_ms) | 22 int initial_frame_length_ms) |
29 : initial_bitrate_bps(initial_bitrate_bps), | 23 : initial_bitrate_bps(initial_bitrate_bps), |
30 initial_frame_length_ms(initial_frame_length_ms) {} | 24 initial_frame_length_ms(initial_frame_length_ms) {} |
31 | 25 |
32 BitrateController::Config::~Config() = default; | 26 BitrateController::Config::~Config() = default; |
33 | 27 |
34 BitrateController::BitrateController(const Config& config) | 28 BitrateController::BitrateController(const Config& config) |
35 : config_(config), | 29 : config_(config), |
36 bitrate_bps_(config_.initial_bitrate_bps), | 30 bitrate_bps_(config_.initial_bitrate_bps), |
37 overhead_rate_bps_(kPacketOverheadBits * 1000 / | 31 frame_length_ms_(config_.initial_frame_length_ms) { |
38 config_.initial_frame_length_ms) { | |
39 RTC_DCHECK_GT(bitrate_bps_, 0); | 32 RTC_DCHECK_GT(bitrate_bps_, 0); |
40 RTC_DCHECK_GT(overhead_rate_bps_, 0); | 33 RTC_DCHECK_GT(frame_length_ms_, 0); |
41 } | 34 } |
42 | 35 |
43 void BitrateController::MakeDecision( | 36 void BitrateController::MakeDecision( |
44 const NetworkMetrics& metrics, | 37 const NetworkMetrics& metrics, |
45 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { | 38 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { |
46 // Decision on |bitrate_bps| should not have been made. | 39 // Decision on |bitrate_bps| should not have been made. |
47 RTC_DCHECK(!config->bitrate_bps); | 40 RTC_DCHECK(!config->bitrate_bps); |
48 | 41 if (metrics.target_audio_bitrate_bps && metrics.overhead_bytes_per_packet) { |
49 if (metrics.target_audio_bitrate_bps) { | 42 // Current implementation of BitrateController can only work when |
50 int overhead_rate = | 43 // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is |
51 config->frame_length_ms | 44 // currently governed by the following field trial. |
52 ? kPacketOverheadBits * 1000 / *config->frame_length_ms | 45 RTC_DCHECK_EQ("Enabled", webrtc::field_trial::FindFullName( |
53 : overhead_rate_bps_; | 46 "WebRTC-SendSideBwe-WithOverhead")); |
54 // If |metrics.target_audio_bitrate_bps| had included overhead, we would | 47 if (config->frame_length_ms) |
55 // simply do: | 48 frame_length_ms_ = *config->frame_length_ms; |
56 // bitrate_bps_ = metrics.target_audio_bitrate_bps - overhead_rate; | 49 int overhead_rate_bps = |
57 // Follow https://bugs.chromium.org/p/webrtc/issues/detail?id=6315 to track | 50 *metrics.overhead_bytes_per_packet * 8 * 1000 / frame_length_ms_; |
58 // progress regarding this. | 51 bitrate_bps_ = |
59 // Now we assume that |metrics.target_audio_bitrate_bps| can handle the | 52 std::max(0, *metrics.target_audio_bitrate_bps - overhead_rate_bps); |
60 // overhead of most recent packets. | |
61 bitrate_bps_ = std::max(0, *metrics.target_audio_bitrate_bps + | |
62 overhead_rate_bps_ - overhead_rate); | |
63 // TODO(minyue): apply a smoothing on the |overhead_rate_bps_|. | |
64 overhead_rate_bps_ = overhead_rate; | |
65 } | 53 } |
66 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); | 54 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); |
67 } | 55 } |
68 | 56 |
69 } // namespace audio_network_adaptor | 57 } // namespace audio_network_adaptor |
70 } // namespace webrtc | 58 } // namespace webrtc |
OLD | NEW |