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:
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user