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

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

Issue 277123002: Rename AudioRenderer::Play/Pause() to Start/StopRendering(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
« no previous file with comments | « media/base/pipeline_unittest.cc ('k') | media/filters/audio_renderer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 virtual ~AudioRendererImpl(); 65 virtual ~AudioRendererImpl();
66 66
67 // AudioRenderer implementation. 67 // AudioRenderer implementation.
68 virtual void Initialize(DemuxerStream* stream, 68 virtual void Initialize(DemuxerStream* stream,
69 const PipelineStatusCB& init_cb, 69 const PipelineStatusCB& init_cb,
70 const StatisticsCB& statistics_cb, 70 const StatisticsCB& statistics_cb,
71 const base::Closure& underflow_cb, 71 const base::Closure& underflow_cb,
72 const TimeCB& time_cb, 72 const TimeCB& time_cb,
73 const base::Closure& ended_cb, 73 const base::Closure& ended_cb,
74 const PipelineStatusCB& error_cb) OVERRIDE; 74 const PipelineStatusCB& error_cb) OVERRIDE;
75 virtual void Play() OVERRIDE; 75 virtual void StartRendering() OVERRIDE;
76 virtual void Pause() OVERRIDE; 76 virtual void StopRendering() OVERRIDE;
77 virtual void Flush(const base::Closure& callback) OVERRIDE; 77 virtual void Flush(const base::Closure& callback) OVERRIDE;
78 virtual void Stop(const base::Closure& callback) OVERRIDE; 78 virtual void Stop(const base::Closure& callback) OVERRIDE;
79 virtual void SetPlaybackRate(float rate) OVERRIDE; 79 virtual void SetPlaybackRate(float rate) OVERRIDE;
80 virtual void Preroll(base::TimeDelta time, 80 virtual void Preroll(base::TimeDelta time,
81 const PipelineStatusCB& cb) OVERRIDE; 81 const PipelineStatusCB& cb) OVERRIDE;
82 virtual void ResumeAfterUnderflow() OVERRIDE; 82 virtual void ResumeAfterUnderflow() OVERRIDE;
83 virtual void SetVolume(float volume) OVERRIDE; 83 virtual void SetVolume(float volume) OVERRIDE;
84 84
85 // Disables underflow support. When used, |state_| will never transition to 85 // Disables underflow support. When used, |state_| will never transition to
86 // kUnderflow resulting in Render calls that underflow returning 0 frames 86 // kUnderflow resulting in Render calls that underflow returning 0 frames
87 // instead of some number of silence frames. Must be called prior to 87 // instead of some number of silence frames. Must be called prior to
88 // Initialize(). 88 // Initialize().
89 void DisableUnderflowForTesting(); 89 void DisableUnderflowForTesting();
90 90
91 // Allows injection of a custom time callback for non-realtime testing. 91 // Allows injection of a custom time callback for non-realtime testing.
92 typedef base::Callback<base::TimeTicks()> NowCB; 92 typedef base::Callback<base::TimeTicks()> NowCB;
93 void set_now_cb_for_testing(const NowCB& now_cb) { 93 void set_now_cb_for_testing(const NowCB& now_cb) {
94 now_cb_ = now_cb; 94 now_cb_ = now_cb;
95 } 95 }
96 96
97 private: 97 private:
98 friend class AudioRendererImplTest; 98 friend class AudioRendererImplTest;
99 99
100 // TODO(acolwell): Add a state machine graph. 100 // Important detail: being in kPlaying doesn't imply that audio is being
101 // rendered. Rather, it means that the renderer is ready to go. The actual
102 // rendering of audio is controlled via Start/StopRendering().
103 //
104 // kUninitialized
105 // | Initialize()
106 // |
107 // V
108 // kInitializing
109 // | Decoders initialized
110 // |
111 // V Decoders reset
112 // kFlushed <------------------ kFlushing
113 // | Preroll() ^
114 // | |
115 // V | Flush()
116 // kPrerolling ----------------> kPlaying ---------.
117 // Enough data buffered ^ | Not enough data
118 // | | buffered
119 // Enough data buffered | V
120 // kRebuffering <--- kUnderflow
121 // ResumeAfterUnderflow()
101 enum State { 122 enum State {
102 kUninitialized, 123 kUninitialized,
103 kInitializing, 124 kInitializing,
104 kPaused,
105 kFlushing, 125 kFlushing,
126 kFlushed,
106 kPrerolling, 127 kPrerolling,
107 kPlaying, 128 kPlaying,
108 kStopped, 129 kStopped,
109 kUnderflow, 130 kUnderflow,
110 kRebuffering, 131 kRebuffering,
111 }; 132 };
112 133
113 // Callback from the audio decoder delivering decoded audio samples. 134 // Callback from the audio decoder delivering decoded audio samples.
114 void DecodedAudioReady(AudioBufferStream::Status status, 135 void DecodedAudioReady(AudioBufferStream::Status status,
115 const scoped_refptr<AudioBuffer>& buffer); 136 const scoped_refptr<AudioBuffer>& buffer);
116 137
117 // Handles buffers that come out of |splicer_|. 138 // Handles buffers that come out of |splicer_|.
118 // Returns true if more buffers are needed. 139 // Returns true if more buffers are needed.
119 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer); 140 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer);
120 141
121 // Helper functions for AudioDecoder::Status values passed to 142 // Helper functions for AudioDecoder::Status values passed to
122 // DecodedAudioReady(). 143 // DecodedAudioReady().
123 void HandleAbortedReadOrDecodeError(bool is_decode_error); 144 void HandleAbortedReadOrDecodeError(bool is_decode_error);
124 145
125 // Estimate earliest time when current buffer can stop playing. 146 // Estimate earliest time when current buffer can stop playing.
126 void UpdateEarliestEndTime_Locked(int frames_filled, 147 void UpdateEarliestEndTime_Locked(int frames_filled,
127 const base::TimeDelta& playback_delay, 148 const base::TimeDelta& playback_delay,
128 const base::TimeTicks& time_now); 149 const base::TimeTicks& time_now);
129 150
130 void DoPlay_Locked(); 151 void StartRendering_Locked();
131 void DoPause_Locked(); 152 void StopRendering_Locked();
132 153
133 // AudioRendererSink::RenderCallback implementation. 154 // AudioRendererSink::RenderCallback implementation.
134 // 155 //
135 // NOTE: These are called on the audio callback thread! 156 // NOTE: These are called on the audio callback thread!
136 // 157 //
137 // Render() fills the given buffer with audio data by delegating to its 158 // Render() fills the given buffer with audio data by delegating to its
138 // |algorithm_|. Render() also takes care of updating the clock. 159 // |algorithm_|. Render() also takes care of updating the clock.
139 // Returns the number of frames copied into |audio_bus|, which may be less 160 // Returns the number of frames copied into |audio_bus|, which may be less
140 // than or equal to the initial number of frames in |audio_bus| 161 // than or equal to the initial number of frames in |audio_bus|
141 // 162 //
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // After Initialize() has completed, all variables below must be accessed 249 // After Initialize() has completed, all variables below must be accessed
229 // under |lock_|. ------------------------------------------------------------ 250 // under |lock_|. ------------------------------------------------------------
230 base::Lock lock_; 251 base::Lock lock_;
231 252
232 // Algorithm for scaling audio. 253 // Algorithm for scaling audio.
233 scoped_ptr<AudioRendererAlgorithm> algorithm_; 254 scoped_ptr<AudioRendererAlgorithm> algorithm_;
234 255
235 // Simple state tracking variable. 256 // Simple state tracking variable.
236 State state_; 257 State state_;
237 258
238 // Keep track of whether or not the sink is playing. 259 // Keep track of whether or not the sink is playing and whether we should be
260 // rendering.
261 bool rendering_;
239 bool sink_playing_; 262 bool sink_playing_;
240 263
241 // Keep track of our outstanding read to |decoder_|. 264 // Keep track of our outstanding read to |decoder_|.
242 bool pending_read_; 265 bool pending_read_;
243 266
244 // Keeps track of whether we received and rendered the end of stream buffer. 267 // Keeps track of whether we received and rendered the end of stream buffer.
245 bool received_end_of_stream_; 268 bool received_end_of_stream_;
246 bool rendered_end_of_stream_; 269 bool rendered_end_of_stream_;
247 270
248 scoped_ptr<AudioClock> audio_clock_; 271 scoped_ptr<AudioClock> audio_clock_;
(...skipping 27 matching lines...) Expand all
276 299
277 // NOTE: Weak pointers must be invalidated before all other member variables. 300 // NOTE: Weak pointers must be invalidated before all other member variables.
278 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; 301 base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
279 302
280 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 303 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
281 }; 304 };
282 305
283 } // namespace media 306 } // namespace media
284 307
285 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ 308 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_
OLDNEW
« no previous file with comments | « media/base/pipeline_unittest.cc ('k') | media/filters/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698