Skip to content

Commit

Permalink
player/audio: invert audio_started boolean
Browse files Browse the repository at this point in the history
Waiting for audio_started to be set to true takes too long which causes
us to miss it for the first frame, instead invert the condition so it's
set on the first frame.

Fixes mpv-player#14615
  • Loading branch information
llyyr authored and na-na-hi committed Sep 16, 2024
1 parent b39883c commit 12ecff7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion player/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ static void ao_chain_reset_state(struct ao_chain *ao_c)
ao_c->start_pts = MP_NOPTS_VALUE;
ao_c->untimed_throttle = false;
ao_c->underrun = false;
ao_c->delaying_audio_start = false;
}

void reset_audio_state(struct MPContext *mpctx)
Expand Down Expand Up @@ -841,12 +842,13 @@ void audio_start_ao(struct MPContext *mpctx)
MP_VERBOSE(mpctx, "delaying audio start %f vs. %f, diff=%f\n",
apts, pts, diff);
mpctx->logged_async_diff = diff;
ao_c->delaying_audio_start = true;
}
return;
}

MP_VERBOSE(mpctx, "starting audio playback\n");
ao_c->audio_started = true;
ao_c->delaying_audio_start = false;
ao_start(ao_c->ao);
mpctx->audio_status = STATUS_PLAYING;
if (ao_c->out_eof) {
Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct ao_chain {
double start_pts;
bool start_pts_known;

bool audio_started;
bool delaying_audio_start;

struct track *track;
struct mp_pin *filter_src;
Expand Down
2 changes: 1 addition & 1 deletion player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ 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)
if (mpctx->ao_chain && !mpctx->ao_chain->delaying_audio_start)
mpctx->delay -= frame_time;
if (mpctx->video_status >= STATUS_PLAYING)
adjust_sync(mpctx, pts, frame_time);
Expand Down

0 comments on commit 12ecff7

Please sign in to comment.