Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
| 8 #include "media/base/filters.h" | 8 #include "media/base/filters.h" |
| 9 #include "media/base/mock_callback.h" | 9 #include "media/base/mock_callback.h" |
| 10 #include "media/base/mock_ffmpeg.h" | 10 #include "media/base/mock_ffmpeg.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 EXPECT_CALL(*data_source_, Stop(NotNull())) | 75 EXPECT_CALL(*data_source_, Stop(NotNull())) |
| 76 .WillRepeatedly(Invoke(&RunStopFilterCallback)); | 76 .WillRepeatedly(Invoke(&RunStopFilterCallback)); |
| 77 | 77 |
| 78 // Initialize FFmpeg fixtures. | 78 // Initialize FFmpeg fixtures. |
| 79 memset(&format_context_, 0, sizeof(format_context_)); | 79 memset(&format_context_, 0, sizeof(format_context_)); |
| 80 memset(&input_format_, 0, sizeof(input_format_)); | 80 memset(&input_format_, 0, sizeof(input_format_)); |
| 81 memset(&streams_, 0, sizeof(streams_)); | 81 memset(&streams_, 0, sizeof(streams_)); |
| 82 memset(&codecs_, 0, sizeof(codecs_)); | 82 memset(&codecs_, 0, sizeof(codecs_)); |
| 83 | 83 |
| 84 // Initialize AVCodecContext structures. | 84 // Initialize AVCodecContext structures. |
| 85 codecs_[AV_STREAM_DATA].codec_type = CODEC_TYPE_DATA; | 85 codecs_[AV_STREAM_DATA].codec_type = AVMEDIA_TYPE_DATA; |
| 86 codecs_[AV_STREAM_DATA].codec_id = CODEC_ID_NONE; | 86 codecs_[AV_STREAM_DATA].codec_id = CODEC_ID_NONE; |
| 87 | 87 |
| 88 codecs_[AV_STREAM_VIDEO].codec_type = CODEC_TYPE_VIDEO; | 88 codecs_[AV_STREAM_VIDEO].codec_type = AVMEDIA_TYPE_VIDEO; |
| 89 codecs_[AV_STREAM_VIDEO].codec_id = CODEC_ID_THEORA; | 89 codecs_[AV_STREAM_VIDEO].codec_id = CODEC_ID_THEORA; |
| 90 codecs_[AV_STREAM_VIDEO].width = kWidth; | 90 codecs_[AV_STREAM_VIDEO].width = kWidth; |
| 91 codecs_[AV_STREAM_VIDEO].height = kHeight; | 91 codecs_[AV_STREAM_VIDEO].height = kHeight; |
| 92 | 92 |
| 93 codecs_[AV_STREAM_AUDIO].codec_type = CODEC_TYPE_AUDIO; | 93 codecs_[AV_STREAM_AUDIO].codec_type = AVMEDIA_TYPE_AUDIO; |
| 94 codecs_[AV_STREAM_AUDIO].codec_id = CODEC_ID_VORBIS; | 94 codecs_[AV_STREAM_AUDIO].codec_id = CODEC_ID_VORBIS; |
| 95 codecs_[AV_STREAM_AUDIO].channels = kChannels; | 95 codecs_[AV_STREAM_AUDIO].channels = kChannels; |
| 96 codecs_[AV_STREAM_AUDIO].sample_rate = kSampleRate; | 96 codecs_[AV_STREAM_AUDIO].sample_rate = kSampleRate; |
| 97 | 97 |
| 98 input_format_.name = "foo"; | 98 input_format_.name = "foo"; |
| 99 format_context_.iformat = &input_format_; | 99 format_context_.iformat = &input_format_; |
| 100 | 100 |
| 101 // Initialize AVStream and AVFormatContext structures. We set the time base | 101 // Initialize AVStream and AVFormatContext structures. We set the time base |
| 102 // of the streams such that duration is reported in microseconds. | 102 // of the streams such that duration is reported in microseconds. |
| 103 format_context_.nb_streams = AV_STREAM_MAX; | 103 format_context_.nb_streams = AV_STREAM_MAX; |
| 104 format_context_.streams = new AVStream*[AV_STREAM_MAX]; | |
| 105 // should probably be the line below but it crashes inside of av_malloc | |
| 106 // format_context_.streams = reinterpret_cast<AVStream **>( | |
| 107 // av_malloc(sizeof(AVStream *) * AV_STREAM_MAX)); | |
|
scherkus (not reviewing)
2011/06/29 17:00:36
this is because media_unittests doesn't load the r
ilja
2011/06/29 21:40:05
Done.
| |
| 104 for (size_t i = 0; i < AV_STREAM_MAX; ++i) { | 108 for (size_t i = 0; i < AV_STREAM_MAX; ++i) { |
| 105 format_context_.streams[i] = &streams_[i]; | 109 format_context_.streams[i] = &streams_[i]; |
| 106 streams_[i].codec = &codecs_[i]; | 110 streams_[i].codec = &codecs_[i]; |
| 107 streams_[i].duration = kDurations[i]; | 111 streams_[i].duration = kDurations[i]; |
| 108 streams_[i].time_base.den = 1 * base::Time::kMicrosecondsPerSecond; | 112 streams_[i].time_base.den = 1 * base::Time::kMicrosecondsPerSecond; |
| 109 streams_[i].time_base.num = 1; | 113 streams_[i].time_base.num = 1; |
| 110 } | 114 } |
| 111 } | 115 } |
| 112 | 116 |
| 113 virtual ~FFmpegDemuxerTest() { | 117 virtual ~FFmpegDemuxerTest() { |
| 114 // Call Stop() to shut down internal threads. | 118 // Call Stop() to shut down internal threads. |
| 115 demuxer_->Stop(NewExpectedCallback()); | 119 demuxer_->Stop(NewExpectedCallback()); |
| 116 | 120 |
| 117 // Finish up any remaining tasks. | 121 // Finish up any remaining tasks. |
| 118 message_loop_.RunAllPending(); | 122 message_loop_.RunAllPending(); |
| 119 | |
| 120 // Release the reference to the demuxer. | 123 // Release the reference to the demuxer. |
| 121 demuxer_ = NULL; | 124 demuxer_ = NULL; |
| 122 } | 125 } |
| 123 | 126 |
| 124 // Sets up MockFFmpeg to allow FFmpegDemuxer to successfully initialize. | 127 // Sets up MockFFmpeg to allow FFmpegDemuxer to successfully initialize. |
| 125 void InitializeDemuxerMocks() { | 128 void InitializeDemuxerMocks() { |
| 126 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 129 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
| 127 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); | 130 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); |
| 128 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) | 131 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) |
| 129 .WillOnce(Return(0)); | 132 .WillOnce(Return(0)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 demuxer_->Initialize(data_source_.get(), | 186 demuxer_->Initialize(data_source_.get(), |
| 184 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_OPEN)); | 187 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_OPEN)); |
| 185 message_loop_.RunAllPending(); | 188 message_loop_.RunAllPending(); |
| 186 } | 189 } |
| 187 | 190 |
| 188 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { | 191 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { |
| 189 // Simulate av_find_stream_info() failing. | 192 // Simulate av_find_stream_info() failing. |
| 190 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 193 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
| 191 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); | 194 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); |
| 192 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) | 195 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) |
| 193 .WillOnce(Return(AVERROR_IO)); | 196 .WillOnce(Return(AVERROR(EIO))); |
| 194 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); | 197 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); |
| 195 | 198 |
| 196 demuxer_->Initialize( | 199 demuxer_->Initialize( |
| 197 data_source_.get(), | 200 data_source_.get(), |
| 198 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_PARSE)); | 201 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_PARSE)); |
| 199 message_loop_.RunAllPending(); | 202 message_loop_.RunAllPending(); |
| 200 } | 203 } |
| 201 | 204 |
| 202 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { | 205 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { |
| 203 // Simulate media with no parseable streams. | 206 // Simulate media with no parseable streams. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 | 262 |
| 260 // Ignore all AVFreePacket() calls. We check this elsewhere. | 263 // Ignore all AVFreePacket() calls. We check this elsewhere. |
| 261 EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); | 264 EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); |
| 262 | 265 |
| 263 // The demuxer will read a data packet which will get immediately freed, | 266 // The demuxer will read a data packet which will get immediately freed, |
| 264 // followed by a read error to end the reading. | 267 // followed by a read error to end the reading. |
| 265 InSequence s; | 268 InSequence s; |
| 266 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) | 269 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) |
| 267 .WillOnce(CreatePacketNoCount(AV_STREAM_DATA, kNullData, 0)); | 270 .WillOnce(CreatePacketNoCount(AV_STREAM_DATA, kNullData, 0)); |
| 268 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) | 271 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) |
| 269 .WillOnce(Return(AVERROR_IO)); | 272 .WillOnce(Return(AVERROR(EIO))); |
| 270 | 273 |
| 271 // Attempt a read from the audio stream and run the message loop until done. | 274 // Attempt a read from the audio stream and run the message loop until done. |
| 272 scoped_refptr<DemuxerStream> audio = | 275 scoped_refptr<DemuxerStream> audio = |
| 273 demuxer_->GetStream(DemuxerStream::AUDIO); | 276 demuxer_->GetStream(DemuxerStream::AUDIO); |
| 274 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); | 277 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); |
| 275 reader->Read(audio); | 278 reader->Read(audio); |
| 276 message_loop_.RunAllPending(); | 279 message_loop_.RunAllPending(); |
| 277 | 280 |
| 278 EXPECT_TRUE(reader->called()); | 281 EXPECT_TRUE(reader->called()); |
| 279 ASSERT_TRUE(reader->buffer()); | 282 ASSERT_TRUE(reader->buffer()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 // indeed inserted. | 470 // indeed inserted. |
| 468 { | 471 { |
| 469 SCOPED_TRACE(""); | 472 SCOPED_TRACE(""); |
| 470 InitializeDemuxer(); | 473 InitializeDemuxer(); |
| 471 } | 474 } |
| 472 | 475 |
| 473 // Ignore all AVFreePacket() calls. We check this via valgrind. | 476 // Ignore all AVFreePacket() calls. We check this via valgrind. |
| 474 EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); | 477 EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); |
| 475 | 478 |
| 476 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) | 479 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) |
| 477 .WillOnce(Return(AVERROR_IO)); | 480 .WillOnce(Return(AVERROR(EIO))); |
| 478 | 481 |
| 479 // We should now expect an end of stream buffer. | 482 // We should now expect an end of stream buffer. |
| 480 scoped_refptr<DemuxerStream> audio = | 483 scoped_refptr<DemuxerStream> audio = |
| 481 demuxer_->GetStream(DemuxerStream::AUDIO); | 484 demuxer_->GetStream(DemuxerStream::AUDIO); |
| 482 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); | 485 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); |
| 483 reader->Read(audio); | 486 reader->Read(audio); |
| 484 message_loop_.RunAllPending(); | 487 message_loop_.RunAllPending(); |
| 485 EXPECT_TRUE(reader->called()); | 488 EXPECT_TRUE(reader->called()); |
| 486 ASSERT_TRUE(reader->buffer()); | 489 ASSERT_TRUE(reader->buffer()); |
| 487 EXPECT_TRUE(reader->buffer()->IsEndOfStream()); | 490 EXPECT_TRUE(reader->buffer()->IsEndOfStream()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 | 713 |
| 711 // Expect all calls in sequence. | 714 // Expect all calls in sequence. |
| 712 InSequence s; | 715 InSequence s; |
| 713 | 716 |
| 714 // The demuxer will read an audio packet which will get immediately freed. | 717 // The demuxer will read an audio packet which will get immediately freed. |
| 715 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) | 718 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) |
| 716 .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kNullData, 0)); | 719 .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kNullData, 0)); |
| 717 | 720 |
| 718 // Then an end-of-stream packet is read. | 721 // Then an end-of-stream packet is read. |
| 719 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) | 722 EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) |
| 720 .WillOnce(Return(AVERROR_IO)); | 723 .WillOnce(Return(AVERROR(EIO))); |
| 721 | 724 |
| 722 // Get our streams. | 725 // Get our streams. |
| 723 scoped_refptr<DemuxerStream> video = | 726 scoped_refptr<DemuxerStream> video = |
| 724 demuxer_->GetStream(DemuxerStream::VIDEO); | 727 demuxer_->GetStream(DemuxerStream::VIDEO); |
| 725 ASSERT_TRUE(video); | 728 ASSERT_TRUE(video); |
| 726 | 729 |
| 727 // Attempt a read from the video stream and run the message loop until done. | 730 // Attempt a read from the video stream and run the message loop until done. |
| 728 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); | 731 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); |
| 729 reader->Read(video); | 732 reader->Read(video); |
| 730 message_loop_.RunAllPending(); | 733 message_loop_.RunAllPending(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 { | 852 { |
| 850 SCOPED_TRACE(""); | 853 SCOPED_TRACE(""); |
| 851 InitializeDemuxer(); | 854 InitializeDemuxer(); |
| 852 } | 855 } |
| 853 EXPECT_CALL(*data_source_, IsStreaming()) | 856 EXPECT_CALL(*data_source_, IsStreaming()) |
| 854 .WillOnce(Return(false)); | 857 .WillOnce(Return(false)); |
| 855 EXPECT_FALSE(demuxer_->IsStreaming()); | 858 EXPECT_FALSE(demuxer_->IsStreaming()); |
| 856 } | 859 } |
| 857 | 860 |
| 858 } // namespace media | 861 } // namespace media |
| OLD | NEW |