display: add initial support for display attributes.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 27 Aug 2012 14:02:49 +0000 (17:02 +0300)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 27 Aug 2012 15:52:32 +0000 (17:52 +0200)
The VA display attributes are mapped to properties so that to maintain the
GStreamer terminology. Properties are to be identified by name, but internal
functions are available to lookup the property by the actual VA display
attribute type.

gst-libs/gst/vaapi/gstvaapidisplay.c
gst-libs/gst/vaapi/gstvaapidisplay.h
gst-libs/gst/vaapi/gstvaapidisplay_priv.h

index 1f82f33..7dc0601 100644 (file)
@@ -45,6 +45,12 @@ struct _GstVaapiConfig {
     GstVaapiEntrypoint  entrypoint;
 };
 
+typedef struct _GstVaapiProperty GstVaapiProperty;
+struct _GstVaapiProperty {
+    const gchar        *name;
+    VADisplayAttribute  attribute;
+};
+
 enum {
     PROP_0,
 
@@ -304,6 +310,40 @@ get_format_caps(GArray *formats)
     return out_caps;
 }
 
+/* Find display attribute */
+static const GstVaapiProperty *
+find_property(GArray *properties, const gchar *name)
+{
+    GstVaapiProperty *prop;
+    guint i;
+
+    if (!name)
+        return NULL;
+
+    for (i = 0; i < properties->len; i++) {
+        prop = &g_array_index(properties, GstVaapiProperty, i);
+        if (strcmp(prop->name, name) == 0)
+            return prop;
+    }
+    return NULL;
+}
+
+#if 0
+static const GstVaapiProperty *
+find_property_by_type(GArray *properties, VADisplayAttribType type)
+{
+    GstVaapiProperty *prop;
+    guint i;
+
+    for (i = 0; i < properties->len; i++) {
+        prop = &g_array_index(properties, GstVaapiProperty, i);
+        if (prop->attribute.type == type)
+            return prop;
+    }
+    return NULL;
+}
+#endif
+
 static void
 gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
 {
@@ -374,6 +414,11 @@ gst_vaapi_display_destroy(GstVaapiDisplay *display)
         priv->subpicture_formats = NULL;
     }
 
+    if (priv->properties) {
+        g_array_free(priv->properties, TRUE);
+        priv->properties = NULL;
+    }
+
     if (priv->display) {
         if (!priv->parent)
             vaTerminate(priv->display);
@@ -523,9 +568,26 @@ gst_vaapi_display_create(GstVaapiDisplay *display)
     if (!vaapi_check_status(status, "vaQueryDisplayAttributes()"))
         goto end;
 
+    priv->properties = g_array_new(FALSE, FALSE, sizeof(GstVaapiProperty));
+    if (!priv->properties)
+        goto end;
+
     GST_DEBUG("%d display attributes", n);
-    for (i = 0; i < n; i++)
-        GST_DEBUG("  %s", string_of_VADisplayAttributeType(display_attrs[i].type));
+    for (i = 0; i < n; i++) {
+        VADisplayAttribute * const attr = &display_attrs[i];
+        GstVaapiProperty prop;
+
+        GST_DEBUG("  %s", string_of_VADisplayAttributeType(attr->type));
+
+        switch (attr->type) {
+        default:
+            prop.attribute.flags = 0;
+            break;
+        }
+        if (!prop.attribute.flags)
+            continue;
+        g_array_append_val(priv->properties, prop);
+    }
 
     /* VA image formats */
     formats = g_new(VAImageFormat, vaMaxNumImageFormats(priv->display));
@@ -755,6 +817,7 @@ gst_vaapi_display_init(GstVaapiDisplay *display)
     priv->encoders              = NULL;
     priv->image_formats         = NULL;
     priv->subpicture_formats    = NULL;
+    priv->properties            = NULL;
     priv->create_display        = TRUE;
 
     g_static_rec_mutex_init(&priv->mutex);
@@ -1153,3 +1216,24 @@ gst_vaapi_display_has_subpicture_format(
 
     return find_format(display->priv->subpicture_formats, format);
 }
+
+/**
+ * gst_vaapi_display_has_property:
+ * @display: a #GstVaapiDisplay
+ * @name: the property name to check
+ *
+ * Returns whether VA @display supports the requested property. The
+ * check is performed against the property @name. So, the client
+ * application may perform this check only once and cache this
+ * information.
+ *
+ * Return value: %TRUE if VA @display supports property @name
+ */
+gboolean
+gst_vaapi_display_has_property(GstVaapiDisplay *display, const gchar *name)
+{
+    g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
+    g_return_val_if_fail(name, FALSE);
+
+    return find_property(display->priv->properties, name) != NULL;
+}
index 2b82666..1b0ade6 100644 (file)
@@ -218,6 +218,9 @@ gst_vaapi_display_has_subpicture_format(
     GstVaapiImageFormat format
 );
 
+gboolean
+gst_vaapi_display_has_property(GstVaapiDisplay *display, const gchar *name);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_DISPLAY_H */
index d48cc60..ac0555e 100644 (file)
@@ -86,6 +86,7 @@ struct _GstVaapiDisplayPrivate {
     GArray             *encoders;
     GArray             *image_formats;
     GArray             *subpicture_formats;
+    GArray             *properties;
     guint               create_display  : 1;
 };