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

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

Issue 2703353002: Change frame length on very low bandwidth. (Closed)
Patch Set: Responsd to comments. Created 3 years, 10 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/frame_length_control ler.h" 11 #include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_control ler.h"
12 12
13 #include <utility> 13 #include <utility>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 namespace {
21 constexpr int kPreventOveruseMarginBps = 5000;
22
23 int OverheadRateBps(size_t overhead_bytes_per_packet, int frame_length_ms) {
24 return static_cast<int>(overhead_bytes_per_packet * 8 * 1000 /
25 frame_length_ms);
26 }
27 }
28
20 FrameLengthController::Config::Config( 29 FrameLengthController::Config::Config(
21 const std::vector<int>& encoder_frame_lengths_ms, 30 const std::vector<int>& encoder_frame_lengths_ms,
22 int initial_frame_length_ms, 31 int initial_frame_length_ms,
32 int min_encoder_bitrate_bps,
23 float fl_increasing_packet_loss_fraction, 33 float fl_increasing_packet_loss_fraction,
24 float fl_decreasing_packet_loss_fraction, 34 float fl_decreasing_packet_loss_fraction,
25 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps) 35 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps)
26 : encoder_frame_lengths_ms(encoder_frame_lengths_ms), 36 : encoder_frame_lengths_ms(encoder_frame_lengths_ms),
27 initial_frame_length_ms(initial_frame_length_ms), 37 initial_frame_length_ms(initial_frame_length_ms),
38 min_encoder_bitrate_bps(min_encoder_bitrate_bps),
28 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction), 39 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction),
29 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction), 40 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction),
30 fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {} 41 fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {}
31 42
32 FrameLengthController::Config::Config(const Config& other) = default; 43 FrameLengthController::Config::Config(const Config& other) = default;
33 44
34 FrameLengthController::Config::~Config() = default; 45 FrameLengthController::Config::~Config() = default;
35 46
36 FrameLengthController::FrameLengthController(const Config& config) 47 FrameLengthController::FrameLengthController(const Config& config)
37 : config_(config) { 48 : config_(config) {
38 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(), 49 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(),
39 config_.encoder_frame_lengths_ms.end(), 50 config_.encoder_frame_lengths_ms.end(),
40 config_.initial_frame_length_ms); 51 config_.initial_frame_length_ms);
41 // |encoder_frame_lengths_ms| must contain |initial_frame_length_ms|. 52 // |encoder_frame_lengths_ms| must contain |initial_frame_length_ms|.
42 RTC_DCHECK(frame_length_ms_ != config_.encoder_frame_lengths_ms.end()); 53 RTC_DCHECK(frame_length_ms_ != config_.encoder_frame_lengths_ms.end());
43 } 54 }
44 55
45 FrameLengthController::~FrameLengthController() = default; 56 FrameLengthController::~FrameLengthController() = default;
46 57
47 void FrameLengthController::UpdateNetworkMetrics( 58 void FrameLengthController::UpdateNetworkMetrics(
48 const NetworkMetrics& network_metrics) { 59 const NetworkMetrics& network_metrics) {
49 if (network_metrics.uplink_bandwidth_bps) 60 if (network_metrics.uplink_bandwidth_bps)
50 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps; 61 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
51 if (network_metrics.uplink_packet_loss_fraction) 62 if (network_metrics.uplink_packet_loss_fraction)
52 uplink_packet_loss_fraction_ = network_metrics.uplink_packet_loss_fraction; 63 uplink_packet_loss_fraction_ = network_metrics.uplink_packet_loss_fraction;
64 if (network_metrics.overhead_bytes_per_packet)
65 overhead_bytes_per_packet_ = network_metrics.overhead_bytes_per_packet;
53 } 66 }
54 67
55 void FrameLengthController::MakeDecision( 68 void FrameLengthController::MakeDecision(
56 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { 69 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
57 // Decision on |frame_length_ms| should not have been made. 70 // Decision on |frame_length_ms| should not have been made.
58 RTC_DCHECK(!config->frame_length_ms); 71 RTC_DCHECK(!config->frame_length_ms);
59 72
60 if (FrameLengthIncreasingDecision(*config)) { 73 if (FrameLengthIncreasingDecision(*config)) {
61 ++frame_length_ms_; 74 ++frame_length_ms_;
62 } else if (FrameLengthDecreasingDecision(*config)) { 75 } else if (FrameLengthDecreasingDecision(*config)) {
(...skipping 11 matching lines...) Expand all
74 bool FrameLengthController::Config::FrameLengthChange::operator<( 87 bool FrameLengthController::Config::FrameLengthChange::operator<(
75 const FrameLengthChange& rhs) const { 88 const FrameLengthChange& rhs) const {
76 return from_frame_length_ms < rhs.from_frame_length_ms || 89 return from_frame_length_ms < rhs.from_frame_length_ms ||
77 (from_frame_length_ms == rhs.from_frame_length_ms && 90 (from_frame_length_ms == rhs.from_frame_length_ms &&
78 to_frame_length_ms < rhs.to_frame_length_ms); 91 to_frame_length_ms < rhs.to_frame_length_ms);
79 } 92 }
80 93
81 bool FrameLengthController::FrameLengthIncreasingDecision( 94 bool FrameLengthController::FrameLengthIncreasingDecision(
82 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const { 95 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
83 // Increase frame length if 96 // Increase frame length if
84 // 1. longer frame length is available AND 97 // 1. |uplink_bandwidth_bps| is known to be smaller or equal than
85 // 2. |uplink_bandwidth_bps| is known to be smaller than a threshold AND 98 // |min_encoder_bitrate_bps| plus |prevent_overuse_margin_bps| plus the
86 // 3. |uplink_packet_loss_fraction| is known to be smaller than a threshold 99 // current overhead rate OR all the following:
100 // 2. longer frame length is available AND
101 // 3. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
102 // 4. |uplink_packet_loss_fraction| is known to be smaller than a threshold
87 // AND 103 // AND
88 // 4. FEC is not decided or is OFF. 104 // 5. FEC is not decided or is OFF.
105
89 auto longer_frame_length_ms = std::next(frame_length_ms_); 106 auto longer_frame_length_ms = std::next(frame_length_ms_);
90 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end()) 107 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end())
91 return false; 108 return false;
92 109
93 auto increase_threshold = config_.fl_changing_bandwidths_bps.find( 110 auto increase_threshold = config_.fl_changing_bandwidths_bps.find(
94 Config::FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms)); 111 Config::FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms));
95 112
96 if (increase_threshold == config_.fl_changing_bandwidths_bps.end()) 113 if (increase_threshold == config_.fl_changing_bandwidths_bps.end())
97 return false; 114 return false;
98 115
116 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
117 *uplink_bandwidth_bps_ <=
118 config_.min_encoder_bitrate_bps + kPreventOveruseMarginBps +
119 OverheadRateBps(*overhead_bytes_per_packet_, *frame_length_ms_)) {
120 return true;
121 }
122
99 return (uplink_bandwidth_bps_ && 123 return (uplink_bandwidth_bps_ &&
100 *uplink_bandwidth_bps_ <= increase_threshold->second) && 124 *uplink_bandwidth_bps_ <= increase_threshold->second) &&
101 (uplink_packet_loss_fraction_ && 125 (uplink_packet_loss_fraction_ &&
102 *uplink_packet_loss_fraction_ <= 126 *uplink_packet_loss_fraction_ <=
103 config_.fl_increasing_packet_loss_fraction) && 127 config_.fl_increasing_packet_loss_fraction) &&
104 !config.enable_fec.value_or(false); 128 !config.enable_fec.value_or(false);
105 } 129 }
106 130
107 bool FrameLengthController::FrameLengthDecreasingDecision( 131 bool FrameLengthController::FrameLengthDecreasingDecision(
108 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const { 132 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
109 // Decrease frame length if 133 // Decrease frame length if
110 // 1. shorter frame length is available AND one or more of the followings: 134 // 1. shorter frame length is available AND
111 // 2. |uplink_bandwidth_bps| is known to be larger than a threshold, 135 // 2. |uplink_bandwidth_bps| is known to be bigger than
112 // 3. |uplink_packet_loss_fraction| is known to be larger than a threshold, 136 // |min_encoder_bitrate_bps| plus |prevent_overuse_margin_bps| plus the
113 // 4. FEC is decided ON. 137 // overhead which would be produced with the shorter frame length AND
138 // one or more of the followings:
139 // 3. |uplink_bandwidth_bps| is known to be larger than a threshold,
140 // 4. |uplink_packet_loss_fraction| is known to be larger than a threshold,
141 // 5. FEC is decided ON.
114 if (frame_length_ms_ == config_.encoder_frame_lengths_ms.begin()) 142 if (frame_length_ms_ == config_.encoder_frame_lengths_ms.begin())
115 return false; 143 return false;
116 144
117 auto shorter_frame_length_ms = std::prev(frame_length_ms_); 145 auto shorter_frame_length_ms = std::prev(frame_length_ms_);
118 auto decrease_threshold = config_.fl_changing_bandwidths_bps.find( 146 auto decrease_threshold = config_.fl_changing_bandwidths_bps.find(
119 Config::FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms)); 147 Config::FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms));
120 148
121 if (decrease_threshold == config_.fl_changing_bandwidths_bps.end()) 149 if (decrease_threshold == config_.fl_changing_bandwidths_bps.end())
122 return false; 150 return false;
123 151
152 if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
153 *uplink_bandwidth_bps_ <= config_.min_encoder_bitrate_bps +
154 kPreventOveruseMarginBps +
155 OverheadRateBps(*overhead_bytes_per_packet_,
156 *shorter_frame_length_ms)) {
157 return false;
158 }
159
124 return (uplink_bandwidth_bps_ && 160 return (uplink_bandwidth_bps_ &&
125 *uplink_bandwidth_bps_ >= decrease_threshold->second) || 161 *uplink_bandwidth_bps_ >= decrease_threshold->second) ||
126 (uplink_packet_loss_fraction_ && 162 (uplink_packet_loss_fraction_ &&
127 *uplink_packet_loss_fraction_ >= 163 *uplink_packet_loss_fraction_ >=
128 config_.fl_decreasing_packet_loss_fraction) || 164 config_.fl_decreasing_packet_loss_fraction) ||
129 config.enable_fec.value_or(false); 165 config.enable_fec.value_or(false);
130 } 166 }
131 167
132 } // namespace webrtc 168 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698