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 <deque> | 5 #include <deque> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "media/base/data_buffer.h" | 11 #include "media/base/data_buffer.h" |
12 #include "media/base/filters.h" | 12 #include "media/base/filters.h" |
13 #include "media/base/mock_callback.h" | 13 #include "media/base/mock_callback.h" |
14 #include "media/base/mock_filter_host.h" | 14 #include "media/base/mock_filter_host.h" |
15 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
17 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
18 #include "media/filters/ffmpeg_video_decoder.h" | 18 #include "media/filters/ffmpeg_video_decoder.h" |
19 #include "media/video/video_decode_engine.h" | 19 #include "media/video/video_decode_engine.h" |
20 #include "media/video/video_decode_context.h" | 20 #include "media/video/video_decode_context.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using ::testing::_; | 23 using ::testing::_; |
24 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
25 using ::testing::DoAll; | 25 using ::testing::DoAll; |
26 using ::testing::Message; | 26 using ::testing::Message; |
27 using ::testing::Return; | 27 using ::testing::Return; |
28 using ::testing::ReturnNull; | 28 using ::testing::ReturnNull; |
| 29 using ::testing::ReturnRef; |
29 using ::testing::SetArgumentPointee; | 30 using ::testing::SetArgumentPointee; |
30 using ::testing::StrictMock; | 31 using ::testing::StrictMock; |
31 using ::testing::WithArg; | 32 using ::testing::WithArg; |
32 using ::testing::Invoke; | 33 using ::testing::Invoke; |
33 | 34 |
34 namespace media { | 35 namespace media { |
35 | 36 |
| 37 static const VideoFrame::Format kVideoFormat = VideoFrame::YV12; |
36 static const gfx::Size kCodedSize(1280, 720); | 38 static const gfx::Size kCodedSize(1280, 720); |
37 static const gfx::Rect kVisibleRect(1280, 720); | 39 static const gfx::Rect kVisibleRect(1280, 720); |
38 static const gfx::Size kNaturalSize(1280, 720); | 40 static const gfx::Size kNaturalSize(1280, 720); |
| 41 static const AVRational kFrameRate = { 100, 1 }; |
| 42 static const AVRational kAspectRatio = { 1, 1 }; |
39 | 43 |
40 // Holds timestamp and duration data needed for properly enqueuing a frame. | 44 // Holds timestamp and duration data needed for properly enqueuing a frame. |
41 struct TimeTuple { | 45 struct TimeTuple { |
42 base::TimeDelta timestamp; | 46 base::TimeDelta timestamp; |
43 base::TimeDelta duration; | 47 base::TimeDelta duration; |
44 }; | 48 }; |
45 | 49 |
46 static const TimeTuple kTestPts1 = | 50 static const TimeTuple kTestPts1 = |
47 { base::TimeDelta::FromMicroseconds(123), | 51 { base::TimeDelta::FromMicroseconds(123), |
48 base::TimeDelta::FromMicroseconds(50) }; | 52 base::TimeDelta::FromMicroseconds(50) }; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 131 |
128 // Inject mocks and prepare a demuxer stream. | 132 // Inject mocks and prepare a demuxer stream. |
129 decoder_->set_host(&host_); | 133 decoder_->set_host(&host_); |
130 decoder_->set_consume_video_frame_callback( | 134 decoder_->set_consume_video_frame_callback( |
131 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, | 135 base::Bind(&MockVideoRenderer::ConsumeVideoFrame, |
132 base::Unretained(renderer_.get()))); | 136 base::Unretained(renderer_.get()))); |
133 decoder_->SetVideoDecodeEngineForTest(engine_); | 137 decoder_->SetVideoDecodeEngineForTest(engine_); |
134 demuxer_ = new StrictMock<MockDemuxerStream>(); | 138 demuxer_ = new StrictMock<MockDemuxerStream>(); |
135 | 139 |
136 // Initialize FFmpeg fixtures. | 140 // Initialize FFmpeg fixtures. |
137 memset(&stream_, 0, sizeof(stream_)); | |
138 memset(&codec_context_, 0, sizeof(codec_context_)); | |
139 memset(&codec_, 0, sizeof(codec_)); | |
140 memset(&yuv_frame_, 0, sizeof(yuv_frame_)); | 141 memset(&yuv_frame_, 0, sizeof(yuv_frame_)); |
141 base::TimeDelta zero; | 142 base::TimeDelta zero; |
142 video_frame_ = VideoFrame::CreateFrame(VideoFrame::YV12, | 143 video_frame_ = VideoFrame::CreateFrame(VideoFrame::YV12, |
143 kVisibleRect.width(), | 144 kVisibleRect.width(), |
144 kVisibleRect.height(), | 145 kVisibleRect.height(), |
145 zero, zero); | 146 zero, zero); |
146 stream_.codec = &codec_context_; | |
147 codec_context_.width = kVisibleRect.width(); | |
148 codec_context_.height = kVisibleRect.height(); | |
149 codec_context_.codec_id = CODEC_ID_H264; | |
150 stream_.r_frame_rate.num = 1; | |
151 stream_.r_frame_rate.den = 1; | |
152 buffer_ = new DataBuffer(1); | 147 buffer_ = new DataBuffer(1); |
153 end_of_stream_buffer_ = new DataBuffer(0); | 148 end_of_stream_buffer_ = new DataBuffer(0); |
154 | 149 |
155 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) | 150 EXPECT_CALL(stats_callback_object_, OnStatistics(_)) |
156 .Times(AnyNumber()); | 151 .Times(AnyNumber()); |
| 152 |
| 153 config_.Initialize(kCodecVP8, kVideoFormat, kCodedSize, kVisibleRect, |
| 154 kFrameRate.num, kFrameRate.den, |
| 155 kAspectRatio.num, kAspectRatio.den, |
| 156 NULL, 0); |
157 } | 157 } |
158 | 158 |
159 virtual ~FFmpegVideoDecoderTest() { | 159 virtual ~FFmpegVideoDecoderTest() { |
160 // The presence of an event handler means we need to uninitialize. | 160 // The presence of an event handler means we need to uninitialize. |
161 if (engine_->event_handler_) { | 161 if (engine_->event_handler_) { |
162 EXPECT_CALL(*engine_, Uninitialize()) | 162 EXPECT_CALL(*engine_, Uninitialize()) |
163 .WillOnce(EngineUninitialize(engine_)); | 163 .WillOnce(EngineUninitialize(engine_)); |
164 } | 164 } |
165 | 165 |
166 decoder_->Stop(NewExpectedClosure()); | 166 decoder_->Stop(NewExpectedClosure()); |
167 | 167 |
168 // Finish up any remaining tasks. | 168 // Finish up any remaining tasks. |
169 message_loop_.RunAllPending(); | 169 message_loop_.RunAllPending(); |
170 } | 170 } |
171 | 171 |
172 void InitializeDecoderSuccessfully() { | 172 void InitializeDecoderSuccessfully() { |
173 // Test successful initialization. | 173 EXPECT_CALL(*demuxer_, video_decoder_config()) |
174 EXPECT_CALL(*demuxer_, GetAVStream()) | 174 .WillOnce(ReturnRef(config_)); |
175 .WillOnce(Return(&stream_)); | |
176 | 175 |
177 EXPECT_CALL(*engine_, Initialize(_, _, _, _)) | 176 EXPECT_CALL(*engine_, Initialize(_, _, _, _)) |
178 .WillOnce(EngineInitialize(engine_, true)); | 177 .WillOnce(EngineInitialize(engine_, true)); |
179 | 178 |
180 decoder_->Initialize(demuxer_, | 179 decoder_->Initialize(demuxer_, |
181 NewExpectedClosure(), NewStatisticsCallback()); | 180 NewExpectedClosure(), NewStatisticsCallback()); |
182 message_loop_.RunAllPending(); | 181 message_loop_.RunAllPending(); |
183 } | 182 } |
184 | 183 |
185 StatisticsCallback NewStatisticsCallback() { | 184 StatisticsCallback NewStatisticsCallback() { |
186 return base::Bind(&MockStatisticsCallback::OnStatistics, | 185 return base::Bind(&MockStatisticsCallback::OnStatistics, |
187 base::Unretained(&stats_callback_object_)); | 186 base::Unretained(&stats_callback_object_)); |
188 } | 187 } |
189 | 188 |
190 // Fixture members. | 189 // Fixture members. |
191 MockVideoDecodeEngine* engine_; // Owned by |decoder_|. | 190 MockVideoDecodeEngine* engine_; // Owned by |decoder_|. |
192 scoped_refptr<DecoderPrivateMock> decoder_; | 191 scoped_refptr<DecoderPrivateMock> decoder_; |
193 scoped_refptr<MockVideoRenderer> renderer_; | 192 scoped_refptr<MockVideoRenderer> renderer_; |
194 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; | 193 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; |
195 scoped_refptr<DataBuffer> buffer_; | 194 scoped_refptr<DataBuffer> buffer_; |
196 scoped_refptr<DataBuffer> end_of_stream_buffer_; | 195 scoped_refptr<DataBuffer> end_of_stream_buffer_; |
197 MockStatisticsCallback stats_callback_object_; | 196 MockStatisticsCallback stats_callback_object_; |
198 StrictMock<MockFilterHost> host_; | 197 StrictMock<MockFilterHost> host_; |
199 MessageLoop message_loop_; | 198 MessageLoop message_loop_; |
200 | 199 |
201 // FFmpeg fixtures. | 200 // FFmpeg fixtures. |
202 AVStream stream_; | |
203 AVCodecContext codec_context_; | |
204 AVCodec codec_; | |
205 AVFrame yuv_frame_; | 201 AVFrame yuv_frame_; |
206 scoped_refptr<VideoFrame> video_frame_; | 202 scoped_refptr<VideoFrame> video_frame_; |
207 | 203 |
| 204 VideoDecoderConfig config_; |
| 205 |
208 private: | 206 private: |
209 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoderTest); | 207 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoderTest); |
210 }; | 208 }; |
211 | 209 |
212 TEST_F(FFmpegVideoDecoderTest, Initialize_GetAVStreamFails) { | |
213 // Test GetAVStream returning NULL. | |
214 EXPECT_CALL(*demuxer_, GetAVStream()) | |
215 .WillOnce(ReturnNull()); | |
216 EXPECT_CALL(host_, SetError(PIPELINE_ERROR_DECODE)); | |
217 | |
218 decoder_->Initialize(demuxer_, | |
219 NewExpectedClosure(), NewStatisticsCallback()); | |
220 | |
221 message_loop_.RunAllPending(); | |
222 } | |
223 | |
224 TEST_F(FFmpegVideoDecoderTest, Initialize_EngineFails) { | 210 TEST_F(FFmpegVideoDecoderTest, Initialize_EngineFails) { |
225 // Test successful initialization. | 211 EXPECT_CALL(*demuxer_, video_decoder_config()) |
226 EXPECT_CALL(*demuxer_, GetAVStream()) | 212 .WillOnce(ReturnRef(config_)); |
227 .WillOnce(Return(&stream_)); | |
228 | 213 |
229 EXPECT_CALL(*engine_, Initialize(_, _, _, _)) | 214 EXPECT_CALL(*engine_, Initialize(_, _, _, _)) |
230 .WillOnce(EngineInitialize(engine_, false)); | 215 .WillOnce(EngineInitialize(engine_, false)); |
231 | 216 |
232 EXPECT_CALL(host_, SetError(PIPELINE_ERROR_DECODE)); | 217 EXPECT_CALL(host_, SetError(PIPELINE_ERROR_DECODE)); |
233 | 218 |
234 decoder_->Initialize(demuxer_, | 219 decoder_->Initialize(demuxer_, |
235 NewExpectedClosure(), NewStatisticsCallback()); | 220 NewExpectedClosure(), NewStatisticsCallback()); |
236 message_loop_.RunAllPending(); | 221 message_loop_.RunAllPending(); |
237 } | 222 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 EXPECT_CALL(*engine_, Seek()) | 389 EXPECT_CALL(*engine_, Seek()) |
405 .WillOnce(EngineSeek(engine_)); | 390 .WillOnce(EngineSeek(engine_)); |
406 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); | 391 decoder_->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK)); |
407 | 392 |
408 EXPECT_TRUE(kZero == decoder_->pts_stream_.current_duration()); | 393 EXPECT_TRUE(kZero == decoder_->pts_stream_.current_duration()); |
409 EXPECT_EQ(FFmpegVideoDecoder::kNormal, decoder_->state_); | 394 EXPECT_EQ(FFmpegVideoDecoder::kNormal, decoder_->state_); |
410 } | 395 } |
411 } | 396 } |
412 | 397 |
413 } // namespace media | 398 } // namespace media |
OLD | NEW |