player/video: fallback to audio sync logic if VO is not visible

The previous commit put all the pieces in place so now this can be
implemented. Scheduling frames is already written with the assumption
that display sync maybe turn on/off at any time. So all that needs to be
done is check if the VO reports that it is not visible. If so, simply
flip mpctx->display_sync_active to false for that frame and skip the
display sync frame handling. It will become true again when the mpv
window comes back into view.
This commit is contained in:
Dudemanguy
2024-12-20 12:47:39 -06:00
parent 91c1b65de0
commit a2fe5ee900
3 changed files with 15 additions and 2 deletions

View File

@@ -820,8 +820,9 @@ static void handle_display_sync_frame(struct MPContext *mpctx,
mpctx->display_sync_active = false;
if (!VS_IS_DISP(mode))
if (!VS_IS_DISP(mode) || !vo_is_visible(vo))
return;
bool resample = mode == VS_DISP_RESAMPLE || mode == VS_DISP_RESAMPLE_VDROP ||
mode == VS_DISP_RESAMPLE_NONE;
bool drop = mode == VS_DISP_VDROP || mode == VS_DISP_RESAMPLE ||

View File

@@ -134,6 +134,7 @@ struct vo_internal {
bool want_redraw; // redraw request from VO to player
bool send_reset; // send VOCTRL_RESET
bool paused;
bool visible;
bool wakeup_on_done;
int queued_events; // event mask for the user
int internal_events; // event mask for us
@@ -859,6 +860,16 @@ bool vo_is_ready_for_frame(struct vo *vo, int64_t next_pts)
return r;
}
// Check if the VO reports that the mpv window is visible.
bool vo_is_visible(struct vo *vo)
{
struct vo_internal *in = vo->in;
mp_mutex_lock(&in->lock);
bool r = in->visible;
mp_mutex_unlock(&in->lock);
return r;
}
// Direct the VO thread to put the currently queued image on the screen.
// vo_is_ready_for_frame() must have returned true before this call.
// Ownership of frame is handed to the vo.
@@ -996,7 +1007,7 @@ static bool render_frame(struct vo *vo)
stats_time_start(in->stats, "video-draw");
vo->driver->draw_frame(vo, frame);
in->visible = vo->driver->draw_frame(vo, frame);
stats_time_end(in->stats, "video-draw");

View File

@@ -533,6 +533,7 @@ int vo_reconfig2(struct vo *vo, struct mp_image *img);
int vo_control(struct vo *vo, int request, void *data);
void vo_control_async(struct vo *vo, int request, void *data);
bool vo_is_ready_for_frame(struct vo *vo, int64_t next_pts);
bool vo_is_visible(struct vo *vo);
void vo_queue_frame(struct vo *vo, struct vo_frame *frame);
void vo_wait_frame(struct vo *vo);
bool vo_still_displaying(struct vo *vo);