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 <algorithm> | 5 #include <algorithm> |
6 #include <deque> | 6 #include <deque> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 CreateDataSource(name); | 81 CreateDataSource(name); |
82 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), | 82 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), |
83 data_source_); | 83 data_source_); |
84 } | 84 } |
85 | 85 |
86 MOCK_METHOD1(CheckPoint, void(int v)); | 86 MOCK_METHOD1(CheckPoint, void(int v)); |
87 | 87 |
88 void InitializeDemuxer() { | 88 void InitializeDemuxer() { |
89 EXPECT_CALL(host_, SetDuration(_)); | 89 EXPECT_CALL(host_, SetDuration(_)); |
90 demuxer_->Initialize(&host_, NewStatusCB(PIPELINE_OK)); | 90 demuxer_->Initialize(&host_, NewExpectedStatusAndQuitCB(PIPELINE_OK)); |
91 message_loop_.Run(); | 91 message_loop_.Run(); |
92 } | 92 } |
93 | 93 |
94 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); | 94 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); |
95 | 95 |
96 // Verifies that |buffer| has a specific |size| and |timestamp|. | 96 // Verifies that |buffer| has a specific |size| and |timestamp|. |
97 // |location| simply indicates where the call to this function was made. | 97 // |location| simply indicates where the call to this function was made. |
98 // This makes it easier to track down where test failures occur. | 98 // This makes it easier to track down where test failures occur. |
99 void OnReadDone(const tracked_objects::Location& location, | 99 void OnReadDone(const tracked_objects::Location& location, |
100 int size, int64 timestampInMicroseconds, | 100 int size, int64 timestampInMicroseconds, |
(...skipping 14 matching lines...) Expand all Loading... |
115 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); | 115 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); |
116 } | 116 } |
117 | 117 |
118 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, | 118 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, |
119 int size, int64 timestampInMicroseconds) { | 119 int size, int64 timestampInMicroseconds) { |
120 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); | 120 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); |
121 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this), | 121 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this), |
122 location, size, timestampInMicroseconds); | 122 location, size, timestampInMicroseconds); |
123 } | 123 } |
124 | 124 |
125 PipelineStatusCB NewStatusCB(PipelineStatus expected) { | |
126 return base::Bind(&FFmpegDemuxerTest::OnStatusDone, | |
127 base::Unretained(this), expected); | |
128 } | |
129 | |
130 void OnStatusDone(PipelineStatus expected, PipelineStatus status) { | |
131 EXPECT_EQ(expected, status); | |
132 | |
133 DCHECK_EQ(&message_loop_, MessageLoop::current()); | |
134 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); | |
135 } | |
136 | |
137 // Accessor to demuxer internals. | 125 // Accessor to demuxer internals. |
138 void set_duration_known(bool duration_known) { | 126 void set_duration_known(bool duration_known) { |
139 demuxer_->duration_known_ = duration_known; | 127 demuxer_->duration_known_ = duration_known; |
140 } | 128 } |
141 | 129 |
142 bool IsStreamStopped(DemuxerStream::Type type) { | 130 bool IsStreamStopped(DemuxerStream::Type type) { |
143 DemuxerStream* stream = demuxer_->GetStream(type); | 131 DemuxerStream* stream = demuxer_->GetStream(type); |
144 CHECK(stream); | 132 CHECK(stream); |
145 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; | 133 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; |
146 } | 134 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 data_source_ = new FileDataSource(); | 173 data_source_ = new FileDataSource(); |
186 EXPECT_TRUE(data_source_->Initialize(file_path)); | 174 EXPECT_TRUE(data_source_->Initialize(file_path)); |
187 } | 175 } |
188 | 176 |
189 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); | 177 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); |
190 }; | 178 }; |
191 | 179 |
192 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { | 180 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { |
193 // Simulate avformat_open_input() failing. | 181 // Simulate avformat_open_input() failing. |
194 CreateDemuxer("ten_byte_file"); | 182 CreateDemuxer("ten_byte_file"); |
195 demuxer_->Initialize(&host_, NewStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); | 183 demuxer_->Initialize( |
| 184 &host_, NewExpectedStatusAndQuitCB(DEMUXER_ERROR_COULD_NOT_OPEN)); |
196 message_loop_.Run(); | 185 message_loop_.Run(); |
197 } | 186 } |
198 | 187 |
199 // TODO(acolwell): Uncomment this test when we discover a file that passes | 188 // TODO(acolwell): Uncomment this test when we discover a file that passes |
200 // avformat_open_input(), but has avformat_find_stream_info() fail. | 189 // avformat_open_input(), but has avformat_find_stream_info() fail. |
201 // | 190 // |
202 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { | 191 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { |
203 // ("find_stream_info_fail.webm"); | 192 // ("find_stream_info_fail.webm"); |
204 // demuxer_->Initialize( | 193 // demuxer_->Initialize( |
205 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); | 194 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); |
206 // message_loop_.RunUntilIdle(); | 195 // message_loop_.RunUntilIdle(); |
207 //} | 196 //} |
208 | 197 |
209 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { | 198 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { |
210 // Open a file with no streams whatsoever. | 199 // Open a file with no streams whatsoever. |
211 CreateDemuxer("no_streams.webm"); | 200 CreateDemuxer("no_streams.webm"); |
212 demuxer_->Initialize(&host_, NewStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | 201 demuxer_->Initialize( |
| 202 &host_, NewExpectedStatusAndQuitCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
213 message_loop_.Run(); | 203 message_loop_.Run(); |
214 } | 204 } |
215 | 205 |
216 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) { | 206 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) { |
217 // Open a file containing streams but none of which are audio/video streams. | 207 // Open a file containing streams but none of which are audio/video streams. |
218 CreateDemuxer("no_audio_video.webm"); | 208 CreateDemuxer("no_audio_video.webm"); |
219 demuxer_->Initialize(&host_, NewStatusCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); | 209 demuxer_->Initialize( |
| 210 &host_, NewExpectedStatusAndQuitCB(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); |
220 message_loop_.Run(); | 211 message_loop_.Run(); |
221 } | 212 } |
222 | 213 |
223 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { | 214 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { |
224 CreateDemuxer("bear-320x240.webm"); | 215 CreateDemuxer("bear-320x240.webm"); |
225 InitializeDemuxer(); | 216 InitializeDemuxer(); |
226 | 217 |
227 // Video stream should be present. | 218 // Video stream should be present. |
228 scoped_refptr<DemuxerStream> stream = | 219 scoped_refptr<DemuxerStream> stream = |
229 demuxer_->GetStream(DemuxerStream::VIDEO); | 220 demuxer_->GetStream(DemuxerStream::VIDEO); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 demuxer_->GetStream(DemuxerStream::AUDIO); | 365 demuxer_->GetStream(DemuxerStream::AUDIO); |
375 ASSERT_TRUE(video); | 366 ASSERT_TRUE(video); |
376 ASSERT_TRUE(audio); | 367 ASSERT_TRUE(audio); |
377 | 368 |
378 // Read a video packet and release it. | 369 // Read a video packet and release it. |
379 video->Read(NewReadCB(FROM_HERE, 22084, 0)); | 370 video->Read(NewReadCB(FROM_HERE, 22084, 0)); |
380 message_loop_.Run(); | 371 message_loop_.Run(); |
381 | 372 |
382 // Issue a simple forward seek, which should discard queued packets. | 373 // Issue a simple forward seek, which should discard queued packets. |
383 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), | 374 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), |
384 NewStatusCB(PIPELINE_OK)); | 375 NewExpectedStatusAndQuitCB(PIPELINE_OK)); |
385 message_loop_.Run(); | 376 message_loop_.Run(); |
386 | 377 |
387 // Audio read #1. | 378 // Audio read #1. |
388 audio->Read(NewReadCB(FROM_HERE, 145, 803000)); | 379 audio->Read(NewReadCB(FROM_HERE, 145, 803000)); |
389 message_loop_.Run(); | 380 message_loop_.Run(); |
390 | 381 |
391 // Audio read #2. | 382 // Audio read #2. |
392 audio->Read(NewReadCB(FROM_HERE, 148, 826000)); | 383 audio->Read(NewReadCB(FROM_HERE, 148, 826000)); |
393 message_loop_.Run(); | 384 message_loop_.Run(); |
394 | 385 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 demuxer_->GetStream(DemuxerStream::AUDIO); | 538 demuxer_->GetStream(DemuxerStream::AUDIO); |
548 ASSERT_TRUE(video); | 539 ASSERT_TRUE(video); |
549 ASSERT_TRUE(audio); | 540 ASSERT_TRUE(audio); |
550 | 541 |
551 // Read a video packet and release it. | 542 // Read a video packet and release it. |
552 video->Read(NewReadCB(FROM_HERE, 22084, 0)); | 543 video->Read(NewReadCB(FROM_HERE, 22084, 0)); |
553 message_loop_.Run(); | 544 message_loop_.Run(); |
554 | 545 |
555 // Issue a simple forward seek, which should discard queued packets. | 546 // Issue a simple forward seek, which should discard queued packets. |
556 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000), | 547 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000), |
557 NewStatusCB(PIPELINE_OK)); | 548 NewExpectedStatusAndQuitCB(PIPELINE_OK)); |
558 message_loop_.Run(); | 549 message_loop_.Run(); |
559 | 550 |
560 // Audio read #1. | 551 // Audio read #1. |
561 audio->Read(NewReadCB(FROM_HERE, 40, 2403000)); | 552 audio->Read(NewReadCB(FROM_HERE, 40, 2403000)); |
562 message_loop_.Run(); | 553 message_loop_.Run(); |
563 | 554 |
564 // Audio read #2. | 555 // Audio read #2. |
565 audio->Read(NewReadCB(FROM_HERE, 42, 2406000)); | 556 audio->Read(NewReadCB(FROM_HERE, 42, 2406000)); |
566 message_loop_.Run(); | 557 message_loop_.Run(); |
567 | 558 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { | 607 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { |
617 CreateDemuxer("vorbis_audio_wmv_video.mkv"); | 608 CreateDemuxer("vorbis_audio_wmv_video.mkv"); |
618 InitializeDemuxer(); | 609 InitializeDemuxer(); |
619 | 610 |
620 // Ensure the expected streams are present. | 611 // Ensure the expected streams are present. |
621 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); | 612 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); |
622 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 613 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); |
623 } | 614 } |
624 | 615 |
625 } // namespace media | 616 } // namespace media |
OLD | NEW |