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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 using ::testing::SaveArg; | 61 using ::testing::SaveArg; |
62 | 62 |
63 namespace media { | 63 namespace media { |
64 | 64 |
65 class MockFrameObserver : public media::VideoCaptureDevice::EventHandler { | 65 class MockFrameObserver : public media::VideoCaptureDevice::EventHandler { |
66 public: | 66 public: |
67 MOCK_METHOD0(ReserveOutputBuffer, scoped_refptr<media::VideoFrame>()); | 67 MOCK_METHOD0(ReserveOutputBuffer, scoped_refptr<media::VideoFrame>()); |
68 MOCK_METHOD0(OnErr, void()); | 68 MOCK_METHOD0(OnErr, void()); |
69 MOCK_METHOD1(OnFrameInfo, void(const VideoCaptureCapability&)); | 69 MOCK_METHOD1(OnFrameInfo, void(const VideoCaptureCapability&)); |
70 MOCK_METHOD1(OnFrameInfoChanged, void(const VideoCaptureCapability&)); | 70 MOCK_METHOD1(OnFrameInfoChanged, void(const VideoCaptureCapability&)); |
| 71 MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated, |
| 72 void(const VideoCaptureFormats& formats)); |
71 | 73 |
72 explicit MockFrameObserver( | 74 explicit MockFrameObserver( |
73 base::Closure frame_cb) | 75 base::Closure frame_cb) |
74 : main_thread_(base::MessageLoopProxy::current()), | 76 : main_thread_(base::MessageLoopProxy::current()), |
75 frame_cb_(frame_cb) {} | 77 frame_cb_(frame_cb) {} |
76 | 78 |
77 virtual void OnError() OVERRIDE { | 79 virtual void OnError() OVERRIDE { |
78 OnErr(); | 80 OnErr(); |
79 } | 81 } |
80 | 82 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 116 |
115 void WaitForCapturedFrame() { | 117 void WaitForCapturedFrame() { |
116 loop_->Run(); | 118 loop_->Run(); |
117 } | 119 } |
118 | 120 |
119 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
120 base::win::ScopedCOMInitializer initialize_com_; | 122 base::win::ScopedCOMInitializer initialize_com_; |
121 #endif | 123 #endif |
122 scoped_ptr<MockFrameObserver> frame_observer_; | 124 scoped_ptr<MockFrameObserver> frame_observer_; |
123 VideoCaptureDevice::Names names_; | 125 VideoCaptureDevice::Names names_; |
| 126 VideoCaptureFormats capture_formats_; |
124 scoped_ptr<base::MessageLoop> loop_; | 127 scoped_ptr<base::MessageLoop> loop_; |
125 }; | 128 }; |
126 | 129 |
127 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 130 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
128 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
129 VideoCaptureDevice::Name::CaptureApiType api_type = | 132 VideoCaptureDevice::Name::CaptureApiType api_type = |
130 VideoCaptureDeviceMFWin::PlatformSupported() | 133 VideoCaptureDeviceMFWin::PlatformSupported() |
131 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION | 134 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION |
132 : VideoCaptureDevice::Name::DIRECT_SHOW; | 135 : VideoCaptureDevice::Name::DIRECT_SHOW; |
133 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); | 136 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 resolution.height(), | 266 resolution.height(), |
264 30, | 267 30, |
265 PIXEL_FORMAT_I420, | 268 PIXEL_FORMAT_I420, |
266 0, | 269 0, |
267 false, | 270 false, |
268 ConstantResolutionVideoCaptureDevice); | 271 ConstantResolutionVideoCaptureDevice); |
269 | 272 |
270 // The device (if it is an async implementation) may or may not get as far | 273 // The device (if it is an async implementation) may or may not get as far |
271 // as the OnFrameInfo() step; we're intentionally not going to wait for it | 274 // as the OnFrameInfo() step; we're intentionally not going to wait for it |
272 // to get that far. | 275 // to get that far. |
273 ON_CALL(*frame_observer, OnFrameInfo(_)); | 276 EXPECT_CALL(*frame_observer, OnFrameInfo(_)).Times(AnyNumber()); |
274 device->AllocateAndStart(requested_format, | 277 device->AllocateAndStart(requested_format, |
275 frame_observer.PassAs<EventHandler>()); | 278 frame_observer.PassAs<EventHandler>()); |
276 device->StopAndDeAllocate(); | 279 device->StopAndDeAllocate(); |
277 } | 280 } |
278 | 281 |
279 // Finally, do a device start and wait for it to finish. | 282 // Finally, do a device start and wait for it to finish. |
280 gfx::Size resolution; | 283 gfx::Size resolution; |
281 VideoCaptureCapability requested_format( | 284 VideoCaptureCapability requested_format( |
282 320, | 285 320, |
283 240, | 286 240, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 // The amount of times the OnFrameInfoChanged gets called depends on how often | 446 // The amount of times the OnFrameInfoChanged gets called depends on how often |
444 // FakeDevice is supposed to change and what is its actual frame rate. | 447 // FakeDevice is supposed to change and what is its actual frame rate. |
445 // We set TimeWait to 200 action timeouts and this should be enough for at | 448 // We set TimeWait to 200 action timeouts and this should be enough for at |
446 // least action_count/kFakeCaptureCapabilityChangePeriod calls. | 449 // least action_count/kFakeCaptureCapabilityChangePeriod calls. |
447 for (int i = 0; i < action_count; ++i) { | 450 for (int i = 0; i < action_count; ++i) { |
448 WaitForCapturedFrame(); | 451 WaitForCapturedFrame(); |
449 } | 452 } |
450 device->StopAndDeAllocate(); | 453 device->StopAndDeAllocate(); |
451 } | 454 } |
452 | 455 |
| 456 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 457 VideoCaptureDevice::Names names; |
| 458 |
| 459 FakeVideoCaptureDevice::GetDeviceNames(&names); |
| 460 scoped_ptr<VideoCaptureDevice> device( |
| 461 FakeVideoCaptureDevice::Create(names.front())); |
| 462 ASSERT_TRUE(device.get() != NULL); |
| 463 EXPECT_CALL(*frame_observer_, OnDeviceSupportedFormatsEnumerated(_)) |
| 464 .Times(1) |
| 465 .WillOnce(SaveArg<0>(&capture_formats_)); |
| 466 device->GetDeviceSupportedFormats(frame_observer_.PassAs<EventHandler>()); |
| 467 |
| 468 EXPECT_GE(capture_formats_.size(), 1u); |
| 469 EXPECT_EQ(capture_formats_[0].width, 640); |
| 470 EXPECT_EQ(capture_formats_[0].height, 480); |
| 471 EXPECT_EQ(capture_formats_[0].color, media::PIXEL_FORMAT_I420); |
| 472 EXPECT_GE(capture_formats_[0].frame_rate, 20); |
| 473 } |
| 474 |
453 }; // namespace media | 475 }; // namespace media |
OLD | NEW |