| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 // Accumulated statistics reported by the renderer. | 92 // Accumulated statistics reported by the renderer. |
| 93 PipelineStatistics statistics; | 93 PipelineStatistics statistics; |
| 94 | 94 |
| 95 // The media timestamp to return while the pipeline is suspended. | 95 // The media timestamp to return while the pipeline is suspended. |
| 96 // Otherwise set to kNoTimestamp. | 96 // Otherwise set to kNoTimestamp. |
| 97 base::TimeDelta suspend_timestamp = kNoTimestamp; | 97 base::TimeDelta suspend_timestamp = kNoTimestamp; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // DemuxerHost implementaion. | 100 // DemuxerHost implementaion. |
| 101 void OnMetadata(PipelineMetadata metadata) final; |
| 101 void OnBufferedTimeRangesChanged(const Ranges<base::TimeDelta>& ranges) final; | 102 void OnBufferedTimeRangesChanged(const Ranges<base::TimeDelta>& ranges) final; |
| 102 void SetDuration(base::TimeDelta duration) final; | 103 void SetDuration(base::TimeDelta duration) final; |
| 103 void OnDemuxerError(PipelineStatus error) final; | 104 void OnDemuxerError(PipelineStatus error) final; |
| 104 void AddTextStream(DemuxerStream* text_stream, | 105 void AddTextStream(DemuxerStream* text_stream, |
| 105 const TextTrackConfig& config) final; | 106 const TextTrackConfig& config) final; |
| 106 void RemoveTextStream(DemuxerStream* text_stream) final; | 107 void RemoveTextStream(DemuxerStream* text_stream) final; |
| 107 | 108 |
| 108 // RendererClient implementation. | 109 // RendererClient implementation. |
| 109 void OnError(PipelineStatus error) final; | 110 void OnError(PipelineStatus error) final; |
| 110 void OnEnded() final; | 111 void OnEnded() final; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 128 bool success); | 129 bool success); |
| 129 void CheckPlaybackEnded(); | 130 void CheckPlaybackEnded(); |
| 130 | 131 |
| 131 // State transition tasks. | 132 // State transition tasks. |
| 132 void SetState(State next_state); | 133 void SetState(State next_state); |
| 133 void CompleteSeek(base::TimeDelta seek_time, PipelineStatus status); | 134 void CompleteSeek(base::TimeDelta seek_time, PipelineStatus status); |
| 134 void CompleteSuspend(PipelineStatus status); | 135 void CompleteSuspend(PipelineStatus status); |
| 135 void InitializeDemuxer(const PipelineStatusCB& done_cb); | 136 void InitializeDemuxer(const PipelineStatusCB& done_cb); |
| 136 void InitializeRenderer(const PipelineStatusCB& done_cb); | 137 void InitializeRenderer(const PipelineStatusCB& done_cb); |
| 137 void DestroyRenderer(); | 138 void DestroyRenderer(); |
| 138 void ReportMetadata(); | |
| 139 | 139 |
| 140 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 140 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
| 141 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 141 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 142 const scoped_refptr<MediaLog> media_log_; | 142 const scoped_refptr<MediaLog> media_log_; |
| 143 | 143 |
| 144 base::WeakPtr<PipelineImpl> weak_pipeline_; | 144 base::WeakPtr<PipelineImpl> weak_pipeline_; |
| 145 Demuxer* demuxer_; | 145 Demuxer* demuxer_; |
| 146 std::unique_ptr<TextRenderer> text_renderer_; | 146 std::unique_ptr<TextRenderer> text_renderer_; |
| 147 double playback_rate_; | 147 double playback_rate_; |
| 148 float volume_; | 148 float volume_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 weak_pipeline_ = weak_pipeline; | 235 weak_pipeline_ = weak_pipeline; |
| 236 | 236 |
| 237 // Queue asynchronous actions required to start. | 237 // Queue asynchronous actions required to start. |
| 238 DCHECK(!pending_callbacks_); | 238 DCHECK(!pending_callbacks_); |
| 239 SerialRunner::Queue fns; | 239 SerialRunner::Queue fns; |
| 240 | 240 |
| 241 // Initialize demuxer. | 241 // Initialize demuxer. |
| 242 fns.Push(base::Bind(&RendererWrapper::InitializeDemuxer, weak_this_)); | 242 fns.Push(base::Bind(&RendererWrapper::InitializeDemuxer, weak_this_)); |
| 243 | 243 |
| 244 // Once the demuxer is initialized successfully, media metadata must be | |
| 245 // available - report the metadata to client. | |
| 246 fns.Push(base::Bind(&RendererWrapper::ReportMetadata, weak_this_)); | |
| 247 | |
| 248 // Initialize renderer. | 244 // Initialize renderer. |
| 249 fns.Push(base::Bind(&RendererWrapper::InitializeRenderer, weak_this_)); | 245 fns.Push(base::Bind(&RendererWrapper::InitializeRenderer, weak_this_)); |
| 250 | 246 |
| 251 // Run tasks. | 247 // Run tasks. |
| 252 pending_callbacks_ = | 248 pending_callbacks_ = |
| 253 SerialRunner::Run(fns, base::Bind(&RendererWrapper::CompleteSeek, | 249 SerialRunner::Run(fns, base::Bind(&RendererWrapper::CompleteSeek, |
| 254 weak_this_, base::TimeDelta())); | 250 weak_this_, base::TimeDelta())); |
| 255 } | 251 } |
| 256 | 252 |
| 257 void PipelineImpl::RendererWrapper::Stop(const base::Closure& stop_cb) { | 253 void PipelineImpl::RendererWrapper::Stop(const base::Closure& stop_cb) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 cdm_context_ = cdm_context; | 475 cdm_context_ = cdm_context; |
| 480 cdm_attached_cb.Run(true); | 476 cdm_attached_cb.Run(true); |
| 481 return; | 477 return; |
| 482 } | 478 } |
| 483 | 479 |
| 484 shared_state_.renderer->SetCdm( | 480 shared_state_.renderer->SetCdm( |
| 485 cdm_context, base::Bind(&RendererWrapper::OnCdmAttached, weak_this_, | 481 cdm_context, base::Bind(&RendererWrapper::OnCdmAttached, weak_this_, |
| 486 cdm_attached_cb, cdm_context)); | 482 cdm_attached_cb, cdm_context)); |
| 487 } | 483 } |
| 488 | 484 |
| 485 void PipelineImpl::RendererWrapper::OnMetadata(PipelineMetadata metadata) { |
| 486 main_task_runner_->PostTask(FROM_HERE, base::Bind(&PipelineImpl::OnMetadata, |
| 487 weak_pipeline_, metadata)); |
| 488 } |
| 489 |
| 489 void PipelineImpl::RendererWrapper::OnBufferedTimeRangesChanged( | 490 void PipelineImpl::RendererWrapper::OnBufferedTimeRangesChanged( |
| 490 const Ranges<base::TimeDelta>& ranges) { | 491 const Ranges<base::TimeDelta>& ranges) { |
| 491 // TODO(alokp): Add thread DCHECK after ensuring that all Demuxer | 492 // TODO(alokp): Add thread DCHECK after ensuring that all Demuxer |
| 492 // implementations call DemuxerHost on the media thread. | 493 // implementations call DemuxerHost on the media thread. |
| 493 base::AutoLock auto_lock(shared_state_lock_); | 494 base::AutoLock auto_lock(shared_state_lock_); |
| 494 shared_state_.did_loading_progress = true; | 495 shared_state_.did_loading_progress = true; |
| 495 shared_state_.buffered_time_ranges = ranges; | 496 shared_state_.buffered_time_ranges = ranges; |
| 496 } | 497 } |
| 497 | 498 |
| 498 void PipelineImpl::RendererWrapper::SetDuration(base::TimeDelta duration) { | 499 void PipelineImpl::RendererWrapper::SetDuration(base::TimeDelta duration) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 839 |
| 839 // Destroy the renderer outside the lock scope to avoid holding the lock | 840 // Destroy the renderer outside the lock scope to avoid holding the lock |
| 840 // while renderer is being destroyed (in case Renderer destructor is costly). | 841 // while renderer is being destroyed (in case Renderer destructor is costly). |
| 841 std::unique_ptr<Renderer> renderer; | 842 std::unique_ptr<Renderer> renderer; |
| 842 { | 843 { |
| 843 base::AutoLock auto_lock(shared_state_lock_); | 844 base::AutoLock auto_lock(shared_state_lock_); |
| 844 renderer.swap(shared_state_.renderer); | 845 renderer.swap(shared_state_.renderer); |
| 845 } | 846 } |
| 846 } | 847 } |
| 847 | 848 |
| 848 void PipelineImpl::RendererWrapper::ReportMetadata() { | |
| 849 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 850 | |
| 851 PipelineMetadata metadata; | |
| 852 metadata.timeline_offset = demuxer_->GetTimelineOffset(); | |
| 853 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | |
| 854 if (stream) { | |
| 855 metadata.has_video = true; | |
| 856 metadata.natural_size = stream->video_decoder_config().natural_size(); | |
| 857 metadata.video_rotation = stream->video_rotation(); | |
| 858 } | |
| 859 if (demuxer_->GetStream(DemuxerStream::AUDIO)) { | |
| 860 metadata.has_audio = true; | |
| 861 } | |
| 862 | |
| 863 main_task_runner_->PostTask(FROM_HERE, base::Bind(&PipelineImpl::OnMetadata, | |
| 864 weak_pipeline_, metadata)); | |
| 865 } | |
| 866 | |
| 867 PipelineImpl::PipelineImpl( | 849 PipelineImpl::PipelineImpl( |
| 868 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 850 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 869 MediaLog* media_log) | 851 MediaLog* media_log) |
| 870 : media_task_runner_(media_task_runner), | 852 : media_task_runner_(media_task_runner), |
| 871 media_log_(media_log), | 853 media_log_(media_log), |
| 872 client_(nullptr), | 854 client_(nullptr), |
| 873 playback_rate_(kDefaultPlaybackRate), | 855 playback_rate_(kDefaultPlaybackRate), |
| 874 volume_(kDefaultVolume), | 856 volume_(kDefaultVolume), |
| 875 weak_factory_(this) { | 857 weak_factory_(this) { |
| 876 DVLOG(2) << __func__; | 858 DVLOG(2) << __func__; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 void PipelineImpl::OnSuspendDone() { | 1217 void PipelineImpl::OnSuspendDone() { |
| 1236 DVLOG(3) << __func__; | 1218 DVLOG(3) << __func__; |
| 1237 DCHECK(thread_checker_.CalledOnValidThread()); | 1219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1238 DCHECK(IsRunning()); | 1220 DCHECK(IsRunning()); |
| 1239 | 1221 |
| 1240 DCHECK(!suspend_cb_.is_null()); | 1222 DCHECK(!suspend_cb_.is_null()); |
| 1241 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK); | 1223 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK); |
| 1242 } | 1224 } |
| 1243 | 1225 |
| 1244 } // namespace media | 1226 } // namespace media |
| OLD | NEW |