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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "media/base/filter_collection.h" | 7 #include "media/base/filter_collection.h" |
8 #include "media/base/media_log.h" | 8 #include "media/base/media_log.h" |
9 #include "media/base/message_loop_factory_impl.h" | 9 #include "media/base/message_loop_factory_impl.h" |
10 #include "media/base/pipeline.h" | 10 #include "media/base/pipeline.h" |
11 #include "media/base/test_data_util.h" | 11 #include "media/base/test_data_util.h" |
12 #include "media/filters/chunk_demuxer.h" | |
13 #include "media/filters/chunk_demuxer_client.h" | |
14 #include "media/filters/chunk_demuxer_factory.h" | |
12 #include "media/filters/ffmpeg_audio_decoder.h" | 15 #include "media/filters/ffmpeg_audio_decoder.h" |
13 #include "media/filters/ffmpeg_demuxer_factory.h" | 16 #include "media/filters/ffmpeg_demuxer_factory.h" |
14 #include "media/filters/ffmpeg_video_decoder.h" | 17 #include "media/filters/ffmpeg_video_decoder.h" |
15 #include "media/filters/file_data_source.h" | 18 #include "media/filters/file_data_source.h" |
16 #include "media/filters/null_audio_renderer.h" | 19 #include "media/filters/null_audio_renderer.h" |
17 #include "media/filters/video_renderer_base.h" | 20 #include "media/filters/video_renderer_base.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
20 | 23 |
21 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
22 | 25 |
23 namespace media { | 26 namespace media { |
24 | 27 |
28 // Helper class that emulates calls made on the ChunkDemuxer by the | |
29 // Media Source API. | |
30 class MockMediaSource : public ChunkDemuxerClient { | |
31 public: | |
32 MockMediaSource(const std::string& filename, int initial_append_size) | |
33 : url_(GetTestDataURL(filename)), | |
34 current_position_(0), | |
35 initial_append_size_(initial_append_size) { | |
36 ReadTestDataFile(filename, &file_data_, &file_data_size_); | |
37 | |
38 DCHECK_GT(initial_append_size_, 0); | |
39 DCHECK_LE(initial_append_size_, file_data_size_); | |
40 } | |
41 | |
42 virtual ~MockMediaSource() {} | |
43 | |
44 const std::string& url() { return url_; } | |
45 | |
46 void Seek(int new_position, int seek_append_size) { | |
47 chunk_demuxer_->FlushData(); | |
48 | |
49 DCHECK_GE(new_position, 0); | |
50 DCHECK_LT(new_position, file_data_size_); | |
51 current_position_ = new_position; | |
52 | |
53 AppendData(seek_append_size); | |
54 } | |
55 | |
56 void AppendData(int size) { | |
57 DCHECK(chunk_demuxer_.get()); | |
58 DCHECK_LT(current_position_, file_data_size_); | |
59 DCHECK_LE(current_position_ + size, file_data_size_); | |
60 chunk_demuxer_->AppendData(file_data_.get() + current_position_, size); | |
61 current_position_ += size; | |
62 } | |
63 | |
64 void EndOfStream() { | |
65 chunk_demuxer_->EndOfStream(PIPELINE_OK); | |
66 } | |
67 | |
68 void Abort() { | |
69 if (!chunk_demuxer_.get()) | |
70 return; | |
71 chunk_demuxer_->Shutdown(); | |
72 } | |
73 | |
74 // ChunkDemuxerClient methods. | |
75 virtual void DemuxerOpened(ChunkDemuxer* demuxer) { | |
76 chunk_demuxer_ = demuxer; | |
77 AppendData(initial_append_size_); | |
78 } | |
79 | |
80 virtual void DemuxerClosed() { | |
81 chunk_demuxer_ = NULL; | |
82 } | |
83 | |
84 private: | |
85 std::string url_; | |
86 scoped_array<uint8> file_data_; | |
87 int file_data_size_; | |
88 int current_position_; | |
89 int initial_append_size_; | |
90 scoped_refptr<ChunkDemuxer> chunk_demuxer_; | |
91 }; | |
92 | |
25 // Integration tests for Pipeline. Real demuxers, real decoders, and | 93 // Integration tests for Pipeline. Real demuxers, real decoders, and |
26 // base renderer implementations are used to verify pipeline functionality. The | 94 // base renderer implementations are used to verify pipeline functionality. The |
27 // renderers used in these tests rely heavily on the AudioRendererBase & | 95 // renderers used in these tests rely heavily on the AudioRendererBase & |
28 // VideoRendererBase implementations which contain a majority of the code used | 96 // VideoRendererBase implementations which contain a majority of the code used |
29 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in | 97 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in |
30 // the browser. The renderers in this test don't actually write data to a | 98 // the browser. The renderers in this test don't actually write data to a |
31 // display or audio device. Both of these devices are simulated since they have | 99 // display or audio device. Both of these devices are simulated since they have |
32 // little effect on verifying pipeline behavior and allow tests to run faster | 100 // little effect on verifying pipeline behavior and allow tests to run faster |
33 // than real-time. | 101 // than real-time. |
34 class PipelineIntegrationTest : public testing::Test { | 102 class PipelineIntegrationTest : public testing::Test { |
35 public: | 103 public: |
36 PipelineIntegrationTest() | 104 PipelineIntegrationTest() |
37 : message_loop_factory_(new MessageLoopFactoryImpl()), | 105 : message_loop_factory_(new MessageLoopFactoryImpl()), |
38 pipeline_(new Pipeline(&message_loop_, new MediaLog())), | 106 pipeline_(new Pipeline(&message_loop_, new MediaLog())), |
39 ended_(false) { | 107 ended_(false) { |
40 pipeline_->Init( | 108 pipeline_->Init( |
41 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 109 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
42 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 110 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
43 Pipeline::NetworkEventCB()); | 111 Pipeline::NetworkEventCB()); |
44 | 112 |
45 EXPECT_CALL(*this, OnVideoRendererPaint()).Times(AnyNumber()); | 113 EXPECT_CALL(*this, OnVideoRendererPaint()).Times(AnyNumber()); |
46 EXPECT_CALL(*this, OnSetOpaque(true)); | 114 EXPECT_CALL(*this, OnSetOpaque(true)).Times(AnyNumber()); |
47 } | 115 } |
48 | 116 |
49 virtual ~PipelineIntegrationTest() { | 117 virtual ~PipelineIntegrationTest() { |
50 if (!pipeline_->IsRunning()) | 118 if (!pipeline_->IsRunning()) |
51 return; | 119 return; |
52 | 120 |
53 Stop(); | 121 Stop(); |
54 } | 122 } |
55 | 123 |
56 void OnStatusCallback(PipelineStatus expected_status, | 124 void OnStatusCallback(PipelineStatus expected_status, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 base::Bind(&PipelineIntegrationTest::QuitAfterCurrentTimeTask, | 199 base::Bind(&PipelineIntegrationTest::QuitAfterCurrentTimeTask, |
132 base::Unretained(this), | 200 base::Unretained(this), |
133 wait_time), | 201 wait_time), |
134 10); | 202 10); |
135 message_loop_.Run(); | 203 message_loop_.Run(); |
136 } | 204 } |
137 | 205 |
138 scoped_ptr<FilterCollection> CreateFilterCollection(const std::string& url) { | 206 scoped_ptr<FilterCollection> CreateFilterCollection(const std::string& url) { |
139 scoped_refptr<FileDataSource> data_source = new FileDataSource(); | 207 scoped_refptr<FileDataSource> data_source = new FileDataSource(); |
140 CHECK_EQ(PIPELINE_OK, data_source->Initialize(url)); | 208 CHECK_EQ(PIPELINE_OK, data_source->Initialize(url)); |
209 return CreateFilterCollection(scoped_ptr<DemuxerFactory>( | |
210 new FFmpegDemuxerFactory(data_source, &message_loop_))); | |
211 } | |
141 | 212 |
142 scoped_ptr<FilterCollection> collection( | 213 scoped_ptr<FilterCollection> CreateFilterCollection( |
143 new FilterCollection()); | 214 ChunkDemuxerClient* client) { |
144 collection->SetDemuxerFactory(scoped_ptr<DemuxerFactory>( | 215 return CreateFilterCollection(scoped_ptr<DemuxerFactory>( |
145 new FFmpegDemuxerFactory(data_source, &message_loop_))); | 216 new ChunkDemuxerFactory(client))); |
217 } | |
218 | |
219 scoped_ptr<FilterCollection> CreateFilterCollection( | |
220 scoped_ptr<DemuxerFactory> demuxer_factory) { | |
221 scoped_ptr<FilterCollection> collection(new FilterCollection()); | |
222 collection->SetDemuxerFactory(demuxer_factory.Pass()); | |
146 collection->AddAudioDecoder(new FFmpegAudioDecoder( | 223 collection->AddAudioDecoder(new FFmpegAudioDecoder( |
147 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); | 224 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
148 collection->AddVideoDecoder(new FFmpegVideoDecoder( | 225 collection->AddVideoDecoder(new FFmpegVideoDecoder( |
149 message_loop_factory_->GetMessageLoop("VideoDecoderThread"))); | 226 message_loop_factory_->GetMessageLoop("VideoDecoderThread"))); |
150 collection->AddVideoRenderer(new VideoRendererBase( | 227 collection->AddVideoRenderer(new VideoRendererBase( |
151 base::Bind(&PipelineIntegrationTest::OnVideoRendererPaint, | 228 base::Bind(&PipelineIntegrationTest::OnVideoRendererPaint, |
152 base::Unretained(this)), | 229 base::Unretained(this)), |
153 base::Bind(&PipelineIntegrationTest::OnSetOpaque, | 230 base::Bind(&PipelineIntegrationTest::OnSetOpaque, |
154 base::Unretained(this)))); | 231 base::Unretained(this)))); |
155 collection->AddAudioRenderer(new NullAudioRenderer()); | 232 collection->AddAudioRenderer(new NullAudioRenderer()); |
156 return collection.Pass(); | 233 return collection.Pass(); |
157 } | 234 } |
158 | 235 |
236 // Verifies that seeking works properly for ChunkDemuxer when the | |
237 // seek happens while there is a pending read on the ChunkDemuxer | |
238 // and no data is available. | |
239 void TestSeekDuringRead(const std::string& filename, | |
240 int initial_append_size, | |
241 base::TimeDelta start_seek_time, | |
242 base::TimeDelta seek_time, | |
243 int seek_file_position, | |
244 int seek_append_size) { | |
245 MockMediaSource source(filename, initial_append_size); | |
246 | |
247 pipeline_->Start(CreateFilterCollection(&source), source.url(), | |
248 QuitOnStatusCB(PIPELINE_OK)); | |
249 message_loop_.Run(); | |
250 | |
251 Play(); | |
252 WaitUntilCurrentTimeIsAfter(start_seek_time); | |
253 | |
254 source.Seek(seek_file_position, seek_append_size); | |
255 Seek(seek_time); | |
256 | |
257 source.EndOfStream(); | |
258 | |
259 source.Abort(); | |
260 Stop(); | |
261 } | |
262 | |
159 protected: | 263 protected: |
160 MessageLoop message_loop_; | 264 MessageLoop message_loop_; |
161 scoped_ptr<MessageLoopFactory> message_loop_factory_; | 265 scoped_ptr<MessageLoopFactory> message_loop_factory_; |
162 scoped_refptr<Pipeline> pipeline_; | 266 scoped_refptr<Pipeline> pipeline_; |
163 bool ended_; | 267 bool ended_; |
164 | 268 |
165 private: | 269 private: |
166 MOCK_METHOD0(OnVideoRendererPaint, void()); | 270 MOCK_METHOD0(OnVideoRendererPaint, void()); |
167 MOCK_METHOD1(OnSetOpaque, void(bool)); | 271 MOCK_METHOD1(OnSetOpaque, void(bool)); |
168 }; | 272 }; |
(...skipping 23 matching lines...) Expand all Loading... | |
192 WaitUntilOnEnded(); | 296 WaitUntilOnEnded(); |
193 | 297 |
194 // Make sure seeking after reaching the end works as expected. | 298 // Make sure seeking after reaching the end works as expected. |
195 Pause(); | 299 Pause(); |
196 Seek(seek_time); | 300 Seek(seek_time); |
197 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); | 301 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); |
198 Play(); | 302 Play(); |
199 WaitUntilOnEnded(); | 303 WaitUntilOnEnded(); |
200 } | 304 } |
201 | 305 |
202 TEST_F(PipelineIntegrationTest, SeekWhilePlaying) { | 306 // TODO(acolwell): Fix flakiness http://crbug.com/109875 |
Ami GONE FROM CHROMIUM
2012/01/30 17:37:42
Is this only flaky for valgrind/tsan? Can you jus
acolwell GONE FROM CHROMIUM
2012/01/30 22:01:17
Unfortunately the flakiness isn't valgrind/tsan on
| |
307 TEST_F(PipelineIntegrationTest, FLAKY_SeekWhilePlaying) { | |
203 Start(GetTestDataURL("bear-320x240.webm"), PIPELINE_OK); | 308 Start(GetTestDataURL("bear-320x240.webm"), PIPELINE_OK); |
204 | 309 |
205 base::TimeDelta duration(pipeline_->GetMediaDuration()); | 310 base::TimeDelta duration(pipeline_->GetMediaDuration()); |
206 base::TimeDelta start_seek_time(duration / 4); | 311 base::TimeDelta start_seek_time(duration / 4); |
207 base::TimeDelta seek_time(duration * 3 / 4); | 312 base::TimeDelta seek_time(duration * 3 / 4); |
208 | 313 |
209 Play(); | 314 Play(); |
210 WaitUntilCurrentTimeIsAfter(start_seek_time); | 315 WaitUntilCurrentTimeIsAfter(start_seek_time); |
211 Seek(seek_time); | 316 Seek(seek_time); |
212 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); | 317 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); |
213 WaitUntilOnEnded(); | 318 WaitUntilOnEnded(); |
214 | 319 |
215 // Make sure seeking after reaching the end works as expected. | 320 // Make sure seeking after reaching the end works as expected. |
216 Seek(seek_time); | 321 Seek(seek_time); |
217 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); | 322 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); |
218 WaitUntilOnEnded(); | 323 WaitUntilOnEnded(); |
219 } | 324 } |
220 | 325 |
326 // Verify audio decoder & renderer can handle aborted demuxer reads. | |
327 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) { | |
328 TestSeekDuringRead("bear-320x240-audio-only.webm", 8192, | |
329 base::TimeDelta::FromMilliseconds(477), | |
330 base::TimeDelta::FromMilliseconds(617), | |
331 0x10CA, 19730); | |
332 } | |
333 | |
334 // Verify video decoder & renderer can handle aborted demuxer reads. | |
335 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { | |
336 TestSeekDuringRead("bear-320x240-video-only.webm", 32768, | |
337 base::TimeDelta::FromMilliseconds(200), | |
338 base::TimeDelta::FromMilliseconds(1668), | |
339 0x1C896, 65536); | |
340 } | |
341 | |
221 } // namespace media | 342 } // namespace media |
OLD | NEW |