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

@ -104,8 +104,7 @@ class MediaCodecVideoEncoder : public VideoEncoder {
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) override;
int32_t Release() override;
int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation,
uint32_t frame_rate) override;
void SetRates(const RateControlParameters& parameters) override;
EncoderInfo GetEncoderInfo() const override;
// Fills the input buffer with data from the buffers passed as parameters.
@ -900,17 +899,16 @@ int32_t MediaCodecVideoEncoder::Release() {
return WEBRTC_VIDEO_CODEC_OK;
}
int32_t MediaCodecVideoEncoder::SetRateAllocation(
const VideoBitrateAllocation& rate_allocation,
uint32_t frame_rate) {
void MediaCodecVideoEncoder::SetRates(const RateControlParameters& parameters) {
RTC_DCHECK_RUN_ON(&encoder_queue_checker_);
const uint32_t new_bit_rate = rate_allocation.get_sum_kbps();
const uint32_t new_bit_rate = parameters.bitrate.get_sum_kbps();
if (sw_fallback_required_)
return WEBRTC_VIDEO_CODEC_OK;
return;
uint32_t frame_rate = static_cast<uint32_t>(parameters.framerate_fps + 0.5);
frame_rate =
(frame_rate < MAX_ALLOWED_VIDEO_FPS) ? frame_rate : MAX_ALLOWED_VIDEO_FPS;
if (last_set_bitrate_kbps_ == new_bit_rate && last_set_fps_ == frame_rate) {
return WEBRTC_VIDEO_CODEC_OK;
return;
}
JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedLocalRefFrame local_ref_frame(jni);
@ -926,10 +924,7 @@ int32_t MediaCodecVideoEncoder::SetRateAllocation(
rtc::dchecked_cast<int>(last_set_fps_));
if (CheckException(jni) || !ret) {
ProcessHWError(true /* reset_if_fallback_unavailable */);
return sw_fallback_required_ ? WEBRTC_VIDEO_CODEC_OK
: WEBRTC_VIDEO_CODEC_ERROR;
}
return WEBRTC_VIDEO_CODEC_OK;
}
VideoEncoder::EncoderInfo MediaCodecVideoEncoder::GetEncoderInfo() const {

View File

@ -146,16 +146,15 @@ int32_t VideoEncoderWrapper::Encode(
return HandleReturnCode(jni, ret, "encode");
}
int32_t VideoEncoderWrapper::SetRateAllocation(
const VideoBitrateAllocation& allocation,
uint32_t framerate) {
void VideoEncoderWrapper::SetRates(const RateControlParameters& parameters) {
JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedJavaLocalRef<jobject> j_bitrate_allocation =
ToJavaBitrateAllocation(jni, allocation);
ToJavaBitrateAllocation(jni, parameters.bitrate);
ScopedJavaLocalRef<jobject> ret = Java_VideoEncoder_setRateAllocation(
jni, encoder_, j_bitrate_allocation, (jint)framerate);
return HandleReturnCode(jni, ret, "setRateAllocation");
jni, encoder_, j_bitrate_allocation,
(jint)(parameters.framerate_fps + 0.5));
HandleReturnCode(jni, ret, "setRateAllocation");
}
VideoEncoder::EncoderInfo VideoEncoderWrapper::GetEncoderInfo() const {

View File

@ -44,8 +44,7 @@ class VideoEncoderWrapper : public VideoEncoder {
int32_t Encode(const VideoFrame& frame,
const std::vector<VideoFrameType>* frame_types) override;
int32_t SetRateAllocation(const VideoBitrateAllocation& allocation,
uint32_t framerate) override;
void SetRates(const RateControlParameters& parameters) override;
EncoderInfo GetEncoderInfo() const override;