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 for testing ChunkDemuxer. | |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
IMO it would be more helpful to describe what this
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
Done.
| |
29 class TestChunkDemuxerClient : public ChunkDemuxerClient { | |
30 public: | |
31 TestChunkDemuxerClient(const std::string& filename, int initial_append_size) | |
32 : url_(GetTestDataURL(filename)), | |
33 current_position_(0), | |
34 initial_append_size_(initial_append_size) { | |
35 ReadTestDataFile(filename, &file_data_, &file_data_size_); | |
36 | |
37 DCHECK_GT(initial_append_size_, 0); | |
38 DCHECK_LE(initial_append_size_, file_data_size_); | |
39 } | |
40 | |
41 virtual ~TestChunkDemuxerClient() {} | |
42 | |
43 const std::string& url() { return url_; } | |
44 | |
45 void FlushData() { | |
46 DCHECK(chunk_demuxer_.get()); | |
47 chunk_demuxer_->FlushData(); | |
48 } | |
49 | |
50 void Seek(int new_position) { | |
51 DCHECK_GE(new_position, 0); | |
52 DCHECK_LT(new_position, file_data_size_); | |
53 current_position_ = new_position; | |
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 |
103 : public testing::Test { | |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
unnecessary newline
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
Done.
| |
104 | |
35 public: | 105 public: |
36 PipelineIntegrationTest() | 106 PipelineIntegrationTest() |
37 : message_loop_factory_(new MessageLoopFactoryImpl()), | 107 : message_loop_factory_(new MessageLoopFactoryImpl()), |
38 pipeline_(new Pipeline(&message_loop_, new MediaLog())), | 108 pipeline_(new Pipeline(&message_loop_, new MediaLog())), |
39 ended_(false) { | 109 ended_(false) { |
40 pipeline_->Init( | 110 pipeline_->Init( |
41 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 111 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
42 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 112 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
43 Pipeline::NetworkEventCB()); | 113 Pipeline::NetworkEventCB()); |
44 | 114 |
45 EXPECT_CALL(*this, OnVideoRendererPaint()).Times(AnyNumber()); | 115 EXPECT_CALL(*this, OnVideoRendererPaint()).Times(AnyNumber()); |
46 EXPECT_CALL(*this, OnSetOpaque(true)); | 116 EXPECT_CALL(*this, OnSetOpaque(true)).Times(AnyNumber()); |
47 } | 117 } |
48 | 118 |
49 virtual ~PipelineIntegrationTest() { | 119 virtual ~PipelineIntegrationTest() { |
50 if (!pipeline_->IsRunning()) | 120 if (!pipeline_->IsRunning()) |
51 return; | 121 return; |
52 | 122 |
53 Stop(); | 123 Stop(); |
54 } | 124 } |
55 | 125 |
56 void OnStatusCallback(PipelineStatus expected_status, | 126 void OnStatusCallback(PipelineStatus expected_status, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 base::Bind(&PipelineIntegrationTest::QuitAfterCurrentTimeTask, | 201 base::Bind(&PipelineIntegrationTest::QuitAfterCurrentTimeTask, |
132 base::Unretained(this), | 202 base::Unretained(this), |
133 wait_time), | 203 wait_time), |
134 10); | 204 10); |
135 message_loop_.Run(); | 205 message_loop_.Run(); |
136 } | 206 } |
137 | 207 |
138 scoped_ptr<FilterCollection> CreateFilterCollection(const std::string& url) { | 208 scoped_ptr<FilterCollection> CreateFilterCollection(const std::string& url) { |
139 scoped_refptr<FileDataSource> data_source = new FileDataSource(); | 209 scoped_refptr<FileDataSource> data_source = new FileDataSource(); |
140 CHECK_EQ(PIPELINE_OK, data_source->Initialize(url)); | 210 CHECK_EQ(PIPELINE_OK, data_source->Initialize(url)); |
211 return CreateFilterCollection(scoped_ptr<DemuxerFactory>( | |
212 new FFmpegDemuxerFactory(data_source, &message_loop_))); | |
213 } | |
141 | 214 |
142 scoped_ptr<FilterCollection> collection( | 215 scoped_ptr<FilterCollection> CreateFilterCollection( |
143 new FilterCollection()); | 216 ChunkDemuxerClient* client) { |
144 collection->SetDemuxerFactory(scoped_ptr<DemuxerFactory>( | 217 return CreateFilterCollection(scoped_ptr<DemuxerFactory>( |
145 new FFmpegDemuxerFactory(data_source, &message_loop_))); | 218 new ChunkDemuxerFactory(client))); |
219 } | |
220 | |
221 scoped_ptr<FilterCollection> CreateFilterCollection( | |
222 scoped_ptr<DemuxerFactory> demuxer_factory) { | |
223 scoped_ptr<FilterCollection> collection(new FilterCollection()); | |
224 collection->SetDemuxerFactory(demuxer_factory.Pass()); | |
146 collection->AddAudioDecoder(new FFmpegAudioDecoder( | 225 collection->AddAudioDecoder(new FFmpegAudioDecoder( |
147 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); | 226 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
148 collection->AddVideoDecoder(new FFmpegVideoDecoder( | 227 collection->AddVideoDecoder(new FFmpegVideoDecoder( |
149 message_loop_factory_->GetMessageLoop("VideoDecoderThread"))); | 228 message_loop_factory_->GetMessageLoop("VideoDecoderThread"))); |
150 collection->AddVideoRenderer(new VideoRendererBase( | 229 collection->AddVideoRenderer(new VideoRendererBase( |
151 base::Bind(&PipelineIntegrationTest::OnVideoRendererPaint, | 230 base::Bind(&PipelineIntegrationTest::OnVideoRendererPaint, |
152 base::Unretained(this)), | 231 base::Unretained(this)), |
153 base::Bind(&PipelineIntegrationTest::OnSetOpaque, | 232 base::Bind(&PipelineIntegrationTest::OnSetOpaque, |
154 base::Unretained(this)))); | 233 base::Unretained(this)))); |
155 collection->AddAudioRenderer(new NullAudioRenderer()); | 234 collection->AddAudioRenderer(new NullAudioRenderer()); |
156 return collection.Pass(); | 235 return collection.Pass(); |
157 } | 236 } |
158 | 237 |
238 // Verifies that seeking works properly for ChunkDemuxer when the | |
239 // seek happens while there is a pending read on the ChunkDemuxer | |
240 // and no data is available. | |
241 void TestChunkDemuxerSeekDuringRead(const std::string& filename, | |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
#damnson !
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
removed ChunkDemuxer to make the name a little sho
Ami GONE FROM CHROMIUM
2012/01/29 22:12:38
Sorry, I didn't mean the name was too long; I was
| |
242 int initial_append_size, | |
243 base::TimeDelta start_seek_time, | |
244 base::TimeDelta seek_time, | |
245 int seek_file_position, | |
246 int seek_append_size) { | |
247 TestChunkDemuxerClient client(filename, initial_append_size); | |
248 | |
249 pipeline_->Start(CreateFilterCollection(&client), client.url(), | |
250 QuitOnStatusCB(PIPELINE_OK)); | |
251 message_loop_.Run(); | |
252 | |
253 Play(); | |
254 WaitUntilCurrentTimeIsAfter(start_seek_time); | |
255 | |
256 client.FlushData(); | |
257 | |
258 ended_ = false; | |
259 pipeline_->Seek(seek_time, QuitOnStatusCB(PIPELINE_OK)); | |
260 client.Seek(seek_file_position); | |
261 client.AppendData(seek_append_size); | |
262 | |
263 message_loop_.Run(); | |
264 | |
265 client.EndOfStream(); | |
266 | |
267 client.Abort(); | |
268 Stop(); | |
269 } | |
270 | |
159 protected: | 271 protected: |
160 MessageLoop message_loop_; | 272 MessageLoop message_loop_; |
161 scoped_ptr<MessageLoopFactory> message_loop_factory_; | 273 scoped_ptr<MessageLoopFactory> message_loop_factory_; |
162 scoped_refptr<Pipeline> pipeline_; | 274 scoped_refptr<Pipeline> pipeline_; |
163 bool ended_; | 275 bool ended_; |
164 | 276 |
165 private: | 277 private: |
166 MOCK_METHOD0(OnVideoRendererPaint, void()); | 278 MOCK_METHOD0(OnVideoRendererPaint, void()); |
167 MOCK_METHOD1(OnSetOpaque, void(bool)); | 279 MOCK_METHOD1(OnSetOpaque, void(bool)); |
280 | |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
extra newline
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
Done.
| |
168 }; | 281 }; |
169 | 282 |
170 | 283 |
171 TEST_F(PipelineIntegrationTest, BasicPlayback) { | 284 TEST_F(PipelineIntegrationTest, BasicPlayback) { |
172 Start(GetTestDataURL("bear-320x240.webm"), PIPELINE_OK); | 285 Start(GetTestDataURL("bear-320x240.webm"), PIPELINE_OK); |
173 | 286 |
174 Play(); | 287 Play(); |
175 | 288 |
176 WaitUntilOnEnded(); | 289 WaitUntilOnEnded(); |
177 } | 290 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 Seek(seek_time); | 324 Seek(seek_time); |
212 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); | 325 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); |
213 WaitUntilOnEnded(); | 326 WaitUntilOnEnded(); |
214 | 327 |
215 // Make sure seeking after reaching the end works as expected. | 328 // Make sure seeking after reaching the end works as expected. |
216 Seek(seek_time); | 329 Seek(seek_time); |
217 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); | 330 EXPECT_GE(pipeline_->GetCurrentTime(), seek_time); |
218 WaitUntilOnEnded(); | 331 WaitUntilOnEnded(); |
219 } | 332 } |
220 | 333 |
334 // Verify audio decoder & renderer can handle aborted demuxer reads. | |
335 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) { | |
336 TestChunkDemuxerSeekDuringRead("bear-320x240-audio-only.webm", 8192, | |
337 base::TimeDelta::FromMilliseconds(477), | |
338 base::TimeDelta::FromMilliseconds(617), | |
339 0x10CA, 19730); | |
340 } | |
341 | |
342 // Verify video decoder & renderer can handle aborted demuxer reads. | |
343 TEST_F(PipelineIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { | |
344 TestChunkDemuxerSeekDuringRead("bear-320x240-video-only.webm", 32768, | |
345 base::TimeDelta::FromMilliseconds(200), | |
346 base::TimeDelta::FromMilliseconds(1668), | |
347 0x1C896, 65536); | |
348 } | |
349 | |
221 } // namespace media | 350 } // namespace media |
OLD | NEW |