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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 BitrateController::Config::~Config() = default; | 26 BitrateController::Config::~Config() = default; |
27 | 27 |
28 BitrateController::BitrateController(const Config& config) | 28 BitrateController::BitrateController(const Config& config) |
29 : config_(config), | 29 : config_(config), |
30 bitrate_bps_(config_.initial_bitrate_bps), | 30 bitrate_bps_(config_.initial_bitrate_bps), |
31 frame_length_ms_(config_.initial_frame_length_ms) { | 31 frame_length_ms_(config_.initial_frame_length_ms) { |
32 RTC_DCHECK_GT(bitrate_bps_, 0); | 32 RTC_DCHECK_GT(bitrate_bps_, 0); |
33 RTC_DCHECK_GT(frame_length_ms_, 0); | 33 RTC_DCHECK_GT(frame_length_ms_, 0); |
34 } | 34 } |
35 | 35 |
| 36 BitrateController::~BitrateController() = default; |
| 37 |
| 38 void BitrateController::UpdateNetworkMetrics( |
| 39 const NetworkMetrics& network_metrics) { |
| 40 if (network_metrics.target_audio_bitrate_bps) |
| 41 target_audio_bitrate_bps_ = network_metrics.target_audio_bitrate_bps; |
| 42 if (network_metrics.overhead_bytes_per_packet) |
| 43 overhead_bytes_per_packet_ = network_metrics.overhead_bytes_per_packet; |
| 44 } |
| 45 |
36 void BitrateController::MakeDecision( | 46 void BitrateController::MakeDecision( |
37 const NetworkMetrics& metrics, | |
38 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { | 47 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { |
39 // Decision on |bitrate_bps| should not have been made. | 48 // Decision on |bitrate_bps| should not have been made. |
40 RTC_DCHECK(!config->bitrate_bps); | 49 RTC_DCHECK(!config->bitrate_bps); |
41 if (metrics.target_audio_bitrate_bps && metrics.overhead_bytes_per_packet) { | 50 if (target_audio_bitrate_bps_ && overhead_bytes_per_packet_) { |
42 // Current implementation of BitrateController can only work when | 51 // Current implementation of BitrateController can only work when |
43 // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is | 52 // |metrics.target_audio_bitrate_bps| includes overhead is enabled. This is |
44 // currently governed by the following field trial. | 53 // currently governed by the following field trial. |
45 RTC_DCHECK_EQ("Enabled", webrtc::field_trial::FindFullName( | 54 RTC_DCHECK_EQ("Enabled", webrtc::field_trial::FindFullName( |
46 "WebRTC-SendSideBwe-WithOverhead")); | 55 "WebRTC-SendSideBwe-WithOverhead")); |
47 if (config->frame_length_ms) | 56 if (config->frame_length_ms) |
48 frame_length_ms_ = *config->frame_length_ms; | 57 frame_length_ms_ = *config->frame_length_ms; |
49 int overhead_rate_bps = | 58 int overhead_rate_bps = |
50 *metrics.overhead_bytes_per_packet * 8 * 1000 / frame_length_ms_; | 59 *overhead_bytes_per_packet_ * 8 * 1000 / frame_length_ms_; |
51 bitrate_bps_ = | 60 bitrate_bps_ = std::max(0, *target_audio_bitrate_bps_ - overhead_rate_bps); |
52 std::max(0, *metrics.target_audio_bitrate_bps - overhead_rate_bps); | |
53 } | 61 } |
54 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); | 62 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); |
55 } | 63 } |
56 | 64 |
57 } // namespace audio_network_adaptor | 65 } // namespace audio_network_adaptor |
58 } // namespace webrtc | 66 } // namespace webrtc |
OLD | NEW |