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

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

Issue 3461019: FBTF: Move virtual methods to implementation files. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Win+chromeos+mac fixes Created 10 years, 3 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
OLDNEW
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 <
11 // DemuxerStream(Audio) <- AudioDecoder <- AudioRenderer 11 // DemuxerStream(Audio) <- AudioDecoder <- AudioRenderer
12 // 12 //
13 // Upstream -------------------------------------------------------> Downstream 13 // Upstream -------------------------------------------------------> Downstream
14 // <- Reads flow this way 14 // <- Reads flow this way
15 // Buffer assignments flow this way -> 15 // Buffer assignments flow this way ->
16 // 16 //
17 // Every filter maintains a reference to the scheduler, who maintains data 17 // Every filter maintains a reference to the scheduler, who maintains data
18 // shared between filters (i.e., reference clock value, playback state). The 18 // shared between filters (i.e., reference clock value, playback state). The
19 // scheduler is also responsible for scheduling filter tasks (i.e., a read on 19 // scheduler is also responsible for scheduling filter tasks (i.e., a read on
20 // a VideoDecoder would result in scheduling a Decode task). Filters can also 20 // a VideoDecoder would result in scheduling a Decode task). Filters can also
21 // use the scheduler to signal errors and shutdown playback. 21 // use the scheduler to signal errors and shutdown playback.
22 22
23 #ifndef MEDIA_BASE_FILTERS_H_ 23 #ifndef MEDIA_BASE_FILTERS_H_
24 #define MEDIA_BASE_FILTERS_H_ 24 #define MEDIA_BASE_FILTERS_H_
25 25
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/logging.h"
31 #include "base/message_loop.h"
32 #include "base/ref_counted.h" 30 #include "base/ref_counted.h"
33 #include "base/time.h" 31 #include "base/time.h"
34 #include "base/scoped_ptr.h" 32 #include "base/scoped_ptr.h"
35 #include "media/base/media_format.h" 33 #include "media/base/media_format.h"
36 #include "media/base/video_frame.h" 34 #include "media/base/video_frame.h"
37 35
36 class MessageLoop;
37
38 namespace media { 38 namespace media {
39 39
40 class Buffer; 40 class Buffer;
41 class Decoder; 41 class Decoder;
42 class DemuxerStream; 42 class DemuxerStream;
43 class FilterHost; 43 class FilterHost;
44 class WritableBuffer; 44 class WritableBuffer;
45 45
46 // Identifies the type of filter implementation. Used in conjunction with some 46 // Identifies the type of filter implementation. Used in conjunction with some
47 // template wizardry to enforce strongly typed operations. More or less a 47 // template wizardry to enforce strongly typed operations. More or less a
48 // knock off of MSVC's __uuidof() operator. 48 // knock off of MSVC's __uuidof() operator.
49 enum FilterType { 49 enum FilterType {
50 FILTER_DATA_SOURCE, 50 FILTER_DATA_SOURCE,
51 FILTER_DEMUXER, 51 FILTER_DEMUXER,
52 FILTER_AUDIO_DECODER, 52 FILTER_AUDIO_DECODER,
53 FILTER_VIDEO_DECODER, 53 FILTER_VIDEO_DECODER,
54 FILTER_AUDIO_RENDERER, 54 FILTER_AUDIO_RENDERER,
55 FILTER_VIDEO_RENDERER 55 FILTER_VIDEO_RENDERER
56 }; 56 };
57 57
58 // Used for completing asynchronous methods. 58 // Used for completing asynchronous methods.
59 typedef Callback0::Type FilterCallback; 59 typedef Callback0::Type FilterCallback;
60 60
61 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> { 61 class MediaFilter : public base::RefCountedThreadSafe<MediaFilter> {
62 public: 62 public:
63 MediaFilter() : host_(NULL), message_loop_(NULL) {} 63 MediaFilter();
64 64
65 // Sets the private member |host_|. This is the first method called by 65 // Sets the private member |host_|. This is the first method called by
66 // the FilterHost after a filter is created. The host holds a strong 66 // the FilterHost after a filter is created. The host holds a strong
67 // reference to the filter. The reference held by the host is guaranteed 67 // reference to the filter. The reference held by the host is guaranteed
68 // to be released before the host object is destroyed by the pipeline. 68 // to be released before the host object is destroyed by the pipeline.
69 virtual void set_host(FilterHost* host) { 69 virtual void set_host(FilterHost* host);
70 DCHECK(host);
71 DCHECK(!host_);
72 host_ = host;
73 }
74 70
75 virtual FilterHost* host() { 71 virtual FilterHost* host();
76 return host_;
77 }
78 72
79 // Sets the private member |message_loop_|, which is used by filters for 73 // Sets the private member |message_loop_|, which is used by filters for
80 // processing asynchronous tasks and maintaining synchronized access to 74 // processing asynchronous tasks and maintaining synchronized access to
81 // internal data members. The message loop should be running and exceed the 75 // internal data members. The message loop should be running and exceed the
82 // lifetime of the filter. 76 // lifetime of the filter.
83 virtual void set_message_loop(MessageLoop* message_loop) { 77 virtual void set_message_loop(MessageLoop* message_loop);
84 DCHECK(message_loop);
85 DCHECK(!message_loop_);
86 message_loop_ = message_loop;
87 }
88 78
89 virtual MessageLoop* message_loop() { 79 virtual MessageLoop* message_loop();
90 return message_loop_;
91 }
92 80
93 // The pipeline has resumed playback. Filters can continue requesting reads. 81 // The pipeline has resumed playback. Filters can continue requesting reads.
94 // Filters may implement this method if they need to respond to this call. 82 // Filters may implement this method if they need to respond to this call.
95 // TODO(boliu): Check that callback is not NULL in subclasses. 83 // TODO(boliu): Check that callback is not NULL in subclasses.
96 virtual void Play(FilterCallback* callback) { 84 virtual void Play(FilterCallback* callback);
97 DCHECK(callback);
98 if (callback) {
99 callback->Run();
100 delete callback;
101 }
102 }
103 85
104 // The pipeline has paused playback. Filters should stop buffer exchange. 86 // The pipeline has paused playback. Filters should stop buffer exchange.
105 // Filters may implement this method if they need to respond to this call. 87 // Filters may implement this method if they need to respond to this call.
106 // TODO(boliu): Check that callback is not NULL in subclasses. 88 // TODO(boliu): Check that callback is not NULL in subclasses.
107 virtual void Pause(FilterCallback* callback) { 89 virtual void Pause(FilterCallback* callback);
108 DCHECK(callback);
109 if (callback) {
110 callback->Run();
111 delete callback;
112 }
113 }
114 90
115 // The pipeline has been flushed. Filters should return buffer to owners. 91 // The pipeline has been flushed. Filters should return buffer to owners.
116 // Filters may implement this method if they need to respond to this call. 92 // Filters may implement this method if they need to respond to this call.
117 // TODO(boliu): Check that callback is not NULL in subclasses. 93 // TODO(boliu): Check that callback is not NULL in subclasses.
118 virtual void Flush(FilterCallback* callback) { 94 virtual void Flush(FilterCallback* callback);
119 DCHECK(callback);
120 if (callback) {
121 callback->Run();
122 delete callback;
123 }
124 }
125 95
126 // The pipeline is being stopped either as a result of an error or because 96 // The pipeline is being stopped either as a result of an error or because
127 // the client called Stop(). 97 // the client called Stop().
128 // TODO(boliu): Check that callback is not NULL in subclasses. 98 // TODO(boliu): Check that callback is not NULL in subclasses.
129 virtual void Stop(FilterCallback* callback) { 99 virtual void Stop(FilterCallback* callback);
130 DCHECK(callback);
131 if (callback) {
132 callback->Run();
133 delete callback;
134 }
135 }
136 100
137 // The pipeline playback rate has been changed. Filters may implement this 101 // The pipeline playback rate has been changed. Filters may implement this
138 // method if they need to respond to this call. 102 // method if they need to respond to this call.
139 virtual void SetPlaybackRate(float playback_rate) {} 103 virtual void SetPlaybackRate(float playback_rate);
140 104
141 // Carry out any actions required to seek to the given time, executing the 105 // Carry out any actions required to seek to the given time, executing the
142 // callback upon completion. 106 // callback upon completion.
143 virtual void Seek(base::TimeDelta time, FilterCallback* callback) { 107 virtual void Seek(base::TimeDelta time, FilterCallback* callback);
144 scoped_ptr<FilterCallback> seek_callback(callback);
145 if (seek_callback.get()) {
146 seek_callback->Run();
147 }
148 }
149 108
150 // This method is called from the pipeline when the audio renderer 109 // This method is called from the pipeline when the audio renderer
151 // is disabled. Filters can ignore the notification if they do not 110 // is disabled. Filters can ignore the notification if they do not
152 // need to react to this event. 111 // need to react to this event.
153 virtual void OnAudioRendererDisabled() { 112 virtual void OnAudioRendererDisabled();
154 }
155 113
156 protected: 114 protected:
157 // Only allow scoped_refptr<> to delete filters. 115 // Only allow scoped_refptr<> to delete filters.
158 friend class base::RefCountedThreadSafe<MediaFilter>; 116 friend class base::RefCountedThreadSafe<MediaFilter>;
159 virtual ~MediaFilter() {} 117 virtual ~MediaFilter();
160 118
161 FilterHost* host() const { return host_; } 119 FilterHost* host() const { return host_; }
162 MessageLoop* message_loop() const { return message_loop_; } 120 MessageLoop* message_loop() const { return message_loop_; }
163 121
164 private: 122 private:
165 FilterHost* host_; 123 FilterHost* host_;
166 MessageLoop* message_loop_; 124 MessageLoop* message_loop_;
167 125
168 DISALLOW_COPY_AND_ASSIGN(MediaFilter); 126 DISALLOW_COPY_AND_ASSIGN(MediaFilter);
169 }; 127 };
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // buffer. 352 // buffer.
395 virtual bool HasEnded() = 0; 353 virtual bool HasEnded() = 0;
396 354
397 // Sets the output volume. 355 // Sets the output volume.
398 virtual void SetVolume(float volume) = 0; 356 virtual void SetVolume(float volume) = 0;
399 }; 357 };
400 358
401 } // namespace media 359 } // namespace media
402 360
403 #endif // MEDIA_BASE_FILTERS_H_ 361 #endif // MEDIA_BASE_FILTERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698