summaryrefslogtreecommitdiffstats
path: root/media/base
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-18 22:06:43 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-18 22:06:43 +0000
commit71893bf4539fe2d65cfc3fc2e0f532a31db9f76a (patch)
tree25967e4975c4673add7765fab145356a07b0be1f /media/base
parent7c4329e5a84ef883d5e3f116d8cb78a401b92b2b (diff)
downloadchromium_src-71893bf4539fe2d65cfc3fc2e0f532a31db9f76a.zip
chromium_src-71893bf4539fe2d65cfc3fc2e0f532a31db9f76a.tar.gz
chromium_src-71893bf4539fe2d65cfc3fc2e0f532a31db9f76a.tar.bz2
Revert 75444 - Move MockFFmpeg instance setting into the constructor/destructor.
Previously tests had to manually call MockFFmpeg::set() during test setup and teardown. Now that operation is handled automatically via scoping. BUG=72933 TEST=media_unittests Review URL: http://codereview.chromium.org/6539021 TBR=scherkus@chromium.org Review URL: http://codereview.chromium.org/6541037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75448 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r--media/base/mock_ffmpeg.cc86
-rw-r--r--media/base/mock_ffmpeg.h5
2 files changed, 52 insertions, 39 deletions
diff --git a/media/base/mock_ffmpeg.cc b/media/base/mock_ffmpeg.cc
index 4a20563..f3aa552 100644
--- a/media/base/mock_ffmpeg.cc
+++ b/media/base/mock_ffmpeg.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -20,9 +20,6 @@ URLProtocol* MockFFmpeg::protocol_ = NULL;
MockFFmpeg::MockFFmpeg()
: outstanding_packets_(0) {
- CHECK(instance_ == NULL) << "Only a single MockFFmpeg instance can exist";
- instance_ = this;
-
// If we haven't assigned our static copy of URLProtocol, set up expectations
// to catch the URLProtocol registered when the singleton instance of
// FFmpegGlue is created.
@@ -43,13 +40,16 @@ MockFFmpeg::MockFFmpeg()
.Times(AtMost(1))
.WillOnce(Return());
}
+ // av_lockmgr_register() is also called from ~FFmpegLock(), so we expect
+ // it to be called at the end.
+ EXPECT_CALL(*this, AVRegisterLockManager(_))
+ .Times(AtMost(2))
+ .WillRepeatedly(Return(0));
}
MockFFmpeg::~MockFFmpeg() {
CHECK(!outstanding_packets_)
<< "MockFFmpeg destroyed with outstanding packets";
- CHECK(instance_);
- instance_ = NULL;
}
void MockFFmpeg::inc_outstanding_packets() {
@@ -62,6 +62,16 @@ void MockFFmpeg::dec_outstanding_packets() {
}
// static
+void MockFFmpeg::set(MockFFmpeg* instance) {
+ instance_ = instance;
+}
+
+// static
+MockFFmpeg* MockFFmpeg::get() {
+ return instance_;
+}
+
+// static
URLProtocol* MockFFmpeg::protocol() {
return protocol_;
}
@@ -76,57 +86,59 @@ void MockFFmpeg::DestructPacket(AVPacket* packet) {
// FFmpeg stubs that delegate to the FFmpegMock instance.
extern "C" {
void avcodec_init() {
- MockFFmpeg::get()->AVCodecInit();
+ media::MockFFmpeg::get()->AVCodecInit();
}
int av_register_protocol2(URLProtocol* protocol, int size) {
- return MockFFmpeg::get()->AVRegisterProtocol2(protocol, size);
+ return media::MockFFmpeg::get()->AVRegisterProtocol2(protocol, size);
}
void av_register_all() {
- MockFFmpeg::get()->AVRegisterAll();
+ media::MockFFmpeg::get()->AVRegisterAll();
}
int av_lockmgr_register(int (*cb)(void**, enum AVLockOp)) {
+ media::MockFFmpeg* mock = media::MockFFmpeg::get();
// Here |mock| may be NULL when this function is called from ~FFmpegGlue().
- if (MockFFmpeg::get()) {
- return MockFFmpeg::get()->AVRegisterLockManager(cb);
+ if (mock != NULL) {
+ return mock->AVRegisterLockManager(cb);
+ } else {
+ return 0;
}
- return 0;
}
AVCodec* avcodec_find_decoder(enum CodecID id) {
- return MockFFmpeg::get()->AVCodecFindDecoder(id);
+ return media::MockFFmpeg::get()->AVCodecFindDecoder(id);
}
int avcodec_open(AVCodecContext* avctx, AVCodec* codec) {
- return MockFFmpeg::get()->AVCodecOpen(avctx, codec);
+ return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec);
}
int avcodec_close(AVCodecContext* avctx) {
- return MockFFmpeg::get()->AVCodecClose(avctx);
+ return media::MockFFmpeg::get()->AVCodecClose(avctx);
}
int avcodec_thread_init(AVCodecContext* avctx, int threads) {
- return MockFFmpeg::get()->AVCodecThreadInit(avctx, threads);
+ return media::MockFFmpeg::get()->AVCodecThreadInit(avctx, threads);
}
void avcodec_flush_buffers(AVCodecContext* avctx) {
- return MockFFmpeg::get()->AVCodecFlushBuffers(avctx);
+ return media::MockFFmpeg::get()->AVCodecFlushBuffers(avctx);
}
AVFrame* avcodec_alloc_frame() {
- return MockFFmpeg::get()->AVCodecAllocFrame();
+ return media::MockFFmpeg::get()->AVCodecAllocFrame();
}
int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture,
int* got_picture_ptr, AVPacket* avpkt) {
- return MockFFmpeg::get()->
+ return media::MockFFmpeg::get()->
AVCodecDecodeVideo2(avctx, picture, got_picture_ptr, avpkt);
}
AVBitStreamFilterContext* av_bitstream_filter_init(const char* name) {
- return MockFFmpeg::get()->AVBitstreamFilterInit(name);
+ return media::MockFFmpeg::get()->AVBitstreamFilterInit(name);
}
int av_bitstream_filter_filter(AVBitStreamFilterContext* bsfc,
@@ -137,29 +149,29 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext* bsfc,
const uint8_t* buf,
int buf_size,
int keyframe) {
- return MockFFmpeg::get()->
+ return media::MockFFmpeg::get()->
AVBitstreamFilterFilter(bsfc, avctx, args, poutbuf, poutbuf_size, buf,
buf_size, keyframe);
}
void av_bitstream_filter_close(AVBitStreamFilterContext* bsf) {
- return MockFFmpeg::get()->AVBitstreamFilterClose(bsf);
+ return media::MockFFmpeg::get()->AVBitstreamFilterClose(bsf);
}
int av_open_input_file(AVFormatContext** format, const char* filename,
AVInputFormat* input_format, int buffer_size,
AVFormatParameters* parameters) {
- return MockFFmpeg::get()->AVOpenInputFile(format, filename,
- input_format, buffer_size,
- parameters);
+ return media::MockFFmpeg::get()->AVOpenInputFile(format, filename,
+ input_format, buffer_size,
+ parameters);
}
void av_close_input_file(AVFormatContext* format) {
- MockFFmpeg::get()->AVCloseInputFile(format);
+ media::MockFFmpeg::get()->AVCloseInputFile(format);
}
int av_find_stream_info(AVFormatContext* format) {
- return MockFFmpeg::get()->AVFindStreamInfo(format);
+ return media::MockFFmpeg::get()->AVFindStreamInfo(format);
}
int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) {
@@ -171,45 +183,45 @@ int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) {
}
int av_read_frame(AVFormatContext* format, AVPacket* packet) {
- return MockFFmpeg::get()->AVReadFrame(format, packet);
+ return media::MockFFmpeg::get()->AVReadFrame(format, packet);
}
int av_seek_frame(AVFormatContext *format, int stream_index, int64_t timestamp,
int flags) {
- return MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp,
- flags)
+ return media::MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp,
+ flags);
}
void av_init_packet(AVPacket* pkt) {
- return MockFFmpeg::get()->AVInitPacket(pkt);
+ return media::MockFFmpeg::get()->AVInitPacket(pkt);
}
int av_new_packet(AVPacket* packet, int size) {
- return MockFFmpeg::get()->AVNewPacket(packet, size);
+ return media::MockFFmpeg::get()->AVNewPacket(packet, size);
}
void av_free_packet(AVPacket* packet) {
- MockFFmpeg::get()->AVFreePacket(packet);
+ media::MockFFmpeg::get()->AVFreePacket(packet);
}
void av_free(void* ptr) {
// Freeing NULL pointers are valid, but they aren't interesting from a mock
// perspective.
if (ptr) {
- MockFFmpeg::get()->AVFree(ptr);
+ media::MockFFmpeg::get()->AVFree(ptr);
}
}
int av_dup_packet(AVPacket* packet) {
- return MockFFmpeg::get()->AVDupPacket(packet);
+ return media::MockFFmpeg::get()->AVDupPacket(packet);
}
void av_log_set_level(int level) {
- MockFFmpeg::get()->AVLogSetLevel(level);
+ media::MockFFmpeg::get()->AVLogSetLevel(level);
}
void av_destruct_packet(AVPacket *pkt) {
- MockFFmpeg::get()->AVDestructPacket(pkt);
+ media::MockFFmpeg::get()->AVDestructPacket(pkt);
}
} // extern "C"
diff --git a/media/base/mock_ffmpeg.h b/media/base/mock_ffmpeg.h
index 89402fe..09daf03 100644
--- a/media/base/mock_ffmpeg.h
+++ b/media/base/mock_ffmpeg.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -65,7 +65,8 @@ class MockFFmpeg {
// Used for verifying check points during tests.
MOCK_METHOD1(CheckPoint, void(int id));
- // Returns the current MockFFmpeg instance.
+ // Setter/getter for the global instance of MockFFmpeg.
+ static void set(MockFFmpeg* instance);
static MockFFmpeg* get();
// Returns the URLProtocol registered by the FFmpegGlue singleton.