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

Unified Diff: media/filters/audio_clock.cc

Issue 1160853006: Improve audio/video sync during underflow, reduce underflow frequency. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/audio_clock.h ('k') | media/filters/audio_clock_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_clock.cc
diff --git a/media/filters/audio_clock.cc b/media/filters/audio_clock.cc
index aebc5e55befef998107d99392bb5edfac6a798e4..d93db1df2ce7c718dbe333a327f8cf11fcbd14d5 100644
--- a/media/filters/audio_clock.cc
+++ b/media/filters/audio_clock.cc
@@ -36,7 +36,7 @@ void AudioClock::WroteAudio(int frames_written,
// First write: initialize buffer with silence.
if (start_timestamp_ == front_timestamp_ && buffered_.empty())
- PushBufferedAudioData(delay_frames, 0.0f);
+ PushBufferedAudioData(delay_frames, 0.0);
// Move frames from |buffered_| into the computed timestamp based on
// |delay_frames|.
@@ -47,7 +47,7 @@ void AudioClock::WroteAudio(int frames_written,
std::max(INT64_C(0), total_buffered_frames_ - delay_frames);
front_timestamp_ += ComputeBufferedMediaTime(frames_played);
PushBufferedAudioData(frames_written, playback_rate);
- PushBufferedAudioData(frames_requested - frames_written, 0.0f);
+ PushBufferedAudioData(frames_requested - frames_written, 0.0);
PopBufferedAudioData(frames_played);
back_timestamp_ += base::TimeDelta::FromMicroseconds(
@@ -80,6 +80,23 @@ void AudioClock::WroteAudio(int frames_written,
microseconds_per_frame_);
}
+void AudioClock::CompensateForSuspendedWrites(base::TimeDelta elapsed,
+ int delay_frames) {
+ const int64_t frames_elapsed =
+ elapsed.InMicroseconds() / microseconds_per_frame_ + 0.5;
+
+ // No need to do anything if we're within the limits of our played out audio
+ // or there are no delay frames, the next WroteAudio() call will expire
+ // everything correctly.
+ if (frames_elapsed < total_buffered_frames_ || !delay_frames)
+ return;
+
+ // Otherwise, flush everything and prime with the delay frames.
+ WroteAudio(0, 0, 0, 0);
+ DCHECK(buffered_.empty());
+ PushBufferedAudioData(delay_frames, 0.0);
+}
+
base::TimeDelta AudioClock::TimeUntilPlayback(base::TimeDelta timestamp) const {
DCHECK_GE(timestamp, front_timestamp_);
DCHECK_LE(timestamp, back_timestamp_);
« no previous file with comments | « media/filters/audio_clock.h ('k') | media/filters/audio_clock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698