| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "media/video/capture/fake_video_capture_device.h" | 10 #include "media/video/capture/fake_video_capture_device.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 VideoCaptureCapability rx_capability; | 152 VideoCaptureCapability rx_capability; |
| 153 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 153 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 154 .Times(1).WillOnce(SaveArg<0>(&rx_capability)); | 154 .Times(1).WillOnce(SaveArg<0>(&rx_capability)); |
| 155 | 155 |
| 156 EXPECT_CALL(*frame_observer_, OnErr()) | 156 EXPECT_CALL(*frame_observer_, OnErr()) |
| 157 .Times(0); | 157 .Times(0); |
| 158 | 158 |
| 159 VideoCaptureCapability capture_format(640, | 159 VideoCaptureCapability capture_format(640, |
| 160 480, | 160 480, |
| 161 30, | 161 30, |
| 162 VideoCaptureCapability::kI420, | 162 PIXEL_FORMAT_I420, |
| 163 0, | 163 0, |
| 164 false, | 164 false, |
| 165 ConstantResolutionVideoCaptureDevice); | 165 ConstantResolutionVideoCaptureDevice); |
| 166 device->Allocate(capture_format, frame_observer_.get()); | 166 device->Allocate(capture_format, frame_observer_.get()); |
| 167 device->Start(); | 167 device->Start(); |
| 168 // Get captured video frames. | 168 // Get captured video frames. |
| 169 PostQuitTask(); | 169 PostQuitTask(); |
| 170 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 170 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 171 EXPECT_EQ(rx_capability.width, 640); | 171 EXPECT_EQ(rx_capability.width, 640); |
| 172 EXPECT_EQ(rx_capability.height, 480); | 172 EXPECT_EQ(rx_capability.height, 480); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 190 // be different from one machine to the next. | 190 // be different from one machine to the next. |
| 191 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 191 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 192 .Times(1); | 192 .Times(1); |
| 193 | 193 |
| 194 EXPECT_CALL(*frame_observer_, OnErr()) | 194 EXPECT_CALL(*frame_observer_, OnErr()) |
| 195 .Times(0); | 195 .Times(0); |
| 196 | 196 |
| 197 VideoCaptureCapability capture_format(1280, | 197 VideoCaptureCapability capture_format(1280, |
| 198 720, | 198 720, |
| 199 30, | 199 30, |
| 200 VideoCaptureCapability::kI420, | 200 PIXEL_FORMAT_I420, |
| 201 0, | 201 0, |
| 202 false, | 202 false, |
| 203 ConstantResolutionVideoCaptureDevice); | 203 ConstantResolutionVideoCaptureDevice); |
| 204 device->Allocate(capture_format, frame_observer_.get()); | 204 device->Allocate(capture_format, frame_observer_.get()); |
| 205 device->Start(); | 205 device->Start(); |
| 206 // Get captured video frames. | 206 // Get captured video frames. |
| 207 PostQuitTask(); | 207 PostQuitTask(); |
| 208 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 208 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 209 device->Stop(); | 209 device->Stop(); |
| 210 device->DeAllocate(); | 210 device->DeAllocate(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 224 .Times(0); | 224 .Times(0); |
| 225 | 225 |
| 226 // Get info about the new resolution. | 226 // Get info about the new resolution. |
| 227 VideoCaptureCapability rx_capability; | 227 VideoCaptureCapability rx_capability; |
| 228 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 228 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 229 .Times(AtLeast(1)).WillOnce(SaveArg<0>(&rx_capability)); | 229 .Times(AtLeast(1)).WillOnce(SaveArg<0>(&rx_capability)); |
| 230 | 230 |
| 231 VideoCaptureCapability capture_format(637, | 231 VideoCaptureCapability capture_format(637, |
| 232 472, | 232 472, |
| 233 35, | 233 35, |
| 234 VideoCaptureCapability::kI420, | 234 PIXEL_FORMAT_I420, |
| 235 0, | 235 0, |
| 236 false, | 236 false, |
| 237 ConstantResolutionVideoCaptureDevice); | 237 ConstantResolutionVideoCaptureDevice); |
| 238 device->Allocate(capture_format, frame_observer_.get()); | 238 device->Allocate(capture_format, frame_observer_.get()); |
| 239 device->DeAllocate(); | 239 device->DeAllocate(); |
| 240 EXPECT_EQ(rx_capability.width, 640); | 240 EXPECT_EQ(rx_capability.width, 640); |
| 241 EXPECT_EQ(rx_capability.height, 480); | 241 EXPECT_EQ(rx_capability.height, 480); |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 244 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
| 245 VideoCaptureDevice::GetDeviceNames(&names_); | 245 VideoCaptureDevice::GetDeviceNames(&names_); |
| 246 if (!names_.size()) { | 246 if (!names_.size()) { |
| 247 DVLOG(1) << "No camera available. Exiting test."; | 247 DVLOG(1) << "No camera available. Exiting test."; |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 scoped_ptr<VideoCaptureDevice> device( | 250 scoped_ptr<VideoCaptureDevice> device( |
| 251 VideoCaptureDevice::Create(names_.front())); | 251 VideoCaptureDevice::Create(names_.front())); |
| 252 ASSERT_TRUE(device.get() != NULL); | 252 ASSERT_TRUE(device.get() != NULL); |
| 253 EXPECT_CALL(*frame_observer_, OnErr()) | 253 EXPECT_CALL(*frame_observer_, OnErr()) |
| 254 .Times(0); | 254 .Times(0); |
| 255 // Get info about the new resolution. | 255 // Get info about the new resolution. |
| 256 VideoCaptureCapability rx_capability_1; | 256 VideoCaptureCapability rx_capability_1; |
| 257 VideoCaptureCapability rx_capability_2; | 257 VideoCaptureCapability rx_capability_2; |
| 258 VideoCaptureCapability capture_format_1(640, | 258 VideoCaptureCapability capture_format_1(640, |
| 259 480, | 259 480, |
| 260 30, | 260 30, |
| 261 VideoCaptureCapability::kI420, | 261 PIXEL_FORMAT_I420, |
| 262 0, | 262 0, |
| 263 false, | 263 false, |
| 264 ConstantResolutionVideoCaptureDevice); | 264 ConstantResolutionVideoCaptureDevice); |
| 265 VideoCaptureCapability capture_format_2(1280, | 265 VideoCaptureCapability capture_format_2(1280, |
| 266 1024, | 266 1024, |
| 267 30, | 267 30, |
| 268 VideoCaptureCapability::kI420, | 268 PIXEL_FORMAT_I420, |
| 269 0, | 269 0, |
| 270 false, | 270 false, |
| 271 ConstantResolutionVideoCaptureDevice); | 271 ConstantResolutionVideoCaptureDevice); |
| 272 VideoCaptureCapability capture_format_3(320, | 272 VideoCaptureCapability capture_format_3(320, |
| 273 240, | 273 240, |
| 274 30, | 274 30, |
| 275 VideoCaptureCapability::kI420, | 275 PIXEL_FORMAT_I420, |
| 276 0, | 276 0, |
| 277 false, | 277 false, |
| 278 ConstantResolutionVideoCaptureDevice); | 278 ConstantResolutionVideoCaptureDevice); |
| 279 | 279 |
| 280 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 280 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 281 .WillOnce(SaveArg<0>(&rx_capability_1)); | 281 .WillOnce(SaveArg<0>(&rx_capability_1)); |
| 282 device->Allocate(capture_format_1, frame_observer_.get()); | 282 device->Allocate(capture_format_1, frame_observer_.get()); |
| 283 device->Start(); | 283 device->Start(); |
| 284 // Nothing shall happen. | 284 // Nothing shall happen. |
| 285 device->Allocate(capture_format_2, frame_observer_.get()); | 285 device->Allocate(capture_format_2, frame_observer_.get()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 314 EXPECT_CALL(*frame_observer_, OnErr()) | 314 EXPECT_CALL(*frame_observer_, OnErr()) |
| 315 .Times(0); | 315 .Times(0); |
| 316 // Get info about the new resolution. | 316 // Get info about the new resolution. |
| 317 VideoCaptureCapability rx_capability; | 317 VideoCaptureCapability rx_capability; |
| 318 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 318 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 319 .WillOnce(SaveArg<0>(&rx_capability)); | 319 .WillOnce(SaveArg<0>(&rx_capability)); |
| 320 | 320 |
| 321 VideoCaptureCapability capture_format(640, | 321 VideoCaptureCapability capture_format(640, |
| 322 480, | 322 480, |
| 323 30, | 323 30, |
| 324 VideoCaptureCapability::kI420, | 324 PIXEL_FORMAT_I420, |
| 325 0, | 325 0, |
| 326 false, | 326 false, |
| 327 ConstantResolutionVideoCaptureDevice); | 327 ConstantResolutionVideoCaptureDevice); |
| 328 device->Allocate(capture_format, frame_observer_.get()); | 328 device->Allocate(capture_format, frame_observer_.get()); |
| 329 | 329 |
| 330 device->Start(); | 330 device->Start(); |
| 331 // Get captured video frames. | 331 // Get captured video frames. |
| 332 PostQuitTask(); | 332 PostQuitTask(); |
| 333 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 333 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 334 EXPECT_EQ(rx_capability.width, 640); | 334 EXPECT_EQ(rx_capability.width, 640); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 352 VideoCaptureCapability rx_capability; | 352 VideoCaptureCapability rx_capability; |
| 353 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 353 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 354 .Times(1).WillOnce(SaveArg<0>(&rx_capability)); | 354 .Times(1).WillOnce(SaveArg<0>(&rx_capability)); |
| 355 | 355 |
| 356 EXPECT_CALL(*frame_observer_, OnErr()) | 356 EXPECT_CALL(*frame_observer_, OnErr()) |
| 357 .Times(0); | 357 .Times(0); |
| 358 | 358 |
| 359 VideoCaptureCapability capture_format(640, | 359 VideoCaptureCapability capture_format(640, |
| 360 480, | 360 480, |
| 361 30, | 361 30, |
| 362 VideoCaptureCapability::kI420, | 362 PIXEL_FORMAT_I420, |
| 363 0, | 363 0, |
| 364 false, | 364 false, |
| 365 ConstantResolutionVideoCaptureDevice); | 365 ConstantResolutionVideoCaptureDevice); |
| 366 device->Allocate(capture_format, frame_observer_.get()); | 366 device->Allocate(capture_format, frame_observer_.get()); |
| 367 | 367 |
| 368 device->Start(); | 368 device->Start(); |
| 369 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 369 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 370 EXPECT_EQ(rx_capability.width, 640); | 370 EXPECT_EQ(rx_capability.width, 640); |
| 371 EXPECT_EQ(rx_capability.height, 480); | 371 EXPECT_EQ(rx_capability.height, 480); |
| 372 EXPECT_EQ(rx_capability.frame_rate, 30); | 372 EXPECT_EQ(rx_capability.frame_rate, 30); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 389 .Times(0); | 389 .Times(0); |
| 390 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 390 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 391 // @ 30 fps, so we don't care about the exact resolution we get. | 391 // @ 30 fps, so we don't care about the exact resolution we get. |
| 392 VideoCaptureCapability rx_capability; | 392 VideoCaptureCapability rx_capability; |
| 393 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) | 393 EXPECT_CALL(*frame_observer_, OnFrameInfo(_)) |
| 394 .WillOnce(SaveArg<0>(&rx_capability)); | 394 .WillOnce(SaveArg<0>(&rx_capability)); |
| 395 | 395 |
| 396 VideoCaptureCapability capture_format(1280, | 396 VideoCaptureCapability capture_format(1280, |
| 397 720, | 397 720, |
| 398 30, | 398 30, |
| 399 VideoCaptureCapability::kMJPEG, | 399 PIXEL_FORMAT_MJPEG, |
| 400 0, | 400 0, |
| 401 false, | 401 false, |
| 402 ConstantResolutionVideoCaptureDevice); | 402 ConstantResolutionVideoCaptureDevice); |
| 403 device->Allocate(capture_format, frame_observer_.get()); | 403 device->Allocate(capture_format, frame_observer_.get()); |
| 404 | 404 |
| 405 device->Start(); | 405 device->Start(); |
| 406 // Get captured video frames. | 406 // Get captured video frames. |
| 407 PostQuitTask(); | 407 PostQuitTask(); |
| 408 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 408 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 409 EXPECT_EQ(rx_capability.color, VideoCaptureCapability::kMJPEG); | 409 EXPECT_EQ(rx_capability.color, PIXEL_FORMAT_MJPEG); |
| 410 device->DeAllocate(); | 410 device->DeAllocate(); |
| 411 } | 411 } |
| 412 | 412 |
| 413 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { | 413 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { |
| 414 VideoCaptureDevice::Names names; | 414 VideoCaptureDevice::Names names; |
| 415 | 415 |
| 416 FakeVideoCaptureDevice::GetDeviceNames(&names); | 416 FakeVideoCaptureDevice::GetDeviceNames(&names); |
| 417 media::VideoCaptureCapability capture_format; | 417 media::VideoCaptureCapability capture_format; |
| 418 capture_format.width = 640; | 418 capture_format.width = 640; |
| 419 capture_format.height = 480; | 419 capture_format.height = 480; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 444 .Times(AtLeast(action_count / 30)); | 444 .Times(AtLeast(action_count / 30)); |
| 445 device->Start(); | 445 device->Start(); |
| 446 for (int i = 0; i < action_count; ++i) { | 446 for (int i = 0; i < action_count; ++i) { |
| 447 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_timeout())); | 447 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_timeout())); |
| 448 } | 448 } |
| 449 device->Stop(); | 449 device->Stop(); |
| 450 device->DeAllocate(); | 450 device->DeAllocate(); |
| 451 } | 451 } |
| 452 | 452 |
| 453 }; // namespace media | 453 }; // namespace media |
| OLD | NEW |