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

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: updates 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 2014 The Chromium Authors. All rights reserved.
xhwang 2016/02/29 18:28:05 2016
jrummell 2016/03/01 00:41:05 Done.
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(MojoVideoFrameTest, CreateFrameWithSharedMemory) {
21 const int kWidth = 16;
22 const int kHeight = 9;
23 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
24
25 // Create a MojoVideoFrame which will allocate enough space to hold a 64x48
xhwang 2016/02/29 18:28:05 Why 64x48?
jrummell 2016/03/01 00:41:05 This was in the VideoFrame test. I actually made i
26 // video frame.
27 gfx::Size size(kWidth, kHeight);
28 scoped_refptr<MojoVideoFrame> frame =
29 MojoVideoFrame::Create(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 EXPECT_TRUE(frame->handle().is_valid());
35 EXPECT_GT(frame->mapped_size(), 0u);
36
37 // The offsets should be set appropriately.
38 EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), 0u);
39 EXPECT_GT(frame->plane_offset(VideoFrame::kUPlane), 0u);
40 EXPECT_GT(frame->plane_offset(VideoFrame::kVPlane), 0u);
41
42 // The strides should be set appropriately.
43 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), kWidth);
44 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), kWidth / 2);
45 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), kWidth / 2);
46
47 // The data pointers for each plane should be set.
48 EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
49 EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
50 EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
51 }
52
53 TEST(MojoVideoFrameTest, CreateFrameAndReuseSharedMemory) {
54 const int kWidth = 32;
55 const int kHeight = 18;
56 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1338);
57
58 // Some random values to use. Since we actually don't use the data inside the
59 // frame, random values are fine (as long as the offsets are within the
60 // memory size allocated).
61 const VideoPixelFormat format = PIXEL_FORMAT_YV12;
62 const size_t y_offset = kWidth * 2;
63 const size_t u_offset = kWidth * 3;
64 const size_t v_offset = kWidth * 5;
65 const int32_t y_stride = kWidth;
66 const int32_t u_stride = kWidth - 1;
67 const int32_t v_stride = kWidth - 2;
68
69 // Allocate some shared memory.
70 gfx::Size size(kWidth, kHeight);
71 gfx::Rect visible_rect(size);
72 size_t requested_size = VideoFrame::AllocationSize(format, size);
73 ASSERT_LT(y_offset, requested_size);
74 mojo::ScopedSharedBufferHandle handle;
75 MojoResult result =
76 mojo::CreateSharedBuffer(nullptr, requested_size, &handle);
77 ASSERT_EQ(result, MOJO_RESULT_OK);
78
79 // Allocate frame.
80 scoped_refptr<MojoVideoFrame> frame = MojoVideoFrame::Create(
81 format, size, visible_rect, size, handle.get(), requested_size, y_offset,
82 u_offset, v_offset, y_stride, u_stride, v_stride, kTimestamp);
83 ASSERT_TRUE(frame.get());
84 EXPECT_EQ(frame->format(), format);
85
86 // |frame| should have it's own handle to the memory, so ensure the original
87 // is still valid.
88 EXPECT_TRUE(handle.get().is_valid());
89 EXPECT_TRUE(frame->handle().is_valid());
90 EXPECT_NE(handle.get().value(), frame->handle().value());
91 EXPECT_EQ(frame->mapped_size(), requested_size);
92
93 // The offsets should be set appropriately.
94 EXPECT_EQ(frame->plane_offset(VideoFrame::kYPlane), y_offset);
95 EXPECT_EQ(frame->plane_offset(VideoFrame::kUPlane), u_offset);
96 EXPECT_EQ(frame->plane_offset(VideoFrame::kVPlane), v_offset);
97
98 // The strides should be set appropriately.
99 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), y_stride);
100 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), u_stride);
101 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), v_stride);
102
103 // The data pointers for each plane should be set.
104 EXPECT_TRUE(frame->data(VideoFrame::kYPlane));
105 EXPECT_TRUE(frame->data(VideoFrame::kUPlane));
106 EXPECT_TRUE(frame->data(VideoFrame::kVPlane));
107 }
108
109 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698