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) |
11 // All AudioDecoder methods are called on this thread. | 11 // All AudioDecoder methods are called on this thread. |
12 // 3. Audio thread created by the AudioRendererSink. | 12 // 3. Audio thread created by the AudioRendererSink. |
13 // Render() is called here where audio data is decoded into raw PCM data. | 13 // Render() is called here where audio data is decoded into raw PCM data. |
14 // | 14 // |
15 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of | 15 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of |
16 // queueing audio data and stretching/shrinking audio data when playback rate != | 16 // queueing audio data and stretching/shrinking audio data when playback rate != |
17 // 1.0 or 0.0. | 17 // 1.0 or 0.0. |
18 | 18 |
19 #ifndef MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 19 #ifndef MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
20 #define MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 20 #define MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
21 | 21 |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 | 23 |
24 #include <deque> | 24 #include <deque> |
| 25 #include <memory> |
25 | 26 |
26 #include "base/macros.h" | 27 #include "base/macros.h" |
27 #include "base/memory/scoped_ptr.h" | |
28 #include "base/memory/weak_ptr.h" | 28 #include "base/memory/weak_ptr.h" |
29 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
30 #include "media/base/audio_decoder.h" | 30 #include "media/base/audio_decoder.h" |
31 #include "media/base/audio_renderer.h" | 31 #include "media/base/audio_renderer.h" |
32 #include "media/base/audio_renderer_sink.h" | 32 #include "media/base/audio_renderer_sink.h" |
33 #include "media/base/decryptor.h" | 33 #include "media/base/decryptor.h" |
34 #include "media/base/media_log.h" | 34 #include "media/base/media_log.h" |
35 #include "media/base/time_source.h" | 35 #include "media/base/time_source.h" |
36 #include "media/filters/audio_renderer_algorithm.h" | 36 #include "media/filters/audio_renderer_algorithm.h" |
37 #include "media/filters/decoder_stream.h" | 37 #include "media/filters/decoder_stream.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 void OnNewSpliceBuffer(base::TimeDelta); | 187 void OnNewSpliceBuffer(base::TimeDelta); |
188 | 188 |
189 // Called by the AudioBufferStream when a config change occurs. | 189 // Called by the AudioBufferStream when a config change occurs. |
190 void OnConfigChange(); | 190 void OnConfigChange(); |
191 | 191 |
192 // Updates |buffering_state_| and fires |buffering_state_cb_|. | 192 // Updates |buffering_state_| and fires |buffering_state_cb_|. |
193 void SetBufferingState_Locked(BufferingState buffering_state); | 193 void SetBufferingState_Locked(BufferingState buffering_state); |
194 | 194 |
195 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 195 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
196 | 196 |
197 scoped_ptr<AudioSplicer> splicer_; | 197 std::unique_ptr<AudioSplicer> splicer_; |
198 scoped_ptr<AudioBufferConverter> buffer_converter_; | 198 std::unique_ptr<AudioBufferConverter> buffer_converter_; |
199 | 199 |
200 // Whether or not we expect to handle config changes. | 200 // Whether or not we expect to handle config changes. |
201 bool expecting_config_changes_; | 201 bool expecting_config_changes_; |
202 | 202 |
203 // The sink (destination) for rendered audio. |sink_| must only be accessed | 203 // The sink (destination) for rendered audio. |sink_| must only be accessed |
204 // on |task_runner_|. |sink_| must never be called under |lock_| or else we | 204 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
205 // may deadlock between |task_runner_| and the audio callback thread. | 205 // may deadlock between |task_runner_| and the audio callback thread. |
206 scoped_refptr<media::AudioRendererSink> sink_; | 206 scoped_refptr<media::AudioRendererSink> sink_; |
207 | 207 |
208 scoped_ptr<AudioBufferStream> audio_buffer_stream_; | 208 std::unique_ptr<AudioBufferStream> audio_buffer_stream_; |
209 | 209 |
210 // Interface to the hardware audio params. | 210 // Interface to the hardware audio params. |
211 const AudioHardwareConfig& hardware_config_; | 211 const AudioHardwareConfig& hardware_config_; |
212 | 212 |
213 scoped_refptr<MediaLog> media_log_; | 213 scoped_refptr<MediaLog> media_log_; |
214 | 214 |
215 // Cached copy of hardware params from |hardware_config_|. | 215 // Cached copy of hardware params from |hardware_config_|. |
216 AudioParameters audio_parameters_; | 216 AudioParameters audio_parameters_; |
217 | 217 |
218 // Callbacks provided during Initialize(). | 218 // Callbacks provided during Initialize(). |
219 PipelineStatusCB init_cb_; | 219 PipelineStatusCB init_cb_; |
220 BufferingStateCB buffering_state_cb_; | 220 BufferingStateCB buffering_state_cb_; |
221 base::Closure ended_cb_; | 221 base::Closure ended_cb_; |
222 PipelineStatusCB error_cb_; | 222 PipelineStatusCB error_cb_; |
223 StatisticsCB statistics_cb_; | 223 StatisticsCB statistics_cb_; |
224 | 224 |
225 // Callback provided to Flush(). | 225 // Callback provided to Flush(). |
226 base::Closure flush_cb_; | 226 base::Closure flush_cb_; |
227 | 227 |
228 // Overridable tick clock for testing. | 228 // Overridable tick clock for testing. |
229 scoped_ptr<base::TickClock> tick_clock_; | 229 std::unique_ptr<base::TickClock> tick_clock_; |
230 | 230 |
231 // Memory usage of |algorithm_| recorded during the last | 231 // Memory usage of |algorithm_| recorded during the last |
232 // HandleSplicerBuffer_Locked() call. | 232 // HandleSplicerBuffer_Locked() call. |
233 int64_t last_audio_memory_usage_; | 233 int64_t last_audio_memory_usage_; |
234 | 234 |
235 // Sample rate of the last decoded audio buffer. Allows for detection of | 235 // Sample rate of the last decoded audio buffer. Allows for detection of |
236 // sample rate changes due to implicit AAC configuration change. | 236 // sample rate changes due to implicit AAC configuration change. |
237 int last_decoded_sample_rate_; | 237 int last_decoded_sample_rate_; |
238 | 238 |
239 // After Initialize() has completed, all variables below must be accessed | 239 // After Initialize() has completed, all variables below must be accessed |
240 // under |lock_|. ------------------------------------------------------------ | 240 // under |lock_|. ------------------------------------------------------------ |
241 base::Lock lock_; | 241 base::Lock lock_; |
242 | 242 |
243 // Algorithm for scaling audio. | 243 // Algorithm for scaling audio. |
244 double playback_rate_; | 244 double playback_rate_; |
245 scoped_ptr<AudioRendererAlgorithm> algorithm_; | 245 std::unique_ptr<AudioRendererAlgorithm> algorithm_; |
246 | 246 |
247 // Simple state tracking variable. | 247 // Simple state tracking variable. |
248 State state_; | 248 State state_; |
249 | 249 |
250 BufferingState buffering_state_; | 250 BufferingState buffering_state_; |
251 | 251 |
252 // Keep track of whether or not the sink is playing and whether we should be | 252 // Keep track of whether or not the sink is playing and whether we should be |
253 // rendering. | 253 // rendering. |
254 bool rendering_; | 254 bool rendering_; |
255 bool sink_playing_; | 255 bool sink_playing_; |
256 | 256 |
257 // Keep track of our outstanding read to |decoder_|. | 257 // Keep track of our outstanding read to |decoder_|. |
258 bool pending_read_; | 258 bool pending_read_; |
259 | 259 |
260 // Keeps track of whether we received and rendered the end of stream buffer. | 260 // Keeps track of whether we received and rendered the end of stream buffer. |
261 bool received_end_of_stream_; | 261 bool received_end_of_stream_; |
262 bool rendered_end_of_stream_; | 262 bool rendered_end_of_stream_; |
263 | 263 |
264 scoped_ptr<AudioClock> audio_clock_; | 264 std::unique_ptr<AudioClock> audio_clock_; |
265 | 265 |
266 // The media timestamp to begin playback at after seeking. Set via | 266 // The media timestamp to begin playback at after seeking. Set via |
267 // SetMediaTime(). | 267 // SetMediaTime(). |
268 base::TimeDelta start_timestamp_; | 268 base::TimeDelta start_timestamp_; |
269 | 269 |
270 // The media timestamp to signal end of audio playback. Determined during | 270 // The media timestamp to signal end of audio playback. Determined during |
271 // Render() when writing the final frames of decoded audio data. | 271 // Render() when writing the final frames of decoded audio data. |
272 base::TimeDelta ended_timestamp_; | 272 base::TimeDelta ended_timestamp_; |
273 | 273 |
274 // Set every Render() and used to provide an interpolated time value to | 274 // Set every Render() and used to provide an interpolated time value to |
(...skipping 17 matching lines...) Expand all Loading... |
292 | 292 |
293 // NOTE: Weak pointers must be invalidated before all other member variables. | 293 // NOTE: Weak pointers must be invalidated before all other member variables. |
294 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 294 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
295 | 295 |
296 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 296 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
297 }; | 297 }; |
298 | 298 |
299 } // namespace media | 299 } // namespace media |
300 | 300 |
301 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 301 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |