diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 23:50:57 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 23:50:57 +0000 |
commit | 5942fbfe6efa448722685c6ec3f157a8dd996228 (patch) | |
tree | 95f3001e63ada59e0d4b57d62025425012ed2545 /media | |
parent | 9f1591d628b6b90e5bad4ad00264300188b29194 (diff) | |
download | chromium_src-5942fbfe6efa448722685c6ec3f157a8dd996228.zip chromium_src-5942fbfe6efa448722685c6ec3f157a8dd996228.tar.gz chromium_src-5942fbfe6efa448722685c6ec3f157a8dd996228.tar.bz2 |
Moving MockFFmpeg to its own file and some media.gyp cleanup.
Step one of having a completely mocked FFmpeg library.
Review URL: http://codereview.chromium.org/126160
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18455 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/mock_ffmpeg.cc | 60 | ||||
-rw-r--r-- | media/base/mock_ffmpeg.h | 34 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 59 | ||||
-rw-r--r-- | media/media.gyp | 38 |
4 files changed, 116 insertions, 75 deletions
diff --git a/media/base/mock_ffmpeg.cc b/media/base/mock_ffmpeg.cc new file mode 100644 index 0000000..4e9fc03 --- /dev/null +++ b/media/base/mock_ffmpeg.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/mock_ffmpeg.h" + +#include "base/logging.h" +#include "media/filters/ffmpeg_common.h" + +namespace media { + +MockFFmpeg* MockFFmpeg::instance_ = NULL; + +// static +void MockFFmpeg::set(MockFFmpeg* instance) { + instance_ = instance; +} + +// static +MockFFmpeg* MockFFmpeg::get() { + return instance_; +} + +// FFmpeg stubs that delegate to the FFmpegMock instance. +extern "C" { + +AVCodec* avcodec_find_decoder(enum CodecID id) { + return media::MockFFmpeg::get()->AVCodecFindDecoder(id); +} + +int avcodec_open(AVCodecContext* avctx, AVCodec* codec) { + return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec); +} + +int avcodec_thread_init(AVCodecContext* avctx, int threads) { + return media::MockFFmpeg::get()->AVCodecThreadInit(avctx, threads); +} + +void avcodec_flush_buffers(AVCodecContext* avctx) { + NOTREACHED(); +} + +AVFrame* avcodec_alloc_frame() { + NOTREACHED(); + return NULL; +} + +int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture, + int* got_picture_ptr, AVPacket* avpkt) { + NOTREACHED(); + return 0; +} + +void av_init_packet(AVPacket* pkt) { + NOTREACHED(); +} + +} // extern "C" + +} // namespace media diff --git a/media/base/mock_ffmpeg.h b/media/base/mock_ffmpeg.h new file mode 100644 index 0000000..62b085c --- /dev/null +++ b/media/base/mock_ffmpeg.h @@ -0,0 +1,34 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_BASE_MOCK_FFMPEG_H_ +#define MEDIA_BASE_MOCK_FFMPEG_H_ + +#include "testing/gmock/include/gmock/gmock.h" + +struct AVCodec; +struct AVCodecContext; +struct AVFrame; +struct AVPacket; +enum CodecID; + +namespace media { + +class MockFFmpeg { + public: + MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id)); + MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec)); + MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads)); + + // Setter/getter for the global instance of MockFFmpeg. + static void set(MockFFmpeg* instance); + static MockFFmpeg* get(); + + private: + static MockFFmpeg* instance_; +}; + +} // namespace media + +#endif // MEDIA_BASE_MOCK_FFMPEG_H_ diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index 7cb0d7b..4faf0f8 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -6,11 +6,11 @@ #include "base/singleton.h" #include "media/base/filters.h" +#include "media/base/mock_ffmpeg.h" #include "media/base/mock_filter_host.h" #include "media/filters/ffmpeg_common.h" #include "media/filters/ffmpeg_interfaces.h" #include "media/filters/ffmpeg_video_decoder.h" -#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" using ::testing::Return; @@ -29,65 +29,8 @@ class MockDemuxerStream : public DemuxerStream, public AVStreamProvider { MOCK_METHOD0(GetAVStream, AVStream*()); }; -class MockFFmpeg { - public: - MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id)); - MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec)); - MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads)); - - // Setter/getter for the global instance of MockFFmpeg. - static void set(MockFFmpeg* instance) { - instance_ = instance; - } - - static MockFFmpeg* get() { - return instance_; - } - - private: - static MockFFmpeg* instance_; -}; - -MockFFmpeg* MockFFmpeg::instance_ = NULL; - } // namespace media -// FFmpeg mocks to remove dependency on having the DLLs present. -extern "C" { - -AVCodec* avcodec_find_decoder(enum CodecID id) { - return media::MockFFmpeg::get()->AVCodecFindDecoder(id); -} - -int avcodec_open(AVCodecContext* avctx, AVCodec* codec) { - return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec); -} - -int avcodec_thread_init(AVCodecContext* avctx, int threads) { - return media::MockFFmpeg::get()->AVCodecThreadInit(avctx, threads); -} - -void avcodec_flush_buffers(AVCodecContext* avctx) { - NOTREACHED(); -} - -AVFrame* avcodec_alloc_frame() { - NOTREACHED(); - return NULL; -} - -int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture, - int* got_picture_ptr, AVPacket* avpkt) { - NOTREACHED(); - return 0; -} - -void av_init_packet(AVPacket* pkt) { - NOTREACHED(); -} - -} // extern "C" - namespace media { // Fixture class to facilitate writing tests. Takes care of setting up the diff --git a/media/media.gyp b/media/media.gyp index 8453038..0545788 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -57,9 +57,6 @@ 'base/media.h', 'base/media_format.cc', 'base/media_format.h', - 'base/mock_filter_host.h', - 'base/mock_media_filters.h', - 'base/mock_pipeline.h', 'base/pipeline.h', 'base/pipeline_impl.cc', 'base/pipeline_impl.h', @@ -150,6 +147,11 @@ 'audio/mac/audio_output_mac_unittest.cc', 'audio/simple_sources_unittest.cc', 'base/data_buffer_unittest.cc', + 'base/mock_ffmpeg.cc', + 'base/mock_ffmpeg.h', + 'base/mock_filter_host.h', + 'base/mock_media_filters.h', + 'base/mock_pipeline.h', 'base/pipeline_impl_unittest.cc', 'base/run_all_unittests.cc', 'base/seekable_buffer_unittest.cc', @@ -172,6 +174,7 @@ '../build/linux/system.gyp:gtk', ], 'sources!': [ + 'base/mock_ffmpeg.cc', 'filters/ffmpeg_demuxer_unittest.cc', 'filters/ffmpeg_glue_unittest.cc', 'filters/ffmpeg_video_decoder_unittest.cc', @@ -179,6 +182,7 @@ }], ['OS=="mac"', { 'sources!': [ + 'base/mock_ffmpeg.cc', 'filters/ffmpeg_demuxer_unittest.cc', 'filters/ffmpeg_glue_unittest.cc', 'filters/ffmpeg_video_decoder_unittest.cc', @@ -220,20 +224,20 @@ '../third_party/ffmpeg/ffmpeg.gyp:ffmpeg', ], 'sources': [ - 'player/list.h', - 'player/mainfrm.h', - 'player/movie.cc', - 'player/movie.h', - 'player/player_wtl.cc', - 'player/player_wtl.rc', - 'player/props.h', - 'player/seek.h', - 'player/resource.h', - 'player/stdafx.h', - 'player/view.h', - 'player/wtl_renderer.cc', - 'player/wtl_renderer.h', - ], + 'player/list.h', + 'player/mainfrm.h', + 'player/movie.cc', + 'player/movie.h', + 'player/player_wtl.cc', + 'player/player_wtl.rc', + 'player/props.h', + 'player/seek.h', + 'player/resource.h', + 'player/stdafx.h', + 'player/view.h', + 'player/wtl_renderer.cc', + 'player/wtl_renderer.h', + ], 'msvs_settings': { 'VCLinkerTool': { 'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS |