Clean up for setting up reference surface state
authorXiang, Haihao <haihao.xiang@intel.com>
Sun, 29 Sep 2013 06:53:12 +0000 (14:53 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Wed, 13 Nov 2013 07:28:39 +0000 (15:28 +0800)
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
(cherry picked from commit 939b6bef6d8f8ecfee589cf70fde51f7a34175a1)

src/gen6_mfc_common.c
src/gen6_vme.c
src/gen6_vme.h
src/gen75_vme.c
src/gen7_vme.c

index d66f4c5..7761e97 100644 (file)
@@ -1310,3 +1310,38 @@ gen7_vme_mpeg2_walker_fill_vme_batchbuffer(VADriverContextP ctx,
     dri_bo_unmap(vme_context->vme_batchbuffer.bo);
     return;
 }
+
+void
+intel_avc_vme_reference_state(VADriverContextP ctx,
+                              struct encode_state *encode_state,
+                              struct intel_encoder_context *encoder_context,
+                              int list_index,
+                              int surface_index,
+                              void (* vme_source_surface_state)(
+                                  VADriverContextP ctx,
+                                  int index,
+                                  struct object_surface *obj_surface,
+                                  struct intel_encoder_context *encoder_context))
+{
+    struct object_surface *obj_surface = NULL;
+    struct i965_driver_data *i965 = i965_driver_data(ctx);
+    VASurfaceID ref_surface_id;
+    VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
+
+    if (list_index == 0) {
+        ref_surface_id = slice_param->RefPicList0[0].picture_id;
+    } else {
+        ref_surface_id = slice_param->RefPicList1[0].picture_id;
+    }
+
+    if (ref_surface_id != VA_INVALID_SURFACE)
+        obj_surface = SURFACE(ref_surface_id);
+
+    if (!obj_surface ||
+        !obj_surface->bo)
+        obj_surface = encode_state->reference_objects[list_index];
+
+    if (obj_surface &&
+        obj_surface->bo)
+        vme_source_surface_state(ctx, surface_index, obj_surface, encoder_context);
+}
index e1403d2..dbe099c 100644 (file)
@@ -204,7 +204,6 @@ gen6_vme_surface_setup(VADriverContextP ctx,
                        struct intel_encoder_context *encoder_context)
 {
     struct object_surface *obj_surface;
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -215,42 +214,14 @@ gen6_vme_surface_setup(VADriverContextP ctx,
     if (!is_intra) {
        VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
        int slice_type;
-       struct object_surface *slice_obj_surface;
-       int ref_surface_id;
 
        slice_type = intel_avc_enc_slice_type_fixup(slice_param->slice_type);
+        assert(slice_type != SLICE_TYPE_I && slice_type != SLICE_TYPE_SI);
 
-       if (slice_type == SLICE_TYPE_P || slice_type == SLICE_TYPE_B) {
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList0[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[0];
-            }
-            /* reference 0 */
-            if (obj_surface && obj_surface->bo)
-                gen6_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
-       }
-       if (slice_type == SLICE_TYPE_B) {
-            /* reference 1 */
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList1[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[1];
-            }
+        intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 0, 1, gen6_vme_source_surface_state);
 
-            if (obj_surface && obj_surface->bo)
-                gen6_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
-       }
+       if (slice_type == SLICE_TYPE_B)
+            intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 1, 2, gen6_vme_source_surface_state);
     }
 
     /* VME output */
index 09d9673..5841cfd 100644 (file)
@@ -158,4 +158,16 @@ gen7_vme_mpeg2_walker_fill_vme_batchbuffer(VADriverContextP ctx,
                                            int kernel,
                                            struct intel_encoder_context *encoder_context);
 
+void
+intel_avc_vme_reference_state(VADriverContextP ctx,
+                              struct encode_state *encode_state,
+                              struct intel_encoder_context *encoder_context,
+                              int list_index,
+                              int surface_index,
+                              void (* vme_source_surface_state)(
+                                  VADriverContextP ctx,
+                                  int index,
+                                  struct object_surface *obj_surface,
+                                  struct intel_encoder_context *encoder_context));
+
 #endif /* _GEN6_VME_H_ */
index b1596fa..979b109 100644 (file)
@@ -264,7 +264,6 @@ gen75_vme_surface_setup(VADriverContextP ctx,
                         struct intel_encoder_context *encoder_context)
 {
     struct object_surface *obj_surface;
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -276,42 +275,14 @@ gen75_vme_surface_setup(VADriverContextP ctx,
     if (!is_intra) {
        VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
        int slice_type;
-       struct object_surface *slice_obj_surface;
-       int ref_surface_id;
 
        slice_type = intel_avc_enc_slice_type_fixup(slice_param->slice_type);
+        assert(slice_type != SLICE_TYPE_I && slice_type != SLICE_TYPE_SI);
 
-       if (slice_type == SLICE_TYPE_P || slice_type == SLICE_TYPE_B) {
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList0[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[0];
-            }
-            /* reference 0 */
-            if (obj_surface && obj_surface->bo)
-                gen75_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
-       }
-       if (slice_type == SLICE_TYPE_B) {
-            /* reference 1 */
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList1[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[1];
-            }
+        intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 0, 1, gen75_vme_source_surface_state);
 
-            if (obj_surface && obj_surface->bo)
-                gen75_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
-       }
+       if (slice_type == SLICE_TYPE_B)
+            intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 1, 2, gen75_vme_source_surface_state);
     }
 
     /* VME output */
index 8594b0f..ed2ee5a 100644 (file)
@@ -250,7 +250,6 @@ gen7_vme_surface_setup(VADriverContextP ctx,
                        struct intel_encoder_context *encoder_context)
 {
     struct object_surface *obj_surface;
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -261,42 +260,14 @@ gen7_vme_surface_setup(VADriverContextP ctx,
     if (!is_intra) {
        VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
        int slice_type;
-       struct object_surface *slice_obj_surface;
-       int ref_surface_id;
 
        slice_type = intel_avc_enc_slice_type_fixup(slice_param->slice_type);
+        assert(slice_type != SLICE_TYPE_I && slice_type != SLICE_TYPE_SI);
 
-       if (slice_type == SLICE_TYPE_P || slice_type == SLICE_TYPE_B) {
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList0[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[0];
-            }
-            /* reference 0 */
-            if (obj_surface && obj_surface->bo)
-                gen7_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
-       }
-       if (slice_type == SLICE_TYPE_B) {
-            /* reference 1 */
-            slice_obj_surface = NULL;
-            ref_surface_id = slice_param->RefPicList1[0].picture_id;
-            if (ref_surface_id != VA_INVALID_SURFACE) {
-                slice_obj_surface = SURFACE(ref_surface_id);
-            }
-            if (slice_obj_surface && slice_obj_surface->bo) {
-                obj_surface = slice_obj_surface;
-            } else {
-                obj_surface = encode_state->reference_objects[1];
-            }
+        intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 0, 1, gen7_vme_source_surface_state);
 
-            if (obj_surface && obj_surface->bo)
-                gen7_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
-       }
+       if (slice_type == SLICE_TYPE_B)
+            intel_avc_vme_reference_state(ctx, encode_state, encoder_context, 1, 2, gen7_vme_source_surface_state);
     }
 
     /* VME output */