OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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/fec_controller_rplr_
based.h" | 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_rplr_
based.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 FecControllerRplrBased::Config::Threshold::Threshold( | 20 FecControllerRplrBased::Config::Config( |
21 int low_bandwidth_bps, | 21 bool initial_fec_enabled, |
22 float low_bandwidth_recoverable_packet_loss, | 22 const ThresholdCurve& fec_enabling_threshold, |
23 int high_bandwidth_bps, | 23 const ThresholdCurve& fec_disabling_threshold) |
24 float high_bandwidth_recoverable_packet_loss) | |
25 : low_bandwidth_bps(low_bandwidth_bps), | |
26 low_bandwidth_recoverable_packet_loss( | |
27 low_bandwidth_recoverable_packet_loss), | |
28 high_bandwidth_bps(high_bandwidth_bps), | |
29 high_bandwidth_recoverable_packet_loss( | |
30 high_bandwidth_recoverable_packet_loss) {} | |
31 | |
32 FecControllerRplrBased::Config::Config(bool initial_fec_enabled, | |
33 const Threshold& fec_enabling_threshold, | |
34 const Threshold& fec_disabling_threshold) | |
35 : initial_fec_enabled(initial_fec_enabled), | 24 : initial_fec_enabled(initial_fec_enabled), |
36 fec_enabling_threshold(fec_enabling_threshold), | 25 fec_enabling_threshold(fec_enabling_threshold), |
37 fec_disabling_threshold(fec_disabling_threshold) {} | 26 fec_disabling_threshold(fec_disabling_threshold) {} |
38 | 27 |
39 FecControllerRplrBased::FecControllerRplrBased(const Config& config) | 28 FecControllerRplrBased::FecControllerRplrBased(const Config& config) |
40 : config_(config), | 29 : config_(config), fec_enabled_(config.initial_fec_enabled) { |
41 fec_enabled_(config.initial_fec_enabled), | 30 RTC_DCHECK(config_.fec_disabling_threshold <= config_.fec_enabling_threshold); |
42 fec_enabling_threshold_info_(config_.fec_enabling_threshold), | |
43 fec_disabling_threshold_info_(config_.fec_disabling_threshold) { | |
44 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); | |
45 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); | |
46 RTC_DCHECK_LE( | |
47 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps, | |
48 config_.fec_disabling_threshold, | |
49 fec_disabling_threshold_info_), | |
50 config_.fec_enabling_threshold.low_bandwidth_recoverable_packet_loss); | |
51 RTC_DCHECK_LE( | |
52 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps, | |
53 config_.fec_disabling_threshold, | |
54 fec_disabling_threshold_info_), | |
55 config_.fec_enabling_threshold.high_bandwidth_recoverable_packet_loss); | |
56 } | 31 } |
57 | 32 |
58 FecControllerRplrBased::~FecControllerRplrBased() = default; | 33 FecControllerRplrBased::~FecControllerRplrBased() = default; |
59 | 34 |
60 void FecControllerRplrBased::UpdateNetworkMetrics( | 35 void FecControllerRplrBased::UpdateNetworkMetrics( |
61 const NetworkMetrics& network_metrics) { | 36 const NetworkMetrics& network_metrics) { |
62 if (network_metrics.uplink_bandwidth_bps) | 37 if (network_metrics.uplink_bandwidth_bps) |
63 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps; | 38 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps; |
64 if (network_metrics.uplink_recoverable_packet_loss_fraction) { | 39 if (network_metrics.uplink_recoverable_packet_loss_fraction) { |
65 uplink_recoverable_packet_loss_ = | 40 uplink_recoverable_packet_loss_ = |
66 network_metrics.uplink_recoverable_packet_loss_fraction; | 41 network_metrics.uplink_recoverable_packet_loss_fraction; |
67 } | 42 } |
68 } | 43 } |
69 | 44 |
70 void FecControllerRplrBased::MakeDecision( | 45 void FecControllerRplrBased::MakeDecision( |
71 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { | 46 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { |
72 RTC_DCHECK(!config->enable_fec); | 47 RTC_DCHECK(!config->enable_fec); |
73 RTC_DCHECK(!config->uplink_packet_loss_fraction); | 48 RTC_DCHECK(!config->uplink_packet_loss_fraction); |
74 | 49 |
75 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision() : FecEnablingDecision(); | 50 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision() : FecEnablingDecision(); |
76 | 51 |
77 config->enable_fec = rtc::Optional<bool>(fec_enabled_); | 52 config->enable_fec = rtc::Optional<bool>(fec_enabled_); |
78 config->uplink_packet_loss_fraction = rtc::Optional<float>( | 53 config->uplink_packet_loss_fraction = rtc::Optional<float>( |
79 uplink_recoverable_packet_loss_ ? *uplink_recoverable_packet_loss_ : 0.0); | 54 uplink_recoverable_packet_loss_ ? *uplink_recoverable_packet_loss_ : 0.0); |
80 } | 55 } |
81 | 56 |
82 FecControllerRplrBased::ThresholdInfo::ThresholdInfo( | |
83 const Config::Threshold& threshold) { | |
84 int bandwidth_diff_bps = | |
85 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps; | |
86 float recoverable_packet_loss_diff = | |
87 threshold.high_bandwidth_recoverable_packet_loss - | |
88 threshold.low_bandwidth_recoverable_packet_loss; | |
89 slope = bandwidth_diff_bps == 0 | |
90 ? 0.0 | |
91 : recoverable_packet_loss_diff / bandwidth_diff_bps; | |
92 offset = threshold.low_bandwidth_recoverable_packet_loss - | |
93 slope * threshold.low_bandwidth_bps; | |
94 } | |
95 | |
96 float FecControllerRplrBased::GetPacketLossThreshold( | |
97 int bandwidth_bps, | |
98 const Config::Threshold& threshold, | |
99 const ThresholdInfo& threshold_info) const { | |
100 if (bandwidth_bps < threshold.low_bandwidth_bps) { | |
101 return std::numeric_limits<float>::max(); | |
102 } else if (bandwidth_bps >= threshold.high_bandwidth_bps) { | |
103 return threshold.high_bandwidth_recoverable_packet_loss; | |
104 } else { | |
105 float rc = threshold_info.offset + threshold_info.slope * bandwidth_bps; | |
106 RTC_DCHECK_LE(rc, threshold.low_bandwidth_recoverable_packet_loss); | |
107 RTC_DCHECK_GE(rc, threshold.high_bandwidth_recoverable_packet_loss); | |
108 return rc; | |
109 } | |
110 } | |
111 | |
112 bool FecControllerRplrBased::FecEnablingDecision() const { | 57 bool FecControllerRplrBased::FecEnablingDecision() const { |
113 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) { | 58 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) { |
114 return false; | 59 return false; |
115 } else { | 60 } else { |
116 return *uplink_recoverable_packet_loss_ >= | 61 // Enable when above the curve or exactly on it. |
117 GetPacketLossThreshold(*uplink_bandwidth_bps_, | 62 return !config_.fec_enabling_threshold.IsBelowCurve( |
118 config_.fec_enabling_threshold, | 63 {static_cast<float>(*uplink_bandwidth_bps_), |
119 fec_enabling_threshold_info_); | 64 *uplink_recoverable_packet_loss_}); |
120 } | 65 } |
121 } | 66 } |
122 | 67 |
123 bool FecControllerRplrBased::FecDisablingDecision() const { | 68 bool FecControllerRplrBased::FecDisablingDecision() const { |
124 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) { | 69 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) { |
125 return false; | 70 return false; |
126 } else { | 71 } else { |
127 return *uplink_recoverable_packet_loss_ <= | 72 // Disable when below the curve or exactly on it. |
128 GetPacketLossThreshold(*uplink_bandwidth_bps_, | 73 return !config_.fec_disabling_threshold.IsAboveCurve( |
129 config_.fec_disabling_threshold, | 74 {static_cast<float>(*uplink_bandwidth_bps_), |
130 fec_disabling_threshold_info_); | 75 *uplink_recoverable_packet_loss_}); |
131 } | 76 } |
132 } | 77 } |
133 | 78 |
134 } // namespace webrtc | 79 } // namespace webrtc |
OLD | NEW |