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

Side by Side Diff: webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.cc

Issue 2672933003: Introduce FecControllerRplrBased (Closed)
Patch Set: Merged 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 unified diff | Download patch
OLDNEW
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
11 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller.h" 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_plr_b ased.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 FecController::Config::Threshold::Threshold(int low_bandwidth_bps, 20 FecControllerPlrBased::Config::Threshold::Threshold(
21 float low_bandwidth_packet_loss, 21 int low_bandwidth_bps,
22 int high_bandwidth_bps, 22 float low_bandwidth_packet_loss,
23 float high_bandwidth_packet_loss) 23 int high_bandwidth_bps,
24 float high_bandwidth_packet_loss)
24 : low_bandwidth_bps(low_bandwidth_bps), 25 : low_bandwidth_bps(low_bandwidth_bps),
25 low_bandwidth_packet_loss(low_bandwidth_packet_loss), 26 low_bandwidth_packet_loss(low_bandwidth_packet_loss),
26 high_bandwidth_bps(high_bandwidth_bps), 27 high_bandwidth_bps(high_bandwidth_bps),
27 high_bandwidth_packet_loss(high_bandwidth_packet_loss) {} 28 high_bandwidth_packet_loss(high_bandwidth_packet_loss) {}
28 29
29 FecController::Config::Config(bool initial_fec_enabled, 30 FecControllerPlrBased::Config::Config(bool initial_fec_enabled,
30 const Threshold& fec_enabling_threshold, 31 const Threshold& fec_enabling_threshold,
31 const Threshold& fec_disabling_threshold, 32 const Threshold& fec_disabling_threshold,
32 int time_constant_ms, 33 int time_constant_ms,
33 const Clock* clock) 34 const Clock* clock)
34 : initial_fec_enabled(initial_fec_enabled), 35 : initial_fec_enabled(initial_fec_enabled),
35 fec_enabling_threshold(fec_enabling_threshold), 36 fec_enabling_threshold(fec_enabling_threshold),
36 fec_disabling_threshold(fec_disabling_threshold), 37 fec_disabling_threshold(fec_disabling_threshold),
37 time_constant_ms(time_constant_ms), 38 time_constant_ms(time_constant_ms),
38 clock(clock) {} 39 clock(clock) {}
39 40
40 FecController::FecController(const Config& config, 41 FecControllerPlrBased::FecControllerPlrBased(
41 std::unique_ptr<SmoothingFilter> smoothing_filter) 42 const Config& config,
43 std::unique_ptr<SmoothingFilter> smoothing_filter)
42 : config_(config), 44 : config_(config),
43 fec_enabled_(config.initial_fec_enabled), 45 fec_enabled_(config.initial_fec_enabled),
44 packet_loss_smoother_(std::move(smoothing_filter)), 46 packet_loss_smoother_(std::move(smoothing_filter)),
45 fec_enabling_threshold_info_(config_.fec_enabling_threshold), 47 fec_enabling_threshold_info_(config_.fec_enabling_threshold),
46 fec_disabling_threshold_info_(config_.fec_disabling_threshold) { 48 fec_disabling_threshold_info_(config_.fec_disabling_threshold) {
47 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); 49 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
48 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); 50 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
49 RTC_DCHECK_LE( 51 RTC_DCHECK_LE(
50 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps, 52 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps,
51 config_.fec_disabling_threshold, 53 config_.fec_disabling_threshold,
52 fec_disabling_threshold_info_), 54 fec_disabling_threshold_info_),
53 config_.fec_enabling_threshold.low_bandwidth_packet_loss); 55 config_.fec_enabling_threshold.low_bandwidth_packet_loss);
54 RTC_DCHECK_LE( 56 RTC_DCHECK_LE(
55 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps, 57 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps,
56 config_.fec_disabling_threshold, 58 config_.fec_disabling_threshold,
57 fec_disabling_threshold_info_), 59 fec_disabling_threshold_info_),
58 config_.fec_enabling_threshold.high_bandwidth_packet_loss); 60 config_.fec_enabling_threshold.high_bandwidth_packet_loss);
59 } 61 }
60 62
61 FecController::FecController(const Config& config) 63 FecControllerPlrBased::FecControllerPlrBased(const Config& config)
62 : FecController( 64 : FecControllerPlrBased(
63 config, 65 config,
64 std::unique_ptr<SmoothingFilter>( 66 std::unique_ptr<SmoothingFilter>(
65 new SmoothingFilterImpl(config.time_constant_ms, config.clock))) { 67 new SmoothingFilterImpl(config.time_constant_ms, config.clock))) {
66 } 68 }
67 69
68 FecController::~FecController() = default; 70 FecControllerPlrBased::~FecControllerPlrBased() = default;
69 71
70 void FecController::UpdateNetworkMetrics( 72 void FecControllerPlrBased::UpdateNetworkMetrics(
71 const NetworkMetrics& network_metrics) { 73 const NetworkMetrics& network_metrics) {
72 if (network_metrics.uplink_bandwidth_bps) 74 if (network_metrics.uplink_bandwidth_bps)
73 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps; 75 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
74 if (network_metrics.uplink_packet_loss_fraction) { 76 if (network_metrics.uplink_packet_loss_fraction) {
75 packet_loss_smoother_->AddSample( 77 packet_loss_smoother_->AddSample(
76 *network_metrics.uplink_packet_loss_fraction); 78 *network_metrics.uplink_packet_loss_fraction);
77 } 79 }
78 } 80 }
79 81
80 void FecController::MakeDecision( 82 void FecControllerPlrBased::MakeDecision(
81 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { 83 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
82 RTC_DCHECK(!config->enable_fec); 84 RTC_DCHECK(!config->enable_fec);
83 RTC_DCHECK(!config->uplink_packet_loss_fraction); 85 RTC_DCHECK(!config->uplink_packet_loss_fraction);
84 86
85 const auto& packet_loss = packet_loss_smoother_->GetAverage(); 87 const auto& packet_loss = packet_loss_smoother_->GetAverage();
86 88
87 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss) 89 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss)
88 : FecEnablingDecision(packet_loss); 90 : FecEnablingDecision(packet_loss);
89 91
90 config->enable_fec = rtc::Optional<bool>(fec_enabled_); 92 config->enable_fec = rtc::Optional<bool>(fec_enabled_);
91 93
92 config->uplink_packet_loss_fraction = 94 config->uplink_packet_loss_fraction =
93 rtc::Optional<float>(packet_loss ? *packet_loss : 0.0); 95 rtc::Optional<float>(packet_loss ? *packet_loss : 0.0);
94 } 96 }
95 97
96 FecController::ThresholdInfo::ThresholdInfo( 98 FecControllerPlrBased::ThresholdInfo::ThresholdInfo(
97 const Config::Threshold& threshold) { 99 const Config::Threshold& threshold) {
98 int bandwidth_diff_bps = 100 int bandwidth_diff_bps =
99 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps; 101 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps;
100 float packet_loss_diff = threshold.high_bandwidth_packet_loss - 102 float packet_loss_diff = threshold.high_bandwidth_packet_loss -
101 threshold.low_bandwidth_packet_loss; 103 threshold.low_bandwidth_packet_loss;
102 slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps; 104 slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps;
103 offset = 105 offset =
104 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps; 106 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps;
105 } 107 }
106 108
107 float FecController::GetPacketLossThreshold( 109 float FecControllerPlrBased::GetPacketLossThreshold(
108 int bandwidth_bps, 110 int bandwidth_bps,
109 const Config::Threshold& threshold, 111 const Config::Threshold& threshold,
110 const ThresholdInfo& threshold_info) const { 112 const ThresholdInfo& threshold_info) const {
111 if (bandwidth_bps < threshold.low_bandwidth_bps) 113 if (bandwidth_bps < threshold.low_bandwidth_bps) {
112 return std::numeric_limits<float>::max(); 114 return std::numeric_limits<float>::max();
113 if (bandwidth_bps >= threshold.high_bandwidth_bps) 115 } else if (bandwidth_bps >= threshold.high_bandwidth_bps) {
114 return threshold.high_bandwidth_packet_loss; 116 return threshold.high_bandwidth_packet_loss;
115 return threshold_info.offset + threshold_info.slope * bandwidth_bps; 117 } else {
118 float rc = threshold_info.offset + threshold_info.slope * bandwidth_bps;
119 RTC_DCHECK_LE(rc, threshold.low_bandwidth_packet_loss);
120 RTC_DCHECK_GE(rc, threshold.high_bandwidth_packet_loss);
121 return rc;
122 }
116 } 123 }
117 124
118 bool FecController::FecEnablingDecision( 125 bool FecControllerPlrBased::FecEnablingDecision(
119 const rtc::Optional<float>& packet_loss) const { 126 const rtc::Optional<float>& packet_loss) const {
120 if (!uplink_bandwidth_bps_) 127 if (!uplink_bandwidth_bps_)
121 return false; 128 return false;
122 if (!packet_loss) 129 if (!packet_loss)
123 return false; 130 return false;
124 return *packet_loss >= GetPacketLossThreshold(*uplink_bandwidth_bps_, 131 return *packet_loss >= GetPacketLossThreshold(*uplink_bandwidth_bps_,
125 config_.fec_enabling_threshold, 132 config_.fec_enabling_threshold,
126 fec_enabling_threshold_info_); 133 fec_enabling_threshold_info_);
127 } 134 }
128 135
129 bool FecController::FecDisablingDecision( 136 bool FecControllerPlrBased::FecDisablingDecision(
130 const rtc::Optional<float>& packet_loss) const { 137 const rtc::Optional<float>& packet_loss) const {
131 if (!uplink_bandwidth_bps_) 138 if (!uplink_bandwidth_bps_)
132 return false; 139 return false;
133 if (!packet_loss) 140 if (!packet_loss)
134 return false; 141 return false;
135 return *packet_loss <= GetPacketLossThreshold(*uplink_bandwidth_bps_, 142 return *packet_loss <= GetPacketLossThreshold(*uplink_bandwidth_bps_,
136 config_.fec_disabling_threshold, 143 config_.fec_disabling_threshold,
137 fec_disabling_threshold_info_); 144 fec_disabling_threshold_info_);
138 } 145 }
139 146
140 } // namespace webrtc 147 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698