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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "media/base/data_buffer.h" | 7 #include "media/base/data_buffer.h" |
8 #include "media/base/mock_ffmpeg.h" | 8 #include "media/base/mock_ffmpeg.h" |
9 #include "media/base/mock_task.h" | 9 #include "media/base/mock_task.h" |
10 #include "media/base/pipeline.h" | 10 #include "media/base/pipeline.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 test_engine_.reset(); | 79 test_engine_.reset(); |
80 } | 80 } |
81 | 81 |
82 void Initialize() { | 82 void Initialize() { |
83 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) | 83 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) |
84 .WillOnce(Return(&codec_context_)); | 84 .WillOnce(Return(&codec_context_)); |
85 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) | 85 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) |
86 .WillOnce(Return(&codec_)); | 86 .WillOnce(Return(&codec_)); |
87 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 87 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) |
88 .WillOnce(Return(&yuv_frame_)); | 88 .WillOnce(Return(&yuv_frame_)); |
89 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | |
90 .WillOnce(Return(0)); | |
91 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) | 89 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) |
92 .WillOnce(Return(0)); | 90 .WillOnce(Return(0)); |
93 EXPECT_CALL(mock_ffmpeg_, AVCodecClose(&codec_context_)) | 91 EXPECT_CALL(mock_ffmpeg_, AVCodecClose(&codec_context_)) |
94 .WillOnce(Return(0)); | 92 .WillOnce(Return(0)); |
95 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 93 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) |
96 .Times(1); | 94 .Times(1); |
97 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) | 95 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) |
98 .Times(1); | 96 .Times(1); |
99 | 97 |
100 EXPECT_CALL(*this, OnInitializeComplete(_)) | 98 EXPECT_CALL(*this, OnInitializeComplete(_)) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 .Times(1); | 180 .Times(1); |
183 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) | 181 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) |
184 .Times(1); | 182 .Times(1); |
185 | 183 |
186 EXPECT_CALL(*this, OnInitializeComplete(_)) | 184 EXPECT_CALL(*this, OnInitializeComplete(_)) |
187 .WillOnce(SaveInitializeResult(this)); | 185 .WillOnce(SaveInitializeResult(this)); |
188 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | 186 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); |
189 EXPECT_FALSE(info_.success); | 187 EXPECT_FALSE(info_.success); |
190 } | 188 } |
191 | 189 |
192 // Note There are 2 threads for FFmpeg-mt. | |
193 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { | |
194 // Test avcodec_thread_init() failing. | |
195 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) | |
196 .WillOnce(Return(&codec_context_)); | |
197 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) | |
198 .WillOnce(Return(&codec_)); | |
199 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | |
200 .WillOnce(Return(&yuv_frame_)); | |
201 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | |
202 .WillOnce(Return(-1)); | |
203 EXPECT_CALL(mock_ffmpeg_, AVCodecClose(&codec_context_)) | |
204 .WillOnce(Return(0)); | |
205 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | |
206 .Times(1); | |
207 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) | |
208 .Times(1); | |
209 | |
210 EXPECT_CALL(*this, OnInitializeComplete(_)) | |
211 .WillOnce(SaveInitializeResult(this)); | |
212 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | |
213 EXPECT_FALSE(info_.success); | |
214 } | |
215 | |
216 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { | 190 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { |
217 // Test avcodec_open() failing. | 191 // Test avcodec_open() failing. |
218 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) | 192 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) |
219 .WillOnce(Return(&codec_context_)); | 193 .WillOnce(Return(&codec_context_)); |
220 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) | 194 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) |
221 .WillOnce(Return(&codec_)); | 195 .WillOnce(Return(&codec_)); |
222 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 196 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) |
223 .WillOnce(Return(&yuv_frame_)); | 197 .WillOnce(Return(&yuv_frame_)); |
224 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | |
225 .WillOnce(Return(0)); | |
226 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) | 198 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) |
227 .WillOnce(Return(-1)); | 199 .WillOnce(Return(-1)); |
228 EXPECT_CALL(mock_ffmpeg_, AVCodecClose(&codec_context_)) | 200 EXPECT_CALL(mock_ffmpeg_, AVCodecClose(&codec_context_)) |
229 .WillOnce(Return(0)); | 201 .WillOnce(Return(0)); |
230 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 202 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) |
231 .Times(1); | 203 .Times(1); |
232 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) | 204 EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) |
233 .Times(1); | 205 .Times(1); |
234 | 206 |
235 EXPECT_CALL(*this, OnInitializeComplete(_)) | 207 EXPECT_CALL(*this, OnInitializeComplete(_)) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); | 307 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); |
336 codec_context_.pix_fmt = PIX_FMT_YUVJ422P; | 308 codec_context_.pix_fmt = PIX_FMT_YUVJ422P; |
337 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); | 309 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); |
338 | 310 |
339 // Invalid value. | 311 // Invalid value. |
340 codec_context_.pix_fmt = PIX_FMT_NONE; | 312 codec_context_.pix_fmt = PIX_FMT_NONE; |
341 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat()); | 313 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat()); |
342 } | 314 } |
343 | 315 |
344 } // namespace media | 316 } // namespace media |
OLD | NEW |