Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 9577be3

Browse files
eshrubsCommit Bot
authored andcommitted
Use VideoFrameBuffer::CropAndScale in VideoStreamEncoder
This avoids a conversion to I420 for frames that support crop and scale. Bug: webrtc:11976 Change-Id: I6517a016403cff3ea7ebce1f3de9f9af8b569933 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187357 Reviewed-by: Ilya Nikolaevskiy <[email protected]> Commit-Queue: Evan Shrubsole <[email protected]> Cr-Commit-Position: refs/heads/master@{#32366}
1 parent 4cf8e17 commit 9577be3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

video/video_stream_encoder.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,36 +1347,36 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
13471347
out_frame.video_frame_buffer()->type() !=
13481348
VideoFrameBuffer::Type::kNative) {
13491349
// If the frame can't be converted to I420, drop it.
1350-
auto i420_buffer = video_frame.video_frame_buffer()->ToI420();
1351-
if (!i420_buffer) {
1352-
RTC_LOG(LS_ERROR) << "Frame conversion for crop failed, dropping frame.";
1353-
return;
1354-
}
13551350
int cropped_width = video_frame.width() - crop_width_;
13561351
int cropped_height = video_frame.height() - crop_height_;
1357-
rtc::scoped_refptr<I420Buffer> cropped_buffer =
1358-
I420Buffer::Create(cropped_width, cropped_height);
1352+
rtc::scoped_refptr<VideoFrameBuffer> cropped_buffer;
13591353
// TODO(ilnik): Remove scaling if cropping is too big, as it should never
13601354
// happen after SinkWants signaled correctly from ReconfigureEncoder.
13611355
VideoFrame::UpdateRect update_rect = video_frame.update_rect();
13621356
if (crop_width_ < 4 && crop_height_ < 4) {
1363-
cropped_buffer->CropAndScaleFrom(*i420_buffer, crop_width_ / 2,
1364-
crop_height_ / 2, cropped_width,
1365-
cropped_height);
1357+
cropped_buffer = video_frame.video_frame_buffer()->CropAndScale(
1358+
crop_width_ / 2, crop_height_ / 2, cropped_width, cropped_height,
1359+
cropped_width, cropped_height);
13661360
update_rect.offset_x -= crop_width_ / 2;
13671361
update_rect.offset_y -= crop_height_ / 2;
13681362
update_rect.Intersect(
13691363
VideoFrame::UpdateRect{0, 0, cropped_width, cropped_height});
13701364

13711365
} else {
1372-
cropped_buffer->ScaleFrom(*i420_buffer);
1366+
cropped_buffer = video_frame.video_frame_buffer()->Scale(cropped_width,
1367+
cropped_height);
13731368
if (!update_rect.IsEmpty()) {
13741369
// Since we can't reason about pixels after scaling, we invalidate whole
13751370
// picture, if anything changed.
13761371
update_rect =
13771372
VideoFrame::UpdateRect{0, 0, cropped_width, cropped_height};
13781373
}
13791374
}
1375+
if (!cropped_buffer) {
1376+
RTC_LOG(LS_ERROR) << "Cropping and scaling frame failed, dropping frame.";
1377+
return;
1378+
}
1379+
13801380
out_frame.set_video_frame_buffer(cropped_buffer);
13811381
out_frame.set_update_rect(update_rect);
13821382
out_frame.set_ntp_time_ms(video_frame.ntp_time_ms());

0 commit comments

Comments
 (0)