Replace usage of old SetRates/SetRateAllocation methods

This rather large CL replaces all relevant usage of the old
VideoEncoder::SetRates()/SetRateAllocation() methods in WebRTC.
API is unchanged to allow downstream projects to update without
breakage.

Bug: webrtc:10481
Change-Id: Iab8f292ce6be6c3f5056a239d26361962b14bb38
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131949
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27554}
This commit is contained in:
Erik Språng
2019-04-11 09:06:13 +02:00
committed by Commit Bot
parent 71ec39e355
commit 7ac0d5f348
41 changed files with 430 additions and 389 deletions

View File

@ -114,10 +114,8 @@ class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test {
return WEBRTC_VIDEO_CODEC_OK;
}
int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate) override {
void SetRates(const RateControlParameters& parameters) override {
++set_rates_count_;
return WEBRTC_VIDEO_CODEC_OK;
}
EncoderInfo GetEncoderInfo() const override {
@ -205,10 +203,8 @@ void VideoEncoderSoftwareFallbackWrapperTest::UtilizeFallbackEncoder() {
fake_encoder_->init_encode_return_code_ = WEBRTC_VIDEO_CODEC_ERROR;
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
fallback_wrapper_->InitEncode(&codec_, kNumCores, kMaxPayloadSize));
EXPECT_EQ(
WEBRTC_VIDEO_CODEC_OK,
fallback_wrapper_->SetRateAllocation(
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
int callback_count = callback_.callback_count_;
int encode_count = fake_encoder_->encode_count_;
@ -226,10 +222,8 @@ void VideoEncoderSoftwareFallbackWrapperTest::FallbackFromEncodeRequest() {
codec_.VP8()->numberOfTemporalLayers = 1;
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
fallback_wrapper_->InitEncode(&codec_, 2, kMaxPayloadSize);
EXPECT_EQ(
WEBRTC_VIDEO_CODEC_OK,
fallback_wrapper_->SetRateAllocation(
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(300000, kFramerate), kFramerate));
EXPECT_EQ(1, fake_encoder_->init_encode_count_);
// Have the non-fallback encoder request a software fallback.
@ -302,7 +296,8 @@ TEST_F(VideoEncoderSoftwareFallbackWrapperTest,
SetRatesForwardedDuringFallback) {
UtilizeFallbackEncoder();
EXPECT_EQ(1, fake_encoder_->set_rates_count_);
fallback_wrapper_->SetRateAllocation(VideoBitrateAllocation(), 1);
fallback_wrapper_->SetRates(
VideoEncoder::RateControlParameters(VideoBitrateAllocation(), 1));
EXPECT_EQ(2, fake_encoder_->set_rates_count_);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_->Release());
}
@ -386,10 +381,9 @@ class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest {
}
void SetRateAllocation(uint32_t bitrate_kbps) {
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_->SetRateAllocation(
rate_allocator_->GetAllocation(
bitrate_kbps * 1000, kFramerate),
kFramerate));
fallback_wrapper_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(bitrate_kbps * 1000, kFramerate),
kFramerate));
}
void EncodeFrameAndVerifyLastName(const char* expected_name) {

View File

@ -106,6 +106,13 @@ VideoEncoder::RateControlParameters::RateControlParameters()
framerate_fps(0.0),
bandwidth_allocation(DataRate::Zero()) {}
VideoEncoder::RateControlParameters::RateControlParameters(
const VideoBitrateAllocation& bitrate,
double framerate_fps)
: bitrate(bitrate),
framerate_fps(framerate_fps),
bandwidth_allocation(DataRate::bps(bitrate.get_sum_bps())) {}
VideoEncoder::RateControlParameters::RateControlParameters(
const VideoBitrateAllocation& bitrate,
double framerate_fps,

View File

@ -195,6 +195,8 @@ class RTC_EXPORT VideoEncoder {
struct RateControlParameters {
RateControlParameters();
RateControlParameters(const VideoBitrateAllocation& bitrate,
double framerate_fps);
RateControlParameters(const VideoBitrateAllocation& bitrate,
double framerate_fps,
DataRate bandwidth_allocation);

View File

@ -88,8 +88,7 @@ class VideoEncoderSoftwareFallbackWrapper final : public VideoEncoder {
int32_t Release() override;
int32_t Encode(const VideoFrame& frame,
const std::vector<VideoFrameType>* frame_types) override;
int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate) override;
void SetRates(const RateControlParameters& parameters) override;
EncoderInfo GetEncoderInfo() const override;
private:
@ -122,10 +121,8 @@ class VideoEncoderSoftwareFallbackWrapper final : public VideoEncoder {
int32_t number_of_cores_;
size_t max_payload_size_;
// The last bitrate/framerate set, and a flag for noting they are set.
bool rates_set_;
VideoBitrateAllocation bitrate_allocation_;
uint32_t framerate_;
// The last rate control settings, if set.
absl::optional<RateControlParameters> rate_control_parameters_;
// The last channel parameters set, and a flag for noting they are set.
bool channel_parameters_set_;
@ -147,8 +144,6 @@ VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper(
std::unique_ptr<webrtc::VideoEncoder> hw_encoder)
: number_of_cores_(0),
max_payload_size_(0),
rates_set_(false),
framerate_(0),
channel_parameters_set_(false),
packet_loss_(0),
rtt_(0),
@ -181,8 +176,8 @@ bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() {
// Replay callback, rates, and channel parameters.
if (callback_)
fallback_encoder_->RegisterEncodeCompleteCallback(callback_);
if (rates_set_)
fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate_);
if (rate_control_parameters_)
fallback_encoder_->SetRates(*rate_control_parameters_);
// Since we're switching to the fallback encoder, Release the real encoder. It
// may be re-initialized via InitEncode later, and it will continue to get
@ -201,7 +196,7 @@ int32_t VideoEncoderSoftwareFallbackWrapper::InitEncode(
number_of_cores_ = number_of_cores;
max_payload_size_ = max_payload_size;
// Clear stored rate/channel parameters.
rates_set_ = false;
rate_control_parameters_ = absl::nullopt;
ValidateSettingsForForcedFallback();
// Try to reinit forced software codec if it is in use.
@ -264,16 +259,12 @@ int32_t VideoEncoderSoftwareFallbackWrapper::Encode(
return ret;
}
int32_t VideoEncoderSoftwareFallbackWrapper::SetRateAllocation(
const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate) {
rates_set_ = true;
bitrate_allocation_ = bitrate_allocation;
framerate_ = framerate;
int32_t ret = encoder_->SetRateAllocation(bitrate_allocation_, framerate);
void VideoEncoderSoftwareFallbackWrapper::SetRates(
const RateControlParameters& parameters) {
rate_control_parameters_ = parameters;
encoder_->SetRates(parameters);
if (use_fallback_encoder_)
return fallback_encoder_->SetRateAllocation(bitrate_allocation_, framerate);
return ret;
fallback_encoder_->SetRates(parameters);
}
VideoEncoder::EncoderInfo VideoEncoderSoftwareFallbackWrapper::GetEncoderInfo()