Revert "Replace usage of old SetRates/SetRateAllocation methods"

This reverts commit 7ac0d5f348f0b956089c4ed65c46e65bac125508.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> 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}

TBR=brandtr@webrtc.org,sakal@webrtc.org,nisse@webrtc.org,sprang@webrtc.org,perkj@webrtc.org

Change-Id: I576760b584e3f258013b0279c0c173c895bbb37e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:10481
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132561
Reviewed-by: Minyue Li <minyue@webrtc.org>
Commit-Queue: Minyue Li <minyue@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27559}
This commit is contained in:
Minyue Li
2019-04-11 10:50:19 +00:00
committed by Commit Bot
parent 7061e51b48
commit 7ddef1af88
41 changed files with 389 additions and 430 deletions

View File

@ -306,8 +306,7 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
SimulcastRateAllocator init_allocator(codec_);
VideoBitrateAllocation allocation = init_allocator.GetAllocation(
codec_.startBitrate * 1000, codec_.maxFramerate);
SetRates(RateControlParameters(allocation, codec_.maxFramerate));
return WEBRTC_VIDEO_CODEC_OK;
return SetRateAllocation(allocation, codec_.maxFramerate);
}
int32_t H264EncoderImpl::Release() {
@ -332,40 +331,36 @@ int32_t H264EncoderImpl::RegisterEncodeCompleteCallback(
return WEBRTC_VIDEO_CODEC_OK;
}
void H264EncoderImpl::SetRates(const RateControlParameters& parameters) {
if (encoders_.empty()) {
RTC_LOG(LS_WARNING) << "SetRates() while uninitialized.";
return;
}
int32_t H264EncoderImpl::SetRateAllocation(
const VideoBitrateAllocation& bitrate,
uint32_t new_framerate) {
if (encoders_.empty())
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
if (parameters.framerate_fps < 1.0) {
RTC_LOG(LS_WARNING) << "Invalid frame rate: " << parameters.framerate_fps;
return;
}
if (new_framerate < 1)
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
if (parameters.bitrate.get_sum_bps() == 0) {
if (bitrate.get_sum_bps() == 0) {
// Encoder paused, turn off all encoding.
for (size_t i = 0; i < configurations_.size(); ++i)
configurations_[i].SetStreamState(false);
return;
return WEBRTC_VIDEO_CODEC_OK;
}
// At this point, bitrate allocation should already match codec settings.
if (codec_.maxBitrate > 0)
RTC_DCHECK_LE(parameters.bitrate.get_sum_kbps(), codec_.maxBitrate);
RTC_DCHECK_GE(parameters.bitrate.get_sum_kbps(), codec_.minBitrate);
RTC_DCHECK_LE(bitrate.get_sum_kbps(), codec_.maxBitrate);
RTC_DCHECK_GE(bitrate.get_sum_kbps(), codec_.minBitrate);
if (codec_.numberOfSimulcastStreams > 0)
RTC_DCHECK_GE(parameters.bitrate.get_sum_kbps(),
codec_.simulcastStream[0].minBitrate);
RTC_DCHECK_GE(bitrate.get_sum_kbps(), codec_.simulcastStream[0].minBitrate);
codec_.maxFramerate = static_cast<uint32_t>(parameters.framerate_fps);
codec_.maxFramerate = new_framerate;
size_t stream_idx = encoders_.size() - 1;
for (size_t i = 0; i < encoders_.size(); ++i, --stream_idx) {
// Update layer config.
configurations_[i].target_bps =
parameters.bitrate.GetSpatialLayerSum(stream_idx);
configurations_[i].max_frame_rate = parameters.framerate_fps;
configurations_[i].target_bps = bitrate.GetSpatialLayerSum(stream_idx);
configurations_[i].max_frame_rate = static_cast<float>(new_framerate);
if (configurations_[i].target_bps) {
configurations_[i].SetStreamState(true);
@ -382,6 +377,8 @@ void H264EncoderImpl::SetRates(const RateControlParameters& parameters) {
configurations_[i].SetStreamState(false);
}
}
return WEBRTC_VIDEO_CODEC_OK;
}
int32_t H264EncoderImpl::Encode(

View File

@ -61,7 +61,8 @@ class H264EncoderImpl : public H264Encoder {
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) override;
void SetRates(const RateControlParameters& parameters) override;
int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate) override;
// The result of encoding - an EncodedImage and RTPFragmentationHeader - are
// passed to the encode complete callback.

View File

@ -45,7 +45,8 @@ class MultiplexEncoderAdapter : public VideoEncoder {
int Encode(const VideoFrame& input_image,
const std::vector<VideoFrameType>* frame_types) override;
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
void SetRates(const RateControlParameters& parameters) override;
int SetRateAllocation(const VideoBitrateAllocation& bitrate,
uint32_t new_framerate) override;
int Release() override;
EncoderInfo GetEncoderInfo() const override;

View File

@ -216,21 +216,23 @@ int MultiplexEncoderAdapter::RegisterEncodeCompleteCallback(
return WEBRTC_VIDEO_CODEC_OK;
}
void MultiplexEncoderAdapter::SetRates(
const RateControlParameters& parameters) {
VideoBitrateAllocation bitrate_allocation(parameters.bitrate);
int MultiplexEncoderAdapter::SetRateAllocation(
const VideoBitrateAllocation& bitrate,
uint32_t framerate) {
VideoBitrateAllocation bitrate_allocation(bitrate);
bitrate_allocation.SetBitrate(
0, 0, parameters.bitrate.GetBitrate(0, 0) - augmenting_data_size_);
0, 0, bitrate.GetBitrate(0, 0) - augmenting_data_size_);
for (auto& encoder : encoders_) {
// TODO(emircan): |framerate| is used to calculate duration in encoder
// instances. We report the total frame rate to keep real time for now.
// Remove this after refactoring duration logic.
encoder->SetRates(RateControlParameters(
const int rv = encoder->SetRateAllocation(
bitrate_allocation,
static_cast<uint32_t>(encoders_.size() * parameters.framerate_fps),
parameters.bandwidth_allocation -
DataRate::bps(augmenting_data_size_)));
static_cast<uint32_t>(encoders_.size()) * framerate);
if (rv)
return rv;
}
return WEBRTC_VIDEO_CODEC_OK;
}
int MultiplexEncoderAdapter::Release() {

View File

@ -300,8 +300,10 @@ void VideoProcessor::SetRates(size_t bitrate_kbps, size_t framerate_fps) {
framerate_fps_ = static_cast<uint32_t>(framerate_fps);
bitrate_allocation_ = bitrate_allocator_->GetAllocation(
static_cast<uint32_t>(bitrate_kbps * 1000), framerate_fps_);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation_, static_cast<double>(framerate_fps_)));
const int set_rates_result =
encoder_->SetRateAllocation(bitrate_allocation_, framerate_fps_);
RTC_DCHECK_GE(set_rates_result, 0)
<< "Failed to update encoder with new rate " << bitrate_kbps << ".";
}
int32_t VideoProcessor::VideoProcessorDecodeCompleteCallback::Decoded(

View File

@ -25,10 +25,7 @@
#include "test/testsupport/mock/mock_frame_reader.h"
using ::testing::_;
using ::testing::AllOf;
using ::testing::Field;
using ::testing::Property;
using ::testing::ResultOf;
using ::testing::Return;
namespace webrtc {
@ -99,11 +96,9 @@ TEST_F(VideoProcessorTest, InitRelease) {
TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
const int kBitrateKbps = 456;
const int kFramerateFps = 31;
EXPECT_CALL(
encoder_mock_,
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kFramerateFps))))
.Times(1);
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kFramerateFps))
.Times(1)
.WillOnce(Return(0));
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
EXPECT_CALL(frame_reader_mock_, ReadFrame())
@ -127,11 +122,9 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
const int kBitrateKbps = 456;
const int kStartFramerateFps = 27;
const int kStartTimestamp = 90000 / kStartFramerateFps;
EXPECT_CALL(
encoder_mock_,
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kStartFramerateFps))))
.Times(1);
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kStartFramerateFps))
.Times(1)
.WillOnce(Return(0));
q_.SendTask(
[=] { video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
@ -143,11 +136,9 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
q_.SendTask([this] { video_processor_->ProcessFrame(); });
const int kNewFramerateFps = 13;
EXPECT_CALL(
encoder_mock_,
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kNewFramerateFps))))
.Times(1);
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kNewFramerateFps))
.Times(1)
.WillOnce(Return(0));
q_.SendTask(
[=] { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); });
@ -162,32 +153,21 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
}
TEST_F(VideoProcessorTest, SetRates) {
const uint32_t kBitrateKbps = 123;
const int kBitrateKbps = 123;
const int kFramerateFps = 17;
EXPECT_CALL(
encoder_mock_,
SetRates(AllOf(ResultOf(
[](const VideoEncoder::RateControlParameters& params) {
return params.bitrate.get_sum_kbps();
},
kBitrateKbps),
Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kFramerateFps)))))
EXPECT_CALL(encoder_mock_,
SetRateAllocation(
Property(&VideoBitrateAllocation::get_sum_kbps, kBitrateKbps),
kFramerateFps))
.Times(1);
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
const uint32_t kNewBitrateKbps = 456;
const int kNewBitrateKbps = 456;
const int kNewFramerateFps = 34;
EXPECT_CALL(
encoder_mock_,
SetRates(AllOf(ResultOf(
[](const VideoEncoder::RateControlParameters& params) {
return params.bitrate.get_sum_kbps();
},
kNewBitrateKbps),
Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kNewFramerateFps)))))
EXPECT_CALL(encoder_mock_,
SetRateAllocation(Property(&VideoBitrateAllocation::get_sum_kbps,
kNewBitrateKbps),
kNewFramerateFps))
.Times(1);
q_.SendTask(
[=] { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });

View File

@ -36,7 +36,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/experiments/field_trial_parser.h"
#include "rtc_base/experiments/field_trial_units.h"
#include "rtc_base/logging.h"
#include "rtc_base/trace_event.h"
#include "system_wrappers/include/field_trial.h"
#include "third_party/libyuv/include/libyuv/scale.h"
@ -248,40 +247,33 @@ int LibvpxVp8Encoder::Release() {
return ret_val;
}
void LibvpxVp8Encoder::SetRates(const RateControlParameters& parameters) {
if (!inited_) {
RTC_LOG(LS_WARNING) << "SetRates() while not initialize";
return;
}
int LibvpxVp8Encoder::SetRateAllocation(const VideoBitrateAllocation& bitrate,
uint32_t new_framerate) {
if (!inited_)
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
if (encoders_[0].err) {
RTC_LOG(LS_WARNING) << "Encoder in error state.";
return;
}
if (encoders_[0].err)
return WEBRTC_VIDEO_CODEC_ERROR;
if (parameters.framerate_fps < 1.0) {
RTC_LOG(LS_WARNING) << "Unsupported framerate (must be >= 1.0): "
<< parameters.framerate_fps;
return;
}
if (new_framerate < 1)
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
if (parameters.bitrate.get_sum_bps() == 0) {
if (bitrate.get_sum_bps() == 0) {
// Encoder paused, turn off all encoding.
const int num_streams = static_cast<size_t>(encoders_.size());
for (int i = 0; i < num_streams; ++i)
SetStreamState(false, i);
return;
return WEBRTC_VIDEO_CODEC_OK;
}
// At this point, bitrate allocation should already match codec settings.
if (codec_.maxBitrate > 0)
RTC_DCHECK_LE(parameters.bitrate.get_sum_kbps(), codec_.maxBitrate);
RTC_DCHECK_GE(parameters.bitrate.get_sum_kbps(), codec_.minBitrate);
RTC_DCHECK_LE(bitrate.get_sum_kbps(), codec_.maxBitrate);
RTC_DCHECK_GE(bitrate.get_sum_kbps(), codec_.minBitrate);
if (codec_.numberOfSimulcastStreams > 0)
RTC_DCHECK_GE(parameters.bitrate.get_sum_kbps(),
codec_.simulcastStream[0].minBitrate);
RTC_DCHECK_GE(bitrate.get_sum_kbps(), codec_.simulcastStream[0].minBitrate);
codec_.maxFramerate = static_cast<uint32_t>(parameters.framerate_fps + 0.5);
codec_.maxFramerate = new_framerate;
if (encoders_.size() > 1) {
// If we have more than 1 stream, reduce the qp_max for the low resolution
@ -290,7 +282,7 @@ void LibvpxVp8Encoder::SetRates(const RateControlParameters& parameters) {
// above some threshold (base temporal layer is down to 1/4 for 3 layers).
// We may want to condition this on bitrate later.
if (rate_control_settings_.Vp8BoostBaseLayerQuality() &&
parameters.framerate_fps > 20.0) {
new_framerate > 20) {
configurations_[encoders_.size() - 1].rc_max_quantizer = 45;
} else {
// Go back to default value set in InitEncode.
@ -301,7 +293,7 @@ void LibvpxVp8Encoder::SetRates(const RateControlParameters& parameters) {
size_t stream_idx = encoders_.size() - 1;
for (size_t i = 0; i < encoders_.size(); ++i, --stream_idx) {
unsigned int target_bitrate_kbps =
parameters.bitrate.GetSpatialLayerSum(stream_idx) / 1000;
bitrate.GetSpatialLayerSum(stream_idx) / 1000;
bool send_stream = target_bitrate_kbps > 0;
if (send_stream || encoders_.size() > 1)
@ -310,19 +302,18 @@ void LibvpxVp8Encoder::SetRates(const RateControlParameters& parameters) {
configurations_[i].rc_target_bitrate = target_bitrate_kbps;
if (send_stream) {
frame_buffer_controller_->OnRatesUpdated(
stream_idx, parameters.bitrate.GetTemporalLayerAllocation(stream_idx),
static_cast<int>(parameters.framerate_fps + 0.5));
stream_idx, bitrate.GetTemporalLayerAllocation(stream_idx),
new_framerate);
}
UpdateVpxConfiguration(stream_idx, frame_buffer_controller_.get(),
&configurations_[i]);
vpx_codec_err_t err =
libvpx_->codec_enc_config_set(&encoders_[i], &configurations_[i]);
if (err != VPX_CODEC_OK) {
RTC_LOG(LS_WARNING) << "Error configuring codec, error code: " << err;
if (libvpx_->codec_enc_config_set(&encoders_[i], &configurations_[i])) {
return WEBRTC_VIDEO_CODEC_ERROR;
}
}
return WEBRTC_VIDEO_CODEC_OK;
}
void LibvpxVp8Encoder::OnPacketLossRateUpdate(float packet_loss_rate) {

View File

@ -54,7 +54,8 @@ class LibvpxVp8Encoder : public VideoEncoder {
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
void SetRates(const RateControlParameters& parameters) override;
int SetRateAllocation(const VideoBitrateAllocation& bitrate,
uint32_t new_framerate) override;
void OnPacketLossRateUpdate(float packet_loss_rate) override;

View File

@ -110,23 +110,20 @@ class TestVp8Impl : public VideoCodecUnitTest {
}
};
TEST_F(TestVp8Impl, SetRates) {
auto* const vpx = new NiceMock<MockLibvpxVp8Interface>();
LibvpxVp8Encoder encoder((std::unique_ptr<LibvpxInterface>(vpx)));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder.InitEncode(&codec_settings_, 1, 1000));
TEST_F(TestVp8Impl, SetRateAllocation) {
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
const uint32_t kBitrateBps = 300000;
const int kBitrateBps = 300000;
VideoBitrateAllocation bitrate_allocation;
bitrate_allocation.SetBitrate(0, 0, kBitrateBps);
EXPECT_CALL(*vpx, codec_enc_config_set(_, _))
.WillOnce(
Invoke([&](vpx_codec_ctx_t* ctx, const vpx_codec_enc_cfg_t* cfg) {
EXPECT_EQ(cfg->rc_target_bitrate, kBitrateBps / 1000);
return VPX_CODEC_OK;
}));
encoder.SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, static_cast<double>(codec_settings_.maxFramerate)));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
}
TEST_F(TestVp8Impl, EncodeFrameAndRelease) {
@ -444,8 +441,7 @@ TEST_F(TestVp8Impl, DontDropKeyframes) {
VideoBitrateAllocation bitrate_allocation;
// Bitrate only enough for TL0.
bitrate_allocation.SetBitrate(0, 0, 200000);
encoder_->SetRates(
VideoEncoder::RateControlParameters(bitrate_allocation, 5.0));
encoder_->SetRateAllocation(bitrate_allocation, 5);
EncodedImage encoded_frame;
CodecSpecificInfo codec_specific_info;

View File

@ -375,8 +375,9 @@ TEST_F(TestVp9Impl, EnableDisableSpatialLayers) {
bitrate_allocation.SetBitrate(
sl_idx, 0,
codec_settings_.spatialLayers[sl_idx].targetBitrate * 1000 * 2);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
for (size_t frame_num = 0; frame_num < num_frames_to_encode; ++frame_num) {
SetWaitForEncodedFramesThreshold(sl_idx + 1);
@ -393,8 +394,9 @@ TEST_F(TestVp9Impl, EnableDisableSpatialLayers) {
for (size_t i = 0; i < num_spatial_layers - 1; ++i) {
const size_t sl_idx = num_spatial_layers - i - 1;
bitrate_allocation.SetBitrate(sl_idx, 0, 0);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
for (size_t frame_num = 0; frame_num < num_frames_to_encode; ++frame_num) {
SetWaitForEncodedFramesThreshold(sl_idx);
@ -424,8 +426,9 @@ TEST_F(TestVp9Impl, EndOfPicture) {
0, 0, codec_settings_.spatialLayers[0].targetBitrate * 1000);
bitrate_allocation.SetBitrate(
1, 0, codec_settings_.spatialLayers[1].targetBitrate * 1000);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
SetWaitForEncodedFramesThreshold(2);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->Encode(*NextInputFrame(), nullptr));
@ -439,8 +442,9 @@ TEST_F(TestVp9Impl, EndOfPicture) {
// Encode only base layer. Check that end-of-superframe flag is
// set on base layer frame.
bitrate_allocation.SetBitrate(1, 0, 0);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
0 /* max payload size (unused) */));
@ -475,8 +479,9 @@ TEST_F(TestVp9Impl, InterLayerPred) {
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
0 /* max payload size (unused) */));
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
SetWaitForEncodedFramesThreshold(2);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
@ -545,8 +550,9 @@ TEST_F(TestVp9Impl,
bitrate_allocation.SetBitrate(
sl_idx, 0,
codec_settings_.spatialLayers[sl_idx].targetBitrate * 1000);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
for (size_t frame_num = 0; frame_num < num_frames_to_encode;
++frame_num) {
@ -604,8 +610,9 @@ TEST_F(TestVp9Impl,
bitrate_allocation.SetBitrate(
sl_idx, 0,
codec_settings_.spatialLayers[sl_idx].targetBitrate * 1000);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
for (size_t frame_num = 0; frame_num < num_frames_to_encode;
++frame_num) {
@ -661,8 +668,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerInTheSameGof) {
1, 0, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
bitrate_allocation.SetBitrate(
1, 1, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
std::vector<EncodedImage> encoded_frame;
std::vector<CodecSpecificInfo> codec_specific_info;
@ -679,8 +687,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerInTheSameGof) {
// Disable SL1 layer.
bitrate_allocation.SetBitrate(1, 0, 0);
bitrate_allocation.SetBitrate(1, 1, 0);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode 1 frame.
SetWaitForEncodedFramesThreshold(1);
@ -697,8 +706,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerInTheSameGof) {
1, 0, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
bitrate_allocation.SetBitrate(
1, 1, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode 1 frame.
SetWaitForEncodedFramesThreshold(2);
@ -736,8 +746,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerAccrossGof) {
1, 0, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
bitrate_allocation.SetBitrate(
1, 1, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
std::vector<EncodedImage> encoded_frame;
std::vector<CodecSpecificInfo> codec_specific_info;
@ -754,8 +765,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerAccrossGof) {
// Disable SL1 layer.
bitrate_allocation.SetBitrate(1, 0, 0);
bitrate_allocation.SetBitrate(1, 1, 0);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode 11 frames. More than Gof length 2, and odd to end at TL1 frame.
for (int i = 0; i < 11; ++i) {
@ -775,8 +787,9 @@ TEST_F(TestVp9Impl, EnablingDisablingUpperLayerAccrossGof) {
1, 0, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
bitrate_allocation.SetBitrate(
1, 1, codec_settings_.spatialLayers[1].targetBitrate * 1000 / 2);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode 1 frame.
SetWaitForEncodedFramesThreshold(2);
@ -822,8 +835,9 @@ TEST_F(TestVp9Impl, EnablingNewLayerIsDelayedInScreenshareAndAddsSsInfo) {
bitrate_allocation.SetBitrate(
sl_idx, 0, codec_settings_.spatialLayers[sl_idx].targetBitrate * 1000);
}
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode enough frames to force drop due to framerate capping.
for (size_t frame_num = 0; frame_num < num_frames_to_encode_before_drop;
@ -841,8 +855,9 @@ TEST_F(TestVp9Impl, EnablingNewLayerIsDelayedInScreenshareAndAddsSsInfo) {
num_spatial_layers - 1, 0,
codec_settings_.spatialLayers[num_spatial_layers - 1].targetBitrate *
1000);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
for (size_t frame_num = 0; frame_num < num_dropped_frames; ++frame_num) {
SetWaitForEncodedFramesThreshold(1);
@ -898,8 +913,9 @@ TEST_F(TestVp9Impl, RemovingLayerIsNotDelayedInScreenshareAndAddsSsInfo) {
bitrate_allocation.SetBitrate(
sl_idx, 0, codec_settings_.spatialLayers[sl_idx].targetBitrate * 1000);
}
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Encode enough frames to force drop due to framerate capping.
for (size_t frame_num = 0; frame_num < num_frames_to_encode_before_drop;
@ -928,8 +944,9 @@ TEST_F(TestVp9Impl, RemovingLayerIsNotDelayedInScreenshareAndAddsSsInfo) {
// Disable the last layer.
bitrate_allocation.SetBitrate(num_spatial_layers - 1, 0, 0);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Still expected to drop first layer. Last layer has to be disable also.
for (size_t frame_num = num_dropped_frames - 2;
@ -985,8 +1002,9 @@ TEST_F(TestVp9Impl, DisableNewLayerInVideoDelaysSsInfoTillTL0) {
num_temporal_layers);
}
}
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
std::vector<EncodedImage> encoded_frames;
std::vector<CodecSpecificInfo> codec_specific_info;
@ -1002,8 +1020,9 @@ TEST_F(TestVp9Impl, DisableNewLayerInVideoDelaysSsInfoTillTL0) {
for (size_t tl_idx = 0; tl_idx < num_temporal_layers; ++tl_idx) {
bitrate_allocation.SetBitrate(num_spatial_layers - 1, tl_idx, 0);
}
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
// Next is TL1 frame. The last layer is disabled immediately, but SS structure
// is not provided here.
@ -1040,8 +1059,9 @@ TEST_F(TestVp9Impl,
VideoBitrateAllocation bitrate_allocation;
bitrate_allocation.SetBitrate(
0, 0, codec_settings_.spatialLayers[0].targetBitrate * 1000);
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->Encode(*NextInputFrame(), nullptr));
EncodedImage encoded_frame;
@ -1309,8 +1329,9 @@ TEST_F(TestVp9ImplFrameDropping, DifferentFrameratePerSpatialLayer) {
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
0 /* max payload size (unused) */));
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_settings_.maxFramerate));
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation,
codec_settings_.maxFramerate));
VideoFrame* input_frame = NextInputFrame();
for (size_t frame_num = 0; frame_num < num_input_frames; ++frame_num) {
@ -1363,8 +1384,9 @@ TEST_F(TestVp9ImplFrameDropping, LayerMaxFramerateIsCappedByCodecMaxFramerate) {
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
0 /* max payload size (unused) */));
encoder_->SetRates(VideoEncoder::RateControlParameters(
bitrate_allocation, codec_max_framerate_fps));
EXPECT_EQ(
WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation, codec_max_framerate_fps));
VideoFrame* input_frame = NextInputFrame();
for (size_t frame_num = 0; frame_num < num_input_frames; ++frame_num) {

View File

@ -309,33 +309,29 @@ bool VP9EncoderImpl::SetSvcRates(
return true;
}
void VP9EncoderImpl::SetRates(const RateControlParameters& parameters) {
int VP9EncoderImpl::SetRateAllocation(
const VideoBitrateAllocation& bitrate_allocation,
uint32_t frame_rate) {
if (!inited_) {
RTC_LOG(LS_WARNING) << "SetRates() calll while uninitialzied.";
return;
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
}
if (encoder_->err) {
RTC_LOG(LS_WARNING) << "Encoder in error state: " << encoder_->err;
return;
return WEBRTC_VIDEO_CODEC_ERROR;
}
if (parameters.framerate_fps < 1.0) {
RTC_LOG(LS_WARNING) << "Unsupported framerate: "
<< parameters.framerate_fps;
return;
if (frame_rate < 1) {
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
// Update bit rate
if (codec_.maxBitrate > 0 &&
parameters.bitrate.get_sum_kbps() > codec_.maxBitrate) {
RTC_LOG(LS_WARNING) << "Target bitrate exceeds maximum: "
<< parameters.bitrate.get_sum_kbps() << " vs "
<< codec_.maxBitrate;
return;
bitrate_allocation.get_sum_kbps() > codec_.maxBitrate) {
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
codec_.maxFramerate = static_cast<uint32_t>(parameters.framerate_fps + 0.5);
requested_bitrate_allocation_ = parameters.bitrate;
codec_.maxFramerate = frame_rate;
return;
requested_bitrate_allocation_ = bitrate_allocation;
return WEBRTC_VIDEO_CODEC_OK;
}
int VP9EncoderImpl::InitEncode(const VideoCodec* inst,

View File

@ -48,7 +48,8 @@ class VP9EncoderImpl : public VP9Encoder {
int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override;
void SetRates(const RateControlParameters& parameters) override;
int SetRateAllocation(const VideoBitrateAllocation& bitrate_allocation,
uint32_t frame_rate) override;
EncoderInfo GetEncoderInfo() const override;