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-08-27 17:52:32 +0200
commita192f40ed9dceba9434823877aa04ca33865ce3a (patch)
tree7cdaf957a9f50b8f85559e0da8178c5e55b2c3d6
parenta503aaf9b9bddb4b381a500a7dff31a3fa9dd593 (diff)
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.c178
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.h13
-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, 245 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c
index 7dc0601..8eed95d 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.c
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.c
@@ -1237,3 +1237,181 @@ 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
+)
+{
+ switch (display->priv->display_type) {
+#if USE_WAYLAND
+ case GST_VAAPI_DISPLAY_TYPE_WAYLAND:
+ /* wl_buffer mapped from VA surface through vaGetSurfaceBufferWl() */
+ *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
+ break;
+#endif
+#if USE_DRM
+ case GST_VAAPI_DISPLAY_TYPE_DRM:
+ /* vaGetSurfaceBufferDRM() returns the underlying DRM buffer handle */
+ *pmode = GST_VAAPI_RENDER_MODE_OVERLAY;
+ break;
+#endif
+ default:
+ /* This includes VA/X11 and VA/GLX modes */
+ *pmode = GST_VAAPI_RENDER_MODE_TEXTURE;
+ break;
+ }
+ 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 1b0ade6..6240e51 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.h
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.h
@@ -25,6 +25,7 @@
#include <va/va.h>
#include <gst/gst.h>
+#include <gst/vaapi/gstvaapitypes.h>
#include <gst/vaapi/gstvaapiimageformat.h>
#include <gst/vaapi/gstvaapiprofile.h>
@@ -221,6 +222,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 a6312b1..241051f 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 112d1b4..703fca9 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 a5a52be..0c2c719 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 */