2020-03-22 18:00:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2020 Igalia, S.L.
|
|
|
|
* Author: Víctor Jáquez <vjaquez@igalia.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstvapool
|
|
|
|
* @title: GstVaPool
|
|
|
|
* @short_description: VA Buffer pool
|
|
|
|
* @sources:
|
|
|
|
* - gstvapool.h
|
|
|
|
*
|
|
|
|
* @GstVaPool is a buffer pool for VA allocators.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstvapool.h"
|
2023-02-22 10:39:22 +00:00
|
|
|
#include "gstvavideoformat.h"
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_va_pool_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_va_pool_debug
|
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* GstVaPool:
|
|
|
|
*
|
|
|
|
* A buffer pool that uses either #GstVaAllocator or
|
|
|
|
* #GstVaDmabufAllocator to pre-allocate and recycle #GstBuffers.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
2022-03-30 05:03:59 +00:00
|
|
|
typedef struct _GstVaPool GstVaPool;
|
|
|
|
typedef struct _GstVaPoolClass GstVaPoolClass;
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
struct _GstVaPool
|
|
|
|
{
|
|
|
|
GstBufferPool parent;
|
|
|
|
|
|
|
|
GstVideoInfo alloc_info;
|
2023-02-22 10:39:22 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
GstVideoInfo caps_info;
|
|
|
|
/* GstVideoInfoDmaDrm contains GstVideoInfo. */
|
|
|
|
GstVideoInfoDmaDrm caps_info_drm;
|
|
|
|
};
|
2020-03-22 18:00:50 +00:00
|
|
|
GstAllocator *allocator;
|
2020-10-07 16:03:20 +00:00
|
|
|
gboolean force_videometa;
|
2020-03-22 18:00:50 +00:00
|
|
|
gboolean add_videometa;
|
2021-06-09 09:19:04 +00:00
|
|
|
gint crop_left;
|
|
|
|
gint crop_top;
|
2020-10-08 08:26:54 +00:00
|
|
|
|
|
|
|
gboolean starting;
|
2020-03-22 18:00:50 +00:00
|
|
|
};
|
|
|
|
|
2022-02-23 07:40:19 +00:00
|
|
|
struct _GstVaPoolClass
|
|
|
|
{
|
|
|
|
GstBufferPoolClass parent_class;
|
|
|
|
};
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
#define gst_va_pool_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVaPool, gst_va_pool, GST_TYPE_BUFFER_POOL,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_va_pool_debug, "vapool", 0, "VA Pool"));
|
|
|
|
|
|
|
|
static const gchar **
|
|
|
|
gst_va_pool_get_options (GstBufferPool * pool)
|
|
|
|
{
|
2022-04-23 15:52:34 +00:00
|
|
|
static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, NULL };
|
2020-03-22 18:00:50 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
gst_buffer_pool_config_get_va_allocation_params (GstStructure * config,
|
2022-03-29 12:52:33 +00:00
|
|
|
guint32 * usage_hint, GstVaFeature * use_derived)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
2022-03-29 12:52:33 +00:00
|
|
|
if (!gst_structure_get (config, "usage-hint", G_TYPE_UINT, usage_hint, NULL)) {
|
2020-03-22 18:00:50 +00:00
|
|
|
*usage_hint = VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC;
|
2022-03-29 12:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_get (config, "use-derived", GST_TYPE_VA_FEATURE,
|
|
|
|
use_derived, NULL)) {
|
|
|
|
*use_derived = GST_VA_FEATURE_AUTO;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-04-23 15:40:14 +00:00
|
|
|
static inline gboolean
|
|
|
|
gst_buffer_pool_config_get_va_alignment (GstStructure * config,
|
|
|
|
GstVideoAlignment * align)
|
|
|
|
{
|
|
|
|
return gst_structure_get (config,
|
|
|
|
"va-padding-top", G_TYPE_UINT, &align->padding_top,
|
|
|
|
"va-padding-bottom", G_TYPE_UINT, &align->padding_bottom,
|
|
|
|
"va-padding-left", G_TYPE_UINT, &align->padding_left,
|
|
|
|
"va-padding-right", G_TYPE_UINT, &align->padding_right, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_va_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|
|
|
{
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstVaPool *vpool = GST_VA_POOL (pool);
|
|
|
|
GstVideoAlignment video_align = { 0, };
|
2023-02-22 10:39:22 +00:00
|
|
|
GstVideoInfo orginal_alloc_info;
|
|
|
|
GstVideoInfoDmaDrm alloc_info_drm;
|
2020-03-22 18:00:50 +00:00
|
|
|
gint width, height;
|
2020-10-07 16:03:20 +00:00
|
|
|
guint i, min_buffers, max_buffers;
|
2020-03-22 18:00:50 +00:00
|
|
|
guint32 usage_hint;
|
2022-03-29 12:52:33 +00:00
|
|
|
GstVaFeature use_derived;
|
2021-06-06 16:49:49 +00:00
|
|
|
gboolean has_alignment;
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2020-10-04 09:14:38 +00:00
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
|
2020-03-22 18:00:50 +00:00
|
|
|
&max_buffers))
|
|
|
|
goto wrong_config;
|
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_get_allocator (config, &allocator, NULL))
|
|
|
|
goto wrong_config;
|
|
|
|
|
2023-02-22 10:39:22 +00:00
|
|
|
if (!allocator)
|
2020-03-22 18:00:50 +00:00
|
|
|
goto wrong_config;
|
|
|
|
|
2023-02-22 10:39:22 +00:00
|
|
|
gst_video_info_dma_drm_init (&vpool->caps_info_drm);
|
|
|
|
if (gst_video_is_dma_drm_caps (caps)) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!GST_IS_VA_DMABUF_ALLOCATOR (allocator))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
if (!gst_video_info_dma_drm_from_caps (&vpool->caps_info_drm, caps))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
if (!gst_va_dma_drm_info_to_video_info (&vpool->caps_info_drm, &info))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
vpool->caps_info_drm.vinfo = info;
|
|
|
|
} else {
|
|
|
|
if (!GST_IS_VA_ALLOCATOR (allocator))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&vpool->caps_info, caps))
|
|
|
|
goto wrong_caps;
|
|
|
|
}
|
|
|
|
|
2022-03-29 12:52:33 +00:00
|
|
|
if (!gst_buffer_pool_config_get_va_allocation_params (config, &usage_hint,
|
|
|
|
&use_derived))
|
2020-03-22 18:00:50 +00:00
|
|
|
goto wrong_config;
|
|
|
|
|
2023-02-22 10:39:22 +00:00
|
|
|
width = GST_VIDEO_INFO_WIDTH (&vpool->caps_info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&vpool->caps_info);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2020-10-04 09:14:38 +00:00
|
|
|
GST_LOG_OBJECT (vpool, "%dx%d | %" GST_PTR_FORMAT, width, height, caps);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
/* enable metadata based on config of the pool */
|
|
|
|
vpool->add_videometa = gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
/* parse extra alignment info */
|
2022-04-23 15:52:34 +00:00
|
|
|
has_alignment = gst_buffer_pool_config_get_va_alignment (config,
|
|
|
|
&video_align);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2021-06-06 16:49:49 +00:00
|
|
|
if (has_alignment) {
|
2020-03-22 18:00:50 +00:00
|
|
|
width += video_align.padding_left + video_align.padding_right;
|
|
|
|
height += video_align.padding_bottom + video_align.padding_top;
|
2021-06-09 09:19:04 +00:00
|
|
|
|
|
|
|
if (video_align.padding_left > 0)
|
|
|
|
vpool->crop_left = video_align.padding_left;
|
|
|
|
if (video_align.padding_top > 0)
|
|
|
|
vpool->crop_top = video_align.padding_top;
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 16:03:20 +00:00
|
|
|
/* update allocation info with aligned size */
|
2023-02-22 10:39:22 +00:00
|
|
|
alloc_info_drm = vpool->caps_info_drm;
|
|
|
|
g_assert (GST_VIDEO_INFO_FORMAT (&alloc_info_drm.vinfo) !=
|
|
|
|
GST_VIDEO_FORMAT_UNKNOWN
|
|
|
|
&& GST_VIDEO_INFO_FORMAT (&alloc_info_drm.vinfo) !=
|
|
|
|
GST_VIDEO_FORMAT_DMA_DRM);
|
|
|
|
GST_VIDEO_INFO_WIDTH (&alloc_info_drm.vinfo) = width;
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&alloc_info_drm.vinfo) = height;
|
|
|
|
|
|
|
|
orginal_alloc_info = alloc_info_drm.vinfo;
|
2020-03-22 18:00:50 +00:00
|
|
|
|
2020-10-07 16:03:20 +00:00
|
|
|
if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) {
|
2023-02-22 10:39:22 +00:00
|
|
|
if (!gst_va_dmabuf_allocator_set_format (allocator, &alloc_info_drm,
|
2020-10-07 16:03:20 +00:00
|
|
|
usage_hint))
|
|
|
|
goto failed_allocator;
|
|
|
|
} else if (GST_IS_VA_ALLOCATOR (allocator)) {
|
2023-02-22 10:39:22 +00:00
|
|
|
if (!gst_va_allocator_set_format (allocator, &alloc_info_drm.vinfo,
|
|
|
|
usage_hint, use_derived))
|
2020-10-07 16:03:20 +00:00
|
|
|
goto failed_allocator;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_replace ((GstObject **) & vpool->allocator,
|
|
|
|
GST_OBJECT (allocator));
|
|
|
|
|
2023-02-22 10:39:22 +00:00
|
|
|
vpool->alloc_info = alloc_info_drm.vinfo;
|
2020-10-25 15:13:46 +00:00
|
|
|
|
2023-02-22 10:39:22 +00:00
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&orginal_alloc_info); i++) {
|
|
|
|
if (GST_VIDEO_INFO_PLANE_STRIDE (&orginal_alloc_info, i) !=
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (&alloc_info_drm.vinfo, i) ||
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (&orginal_alloc_info, i) !=
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (&alloc_info_drm.vinfo, i)) {
|
2020-11-02 17:59:46 +00:00
|
|
|
GST_INFO_OBJECT (vpool, "Video meta is required in buffer.");
|
|
|
|
vpool->force_videometa = TRUE;
|
|
|
|
break;
|
2020-10-07 16:03:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 12:26:24 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps,
|
2023-02-22 10:39:22 +00:00
|
|
|
GST_VIDEO_INFO_SIZE (&alloc_info_drm.vinfo), min_buffers, max_buffers);
|
2020-03-22 18:00:50 +00:00
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config);
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_config:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (vpool, "invalid config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (vpool, "no caps in config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (vpool,
|
|
|
|
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-07 16:03:20 +00:00
|
|
|
failed_allocator:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (vpool, "Failed to set format to allocator");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_va_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|
|
|
GstBufferPoolAcquireParams * params)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstVaPool *vpool = GST_VA_POOL (pool);
|
|
|
|
|
|
|
|
buf = gst_buffer_new ();
|
|
|
|
|
|
|
|
if (GST_IS_VA_DMABUF_ALLOCATOR (vpool->allocator)) {
|
2021-02-07 15:12:56 +00:00
|
|
|
if (vpool->starting) {
|
|
|
|
if (!gst_va_dmabuf_allocator_setup_buffer (vpool->allocator, buf))
|
|
|
|
goto no_memory;
|
|
|
|
} else if (!gst_va_dmabuf_allocator_prepare_buffer (vpool->allocator, buf)) {
|
|
|
|
if (!gst_va_dmabuf_allocator_setup_buffer (vpool->allocator, buf))
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
} else if (GST_IS_VA_ALLOCATOR (vpool->allocator)) {
|
2021-02-07 15:12:56 +00:00
|
|
|
if (vpool->starting) {
|
|
|
|
if (!gst_va_allocator_setup_buffer (vpool->allocator, buf))
|
|
|
|
goto no_memory;
|
|
|
|
} else if (!gst_va_allocator_prepare_buffer (vpool->allocator, buf)) {
|
|
|
|
if (!gst_va_allocator_setup_buffer (vpool->allocator, buf))
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
} else
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if (vpool->add_videometa) {
|
2021-06-09 09:19:04 +00:00
|
|
|
if (vpool->crop_left > 0 || vpool->crop_top > 0) {
|
|
|
|
GstVideoCropMeta *crop_meta;
|
|
|
|
|
|
|
|
/* For video crop, its video meta's width and height should be
|
|
|
|
the full size of uncropped resolution. */
|
|
|
|
gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vpool->alloc_info),
|
|
|
|
GST_VIDEO_INFO_WIDTH (&vpool->alloc_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&vpool->alloc_info),
|
|
|
|
GST_VIDEO_INFO_N_PLANES (&vpool->alloc_info),
|
|
|
|
vpool->alloc_info.offset, vpool->alloc_info.stride);
|
|
|
|
|
|
|
|
crop_meta = gst_buffer_add_video_crop_meta (buf);
|
|
|
|
crop_meta->x = vpool->crop_left;
|
|
|
|
crop_meta->y = vpool->crop_top;
|
|
|
|
crop_meta->width = GST_VIDEO_INFO_WIDTH (&vpool->caps_info);
|
|
|
|
crop_meta->height = GST_VIDEO_INFO_HEIGHT (&vpool->caps_info);
|
|
|
|
} else {
|
|
|
|
/* GstVaAllocator may update offset/stride given the physical
|
|
|
|
* memory */
|
|
|
|
gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
|
|
|
|
GST_VIDEO_INFO_FORMAT (&vpool->caps_info),
|
|
|
|
GST_VIDEO_INFO_WIDTH (&vpool->caps_info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&vpool->caps_info),
|
|
|
|
GST_VIDEO_INFO_N_PLANES (&vpool->caps_info),
|
|
|
|
vpool->alloc_info.offset, vpool->alloc_info.stride);
|
|
|
|
}
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*buffer = buf;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
no_memory:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
GST_WARNING_OBJECT (vpool, "can't create memory");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 14:34:56 +00:00
|
|
|
static gboolean
|
|
|
|
gst_va_pool_start (GstBufferPool * pool)
|
2020-09-30 17:35:14 +00:00
|
|
|
{
|
|
|
|
GstVaPool *vpool = GST_VA_POOL (pool);
|
2021-02-15 14:34:56 +00:00
|
|
|
gboolean ret;
|
2020-09-30 17:35:14 +00:00
|
|
|
|
2021-02-15 14:34:56 +00:00
|
|
|
vpool->starting = TRUE;
|
|
|
|
ret = GST_BUFFER_POOL_CLASS (parent_class)->start (pool);
|
|
|
|
vpool->starting = FALSE;
|
|
|
|
|
|
|
|
return ret;
|
2020-09-30 17:35:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 08:26:54 +00:00
|
|
|
static gboolean
|
2021-02-15 14:34:56 +00:00
|
|
|
gst_va_pool_stop (GstBufferPool * pool)
|
2020-10-08 08:26:54 +00:00
|
|
|
{
|
|
|
|
GstVaPool *vpool = GST_VA_POOL (pool);
|
|
|
|
gboolean ret;
|
|
|
|
|
2021-02-15 14:34:56 +00:00
|
|
|
ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (pool);
|
|
|
|
|
|
|
|
if (GST_IS_VA_DMABUF_ALLOCATOR (vpool->allocator))
|
|
|
|
gst_va_dmabuf_allocator_flush (vpool->allocator);
|
|
|
|
else if (GST_IS_VA_ALLOCATOR (vpool->allocator))
|
|
|
|
gst_va_allocator_flush (vpool->allocator);
|
2020-10-08 08:26:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-22 18:00:50 +00:00
|
|
|
static void
|
|
|
|
gst_va_pool_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstVaPool *pool = GST_VA_POOL (object);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "finalize video buffer pool %p", pool);
|
|
|
|
|
|
|
|
gst_clear_object (&pool->allocator);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_pool_class_init (GstVaPoolClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstBufferPoolClass *gstbufferpool_class = GST_BUFFER_POOL_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = gst_va_pool_dispose;
|
|
|
|
|
|
|
|
gstbufferpool_class->get_options = gst_va_pool_get_options;
|
|
|
|
gstbufferpool_class->set_config = gst_va_pool_set_config;
|
|
|
|
gstbufferpool_class->alloc_buffer = gst_va_pool_alloc;
|
2020-10-08 08:26:54 +00:00
|
|
|
gstbufferpool_class->start = gst_va_pool_start;
|
2021-02-15 14:34:56 +00:00
|
|
|
gstbufferpool_class->stop = gst_va_pool_stop;
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_va_pool_init (GstVaPool * self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* gst_va_pool_new:
|
|
|
|
*
|
|
|
|
* Returns: A new #GstBufferPool for VA allocators.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
2020-03-22 18:00:50 +00:00
|
|
|
GstBufferPool *
|
|
|
|
gst_va_pool_new (void)
|
|
|
|
{
|
|
|
|
GstVaPool *pool;
|
|
|
|
|
|
|
|
pool = g_object_new (GST_TYPE_VA_POOL, NULL);
|
|
|
|
gst_object_ref_sink (pool);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "new va video buffer pool %p", pool);
|
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CAST (pool);
|
|
|
|
}
|
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_set_va_allocation_params:
|
|
|
|
* @config: the #GstStructure with the pool's configuration.
|
|
|
|
* @usage_hint: the VA usage hint for new VASurfaceID.
|
|
|
|
* @use_derived: a #GstVaFeature for derived mapping (only used when
|
|
|
|
* VA allocator).
|
|
|
|
*
|
|
|
|
* Sets the usage hint for the buffers handled by the buffer pool.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
2020-03-22 18:00:50 +00:00
|
|
|
void
|
|
|
|
gst_buffer_pool_config_set_va_allocation_params (GstStructure * config,
|
2022-03-29 12:52:33 +00:00
|
|
|
guint usage_hint, GstVaFeature use_derived)
|
2020-03-22 18:00:50 +00:00
|
|
|
{
|
2022-03-29 12:52:33 +00:00
|
|
|
gst_structure_set (config, "usage-hint", G_TYPE_UINT, usage_hint,
|
|
|
|
"use-derived", GST_TYPE_VA_FEATURE, use_derived, NULL);
|
2020-03-22 18:00:50 +00:00
|
|
|
}
|
2020-10-07 16:03:20 +00:00
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_set_va_alignment:
|
|
|
|
* @config: the #GstStructure with the pool's configuration.
|
|
|
|
* @align: a #GstVideoAlignment
|
|
|
|
*
|
|
|
|
* Video alignment is not handled as expected by VA since it uses
|
|
|
|
* opaque surfaces, not directly mappable memory. Still, decoders
|
|
|
|
* might need to request bigger surfaces for coded size rather than
|
|
|
|
* display sizes. This method will set the coded size to bufferpool's
|
|
|
|
* configuration, out of the typical video aligment.
|
|
|
|
*
|
|
|
|
* Since: 1.20.2
|
|
|
|
*/
|
2022-04-23 15:40:14 +00:00
|
|
|
void
|
|
|
|
gst_buffer_pool_config_set_va_alignment (GstStructure * config,
|
|
|
|
const GstVideoAlignment * align)
|
|
|
|
{
|
|
|
|
gst_structure_set (config,
|
|
|
|
"va-padding-top", G_TYPE_UINT, align->padding_top,
|
|
|
|
"va-padding-bottom", G_TYPE_UINT, align->padding_bottom,
|
|
|
|
"va-padding-left", G_TYPE_UINT, align->padding_left,
|
|
|
|
"va-padding-right", G_TYPE_UINT, align->padding_right, NULL);
|
|
|
|
}
|
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* gst_va_pool_requires_video_meta:
|
|
|
|
* @pool: the #GstBufferPool
|
|
|
|
*
|
|
|
|
* Retuns: %TRUE if @pool always add #GstVideoMeta to its
|
|
|
|
* buffers. Otherwise, %FALSE.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
2020-10-07 16:03:20 +00:00
|
|
|
gboolean
|
|
|
|
gst_va_pool_requires_video_meta (GstBufferPool * pool)
|
|
|
|
{
|
2022-02-23 07:40:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VA_POOL (pool), FALSE);
|
|
|
|
|
2020-10-07 16:03:20 +00:00
|
|
|
return GST_VA_POOL (pool)->force_videometa;
|
|
|
|
}
|
2021-07-27 11:03:37 +00:00
|
|
|
|
2022-02-07 16:34:57 +00:00
|
|
|
/**
|
|
|
|
* gst_va_pool_new_with_config:
|
|
|
|
* @caps: the #GstCaps of the buffers handled by the new pool.
|
|
|
|
* @size: the size of the frames to hold.
|
|
|
|
* @min_buffers: minimum number of frames to create.
|
|
|
|
* @max_buffers: maximum number of frames to create.
|
|
|
|
* @usage_hint: VA usage hint
|
|
|
|
* @use_derived: a #GstVaFeature for derived mapping (only used when
|
|
|
|
* VA allocator).
|
|
|
|
* @allocator: the VA allocator to use.
|
|
|
|
* @alloc_params: #GstAllocationParams to use.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstBufferPool that handles VASurfacesID-backed
|
|
|
|
* buffers. If the pool cannot be configured correctly, %NULL is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
2021-07-27 11:03:37 +00:00
|
|
|
GstBufferPool *
|
|
|
|
gst_va_pool_new_with_config (GstCaps * caps, guint size, guint min_buffers,
|
2022-03-29 12:52:33 +00:00
|
|
|
guint max_buffers, guint usage_hint, GstVaFeature use_derived,
|
|
|
|
GstAllocator * allocator, GstAllocationParams * alloc_params)
|
2021-07-27 11:03:37 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
|
|
|
|
pool = gst_va_pool_new ();
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
|
|
|
|
max_buffers);
|
2022-03-29 12:52:33 +00:00
|
|
|
gst_buffer_pool_config_set_va_allocation_params (config, usage_hint,
|
|
|
|
use_derived);
|
2021-07-27 11:03:37 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, alloc_params);
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
gst_clear_object (&pool);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|