| OLD | NEW |
| 1 // Copyright (c) 2008-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> |
| 12 #include <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 16 #include "base/thread.h" | 16 #include "base/thread.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "media/base/pipeline.h" | 18 #include "media/base/pipeline.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 | 21 |
| 22 class FilterHostImpl; | 22 class FilterHostImpl; |
| 23 class PipelineThread; | 23 class PipelineInternal; |
| 24 | 24 |
| 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 PipelineInternal 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 PipelineInternal object. |
| 30 class PipelineImpl : public Pipeline { | 30 class PipelineImpl : public Pipeline { |
| 31 public: | 31 public: |
| 32 PipelineImpl(); | 32 PipelineImpl(MessageLoop* message_loop); |
| 33 virtual ~PipelineImpl(); | 33 virtual ~PipelineImpl(); |
| 34 | 34 |
| 35 // Pipeline implementation. | 35 // Pipeline implementation. |
| 36 virtual bool Start(FilterFactory* filter_factory, | 36 virtual bool Start(FilterFactory* filter_factory, |
| 37 const std::string& uri, | 37 const std::string& uri, |
| 38 PipelineCallback* start_callback); | 38 PipelineCallback* start_callback); |
| 39 virtual void Stop(); | 39 virtual void Stop(PipelineCallback* stop_callback); |
| 40 virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback); | 40 virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback); |
| 41 virtual bool IsRunning() const; |
| 41 virtual bool IsInitialized() const; | 42 virtual bool IsInitialized() const; |
| 42 virtual bool IsRendered(const std::string& major_mime_type) const; | 43 virtual bool IsRendered(const std::string& major_mime_type) const; |
| 43 virtual float GetPlaybackRate() const; | 44 virtual float GetPlaybackRate() const; |
| 44 virtual void SetPlaybackRate(float playback_rate); | 45 virtual void SetPlaybackRate(float playback_rate); |
| 45 virtual float GetVolume() const; | 46 virtual float GetVolume() const; |
| 46 virtual void SetVolume(float volume); | 47 virtual void SetVolume(float volume); |
| 47 virtual base::TimeDelta GetTime() const; | 48 virtual base::TimeDelta GetTime() const; |
| 48 virtual base::TimeDelta GetBufferedTime() const; | 49 virtual base::TimeDelta GetBufferedTime() const; |
| 49 virtual base::TimeDelta GetDuration() const; | 50 virtual base::TimeDelta GetDuration() const; |
| 50 virtual int64 GetBufferedBytes() const; | 51 virtual int64 GetBufferedBytes() const; |
| 51 virtual int64 GetTotalBytes() const; | 52 virtual int64 GetTotalBytes() const; |
| 52 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; | 53 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; |
| 53 virtual PipelineError GetError() const; | 54 virtual PipelineError GetError() const; |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 friend class FilterHostImpl; | 57 friend class FilterHostImpl; |
| 57 friend class PipelineThread; | 58 friend class PipelineInternal; |
| 58 | 59 |
| 59 // Reset the state of the pipeline object to the initial state. This method | 60 // Reset the state of the pipeline object to the initial state. This method |
| 60 // is used by the constructor, and the Stop method. | 61 // is used by the constructor, and the Stop method. |
| 61 void ResetState(); | 62 void ResetState(); |
| 62 | 63 |
| 63 // Used internally to make sure that the thread is in a state that is | 64 // Used internally to make sure that the thread is in a state that is |
| 64 // acceptable to post a task to. It must exist, be initialized, and there | 65 // acceptable to post a task to. It must exist, be initialized, and there |
| 65 // must not be an error. | 66 // must not be an error. |
| 66 bool IsPipelineOk() const; | 67 bool IsPipelineOk() const; |
| 67 | 68 |
| 68 // Returns true if we're currently executing on the pipeline thread. Mostly | |
| 69 // used in DCHECKs. | |
| 70 bool IsPipelineThread() const; | |
| 71 | |
| 72 // Methods called by FilterHostImpl to update pipeline state. | 69 // Methods called by FilterHostImpl to update pipeline state. |
| 73 void SetDuration(base::TimeDelta duration); | 70 void SetDuration(base::TimeDelta duration); |
| 74 void SetBufferedTime(base::TimeDelta buffered_time); | 71 void SetBufferedTime(base::TimeDelta buffered_time); |
| 75 void SetTotalBytes(int64 total_bytes); | 72 void SetTotalBytes(int64 total_bytes); |
| 76 void SetBufferedBytes(int64 buffered_bytes); | 73 void SetBufferedBytes(int64 buffered_bytes); |
| 77 void SetVideoSize(size_t width, size_t height); | 74 void SetVideoSize(size_t width, size_t height); |
| 78 void SetTime(base::TimeDelta time); | 75 void SetTime(base::TimeDelta time); |
| 79 void InternalSetPlaybackRate(float rate); | 76 void InternalSetPlaybackRate(float rate); |
| 80 | 77 |
| 81 // Sets the error to the new error code only if the current error state is | 78 // Sets the error to the new error code only if the current error state is |
| 82 // PIPELINE_OK. Returns true if error set, otherwise leaves current error | 79 // PIPELINE_OK. Returns true if error set, otherwise leaves current error |
| 83 // alone, and returns false. | 80 // alone, and returns false. |
| 84 bool InternalSetError(PipelineError error); | 81 bool InternalSetError(PipelineError error); |
| 85 | 82 |
| 86 // Method called by the |pipeline_thread_| to insert a mime type into | 83 // Method called by the |pipeline_internal_| to insert a mime type into |
| 87 // the |rendered_mime_types_| set. | 84 // the |rendered_mime_types_| set. |
| 88 void InsertRenderedMimeType(const std::string& major_mime_type); | 85 void InsertRenderedMimeType(const std::string& major_mime_type); |
| 89 | 86 |
| 90 // Holds a ref counted reference to the PipelineThread object associated | 87 // Message loop used to execute pipeline tasks. |
| 91 // with this pipeline. Prior to the call to the Start method, this member | 88 MessageLoop* message_loop_; |
| 92 // will be NULL, since no thread is running. | 89 |
| 93 scoped_refptr<PipelineThread> pipeline_thread_; | 90 // Holds a ref counted reference to the PipelineInternal object associated |
| 91 // with this pipeline. Prior to the call to the Start() method, this member |
| 92 // will be NULL, since we are not running. |
| 93 scoped_refptr<PipelineInternal> pipeline_internal_; |
| 94 | 94 |
| 95 // After calling Start, if all of the required filters are created and | 95 // After calling Start, if all of the required filters are created and |
| 96 // initialized, this member will be set to true by the pipeline thread. | 96 // initialized, this member will be set to true by the pipeline thread. |
| 97 bool initialized_; | 97 bool initialized_; |
| 98 | 98 |
| 99 // Duration of the media in microseconds. Set by a FilterHostImpl object on | 99 // Duration of the media in microseconds. Set by a FilterHostImpl object on |
| 100 // behalf of a filter. | 100 // behalf of a filter. |
| 101 base::TimeDelta duration_; | 101 base::TimeDelta duration_; |
| 102 | 102 |
| 103 // Amount of available buffered data in microseconds. Set by a | 103 // Amount of available buffered data in microseconds. Set by a |
| (...skipping 13 matching lines...) Expand all Loading... |
| 117 | 117 |
| 118 // Video width and height. Set by a FilterHostImpl object on behalf | 118 // Video width and height. Set by a FilterHostImpl object on behalf |
| 119 // 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 |
| 120 // 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. |
| 121 size_t video_width_; | 121 size_t video_width_; |
| 122 size_t video_height_; | 122 size_t video_height_; |
| 123 | 123 |
| 124 // 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 |
| 125 // 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 |
| 126 // 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 |
| 127 // this value being updated. Set by the PipelineThread just prior to calling | 127 // this value being updated. Set by the PipelineInternal just prior to |
| 128 // the audio renderer. | 128 // calling the audio renderer. |
| 129 float volume_; | 129 float volume_; |
| 130 | 130 |
| 131 // Current playback rate (>= 0.0f). This member reflects the last value | 131 // Current playback rate (>= 0.0f). This member reflects the last value |
| 132 // 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 |
| 133 // period of time between the client calling SetPlaybackRate and this value | 133 // period of time between the client calling SetPlaybackRate and this value |
| 134 // being updated. Set by the PipelineThread just prior to calling filters. | 134 // being updated. Set by the PipelineInternal just prior to calling filters. |
| 135 float playback_rate_; | 135 float playback_rate_; |
| 136 | 136 |
| 137 // 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 |
| 138 // audio renderer filter. | 138 // audio renderer filter. |
| 139 base::TimeDelta time_; | 139 base::TimeDelta time_; |
| 140 | 140 |
| 141 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that | 141 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that |
| 142 // the pipeline is operating correctly. Any other value indicates that the | 142 // the pipeline is operating correctly. Any other value indicates that the |
| 143 // 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 |
| 144 // reset the pipeline state, and restore this to PIPELINE_OK. | 144 // reset the pipeline state, and restore this to PIPELINE_OK. |
| 145 PipelineError error_; | 145 PipelineError error_; |
| 146 | 146 |
| 147 // 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. |
| 148 typedef std::set<std::string> RenderedMimeTypesSet; | 148 typedef std::set<std::string> RenderedMimeTypesSet; |
| 149 RenderedMimeTypesSet rendered_mime_types_; | 149 RenderedMimeTypesSet rendered_mime_types_; |
| 150 | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 151 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 | 154 |
| 155 // The PipelineThread contains most of the logic involved with running the | 155 // PipelineInternal contains most of the logic involved with running the |
| 156 // media pipeline. Filters are created and called on a dedicated thread owned | 156 // media pipeline. Filters are created and called on the message loop injected |
| 157 // by this object. This object works like a state machine to perform | 157 // into this object. PipelineInternal works like a state machine to perform |
| 158 // asynchronous initialization. Initialization is done in multiple passes in | 158 // asynchronous initialization. Initialization is done in multiple passes by |
| 159 // StartTask(). In each pass a different filter is created and chained with a | 159 // InitializeTask(). In each pass a different filter is created and chained with |
| 160 // previously created filter. | 160 // a previously created filter. |
| 161 // | 161 // |
| 162 // Here's a state diagram that describes the lifetime of this object. | 162 // Here's a state diagram that describes the lifetime of this object. |
| 163 // | 163 // |
| 164 // [ *Created ] -> [ InitDataSource ] -> [ InitDemuxer ] -> | 164 // [ *Created ] -> [ InitDataSource ] -> [ InitDemuxer ] -> |
| 165 // [ InitAudioDecoder ] -> [ InitAudioRenderer ] -> | 165 // [ InitAudioDecoder ] -> [ InitAudioRenderer ] -> |
| 166 // [ InitVideoDecoder ] -> [ InitVideoRenderer ] -> [ Started ] | 166 // [ InitVideoDecoder ] -> [ InitVideoRenderer ] -> [ Started ] |
| 167 // | | | | 167 // | | | |
| 168 // .-> [ Error ] .-> [ Stopped ] <-. | 168 // .-> [ Error ] .-> [ Stopped ] <-. |
| 169 // | 169 // |
| 170 // Initialization is a series of state transitions from "Created" to | 170 // Initialization is a series of state transitions from "Created" to |
| 171 // "Started". If any error happens during initialization, this object will | 171 // "Started". If any error happens during initialization, this object will |
| 172 // transition to the "Error" state from any state. If Stop() is called during | 172 // transition to the "Error" state from any state. If Stop() is called during |
| 173 // initialization, this object will transition to "Stopped" state. | 173 // initialization, this object will transition to "Stopped" state. |
| 174 | 174 |
| 175 class PipelineThread : public base::RefCountedThreadSafe<PipelineThread>, | 175 class PipelineInternal : public base::RefCountedThreadSafe<PipelineInternal> { |
| 176 public MessageLoop::DestructionObserver { | |
| 177 public: | 176 public: |
| 178 // Methods called by PipelineImpl object on the client's thread. These | 177 // Methods called by PipelineImpl object on the client's thread. These |
| 179 // methods post a task to call a corresponding xxxTask() method on the | 178 // methods post a task to call a corresponding xxxTask() method on the |
| 180 // pipeline thread. For example, Seek posts a task to call SeekTask. | 179 // message loop. For example, Seek posts a task to call SeekTask. |
| 181 explicit PipelineThread(PipelineImpl* pipeline); | 180 explicit PipelineInternal(PipelineImpl* pipeline, MessageLoop* message_loop); |
| 182 | 181 |
| 183 // After Start() is called, a task of StartTask() is posted on the pipeline | 182 // After Start() is called, a task of StartTask() is posted on the pipeline |
| 184 // thread to perform initialization. See StartTask() to learn more about | 183 // thread to perform initialization. See StartTask() to learn more about |
| 185 // initialization. | 184 // initialization. |
| 186 bool Start(FilterFactory* filter_factory, | 185 void Start(FilterFactory* filter_factory, |
| 187 const std::string& url_media_source, | 186 const std::string& url_media_source, |
| 188 PipelineCallback* init_complete_callback); | 187 PipelineCallback* start_callback); |
| 189 void Stop(); | 188 void Stop(PipelineCallback* stop_callback); |
| 190 void Seek(base::TimeDelta time, PipelineCallback* seek_callback); | 189 void Seek(base::TimeDelta time, PipelineCallback* seek_callback); |
| 191 void SetPlaybackRate(float rate); | 190 void SetPlaybackRate(float rate); |
| 192 void SetVolume(float volume); | 191 void SetVolume(float volume); |
| 193 | 192 |
| 194 // Methods called by a FilterHostImpl object. These methods may be called | 193 // Methods called by a FilterHostImpl object. These methods may be called |
| 195 // on any thread, either the pipeline's thread or any other. | 194 // on any thread, either the pipeline's thread or any other. |
| 196 | 195 |
| 197 // When a filter calls it's FilterHost, the filter host calls back to the | 196 // When a filter calls it's FilterHost, the filter host calls back to the |
| 198 // pipeline thread. If the pipeline thread is running a nested message loop | 197 // pipeline thread. If the pipeline thread is running a nested message loop |
| 199 // then it will be exited. | 198 // then it will be exited. |
| 200 void InitializationComplete(FilterHostImpl* host); | 199 void InitializationComplete(FilterHostImpl* host); |
| 201 | 200 |
| 202 // Sets the pipeline time and schedules a task to call back to any filters | 201 // Sets the pipeline time and schedules a task to call back to any filters |
| 203 // that have registered a time update callback. | 202 // that have registered a time update callback. |
| 204 void SetTime(base::TimeDelta time); | 203 void SetTime(base::TimeDelta time); |
| 205 | 204 |
| 206 // Called by a FilterHostImpl on behalf of a filter calling FilterHost::Error. | 205 // Called by a FilterHostImpl on behalf of a filter calling FilterHost::Error. |
| 207 // If the pipeline is running a nested message loop, it will be exited. | 206 // If the pipeline is running a nested message loop, it will be exited. |
| 208 void Error(PipelineError error); | 207 void Error(PipelineError error); |
| 209 | 208 |
| 210 // Simple accessor used by the FilterHostImpl class to get access to the | 209 // Simple accessor used by the FilterHostImpl class to get access to the |
| 211 // pipeline object. | 210 // pipeline object. |
| 211 // |
| 212 // TODO(scherkus): I think FilterHostImpl should not be talking to |
| 213 // PipelineImpl but rather PipelineInternal. |
| 212 PipelineImpl* pipeline() const { return pipeline_; } | 214 PipelineImpl* pipeline() const { return pipeline_; } |
| 213 | 215 |
| 214 // Accessor used to post messages to thread's message loop. | 216 // Returns true if the pipeline has fully initialized. |
| 215 MessageLoop* message_loop() const { return thread_.message_loop(); } | 217 bool IsInitialized() { return state_ == kStarted; } |
| 216 | |
| 217 // Accessor used by PipelineImpl to check if we're executing on the pipeline | |
| 218 // thread. | |
| 219 PlatformThreadId thread_id() const { return thread_.thread_id(); } | |
| 220 | 218 |
| 221 private: | 219 private: |
| 222 // Only allow ourselves to be destroyed via ref-counting. | 220 // Only allow ourselves to be destroyed via ref-counting. |
| 223 friend class base::RefCountedThreadSafe<PipelineThread>; | 221 friend class base::RefCountedThreadSafe<PipelineInternal>; |
| 224 virtual ~PipelineThread(); | 222 virtual ~PipelineInternal(); |
| 225 | 223 |
| 226 enum State { | 224 enum State { |
| 227 kCreated, | 225 kCreated, |
| 228 kInitDataSource, | 226 kInitDataSource, |
| 229 kInitDemuxer, | 227 kInitDemuxer, |
| 230 kInitAudioDecoder, | 228 kInitAudioDecoder, |
| 231 kInitAudioRenderer, | 229 kInitAudioRenderer, |
| 232 kInitVideoDecoder, | 230 kInitVideoDecoder, |
| 233 kInitVideoRenderer, | 231 kInitVideoRenderer, |
| 234 kStarted, | 232 kStarted, |
| 235 kStopped, | 233 kStopped, |
| 236 kError, | 234 kError, |
| 237 }; | 235 }; |
| 238 | 236 |
| 239 // Simple method used to make sure the pipeline is running normally. | 237 // Simple method used to make sure the pipeline is running normally. |
| 240 bool IsPipelineOk() { return PIPELINE_OK == pipeline_->error_; } | 238 bool IsPipelineOk() { return PIPELINE_OK == pipeline_->error_; } |
| 241 | 239 |
| 242 // Helper method to tell whether we are in the state of initializing. | 240 // Helper method to tell whether we are in the state of initializing. |
| 243 bool IsPipelineInitializing() { | 241 bool IsPipelineInitializing() { |
| 244 return state_ == kInitDataSource || | 242 return state_ == kInitDataSource || |
| 245 state_ == kInitDemuxer || | 243 state_ == kInitDemuxer || |
| 246 state_ == kInitAudioDecoder || | 244 state_ == kInitAudioDecoder || |
| 247 state_ == kInitAudioRenderer || | 245 state_ == kInitAudioRenderer || |
| 248 state_ == kInitVideoDecoder || | 246 state_ == kInitVideoDecoder || |
| 249 state_ == kInitVideoRenderer; | 247 state_ == kInitVideoRenderer; |
| 250 } | 248 } |
| 251 | 249 |
| 252 // Implementation of MessageLoop::DestructionObserver. StartTask registers | 250 // The following "task" methods correspond to the public methods, but these |
| 253 // this class as a destruction observer on the thread's message loop. | 251 // methods are run as the result of posting a task to the PipelineInternal's |
| 254 // It is used to destroy the list of FilterHosts | 252 // message loop. |
| 255 // (and thus destroy the associated filters) when all tasks have been | 253 void StartTask(FilterFactory* filter_factory, |
| 256 // processed and the message loop has been quit. | 254 const std::string& url, |
| 257 virtual void WillDestroyCurrentMessageLoop(); | 255 PipelineCallback* start_callback); |
| 258 | 256 |
| 259 // The following "task" methods correspond to the public methods, but these | 257 // InitializeTask() performs initialization in multiple passes. It is executed |
| 260 // methods are run as the result of posting a task to the PipelineThread's | 258 // as a result of calling Start() or InitializationComplete() that advances |
| 261 // message loop. | 259 // initialization to the next state. It works as a hub of state transition for |
| 260 // initialization. |
| 261 void InitializeTask(); |
| 262 | 262 |
| 263 // StartTask() is a special task that performs initialization in multiple | 263 // StopTask() and ErrorTask() are similar but serve different purposes: |
| 264 // passes. It is executed as a result of calling Start() or | 264 // - Both destroy the filter chain. |
| 265 // InitializationComplete() that advances initialization to the next state. It | 265 // - Both will execute |start_callback| if the pipeline was initializing. |
| 266 // works as a hub of state transition for initialization. | 266 // - StopTask() resets the pipeline to a fresh state, where as ErrorTask() |
| 267 void StartTask(); | 267 // leaves the pipeline as is for client inspection. |
| 268 void StopTask(); | 268 // - StopTask() can be scheduled by the client calling Stop(), where as |
| 269 // ErrorTask() is scheduled as a result of a filter calling Error(). |
| 270 void StopTask(PipelineCallback* stop_callback); |
| 271 void ErrorTask(PipelineError error); |
| 272 |
| 269 void SetPlaybackRateTask(float rate); | 273 void SetPlaybackRateTask(float rate); |
| 270 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); | 274 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); |
| 271 void SetVolumeTask(float volume); | 275 void SetVolumeTask(float volume); |
| 272 | 276 |
| 273 // Internal methods used in the implementation of the pipeline thread. All | 277 // Internal methods used in the implementation of the pipeline thread. All |
| 274 // of these methods are only called on the pipeline thread. | 278 // of these methods are only called on the pipeline thread. |
| 275 | 279 |
| 276 // The following template functions make use of the fact that media filter | 280 // The following template functions make use of the fact that media filter |
| 277 // derived interfaces are self-describing in the sense that they all contain | 281 // derived interfaces are self-describing in the sense that they all contain |
| 278 // the static method filter_type() which returns a FilterType enum that | 282 // the static method filter_type() which returns a FilterType enum that |
| (...skipping 16 matching lines...) Expand all Loading... |
| 295 // Callers can optionally use the returned Filter for further processing, | 299 // Callers can optionally use the returned Filter for further processing, |
| 296 // but since the call already placed the filter in the list of filter hosts, | 300 // but since the call already placed the filter in the list of filter hosts, |
| 297 // callers can ignore the return value. In any case, if this function can | 301 // callers can ignore the return value. In any case, if this function can |
| 298 // not create and initializes the specified Filter, then this method will | 302 // not create and initializes the specified Filter, then this method will |
| 299 // return with |pipeline_->error_| != PIPELINE_OK. | 303 // return with |pipeline_->error_| != PIPELINE_OK. |
| 300 template <class Filter, class Source> | 304 template <class Filter, class Source> |
| 301 void CreateFilter(FilterFactory* filter_factory, | 305 void CreateFilter(FilterFactory* filter_factory, |
| 302 Source source, | 306 Source source, |
| 303 const MediaFormat& source_media_format); | 307 const MediaFormat& source_media_format); |
| 304 | 308 |
| 305 // Creates a Filter and initilizes it with the given |source|. If a Filter | 309 // Creates a Filter and initializes it with the given |source|. If a Filter |
| 306 // could not be created or an error occurred, this metod returns NULL and the | 310 // could not be created or an error occurred, this method returns NULL and the |
| 307 // pipeline's |error_| member will contain a specific error code. Note that | 311 // pipeline's |error_| member will contain a specific error code. Note that |
| 308 // the Source could be a filter or a DemuxerStream, but it must support the | 312 // the Source could be a filter or a DemuxerStream, but it must support the |
| 309 // GetMediaFormat() method. | 313 // GetMediaFormat() method. |
| 310 template <class Filter, class Source> | 314 template <class Filter, class Source> |
| 311 void CreateFilter(FilterFactory* filter_factory, Source* source) { | 315 void CreateFilter(FilterFactory* filter_factory, Source* source) { |
| 312 CreateFilter<Filter, Source*>(filter_factory, | 316 CreateFilter<Filter, Source*>(filter_factory, |
| 313 source, | 317 source, |
| 314 source->media_format()); | 318 source->media_format()); |
| 315 } | 319 } |
| 316 | 320 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 332 // stream does not exist. | 336 // stream does not exist. |
| 333 template <class Decoder, class Renderer> | 337 template <class Decoder, class Renderer> |
| 334 bool CreateRenderer(); | 338 bool CreateRenderer(); |
| 335 | 339 |
| 336 // Examine the list of existing filters to find one that supports the | 340 // Examine the list of existing filters to find one that supports the |
| 337 // specified Filter interface. If one exists, the |filter_out| will contain | 341 // specified Filter interface. If one exists, the |filter_out| will contain |
| 338 // the filter, |*filter_out| will be NULL. | 342 // the filter, |*filter_out| will be NULL. |
| 339 template <class Filter> | 343 template <class Filter> |
| 340 void GetFilter(scoped_refptr<Filter>* filter_out) const; | 344 void GetFilter(scoped_refptr<Filter>* filter_out) const; |
| 341 | 345 |
| 342 // Pointer to the pipeline that owns this PipelineThread. | 346 // Stops every filters, filter host and filter thread and releases all |
| 343 PipelineImpl* const pipeline_; | 347 // references to them. |
| 348 void DestroyFilters(); |
| 344 | 349 |
| 345 // The actual thread. | 350 // Pointer to the pipeline that owns this PipelineInternal. |
| 346 base::Thread thread_; | 351 PipelineImpl* pipeline_; |
| 347 | 352 |
| 348 // Used to avoid scheduling multiple time update tasks. If this member is | 353 // Message loop used to execute pipeline tasks. |
| 349 // true then a task that will call the SetTimeTask() method is in the message | 354 MessageLoop* message_loop_; |
| 350 // loop's queue. | |
| 351 bool time_update_callback_scheduled_; | |
| 352 | 355 |
| 353 // Member that tracks the current state. | 356 // Member that tracks the current state. |
| 354 State state_; | 357 State state_; |
| 355 | 358 |
| 356 // Filter factory as passed in by Start(). | 359 // Filter factory as passed in by Start(). |
| 357 scoped_refptr<FilterFactory> filter_factory_; | 360 scoped_refptr<FilterFactory> filter_factory_; |
| 358 | 361 |
| 359 // URL for the data source as passed in by Start(). | 362 // URL for the data source as passed in by Start(). |
| 360 std::string url_; | 363 std::string url_; |
| 361 | 364 |
| 362 // Initialization callback as passed in by Start(). | 365 // Callbacks for various pipeline operations. |
| 363 scoped_ptr<PipelineCallback> init_callback_; | 366 scoped_ptr<PipelineCallback> start_callback_; |
| 367 scoped_ptr<PipelineCallback> seek_callback_; |
| 368 scoped_ptr<PipelineCallback> stop_callback_; |
| 364 | 369 |
| 365 // Vector of FilterHostImpl objects that contian the filters for the pipeline. | 370 // Vector of FilterHostImpl objects that contain the filters for the pipeline. |
| 366 typedef std::vector<FilterHostImpl*> FilterHostVector; | 371 typedef std::vector<FilterHostImpl*> FilterHostVector; |
| 367 FilterHostVector filter_hosts_; | 372 FilterHostVector filter_hosts_; |
| 368 | 373 |
| 369 typedef std::vector<base::Thread*> FilterThreadVector; | 374 typedef std::vector<base::Thread*> FilterThreadVector; |
| 370 FilterThreadVector filter_threads_; | 375 FilterThreadVector filter_threads_; |
| 371 | 376 |
| 372 DISALLOW_COPY_AND_ASSIGN(PipelineThread); | 377 DISALLOW_COPY_AND_ASSIGN(PipelineInternal); |
| 373 }; | 378 }; |
| 374 | 379 |
| 375 } // namespace media | 380 } // namespace media |
| 376 | 381 |
| 377 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 382 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |