Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "webrtc/base/checks.h" | |
| 14 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller.h" | |
|
hlundin-webrtc
2016/09/19 14:46:43
fec_controller.h first of all.
minyue-webrtc
2016/09/20 11:58:43
Done.
| |
| 15 | |
| 16 namespace webrtc { | |
| 17 | |
| 18 FecController::Config::Threshold::Threshold(int low_bandwidth_bps, | |
| 19 float low_bandwidth_packet_loss, | |
| 20 int high_bandwidth_bps, | |
| 21 float high_bandwidth_packet_loss) | |
| 22 : low_bandwidth_bps(low_bandwidth_bps), | |
| 23 low_bandwidth_packet_loss(low_bandwidth_packet_loss), | |
| 24 high_bandwidth_bps(high_bandwidth_bps), | |
| 25 high_bandwidth_packet_loss(high_bandwidth_packet_loss) {} | |
| 26 | |
| 27 FecController::Config::Config(bool initial_fec_enabled, | |
| 28 const Threshold& fec_enabling_threshold, | |
| 29 const Threshold& fec_disabling_threshold, | |
| 30 int time_constant_ms, | |
| 31 Clock* clock) | |
| 32 : initial_fec_enabled(initial_fec_enabled), | |
| 33 fec_enabling_threshold(fec_enabling_threshold), | |
| 34 fec_disabling_threshold(fec_disabling_threshold), | |
| 35 time_constant_ms(time_constant_ms), | |
| 36 clock(clock) {} | |
| 37 | |
| 38 FecController::FecController(const Config& config) | |
| 39 : config_(config), | |
| 40 fec_enabled_(config.initial_fec_enabled), | |
| 41 packet_loss_smoothed_( | |
| 42 new SmoothingFilterImpl(config_.time_constant_ms, config_.clock)), | |
| 43 fec_enabling_threshold_info(config_.fec_enabling_threshold), | |
| 44 fec_disabling_threshold_info(config_.fec_disabling_threshold) { | |
| 45 RTC_DCHECK_LE(fec_enabling_threshold_info.slope, 0); | |
|
hlundin-webrtc
2016/09/19 14:46:43
Are these checks enough to make sure the lines don
minyue-webrtc
2016/09/20 11:58:43
No, this cannot guarantee no-intersection. they on
| |
| 46 RTC_DCHECK_LE(fec_enabling_threshold_info.slope, 0); | |
| 47 RTC_DCHECK_GE(config_.fec_enabling_threshold.low_bandwidth_bps, | |
| 48 config_.fec_disabling_threshold.low_bandwidth_bps); | |
| 49 RTC_DCHECK_GE(config_.fec_enabling_threshold.high_bandwidth_packet_loss, | |
| 50 config_.fec_disabling_threshold.high_bandwidth_packet_loss); | |
| 51 } | |
| 52 | |
| 53 FecController::FecController(const Config& config, | |
| 54 std::unique_ptr<SmoothingFilter> smoothing_filter) | |
| 55 : FecController(config) { | |
| 56 packet_loss_smoothed_ = std::move(smoothing_filter); | |
| 57 } | |
| 58 | |
| 59 FecController::~FecController() = default; | |
| 60 | |
| 61 void FecController::MakeDecision( | |
| 62 const NetworkMetrics& metrics, | |
| 63 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { | |
| 64 RTC_DCHECK(!config->enable_fec); | |
| 65 RTC_DCHECK(!config->uplink_packet_loss_fraction); | |
| 66 | |
| 67 if (metrics.uplink_packet_loss_fraction) | |
| 68 packet_loss_smoothed_->AddSample(*metrics.uplink_packet_loss_fraction); | |
| 69 | |
| 70 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(metrics) | |
| 71 : FecEnablingDecision(metrics); | |
| 72 | |
| 73 config->enable_fec = rtc::Optional<bool>(fec_enabled_); | |
| 74 | |
| 75 if (fec_enabled_) { | |
| 76 auto packet_loss_fraction = packet_loss_smoothed_->GetAverage(); | |
| 77 config->uplink_packet_loss_fraction = rtc::Optional<float>( | |
| 78 packet_loss_fraction ? *packet_loss_fraction : 0.0); | |
| 79 } else { | |
| 80 config->uplink_packet_loss_fraction = rtc::Optional<float>(0.0); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 FecController::ThresholdInfo::ThresholdInfo( | |
| 85 const Config::Threshold& threshold) { | |
| 86 int bandwidth_diff_bps = | |
| 87 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps; | |
| 88 float packet_loss_diff = threshold.high_bandwidth_packet_loss - | |
| 89 threshold.low_bandwidth_packet_loss; | |
| 90 slope = packet_loss_diff / bandwidth_diff_bps; | |
|
hlundin-webrtc
2016/09/19 14:46:43
How is bandwidth_diff_bps protected from being 0?
minyue-webrtc
2016/09/20 11:58:43
good catch.
| |
| 91 offset = | |
| 92 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps; | |
| 93 } | |
| 94 | |
| 95 float FecController::GetPacketLossThreshold( | |
| 96 int bandwidth_bps, | |
| 97 const FecController::ThresholdInfo& threshold_info) const { | |
| 98 return threshold_info.offset + threshold_info.slope * bandwidth_bps; | |
| 99 } | |
| 100 | |
| 101 bool FecController::FecEnablingDecision(const NetworkMetrics& metrics) const { | |
| 102 if (!metrics.uplink_bandwidth_bps) | |
| 103 return false; | |
| 104 | |
| 105 auto packet_loss = packet_loss_smoothed_->GetAverage(); | |
| 106 if (!packet_loss) | |
| 107 return false; | |
| 108 | |
| 109 if (*metrics.uplink_bandwidth_bps >= | |
| 110 config_.fec_enabling_threshold.high_bandwidth_bps && | |
| 111 *packet_loss >= config_.fec_enabling_threshold.high_bandwidth_packet_loss) | |
| 112 return true; | |
| 113 | |
| 114 if (*metrics.uplink_bandwidth_bps < | |
| 115 config_.fec_enabling_threshold.high_bandwidth_bps && | |
| 116 *metrics.uplink_bandwidth_bps >= | |
| 117 config_.fec_enabling_threshold.low_bandwidth_bps && | |
| 118 *packet_loss >= GetPacketLossThreshold(*metrics.uplink_bandwidth_bps, | |
| 119 fec_enabling_threshold_info)) | |
| 120 return true; | |
| 121 | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 bool FecController::FecDisablingDecision(const NetworkMetrics& metrics) const { | |
| 126 if (!metrics.uplink_bandwidth_bps) | |
| 127 return false; | |
| 128 | |
| 129 auto packet_loss = packet_loss_smoothed_->GetAverage(); | |
| 130 if (!packet_loss) | |
| 131 return false; | |
| 132 | |
| 133 if (*metrics.uplink_bandwidth_bps <= | |
| 134 config_.fec_disabling_threshold.low_bandwidth_bps) | |
| 135 return true; | |
| 136 | |
| 137 if (*metrics.uplink_bandwidth_bps >= | |
| 138 config_.fec_disabling_threshold.high_bandwidth_bps && | |
| 139 *packet_loss <= | |
| 140 config_.fec_disabling_threshold.high_bandwidth_packet_loss) | |
| 141 return true; | |
| 142 | |
| 143 if (*metrics.uplink_bandwidth_bps > | |
| 144 config_.fec_disabling_threshold.low_bandwidth_bps && | |
| 145 *metrics.uplink_bandwidth_bps < | |
| 146 config_.fec_disabling_threshold.high_bandwidth_bps && | |
| 147 *packet_loss <= GetPacketLossThreshold(*metrics.uplink_bandwidth_bps, | |
| 148 fec_disabling_threshold_info)) | |
| 149 return true; | |
| 150 | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 } // namespace webrtc | |
| OLD | NEW |