Handle null return from ToI420 in encoders

In cases where ToI420 fails it should be able to return null.

Bug: webrtc:12877
Change-Id: Ia13859c104d978a29712ae10f8e15acada8406ac
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/222613
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#34342}
This commit is contained in:
Evan Shrubsole
2021-06-21 13:47:44 +02:00
committed by WebRTC LUCI CQ
parent 76a35d9ce2
commit f906ec40d4
3 changed files with 36 additions and 2 deletions

View File

@ -588,12 +588,26 @@ int32_t LibaomAv1Encoder::Encode(
// kNative. As a workaround to this, we perform ToI420() a second time. // kNative. As a workaround to this, we perform ToI420() a second time.
// TODO(https://crbug.com/webrtc/12602): When Android buffers have a correct // TODO(https://crbug.com/webrtc/12602): When Android buffers have a correct
// ToI420() implementaion, remove his workaround. // ToI420() implementaion, remove his workaround.
if (!converted_buffer) {
RTC_LOG(LS_ERROR) << "Failed to convert "
<< VideoFrameBufferTypeToString(
converted_buffer->type())
<< " image to I420. Can't encode frame.";
return WEBRTC_VIDEO_CODEC_ENCODER_FAILURE;
}
if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 && if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 &&
converted_buffer->type() != VideoFrameBuffer::Type::kI420A) { converted_buffer->type() != VideoFrameBuffer::Type::kI420A) {
converted_buffer = converted_buffer->ToI420(); converted_buffer = converted_buffer->ToI420();
RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 || RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 ||
converted_buffer->type() == VideoFrameBuffer::Type::kI420A); converted_buffer->type() == VideoFrameBuffer::Type::kI420A);
} }
if (!converted_buffer) {
RTC_LOG(LS_ERROR) << "Failed to convert "
<< VideoFrameBufferTypeToString(
converted_buffer->type())
<< " image to I420. Can't encode frame.";
return WEBRTC_VIDEO_CODEC_ENCODER_FAILURE;
}
prepped_input_frame = VideoFrame(converted_buffer, frame.timestamp(), prepped_input_frame = VideoFrame(converted_buffer, frame.timestamp(),
frame.render_time_ms(), frame.rotation()); frame.render_time_ms(), frame.rotation());
} }

View File

@ -1336,6 +1336,13 @@ LibvpxVp8Encoder::PrepareBuffers(rtc::scoped_refptr<VideoFrameBuffer> buffer) {
if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 && if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 &&
converted_buffer->type() != VideoFrameBuffer::Type::kI420A) { converted_buffer->type() != VideoFrameBuffer::Type::kI420A) {
converted_buffer = converted_buffer->ToI420(); converted_buffer = converted_buffer->ToI420();
if (!converted_buffer) {
RTC_LOG(LS_ERROR) << "Failed to convert "
<< VideoFrameBufferTypeToString(
converted_buffer->type())
<< " image to I420. Can't encode frame.";
return {};
}
RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 || RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 ||
converted_buffer->type() == VideoFrameBuffer::Type::kI420A); converted_buffer->type() == VideoFrameBuffer::Type::kI420A);
} }

View File

@ -1068,8 +1068,15 @@ int LibvpxVp9Encoder::Encode(const VideoFrame& input_image,
break; break;
} }
default: { default: {
i010_copy = auto i420_buffer = input_image.video_frame_buffer()->ToI420();
I010Buffer::Copy(*input_image.video_frame_buffer()->ToI420()); if (!i420_buffer) {
RTC_LOG(LS_ERROR) << "Failed to convert "
<< VideoFrameBufferTypeToString(
input_image.video_frame_buffer()->type())
<< " image to I420. Can't encode frame.";
return WEBRTC_VIDEO_CODEC_ERROR;
}
i010_copy = I010Buffer::Copy(*i420_buffer);
i010_buffer = i010_copy.get(); i010_buffer = i010_copy.get();
} }
} }
@ -1908,6 +1915,12 @@ rtc::scoped_refptr<VideoFrameBuffer> LibvpxVp9Encoder::PrepareBufferForProfile0(
if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 && if (converted_buffer->type() != VideoFrameBuffer::Type::kI420 &&
converted_buffer->type() != VideoFrameBuffer::Type::kI420A) { converted_buffer->type() != VideoFrameBuffer::Type::kI420A) {
converted_buffer = converted_buffer->ToI420(); converted_buffer = converted_buffer->ToI420();
if (!converted_buffer) {
RTC_LOG(LS_ERROR) << "Failed to convert "
<< VideoFrameBufferTypeToString(buffer->type())
<< " image to I420. Can't encode frame.";
return {};
}
RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 || RTC_CHECK(converted_buffer->type() == VideoFrameBuffer::Type::kI420 ||
converted_buffer->type() == VideoFrameBuffer::Type::kI420A); converted_buffer->type() == VideoFrameBuffer::Type::kI420A);
} }