2011-11-04 20:50:15 +00:00
|
|
|
/*
|
|
|
|
* gstvaapipluginutil.h - VA-API plugin helpers
|
|
|
|
*
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2011-11-04 20:50:15 +00:00
|
|
|
* Copyright (C) 2011 Collabora
|
|
|
|
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2013-03-20 10:57:03 +00:00
|
|
|
#include "gst/vaapi/sysdeps.h"
|
2013-05-22 16:07:52 +00:00
|
|
|
#include "gstvaapivideocontext.h"
|
2012-08-01 13:46:19 +00:00
|
|
|
#if USE_DRM
|
|
|
|
# include <gst/vaapi/gstvaapidisplay_drm.h>
|
|
|
|
#endif
|
2012-07-23 14:15:38 +00:00
|
|
|
#if USE_X11
|
|
|
|
# include <gst/vaapi/gstvaapidisplay_x11.h>
|
|
|
|
#endif
|
|
|
|
#if USE_GLX
|
|
|
|
# include <gst/vaapi/gstvaapidisplay_glx.h>
|
2011-11-04 20:50:15 +00:00
|
|
|
#endif
|
2012-07-24 07:45:25 +00:00
|
|
|
#if USE_WAYLAND
|
|
|
|
# include <gst/vaapi/gstvaapidisplay_wayland.h>
|
|
|
|
#endif
|
2011-11-04 20:50:15 +00:00
|
|
|
#include "gstvaapipluginutil.h"
|
2013-12-13 10:52:47 +00:00
|
|
|
#include "gstvaapipluginbase.h"
|
2011-11-04 20:50:15 +00:00
|
|
|
|
|
|
|
/* Preferred first */
|
|
|
|
static const char *display_types[] = {
|
2013-12-21 05:22:30 +00:00
|
|
|
"gst-vaapi-display",
|
|
|
|
"vaapi-display",
|
2012-07-24 07:45:25 +00:00
|
|
|
#if USE_WAYLAND
|
2013-12-21 05:22:30 +00:00
|
|
|
"wl-display",
|
|
|
|
"wl-display-name",
|
2012-07-24 07:45:25 +00:00
|
|
|
#endif
|
2012-07-24 13:07:48 +00:00
|
|
|
#if USE_X11
|
2013-12-21 05:22:30 +00:00
|
|
|
"x11-display",
|
|
|
|
"x11-display-name",
|
2012-08-01 13:46:19 +00:00
|
|
|
#endif
|
|
|
|
#if USE_DRM
|
2013-12-21 05:22:30 +00:00
|
|
|
"drm-device",
|
|
|
|
"drm-device-path",
|
2012-07-24 13:07:48 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
NULL
|
2011-11-04 20:50:15 +00:00
|
|
|
};
|
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const gchar *type_str;
|
|
|
|
GstVaapiDisplayType type;
|
|
|
|
GstVaapiDisplay *(*create_display) (const gchar *);
|
2012-07-23 16:37:38 +00:00
|
|
|
} DisplayMap;
|
|
|
|
|
|
|
|
static const DisplayMap g_display_map[] = {
|
2012-07-24 07:45:25 +00:00
|
|
|
#if USE_WAYLAND
|
2013-12-21 05:22:30 +00:00
|
|
|
{"wayland",
|
|
|
|
GST_VAAPI_DISPLAY_TYPE_WAYLAND,
|
|
|
|
gst_vaapi_display_wayland_new},
|
2012-07-24 07:45:25 +00:00
|
|
|
#endif
|
2012-07-27 08:45:41 +00:00
|
|
|
#if USE_GLX
|
2013-12-21 05:22:30 +00:00
|
|
|
{"glx",
|
|
|
|
GST_VAAPI_DISPLAY_TYPE_GLX,
|
|
|
|
gst_vaapi_display_glx_new},
|
2012-08-01 13:46:19 +00:00
|
|
|
#endif
|
2013-06-06 09:36:03 +00:00
|
|
|
#if USE_X11
|
2013-12-21 05:22:30 +00:00
|
|
|
{"x11",
|
|
|
|
GST_VAAPI_DISPLAY_TYPE_X11,
|
|
|
|
gst_vaapi_display_x11_new},
|
2013-06-06 09:36:03 +00:00
|
|
|
#endif
|
2012-08-01 13:46:19 +00:00
|
|
|
#if USE_DRM
|
2013-12-21 05:22:30 +00:00
|
|
|
{"drm",
|
|
|
|
GST_VAAPI_DISPLAY_TYPE_DRM,
|
|
|
|
gst_vaapi_display_drm_new},
|
2012-07-23 16:37:38 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
{NULL,}
|
2012-07-23 16:37:38 +00:00
|
|
|
};
|
|
|
|
|
2013-05-24 09:04:01 +00:00
|
|
|
static GstVaapiDisplay *
|
2014-07-25 09:13:29 +00:00
|
|
|
gst_vaapi_create_display (GstVaapiDisplayType display_type,
|
|
|
|
const gchar * display_name)
|
2013-05-24 09:04:01 +00:00
|
|
|
{
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVaapiDisplay *display = NULL;
|
|
|
|
const DisplayMap *m;
|
|
|
|
|
|
|
|
for (m = g_display_map; m->type_str != NULL; m++) {
|
|
|
|
if (display_type != GST_VAAPI_DISPLAY_TYPE_ANY && display_type != m->type)
|
|
|
|
continue;
|
|
|
|
|
2014-07-25 09:13:29 +00:00
|
|
|
display = m->create_display (display_name);
|
2013-12-21 05:22:30 +00:00
|
|
|
if (display || display_type != GST_VAAPI_DISPLAY_TYPE_ANY)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return display;
|
2013-05-24 09:04:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 20:50:15 +00:00
|
|
|
gboolean
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_ensure_display (gpointer element, GstVaapiDisplayType type)
|
2011-11-04 20:50:15 +00:00
|
|
|
{
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element);
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstVideoContext *context;
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_VIDEO_CONTEXT (element), FALSE);
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
context = GST_VIDEO_CONTEXT (element);
|
|
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
2012-07-25 08:02:29 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_video_context_prepare (context, display_types);
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
/* Neighbour found and it updated the display */
|
|
|
|
if (plugin->display
|
|
|
|
&& gst_vaapi_display_type_is_compatible (plugin->display_type, type))
|
|
|
|
return TRUE;
|
2012-07-25 08:02:29 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
/* If no neighboor, or application not interested, use system default */
|
2014-07-25 09:13:29 +00:00
|
|
|
display = gst_vaapi_create_display (type, plugin->display_name);
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
2013-05-22 16:07:52 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_video_context_propagate (context, display);
|
|
|
|
GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE (plugin, display);
|
|
|
|
gst_vaapi_display_unref (display);
|
|
|
|
return TRUE;
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_set_display (const gchar * type,
|
|
|
|
const GValue * value, GstVaapiDisplay ** display_ptr)
|
2011-11-04 20:50:15 +00:00
|
|
|
{
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVaapiDisplay *display = NULL;
|
|
|
|
|
|
|
|
if (!strcmp (type, "vaapi-display")) {
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_POINTER (value));
|
|
|
|
display = gst_vaapi_display_new_with_display (g_value_get_pointer (value));
|
|
|
|
} else if (!strcmp (type, "gst-vaapi-display")) {
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_POINTER (value));
|
|
|
|
display = gst_vaapi_display_ref (g_value_get_pointer (value));
|
|
|
|
}
|
2012-08-01 13:46:19 +00:00
|
|
|
#if USE_DRM
|
2013-12-21 05:22:30 +00:00
|
|
|
else if (!strcmp (type, "drm-device")) {
|
|
|
|
gint device;
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_INT (value));
|
|
|
|
device = g_value_get_int (value);
|
|
|
|
display = gst_vaapi_display_drm_new_with_device (device);
|
|
|
|
} else if (!strcmp (type, "drm-device-path")) {
|
|
|
|
const gchar *device_path;
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_STRING (value));
|
|
|
|
device_path = g_value_get_string (value);
|
|
|
|
display = gst_vaapi_display_drm_new (device_path);
|
|
|
|
}
|
2012-08-01 13:46:19 +00:00
|
|
|
#endif
|
2012-07-24 13:07:48 +00:00
|
|
|
#if USE_X11
|
2013-12-21 05:22:30 +00:00
|
|
|
else if (!strcmp (type, "x11-display-name")) {
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_STRING (value));
|
2012-07-23 14:15:38 +00:00
|
|
|
#if USE_GLX
|
2013-12-21 05:22:30 +00:00
|
|
|
display = gst_vaapi_display_glx_new (g_value_get_string (value));
|
2011-11-04 20:50:15 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!display)
|
|
|
|
display = gst_vaapi_display_x11_new (g_value_get_string (value));
|
|
|
|
} else if (!strcmp (type, "x11-display")) {
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_POINTER (value));
|
2012-07-23 14:15:38 +00:00
|
|
|
#if USE_GLX
|
2013-12-21 05:22:30 +00:00
|
|
|
display =
|
|
|
|
gst_vaapi_display_glx_new_with_display (g_value_get_pointer (value));
|
2011-11-04 20:50:15 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!display)
|
|
|
|
display =
|
|
|
|
gst_vaapi_display_x11_new_with_display (g_value_get_pointer (value));
|
|
|
|
}
|
2012-07-24 13:07:48 +00:00
|
|
|
#endif
|
2012-07-24 07:45:25 +00:00
|
|
|
#if USE_WAYLAND
|
2013-12-21 05:22:30 +00:00
|
|
|
else if (!strcmp (type, "wl-display")) {
|
|
|
|
struct wl_display *wl_display;
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_POINTER (value));
|
|
|
|
wl_display = g_value_get_pointer (value);
|
|
|
|
display = gst_vaapi_display_wayland_new_with_display (wl_display);
|
|
|
|
} else if (!strcmp (type, "wl-display-name")) {
|
|
|
|
const gchar *display_name;
|
|
|
|
g_return_if_fail (G_VALUE_HOLDS_STRING (value));
|
|
|
|
display_name = g_value_get_string (value);
|
|
|
|
display = gst_vaapi_display_wayland_new (display_name);
|
|
|
|
}
|
2012-07-24 07:45:25 +00:00
|
|
|
#endif
|
2012-07-23 16:01:26 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (display) {
|
|
|
|
gst_vaapi_display_replace (display_ptr, display);
|
|
|
|
gst_vaapi_display_unref (display);
|
|
|
|
}
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_reply_to_query (GstQuery * query, GstVaapiDisplay * display)
|
2011-11-04 20:50:15 +00:00
|
|
|
{
|
2013-05-21 16:42:39 +00:00
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
2013-12-21 05:22:30 +00:00
|
|
|
const gchar *type = NULL;
|
|
|
|
GstContext *context;
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (GST_QUERY_TYPE (query) != GST_QUERY_CONTEXT)
|
|
|
|
return FALSE;
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!gst_query_parse_context_type (query, &type))
|
|
|
|
return FALSE;
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (g_strcmp0 (type, GST_VAAPI_DISPLAY_CONTEXT_TYPE_NAME))
|
|
|
|
return FALSE;
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
context = gst_vaapi_video_context_new_with_display (display, FALSE);
|
|
|
|
gst_query_set_context (query, context);
|
|
|
|
gst_context_unref (context);
|
2013-10-01 15:57:11 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
return TRUE;
|
2013-05-21 16:42:39 +00:00
|
|
|
#else
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVaapiDisplayType display_type;
|
|
|
|
const gchar **types;
|
|
|
|
const gchar *type;
|
|
|
|
gint i;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
if (GST_QUERY_TYPE (query) != GST_QUERY_CUSTOM)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
types = gst_video_context_query_get_supported_types (query);
|
|
|
|
|
|
|
|
if (!types)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
display_type = gst_vaapi_display_get_display_type (display);
|
|
|
|
for (i = 0; types[i] && !res; i++) {
|
|
|
|
type = types[i];
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
if (!strcmp (type, "gst-vaapi-display")) {
|
|
|
|
gst_video_context_query_set_pointer (query, type, display);
|
|
|
|
} else if (!strcmp (type, "vaapi-display")) {
|
|
|
|
VADisplay vadpy = gst_vaapi_display_get_display (display);
|
|
|
|
gst_video_context_query_set_pointer (query, type, vadpy);
|
|
|
|
} else {
|
|
|
|
switch (display_type) {
|
2012-08-01 13:46:19 +00:00
|
|
|
#if USE_DRM
|
2013-12-21 05:22:30 +00:00
|
|
|
case GST_VAAPI_DISPLAY_TYPE_DRM:{
|
|
|
|
GstVaapiDisplayDRM *const drm_dpy = GST_VAAPI_DISPLAY_DRM (display);
|
|
|
|
if (!strcmp (type, "drm-device-path"))
|
|
|
|
gst_video_context_query_set_string (query, type,
|
|
|
|
gst_vaapi_display_drm_get_device_path (drm_dpy));
|
2012-08-01 13:46:19 +00:00
|
|
|
#if 0
|
2013-12-21 05:22:30 +00:00
|
|
|
/* XXX: gst_video_context_query_set_int() does not exist yet */
|
|
|
|
else if (!strcmp (type, "drm-device"))
|
|
|
|
gst_video_context_query_set_int (query, type,
|
|
|
|
gst_vaapi_display_drm_get_device (drm_dpy));
|
2012-08-01 13:46:19 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-01 13:46:19 +00:00
|
|
|
#endif
|
2012-07-24 13:07:48 +00:00
|
|
|
#if USE_X11
|
2012-07-25 12:51:28 +00:00
|
|
|
#if USE_GLX
|
2013-12-21 05:22:30 +00:00
|
|
|
case GST_VAAPI_DISPLAY_TYPE_GLX:
|
2012-07-25 12:51:28 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
case GST_VAAPI_DISPLAY_TYPE_X11:{
|
|
|
|
GstVaapiDisplayX11 *const xvadpy = GST_VAAPI_DISPLAY_X11 (display);
|
|
|
|
Display *const x11dpy = gst_vaapi_display_x11_get_display (xvadpy);
|
|
|
|
if (!strcmp (type, "x11-display"))
|
|
|
|
gst_video_context_query_set_pointer (query, type, x11dpy);
|
|
|
|
else if (!strcmp (type, "x11-display-name"))
|
|
|
|
gst_video_context_query_set_string (query, type,
|
|
|
|
DisplayString (x11dpy));
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-24 13:07:48 +00:00
|
|
|
#endif
|
2012-07-24 07:45:25 +00:00
|
|
|
#if USE_WAYLAND
|
2013-12-21 05:22:30 +00:00
|
|
|
case GST_VAAPI_DISPLAY_TYPE_WAYLAND:{
|
|
|
|
GstVaapiDisplayWayland *const wlvadpy =
|
|
|
|
GST_VAAPI_DISPLAY_WAYLAND (display);
|
|
|
|
struct wl_display *const wldpy =
|
|
|
|
gst_vaapi_display_wayland_get_display (wlvadpy);
|
|
|
|
if (!strcmp (type, "wl-display"))
|
|
|
|
gst_video_context_query_set_pointer (query, type, wldpy);
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2012-07-23 16:01:26 +00:00
|
|
|
}
|
2013-12-21 05:22:30 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
2013-12-21 05:22:30 +00:00
|
|
|
}
|
|
|
|
return res;
|
2013-05-21 16:42:39 +00:00
|
|
|
#endif /* !GST_CHECK_VERSION(1,1,0) */
|
2011-11-04 20:50:15 +00:00
|
|
|
}
|
2012-01-05 10:00:39 +00:00
|
|
|
|
|
|
|
gboolean
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_append_surface_caps (GstCaps * out_caps, GstCaps * in_caps)
|
2012-01-05 10:00:39 +00:00
|
|
|
{
|
2013-12-21 05:22:30 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
const GValue *v_width, *v_height, *v_framerate, *v_par;
|
|
|
|
guint i, n_structures;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (in_caps, 0);
|
|
|
|
v_width = gst_structure_get_value (structure, "width");
|
|
|
|
v_height = gst_structure_get_value (structure, "height");
|
|
|
|
v_framerate = gst_structure_get_value (structure, "framerate");
|
|
|
|
v_par = gst_structure_get_value (structure, "pixel-aspect-ratio");
|
|
|
|
if (!v_width || !v_height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
n_structures = gst_caps_get_size (out_caps);
|
|
|
|
for (i = 0; i < n_structures; i++) {
|
|
|
|
structure = gst_caps_get_structure (out_caps, i);
|
|
|
|
gst_structure_set_value (structure, "width", v_width);
|
|
|
|
gst_structure_set_value (structure, "height", v_height);
|
|
|
|
if (v_framerate)
|
|
|
|
gst_structure_set_value (structure, "framerate", v_framerate);
|
|
|
|
if (v_par)
|
|
|
|
gst_structure_set_value (structure, "pixel-aspect-ratio", v_par);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2012-01-05 10:00:39 +00:00
|
|
|
}
|
2013-03-21 15:32:43 +00:00
|
|
|
|
|
|
|
gboolean
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_vaapi_apply_composition (GstVaapiSurface * surface, GstBuffer * buffer)
|
2013-03-21 15:32:43 +00:00
|
|
|
{
|
2012-09-03 11:00:25 +00:00
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVideoOverlayCompositionMeta *const cmeta =
|
|
|
|
gst_buffer_get_video_overlay_composition_meta (buffer);
|
|
|
|
GstVideoOverlayComposition *composition;
|
2012-09-03 11:00:25 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!cmeta)
|
|
|
|
return TRUE;
|
|
|
|
composition = cmeta->overlay;
|
2012-09-03 11:00:25 +00:00
|
|
|
#else
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVideoOverlayComposition *const composition =
|
|
|
|
gst_video_buffer_get_overlay_composition (buffer);
|
2012-09-03 11:00:25 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
if (!composition)
|
|
|
|
return TRUE;
|
|
|
|
return gst_vaapi_surface_set_subpictures_from_composition (surface,
|
|
|
|
composition, TRUE);
|
2013-03-21 15:32:43 +00:00
|
|
|
}
|
2013-10-04 17:30:36 +00:00
|
|
|
|
2013-12-21 05:41:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_value_set_format (GValue * value, GstVideoFormat format)
|
|
|
|
{
|
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
|
|
|
const gchar *str;
|
|
|
|
|
|
|
|
str = gst_video_format_to_string (format);
|
|
|
|
if (!str)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (value, str);
|
|
|
|
#else
|
|
|
|
guint32 fourcc;
|
|
|
|
|
|
|
|
fourcc = gst_video_format_to_fourcc (format);
|
|
|
|
if (!fourcc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_value_init (value, GST_TYPE_FOURCC);
|
|
|
|
gst_value_set_fourcc (value, fourcc);
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_value_set_format_list (GValue * value, GArray * formats)
|
|
|
|
{
|
|
|
|
GValue v_format = G_VALUE_INIT;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_value_init (value, GST_TYPE_LIST);
|
|
|
|
for (i = 0; i < formats->len; i++) {
|
|
|
|
GstVideoFormat const format = g_array_index (formats, GstVideoFormat, i);
|
|
|
|
|
|
|
|
if (!gst_vaapi_value_set_format (&v_format, format))
|
|
|
|
continue;
|
|
|
|
gst_value_list_append_value (value, &v_format);
|
|
|
|
g_value_unset (&v_format);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-21 09:41:22 +00:00
|
|
|
void
|
|
|
|
set_video_template_caps (GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstStructure *const structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
gst_structure_set (structure,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_video_format_new_template_caps (GstVideoFormat format)
|
|
|
|
{
|
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN, NULL);
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty_simple ("video/x-raw");
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gst_caps_set_simple (caps,
|
|
|
|
"format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
|
|
|
|
set_video_template_caps (caps);
|
|
|
|
return caps;
|
|
|
|
#else
|
|
|
|
return gst_video_format_new_template_caps (format);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_video_format_new_template_caps_from_list (GArray * formats)
|
|
|
|
{
|
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
|
|
|
GValue v_formats = G_VALUE_INIT;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty_simple ("video/x-raw");
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_vaapi_value_set_format_list (&v_formats, formats)) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_set_value (caps, "format", &v_formats);
|
|
|
|
set_video_template_caps (caps);
|
2014-08-22 11:25:03 +00:00
|
|
|
g_value_unset (&v_formats);
|
2013-12-21 09:41:22 +00:00
|
|
|
#else
|
|
|
|
GstCaps *caps, *tmp_caps;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (formats != NULL, NULL);
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty ();
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < formats->len; i++) {
|
|
|
|
const GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
|
|
|
|
tmp_caps = gst_vaapi_video_format_new_template_caps (format);
|
|
|
|
if (tmp_caps)
|
|
|
|
gst_caps_append (caps, tmp_caps);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:08:36 +00:00
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_video_format_new_template_caps_with_features (GstVideoFormat format,
|
|
|
|
const gchar * features_string)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_vaapi_video_format_new_template_caps (format);
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
|
|
|
GstCapsFeatures *const features =
|
|
|
|
gst_caps_features_new (features_string, NULL);
|
|
|
|
if (!features) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
gst_caps_set_features (caps, 0, features);
|
|
|
|
#endif
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstVaapiCapsFeature
|
|
|
|
gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstVideoFormat format)
|
|
|
|
{
|
|
|
|
GstVaapiCapsFeature feature = GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY;
|
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
|
|
|
guint i, num_structures;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstCaps *gl_texture_upload_caps = NULL;
|
|
|
|
GstCaps *sysmem_caps = NULL;
|
|
|
|
GstCaps *vaapi_caps = NULL;
|
|
|
|
GstCaps *out_caps;
|
|
|
|
|
|
|
|
out_caps = gst_pad_peer_query_caps (pad, NULL);
|
|
|
|
if (!out_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
gl_texture_upload_caps =
|
|
|
|
gst_vaapi_video_format_new_template_caps_with_features
|
|
|
|
(GST_VIDEO_FORMAT_RGBA,
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META);
|
|
|
|
if (!gl_texture_upload_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_ENCODED)
|
2014-07-23 08:23:06 +00:00
|
|
|
format = GST_VIDEO_FORMAT_I420;
|
2014-01-14 18:08:36 +00:00
|
|
|
|
|
|
|
vaapi_caps =
|
|
|
|
gst_vaapi_video_format_new_template_caps_with_features (format,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE);
|
|
|
|
if (!vaapi_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
sysmem_caps =
|
|
|
|
gst_vaapi_video_format_new_template_caps_with_features (format,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
if (!sysmem_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
num_structures = gst_caps_get_size (out_caps);
|
|
|
|
for (i = 0; i < num_structures; i++) {
|
|
|
|
GstCapsFeatures *const features = gst_caps_get_features (out_caps, i);
|
|
|
|
GstStructure *const structure = gst_caps_get_structure (out_caps, i);
|
|
|
|
|
2014-07-28 16:00:19 +00:00
|
|
|
#if GST_CHECK_VERSION(1,3,0)
|
|
|
|
/* Skip ANY features, we need an exact match for correct evaluation */
|
|
|
|
if (gst_caps_features_is_any (features))
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
2014-01-14 18:08:36 +00:00
|
|
|
caps = gst_caps_new_full (gst_structure_copy (structure), NULL);
|
|
|
|
if (!caps)
|
|
|
|
continue;
|
|
|
|
gst_caps_set_features (caps, 0, gst_caps_features_copy (features));
|
|
|
|
|
|
|
|
if (gst_caps_can_intersect (caps, vaapi_caps) &&
|
|
|
|
feature < GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE)
|
|
|
|
feature = GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE;
|
|
|
|
else if (gst_caps_can_intersect (caps, gl_texture_upload_caps) &&
|
|
|
|
feature < GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META)
|
|
|
|
feature = GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META;
|
|
|
|
else if (gst_caps_can_intersect (caps, sysmem_caps) &&
|
|
|
|
feature < GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY)
|
|
|
|
feature = GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY;
|
|
|
|
gst_caps_replace (&caps, NULL);
|
2014-07-28 16:00:19 +00:00
|
|
|
|
|
|
|
#if GST_CHECK_VERSION(1,3,0)
|
|
|
|
/* Stop at the first match, the caps should already be sorted out
|
|
|
|
by preference order from downstream elements */
|
|
|
|
if (feature != GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY)
|
|
|
|
break;
|
|
|
|
#endif
|
2014-01-14 18:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
gst_caps_replace (&gl_texture_upload_caps, NULL);
|
|
|
|
gst_caps_replace (&sysmem_caps, NULL);
|
|
|
|
gst_caps_replace (&vaapi_caps, NULL);
|
|
|
|
gst_caps_replace (&caps, NULL);
|
|
|
|
gst_caps_replace (&out_caps, NULL);
|
|
|
|
#endif
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
|
2014-08-22 13:22:32 +00:00
|
|
|
const gchar *
|
|
|
|
gst_vaapi_caps_feature_to_string (GstVaapiCapsFeature feature)
|
|
|
|
{
|
|
|
|
const gchar *str;
|
|
|
|
|
|
|
|
switch (feature) {
|
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
|
|
|
case GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY:
|
|
|
|
str = GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META:
|
|
|
|
str = GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE:
|
|
|
|
str = GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
str = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-10-04 17:30:36 +00:00
|
|
|
gboolean
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip)
|
2013-10-04 17:30:36 +00:00
|
|
|
{
|
|
|
|
#if GST_CHECK_VERSION(1,0,0)
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVideoInterlaceMode mode;
|
|
|
|
const gchar *mode_str;
|
2013-10-04 17:30:36 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
mode = vip ? GST_VIDEO_INFO_INTERLACE_MODE (vip) :
|
|
|
|
GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
|
|
|
switch (mode) {
|
2013-10-04 17:30:36 +00:00
|
|
|
case GST_VIDEO_INTERLACE_MODE_PROGRESSIVE:
|
2013-12-21 05:22:30 +00:00
|
|
|
mode_str = "progressive";
|
|
|
|
break;
|
2013-10-04 17:30:36 +00:00
|
|
|
case GST_VIDEO_INTERLACE_MODE_INTERLEAVED:
|
2013-12-21 05:22:30 +00:00
|
|
|
mode_str = "interleaved";
|
|
|
|
break;
|
2013-10-04 14:00:56 +00:00
|
|
|
case GST_VIDEO_INTERLACE_MODE_MIXED:
|
2013-12-21 05:22:30 +00:00
|
|
|
mode_str = "mixed";
|
|
|
|
break;
|
2013-10-04 17:30:36 +00:00
|
|
|
default:
|
2013-12-21 05:22:30 +00:00
|
|
|
GST_ERROR ("unsupported `interlace-mode' %d", mode);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-04 17:30:36 +00:00
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING, mode_str, NULL);
|
2013-10-04 17:30:36 +00:00
|
|
|
#else
|
2013-12-21 05:22:30 +00:00
|
|
|
gst_caps_set_simple (caps, "interlaced", G_TYPE_BOOLEAN,
|
|
|
|
vip ? GST_VIDEO_INFO_IS_INTERLACED (vip) : FALSE, NULL);
|
2013-10-04 17:30:36 +00:00
|
|
|
#endif
|
2013-12-21 05:22:30 +00:00
|
|
|
return TRUE;
|
2013-10-04 17:30:36 +00:00
|
|
|
}
|
2014-08-20 09:30:41 +00:00
|
|
|
|
|
|
|
/* Checks whether the supplied caps contain VA surfaces */
|
|
|
|
gboolean
|
|
|
|
gst_caps_has_vaapi_surface (GstCaps * caps)
|
|
|
|
{
|
|
|
|
gboolean found_caps = FALSE;
|
|
|
|
guint i, num_structures;
|
|
|
|
|
|
|
|
g_return_val_if_fail (caps != NULL, FALSE);
|
|
|
|
|
|
|
|
num_structures = gst_caps_get_size (caps);
|
|
|
|
if (num_structures < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
#if GST_CHECK_VERSION(1,1,0)
|
|
|
|
for (i = 0; i < num_structures && !found_caps; i++) {
|
|
|
|
GstCapsFeatures *const features = gst_caps_get_features (caps, i);
|
|
|
|
|
|
|
|
#if GST_CHECK_VERSION(1,3,0)
|
|
|
|
/* Skip ANY features, we need an exact match for correct evaluation */
|
|
|
|
if (gst_caps_features_is_any (features))
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
found_caps = gst_caps_features_contains (features,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
for (i = 0; i < num_structures && !found_caps; i++) {
|
|
|
|
GstStructure *const structure = gst_caps_get_structure (caps, i);
|
|
|
|
GstCaps *test_caps;
|
|
|
|
GstVideoInfo vi;
|
|
|
|
|
|
|
|
test_caps = gst_caps_new_full (gst_structure_copy (structure), NULL);
|
|
|
|
if (!test_caps)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
found_caps = gst_video_info_from_caps (&vi, test_caps) &&
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vi) == GST_VIDEO_FORMAT_ENCODED;
|
|
|
|
gst_caps_unref (test_caps);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return found_caps;
|
|
|
|
}
|
2014-11-18 13:57:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_video_info_change_format (GstVideoInfo * vip, GstVideoFormat format,
|
|
|
|
guint width, guint height)
|
|
|
|
{
|
|
|
|
GstVideoInfo vi = *vip;
|
|
|
|
|
|
|
|
gst_video_info_set_format (vip, format, width, height);
|
|
|
|
|
|
|
|
vip->interlace_mode = vi.interlace_mode;
|
|
|
|
vip->flags = vi.flags;
|
|
|
|
vip->views = vi.views;
|
|
|
|
vip->par_n = vi.par_n;
|
|
|
|
vip->par_d = vi.par_d;
|
|
|
|
vip->fps_n = vi.fps_n;
|
|
|
|
vip->fps_d = vi.fps_d;
|
|
|
|
}
|