Skip to content

Commit

Permalink
[LibvpxVp8Encoder] Allow I420A to be scaled to I420.
Browse files Browse the repository at this point in the history
In Chromium, the I420ABufferInterface implementation uses the default
CropAndScale() implementation which converts to I420 in the process.

This should be OK, because we do not encode the alpha channel anyway,
so having WebRTC scaling ignore the alpha channel might even be a good
thing. Unfortunatety, an if statement in the LibvpxVp8Encoder did not
consider I420A and I420 to be the same, resulting in dropping perfectly
valid frames.

This CL fixes that by considering I420A and I420 "compatible" in a
comparison helper function. The problem only happens in this encoder,
so only this encoder needs to be fixed.

Bug: chromium:1203206
Change-Id: Iec434d4ada897c79e09914cac823148fd5b05e57
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/216323
Reviewed-by: Evan Shrubsole <[email protected]>
Reviewed-by: Ilya Nikolaevskiy <[email protected]>
Commit-Queue: Henrik Boström <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33845}
  • Loading branch information
henbos authored and Commit Bot committed Apr 27, 2021
1 parent fad23c1 commit 065ce9c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ void ApplyVp8EncoderConfigToVpxConfig(const Vp8EncoderConfig& encoder_config,
}
}

bool IsCompatibleVideoFrameBufferType(VideoFrameBuffer::Type left,
VideoFrameBuffer::Type right) {
if (left == VideoFrameBuffer::Type::kI420 ||
left == VideoFrameBuffer::Type::kI420A) {
// LibvpxVp8Encoder does not care about the alpha channel, I420A and I420
// are considered compatible.
return right == VideoFrameBuffer::Type::kI420 ||
right == VideoFrameBuffer::Type::kI420A;
}
return left == right;
}

void SetRawImagePlanes(vpx_image_t* raw_image, VideoFrameBuffer* buffer) {
switch (buffer->type()) {
case VideoFrameBuffer::Type::kI420:
Expand Down Expand Up @@ -1378,7 +1390,8 @@ LibvpxVp8Encoder::PrepareBuffers(rtc::scoped_refptr<VideoFrameBuffer> buffer) {
}
RTC_DCHECK_EQ(scaled_buffer->type(), mapped_buffer->type())
<< "Scaled frames must have the same type as the mapped frame.";
if (scaled_buffer->type() != mapped_buffer->type()) {
if (!IsCompatibleVideoFrameBufferType(scaled_buffer->type(),
mapped_buffer->type())) {
RTC_LOG(LS_ERROR) << "When scaling "
<< VideoFrameBufferTypeToString(buffer_to_scale->type())
<< ", the image was unexpectedly converted to "
Expand Down

0 comments on commit 065ce9c

Please sign in to comment.