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

Side by Side Diff: components/video_capture/video_capture_device_client_impl_unittest.cc

Issue 1637793004: [WIP] Mojo Video Capture thingy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rockot@ comments 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 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 "base/bind.h"
6 #include "base/run_loop.h"
7 #include "components/video_capture/mojo_video_frame.h"
8 #include "components/video_capture/video_capture_device_client_impl.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using ::testing::_;
13 using ::testing::InSequence;
14 using ::testing::SaveArg;
15
16 namespace video_capture {
17
18 class VideoCaptureDeviceClientImplTest : public testing::Test,
19 public VideoCaptureDeviceClientImpl::Delegate {
20 public:
21 VideoCaptureDeviceClientImplTest() : device_client_impl_(this) {}
22
23 void SetUp() override {}
24 void TearDown() override {}
25
26 // VideoCaptureDeviceClientImpl::Delegate
27 MOCK_METHOD2(OnFrame,
28 void(const scoped_refptr<MojoVideoFrame>& frame,
29 const base::TimeTicks& timestamp));
30 MOCK_METHOD1(OnError, void(const std::string& reason));
31
32 void OnIncomingCapturedData(const uint8_t* data,
33 int length,
34 const media::VideoCaptureFormat& frame_format,
35 int clockwise_rotation,
36 const base::TimeTicks& timestamp) {
37 device_client_impl_.OnIncomingCapturedData(data, length, frame_format,
38 clockwise_rotation, timestamp);
39 }
40 void OnError(const tracked_objects::Location& from_here,
41 const std::string& reason) {
42 device_client_impl_.OnError(from_here, reason);
43 }
44 protected:
45 base::MessageLoop loop_;
46
47 // The mock of the (remote) video capture client.
48 VideoCaptureDeviceClientImpl device_client_impl_;
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientImplTest);
52 };
53
54 TEST_F(VideoCaptureDeviceClientImplTest, CreateAndDestroy) {
55 }
56
57 // Tests that OnError is correctly forwarded.
58 TEST_F(VideoCaptureDeviceClientImplTest, OnError) {
59 const std::string kBigError("Kaiju-size error");
60 EXPECT_CALL(*this, OnError(kBigError)).Times(1);
61 OnError(FROM_HERE, kBigError);
62 base::RunLoop().RunUntilIdle();
63 }
64
65 // Tests that buffer-based capture API accepts all memory-backed pixel formats.
66 // Same as VideoCaptureDeviceClientTest's homonym test case.
67 TEST_F(VideoCaptureDeviceClientImplTest,
68 DataCaptureInEachVideoFormatInSequence) {
69 // The usual ReserveOutputBuffer() -> OnIncomingCapturedVideoFrame() cannot
70 // be used since it does not accept all pixel formats. The memory backed
71 // buffer OnIncomingCapturedData() is used instead, with a dummy scratchpad
72 // buffer.
73 const size_t kScratchpadSizeInBytes = 400;
74 unsigned char data[kScratchpadSizeInBytes] = {};
75 const gfx::Size capture_resolution(10, 10);
76 ASSERT_GE(kScratchpadSizeInBytes, capture_resolution.GetArea() * 4u)
77 << "Scratchpad is too small to hold the largest pixel format (ARGB).";
78
79 const media::VideoPixelFormat kSupportedFormats[] = {
80 media::PIXEL_FORMAT_I420,
81 media::PIXEL_FORMAT_YV12,
82 media::PIXEL_FORMAT_NV12,
83 media::PIXEL_FORMAT_NV21,
84 media::PIXEL_FORMAT_YUY2,
85 media::PIXEL_FORMAT_UYVY,
86 #if defined(OS_LINUX) || defined(OS_WIN)
87 media::PIXEL_FORMAT_RGB24,
88 #endif
89 media::PIXEL_FORMAT_RGB32,
90 media::PIXEL_FORMAT_ARGB
91 };
92
93 for (media::VideoPixelFormat format : kSupportedFormats) {
94 media::VideoCaptureParams params;
95 params.requested_format =
96 media::VideoCaptureFormat(capture_resolution, 30.0f, format);
97
98 scoped_refptr<MojoVideoFrame> frame;
99 const base::TimeTicks now = base::TimeTicks::Now();
100
101 EXPECT_CALL(*this, OnFrame(_, now))
102 .Times(1)
103 .WillOnce(SaveArg<0>(&frame));
104 OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
105 params.requested_format, 0 /* clockwise_rotation */,
106 now);
107 base::RunLoop().RunUntilIdle();
108
109 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame->format());
110 EXPECT_EQ(10, frame->coded_size().width());
111 EXPECT_EQ(10, frame->coded_size().height());
112 }
113 }
114
115 // Test that we receive the expected resolution for a given captured frame
116 // resolution and rotation. Odd resolutions are also cropped.
117 // Same as VideoCaptureDeviceClientTest's homonym test case.
118 TEST_F(VideoCaptureDeviceClientImplTest, CheckRotationsAndCrops) {
119 const struct SizeAndRotation {
120 gfx::Size input_resolution;
121 int rotation;
122 gfx::Size output_resolution;
123 } kSizeAndRotations[] = {{{6, 4}, 0, {6, 4}},
124 {{6, 4}, 90, {4, 6}},
125 {{6, 4}, 180, {6, 4}},
126 {{6, 4}, 270, {4, 6}},
127 {{7, 4}, 0, {6, 4}},
128 {{7, 4}, 90, {4, 6}},
129 {{7, 4}, 180, {6, 4}},
130 {{7, 4}, 270, {4, 6}}};
131
132 // The usual ReserveOutputBuffer() -> OnIncomingCapturedVideoFrame() cannot
133 // be used since it does not resolve rotations or crops. The memory backed
134 // buffer OnIncomingCapturedData() is used instead, with a dummy scratchpad
135 // buffer.
136 const size_t kScratchpadSizeInBytes = 400;
137 unsigned char data[kScratchpadSizeInBytes] = {};
138
139 media::VideoCaptureParams params;
140 for (const auto& size_and_rotation : kSizeAndRotations) {
141 ASSERT_GE(kScratchpadSizeInBytes,
142 size_and_rotation.input_resolution.GetArea() * 4u)
143 << "Scratchpad is too small to hold the largest pixel format (ARGB).";
144 params.requested_format =
145 media::VideoCaptureFormat(size_and_rotation.input_resolution, 30.0f,
146 media::PIXEL_FORMAT_ARGB);
147
148 scoped_refptr<MojoVideoFrame> frame;
149 const base::TimeTicks now = base::TimeTicks::Now();
150 EXPECT_CALL(*this, OnFrame(_, now))
151 .Times(1)
152 .WillOnce(SaveArg<0>(&frame));
153 OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
154 params.requested_format, size_and_rotation.rotation,
155 now);
156 base::RunLoop().RunUntilIdle();
157
158 EXPECT_EQ(frame->coded_size().width(),
159 size_and_rotation.output_resolution.width());
160 EXPECT_EQ(frame->coded_size().height(),
161 size_and_rotation.output_resolution.height());
162 }
163 }
164
165
166 } // namespace video_capture
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698