display: add support for rotation modes.
authorWind Yuan <feng.yuan@intel.com>
Wed, 22 Aug 2012 06:18:11 +0000 (02:18 -0400)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 27 Aug 2012 16:41:22 +0000 (18:41 +0200)
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
gst-libs/gst/vaapi/gstvaapidisplay.c
gst-libs/gst/vaapi/gstvaapidisplay.h
gst-libs/gst/vaapi/gstvaapitypes.h
gst-libs/gst/vaapi/gstvaapiutils.c
gst-libs/gst/vaapi/gstvaapiutils.h
gst-libs/gst/vaapi/gstvaapivalue.c
gst-libs/gst/vaapi/gstvaapivalue.h

index 8eed95d..a212a10 100644 (file)
@@ -1415,3 +1415,54 @@ gst_vaapi_display_set_render_mode(
         return FALSE;
     return TRUE;
 }
+
+/**
+ * gst_vaapi_display_get_rotation:
+ * @display: a #GstVaapiDisplay
+ *
+ * Returns the current VA @display rotation angle. If the VA driver
+ * does not support "rotation" display attribute, then the display is
+ * assumed to be un-rotated.
+ *
+ * Return value: the current #GstVaapiRotation value
+ */
+GstVaapiRotation
+gst_vaapi_display_get_rotation(GstVaapiDisplay *display)
+{
+    gint value;
+
+    g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), GST_VAAPI_ROTATION_0);
+
+    if (!get_attribute(display, VADisplayAttribRotation, &value))
+        value = VA_ROTATION_NONE;
+    return to_GstVaapiRotation(value);
+}
+
+/**
+ * gst_vaapi_display_set_rotation:
+ * @display: a #GstVaapiDisplay
+ * @rotation: the #GstVaapiRotation value to set
+ *
+ * Sets the VA @display rotation angle to the supplied @rotation
+ * value. This function returns %FALSE if the rotation angle could not
+ * be set, e.g. the VA driver does not allow to change the display
+ * rotation angle.
+ *
+ * Return value: %TRUE if VA @display rotation angle could be changed
+ *   to the requested value
+ */
+gboolean
+gst_vaapi_display_set_rotation(
+    GstVaapiDisplay *display,
+    GstVaapiRotation rotation
+)
+{
+    guint value;
+
+    g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
+
+    value = from_GstVaapiRotation(rotation);
+    if (!set_attribute(display, VADisplayAttribRotation, value))
+        return FALSE;
+    return TRUE;
+}
index 6240e51..6dac4c5 100644 (file)
@@ -234,6 +234,15 @@ gst_vaapi_display_set_render_mode(
     GstVaapiRenderMode mode
 );
 
+GstVaapiRotation
+gst_vaapi_display_get_rotation(GstVaapiDisplay *display);
+
+gboolean
+gst_vaapi_display_set_rotation(
+    GstVaapiDisplay *display,
+    GstVaapiRotation rotation
+);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_DISPLAY_H */
index 241051f..ff5f9eb 100644 (file)
@@ -135,6 +135,21 @@ enum _GstVaapiRenderMode {
     GST_VAAPI_RENDER_MODE_TEXTURE
 };
 
+/**
+ * GstVaapiRotation:
+ * @GST_VAAPI_ROTATION_0: the VA display is not rotated.
+ * @GST_VAAPI_ROTATION_90: the VA display is rotated by 90°, clockwise.
+ * @GST_VAAPI_ROTATION_180: the VA display is rotated by 180°, clockwise.
+ * @GST_VAAPI_ROTATION_270: the VA display is rotated by 270°, clockwise.
+ */
+typedef enum _GstVaapiRotation GstVaapiRotation;
+enum _GstVaapiRotation {
+    GST_VAAPI_ROTATION_0   = 0,
+    GST_VAAPI_ROTATION_90  = 90,
+    GST_VAAPI_ROTATION_180 = 180,
+    GST_VAAPI_ROTATION_270 = 270,
+};
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_TYPES_H */
index 41682a9..996e328 100644 (file)
@@ -273,3 +273,31 @@ to_GstVaapiSurfaceStatus(guint va_flags)
 #endif
     return flags;
 }
+
+/* Translate GstVaapiRotation value to VA-API rotation value */
+guint
+from_GstVaapiRotation(guint value)
+{
+    switch (value) {
+    case GST_VAAPI_ROTATION_0:   return VA_ROTATION_NONE;
+    case GST_VAAPI_ROTATION_90:  return VA_ROTATION_90;
+    case GST_VAAPI_ROTATION_180: return VA_ROTATION_180;
+    case GST_VAAPI_ROTATION_270: return VA_ROTATION_270;
+    }
+    GST_ERROR("unsupported GstVaapiRotation value %d", value);
+    return VA_ROTATION_NONE;
+}
+
+/* Translate VA-API rotation value to GstVaapiRotation value */
+guint
+to_GstVaapiRotation(guint value)
+{
+    switch (value) {
+    case VA_ROTATION_NONE: return GST_VAAPI_ROTATION_0;
+    case VA_ROTATION_90:   return GST_VAAPI_ROTATION_90;
+    case VA_ROTATION_180:  return GST_VAAPI_ROTATION_180;
+    case VA_ROTATION_270:  return GST_VAAPI_ROTATION_270;
+    }
+    GST_ERROR("unsupported VA-API rotation value %d", value);
+    return GST_VAAPI_ROTATION_0;
+}
index 644fd58..98d91e3 100644 (file)
@@ -81,4 +81,12 @@ G_GNUC_INTERNAL
 guint
 to_GstVaapiSurfaceStatus(guint va_flags);
 
+G_GNUC_INTERNAL
+guint
+from_GstVaapiRotation(guint value);
+
+G_GNUC_INTERNAL
+guint
+to_GstVaapiRotation(guint value);
+
 #endif /* GST_VAAPI_UTILS_H */
index 703fca9..8461c09 100644 (file)
@@ -185,3 +185,26 @@ gst_vaapi_render_mode_get_type(void)
     }
     return render_mode_type;
 }
+
+/* --- GstVaapiRotation --- */
+
+GType
+gst_vaapi_rotation_get_type(void)
+{
+    static GType g_type = 0;
+
+    static const GEnumValue rotation_values[] = {
+        { GST_VAAPI_ROTATION_0,
+          "Unrotated mode", "0" },
+        { GST_VAAPI_ROTATION_90,
+          "Rotated by 90°, clockwise", "90" },
+        { GST_VAAPI_ROTATION_180,
+          "Rotated by 180°, clockwise", "180" },
+        { GST_VAAPI_ROTATION_270,
+          "Rotated by 270°, clockwise", "270" },
+    };
+
+    if (!g_type)
+        g_type = g_enum_register_static("GstVaapiRotation", rotation_values);
+    return g_type;
+}
index 0c2c719..ec99f8e 100644 (file)
@@ -54,6 +54,15 @@ G_BEGIN_DECLS
  */
 #define GST_VAAPI_TYPE_RENDER_MODE gst_vaapi_render_mode_get_type()
 
+/**
+ * GST_VAAPI_TYPE_ROTATION:
+ *
+ * A type that represents the VA display rotation.
+ *
+ * Return value: the #GType of GstVaapiRotation
+ */
+#define GST_VAAPI_TYPE_ROTATION gst_vaapi_rotation_get_type()
+
 GType
 gst_vaapi_id_get_type(void) G_GNUC_CONST;
 
@@ -66,6 +75,9 @@ gst_vaapi_value_set_id(GValue *value, GstVaapiID id);
 GType
 gst_vaapi_render_mode_get_type(void) G_GNUC_CONST;
 
+GType
+gst_vaapi_rotation_get_type(void) G_GNUC_CONST;
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_VALUE_H */