OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // FilterHost describes an interface for individual filters to access and | 5 // FilterHost describes an interface for individual filters to access and |
6 // modify global playback information. Every filter is given a filter host | 6 // modify global playback information. Every filter is given a filter host |
7 // reference as part of initialization. | 7 // reference as part of initialization. |
8 // | 8 // |
9 // This interface is intentionally verbose to cover the needs for the different | 9 // This interface is intentionally verbose to cover the needs for the different |
10 // types of filters (see media/base/filters.h for filter definitionss). Filters | 10 // types of filters (see media/base/filters.h for filter definitionss). Filters |
11 // typically use parts of the interface that are relevant to their function. | 11 // typically use parts of the interface that are relevant to their function. |
12 // For example, an audio renderer filter typically calls SetTime as it feeds | 12 // For example, an audio renderer filter typically calls SetTime as it feeds |
13 // data to the audio hardware. A video renderer filter typically calls GetTime | 13 // data to the audio hardware. A video renderer filter typically calls GetTime |
14 // to synchronize video with audio. An audio and video decoder would typically | 14 // to synchronize video with audio. An audio and video decoder would typically |
15 // have no need to call either SetTime or GetTime. | 15 // have no need to call either SetTime or GetTime. |
16 // | 16 // |
17 // Filter state is managed by the FilterHost implementor, with the filter | |
18 // receiving notifications from the host when a state transition is starting | |
19 // and the filter notifying the host when the filter has completed the | |
20 // transition. The state transition is broken into two steps since some state | |
21 // transitions may be blocking or long running. The host provides PostTask to | |
22 // help filters schedule such tasks. | |
23 // | |
24 // Example of a pause state transition: | |
25 // During Initialization: | |
26 // - Audio renderer registers OnPause with SetPauseCallback | |
27 // | |
28 // During Playback: | |
29 // - User hits pause button, triggering a pause state transition | |
30 // - Filter host executes the pause callback | |
31 // - Inside OnPause, the audio renderer schedules DoPause with PostTask | |
32 // and immediately returns | |
33 // - Filter host asynchronously executes DoPause | |
34 // - Inside DoPause, the audio renderer does its blocking operations and | |
35 // when complete calls PauseComplete | |
36 // | |
37 // The reasoning behind providing PostTask is to discourage filters from | 17 // The reasoning behind providing PostTask is to discourage filters from |
38 // implementing their own threading. The overall design is that many filters | 18 // implementing their own threading. The overall design is that many filters |
39 // can share few threads and that notifications return quickly by scheduling | 19 // can share few threads and that notifications return quickly by scheduling |
40 // processing with PostTask. | 20 // processing with PostTask. |
41 | 21 |
42 #ifndef MEDIA_BASE_FILTER_HOST_H_ | 22 #ifndef MEDIA_BASE_FILTER_HOST_H_ |
43 #define MEDIA_BASE_FILTER_HOST_H_ | 23 #define MEDIA_BASE_FILTER_HOST_H_ |
44 | 24 |
45 #include "base/task.h" | 25 #include "base/task.h" |
| 26 #include "media/base/pipeline.h" |
46 | 27 |
47 namespace media { | 28 namespace media { |
48 | 29 |
49 class FilterHost { | 30 class FilterHost { |
50 public: | 31 public: |
51 // Returns the global time. | 32 // The PipelineStatus class allows read-only access to the pipeline state. |
52 virtual int64 GetTime() const = 0; | 33 // This is the same object that is used by the pipeline client to examine |
| 34 // the state of the running pipeline. The lifetime of the PipelineStatus |
| 35 // interface is the same as the lifetime of the FilterHost interface, so |
| 36 // it is acceptable for filters to use the returned pointer until their |
| 37 // Stop method has been called. |
| 38 virtual const PipelineStatus* GetPipelineStatus() const = 0; |
53 | 39 |
54 // Updates the global time. | 40 // Registers a callback to receive global clock update notifications. The |
| 41 // callback will be called repeatedly and filters do not need to re-register |
| 42 // after each invocation of the callback. To remove the callback, filters |
| 43 // may call this method passing NULL for the callback argument. |
| 44 // |
| 45 // Callback arguments: |
| 46 // int64 the new pipeline time, in microseconds |
| 47 virtual void SetTimeUpdateCallback(Callback1<int64>::Type* callback) = 0; |
| 48 |
| 49 // Filters must call this method to indicate that their initialization is |
| 50 // complete. They may call this from within their Initialize() method or may |
| 51 // choose call it after processing some data. |
| 52 virtual void InitializationComplete() = 0; |
| 53 |
| 54 // Posts a task to be executed asynchronously on the pipeline's thread. |
| 55 virtual void PostTask(Task* task) = 0; |
| 56 |
| 57 // Stops execution of the pipeline due to a fatal error. |
| 58 virtual void Error(PipelineError error) = 0; |
| 59 |
| 60 // Sets the current time. Any filters that have registered a callback through |
| 61 // the SetTimeUpdateCallback method will be notified of the change. |
55 virtual void SetTime(int64 time) = 0; | 62 virtual void SetTime(int64 time) = 0; |
56 | 63 |
57 // Returns the global duration. | 64 // Get the duration of the media in microseconds. If the duration has not |
58 virtual int64 GetDuration() const = 0; | 65 // been determined yet, then returns 0. |
59 | |
60 // Updates the global media duration. | |
61 virtual void SetDuration(int64 duration) = 0; | 66 virtual void SetDuration(int64 duration) = 0; |
62 | 67 |
63 // Posts a task to be executed asynchronously. | 68 // Set the approximate amount of playable data buffered so far in micro- |
64 virtual void PostTask(Task* task) = 0; | 69 // seconds. |
| 70 virtual void SetBufferedTime(int64 buffered_time) = 0; |
65 | 71 |
66 // Notifies the host that the filter has transitioned into the playing state. | 72 // Set the total size of the media file. |
67 virtual bool PlayComplete() = 0; | 73 virtual void SetTotalBytes(int64 total_bytes) = 0; |
68 | 74 |
69 // Notifies the host that the filter has transitioned into the paused state. | 75 // Sets the total number of bytes that are buffered on the client and ready to |
70 virtual bool PauseComplete() = 0; | 76 // be played. |
| 77 virtual void SetBufferedBytes(int64 buffered_bytes) = 0; |
71 | 78 |
72 // Notifies the host that the filter has transitioned into the seek state. | 79 // Sets the size of the video output in pixel units. |
73 virtual bool SeekComplete() = 0; | 80 virtual void SetVideoSize(size_t width, size_t height) = 0; |
74 | |
75 // Notifies the host that the filter has transitioned into the shutdown state. | |
76 virtual bool ShutdownComplete() = 0; | |
77 | |
78 // Notifies the host that an error has occurred and that further processing | |
79 // cannot continue. |error| identifies the type of error that occurred. | |
80 // | |
81 // TODO(scherkus): Add error constants as we start implementing filters. | |
82 virtual void Error(int error) = 0; | |
83 | |
84 // Notifies the host that the end of the stream has been reached. | |
85 virtual void EndOfStream() = 0; | |
86 | |
87 // Registers a callback to handle the play state transition. The filter must | |
88 // call PlayComplete at some point in the future to signal completion of | |
89 // the transition. | |
90 // | |
91 // Callback arguments: | |
92 // None | |
93 virtual void SetPlayCallback(Callback0::Type* callback) = 0; | |
94 | |
95 // Registers a callback to handle the pause state transition. The filter must | |
96 // call PauseComplete at some point in the future to signal completion of | |
97 // the transition. | |
98 // | |
99 // Callback arguments: | |
100 // bool true if the pause was triggered by end of stream | |
101 virtual void SetPauseCallback(Callback1<bool>::Type* callback) = 0; | |
102 | |
103 // Registers a callback to handle the seek state transition. The filter must | |
104 // call SeekComplete at some point in the future to signal completion of | |
105 // the transition. | |
106 // | |
107 // Callback arguments: | |
108 // int64 the timestamp position to seek to, in microseconds | |
109 virtual void SetSeekCallback(Callback1<int64>::Type* callback) = 0; | |
110 | |
111 // Registers a callback to handle the shutdown state transition. The filter | |
112 // must call ShutdownComplete at some point in the future to signal completion | |
113 // of the transition. | |
114 // | |
115 // Callback arguments: | |
116 // None | |
117 virtual void SetShutdownCallback(Callback0::Type* callback) = 0; | |
118 | |
119 // Registers a callback to receive global clock update notifications. | |
120 // | |
121 // Callback arguments: | |
122 // int64 the new global time, in microseconds | |
123 virtual void SetClockCallback(Callback1<int64>::Type* callback) = 0; | |
124 | |
125 // Registers a callback to receive global error notifications. | |
126 // | |
127 // Callback arguments: | |
128 // int the error code reported. | |
129 virtual void SetErrorCallback(Callback1<int>::Type* callback) = 0; | |
130 | 81 |
131 protected: | 82 protected: |
132 virtual ~FilterHost() {} | 83 virtual ~FilterHost() = 0; |
133 }; | 84 }; |
134 | 85 |
135 } // namespace media | 86 } // namespace media |
136 | 87 |
137 #endif // MEDIA_BASE_FILTER_HOST_H_ | 88 #endif // MEDIA_BASE_FILTER_HOST_H_ |
OLD | NEW |