| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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_FILTERS_PIPELINE_CONTROLLER_H_ | 5 #ifndef MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
| 6 #define MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | 6 #define MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 PLAYING, | 34 PLAYING, |
| 35 SEEKING, | 35 SEEKING, |
| 36 SUSPENDING, | 36 SUSPENDING, |
| 37 SUSPENDED, | 37 SUSPENDED, |
| 38 RESUMING, | 38 RESUMING, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 using RendererFactoryCB = base::Callback<scoped_ptr<Renderer>(void)>; | 41 using RendererFactoryCB = base::Callback<scoped_ptr<Renderer>(void)>; |
| 42 using SeekedCB = base::Callback<void(bool time_updated)>; | 42 using SeekedCB = base::Callback<void(bool time_updated)>; |
| 43 using SuspendedCB = base::Callback<void()>; | 43 using SuspendedCB = base::Callback<void()>; |
| 44 using ResumedCB = base::Callback<void()>; | |
| 45 | 44 |
| 46 // Construct a PipelineController wrapping |pipeline_|. |pipeline_| must | 45 // Construct a PipelineController wrapping |pipeline_|. |pipeline_| must |
| 47 // outlive the resulting PipelineController. The callbacks are: | 46 // outlive the resulting PipelineController. The callbacks are: |
| 48 // - |renderer_factory_cb| is called by PipelineController to create new | 47 // - |renderer_factory_cb| is called by PipelineController to create new |
| 49 // renderers when starting and resuming. | 48 // renderers when starting and resuming. |
| 50 // - |seeked_cb| is called upon reaching a stable state if a seek occured. | 49 // - |seeked_cb| is called upon reaching a stable state if a seek occured. |
| 51 // - |suspended_cb| is called immediately after suspendeding. | 50 // - |suspended_cb| is called immediately after suspendeding. |
| 52 // - |resumed_cb| is called immediately after resuming. | |
| 53 // - |error_cb| is called if any operation on |pipeline_| does not result | 51 // - |error_cb| is called if any operation on |pipeline_| does not result |
| 54 // in PIPELINE_OK or its error callback is called. | 52 // in PIPELINE_OK or its error callback is called. |
| 55 PipelineController(Pipeline* pipeline, | 53 PipelineController(Pipeline* pipeline, |
| 56 const RendererFactoryCB& renderer_factory_cb, | 54 const RendererFactoryCB& renderer_factory_cb, |
| 57 const SeekedCB& seeked_cb, | 55 const SeekedCB& seeked_cb, |
| 58 const SuspendedCB& suspended_cb, | 56 const SuspendedCB& suspended_cb, |
| 59 const ResumedCB& resumed_cb, | |
| 60 const PipelineStatusCB& error_cb); | 57 const PipelineStatusCB& error_cb); |
| 61 ~PipelineController(); | 58 ~PipelineController(); |
| 62 | 59 |
| 63 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/ | 60 // Start |pipeline_|. |demuxer| will be retained and StartWaitingForSeek()/ |
| 64 // CancelPendingSeek() will be issued to it as necessary. | 61 // CancelPendingSeek() will be issued to it as necessary. |
| 65 // | 62 // |
| 66 // When |is_streaming| is true, Resume() will always start at the | 63 // When |is_streaming| is true, Resume() will always start at the |
| 67 // beginning of the stream, rather than attempting to seek to the current | 64 // beginning of the stream, rather than attempting to seek to the current |
| 68 // time. | 65 // time. |
| 69 // | 66 // |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 | 94 |
| 98 // Returns true if the current state is stable. This means that |state_| is | 95 // Returns true if the current state is stable. This means that |state_| is |
| 99 // PLAYING and there are no pending operations. Requests are processed | 96 // PLAYING and there are no pending operations. Requests are processed |
| 100 // immediately when the state is stable, otherwise they are queued. | 97 // immediately when the state is stable, otherwise they are queued. |
| 101 // | 98 // |
| 102 // Exceptions to the above: | 99 // Exceptions to the above: |
| 103 // - Start() is processed immediately while in the CREATED state. | 100 // - Start() is processed immediately while in the CREATED state. |
| 104 // - Resume() is processed immediately while in the SUSPENDED state. | 101 // - Resume() is processed immediately while in the SUSPENDED state. |
| 105 bool IsStable(); | 102 bool IsStable(); |
| 106 | 103 |
| 104 // Returns true if the current target state is suspended. |
| 105 bool IsSuspended(); |
| 106 |
| 107 // Returns true if |pipeline_| is suspended. | 107 // Returns true if |pipeline_| is suspended. |
| 108 bool IsSuspended(); | 108 bool IsPipelineSuspended(); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 // Attempts to make progress from the current state to the target state. | 111 // Attempts to make progress from the current state to the target state. |
| 112 void Dispatch(); | 112 void Dispatch(); |
| 113 | 113 |
| 114 // PipelineStaus callback that also carries the target state. | 114 // PipelineStaus callback that also carries the target state. |
| 115 void OnPipelineStatus(State state, PipelineStatus pipeline_status); | 115 void OnPipelineStatus(State state, PipelineStatus pipeline_status); |
| 116 | 116 |
| 117 // The Pipeline we are managing state for. | 117 // The Pipeline we are managing state for. |
| 118 Pipeline* pipeline_ = nullptr; | 118 Pipeline* pipeline_ = nullptr; |
| 119 | 119 |
| 120 // Factory for Renderers, used for Start() and Resume(). | 120 // Factory for Renderers, used for Start() and Resume(). |
| 121 RendererFactoryCB renderer_factory_cb_; | 121 RendererFactoryCB renderer_factory_cb_; |
| 122 | 122 |
| 123 // Called after seeks (which includes Start()) upon reaching a stable state. | 123 // Called after seeks (which includes Start()) upon reaching a stable state. |
| 124 // Multiple seeks result in only one callback if no stable state occurs | 124 // Multiple seeks result in only one callback if no stable state occurs |
| 125 // between them. | 125 // between them. |
| 126 SeekedCB seeked_cb_; | 126 SeekedCB seeked_cb_; |
| 127 | 127 |
| 128 // Called immediately when |pipeline_| completes a suspend operation. | 128 // Called immediately when |pipeline_| completes a suspend operation. |
| 129 SuspendedCB suspended_cb_; | 129 SuspendedCB suspended_cb_; |
| 130 | 130 |
| 131 // Called immediately when |pipeline_| completes a resume operation. | |
| 132 ResumedCB resumed_cb_; | |
| 133 | |
| 134 // Called immediately when any operation on |pipeline_| results in an error. | 131 // Called immediately when any operation on |pipeline_| results in an error. |
| 135 PipelineStatusCB error_cb_; | 132 PipelineStatusCB error_cb_; |
| 136 | 133 |
| 137 // State for handling StartWaitingForSeek()/CancelPendingSeek(). | 134 // State for handling StartWaitingForSeek()/CancelPendingSeek(). |
| 138 Demuxer* demuxer_ = nullptr; | 135 Demuxer* demuxer_ = nullptr; |
| 139 bool waiting_for_seek_ = false; | 136 bool waiting_for_seek_ = false; |
| 140 | 137 |
| 141 // When true, Resume() will start at time zero instead of seeking to the | 138 // When true, Resume() will start at time zero instead of seeking to the |
| 142 // current time. | 139 // current time. |
| 143 bool is_streaming_ = false; | 140 bool is_streaming_ = false; |
| 144 | 141 |
| 145 // When true, seeking to the current time may be elided. | 142 // When true, seeking to the current time may be elided. |
| 146 bool is_static_ = true; | 143 bool is_static_ = true; |
| 147 | 144 |
| 148 // Tracks the current state of |pipeline_|. | 145 // Tracks the current state of |pipeline_|. |
| 149 State state_ = State::CREATED; | 146 State state_ = State::CREATED; |
| 150 | 147 |
| 151 // Indicates that a seek has occurred. When set, a seeked callback will be | 148 // Indicates that a seek has occurred. When set, a seeked callback will be |
| 152 // issued at the next stable state. | 149 // issued at the next stable state. |
| 153 bool pending_seeked_cb_ = false; | 150 bool pending_seeked_cb_ = false; |
| 154 | 151 |
| 155 // Indicates that time has been changed by a seek, which will be reported at | 152 // Indicates that time has been changed by a seek, which will be reported at |
| 156 // the next seeked callback. | 153 // the next seeked callback. |
| 157 bool pending_time_updated_ = false; | 154 bool pending_time_updated_ = false; |
| 158 | 155 |
| 159 // Indicates that the |pipeline_| was suspended, and therefore that a resumed | |
| 160 // callback should be issued the next time we enter State::PLAYING. | |
| 161 bool pending_resumed_cb_ = false; | |
| 162 | |
| 163 // The target time of the active seek; valid while SEEKING or RESUMING. | 156 // The target time of the active seek; valid while SEEKING or RESUMING. |
| 164 base::TimeDelta seek_time_; | 157 base::TimeDelta seek_time_; |
| 165 | 158 |
| 166 // Target state which we will work to achieve. |pending_seek_time_| is only | 159 // Target state which we will work to achieve. |pending_seek_time_| is only |
| 167 // valid when |pending_seek_| is true. | 160 // valid when |pending_seek_| is true. |
| 168 bool pending_seek_ = false; | 161 bool pending_seek_ = false; |
| 169 base::TimeDelta pending_seek_time_; | 162 base::TimeDelta pending_seek_time_; |
| 170 bool pending_suspend_ = false; | 163 bool pending_suspend_ = false; |
| 171 bool pending_resume_ = false; | 164 bool pending_resume_ = false; |
| 172 | 165 |
| 173 base::ThreadChecker thread_checker_; | 166 base::ThreadChecker thread_checker_; |
| 174 base::WeakPtrFactory<PipelineController> weak_factory_; | 167 base::WeakPtrFactory<PipelineController> weak_factory_; |
| 175 | 168 |
| 176 DISALLOW_COPY_AND_ASSIGN(PipelineController); | 169 DISALLOW_COPY_AND_ASSIGN(PipelineController); |
| 177 }; | 170 }; |
| 178 | 171 |
| 179 } // namespace media | 172 } // namespace media |
| 180 | 173 |
| 181 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ | 174 #endif // MEDIA_FILTERS_PIPELINE_CONTROLLER_H_ |
| OLD | NEW |