| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.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" |
| 11 #include "media/video/ffmpeg_video_decode_engine.h" | 11 #include "media/video/ffmpeg_video_decode_engine.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 codec_context_.time_base = kTimeBase; | 61 codec_context_.time_base = kTimeBase; |
| 62 | 62 |
| 63 memset(&codec_, 0, sizeof(codec_)); | 63 memset(&codec_, 0, sizeof(codec_)); |
| 64 memset(&stream_, 0, sizeof(stream_)); | 64 memset(&stream_, 0, sizeof(stream_)); |
| 65 stream_.codec = &codec_context_; | 65 stream_.codec = &codec_context_; |
| 66 stream_.r_frame_rate.num = kTimeBase.den; | 66 stream_.r_frame_rate.num = kTimeBase.den; |
| 67 stream_.r_frame_rate.den = kTimeBase.num; | 67 stream_.r_frame_rate.den = kTimeBase.num; |
| 68 | 68 |
| 69 buffer_ = new DataBuffer(1); | 69 buffer_ = new DataBuffer(1); |
| 70 | 70 |
| 71 // Initialize MockFFmpeg. |
| 72 MockFFmpeg::set(&mock_ffmpeg_); |
| 73 |
| 71 test_engine_.reset(new FFmpegVideoDecodeEngine()); | 74 test_engine_.reset(new FFmpegVideoDecodeEngine()); |
| 72 test_engine_->SetCodecContextForTest(&codec_context_); | 75 test_engine_->SetCodecContextForTest(&codec_context_); |
| 73 | 76 |
| 74 VideoFrame::CreateFrame(VideoFrame::YV12, | 77 VideoFrame::CreateFrame(VideoFrame::YV12, |
| 75 kWidth, | 78 kWidth, |
| 76 kHeight, | 79 kHeight, |
| 77 kNoTimestamp, | 80 kNoTimestamp, |
| 78 kNoTimestamp, | 81 kNoTimestamp, |
| 79 &video_frame_); | 82 &video_frame_); |
| 80 } | 83 } |
| 81 | 84 |
| 82 ~FFmpegVideoDecodeEngineTest() { | 85 ~FFmpegVideoDecodeEngineTest() { |
| 83 test_engine_.reset(); | 86 test_engine_.reset(); |
| 87 MockFFmpeg::set(NULL); |
| 84 } | 88 } |
| 85 | 89 |
| 86 void Initialize() { | 90 void Initialize() { |
| 87 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) | 91 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) |
| 88 .WillOnce(Return(&codec_)); | 92 .WillOnce(Return(&codec_)); |
| 89 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 93 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) |
| 90 .WillOnce(Return(&yuv_frame_)); | 94 .WillOnce(Return(&yuv_frame_)); |
| 91 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | 95 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) |
| 92 .WillOnce(Return(0)); | 96 .WillOnce(Return(0)); |
| 93 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) | 97 EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) |
| 94 .WillOnce(Return(0)); | 98 .WillOnce(Return(0)); |
| 95 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 99 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) |
| 96 .Times(1); | 100 .Times(1); |
| 97 | 101 |
| 98 config_.codec = kCodecH264; | 102 config_.codec = kCodecH264; |
| 99 config_.opaque_context = &stream_; | 103 config_.opaque_context = &stream_; |
| 100 config_.width = kWidth; | 104 config_.width = kWidth; |
| 101 config_.height = kHeight; | 105 config_.height = kHeight; |
| 102 EXPECT_CALL(*this, OnInitializeComplete(_)) | 106 EXPECT_CALL(*this, OnInitializeComplete(_)) |
| 103 .WillOnce(SaveInitializeResult(this)); | 107 .WillOnce(SaveInitializeResult(this)); |
| 104 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | 108 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); |
| 105 EXPECT_TRUE(info_.success); | 109 EXPECT_TRUE(info_.success); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 scoped_refptr<DataBuffer> buffer_; | 159 scoped_refptr<DataBuffer> buffer_; |
| 156 | 160 |
| 157 }; | 161 }; |
| 158 | 162 |
| 159 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { | 163 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { |
| 160 Initialize(); | 164 Initialize(); |
| 161 } | 165 } |
| 162 | 166 |
| 163 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { | 167 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { |
| 164 // Test avcodec_find_decoder() returning NULL. | 168 // Test avcodec_find_decoder() returning NULL. |
| 165 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) | 169 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) |
| 166 .WillOnce(ReturnNull()); | 170 .WillOnce(ReturnNull()); |
| 167 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 171 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) |
| 168 .WillOnce(Return(&yuv_frame_)); | 172 .WillOnce(Return(&yuv_frame_)); |
| 169 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 173 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) |
| 170 .Times(1); | 174 .Times(1); |
| 171 | 175 |
| 172 config_.codec = kCodecH264; | 176 config_.codec = kCodecH264; |
| 173 config_.opaque_context = &stream_; | 177 config_.opaque_context = &stream_; |
| 174 config_.width = kWidth; | 178 config_.width = kWidth; |
| 175 config_.height = kHeight; | 179 config_.height = kHeight; |
| 176 EXPECT_CALL(*this, OnInitializeComplete(_)) | 180 EXPECT_CALL(*this, OnInitializeComplete(_)) |
| 177 .WillOnce(SaveInitializeResult(this)); | 181 .WillOnce(SaveInitializeResult(this)); |
| 178 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | 182 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); |
| 179 EXPECT_FALSE(info_.success); | 183 EXPECT_FALSE(info_.success); |
| 180 } | 184 } |
| 181 | 185 |
| 182 // Note There are 2 threads for FFmpeg-mt. | 186 // Note There are 2 threads for FFmpeg-mt. |
| 183 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { | 187 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { |
| 184 // Test avcodec_thread_init() failing. | 188 // Test avcodec_thread_init() failing. |
| 185 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) | 189 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) |
| 186 .WillOnce(Return(&codec_)); | 190 .WillOnce(Return(&codec_)); |
| 187 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 191 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) |
| 188 .WillOnce(Return(&yuv_frame_)); | 192 .WillOnce(Return(&yuv_frame_)); |
| 189 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | 193 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) |
| 190 .WillOnce(Return(-1)); | 194 .WillOnce(Return(-1)); |
| 191 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 195 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) |
| 192 .Times(1); | 196 .Times(1); |
| 193 | 197 |
| 194 config_.codec = kCodecH264; | 198 config_.codec = kCodecH264; |
| 195 config_.opaque_context = &stream_; | 199 config_.opaque_context = &stream_; |
| 196 config_.width = kWidth; | 200 config_.width = kWidth; |
| 197 config_.height = kHeight; | 201 config_.height = kHeight; |
| 198 EXPECT_CALL(*this, OnInitializeComplete(_)) | 202 EXPECT_CALL(*this, OnInitializeComplete(_)) |
| 199 .WillOnce(SaveInitializeResult(this)); | 203 .WillOnce(SaveInitializeResult(this)); |
| 200 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | 204 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); |
| 201 EXPECT_FALSE(info_.success); | 205 EXPECT_FALSE(info_.success); |
| 202 } | 206 } |
| 203 | 207 |
| 204 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { | 208 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { |
| 205 // Test avcodec_open() failing. | 209 // Test avcodec_open() failing. |
| 206 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) | 210 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) |
| 207 .WillOnce(Return(&codec_)); | 211 .WillOnce(Return(&codec_)); |
| 208 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) | 212 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) |
| 209 .WillOnce(Return(&yuv_frame_)); | 213 .WillOnce(Return(&yuv_frame_)); |
| 210 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) | 214 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) |
| 211 .WillOnce(Return(0)); | 215 .WillOnce(Return(0)); |
| 212 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) | 216 EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) |
| 213 .WillOnce(Return(-1)); | 217 .WillOnce(Return(-1)); |
| 214 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) | 218 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) |
| 215 .Times(1); | 219 .Times(1); |
| 216 | 220 |
| 217 config_.codec = kCodecH264; | 221 config_.codec = kCodecH264; |
| 218 config_.opaque_context = &stream_; | 222 config_.opaque_context = &stream_; |
| 219 config_.width = kWidth; | 223 config_.width = kWidth; |
| 220 config_.height = kHeight; | 224 config_.height = kHeight; |
| 221 EXPECT_CALL(*this, OnInitializeComplete(_)) | 225 EXPECT_CALL(*this, OnInitializeComplete(_)) |
| 222 .WillOnce(SaveInitializeResult(this)); | 226 .WillOnce(SaveInitializeResult(this)); |
| 223 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); | 227 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); |
| 224 EXPECT_FALSE(info_.success); | 228 EXPECT_FALSE(info_.success); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); | 325 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); |
| 322 codec_context_.pix_fmt = PIX_FMT_YUVJ422P; | 326 codec_context_.pix_fmt = PIX_FMT_YUVJ422P; |
| 323 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); | 327 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); |
| 324 | 328 |
| 325 // Invalid value. | 329 // Invalid value. |
| 326 codec_context_.pix_fmt = PIX_FMT_NONE; | 330 codec_context_.pix_fmt = PIX_FMT_NONE; |
| 327 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat()); | 331 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat()); |
| 328 } | 332 } |
| 329 | 333 |
| 330 } // namespace media | 334 } // namespace media |
| OLD | NEW |