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