Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
| 28 #include "media/base/audio_decoder.h" | 28 #include "media/base/audio_decoder.h" |
| 29 #include "media/base/audio_renderer.h" | 29 #include "media/base/audio_renderer.h" |
| 30 #include "media/base/audio_renderer_sink.h" | 30 #include "media/base/audio_renderer_sink.h" |
| 31 #include "media/base/decryptor.h" | 31 #include "media/base/decryptor.h" |
| 32 #include "media/filters/audio_renderer_algorithm.h" | 32 #include "media/filters/audio_renderer_algorithm.h" |
| 33 #include "media/filters/decoder_stream.h" | 33 #include "media/filters/decoder_stream.h" |
| 34 | 34 |
| 35 namespace base { | 35 namespace base { |
| 36 class SingleThreadTaskRunner; | 36 class SingleThreadTaskRunner; |
| 37 class TickClock; | |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace media { | 40 namespace media { |
| 40 | 41 |
| 41 class AudioBufferConverter; | 42 class AudioBufferConverter; |
| 42 class AudioBus; | 43 class AudioBus; |
| 43 class AudioClock; | 44 class AudioClock; |
| 44 class AudioHardwareConfig; | 45 class AudioHardwareConfig; |
| 45 class AudioSplicer; | 46 class AudioSplicer; |
| 46 class DecryptingDemuxerStream; | 47 class DecryptingDemuxerStream; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 58 // |set_decryptor_ready_cb| is fired when the audio decryptor is available | 59 // |set_decryptor_ready_cb| is fired when the audio decryptor is available |
| 59 // (only applicable if the stream is encrypted and we have a decryptor). | 60 // (only applicable if the stream is encrypted and we have a decryptor). |
| 60 AudioRendererImpl( | 61 AudioRendererImpl( |
| 61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 62 AudioRendererSink* sink, | 63 AudioRendererSink* sink, |
| 63 ScopedVector<AudioDecoder> decoders, | 64 ScopedVector<AudioDecoder> decoders, |
| 64 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 65 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 65 AudioHardwareConfig* hardware_params); | 66 AudioHardwareConfig* hardware_params); |
| 66 virtual ~AudioRendererImpl(); | 67 virtual ~AudioRendererImpl(); |
| 67 | 68 |
| 69 // TimeSource implementation. | |
|
xhwang
2014/07/21 22:10:06
Since AudioRenderer inherits TimeSource, this is n
| |
| 70 virtual void StartTicking() OVERRIDE; | |
| 71 virtual void StopTicking() OVERRIDE; | |
| 72 virtual void SetPlaybackRate(float rate) OVERRIDE; | |
| 73 virtual void SetMediaTime(base::TimeDelta timestamp) OVERRIDE; | |
| 74 virtual base::TimeDelta CurrentMediaTime() OVERRIDE; | |
| 75 | |
| 68 // AudioRenderer implementation. | 76 // AudioRenderer implementation. |
| 69 virtual void Initialize(DemuxerStream* stream, | 77 virtual void Initialize(DemuxerStream* stream, |
| 70 const PipelineStatusCB& init_cb, | 78 const PipelineStatusCB& init_cb, |
| 71 const StatisticsCB& statistics_cb, | 79 const StatisticsCB& statistics_cb, |
| 72 const TimeCB& time_cb, | 80 const TimeCB& time_cb, |
| 73 const BufferingStateCB& buffering_state_cb, | 81 const BufferingStateCB& buffering_state_cb, |
| 74 const base::Closure& ended_cb, | 82 const base::Closure& ended_cb, |
| 75 const PipelineStatusCB& error_cb) OVERRIDE; | 83 const PipelineStatusCB& error_cb) OVERRIDE; |
| 76 virtual void StartRendering() OVERRIDE; | |
| 77 virtual void StopRendering() OVERRIDE; | |
| 78 virtual void SetMediaTime(base::TimeDelta time) OVERRIDE; | |
| 79 virtual void Flush(const base::Closure& callback) OVERRIDE; | 84 virtual void Flush(const base::Closure& callback) OVERRIDE; |
| 80 virtual void Stop(const base::Closure& callback) OVERRIDE; | 85 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 81 virtual void SetPlaybackRate(float rate) OVERRIDE; | |
| 82 virtual void StartPlaying() OVERRIDE; | 86 virtual void StartPlaying() OVERRIDE; |
| 83 virtual void SetVolume(float volume) OVERRIDE; | 87 virtual void SetVolume(float volume) OVERRIDE; |
| 84 | 88 |
| 89 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | |
| 90 | |
| 85 private: | 91 private: |
| 86 friend class AudioRendererImplTest; | 92 friend class AudioRendererImplTest; |
| 87 | 93 |
| 88 // Important detail: being in kPlaying doesn't imply that audio is being | 94 // Important detail: being in kPlaying doesn't imply that audio is being |
| 89 // rendered. Rather, it means that the renderer is ready to go. The actual | 95 // rendered. Rather, it means that the renderer is ready to go. The actual |
| 90 // rendering of audio is controlled via Start/StopRendering(). | 96 // rendering of audio is controlled via Start/StopRendering(). |
| 91 // | 97 // |
| 92 // kUninitialized | 98 // kUninitialized |
| 93 // | Initialize() | 99 // | Initialize() |
| 94 // | | 100 // | |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // Callbacks provided during Initialize(). | 216 // Callbacks provided during Initialize(). |
| 211 PipelineStatusCB init_cb_; | 217 PipelineStatusCB init_cb_; |
| 212 TimeCB time_cb_; | 218 TimeCB time_cb_; |
| 213 BufferingStateCB buffering_state_cb_; | 219 BufferingStateCB buffering_state_cb_; |
| 214 base::Closure ended_cb_; | 220 base::Closure ended_cb_; |
| 215 PipelineStatusCB error_cb_; | 221 PipelineStatusCB error_cb_; |
| 216 | 222 |
| 217 // Callback provided to Flush(). | 223 // Callback provided to Flush(). |
| 218 base::Closure flush_cb_; | 224 base::Closure flush_cb_; |
| 219 | 225 |
| 226 scoped_ptr<base::TickClock> tick_clock_; | |
| 227 | |
| 220 // After Initialize() has completed, all variables below must be accessed | 228 // After Initialize() has completed, all variables below must be accessed |
| 221 // under |lock_|. ------------------------------------------------------------ | 229 // under |lock_|. ------------------------------------------------------------ |
| 222 base::Lock lock_; | 230 base::Lock lock_; |
| 223 | 231 |
| 224 // Algorithm for scaling audio. | 232 // Algorithm for scaling audio. |
| 225 scoped_ptr<AudioRendererAlgorithm> algorithm_; | 233 scoped_ptr<AudioRendererAlgorithm> algorithm_; |
| 226 | 234 |
| 227 // Simple state tracking variable. | 235 // Simple state tracking variable. |
| 228 State state_; | 236 State state_; |
| 229 | 237 |
| 230 BufferingState buffering_state_; | 238 BufferingState buffering_state_; |
| 231 | 239 |
| 232 // Keep track of whether or not the sink is playing and whether we should be | 240 // Keep track of whether or not the sink is playing and whether we should be |
| 233 // rendering. | 241 // rendering. |
| 234 bool rendering_; | 242 bool rendering_; |
| 235 bool sink_playing_; | 243 bool sink_playing_; |
| 236 | 244 |
| 237 // Keep track of our outstanding read to |decoder_|. | 245 // Keep track of our outstanding read to |decoder_|. |
| 238 bool pending_read_; | 246 bool pending_read_; |
| 239 | 247 |
| 240 // Keeps track of whether we received and rendered the end of stream buffer. | 248 // Keeps track of whether we received and rendered the end of stream buffer. |
| 241 bool received_end_of_stream_; | 249 bool received_end_of_stream_; |
| 242 bool rendered_end_of_stream_; | 250 bool rendered_end_of_stream_; |
| 243 | 251 |
| 244 scoped_ptr<AudioClock> audio_clock_; | 252 scoped_ptr<AudioClock> audio_clock_; |
| 253 base::TimeTicks last_render_ticks_; | |
| 245 | 254 |
| 246 base::TimeDelta start_timestamp_; | 255 base::TimeDelta start_timestamp_; |
| 247 | 256 |
| 248 // End variables which must be accessed under |lock_|. ---------------------- | 257 // End variables which must be accessed under |lock_|. ---------------------- |
| 249 | 258 |
| 250 // NOTE: Weak pointers must be invalidated before all other member variables. | 259 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 251 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 260 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
| 252 | 261 |
| 253 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 262 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 254 }; | 263 }; |
| 255 | 264 |
| 256 } // namespace media | 265 } // namespace media |
| 257 | 266 |
| 258 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 267 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |