diff options
author | wm4 <wm4@nowhere> | 2014-07-30 00:40:45 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-07-30 00:40:45 +0200 |
commit | da780309d707ac995941c14d1f5bbc8f1a7239b8 (patch) | |
tree | fac9135fbee262012cd99869f7aa6d8888e0a31f | |
parent | 1cd2b5976dd01d2537208b5e56bc377aaff4bc13 (diff) | |
download | mpv-da780309d707ac995941c14d1f5bbc8f1a7239b8.tar.bz2 mpv-da780309d707ac995941c14d1f5bbc8f1a7239b8.tar.xz |
audio: better initial sync for files where audio starts later
Some files have the first audio much later into the video (for whatever
reasons). Instead of appending large amounts of silence to the audio
buffer (and refusing to sync if the audio to append is "too large"),
just wait until enough video has played.
-rw-r--r-- | player/audio.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/player/audio.c b/player/audio.c index b5eb8884f9..f371b69bb4 100644 --- a/player/audio.c +++ b/player/audio.c @@ -405,6 +405,15 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts) } } + // If EOF was reached before, but now something can be decoded, try to + // restart audio properly. This helps with video files where audio starts + // later. Retrying is needed to get the correct sync PTS. + if (mpctx->audio_status == STATUS_EOF && status == AD_OK) { + mpctx->audio_status = STATUS_SYNCING; + mpctx->sleeptime = 0; + return; // retry on next iteration + } + bool end_sync = status != AD_OK; // (on error/EOF, start playback immediately) if (skip >= 0) { int max = mp_audio_buffer_samples(mpctx->ao_buffer); @@ -412,12 +421,13 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts) // If something is left, we definitely reached the target time. end_sync |= sync_known && skip < max; } else if (skip < 0) { - if (-skip < 1000000) { // heuristic against making the buffer too large - mp_audio_buffer_prepend_silence(mpctx->ao_buffer, -skip); - } else { - MP_ERR(mpctx, "Audio starts too late: sync. failed.\n"); - ao_reset(mpctx->ao); + if (-skip > playsize) { // heuristic against making the buffer too large + ao_reset(mpctx->ao); // some AOs repeat data on underflow + mpctx->audio_status = STATUS_EOF; + mpctx->delay = 0; + return; } + mp_audio_buffer_prepend_silence(mpctx->ao_buffer, -skip); end_sync = true; } |