| Index: webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.cc
|
| diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.cc b/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.cc
|
| index d684e956a8a95c6ea36cfe61ede19022993f09da..580d08087b3e57d3ba3739d1ac31e4a50061ebd5 100644
|
| --- a/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.cc
|
| +++ b/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.cc
|
| @@ -17,14 +17,25 @@
|
|
|
| namespace webrtc {
|
|
|
| +namespace {
|
| +constexpr int kPreventOveruseMarginBps = 5000;
|
| +
|
| +int OverheadRateBps(size_t overhead_bytes_per_packet, int frame_length_ms) {
|
| + return static_cast<int>(overhead_bytes_per_packet * 8 * 1000 /
|
| + frame_length_ms);
|
| +}
|
| +}
|
| +
|
| FrameLengthController::Config::Config(
|
| const std::vector<int>& encoder_frame_lengths_ms,
|
| int initial_frame_length_ms,
|
| + int min_encoder_bitrate_bps,
|
| float fl_increasing_packet_loss_fraction,
|
| float fl_decreasing_packet_loss_fraction,
|
| std::map<FrameLengthChange, int> fl_changing_bandwidths_bps)
|
| : encoder_frame_lengths_ms(encoder_frame_lengths_ms),
|
| initial_frame_length_ms(initial_frame_length_ms),
|
| + min_encoder_bitrate_bps(min_encoder_bitrate_bps),
|
| fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction),
|
| fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction),
|
| fl_changing_bandwidths_bps(std::move(fl_changing_bandwidths_bps)) {}
|
| @@ -50,6 +61,8 @@ void FrameLengthController::UpdateNetworkMetrics(
|
| uplink_bandwidth_bps_ = network_metrics.uplink_bandwidth_bps;
|
| if (network_metrics.uplink_packet_loss_fraction)
|
| uplink_packet_loss_fraction_ = network_metrics.uplink_packet_loss_fraction;
|
| + if (network_metrics.overhead_bytes_per_packet)
|
| + overhead_bytes_per_packet_ = network_metrics.overhead_bytes_per_packet;
|
| }
|
|
|
| void FrameLengthController::MakeDecision(
|
| @@ -81,11 +94,15 @@ bool FrameLengthController::Config::FrameLengthChange::operator<(
|
| bool FrameLengthController::FrameLengthIncreasingDecision(
|
| const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
|
| // Increase frame length if
|
| - // 1. longer frame length is available AND
|
| - // 2. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
|
| - // 3. |uplink_packet_loss_fraction| is known to be smaller than a threshold
|
| + // 1. |uplink_bandwidth_bps| is known to be smaller or equal than
|
| + // |min_encoder_bitrate_bps| plus |prevent_overuse_margin_bps| plus the
|
| + // current overhead rate OR all the following:
|
| + // 2. longer frame length is available AND
|
| + // 3. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
|
| + // 4. |uplink_packet_loss_fraction| is known to be smaller than a threshold
|
| // AND
|
| - // 4. FEC is not decided or is OFF.
|
| + // 5. FEC is not decided or is OFF.
|
| +
|
| auto longer_frame_length_ms = std::next(frame_length_ms_);
|
| if (longer_frame_length_ms == config_.encoder_frame_lengths_ms.end())
|
| return false;
|
| @@ -96,6 +113,13 @@ bool FrameLengthController::FrameLengthIncreasingDecision(
|
| if (increase_threshold == config_.fl_changing_bandwidths_bps.end())
|
| return false;
|
|
|
| + if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
|
| + *uplink_bandwidth_bps_ <=
|
| + config_.min_encoder_bitrate_bps + kPreventOveruseMarginBps +
|
| + OverheadRateBps(*overhead_bytes_per_packet_, *frame_length_ms_)) {
|
| + return true;
|
| + }
|
| +
|
| return (uplink_bandwidth_bps_ &&
|
| *uplink_bandwidth_bps_ <= increase_threshold->second) &&
|
| (uplink_packet_loss_fraction_ &&
|
| @@ -107,10 +131,14 @@ bool FrameLengthController::FrameLengthIncreasingDecision(
|
| bool FrameLengthController::FrameLengthDecreasingDecision(
|
| const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const {
|
| // Decrease frame length if
|
| - // 1. shorter frame length is available AND one or more of the followings:
|
| - // 2. |uplink_bandwidth_bps| is known to be larger than a threshold,
|
| - // 3. |uplink_packet_loss_fraction| is known to be larger than a threshold,
|
| - // 4. FEC is decided ON.
|
| + // 1. shorter frame length is available AND
|
| + // 2. |uplink_bandwidth_bps| is known to be bigger than
|
| + // |min_encoder_bitrate_bps| plus |prevent_overuse_margin_bps| plus the
|
| + // overhead which would be produced with the shorter frame length AND
|
| + // one or more of the followings:
|
| + // 3. |uplink_bandwidth_bps| is known to be larger than a threshold,
|
| + // 4. |uplink_packet_loss_fraction| is known to be larger than a threshold,
|
| + // 5. FEC is decided ON.
|
| if (frame_length_ms_ == config_.encoder_frame_lengths_ms.begin())
|
| return false;
|
|
|
| @@ -121,6 +149,14 @@ bool FrameLengthController::FrameLengthDecreasingDecision(
|
| if (decrease_threshold == config_.fl_changing_bandwidths_bps.end())
|
| return false;
|
|
|
| + if (uplink_bandwidth_bps_ && overhead_bytes_per_packet_ &&
|
| + *uplink_bandwidth_bps_ <= config_.min_encoder_bitrate_bps +
|
| + kPreventOveruseMarginBps +
|
| + OverheadRateBps(*overhead_bytes_per_packet_,
|
| + *shorter_frame_length_ms)) {
|
| + return false;
|
| + }
|
| +
|
| return (uplink_bandwidth_bps_ &&
|
| *uplink_bandwidth_bps_ >= decrease_threshold->second) ||
|
| (uplink_packet_loss_fraction_ &&
|
|
|