2009-12-17 11:34:42 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
2011-02-25 12:15:25 +00:00
|
|
|
* unit test for GstMeta
|
2009-12-17 11:34:42 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) <2009> 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 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-12-17 11:34:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
/* test metadata for PTS/DTS and duration */
|
|
|
|
typedef struct
|
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMeta meta;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
GstClockTime pts;
|
|
|
|
GstClockTime dts;
|
|
|
|
GstClockTime duration;
|
|
|
|
GstClockTime clock_rate;
|
2011-02-28 08:39:44 +00:00
|
|
|
} GstMetaTest;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
static GType gst_meta_test_api_get_type (void);
|
|
|
|
#define GST_META_TEST_API_TYPE (gst_meta_test_api_get_type())
|
|
|
|
|
2011-02-28 08:39:44 +00:00
|
|
|
static const GstMetaInfo *gst_meta_test_get_info (void);
|
|
|
|
#define GST_META_TEST_INFO (gst_meta_test_get_info())
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
#define GST_META_TEST_GET(buf) ((GstMetaTest *)gst_buffer_get_meta(buf,GST_META_TEST_API_TYPE))
|
2011-02-28 08:39:44 +00:00
|
|
|
#define GST_META_TEST_ADD(buf) ((GstMetaTest *)gst_buffer_add_meta(buf,GST_META_TEST_INFO,NULL))
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2016-12-14 18:19:00 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstMeta meta;
|
|
|
|
} GstMetaFoo;
|
|
|
|
|
|
|
|
static GType gst_meta_foo_api_get_type (void);
|
|
|
|
#define GST_META_FOO_API_TYPE (gst_meta_foo_api_get_type())
|
|
|
|
|
|
|
|
static const GstMetaInfo *gst_meta_foo_get_info (void);
|
|
|
|
#define GST_META_FOO_INFO (gst_meta_foo_get_info())
|
|
|
|
|
|
|
|
#define GST_META_FOO_GET(buf) ((GstMetaFoo *)gst_buffer_get_meta(buf,GST_META_FOO_API_TYPE))
|
|
|
|
#define GST_META_FOO_ADD(buf) ((GstMetaFoo *)gst_buffer_add_meta(buf,GST_META_FOO_INFO,NULL))
|
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
#if 0
|
|
|
|
/* unused currently. This is a user function to fill the metadata with default
|
|
|
|
* values. We don't call this from the init function because the user is mostly
|
|
|
|
* likely going to override the values immediately after */
|
|
|
|
static void
|
2011-02-28 08:39:44 +00:00
|
|
|
gst_meta_test_init (GstMetaTest * meta)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
|
|
|
meta->pts = GST_CLOCK_TIME_NONE;
|
|
|
|
meta->dts = GST_CLOCK_TIME_NONE;
|
|
|
|
meta->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
meta->clock_rate = GST_SECOND;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-28 15:17:47 +00:00
|
|
|
static gboolean
|
|
|
|
test_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG ("init called on buffer %p, meta %p", buffer, meta);
|
|
|
|
/* nothing to init really, the init function is mostly for allocating
|
|
|
|
* additional memory or doing special setup as part of adding the metadata to
|
|
|
|
* the buffer*/
|
2012-02-28 15:17:47 +00:00
|
|
|
return TRUE;
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-28 15:17:47 +00:00
|
|
|
test_free_func (GstMeta * meta, GstBuffer * buffer)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG ("free called on buffer %p, meta %p", buffer, meta);
|
|
|
|
/* nothing to free really */
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:17:47 +00:00
|
|
|
static gboolean
|
|
|
|
test_transform_func (GstBuffer * transbuf, GstMeta * meta,
|
2012-02-24 09:23:27 +00:00
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
2012-02-28 15:17:47 +00:00
|
|
|
GstMetaTest *test, *tmeta = (GstMetaTest *) meta;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
2012-02-24 09:23:27 +00:00
|
|
|
GST_DEBUG ("transform %s called from buffer %p to %p, meta %p",
|
|
|
|
g_quark_to_string (type), buffer, transbuf, meta);
|
|
|
|
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
GstMetaTransformCopy *copy_data = data;
|
|
|
|
|
|
|
|
test = GST_META_TEST_ADD (transbuf);
|
2012-03-02 12:02:37 +00:00
|
|
|
|
2012-02-24 09:23:27 +00:00
|
|
|
if (copy_data->offset == 0) {
|
|
|
|
/* same offset, copy timestamps */
|
2012-02-28 15:17:47 +00:00
|
|
|
test->pts = tmeta->pts;
|
|
|
|
test->dts = tmeta->dts;
|
2012-03-02 12:02:37 +00:00
|
|
|
if (!copy_data->region) {
|
|
|
|
fail_unless (gst_buffer_get_size (buffer) == copy_data->size);
|
2012-02-24 09:23:27 +00:00
|
|
|
/* same size, copy duration */
|
2012-02-28 15:17:47 +00:00
|
|
|
test->duration = tmeta->duration;
|
2012-02-24 09:23:27 +00:00
|
|
|
} else {
|
2012-03-02 12:02:37 +00:00
|
|
|
fail_unless (gst_buffer_get_size (buffer) > copy_data->size);
|
2012-02-24 09:23:27 +00:00
|
|
|
/* else clear */
|
|
|
|
test->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2009-12-17 11:34:42 +00:00
|
|
|
} else {
|
2012-03-02 12:02:37 +00:00
|
|
|
fail_unless (copy_data->region == TRUE);
|
2012-02-24 09:23:27 +00:00
|
|
|
test->pts = -1;
|
|
|
|
test->dts = -1;
|
|
|
|
test->duration = -1;
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
2012-02-28 15:17:47 +00:00
|
|
|
test->clock_rate = tmeta->clock_rate;
|
2015-07-07 01:46:48 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
2012-02-28 15:17:47 +00:00
|
|
|
return TRUE;
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
static GType
|
|
|
|
gst_meta_test_api_get_type (void)
|
|
|
|
{
|
2021-03-18 03:46:15 +00:00
|
|
|
static GType type;
|
2012-02-29 16:20:23 +00:00
|
|
|
static const gchar *tags[] = { "timing", NULL };
|
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstMetaTestAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2016-12-14 18:19:00 +00:00
|
|
|
static gboolean
|
|
|
|
foo_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("init called on buffer %p, foo meta %p", buffer, meta);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
foo_free_func (GstMeta * meta, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("free called on buffer %p, foo meta %p", buffer, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
static const GstMetaInfo *
|
2011-02-28 08:39:44 +00:00
|
|
|
gst_meta_test_get_info (void)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
2011-02-28 08:39:44 +00:00
|
|
|
static const GstMetaInfo *meta_test_info = NULL;
|
2009-12-27 21:03:32 +00:00
|
|
|
|
2018-08-25 22:45:45 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & meta_test_info)) {
|
2012-10-03 11:45:22 +00:00
|
|
|
const GstMetaInfo *mi = gst_meta_register (GST_META_TEST_API_TYPE,
|
2012-02-29 16:20:23 +00:00
|
|
|
"GstMetaTest",
|
2011-02-28 08:39:44 +00:00
|
|
|
sizeof (GstMetaTest),
|
2012-02-29 16:20:23 +00:00
|
|
|
test_init_func, test_free_func, test_transform_func);
|
2018-08-25 22:45:45 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & meta_test_info, (GstMetaInfo *) mi);
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
2011-02-28 08:39:44 +00:00
|
|
|
return meta_test_info;
|
2009-12-17 11:34:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 18:19:00 +00:00
|
|
|
static gboolean
|
|
|
|
foo_transform_func (GstBuffer * transbuf, GstMeta * meta,
|
|
|
|
GstBuffer * buffer, GQuark type, gpointer data)
|
|
|
|
{
|
|
|
|
GST_DEBUG ("transform %s called from buffer %p to %p, meta %p",
|
|
|
|
g_quark_to_string (type), buffer, transbuf, meta);
|
|
|
|
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
2019-02-05 12:48:48 +00:00
|
|
|
G_GNUC_UNUSED GstMetaFoo *unused = GST_META_FOO_ADD (transbuf);
|
2016-12-14 18:19:00 +00:00
|
|
|
} else {
|
|
|
|
/* return FALSE, if transform type is not supported */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gst_meta_foo_api_get_type (void)
|
|
|
|
{
|
2021-03-18 03:46:15 +00:00
|
|
|
static GType type;
|
2016-12-14 18:19:00 +00:00
|
|
|
static const gchar *tags[] = { NULL };
|
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstMetaFooAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstMetaInfo *
|
|
|
|
gst_meta_foo_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *meta_foo_info = NULL;
|
|
|
|
|
2018-08-25 22:45:45 +00:00
|
|
|
if (g_once_init_enter ((GstMetaInfo **) & meta_foo_info)) {
|
2016-12-14 18:19:00 +00:00
|
|
|
const GstMetaInfo *mi = gst_meta_register (GST_META_FOO_API_TYPE,
|
|
|
|
"GstMetaFoo",
|
|
|
|
sizeof (GstMetaFoo),
|
|
|
|
foo_init_func, foo_free_func, foo_transform_func);
|
2018-08-25 22:45:45 +00:00
|
|
|
g_once_init_leave ((GstMetaInfo **) & meta_foo_info, (GstMetaInfo *) mi);
|
2016-12-14 18:19:00 +00:00
|
|
|
}
|
|
|
|
return meta_foo_info;
|
|
|
|
}
|
|
|
|
|
2011-02-28 08:39:44 +00:00
|
|
|
GST_START_TEST (test_meta_test)
|
2009-12-17 11:34:42 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buffer, *copy, *subbuf;
|
2011-02-28 08:39:44 +00:00
|
|
|
GstMetaTest *meta;
|
2012-01-20 13:23:57 +00:00
|
|
|
GstMapInfo info;
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
2011-06-08 10:04:49 +00:00
|
|
|
fail_if (buffer == NULL);
|
2011-03-21 18:15:27 +00:00
|
|
|
|
2012-01-20 13:23:57 +00:00
|
|
|
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
|
|
|
fail_if (info.data == NULL);
|
|
|
|
memset (info.data, 0, 4);
|
|
|
|
gst_buffer_unmap (buffer, &info);
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
/* add some metadata */
|
2011-02-28 08:39:44 +00:00
|
|
|
meta = GST_META_TEST_ADD (buffer);
|
2009-12-17 11:34:42 +00:00
|
|
|
fail_if (meta == NULL);
|
|
|
|
/* fill some values */
|
|
|
|
meta->pts = 1000;
|
|
|
|
meta->dts = 2000;
|
|
|
|
meta->duration = 1000;
|
|
|
|
meta->clock_rate = 1000;
|
|
|
|
|
|
|
|
/* copy of the buffer */
|
|
|
|
copy = gst_buffer_copy (buffer);
|
|
|
|
/* get metadata of the buffer */
|
2011-02-28 08:39:44 +00:00
|
|
|
meta = GST_META_TEST_GET (copy);
|
2009-12-17 11:34:42 +00:00
|
|
|
fail_if (meta == NULL);
|
|
|
|
fail_if (meta->pts != 1000);
|
|
|
|
fail_if (meta->dts != 2000);
|
|
|
|
fail_if (meta->duration != 1000);
|
|
|
|
fail_if (meta->clock_rate != 1000);
|
|
|
|
gst_buffer_unref (copy);
|
|
|
|
|
|
|
|
/* make subbuffer */
|
2011-03-30 14:47:55 +00:00
|
|
|
subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 1);
|
2009-12-17 11:34:42 +00:00
|
|
|
/* get metadata of the buffer */
|
2011-02-28 08:39:44 +00:00
|
|
|
meta = GST_META_TEST_GET (subbuf);
|
2009-12-17 11:34:42 +00:00
|
|
|
fail_if (meta == NULL);
|
|
|
|
fail_if (meta->pts != 1000);
|
|
|
|
fail_if (meta->dts != 2000);
|
|
|
|
fail_if (meta->duration != -1);
|
|
|
|
fail_if (meta->clock_rate != 1000);
|
|
|
|
gst_buffer_unref (subbuf);
|
|
|
|
|
|
|
|
/* make another subbuffer */
|
2011-03-30 14:47:55 +00:00
|
|
|
subbuf = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 3);
|
2009-12-17 11:34:42 +00:00
|
|
|
/* get metadata of the buffer */
|
2011-02-28 08:39:44 +00:00
|
|
|
meta = GST_META_TEST_GET (subbuf);
|
2009-12-17 11:34:42 +00:00
|
|
|
fail_if (meta == NULL);
|
|
|
|
fail_if (meta->pts != -1);
|
|
|
|
fail_if (meta->dts != -1);
|
|
|
|
fail_if (meta->duration != -1);
|
|
|
|
fail_if (meta->clock_rate != 1000);
|
|
|
|
gst_buffer_unref (subbuf);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2012-04-17 13:37:27 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_meta (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
|
|
|
|
{
|
|
|
|
/* try to remove */
|
|
|
|
*meta = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_locked)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta == NULL);
|
|
|
|
GST_META_FLAG_SET (meta, GST_META_FLAG_LOCKED);
|
|
|
|
|
|
|
|
ASSERT_CRITICAL (gst_buffer_remove_meta (buffer, (GstMeta *) meta));
|
|
|
|
ASSERT_CRITICAL (gst_buffer_foreach_meta (buffer, foreach_meta, NULL));
|
|
|
|
|
|
|
|
GST_META_FLAG_UNSET (meta, GST_META_FLAG_LOCKED);
|
|
|
|
|
|
|
|
gst_buffer_remove_meta (buffer, (GstMeta *) meta);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2017-10-06 19:59:03 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_meta_remove_one (GstBuffer * buffer, GstMeta ** meta,
|
|
|
|
gpointer to_remove)
|
|
|
|
{
|
|
|
|
if (*meta == to_remove) {
|
|
|
|
*meta = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
count_buffer_meta (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gint ret = 0;
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
while (gst_buffer_iterate_meta (buffer, &state))
|
|
|
|
ret++;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-01 15:32:07 +00:00
|
|
|
GST_START_TEST (test_meta_foreach_remove_one_of_one)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1;
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 1);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_one, meta1);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_foreach_remove_head_of_three)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3;
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta2 == NULL);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta3 == NULL);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 3);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_one, meta3);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta1);
|
2019-03-01 10:59:14 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta2);
|
2018-12-01 15:32:07 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_foreach_remove_middle_of_three)
|
2017-10-06 19:59:03 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3;
|
2018-12-01 15:32:07 +00:00
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta2 == NULL);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta3 == NULL);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 3);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_one, meta2);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta1);
|
2019-03-01 10:59:14 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta3);
|
2018-12-01 15:32:07 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_foreach_remove_tail_of_three)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3;
|
|
|
|
gpointer state = NULL;
|
2017-10-06 19:59:03 +00:00
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta2 == NULL);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta3 == NULL);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 3);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_one, meta1);
|
|
|
|
|
2018-12-01 15:32:07 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta2);
|
2019-03-01 10:59:14 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta3);
|
2018-12-01 15:32:07 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
foreach_meta_remove_unpooled (GstBuffer * buffer, GstMeta ** meta,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
if (!GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
|
|
|
|
*meta = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_foreach_remove_head_and_tail_of_three)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3;
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta2 == NULL);
|
|
|
|
GST_META_FLAG_SET (meta2, GST_META_FLAG_POOLED);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta3 == NULL);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 3);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_unpooled, NULL);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta2);
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_foreach_remove_several)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3, *meta4, *meta5;
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta1 == NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta2 == NULL);
|
|
|
|
GST_META_FLAG_SET (meta2, GST_META_FLAG_POOLED);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta3 == NULL);
|
|
|
|
meta4 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta4 == NULL);
|
|
|
|
meta5 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_if (meta5 == NULL);
|
|
|
|
GST_META_FLAG_SET (meta5, GST_META_FLAG_POOLED);
|
|
|
|
|
|
|
|
fail_unless_equals_int (count_buffer_meta (buffer), 5);
|
|
|
|
|
|
|
|
gst_buffer_foreach_meta (buffer, foreach_meta_remove_unpooled, NULL);
|
|
|
|
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta2);
|
2019-03-01 10:59:14 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == (GstMeta *) meta5);
|
2018-12-01 15:32:07 +00:00
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
2017-10-06 19:59:03 +00:00
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2016-12-14 18:19:00 +00:00
|
|
|
GST_START_TEST (test_meta_iterate)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMeta *m1, *m2, *m3, *m_found;
|
|
|
|
GList *metas;
|
|
|
|
gpointer state;
|
|
|
|
|
|
|
|
/* buffer with single meta */
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
m1 = (GstMeta *) GST_META_TEST_ADD (buffer);
|
|
|
|
fail_unless (m1 != NULL);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) != NULL);
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_TEST_API_TYPE) != NULL);
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_TEST_API_TYPE) == NULL);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_FOO_API_TYPE) == NULL);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_TEST_API_TYPE) != NULL);
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_TEST_API_TYPE) == NULL);
|
|
|
|
|
|
|
|
/* buffer with multiple metas */
|
|
|
|
m2 = (GstMeta *) GST_META_FOO_ADD (buffer);
|
|
|
|
fail_unless (m2 != NULL);
|
|
|
|
m3 = (GstMeta *) GST_META_TEST_ADD (buffer);
|
|
|
|
fail_unless (m3 != NULL);
|
|
|
|
|
|
|
|
/* create a list with metas, we don't know what order buffer_iterate has */
|
|
|
|
metas = g_list_prepend (g_list_prepend (g_list_prepend (NULL, m1), m2), m3);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
m_found = gst_buffer_iterate_meta (buffer, &state);
|
|
|
|
fail_unless (m_found != NULL);
|
|
|
|
metas = g_list_remove (metas, m_found);
|
|
|
|
m_found = gst_buffer_iterate_meta (buffer, &state);
|
|
|
|
fail_unless (m_found != NULL);
|
|
|
|
metas = g_list_remove (metas, m_found);
|
|
|
|
m_found = gst_buffer_iterate_meta (buffer, &state);
|
|
|
|
fail_unless (m_found != NULL);
|
|
|
|
metas = g_list_remove (metas, m_found);
|
|
|
|
|
|
|
|
/* should only have 3 metas, so the 4th time we should get NULL back */
|
|
|
|
fail_unless (gst_buffer_iterate_meta (buffer, &state) == NULL);
|
|
|
|
|
|
|
|
/* list should be empty now, we should have seen each meta once */
|
|
|
|
fail_unless (metas == NULL);
|
|
|
|
|
|
|
|
/* same test as above with iterate_filtered */
|
|
|
|
|
|
|
|
/* create a list with metas, we don't know what order buffer_iterate has */
|
|
|
|
metas = g_list_prepend (g_list_prepend (g_list_prepend (NULL, m1), m2), m3);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
m_found =
|
|
|
|
gst_buffer_iterate_meta_filtered (buffer, &state, GST_META_TEST_API_TYPE);
|
|
|
|
fail_unless (m_found != NULL);
|
|
|
|
metas = g_list_remove (metas, m_found);
|
|
|
|
m_found =
|
|
|
|
gst_buffer_iterate_meta_filtered (buffer, &state, GST_META_TEST_API_TYPE);
|
|
|
|
fail_unless (m_found != NULL);
|
|
|
|
metas = g_list_remove (metas, m_found);
|
|
|
|
|
|
|
|
/* should only have 2 Test metas, so now we should get NULL back */
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_TEST_API_TYPE) == NULL);
|
|
|
|
|
|
|
|
/* but there should also still be a Foo meta */
|
|
|
|
fail_unless_equals_int (g_list_length (metas), 1);
|
|
|
|
fail_unless (metas->data == m2);
|
|
|
|
metas = g_list_remove (metas, m2);
|
|
|
|
|
|
|
|
state = NULL;
|
|
|
|
m_found =
|
|
|
|
gst_buffer_iterate_meta_filtered (buffer, &state, GST_META_FOO_API_TYPE);
|
|
|
|
fail_unless (m_found == m2);
|
|
|
|
|
|
|
|
/* only have 1 Foo meta, so now we should get NULL back */
|
|
|
|
fail_unless (gst_buffer_iterate_meta_filtered (buffer, &state,
|
|
|
|
GST_META_FOO_API_TYPE) == NULL);
|
|
|
|
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2016-12-02 17:56:59 +00:00
|
|
|
#define test_meta_compare_seqnum(a,b) \
|
|
|
|
gst_meta_compare_seqnum((GstMeta*)(a),(GstMeta*)(b))
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_seqnum)
|
|
|
|
{
|
|
|
|
GstMetaTest *meta1, *meta2, *meta3;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_unless (buffer != NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta1 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_unless (meta1 != NULL);
|
|
|
|
meta2 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_unless (meta2 != NULL);
|
|
|
|
meta3 = GST_META_TEST_ADD (buffer);
|
|
|
|
fail_unless (meta3 != NULL);
|
|
|
|
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta1, meta2) < 0);
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta2, meta3) < 0);
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta1, meta3) < 0);
|
|
|
|
|
|
|
|
fail_unless_equals_int (test_meta_compare_seqnum (meta1, meta1), 0);
|
|
|
|
fail_unless_equals_int (test_meta_compare_seqnum (meta2, meta2), 0);
|
|
|
|
fail_unless_equals_int (test_meta_compare_seqnum (meta3, meta3), 0);
|
|
|
|
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta2, meta1) > 0);
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta3, meta2) > 0);
|
|
|
|
fail_unless (test_meta_compare_seqnum (meta3, meta1) > 0);
|
|
|
|
|
|
|
|
/* Check that gst_meta_compare_seqnum() works correctly as a GCompareFunc */
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
/* Make list: 3, 1, 2 */
|
|
|
|
list = g_list_prepend (NULL, meta2);
|
|
|
|
list = g_list_prepend (list, meta1);
|
|
|
|
list = g_list_prepend (list, meta3);
|
|
|
|
|
|
|
|
list = g_list_sort (list, (GCompareFunc) gst_meta_compare_seqnum);
|
|
|
|
|
|
|
|
fail_unless (g_list_nth_data (list, 0) == meta1);
|
|
|
|
fail_unless (g_list_nth_data (list, 1) == meta2);
|
|
|
|
fail_unless (g_list_nth_data (list, 2) == meta3);
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2020-09-01 21:03:18 +00:00
|
|
|
GST_START_TEST (test_meta_custom)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
const GstMetaInfo *info;
|
|
|
|
GstCustomMeta *meta;
|
|
|
|
GstMeta *it;
|
|
|
|
GstStructure *s, *expected;
|
|
|
|
gpointer state = NULL;
|
|
|
|
const gchar *tags[] = { "test-tag", NULL };
|
|
|
|
|
|
|
|
info = gst_meta_register_custom ("test-custom", tags, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
fail_unless (info != NULL);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta = gst_buffer_add_custom_meta (buffer, "test-custom");
|
|
|
|
fail_if (meta == NULL);
|
|
|
|
|
|
|
|
fail_unless (gst_custom_meta_has_name ((GstCustomMeta *) meta,
|
|
|
|
"test-custom"));
|
|
|
|
|
|
|
|
expected = gst_structure_new_empty ("test-custom");
|
|
|
|
s = gst_custom_meta_get_structure (meta);
|
|
|
|
fail_unless (gst_structure_is_equal (s, expected));
|
|
|
|
gst_structure_free (expected);
|
|
|
|
|
|
|
|
gst_structure_set (s, "test-field", G_TYPE_INT, 42, NULL);
|
|
|
|
gst_buffer_ref (buffer);
|
|
|
|
ASSERT_CRITICAL (gst_structure_set (s, "test-field", G_TYPE_INT, 43, NULL));
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
expected = gst_structure_new ("test-custom",
|
|
|
|
"test-field", G_TYPE_INT, 42, NULL);
|
|
|
|
fail_unless (gst_structure_is_equal (s, expected));
|
|
|
|
gst_structure_free (expected);
|
|
|
|
|
|
|
|
it = gst_buffer_iterate_meta (buffer, &state);
|
|
|
|
|
|
|
|
fail_unless ((GstCustomMeta *) it == meta);
|
|
|
|
|
|
|
|
fail_unless (it->info == info);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
transform_custom (GstBuffer * transbuf, GstMeta * meta, GstBuffer * buffer,
|
|
|
|
GQuark type, gpointer data, gint * user_data)
|
|
|
|
{
|
|
|
|
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
|
|
|
GstStructure *s;
|
|
|
|
GstCustomMeta *custom;
|
|
|
|
|
|
|
|
custom = (GstCustomMeta *) gst_buffer_add_meta (transbuf, meta->info, NULL);
|
|
|
|
s = gst_custom_meta_get_structure (custom);
|
|
|
|
gst_structure_set (s, "test-field", G_TYPE_INT, *user_data, NULL);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_meta_custom_transform)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer, *buffer_copy;
|
|
|
|
const GstMetaInfo *info;
|
|
|
|
GstCustomMeta *meta;
|
|
|
|
GstStructure *s, *expected;
|
|
|
|
const gchar *tags[] = { "test-tag", NULL };
|
|
|
|
gint *user_data;
|
|
|
|
|
|
|
|
/* That memory should be deallocated at gst_deinit time */
|
|
|
|
user_data = g_malloc (sizeof (gint));
|
|
|
|
*user_data = 42;
|
|
|
|
info =
|
|
|
|
gst_meta_register_custom ("test-custom", tags,
|
|
|
|
(GstCustomMetaTransformFunction) transform_custom, user_data, g_free);
|
|
|
|
|
|
|
|
fail_unless (info != NULL);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_and_alloc (4);
|
|
|
|
fail_if (buffer == NULL);
|
|
|
|
|
|
|
|
/* add some metadata */
|
|
|
|
meta = gst_buffer_add_custom_meta (buffer, "test-custom");
|
|
|
|
fail_if (meta == NULL);
|
|
|
|
|
|
|
|
buffer_copy = gst_buffer_copy (buffer);
|
|
|
|
meta = gst_buffer_get_custom_meta (buffer_copy, "test-custom");
|
|
|
|
fail_unless (meta != NULL);
|
|
|
|
expected =
|
|
|
|
gst_structure_new ("test-custom", "test-field", G_TYPE_INT, 42, NULL);
|
|
|
|
s = gst_custom_meta_get_structure (meta);
|
|
|
|
fail_unless (gst_structure_is_equal (s, expected));
|
|
|
|
gst_structure_free (expected);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
gst_buffer_unref (buffer_copy);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-12-17 11:34:42 +00:00
|
|
|
static Suite *
|
|
|
|
gst_buffermeta_suite (void)
|
|
|
|
{
|
2011-02-25 12:15:25 +00:00
|
|
|
Suite *s = suite_create ("GstMeta");
|
2009-12-17 11:34:42 +00:00
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
2011-02-28 08:39:44 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_test);
|
2012-04-17 13:37:27 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_locked);
|
2018-12-01 15:32:07 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_one_of_one);
|
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_head_of_three);
|
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_middle_of_three);
|
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_tail_of_three);
|
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_head_and_tail_of_three);
|
|
|
|
tcase_add_test (tc_chain, test_meta_foreach_remove_several);
|
2016-12-14 18:19:00 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_iterate);
|
2016-12-02 17:56:59 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_seqnum);
|
2020-09-01 21:03:18 +00:00
|
|
|
tcase_add_test (tc_chain, test_meta_custom);
|
|
|
|
tcase_add_test (tc_chain, test_meta_custom_transform);
|
2009-12-17 11:34:42 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (gst_buffermeta);
|