Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to audio sync logic if mpv window isn't visible #15552

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
13 changes: 12 additions & 1 deletion video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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");

Expand Down
7 changes: 6 additions & 1 deletion video/out/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,12 @@ struct vo_driver {
* frame is freed by the caller if the callee did not assume ownership
* of the frames, but in any case the callee can still modify the
* contained data and references.
*
* Return false to signal to the core that rendering is being skipped for
* this particular frame. vo.c will sleep for the expected duration of that
* frame before advancing forward.
*/
void (*draw_frame)(struct vo *vo, struct vo_frame *frame);
bool (*draw_frame)(struct vo *vo, struct vo_frame *frame);

/*
* Blit/Flip buffer to the screen. Must be called after each frame!
Expand Down Expand Up @@ -529,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);
Expand Down
7 changes: 5 additions & 2 deletions video/out/vo_caca.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,18 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
return resize(vo);
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *priv = vo->priv;
struct mp_image *mpi = frame->current;
if (!mpi)
return;
goto done;
memcpy_pic(priv->dither_buffer, mpi->planes[0], priv->image_width * depth, priv->image_height,
priv->image_width * depth, mpi->stride[0]);
caca_dither_bitmap(priv->canvas, 0, 0, priv->screen_w, priv->screen_h, priv->dither, priv->dither_buffer);

done:
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
11 changes: 7 additions & 4 deletions video/out/vo_direct3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,18 +1003,18 @@ static bool get_video_buffer(d3d_priv *priv, struct mp_image *out)
return true;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
d3d_priv *priv = vo->priv;
if (!priv->d3d_device)
return;
goto done;

struct mp_image buffer;
if (!get_video_buffer(priv, &buffer))
return;
goto done;

if (!frame->current)
return;
goto done;

mp_image_copy(&buffer, frame->current);

Expand All @@ -1024,6 +1024,9 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
priv->osd_pts = frame->current->pts;

d3d_draw_frame(priv);

done:
return VO_TRUE;
}

static mp_image_t *get_window_screenshot(d3d_priv *priv)
Expand Down
6 changes: 4 additions & 2 deletions video/out/vo_dmabuf_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ static bool draw_osd(struct vo *vo, struct mp_image *cur, double pts)
return draw;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
struct vo_wayland_state *wl = vo->wl;
Expand All @@ -603,7 +603,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
if (!vo_wayland_check_visible(vo)) {
if (frame->current)
talloc_free(frame);
return;
return VO_FALSE;
}

if (p->destroy_buffers)
Expand Down Expand Up @@ -641,6 +641,8 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
p->osd_surface_is_mapped = false;
}
}

return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
7 changes: 5 additions & 2 deletions video/out/vo_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ static void swapchain_step(struct vo *vo)
}
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct vo_drm_state *drm = vo->drm;
struct priv *p = vo->priv;

if (!drm->active)
return;
goto done;

drm->still = frame->still;

Expand All @@ -319,6 +319,9 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
}

enqueue_frame(vo, fb);

done:
return VO_TRUE;
}

static void queue_flip(struct vo *vo, struct drm_frame *frame)
Expand Down
8 changes: 5 additions & 3 deletions video/out/vo_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@ static void resize(struct vo *vo)
vo->want_redraw = true;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct gpu_priv *p = vo->priv;
struct ra_swapchain *sw = p->ctx->swapchain;

struct ra_fbo fbo;
if (!sw->fns->start_frame(sw, &fbo))
return;
return VO_FALSE;

gl_video_render_frame(p->renderer, frame, &fbo, RENDER_FRAME_DEF);
if (!sw->fns->submit_frame(sw, frame)) {
MP_ERR(vo, "Failed presenting frame!\n");
return;
return VO_FALSE;
}

struct mp_image_params *params = gl_video_get_target_params_ptr(p->renderer);
mp_mutex_lock(&vo->params_mutex);
vo->target_params = params;
mp_mutex_unlock(&vo->params_mutex);

return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
5 changes: 3 additions & 2 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ static void update_tm_viz(struct pl_color_map_params *params,
static void update_hook_opts_dynamic(struct priv *p, const struct pl_hook *hook,
const struct mp_image *mpi);

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
pl_options pars = p->pars;
Expand Down Expand Up @@ -1029,7 +1029,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
#endif
pl_queue_update(p->queue, NULL, &qparams);
}
return;
return VO_FALSE;
}

bool valid = false;
Expand Down Expand Up @@ -1173,6 +1173,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)

pl_gpu_flush(gpu);
p->frame_pending = true;
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
7 changes: 5 additions & 2 deletions video/out/vo_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
return 0;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
if (!frame->current)
return;
goto done;

p->current = frame->current;

struct mp_osd_res dim = osd_res_from_image_params(vo->params);
osd_draw_on_image(vo->osd, dim, frame->current->pts, OSD_DRAW_SUB_ONLY, p->current);

done:
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
7 changes: 5 additions & 2 deletions video/out/vo_kitty.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static int create_shm(struct vo *vo)
#endif
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;
mp_image_t *mpi = NULL;
Expand Down Expand Up @@ -273,7 +273,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)


if (p->opts.use_shm && !create_shm(vo))
return;
goto done;

memcpy_pic(p->buffer, p->frame->planes[0], p->width * BYTES_PER_PX,
p->height, p->width * BYTES_PER_PX, p->frame->stride[0]);
Expand All @@ -282,6 +282,9 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
av_base64_encode(p->output, p->output_size, p->buffer, p->buffer_size);

talloc_free(mpi);

done:
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
9 changes: 6 additions & 3 deletions video/out/vo_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,23 @@ static int query_format(struct vo *vo, int format)
return 0;
}

static void draw_frame(struct vo *vo, struct vo_frame *voframe)
static bool draw_frame(struct vo *vo, struct vo_frame *voframe)
{
struct priv *vc = vo->priv;
struct encoder_context *enc = vc->enc;
struct encode_lavc_context *ectx = enc->encode_lavc_ctx;
AVCodecContext *avc = enc->encoder;

if (voframe->redraw || voframe->repeat || voframe->num_frames < 1)
return;
goto done;

struct mp_image *mpi = voframe->frames[0];

struct mp_osd_res dim = osd_res_from_image_params(vo->params);
osd_draw_on_image(vo->osd, dim, mpi->pts, OSD_DRAW_SUB_ONLY, mpi);

if (vc->shutdown)
return;
goto done;

// Lock for shared timestamp fields.
mp_mutex_lock(&ectx->lock);
Expand Down Expand Up @@ -241,6 +241,9 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe)
frame->quality = avc->global_quality;
encoder_encode(enc, frame);
av_frame_free(&frame);

done:
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
3 changes: 2 additions & 1 deletion video/out/vo_libmpv.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ int mpv_render_context_get_info(mpv_render_context *ctx,
return res;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct vo_priv *p = vo->priv;
struct mpv_render_context *ctx = p->ctx;
Expand All @@ -498,6 +498,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
mp_mutex_unlock(&ctx->lock);

update(ctx);
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
3 changes: 2 additions & 1 deletion video/out/vo_mediacodec_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void flip_page(struct vo *vo)
mp_image_unrefp(&p->next_image);
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *p = vo->priv;

Expand All @@ -86,6 +86,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)

talloc_free(p->next_image);
p->next_image = mpi;
return VO_TRUE;
}

static int query_format(struct vo *vo, int format)
Expand Down
3 changes: 2 additions & 1 deletion video/out/vo_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ struct priv {
double cfg_fps;
};

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
return VO_TRUE;
}

static void flip_page(struct vo *vo)
Expand Down
7 changes: 5 additions & 2 deletions video/out/vo_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ static int query_format(struct vo *vo, int format)
return 0;
}

static void draw_frame(struct vo *vo, struct vo_frame *frame)
static bool draw_frame(struct vo *vo, struct vo_frame *frame)
{
struct priv *vc = vo->priv;

Expand All @@ -894,7 +894,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)

mp_image_t texmpi;
if (!lock_texture(vo, &texmpi))
return;
goto done;

mp_image_copy(&texmpi, frame->current);

Expand All @@ -914,6 +914,9 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
SDL_RenderCopy(vc->renderer, vc->tex, &src, &dst);

draw_osd(vo);

done:
return VO_TRUE;
}

static struct mp_image *get_window_screenshot(struct vo *vo)
Expand Down
Loading
Loading