2011-04-28 17:20:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-04-28 17:20:58 +00:00
|
|
|
*/
|
2018-04-28 13:50:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2011-10-31 01:23:21 +00:00
|
|
|
#include "gstvideometa.h"
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2013-04-17 08:35:22 +00:00
|
|
|
#include <string.h>
|
2023-09-18 23:24:35 +00:00
|
|
|
#include <gst/base/base.h>
|
2013-04-17 08:35:22 +00:00
|
|
|
|
2018-04-02 06:34:58 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstvideometa
|
|
|
|
* @title: GstMeta for video
|
|
|
|
* @short_description: Video related GstMeta
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-09-18 23:24:35 +00:00
|
|
|
static gboolean
|
|
|
|
default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
|
|
|
|
gpointer * data, gint * stride, GstMapFlags flags);
|
|
|
|
static gboolean
|
|
|
|
default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info);
|
|
|
|
|
2015-07-15 10:45:10 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
#define GST_CAT_DEFAULT ensure_debug_category()
|
|
|
|
static GstDebugCategory *
|
|
|
|
ensure_debug_category (void)
|
|
|
|
{
|
|
|
|
static gsize cat_gonce = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&cat_gonce)) {
|
|
|
|
gsize cat_done;
|
|
|
|
|
|
|
|
cat_done = (gsize) _gst_debug_category_new ("videometa", 0, "videometa");
|
|
|
|
|
|
|
|
g_once_init_leave (&cat_gonce, cat_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (GstDebugCategory *) cat_gonce;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ensure_debug_category() /* NOOP */
|
|
|
|
#endif /* GST_DISABLE_GST_DEBUG */
|
|
|
|
|
2016-04-13 07:07:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoMeta *emeta = (GstVideoMeta *) meta;
|
|
|
|
|
|
|
|
emeta->buffer = NULL;
|
|
|
|
emeta->flags = GST_VIDEO_FRAME_FLAG_NONE;
|
|
|
|
emeta->format = GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
emeta->id = 0;
|
|
|
|
emeta->width = emeta->height = emeta->n_planes = 0;
|
|
|
|
memset (emeta->offset, 0, sizeof (emeta->offset));
|
|
|
|
memset (emeta->stride, 0, sizeof (emeta->stride));
|
2019-07-09 10:17:44 +00:00
|
|
|
gst_video_alignment_reset (&emeta->alignment);
|
2016-04-13 07:07:33 +00:00
|
|
|
emeta->map = NULL;
|
|
|
|
emeta->unmap = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:18:30 +00:00
|
|
|
static gboolean
|
2012-02-24 09:26:04 +00:00
|
|
|
gst_video_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
2011-12-01 14:45:28 +00:00
|
|
|
{
|
|
|
|
GstVideoMeta *dmeta, *smeta;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
smeta = (GstVideoMeta *) meta;
|
|
|
|
|
2012-02-24 09:26:04 +00:00
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
2012-03-02 12:04:26 +00:00
|
|
|
GstMetaTransformCopy *copy = data;
|
|
|
|
|
|
|
|
if (!copy->region) {
|
|
|
|
/* only copy if the complete data is copied as well */
|
|
|
|
dmeta =
|
|
|
|
(GstVideoMeta *) gst_buffer_add_meta (dest, GST_VIDEO_META_INFO,
|
|
|
|
NULL);
|
2013-04-11 17:25:51 +00:00
|
|
|
|
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-03-02 12:04:26 +00:00
|
|
|
dmeta->buffer = dest;
|
|
|
|
|
|
|
|
GST_DEBUG ("copy video metadata");
|
2012-04-19 12:14:35 +00:00
|
|
|
dmeta->flags = smeta->flags;
|
2012-03-02 12:04:26 +00:00
|
|
|
dmeta->format = smeta->format;
|
2012-03-13 19:17:55 +00:00
|
|
|
dmeta->id = smeta->id;
|
2012-03-02 12:04:26 +00:00
|
|
|
dmeta->width = smeta->width;
|
|
|
|
dmeta->height = smeta->height;
|
|
|
|
|
|
|
|
dmeta->n_planes = smeta->n_planes;
|
|
|
|
for (i = 0; i < dmeta->n_planes; i++) {
|
|
|
|
dmeta->offset[i] = smeta->offset[i];
|
|
|
|
dmeta->stride[i] = smeta->stride[i];
|
2019-07-09 10:17:44 +00:00
|
|
|
dmeta->alignment = smeta->alignment;
|
2012-03-02 12:04:26 +00:00
|
|
|
}
|
2012-03-13 19:17:55 +00:00
|
|
|
dmeta->map = smeta->map;
|
|
|
|
dmeta->unmap = smeta->unmap;
|
2012-02-24 09:26:04 +00:00
|
|
|
}
|
2015-07-07 13:23:57 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
2011-12-01 14:45:28 +00:00
|
|
|
}
|
2012-02-28 15:18:30 +00:00
|
|
|
return TRUE;
|
2011-12-01 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 16:25:10 +00:00
|
|
|
GType
|
|
|
|
gst_video_meta_api_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static GType type = 0;
|
2013-08-21 21:56:15 +00:00
|
|
|
static const gchar *tags[] =
|
|
|
|
{ GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR,
|
|
|
|
GST_META_TAG_VIDEO_COLORSPACE_STR,
|
|
|
|
GST_META_TAG_VIDEO_SIZE_STR, NULL
|
|
|
|
};
|
2012-02-29 16:25:10 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstVideoMetaAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2023-09-18 23:24:35 +00:00
|
|
|
static gboolean
|
|
|
|
video_meta_serialize (const GstMeta * meta, GstByteArrayInterface * data,
|
|
|
|
guint8 * version)
|
|
|
|
{
|
|
|
|
GstVideoMeta *vmeta = (GstVideoMeta *) meta;
|
|
|
|
|
|
|
|
if (vmeta->map != default_map || vmeta->unmap != default_unmap) {
|
|
|
|
GST_WARNING ("Cannot serialize video meta with custom map/unmap functions");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize size = 36 + vmeta->n_planes * 16;
|
|
|
|
guint8 *ptr = gst_byte_array_interface_append (data, size);
|
|
|
|
if (ptr == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GstByteWriter bw;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
gst_byte_writer_init_with_data (&bw, ptr, size, FALSE);
|
|
|
|
success &= gst_byte_writer_put_int32_le (&bw, vmeta->flags);
|
|
|
|
success &= gst_byte_writer_put_int32_le (&bw, vmeta->format);
|
|
|
|
success &= gst_byte_writer_put_uint32_le (&bw, vmeta->width);
|
|
|
|
success &= gst_byte_writer_put_uint32_le (&bw, vmeta->height);
|
|
|
|
success &= gst_byte_writer_put_uint32_le (&bw, vmeta->n_planes);
|
|
|
|
for (int n = 0; n < vmeta->n_planes; n++)
|
|
|
|
success &= gst_byte_writer_put_uint64_le (&bw, vmeta->offset[n]);
|
|
|
|
for (int n = 0; n < vmeta->n_planes; n++)
|
|
|
|
success &= gst_byte_writer_put_int32_le (&bw, vmeta->stride[n]);
|
|
|
|
success &= gst_byte_writer_put_uint32_le (&bw, vmeta->alignment.padding_top);
|
|
|
|
success &=
|
|
|
|
gst_byte_writer_put_uint32_le (&bw, vmeta->alignment.padding_bottom);
|
|
|
|
success &= gst_byte_writer_put_uint32_le (&bw, vmeta->alignment.padding_left);
|
|
|
|
success &=
|
|
|
|
gst_byte_writer_put_uint32_le (&bw, vmeta->alignment.padding_right);
|
|
|
|
for (int n = 0; n < vmeta->n_planes; n++)
|
|
|
|
success &=
|
|
|
|
gst_byte_writer_put_uint32_le (&bw, vmeta->alignment.stride_align[n]);
|
|
|
|
g_assert (success);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstMeta *
|
|
|
|
video_meta_deserialize (const GstMetaInfo * info, GstBuffer * buffer,
|
|
|
|
const guint8 * data, gsize size, guint8 version)
|
|
|
|
{
|
|
|
|
GstVideoMeta *vmeta = NULL;
|
|
|
|
gint32 flags;
|
|
|
|
gint32 format;
|
|
|
|
guint width;
|
|
|
|
guint height;
|
|
|
|
guint n_planes;
|
|
|
|
GstVideoAlignment align;
|
|
|
|
guint64 offset64[GST_VIDEO_MAX_PLANES];
|
|
|
|
gint32 stride[GST_VIDEO_MAX_PLANES];
|
|
|
|
|
|
|
|
if (version != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GstByteReader br;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
gst_byte_reader_init (&br, data, size);
|
|
|
|
success &= gst_byte_reader_get_int32_le (&br, &flags);
|
|
|
|
success &= gst_byte_reader_get_int32_le (&br, &format);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &width);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &height);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &n_planes);
|
|
|
|
|
|
|
|
if (!success || n_planes > GST_VIDEO_MAX_PLANES)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (int n = 0; n < n_planes; n++)
|
|
|
|
success &= gst_byte_reader_get_uint64_le (&br, &offset64[n]);
|
|
|
|
for (int n = 0; n < n_planes; n++)
|
|
|
|
success &= gst_byte_reader_get_int32_le (&br, &stride[n]);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &align.padding_top);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &align.padding_bottom);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &align.padding_left);
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &align.padding_right);
|
|
|
|
for (int n = 0; n < n_planes; n++)
|
|
|
|
success &= gst_byte_reader_get_uint32_le (&br, &align.stride_align[n]);
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
#if GLIB_SIZEOF_SIZE_T != 8
|
|
|
|
gsize offset[GST_VIDEO_MAX_PLANES];
|
|
|
|
for (int i = 0; i < n_planes; i++) {
|
|
|
|
if (offset64[i] > G_MAXSIZE)
|
|
|
|
return NULL;
|
|
|
|
offset[i] = offset64[i];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
gsize *offset = (gsize *) offset64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vmeta =
|
|
|
|
gst_buffer_add_video_meta_full (buffer, flags, format, width, height,
|
|
|
|
n_planes, offset, stride);
|
|
|
|
gst_video_meta_set_alignment (vmeta, align);
|
|
|
|
|
|
|
|
return (GstMeta *) vmeta;
|
|
|
|
}
|
|
|
|
|
2011-04-28 17:20:58 +00:00
|
|
|
/* video metadata */
|
|
|
|
const GstMetaInfo *
|
2011-10-31 01:23:21 +00:00
|
|
|
gst_video_meta_get_info (void)
|
2011-04-28 17:20:58 +00:00
|
|
|
{
|
2011-10-31 01:23:21 +00:00
|
|
|
static const GstMetaInfo *video_meta_info = NULL;
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & video_meta_info)) {
|
2012-10-03 17:44:59 +00:00
|
|
|
const GstMetaInfo *meta =
|
2023-09-18 23:24:35 +00:00
|
|
|
gst_meta_register_serializable (GST_VIDEO_META_API_TYPE, "GstVideoMeta",
|
2016-04-13 07:07:33 +00:00
|
|
|
sizeof (GstVideoMeta), (GstMetaInitFunction) gst_video_meta_init,
|
2023-09-18 23:24:35 +00:00
|
|
|
(GstMetaFreeFunction) NULL, gst_video_meta_transform,
|
|
|
|
video_meta_serialize, video_meta_deserialize);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & video_meta_info,
|
|
|
|
(GstMetaInfo *) meta);
|
2011-04-28 17:20:58 +00:00
|
|
|
}
|
2011-10-31 01:23:21 +00:00
|
|
|
return video_meta_info;
|
2011-04-28 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 14:13:29 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_video_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Find the #GstVideoMeta on @buffer with the lowest @id.
|
|
|
|
*
|
|
|
|
* Buffers can contain multiple #GstVideoMeta metadata items when dealing with
|
|
|
|
* multiview buffers.
|
|
|
|
*
|
2022-10-14 18:59:43 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstVideoMeta with lowest id (usually 0) or %NULL when there
|
2014-10-08 14:13:29 +00:00
|
|
|
* is no such metadata on @buffer.
|
|
|
|
*/
|
|
|
|
GstVideoMeta *
|
|
|
|
gst_buffer_get_video_meta (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gpointer state = NULL;
|
|
|
|
GstVideoMeta *out = NULL;
|
|
|
|
GstMeta *meta;
|
|
|
|
const GstMetaInfo *info = GST_VIDEO_META_INFO;
|
|
|
|
|
|
|
|
while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
|
|
|
|
if (meta->info->api == info->api) {
|
|
|
|
GstVideoMeta *vmeta = (GstVideoMeta *) meta;
|
|
|
|
if (vmeta->id == 0)
|
|
|
|
return vmeta; /* Early out for id 0 */
|
|
|
|
if (out == NULL || vmeta->id < out->id)
|
|
|
|
out = vmeta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-08-24 11:52:20 +00:00
|
|
|
/**
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_buffer_get_video_meta_id:
|
2011-08-24 11:52:20 +00:00
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @id: a metadata id
|
|
|
|
*
|
2011-10-31 01:23:21 +00:00
|
|
|
* Find the #GstVideoMeta on @buffer with the given @id.
|
2011-08-24 11:52:20 +00:00
|
|
|
*
|
2011-10-31 01:23:21 +00:00
|
|
|
* Buffers can contain multiple #GstVideoMeta metadata items when dealing with
|
2011-08-24 11:52:20 +00:00
|
|
|
* multiview buffers.
|
|
|
|
*
|
2022-10-14 18:59:43 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstVideoMeta with @id or %NULL when there is no such metadata
|
2011-08-24 11:52:20 +00:00
|
|
|
* on @buffer.
|
|
|
|
*/
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *
|
|
|
|
gst_buffer_get_video_meta_id (GstBuffer * buffer, gint id)
|
2011-08-24 11:52:20 +00:00
|
|
|
{
|
|
|
|
gpointer state = NULL;
|
|
|
|
GstMeta *meta;
|
2011-10-31 01:23:21 +00:00
|
|
|
const GstMetaInfo *info = GST_VIDEO_META_INFO;
|
2011-08-24 11:52:20 +00:00
|
|
|
|
|
|
|
while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
|
|
|
|
if (meta->info->api == info->api) {
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *vmeta = (GstVideoMeta *) meta;
|
2011-08-24 11:52:20 +00:00
|
|
|
if (vmeta->id == id)
|
|
|
|
return vmeta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-23 15:28:29 +00:00
|
|
|
static gboolean
|
|
|
|
default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
|
|
|
|
gpointer * data, gint * stride, GstMapFlags flags)
|
|
|
|
{
|
2012-06-26 09:09:50 +00:00
|
|
|
guint idx, length;
|
|
|
|
gsize offset, skip;
|
2012-02-23 15:28:29 +00:00
|
|
|
GstBuffer *buffer = meta->buffer;
|
|
|
|
|
|
|
|
offset = meta->offset[plane];
|
|
|
|
|
2012-04-01 16:04:10 +00:00
|
|
|
/* find the memory block for this plane, this is the memory block containing
|
|
|
|
* the plane offset. FIXME use plane size */
|
|
|
|
if (!gst_buffer_find_memory (buffer, offset, 1, &idx, &length, &skip))
|
|
|
|
goto no_memory;
|
2012-02-23 15:28:29 +00:00
|
|
|
|
2012-04-01 16:04:10 +00:00
|
|
|
if (!gst_buffer_map_range (buffer, idx, length, info, flags))
|
|
|
|
goto cannot_map;
|
2012-02-23 15:28:29 +00:00
|
|
|
|
2012-04-01 16:04:10 +00:00
|
|
|
*stride = meta->stride[plane];
|
|
|
|
*data = (guint8 *) info->data + skip;
|
2012-02-23 15:28:29 +00:00
|
|
|
|
2012-04-01 16:04:10 +00:00
|
|
|
return TRUE;
|
2012-02-23 15:28:29 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_memory:
|
|
|
|
{
|
2018-10-15 14:15:46 +00:00
|
|
|
GST_ERROR ("plane %u, no memory at offset %" G_GSIZE_FORMAT, plane, offset);
|
2012-02-23 15:28:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
cannot_map:
|
|
|
|
{
|
2018-10-15 14:15:46 +00:00
|
|
|
GST_ERROR ("cannot map memory range %u-%u", idx, length);
|
2012-02-23 15:28:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
|
|
|
|
{
|
2012-04-01 16:04:10 +00:00
|
|
|
GstBuffer *buffer = meta->buffer;
|
|
|
|
|
|
|
|
gst_buffer_unmap (buffer, info);
|
2012-02-23 15:28:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-23 07:55:27 +00:00
|
|
|
/**
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_buffer_add_video_meta:
|
2011-06-23 07:55:27 +00:00
|
|
|
* @buffer: a #GstBuffer
|
2012-04-19 12:14:35 +00:00
|
|
|
* @flags: #GstVideoFrameFlags
|
2011-06-23 07:55:27 +00:00
|
|
|
* @format: a #GstVideoFormat
|
|
|
|
* @width: the width
|
|
|
|
* @height: the height
|
|
|
|
*
|
|
|
|
* Attaches GstVideoMeta metadata to @buffer with the given parameters and the
|
|
|
|
* default offsets and strides for @format and @width x @height.
|
|
|
|
*
|
|
|
|
* This function calculates the default offsets and strides and then calls
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_buffer_add_video_meta_full() with them.
|
2011-06-23 07:55:27 +00:00
|
|
|
*
|
2015-06-16 20:07:27 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoMeta on @buffer.
|
2011-06-23 07:55:27 +00:00
|
|
|
*/
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *
|
2012-04-19 10:03:19 +00:00
|
|
|
gst_buffer_add_video_meta (GstBuffer * buffer,
|
2012-04-19 12:14:35 +00:00
|
|
|
GstVideoFrameFlags flags, GstVideoFormat format, guint width, guint height)
|
2011-04-28 17:20:58 +00:00
|
|
|
{
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *meta;
|
2011-06-17 07:21:27 +00:00
|
|
|
GstVideoInfo info;
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2016-11-23 18:10:34 +00:00
|
|
|
if (!gst_video_info_set_format (&info, format, width, height))
|
|
|
|
return NULL;
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2012-04-19 10:03:19 +00:00
|
|
|
meta =
|
2012-04-19 12:14:35 +00:00
|
|
|
gst_buffer_add_video_meta_full (buffer, flags, format, width,
|
2012-04-19 10:03:19 +00:00
|
|
|
height, info.finfo->n_planes, info.offset, info.stride);
|
2011-04-28 17:20:58 +00:00
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
2011-06-23 07:55:27 +00:00
|
|
|
/**
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_buffer_add_video_meta_full:
|
2011-06-23 07:55:27 +00:00
|
|
|
* @buffer: a #GstBuffer
|
2012-04-19 12:14:35 +00:00
|
|
|
* @flags: #GstVideoFrameFlags
|
2011-06-23 07:55:27 +00:00
|
|
|
* @format: a #GstVideoFormat
|
|
|
|
* @width: the width
|
|
|
|
* @height: the height
|
|
|
|
* @n_planes: number of planes
|
2018-09-29 08:26:27 +00:00
|
|
|
* @offset: (array fixed-size=4): offset of each plane
|
|
|
|
* @stride: (array fixed-size=4): stride of each plane
|
2011-06-23 07:55:27 +00:00
|
|
|
*
|
|
|
|
* Attaches GstVideoMeta metadata to @buffer with the given parameters.
|
|
|
|
*
|
2015-06-16 20:07:27 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoMeta on @buffer.
|
2011-06-23 07:55:27 +00:00
|
|
|
*/
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *
|
2012-04-19 10:03:19 +00:00
|
|
|
gst_buffer_add_video_meta_full (GstBuffer * buffer,
|
2012-04-19 12:14:35 +00:00
|
|
|
GstVideoFrameFlags flags, GstVideoFormat format, guint width,
|
2023-09-18 23:24:35 +00:00
|
|
|
guint height, guint n_planes, const gsize offset[GST_VIDEO_MAX_PLANES],
|
|
|
|
const gint stride[GST_VIDEO_MAX_PLANES])
|
2011-04-28 17:20:58 +00:00
|
|
|
{
|
2011-10-31 01:23:21 +00:00
|
|
|
GstVideoMeta *meta;
|
2011-04-28 17:20:58 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
meta =
|
2011-10-31 01:23:21 +00:00
|
|
|
(GstVideoMeta *) gst_buffer_add_meta (buffer, GST_VIDEO_META_INFO, NULL);
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2013-04-11 17:25:51 +00:00
|
|
|
if (!meta)
|
|
|
|
return NULL;
|
|
|
|
|
2012-04-19 12:14:35 +00:00
|
|
|
meta->flags = flags;
|
2011-04-28 17:20:58 +00:00
|
|
|
meta->format = format;
|
2011-08-24 11:52:20 +00:00
|
|
|
meta->id = 0;
|
2011-04-28 17:20:58 +00:00
|
|
|
meta->width = width;
|
|
|
|
meta->height = height;
|
2011-06-17 15:44:56 +00:00
|
|
|
meta->buffer = buffer;
|
2011-04-28 17:20:58 +00:00
|
|
|
|
|
|
|
meta->n_planes = n_planes;
|
2011-06-20 09:25:58 +00:00
|
|
|
for (i = 0; i < n_planes; i++) {
|
|
|
|
meta->offset[i] = offset[i];
|
|
|
|
meta->stride[i] = stride[i];
|
2012-12-18 14:31:52 +00:00
|
|
|
GST_LOG ("plane %d, offset %" G_GSIZE_FORMAT ", stride %d", i, offset[i],
|
|
|
|
stride[i]);
|
2011-06-20 09:25:58 +00:00
|
|
|
}
|
2012-02-23 15:28:29 +00:00
|
|
|
meta->map = default_map;
|
|
|
|
meta->unmap = default_unmap;
|
2012-02-13 16:07:25 +00:00
|
|
|
|
2012-02-23 15:28:29 +00:00
|
|
|
return meta;
|
2011-04-28 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 07:55:27 +00:00
|
|
|
/**
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_video_meta_map:
|
2011-06-23 07:55:27 +00:00
|
|
|
* @meta: a #GstVideoMeta
|
|
|
|
* @plane: a plane
|
2012-01-20 15:11:54 +00:00
|
|
|
* @info: a #GstMapInfo
|
2018-04-20 19:53:16 +00:00
|
|
|
* @data: (out): the data of @plane
|
|
|
|
* @stride: (out): the stride of @plane
|
2011-06-23 07:55:27 +00:00
|
|
|
* @flags: @GstMapFlags
|
|
|
|
*
|
|
|
|
* Map the video plane with index @plane in @meta and return a pointer to the
|
|
|
|
* first byte of the plane and the stride of the plane.
|
|
|
|
*
|
2012-02-23 15:55:11 +00:00
|
|
|
* Returns: TRUE if the map operation was successful.
|
2011-06-23 07:55:27 +00:00
|
|
|
*/
|
2012-01-20 15:11:54 +00:00
|
|
|
gboolean
|
|
|
|
gst_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
|
2012-02-23 15:28:29 +00:00
|
|
|
gpointer * data, gint * stride, GstMapFlags flags)
|
2011-04-28 17:20:58 +00:00
|
|
|
{
|
2012-01-20 15:11:54 +00:00
|
|
|
g_return_val_if_fail (meta != NULL, FALSE);
|
2012-02-23 15:28:29 +00:00
|
|
|
g_return_val_if_fail (meta->map != NULL, FALSE);
|
2012-01-20 15:11:54 +00:00
|
|
|
g_return_val_if_fail (plane < meta->n_planes, FALSE);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2012-02-23 15:28:29 +00:00
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
2012-01-20 15:11:54 +00:00
|
|
|
g_return_val_if_fail (stride != NULL, FALSE);
|
2012-02-23 15:28:29 +00:00
|
|
|
g_return_val_if_fail (meta->buffer != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (!(flags & GST_MAP_WRITE)
|
|
|
|
|| gst_buffer_is_writable (meta->buffer), FALSE);
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2012-02-23 15:28:29 +00:00
|
|
|
return meta->map (meta, plane, info, data, stride, flags);
|
2011-04-28 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 07:55:27 +00:00
|
|
|
/**
|
2011-10-31 01:23:21 +00:00
|
|
|
* gst_video_meta_unmap:
|
2011-06-23 07:55:27 +00:00
|
|
|
* @meta: a #GstVideoMeta
|
|
|
|
* @plane: a plane
|
2012-01-20 15:11:54 +00:00
|
|
|
* @info: a #GstMapInfo
|
2011-06-23 07:55:27 +00:00
|
|
|
*
|
2012-01-19 08:17:07 +00:00
|
|
|
* Unmap a previously mapped plane with gst_video_meta_map().
|
2011-06-23 07:55:27 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE if the memory was successfully unmapped.
|
|
|
|
*/
|
2011-04-28 17:20:58 +00:00
|
|
|
gboolean
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
|
2011-04-28 17:20:58 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (meta != NULL, FALSE);
|
2012-02-23 15:28:29 +00:00
|
|
|
g_return_val_if_fail (meta->unmap != NULL, FALSE);
|
2011-04-28 17:20:58 +00:00
|
|
|
g_return_val_if_fail (plane < meta->n_planes, FALSE);
|
2012-01-20 15:11:54 +00:00
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2011-04-28 17:20:58 +00:00
|
|
|
|
2012-02-23 15:28:29 +00:00
|
|
|
return meta->unmap (meta, plane, info);
|
2011-04-28 17:20:58 +00:00
|
|
|
}
|
2011-06-23 07:30:19 +00:00
|
|
|
|
2023-05-19 07:20:16 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_meta_is_alignment_valid (GstVideoAlignment * align)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (align != NULL, FALSE);
|
|
|
|
|
|
|
|
if (align->padding_top != 0 || align->padding_bottom != 0 ||
|
|
|
|
align->padding_left != 0 || align->padding_right != 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
|
|
|
if (align->stride_align[i] != 0)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-07-09 10:17:44 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_meta_validate_alignment (GstVideoMeta * meta,
|
|
|
|
gsize plane_size[GST_VIDEO_MAX_PLANES])
|
|
|
|
{
|
|
|
|
GstVideoInfo info;
|
|
|
|
guint i;
|
|
|
|
|
2023-05-19 07:20:16 +00:00
|
|
|
if (!gst_video_meta_is_alignment_valid (&meta->alignment)) {
|
|
|
|
GST_LOG ("Set alignment on meta to all zero");
|
|
|
|
|
|
|
|
/* When alignment is invalid, no further check is needed,
|
|
|
|
unless user wants to calculate the pitch for each plane. */
|
|
|
|
if (!plane_size)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-07-09 10:17:44 +00:00
|
|
|
gst_video_info_init (&info);
|
|
|
|
gst_video_info_set_format (&info, meta->format, meta->width, meta->height);
|
|
|
|
|
|
|
|
if (!gst_video_info_align_full (&info, &meta->alignment, plane_size)) {
|
|
|
|
GST_WARNING ("Failed to align meta with its alignment");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
|
|
|
|
if (GST_VIDEO_INFO_PLANE_STRIDE (&info, i) != meta->stride[i]) {
|
|
|
|
GST_WARNING
|
|
|
|
("Stride of plane %d defined in meta (%d) is different from the one computed from the alignment (%d)",
|
|
|
|
i, meta->stride[i], GST_VIDEO_INFO_PLANE_STRIDE (&info, i));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_meta_set_alignment:
|
|
|
|
* @meta: a #GstVideoMeta
|
|
|
|
* @alignment: a #GstVideoAlignment
|
|
|
|
*
|
|
|
|
* Set the alignment of @meta to @alignment. This function checks that
|
|
|
|
* the paddings defined in @alignment are compatible with the strides
|
|
|
|
* defined in @meta and will fail to update if they are not.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @alignment's meta has been updated, %FALSE if not
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_meta_set_alignment (GstVideoMeta * meta, GstVideoAlignment alignment)
|
|
|
|
{
|
|
|
|
GstVideoAlignment old;
|
|
|
|
|
|
|
|
g_return_val_if_fail (meta, FALSE);
|
|
|
|
|
|
|
|
old = meta->alignment;
|
|
|
|
meta->alignment = alignment;
|
|
|
|
|
|
|
|
if (!gst_video_meta_validate_alignment (meta, NULL)) {
|
|
|
|
/* Invalid alignment, restore the previous one */
|
|
|
|
meta->alignment = old;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("Set alignment on meta: padding %u-%ux%u-%u", alignment.padding_top,
|
|
|
|
alignment.padding_left, alignment.padding_right,
|
|
|
|
alignment.padding_bottom);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_meta_get_plane_size:
|
|
|
|
* @meta: a #GstVideoMeta
|
2020-12-01 08:31:48 +00:00
|
|
|
* @plane_size: (out caller-allocates) (array fixed-size=4): array used to store the plane sizes
|
2019-07-09 10:17:44 +00:00
|
|
|
*
|
|
|
|
* Compute the size, in bytes, of each video plane described in @meta including
|
|
|
|
* any padding and alignment constraint defined in @meta->alignment.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @meta's alignment is valid and @plane_size has been
|
|
|
|
* updated, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_meta_get_plane_size (GstVideoMeta * meta,
|
|
|
|
gsize plane_size[GST_VIDEO_MAX_PLANES])
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (meta, FALSE);
|
|
|
|
g_return_val_if_fail (plane_size, FALSE);
|
|
|
|
|
|
|
|
return gst_video_meta_validate_alignment (meta, plane_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_meta_get_plane_height:
|
|
|
|
* @meta: a #GstVideoMeta
|
2020-12-01 08:31:48 +00:00
|
|
|
* @plane_height: (out caller-allocates) (array fixed-size=4): array used to store the plane height
|
2019-07-09 10:17:44 +00:00
|
|
|
*
|
|
|
|
* Compute the padded height of each plane from @meta (padded size
|
|
|
|
* divided by stride).
|
|
|
|
*
|
|
|
|
* It is not valid to call this function with a meta associated to a
|
|
|
|
* TILED video format.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @meta's alignment is valid and @plane_height has been
|
|
|
|
* updated, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_meta_get_plane_height (GstVideoMeta * meta,
|
|
|
|
guint plane_height[GST_VIDEO_MAX_PLANES])
|
|
|
|
{
|
|
|
|
gsize plane_size[GST_VIDEO_MAX_PLANES];
|
|
|
|
guint i;
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (meta, FALSE);
|
|
|
|
g_return_val_if_fail (plane_height, FALSE);
|
|
|
|
|
|
|
|
gst_video_info_init (&info);
|
|
|
|
gst_video_info_set_format (&info, meta->format, meta->width, meta->height);
|
|
|
|
g_return_val_if_fail (!GST_VIDEO_FORMAT_INFO_IS_TILED (&info), FALSE);
|
|
|
|
|
|
|
|
if (!gst_video_meta_get_plane_size (meta, plane_size))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < meta->n_planes; i++) {
|
|
|
|
if (!meta->stride[i])
|
|
|
|
plane_height[i] = 0;
|
|
|
|
else
|
|
|
|
plane_height[i] = plane_size[i] / meta->stride[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < GST_VIDEO_MAX_PLANES; i++)
|
|
|
|
plane_height[i] = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:18:30 +00:00
|
|
|
static gboolean
|
2012-02-24 09:26:04 +00:00
|
|
|
gst_video_crop_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
2011-12-01 14:45:28 +00:00
|
|
|
{
|
|
|
|
GstVideoCropMeta *dmeta, *smeta;
|
|
|
|
|
2012-02-24 09:26:04 +00:00
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
smeta = (GstVideoCropMeta *) meta;
|
|
|
|
dmeta = gst_buffer_add_video_crop_meta (dest);
|
2015-07-07 13:23:57 +00:00
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
2011-12-01 14:45:28 +00:00
|
|
|
|
2012-03-02 12:04:26 +00:00
|
|
|
GST_DEBUG ("copy crop metadata");
|
2012-02-24 09:26:04 +00:00
|
|
|
dmeta->x = smeta->x;
|
|
|
|
dmeta->y = smeta->y;
|
|
|
|
dmeta->width = smeta->width;
|
|
|
|
dmeta->height = smeta->height;
|
2012-03-02 12:04:26 +00:00
|
|
|
} else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
|
2012-03-06 11:52:01 +00:00
|
|
|
GstVideoMetaTransform *trans = data;
|
|
|
|
gint ow, oh, nw, nh;
|
|
|
|
|
|
|
|
smeta = (GstVideoCropMeta *) meta;
|
|
|
|
dmeta = gst_buffer_add_video_crop_meta (dest);
|
2015-07-07 13:23:57 +00:00
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
2012-03-06 11:52:01 +00:00
|
|
|
|
|
|
|
ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
|
|
|
|
nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
|
|
|
|
oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
|
|
|
|
nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
|
|
|
|
|
|
|
|
GST_DEBUG ("scaling crop metadata %dx%d -> %dx%d", ow, oh, nw, nh);
|
|
|
|
dmeta->x = (smeta->x * nw) / ow;
|
|
|
|
dmeta->y = (smeta->y * nh) / oh;
|
|
|
|
dmeta->width = (smeta->width * nw) / ow;
|
|
|
|
dmeta->height = (smeta->height * nh) / oh;
|
|
|
|
GST_DEBUG ("crop offset %dx%d -> %dx%d", smeta->x, smeta->y, dmeta->x,
|
|
|
|
dmeta->y);
|
|
|
|
GST_DEBUG ("crop size %dx%d -> %dx%d", smeta->width, smeta->height,
|
|
|
|
dmeta->width, dmeta->height);
|
2015-07-07 13:23:57 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
2012-02-24 09:26:04 +00:00
|
|
|
}
|
2012-02-28 15:18:30 +00:00
|
|
|
return TRUE;
|
2011-12-01 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 16:25:10 +00:00
|
|
|
GType
|
|
|
|
gst_video_crop_meta_api_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static GType type = 0;
|
2013-08-21 21:56:15 +00:00
|
|
|
static const gchar *tags[] =
|
|
|
|
{ GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_SIZE_STR,
|
|
|
|
GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
|
|
|
|
};
|
2012-02-29 16:25:10 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstVideoCropMetaAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2016-04-11 15:28:00 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_crop_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoCropMeta *emeta = (GstVideoCropMeta *) meta;
|
|
|
|
emeta->x = emeta->y = emeta->width = emeta->height = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-23 07:30:19 +00:00
|
|
|
const GstMetaInfo *
|
2011-10-31 01:23:21 +00:00
|
|
|
gst_video_crop_meta_get_info (void)
|
2011-06-23 07:30:19 +00:00
|
|
|
{
|
2011-10-31 01:23:21 +00:00
|
|
|
static const GstMetaInfo *video_crop_meta_info = NULL;
|
2011-06-23 07:30:19 +00:00
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & video_crop_meta_info)) {
|
2012-10-03 17:44:59 +00:00
|
|
|
const GstMetaInfo *meta =
|
2012-02-29 16:25:10 +00:00
|
|
|
gst_meta_register (GST_VIDEO_CROP_META_API_TYPE, "GstVideoCropMeta",
|
2016-04-11 15:28:00 +00:00
|
|
|
sizeof (GstVideoCropMeta),
|
|
|
|
(GstMetaInitFunction) gst_video_crop_meta_init,
|
2012-02-29 16:25:10 +00:00
|
|
|
(GstMetaFreeFunction) NULL, gst_video_crop_meta_transform);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & video_crop_meta_info,
|
|
|
|
(GstMetaInfo *) meta);
|
2011-06-23 07:30:19 +00:00
|
|
|
}
|
2011-10-31 01:23:21 +00:00
|
|
|
return video_crop_meta_info;
|
2011-06-23 07:30:19 +00:00
|
|
|
}
|
2012-03-02 12:04:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_meta_transform_scale_get_quark:
|
|
|
|
*
|
|
|
|
* Get the #GQuark for the "gst-video-scale" metadata transform operation.
|
|
|
|
*
|
|
|
|
* Returns: a #GQuark
|
|
|
|
*/
|
|
|
|
GQuark
|
|
|
|
gst_video_meta_transform_scale_get_quark (void)
|
|
|
|
{
|
|
|
|
static GQuark _value = 0;
|
|
|
|
|
|
|
|
if (_value == 0) {
|
|
|
|
_value = g_quark_from_static_string ("gst-video-scale");
|
|
|
|
}
|
|
|
|
return _value;
|
|
|
|
}
|
2013-03-29 13:46:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_video_gl_texture_upload_meta_api_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static GType type = 0;
|
2013-08-21 21:56:15 +00:00
|
|
|
static const gchar *tags[] =
|
|
|
|
{ GST_META_TAG_VIDEO_STR, GST_META_TAG_MEMORY_STR, NULL };
|
2013-03-29 13:46:00 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type =
|
|
|
|
gst_meta_api_type_register ("GstVideoGLTextureUploadMetaAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2016-04-13 07:07:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_gl_texture_upload_meta_init (GstMeta * meta, gpointer params,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
|
|
|
|
|
|
|
|
vmeta->texture_orientation =
|
|
|
|
GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;
|
|
|
|
vmeta->n_textures = 0;
|
|
|
|
memset (vmeta->texture_type, 0, sizeof (vmeta->texture_type));
|
|
|
|
vmeta->buffer = NULL;
|
|
|
|
vmeta->upload = NULL;
|
|
|
|
vmeta->user_data = NULL;
|
|
|
|
vmeta->user_data_copy = NULL;
|
|
|
|
vmeta->user_data_free = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-29 13:46:00 +00:00
|
|
|
static void
|
|
|
|
gst_video_gl_texture_upload_meta_free (GstMeta * meta, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoGLTextureUploadMeta *vmeta = (GstVideoGLTextureUploadMeta *) meta;
|
|
|
|
|
2013-03-29 15:37:01 +00:00
|
|
|
if (vmeta->user_data_free)
|
|
|
|
vmeta->user_data_free (vmeta->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_gl_texture_upload_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
|
|
|
{
|
|
|
|
GstVideoGLTextureUploadMeta *dmeta, *smeta;
|
|
|
|
|
|
|
|
smeta = (GstVideoGLTextureUploadMeta *) meta;
|
|
|
|
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
GstMetaTransformCopy *copy = data;
|
|
|
|
|
|
|
|
if (!copy->region) {
|
|
|
|
/* only copy if the complete data is copied as well */
|
|
|
|
dmeta =
|
|
|
|
(GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (dest,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
|
2013-04-11 17:25:51 +00:00
|
|
|
|
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-17 08:35:22 +00:00
|
|
|
dmeta->texture_orientation = smeta->texture_orientation;
|
|
|
|
dmeta->n_textures = smeta->n_textures;
|
|
|
|
memcpy (dmeta->texture_type, smeta->texture_type,
|
2014-04-10 11:10:47 +00:00
|
|
|
sizeof (smeta->texture_type[0]) * 4);
|
2013-03-29 15:37:01 +00:00
|
|
|
dmeta->buffer = dest;
|
|
|
|
dmeta->upload = smeta->upload;
|
|
|
|
dmeta->user_data = smeta->user_data;
|
|
|
|
dmeta->user_data_copy = smeta->user_data_copy;
|
|
|
|
dmeta->user_data_free = smeta->user_data_free;
|
|
|
|
if (dmeta->user_data_copy)
|
|
|
|
dmeta->user_data = dmeta->user_data_copy (dmeta->user_data);
|
|
|
|
}
|
2015-07-07 13:23:57 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
2013-03-29 15:37:01 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2013-03-29 13:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const GstMetaInfo *
|
|
|
|
gst_video_gl_texture_upload_meta_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *info = NULL;
|
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & info)) {
|
2013-03-29 13:46:00 +00:00
|
|
|
const GstMetaInfo *meta =
|
|
|
|
gst_meta_register (GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE,
|
|
|
|
"GstVideoGLTextureUploadMeta",
|
|
|
|
sizeof (GstVideoGLTextureUploadMeta),
|
2016-04-13 07:07:33 +00:00
|
|
|
gst_video_gl_texture_upload_meta_init,
|
2013-03-29 13:46:00 +00:00
|
|
|
gst_video_gl_texture_upload_meta_free,
|
2013-03-29 15:37:01 +00:00
|
|
|
gst_video_gl_texture_upload_meta_transform);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta);
|
2013-03-29 13:46:00 +00:00
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-29 15:55:56 +00:00
|
|
|
* gst_buffer_add_video_gl_texture_upload_meta:
|
2013-03-29 13:46:00 +00:00
|
|
|
* @buffer: a #GstBuffer
|
2015-06-16 20:07:27 +00:00
|
|
|
* @texture_orientation: the #GstVideoGLTextureOrientation
|
|
|
|
* @n_textures: the number of textures
|
|
|
|
* @texture_type: array of #GstVideoGLTextureType
|
|
|
|
* @upload: (scope call): the function to upload the buffer to a specific texture ID
|
2013-03-29 15:55:56 +00:00
|
|
|
* @user_data: user data for the implementor of @upload
|
2015-06-16 20:07:27 +00:00
|
|
|
* @user_data_copy: (scope call): function to copy @user_data
|
|
|
|
* @user_data_free: (scope call): function to free @user_data
|
2013-03-29 13:46:00 +00:00
|
|
|
*
|
2013-03-29 15:55:56 +00:00
|
|
|
* Attaches GstVideoGLTextureUploadMeta metadata to @buffer with the given
|
|
|
|
* parameters.
|
2013-03-29 13:46:00 +00:00
|
|
|
*
|
2015-06-16 20:07:27 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoGLTextureUploadMeta on @buffer.
|
2013-03-29 13:46:00 +00:00
|
|
|
*/
|
|
|
|
GstVideoGLTextureUploadMeta *
|
|
|
|
gst_buffer_add_video_gl_texture_upload_meta (GstBuffer * buffer,
|
2013-04-17 08:35:22 +00:00
|
|
|
GstVideoGLTextureOrientation texture_orientation, guint n_textures,
|
|
|
|
GstVideoGLTextureType texture_type[4], GstVideoGLTextureUpload upload,
|
|
|
|
gpointer user_data, GBoxedCopyFunc user_data_copy,
|
|
|
|
GBoxedFreeFunc user_data_free)
|
2013-03-29 13:46:00 +00:00
|
|
|
{
|
|
|
|
GstVideoGLTextureUploadMeta *meta;
|
|
|
|
|
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
|
|
|
g_return_val_if_fail (upload != NULL, NULL);
|
2013-04-17 08:35:22 +00:00
|
|
|
g_return_val_if_fail (n_textures > 0 && n_textures < 5, NULL);
|
2013-03-29 13:46:00 +00:00
|
|
|
|
|
|
|
meta =
|
|
|
|
(GstVideoGLTextureUploadMeta *) gst_buffer_add_meta (buffer,
|
|
|
|
GST_VIDEO_GL_TEXTURE_UPLOAD_META_INFO, NULL);
|
|
|
|
|
2013-04-11 17:25:51 +00:00
|
|
|
if (!meta)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-17 08:35:22 +00:00
|
|
|
meta->texture_orientation = texture_orientation;
|
|
|
|
meta->n_textures = n_textures;
|
2014-04-10 11:10:47 +00:00
|
|
|
memcpy (meta->texture_type, texture_type, sizeof (texture_type[0]) * 4);
|
2013-03-29 13:46:00 +00:00
|
|
|
meta->buffer = buffer;
|
|
|
|
meta->upload = upload;
|
|
|
|
meta->user_data = user_data;
|
2013-03-29 15:37:01 +00:00
|
|
|
meta->user_data_copy = user_data_copy;
|
|
|
|
meta->user_data_free = user_data_free;
|
2013-03-29 13:46:00 +00:00
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
2013-03-29 15:55:56 +00:00
|
|
|
/**
|
|
|
|
* gst_video_gl_texture_upload_meta_upload:
|
|
|
|
* @meta: a #GstVideoGLTextureUploadMeta
|
2013-04-17 08:35:22 +00:00
|
|
|
* @texture_id: the texture IDs to upload to
|
2013-03-29 15:55:56 +00:00
|
|
|
*
|
|
|
|
* Uploads the buffer which owns the meta to a specific texture ID.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if uploading succeeded, %FALSE otherwise.
|
|
|
|
*/
|
2013-03-29 13:46:00 +00:00
|
|
|
gboolean
|
|
|
|
gst_video_gl_texture_upload_meta_upload (GstVideoGLTextureUploadMeta * meta,
|
2013-04-17 08:35:22 +00:00
|
|
|
guint texture_id[4])
|
2013-03-29 13:46:00 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (meta != NULL, FALSE);
|
|
|
|
|
2013-04-17 08:35:22 +00:00
|
|
|
return meta->upload (meta, texture_id);
|
2013-03-29 13:46:00 +00:00
|
|
|
}
|
2013-07-16 08:04:00 +00:00
|
|
|
|
|
|
|
/* Region of Interest Meta implementation *******************************************/
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_video_region_of_interest_meta_api_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static GType type;
|
2013-08-21 21:56:15 +00:00
|
|
|
static const gchar *tags[] =
|
|
|
|
{ GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
|
|
|
|
GST_META_TAG_VIDEO_SIZE_STR, NULL
|
|
|
|
};
|
2013-07-16 08:04:00 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type =
|
|
|
|
gst_meta_api_type_register ("GstVideoRegionOfInterestMetaAPI", tags);
|
|
|
|
GST_INFO ("registering");
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_region_of_interest_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
|
|
|
{
|
|
|
|
GstVideoRegionOfInterestMeta *dmeta, *smeta;
|
|
|
|
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
smeta = (GstVideoRegionOfInterestMeta *) meta;
|
|
|
|
|
|
|
|
GST_DEBUG ("copy region of interest metadata");
|
|
|
|
dmeta =
|
2013-07-16 08:09:27 +00:00
|
|
|
gst_buffer_add_video_region_of_interest_meta_id (dest,
|
2013-07-16 08:04:00 +00:00
|
|
|
smeta->roi_type, smeta->x, smeta->y, smeta->w, smeta->h);
|
2015-07-07 13:23:57 +00:00
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-16 08:04:00 +00:00
|
|
|
dmeta->id = smeta->id;
|
|
|
|
dmeta->parent_id = smeta->parent_id;
|
2018-02-27 15:48:23 +00:00
|
|
|
dmeta->params = g_list_copy_deep (smeta->params,
|
|
|
|
(GCopyFunc) gst_structure_copy, NULL);
|
2013-07-16 08:04:00 +00:00
|
|
|
} else if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
|
|
|
|
GstVideoMetaTransform *trans = data;
|
|
|
|
gint ow, oh, nw, nh;
|
|
|
|
ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
|
|
|
|
nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
|
|
|
|
oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
|
|
|
|
nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
|
|
|
|
GST_DEBUG ("scaling region of interest metadata %dx%d -> %dx%d", ow, oh, nw,
|
|
|
|
nh);
|
|
|
|
|
|
|
|
smeta = (GstVideoRegionOfInterestMeta *) meta;
|
|
|
|
dmeta =
|
2013-07-16 08:09:27 +00:00
|
|
|
gst_buffer_add_video_region_of_interest_meta_id (dest,
|
2013-07-16 08:04:00 +00:00
|
|
|
smeta->roi_type, (smeta->x * nw) / ow, (smeta->y * nh) / oh,
|
|
|
|
(smeta->w * nw) / ow, (smeta->h * nh) / oh);
|
2015-07-07 13:23:57 +00:00
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-16 08:04:00 +00:00
|
|
|
dmeta->id = smeta->id;
|
|
|
|
dmeta->parent_id = smeta->parent_id;
|
|
|
|
|
|
|
|
GST_DEBUG ("region of interest (id:%d, parent id:%d) offset %dx%d -> %dx%d",
|
|
|
|
smeta->id, smeta->parent_id, smeta->x, smeta->y, dmeta->x, dmeta->y);
|
|
|
|
GST_DEBUG ("region of interest size %dx%d -> %dx%d", smeta->w, smeta->h,
|
|
|
|
dmeta->w, dmeta->h);
|
2015-07-07 13:23:57 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
2013-07-16 08:04:00 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_region_of_interest_meta_init (GstMeta * meta, gpointer params,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
|
2016-04-13 07:07:33 +00:00
|
|
|
emeta->roi_type = 0;
|
2013-07-16 08:04:00 +00:00
|
|
|
emeta->id = 0;
|
|
|
|
emeta->parent_id = 0;
|
|
|
|
emeta->x = emeta->y = emeta->w = emeta->h = 0;
|
2018-02-09 13:45:08 +00:00
|
|
|
emeta->params = NULL;
|
2013-07-16 08:04:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_region_of_interest_meta_free (GstMeta * meta, GstBuffer * buffer)
|
|
|
|
{
|
2018-02-09 13:45:08 +00:00
|
|
|
GstVideoRegionOfInterestMeta *emeta = (GstVideoRegionOfInterestMeta *) meta;
|
|
|
|
|
|
|
|
g_list_free_full (emeta->params, (GDestroyNotify) gst_structure_free);
|
2013-07-16 08:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const GstMetaInfo *
|
|
|
|
gst_video_region_of_interest_meta_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *meta_info = NULL;
|
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
|
2013-07-16 08:04:00 +00:00
|
|
|
const GstMetaInfo *mi =
|
|
|
|
gst_meta_register (GST_VIDEO_REGION_OF_INTEREST_META_API_TYPE,
|
|
|
|
"GstVideoRegionOfInterestMeta",
|
|
|
|
sizeof (GstVideoRegionOfInterestMeta),
|
|
|
|
gst_video_region_of_interest_meta_init,
|
|
|
|
gst_video_region_of_interest_meta_free,
|
|
|
|
gst_video_region_of_interest_meta_transform);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
|
2013-07-16 08:04:00 +00:00
|
|
|
}
|
|
|
|
return meta_info;
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:42:48 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_get_video_region_of_interest_meta_id:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @id: a metadata id
|
|
|
|
*
|
|
|
|
* Find the #GstVideoRegionOfInterestMeta on @buffer with the given @id.
|
|
|
|
*
|
|
|
|
* Buffers can contain multiple #GstVideoRegionOfInterestMeta metadata items if
|
|
|
|
* multiple regions of interests are marked on a frame.
|
|
|
|
*
|
2022-10-14 18:59:43 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstVideoRegionOfInterestMeta with @id or %NULL when there is
|
2013-07-17 09:42:48 +00:00
|
|
|
* no such metadata on @buffer.
|
|
|
|
*/
|
2013-07-16 08:04:00 +00:00
|
|
|
GstVideoRegionOfInterestMeta *
|
|
|
|
gst_buffer_get_video_region_of_interest_meta_id (GstBuffer * buffer, gint id)
|
|
|
|
{
|
|
|
|
gpointer state = NULL;
|
|
|
|
GstMeta *meta;
|
2013-07-16 14:54:10 +00:00
|
|
|
const GstMetaInfo *info = GST_VIDEO_REGION_OF_INTEREST_META_INFO;
|
2013-07-16 08:04:00 +00:00
|
|
|
|
|
|
|
while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
|
|
|
|
if (meta->info->api == info->api) {
|
|
|
|
GstVideoRegionOfInterestMeta *vmeta =
|
|
|
|
(GstVideoRegionOfInterestMeta *) meta;
|
|
|
|
if (vmeta->id == id)
|
|
|
|
return vmeta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:42:48 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_add_video_region_of_interest_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @roi_type: Type of the region of interest (e.g. "face")
|
|
|
|
* @x: X position
|
|
|
|
* @y: Y position
|
|
|
|
* @w: width
|
|
|
|
* @h: height
|
|
|
|
*
|
|
|
|
* Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
|
|
|
|
* parameters.
|
|
|
|
*
|
2015-06-16 20:07:27 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
|
2013-07-17 09:42:48 +00:00
|
|
|
*/
|
2013-07-16 08:04:00 +00:00
|
|
|
GstVideoRegionOfInterestMeta *
|
2013-07-16 08:09:27 +00:00
|
|
|
gst_buffer_add_video_region_of_interest_meta (GstBuffer * buffer,
|
2013-07-16 08:04:00 +00:00
|
|
|
const gchar * roi_type, guint x, guint y, guint w, guint h)
|
|
|
|
{
|
2013-07-16 08:09:27 +00:00
|
|
|
return gst_buffer_add_video_region_of_interest_meta_id (buffer,
|
2013-07-16 08:04:00 +00:00
|
|
|
g_quark_from_string (roi_type), x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:42:48 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_add_video_region_of_interest_meta_id:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @roi_type: Type of the region of interest (e.g. "face")
|
|
|
|
* @x: X position
|
|
|
|
* @y: Y position
|
|
|
|
* @w: width
|
|
|
|
* @h: height
|
|
|
|
*
|
|
|
|
* Attaches #GstVideoRegionOfInterestMeta metadata to @buffer with the given
|
|
|
|
* parameters.
|
|
|
|
*
|
2015-06-16 20:07:27 +00:00
|
|
|
* Returns: (transfer none): the #GstVideoRegionOfInterestMeta on @buffer.
|
2013-07-17 09:42:48 +00:00
|
|
|
*/
|
2013-07-16 08:04:00 +00:00
|
|
|
GstVideoRegionOfInterestMeta *
|
2013-07-16 08:09:27 +00:00
|
|
|
gst_buffer_add_video_region_of_interest_meta_id (GstBuffer * buffer,
|
2013-07-16 08:04:00 +00:00
|
|
|
GQuark roi_type, guint x, guint y, guint w, guint h)
|
|
|
|
{
|
|
|
|
GstVideoRegionOfInterestMeta *meta;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
|
|
|
|
|
|
|
meta = (GstVideoRegionOfInterestMeta *) gst_buffer_add_meta (buffer,
|
|
|
|
GST_VIDEO_REGION_OF_INTEREST_META_INFO, NULL);
|
|
|
|
meta->roi_type = roi_type;
|
|
|
|
meta->x = x;
|
|
|
|
meta->y = y;
|
|
|
|
meta->w = w;
|
|
|
|
meta->h = h;
|
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|
2016-05-14 14:59:20 +00:00
|
|
|
|
2018-02-09 13:45:08 +00:00
|
|
|
/**
|
|
|
|
* gst_video_region_of_interest_meta_add_param:
|
|
|
|
* @meta: a #GstVideoRegionOfInterestMeta
|
|
|
|
* @s: (transfer full): a #GstStructure
|
|
|
|
*
|
|
|
|
* Attach element-specific parameters to @meta meant to be used by downstream
|
|
|
|
* elements which may handle this ROI.
|
|
|
|
* The name of @s is used to identify the element these parameters are meant for.
|
|
|
|
*
|
|
|
|
* This is typically used to tell encoders how they should encode this specific region.
|
|
|
|
* For example, a structure named "roi/x264enc" could be used to give the
|
|
|
|
* QP offsets this encoder should use when encoding the region described in @meta.
|
|
|
|
* Multiple parameters can be defined for the same meta so different encoders
|
|
|
|
* can be supported by cross platform applications).
|
|
|
|
*
|
|
|
|
* Since: 1.14
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_video_region_of_interest_meta_add_param (GstVideoRegionOfInterestMeta *
|
|
|
|
meta, GstStructure * s)
|
|
|
|
{
|
|
|
|
g_return_if_fail (meta);
|
|
|
|
g_return_if_fail (s);
|
|
|
|
|
|
|
|
meta->params = g_list_append (meta->params, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_region_of_interest_meta_get_param:
|
|
|
|
* @meta: a #GstVideoRegionOfInterestMeta
|
2018-04-02 06:34:58 +00:00
|
|
|
* @name: a name.
|
2018-02-09 13:45:08 +00:00
|
|
|
*
|
|
|
|
* Retrieve the parameter for @meta having @name as structure name,
|
|
|
|
* or %NULL if there is none.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): a #GstStructure
|
|
|
|
*
|
|
|
|
* Since: 1.14
|
2018-02-22 21:11:20 +00:00
|
|
|
* See also: gst_video_region_of_interest_meta_add_param()
|
2018-02-09 13:45:08 +00:00
|
|
|
*/
|
|
|
|
GstStructure *
|
|
|
|
gst_video_region_of_interest_meta_get_param (GstVideoRegionOfInterestMeta *
|
|
|
|
meta, const gchar * name)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (meta, NULL);
|
|
|
|
g_return_val_if_fail (name, NULL);
|
|
|
|
|
|
|
|
for (l = meta->params; l; l = g_list_next (l)) {
|
|
|
|
GstStructure *s = l->data;
|
|
|
|
|
|
|
|
if (gst_structure_has_name (s, name))
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-14 14:59:20 +00:00
|
|
|
/* Time Code Meta implementation *******************************************/
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_video_time_code_meta_api_get_type (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static GType type;
|
2016-05-14 14:59:20 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
static const gchar *tags[] = { NULL };
|
|
|
|
GType _type = gst_meta_api_type_register ("GstVideoTimeCodeMetaAPI", tags);
|
|
|
|
GST_INFO ("registering");
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_time_code_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
|
|
|
{
|
|
|
|
GstVideoTimeCodeMeta *dmeta, *smeta;
|
|
|
|
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
smeta = (GstVideoTimeCodeMeta *) meta;
|
|
|
|
|
|
|
|
GST_DEBUG ("copy time code metadata");
|
|
|
|
dmeta =
|
|
|
|
gst_buffer_add_video_time_code_meta_full (dest, smeta->tc.config.fps_n,
|
|
|
|
smeta->tc.config.fps_d, smeta->tc.config.latest_daily_jam,
|
|
|
|
smeta->tc.config.flags, smeta->tc.hours, smeta->tc.minutes,
|
|
|
|
smeta->tc.seconds, smeta->tc.frames, smeta->tc.field_count);
|
|
|
|
if (!dmeta)
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_video_time_code_meta_init (GstMeta * meta, gpointer params,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
|
|
|
|
memset (&emeta->tc, 0, sizeof (emeta->tc));
|
|
|
|
gst_video_time_code_clear (&emeta->tc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_video_time_code_meta_free (GstMeta * meta, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoTimeCodeMeta *emeta = (GstVideoTimeCodeMeta *) meta;
|
|
|
|
|
|
|
|
gst_video_time_code_clear (&emeta->tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GstMetaInfo *
|
|
|
|
gst_video_time_code_meta_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *meta_info = NULL;
|
|
|
|
|
2016-11-15 00:48:16 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & meta_info)) {
|
2016-05-14 14:59:20 +00:00
|
|
|
const GstMetaInfo *mi =
|
|
|
|
gst_meta_register (GST_VIDEO_TIME_CODE_META_API_TYPE,
|
|
|
|
"GstVideoTimeCodeMeta",
|
|
|
|
sizeof (GstVideoTimeCodeMeta),
|
|
|
|
gst_video_time_code_meta_init,
|
|
|
|
gst_video_time_code_meta_free,
|
|
|
|
gst_video_time_code_meta_transform);
|
2016-11-15 00:48:16 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & meta_info, (GstMetaInfo *) mi);
|
2016-05-14 14:59:20 +00:00
|
|
|
}
|
|
|
|
return meta_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_add_video_time_code_meta:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @tc: a #GstVideoTimeCode
|
|
|
|
*
|
|
|
|
* Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
|
|
|
|
* parameters.
|
|
|
|
*
|
2019-04-08 19:52:52 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstVideoTimeCodeMeta on @buffer, or
|
2019-04-03 15:34:00 +00:00
|
|
|
* (since 1.16) %NULL if the timecode was invalid.
|
2016-05-14 14:59:20 +00:00
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
GstVideoTimeCodeMeta *
|
2020-03-16 04:32:47 +00:00
|
|
|
gst_buffer_add_video_time_code_meta (GstBuffer * buffer,
|
|
|
|
const GstVideoTimeCode * tc)
|
2016-05-14 14:59:20 +00:00
|
|
|
{
|
2019-04-03 15:34:00 +00:00
|
|
|
if (!gst_video_time_code_is_valid (tc))
|
|
|
|
return NULL;
|
|
|
|
|
2016-05-14 14:59:20 +00:00
|
|
|
return gst_buffer_add_video_time_code_meta_full (buffer, tc->config.fps_n,
|
|
|
|
tc->config.fps_d, tc->config.latest_daily_jam, tc->config.flags,
|
|
|
|
tc->hours, tc->minutes, tc->seconds, tc->frames, tc->field_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_add_video_time_code_meta_full:
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
* @fps_n: framerate numerator
|
|
|
|
* @fps_d: framerate denominator
|
|
|
|
* @latest_daily_jam: a #GDateTime for the latest daily jam
|
|
|
|
* @flags: a #GstVideoTimeCodeFlags
|
|
|
|
* @hours: hours since the daily jam
|
|
|
|
* @minutes: minutes since the daily jam
|
|
|
|
* @seconds: seconds since the daily jam
|
|
|
|
* @frames: frames since the daily jam
|
|
|
|
* @field_count: fields since the daily jam
|
|
|
|
*
|
|
|
|
* Attaches #GstVideoTimeCodeMeta metadata to @buffer with the given
|
|
|
|
* parameters.
|
|
|
|
*
|
2022-10-14 18:59:43 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstVideoTimeCodeMeta on @buffer, or
|
2019-04-03 15:34:00 +00:00
|
|
|
* (since 1.16) %NULL if the timecode was invalid.
|
2016-05-14 14:59:20 +00:00
|
|
|
*
|
|
|
|
* Since: 1.10
|
|
|
|
*/
|
|
|
|
GstVideoTimeCodeMeta *
|
|
|
|
gst_buffer_add_video_time_code_meta_full (GstBuffer * buffer, guint fps_n,
|
|
|
|
guint fps_d, GDateTime * latest_daily_jam, GstVideoTimeCodeFlags flags,
|
|
|
|
guint hours, guint minutes, guint seconds, guint frames, guint field_count)
|
|
|
|
{
|
|
|
|
GstVideoTimeCodeMeta *meta;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
|
|
|
|
|
|
|
meta = (GstVideoTimeCodeMeta *) gst_buffer_add_meta (buffer,
|
|
|
|
GST_VIDEO_TIME_CODE_META_INFO, NULL);
|
2017-07-24 13:29:53 +00:00
|
|
|
g_return_val_if_fail (meta != NULL, NULL);
|
|
|
|
|
2016-05-14 14:59:20 +00:00
|
|
|
gst_video_time_code_init (&meta->tc, fps_n, fps_d, latest_daily_jam, flags,
|
|
|
|
hours, minutes, seconds, frames, field_count);
|
|
|
|
|
2019-04-03 15:34:00 +00:00
|
|
|
if (!gst_video_time_code_is_valid (&meta->tc)) {
|
|
|
|
gst_buffer_remove_meta (buffer, (GstMeta *) meta);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-05-14 14:59:20 +00:00
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|