Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Unified Diff: media/base/video_util.cc

Issue 1913503002: Memory copy the VideoFrame to match the requirement for HW encoders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/video_util.cc
diff --git a/media/base/video_util.cc b/media/base/video_util.cc
index d9954f8f8e7b4b902d33bd6c63aebd42d619801c..931620f4e910b836267193dc7701edc34e2deab0 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 {
@@ -19,6 +20,31 @@ namespace {
// Empty method used for keeping a reference to the original media::VideoFrame.
void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {}
+// Helper to apply padding to the region outside visible rect with the repeated
+// last column / row of the visible rect.
+void FillRegionOutsideVisibleRect(uint8_t* frame,
+ const gfx::Size& frame_size,
+ const gfx::Size& visible_size) {
+ if (visible_size.IsEmpty())
miu 2016/05/03 19:05:43 This just occurred to me: If coded_size is non-emp
xjz 2016/05/03 23:30:15 Done.
+ return;
+
+ const int stride = frame_size.width();
+ if (visible_size.width() < stride) {
+ const int pad_length = stride - visible_size.width();
+ uint8_t* dst = frame + visible_size.width();
+ for (int i = 0; i < visible_size.height(); ++i, dst += stride)
+ std::memset(dst, *(dst - 1), pad_length);
+ }
+
+ if (visible_size.height() < frame_size.height()) {
+ uint8_t* dst = frame + visible_size.height() * stride;
+ uint8_t* src = dst - stride;
+ for (int i = visible_size.height(); i < frame_size.height();
+ ++i, dst += stride)
+ std::memcpy(dst, src, stride);
+ }
+}
+
} // namespace
gfx::Size GetNaturalSize(const gfx::Size& visible_size,
@@ -339,4 +365,49 @@ scoped_refptr<VideoFrame> WrapAsI420VideoFrame(
return wrapped_frame;
}
+bool I420CopyWithPadding(const VideoFrame& src_frame, VideoFrame* dst_frame) {
+ if (!dst_frame)
miu 2016/05/03 19:05:43 Need to check for non-memory-backed VideoFrames:
xjz 2016/05/03 23:30:15 Done.
+ return false;
+
+ DCHECK_GE(dst_frame->coded_size().width(), src_frame.visible_rect().width());
+ DCHECK_GE(dst_frame->coded_size().height(),
+ src_frame.visible_rect().height());
+ DCHECK(dst_frame->visible_rect().origin().IsOrigin());
+
+ if (libyuv::I420Copy(src_frame.visible_data(media::VideoFrame::kYPlane),
+ src_frame.stride(media::VideoFrame::kYPlane),
+ src_frame.visible_data(media::VideoFrame::kUPlane),
+ src_frame.stride(media::VideoFrame::kUPlane),
+ src_frame.visible_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 the region outside the visible rect with the repeated last
+ // column / row of the visible rect. This can improve the coding efficiency.
+ FillRegionOutsideVisibleRect(dst_frame->data(media::VideoFrame::kYPlane),
+ dst_frame->coded_size(),
+ src_frame.visible_rect().size());
+ FillRegionOutsideVisibleRect(
+ dst_frame->data(media::VideoFrame::kUPlane),
+ VideoFrame::PlaneSize(PIXEL_FORMAT_I420, media::VideoFrame::kUPlane,
+ dst_frame->coded_size()),
+ VideoFrame::PlaneSize(PIXEL_FORMAT_I420, media::VideoFrame::kUPlane,
+ src_frame.visible_rect().size()));
+ FillRegionOutsideVisibleRect(
+ dst_frame->data(media::VideoFrame::kVPlane),
+ VideoFrame::PlaneSize(PIXEL_FORMAT_I420, media::VideoFrame::kVPlane,
+ dst_frame->coded_size()),
+ VideoFrame::PlaneSize(PIXEL_FORMAT_I420, media::VideoFrame::kVPlane,
+ src_frame.visible_rect().size()));
+ return true;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698