[Libva] [PATCH intel-driver 2/2] Report BUSY surface state accordingly.

Gwenole Beauchesne gb.devel at gmail.com
Tue Aug 26 05:32:38 PDT 2014


Return VA_STATUS_ERROR_SURFACE_BUSY for key interfaces.

This covers for va{Get,Put}Image(), as originally mandated by the
VA-API specs; vaBeginPicture() as this is the entry-point to any
decode, encode or video processing operation; but also for plain
vaMapBuffer() operation.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/i965_drv_video.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/i965_drv_video.h |    1 +
 2 files changed, 49 insertions(+)

diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index e45cfb3..a628e05 100755
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -337,6 +337,37 @@ get_subpic_format(const VAImageFormat *va_format)
     return NULL;
 }
 
+/* Checks whether the surface is in busy state */
+static bool
+is_surface_busy(struct i965_driver_data *i965,
+    struct object_surface *obj_surface)
+{
+    assert(obj_surface != NULL);
+
+    if (obj_surface->locked_image_id != VA_INVALID_ID)
+        return true;
+    if (obj_surface->derived_image_id != VA_INVALID_ID)
+        return true;
+    return false;
+}
+
+/* Checks whether the image is in busy state */
+static bool
+is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image)
+{
+    struct object_buffer *obj_buffer;
+
+    assert(obj_image != NULL);
+
+    if (obj_image->derived_surface != VA_INVALID_ID)
+        return true;
+
+    obj_buffer = BUFFER(obj_image->image.buf);
+    if (obj_buffer && obj_buffer->export_refcount > 0)
+        return true;
+    return false;
+}
+
 #define I965_PACKED_HEADER_BASE         0
 #define I965_PACKED_MISC_HEADER_BASE    3
 
@@ -1206,6 +1237,7 @@ i965_CreateSurfaces2(
         obj_surface->fourcc = 0;
         obj_surface->bo = NULL;
         obj_surface->locked_image_id = VA_INVALID_ID;
+        obj_surface->derived_image_id = VA_INVALID_ID;
         obj_surface->private_data = NULL;
         obj_surface->free_private_data = NULL;
         obj_surface->subsampling = SUBSAMPLE_YUV420;
@@ -2075,6 +2107,9 @@ i965_MapBuffer(VADriverContextP ctx,
     ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
     ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
 
+    if (obj_buffer->export_refcount > 0)
+        return VA_STATUS_ERROR_INVALID_BUFFER;
+
     if (NULL != obj_buffer->buffer_store->bo) {
         unsigned int tiling, swizzle;
 
@@ -2207,6 +2242,9 @@ i965_BeginPicture(VADriverContextP ctx,
     obj_config = obj_context->obj_config;
     ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
 
+    if (is_surface_busy(i965, obj_surface))
+        return VA_STATUS_ERROR_SURFACE_BUSY;
+
     switch (obj_config->profile) {
     case VAProfileMPEG2Simple:
     case VAProfileMPEG2Main:
@@ -3614,6 +3652,7 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
 
     *out_image = *image;
     obj_surface->flags |= SURFACE_DERIVED;
+    obj_surface->derived_image_id = image_id;
     obj_image->derived_surface = surface;
 
     return VA_STATUS_SUCCESS;
@@ -3657,6 +3696,7 @@ i965_DestroyImage(VADriverContextP ctx, VAImageID image)
 
     if (obj_surface) {
         obj_surface->flags &= ~SURFACE_DERIVED;
+        obj_surface->derived_image_id = VA_INVALID_ID;
     }
 
     i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
@@ -3958,9 +3998,13 @@ i965_GetImage(VADriverContextP ctx,
         return VA_STATUS_ERROR_INVALID_SURFACE;
     if (!obj_surface->bo) /* don't get anything, keep previous data */
         return VA_STATUS_SUCCESS;
+    if (is_surface_busy(i965, obj_surface))
+        return VA_STATUS_ERROR_SURFACE_BUSY;
 
     if (!obj_image || !obj_image->bo)
         return VA_STATUS_ERROR_INVALID_IMAGE;
+    if (is_image_busy(i965, obj_image))
+        return VA_STATUS_ERROR_SURFACE_BUSY;
 
     if (x < 0 || y < 0)
         return VA_STATUS_ERROR_INVALID_PARAMETER;
@@ -4265,9 +4309,13 @@ i965_PutImage(VADriverContextP ctx,
 
     if (!obj_surface)
         return VA_STATUS_ERROR_INVALID_SURFACE;
+    if (is_surface_busy(i965, obj_surface))
+        return VA_STATUS_ERROR_SURFACE_BUSY;
 
     if (!obj_image || !obj_image->bo)
         return VA_STATUS_ERROR_INVALID_IMAGE;
+    if (is_image_busy(i965, obj_image))
+        return VA_STATUS_ERROR_SURFACE_BUSY;
 
     if (src_x < 0 ||
         src_y < 0 ||
diff --git a/src/i965_drv_video.h b/src/i965_drv_video.h
index 145071f..97181db 100644
--- a/src/i965_drv_video.h
+++ b/src/i965_drv_video.h
@@ -263,6 +263,7 @@ struct object_surface
     unsigned int fourcc;    
     dri_bo *bo;
     VAImageID locked_image_id;
+    VAImageID derived_image_id;
     void (*free_private_data)(void **data);
     void *private_data;
     unsigned int subsampling;
-- 
1.7.9.5



More information about the Libva mailing list