Skip to content

Commit

Permalink
player: remove speed adjustment from playing_audio_pts
Browse files Browse the repository at this point in the history
When calculating the audio pts, mpv multiplies the ao delay by the
current audio speed and subtracts it from the written audio pts. This
doesn't really make sense though. mpctx->video_pts is never affected by
the playback speed, and this leads to weird behavior like the audio-pts
property changing values while paused merely because the playback speed
changes. Remove the multiplication and simply subtract the delay by a
factor of 1 instead. When updating the av_diff in player/video, this
does actually need to take in account the audio speed so we do the
calculation there.
  • Loading branch information
Dudemanguy committed Feb 26, 2024
1 parent d5dc1e8 commit 7051e94
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion player/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ double playing_audio_pts(struct MPContext *mpctx)
double pts = written_audio_pts(mpctx);
if (pts == MP_NOPTS_VALUE || !mpctx->ao)
return pts;
return pts - mpctx->audio_speed * ao_get_delay(mpctx->ao);
return pts - ao_get_delay(mpctx->ao);
}

// This garbage is needed for untimed AOs. These consume audio infinitely fast,
Expand Down
3 changes: 2 additions & 1 deletion player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,9 @@ static void update_av_diff(struct MPContext *mpctx, double offset)
if (mpctx->vo_chain && mpctx->vo_chain->is_sparse)
return;

double a_pos = playing_audio_pts(mpctx);
double a_pos = written_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;
}
Expand Down

0 comments on commit 7051e94

Please sign in to comment.