Adding FrameLengthController to audio network adaptor.
BUG=webrtc:6303 Review-Url: https://codereview.webrtc.org/2335163002 Cr-Commit-Position: refs/heads/master@{#14339}
This commit is contained in:
@ -709,6 +709,8 @@ source_set("audio_network_adaptor") {
|
||||
"audio_network_adaptor/controller_manager.h",
|
||||
"audio_network_adaptor/dtx_controller.cc",
|
||||
"audio_network_adaptor/dtx_controller.h",
|
||||
"audio_network_adaptor/frame_length_controller.cc",
|
||||
"audio_network_adaptor/frame_length_controller.h",
|
||||
"audio_network_adaptor/include/audio_network_adaptor.h",
|
||||
"audio_network_adaptor/smoothing_filter.cc",
|
||||
"audio_network_adaptor/smoothing_filter.h",
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
'controller_manager.h',
|
||||
'dtx_controller.h',
|
||||
'dtx_controller.cc',
|
||||
'frame_length_controller.cc',
|
||||
'frame_length_controller.h',
|
||||
'include/audio_network_adaptor.h',
|
||||
'smoothing_filter.h',
|
||||
'smoothing_filter.cc',
|
||||
|
||||
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
FrameLengthController::Config::Config(
|
||||
const std::vector<int>& encoder_frame_lengths_ms,
|
||||
int initial_frame_length_ms,
|
||||
float fl_increasing_packet_loss_fraction,
|
||||
float fl_decreasing_packet_loss_fraction,
|
||||
int fl_20ms_to_60ms_bandwidth_bps,
|
||||
int fl_60ms_to_20ms_bandwidth_bps)
|
||||
: encoder_frame_lengths_ms(encoder_frame_lengths_ms),
|
||||
initial_frame_length_ms(initial_frame_length_ms),
|
||||
fl_increasing_packet_loss_fraction(fl_increasing_packet_loss_fraction),
|
||||
fl_decreasing_packet_loss_fraction(fl_decreasing_packet_loss_fraction),
|
||||
fl_20ms_to_60ms_bandwidth_bps(fl_20ms_to_60ms_bandwidth_bps),
|
||||
fl_60ms_to_20ms_bandwidth_bps(fl_60ms_to_20ms_bandwidth_bps) {}
|
||||
|
||||
FrameLengthController::Config::Config(const Config& other) = default;
|
||||
|
||||
FrameLengthController::Config::~Config() = default;
|
||||
|
||||
FrameLengthController::FrameLengthController(const Config& config)
|
||||
: config_(config) {
|
||||
// |encoder_frame_lengths_ms| must contain |initial_frame_length_ms|.
|
||||
RTC_DCHECK(config_.encoder_frame_lengths_ms.end() !=
|
||||
std::find(config_.encoder_frame_lengths_ms.begin(),
|
||||
config_.encoder_frame_lengths_ms.end(),
|
||||
config_.initial_frame_length_ms));
|
||||
|
||||
// We start with assuming that the receiver only accepts
|
||||
// |config_.initial_frame_length_ms|.
|
||||
run_time_frame_lengths_ms_.push_back(config_.initial_frame_length_ms);
|
||||
frame_length_ms_ = run_time_frame_lengths_ms_.begin();
|
||||
|
||||
frame_length_change_criteria_.insert(std::make_pair(
|
||||
FrameLengthChange(20, 60), config_.fl_20ms_to_60ms_bandwidth_bps));
|
||||
frame_length_change_criteria_.insert(std::make_pair(
|
||||
FrameLengthChange(60, 20), config_.fl_60ms_to_20ms_bandwidth_bps));
|
||||
}
|
||||
|
||||
FrameLengthController::~FrameLengthController() = default;
|
||||
|
||||
void FrameLengthController::MakeDecision(
|
||||
const NetworkMetrics& metrics,
|
||||
AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
|
||||
// Decision on |frame_length_ms| should not have been made.
|
||||
RTC_DCHECK(!config->frame_length_ms);
|
||||
|
||||
if (FrameLengthIncreasingDecision(metrics, *config)) {
|
||||
++frame_length_ms_;
|
||||
} else if (FrameLengthDecreasingDecision(metrics, *config)) {
|
||||
--frame_length_ms_;
|
||||
}
|
||||
config->frame_length_ms = rtc::Optional<int>(*frame_length_ms_);
|
||||
}
|
||||
|
||||
void FrameLengthController::SetConstraints(const Constraints& constraints) {
|
||||
if (constraints.receiver_frame_length_range) {
|
||||
SetReceiverFrameLengthRange(
|
||||
constraints.receiver_frame_length_range->min_frame_length_ms,
|
||||
constraints.receiver_frame_length_range->max_frame_length_ms);
|
||||
}
|
||||
}
|
||||
|
||||
FrameLengthController::FrameLengthChange::FrameLengthChange(
|
||||
int from_frame_length_ms,
|
||||
int to_frame_length_ms)
|
||||
: from_frame_length_ms(from_frame_length_ms),
|
||||
to_frame_length_ms(to_frame_length_ms) {}
|
||||
|
||||
FrameLengthController::FrameLengthChange::~FrameLengthChange() = default;
|
||||
|
||||
bool FrameLengthController::FrameLengthChange::operator<(
|
||||
const FrameLengthChange& rhs) const {
|
||||
return from_frame_length_ms < rhs.from_frame_length_ms ||
|
||||
(from_frame_length_ms == rhs.from_frame_length_ms &&
|
||||
to_frame_length_ms < rhs.to_frame_length_ms);
|
||||
}
|
||||
|
||||
void FrameLengthController::SetReceiverFrameLengthRange(
|
||||
int min_frame_length_ms,
|
||||
int max_frame_length_ms) {
|
||||
int frame_length_ms = *frame_length_ms_;
|
||||
// Reset |run_time_frame_lengths_ms_| by filtering |config_.frame_lengths_ms|
|
||||
// with the receiver frame length range.
|
||||
run_time_frame_lengths_ms_.clear();
|
||||
std::copy_if(config_.encoder_frame_lengths_ms.begin(),
|
||||
config_.encoder_frame_lengths_ms.end(),
|
||||
std::back_inserter(run_time_frame_lengths_ms_),
|
||||
[&](int frame_length_ms) {
|
||||
return frame_length_ms >= min_frame_length_ms &&
|
||||
frame_length_ms <= max_frame_length_ms;
|
||||
});
|
||||
RTC_DCHECK(std::is_sorted(run_time_frame_lengths_ms_.begin(),
|
||||
run_time_frame_lengths_ms_.end()));
|
||||
|
||||
// Keep the current frame length. If it has gone out of the new range, use
|
||||
// the smallest available frame length.
|
||||
frame_length_ms_ =
|
||||
std::find(run_time_frame_lengths_ms_.begin(),
|
||||
run_time_frame_lengths_ms_.end(), frame_length_ms);
|
||||
if (frame_length_ms_ == run_time_frame_lengths_ms_.end()) {
|
||||
LOG(LS_WARNING)
|
||||
<< "Actual frame length not in frame length range of the receiver";
|
||||
frame_length_ms_ = run_time_frame_lengths_ms_.begin();
|
||||
}
|
||||
}
|
||||
|
||||
bool FrameLengthController::FrameLengthIncreasingDecision(
|
||||
const NetworkMetrics& metrics,
|
||||
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
|
||||
// AND
|
||||
// 4. FEC is not decided or is OFF.
|
||||
auto longer_frame_length_ms = std::next(frame_length_ms_);
|
||||
if (longer_frame_length_ms == run_time_frame_lengths_ms_.end())
|
||||
return false;
|
||||
|
||||
auto increase_threshold = frame_length_change_criteria_.find(
|
||||
FrameLengthChange(*frame_length_ms_, *longer_frame_length_ms));
|
||||
|
||||
if (increase_threshold == frame_length_change_criteria_.end())
|
||||
return false;
|
||||
|
||||
return (metrics.uplink_bandwidth_bps &&
|
||||
*metrics.uplink_bandwidth_bps <= increase_threshold->second) &&
|
||||
(metrics.uplink_packet_loss_fraction &&
|
||||
*metrics.uplink_packet_loss_fraction <=
|
||||
config_.fl_increasing_packet_loss_fraction) &&
|
||||
!config.enable_fec.value_or(false);
|
||||
}
|
||||
|
||||
bool FrameLengthController::FrameLengthDecreasingDecision(
|
||||
const NetworkMetrics& metrics,
|
||||
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.
|
||||
if (frame_length_ms_ == run_time_frame_lengths_ms_.begin())
|
||||
return false;
|
||||
|
||||
auto shorter_frame_length_ms = std::prev(frame_length_ms_);
|
||||
auto decrease_threshold = frame_length_change_criteria_.find(
|
||||
FrameLengthChange(*frame_length_ms_, *shorter_frame_length_ms));
|
||||
|
||||
if (decrease_threshold == frame_length_change_criteria_.end())
|
||||
return false;
|
||||
|
||||
return (metrics.uplink_bandwidth_bps &&
|
||||
*metrics.uplink_bandwidth_bps >= decrease_threshold->second) ||
|
||||
(metrics.uplink_packet_loss_fraction &&
|
||||
*metrics.uplink_packet_loss_fraction >=
|
||||
config_.fl_decreasing_packet_loss_fraction) ||
|
||||
config.enable_fec.value_or(false);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FRAME_LENGTH_CONTROLLER_H_
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FRAME_LENGTH_CONTROLLER_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/modules/audio_coding/audio_network_adaptor/controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Determines target frame length based on the network metrics and the decision
|
||||
// of FEC controller.
|
||||
class FrameLengthController final : public Controller {
|
||||
public:
|
||||
struct Config {
|
||||
Config(const std::vector<int>& encoder_frame_lengths_ms,
|
||||
int initial_frame_length_ms,
|
||||
float fl_increasing_packet_loss_fraction,
|
||||
float fl_decreasing_packet_loss_fraction,
|
||||
int fl_20ms_to_60ms_bandwidth_bps,
|
||||
int fl_60ms_to_20ms_bandwidth_bps);
|
||||
Config(const Config& other);
|
||||
~Config();
|
||||
std::vector<int> encoder_frame_lengths_ms;
|
||||
int initial_frame_length_ms;
|
||||
float fl_increasing_packet_loss_fraction;
|
||||
float fl_decreasing_packet_loss_fraction;
|
||||
int fl_20ms_to_60ms_bandwidth_bps;
|
||||
int fl_60ms_to_20ms_bandwidth_bps;
|
||||
};
|
||||
|
||||
explicit FrameLengthController(const Config& config);
|
||||
|
||||
~FrameLengthController() override;
|
||||
|
||||
void MakeDecision(const NetworkMetrics& metrics,
|
||||
AudioNetworkAdaptor::EncoderRuntimeConfig* config) override;
|
||||
|
||||
void SetConstraints(const Constraints& constraints) override;
|
||||
|
||||
private:
|
||||
friend class FrameLengthControllerForTest;
|
||||
|
||||
struct FrameLengthChange {
|
||||
FrameLengthChange(int from_frame_length_ms, int to_frame_length_ms);
|
||||
~FrameLengthChange();
|
||||
bool operator<(const FrameLengthChange& rhs) const;
|
||||
int from_frame_length_ms;
|
||||
int to_frame_length_ms;
|
||||
};
|
||||
|
||||
void SetReceiverFrameLengthRange(int min_frame_length_ms,
|
||||
int max_frame_length_ms);
|
||||
|
||||
bool FrameLengthIncreasingDecision(
|
||||
const NetworkMetrics& metrics,
|
||||
const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const;
|
||||
|
||||
bool FrameLengthDecreasingDecision(
|
||||
const NetworkMetrics& metrics,
|
||||
const AudioNetworkAdaptor::EncoderRuntimeConfig& config) const;
|
||||
|
||||
const Config config_;
|
||||
|
||||
std::vector<int> run_time_frame_lengths_ms_;
|
||||
|
||||
std::vector<int>::iterator frame_length_ms_;
|
||||
|
||||
std::map<FrameLengthChange, int> frame_length_change_criteria_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(FrameLengthController);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_AUDIO_CODING_AUDIO_NETWORK_ADAPTOR_FRAME_LENGTH_CONTROLLER_H_
|
||||
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kFlIncreasingPacketLossFraction = 0.04f;
|
||||
constexpr float kFlDecreasingPacketLossFraction = 0.05f;
|
||||
constexpr int kFl20msTo60msBandwidthBps = 22000;
|
||||
constexpr int kFl60msTo20msBandwidthBps = 88000;
|
||||
constexpr int kMinReceiverFrameLengthMs = 10;
|
||||
constexpr int kMaxReceiverFrameLengthMs = 120;
|
||||
constexpr int kMediumBandwidthBps =
|
||||
(kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2;
|
||||
constexpr float kMediumPacketLossFraction =
|
||||
(kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2;
|
||||
|
||||
void SetReceiverFrameLengthRange(FrameLengthController* controller,
|
||||
int min_frame_length_ms,
|
||||
int max_frame_length_ms) {
|
||||
Controller::Constraints constraints;
|
||||
using FrameLengthRange = Controller::Constraints::FrameLengthRange;
|
||||
constraints.receiver_frame_length_range = rtc::Optional<FrameLengthRange>(
|
||||
FrameLengthRange(min_frame_length_ms, max_frame_length_ms));
|
||||
controller->SetConstraints(constraints);
|
||||
}
|
||||
|
||||
std::unique_ptr<FrameLengthController> CreateController(
|
||||
int initial_frame_length_ms) {
|
||||
std::unique_ptr<FrameLengthController> controller(
|
||||
new FrameLengthController(FrameLengthController::Config(
|
||||
{20, 60}, initial_frame_length_ms, kFlIncreasingPacketLossFraction,
|
||||
kFlDecreasingPacketLossFraction, kFl20msTo60msBandwidthBps,
|
||||
kFl60msTo20msBandwidthBps)));
|
||||
SetReceiverFrameLengthRange(controller.get(), kMinReceiverFrameLengthMs,
|
||||
kMaxReceiverFrameLengthMs);
|
||||
return controller;
|
||||
}
|
||||
|
||||
void CheckDecision(FrameLengthController* controller,
|
||||
const rtc::Optional<int>& uplink_bandwidth_bps,
|
||||
const rtc::Optional<float>& uplink_packet_loss_fraction,
|
||||
const rtc::Optional<bool>& enable_fec,
|
||||
int expected_frame_length_ms) {
|
||||
Controller::NetworkMetrics metrics;
|
||||
metrics.uplink_bandwidth_bps = uplink_bandwidth_bps;
|
||||
metrics.uplink_packet_loss_fraction = uplink_packet_loss_fraction;
|
||||
AudioNetworkAdaptor::EncoderRuntimeConfig config;
|
||||
config.enable_fec = enable_fec;
|
||||
controller->MakeDecision(metrics, &config);
|
||||
EXPECT_EQ(rtc::Optional<int>(expected_frame_length_ms),
|
||||
config.frame_length_ms);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(FrameLengthControllerTest,
|
||||
OutputInitValueWhenReceiverFrameLengthRangeUnset) {
|
||||
constexpr int kInitialFrameLenghtMs = 60;
|
||||
std::unique_ptr<FrameLengthController> controller(
|
||||
new FrameLengthController(FrameLengthController::Config(
|
||||
{20, 60}, kInitialFrameLenghtMs, kFlIncreasingPacketLossFraction,
|
||||
kFlDecreasingPacketLossFraction, kFl20msTo60msBandwidthBps,
|
||||
kFl60msTo20msBandwidthBps)));
|
||||
// Use a high uplink bandwidth that would cause frame length to decrease if
|
||||
// receiver frame length is set.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<bool>(),
|
||||
kInitialFrameLenghtMs);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkBandwidth) {
|
||||
auto controller = CreateController(60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, DecreaseTo20MsOnHighUplinkPacketLossFraction) {
|
||||
auto controller = CreateController(60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, DecreaseTo20MsWhenFecIsOn) {
|
||||
auto controller = CreateController(60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(true), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest,
|
||||
Maintain60MsIf20MsNotInReceiverFrameLengthRange) {
|
||||
auto controller = CreateController(60);
|
||||
SetReceiverFrameLengthRange(controller.get(), 21, 60);
|
||||
// Set FEC on that would cause frame length to decrease if receiver frame
|
||||
// length range included 20ms.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(true), 60);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, Maintain60MsOnMultipleConditions) {
|
||||
// Maintain 60ms frame length if
|
||||
// 1. |uplink_bandwidth_bps| is at medium level,
|
||||
// 2. |uplink_packet_loss_fraction| is at medium,
|
||||
// 3. FEC is not decided ON.
|
||||
auto controller = CreateController(60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, IncreaseTo60MsOnMultipleConditions) {
|
||||
// Increase to 60ms frame length if
|
||||
// 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
|
||||
// 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold
|
||||
// AND
|
||||
// 3. FEC is not decided or OFF.
|
||||
auto controller = CreateController(20);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest,
|
||||
Maintain20MsIf60MsNotInReceiverFrameLengthRange) {
|
||||
auto controller = CreateController(20);
|
||||
SetReceiverFrameLengthRange(controller.get(), 10, 59);
|
||||
// Use a low uplink bandwidth and a low uplink packet loss fraction that would
|
||||
// cause frame length to increase if receiver frame length included 60ms.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkBandwidth) {
|
||||
auto controller = CreateController(20);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, Maintain20MsOnMediumUplinkPacketLossFraction) {
|
||||
auto controller = CreateController(20);
|
||||
// Use a low uplink bandwidth that would cause frame length to increase if
|
||||
// uplink packet loss fraction was low.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, Maintain20MsWhenFecIsOn) {
|
||||
auto controller = CreateController(20);
|
||||
// Use a low uplink bandwidth and a low uplink packet loss fraction that would
|
||||
// cause frame length to increase if FEC was not ON.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(true), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest,
|
||||
MaintainFrameLengthOnSetReceiverFrameLengthRange) {
|
||||
auto controller = CreateController(60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(true), 20);
|
||||
SetReceiverFrameLengthRange(controller.get(), 10, 60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr int kFl60msTo120msBandwidthBps = 18000;
|
||||
constexpr int kFl120msTo60msBandwidthBps = 72000;
|
||||
}
|
||||
|
||||
class FrameLengthControllerForTest {
|
||||
public:
|
||||
// This class is to test multiple frame lengths. FrameLengthController is
|
||||
// implemented to support this, but is not enabled for the default constructor
|
||||
// for the time being. We use this class to test it.
|
||||
explicit FrameLengthControllerForTest(int initial_frame_length_ms)
|
||||
: frame_length_controller_(
|
||||
FrameLengthController::Config({20, 60, 120},
|
||||
initial_frame_length_ms,
|
||||
kFlIncreasingPacketLossFraction,
|
||||
kFlDecreasingPacketLossFraction,
|
||||
kFl20msTo60msBandwidthBps,
|
||||
kFl60msTo20msBandwidthBps)) {
|
||||
frame_length_controller_.frame_length_change_criteria_.insert(
|
||||
std::make_pair(FrameLengthController::FrameLengthChange(60, 120),
|
||||
kFl60msTo120msBandwidthBps));
|
||||
frame_length_controller_.frame_length_change_criteria_.insert(
|
||||
std::make_pair(FrameLengthController::FrameLengthChange(120, 60),
|
||||
kFl120msTo60msBandwidthBps));
|
||||
frame_length_controller_.SetReceiverFrameLengthRange(20, 120);
|
||||
}
|
||||
FrameLengthController* get() { return &frame_length_controller_; }
|
||||
|
||||
private:
|
||||
FrameLengthController frame_length_controller_;
|
||||
};
|
||||
|
||||
TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkBandwidth) {
|
||||
FrameLengthControllerForTest controller(120);
|
||||
// It takes two steps for frame length to go from 120ms to 20ms.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl60msTo20msBandwidthBps),
|
||||
rtc::Optional<float>(), rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, From120MsTo20MsOnHighUplinkPacketLossFraction) {
|
||||
FrameLengthControllerForTest controller(120);
|
||||
// It takes two steps for frame length to go from 120ms to 20ms.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, From120MsTo20MsWhenFecIsOn) {
|
||||
FrameLengthControllerForTest controller(120);
|
||||
// It takes two steps for frame length to go from 120ms to 20ms.
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(true), 60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(), rtc::Optional<float>(),
|
||||
rtc::Optional<bool>(true), 20);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, From20MsTo120MsOnMultipleConditions) {
|
||||
// Increase to 120ms frame length if
|
||||
// 1. |uplink_bandwidth_bps| is known to be smaller than a threshold AND
|
||||
// 2. |uplink_packet_loss_fraction| is known to be smaller than a threshold
|
||||
// AND
|
||||
// 3. FEC is not decided or OFF.
|
||||
FrameLengthControllerForTest controller(20);
|
||||
// It takes two steps for frame length to go from 20ms to 120ms.
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 120);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, Stall60MsIf120MsNotInReceiverFrameLengthRange) {
|
||||
FrameLengthControllerForTest controller(20);
|
||||
SetReceiverFrameLengthRange(controller.get(), 20, 119);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
}
|
||||
|
||||
TEST(FrameLengthControllerTest, CheckBehaviorOnChangingNetworkMetrics) {
|
||||
FrameLengthControllerForTest controller(20);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kFl20msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kMediumPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl60msTo120msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 120);
|
||||
CheckDecision(controller.get(),
|
||||
rtc::Optional<int>(kFl120msTo60msBandwidthBps),
|
||||
rtc::Optional<float>(kFlIncreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 60);
|
||||
CheckDecision(controller.get(), rtc::Optional<int>(kMediumPacketLossFraction),
|
||||
rtc::Optional<float>(kFlDecreasingPacketLossFraction),
|
||||
rtc::Optional<bool>(), 20);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
Reference in New Issue
Block a user