summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-11-06 15:41:39 +0200
committerUoti Urpala <uau@mplayer2.org>2011-11-14 20:24:39 +0200
commit0aa8df2b7d95ba270394c1a1d2a11ccd73956a56 (patch)
tree7d0e1b9961193d970a179813eb9fcc9fffa189f9 /mplayer.c
parent32b2242d677aed39167b8c2b57d3d6538b48acd7 (diff)
downloadmpv-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.c22
1 files changed, 18 insertions, 4 deletions
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);