From 0a6c334b592d4fd5e61addb9ba28b1182aecb6d9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Sep 2015 12:14:19 +0200 Subject: vo_opengl: vaapi: undo vaAcquireBufferHandle() correctly on error Checking and resetting the VAImage.buf field is non-sense, even if it happened to work out in the normal case. buf is actually freed when vaDestroyImage() is called (not quite intuitive), and we need an extra field to know whether vaReleaseBufferHandle() has to be called. --- video/out/opengl/hwdec_vaegl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/video/out/opengl/hwdec_vaegl.c b/video/out/opengl/hwdec_vaegl.c index 52738cbb4d..197c8beae8 100644 --- a/video/out/opengl/hwdec_vaegl.c +++ b/video/out/opengl/hwdec_vaegl.c @@ -39,6 +39,7 @@ struct priv { GLuint gl_textures[4]; EGLImageKHR images[4]; VAImage current_image; + bool buffer_acquired; struct mp_image *current_ref; }; @@ -55,10 +56,10 @@ static void unref_image(struct gl_hwdec *hw) va_lock(p->ctx); - if (p->current_image.buf != VA_INVALID_ID) { + if (p->buffer_acquired) { status = vaReleaseBufferHandle(p->display, p->current_image.buf); CHECK_VA_STATUS(p, "vaReleaseBufferHandle()"); - p->current_image.buf = VA_INVALID_ID; + p->buffer_acquired = false; } if (p->current_image.image_id != VA_INVALID_ID) { status = vaDestroyImage(p->display, p->current_image.image_id); @@ -194,6 +195,7 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image, status = vaAcquireBufferHandle(p->display, va_image->buf, &buffer_info); if (!CHECK_VA_STATUS(p, "vaAcquireBufferHandle()")) goto err; + p->buffer_acquired = true; struct mp_image layout = {0}; mp_image_set_params(&layout, &hw_image->params); -- cgit v1.2.3