Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc

Issue 2688613003: Introduce ThresholdCurve (avoids code duplication between PLR/RPLR-based FecController) (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc b/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc
index 6252364cd5e3e2dae6a289fff69232b98ce35552..835970f17ddd3195ece93d6809919e3215e98e4d 100644
--- a/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc
@@ -37,21 +37,12 @@ class NullSmoothingFilter final : public SmoothingFilter {
};
}
-FecControllerPlrBased::Config::Threshold::Threshold(
- int low_bandwidth_bps,
- float low_bandwidth_packet_loss,
- int high_bandwidth_bps,
- float high_bandwidth_packet_loss)
- : low_bandwidth_bps(low_bandwidth_bps),
- low_bandwidth_packet_loss(low_bandwidth_packet_loss),
- high_bandwidth_bps(high_bandwidth_bps),
- high_bandwidth_packet_loss(high_bandwidth_packet_loss) {}
-
-FecControllerPlrBased::Config::Config(bool initial_fec_enabled,
- const Threshold& fec_enabling_threshold,
- const Threshold& fec_disabling_threshold,
- int time_constant_ms,
- const Clock* clock)
+FecControllerPlrBased::Config::Config(
+ bool initial_fec_enabled,
+ const ThresholdCurve& fec_enabling_threshold,
+ const ThresholdCurve& fec_disabling_threshold,
+ int time_constant_ms,
+ const Clock* clock)
: initial_fec_enabled(initial_fec_enabled),
fec_enabling_threshold(fec_enabling_threshold),
fec_disabling_threshold(fec_disabling_threshold),
@@ -63,21 +54,8 @@ FecControllerPlrBased::FecControllerPlrBased(
std::unique_ptr<SmoothingFilter> smoothing_filter)
: config_(config),
fec_enabled_(config.initial_fec_enabled),
- packet_loss_smoother_(std::move(smoothing_filter)),
- fec_enabling_threshold_info_(config_.fec_enabling_threshold),
- fec_disabling_threshold_info_(config_.fec_disabling_threshold) {
- RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
- RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
- RTC_DCHECK_LE(
- GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps,
- config_.fec_disabling_threshold,
- fec_disabling_threshold_info_),
- config_.fec_enabling_threshold.low_bandwidth_packet_loss);
- RTC_DCHECK_LE(
- GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps,
- config_.fec_disabling_threshold,
- fec_disabling_threshold_info_),
- config_.fec_enabling_threshold.high_bandwidth_packet_loss);
+ packet_loss_smoother_(std::move(smoothing_filter)) {
+ RTC_DCHECK(config_.fec_disabling_threshold <= config_.fec_enabling_threshold);
}
FecControllerPlrBased::FecControllerPlrBased(const Config& config)
@@ -117,53 +95,26 @@ void FecControllerPlrBased::MakeDecision(
rtc::Optional<float>(packet_loss ? *packet_loss : 0.0);
}
-FecControllerPlrBased::ThresholdInfo::ThresholdInfo(
- const Config::Threshold& threshold) {
- int bandwidth_diff_bps =
- threshold.high_bandwidth_bps - threshold.low_bandwidth_bps;
- float packet_loss_diff = threshold.high_bandwidth_packet_loss -
- threshold.low_bandwidth_packet_loss;
- slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps;
- offset =
- threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps;
-}
-
-float FecControllerPlrBased::GetPacketLossThreshold(
- int bandwidth_bps,
- const Config::Threshold& threshold,
- const ThresholdInfo& threshold_info) const {
- if (bandwidth_bps < threshold.low_bandwidth_bps) {
- return std::numeric_limits<float>::max();
- } else if (bandwidth_bps >= threshold.high_bandwidth_bps) {
- return threshold.high_bandwidth_packet_loss;
- } else {
- float rc = threshold_info.offset + threshold_info.slope * bandwidth_bps;
- RTC_DCHECK_LE(rc, threshold.low_bandwidth_packet_loss);
- RTC_DCHECK_GE(rc, threshold.high_bandwidth_packet_loss);
- return rc;
- }
-}
-
bool FecControllerPlrBased::FecEnablingDecision(
const rtc::Optional<float>& packet_loss) const {
- if (!uplink_bandwidth_bps_)
+ if (!uplink_bandwidth_bps_ || !packet_loss) {
return false;
- if (!packet_loss)
- return false;
- return *packet_loss >= GetPacketLossThreshold(*uplink_bandwidth_bps_,
- config_.fec_enabling_threshold,
- fec_enabling_threshold_info_);
+ } else {
+ // Enable when above the curve or exactly on it.
+ return !config_.fec_enabling_threshold.IsBelowCurve(
+ {static_cast<float>(*uplink_bandwidth_bps_), *packet_loss});
+ }
}
bool FecControllerPlrBased::FecDisablingDecision(
const rtc::Optional<float>& packet_loss) const {
- if (!uplink_bandwidth_bps_)
+ if (!uplink_bandwidth_bps_ || !packet_loss) {
return false;
- if (!packet_loss)
- return false;
- return *packet_loss <= GetPacketLossThreshold(*uplink_bandwidth_bps_,
- config_.fec_disabling_threshold,
- fec_disabling_threshold_info_);
+ } else {
+ // Disable when below the curve or exactly on it.
+ return !config_.fec_disabling_threshold.IsAboveCurve(
+ {static_cast<float>(*uplink_bandwidth_bps_), *packet_loss});
+ }
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698