summaryrefslogtreecommitdiffstats
path: root/player/playloop.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-08-04 11:26:57 +0200
committerwm4 <wm4@nowhere>2016-08-04 11:26:57 +0200
commit3c3361217c96337270b112e52f9eb6cc5931b390 (patch)
treeb1133f42294800b4da44730c6869db2ec589f80f /player/playloop.c
parent356e703510170151a1678e9b1deab2ffdd5c92fb (diff)
downloadmpv-3c3361217c96337270b112e52f9eb6cc5931b390.tar.bz2
mpv-3c3361217c96337270b112e52f9eb6cc5931b390.tar.xz
player: offset demuxer on start/seek properly with audio/sub delay
Assume you use a large value like --audio-delay=20. Then until now the player would just have seeked normally to a "too late" position, and played silence for about 20 seconds until audio in the correct time range is coming again. Change this by offsetting seeks by the right amount. This works for both external and muxed files. If a seek isn't precise, then it works only for external files. This might cause issues with very large delay options. Hr-seek skipping could take a lot of time (especially because it affects video too), the demuxer queue could overflow, and other weird corner cases could appear. But we just try this on best-effort basis, and if the user uses extreme values we don't guarantee good behavior.
Diffstat (limited to 'player/playloop.c')
-rw-r--r--player/playloop.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/player/playloop.c b/player/playloop.c
index fd16c78e68..da3e995975 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -247,6 +247,12 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
// The value is arbitrary, but should be "good enough" in most situations.
if (hr_seek_very_exact)
hr_seek_offset = MPMAX(hr_seek_offset, 0.5); // arbitrary
+ for (int n = 0; n < mpctx->num_tracks; n++) {
+ double offset = 0;
+ if (!mpctx->tracks[n]->is_external)
+ offset += get_track_seek_offset(mpctx, mpctx->tracks[n]);
+ hr_seek_offset = MPMAX(hr_seek_offset, -offset);
+ }
demux_pts -= hr_seek_offset;
demux_flags = (demux_flags | SEEK_HR | SEEK_BACKWARD) & ~SEEK_FORWARD;
}
@@ -258,6 +264,8 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek)
struct track *track = mpctx->tracks[t];
if (track->selected && track->is_external && track->demuxer) {
double main_new_pos = demux_pts;
+ if (!hr_seek || track->is_external)
+ main_new_pos += get_track_seek_offset(mpctx, track);
if (demux_flags & SEEK_FACTOR)
main_new_pos = seek_pts;
demux_seek(track->demuxer, main_new_pos, 0);