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
|
|
|
|
*/
|
|
|
|
|
2015-04-03 14:08:30 +00:00
|
|
|
#include "gstcompat.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
|
2015-02-20 14:29:17 +00:00
|
|
|
#if USE_EGL
|
|
|
|
# include <gst/vaapi/gstvaapidisplay_egl.h>
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
2015-02-20 14:29:17 +00:00
|
|
|
typedef GstVaapiDisplay *(*GstVaapiDisplayCreateFunc) (const gchar *);
|
|
|
|
typedef GstVaapiDisplay *(*GstVaapiDisplayCreateFromHandleFunc) (gpointer);
|
|
|
|
|
2013-12-21 05:22:30 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const gchar *type_str;
|
|
|
|
GstVaapiDisplayType type;
|
2015-02-20 14:29:17 +00:00
|
|
|
GstVaapiDisplayCreateFunc create_display;
|
|
|
|
GstVaapiDisplayCreateFromHandleFunc create_display_from_handle;
|
2012-07-23 16:37:38 +00:00
|
|
|
} DisplayMap;
|
|
|
|
|
2015-02-20 14:29:17 +00:00
|
|
|
/* *INDENT-OFF* */
|
2012-07-23 16:37:38 +00:00
|
|
|
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",
|
2015-02-20 14:29:17 +00:00
|
|
|
GST_VAAPI_DISPLAY_TYPE_WAYLAND,
|
|
|
|
gst_vaapi_display_wayland_new,
|
|
|
|
(GstVaapiDisplayCreateFromHandleFunc)
|
|
|
|
gst_vaapi_display_wayland_new_with_display},
|
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",
|
2015-02-20 14:29:17 +00:00
|
|
|
GST_VAAPI_DISPLAY_TYPE_GLX,
|
|
|
|
gst_vaapi_display_glx_new,
|
|
|
|
(GstVaapiDisplayCreateFromHandleFunc)
|
|
|
|
gst_vaapi_display_glx_new_with_display},
|
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",
|
2015-02-20 14:29:17 +00:00
|
|
|
GST_VAAPI_DISPLAY_TYPE_X11,
|
|
|
|
gst_vaapi_display_x11_new,
|
|
|
|
(GstVaapiDisplayCreateFromHandleFunc)
|
|
|
|
gst_vaapi_display_x11_new_with_display},
|
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",
|
2015-02-20 14:29:17 +00:00
|
|
|
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
|
|
|
};
|
2015-02-20 14:29:17 +00:00
|
|
|
/* *INDENT-ON* */
|
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
|
|
|
}
|
|
|
|
|
2015-02-20 14:29:17 +00:00
|
|
|
static GstVaapiDisplay *
|
|
|
|
gst_vaapi_create_display_from_handle (GstVaapiDisplayType display_type,
|
|
|
|
gpointer handle)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
const DisplayMap *m;
|
|
|
|
|
|
|
|
if (display_type == GST_VAAPI_DISPLAY_TYPE_ANY)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (m = g_display_map; m->type_str != NULL; m++) {
|
|
|
|
if (m->type == display_type) {
|
|
|
|
display = m->create_display_from_handle ?
|
|
|
|
m->create_display_from_handle (handle) : NULL;
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstVaapiDisplay *
|
|
|
|
gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object)
|
|
|
|
{
|
|
|
|
#if USE_GST_GL_HELPERS
|
|
|
|
GstGLContext *const gl_context = GST_GL_CONTEXT (gl_context_object);
|
|
|
|
GstGLDisplay *const gl_display = gst_gl_context_get_display (gl_context);
|
2015-01-23 08:31:57 +00:00
|
|
|
gpointer native_display =
|
|
|
|
GSIZE_TO_POINTER (gst_gl_display_get_handle (gl_display));
|
2015-02-20 14:29:17 +00:00
|
|
|
GstVaapiDisplay *display, *out_display;
|
|
|
|
GstVaapiDisplayType display_type;
|
|
|
|
|
|
|
|
switch (gst_gl_display_get_handle_type (gl_display)) {
|
|
|
|
#if USE_X11
|
|
|
|
case GST_GL_DISPLAY_TYPE_X11:
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_X11;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if USE_WAYLAND
|
|
|
|
case GST_GL_DISPLAY_TYPE_WAYLAND:
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND;
|
|
|
|
break;
|
|
|
|
#endif
|
2015-01-23 08:31:57 +00:00
|
|
|
case GST_GL_DISPLAY_TYPE_ANY:{
|
|
|
|
/* Derive from the active window */
|
|
|
|
GstGLWindow *const gl_window = gst_gl_context_get_window (gl_context);
|
|
|
|
const gchar *const gl_window_type = g_getenv ("GST_GL_WINDOW");
|
|
|
|
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
|
|
|
|
if (!gl_window)
|
|
|
|
break;
|
|
|
|
native_display = GSIZE_TO_POINTER (gst_gl_window_get_display (gl_window));
|
|
|
|
|
|
|
|
if (gl_window_type) {
|
|
|
|
#if USE_X11
|
|
|
|
if (!display_type && g_strcmp0 (gl_window_type, "x11") == 0)
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_X11;
|
|
|
|
#endif
|
|
|
|
#if USE_WAYLAND
|
|
|
|
if (!display_type && g_strcmp0 (gl_window_type, "wayland") == 0)
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#if USE_X11
|
|
|
|
if (!display_type && GST_GL_HAVE_WINDOW_X11)
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_X11;
|
|
|
|
#endif
|
|
|
|
#if USE_WAYLAND
|
|
|
|
if (!display_type && GST_GL_HAVE_WINDOW_WAYLAND)
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-02-20 14:29:17 +00:00
|
|
|
default:
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!display_type)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-23 08:31:57 +00:00
|
|
|
display = gst_vaapi_create_display_from_handle (display_type, native_display);
|
2015-02-20 14:29:17 +00:00
|
|
|
if (!display)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (gst_gl_context_get_gl_platform (gl_context)) {
|
|
|
|
#if USE_EGL
|
|
|
|
case GST_GL_PLATFORM_EGL:{
|
|
|
|
guint gles_version;
|
|
|
|
|
|
|
|
switch (gst_gl_context_get_gl_api (gl_context)) {
|
|
|
|
case GST_GL_API_GLES1:
|
|
|
|
gles_version = 1;
|
|
|
|
goto create_egl_display;
|
|
|
|
case GST_GL_API_GLES2:
|
|
|
|
gles_version = 2;
|
|
|
|
goto create_egl_display;
|
|
|
|
case GST_GL_API_OPENGL:
|
|
|
|
case GST_GL_API_OPENGL3:
|
|
|
|
gles_version = 0;
|
|
|
|
create_egl_display:
|
|
|
|
out_display = gst_vaapi_display_egl_new (display, gles_version);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out_display = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!out_display)
|
|
|
|
return NULL;
|
|
|
|
gst_vaapi_display_egl_set_gl_context (GST_VAAPI_DISPLAY_EGL (out_display),
|
|
|
|
GSIZE_TO_POINTER (gst_gl_context_get_gl_context (gl_context)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
out_display = gst_vaapi_display_ref (display);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_vaapi_display_unref (display);
|
|
|
|
return out_display;
|
|
|
|
#endif
|
|
|
|
GST_ERROR ("unsupported GStreamer version %s", GST_API_VERSION_S);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-04 20:50:15 +00:00
|
|
|
gboolean
|
2015-05-08 13:54:09 +00:00
|
|
|
gst_vaapi_ensure_display (GstElement * 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;
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2015-05-08 13:54:09 +00:00
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
2011-11-04 20:50:15 +00:00
|
|
|
|
2015-05-08 13:54:09 +00:00
|
|
|
gst_vaapi_video_context_prepare (element, 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 */
|
2014-12-03 14:45:52 +00:00
|
|
|
if (gst_vaapi_plugin_base_has_display_type (plugin, type))
|
2013-12-21 05:22:30 +00:00
|
|
|
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 */
|
2015-02-20 14:29:17 +00:00
|
|
|
if (plugin->gl_context)
|
|
|
|
display = gst_vaapi_create_display_from_gl_context (plugin->gl_context);
|
|
|
|
else
|
|
|
|
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
|
|
|
|
2015-05-08 13:54:09 +00:00
|
|
|
gst_vaapi_video_context_propagate (element, display);
|
2013-12-21 05:22:30 +00:00
|
|
|
GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE (plugin, display);
|
|
|
|
gst_vaapi_display_unref (display);
|
|
|
|
return TRUE;
|
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-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;
|
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
|
|
|
{
|
2013-12-21 05:22:30 +00:00
|
|
|
GstVideoOverlayCompositionMeta *const cmeta =
|
|
|
|
gst_buffer_get_video_overlay_composition_meta (buffer);
|
2015-01-27 14:25:21 +00:00
|
|
|
GstVideoOverlayComposition *composition = NULL;
|
2012-09-03 11:00:25 +00:00
|
|
|
|
2015-01-27 14:25:21 +00:00
|
|
|
if (cmeta)
|
|
|
|
composition = cmeta->overlay;
|
2013-12-21 05:22:30 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_video_format_new_template_caps_from_list (GArray * formats)
|
|
|
|
{
|
|
|
|
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
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
static GstCaps *
|
|
|
|
new_gl_texture_upload_meta_caps (void)
|
|
|
|
{
|
|
|
|
return gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES (
|
|
|
|
GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, "{ RGBA, BGRA }"));
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:08:36 +00:00
|
|
|
GstVaapiCapsFeature
|
2015-02-09 20:09:07 +00:00
|
|
|
gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstVideoFormat format,
|
|
|
|
GstVideoFormat * out_format_ptr)
|
2014-01-14 18:08:36 +00:00
|
|
|
{
|
|
|
|
GstVaapiCapsFeature feature = GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY;
|
|
|
|
guint i, num_structures;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstCaps *gl_texture_upload_caps = NULL;
|
|
|
|
GstCaps *sysmem_caps = NULL;
|
|
|
|
GstCaps *vaapi_caps = NULL;
|
|
|
|
GstCaps *out_caps;
|
2015-02-09 20:09:07 +00:00
|
|
|
GstVideoFormat out_format;
|
2014-01-14 18:08:36 +00:00
|
|
|
|
vaapidecode: delayed src caps negotiation
Currently the src caps are set immediately after the sink caps are set, but in
that moment the pipeline might not fully constructed and the video sink has
not negotiated its supported caps and features. As a consequence, in many cases
of playback, the least optimized caps feature is forced. This is partially the
responsible of bug #744039.
Also, vaapidecode doesn't attend the reconfigure events from downstream,
which is a problem too, since the video sink can be changed with different
caps features.
This patch delays the src caps, setting them until the first frame arrives to
the decoder, assuming until that very moment the whole pipeline is already
negotiated. Particularly, it checks if the src pad needs to be reconfigured,
as a consequence of a reconfiguration event from downstream.
A key part of this patch is the new GstVaapiCapsFeature
GST_VAAPI_CAPS_FEATURE_NOT_NEGOTIATED, which is returned when the src pad
doesn't have a peer yet. Also, for a better report of the caps allowed
through the src pad and its peer, this patch uses gst_pad_get_allowed_caps()
instead of gst_pad_peer_query_caps() when looking for the preferred feature.
v3: move the input_state unref to close(), since videodecoder resets at
some events such as navigation.
v4: a) the state_changed() callback replaces the input_state if the media
changed, so this case is also handled.
b) since the parameter ref_state in gst_vaapidecode_update_src_caps() is
always the input_state, the parameter were removed.
c) there were a lot of repeated code handling the input_state, so I
refactored it with the function gst_vaapi_decode_input_state_replace().
https://bugzilla.gnome.org/show_bug.cgi?id=744618
Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
2015-02-26 10:24:55 +00:00
|
|
|
out_caps= gst_pad_get_allowed_caps (pad);
|
|
|
|
if (!out_caps) {
|
|
|
|
feature = GST_VAAPI_CAPS_FEATURE_NOT_NEGOTIATED;
|
2014-01-14 18:08:36 +00:00
|
|
|
goto cleanup;
|
vaapidecode: delayed src caps negotiation
Currently the src caps are set immediately after the sink caps are set, but in
that moment the pipeline might not fully constructed and the video sink has
not negotiated its supported caps and features. As a consequence, in many cases
of playback, the least optimized caps feature is forced. This is partially the
responsible of bug #744039.
Also, vaapidecode doesn't attend the reconfigure events from downstream,
which is a problem too, since the video sink can be changed with different
caps features.
This patch delays the src caps, setting them until the first frame arrives to
the decoder, assuming until that very moment the whole pipeline is already
negotiated. Particularly, it checks if the src pad needs to be reconfigured,
as a consequence of a reconfiguration event from downstream.
A key part of this patch is the new GstVaapiCapsFeature
GST_VAAPI_CAPS_FEATURE_NOT_NEGOTIATED, which is returned when the src pad
doesn't have a peer yet. Also, for a better report of the caps allowed
through the src pad and its peer, this patch uses gst_pad_get_allowed_caps()
instead of gst_pad_peer_query_caps() when looking for the preferred feature.
v3: move the input_state unref to close(), since videodecoder resets at
some events such as navigation.
v4: a) the state_changed() callback replaces the input_state if the media
changed, so this case is also handled.
b) since the parameter ref_state in gst_vaapidecode_update_src_caps() is
always the input_state, the parameter were removed.
c) there were a lot of repeated code handling the input_state, so I
refactored it with the function gst_vaapi_decode_input_state_replace().
https://bugzilla.gnome.org/show_bug.cgi?id=744618
Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
2015-02-26 10:24:55 +00:00
|
|
|
}
|
2014-01-14 18:08:36 +00:00
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
out_format = format == GST_VIDEO_FORMAT_ENCODED ?
|
|
|
|
GST_VIDEO_FORMAT_I420 : format;
|
|
|
|
|
|
|
|
gl_texture_upload_caps = new_gl_texture_upload_meta_caps ();
|
2014-01-14 18:08:36 +00:00
|
|
|
if (!gl_texture_upload_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vaapi_caps =
|
2015-02-09 20:09:07 +00:00
|
|
|
gst_vaapi_video_format_new_template_caps_with_features (out_format,
|
2014-01-14 18:08:36 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE);
|
|
|
|
if (!vaapi_caps)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
sysmem_caps =
|
2015-02-09 20:09:07 +00:00
|
|
|
gst_vaapi_video_format_new_template_caps_with_features (out_format,
|
2014-01-14 18:08:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-02-09 20:09:07 +00:00
|
|
|
if (out_format_ptr) {
|
|
|
|
if (feature == GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META) {
|
|
|
|
GstStructure *structure;
|
|
|
|
gchar *format_str;
|
|
|
|
out_format = GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
do {
|
|
|
|
caps = gst_caps_intersect_full (out_caps, gl_texture_upload_caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
if (!caps)
|
|
|
|
break;
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (!structure)
|
|
|
|
break;
|
|
|
|
if (!gst_structure_get (structure, "format", G_TYPE_STRING,
|
|
|
|
&format_str, NULL))
|
|
|
|
break;
|
|
|
|
out_format = gst_video_format_from_string (format_str);
|
|
|
|
g_free (format_str);
|
|
|
|
} while (0);
|
|
|
|
if (!out_format)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*out_format_ptr = out_format;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
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
|
|
|
{
|
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);
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|