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

Side by Side Diff: media/video/ffmpeg_video_decode_engine_unittest.cc

Issue 6539021: Move MockFFmpeg instance setting into the constructor/destructor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « media/media.gyp ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 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 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "media/base/data_buffer.h" 7 #include "media/base/data_buffer.h"
8 #include "media/base/mock_ffmpeg.h" 8 #include "media/base/mock_ffmpeg.h"
9 #include "media/base/mock_task.h" 9 #include "media/base/mock_task.h"
10 #include "media/base/pipeline.h" 10 #include "media/base/pipeline.h"
11 #include "media/video/ffmpeg_video_decode_engine.h" 11 #include "media/video/ffmpeg_video_decode_engine.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 codec_context_.time_base = kTimeBase; 61 codec_context_.time_base = kTimeBase;
62 62
63 memset(&codec_, 0, sizeof(codec_)); 63 memset(&codec_, 0, sizeof(codec_));
64 memset(&stream_, 0, sizeof(stream_)); 64 memset(&stream_, 0, sizeof(stream_));
65 stream_.codec = &codec_context_; 65 stream_.codec = &codec_context_;
66 stream_.r_frame_rate.num = kTimeBase.den; 66 stream_.r_frame_rate.num = kTimeBase.den;
67 stream_.r_frame_rate.den = kTimeBase.num; 67 stream_.r_frame_rate.den = kTimeBase.num;
68 68
69 buffer_ = new DataBuffer(1); 69 buffer_ = new DataBuffer(1);
70 70
71 // Initialize MockFFmpeg.
72 MockFFmpeg::set(&mock_ffmpeg_);
73
74 test_engine_.reset(new FFmpegVideoDecodeEngine()); 71 test_engine_.reset(new FFmpegVideoDecodeEngine());
75 test_engine_->SetCodecContextForTest(&codec_context_); 72 test_engine_->SetCodecContextForTest(&codec_context_);
76 73
77 VideoFrame::CreateFrame(VideoFrame::YV12, 74 VideoFrame::CreateFrame(VideoFrame::YV12,
78 kWidth, 75 kWidth,
79 kHeight, 76 kHeight,
80 kNoTimestamp, 77 kNoTimestamp,
81 kNoTimestamp, 78 kNoTimestamp,
82 &video_frame_); 79 &video_frame_);
83 } 80 }
84 81
85 ~FFmpegVideoDecodeEngineTest() { 82 ~FFmpegVideoDecodeEngineTest() {
86 test_engine_.reset(); 83 test_engine_.reset();
87 MockFFmpeg::set(NULL);
88 } 84 }
89 85
90 void Initialize() { 86 void Initialize() {
91 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) 87 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE))
92 .WillOnce(Return(&codec_)); 88 .WillOnce(Return(&codec_));
93 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) 89 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame())
94 .WillOnce(Return(&yuv_frame_)); 90 .WillOnce(Return(&yuv_frame_));
95 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) 91 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2))
96 .WillOnce(Return(0)); 92 .WillOnce(Return(0));
97 EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) 93 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_))
98 .WillOnce(Return(0)); 94 .WillOnce(Return(0));
99 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) 95 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_))
100 .Times(1); 96 .Times(1);
101 97
102 config_.codec = kCodecH264; 98 config_.codec = kCodecH264;
103 config_.opaque_context = &stream_; 99 config_.opaque_context = &stream_;
104 config_.width = kWidth; 100 config_.width = kWidth;
105 config_.height = kHeight; 101 config_.height = kHeight;
106 EXPECT_CALL(*this, OnInitializeComplete(_)) 102 EXPECT_CALL(*this, OnInitializeComplete(_))
107 .WillOnce(SaveInitializeResult(this)); 103 .WillOnce(SaveInitializeResult(this));
108 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); 104 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_);
109 EXPECT_TRUE(info_.success); 105 EXPECT_TRUE(info_.success);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scoped_refptr<DataBuffer> buffer_; 155 scoped_refptr<DataBuffer> buffer_;
160 156
161 }; 157 };
162 158
163 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { 159 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) {
164 Initialize(); 160 Initialize();
165 } 161 }
166 162
167 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { 163 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) {
168 // Test avcodec_find_decoder() returning NULL. 164 // Test avcodec_find_decoder() returning NULL.
169 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) 165 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE))
170 .WillOnce(ReturnNull()); 166 .WillOnce(ReturnNull());
171 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) 167 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame())
172 .WillOnce(Return(&yuv_frame_)); 168 .WillOnce(Return(&yuv_frame_));
173 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) 169 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_))
174 .Times(1); 170 .Times(1);
175 171
176 config_.codec = kCodecH264; 172 config_.codec = kCodecH264;
177 config_.opaque_context = &stream_; 173 config_.opaque_context = &stream_;
178 config_.width = kWidth; 174 config_.width = kWidth;
179 config_.height = kHeight; 175 config_.height = kHeight;
180 EXPECT_CALL(*this, OnInitializeComplete(_)) 176 EXPECT_CALL(*this, OnInitializeComplete(_))
181 .WillOnce(SaveInitializeResult(this)); 177 .WillOnce(SaveInitializeResult(this));
182 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); 178 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_);
183 EXPECT_FALSE(info_.success); 179 EXPECT_FALSE(info_.success);
184 } 180 }
185 181
186 // Note There are 2 threads for FFmpeg-mt. 182 // Note There are 2 threads for FFmpeg-mt.
187 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { 183 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) {
188 // Test avcodec_thread_init() failing. 184 // Test avcodec_thread_init() failing.
189 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) 185 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE))
190 .WillOnce(Return(&codec_)); 186 .WillOnce(Return(&codec_));
191 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) 187 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame())
192 .WillOnce(Return(&yuv_frame_)); 188 .WillOnce(Return(&yuv_frame_));
193 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) 189 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2))
194 .WillOnce(Return(-1)); 190 .WillOnce(Return(-1));
195 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) 191 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_))
196 .Times(1); 192 .Times(1);
197 193
198 config_.codec = kCodecH264; 194 config_.codec = kCodecH264;
199 config_.opaque_context = &stream_; 195 config_.opaque_context = &stream_;
200 config_.width = kWidth; 196 config_.width = kWidth;
201 config_.height = kHeight; 197 config_.height = kHeight;
202 EXPECT_CALL(*this, OnInitializeComplete(_)) 198 EXPECT_CALL(*this, OnInitializeComplete(_))
203 .WillOnce(SaveInitializeResult(this)); 199 .WillOnce(SaveInitializeResult(this));
204 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); 200 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_);
205 EXPECT_FALSE(info_.success); 201 EXPECT_FALSE(info_.success);
206 } 202 }
207 203
208 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { 204 TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) {
209 // Test avcodec_open() failing. 205 // Test avcodec_open() failing.
210 EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) 206 EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE))
211 .WillOnce(Return(&codec_)); 207 .WillOnce(Return(&codec_));
212 EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) 208 EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame())
213 .WillOnce(Return(&yuv_frame_)); 209 .WillOnce(Return(&yuv_frame_));
214 EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) 210 EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2))
215 .WillOnce(Return(0)); 211 .WillOnce(Return(0));
216 EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) 212 EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_))
217 .WillOnce(Return(-1)); 213 .WillOnce(Return(-1));
218 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) 214 EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_))
219 .Times(1); 215 .Times(1);
220 216
221 config_.codec = kCodecH264; 217 config_.codec = kCodecH264;
222 config_.opaque_context = &stream_; 218 config_.opaque_context = &stream_;
223 config_.width = kWidth; 219 config_.width = kWidth;
224 config_.height = kHeight; 220 config_.height = kHeight;
225 EXPECT_CALL(*this, OnInitializeComplete(_)) 221 EXPECT_CALL(*this, OnInitializeComplete(_))
226 .WillOnce(SaveInitializeResult(this)); 222 .WillOnce(SaveInitializeResult(this));
227 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_); 223 test_engine_->Initialize(MessageLoop::current(), this, NULL, config_);
228 EXPECT_FALSE(info_.success); 224 EXPECT_FALSE(info_.success);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); 321 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat());
326 codec_context_.pix_fmt = PIX_FMT_YUVJ422P; 322 codec_context_.pix_fmt = PIX_FMT_YUVJ422P;
327 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat()); 323 EXPECT_EQ(VideoFrame::YV16, test_engine_->GetSurfaceFormat());
328 324
329 // Invalid value. 325 // Invalid value.
330 codec_context_.pix_fmt = PIX_FMT_NONE; 326 codec_context_.pix_fmt = PIX_FMT_NONE;
331 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat()); 327 EXPECT_EQ(VideoFrame::INVALID, test_engine_->GetSurfaceFormat());
332 } 328 }
333 329
334 } // namespace media 330 } // namespace media
OLDNEW
« no previous file with comments | « media/media.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698