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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 using ::testing::SaveArg; |
62 | 62 |
63 namespace media { | 63 namespace media { |
64 | 64 |
65 class MockClient : public media::VideoCaptureDevice::Client { | 65 class MockClient : public media::VideoCaptureDevice::Client { |
66 public: | 66 public: |
67 MOCK_METHOD1(ReserveOutputBuffer, | 67 MOCK_METHOD2(ReserveOutputBuffer, |
68 scoped_refptr<media::VideoFrame>(const gfx::Size&)); | 68 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
| 69 const gfx::Size& dimensions)); |
69 MOCK_METHOD0(OnErr, void()); | 70 MOCK_METHOD0(OnErr, void()); |
70 | 71 |
71 explicit MockClient( | 72 explicit MockClient( |
72 base::Callback<void(const VideoCaptureCapability&)> frame_cb) | 73 base::Callback<void(const VideoCaptureCapability&)> frame_cb) |
73 : main_thread_(base::MessageLoopProxy::current()), | 74 : main_thread_(base::MessageLoopProxy::current()), frame_cb_(frame_cb) {} |
74 frame_cb_(frame_cb) {} | |
75 | 75 |
76 virtual void OnError() OVERRIDE { | 76 virtual void OnError() OVERRIDE { |
77 OnErr(); | 77 OnErr(); |
78 } | 78 } |
79 | 79 |
80 virtual void OnIncomingCapturedFrame( | 80 virtual void OnIncomingCapturedFrame(const uint8* data, |
81 const uint8* data, | 81 int length, |
82 int length, | 82 base::Time timestamp, |
83 base::Time timestamp, | 83 int rotation, |
84 int rotation, | 84 bool flip_vert, |
85 bool flip_vert, | 85 bool flip_horiz, |
86 bool flip_horiz, | 86 const VideoCaptureCapability& frame_info) |
87 const VideoCaptureCapability& frame_info) OVERRIDE { | 87 OVERRIDE { |
88 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, frame_info)); | 88 main_thread_->PostTask(FROM_HERE, base::Bind(frame_cb_, frame_info)); |
89 } | 89 } |
90 | 90 |
91 virtual void OnIncomingCapturedVideoFrame( | 91 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, |
92 const scoped_refptr<media::VideoFrame>& frame, | 92 media::VideoFrame::Format format, |
93 base::Time timestamp, | 93 const gfx::Size& dimensions, |
94 int frame_rate) OVERRIDE { | 94 base::Time timestamp, |
| 95 int frame_rate) OVERRIDE { |
95 NOTREACHED(); | 96 NOTREACHED(); |
96 } | 97 } |
97 | 98 |
98 private: | 99 private: |
99 scoped_refptr<base::MessageLoopProxy> main_thread_; | 100 scoped_refptr<base::MessageLoopProxy> main_thread_; |
100 base::Callback<void(const VideoCaptureCapability&)> frame_cb_; | 101 base::Callback<void(const VideoCaptureCapability&)> frame_cb_; |
101 }; | 102 }; |
102 | 103 |
103 class VideoCaptureDeviceTest : public testing::Test { | 104 class VideoCaptureDeviceTest : public testing::Test { |
104 protected: | 105 protected: |
105 typedef media::VideoCaptureDevice::Client Client; | 106 typedef media::VideoCaptureDevice::Client Client; |
106 | 107 |
107 VideoCaptureDeviceTest() | 108 VideoCaptureDeviceTest() |
108 : loop_(new base::MessageLoop()), | 109 : loop_(new base::MessageLoop()), |
109 client_(new MockClient(base::Bind( | 110 client_( |
110 &VideoCaptureDeviceTest::OnFrameCaptured, | 111 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, |
111 base::Unretained(this)))) {} | 112 base::Unretained(this)))) {} |
112 | 113 |
113 virtual void SetUp() { | 114 virtual void SetUp() { |
114 #if defined(OS_ANDROID) | 115 #if defined(OS_ANDROID) |
115 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( | 116 media::VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( |
116 base::android::AttachCurrentThread()); | 117 base::android::AttachCurrentThread()); |
117 #endif | 118 #endif |
118 } | 119 } |
119 | 120 |
120 void ResetWithNewClient() { | 121 void ResetWithNewClient() { |
121 client_.reset(new MockClient(base::Bind( | 122 client_.reset(new MockClient(base::Bind( |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } else { | 260 } else { |
260 resolution = gfx::Size(1280, 1024); | 261 resolution = gfx::Size(1280, 1024); |
261 } | 262 } |
262 VideoCaptureCapability requested_format( | 263 VideoCaptureCapability requested_format( |
263 resolution.width(), | 264 resolution.width(), |
264 resolution.height(), | 265 resolution.height(), |
265 30, | 266 30, |
266 PIXEL_FORMAT_I420, | 267 PIXEL_FORMAT_I420, |
267 ConstantResolutionVideoCaptureDevice); | 268 ConstantResolutionVideoCaptureDevice); |
268 | 269 |
269 device->AllocateAndStart(requested_format, | 270 device->AllocateAndStart(requested_format, client_.PassAs<Client>()); |
270 client_.PassAs<Client>()); | |
271 device->StopAndDeAllocate(); | 271 device->StopAndDeAllocate(); |
272 } | 272 } |
273 | 273 |
274 // Finally, do a device start and wait for it to finish. | 274 // Finally, do a device start and wait for it to finish. |
275 gfx::Size resolution; | 275 gfx::Size resolution; |
276 VideoCaptureCapability requested_format( | 276 VideoCaptureCapability requested_format( |
277 320, | 277 320, |
278 240, | 278 240, |
279 30, | 279 30, |
280 PIXEL_FORMAT_I420, | 280 PIXEL_FORMAT_I420, |
281 ConstantResolutionVideoCaptureDevice); | 281 ConstantResolutionVideoCaptureDevice); |
282 | 282 |
283 ResetWithNewClient(); | 283 ResetWithNewClient(); |
284 scoped_ptr<VideoCaptureDevice> device( | 284 scoped_ptr<VideoCaptureDevice> device( |
285 VideoCaptureDevice::Create(names_.front())); | 285 VideoCaptureDevice::Create(names_.front())); |
286 | 286 |
287 device->AllocateAndStart(requested_format, | 287 device->AllocateAndStart(requested_format, client_.PassAs<Client>()); |
288 client_.PassAs<Client>()); | |
289 WaitForCapturedFrame(); | 288 WaitForCapturedFrame(); |
290 device->StopAndDeAllocate(); | 289 device->StopAndDeAllocate(); |
291 device.reset(); | 290 device.reset(); |
292 EXPECT_EQ(last_frame_info().width, 320); | 291 EXPECT_EQ(last_frame_info().width, 320); |
293 EXPECT_EQ(last_frame_info().height, 240); | 292 EXPECT_EQ(last_frame_info().height, 240); |
294 } | 293 } |
295 | 294 |
296 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { | 295 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { |
297 VideoCaptureDevice::GetDeviceNames(&names_); | 296 VideoCaptureDevice::GetDeviceNames(&names_); |
298 if (!names_.size()) { | 297 if (!names_.size()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 &capture_formats); | 434 &capture_formats); |
436 EXPECT_GE(capture_formats.size(), 1u); | 435 EXPECT_GE(capture_formats.size(), 1u); |
437 EXPECT_EQ(capture_formats[0].width, 640); | 436 EXPECT_EQ(capture_formats[0].width, 640); |
438 EXPECT_EQ(capture_formats[0].height, 480); | 437 EXPECT_EQ(capture_formats[0].height, 480); |
439 EXPECT_EQ(capture_formats[0].color, media::PIXEL_FORMAT_I420); | 438 EXPECT_EQ(capture_formats[0].color, media::PIXEL_FORMAT_I420); |
440 EXPECT_GE(capture_formats[0].frame_rate, 20); | 439 EXPECT_GE(capture_formats[0].frame_rate, 20); |
441 } | 440 } |
442 } | 441 } |
443 | 442 |
444 }; // namespace media | 443 }; // namespace media |
OLD | NEW |