| 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" | |
| 7 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | |
| 10 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 11 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 12 #include "media/video/capture/fake_video_capture_device.h" | |
| 13 #include "media/video/capture/fake_video_capture_device_factory.h" | |
| 14 #include "media/video/capture/video_capture_device.h" | 10 #include "media/video/capture/video_capture_device.h" |
| 11 #include "media/video/capture/video_capture_device_factory.h" |
| 15 #include "media/video/capture/video_capture_types.h" | 12 #include "media/video/capture/video_capture_types.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 15 |
| 19 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 20 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
| 21 #include "media/video/capture/win/video_capture_device_mf_win.h" | 18 #include "media/video/capture/win/video_capture_device_mf_win.h" |
| 22 #endif | 19 #endif |
| 23 | 20 |
| 24 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 43 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| 47 #define ReAllocateCamera DISABLED_ReAllocateCamera | 44 #define ReAllocateCamera DISABLED_ReAllocateCamera |
| 48 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 45 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
| 49 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning | 46 #define DeAllocateCameraWhileRunning DISABLED_DeAllocateCameraWhileRunning |
| 50 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg | 47 #define MAYBE_CaptureMjpeg DISABLED_CaptureMjpeg |
| 51 #else | 48 #else |
| 52 #define MAYBE_AllocateBadSize AllocateBadSize | 49 #define MAYBE_AllocateBadSize AllocateBadSize |
| 53 #define MAYBE_CaptureMjpeg CaptureMjpeg | 50 #define MAYBE_CaptureMjpeg CaptureMjpeg |
| 54 #endif | 51 #endif |
| 55 | 52 |
| 56 using ::testing::_; | |
| 57 using ::testing::AnyNumber; | |
| 58 using ::testing::Return; | |
| 59 using ::testing::AtLeast; | |
| 60 | |
| 61 namespace media { | 53 namespace media { |
| 62 | 54 |
| 63 class MockClient : public media::VideoCaptureDevice::Client { | 55 class MockClient : public media::VideoCaptureDevice::Client { |
| 64 public: | 56 public: |
| 65 MOCK_METHOD2(ReserveOutputBuffer, | 57 MOCK_METHOD2(ReserveOutputBuffer, |
| 66 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 58 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
| 67 const gfx::Size& dimensions)); | 59 const gfx::Size& dimensions)); |
| 68 MOCK_METHOD0(OnErr, void()); | 60 MOCK_METHOD0(OnErr, void()); |
| 69 | 61 |
| 70 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 62 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 97 | 89 |
| 98 class VideoCaptureDeviceTest : public testing::Test { | 90 class VideoCaptureDeviceTest : public testing::Test { |
| 99 protected: | 91 protected: |
| 100 typedef media::VideoCaptureDevice::Client Client; | 92 typedef media::VideoCaptureDevice::Client Client; |
| 101 | 93 |
| 102 VideoCaptureDeviceTest() | 94 VideoCaptureDeviceTest() |
| 103 : loop_(new base::MessageLoop()), | 95 : loop_(new base::MessageLoop()), |
| 104 client_( | 96 client_( |
| 105 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 97 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
| 106 base::Unretained(this)))), | 98 base::Unretained(this)))), |
| 107 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} | 99 video_capture_device_factory_( |
| 100 VideoCaptureDeviceFactory::CreateFactory()) {} |
| 108 | 101 |
| 109 virtual void SetUp() { | 102 virtual void SetUp() { |
| 110 #if defined(OS_ANDROID) | 103 #if defined(OS_ANDROID) |
| 111 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 104 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
| 112 base::android::AttachCurrentThread()); | 105 base::android::AttachCurrentThread()); |
| 113 #endif | 106 #endif |
| 114 } | 107 } |
| 115 | 108 |
| 116 void ResetWithNewClient() { | 109 void ResetWithNewClient() { |
| 117 client_.reset(new MockClient(base::Bind( | 110 client_.reset(new MockClient(base::Bind( |
| 118 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); | 111 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); |
| 119 } | 112 } |
| 120 | 113 |
| 121 void OnFrameCaptured(const VideoCaptureFormat& format) { | 114 void OnFrameCaptured(const VideoCaptureFormat& format) { |
| 122 last_format_ = format; | 115 last_format_ = format; |
| 123 run_loop_->QuitClosure().Run(); | 116 run_loop_->QuitClosure().Run(); |
| 124 } | 117 } |
| 125 | 118 |
| 126 void WaitForCapturedFrame() { | 119 void WaitForCapturedFrame() { |
| 127 run_loop_.reset(new base::RunLoop()); | 120 run_loop_.reset(new base::RunLoop()); |
| 128 run_loop_->Run(); | 121 run_loop_->Run(); |
| 129 } | 122 } |
| 130 | 123 |
| 131 const VideoCaptureFormat& last_format() const { return last_format_; } | 124 const VideoCaptureFormat& last_format() const { return last_format_; } |
| 132 | 125 |
| 133 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( | 126 scoped_ptr<VideoCaptureDevice::Name> GetFirstDeviceNameSupportingPixelFormat( |
| 134 const VideoPixelFormat& pixel_format) { | 127 const VideoPixelFormat& pixel_format) { |
| 135 VideoCaptureDevice::GetDeviceNames(&names_); | 128 video_capture_device_factory_->GetDeviceNames(&names_); |
| 136 if (!names_.size()) { | 129 if (!names_.size()) { |
| 137 DVLOG(1) << "No camera available."; | 130 DVLOG(1) << "No camera available."; |
| 138 return scoped_ptr<VideoCaptureDevice::Name>(); | 131 return scoped_ptr<VideoCaptureDevice::Name>(); |
| 139 } | 132 } |
| 140 VideoCaptureDevice::Names::iterator names_iterator; | 133 VideoCaptureDevice::Names::iterator names_iterator; |
| 141 for (names_iterator = names_.begin(); names_iterator != names_.end(); | 134 for (names_iterator = names_.begin(); names_iterator != names_.end(); |
| 142 ++names_iterator) { | 135 ++names_iterator) { |
| 143 VideoCaptureFormats supported_formats; | 136 VideoCaptureFormats supported_formats; |
| 144 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator, | 137 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 145 &supported_formats); | 138 *names_iterator, |
| 139 &supported_formats); |
| 146 VideoCaptureFormats::iterator formats_iterator; | 140 VideoCaptureFormats::iterator formats_iterator; |
| 147 for (formats_iterator = supported_formats.begin(); | 141 for (formats_iterator = supported_formats.begin(); |
| 148 formats_iterator != supported_formats.end(); ++formats_iterator) { | 142 formats_iterator != supported_formats.end(); ++formats_iterator) { |
| 149 if (formats_iterator->pixel_format == pixel_format) { | 143 if (formats_iterator->pixel_format == pixel_format) { |
| 150 return scoped_ptr<VideoCaptureDevice::Name>( | 144 return scoped_ptr<VideoCaptureDevice::Name>( |
| 151 new VideoCaptureDevice::Name(*names_iterator)); | 145 new VideoCaptureDevice::Name(*names_iterator)); |
| 152 } | 146 } |
| 153 } | 147 } |
| 154 } | 148 } |
| 155 DVLOG(1) << "No camera can capture the format: " << pixel_format; | 149 DVLOG(1) << "No camera can capture the format: " << pixel_format; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 164 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
| 171 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
| 172 VideoCaptureDevice::Name::CaptureApiType api_type = | 166 VideoCaptureDevice::Name::CaptureApiType api_type = |
| 173 VideoCaptureDeviceMFWin::PlatformSupported() | 167 VideoCaptureDeviceMFWin::PlatformSupported() |
| 174 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | 168 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION |
| 175 : VideoCaptureDevice::Name::DIRECT_SHOW; | 169 : VideoCaptureDevice::Name::DIRECT_SHOW; |
| 176 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | 170 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
| 177 #else | 171 #else |
| 178 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); | 172 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); |
| 179 #endif | 173 #endif |
| 180 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 174 scoped_ptr<VideoCaptureDevice> device = |
| 175 video_capture_device_factory_->Create(device_name); |
| 181 EXPECT_TRUE(device == NULL); | 176 EXPECT_TRUE(device == NULL); |
| 182 } | 177 } |
| 183 | 178 |
| 184 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 179 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
| 185 VideoCaptureDevice::GetDeviceNames(&names_); | 180 video_capture_device_factory_->GetDeviceNames(&names_); |
| 186 if (!names_.size()) { | 181 if (!names_.size()) { |
| 187 DVLOG(1) << "No camera available. Exiting test."; | 182 DVLOG(1) << "No camera available. Exiting test."; |
| 188 return; | 183 return; |
| 189 } | 184 } |
| 190 | 185 |
| 191 scoped_ptr<VideoCaptureDevice> device( | 186 scoped_ptr<VideoCaptureDevice> device( |
| 192 VideoCaptureDevice::Create(names_.front())); | 187 video_capture_device_factory_->Create(names_.front())); |
| 193 ASSERT_TRUE(device); | 188 ASSERT_TRUE(device); |
| 194 DVLOG(1) << names_.front().id(); | 189 DVLOG(1) << names_.front().id(); |
| 195 | 190 |
| 196 EXPECT_CALL(*client_, OnErr()) | 191 EXPECT_CALL(*client_, OnErr()) |
| 197 .Times(0); | 192 .Times(0); |
| 198 | 193 |
| 199 VideoCaptureParams capture_params; | 194 VideoCaptureParams capture_params; |
| 200 capture_params.requested_format.frame_size.SetSize(640, 480); | 195 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 201 capture_params.requested_format.frame_rate = 30; | 196 capture_params.requested_format.frame_rate = 30; |
| 202 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 197 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 203 capture_params.allow_resolution_change = false; | 198 capture_params.allow_resolution_change = false; |
| 204 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 199 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 205 // Get captured video frames. | 200 // Get captured video frames. |
| 206 WaitForCapturedFrame(); | 201 WaitForCapturedFrame(); |
| 207 EXPECT_EQ(last_format().frame_size.width(), 640); | 202 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 208 EXPECT_EQ(last_format().frame_size.height(), 480); | 203 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 209 device->StopAndDeAllocate(); | 204 device->StopAndDeAllocate(); |
| 210 } | 205 } |
| 211 | 206 |
| 212 TEST_F(VideoCaptureDeviceTest, Capture720p) { | 207 TEST_F(VideoCaptureDeviceTest, Capture720p) { |
| 213 VideoCaptureDevice::GetDeviceNames(&names_); | 208 video_capture_device_factory_->GetDeviceNames(&names_); |
| 214 if (!names_.size()) { | 209 if (!names_.size()) { |
| 215 DVLOG(1) << "No camera available. Exiting test."; | 210 DVLOG(1) << "No camera available. Exiting test."; |
| 216 return; | 211 return; |
| 217 } | 212 } |
| 218 | 213 |
| 219 scoped_ptr<VideoCaptureDevice> device( | 214 scoped_ptr<VideoCaptureDevice> device( |
| 220 VideoCaptureDevice::Create(names_.front())); | 215 video_capture_device_factory_->Create(names_.front())); |
| 221 ASSERT_TRUE(device); | 216 ASSERT_TRUE(device); |
| 222 | 217 |
| 223 EXPECT_CALL(*client_, OnErr()) | 218 EXPECT_CALL(*client_, OnErr()) |
| 224 .Times(0); | 219 .Times(0); |
| 225 | 220 |
| 226 VideoCaptureParams capture_params; | 221 VideoCaptureParams capture_params; |
| 227 capture_params.requested_format.frame_size.SetSize(1280, 720); | 222 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 228 capture_params.requested_format.frame_rate = 30; | 223 capture_params.requested_format.frame_rate = 30; |
| 229 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 224 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 230 capture_params.allow_resolution_change = false; | 225 capture_params.allow_resolution_change = false; |
| 231 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 226 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 232 // Get captured video frames. | 227 // Get captured video frames. |
| 233 WaitForCapturedFrame(); | 228 WaitForCapturedFrame(); |
| 234 device->StopAndDeAllocate(); | 229 device->StopAndDeAllocate(); |
| 235 } | 230 } |
| 236 | 231 |
| 237 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { | 232 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { |
| 238 VideoCaptureDevice::GetDeviceNames(&names_); | 233 video_capture_device_factory_->GetDeviceNames(&names_); |
| 239 if (!names_.size()) { | 234 if (!names_.size()) { |
| 240 DVLOG(1) << "No camera available. Exiting test."; | 235 DVLOG(1) << "No camera available. Exiting test."; |
| 241 return; | 236 return; |
| 242 } | 237 } |
| 243 scoped_ptr<VideoCaptureDevice> device( | 238 scoped_ptr<VideoCaptureDevice> device( |
| 244 VideoCaptureDevice::Create(names_.front())); | 239 video_capture_device_factory_->Create(names_.front())); |
| 245 ASSERT_TRUE(device); | 240 ASSERT_TRUE(device); |
| 246 | 241 |
| 247 EXPECT_CALL(*client_, OnErr()) | 242 EXPECT_CALL(*client_, OnErr()) |
| 248 .Times(0); | 243 .Times(0); |
| 249 | 244 |
| 250 VideoCaptureParams capture_params; | 245 VideoCaptureParams capture_params; |
| 251 capture_params.requested_format.frame_size.SetSize(637, 472); | 246 capture_params.requested_format.frame_size.SetSize(637, 472); |
| 252 capture_params.requested_format.frame_rate = 35; | 247 capture_params.requested_format.frame_rate = 35; |
| 253 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 248 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 254 capture_params.allow_resolution_change = false; | 249 capture_params.allow_resolution_change = false; |
| 255 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 250 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 256 WaitForCapturedFrame(); | 251 WaitForCapturedFrame(); |
| 257 device->StopAndDeAllocate(); | 252 device->StopAndDeAllocate(); |
| 258 EXPECT_EQ(last_format().frame_size.width(), 640); | 253 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 259 EXPECT_EQ(last_format().frame_size.height(), 480); | 254 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 260 } | 255 } |
| 261 | 256 |
| 262 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { | 257 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { |
| 263 VideoCaptureDevice::GetDeviceNames(&names_); | 258 video_capture_device_factory_->GetDeviceNames(&names_); |
| 264 if (!names_.size()) { | 259 if (!names_.size()) { |
| 265 DVLOG(1) << "No camera available. Exiting test."; | 260 DVLOG(1) << "No camera available. Exiting test."; |
| 266 return; | 261 return; |
| 267 } | 262 } |
| 268 | 263 |
| 269 // First, do a number of very fast device start/stops. | 264 // First, do a number of very fast device start/stops. |
| 270 for (int i = 0; i <= 5; i++) { | 265 for (int i = 0; i <= 5; i++) { |
| 271 ResetWithNewClient(); | 266 ResetWithNewClient(); |
| 272 scoped_ptr<VideoCaptureDevice> device( | 267 scoped_ptr<VideoCaptureDevice> device( |
| 273 VideoCaptureDevice::Create(names_.front())); | 268 video_capture_device_factory_->Create(names_.front())); |
| 274 gfx::Size resolution; | 269 gfx::Size resolution; |
| 275 if (i % 2) { | 270 if (i % 2) { |
| 276 resolution = gfx::Size(640, 480); | 271 resolution = gfx::Size(640, 480); |
| 277 } else { | 272 } else { |
| 278 resolution = gfx::Size(1280, 1024); | 273 resolution = gfx::Size(1280, 1024); |
| 279 } | 274 } |
| 280 VideoCaptureParams capture_params; | 275 VideoCaptureParams capture_params; |
| 281 capture_params.requested_format.frame_size = resolution; | 276 capture_params.requested_format.frame_size = resolution; |
| 282 capture_params.requested_format.frame_rate = 30; | 277 capture_params.requested_format.frame_rate = 30; |
| 283 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 278 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 284 capture_params.allow_resolution_change = false; | 279 capture_params.allow_resolution_change = false; |
| 285 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 280 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 286 device->StopAndDeAllocate(); | 281 device->StopAndDeAllocate(); |
| 287 } | 282 } |
| 288 | 283 |
| 289 // Finally, do a device start and wait for it to finish. | 284 // Finally, do a device start and wait for it to finish. |
| 290 VideoCaptureParams capture_params; | 285 VideoCaptureParams capture_params; |
| 291 capture_params.requested_format.frame_size.SetSize(320, 240); | 286 capture_params.requested_format.frame_size.SetSize(320, 240); |
| 292 capture_params.requested_format.frame_rate = 30; | 287 capture_params.requested_format.frame_rate = 30; |
| 293 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 288 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 294 capture_params.allow_resolution_change = false; | 289 capture_params.allow_resolution_change = false; |
| 295 | 290 |
| 296 ResetWithNewClient(); | 291 ResetWithNewClient(); |
| 297 scoped_ptr<VideoCaptureDevice> device( | 292 scoped_ptr<VideoCaptureDevice> device( |
| 298 VideoCaptureDevice::Create(names_.front())); | 293 video_capture_device_factory_->Create(names_.front())); |
| 299 | 294 |
| 300 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 295 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 301 WaitForCapturedFrame(); | 296 WaitForCapturedFrame(); |
| 302 device->StopAndDeAllocate(); | 297 device->StopAndDeAllocate(); |
| 303 device.reset(); | 298 device.reset(); |
| 304 EXPECT_EQ(last_format().frame_size.width(), 320); | 299 EXPECT_EQ(last_format().frame_size.width(), 320); |
| 305 EXPECT_EQ(last_format().frame_size.height(), 240); | 300 EXPECT_EQ(last_format().frame_size.height(), 240); |
| 306 } | 301 } |
| 307 | 302 |
| 308 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 303 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
| 309 VideoCaptureDevice::GetDeviceNames(&names_); | 304 video_capture_device_factory_->GetDeviceNames(&names_); |
| 310 if (!names_.size()) { | 305 if (!names_.size()) { |
| 311 DVLOG(1) << "No camera available. Exiting test."; | 306 DVLOG(1) << "No camera available. Exiting test."; |
| 312 return; | 307 return; |
| 313 } | 308 } |
| 314 scoped_ptr<VideoCaptureDevice> device( | 309 scoped_ptr<VideoCaptureDevice> device( |
| 315 VideoCaptureDevice::Create(names_.front())); | 310 video_capture_device_factory_->Create(names_.front())); |
| 316 ASSERT_TRUE(device); | 311 ASSERT_TRUE(device); |
| 317 | 312 |
| 318 EXPECT_CALL(*client_, OnErr()) | 313 EXPECT_CALL(*client_, OnErr()) |
| 319 .Times(0); | 314 .Times(0); |
| 320 | 315 |
| 321 VideoCaptureParams capture_params; | 316 VideoCaptureParams capture_params; |
| 322 capture_params.requested_format.frame_size.SetSize(640, 480); | 317 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 323 capture_params.requested_format.frame_rate = 30; | 318 capture_params.requested_format.frame_rate = 30; |
| 324 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | 319 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; |
| 325 capture_params.allow_resolution_change = false; | 320 capture_params.allow_resolution_change = false; |
| 326 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 321 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 327 // Get captured video frames. | 322 // Get captured video frames. |
| 328 WaitForCapturedFrame(); | 323 WaitForCapturedFrame(); |
| 329 EXPECT_EQ(last_format().frame_size.width(), 640); | 324 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 330 EXPECT_EQ(last_format().frame_size.height(), 480); | 325 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 331 EXPECT_EQ(last_format().frame_rate, 30); | 326 EXPECT_EQ(last_format().frame_rate, 30); |
| 332 device->StopAndDeAllocate(); | 327 device->StopAndDeAllocate(); |
| 333 } | 328 } |
| 334 | 329 |
| 335 TEST_F(VideoCaptureDeviceTest, FakeCapture) { | |
| 336 VideoCaptureDevice::Names names; | |
| 337 | |
| 338 video_capture_device_factory_->GetDeviceNames(&names); | |
| 339 | |
| 340 ASSERT_GT(static_cast<int>(names.size()), 0); | |
| 341 | |
| 342 scoped_ptr<VideoCaptureDevice> device( | |
| 343 video_capture_device_factory_->Create(names.front())); | |
| 344 ASSERT_TRUE(device); | |
| 345 | |
| 346 EXPECT_CALL(*client_, OnErr()) | |
| 347 .Times(0); | |
| 348 | |
| 349 VideoCaptureParams capture_params; | |
| 350 capture_params.requested_format.frame_size.SetSize(640, 480); | |
| 351 capture_params.requested_format.frame_rate = 30; | |
| 352 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
| 353 capture_params.allow_resolution_change = false; | |
| 354 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
| 355 WaitForCapturedFrame(); | |
| 356 EXPECT_EQ(last_format().frame_size.width(), 640); | |
| 357 EXPECT_EQ(last_format().frame_size.height(), 480); | |
| 358 EXPECT_EQ(last_format().frame_rate, 30); | |
| 359 device->StopAndDeAllocate(); | |
| 360 } | |
| 361 | |
| 362 // Start the camera in 720p to capture MJPEG instead of a raw format. | 330 // Start the camera in 720p to capture MJPEG instead of a raw format. |
| 363 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { | 331 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { |
| 364 scoped_ptr<VideoCaptureDevice::Name> name = | 332 scoped_ptr<VideoCaptureDevice::Name> name = |
| 365 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); | 333 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); |
| 366 if (!name) { | 334 if (!name) { |
| 367 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; | 335 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; |
| 368 return; | 336 return; |
| 369 } | 337 } |
| 370 scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name)); | 338 scoped_ptr<VideoCaptureDevice> device( |
| 339 video_capture_device_factory_->Create(*name)); |
| 371 ASSERT_TRUE(device); | 340 ASSERT_TRUE(device); |
| 372 | 341 |
| 373 EXPECT_CALL(*client_, OnErr()) | 342 EXPECT_CALL(*client_, OnErr()) |
| 374 .Times(0); | 343 .Times(0); |
| 375 | 344 |
| 376 VideoCaptureParams capture_params; | 345 VideoCaptureParams capture_params; |
| 377 capture_params.requested_format.frame_size.SetSize(1280, 720); | 346 capture_params.requested_format.frame_size.SetSize(1280, 720); |
| 378 capture_params.requested_format.frame_rate = 30; | 347 capture_params.requested_format.frame_rate = 30; |
| 379 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; | 348 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; |
| 380 capture_params.allow_resolution_change = false; | 349 capture_params.allow_resolution_change = false; |
| 381 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | 350 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); |
| 382 // Get captured video frames. | 351 // Get captured video frames. |
| 383 WaitForCapturedFrame(); | 352 WaitForCapturedFrame(); |
| 384 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 | 353 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 |
| 385 // @ 30 fps, so we don't care about the exact resolution we get. | 354 // @ 30 fps, so we don't care about the exact resolution we get. |
| 386 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); | 355 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); |
| 387 device->StopAndDeAllocate(); | 356 device->StopAndDeAllocate(); |
| 388 } | 357 } |
| 389 | 358 |
| 390 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 359 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 391 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 360 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
| 392 // GetDeviceSupportedFormats(). | 361 // GetDeviceSupportedFormats(). |
| 393 scoped_ptr<VideoCaptureDevice::Name> name = | 362 scoped_ptr<VideoCaptureDevice::Name> name = |
| 394 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 363 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
| 395 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 364 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
| 396 // since we cannot forecast the hardware capabilities. | 365 // since we cannot forecast the hardware capabilities. |
| 397 ASSERT_FALSE(name); | 366 ASSERT_FALSE(name); |
| 398 } | 367 } |
| 399 | 368 |
| 400 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { | |
| 401 VideoCaptureDevice::Names names; | |
| 402 | |
| 403 video_capture_device_factory_->GetDeviceNames(&names); | |
| 404 VideoCaptureParams capture_params; | |
| 405 capture_params.requested_format.frame_size.SetSize(640, 480); | |
| 406 capture_params.requested_format.frame_rate = 30; | |
| 407 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; | |
| 408 capture_params.allow_resolution_change = true; | |
| 409 | |
| 410 ASSERT_GT(static_cast<int>(names.size()), 0); | |
| 411 | |
| 412 scoped_ptr<VideoCaptureDevice> device( | |
| 413 video_capture_device_factory_->Create(names.front())); | |
| 414 ASSERT_TRUE(device); | |
| 415 | |
| 416 // Configure the FakeVideoCaptureDevice to use all its formats as roster. | |
| 417 VideoCaptureFormats formats; | |
| 418 video_capture_device_factory_->GetDeviceSupportedFormats(names.front(), | |
| 419 &formats); | |
| 420 static_cast<FakeVideoCaptureDevice*>(device.get())-> | |
| 421 PopulateVariableFormatsRoster(formats); | |
| 422 | |
| 423 EXPECT_CALL(*client_, OnErr()) | |
| 424 .Times(0); | |
| 425 int action_count = 200; | |
| 426 | |
| 427 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); | |
| 428 | |
| 429 // We set TimeWait to 200 action timeouts and this should be enough for at | |
| 430 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | |
| 431 for (int i = 0; i < action_count; ++i) { | |
| 432 WaitForCapturedFrame(); | |
| 433 } | |
| 434 device->StopAndDeAllocate(); | |
| 435 } | |
| 436 | |
| 437 TEST_F(VideoCaptureDeviceTest, FakeGetDeviceSupportedFormats) { | |
| 438 VideoCaptureDevice::Names names; | |
| 439 video_capture_device_factory_->GetDeviceNames(&names); | |
| 440 | |
| 441 VideoCaptureFormats supported_formats; | |
| 442 VideoCaptureDevice::Names::iterator names_iterator; | |
| 443 | |
| 444 for (names_iterator = names.begin(); names_iterator != names.end(); | |
| 445 ++names_iterator) { | |
| 446 video_capture_device_factory_->GetDeviceSupportedFormats( | |
| 447 *names_iterator, &supported_formats); | |
| 448 EXPECT_EQ(supported_formats.size(), 3u); | |
| 449 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); | |
| 450 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); | |
| 451 EXPECT_EQ(supported_formats[0].pixel_format, media::PIXEL_FORMAT_I420); | |
| 452 EXPECT_GE(supported_formats[0].frame_rate, 20); | |
| 453 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); | |
| 454 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); | |
| 455 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); | |
| 456 EXPECT_GE(supported_formats[1].frame_rate, 20); | |
| 457 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); | |
| 458 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); | |
| 459 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); | |
| 460 EXPECT_GE(supported_formats[2].frame_rate, 20); | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 }; // namespace media | 369 }; // namespace media |
| OLD | NEW |