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

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

Issue 2643133003: Instantly pass network changes to controllers in audio network adaptor. (Closed)
Patch Set: new solution Created 3 years, 11 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
(...skipping 22 matching lines...) Expand all
33 const Clock* clock) 33 const Clock* clock)
34 : initial_fec_enabled(initial_fec_enabled), 34 : initial_fec_enabled(initial_fec_enabled),
35 fec_enabling_threshold(fec_enabling_threshold), 35 fec_enabling_threshold(fec_enabling_threshold),
36 fec_disabling_threshold(fec_disabling_threshold), 36 fec_disabling_threshold(fec_disabling_threshold),
37 time_constant_ms(time_constant_ms), 37 time_constant_ms(time_constant_ms),
38 clock(clock) {} 38 clock(clock) {}
39 39
40 FecController::FecController(const Config& config) 40 FecController::FecController(const Config& config)
41 : config_(config), 41 : config_(config),
42 fec_enabled_(config.initial_fec_enabled), 42 fec_enabled_(config.initial_fec_enabled),
43 packet_loss_smoothed_( 43 packet_loss_smoother_(
44 new SmoothingFilterImpl(config_.time_constant_ms, config_.clock)), 44 new SmoothingFilterImpl(config_.time_constant_ms, config_.clock)),
45 fec_enabling_threshold_info_(config_.fec_enabling_threshold), 45 fec_enabling_threshold_info_(config_.fec_enabling_threshold),
46 fec_disabling_threshold_info_(config_.fec_disabling_threshold) { 46 fec_disabling_threshold_info_(config_.fec_disabling_threshold) {
47 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); 47 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
48 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0); 48 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
49 RTC_DCHECK_LE( 49 RTC_DCHECK_LE(
50 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps, 50 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps,
51 config_.fec_disabling_threshold, 51 config_.fec_disabling_threshold,
52 fec_disabling_threshold_info_), 52 fec_disabling_threshold_info_),
53 config_.fec_enabling_threshold.low_bandwidth_packet_loss); 53 config_.fec_enabling_threshold.low_bandwidth_packet_loss);
54 RTC_DCHECK_LE( 54 RTC_DCHECK_LE(
55 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps, 55 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps,
56 config_.fec_disabling_threshold, 56 config_.fec_disabling_threshold,
57 fec_disabling_threshold_info_), 57 fec_disabling_threshold_info_),
58 config_.fec_enabling_threshold.high_bandwidth_packet_loss); 58 config_.fec_enabling_threshold.high_bandwidth_packet_loss);
59 } 59 }
60 60
61 FecController::FecController(const Config& config, 61 FecController::FecController(const Config& config,
62 std::unique_ptr<SmoothingFilter> smoothing_filter) 62 std::unique_ptr<SmoothingFilter> smoothing_filter)
63 : FecController(config) { 63 : FecController(config) {
64 packet_loss_smoothed_ = std::move(smoothing_filter); 64 packet_loss_smoother_ = std::move(smoothing_filter);
michaelt 2017/01/23 15:15:52 I would prefer to make packet_loss_smoothed_ const
65 } 65 }
66 66
67 FecController::~FecController() = default; 67 FecController::~FecController() = default;
68 68
69 void FecController::UpdateNetworkMetrics(
70 const NetworkMetrics& network_metrics) {
71 if (network_metrics.uplink_bandwidth_bps)
72 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
73 if (network_metrics.uplink_packet_loss_fraction) {
74 packet_loss_smoother_->AddSample(
75 *network_metrics.uplink_packet_loss_fraction);
76 }
77 }
78
69 void FecController::MakeDecision( 79 void FecController::MakeDecision(
70 const NetworkMetrics& metrics,
71 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { 80 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
72 RTC_DCHECK(!config->enable_fec); 81 RTC_DCHECK(!config->enable_fec);
73 RTC_DCHECK(!config->uplink_packet_loss_fraction); 82 RTC_DCHECK(!config->uplink_packet_loss_fraction);
74 83
75 if (metrics.uplink_packet_loss_fraction) 84 const auto& packet_loss = packet_loss_smoother_->GetAverage();
76 packet_loss_smoothed_->AddSample(*metrics.uplink_packet_loss_fraction);
77 85
78 const auto& packet_loss = packet_loss_smoothed_->GetAverage(); 86 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(packet_loss)
79 87 : FecEnablingDecision(packet_loss);
80 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision(metrics, packet_loss)
81 : FecEnablingDecision(metrics, packet_loss);
82 88
83 config->enable_fec = rtc::Optional<bool>(fec_enabled_); 89 config->enable_fec = rtc::Optional<bool>(fec_enabled_);
84 90
85 auto packet_loss_fraction = packet_loss_smoothed_->GetAverage(); 91 config->uplink_packet_loss_fraction =
86 config->uplink_packet_loss_fraction = rtc::Optional<float>( 92 rtc::Optional<float>(packet_loss ? *packet_loss : 0.0);
87 packet_loss_fraction ? *packet_loss_fraction : 0.0);
88 } 93 }
89 94
90 FecController::ThresholdInfo::ThresholdInfo( 95 FecController::ThresholdInfo::ThresholdInfo(
91 const Config::Threshold& threshold) { 96 const Config::Threshold& threshold) {
92 int bandwidth_diff_bps = 97 int bandwidth_diff_bps =
93 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps; 98 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps;
94 float packet_loss_diff = threshold.high_bandwidth_packet_loss - 99 float packet_loss_diff = threshold.high_bandwidth_packet_loss -
95 threshold.low_bandwidth_packet_loss; 100 threshold.low_bandwidth_packet_loss;
96 slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps; 101 slope = bandwidth_diff_bps == 0 ? 0.0 : packet_loss_diff / bandwidth_diff_bps;
97 offset = 102 offset =
98 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps; 103 threshold.low_bandwidth_packet_loss - slope * threshold.low_bandwidth_bps;
99 } 104 }
100 105
101 float FecController::GetPacketLossThreshold( 106 float FecController::GetPacketLossThreshold(
102 int bandwidth_bps, 107 int bandwidth_bps,
103 const Config::Threshold& threshold, 108 const Config::Threshold& threshold,
104 const ThresholdInfo& threshold_info) const { 109 const ThresholdInfo& threshold_info) const {
105 if (bandwidth_bps < threshold.low_bandwidth_bps) 110 if (bandwidth_bps < threshold.low_bandwidth_bps)
106 return std::numeric_limits<float>::max(); 111 return std::numeric_limits<float>::max();
107 if (bandwidth_bps >= threshold.high_bandwidth_bps) 112 if (bandwidth_bps >= threshold.high_bandwidth_bps)
108 return threshold.high_bandwidth_packet_loss; 113 return threshold.high_bandwidth_packet_loss;
109 return threshold_info.offset + threshold_info.slope * bandwidth_bps; 114 return threshold_info.offset + threshold_info.slope * bandwidth_bps;
110 } 115 }
111 116
112 bool FecController::FecEnablingDecision( 117 bool FecController::FecEnablingDecision(
113 const NetworkMetrics& metrics,
114 const rtc::Optional<float>& packet_loss) const { 118 const rtc::Optional<float>& packet_loss) const {
115 if (!metrics.uplink_bandwidth_bps) 119 if (!uplink_bandwidth_bps_)
116 return false; 120 return false;
117 if (!packet_loss) 121 if (!packet_loss)
118 return false; 122 return false;
119 return *packet_loss >= GetPacketLossThreshold(*metrics.uplink_bandwidth_bps, 123 return *packet_loss >= GetPacketLossThreshold(*uplink_bandwidth_bps_,
120 config_.fec_enabling_threshold, 124 config_.fec_enabling_threshold,
121 fec_enabling_threshold_info_); 125 fec_enabling_threshold_info_);
122 } 126 }
123 127
124 bool FecController::FecDisablingDecision( 128 bool FecController::FecDisablingDecision(
125 const NetworkMetrics& metrics,
126 const rtc::Optional<float>& packet_loss) const { 129 const rtc::Optional<float>& packet_loss) const {
127 if (!metrics.uplink_bandwidth_bps) 130 if (!uplink_bandwidth_bps_)
128 return false; 131 return false;
129 if (!packet_loss) 132 if (!packet_loss)
130 return false; 133 return false;
131 return *packet_loss <= GetPacketLossThreshold(*metrics.uplink_bandwidth_bps, 134 return *packet_loss <= GetPacketLossThreshold(*uplink_bandwidth_bps_,
132 config_.fec_disabling_threshold, 135 config_.fec_disabling_threshold,
133 fec_disabling_threshold_info_); 136 fec_disabling_threshold_info_);
134 } 137 }
135 138
136 } // namespace webrtc 139 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698