From: Zhao Halley Date: Fri, 31 Aug 2012 06:59:48 +0000 (+0800) Subject: add fourcc for GstVaapiSurface X-Git-Tag: accepted/2.0/20130321.180609~74 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=27cd10b0f33353073de0713233895ca830671c1a;p=profile%2Fivi%2Fgstreamer-vaapi.git add fourcc for GstVaapiSurface surface creation with dedicate fourcc is supported after VA API 0.34 legacy interface still works on lower version VA API --- diff --git a/gst-libs/gst/vaapi/gstvaapisurface.c b/gst-libs/gst/vaapi/gstvaapisurface.c old mode 100644 new mode 100755 index 745495d..965912c --- a/gst-libs/gst/vaapi/gstvaapisurface.c +++ b/gst-libs/gst/vaapi/gstvaapisurface.c @@ -48,6 +48,7 @@ struct _GstVaapiSurfacePrivate { guint width; guint height; GstVaapiChromaType chroma_type; + guint32 fourcc; GPtrArray *subpictures; GstVaapiContext *parent_context; }; @@ -58,6 +59,7 @@ enum { PROP_WIDTH, PROP_HEIGHT, PROP_CHROMA_TYPE, + PROP_FOURCC, PROP_PARENT_CONTEXT }; @@ -130,29 +132,71 @@ gst_vaapi_surface_create(GstVaapiSurface *surface) VAStatus status; guint format; - switch (priv->chroma_type) { - case GST_VAAPI_CHROMA_TYPE_YUV420: + switch (priv->fourcc) { + case VA_FOURCC_NV12: + case VA_FOURCC_YV12: format = VA_RT_FORMAT_YUV420; break; - case GST_VAAPI_CHROMA_TYPE_YUV422: + case VA_FOURCC_YUY2: + case VA_FOURCC_UYVY: format = VA_RT_FORMAT_YUV422; break; - case GST_VAAPI_CHROMA_TYPE_YUV444: + case VA_FOURCC_AYUV: format = VA_RT_FORMAT_YUV444; break; + case 0: + switch (priv->chroma_type) { + case GST_VAAPI_CHROMA_TYPE_YUV420: + format = VA_RT_FORMAT_YUV420; + break; + case GST_VAAPI_CHROMA_TYPE_YUV422: + format = VA_RT_FORMAT_YUV422; + break; + case GST_VAAPI_CHROMA_TYPE_YUV444: + format = VA_RT_FORMAT_YUV444; + break; + default: + GST_DEBUG("unsupported chroma-type %u\n", priv->chroma_type); + return FALSE; + } + break; default: - GST_DEBUG("unsupported chroma-type %u\n", priv->chroma_type); - return FALSE; + break; } GST_VAAPI_DISPLAY_LOCK(display); +#if VA_CHECK_VERSION(0,34,0) + VASurfaceAttrib *p_attrib = NULL; + int num_attrib = 0; + 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), + format, + priv->width, + priv->height, + &surface_id, 1, + p_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. + if (priv->fourcc) { + GST_WARNING("surface format are specified but not supported on your version of libva"); + } status = vaCreateSurfaces( GST_VAAPI_DISPLAY_VADISPLAY(display), priv->width, priv->height, format, - 1, &surface_id - ); + 1, &surface_id); +#endif GST_VAAPI_DISPLAY_UNLOCK(display); if (!vaapi_check_status(status, "vaCreateSurfaces()")) return FALSE; @@ -191,6 +235,9 @@ gst_vaapi_surface_set_property( case PROP_CHROMA_TYPE: priv->chroma_type = g_value_get_uint(value); break; + case PROP_FOURCC: + priv->fourcc= g_value_get_uint(value); + break; case PROP_PARENT_CONTEXT: gst_vaapi_surface_set_parent_context(surface, g_value_get_object(value)); break; @@ -283,6 +330,15 @@ gst_vaapi_surface_class_init(GstVaapiSurfaceClass *klass) g_object_class_install_property (object_class, + PROP_FOURCC, + g_param_spec_uint("fourcc", + "fourcc", + "fourcc of the surface", + 0, G_MAXUINT32, 0, + G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property + (object_class, PROP_PARENT_CONTEXT, g_param_spec_object("parent-context", "Parent Context", @@ -334,6 +390,36 @@ gst_vaapi_surface_new( "chroma-type", chroma_type, NULL); } +/** + * gst_vaapi_surface_new_with_fourcc: + * @display: a #GstVaapiDisplay + * @fourcc: surface format + * @width: the requested surface width + * @height: the requested surface height + * + * Creates a new #GstVaapiSurface with the specified fourcc and + * dimensions. + * + * Return value: the newly allocated #GstVaapiSurface object + */ +GstVaapiSurface * +gst_vaapi_surface_new_with_fourcc( + GstVaapiDisplay *display, + guint32 fourcc, + guint width, + guint height +) +{ + GST_DEBUG("size %ux%u, fourcc 0x%x ", width, height, fourcc); + + return g_object_new(GST_VAAPI_TYPE_SURFACE, + "display", display, + "id", GST_VAAPI_ID(VA_INVALID_ID), + "width", width, + "height", height, + "fourcc", fourcc, + NULL); +} /** * gst_vaapi_surface_get_id: diff --git a/gst-libs/gst/vaapi/gstvaapisurface.h b/gst-libs/gst/vaapi/gstvaapisurface.h old mode 100644 new mode 100755 index 4b8aaea..709b2f1 --- a/gst-libs/gst/vaapi/gstvaapisurface.h +++ b/gst-libs/gst/vaapi/gstvaapisurface.h @@ -173,7 +173,13 @@ gst_vaapi_surface_new( guint width, guint height ); - +GstVaapiSurface * +gst_vaapi_surface_new_with_fourcc( + GstVaapiDisplay *display, + guint32 fourcc, + guint width, + guint height +); GstVaapiID gst_vaapi_surface_get_id(GstVaapiSurface *surface);