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

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

Issue 382633005: Use AudioClock to determine when audio playback has ended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « no previous file | 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const scoped_refptr<AudioBuffer>& buffer); 120 const scoped_refptr<AudioBuffer>& buffer);
121 121
122 // Handles buffers that come out of |splicer_|. 122 // Handles buffers that come out of |splicer_|.
123 // Returns true if more buffers are needed. 123 // Returns true if more buffers are needed.
124 bool HandleSplicerBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer); 124 bool HandleSplicerBuffer_Locked(const scoped_refptr<AudioBuffer>& buffer);
125 125
126 // Helper functions for AudioDecoder::Status values passed to 126 // Helper functions for AudioDecoder::Status values passed to
127 // DecodedAudioReady(). 127 // DecodedAudioReady().
128 void HandleAbortedReadOrDecodeError(bool is_decode_error); 128 void HandleAbortedReadOrDecodeError(bool is_decode_error);
129 129
130 // Estimate earliest time when current buffer can stop playing.
131 void UpdateEarliestEndTime_Locked(int frames_filled,
132 const base::TimeDelta& playback_delay,
133 const base::TimeTicks& time_now);
134
135 void StartRendering_Locked(); 130 void StartRendering_Locked();
136 void StopRendering_Locked(); 131 void StopRendering_Locked();
137 132
138 // AudioRendererSink::RenderCallback implementation. 133 // AudioRendererSink::RenderCallback implementation.
139 // 134 //
140 // NOTE: These are called on the audio callback thread! 135 // NOTE: These are called on the audio callback thread!
141 // 136 //
142 // 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
143 // |algorithm_|. Render() also takes care of updating the clock. 138 // |algorithm_|. Render() also takes care of updating the clock.
144 // 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
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 bool pending_read_; 245 bool pending_read_;
251 246
252 // Keeps track of whether we received and rendered the end of stream buffer. 247 // Keeps track of whether we received and rendered the end of stream buffer.
253 bool received_end_of_stream_; 248 bool received_end_of_stream_;
254 bool rendered_end_of_stream_; 249 bool rendered_end_of_stream_;
255 250
256 scoped_ptr<AudioClock> audio_clock_; 251 scoped_ptr<AudioClock> audio_clock_;
257 252
258 base::TimeDelta start_timestamp_; 253 base::TimeDelta start_timestamp_;
259 254
260 // We're supposed to know amount of audio data OS or hardware buffered, but
261 // that is not always so -- on my Linux box
262 // AudioBuffersState::hardware_delay_bytes never reaches 0.
263 //
264 // As a result we cannot use it to find when stream ends. If we just ignore
265 // buffered data we will notify host that stream ended before it is actually
266 // did so, I've seen it done ~140ms too early when playing ~150ms file.
267 //
268 // Instead of trying to invent OS-specific solution for each and every OS we
269 // are supporting, use simple workaround: every time we fill the buffer we
270 // remember when it should stop playing, and do not assume that buffer is
271 // empty till that time. Workaround is not bulletproof, as we don't exactly
272 // know when that particular data would start playing, but it is much better
273 // than nothing.
274 base::TimeTicks earliest_end_time_;
275 size_t total_frames_filled_;
scherkus (not reviewing) 2014/07/10 00:33:44 apparently this variable was completely unused
DaleCurtis 2014/07/10 01:44:05 Haha, yeah, I've removed it a couple times locally
276
277 // End variables which must be accessed under |lock_|. ---------------------- 255 // End variables which must be accessed under |lock_|. ----------------------
278 256
279 // NOTE: Weak pointers must be invalidated before all other member variables. 257 // NOTE: Weak pointers must be invalidated before all other member variables.
280 base::WeakPtrFactory<AudioRendererImpl> weak_factory_; 258 base::WeakPtrFactory<AudioRendererImpl> weak_factory_;
281 259
282 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); 260 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
283 }; 261 };
284 262
285 } // namespace media 263 } // namespace media
286 264
287 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_ 265 #endif // MEDIA_FILTERS_AUDIO_RENDERER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | media/filters/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698