Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: media/video/capture/video_capture_device_unittest.cc

Issue 7229013: This is the VideoCaptureDevice implementation for windows. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/thread.h"
8 #include "media/video/capture/fake_video_capture_device.h"
9 #include "media/video/capture/video_capture_device.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using ::testing::_;
14 using ::testing::AnyNumber;
15 using ::testing::Return;
16 using ::testing::AtLeast;
17
18 namespace media {
19 const int kWaitTime = 3000;
20
21 class MockFrameObserver: public media::VideoCaptureDevice::EventHandler {
22 public:
23 MOCK_METHOD0(OnErr, void());
24 MOCK_METHOD3(OnFrameInfo, void(int width, int height, int frame_rate));
25
26 explicit MockFrameObserver(base::WaitableEvent* wait_event)
27 : wait_event_(wait_event) {}
28
29 virtual void OnError() OVERRIDE {
30 OnErr();
31 }
32
33 virtual void OnFrameInfo(
34 const VideoCaptureDevice::Capability& info) OVERRIDE {
35 OnFrameInfo(info.width, info.height, info.frame_rate);
36 }
37 virtual void OnIncomingCapturedFrame(const uint8* data, int length,
38 base::Time timestamp) OVERRIDE {
39 wait_event_->Signal();
40 }
41
42 private:
43 base::WaitableEvent* wait_event_;
44 };
45
46 class VideoCaptureDeviceTest : public testing::Test {
47 public:
48 VideoCaptureDeviceTest(): wait_event_(false, false) { }
49
50 protected:
51 virtual void SetUp() {
52 frame_observer_.reset(new MockFrameObserver(&wait_event_));
53 }
54
55 virtual void TearDown() {
56 }
57
58 base::WaitableEvent wait_event_;
59 scoped_ptr<MockFrameObserver> frame_observer_;
60 VideoCaptureDevice::Names names_;
61 };
62
63 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) {
64 VideoCaptureDevice::Name device_name;
65 device_name.device_name = "jibberish";
66 device_name.unique_id = "jibberish";
67 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name);
68 EXPECT_TRUE(device == NULL);
69 }
70
71 TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
72 VideoCaptureDevice::GetDeviceNames(&names_);
73 // Make sure there are more than 0 cameras.
74 if (!names_.size()) {
tommi (sloooow) - chröme 2011/06/27 13:20:37 use if (names_.empty())
75 LOG(WARNING) << "No camera available. Exiting test.";
76 return;
77 }
78
79 scoped_ptr<VideoCaptureDevice> device(
80 VideoCaptureDevice::Create(names_.front()));
81 ASSERT_FALSE(device.get() == NULL);
82
83 // Get info about the new resolution.
84 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30))
85 .Times(1);
86
87 EXPECT_CALL(*frame_observer_, OnErr())
88 .Times(0);
89
90 device->Allocate(640, 480, 30, frame_observer_.get());
91 device->Start();
92 // Wait for 3s or for captured frame.
93 EXPECT_TRUE(wait_event_.TimedWait(
94 base::TimeDelta::FromMilliseconds(kWaitTime)));
95 device->Stop();
96 device->DeAllocate();
97 }
98
99 TEST_F(VideoCaptureDeviceTest, Capture720p) {
100 VideoCaptureDevice::GetDeviceNames(&names_);
101 // Make sure there are more than 0 cameras.
102 if (!names_.size()) {
103 LOG(WARNING) << "No camera available. Exiting test.";
104 return;
105 }
106
107 scoped_ptr<VideoCaptureDevice> device(
108 VideoCaptureDevice::Create(names_.front()));
109 ASSERT_FALSE(device.get() == NULL);
110
111 // Get info about the new resolution.
112 // We don't care about the resulting resolution or frame rate as it might
113 // be different from one machine to the next.
114 EXPECT_CALL(*frame_observer_, OnFrameInfo(_, _, _))
115 .Times(1);
116
117 EXPECT_CALL(*frame_observer_, OnErr())
118 .Times(0);
119
120 device->Allocate(1280, 720, 30, frame_observer_.get());
121 device->Start();
122 // Get captured video frames.
123 EXPECT_TRUE(wait_event_.TimedWait(
124 base::TimeDelta::FromMilliseconds(kWaitTime)));
125 device->Stop();
126 device->DeAllocate();
127 }
128
129 TEST_F(VideoCaptureDeviceTest, AllocateSameCameraTwice) {
130 VideoCaptureDevice::GetDeviceNames(&names_);
131 if (!names_.size()) {
132 LOG(WARNING) << "No camera available. Exiting test.";
133 return;
134 }
135 scoped_ptr<VideoCaptureDevice> device1(
136 VideoCaptureDevice::Create(names_.front()));
137 ASSERT_TRUE(device1.get() != NULL);
138
139 scoped_ptr<VideoCaptureDevice> device2(
140 VideoCaptureDevice::Create(names_.front()));
141 ASSERT_TRUE(device2.get() != NULL);
142
143 // 1. Get info about the new resolution on the first allocated camera
144 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30));
145
146 device1->Allocate(640, 480, 30, frame_observer_.get());
147
148 // 2. Error when trying to allocate the same camera again.
149 EXPECT_CALL(*frame_observer_, OnErr());
150 device2->Allocate(640, 480, 30, frame_observer_.get());
151
152 device1->DeAllocate();
153 device2->DeAllocate();
154 }
155
156 TEST_F(VideoCaptureDeviceTest, AllocateBadSize) {
157 VideoCaptureDevice::GetDeviceNames(&names_);
158 if (!names_.size()) {
159 LOG(WARNING) << "No camera available. Exiting test.";
160 return;
161 }
162 scoped_ptr<VideoCaptureDevice> device(
163 VideoCaptureDevice::Create(names_.front()));
164 ASSERT_TRUE(device.get() != NULL);
165
166 EXPECT_CALL(*frame_observer_, OnErr())
167 .Times(0);
168
169 // get info about the new resolution
170 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480 , _))
171 .Times(AtLeast(1));
172
173 device->Allocate(637, 472, 35, frame_observer_.get());
174 device->DeAllocate();
175 }
176
177 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
178 VideoCaptureDevice::GetDeviceNames(&names_);
179 if (!names_.size()) {
180 LOG(WARNING) << "No camera available. Exiting test.";
181 return;
182 }
183 scoped_ptr<VideoCaptureDevice> device(
184 VideoCaptureDevice::Create(names_.front()));
185 ASSERT_TRUE(device.get() != NULL);
186 EXPECT_CALL(*frame_observer_, OnErr())
187 .Times(0);
188 // get info about the new resolution
189 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, _));
190
191 EXPECT_CALL(*frame_observer_, OnFrameInfo(320, 240, _));
192
193 device->Allocate(640, 480, 30, frame_observer_.get());
194 device->Start();
195 // Nothing shall happen.
196 device->Allocate(1280, 1024, 30, frame_observer_.get());
197 device->DeAllocate();
198 // Allocate new size 320, 240
199 device->Allocate(320, 240, 30, frame_observer_.get());
200
201 device->Start();
202 // Get captured video frames.
203 EXPECT_TRUE(wait_event_.TimedWait(
204 base::TimeDelta::FromMilliseconds(kWaitTime)));
205 device->Stop();
206 device->DeAllocate();
207 }
208
209 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
210 VideoCaptureDevice::GetDeviceNames(&names_);
211 if (!names_.size()) {
212 LOG(WARNING) << "No camera available. Exiting test.";
213 return;
214 }
215 scoped_ptr<VideoCaptureDevice> device(
216 VideoCaptureDevice::Create(names_.front()));
217 ASSERT_TRUE(device.get() != NULL);
218
219 // 1. Get info about the new resolution.
220 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30));
221
222 device->Allocate(640, 480, 30, frame_observer_.get());
223
224 device->Start();
225 // Get captured video frames.
226 EXPECT_TRUE(wait_event_.TimedWait(
227 base::TimeDelta::FromMilliseconds(kWaitTime)));
228 device->DeAllocate();
229 }
230
231 TEST_F(VideoCaptureDeviceTest, TestFakeCapture) {
232 VideoCaptureDevice::Names names;
233
234 FakeVideoCaptureDevice::GetDeviceNames(&names);
235
236 ASSERT_GT(static_cast<int>(names.size()), 0);
237
238 scoped_ptr<VideoCaptureDevice> device(
239 FakeVideoCaptureDevice::Create(names.front()));
240 ASSERT_TRUE(device.get() != NULL);
241
242 // Get info about the new resolution.
243 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30))
244 .Times(1);
245
246 EXPECT_CALL(*frame_observer_, OnErr())
247 .Times(0);
248
249 device->Allocate(640, 480, 30, frame_observer_.get());
250
251 device->Start();
252 EXPECT_TRUE(wait_event_.TimedWait(
253 base::TimeDelta::FromMilliseconds(kWaitTime)));
254 device->Stop();
255 device->DeAllocate();
256 }
257
258 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698