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" |
| 7 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
8 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
9 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
11 #include "media/video/capture/video_capture_device.h" | 13 #include "media/video/capture/video_capture_device.h" |
12 #include "media/video/capture/video_capture_device_factory.h" | 14 #include "media/video/capture/video_capture_device_factory.h" |
13 #include "media/video/capture/video_capture_types.h" | 15 #include "media/video/capture/video_capture_types.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 28 matching lines...) Expand all Loading... |
44 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
45 #define ReAllocateCamera DISABLED_ReAllocateCamera | 47 #define ReAllocateCamera DISABLED_ReAllocateCamera |
46 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 48 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
47 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 49 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
48 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
49 #else | 51 #else |
50 #define MAYBE_AllocateBadSize AllocateBadSize | 52 #define MAYBE_AllocateBadSize AllocateBadSize |
51 #define MAYBE_CaptureMjpeg CaptureMjpeg | 53 #define MAYBE_CaptureMjpeg CaptureMjpeg |
52 #endif | 54 #endif |
53 | 55 |
| 56 using ::testing::_; |
| 57 using ::testing::SaveArg; |
| 58 |
54 namespace media { | 59 namespace media { |
55 | 60 |
56 class MockClient : public media::VideoCaptureDevice::Client { | 61 class MockClient : public media::VideoCaptureDevice::Client { |
57 public: | 62 public: |
58 MOCK_METHOD2(ReserveOutputBuffer, | 63 MOCK_METHOD2(ReserveOutputBuffer, |
59 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 64 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
60 const gfx::Size& dimensions)); | 65 const gfx::Size& dimensions)); |
61 MOCK_METHOD0(OnErr, void()); | 66 MOCK_METHOD0(OnErr, void()); |
62 | 67 |
63 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 68 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
(...skipping 17 matching lines...) Expand all Loading... |
81 const scoped_refptr<media::VideoFrame>& frame, | 86 const scoped_refptr<media::VideoFrame>& frame, |
82 base::TimeTicks timestamp) OVERRIDE { | 87 base::TimeTicks timestamp) OVERRIDE { |
83 NOTREACHED(); | 88 NOTREACHED(); |
84 } | 89 } |
85 | 90 |
86 private: | 91 private: |
87 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 92 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
88 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 93 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
89 }; | 94 }; |
90 | 95 |
| 96 class DeviceEnumerationListener : |
| 97 public base::RefCounted<DeviceEnumerationListener>{ |
| 98 public: |
| 99 MOCK_METHOD1(OnEnumeratedDevicesCallback, |
| 100 void(const media::VideoCaptureDevice::Names& names)); |
| 101 |
| 102 private: |
| 103 friend class base::RefCounted<DeviceEnumerationListener>; |
| 104 virtual ~DeviceEnumerationListener() {} |
| 105 }; |
| 106 |
91 class VideoCaptureDeviceTest : public testing::Test { | 107 class VideoCaptureDeviceTest : public testing::Test { |
92 protected: | 108 protected: |
93 typedef media::VideoCaptureDevice::Client Client; | 109 typedef media::VideoCaptureDevice::Client Client; |
94 | 110 |
95 VideoCaptureDeviceTest() | 111 VideoCaptureDeviceTest() |
96 : loop_(new base::MessageLoop()), | 112 : loop_(new base::MessageLoop()), |
97 client_( | 113 client_( |
98 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 114 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
99 base::Unretained(this)))), | 115 base::Unretained(this)))), |
100 video_capture_device_factory_( | 116 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( |
101 VideoCaptureDeviceFactory::CreateFactory()) {} | 117 base::MessageLoopProxy::current())) { |
| 118 device_enumeration_listener_ = new DeviceEnumerationListener(); |
| 119 } |
102 | 120 |
103 virtual void SetUp() { | 121 virtual void SetUp() { |
104 #if defined(OS_ANDROID) | 122 #if defined(OS_ANDROID) |
105 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 123 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
106 base::android::AttachCurrentThread()); | 124 base::android::AttachCurrentThread()); |
107 #endif | 125 #endif |
108 } | 126 } |
109 | 127 |
110 void ResetWithNewClient() { | 128 void ResetWithNewClient() { |
111 client_.reset(new MockClient(base::Bind( | 129 client_.reset(new MockClient(base::Bind( |
112 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 130 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
113 } | 131 } |
114 | 132 |
115 void OnFrameCaptured(const VideoCaptureFormat& format) { | 133 void OnFrameCaptured(const VideoCaptureFormat& format) { |
116 last_format_ = format; | 134 last_format_ = format; |
117 run_loop_->QuitClosure().Run(); | 135 run_loop_->QuitClosure().Run(); |
118 } | 136 } |
119 | 137 |
120 void WaitForCapturedFrame() { | 138 void WaitForCapturedFrame() { |
121 run_loop_.reset(new base::RunLoop()); | 139 run_loop_.reset(new base::RunLoop()); |
122 run_loop_->Run(); | 140 run_loop_->Run(); |
123 } | 141 } |
124 | 142 |
| 143 void EnumerateDevices(VideoCaptureDevice::Names* device_names) { |
| 144 EXPECT_CALL(*device_enumeration_listener_, OnEnumeratedDevicesCallback(_)) |
| 145 .WillOnce(SaveArg<0>(device_names)); |
| 146 |
| 147 video_capture_device_factory_->EnumerateDeviceNames( |
| 148 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, |
| 149 device_enumeration_listener_)); |
| 150 base::MessageLoop::current()->RunUntilIdle(); |
| 151 } |
| 152 |
125 const VideoCaptureFormat& last_format() const { return last_format_; } | 153 const VideoCaptureFormat& last_format() const { return last_format_; } |
126 | 154 |
127 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | 155 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
128 const VideoPixelFormat& pixel_format) { | 156 const VideoPixelFormat& pixel_format) { |
129 video_capture_device_factory_->GetDeviceNames(&names_); | 157 EnumerateDevices(&names_); |
130 if (!names_.size()) { | 158 if (!names_.size()) { |
131 DVLOG(1) << "No camera available."; | 159 DVLOG(1) << "No camera available."; |
132 return scoped_ptr<VideoCaptureDevice::Name>(); | 160 return scoped_ptr<VideoCaptureDevice::Name>(); |
133 } | 161 } |
134 VideoCaptureDevice::Names::iterator names_iterator; | 162 VideoCaptureDevice::Names::iterator names_iterator; |
135 for (names_iterator = names_.begin(); names_iterator != names_.end(); | 163 for (names_iterator = names_.begin(); names_iterator != names_.end(); |
136 ++names_iterator) { | 164 ++names_iterator) { |
137 VideoCaptureFormats supported_formats; | 165 VideoCaptureFormats supported_formats; |
138 video_capture_device_factory_->GetDeviceSupportedFormats( | 166 video_capture_device_factory_->GetDeviceSupportedFormats( |
139 *names_iterator, | 167 *names_iterator, |
(...skipping 11 matching lines...) Expand all Loading... |
151 return scoped_ptr<VideoCaptureDevice::Name>(); | 179 return scoped_ptr<VideoCaptureDevice::Name>(); |
152 } | 180 } |
153 | 181 |
154 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
155 base::win::ScopedCOMInitializer initialize_com_; | 183 base::win::ScopedCOMInitializer initialize_com_; |
156 #endif | 184 #endif |
157 VideoCaptureDevice::Names names_; | 185 VideoCaptureDevice::Names names_; |
158 scoped_ptr<base::MessageLoop> loop_; | 186 scoped_ptr<base::MessageLoop> loop_; |
159 scoped_ptr<base::RunLoop> run_loop_; | 187 scoped_ptr<base::RunLoop> run_loop_; |
160 scoped_ptr<MockClient> client_; | 188 scoped_ptr<MockClient> client_; |
| 189 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
161 VideoCaptureFormat last_format_; | 190 VideoCaptureFormat last_format_; |
162 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; | 191 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
163 }; | 192 }; |
164 | 193 |
165 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 194 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
166 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
167 VideoCaptureDevice::Name::CaptureApiType api_type = | 196 VideoCaptureDevice::Name::CaptureApiType api_type = |
168 VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() | 197 VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() |
169 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | 198 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION |
170 : VideoCaptureDevice::Name::DIRECT_SHOW; | 199 : VideoCaptureDevice::Name::DIRECT_SHOW; |
171 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | 200 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
172 #elif defined(OS_MACOSX) | 201 #elif defined(OS_MACOSX) |
173 VideoCaptureDevice::Name device_name("jibberish", "jibberish", | 202 VideoCaptureDevice::Name device_name("jibberish", "jibberish", |
174 VideoCaptureDevice::Name::AVFOUNDATION); | 203 VideoCaptureDevice::Name::AVFOUNDATION); |
175 #else | 204 #else |
176 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); | 205 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); |
177 #endif | 206 #endif |
178 scoped_ptr<VideoCaptureDevice> device = | 207 scoped_ptr<VideoCaptureDevice> device = |
179 video_capture_device_factory_->Create( | 208 video_capture_device_factory_->Create(device_name); |
180 base::MessageLoopProxy::current(), | |
181 device_name); | |
182 EXPECT_TRUE(device == NULL); | 209 EXPECT_TRUE(device == NULL); |
183 } | 210 } |
184 | 211 |
185 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 212 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
186 video_capture_device_factory_->GetDeviceNames(&names_); | 213 EnumerateDevices(&names_); |
187 if (!names_.size()) { | 214 if (!names_.size()) { |
188 DVLOG(1) << "No camera available. Exiting test."; | 215 DVLOG(1) << "No camera available. Exiting test."; |
189 return; | 216 return; |
190 } | 217 } |
191 | 218 |
192 scoped_ptr<VideoCaptureDevice> device( | 219 scoped_ptr<VideoCaptureDevice> device( |
193 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 220 video_capture_device_factory_->Create(names_.front())); |
194 names_.front())); | |
195 ASSERT_TRUE(device); | 221 ASSERT_TRUE(device); |
196 DVLOG(1) << names_.front().id(); | 222 DVLOG(1) << names_.front().id(); |
197 | 223 |
198 EXPECT_CALL(*client_, OnErr()) | 224 EXPECT_CALL(*client_, OnErr()) |
199 .Times(0); | 225 .Times(0); |
200 | 226 |
201 VideoCaptureParams capture_params; | 227 VideoCaptureParams capture_params; |
202 capture_params.requested_format.frame_size.SetSize(640, 480); | 228 capture_params.requested_format.frame_size.SetSize(640, 480); |
203 capture_params.requested_format.frame_rate = 30; | 229 capture_params.requested_format.frame_rate = 30; |
204 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 230 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
205 capture_params.allow_resolution_change = false; | 231 capture_params.allow_resolution_change = false; |
206 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 232 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
207 // Get captured video frames. | 233 // Get captured video frames. |
208 WaitForCapturedFrame(); | 234 WaitForCapturedFrame(); |
209 EXPECT_EQ(last_format().frame_size.width(), 640); | 235 EXPECT_EQ(last_format().frame_size.width(), 640); |
210 EXPECT_EQ(last_format().frame_size.height(), 480); | 236 EXPECT_EQ(last_format().frame_size.height(), 480); |
211 device->StopAndDeAllocate(); | 237 device->StopAndDeAllocate(); |
212 } | 238 } |
213 | 239 |
214 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 240 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
215 video_capture_device_factory_->GetDeviceNames(&names_); | 241 EnumerateDevices(&names_); |
216 if (!names_.size()) { | 242 if (!names_.size()) { |
217 DVLOG(1) << "No camera available. Exiting test."; | 243 DVLOG(1) << "No camera available. Exiting test."; |
218 return; | 244 return; |
219 } | 245 } |
220 | 246 |
221 scoped_ptr<VideoCaptureDevice> device( | 247 scoped_ptr<VideoCaptureDevice> device( |
222 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 248 video_capture_device_factory_->Create(names_.front())); |
223 names_.front())); | |
224 ASSERT_TRUE(device); | 249 ASSERT_TRUE(device); |
225 | 250 |
226 EXPECT_CALL(*client_, OnErr()) | 251 EXPECT_CALL(*client_, OnErr()) |
227 .Times(0); | 252 .Times(0); |
228 | 253 |
229 VideoCaptureParams capture_params; | 254 VideoCaptureParams capture_params; |
230 capture_params.requested_format.frame_size.SetSize(1280, 720); | 255 capture_params.requested_format.frame_size.SetSize(1280, 720); |
231 capture_params.requested_format.frame_rate = 30; | 256 capture_params.requested_format.frame_rate = 30; |
232 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 257 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
233 capture_params.allow_resolution_change = false; | 258 capture_params.allow_resolution_change = false; |
234 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 259 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
235 // Get captured video frames. | 260 // Get captured video frames. |
236 WaitForCapturedFrame(); | 261 WaitForCapturedFrame(); |
237 device->StopAndDeAllocate(); | 262 device->StopAndDeAllocate(); |
238 } | 263 } |
239 | 264 |
240 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 265 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
241 video_capture_device_factory_->GetDeviceNames(&names_); | 266 EnumerateDevices(&names_); |
242 if (!names_.size()) { | 267 if (!names_.size()) { |
243 DVLOG(1) << "No camera available. Exiting test."; | 268 DVLOG(1) << "No camera available. Exiting test."; |
244 return; | 269 return; |
245 } | 270 } |
246 scoped_ptr<VideoCaptureDevice> device( | 271 scoped_ptr<VideoCaptureDevice> device( |
247 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 272 video_capture_device_factory_->Create(names_.front())); |
248 names_.front())); | |
249 ASSERT_TRUE(device); | 273 ASSERT_TRUE(device); |
250 | 274 |
251 EXPECT_CALL(*client_, OnErr()) | 275 EXPECT_CALL(*client_, OnErr()) |
252 .Times(0); | 276 .Times(0); |
253 | 277 |
254 VideoCaptureParams capture_params; | 278 VideoCaptureParams capture_params; |
255 capture_params.requested_format.frame_size.SetSize(637, 472); | 279 capture_params.requested_format.frame_size.SetSize(637, 472); |
256 capture_params.requested_format.frame_rate = 35; | 280 capture_params.requested_format.frame_rate = 35; |
257 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 281 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
258 capture_params.allow_resolution_change = false; | 282 capture_params.allow_resolution_change = false; |
259 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 283 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
260 WaitForCapturedFrame(); | 284 WaitForCapturedFrame(); |
261 device->StopAndDeAllocate(); | 285 device->StopAndDeAllocate(); |
262 EXPECT_EQ(last_format().frame_size.width(), 640); | 286 EXPECT_EQ(last_format().frame_size.width(), 640); |
263 EXPECT_EQ(last_format().frame_size.height(), 480); | 287 EXPECT_EQ(last_format().frame_size.height(), 480); |
264 } | 288 } |
265 | 289 |
266 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 290 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
267 video_capture_device_factory_->GetDeviceNames(&names_); | 291 EnumerateDevices(&names_); |
268 if (!names_.size()) { | 292 if (!names_.size()) { |
269 DVLOG(1) << "No camera available. Exiting test."; | 293 DVLOG(1) << "No camera available. Exiting test."; |
270 return; | 294 return; |
271 } | 295 } |
272 | 296 |
273 // First, do a number of very fast device start/stops. | 297 // First, do a number of very fast device start/stops. |
274 for (int i = 0; i <= 5; i++) { | 298 for (int i = 0; i <= 5; i++) { |
275 ResetWithNewClient(); | 299 ResetWithNewClient(); |
276 scoped_ptr<VideoCaptureDevice> device( | 300 scoped_ptr<VideoCaptureDevice> device( |
277 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 301 video_capture_device_factory_->Create(names_.front())); |
278 names_.front())); | |
279 gfx::Size resolution; | 302 gfx::Size resolution; |
280 if (i % 2) { | 303 if (i % 2) { |
281 resolution = gfx::Size(640, 480); | 304 resolution = gfx::Size(640, 480); |
282 } else { | 305 } else { |
283 resolution = gfx::Size(1280, 1024); | 306 resolution = gfx::Size(1280, 1024); |
284 } | 307 } |
285 VideoCaptureParams capture_params; | 308 VideoCaptureParams capture_params; |
286 capture_params.requested_format.frame_size = resolution; | 309 capture_params.requested_format.frame_size = resolution; |
287 capture_params.requested_format.frame_rate = 30; | 310 capture_params.requested_format.frame_rate = 30; |
288 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 311 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
289 capture_params.allow_resolution_change = false; | 312 capture_params.allow_resolution_change = false; |
290 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 313 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
291 device->StopAndDeAllocate(); | 314 device->StopAndDeAllocate(); |
292 } | 315 } |
293 | 316 |
294 // Finally, do a device start and wait for it to finish. | 317 // Finally, do a device start and wait for it to finish. |
295 VideoCaptureParams capture_params; | 318 VideoCaptureParams capture_params; |
296 capture_params.requested_format.frame_size.SetSize(320, 240); | 319 capture_params.requested_format.frame_size.SetSize(320, 240); |
297 capture_params.requested_format.frame_rate = 30; | 320 capture_params.requested_format.frame_rate = 30; |
298 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 321 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
299 capture_params.allow_resolution_change = false; | 322 capture_params.allow_resolution_change = false; |
300 | 323 |
301 ResetWithNewClient(); | 324 ResetWithNewClient(); |
302 scoped_ptr<VideoCaptureDevice> device( | 325 scoped_ptr<VideoCaptureDevice> device( |
303 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 326 video_capture_device_factory_->Create(names_.front())); |
304 names_.front())); | |
305 | 327 |
306 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 328 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
307 WaitForCapturedFrame(); | 329 WaitForCapturedFrame(); |
308 device->StopAndDeAllocate(); | 330 device->StopAndDeAllocate(); |
309 device.reset(); | 331 device.reset(); |
310 EXPECT_EQ(last_format().frame_size.width(), 320); | 332 EXPECT_EQ(last_format().frame_size.width(), 320); |
311 EXPECT_EQ(last_format().frame_size.height(), 240); | 333 EXPECT_EQ(last_format().frame_size.height(), 240); |
312 } | 334 } |
313 | 335 |
314 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 336 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
315 video_capture_device_factory_->GetDeviceNames(&names_); | 337 EnumerateDevices(&names_); |
316 if (!names_.size()) { | 338 if (!names_.size()) { |
317 DVLOG(1) << "No camera available. Exiting test."; | 339 DVLOG(1) << "No camera available. Exiting test."; |
318 return; | 340 return; |
319 } | 341 } |
320 scoped_ptr<VideoCaptureDevice> device( | 342 scoped_ptr<VideoCaptureDevice> device( |
321 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 343 video_capture_device_factory_->Create(names_.front())); |
322 names_.front())); | |
323 ASSERT_TRUE(device); | 344 ASSERT_TRUE(device); |
324 | 345 |
325 EXPECT_CALL(*client_, OnErr()) | 346 EXPECT_CALL(*client_, OnErr()) |
326 .Times(0); | 347 .Times(0); |
327 | 348 |
328 VideoCaptureParams capture_params; | 349 VideoCaptureParams capture_params; |
329 capture_params.requested_format.frame_size.SetSize(640, 480); | 350 capture_params.requested_format.frame_size.SetSize(640, 480); |
330 capture_params.requested_format.frame_rate = 30; | 351 capture_params.requested_format.frame_rate = 30; |
331 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 352 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
332 capture_params.allow_resolution_change = false; | 353 capture_params.allow_resolution_change = false; |
333 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 354 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
334 // Get captured video frames. | 355 // Get captured video frames. |
335 WaitForCapturedFrame(); | 356 WaitForCapturedFrame(); |
336 EXPECT_EQ(last_format().frame_size.width(), 640); | 357 EXPECT_EQ(last_format().frame_size.width(), 640); |
337 EXPECT_EQ(last_format().frame_size.height(), 480); | 358 EXPECT_EQ(last_format().frame_size.height(), 480); |
338 EXPECT_EQ(last_format().frame_rate, 30); | 359 EXPECT_EQ(last_format().frame_rate, 30); |
339 device->StopAndDeAllocate(); | 360 device->StopAndDeAllocate(); |
340 } | 361 } |
341 | 362 |
342 // Start the camera in 720p to capture MJPEG instead of a raw format. | 363 // Start the camera in 720p to capture MJPEG instead of a raw format. |
343 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 364 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
344 scoped_ptr<VideoCaptureDevice::Name> name = | 365 scoped_ptr<VideoCaptureDevice::Name> name = |
345 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 366 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
346 if (!name) { | 367 if (!name) { |
347 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 368 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
348 return; | 369 return; |
349 } | 370 } |
350 scoped_ptr<VideoCaptureDevice> device( | 371 scoped_ptr<VideoCaptureDevice> device( |
351 video_capture_device_factory_->Create(base::MessageLoopProxy::current(), | 372 video_capture_device_factory_->Create(*name)); |
352 *name)); | |
353 ASSERT_TRUE(device); | 373 ASSERT_TRUE(device); |
354 | 374 |
355 EXPECT_CALL(*client_, OnErr()) | 375 EXPECT_CALL(*client_, OnErr()) |
356 .Times(0); | 376 .Times(0); |
357 | 377 |
358 VideoCaptureParams capture_params; | 378 VideoCaptureParams capture_params; |
359 capture_params.requested_format.frame_size.SetSize(1280, 720); | 379 capture_params.requested_format.frame_size.SetSize(1280, 720); |
360 capture_params.requested_format.frame_rate = 30; | 380 capture_params.requested_format.frame_rate = 30; |
361 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 381 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
362 capture_params.allow_resolution_change = false; | 382 capture_params.allow_resolution_change = false; |
(...skipping 10 matching lines...) Expand all Loading... |
373 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 393 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
374 // GetDeviceSupportedFormats(). | 394 // GetDeviceSupportedFormats(). |
375 scoped_ptr<VideoCaptureDevice::Name> name = | 395 scoped_ptr<VideoCaptureDevice::Name> name = |
376 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 396 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
377 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 397 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
378 // since we cannot forecast the hardware capabilities. | 398 // since we cannot forecast the hardware capabilities. |
379 ASSERT_FALSE(name); | 399 ASSERT_FALSE(name); |
380 } | 400 } |
381 | 401 |
382 }; // namespace media | 402 }; // namespace media |
OLD | NEW |