mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
tocsetter: clean up and update API for refcounted TOCs
Let's keep it simple for now: gst_toc_setter_reset_toc() -> gst_toc_setter_reset() gst_toc_setter_get_toc_copy() -> removed gst_toc_setter_get_toc() -> returns a ref now gst_toc_setter_get_toc_entry_copy() -> removed, use TOC functions instead gst_toc_setter_get_toc_entry() -> removed, use TOC functions instead gst_toc_setter_add_toc_entry() -> removed, to avoid problems with (refcount-dependent) writability of TOC; use TOC functions instead
This commit is contained in:
parent
17022f7ad1
commit
03ac16c1d8
5 changed files with 39 additions and 190 deletions
|
@ -2741,14 +2741,10 @@ gst_toc_entry_type_get_type
|
||||||
<FILE>gsttocsetter</FILE>
|
<FILE>gsttocsetter</FILE>
|
||||||
<TITLE>GstTocSetter</TITLE>
|
<TITLE>GstTocSetter</TITLE>
|
||||||
GstTocSetter
|
GstTocSetter
|
||||||
GstTocSetterIFace
|
GstTocSetterInterface
|
||||||
gst_toc_setter_get_toc
|
|
||||||
gst_toc_setter_get_toc_copy
|
|
||||||
gst_toc_setter_reset_toc
|
|
||||||
gst_toc_setter_set_toc
|
gst_toc_setter_set_toc
|
||||||
gst_toc_setter_get_toc_entry
|
gst_toc_setter_get_toc
|
||||||
gst_toc_setter_get_toc_entry_copy
|
gst_toc_setter_reset
|
||||||
gst_toc_setter_add_toc_entry
|
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
GST_IS_TOC_SETTER
|
GST_IS_TOC_SETTER
|
||||||
GST_TOC_SETTER
|
GST_TOC_SETTER
|
||||||
|
|
|
@ -106,7 +106,7 @@ gst_toc_setter_get_data (GstTocSetter * setter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_toc_setter_reset_toc:
|
* gst_toc_setter_reset:
|
||||||
* @setter: a #GstTocSetter.
|
* @setter: a #GstTocSetter.
|
||||||
*
|
*
|
||||||
* Reset the internal TOC. Elements should call this from within the
|
* Reset the internal TOC. Elements should call this from within the
|
||||||
|
@ -115,20 +115,11 @@ gst_toc_setter_get_data (GstTocSetter * setter)
|
||||||
* Since: 0.10.37
|
* Since: 0.10.37
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gst_toc_setter_reset_toc (GstTocSetter * setter)
|
gst_toc_setter_reset (GstTocSetter * setter)
|
||||||
{
|
{
|
||||||
GstTocData *data;
|
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_TOC_SETTER (setter));
|
g_return_if_fail (GST_IS_TOC_SETTER (setter));
|
||||||
|
|
||||||
data = gst_toc_setter_get_data (setter);
|
gst_toc_setter_set_toc (setter, NULL);
|
||||||
|
|
||||||
g_mutex_lock (&data->lock);
|
|
||||||
if (data->toc) {
|
|
||||||
gst_toc_unref (data->toc);
|
|
||||||
data->toc = NULL;
|
|
||||||
}
|
|
||||||
g_mutex_unlock (&data->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,39 +127,16 @@ gst_toc_setter_reset_toc (GstTocSetter * setter)
|
||||||
* @setter: a #GstTocSetter.
|
* @setter: a #GstTocSetter.
|
||||||
*
|
*
|
||||||
* Return current TOC the setter uses. The TOC should not be
|
* Return current TOC the setter uses. The TOC should not be
|
||||||
* modified or freed.
|
* modified without making it writable first.
|
||||||
*
|
*
|
||||||
* This function is not thread-safe. Use gst_toc_setter_get_toc_copy() instead.
|
|
||||||
*
|
*
|
||||||
* Returns: a current snapshot of the TOC used in the setter
|
* Returns: (transfer full): TOC set, or NULL. Unref with gst_toc_unref()
|
||||||
* or NULL if none is used.
|
* when no longer needed
|
||||||
*
|
|
||||||
* Since: 0.10.37
|
|
||||||
*/
|
|
||||||
const GstToc *
|
|
||||||
gst_toc_setter_get_toc (GstTocSetter * setter)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (GST_IS_TOC_SETTER (setter), NULL);
|
|
||||||
|
|
||||||
return gst_toc_setter_get_data (setter)->toc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_toc_setter_get_toc_copy:
|
|
||||||
* @setter: a #GstTocSetter.
|
|
||||||
*
|
|
||||||
* Return current TOC the setter uses. The difference between this
|
|
||||||
* function and gst_toc_setter_get_toc() is that this function returns deep
|
|
||||||
* copy of the TOC, so you can modify it in any way. This function is thread-safe.
|
|
||||||
* Free it when done with gst_toc_unref().
|
|
||||||
*
|
|
||||||
* Returns: a copy of the current snapshot of the TOC used in the setter
|
|
||||||
* or NULL if none is used.
|
|
||||||
*
|
*
|
||||||
* Since: 0.10.37
|
* Since: 0.10.37
|
||||||
*/
|
*/
|
||||||
GstToc *
|
GstToc *
|
||||||
gst_toc_setter_get_toc_copy (GstTocSetter * setter)
|
gst_toc_setter_get_toc (GstTocSetter * setter)
|
||||||
{
|
{
|
||||||
GstTocData *data;
|
GstTocData *data;
|
||||||
GstToc *ret = NULL;
|
GstToc *ret = NULL;
|
||||||
|
@ -179,7 +147,7 @@ gst_toc_setter_get_toc_copy (GstTocSetter * setter)
|
||||||
g_mutex_lock (&data->lock);
|
g_mutex_lock (&data->lock);
|
||||||
|
|
||||||
if (data->toc != NULL)
|
if (data->toc != NULL)
|
||||||
ret = gst_toc_copy (data->toc);
|
ret = gst_toc_ref (data->toc);
|
||||||
|
|
||||||
g_mutex_unlock (&data->lock);
|
g_mutex_unlock (&data->lock);
|
||||||
|
|
||||||
|
@ -189,15 +157,15 @@ gst_toc_setter_get_toc_copy (GstTocSetter * setter)
|
||||||
/**
|
/**
|
||||||
* gst_toc_setter_set_toc:
|
* gst_toc_setter_set_toc:
|
||||||
* @setter: a #GstTocSetter.
|
* @setter: a #GstTocSetter.
|
||||||
* @toc: a #GstToc to set.
|
* @toc: (allow-none): a #GstToc to set.
|
||||||
*
|
*
|
||||||
* Set the given TOC on the setter. Previously setted TOC will be
|
* Set the given TOC on the setter. Previously setted TOC will be
|
||||||
* freed before setting a new one.
|
* unrefed before setting a new one.
|
||||||
*
|
*
|
||||||
* Since: 0.10.37
|
* Since: 0.10.37
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gst_toc_setter_set_toc (GstTocSetter * setter, const GstToc * toc)
|
gst_toc_setter_set_toc (GstTocSetter * setter, GstToc * toc)
|
||||||
{
|
{
|
||||||
GstTocData *data;
|
GstTocData *data;
|
||||||
|
|
||||||
|
@ -206,131 +174,13 @@ gst_toc_setter_set_toc (GstTocSetter * setter, const GstToc * toc)
|
||||||
data = gst_toc_setter_get_data (setter);
|
data = gst_toc_setter_get_data (setter);
|
||||||
|
|
||||||
g_mutex_lock (&data->lock);
|
g_mutex_lock (&data->lock);
|
||||||
if (data->toc)
|
|
||||||
gst_toc_unref (data->toc);
|
|
||||||
|
|
||||||
data->toc = gst_toc_copy (toc);
|
if (data->toc != toc) {
|
||||||
|
if (data->toc)
|
||||||
|
gst_toc_unref (data->toc);
|
||||||
|
|
||||||
g_mutex_unlock (&data->lock);
|
data->toc = (toc) ? gst_toc_ref (toc) : NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_toc_setter_get_toc_entry:
|
|
||||||
* @setter: a #GstTocSetter.
|
|
||||||
* @uid: UID to find entry with.
|
|
||||||
*
|
|
||||||
* Return #GstTocEntry (if any) with given @uid. Returned entry should
|
|
||||||
* not be modified or freed.
|
|
||||||
*
|
|
||||||
* This function is not thread-safe. Use gst_toc_setter_get_toc_entry_copy() instead.
|
|
||||||
*
|
|
||||||
* Returns: a TOC entry with given @uid from the TOC in the setter
|
|
||||||
* or NULL if none entry with such @uid was found.
|
|
||||||
*
|
|
||||||
* Since: 0.10.37
|
|
||||||
*/
|
|
||||||
const GstTocEntry *
|
|
||||||
gst_toc_setter_get_toc_entry (GstTocSetter * setter, const gchar * uid)
|
|
||||||
{
|
|
||||||
GstTocData *data;
|
|
||||||
const GstTocEntry *ret;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_TOC_SETTER (setter), NULL);
|
|
||||||
g_return_val_if_fail (uid != NULL, NULL);
|
|
||||||
|
|
||||||
data = gst_toc_setter_get_data (setter);
|
|
||||||
|
|
||||||
g_mutex_lock (&data->lock);
|
|
||||||
|
|
||||||
ret = gst_toc_find_entry (data->toc, uid);
|
|
||||||
|
|
||||||
g_mutex_unlock (&data->lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_toc_setter_get_toc_entry_copy:
|
|
||||||
* @setter: a #GstTocSetter.
|
|
||||||
* @uid: UID to find entry with.
|
|
||||||
*
|
|
||||||
* Return #GstTocEntry (if any) with given @uid. It perform a deep copying,
|
|
||||||
* so you can modify returned value. Free it when done with gst_toc_entry_free().
|
|
||||||
* This function is thread-safe.
|
|
||||||
*
|
|
||||||
* Returns: a TOC entry with given @uid from the TOC in the setter
|
|
||||||
* or NULL if none entry with such @uid was found.
|
|
||||||
*
|
|
||||||
* Since: 0.10.37
|
|
||||||
*/
|
|
||||||
GstTocEntry *
|
|
||||||
gst_toc_setter_get_toc_entry_copy (GstTocSetter * setter, const gchar * uid)
|
|
||||||
{
|
|
||||||
GstTocData *data;
|
|
||||||
GstTocEntry *ret = NULL;
|
|
||||||
const GstTocEntry *search;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_TOC_SETTER (setter), NULL);
|
|
||||||
g_return_val_if_fail (uid != NULL, NULL);
|
|
||||||
|
|
||||||
data = gst_toc_setter_get_data (setter);
|
|
||||||
|
|
||||||
g_mutex_lock (&data->lock);
|
|
||||||
|
|
||||||
search = gst_toc_find_entry (data->toc, uid);
|
|
||||||
if (search != NULL)
|
|
||||||
ret = gst_toc_entry_copy (search);
|
|
||||||
|
|
||||||
g_mutex_unlock (&data->lock);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_toc_setter_add_toc_entry:
|
|
||||||
* @setter: a #GstTocSetter.
|
|
||||||
* @parent_uid: UID of the parent entry to append given @entry. Use 0 for the TOC root level.
|
|
||||||
* @entry: #GstTocEntry to append.
|
|
||||||
*
|
|
||||||
* Try to find entry with given @parent_uid and append an @entry to that #GstTocEntry.
|
|
||||||
*
|
|
||||||
* Returns: TRUE if entry with @parent_uid was found, FALSE otherwise.
|
|
||||||
*
|
|
||||||
* Since: 0.10.37
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
gst_toc_setter_add_toc_entry (GstTocSetter * setter, const gchar * parent_uid,
|
|
||||||
const GstTocEntry * entry)
|
|
||||||
{
|
|
||||||
GstTocData *data;
|
|
||||||
GstTocEntry *parent;
|
|
||||||
GstTocEntry *copy_entry;
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_TOC_SETTER (setter), FALSE);
|
|
||||||
g_return_val_if_fail (parent_uid != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (entry != NULL, FALSE);
|
|
||||||
|
|
||||||
data = gst_toc_setter_get_data (setter);
|
|
||||||
|
|
||||||
g_mutex_lock (&data->lock);
|
|
||||||
|
|
||||||
copy_entry = gst_toc_entry_copy (entry);
|
|
||||||
|
|
||||||
if (g_strcmp0 (parent_uid, "0") == 0) {
|
|
||||||
if (data->toc == NULL)
|
|
||||||
data->toc = gst_toc_new ();
|
|
||||||
data->toc->entries = g_list_append (data->toc->entries, copy_entry);
|
|
||||||
} else {
|
|
||||||
parent = gst_toc_find_entry (data->toc, parent_uid);
|
|
||||||
|
|
||||||
if (parent != NULL) {
|
|
||||||
parent->subentries = g_list_append (parent->subentries, copy_entry);
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_unlock (&data->lock);
|
g_mutex_unlock (&data->lock);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_TYPE_TOC_SETTER (gst_toc_setter_get_type ())
|
#define GST_TYPE_TOC_SETTER (gst_toc_setter_get_type ())
|
||||||
#define GST_TOC_SETTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TOC_SETTER, GstTocSetter))
|
#define GST_TOC_SETTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TOC_SETTER, GstTocSetter))
|
||||||
#define GST_IS_TOC_SETTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TOC_SETTER))
|
#define GST_IS_TOC_SETTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TOC_SETTER))
|
||||||
|
@ -53,15 +54,15 @@ struct _GstTocSetterInterface
|
||||||
/* virtual table */
|
/* virtual table */
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_toc_setter_get_type (void);
|
GType gst_toc_setter_get_type (void);
|
||||||
void gst_toc_setter_reset_toc (GstTocSetter *setter);
|
|
||||||
const GstToc * gst_toc_setter_get_toc (GstTocSetter *setter);
|
void gst_toc_setter_reset (GstTocSetter *setter);
|
||||||
GstToc * gst_toc_setter_get_toc_copy (GstTocSetter *setter);
|
|
||||||
void gst_toc_setter_set_toc (GstTocSetter *setter, const GstToc *toc);
|
GstToc * gst_toc_setter_get_toc (GstTocSetter *setter);
|
||||||
const GstTocEntry * gst_toc_setter_get_toc_entry (GstTocSetter *setter, const gchar *uid);
|
|
||||||
GstTocEntry * gst_toc_setter_get_toc_entry_copy (GstTocSetter *setter, const gchar *uid);
|
void gst_toc_setter_set_toc (GstTocSetter *setter, GstToc *toc);
|
||||||
gboolean gst_toc_setter_add_toc_entry (GstTocSetter *setter, const gchar *parent_uid, const GstTocEntry *entry);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_TOC_SETTER_H__ */
|
#endif /* __GST_TOC_SETTER_H__ */
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,9 @@ create_toc (void)
|
||||||
GST_START_TEST (test_set)
|
GST_START_TEST (test_set)
|
||||||
{
|
{
|
||||||
GstToc *toc;
|
GstToc *toc;
|
||||||
|
#if 0
|
||||||
GstTocEntry *entry, *ed;
|
GstTocEntry *entry, *ed;
|
||||||
|
#endif
|
||||||
GstTocSetter *setter;
|
GstTocSetter *setter;
|
||||||
GstElement *enc;
|
GstElement *enc;
|
||||||
|
|
||||||
|
@ -255,10 +257,11 @@ GST_START_TEST (test_set)
|
||||||
gst_toc_setter_set_toc (setter, toc);
|
gst_toc_setter_set_toc (setter, toc);
|
||||||
|
|
||||||
gst_toc_unref (toc);
|
gst_toc_unref (toc);
|
||||||
toc = gst_toc_setter_get_toc_copy (setter);
|
toc = gst_toc_setter_get_toc (setter);
|
||||||
|
|
||||||
CHECK_TOC (toc);
|
CHECK_TOC (toc);
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* test entry adding into the root TOC */
|
/* test entry adding into the root TOC */
|
||||||
entry = g_list_last (toc->entries)->data;
|
entry = g_list_last (toc->entries)->data;
|
||||||
toc->entries = g_list_remove (toc->entries, entry);
|
toc->entries = g_list_remove (toc->entries, entry);
|
||||||
|
@ -268,10 +271,12 @@ GST_START_TEST (test_set)
|
||||||
|
|
||||||
gst_toc_unref (toc);
|
gst_toc_unref (toc);
|
||||||
gst_toc_entry_unref (entry);
|
gst_toc_entry_unref (entry);
|
||||||
toc = gst_toc_setter_get_toc_copy (setter);
|
toc = gst_toc_setter_get_toc (setter);
|
||||||
|
|
||||||
CHECK_TOC (toc);
|
CHECK_TOC (toc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* test entry adding into the arbitrary entry */
|
/* test entry adding into the arbitrary entry */
|
||||||
entry = gst_toc_find_entry (toc, ENTRY_CH2);
|
entry = gst_toc_find_entry (toc, ENTRY_CH2);
|
||||||
fail_if (entry == NULL);
|
fail_if (entry == NULL);
|
||||||
|
@ -282,10 +287,11 @@ GST_START_TEST (test_set)
|
||||||
gst_toc_setter_add_toc_entry (setter, ed->uid, entry);
|
gst_toc_setter_add_toc_entry (setter, ed->uid, entry);
|
||||||
|
|
||||||
CHECK_TOC (toc);
|
CHECK_TOC (toc);
|
||||||
|
#endif
|
||||||
|
|
||||||
gst_toc_unref (toc);
|
gst_toc_unref (toc);
|
||||||
gst_toc_setter_reset_toc (setter);
|
gst_toc_setter_reset (setter);
|
||||||
toc = gst_toc_setter_get_toc_copy (setter);
|
toc = gst_toc_setter_get_toc (setter);
|
||||||
|
|
||||||
fail_unless (toc == NULL);
|
fail_unless (toc == NULL);
|
||||||
|
|
||||||
|
@ -367,7 +373,7 @@ test_threads_thread_func3 (gpointer data)
|
||||||
g_timer_start (timer);
|
g_timer_start (timer);
|
||||||
|
|
||||||
while (g_timer_elapsed (timer, NULL) < THREADS_TEST_SECONDS) {
|
while (g_timer_elapsed (timer, NULL) < THREADS_TEST_SECONDS) {
|
||||||
gst_toc_setter_reset_toc (setter);
|
gst_toc_setter_reset (setter);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_timer_destroy (timer);
|
g_timer_destroy (timer);
|
||||||
|
|
|
@ -1137,13 +1137,9 @@ EXPORTS
|
||||||
gst_toc_find_entry
|
gst_toc_find_entry
|
||||||
gst_toc_get_type
|
gst_toc_get_type
|
||||||
gst_toc_new
|
gst_toc_new
|
||||||
gst_toc_setter_add_toc_entry
|
|
||||||
gst_toc_setter_get_toc
|
gst_toc_setter_get_toc
|
||||||
gst_toc_setter_get_toc_copy
|
|
||||||
gst_toc_setter_get_toc_entry
|
|
||||||
gst_toc_setter_get_toc_entry_copy
|
|
||||||
gst_toc_setter_get_type
|
gst_toc_setter_get_type
|
||||||
gst_toc_setter_reset_toc
|
gst_toc_setter_reset
|
||||||
gst_toc_setter_set_toc
|
gst_toc_setter_set_toc
|
||||||
gst_type_find_factory_call_function
|
gst_type_find_factory_call_function
|
||||||
gst_type_find_factory_get_caps
|
gst_type_find_factory_get_caps
|
||||||
|
|
Loading…
Reference in a new issue