Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: media/base/pipeline.h

Issue 149215: Big media::Pipeline cleanup. (Closed)
Patch Set: Test Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/mock_filter_host.h ('k') | media/base/pipeline_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // The pipeline is the public API clients use for playing back media. Clients 5 // The pipeline is the public API clients use for playing back media. Clients
6 // provide a filter factory containing the filters they want the pipeline to 6 // provide a filter factory containing the filters they want the pipeline to
7 // use to render media. 7 // use to render media.
8 8
9 #ifndef MEDIA_BASE_PIPELINE_H_ 9 #ifndef MEDIA_BASE_PIPELINE_H_
10 #define MEDIA_BASE_PIPELINE_H_ 10 #define MEDIA_BASE_PIPELINE_H_
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/task.h" 14 #include "base/task.h"
15 #include "media/base/factory.h" 15 #include "media/base/factory.h"
16 16
17 namespace base { 17 namespace base {
18 class TimeDelta; 18 class TimeDelta;
19 } 19 }
20 20
21 namespace media { 21 namespace media {
22 22
23 // Error definitions for pipeline. All codes indicate an error except: 23 // Error definitions for pipeline. All codes indicate an error except:
24 // PIPELINE_OK indicates the pipeline is running normally. 24 // PIPELINE_OK indicates the pipeline is running normally.
25 // PIPELINE_STOPPING is used internally when Pipeline::Stop() is called. 25 // PIPELINE_STOPPING is used internally when Pipeline::Stop() is called.
26 enum PipelineError { 26 enum PipelineError {
27 PIPELINE_OK, 27 PIPELINE_OK,
28 PIPELINE_STOPPING, 28 PIPELINE_STOPPING,
29 PIPELINE_ERROR_URL_NOT_FOUND, 29 PIPELINE_ERROR_URL_NOT_FOUND,
30 PIPELINE_ERROR_NETWORK, 30 PIPELINE_ERROR_NETWORK,
31 PIPELINE_ERROR_DECODE, 31 PIPELINE_ERROR_DECODE,
32 PIPELINE_ERROR_ABORT, 32 PIPELINE_ERROR_ABORT,
33 PIPELINE_ERROR_INITIALIZATION_FAILED, 33 PIPELINE_ERROR_INITIALIZATION_FAILED,
34 PIPELINE_ERROR_REQUIRED_FILTER_MISSING, 34 PIPELINE_ERROR_REQUIRED_FILTER_MISSING,
35 PIPELINE_ERROR_OUT_OF_MEMORY, 35 PIPELINE_ERROR_OUT_OF_MEMORY,
36 PIPELINE_ERROR_COULD_NOT_RENDER, 36 PIPELINE_ERROR_COULD_NOT_RENDER,
37 PIPELINE_ERROR_READ, 37 PIPELINE_ERROR_READ,
38 PIPELINE_ERROR_AUDIO_HARDWARE, 38 PIPELINE_ERROR_AUDIO_HARDWARE,
39 PIPELINE_ERROR_NO_DATA, 39 PIPELINE_ERROR_NO_DATA,
40 // Demuxer related errors. 40 // Demuxer related errors.
41 DEMUXER_ERROR_COULD_NOT_OPEN, 41 DEMUXER_ERROR_COULD_NOT_OPEN,
42 DEMUXER_ERROR_COULD_NOT_PARSE, 42 DEMUXER_ERROR_COULD_NOT_PARSE,
43 DEMUXER_ERROR_NO_SUPPORTED_STREAMS, 43 DEMUXER_ERROR_NO_SUPPORTED_STREAMS,
44 DEMUXER_ERROR_COULD_NOT_CREATE_THREAD, 44 DEMUXER_ERROR_COULD_NOT_CREATE_THREAD,
45 }; 45 };
46 46
47 // Base class for Pipeline class which allows for read-only access to members.
48 // Filters are allowed to access the PipelineStatus interface but are not given
49 // access to the client Pipeline methods.
50 class PipelineStatus {
51 public:
52 // Returns the current initialization state of the pipeline. Clients can
53 // examine this to determine if it is acceptable to call SetRate/SetVolume/
54 // Seek after calling Start on the pipeline. Note that this will be
55 // set to true prior to a call to the client's |init_complete_callback| if
56 // initialization is successful.
57 virtual bool IsInitialized() const = 0;
58
59 // Get the duration of the media in microseconds. If the duration has not
60 // been determined yet, then returns 0.
61 virtual base::TimeDelta GetDuration() const = 0;
62
63 // Get the approximate amount of playable data buffered so far in micro-
64 // seconds.
65 virtual base::TimeDelta GetBufferedTime() const = 0;
66
67 // Get the total size of the media file. If the size has not yet been
68 // determined or can not be determined, this value is 0.
69 virtual int64 GetTotalBytes() const = 0;
70
71 // Get the total number of bytes that are buffered on the client and ready to
72 // be played.
73 virtual int64 GetBufferedBytes() const = 0;
74
75 // Gets the size of the video output in pixel units. If there is no video
76 // or the video has not been rendered yet, the width and height will be 0.
77 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const = 0;
78
79 // Gets the current volume setting being used by the audio renderer. When
80 // the pipeline is started, this value will be 1.0f. Valid values range
81 // from 0.0f to 1.0f.
82 virtual float GetVolume() const = 0;
83
84 // Gets the current playback rate of the pipeline. When the pipeline is
85 // started, the playback rate will be 0.0f. A rate of 1.0f indicates
86 // that the pipeline is rendering the media at the standard rate. Valid
87 // values for playback rate are >= 0.0f.
88 virtual float GetPlaybackRate() const = 0;
89
90 // Gets the current pipeline time in microseconds. For a pipeline "time"
91 // progresses from 0 to the end of the media. This time base is updated
92 // by the audio renderer to allow for synchronization of audio and video.
93 // Note that a more accurate time may be obtained by calling the
94 // GetInterpolatedTime method which estimates the position of the audio
95 // device based on a combination of the last time the audio device reported
96 // it's position and the current system time.
97 virtual base::TimeDelta GetTime() const = 0;
98
99 // Gets the current pipeline time in microseconds. For a pipeline "time"
100 // progresses from 0 to the end of the media. Becuase this method provides
101 // an estimated time, it is possible that subsequent calls to this method will
102 // actually progress backwards slightly, so callers must not assume that this
103 // method will always return times larger than the last one.
104 virtual base::TimeDelta GetInterpolatedTime() const = 0;
105
106 // Gets the current error status for the pipeline. If the pipeline is
107 // operating correctly, this will return OK.
108 virtual PipelineError GetError() const = 0;
109
110 // If the |major_mime_type| exists in the pipeline and is being rendered, this
111 // method will return true. Types are defined in media/base/media_foramt.h.
112 // For example, to determine if a pipeline contains video:
113 // bool has_video = pipeline->IsRendered(mime_type::kMajorTypeVideo);
114 virtual bool IsRendered(const std::string& major_mime_type) const = 0;
115
116 protected:
117 virtual ~PipelineStatus() {}
118 };
119
120 // Client-provided callbacks for various pipeline operations. 47 // Client-provided callbacks for various pipeline operations.
121 // 48 //
122 // TODO(scherkus): consider returning a PipelineError instead of a bool, or 49 // TODO(scherkus): consider returning a PipelineError instead of a bool, or
123 // perhaps a client callback interface. 50 // perhaps a client callback interface.
124 typedef Callback1<bool>::Type PipelineCallback; 51 typedef Callback1<bool>::Type PipelineCallback;
125 52
126 class Pipeline : public PipelineStatus { 53 class Pipeline {
127 public: 54 public:
128 // Build a pipeline to render the given URI using the given filter factory to 55 // Build a pipeline to render the given URL using the given filter factory to
129 // construct a filter chain. Returns true if successful, false otherwise 56 // construct a filter chain. Returns true if successful, false otherwise
130 // (i.e., pipeline already started). Note that a return value of true 57 // (i.e., pipeline already started). Note that a return value of true
131 // only indicates that the initialization process has started successfully. 58 // only indicates that the initialization process has started successfully.
132 // Pipeline initialization is an inherently asynchronous process. Clients 59 // Pipeline initialization is an inherently asynchronous process. Clients
133 // should not call SetPlaybackRate(), Seek(), or SetVolume() until 60 // should not call SetPlaybackRate(), Seek(), or SetVolume() until
134 // initialization is complete. Clients can either poll the IsInitialized() 61 // initialization is complete. Clients can either poll the IsInitialized()
135 // method (which is discouraged) or use the |start_callback| as described 62 // method (which is discouraged) or use the |start_callback| as described
136 // below. 63 // below.
137 // 64 //
138 // This method is asynchronous and can execute a callback when completed. 65 // This method is asynchronous and can execute a callback when completed.
139 // If the caller provides a |start_callback|, it will be called when the 66 // If the caller provides a |start_callback|, it will be called when the
140 // pipeline initialization completes. If successful, the callback's bool 67 // pipeline initialization completes. If successful, the callback's bool
141 // parameter will be true. If the callback is called with false, then the 68 // parameter will be true. If the callback is called with false, then the
142 // client can use the GetError() method to obtain more information about the 69 // client can use the GetError() method to obtain more information about the
143 // reason initialization failed. The prototype for the client callback is: 70 // reason initialization failed. The prototype for the client callback is:
144 // void Client::PipelineInitComplete(bool init_was_successful); 71 // void Client::PipelineInitComplete(bool init_was_successful);
145 // 72 //
146 // Note that clients must not call the Stop method from within the 73 // Note that clients must not call the Stop method from within the
147 // |start_callback|. Other methods, including SetPlaybackRate(), Seek(), and 74 // |start_callback|. Other methods, including SetPlaybackRate(), Seek(), and
148 // SetVolume() may be called. The client will be called on a thread owned by 75 // SetVolume() may be called. The client will be called on a thread owned by
149 // the pipeline class, not on the thread that originally called the Start() 76 // the pipeline class, not on the thread that originally called the Start()
150 // method. 77 // method.
151 virtual bool Start(FilterFactory* filter_factory, 78 virtual bool Start(FilterFactory* filter_factory,
152 const std::string& uri, 79 const std::string& url,
153 PipelineCallback* start_callback) = 0; 80 PipelineCallback* start_callback) = 0;
154 81
155 // Stops the pipeline and resets to an uninitialized state. This method 82 // Stops the pipeline and resets to an uninitialized state. This method
156 // will block the calling thread until the pipeline has been completely 83 // will block the calling thread until the pipeline has been completely
157 // torn down and reset to an uninitialized state. After calling Stop, it 84 // torn down and reset to an uninitialized state. After calling Stop(), it
158 // is acceptable to call Start again since Stop leaves the pipeline 85 // is acceptable to call Start() again since Stop() leaves the pipeline
159 // in a state identical to a newly created pipeline. 86 // in a state identical to a newly created pipeline.
160 // Calling this method is not strictly required because the pipeline 87 //
161 // destructor will stop it pipeline if it has not been stopped already. 88 // Stop() must be called before destroying the pipeline.
89 //
90 // TODO(scherkus): it shouldn't be acceptable to call Start() again after you
91 // Stop() a pipeline -- it should be destroyed and replaced with a new
92 // instance.
162 virtual void Stop() = 0; 93 virtual void Stop() = 0;
163 94
164 // Attempt to adjust the playback rate. Setting a playback rate of 0.0f pauses
165 // all rendering of the media. A rate of 1.0f indicates a normal playback
166 // rate. Values for the playback rate must be greater than or equal to 0.0f.
167 // TODO(ralphl): What about maximum rate? Does HTML5 specify a max?
168 //
169 // This method must be called only after initialization has completed.
170 virtual void SetPlaybackRate(float playback_rate) = 0;
171
172 // Attempt to seek to the position specified by time. |seek_callback| will be 95 // Attempt to seek to the position specified by time. |seek_callback| will be
173 // executed when the all filters in the pipeline have processed the seek. 96 // executed when the all filters in the pipeline have processed the seek.
174 // The callback will return true if the seek was carried out, false otherwise 97 // The callback will return true if the seek was carried out, false otherwise
175 // (i.e., streaming media). 98 // (i.e., streaming media).
99 virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback) = 0;
100
101 // Returns the current initialization state of the pipeline. Note that this
102 // will be set to true prior to a executing |init_complete_callback| if
103 // initialization is successful.
104 virtual bool IsInitialized() const = 0;
105
106 // If the |major_mime_type| exists in the pipeline and is being rendered, this
107 // method will return true. Types are defined in media/base/media_foramt.h.
108 // For example, to determine if a pipeline contains video:
109 // bool has_video = pipeline->IsRendered(mime_type::kMajorTypeVideo);
110 virtual bool IsRendered(const std::string& major_mime_type) const = 0;
111
112 // Gets the current playback rate of the pipeline. When the pipeline is
113 // started, the playback rate will be 0.0f. A rate of 1.0f indicates
114 // that the pipeline is rendering the media at the standard rate. Valid
115 // values for playback rate are >= 0.0f.
116 virtual float GetPlaybackRate() const = 0;
117
118 // Attempt to adjust the playback rate. Setting a playback rate of 0.0f pauses
119 // all rendering of the media. A rate of 1.0f indicates a normal playback
120 // rate. Values for the playback rate must be greater than or equal to 0.0f.
176 // 121 //
177 // This method must be called only after initialization has completed. 122 // TODO(scherkus): What about maximum rate? Does HTML5 specify a max?
178 virtual void Seek(base::TimeDelta time, 123 virtual void SetPlaybackRate(float playback_rate) = 0;
179 PipelineCallback* seek_callback) = 0; 124
125 // Gets the current volume setting being used by the audio renderer. When
126 // the pipeline is started, this value will be 1.0f. Valid values range
127 // from 0.0f to 1.0f.
128 virtual float GetVolume() const = 0;
180 129
181 // Attempt to set the volume of the audio renderer. Valid values for volume 130 // Attempt to set the volume of the audio renderer. Valid values for volume
182 // range from 0.0f (muted) to 1.0f (full volume). This value affects all 131 // range from 0.0f (muted) to 1.0f (full volume). This value affects all
183 // channels proportionately for multi-channel audio streams. 132 // channels proportionately for multi-channel audio streams.
184 //
185 // This method must be called only after initialization has completed.
186 virtual void SetVolume(float volume) = 0; 133 virtual void SetVolume(float volume) = 0;
187 134
135 // Gets the current pipeline time. For a pipeline "time" progresses from 0 to
136 // the end of the media.
137 virtual base::TimeDelta GetTime() const = 0;
138
139 // Get the approximate amount of playable data buffered so far in micro-
140 // seconds.
141 virtual base::TimeDelta GetBufferedTime() const = 0;
142
143 // Get the duration of the media in microseconds. If the duration has not
144 // been determined yet, then returns 0.
145 virtual base::TimeDelta GetDuration() const = 0;
146
147 // Get the total number of bytes that are buffered on the client and ready to
148 // be played.
149 virtual int64 GetBufferedBytes() const = 0;
150
151 // Get the total size of the media file. If the size has not yet been
152 // determined or can not be determined, this value is 0.
153 virtual int64 GetTotalBytes() const = 0;
154
155 // Gets the size of the video output in pixel units. If there is no video
156 // or the video has not been rendered yet, the width and height will be 0.
157 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const = 0;
158
159 // Gets the current error status for the pipeline. If the pipeline is
160 // operating correctly, this will return OK.
161 virtual PipelineError GetError() const = 0;
162
188 protected: 163 protected:
189 virtual ~Pipeline() {} 164 virtual ~Pipeline() {}
190 }; 165 };
191 166
192 } // namespace media 167 } // namespace media
193 168
194 #endif // MEDIA_BASE_PIPELINE_H_ 169 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW
« no previous file with comments | « media/base/mock_filter_host.h ('k') | media/base/pipeline_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698