| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 FFmpegDemuxerTest() { | 66 FFmpegDemuxerTest() { |
| 67 // Create an FFmpegDemuxer. | 67 // Create an FFmpegDemuxer. |
| 68 demuxer_ = new FFmpegDemuxer(&message_loop_); | 68 demuxer_ = new FFmpegDemuxer(&message_loop_); |
| 69 DCHECK(demuxer_); | 69 DCHECK(demuxer_); |
| 70 | 70 |
| 71 // Inject a filter host and message loop and prepare a data source. | 71 // Inject a filter host and message loop and prepare a data source. |
| 72 demuxer_->set_host(&host_); | 72 demuxer_->set_host(&host_); |
| 73 data_source_ = new StrictMock<MockDataSource>(); | 73 data_source_ = new StrictMock<MockDataSource>(); |
| 74 | 74 |
| 75 EXPECT_CALL(*data_source_, Stop(NotNull())) |
| 76 .WillRepeatedly(Invoke(&RunStopFilterCallback)); |
| 77 |
| 75 // Initialize FFmpeg fixtures. | 78 // Initialize FFmpeg fixtures. |
| 76 memset(&format_context_, 0, sizeof(format_context_)); | 79 memset(&format_context_, 0, sizeof(format_context_)); |
| 77 memset(&input_format_, 0, sizeof(input_format_)); | 80 memset(&input_format_, 0, sizeof(input_format_)); |
| 78 memset(&streams_, 0, sizeof(streams_)); | 81 memset(&streams_, 0, sizeof(streams_)); |
| 79 memset(&codecs_, 0, sizeof(codecs_)); | 82 memset(&codecs_, 0, sizeof(codecs_)); |
| 80 | 83 |
| 81 // Initialize AVCodecContext structures. | 84 // Initialize AVCodecContext structures. |
| 82 codecs_[AV_STREAM_DATA].codec_type = CODEC_TYPE_DATA; | 85 codecs_[AV_STREAM_DATA].codec_type = CODEC_TYPE_DATA; |
| 83 codecs_[AV_STREAM_DATA].codec_id = CODEC_ID_NONE; | 86 codecs_[AV_STREAM_DATA].codec_id = CODEC_ID_NONE; |
| 84 | 87 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // Initializes both MockFFmpeg and FFmpegDemuxer. | 133 // Initializes both MockFFmpeg and FFmpegDemuxer. |
| 131 void InitializeDemuxer() { | 134 void InitializeDemuxer() { |
| 132 InitializeDemuxerMocks(); | 135 InitializeDemuxerMocks(); |
| 133 | 136 |
| 134 // Since we ignore data streams, the duration should be equal to the longest | 137 // Since we ignore data streams, the duration should be equal to the longest |
| 135 // supported stream's duration (audio, in this case). | 138 // supported stream's duration (audio, in this case). |
| 136 base::TimeDelta expected_duration = | 139 base::TimeDelta expected_duration = |
| 137 base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]); | 140 base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]); |
| 138 EXPECT_CALL(host_, SetDuration(expected_duration)); | 141 EXPECT_CALL(host_, SetDuration(expected_duration)); |
| 139 | 142 |
| 140 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 143 demuxer_->Initialize(data_source_.get(), |
| 144 NewExpectedStatusCallback(PIPELINE_OK)); |
| 141 message_loop_.RunAllPending(); | 145 message_loop_.RunAllPending(); |
| 142 } | 146 } |
| 143 | 147 |
| 144 // Fixture members. | 148 // Fixture members. |
| 145 scoped_refptr<FFmpegDemuxer> demuxer_; | 149 scoped_refptr<FFmpegDemuxer> demuxer_; |
| 146 scoped_refptr<StrictMock<MockDataSource> > data_source_; | 150 scoped_refptr<StrictMock<MockDataSource> > data_source_; |
| 147 StrictMock<MockFilterHost> host_; | 151 StrictMock<MockFilterHost> host_; |
| 148 MessageLoop message_loop_; | 152 MessageLoop message_loop_; |
| 149 | 153 |
| 150 // FFmpeg fixtures. | 154 // FFmpeg fixtures. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 168 | 172 |
| 169 const size_t FFmpegDemuxerTest::kDataSize = 4; | 173 const size_t FFmpegDemuxerTest::kDataSize = 4; |
| 170 const uint8 FFmpegDemuxerTest::kAudioData[kDataSize] = {0, 1, 2, 3}; | 174 const uint8 FFmpegDemuxerTest::kAudioData[kDataSize] = {0, 1, 2, 3}; |
| 171 const uint8 FFmpegDemuxerTest::kVideoData[kDataSize] = {4, 5, 6, 7}; | 175 const uint8 FFmpegDemuxerTest::kVideoData[kDataSize] = {4, 5, 6, 7}; |
| 172 const uint8* FFmpegDemuxerTest::kNullData = NULL; | 176 const uint8* FFmpegDemuxerTest::kNullData = NULL; |
| 173 | 177 |
| 174 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { | 178 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { |
| 175 // Simulate av_open_input_file() failing. | 179 // Simulate av_open_input_file() failing. |
| 176 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 180 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
| 177 .WillOnce(Return(-1)); | 181 .WillOnce(Return(-1)); |
| 178 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_OPEN)); | |
| 179 | 182 |
| 180 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 183 demuxer_->Initialize(data_source_.get(), |
| 184 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_OPEN)); |
| 181 message_loop_.RunAllPending(); | 185 message_loop_.RunAllPending(); |
| 182 } | 186 } |
| 183 | 187 |
| 184 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { | 188 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { |
| 185 // Simulate av_find_stream_info() failing. | 189 // Simulate av_find_stream_info() failing. |
| 186 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 190 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
| 187 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); | 191 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); |
| 188 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) | 192 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) |
| 189 .WillOnce(Return(AVERROR_IO)); | 193 .WillOnce(Return(AVERROR_IO)); |
| 190 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); | 194 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); |
| 191 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_PARSE)); | |
| 192 | 195 |
| 193 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 196 demuxer_->Initialize( |
| 197 data_source_.get(), |
| 198 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_PARSE)); |
| 194 message_loop_.RunAllPending(); | 199 message_loop_.RunAllPending(); |
| 195 } | 200 } |
| 196 | 201 |
| 197 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { | 202 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { |
| 198 // Simulate media with no parseable streams. | 203 // Simulate media with no parseable streams. |
| 199 { | 204 { |
| 200 SCOPED_TRACE(""); | 205 SCOPED_TRACE(""); |
| 201 InitializeDemuxerMocks(); | 206 InitializeDemuxerMocks(); |
| 202 } | 207 } |
| 203 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | |
| 204 format_context_.nb_streams = 0; | 208 format_context_.nb_streams = 0; |
| 205 | 209 |
| 206 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 210 demuxer_->Initialize( |
| 211 data_source_.get(), |
| 212 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
| 207 message_loop_.RunAllPending(); | 213 message_loop_.RunAllPending(); |
| 208 } | 214 } |
| 209 | 215 |
| 210 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { | 216 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { |
| 211 // Simulate media with a data stream but no audio or video streams. | 217 // Simulate media with a data stream but no audio or video streams. |
| 212 { | 218 { |
| 213 SCOPED_TRACE(""); | 219 SCOPED_TRACE(""); |
| 214 InitializeDemuxerMocks(); | 220 InitializeDemuxerMocks(); |
| 215 } | 221 } |
| 216 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | |
| 217 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); | 222 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); |
| 218 format_context_.nb_streams = 1; | 223 format_context_.nb_streams = 1; |
| 219 | 224 |
| 220 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 225 demuxer_->Initialize( |
| 226 data_source_.get(), |
| 227 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
| 221 message_loop_.RunAllPending(); | 228 message_loop_.RunAllPending(); |
| 222 } | 229 } |
| 223 | 230 |
| 224 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { | 231 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { |
| 225 { | 232 { |
| 226 SCOPED_TRACE(""); | 233 SCOPED_TRACE(""); |
| 227 InitializeDemuxer(); | 234 InitializeDemuxer(); |
| 228 } | 235 } |
| 229 | 236 |
| 230 // Verify that our demuxer streams were created from our AVStream structures. | 237 // Verify that our demuxer streams were created from our AVStream structures. |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 553 |
| 547 // Create our mocked callback. The demuxer will take ownership of this | 554 // Create our mocked callback. The demuxer will take ownership of this |
| 548 // pointer. | 555 // pointer. |
| 549 scoped_ptr<StrictMock<MockReadCallback> > callback( | 556 scoped_ptr<StrictMock<MockReadCallback> > callback( |
| 550 new StrictMock<MockReadCallback>()); | 557 new StrictMock<MockReadCallback>()); |
| 551 | 558 |
| 552 // Get our stream. | 559 // Get our stream. |
| 553 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO); | 560 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO); |
| 554 ASSERT_TRUE(audio); | 561 ASSERT_TRUE(audio); |
| 555 | 562 |
| 556 // Stop the demuxer. | 563 // Stop the demuxer, overriding the default expectation to assert that |
| 564 // data_source_ really is Stop()'d. |
| 565 EXPECT_CALL(*data_source_, Stop(_)) |
| 566 .WillOnce(Invoke(&RunStopFilterCallback)) |
| 567 .RetiresOnSaturation(); |
| 557 demuxer_->Stop(NewExpectedCallback()); | 568 demuxer_->Stop(NewExpectedCallback()); |
| 558 | 569 |
| 559 // Expect all calls in sequence. | 570 // Expect all calls in sequence. |
| 560 InSequence s; | 571 InSequence s; |
| 561 | 572 |
| 562 // The callback should be immediately deleted. We'll use a checkpoint to | 573 // The callback should be immediately deleted. We'll use a checkpoint to |
| 563 // verify that it has indeed been deleted. | 574 // verify that it has indeed been deleted. |
| 564 EXPECT_CALL(*callback, OnDelete()); | 575 EXPECT_CALL(*callback, OnDelete()); |
| 565 EXPECT_CALL(mock_ffmpeg_, CheckPoint(1)); | 576 EXPECT_CALL(mock_ffmpeg_, CheckPoint(1)); |
| 566 | 577 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 { | 740 { |
| 730 SCOPED_TRACE(""); | 741 SCOPED_TRACE(""); |
| 731 InitializeDemuxer(); | 742 InitializeDemuxer(); |
| 732 } | 743 } |
| 733 EXPECT_CALL(*data_source_, IsStreaming()) | 744 EXPECT_CALL(*data_source_, IsStreaming()) |
| 734 .WillOnce(Return(false)); | 745 .WillOnce(Return(false)); |
| 735 EXPECT_FALSE(demuxer_->IsStreaming()); | 746 EXPECT_FALSE(demuxer_->IsStreaming()); |
| 736 } | 747 } |
| 737 | 748 |
| 738 } // namespace media | 749 } // namespace media |
| OLD | NEW |