Provide Environment to SimulcastRateAllocator at construction
So that this class can use propagated field trials instead of the global Bug: webrtc:42220378 Change-Id: Ic1dba0c4967735606904329f7e9e6c09f186b809 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/350641 Reviewed-by: Erik Språng <sprang@webrtc.org> Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42326}
This commit is contained in:
parent
a45c7056ad
commit
fd89ff5d93
@ -264,7 +264,6 @@ rtc_source_set("video_bitrate_allocator_factory") {
|
||||
sources = [ "video_bitrate_allocator_factory.h" ]
|
||||
deps = [
|
||||
":video_bitrate_allocator",
|
||||
"../../rtc_base:checks",
|
||||
"../environment",
|
||||
"../video_codecs:video_codecs_api",
|
||||
]
|
||||
|
||||
@ -29,7 +29,8 @@ class BuiltinVideoBitrateAllocatorFactory
|
||||
BuiltinVideoBitrateAllocatorFactory() = default;
|
||||
~BuiltinVideoBitrateAllocatorFactory() override = default;
|
||||
|
||||
std::unique_ptr<VideoBitrateAllocator> CreateVideoBitrateAllocator(
|
||||
std::unique_ptr<VideoBitrateAllocator> Create(
|
||||
const Environment& env,
|
||||
const VideoCodec& codec) override {
|
||||
// TODO(https://crbug.com/webrtc/14884): Update SvcRateAllocator to
|
||||
// support simulcast and use it for VP9/AV1 simulcast as well.
|
||||
@ -38,7 +39,7 @@ class BuiltinVideoBitrateAllocatorFactory
|
||||
codec.numberOfSimulcastStreams <= 1) {
|
||||
return std::make_unique<SvcRateAllocator>(codec);
|
||||
}
|
||||
return std::make_unique<SimulcastRateAllocator>(codec);
|
||||
return std::make_unique<SimulcastRateAllocator>(env, codec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/video/video_bitrate_allocator.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -29,15 +28,7 @@ class VideoBitrateAllocatorFactory {
|
||||
// Creates a VideoBitrateAllocator for a specific video codec.
|
||||
virtual std::unique_ptr<VideoBitrateAllocator> Create(
|
||||
const Environment& env,
|
||||
const VideoCodec& codec) {
|
||||
return CreateVideoBitrateAllocator(codec);
|
||||
}
|
||||
virtual std::unique_ptr<VideoBitrateAllocator> CreateVideoBitrateAllocator(
|
||||
const VideoCodec& codec) {
|
||||
// Newer code shouldn't call this function,
|
||||
// Older code should implement it in derived classes.
|
||||
RTC_CHECK_NOTREACHED();
|
||||
}
|
||||
const VideoCodec& codec) = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -93,10 +93,11 @@ class VideoEncoderSoftwareFallbackWrapperTestBase : public ::testing::Test {
|
||||
VideoEncoderSoftwareFallbackWrapperTestBase(
|
||||
const Environment& env,
|
||||
std::unique_ptr<VideoEncoder> sw_encoder)
|
||||
: fake_encoder_(new CountingFakeEncoder()),
|
||||
: env_(env),
|
||||
fake_encoder_(new CountingFakeEncoder()),
|
||||
wrapper_initialized_(false),
|
||||
fallback_wrapper_(CreateVideoEncoderSoftwareFallbackWrapper(
|
||||
env,
|
||||
env_,
|
||||
std::move(sw_encoder),
|
||||
std::unique_ptr<VideoEncoder>(fake_encoder_),
|
||||
false)) {}
|
||||
@ -172,6 +173,7 @@ class VideoEncoderSoftwareFallbackWrapperTestBase : public ::testing::Test {
|
||||
fallback_wrapper_->GetEncoderInfo().implementation_name);
|
||||
}
|
||||
|
||||
const Environment env_;
|
||||
FakeEncodedImageCallback callback_;
|
||||
// `fake_encoder_` is owned and released by `fallback_wrapper_`.
|
||||
CountingFakeEncoder* fake_encoder_;
|
||||
@ -232,7 +234,7 @@ void VideoEncoderSoftwareFallbackWrapperTestBase::InitEncode() {
|
||||
codec_.width = kWidth;
|
||||
codec_.height = kHeight;
|
||||
codec_.VP8()->numberOfTemporalLayers = 1;
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
|
||||
if (wrapper_initialized_) {
|
||||
fallback_wrapper_->Release();
|
||||
@ -263,7 +265,7 @@ void VideoEncoderSoftwareFallbackWrapperTestBase::UtilizeFallbackEncoder() {
|
||||
codec_.width = kWidth;
|
||||
codec_.height = kHeight;
|
||||
codec_.VP8()->numberOfTemporalLayers = 1;
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
|
||||
if (wrapper_initialized_) {
|
||||
fallback_wrapper_->Release();
|
||||
@ -291,7 +293,7 @@ void VideoEncoderSoftwareFallbackWrapperTestBase::FallbackFromEncodeRequest() {
|
||||
codec_.width = kWidth;
|
||||
codec_.height = kHeight;
|
||||
codec_.VP8()->numberOfTemporalLayers = 1;
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
if (wrapper_initialized_) {
|
||||
fallback_wrapper_->Release();
|
||||
}
|
||||
@ -514,7 +516,7 @@ class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTestBase {
|
||||
codec_.VP8()->numberOfTemporalLayers = 1;
|
||||
codec_.VP8()->automaticResizeOn = true;
|
||||
codec_.SetFrameDropEnabled(true);
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
}
|
||||
|
||||
void InitEncode(int width, int height) {
|
||||
|
||||
@ -39,12 +39,13 @@
|
||||
#include "rtc_base/experiments/rate_control_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
// Max qp for lowest spatial resolution when doing simulcast.
|
||||
const unsigned int kLowestResMaxQp = 45;
|
||||
|
||||
uint32_t SumStreamMaxBitrate(int streams, const webrtc::VideoCodec& codec) {
|
||||
uint32_t SumStreamMaxBitrate(int streams, const VideoCodec& codec) {
|
||||
uint32_t bitrate_sum = 0;
|
||||
for (int i = 0; i < streams; ++i) {
|
||||
bitrate_sum += codec.simulcastStream[i].maxBitrate;
|
||||
@ -52,7 +53,7 @@ uint32_t SumStreamMaxBitrate(int streams, const webrtc::VideoCodec& codec) {
|
||||
return bitrate_sum;
|
||||
}
|
||||
|
||||
int CountAllStreams(const webrtc::VideoCodec& codec) {
|
||||
int CountAllStreams(const VideoCodec& codec) {
|
||||
int total_streams_count =
|
||||
codec.numberOfSimulcastStreams < 1 ? 1 : codec.numberOfSimulcastStreams;
|
||||
uint32_t simulcast_max_bitrate =
|
||||
@ -63,7 +64,7 @@ int CountAllStreams(const webrtc::VideoCodec& codec) {
|
||||
return total_streams_count;
|
||||
}
|
||||
|
||||
int CountActiveStreams(const webrtc::VideoCodec& codec) {
|
||||
int CountActiveStreams(const VideoCodec& codec) {
|
||||
if (codec.numberOfSimulcastStreams < 1) {
|
||||
return 1;
|
||||
}
|
||||
@ -77,7 +78,7 @@ int CountActiveStreams(const webrtc::VideoCodec& codec) {
|
||||
return active_streams_count;
|
||||
}
|
||||
|
||||
int VerifyCodec(const webrtc::VideoCodec* codec_settings) {
|
||||
int VerifyCodec(const VideoCodec* codec_settings) {
|
||||
if (codec_settings == nullptr) {
|
||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||
}
|
||||
@ -100,14 +101,13 @@ int VerifyCodec(const webrtc::VideoCodec* codec_settings) {
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
bool StreamQualityCompare(const webrtc::SimulcastStream& a,
|
||||
const webrtc::SimulcastStream& b) {
|
||||
bool StreamQualityCompare(const SimulcastStream& a, const SimulcastStream& b) {
|
||||
return std::tie(a.height, a.width, a.maxBitrate, a.maxFramerate) <
|
||||
std::tie(b.height, b.width, b.maxBitrate, b.maxFramerate);
|
||||
}
|
||||
|
||||
void GetLowestAndHighestQualityStreamIndixes(
|
||||
rtc::ArrayView<webrtc::SimulcastStream> streams,
|
||||
rtc::ArrayView<const SimulcastStream> streams,
|
||||
int* lowest_quality_stream_idx,
|
||||
int* highest_quality_stream_idx) {
|
||||
const auto lowest_highest_quality_streams =
|
||||
@ -118,14 +118,13 @@ void GetLowestAndHighestQualityStreamIndixes(
|
||||
std::distance(streams.begin(), lowest_highest_quality_streams.second);
|
||||
}
|
||||
|
||||
std::vector<uint32_t> GetStreamStartBitratesKbps(
|
||||
const webrtc::VideoCodec& codec) {
|
||||
std::vector<uint32_t> GetStreamStartBitratesKbps(const Environment& env,
|
||||
const VideoCodec& codec) {
|
||||
std::vector<uint32_t> start_bitrates;
|
||||
std::unique_ptr<webrtc::VideoBitrateAllocator> rate_allocator =
|
||||
std::make_unique<webrtc::SimulcastRateAllocator>(codec);
|
||||
webrtc::VideoBitrateAllocation allocation =
|
||||
rate_allocator->Allocate(webrtc::VideoBitrateAllocationParameters(
|
||||
codec.startBitrate * 1000, codec.maxFramerate));
|
||||
VideoBitrateAllocation allocation =
|
||||
SimulcastRateAllocator(env, codec)
|
||||
.Allocate(VideoBitrateAllocationParameters(codec.startBitrate * 1000,
|
||||
codec.maxFramerate));
|
||||
|
||||
int total_streams_count = CountAllStreams(codec);
|
||||
for (int i = 0; i < total_streams_count; ++i) {
|
||||
@ -137,8 +136,6 @@ std::vector<uint32_t> GetStreamStartBitratesKbps(
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
SimulcastEncoderAdapter::EncoderContext::EncoderContext(
|
||||
std::unique_ptr<VideoEncoder> encoder,
|
||||
bool prefer_temporal_support,
|
||||
@ -377,7 +374,7 @@ int SimulcastEncoderAdapter::InitEncode(
|
||||
|
||||
// Multi-encoder simulcast or singlecast (deactivated layers).
|
||||
std::vector<uint32_t> stream_start_bitrate_kbps =
|
||||
GetStreamStartBitratesKbps(codec_);
|
||||
GetStreamStartBitratesKbps(env_, codec_);
|
||||
|
||||
for (int stream_idx = 0; stream_idx < total_streams_count_; ++stream_idx) {
|
||||
if (!is_legacy_singlecast && !codec_.simulcastStream[stream_idx].active) {
|
||||
|
||||
@ -447,7 +447,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,
|
||||
|
||||
void SetUp() override {
|
||||
helper_ = std::make_unique<TestSimulcastEncoderAdapterFakeHelper>(
|
||||
CreateEnvironment(&field_trials_), use_fallback_factory_,
|
||||
env_, use_fallback_factory_,
|
||||
SdpVideoFormat("VP8", sdp_video_parameters_));
|
||||
adapter_ = helper_->CreateMockEncoderAdapter();
|
||||
last_encoded_image_width_ = absl::nullopt;
|
||||
@ -503,7 +503,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,
|
||||
codec_.simulcastStream[stream_idx].active = active_streams[stream_idx];
|
||||
}
|
||||
}
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
}
|
||||
@ -579,6 +579,8 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,
|
||||
}
|
||||
|
||||
protected:
|
||||
test::ScopedKeyValueConfig field_trials_;
|
||||
const Environment env_ = CreateEnvironment(&field_trials_);
|
||||
std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_;
|
||||
std::unique_ptr<VideoEncoder> adapter_;
|
||||
VideoCodec codec_;
|
||||
@ -588,7 +590,6 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,
|
||||
std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
|
||||
bool use_fallback_factory_;
|
||||
CodecParameterMap sdp_video_parameters_;
|
||||
test::ScopedKeyValueConfig field_trials_;
|
||||
};
|
||||
|
||||
TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) {
|
||||
@ -662,7 +663,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
|
||||
SimulcastTestFixtureImpl::DefaultSettings(
|
||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||
kVideoCodecVP8);
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
const uint32_t target_bitrate =
|
||||
1000 * (codec_.simulcastStream[0].targetBitrate +
|
||||
@ -913,7 +914,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
|
||||
codec_.minBitrate = 50;
|
||||
codec_.numberOfSimulcastStreams = 1;
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
|
||||
// Above min should be respected.
|
||||
VideoBitrateAllocation target_bitrate = rate_allocator_->Allocate(
|
||||
@ -1110,7 +1111,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, GeneratesKeyFramesOnRequestedLayers) {
|
||||
SimulcastTestFixtureImpl::DefaultSettings(
|
||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||
kVideoCodecVP8);
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
// Input data.
|
||||
@ -1299,7 +1300,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, ActivatesCorrectStreamsInInitEncode) {
|
||||
SimulcastTestFixtureImpl::DefaultSettings(
|
||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||
kVideoCodecVP8);
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
// Only enough start bitrate for the lowest stream.
|
||||
@ -1337,7 +1338,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, TrustedRateControl) {
|
||||
SimulcastTestFixtureImpl::DefaultSettings(
|
||||
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
|
||||
kVideoCodecVP8);
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
// Only enough start bitrate for the lowest stream.
|
||||
@ -1584,7 +1585,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, SetRateDistributesBandwithAllocation) {
|
||||
const DataRate bandwidth_allocation =
|
||||
target_bitrate + DataRate::KilobitsPerSec(600);
|
||||
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
@ -1620,7 +1621,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, CanSetZeroBitrateWithHeadroom) {
|
||||
kVideoCodecVP8);
|
||||
codec_.numberOfSimulcastStreams = 3;
|
||||
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, codec_);
|
||||
EXPECT_EQ(0, adapter_->InitEncode(&codec_, kSettings));
|
||||
adapter_->RegisterEncodeCompleteCallback(this);
|
||||
|
||||
|
||||
@ -420,9 +420,9 @@ rtc_library("video_coding_utility") {
|
||||
":video_codec_interface",
|
||||
"../../api:array_view",
|
||||
"../../api:field_trials_view",
|
||||
"../../api:field_trials_view",
|
||||
"../../api:scoped_refptr",
|
||||
"../../api:sequence_checker",
|
||||
"../../api/environment",
|
||||
"../../api/units:time_delta",
|
||||
"../../api/video:encoded_frame",
|
||||
"../../api/video:encoded_image",
|
||||
@ -453,7 +453,6 @@ rtc_library("video_coding_utility") {
|
||||
"../../rtc_base/system:file_wrapper",
|
||||
"../../rtc_base/system:no_unique_address",
|
||||
"../../rtc_base/task_utils:repeating_task",
|
||||
"../../system_wrappers:field_trial",
|
||||
"../rtp_rtcp:rtp_rtcp_format",
|
||||
"svc:scalability_mode_util",
|
||||
]
|
||||
|
||||
@ -174,7 +174,8 @@ static void RtpFragmentize(EncodedImage* encoded_image, SFrameBSInfo* info) {
|
||||
|
||||
H264EncoderImpl::H264EncoderImpl(const Environment& env,
|
||||
H264EncoderSettings settings)
|
||||
: packetization_mode_(settings.packetization_mode),
|
||||
: env_(env),
|
||||
packetization_mode_(settings.packetization_mode),
|
||||
max_payload_size_(0),
|
||||
number_of_cores_(0),
|
||||
encoded_image_callback_(nullptr),
|
||||
@ -326,7 +327,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
|
||||
}
|
||||
}
|
||||
|
||||
SimulcastRateAllocator init_allocator(codec_);
|
||||
SimulcastRateAllocator init_allocator(env_, codec_);
|
||||
VideoBitrateAllocation allocation =
|
||||
init_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
DataRate::KilobitsPerSec(codec_.startBitrate), codec_.maxFramerate));
|
||||
|
||||
@ -106,6 +106,7 @@ class H264EncoderImpl : public VideoEncoder {
|
||||
absl::InlinedVector<absl::optional<ScalabilityMode>, kMaxSimulcastStreams>
|
||||
scalability_modes_;
|
||||
|
||||
const Environment env_;
|
||||
VideoCodec codec_;
|
||||
H264PacketizationMode packetization_mode_;
|
||||
size_t max_payload_size_;
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "api/video_codecs/vp8_frame_config.h"
|
||||
@ -98,7 +99,7 @@ std::vector<uint32_t> GetTemporalLayerRates(int target_bitrate_kbps,
|
||||
codec.simulcastStream[0].maxBitrate = target_bitrate_kbps;
|
||||
codec.simulcastStream[0].numberOfTemporalLayers = num_temporal_layers;
|
||||
codec.simulcastStream[0].active = true;
|
||||
SimulcastRateAllocator allocator(codec);
|
||||
SimulcastRateAllocator allocator(CreateEnvironment(), codec);
|
||||
return allocator
|
||||
.Allocate(
|
||||
VideoBitrateAllocationParameters(target_bitrate_kbps, framerate_fps))
|
||||
|
||||
@ -678,7 +678,7 @@ int LibvpxVp8Encoder::InitEncode(const VideoCodec* inst,
|
||||
// Note the order we use is different from webm, we have lowest resolution
|
||||
// at position 0 and they have highest resolution at position 0.
|
||||
const size_t stream_idx_cfg_0 = encoders_.size() - 1;
|
||||
SimulcastRateAllocator init_allocator(codec_);
|
||||
SimulcastRateAllocator init_allocator(env_, codec_);
|
||||
VideoBitrateAllocation allocation =
|
||||
init_allocator.Allocate(VideoBitrateAllocationParameters(
|
||||
inst->startBitrate * 1000, inst->maxFramerate));
|
||||
|
||||
@ -20,9 +20,9 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "api/environment/environment.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/rate_control_settings.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
@ -64,6 +64,14 @@ SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec)
|
||||
rate_control_settings_(RateControlSettings::ParseFromFieldTrials()),
|
||||
legacy_conference_mode_(false) {}
|
||||
|
||||
SimulcastRateAllocator::SimulcastRateAllocator(const Environment& env,
|
||||
const VideoCodec& codec)
|
||||
: codec_(codec),
|
||||
stable_rate_settings_(StableTargetRateExperiment::ParseFromKeyValueConfig(
|
||||
&env.field_trials())),
|
||||
rate_control_settings_(env.field_trials()),
|
||||
legacy_conference_mode_(false) {}
|
||||
|
||||
SimulcastRateAllocator::~SimulcastRateAllocator() = default;
|
||||
|
||||
VideoBitrateAllocation SimulcastRateAllocator::Allocate(
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "api/video/video_bitrate_allocator.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
@ -26,7 +27,8 @@ namespace webrtc {
|
||||
|
||||
class SimulcastRateAllocator : public VideoBitrateAllocator {
|
||||
public:
|
||||
explicit SimulcastRateAllocator(const VideoCodec& codec);
|
||||
[[deprecated]] explicit SimulcastRateAllocator(const VideoCodec& codec);
|
||||
SimulcastRateAllocator(const Environment& env, const VideoCodec& codec);
|
||||
~SimulcastRateAllocator() override;
|
||||
|
||||
SimulcastRateAllocator(const SimulcastRateAllocator&) = delete;
|
||||
|
||||
@ -15,16 +15,19 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/video_codecs/vp8_frame_buffer_controller.h"
|
||||
#include "api/video_codecs/vp8_frame_config.h"
|
||||
#include "api/video_codecs/vp8_temporal_layers.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "test/field_trial.h"
|
||||
#include "test/explicit_key_value_config.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
using test::ExplicitKeyValueConfig;
|
||||
using ::testing::_;
|
||||
|
||||
constexpr uint32_t kFramerateFps = 5;
|
||||
@ -90,9 +93,8 @@ class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
|
||||
EXPECT_EQ(sum, actual.get_sum_bps());
|
||||
}
|
||||
|
||||
void CreateAllocator(bool legacy_conference_mode = false) {
|
||||
allocator_.reset(new SimulcastRateAllocator(codec_));
|
||||
allocator_->SetLegacyConferenceMode(legacy_conference_mode);
|
||||
void CreateAllocator(Environment env = CreateEnvironment()) {
|
||||
allocator_ = std::make_unique<SimulcastRateAllocator>(env, codec_);
|
||||
}
|
||||
|
||||
void SetupCodec3SL3TL(const std::vector<bool>& active_streams) {
|
||||
@ -298,11 +300,11 @@ TEST_F(SimulcastRateAllocatorTest, Regular3TLTemporalRateAllocation) {
|
||||
}
|
||||
|
||||
TEST_F(SimulcastRateAllocatorTest, BaseHeavy3TLTemporalRateAllocation) {
|
||||
test::ScopedFieldTrials field_trials(
|
||||
ExplicitKeyValueConfig field_trials(
|
||||
"WebRTC-UseBaseHeavyVP8TL3RateAllocation/Enabled/");
|
||||
|
||||
SetupCodec3SL3TL({true, true, true});
|
||||
CreateAllocator();
|
||||
CreateAllocator(CreateEnvironment(&field_trials));
|
||||
|
||||
const VideoBitrateAllocation alloc = GetAllocation(kMinBitrateKbps);
|
||||
// 60/20/20.
|
||||
@ -583,13 +585,13 @@ TEST_F(SimulcastRateAllocatorTest, NonConferenceModeScreenshare) {
|
||||
}
|
||||
|
||||
TEST_F(SimulcastRateAllocatorTest, StableRate) {
|
||||
webrtc::test::ScopedFieldTrials field_trials(
|
||||
ExplicitKeyValueConfig field_trials(
|
||||
"WebRTC-StableTargetRate/"
|
||||
"enabled:true,"
|
||||
"video_hysteresis_factor:1.1/");
|
||||
|
||||
SetupCodec3SL3TL({true, true, true});
|
||||
CreateAllocator();
|
||||
CreateAllocator(CreateEnvironment(&field_trials));
|
||||
|
||||
// Let the volatile rate always be be enough for all streams, in this test we
|
||||
// are only interested in how the stable rate affects enablement.
|
||||
@ -685,7 +687,8 @@ INSTANTIATE_TEST_SUITE_P(ScreenshareTest,
|
||||
|
||||
TEST_P(ScreenshareRateAllocationTest, ConferenceBitrateBelowTl0) {
|
||||
SetupConferenceScreenshare(GetParam());
|
||||
CreateAllocator(true);
|
||||
CreateAllocator();
|
||||
allocator_->SetLegacyConferenceMode(true);
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
@ -700,7 +703,8 @@ TEST_P(ScreenshareRateAllocationTest, ConferenceBitrateBelowTl0) {
|
||||
|
||||
TEST_P(ScreenshareRateAllocationTest, ConferenceBitrateAboveTl0) {
|
||||
SetupConferenceScreenshare(GetParam());
|
||||
CreateAllocator(true);
|
||||
CreateAllocator();
|
||||
allocator_->SetLegacyConferenceMode(true);
|
||||
|
||||
uint32_t target_bitrate_kbps =
|
||||
(kLegacyScreenshareTargetBitrateKbps + kLegacyScreenshareMaxBitrateKbps) /
|
||||
@ -721,7 +725,8 @@ TEST_P(ScreenshareRateAllocationTest, ConferenceBitrateAboveTl0) {
|
||||
TEST_F(ScreenshareRateAllocationTest, ConferenceBitrateAboveTl1) {
|
||||
// This test is only for the non-simulcast case.
|
||||
SetupConferenceScreenshare(false);
|
||||
CreateAllocator(true);
|
||||
CreateAllocator();
|
||||
allocator_->SetLegacyConferenceMode(true);
|
||||
|
||||
VideoBitrateAllocation allocation =
|
||||
allocator_->Allocate(VideoBitrateAllocationParameters(
|
||||
|
||||
@ -259,10 +259,10 @@ SimulcastTestFixtureImpl::SimulcastTestFixtureImpl(
|
||||
std::unique_ptr<VideoEncoderFactory> encoder_factory,
|
||||
std::unique_ptr<VideoDecoderFactory> decoder_factory,
|
||||
SdpVideoFormat video_format)
|
||||
: codec_type_(PayloadStringToCodecType(video_format.name)) {
|
||||
Environment env = CreateEnvironment();
|
||||
encoder_ = encoder_factory->Create(env, video_format);
|
||||
decoder_ = decoder_factory->Create(env, video_format);
|
||||
: env_(CreateEnvironment()),
|
||||
codec_type_(PayloadStringToCodecType(video_format.name)) {
|
||||
encoder_ = encoder_factory->Create(env_, video_format);
|
||||
decoder_ = decoder_factory->Create(env_, video_format);
|
||||
SetUpCodec((codec_type_ == kVideoCodecVP8 || codec_type_ == kVideoCodecH264)
|
||||
? kDefaultTemporalLayerProfile
|
||||
: kNoTemporalLayerProfile);
|
||||
@ -294,7 +294,7 @@ void SimulcastTestFixtureImpl::SetUpCodec(const int* temporal_layer_profile) {
|
||||
}
|
||||
|
||||
void SimulcastTestFixtureImpl::SetUpRateAllocator() {
|
||||
rate_allocator_.reset(new SimulcastRateAllocator(settings_));
|
||||
rate_allocator_ = std::make_unique<SimulcastRateAllocator>(env_, settings_);
|
||||
}
|
||||
|
||||
void SimulcastTestFixtureImpl::SetRates(uint32_t bitrate_kbps, uint32_t fps) {
|
||||
|
||||
@ -78,6 +78,7 @@ class SimulcastTestFixtureImpl final : public SimulcastTestFixture {
|
||||
int num_spatial_layers);
|
||||
void SwitchingToOneStream(int width, int height);
|
||||
|
||||
const Environment env_;
|
||||
std::unique_ptr<VideoEncoder> encoder_;
|
||||
MockEncodedImageCallback encoder_callback_;
|
||||
std::unique_ptr<VideoDecoder> decoder_;
|
||||
|
||||
@ -4781,7 +4781,7 @@ TEST_F(VideoStreamEncoderTest, ReportsVideoBitrateAllocation) {
|
||||
|
||||
const int kDefaultFps = 30;
|
||||
const VideoBitrateAllocation expected_bitrate =
|
||||
SimulcastRateAllocator(fake_encoder_.config())
|
||||
SimulcastRateAllocator(env_, fake_encoder_.config())
|
||||
.Allocate(VideoBitrateAllocationParameters(kLowTargetBitrate.bps(),
|
||||
kDefaultFps));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user