Skip to content

Commit

Permalink
vo: Fix race condition causing redraw requests to be ignored
Browse files Browse the repository at this point in the history
This manifested most frequently as a bug where the OSD fails to update
after pausing or single-stepping forwards (issues mpv-player#8172, mpv-player#8350).

In `render_frame`, the vo thread takes the lock once before rendering
the frame, and once after. The lock is relinquished whilst the frame is
actually rendering.

The `redraw_request` flag was being cleared whilst holding the lock
*after* the video frame has been rendered; however this frame was
rendered according to the request fetched whilst holding the lock the
first time. If the OSD was updated during the rendering of this frame,
the redraw request is cleared once the frame finishes rendering even
though the updated OSD is not included in the rendered frame.

This patch fixes the race condition by clearing the `redraw_request`
flag *before* the video frame rendering starts. That way, a redraw
request that comes in during frame rendering will not be cleared without
another call to `render_frame` or `do_redraw`.
  • Loading branch information
chengsun committed Jan 21, 2022
1 parent 9cddd73 commit 8a73a9d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ static bool render_frame(struct vo *vo)
} else {
in->rendering = true;
in->hasframe_rendered = true;
in->request_redraw = false;
int64_t prev_drop_count = vo->in->drop_count;
// Can the core queue new video now? Non-display-sync uses a separate
// timer instead, but possibly benefits from preparing a frame early.
Expand Down Expand Up @@ -997,8 +998,6 @@ static bool render_frame(struct vo *vo)

if (in->dropped_frame) {
MP_STATS(vo, "drop-vo");
} else {
in->request_redraw = false;
}

if (in->current_frame && in->current_frame->num_vsyncs &&
Expand Down

0 comments on commit 8a73a9d

Please sign in to comment.