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

Side by Side Diff: components/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: 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/device_client_impl.h"
8 #include "media/base/video_frame.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 DeviceClientImplTest : public testing::Test,
19 public DeviceClientImpl::Delegate {
20 public:
21 DeviceClientImplTest() : device_client_impl_(this) {}
22
23 void SetUp() override {}
24 void TearDown() override {}
25
26 // DeviceClientImpl::Delegate
27 MOCK_METHOD3(OnFrame,
28 void(const scoped_refptr<media::VideoFrame>& frame,
29 const base::TimeTicks& timestamp,
30 const base::Closure& release_callback));
31 MOCK_METHOD1(OnError, void(const std::string& reason));
32
33 void OnIncomingCapturedData(const uint8_t* data,
34 int length,
35 const media::VideoCaptureFormat& frame_format,
36 int clockwise_rotation,
37 const base::TimeTicks& timestamp) {
38 device_client_impl_.OnIncomingCapturedData(data, length, frame_format,
39 clockwise_rotation, timestamp);
40 }
41 void OnError(const tracked_objects::Location& from_here,
42 const std::string& reason) {
43 device_client_impl_.OnError(from_here, reason);
44 }
45 protected:
46 base::MessageLoop loop_;
47
48 // The mock of the (remote) video capture client.
49 DeviceClientImpl device_client_impl_;
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(DeviceClientImplTest);
53 };
54
55 TEST_F(DeviceClientImplTest, CreateAndDestroy) {
56 }
57
58 // Tests that OnError is correctly forwarded.
59 TEST_F(DeviceClientImplTest, OnError) {
60 const std::string kBigError("Kaiju-size error");
61 EXPECT_CALL(*this, OnError(kBigError)).Times(1);
62 OnError(FROM_HERE, kBigError);
63 base::RunLoop().RunUntilIdle();
64 }
65
66 // Tests that buffer-based capture API accepts all memory-backed pixel formats.
67 // Same as VideoCaptureDeviceClientTest's homonym test case.
68 TEST_F(DeviceClientImplTest, 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 for (int format = 0; format < media::PIXEL_FORMAT_MAX; ++format) {
80 // Conversion from some formats are unsupported.
81 if (format == media::PIXEL_FORMAT_UNKNOWN ||
82 format == media::PIXEL_FORMAT_YV16 ||
83 format == media::PIXEL_FORMAT_YV12A ||
84 format == media::PIXEL_FORMAT_YV24 ||
85 format == media::PIXEL_FORMAT_ARGB ||
86 format == media::PIXEL_FORMAT_XRGB ||
87 format == media::PIXEL_FORMAT_MJPEG ||
88 format == media::PIXEL_FORMAT_MT21) {
89 continue;
90 }
91 #if !defined(OS_LINUX) && !defined(OS_WIN)
92 if (format == media::PIXEL_FORMAT_RGB24){
93 continue;
94 }
95 #endif
96 media::VideoCaptureParams params;
97 params.requested_format = media::VideoCaptureFormat(
98 capture_resolution, 30.0f, media::VideoPixelFormat(format));
99
100 EXPECT_CALL(*this, OnFrame(_, _, _)).Times(1);
101 OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
102 params.requested_format, 0 /* clockwise_rotation */,
103 base::TimeTicks());
104 base::RunLoop().RunUntilIdle();
105
106 }
107 }
108
109 // Test that we receive the expected resolution for a given captured frame
110 // resolution and rotation. Odd resolutions are also cropped.
111 // Same as VideoCaptureDeviceClientTest's homonym test case.
112 TEST_F(DeviceClientImplTest, CheckRotationsAndCrops) {
113 const struct SizeAndRotation {
114 gfx::Size input_resolution;
115 int rotation;
116 gfx::Size output_resolution;
117 } kSizeAndRotations[] = {{{6, 4}, 0, {6, 4}},
118 {{6, 4}, 90, {4, 6}},
119 {{6, 4}, 180, {6, 4}},
120 {{6, 4}, 270, {4, 6}},
121 {{7, 4}, 0, {6, 4}},
122 {{7, 4}, 90, {4, 6}},
123 {{7, 4}, 180, {6, 4}},
124 {{7, 4}, 270, {4, 6}}};
125
126 // The usual ReserveOutputBuffer() -> OnIncomingCapturedVideoFrame() cannot
127 // be used since it does not resolve rotations or crops. The memory backed
128 // buffer OnIncomingCapturedData() is used instead, with a dummy scratchpad
129 // buffer.
130 const size_t kScratchpadSizeInBytes = 400;
131 unsigned char data[kScratchpadSizeInBytes] = {};
132
133 media::VideoCaptureParams params;
134 for (const auto& size_and_rotation : kSizeAndRotations) {
135 ASSERT_GE(kScratchpadSizeInBytes,
136 size_and_rotation.input_resolution.GetArea() * 4u)
137 << "Scratchpad is too small to hold the largest pixel format (ARGB).";
138 params.requested_format =
139 media::VideoCaptureFormat(size_and_rotation.input_resolution, 30.0f,
140 media::PIXEL_FORMAT_ARGB);
141
142 scoped_refptr<media::VideoFrame> frame;
143 const base::TimeTicks now = base::TimeTicks::Now();
144 EXPECT_CALL(*this, OnFrame(_, now, _))
145 .Times(1)
146 .WillOnce(SaveArg<0>(&frame));
147 OnIncomingCapturedData(data, params.requested_format.ImageAllocationSize(),
148 params.requested_format, size_and_rotation.rotation,
149 now);
150 base::RunLoop().RunUntilIdle();
151
152 EXPECT_EQ(frame->coded_size().width(),
153 size_and_rotation.output_resolution.width());
154 EXPECT_EQ(frame->coded_size().height(),
155 size_and_rotation.output_resolution.height());
156
157 }
158 }
159
160
161 } // namespace video_capture
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698