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

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

Issue 18380: This is the frozen interface definition for the media pipeline, filters, and ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 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 // 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 //
9 // Playback controls (play, pause, seek) are asynchronous and clients are
10 // notified via callbacks.
11 8
12 #ifndef MEDIA_BASE_PIPELINE_H_ 9 #ifndef MEDIA_BASE_PIPELINE_H_
13 #define MEDIA_BASE_PIPELINE_H_ 10 #define MEDIA_BASE_PIPELINE_H_
14 11
12 #include <string>
13
15 #include "base/task.h" 14 #include "base/task.h"
15 #include "media/base/factory.h"
16 16
17 namespace media { 17 namespace media {
18 18
19 class FilterFactoryInterface; 19 // Error definitions for pipeline.
20 20 enum PipelineError {
21 enum PipelineState { 21 PIPELINE_OK,
22 PS_UNINITIALIZED, 22 PIPELINE_ERROR_NETWORK,
23 PS_PLAY, 23 PIPELINE_ERROR_DECODE,
24 PS_PAUSE, 24 PIPELINE_ERROR_ABORT,
25 PS_SEEK, 25 PIPELINE_ERROR_INITIALIZATION_FAILED,
26 PS_SHUTDOWN 26 PIPELINE_STOPPING
27 }; 27 };
28 28
29 class Pipeline : public base::RefCountedThreadSafe<Pipeline> { 29 // Base class for Pipeline class which allows for read-only access to members.
30 // Filters are allowed to access the PipelineStatus interface but are not given
31 // access to the client Pipeline methods.
32 class PipelineStatus {
33 public:
34 // Returns the current initialization state of the pipeline. Clients can
35 // examine this to determine if it is acceptable to call SetRate/SetVolume/
36 // Seek after calling Start on the pipeline. Note that this will be
37 // set to true prior to a call to the client's |init_complete_callback| if
38 // initialization is successful.
39 virtual bool IsInitialized() const = 0;
40
41 // Get the duration of the media in microseconds. If the duration has not
42 // been determined yet, then returns 0.
43 virtual int64 GetDuration() const = 0;
44
45 // Get the approximate amount of playable data buffered so far in micro-
46 // seconds.
47 virtual int64 GetBufferedTime() const = 0;
48
49 // Get the total size of the media file. If the size has not yet been
50 // determined or can not be determined, this value is 0.
51 virtual int64 GetTotalBytes() const = 0;
52
53 // Get the total number of bytes that are buffered on the client and ready to
54 // be played.
55 virtual int64 GetBufferedBytes() const = 0;
56
57 // Gets the size of the video output in pixel units. If there is no video
58 // or the video has not been rendered yet, the width and height will be 0.
59 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const = 0;
60
61 // Gets the current volume setting being used by the audio renderer. When
62 // the pipeline is started, this value will be 1.0f. Valid values range
63 // from 0.0f to 1.0f.
64 virtual float GetVolume() const = 0;
65
66 // Gets the current playback rate of the pipeline. When the pipeline is
67 // started, the playback rate will be 0.0f. A rate of 1.0f indicates
68 // that the pipeline is rendering the media at the standard rate. Valid
69 // values for playback rate are >= 0.0f.
70 virtual float GetPlaybackRate() const = 0;
71
72 // Gets the current pipeline time in microseconds. For a pipeline "time"
73 // progresses from 0 to the end of the media.
74 virtual int64 GetTime() const = 0;
75
76 // Gets the current error status for the pipeline. If the pipeline is
77 // operating correctly, this will return OK.
78 virtual PipelineError GetError() const = 0;
79
80 protected:
81 virtual ~PipelineStatus() = 0;
82 };
83
84
85 class Pipeline : public PipelineStatus {
30 public: 86 public:
31 // Build a pipeline to render the given URI using the given filter factory to 87 // Build a pipeline to render the given URI using the given filter factory to
32 // construct a filter chain. Returns true if successful, false otherwise 88 // construct a filter chain. Returns true if successful, false otherwise
33 // (i.e., pipeline already initialized). 89 // (i.e., pipeline already started). Note that a return value of true
90 // only indicates that the initialization process has started successfully.
91 // Pipeline initializaion is an inherently asynchronous process. Clients
92 // should not call SetPlaybackRate, Seek, or SetVolume until initialization
93 // is complete. Clients can either poll the IsInitialized() method (which is
94 // discouraged) or use the init_complete_callback as described below.
34 // 95 //
35 // This method is asynchronous and will execute a state change callback when 96 // This method is asynchronous and can execute a callback when completed.
36 // completed. 97 // If the caller provides an init_complete_callback, it will be
37 virtual bool Initialize(FilterFactoryInterface* filter_factory, 98 // called when the pipeline initiailization completes. If successful, the
38 const std::string& uri) = 0; 99 // callback's bool parameter will be true. If the callback is called with
100 // false, then the client can use the GetError method to obtain more
101 // information about the reason initialization failed. The prototype for
102 // the client callback is:
103 // void Client::PipelineInitComplete(bool init_was_successful);
104 //
105 // Note that clients must not call the Stop method from within the
106 // init_complete_callback. Other methods, including SetPlaybackRate,
107 // Seek, and SetVolume may be called. The client will be called on a
108 // thread owned by the pipeline class, not on the thread that originally
109 // called the Start method.
110 virtual bool Start(FilterFactory* filter_factory,
111 const std::string& uri,
112 Callback1<bool>::Type* init_complete_callback) = 0;
39 113
40 // Attempt to play the media. Returns true if successful, false otherwise 114 // Stops the pipeline and resets to an uninitialized state. This method
41 // (i.e., pipeline is unititalized). 115 // will block the calling thread until the pipeline has been completely
116 // torn down and reset to an uninitialized state. After calling Stop, it
117 // is acceptable to call Start again since Stop leaves the pipeline
118 // in a state identical to a newly created pipeline.
119 virtual void Stop() = 0;
120
121 // Attempt to adjust the playback rate. Returns true if successful,
122 // false otherwise. Setting a playback rate of 0.0f pauses all rendering
123 // of the media. A rate of 1.0f indicates a normal playback rate. Values
124 // for the playback rate must be greater than or equal to 0.0f.
125 // TODO(ralphl) What about maximum rate? Does HTML5 specify a max?
42 // 126 //
43 // This method is asynchronous and will execute a state change callback when 127 // This method must be called only after initialization has completed.
44 // completed. 128 virtual bool SetPlaybackRate(float playback_rate) = 0;
45 virtual bool Play() = 0;
46
47 // Attempt to pause the media. Returns true if successful, false otherwise
48 // (i.e., pipeline is unititalized). Pause() is not a toggle and should not
49 // resume playback if already paused.
50 //
51 // This method is asynchronous and will execute a state change callback when
52 // completed.
53 virtual bool Pause() = 0;
54 129
55 // Attempt to seek to the position in microseconds. Returns true if 130 // Attempt to seek to the position in microseconds. Returns true if
56 // successful, false otherwise. Playback is paused after the seek completes. 131 // successful, false otherwise. Playback is paused after the seek completes.
57 // 132 //
58 // This method is asynchronous and will execute a state change callback when 133 // This method must be called only after initialization has completed.
59 // completed. 134 virtual bool Seek(int64 time) = 0;
60 virtual bool Seek(int64 seek_position) = 0;
61 135
62 // Shutdown the pipeline and destroy the filter chain. 136 // Attempt to set the volume of the audio renderer. Valid values for volume
63 virtual void Shutdown() = 0; 137 // range from 0.0f (muted) to 1.0f (full volume). This value affects all
64 138 // channels proportionately for multi-channel audio streams.
65 // Returns the current playback position in microseconds. 139 //
66 virtual int64 GetTime() const = 0; 140 // This method must be called only after initialization has completed.
67 141 virtual bool SetVolume(float volume) = 0;
68 // Returns the media duration in microseconds. Returns zero if the duration
69 // is not known (i.e., streaming media).
70 virtual int64 GetDuration() const = 0;
71
72 // Set a callback to receive state change notifications. This callback is
73 // executed only after the state transition has been successfully carried out.
74 // For example, calling Play() will only execute a callback with PS_PLAY
75 // some time in the future.
76 virtual void SetStateChangedCallback(
77 Callback1<PipelineState>::Type* callback) = 0;
78
79 // Set a callback to receive time change notifications.
80 virtual void SetTimeChangedCallback(Callback1<int64>::Type* callback) = 0;
81
82 protected:
83 friend class base::RefCountedThreadSafe<Pipeline>;
84 virtual ~Pipeline() {}
85 }; 142 };
86 143
87 } // namespace media 144 } // namespace media
88 145
89 #endif // MEDIA_BASE_PIPELINE_H_ 146 #endif // MEDIA_BASE_PIPELINE_H_
OLDNEW
« media/base/filters.h ('K') | « media/base/filters.h ('k') | media/base/pipeline_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698