[Libva] [PATCH 3/9] Unify the XXX_free_avc_surface for media encoding/decoding

yakui.zhao at intel.com yakui.zhao at intel.com
Wed Oct 31 01:47:53 PDT 2012


From: Zhao Yakui <yakui.zhao at intel.com>

Signed-off-by: Zhao Yakui <yakui.zhao at intel.com>
---
 src/Makefile.am    |  1 +
 src/gen6_mfc.c     | 39 +++++++++-------------------
 src/gen6_mfd.c     |  1 +
 src/gen75_mfc.c    | 37 +++++++++------------------
 src/gen75_mfd.c    |  1 +
 src/gen7_mfd.c     |  1 +
 src/i965_avc_bsd.c |  1 +
 src/i965_decoder.h | 39 ----------------------------
 src/intel_media.h  | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 103 insertions(+), 91 deletions(-)
 create mode 100644 src/intel_media.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 923a945..69d101f 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -109,6 +109,7 @@ source_h = \
 	intel_driver.h          \
 	intel_memman.h          \
 	object_heap.h           \
+	intel_media.h           \
 	$(NULL)
 
 i965_drv_video_la_LTLIBRARIES	= i965_drv_video.la
diff --git a/src/gen6_mfc.c b/src/gen6_mfc.c
index 09d1110..af1047d 100644
--- a/src/gen6_mfc.c
+++ b/src/gen6_mfc.c
@@ -26,6 +26,10 @@
  *
  */
 
+#ifndef HAVE_GEN_AVC_SURFACE
+#define HAVE_GEN_AVC_SURFACE 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,7 +44,7 @@
 #include "i965_encoder_utils.h"
 #include "gen6_mfc.h"
 #include "gen6_vme.h"
-
+#include "intel_media.h"
 
 static const uint32_t gen6_mfc_batchbuffer_avc_intra[][4] = {
 #include "shaders/utils/mfc_batchbuffer_avc_intra.g6b"
@@ -637,25 +641,6 @@ static void gen6_mfc_avc_pipeline_picture_programing( VADriverContextP ctx,
     gen6_mfc_avc_ref_idx_state(ctx, encoder_context);
 }
 
-static void 
-gen6_mfc_free_avc_surface(void **data)
-{
-    struct gen6_mfc_avc_surface_aux *avc_surface = *data;
-
-    if (!avc_surface)
-        return;
-
-    dri_bo_unreference(avc_surface->dmv_top);
-    avc_surface->dmv_top = NULL;
-    dri_bo_unreference(avc_surface->dmv_bottom);
-    avc_surface->dmv_bottom = NULL;
-
-    free(avc_surface);
-    *data = NULL;
-}
-
-
-
 
 static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx, 
                                      struct encode_state *encode_state,
@@ -665,7 +650,7 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
     struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
     struct object_surface *obj_surface;	
     struct object_buffer *obj_buffer;
-    struct gen6_mfc_avc_surface_aux* gen6_avc_surface;
+    GenAvcSurface *gen6_avc_surface;
     dri_bo *bo;
     VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
@@ -702,7 +687,7 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
     i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
 
     if ( obj_surface->private_data == NULL) {
-        gen6_avc_surface = calloc(sizeof(struct gen6_mfc_avc_surface_aux), 1);
+        gen6_avc_surface = calloc(sizeof(GenAvcSurface), 1);
         gen6_avc_surface->dmv_top = 
             dri_bo_alloc(i965->intel.bufmgr,
                          "Buffer",
@@ -716,9 +701,9 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
         assert(gen6_avc_surface->dmv_top);
         assert(gen6_avc_surface->dmv_bottom);
         obj_surface->private_data = (void *)gen6_avc_surface;
-        obj_surface->free_private_data = (void *)gen6_mfc_free_avc_surface; 
+        obj_surface->free_private_data = (void *)gen_free_avc_surface; 
     }
-    gen6_avc_surface = (struct gen6_mfc_avc_surface_aux*) obj_surface->private_data;
+    gen6_avc_surface = (GenAvcSurface *) obj_surface->private_data;
     mfc_context->direct_mv_buffers[NUM_MFC_DMV_BUFFERS - 2].bo = gen6_avc_surface->dmv_top;
     mfc_context->direct_mv_buffers[NUM_MFC_DMV_BUFFERS - 1].bo = gen6_avc_surface->dmv_bottom;
     dri_bo_reference(gen6_avc_surface->dmv_top);
@@ -749,7 +734,7 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
             /* Check DMV buffer */
             if ( obj_surface->private_data == NULL) {
                 
-                gen6_avc_surface = calloc(sizeof(struct gen6_mfc_avc_surface_aux), 1);
+                gen6_avc_surface = calloc(sizeof(GenAvcSurface), 1);
                 gen6_avc_surface->dmv_top = 
                     dri_bo_alloc(i965->intel.bufmgr,
                                  "Buffer",
@@ -763,10 +748,10 @@ static VAStatus gen6_mfc_avc_prepare(VADriverContextP ctx,
                 assert(gen6_avc_surface->dmv_top);
                 assert(gen6_avc_surface->dmv_bottom);
                 obj_surface->private_data = gen6_avc_surface;
-                obj_surface->free_private_data = gen6_mfc_free_avc_surface; 
+                obj_surface->free_private_data = gen_free_avc_surface; 
             }
     
-            gen6_avc_surface = (struct gen6_mfc_avc_surface_aux*) obj_surface->private_data;
+            gen6_avc_surface = (GenAvcSurface *) obj_surface->private_data;
             /* Setup DMV buffer */
             mfc_context->direct_mv_buffers[i*2].bo = gen6_avc_surface->dmv_top;
             mfc_context->direct_mv_buffers[i*2+1].bo = gen6_avc_surface->dmv_bottom; 
diff --git a/src/gen6_mfd.c b/src/gen6_mfd.c
index b3ee17f..0811226 100755
--- a/src/gen6_mfd.c
+++ b/src/gen6_mfd.c
@@ -43,6 +43,7 @@
 #include "i965_decoder_utils.h"
 
 #include "gen6_mfd.h"
+#include "intel_media.h"
 
 static const uint32_t zigzag_direct[64] = {
     0,   1,  8, 16,  9,  2,  3, 10,
diff --git a/src/gen75_mfc.c b/src/gen75_mfc.c
index f15bd84..eecdd8d 100644
--- a/src/gen75_mfc.c
+++ b/src/gen75_mfc.c
@@ -27,6 +27,10 @@
  *
  */
 
+#ifndef HAVE_GEN_AVC_SURFACE
+#define HAVE_GEN_AVC_SURFACE 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -41,6 +45,7 @@
 #include "i965_encoder_utils.h"
 #include "gen6_mfc.h"
 #include "gen6_vme.h"
+#include "intel_media.h"
 
 #define MFC_SOFTWARE_HASWELL	1
 
@@ -408,24 +413,6 @@ gen75_mfc_avc_insert_object(VADriverContextP ctx, struct intel_encoder_context *
 }
 
 
-
-static void 
-gen75_mfc_free_avc_surface(void **data)
-{
-    struct gen6_mfc_avc_surface_aux *avc_surface = *data;
-
-    if (!avc_surface)
-        return;
-
-    dri_bo_unreference(avc_surface->dmv_top);
-    avc_surface->dmv_top = NULL;
-    dri_bo_unreference(avc_surface->dmv_bottom);
-    avc_surface->dmv_bottom = NULL;
-
-    free(avc_surface);
-    *data = NULL;
-}
-
 static void gen75_mfc_init(VADriverContextP ctx, struct intel_encoder_context *encoder_context)
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
@@ -857,7 +844,7 @@ static VAStatus gen75_mfc_avc_prepare(VADriverContextP ctx,
     struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
     struct object_surface *obj_surface;	
     struct object_buffer *obj_buffer;
-    struct gen6_mfc_avc_surface_aux* gen6_avc_surface;
+    GenAvcSurface *gen6_avc_surface;
     dri_bo *bo;
     VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
@@ -894,7 +881,7 @@ static VAStatus gen75_mfc_avc_prepare(VADriverContextP ctx,
     i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420);
 
     if ( obj_surface->private_data == NULL) {
-        gen6_avc_surface = calloc(sizeof(struct gen6_mfc_avc_surface_aux), 1);
+        gen6_avc_surface = calloc(sizeof(GenAvcSurface), 1);
         gen6_avc_surface->dmv_top = 
             dri_bo_alloc(i965->intel.bufmgr,
                          "Buffer",
@@ -908,9 +895,9 @@ static VAStatus gen75_mfc_avc_prepare(VADriverContextP ctx,
         assert(gen6_avc_surface->dmv_top);
         assert(gen6_avc_surface->dmv_bottom);
         obj_surface->private_data = (void *)gen6_avc_surface;
-        obj_surface->free_private_data = (void *)gen75_mfc_free_avc_surface; 
+        obj_surface->free_private_data = (void *)gen_free_avc_surface; 
     }
-    gen6_avc_surface = (struct gen6_mfc_avc_surface_aux*) obj_surface->private_data;
+    gen6_avc_surface = (GenAvcSurface *) obj_surface->private_data;
     mfc_context->direct_mv_buffers[NUM_MFC_DMV_BUFFERS - 2].bo = gen6_avc_surface->dmv_top;
     mfc_context->direct_mv_buffers[NUM_MFC_DMV_BUFFERS - 1].bo = gen6_avc_surface->dmv_bottom;
     dri_bo_reference(gen6_avc_surface->dmv_top);
@@ -941,7 +928,7 @@ static VAStatus gen75_mfc_avc_prepare(VADriverContextP ctx,
             /* Check DMV buffer */
             if ( obj_surface->private_data == NULL) {
                 
-                gen6_avc_surface = calloc(sizeof(struct gen6_mfc_avc_surface_aux), 1);
+                gen6_avc_surface = calloc(sizeof(GenAvcSurface), 1);
                 gen6_avc_surface->dmv_top = 
                     dri_bo_alloc(i965->intel.bufmgr,
                                  "Buffer",
@@ -955,10 +942,10 @@ static VAStatus gen75_mfc_avc_prepare(VADriverContextP ctx,
                 assert(gen6_avc_surface->dmv_top);
                 assert(gen6_avc_surface->dmv_bottom);
                 obj_surface->private_data = gen6_avc_surface;
-                obj_surface->free_private_data = gen75_mfc_free_avc_surface; 
+                obj_surface->free_private_data = gen_free_avc_surface; 
             }
     
-            gen6_avc_surface = (struct gen6_mfc_avc_surface_aux*) obj_surface->private_data;
+            gen6_avc_surface = (GenAvcSurface *) obj_surface->private_data;
             /* Setup DMV buffer */
             mfc_context->direct_mv_buffers[i*2].bo = gen6_avc_surface->dmv_top;
             mfc_context->direct_mv_buffers[i*2+1].bo = gen6_avc_surface->dmv_bottom; 
diff --git a/src/gen75_mfd.c b/src/gen75_mfd.c
index 80b7881..4d63c83 100644
--- a/src/gen75_mfd.c
+++ b/src/gen75_mfd.c
@@ -45,6 +45,7 @@
 #include "i965_decoder_utils.h"
 
 #include "gen7_mfd.h"
+#include "intel_media.h"
 
 #define B0_STEP_REV		2
 #define IS_STEPPING_BPLUS(i965)	((i965->intel.revision) >= B0_STEP_REV)
diff --git a/src/gen7_mfd.c b/src/gen7_mfd.c
index 4d3a260..1515e2a 100755
--- a/src/gen7_mfd.c
+++ b/src/gen7_mfd.c
@@ -44,6 +44,7 @@
 #include "i965_decoder_utils.h"
 
 #include "gen7_mfd.h"
+#include "intel_media.h"
 
 static const uint32_t zigzag_direct[64] = {
     0,   1,  8, 16,  9,  2,  3, 10,
diff --git a/src/i965_avc_bsd.c b/src/i965_avc_bsd.c
index 667e29f..439498a 100644
--- a/src/i965_avc_bsd.c
+++ b/src/i965_avc_bsd.c
@@ -43,6 +43,7 @@
 #include "i965_media_h264.h"
 #include "i965_media.h"
 #include "i965_decoder_utils.h"
+#include "intel_media.h"
 
 static void
 i965_avc_bsd_init_avc_bsd_surface(VADriverContextP ctx, 
diff --git a/src/i965_decoder.h b/src/i965_decoder.h
index 5de8085..f36df44 100644
--- a/src/i965_decoder.h
+++ b/src/i965_decoder.h
@@ -45,45 +45,6 @@ struct gen_buffer {
     int         valid;
 };
 
-#if HAVE_GEN_AVC_SURFACE
-
-static pthread_mutex_t free_avc_surface_lock = PTHREAD_MUTEX_INITIALIZER;
-
-typedef struct gen_avc_surface GenAvcSurface;
-struct gen_avc_surface
-{
-    dri_bo *dmv_top;
-    dri_bo *dmv_bottom;
-    int dmv_bottom_flag;
-};
-
-static void 
-gen_free_avc_surface(void **data)
-{
-    GenAvcSurface *avc_surface;
-
-    pthread_mutex_lock(&free_avc_surface_lock);
-
-    avc_surface = *data;
-
-    if (!avc_surface) {
-        pthread_mutex_unlock(&free_avc_surface_lock);
-        return;
-    }
-
-
-    dri_bo_unreference(avc_surface->dmv_top);
-    avc_surface->dmv_top = NULL;
-    dri_bo_unreference(avc_surface->dmv_bottom);
-    avc_surface->dmv_bottom = NULL;
-
-    free(avc_surface);
-    *data = NULL;
-
-    pthread_mutex_unlock(&free_avc_surface_lock);
-}
-
-#endif
 
 struct hw_context *
 gen75_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config);
diff --git a/src/intel_media.h b/src/intel_media.h
new file mode 100644
index 0000000..5493c60
--- /dev/null
+++ b/src/intel_media.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef INTEL_MEDIA_H
+#define INTEL_MEDIA_H
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <va/va.h>
+#include <intel_bufmgr.h>
+
+#if HAVE_GEN_AVC_SURFACE
+
+static pthread_mutex_t free_avc_surface_lock = PTHREAD_MUTEX_INITIALIZER;
+
+typedef struct gen_avc_surface GenAvcSurface;
+struct gen_avc_surface
+{
+    dri_bo *dmv_top;
+    dri_bo *dmv_bottom;
+    int dmv_bottom_flag;
+};
+
+static void 
+gen_free_avc_surface(void **data)
+{
+    GenAvcSurface *avc_surface;
+
+    pthread_mutex_lock(&free_avc_surface_lock);
+
+    avc_surface = *data;
+
+    if (!avc_surface) {
+        pthread_mutex_unlock(&free_avc_surface_lock);
+        return;
+    }
+
+
+    dri_bo_unreference(avc_surface->dmv_top);
+    avc_surface->dmv_top = NULL;
+    dri_bo_unreference(avc_surface->dmv_bottom);
+    avc_surface->dmv_bottom = NULL;
+
+    free(avc_surface);
+    *data = NULL;
+
+    pthread_mutex_unlock(&free_avc_surface_lock);
+}
+
+#endif
+
+#endif /* INTEL_MEDIA_H */
-- 
1.7.12-rc1



More information about the Libva mailing list