From 0aa8df2b7d95ba270394c1a1d2a11ccd73956a56 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sun, 6 Nov 2011 15:41:39 +0200 Subject: core/hrseek: support precise seeks in audio-only case Before, precise seeking only worked if there was a video stream; in the audio-only case playback always started from the demuxer seek position. Add code to cut away samples from the demuxer seek position to the seek target position. --- mplayer.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 7030a50da0..c13f56a143 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2464,10 +2464,16 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize) bool did_retry = false; double written_pts; double bps = ao->bps / opts->playback_speed; + bool hrseek = mpctx->hrseek_active; // audio only hrseek + mpctx->hrseek_active = false; while (1) { written_pts = written_audio_pts(mpctx); - double ptsdiff = written_pts - mpctx->sh_video->pts - mpctx->delay - - audio_delay; + double ptsdiff; + if (hrseek) + ptsdiff = written_pts - mpctx->hrseek_pts; + else + ptsdiff = written_pts - mpctx->sh_video->pts - mpctx->delay + - audio_delay; bytes = ptsdiff * bps; bytes -= bytes % (ao->channels * af_fmt2bits(ao->format) / 8); @@ -2506,6 +2512,9 @@ static int audio_start_sync(struct MPContext *mpctx, int playsize) if (res < 0) return res; } + if (hrseek) + // Don't add silence in audio-only case even if position is too late + return 0; int fillbyte = 0; if ((ao->format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_US) fillbyte = 0x80; @@ -2557,11 +2566,16 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) current_module = "decode_audio"; t = GetTimer(); - if (!opts->initial_audio_sync || !modifiable_audio_format) + // Coming here with hrseek_active still set means audio-only + if (!mpctx->sh_video) + mpctx->syncing_audio = false; + if (!opts->initial_audio_sync || !modifiable_audio_format) { mpctx->syncing_audio = false; + mpctx->hrseek_active = false; + } int res; - if (mpctx->syncing_audio && mpctx->sh_video) + if (mpctx->syncing_audio || mpctx->hrseek_active) res = audio_start_sync(mpctx, playsize); else res = decode_audio(sh_audio, &ao->buffer, playsize); -- cgit v1.2.3