1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

player: fix initial audio sync in certain cases

Regression caused by commit 3b95dd47. Also see commit 4c25b000. We can
either use video_next_pts and add "delay", or we just use video_pts. Any
other combination breaks. The reason why the assumption that delay==0 at
this point was wrong exactly because after displaying the first video
frame (usually done before audio resync) a new frame might be "added"
immediately, resulting in a new video_next_pts and "delay", which will
still amount to video_pts.

Fixes #2770. (The reason why display-sync was blamed in this issue is
because enabling display-sync in the options forces a prefetch by 2
instead of 1 frames for seeks/playback restart, which triggers the
issue, even if display-sync is not actually enabled. In this case,
display-sync is never enabled because the frames have a unusually high
frame duration. This is also what exposed the initial desync issue.)
This commit is contained in:
wm4 2016-01-29 22:43:59 +01:00
parent d980fd0856
commit 340deb4e6e
3 changed files with 2 additions and 6 deletions

View File

@ -512,8 +512,8 @@ static bool get_sync_samples(struct MPContext *mpctx, int *skip)
if (sync_to_video) {
if (mpctx->video_status < STATUS_READY)
return false; // wait until we know a video PTS
if (mpctx->video_next_pts != MP_NOPTS_VALUE)
sync_pts = mpctx->video_next_pts - opts->audio_delay;
if (mpctx->video_pts != MP_NOPTS_VALUE)
sync_pts = mpctx->video_pts - opts->audio_delay;
} else if (mpctx->hrseek_active) {
sync_pts = mpctx->hrseek_pts;
}

View File

@ -351,8 +351,6 @@ typedef struct MPContext {
* (or at least queued to be flipped by VO) */
double video_pts;
double last_seek_pts;
// Mostly unused; for proper audio resync on speed changes.
double video_next_pts;
// As video_pts, but is not reset when seeking away. (For the very short
// period of time until a new frame is decoded and shown.)
double last_vo_pts;

View File

@ -254,7 +254,6 @@ void reset_video_state(struct MPContext *mpctx)
mpctx->delay = 0;
mpctx->time_frame = 0;
mpctx->video_pts = MP_NOPTS_VALUE;
mpctx->video_next_pts = MP_NOPTS_VALUE;
mpctx->num_past_frames = 0;
mpctx->total_avsync_change = 0;
mpctx->last_av_difference = 0;
@ -632,7 +631,6 @@ static void handle_new_frame(struct MPContext *mpctx)
frame_time = 0;
}
}
mpctx->video_next_pts = pts;
mpctx->delay -= frame_time;
if (mpctx->video_status >= STATUS_PLAYING) {
mpctx->time_frame += frame_time / mpctx->video_speed;