2012-07-06 09:05:03 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2012 Matthew Waters <>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-07-06 09:05:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglbufferpool.h"
|
2017-07-07 15:15:12 +00:00
|
|
|
|
|
|
|
#include "gstglmemory.h"
|
|
|
|
#include "gstglsyncmeta.h"
|
2014-12-19 17:11:08 +00:00
|
|
|
#include "gstglutils.h"
|
2012-07-06 09:05:03 +00:00
|
|
|
|
2023-08-03 05:08:03 +00:00
|
|
|
#define DEFAULT_FREE_QUEUE_MIN_DEPTH 0
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglbufferpool
|
2017-07-26 09:04:09 +00:00
|
|
|
* @title: GstGLBufferPool
|
2016-11-03 01:03:24 +00:00
|
|
|
* @short_description: buffer pool for #GstGLBaseMemory objects
|
|
|
|
* @see_also: #GstBufferPool, #GstGLBaseMemory, #GstGLMemory
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* a #GstGLBufferPool is an object that allocates buffers with #GstGLBaseMemory
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
|
|
|
* A #GstGLBufferPool is created with gst_gl_buffer_pool_new()
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* #GstGLBufferPool implements the VideoMeta buffer pool option
|
2016-11-03 01:03:24 +00:00
|
|
|
* %GST_BUFFER_POOL_OPTION_VIDEO_META, the VideoAligment buffer pool option
|
|
|
|
* %GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT as well as the OpenGL specific
|
|
|
|
* %GST_BUFFER_POOL_OPTION_GL_SYNC_META buffer pool option.
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-06 09:05:03 +00:00
|
|
|
/* bufferpool */
|
|
|
|
struct _GstGLBufferPoolPrivate
|
|
|
|
{
|
|
|
|
GstAllocator *allocator;
|
2015-12-16 07:32:40 +00:00
|
|
|
GstGLVideoAllocationParams *gl_params;
|
2012-07-06 09:05:03 +00:00
|
|
|
GstCaps *caps;
|
2012-09-17 00:30:01 +00:00
|
|
|
gboolean add_videometa;
|
2014-10-17 13:22:24 +00:00
|
|
|
gboolean add_glsyncmeta;
|
2023-08-03 05:08:03 +00:00
|
|
|
|
|
|
|
gsize free_queue_min_depth;
|
|
|
|
/* work around the GPU still potentially executing a buffer after it has been
|
|
|
|
* freed by keeping N buffers before being able to reuse them */
|
|
|
|
GQueue *free_cache_buffers;
|
2012-07-06 09:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_gl_buffer_pool_finalize (GObject * object);
|
|
|
|
|
2012-09-20 13:21:19 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_GL_BUFFER_POOL);
|
|
|
|
#define GST_CAT_DEFAULT GST_CAT_GL_BUFFER_POOL
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define _init \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_GL_BUFFER_POOL, "glbufferpool", 0, \
|
|
|
|
"GL Buffer Pool");
|
2012-07-06 09:05:03 +00:00
|
|
|
|
|
|
|
#define gst_gl_buffer_pool_parent_class parent_class
|
2012-09-20 13:21:19 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLBufferPool, gst_gl_buffer_pool,
|
2018-06-23 19:33:16 +00:00
|
|
|
GST_TYPE_BUFFER_POOL, G_ADD_PRIVATE (GstGLBufferPool)
|
|
|
|
_init);
|
2012-07-06 09:05:03 +00:00
|
|
|
|
|
|
|
static const gchar **
|
|
|
|
gst_gl_buffer_pool_get_options (GstBufferPool * pool)
|
|
|
|
{
|
2014-10-18 08:03:43 +00:00
|
|
|
static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META,
|
2014-12-19 17:11:08 +00:00
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT,
|
2015-10-29 14:27:36 +00:00
|
|
|
GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_2D,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_RECTANGLE,
|
2014-12-19 17:11:08 +00:00
|
|
|
NULL
|
2012-07-06 09:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|
|
|
{
|
|
|
|
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
|
|
|
GstGLBufferPoolPrivate *priv = glpool->priv;
|
|
|
|
GstVideoInfo info;
|
2014-08-10 21:58:22 +00:00
|
|
|
GstCaps *caps = NULL;
|
2014-12-19 17:11:08 +00:00
|
|
|
guint min_buffers, max_buffers;
|
2015-09-15 10:34:12 +00:00
|
|
|
guint max_align, n;
|
2014-08-10 21:58:22 +00:00
|
|
|
GstAllocator *allocator = NULL;
|
2012-07-06 09:05:03 +00:00
|
|
|
GstAllocationParams alloc_params;
|
2015-12-16 07:32:40 +00:00
|
|
|
GstGLTextureTarget tex_target;
|
2015-12-11 05:07:36 +00:00
|
|
|
gboolean ret = TRUE;
|
2014-12-19 17:22:12 +00:00
|
|
|
gint p;
|
2012-07-06 09:05:03 +00:00
|
|
|
|
2014-12-19 17:11:08 +00:00
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
|
|
|
|
&max_buffers))
|
2012-07-06 09:05:03 +00:00
|
|
|
goto wrong_config;
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
/* now parse the caps from the config */
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height,
|
|
|
|
caps);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_get_allocator (config, &allocator, &alloc_params))
|
|
|
|
goto wrong_config;
|
|
|
|
|
2023-08-03 05:08:03 +00:00
|
|
|
{
|
|
|
|
guint min_free_queue_size =
|
|
|
|
gst_buffer_pool_config_get_gl_min_free_queue_size (config);
|
|
|
|
if (min_buffers < min_free_queue_size) {
|
|
|
|
min_buffers = MAX (min_buffers, min_free_queue_size);
|
|
|
|
}
|
|
|
|
if (max_buffers != 0 && max_buffers < min_buffers)
|
|
|
|
goto wrong_buffer_count;
|
|
|
|
|
|
|
|
priv->free_queue_min_depth = min_free_queue_size;
|
|
|
|
}
|
|
|
|
|
2016-01-16 14:55:42 +00:00
|
|
|
gst_caps_replace (&priv->caps, caps);
|
2015-12-16 07:32:40 +00:00
|
|
|
|
2014-08-10 21:58:22 +00:00
|
|
|
if (priv->allocator)
|
|
|
|
gst_object_unref (priv->allocator);
|
|
|
|
|
2016-11-15 03:36:11 +00:00
|
|
|
if (allocator) {
|
|
|
|
if (!GST_IS_GL_MEMORY_ALLOCATOR (allocator)) {
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
goto wrong_allocator;
|
|
|
|
} else {
|
|
|
|
priv->allocator = gst_object_ref (allocator);
|
|
|
|
}
|
2015-12-16 07:32:40 +00:00
|
|
|
} else {
|
2015-12-18 02:17:34 +00:00
|
|
|
priv->allocator =
|
|
|
|
GST_ALLOCATOR (gst_gl_memory_allocator_get_default (glpool->context));
|
2015-12-16 07:32:40 +00:00
|
|
|
g_assert (priv->allocator);
|
2012-07-06 09:05:03 +00:00
|
|
|
}
|
2014-08-10 21:58:22 +00:00
|
|
|
|
2012-09-17 00:30:01 +00:00
|
|
|
priv->add_videometa = gst_buffer_pool_config_has_option (config,
|
2012-07-06 09:05:03 +00:00
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
2014-10-17 13:22:24 +00:00
|
|
|
priv->add_glsyncmeta = gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_SYNC_META);
|
2012-07-06 09:05:03 +00:00
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
if (priv->gl_params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) priv->gl_params);
|
|
|
|
priv->gl_params = (GstGLVideoAllocationParams *)
|
|
|
|
gst_buffer_pool_config_get_gl_allocation_params (config);
|
|
|
|
if (!priv->gl_params)
|
|
|
|
priv->gl_params = gst_gl_video_allocation_params_new (glpool->context,
|
2016-06-28 03:51:22 +00:00
|
|
|
&alloc_params, &info, -1, NULL, 0, 0);
|
2015-12-16 07:32:40 +00:00
|
|
|
|
2015-09-15 10:34:12 +00:00
|
|
|
max_align = alloc_params.align;
|
|
|
|
|
2014-12-19 17:11:08 +00:00
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT)) {
|
|
|
|
priv->add_videometa = TRUE;
|
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
gst_buffer_pool_config_get_video_alignment (config,
|
|
|
|
priv->gl_params->valign);
|
2015-09-15 10:34:12 +00:00
|
|
|
|
|
|
|
for (n = 0; n < GST_VIDEO_MAX_PLANES; ++n)
|
2015-12-16 07:32:40 +00:00
|
|
|
max_align |= priv->gl_params->valign->stride_align[n];
|
2015-09-15 10:34:12 +00:00
|
|
|
|
|
|
|
for (n = 0; n < GST_VIDEO_MAX_PLANES; ++n)
|
2015-12-16 07:32:40 +00:00
|
|
|
priv->gl_params->valign->stride_align[n] = max_align;
|
2015-09-15 10:34:12 +00:00
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
gst_video_info_align (priv->gl_params->v_info, priv->gl_params->valign);
|
2014-12-19 17:11:08 +00:00
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
gst_buffer_pool_config_set_video_alignment (config,
|
|
|
|
priv->gl_params->valign);
|
2014-12-19 17:11:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 10:34:12 +00:00
|
|
|
if (alloc_params.align < max_align) {
|
|
|
|
GST_WARNING_OBJECT (pool, "allocation params alignment %u is smaller "
|
|
|
|
"than the max specified video stride alignment %u, fixing",
|
|
|
|
(guint) alloc_params.align, max_align);
|
|
|
|
|
|
|
|
alloc_params.align = max_align;
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, &alloc_params);
|
2015-12-16 07:32:40 +00:00
|
|
|
if (priv->gl_params->parent.alloc_params)
|
|
|
|
gst_allocation_params_free (priv->gl_params->parent.alloc_params);
|
|
|
|
priv->gl_params->parent.alloc_params =
|
|
|
|
gst_allocation_params_copy (&alloc_params);
|
2015-09-15 10:34:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 14:27:36 +00:00
|
|
|
{
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
|
|
const gchar *target_str = gst_structure_get_string (s, "texture-target");
|
|
|
|
gboolean multiple_texture_targets = FALSE;
|
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
tex_target = priv->gl_params->target;
|
2015-10-29 14:27:36 +00:00
|
|
|
if (target_str)
|
2015-12-16 07:32:40 +00:00
|
|
|
tex_target = gst_gl_texture_target_from_string (target_str);
|
2015-10-29 14:27:36 +00:00
|
|
|
|
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_2D)) {
|
2015-12-16 07:32:40 +00:00
|
|
|
if (tex_target && tex_target != GST_GL_TEXTURE_TARGET_2D)
|
2015-10-29 14:27:36 +00:00
|
|
|
multiple_texture_targets = TRUE;
|
2015-12-16 07:32:40 +00:00
|
|
|
tex_target = GST_GL_TEXTURE_TARGET_2D;
|
2015-10-29 14:27:36 +00:00
|
|
|
}
|
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_RECTANGLE)) {
|
2015-12-16 07:32:40 +00:00
|
|
|
if (tex_target && tex_target != GST_GL_TEXTURE_TARGET_RECTANGLE)
|
2015-10-29 14:27:36 +00:00
|
|
|
multiple_texture_targets = TRUE;
|
2015-12-16 07:32:40 +00:00
|
|
|
tex_target = GST_GL_TEXTURE_TARGET_RECTANGLE;
|
2015-10-29 14:27:36 +00:00
|
|
|
}
|
|
|
|
if (gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_GL_TEXTURE_TARGET_EXTERNAL_OES)) {
|
2015-12-16 07:32:40 +00:00
|
|
|
if (tex_target && tex_target != GST_GL_TEXTURE_TARGET_EXTERNAL_OES)
|
2015-10-29 14:27:36 +00:00
|
|
|
multiple_texture_targets = TRUE;
|
2015-12-16 07:32:40 +00:00
|
|
|
tex_target = GST_GL_TEXTURE_TARGET_EXTERNAL_OES;
|
2015-10-29 14:27:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
if (!tex_target)
|
|
|
|
tex_target = GST_GL_TEXTURE_TARGET_2D;
|
2015-10-29 14:27:36 +00:00
|
|
|
|
|
|
|
if (multiple_texture_targets) {
|
|
|
|
GST_WARNING_OBJECT (pool, "Multiple texture targets configured either "
|
|
|
|
"through caps or buffer pool options");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2015-12-16 07:32:40 +00:00
|
|
|
|
|
|
|
priv->gl_params->target = tex_target;
|
2015-10-29 14:27:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
/* Recalculate the size and offset as we don't add padding between planes. */
|
2015-12-16 07:32:40 +00:00
|
|
|
priv->gl_params->v_info->size = 0;
|
|
|
|
for (p = 0; p < GST_VIDEO_INFO_N_PLANES (priv->gl_params->v_info); p++) {
|
|
|
|
priv->gl_params->v_info->offset[p] = priv->gl_params->v_info->size;
|
|
|
|
priv->gl_params->v_info->size +=
|
|
|
|
gst_gl_get_plane_data_size (priv->gl_params->v_info,
|
|
|
|
priv->gl_params->valign, p);
|
2014-12-19 17:22:12 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps,
|
|
|
|
priv->gl_params->v_info->size, min_buffers, max_buffers);
|
2014-12-19 17:11:08 +00:00
|
|
|
|
2015-10-29 14:27:36 +00:00
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config) && ret;
|
2012-07-06 09:05:03 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_config:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "invalid config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "no caps in config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool,
|
|
|
|
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
2016-11-15 03:36:11 +00:00
|
|
|
}
|
|
|
|
wrong_allocator:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "Incorrect allocator type for this pool");
|
|
|
|
return FALSE;
|
2012-07-06 09:05:03 +00:00
|
|
|
}
|
2023-08-03 05:08:03 +00:00
|
|
|
wrong_buffer_count:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "Cannot achieve minimum buffer requirements");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-05-01 06:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_buffer_pool_start (GstBufferPool * pool)
|
|
|
|
{
|
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->start (pool);
|
2012-07-06 09:05:03 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 05:08:03 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_buffer_pool_stop (GstBufferPool * pool)
|
|
|
|
{
|
|
|
|
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
|
|
|
GstGLBufferPoolPrivate *priv = glpool->priv;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
while ((buffer = g_queue_pop_head (priv->free_cache_buffers))) {
|
|
|
|
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (pool, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->stop (pool);
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:05:03 +00:00
|
|
|
/* This function handles GstBuffer creation */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|
|
|
GstBufferPoolAcquireParams * params)
|
|
|
|
{
|
2015-12-16 07:32:40 +00:00
|
|
|
GstGLMemoryAllocator *alloc;
|
2012-07-06 09:05:03 +00:00
|
|
|
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
|
|
|
GstGLBufferPoolPrivate *priv = glpool->priv;
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
if (!(buf = gst_buffer_new ())) {
|
|
|
|
goto no_buffer;
|
|
|
|
}
|
|
|
|
|
2015-12-16 07:32:40 +00:00
|
|
|
alloc = GST_GL_MEMORY_ALLOCATOR (priv->allocator);
|
2016-06-28 03:51:22 +00:00
|
|
|
if (!gst_gl_memory_setup_buffer (alloc, buf, priv->gl_params, NULL, NULL, 0))
|
2012-07-06 09:05:03 +00:00
|
|
|
goto mem_create_failed;
|
|
|
|
|
2014-10-17 13:22:24 +00:00
|
|
|
if (priv->add_glsyncmeta)
|
|
|
|
gst_buffer_add_gl_sync_meta (glpool->context, buf);
|
|
|
|
|
2012-07-06 09:05:03 +00:00
|
|
|
*buffer = buf;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
no_buffer:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "can't create image");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
mem_create_failed:
|
|
|
|
{
|
2012-09-27 05:53:46 +00:00
|
|
|
GST_WARNING_OBJECT (pool, "Could not create GL Memory");
|
2012-07-06 09:05:03 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-03 05:08:03 +00:00
|
|
|
static void
|
|
|
|
gst_gl_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool);
|
|
|
|
GstGLBufferPoolPrivate *priv = glpool->priv;
|
|
|
|
|
|
|
|
if (priv->free_queue_min_depth == 0
|
|
|
|
&& g_queue_get_length (priv->free_cache_buffers) == 0) {
|
|
|
|
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (pool, buffer);
|
|
|
|
} else {
|
|
|
|
g_queue_push_tail (priv->free_cache_buffers, buffer);
|
|
|
|
|
|
|
|
while (g_queue_get_length (priv->free_cache_buffers) >
|
|
|
|
priv->free_queue_min_depth) {
|
|
|
|
GstBuffer *release_buffer = g_queue_pop_head (priv->free_cache_buffers);
|
|
|
|
GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (pool,
|
|
|
|
release_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_buffer_pool_new:
|
2015-03-18 17:12:49 +00:00
|
|
|
* @context: the #GstGLContext to use
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstBufferPool that allocates buffers with #GstGLMemory
|
|
|
|
*/
|
2012-07-06 09:05:03 +00:00
|
|
|
GstBufferPool *
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_buffer_pool_new (GstGLContext * context)
|
2012-07-06 09:05:03 +00:00
|
|
|
{
|
|
|
|
GstGLBufferPool *pool;
|
|
|
|
|
|
|
|
pool = g_object_new (GST_TYPE_GL_BUFFER_POOL, NULL);
|
2017-05-15 17:31:31 +00:00
|
|
|
gst_object_ref_sink (pool);
|
2013-09-15 04:23:43 +00:00
|
|
|
pool->context = gst_object_ref (context);
|
2012-07-06 09:05:03 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_LOG_OBJECT (pool, "new GL buffer pool for context %" GST_PTR_FORMAT,
|
|
|
|
context);
|
2012-07-06 09:05:03 +00:00
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CAST (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_buffer_pool_class_init (GstGLBufferPoolClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_gl_buffer_pool_finalize;
|
|
|
|
|
|
|
|
gstbufferpool_class->get_options = gst_gl_buffer_pool_get_options;
|
|
|
|
gstbufferpool_class->set_config = gst_gl_buffer_pool_set_config;
|
|
|
|
gstbufferpool_class->alloc_buffer = gst_gl_buffer_pool_alloc;
|
2023-08-03 05:08:03 +00:00
|
|
|
gstbufferpool_class->release_buffer = gst_gl_buffer_pool_release_buffer;
|
2014-05-01 06:07:05 +00:00
|
|
|
gstbufferpool_class->start = gst_gl_buffer_pool_start;
|
2023-08-03 05:08:03 +00:00
|
|
|
gstbufferpool_class->stop = gst_gl_buffer_pool_stop;
|
2012-07-06 09:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_buffer_pool_init (GstGLBufferPool * pool)
|
|
|
|
{
|
2014-03-22 22:01:49 +00:00
|
|
|
GstGLBufferPoolPrivate *priv = NULL;
|
2013-06-13 04:36:41 +00:00
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
pool->priv = gst_gl_buffer_pool_get_instance_private (pool);
|
2014-03-22 22:01:49 +00:00
|
|
|
priv = pool->priv;
|
|
|
|
|
|
|
|
priv->allocator = NULL;
|
|
|
|
priv->caps = NULL;
|
|
|
|
priv->add_videometa = TRUE;
|
2014-10-17 13:22:24 +00:00
|
|
|
priv->add_glsyncmeta = FALSE;
|
2023-08-03 05:08:03 +00:00
|
|
|
priv->free_queue_min_depth = DEFAULT_FREE_QUEUE_MIN_DEPTH;
|
|
|
|
priv->free_cache_buffers = g_queue_new ();
|
2013-06-13 04:36:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 09:05:03 +00:00
|
|
|
static void
|
|
|
|
gst_gl_buffer_pool_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLBufferPool *pool = GST_GL_BUFFER_POOL_CAST (object);
|
|
|
|
GstGLBufferPoolPrivate *priv = pool->priv;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "finalize GL buffer pool %p", pool);
|
|
|
|
|
|
|
|
if (priv->caps)
|
|
|
|
gst_caps_unref (priv->caps);
|
|
|
|
|
2023-08-03 05:08:03 +00:00
|
|
|
g_clear_pointer (&priv->free_cache_buffers, g_queue_free);
|
|
|
|
|
2012-07-06 09:05:03 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_buffer_pool_parent_class)->finalize (object);
|
2014-03-22 22:01:49 +00:00
|
|
|
|
|
|
|
/* only release the context once all our memory have been deleted */
|
|
|
|
if (pool->context) {
|
|
|
|
gst_object_unref (pool->context);
|
|
|
|
pool->context = NULL;
|
|
|
|
}
|
2014-08-10 21:58:22 +00:00
|
|
|
|
|
|
|
if (priv->allocator) {
|
|
|
|
gst_object_unref (priv->allocator);
|
|
|
|
priv->allocator = NULL;
|
|
|
|
}
|
2015-12-16 07:32:40 +00:00
|
|
|
|
|
|
|
if (priv->gl_params)
|
|
|
|
gst_gl_allocation_params_free ((GstGLAllocationParams *) priv->gl_params);
|
|
|
|
priv->gl_params = NULL;
|
|
|
|
}
|
|
|
|
|
2021-03-17 02:54:17 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_buffer_pool_get_gl_allocation_params:
|
|
|
|
* @pool: the #GstGLBufferPool
|
|
|
|
*
|
|
|
|
* The returned #GstGLAllocationParams will by %NULL before the first successful
|
|
|
|
* call to gst_buffer_pool_set_config(). Subsequent successful calls to
|
|
|
|
* gst_buffer_pool_set_config() will cause this function to return a new
|
|
|
|
* #GstGLAllocationParams which may or may not contain the same information.
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): a copy of the #GstGLAllocationParams being used by the @pool
|
2021-03-17 02:54:17 +00:00
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
GstGLAllocationParams *
|
|
|
|
gst_gl_buffer_pool_get_gl_allocation_params (GstGLBufferPool * pool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GL_BUFFER_POOL (pool), NULL);
|
|
|
|
|
|
|
|
if (pool->priv->gl_params)
|
|
|
|
return gst_gl_allocation_params_copy ((GstGLAllocationParams *) pool->
|
|
|
|
priv->gl_params);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-06 08:35:38 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_get_gl_allocation_params:
|
|
|
|
* @config: a buffer pool config
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): the currently set #GstGLAllocationParams or %NULL
|
2016-03-06 08:35:38 +00:00
|
|
|
*/
|
2015-12-16 07:32:40 +00:00
|
|
|
GstGLAllocationParams *
|
|
|
|
gst_buffer_pool_config_get_gl_allocation_params (GstStructure * config)
|
|
|
|
{
|
|
|
|
GstGLAllocationParams *ret;
|
|
|
|
|
|
|
|
if (!gst_structure_get (config, "gl-allocation-params",
|
|
|
|
GST_TYPE_GL_ALLOCATION_PARAMS, &ret, NULL))
|
|
|
|
ret = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-06 08:35:38 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_set_gl_allocation_params:
|
|
|
|
* @config: a buffer pool config
|
2022-10-15 09:16:01 +00:00
|
|
|
* @params: (transfer none) (nullable): a #GstGLAllocationParams
|
2016-03-06 08:35:38 +00:00
|
|
|
*
|
|
|
|
* Sets @params on @config
|
|
|
|
*/
|
2015-12-16 07:32:40 +00:00
|
|
|
void
|
|
|
|
gst_buffer_pool_config_set_gl_allocation_params (GstStructure * config,
|
2021-01-04 22:25:10 +00:00
|
|
|
const GstGLAllocationParams * params)
|
2015-12-16 07:32:40 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (config != NULL);
|
|
|
|
g_return_if_fail (params != NULL);
|
|
|
|
|
|
|
|
gst_structure_set (config, "gl-allocation-params",
|
|
|
|
GST_TYPE_GL_ALLOCATION_PARAMS, params, NULL);
|
2012-07-06 09:05:03 +00:00
|
|
|
}
|
2023-08-03 05:08:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_set_gl_min_free_queue_size:
|
|
|
|
* @config: a buffer pool config
|
|
|
|
* @queue_size: the number of buffers
|
|
|
|
*
|
|
|
|
* Instructs the #GstGLBufferPool to keep @queue_size amount of buffers around
|
|
|
|
* before allowing them for reuse.
|
|
|
|
*
|
|
|
|
* This is helpful to allow GPU processing to complete before the CPU
|
|
|
|
* operations on the same buffer could start. Particularly useful when
|
|
|
|
* uploading or downloading data to/from the GPU.
|
|
|
|
*
|
|
|
|
* A value of 0 disabled this functionality.
|
|
|
|
*
|
|
|
|
* This value must be less than the configured maximum amount of buffers for
|
|
|
|
* this @config.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_buffer_pool_config_set_gl_min_free_queue_size (GstStructure * config,
|
|
|
|
guint queue_size)
|
|
|
|
{
|
|
|
|
g_return_if_fail (config != NULL);
|
|
|
|
|
|
|
|
gst_structure_set (config, "gl-min-free-queue-size",
|
|
|
|
G_TYPE_UINT, queue_size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_get_gl_min_free_queue_size:
|
|
|
|
* @config: a buffer pool config
|
|
|
|
*
|
|
|
|
* See gst_buffer_pool_config_set_gl_min_free_queue_size().
|
|
|
|
*
|
|
|
|
* Returns: then number of buffers configured the free queue
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_buffer_pool_config_get_gl_min_free_queue_size (GstStructure * config)
|
|
|
|
{
|
|
|
|
guint queue_size = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (config != NULL, 0);
|
|
|
|
|
|
|
|
if (!gst_structure_get (config, "gl-min-free-queue-size",
|
|
|
|
G_TYPE_UINT, &queue_size, NULL))
|
|
|
|
queue_size = 0;
|
|
|
|
|
|
|
|
return queue_size;
|
|
|
|
}
|