Pass Environment into UlpfecGenerator

To make it available for FEC to use field trials in follow ups

Bug: webrtc:355577231
Change-Id: I4a6260a38e50a70dae27db28401b08bf0160aaec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358680
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42740}
This commit is contained in:
Xinyu Ma 2024-08-06 14:37:38 -07:00 committed by WebRTC LUCI CQ
parent e1dbddfbcf
commit 675986ec5f
8 changed files with 39 additions and 26 deletions

View File

@ -176,9 +176,8 @@ std::unique_ptr<VideoFecGenerator> MaybeCreateFecGenerator(
!ShouldDisableRedAndUlpfec(/*flexfec_enabled=*/false, rtp,
env.field_trials())) {
// Flexfec not configured, but ulpfec is and is not disabled.
return std::make_unique<UlpfecGenerator>(rtp.ulpfec.red_payload_type,
rtp.ulpfec.ulpfec_payload_type,
&env.clock());
return std::make_unique<UlpfecGenerator>(env, rtp.ulpfec.red_payload_type,
rtp.ulpfec.ulpfec_payload_type);
}
// Not a single FEC is given.

View File

@ -94,8 +94,8 @@ FlexfecSender::FlexfecSender(
seq_num_(rtp_state ? rtp_state->sequence_number
: random_.Rand(1, kMaxInitRtpSeqNumber)),
ulpfec_generator_(
ForwardErrorCorrection::CreateFlexfec(ssrc, protected_media_ssrc),
&env_.clock()),
env_,
ForwardErrorCorrection::CreateFlexfec(ssrc, protected_media_ssrc)),
rtp_header_extension_map_(
RegisterSupportedExtensions(rtp_header_extensions)),
header_extensions_size_(

View File

@ -1030,8 +1030,7 @@ TEST_F(RtpRtcpImpl2Test, GeneratesFlexfec) {
TEST_F(RtpRtcpImpl2Test, GeneratesUlpfec) {
constexpr int kUlpfecPayloadType = 118;
constexpr int kRedPayloadType = 119;
UlpfecGenerator ulpfec_sender(kRedPayloadType, kUlpfecPayloadType,
time_controller_.GetClock());
UlpfecGenerator ulpfec_sender(env_, kRedPayloadType, kUlpfecPayloadType);
ReinitWithFec(&ulpfec_sender, kRedPayloadType);
// Parameters selected to generate a single FEC packet per media packet.

View File

@ -67,12 +67,12 @@ UlpfecGenerator::Params::Params(FecProtectionParams delta_params,
FecProtectionParams keyframe_params)
: delta_params(delta_params), keyframe_params(keyframe_params) {}
UlpfecGenerator::UlpfecGenerator(int red_payload_type,
int ulpfec_payload_type,
Clock* clock)
: red_payload_type_(red_payload_type),
UlpfecGenerator::UlpfecGenerator(const Environment& env,
int red_payload_type,
int ulpfec_payload_type)
: env_(env),
red_payload_type_(red_payload_type),
ulpfec_payload_type_(ulpfec_payload_type),
clock_(clock),
fec_(ForwardErrorCorrection::CreateUlpfec(kUnknownSsrc)),
num_protected_frames_(0),
min_num_media_packets_(1),
@ -80,11 +80,11 @@ UlpfecGenerator::UlpfecGenerator(int red_payload_type,
fec_bitrate_(/*max_window_size=*/TimeDelta::Seconds(1)) {}
// Used by FlexFecSender, payload types are unused.
UlpfecGenerator::UlpfecGenerator(std::unique_ptr<ForwardErrorCorrection> fec,
Clock* clock)
: red_payload_type_(0),
UlpfecGenerator::UlpfecGenerator(const Environment& env,
std::unique_ptr<ForwardErrorCorrection> fec)
: env_(env),
red_payload_type_(0),
ulpfec_payload_type_(0),
clock_(clock),
fec_(std::move(fec)),
num_protected_frames_(0),
min_num_media_packets_(1),
@ -235,14 +235,15 @@ std::vector<std::unique_ptr<RtpPacketToSend>> UlpfecGenerator::GetFecPackets() {
ResetState();
MutexLock lock(&mutex_);
fec_bitrate_.Update(total_fec_size_bytes, clock_->CurrentTime());
fec_bitrate_.Update(total_fec_size_bytes, env_.clock().CurrentTime());
return fec_packets;
}
DataRate UlpfecGenerator::CurrentFecRate() const {
MutexLock lock(&mutex_);
return fec_bitrate_.Rate(clock_->CurrentTime()).value_or(DataRate::Zero());
return fec_bitrate_.Rate(env_.clock().CurrentTime())
.value_or(DataRate::Zero());
}
int UlpfecGenerator::Overhead() const {

View File

@ -18,6 +18,7 @@
#include <memory>
#include <vector>
#include "api/environment/environment.h"
#include "modules/include/module_fec_types.h"
#include "modules/rtp_rtcp/source/forward_error_correction.h"
#include "modules/rtp_rtcp/source/video_fec_generator.h"
@ -33,7 +34,9 @@ class UlpfecGenerator : public VideoFecGenerator {
friend class FlexfecSender;
public:
UlpfecGenerator(int red_payload_type, int ulpfec_payload_type, Clock* clock);
UlpfecGenerator(const Environment& env,
int red_payload_type,
int ulpfec_payload_type);
~UlpfecGenerator();
FecType GetFecType() const override {
@ -72,7 +75,8 @@ class UlpfecGenerator : public VideoFecGenerator {
FecProtectionParams keyframe_params;
};
UlpfecGenerator(std::unique_ptr<ForwardErrorCorrection> fec, Clock* clock);
UlpfecGenerator(const Environment& env,
std::unique_ptr<ForwardErrorCorrection> fec);
// Overhead is defined as relative to the number of media packets, and not
// relative to total number of packets. This definition is inherited from the
@ -95,9 +99,9 @@ class UlpfecGenerator : public VideoFecGenerator {
void ResetState();
const Environment env_;
const int red_payload_type_;
const int ulpfec_payload_type_;
Clock* const clock_;
rtc::RaceChecker race_checker_;
const std::unique_ptr<ForwardErrorCorrection> fec_

View File

@ -15,6 +15,8 @@
#include <utility>
#include <vector>
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/fec_test_helper.h"
#include "modules/rtp_rtcp/source/forward_error_correction.h"
@ -50,11 +52,11 @@ void VerifyHeader(uint16_t seq_num,
class UlpfecGeneratorTest : public ::testing::Test {
protected:
UlpfecGeneratorTest()
: fake_clock_(1),
ulpfec_generator_(kRedPayloadType, kFecPayloadType, &fake_clock_),
: env_(CreateEnvironment(std::make_unique<SimulatedClock>(1))),
ulpfec_generator_(env_, kRedPayloadType, kFecPayloadType),
packet_generator_(kMediaSsrc) {}
SimulatedClock fake_clock_;
const Environment env_;
UlpfecGenerator ulpfec_generator_;
AugmentedPacketGenerator packet_generator_;
};

View File

@ -184,6 +184,8 @@ webrtc_fuzzer_test("ulpfec_header_reader_fuzzer") {
webrtc_fuzzer_test("ulpfec_generator_fuzzer") {
sources = [ "ulpfec_generator_fuzzer.cc" ]
deps = [
"../../api/environment",
"../../api/environment:environment_factory",
"../../modules:module_api_public",
"../../modules/rtp_rtcp",
"../../modules/rtp_rtcp:fec_test_helper",

View File

@ -10,6 +10,8 @@
#include <memory>
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "modules/include/module_common_types_public.h"
#include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/fec_test_helper.h"
@ -26,8 +28,12 @@ constexpr uint8_t kRedPayloadType = 97;
} // namespace
void FuzzOneInput(const uint8_t* data, size_t size) {
SimulatedClock clock(1);
UlpfecGenerator generator(kRedPayloadType, kFecPayloadType, &clock);
// Create Environment once because creating it for each input noticably
// reduces the speed of the fuzzer.
static const Environment* const env =
new Environment(CreateEnvironment(std::make_unique<SimulatedClock>(1)));
UlpfecGenerator generator(*env, kRedPayloadType, kFecPayloadType);
size_t i = 0;
if (size < 4)
return;