OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Audio rendering unit utilizing an AudioRendererSink to output data. | 5 // Audio rendering unit utilizing an AudioRendererSink to output data. |
6 // | 6 // |
7 // This class lives inside three threads during it's lifetime, namely: | 7 // This class lives inside three threads during it's lifetime, namely: |
8 // 1. Render thread | 8 // 1. Render thread |
9 // Where the object is created. | 9 // Where the object is created. |
10 // 2. Media thread (provided via constructor) | 10 // 2. Media thread (provided via constructor) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // | 146 // |
147 // Render() updates the pipeline's playback timestamp. If Render() is | 147 // Render() updates the pipeline's playback timestamp. If Render() is |
148 // not called at the same rate as audio samples are played, then the reported | 148 // not called at the same rate as audio samples are played, then the reported |
149 // timestamp in the pipeline will be ahead of the actual audio playback. In | 149 // timestamp in the pipeline will be ahead of the actual audio playback. In |
150 // this case |audio_delay_milliseconds| should be used to indicate when in the | 150 // this case |audio_delay_milliseconds| should be used to indicate when in the |
151 // future should the filled buffer be played. | 151 // future should the filled buffer be played. |
152 virtual int Render(AudioBus* audio_bus, | 152 virtual int Render(AudioBus* audio_bus, |
153 int audio_delay_milliseconds) OVERRIDE; | 153 int audio_delay_milliseconds) OVERRIDE; |
154 virtual void OnRenderError() OVERRIDE; | 154 virtual void OnRenderError() OVERRIDE; |
155 | 155 |
156 // Contains result of the last call to Render(). Used to update |audio_clock_| | |
157 // and changes in buffering state. | |
158 struct RenderResult { | |
159 RenderResult(); | |
160 | |
161 int requested_frames; | |
162 int delay_frames; | |
163 int frames_written; | |
164 float playback_rate; | |
165 base::TimeDelta endpoint_timestamp; | |
166 }; | |
167 void DidRender(RenderResult result); | |
DaleCurtis
2014/07/10 23:37:00
const&
| |
168 | |
156 // Helper methods that schedule an asynchronous read from the decoder as long | 169 // Helper methods that schedule an asynchronous read from the decoder as long |
157 // as there isn't a pending read. | 170 // as there isn't a pending read. |
158 // | 171 // |
159 // Must be called on |task_runner_|. | 172 // Must be called on |task_runner_|. |
160 void AttemptRead(); | |
161 void AttemptRead_Locked(); | 173 void AttemptRead_Locked(); |
162 bool CanRead_Locked(); | |
163 void ChangeState_Locked(State new_state); | 174 void ChangeState_Locked(State new_state); |
164 | 175 |
165 // Returns true if the data in the buffer is all before |start_timestamp_|. | 176 // Returns true if the data in the buffer is all before |start_timestamp_|. |
166 // This can only return true while in the kPlaying state. | 177 // This can only return true while in the kPlaying state. |
167 bool IsBeforeStartTime(const scoped_refptr<AudioBuffer>& buffer); | 178 bool IsBeforeStartTime(const scoped_refptr<AudioBuffer>& buffer); |
168 | 179 |
169 // Called upon AudioBufferStream initialization, or failure thereof (indicated | 180 // Called upon AudioBufferStream initialization, or failure thereof (indicated |
170 // by the value of |success|). | 181 // by the value of |success|). |
171 void OnAudioBufferStreamInitialized(bool succes); | 182 void OnAudioBufferStreamInitialized(bool succes); |
172 | 183 |
173 // Used to initiate the flush operation once all pending reads have | 184 // Used to initiate the flush operation once all pending reads have |
174 // completed. | 185 // completed. |
175 void DoFlush_Locked(); | 186 void DoFlush_Locked(); |
176 | 187 |
177 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get | 188 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get |
178 // called when the reset completes. | 189 // called when the reset completes. |
179 void ResetDecoder(); | 190 void ResetDecoder(); |
180 | 191 |
181 // Called when the |decoder_|.Reset() has completed. | 192 // Called when the |decoder_|.Reset() has completed. |
182 void ResetDecoderDone(); | 193 void ResetDecoderDone(); |
183 | 194 |
184 // Called by the AudioBufferStream when a splice buffer is demuxed. | 195 // Called by the AudioBufferStream when a splice buffer is demuxed. |
185 void OnNewSpliceBuffer(base::TimeDelta); | 196 void OnNewSpliceBuffer(base::TimeDelta); |
186 | 197 |
187 // Called by the AudioBufferStream when a config change occurs. | 198 // Called by the AudioBufferStream when a config change occurs. |
188 void OnConfigChange(); | 199 void OnConfigChange(); |
189 | 200 |
190 // Updates |buffering_state_| and fires |buffering_state_cb_|. | 201 // Updates |buffering_state_| and fires |buffering_state_cb_|. |
191 void SetBufferingState_Locked(BufferingState buffering_state); | 202 void SetBufferingState(BufferingState buffering_state); |
192 | 203 |
193 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 204 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
194 | 205 |
195 scoped_ptr<AudioSplicer> splicer_; | 206 scoped_ptr<AudioSplicer> splicer_; |
196 scoped_ptr<AudioBufferConverter> buffer_converter_; | 207 scoped_ptr<AudioBufferConverter> buffer_converter_; |
197 | 208 |
198 // Whether or not we expect to handle config changes. | 209 // Whether or not we expect to handle config changes. |
199 bool expecting_config_changes_; | 210 bool expecting_config_changes_; |
200 | 211 |
201 // The sink (destination) for rendered audio. |sink_| must only be accessed | 212 // The sink (destination) for rendered audio. |sink_| must only be accessed |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 | 267 |
257 // NOTE: Weak pointers must be invalidated before all other member variables. | 268 // NOTE: Weak pointers must be invalidated before all other member variables. |
258 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 269 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
259 | 270 |
260 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 271 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
261 }; | 272 }; |
262 | 273 |
263 } // namespace media | 274 } // namespace media |
264 | 275 |
265 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 276 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |