| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #else | 53 #else |
| 54 #define MAYBE_AllocateBadSize AllocateBadSize | 54 #define MAYBE_AllocateBadSize AllocateBadSize |
| 55 #define MAYBE_CaptureMjpeg CaptureMjpeg | 55 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 using ::testing::_; | 58 using ::testing::_; |
| 59 using ::testing::SaveArg; | 59 using ::testing::SaveArg; |
| 60 | 60 |
| 61 namespace media { | 61 namespace media { |
| 62 | 62 |
| 63 class MockClient : public media::VideoCaptureDevice::Client { | 63 namespace { |
| 64 |
| 65 class MockClient : public VideoCaptureDevice::Client { |
| 64 public: | 66 public: |
| 65 MOCK_METHOD2(ReserveOutputBuffer, | 67 MOCK_METHOD2(ReserveOutputBuffer, |
| 66 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 68 scoped_refptr<Buffer>(VideoFrame::Format format, |
| 67 const gfx::Size& dimensions)); | 69 const gfx::Size& dimensions)); |
| 68 MOCK_METHOD0(OnErr, void()); | 70 MOCK_METHOD0(OnErr, void()); |
| 69 | 71 |
| 70 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 72 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| 71 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} | 73 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} |
| 72 | 74 |
| 73 virtual void OnError(const std::string& error_message) override { | 75 void OnError(const std::string& error_message) override { |
| 74 OnErr(); | 76 OnErr(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 virtual void OnIncomingCapturedData(const uint8* data, | 79 void OnIncomingCapturedData(const uint8* data, |
| 78 int length, | 80 int length, |
| 79 const VideoCaptureFormat& format, | 81 const VideoCaptureFormat& format, |
| 80 int rotation, | 82 int rotation, |
| 81 base::TimeTicks timestamp) override { | 83 base::TimeTicks timestamp) override { |
| 82 ASSERT_GT(length, 0); | 84 ASSERT_GT(length, 0); |
| 83 ASSERT_TRUE(data != NULL); | 85 ASSERT_TRUE(data != NULL); |
| 84 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); | 86 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); |
| 85 } | 87 } |
| 86 | 88 |
| 87 virtual void OnIncomingCapturedVideoFrame( | 89 void OnIncomingCapturedVideoFrame( |
| 88 const scoped_refptr<Buffer>& buffer, | 90 const scoped_refptr<Buffer>& buffer, |
| 89 const media::VideoCaptureFormat& buffer_format, | 91 const VideoCaptureFormat& buffer_format, |
| 90 const scoped_refptr<media::VideoFrame>& frame, | 92 const scoped_refptr<VideoFrame>& frame, |
| 91 base::TimeTicks timestamp) override { | 93 base::TimeTicks timestamp) override { |
| 92 NOTREACHED(); | 94 NOTREACHED(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 private: | 97 private: |
| 96 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 98 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 97 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; | 99 base::Callback<void(const VideoCaptureFormat&)> frame_cb_; |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 class DeviceEnumerationListener : | 102 class DeviceEnumerationListener : |
| 101 public base::RefCounted<DeviceEnumerationListener>{ | 103 public base::RefCounted<DeviceEnumerationListener> { |
| 102 public: | 104 public: |
| 103 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, | 105 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, |
| 104 void(media::VideoCaptureDevice::Names* names)); | 106 void(VideoCaptureDevice::Names* names)); |
| 105 // GMock doesn't support move-only arguments, so we use this forward method. | 107 // GMock doesn't support move-only arguments, so we use this forward method. |
| 106 void OnEnumeratedDevicesCallback( | 108 void OnEnumeratedDevicesCallback( |
| 107 scoped_ptr<media::VideoCaptureDevice::Names> names) { | 109 scoped_ptr<VideoCaptureDevice::Names> names) { |
| 108 OnEnumeratedDevicesCallbackPtr(names.release()); | 110 OnEnumeratedDevicesCallbackPtr(names.release()); |
| 109 } | 111 } |
| 110 private: | 112 private: |
| 111 friend class base::RefCounted<DeviceEnumerationListener>; | 113 friend class base::RefCounted<DeviceEnumerationListener>; |
| 112 virtual ~DeviceEnumerationListener() {} | 114 virtual ~DeviceEnumerationListener() {} |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 class VideoCaptureDeviceTest : public testing::Test { | 117 class VideoCaptureDeviceTest : public testing::Test { |
| 116 protected: | 118 protected: |
| 117 typedef media::VideoCaptureDevice::Client Client; | 119 typedef VideoCaptureDevice::Client Client; |
| 118 | 120 |
| 119 VideoCaptureDeviceTest() | 121 VideoCaptureDeviceTest() |
| 120 : loop_(new base::MessageLoop()), | 122 : loop_(new base::MessageLoop()), |
| 121 client_( | 123 client_( |
| 122 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 124 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
| 123 base::Unretained(this)))), | 125 base::Unretained(this)))), |
| 124 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( | 126 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( |
| 125 base::MessageLoopProxy::current())) { | 127 base::MessageLoopProxy::current())) { |
| 126 device_enumeration_listener_ = new DeviceEnumerationListener(); | 128 device_enumeration_listener_ = new DeviceEnumerationListener(); |
| 127 } | 129 } |
| 128 | 130 |
| 131 #if defined(OS_ANDROID) |
| 129 void SetUp() override { | 132 void SetUp() override { |
| 130 #if defined(OS_ANDROID) | 133 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
| 131 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | |
| 132 base::android::AttachCurrentThread()); | 134 base::android::AttachCurrentThread()); |
| 135 } |
| 133 #endif | 136 #endif |
| 134 } | |
| 135 | 137 |
| 136 void ResetWithNewClient() { | 138 void ResetWithNewClient() { |
| 137 client_.reset(new MockClient(base::Bind( | 139 client_.reset(new MockClient(base::Bind( |
| 138 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 140 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void OnFrameCaptured(const VideoCaptureFormat& format) { | 143 void OnFrameCaptured(const VideoCaptureFormat& format) { |
| 142 last_format_ = format; | 144 last_format_ = format; |
| 143 run_loop_->QuitClosure().Run(); | 145 run_loop_->QuitClosure().Run(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 void WaitForCapturedFrame() { | 148 void WaitForCapturedFrame() { |
| 147 run_loop_.reset(new base::RunLoop()); | 149 run_loop_.reset(new base::RunLoop()); |
| 148 run_loop_->Run(); | 150 run_loop_->Run(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 scoped_ptr<media::VideoCaptureDevice::Names> EnumerateDevices() { | 153 scoped_ptr<VideoCaptureDevice::Names> EnumerateDevices() { |
| 152 media::VideoCaptureDevice::Names* names; | 154 VideoCaptureDevice::Names* names; |
| 153 EXPECT_CALL(*device_enumeration_listener_.get(), | 155 EXPECT_CALL(*device_enumeration_listener_.get(), |
| 154 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); | 156 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); |
| 155 | 157 |
| 156 video_capture_device_factory_->EnumerateDeviceNames( | 158 video_capture_device_factory_->EnumerateDeviceNames( |
| 157 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, | 159 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, |
| 158 device_enumeration_listener_)); | 160 device_enumeration_listener_)); |
| 159 base::MessageLoop::current()->RunUntilIdle(); | 161 base::MessageLoop::current()->RunUntilIdle(); |
| 160 return scoped_ptr<media::VideoCaptureDevice::Names>(names); | 162 return scoped_ptr<VideoCaptureDevice::Names>(names); |
| 161 } | 163 } |
| 162 | 164 |
| 163 const VideoCaptureFormat& last_format() const { return last_format_; } | 165 const VideoCaptureFormat& last_format() const { return last_format_; } |
| 164 | 166 |
| 165 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | 167 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
| 166 const VideoPixelFormat& pixel_format) { | 168 const VideoPixelFormat& pixel_format) { |
| 167 names_ = EnumerateDevices(); | 169 names_ = EnumerateDevices(); |
| 168 if (!names_->size()) { | 170 if (names_->empty()) { |
| 169 DVLOG(1) << "No camera available."; | 171 DVLOG(1) << "No camera available."; |
| 170 return scoped_ptr<VideoCaptureDevice::Name>(); | 172 return scoped_ptr<VideoCaptureDevice::Name>(); |
| 171 } | 173 } |
| 172 VideoCaptureDevice::Names::iterator names_iterator; | 174 for (const auto& names_iterator : *names_) { |
| 173 for (names_iterator = names_->begin(); names_iterator != names_->end(); | |
| 174 ++names_iterator) { | |
| 175 VideoCaptureFormats supported_formats; | 175 VideoCaptureFormats supported_formats; |
| 176 video_capture_device_factory_->GetDeviceSupportedFormats( | 176 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 177 *names_iterator, | 177 names_iterator, |
| 178 &supported_formats); | 178 &supported_formats); |
| 179 VideoCaptureFormats::iterator formats_iterator; | 179 for (const auto& formats_iterator : supported_formats) { |
| 180 for (formats_iterator = supported_formats.begin(); | 180 if (formats_iterator.pixel_format == pixel_format) { |
| 181 formats_iterator != supported_formats.end(); ++formats_iterator) { | |
| 182 if (formats_iterator->pixel_format == pixel_format) { | |
| 183 return scoped_ptr<VideoCaptureDevice::Name>( | 181 return scoped_ptr<VideoCaptureDevice::Name>( |
| 184 new VideoCaptureDevice::Name(*names_iterator)); | 182 new VideoCaptureDevice::Name(names_iterator)); |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 } | 185 } |
| 188 DVLOG(1) << "No camera can capture the format: " << pixel_format; | 186 DVLOG(1) << "No camera can capture the format: " << pixel_format; |
| 189 return scoped_ptr<VideoCaptureDevice::Name>(); | 187 return scoped_ptr<VideoCaptureDevice::Name>(); |
| 190 } | 188 } |
| 191 | 189 |
| 192 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
| 193 base::win::ScopedCOMInitializer initialize_com_; | 191 base::win::ScopedCOMInitializer initialize_com_; |
| 194 #endif | 192 #endif |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 capture_params.requested_format.frame_rate = 30; | 238 capture_params.requested_format.frame_rate = 30; |
| 241 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 239 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 242 device->AllocateAndStart(capture_params, client_.Pass()); | 240 device->AllocateAndStart(capture_params, client_.Pass()); |
| 243 device->StopAndDeAllocate(); | 241 device->StopAndDeAllocate(); |
| 244 } | 242 } |
| 245 #endif | 243 #endif |
| 246 } | 244 } |
| 247 | 245 |
| 248 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 246 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
| 249 names_ = EnumerateDevices(); | 247 names_ = EnumerateDevices(); |
| 250 if (!names_->size()) { | 248 if (names_->empty()) { |
| 251 DVLOG(1) << "No camera available. Exiting test."; | 249 DVLOG(1) << "No camera available. Exiting test."; |
| 252 return; | 250 return; |
| 253 } | 251 } |
| 254 | 252 |
| 255 scoped_ptr<VideoCaptureDevice> device( | 253 scoped_ptr<VideoCaptureDevice> device( |
| 256 video_capture_device_factory_->Create(names_->front())); | 254 video_capture_device_factory_->Create(names_->front())); |
| 257 ASSERT_TRUE(device); | 255 ASSERT_TRUE(device); |
| 258 DVLOG(1) << names_->front().id(); | 256 DVLOG(1) << names_->front().id(); |
| 259 | 257 |
| 260 EXPECT_CALL(*client_, OnErr()) | 258 EXPECT_CALL(*client_, OnErr()).Times(0); |
| 261 .Times(0); | |
| 262 | 259 |
| 263 VideoCaptureParams capture_params; | 260 VideoCaptureParams capture_params; |
| 264 capture_params.requested_format.frame_size.SetSize(640, 480); | 261 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 265 capture_params.requested_format.frame_rate = 30; | 262 capture_params.requested_format.frame_rate = 30; |
| 266 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 263 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 267 device->AllocateAndStart(capture_params, client_.Pass()); | 264 device->AllocateAndStart(capture_params, client_.Pass()); |
| 268 // Get captured video frames. | 265 // Get captured video frames. |
| 269 WaitForCapturedFrame(); | 266 WaitForCapturedFrame(); |
| 270 EXPECT_EQ(last_format().frame_size.width(), 640); | 267 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 271 EXPECT_EQ(last_format().frame_size.height(), 480); | 268 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 272 device->StopAndDeAllocate(); | 269 device->StopAndDeAllocate(); |
| 273 } | 270 } |
| 274 | 271 |
| 275 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 272 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
| 276 names_ = EnumerateDevices(); | 273 names_ = EnumerateDevices(); |
| 277 if (!names_->size()) { | 274 if (names_->empty()) { |
| 278 DVLOG(1) << "No camera available. Exiting test."; | 275 DVLOG(1) << "No camera available. Exiting test."; |
| 279 return; | 276 return; |
| 280 } | 277 } |
| 281 | 278 |
| 282 scoped_ptr<VideoCaptureDevice> device( | 279 scoped_ptr<VideoCaptureDevice> device( |
| 283 video_capture_device_factory_->Create(names_->front())); | 280 video_capture_device_factory_->Create(names_->front())); |
| 284 ASSERT_TRUE(device); | 281 ASSERT_TRUE(device); |
| 285 | 282 |
| 286 EXPECT_CALL(*client_, OnErr()) | 283 EXPECT_CALL(*client_, OnErr()).Times(0); |
| 287 .Times(0); | |
| 288 | 284 |
| 289 VideoCaptureParams capture_params; | 285 VideoCaptureParams capture_params; |
| 290 capture_params.requested_format.frame_size.SetSize(1280, 720); | 286 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 291 capture_params.requested_format.frame_rate = 30; | 287 capture_params.requested_format.frame_rate = 30; |
| 292 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 288 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 293 device->AllocateAndStart(capture_params, client_.Pass()); | 289 device->AllocateAndStart(capture_params, client_.Pass()); |
| 294 // Get captured video frames. | 290 // Get captured video frames. |
| 295 WaitForCapturedFrame(); | 291 WaitForCapturedFrame(); |
| 296 device->StopAndDeAllocate(); | 292 device->StopAndDeAllocate(); |
| 297 } | 293 } |
| 298 | 294 |
| 299 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 295 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 300 names_ = EnumerateDevices(); | 296 names_ = EnumerateDevices(); |
| 301 if (!names_->size()) { | 297 if (names_->empty()) { |
| 302 DVLOG(1) << "No camera available. Exiting test."; | 298 DVLOG(1) << "No camera available. Exiting test."; |
| 303 return; | 299 return; |
| 304 } | 300 } |
| 305 scoped_ptr<VideoCaptureDevice> device( | 301 scoped_ptr<VideoCaptureDevice> device( |
| 306 video_capture_device_factory_->Create(names_->front())); | 302 video_capture_device_factory_->Create(names_->front())); |
| 307 ASSERT_TRUE(device); | 303 ASSERT_TRUE(device); |
| 308 | 304 |
| 309 EXPECT_CALL(*client_, OnErr()) | 305 EXPECT_CALL(*client_, OnErr()).Times(0); |
| 310 .Times(0); | |
| 311 | 306 |
| 312 VideoCaptureParams capture_params; | 307 VideoCaptureParams capture_params; |
| 313 capture_params.requested_format.frame_size.SetSize(637, 472); | 308 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 314 capture_params.requested_format.frame_rate = 35; | 309 capture_params.requested_format.frame_rate = 35; |
| 315 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 310 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 316 device->AllocateAndStart(capture_params, client_.Pass()); | 311 device->AllocateAndStart(capture_params, client_.Pass()); |
| 317 WaitForCapturedFrame(); | 312 WaitForCapturedFrame(); |
| 318 device->StopAndDeAllocate(); | 313 device->StopAndDeAllocate(); |
| 319 EXPECT_EQ(last_format().frame_size.width(), 640); | 314 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 320 EXPECT_EQ(last_format().frame_size.height(), 480); | 315 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 321 } | 316 } |
| 322 | 317 |
| 323 // Cause hangs on Windows Debug. http://crbug.com/417824 | 318 // Cause hangs on Windows Debug. http://crbug.com/417824 |
| 324 #if defined(OS_WIN) && !defined(NDEBUG) | 319 #if defined(OS_WIN) && !defined(NDEBUG) |
| 325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera | 320 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera |
| 326 #else | 321 #else |
| 327 #define MAYBE_ReAllocateCamera ReAllocateCamera | 322 #define MAYBE_ReAllocateCamera ReAllocateCamera |
| 328 #endif | 323 #endif |
| 329 | 324 |
| 330 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { | 325 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { |
| 331 names_ = EnumerateDevices(); | 326 names_ = EnumerateDevices(); |
| 332 if (!names_->size()) { | 327 if (names_->empty()) { |
| 333 DVLOG(1) << "No camera available. Exiting test."; | 328 DVLOG(1) << "No camera available. Exiting test."; |
| 334 return; | 329 return; |
| 335 } | 330 } |
| 336 | 331 |
| 337 // First, do a number of very fast device start/stops. | 332 // First, do a number of very fast device start/stops. |
| 338 for (int i = 0; i <= 5; i++) { | 333 for (int i = 0; i <= 5; i++) { |
| 339 ResetWithNewClient(); | 334 ResetWithNewClient(); |
| 340 scoped_ptr<VideoCaptureDevice> device( | 335 scoped_ptr<VideoCaptureDevice> device( |
| 341 video_capture_device_factory_->Create(names_->front())); | 336 video_capture_device_factory_->Create(names_->front())); |
| 342 gfx::Size resolution; | 337 gfx::Size resolution; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 366 device->AllocateAndStart(capture_params, client_.Pass()); | 361 device->AllocateAndStart(capture_params, client_.Pass()); |
| 367 WaitForCapturedFrame(); | 362 WaitForCapturedFrame(); |
| 368 device->StopAndDeAllocate(); | 363 device->StopAndDeAllocate(); |
| 369 device.reset(); | 364 device.reset(); |
| 370 EXPECT_EQ(last_format().frame_size.width(), 320); | 365 EXPECT_EQ(last_format().frame_size.width(), 320); |
| 371 EXPECT_EQ(last_format().frame_size.height(), 240); | 366 EXPECT_EQ(last_format().frame_size.height(), 240); |
| 372 } | 367 } |
| 373 | 368 |
| 374 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 369 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
| 375 names_ = EnumerateDevices(); | 370 names_ = EnumerateDevices(); |
| 376 if (!names_->size()) { | 371 if (names_->empty()) { |
| 377 DVLOG(1) << "No camera available. Exiting test."; | 372 DVLOG(1) << "No camera available. Exiting test."; |
| 378 return; | 373 return; |
| 379 } | 374 } |
| 380 scoped_ptr<VideoCaptureDevice> device( | 375 scoped_ptr<VideoCaptureDevice> device( |
| 381 video_capture_device_factory_->Create(names_->front())); | 376 video_capture_device_factory_->Create(names_->front())); |
| 382 ASSERT_TRUE(device); | 377 ASSERT_TRUE(device); |
| 383 | 378 |
| 384 EXPECT_CALL(*client_, OnErr()) | 379 EXPECT_CALL(*client_, OnErr()).Times(0); |
| 385 .Times(0); | |
| 386 | 380 |
| 387 VideoCaptureParams capture_params; | 381 VideoCaptureParams capture_params; |
| 388 capture_params.requested_format.frame_size.SetSize(640, 480); | 382 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 389 capture_params.requested_format.frame_rate = 30; | 383 capture_params.requested_format.frame_rate = 30; |
| 390 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 384 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 391 device->AllocateAndStart(capture_params, client_.Pass()); | 385 device->AllocateAndStart(capture_params, client_.Pass()); |
| 392 // Get captured video frames. | 386 // Get captured video frames. |
| 393 WaitForCapturedFrame(); | 387 WaitForCapturedFrame(); |
| 394 EXPECT_EQ(last_format().frame_size.width(), 640); | 388 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 395 EXPECT_EQ(last_format().frame_size.height(), 480); | 389 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 396 EXPECT_EQ(last_format().frame_rate, 30); | 390 EXPECT_EQ(last_format().frame_rate, 30); |
| 397 device->StopAndDeAllocate(); | 391 device->StopAndDeAllocate(); |
| 398 } | 392 } |
| 399 | 393 |
| 400 // Start the camera in 720p to capture MJPEG instead of a raw format. | 394 // Start the camera in 720p to capture MJPEG instead of a raw format. |
| 401 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 395 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| 402 scoped_ptr<VideoCaptureDevice::Name> name = | 396 scoped_ptr<VideoCaptureDevice::Name> name = |
| 403 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 397 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
| 404 if (!name) { | 398 if (!name) { |
| 405 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 399 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| 406 return; | 400 return; |
| 407 } | 401 } |
| 408 scoped_ptr<VideoCaptureDevice> device( | 402 scoped_ptr<VideoCaptureDevice> device( |
| 409 video_capture_device_factory_->Create(*name)); | 403 video_capture_device_factory_->Create(*name)); |
| 410 ASSERT_TRUE(device); | 404 ASSERT_TRUE(device); |
| 411 | 405 |
| 412 EXPECT_CALL(*client_, OnErr()) | 406 EXPECT_CALL(*client_, OnErr()).Times(0); |
| 413 .Times(0); | |
| 414 | 407 |
| 415 VideoCaptureParams capture_params; | 408 VideoCaptureParams capture_params; |
| 416 capture_params.requested_format.frame_size.SetSize(1280, 720); | 409 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 417 capture_params.requested_format.frame_rate = 30; | 410 capture_params.requested_format.frame_rate = 30; |
| 418 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 411 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 419 device->AllocateAndStart(capture_params, client_.Pass()); | 412 device->AllocateAndStart(capture_params, client_.Pass()); |
| 420 // Get captured video frames. | 413 // Get captured video frames. |
| 421 WaitForCapturedFrame(); | 414 WaitForCapturedFrame(); |
| 422 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 415 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 423 // @ 30 fps, so we don't care about the exact resolution we get. | 416 // @ 30 fps, so we don't care about the exact resolution we get. |
| 424 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 417 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
| 425 device->StopAndDeAllocate(); | 418 device->StopAndDeAllocate(); |
| 426 } | 419 } |
| 427 | 420 |
| 428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 421 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 422 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 430 // GetDeviceSupportedFormats(). | 423 // GetDeviceSupportedFormats(). |
| 431 scoped_ptr<VideoCaptureDevice::Name> name = | 424 scoped_ptr<VideoCaptureDevice::Name> name = |
| 432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 425 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 433 // 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 |
| 434 // since we cannot forecast the hardware capabilities. | 427 // since we cannot forecast the hardware capabilities. |
| 435 ASSERT_FALSE(name); | 428 ASSERT_FALSE(name); |
| 436 } | 429 } |
| 437 | 430 |
| 431 } // namespace |
| 432 |
| 438 }; // namespace media | 433 }; // namespace media |
| OLD | NEW |