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 "media/filters/pipeline_integration_test_base.h" | 5 #include "media/filters/pipeline_integration_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "media/base/decoder_buffer.h" | 11 #include "media/base/decoder_buffer.h" |
12 #include "media/base/test_data_util.h" | 12 #include "media/base/test_data_util.h" |
13 #include "media/crypto/aes_decryptor.h" | 13 #include "media/crypto/aes_decryptor.h" |
| 14 #include "media/filters/chunk_demuxer.h" |
14 | 15 |
15 using testing::AtMost; | 16 using testing::AtMost; |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
19 static const char kSourceId[] = "SourceId"; | 20 static const char kSourceId[] = "SourceId"; |
20 static const char kClearKeySystem[] = "org.w3.clearkey"; | 21 static const char kClearKeySystem[] = "org.w3.clearkey"; |
21 static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; | 22 static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; |
22 | 23 |
23 static const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\""; | 24 static const char kWebM[] = "video/webm; codecs=\"vp8,vorbis\""; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 // Helper class that emulates calls made on the ChunkDemuxer by the | 225 // Helper class that emulates calls made on the ChunkDemuxer by the |
225 // Media Source API. | 226 // Media Source API. |
226 class MockMediaSource { | 227 class MockMediaSource { |
227 public: | 228 public: |
228 MockMediaSource(const std::string& filename, const std::string& mimetype, | 229 MockMediaSource(const std::string& filename, const std::string& mimetype, |
229 int initial_append_size) | 230 int initial_append_size) |
230 : file_path_(GetTestDataFilePath(filename)), | 231 : file_path_(GetTestDataFilePath(filename)), |
231 current_position_(0), | 232 current_position_(0), |
232 initial_append_size_(initial_append_size), | 233 initial_append_size_(initial_append_size), |
233 mimetype_(mimetype) { | 234 mimetype_(mimetype), |
234 chunk_demuxer_ = new ChunkDemuxer( | 235 chunk_demuxer_(new ChunkDemuxer( |
235 base::Bind(&MockMediaSource::DemuxerOpened, base::Unretained(this)), | 236 base::Bind(&MockMediaSource::DemuxerOpened, |
236 base::Bind(&MockMediaSource::DemuxerNeedKey, base::Unretained(this)), | 237 base::Unretained(this)), |
237 LogCB()); | 238 base::Bind(&MockMediaSource::DemuxerNeedKey, |
| 239 base::Unretained(this)), |
| 240 LogCB())), |
| 241 owned_chunk_demuxer_(chunk_demuxer_) { |
238 | 242 |
239 file_data_ = ReadTestDataFile(filename); | 243 file_data_ = ReadTestDataFile(filename); |
240 | 244 |
241 if (initial_append_size_ == kAppendWholeFile) | 245 if (initial_append_size_ == kAppendWholeFile) |
242 initial_append_size_ = file_data_->GetDataSize(); | 246 initial_append_size_ = file_data_->GetDataSize(); |
243 | 247 |
244 DCHECK_GT(initial_append_size_, 0); | 248 DCHECK_GT(initial_append_size_, 0); |
245 DCHECK_LE(initial_append_size_, file_data_->GetDataSize()); | 249 DCHECK_LE(initial_append_size_, file_data_->GetDataSize()); |
246 } | 250 } |
247 | 251 |
248 virtual ~MockMediaSource() {} | 252 virtual ~MockMediaSource() {} |
249 | 253 |
250 const scoped_refptr<ChunkDemuxer>& demuxer() const { return chunk_demuxer_; } | 254 scoped_ptr<Demuxer> GetDemuxer() { return owned_chunk_demuxer_.Pass(); } |
251 | 255 |
252 void set_need_key_cb(const NeedKeyCB& need_key_cb) { | 256 void set_need_key_cb(const NeedKeyCB& need_key_cb) { |
253 need_key_cb_ = need_key_cb; | 257 need_key_cb_ = need_key_cb; |
254 } | 258 } |
255 | 259 |
256 void Seek(int new_position, int seek_append_size) { | 260 void Seek(int new_position, int seek_append_size) { |
257 chunk_demuxer_->StartWaitingForSeek(); | 261 chunk_demuxer_->StartWaitingForSeek(); |
258 | 262 |
259 chunk_demuxer_->Abort(kSourceId); | 263 chunk_demuxer_->Abort(kSourceId); |
260 | 264 |
261 DCHECK_GE(new_position, 0); | 265 DCHECK_GE(new_position, 0); |
262 DCHECK_LT(new_position, file_data_->GetDataSize()); | 266 DCHECK_LT(new_position, file_data_->GetDataSize()); |
263 current_position_ = new_position; | 267 current_position_ = new_position; |
264 | 268 |
265 AppendData(seek_append_size); | 269 AppendData(seek_append_size); |
266 } | 270 } |
267 | 271 |
268 void AppendData(int size) { | 272 void AppendData(int size) { |
269 DCHECK(chunk_demuxer_.get()); | 273 DCHECK(chunk_demuxer_); |
270 DCHECK_LT(current_position_, file_data_->GetDataSize()); | 274 DCHECK_LT(current_position_, file_data_->GetDataSize()); |
271 DCHECK_LE(current_position_ + size, file_data_->GetDataSize()); | 275 DCHECK_LE(current_position_ + size, file_data_->GetDataSize()); |
272 chunk_demuxer_->AppendData( | 276 chunk_demuxer_->AppendData( |
273 kSourceId, file_data_->GetData() + current_position_, size); | 277 kSourceId, file_data_->GetData() + current_position_, size); |
274 current_position_ += size; | 278 current_position_ += size; |
275 } | 279 } |
276 | 280 |
277 void AppendAtTime(const base::TimeDelta& timestampOffset, | 281 void AppendAtTime(const base::TimeDelta& timestampOffset, |
278 const uint8* pData, int size) { | 282 const uint8* pData, int size) { |
279 CHECK(chunk_demuxer_->SetTimestampOffset(kSourceId, timestampOffset)); | 283 CHECK(chunk_demuxer_->SetTimestampOffset(kSourceId, timestampOffset)); |
280 chunk_demuxer_->AppendData(kSourceId, pData, size); | 284 chunk_demuxer_->AppendData(kSourceId, pData, size); |
281 CHECK(chunk_demuxer_->SetTimestampOffset(kSourceId, base::TimeDelta())); | 285 CHECK(chunk_demuxer_->SetTimestampOffset(kSourceId, base::TimeDelta())); |
282 } | 286 } |
283 | 287 |
284 void EndOfStream() { | 288 void EndOfStream() { |
285 chunk_demuxer_->EndOfStream(PIPELINE_OK); | 289 chunk_demuxer_->EndOfStream(PIPELINE_OK); |
286 } | 290 } |
287 | 291 |
288 void Abort() { | 292 void Abort() { |
289 if (!chunk_demuxer_.get()) | 293 if (!chunk_demuxer_) |
290 return; | 294 return; |
291 chunk_demuxer_->Shutdown(); | 295 chunk_demuxer_->Shutdown(); |
292 chunk_demuxer_ = NULL; | 296 chunk_demuxer_ = NULL; |
293 } | 297 } |
294 | 298 |
295 void DemuxerOpened() { | 299 void DemuxerOpened() { |
296 MessageLoop::current()->PostTask( | 300 MessageLoop::current()->PostTask( |
297 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask, | 301 FROM_HERE, base::Bind(&MockMediaSource::DemuxerOpenedTask, |
298 base::Unretained(this))); | 302 base::Unretained(this))); |
299 } | 303 } |
(...skipping 19 matching lines...) Expand all Loading... |
319 need_key_cb_.Run( | 323 need_key_cb_.Run( |
320 std::string(), std::string(), type, init_data.Pass(), init_data_size); | 324 std::string(), std::string(), type, init_data.Pass(), init_data_size); |
321 } | 325 } |
322 | 326 |
323 private: | 327 private: |
324 base::FilePath file_path_; | 328 base::FilePath file_path_; |
325 scoped_refptr<DecoderBuffer> file_data_; | 329 scoped_refptr<DecoderBuffer> file_data_; |
326 int current_position_; | 330 int current_position_; |
327 int initial_append_size_; | 331 int initial_append_size_; |
328 std::string mimetype_; | 332 std::string mimetype_; |
329 scoped_refptr<ChunkDemuxer> chunk_demuxer_; | 333 ChunkDemuxer* chunk_demuxer_; |
| 334 scoped_ptr<Demuxer> owned_chunk_demuxer_; |
330 NeedKeyCB need_key_cb_; | 335 NeedKeyCB need_key_cb_; |
331 }; | 336 }; |
332 | 337 |
333 class PipelineIntegrationTest | 338 class PipelineIntegrationTest |
334 : public testing::Test, | 339 : public testing::Test, |
335 public PipelineIntegrationTestBase { | 340 public PipelineIntegrationTestBase { |
336 public: | 341 public: |
337 void StartPipelineWithMediaSource(MockMediaSource* source) { | 342 void StartPipelineWithMediaSource(MockMediaSource* source) { |
338 EXPECT_CALL(*this, OnBufferingState(Pipeline::kHaveMetadata)) | 343 EXPECT_CALL(*this, OnBufferingState(Pipeline::kHaveMetadata)) |
339 .Times(AtMost(1)); | 344 .Times(AtMost(1)); |
340 EXPECT_CALL(*this, OnBufferingState(Pipeline::kPrerollCompleted)) | 345 EXPECT_CALL(*this, OnBufferingState(Pipeline::kPrerollCompleted)) |
341 .Times(AtMost(1)); | 346 .Times(AtMost(1)); |
342 pipeline_->Start( | 347 pipeline_->Start( |
343 CreateFilterCollection(source->demuxer(), NULL), | 348 CreateFilterCollection(source->GetDemuxer(), NULL), |
344 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 349 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
345 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 350 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
346 QuitOnStatusCB(PIPELINE_OK), | 351 QuitOnStatusCB(PIPELINE_OK), |
347 base::Bind(&PipelineIntegrationTest::OnBufferingState, | 352 base::Bind(&PipelineIntegrationTest::OnBufferingState, |
348 base::Unretained(this)), | 353 base::Unretained(this)), |
349 base::Closure()); | 354 base::Closure()); |
350 | 355 |
351 message_loop_.Run(); | 356 message_loop_.Run(); |
352 } | 357 } |
353 | 358 |
354 void StartPipelineWithEncryptedMedia( | 359 void StartPipelineWithEncryptedMedia( |
355 MockMediaSource* source, | 360 MockMediaSource* source, |
356 FakeEncryptedMedia* encrypted_media) { | 361 FakeEncryptedMedia* encrypted_media) { |
357 EXPECT_CALL(*this, OnBufferingState(Pipeline::kHaveMetadata)) | 362 EXPECT_CALL(*this, OnBufferingState(Pipeline::kHaveMetadata)) |
358 .Times(AtMost(1)); | 363 .Times(AtMost(1)); |
359 EXPECT_CALL(*this, OnBufferingState(Pipeline::kPrerollCompleted)) | 364 EXPECT_CALL(*this, OnBufferingState(Pipeline::kPrerollCompleted)) |
360 .Times(AtMost(1)); | 365 .Times(AtMost(1)); |
361 pipeline_->Start( | 366 pipeline_->Start( |
362 CreateFilterCollection(source->demuxer(), encrypted_media->decryptor()), | 367 CreateFilterCollection(source->GetDemuxer(), |
| 368 encrypted_media->decryptor()), |
363 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 369 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
364 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 370 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
365 QuitOnStatusCB(PIPELINE_OK), | 371 QuitOnStatusCB(PIPELINE_OK), |
366 base::Bind(&PipelineIntegrationTest::OnBufferingState, | 372 base::Bind(&PipelineIntegrationTest::OnBufferingState, |
367 base::Unretained(this)), | 373 base::Unretained(this)), |
368 base::Closure()); | 374 base::Closure()); |
369 | 375 |
370 source->set_need_key_cb(base::Bind(&FakeEncryptedMedia::NeedKey, | 376 source->set_need_key_cb(base::Bind(&FakeEncryptedMedia::NeedKey, |
371 base::Unretained(encrypted_media))); | 377 base::Unretained(encrypted_media))); |
372 | 378 |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 // back. | 923 // back. |
918 // Disabled since it might crash or corrupt heap, see http://crbug.com/173333 | 924 // Disabled since it might crash or corrupt heap, see http://crbug.com/173333 |
919 TEST_F(PipelineIntegrationTest, DISABLED_BasicPlayback_VP9_Opus_WebM) { | 925 TEST_F(PipelineIntegrationTest, DISABLED_BasicPlayback_VP9_Opus_WebM) { |
920 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp9-opus.webm"), | 926 ASSERT_TRUE(Start(GetTestDataFilePath("bear-vp9-opus.webm"), |
921 PIPELINE_OK)); | 927 PIPELINE_OK)); |
922 Play(); | 928 Play(); |
923 ASSERT_TRUE(WaitUntilOnEnded()); | 929 ASSERT_TRUE(WaitUntilOnEnded()); |
924 } | 930 } |
925 | 931 |
926 } // namespace media | 932 } // namespace media |
OLD | NEW |