summaryrefslogtreecommitdiffstats
path: root/media/base/mock_ffmpeg.h
diff options
context:
space:
mode:
Diffstat (limited to 'media/base/mock_ffmpeg.h')
-rw-r--r--media/base/mock_ffmpeg.h78
1 files changed, 77 insertions, 1 deletions
diff --git a/media/base/mock_ffmpeg.h b/media/base/mock_ffmpeg.h
index 711cf15..597898e 100644
--- a/media/base/mock_ffmpeg.h
+++ b/media/base/mock_ffmpeg.h
@@ -7,25 +7,101 @@
// TODO(scherkus): See if we can remove ffmpeg_common from this file.
#include "media/filters/ffmpeg_common.h"
-
#include "testing/gmock/include/gmock/gmock.h"
namespace media {
class MockFFmpeg {
public:
+ MockFFmpeg();
+ ~MockFFmpeg();
+
MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id));
MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec));
MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads));
+ MOCK_METHOD5(AVOpenInputFile, int(AVFormatContext** format,
+ const char* filename,
+ AVInputFormat* input_format,
+ int buffer_size,
+ AVFormatParameters* parameters));
+ MOCK_METHOD1(AVFindStreamInfo, int(AVFormatContext* format));
+ MOCK_METHOD2(AVReadFrame, int(AVFormatContext* format, AVPacket* packet));
+ MOCK_METHOD4(AVSeekFrame, int(AVFormatContext *format,
+ int stream_index,
+ int64_t timestamp,
+ int flags));
+
+ MOCK_METHOD2(AVNewPacket, int(AVPacket* packet, int size));
+ MOCK_METHOD1(AVFree, void(void* ptr));
+ MOCK_METHOD1(AVFreePacket, void(AVPacket* packet));
+
+ // Used for verifying check points during tests.
+ MOCK_METHOD1(CheckPoint, void(int id));
+
// Setter/getter for the global instance of MockFFmpeg.
static void set(MockFFmpeg* instance);
static MockFFmpeg* get();
+ // AVPacket destructor for packets allocated by av_new_packet().
+ static void DestructPacket(AVPacket* packet);
+
+ // Modifies the number of outstanding packets.
+ void inc_outstanding_packets();
+ void dec_outstanding_packets();
+
private:
static MockFFmpeg* instance_;
+
+ // Tracks the number of packets allocated by calls to av_read_frame() and
+ // av_free_packet(). We crash the unit test if this is not zero at time of
+ // destruction.
+ int outstanding_packets_;
};
+// Used for simulating av_read_frame().
+ACTION_P3(CreatePacket, stream_index, data, size) {
+ // Confirm we're dealing with AVPacket so we can safely const_cast<>.
+ ::testing::StaticAssertTypeEq<AVPacket*, arg1_type>();
+ memset(arg1, 0, sizeof(*arg1));
+ arg1->stream_index = stream_index;
+ arg1->data = const_cast<uint8*>(data);
+ arg1->size = size;
+
+ // Increment number of packets allocated.
+ MockFFmpeg::get()->inc_outstanding_packets();
+
+ return 0;
+}
+
+// Used for simulating av_new_packet().
+ACTION(NewPacket) {
+ ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>();
+ int size = arg1;
+ memset(arg0, 0, sizeof(*arg0));
+ arg0->data = new uint8[size];
+ arg0->size = size;
+ arg0->destruct = &MockFFmpeg::DestructPacket;
+
+ // Increment number of packets allocated.
+ MockFFmpeg::get()->inc_outstanding_packets();
+
+ return 0;
+}
+
+// Used for simulating av_free_packet().
+ACTION(FreePacket) {
+ ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>();
+
+ // Call the destructor if present, such as the one assigned in NewPacket().
+ if (arg0->destruct) {
+ arg0->destruct(arg0);
+ }
+
+ // Decrement number of packets allocated.
+ MockFFmpeg::get()->dec_outstanding_packets();
+}
+
} // namespace media
#endif // MEDIA_BASE_MOCK_FFMPEG_H_