2 * Copyright (C) 2010, 2012 Alexander Saprykin <xelfium@gmail.com>
4 * gsttocsetter.c: interface for TOC setting on elements
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * SECTION:gsttocsetter
24 * @title: GstTocSetter
25 * @short_description: Element interface that allows setting and retrieval
28 * Element interface that allows setting of the TOC.
30 * Elements that support some kind of chapters or editions (or tracks like in
31 * the FLAC cue sheet) will implement this interface.
33 * If you just want to retrieve the TOC in your application then all you
34 * need to do is watch for TOC messages on your pipeline's bus (or you can
35 * perform TOC query). This interface is only for setting TOC data, not for
36 * extracting it. To set TOC from the application, find proper tocsetter element
37 * and set TOC using gst_toc_setter_set_toc().
39 * Elements implementing the #GstTocSetter interface can extend existing TOC
40 * by getting extend UID for that (you can use gst_toc_find_entry() to retrieve it)
41 * with any TOC entries received from downstream.
49 #include "gst_private.h"
50 #include "gsttocsetter.h"
51 #include <gobject/gvaluecollector.h>
54 static GQuark gst_toc_key;
56 G_DEFINE_INTERFACE_WITH_CODE (GstTocSetter, gst_toc_setter, GST_TYPE_ELEMENT,
57 gst_toc_key = g_quark_from_static_string ("gst-toc-setter-data"););
60 gst_toc_setter_default_init (GstTocSetterInterface * klass)
62 /* nothing to do here, it's a dummy interface */
72 gst_toc_data_free (gpointer p)
74 GstTocData *data = (GstTocData *) p;
77 gst_toc_unref (data->toc);
79 g_mutex_clear (&data->lock);
81 g_slice_free (GstTocData, data);
85 gst_toc_setter_get_data (GstTocSetter * setter)
89 data = g_object_get_qdata (G_OBJECT (setter), gst_toc_key);
91 static GMutex create_mutex;
93 /* make sure no other thread is creating a GstTocData at the same time */
94 g_mutex_lock (&create_mutex);
95 data = g_object_get_qdata (G_OBJECT (setter), gst_toc_key);
97 data = g_slice_new (GstTocData);
98 g_mutex_init (&data->lock);
100 g_object_set_qdata_full (G_OBJECT (setter), gst_toc_key, data,
103 g_mutex_unlock (&create_mutex);
110 * gst_toc_setter_reset:
111 * @setter: a #GstTocSetter.
113 * Reset the internal TOC. Elements should call this from within the
114 * state-change handler.
117 gst_toc_setter_reset (GstTocSetter * setter)
119 g_return_if_fail (GST_IS_TOC_SETTER (setter));
121 gst_toc_setter_set_toc (setter, NULL);
125 * gst_toc_setter_get_toc:
126 * @setter: a #GstTocSetter.
128 * Return current TOC the setter uses. The TOC should not be
129 * modified without making it writable first.
131 * Returns: (transfer full) (nullable): TOC set, or %NULL. Unref with
132 * gst_toc_unref() when no longer needed
135 gst_toc_setter_get_toc (GstTocSetter * setter)
140 g_return_val_if_fail (GST_IS_TOC_SETTER (setter), NULL);
142 data = gst_toc_setter_get_data (setter);
143 g_mutex_lock (&data->lock);
145 if (data->toc != NULL)
146 ret = gst_toc_ref (data->toc);
148 g_mutex_unlock (&data->lock);
154 * gst_toc_setter_set_toc:
155 * @setter: a #GstTocSetter.
156 * @toc: (allow-none): a #GstToc to set.
158 * Set the given TOC on the setter. Previously set TOC will be
159 * unreffed before setting a new one.
162 gst_toc_setter_set_toc (GstTocSetter * setter, GstToc * toc)
166 g_return_if_fail (GST_IS_TOC_SETTER (setter));
168 data = gst_toc_setter_get_data (setter);
170 g_mutex_lock (&data->lock);
172 if (data->toc != toc) {
174 gst_toc_unref (data->toc);
176 data->toc = (toc) ? gst_toc_ref (toc) : NULL;
179 g_mutex_unlock (&data->lock);