OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Filters are connected in a strongly typed manner, with downstream filters | 5 // Filters are connected in a strongly typed manner, with downstream filters |
6 // always reading data from upstream filters. Upstream filters have no clue | 6 // always reading data from upstream filters. Upstream filters have no clue |
7 // who is actually reading from them, and return the results via callbacks. | 7 // who is actually reading from them, and return the results via callbacks. |
8 // | 8 // |
9 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer | 9 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer |
10 // DataSource <- Demuxer < | 10 // DataSource <- Demuxer < |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include <limits> | 26 #include <limits> |
27 #include <string> | 27 #include <string> |
28 | 28 |
29 #include "base/callback.h" | 29 #include "base/callback.h" |
30 #include "base/ref_counted.h" | 30 #include "base/ref_counted.h" |
31 #include "base/time.h" | 31 #include "base/time.h" |
32 #include "base/scoped_ptr.h" | 32 #include "base/scoped_ptr.h" |
33 #include "media/base/media_format.h" | 33 #include "media/base/media_format.h" |
34 #include "media/base/video_frame.h" | 34 #include "media/base/video_frame.h" |
35 | 35 |
36 class MessageLoop; | |
37 | |
38 namespace media { | 36 namespace media { |
39 | 37 |
40 class Buffer; | 38 class Buffer; |
41 class Decoder; | 39 class Decoder; |
42 class DemuxerStream; | 40 class DemuxerStream; |
43 class Filter; | 41 class Filter; |
44 class FilterHost; | 42 class FilterHost; |
45 | 43 |
46 // Used for completing asynchronous methods. | 44 // Used for completing asynchronous methods. |
47 typedef Callback0::Type FilterCallback; | 45 typedef Callback0::Type FilterCallback; |
48 | 46 |
49 class Filter : public base::RefCountedThreadSafe<Filter> { | 47 class Filter : public base::RefCountedThreadSafe<Filter> { |
50 public: | 48 public: |
51 Filter(); | 49 Filter(); |
52 | 50 |
53 // Return the major mime type for this filter. | 51 // Return the major mime type for this filter. |
54 virtual const char* major_mime_type() const; | 52 virtual const char* major_mime_type() const; |
55 | 53 |
56 // Sets the private member |host_|. This is the first method called by | 54 // Sets the private member |host_|. This is the first method called by |
57 // the FilterHost after a filter is created. The host holds a strong | 55 // the FilterHost after a filter is created. The host holds a strong |
58 // reference to the filter. The reference held by the host is guaranteed | 56 // reference to the filter. The reference held by the host is guaranteed |
59 // to be released before the host object is destroyed by the pipeline. | 57 // to be released before the host object is destroyed by the pipeline. |
60 virtual void set_host(FilterHost* host); | 58 virtual void set_host(FilterHost* host); |
61 | 59 |
62 virtual FilterHost* host(); | 60 virtual FilterHost* host(); |
63 | 61 |
64 // Indicates whether this filter requires a message loop to operate. | |
65 virtual bool requires_message_loop() const; | |
66 | |
67 // The name to associate with this filter's message loop. | |
68 virtual const char* message_loop_name() const; | |
69 | |
70 // Sets the private member |message_loop_|, which is used by filters for | |
71 // processing asynchronous tasks and maintaining synchronized access to | |
72 // internal data members. The message loop should be running and exceed the | |
73 // lifetime of the filter. | |
74 virtual void set_message_loop(MessageLoop* message_loop); | |
75 | |
76 virtual MessageLoop* message_loop(); | |
77 | |
78 // The pipeline has resumed playback. Filters can continue requesting reads. | 62 // The pipeline has resumed playback. Filters can continue requesting reads. |
79 // Filters may implement this method if they need to respond to this call. | 63 // Filters may implement this method if they need to respond to this call. |
80 // TODO(boliu): Check that callback is not NULL in subclasses. | 64 // TODO(boliu): Check that callback is not NULL in subclasses. |
81 virtual void Play(FilterCallback* callback); | 65 virtual void Play(FilterCallback* callback); |
82 | 66 |
83 // The pipeline has paused playback. Filters should stop buffer exchange. | 67 // The pipeline has paused playback. Filters should stop buffer exchange. |
84 // Filters may implement this method if they need to respond to this call. | 68 // Filters may implement this method if they need to respond to this call. |
85 // TODO(boliu): Check that callback is not NULL in subclasses. | 69 // TODO(boliu): Check that callback is not NULL in subclasses. |
86 virtual void Pause(FilterCallback* callback); | 70 virtual void Pause(FilterCallback* callback); |
87 | 71 |
(...skipping 19 matching lines...) Expand all Loading... |
107 // is disabled. Filters can ignore the notification if they do not | 91 // is disabled. Filters can ignore the notification if they do not |
108 // need to react to this event. | 92 // need to react to this event. |
109 virtual void OnAudioRendererDisabled(); | 93 virtual void OnAudioRendererDisabled(); |
110 | 94 |
111 protected: | 95 protected: |
112 // Only allow scoped_refptr<> to delete filters. | 96 // Only allow scoped_refptr<> to delete filters. |
113 friend class base::RefCountedThreadSafe<Filter>; | 97 friend class base::RefCountedThreadSafe<Filter>; |
114 virtual ~Filter(); | 98 virtual ~Filter(); |
115 | 99 |
116 FilterHost* host() const { return host_; } | 100 FilterHost* host() const { return host_; } |
117 MessageLoop* message_loop() const { return message_loop_; } | |
118 | 101 |
119 private: | 102 private: |
120 FilterHost* host_; | 103 FilterHost* host_; |
121 MessageLoop* message_loop_; | |
122 | 104 |
123 DISALLOW_COPY_AND_ASSIGN(Filter); | 105 DISALLOW_COPY_AND_ASSIGN(Filter); |
124 }; | 106 }; |
125 | 107 |
126 class DataSource : public Filter { | 108 class DataSource : public Filter { |
127 public: | 109 public: |
128 typedef Callback1<size_t>::Type ReadCallback; | 110 typedef Callback1<size_t>::Type ReadCallback; |
129 static const size_t kReadError = static_cast<size_t>(-1); | 111 static const size_t kReadError = static_cast<size_t>(-1); |
130 | 112 |
131 virtual bool IsUrlSupported(const std::string& url); | 113 virtual bool IsUrlSupported(const std::string& url); |
(...skipping 15 matching lines...) Expand all Loading... |
147 virtual bool GetSize(int64* size_out) = 0; | 129 virtual bool GetSize(int64* size_out) = 0; |
148 | 130 |
149 // Returns true if we are performing streaming. In this case seeking is | 131 // Returns true if we are performing streaming. In this case seeking is |
150 // not possible. | 132 // not possible. |
151 virtual bool IsStreaming() = 0; | 133 virtual bool IsStreaming() = 0; |
152 }; | 134 }; |
153 | 135 |
154 | 136 |
155 class Demuxer : public Filter { | 137 class Demuxer : public Filter { |
156 public: | 138 public: |
157 virtual bool requires_message_loop() const; | |
158 virtual const char* message_loop_name() const; | |
159 | |
160 // Initialize a Demuxer with the given DataSource, executing the callback upon | 139 // Initialize a Demuxer with the given DataSource, executing the callback upon |
161 // completion. | 140 // completion. |
162 virtual void Initialize(DataSource* data_source, | 141 virtual void Initialize(DataSource* data_source, |
163 FilterCallback* callback) = 0; | 142 FilterCallback* callback) = 0; |
164 | 143 |
165 // Returns the number of streams available | 144 // Returns the number of streams available |
166 virtual size_t GetNumberOfStreams() = 0; | 145 virtual size_t GetNumberOfStreams() = 0; |
167 | 146 |
168 // Returns the stream for the given index, NULL otherwise | 147 // Returns the stream for the given index, NULL otherwise |
169 virtual scoped_refptr<DemuxerStream> GetStream(int stream_id) = 0; | 148 virtual scoped_refptr<DemuxerStream> GetStream(int stream_id) = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 virtual void* QueryInterface(const char* interface_id); | 183 virtual void* QueryInterface(const char* interface_id); |
205 | 184 |
206 friend class base::RefCountedThreadSafe<DemuxerStream>; | 185 friend class base::RefCountedThreadSafe<DemuxerStream>; |
207 virtual ~DemuxerStream(); | 186 virtual ~DemuxerStream(); |
208 }; | 187 }; |
209 | 188 |
210 | 189 |
211 class VideoDecoder : public Filter { | 190 class VideoDecoder : public Filter { |
212 public: | 191 public: |
213 virtual const char* major_mime_type() const; | 192 virtual const char* major_mime_type() const; |
214 virtual bool requires_message_loop() const; | |
215 virtual const char* message_loop_name() const; | |
216 | |
217 | 193 |
218 // Initialize a VideoDecoder with the given DemuxerStream, executing the | 194 // Initialize a VideoDecoder with the given DemuxerStream, executing the |
219 // callback upon completion. | 195 // callback upon completion. |
220 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 196 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
221 | 197 |
222 // |set_fill_buffer_done_callback| install permanent callback from downstream | 198 // |set_fill_buffer_done_callback| install permanent callback from downstream |
223 // filter (i.e. Renderer). The callback is used to deliver video frames at | 199 // filter (i.e. Renderer). The callback is used to deliver video frames at |
224 // runtime to downstream filter | 200 // runtime to downstream filter |
225 typedef Callback1<scoped_refptr<VideoFrame> >::Type ConsumeVideoFrameCallback; | 201 typedef Callback1<scoped_refptr<VideoFrame> >::Type ConsumeVideoFrameCallback; |
226 void set_consume_video_frame_callback(ConsumeVideoFrameCallback* callback) { | 202 void set_consume_video_frame_callback(ConsumeVideoFrameCallback* callback) { |
(...skipping 22 matching lines...) Expand all Loading... |
249 virtual ~VideoDecoder(); | 225 virtual ~VideoDecoder(); |
250 | 226 |
251 private: | 227 private: |
252 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; | 228 scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; |
253 }; | 229 }; |
254 | 230 |
255 | 231 |
256 class AudioDecoder : public Filter { | 232 class AudioDecoder : public Filter { |
257 public: | 233 public: |
258 virtual const char* major_mime_type() const; | 234 virtual const char* major_mime_type() const; |
259 virtual bool requires_message_loop() const; | |
260 virtual const char* message_loop_name() const; | |
261 | 235 |
262 // Initialize a AudioDecoder with the given DemuxerStream, executing the | 236 // Initialize a AudioDecoder with the given DemuxerStream, executing the |
263 // callback upon completion. | 237 // callback upon completion. |
264 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; | 238 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback) = 0; |
265 | 239 |
266 // |set_fill_buffer_done_callback| install permanent callback from downstream | 240 // |set_fill_buffer_done_callback| install permanent callback from downstream |
267 // filter (i.e. Renderer). The callback is used to deliver buffers at | 241 // filter (i.e. Renderer). The callback is used to deliver buffers at |
268 // runtime to downstream filter. | 242 // runtime to downstream filter. |
269 typedef Callback1<scoped_refptr<Buffer> >::Type ConsumeAudioSamplesCallback; | 243 typedef Callback1<scoped_refptr<Buffer> >::Type ConsumeAudioSamplesCallback; |
270 void set_consume_audio_samples_callback( | 244 void set_consume_audio_samples_callback( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // buffer. | 292 // buffer. |
319 virtual bool HasEnded() = 0; | 293 virtual bool HasEnded() = 0; |
320 | 294 |
321 // Sets the output volume. | 295 // Sets the output volume. |
322 virtual void SetVolume(float volume) = 0; | 296 virtual void SetVolume(float volume) = 0; |
323 }; | 297 }; |
324 | 298 |
325 } // namespace media | 299 } // namespace media |
326 | 300 |
327 #endif // MEDIA_BASE_FILTERS_H_ | 301 #endif // MEDIA_BASE_FILTERS_H_ |
OLD | NEW |