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

Unified Diff: media/mojo/common/mojo_video_frame_unittest.cc

Issue 1704273002: Add MojoVideoFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes Created 4 years, 10 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/mojo/common/mojo_video_frame_unittest.cc
diff --git a/media/mojo/common/mojo_video_frame_unittest.cc b/media/mojo/common/mojo_video_frame_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7bcdcbd0c3c141b0a1b242b56cd66cc30594a931
--- /dev/null
+++ b/media/mojo/common/mojo_video_frame_unittest.cc
@@ -0,0 +1,102 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/mojo/common/mojo_video_frame.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
+#include "mojo/public/cpp/system/buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace media {
+
+TEST(MojoSharedBufferVideoFrameTest, CreateFrameWithSharedMemory) {
+ const int kWidth = 16;
+ const int kHeight = 9;
+ const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
+
+ // Create a MojoSharedBufferVideoFrame which will allocate enough space
+ // to hold a 16x9 video frame.
+ gfx::Size size(kWidth, kHeight);
+ scoped_refptr<MojoSharedBufferVideoFrame> frame =
+ MojoSharedBufferVideoFrame::CreateDefaultI420(size, kTimestamp);
+ ASSERT_TRUE(frame.get());
+
+ // Verify that the correct frame was allocated along with some memory.
+ EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format());
+
+ // The offsets should be set appropriately.
+ EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), 0u);
+ EXPECT_GT(frame->plane_offset(VideoFrame::kUPlane), 0u);
+ EXPECT_GT(frame->plane_offset(VideoFrame::kVPlane), 0u);
+
+ // The strides should be set appropriately.
+ EXPECT_EQ(frame->stride(VideoFrame::kYPlane), kWidth);
+ EXPECT_EQ(frame->stride(VideoFrame::kUPlane), kWidth / 2);
+ EXPECT_EQ(frame->stride(VideoFrame::kVPlane), kWidth / 2);
+
+ // The data pointers for each plane should be set.
+ EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
+ EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
+ EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
+}
+
+TEST(MojoSharedBufferVideoFrameTest, CreateFrameAndReuseSharedMemory) {
xhwang 2016/03/04 00:55:34 Is "reuse" still relevant?
jrummell 2016/03/04 02:19:06 Not really. Changed to "Pass".
+ const int kWidth = 32;
+ const int kHeight = 18;
+ const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1338);
+
+ // Some random values to use. Since we actually don't use the data inside the
+ // frame, random values are fine (as long as the offsets are within the
+ // memory size allocated).
+ const VideoPixelFormat format = PIXEL_FORMAT_YV12;
+ const size_t y_offset = kWidth * 2;
+ const size_t u_offset = kWidth * 3;
+ const size_t v_offset = kWidth * 5;
+ const int32_t y_stride = kWidth;
+ const int32_t u_stride = kWidth - 1;
+ const int32_t v_stride = kWidth - 2;
+
+ // Allocate some shared memory.
+ gfx::Size size(kWidth, kHeight);
+ gfx::Rect visible_rect(size);
+ size_t requested_size = VideoFrame::AllocationSize(format, size);
+ ASSERT_LT(y_offset, requested_size);
+ mojo::ScopedSharedBufferHandle handle;
+ MojoResult result =
+ mojo::CreateSharedBuffer(nullptr, requested_size, &handle);
+ ASSERT_EQ(result, MOJO_RESULT_OK);
+
+ // Allocate frame.
+ scoped_refptr<MojoSharedBufferVideoFrame> frame =
+ MojoSharedBufferVideoFrame::Create(format, size, visible_rect, size,
+ std::move(handle), requested_size,
+ y_offset, u_offset, v_offset, y_stride,
+ u_stride, v_stride, kTimestamp);
+ ASSERT_TRUE(frame.get());
+ EXPECT_EQ(frame->format(), format);
+
+ // The offsets should be set appropriately.
+ EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), y_offset);
+ EXPECT_EQ(frame->plane_offset(VideoFrame::kUPlane), u_offset);
+ EXPECT_EQ(frame->plane_offset(VideoFrame::kVPlane), v_offset);
+
+ // The strides should be set appropriately.
+ EXPECT_EQ(frame->stride(VideoFrame::kYPlane), y_stride);
+ EXPECT_EQ(frame->stride(VideoFrame::kUPlane), u_stride);
+ EXPECT_EQ(frame->stride(VideoFrame::kVPlane), v_stride);
+
+ // The data pointers for each plane should be set.
+ EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
+ EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
+ EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
+}
+
xhwang 2016/03/04 00:55:34 Do we support odd width? If so can we have a test
jrummell 2016/03/04 02:19:06 Done.
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698