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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « media/base/mock_ffmpeg.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/mock_ffmpeg.h" 5 #include "media/base/mock_ffmpeg.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/filters/ffmpeg_common.h" 8 #include "media/filters/ffmpeg_common.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 MockFFmpeg* MockFFmpeg::instance_ = NULL; 12 MockFFmpeg* MockFFmpeg::instance_ = NULL;
13 13
14 MockFFmpeg::MockFFmpeg()
15 : outstanding_packets_(0) {
16 }
17
18 MockFFmpeg::~MockFFmpeg() {
19 CHECK(!outstanding_packets_)
20 << "MockFFmpeg destroyed with outstanding packets";
21 }
22
23 void MockFFmpeg::inc_outstanding_packets() {
24 ++outstanding_packets_;
25 }
26
27 void MockFFmpeg::dec_outstanding_packets() {
28 CHECK(outstanding_packets_ > 0);
29 --outstanding_packets_;
30 }
31
14 // static 32 // static
15 void MockFFmpeg::set(MockFFmpeg* instance) { 33 void MockFFmpeg::set(MockFFmpeg* instance) {
16 instance_ = instance; 34 instance_ = instance;
17 } 35 }
18 36
19 // static 37 // static
20 MockFFmpeg* MockFFmpeg::get() { 38 MockFFmpeg* MockFFmpeg::get() {
21 return instance_; 39 return instance_;
22 } 40 }
23 41
42 // static
43 void MockFFmpeg::DestructPacket(AVPacket* packet) {
44 delete [] packet->data;
45 packet->data = NULL;
46 packet->size = 0;
47 }
48
24 // FFmpeg stubs that delegate to the FFmpegMock instance. 49 // FFmpeg stubs that delegate to the FFmpegMock instance.
25 extern "C" { 50 extern "C" {
26 51
27 AVCodec* avcodec_find_decoder(enum CodecID id) { 52 AVCodec* avcodec_find_decoder(enum CodecID id) {
28 return media::MockFFmpeg::get()->AVCodecFindDecoder(id); 53 return media::MockFFmpeg::get()->AVCodecFindDecoder(id);
29 } 54 }
30 55
31 int avcodec_open(AVCodecContext* avctx, AVCodec* codec) { 56 int avcodec_open(AVCodecContext* avctx, AVCodec* codec) {
32 return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec); 57 return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec);
33 } 58 }
(...skipping 14 matching lines...) Expand all
48 int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture, 73 int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture,
49 int* got_picture_ptr, AVPacket* avpkt) { 74 int* got_picture_ptr, AVPacket* avpkt) {
50 NOTREACHED(); 75 NOTREACHED();
51 return 0; 76 return 0;
52 } 77 }
53 78
54 void av_init_packet(AVPacket* pkt) { 79 void av_init_packet(AVPacket* pkt) {
55 NOTREACHED(); 80 NOTREACHED();
56 } 81 }
57 82
83 int av_open_input_file(AVFormatContext** format, const char* filename,
84 AVInputFormat* input_format, int buffer_size,
85 AVFormatParameters* parameters) {
86 return media::MockFFmpeg::get()->AVOpenInputFile(format, filename,
87 input_format, buffer_size,
88 parameters);
89 }
90
91 int av_find_stream_info(AVFormatContext* format) {
92 return media::MockFFmpeg::get()->AVFindStreamInfo(format);
93 }
94
95 int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) {
96 // Because this is a math function there's little point in mocking it, so we
97 // implement a cheap version that's capable of overflowing.
98 int64 num = bq.num * cq.den;
99 int64 den = cq.num * bq.den;
100 return a * num / den;
101 }
102
103 void av_free_packet(AVPacket* packet) {
104 media::MockFFmpeg::get()->AVFreePacket(packet);
105 }
106
107 int av_new_packet(AVPacket* packet, int size) {
108 return media::MockFFmpeg::get()->AVNewPacket(packet, size);
109 }
110
111 void av_free(void* ptr) {
112 // Freeing NULL pointers are valid, but they aren't interesting from a mock
113 // perspective.
114 if (ptr) {
115 media::MockFFmpeg::get()->AVFree(ptr);
116 }
117 }
118
119 int av_read_frame(AVFormatContext* format, AVPacket* packet) {
120 return media::MockFFmpeg::get()->AVReadFrame(format, packet);
121 }
122
123 int av_seek_frame(AVFormatContext *format, int stream_index, int64_t timestamp,
124 int flags) {
125 return media::MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp,
126 flags);
127 }
128
58 } // extern "C" 129 } // extern "C"
59 130
60 } // namespace media 131 } // namespace media
OLDNEW
« 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