Commit 0b202945 authored by Eugene Zemtsov's avatar Eugene Zemtsov Committed by Chromium LUCI CQ

cleanup: Use NV12Scale from libyuv

NV12Scale has been recently added to libyuv, so there is no reason
to use a self-written version.

Change-Id: I6b207788e964c7ee21697eab9931fa2854031718
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580916Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarMatthew Wolenetz <wolenetz@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835582}
parent a4512348
......@@ -19,60 +19,6 @@ namespace media {
namespace {
// TODO(https://bugs.chromium.org/p/libyuv/issues/detail?id=838): Remove
// this once libyuv implements NV12Scale and use the libyuv::NV12Scale().
// This is copy-pasted from
// third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h.
void NV12Scale(uint8_t* tmp_buffer,
const uint8_t* src_y,
int src_stride_y,
const uint8_t* src_uv,
int src_stride_uv,
int src_width,
int src_height,
uint8_t* dst_y,
int dst_stride_y,
uint8_t* dst_uv,
int dst_stride_uv,
int dst_width,
int dst_height) {
const int src_chroma_width = (src_width + 1) / 2;
const int src_chroma_height = (src_height + 1) / 2;
if (src_width == dst_width && src_height == dst_height) {
// No scaling.
libyuv::CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_width,
src_height);
libyuv::CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv,
src_chroma_width * 2, src_chroma_height);
return;
}
// Scaling.
// Allocate temporary memory for spitting UV planes and scaling them.
const int dst_chroma_width = (dst_width + 1) / 2;
const int dst_chroma_height = (dst_height + 1) / 2;
uint8_t* const src_u = tmp_buffer;
uint8_t* const src_v = src_u + src_chroma_width * src_chroma_height;
uint8_t* const dst_u = src_v + src_chroma_width * src_chroma_height;
uint8_t* const dst_v = dst_u + dst_chroma_width * dst_chroma_height;
// Split source UV plane into separate U and V plane using the temporary data.
libyuv::SplitUVPlane(src_uv, src_stride_uv, src_u, src_chroma_width, src_v,
src_chroma_width, src_chroma_width, src_chroma_height);
// Scale the planes.
libyuv::I420Scale(
src_y, src_stride_y, src_u, src_chroma_width, src_v, src_chroma_width,
src_width, src_height, dst_y, dst_stride_y, dst_u, dst_chroma_width,
dst_v, dst_chroma_width, dst_width, dst_height, libyuv::kFilterBox);
// Merge the UV planes into the destination.
libyuv::MergeUVPlane(dst_u, dst_chroma_width, dst_v, dst_chroma_width, dst_uv,
dst_stride_uv, dst_chroma_width, dst_chroma_height);
}
// TODO(https://bugs.chromium.org/p/libyuv/issues/detail?id=840): Remove
// this once libyuv implements NV12Rotate() and use the libyuv::NV12Rotate().
bool NV12Rotate(uint8_t* tmp_buffer,
......@@ -254,19 +200,6 @@ std::unique_ptr<ImageProcessorBackend> LibYUVImageProcessorBackend::Create(
<< output_config.visible_rect.ToString();
return nullptr;
}
// Down-scaling support only.
// This restriction is to simplify |intermediate_frame_| creation. It is
// used as |tmp_buffer| in NV12Scale().
// TODO(hiroh): Remove this restriction once libyuv:NV12Scale() is arrived.
if (!gfx::Rect(input_config.visible_rect.size())
.Contains(gfx::Rect(output_config.visible_rect.size())) &&
relative_rotation == VIDEO_ROTATION_0) {
VLOGF(2) << "Down-scaling support only, input_config.visible_rect="
<< input_config.visible_rect.ToString()
<< ", output_config.visible_rect="
<< output_config.visible_rect.ToString();
return nullptr;
}
}
scoped_refptr<VideoFrame> intermediate_frame;
......@@ -429,19 +362,14 @@ int LibYUVImageProcessorBackend::DoConversion(const VideoFrame* const input,
}
// Scaling mode.
// The size of |tmp_buffer| of NV12Scale() should be
// input_visible_rect().GetArea() / 2 +
// output_visible_rect().GetArea() / 2. Although |intermediate_frame_|
// is much larger than the required size, we use the frame to simplify
// the code.
NV12Scale(intermediate_frame_->data(0),
input->visible_data(VideoFrame::kYPlane),
input->stride(VideoFrame::kYPlane),
input->visible_data(VideoFrame::kUPlane),
input->stride(VideoFrame::kUPlane),
input->visible_rect().width(), input->visible_rect().height(),
Y_UV_DATA(output), output->visible_rect().width(),
output->visible_rect().height());
libyuv::NV12Scale(input->visible_data(VideoFrame::kYPlane),
input->stride(VideoFrame::kYPlane),
input->visible_data(VideoFrame::kUPlane),
input->stride(VideoFrame::kUPlane),
input->visible_rect().width(),
input->visible_rect().height(), Y_UV_DATA(output),
output->visible_rect().width(),
output->visible_rect().height(), libyuv::kFilterBox);
return 0;
default:
VLOGF(1) << "Unexpected input format: " << input->format();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment