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

Side by Side Diff: media/filters/ffmpeg_video_decoder_unittest.cc

Issue 10910293: Add is_encrypted() in VideoDecoderConfig. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve comments. Created 8 years, 3 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/filters/chunk_demuxer_unittest.cc ('k') | media/filters/gpu_video_decoder.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, 81 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >,
82 message_loop_.message_loop_proxy()), 82 message_loop_.message_loop_proxy()),
83 decryptor_.get()); 83 decryptor_.get());
84 84
85 // Initialize various test buffers. 85 // Initialize various test buffers.
86 frame_buffer_.reset(new uint8[kCodedSize.GetArea()]); 86 frame_buffer_.reset(new uint8[kCodedSize.GetArea()]);
87 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer(); 87 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer();
88 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240"); 88 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240");
89 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame"); 89 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame");
90 encrypted_i_frame_buffer_ = CreateFakeEncryptedBuffer(); 90 encrypted_i_frame_buffer_ = CreateFakeEncryptedBuffer();
91
92 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
93 kVideoFormat, kCodedSize, kVisibleRect, kNaturalSize,
94 NULL, 0, true);
95 } 91 }
96 92
97 virtual ~FFmpegVideoDecoderTest() {} 93 virtual ~FFmpegVideoDecoderTest() {}
98 94
99 void Initialize() { 95 void Initialize() {
96 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat,
97 kCodedSize, kVisibleRect, kNaturalSize,
98 NULL, 0, false, true);
100 InitializeWithConfig(config_); 99 InitializeWithConfig(config_);
101 } 100 }
102 101
102 void InitializeWithEncryptedConfig() {
103 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat,
104 kCodedSize, kVisibleRect, kNaturalSize,
105 NULL, 0, true, true);
106 InitializeWithConfig(config_);
107 }
108
103 void InitializeWithConfigAndStatus(const VideoDecoderConfig& config, 109 void InitializeWithConfigAndStatus(const VideoDecoderConfig& config,
104 PipelineStatus status) { 110 PipelineStatus status) {
105 EXPECT_CALL(*demuxer_, video_decoder_config()) 111 EXPECT_CALL(*demuxer_, video_decoder_config())
106 .WillRepeatedly(ReturnRef(config)); 112 .WillRepeatedly(ReturnRef(config));
107 113
108 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), 114 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status),
109 base::Bind(&MockStatisticsCB::OnStatistics, 115 base::Bind(&MockStatisticsCB::OnStatistics,
110 base::Unretained(&statistics_cb_))); 116 base::Unretained(&statistics_cb_)));
111 117
112 message_loop_.RunAllPending(); 118 message_loop_.RunAllPending();
(...skipping 13 matching lines...) Expand all
126 message_loop_.RunAllPending(); 132 message_loop_.RunAllPending();
127 } 133 }
128 134
129 // Sets up expectations and actions to put FFmpegVideoDecoder in an active 135 // Sets up expectations and actions to put FFmpegVideoDecoder in an active
130 // decoding state. 136 // decoding state.
131 void EnterDecodingState() { 137 void EnterDecodingState() {
132 VideoDecoder::Status status; 138 VideoDecoder::Status status;
133 scoped_refptr<VideoFrame> video_frame; 139 scoped_refptr<VideoFrame> video_frame;
134 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame); 140 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame);
135 141
136 EXPECT_EQ(status, VideoDecoder::kOk); 142 EXPECT_EQ(VideoDecoder::kOk, status);
xhwang 2012/09/17 19:42:25 Changed the order here since otherwise it gives fu
137 ASSERT_TRUE(video_frame); 143 ASSERT_TRUE(video_frame);
138 EXPECT_FALSE(video_frame->IsEndOfStream()); 144 EXPECT_FALSE(video_frame->IsEndOfStream());
139 } 145 }
140 146
141 // Sets up expectations and actions to put FFmpegVideoDecoder in an end 147 // Sets up expectations and actions to put FFmpegVideoDecoder in an end
142 // of stream state. 148 // of stream state.
143 void EnterEndOfStreamState() { 149 void EnterEndOfStreamState() {
144 scoped_refptr<VideoFrame> video_frame; 150 scoped_refptr<VideoFrame> video_frame;
145 VideoDecoder::Status status; 151 VideoDecoder::Status status;
146 Read(&status, &video_frame); 152 Read(&status, &video_frame);
147 EXPECT_EQ(status, VideoDecoder::kOk); 153 EXPECT_EQ(VideoDecoder::kOk, status);
148 ASSERT_TRUE(video_frame); 154 ASSERT_TRUE(video_frame);
149 EXPECT_TRUE(video_frame->IsEndOfStream()); 155 EXPECT_TRUE(video_frame->IsEndOfStream());
150 } 156 }
151 157
152 // Decodes the single compressed frame in |buffer| and writes the 158 // Decodes the single compressed frame in |buffer| and writes the
153 // uncompressed output to |video_frame|. This method works with single 159 // uncompressed output to |video_frame|. This method works with single
154 // and multithreaded decoders. End of stream buffers are used to trigger 160 // and multithreaded decoders. End of stream buffers are used to trigger
155 // the frame to be returned in the multithreaded decoder case. 161 // the frame to be returned in the multithreaded decoder case.
156 void DecodeSingleFrame(const scoped_refptr<DecoderBuffer>& buffer, 162 void DecodeSingleFrame(const scoped_refptr<DecoderBuffer>& buffer,
157 VideoDecoder::Status* status, 163 VideoDecoder::Status* status,
(...skipping 27 matching lines...) Expand all
185 .WillOnce(ReturnBuffer(buffer)) 191 .WillOnce(ReturnBuffer(buffer))
186 .WillRepeatedly(ReturnBuffer(end_of_stream_buffer_)); 192 .WillRepeatedly(ReturnBuffer(end_of_stream_buffer_));
187 193
188 EXPECT_CALL(statistics_cb_, OnStatistics(_)) 194 EXPECT_CALL(statistics_cb_, OnStatistics(_))
189 .Times(2); 195 .Times(2);
190 196
191 Read(&status_a, &video_frame_a); 197 Read(&status_a, &video_frame_a);
192 Read(&status_b, &video_frame_b); 198 Read(&status_b, &video_frame_b);
193 199
194 gfx::Size original_size = kVisibleRect.size(); 200 gfx::Size original_size = kVisibleRect.size();
195 EXPECT_EQ(status_a, VideoDecoder::kOk); 201 EXPECT_EQ(VideoDecoder::kOk, status_a);
196 EXPECT_EQ(status_b, VideoDecoder::kOk); 202 EXPECT_EQ(VideoDecoder::kOk, status_b);
197 ASSERT_TRUE(video_frame_a); 203 ASSERT_TRUE(video_frame_a);
198 ASSERT_TRUE(video_frame_b); 204 ASSERT_TRUE(video_frame_b);
199 EXPECT_EQ(original_size.width(), video_frame_a->data_size().width()); 205 EXPECT_EQ(original_size.width(), video_frame_a->data_size().width());
200 EXPECT_EQ(original_size.height(), video_frame_a->data_size().height()); 206 EXPECT_EQ(original_size.height(), video_frame_a->data_size().height());
201 EXPECT_EQ(expected_width, video_frame_b->data_size().width()); 207 EXPECT_EQ(expected_width, video_frame_b->data_size().width());
202 EXPECT_EQ(expected_height, video_frame_b->data_size().height()); 208 EXPECT_EQ(expected_height, video_frame_b->data_size().height());
203 } 209 }
204 210
205 void Read(VideoDecoder::Status* status, 211 void Read(VideoDecoder::Status* status,
206 scoped_refptr<VideoFrame>* video_frame) { 212 scoped_refptr<VideoFrame>* video_frame) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 246
241 TEST_F(FFmpegVideoDecoderTest, Initialize_Normal) { 247 TEST_F(FFmpegVideoDecoderTest, Initialize_Normal) {
242 Initialize(); 248 Initialize();
243 } 249 }
244 250
245 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedDecoder) { 251 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedDecoder) {
246 // Test avcodec_find_decoder() returning NULL. 252 // Test avcodec_find_decoder() returning NULL.
247 VideoDecoderConfig config(kUnknownVideoCodec, VIDEO_CODEC_PROFILE_UNKNOWN, 253 VideoDecoderConfig config(kUnknownVideoCodec, VIDEO_CODEC_PROFILE_UNKNOWN,
248 kVideoFormat, 254 kVideoFormat,
249 kCodedSize, kVisibleRect, kNaturalSize, 255 kCodedSize, kVisibleRect, kNaturalSize,
250 NULL, 0); 256 NULL, 0, false);
251 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 257 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
252 } 258 }
253 259
254 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) { 260 TEST_F(FFmpegVideoDecoderTest, Initialize_UnsupportedPixelFormat) {
255 // Ensure decoder handles unsupport pixel formats without crashing. 261 // Ensure decoder handles unsupport pixel formats without crashing.
256 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, 262 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
257 VideoFrame::INVALID, 263 VideoFrame::INVALID,
258 kCodedSize, kVisibleRect, kNaturalSize, 264 kCodedSize, kVisibleRect, kNaturalSize,
259 NULL, 0); 265 NULL, 0, false);
260 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 266 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
261 } 267 }
262 268
263 TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) { 269 TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) {
264 // Specify Theora w/o extra data so that avcodec_open2() fails. 270 // Specify Theora w/o extra data so that avcodec_open2() fails.
265 VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN, 271 VideoDecoderConfig config(kCodecTheora, VIDEO_CODEC_PROFILE_UNKNOWN,
266 kVideoFormat, 272 kVideoFormat,
267 kCodedSize, kVisibleRect, kNaturalSize, 273 kCodedSize, kVisibleRect, kNaturalSize,
268 NULL, 0); 274 NULL, 0, false);
269 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 275 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
270 } 276 }
271 277
272 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorZero) { 278 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorZero) {
273 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1); 279 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1);
274 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 280 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
275 kVideoFormat, 281 kVideoFormat,
276 kCodedSize, kVisibleRect, natural_size, 282 kCodedSize, kVisibleRect, natural_size,
277 NULL, 0); 283 NULL, 0, false);
278 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 284 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
279 } 285 }
280 286
281 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorZero) { 287 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorZero) {
282 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0); 288 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0);
283 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 289 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
284 kVideoFormat, 290 kVideoFormat,
285 kCodedSize, kVisibleRect, natural_size, 291 kCodedSize, kVisibleRect, natural_size,
286 NULL, 0); 292 NULL, 0, false);
287 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 293 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
288 } 294 }
289 295
290 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorNegative) { 296 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorNegative) {
291 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1); 297 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1);
292 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 298 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
293 kVideoFormat, 299 kVideoFormat,
294 kCodedSize, kVisibleRect, natural_size, 300 kCodedSize, kVisibleRect, natural_size,
295 NULL, 0); 301 NULL, 0, false);
296 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 302 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
297 } 303 }
298 304
299 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorNegative) { 305 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorNegative) {
300 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1); 306 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1);
301 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 307 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
302 kVideoFormat, 308 kVideoFormat,
303 kCodedSize, kVisibleRect, natural_size, 309 kCodedSize, kVisibleRect, natural_size,
304 NULL, 0); 310 NULL, 0, false);
305 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 311 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
306 } 312 }
307 313
308 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorTooLarge) { 314 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioNumeratorTooLarge) {
309 int width = kVisibleRect.size().width(); 315 int width = kVisibleRect.size().width();
310 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width); 316 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width);
311 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1); 317 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1);
312 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 318 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
313 kVideoFormat, 319 kVideoFormat,
314 kCodedSize, kVisibleRect, natural_size, 320 kCodedSize, kVisibleRect, natural_size,
315 NULL, 0); 321 NULL, 0, false);
316 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 322 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
317 } 323 }
318 324
319 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorTooLarge) { 325 TEST_F(FFmpegVideoDecoderTest, Initialize_AspectRatioDenominatorTooLarge) {
320 int den = kVisibleRect.size().width() + 1; 326 int den = kVisibleRect.size().width() + 1;
321 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den); 327 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den);
322 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN, 328 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_MAIN,
323 kVideoFormat, 329 kVideoFormat,
324 kCodedSize, kVisibleRect, natural_size, 330 kCodedSize, kVisibleRect, natural_size,
325 NULL, 0); 331 NULL, 0, false);
326 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE); 332 InitializeWithConfigAndStatus(config, PIPELINE_ERROR_DECODE);
327 } 333 }
328 334
329 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_Normal) { 335 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_Normal) {
330 Initialize(); 336 Initialize();
331 337
332 // Simulate decoding a single frame. 338 // Simulate decoding a single frame.
333 VideoDecoder::Status status; 339 VideoDecoder::Status status;
334 scoped_refptr<VideoFrame> video_frame; 340 scoped_refptr<VideoFrame> video_frame;
335 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame); 341 DecodeSingleFrame(i_frame_buffer_, &status, &video_frame);
336 342
337 EXPECT_EQ(status, VideoDecoder::kOk); 343 EXPECT_EQ(VideoDecoder::kOk, status);
338 ASSERT_TRUE(video_frame); 344 ASSERT_TRUE(video_frame);
339 EXPECT_FALSE(video_frame->IsEndOfStream()); 345 EXPECT_FALSE(video_frame->IsEndOfStream());
340 } 346 }
341 347
342 // Verify current behavior for 0 byte frames. FFmpeg simply ignores 348 // Verify current behavior for 0 byte frames. FFmpeg simply ignores
343 // the 0 byte frames. 349 // the 0 byte frames.
344 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_0ByteFrame) { 350 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_0ByteFrame) {
345 Initialize(); 351 Initialize();
346 352
347 scoped_refptr<DecoderBuffer> zero_byte_buffer = new DecoderBuffer(0); 353 scoped_refptr<DecoderBuffer> zero_byte_buffer = new DecoderBuffer(0);
(...skipping 11 matching lines...) Expand all
359 .WillOnce(ReturnBuffer(i_frame_buffer_)) 365 .WillOnce(ReturnBuffer(i_frame_buffer_))
360 .WillRepeatedly(ReturnBuffer(end_of_stream_buffer_)); 366 .WillRepeatedly(ReturnBuffer(end_of_stream_buffer_));
361 367
362 EXPECT_CALL(statistics_cb_, OnStatistics(_)) 368 EXPECT_CALL(statistics_cb_, OnStatistics(_))
363 .Times(2); 369 .Times(2);
364 370
365 Read(&status_a, &video_frame_a); 371 Read(&status_a, &video_frame_a);
366 Read(&status_b, &video_frame_b); 372 Read(&status_b, &video_frame_b);
367 Read(&status_c, &video_frame_c); 373 Read(&status_c, &video_frame_c);
368 374
369 EXPECT_EQ(status_a, VideoDecoder::kOk); 375 EXPECT_EQ(VideoDecoder::kOk, status_a);
370 EXPECT_EQ(status_b, VideoDecoder::kOk); 376 EXPECT_EQ(VideoDecoder::kOk, status_b);
371 EXPECT_EQ(status_c, VideoDecoder::kOk); 377 EXPECT_EQ(VideoDecoder::kOk, status_c);
372 378
373 ASSERT_TRUE(video_frame_a); 379 ASSERT_TRUE(video_frame_a);
374 ASSERT_TRUE(video_frame_b); 380 ASSERT_TRUE(video_frame_b);
375 ASSERT_TRUE(video_frame_c); 381 ASSERT_TRUE(video_frame_c);
376 382
377 EXPECT_FALSE(video_frame_a->IsEndOfStream()); 383 EXPECT_FALSE(video_frame_a->IsEndOfStream());
378 EXPECT_FALSE(video_frame_b->IsEndOfStream()); 384 EXPECT_FALSE(video_frame_b->IsEndOfStream());
379 EXPECT_TRUE(video_frame_c->IsEndOfStream()); 385 EXPECT_TRUE(video_frame_c->IsEndOfStream());
380 } 386 }
381 387
382 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeError) { 388 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeError) {
383 Initialize(); 389 Initialize();
384 390
385 EXPECT_CALL(*demuxer_, Read(_)) 391 EXPECT_CALL(*demuxer_, Read(_))
386 .WillOnce(ReturnBuffer(corrupt_i_frame_buffer_)) 392 .WillOnce(ReturnBuffer(corrupt_i_frame_buffer_))
387 .WillRepeatedly(ReturnBuffer(i_frame_buffer_)); 393 .WillRepeatedly(ReturnBuffer(i_frame_buffer_));
388 394
389 // The error is only raised on the second decode attempt, so we expect at 395 // The error is only raised on the second decode attempt, so we expect at
390 // least one successful decode but we don't expect FrameReady() to be 396 // least one successful decode but we don't expect FrameReady() to be
391 // executed as an error is raised instead. 397 // executed as an error is raised instead.
392 EXPECT_CALL(statistics_cb_, OnStatistics(_)); 398 EXPECT_CALL(statistics_cb_, OnStatistics(_));
393 399
394 // Our read should still get satisfied with end of stream frame during an 400 // Our read should still get satisfied with end of stream frame during an
395 // error. 401 // error.
396 VideoDecoder::Status status; 402 VideoDecoder::Status status;
397 scoped_refptr<VideoFrame> video_frame; 403 scoped_refptr<VideoFrame> video_frame;
398 Read(&status, &video_frame); 404 Read(&status, &video_frame);
399 EXPECT_EQ(status, VideoDecoder::kDecodeError); 405 EXPECT_EQ(VideoDecoder::kDecodeError, status);
400 EXPECT_FALSE(video_frame); 406 EXPECT_FALSE(video_frame);
401 407
402 message_loop_.RunAllPending(); 408 message_loop_.RunAllPending();
403 } 409 }
404 410
405 // Multi-threaded decoders have different behavior than single-threaded 411 // Multi-threaded decoders have different behavior than single-threaded
406 // decoders at the end of the stream. Multithreaded decoders hide errors 412 // decoders at the end of the stream. Multithreaded decoders hide errors
407 // that happen on the last |codec_context_->thread_count| frames to avoid 413 // that happen on the last |codec_context_->thread_count| frames to avoid
408 // prematurely signalling EOS. This test just exposes that behavior so we can 414 // prematurely signalling EOS. This test just exposes that behavior so we can
409 // detect if it changes. 415 // detect if it changes.
410 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeErrorAtEndOfStream) { 416 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeErrorAtEndOfStream) {
411 Initialize(); 417 Initialize();
412 418
413 VideoDecoder::Status status; 419 VideoDecoder::Status status;
414 scoped_refptr<VideoFrame> video_frame; 420 scoped_refptr<VideoFrame> video_frame;
415 DecodeSingleFrame(corrupt_i_frame_buffer_, &status, &video_frame); 421 DecodeSingleFrame(corrupt_i_frame_buffer_, &status, &video_frame);
416 422
417 EXPECT_EQ(status, VideoDecoder::kOk); 423 EXPECT_EQ(VideoDecoder::kOk, status);
418 ASSERT_TRUE(video_frame); 424 ASSERT_TRUE(video_frame);
419 EXPECT_TRUE(video_frame->IsEndOfStream()); 425 EXPECT_TRUE(video_frame->IsEndOfStream());
420 } 426 }
421 427
422 // Decode |i_frame_buffer_| and then a frame with a larger width and verify 428 // Decode |i_frame_buffer_| and then a frame with a larger width and verify
423 // the output size was adjusted. 429 // the output size was adjusted.
424 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerWidth) { 430 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerWidth) {
425 DecodeIFrameThenTestFile("vp8-I-frame-640x240", 640, 240); 431 DecodeIFrameThenTestFile("vp8-I-frame-640x240", 640, 240);
426 } 432 }
427 433
428 // Decode |i_frame_buffer_| and then a frame with a smaller width and verify 434 // Decode |i_frame_buffer_| and then a frame with a smaller width and verify
429 // the output size was adjusted. 435 // the output size was adjusted.
430 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerWidth) { 436 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerWidth) {
431 DecodeIFrameThenTestFile("vp8-I-frame-160x240", 160, 240); 437 DecodeIFrameThenTestFile("vp8-I-frame-160x240", 160, 240);
432 } 438 }
433 439
434 // Decode |i_frame_buffer_| and then a frame with a larger height and verify 440 // Decode |i_frame_buffer_| and then a frame with a larger height and verify
435 // the output size was adjusted. 441 // the output size was adjusted.
436 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerHeight) { 442 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerHeight) {
437 DecodeIFrameThenTestFile("vp8-I-frame-320x480", 320, 480); 443 DecodeIFrameThenTestFile("vp8-I-frame-320x480", 320, 480);
438 } 444 }
439 445
440 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify 446 // Decode |i_frame_buffer_| and then a frame with a smaller height and verify
441 // the output size was adjusted. 447 // the output size was adjusted.
442 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) { 448 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) {
443 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120); 449 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120);
444 } 450 }
445 451
446 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { 452 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) {
447 Initialize(); 453 InitializeWithEncryptedConfig();
448 454
449 // Simulate decoding a single encrypted frame. 455 // Simulate decoding a single encrypted frame.
450 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 456 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
451 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_)); 457 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_));
452 458
453 VideoDecoder::Status status; 459 VideoDecoder::Status status;
454 scoped_refptr<VideoFrame> video_frame; 460 scoped_refptr<VideoFrame> video_frame;
455 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame); 461 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame);
456 462
457 EXPECT_EQ(status, VideoDecoder::kOk); 463 EXPECT_EQ(VideoDecoder::kOk, status);
458 ASSERT_TRUE(video_frame); 464 ASSERT_TRUE(video_frame);
459 EXPECT_FALSE(video_frame->IsEndOfStream()); 465 EXPECT_FALSE(video_frame->IsEndOfStream());
460 } 466 }
461 467
462 // Test the case that the decryptor fails to decrypt the encrypted buffer. 468 // Test the case that the decryptor fails to decrypt the encrypted buffer.
463 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) { 469 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) {
464 Initialize(); 470 InitializeWithEncryptedConfig();
465 471
466 // Simulate decoding a single encrypted frame. 472 // Simulate decoding a single encrypted frame.
467 EXPECT_CALL(*demuxer_, Read(_)) 473 EXPECT_CALL(*demuxer_, Read(_))
468 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 474 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
469 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 475 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
470 .WillRepeatedly(RunDecryptCB(Decryptor::kError, 476 .WillRepeatedly(RunDecryptCB(Decryptor::kError,
471 scoped_refptr<media::DecoderBuffer>())); 477 scoped_refptr<media::DecoderBuffer>()));
472 478
473 // Our read should still get satisfied with end of stream frame during an 479 // Our read should still get satisfied with end of stream frame during an
474 // error. 480 // error.
475 VideoDecoder::Status status; 481 VideoDecoder::Status status;
476 scoped_refptr<VideoFrame> video_frame; 482 scoped_refptr<VideoFrame> video_frame;
477 Read(&status, &video_frame); 483 Read(&status, &video_frame);
478 EXPECT_EQ(VideoDecoder::kDecryptError, status); 484 EXPECT_EQ(VideoDecoder::kDecryptError, status);
479 EXPECT_FALSE(video_frame); 485 EXPECT_FALSE(video_frame);
480 486
481 message_loop_.RunAllPending(); 487 message_loop_.RunAllPending();
482 } 488 }
483 489
484 // Test the case that the decryptor has no key to decrypt the encrypted buffer. 490 // Test the case that the decryptor has no key to decrypt the encrypted buffer.
485 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) { 491 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) {
486 Initialize(); 492 InitializeWithEncryptedConfig();
487 493
488 // Simulate decoding a single encrypted frame. 494 // Simulate decoding a single encrypted frame.
489 EXPECT_CALL(*demuxer_, Read(_)) 495 EXPECT_CALL(*demuxer_, Read(_))
490 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 496 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
491 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 497 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
492 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, 498 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey,
493 scoped_refptr<media::DecoderBuffer>())); 499 scoped_refptr<media::DecoderBuffer>()));
494 500
495 // Our read should still get satisfied with end of stream frame during an 501 // Our read should still get satisfied with end of stream frame during an
496 // error. 502 // error.
497 VideoDecoder::Status status; 503 VideoDecoder::Status status;
498 scoped_refptr<VideoFrame> video_frame; 504 scoped_refptr<VideoFrame> video_frame;
499 Read(&status, &video_frame); 505 Read(&status, &video_frame);
500 EXPECT_EQ(VideoDecoder::kDecryptError, status); 506 EXPECT_EQ(VideoDecoder::kDecryptError, status);
501 EXPECT_FALSE(video_frame); 507 EXPECT_FALSE(video_frame);
502 508
503 message_loop_.RunAllPending(); 509 message_loop_.RunAllPending();
504 } 510 }
505 511
506 // Test the case that the decryptor fails to decrypt the encrypted buffer but 512 // Test the case that the decryptor fails to decrypt the encrypted buffer but
507 // cannot detect the decryption error and returns a corrupted buffer. 513 // cannot detect the decryption error and returns a corrupted buffer.
508 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) { 514 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) {
509 Initialize(); 515 InitializeWithEncryptedConfig();
510 516
511 // Simulate decoding a single encrypted frame. 517 // Simulate decoding a single encrypted frame.
512 EXPECT_CALL(*demuxer_, Read(_)) 518 EXPECT_CALL(*demuxer_, Read(_))
513 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 519 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
514 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _)) 520 EXPECT_CALL(*decryptor_, Decrypt(encrypted_i_frame_buffer_, _))
515 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, 521 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess,
516 corrupt_i_frame_buffer_)); 522 corrupt_i_frame_buffer_));
517 523
518 // Our read should still get satisfied with end of stream frame during an 524 // Our read should still get satisfied with end of stream frame during an
519 // error. 525 // error.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 Initialize(); 627 Initialize();
622 628
623 EXPECT_CALL(*demuxer_, Read(_)) 629 EXPECT_CALL(*demuxer_, Read(_))
624 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); 630 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>()));
625 631
626 VideoDecoder::Status status; 632 VideoDecoder::Status status;
627 scoped_refptr<VideoFrame> video_frame; 633 scoped_refptr<VideoFrame> video_frame;
628 634
629 Read(&status, &video_frame); 635 Read(&status, &video_frame);
630 636
631 EXPECT_EQ(status, VideoDecoder::kOk); 637 EXPECT_EQ(VideoDecoder::kOk, status);
632 EXPECT_FALSE(video_frame); 638 EXPECT_FALSE(video_frame);
633 } 639 }
634 640
635 // Test aborted read on the demuxer stream. 641 // Test aborted read on the demuxer stream.
636 TEST_F(FFmpegVideoDecoderTest, AbortPendingReadDuringFlush) { 642 TEST_F(FFmpegVideoDecoderTest, AbortPendingReadDuringFlush) {
637 Initialize(); 643 Initialize();
638 644
639 DemuxerStream::ReadCB read_cb; 645 DemuxerStream::ReadCB read_cb;
640 646
641 // Request a read on the decoder and run the MessageLoop to 647 // Request a read on the decoder and run the MessageLoop to
(...skipping 10 matching lines...) Expand all
652 658
653 // Signal an aborted demuxer read. 659 // Signal an aborted demuxer read.
654 read_cb.Run(DemuxerStream::kAborted, NULL); 660 read_cb.Run(DemuxerStream::kAborted, NULL);
655 661
656 // Make sure we get a NULL video frame returned. 662 // Make sure we get a NULL video frame returned.
657 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 663 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
658 message_loop_.RunAllPending(); 664 message_loop_.RunAllPending();
659 } 665 }
660 666
661 } // namespace media 667 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer_unittest.cc ('k') | media/filters/gpu_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698