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 "modules/audio_coding/audio_network_adaptor/bitrate_controller.h" | 11 #include "modules/audio_coding/audio_network_adaptor/bitrate_controller.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "rtc_base/checks.h" | 15 #include "rtc_base/checks.h" |
16 #include "system_wrappers/include/field_trial.h" | 16 #include "system_wrappers/include/field_trial.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 namespace audio_network_adaptor { | 19 namespace audio_network_adaptor { |
20 | 20 |
21 BitrateController::Config::Config(int initial_bitrate_bps, | 21 BitrateController::Config::Config(int initial_bitrate_bps, |
22 int initial_frame_length_ms) | 22 int initial_frame_length_ms, |
| 23 int fl_increase_overhead_offset, |
| 24 int fl_decrease_overhead_offset) |
23 : initial_bitrate_bps(initial_bitrate_bps), | 25 : initial_bitrate_bps(initial_bitrate_bps), |
24 initial_frame_length_ms(initial_frame_length_ms) {} | 26 initial_frame_length_ms(initial_frame_length_ms), |
| 27 fl_increase_overhead_offset(fl_increase_overhead_offset), |
| 28 fl_decrease_overhead_offset(fl_decrease_overhead_offset) {} |
25 | 29 |
26 BitrateController::Config::~Config() = default; | 30 BitrateController::Config::~Config() = default; |
27 | 31 |
28 BitrateController::BitrateController(const Config& config) | 32 BitrateController::BitrateController(const Config& config) |
29 : config_(config), | 33 : config_(config), |
30 bitrate_bps_(config_.initial_bitrate_bps), | 34 bitrate_bps_(config_.initial_bitrate_bps), |
31 frame_length_ms_(config_.initial_frame_length_ms) { | 35 frame_length_ms_(config_.initial_frame_length_ms) { |
32 RTC_DCHECK_GT(bitrate_bps_, 0); | 36 RTC_DCHECK_GT(bitrate_bps_, 0); |
33 RTC_DCHECK_GT(frame_length_ms_, 0); | 37 RTC_DCHECK_GT(frame_length_ms_, 0); |
34 } | 38 } |
(...skipping 12 matching lines...) Expand all Loading... |
47 // Decision on |bitrate_bps| should not have been made. | 51 // Decision on |bitrate_bps| should not have been made. |
48 RTC_DCHECK(!config->bitrate_bps); | 52 RTC_DCHECK(!config->bitrate_bps); |
49 if (target_audio_bitrate_bps_ && overhead_bytes_per_packet_) { | 53 if (target_audio_bitrate_bps_ && overhead_bytes_per_packet_) { |
50 // Current implementation of BitrateController can only work when | 54 // Current implementation of BitrateController can only work when |
51 // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is | 55 // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is |
52 // currently governed by the following field trial. | 56 // currently governed by the following field trial. |
53 RTC_DCHECK( | 57 RTC_DCHECK( |
54 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")); | 58 webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")); |
55 if (config->frame_length_ms) | 59 if (config->frame_length_ms) |
56 frame_length_ms_ = *config->frame_length_ms; | 60 frame_length_ms_ = *config->frame_length_ms; |
57 int overhead_rate_bps = | 61 int offset = config->last_fl_change_increase |
58 static_cast<int>(*overhead_bytes_per_packet_ * 8 * 1000 / | 62 ? config_.fl_increase_overhead_offset |
59 frame_length_ms_); | 63 : config_.fl_decrease_overhead_offset; |
| 64 // Check that |
| 65 // -(*overhead_bytes_per_packet_) <= offset <= (*overhead_bytes_per_packet_) |
| 66 RTC_DCHECK_GE(*overhead_bytes_per_packet_, -offset); |
| 67 RTC_DCHECK_LE(offset, *overhead_bytes_per_packet_); |
| 68 int overhead_rate_bps = static_cast<int>( |
| 69 (*overhead_bytes_per_packet_ + offset) * 8 * 1000 / frame_length_ms_); |
60 bitrate_bps_ = std::max(0, *target_audio_bitrate_bps_ - overhead_rate_bps); | 70 bitrate_bps_ = std::max(0, *target_audio_bitrate_bps_ - overhead_rate_bps); |
61 } | 71 } |
62 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); | 72 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); |
63 } | 73 } |
64 | 74 |
65 } // namespace audio_network_adaptor | 75 } // namespace audio_network_adaptor |
66 } // namespace webrtc | 76 } // namespace webrtc |
OLD | NEW |