OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
19 #include "media/base/gmock_callback_support.h" | 20 #include "media/base/gmock_callback_support.h" |
20 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
| 22 #include "media/base/media_log.h" |
21 #include "media/base/media_util.h" | 23 #include "media/base/media_util.h" |
22 #include "media/base/mock_filters.h" | 24 #include "media/base/mock_filters.h" |
| 25 #include "media/base/mock_media_log.h" |
23 #include "media/base/test_data_util.h" | 26 #include "media/base/test_data_util.h" |
24 #include "media/base/test_helpers.h" | 27 #include "media/base/test_helpers.h" |
25 #include "media/base/video_decoder.h" | 28 #include "media/base/video_decoder.h" |
26 #include "media/base/video_frame.h" | 29 #include "media/base/video_frame.h" |
27 #include "media/base/video_util.h" | 30 #include "media/base/video_util.h" |
28 #include "media/ffmpeg/ffmpeg_common.h" | 31 #include "media/ffmpeg/ffmpeg_common.h" |
29 #include "media/filters/ffmpeg_glue.h" | 32 #include "media/filters/ffmpeg_glue.h" |
30 #include "media/filters/ffmpeg_video_decoder.h" | 33 #include "media/filters/ffmpeg_video_decoder.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
32 | 35 |
(...skipping 10 matching lines...) Expand all Loading... |
43 | 46 |
44 static const VideoPixelFormat kVideoFormat = PIXEL_FORMAT_YV12; | 47 static const VideoPixelFormat kVideoFormat = PIXEL_FORMAT_YV12; |
45 static const gfx::Size kCodedSize(320, 240); | 48 static const gfx::Size kCodedSize(320, 240); |
46 static const gfx::Rect kVisibleRect(320, 240); | 49 static const gfx::Rect kVisibleRect(320, 240); |
47 static const gfx::Size kNaturalSize(320, 240); | 50 static const gfx::Size kNaturalSize(320, 240); |
48 | 51 |
49 ACTION_P(ReturnBuffer, buffer) { | 52 ACTION_P(ReturnBuffer, buffer) { |
50 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); | 53 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); |
51 } | 54 } |
52 | 55 |
| 56 MATCHER(ContainsInvalidDataLog, "") { |
| 57 return CONTAINS_STRING(arg, "Invalid data"); |
| 58 } |
| 59 |
53 class FFmpegVideoDecoderTest : public testing::Test { | 60 class FFmpegVideoDecoderTest : public testing::Test { |
54 public: | 61 public: |
55 FFmpegVideoDecoderTest() | 62 FFmpegVideoDecoderTest() |
56 : decoder_(new FFmpegVideoDecoder()), | 63 : media_log_(new StrictMock<MockMediaLog>()), |
| 64 decoder_(new FFmpegVideoDecoder(media_log_)), |
57 decode_cb_(base::Bind(&FFmpegVideoDecoderTest::DecodeDone, | 65 decode_cb_(base::Bind(&FFmpegVideoDecoderTest::DecodeDone, |
58 base::Unretained(this))) { | 66 base::Unretained(this))) { |
59 FFmpegGlue::InitializeFFmpeg(); | 67 FFmpegGlue::InitializeFFmpeg(); |
60 | 68 |
61 // Initialize various test buffers. | 69 // Initialize various test buffers. |
62 frame_buffer_.reset(new uint8_t[kCodedSize.GetArea()]); | 70 frame_buffer_.reset(new uint8_t[kCodedSize.GetArea()]); |
63 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer(); | 71 end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer(); |
64 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240"); | 72 i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240"); |
65 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame"); | 73 corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame"); |
66 } | 74 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return status; | 198 return status; |
191 } | 199 } |
192 | 200 |
193 void FrameReady(const scoped_refptr<VideoFrame>& frame) { | 201 void FrameReady(const scoped_refptr<VideoFrame>& frame) { |
194 DCHECK(!frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); | 202 DCHECK(!frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); |
195 output_frames_.push_back(frame); | 203 output_frames_.push_back(frame); |
196 } | 204 } |
197 | 205 |
198 MOCK_METHOD1(DecodeDone, void(DecodeStatus)); | 206 MOCK_METHOD1(DecodeDone, void(DecodeStatus)); |
199 | 207 |
| 208 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
| 209 |
200 base::MessageLoop message_loop_; | 210 base::MessageLoop message_loop_; |
201 std::unique_ptr<FFmpegVideoDecoder> decoder_; | 211 std::unique_ptr<FFmpegVideoDecoder> decoder_; |
202 | 212 |
203 VideoDecoder::DecodeCB decode_cb_; | 213 VideoDecoder::DecodeCB decode_cb_; |
204 | 214 |
205 // Various buffers for testing. | 215 // Various buffers for testing. |
206 std::unique_ptr<uint8_t[]> frame_buffer_; | 216 std::unique_ptr<uint8_t[]> frame_buffer_; |
207 scoped_refptr<DecoderBuffer> end_of_stream_buffer_; | 217 scoped_refptr<DecoderBuffer> end_of_stream_buffer_; |
208 scoped_refptr<DecoderBuffer> i_frame_buffer_; | 218 scoped_refptr<DecoderBuffer> i_frame_buffer_; |
209 scoped_refptr<DecoderBuffer> corrupt_i_frame_buffer_; | 219 scoped_refptr<DecoderBuffer> corrupt_i_frame_buffer_; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 278 |
269 DecodeStatus status = DecodeMultipleFrames(input_buffers); | 279 DecodeStatus status = DecodeMultipleFrames(input_buffers); |
270 | 280 |
271 EXPECT_EQ(DecodeStatus::OK, status); | 281 EXPECT_EQ(DecodeStatus::OK, status); |
272 ASSERT_EQ(2U, output_frames_.size()); | 282 ASSERT_EQ(2U, output_frames_.size()); |
273 } | 283 } |
274 | 284 |
275 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeError) { | 285 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeError) { |
276 Initialize(); | 286 Initialize(); |
277 | 287 |
| 288 EXPECT_MEDIA_LOG(ContainsInvalidDataLog()); |
| 289 |
278 // The error is only raised on the second decode attempt, so we expect at | 290 // The error is only raised on the second decode attempt, so we expect at |
279 // least one successful decode but we don't expect valid frame to be decoded. | 291 // least one successful decode but we don't expect valid frame to be decoded. |
280 // During the second decode attempt an error is raised. | 292 // During the second decode attempt an error is raised. |
281 EXPECT_EQ(DecodeStatus::OK, Decode(corrupt_i_frame_buffer_)); | 293 EXPECT_EQ(DecodeStatus::OK, Decode(corrupt_i_frame_buffer_)); |
282 EXPECT_TRUE(output_frames_.empty()); | 294 EXPECT_TRUE(output_frames_.empty()); |
283 EXPECT_EQ(DecodeStatus::DECODE_ERROR, Decode(i_frame_buffer_)); | 295 EXPECT_EQ(DecodeStatus::DECODE_ERROR, Decode(i_frame_buffer_)); |
284 EXPECT_TRUE(output_frames_.empty()); | 296 EXPECT_TRUE(output_frames_.empty()); |
285 | 297 |
286 // After a decode error occurred, all following decodes will return | 298 // After a decode error occurred, all following decodes will return |
287 // DecodeStatus::DECODE_ERROR. | 299 // DecodeStatus::DECODE_ERROR. |
288 EXPECT_EQ(DecodeStatus::DECODE_ERROR, Decode(i_frame_buffer_)); | 300 EXPECT_EQ(DecodeStatus::DECODE_ERROR, Decode(i_frame_buffer_)); |
289 EXPECT_TRUE(output_frames_.empty()); | 301 EXPECT_TRUE(output_frames_.empty()); |
290 } | 302 } |
291 | 303 |
292 // A corrupt frame followed by an EOS buffer should raise a decode error. | 304 // A corrupt frame followed by an EOS buffer should raise a decode error. |
293 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeErrorAtEndOfStream) { | 305 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_DecodeErrorAtEndOfStream) { |
294 Initialize(); | 306 Initialize(); |
295 | 307 |
| 308 EXPECT_MEDIA_LOG(ContainsInvalidDataLog()); |
| 309 |
296 EXPECT_EQ(DecodeStatus::DECODE_ERROR, | 310 EXPECT_EQ(DecodeStatus::DECODE_ERROR, |
297 DecodeSingleFrame(corrupt_i_frame_buffer_)); | 311 DecodeSingleFrame(corrupt_i_frame_buffer_)); |
298 } | 312 } |
299 | 313 |
300 // Decode |i_frame_buffer_| and then a frame with a larger width and verify | 314 // Decode |i_frame_buffer_| and then a frame with a larger width and verify |
301 // the output size was adjusted. | 315 // the output size was adjusted. |
302 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerWidth) { | 316 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_LargerWidth) { |
303 DecodeIFrameThenTestFile("vp8-I-frame-640x240", 640, 240); | 317 DecodeIFrameThenTestFile("vp8-I-frame-640x240", 640, 240); |
304 } | 318 } |
305 | 319 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 371 |
358 // Test destruction when decoder has hit end of stream. | 372 // Test destruction when decoder has hit end of stream. |
359 TEST_F(FFmpegVideoDecoderTest, Destroy_EndOfStream) { | 373 TEST_F(FFmpegVideoDecoderTest, Destroy_EndOfStream) { |
360 Initialize(); | 374 Initialize(); |
361 EnterDecodingState(); | 375 EnterDecodingState(); |
362 EnterEndOfStreamState(); | 376 EnterEndOfStreamState(); |
363 Destroy(); | 377 Destroy(); |
364 } | 378 } |
365 | 379 |
366 } // namespace media | 380 } // namespace media |
OLD | NEW |