[Libva] [PATCH] avcenc.c: use multi-slice encoding

Haitao Huang haitao.huang at intel.com
Wed Aug 22 08:04:48 PDT 2012


Change-Id: Ibb5e03ddb6165aeb298a2960d369cb22fa948453
Signed-off-by: Haitao Huang <haitao.huang at intel.com>
---
 test/encode/avcenc.c |   96 ++++++++++++++++++++++----------------------------
 1 files changed, 42 insertions(+), 54 deletions(-)

diff --git a/test/encode/avcenc.c b/test/encode/avcenc.c
index 54761a5..1d501b3 100644
--- a/test/encode/avcenc.c
+++ b/test/encode/avcenc.c
@@ -367,63 +367,51 @@ static void avcenc_update_slice_parameter(int slice_type)
 {
     VAEncSliceParameterBufferH264 *slice_param;
     VAStatus va_status;
-    int i;
-
-    // Slice level
-    i = 0;
-    slice_param = &avcenc_context.slice_param[i];
-    slice_param->macroblock_address = 0;
-    slice_param->num_macroblocks = picture_height_in_mbs * picture_width_in_mbs; 
-    slice_param->pic_parameter_set_id = 0;
-    slice_param->slice_type = slice_type;
-    slice_param->direct_spatial_mv_pred_flag = 0;
-    slice_param->num_ref_idx_l0_active_minus1 = 0;      /* FIXME: ??? */
-    slice_param->num_ref_idx_l1_active_minus1 = 0;
-    slice_param->cabac_init_idc = 0;
-    slice_param->slice_qp_delta = 0;
-    slice_param->disable_deblocking_filter_idc = 0;
-    slice_param->slice_alpha_c0_offset_div2 = 2;
-    slice_param->slice_beta_offset_div2 = 2;
-    slice_param->idr_pic_id = 0;
-
-    /* FIXME: fill other fields */
+    int sliceIndex, actualSliceHeightInMB;
+    int sliceNum=2;
+
+    int unevenRowsInMB = picture_height_in_mbs % sliceNum;
+    int sliceHeightInMB = (picture_height_in_mbs - unevenRowsInMB) / sliceNum ;
+
+    int startAddressInMB = 0;
+
+    for (sliceIndex = 0; sliceIndex < sliceNum; sliceIndex++) {
+
+        slice_param = &avcenc_context.slice_param[sliceIndex];
+        slice_param->pic_parameter_set_id = 0;
+        slice_param->slice_type = slice_type;
+        slice_param->direct_spatial_mv_pred_flag = 0;
+        slice_param->num_ref_idx_l0_active_minus1 = 0;      /* FIXME: ??? */
+        slice_param->num_ref_idx_l1_active_minus1 = 0;
+        slice_param->cabac_init_idc = 0;
+        slice_param->slice_qp_delta = 0;
+        slice_param->disable_deblocking_filter_idc = 0;
+        slice_param->slice_alpha_c0_offset_div2 = 2;
+        slice_param->slice_beta_offset_div2 = 2;
+        slice_param->idr_pic_id = 0;
+
+        actualSliceHeightInMB = sliceHeightInMB;
+        if (sliceIndex < unevenRowsInMB) {
+            //spread the remaining MB rows evenly one each for first few slices
+            actualSliceHeightInMB ++;
+        }
+        slice_param->macroblock_address = startAddressInMB;
+        slice_param->num_macroblocks = actualSliceHeightInMB * picture_width_in_mbs;
 
-    va_status = vaCreateBuffer(va_dpy,
-                               avcenc_context.context_id,
-                               VAEncSliceParameterBufferType,
-                               sizeof(*slice_param), 1, slice_param,
-                               &avcenc_context.slice_param_buf_id[i]);
-    CHECK_VASTATUS(va_status,"vaCreateBuffer");;
-    i++;
+        /* FIXME: fill other fields */
+        va_status = vaCreateBuffer(
+                va_dpy,
+                avcenc_context.context_id,
+                VAEncSliceParameterBufferType,
+                sizeof(VAEncSliceParameterBufferH264),
+                1, slice_param,
+                &avcenc_context.slice_param_buf_id[sliceIndex]);
+        CHECK_VASTATUS(va_status,"vaCreateBuffer")
 
-#if 0
-    slice_param = &avcenc_context.slice_param[i];
-    slice_param->macroblock_address = picture_height_in_mbs * picture_width_in_mbs / 2;
-    slice_param->num_macroblocks = picture_height_in_mbs * picture_width_in_mbs / 2;
-    slice_param->pic_parameter_set_id = 0;
-    slice_param->slice_type = slice_type;
-    slice_param->direct_spatial_mv_pred_flag = 0;
-    slice_param->num_ref_idx_l0_active_minus1 = 0;      /* FIXME: ??? */
-    slice_param->num_ref_idx_l1_active_minus1 = 0;
-    slice_param->cabac_init_idc = 0;
-    slice_param->slice_qp_delta = 0;
-    slice_param->disable_deblocking_filter_idc = 0;
-    slice_param->slice_alpha_c0_offset_div2 = 2;
-    slice_param->slice_beta_offset_div2 = 2;
-    slice_param->idr_pic_id = 0;
-
-    /* FIXME: fill other fields */
 
-    va_status = vaCreateBuffer(va_dpy,
-                               avcenc_context.context_id,
-                               VAEncSliceParameterBufferType,
-                               sizeof(*slice_param), 1, slice_param,
-                               &avcenc_context.slice_param_buf_id[i]);
-    CHECK_VASTATUS(va_status,"vaCreateBuffer");;
-    i++;
-#endif
-
-    avcenc_context.num_slices = i;
+        startAddressInMB += actualSliceHeightInMB*picture_width_in_mbs;
+    }
+    avcenc_context.num_slices = sliceNum;
 }
 
 static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice_type, int is_idr)
-- 
1.7.5.4



More information about the Libva mailing list