Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: media/filters/audio_renderer_impl.h

Issue 10918022: Move AudioDecoder initialization into AudioRenderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
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 // AudioRenderer implementation. 43 // AudioRenderer implementation.
44 virtual void Initialize(const scoped_refptr<AudioDecoder>& decoder, 44 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream,
45 const AudioDecoderList& decoders,
45 const PipelineStatusCB& init_cb, 46 const PipelineStatusCB& init_cb,
47 const StatisticsCB& statistics_cb,
46 const base::Closure& underflow_cb, 48 const base::Closure& underflow_cb,
47 const TimeCB& time_cb, 49 const TimeCB& time_cb,
48 const base::Closure& ended_cb, 50 const base::Closure& ended_cb,
49 const base::Closure& disabled_cb, 51 const base::Closure& disabled_cb,
50 const PipelineStatusCB& error_cb) OVERRIDE; 52 const PipelineStatusCB& error_cb) OVERRIDE;
51 virtual void Play(const base::Closure& callback) OVERRIDE; 53 virtual void Play(const base::Closure& callback) OVERRIDE;
52 virtual void Pause(const base::Closure& callback) OVERRIDE; 54 virtual void Pause(const base::Closure& callback) OVERRIDE;
53 virtual void Flush(const base::Closure& callback) OVERRIDE; 55 virtual void Flush(const base::Closure& callback) OVERRIDE;
54 virtual void Stop(const base::Closure& callback) OVERRIDE; 56 virtual void Stop(const base::Closure& callback) OVERRIDE;
55 virtual void SetPlaybackRate(float rate) OVERRIDE; 57 virtual void SetPlaybackRate(float rate) OVERRIDE;
56 virtual void Preroll(base::TimeDelta time, 58 virtual void Preroll(base::TimeDelta time,
57 const PipelineStatusCB& cb) OVERRIDE; 59 const PipelineStatusCB& cb) OVERRIDE;
58 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE; 60 virtual void ResumeAfterUnderflow(bool buffer_more_audio) OVERRIDE;
59 virtual void SetVolume(float volume) OVERRIDE; 61 virtual void SetVolume(float volume) OVERRIDE;
60 62
61 // Disables underflow support. When used, |state_| will never transition to 63 // Disables underflow support. When used, |state_| will never transition to
62 // kUnderflow resulting in Render calls that underflow returning 0 frames 64 // kUnderflow resulting in Render calls that underflow returning 0 frames
63 // instead of some number of silence frames. Must be called prior to 65 // instead of some number of silence frames. Must be called prior to
64 // Initialize(). 66 // Initialize().
65 void DisableUnderflowForTesting(); 67 void DisableUnderflowForTesting();
66 68
67 protected: 69 protected:
68 virtual ~AudioRendererImpl(); 70 virtual ~AudioRendererImpl();
69 71
70 private: 72 private:
71 friend class AudioRendererImplTest; 73 friend class AudioRendererImplTest;
72 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, EndOfStream); 74 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, EndOfStream);
73 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Underflow_EndOfStream); 75 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Underflow_EndOfStream);
74 76
77 // Pops the front of |decoders|, assigns it to |decoder_| and then
78 // calls initialize on the new decoder.
79 void InitializeNextDecoder(const scoped_refptr<DemuxerStream>& demuxer_stream,
80 scoped_ptr<AudioDecoderList> decoders);
81
82 // Called when |decoder_| initialization completes.
83 // |demuxer_stream| & |decoders| are used if initialization failed and
84 // InitializeNextDecoder() needs to be called again.
85 void OnDecoderInitDone(const scoped_refptr<DemuxerStream>& demuxer_stream,
86 scoped_ptr<AudioDecoderList> decoders,
87 PipelineStatus status);
88
75 // Callback from the audio decoder delivering decoded audio samples. 89 // Callback from the audio decoder delivering decoded audio samples.
76 void DecodedAudioReady(AudioDecoder::Status status, 90 void DecodedAudioReady(AudioDecoder::Status status,
77 const scoped_refptr<Buffer>& buffer); 91 const scoped_refptr<Buffer>& buffer);
78 92
79 // Helper functions for AudioDecoder::Status values passed to 93 // Helper functions for AudioDecoder::Status values passed to
80 // DecodedAudioReady(). 94 // DecodedAudioReady().
81 void HandleAbortedReadOrDecodeError(bool is_decode_error); 95 void HandleAbortedReadOrDecodeError(bool is_decode_error);
82 96
83 // Fills the given buffer with audio data by delegating to its |algorithm_|. 97 // Fills the given buffer with audio data by delegating to its |algorithm_|.
84 // FillBuffer() also takes care of updating the clock. Returns the number of 98 // FillBuffer() also takes care of updating the clock. Returns the number of
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 177
164 // The timestamp of the last frame (i.e. furthest in the future) buffered as 178 // The timestamp of the last frame (i.e. furthest in the future) buffered as
165 // well as the current time that takes current playback delay into account. 179 // well as the current time that takes current playback delay into account.
166 base::TimeDelta audio_time_buffered_; 180 base::TimeDelta audio_time_buffered_;
167 base::TimeDelta current_time_; 181 base::TimeDelta current_time_;
168 182
169 // Filter callbacks. 183 // Filter callbacks.
170 base::Closure pause_cb_; 184 base::Closure pause_cb_;
171 PipelineStatusCB preroll_cb_; 185 PipelineStatusCB preroll_cb_;
172 186
187 PipelineStatusCB init_cb_;
188 StatisticsCB statistics_cb_;
173 base::Closure underflow_cb_; 189 base::Closure underflow_cb_;
174 TimeCB time_cb_; 190 TimeCB time_cb_;
175 base::Closure ended_cb_; 191 base::Closure ended_cb_;
176 base::Closure disabled_cb_; 192 base::Closure disabled_cb_;
177 PipelineStatusCB error_cb_; 193 PipelineStatusCB error_cb_;
178 194
179 base::TimeDelta preroll_timestamp_; 195 base::TimeDelta preroll_timestamp_;
180 196
181 uint32 bytes_per_frame_; 197 uint32 bytes_per_frame_;
182 198
183 // Used to calculate audio delay given bytes.
184 uint32 bytes_per_second_;
185
186 // A flag that indicates this filter is called to stop. 199 // A flag that indicates this filter is called to stop.
187 bool stopped_; 200 bool stopped_;
188 201
189 // The sink (destination) for rendered audio. 202 // The sink (destination) for rendered audio.
190 scoped_refptr<media::AudioRendererSink> sink_; 203 scoped_refptr<media::AudioRendererSink> sink_;
191 204
192 // Set to true when OnInitialize() is called. 205 // Set to true when OnInitialize() is called.
193 bool is_initialized_; 206 bool is_initialized_;
194 207
195 // We're supposed to know amount of audio data OS or hardware buffered, but 208 // We're supposed to know amount of audio data OS or hardware buffered, but
(...skipping 15 matching lines...) Expand all
211 AudioParameters audio_parameters_; 224 AudioParameters audio_parameters_;
212 225
213 bool underflow_disabled_; 226 bool underflow_disabled_;
214 227
215 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 228 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
216 }; 229 };
217 230
218 } // namespace media 231 } // namespace media
219 232
220 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ 233 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698