From ed9295c250ddfb845e48f123343e7b02326e8920 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Oct 2013 23:35:51 +0200 Subject: video/out: always support redrawing VO window at any point Before, a VO could easily refuse to respond to VOCTRL_REDRAW_FRAME, which means the VO wouldn't redraw OSD and window contents, and the player would appear frozen to the user. This was a bit stupid, and makes dealing with some corner cases much harder (think of --keep-open, which was hard to implement, because the VO gets into this state if there are no new video frames after a seek reset). Change this, and require VOs to always react to VOCTRL_REDRAW_FRAME. There are two aspects of this: First, behavior after a (successful) vo_reconfig() call, but before any video frame has been displayed. Second, behavior after a vo_seek_reset(). For the first issue, we define that sending VOCTRL_REDRAW_FRAME after vo_reconfig() should clear the window with black. This requires minor changes to some VOs. In particular vaapi makes this horribly complicated, because OSD rendering is bound to a video surface. We create a black dummy surface for this purpose. The second issue is much simpler and works already with most VOs: they simply redraw whatever has been uploaded previously. The exception is vdpau, which has a complicated mechanism to track and filter video frames. The state associated with this mechanism is completely cleared with vo_seek_reset(), so implementing this to work as expected is not trivial. For now, we just clear the window with black. --- video/out/vo_vaapi.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'video/out/vo_vaapi.c') diff --git a/video/out/vo_vaapi.c b/video/out/vo_vaapi.c index 6973882176..7dab1ed058 100644 --- a/video/out/vo_vaapi.c +++ b/video/out/vo_vaapi.c @@ -91,6 +91,9 @@ struct priv { struct va_surface_pool *pool; struct va_image_formats *va_image_formats; + + struct va_surface *black_surface; + VAImageFormat *va_subpic_formats; unsigned int *va_subpic_flags; int va_num_subpic_formats; @@ -119,6 +122,8 @@ static void free_video_specific(struct priv *p) { flush_output_surfaces(p); + va_surface_releasep(&p->black_surface); + for (int n = 0; n < MAX_OUTPUT_SURFACES; n++) mp_image_unrefp(&p->swdec_surfaces[n]); } @@ -149,6 +154,8 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags) { struct priv *p = vo->priv; + free_video_specific(p); + vo_x11_config_vo_window(vo, NULL, vo->dx, vo->dy, vo->dwidth, vo->dheight, flags, "vaapi"); @@ -173,10 +180,29 @@ static int query_format(struct vo *vo, uint32_t imgfmt) static bool render_to_screen(struct priv *p, struct mp_image *mpi) { - bool res = true; VAStatus status; VASurfaceID surface = va_surface_id_in_mp_image(mpi); + if (surface == VA_INVALID_ID) { + if (!p->black_surface) { + int w = p->image_params.w, h = p->image_params.h; + // 4:2:0 should work everywhere + int fmt = IMGFMT_420P; + p->black_surface = + va_surface_pool_get_by_imgfmt(p->pool, p->va_image_formats, + fmt, w, h); + if (p->black_surface) { + struct mp_image *img = mp_image_alloc(fmt, w, h); + mp_image_clear(img, 0, 0, w, h); + if (!va_surface_upload(p->black_surface, img)) + va_surface_releasep(&p->black_surface); + talloc_free(img); + } + } + surface = va_surface_id(p->black_surface); + } + + int fields = mpi ? mpi->fields : 0; if (surface == VA_INVALID_ID) return false; @@ -199,9 +225,8 @@ static bool render_to_screen(struct priv *p, struct mp_image *mpi) } int flags = va_get_colorspace_flag(p->image_params.colorspace) | p->scaling; - if (p->deint && (mpi->fields & MP_IMGFIELD_INTERLACED)) { - flags |= (mpi->fields & MP_IMGFIELD_TOP_FIRST) ? - VA_BOTTOM_FIELD : VA_TOP_FIELD; + if (p->deint && (fields & MP_IMGFIELD_INTERLACED)) { + flags |= (fields & MP_IMGFIELD_TOP_FIRST) ? VA_BOTTOM_FIELD : VA_TOP_FIELD; } else { flags |= VA_FRAME_PICTURE; } @@ -230,7 +255,7 @@ static bool render_to_screen(struct priv *p, struct mp_image *mpi) } } - return res; + return true; } static void flip_page(struct vo *vo) @@ -505,7 +530,8 @@ static int control(struct vo *vo, uint32_t request, void *data) return get_equalizer(p, eq->name, eq->valueptr); } case VOCTRL_REDRAW_FRAME: - return redraw_frame(p); + redraw_frame(p); + return true; case VOCTRL_SCREENSHOT: { struct voctrl_screenshot_args *args = data; args->out_image = get_screenshot(p); -- cgit v1.2.3