| 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 29 matching lines...) Expand all Loading... |
| 40 namespace base { | 40 namespace base { |
| 41 class SingleThreadTaskRunner; | 41 class SingleThreadTaskRunner; |
| 42 class TickClock; | 42 class TickClock; |
| 43 } | 43 } |
| 44 | 44 |
| 45 namespace media { | 45 namespace media { |
| 46 | 46 |
| 47 class AudioBufferConverter; | 47 class AudioBufferConverter; |
| 48 class AudioBus; | 48 class AudioBus; |
| 49 class AudioClock; | 49 class AudioClock; |
| 50 class AudioSplicer; | |
| 51 class DecryptingDemuxerStream; | 50 class DecryptingDemuxerStream; |
| 52 | 51 |
| 53 class MEDIA_EXPORT AudioRendererImpl | 52 class MEDIA_EXPORT AudioRendererImpl |
| 54 : public AudioRenderer, | 53 : public AudioRenderer, |
| 55 public TimeSource, | 54 public TimeSource, |
| 56 public base::PowerObserver, | 55 public base::PowerObserver, |
| 57 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 56 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 58 public: | 57 public: |
| 59 // |task_runner| is the thread on which AudioRendererImpl will execute. | 58 // |task_runner| is the thread on which AudioRendererImpl will execute. |
| 60 // | 59 // |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 kFlushed, | 118 kFlushed, |
| 120 kPlaying | 119 kPlaying |
| 121 }; | 120 }; |
| 122 | 121 |
| 123 // Callback from the audio decoder delivering decoded audio samples. | 122 // Callback from the audio decoder delivering decoded audio samples. |
| 124 void DecodedAudioReady(AudioBufferStream::Status status, | 123 void DecodedAudioReady(AudioBufferStream::Status status, |
| 125 const scoped_refptr<AudioBuffer>& buffer); | 124 const scoped_refptr<AudioBuffer>& buffer); |
| 126 | 125 |
| 127 // Handles buffers that come out of |splicer_|. | 126 // Handles buffers that come out of |splicer_|. |
| 128 // Returns true if more buffers are needed. | 127 // Returns true if more buffers are needed. |
| 129 bool HandleSplicerBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer); | 128 bool HandleDecodedBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer); |
| 130 | 129 |
| 131 // Helper functions for DecodeStatus values passed to | 130 // Helper functions for DecodeStatus values passed to |
| 132 // DecodedAudioReady(). | 131 // DecodedAudioReady(). |
| 133 void HandleAbortedReadOrDecodeError(PipelineStatus status); | 132 void HandleAbortedReadOrDecodeError(PipelineStatus status); |
| 134 | 133 |
| 135 void StartRendering_Locked(); | 134 void StartRendering_Locked(); |
| 136 void StopRendering_Locked(); | 135 void StopRendering_Locked(); |
| 137 | 136 |
| 138 // AudioRendererSink::RenderCallback implementation. | 137 // AudioRendererSink::RenderCallback implementation. |
| 139 // | 138 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void OnNewSpliceBuffer(base::TimeDelta); | 193 void OnNewSpliceBuffer(base::TimeDelta); |
| 195 | 194 |
| 196 // Called by the AudioBufferStream when a config change occurs. | 195 // Called by the AudioBufferStream when a config change occurs. |
| 197 void OnConfigChange(); | 196 void OnConfigChange(); |
| 198 | 197 |
| 199 // Updates |buffering_state_| and fires |buffering_state_cb_|. | 198 // Updates |buffering_state_| and fires |buffering_state_cb_|. |
| 200 void SetBufferingState_Locked(BufferingState buffering_state); | 199 void SetBufferingState_Locked(BufferingState buffering_state); |
| 201 | 200 |
| 202 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 201 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 203 | 202 |
| 204 std::unique_ptr<AudioSplicer> splicer_; | |
| 205 std::unique_ptr<AudioBufferConverter> buffer_converter_; | 203 std::unique_ptr<AudioBufferConverter> buffer_converter_; |
| 206 | 204 |
| 207 // Whether or not we expect to handle config changes. | 205 // Whether or not we expect to handle config changes. |
| 208 bool expecting_config_changes_; | 206 bool expecting_config_changes_; |
| 209 | 207 |
| 210 // The sink (destination) for rendered audio. |sink_| must only be accessed | 208 // The sink (destination) for rendered audio. |sink_| must only be accessed |
| 211 // on |task_runner_|. |sink_| must never be called under |lock_| or else we | 209 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
| 212 // may deadlock between |task_runner_| and the audio callback thread. | 210 // may deadlock between |task_runner_| and the audio callback thread. |
| 213 scoped_refptr<media::AudioRendererSink> sink_; | 211 scoped_refptr<media::AudioRendererSink> sink_; |
| 214 | 212 |
| 215 std::unique_ptr<AudioBufferStream> audio_buffer_stream_; | 213 std::unique_ptr<AudioBufferStream> audio_buffer_stream_; |
| 216 | 214 |
| 217 scoped_refptr<MediaLog> media_log_; | 215 scoped_refptr<MediaLog> media_log_; |
| 218 | 216 |
| 219 // Cached copy of hardware params from |sink_|. | 217 // Cached copy of hardware params from |sink_|. |
| 220 AudioParameters audio_parameters_; | 218 AudioParameters audio_parameters_; |
| 221 | 219 |
| 222 RendererClient* client_; | 220 RendererClient* client_; |
| 223 | 221 |
| 224 // Callback provided during Initialize(). | 222 // Callback provided during Initialize(). |
| 225 PipelineStatusCB init_cb_; | 223 PipelineStatusCB init_cb_; |
| 226 | 224 |
| 227 // Callback provided to Flush(). | 225 // Callback provided to Flush(). |
| 228 base::Closure flush_cb_; | 226 base::Closure flush_cb_; |
| 229 | 227 |
| 230 // Overridable tick clock for testing. | 228 // Overridable tick clock for testing. |
| 231 std::unique_ptr<base::TickClock> tick_clock_; | 229 std::unique_ptr<base::TickClock> tick_clock_; |
| 232 | 230 |
| 233 // Memory usage of |algorithm_| recorded during the last | 231 // Memory usage of |algorithm_| recorded during the last |
| 234 // HandleSplicerBuffer_Locked() call. | 232 // HandleDecodedBuffer_Locked() call. |
| 235 int64_t last_audio_memory_usage_; | 233 int64_t last_audio_memory_usage_; |
| 236 | 234 |
| 237 // 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 |
| 238 // sample rate changes due to implicit AAC configuration change. | 236 // sample rate changes due to implicit AAC configuration change. |
| 239 int last_decoded_sample_rate_; | 237 int last_decoded_sample_rate_; |
| 240 | 238 |
| 241 // After Initialize() has completed, all variables below must be accessed | 239 // After Initialize() has completed, all variables below must be accessed |
| 242 // under |lock_|. ------------------------------------------------------------ | 240 // under |lock_|. ------------------------------------------------------------ |
| 243 base::Lock lock_; | 241 base::Lock lock_; |
| 244 | 242 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 292 |
| 295 // NOTE: Weak pointers must be invalidated before all other member variables. | 293 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 296 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 294 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
| 297 | 295 |
| 298 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 296 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 299 }; | 297 }; |
| 300 | 298 |
| 301 } // namespace media | 299 } // namespace media |
| 302 | 300 |
| 303 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 301 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |