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/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" | |
13 #include "media/video/capture/fake_video_capture_device_factory.h" | |
14 #include "media/video/capture/video_capture_device.h" | 10 #include "media/video/capture/video_capture_device.h" |
11 #include "media/video/capture/video_capture_device_factory.h" | |
15 #include "media/video/capture/video_capture_types.h" | 12 #include "media/video/capture/video_capture_types.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
18 | 15 |
19 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
20 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
21 #include "media/video/capture/win/video_capture_device_mf_win.h" | 18 #include "media/video/capture/win/video_capture_device_mf_win.h" |
22 #endif | 19 #endif |
23 | 20 |
24 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
(...skipping 21 matching lines...) Expand all Loading... | |
46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 43 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
47 #define ReAllocateCamera DISABLED_ReAllocateCamera | 44 #define ReAllocateCamera DISABLED_ReAllocateCamera |
48 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 45 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
49 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 46 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 47 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
51 #else | 48 #else |
52 #define MAYBE_AllocateBadSize AllocateBadSize | 49 #define MAYBE_AllocateBadSize AllocateBadSize |
53 #define MAYBE_CaptureMjpeg CaptureMjpeg | 50 #define MAYBE_CaptureMjpeg CaptureMjpeg |
54 #endif | 51 #endif |
55 | 52 |
56 using ::testing::_; | |
57 using ::testing::AnyNumber; | |
58 using ::testing::Return; | |
59 using ::testing::AtLeast; | |
60 | |
61 namespace media { | 53 namespace media { |
62 | 54 |
63 class MockClient : public media::VideoCaptureDevice::Client { | 55 class MockClient : public media::VideoCaptureDevice::Client { |
64 public: | 56 public: |
65 MOCK_METHOD2(ReserveOutputBuffer, | 57 MOCK_METHOD2(ReserveOutputBuffer, |
66 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 58 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
67 const gfx::Size& dimensions)); | 59 const gfx::Size& dimensions)); |
68 MOCK_METHOD0(OnErr, void()); | 60 MOCK_METHOD0(OnErr, void()); |
69 | 61 |
70 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 62 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
(...skipping 26 matching lines...) Expand all Loading... | |
97 | 89 |
98 class VideoCaptureDeviceTest : public testing::Test { | 90 class VideoCaptureDeviceTest : public testing::Test { |
99 protected: | 91 protected: |
100 typedef media::VideoCaptureDevice::Client Client; | 92 typedef media::VideoCaptureDevice::Client Client; |
101 | 93 |
102 VideoCaptureDeviceTest() | 94 VideoCaptureDeviceTest() |
103 : loop_(new base::MessageLoop()), | 95 : loop_(new base::MessageLoop()), |
104 client_( | 96 client_( |
105 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 97 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
106 base::Unretained(this)))), | 98 base::Unretained(this)))), |
107 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} | 99 video_capture_device_factory_(new VideoCaptureDeviceFactory()) {} |
mcasas
2014/05/06 12:47:21
Should use VideoCaptureDeviceFactory::CreateFactor
| |
108 | 100 |
109 virtual void SetUp() { | 101 virtual void SetUp() { |
110 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
111 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 103 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
112 base::android::AttachCurrentThread()); | 104 base::android::AttachCurrentThread()); |
113 #endif | 105 #endif |
114 } | 106 } |
115 | 107 |
116 void ResetWithNewClient() { | 108 void ResetWithNewClient() { |
117 client_.reset(new MockClient(base::Bind( | 109 client_.reset(new MockClient(base::Bind( |
118 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 110 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
119 } | 111 } |
120 | 112 |
121 void OnFrameCaptured(const VideoCaptureFormat& format) { | 113 void OnFrameCaptured(const VideoCaptureFormat& format) { |
122 last_format_ = format; | 114 last_format_ = format; |
123 run_loop_->QuitClosure().Run(); | 115 run_loop_->QuitClosure().Run(); |
124 } | 116 } |
125 | 117 |
126 void WaitForCapturedFrame() { | 118 void WaitForCapturedFrame() { |
127 run_loop_.reset(new base::RunLoop()); | 119 run_loop_.reset(new base::RunLoop()); |
128 run_loop_->Run(); | 120 run_loop_->Run(); |
129 } | 121 } |
130 | 122 |
131 const VideoCaptureFormat& last_format() const { return last_format_; } | 123 const VideoCaptureFormat& last_format() const { return last_format_; } |
132 | 124 |
133 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | 125 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
134 const VideoPixelFormat& pixel_format) { | 126 const VideoPixelFormat& pixel_format) { |
135 VideoCaptureDevice::GetDeviceNames(&names_); | 127 video_capture_device_factory_->GetDeviceNames(&names_); |
136 if (!names_.size()) { | 128 if (!names_.size()) { |
137 DVLOG(1) << "No camera available."; | 129 DVLOG(1) << "No camera available."; |
138 return scoped_ptr<VideoCaptureDevice::Name>(); | 130 return scoped_ptr<VideoCaptureDevice::Name>(); |
139 } | 131 } |
140 VideoCaptureDevice::Names::iterator names_iterator; | 132 VideoCaptureDevice::Names::iterator names_iterator; |
141 for (names_iterator = names_.begin(); names_iterator != names_.end(); | 133 for (names_iterator = names_.begin(); names_iterator != names_.end(); |
142 ++names_iterator) { | 134 ++names_iterator) { |
143 VideoCaptureFormats supported_formats; | 135 VideoCaptureFormats supported_formats; |
144 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, | 136 video_capture_device_factory_->GetDeviceSupportedFormats( |
145 &supported_formats); | 137 *names_iterator, |
138 &supported_formats); | |
146 VideoCaptureFormats::iterator formats_iterator; | 139 VideoCaptureFormats::iterator formats_iterator; |
147 for (formats_iterator = supported_formats.begin(); | 140 for (formats_iterator = supported_formats.begin(); |
148 formats_iterator != supported_formats.end(); ++formats_iterator) { | 141 formats_iterator != supported_formats.end(); ++formats_iterator) { |
149 if (formats_iterator->pixel_format == pixel_format) { | 142 if (formats_iterator->pixel_format == pixel_format) { |
150 return scoped_ptr<VideoCaptureDevice::Name>( | 143 return scoped_ptr<VideoCaptureDevice::Name>( |
151 new VideoCaptureDevice::Name(*names_iterator)); | 144 new VideoCaptureDevice::Name(*names_iterator)); |
152 } | 145 } |
153 } | 146 } |
154 } | 147 } |
155 DVLOG(1) << "No camera can capture the format: " << pixel_format; | 148 DVLOG(1) << "No camera can capture the format: " << pixel_format; |
(...skipping 14 matching lines...) Expand all Loading... | |
170 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 163 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
171 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
172 VideoCaptureDevice::Name::CaptureApiType api_type = | 165 VideoCaptureDevice::Name::CaptureApiType api_type = |
173 VideoCaptureDeviceMFWin::PlatformSupported() | 166 VideoCaptureDeviceMFWin::PlatformSupported() |
174 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | 167 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION |
175 : VideoCaptureDevice::Name::DIRECT_SHOW; | 168 : VideoCaptureDevice::Name::DIRECT_SHOW; |
176 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | 169 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
177 #else | 170 #else |
178 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); | 171 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); |
179 #endif | 172 #endif |
180 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 173 scoped_ptr<VideoCaptureDevice> device = |
174 video_capture_device_factory_->Create(device_name); | |
181 EXPECT_TRUE(device == NULL); | 175 EXPECT_TRUE(device == NULL); |
182 } | 176 } |
183 | 177 |
184 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 178 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
185 VideoCaptureDevice::GetDeviceNames(&names_); | 179 video_capture_device_factory_->GetDeviceNames(&names_); |
186 if (!names_.size()) { | 180 if (!names_.size()) { |
187 DVLOG(1) << "No camera available. Exiting test."; | 181 DVLOG(1) << "No camera available. Exiting test."; |
188 return; | 182 return; |
189 } | 183 } |
190 | 184 |
191 scoped_ptr<VideoCaptureDevice> device( | 185 scoped_ptr<VideoCaptureDevice> device( |
192 VideoCaptureDevice::Create(names_.front())); | 186 video_capture_device_factory_->Create(names_.front())); |
193 ASSERT_TRUE(device); | 187 ASSERT_TRUE(device); |
194 DVLOG(1) << names_.front().id(); | 188 DVLOG(1) << names_.front().id(); |
195 | 189 |
196 EXPECT_CALL(*client_, OnErr()) | 190 EXPECT_CALL(*client_, OnErr()) |
197 .Times(0); | 191 .Times(0); |
198 | 192 |
199 VideoCaptureParams capture_params; | 193 VideoCaptureParams capture_params; |
200 capture_params.requested_format.frame_size.SetSize(640, 480); | 194 capture_params.requested_format.frame_size.SetSize(640, 480); |
201 capture_params.requested_format.frame_rate = 30; | 195 capture_params.requested_format.frame_rate = 30; |
202 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 196 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
203 capture_params.allow_resolution_change = false; | 197 capture_params.allow_resolution_change = false; |
204 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 198 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
205 // Get captured video frames. | 199 // Get captured video frames. |
206 WaitForCapturedFrame(); | 200 WaitForCapturedFrame(); |
207 EXPECT_EQ(last_format().frame_size.width(), 640); | 201 EXPECT_EQ(last_format().frame_size.width(), 640); |
208 EXPECT_EQ(last_format().frame_size.height(), 480); | 202 EXPECT_EQ(last_format().frame_size.height(), 480); |
209 device->StopAndDeAllocate(); | 203 device->StopAndDeAllocate(); |
210 } | 204 } |
211 | 205 |
212 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 206 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
213 VideoCaptureDevice::GetDeviceNames(&names_); | 207 video_capture_device_factory_->GetDeviceNames(&names_); |
214 if (!names_.size()) { | 208 if (!names_.size()) { |
215 DVLOG(1) << "No camera available. Exiting test."; | 209 DVLOG(1) << "No camera available. Exiting test."; |
216 return; | 210 return; |
217 } | 211 } |
218 | 212 |
219 scoped_ptr<VideoCaptureDevice> device( | 213 scoped_ptr<VideoCaptureDevice> device( |
220 VideoCaptureDevice::Create(names_.front())); | 214 video_capture_device_factory_->Create(names_.front())); |
221 ASSERT_TRUE(device); | 215 ASSERT_TRUE(device); |
222 | 216 |
223 EXPECT_CALL(*client_, OnErr()) | 217 EXPECT_CALL(*client_, OnErr()) |
224 .Times(0); | 218 .Times(0); |
225 | 219 |
226 VideoCaptureParams capture_params; | 220 VideoCaptureParams capture_params; |
227 capture_params.requested_format.frame_size.SetSize(1280, 720); | 221 capture_params.requested_format.frame_size.SetSize(1280, 720); |
228 capture_params.requested_format.frame_rate = 30; | 222 capture_params.requested_format.frame_rate = 30; |
229 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 223 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
230 capture_params.allow_resolution_change = false; | 224 capture_params.allow_resolution_change = false; |
231 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 225 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
232 // Get captured video frames. | 226 // Get captured video frames. |
233 WaitForCapturedFrame(); | 227 WaitForCapturedFrame(); |
234 device->StopAndDeAllocate(); | 228 device->StopAndDeAllocate(); |
235 } | 229 } |
236 | 230 |
237 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 231 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
238 VideoCaptureDevice::GetDeviceNames(&names_); | 232 video_capture_device_factory_->GetDeviceNames(&names_); |
239 if (!names_.size()) { | 233 if (!names_.size()) { |
240 DVLOG(1) << "No camera available. Exiting test."; | 234 DVLOG(1) << "No camera available. Exiting test."; |
241 return; | 235 return; |
242 } | 236 } |
243 scoped_ptr<VideoCaptureDevice> device( | 237 scoped_ptr<VideoCaptureDevice> device( |
244 VideoCaptureDevice::Create(names_.front())); | 238 video_capture_device_factory_->Create(names_.front())); |
245 ASSERT_TRUE(device); | 239 ASSERT_TRUE(device); |
246 | 240 |
247 EXPECT_CALL(*client_, OnErr()) | 241 EXPECT_CALL(*client_, OnErr()) |
248 .Times(0); | 242 .Times(0); |
249 | 243 |
250 VideoCaptureParams capture_params; | 244 VideoCaptureParams capture_params; |
251 capture_params.requested_format.frame_size.SetSize(637, 472); | 245 capture_params.requested_format.frame_size.SetSize(637, 472); |
252 capture_params.requested_format.frame_rate = 35; | 246 capture_params.requested_format.frame_rate = 35; |
253 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 247 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
254 capture_params.allow_resolution_change = false; | 248 capture_params.allow_resolution_change = false; |
255 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 249 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
256 WaitForCapturedFrame(); | 250 WaitForCapturedFrame(); |
257 device->StopAndDeAllocate(); | 251 device->StopAndDeAllocate(); |
258 EXPECT_EQ(last_format().frame_size.width(), 640); | 252 EXPECT_EQ(last_format().frame_size.width(), 640); |
259 EXPECT_EQ(last_format().frame_size.height(), 480); | 253 EXPECT_EQ(last_format().frame_size.height(), 480); |
260 } | 254 } |
261 | 255 |
262 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 256 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
263 VideoCaptureDevice::GetDeviceNames(&names_); | 257 video_capture_device_factory_->GetDeviceNames(&names_); |
264 if (!names_.size()) { | 258 if (!names_.size()) { |
265 DVLOG(1) << "No camera available. Exiting test."; | 259 DVLOG(1) << "No camera available. Exiting test."; |
266 return; | 260 return; |
267 } | 261 } |
268 | 262 |
269 // First, do a number of very fast device start/stops. | 263 // First, do a number of very fast device start/stops. |
270 for (int i = 0; i <= 5; i++) { | 264 for (int i = 0; i <= 5; i++) { |
271 ResetWithNewClient(); | 265 ResetWithNewClient(); |
272 scoped_ptr<VideoCaptureDevice> device( | 266 scoped_ptr<VideoCaptureDevice> device( |
273 VideoCaptureDevice::Create(names_.front())); | 267 video_capture_device_factory_->Create(names_.front())); |
274 gfx::Size resolution; | 268 gfx::Size resolution; |
275 if (i % 2) { | 269 if (i % 2) { |
276 resolution = gfx::Size(640, 480); | 270 resolution = gfx::Size(640, 480); |
277 } else { | 271 } else { |
278 resolution = gfx::Size(1280, 1024); | 272 resolution = gfx::Size(1280, 1024); |
279 } | 273 } |
280 VideoCaptureParams capture_params; | 274 VideoCaptureParams capture_params; |
281 capture_params.requested_format.frame_size = resolution; | 275 capture_params.requested_format.frame_size = resolution; |
282 capture_params.requested_format.frame_rate = 30; | 276 capture_params.requested_format.frame_rate = 30; |
283 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 277 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
284 capture_params.allow_resolution_change = false; | 278 capture_params.allow_resolution_change = false; |
285 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 279 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
286 device->StopAndDeAllocate(); | 280 device->StopAndDeAllocate(); |
287 } | 281 } |
288 | 282 |
289 // Finally, do a device start and wait for it to finish. | 283 // Finally, do a device start and wait for it to finish. |
290 VideoCaptureParams capture_params; | 284 VideoCaptureParams capture_params; |
291 capture_params.requested_format.frame_size.SetSize(320, 240); | 285 capture_params.requested_format.frame_size.SetSize(320, 240); |
292 capture_params.requested_format.frame_rate = 30; | 286 capture_params.requested_format.frame_rate = 30; |
293 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 287 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
294 capture_params.allow_resolution_change = false; | 288 capture_params.allow_resolution_change = false; |
295 | 289 |
296 ResetWithNewClient(); | 290 ResetWithNewClient(); |
297 scoped_ptr<VideoCaptureDevice> device( | 291 scoped_ptr<VideoCaptureDevice> device( |
298 VideoCaptureDevice::Create(names_.front())); | 292 video_capture_device_factory_->Create(names_.front())); |
299 | 293 |
300 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 294 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
301 WaitForCapturedFrame(); | 295 WaitForCapturedFrame(); |
302 device->StopAndDeAllocate(); | 296 device->StopAndDeAllocate(); |
303 device.reset(); | 297 device.reset(); |
304 EXPECT_EQ(last_format().frame_size.width(), 320); | 298 EXPECT_EQ(last_format().frame_size.width(), 320); |
305 EXPECT_EQ(last_format().frame_size.height(), 240); | 299 EXPECT_EQ(last_format().frame_size.height(), 240); |
306 } | 300 } |
307 | 301 |
308 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 302 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
309 VideoCaptureDevice::GetDeviceNames(&names_); | 303 video_capture_device_factory_->GetDeviceNames(&names_); |
310 if (!names_.size()) { | 304 if (!names_.size()) { |
311 DVLOG(1) << "No camera available. Exiting test."; | 305 DVLOG(1) << "No camera available. Exiting test."; |
312 return; | 306 return; |
313 } | 307 } |
314 scoped_ptr<VideoCaptureDevice> device( | 308 scoped_ptr<VideoCaptureDevice> device( |
315 VideoCaptureDevice::Create(names_.front())); | 309 video_capture_device_factory_->Create(names_.front())); |
316 ASSERT_TRUE(device); | 310 ASSERT_TRUE(device); |
317 | 311 |
318 EXPECT_CALL(*client_, OnErr()) | 312 EXPECT_CALL(*client_, OnErr()) |
319 .Times(0); | 313 .Times(0); |
320 | 314 |
321 VideoCaptureParams capture_params; | 315 VideoCaptureParams capture_params; |
322 capture_params.requested_format.frame_size.SetSize(640, 480); | 316 capture_params.requested_format.frame_size.SetSize(640, 480); |
323 capture_params.requested_format.frame_rate = 30; | 317 capture_params.requested_format.frame_rate = 30; |
324 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 318 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
325 capture_params.allow_resolution_change = false; | 319 capture_params.allow_resolution_change = false; |
326 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 320 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
327 // Get captured video frames. | 321 // Get captured video frames. |
328 WaitForCapturedFrame(); | 322 WaitForCapturedFrame(); |
329 EXPECT_EQ(last_format().frame_size.width(), 640); | 323 EXPECT_EQ(last_format().frame_size.width(), 640); |
330 EXPECT_EQ(last_format().frame_size.height(), 480); | 324 EXPECT_EQ(last_format().frame_size.height(), 480); |
331 EXPECT_EQ(last_format().frame_rate, 30); | 325 EXPECT_EQ(last_format().frame_rate, 30); |
332 device->StopAndDeAllocate(); | 326 device->StopAndDeAllocate(); |
333 } | 327 } |
334 | 328 |
335 TEST_F(VideoCaptureDeviceTest, FakeCapture) { | |
336 VideoCaptureDevice::Names names; | |
337 | |
338 video_capture_device_factory_->GetDeviceNames(&names); | |
339 | |
340 ASSERT_GT(static_cast<int>(names.size()), 0); | |
341 | |
342 scoped_ptr<VideoCaptureDevice> device( | |
343 video_capture_device_factory_->Create(names.front())); | |
344 ASSERT_TRUE(device); | |
345 | |
346 EXPECT_CALL(*client_, OnErr()) | |
347 .Times(0); | |
348 | |
349 VideoCaptureParams capture_params; | |
350 capture_params.requested_format.frame_size.SetSize(640, 480); | |
351 capture_params.requested_format.frame_rate = 30; | |
352 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
353 capture_params.allow_resolution_change = false; | |
354 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
355 WaitForCapturedFrame(); | |
356 EXPECT_EQ(last_format().frame_size.width(), 640); | |
357 EXPECT_EQ(last_format().frame_size.height(), 480); | |
358 EXPECT_EQ(last_format().frame_rate, 30); | |
359 device->StopAndDeAllocate(); | |
360 } | |
361 | |
362 // Start the camera in 720p to capture MJPEG instead of a raw format. | 329 // Start the camera in 720p to capture MJPEG instead of a raw format. |
363 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 330 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
364 scoped_ptr<VideoCaptureDevice::Name> name = | 331 scoped_ptr<VideoCaptureDevice::Name> name = |
365 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 332 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
366 if (!name) { | 333 if (!name) { |
367 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 334 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
368 return; | 335 return; |
369 } | 336 } |
370 scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name)); | 337 scoped_ptr<VideoCaptureDevice> device( |
338 video_capture_device_factory_->Create(*name)); | |
371 ASSERT_TRUE(device); | 339 ASSERT_TRUE(device); |
372 | 340 |
373 EXPECT_CALL(*client_, OnErr()) | 341 EXPECT_CALL(*client_, OnErr()) |
374 .Times(0); | 342 .Times(0); |
375 | 343 |
376 VideoCaptureParams capture_params; | 344 VideoCaptureParams capture_params; |
377 capture_params.requested_format.frame_size.SetSize(1280, 720); | 345 capture_params.requested_format.frame_size.SetSize(1280, 720); |
378 capture_params.requested_format.frame_rate = 30; | 346 capture_params.requested_format.frame_rate = 30; |
379 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 347 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
380 capture_params.allow_resolution_change = false; | 348 capture_params.allow_resolution_change = false; |
381 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 349 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
382 // Get captured video frames. | 350 // Get captured video frames. |
383 WaitForCapturedFrame(); | 351 WaitForCapturedFrame(); |
384 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 352 // 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. | 353 // @ 30 fps, so we don't care about the exact resolution we get. |
386 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 354 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
387 device->StopAndDeAllocate(); | 355 device->StopAndDeAllocate(); |
388 } | 356 } |
389 | 357 |
390 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 358 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
391 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 359 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
392 // GetDeviceSupportedFormats(). | 360 // GetDeviceSupportedFormats(). |
393 scoped_ptr<VideoCaptureDevice::Name> name = | 361 scoped_ptr<VideoCaptureDevice::Name> name = |
394 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 362 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
395 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 363 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
396 // since we cannot forecast the hardware capabilities. | 364 // since we cannot forecast the hardware capabilities. |
397 ASSERT_FALSE(name); | 365 ASSERT_FALSE(name); |
398 } | 366 } |
399 | 367 |
400 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { | |
401 VideoCaptureDevice::Names names; | |
402 | |
403 video_capture_device_factory_->GetDeviceNames(&names); | |
404 VideoCaptureParams capture_params; | |
405 capture_params.requested_format.frame_size.SetSize(640, 480); | |
406 capture_params.requested_format.frame_rate = 30; | |
407 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
408 capture_params.allow_resolution_change = true; | |
409 | |
410 ASSERT_GT(static_cast<int>(names.size()), 0); | |
411 | |
412 scoped_ptr<VideoCaptureDevice> device( | |
413 video_capture_device_factory_->Create(names.front())); | |
414 ASSERT_TRUE(device); | |
415 | |
416 // Configure the FakeVideoCaptureDevice to use all its formats as roster. | |
417 VideoCaptureFormats formats; | |
418 video_capture_device_factory_->GetDeviceSupportedFormats(names.front(), | |
419 &formats); | |
420 static_cast<FakeVideoCaptureDevice*>(device.get())-> | |
421 PopulateVariableFormatsRoster(formats); | |
422 | |
423 EXPECT_CALL(*client_, OnErr()) | |
424 .Times(0); | |
425 int action_count = 200; | |
426 | |
427 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
428 | |
429 // We set TimeWait to 200 action timeouts and this should be enough for at | |
430 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | |
431 for (int i = 0; i < action_count; ++i) { | |
432 WaitForCapturedFrame(); | |
433 } | |
434 device->StopAndDeAllocate(); | |
435 } | |
436 | |
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 | 368 }; // namespace media |
OLD | NEW |