OLD | NEW |
---|---|
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 // 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 OnAssignment | 7 // who is actually reading from them, and return the results via OnAssignment |
8 // using the AssignableInterface<SomeBufferType> interface: | 8 // using the AssignableInterface<SomeBufferType> interface: |
9 // | 9 // |
10 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer | 10 // DemuxerStream(Video) <- VideoDecoder <- VideoRenderer |
11 // DataSource <- Demuxer < | 11 // DataSource <- Demuxer < |
12 // DemuxerStream(Audio) <- AudioDecoder <- AudioRenderer | 12 // DemuxerStream(Audio) <- AudioDecoder <- AudioRenderer |
13 // | 13 // |
14 // Upstream -------------------------------------------------------> Downstream | 14 // Upstream -------------------------------------------------------> Downstream |
15 // <- Reads flow this way | 15 // <- Reads flow this way |
16 // Buffer assignments flow this way -> | 16 // Buffer assignments flow this way -> |
17 // | 17 // |
18 // Every filter maintains a reference to the scheduler, who maintains data | 18 // Every filter maintains a reference to the scheduler, who maintains data |
19 // shared between filters (i.e., reference clock value, playback state). The | 19 // shared between filters (i.e., reference clock value, playback state). The |
20 // scheduler is also responsible for scheduling filter tasks (i.e., a read on | 20 // scheduler is also responsible for scheduling filter tasks (i.e., a read on |
21 // a VideoDecoder would result in scheduling a Decode task). Filters can also | 21 // a VideoDecoder would result in scheduling a Decode task). Filters can also |
22 // use the scheduler to signal errors and shutdown playback. | 22 // use the scheduler to signal errors and shutdown playback. |
23 | 23 |
24 #ifndef MEDIA_BASE_FILTERS_H_ | 24 #ifndef MEDIA_BASE_FILTERS_H_ |
25 #define MEDIA_BASE_FILTERS_H_ | 25 #define MEDIA_BASE_FILTERS_H_ |
26 | 26 |
27 #include <limits> | 27 #include <limits> |
28 #include <string> | 28 #include <string> |
29 | |
30 #include "base/logging.h" | |
29 #include "base/ref_counted.h" | 31 #include "base/ref_counted.h" |
30 | 32 |
31 namespace media { | 33 namespace media { |
32 | 34 |
33 template <class TBuffer> class Assignable; | 35 template <class TBuffer> class Assignable; |
34 class Buffer; | 36 class Buffer; |
35 class Decoder; | 37 class Decoder; |
36 class DemuxerStream; | 38 class DemuxerStream; |
37 class FilterHost; | 39 class FilterHost; |
38 class MediaFormat; | 40 class MediaFormat; |
39 class VideoFrame; | 41 class VideoFrame; |
40 class WritableBuffer; | 42 class WritableBuffer; |
41 | 43 |
42 // Identifies the type of filter implementation. Used in conjunction with some | 44 // Identifies the type of filter implementation. Used in conjunction with some |
43 // template wizardry to enforce strongly typed operations. More or less a | 45 // template wizardry to enforce strongly typed operations. More or less a |
44 // knock off of MSVC's __uuidof() operator. | 46 // knock off of MSVC's __uuidof() operator. |
45 enum FilterType { | 47 enum FilterType { |
46 FILTER_DATA_SOURCE, | 48 FILTER_DATA_SOURCE, |
47 FILTER_DEMUXER, | 49 FILTER_DEMUXER, |
48 FILTER_AUDIO_DECODER, | 50 FILTER_AUDIO_DECODER, |
49 FILTER_VIDEO_DECODER, | 51 FILTER_VIDEO_DECODER, |
50 FILTER_AUDIO_RENDERER, | 52 FILTER_AUDIO_RENDERER, |
51 FILTER_VIDEO_RENDERER, | 53 FILTER_VIDEO_RENDERER |
52 FILTER_MAX | |
53 }; | 54 }; |
54 | 55 |
55 | 56 |
56 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { | 57 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { |
57 public: | 58 public: |
58 virtual void SetFilterHost(FilterHost* filter_host) = 0; | 59 MediaFilter() : host_(NULL) {} |
60 | |
61 // Sets the protected member |host_|. This is the first method called by | |
62 // the FilterHost after a filter is created. The host holds a strong | |
63 // reference to the filter. The refernce held by the host is guaranteed | |
64 // to be released before the host object is destroyed by the pipeline. | |
65 virtual void SetFilterHost(FilterHost* host) { | |
66 DCHECK(NULL == host_); | |
67 DCHECK(NULL != host); | |
68 host_ = host; | |
69 } | |
70 | |
71 // The pipeline is being stopped either as a result of an error or because | |
72 // the client called Stop(). | |
73 virtual void Stop() = 0; | |
74 | |
75 // The pipeline playback rate has been changed. Filters may implement this | |
76 // method if they need to respond to this call. | |
77 virtual void SetPlaybackRate(float playback_rate) {} | |
78 | |
79 // The pipeline is being seeked to the specified time. Filters may implement | |
80 // this method if they need to respond to this call. | |
81 virtual void Seek(int64 time) {} | |
59 | 82 |
60 protected: | 83 protected: |
84 FilterHost* host_; | |
61 friend class base::RefCountedThreadSafe<MediaFilter>; | 85 friend class base::RefCountedThreadSafe<MediaFilter>; |
62 virtual ~MediaFilter() {} | 86 virtual ~MediaFilter() {} |
87 | |
88 private: | |
89 DISALLOW_COPY_AND_ASSIGN(MediaFilter); | |
63 }; | 90 }; |
64 | 91 |
65 | 92 |
66 class DataSource : public MediaFilter { | 93 class DataSource : public MediaFilter { |
67 public: | 94 public: |
68 static const FilterType kFilterType = FILTER_DATA_SOURCE; | 95 static const FilterType kFilterType = FILTER_DATA_SOURCE; |
69 static const size_t kReadError = static_cast<size_t>(-1); | 96 static const size_t kReadError = static_cast<size_t>(-1); |
70 | 97 |
71 // Initializes this filter, returns true if successful, false otherwise. | 98 // Initializes this filter, returns true if successful, false otherwise. |
72 virtual bool Initialize(const std::string& uri) = 0; | 99 virtual bool Initialize(const std::string& uri) = 0; |
(...skipping 15 matching lines...) Expand all Loading... | |
88 // Returns true and the file size, false if the file size could not be | 115 // Returns true and the file size, false if the file size could not be |
89 // retrieved. | 116 // retrieved. |
90 virtual bool GetSize(int64* size_out) = 0; | 117 virtual bool GetSize(int64* size_out) = 0; |
91 }; | 118 }; |
92 | 119 |
93 | 120 |
94 class Demuxer : public MediaFilter { | 121 class Demuxer : public MediaFilter { |
95 public: | 122 public: |
96 static const FilterType kFilterType = FILTER_DEMUXER; | 123 static const FilterType kFilterType = FILTER_DEMUXER; |
97 | 124 |
98 // Initializes this filter, returns true if successful, false otherwise. | 125 // Initializes this filter, returns true if successful, false otherwise. |
99 virtual bool Initialize(DataSource* data_source) = 0; | 126 virtual bool Initialize(DataSource* data_source) = 0; |
100 | 127 |
101 // Returns the number of streams available | 128 // Returns the number of streams available |
102 virtual size_t GetNumberOfStreams() = 0; | 129 virtual size_t GetNumberOfStreams() = 0; |
103 | 130 |
104 // Returns the stream for the given index, NULL otherwise | 131 // Returns the stream for the given index, NULL otherwise |
105 virtual DemuxerStream* GetStream(int stream_id) = 0; | 132 virtual DemuxerStream* GetStream(int stream_id) = 0; |
106 }; | 133 }; |
107 | 134 |
108 | 135 |
109 class DemuxerStream { | 136 class DemuxerStream { |
110 public: | 137 public: |
111 // Returns the MediaFormat for this filter. | 138 // Returns the MediaFormat for this filter. |
112 virtual const MediaFormat* GetMediaFormat() = 0; | 139 virtual const MediaFormat* GetMediaFormat() = 0; |
113 | 140 |
114 // Schedules a read and takes ownership of the given buffer. | 141 // Schedules a read and takes ownership of the given buffer. |
115 virtual void Read(Assignable<Buffer>* buffer) = 0; | 142 virtual void Read(Assignable<Buffer>* buffer) = 0; |
143 | |
144 virtual ~DemuxerStream() {} | |
scherkus (not reviewing)
2009/01/21 22:24:45
This should be protected pure virtual.
| |
116 }; | 145 }; |
117 | 146 |
118 | 147 |
119 class VideoDecoder : public MediaFilter { | 148 class VideoDecoder : public MediaFilter { |
120 public: | 149 public: |
121 static const FilterType kFilterType = FILTER_VIDEO_DECODER; | 150 static const FilterType kFilterType = FILTER_VIDEO_DECODER; |
122 | 151 |
123 // Initializes this filter, returns true if successful, false otherwise. | 152 // Initializes this filter, returns true if successful, false otherwise. |
124 virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; | 153 virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; |
125 | 154 |
(...skipping 28 matching lines...) Expand all Loading... | |
154 virtual bool Initialize(VideoDecoder* decoder) = 0; | 183 virtual bool Initialize(VideoDecoder* decoder) = 0; |
155 }; | 184 }; |
156 | 185 |
157 | 186 |
158 class AudioRenderer : public MediaFilter { | 187 class AudioRenderer : public MediaFilter { |
159 public: | 188 public: |
160 static const FilterType kFilterType = FILTER_AUDIO_RENDERER; | 189 static const FilterType kFilterType = FILTER_AUDIO_RENDERER; |
161 | 190 |
162 // Initializes this filter, returns true if successful, false otherwise. | 191 // Initializes this filter, returns true if successful, false otherwise. |
163 virtual bool Initialize(AudioDecoder* decoder) = 0; | 192 virtual bool Initialize(AudioDecoder* decoder) = 0; |
193 | |
194 // Sets the output volume. | |
195 virtual void SetVolume(float volume) = 0; | |
164 }; | 196 }; |
165 | 197 |
166 } // namespace media | 198 } // namespace media |
167 | 199 |
168 #endif // MEDIA_BASE_FILTERS_H_ | 200 #endif // MEDIA_BASE_FILTERS_H_ |
OLD | NEW |