2013-12-13 09:24:26 +00:00
|
|
|
/*
|
|
|
|
* gstvaapipluginbase.c - Base GStreamer VA-API Plugin element
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-12-13 09:24:26 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
|
|
|
*
|
|
|
|
* 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"
|
2014-01-23 10:00:09 +00:00
|
|
|
#include <gst/vaapi/gstvaapisurface_drm.h>
|
2015-01-26 17:30:47 +00:00
|
|
|
#include <gst/base/gstpushsrc.h>
|
2013-12-13 09:24:26 +00:00
|
|
|
#include "gstvaapipluginbase.h"
|
2013-12-13 10:52:47 +00:00
|
|
|
#include "gstvaapipluginutil.h"
|
2013-12-13 15:03:08 +00:00
|
|
|
#include "gstvaapivideocontext.h"
|
2013-12-17 17:52:23 +00:00
|
|
|
#include "gstvaapivideometa.h"
|
|
|
|
#include "gstvaapivideobufferpool.h"
|
2017-01-26 11:02:56 +00:00
|
|
|
#if USE_GST_GL_HELPERS
|
|
|
|
# include <gst/gl/gl.h>
|
|
|
|
#endif
|
2013-12-13 09:24:26 +00:00
|
|
|
|
2018-02-15 18:32:19 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
|
2013-12-13 10:52:47 +00:00
|
|
|
/* Default debug category is from the subclass */
|
2013-12-13 09:24:26 +00:00
|
|
|
#define GST_CAT_DEFAULT (plugin->debug_category)
|
|
|
|
|
2017-01-10 06:15:31 +00:00
|
|
|
#define BUFFER_POOL_SINK_MIN_BUFFERS 2
|
|
|
|
|
2013-12-13 15:03:08 +00:00
|
|
|
/* GstVideoContext interface */
|
2014-07-25 09:13:29 +00:00
|
|
|
static void
|
|
|
|
plugin_set_display (GstVaapiPluginBase * plugin, GstVaapiDisplay * display)
|
|
|
|
{
|
|
|
|
const gchar *const display_name =
|
|
|
|
gst_vaapi_display_get_display_name (display);
|
|
|
|
|
|
|
|
if (plugin->display_name && g_strcmp0 (plugin->display_name, display_name)) {
|
|
|
|
GST_DEBUG_OBJECT (plugin, "incompatible display name '%s', requested '%s'",
|
|
|
|
display_name, plugin->display_name);
|
|
|
|
gst_vaapi_display_replace (&plugin->display, NULL);
|
|
|
|
} else {
|
2016-11-02 14:38:52 +00:00
|
|
|
GST_INFO_OBJECT (plugin, "set display %" GST_PTR_FORMAT, display);
|
2014-07-25 09:13:29 +00:00
|
|
|
gst_vaapi_display_replace (&plugin->display, display);
|
|
|
|
plugin->display_type = gst_vaapi_display_get_display_type (display);
|
|
|
|
gst_vaapi_plugin_base_set_display_name (plugin, display_name);
|
|
|
|
}
|
2018-06-13 15:54:23 +00:00
|
|
|
gst_object_unref (display);
|
2014-07-25 09:13:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 10:57:30 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_context:
|
|
|
|
* @plugin: a #GstVaapiPluginBase instance
|
|
|
|
* @context: a #GstContext to set
|
|
|
|
*
|
|
|
|
* This is a common set_context() element's vmethod for all the
|
|
|
|
* GStreamer VA-API elements.
|
|
|
|
*
|
|
|
|
* It normally should be used through the macro
|
|
|
|
* #GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT()
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin,
|
|
|
|
GstContext * context)
|
2013-12-13 15:03:08 +00:00
|
|
|
{
|
|
|
|
GstVaapiDisplay *display = NULL;
|
|
|
|
|
vaapivideocontext: only vaapisink process app context
gst.vaapi.app.Display context is made for applications that will
provide the VA display and the native display to used by the
pipeline, when are using vaapisink as overlay. There are no use
case for encoders, decoders, neither for the postprocessor.
In the case of the vaapisink, it shall query for gst.vaapi.Display
upstream first, and then, if there is no reply,
gst.vaapi.app.Display context will be posted in the bus for the
application. If the application replies, a GstVaapiDisplay object
is instantiated given the context info, otherwise a
GstVaapiDisplay is created with the normal algorithm to guess the
graphics platform. Either way, the instantiated GstVaapiDisplay
is propagated among the pipeline and the have-message bus message.
Also only vaapisink will process the gst.vaapi.app.Display, if
and only if, it doesn't have a display already set. This is
caused because if vaapisink is in a bin (playsink, for example)
the need-context is posted twice, leading to an error state.
https://bugzilla.gnome.org/show_bug.cgi?id=790999
2017-11-29 10:02:03 +00:00
|
|
|
/* gst.vaapi.app.Display is only attended _if_ the element is
|
|
|
|
* vaapisink and it doesn't have a display set yet */
|
|
|
|
if (gst_vaapi_video_context_get_display (context,
|
|
|
|
GST_IS_VIDEO_SINK (plugin) && !plugin->display, &display)) {
|
2014-07-25 09:13:29 +00:00
|
|
|
plugin_set_display (plugin, display);
|
vaapivideocontext: only vaapisink process app context
gst.vaapi.app.Display context is made for applications that will
provide the VA display and the native display to used by the
pipeline, when are using vaapisink as overlay. There are no use
case for encoders, decoders, neither for the postprocessor.
In the case of the vaapisink, it shall query for gst.vaapi.Display
upstream first, and then, if there is no reply,
gst.vaapi.app.Display context will be posted in the bus for the
application. If the application replies, a GstVaapiDisplay object
is instantiated given the context info, otherwise a
GstVaapiDisplay is created with the normal algorithm to guess the
graphics platform. Either way, the instantiated GstVaapiDisplay
is propagated among the pipeline and the have-message bus message.
Also only vaapisink will process the gst.vaapi.app.Display, if
and only if, it doesn't have a display already set. This is
caused because if vaapisink is in a bin (playsink, for example)
the need-context is posted twice, leading to an error state.
https://bugzilla.gnome.org/show_bug.cgi?id=790999
2017-11-29 10:02:03 +00:00
|
|
|
}
|
2017-01-26 11:02:56 +00:00
|
|
|
#if USE_GST_GL_HELPERS
|
2018-04-26 13:03:23 +00:00
|
|
|
gst_gl_handle_set_context (GST_ELEMENT_CAST (plugin), context,
|
|
|
|
(GstGLDisplay **) & plugin->gl_display,
|
|
|
|
(GstGLContext **) & plugin->gl_other_context);
|
2017-01-26 11:02:56 +00:00
|
|
|
#endif
|
2013-12-13 15:03:08 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 12:24:24 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_init_interfaces (GType g_define_type_id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
default_has_interface (GstVaapiPluginBase * plugin, GType type)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-12-13 10:52:47 +00:00
|
|
|
static void
|
|
|
|
default_display_changed (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-31 06:26:33 +00:00
|
|
|
static GstVaapiSurface *
|
|
|
|
_get_cached_surface (GstBuffer * buf)
|
|
|
|
{
|
|
|
|
return gst_mini_object_get_qdata (GST_MINI_OBJECT (buf),
|
|
|
|
g_quark_from_static_string ("GstVaapiDMABufSurface"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_set_cached_surface (GstBuffer * buf, GstVaapiSurface * surface)
|
|
|
|
{
|
|
|
|
return gst_mini_object_set_qdata (GST_MINI_OBJECT (buf),
|
|
|
|
g_quark_from_static_string ("GstVaapiDMABufSurface"), surface,
|
|
|
|
(GDestroyNotify) gst_vaapi_object_unref);
|
|
|
|
}
|
|
|
|
|
2014-01-23 10:00:09 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_update_sinkpad_info_from_buffer (GstVaapiPluginBase * plugin,
|
|
|
|
GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstVideoInfo *const vip = &plugin->sinkpad_info;
|
|
|
|
GstVideoMeta *vmeta;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
vmeta = gst_buffer_get_video_meta (buf);
|
|
|
|
if (!vmeta)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (vip) != vmeta->format ||
|
|
|
|
GST_VIDEO_INFO_WIDTH (vip) != vmeta->width ||
|
|
|
|
GST_VIDEO_INFO_HEIGHT (vip) != vmeta->height ||
|
|
|
|
GST_VIDEO_INFO_N_PLANES (vip) != vmeta->n_planes)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (vip); ++i) {
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (vip, i) = vmeta->offset[i];
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (vip, i) = vmeta->stride[i];
|
|
|
|
}
|
|
|
|
GST_VIDEO_INFO_SIZE (vip) = gst_buffer_get_size (buf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_dma_buffer (GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstMemory *mem;
|
|
|
|
|
|
|
|
if (gst_buffer_n_memory (buf) < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
mem = gst_buffer_peek_memory (buf, 0);
|
|
|
|
if (!mem || !gst_is_dmabuf_memory (mem))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_bind_dma_to_vaapi_buffer (GstVaapiPluginBase * plugin,
|
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf)
|
|
|
|
{
|
|
|
|
GstVideoInfo *const vip = &plugin->sinkpad_info;
|
|
|
|
GstVaapiVideoMeta *meta;
|
|
|
|
GstVaapiSurface *surface;
|
|
|
|
GstVaapiSurfaceProxy *proxy;
|
|
|
|
gint fd;
|
|
|
|
|
|
|
|
fd = gst_dmabuf_memory_get_fd (gst_buffer_peek_memory (inbuf, 0));
|
|
|
|
if (fd < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!plugin_update_sinkpad_info_from_buffer (plugin, inbuf))
|
|
|
|
goto error_update_sinkpad_info;
|
|
|
|
|
|
|
|
meta = gst_buffer_get_vaapi_video_meta (outbuf);
|
|
|
|
g_return_val_if_fail (meta != NULL, FALSE);
|
|
|
|
|
2016-05-31 06:26:33 +00:00
|
|
|
/* Check for a VASurface cached in the buffer */
|
|
|
|
surface = _get_cached_surface (inbuf);
|
|
|
|
if (!surface) {
|
|
|
|
/* otherwise create one and cache it */
|
|
|
|
surface =
|
|
|
|
gst_vaapi_surface_new_with_dma_buf_handle (plugin->display, fd, vip);
|
|
|
|
if (!surface)
|
|
|
|
goto error_create_surface;
|
|
|
|
_set_cached_surface (inbuf, surface);
|
|
|
|
}
|
2014-01-23 10:00:09 +00:00
|
|
|
|
|
|
|
proxy = gst_vaapi_surface_proxy_new (surface);
|
|
|
|
if (!proxy)
|
|
|
|
goto error_create_proxy;
|
|
|
|
gst_vaapi_video_meta_set_surface_proxy (meta, proxy);
|
|
|
|
gst_vaapi_surface_proxy_unref (proxy);
|
2016-05-31 09:52:57 +00:00
|
|
|
gst_buffer_add_parent_buffer_meta (outbuf, inbuf);
|
2014-01-23 10:00:09 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_update_sinkpad_info:
|
2016-05-23 15:47:36 +00:00
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin,
|
|
|
|
"failed to update sink pad video info from video meta");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-01-23 10:00:09 +00:00
|
|
|
error_create_surface:
|
2016-05-23 15:47:36 +00:00
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin,
|
|
|
|
"failed to create VA surface from dma_buf handle");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-01-23 10:00:09 +00:00
|
|
|
error_create_proxy:
|
2016-05-23 15:47:36 +00:00
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin,
|
|
|
|
"failed to create VA surface proxy from wrapped VA surface");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-01-23 10:00:09 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 07:34:48 +00:00
|
|
|
static void
|
|
|
|
plugin_reset_texture_map (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
if (plugin->display)
|
|
|
|
gst_vaapi_display_reset_texture_map (plugin->display);
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:24:26 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass)
|
|
|
|
{
|
2013-12-13 12:24:24 +00:00
|
|
|
klass->has_interface = default_has_interface;
|
2013-12-13 10:52:47 +00:00
|
|
|
klass->display_changed = default_display_changed;
|
2013-12-13 09:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_init (GstVaapiPluginBase * plugin,
|
|
|
|
GstDebugCategory * debug_category)
|
|
|
|
{
|
|
|
|
plugin->debug_category = debug_category;
|
2013-12-13 10:52:47 +00:00
|
|
|
plugin->display_type = GST_VAAPI_DISPLAY_TYPE_ANY;
|
|
|
|
plugin->display_type_req = GST_VAAPI_DISPLAY_TYPE_ANY;
|
2013-12-17 17:46:07 +00:00
|
|
|
|
|
|
|
/* sink pad */
|
|
|
|
plugin->sinkpad = gst_element_get_static_pad (GST_ELEMENT (plugin), "sink");
|
|
|
|
gst_video_info_init (&plugin->sinkpad_info);
|
|
|
|
|
|
|
|
/* src pad */
|
2016-01-22 18:27:13 +00:00
|
|
|
if (!(GST_OBJECT_FLAGS (plugin) & GST_ELEMENT_FLAG_SINK))
|
2013-12-17 17:46:07 +00:00
|
|
|
plugin->srcpad = gst_element_get_static_pad (GST_ELEMENT (plugin), "src");
|
|
|
|
gst_video_info_init (&plugin->srcpad_info);
|
2016-12-08 17:51:54 +00:00
|
|
|
|
|
|
|
plugin->enable_direct_rendering =
|
|
|
|
(g_getenv ("GST_VAAPI_ENABLE_DIRECT_RENDERING") != NULL);
|
2013-12-13 09:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_finalize (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
gst_vaapi_plugin_base_close (plugin);
|
2014-08-22 11:25:03 +00:00
|
|
|
g_free (plugin->display_name);
|
2013-12-17 17:46:07 +00:00
|
|
|
if (plugin->sinkpad)
|
|
|
|
gst_object_unref (plugin->sinkpad);
|
|
|
|
if (plugin->srcpad)
|
|
|
|
gst_object_unref (plugin->srcpad);
|
2013-12-13 09:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_open:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
*
|
|
|
|
* Allocates any internal resources needed for correct operation from
|
|
|
|
* the subclass.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_open (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_close:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
*
|
|
|
|
* Deallocates all internal resources that were allocated so
|
|
|
|
* far. i.e. put the base plugin object into a clean state.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_close (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
2016-09-22 07:34:48 +00:00
|
|
|
/* Release vaapi textures first if exist, which refs display object */
|
|
|
|
plugin_reset_texture_map (plugin);
|
|
|
|
|
2013-12-13 09:24:26 +00:00
|
|
|
gst_vaapi_display_replace (&plugin->display, NULL);
|
2014-12-03 13:14:30 +00:00
|
|
|
gst_object_replace (&plugin->gl_context, NULL);
|
2017-01-26 11:02:56 +00:00
|
|
|
gst_object_replace (&plugin->gl_display, NULL);
|
|
|
|
gst_object_replace (&plugin->gl_other_context, NULL);
|
2013-12-17 17:46:07 +00:00
|
|
|
|
|
|
|
gst_caps_replace (&plugin->sinkpad_caps, NULL);
|
|
|
|
gst_video_info_init (&plugin->sinkpad_info);
|
2018-01-17 16:26:24 +00:00
|
|
|
|
|
|
|
g_clear_object (&plugin->sinkpad_buffer_pool);
|
2014-08-21 12:10:36 +00:00
|
|
|
g_clear_object (&plugin->srcpad_buffer_pool);
|
2013-12-17 17:46:07 +00:00
|
|
|
|
2016-05-25 10:31:15 +00:00
|
|
|
g_clear_object (&plugin->sinkpad_allocator);
|
|
|
|
g_clear_object (&plugin->srcpad_allocator);
|
2018-02-15 18:28:33 +00:00
|
|
|
g_clear_object (&plugin->other_srcpad_allocator);
|
2016-05-25 10:31:15 +00:00
|
|
|
|
2013-12-17 17:46:07 +00:00
|
|
|
gst_caps_replace (&plugin->srcpad_caps, NULL);
|
|
|
|
gst_video_info_init (&plugin->srcpad_info);
|
2015-07-23 11:11:40 +00:00
|
|
|
gst_caps_replace (&plugin->allowed_raw_caps, NULL);
|
2013-12-13 09:24:26 +00:00
|
|
|
}
|
2013-12-13 10:52:47 +00:00
|
|
|
|
2014-12-03 14:45:52 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_has_display_type:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @display_type_req: the desired #GstVaapiDisplayType
|
|
|
|
*
|
|
|
|
* Checks whether the @plugin elements already has a #GstVaapiDisplay
|
|
|
|
* instance compatible with type @display_type_req.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if @plugin has a compatible display, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_has_display_type (GstVaapiPluginBase * plugin,
|
|
|
|
GstVaapiDisplayType display_type_req)
|
|
|
|
{
|
|
|
|
GstVaapiDisplayType display_type;
|
|
|
|
|
|
|
|
if (!plugin->display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
display_type = plugin->display_type;
|
|
|
|
if (gst_vaapi_display_type_is_compatible (display_type, display_type_req))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
display_type = gst_vaapi_display_get_class_type (plugin->display);
|
|
|
|
if (gst_vaapi_display_type_is_compatible (display_type, display_type_req))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-12-13 10:52:47 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_display_type:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @display_type: the new request #GstVaapiDisplayType
|
|
|
|
*
|
|
|
|
* Requests a new display type. The change is effective at the next
|
|
|
|
* call to gst_vaapi_plugin_base_ensure_display().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
|
|
|
|
GstVaapiDisplayType display_type)
|
|
|
|
{
|
|
|
|
plugin->display_type_req = display_type;
|
|
|
|
}
|
|
|
|
|
2014-07-25 09:13:29 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_display_name:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @display_name: the new display name to match
|
|
|
|
*
|
|
|
|
* Sets the name of the display to look for. The change is effective
|
|
|
|
* at the next call to gst_vaapi_plugin_base_ensure_display().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_set_display_name (GstVaapiPluginBase * plugin,
|
|
|
|
const gchar * display_name)
|
|
|
|
{
|
|
|
|
g_free (plugin->display_name);
|
|
|
|
plugin->display_name = g_strdup (display_name);
|
|
|
|
}
|
|
|
|
|
2013-12-13 10:52:47 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_ensure_display:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
*
|
|
|
|
* Ensures the display stored in @plugin complies with the requested
|
|
|
|
* display type constraints.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the display was created to match the requested
|
|
|
|
* type, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
2014-12-03 14:45:52 +00:00
|
|
|
if (gst_vaapi_plugin_base_has_display_type (plugin, plugin->display_type_req))
|
2013-12-13 10:52:47 +00:00
|
|
|
return TRUE;
|
|
|
|
gst_vaapi_display_replace (&plugin->display, NULL);
|
|
|
|
|
2015-05-08 13:54:09 +00:00
|
|
|
if (!gst_vaapi_ensure_display (GST_ELEMENT (plugin),
|
|
|
|
plugin->display_type_req))
|
2013-12-13 10:52:47 +00:00
|
|
|
return FALSE;
|
|
|
|
plugin->display_type = gst_vaapi_display_get_display_type (plugin->display);
|
|
|
|
|
|
|
|
GST_VAAPI_PLUGIN_BASE_GET_CLASS (plugin)->display_changed (plugin);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-17 17:46:07 +00:00
|
|
|
|
2016-05-23 20:49:11 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vaapi_buffer_pool_caps_is_equal (GstBufferPool * pool, GstCaps * newcaps)
|
|
|
|
{
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
caps = NULL;
|
|
|
|
ret = FALSE;
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
if (gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
|
|
|
|
ret = gst_caps_is_equal (newcaps, caps);
|
|
|
|
gst_structure_free (config);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-19 18:02:54 +00:00
|
|
|
static inline gboolean
|
|
|
|
reset_allocator (GstAllocator * allocator, GstVideoInfo * vinfo)
|
|
|
|
{
|
|
|
|
const GstVideoInfo *orig_vi;
|
|
|
|
|
|
|
|
if (!allocator)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
orig_vi = gst_allocator_get_vaapi_video_info (allocator, NULL);
|
|
|
|
if (!gst_video_info_changed (orig_vi, vinfo))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-25 10:31:15 +00:00
|
|
|
static gboolean
|
2016-10-24 17:25:27 +00:00
|
|
|
ensure_sinkpad_allocator (GstVaapiPluginBase * plugin, GstCaps * caps,
|
|
|
|
guint * size)
|
2016-05-25 10:31:15 +00:00
|
|
|
{
|
2016-10-24 17:25:27 +00:00
|
|
|
GstVideoInfo vinfo;
|
2017-06-23 12:38:10 +00:00
|
|
|
const GstVideoInfo *image_info;
|
2016-10-20 17:37:01 +00:00
|
|
|
GstVaapiImageUsageFlags usage_flag =
|
|
|
|
GST_VAAPI_IMAGE_USAGE_FLAG_NATIVE_FORMATS;
|
2016-10-24 17:25:27 +00:00
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&vinfo, caps))
|
|
|
|
goto error_invalid_caps;
|
|
|
|
|
|
|
|
if (!reset_allocator (plugin->sinkpad_allocator, &vinfo))
|
2017-06-23 12:38:10 +00:00
|
|
|
goto bail;
|
2016-05-25 10:31:15 +00:00
|
|
|
|
2016-10-20 17:37:01 +00:00
|
|
|
/* enable direct upload if upstream requests raw video */
|
|
|
|
if (gst_caps_is_video_raw (caps)) {
|
|
|
|
usage_flag = GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_UPLOAD;
|
|
|
|
GST_INFO_OBJECT (plugin, "enabling direct upload in sink allocator");
|
|
|
|
}
|
|
|
|
plugin->sinkpad_allocator =
|
|
|
|
gst_vaapi_video_allocator_new (plugin->display, &vinfo, 0, usage_flag);
|
|
|
|
|
|
|
|
bail:
|
2016-10-24 17:25:27 +00:00
|
|
|
if (!plugin->sinkpad_allocator)
|
|
|
|
goto error_create_allocator;
|
2017-06-23 12:38:10 +00:00
|
|
|
|
|
|
|
image_info =
|
|
|
|
gst_allocator_get_vaapi_video_info (plugin->sinkpad_allocator, NULL);
|
|
|
|
g_assert (image_info); /* allocator ought set its image info */
|
|
|
|
|
|
|
|
/* update the size with the one generated by the allocator */
|
|
|
|
*size = GST_VIDEO_INFO_SIZE (image_info);
|
|
|
|
|
2016-10-24 17:25:27 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_invalid_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "invalid caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
error_create_allocator:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "failed to create sink pad's allocator");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-25 10:31:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 14:47:41 +00:00
|
|
|
static inline guint
|
2017-02-09 11:49:44 +00:00
|
|
|
get_dmabuf_surface_allocation_flags (void)
|
2016-10-19 14:47:41 +00:00
|
|
|
{
|
|
|
|
/* @FIXME: fetch the real devices ids */
|
|
|
|
/* Pair vendor/device identifies an unique physical device. */
|
|
|
|
guint va_vendor_id = 0x00;
|
|
|
|
guint va_device_id = 0x00;
|
|
|
|
guint gl_vendor_id = 0x00;
|
|
|
|
guint gl_device_id = 0x00;
|
|
|
|
|
|
|
|
/* Requires linear memory only if fd export is done on a different
|
|
|
|
* device than the device where the fd is imported. */
|
|
|
|
gboolean same_physical_device = va_vendor_id == gl_vendor_id
|
|
|
|
&& va_device_id == gl_device_id;
|
|
|
|
|
|
|
|
if (same_physical_device)
|
|
|
|
return 0;
|
|
|
|
return GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE;
|
|
|
|
}
|
|
|
|
|
2017-06-01 17:13:52 +00:00
|
|
|
static inline GstAllocator *
|
|
|
|
create_dmabuf_srcpad_allocator (GstVaapiPluginBase * plugin,
|
|
|
|
GstVideoInfo * vinfo, gboolean check_for_map)
|
|
|
|
{
|
|
|
|
GstAllocator *allocator;
|
|
|
|
|
|
|
|
if (!GST_IS_VIDEO_DECODER (plugin) && !GST_IS_BASE_TRANSFORM (plugin))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
allocator = gst_vaapi_dmabuf_allocator_new (plugin->display, vinfo,
|
|
|
|
get_dmabuf_surface_allocation_flags (), GST_PAD_SRC);
|
|
|
|
if (!allocator || !check_for_map)
|
|
|
|
return allocator;
|
|
|
|
|
|
|
|
/* the dmabuf allocator *must* be capable to map a buffer with raw
|
|
|
|
* caps and the there's no evidence of downstream dmabuf
|
|
|
|
* importation */
|
|
|
|
if (!gst_vaapi_dmabuf_can_map (plugin->display, allocator)) {
|
|
|
|
GST_INFO_OBJECT (plugin, "dmabuf allocator generates unmappable buffers");
|
|
|
|
gst_object_replace ((GstObject **) & allocator, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocator;
|
|
|
|
}
|
|
|
|
|
2016-05-25 10:31:15 +00:00
|
|
|
static gboolean
|
2016-10-21 09:48:54 +00:00
|
|
|
ensure_srcpad_allocator (GstVaapiPluginBase * plugin, GstVideoInfo * vinfo,
|
|
|
|
GstCaps * caps)
|
2016-05-25 10:31:15 +00:00
|
|
|
{
|
2016-11-03 16:30:46 +00:00
|
|
|
gboolean different_caps;
|
2017-06-23 12:38:10 +00:00
|
|
|
const GstVideoInfo *image_info;
|
2016-10-21 09:48:54 +00:00
|
|
|
|
2017-06-09 11:05:36 +00:00
|
|
|
if (!reset_allocator (plugin->srcpad_allocator, vinfo))
|
2017-06-23 12:38:10 +00:00
|
|
|
goto valid_allocator;
|
2016-05-25 10:31:15 +00:00
|
|
|
|
2016-12-16 13:12:30 +00:00
|
|
|
plugin->srcpad_allocator = NULL;
|
2016-10-21 09:48:54 +00:00
|
|
|
if (caps && gst_caps_is_video_raw (caps)) {
|
2017-06-01 17:13:52 +00:00
|
|
|
GstAllocator *allocator = create_dmabuf_srcpad_allocator (plugin, vinfo,
|
|
|
|
!plugin->srcpad_can_dmabuf);
|
|
|
|
plugin->srcpad_allocator = allocator;
|
2017-06-23 10:12:12 +00:00
|
|
|
} else if (caps && gst_vaapi_caps_feature_contains (caps,
|
|
|
|
GST_VAAPI_CAPS_FEATURE_DMABUF)) {
|
|
|
|
plugin->srcpad_allocator =
|
|
|
|
create_dmabuf_srcpad_allocator (plugin, vinfo, FALSE);
|
|
|
|
if (!plugin->srcpad_allocator)
|
|
|
|
goto error_create_allocator;
|
2016-12-16 13:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!plugin->srcpad_allocator) {
|
2017-10-31 12:10:50 +00:00
|
|
|
GstVaapiImageUsageFlags usage_flag =
|
|
|
|
GST_VAAPI_IMAGE_USAGE_FLAG_NATIVE_FORMATS;
|
|
|
|
|
|
|
|
if (plugin->enable_direct_rendering) {
|
|
|
|
usage_flag = GST_VAAPI_IMAGE_USAGE_FLAG_DIRECT_RENDER;
|
|
|
|
GST_INFO_OBJECT (plugin, "enabling direct rendering in source allocator");
|
|
|
|
}
|
|
|
|
|
2016-12-16 13:12:30 +00:00
|
|
|
plugin->srcpad_allocator =
|
|
|
|
gst_vaapi_video_allocator_new (plugin->display, vinfo, 0, usage_flag);
|
2016-10-21 09:48:54 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 18:09:59 +00:00
|
|
|
if (!plugin->srcpad_allocator)
|
|
|
|
goto error_create_allocator;
|
2016-11-03 16:30:46 +00:00
|
|
|
|
2017-06-23 12:38:10 +00:00
|
|
|
valid_allocator:
|
|
|
|
image_info =
|
|
|
|
gst_allocator_get_vaapi_video_info (plugin->srcpad_allocator, NULL);
|
|
|
|
g_assert (image_info); /* both allocators ought set its image
|
|
|
|
* info */
|
|
|
|
|
|
|
|
/* update the size with the one generated by the allocator */
|
|
|
|
GST_VIDEO_INFO_SIZE (vinfo) = GST_VIDEO_INFO_SIZE (image_info);
|
|
|
|
|
2017-06-09 11:05:36 +00:00
|
|
|
/* the received caps are the "allocation caps" which may be
|
|
|
|
* different from the "negotiation caps". In this case, we should
|
|
|
|
* indicate the allocator to store the negotiation caps since they
|
|
|
|
* are the one should be used for frame mapping with GstVideoMeta */
|
|
|
|
different_caps = GST_IS_VIDEO_DECODER (plugin) && plugin->srcpad_caps &&
|
|
|
|
!gst_caps_is_strictly_equal (plugin->srcpad_caps, caps);
|
|
|
|
|
2016-11-21 11:51:25 +00:00
|
|
|
if (different_caps) {
|
2017-06-09 11:05:36 +00:00
|
|
|
guint i;
|
|
|
|
GstVideoInfo vi = plugin->srcpad_info;
|
|
|
|
|
|
|
|
/* update the planes and the size with the allocator image/surface
|
|
|
|
* info, but not the resolution */
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (image_info); i++) {
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (&vi, i) =
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (image_info, i);
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (&vi, i) =
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (image_info, i);
|
2016-11-21 11:51:25 +00:00
|
|
|
}
|
2017-06-09 11:05:36 +00:00
|
|
|
GST_VIDEO_INFO_SIZE (&vi) = GST_VIDEO_INFO_SIZE (image_info);
|
|
|
|
gst_allocator_set_vaapi_negotiated_video_info (plugin->srcpad_allocator,
|
|
|
|
&vi);
|
2016-11-21 11:51:25 +00:00
|
|
|
}
|
2016-11-03 16:30:46 +00:00
|
|
|
|
2016-10-24 18:09:59 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_create_allocator:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "failed to create src pad's allocator");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-25 10:31:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 13:57:06 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_create_pool:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @caps: the initial #GstCaps for the resulting buffer pool
|
|
|
|
* @size: the size of each buffer, not including prefix and padding
|
2016-05-25 08:58:01 +00:00
|
|
|
* @options: a set of #GstVaapiVideoBufferPoolOption encoded as bit-wise
|
2016-05-10 13:57:06 +00:00
|
|
|
* @allocator: (allow-none): the #GstAllocator to use or %NULL
|
|
|
|
*
|
|
|
|
* Create an instance of #GstVaapiVideoBufferPool
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new allocated #GstBufferPool
|
|
|
|
**/
|
|
|
|
static GstBufferPool *
|
|
|
|
gst_vaapi_plugin_base_create_pool (GstVaapiPluginBase * plugin, GstCaps * caps,
|
|
|
|
gsize size, guint min_buffers, guint max_buffers, guint options,
|
|
|
|
GstAllocator * allocator)
|
|
|
|
{
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
|
|
|
|
if (!(pool = gst_vaapi_video_buffer_pool_new (plugin->display)))
|
|
|
|
goto error_create_pool;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
|
|
|
|
max_buffers);
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META);
|
2016-05-25 08:58:01 +00:00
|
|
|
if (options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META) {
|
2016-05-10 13:57:06 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
}
|
2016-05-25 08:58:01 +00:00
|
|
|
if (options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT) {
|
2016-05-10 13:57:06 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
|
|
|
}
|
|
|
|
#if (USE_GLX || USE_EGL)
|
2016-05-25 08:58:01 +00:00
|
|
|
if (options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD) {
|
2016-05-10 13:57:06 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (allocator)
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, NULL);
|
2016-06-13 17:48:41 +00:00
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_validate_params (config, caps, size,
|
|
|
|
min_buffers, max_buffers)) {
|
|
|
|
gst_structure_free (config);
|
|
|
|
goto error_pool_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto error_pool_config;
|
|
|
|
}
|
2016-05-10 13:57:06 +00:00
|
|
|
return pool;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_create_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "failed to create buffer pool");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
error_pool_config:
|
|
|
|
{
|
|
|
|
gst_object_unref (pool);
|
|
|
|
GST_ELEMENT_ERROR (plugin, RESOURCE, SETTINGS,
|
|
|
|
("Failed to configure the buffer pool"),
|
|
|
|
("Configuration is most likely invalid, please report this issue."));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
/**
|
|
|
|
* ensure_sinkpad_buffer_pool:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @caps: the initial #GstCaps for the resulting buffer pool
|
|
|
|
*
|
|
|
|
* Makes sure the sink pad video buffer pool is created with the
|
|
|
|
* appropriate @caps.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
ensure_sinkpad_buffer_pool (GstVaapiPluginBase * plugin, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstBufferPool *pool;
|
2016-09-08 07:16:09 +00:00
|
|
|
guint size;
|
2013-12-17 17:52:23 +00:00
|
|
|
|
2016-05-24 14:22:24 +00:00
|
|
|
/* video decoders don't use a buffer pool in the sink pad */
|
|
|
|
if (GST_IS_VIDEO_DECODER (plugin))
|
|
|
|
return TRUE;
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
if (!gst_vaapi_plugin_base_ensure_display (plugin))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (plugin->sinkpad_buffer_pool) {
|
2016-05-23 20:49:11 +00:00
|
|
|
if (gst_vaapi_buffer_pool_caps_is_equal (plugin->sinkpad_buffer_pool, caps))
|
2013-12-17 17:52:23 +00:00
|
|
|
return TRUE;
|
2016-05-24 14:29:33 +00:00
|
|
|
gst_buffer_pool_set_active (plugin->sinkpad_buffer_pool, FALSE);
|
2013-12-17 17:52:23 +00:00
|
|
|
g_clear_object (&plugin->sinkpad_buffer_pool);
|
2016-07-19 17:27:27 +00:00
|
|
|
g_clear_object (&plugin->sinkpad_allocator);
|
2013-12-17 17:52:23 +00:00
|
|
|
plugin->sinkpad_buffer_size = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:25:27 +00:00
|
|
|
if (!ensure_sinkpad_allocator (plugin, caps, &size))
|
2016-11-21 11:29:26 +00:00
|
|
|
return FALSE;
|
2016-09-08 07:16:09 +00:00
|
|
|
|
2017-01-10 06:15:31 +00:00
|
|
|
pool =
|
|
|
|
gst_vaapi_plugin_base_create_pool (plugin, caps, size,
|
|
|
|
BUFFER_POOL_SINK_MIN_BUFFERS, 0,
|
2016-05-25 10:31:15 +00:00
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META, plugin->sinkpad_allocator);
|
2016-05-10 13:57:06 +00:00
|
|
|
if (!pool)
|
2016-11-21 11:29:26 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
plugin->sinkpad_buffer_pool = pool;
|
2016-09-08 07:16:09 +00:00
|
|
|
plugin->sinkpad_buffer_size = size;
|
2013-12-17 17:52:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-17 17:46:07 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_caps:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @incaps: the sink pad (input) caps
|
|
|
|
* @outcaps: the src pad (output) caps
|
|
|
|
*
|
|
|
|
* Notifies the base plugin object of the new input and output caps,
|
|
|
|
* obtained from the subclass.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the update of caps was successful, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_set_caps (GstVaapiPluginBase * plugin, GstCaps * incaps,
|
|
|
|
GstCaps * outcaps)
|
|
|
|
{
|
|
|
|
if (incaps && incaps != plugin->sinkpad_caps) {
|
|
|
|
if (!gst_video_info_from_caps (&plugin->sinkpad_info, incaps))
|
|
|
|
return FALSE;
|
2016-11-21 17:27:00 +00:00
|
|
|
gst_caps_replace (&plugin->sinkpad_caps, incaps);
|
2014-08-20 09:43:08 +00:00
|
|
|
plugin->sinkpad_caps_is_raw = !gst_caps_has_vaapi_surface (incaps);
|
2013-12-17 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (outcaps && outcaps != plugin->srcpad_caps) {
|
2016-11-21 17:27:00 +00:00
|
|
|
if (!gst_video_info_from_caps (&plugin->srcpad_info, outcaps))
|
|
|
|
return FALSE;
|
2016-11-21 17:28:18 +00:00
|
|
|
if (plugin->srcpad_buffer_pool
|
|
|
|
&& !gst_vaapi_buffer_pool_caps_is_equal (plugin->srcpad_buffer_pool,
|
|
|
|
outcaps)) {
|
|
|
|
gst_buffer_pool_set_active (plugin->srcpad_buffer_pool, FALSE);
|
|
|
|
g_clear_object (&plugin->srcpad_buffer_pool);
|
|
|
|
g_clear_object (&plugin->srcpad_allocator);
|
|
|
|
plugin_reset_texture_map (plugin);
|
|
|
|
}
|
2013-12-17 17:46:07 +00:00
|
|
|
gst_caps_replace (&plugin->srcpad_caps, outcaps);
|
|
|
|
}
|
2013-12-17 17:52:23 +00:00
|
|
|
|
|
|
|
if (!ensure_sinkpad_buffer_pool (plugin, plugin->sinkpad_caps))
|
|
|
|
return FALSE;
|
2013-12-17 17:46:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-17 17:52:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_propose_allocation:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @query: the allocation query to configure
|
|
|
|
*
|
|
|
|
* Proposes allocation parameters to the upstream elements.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_propose_allocation (GstVaapiPluginBase * plugin,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
2017-09-06 18:03:25 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
2013-12-17 17:52:23 +00:00
|
|
|
gboolean need_pool;
|
2018-02-07 08:13:26 +00:00
|
|
|
guint size = 0, n_allocators;
|
2013-12-17 17:52:23 +00:00
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
2016-05-23 20:21:15 +00:00
|
|
|
if (!caps)
|
|
|
|
goto error_no_caps;
|
2013-12-17 17:52:23 +00:00
|
|
|
|
2018-01-17 16:30:50 +00:00
|
|
|
if (!ensure_sinkpad_allocator (plugin, caps, &size))
|
2017-09-06 18:03:25 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
if (need_pool) {
|
2018-01-17 16:30:50 +00:00
|
|
|
pool = gst_vaapi_plugin_base_create_pool (plugin, caps, size,
|
|
|
|
BUFFER_POOL_SINK_MIN_BUFFERS, 0,
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META,
|
|
|
|
plugin->sinkpad_allocator);
|
|
|
|
if (!pool)
|
|
|
|
return FALSE;
|
2018-02-07 08:13:26 +00:00
|
|
|
}
|
2018-01-17 16:30:50 +00:00
|
|
|
|
2018-02-07 08:13:26 +00:00
|
|
|
/* Set sinkpad allocator as the last allocation param.
|
|
|
|
*
|
|
|
|
* If there's none, set system's allocator first and VAAPI allocator
|
|
|
|
* second
|
|
|
|
*/
|
|
|
|
n_allocators = gst_query_get_n_allocation_params (query);
|
|
|
|
if (n_allocators == 0) {
|
|
|
|
GstAllocator *allocator;
|
|
|
|
|
|
|
|
allocator = gst_allocator_find (GST_ALLOCATOR_SYSMEM);
|
|
|
|
gst_query_add_allocation_param (query, allocator, NULL);
|
|
|
|
gst_object_unref (allocator);
|
2013-12-17 17:52:23 +00:00
|
|
|
}
|
2018-02-07 08:13:26 +00:00
|
|
|
gst_query_add_allocation_param (query, plugin->sinkpad_allocator, NULL);
|
2013-12-17 17:52:23 +00:00
|
|
|
|
2018-01-17 16:30:50 +00:00
|
|
|
gst_query_add_allocation_pool (query, pool, size,
|
2017-09-06 18:03:25 +00:00
|
|
|
BUFFER_POOL_SINK_MIN_BUFFERS, 0);
|
2018-01-17 16:30:50 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2017-09-06 18:03:25 +00:00
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VAAPI_VIDEO_META_API_TYPE, NULL);
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_no_caps:
|
|
|
|
{
|
2015-06-22 15:38:41 +00:00
|
|
|
GST_INFO_OBJECT (plugin, "no caps specified");
|
2013-12-17 17:52:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 12:10:36 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_decide_allocation:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @query: the allocation query to parse
|
|
|
|
* @feature: the desired #GstVaapiCapsFeature, or zero to find the
|
|
|
|
* preferred one
|
|
|
|
*
|
|
|
|
* Decides allocation parameters for the downstream elements.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
|
2016-03-10 15:43:16 +00:00
|
|
|
GstQuery * query)
|
2014-08-21 12:10:36 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstVideoInfo vi;
|
2018-02-07 08:13:26 +00:00
|
|
|
guint i, size, min, max, pool_options, num_allocators;
|
|
|
|
gint index_allocator;
|
|
|
|
gboolean update_pool = FALSE;
|
2015-04-03 14:09:08 +00:00
|
|
|
#if (USE_GLX || USE_EGL)
|
2014-12-03 13:14:30 +00:00
|
|
|
guint idx;
|
2014-08-21 12:10:36 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-24 13:09:43 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
2016-05-23 20:21:15 +00:00
|
|
|
if (!caps)
|
|
|
|
goto error_no_caps;
|
2016-03-24 13:09:43 +00:00
|
|
|
|
2016-05-10 13:57:06 +00:00
|
|
|
pool_options = 0;
|
|
|
|
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
|
2016-05-25 08:58:01 +00:00
|
|
|
pool_options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META;
|
2014-08-21 12:10:36 +00:00
|
|
|
|
2015-04-03 14:09:08 +00:00
|
|
|
#if (USE_GLX || USE_EGL)
|
2016-05-10 13:57:06 +00:00
|
|
|
if (gst_query_find_allocation_meta (query,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx) &&
|
2016-03-10 15:43:16 +00:00
|
|
|
gst_vaapi_caps_feature_contains (caps,
|
2016-05-10 13:57:06 +00:00
|
|
|
GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META))
|
2016-05-25 08:58:01 +00:00
|
|
|
pool_options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD;
|
2014-12-03 13:14:30 +00:00
|
|
|
|
|
|
|
#if USE_GST_GL_HELPERS
|
2016-06-02 17:57:08 +00:00
|
|
|
if (!plugin->gl_context &&
|
|
|
|
(pool_options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD)) {
|
2014-12-03 13:14:30 +00:00
|
|
|
const GstStructure *params;
|
|
|
|
GstObject *gl_context;
|
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_meta (query, idx, ¶ms);
|
|
|
|
if (params) {
|
2016-11-03 08:31:17 +00:00
|
|
|
if (gst_structure_get (params, "gst.gl.GstGLContext", GST_TYPE_GL_CONTEXT,
|
2014-12-03 13:14:30 +00:00
|
|
|
&gl_context, NULL) && gl_context) {
|
|
|
|
gst_vaapi_plugin_base_set_gl_context (plugin, gl_context);
|
2017-10-04 09:54:31 +00:00
|
|
|
gst_vaapi_plugin_base_set_srcpad_can_dmabuf (plugin, gl_context);
|
2014-12-03 13:14:30 +00:00
|
|
|
gst_object_unref (gl_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-21 12:10:36 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-03 14:45:52 +00:00
|
|
|
/* Make sure the display we pass down to the buffer pool is actually
|
|
|
|
the expected one, especially when the downstream element requires
|
|
|
|
a GLX or EGL display */
|
|
|
|
if (!gst_vaapi_plugin_base_ensure_display (plugin))
|
|
|
|
goto error_ensure_display;
|
|
|
|
|
2016-05-23 15:55:35 +00:00
|
|
|
if (!gst_video_info_from_caps (&vi, caps))
|
|
|
|
goto error_invalid_caps;
|
2016-05-23 13:38:07 +00:00
|
|
|
gst_video_info_force_nv12_if_encoded (&vi);
|
2014-08-21 12:10:36 +00:00
|
|
|
|
2018-02-07 08:13:26 +00:00
|
|
|
index_allocator = -1;
|
|
|
|
num_allocators = gst_query_get_n_allocation_params (query);
|
|
|
|
for (i = 0; i < num_allocators; i++) {
|
|
|
|
GstAllocator *allocator = NULL;
|
2018-02-15 18:28:33 +00:00
|
|
|
GstAllocationParams params;
|
2018-02-07 08:13:26 +00:00
|
|
|
|
2018-02-15 18:28:33 +00:00
|
|
|
gst_query_parse_nth_allocation_param (query, i, &allocator, ¶ms);
|
2018-02-07 08:13:26 +00:00
|
|
|
if (!allocator)
|
|
|
|
continue;
|
2018-02-15 18:28:33 +00:00
|
|
|
|
|
|
|
/* Let's keep the the first allocator if it is not VA-API. It
|
|
|
|
* might be used if it is required to copy the output frame to a
|
|
|
|
* new buffer */
|
|
|
|
if (i == 0
|
|
|
|
&& g_strcmp0 (allocator->mem_type, GST_VAAPI_VIDEO_MEMORY_NAME) != 0) {
|
|
|
|
if (plugin->other_srcpad_allocator)
|
|
|
|
gst_object_unref (plugin->other_srcpad_allocator);
|
|
|
|
plugin->other_srcpad_allocator = allocator;
|
|
|
|
plugin->other_allocator_params = params;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-07 08:13:26 +00:00
|
|
|
if (g_strcmp0 (allocator->mem_type, GST_VAAPI_VIDEO_MEMORY_NAME) == 0) {
|
|
|
|
GST_DEBUG_OBJECT (plugin, "found vaapi allocator in query %"
|
|
|
|
GST_PTR_FORMAT, allocator);
|
|
|
|
index_allocator = i;
|
|
|
|
if (plugin->srcpad_allocator)
|
|
|
|
gst_object_unref (plugin->srcpad_allocator);
|
|
|
|
plugin->srcpad_allocator = allocator;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
}
|
2016-11-21 10:25:21 +00:00
|
|
|
|
2014-08-21 12:10:36 +00:00
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
2015-06-17 06:53:29 +00:00
|
|
|
update_pool = TRUE;
|
2016-05-20 19:01:02 +00:00
|
|
|
size = MAX (size, GST_VIDEO_INFO_SIZE (&vi));
|
2015-04-17 19:10:35 +00:00
|
|
|
if (pool) {
|
|
|
|
/* Check whether downstream element proposed a bufferpool but did
|
|
|
|
not provide a correct propose_allocation() implementation */
|
2016-05-10 13:57:06 +00:00
|
|
|
if (gst_buffer_pool_has_option (pool,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT))
|
2016-05-25 08:58:01 +00:00
|
|
|
pool_options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT;
|
2016-05-13 11:14:23 +00:00
|
|
|
|
|
|
|
/* GstVaapiVideoMeta is mandatory, and this implies VA surface memory */
|
|
|
|
if (!gst_buffer_pool_has_option (pool,
|
|
|
|
GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META)) {
|
|
|
|
GST_INFO_OBJECT (plugin, "ignoring non-VAAPI pool: %" GST_PTR_FORMAT,
|
|
|
|
pool);
|
|
|
|
g_clear_object (&pool);
|
|
|
|
}
|
2015-04-17 19:10:35 +00:00
|
|
|
}
|
2014-08-21 12:10:36 +00:00
|
|
|
} else {
|
|
|
|
pool = NULL;
|
2016-05-20 19:01:02 +00:00
|
|
|
size = GST_VIDEO_INFO_SIZE (&vi);
|
2014-08-21 12:10:36 +00:00
|
|
|
min = max = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 11:14:23 +00:00
|
|
|
if (!pool) {
|
2016-10-21 09:48:54 +00:00
|
|
|
if (!ensure_srcpad_allocator (plugin, &vi, caps))
|
2016-10-24 18:09:59 +00:00
|
|
|
goto error;
|
2017-06-23 12:38:10 +00:00
|
|
|
size = GST_VIDEO_INFO_SIZE (&vi); /* size might be updated by
|
|
|
|
* allocator */
|
2016-05-10 13:57:06 +00:00
|
|
|
pool = gst_vaapi_plugin_base_create_pool (plugin, caps, size, min, max,
|
2016-05-25 10:31:15 +00:00
|
|
|
pool_options, plugin->srcpad_allocator);
|
2016-05-10 13:57:06 +00:00
|
|
|
if (!pool)
|
2016-10-24 18:09:59 +00:00
|
|
|
goto error;
|
2014-08-21 12:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update_pool)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
2018-02-07 08:13:26 +00:00
|
|
|
/* allocator might be updated by ensure_srcpad_allocator() */
|
|
|
|
if (plugin->srcpad_allocator) {
|
|
|
|
if (index_allocator > 0) {
|
|
|
|
gst_query_set_nth_allocation_param (query, index_allocator,
|
|
|
|
plugin->srcpad_allocator, NULL);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (plugin, "adding allocator in query %" GST_PTR_FORMAT,
|
|
|
|
plugin->srcpad_allocator);
|
|
|
|
gst_query_add_allocation_param (query, plugin->srcpad_allocator, NULL);
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 10:25:21 +00:00
|
|
|
|
2014-08-21 12:10:36 +00:00
|
|
|
g_clear_object (&plugin->srcpad_buffer_pool);
|
|
|
|
plugin->srcpad_buffer_pool = pool;
|
2018-02-15 18:29:51 +00:00
|
|
|
|
|
|
|
/* if downstream doesn't support GstVideoMeta, and the negotiated
|
|
|
|
* caps are raw video, and the used allocator is the VA-API one, we
|
|
|
|
* should copy the VA-API frame into a dumb buffer */
|
|
|
|
plugin->copy_output_frame = gst_vaapi_video_buffer_pool_copy_buffer (pool);
|
|
|
|
|
2014-08-21 12:10:36 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_no_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-23 15:55:35 +00:00
|
|
|
error_invalid_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "invalid caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-03 14:45:52 +00:00
|
|
|
error_ensure_display:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (plugin, "failed to ensure display of type %d",
|
|
|
|
plugin->display_type_req);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-10-24 18:09:59 +00:00
|
|
|
error:
|
2015-04-29 10:27:43 +00:00
|
|
|
{
|
2016-05-10 13:57:06 +00:00
|
|
|
/* error message already sent */
|
2015-04-29 10:27:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-08-21 12:10:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_get_input_buffer:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
2016-05-18 14:05:03 +00:00
|
|
|
* @inbuf: the sink pad (input) buffer
|
2013-12-17 17:52:23 +00:00
|
|
|
* @outbuf_ptr: the pointer to location to the VA surface backed buffer
|
|
|
|
*
|
|
|
|
* Acquires the sink pad (input) buffer as a VA surface backed
|
|
|
|
* buffer. This is mostly useful for raw YUV buffers, as source
|
|
|
|
* buffers that are already backed as a VA surface are passed
|
|
|
|
* verbatim.
|
|
|
|
*
|
|
|
|
* Returns: #GST_FLOW_OK if the buffer could be acquired
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin,
|
|
|
|
GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
|
|
|
|
{
|
|
|
|
GstVaapiVideoMeta *meta;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
GstVideoFrame src_frame, out_frame;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
g_return_val_if_fail (inbuf != NULL, GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (outbuf_ptr != NULL, GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
meta = gst_buffer_get_vaapi_video_meta (inbuf);
|
|
|
|
if (meta) {
|
|
|
|
*outbuf_ptr = gst_buffer_ref (inbuf);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-20 09:43:08 +00:00
|
|
|
if (!plugin->sinkpad_caps_is_raw)
|
2013-12-17 17:52:23 +00:00
|
|
|
goto error_invalid_buffer;
|
|
|
|
|
|
|
|
if (!plugin->sinkpad_buffer_pool)
|
|
|
|
goto error_no_pool;
|
|
|
|
|
2017-01-18 16:20:21 +00:00
|
|
|
if (!gst_buffer_pool_is_active (plugin->sinkpad_buffer_pool) &&
|
|
|
|
!gst_buffer_pool_set_active (plugin->sinkpad_buffer_pool, TRUE))
|
2013-12-17 17:52:23 +00:00
|
|
|
goto error_active_pool;
|
|
|
|
|
|
|
|
outbuf = NULL;
|
|
|
|
if (gst_buffer_pool_acquire_buffer (plugin->sinkpad_buffer_pool,
|
|
|
|
&outbuf, NULL) != GST_FLOW_OK)
|
|
|
|
goto error_create_buffer;
|
|
|
|
|
2014-01-23 10:00:09 +00:00
|
|
|
if (is_dma_buffer (inbuf)) {
|
|
|
|
if (!plugin_bind_dma_to_vaapi_buffer (plugin, inbuf, outbuf))
|
|
|
|
goto error_bind_dma_buffer;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-12-17 17:52:23 +00:00
|
|
|
if (!gst_video_frame_map (&src_frame, &plugin->sinkpad_info, inbuf,
|
|
|
|
GST_MAP_READ))
|
|
|
|
goto error_map_src_buffer;
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&out_frame, &plugin->sinkpad_info, outbuf,
|
|
|
|
GST_MAP_WRITE))
|
|
|
|
goto error_map_dst_buffer;
|
|
|
|
|
|
|
|
success = gst_video_frame_copy (&out_frame, &src_frame);
|
|
|
|
gst_video_frame_unmap (&out_frame);
|
|
|
|
gst_video_frame_unmap (&src_frame);
|
|
|
|
if (!success)
|
|
|
|
goto error_copy_buffer;
|
|
|
|
|
2014-01-23 10:00:09 +00:00
|
|
|
done:
|
2018-02-23 15:25:51 +00:00
|
|
|
if (!gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_FLAGS |
|
|
|
|
GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_META, 0, -1))
|
|
|
|
return GST_FLOW_ERROR;
|
2013-12-17 17:52:23 +00:00
|
|
|
*outbuf_ptr = outbuf;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_no_pool:
|
|
|
|
{
|
2015-02-18 09:19:26 +00:00
|
|
|
GST_ELEMENT_ERROR (plugin, STREAM, FAILED,
|
2015-06-30 06:44:18 +00:00
|
|
|
("no buffer pool was negotiated"), ("no buffer pool was negotiated"));
|
2013-12-17 17:52:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
error_active_pool:
|
|
|
|
{
|
2015-02-18 09:19:26 +00:00
|
|
|
GST_ELEMENT_ERROR (plugin, STREAM, FAILED,
|
2015-06-30 06:44:18 +00:00
|
|
|
("failed to activate buffer pool"), ("failed to activate buffer pool"));
|
2013-12-17 17:52:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
error_map_dst_buffer:
|
|
|
|
{
|
|
|
|
gst_video_frame_unmap (&src_frame);
|
|
|
|
// fall-through
|
|
|
|
}
|
|
|
|
error_map_src_buffer:
|
|
|
|
{
|
|
|
|
GST_WARNING ("failed to map buffer");
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return GST_FLOW_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_invalid_buffer:
|
|
|
|
{
|
2015-02-18 09:19:26 +00:00
|
|
|
GST_ELEMENT_ERROR (plugin, STREAM, FAILED,
|
|
|
|
("failed to validate source buffer"),
|
|
|
|
("failed to validate source buffer"));
|
2013-12-17 17:52:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
error_create_buffer:
|
|
|
|
{
|
2015-02-18 09:19:26 +00:00
|
|
|
GST_ELEMENT_ERROR (plugin, STREAM, FAILED, ("Allocation failed"),
|
|
|
|
("failed to create buffer"));
|
2013-12-17 17:52:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2014-01-23 10:00:09 +00:00
|
|
|
error_bind_dma_buffer:
|
|
|
|
{
|
2015-02-18 09:19:26 +00:00
|
|
|
GST_ELEMENT_ERROR (plugin, STREAM, FAILED, ("Allocation failed"),
|
|
|
|
("failed to bind dma_buf to VA surface buffer"));
|
2014-01-23 10:00:09 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2013-12-17 17:52:23 +00:00
|
|
|
error_copy_buffer:
|
|
|
|
{
|
2016-05-23 15:47:36 +00:00
|
|
|
GST_WARNING_OBJECT (plugin, "failed to upload buffer to VA surface");
|
2013-12-17 17:52:23 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return GST_FLOW_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
2014-12-03 13:14:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_gl_context:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @object: the new GL context from downstream
|
|
|
|
*
|
|
|
|
* Registers the new GL context. The change is effective at the next
|
|
|
|
* call to gst_vaapi_plugin_base_ensure_display(), where the
|
|
|
|
* underlying display object could be re-allocated to fit the GL
|
|
|
|
* context needs
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
|
|
|
|
GstObject * object)
|
|
|
|
{
|
|
|
|
#if USE_GST_GL_HELPERS
|
2014-12-03 14:45:52 +00:00
|
|
|
GstGLContext *const gl_context = GST_GL_CONTEXT (object);
|
|
|
|
GstVaapiDisplayType display_type;
|
|
|
|
|
2016-06-02 17:57:08 +00:00
|
|
|
if (plugin->gl_context == object)
|
|
|
|
return;
|
|
|
|
|
2014-12-03 13:14:30 +00:00
|
|
|
gst_object_replace (&plugin->gl_context, object);
|
2014-12-03 14:45:52 +00:00
|
|
|
|
|
|
|
switch (gst_gl_context_get_gl_platform (gl_context)) {
|
|
|
|
#if USE_GLX
|
|
|
|
case GST_GL_PLATFORM_GLX:
|
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_GLX;
|
|
|
|
break;
|
2015-02-20 14:29:17 +00:00
|
|
|
#endif
|
|
|
|
case GST_GL_PLATFORM_EGL:
|
2016-06-02 20:13:51 +00:00
|
|
|
#if USE_EGL
|
2015-02-20 14:29:17 +00:00
|
|
|
display_type = GST_VAAPI_DISPLAY_TYPE_EGL;
|
|
|
|
break;
|
2014-12-03 14:45:52 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
display_type = plugin->display_type;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-02 17:57:08 +00:00
|
|
|
GST_INFO_OBJECT (plugin, "GL context: %" GST_PTR_FORMAT, plugin->gl_context);
|
2014-12-03 14:45:52 +00:00
|
|
|
gst_vaapi_plugin_base_set_display_type (plugin, display_type);
|
2014-12-03 13:14:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-07-23 11:11:40 +00:00
|
|
|
|
2017-01-26 11:02:56 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_create_gl_context:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
*
|
|
|
|
* It queries downstream and upstream for a #GstGLDisplay and a other
|
|
|
|
* #GstGLContext. If not found, a new #GstGLDisplay and #GstGLContext
|
|
|
|
* are created, if it is possible.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) a new created #GstGLContext or %NULL
|
|
|
|
**/
|
|
|
|
GstObject *
|
|
|
|
gst_vaapi_plugin_base_create_gl_context (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
#if USE_GST_GL_HELPERS
|
2017-10-10 17:13:35 +00:00
|
|
|
GstGLContext *gl_other_context = NULL, *gl_context = NULL;
|
|
|
|
GstGLDisplay *gl_display = NULL;
|
2017-01-26 11:02:56 +00:00
|
|
|
|
2018-04-26 16:15:47 +00:00
|
|
|
if (!plugin->gl_display)
|
|
|
|
return NULL;
|
2017-01-26 11:02:56 +00:00
|
|
|
|
2018-04-25 07:24:32 +00:00
|
|
|
gl_display = (GstGLDisplay *) plugin->gl_display;
|
2017-08-01 16:10:50 +00:00
|
|
|
if (gst_gl_display_get_handle_type (gl_display) == GST_GL_DISPLAY_TYPE_ANY)
|
|
|
|
goto no_valid_gl_display;
|
2018-04-25 07:24:32 +00:00
|
|
|
gl_other_context = (GstGLContext *) plugin->gl_other_context;
|
2017-01-26 11:02:56 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (plugin, "creating a new GstGL context");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (gl_display);
|
|
|
|
do {
|
|
|
|
if (gl_context)
|
|
|
|
gst_object_unref (gl_context);
|
|
|
|
gl_context = gst_gl_display_get_gl_context_for_thread (gl_display, NULL);
|
|
|
|
if (!gl_context) {
|
|
|
|
if (!gst_gl_display_create_context (gl_display, gl_other_context,
|
|
|
|
&gl_context, NULL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!gst_gl_display_add_context (gl_display, gl_context));
|
|
|
|
GST_OBJECT_UNLOCK (gl_display);
|
|
|
|
|
|
|
|
return GST_OBJECT_CAST (gl_context);
|
2017-08-01 16:10:50 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_valid_gl_display:
|
|
|
|
{
|
2018-04-25 07:24:32 +00:00
|
|
|
GST_INFO_OBJECT (plugin, "No valid GL display found");
|
|
|
|
gst_object_replace (&plugin->gl_display, NULL);
|
|
|
|
gst_object_replace (&plugin->gl_other_context, NULL);
|
2017-08-01 16:10:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-01-26 11:02:56 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:57:33 +00:00
|
|
|
static GArray *
|
2018-12-24 06:08:42 +00:00
|
|
|
extract_allowed_surface_formats (GstVaapiDisplay * display,
|
|
|
|
GArray * img_formats, GstVideoFormat specified_format,
|
|
|
|
GstPadDirection direction)
|
2015-07-23 11:11:40 +00:00
|
|
|
{
|
|
|
|
guint i;
|
2018-09-20 01:57:33 +00:00
|
|
|
GArray *out_formats;
|
2018-12-24 06:08:42 +00:00
|
|
|
GstVaapiSurface *surface = NULL;
|
|
|
|
|
|
|
|
g_assert (direction == GST_PAD_SRC || direction == GST_PAD_SINK);
|
2015-07-23 11:11:40 +00:00
|
|
|
|
|
|
|
out_formats =
|
2018-12-24 06:08:42 +00:00
|
|
|
g_array_sized_new (FALSE, FALSE, sizeof (GstVideoFormat),
|
|
|
|
img_formats->len);
|
2015-07-23 11:11:40 +00:00
|
|
|
if (!out_formats)
|
2018-09-20 01:57:33 +00:00
|
|
|
return NULL;
|
2015-07-23 11:11:40 +00:00
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
for (i = 0; i < img_formats->len; i++) {
|
|
|
|
const GstVideoFormat img_format =
|
|
|
|
g_array_index (img_formats, GstVideoFormat, i);
|
2015-07-23 11:11:40 +00:00
|
|
|
GstVaapiImage *image;
|
2018-11-14 05:11:56 +00:00
|
|
|
GstVideoInfo vi;
|
2018-12-24 06:08:42 +00:00
|
|
|
GstVideoFormat surface_format;
|
|
|
|
gboolean res;
|
2015-07-23 11:11:40 +00:00
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
if (img_format == GST_VIDEO_FORMAT_UNKNOWN)
|
2015-07-23 11:11:40 +00:00
|
|
|
continue;
|
2018-11-14 05:11:56 +00:00
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
surface_format =
|
|
|
|
(specified_format == GST_VIDEO_FORMAT_UNKNOWN) ?
|
|
|
|
img_format : specified_format;
|
|
|
|
if (!surface) {
|
|
|
|
gst_video_info_set_format (&vi, surface_format, 64, 64);
|
|
|
|
surface = gst_vaapi_surface_new_full (display, &vi, 0);
|
|
|
|
if (!surface)
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-14 05:11:56 +00:00
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
image = gst_vaapi_image_new (display, img_format, 64, 64);
|
2018-09-20 01:57:33 +00:00
|
|
|
if (!image) {
|
2018-12-24 06:08:42 +00:00
|
|
|
/* Just reuse the surface if the format is specified */
|
|
|
|
if (specified_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
gst_vaapi_object_replace (&surface, NULL);
|
|
|
|
|
2015-07-23 11:11:40 +00:00
|
|
|
continue;
|
2018-09-20 01:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
res = FALSE;
|
|
|
|
if (direction == GST_PAD_SRC) {
|
|
|
|
res = gst_vaapi_surface_get_image (surface, image);
|
|
|
|
} else {
|
|
|
|
res = gst_vaapi_surface_put_image (surface, image);
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
g_array_append_val (out_formats, img_format);
|
2018-09-20 01:57:33 +00:00
|
|
|
|
2015-07-23 11:11:40 +00:00
|
|
|
gst_vaapi_object_unref (image);
|
2018-12-24 06:08:42 +00:00
|
|
|
/* Just reuse the surface if the format is specified */
|
|
|
|
if (specified_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
gst_vaapi_object_replace (&surface, NULL);
|
2015-07-23 11:11:40 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 06:08:42 +00:00
|
|
|
if (surface)
|
|
|
|
gst_vaapi_object_unref (surface);
|
|
|
|
|
2018-09-20 01:57:33 +00:00
|
|
|
if (out_formats->len == 0) {
|
|
|
|
g_array_unref (out_formats);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return out_formats;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-12-24 06:08:42 +00:00
|
|
|
ensure_allowed_raw_caps (GstVaapiPluginBase * plugin, GstVideoFormat format,
|
|
|
|
GstPadDirection direction)
|
2018-09-20 01:57:33 +00:00
|
|
|
{
|
|
|
|
GArray *formats, *out_formats;
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstCaps *out_caps;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (plugin->allowed_raw_caps)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
out_formats = NULL;
|
|
|
|
display = gst_object_ref (plugin->display);
|
|
|
|
formats = gst_vaapi_display_get_image_formats (display);
|
|
|
|
if (!formats)
|
|
|
|
goto bail;
|
2018-12-24 06:08:42 +00:00
|
|
|
out_formats =
|
|
|
|
extract_allowed_surface_formats (display, formats, format, direction);
|
2018-09-20 01:57:33 +00:00
|
|
|
if (!out_formats)
|
|
|
|
goto bail;
|
2015-07-23 11:11:40 +00:00
|
|
|
out_caps = gst_vaapi_video_format_new_template_caps_from_list (out_formats);
|
|
|
|
if (!out_caps)
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
gst_caps_replace (&plugin->allowed_raw_caps, out_caps);
|
|
|
|
gst_caps_unref (out_caps);
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
bail:
|
|
|
|
if (formats)
|
|
|
|
g_array_unref (formats);
|
|
|
|
if (out_formats)
|
|
|
|
g_array_unref (out_formats);
|
2018-06-13 15:54:23 +00:00
|
|
|
gst_object_unref (display);
|
2015-07-23 11:11:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-24 06:08:42 +00:00
|
|
|
* gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
*
|
|
|
|
* Returns the raw #GstCaps allowed by the element.
|
|
|
|
*
|
|
|
|
* Returns: the allowed raw #GstCaps or %NULL
|
|
|
|
**/
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin)
|
|
|
|
{
|
|
|
|
if (!ensure_allowed_raw_caps (plugin, GST_VIDEO_FORMAT_UNKNOWN, GST_PAD_SINK))
|
|
|
|
return NULL;
|
|
|
|
return plugin->allowed_raw_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps:
|
2015-07-23 11:11:40 +00:00
|
|
|
* @plugin: a #GstVaapiPluginBase
|
2018-12-24 06:08:42 +00:00
|
|
|
* @format: a #GstVideoFormat, the format we need to check
|
2015-07-23 11:11:40 +00:00
|
|
|
*
|
|
|
|
* Returns the raw #GstCaps allowed by the element.
|
|
|
|
*
|
|
|
|
* Returns: the allowed raw #GstCaps or %NULL
|
|
|
|
**/
|
|
|
|
GstCaps *
|
2018-12-24 06:08:42 +00:00
|
|
|
gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (GstVaapiPluginBase *
|
|
|
|
plugin, GstVideoFormat format)
|
2015-07-23 11:11:40 +00:00
|
|
|
{
|
2018-12-24 06:08:42 +00:00
|
|
|
if (!ensure_allowed_raw_caps (plugin, format, GST_PAD_SRC))
|
2015-07-23 11:11:40 +00:00
|
|
|
return NULL;
|
|
|
|
return plugin->allowed_raw_caps;
|
|
|
|
}
|
2017-10-04 06:30:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_base_set_srcpad_can_dmabuf:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @object: the GL context from gst-gl
|
|
|
|
*
|
|
|
|
* This function will determine if @object supports dmabuf
|
|
|
|
* importing.
|
|
|
|
*
|
|
|
|
* Please note that the context @object should come from downstream.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
|
|
|
|
GstObject * object)
|
|
|
|
{
|
2018-12-24 04:58:53 +00:00
|
|
|
#if USE_EGL && USE_GST_GL_HELPERS
|
2017-10-04 06:30:51 +00:00
|
|
|
GstGLContext *const gl_context = GST_GL_CONTEXT (object);
|
|
|
|
|
|
|
|
plugin->srcpad_can_dmabuf =
|
|
|
|
(!(gst_gl_context_get_gl_api (gl_context) & GST_GL_API_GLES1)
|
|
|
|
&& gst_gl_context_check_feature (gl_context,
|
|
|
|
"EGL_EXT_image_dma_buf_import"));
|
|
|
|
#endif
|
|
|
|
}
|
2018-02-15 18:32:19 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_init_performance_debug (void)
|
|
|
|
{
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
static volatile gsize _init = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_plugin_copy_va_buffer:
|
|
|
|
* @plugin: a #GstVaapiPluginBase
|
|
|
|
* @inbuf: a #GstBuffer with VA memory type
|
|
|
|
* @outbuf: a #GstBuffer with system allocated memory
|
|
|
|
*
|
|
|
|
* Copy @inbuf to @outbuf. This if required when downstream doesn't
|
|
|
|
* support GstVideoMeta, and since VA memory may have custom strides a
|
|
|
|
* frame copy is required.
|
|
|
|
*
|
|
|
|
* Returns: %FALSE if the copy failed, otherwise %TRUE. Also returns
|
|
|
|
* %TRUE if it is not required to do the copy
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_plugin_copy_va_buffer (GstVaapiPluginBase * plugin,
|
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf)
|
|
|
|
{
|
|
|
|
GstVideoMeta *vmeta;
|
|
|
|
GstVideoFrame src_frame, dst_frame;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
if (!plugin->copy_output_frame)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* inbuf shall have video meta */
|
|
|
|
vmeta = gst_buffer_get_video_meta (inbuf);
|
|
|
|
if (!vmeta)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
_init_performance_debug ();
|
|
|
|
GST_CAT_INFO (CAT_PERFORMANCE, "copying VA buffer to system memory buffer");
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&src_frame, &plugin->srcpad_info, inbuf,
|
|
|
|
GST_MAP_READ))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_video_frame_map (&dst_frame, &plugin->srcpad_info, outbuf,
|
|
|
|
GST_MAP_WRITE)) {
|
|
|
|
gst_video_frame_unmap (&src_frame);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
success = gst_video_frame_copy (&dst_frame, &src_frame);
|
|
|
|
gst_video_frame_unmap (&dst_frame);
|
|
|
|
gst_video_frame_unmap (&src_frame);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS
|
|
|
|
| GST_BUFFER_COPY_FLAGS, 0, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|