Chromium Code Reviews| Index: media/base/video_util.cc |
| diff --git a/media/base/video_util.cc b/media/base/video_util.cc |
| index d9954f8f8e7b4b902d33bd6c63aebd42d619801c..aaffe16ab38439bc838b7d6a6fa40a5128ef0868 100644 |
| --- a/media/base/video_util.cc |
| +++ b/media/base/video_util.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/numerics/safe_math.h" |
| #include "media/base/video_frame.h" |
| #include "media/base/yuv_convert.h" |
| +#include "third_party/libyuv/include/libyuv.h" |
| namespace media { |
| @@ -339,4 +340,64 @@ scoped_refptr<VideoFrame> WrapAsI420VideoFrame( |
| return wrapped_frame; |
| } |
| +// Helper to pad the input |frame| with the repeated last column / row. |
| +void Padding(uint8_t* frame, |
|
miu
2016/04/30 00:41:13
Please put this function in an anonymous namespace
miu
2016/04/30 00:41:14
naming nit: ApplyPaddingOutsideVisibleRegion() or
xjz
2016/05/03 01:17:58
Done. Renamed as FillRegionOutsideVisibleRect().
xjz
2016/05/03 01:17:58
Done.
|
| + const gfx::Size& frame_size, |
| + const gfx::Size& visible_size) { |
| + if (!frame) |
|
miu
2016/04/30 00:41:13
This should go at the top of I420CopyWithPadding()
xjz
2016/05/03 01:17:58
Done.
|
| + return; |
| + uint8_t* dst = frame; |
| + const int stride = frame_size.width(); |
| + if (visible_size.width() < stride) { |
|
miu
2016/04/30 00:41:13
To avoid the possibility of copying from an empty
xjz
2016/05/03 01:17:58
Done. Add early return when the visible region is
|
| + const int width = visible_size.width(); |
| + const int pad_length = stride - visible_size.width(); |
| + for (int i = 0; i < visible_size.height(); ++i, dst += stride) |
| + std::memset(dst + width, dst[width - 1], pad_length); |
| + } |
| + |
| + if (visible_size.height() < frame_size.height()) { |
|
miu
2016/04/30 00:41:13
Here too:
if (... && !visible_size.IsEmpty()) {
xjz
2016/05/03 01:17:58
Add early return when the visible region is empty.
|
| + uint8_t* src = dst - stride; |
| + for (int i = visible_size.height(); i < frame_size.height(); |
| + ++i, dst += stride) |
| + std::memcpy(dst, src, frame_size.width()); |
| + } |
| +} |
| + |
| +bool I420CopyWithPadding(const scoped_refptr<VideoFrame> src_frame, |
| + scoped_refptr<VideoFrame> dst_frame) { |
| + DCHECK_GE(dst_frame->coded_size().width(), src_frame->visible_rect().width()); |
| + DCHECK_GE(dst_frame->coded_size().height(), |
|
miu
2016/04/30 00:41:14
Looks like this code assumes dst_frame->visible_re
xjz
2016/05/03 01:17:58
Done.
|
| + src_frame->visible_rect().height()); |
| + |
| + if (libyuv::I420Copy(src_frame->data(media::VideoFrame::kYPlane), |
|
miu
2016/04/30 00:41:13
Please replace all data() calls with visible_data(
xjz
2016/05/03 01:17:58
Done. Though I think in our application src_frame-
|
| + src_frame->stride(media::VideoFrame::kYPlane), |
| + src_frame->data(media::VideoFrame::kUPlane), |
| + src_frame->stride(media::VideoFrame::kUPlane), |
| + src_frame->data(media::VideoFrame::kVPlane), |
| + src_frame->stride(media::VideoFrame::kVPlane), |
| + dst_frame->data(media::VideoFrame::kYPlane), |
| + dst_frame->stride(media::VideoFrame::kYPlane), |
| + dst_frame->data(media::VideoFrame::kUPlane), |
| + dst_frame->stride(media::VideoFrame::kUPlane), |
| + dst_frame->data(media::VideoFrame::kVPlane), |
| + dst_frame->stride(media::VideoFrame::kVPlane), |
| + src_frame->visible_rect().width(), |
| + src_frame->visible_rect().height())) |
| + return false; |
| + |
| + // Padding with the repeated last column / row. |
| + Padding(dst_frame->data(media::VideoFrame::kYPlane), dst_frame->coded_size(), |
| + src_frame->visible_rect().size()); |
| + const gfx::Size uv_visible_size(src_frame->visible_rect().width() / 2, |
|
miu
2016/04/30 00:41:14
Is this correct for odd widths/heights? The logic
xjz
2016/05/03 01:17:58
Done.
|
| + src_frame->visible_rect().height() / 2); |
| + const gfx::Size uv_coded_size(dst_frame->coded_size().width() / 2, |
| + dst_frame->coded_size().height() / 2); |
| + Padding(dst_frame->data(media::VideoFrame::kUPlane), uv_coded_size, |
| + uv_visible_size); |
| + Padding(dst_frame->data(media::VideoFrame::kVPlane), uv_coded_size, |
| + uv_visible_size); |
| + |
| + return true; |
| +} |
| + |
| } // namespace media |