0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: put speed adjustment back into playing_audio_pts

Effectively reverts 7051e94e4b. 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.
This commit is contained in:
Dudemanguy 2024-05-24 22:18:29 -05:00
parent eaae9e9cf5
commit 652036ba54
2 changed files with 5 additions and 6 deletions

View File

@ -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)
{

View File

@ -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;
}