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 |
11 // Initialize() is called here with the audio format. | 11 // Initialize() is called here with the audio format. |
12 // Play/Pause/Preroll() also happens here. | 12 // Play/Pause/Preroll() also happens here. |
13 // 3. Audio thread created by the AudioRendererSink. | 13 // 3. Audio thread created by the AudioRendererSink. |
14 // Render() is called here where audio data is decoded into raw PCM data. | 14 // Render() is called here where audio data is decoded into raw PCM data. |
15 // | 15 // |
16 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of | 16 // AudioRendererImpl talks to an AudioRendererAlgorithm that takes care of |
17 // queueing audio data and stretching/shrinking audio data when playback rate != | 17 // queueing audio data and stretching/shrinking audio data when playback rate != |
18 // 1.0 or 0.0. | 18 // 1.0 or 0.0. |
19 | 19 |
20 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 20 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
21 #define MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 21 #define MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
22 | 22 |
23 #include <deque> | 23 #include <deque> |
24 | 24 |
25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
26 #include "base/threading/thread_checker.h" | |
26 #include "media/base/audio_decoder.h" | 27 #include "media/base/audio_decoder.h" |
27 #include "media/base/audio_renderer.h" | 28 #include "media/base/audio_renderer.h" |
28 #include "media/base/audio_renderer_sink.h" | 29 #include "media/base/audio_renderer_sink.h" |
29 #include "media/base/buffers.h" | 30 #include "media/base/buffers.h" |
30 #include "media/filters/audio_renderer_algorithm.h" | 31 #include "media/filters/audio_renderer_algorithm.h" |
31 | 32 |
32 namespace media { | 33 namespace media { |
33 | 34 |
34 class MEDIA_EXPORT AudioRendererImpl | 35 class MEDIA_EXPORT AudioRendererImpl |
35 : public AudioRenderer, | 36 : public AudioRenderer, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 base::Closure underflow_cb_; | 191 base::Closure underflow_cb_; |
191 TimeCB time_cb_; | 192 TimeCB time_cb_; |
192 base::Closure ended_cb_; | 193 base::Closure ended_cb_; |
193 base::Closure disabled_cb_; | 194 base::Closure disabled_cb_; |
194 PipelineStatusCB error_cb_; | 195 PipelineStatusCB error_cb_; |
195 | 196 |
196 base::TimeDelta preroll_timestamp_; | 197 base::TimeDelta preroll_timestamp_; |
197 | 198 |
198 uint32 bytes_per_frame_; | 199 uint32 bytes_per_frame_; |
199 | 200 |
200 // A flag that indicates this filter is called to stop. | 201 // A flag that indicates this filter is called to stop. |
Ami GONE FROM CHROMIUM
2012/11/01 19:57:01
doco that this must be only read/written on pipeli
DaleCurtis
2012/11/01 22:02:59
Removed.
| |
201 bool stopped_; | 202 bool stopped_; |
Ami GONE FROM CHROMIUM
2012/11/01 19:57:01
Might be worthwhile to drop stopped_ in favor of c
DaleCurtis
2012/11/01 22:02:59
Done. The new patch set relies on nothing else bei
| |
202 | 203 |
203 // The sink (destination) for rendered audio. | 204 // The sink (destination) for rendered audio. |sink_| must only be accessed |
205 // on the pipeline thread (verify with |pipeline_thread_checker_|). |sink_| | |
206 // must never be called under |lock_| or the 3-way thread bridge between the | |
207 // audio, pipeline, and decoder threads may dead lock. | |
204 scoped_refptr<media::AudioRendererSink> sink_; | 208 scoped_refptr<media::AudioRendererSink> sink_; |
205 | 209 |
206 // We're supposed to know amount of audio data OS or hardware buffered, but | 210 // We're supposed to know amount of audio data OS or hardware buffered, but |
207 // that is not always so -- on my Linux box | 211 // that is not always so -- on my Linux box |
208 // AudioBuffersState::hardware_delay_bytes never reaches 0. | 212 // AudioBuffersState::hardware_delay_bytes never reaches 0. |
209 // | 213 // |
210 // As a result we cannot use it to find when stream ends. If we just ignore | 214 // As a result we cannot use it to find when stream ends. If we just ignore |
211 // buffered data we will notify host that stream ended before it is actually | 215 // buffered data we will notify host that stream ended before it is actually |
212 // did so, I've seen it done ~140ms too early when playing ~150ms file. | 216 // did so, I've seen it done ~140ms too early when playing ~150ms file. |
213 // | 217 // |
214 // Instead of trying to invent OS-specific solution for each and every OS we | 218 // Instead of trying to invent OS-specific solution for each and every OS we |
215 // are supporting, use simple workaround: every time we fill the buffer we | 219 // are supporting, use simple workaround: every time we fill the buffer we |
216 // remember when it should stop playing, and do not assume that buffer is | 220 // remember when it should stop playing, and do not assume that buffer is |
217 // empty till that time. Workaround is not bulletproof, as we don't exactly | 221 // empty till that time. Workaround is not bulletproof, as we don't exactly |
218 // know when that particular data would start playing, but it is much better | 222 // know when that particular data would start playing, but it is much better |
219 // than nothing. | 223 // than nothing. |
220 base::Time earliest_end_time_; | 224 base::Time earliest_end_time_; |
221 | 225 |
222 AudioParameters audio_parameters_; | 226 AudioParameters audio_parameters_; |
223 | 227 |
224 bool underflow_disabled_; | 228 bool underflow_disabled_; |
225 | 229 |
226 // True if the renderer receives a buffer with kAborted status during preroll, | 230 // True if the renderer receives a buffer with kAborted status during preroll, |
227 // false otherwise. This flag is cleared on the next Preroll() call. | 231 // false otherwise. This flag is cleared on the next Preroll() call. |
228 bool preroll_aborted_; | 232 bool preroll_aborted_; |
229 | 233 |
234 // Ensures certain methods are always called on the pipeline thread. | |
235 base::ThreadChecker pipeline_thread_checker_; | |
236 | |
230 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 237 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
231 }; | 238 }; |
232 | 239 |
233 } // namespace media | 240 } // namespace media |
234 | 241 |
235 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ | 242 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ |
OLD | NEW |