diff options
author | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 02:34:54 +0000 |
---|---|---|
committer | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 02:34:54 +0000 |
commit | 4a46734e12d09c0fa38a2ce706441a25e5d016c0 (patch) | |
tree | 38534d75bd050fcfd8c14055974e76524b3c39d6 /media/video/ffmpeg_video_decode_engine_unittest.cc | |
parent | 1d124d66343f85bdb54e3cf3fc4ce44ffb2e7cf7 (diff) | |
download | chromium_src-4a46734e12d09c0fa38a2ce706441a25e5d016c0.zip chromium_src-4a46734e12d09c0fa38a2ce706441a25e5d016c0.tar.gz chromium_src-4a46734e12d09c0fa38a2ce706441a25e5d016c0.tar.bz2 |
Revert 77476 - Remove FFmpegVideoDecodeEngine's dependency on AVStream.
This change seems to have caused Linux Heapcheck bot redness.
http://build.chromium.org/p/chromium.memory/builders/Linux%20Heapcheck/builds/4846
First step of many towards removing DemuxerStream::QueryInterface, AVStreamProvider, and MediaFormat.
BUG=28206
TEST=media_unittests
Review URL: http://codereview.chromium.org/6624062
TBR=scherkus@chromium.org
Review URL: http://codereview.chromium.org/6665020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77770 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/video/ffmpeg_video_decode_engine_unittest.cc')
-rw-r--r-- | media/video/ffmpeg_video_decode_engine_unittest.cc | 82 |
1 files changed, 38 insertions, 44 deletions
diff --git a/media/video/ffmpeg_video_decode_engine_unittest.cc b/media/video/ffmpeg_video_decode_engine_unittest.cc index a4e3123..e3bea41 100644 --- a/media/video/ffmpeg_video_decode_engine_unittest.cc +++ b/media/video/ffmpeg_video_decode_engine_unittest.cc @@ -23,7 +23,7 @@ namespace media { static const int kWidth = 320; static const int kHeight = 240; -static const AVRational kFrameRate = { 100, 1 }; +static const AVRational kTimeBase = { 1, 100 }; static void InitializeFrame(uint8_t* data, int width, AVFrame* frame) { frame->data[0] = data; @@ -35,7 +35,7 @@ static void InitializeFrame(uint8_t* data, int width, AVFrame* frame) { } ACTION_P(DecodeComplete, decoder) { - decoder->set_video_frame(arg0); + decoder->video_frame_ = arg0; } ACTION_P2(DemuxComplete, engine, buffer) { @@ -43,27 +43,33 @@ ACTION_P2(DemuxComplete, engine, buffer) { } ACTION_P(SaveInitializeResult, engine) { - engine->set_video_codec_info(arg0); + engine->info_ = arg0; } class FFmpegVideoDecodeEngineTest : public testing::Test, public VideoDecodeEngine::EventHandler { - public: - FFmpegVideoDecodeEngineTest() - : config_(kCodecH264, kWidth, kHeight, - kFrameRate.num, kFrameRate.den, NULL, 0) { - + protected: + FFmpegVideoDecodeEngineTest() { // Setup FFmpeg structures. frame_buffer_.reset(new uint8[kWidth * kHeight]); memset(&yuv_frame_, 0, sizeof(yuv_frame_)); InitializeFrame(frame_buffer_.get(), kWidth, &yuv_frame_); memset(&codec_context_, 0, sizeof(codec_context_)); + codec_context_.width = kWidth; + codec_context_.height = kHeight; + codec_context_.time_base = kTimeBase; + memset(&codec_, 0, sizeof(codec_)); + memset(&stream_, 0, sizeof(stream_)); + stream_.codec = &codec_context_; + stream_.r_frame_rate.num = kTimeBase.den; + stream_.r_frame_rate.den = kTimeBase.num; buffer_ = new DataBuffer(1); test_engine_.reset(new FFmpegVideoDecodeEngine()); + test_engine_->SetCodecContextForTest(&codec_context_); VideoFrame::CreateFrame(VideoFrame::YV12, kWidth, @@ -78,9 +84,7 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, } void Initialize() { - EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) - .WillOnce(Return(&codec_context_)); - EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); @@ -90,9 +94,11 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, .WillOnce(Return(0)); EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); - EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) - .Times(1); + config_.codec = kCodecH264; + config_.opaque_context = &stream_; + config_.width = kWidth; + config_.height = kHeight; EXPECT_CALL(*this, OnInitializeComplete(_)) .WillOnce(SaveInitializeResult(this)); test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); @@ -120,7 +126,7 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, codec_context_.height = height; } - // VideoDecodeEngine::EventHandler implementation. + public: MOCK_METHOD2(ConsumeVideoFrame, void(scoped_refptr<VideoFrame> video_frame, const PipelineStatistics& statistics)); @@ -134,30 +140,20 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, MOCK_METHOD0(OnError, void()); MOCK_METHOD1(OnFormatChange, void(VideoStreamInfo stream_info)); - // Used by gmock actions. - void set_video_frame(scoped_refptr<VideoFrame> video_frame) { - video_frame_ = video_frame; - } - - void set_video_codec_info(const VideoCodecInfo& info) { - info_ = info; - } - - protected: + scoped_refptr<VideoFrame> video_frame_; VideoCodecConfig config_; VideoCodecInfo info_; - scoped_refptr<VideoFrame> video_frame_; + protected: scoped_ptr<FFmpegVideoDecodeEngine> test_engine_; scoped_array<uint8_t> frame_buffer_; StrictMock<MockFFmpeg> mock_ffmpeg_; AVFrame yuv_frame_; AVCodecContext codec_context_; + AVStream stream_; AVCodec codec_; scoped_refptr<DataBuffer> buffer_; - private: - DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecodeEngineTest); }; TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { @@ -166,17 +162,17 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { // Test avcodec_find_decoder() returning NULL. - EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) - .WillOnce(Return(&codec_context_)); - EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(ReturnNull()); EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); - EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) - .Times(1); + config_.codec = kCodecH264; + config_.opaque_context = &stream_; + config_.width = kWidth; + config_.height = kHeight; EXPECT_CALL(*this, OnInitializeComplete(_)) .WillOnce(SaveInitializeResult(this)); test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); @@ -186,9 +182,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { // Note There are 2 threads for FFmpeg-mt. TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { // Test avcodec_thread_init() failing. - EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) - .WillOnce(Return(&codec_context_)); - EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); @@ -196,9 +190,11 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { .WillOnce(Return(-1)); EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); - EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) - .Times(1); + config_.codec = kCodecH264; + config_.opaque_context = &stream_; + config_.width = kWidth; + config_.height = kHeight; EXPECT_CALL(*this, OnInitializeComplete(_)) .WillOnce(SaveInitializeResult(this)); test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); @@ -207,9 +203,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { // Test avcodec_open() failing. - EXPECT_CALL(mock_ffmpeg_, AVCodecAllocContext()) - .WillOnce(Return(&codec_context_)); - EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_H264)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); @@ -219,9 +213,11 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { .WillOnce(Return(-1)); EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); - EXPECT_CALL(mock_ffmpeg_, AVFree(&codec_context_)) - .Times(1); + config_.codec = kCodecH264; + config_.opaque_context = &stream_; + config_.width = kWidth; + config_.height = kHeight; EXPECT_CALL(*this, OnInitializeComplete(_)) .WillOnce(SaveInitializeResult(this)); test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); @@ -314,8 +310,6 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_SmallerHeight) { } TEST_F(FFmpegVideoDecodeEngineTest, GetSurfaceFormat) { - Initialize(); - // YV12 formats. codec_context_.pix_fmt = PIX_FMT_YUV420P; EXPECT_EQ(VideoFrame::YV12, test_engine_->GetSurfaceFormat()); |