#include "modules/audio_coding/audio_network_adaptor/controller_manager.h"
#include <cmath>
#include <memory>
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/audio_network_adaptor/bitrate_controller.h"
#include "modules/audio_coding/audio_network_adaptor/channel_controller.h"
#include "modules/audio_coding/audio_network_adaptor/debug_dump_writer.h"
#include "modules/audio_coding/audio_network_adaptor/dtx_controller.h"
#include "modules/audio_coding/audio_network_adaptor/fec_controller_plr_based.h"
#include "modules/audio_coding/audio_network_adaptor/frame_length_controller.h"
#include "modules/audio_coding/audio_network_adaptor/frame_length_controller_v2.h"
#include "modules/audio_coding/audio_network_adaptor/util/threshold_curve.h"
#include "rtc_base/logging.h"
#include "rtc_base/time_utils.h"
#if WEBRTC_ENABLE_PROTOBUF
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
#include "external/webrtc/webrtc/modules/audio_coding/audio_network_adaptor/config.pb.h"
#else
#include "modules/audio_coding/audio_network_adaptor/config.pb.h"
#endif
#endif
namespace webrtc {
namespace {
#if WEBRTC_ENABLE_PROTOBUF
std::unique_ptr<FecControllerPlrBased> CreateFecControllerPlrBased(
const audio_network_adaptor::config::FecController& config,
bool initial_fec_enabled) { … }
std::unique_ptr<FrameLengthController> CreateFrameLengthController(
const audio_network_adaptor::config::FrameLengthController& config,
rtc::ArrayView<const int> encoder_frame_lengths_ms,
int initial_frame_length_ms,
int min_encoder_bitrate_bps) { … }
std::unique_ptr<ChannelController> CreateChannelController(
const audio_network_adaptor::config::ChannelController& config,
size_t num_encoder_channels,
size_t intial_channels_to_encode) { … }
std::unique_ptr<DtxController> CreateDtxController(
const audio_network_adaptor::config::DtxController& dtx_config,
bool initial_dtx_enabled) { … }
BitrateController;
std::unique_ptr<BitrateController> CreateBitrateController(
const audio_network_adaptor::config::BitrateController& bitrate_config,
int initial_bitrate_bps,
int initial_frame_length_ms) { … }
std::unique_ptr<FrameLengthControllerV2> CreateFrameLengthControllerV2(
const audio_network_adaptor::config::FrameLengthControllerV2& config,
rtc::ArrayView<const int> encoder_frame_lengths_ms) { … }
#endif
}
ControllerManagerImpl::Config::Config(int min_reordering_time_ms,
float min_reordering_squared_distance)
: … { … }
ControllerManagerImpl::Config::~Config() = default;
std::unique_ptr<ControllerManager> ControllerManagerImpl::Create(
absl::string_view config_string,
size_t num_encoder_channels,
rtc::ArrayView<const int> encoder_frame_lengths_ms,
int min_encoder_bitrate_bps,
size_t intial_channels_to_encode,
int initial_frame_length_ms,
int initial_bitrate_bps,
bool initial_fec_enabled,
bool initial_dtx_enabled) { … }
std::unique_ptr<ControllerManager> ControllerManagerImpl::Create(
absl::string_view config_string,
size_t num_encoder_channels,
rtc::ArrayView<const int> encoder_frame_lengths_ms,
int min_encoder_bitrate_bps,
size_t intial_channels_to_encode,
int initial_frame_length_ms,
int initial_bitrate_bps,
bool initial_fec_enabled,
bool initial_dtx_enabled,
DebugDumpWriter* debug_dump_writer) { … }
ControllerManagerImpl::ControllerManagerImpl(const Config& config)
: … { … }
ControllerManagerImpl::ControllerManagerImpl(
const Config& config,
std::vector<std::unique_ptr<Controller>> controllers,
const std::map<const Controller*, std::pair<int, float>>& scoring_points)
: … { … }
ControllerManagerImpl::~ControllerManagerImpl() = default;
std::vector<Controller*> ControllerManagerImpl::GetSortedControllers(
const Controller::NetworkMetrics& metrics) { … }
std::vector<Controller*> ControllerManagerImpl::GetControllers() const { … }
ControllerManagerImpl::ScoringPoint::ScoringPoint(
int uplink_bandwidth_bps,
float uplink_packet_loss_fraction)
: … { … }
namespace {
constexpr int kMinUplinkBandwidthBps = …;
constexpr int kMaxUplinkBandwidthBps = …;
float NormalizeUplinkBandwidth(int uplink_bandwidth_bps) { … }
float NormalizePacketLossFraction(float uplink_packet_loss_fraction) { … }
}
float ControllerManagerImpl::ScoringPoint::SquaredDistanceTo(
const ScoringPoint& scoring_point) const { … }
}