Set default va surface format to NV12
authorZhao Halley <halley.zhao@intel.com>
Sun, 28 Apr 2013 03:15:17 +0000 (11:15 +0800)
committerZhao Halley <halley.zhao@intel.com>
Sun, 28 Apr 2013 03:15:17 +0000 (11:15 +0800)
when format is not specificed in vaCreateSurface, GenX video driver will
defer it to a later time. (it is not always default to NV12).
if this surface is used as dst surface for vpp (including vaPutImage),
the src surface/image format will be used as default. it is not our expectation
in most case (for example, upload camera data (YUY2) to vaSurface for encoding).
So, I try to set NV12 as default fourcc for vaSurface when it isn't explicitly said.

move default caps of surface pool generation to gstvaapiuploader.c,
so it can be shared between vaapisink and vaapiupload.

gst-libs/gst/vaapi/gstvaapisurface.c
gst/vaapi/gstvaapisink.c
gst/vaapi/gstvaapiuploader.c

index 9830b45..910afbc 100755 (executable)
@@ -177,16 +177,16 @@ gst_vaapi_surface_create(GstVaapiSurface *surface)
 
     GST_VAAPI_DISPLAY_LOCK(display);
 #if VA_CHECK_VERSION(0,34,0)
-    VASurfaceAttrib *p_attrib = NULL;
     int num_attrib = 0;
+    VASurfaceAttrib attrib;
+    attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
+    attrib.type = VASurfaceAttribPixelFormat;
+    attrib.value.type = VAGenericValueTypeInteger;
+    attrib.value.value.i = VA_FOURCC_NV12;
+    num_attrib = 1;
+
     if(priv->fourcc) {
-        VASurfaceAttrib attrib;
-        attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
-        attrib.type = VASurfaceAttribPixelFormat;
-        attrib.value.type = VAGenericValueTypeInteger;
         attrib.value.value.i = priv->fourcc;
-        p_attrib = &attrib;
-        num_attrib = 1;
     }
     status = vaCreateSurfaces(
         GST_VAAPI_DISPLAY_VADISPLAY(display),
@@ -194,7 +194,7 @@ gst_vaapi_surface_create(GstVaapiSurface *surface)
         priv->width,
         priv->height,
         &surface_id, 1,
-        p_attrib, num_attrib);
+        &attrib, num_attrib);
 #else
     // I don't add VA_CHECK_VERSION for each place where fourcc is mentioned, but leave
     // a warning here if it is used by mistake.
index 573228e..a8408ca 100755 (executable)
@@ -1054,18 +1054,8 @@ gst_vaapisink_buffer_alloc(
 
     if (!gst_vaapi_uploader_ensure_display(sink->uploader, sink->display))
         return GST_FLOW_NOT_SUPPORTED;
-    gint width, height;
-    gst_structure_get_int(structure, "width", &width);
-    gst_structure_get_int(structure, "height", &height);
-
-    dst_caps =  gst_caps_new_simple ("video/x-surface",
-    // "format", G_TYPE_STRING, "I420", // leave format as empty, so video driver default format will be use to create surface pool.
-    "width", G_TYPE_INT, width,
-    "height", G_TYPE_INT, height,
-     NULL);
-    gboolean ret = gst_vaapi_uploader_ensure_caps(sink->uploader, caps, dst_caps);
-    gst_caps_unref(dst_caps);
-    if(!ret) return GST_FLOW_NOT_SUPPORTED;
+    if (!gst_vaapi_uploader_ensure_caps(sink->uploader, caps, NULL))
+        return GST_FLOW_NOT_SUPPORTED;
     if (!gst_vaapi_uploader_has_direct_rendering(sink->uploader)) {
         return GST_FLOW_OK;
     }
index ab340d4..7e44109 100755 (executable)
@@ -329,17 +329,27 @@ gst_vaapi_uploader_ensure_caps(
 
     if (!ensure_image_pool(uploader, src_caps))
         return FALSE;
-    if (!ensure_surface_pool(uploader, out_caps ? out_caps : src_caps))
-        return FALSE;
-
-    priv = uploader->priv;
-    priv->direct_rendering = 0;
 
     structure = gst_caps_get_structure(src_caps, 0);
     if (!structure)
         return FALSE;
     gst_structure_get_int(structure, "width",  &width);
     gst_structure_get_int(structure, "height", &height);
+    GstCaps *default_out_caps = NULL;
+    if (out_caps == NULL) {
+        default_out_caps = gst_caps_new_simple ("video/x-surface",
+        // "format", G_TYPE_STRING, "I420", // leave format as empty, so video driver default format will be use to create surface pool.
+        "width", G_TYPE_INT, width,
+        "height", G_TYPE_INT, height,
+         NULL);
+    }
+
+    if (!ensure_surface_pool(uploader, out_caps ? out_caps : default_out_caps))
+        return FALSE;
+    if (default_out_caps) gst_caps_unref(default_out_caps);
+
+    priv = uploader->priv;
+    priv->direct_rendering = 0;
 
     /* Translate from Gst video format to VA image format */
     if (!gst_video_format_parse_caps(src_caps, &vformat, NULL, NULL))