Skip to content

Commit

Permalink
Remove usage of deprecated VideoEncoder::SetRates() methods
Browse files Browse the repository at this point in the history
Bug: webrtc:10481
Change-Id: I481b63441ab225334958dfdf03bfe6de59fd72f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569108
Reviewed-by: Florent Castelli <orphis@chromium.org>
Reviewed-by: Lambros Lambrou <lambroslambrou@chromium.org>
Commit-Queue: Erik Språng <sprang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653795}
  • Loading branch information
Erik Språng authored and Commit Bot committed Apr 24, 2019
1 parent f147222 commit 9734cb7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
47 changes: 24 additions & 23 deletions content/renderer/media/webrtc/rtc_video_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ class RTCVideoEncoder::Impl
void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);

// Request encoding parameter change for the underlying encoder.
void RequestEncodingParametersChange(webrtc::VideoBitrateAllocation bitrate,
uint32_t framerate);
void RequestEncodingParametersChange(
const webrtc::VideoEncoder::RateControlParameters& parameters);

void RegisterEncodeCompleteCallback(base::WaitableEvent* async_waiter,
int32_t* async_retval,
Expand Down Expand Up @@ -400,39 +400,41 @@ void RTCVideoEncoder::Impl::UseOutputBitstreamBufferId(
}

void RTCVideoEncoder::Impl::RequestEncodingParametersChange(
webrtc::VideoBitrateAllocation bitrate,
uint32_t framerate) {
DVLOG(3) << __func__ << " bitrate=" << bitrate.ToString()
<< ", framerate=" << framerate;
const webrtc::VideoEncoder::RateControlParameters& parameters) {
DVLOG(3) << __func__ << " bitrate=" << parameters.bitrate.ToString()
<< ", framerate=" << parameters.framerate_fps;
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

// This is a workaround to zero being temporarily provided, as part of the
// initial setup, by WebRTC.
if (bitrate.get_sum_bps() == 0) {
bitrate.SetBitrate(0, 0, 1);
}
framerate = std::max(1u, framerate);

if (video_encoder_) {
media::VideoBitrateAllocation allocation;
if (parameters.bitrate.get_sum_bps() == 0) {
allocation.SetBitrate(0, 0, 1);
}
uint32_t framerate =
std::max(1u, static_cast<uint32_t>(parameters.framerate_fps + 0.5));

for (size_t spatial_id = 0;
spatial_id < media::VideoBitrateAllocation::kMaxSpatialLayers;
++spatial_id) {
for (size_t temporal_id = 0;
temporal_id < media::VideoBitrateAllocation::kMaxTemporalLayers;
++temporal_id) {
// TODO(sprang): Clean this up if/when webrtc struct moves to int.
uint32_t layer_bitrate = bitrate.GetBitrate(spatial_id, temporal_id);
uint32_t layer_bitrate =
parameters.bitrate.GetBitrate(spatial_id, temporal_id);
RTC_CHECK_LE(layer_bitrate,
static_cast<uint32_t>(std::numeric_limits<int>::max()));
if (!allocation.SetBitrate(spatial_id, temporal_id, layer_bitrate)) {
LOG(WARNING) << "Overflow in bitrate allocation: "
<< bitrate.ToString();
<< parameters.bitrate.ToString();
break;
}
}
}
DCHECK_EQ(allocation.GetSumBps(), static_cast<int>(bitrate.get_sum_bps()));
DCHECK_EQ(allocation.GetSumBps(),
static_cast<int>(parameters.bitrate.get_sum_bps()));
video_encoder_->RequestEncodingParametersChange(allocation, framerate);
}
}
Expand Down Expand Up @@ -977,27 +979,26 @@ int32_t RTCVideoEncoder::Release() {
return WEBRTC_VIDEO_CODEC_OK;
}

int32_t RTCVideoEncoder::SetRateAllocation(
const webrtc::VideoBitrateAllocation& allocation,
uint32_t frame_rate) {
DVLOG(3) << __func__ << " new_bit_rate=" << allocation.ToString()
<< ", frame_rate=" << frame_rate;
void RTCVideoEncoder::SetRates(
const webrtc::VideoEncoder::RateControlParameters& parameters) {
DVLOG(3) << __func__ << " new_bit_rate=" << parameters.bitrate.ToString()
<< ", frame_rate=" << parameters.framerate_fps;
if (!impl_.get()) {
DVLOG(3) << "Encoder is not initialized";
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
return;
}

const int32_t retval = impl_->GetStatus();
if (retval != WEBRTC_VIDEO_CODEC_OK) {
DVLOG(3) << __func__ << " returning " << retval;
return retval;
return;
}

gpu_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&RTCVideoEncoder::Impl::RequestEncodingParametersChange,
impl_, allocation, frame_rate));
return WEBRTC_VIDEO_CODEC_OK;
impl_, parameters));
return;
}

webrtc::VideoEncoder::EncoderInfo RTCVideoEncoder::GetEncoderInfo() const {
Expand Down
4 changes: 2 additions & 2 deletions content/renderer/media/webrtc/rtc_video_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class CONTENT_EXPORT RTCVideoEncoder : public webrtc::VideoEncoder {
int32_t RegisterEncodeCompleteCallback(
webrtc::EncodedImageCallback* callback) override;
int32_t Release() override;
int32_t SetRateAllocation(const webrtc::VideoBitrateAllocation& allocation,
uint32_t framerate) override;
void SetRates(
const webrtc::VideoEncoder::RateControlParameters& parameters) override;
EncoderInfo GetEncoderInfo() const override;

private:
Expand Down
8 changes: 4 additions & 4 deletions remoting/protocol/webrtc_dummy_video_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ int32_t WebrtcDummyVideoEncoder::Encode(
return WEBRTC_VIDEO_CODEC_OK;
}

int32_t WebrtcDummyVideoEncoder::SetRates(uint32_t bitrate,
uint32_t framerate) {
void WebrtcDummyVideoEncoder::SetRates(
const RateControlParameters& parameters) {
main_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&VideoChannelStateObserver::OnTargetBitrateChanged,
video_channel_state_observer_, bitrate));
video_channel_state_observer_,
parameters.bitrate.get_sum_kbps()));
// framerate is not expected to be valid given we never report captured
// frames.
return WEBRTC_VIDEO_CODEC_OK;
}

webrtc::EncodedImageCallback::Result WebrtcDummyVideoEncoder::SendEncodedFrame(
Expand Down
2 changes: 1 addition & 1 deletion remoting/protocol/webrtc_dummy_video_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class WebrtcDummyVideoEncoder : public webrtc::VideoEncoder {
int32_t Encode(
const webrtc::VideoFrame& frame,
const std::vector<webrtc::VideoFrameType>* frame_types) override;
int32_t SetRates(uint32_t bitrate, uint32_t framerate) override;
void SetRates(const RateControlParameters& parameters) override;
webrtc::VideoEncoder::EncoderInfo GetEncoderInfo() const override;

webrtc::EncodedImageCallback::Result SendEncodedFrame(
Expand Down

0 comments on commit 9734cb7

Please sign in to comment.