Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(864)

Side by Side Diff: media/video/capture/video_capture_device_unittest.cc

Issue 265263004: Mac Video Capture Device: split VCD into VCD and Factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reconnected VCDFMac::Create() check for device name; VCDTest::OpenInvalidDevice needs Mac API Type. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/video/capture/video_capture_device_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_(
100 VideoCaptureDeviceFactory::CreateFactory()) {}
108 101
109 virtual void SetUp() { 102 virtual void SetUp() {
110 #if defined(OS_ANDROID) 103 #if defined(OS_ANDROID)
111 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( 104 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(
112 base::android::AttachCurrentThread()); 105 base::android::AttachCurrentThread());
113 #endif 106 #endif
114 } 107 }
115 108
116 void ResetWithNewClient() { 109 void ResetWithNewClient() {
117 client_.reset(new MockClient(base::Bind( 110 client_.reset(new MockClient(base::Bind(
118 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); 111 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this))));
119 } 112 }
120 113
121 void OnFrameCaptured(const VideoCaptureFormat& format) { 114 void OnFrameCaptured(const VideoCaptureFormat& format) {
122 last_format_ = format; 115 last_format_ = format;
123 run_loop_->QuitClosure().Run(); 116 run_loop_->QuitClosure().Run();
124 } 117 }
125 118
126 void WaitForCapturedFrame() { 119 void WaitForCapturedFrame() {
127 run_loop_.reset(new base::RunLoop()); 120 run_loop_.reset(new base::RunLoop());
128 run_loop_->Run(); 121 run_loop_->Run();
129 } 122 }
130 123
131 const VideoCaptureFormat& last_format() const { return last_format_; } 124 const VideoCaptureFormat& last_format() const { return last_format_; }
132 125
133 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( 126 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat(
134 const VideoPixelFormat& pixel_format) { 127 const VideoPixelFormat& pixel_format) {
135 VideoCaptureDevice::GetDeviceNames(&names_); 128 video_capture_device_factory_->GetDeviceNames(&names_);
136 if (!names_.size()) { 129 if (!names_.size()) {
137 DVLOG(1) << "No camera available."; 130 DVLOG(1) << "No camera available.";
138 return scoped_ptr<VideoCaptureDevice::Name>(); 131 return scoped_ptr<VideoCaptureDevice::Name>();
139 } 132 }
140 VideoCaptureDevice::Names::iterator names_iterator; 133 VideoCaptureDevice::Names::iterator names_iterator;
141 for (names_iterator = names_.begin(); names_iterator != names_.end(); 134 for (names_iterator = names_.begin(); names_iterator != names_.end();
142 ++names_iterator) { 135 ++names_iterator) {
143 VideoCaptureFormats supported_formats; 136 VideoCaptureFormats supported_formats;
144 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, 137 video_capture_device_factory_->GetDeviceSupportedFormats(
145 &supported_formats); 138 *names_iterator,
139 &supported_formats);
146 VideoCaptureFormats::iterator formats_iterator; 140 VideoCaptureFormats::iterator formats_iterator;
147 for (formats_iterator = supported_formats.begin(); 141 for (formats_iterator = supported_formats.begin();
148 formats_iterator != supported_formats.end(); ++formats_iterator) { 142 formats_iterator != supported_formats.end(); ++formats_iterator) {
149 if (formats_iterator->pixel_format == pixel_format) { 143 if (formats_iterator->pixel_format == pixel_format) {
150 return scoped_ptr<VideoCaptureDevice::Name>( 144 return scoped_ptr<VideoCaptureDevice::Name>(
151 new VideoCaptureDevice::Name(*names_iterator)); 145 new VideoCaptureDevice::Name(*names_iterator));
152 } 146 }
153 } 147 }
154 } 148 }
155 DVLOG(1) << "No camera can capture the format: " << pixel_format; 149 DVLOG(1) << "No camera can capture the format: " << pixel_format;
(...skipping 11 matching lines...) Expand all
167 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; 161 scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_;
168 }; 162 };
169 163
170 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { 164 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) {
171 #if defined(OS_WIN) 165 #if defined(OS_WIN)
172 VideoCaptureDevice::Name::CaptureApiType api_type = 166 VideoCaptureDevice::Name::CaptureApiType api_type =
173 VideoCaptureDeviceMFWin::PlatformSupported() 167 VideoCaptureDeviceMFWin::PlatformSupported()
174 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION 168 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION
175 : VideoCaptureDevice::Name::DIRECT_SHOW; 169 : VideoCaptureDevice::Name::DIRECT_SHOW;
176 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); 170 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type);
171 #elif defined(OS_MACOSX)
172 VideoCaptureDevice::Name device_name("jibberish", "jibberish",
173 VideoCaptureDevice::Name::AVFOUNDATION);
177 #else 174 #else
178 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); 175 VideoCaptureDevice::Name device_name("jibberish", "jibberish");
179 #endif 176 #endif
180 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); 177 scoped_ptr<VideoCaptureDevice> device =
178 video_capture_device_factory_->Create(device_name);
181 EXPECT_TRUE(device == NULL); 179 EXPECT_TRUE(device == NULL);
182 } 180 }
183 181
184 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { 182 TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
185 VideoCaptureDevice::GetDeviceNames(&names_); 183 video_capture_device_factory_->GetDeviceNames(&names_);
186 if (!names_.size()) { 184 if (!names_.size()) {
187 DVLOG(1) << "No camera available. Exiting test."; 185 DVLOG(1) << "No camera available. Exiting test.";
188 return; 186 return;
189 } 187 }
190 188
191 scoped_ptr<VideoCaptureDevice> device( 189 scoped_ptr<VideoCaptureDevice> device(
192 VideoCaptureDevice::Create(names_.front())); 190 video_capture_device_factory_->Create(names_.front()));
193 ASSERT_TRUE(device); 191 ASSERT_TRUE(device);
194 DVLOG(1) << names_.front().id(); 192 DVLOG(1) << names_.front().id();
195 193
196 EXPECT_CALL(*client_, OnErr()) 194 EXPECT_CALL(*client_, OnErr())
197 .Times(0); 195 .Times(0);
198 196
199 VideoCaptureParams capture_params; 197 VideoCaptureParams capture_params;
200 capture_params.requested_format.frame_size.SetSize(640, 480); 198 capture_params.requested_format.frame_size.SetSize(640, 480);
201 capture_params.requested_format.frame_rate = 30; 199 capture_params.requested_format.frame_rate = 30;
202 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 200 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
203 capture_params.allow_resolution_change = false; 201 capture_params.allow_resolution_change = false;
204 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 202 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
205 // Get captured video frames. 203 // Get captured video frames.
206 WaitForCapturedFrame(); 204 WaitForCapturedFrame();
207 EXPECT_EQ(last_format().frame_size.width(), 640); 205 EXPECT_EQ(last_format().frame_size.width(), 640);
208 EXPECT_EQ(last_format().frame_size.height(), 480); 206 EXPECT_EQ(last_format().frame_size.height(), 480);
209 device->StopAndDeAllocate(); 207 device->StopAndDeAllocate();
210 } 208 }
211 209
212 TEST_F(VideoCaptureDeviceTest, Capture720p) { 210 TEST_F(VideoCaptureDeviceTest, Capture720p) {
213 VideoCaptureDevice::GetDeviceNames(&names_); 211 video_capture_device_factory_->GetDeviceNames(&names_);
214 if (!names_.size()) { 212 if (!names_.size()) {
215 DVLOG(1) << "No camera available. Exiting test."; 213 DVLOG(1) << "No camera available. Exiting test.";
216 return; 214 return;
217 } 215 }
218 216
219 scoped_ptr<VideoCaptureDevice> device( 217 scoped_ptr<VideoCaptureDevice> device(
220 VideoCaptureDevice::Create(names_.front())); 218 video_capture_device_factory_->Create(names_.front()));
221 ASSERT_TRUE(device); 219 ASSERT_TRUE(device);
222 220
223 EXPECT_CALL(*client_, OnErr()) 221 EXPECT_CALL(*client_, OnErr())
224 .Times(0); 222 .Times(0);
225 223
226 VideoCaptureParams capture_params; 224 VideoCaptureParams capture_params;
227 capture_params.requested_format.frame_size.SetSize(1280, 720); 225 capture_params.requested_format.frame_size.SetSize(1280, 720);
228 capture_params.requested_format.frame_rate = 30; 226 capture_params.requested_format.frame_rate = 30;
229 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 227 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
230 capture_params.allow_resolution_change = false; 228 capture_params.allow_resolution_change = false;
231 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 229 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
232 // Get captured video frames. 230 // Get captured video frames.
233 WaitForCapturedFrame(); 231 WaitForCapturedFrame();
234 device->StopAndDeAllocate(); 232 device->StopAndDeAllocate();
235 } 233 }
236 234
237 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 235 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
238 VideoCaptureDevice::GetDeviceNames(&names_); 236 video_capture_device_factory_->GetDeviceNames(&names_);
239 if (!names_.size()) { 237 if (!names_.size()) {
240 DVLOG(1) << "No camera available. Exiting test."; 238 DVLOG(1) << "No camera available. Exiting test.";
241 return; 239 return;
242 } 240 }
243 scoped_ptr<VideoCaptureDevice> device( 241 scoped_ptr<VideoCaptureDevice> device(
244 VideoCaptureDevice::Create(names_.front())); 242 video_capture_device_factory_->Create(names_.front()));
245 ASSERT_TRUE(device); 243 ASSERT_TRUE(device);
246 244
247 EXPECT_CALL(*client_, OnErr()) 245 EXPECT_CALL(*client_, OnErr())
248 .Times(0); 246 .Times(0);
249 247
250 VideoCaptureParams capture_params; 248 VideoCaptureParams capture_params;
251 capture_params.requested_format.frame_size.SetSize(637, 472); 249 capture_params.requested_format.frame_size.SetSize(637, 472);
252 capture_params.requested_format.frame_rate = 35; 250 capture_params.requested_format.frame_rate = 35;
253 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 251 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
254 capture_params.allow_resolution_change = false; 252 capture_params.allow_resolution_change = false;
255 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 253 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
256 WaitForCapturedFrame(); 254 WaitForCapturedFrame();
257 device->StopAndDeAllocate(); 255 device->StopAndDeAllocate();
258 EXPECT_EQ(last_format().frame_size.width(), 640); 256 EXPECT_EQ(last_format().frame_size.width(), 640);
259 EXPECT_EQ(last_format().frame_size.height(), 480); 257 EXPECT_EQ(last_format().frame_size.height(), 480);
260 } 258 }
261 259
262 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { 260 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
263 VideoCaptureDevice::GetDeviceNames(&names_); 261 video_capture_device_factory_->GetDeviceNames(&names_);
264 if (!names_.size()) { 262 if (!names_.size()) {
265 DVLOG(1) << "No camera available. Exiting test."; 263 DVLOG(1) << "No camera available. Exiting test.";
266 return; 264 return;
267 } 265 }
268 266
269 // First, do a number of very fast device start/stops. 267 // First, do a number of very fast device start/stops.
270 for (int i = 0; i <= 5; i++) { 268 for (int i = 0; i <= 5; i++) {
271 ResetWithNewClient(); 269 ResetWithNewClient();
272 scoped_ptr<VideoCaptureDevice> device( 270 scoped_ptr<VideoCaptureDevice> device(
273 VideoCaptureDevice::Create(names_.front())); 271 video_capture_device_factory_->Create(names_.front()));
274 gfx::Size resolution; 272 gfx::Size resolution;
275 if (i % 2) { 273 if (i % 2) {
276 resolution = gfx::Size(640, 480); 274 resolution = gfx::Size(640, 480);
277 } else { 275 } else {
278 resolution = gfx::Size(1280, 1024); 276 resolution = gfx::Size(1280, 1024);
279 } 277 }
280 VideoCaptureParams capture_params; 278 VideoCaptureParams capture_params;
281 capture_params.requested_format.frame_size = resolution; 279 capture_params.requested_format.frame_size = resolution;
282 capture_params.requested_format.frame_rate = 30; 280 capture_params.requested_format.frame_rate = 30;
283 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 281 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
284 capture_params.allow_resolution_change = false; 282 capture_params.allow_resolution_change = false;
285 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 283 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
286 device->StopAndDeAllocate(); 284 device->StopAndDeAllocate();
287 } 285 }
288 286
289 // Finally, do a device start and wait for it to finish. 287 // Finally, do a device start and wait for it to finish.
290 VideoCaptureParams capture_params; 288 VideoCaptureParams capture_params;
291 capture_params.requested_format.frame_size.SetSize(320, 240); 289 capture_params.requested_format.frame_size.SetSize(320, 240);
292 capture_params.requested_format.frame_rate = 30; 290 capture_params.requested_format.frame_rate = 30;
293 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 291 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
294 capture_params.allow_resolution_change = false; 292 capture_params.allow_resolution_change = false;
295 293
296 ResetWithNewClient(); 294 ResetWithNewClient();
297 scoped_ptr<VideoCaptureDevice> device( 295 scoped_ptr<VideoCaptureDevice> device(
298 VideoCaptureDevice::Create(names_.front())); 296 video_capture_device_factory_->Create(names_.front()));
299 297
300 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 298 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
301 WaitForCapturedFrame(); 299 WaitForCapturedFrame();
302 device->StopAndDeAllocate(); 300 device->StopAndDeAllocate();
303 device.reset(); 301 device.reset();
304 EXPECT_EQ(last_format().frame_size.width(), 320); 302 EXPECT_EQ(last_format().frame_size.width(), 320);
305 EXPECT_EQ(last_format().frame_size.height(), 240); 303 EXPECT_EQ(last_format().frame_size.height(), 240);
306 } 304 }
307 305
308 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 306 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
309 VideoCaptureDevice::GetDeviceNames(&names_); 307 video_capture_device_factory_->GetDeviceNames(&names_);
310 if (!names_.size()) { 308 if (!names_.size()) {
311 DVLOG(1) << "No camera available. Exiting test."; 309 DVLOG(1) << "No camera available. Exiting test.";
312 return; 310 return;
313 } 311 }
314 scoped_ptr<VideoCaptureDevice> device( 312 scoped_ptr<VideoCaptureDevice> device(
315 VideoCaptureDevice::Create(names_.front())); 313 video_capture_device_factory_->Create(names_.front()));
316 ASSERT_TRUE(device); 314 ASSERT_TRUE(device);
317 315
318 EXPECT_CALL(*client_, OnErr()) 316 EXPECT_CALL(*client_, OnErr())
319 .Times(0); 317 .Times(0);
320 318
321 VideoCaptureParams capture_params; 319 VideoCaptureParams capture_params;
322 capture_params.requested_format.frame_size.SetSize(640, 480); 320 capture_params.requested_format.frame_size.SetSize(640, 480);
323 capture_params.requested_format.frame_rate = 30; 321 capture_params.requested_format.frame_rate = 30;
324 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 322 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
325 capture_params.allow_resolution_change = false; 323 capture_params.allow_resolution_change = false;
326 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 324 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
327 // Get captured video frames. 325 // Get captured video frames.
328 WaitForCapturedFrame(); 326 WaitForCapturedFrame();
329 EXPECT_EQ(last_format().frame_size.width(), 640); 327 EXPECT_EQ(last_format().frame_size.width(), 640);
330 EXPECT_EQ(last_format().frame_size.height(), 480); 328 EXPECT_EQ(last_format().frame_size.height(), 480);
331 EXPECT_EQ(last_format().frame_rate, 30); 329 EXPECT_EQ(last_format().frame_rate, 30);
332 device->StopAndDeAllocate(); 330 device->StopAndDeAllocate();
333 } 331 }
334 332
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. 333 // Start the camera in 720p to capture MJPEG instead of a raw format.
363 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 334 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
364 scoped_ptr<VideoCaptureDevice::Name> name = 335 scoped_ptr<VideoCaptureDevice::Name> name =
365 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); 336 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
366 if (!name) { 337 if (!name) {
367 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; 338 DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
368 return; 339 return;
369 } 340 }
370 scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name)); 341 scoped_ptr<VideoCaptureDevice> device(
342 video_capture_device_factory_->Create(*name));
371 ASSERT_TRUE(device); 343 ASSERT_TRUE(device);
372 344
373 EXPECT_CALL(*client_, OnErr()) 345 EXPECT_CALL(*client_, OnErr())
374 .Times(0); 346 .Times(0);
375 347
376 VideoCaptureParams capture_params; 348 VideoCaptureParams capture_params;
377 capture_params.requested_format.frame_size.SetSize(1280, 720); 349 capture_params.requested_format.frame_size.SetSize(1280, 720);
378 capture_params.requested_format.frame_rate = 30; 350 capture_params.requested_format.frame_rate = 30;
379 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
380 capture_params.allow_resolution_change = false; 352 capture_params.allow_resolution_change = false;
381 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 353 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
382 // Get captured video frames. 354 // Get captured video frames.
383 WaitForCapturedFrame(); 355 WaitForCapturedFrame();
384 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 356 // 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. 357 // @ 30 fps, so we don't care about the exact resolution we get.
386 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 358 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
387 device->StopAndDeAllocate(); 359 device->StopAndDeAllocate();
388 } 360 }
389 361
390 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 362 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
391 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 363 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
392 // GetDeviceSupportedFormats(). 364 // GetDeviceSupportedFormats().
393 scoped_ptr<VideoCaptureDevice::Name> name = 365 scoped_ptr<VideoCaptureDevice::Name> name =
394 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 366 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
395 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 367 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
396 // since we cannot forecast the hardware capabilities. 368 // since we cannot forecast the hardware capabilities.
397 ASSERT_FALSE(name); 369 ASSERT_FALSE(name);
398 } 370 }
399 371
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 372 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/video_capture_device_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698