diff options
-rw-r--r-- | media/BUILD.gn | 1 | ||||
-rw-r--r-- | media/base/video_util.cc | 41 | ||||
-rw-r--r-- | media/base/video_util.h | 22 | ||||
-rw-r--r-- | media/base/video_util_unittest.cc | 26 | ||||
-rw-r--r-- | media/filters/vpx_video_decoder.cc | 6 | ||||
-rw-r--r-- | media/media.gyp | 1 | ||||
-rw-r--r-- | media/renderers/skcanvas_video_renderer_unittest.cc | 11 |
7 files changed, 13 insertions, 95 deletions
diff --git a/media/BUILD.gn b/media/BUILD.gn index b5e2e40..913c052 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -683,6 +683,7 @@ test("media_unittests") { "//skia", # Direct dependency required to inherit config. "//testing/gmock", "//testing/gtest", + "//third_party/libyuv", "//third_party/widevine/cdm:version_h", "//ui/gfx:test_support", "//url", diff --git a/media/base/video_util.cc b/media/base/video_util.cc index cddbb9c..414e57b 100644 --- a/media/base/video_util.cc +++ b/media/base/video_util.cc @@ -29,47 +29,6 @@ gfx::Size GetNaturalSize(const gfx::Size& visible_size, visible_size.height()); } -void CopyPlane(size_t plane, const uint8* source, int stride, int rows, - VideoFrame* frame) { - uint8* dest = frame->data(plane); - int dest_stride = frame->stride(plane); - - // Clamp in case source frame has smaller stride. - int bytes_to_copy_per_row = std::min(frame->row_bytes(plane), stride); - - // Clamp in case source frame has smaller height. - int rows_to_copy = std::min(frame->rows(plane), rows); - - // Copy! - for (int row = 0; row < rows_to_copy; ++row) { - memcpy(dest, source, bytes_to_copy_per_row); - source += stride; - dest += dest_stride; - } -} - -void CopyYPlane(const uint8* source, int stride, int rows, VideoFrame* frame) { - CopyPlane(VideoFrame::kYPlane, source, stride, rows, frame); -} - -void CopyUPlane(const uint8* source, int stride, int rows, VideoFrame* frame) { - CopyPlane(VideoFrame::kUPlane, source, stride, rows, frame); -} - -void CopyVPlane(const uint8* source, int stride, int rows, VideoFrame* frame) { - CopyPlane(VideoFrame::kVPlane, source, stride, rows, frame); -} - -void CopyAPlane(const uint8* source, int stride, int rows, VideoFrame* frame) { - CopyPlane(VideoFrame::kAPlane, source, stride, rows, frame); -} - -void MakeOpaqueAPlane(int stride, int rows, VideoFrame* frame) { - int rows_to_clear = std::min(frame->rows(VideoFrame::kAPlane), rows); - memset(frame->data(VideoFrame::kAPlane), 255, - frame->stride(VideoFrame::kAPlane) * rows_to_clear); -} - void FillYUV(VideoFrame* frame, uint8 y, uint8 u, uint8 v) { // Fill the Y plane. uint8* y_plane = frame->data(VideoFrame::kYPlane); diff --git a/media/base/video_util.h b/media/base/video_util.h index abbcad4..77c6523 100644 --- a/media/base/video_util.h +++ b/media/base/video_util.h @@ -19,28 +19,6 @@ MEDIA_EXPORT gfx::Size GetNaturalSize(const gfx::Size& visible_size, int aspect_ratio_numerator, int aspect_ratio_denominator); -// Copies a plane of YUV(A) source into a VideoFrame object, taking into account -// source and destinations dimensions. -// -// NOTE: rows is *not* the same as height! -MEDIA_EXPORT void CopyYPlane(const uint8* source, int stride, int rows, - VideoFrame* frame); -MEDIA_EXPORT void CopyUPlane(const uint8* source, int stride, int rows, - VideoFrame* frame); -MEDIA_EXPORT void CopyVPlane(const uint8* source, int stride, int rows, - VideoFrame* frame); -MEDIA_EXPORT void CopyAPlane(const uint8* source, int stride, int rows, - VideoFrame* frame); - -// Sets alpha plane values to be completely opaque (all 255's). -MEDIA_EXPORT void MakeOpaqueAPlane(int stride, int rows, VideoFrame* frame); - -// |plane| is one of VideoFrame::kYPlane, VideoFrame::kUPlane, -// VideoFrame::kVPlane or VideoFrame::kAPlane -MEDIA_EXPORT void CopyPlane(size_t plane, const uint8* source, int stride, - int rows, VideoFrame* frame); - - // Fills |frame| containing YUV data to the given color values. MEDIA_EXPORT void FillYUV(VideoFrame* frame, uint8 y, uint8 u, uint8 v); diff --git a/media/base/video_util_unittest.cc b/media/base/video_util_unittest.cc index a62f0cb..ba53a58 100644 --- a/media/base/video_util_unittest.cc +++ b/media/base/video_util_unittest.cc @@ -42,14 +42,6 @@ class VideoUtilTest : public testing::Test { PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, base::TimeDelta()); } - void CopyPlanes() { - CopyYPlane(y_plane_.get(), y_stride_, height_, destination_frame_.get()); - CopyUPlane( - u_plane_.get(), u_stride_, height_ / 2, destination_frame_.get()); - CopyVPlane( - v_plane_.get(), v_stride_, height_ / 2, destination_frame_.get()); - } - private: scoped_ptr<uint8[]> y_plane_; scoped_ptr<uint8[]> u_plane_; @@ -94,24 +86,6 @@ TEST_F(VideoUtilTest, GetNaturalSize) { EXPECT_EQ(gfx::Size(207, 240), GetNaturalSize(visible_size, 11, 17)); } -TEST_F(VideoUtilTest, CopyPlane_Exact) { - CreateSourceFrame(16, 16, 16, 8, 8); - CreateDestinationFrame(16, 16); - CopyPlanes(); -} - -TEST_F(VideoUtilTest, CopyPlane_SmallerSource) { - CreateSourceFrame(8, 8, 8, 4, 4); - CreateDestinationFrame(16, 16); - CopyPlanes(); -} - -TEST_F(VideoUtilTest, CopyPlane_SmallerDestination) { - CreateSourceFrame(16, 16, 16, 8, 8); - CreateDestinationFrame(8, 8); - CopyPlanes(); -} - namespace { uint8 src6x4[] = { diff --git a/media/filters/vpx_video_decoder.cc b/media/filters/vpx_video_decoder.cc index 10b8d91..e3cc170 100644 --- a/media/filters/vpx_video_decoder.cc +++ b/media/filters/vpx_video_decoder.cc @@ -543,9 +543,9 @@ bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, void VpxVideoDecoder::CopyVpxImageToVideoFrame( const struct vpx_image* vpx_image, scoped_refptr<VideoFrame>* video_frame) { - CHECK(vpx_image); - CHECK(vpx_image->fmt == VPX_IMG_FMT_I420 || - vpx_image->fmt == VPX_IMG_FMT_I444); + DCHECK(vpx_image); + DCHECK(vpx_image->fmt == VPX_IMG_FMT_I420 || + vpx_image->fmt == VPX_IMG_FMT_I444); VideoPixelFormat codec_format = PIXEL_FORMAT_YV12; if (vpx_image->fmt == VPX_IMG_FMT_I444) diff --git a/media/media.gyp b/media/media.gyp index d0c3f78..c5cc228 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -1187,6 +1187,7 @@ '../skia/skia.gyp:skia', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', + '../third_party/libyuv/libyuv.gyp:libyuv', '../third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', diff --git a/media/renderers/skcanvas_video_renderer_unittest.cc b/media/renderers/skcanvas_video_renderer_unittest.cc index d787bf0..fad340d 100644 --- a/media/renderers/skcanvas_video_renderer_unittest.cc +++ b/media/renderers/skcanvas_video_renderer_unittest.cc @@ -10,6 +10,7 @@ #include "media/base/video_util.h" #include "media/renderers/skcanvas_video_renderer.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/libyuv/include/libyuv/convert.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/gpu/GrContext.h" #include "third_party/skia/include/gpu/gl/GrGLInterface.h" @@ -189,9 +190,13 @@ SkCanvasVideoRendererTest::SkCanvasVideoRendererTest() 107, 107, 107, 107, 21, 21, 21, 21, 107, 107, 107, 107, }; - media::CopyYPlane(cropped_y_plane, 16, 16, cropped_frame().get()); - media::CopyUPlane(cropped_u_plane, 8, 8, cropped_frame().get()); - media::CopyVPlane(cropped_v_plane, 8, 8, cropped_frame().get()); + libyuv::I420Copy(cropped_y_plane, 16, cropped_u_plane, 8, cropped_v_plane, 8, + cropped_frame()->data(VideoFrame::kYPlane), + cropped_frame()->stride(VideoFrame::kYPlane), + cropped_frame()->data(VideoFrame::kUPlane), + cropped_frame()->stride(VideoFrame::kUPlane), + cropped_frame()->data(VideoFrame::kVPlane), + cropped_frame()->stride(VideoFrame::kVPlane), 16, 16); } SkCanvasVideoRendererTest::~SkCanvasVideoRendererTest() {} |