summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-08-27 18:11:37 +0300
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-09-07 14:26:56 +0200
commitf6fb598b147f5dd942016d6616b2e8764039c7b1 (patch)
tree0092a43bddd77e51a0d8f1dc18ab5aed2bda4a51
parentbcc3362017f5fdf324e64dbce49b521d85e24414 (diff)
downloadgst-vaapi-f6fb598b147f5dd942016d6616b2e8764039c7b1.tar.gz
display: add support for rendering modes.
A rendering mode can be "overlay" or "texture"'ed blit. The former mode implies that a VA surface used for rendering can't be re-used right away for decoding, so the sink shall make provisions to retain the associated surface proxy until the next surface is to be displayed. The latter mode implies that the VA surface is implicitly copied to an intermediate backing store, or back buffer of a frame buffer, so the associated surface proxy can be disposed right away.
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.c175
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.h19
-rw-r--r--gst-libs/gst/vaapi/gstvaapitypes.h19
-rw-r--r--gst-libs/gst/vaapi/gstvaapivalue.c22
-rw-r--r--gst-libs/gst/vaapi/gstvaapivalue.h13
5 files changed, 246 insertions, 2 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c
index 4d9f37be..bb980600 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.c
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.c
@@ -537,12 +537,21 @@ gst_vaapi_display_create(GstVaapiDisplay *display)
GST_DEBUG(" %s", string_of_VADisplayAttributeType(attr->type));
switch (attr->type) {
+#if !VA_CHECK_VERSION(0,34,0)
+ case VADisplayAttribDirectSurface:
+ prop.name = GST_VAAPI_DISPLAY_PROP_RENDER_MODE;
+ break;
+#endif
+ case VADisplayAttribRenderMode:
+ prop.name = GST_VAAPI_DISPLAY_PROP_RENDER_MODE;
+ break;
default:
- prop.attribute.flags = 0;
+ prop.name = NULL;
break;
}
- if (!prop.attribute.flags)
+ if (!prop.name)
continue;
+ prop.attribute = *attr;
g_array_append_val(priv->properties, prop);
}
@@ -1160,3 +1169,165 @@ gst_vaapi_display_has_property(GstVaapiDisplay *display, const gchar *name)
return find_property(display->priv->properties, name) != NULL;
}
+
+static gboolean
+get_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint *value)
+{
+ VADisplayAttribute attr;
+ VAStatus status;
+
+ attr.type = type;
+ attr.flags = VA_DISPLAY_ATTRIB_GETTABLE;
+ status = vaGetDisplayAttributes(display->priv->display, &attr, 1);
+ if (!vaapi_check_status(status, "vaGetDisplayAttributes()"))
+ return FALSE;
+ *value = attr.value;
+ return TRUE;
+}
+
+static gboolean
+set_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint value)
+{
+ VADisplayAttribute attr;
+ VAStatus status;
+
+ attr.type = type;
+ attr.value = value;
+ attr.flags = VA_DISPLAY_ATTRIB_SETTABLE;
+ status = vaSetDisplayAttributes(display->priv->display, &attr, 1);
+ if (!vaapi_check_status(status, "vaSetDisplayAttributes()"))
+ return FALSE;
+ return TRUE;
+}
+
+static gboolean
+get_render_mode_VADisplayAttribRenderMode(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode *pmode
+)
+{
+ gint modes, devices;
+
+ if (!get_attribute(display, VADisplayAttribRenderDevice, &devices))
+ return FALSE;
+ if (!devices)
+ return FALSE;
+ if (!get_attribute(display, VADisplayAttribRenderMode, &modes))
+ return FALSE;
+
+ /* Favor "overlay" mode since it is the most restrictive one */
+ if (modes & (VA_RENDER_MODE_LOCAL_OVERLAY|VA_RENDER_MODE_EXTERNAL_OVERLAY))
+ *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
+ else
+ *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
+ return TRUE;
+}
+
+static gboolean
+get_render_mode_VADisplayAttribDirectSurface(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode *pmode
+)
+{
+#if VA_CHECK_VERSION(0,34,0)
+ /* VADisplayAttribDirectsurface was removed in VA-API >= 0.34.0 */
+ return FALSE;
+#else
+ gint direct_surface;
+
+ if (!get_attribute(display, VADisplayAttribDirectSurface, &direct_surface))
+ return FALSE;
+ if (direct_surface)
+ *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
+ else
+ *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
+ return TRUE;
+#endif
+}
+
+static gboolean
+get_render_mode_default(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode *pmode
+)
+{
+ /* Assume "textured-blit" mode by default */
+ *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
+ return TRUE;
+}
+
+/**
+ * gst_vaapi_display_get_render_mode:
+ * @display: a #GstVaapiDisplay
+ * @pmode: return location for the VA @display rendering mode
+ *
+ * Returns the current VA @display rendering mode.
+ *
+ * Return value: %TRUE if VA @display rendering mode could be determined
+ */
+gboolean
+gst_vaapi_display_get_render_mode(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode *pmode
+)
+{
+ g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
+
+ /* Try with render-mode attribute */
+ if (get_render_mode_VADisplayAttribRenderMode(display, pmode))
+ return TRUE;
+
+ /* Try with direct-surface attribute */
+ if (get_render_mode_VADisplayAttribDirectSurface(display, pmode))
+ return TRUE;
+
+ /* Default: determine from the display type */
+ return get_render_mode_default(display, pmode);
+}
+
+/**
+ * gst_vaapi_display_set_render_mode:
+ * @display: a #GstVaapiDisplay
+ * @mode: the #GstVaapiRenderMode to set
+ *
+ * Sets the VA @display rendering mode to the supplied @mode. This
+ * function returns %FALSE if the rendering mode could not be set,
+ * e.g. run-time switching rendering mode is not supported.
+ *
+ * Return value: %TRUE if VA @display rendering @mode could be changed
+ * to the requested value
+ */
+gboolean
+gst_vaapi_display_set_render_mode(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode mode
+)
+{
+ gint modes, devices;
+
+ g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), FALSE);
+
+ if (!get_attribute(display, VADisplayAttribRenderDevice, &devices))
+ return FALSE;
+
+ modes = 0;
+ switch (mode) {
+ case GST_VAAPI_RENDER_MODE_OVERLAY:
+ if (devices & VA_RENDER_DEVICE_LOCAL)
+ modes |= VA_RENDER_MODE_LOCAL_OVERLAY;
+ if (devices & VA_RENDER_DEVICE_EXTERNAL)
+ modes |= VA_RENDER_MODE_EXTERNAL_OVERLAY;
+ break;
+ case GST_VAAPI_RENDER_MODE_TEXTURE:
+ if (devices & VA_RENDER_DEVICE_LOCAL)
+ modes |= VA_RENDER_MODE_LOCAL_GPU;
+ if (devices & VA_RENDER_DEVICE_EXTERNAL)
+ modes |= VA_RENDER_MODE_EXTERNAL_GPU;
+ break;
+ }
+ if (!modes)
+ return FALSE;
+ if (!set_attribute(display, VADisplayAttribRenderMode, modes))
+ return FALSE;
+ return TRUE;
+}
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.h b/gst-libs/gst/vaapi/gstvaapidisplay.h
index 08f2df5e..bced89cc 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.h
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.h
@@ -30,6 +30,7 @@
#endif
#include <gst/gst.h>
+#include <gst/vaapi/gstvaapitypes.h>
#include <gst/vaapi/gstvaapiimageformat.h>
#include <gst/vaapi/gstvaapiprofile.h>
@@ -77,6 +78,12 @@ struct _GstVaapiDisplayInfo {
};
/**
+ * GstVaapiDisplayProperties:
+ * @GST_VAAPI_DISPLAY_PROP_RENDER_MODE: rendering mode (#GstVaapiRenderMode).
+ */
+#define GST_VAAPI_DISPLAY_PROP_RENDER_MODE "render-mode"
+
+/**
* GstVaapiDisplay:
*
* Base class for VA displays.
@@ -199,6 +206,18 @@ gst_vaapi_display_has_subpicture_format(
gboolean
gst_vaapi_display_has_property(GstVaapiDisplay *display, const gchar *name);
+gboolean
+gst_vaapi_display_get_render_mode(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode *pmode
+);
+
+gboolean
+gst_vaapi_display_set_render_mode(
+ GstVaapiDisplay *display,
+ GstVaapiRenderMode mode
+);
+
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 a6312b1f..241051f8 100644
--- a/gst-libs/gst/vaapi/gstvaapitypes.h
+++ b/gst-libs/gst/vaapi/gstvaapitypes.h
@@ -116,6 +116,25 @@ struct _GstVaapiRectangle {
guint32 height;
};
+/**
+ * GstVaapiRenderMode:
+ * @GST_VAAPI_RENDER_MODE_OVERLAY: in this mode, the VA display
+ * backend renders surfaces with an overlay engine. This means that
+ * the surface that is currently displayed shall not be re-used
+ * right away for decoding. i.e. it needs to be retained further,
+ * until the next surface is to be displayed.
+ * @GST_VAAPI_RENDER_MODE_TEXTURE: in this modem the VA display
+ * backend renders surfaces with a textured blit (GPU/3D engine).
+ * This means that the surface is copied to some intermediate
+ * backing store, or back buffer of a frame buffer, and is free to
+ * be re-used right away for decoding.
+ */
+typedef enum _GstVaapiRenderMode GstVaapiRenderMode;
+enum _GstVaapiRenderMode {
+ GST_VAAPI_RENDER_MODE_OVERLAY = 1,
+ GST_VAAPI_RENDER_MODE_TEXTURE
+};
+
G_END_DECLS
#endif /* GST_VAAPI_TYPES_H */
diff --git a/gst-libs/gst/vaapi/gstvaapivalue.c b/gst-libs/gst/vaapi/gstvaapivalue.c
index 112d1b4a..703fca9c 100644
--- a/gst-libs/gst/vaapi/gstvaapivalue.c
+++ b/gst-libs/gst/vaapi/gstvaapivalue.c
@@ -163,3 +163,25 @@ gst_vaapi_value_set_id(GValue *value, GstVaapiID id)
GST_VAAPI_VALUE_ID(value) = id;
}
+
+/* --- GstVaapiRenderMode --- */
+
+GType
+gst_vaapi_render_mode_get_type(void)
+{
+ static GType render_mode_type = 0;
+
+ static const GEnumValue render_modes[] = {
+ { GST_VAAPI_RENDER_MODE_OVERLAY,
+ "Overlay render mode", "overlay" },
+ { GST_VAAPI_RENDER_MODE_TEXTURE,
+ "Textured-blit render mode", "texture" },
+ { 0, NULL, NULL }
+ };
+
+ if (!render_mode_type) {
+ render_mode_type =
+ g_enum_register_static("GstVaapiRenderMode", render_modes);
+ }
+ return render_mode_type;
+}
diff --git a/gst-libs/gst/vaapi/gstvaapivalue.h b/gst-libs/gst/vaapi/gstvaapivalue.h
index a5a52bec..0c2c719e 100644
--- a/gst-libs/gst/vaapi/gstvaapivalue.h
+++ b/gst-libs/gst/vaapi/gstvaapivalue.h
@@ -44,6 +44,16 @@ G_BEGIN_DECLS
*/
#define GST_VAAPI_VALUE_HOLDS_ID(x) (G_VALUE_HOLDS((x), GST_VAAPI_TYPE_ID))
+/**
+ * GST_VAAPI_TYPE_RENDER_MODE:
+ *
+ * A #GstVaapiRenderMode type that represents the VA display backend
+ * rendering mode: overlay (2D engine) or textured-blit (3D engine).
+ *
+ * Return value: the #GType of GstVaapiRenderMode
+ */
+#define GST_VAAPI_TYPE_RENDER_MODE gst_vaapi_render_mode_get_type()
+
GType
gst_vaapi_id_get_type(void) G_GNUC_CONST;
@@ -53,6 +63,9 @@ gst_vaapi_value_get_id(const GValue *value);
void
gst_vaapi_value_set_id(GValue *value, GstVaapiID id);
+GType
+gst_vaapi_render_mode_get_type(void) G_GNUC_CONST;
+
G_END_DECLS
#endif /* GST_VAAPI_VALUE_H */