| 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 // This object is created on the render thread. | 9 // This object is created on the render thread. |
| 10 // 2. Pipeline thread | 10 // 2. Pipeline thread |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class MEDIA_EXPORT AudioRendererImpl | 34 class MEDIA_EXPORT AudioRendererImpl |
| 35 : public AudioRenderer, | 35 : public AudioRenderer, |
| 36 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { | 36 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback) { |
| 37 public: | 37 public: |
| 38 // Methods called on Render thread ------------------------------------------ | 38 // Methods called on Render thread ------------------------------------------ |
| 39 // An AudioRendererSink is used as the destination for the rendered audio. | 39 // An AudioRendererSink is used as the destination for the rendered audio. |
| 40 explicit AudioRendererImpl(media::AudioRendererSink* sink); | 40 explicit AudioRendererImpl(media::AudioRendererSink* sink); |
| 41 | 41 |
| 42 // Methods called on pipeline thread ---------------------------------------- | 42 // Methods called on pipeline thread ---------------------------------------- |
| 43 // Filter implementation. | 43 // AudioRenderer implementation. |
| 44 virtual void SetHost(FilterHost* host) OVERRIDE; | 44 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, |
| 45 const PipelineStatusCB& init_cb, |
| 46 const base::Closure& underflow_cb, |
| 47 const TimeCB& time_cb, |
| 48 const base::Closure& ended_cb, |
| 49 const base::Closure& disabled_cb, |
| 50 const PipelineStatusCB& error_cb) OVERRIDE; |
| 45 virtual void Play(const base::Closure& callback) OVERRIDE; | 51 virtual void Play(const base::Closure& callback) OVERRIDE; |
| 46 virtual void Pause(const base::Closure& callback) OVERRIDE; | 52 virtual void Pause(const base::Closure& callback) OVERRIDE; |
| 47 virtual void Flush(const base::Closure& callback) OVERRIDE; | 53 virtual void Flush(const base::Closure& callback) OVERRIDE; |
| 48 virtual void Stop(const base::Closure& callback) OVERRIDE; | 54 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 49 virtual void SetPlaybackRate(float rate) OVERRIDE; | 55 virtual void SetPlaybackRate(float rate) OVERRIDE; |
| 50 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 56 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 51 | |
| 52 // AudioRenderer implementation. | |
| 53 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, | |
| 54 const PipelineStatusCB& init_cb, | |
| 55 const base::Closure& underflow_cb, | |
| 56 const TimeCB& time_cb) OVERRIDE; | |
| 57 virtual bool HasEnded() OVERRIDE; | 57 virtual bool HasEnded() OVERRIDE; |
| 58 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; | 58 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; |
| 59 virtual void SetVolume(float volume) OVERRIDE; | 59 virtual void SetVolume(float volume) OVERRIDE; |
| 60 | 60 |
| 61 // Disables underflow support. When used, |state_| will never transition to | 61 // Disables underflow support. When used, |state_| will never transition to |
| 62 // kUnderflow resulting in Render calls that underflow returning 0 frames | 62 // kUnderflow resulting in Render calls that underflow returning 0 frames |
| 63 // instead of some number of silence frames. Must be called prior to | 63 // instead of some number of silence frames. Must be called prior to |
| 64 // Initialize(). | 64 // Initialize(). |
| 65 void DisableUnderflowForTesting(); | 65 void DisableUnderflowForTesting(); |
| 66 | 66 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // increments |pending_reads_|. | 129 // increments |pending_reads_|. |
| 130 // | 130 // |
| 131 // Safe to call from any thread. | 131 // Safe to call from any thread. |
| 132 void ScheduleRead_Locked(); | 132 void ScheduleRead_Locked(); |
| 133 | 133 |
| 134 // Returns true if the data in the buffer is all before | 134 // Returns true if the data in the buffer is all before |
| 135 // |seek_timestamp_|. This can only return true while | 135 // |seek_timestamp_|. This can only return true while |
| 136 // in the kSeeking state. | 136 // in the kSeeking state. |
| 137 bool IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer); | 137 bool IsBeforeSeekTime(const scoped_refptr<Buffer>& buffer); |
| 138 | 138 |
| 139 FilterHost* host_; | |
| 140 | |
| 141 // Audio decoder. | 139 // Audio decoder. |
| 142 scoped_refptr<AudioDecoder> decoder_; | 140 scoped_refptr<AudioDecoder> decoder_; |
| 143 | 141 |
| 144 // Algorithm for scaling audio. | 142 // Algorithm for scaling audio. |
| 145 scoped_ptr<AudioRendererAlgorithm> algorithm_; | 143 scoped_ptr<AudioRendererAlgorithm> algorithm_; |
| 146 | 144 |
| 147 base::Lock lock_; | 145 base::Lock lock_; |
| 148 | 146 |
| 149 // Simple state tracking variable. | 147 // Simple state tracking variable. |
| 150 enum State { | 148 enum State { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 168 // The timestamp of the last frame (i.e. furthest in the future) buffered as | 166 // The timestamp of the last frame (i.e. furthest in the future) buffered as |
| 169 // well as the current time that takes current playback delay into account. | 167 // well as the current time that takes current playback delay into account. |
| 170 base::TimeDelta audio_time_buffered_; | 168 base::TimeDelta audio_time_buffered_; |
| 171 base::TimeDelta current_time_; | 169 base::TimeDelta current_time_; |
| 172 | 170 |
| 173 // Filter callbacks. | 171 // Filter callbacks. |
| 174 base::Closure pause_cb_; | 172 base::Closure pause_cb_; |
| 175 PipelineStatusCB seek_cb_; | 173 PipelineStatusCB seek_cb_; |
| 176 | 174 |
| 177 base::Closure underflow_cb_; | 175 base::Closure underflow_cb_; |
| 178 | |
| 179 TimeCB time_cb_; | 176 TimeCB time_cb_; |
| 177 base::Closure ended_cb_; |
| 178 base::Closure disabled_cb_; |
| 179 PipelineStatusCB error_cb_; |
| 180 | 180 |
| 181 base::TimeDelta seek_timestamp_; | 181 base::TimeDelta seek_timestamp_; |
| 182 | 182 |
| 183 uint32 bytes_per_frame_; | 183 uint32 bytes_per_frame_; |
| 184 | 184 |
| 185 // Used to calculate audio delay given bytes. | 185 // Used to calculate audio delay given bytes. |
| 186 uint32 bytes_per_second_; | 186 uint32 bytes_per_second_; |
| 187 | 187 |
| 188 // A flag that indicates this filter is called to stop. | 188 // A flag that indicates this filter is called to stop. |
| 189 bool stopped_; | 189 bool stopped_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 215 bool underflow_disabled_; | 215 bool underflow_disabled_; |
| 216 | 216 |
| 217 AudioDecoder::ReadCB read_cb_; | 217 AudioDecoder::ReadCB read_cb_; |
| 218 | 218 |
| 219 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 219 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 } // namespace media | 222 } // namespace media |
| 223 | 223 |
| 224 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 224 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |