Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 | 13 |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 15 #include "base/thread.h" | 16 #include "base/thread.h" |
| 16 #include "base/time.h" | 17 #include "base/time.h" |
| 17 #include "media/base/pipeline.h" | 18 #include "media/base/pipeline.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 class FilterHostImpl; | 22 class FilterHostImpl; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 36 virtual base::TimeDelta GetDuration() const; | 37 virtual base::TimeDelta GetDuration() const; |
| 37 virtual base::TimeDelta GetBufferedTime() const; | 38 virtual base::TimeDelta GetBufferedTime() const; |
| 38 virtual int64 GetTotalBytes() const; | 39 virtual int64 GetTotalBytes() const; |
| 39 virtual int64 GetBufferedBytes()const; | 40 virtual int64 GetBufferedBytes()const; |
| 40 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; | 41 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; |
| 41 virtual float GetVolume() const; | 42 virtual float GetVolume() const; |
| 42 virtual float GetPlaybackRate() const; | 43 virtual float GetPlaybackRate() const; |
| 43 virtual base::TimeDelta GetTime() const; | 44 virtual base::TimeDelta GetTime() const; |
| 44 virtual base::TimeDelta GetInterpolatedTime() const; | 45 virtual base::TimeDelta GetInterpolatedTime() const; |
| 45 virtual PipelineError GetError() const; | 46 virtual PipelineError GetError() const; |
| 47 virtual bool IsRendered(const std::string& major_mime_type) const; | |
| 46 | 48 |
| 47 // Impementation of Pipeline methods. | 49 // Impementation of Pipeline methods. |
| 48 virtual bool Start(FilterFactory* filter_factory, | 50 virtual bool Start(FilterFactory* filter_factory, |
| 49 const std::string& url, | 51 const std::string& url, |
| 50 Callback1<bool>::Type* init_complete_callback); | 52 Callback1<bool>::Type* init_complete_callback); |
| 51 virtual void Stop(); | 53 virtual void Stop(); |
| 52 virtual void SetPlaybackRate(float rate); | 54 virtual void SetPlaybackRate(float rate); |
| 53 virtual void Seek(base::TimeDelta time); | 55 virtual void Seek(base::TimeDelta time); |
| 54 virtual void SetVolume(float volume); | 56 virtual void SetVolume(float volume); |
| 55 | 57 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 75 void SetBufferedBytes(int64 buffered_bytes); | 77 void SetBufferedBytes(int64 buffered_bytes); |
| 76 void SetVideoSize(size_t width, size_t height); | 78 void SetVideoSize(size_t width, size_t height); |
| 77 void SetTime(base::TimeDelta time); | 79 void SetTime(base::TimeDelta time); |
| 78 void InternalSetPlaybackRate(float rate); | 80 void InternalSetPlaybackRate(float rate); |
| 79 | 81 |
| 80 // Sets the error to the new error code only if the current error state is | 82 // Sets the error to the new error code only if the current error state is |
| 81 // PIPELINE_OK. Returns true if error set, otherwise leaves current error | 83 // PIPELINE_OK. Returns true if error set, otherwise leaves current error |
| 82 // alone, and returns false. | 84 // alone, and returns false. |
| 83 bool InternalSetError(PipelineError error); | 85 bool InternalSetError(PipelineError error); |
| 84 | 86 |
| 87 // Method called by the |pipeline_thread_| to insert a mime type into | |
| 88 // the |rendered_mime_types_| set. | |
| 89 void InsertRenderedMimeType(const std::string& major_mime_type); | |
| 90 | |
| 85 // Holds a ref counted reference to the PipelineThread object associated | 91 // Holds a ref counted reference to the PipelineThread object associated |
| 86 // with this pipeline. Prior to the call to the Start method, this member | 92 // with this pipeline. Prior to the call to the Start method, this member |
| 87 // will be NULL, since no thread is running. | 93 // will be NULL, since no thread is running. |
| 88 scoped_refptr<PipelineThread> pipeline_thread_; | 94 scoped_refptr<PipelineThread> pipeline_thread_; |
| 89 | 95 |
| 90 // After calling Start, if all of the required filters are created and | 96 // After calling Start, if all of the required filters are created and |
| 91 // initialized, this member will be set to true by the pipeline thread. | 97 // initialized, this member will be set to true by the pipeline thread. |
| 92 bool initialized_; | 98 bool initialized_; |
| 93 | 99 |
| 94 // Duration of the media in microseconds. Set by a FilterHostImpl object on | 100 // Duration of the media in microseconds. Set by a FilterHostImpl object on |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 // Internal system timer at last time the SetTime method was called. Used to | 142 // Internal system timer at last time the SetTime method was called. Used to |
| 137 // compute interpolated time. | 143 // compute interpolated time. |
| 138 base::TimeTicks ticks_at_last_set_time_; | 144 base::TimeTicks ticks_at_last_set_time_; |
| 139 | 145 |
| 140 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that | 146 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that |
| 141 // the pipeline is operating correctly. Any other value indicates that the | 147 // the pipeline is operating correctly. Any other value indicates that the |
| 142 // pipeline is stopped or is stopping. Clients can call the Stop method to | 148 // pipeline is stopped or is stopping. Clients can call the Stop method to |
| 143 // reset the pipeline state, and restore this to PIPELINE_OK. | 149 // reset the pipeline state, and restore this to PIPELINE_OK. |
| 144 PipelineError error_; | 150 PipelineError error_; |
| 145 | 151 |
| 152 // Vector of major mime types that have been rendered by this pipeline. | |
| 153 typedef std::set<std::string> RenderedMimeTypesSet; | |
| 154 RenderedMimeTypesSet rendered_mime_types_; | |
| 155 | |
| 146 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); | 156 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); |
| 147 }; | 157 }; |
| 148 | 158 |
| 149 | 159 |
| 150 // The PipelineThread contains most of the logic involved with running the | 160 // The PipelineThread contains most of the logic involved with running the |
| 151 // media pipeline. Filters are created and called on a dedicated thread owned | 161 // media pipeline. Filters are created and called on a dedicated thread owned |
| 152 // by this object. | 162 // by this object. |
| 153 class PipelineThread : public base::RefCountedThreadSafe<PipelineThread>, | 163 class PipelineThread : public base::RefCountedThreadSafe<PipelineThread>, |
| 154 public MessageLoop::DestructionObserver { | 164 public MessageLoop::DestructionObserver { |
| 155 public: | 165 public: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 // Implementation of MessageLoop::DestructionObserver. StartTask registers | 207 // Implementation of MessageLoop::DestructionObserver. StartTask registers |
| 198 // this class as a destruction observer on the thread's message loop. | 208 // this class as a destruction observer on the thread's message loop. |
| 199 // It is used to destroy the list of FilterHosts | 209 // It is used to destroy the list of FilterHosts |
| 200 // (and thus destroy the associated filters) when all tasks have been | 210 // (and thus destroy the associated filters) when all tasks have been |
| 201 // processed and the message loop has been quit. | 211 // processed and the message loop has been quit. |
| 202 virtual void WillDestroyCurrentMessageLoop(); | 212 virtual void WillDestroyCurrentMessageLoop(); |
| 203 | 213 |
| 204 friend class base::RefCountedThreadSafe<PipelineThread>; | 214 friend class base::RefCountedThreadSafe<PipelineThread>; |
| 205 virtual ~PipelineThread(); | 215 virtual ~PipelineThread(); |
| 206 | 216 |
| 217 // Simple method used to make sure the pipeline is running normally. | |
| 218 bool PipelineOk() { return PIPELINE_OK == pipeline_->error_; } | |
| 219 | |
| 207 // The following "task" methods correspond to the public methods, but these | 220 // The following "task" methods correspond to the public methods, but these |
| 208 // methods are run as the result of posting a task to the PipelineThread's | 221 // methods are run as the result of posting a task to the PipelineThread's |
| 209 // message loop. For example, the Start method posts a task to call the | 222 // message loop. For example, the Start method posts a task to call the |
| 210 // StartTask message on the pipeline thread. | 223 // StartTask message on the pipeline thread. |
| 211 void StartTask(FilterFactory* filter_factory, | 224 void StartTask(FilterFactory* filter_factory, |
| 212 const std::string& url, | 225 const std::string& url, |
| 213 Callback1<bool>::Type* init_complete_callback); | 226 Callback1<bool>::Type* init_complete_callback); |
| 214 void StopTask(); | 227 void StopTask(); |
| 215 void SetPlaybackRateTask(float rate); | 228 void SetPlaybackRateTask(float rate); |
| 216 void SeekTask(base::TimeDelta time); | 229 void SeekTask(base::TimeDelta time); |
| 217 void SetVolumeTask(float volume); | 230 void SetVolumeTask(float volume); |
| 218 void SetTimeTask(); | 231 void SetTimeTask(); |
| 219 void InitializationCompleteTask(FilterHostImpl* FilterHost); | 232 void InitializationCompleteTask(FilterHostImpl* FilterHost); |
| 220 | 233 |
| 221 // Internal methods used in the implementation of the pipeline thread. All | 234 // Internal methods used in the implementation of the pipeline thread. All |
| 222 // of these methods are only called on the pipeline thread. | 235 // of these methods are only called on the pipeline thread. |
| 223 | 236 |
| 224 // Calls the Stop method on every filter in the pipeline | 237 // Calls the Stop method on every filter in the pipeline |
| 225 void StopFilters(); | 238 void StopFilters(); |
| 226 | 239 |
| 227 // Examines the demuxer filter output streams. If one contains video then | |
| 228 // returns true. | |
| 229 bool HasVideo() const; | |
| 230 | |
| 231 // The following template funcions make use of the fact that media filter | 240 // The following template funcions make use of the fact that media filter |
| 232 // derived interfaces are self-describing in the sense that they all contain | 241 // derived interfaces are self-describing in the sense that they all contain |
| 233 // the static method filter_type() which returns a FilterType enum that | 242 // the static method filter_type() which returns a FilterType enum that |
| 234 // uniquely identifies the filer's interface. In addition, filters that are | 243 // uniquely identifies the filer's interface. In addition, filters that are |
| 235 // specific to audio or video also support a static method major_mime_type() | 244 // specific to audio or video also support a static method major_mime_type() |
| 236 // which returns a string of "audio/" or "video/". | 245 // which returns a string of "audio/" or "video/". |
| 237 | 246 |
| 238 // Uses the FilterFactory to create a new filter of the NewFilter class, and | 247 // Uses the FilterFactory to create a new filter of the Filter class, and |
| 239 // initiaializes it using the Source object. The source may be another filter | 248 // initiaializes it using the Source object. The source may be another filter |
| 240 // or it could be a string in the case of a DataSource. | 249 // or it could be a string in the case of a DataSource. |
| 241 // | 250 // |
| 242 // The CreateFilter method actually does much more than simply creating the | 251 // The CreateFilter method actually does much more than simply creating the |
| 243 // filter. It creates the FilterHostImpl object, creates the filter using | 252 // filter. It creates the FilterHostImpl object, creates the filter using |
| 244 // the filter factory, calls the MediaFilter::SetHost method on the filter, | 253 // the filter factory, calls the MediaFilter::SetHost method on the filter, |
| 245 // and then calls the filter's type-specific Initialize(source) method to | 254 // and then calls the filter's type-specific Initialize(source) method to |
| 246 // initialize the filter. It then runs the thread's message loop and waits | 255 // initialize the filter. It then runs the thread's message loop and waits |
| 247 // until one of the following occurs: | 256 // until one of the following occurs: |
| 248 // 1. The filter calls FilterHost::InitializationComplete() | 257 // 1. The filter calls FilterHost::InitializationComplete() |
| 249 // 2. A filter calls FilterHost::Error() | 258 // 2. A filter calls FilterHost::Error() |
| 250 // 3. The client calls Pipeline::Stop() | 259 // 3. The client calls Pipeline::Stop() |
| 251 template <class NewFilter, class Source> | 260 // |
| 252 bool CreateFilter(FilterFactory* filter_factory, | 261 // Callers can optionally use the returned Filter for further processing, |
| 253 Source source, | 262 // but since the call already placed the filter in the list of filter hosts, |
| 254 const MediaFormat* source_media_format); | 263 // callers can ignore the return value. In any case, if this function can |
| 264 // not create and initailze the speified Filter, then this method will return | |
| 265 // with |pipeline_->error_| != PIPELINE_OK. | |
| 266 template <class Filter, class Source> | |
| 267 scoped_refptr<Filter> CreateFilter(FilterFactory* filter_factory, | |
| 268 Source source, | |
| 269 const MediaFormat* source_media_format); | |
| 270 | |
| 271 // Creates a Filter and initilizes it with the given |source|. If a Filter | |
| 272 // could not be created or an error occurred, this metod returns NULL and the | |
| 273 // pipeline's |error_| member will contain a specific error code. Note that | |
| 274 // the Source could be a filter or a DemuxerStream, but it must support the | |
| 275 // GetMediaFormat() method. | |
| 276 template <class Filter, class Source> | |
| 277 scoped_refptr<Filter> CreateFilter(FilterFactory* filter_factory, | |
| 278 Source* source) { | |
| 279 return CreateFilter<Filter, Source*>(filter_factory, | |
| 280 source, | |
| 281 source->GetMediaFormat()); | |
| 282 } | |
| 255 | 283 |
| 256 // Creates a DataSource (the first filter in a pipeline), and initializes it | 284 // Creates a DataSource (the first filter in a pipeline), and initializes it |
| 257 // with the specified URL. | 285 // with the specified URL. |
| 258 bool CreateDataSource(FilterFactory* filter_factory, | 286 scoped_refptr<DataSource> CreateDataSource(FilterFactory* filter_factory, |
| 259 const std::string& url); | 287 const std::string& url); |
| 260 | 288 |
| 261 // Examines the list of existing filters to find a Source, then creates a | 289 // If the |demuxer| contains a stream that matches Decoder::major_media_type() |
| 262 // NewFilter, and initializes it with the Source filter. | 290 // this method creates and initializes the specified Decoder and Renderer. |
| 263 template <class NewFilter, class Source> | 291 // Callers should examine the |pipeline_->error_| member to see if there was |
| 264 bool CreateAndConnect(FilterFactory* filter_factory); | 292 // an error duing the call. The lack of the specified stream does not |
| 265 | 293 // constitute an error, and no Decoder or Renderer will be created if the |
| 266 // Creates and initiaializes a decoder. | 294 // data stream does not exist in the |demuxer|. If a stream is rendered, then |
| 267 template <class Decoder> | 295 // this method will call |pipeline_|->InsertRenderedMimeType() to add the |
| 268 bool CreateDecoder(FilterFactory* filter_factory); | 296 // mime type to the set of rendered major mime types for the pipeline. |
| 297 template <class Decoder, class Renderer> | |
| 298 void Render(FilterFactory* filter_factory, Demuxer* demuxer); | |
| 269 | 299 |
| 270 // Examine the list of existing filters to find one that supports the | 300 // Examine the list of existing filters to find one that supports the |
| 271 // specified Filter interface. If one exists, the specified Filter interface | 301 // specified Filter interface. If one exists, the |filter_out| will contain |
| 272 // is returned otherwise the method retuns NULL. | 302 // the filter, |*filer_out| will be NULL. |
|
scherkus (not reviewing)
2009/03/06 18:52:20
typo on filter_out
| |
| 273 template <class Filter> | 303 template <class Filter> |
| 274 Filter* GetFilter() const; | 304 void GetFilter(scoped_refptr<Filter>* filter_out) const; |
| 275 | |
| 276 // Simple function that returns true if the specified MediaFormat object | |
| 277 // has a mime type that matches the major_mime_type. Examples of major mime | |
| 278 // types are "audio/" and "video/" | |
| 279 bool IsMajorMimeType(const MediaFormat* media_format, | |
| 280 const std::string& major_mime_type) const; | |
| 281 | 305 |
| 282 // Pointer to the pipeline that owns this PipelineThread. | 306 // Pointer to the pipeline that owns this PipelineThread. |
| 283 PipelineImpl* const pipeline_; | 307 PipelineImpl* const pipeline_; |
| 284 | 308 |
| 285 // The actual thread. | 309 // The actual thread. |
| 286 base::Thread thread_; | 310 base::Thread thread_; |
| 287 | 311 |
| 288 // Used to avoid scheduling multiple time update tasks. If this member is | 312 // Used to avoid scheduling multiple time update tasks. If this member is |
| 289 // true then a task that will call the SetTimeTask() method is in the message | 313 // true then a task that will call the SetTimeTask() method is in the message |
| 290 // loop's queue. | 314 // loop's queue. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 301 // Vector of FilterHostImpl objects that contian the filters for the pipeline. | 325 // Vector of FilterHostImpl objects that contian the filters for the pipeline. |
| 302 typedef std::vector<FilterHostImpl*> FilterHostVector; | 326 typedef std::vector<FilterHostImpl*> FilterHostVector; |
| 303 FilterHostVector filter_hosts_; | 327 FilterHostVector filter_hosts_; |
| 304 | 328 |
| 305 DISALLOW_COPY_AND_ASSIGN(PipelineThread); | 329 DISALLOW_COPY_AND_ASSIGN(PipelineThread); |
| 306 }; | 330 }; |
| 307 | 331 |
| 308 } // namespace media | 332 } // namespace media |
| 309 | 333 |
| 310 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ | 334 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ |
| OLD | NEW |