Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: media/base/mock_ffmpeg.cc

Issue 126306: Refactor FFmpegDemuxerTest to use gmock and eliminate flakiness. (Closed)
Patch Set: Added SCOPED_TRACE Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/mock_ffmpeg.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/mock_ffmpeg.cc
diff --git a/media/base/mock_ffmpeg.cc b/media/base/mock_ffmpeg.cc
index 4e9fc03d8627d1c81146ca49c94334dfcae4a66e..b1de0c46505388419ed59275c31d158834546213 100644
--- a/media/base/mock_ffmpeg.cc
+++ b/media/base/mock_ffmpeg.cc
@@ -11,6 +11,24 @@ namespace media {
MockFFmpeg* MockFFmpeg::instance_ = NULL;
+MockFFmpeg::MockFFmpeg()
+ : outstanding_packets_(0) {
+}
+
+MockFFmpeg::~MockFFmpeg() {
+ CHECK(!outstanding_packets_)
+ << "MockFFmpeg destroyed with outstanding packets";
+}
+
+void MockFFmpeg::inc_outstanding_packets() {
+ ++outstanding_packets_;
+}
+
+void MockFFmpeg::dec_outstanding_packets() {
+ CHECK(outstanding_packets_ > 0);
+ --outstanding_packets_;
+}
+
// static
void MockFFmpeg::set(MockFFmpeg* instance) {
instance_ = instance;
@@ -21,6 +39,13 @@ MockFFmpeg* MockFFmpeg::get() {
return instance_;
}
+// static
+void MockFFmpeg::DestructPacket(AVPacket* packet) {
+ delete [] packet->data;
+ packet->data = NULL;
+ packet->size = 0;
+}
+
// FFmpeg stubs that delegate to the FFmpegMock instance.
extern "C" {
@@ -55,6 +80,52 @@ void av_init_packet(AVPacket* pkt) {
NOTREACHED();
}
+int av_open_input_file(AVFormatContext** format, const char* filename,
+ AVInputFormat* input_format, int buffer_size,
+ AVFormatParameters* parameters) {
+ return media::MockFFmpeg::get()->AVOpenInputFile(format, filename,
+ input_format, buffer_size,
+ parameters);
+}
+
+int av_find_stream_info(AVFormatContext* format) {
+ return media::MockFFmpeg::get()->AVFindStreamInfo(format);
+}
+
+int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) {
+ // Because this is a math function there's little point in mocking it, so we
+ // implement a cheap version that's capable of overflowing.
+ int64 num = bq.num * cq.den;
+ int64 den = cq.num * bq.den;
+ return a * num / den;
+}
+
+void av_free_packet(AVPacket* packet) {
+ media::MockFFmpeg::get()->AVFreePacket(packet);
+}
+
+int av_new_packet(AVPacket* packet, int size) {
+ return media::MockFFmpeg::get()->AVNewPacket(packet, size);
+}
+
+void av_free(void* ptr) {
+ // Freeing NULL pointers are valid, but they aren't interesting from a mock
+ // perspective.
+ if (ptr) {
+ media::MockFFmpeg::get()->AVFree(ptr);
+ }
+}
+
+int av_read_frame(AVFormatContext* format, AVPacket* packet) {
+ return media::MockFFmpeg::get()->AVReadFrame(format, packet);
+}
+
+int av_seek_frame(AVFormatContext *format, int stream_index, int64_t timestamp,
+ int flags) {
+ return media::MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp,
+ flags);
+}
+
} // extern "C"
} // namespace media
« no previous file with comments | « media/base/mock_ffmpeg.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698