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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/mojo/common/mojo_video_frame.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <string>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h"
13 #include "mojo/public/cpp/system/buffer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h"
17
18 namespace media {
19
20 TEST(MojoSharedBufferVideoFrameTest, CreateFrameWithSharedMemory) {
21 const int kWidth = 16;
22 const int kHeight = 9;
23 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
24
25 // Create a MojoSharedBufferVideoFrame which will allocate enough space
26 // to hold a 16x9 video frame.
27 gfx::Size size(kWidth, kHeight);
28 scoped_refptr<MojoSharedBufferVideoFrame> frame =
29 MojoSharedBufferVideoFrame::CreateDefaultI420(size, kTimestamp);
30 ASSERT_TRUE(frame.get());
31
32 // Verify that the correct frame was allocated along with some memory.
33 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format());
34
35 // The offsets should be set appropriately.
36 EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), 0u);
37 EXPECT_GT(frame->plane_offset(VideoFrame::kUPlane), 0u);
38 EXPECT_GT(frame->plane_offset(VideoFrame::kVPlane), 0u);
39
40 // The strides should be set appropriately.
41 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), kWidth);
42 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), kWidth / 2);
43 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), kWidth / 2);
44
45 // The data pointers for each plane should be set.
46 EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
47 EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
48 EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
49 }
50
51 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".
52 const int kWidth = 32;
53 const int kHeight = 18;
54 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1338);
55
56 // Some random values to use. Since we actually don't use the data inside the
57 // frame, random values are fine (as long as the offsets are within the
58 // memory size allocated).
59 const VideoPixelFormat format = PIXEL_FORMAT_YV12;
60 const size_t y_offset = kWidth * 2;
61 const size_t u_offset = kWidth * 3;
62 const size_t v_offset = kWidth * 5;
63 const int32_t y_stride = kWidth;
64 const int32_t u_stride = kWidth - 1;
65 const int32_t v_stride = kWidth - 2;
66
67 // Allocate some shared memory.
68 gfx::Size size(kWidth, kHeight);
69 gfx::Rect visible_rect(size);
70 size_t requested_size = VideoFrame::AllocationSize(format, size);
71 ASSERT_LT(y_offset, requested_size);
72 mojo::ScopedSharedBufferHandle handle;
73 MojoResult result =
74 mojo::CreateSharedBuffer(nullptr, requested_size, &handle);
75 ASSERT_EQ(result, MOJO_RESULT_OK);
76
77 // Allocate frame.
78 scoped_refptr<MojoSharedBufferVideoFrame> frame =
79 MojoSharedBufferVideoFrame::Create(format, size, visible_rect, size,
80 std::move(handle), requested_size,
81 y_offset, u_offset, v_offset, y_stride,
82 u_stride, v_stride, kTimestamp);
83 ASSERT_TRUE(frame.get());
84 EXPECT_EQ(frame->format(), format);
85
86 // The offsets should be set appropriately.
87 EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), y_offset);
88 EXPECT_EQ(frame->plane_offset(VideoFrame::kUPlane), u_offset);
89 EXPECT_EQ(frame->plane_offset(VideoFrame::kVPlane), v_offset);
90
91 // The strides should be set appropriately.
92 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), y_stride);
93 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), u_stride);
94 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), v_stride);
95
96 // The data pointers for each plane should be set.
97 EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
98 EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
99 EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
100 }
101
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.
102 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698