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/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 while (!read_cbs_.empty()) { | 326 while (!read_cbs_.empty()) { |
327 closures->push_back(base::Bind(read_cbs_.front(), end_of_stream_buffer)); | 327 closures->push_back(base::Bind(read_cbs_.front(), end_of_stream_buffer)); |
328 read_cbs_.pop_front(); | 328 read_cbs_.pop_front(); |
329 } | 329 } |
330 | 330 |
331 ChangeState_Locked(RETURNING_EOS_FOR_READS); | 331 ChangeState_Locked(RETURNING_EOS_FOR_READS); |
332 } | 332 } |
333 | 333 |
334 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client) | 334 ChunkDemuxer::ChunkDemuxer(ChunkDemuxerClient* client) |
335 : state_(WAITING_FOR_INIT), | 335 : state_(WAITING_FOR_INIT), |
| 336 host_(NULL), |
336 client_(client), | 337 client_(client), |
337 buffered_bytes_(0), | 338 buffered_bytes_(0), |
338 seek_waits_for_data_(true) { | 339 seek_waits_for_data_(true) { |
339 DCHECK(client); | 340 DCHECK(client); |
340 } | 341 } |
341 | 342 |
342 ChunkDemuxer::~ChunkDemuxer() { | 343 ChunkDemuxer::~ChunkDemuxer() { |
343 DCHECK_NE(state_, INITIALIZED); | 344 DCHECK_NE(state_, INITIALIZED); |
344 } | 345 } |
345 | 346 |
346 void ChunkDemuxer::Initialize(const PipelineStatusCB& cb) { | 347 void ChunkDemuxer::Initialize(DemuxerHost* host, |
| 348 const PipelineStatusCB& cb) { |
347 DVLOG(1) << "Init()"; | 349 DVLOG(1) << "Init()"; |
348 { | 350 { |
349 base::AutoLock auto_lock(lock_); | 351 base::AutoLock auto_lock(lock_); |
350 DCHECK_EQ(state_, WAITING_FOR_INIT); | 352 DCHECK_EQ(state_, WAITING_FOR_INIT); |
| 353 host_ = host; |
351 | 354 |
352 ChangeState_Locked(INITIALIZING); | 355 ChangeState_Locked(INITIALIZING); |
353 init_cb_ = cb; | 356 init_cb_ = cb; |
354 stream_parser_.reset(new WebMStreamParser()); | 357 stream_parser_.reset(new WebMStreamParser()); |
355 | 358 |
356 stream_parser_->Init( | 359 stream_parser_->Init( |
357 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), | 360 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), |
358 this); | 361 this); |
359 } | 362 } |
360 | 363 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 533 |
531 if (video_.get() && video_->GetLastBufferTimestamp(&tmp) && | 534 if (video_.get() && video_->GetLastBufferTimestamp(&tmp) && |
532 tmp > buffered_ts) { | 535 tmp > buffered_ts) { |
533 buffered_ts = tmp; | 536 buffered_ts = tmp; |
534 } | 537 } |
535 | 538 |
536 buffered_bytes = buffered_bytes_; | 539 buffered_bytes = buffered_bytes_; |
537 } | 540 } |
538 | 541 |
539 // Notify the host of 'network activity' because we got data. | 542 // Notify the host of 'network activity' because we got data. |
540 host()->SetBufferedBytes(buffered_bytes); | 543 host_->SetBufferedBytes(buffered_bytes); |
541 | 544 |
542 if (buffered_ts.InSeconds() >= 0) { | 545 if (buffered_ts.InSeconds() >= 0) { |
543 host()->SetBufferedTime(buffered_ts); | 546 host_->SetBufferedTime(buffered_ts); |
544 } | 547 } |
545 | 548 |
546 host()->SetNetworkActivity(true); | 549 host_->SetNetworkActivity(true); |
547 | 550 |
548 if (!cb.is_null()) | 551 if (!cb.is_null()) |
549 cb.Run(PIPELINE_OK); | 552 cb.Run(PIPELINE_OK); |
550 | 553 |
551 return true; | 554 return true; |
552 } | 555 } |
553 | 556 |
554 void ChunkDemuxer::EndOfStream(PipelineStatus status) { | 557 void ChunkDemuxer::EndOfStream(PipelineStatus status) { |
555 DVLOG(1) << "EndOfStream(" << status << ")"; | 558 DVLOG(1) << "EndOfStream(" << status << ")"; |
556 base::AutoLock auto_lock(lock_); | 559 base::AutoLock auto_lock(lock_); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 video_->Shutdown(); | 645 video_->Shutdown(); |
643 } | 646 } |
644 | 647 |
645 if (!cb.is_null()) { | 648 if (!cb.is_null()) { |
646 base::AutoUnlock auto_unlock(lock_); | 649 base::AutoUnlock auto_unlock(lock_); |
647 cb.Run(error); | 650 cb.Run(error); |
648 return; | 651 return; |
649 } | 652 } |
650 | 653 |
651 base::AutoUnlock auto_unlock(lock_); | 654 base::AutoUnlock auto_unlock(lock_); |
652 host()->OnDemuxerError(error); | 655 host_->OnDemuxerError(error); |
653 } | 656 } |
654 | 657 |
655 void ChunkDemuxer::OnStreamParserInitDone(bool success, | 658 void ChunkDemuxer::OnStreamParserInitDone(bool success, |
656 base::TimeDelta duration) { | 659 base::TimeDelta duration) { |
657 lock_.AssertAcquired(); | 660 lock_.AssertAcquired(); |
658 DCHECK_EQ(state_, INITIALIZING); | 661 DCHECK_EQ(state_, INITIALIZING); |
659 if (!success || (!audio_.get() && !video_.get())) { | 662 if (!success || (!audio_.get() && !video_.get())) { |
660 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); | 663 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); |
661 return; | 664 return; |
662 } | 665 } |
663 | 666 |
664 duration_ = duration; | 667 duration_ = duration; |
665 host()->SetDuration(duration_); | 668 host_->SetDuration(duration_); |
666 host()->SetCurrentReadPosition(0); | 669 host_->SetCurrentReadPosition(0); |
667 | 670 |
668 ChangeState_Locked(INITIALIZED); | 671 ChangeState_Locked(INITIALIZED); |
669 PipelineStatusCB cb; | 672 PipelineStatusCB cb; |
670 std::swap(cb, init_cb_); | 673 std::swap(cb, init_cb_); |
671 cb.Run(PIPELINE_OK); | 674 cb.Run(PIPELINE_OK); |
672 } | 675 } |
673 | 676 |
674 bool ChunkDemuxer::OnNewAudioConfig(const AudioDecoderConfig& config) { | 677 bool ChunkDemuxer::OnNewAudioConfig(const AudioDecoderConfig& config) { |
675 lock_.AssertAcquired(); | 678 lock_.AssertAcquired(); |
676 // Only allow a single audio config for now. | 679 // Only allow a single audio config for now. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 if (!video_->CanAddBuffers(buffers)) | 714 if (!video_->CanAddBuffers(buffers)) |
712 return false; | 715 return false; |
713 | 716 |
714 video_->AddBuffers(buffers); | 717 video_->AddBuffers(buffers); |
715 seek_waits_for_data_ = false; | 718 seek_waits_for_data_ = false; |
716 | 719 |
717 return true; | 720 return true; |
718 } | 721 } |
719 | 722 |
720 } // namespace media | 723 } // namespace media |
OLD | NEW |