diff options
author | Uoti Urpala <uau@mplayer2.org> | 2011-11-06 15:41:39 +0200 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2011-11-14 20:24:39 +0200 |
commit | 0aa8df2b7d95ba270394c1a1d2a11ccd73956a56 (patch) | |
tree | 7d0e1b9961193d970a179813eb9fcc9fffa189f9 /mplayer.c | |
parent | 32b2242d677aed39167b8c2b57d3d6538b48acd7 (diff) | |
download | mpv-0aa8df2b7d95ba270394c1a1d2a11ccd73956a56.tar.bz2 mpv-0aa8df2b7d95ba270394c1a1d2a11ccd73956a56.tar.xz |
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.
Diffstat (limited to 'mplayer.c')
-rw-r--r-- | mplayer.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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); |