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" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" |
11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "media/base/video_capture_types.h" | 14 #include "media/base/video_capture_types.h" |
14 #include "media/video/capture/video_capture_device.h" | 15 #include "media/video/capture/video_capture_device.h" |
15 #include "media/video/capture/video_capture_device_factory.h" | 16 #include "media/video/capture/video_capture_device_factory.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include "base/win/scoped_com_initializer.h" | 21 #include "base/win/scoped_com_initializer.h" |
21 #include "media/video/capture/win/video_capture_device_factory_win.h" | 22 #include "media/video/capture/win/video_capture_device_factory_win.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 size_t v_stride, | 74 size_t v_stride, |
74 const VideoCaptureFormat& frame_format, | 75 const VideoCaptureFormat& frame_format, |
75 int clockwise_rotation, | 76 int clockwise_rotation, |
76 const base::TimeTicks& timestamp)); | 77 const base::TimeTicks& timestamp)); |
77 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 78 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
78 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 79 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
79 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 80 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
80 MOCK_METHOD1(OnError, void(const std::string& reason)); | 81 MOCK_METHOD1(OnError, void(const std::string& reason)); |
81 | 82 |
82 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) | 83 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) |
83 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} | 84 : main_thread_(base::ThreadTaskRunnerHandle::Get()), |
| 85 frame_cb_(frame_cb) {} |
84 | 86 |
85 void OnIncomingCapturedData(const uint8* data, | 87 void OnIncomingCapturedData(const uint8* data, |
86 int length, | 88 int length, |
87 const VideoCaptureFormat& format, | 89 const VideoCaptureFormat& format, |
88 int rotation, | 90 int rotation, |
89 const base::TimeTicks& timestamp) override { | 91 const base::TimeTicks& timestamp) override { |
90 ASSERT_GT(length, 0); | 92 ASSERT_GT(length, 0); |
91 ASSERT_TRUE(data != NULL); | 93 ASSERT_TRUE(data != NULL); |
92 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); | 94 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, format)); |
93 } | 95 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 class VideoCaptureDeviceTest : public testing::Test { | 136 class VideoCaptureDeviceTest : public testing::Test { |
135 protected: | 137 protected: |
136 typedef VideoCaptureDevice::Client Client; | 138 typedef VideoCaptureDevice::Client Client; |
137 | 139 |
138 VideoCaptureDeviceTest() | 140 VideoCaptureDeviceTest() |
139 : loop_(new base::MessageLoop()), | 141 : loop_(new base::MessageLoop()), |
140 client_( | 142 client_( |
141 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, | 143 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
142 base::Unretained(this)))), | 144 base::Unretained(this)))), |
143 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( | 145 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( |
144 base::MessageLoopProxy::current())) { | 146 base::ThreadTaskRunnerHandle::Get())) { |
145 device_enumeration_listener_ = new DeviceEnumerationListener(); | 147 device_enumeration_listener_ = new DeviceEnumerationListener(); |
146 } | 148 } |
147 | 149 |
148 void SetUp() override { | 150 void SetUp() override { |
149 #if defined(OS_ANDROID) | 151 #if defined(OS_ANDROID) |
150 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 152 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
151 base::android::AttachCurrentThread()); | 153 base::android::AttachCurrentThread()); |
152 #endif | 154 #endif |
153 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) | 155 EXPECT_CALL(*client_, OnIncomingCapturedYuvData(_,_,_,_,_,_,_,_,_)) |
154 .Times(0); | 156 .Times(0); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // Use PIXEL_FORMAT_MAX to iterate all device names for testing | 457 // Use PIXEL_FORMAT_MAX to iterate all device names for testing |
456 // GetDeviceSupportedFormats(). | 458 // GetDeviceSupportedFormats(). |
457 scoped_ptr<VideoCaptureDevice::Name> name = | 459 scoped_ptr<VideoCaptureDevice::Name> name = |
458 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); | 460 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); |
459 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here | 461 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here |
460 // since we cannot forecast the hardware capabilities. | 462 // since we cannot forecast the hardware capabilities. |
461 ASSERT_FALSE(name); | 463 ASSERT_FALSE(name); |
462 } | 464 } |
463 | 465 |
464 }; // namespace media | 466 }; // namespace media |
OLD | NEW |