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

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

Issue 83633008: Reland: Reorganize media::VideoCapture* types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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.h ('k') | media/video/capture/video_capture_proxy.cc » ('j') | 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" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg 51 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg
52 #else 52 #else
53 #define MAYBE_AllocateBadSize AllocateBadSize 53 #define MAYBE_AllocateBadSize AllocateBadSize
54 #define MAYBE_CaptureMjpeg CaptureMjpeg 54 #define MAYBE_CaptureMjpeg CaptureMjpeg
55 #endif 55 #endif
56 56
57 using ::testing::_; 57 using ::testing::_;
58 using ::testing::AnyNumber; 58 using ::testing::AnyNumber;
59 using ::testing::Return; 59 using ::testing::Return;
60 using ::testing::AtLeast; 60 using ::testing::AtLeast;
61 using ::testing::SaveArg;
62 61
63 namespace media { 62 namespace media {
64 63
65 class MockClient : public media::VideoCaptureDevice::Client { 64 class MockClient : public media::VideoCaptureDevice::Client {
66 public: 65 public:
67 MOCK_METHOD2(ReserveOutputBuffer, 66 MOCK_METHOD2(ReserveOutputBuffer,
68 scoped_refptr<Buffer>(media::VideoFrame::Format format, 67 scoped_refptr<Buffer>(media::VideoFrame::Format format,
69 const gfx::Size& dimensions)); 68 const gfx::Size& dimensions));
70 MOCK_METHOD0(OnErr, void()); 69 MOCK_METHOD0(OnErr, void());
71 70
72 explicit MockClient( 71 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb)
73 base::Callback<void(const VideoCaptureCapability&)> frame_cb)
74 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} 72 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {}
75 73
76 virtual void OnError() OVERRIDE { 74 virtual void OnError() OVERRIDE {
77 OnErr(); 75 OnErr();
78 } 76 }
79 77
80 virtual void OnIncomingCapturedFrame(const uint8* data, 78 virtual void OnIncomingCapturedFrame(const uint8* data,
81 int length, 79 int length,
82 base::Time timestamp, 80 base::Time timestamp,
83 int rotation, 81 int rotation,
84 bool flip_vert, 82 bool flip_vert,
85 bool flip_horiz, 83 bool flip_horiz,
86 const VideoCaptureCapability& frame_info) 84 const VideoCaptureFormat& format)
87 OVERRIDE { 85 OVERRIDE {
88 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, frame_info)); 86 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format));
89 } 87 }
90 88
91 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, 89 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer,
92 media::VideoFrame::Format format, 90 media::VideoFrame::Format format,
93 const gfx::Size& dimensions, 91 const gfx::Size& dimensions,
94 base::Time timestamp, 92 base::Time timestamp,
95 int frame_rate) OVERRIDE { 93 int frame_rate) OVERRIDE {
96 NOTREACHED(); 94 NOTREACHED();
97 } 95 }
98 96
99 private: 97 private:
100 scoped_refptr<base::MessageLoopProxy> main_thread_; 98 scoped_refptr<base::MessageLoopProxy> main_thread_;
101 base::Callback<void(const VideoCaptureCapability&)> frame_cb_; 99 base::Callback<void(const VideoCaptureFormat&)> frame_cb_;
102 }; 100 };
103 101
104 class VideoCaptureDeviceTest : public testing::Test { 102 class VideoCaptureDeviceTest : public testing::Test {
105 protected: 103 protected:
106 typedef media::VideoCaptureDevice::Client Client; 104 typedef media::VideoCaptureDevice::Client Client;
107 105
108 VideoCaptureDeviceTest() 106 VideoCaptureDeviceTest()
109 : loop_(new base::MessageLoop()), 107 : loop_(new base::MessageLoop()),
110 client_( 108 client_(
111 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, 109 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured,
112 base::Unretained(this)))) {} 110 base::Unretained(this)))) {}
113 111
114 virtual void SetUp() { 112 virtual void SetUp() {
115 #if defined(OS_ANDROID) 113 #if defined(OS_ANDROID)
116 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( 114 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(
117 base::android::AttachCurrentThread()); 115 base::android::AttachCurrentThread());
118 #endif 116 #endif
119 } 117 }
120 118
121 void ResetWithNewClient() { 119 void ResetWithNewClient() {
122 client_.reset(new MockClient(base::Bind( 120 client_.reset(new MockClient(base::Bind(
123 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); 121 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this))));
124 } 122 }
125 123
126 void OnFrameCaptured(const VideoCaptureCapability& frame_info) { 124 void OnFrameCaptured(const VideoCaptureFormat& format) {
127 last_frame_info_ = frame_info; 125 last_format_ = format;
128 run_loop_->QuitClosure().Run(); 126 run_loop_->QuitClosure().Run();
129 } 127 }
130 128
131 void WaitForCapturedFrame() { 129 void WaitForCapturedFrame() {
132 run_loop_.reset(new base::RunLoop()); 130 run_loop_.reset(new base::RunLoop());
133 run_loop_->Run(); 131 run_loop_->Run();
134 } 132 }
135 133
136 const VideoCaptureCapability& last_frame_info() const { 134 const VideoCaptureFormat& last_format() const { return last_format_; }
137 return last_frame_info_;
138 }
139 135
140 #if defined(OS_WIN) 136 #if defined(OS_WIN)
141 base::win::ScopedCOMInitializer initialize_com_; 137 base::win::ScopedCOMInitializer initialize_com_;
142 #endif 138 #endif
143 VideoCaptureDevice::Names names_; 139 VideoCaptureDevice::Names names_;
144 scoped_ptr<base::MessageLoop> loop_; 140 scoped_ptr<base::MessageLoop> loop_;
145 scoped_ptr<base::RunLoop> run_loop_; 141 scoped_ptr<base::RunLoop> run_loop_;
146 scoped_ptr<MockClient> client_; 142 scoped_ptr<MockClient> client_;
147 VideoCaptureCapability last_frame_info_; 143 VideoCaptureFormat last_format_;
148 }; 144 };
149 145
150 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { 146 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) {
151 #if defined(OS_WIN) 147 #if defined(OS_WIN)
152 VideoCaptureDevice::Name::CaptureApiType api_type = 148 VideoCaptureDevice::Name::CaptureApiType api_type =
153 VideoCaptureDeviceMFWin::PlatformSupported() 149 VideoCaptureDeviceMFWin::PlatformSupported()
154 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION 150 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION
155 : VideoCaptureDevice::Name::DIRECT_SHOW; 151 : VideoCaptureDevice::Name::DIRECT_SHOW;
156 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); 152 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type);
157 #else 153 #else
(...skipping 11 matching lines...) Expand all
169 } 165 }
170 166
171 scoped_ptr<VideoCaptureDevice> device( 167 scoped_ptr<VideoCaptureDevice> device(
172 VideoCaptureDevice::Create(names_.front())); 168 VideoCaptureDevice::Create(names_.front()));
173 ASSERT_FALSE(device.get() == NULL); 169 ASSERT_FALSE(device.get() == NULL);
174 DVLOG(1) << names_.front().id(); 170 DVLOG(1) << names_.front().id();
175 171
176 EXPECT_CALL(*client_, OnErr()) 172 EXPECT_CALL(*client_, OnErr())
177 .Times(0); 173 .Times(0);
178 174
179 VideoCaptureCapability capture_format(640, 175 VideoCaptureParams capture_params;
180 480, 176 capture_params.requested_format.frame_size.SetSize(640, 480);
181 30, 177 capture_params.requested_format.frame_rate = 30;
182 PIXEL_FORMAT_I420, 178 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
183 ConstantResolutionVideoCaptureDevice); 179 capture_params.allow_resolution_change = false;
184 device->AllocateAndStart(capture_format, 180 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
185 client_.PassAs<Client>());
186 // Get captured video frames. 181 // Get captured video frames.
187 WaitForCapturedFrame(); 182 WaitForCapturedFrame();
188 EXPECT_EQ(last_frame_info().width, 640); 183 EXPECT_EQ(last_format().frame_size.width(), 640);
189 EXPECT_EQ(last_frame_info().height, 480); 184 EXPECT_EQ(last_format().frame_size.height(), 480);
190 device->StopAndDeAllocate(); 185 device->StopAndDeAllocate();
191 } 186 }
192 187
193 TEST_F(VideoCaptureDeviceTest, Capture720p) { 188 TEST_F(VideoCaptureDeviceTest, Capture720p) {
194 VideoCaptureDevice::GetDeviceNames(&names_); 189 VideoCaptureDevice::GetDeviceNames(&names_);
195 if (!names_.size()) { 190 if (!names_.size()) {
196 DVLOG(1) << "No camera available. Exiting test."; 191 DVLOG(1) << "No camera available. Exiting test.";
197 return; 192 return;
198 } 193 }
199 194
200 scoped_ptr<VideoCaptureDevice> device( 195 scoped_ptr<VideoCaptureDevice> device(
201 VideoCaptureDevice::Create(names_.front())); 196 VideoCaptureDevice::Create(names_.front()));
202 ASSERT_FALSE(device.get() == NULL); 197 ASSERT_FALSE(device.get() == NULL);
203 198
204 EXPECT_CALL(*client_, OnErr()) 199 EXPECT_CALL(*client_, OnErr())
205 .Times(0); 200 .Times(0);
206 201
207 VideoCaptureCapability capture_format(1280, 202 VideoCaptureParams capture_params;
208 720, 203 capture_params.requested_format.frame_size.SetSize(1280, 720);
209 30, 204 capture_params.requested_format.frame_rate = 30;
210 PIXEL_FORMAT_I420, 205 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
211 ConstantResolutionVideoCaptureDevice); 206 capture_params.allow_resolution_change = false;
212 device->AllocateAndStart(capture_format, 207 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
213 client_.PassAs<Client>());
214 // Get captured video frames. 208 // Get captured video frames.
215 WaitForCapturedFrame(); 209 WaitForCapturedFrame();
216 device->StopAndDeAllocate(); 210 device->StopAndDeAllocate();
217 } 211 }
218 212
219 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 213 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
220 VideoCaptureDevice::GetDeviceNames(&names_); 214 VideoCaptureDevice::GetDeviceNames(&names_);
221 if (!names_.size()) { 215 if (!names_.size()) {
222 DVLOG(1) << "No camera available. Exiting test."; 216 DVLOG(1) << "No camera available. Exiting test.";
223 return; 217 return;
224 } 218 }
225 scoped_ptr<VideoCaptureDevice> device( 219 scoped_ptr<VideoCaptureDevice> device(
226 VideoCaptureDevice::Create(names_.front())); 220 VideoCaptureDevice::Create(names_.front()));
227 ASSERT_TRUE(device.get() != NULL); 221 ASSERT_TRUE(device.get() != NULL);
228 222
229 EXPECT_CALL(*client_, OnErr()) 223 EXPECT_CALL(*client_, OnErr())
230 .Times(0); 224 .Times(0);
231 225
232 VideoCaptureCapability capture_format(637, 226 VideoCaptureParams capture_params;
233 472, 227 capture_params.requested_format.frame_size.SetSize(637, 472);
234 35, 228 capture_params.requested_format.frame_rate = 35;
235 PIXEL_FORMAT_I420, 229 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
236 ConstantResolutionVideoCaptureDevice); 230 capture_params.allow_resolution_change = false;
237 device->AllocateAndStart(capture_format, 231 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
238 client_.PassAs<Client>());
239 WaitForCapturedFrame(); 232 WaitForCapturedFrame();
240 device->StopAndDeAllocate(); 233 device->StopAndDeAllocate();
241 EXPECT_EQ(last_frame_info().width, 640); 234 EXPECT_EQ(last_format().frame_size.width(), 640);
242 EXPECT_EQ(last_frame_info().height, 480); 235 EXPECT_EQ(last_format().frame_size.height(), 480);
243 } 236 }
244 237
245 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { 238 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
246 VideoCaptureDevice::GetDeviceNames(&names_); 239 VideoCaptureDevice::GetDeviceNames(&names_);
247 if (!names_.size()) { 240 if (!names_.size()) {
248 DVLOG(1) << "No camera available. Exiting test."; 241 DVLOG(1) << "No camera available. Exiting test.";
249 return; 242 return;
250 } 243 }
251 244
252 // First, do a number of very fast device start/stops. 245 // First, do a number of very fast device start/stops.
253 for (int i = 0; i <= 5; i++) { 246 for (int i = 0; i <= 5; i++) {
254 ResetWithNewClient(); 247 ResetWithNewClient();
255 scoped_ptr<VideoCaptureDevice> device( 248 scoped_ptr<VideoCaptureDevice> device(
256 VideoCaptureDevice::Create(names_.front())); 249 VideoCaptureDevice::Create(names_.front()));
257 gfx::Size resolution; 250 gfx::Size resolution;
258 if (i % 2) { 251 if (i % 2) {
259 resolution = gfx::Size(640, 480); 252 resolution = gfx::Size(640, 480);
260 } else { 253 } else {
261 resolution = gfx::Size(1280, 1024); 254 resolution = gfx::Size(1280, 1024);
262 } 255 }
263 VideoCaptureCapability requested_format( 256 VideoCaptureParams capture_params;
264 resolution.width(), 257 capture_params.requested_format.frame_size = resolution;
265 resolution.height(), 258 capture_params.requested_format.frame_rate = 30;
266 30, 259 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
267 PIXEL_FORMAT_I420, 260 capture_params.allow_resolution_change = false;
268 ConstantResolutionVideoCaptureDevice); 261 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
269
270 device->AllocateAndStart(requested_format, client_.PassAs<Client>());
271 device->StopAndDeAllocate(); 262 device->StopAndDeAllocate();
272 } 263 }
273 264
274 // Finally, do a device start and wait for it to finish. 265 // Finally, do a device start and wait for it to finish.
275 gfx::Size resolution; 266 VideoCaptureParams capture_params;
276 VideoCaptureCapability requested_format( 267 capture_params.requested_format.frame_size.SetSize(320, 240);
277 320, 268 capture_params.requested_format.frame_rate = 30;
278 240, 269 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
279 30, 270 capture_params.allow_resolution_change = false;
280 PIXEL_FORMAT_I420,
281 ConstantResolutionVideoCaptureDevice);
282 271
283 ResetWithNewClient(); 272 ResetWithNewClient();
284 scoped_ptr<VideoCaptureDevice> device( 273 scoped_ptr<VideoCaptureDevice> device(
285 VideoCaptureDevice::Create(names_.front())); 274 VideoCaptureDevice::Create(names_.front()));
286 275
287 device->AllocateAndStart(requested_format, client_.PassAs<Client>()); 276 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
288 WaitForCapturedFrame(); 277 WaitForCapturedFrame();
289 device->StopAndDeAllocate(); 278 device->StopAndDeAllocate();
290 device.reset(); 279 device.reset();
291 EXPECT_EQ(last_frame_info().width, 320); 280 EXPECT_EQ(last_format().frame_size.width(), 320);
292 EXPECT_EQ(last_frame_info().height, 240); 281 EXPECT_EQ(last_format().frame_size.height(), 240);
293 } 282 }
294 283
295 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 284 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
296 VideoCaptureDevice::GetDeviceNames(&names_); 285 VideoCaptureDevice::GetDeviceNames(&names_);
297 if (!names_.size()) { 286 if (!names_.size()) {
298 DVLOG(1) << "No camera available. Exiting test."; 287 DVLOG(1) << "No camera available. Exiting test.";
299 return; 288 return;
300 } 289 }
301 scoped_ptr<VideoCaptureDevice> device( 290 scoped_ptr<VideoCaptureDevice> device(
302 VideoCaptureDevice::Create(names_.front())); 291 VideoCaptureDevice::Create(names_.front()));
303 ASSERT_TRUE(device.get() != NULL); 292 ASSERT_TRUE(device.get() != NULL);
304 293
305 EXPECT_CALL(*client_, OnErr()) 294 EXPECT_CALL(*client_, OnErr())
306 .Times(0); 295 .Times(0);
307 296
308 VideoCaptureCapability capture_format(640, 297 VideoCaptureParams capture_params;
309 480, 298 capture_params.requested_format.frame_size.SetSize(640, 480);
310 30, 299 capture_params.requested_format.frame_rate = 30;
311 PIXEL_FORMAT_I420, 300 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
312 ConstantResolutionVideoCaptureDevice); 301 capture_params.allow_resolution_change = false;
313 device->AllocateAndStart(capture_format, client_.PassAs<Client>()); 302 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
314 // Get captured video frames. 303 // Get captured video frames.
315 WaitForCapturedFrame(); 304 WaitForCapturedFrame();
316 EXPECT_EQ(last_frame_info().width, 640); 305 EXPECT_EQ(last_format().frame_size.width(), 640);
317 EXPECT_EQ(last_frame_info().height, 480); 306 EXPECT_EQ(last_format().frame_size.height(), 480);
318 EXPECT_EQ(last_frame_info().frame_rate, 30); 307 EXPECT_EQ(last_format().frame_rate, 30);
319 device->StopAndDeAllocate(); 308 device->StopAndDeAllocate();
320 } 309 }
321 310
322 TEST_F(VideoCaptureDeviceTest, FakeCapture) { 311 TEST_F(VideoCaptureDeviceTest, FakeCapture) {
323 VideoCaptureDevice::Names names; 312 VideoCaptureDevice::Names names;
324 313
325 FakeVideoCaptureDevice::GetDeviceNames(&names); 314 FakeVideoCaptureDevice::GetDeviceNames(&names);
326 315
327 ASSERT_GT(static_cast<int>(names.size()), 0); 316 ASSERT_GT(static_cast<int>(names.size()), 0);
328 317
329 scoped_ptr<VideoCaptureDevice> device( 318 scoped_ptr<VideoCaptureDevice> device(
330 FakeVideoCaptureDevice::Create(names.front())); 319 FakeVideoCaptureDevice::Create(names.front()));
331 ASSERT_TRUE(device.get() != NULL); 320 ASSERT_TRUE(device.get() != NULL);
332 321
333 EXPECT_CALL(*client_, OnErr()) 322 EXPECT_CALL(*client_, OnErr())
334 .Times(0); 323 .Times(0);
335 324
336 VideoCaptureCapability capture_format(640, 325 VideoCaptureParams capture_params;
337 480, 326 capture_params.requested_format.frame_size.SetSize(640, 480);
338 30, 327 capture_params.requested_format.frame_rate = 30;
339 PIXEL_FORMAT_I420, 328 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
340 ConstantResolutionVideoCaptureDevice); 329 capture_params.allow_resolution_change = false;
341 device->AllocateAndStart(capture_format, 330 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
342 client_.PassAs<Client>());
343 WaitForCapturedFrame(); 331 WaitForCapturedFrame();
344 EXPECT_EQ(last_frame_info().width, 640); 332 EXPECT_EQ(last_format().frame_size.width(), 640);
345 EXPECT_EQ(last_frame_info().height, 480); 333 EXPECT_EQ(last_format().frame_size.height(), 480);
346 EXPECT_EQ(last_frame_info().frame_rate, 30); 334 EXPECT_EQ(last_format().frame_rate, 30);
347 device->StopAndDeAllocate(); 335 device->StopAndDeAllocate();
348 } 336 }
349 337
350 // Start the camera in 720p to capture MJPEG instead of a raw format. 338 // Start the camera in 720p to capture MJPEG instead of a raw format.
351 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 339 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
352 VideoCaptureDevice::GetDeviceNames(&names_); 340 VideoCaptureDevice::GetDeviceNames(&names_);
353 if (!names_.size()) { 341 if (!names_.size()) {
354 DVLOG(1) << "No camera available. Exiting test."; 342 DVLOG(1) << "No camera available. Exiting test.";
355 return; 343 return;
356 } 344 }
357 scoped_ptr<VideoCaptureDevice> device( 345 scoped_ptr<VideoCaptureDevice> device(
358 VideoCaptureDevice::Create(names_.front())); 346 VideoCaptureDevice::Create(names_.front()));
359 ASSERT_TRUE(device.get() != NULL); 347 ASSERT_TRUE(device.get() != NULL);
360 348
361 EXPECT_CALL(*client_, OnErr()) 349 EXPECT_CALL(*client_, OnErr())
362 .Times(0); 350 .Times(0);
363 351
364 VideoCaptureCapability capture_format(1280, 352 VideoCaptureParams capture_params;
365 720, 353 capture_params.requested_format.frame_size.SetSize(1280, 720);
366 30, 354 capture_params.requested_format.frame_rate = 30;
367 PIXEL_FORMAT_MJPEG, 355 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
368 ConstantResolutionVideoCaptureDevice); 356 capture_params.allow_resolution_change = false;
369 device->AllocateAndStart(capture_format, client_.PassAs<Client>()); 357 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
370 // Get captured video frames. 358 // Get captured video frames.
371 WaitForCapturedFrame(); 359 WaitForCapturedFrame();
372 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 360 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
373 // @ 30 fps, so we don't care about the exact resolution we get. 361 // @ 30 fps, so we don't care about the exact resolution we get.
374 EXPECT_EQ(last_frame_info().color, PIXEL_FORMAT_MJPEG); 362 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
375 device->StopAndDeAllocate(); 363 device->StopAndDeAllocate();
376 } 364 }
377 365
378 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 366 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
379 VideoCaptureDevice::GetDeviceNames(&names_); 367 VideoCaptureDevice::GetDeviceNames(&names_);
380 if (!names_.size()) { 368 if (!names_.size()) {
381 DVLOG(1) << "No camera available. Exiting test."; 369 DVLOG(1) << "No camera available. Exiting test.";
382 return; 370 return;
383 } 371 }
384 VideoCaptureCapabilities capture_formats; 372 VideoCaptureCapabilities capture_capabilities;
385 VideoCaptureDevice::Names::iterator names_iterator; 373 VideoCaptureDevice::Names::iterator names_iterator;
386 for (names_iterator = names_.begin(); names_iterator != names_.end(); 374 for (names_iterator = names_.begin(); names_iterator != names_.end();
387 ++names_iterator) { 375 ++names_iterator) {
388 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, 376 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
389 &capture_formats); 377 &capture_capabilities);
390 // Nothing to test here since we cannot forecast the hardware capabilities. 378 // Nothing to test here since we cannot forecast the hardware capabilities.
391 } 379 }
392 } 380 }
393 381
394 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { 382 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) {
395 VideoCaptureDevice::Names names; 383 VideoCaptureDevice::Names names;
396 384
397 FakeVideoCaptureDevice::GetDeviceNames(&names); 385 FakeVideoCaptureDevice::GetDeviceNames(&names);
398 media::VideoCaptureCapability capture_format; 386 VideoCaptureParams capture_params;
399 capture_format.width = 640; 387 capture_params.requested_format.frame_size.SetSize(640, 480);
400 capture_format.height = 480; 388 capture_params.requested_format.frame_rate = 30;
401 capture_format.frame_rate = 30; 389 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
402 capture_format.frame_size_type = media::VariableResolutionVideoCaptureDevice; 390 capture_params.allow_resolution_change = true;
403 391
404 ASSERT_GT(static_cast<int>(names.size()), 0); 392 ASSERT_GT(static_cast<int>(names.size()), 0);
405 393
406 scoped_ptr<VideoCaptureDevice> device( 394 scoped_ptr<VideoCaptureDevice> device(
407 FakeVideoCaptureDevice::Create(names.front())); 395 FakeVideoCaptureDevice::Create(names.front()));
408 ASSERT_TRUE(device.get() != NULL); 396 ASSERT_TRUE(device.get() != NULL);
409 397
410 EXPECT_CALL(*client_, OnErr()) 398 EXPECT_CALL(*client_, OnErr())
411 .Times(0); 399 .Times(0);
412 int action_count = 200; 400 int action_count = 200;
413 401
414 device->AllocateAndStart(capture_format, client_.PassAs<Client>()); 402 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
415 403
416 // We set TimeWait to 200 action timeouts and this should be enough for at 404 // We set TimeWait to 200 action timeouts and this should be enough for at
417 // least action_count/kFakeCaptureCapabilityChangePeriod calls. 405 // least action_count/kFakeCaptureCapabilityChangePeriod calls.
418 for (int i = 0; i < action_count; ++i) { 406 for (int i = 0; i < action_count; ++i) {
419 WaitForCapturedFrame(); 407 WaitForCapturedFrame();
420 } 408 }
421 device->StopAndDeAllocate(); 409 device->StopAndDeAllocate();
422 } 410 }
423 411
424 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) { 412 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) {
425 VideoCaptureDevice::Names names; 413 VideoCaptureDevice::Names names;
426 FakeVideoCaptureDevice::GetDeviceNames(&names); 414 FakeVideoCaptureDevice::GetDeviceNames(&names);
427 415
428 VideoCaptureCapabilities capture_formats; 416 VideoCaptureCapabilities capture_capabilities;
429 VideoCaptureDevice::Names::iterator names_iterator; 417 VideoCaptureDevice::Names::iterator names_iterator;
430 418
431 for (names_iterator = names.begin(); names_iterator != names.end(); 419 for (names_iterator = names.begin(); names_iterator != names.end();
432 ++names_iterator) { 420 ++names_iterator) {
433 FakeVideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, 421 FakeVideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
434 &capture_formats); 422 &capture_capabilities);
435 EXPECT_GE(capture_formats.size(), 1u); 423 EXPECT_GE(capture_capabilities.size(), 1u);
436 EXPECT_EQ(capture_formats[0].width, 640); 424 EXPECT_EQ(capture_capabilities[0].supported_format.frame_size.width(), 640);
437 EXPECT_EQ(capture_formats[0].height, 480); 425 EXPECT_EQ(capture_capabilities[0].supported_format.frame_size.height(),
438 EXPECT_EQ(capture_formats[0].color, media::PIXEL_FORMAT_I420); 426 480);
439 EXPECT_GE(capture_formats[0].frame_rate, 20); 427 EXPECT_EQ(capture_capabilities[0].supported_format.pixel_format,
428 media::PIXEL_FORMAT_I420);
429 EXPECT_GE(capture_capabilities[0].supported_format.frame_rate, 20);
440 } 430 }
441 } 431 }
442 432
443 }; // namespace media 433 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/video_capture_device.h ('k') | media/video/capture/video_capture_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698