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 AudioRendererImpl(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 56 AudioRendererImpl( |
57 AudioRendererSink* sink, | 57 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
58 ScopedVector<AudioDecoder> decoders, | 58 AudioRendererSink* sink, |
59 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 59 ScopedVector<AudioDecoder> decoders, |
| 60 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
60 virtual ~AudioRendererImpl(); | 61 virtual ~AudioRendererImpl(); |
61 | 62 |
62 // AudioRenderer implementation. | 63 // AudioRenderer implementation. |
63 virtual void Initialize(DemuxerStream* stream, | 64 virtual void Initialize(DemuxerStream* stream, |
64 const PipelineStatusCB& init_cb, | 65 const PipelineStatusCB& init_cb, |
65 const StatisticsCB& statistics_cb, | 66 const StatisticsCB& statistics_cb, |
66 const base::Closure& underflow_cb, | 67 const base::Closure& underflow_cb, |
67 const TimeCB& time_cb, | 68 const TimeCB& time_cb, |
68 const base::Closure& ended_cb, | 69 const base::Closure& ended_cb, |
69 const base::Closure& disabled_cb, | 70 const base::Closure& disabled_cb, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // timestamp in the pipeline will be ahead of the actual audio playback. In | 145 // timestamp in the pipeline will be ahead of the actual audio playback. In |
145 // this case |audio_delay_milliseconds| should be used to indicate when in the | 146 // this case |audio_delay_milliseconds| should be used to indicate when in the |
146 // future should the filled buffer be played. | 147 // future should the filled buffer be played. |
147 virtual int Render(AudioBus* audio_bus, | 148 virtual int Render(AudioBus* audio_bus, |
148 int audio_delay_milliseconds) OVERRIDE; | 149 int audio_delay_milliseconds) OVERRIDE; |
149 virtual void OnRenderError() OVERRIDE; | 150 virtual void OnRenderError() OVERRIDE; |
150 | 151 |
151 // Helper methods that schedule an asynchronous read from the decoder as long | 152 // Helper methods that schedule an asynchronous read from the decoder as long |
152 // as there isn't a pending read. | 153 // as there isn't a pending read. |
153 // | 154 // |
154 // Must be called on |message_loop_|. | 155 // Must be called on |task_runner_|. |
155 void AttemptRead(); | 156 void AttemptRead(); |
156 void AttemptRead_Locked(); | 157 void AttemptRead_Locked(); |
157 bool CanRead_Locked(); | 158 bool CanRead_Locked(); |
158 void ChangeState_Locked(State new_state); | 159 void ChangeState_Locked(State new_state); |
159 | 160 |
160 // Returns true if the data in the buffer is all before | 161 // Returns true if the data in the buffer is all before |
161 // |preroll_timestamp_|. This can only return true while | 162 // |preroll_timestamp_|. This can only return true while |
162 // in the kPrerolling state. | 163 // in the kPrerolling state. |
163 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); | 164 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); |
164 | 165 |
(...skipping 10 matching lines...) Expand all Loading... |
175 // completed. | 176 // completed. |
176 void DoFlush_Locked(); | 177 void DoFlush_Locked(); |
177 | 178 |
178 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get | 179 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get |
179 // called when the reset completes. | 180 // called when the reset completes. |
180 void ResetDecoder(); | 181 void ResetDecoder(); |
181 | 182 |
182 // Called when the |decoder_|.Reset() has completed. | 183 // Called when the |decoder_|.Reset() has completed. |
183 void ResetDecoderDone(); | 184 void ResetDecoderDone(); |
184 | 185 |
185 scoped_refptr<base::MessageLoopProxy> message_loop_; | 186 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
186 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 187 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
187 base::WeakPtr<AudioRendererImpl> weak_this_; | 188 base::WeakPtr<AudioRendererImpl> weak_this_; |
188 | 189 |
189 scoped_ptr<AudioSplicer> splicer_; | 190 scoped_ptr<AudioSplicer> splicer_; |
190 | 191 |
191 // The sink (destination) for rendered audio. |sink_| must only be accessed | 192 // The sink (destination) for rendered audio. |sink_| must only be accessed |
192 // on |message_loop_|. |sink_| must never be called under |lock_| or else we | 193 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
193 // may deadlock between |message_loop_| and the audio callback thread. | 194 // may deadlock between |task_runner_| and the audio callback thread. |
194 scoped_refptr<media::AudioRendererSink> sink_; | 195 scoped_refptr<media::AudioRendererSink> sink_; |
195 | 196 |
196 scoped_ptr<AudioDecoderSelector> decoder_selector_; | 197 scoped_ptr<AudioDecoderSelector> decoder_selector_; |
197 | 198 |
198 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). | 199 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). |
199 scoped_ptr<AudioDecoder> decoder_; | 200 scoped_ptr<AudioDecoder> decoder_; |
200 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | 201 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; |
201 | 202 |
202 // AudioParameters constructed during Initialize() based on |decoder_|. | 203 // AudioParameters constructed during Initialize() based on |decoder_|. |
203 AudioParameters audio_parameters_; | 204 AudioParameters audio_parameters_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 bool preroll_aborted_; | 272 bool preroll_aborted_; |
272 | 273 |
273 // End variables which must be accessed under |lock_|. ---------------------- | 274 // End variables which must be accessed under |lock_|. ---------------------- |
274 | 275 |
275 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 276 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
276 }; | 277 }; |
277 | 278 |
278 } // namespace media | 279 } // namespace media |
279 | 280 |
280 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 281 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |