| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 kInitializing, | 116 kInitializing, |
| 118 kFlushing, | 117 kFlushing, |
| 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 decoder (MSE: after passing through |
| 127 // |buffer_converter_|). |
| 128 // Returns true if more buffers are needed. | 128 // Returns true if more buffers are needed. |
| 129 bool HandleSplicerBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer); | 129 bool HandleDecodedBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer); |
| 130 | 130 |
| 131 // Helper functions for DecodeStatus values passed to | 131 // Helper functions for DecodeStatus values passed to |
| 132 // DecodedAudioReady(). | 132 // DecodedAudioReady(). |
| 133 void HandleAbortedReadOrDecodeError(PipelineStatus status); | 133 void HandleAbortedReadOrDecodeError(PipelineStatus status); |
| 134 | 134 |
| 135 void StartRendering_Locked(); | 135 void StartRendering_Locked(); |
| 136 void StopRendering_Locked(); | 136 void StopRendering_Locked(); |
| 137 | 137 |
| 138 // AudioRendererSink::RenderCallback implementation. | 138 // AudioRendererSink::RenderCallback implementation. |
| 139 // | 139 // |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void OnBufferingStateChange(BufferingState state); | 183 void OnBufferingStateChange(BufferingState state); |
| 184 void OnWaitingForDecryptionKey(); | 184 void OnWaitingForDecryptionKey(); |
| 185 | 185 |
| 186 // Used to initiate the flush operation once all pending reads have | 186 // Used to initiate the flush operation once all pending reads have |
| 187 // completed. | 187 // completed. |
| 188 void DoFlush_Locked(); | 188 void DoFlush_Locked(); |
| 189 | 189 |
| 190 // Called when the |decoder_|.Reset() has completed. | 190 // Called when the |decoder_|.Reset() has completed. |
| 191 void ResetDecoderDone(); | 191 void ResetDecoderDone(); |
| 192 | 192 |
| 193 // Called by the AudioBufferStream when a splice buffer is demuxed. | |
| 194 void OnNewSpliceBuffer(base::TimeDelta); | |
| 195 | |
| 196 // Called by the AudioBufferStream when a config change occurs. | 193 // Called by the AudioBufferStream when a config change occurs. |
| 197 void OnConfigChange(); | 194 void OnConfigChange(); |
| 198 | 195 |
| 199 // Updates |buffering_state_| and fires |buffering_state_cb_|. | 196 // Updates |buffering_state_| and fires |buffering_state_cb_|. |
| 200 void SetBufferingState_Locked(BufferingState buffering_state); | 197 void SetBufferingState_Locked(BufferingState buffering_state); |
| 201 | 198 |
| 202 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 199 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 203 | 200 |
| 204 std::unique_ptr<AudioSplicer> splicer_; | |
| 205 std::unique_ptr<AudioBufferConverter> buffer_converter_; | 201 std::unique_ptr<AudioBufferConverter> buffer_converter_; |
| 206 | 202 |
| 207 // Whether or not we expect to handle config changes. | 203 // Whether or not we expect to handle config changes. |
| 208 bool expecting_config_changes_; | 204 bool expecting_config_changes_; |
| 209 | 205 |
| 210 // The sink (destination) for rendered audio. |sink_| must only be accessed | 206 // 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 | 207 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
| 212 // may deadlock between |task_runner_| and the audio callback thread. | 208 // may deadlock between |task_runner_| and the audio callback thread. |
| 213 scoped_refptr<media::AudioRendererSink> sink_; | 209 scoped_refptr<media::AudioRendererSink> sink_; |
| 214 | 210 |
| 215 std::unique_ptr<AudioBufferStream> audio_buffer_stream_; | 211 std::unique_ptr<AudioBufferStream> audio_buffer_stream_; |
| 216 | 212 |
| 217 scoped_refptr<MediaLog> media_log_; | 213 scoped_refptr<MediaLog> media_log_; |
| 218 | 214 |
| 219 // Cached copy of hardware params from |sink_|. | 215 // Cached copy of hardware params from |sink_|. |
| 220 AudioParameters audio_parameters_; | 216 AudioParameters audio_parameters_; |
| 221 | 217 |
| 222 RendererClient* client_; | 218 RendererClient* client_; |
| 223 | 219 |
| 224 // Callback provided during Initialize(). | 220 // Callback provided during Initialize(). |
| 225 PipelineStatusCB init_cb_; | 221 PipelineStatusCB init_cb_; |
| 226 | 222 |
| 227 // Callback provided to Flush(). | 223 // Callback provided to Flush(). |
| 228 base::Closure flush_cb_; | 224 base::Closure flush_cb_; |
| 229 | 225 |
| 230 // Overridable tick clock for testing. | 226 // Overridable tick clock for testing. |
| 231 std::unique_ptr<base::TickClock> tick_clock_; | 227 std::unique_ptr<base::TickClock> tick_clock_; |
| 232 | 228 |
| 233 // Memory usage of |algorithm_| recorded during the last | 229 // Memory usage of |algorithm_| recorded during the last |
| 234 // HandleSplicerBuffer_Locked() call. | 230 // HandleDecodedBuffer_Locked() call. |
| 235 int64_t last_audio_memory_usage_; | 231 int64_t last_audio_memory_usage_; |
| 236 | 232 |
| 237 // Sample rate of the last decoded audio buffer. Allows for detection of | 233 // Sample rate of the last decoded audio buffer. Allows for detection of |
| 238 // sample rate changes due to implicit AAC configuration change. | 234 // sample rate changes due to implicit AAC configuration change. |
| 239 int last_decoded_sample_rate_; | 235 int last_decoded_sample_rate_; |
| 240 | 236 |
| 241 // After Initialize() has completed, all variables below must be accessed | 237 // After Initialize() has completed, all variables below must be accessed |
| 242 // under |lock_|. ------------------------------------------------------------ | 238 // under |lock_|. ------------------------------------------------------------ |
| 243 base::Lock lock_; | 239 base::Lock lock_; |
| 244 | 240 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 290 |
| 295 // NOTE: Weak pointers must be invalidated before all other member variables. | 291 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 296 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 292 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
| 297 | 293 |
| 298 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 294 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 299 }; | 295 }; |
| 300 | 296 |
| 301 } // namespace media | 297 } // namespace media |
| 302 | 298 |
| 303 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ | 299 #endif // MEDIA_RENDERERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |