| OLD | NEW |
| (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_shared_buffer_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. |
| 33 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format()); |
| 34 |
| 35 // The offsets should be set appropriately. |
| 36 EXPECT_EQ(frame->PlaneOffset(VideoFrame::kYPlane), 0u); |
| 37 EXPECT_GT(frame->PlaneOffset(VideoFrame::kUPlane), 0u); |
| 38 EXPECT_GT(frame->PlaneOffset(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, CreateFrameAndPassSharedMemory) { |
| 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->PlaneOffset(VideoFrame::kYPlane), y_offset); |
| 88 EXPECT_EQ(frame->PlaneOffset(VideoFrame::kUPlane), u_offset); |
| 89 EXPECT_EQ(frame->PlaneOffset(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 |
| 102 TEST(MojoSharedBufferVideoFrameTest, CreateFrameOddWidth) { |
| 103 const int kWidth = 15; |
| 104 const int kHeight = 9; |
| 105 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
| 106 |
| 107 // Create a MojoSharedBufferVideoFrame which will allocate enough space |
| 108 // to hold the video frame. Size should be adjusted. |
| 109 gfx::Size size(kWidth, kHeight); |
| 110 scoped_refptr<MojoSharedBufferVideoFrame> frame = |
| 111 MojoSharedBufferVideoFrame::CreateDefaultI420(size, kTimestamp); |
| 112 ASSERT_TRUE(frame.get()); |
| 113 |
| 114 // Verify that the correct frame was allocated. |
| 115 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format()); |
| 116 |
| 117 // The size should be >= 15x9. |
| 118 EXPECT_GE(frame->coded_size().width(), kWidth); |
| 119 EXPECT_GE(frame->coded_size().height(), kHeight); |
| 120 } |
| 121 |
| 122 } // namespace media |
| OLD | NEW |