Encoder: directly use the surface object of the input surface
authorXiang, Haihao <haihao.xiang@intel.com>
Tue, 12 Mar 2013 05:23:03 +0000 (13:23 +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 7eeb71d..1393f1b 100644 (file)
@@ -632,9 +632,7 @@ VAStatus intel_mfc_avc_prepare(VADriverContextP ctx,
         }
     }
        
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface && obj_surface->bo);
-    mfc_context->uncompressed_picture_source.bo = obj_surface->bo;
+    mfc_context->uncompressed_picture_source.bo = encode_state->input_yuv_object->bo;
     dri_bo_reference(mfc_context->uncompressed_picture_source.bo);
 
     obj_buffer = BUFFER (pPicParameter->coded_buf); /* FIXME: fix this later */
index ec70286..3d5baa5 100644 (file)
@@ -277,8 +277,7 @@ gen6_vme_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen6_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen6_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
 
@@ -741,8 +740,7 @@ gen6_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen6_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen6_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
 
index e055d32..5da00de 100644 (file)
@@ -2451,8 +2451,7 @@ intel_mfc_mpeg2_prepare(VADriverContextP ctx,
     }
     
     /* input YUV surface */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface && obj_surface->bo);
+    obj_surface = encode_state->input_yuv_object;
     mfc_context->uncompressed_picture_source.bo = obj_surface->bo;
     dri_bo_reference(mfc_context->uncompressed_picture_source.bo);
 
index 5853757..37751cf 100644 (file)
@@ -272,8 +272,7 @@ gen75_vme_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen75_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen75_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
     gen75_vme_media_chroma_source_surface_state(ctx, 6, obj_surface, encoder_context);
@@ -783,8 +782,7 @@ gen75_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen75_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen75_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
     gen75_vme_media_chroma_source_surface_state(ctx, 6, obj_surface, encoder_context);
index 759b10a..3abcacd 100644 (file)
@@ -1056,8 +1056,7 @@ gen7_mfc_mpeg2_prepare(VADriverContextP ctx,
     }
     
     /* input YUV surface */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface && obj_surface->bo);
+    obj_surface = encode_state->input_yuv_object;
     mfc_context->uncompressed_picture_source.bo = obj_surface->bo;
     dri_bo_reference(mfc_context->uncompressed_picture_source.bo);
 
index 493992f..e5b2020 100644 (file)
@@ -255,8 +255,7 @@ gen7_vme_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen7_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen7_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
 
@@ -848,8 +847,7 @@ gen7_vme_mpeg2_surface_setup(VADriverContextP ctx,
 
     /*Setup surfaces state*/
     /* current picture for encoding */
-    obj_surface = SURFACE(encoder_context->input_yuv_surface);
-    assert(obj_surface);
+    obj_surface = encode_state->input_yuv_object;
     gen7_vme_source_surface_state(ctx, 0, obj_surface, encoder_context);
     gen7_vme_media_source_surface_state(ctx, 4, obj_surface, encoder_context);
 
index 37f8697..77ba9ab 100644 (file)
@@ -132,6 +132,7 @@ struct encode_state
     struct buffer_store *misc_param[8];
 
     VASurfaceID current_render_target;
+    struct object_surface *input_yuv_object;
 };
 
 struct proc_state
index 72ea548..a7334ac 100644 (file)
@@ -56,7 +56,7 @@ i965_CreateSurfaces(VADriverContextP ctx,
                     int num_surfaces,
                     VASurfaceID *surfaces);
 
-static void
+static VAStatus
 intel_encoder_check_yuv_surface(VADriverContextP ctx,
                                 VAProfile profile,
                                 struct encode_state *encode_state,
@@ -71,12 +71,16 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
     /* releae the temporary surface */
     if (encoder_context->is_tmp_id) {
         i965_DestroySurfaces(ctx, &encoder_context->input_yuv_surface, 1);
+        encode_state->input_yuv_object = NULL;
     }
 
     encoder_context->is_tmp_id = 0;
     obj_surface = SURFACE(encode_state->current_render_target);
     assert(obj_surface && obj_surface->bo);
 
+    if (!obj_surface || !obj_surface->bo)
+        return VA_STATUS_ERROR_INVALID_PARAMETER;
+
     if (obj_surface->fourcc == VA_FOURCC('N', 'V', '1', '2')) {
         unsigned int tiling = 0, swizzle = 0;
 
@@ -84,7 +88,8 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
 
         if (tiling == I915_TILING_Y) {
             encoder_context->input_yuv_surface = encode_state->current_render_target;
-            return;
+            encode_state->input_yuv_object = obj_surface;
+            return VA_STATUS_SUCCESS;
         }
     }
 
@@ -104,7 +109,12 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
                                  1,
                                  &encoder_context->input_yuv_surface);
     assert(status == VA_STATUS_SUCCESS);
+
+    if (status != VA_STATUS_SUCCESS)
+        return status;
+
     obj_surface = SURFACE(encoder_context->input_yuv_surface);
+    encode_state->input_yuv_object = obj_surface;
     i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N', 'V', '1', '2'), SUBSAMPLE_YUV420);
     
     dst_surface.id = encoder_context->input_yuv_surface;
@@ -119,6 +129,8 @@ intel_encoder_check_yuv_surface(VADriverContextP ctx,
     assert(status == VA_STATUS_SUCCESS);
 
     encoder_context->is_tmp_id = 1;
+
+    return VA_STATUS_SUCCESS;
 }
 
 static VAStatus
@@ -131,7 +143,10 @@ intel_encoder_end_picture(VADriverContextP ctx,
     struct encode_state *encode_state = &codec_state->encode;
     VAStatus vaStatus;
 
-    intel_encoder_check_yuv_surface(ctx, profile, encode_state, encoder_context);
+    vaStatus = intel_encoder_check_yuv_surface(ctx, profile, encode_state, encoder_context);
+
+    if (vaStatus != VA_STATUS_SUCCESS)
+        return vaStatus;
 
     encoder_context->mfc_brc_prepare(encode_state, encoder_context);
 
@@ -163,6 +178,8 @@ gen6_enc_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
     encoder_context->base.destroy = intel_encoder_context_destroy;
     encoder_context->base.run = intel_encoder_end_picture;
     encoder_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
+    encoder_context->input_yuv_surface = VA_INVALID_SURFACE;
+    encoder_context->is_tmp_id = 0;
     encoder_context->rate_control_mode = VA_RC_NONE;
     encoder_context->profile = obj_config->profile;