[Mesa-dev] [PATCH 07/15] st/va: implement vlVa(Create|Destroy)Context

Christian König deathsimple at vodafone.de
Tue Jun 18 02:27:37 PDT 2013


From: Christian König <christian.koenig at amd.com>

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/gallium/state_trackers/va/context.c    |   71 +++++++++++++++++++++++-----
 src/gallium/state_trackers/va/va_private.h |   12 +++++
 2 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/src/gallium/state_trackers/va/context.c b/src/gallium/state_trackers/va/context.c
index 51eb259..d535a6b 100644
--- a/src/gallium/state_trackers/va/context.c
+++ b/src/gallium/state_trackers/va/context.c
@@ -96,17 +96,16 @@ __vaDriverInit_0_32(VADriverContextP ctx)
       return VA_STATUS_ERROR_ALLOCATION_FAILED;
 
    drv->vscreen = vl_screen_create(ctx->native_dpy, ctx->x11_screen);
-   if (!drv->vscreen) {
-      FREE(drv);
-      return VA_STATUS_ERROR_ALLOCATION_FAILED;
-   }
+   if (!drv->vscreen)
+      goto error_screen;
+
+   drv->pipe = drv->vscreen->pscreen->context_create(drv->vscreen->pscreen, drv->vscreen);
+   if (!drv->pipe)
+      goto error_pipe;
 
    drv->htab = handle_table_create();
-   if (!drv->htab) {
-      vl_screen_destroy(drv->vscreen);
-      FREE(drv);
-      return VA_STATUS_ERROR_ALLOCATION_FAILED;
-   }
+   if (!drv->htab)
+      goto error_htab;
 
    ctx->pDriverData = (void *)drv;
    ctx->version_major = 0;
@@ -121,26 +120,71 @@ __vaDriverInit_0_32(VADriverContextP ctx)
    ctx->str_vendor = "mesa gallium vaapi";
 
    return VA_STATUS_SUCCESS;
+
+error_htab:
+   drv->pipe->destroy(drv->pipe);
+
+error_pipe:
+   vl_screen_destroy(drv->vscreen);
+
+error_screen:
+   FREE(drv);
+   return VA_STATUS_ERROR_ALLOCATION_FAILED;
 }
 
 VAStatus
 vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,
                   int picture_height, int flag, VASurfaceID *render_targets,
-                  int num_render_targets, VAContextID *conext)
+                  int num_render_targets, VAContextID *context_id)
 {
+   vlVaDriver *drv;
+   vlVaContext *context;
+
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-   return VA_STATUS_ERROR_UNIMPLEMENTED;
+   if (!(picture_width && picture_height))
+      return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
+
+   drv = VL_VA_DRIVER(ctx);
+   context = CALLOC(1, sizeof(vlVaContext));
+   if (!context)
+      return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+   context->decoder = drv->pipe->create_video_decoder
+   (
+      drv->pipe, config_id,
+      PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
+      PIPE_VIDEO_CHROMA_FORMAT_420,
+      picture_width, picture_height, num_render_targets,
+      true
+   );
+   if (!context->decoder) {
+      FREE(context);
+      return VA_STATUS_ERROR_ALLOCATION_FAILED;
+   }
+
+   context->desc.base.profile = config_id;
+   *context_id = handle_table_add(drv->htab, context);
+
+   return VA_STATUS_SUCCESS;
 }
 
 VAStatus
-vlVaDestroyContext(VADriverContextP ctx, VAContextID context)
+vlVaDestroyContext(VADriverContextP ctx, VAContextID context_id)
 {
+   vlVaDriver *drv;
+   vlVaContext *context;
+
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-   return VA_STATUS_ERROR_UNIMPLEMENTED;
+   drv = VL_VA_DRIVER(ctx);
+   context = handle_table_get(drv->htab, context_id);
+   context->decoder->destroy(context->decoder);
+   FREE(context);
+
+   return VA_STATUS_SUCCESS;
 }
 
 VAStatus
@@ -152,6 +196,7 @@ vlVaTerminate(VADriverContextP ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
    drv = ctx->pDriverData;
+   drv->pipe->destroy(drv->pipe);
    vl_screen_destroy(drv->vscreen);
    handle_table_destroy(drv->htab);
    FREE(drv);
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h
index 88418f9..fcc1c59 100644
--- a/src/gallium/state_trackers/va/va_private.h
+++ b/src/gallium/state_trackers/va/va_private.h
@@ -117,10 +117,22 @@ ProfileToPipe(VAProfile profile)
 
 typedef struct {
    struct vl_screen *vscreen;
+   struct pipe_context *pipe;
    struct handle_table *htab;
 } vlVaDriver;
 
 typedef struct {
+   struct pipe_video_decoder *decoder;
+   union {
+      struct pipe_picture_desc base;
+      struct pipe_mpeg12_picture_desc mpeg12;
+      struct pipe_mpeg4_picture_desc mpeg4;
+      struct pipe_vc1_picture_desc vc1;
+      struct pipe_h264_picture_desc h264;
+   } desc;
+} vlVaContext;
+
+typedef struct {
    struct pipe_video_buffer templat, *buffer;
 } vlVaSurface;
 
-- 
1.7.9.5



More information about the mesa-dev mailing list