OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | 6 #include "base/bind_helpers.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #else | 53 #else |
54 #define MAYBE_AllocateBadSize AllocateBadSize | 54 #define MAYBE_AllocateBadSize AllocateBadSize |
55 #define MAYBE_CaptureMjpeg CaptureMjpeg | 55 #define MAYBE_CaptureMjpeg CaptureMjpeg |
56 #endif | 56 #endif |
57 | 57 |
58 using ::testing::_; | 58 using ::testing::_; |
59 using ::testing::SaveArg; | 59 using ::testing::SaveArg; |
60 | 60 |
61 namespace media { | 61 namespace media { |
62 | 62 |
63 class MockClient : public media::VideoCaptureDevice::Client { | 63 namespace { |
| 64 |
| 65 class MockClient : public VideoCaptureDevice::Client { |
64 public: | 66 public: |
65 MOCK_METHOD2(ReserveOutputBuffer, | 67 MOCK_METHOD2(ReserveOutputBuffer, |
66 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 68 scoped_refptr<Buffer>(VideoFrame::Format format, |
67 const gfx::Size& dimensions)); | 69 const gfx::Size& dimensions)); |
68 MOCK_METHOD0(OnErr, void()); | 70 MOCK_METHOD0(OnErr, void()); |
69 | 71 |
70 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 72 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
71 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} | 73 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} |
72 | 74 |
73 virtual void OnError(const std::string& error_message) override { | 75 void OnError(const std::string& error_message) override { |
74 OnErr(); | 76 OnErr(); |
75 } | 77 } |
76 | 78 |
77 virtual void OnIncomingCapturedData(const uint8* data, | 79 void OnIncomingCapturedData(const uint8* data, |
78 int length, | 80 int length, |
79 const VideoCaptureFormat& format, | 81 const VideoCaptureFormat& format, |
80 int rotation, | 82 int rotation, |
81 base::TimeTicks timestamp) override { | 83 base::TimeTicks timestamp) override { |
82 ASSERT_GT(length, 0); | 84 ASSERT_GT(length, 0); |
83 ASSERT_TRUE(data != NULL); | 85 ASSERT_TRUE(data != NULL); |
84 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); | 86 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); |
85 } | 87 } |
86 | 88 |
87 virtual void OnIncomingCapturedVideoFrame( | 89 void OnIncomingCapturedVideoFrame( |
88 const scoped_refptr<Buffer>& buffer, | 90 const scoped_refptr<Buffer>& buffer, |
89 const media::VideoCaptureFormat& buffer_format, | 91 const VideoCaptureFormat& buffer_format, |
90 const scoped_refptr<media::VideoFrame>& frame, | 92 const scoped_refptr<VideoFrame>& frame, |
91 base::TimeTicks timestamp) override { | 93 base::TimeTicks timestamp) override { |
92 NOTREACHED(); | 94 NOTREACHED(); |
93 } | 95 } |
94 | 96 |
95 private: | 97 private: |
96 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 98 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
97 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 99 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
98 }; | 100 }; |
99 | 101 |
100 class DeviceEnumerationListener : | 102 class DeviceEnumerationListener : |
101 public base::RefCounted<DeviceEnumerationListener>{ | 103 public base::RefCounted<DeviceEnumerationListener> { |
102 public: | 104 public: |
103 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, | 105 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, |
104 void(media::VideoCaptureDevice::Names* names)); | 106 void(VideoCaptureDevice::Names* names)); |
105 // GMock doesn't support move-only arguments, so we use this forward method. | 107 // GMock doesn't support move-only arguments, so we use this forward method. |
106 void OnEnumeratedDevicesCallback( | 108 void OnEnumeratedDevicesCallback( |
107 scoped_ptr<media::VideoCaptureDevice::Names> names) { | 109 scoped_ptr<VideoCaptureDevice::Names> names) { |
108 OnEnumeratedDevicesCallbackPtr(names.release()); | 110 OnEnumeratedDevicesCallbackPtr(names.release()); |
109 } | 111 } |
110 private: | 112 private: |
111 friend class base::RefCounted<DeviceEnumerationListener>; | 113 friend class base::RefCounted<DeviceEnumerationListener>; |
112 virtual ~DeviceEnumerationListener() {} | 114 virtual ~DeviceEnumerationListener() {} |
113 }; | 115 }; |
114 | 116 |
| 117 } // namespace |
| 118 |
115 class VideoCaptureDeviceTest : public testing::Test { | 119 class VideoCaptureDeviceTest : public testing::Test { |
116 protected: | 120 protected: |
117 typedef media::VideoCaptureDevice::Client Client; | 121 typedef VideoCaptureDevice::Client Client; |
118 | 122 |
119 VideoCaptureDeviceTest() | 123 VideoCaptureDeviceTest() |
120 : loop_(new base::MessageLoop()), | 124 : loop_(new base::MessageLoop()), |
121 client_( | 125 client_( |
122 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 126 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
123 base::Unretained(this)))), | 127 base::Unretained(this)))), |
124 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( | 128 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( |
125 base::MessageLoopProxy::current())) { | 129 base::MessageLoopProxy::current())) { |
126 device_enumeration_listener_ = new DeviceEnumerationListener(); | 130 device_enumeration_listener_ = new DeviceEnumerationListener(); |
127 } | 131 } |
128 | 132 |
| 133 #if defined(OS_ANDROID) |
129 void SetUp() override { | 134 void SetUp() override { |
130 #if defined(OS_ANDROID) | 135 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
131 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | |
132 base::android::AttachCurrentThread()); | 136 base::android::AttachCurrentThread()); |
| 137 } |
133 #endif | 138 #endif |
134 } | |
135 | 139 |
136 void ResetWithNewClient() { | 140 void ResetWithNewClient() { |
137 client_.reset(new MockClient(base::Bind( | 141 client_.reset(new MockClient(base::Bind( |
138 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 142 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
139 } | 143 } |
140 | 144 |
141 void OnFrameCaptured(const VideoCaptureFormat& format) { | 145 void OnFrameCaptured(const VideoCaptureFormat& format) { |
142 last_format_ = format; | 146 last_format_ = format; |
143 run_loop_->QuitClosure().Run(); | 147 run_loop_->QuitClosure().Run(); |
144 } | 148 } |
145 | 149 |
146 void WaitForCapturedFrame() { | 150 void WaitForCapturedFrame() { |
147 run_loop_.reset(new base::RunLoop()); | 151 run_loop_.reset(new base::RunLoop()); |
148 run_loop_->Run(); | 152 run_loop_->Run(); |
149 } | 153 } |
150 | 154 |
151 scoped_ptr<media::VideoCaptureDevice::Names> EnumerateDevices() { | 155 scoped_ptr<VideoCaptureDevice::Names> EnumerateDevices() { |
152 media::VideoCaptureDevice::Names* names; | 156 VideoCaptureDevice::Names* names; |
153 EXPECT_CALL(*device_enumeration_listener_.get(), | 157 EXPECT_CALL(*device_enumeration_listener_.get(), |
154 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); | 158 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); |
155 | 159 |
156 video_capture_device_factory_->EnumerateDeviceNames( | 160 video_capture_device_factory_->EnumerateDeviceNames( |
157 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, | 161 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, |
158 device_enumeration_listener_)); | 162 device_enumeration_listener_)); |
159 base::MessageLoop::current()->RunUntilIdle(); | 163 base::MessageLoop::current()->RunUntilIdle(); |
160 return scoped_ptr<media::VideoCaptureDevice::Names>(names); | 164 return scoped_ptr<VideoCaptureDevice::Names>(names); |
161 } | 165 } |
162 | 166 |
163 const VideoCaptureFormat& last_format() const { return last_format_; } | 167 const VideoCaptureFormat& last_format() const { return last_format_; } |
164 | 168 |
165 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | 169 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
166 const VideoPixelFormat& pixel_format) { | 170 const VideoPixelFormat& pixel_format) { |
167 names_ = EnumerateDevices(); | 171 names_ = EnumerateDevices(); |
168 if (!names_->size()) { | 172 if (names_->empty()) { |
169 DVLOG(1) << "No camera available."; | 173 DVLOG(1) << "No camera available."; |
170 return scoped_ptr<VideoCaptureDevice::Name>(); | 174 return scoped_ptr<VideoCaptureDevice::Name>(); |
171 } | 175 } |
172 VideoCaptureDevice::Names::iterator names_iterator; | 176 for (const auto& names_iterator : *names_) { |
173 for (names_iterator = names_->begin(); names_iterator != names_->end(); | |
174 ++names_iterator) { | |
175 VideoCaptureFormats supported_formats; | 177 VideoCaptureFormats supported_formats; |
176 video_capture_device_factory_->GetDeviceSupportedFormats( | 178 video_capture_device_factory_->GetDeviceSupportedFormats( |
177 *names_iterator, | 179 names_iterator, |
178 &supported_formats); | 180 &supported_formats); |
179 VideoCaptureFormats::iterator formats_iterator; | 181 for (const auto& formats_iterator : supported_formats) { |
180 for (formats_iterator = supported_formats.begin(); | 182 if (formats_iterator.pixel_format == pixel_format) { |
181 formats_iterator != supported_formats.end(); ++formats_iterator) { | |
182 if (formats_iterator->pixel_format == pixel_format) { | |
183 return scoped_ptr<VideoCaptureDevice::Name>( | 183 return scoped_ptr<VideoCaptureDevice::Name>( |
184 new VideoCaptureDevice::Name(*names_iterator)); | 184 new VideoCaptureDevice::Name(names_iterator)); |
185 } | 185 } |
186 } | 186 } |
187 } | 187 } |
188 DVLOG(1) << "No camera can capture the format: " << pixel_format; | 188 DVLOG(1) << "No camera can capture the format: " << pixel_format; |
189 return scoped_ptr<VideoCaptureDevice::Name>(); | 189 return scoped_ptr<VideoCaptureDevice::Name>(); |
190 } | 190 } |
191 | 191 |
192 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
193 base::win::ScopedCOMInitializer initialize_com_; | 193 base::win::ScopedCOMInitializer initialize_com_; |
194 #endif | 194 #endif |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 capture_params.requested_format.frame_rate = 30; | 240 capture_params.requested_format.frame_rate = 30; |
241 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 241 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
242 device->AllocateAndStart(capture_params, client_.Pass()); | 242 device->AllocateAndStart(capture_params, client_.Pass()); |
243 device->StopAndDeAllocate(); | 243 device->StopAndDeAllocate(); |
244 } | 244 } |
245 #endif | 245 #endif |
246 } | 246 } |
247 | 247 |
248 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 248 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
249 names_ = EnumerateDevices(); | 249 names_ = EnumerateDevices(); |
250 if (!names_->size()) { | 250 if (names_->empty()) { |
251 DVLOG(1) << "No camera available. Exiting test."; | 251 DVLOG(1) << "No camera available. Exiting test."; |
252 return; | 252 return; |
253 } | 253 } |
254 | 254 |
255 scoped_ptr<VideoCaptureDevice> device( | 255 scoped_ptr<VideoCaptureDevice> device( |
256 video_capture_device_factory_->Create(names_->front())); | 256 video_capture_device_factory_->Create(names_->front())); |
257 ASSERT_TRUE(device); | 257 ASSERT_TRUE(device); |
258 DVLOG(1) << names_->front().id(); | 258 DVLOG(1) << names_->front().id(); |
259 | 259 |
260 EXPECT_CALL(*client_, OnErr()) | 260 EXPECT_CALL(*client_, OnErr()).Times(0); |
261 .Times(0); | |
262 | 261 |
263 VideoCaptureParams capture_params; | 262 VideoCaptureParams capture_params; |
264 capture_params.requested_format.frame_size.SetSize(640, 480); | 263 capture_params.requested_format.frame_size.SetSize(640, 480); |
265 capture_params.requested_format.frame_rate = 30; | 264 capture_params.requested_format.frame_rate = 30; |
266 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 265 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
267 device->AllocateAndStart(capture_params, client_.Pass()); | 266 device->AllocateAndStart(capture_params, client_.Pass()); |
268 // Get captured video frames. | 267 // Get captured video frames. |
269 WaitForCapturedFrame(); | 268 WaitForCapturedFrame(); |
270 EXPECT_EQ(last_format().frame_size.width(), 640); | 269 EXPECT_EQ(last_format().frame_size.width(), 640); |
271 EXPECT_EQ(last_format().frame_size.height(), 480); | 270 EXPECT_EQ(last_format().frame_size.height(), 480); |
272 device->StopAndDeAllocate(); | 271 device->StopAndDeAllocate(); |
273 } | 272 } |
274 | 273 |
275 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 274 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
276 names_ = EnumerateDevices(); | 275 names_ = EnumerateDevices(); |
277 if (!names_->size()) { | 276 if (names_->empty()) { |
278 DVLOG(1) << "No camera available. Exiting test."; | 277 DVLOG(1) << "No camera available. Exiting test."; |
279 return; | 278 return; |
280 } | 279 } |
281 | 280 |
282 scoped_ptr<VideoCaptureDevice> device( | 281 scoped_ptr<VideoCaptureDevice> device( |
283 video_capture_device_factory_->Create(names_->front())); | 282 video_capture_device_factory_->Create(names_->front())); |
284 ASSERT_TRUE(device); | 283 ASSERT_TRUE(device); |
285 | 284 |
286 EXPECT_CALL(*client_, OnErr()) | 285 EXPECT_CALL(*client_, OnErr()).Times(0); |
287 .Times(0); | |
288 | 286 |
289 VideoCaptureParams capture_params; | 287 VideoCaptureParams capture_params; |
290 capture_params.requested_format.frame_size.SetSize(1280, 720); | 288 capture_params.requested_format.frame_size.SetSize(1280, 720); |
291 capture_params.requested_format.frame_rate = 30; | 289 capture_params.requested_format.frame_rate = 30; |
292 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 290 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
293 device->AllocateAndStart(capture_params, client_.Pass()); | 291 device->AllocateAndStart(capture_params, client_.Pass()); |
294 // Get captured video frames. | 292 // Get captured video frames. |
295 WaitForCapturedFrame(); | 293 WaitForCapturedFrame(); |
296 device->StopAndDeAllocate(); | 294 device->StopAndDeAllocate(); |
297 } | 295 } |
298 | 296 |
299 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 297 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
300 names_ = EnumerateDevices(); | 298 names_ = EnumerateDevices(); |
301 if (!names_->size()) { | 299 if (names_->empty()) { |
302 DVLOG(1) << "No camera available. Exiting test."; | 300 DVLOG(1) << "No camera available. Exiting test."; |
303 return; | 301 return; |
304 } | 302 } |
305 scoped_ptr<VideoCaptureDevice> device( | 303 scoped_ptr<VideoCaptureDevice> device( |
306 video_capture_device_factory_->Create(names_->front())); | 304 video_capture_device_factory_->Create(names_->front())); |
307 ASSERT_TRUE(device); | 305 ASSERT_TRUE(device); |
308 | 306 |
309 EXPECT_CALL(*client_, OnErr()) | 307 EXPECT_CALL(*client_, OnErr()).Times(0); |
310 .Times(0); | |
311 | 308 |
312 VideoCaptureParams capture_params; | 309 VideoCaptureParams capture_params; |
313 capture_params.requested_format.frame_size.SetSize(637, 472); | 310 capture_params.requested_format.frame_size.SetSize(637, 472); |
314 capture_params.requested_format.frame_rate = 35; | 311 capture_params.requested_format.frame_rate = 35; |
315 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 312 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
316 device->AllocateAndStart(capture_params, client_.Pass()); | 313 device->AllocateAndStart(capture_params, client_.Pass()); |
317 WaitForCapturedFrame(); | 314 WaitForCapturedFrame(); |
318 device->StopAndDeAllocate(); | 315 device->StopAndDeAllocate(); |
319 EXPECT_EQ(last_format().frame_size.width(), 640); | 316 EXPECT_EQ(last_format().frame_size.width(), 640); |
320 EXPECT_EQ(last_format().frame_size.height(), 480); | 317 EXPECT_EQ(last_format().frame_size.height(), 480); |
321 } | 318 } |
322 | 319 |
323 // Cause hangs on Windows Debug. http://crbug.com/417824 | 320 // Cause hangs on Windows Debug. http://crbug.com/417824 |
324 #if defined(OS_WIN) && !defined(NDEBUG) | 321 #if defined(OS_WIN) && !defined(NDEBUG) |
325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 322 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
326 #else | 323 #else |
327 #define MAYBE_ReAllocateCamera ReAllocateCamera | 324 #define MAYBE_ReAllocateCamera ReAllocateCamera |
328 #endif | 325 #endif |
329 | 326 |
330 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { | 327 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { |
331 names_ = EnumerateDevices(); | 328 names_ = EnumerateDevices(); |
332 if (!names_->size()) { | 329 if (names_->empty()) { |
333 DVLOG(1) << "No camera available. Exiting test."; | 330 DVLOG(1) << "No camera available. Exiting test."; |
334 return; | 331 return; |
335 } | 332 } |
336 | 333 |
337 // First, do a number of very fast device start/stops. | 334 // First, do a number of very fast device start/stops. |
338 for (int i = 0; i <= 5; i++) { | 335 for (int i = 0; i <= 5; i++) { |
339 ResetWithNewClient(); | 336 ResetWithNewClient(); |
340 scoped_ptr<VideoCaptureDevice> device( | 337 scoped_ptr<VideoCaptureDevice> device( |
341 video_capture_device_factory_->Create(names_->front())); | 338 video_capture_device_factory_->Create(names_->front())); |
342 gfx::Size resolution; | 339 gfx::Size resolution; |
(...skipping 23 matching lines...) Expand all Loading... |
366 device->AllocateAndStart(capture_params, client_.Pass()); | 363 device->AllocateAndStart(capture_params, client_.Pass()); |
367 WaitForCapturedFrame(); | 364 WaitForCapturedFrame(); |
368 device->StopAndDeAllocate(); | 365 device->StopAndDeAllocate(); |
369 device.reset(); | 366 device.reset(); |
370 EXPECT_EQ(last_format().frame_size.width(), 320); | 367 EXPECT_EQ(last_format().frame_size.width(), 320); |
371 EXPECT_EQ(last_format().frame_size.height(), 240); | 368 EXPECT_EQ(last_format().frame_size.height(), 240); |
372 } | 369 } |
373 | 370 |
374 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 371 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
375 names_ = EnumerateDevices(); | 372 names_ = EnumerateDevices(); |
376 if (!names_->size()) { | 373 if (names_->empty()) { |
377 DVLOG(1) << "No camera available. Exiting test."; | 374 DVLOG(1) << "No camera available. Exiting test."; |
378 return; | 375 return; |
379 } | 376 } |
380 scoped_ptr<VideoCaptureDevice> device( | 377 scoped_ptr<VideoCaptureDevice> device( |
381 video_capture_device_factory_->Create(names_->front())); | 378 video_capture_device_factory_->Create(names_->front())); |
382 ASSERT_TRUE(device); | 379 ASSERT_TRUE(device); |
383 | 380 |
384 EXPECT_CALL(*client_, OnErr()) | 381 EXPECT_CALL(*client_, OnErr()).Times(0); |
385 .Times(0); | |
386 | 382 |
387 VideoCaptureParams capture_params; | 383 VideoCaptureParams capture_params; |
388 capture_params.requested_format.frame_size.SetSize(640, 480); | 384 capture_params.requested_format.frame_size.SetSize(640, 480); |
389 capture_params.requested_format.frame_rate = 30; | 385 capture_params.requested_format.frame_rate = 30; |
390 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 386 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
391 device->AllocateAndStart(capture_params, client_.Pass()); | 387 device->AllocateAndStart(capture_params, client_.Pass()); |
392 // Get captured video frames. | 388 // Get captured video frames. |
393 WaitForCapturedFrame(); | 389 WaitForCapturedFrame(); |
394 EXPECT_EQ(last_format().frame_size.width(), 640); | 390 EXPECT_EQ(last_format().frame_size.width(), 640); |
395 EXPECT_EQ(last_format().frame_size.height(), 480); | 391 EXPECT_EQ(last_format().frame_size.height(), 480); |
396 EXPECT_EQ(last_format().frame_rate, 30); | 392 EXPECT_EQ(last_format().frame_rate, 30); |
397 device->StopAndDeAllocate(); | 393 device->StopAndDeAllocate(); |
398 } | 394 } |
399 | 395 |
400 // Start the camera in 720p to capture MJPEG instead of a raw format. | 396 // Start the camera in 720p to capture MJPEG instead of a raw format. |
401 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 397 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
402 scoped_ptr<VideoCaptureDevice::Name> name = | 398 scoped_ptr<VideoCaptureDevice::Name> name = |
403 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 399 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
404 if (!name) { | 400 if (!name) { |
405 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 401 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
406 return; | 402 return; |
407 } | 403 } |
408 scoped_ptr<VideoCaptureDevice> device( | 404 scoped_ptr<VideoCaptureDevice> device( |
409 video_capture_device_factory_->Create(*name)); | 405 video_capture_device_factory_->Create(*name)); |
410 ASSERT_TRUE(device); | 406 ASSERT_TRUE(device); |
411 | 407 |
412 EXPECT_CALL(*client_, OnErr()) | 408 EXPECT_CALL(*client_, OnErr()).Times(0); |
413 .Times(0); | |
414 | 409 |
415 VideoCaptureParams capture_params; | 410 VideoCaptureParams capture_params; |
416 capture_params.requested_format.frame_size.SetSize(1280, 720); | 411 capture_params.requested_format.frame_size.SetSize(1280, 720); |
417 capture_params.requested_format.frame_rate = 30; | 412 capture_params.requested_format.frame_rate = 30; |
418 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 413 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
419 device->AllocateAndStart(capture_params, client_.Pass()); | 414 device->AllocateAndStart(capture_params, client_.Pass()); |
420 // Get captured video frames. | 415 // Get captured video frames. |
421 WaitForCapturedFrame(); | 416 WaitForCapturedFrame(); |
422 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 417 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
423 // @ 30 fps, so we don't care about the exact resolution we get. | 418 // @ 30 fps, so we don't care about the exact resolution we get. |
424 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 419 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
425 device->StopAndDeAllocate(); | 420 device->StopAndDeAllocate(); |
426 } | 421 } |
427 | 422 |
428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 423 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 424 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
430 // GetDeviceSupportedFormats(). | 425 // GetDeviceSupportedFormats(). |
431 scoped_ptr<VideoCaptureDevice::Name> name = | 426 scoped_ptr<VideoCaptureDevice::Name> name = |
432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 427 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
433 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 428 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
434 // since we cannot forecast the hardware capabilities. | 429 // since we cannot forecast the hardware capabilities. |
435 ASSERT_FALSE(name); | 430 ASSERT_FALSE(name); |
436 } | 431 } |
437 | 432 |
438 }; // namespace media | 433 }; // namespace media |
OLD | NEW |