| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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 <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 25 // Class which implements the Media::Pipeline contract. The majority of the | 25 // Class which implements the Media::Pipeline contract. The majority of the |
| 26 // actual code for this object lives in the PipelineThread class, which is | 26 // actual code for this object lives in the PipelineThread class, which is |
| 27 // responsible for actually building and running the pipeline. This object | 27 // responsible for actually building and running the pipeline. This object |
| 28 // is basically a simple container for state information, and is responsible | 28 // is basically a simple container for state information, and is responsible |
| 29 // for creating and communicating with the PipelineThread object. | 29 // for creating and communicating with the PipelineThread object. |
| 30 class PipelineImpl : public Pipeline { | 30 class PipelineImpl : public Pipeline { |
| 31 public: | 31 public: |
| 32 PipelineImpl(); | 32 PipelineImpl(); |
| 33 virtual ~PipelineImpl(); | 33 virtual ~PipelineImpl(); |
| 34 | 34 |
| 35 // Implementation of PipelineStatus methods. | 35 // Pipeline implementation. |
| 36 virtual bool IsInitialized() const; | |
| 37 virtual base::TimeDelta GetDuration() const; | |
| 38 virtual base::TimeDelta GetBufferedTime() const; | |
| 39 virtual int64 GetTotalBytes() const; | |
| 40 virtual int64 GetBufferedBytes()const; | |
| 41 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; | |
| 42 virtual float GetVolume() const; | |
| 43 virtual float GetPlaybackRate() const; | |
| 44 virtual base::TimeDelta GetTime() const; | |
| 45 virtual base::TimeDelta GetInterpolatedTime() const; | |
| 46 virtual PipelineError GetError() const; | |
| 47 virtual bool IsRendered(const std::string& major_mime_type) const; | |
| 48 | |
| 49 // Implementation of Pipeline methods. | |
| 50 virtual bool Start(FilterFactory* filter_factory, | 36 virtual bool Start(FilterFactory* filter_factory, |
| 51 const std::string& url, | 37 const std::string& uri, |
| 52 PipelineCallback* start_callback); | 38 PipelineCallback* start_callback); |
| 53 virtual void Stop(); | 39 virtual void Stop(); |
| 54 virtual void SetPlaybackRate(float rate); | 40 virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback); |
| 55 virtual void Seek(base::TimeDelta time, | 41 virtual bool IsInitialized() const; |
| 56 PipelineCallback* seek_callback); | 42 virtual bool IsRendered(const std::string& major_mime_type) const; |
| 43 virtual float GetPlaybackRate() const; |
| 44 virtual void SetPlaybackRate(float playback_rate); |
| 45 virtual float GetVolume() const; |
| 57 virtual void SetVolume(float volume); | 46 virtual void SetVolume(float volume); |
| 47 virtual base::TimeDelta GetTime() const; |
| 48 virtual base::TimeDelta GetBufferedTime() const; |
| 49 virtual base::TimeDelta GetDuration() const; |
| 50 virtual int64 GetBufferedBytes() const; |
| 51 virtual int64 GetTotalBytes() const; |
| 52 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; |
| 53 virtual PipelineError GetError() const; |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 friend class FilterHostImpl; | 56 friend class FilterHostImpl; |
| 61 friend class PipelineThread; | 57 friend class PipelineThread; |
| 62 | 58 |
| 63 // Reset the state of the pipeline object to the initial state. This method | 59 // Reset the state of the pipeline object to the initial state. This method |
| 64 // is used by the constructor, and the Stop method. | 60 // is used by the constructor, and the Stop method. |
| 65 void ResetState(); | 61 void ResetState(); |
| 66 | 62 |
| 67 // Used internally to make sure that the thread is in a state that is | 63 // Used internally to make sure that the thread is in a state that is |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 106 |
| 111 // Amount of available buffered data. Set by a FilterHostImpl object | 107 // Amount of available buffered data. Set by a FilterHostImpl object |
| 112 // on behalf of a filter. | 108 // on behalf of a filter. |
| 113 int64 buffered_bytes_; | 109 int64 buffered_bytes_; |
| 114 | 110 |
| 115 // Total size of the media. Set by a FilterHostImpl object on behalf | 111 // Total size of the media. Set by a FilterHostImpl object on behalf |
| 116 // of a filter. | 112 // of a filter. |
| 117 int64 total_bytes_; | 113 int64 total_bytes_; |
| 118 | 114 |
| 119 // Lock used to serialize access for getter/setter methods. | 115 // Lock used to serialize access for getter/setter methods. |
| 120 Lock lock_; | 116 mutable Lock lock_; |
| 121 | 117 |
| 122 // Video width and height. Set by a FilterHostImpl object on behalf | 118 // Video width and height. Set by a FilterHostImpl object on behalf |
| 123 // of a filter. The video_size_access_lock_ is used to make sure access | 119 // of a filter. The video_size_access_lock_ is used to make sure access |
| 124 // to the pair of width and height are modified or read in thread safe way. | 120 // to the pair of width and height are modified or read in thread safe way. |
| 125 size_t video_width_; | 121 size_t video_width_; |
| 126 size_t video_height_; | 122 size_t video_height_; |
| 127 | 123 |
| 128 // Current volume level (from 0.0f to 1.0f). The volume reflects the last | 124 // Current volume level (from 0.0f to 1.0f). The volume reflects the last |
| 129 // value the audio filter was called with SetVolume, so there will be a short | 125 // value the audio filter was called with SetVolume, so there will be a short |
| 130 // period of time between the client calling SetVolume on the pipeline and | 126 // period of time between the client calling SetVolume on the pipeline and |
| 131 // this value being updated. Set by the PipelineThread just prior to calling | 127 // this value being updated. Set by the PipelineThread just prior to calling |
| 132 // the audio renderer. | 128 // the audio renderer. |
| 133 float volume_; | 129 float volume_; |
| 134 | 130 |
| 135 // Current playback rate (>= 0.0f). This member reflects the last value | 131 // Current playback rate (>= 0.0f). This member reflects the last value |
| 136 // that the filters in the pipeline were called with, so there will be a short | 132 // that the filters in the pipeline were called with, so there will be a short |
| 137 // period of time between the client calling SetPlaybackRate and this value | 133 // period of time between the client calling SetPlaybackRate and this value |
| 138 // being updated. Set by the PipelineThread just prior to calling filters. | 134 // being updated. Set by the PipelineThread just prior to calling filters. |
| 139 float playback_rate_; | 135 float playback_rate_; |
| 140 | 136 |
| 141 // Current playback time. Set by a FilterHostImpl object on behalf of the | 137 // Current playback time. Set by a FilterHostImpl object on behalf of the |
| 142 // audio renderer filter. | 138 // audio renderer filter. |
| 143 base::TimeDelta time_; | 139 base::TimeDelta time_; |
| 144 | 140 |
| 145 // Internal system timer at last time the SetTime method was called. Used to | |
| 146 // compute interpolated time. | |
| 147 base::TimeTicks ticks_at_last_set_time_; | |
| 148 | |
| 149 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that | 141 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that |
| 150 // the pipeline is operating correctly. Any other value indicates that the | 142 // the pipeline is operating correctly. Any other value indicates that the |
| 151 // pipeline is stopped or is stopping. Clients can call the Stop method to | 143 // pipeline is stopped or is stopping. Clients can call the Stop method to |
| 152 // reset the pipeline state, and restore this to PIPELINE_OK. | 144 // reset the pipeline state, and restore this to PIPELINE_OK. |
| 153 PipelineError error_; | 145 PipelineError error_; |
| 154 | 146 |
| 155 // Vector of major mime types that have been rendered by this pipeline. | 147 // Vector of major mime types that have been rendered by this pipeline. |
| 156 typedef std::set<std::string> RenderedMimeTypesSet; | 148 typedef std::set<std::string> RenderedMimeTypesSet; |
| 157 RenderedMimeTypesSet rendered_mime_types_; | 149 RenderedMimeTypesSet rendered_mime_types_; |
| 158 | 150 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 188 // pipeline thread. For example, Seek posts a task to call SeekTask. | 180 // pipeline thread. For example, Seek posts a task to call SeekTask. |
| 189 explicit PipelineThread(PipelineImpl* pipeline); | 181 explicit PipelineThread(PipelineImpl* pipeline); |
| 190 | 182 |
| 191 // After Start() is called, a task of StartTask() is posted on the pipeline | 183 // After Start() is called, a task of StartTask() is posted on the pipeline |
| 192 // thread to perform initialization. See StartTask() to learn more about | 184 // thread to perform initialization. See StartTask() to learn more about |
| 193 // initialization. | 185 // initialization. |
| 194 bool Start(FilterFactory* filter_factory, | 186 bool Start(FilterFactory* filter_factory, |
| 195 const std::string& url_media_source, | 187 const std::string& url_media_source, |
| 196 PipelineCallback* init_complete_callback); | 188 PipelineCallback* init_complete_callback); |
| 197 void Stop(); | 189 void Stop(); |
| 190 void Seek(base::TimeDelta time, PipelineCallback* seek_callback); |
| 198 void SetPlaybackRate(float rate); | 191 void SetPlaybackRate(float rate); |
| 199 void Seek(base::TimeDelta time, PipelineCallback* seek_callback); | |
| 200 void SetVolume(float volume); | 192 void SetVolume(float volume); |
| 201 | 193 |
| 202 // Methods called by a FilterHostImpl object. These methods may be called | 194 // Methods called by a FilterHostImpl object. These methods may be called |
| 203 // on any thread, either the pipeline's thread or any other. | 195 // on any thread, either the pipeline's thread or any other. |
| 204 | 196 |
| 205 // When a filter calls it's FilterHost, the filter host calls back to the | 197 // When a filter calls it's FilterHost, the filter host calls back to the |
| 206 // pipeline thread. If the pipeline thread is running a nested message loop | 198 // pipeline thread. If the pipeline thread is running a nested message loop |
| 207 // then it will be exited. | 199 // then it will be exited. |
| 208 void InitializationComplete(FilterHostImpl* host); | 200 void InitializationComplete(FilterHostImpl* host); |
| 209 | 201 |
| 210 // Sets the pipeline time and schedules a task to call back to any filters | 202 // Sets the pipeline time and schedules a task to call back to any filters |
| 211 // that have registered a time update callback. | 203 // that have registered a time update callback. |
| 212 void SetTime(base::TimeDelta time); | 204 void SetTime(base::TimeDelta time); |
| 213 | 205 |
| 214 // Called by a FilterHostImpl on behalf of a filter calling FilterHost::Error. | 206 // Called by a FilterHostImpl on behalf of a filter calling FilterHost::Error. |
| 215 // If the pipeline is running a nested message loop, it will be exited. | 207 // If the pipeline is running a nested message loop, it will be exited. |
| 216 void Error(PipelineError error); | 208 void Error(PipelineError error); |
| 217 | 209 |
| 218 // Called by a FilterHostImpl on behalf of a filter that calls the | |
| 219 // FilterHost::PostTask method. | |
| 220 void PostTask(Task* task); | |
| 221 | |
| 222 // Simple accessor used by the FilterHostImpl class to get access to the | 210 // Simple accessor used by the FilterHostImpl class to get access to the |
| 223 // pipeline object. | 211 // pipeline object. |
| 224 PipelineImpl* pipeline() const { return pipeline_; } | 212 PipelineImpl* pipeline() const { return pipeline_; } |
| 225 | 213 |
| 226 // Accessor used to post messages to thread's message loop. | 214 // Accessor used to post messages to thread's message loop. |
| 227 MessageLoop* message_loop() const { return thread_.message_loop(); } | 215 MessageLoop* message_loop() const { return thread_.message_loop(); } |
| 228 | 216 |
| 229 // Accessor used by PipelineImpl to check if we're executing on the pipeline | 217 // Accessor used by PipelineImpl to check if we're executing on the pipeline |
| 230 // thread. | 218 // thread. |
| 231 PlatformThreadId thread_id() const { return thread_.thread_id(); } | 219 PlatformThreadId thread_id() const { return thread_.thread_id(); } |
| 232 | 220 |
| 233 private: | 221 private: |
| 222 // Only allow ourselves to be destroyed via ref-counting. |
| 223 friend class base::RefCountedThreadSafe<PipelineThread>; |
| 224 virtual ~PipelineThread(); |
| 225 |
| 234 enum State { | 226 enum State { |
| 235 kCreated, | 227 kCreated, |
| 236 kInitDataSource, | 228 kInitDataSource, |
| 237 kInitDemuxer, | 229 kInitDemuxer, |
| 238 kInitAudioDecoder, | 230 kInitAudioDecoder, |
| 239 kInitAudioRenderer, | 231 kInitAudioRenderer, |
| 240 kInitVideoDecoder, | 232 kInitVideoDecoder, |
| 241 kInitVideoRenderer, | 233 kInitVideoRenderer, |
| 242 kStarted, | 234 kStarted, |
| 243 kStopped, | 235 kStopped, |
| 244 kError, | 236 kError, |
| 245 }; | 237 }; |
| 246 | 238 |
| 247 // Implementation of MessageLoop::DestructionObserver. StartTask registers | |
| 248 // this class as a destruction observer on the thread's message loop. | |
| 249 // It is used to destroy the list of FilterHosts | |
| 250 // (and thus destroy the associated filters) when all tasks have been | |
| 251 // processed and the message loop has been quit. | |
| 252 virtual void WillDestroyCurrentMessageLoop(); | |
| 253 | |
| 254 friend class base::RefCountedThreadSafe<PipelineThread>; | |
| 255 virtual ~PipelineThread(); | |
| 256 | |
| 257 // Simple method used to make sure the pipeline is running normally. | 239 // Simple method used to make sure the pipeline is running normally. |
| 258 bool IsPipelineOk() { return PIPELINE_OK == pipeline_->error_; } | 240 bool IsPipelineOk() { return PIPELINE_OK == pipeline_->error_; } |
| 259 | 241 |
| 260 // Helper method to tell whether we are in the state of initializing. | 242 // Helper method to tell whether we are in the state of initializing. |
| 261 bool IsPipelineInitializing() { | 243 bool IsPipelineInitializing() { |
| 262 return state_ == kInitDataSource || | 244 return state_ == kInitDataSource || |
| 263 state_ == kInitDemuxer || | 245 state_ == kInitDemuxer || |
| 264 state_ == kInitAudioDecoder || | 246 state_ == kInitAudioDecoder || |
| 265 state_ == kInitAudioRenderer || | 247 state_ == kInitAudioRenderer || |
| 266 state_ == kInitVideoDecoder || | 248 state_ == kInitVideoDecoder || |
| 267 state_ == kInitVideoRenderer; | 249 state_ == kInitVideoRenderer; |
| 268 } | 250 } |
| 269 | 251 |
| 252 // Implementation of MessageLoop::DestructionObserver. StartTask registers |
| 253 // this class as a destruction observer on the thread's message loop. |
| 254 // It is used to destroy the list of FilterHosts |
| 255 // (and thus destroy the associated filters) when all tasks have been |
| 256 // processed and the message loop has been quit. |
| 257 virtual void WillDestroyCurrentMessageLoop(); |
| 258 |
| 270 // The following "task" methods correspond to the public methods, but these | 259 // The following "task" methods correspond to the public methods, but these |
| 271 // methods are run as the result of posting a task to the PipelineThread's | 260 // methods are run as the result of posting a task to the PipelineThread's |
| 272 // message loop. | 261 // message loop. |
| 273 | 262 |
| 274 // StartTask() is a special task that performs initialization in multiple | 263 // StartTask() is a special task that performs initialization in multiple |
| 275 // passes. It is executed as a result of calling Start() or | 264 // passes. It is executed as a result of calling Start() or |
| 276 // InitializationComplete() that advances initialization to the next state. It | 265 // InitializationComplete() that advances initialization to the next state. It |
| 277 // works as a hub of state transition for initialization. | 266 // works as a hub of state transition for initialization. |
| 278 void StartTask(); | 267 void StartTask(); |
| 279 void StopTask(); | 268 void StopTask(); |
| 280 void SetPlaybackRateTask(float rate); | 269 void SetPlaybackRateTask(float rate); |
| 281 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); | 270 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); |
| 282 void SetVolumeTask(float volume); | 271 void SetVolumeTask(float volume); |
| 283 void SetTimeTask(); | |
| 284 | 272 |
| 285 // Internal methods used in the implementation of the pipeline thread. All | 273 // Internal methods used in the implementation of the pipeline thread. All |
| 286 // of these methods are only called on the pipeline thread. | 274 // of these methods are only called on the pipeline thread. |
| 287 | 275 |
| 288 // Calls the Stop method on every filter in the pipeline | |
| 289 void StopFilters(); | |
| 290 | |
| 291 // The following template functions make use of the fact that media filter | 276 // The following template functions make use of the fact that media filter |
| 292 // derived interfaces are self-describing in the sense that they all contain | 277 // derived interfaces are self-describing in the sense that they all contain |
| 293 // the static method filter_type() which returns a FilterType enum that | 278 // the static method filter_type() which returns a FilterType enum that |
| 294 // uniquely identifies the filter's interface. In addition, filters that are | 279 // uniquely identifies the filter's interface. In addition, filters that are |
| 295 // specific to audio or video also support a static method major_mime_type() | 280 // specific to audio or video also support a static method major_mime_type() |
| 296 // which returns a string of "audio/" or "video/". | 281 // which returns a string of "audio/" or "video/". |
| 297 // | 282 // |
| 298 // Uses the FilterFactory to create a new filter of the Filter class, and | 283 // Uses the FilterFactory to create a new filter of the Filter class, and |
| 299 // initializes it using the Source object. The source may be another filter | 284 // initializes it using the Source object. The source may be another filter |
| 300 // or it could be a string in the case of a DataSource. | 285 // or it could be a string in the case of a DataSource. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 368 |
| 384 typedef std::vector<base::Thread*> FilterThreadVector; | 369 typedef std::vector<base::Thread*> FilterThreadVector; |
| 385 FilterThreadVector filter_threads_; | 370 FilterThreadVector filter_threads_; |
| 386 | 371 |
| 387 DISALLOW_COPY_AND_ASSIGN(PipelineThread); | 372 DISALLOW_COPY_AND_ASSIGN(PipelineThread); |
| 388 }; | 373 }; |
| 389 | 374 |
| 390 } // namespace media | 375 } // namespace media |
| 391 | 376 |
| 392 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 377 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |