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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Initializes both MockFFmpeg and FFmpegDemuxer. | 130 // Initializes both MockFFmpeg and FFmpegDemuxer. |
131 void InitializeDemuxer() { | 131 void InitializeDemuxer() { |
132 InitializeDemuxerMocks(); | 132 InitializeDemuxerMocks(); |
133 | 133 |
134 // Since we ignore data streams, the duration should be equal to the longest | 134 // Since we ignore data streams, the duration should be equal to the longest |
135 // supported stream's duration (audio, in this case). | 135 // supported stream's duration (audio, in this case). |
136 base::TimeDelta expected_duration = | 136 base::TimeDelta expected_duration = |
137 base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]); | 137 base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]); |
138 EXPECT_CALL(host_, SetDuration(expected_duration)); | 138 EXPECT_CALL(host_, SetDuration(expected_duration)); |
139 | 139 |
140 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 140 demuxer_->Initialize(data_source_.get(), |
| 141 NewExpectedStatusCallback(PIPELINE_OK)); |
141 message_loop_.RunAllPending(); | 142 message_loop_.RunAllPending(); |
142 } | 143 } |
143 | 144 |
144 // Fixture members. | 145 // Fixture members. |
145 scoped_refptr<FFmpegDemuxer> demuxer_; | 146 scoped_refptr<FFmpegDemuxer> demuxer_; |
146 scoped_refptr<StrictMock<MockDataSource> > data_source_; | 147 scoped_refptr<StrictMock<MockDataSource> > data_source_; |
147 StrictMock<MockFilterHost> host_; | 148 StrictMock<MockFilterHost> host_; |
148 MessageLoop message_loop_; | 149 MessageLoop message_loop_; |
149 | 150 |
150 // FFmpeg fixtures. | 151 // FFmpeg fixtures. |
(...skipping 17 matching lines...) Expand all Loading... |
168 | 169 |
169 const size_t FFmpegDemuxerTest::kDataSize = 4; | 170 const size_t FFmpegDemuxerTest::kDataSize = 4; |
170 const uint8 FFmpegDemuxerTest::kAudioData[kDataSize] = {0, 1, 2, 3}; | 171 const uint8 FFmpegDemuxerTest::kAudioData[kDataSize] = {0, 1, 2, 3}; |
171 const uint8 FFmpegDemuxerTest::kVideoData[kDataSize] = {4, 5, 6, 7}; | 172 const uint8 FFmpegDemuxerTest::kVideoData[kDataSize] = {4, 5, 6, 7}; |
172 const uint8* FFmpegDemuxerTest::kNullData = NULL; | 173 const uint8* FFmpegDemuxerTest::kNullData = NULL; |
173 | 174 |
174 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { | 175 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { |
175 // Simulate av_open_input_file() failing. | 176 // Simulate av_open_input_file() failing. |
176 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 177 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
177 .WillOnce(Return(-1)); | 178 .WillOnce(Return(-1)); |
178 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_OPEN)); | |
179 | 179 |
180 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 180 demuxer_->Initialize(data_source_.get(), |
| 181 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_OPEN)); |
181 message_loop_.RunAllPending(); | 182 message_loop_.RunAllPending(); |
182 } | 183 } |
183 | 184 |
184 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { | 185 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { |
185 // Simulate av_find_stream_info() failing. | 186 // Simulate av_find_stream_info() failing. |
186 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) | 187 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) |
187 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); | 188 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); |
188 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) | 189 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) |
189 .WillOnce(Return(AVERROR_IO)); | 190 .WillOnce(Return(AVERROR_IO)); |
190 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); | 191 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); |
191 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_PARSE)); | |
192 | 192 |
193 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 193 demuxer_->Initialize(data_source_.get(), |
| 194 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_PARSE))
; |
194 message_loop_.RunAllPending(); | 195 message_loop_.RunAllPending(); |
195 } | 196 } |
196 | 197 |
197 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { | 198 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { |
198 // Simulate media with no parseable streams. | 199 // Simulate media with no parseable streams. |
199 { | 200 { |
200 SCOPED_TRACE(""); | 201 SCOPED_TRACE(""); |
201 InitializeDemuxerMocks(); | 202 InitializeDemuxerMocks(); |
202 } | 203 } |
203 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | |
204 format_context_.nb_streams = 0; | 204 format_context_.nb_streams = 0; |
205 | 205 |
206 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 206 demuxer_->Initialize( |
| 207 data_source_.get(), |
| 208 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
207 message_loop_.RunAllPending(); | 209 message_loop_.RunAllPending(); |
208 } | 210 } |
209 | 211 |
210 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { | 212 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { |
211 // Simulate media with a data stream but no audio or video streams. | 213 // Simulate media with a data stream but no audio or video streams. |
212 { | 214 { |
213 SCOPED_TRACE(""); | 215 SCOPED_TRACE(""); |
214 InitializeDemuxerMocks(); | 216 InitializeDemuxerMocks(); |
215 } | 217 } |
216 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | |
217 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); | 218 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); |
218 format_context_.nb_streams = 1; | 219 format_context_.nb_streams = 1; |
219 | 220 |
220 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); | 221 demuxer_->Initialize( |
| 222 data_source_.get(), |
| 223 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
221 message_loop_.RunAllPending(); | 224 message_loop_.RunAllPending(); |
222 } | 225 } |
223 | 226 |
224 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { | 227 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { |
225 { | 228 { |
226 SCOPED_TRACE(""); | 229 SCOPED_TRACE(""); |
227 InitializeDemuxer(); | 230 InitializeDemuxer(); |
228 } | 231 } |
229 | 232 |
230 // Verify that our demuxer streams were created from our AVStream structures. | 233 // Verify that our demuxer streams were created from our AVStream structures. |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 { | 732 { |
730 SCOPED_TRACE(""); | 733 SCOPED_TRACE(""); |
731 InitializeDemuxer(); | 734 InitializeDemuxer(); |
732 } | 735 } |
733 EXPECT_CALL(*data_source_, IsStreaming()) | 736 EXPECT_CALL(*data_source_, IsStreaming()) |
734 .WillOnce(Return(false)); | 737 .WillOnce(Return(false)); |
735 EXPECT_FALSE(demuxer_->IsStreaming()); | 738 EXPECT_FALSE(demuxer_->IsStreaming()); |
736 } | 739 } |
737 | 740 |
738 } // namespace media | 741 } // namespace media |
OLD | NEW |