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_impl.h" | 5 #include "media/base/pipeline_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 running_(false), | 40 running_(false), |
| 41 did_loading_progress_(false), | 41 did_loading_progress_(false), |
| 42 volume_(1.0f), | 42 volume_(1.0f), |
| 43 playback_rate_(0.0), | 43 playback_rate_(0.0), |
| 44 status_(PIPELINE_OK), | 44 status_(PIPELINE_OK), |
| 45 state_(kCreated), | 45 state_(kCreated), |
| 46 suspend_timestamp_(kNoTimestamp()), | 46 suspend_timestamp_(kNoTimestamp()), |
| 47 renderer_ended_(false), | 47 renderer_ended_(false), |
| 48 text_renderer_ended_(false), | 48 text_renderer_ended_(false), |
| 49 demuxer_(NULL), | 49 demuxer_(NULL), |
| 50 pending_cdm_context_(nullptr), | 50 cdm_context_(nullptr), |
| 51 weak_factory_(this) { | 51 weak_factory_(this) { |
| 52 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated)); | 52 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 PipelineImpl::~PipelineImpl() { | 55 PipelineImpl::~PipelineImpl() { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()) | 56 DCHECK(thread_checker_.CalledOnValidThread()) |
| 57 << "Pipeline must be destroyed on same thread that created it"; | 57 << "Pipeline must be destroyed on same thread that created it"; |
| 58 DCHECK(!running_) << "Stop() must complete before destroying object"; | 58 DCHECK(!running_) << "Stop() must complete before destroying object"; |
| 59 DCHECK(stop_cb_.is_null()); | 59 DCHECK(stop_cb_.is_null()); |
| 60 DCHECK(seek_cb_.is_null()); | 60 DCHECK(seek_cb_.is_null()); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 | 526 |
| 527 CHECK_EQ(kCreated, state_) | 527 CHECK_EQ(kCreated, state_) |
| 528 << "Media pipeline cannot be started more than once"; | 528 << "Media pipeline cannot be started more than once"; |
| 529 | 529 |
| 530 text_renderer_ = CreateTextRenderer(); | 530 text_renderer_ = CreateTextRenderer(); |
| 531 if (text_renderer_) { | 531 if (text_renderer_) { |
| 532 text_renderer_->Initialize(base::Bind(&PipelineImpl::OnTextRendererEnded, | 532 text_renderer_->Initialize(base::Bind(&PipelineImpl::OnTextRendererEnded, |
| 533 weak_factory_.GetWeakPtr())); | 533 weak_factory_.GetWeakPtr())); |
| 534 } | 534 } |
| 535 | 535 |
| 536 // Set CDM early to avoid unnecessary delay in Renderer::Initialize(). | |
| 537 if (pending_cdm_context_) { | |
| 538 renderer_->SetCdm(pending_cdm_context_, base::Bind(&IgnoreCdmAttached)); | |
| 539 pending_cdm_context_ = nullptr; | |
| 540 } | |
| 541 | |
| 542 StateTransitionTask(PIPELINE_OK); | 536 StateTransitionTask(PIPELINE_OK); |
| 543 } | 537 } |
| 544 | 538 |
| 545 void PipelineImpl::StopTask(const base::Closure& stop_cb) { | 539 void PipelineImpl::StopTask(const base::Closure& stop_cb) { |
| 546 DCHECK(task_runner_->BelongsToCurrentThread()); | 540 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 547 DCHECK(stop_cb_.is_null()); | 541 DCHECK(stop_cb_.is_null()); |
| 548 | 542 |
| 549 if (state_ == kStopped) { | 543 if (state_ == kStopped) { |
| 550 // Invalid all weak pointers so it's safe to destroy |this| on the render | 544 // Invalid all weak pointers so it's safe to destroy |this| on the render |
| 551 // main thread. | 545 // main thread. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 fns.Push(base::Bind(&PipelineImpl::InitializeRenderer, weak_this)); | 729 fns.Push(base::Bind(&PipelineImpl::InitializeRenderer, weak_this)); |
| 736 | 730 |
| 737 pending_callbacks_ = SerialRunner::Run( | 731 pending_callbacks_ = SerialRunner::Run( |
| 738 fns, base::Bind(&PipelineImpl::StateTransitionTask, weak_this)); | 732 fns, base::Bind(&PipelineImpl::StateTransitionTask, weak_this)); |
| 739 } | 733 } |
| 740 | 734 |
| 741 void PipelineImpl::SetCdmTask(CdmContext* cdm_context, | 735 void PipelineImpl::SetCdmTask(CdmContext* cdm_context, |
| 742 const CdmAttachedCB& cdm_attached_cb) { | 736 const CdmAttachedCB& cdm_attached_cb) { |
| 743 base::AutoLock auto_lock(lock_); | 737 base::AutoLock auto_lock(lock_); |
| 744 if (!renderer_) { | 738 if (!renderer_) { |
| 745 pending_cdm_context_ = cdm_context; | 739 cdm_context_ = cdm_context; |
| 746 cdm_attached_cb.Run(true); | 740 cdm_attached_cb.Run(true); |
| 747 return; | 741 return; |
| 748 } | 742 } |
| 749 | 743 |
| 750 renderer_->SetCdm(cdm_context, cdm_attached_cb); | 744 renderer_->SetCdm(cdm_context, base::Bind(&PipelineImpl::OnCdmAttached, |
| 745 weak_factory_.GetWeakPtr(), | |
|
xhwang
2016/03/17 23:11:15
It seems we are already calling GetWeakPtr() on tw
sandersd (OOO until July 31)
2016/03/17 23:25:03
It's safe to call from two threads; the rule is th
xhwang
2016/03/18 17:05:55
+wez
GetWeakPtr() call is not thread safe accordi
Wez
2016/03/18 19:49:28
GetWeakPtr is safe to call from different threads,
xhwang
2016/03/18 20:05:34
This is one of the oldest piece of our code base a
| |
| 746 cdm_attached_cb, cdm_context)); | |
| 747 } | |
| 748 | |
| 749 void PipelineImpl::OnCdmAttached(const CdmAttachedCB& cdm_attached_cb, | |
| 750 CdmContext* cdm_context, | |
| 751 bool success) { | |
| 752 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 753 if (success) | |
| 754 cdm_context_ = cdm_context; | |
| 755 cdm_attached_cb.Run(success); | |
| 751 } | 756 } |
| 752 | 757 |
| 753 void PipelineImpl::OnRendererEnded() { | 758 void PipelineImpl::OnRendererEnded() { |
| 754 DCHECK(task_runner_->BelongsToCurrentThread()); | 759 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 755 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); | 760 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); |
| 756 | 761 |
| 757 if (state_ != kPlaying) | 762 if (state_ != kPlaying) |
| 758 return; | 763 return; |
| 759 | 764 |
| 760 DCHECK(!renderer_ended_); | 765 DCHECK(!renderer_ended_); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 if (!demuxer_->GetStream(DemuxerStream::AUDIO) && | 838 if (!demuxer_->GetStream(DemuxerStream::AUDIO) && |
| 834 !demuxer_->GetStream(DemuxerStream::VIDEO)) { | 839 !demuxer_->GetStream(DemuxerStream::VIDEO)) { |
| 835 { | 840 { |
| 836 base::AutoLock auto_lock(lock_); | 841 base::AutoLock auto_lock(lock_); |
| 837 renderer_.reset(); | 842 renderer_.reset(); |
| 838 } | 843 } |
| 839 OnError(PIPELINE_ERROR_COULD_NOT_RENDER); | 844 OnError(PIPELINE_ERROR_COULD_NOT_RENDER); |
| 840 return; | 845 return; |
| 841 } | 846 } |
| 842 | 847 |
| 848 if (cdm_context_) | |
| 849 renderer_->SetCdm(cdm_context_, base::Bind(&IgnoreCdmAttached)); | |
| 850 | |
| 843 base::WeakPtr<PipelineImpl> weak_this = weak_factory_.GetWeakPtr(); | 851 base::WeakPtr<PipelineImpl> weak_this = weak_factory_.GetWeakPtr(); |
| 844 renderer_->Initialize( | 852 renderer_->Initialize( |
| 845 demuxer_, done_cb, | 853 demuxer_, done_cb, |
| 846 base::Bind(&PipelineImpl::OnUpdateStatistics, weak_this), | 854 base::Bind(&PipelineImpl::OnUpdateStatistics, weak_this), |
| 847 base::Bind(&PipelineImpl::BufferingStateChanged, weak_this), | 855 base::Bind(&PipelineImpl::BufferingStateChanged, weak_this), |
| 848 base::Bind(&PipelineImpl::OnRendererEnded, weak_this), | 856 base::Bind(&PipelineImpl::OnRendererEnded, weak_this), |
| 849 base::Bind(&PipelineImpl::OnError, weak_this), | 857 base::Bind(&PipelineImpl::OnError, weak_this), |
| 850 waiting_for_decryption_key_cb_); | 858 waiting_for_decryption_key_cb_); |
| 851 } | 859 } |
| 852 | 860 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 866 metadata_cb_.Run(metadata); | 874 metadata_cb_.Run(metadata); |
| 867 } | 875 } |
| 868 | 876 |
| 869 void PipelineImpl::BufferingStateChanged(BufferingState new_buffering_state) { | 877 void PipelineImpl::BufferingStateChanged(BufferingState new_buffering_state) { |
| 870 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; | 878 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; |
| 871 DCHECK(task_runner_->BelongsToCurrentThread()); | 879 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 872 buffering_state_cb_.Run(new_buffering_state); | 880 buffering_state_cb_.Run(new_buffering_state); |
| 873 } | 881 } |
| 874 | 882 |
| 875 } // namespace media | 883 } // namespace media |
| OLD | NEW |