Chromium Code Reviews| 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/base/pipeline.h" | 5 #include "media/base/pipeline.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 bound_fns.Push(base::Bind( | 577 bound_fns.Push(base::Bind( |
| 578 &AudioRenderer::Flush, base::Unretained(audio_renderer_.get()))); | 578 &AudioRenderer::Flush, base::Unretained(audio_renderer_.get()))); |
| 579 } | 579 } |
| 580 if (video_renderer_) { | 580 if (video_renderer_) { |
| 581 bound_fns.Push(base::Bind( | 581 bound_fns.Push(base::Bind( |
| 582 &VideoRenderer::Flush, base::Unretained(video_renderer_.get()))); | 582 &VideoRenderer::Flush, base::Unretained(video_renderer_.get()))); |
| 583 } | 583 } |
| 584 | 584 |
| 585 // Seek demuxer. | 585 // Seek demuxer. |
| 586 bound_fns.Push(base::Bind( | 586 bound_fns.Push(base::Bind( |
| 587 &Demuxer::Seek, demuxer_, seek_timestamp)); | 587 &Demuxer::Seek, base::Unretained(demuxer_.get()), seek_timestamp)); |
| 588 | 588 |
| 589 // Preroll renderers. | 589 // Preroll renderers. |
| 590 if (audio_renderer_) { | 590 if (audio_renderer_) { |
| 591 bound_fns.Push(base::Bind( | 591 bound_fns.Push(base::Bind( |
| 592 &AudioRenderer::Preroll, base::Unretained(audio_renderer_.get()), | 592 &AudioRenderer::Preroll, base::Unretained(audio_renderer_.get()), |
| 593 seek_timestamp)); | 593 seek_timestamp)); |
| 594 } | 594 } |
| 595 | 595 |
| 596 if (video_renderer_) { | 596 if (video_renderer_) { |
| 597 bound_fns.Push(base::Bind( | 597 bound_fns.Push(base::Bind( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 621 } | 621 } |
| 622 | 622 |
| 623 pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); | 623 pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); |
| 624 } | 624 } |
| 625 | 625 |
| 626 void Pipeline::DoStop(const PipelineStatusCB& done_cb) { | 626 void Pipeline::DoStop(const PipelineStatusCB& done_cb) { |
| 627 DCHECK(message_loop_->BelongsToCurrentThread()); | 627 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 628 DCHECK(!pending_callbacks_.get()); | 628 DCHECK(!pending_callbacks_.get()); |
| 629 SerialRunner::Queue bound_fns; | 629 SerialRunner::Queue bound_fns; |
| 630 | 630 |
| 631 if (demuxer_) | 631 if (demuxer_) { |
| 632 bound_fns.Push(base::Bind(&Demuxer::Stop, demuxer_)); | 632 bound_fns.Push(base::Bind( |
| 633 &Demuxer::Stop, base::Unretained(demuxer_.get()))); | |
| 634 } | |
| 633 | 635 |
| 634 if (audio_renderer_) { | 636 if (audio_renderer_) { |
| 635 bound_fns.Push(base::Bind( | 637 bound_fns.Push(base::Bind( |
| 636 &AudioRenderer::Stop, base::Unretained(audio_renderer_.get()))); | 638 &AudioRenderer::Stop, base::Unretained(audio_renderer_.get()))); |
| 637 } | 639 } |
| 638 | 640 |
| 639 if (video_renderer_) { | 641 if (video_renderer_) { |
| 640 bound_fns.Push(base::Bind( | 642 bound_fns.Push(base::Bind( |
| 641 &VideoRenderer::Stop, base::Unretained(video_renderer_.get()))); | 643 &VideoRenderer::Stop, base::Unretained(video_renderer_.get()))); |
| 642 } | 644 } |
| 643 | 645 |
| 644 pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); | 646 pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb); |
| 645 } | 647 } |
| 646 | 648 |
| 647 void Pipeline::OnStopCompleted(PipelineStatus status) { | 649 void Pipeline::OnStopCompleted(PipelineStatus status) { |
| 648 DCHECK(message_loop_->BelongsToCurrentThread()); | 650 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 649 DCHECK_EQ(state_, kStopping); | 651 DCHECK_EQ(state_, kStopping); |
| 650 { | 652 { |
| 651 base::AutoLock l(lock_); | 653 base::AutoLock l(lock_); |
| 652 running_ = false; | 654 running_ = false; |
| 653 } | 655 } |
| 654 | 656 |
| 655 SetState(kStopped); | 657 SetState(kStopped); |
| 656 pending_callbacks_.reset(); | 658 pending_callbacks_.reset(); |
| 657 filter_collection_.reset(); | 659 filter_collection_.reset(); |
| 658 audio_renderer_.reset(); | 660 audio_renderer_.reset(); |
| 659 video_renderer_.reset(); | 661 video_renderer_.reset(); |
| 660 demuxer_ = NULL; | 662 demuxer_.reset(); |
|
scherkus (not reviewing)
2013/04/17 17:21:59
I'm still skeptical that we should be deleting the
| |
| 661 | 663 |
| 662 // If we stop during initialization/seeking we want to run |seek_cb_| | 664 // If we stop during initialization/seeking we want to run |seek_cb_| |
| 663 // followed by |stop_cb_| so we don't leave outstanding callbacks around. | 665 // followed by |stop_cb_| so we don't leave outstanding callbacks around. |
| 664 if (!seek_cb_.is_null()) { | 666 if (!seek_cb_.is_null()) { |
| 665 base::ResetAndReturn(&seek_cb_).Run(status_); | 667 base::ResetAndReturn(&seek_cb_).Run(status_); |
| 666 error_cb_.Reset(); | 668 error_cb_.Reset(); |
| 667 } | 669 } |
| 668 if (!stop_cb_.is_null()) { | 670 if (!stop_cb_.is_null()) { |
| 669 base::ResetAndReturn(&stop_cb_).Run(); | 671 base::ResetAndReturn(&stop_cb_).Run(); |
| 670 error_cb_.Reset(); | 672 error_cb_.Reset(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) { | 906 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) { |
| 905 DCHECK(message_loop_->BelongsToCurrentThread()); | 907 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 906 | 908 |
| 907 demuxer_ = filter_collection_->GetDemuxer(); | 909 demuxer_ = filter_collection_->GetDemuxer(); |
| 908 demuxer_->Initialize(this, done_cb); | 910 demuxer_->Initialize(this, done_cb); |
| 909 } | 911 } |
| 910 | 912 |
| 911 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) { | 913 void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) { |
| 912 DCHECK(message_loop_->BelongsToCurrentThread()); | 914 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 913 | 915 |
| 914 scoped_refptr<DemuxerStream> stream = | |
| 915 demuxer_->GetStream(DemuxerStream::AUDIO); | |
| 916 DCHECK(stream); | |
| 917 | |
| 918 audio_renderer_ = filter_collection_->GetAudioRenderer(); | 916 audio_renderer_ = filter_collection_->GetAudioRenderer(); |
| 919 audio_renderer_->Initialize( | 917 audio_renderer_->Initialize( |
| 920 stream, | 918 demuxer_->GetStream(DemuxerStream::AUDIO), |
| 921 done_cb, | 919 done_cb, |
| 922 base::Bind(&Pipeline::OnUpdateStatistics, this), | 920 base::Bind(&Pipeline::OnUpdateStatistics, this), |
| 923 base::Bind(&Pipeline::OnAudioUnderflow, this), | 921 base::Bind(&Pipeline::OnAudioUnderflow, this), |
| 924 base::Bind(&Pipeline::OnAudioTimeUpdate, this), | 922 base::Bind(&Pipeline::OnAudioTimeUpdate, this), |
| 925 base::Bind(&Pipeline::OnAudioRendererEnded, this), | 923 base::Bind(&Pipeline::OnAudioRendererEnded, this), |
| 926 base::Bind(&Pipeline::OnAudioDisabled, this), | 924 base::Bind(&Pipeline::OnAudioDisabled, this), |
| 927 base::Bind(&Pipeline::SetError, this)); | 925 base::Bind(&Pipeline::SetError, this)); |
| 928 } | 926 } |
| 929 | 927 |
| 930 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { | 928 void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { |
| 931 DCHECK(message_loop_->BelongsToCurrentThread()); | 929 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 932 | 930 |
| 933 scoped_refptr<DemuxerStream> stream = | 931 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 934 demuxer_->GetStream(DemuxerStream::VIDEO); | |
| 935 DCHECK(stream); | |
| 936 | 932 |
| 937 { | 933 { |
| 938 // Get an initial natural size so we have something when we signal | 934 // Get an initial natural size so we have something when we signal |
| 939 // the kHaveMetadata buffering state. | 935 // the kHaveMetadata buffering state. |
| 940 base::AutoLock l(lock_); | 936 base::AutoLock l(lock_); |
| 941 natural_size_ = stream->video_decoder_config().natural_size(); | 937 natural_size_ = stream->video_decoder_config().natural_size(); |
| 942 } | 938 } |
| 943 | 939 |
| 944 video_renderer_ = filter_collection_->GetVideoRenderer(); | 940 video_renderer_ = filter_collection_->GetVideoRenderer(); |
| 945 video_renderer_->Initialize( | 941 video_renderer_->Initialize( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 971 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 967 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
| 972 lock_.AssertAcquired(); | 968 lock_.AssertAcquired(); |
| 973 if (!waiting_for_clock_update_) | 969 if (!waiting_for_clock_update_) |
| 974 return; | 970 return; |
| 975 | 971 |
| 976 waiting_for_clock_update_ = false; | 972 waiting_for_clock_update_ = false; |
| 977 clock_->Play(); | 973 clock_->Play(); |
| 978 } | 974 } |
| 979 | 975 |
| 980 } // namespace media | 976 } // namespace media |
| OLD | NEW |