OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | |
7 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
8 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
11 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
12 #include "media/video/capture/fake_video_capture_device.h" | 10 #include "media/video/capture/fake_video_capture_device.h" |
13 #include "media/video/capture/fake_video_capture_device_factory.h" | 11 #include "media/video/capture/fake_video_capture_device_factory.h" |
14 #include "media/video/capture/video_capture_device.h" | 12 #include "media/video/capture/video_capture_device.h" |
15 #include "media/video/capture/video_capture_types.h" | 13 #include "media/video/capture/video_capture_types.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
18 | 16 |
19 #if defined(OS_WIN) | |
20 #include "base/win/scoped_com_initializer.h" | |
21 #include "media/video/capture/win/video_capture_device_mf_win.h" | |
22 #endif | |
23 | |
24 #if defined(OS_ANDROID) | |
25 #include "base/android/jni_android.h" | |
26 #include "media/video/capture/android/video_capture_device_android.h" | |
27 #endif | |
28 | |
29 #if defined(OS_MACOSX) | |
30 // Mac/QTKit will always give you the size you ask for and this case will fail. | |
31 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | |
32 // We will always get YUYV from the Mac QTKit/AVFoundation implementations. | |
33 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | |
34 #elif defined(OS_WIN) | |
35 #define MAYBE_AllocateBadSize AllocateBadSize | |
36 // Windows currently uses DirectShow to convert from MJPEG and a raw format is | |
37 // always delivered. | |
38 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | |
39 #elif defined(OS_ANDROID) | |
40 // TODO(wjia): enable those tests on Android. | |
41 // On Android, native camera (JAVA) delivers frames on UI thread which is the | |
42 // main thread for tests. This results in no frame received by | |
43 // VideoCaptureAndroid. | |
44 #define CaptureVGA DISABLED_CaptureVGA | |
45 #define Capture720p DISABLED_Capture720p | |
46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | |
47 #define ReAllocateCamera DISABLED_ReAllocateCamera | |
48 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | |
49 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | |
50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | |
51 #else | |
52 #define MAYBE_AllocateBadSize AllocateBadSize | |
53 #define MAYBE_CaptureMjpeg CaptureMjpeg | |
54 #endif | |
55 | |
56 using ::testing::_; | 17 using ::testing::_; |
57 using ::testing::AnyNumber; | |
58 using ::testing::Return; | |
59 using ::testing::AtLeast; | |
60 | 18 |
61 namespace media { | 19 namespace media { |
62 | 20 |
63 class MockClient : public media::VideoCaptureDevice::Client { | 21 class MockClient : public media::VideoCaptureDevice::Client { |
64 public: | 22 public: |
65 MOCK_METHOD2(ReserveOutputBuffer, | 23 MOCK_METHOD2(ReserveOutputBuffer, |
66 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 24 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
67 const gfx::Size& dimensions)); | 25 const gfx::Size& dimensions)); |
68 MOCK_METHOD0(OnErr, void()); | 26 MOCK_METHOD0(OnErr, void()); |
69 | 27 |
(...skipping 18 matching lines...) Expand all Loading... |
88 const scoped_refptr<media::VideoFrame>& frame, | 46 const scoped_refptr<media::VideoFrame>& frame, |
89 base::TimeTicks timestamp) OVERRIDE { | 47 base::TimeTicks timestamp) OVERRIDE { |
90 NOTREACHED(); | 48 NOTREACHED(); |
91 } | 49 } |
92 | 50 |
93 private: | 51 private: |
94 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 52 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
95 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 53 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
96 }; | 54 }; |
97 | 55 |
98 class VideoCaptureDeviceTest : public testing::Test { | 56 class FakeVideoCaptureDeviceTest : public testing::Test { |
99 protected: | 57 protected: |
100 typedef media::VideoCaptureDevice::Client Client; | 58 typedef media::VideoCaptureDevice::Client Client; |
101 | 59 |
102 VideoCaptureDeviceTest() | 60 FakeVideoCaptureDeviceTest() |
103 : loop_(new base::MessageLoop()), | 61 : loop_(new base::MessageLoop()), |
104 client_( | 62 client_(new MockClient( |
105 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 63 base::Bind(&FakeVideoCaptureDeviceTest::OnFrameCaptured, |
106 base::Unretained(this)))), | 64 base::Unretained(this)))), |
107 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} | 65 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
108 | 66 |
109 virtual void SetUp() { | 67 virtual void SetUp() { |
110 #if defined(OS_ANDROID) | |
111 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | |
112 base::android::AttachCurrentThread()); | |
113 #endif | |
114 } | |
115 | |
116 void ResetWithNewClient() { | |
117 client_.reset(new MockClient(base::Bind( | |
118 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | |
119 } | 68 } |
120 | 69 |
121 void OnFrameCaptured(const VideoCaptureFormat& format) { | 70 void OnFrameCaptured(const VideoCaptureFormat& format) { |
122 last_format_ = format; | 71 last_format_ = format; |
123 run_loop_->QuitClosure().Run(); | 72 run_loop_->QuitClosure().Run(); |
124 } | 73 } |
125 | 74 |
126 void WaitForCapturedFrame() { | 75 void WaitForCapturedFrame() { |
127 run_loop_.reset(new base::RunLoop()); | 76 run_loop_.reset(new base::RunLoop()); |
128 run_loop_->Run(); | 77 run_loop_->Run(); |
129 } | 78 } |
130 | 79 |
131 const VideoCaptureFormat& last_format() const { return last_format_; } | 80 const VideoCaptureFormat& last_format() const { return last_format_; } |
132 | 81 |
133 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | |
134 const VideoPixelFormat& pixel_format) { | |
135 VideoCaptureDevice::GetDeviceNames(&names_); | |
136 if (!names_.size()) { | |
137 DVLOG(1) << "No camera available."; | |
138 return scoped_ptr<VideoCaptureDevice::Name>(); | |
139 } | |
140 VideoCaptureDevice::Names::iterator names_iterator; | |
141 for (names_iterator = names_.begin(); names_iterator != names_.end(); | |
142 ++names_iterator) { | |
143 VideoCaptureFormats supported_formats; | |
144 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, | |
145 &supported_formats); | |
146 VideoCaptureFormats::iterator formats_iterator; | |
147 for (formats_iterator = supported_formats.begin(); | |
148 formats_iterator != supported_formats.end(); ++formats_iterator) { | |
149 if (formats_iterator->pixel_format == pixel_format) { | |
150 return scoped_ptr<VideoCaptureDevice::Name>( | |
151 new VideoCaptureDevice::Name(*names_iterator)); | |
152 } | |
153 } | |
154 } | |
155 DVLOG(1) << "No camera can capture the format: " << pixel_format; | |
156 return scoped_ptr<VideoCaptureDevice::Name>(); | |
157 } | |
158 | |
159 #if defined(OS_WIN) | |
160 base::win::ScopedCOMInitializer initialize_com_; | |
161 #endif | |
162 VideoCaptureDevice::Names names_; | 82 VideoCaptureDevice::Names names_; |
163 scoped_ptr<base::MessageLoop> loop_; | 83 scoped_ptr<base::MessageLoop> loop_; |
164 scoped_ptr<base::RunLoop> run_loop_; | 84 scoped_ptr<base::RunLoop> run_loop_; |
165 scoped_ptr<MockClient> client_; | 85 scoped_ptr<MockClient> client_; |
166 VideoCaptureFormat last_format_; | 86 VideoCaptureFormat last_format_; |
167 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; | 87 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
168 }; | 88 }; |
169 | 89 |
170 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 90 TEST_F(FakeVideoCaptureDeviceTest, Capture) { |
171 #if defined(OS_WIN) | |
172 VideoCaptureDevice::Name::CaptureApiType api_type = | |
173 VideoCaptureDeviceMFWin::PlatformSupported() | |
174 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | |
175 : VideoCaptureDevice::Name::DIRECT_SHOW; | |
176 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | |
177 #else | |
178 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); | |
179 #endif | |
180 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | |
181 EXPECT_TRUE(device == NULL); | |
182 } | |
183 | |
184 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | |
185 VideoCaptureDevice::GetDeviceNames(&names_); | |
186 if (!names_.size()) { | |
187 DVLOG(1) << "No camera available. Exiting test."; | |
188 return; | |
189 } | |
190 | |
191 scoped_ptr<VideoCaptureDevice> device( | |
192 VideoCaptureDevice::Create(names_.front())); | |
193 ASSERT_TRUE(device); | |
194 DVLOG(1) << names_.front().id(); | |
195 | |
196 EXPECT_CALL(*client_, OnErr()) | |
197 .Times(0); | |
198 | |
199 VideoCaptureParams capture_params; | |
200 capture_params.requested_format.frame_size.SetSize(640, 480); | |
201 capture_params.requested_format.frame_rate = 30; | |
202 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
203 capture_params.allow_resolution_change = false; | |
204 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
205 // Get captured video frames. | |
206 WaitForCapturedFrame(); | |
207 EXPECT_EQ(last_format().frame_size.width(), 640); | |
208 EXPECT_EQ(last_format().frame_size.height(), 480); | |
209 device->StopAndDeAllocate(); | |
210 } | |
211 | |
212 TEST_F(VideoCaptureDeviceTest, Capture720p) { | |
213 VideoCaptureDevice::GetDeviceNames(&names_); | |
214 if (!names_.size()) { | |
215 DVLOG(1) << "No camera available. Exiting test."; | |
216 return; | |
217 } | |
218 | |
219 scoped_ptr<VideoCaptureDevice> device( | |
220 VideoCaptureDevice::Create(names_.front())); | |
221 ASSERT_TRUE(device); | |
222 | |
223 EXPECT_CALL(*client_, OnErr()) | |
224 .Times(0); | |
225 | |
226 VideoCaptureParams capture_params; | |
227 capture_params.requested_format.frame_size.SetSize(1280, 720); | |
228 capture_params.requested_format.frame_rate = 30; | |
229 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
230 capture_params.allow_resolution_change = false; | |
231 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
232 // Get captured video frames. | |
233 WaitForCapturedFrame(); | |
234 device->StopAndDeAllocate(); | |
235 } | |
236 | |
237 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | |
238 VideoCaptureDevice::GetDeviceNames(&names_); | |
239 if (!names_.size()) { | |
240 DVLOG(1) << "No camera available. Exiting test."; | |
241 return; | |
242 } | |
243 scoped_ptr<VideoCaptureDevice> device( | |
244 VideoCaptureDevice::Create(names_.front())); | |
245 ASSERT_TRUE(device); | |
246 | |
247 EXPECT_CALL(*client_, OnErr()) | |
248 .Times(0); | |
249 | |
250 VideoCaptureParams capture_params; | |
251 capture_params.requested_format.frame_size.SetSize(637, 472); | |
252 capture_params.requested_format.frame_rate = 35; | |
253 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
254 capture_params.allow_resolution_change = false; | |
255 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
256 WaitForCapturedFrame(); | |
257 device->StopAndDeAllocate(); | |
258 EXPECT_EQ(last_format().frame_size.width(), 640); | |
259 EXPECT_EQ(last_format().frame_size.height(), 480); | |
260 } | |
261 | |
262 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | |
263 VideoCaptureDevice::GetDeviceNames(&names_); | |
264 if (!names_.size()) { | |
265 DVLOG(1) << "No camera available. Exiting test."; | |
266 return; | |
267 } | |
268 | |
269 // First, do a number of very fast device start/stops. | |
270 for (int i = 0; i <= 5; i++) { | |
271 ResetWithNewClient(); | |
272 scoped_ptr<VideoCaptureDevice> device( | |
273 VideoCaptureDevice::Create(names_.front())); | |
274 gfx::Size resolution; | |
275 if (i % 2) { | |
276 resolution = gfx::Size(640, 480); | |
277 } else { | |
278 resolution = gfx::Size(1280, 1024); | |
279 } | |
280 VideoCaptureParams capture_params; | |
281 capture_params.requested_format.frame_size = resolution; | |
282 capture_params.requested_format.frame_rate = 30; | |
283 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
284 capture_params.allow_resolution_change = false; | |
285 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
286 device->StopAndDeAllocate(); | |
287 } | |
288 | |
289 // Finally, do a device start and wait for it to finish. | |
290 VideoCaptureParams capture_params; | |
291 capture_params.requested_format.frame_size.SetSize(320, 240); | |
292 capture_params.requested_format.frame_rate = 30; | |
293 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
294 capture_params.allow_resolution_change = false; | |
295 | |
296 ResetWithNewClient(); | |
297 scoped_ptr<VideoCaptureDevice> device( | |
298 VideoCaptureDevice::Create(names_.front())); | |
299 | |
300 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
301 WaitForCapturedFrame(); | |
302 device->StopAndDeAllocate(); | |
303 device.reset(); | |
304 EXPECT_EQ(last_format().frame_size.width(), 320); | |
305 EXPECT_EQ(last_format().frame_size.height(), 240); | |
306 } | |
307 | |
308 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | |
309 VideoCaptureDevice::GetDeviceNames(&names_); | |
310 if (!names_.size()) { | |
311 DVLOG(1) << "No camera available. Exiting test."; | |
312 return; | |
313 } | |
314 scoped_ptr<VideoCaptureDevice> device( | |
315 VideoCaptureDevice::Create(names_.front())); | |
316 ASSERT_TRUE(device); | |
317 | |
318 EXPECT_CALL(*client_, OnErr()) | |
319 .Times(0); | |
320 | |
321 VideoCaptureParams capture_params; | |
322 capture_params.requested_format.frame_size.SetSize(640, 480); | |
323 capture_params.requested_format.frame_rate = 30; | |
324 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
325 capture_params.allow_resolution_change = false; | |
326 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
327 // Get captured video frames. | |
328 WaitForCapturedFrame(); | |
329 EXPECT_EQ(last_format().frame_size.width(), 640); | |
330 EXPECT_EQ(last_format().frame_size.height(), 480); | |
331 EXPECT_EQ(last_format().frame_rate, 30); | |
332 device->StopAndDeAllocate(); | |
333 } | |
334 | |
335 TEST_F(VideoCaptureDeviceTest, FakeCapture) { | |
336 VideoCaptureDevice::Names names; | 91 VideoCaptureDevice::Names names; |
337 | 92 |
338 video_capture_device_factory_->GetDeviceNames(&names); | 93 video_capture_device_factory_->GetDeviceNames(&names); |
339 | 94 |
340 ASSERT_GT(static_cast<int>(names.size()), 0); | 95 ASSERT_GT(static_cast<int>(names.size()), 0); |
341 | 96 |
342 scoped_ptr<VideoCaptureDevice> device( | 97 scoped_ptr<VideoCaptureDevice> device( |
343 video_capture_device_factory_->Create(names.front())); | 98 video_capture_device_factory_->Create(names.front())); |
344 ASSERT_TRUE(device); | 99 ASSERT_TRUE(device); |
345 | 100 |
346 EXPECT_CALL(*client_, OnErr()) | 101 EXPECT_CALL(*client_, OnErr()).Times(0); |
347 .Times(0); | |
348 | 102 |
349 VideoCaptureParams capture_params; | 103 VideoCaptureParams capture_params; |
350 capture_params.requested_format.frame_size.SetSize(640, 480); | 104 capture_params.requested_format.frame_size.SetSize(640, 480); |
351 capture_params.requested_format.frame_rate = 30; | 105 capture_params.requested_format.frame_rate = 30; |
352 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 106 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
353 capture_params.allow_resolution_change = false; | 107 capture_params.allow_resolution_change = false; |
354 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 108 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
355 WaitForCapturedFrame(); | 109 WaitForCapturedFrame(); |
356 EXPECT_EQ(last_format().frame_size.width(), 640); | 110 EXPECT_EQ(last_format().frame_size.width(), 640); |
357 EXPECT_EQ(last_format().frame_size.height(), 480); | 111 EXPECT_EQ(last_format().frame_size.height(), 480); |
358 EXPECT_EQ(last_format().frame_rate, 30); | 112 EXPECT_EQ(last_format().frame_rate, 30); |
359 device->StopAndDeAllocate(); | 113 device->StopAndDeAllocate(); |
360 } | 114 } |
361 | 115 |
362 // Start the camera in 720p to capture MJPEG instead of a raw format. | 116 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
363 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 117 VideoCaptureDevice::Names names; |
364 scoped_ptr<VideoCaptureDevice::Name> name = | 118 video_capture_device_factory_->GetDeviceNames(&names); |
365 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 119 |
366 if (!name) { | 120 VideoCaptureFormats supported_formats; |
367 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 121 VideoCaptureDevice::Names::iterator names_iterator; |
368 return; | 122 |
| 123 for (names_iterator = names.begin(); names_iterator != names.end(); |
| 124 ++names_iterator) { |
| 125 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 126 *names_iterator, &supported_formats); |
| 127 EXPECT_EQ(supported_formats.size(), 3u); |
| 128 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); |
| 129 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); |
| 130 EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420); |
| 131 EXPECT_GE(supported_formats[0].frame_rate, 20); |
| 132 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); |
| 133 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); |
| 134 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); |
| 135 EXPECT_GE(supported_formats[1].frame_rate, 20); |
| 136 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); |
| 137 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); |
| 138 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); |
| 139 EXPECT_GE(supported_formats[2].frame_rate, 20); |
369 } | 140 } |
370 scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name)); | |
371 ASSERT_TRUE(device); | |
372 | |
373 EXPECT_CALL(*client_, OnErr()) | |
374 .Times(0); | |
375 | |
376 VideoCaptureParams capture_params; | |
377 capture_params.requested_format.frame_size.SetSize(1280, 720); | |
378 capture_params.requested_format.frame_rate = 30; | |
379 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | |
380 capture_params.allow_resolution_change = false; | |
381 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
382 // Get captured video frames. | |
383 WaitForCapturedFrame(); | |
384 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | |
385 // @ 30 fps, so we don't care about the exact resolution we get. | |
386 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | |
387 device->StopAndDeAllocate(); | |
388 } | 141 } |
389 | 142 |
390 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 143 TEST_F(FakeVideoCaptureDeviceTest, CaptureVariableResolution) { |
391 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | |
392 // GetDeviceSupportedFormats(). | |
393 scoped_ptr<VideoCaptureDevice::Name> name = | |
394 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | |
395 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | |
396 // since we cannot forecast the hardware capabilities. | |
397 ASSERT_FALSE(name); | |
398 } | |
399 | |
400 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { | |
401 VideoCaptureDevice::Names names; | 144 VideoCaptureDevice::Names names; |
402 | 145 |
403 video_capture_device_factory_->GetDeviceNames(&names); | 146 video_capture_device_factory_->GetDeviceNames(&names); |
404 VideoCaptureParams capture_params; | 147 VideoCaptureParams capture_params; |
405 capture_params.requested_format.frame_size.SetSize(640, 480); | 148 capture_params.requested_format.frame_size.SetSize(640, 480); |
406 capture_params.requested_format.frame_rate = 30; | 149 capture_params.requested_format.frame_rate = 30; |
407 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 150 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
408 capture_params.allow_resolution_change = true; | 151 capture_params.allow_resolution_change = true; |
409 | 152 |
410 ASSERT_GT(static_cast<int>(names.size()), 0); | 153 ASSERT_GT(static_cast<int>(names.size()), 0); |
(...skipping 16 matching lines...) Expand all Loading... |
427 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 170 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
428 | 171 |
429 // We set TimeWait to 200 action timeouts and this should be enough for at | 172 // We set TimeWait to 200 action timeouts and this should be enough for at |
430 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | 173 // least action_count/kFakeCaptureCapabilityChangePeriod calls. |
431 for (int i = 0; i < action_count; ++i) { | 174 for (int i = 0; i < action_count; ++i) { |
432 WaitForCapturedFrame(); | 175 WaitForCapturedFrame(); |
433 } | 176 } |
434 device->StopAndDeAllocate(); | 177 device->StopAndDeAllocate(); |
435 } | 178 } |
436 | 179 |
437 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) { | |
438 VideoCaptureDevice::Names names; | |
439 video_capture_device_factory_->GetDeviceNames(&names); | |
440 | |
441 VideoCaptureFormats supported_formats; | |
442 VideoCaptureDevice::Names::iterator names_iterator; | |
443 | |
444 for (names_iterator = names.begin(); names_iterator != names.end(); | |
445 ++names_iterator) { | |
446 video_capture_device_factory_->GetDeviceSupportedFormats( | |
447 *names_iterator, &supported_formats); | |
448 EXPECT_EQ(supported_formats.size(), 3u); | |
449 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); | |
450 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); | |
451 EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420); | |
452 EXPECT_GE(supported_formats[0].frame_rate, 20); | |
453 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); | |
454 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); | |
455 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); | |
456 EXPECT_GE(supported_formats[1].frame_rate, 20); | |
457 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); | |
458 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); | |
459 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); | |
460 EXPECT_GE(supported_formats[2].frame_rate, 20); | |
461 } | |
462 } | |
463 | |
464 }; // namespace media | 180 }; // namespace media |
OLD | NEW |