| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Implementation of Pipeline. | 5 // Implementation of Pipeline. |
| 6 | 6 |
| 7 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ | 7 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ |
| 8 #define MEDIA_BASE_PIPELINE_IMPL_H_ | 8 #define MEDIA_BASE_PIPELINE_IMPL_H_ |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // V | | 39 // V | |
| 40 // [ Starting (for each filter) ] | | 40 // [ Starting (for each filter) ] | |
| 41 // | | | 41 // | | |
| 42 // V Seek() | | 42 // V Seek() | |
| 43 // [ Started ] --------> [ Pausing (for each filter) ] -' | 43 // [ Started ] --------> [ Pausing (for each filter) ] -' |
| 44 // | | | 44 // | | |
| 45 // | NotifyEnded() Seek() | | 45 // | NotifyEnded() Seek() | |
| 46 // `-------------> [ Ended ] ---------------------' | 46 // `-------------> [ Ended ] ---------------------' |
| 47 // | 47 // |
| 48 // SetError() | 48 // SetError() |
| 49 // [ Any State ] -------------> [ Error ] | 49 // [ Any State ] -------------> [ Stopping (for each filter)] |
| 50 // | Stop() | 50 // | Stop() | |
| 51 // '--------------------> [ Stopped ] | 51 // V V |
| 52 // [ Stopping (for each filter) ] [ Error ] |
| 53 // | |
| 54 // V |
| 55 // [ Stopped ] |
| 52 // | 56 // |
| 53 // Initialization is a series of state transitions from "Created" through each | 57 // Initialization is a series of state transitions from "Created" through each |
| 54 // filter initialization state. When all filter initialization states have | 58 // filter initialization state. When all filter initialization states have |
| 55 // completed, we are implicitly in a "Paused" state. At that point we simulate | 59 // completed, we are implicitly in a "Paused" state. At that point we simulate |
| 56 // a Seek() to the beginning of the media to give filters a chance to preroll. | 60 // a Seek() to the beginning of the media to give filters a chance to preroll. |
| 57 // From then on the normal Seek() transitions are carried out and we start | 61 // From then on the normal Seek() transitions are carried out and we start |
| 58 // playing the media. | 62 // playing the media. |
| 59 // | 63 // |
| 60 // If any error ever happens, this object will transition to the "Error" state | 64 // If any error ever happens, this object will transition to the "Error" state |
| 61 // from any state. If Stop() is ever called, this object will transition to | 65 // from any state. If Stop() is ever called, this object will transition to |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 kInitDemuxer, | 112 kInitDemuxer, |
| 109 kInitAudioDecoder, | 113 kInitAudioDecoder, |
| 110 kInitAudioRenderer, | 114 kInitAudioRenderer, |
| 111 kInitVideoDecoder, | 115 kInitVideoDecoder, |
| 112 kInitVideoRenderer, | 116 kInitVideoRenderer, |
| 113 kPausing, | 117 kPausing, |
| 114 kSeeking, | 118 kSeeking, |
| 115 kStarting, | 119 kStarting, |
| 116 kStarted, | 120 kStarted, |
| 117 kEnded, | 121 kEnded, |
| 122 kStopping, |
| 118 kStopped, | 123 kStopped, |
| 119 kError, | 124 kError, |
| 120 }; | 125 }; |
| 121 | 126 |
| 122 virtual ~PipelineImpl(); | 127 virtual ~PipelineImpl(); |
| 123 | 128 |
| 124 // Reset the state of the pipeline object to the initial state. This method | 129 // Reset the state of the pipeline object to the initial state. This method |
| 125 // is used by the constructor, and the Stop() method. | 130 // is used by the constructor, and the Stop() method. |
| 126 void ResetState(); | 131 void ResetState(); |
| 127 | 132 |
| 128 // Simple method used to make sure the pipeline is running normally. | 133 // Simple method used to make sure the pipeline is running normally. |
| 129 bool IsPipelineOk(); | 134 bool IsPipelineOk(); |
| 130 | 135 |
| 131 // Helper method to tell whether we are in the state of initializing. | 136 // Helper method to tell whether we are in the state of initializing. |
| 132 bool IsPipelineInitializing(); | 137 bool IsPipelineInitializing(); |
| 133 | 138 |
| 134 // Returns true if the given state is one that transitions to the started | 139 // Helper method to tell whether we are stopped or in error. |
| 135 // state. | 140 bool IsPipelineStopped(); |
| 136 static bool StateTransitionsToStarted(State state); | 141 |
| 142 // Helper method to execute callback from Start() and reset |
| 143 // |filter_factory_|. Called when initialization completes |
| 144 // normally or when pipeline is stopped or error occurs during |
| 145 // initialization. |
| 146 void FinishInitialization(); |
| 147 |
| 148 // Returns true if the given state is one that transitions to a new state |
| 149 // after iterating through each filter. |
| 150 static bool TransientState(State state); |
| 137 | 151 |
| 138 // Given the current state, returns the next state. | 152 // Given the current state, returns the next state. |
| 139 static State FindNextState(State current); | 153 static State FindNextState(State current); |
| 140 | 154 |
| 141 // FilterHost implementation. | 155 // FilterHost implementation. |
| 142 virtual void SetError(PipelineError error); | 156 virtual void SetError(PipelineError error); |
| 143 virtual base::TimeDelta GetTime() const; | 157 virtual base::TimeDelta GetTime() const; |
| 144 virtual base::TimeDelta GetDuration() const; | 158 virtual base::TimeDelta GetDuration() const; |
| 145 virtual void SetTime(base::TimeDelta time); | 159 virtual void SetTime(base::TimeDelta time); |
| 146 virtual void SetDuration(base::TimeDelta duration); | 160 virtual void SetDuration(base::TimeDelta duration); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 // Method called during initialization to insert a mime type into the | 173 // Method called during initialization to insert a mime type into the |
| 160 // |rendered_mime_types_| set. | 174 // |rendered_mime_types_| set. |
| 161 void InsertRenderedMimeType(const std::string& major_mime_type); | 175 void InsertRenderedMimeType(const std::string& major_mime_type); |
| 162 | 176 |
| 163 // Method called during initialization to determine if we rendered anything. | 177 // Method called during initialization to determine if we rendered anything. |
| 164 bool HasRenderedMimeTypes() const; | 178 bool HasRenderedMimeTypes() const; |
| 165 | 179 |
| 166 // Callback executed by filters upon completing initialization. | 180 // Callback executed by filters upon completing initialization. |
| 167 void OnFilterInitialize(); | 181 void OnFilterInitialize(); |
| 168 | 182 |
| 169 // Callback executed by filters upon completing Play(), Pause() or Seek(). | 183 // Callback executed by filters upon completing Play(), Pause(), Seek(), |
| 184 // or Stop(). |
| 170 void OnFilterStateTransition(); | 185 void OnFilterStateTransition(); |
| 171 | 186 |
| 172 // The following "task" methods correspond to the public methods, but these | 187 // The following "task" methods correspond to the public methods, but these |
| 173 // methods are run as the result of posting a task to the PipelineInternal's | 188 // methods are run as the result of posting a task to the PipelineInternal's |
| 174 // message loop. | 189 // message loop. |
| 175 void StartTask(FilterFactory* filter_factory, | 190 void StartTask(FilterFactory* filter_factory, |
| 176 const std::string& url, | 191 const std::string& url, |
| 177 PipelineCallback* start_callback); | 192 PipelineCallback* start_callback); |
| 178 | 193 |
| 179 // InitializeTask() performs initialization in multiple passes. It is executed | 194 // InitializeTask() performs initialization in multiple passes. It is executed |
| 180 // as a result of calling Start() or InitializationComplete() that advances | 195 // as a result of calling Start() or InitializationComplete() that advances |
| 181 // initialization to the next state. It works as a hub of state transition for | 196 // initialization to the next state. It works as a hub of state transition for |
| 182 // initialization. | 197 // initialization. |
| 183 void InitializeTask(); | 198 void InitializeTask(); |
| 184 | 199 |
| 185 // Stops and destroys all filters, placing the pipeline in the kStopped state | 200 // Stops and destroys all filters, placing the pipeline in the kStopped state. |
| 186 // and setting the error code to PIPELINE_STOPPED. | |
| 187 void StopTask(PipelineCallback* stop_callback); | 201 void StopTask(PipelineCallback* stop_callback); |
| 188 | 202 |
| 189 // Carries out stopping and destroying all filters, placing the pipeline in | 203 // Carries out stopping and destroying all filters, placing the pipeline in |
| 190 // the kError state. | 204 // the kError state. |
| 191 void ErrorChangedTask(PipelineError error); | 205 void ErrorChangedTask(PipelineError error); |
| 192 | 206 |
| 193 // Carries out notifying filters that the playback rate has changed. | 207 // Carries out notifying filters that the playback rate has changed. |
| 194 void PlaybackRateChangedTask(float playback_rate); | 208 void PlaybackRateChangedTask(float playback_rate); |
| 195 | 209 |
| 196 // Carries out notifying filters that the volume has changed. | 210 // Carries out notifying filters that the volume has changed. |
| 197 void VolumeChangedTask(float volume); | 211 void VolumeChangedTask(float volume); |
| 198 | 212 |
| 199 // Carries out notifying filters that we are seeking to a new timestamp. | 213 // Carries out notifying filters that we are seeking to a new timestamp. |
| 200 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); | 214 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); |
| 201 | 215 |
| 202 // Carries out handling a notification from a filter that it has ended. | 216 // Carries out handling a notification from a filter that it has ended. |
| 203 void NotifyEndedTask(); | 217 void NotifyEndedTask(); |
| 204 | 218 |
| 205 // Carries out handling a notification of network event. | 219 // Carries out handling a notification of network event. |
| 206 void NotifyNetworkEventTask(); | 220 void NotifyNetworkEventTask(); |
| 207 | 221 |
| 208 // Carries out disabling the audio renderer. | 222 // Carries out disabling the audio renderer. |
| 209 void DisableAudioRendererTask(); | 223 void DisableAudioRendererTask(); |
| 210 | 224 |
| 211 // Carries out advancing to the next filter during Play()/Pause()/Seek(). | 225 // Carries out advancing to the next filter during Play()/Pause()/Seek(). |
| 212 void FilterStateTransitionTask(); | 226 void FilterStateTransitionTask(); |
| 213 | 227 |
| 228 // Carries out stopping filter threads, deleting filters, running |
| 229 // appropriate callbacks, and setting the appropriate pipeline state |
| 230 // depending on whether we performing Stop() or SetError(). |
| 231 // Called after all filters have been stopped. |
| 232 void FinishDestroyingFiltersTask(); |
| 233 |
| 214 // Internal methods used in the implementation of the pipeline thread. All | 234 // Internal methods used in the implementation of the pipeline thread. All |
| 215 // of these methods are only called on the pipeline thread. | 235 // of these methods are only called on the pipeline thread. |
| 216 | 236 |
| 217 // The following template functions make use of the fact that media filter | 237 // The following template functions make use of the fact that media filter |
| 218 // derived interfaces are self-describing in the sense that they all contain | 238 // derived interfaces are self-describing in the sense that they all contain |
| 219 // the static method filter_type() which returns a FilterType enum that | 239 // the static method filter_type() which returns a FilterType enum that |
| 220 // uniquely identifies the filter's interface. In addition, filters that are | 240 // uniquely identifies the filter's interface. In addition, filters that are |
| 221 // specific to audio or video also support a static method major_mime_type() | 241 // specific to audio or video also support a static method major_mime_type() |
| 222 // which returns a string of "audio/" or "video/". | 242 // which returns a string of "audio/" or "video/". |
| 223 // | 243 // |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // stream does not exist. | 286 // stream does not exist. |
| 267 template <class Decoder, class Renderer> | 287 template <class Decoder, class Renderer> |
| 268 bool CreateRenderer(); | 288 bool CreateRenderer(); |
| 269 | 289 |
| 270 // Examine the list of existing filters to find one that supports the | 290 // Examine the list of existing filters to find one that supports the |
| 271 // specified Filter interface. If one exists, the |filter_out| will contain | 291 // specified Filter interface. If one exists, the |filter_out| will contain |
| 272 // the filter, |*filter_out| will be NULL. | 292 // the filter, |*filter_out| will be NULL. |
| 273 template <class Filter> | 293 template <class Filter> |
| 274 void GetFilter(scoped_refptr<Filter>* filter_out) const; | 294 void GetFilter(scoped_refptr<Filter>* filter_out) const; |
| 275 | 295 |
| 276 // Stops every filters, filter host and filter thread and releases all | 296 // Kicks off stopping filters. Called by StopTask() and ErrorChangedTask(). |
| 277 // references to them. | 297 void StartDestroyingFilters(); |
| 278 void DestroyFilters(); | |
| 279 | 298 |
| 280 // Message loop used to execute pipeline tasks. | 299 // Message loop used to execute pipeline tasks. |
| 281 MessageLoop* message_loop_; | 300 MessageLoop* message_loop_; |
| 282 | 301 |
| 283 // Lock used to serialize access for the following data members. | 302 // Lock used to serialize access for the following data members. |
| 284 mutable Lock lock_; | 303 mutable Lock lock_; |
| 285 | 304 |
| 286 // Whether or not the pipeline is running. | 305 // Whether or not the pipeline is running. |
| 287 bool running_; | 306 bool running_; |
| 288 | 307 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // Vector of threads owned by the pipeline and being used by filters. | 411 // Vector of threads owned by the pipeline and being used by filters. |
| 393 typedef std::vector<base::Thread*> FilterThreadVector; | 412 typedef std::vector<base::Thread*> FilterThreadVector; |
| 394 FilterThreadVector filter_threads_; | 413 FilterThreadVector filter_threads_; |
| 395 | 414 |
| 396 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 415 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 397 }; | 416 }; |
| 398 | 417 |
| 399 } // namespace media | 418 } // namespace media |
| 400 | 419 |
| 401 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 420 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |