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

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

Powered by Google App Engine
This is Rietveld 408576698