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 19 matching lines...) Expand all Loading... |
30 bool SetTimeConstantMs(int time_constant_ms) override { | 30 bool SetTimeConstantMs(int time_constant_ms) override { |
31 RTC_NOTREACHED(); | 31 RTC_NOTREACHED(); |
32 return false; | 32 return false; |
33 } | 33 } |
34 | 34 |
35 private: | 35 private: |
36 rtc::Optional<float> last_sample_; | 36 rtc::Optional<float> last_sample_; |
37 }; | 37 }; |
38 } | 38 } |
39 | 39 |
40 FecControllerPlrBased::Config::Threshold::Threshold( | 40 FecControllerPlrBased::Config::Config( |
41 int low_bandwidth_bps, | 41 bool initial_fec_enabled, |
42 float low_bandwidth_packet_loss, | 42 const ThresholdCurve& fec_enabling_threshold, |
43 int high_bandwidth_bps, | 43 const ThresholdCurve& fec_disabling_threshold, |
44 float high_bandwidth_packet_loss) | 44 int time_constant_ms, |
45 : low_bandwidth_bps(low_bandwidth_bps), | 45 const Clock* clock) |
46 low_bandwidth_packet_loss(low_bandwidth_packet_loss), | |
47 high_bandwidth_bps(high_bandwidth_bps), | |
48 high_bandwidth_packet_loss(high_bandwidth_packet_loss) {} | |
49 | |
50 FecControllerPlrBased::Config::Config(bool initial_fec_enabled, | |
51 const Threshold& fec_enabling_threshold, | |
52 const Threshold& fec_disabling_threshold, | |
53 int time_constant_ms, | |
54 const Clock* clock) | |
55 : initial_fec_enabled(initial_fec_enabled), | 46 : initial_fec_enabled(initial_fec_enabled), |
56 fec_enabling_threshold(fec_enabling_threshold), | 47 fec_enabling_threshold(fec_enabling_threshold), |
57 fec_disabling_threshold(fec_disabling_threshold), | 48 fec_disabling_threshold(fec_disabling_threshold), |
58 time_constant_ms(time_constant_ms), | 49 time_constant_ms(time_constant_ms), |
59 clock(clock) {} | 50 clock(clock) {} |
60 | 51 |
61 FecControllerPlrBased::FecControllerPlrBased( | 52 FecControllerPlrBased::FecControllerPlrBased( |
62 const Config& config, | 53 const Config& config, |
63 std::unique_ptr<SmoothingFilter> smoothing_filter) | 54 std::unique_ptr<SmoothingFilter> smoothing_filter) |
64 : config_(config), | 55 : config_(config), |
65 fec_enabled_(config.initial_fec_enabled), | 56 fec_enabled_(config.initial_fec_enabled), |
66 packet_loss_smoother_(std::move(smoothing_filter)), | 57 packet_loss_smoother_(std::move(smoothing_filter)) { |
67 fec_enabling_threshold_info_(config_.fec_enabling_threshold), | 58 RTC_DCHECK(config_.fec_disabling_threshold <= config_.fec_enabling_threshold); |
68 fec_disabling_threshold_info_(config_.fec_disabling_threshold) { | |
69 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); | |
70 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); | |
71 RTC_DCHECK_LE( | |
72 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps, | |
73 config_.fec_disabling_threshold, | |
74 fec_disabling_threshold_info_), | |
75 config_.fec_enabling_threshold.low_bandwidth_packet_loss); | |
76 RTC_DCHECK_LE( | |
77 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps, | |
78 config_.fec_disabling_threshold, | |
79 fec_disabling_threshold_info_), | |
80 config_.fec_enabling_threshold.high_bandwidth_packet_loss); | |
81 } | 59 } |
82 | 60 |
83 FecControllerPlrBased::FecControllerPlrBased(const Config& config) | 61 FecControllerPlrBased::FecControllerPlrBased(const Config& config) |
84 : FecControllerPlrBased( | 62 : FecControllerPlrBased( |
85 config, | 63 config, |
86 webrtc::field_trial::FindFullName("UseTwccPlrForAna") == "Enabled" | 64 webrtc::field_trial::FindFullName("UseTwccPlrForAna") == "Enabled" |
87 ? std::unique_ptr<NullSmoothingFilter>(new NullSmoothingFilter()) | 65 ? std::unique_ptr<NullSmoothingFilter>(new NullSmoothingFilter()) |
88 : std::unique_ptr<SmoothingFilter>( | 66 : std::unique_ptr<SmoothingFilter>( |
89 new SmoothingFilterImpl(config.time_constant_ms, | 67 new SmoothingFilterImpl(config.time_constant_ms, |
90 config.clock))) {} | 68 config.clock))) {} |
(...skipping 19 matching lines...) Expand all Loading... |
110 | 88 |
111 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss) | 89 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss) |
112 : FecEnablingDecision(packet_loss); | 90 : FecEnablingDecision(packet_loss); |
113 | 91 |
114 config->enable_fec = rtc::Optional<bool>(fec_enabled_); | 92 config->enable_fec = rtc::Optional<bool>(fec_enabled_); |
115 | 93 |
116 config->uplink_packet_loss_fraction = | 94 config->uplink_packet_loss_fraction = |
117 rtc::Optional<float>(packet_loss ? *packet_loss : 0.0); | 95 rtc::Optional<float>(packet_loss ? *packet_loss : 0.0); |
118 } | 96 } |
119 | 97 |
120 FecControllerPlrBased::ThresholdInfo::ThresholdInfo( | |
121 const Config::Threshold& threshold) { | |
122 int bandwidth_diff_bps = | |
123 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps; | |
124 float packet_loss_diff = threshold.high_bandwidth_packet_loss - | |
125 threshold.low_bandwidth_packet_loss; | |
126 slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps; | |
127 offset = | |
128 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps; | |
129 } | |
130 | |
131 float FecControllerPlrBased::GetPacketLossThreshold( | |
132 int bandwidth_bps, | |
133 const Config::Threshold& threshold, | |
134 const ThresholdInfo& threshold_info) const { | |
135 if (bandwidth_bps < threshold.low_bandwidth_bps) { | |
136 return std::numeric_limits<float>::max(); | |
137 } else if (bandwidth_bps >= threshold.high_bandwidth_bps) { | |
138 return threshold.high_bandwidth_packet_loss; | |
139 } else { | |
140 float rc = threshold_info.offset + threshold_info.slope * bandwidth_bps; | |
141 RTC_DCHECK_LE(rc, threshold.low_bandwidth_packet_loss); | |
142 RTC_DCHECK_GE(rc, threshold.high_bandwidth_packet_loss); | |
143 return rc; | |
144 } | |
145 } | |
146 | |
147 bool FecControllerPlrBased::FecEnablingDecision( | 98 bool FecControllerPlrBased::FecEnablingDecision( |
148 const rtc::Optional<float>& packet_loss) const { | 99 const rtc::Optional<float>& packet_loss) const { |
149 if (!uplink_bandwidth_bps_) | 100 if (!uplink_bandwidth_bps_ || !packet_loss) { |
150 return false; | 101 return false; |
151 if (!packet_loss) | 102 } else { |
152 return false; | 103 // Enable when above the curve or exactly on it. |
153 return *packet_loss >= GetPacketLossThreshold(*uplink_bandwidth_bps_, | 104 return !config_.fec_enabling_threshold.IsBelowCurve( |
154 config_.fec_enabling_threshold, | 105 {static_cast<float>(*uplink_bandwidth_bps_), *packet_loss}); |
155 fec_enabling_threshold_info_); | 106 } |
156 } | 107 } |
157 | 108 |
158 bool FecControllerPlrBased::FecDisablingDecision( | 109 bool FecControllerPlrBased::FecDisablingDecision( |
159 const rtc::Optional<float>& packet_loss) const { | 110 const rtc::Optional<float>& packet_loss) const { |
160 if (!uplink_bandwidth_bps_) | 111 if (!uplink_bandwidth_bps_ || !packet_loss) { |
161 return false; | 112 return false; |
162 if (!packet_loss) | 113 } else { |
163 return false; | 114 // Disable when below the curve or exactly on it. |
164 return *packet_loss <= GetPacketLossThreshold(*uplink_bandwidth_bps_, | 115 return !config_.fec_disabling_threshold.IsAboveCurve( |
165 config_.fec_disabling_threshold, | 116 {static_cast<float>(*uplink_bandwidth_bps_), *packet_loss}); |
166 fec_disabling_threshold_info_); | 117 } |
167 } | 118 } |
168 | 119 |
169 } // namespace webrtc | 120 } // namespace webrtc |
OLD | NEW |