mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
taglist: add functions to create a new taglist with tags in one go
Add functions to create a new tag list and set tags in one go, which is nice for use in combination with functions that take ownership of the taglist, such as gst_event_new_tag() or gst_element_found_tags(). API: add gst_tag_list_new_full() API: add gst_tag_list_new_full_valist()
This commit is contained in:
parent
cec504cb7f
commit
dccea0406b
5 changed files with 97 additions and 0 deletions
|
@ -2158,6 +2158,8 @@ gst_tag_get_description
|
|||
gst_tag_get_flag
|
||||
gst_tag_is_fixed
|
||||
gst_tag_list_new
|
||||
gst_tag_list_new_full
|
||||
gst_tag_list_new_full_valist
|
||||
gst_is_tag_list
|
||||
gst_tag_list_is_empty
|
||||
gst_tag_list_copy
|
||||
|
|
|
@ -534,6 +534,67 @@ gst_tag_list_new (void)
|
|||
return GST_TAG_LIST (gst_structure_id_empty_new (GST_QUARK (TAGLIST)));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_tag_list_new_full:
|
||||
* @tag: tag
|
||||
* @...: NULL-terminated list of values to set
|
||||
*
|
||||
* Creates a new taglist and appends the values for the given tags. It expects
|
||||
* tag-value pairs like gst_tag_list_add(), and a NULL terminator after the
|
||||
* last pair. The type of the values is implicit and is documented in the API
|
||||
* reference, but can also be queried at runtime with gst_tag_get_type(). It
|
||||
* is an error to pass a value of a type not matching the tag type into this
|
||||
* function. The tag list will make copies of any arguments passed
|
||||
* (e.g. strings, buffers).
|
||||
*
|
||||
* Returns: a new #GstTagList. Free with gst_tag_list_free() when no longer
|
||||
* needed.
|
||||
*
|
||||
* Since: 0.10.24
|
||||
*/
|
||||
/* FIXME 0.11: rename gst_tag_list_new_full to _new and _new to _new_empty */
|
||||
GstTagList *
|
||||
gst_tag_list_new_full (const gchar * tag, ...)
|
||||
{
|
||||
GstTagList *list;
|
||||
va_list args;
|
||||
|
||||
g_return_val_if_fail (tag != NULL, NULL);
|
||||
|
||||
list = gst_tag_list_new ();
|
||||
va_start (args, tag);
|
||||
gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, args);
|
||||
va_end (args);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_tag_list_new_full_valist:
|
||||
* @var_args: tag / value pairs to set
|
||||
*
|
||||
* Just like gst_tag_list_new_full(), only that it takes a va_list argument.
|
||||
* Useful mostly for language bindings.
|
||||
*
|
||||
* Returns: a new #GstTagList. Free with gst_tag_list_free() when no longer
|
||||
* needed.
|
||||
*
|
||||
* Since: 0.10.24
|
||||
*/
|
||||
GstTagList *
|
||||
gst_tag_list_new_full_valist (va_list var_args)
|
||||
{
|
||||
GstTagList *list;
|
||||
const gchar *tag;
|
||||
|
||||
list = gst_tag_list_new ();
|
||||
|
||||
tag = va_arg (var_args, gchar *);
|
||||
gst_tag_list_add_valist (list, GST_TAG_MERGE_APPEND, tag, var_args);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_tag_list_is_empty:
|
||||
* @list: A #GstTagList.
|
||||
|
|
|
@ -198,6 +198,9 @@ gboolean gst_tag_is_fixed (const gchar * tag);
|
|||
|
||||
/* tag lists */
|
||||
GstTagList * gst_tag_list_new (void);
|
||||
GstTagList * gst_tag_list_new_full (const gchar * tag, ...);
|
||||
GstTagList * gst_tag_list_new_full_valist (va_list var_args);
|
||||
|
||||
gboolean gst_is_tag_list (gconstpointer p);
|
||||
GstTagList * gst_tag_list_copy (const GstTagList * list);
|
||||
gboolean gst_tag_list_is_empty (const GstTagList * list);
|
||||
|
|
|
@ -398,6 +398,34 @@ GST_START_TEST (test_empty_tags)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_new_full)
|
||||
{
|
||||
GstTagList *tags;
|
||||
gchar *artist, *title;
|
||||
gdouble track_gain;
|
||||
guint track_num;
|
||||
|
||||
tags = gst_tag_list_new_full (GST_TAG_ARTIST, "Arty Ist",
|
||||
GST_TAG_TRACK_NUMBER, 9, GST_TAG_TRACK_GAIN, 4.242, GST_TAG_TITLE,
|
||||
"Title!", NULL);
|
||||
|
||||
fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &artist));
|
||||
fail_unless_equals_string (artist, "Arty Ist");
|
||||
fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &title));
|
||||
fail_unless_equals_string (title, "Title!");
|
||||
fail_unless (gst_tag_list_get_uint (tags, GST_TAG_TRACK_NUMBER, &track_num));
|
||||
fail_unless_equals_int (track_num, 9);
|
||||
fail_unless (gst_tag_list_get_double (tags, GST_TAG_TRACK_GAIN, &track_gain));
|
||||
fail_unless_equals_float (track_gain, 4.242);
|
||||
fail_unless (tags != NULL);
|
||||
|
||||
gst_tag_list_free (tags);
|
||||
g_free (artist);
|
||||
g_free (title);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static Suite *
|
||||
gst_tag_suite (void)
|
||||
{
|
||||
|
@ -413,6 +441,7 @@ gst_tag_suite (void)
|
|||
tcase_add_test (tc_chain, test_set_non_utf8_string);
|
||||
tcase_add_test (tc_chain, test_buffer_tags);
|
||||
tcase_add_test (tc_chain, test_empty_tags);
|
||||
tcase_add_test (tc_chain, test_new_full);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -966,6 +966,8 @@ EXPORTS
|
|||
gst_tag_list_is_empty
|
||||
gst_tag_list_merge
|
||||
gst_tag_list_new
|
||||
gst_tag_list_new_full
|
||||
gst_tag_list_new_full_valist
|
||||
gst_tag_list_remove_tag
|
||||
gst_tag_merge_mode_get_type
|
||||
gst_tag_merge_strings_with_comma
|
||||
|
|
Loading…
Reference in a new issue