Skip to content

Commit

Permalink
player/video: subtract frame_time from delay when ao_chain starts audio
Browse files Browse the repository at this point in the history
This seems more robust than relying on the audio status to actually be
playing. For files where there is no audio or the audio start is
delayed, this guards against that but it allows the subtraction to
always occur otherwise on normal files with audio.
  • Loading branch information
Dudemanguy committed Mar 2, 2024
1 parent a075860 commit 5f952e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions player/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ void audio_start_ao(struct MPContext *mpctx)
}

MP_VERBOSE(mpctx, "starting audio playback\n");
ao_c->audio_started = true;
ao_start(ao_c->ao);
mpctx->audio_status = STATUS_PLAYING;
if (ao_c->out_eof) {
Expand Down
2 changes: 2 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ struct ao_chain {
double start_pts;
bool start_pts_known;

bool audio_started;

struct track *track;
struct mp_pin *filter_src;
struct mp_pin *dec_src;
Expand Down
3 changes: 2 additions & 1 deletion player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ static void adjust_sync(struct MPContext *mpctx, double v_pts, double frame_time
if (mpctx->audio_status != STATUS_PLAYING)
return;

mpctx->delay -= frame_time;
double a_pts = written_audio_pts(mpctx) + opts->audio_delay - mpctx->delay;
double av_delay = a_pts - v_pts;

Expand Down Expand Up @@ -402,6 +401,8 @@ static void handle_new_frame(struct MPContext *mpctx)
}
}
mpctx->time_frame += frame_time / mpctx->video_speed;
if (mpctx->ao_chain && mpctx->ao_chain->audio_started)
mpctx->delay -= frame_time;
if (mpctx->video_status >= STATUS_PLAYING)
adjust_sync(mpctx, pts, frame_time);
MP_TRACE(mpctx, "frametime=%5.3f\n", frame_time);
Expand Down

0 comments on commit 5f952e6

Please sign in to comment.