[Libva] [PATCH 3/3] Encoding: Add support for grouped submission of packed slice headers

sreerenj.balachandran at intel.com sreerenj.balachandran at intel.com
Wed May 28 14:02:43 PDT 2014


From: Sreerenj Balachandran <sreerenj.balachandran at intel.com>

This is adding the necessary fixes to provide support for
the grouped submission of all packed slice headers (packed slice
headers are not paired with the submission of VAEncSliceParameterBuffer)
from the upper layer in multiple slice per frame encoding scenario.
---
 src/i965_drv_video.c | 48 ++++++++++++++++++++++++++++++++++++++----------
 src/i965_drv_video.h |  3 +++
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index 4854a62..13593d7 100755
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -1617,8 +1617,10 @@ i965_CreateContext(VADriverContextP ctx,
             obj_context->codec_state.encode.slice_rawdata_count =
                 calloc(obj_context->codec_state.encode.slice_num, sizeof(int));
 
+            obj_context->codec_state.encode.max_packed_slice_header_ext = NUM_SLICES;
             obj_context->codec_state.encode.slice_header_index =
-                calloc(obj_context->codec_state.encode.slice_num, sizeof(int));
+                calloc(obj_context->codec_state.encode.max_packed_slice_header_ext,
+                    sizeof(int));
 
             assert(i965->codec_info->enc_hw_context_init);
             obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
@@ -2053,6 +2055,7 @@ i965_BeginPicture(VADriverContextP ctx,
             i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
         obj_context->codec_state.encode.num_packed_header_params_ext = 0;
         obj_context->codec_state.encode.num_packed_header_data_ext = 0;
+        obj_context->codec_state.encode.num_packed_slice_header_ext = 0;
     } else {
         obj_context->codec_state.decode.current_render_target = render_target;
         i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
@@ -2299,14 +2302,21 @@ i965_encoder_render_picture(VADriverContextP ctx,
                                                           encode->slice_num * sizeof(int));
                     encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
                                                           encode->slice_num * sizeof(int));
-                    encode->slice_header_index = realloc(encode->slice_header_index,
-                                                          encode->slice_num * sizeof(int));
+                    
                     memset(encode->slice_rawdata_index + slice_num, 0,
                         sizeof(int) * NUM_SLICES);
                     memset(encode->slice_rawdata_count + slice_num, 0,
                         sizeof(int) * NUM_SLICES);
-                    memset(encode->slice_header_index + slice_num, 0,
-                        sizeof(int) * NUM_SLICES);
+                    /* Even though the driver is not working in packed slice header
+                    * mode, we should allocate enough space for for the
+                    * slice_header_index array to avoid array dereferening issues in
+                    * other parts of the implementation */
+                    if (encode->num_packed_slice_header_ext == 0) {
+                        encode->slice_header_index = realloc(
+                            encode->slice_header_index, encode->slice_num * sizeof(int));
+                        memset(encode->slice_header_index + slice_num, 0,
+                            sizeof(int) * NUM_SLICES);
+                    }
                     if ((encode->slice_rawdata_index == NULL) ||
                         (encode->slice_header_index == NULL)  ||
                         (encode->slice_rawdata_count == NULL)) {
@@ -2355,12 +2365,30 @@ i965_encoder_render_picture(VADriverContextP ctx,
                 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
                 if (vaStatus == VA_STATUS_SUCCESS) {
                     if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
-                        if (encode->slice_header_index[encode->num_slice_params_ext] == 0) {
-                            encode->slice_header_index[encode->num_slice_params_ext] =
-                                SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
-                        } else {
+                        if (encode->max_packed_slice_header_ext <=
+                            encode->num_packed_slice_header_ext) {
+                            encode->max_packed_slice_header_ext += NUM_SLICES;
+
+                            encode->slice_header_index = realloc(
+                                encode->slice_header_index,
+                                encode->max_packed_slice_header_ext * sizeof(int));
+
+                            memset(encode->slice_header_index +
+                                encode->num_packed_slice_header_ext, 0,
+                                sizeof(int) * NUM_SLICES);
+
+                           if (encode->slice_header_index == NULL){
+                                vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
+                               return vaStatus;
+                           }
+                       }
+                       if (encode->slice_header_index[encode->num_packed_slice_header_ext] == 0) {
+                           encode->slice_header_index[encode->num_packed_slice_header_ext] =
+                           SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
+                           encode->num_packed_slice_header_ext++;
+                       } else {
                             WARN_ONCE("Multi slice header data is passed for"
-                                      " slice %d!\n", encode->num_slice_params_ext);
+                                      " slice %d!\n", encode->num_packed_slice_header_ext);
                         }
                     }
                 }
diff --git a/src/i965_drv_video.h b/src/i965_drv_video.h
index aae9735..7cdd002 100644
--- a/src/i965_drv_video.h
+++ b/src/i965_drv_video.h
@@ -161,6 +161,9 @@ struct encode_state
 
     /* This is to store the index of packed slice header for one slice */
     int *slice_header_index;
+    /* This is to track the packed slice header count */
+    int num_packed_slice_header_ext;
+    int max_packed_slice_header_ext;
 
     int last_packed_header_type;
 
-- 
1.9.1



More information about the Libva mailing list