| Index: media/base/pipeline_impl.h
|
| diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h
|
| index 3a8a90a0ac58d6914c4a9e49e4f134e9b646da14..beb0b010492b908fc56ffcbc6de193779f045ac2 100644
|
| --- a/media/base/pipeline_impl.h
|
| +++ b/media/base/pipeline_impl.h
|
| @@ -7,23 +7,12 @@
|
|
|
| #include <memory>
|
|
|
| -#include "base/gtest_prod_util.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "base/synchronization/lock.h"
|
| #include "base/threading/thread_checker.h"
|
| -#include "base/time/time.h"
|
| -#include "media/base/buffering_state.h"
|
| -#include "media/base/cdm_context.h"
|
| -#include "media/base/demuxer.h"
|
| #include "media/base/media_export.h"
|
| #include "media/base/pipeline.h"
|
| -#include "media/base/pipeline_status.h"
|
| -#include "media/base/ranges.h"
|
| -#include "media/base/renderer_client.h"
|
| -#include "media/base/serial_runner.h"
|
| -#include "media/base/text_track.h"
|
|
|
| namespace base {
|
| class SingleThreadTaskRunner;
|
| @@ -32,7 +21,6 @@ class SingleThreadTaskRunner;
|
| namespace media {
|
|
|
| class MediaLog;
|
| -class Renderer;
|
| class TextRenderer;
|
|
|
| // Pipeline runs the media pipeline. Filters are created and called on the
|
| @@ -75,9 +63,7 @@ class TextRenderer;
|
| // TODO(sandersd): It should be possible to pass through Suspended when going
|
| // from InitDemuxer to InitRenderer, thereby eliminating the Resuming state.
|
| // Some annoying differences between the two paths need to be removed first.
|
| -class MEDIA_EXPORT PipelineImpl : public Pipeline,
|
| - public DemuxerHost,
|
| - public RendererClient {
|
| +class MEDIA_EXPORT PipelineImpl : public Pipeline {
|
| public:
|
| // Constructs a media pipeline that will execute media tasks on
|
| // |media_task_runner|.
|
| @@ -86,9 +72,6 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline,
|
| MediaLog* media_log);
|
| ~PipelineImpl() override;
|
|
|
| - void SetErrorForTesting(PipelineStatus status);
|
| - bool HasWeakPtrsForTesting() const;
|
| -
|
| // Pipeline implementation.
|
| void Start(Demuxer* demuxer,
|
| std::unique_ptr<Renderer> renderer,
|
| @@ -96,13 +79,13 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline,
|
| const PipelineStatusCB& seek_cb) override;
|
| void Stop() override;
|
| void Seek(base::TimeDelta time, const PipelineStatusCB& seek_cb) override;
|
| - bool IsRunning() const override;
|
| - double GetPlaybackRate() const override;
|
| - void SetPlaybackRate(double playback_rate) override;
|
| void Suspend(const PipelineStatusCB& suspend_cb) override;
|
| void Resume(std::unique_ptr<Renderer> renderer,
|
| - base::TimeDelta timestamp,
|
| + base::TimeDelta time,
|
| const PipelineStatusCB& seek_cb) override;
|
| + bool IsRunning() const override;
|
| + double GetPlaybackRate() const override;
|
| + void SetPlaybackRate(double playback_rate) override;
|
| float GetVolume() const override;
|
| void SetVolume(float volume) override;
|
| base::TimeDelta GetMediaTime() const override;
|
| @@ -115,9 +98,11 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline,
|
|
|
| private:
|
| friend class MediaLog;
|
| - friend class PipelineImplTest;
|
| + class RendererWrapper;
|
|
|
| // Pipeline states, as described above.
|
| + // TODO(alokp): Move this to RendererWrapper after removing the references
|
| + // from MediaLog.
|
| enum State {
|
| kCreated,
|
| kInitDemuxer,
|
| @@ -130,212 +115,66 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline,
|
| kSuspended,
|
| kResuming,
|
| };
|
| -
|
| - // Updates |state_|. All state transitions should use this call.
|
| - void SetState(State next_state);
|
| -
|
| static const char* GetStateString(State state);
|
| - State GetNextState() const;
|
| -
|
| - // Helper method that runs & resets |seek_cb_| and resets |seek_timestamp_|
|
| - // and |seek_pending_|.
|
| - void FinishSeek();
|
| -
|
| - // DemuxerHost implementaion.
|
| - void OnBufferedTimeRangesChanged(
|
| - const Ranges<base::TimeDelta>& ranges) override;
|
| - void SetDuration(base::TimeDelta duration) override;
|
| - void OnDemuxerError(PipelineStatus error) override;
|
| - void AddTextStream(DemuxerStream* text_stream,
|
| - const TextTrackConfig& config) override;
|
| - void RemoveTextStream(DemuxerStream* text_stream) override;
|
| -
|
| - // RendererClient implementation.
|
| - void OnError(PipelineStatus error) override;
|
| - void OnEnded() override;
|
| - void OnStatisticsUpdate(const PipelineStatistics& stats) override;
|
| - void OnBufferingStateChange(BufferingState state) override;
|
| - void OnWaitingForDecryptionKey() override;
|
| - void OnVideoNaturalSizeChange(const gfx::Size& size) override;
|
| - void OnVideoOpacityChange(bool opaque) override;
|
| -
|
| - // The following "task" methods correspond to the public methods, but these
|
| - // methods are run as the result of posting a task to the Pipeline's
|
| - // task runner.
|
| - void StartTask();
|
| -
|
| - // Suspends the pipeline, discarding the current renderer.
|
| - void SuspendTask(const PipelineStatusCB& suspend_cb);
|
| -
|
| - // Resumes the pipeline with a new renderer, and initializes it with a seek.
|
| - void ResumeTask(std::unique_ptr<Renderer> renderer,
|
| - base::TimeDelta timestamp,
|
| - const PipelineStatusCB& seek_sb);
|
| -
|
| - // Stops and destroys all filters, placing the pipeline in the kStopped state.
|
| - void StopTask(const base::Closure& stop_cb);
|
| -
|
| - // Carries out stopping and destroying all filters, placing the pipeline in
|
| - // the kStopped state.
|
| - void ErrorChangedTask(PipelineStatus error);
|
|
|
| - // Carries out notifying filters that the playback rate has changed.
|
| - void PlaybackRateChangedTask(double playback_rate);
|
| -
|
| - // Carries out notifying filters that the volume has changed.
|
| - void VolumeChangedTask(float volume);
|
| -
|
| - // Carries out notifying filters that we are seeking to a new timestamp.
|
| - void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb);
|
| -
|
| - // Carries out setting the |cdm_context| in |renderer_|, and then fires
|
| - // |cdm_attached_cb| with the result. If |renderer_| is null,
|
| - // |cdm_attached_cb| will be fired immediately with true, and |cdm_context|
|
| - // will be set in |renderer_| later when |renderer_| is created.
|
| - void SetCdmTask(CdmContext* cdm_context,
|
| - const CdmAttachedCB& cdm_attached_cb);
|
| - void OnCdmAttached(const CdmAttachedCB& cdm_attached_cb,
|
| - CdmContext* cdm_context,
|
| - bool success);
|
| -
|
| - // Callbacks executed when text renderer has ended.
|
| - void OnTextRendererEnded();
|
| - void RunEndedCallbackIfNeeded();
|
| -
|
| - std::unique_ptr<TextRenderer> CreateTextRenderer();
|
| -
|
| - // Carries out adding a new text stream to the text renderer.
|
| - void AddTextStreamTask(DemuxerStream* text_stream,
|
| - const TextTrackConfig& config);
|
| -
|
| - // Carries out removing a text stream from the text renderer.
|
| - void RemoveTextStreamTask(DemuxerStream* text_stream);
|
| -
|
| - // Callbacks executed when a text track is added.
|
| + // Notifications from RendererWrapper.
|
| + void OnError(PipelineStatus error);
|
| + void OnEnded();
|
| + void OnMetadata(PipelineMetadata metadata);
|
| + void OnBufferingStateChange(BufferingState state);
|
| + void OnDurationChange(base::TimeDelta duration);
|
| void OnAddTextTrack(const TextTrackConfig& config,
|
| const AddTextTrackDoneCB& done_cb);
|
| + void OnWaitingForDecryptionKey();
|
| + void OnVideoNaturalSizeChange(const gfx::Size& size);
|
| + void OnVideoOpacityChange(bool opaque);
|
| + void OnBufferedTimeRangesChange(const Ranges<base::TimeDelta>& ranges);
|
| + void OnStatisticsUpdate(const PipelineStatistics& stats);
|
|
|
| - // Kicks off initialization for each media object, executing |done_cb| with
|
| - // the result when completed.
|
| - void InitializeDemuxer(const PipelineStatusCB& done_cb);
|
| - void InitializeRenderer(const PipelineStatusCB& done_cb);
|
| + // Task completion callbacks from RendererWrapper.
|
| + void OnSeekDone(base::TimeDelta start_time);
|
| + void OnSuspendDone(base::TimeDelta suspend_time);
|
|
|
| - void StateTransitionTask(PipelineStatus status);
|
| -
|
| - // Initiates an asynchronous pause-flush-seek-preroll call sequence
|
| - // executing |done_cb| with the final status when completed.
|
| - void DoSeek(base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb);
|
| -
|
| - // Stops media rendering and executes |stop_cb_| when done.
|
| - void DoStop();
|
| -
|
| - void ReportMetadata();
|
| -
|
| - // Task runner of the thread on which this class is constructed.
|
| - // Also used to post notifications on Pipeline::Client object.
|
| - const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
|
| -
|
| - // Task runner used to execute pipeline tasks.
|
| + // Parameters passed in the constructor.
|
| const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
|
| + const scoped_refptr<MediaLog> media_log_;
|
|
|
| - // MediaLog to which to log events.
|
| - scoped_refptr<MediaLog> media_log_;
|
| + // Pipeline client. Valid only while the pipeline is running.
|
| + Client* client_;
|
|
|
| - // Lock used to serialize access for the following data members.
|
| - mutable base::Lock lock_;
|
| + // RendererWrapper instance that runs on the media thread.
|
| + std::unique_ptr<RendererWrapper> renderer_wrapper_;
|
|
|
| - // Whether or not the pipeline is running.
|
| - bool running_;
|
| + // Temporary callback used for Start(), Seek(), and Resume().
|
| + PipelineStatusCB seek_cb_;
|
|
|
| - // Amount of available buffered data as reported by |demuxer_|.
|
| - Ranges<base::TimeDelta> buffered_time_ranges_;
|
| + // Temporary callback used for Suspend().
|
| + PipelineStatusCB suspend_cb_;
|
|
|
| - // True when OnBufferedTimeRangesChanged() has been called more recently than
|
| - // DidLoadingProgress().
|
| - bool did_loading_progress_;
|
| + // Current playback rate (>= 0.0). This value is set immediately via
|
| + // SetPlaybackRate() and a task is dispatched on the task runner to notify
|
| + // the filters.
|
| + double playback_rate_;
|
|
|
| - // Current volume level (from 0.0f to 1.0f). This value is set immediately
|
| + // Current volume level (from 0.0f to 1.0f). This value is set immediately
|
| // via SetVolume() and a task is dispatched on the task runner to notify the
|
| // filters.
|
| float volume_;
|
|
|
| - // Current playback rate (>= 0.0). This value is set immediately via
|
| - // SetPlaybackRate() and a task is dispatched on the task runner to notify
|
| - // the filters.
|
| - double playback_rate_;
|
| + // Amount of available buffered data as reported by Demuxer.
|
| + Ranges<base::TimeDelta> buffered_time_ranges_;
|
|
|
| - // Current duration as reported by |demuxer_|.
|
| + // Current duration as reported by Demuxer.
|
| base::TimeDelta duration_;
|
|
|
| - // Status of the pipeline. Initialized to PIPELINE_OK which indicates that
|
| - // the pipeline is operating correctly. Any other value indicates that the
|
| - // pipeline is stopped or is stopping. Clients can call the Stop() method to
|
| - // reset the pipeline state, and restore this to PIPELINE_OK.
|
| - PipelineStatus status_;
|
| -
|
| - // The following data members are only accessed by tasks posted to
|
| - // |task_runner_|.
|
| -
|
| - // Member that tracks the current state.
|
| - State state_;
|
| -
|
| - // The timestamp to start playback from after starting/seeking/resuming has
|
| - // completed.
|
| - base::TimeDelta start_timestamp_;
|
| -
|
| - // The media timestamp to return while the pipeline is suspended. Otherwise
|
| - // set to kNoTimestamp().
|
| - base::TimeDelta suspend_timestamp_;
|
| -
|
| - // Whether we've received the audio/video/text ended events.
|
| - bool renderer_ended_;
|
| - bool text_renderer_ended_;
|
| -
|
| - // Temporary callback used for Start(), Seek(), and Resume().
|
| - PipelineStatusCB seek_cb_;
|
| -
|
| - // Temporary callback used for Stop().
|
| - base::Closure stop_cb_;
|
| -
|
| - // Temporary callback used for Suspend().
|
| - PipelineStatusCB suspend_cb_;
|
| -
|
| - // Holds the initialized demuxer. Used for seeking. Owned by client.
|
| - Demuxer* demuxer_;
|
| -
|
| - // Holds the initialized renderers. Used for setting the volume,
|
| - // playback rate, and determining when playback has finished.
|
| - std::unique_ptr<Renderer> renderer_;
|
| - std::unique_ptr<TextRenderer> text_renderer_;
|
| -
|
| - // Holds the client passed on Start().
|
| - // Initialized, Dereferenced, and Invalidated on |main_task_runner_|.
|
| - // Used on |media_task_runner_| to post tasks on |main_task_runner_|.
|
| - base::WeakPtr<Client> weak_client_;
|
| - // Created and destroyed on |main_task_runner_|.
|
| - std::unique_ptr<base::WeakPtrFactory<Client>> client_weak_factory_;
|
| + // True when OnBufferedTimeRangesChange() has been called more recently than
|
| + // DidLoadingProgress().
|
| + bool did_loading_progress_;
|
|
|
| + // Accumulated statistics reported by the renderer.
|
| PipelineStatistics statistics_;
|
|
|
| - std::unique_ptr<SerialRunner> pending_callbacks_;
|
| -
|
| - // The CdmContext to be used to decrypt (and decode) encrypted stream in this
|
| - // pipeline. It is set when SetCdm() succeeds on the renderer (or when
|
| - // SetCdm() is called before Start()), after which it is guaranteed to outlive
|
| - // this pipeline. The saved value will be used to configure new renderers,
|
| - // when starting or resuming.
|
| - CdmContext* cdm_context_;
|
| -
|
| base::ThreadChecker thread_checker_;
|
| -
|
| - // A weak pointer that can be safely copied on the media thread.
|
| - base::WeakPtr<PipelineImpl> weak_this_;
|
| -
|
| - // Weak pointers must be created on the main thread, and must be dereferenced
|
| - // on the media thread.
|
| - //
|
| - // Declared last so that weak pointers will be invalidated before all other
|
| - // member variables.
|
| base::WeakPtrFactory<PipelineImpl> weak_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(PipelineImpl);
|
|
|