| 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 13 matching lines...) Expand all Loading... |
| 24 #include "base/gtest_prod_util.h" | 24 #include "base/gtest_prod_util.h" |
| 25 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
| 26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
| 27 #include "media/base/audio_decoder.h" | 27 #include "media/base/audio_decoder.h" |
| 28 #include "media/base/audio_renderer.h" | 28 #include "media/base/audio_renderer.h" |
| 29 #include "media/base/audio_renderer_sink.h" | 29 #include "media/base/audio_renderer_sink.h" |
| 30 #include "media/base/decryptor.h" | 30 #include "media/base/decryptor.h" |
| 31 #include "media/filters/audio_renderer_algorithm.h" | 31 #include "media/filters/audio_renderer_algorithm.h" |
| 32 | 32 |
| 33 namespace base { | 33 namespace base { |
| 34 class MessageLoopProxy; | 34 class SingleThreadTaskRunner; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace media { | 37 namespace media { |
| 38 | 38 |
| 39 class AudioBus; | 39 class AudioBus; |
| 40 class AudioDecoderSelector; | 40 class AudioDecoderSelector; |
| 41 class AudioSplicer; | 41 class AudioSplicer; |
| 42 class DecryptingDemuxerStream; | 42 class DecryptingDemuxerStream; |
| 43 | 43 |
| 44 class MEDIA_EXPORT AudioRendererImpl | 44 class MEDIA_EXPORT AudioRendererImpl |
| 45 : public AudioRenderer, | 45 : public AudioRenderer, |
| 46 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 46 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 47 public: | 47 public: |
| 48 // |message_loop| is the thread on which AudioRendererImpl will execute. | 48 // |task_runner| is the thread on which AudioRendererImpl will execute. |
| 49 // | 49 // |
| 50 // |sink| is used as the destination for the rendered audio. | 50 // |sink| is used as the destination for the rendered audio. |
| 51 // | 51 // |
| 52 // |decoders| contains the AudioDecoders to use when initializing. | 52 // |decoders| contains the AudioDecoders to use when initializing. |
| 53 // | 53 // |
| 54 // |set_decryptor_ready_cb| is fired when the audio decryptor is available | 54 // |set_decryptor_ready_cb| is fired when the audio decryptor is available |
| 55 // (only applicable if the stream is encrypted and we have a decryptor). | 55 // (only applicable if the stream is encrypted and we have a decryptor). |
| 56 // | 56 // |
| 57 // |increase_preroll_on_underflow| Set to true if the preroll duration | 57 // |increase_preroll_on_underflow| Set to true if the preroll duration |
| 58 // should be increased when ResumeAfterUnderflow() is called. | 58 // should be increased when ResumeAfterUnderflow() is called. |
| 59 AudioRendererImpl(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 59 AudioRendererImpl( |
| 60 AudioRendererSink* sink, | 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 61 ScopedVector<AudioDecoder> decoders, | 61 AudioRendererSink* sink, |
| 62 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 62 ScopedVector<AudioDecoder> decoders, |
| 63 bool increase_preroll_on_underflow); | 63 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 64 bool increase_preroll_on_underflow); |
| 64 virtual ~AudioRendererImpl(); | 65 virtual ~AudioRendererImpl(); |
| 65 | 66 |
| 66 // AudioRenderer implementation. | 67 // AudioRenderer implementation. |
| 67 virtual void Initialize(DemuxerStream* stream, | 68 virtual void Initialize(DemuxerStream* stream, |
| 68 const PipelineStatusCB& init_cb, | 69 const PipelineStatusCB& init_cb, |
| 69 const StatisticsCB& statistics_cb, | 70 const StatisticsCB& statistics_cb, |
| 70 const base::Closure& underflow_cb, | 71 const base::Closure& underflow_cb, |
| 71 const TimeCB& time_cb, | 72 const TimeCB& time_cb, |
| 72 const base::Closure& ended_cb, | 73 const base::Closure& ended_cb, |
| 73 const base::Closure& disabled_cb, | 74 const base::Closure& disabled_cb, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // timestamp in the pipeline will be ahead of the actual audio playback. In | 147 // timestamp in the pipeline will be ahead of the actual audio playback. In |
| 147 // this case |audio_delay_milliseconds| should be used to indicate when in the | 148 // this case |audio_delay_milliseconds| should be used to indicate when in the |
| 148 // future should the filled buffer be played. | 149 // future should the filled buffer be played. |
| 149 virtual int Render(AudioBus* audio_bus, | 150 virtual int Render(AudioBus* audio_bus, |
| 150 int audio_delay_milliseconds) OVERRIDE; | 151 int audio_delay_milliseconds) OVERRIDE; |
| 151 virtual void OnRenderError() OVERRIDE; | 152 virtual void OnRenderError() OVERRIDE; |
| 152 | 153 |
| 153 // Helper methods that schedule an asynchronous read from the decoder as long | 154 // Helper methods that schedule an asynchronous read from the decoder as long |
| 154 // as there isn't a pending read. | 155 // as there isn't a pending read. |
| 155 // | 156 // |
| 156 // Must be called on |message_loop_|. | 157 // Must be called on |task_runner_|. |
| 157 void AttemptRead(); | 158 void AttemptRead(); |
| 158 void AttemptRead_Locked(); | 159 void AttemptRead_Locked(); |
| 159 bool CanRead_Locked(); | 160 bool CanRead_Locked(); |
| 160 void ChangeState_Locked(State new_state); | 161 void ChangeState_Locked(State new_state); |
| 161 | 162 |
| 162 // Returns true if the data in the buffer is all before | 163 // Returns true if the data in the buffer is all before |
| 163 // |preroll_timestamp_|. This can only return true while | 164 // |preroll_timestamp_|. This can only return true while |
| 164 // in the kPrerolling state. | 165 // in the kPrerolling state. |
| 165 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); | 166 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); |
| 166 | 167 |
| 167 // Called when |decoder_selector_| has selected |decoder| or is null if no | 168 // Called when |decoder_selector_| has selected |decoder| or is null if no |
| 168 // decoder could be selected. | 169 // decoder could be selected. |
| 169 // | 170 // |
| 170 // |decrypting_demuxer_stream| is non-null if a DecryptingDemuxerStream was | 171 // |decrypting_demuxer_stream| is non-null if a DecryptingDemuxerStream was |
| 171 // created to help decrypt the encrypted stream. | 172 // created to help decrypt the encrypted stream. |
| 172 void OnDecoderSelected( | 173 void OnDecoderSelected( |
| 173 scoped_ptr<AudioDecoder> decoder, | 174 scoped_ptr<AudioDecoder> decoder, |
| 174 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); | 175 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); |
| 175 | 176 |
| 176 void ResetDecoder(const base::Closure& callback); | 177 void ResetDecoder(const base::Closure& callback); |
| 177 | 178 |
| 178 scoped_refptr<base::MessageLoopProxy> message_loop_; | 179 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 179 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 180 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
| 180 base::WeakPtr<AudioRendererImpl> weak_this_; | 181 base::WeakPtr<AudioRendererImpl> weak_this_; |
| 181 | 182 |
| 182 scoped_ptr<AudioSplicer> splicer_; | 183 scoped_ptr<AudioSplicer> splicer_; |
| 183 | 184 |
| 184 // The sink (destination) for rendered audio. |sink_| must only be accessed | 185 // The sink (destination) for rendered audio. |sink_| must only be accessed |
| 185 // on |message_loop_|. |sink_| must never be called under |lock_| or else we | 186 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
| 186 // may deadlock between |message_loop_| and the audio callback thread. | 187 // may deadlock between |task_runner_| and the audio callback thread. |
| 187 scoped_refptr<media::AudioRendererSink> sink_; | 188 scoped_refptr<media::AudioRendererSink> sink_; |
| 188 | 189 |
| 189 scoped_ptr<AudioDecoderSelector> decoder_selector_; | 190 scoped_ptr<AudioDecoderSelector> decoder_selector_; |
| 190 | 191 |
| 191 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). | 192 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). |
| 192 scoped_ptr<AudioDecoder> decoder_; | 193 scoped_ptr<AudioDecoder> decoder_; |
| 193 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | 194 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; |
| 194 | 195 |
| 195 // AudioParameters constructed during Initialize() based on |decoder_|. | 196 // AudioParameters constructed during Initialize() based on |decoder_|. |
| 196 AudioParameters audio_parameters_; | 197 AudioParameters audio_parameters_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 bool preroll_aborted_; | 266 bool preroll_aborted_; |
| 266 | 267 |
| 267 // End variables which must be accessed under |lock_|. ---------------------- | 268 // End variables which must be accessed under |lock_|. ---------------------- |
| 268 | 269 |
| 269 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 270 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 270 }; | 271 }; |
| 271 | 272 |
| 272 } // namespace media | 273 } // namespace media |
| 273 | 274 |
| 274 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 275 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |