2012-11-08 14:41:22 +00:00
|
|
|
/*
|
|
|
|
* gstvaapivideobufferpool.c - Gstreamer/VA video buffer pool
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2012-11-08 14:41:22 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2012-11-08 14:41:22 +00:00
|
|
|
#include "gstvaapivideobufferpool.h"
|
|
|
|
#include "gstvaapivideobuffer.h"
|
|
|
|
#include "gstvaapivideomemory.h"
|
2016-05-20 12:15:53 +00:00
|
|
|
#include "gstvaapipluginutil.h"
|
2015-04-03 14:09:08 +00:00
|
|
|
#if (USE_GLX || USE_EGL)
|
2013-11-20 17:20:07 +00:00
|
|
|
#include "gstvaapivideometa_texture.h"
|
|
|
|
#endif
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_debug_vaapivideopool);
|
2012-11-08 14:41:22 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_debug_vaapivideopool
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
G_DEFINE_TYPE (GstVaapiVideoBufferPool,
|
|
|
|
gst_vaapi_video_buffer_pool, GST_TYPE_BUFFER_POOL);
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
PROP_DISPLAY,
|
2012-11-08 14:41:22 +00:00
|
|
|
};
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
struct _GstVaapiVideoBufferPoolPrivate
|
|
|
|
{
|
2016-05-20 12:39:23 +00:00
|
|
|
GstVideoInfo video_info;
|
2014-08-21 08:45:31 +00:00
|
|
|
GstAllocator *allocator;
|
2015-01-26 17:30:47 +00:00
|
|
|
GstVideoInfo alloc_info;
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiDisplay *display;
|
2016-05-25 08:58:01 +00:00
|
|
|
guint options;
|
2015-01-26 17:30:47 +00:00
|
|
|
guint use_dmabuf_memory:1;
|
2012-11-08 14:41:22 +00:00
|
|
|
};
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
#define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL, \
|
|
|
|
GstVaapiVideoBufferPoolPrivate))
|
2012-11-08 14:41:22 +00:00
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_finalize (GObject * object)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_display_replace (&priv->display, NULL);
|
|
|
|
g_clear_object (&priv->allocator);
|
2015-04-28 00:50:19 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_vaapi_video_buffer_pool_parent_class)->finalize (object);
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
switch (prop_id) {
|
2012-11-08 14:41:22 +00:00
|
|
|
case PROP_DISPLAY:
|
2014-08-21 08:45:31 +00:00
|
|
|
priv->display = gst_vaapi_display_ref (g_value_get_pointer (value));
|
|
|
|
break;
|
2012-11-08 14:41:22 +00:00
|
|
|
default:
|
2014-08-21 08:45:31 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL (object)->priv;
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
switch (prop_id) {
|
2012-11-08 14:41:22 +00:00
|
|
|
case PROP_DISPLAY:
|
2014-08-21 08:45:31 +00:00
|
|
|
g_value_set_pointer (value, priv->display);
|
|
|
|
break;
|
2012-11-08 14:41:22 +00:00
|
|
|
default:
|
2014-08-21 08:45:31 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 13:52:06 +00:00
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
fill_video_alignment (GstVaapiVideoBufferPool * pool, GstVideoAlignment * align)
|
2014-07-25 13:52:06 +00:00
|
|
|
{
|
2015-01-26 17:30:47 +00:00
|
|
|
GstVideoInfo *const vip = &pool->priv->alloc_info;
|
2014-08-21 08:45:31 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
gst_video_alignment_reset (align);
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (vip); i++)
|
|
|
|
align->stride_align[i] =
|
|
|
|
(1U << g_bit_nth_lsf (GST_VIDEO_INFO_PLANE_STRIDE (vip, i), 0)) - 1;
|
2014-07-25 13:52:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 14:41:22 +00:00
|
|
|
static const gchar **
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_get_options (GstBufferPool * pool)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
static const gchar *g_options[] = {
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META,
|
|
|
|
GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
return g_options;
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_set_config (GstBufferPool * pool,
|
|
|
|
GstStructure * config)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL (pool)->priv;
|
2016-05-20 16:46:14 +00:00
|
|
|
GstCaps *caps;
|
2016-05-20 12:39:23 +00:00
|
|
|
GstVideoInfo new_vip;
|
2016-05-20 16:46:14 +00:00
|
|
|
const GstVideoInfo *alloc_vip;
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVideoAlignment align;
|
|
|
|
GstAllocator *allocator;
|
2016-06-14 16:45:22 +00:00
|
|
|
gboolean ret, updated = FALSE;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2016-05-20 16:46:14 +00:00
|
|
|
GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
|
|
|
|
|
|
|
|
caps = NULL;
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, NULL, NULL))
|
|
|
|
goto error_invalid_config;
|
2016-05-23 20:30:04 +00:00
|
|
|
if (!caps)
|
2014-08-21 08:45:31 +00:00
|
|
|
goto error_no_caps;
|
2016-05-20 12:39:23 +00:00
|
|
|
if (!gst_video_info_from_caps (&new_vip, caps))
|
2016-05-23 20:30:04 +00:00
|
|
|
goto error_invalid_caps;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2016-05-20 16:46:14 +00:00
|
|
|
allocator = NULL;
|
|
|
|
if (!gst_buffer_pool_config_get_allocator (config, &allocator, NULL))
|
|
|
|
goto error_invalid_allocator;
|
2015-01-26 17:30:47 +00:00
|
|
|
|
2016-05-20 16:46:14 +00:00
|
|
|
if (gst_video_info_changed (&priv->video_info, &new_vip))
|
|
|
|
gst_object_replace ((GstObject **) & priv->allocator, NULL);
|
|
|
|
priv->video_info = new_vip;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META))
|
|
|
|
goto error_no_vaapi_video_meta_option;
|
|
|
|
|
2016-05-20 16:46:14 +00:00
|
|
|
/* not our allocator, not our buffers */
|
|
|
|
if (allocator) {
|
|
|
|
priv->use_dmabuf_memory = gst_vaapi_is_dmabuf_allocator (allocator);
|
|
|
|
if (priv->use_dmabuf_memory ||
|
|
|
|
g_strcmp0 (allocator->mem_type, GST_VAAPI_VIDEO_MEMORY_NAME) == 0) {
|
|
|
|
if (priv->allocator)
|
|
|
|
gst_object_unref (priv->allocator);
|
|
|
|
if ((priv->allocator = allocator))
|
|
|
|
gst_object_ref (allocator);
|
|
|
|
alloc_vip = gst_allocator_get_vaapi_video_info (priv->allocator, NULL);
|
|
|
|
if (!alloc_vip)
|
|
|
|
goto error_create_allocator_info;
|
|
|
|
priv->alloc_info = *alloc_vip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!priv->allocator)
|
|
|
|
goto error_no_allocator;
|
|
|
|
|
2016-05-25 08:58:01 +00:00
|
|
|
priv->options = 0;
|
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META))
|
|
|
|
priv->options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META;
|
2016-06-14 16:45:22 +00:00
|
|
|
else {
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&priv->video_info); i++) {
|
|
|
|
if (GST_VIDEO_INFO_PLANE_OFFSET (&priv->video_info, i) !=
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (&priv->alloc_info, i) ||
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (&priv->video_info, i) !=
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (&priv->alloc_info, i)) {
|
|
|
|
priv->options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META;
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
updated = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2016-05-25 08:58:01 +00:00
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT)) {
|
2014-08-21 08:45:31 +00:00
|
|
|
fill_video_alignment (GST_VAAPI_VIDEO_BUFFER_POOL (pool), &align);
|
|
|
|
gst_buffer_pool_config_set_video_alignment (config, &align);
|
|
|
|
}
|
|
|
|
|
2016-05-25 08:58:01 +00:00
|
|
|
if (!priv->use_dmabuf_memory && gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META))
|
|
|
|
priv->options |= GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2016-06-14 16:45:22 +00:00
|
|
|
ret =
|
2014-08-21 08:45:31 +00:00
|
|
|
GST_BUFFER_POOL_CLASS
|
|
|
|
(gst_vaapi_video_buffer_pool_parent_class)->set_config (pool, config);
|
2016-06-14 16:45:22 +00:00
|
|
|
return !updated && ret;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-08 14:41:22 +00:00
|
|
|
error_invalid_config:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "invalid config");
|
2014-08-21 08:45:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
error_no_caps:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-20 16:46:14 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "no caps in config");
|
2014-08-21 08:45:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-23 20:30:04 +00:00
|
|
|
error_invalid_caps:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (pool, "invalid caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-20 16:46:14 +00:00
|
|
|
error_invalid_allocator:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (pool, "no allocator in config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
error_no_vaapi_video_meta_option:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-20 16:46:14 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "no GstVaapiVideoMeta option in config");
|
2014-08-21 08:45:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-26 17:30:47 +00:00
|
|
|
error_create_allocator_info:
|
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool,
|
|
|
|
"failed to create GstVaapiVideoAllocator `video-info'");
|
2015-01-26 17:30:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-20 16:46:14 +00:00
|
|
|
error_no_allocator:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-20 16:46:14 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "no allocator defined");
|
2014-08-21 08:45:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_alloc_buffer (GstBufferPool * pool,
|
|
|
|
GstBuffer ** out_buffer_ptr, GstBufferPoolAcquireParams * params)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL (pool)->priv;
|
|
|
|
GstVaapiVideoMeta *meta;
|
|
|
|
GstMemory *mem;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
2014-08-21 09:12:39 +00:00
|
|
|
const gboolean alloc_vaapi_video_meta = !params ||
|
|
|
|
!(params->flags & GST_VAAPI_VIDEO_BUFFER_POOL_ACQUIRE_FLAG_NO_ALLOC);
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!priv->allocator)
|
|
|
|
goto error_no_allocator;
|
|
|
|
|
2014-08-21 09:12:39 +00:00
|
|
|
if (alloc_vaapi_video_meta) {
|
|
|
|
meta = gst_vaapi_video_meta_new (priv->display);
|
|
|
|
if (!meta)
|
|
|
|
goto error_create_meta;
|
2014-08-21 08:45:31 +00:00
|
|
|
|
2014-08-21 09:12:39 +00:00
|
|
|
buffer = gst_vaapi_video_buffer_new (meta);
|
|
|
|
} else {
|
|
|
|
meta = NULL;
|
|
|
|
buffer = gst_vaapi_video_buffer_new_empty ();
|
|
|
|
}
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!buffer)
|
|
|
|
goto error_create_buffer;
|
|
|
|
|
2015-01-26 17:30:47 +00:00
|
|
|
if (priv->use_dmabuf_memory)
|
|
|
|
mem = gst_vaapi_dmabuf_memory_new (priv->allocator, meta);
|
|
|
|
else
|
|
|
|
mem = gst_vaapi_video_memory_new (priv->allocator, meta);
|
2014-08-21 08:45:31 +00:00
|
|
|
if (!mem)
|
|
|
|
goto error_create_memory;
|
2014-08-21 09:12:39 +00:00
|
|
|
gst_vaapi_video_meta_replace (&meta, NULL);
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_buffer_append_memory (buffer, mem);
|
|
|
|
|
2016-05-25 08:58:01 +00:00
|
|
|
if (priv->options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_VIDEO_META) {
|
2015-01-26 17:30:47 +00:00
|
|
|
GstVideoInfo *const vip = &priv->alloc_info;
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVideoMeta *vmeta;
|
|
|
|
|
|
|
|
vmeta = gst_buffer_add_video_meta_full (buffer, 0,
|
|
|
|
GST_VIDEO_INFO_FORMAT (vip), GST_VIDEO_INFO_WIDTH (vip),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (vip), GST_VIDEO_INFO_N_PLANES (vip),
|
|
|
|
&GST_VIDEO_INFO_PLANE_OFFSET (vip, 0),
|
|
|
|
&GST_VIDEO_INFO_PLANE_STRIDE (vip, 0));
|
2015-01-26 17:30:47 +00:00
|
|
|
|
|
|
|
if (GST_VAAPI_IS_VIDEO_MEMORY (mem)) {
|
|
|
|
vmeta->map = gst_video_meta_map_vaapi_memory;
|
|
|
|
vmeta->unmap = gst_video_meta_unmap_vaapi_memory;
|
|
|
|
}
|
2014-08-21 08:45:31 +00:00
|
|
|
}
|
2015-04-03 14:09:08 +00:00
|
|
|
#if (USE_GLX || USE_EGL)
|
2016-05-25 08:58:01 +00:00
|
|
|
if (priv->options & GST_VAAPI_VIDEO_BUFFER_POOL_OPTION_GL_TEXTURE_UPLOAD)
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_buffer_add_texture_upload_meta (buffer);
|
2013-11-20 17:20:07 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
*out_buffer_ptr = buffer;
|
|
|
|
return GST_FLOW_OK;
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
/* ERRORS */
|
2012-11-08 14:41:22 +00:00
|
|
|
error_no_allocator:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "no GstAllocator in buffer pool");
|
2014-08-21 08:45:31 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
error_create_meta:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "failed to allocate vaapi video meta");
|
2014-08-21 08:45:31 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
error_create_buffer:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "failed to create video buffer");
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_meta_unref (meta);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
error_create_memory:
|
2014-08-21 08:45:31 +00:00
|
|
|
{
|
2016-05-06 11:17:47 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "failed to create video memory");
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
gst_vaapi_video_meta_unref (meta);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_reset_buffer (GstBufferPool * pool,
|
|
|
|
GstBuffer * buffer)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstMemory *const mem = gst_buffer_peek_memory (buffer, 0);
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
/* Release the underlying surface proxy */
|
2015-01-26 17:30:47 +00:00
|
|
|
if (GST_VAAPI_IS_VIDEO_MEMORY (mem))
|
|
|
|
gst_vaapi_video_memory_reset_surface (GST_VAAPI_VIDEO_MEMORY_CAST (mem));
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
GST_BUFFER_POOL_CLASS (gst_vaapi_video_buffer_pool_parent_class)->reset_buffer
|
|
|
|
(pool, buffer);
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_class_init (GstVaapiVideoBufferPoolClass * klass)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstBufferPoolClass *const pool_class = GST_BUFFER_POOL_CLASS (klass);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_vaapivideopool,
|
|
|
|
"vaapivideopool", 0, "VA-API video pool");
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GstVaapiVideoBufferPoolPrivate));
|
|
|
|
|
|
|
|
object_class->finalize = gst_vaapi_video_buffer_pool_finalize;
|
|
|
|
object_class->set_property = gst_vaapi_video_buffer_pool_set_property;
|
|
|
|
object_class->get_property = gst_vaapi_video_buffer_pool_get_property;
|
|
|
|
pool_class->get_options = gst_vaapi_video_buffer_pool_get_options;
|
|
|
|
pool_class->set_config = gst_vaapi_video_buffer_pool_set_config;
|
|
|
|
pool_class->alloc_buffer = gst_vaapi_video_buffer_pool_alloc_buffer;
|
|
|
|
pool_class->reset_buffer = gst_vaapi_video_buffer_pool_reset_buffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstVaapiVideoBufferPool:display:
|
|
|
|
*
|
|
|
|
* The #GstVaapiDisplay this object is bound to.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_pointer ("display",
|
|
|
|
"Display",
|
|
|
|
"The GstVaapiDisplay to use for this video pool",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_init (GstVaapiVideoBufferPool * pool)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
GstVaapiVideoBufferPoolPrivate *const priv =
|
|
|
|
GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE (pool);
|
2012-11-08 14:41:22 +00:00
|
|
|
|
2014-08-21 08:45:31 +00:00
|
|
|
pool->priv = priv;
|
2013-10-09 15:25:10 +00:00
|
|
|
|
2016-05-20 12:39:23 +00:00
|
|
|
gst_video_info_init (&priv->video_info);
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstBufferPool *
|
2014-08-21 08:45:31 +00:00
|
|
|
gst_vaapi_video_buffer_pool_new (GstVaapiDisplay * display)
|
2012-11-08 14:41:22 +00:00
|
|
|
{
|
2014-08-21 08:45:31 +00:00
|
|
|
return g_object_new (GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,
|
|
|
|
"display", display, NULL);
|
2012-11-08 14:41:22 +00:00
|
|
|
}
|