Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_COMPOSITE_FILTER_H_ | |
| 6 #define MEDIA_BASE_COMPOSITE_FILTER_H_ | |
| 7 | |
| 8 #include "base/thread.h" | |
| 9 #include "media/base/filter_host.h" | |
| 10 #include "media/base/filters.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 class CompositeFilter : public Filter, | |
|
scherkus (not reviewing)
2010/12/15 16:44:02
nit: all of this + { can fit on one line
acolwell GONE FROM CHROMIUM
2010/12/15 18:20:11
Done.
| |
| 15 private FilterHost | |
|
scherkus (not reviewing)
2010/12/15 16:44:02
woah private inheritance!
style recommends public
acolwell GONE FROM CHROMIUM
2010/12/15 18:20:11
FilterHost is private because I don't want other c
| |
| 16 { | |
| 17 public: | |
| 18 typedef base::Thread* (*ThreadFactoryFunction)(const char* thread_name); | |
| 19 | |
| 20 CompositeFilter(MessageLoop* message_loop); | |
| 21 | |
| 22 // Constructor that allows the default thread creation strategy to be | |
| 23 // overridden. | |
| 24 CompositeFilter(MessageLoop* message_loop, | |
| 25 ThreadFactoryFunction thread_factory); | |
| 26 | |
| 27 // Adds a filter to the composite. This is only allowed after set_host() | |
| 28 // is called and before the first state changing operation such as Play(), | |
| 29 // Flush(), Stop(), or Seek(). True is returned if the filter was successfully | |
| 30 // added to the composite. False is returned if the filter couldn't be added | |
| 31 // because the composite is in the wrong state or the filter needed a thread | |
| 32 // and the composite was unable to create one. | |
| 33 bool AddFilter(scoped_refptr<Filter> filter); | |
| 34 | |
| 35 // media::Filter methods. | |
| 36 virtual const char* major_mime_type() const; | |
| 37 virtual void set_host(FilterHost* host); | |
| 38 virtual FilterHost* host(); | |
| 39 virtual bool requires_message_loop() const; | |
| 40 virtual const char* message_loop_name() const; | |
| 41 virtual void set_message_loop(MessageLoop* message_loop); | |
|
scherkus (not reviewing)
2010/12/15 16:44:02
does CompositeFilter need to implement Filter, or
acolwell GONE FROM CHROMIUM
2010/12/15 18:20:11
In my opinion it should implement Filter. The idea
scherkus (not reviewing)
2010/12/15 18:57:44
Rietveld probably isn't the best for discussing, b
| |
| 42 virtual MessageLoop* message_loop(); | |
| 43 virtual void Play(FilterCallback* play_callback); | |
| 44 virtual void Pause(FilterCallback* pause_callback); | |
| 45 virtual void Flush(FilterCallback* flush_callback); | |
| 46 virtual void Stop(FilterCallback* stop_callback); | |
| 47 virtual void SetPlaybackRate(float playback_rate); | |
| 48 virtual void Seek(base::TimeDelta time, FilterCallback* seek_callback); | |
| 49 virtual void OnAudioRendererDisabled(); | |
| 50 | |
| 51 protected: | |
| 52 virtual ~CompositeFilter(); | |
|
scherkus (not reviewing)
2010/12/15 16:44:02
we could also make CompositeFilter non-ref-counted
acolwell GONE FROM CHROMIUM
2010/12/15 18:20:11
Why? This is ref-counted like other filters.
scherkus (not reviewing)
2010/12/15 18:57:44
We've been trying to move away from ref-counting s
| |
| 53 | |
| 54 /// Default thread factory strategy. | |
| 55 static base::Thread* DefaultThreadFactory(const char* thread_name); | |
| 56 | |
| 57 // media::FilterHost methods. | |
| 58 virtual void SetError(PipelineError error); | |
| 59 virtual base::TimeDelta GetTime() const; | |
| 60 virtual base::TimeDelta GetDuration() const; | |
| 61 virtual void SetTime(base::TimeDelta time); | |
| 62 virtual void SetDuration(base::TimeDelta duration); | |
| 63 virtual void SetBufferedTime(base::TimeDelta buffered_time); | |
| 64 virtual void SetTotalBytes(int64 total_bytes); | |
| 65 virtual void SetBufferedBytes(int64 buffered_bytes); | |
| 66 virtual void SetVideoSize(size_t width, size_t height); | |
| 67 virtual void SetStreaming(bool streaming); | |
| 68 virtual void NotifyEnded(); | |
| 69 virtual void SetLoaded(bool loaded); | |
| 70 virtual void SetNetworkActivity(bool network_activity); | |
| 71 virtual void DisableAudioRenderer(); | |
| 72 virtual void SetCurrentReadPosition(int64 offset); | |
| 73 virtual int64 GetCurrentReadPosition(); | |
| 74 | |
| 75 private: | |
| 76 enum State { | |
| 77 kInvalid, | |
| 78 kCreated, | |
| 79 kPaused, | |
| 80 kPlayPending, | |
| 81 kStopWhilePlayPending, | |
| 82 kPlaying, | |
| 83 kPausePending, | |
| 84 kStopWhilePausePending, | |
| 85 kFlushPending, | |
| 86 kStopWhileFlushPending, | |
| 87 kSeekPending, | |
| 88 kStopWhileSeekPending, | |
| 89 kStopPending, | |
| 90 kStopped, | |
| 91 kError | |
| 92 }; | |
| 93 | |
| 94 // Initialization method called by constructors. | |
| 95 void Init(MessageLoop* message_loop, ThreadFactoryFunction thread_factory); | |
| 96 | |
| 97 // Transition to a new state. | |
| 98 void ChangeState(State new_state); | |
| 99 | |
| 100 // Start calling filters in a sequence. | |
| 101 void StartSerialCallSequence(); | |
| 102 | |
| 103 // Call filters in parallel. | |
| 104 void StartParallelCallSequence(); | |
| 105 | |
| 106 // Call the filter based on the current value of state_. | |
| 107 void CallFilter(scoped_refptr<Filter>& filter, FilterCallback* callback); | |
| 108 | |
| 109 // Calls |callback_| and then clears the reference. | |
| 110 void DispatchPendingCallback(); | |
| 111 | |
| 112 // Gets the state to transition to given |state|. | |
| 113 State GetNextState(State state) const; | |
| 114 | |
| 115 // Filter callback for a serial sequence. | |
| 116 void SerialCallback(); | |
| 117 | |
| 118 // Filter callback for a parallel sequence. | |
| 119 void ParallelCallback(); | |
| 120 | |
| 121 // Called when a parallel or serial call sequence completes. | |
| 122 void OnCallSequenceDone(); | |
| 123 | |
| 124 // Helper function for sending an error to the FilterHost. | |
| 125 void SendErrorToHost(PipelineError error); | |
| 126 | |
| 127 // Helper function for handling errors during call sequences. | |
| 128 void HandleError(PipelineError error); | |
| 129 | |
| 130 // Creates a callback that can be called from any thread, but is guaranteed | |
| 131 // to call the specified method on the thread associated with this filter. | |
| 132 FilterCallback* NewThreadSafeCallback(void (CompositeFilter::*method)()); | |
| 133 | |
| 134 // Helper function used by NewThreadSafeCallback() to make sure the | |
| 135 // method gets called on the right thread. | |
| 136 void OnCallback(MessageLoop* message_loop, | |
| 137 void (CompositeFilter::*method)()); | |
| 138 | |
| 139 // Helper function that indicates whether SetError() calls can be forwarded | |
| 140 // to the host of this filter. | |
| 141 bool CanForwardError(); | |
| 142 | |
| 143 // Vector of threads owned by the composite and used by filters in |filters_|. | |
| 144 typedef std::vector<base::Thread*> FilterThreadVector; | |
| 145 FilterThreadVector filter_threads_; | |
| 146 | |
| 147 // Vector of the filters added to the composite. | |
| 148 typedef std::vector<scoped_refptr<Filter> > FilterVector; | |
| 149 FilterVector filters_; | |
| 150 | |
| 151 // Factory function used to create filter threads. | |
| 152 ThreadFactoryFunction thread_factory_; | |
| 153 | |
| 154 // Callback for the pending request. | |
| 155 scoped_ptr<FilterCallback> callback_; | |
| 156 | |
| 157 // Time parameter for the pending Seek() request. | |
| 158 base::TimeDelta pending_seek_time_; | |
| 159 | |
| 160 // Current state of this filter. | |
| 161 State state_; | |
| 162 | |
| 163 // The index of the filter currently processing a request. | |
| 164 unsigned int sequence_index_; | |
|
scherkus (not reviewing)
2010/12/15 16:44:02
bit confused.. if this is an unsigned int I notice
acolwell GONE FROM CHROMIUM
2010/12/15 18:20:11
I'll fix this. The -1 was a hack to get around hav
| |
| 165 | |
| 166 // Message loop passed into the constructor. | |
| 167 MessageLoop* message_loop_; | |
| 168 | |
| 169 // FilterHost passed in via set_host(). | |
| 170 FilterHost* host_; | |
| 171 | |
| 172 // Error passed in the last SetError() call. | |
| 173 PipelineError error_; | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(CompositeFilter); | |
| 176 }; | |
| 177 | |
| 178 } // namespace media | |
| 179 | |
| 180 #endif // MEDIA_BASE_COMPOSITE_FILTER_H_ | |
| OLD | NEW |