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

Side by Side Diff: webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_rplr_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
(Empty)
1 /*
2 * Copyright (c) 2017 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 "webrtc/modules/audio_coding/audio_network_adaptor/fec_controller_rplr_ based.h"
12
13 #include <limits>
14 #include <utility>
15
16 #include "webrtc/base/checks.h"
17
18 namespace webrtc {
19
20 FecControllerRplrBased::Config::Threshold::Threshold(
21 int low_bandwidth_bps,
22 float low_bandwidth_recoverable_packet_loss,
23 int high_bandwidth_bps,
24 float high_bandwidth_recoverable_packet_loss)
25 : low_bandwidth_bps(low_bandwidth_bps),
26 low_bandwidth_recoverable_packet_loss(
27 low_bandwidth_recoverable_packet_loss),
28 high_bandwidth_bps(high_bandwidth_bps),
29 high_bandwidth_recoverable_packet_loss(
30 high_bandwidth_recoverable_packet_loss) {}
31
32 FecControllerRplrBased::Config::Config(bool initial_fec_enabled,
33 const Threshold& fec_enabling_threshold,
34 const Threshold& fec_disabling_threshold,
35 int time_constant_ms,
36 const Clock* clock)
37 : initial_fec_enabled(initial_fec_enabled),
38 fec_enabling_threshold(fec_enabling_threshold),
39 fec_disabling_threshold(fec_disabling_threshold),
40 time_constant_ms(time_constant_ms),
41 clock(clock) {}
42
43 FecControllerRplrBased::FecControllerRplrBased(const Config& config)
44 : config_(config),
45 fec_enabled_(config.initial_fec_enabled),
46 fec_enabling_threshold_info_(config_.fec_enabling_threshold),
47 fec_disabling_threshold_info_(config_.fec_disabling_threshold) {
48 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
49 RTC_DCHECK_LE(fec_enabling_threshold_info_.slope, 0);
50 RTC_DCHECK_LE(
51 GetPacketLossThreshold(config_.fec_enabling_threshold.low_bandwidth_bps,
52 config_.fec_disabling_threshold,
53 fec_disabling_threshold_info_),
54 config_.fec_enabling_threshold.low_bandwidth_recoverable_packet_loss);
55 RTC_DCHECK_LE(
56 GetPacketLossThreshold(config_.fec_enabling_threshold.high_bandwidth_bps,
57 config_.fec_disabling_threshold,
58 fec_disabling_threshold_info_),
59 config_.fec_enabling_threshold.high_bandwidth_recoverable_packet_loss);
60 }
61
62 FecControllerRplrBased::~FecControllerRplrBased() = default;
63
64 void FecControllerRplrBased::UpdateNetworkMetrics(
65 const NetworkMetrics& network_metrics) {
66 if (network_metrics.uplink_bandwidth_bps)
67 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
68 if (network_metrics.uplink_recoverable_packet_loss_fraction) {
69 uplink_recoverable_packet_loss_ =
70 network_metrics.uplink_recoverable_packet_loss_fraction;
71 }
72 }
73
74 void FecControllerRplrBased::MakeDecision(
75 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
76 RTC_DCHECK(!config->enable_fec);
77 RTC_DCHECK(!config->uplink_packet_loss_fraction);
78
79 fec_enabled_ = fec_enabled_ ? !FecDisablingDecision() : FecEnablingDecision();
80
81 config->enable_fec = rtc::Optional<bool>(fec_enabled_);
82 config->uplink_packet_loss_fraction = rtc::Optional<float>(
83 uplink_recoverable_packet_loss_ ? *uplink_recoverable_packet_loss_ : 0.0);
84 }
85
86 FecControllerRplrBased::ThresholdInfo::ThresholdInfo(
87 const Config::Threshold& threshold) {
88 int bandwidth_diff_bps =
89 threshold.high_bandwidth_bps - threshold.low_bandwidth_bps;
90 float recoverable_packet_loss_diff =
91 threshold.high_bandwidth_recoverable_packet_loss -
92 threshold.low_bandwidth_recoverable_packet_loss;
93 slope = bandwidth_diff_bps == 0
94 ? 0.0
95 : recoverable_packet_loss_diff / bandwidth_diff_bps;
96 offset = threshold.low_bandwidth_recoverable_packet_loss -
97 slope * threshold.low_bandwidth_bps;
98 }
99
100 float FecControllerRplrBased::GetPacketLossThreshold(
101 int bandwidth_bps,
102 const Config::Threshold& threshold,
103 const ThresholdInfo& threshold_info) const {
104 if (bandwidth_bps < threshold.low_bandwidth_bps) {
105 return std::numeric_limits<float>::max();
106 } else if (bandwidth_bps >= threshold.high_bandwidth_bps) {
107 return threshold.high_bandwidth_recoverable_packet_loss;
108 } else {
109 float rc = threshold_info.offset + threshold_info.slope * bandwidth_bps;
110 RTC_DCHECK_LE(rc, threshold.low_bandwidth_recoverable_packet_loss);
111 RTC_DCHECK_GE(rc, threshold.high_bandwidth_recoverable_packet_loss);
112 return rc;
113 }
114 }
115
116 bool FecControllerRplrBased::FecEnablingDecision() const {
117 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) {
118 return false;
119 } else {
120 return *uplink_recoverable_packet_loss_ >=
121 GetPacketLossThreshold(*uplink_bandwidth_bps_,
122 config_.fec_enabling_threshold,
123 fec_enabling_threshold_info_);
124 }
125 }
126
127 bool FecControllerRplrBased::FecDisablingDecision() const {
128 if (!uplink_bandwidth_bps_ || !uplink_recoverable_packet_loss_) {
129 return false;
130 } else {
131 return *uplink_recoverable_packet_loss_ <=
132 GetPacketLossThreshold(*uplink_bandwidth_bps_,
133 config_.fec_disabling_threshold,
134 fec_disabling_threshold_info_);
135 }
136 }
137
138 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698