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

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

Issue 2669733002: Add 120ms frame ability to ANA (Closed)
Patch Set: Respond 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 FrameLengthController::Config::Config( 20 FrameLengthController::Config::Config(
21 const std::vector<int>& encoder_frame_lengths_ms, 21 const std::vector<int>& encoder_frame_lengths_ms,
22 int initial_frame_length_ms, 22 int initial_frame_length_ms,
23 float fl_increasing_packet_loss_fraction, 23 float fl_increasing_packet_loss_fraction,
24 float fl_decreasing_packet_loss_fraction, 24 float fl_decreasing_packet_loss_fraction,
25 int fl_20ms_to_60ms_bandwidth_bps, 25 std::map<FrameLengthChange, int> fl_changing_bandwidths_bps)
26 int fl_60ms_to_20ms_bandwidth_bps)
27 : encoder_frame_lengths_ms(encoder_frame_lengths_ms), 26 : encoder_frame_lengths_ms(encoder_frame_lengths_ms),
28 initial_frame_length_ms(initial_frame_length_ms), 27 initial_frame_length_ms(initial_frame_length_ms),
29 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction), 28 fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction),
30 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction), 29 fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction),
31 fl_20ms_to_60ms_bandwidth_bps(fl_20ms_to_60ms_bandwidth_bps), 30 fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {}
32 fl_60ms_to_20ms_bandwidth_bps(fl_60ms_to_20ms_bandwidth_bps) {}
33 31
34 FrameLengthController::Config::Config(const Config& other) = default; 32 FrameLengthController::Config::Config(const Config& other) = default;
35 33
36 FrameLengthController::Config::~Config() = default; 34 FrameLengthController::Config::~Config() = default;
37 35
38 FrameLengthController::FrameLengthController(const Config& config) 36 FrameLengthController::FrameLengthController(const Config& config)
39 : config_(config) { 37 : config_(config) {
40 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(), 38 frame_length_ms_ = std::find(config_.encoder_frame_lengths_ms.begin(),
41 config_.encoder_frame_lengths_ms.end(), 39 config_.encoder_frame_lengths_ms.end(),
42 config_.initial_frame_length_ms); 40 config_.initial_frame_length_ms);
43 // |encoder_frame_lengths_ms| must contain |initial_frame_length_ms|. 41 // |encoder_frame_lengths_ms| must contain |initial_frame_length_ms|.
44 RTC_DCHECK(frame_length_ms_ != config_.encoder_frame_lengths_ms.end()); 42 RTC_DCHECK(frame_length_ms_ != config_.encoder_frame_lengths_ms.end());
45
46 frame_length_change_criteria_.insert(std::make_pair(
47 FrameLengthChange(20, 60), config_.fl_20ms_to_60ms_bandwidth_bps));
48 frame_length_change_criteria_.insert(std::make_pair(
49 FrameLengthChange(60, 20), config_.fl_60ms_to_20ms_bandwidth_bps));
50 } 43 }
51 44
52 FrameLengthController::~FrameLengthController() = default; 45 FrameLengthController::~FrameLengthController() = default;
53 46
54 void FrameLengthController::UpdateNetworkMetrics( 47 void FrameLengthController::UpdateNetworkMetrics(
55 const NetworkMetrics& network_metrics) { 48 const NetworkMetrics& network_metrics) {
56 if (network_metrics.uplink_bandwidth_bps) 49 if (network_metrics.uplink_bandwidth_bps)
57 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps; 50 uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
58 if (network_metrics.uplink_packet_loss_fraction) 51 if (network_metrics.uplink_packet_loss_fraction)
59 uplink_packet_loss_fraction_ = network_metrics.uplink_packet_loss_fraction; 52 uplink_packet_loss_fraction_ = network_metrics.uplink_packet_loss_fraction;
60 } 53 }
61 54
62 void FrameLengthController::MakeDecision( 55 void FrameLengthController::MakeDecision(
63 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { 56 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
64 // Decision on |frame_length_ms| should not have been made. 57 // Decision on |frame_length_ms| should not have been made.
65 RTC_DCHECK(!config->frame_length_ms); 58 RTC_DCHECK(!config->frame_length_ms);
66 59
67 if (FrameLengthIncreasingDecision(*config)) { 60 if (FrameLengthIncreasingDecision(*config)) {
68 ++frame_length_ms_; 61 ++frame_length_ms_;
69 } else if (FrameLengthDecreasingDecision(*config)) { 62 } else if (FrameLengthDecreasingDecision(*config)) {
70 --frame_length_ms_; 63 --frame_length_ms_;
71 } 64 }
72 config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_); 65 config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_);
73 } 66 }
74 67
75 FrameLengthController::FrameLengthChange::FrameLengthChange( 68 FrameLengthController::Config::FrameLengthChange::FrameLengthChange(
76 int from_frame_length_ms, 69 int from_frame_length_ms,
77 int to_frame_length_ms) 70 int to_frame_length_ms)
78 : from_frame_length_ms(from_frame_length_ms), 71 : from_frame_length_ms(from_frame_length_ms),
79 to_frame_length_ms(to_frame_length_ms) {} 72 to_frame_length_ms(to_frame_length_ms) {}
80 73
81 FrameLengthController::FrameLengthChange::~FrameLengthChange() = default; 74 bool FrameLengthController::Config::FrameLengthChange::operator<(
82
83 bool FrameLengthController::FrameLengthChange::operator<(
84 const FrameLengthChange& rhs) const { 75 const FrameLengthChange& rhs) const {
85 return from_frame_length_ms < rhs.from_frame_length_ms || 76 return from_frame_length_ms < rhs.from_frame_length_ms ||
86 (from_frame_length_ms == rhs.from_frame_length_ms && 77 (from_frame_length_ms == rhs.from_frame_length_ms &&
87 to_frame_length_ms < rhs.to_frame_length_ms); 78 to_frame_length_ms < rhs.to_frame_length_ms);
88 } 79 }
89 80
90 bool FrameLengthController::FrameLengthIncreasingDecision( 81 bool FrameLengthController::FrameLengthIncreasingDecision(
91 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const { 82 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
92 // Increase frame length if 83 // Increase frame length if
93 // 1. longer frame length is available AND 84 // 1. longer frame length is available AND
94 // 2. |uplink_bandwidth_bps| is known to be smaller than a threshold AND 85 // 2. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
95 // 3. |uplink_packet_loss_fraction| is known to be smaller than a threshold 86 // 3. |uplink_packet_loss_fraction| is known to be smaller than a threshold
96 // AND 87 // AND
97 // 4. FEC is not decided or is OFF. 88 // 4. FEC is not decided or is OFF.
98 auto longer_frame_length_ms = std::next(frame_length_ms_); 89 auto longer_frame_length_ms = std::next(frame_length_ms_);
99 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end()) 90 if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end())
100 return false; 91 return false;
101 92
102 auto increase_threshold = frame_length_change_criteria_.find( 93 auto increase_threshold = config_.fl_changing_bandwidths_bps.find(
103 FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms)); 94 Config::FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms));
104 95
105 if (increase_threshold == frame_length_change_criteria_.end()) 96 if (increase_threshold == config_.fl_changing_bandwidths_bps.end())
106 return false; 97 return false;
107 98
108 return (uplink_bandwidth_bps_ && 99 return (uplink_bandwidth_bps_ &&
109 *uplink_bandwidth_bps_ <= increase_threshold->second) && 100 *uplink_bandwidth_bps_ <= increase_threshold->second) &&
110 (uplink_packet_loss_fraction_ && 101 (uplink_packet_loss_fraction_ &&
111 *uplink_packet_loss_fraction_ <= 102 *uplink_packet_loss_fraction_ <=
112 config_.fl_increasing_packet_loss_fraction) && 103 config_.fl_increasing_packet_loss_fraction) &&
113 !config.enable_fec.value_or(false); 104 !config.enable_fec.value_or(false);
114 } 105 }
115 106
116 bool FrameLengthController::FrameLengthDecreasingDecision( 107 bool FrameLengthController::FrameLengthDecreasingDecision(
117 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const { 108 const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
118 // Decrease frame length if 109 // Decrease frame length if
119 // 1. shorter frame length is available AND one or more of the followings: 110 // 1. shorter frame length is available AND one or more of the followings:
120 // 2. |uplink_bandwidth_bps| is known to be larger than a threshold, 111 // 2. |uplink_bandwidth_bps| is known to be larger than a threshold,
121 // 3. |uplink_packet_loss_fraction| is known to be larger than a threshold, 112 // 3. |uplink_packet_loss_fraction| is known to be larger than a threshold,
122 // 4. FEC is decided ON. 113 // 4. FEC is decided ON.
123 if (frame_length_ms_ == config_.encoder_frame_lengths_ms.begin()) 114 if (frame_length_ms_ == config_.encoder_frame_lengths_ms.begin())
124 return false; 115 return false;
125 116
126 auto shorter_frame_length_ms = std::prev(frame_length_ms_); 117 auto shorter_frame_length_ms = std::prev(frame_length_ms_);
127 auto decrease_threshold = frame_length_change_criteria_.find( 118 auto decrease_threshold = config_.fl_changing_bandwidths_bps.find(
128 FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms)); 119 Config::FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms));
129 120
130 if (decrease_threshold == frame_length_change_criteria_.end()) 121 if (decrease_threshold == config_.fl_changing_bandwidths_bps.end())
131 return false; 122 return false;
132 123
133 return (uplink_bandwidth_bps_ && 124 return (uplink_bandwidth_bps_ &&
134 *uplink_bandwidth_bps_ >= decrease_threshold->second) || 125 *uplink_bandwidth_bps_ >= decrease_threshold->second) ||
135 (uplink_packet_loss_fraction_ && 126 (uplink_packet_loss_fraction_ &&
136 *uplink_packet_loss_fraction_ >= 127 *uplink_packet_loss_fraction_ >=
137 config_.fl_decreasing_packet_loss_fraction) || 128 config_.fl_decreasing_packet_loss_fraction) ||
138 config.enable_fec.value_or(false); 129 config.enable_fec.value_or(false);
139 } 130 }
140 131
141 } // namespace webrtc 132 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698