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 11 matching lines...) Expand all Loading... |
22 #include <deque> | 22 #include <deque> |
23 | 23 |
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 #include "media/filters/decoder_selector.h" | 32 #include "media/filters/decoder_stream.h" |
33 | 33 |
34 namespace base { | 34 namespace base { |
35 class SingleThreadTaskRunner; | 35 class SingleThreadTaskRunner; |
36 } | 36 } |
37 | 37 |
38 namespace media { | 38 namespace media { |
39 | 39 |
40 class AudioBus; | 40 class AudioBus; |
41 class AudioSplicer; | 41 class AudioSplicer; |
42 class DecryptingDemuxerStream; | 42 class DecryptingDemuxerStream; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 kPaused, | 101 kPaused, |
102 kFlushing, | 102 kFlushing, |
103 kPrerolling, | 103 kPrerolling, |
104 kPlaying, | 104 kPlaying, |
105 kStopped, | 105 kStopped, |
106 kUnderflow, | 106 kUnderflow, |
107 kRebuffering, | 107 kRebuffering, |
108 }; | 108 }; |
109 | 109 |
110 // Callback from the audio decoder delivering decoded audio samples. | 110 // Callback from the audio decoder delivering decoded audio samples. |
111 void DecodedAudioReady(AudioDecoder::Status status, | 111 void DecodedAudioReady(AudioBufferStream::Status status, |
112 const scoped_refptr<AudioBuffer>& buffer); | 112 const scoped_refptr<AudioBuffer>& buffer); |
113 | 113 |
114 // Handles buffers that come out of |splicer_|. | 114 // Handles buffers that come out of |splicer_|. |
115 // Returns true if more buffers are needed. | 115 // Returns true if more buffers are needed. |
116 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer); | 116 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer); |
117 | 117 |
118 // Helper functions for AudioDecoder::Status values passed to | 118 // Helper functions for AudioDecoder::Status values passed to |
119 // DecodedAudioReady(). | 119 // DecodedAudioReady(). |
120 void HandleAbortedReadOrDecodeError(bool is_decode_error); | 120 void HandleAbortedReadOrDecodeError(bool is_decode_error); |
121 | 121 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Returns true if the data in the buffer is all before | 162 // Returns true if the data in the buffer is all before |
163 // |preroll_timestamp_|. This can only return true while | 163 // |preroll_timestamp_|. This can only return true while |
164 // in the kPrerolling state. | 164 // in the kPrerolling state. |
165 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); | 165 bool IsBeforePrerollTime(const scoped_refptr<AudioBuffer>& buffer); |
166 | 166 |
167 // Called when |decoder_selector_| has selected |decoder| or is null if no | 167 // Called when |decoder_selector_| has selected |decoder| or is null if no |
168 // decoder could be selected. | 168 // decoder could be selected. |
169 // | 169 // |
170 // |decrypting_demuxer_stream| is non-null if a DecryptingDemuxerStream was | 170 // |decrypting_demuxer_stream| is non-null if a DecryptingDemuxerStream was |
171 // created to help decrypt the encrypted stream. | 171 // created to help decrypt the encrypted stream. |
172 void OnDecoderSelected( | 172 void OnAudioBufferStreamInitialized(bool succes); |
173 scoped_ptr<AudioDecoder> decoder, | |
174 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); | |
175 | 173 |
176 // Used to initiate the flush operation once all pending reads have | 174 // Used to initiate the flush operation once all pending reads have |
177 // completed. | 175 // completed. |
178 void DoFlush_Locked(); | 176 void DoFlush_Locked(); |
179 | 177 |
180 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get | 178 // Calls |decoder_|.Reset() and arranges for ResetDecoderDone() to get |
181 // called when the reset completes. | 179 // called when the reset completes. |
182 void ResetDecoder(); | 180 void ResetDecoder(); |
183 | 181 |
184 // Called when the |decoder_|.Reset() has completed. | 182 // Called when the |decoder_|.Reset() has completed. |
185 void ResetDecoderDone(); | 183 void ResetDecoderDone(); |
186 | 184 |
187 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 185 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
188 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; | 186 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; |
189 base::WeakPtr<AudioRendererImpl> weak_this_; | 187 base::WeakPtr<AudioRendererImpl> weak_this_; |
190 | 188 |
191 scoped_ptr<AudioSplicer> splicer_; | 189 scoped_ptr<AudioSplicer> splicer_; |
192 | 190 |
193 // The sink (destination) for rendered audio. |sink_| must only be accessed | 191 // The sink (destination) for rendered audio. |sink_| must only be accessed |
194 // on |task_runner_|. |sink_| must never be called under |lock_| or else we | 192 // on |task_runner_|. |sink_| must never be called under |lock_| or else we |
195 // may deadlock between |task_runner_| and the audio callback thread. | 193 // may deadlock between |task_runner_| and the audio callback thread. |
196 scoped_refptr<media::AudioRendererSink> sink_; | 194 scoped_refptr<media::AudioRendererSink> sink_; |
197 | 195 |
198 scoped_ptr<AudioDecoderSelector> decoder_selector_; | 196 AudioBufferStream audio_buffer_stream_; |
199 | 197 |
200 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). | 198 // These two will be set by AudioDecoderSelector::SelectAudioDecoder(). |
201 scoped_ptr<AudioDecoder> decoder_; | 199 scoped_ptr<AudioDecoder> decoder_; |
202 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | 200 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; |
203 | 201 |
204 // AudioParameters constructed during Initialize() based on |decoder_|. | 202 // AudioParameters constructed during Initialize() based on |decoder_|. |
205 AudioParameters audio_parameters_; | 203 AudioParameters audio_parameters_; |
206 | 204 |
207 // Callbacks provided during Initialize(). | 205 // Callbacks provided during Initialize(). |
208 PipelineStatusCB init_cb_; | 206 PipelineStatusCB init_cb_; |
209 StatisticsCB statistics_cb_; | |
210 base::Closure underflow_cb_; | 207 base::Closure underflow_cb_; |
211 TimeCB time_cb_; | 208 TimeCB time_cb_; |
212 base::Closure ended_cb_; | 209 base::Closure ended_cb_; |
213 base::Closure disabled_cb_; | 210 base::Closure disabled_cb_; |
214 PipelineStatusCB error_cb_; | 211 PipelineStatusCB error_cb_; |
215 | 212 |
216 // Callback provided to Flush(). | 213 // Callback provided to Flush(). |
217 base::Closure flush_cb_; | 214 base::Closure flush_cb_; |
218 | 215 |
219 // Callback provided to Stop(). | 216 // Callback provided to Stop(). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 bool preroll_aborted_; | 273 bool preroll_aborted_; |
277 | 274 |
278 // End variables which must be accessed under |lock_|. ---------------------- | 275 // End variables which must be accessed under |lock_|. ---------------------- |
279 | 276 |
280 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 277 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
281 }; | 278 }; |
282 | 279 |
283 } // namespace media | 280 } // namespace media |
284 | 281 |
285 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 282 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |