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

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

Issue 6648004: DemuxerFactory is born! (Closed)
Patch Set: Clean up changes to ffmpeg_demuxer_unittest a bit. Created 9 years, 9 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
OLDNEW
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
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
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
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(data_source_.get(),
197 NewExpectedStatusCallback(DEMUXER_ERROR_COULD_NOT_PARSE)) ;
scherkus (not reviewing) 2011/03/11 21:46:58 >80 chars
Ami GONE FROM CHROMIUM 2011/03/11 22:18:46 Done.
194 message_loop_.RunAllPending(); 198 message_loop_.RunAllPending();
195 } 199 }
196 200
197 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 201 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
198 // Simulate media with no parseable streams. 202 // Simulate media with no parseable streams.
199 { 203 {
200 SCOPED_TRACE(""); 204 SCOPED_TRACE("");
201 InitializeDemuxerMocks(); 205 InitializeDemuxerMocks();
202 } 206 }
203 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
204 format_context_.nb_streams = 0; 207 format_context_.nb_streams = 0;
205 208
206 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); 209 demuxer_->Initialize(
210 data_source_.get(),
211 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
207 message_loop_.RunAllPending(); 212 message_loop_.RunAllPending();
208 } 213 }
209 214
210 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { 215 TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) {
211 // Simulate media with a data stream but no audio or video streams. 216 // Simulate media with a data stream but no audio or video streams.
212 { 217 {
213 SCOPED_TRACE(""); 218 SCOPED_TRACE("");
214 InitializeDemuxerMocks(); 219 InitializeDemuxerMocks();
215 } 220 }
216 EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
217 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); 221 EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]);
218 format_context_.nb_streams = 1; 222 format_context_.nb_streams = 1;
219 223
220 demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); 224 demuxer_->Initialize(
225 data_source_.get(),
226 NewExpectedStatusCallback(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
221 message_loop_.RunAllPending(); 227 message_loop_.RunAllPending();
222 } 228 }
223 229
224 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { 230 TEST_F(FFmpegDemuxerTest, Initialize_Successful) {
225 { 231 {
226 SCOPED_TRACE(""); 232 SCOPED_TRACE("");
227 InitializeDemuxer(); 233 InitializeDemuxer();
228 } 234 }
229 235
230 // Verify that our demuxer streams were created from our AVStream structures. 236 // Verify that our demuxer streams were created from our AVStream structures.
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 552
547 // Create our mocked callback. The demuxer will take ownership of this 553 // Create our mocked callback. The demuxer will take ownership of this
548 // pointer. 554 // pointer.
549 scoped_ptr<StrictMock<MockReadCallback> > callback( 555 scoped_ptr<StrictMock<MockReadCallback> > callback(
550 new StrictMock<MockReadCallback>()); 556 new StrictMock<MockReadCallback>());
551 557
552 // Get our stream. 558 // Get our stream.
553 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO); 559 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO);
554 ASSERT_TRUE(audio); 560 ASSERT_TRUE(audio);
555 561
556 // Stop the demuxer. 562 // Stop the demuxer, overriding the default expectation to assert that
563 // data_source_ really is Stop()'d.
564 EXPECT_CALL(*data_source_, Stop(_))
565 .WillOnce(Invoke(&RunStopFilterCallback))
566 .RetiresOnSaturation();
557 demuxer_->Stop(NewExpectedCallback()); 567 demuxer_->Stop(NewExpectedCallback());
558 568
559 // Expect all calls in sequence. 569 // Expect all calls in sequence.
560 InSequence s; 570 InSequence s;
561 571
562 // The callback should be immediately deleted. We'll use a checkpoint to 572 // The callback should be immediately deleted. We'll use a checkpoint to
563 // verify that it has indeed been deleted. 573 // verify that it has indeed been deleted.
564 EXPECT_CALL(*callback, OnDelete()); 574 EXPECT_CALL(*callback, OnDelete());
565 EXPECT_CALL(mock_ffmpeg_, CheckPoint(1)); 575 EXPECT_CALL(mock_ffmpeg_, CheckPoint(1));
566 576
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 { 739 {
730 SCOPED_TRACE(""); 740 SCOPED_TRACE("");
731 InitializeDemuxer(); 741 InitializeDemuxer();
732 } 742 }
733 EXPECT_CALL(*data_source_, IsStreaming()) 743 EXPECT_CALL(*data_source_, IsStreaming())
734 .WillOnce(Return(false)); 744 .WillOnce(Return(false));
735 EXPECT_FALSE(demuxer_->IsStreaming()); 745 EXPECT_FALSE(demuxer_->IsStreaming());
736 } 746 }
737 747
738 } // namespace media 748 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698