Use propagated instead of global field trials in FecControllerDefault

Bug: webrtc:10335
Change-Id: Ia559ae2655b39e7093cfdb9ed669f3463ef90054
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/333842
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41483}
This commit is contained in:
Danil Chapovalov 2024-01-09 11:46:59 +01:00 committed by WebRTC LUCI CQ
parent 6791c9d17e
commit 1d6bf3156b
6 changed files with 28 additions and 26 deletions

View file

@ -922,7 +922,7 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream(
std::unique_ptr<FecController> fec_controller =
config_.fec_controller_factory
? config_.fec_controller_factory->CreateFecController(env_)
: std::make_unique<FecControllerDefault>(&env_.clock());
: std::make_unique<FecControllerDefault>(env_);
return CreateVideoSendStream(std::move(config), std::move(encoder_config),
std::move(fec_controller));
}

View file

@ -146,8 +146,8 @@ class RtpVideoSenderTestFixture {
&stats_proxy_, frame_count_observer, &stats_proxy_),
&transport_controller_, &env_.event_log(),
&retransmission_rate_limiter_,
std::make_unique<FecControllerDefault>(time_controller_.GetClock()),
nullptr, CryptoOptions{}, frame_transformer, env_.field_trials(),
std::make_unique<FecControllerDefault>(env_), nullptr, CryptoOptions{},
frame_transformer, env_.field_trials(),
time_controller_.GetTaskQueueFactory());
}

View file

@ -218,6 +218,7 @@ rtc_library("video_coding") {
"../../api:rtp_packet_info",
"../../api:scoped_refptr",
"../../api:sequence_checker",
"../../api/environment",
"../../api/task_queue",
"../../api/units:data_rate",
"../../api/units:data_size",
@ -258,7 +259,6 @@ rtc_library("video_coding") {
"../../rtc_base/task_utils:repeating_task",
"../../rtc_base/third_party/base64",
"../../system_wrappers",
"../../system_wrappers:field_trial",
"../../system_wrappers:metrics",
"../../video/config:encoder_config",
"../rtp_rtcp",
@ -1217,6 +1217,7 @@ if (rtc_include_tests) {
"../../api:scoped_refptr",
"../../api:simulcast_test_fixture_api",
"../../api:videocodec_test_fixture_api",
"../../api/environment:environment_factory",
"../../api/task_queue",
"../../api/task_queue:default_task_queue_factory",
"../../api/test/video:function_video_factory",

View file

@ -15,30 +15,28 @@
#include <algorithm>
#include <string>
#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "modules/include/module_fec_types.h"
#include "rtc_base/logging.h"
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
const float kProtectionOverheadRateThreshold = 0.5;
FecControllerDefault::FecControllerDefault(
Clock* clock,
const Environment& env,
VCMProtectionCallback* protection_callback)
: clock_(clock),
: env_(env),
protection_callback_(protection_callback),
loss_prot_logic_(new media_optimization::VCMLossProtectionLogic(
clock_->TimeInMilliseconds())),
env_.clock().TimeInMilliseconds())),
max_payload_size_(1460),
overhead_threshold_(GetProtectionOverheadRateThreshold()) {}
FecControllerDefault::FecControllerDefault(Clock* clock)
: clock_(clock),
loss_prot_logic_(new media_optimization::VCMLossProtectionLogic(
clock_->TimeInMilliseconds())),
max_payload_size_(1460),
overhead_threshold_(GetProtectionOverheadRateThreshold()) {}
FecControllerDefault::FecControllerDefault(const Environment& env)
: FecControllerDefault(env, nullptr) {}
FecControllerDefault::~FecControllerDefault(void) {
loss_prot_logic_->Release();
@ -61,8 +59,8 @@ void FecControllerDefault::SetEncodingData(size_t width,
float FecControllerDefault::GetProtectionOverheadRateThreshold() {
float overhead_threshold =
strtof(webrtc::field_trial::FindFullName(
"WebRTC-ProtectionOverheadRateThreshold")
strtof(env_.field_trials()
.Lookup("WebRTC-ProtectionOverheadRateThreshold")
.c_str(),
nullptr);
if (overhead_threshold > 0 && overhead_threshold <= 1) {
@ -107,7 +105,7 @@ uint32_t FecControllerDefault::UpdateFecRates(
media_optimization::FilterPacketLossMode filter_mode =
media_optimization::kMaxFilter;
uint8_t packet_loss_enc = loss_prot_logic_->FilteredLoss(
clock_->TimeInMilliseconds(), filter_mode, fraction_lost);
env_.clock().TimeInMilliseconds(), filter_mode, fraction_lost);
// For now use the filtered loss for computing the robustness settings.
loss_prot_logic_->UpdateFilteredLossPr(packet_loss_enc);
if (loss_prot_logic_->SelectedType() == media_optimization::kNone) {
@ -191,11 +189,11 @@ void FecControllerDefault::UpdateWithEncodedData(
const float min_packets_per_frame =
encoded_length / static_cast<float>(max_payload_size_);
if (delta_frame) {
loss_prot_logic_->UpdatePacketsPerFrame(min_packets_per_frame,
clock_->TimeInMilliseconds());
loss_prot_logic_->UpdatePacketsPerFrame(
min_packets_per_frame, env_.clock().TimeInMilliseconds());
} else {
loss_prot_logic_->UpdatePacketsPerFrameKey(
min_packets_per_frame, clock_->TimeInMilliseconds());
min_packets_per_frame, env_.clock().TimeInMilliseconds());
}
}
if (!delta_frame && encoded_length > 0) {

View file

@ -17,24 +17,25 @@
#include <memory>
#include <vector>
#include "api/environment/environment.h"
#include "api/fec_controller.h"
#include "modules/video_coding/media_opt_util.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
class FecControllerDefault : public FecController {
public:
FecControllerDefault(Clock* clock,
FecControllerDefault(const Environment& env,
VCMProtectionCallback* protection_callback);
explicit FecControllerDefault(Clock* clock);
~FecControllerDefault() override;
explicit FecControllerDefault(const Environment& env);
FecControllerDefault(const FecControllerDefault&) = delete;
FecControllerDefault& operator=(const FecControllerDefault&) = delete;
~FecControllerDefault() override;
void SetProtectionCallback(
VCMProtectionCallback* protection_callback) override;
void SetProtectionMethod(bool enable_fec, bool enable_nack) override;
@ -54,7 +55,7 @@ class FecControllerDefault : public FecController {
private:
enum { kBitrateAverageWinMs = 1000 };
Clock* const clock_;
const Environment env_;
VCMProtectionCallback* protection_callback_;
Mutex mutex_;
std::unique_ptr<media_optimization::VCMLossProtectionLogic> loss_prot_logic_

View file

@ -14,6 +14,7 @@
#include <vector>
#include "api/environment/environment_factory.h"
#include "modules/include/module_fec_types.h"
#include "modules/video_coding/fec_controller_default.h"
#include "system_wrappers/include/clock.h"
@ -50,7 +51,8 @@ class ProtectionBitrateCalculatorTest : public ::testing::Test {
// Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as
// a special case (e.g. frame rate in media optimization).
ProtectionBitrateCalculatorTest()
: clock_(1000), fec_controller_(&clock_, &protection_callback_) {}
: clock_(1000),
fec_controller_(CreateEnvironment(&clock_), &protection_callback_) {}
SimulatedClock clock_;
ProtectionCallback protection_callback_;