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

Side by Side Diff: modules/audio_coding/audio_network_adaptor/frame_length_controller.cc

Issue 3013613002: Added configurable offsets to the per-packet overhead in ANA. (Closed)
Patch Set: Added conversion to size_t in DCHECK. Created 3 years, 3 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 "modules/audio_coding/audio_network_adaptor/frame_length_controller.h" 11 #include "modules/audio_coding/audio_network_adaptor/frame_length_controller.h"
12 12
13 #include <algorithm>
13 #include <utility> 14 #include <utility>
14 15
15 #include "rtc_base/checks.h" 16 #include "rtc_base/checks.h"
16 #include "rtc_base/logging.h" 17 #include "rtc_base/logging.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 20
20 namespace { 21 namespace {
21 constexpr int kPreventOveruseMarginBps = 5000; 22 constexpr int kPreventOveruseMarginBps = 5000;
22 23
23 int OverheadRateBps(size_t overhead_bytes_per_packet, int frame_length_ms) { 24 int OverheadRateBps(size_t overhead_bytes_per_packet, int frame_length_ms) {
24 return static_cast<int>(overhead_bytes_per_packet * 8 * 1000 / 25 return static_cast<int>(overhead_bytes_per_packet * 8 * 1000 /
25 frame_length_ms); 26 frame_length_ms);
26 } 27 }
27 } 28 }
28 29
29 FrameLengthController::Config::Config( 30 FrameLengthController::Config::Config(
30 const std::vector<int>& encoder_frame_lengths_ms, 31 const std::vector<int>& encoder_frame_lengths_ms,
31 int initial_frame_length_ms, 32 int initial_frame_length_ms,
32 int min_encoder_bitrate_bps, 33 int min_encoder_bitrate_bps,
33 float fl_increasing_packet_loss_fraction, 34 float fl_increasing_packet_loss_fraction,
34 float fl_decreasing_packet_loss_fraction, 35 float fl_decreasing_packet_loss_fraction,
36 int fl_increase_overhead_offset,
37 int fl_decrease_overhead_offset,
35 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps) 38 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps)
36 : encoder_frame_lengths_ms(encoder_frame_lengths_ms), 39 : encoder_frame_lengths_ms(encoder_frame_lengths_ms),
37 initial_frame_length_ms(initial_frame_length_ms), 40 initial_frame_length_ms(initial_frame_length_ms),
38 min_encoder_bitrate_bps(min_encoder_bitrate_bps), 41 min_encoder_bitrate_bps(min_encoder_bitrate_bps),
39 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction), 42 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction),
40 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction), 43 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction),
44 fl_increase_overhead_offset(fl_increase_overhead_offset),
45 fl_decrease_overhead_offset(fl_decrease_overhead_offset),
41 fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {} 46 fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {}
42 47
43 FrameLengthController::Config::Config(const Config& other) = default; 48 FrameLengthController::Config::Config(const Config& other) = default;
44 49
45 FrameLengthController::Config::~Config() = default; 50 FrameLengthController::Config::~Config() = default;
46 51
47 FrameLengthController::FrameLengthController(const Config& config) 52 FrameLengthController::FrameLengthController(const Config& config)
48 : config_(config) { 53 : config_(config) {
49 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(), 54 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(),
50 config_.encoder_frame_lengths_ms.end(), 55 config_.encoder_frame_lengths_ms.end(),
(...skipping 13 matching lines...) Expand all
64 if (network_metrics.overhead_bytes_per_packet) 69 if (network_metrics.overhead_bytes_per_packet)
65 overhead_bytes_per_packet_ = network_metrics.overhead_bytes_per_packet; 70 overhead_bytes_per_packet_ = network_metrics.overhead_bytes_per_packet;
66 } 71 }
67 72
68 void FrameLengthController::MakeDecision(AudioEncoderRuntimeConfig* config) { 73 void FrameLengthController::MakeDecision(AudioEncoderRuntimeConfig* config) {
69 // Decision on |frame_length_ms| should not have been made. 74 // Decision on |frame_length_ms| should not have been made.
70 RTC_DCHECK(!config->frame_length_ms); 75 RTC_DCHECK(!config->frame_length_ms);
71 76
72 if (FrameLengthIncreasingDecision(*config)) { 77 if (FrameLengthIncreasingDecision(*config)) {
73 ++frame_length_ms_; 78 ++frame_length_ms_;
79 prev_decision_increase_ = true;
74 } else if (FrameLengthDecreasingDecision(*config)) { 80 } else if (FrameLengthDecreasingDecision(*config)) {
75 --frame_length_ms_; 81 --frame_length_ms_;
82 prev_decision_increase_ = false;
76 } 83 }
84 config->last_fl_change_increase = prev_decision_increase_;
77 config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_); 85 config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_);
78 } 86 }
79 87
80 FrameLengthController::Config::FrameLengthChange::FrameLengthChange( 88 FrameLengthController::Config::FrameLengthChange::FrameLengthChange(
81 int from_frame_length_ms, 89 int from_frame_length_ms,
82 int to_frame_length_ms) 90 int to_frame_length_ms)
83 : from_frame_length_ms(from_frame_length_ms), 91 : from_frame_length_ms(from_frame_length_ms),
84 to_frame_length_ms(to_frame_length_ms) {} 92 to_frame_length_ms(to_frame_length_ms) {}
85 93
86 bool FrameLengthController::Config::FrameLengthChange::operator<( 94 bool FrameLengthController::Config::FrameLengthChange::operator<(
(...skipping 16 matching lines...) Expand all
103 auto longer_frame_length_ms = std::next(frame_length_ms_); 111 auto longer_frame_length_ms = std::next(frame_length_ms_);
104 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end()) 112 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end())
105 return false; 113 return false;
106 114
107 auto increase_threshold = config_.fl_changing_bandwidths_bps.find( 115 auto increase_threshold = config_.fl_changing_bandwidths_bps.find(
108 Config::FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms)); 116 Config::FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms));
109 117
110 if (increase_threshold == config_.fl_changing_bandwidths_bps.end()) 118 if (increase_threshold == config_.fl_changing_bandwidths_bps.end())
111 return false; 119 return false;
112 120
121 // Check that
122 // -(*overhead_bytes_per_packet_) <= offset <= (*overhead_bytes_per_packet_)
123 RTC_DCHECK(
124 !overhead_bytes_per_packet_ ||
125 (overhead_bytes_per_packet_ &&
126 static_cast<size_t>(std::max(0, -config_.fl_increase_overhead_offset)) <=
127 *overhead_bytes_per_packet_ &&
128 static_cast<size_t>(std::max(0, config_.fl_increase_overhead_offset)) <=
129 *overhead_bytes_per_packet_));
130
113 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ && 131 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
114 *uplink_bandwidth_bps_ <= 132 *uplink_bandwidth_bps_ <=
115 config_.min_encoder_bitrate_bps + kPreventOveruseMarginBps + 133 config_.min_encoder_bitrate_bps + kPreventOveruseMarginBps +
116 OverheadRateBps(*overhead_bytes_per_packet_, *frame_length_ms_)) { 134 OverheadRateBps(*overhead_bytes_per_packet_ +
135 config_.fl_increase_overhead_offset,
136 *frame_length_ms_)) {
117 return true; 137 return true;
118 } 138 }
119 139
120 return (uplink_bandwidth_bps_ && 140 return (uplink_bandwidth_bps_ &&
121 *uplink_bandwidth_bps_ <= increase_threshold->second) && 141 *uplink_bandwidth_bps_ <= increase_threshold->second) &&
122 (uplink_packet_loss_fraction_ && 142 (uplink_packet_loss_fraction_ &&
123 *uplink_packet_loss_fraction_ <= 143 *uplink_packet_loss_fraction_ <=
124 config_.fl_increasing_packet_loss_fraction); 144 config_.fl_increasing_packet_loss_fraction);
125 } 145 }
126 146
(...skipping 11 matching lines...) Expand all
138 return false; 158 return false;
139 159
140 auto shorter_frame_length_ms = std::prev(frame_length_ms_); 160 auto shorter_frame_length_ms = std::prev(frame_length_ms_);
141 auto decrease_threshold = config_.fl_changing_bandwidths_bps.find( 161 auto decrease_threshold = config_.fl_changing_bandwidths_bps.find(
142 Config::FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms)); 162 Config::FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms));
143 163
144 if (decrease_threshold == config_.fl_changing_bandwidths_bps.end()) 164 if (decrease_threshold == config_.fl_changing_bandwidths_bps.end())
145 return false; 165 return false;
146 166
147 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ && 167 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
148 *uplink_bandwidth_bps_ <= config_.min_encoder_bitrate_bps + 168 *uplink_bandwidth_bps_ <=
149 kPreventOveruseMarginBps + 169 config_.min_encoder_bitrate_bps + kPreventOveruseMarginBps +
150 OverheadRateBps(*overhead_bytes_per_packet_, 170 OverheadRateBps(*overhead_bytes_per_packet_ +
151 *shorter_frame_length_ms)) { 171 config_.fl_decrease_overhead_offset,
172 *shorter_frame_length_ms)) {
152 return false; 173 return false;
153 } 174 }
154 175
155 return (uplink_bandwidth_bps_ && 176 return (uplink_bandwidth_bps_ &&
156 *uplink_bandwidth_bps_ >= decrease_threshold->second) || 177 *uplink_bandwidth_bps_ >= decrease_threshold->second) ||
157 (uplink_packet_loss_fraction_ && 178 (uplink_packet_loss_fraction_ &&
158 *uplink_packet_loss_fraction_ >= 179 *uplink_packet_loss_fraction_ >=
159 config_.fl_decreasing_packet_loss_fraction); 180 config_.fl_decreasing_packet_loss_fraction);
160 } 181 }
161 182
162 } // namespace webrtc 183 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698