From 652036ba5401770510698e8c24f70542503b16a5 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Fri, 24 May 2024 22:18:29 -0500 Subject: [PATCH] player: put speed adjustment back into playing_audio_pts Effectively reverts 7051e94e4bacd00e53e88835d28e9d9082de3bb3. There's been some confusion with how audio pts gets used internally in mpv which leads to weird results. The crux of the problem is essentially that playing_audio_pts can return negative numbers and in many places this is not expected. This is the first step in trying to hopefully iron out all the weird corner cases. --- player/audio.c | 8 ++++---- player/video.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/player/audio.c b/player/audio.c index 173f902c97..e74add8cf8 100644 --- a/player/audio.c +++ b/player/audio.c @@ -612,13 +612,14 @@ double written_audio_pts(struct MPContext *mpctx) return mpctx->ao_chain ? mpctx->ao_chain->last_out_pts : MP_NOPTS_VALUE; } -// Return pts value corresponding to currently playing audio. +// Return pts value corresponding to currently playing audio adjusted for AO delay +// and playback speed. double playing_audio_pts(struct MPContext *mpctx) { double pts = written_audio_pts(mpctx); if (pts == MP_NOPTS_VALUE || !mpctx->ao) return pts; - return pts - ao_get_delay(mpctx->ao); + return pts - mpctx->audio_speed * ao_get_delay(mpctx->ao); } // This garbage is needed for untimed AOs. These consume audio infinitely fast, @@ -829,8 +830,7 @@ void audio_start_ao(struct MPContext *mpctx) double pts = MP_NOPTS_VALUE; if (!get_sync_pts(mpctx, &pts)) return; - double apts = written_audio_pts(mpctx); - apts -= apts != MP_NOPTS_VALUE ? mpctx->audio_speed * ao_get_delay(mpctx->ao) : 0; + double apts = playing_audio_pts(mpctx); if (pts != MP_NOPTS_VALUE && apts != MP_NOPTS_VALUE && pts < apts && mpctx->video_status != STATUS_EOF) { diff --git a/player/video.c b/player/video.c index af1aa911e4..ece77e91aa 100644 --- a/player/video.c +++ b/player/video.c @@ -646,9 +646,8 @@ static void update_av_diff(struct MPContext *mpctx, double offset) if (mpctx->vo_chain && mpctx->vo_chain->is_sparse) return; - double a_pos = written_audio_pts(mpctx); + double a_pos = playing_audio_pts(mpctx); if (a_pos != MP_NOPTS_VALUE && mpctx->video_pts != MP_NOPTS_VALUE) { - a_pos -= mpctx->audio_speed * ao_get_delay(mpctx->ao); mpctx->last_av_difference = a_pos - mpctx->video_pts + opts->audio_delay + offset; }