| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ | 5 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ |
| 6 #define MEDIA_BASE_PIPELINE_IMPL_H_ | 6 #define MEDIA_BASE_PIPELINE_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 15 #include "media/base/buffering_state.h" | 17 #include "media/base/buffering_state.h" |
| 16 #include "media/base/cdm_context.h" | 18 #include "media/base/cdm_context.h" |
| 17 #include "media/base/demuxer.h" | 19 #include "media/base/demuxer.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // Constructs a media pipeline that will execute on |task_runner|. | 79 // Constructs a media pipeline that will execute on |task_runner|. |
| 78 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 80 PipelineImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 79 MediaLog* media_log); | 81 MediaLog* media_log); |
| 80 ~PipelineImpl() override; | 82 ~PipelineImpl() override; |
| 81 | 83 |
| 82 void SetErrorForTesting(PipelineStatus status); | 84 void SetErrorForTesting(PipelineStatus status); |
| 83 bool HasWeakPtrsForTesting() const; | 85 bool HasWeakPtrsForTesting() const; |
| 84 | 86 |
| 85 // Pipeline implementation. | 87 // Pipeline implementation. |
| 86 void Start(Demuxer* demuxer, | 88 void Start(Demuxer* demuxer, |
| 87 scoped_ptr<Renderer> renderer, | 89 std::unique_ptr<Renderer> renderer, |
| 88 const base::Closure& ended_cb, | 90 const base::Closure& ended_cb, |
| 89 const PipelineStatusCB& error_cb, | 91 const PipelineStatusCB& error_cb, |
| 90 const PipelineStatusCB& seek_cb, | 92 const PipelineStatusCB& seek_cb, |
| 91 const PipelineMetadataCB& metadata_cb, | 93 const PipelineMetadataCB& metadata_cb, |
| 92 const BufferingStateCB& buffering_state_cb, | 94 const BufferingStateCB& buffering_state_cb, |
| 93 const base::Closure& duration_change_cb, | 95 const base::Closure& duration_change_cb, |
| 94 const AddTextTrackCB& add_text_track_cb, | 96 const AddTextTrackCB& add_text_track_cb, |
| 95 const base::Closure& waiting_for_decryption_key_cb) override; | 97 const base::Closure& waiting_for_decryption_key_cb) override; |
| 96 void Stop(const base::Closure& stop_cb) override; | 98 void Stop(const base::Closure& stop_cb) override; |
| 97 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; | 99 void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override; |
| 98 bool IsRunning() const override; | 100 bool IsRunning() const override; |
| 99 double GetPlaybackRate() const override; | 101 double GetPlaybackRate() const override; |
| 100 void SetPlaybackRate(double playback_rate) override; | 102 void SetPlaybackRate(double playback_rate) override; |
| 101 void Suspend(const PipelineStatusCB& suspend_cb) override; | 103 void Suspend(const PipelineStatusCB& suspend_cb) override; |
| 102 void Resume(scoped_ptr<Renderer> renderer, | 104 void Resume(std::unique_ptr<Renderer> renderer, |
| 103 base::TimeDelta timestamp, | 105 base::TimeDelta timestamp, |
| 104 const PipelineStatusCB& seek_cb) override; | 106 const PipelineStatusCB& seek_cb) override; |
| 105 float GetVolume() const override; | 107 float GetVolume() const override; |
| 106 void SetVolume(float volume) override; | 108 void SetVolume(float volume) override; |
| 107 base::TimeDelta GetMediaTime() const override; | 109 base::TimeDelta GetMediaTime() const override; |
| 108 Ranges<base::TimeDelta> GetBufferedTimeRanges() const override; | 110 Ranges<base::TimeDelta> GetBufferedTimeRanges() const override; |
| 109 base::TimeDelta GetMediaDuration() const override; | 111 base::TimeDelta GetMediaDuration() const override; |
| 110 bool DidLoadingProgress() override; | 112 bool DidLoadingProgress() override; |
| 111 PipelineStatistics GetStatistics() const override; | 113 PipelineStatistics GetStatistics() const override; |
| 112 void SetCdm(CdmContext* cdm_context, | 114 void SetCdm(CdmContext* cdm_context, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 160 |
| 159 // The following "task" methods correspond to the public methods, but these | 161 // The following "task" methods correspond to the public methods, but these |
| 160 // methods are run as the result of posting a task to the Pipeline's | 162 // methods are run as the result of posting a task to the Pipeline's |
| 161 // task runner. | 163 // task runner. |
| 162 void StartTask(); | 164 void StartTask(); |
| 163 | 165 |
| 164 // Suspends the pipeline, discarding the current renderer. | 166 // Suspends the pipeline, discarding the current renderer. |
| 165 void SuspendTask(const PipelineStatusCB& suspend_cb); | 167 void SuspendTask(const PipelineStatusCB& suspend_cb); |
| 166 | 168 |
| 167 // Resumes the pipeline with a new renderer, and initializes it with a seek. | 169 // Resumes the pipeline with a new renderer, and initializes it with a seek. |
| 168 void ResumeTask(scoped_ptr<Renderer> renderer, | 170 void ResumeTask(std::unique_ptr<Renderer> renderer, |
| 169 base::TimeDelta timestamp, | 171 base::TimeDelta timestamp, |
| 170 const PipelineStatusCB& seek_sb); | 172 const PipelineStatusCB& seek_sb); |
| 171 | 173 |
| 172 // Stops and destroys all filters, placing the pipeline in the kStopped state. | 174 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
| 173 void StopTask(const base::Closure& stop_cb); | 175 void StopTask(const base::Closure& stop_cb); |
| 174 | 176 |
| 175 // Carries out stopping and destroying all filters, placing the pipeline in | 177 // Carries out stopping and destroying all filters, placing the pipeline in |
| 176 // the kStopped state. | 178 // the kStopped state. |
| 177 void ErrorChangedTask(PipelineStatus error); | 179 void ErrorChangedTask(PipelineStatus error); |
| 178 | 180 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 193 const CdmAttachedCB& cdm_attached_cb); | 195 const CdmAttachedCB& cdm_attached_cb); |
| 194 void OnCdmAttached(const CdmAttachedCB& cdm_attached_cb, | 196 void OnCdmAttached(const CdmAttachedCB& cdm_attached_cb, |
| 195 CdmContext* cdm_context, | 197 CdmContext* cdm_context, |
| 196 bool success); | 198 bool success); |
| 197 | 199 |
| 198 // Callbacks executed when a renderer has ended. | 200 // Callbacks executed when a renderer has ended. |
| 199 void OnRendererEnded(); | 201 void OnRendererEnded(); |
| 200 void OnTextRendererEnded(); | 202 void OnTextRendererEnded(); |
| 201 void RunEndedCallbackIfNeeded(); | 203 void RunEndedCallbackIfNeeded(); |
| 202 | 204 |
| 203 scoped_ptr<TextRenderer> CreateTextRenderer(); | 205 std::unique_ptr<TextRenderer> CreateTextRenderer(); |
| 204 | 206 |
| 205 // Carries out adding a new text stream to the text renderer. | 207 // Carries out adding a new text stream to the text renderer. |
| 206 void AddTextStreamTask(DemuxerStream* text_stream, | 208 void AddTextStreamTask(DemuxerStream* text_stream, |
| 207 const TextTrackConfig& config); | 209 const TextTrackConfig& config); |
| 208 | 210 |
| 209 // Carries out removing a text stream from the text renderer. | 211 // Carries out removing a text stream from the text renderer. |
| 210 void RemoveTextStreamTask(DemuxerStream* text_stream); | 212 void RemoveTextStreamTask(DemuxerStream* text_stream); |
| 211 | 213 |
| 212 // Callbacks executed when a text track is added. | 214 // Callbacks executed when a text track is added. |
| 213 void OnAddTextTrack(const TextTrackConfig& config, | 215 void OnAddTextTrack(const TextTrackConfig& config, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 BufferingStateCB buffering_state_cb_; | 307 BufferingStateCB buffering_state_cb_; |
| 306 base::Closure duration_change_cb_; | 308 base::Closure duration_change_cb_; |
| 307 AddTextTrackCB add_text_track_cb_; | 309 AddTextTrackCB add_text_track_cb_; |
| 308 base::Closure waiting_for_decryption_key_cb_; | 310 base::Closure waiting_for_decryption_key_cb_; |
| 309 | 311 |
| 310 // Holds the initialized demuxer. Used for seeking. Owned by client. | 312 // Holds the initialized demuxer. Used for seeking. Owned by client. |
| 311 Demuxer* demuxer_; | 313 Demuxer* demuxer_; |
| 312 | 314 |
| 313 // Holds the initialized renderers. Used for setting the volume, | 315 // Holds the initialized renderers. Used for setting the volume, |
| 314 // playback rate, and determining when playback has finished. | 316 // playback rate, and determining when playback has finished. |
| 315 scoped_ptr<Renderer> renderer_; | 317 std::unique_ptr<Renderer> renderer_; |
| 316 scoped_ptr<TextRenderer> text_renderer_; | 318 std::unique_ptr<TextRenderer> text_renderer_; |
| 317 | 319 |
| 318 PipelineStatistics statistics_; | 320 PipelineStatistics statistics_; |
| 319 | 321 |
| 320 scoped_ptr<SerialRunner> pending_callbacks_; | 322 std::unique_ptr<SerialRunner> pending_callbacks_; |
| 321 | 323 |
| 322 // The CdmContext to be used to decrypt (and decode) encrypted stream in this | 324 // The CdmContext to be used to decrypt (and decode) encrypted stream in this |
| 323 // pipeline. It is set when SetCdm() succeeds on the renderer (or when | 325 // pipeline. It is set when SetCdm() succeeds on the renderer (or when |
| 324 // SetCdm() is called before Start()), after which it is guaranteed to outlive | 326 // SetCdm() is called before Start()), after which it is guaranteed to outlive |
| 325 // this pipeline. The saved value will be used to configure new renderers, | 327 // this pipeline. The saved value will be used to configure new renderers, |
| 326 // when starting or resuming. | 328 // when starting or resuming. |
| 327 CdmContext* cdm_context_; | 329 CdmContext* cdm_context_; |
| 328 | 330 |
| 329 base::ThreadChecker thread_checker_; | 331 base::ThreadChecker thread_checker_; |
| 330 | 332 |
| 331 // A weak pointer that can be safely copied on the media thread. | 333 // A weak pointer that can be safely copied on the media thread. |
| 332 base::WeakPtr<PipelineImpl> weak_this_; | 334 base::WeakPtr<PipelineImpl> weak_this_; |
| 333 | 335 |
| 334 // Weak pointers must be created on the main thread, and must be dereferenced | 336 // Weak pointers must be created on the main thread, and must be dereferenced |
| 335 // on the media thread. | 337 // on the media thread. |
| 336 // | 338 // |
| 337 // Declared last so that weak pointers will be invalidated before all other | 339 // Declared last so that weak pointers will be invalidated before all other |
| 338 // member variables. | 340 // member variables. |
| 339 base::WeakPtrFactory<PipelineImpl> weak_factory_; | 341 base::WeakPtrFactory<PipelineImpl> weak_factory_; |
| 340 | 342 |
| 341 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 343 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 342 }; | 344 }; |
| 343 | 345 |
| 344 } // namespace media | 346 } // namespace media |
| 345 | 347 |
| 346 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 348 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |