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