Encoder: directly use the objects for the reference pictures
authorXiang, Haihao <haihao.xiang@intel.com>
Tue, 12 Mar 2013 07:34:21 +0000 (15:34 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Fri, 15 Mar 2013 07:45:28 +0000 (15:45 +0800)
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
src/gen6_mfc_common.c
src/gen6_vme.c
src/gen75_mfc.c
src/gen75_vme.c
src/gen7_mfc.c
src/gen7_vme.c
src/i965_drv_video.h
src/i965_encoder.c

index d7aae3c..1796e95 100644 (file)
@@ -515,7 +515,6 @@ VAStatus intel_mfc_avc_prepare(VADriverContextP ctx,
     struct object_buffer *obj_buffer;
     GenAvcSurface *gen6_avc_surface;
     dri_bo *bo;
-    VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     int i, j, enable_avc_ildb = 0;
     VAEncSliceParameterBufferH264 *slice_param;
@@ -593,13 +592,12 @@ VAStatus intel_mfc_avc_prepare(VADriverContextP ctx,
     
     /* Setup reference frames and direct mv buffers*/
     for(i = 0; i < MAX_MFC_REFERENCE_SURFACES; i++) {
-        if ( pPicParameter->ReferenceFrames[i].picture_id != VA_INVALID_ID ) { 
-            obj_surface = SURFACE(pPicParameter->ReferenceFrames[i].picture_id);
-            assert(obj_surface);
-            if (obj_surface->bo != NULL) {
-                mfc_context->reference_surfaces[i].bo = obj_surface->bo;
-                dri_bo_reference(obj_surface->bo);
-            }
+        obj_surface = encode_state->reference_objects[i];
+        
+        if (obj_surface && obj_surface->bo) {
+            mfc_context->reference_surfaces[i].bo = obj_surface->bo;
+            dri_bo_reference(obj_surface->bo);
+
             /* Check DMV buffer */
             if ( obj_surface->private_data == NULL) {
                 
index 3d5baa5..200a273 100644 (file)
@@ -271,9 +271,7 @@ gen6_vme_surface_setup(VADriverContextP ctx,
                        int is_intra,
                        struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -283,15 +281,15 @@ gen6_vme_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[0].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+
+        if (obj_surface && obj_surface->bo)
             gen6_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[1].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL 
+        obj_surface = encode_state->reference_objects[1];
+
+        if (obj_surface && obj_surface->bo
             gen6_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
 
@@ -734,9 +732,7 @@ gen6_vme_mpeg2_surface_setup(VADriverContextP ctx,
                               int is_intra,
                               struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -746,13 +742,12 @@ gen6_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pic_param->forward_reference_picture);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+        if (obj_surface->bo != NULL)
             gen6_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pic_param->backward_reference_picture);
+        obj_surface = encode_state->reference_objects[1];
         if (obj_surface && obj_surface->bo != NULL) 
             gen6_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
index 2674aef..2fbac6f 100644 (file)
@@ -2400,11 +2400,9 @@ intel_mfc_mpeg2_prepare(VADriverContextP ctx,
                         struct encode_state *encode_state,
                         struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
     struct object_surface *obj_surface;        
     struct object_buffer *obj_buffer;
-    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
     struct i965_coded_buffer_segment *coded_buffer_segment;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     dri_bo *bo;
@@ -2421,7 +2419,7 @@ intel_mfc_mpeg2_prepare(VADriverContextP ctx,
     mfc_context->surface_state.h_pitch = obj_surface->height;
 
     /* forward reference */
-    obj_surface = SURFACE(pic_param->forward_reference_picture);
+    obj_surface = encode_state->reference_objects[0];
 
     if (obj_surface && obj_surface->bo) {
         mfc_context->reference_surfaces[0].bo = obj_surface->bo;
@@ -2430,7 +2428,7 @@ intel_mfc_mpeg2_prepare(VADriverContextP ctx,
         mfc_context->reference_surfaces[0].bo = NULL;
 
     /* backward reference */
-    obj_surface = SURFACE(pic_param->backward_reference_picture);
+    obj_surface = encode_state->reference_objects[1];
 
     if (obj_surface && obj_surface->bo) {
         mfc_context->reference_surfaces[1].bo = obj_surface->bo;
index 37751cf..2a0df88 100644 (file)
@@ -266,9 +266,7 @@ gen75_vme_surface_setup(VADriverContextP ctx,
                         int is_intra,
                         struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -279,15 +277,15 @@ gen75_vme_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[0].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+
+        if (obj_surface && obj_surface->bo)
             gen75_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[1].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL ) 
+        obj_surface = encode_state->reference_objects[1];
+
+        if (obj_surface && obj_surface->bo)
             gen75_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
 
@@ -776,9 +774,7 @@ gen75_vme_mpeg2_surface_setup(VADriverContextP ctx,
                               int is_intra,
                               struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -789,13 +785,12 @@ gen75_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pic_param->forward_reference_picture);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+        if (obj_surface->bo != NULL)
             gen75_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pic_param->backward_reference_picture);
+        obj_surface = encode_state->reference_objects[1];
         if (obj_surface && obj_surface->bo != NULL) 
             gen75_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
index 73c01ac..8572b89 100644 (file)
@@ -1005,11 +1005,9 @@ gen7_mfc_mpeg2_prepare(VADriverContextP ctx,
                         struct encode_state *encode_state,
                         struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
     struct object_surface *obj_surface;
     struct object_buffer *obj_buffer;
-    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
     struct i965_coded_buffer_segment *coded_buffer_segment;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     dri_bo *bo;
@@ -1026,7 +1024,7 @@ gen7_mfc_mpeg2_prepare(VADriverContextP ctx,
     mfc_context->surface_state.h_pitch = obj_surface->height;
 
     /* forward reference */
-    obj_surface = SURFACE(pic_param->forward_reference_picture);
+    obj_surface = encode_state->reference_objects[0];
 
     if (obj_surface && obj_surface->bo) {
         mfc_context->reference_surfaces[0].bo = obj_surface->bo;
@@ -1035,7 +1033,7 @@ gen7_mfc_mpeg2_prepare(VADriverContextP ctx,
         mfc_context->reference_surfaces[0].bo = NULL;
 
     /* backward reference */
-    obj_surface = SURFACE(pic_param->backward_reference_picture);
+    obj_surface = encode_state->reference_objects[1];
 
     if (obj_surface && obj_surface->bo) {
         mfc_context->reference_surfaces[1].bo = obj_surface->bo;
index e5b2020..5da7b28 100644 (file)
@@ -249,9 +249,7 @@ gen7_vme_surface_setup(VADriverContextP ctx,
                        int is_intra,
                        struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferH264 *pPicParameter = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -261,15 +259,15 @@ gen7_vme_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[0].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+
+        if (obj_surface && obj_surface->bo)
             gen7_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pPicParameter->ReferenceFrames[1].picture_id);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL ) 
+        obj_surface = encode_state->reference_objects[1];
+
+        if (obj_surface && obj_surface->bo)
             gen7_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
 
@@ -841,9 +839,7 @@ gen7_vme_mpeg2_surface_setup(VADriverContextP ctx,
                               int is_intra,
                               struct intel_encoder_context *encoder_context)
 {
-    struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface;
-    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
 
     /*Setup surfaces state*/
     /* current picture for encoding */
@@ -853,13 +849,12 @@ gen7_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     if (!is_intra) {
         /* reference 0 */
-        obj_surface = SURFACE(pic_param->forward_reference_picture);
-        assert(obj_surface);
-        if ( obj_surface->bo != NULL)
+        obj_surface = encode_state->reference_objects[0];
+        if (obj_surface->bo != NULL)
             gen7_vme_source_surface_state(ctx, 1, obj_surface, encoder_context);
 
         /* reference 1 */
-        obj_surface = SURFACE(pic_param->backward_reference_picture);
+        obj_surface = encode_state->reference_objects[1];
         if (obj_surface && obj_surface->bo != NULL) 
             gen7_vme_source_surface_state(ctx, 2, obj_surface, encoder_context);
     }
index 0a20b67..29ecade 100644 (file)
@@ -135,6 +135,7 @@ struct encode_state
     struct object_surface *input_yuv_object;
     struct object_surface *reconstructed_object;
     struct object_buffer *coded_buf_object;
+    struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
 };
 
 struct proc_state
index f2d7f6b..8f82344 100644 (file)
@@ -142,6 +142,7 @@ intel_encoder_check_avc_parameter(VADriverContextP ctx,
     struct object_surface *obj_surface;        
     struct object_buffer *obj_buffer;
     VAEncPictureParameterBufferH264 *pic_param = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
+    int i;
 
     assert(!(pic_param->CurrPic.flags & VA_PICTURE_H264_INVALID));
 
@@ -162,6 +163,27 @@ intel_encoder_check_avc_parameter(VADriverContextP ctx,
         goto error;
 
     encode_state->coded_buf_object = obj_buffer;
+
+    for (i = 0; i < 16; i++) {
+        if (pic_param->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID ||
+            pic_param->ReferenceFrames[i].picture_id == VA_INVALID_SURFACE)
+            break;
+        else {
+            obj_surface = SURFACE(pic_param->ReferenceFrames[i].picture_id);
+            assert(obj_surface);
+
+            if (!obj_surface)
+                goto error;
+
+            if (obj_surface->bo)
+                encode_state->reference_objects[i] = obj_surface;
+            else
+                encode_state->reference_objects[i] = NULL; /* FIXME: Warning or Error ??? */
+        }
+    }
+
+    for ( ; i < 16; i++)
+        encode_state->reference_objects[i] = NULL;
     
     return VA_STATUS_SUCCESS;
 
@@ -178,7 +200,8 @@ intel_encoder_check_mpeg2_parameter(VADriverContextP ctx,
     VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
     struct object_surface *obj_surface;        
     struct object_buffer *obj_buffer;
-
+    int i = 0;
+    
     obj_surface = SURFACE(pic_param->reconstructed_picture);
     assert(obj_surface); /* It is possible the store buffer isn't allocated yet */
     
@@ -194,6 +217,40 @@ intel_encoder_check_mpeg2_parameter(VADriverContextP ctx,
 
     encode_state->coded_buf_object = obj_buffer;
 
+    if (pic_param->picture_type == VAEncPictureTypeIntra) {
+    } else if (pic_param->picture_type == VAEncPictureTypePredictive) {
+        assert(pic_param->forward_reference_picture != VA_INVALID_SURFACE);
+        obj_surface = SURFACE(pic_param->forward_reference_picture);
+        assert(obj_surface && obj_surface->bo);
+
+        if (!obj_surface || !obj_surface->bo)
+            goto error;
+
+        encode_state->reference_objects[i++] = obj_surface;
+    } else if (pic_param->picture_type == VAEncPictureTypeBidirectional) {
+        assert(pic_param->forward_reference_picture != VA_INVALID_SURFACE);
+        obj_surface = SURFACE(pic_param->forward_reference_picture);
+        assert(obj_surface && obj_surface->bo);
+
+        if (!obj_surface || !obj_surface->bo)
+            goto error;
+
+        encode_state->reference_objects[i++] = obj_surface;
+
+        assert(pic_param->backward_reference_picture != VA_INVALID_SURFACE);
+        obj_surface = SURFACE(pic_param->backward_reference_picture);
+        assert(obj_surface && obj_surface->bo);
+
+        if (!obj_surface || !obj_surface->bo)
+            goto error;
+
+        encode_state->reference_objects[i++] = obj_surface;
+    } else 
+        goto error;
+
+    for ( ; i < 16; i++)
+        encode_state->reference_objects[i] = NULL;
+
     return VA_STATUS_SUCCESS;
 
 error: