From c899947e17b250a70d26332210314f31934823a3 Mon Sep 17 00:00:00 2001 From: Wind Yuan Date: Wed, 22 Aug 2012 02:18:11 -0400 Subject: display: add support for rotation modes. Signed-off-by: Gwenole Beauchesne --- gst-libs/gst/vaapi/gstvaapidisplay.c | 51 ++++++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapidisplay.h | 9 +++++++ gst-libs/gst/vaapi/gstvaapitypes.h | 15 +++++++++++ gst-libs/gst/vaapi/gstvaapiutils.c | 28 ++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapiutils.h | 8 ++++++ gst-libs/gst/vaapi/gstvaapivalue.c | 23 ++++++++++++++++ gst-libs/gst/vaapi/gstvaapivalue.h | 12 +++++++++ 7 files changed, 146 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c index 8eed95d..a212a10 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay.c @@ -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; +} diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.h b/gst-libs/gst/vaapi/gstvaapidisplay.h index 6240e51..6dac4c5 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay.h +++ b/gst-libs/gst/vaapi/gstvaapidisplay.h @@ -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 */ diff --git a/gst-libs/gst/vaapi/gstvaapitypes.h b/gst-libs/gst/vaapi/gstvaapitypes.h index 241051f..ff5f9eb 100644 --- a/gst-libs/gst/vaapi/gstvaapitypes.h +++ b/gst-libs/gst/vaapi/gstvaapitypes.h @@ -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 */ diff --git a/gst-libs/gst/vaapi/gstvaapiutils.c b/gst-libs/gst/vaapi/gstvaapiutils.c index 41682a9..996e328 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils.c +++ b/gst-libs/gst/vaapi/gstvaapiutils.c @@ -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; +} diff --git a/gst-libs/gst/vaapi/gstvaapiutils.h b/gst-libs/gst/vaapi/gstvaapiutils.h index 644fd58..98d91e3 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils.h +++ b/gst-libs/gst/vaapi/gstvaapiutils.h @@ -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 */ diff --git a/gst-libs/gst/vaapi/gstvaapivalue.c b/gst-libs/gst/vaapi/gstvaapivalue.c index 703fca9..8461c09 100644 --- a/gst-libs/gst/vaapi/gstvaapivalue.c +++ b/gst-libs/gst/vaapi/gstvaapivalue.c @@ -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; +} diff --git a/gst-libs/gst/vaapi/gstvaapivalue.h b/gst-libs/gst/vaapi/gstvaapivalue.h index 0c2c719..ec99f8e 100644 --- a/gst-libs/gst/vaapi/gstvaapivalue.h +++ b/gst-libs/gst/vaapi/gstvaapivalue.h @@ -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 */ -- cgit v1.2.3