OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/media/capture_video_decoder.h" | 6 #include "content/renderer/media/capture_video_decoder.h" |
7 #include "content/renderer/media/video_capture_impl.h" | 7 #include "content/renderer/media/video_capture_impl.h" |
8 #include "content/renderer/media/video_capture_impl_manager.h" | 8 #include "content/renderer/media/video_capture_impl_manager.h" |
9 #include "media/base/filters.h" | 9 #include "media/base/filters.h" |
10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
11 #include "media/base/mock_callback.h" | 11 #include "media/base/mock_callback.h" |
12 #include "media/base/mock_filter_host.h" | 12 #include "media/base/mock_filter_host.h" |
13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
14 #include "media/base/pipeline_status.h" | 14 #include "media/base/pipeline_status.h" |
15 #include "media/video/capture/video_capture_types.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using ::testing::_; | 18 using ::testing::_; |
18 using ::testing::AnyNumber; | 19 using ::testing::AnyNumber; |
19 using ::testing::Return; | 20 using ::testing::Return; |
20 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
21 | 22 |
23 static const int kWidth = 176; | |
24 static const int kHeight = 144; | |
25 static const int kFPS = 30; | |
22 static const media::VideoCaptureSessionId kVideoStreamId = 1; | 26 static const media::VideoCaptureSessionId kVideoStreamId = 1; |
23 | 27 |
24 ACTION_P3(CreateDataBufferFromCapture, decoder, vc_impl, data_buffer_number) { | 28 ACTION_P3(CreateDataBufferFromCapture, decoder, vc_impl, data_buffer_number) { |
25 for (int i = 0; i < data_buffer_number; i++) { | 29 for (int i = 0; i < data_buffer_number; i++) { |
26 media::VideoCapture::VideoFrameBuffer* buffer; | 30 media::VideoCapture::VideoFrameBuffer* buffer; |
27 buffer = new media::VideoCapture::VideoFrameBuffer(); | 31 buffer = new media::VideoCapture::VideoFrameBuffer(); |
28 buffer->width = arg1.width; | 32 buffer->width = arg1.width; |
29 buffer->height = arg1.height; | 33 buffer->height = arg1.height; |
30 int length = buffer->width * buffer->height * 3 / 2; | 34 int length = buffer->width * buffer->height * 3 / 2; |
31 buffer->memory_pointer = new uint8[length]; | 35 buffer->memory_pointer = new uint8[length]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 }; | 82 }; |
79 | 83 |
80 class CaptureVideoDecoderTest : public ::testing::Test { | 84 class CaptureVideoDecoderTest : public ::testing::Test { |
81 protected: | 85 protected: |
82 CaptureVideoDecoderTest() { | 86 CaptureVideoDecoderTest() { |
83 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 87 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
84 message_loop_proxy_ = | 88 message_loop_proxy_ = |
85 base::MessageLoopProxy::current().get(); | 89 base::MessageLoopProxy::current().get(); |
86 vc_manager_ = new MockVideoCaptureImplManager(); | 90 vc_manager_ = new MockVideoCaptureImplManager(); |
87 media::VideoCapture::VideoCaptureCapability capability; | 91 media::VideoCapture::VideoCaptureCapability capability; |
88 capability.width = 176; | 92 capability.width = kWidth; |
89 capability.height = 144; | 93 capability.height = kHeight; |
90 capability.max_fps = 30; | 94 capability.max_fps = kFPS; |
91 capability.expected_capture_delay = 0; | 95 capability.expected_capture_delay = 0; |
92 capability.raw_type = media::VideoFrame::I420; | 96 capability.raw_type = media::VideoFrame::I420; |
93 capability.interlaced = false; | 97 capability.interlaced = false; |
94 | 98 |
95 decoder_ = new CaptureVideoDecoder(message_loop_proxy_, | 99 decoder_ = new CaptureVideoDecoder(message_loop_proxy_, |
96 kVideoStreamId, vc_manager_, capability); | 100 kVideoStreamId, vc_manager_, capability); |
97 decoder_->set_host(&host_); | 101 decoder_->set_host(&host_); |
98 EXPECT_CALL(statistics_callback_object_, OnStatistics(_)) | 102 EXPECT_CALL(statistics_callback_object_, OnStatistics(_)) |
99 .Times(AnyNumber()); | 103 .Times(AnyNumber()); |
100 | 104 |
101 read_cb_ = base::Bind(&CaptureVideoDecoderTest::FrameReady, | 105 read_cb_ = base::Bind(&CaptureVideoDecoderTest::FrameReady, |
102 base::Unretained(this)); | 106 base::Unretained(this)); |
107 | |
108 vc_impl_.reset(new MockVideoCaptureImpl( | |
109 kVideoStreamId, message_loop_proxy_, new VideoCaptureMessageFilter())); | |
103 } | 110 } |
104 | 111 |
105 virtual ~CaptureVideoDecoderTest() { | 112 virtual ~CaptureVideoDecoderTest() { |
106 message_loop_->RunAllPending(); | 113 message_loop_->RunAllPending(); |
107 } | 114 } |
108 | 115 |
109 media::StatisticsCallback NewStatisticsCallback() { | 116 media::StatisticsCallback NewStatisticsCallback() { |
110 return base::Bind(&media::MockStatisticsCallback::OnStatistics, | 117 return base::Bind(&media::MockStatisticsCallback::OnStatistics, |
111 base::Unretained(&statistics_callback_object_)); | 118 base::Unretained(&statistics_callback_object_)); |
112 } | 119 } |
113 | 120 |
121 void Initialize() { | |
122 EXPECT_CALL(*vc_manager_, AddDevice(_, _)) | |
123 .WillOnce(Return(vc_impl_.get())); | |
124 decoder_->Initialize(NULL, | |
125 media::NewExpectedClosure(), | |
126 NewStatisticsCallback()); | |
127 message_loop_->RunAllPending(); | |
128 } | |
129 | |
130 void Seek(int buffer_count) { | |
131 EXPECT_CALL(*vc_impl_, StartCapture(capture_client(), _)) | |
132 .Times(1) | |
133 .WillOnce(CreateDataBufferFromCapture(capture_client(), | |
134 vc_impl_.get(), | |
135 buffer_count)); | |
136 EXPECT_CALL(*vc_impl_, FeedBuffer(_)) | |
137 .Times(buffer_count) | |
138 .WillRepeatedly(DeleteDataBuffer()); | |
139 decoder_->Seek(base::TimeDelta(), | |
140 media::NewExpectedStatusCB(media::PIPELINE_OK)); | |
141 message_loop_->RunAllPending(); | |
142 } | |
143 | |
144 void Play() { | |
145 decoder_->Play(media::NewExpectedClosure()); | |
146 message_loop_->RunAllPending(); | |
147 } | |
148 | |
149 void Stop() { | |
150 EXPECT_CALL(*vc_impl_, StopCapture(capture_client())) | |
151 .Times(1) | |
152 .WillOnce(CaptureStopped(capture_client(), vc_impl_.get())); | |
153 EXPECT_CALL(*vc_manager_, RemoveDevice(_, _)) | |
154 .WillOnce(Return()); | |
155 decoder_->Stop(media::NewExpectedClosure()); | |
156 message_loop_->RunAllPending(); | |
157 } | |
158 | |
159 void Read() { | |
wjia(left Chromium)
2011/11/04 03:31:16
Read() alone will fail to receive FrameReady(). It
scherkus (not reviewing)
2011/11/04 16:32:57
Done.
| |
160 EXPECT_CALL(*this, FrameReady(_)); | |
161 decoder_->Read(read_cb_); | |
162 } | |
163 | |
164 media::VideoCapture::EventHandler* capture_client() { | |
165 return static_cast<media::VideoCapture::EventHandler*>(decoder_); | |
166 } | |
167 | |
114 MOCK_METHOD1(FrameReady, void(scoped_refptr<media::VideoFrame>)); | 168 MOCK_METHOD1(FrameReady, void(scoped_refptr<media::VideoFrame>)); |
115 | 169 |
116 // Fixture members. | 170 // Fixture members. |
117 scoped_refptr<CaptureVideoDecoder> decoder_; | 171 scoped_refptr<CaptureVideoDecoder> decoder_; |
118 scoped_refptr<MockVideoCaptureImplManager> vc_manager_; | 172 scoped_refptr<MockVideoCaptureImplManager> vc_manager_; |
173 scoped_ptr<MockVideoCaptureImpl> vc_impl_; | |
119 media::MockStatisticsCallback statistics_callback_object_; | 174 media::MockStatisticsCallback statistics_callback_object_; |
120 StrictMock<media::MockFilterHost> host_; | 175 StrictMock<media::MockFilterHost> host_; |
121 scoped_ptr<MessageLoop> message_loop_; | 176 scoped_ptr<MessageLoop> message_loop_; |
122 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 177 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
123 media::VideoDecoder::ReadCB read_cb_; | 178 media::VideoDecoder::ReadCB read_cb_; |
124 | 179 |
125 private: | 180 private: |
126 DISALLOW_COPY_AND_ASSIGN(CaptureVideoDecoderTest); | 181 DISALLOW_COPY_AND_ASSIGN(CaptureVideoDecoderTest); |
127 }; | 182 }; |
128 | 183 |
184 TEST_F(CaptureVideoDecoderTest, Initialize) { | |
185 // Test basic initialize and teardown. | |
186 Initialize(); | |
187 | |
188 // Natural size should be initialized to default capability. | |
189 EXPECT_EQ(kWidth, decoder_->natural_size().width()); | |
190 EXPECT_EQ(kHeight, decoder_->natural_size().height()); | |
191 | |
192 Stop(); | |
193 } | |
194 | |
129 TEST_F(CaptureVideoDecoderTest, Play) { | 195 TEST_F(CaptureVideoDecoderTest, Play) { |
130 int data_buffer_number = 1; | 196 // Test basic initialize, play, and teardown sequence. |
131 media::VideoCapture::EventHandler* capture_client = | 197 Initialize(); |
132 static_cast<media::VideoCapture::EventHandler*>(decoder_); | 198 Read(); |
133 scoped_ptr<MockVideoCaptureImpl> vc_impl( | 199 Seek(1); |
134 new MockVideoCaptureImpl(kVideoStreamId, | 200 Play(); |
135 message_loop_proxy_, | 201 Stop(); |
136 new VideoCaptureMessageFilter())); | 202 } |
137 | 203 |
138 EXPECT_CALL(*vc_manager_, AddDevice(_, _)) | 204 TEST_F(CaptureVideoDecoderTest, OnDeviceInfoReceived) { |
139 .WillOnce(Return(vc_impl.get())); | 205 // Test that natural size gets updated as device information is sent. |
140 decoder_->Initialize(NULL, | 206 Initialize(); |
141 media::NewExpectedClosure(), | 207 Read(); |
142 NewStatisticsCallback()); | 208 Seek(1); |
209 | |
210 gfx::Size expected_size(kWidth * 2, kHeight * 2); | |
211 | |
212 media::VideoCaptureParams params; | |
213 params.width = expected_size.width(); | |
214 params.height = expected_size.height(); | |
215 params.frame_per_second = kFPS; | |
216 params.session_id = kVideoStreamId; | |
217 | |
218 EXPECT_CALL(host_, SetNaturalVideoSize(expected_size)); | |
219 decoder_->OnDeviceInfoReceived(vc_impl_.get(), params); | |
143 message_loop_->RunAllPending(); | 220 message_loop_->RunAllPending(); |
144 | 221 |
145 EXPECT_CALL(*this, FrameReady(_)); | 222 EXPECT_EQ(expected_size.width(), decoder_->natural_size().width()); |
146 decoder_->Read(read_cb_); | 223 EXPECT_EQ(expected_size.height(), decoder_->natural_size().height()); |
147 | 224 |
148 EXPECT_CALL(*vc_impl, StartCapture(capture_client, _)) | 225 Stop(); |
149 .Times(1) | |
150 .WillOnce(CreateDataBufferFromCapture(capture_client, vc_impl.get(), | |
151 data_buffer_number)); | |
152 EXPECT_CALL(*vc_impl, FeedBuffer(_)) | |
153 .Times(data_buffer_number) | |
154 .WillRepeatedly(DeleteDataBuffer()); | |
155 decoder_->Seek(base::TimeDelta(), | |
156 media::NewExpectedStatusCB(media::PIPELINE_OK)); | |
157 decoder_->Play(media::NewExpectedClosure()); | |
158 message_loop_->RunAllPending(); | |
159 | |
160 EXPECT_CALL(*vc_impl, StopCapture(capture_client)) | |
161 .Times(1) | |
162 .WillOnce(CaptureStopped(capture_client, vc_impl.get())); | |
163 EXPECT_CALL(*vc_manager_, RemoveDevice(_, _)) | |
164 .WillOnce(Return()); | |
165 decoder_->Stop(media::NewExpectedClosure()); | |
166 message_loop_->RunAllPending(); | |
167 } | 226 } |
OLD | NEW |