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

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

Issue 274443006: Revert of Rename AudioRenderer::Play/Pause() to Start/StopRendering(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 StartRendering() OVERRIDE; 75 virtual void Play() OVERRIDE;
76 virtual void StopRendering() OVERRIDE; 76 virtual void Pause() 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 // Important detail: being in kPlaying doesn't imply that audio is being 100 // TODO(acolwell): Add a state machine graph.
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()
122 enum State { 101 enum State {
123 kUninitialized, 102 kUninitialized,
124 kInitializing, 103 kInitializing,
104 kPaused,
125 kFlushing, 105 kFlushing,
126 kFlushed,
127 kPrerolling, 106 kPrerolling,
128 kPlaying, 107 kPlaying,
129 kStopped, 108 kStopped,
130 kUnderflow, 109 kUnderflow,
131 kRebuffering, 110 kRebuffering,
132 }; 111 };
133 112
134 // Callback from the audio decoder delivering decoded audio samples. 113 // Callback from the audio decoder delivering decoded audio samples.
135 void DecodedAudioReady(AudioBufferStream::Status status, 114 void DecodedAudioReady(AudioBufferStream::Status status,
136 const scoped_refptr<AudioBuffer>& buffer); 115 const scoped_refptr<AudioBuffer>& buffer);
137 116
138 // Handles buffers that come out of |splicer_|. 117 // Handles buffers that come out of |splicer_|.
139 // Returns true if more buffers are needed. 118 // Returns true if more buffers are needed.
140 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer); 119 bool HandleSplicerBuffer(const scoped_refptr<AudioBuffer>& buffer);
141 120
142 // Helper functions for AudioDecoder::Status values passed to 121 // Helper functions for AudioDecoder::Status values passed to
143 // DecodedAudioReady(). 122 // DecodedAudioReady().
144 void HandleAbortedReadOrDecodeError(bool is_decode_error); 123 void HandleAbortedReadOrDecodeError(bool is_decode_error);
145 124
146 // Estimate earliest time when current buffer can stop playing. 125 // Estimate earliest time when current buffer can stop playing.
147 void UpdateEarliestEndTime_Locked(int frames_filled, 126 void UpdateEarliestEndTime_Locked(int frames_filled,
148 const base::TimeDelta& playback_delay, 127 const base::TimeDelta& playback_delay,
149 const base::TimeTicks& time_now); 128 const base::TimeTicks& time_now);
150 129
151 void StartRendering_Locked(); 130 void DoPlay_Locked();
152 void StopRendering_Locked(); 131 void DoPause_Locked();
153 132
154 // AudioRendererSink::RenderCallback implementation. 133 // AudioRendererSink::RenderCallback implementation.
155 // 134 //
156 // NOTE: These are called on the audio callback thread! 135 // NOTE: These are called on the audio callback thread!
157 // 136 //
158 // Render() fills the given buffer with audio data by delegating to its 137 // Render() fills the given buffer with audio data by delegating to its
159 // |algorithm_|. Render() also takes care of updating the clock. 138 // |algorithm_|. Render() also takes care of updating the clock.
160 // Returns the number of frames copied into |audio_bus|, which may be less 139 // Returns the number of frames copied into |audio_bus|, which may be less
161 // than or equal to the initial number of frames in |audio_bus| 140 // than or equal to the initial number of frames in |audio_bus|
162 // 141 //
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // After Initialize() has completed, all variables below must be accessed 228 // After Initialize() has completed, all variables below must be accessed
250 // under |lock_|. ------------------------------------------------------------ 229 // under |lock_|. ------------------------------------------------------------
251 base::Lock lock_; 230 base::Lock lock_;
252 231
253 // Algorithm for scaling audio. 232 // Algorithm for scaling audio.
254 scoped_ptr<AudioRendererAlgorithm> algorithm_; 233 scoped_ptr<AudioRendererAlgorithm> algorithm_;
255 234
256 // Simple state tracking variable. 235 // Simple state tracking variable.
257 State state_; 236 State state_;
258 237
259 // Keep track of whether or not the sink is playing and whether we should be 238 // Keep track of whether or not the sink is playing.
260 // rendering.
261 bool rendering_;
262 bool sink_playing_; 239 bool sink_playing_;
263 240
264 // Keep track of our outstanding read to |decoder_|. 241 // Keep track of our outstanding read to |decoder_|.
265 bool pending_read_; 242 bool pending_read_;
266 243
267 // Keeps track of whether we received and rendered the end of stream buffer. 244 // Keeps track of whether we received and rendered the end of stream buffer.
268 bool received_end_of_stream_; 245 bool received_end_of_stream_;
269 bool rendered_end_of_stream_; 246 bool rendered_end_of_stream_;
270 247
271 scoped_ptr<AudioClock> audio_clock_; 248 scoped_ptr<AudioClock> audio_clock_;
(...skipping 27 matching lines...) Expand all
299 276
300 // NOTE: Weak pointers must be invalidated before all other member variables. 277 // NOTE: Weak pointers must be invalidated before all other member variables.
301 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; 278 base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
302 279
303 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 280 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
304 }; 281 };
305 282
306 } // namespace media 283 } // namespace media
307 284
308 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ 285 #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