OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_BASE_MOCK_FFMPEG_H_ | |
6 #define MEDIA_BASE_MOCK_FFMPEG_H_ | |
7 | |
8 // TODO(scherkus): See if we can remove ffmpeg_common from this file. | |
9 #include "media/ffmpeg/ffmpeg_common.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 | |
12 namespace media { | |
13 | |
14 class MockFFmpeg { | |
15 public: | |
16 MockFFmpeg(); | |
17 virtual ~MockFFmpeg(); | |
18 | |
19 // TODO(ajwong): Organize this class, and make sure that all mock entrypoints | |
20 // are still used. | |
21 MOCK_METHOD0(AVCodecInit, void()); | |
22 MOCK_METHOD2(AVRegisterProtocol2, int(URLProtocol* protocol, int size)); | |
23 MOCK_METHOD0(AVRegisterAll, void()); | |
24 MOCK_METHOD1(AVRegisterLockManager, int(int (*cb)(void**, enum AVLockOp))); | |
25 | |
26 MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id)); | |
27 MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec)); | |
28 MOCK_METHOD1(AVCodecClose, int(AVCodecContext* avctx)); | |
29 MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads)); | |
30 MOCK_METHOD1(AVCodecFlushBuffers, void(AVCodecContext* avctx)); | |
31 MOCK_METHOD0(AVCodecAllocContext, AVCodecContext*()); | |
32 MOCK_METHOD0(AVCodecAllocFrame, AVFrame*()); | |
33 MOCK_METHOD4(AVCodecDecodeVideo2, | |
34 int(AVCodecContext* avctx, AVFrame* picture, | |
35 int* got_picture_ptr, AVPacket* avpkt)); | |
36 MOCK_METHOD1(AVBitstreamFilterInit, | |
37 AVBitStreamFilterContext*(const char *name)); | |
38 MOCK_METHOD8(AVBitstreamFilterFilter, | |
39 int(AVBitStreamFilterContext* bsfc, AVCodecContext* avctx, | |
40 const char* args, uint8_t** poutbuf, int* poutbuf_size, | |
41 const uint8_t* buf, int buf_size, int keyframe)); | |
42 MOCK_METHOD1(AVBitstreamFilterClose, void(AVBitStreamFilterContext* bsf)); | |
43 MOCK_METHOD1(AVDestructPacket, void(AVPacket* packet)); | |
44 | |
45 MOCK_METHOD5(AVOpenInputFile, int(AVFormatContext** format, | |
46 const char* filename, | |
47 AVInputFormat* input_format, | |
48 int buffer_size, | |
49 AVFormatParameters* parameters)); | |
50 MOCK_METHOD1(AVCloseInputFile, void(AVFormatContext* format)); | |
51 MOCK_METHOD1(AVFindStreamInfo, int(AVFormatContext* format)); | |
52 MOCK_METHOD2(AVReadFrame, int(AVFormatContext* format, AVPacket* packet)); | |
53 MOCK_METHOD4(AVSeekFrame, int(AVFormatContext *format, | |
54 int stream_index, | |
55 int64_t timestamp, | |
56 int flags)); | |
57 | |
58 MOCK_METHOD1(AVInitPacket, void(AVPacket* pkt)); | |
59 MOCK_METHOD2(AVNewPacket, int(AVPacket* packet, int size)); | |
60 MOCK_METHOD1(AVFreePacket, void(AVPacket* packet)); | |
61 MOCK_METHOD1(AVFree, void(void* ptr)); | |
62 MOCK_METHOD1(AVDupPacket, int(AVPacket* packet)); | |
63 | |
64 MOCK_METHOD1(AVLogSetLevel, void(int level)); | |
65 | |
66 // Used for verifying check points during tests. | |
67 MOCK_METHOD1(CheckPoint, void(int id)); | |
68 | |
69 // Returns the current MockFFmpeg instance. | |
70 static MockFFmpeg* get(); | |
71 | |
72 // Returns the URLProtocol registered by the FFmpegGlue singleton. | |
73 static URLProtocol* protocol(); | |
74 | |
75 // AVPacket destructor for packets allocated by av_new_packet(). | |
76 static void DestructPacket(AVPacket* packet); | |
77 | |
78 // Modifies the number of outstanding packets. | |
79 void inc_outstanding_packets(); | |
80 void dec_outstanding_packets(); | |
81 | |
82 private: | |
83 static MockFFmpeg* instance_; | |
84 static URLProtocol* protocol_; | |
85 | |
86 // Tracks the number of packets allocated by calls to av_read_frame() and | |
87 // av_free_packet(). We crash the unit test if this is not zero at time of | |
88 // destruction. | |
89 int outstanding_packets_; | |
90 }; | |
91 | |
92 // Used for simulating av_read_frame(). | |
93 ACTION_P3(CreatePacket, stream_index, data, size) { | |
94 // Confirm we're dealing with AVPacket so we can safely const_cast<>. | |
95 ::testing::StaticAssertTypeEq<AVPacket*, arg1_type>(); | |
96 memset(arg1, 0, sizeof(*arg1)); | |
97 arg1->stream_index = stream_index; | |
98 arg1->data = const_cast<uint8*>(data); | |
99 arg1->size = size; | |
100 | |
101 // Increment number of packets allocated. | |
102 MockFFmpeg::get()->inc_outstanding_packets(); | |
103 | |
104 return 0; | |
105 } | |
106 | |
107 // Used for simulating av_read_frame(). | |
108 ACTION_P3(CreatePacketNoCount, stream_index, data, size) { | |
109 // Confirm we're dealing with AVPacket so we can safely const_cast<>. | |
110 ::testing::StaticAssertTypeEq<AVPacket*, arg1_type>(); | |
111 memset(arg1, 0, sizeof(*arg1)); | |
112 arg1->stream_index = stream_index; | |
113 arg1->data = const_cast<uint8*>(data); | |
114 arg1->size = size; | |
115 | |
116 return 0; | |
117 } | |
118 | |
119 // Used for simulating av_read_frame(). | |
120 ACTION_P4(CreatePacketTimeNoCount, stream_index, data, size, pts) { | |
121 // Confirm we're dealing with AVPacket so we can safely const_cast<>. | |
122 ::testing::StaticAssertTypeEq<AVPacket*, arg1_type>(); | |
123 memset(arg1, 0, sizeof(*arg1)); | |
124 arg1->stream_index = stream_index; | |
125 arg1->data = const_cast<uint8*>(data); | |
126 arg1->size = size; | |
127 arg1->pts = pts; | |
128 | |
129 return 0; | |
130 } | |
131 | |
132 // Used for simulating av_new_packet(). | |
133 ACTION(NewPacket) { | |
134 ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>(); | |
135 int size = arg1; | |
136 memset(arg0, 0, sizeof(*arg0)); | |
137 arg0->data = new uint8[size]; | |
138 arg0->size = size; | |
139 arg0->destruct = &MockFFmpeg::DestructPacket; | |
140 | |
141 // Increment number of packets allocated. | |
142 MockFFmpeg::get()->inc_outstanding_packets(); | |
143 | |
144 return 0; | |
145 } | |
146 | |
147 // Used for simulating av_free_packet(). | |
148 ACTION(FreePacket) { | |
149 ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>(); | |
150 | |
151 // Call the destructor if present, such as the one assigned in NewPacket(). | |
152 if (arg0->destruct) { | |
153 arg0->destruct(arg0); | |
154 } | |
155 | |
156 // Decrement number of packets allocated. | |
157 MockFFmpeg::get()->dec_outstanding_packets(); | |
158 } | |
159 | |
160 } // namespace media | |
161 | |
162 #endif // MEDIA_BASE_MOCK_FFMPEG_H_ | |
OLD | NEW |