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