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

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

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

Powered by Google App Engine
This is Rietveld 408576698