Revert "meson: Force gstenum_h to be built when using gst_dep"
[platform/upstream/gstreamer.git] / gst / gsttoc.c
1 /* GStreamer
2  * (c) 2010, 2012 Alexander Saprykin <xelfium@gmail.com>
3  *
4  * gsttoc.c: GstToc initialization and parsing/creation
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 /**
23  * SECTION:gsttoc
24  * @short_description: Generic table of contents support
25  * @see_also: #GstStructure, #GstEvent, #GstMessage, #GstQuery
26  *
27  * #GstToc functions are used to create/free #GstToc and #GstTocEntry structures.
28  * Also they are used to convert #GstToc into #GstStructure and vice versa.
29  *
30  * #GstToc lets you to inform other elements in pipeline or application that playing
31  * source has some kind of table of contents (TOC). These may be chapters, editions,
32  * angles or other types. For example: DVD chapters, Matroska chapters or cue sheet
33  * TOC. Such TOC will be useful for applications to display instead of just a
34  * playlist.
35  *
36  * Using TOC is very easy. Firstly, create #GstToc structure which represents root
37  * contents of the source. You can also attach TOC-specific tags to it. Then fill
38  * it with #GstTocEntry entries by appending them to the #GstToc using
39  * gst_toc_append_entry(), and appending subentries to a #GstTocEntry using
40  * gst_toc_entry_append_sub_entry().
41  *
42  * Note that root level of the TOC can contain only either editions or chapters. You
43  * should not mix them together at the same level. Otherwise you will get serialization
44  * /deserialization errors. Make sure that no one of the entries has negative start and
45  *  stop values.
46  *
47  * Use gst_event_new_toc() to create a new TOC #GstEvent, and gst_event_parse_toc() to
48  * parse received TOC event. Use gst_event_new_toc_select() to create a new TOC select #GstEvent,
49  * and gst_event_parse_toc_select() to parse received TOC select event. The same rule for
50  * the #GstMessage: gst_message_new_toc() to create new TOC #GstMessage, and
51  * gst_message_parse_toc() to parse received TOC message.
52  *
53  * TOCs can have global scope or current scope. Global scope TOCs contain
54  * all entries that can possibly be selected using a toc select event, and
55  * are what an application is usually interested in. TOCs with current scope
56  * only contain the parts of the TOC relevant to the currently selected/playing
57  * stream; the current scope TOC is used by downstream elements such as muxers
58  * to write correct TOC entries when transcoding files, for example. When
59  * playing a DVD, the global TOC would contain a hierarchy of all titles,
60  * chapters and angles, for example, while the current TOC would only contain
61  * the chapters for the currently playing title if playback of a specific
62  * title was requested.
63  *
64  * Applications and plugins should not rely on TOCs having a certain kind of
65  * structure, but should allow for different alternatives. For example, a
66  * simple CUE sheet embedded in a file may be presented as a flat list of
67  * track entries, or could have a top-level edition node (or some other
68  * alternative type entry) with track entries underneath that node; or even
69  * multiple top-level edition nodes (or some other alternative type entries)
70  * each with track entries underneath, in case the source file has extracted
71  * a track listing from different sources).
72  */
73
74 #ifdef HAVE_CONFIG_H
75 #  include "config.h"
76 #endif
77
78 #include "gst_private.h"
79 #include "gstenumtypes.h"
80 #include "gsttaglist.h"
81 #include "gststructure.h"
82 #include "gstvalue.h"
83 #include "gsttoc.h"
84 #include "gstpad.h"
85 #include "gstquark.h"
86
87 struct _GstTocEntry
88 {
89   GstMiniObject mini_object;
90
91   GstToc *toc;
92   GstTocEntry *parent;
93
94   gchar *uid;
95   GstTocEntryType type;
96   GstClockTime start, stop;
97   GList *subentries;
98   GstTagList *tags;
99   GstTocLoopType loop_type;
100   gint repeat_count;
101 };
102
103 struct _GstToc
104 {
105   GstMiniObject mini_object;
106
107   GstTocScope scope;
108   GList *entries;
109   GstTagList *tags;
110 };
111
112 #undef gst_toc_copy
113 static GstToc *gst_toc_copy (const GstToc * toc);
114 static void gst_toc_free (GstToc * toc);
115 #undef gst_toc_entry_copy
116 static GstTocEntry *gst_toc_entry_copy (const GstTocEntry * toc);
117 static void gst_toc_entry_free (GstTocEntry * toc);
118
119 GType _gst_toc_type = 0;
120 GType _gst_toc_entry_type = 0;
121
122 GST_DEFINE_MINI_OBJECT_TYPE (GstToc, gst_toc);
123 GST_DEFINE_MINI_OBJECT_TYPE (GstTocEntry, gst_toc_entry);
124
125 /**
126  * gst_toc_new:
127  * @scope: scope of this TOC
128  *
129  * Create a new #GstToc structure.
130  *
131  * Returns: (transfer full): newly allocated #GstToc structure, free it
132  *     with gst_toc_unref().
133  */
134 GstToc *
135 gst_toc_new (GstTocScope scope)
136 {
137   GstToc *toc;
138
139   g_return_val_if_fail (scope == GST_TOC_SCOPE_GLOBAL ||
140       scope == GST_TOC_SCOPE_CURRENT, NULL);
141
142   toc = g_slice_new0 (GstToc);
143
144   gst_mini_object_init (GST_MINI_OBJECT_CAST (toc), 0, GST_TYPE_TOC,
145       (GstMiniObjectCopyFunction) gst_toc_copy, NULL,
146       (GstMiniObjectFreeFunction) gst_toc_free);
147
148   toc->scope = scope;
149   toc->tags = gst_tag_list_new_empty ();
150
151   return toc;
152 }
153
154 /**
155  * gst_toc_get_scope:
156  * @toc: a #GstToc instance
157  *
158  * Returns: scope of @toc
159  */
160 GstTocScope
161 gst_toc_get_scope (const GstToc * toc)
162 {
163   g_return_val_if_fail (toc != NULL, GST_TOC_SCOPE_GLOBAL);
164
165   return toc->scope;
166 }
167
168 /**
169  * gst_toc_set_tags:
170  * @toc: A #GstToc instance
171  * @tags: (allow-none) (transfer full): A #GstTagList or %NULL
172  *
173  * Set a #GstTagList with tags for the complete @toc.
174  */
175 void
176 gst_toc_set_tags (GstToc * toc, GstTagList * tags)
177 {
178   g_return_if_fail (toc != NULL);
179   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (toc)));
180
181   if (toc->tags)
182     gst_tag_list_unref (toc->tags);
183   toc->tags = tags;
184 }
185
186 /**
187  * gst_toc_merge_tags:
188  * @toc: A #GstToc instance
189  * @tags: (allow-none): A #GstTagList or %NULL
190  * @mode: A #GstTagMergeMode
191  *
192  * Merge @tags into the existing tags of @toc using @mode.
193  */
194 void
195 gst_toc_merge_tags (GstToc * toc, GstTagList * tags, GstTagMergeMode mode)
196 {
197   g_return_if_fail (toc != NULL);
198   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (toc)));
199
200   if (!toc->tags) {
201     toc->tags = gst_tag_list_ref (tags);
202   } else {
203     GstTagList *tmp = gst_tag_list_merge (toc->tags, tags, mode);
204     gst_tag_list_unref (toc->tags);
205     toc->tags = tmp;
206   }
207 }
208
209 /**
210  * gst_toc_get_tags:
211  * @toc: A #GstToc instance
212  *
213  * Gets the tags for @toc.
214  *
215  * Returns: (transfer none): A #GstTagList for @entry
216  */
217 GstTagList *
218 gst_toc_get_tags (const GstToc * toc)
219 {
220   g_return_val_if_fail (toc != NULL, NULL);
221
222   return toc->tags;
223 }
224
225 /**
226  * gst_toc_append_entry:
227  * @toc: A #GstToc instance
228  * @entry: (transfer full): A #GstTocEntry
229  *
230  * Appends the #GstTocEntry @entry to @toc.
231  */
232 void
233 gst_toc_append_entry (GstToc * toc, GstTocEntry * entry)
234 {
235   g_return_if_fail (toc != NULL);
236   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (toc)));
237   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (entry)));
238   g_return_if_fail (entry->toc == NULL);
239   g_return_if_fail (entry->parent == NULL);
240
241   toc->entries = g_list_append (toc->entries, entry);
242   entry->toc = toc;
243
244   GST_LOG ("appended %s entry with uid %s to toc %p",
245       gst_toc_entry_type_get_nick (entry->type), entry->uid, toc);
246
247   gst_toc_dump (toc);
248 }
249
250 /**
251  * gst_toc_get_entries:
252  * @toc: A #GstToc instance
253  *
254  * Gets the list of #GstTocEntry of @toc.
255  *
256  * Returns: (transfer none) (element-type Gst.TocEntry): A #GList of #GstTocEntry for @entry
257  */
258 GList *
259 gst_toc_get_entries (const GstToc * toc)
260 {
261   g_return_val_if_fail (toc != NULL, NULL);
262
263   return toc->entries;
264 }
265
266 static GstTocEntry *
267 gst_toc_entry_new_internal (GstTocEntryType type, const gchar * uid)
268 {
269   GstTocEntry *entry;
270
271   entry = g_slice_new0 (GstTocEntry);
272
273   gst_mini_object_init (GST_MINI_OBJECT_CAST (entry), 0, GST_TYPE_TOC_ENTRY,
274       (GstMiniObjectCopyFunction) gst_toc_entry_copy, NULL,
275       (GstMiniObjectFreeFunction) gst_toc_entry_free);
276
277   entry->uid = g_strdup (uid);
278   entry->type = type;
279   entry->tags = NULL;
280   entry->start = entry->stop = GST_CLOCK_TIME_NONE;
281
282   return entry;
283 }
284
285 /**
286  * gst_toc_entry_new:
287  * @type: entry type.
288  * @uid: unique ID (UID) in the whole TOC.
289  *
290  * Create new #GstTocEntry structure.
291  *
292  * Returns: newly allocated #GstTocEntry structure, free it with gst_toc_entry_unref().
293  */
294 GstTocEntry *
295 gst_toc_entry_new (GstTocEntryType type, const gchar * uid)
296 {
297   g_return_val_if_fail (uid != NULL, NULL);
298
299   return gst_toc_entry_new_internal (type, uid);
300 }
301
302 static void
303 gst_toc_free (GstToc * toc)
304 {
305   g_list_foreach (toc->entries, (GFunc) gst_mini_object_unref, NULL);
306   g_list_free (toc->entries);
307
308   if (toc->tags != NULL)
309     gst_tag_list_unref (toc->tags);
310
311   g_slice_free (GstToc, toc);
312 }
313
314 static void
315 gst_toc_entry_free (GstTocEntry * entry)
316 {
317   g_return_if_fail (entry != NULL);
318
319   g_list_foreach (entry->subentries, (GFunc) gst_mini_object_unref, NULL);
320   g_list_free (entry->subentries);
321
322   g_free (entry->uid);
323
324   if (entry->tags != NULL)
325     gst_tag_list_unref (entry->tags);
326
327   g_slice_free (GstTocEntry, entry);
328 }
329
330 static GstTocEntry *
331 gst_toc_entry_find_sub_entry (const GstTocEntry * entry, const gchar * uid)
332 {
333   GList *cur;
334   GstTocEntry *subentry, *subsubentry;
335
336   g_return_val_if_fail (entry != NULL, NULL);
337   g_return_val_if_fail (uid != NULL, NULL);
338
339   cur = entry->subentries;
340   while (cur != NULL) {
341     subentry = cur->data;
342
343     if (g_strcmp0 (subentry->uid, uid) == 0)
344       return subentry;
345
346     subsubentry = gst_toc_entry_find_sub_entry (subentry, uid);
347     if (subsubentry != NULL)
348       return subsubentry;
349
350     cur = cur->next;
351   }
352
353   return NULL;
354 }
355
356 /**
357  * gst_toc_find_entry:
358  * @toc: #GstToc to search in.
359  * @uid: UID to find #GstTocEntry with.
360  *
361  * Find #GstTocEntry with given @uid in the @toc.
362  *
363  * Returns: (transfer none) (nullable): #GstTocEntry with specified
364  * @uid from the @toc, or %NULL if not found.
365  */
366 GstTocEntry *
367 gst_toc_find_entry (const GstToc * toc, const gchar * uid)
368 {
369   GList *cur;
370   GstTocEntry *entry, *subentry;
371
372   g_return_val_if_fail (toc != NULL, NULL);
373   g_return_val_if_fail (uid != NULL, NULL);
374
375   cur = toc->entries;
376   while (cur != NULL) {
377     entry = cur->data;
378
379     if (g_strcmp0 (entry->uid, uid) == 0)
380       return entry;
381
382     subentry = gst_toc_entry_find_sub_entry (entry, uid);
383     if (subentry != NULL)
384       return subentry;
385     cur = cur->next;
386   }
387
388   return NULL;
389 }
390
391 static GList *
392 gst_toc_deep_copy_toc_entries (GList * entry_list)
393 {
394   GQueue new_entries = G_QUEUE_INIT;
395   GList *l;
396
397   for (l = entry_list; l != NULL; l = l->next)
398     g_queue_push_tail (&new_entries, gst_toc_entry_copy (l->data));
399
400   return new_entries.head;
401 }
402
403 /**
404  * gst_toc_entry_copy:
405  * @entry: #GstTocEntry to copy.
406  *
407  * Copy #GstTocEntry with all subentries (deep copy).
408  *
409  * Returns: (nullable): newly allocated #GstTocEntry in case of
410  * success, %NULL otherwise; free it when done with
411  * gst_toc_entry_unref().
412  */
413 static GstTocEntry *
414 gst_toc_entry_copy (const GstTocEntry * entry)
415 {
416   GstTocEntry *ret;
417   GstTagList *list;
418
419   g_return_val_if_fail (entry != NULL, NULL);
420
421   ret = gst_toc_entry_new (entry->type, entry->uid);
422
423   ret->start = entry->start;
424   ret->stop = entry->stop;
425
426   if (GST_IS_TAG_LIST (entry->tags)) {
427     list = gst_tag_list_copy (entry->tags);
428     if (ret->tags)
429       gst_tag_list_unref (ret->tags);
430     ret->tags = list;
431   }
432
433   ret->subentries = gst_toc_deep_copy_toc_entries (entry->subentries);
434
435   return ret;
436 }
437
438 /**
439  * gst_toc_copy:
440  * @toc: #GstToc to copy.
441  *
442  * Copy #GstToc with all subentries (deep copy).
443  *
444  * Returns: (nullable): newly allocated #GstToc in case of success,
445  * %NULL otherwise; free it when done with gst_toc_unref().
446  */
447 static GstToc *
448 gst_toc_copy (const GstToc * toc)
449 {
450   GstToc *ret;
451   GstTagList *list;
452
453   g_return_val_if_fail (toc != NULL, NULL);
454
455   ret = gst_toc_new (toc->scope);
456
457   if (GST_IS_TAG_LIST (toc->tags)) {
458     list = gst_tag_list_copy (toc->tags);
459     gst_tag_list_unref (ret->tags);
460     ret->tags = list;
461   }
462
463   ret->entries = gst_toc_deep_copy_toc_entries (toc->entries);
464
465   return ret;
466 }
467
468 /**
469  * gst_toc_entry_set_start_stop_times:
470  * @entry: #GstTocEntry to set values.
471  * @start: start value to set.
472  * @stop: stop value to set.
473  *
474  * Set @start and @stop values for the @entry.
475  */
476 void
477 gst_toc_entry_set_start_stop_times (GstTocEntry * entry, gint64 start,
478     gint64 stop)
479 {
480   g_return_if_fail (entry != NULL);
481
482   entry->start = start;
483   entry->stop = stop;
484 }
485
486 /**
487  * gst_toc_entry_get_start_stop_times:
488  * @entry: #GstTocEntry to get values from.
489  * @start: (out) (allow-none): the storage for the start value, leave
490  *   %NULL if not need.
491  * @stop: (out) (allow-none): the storage for the stop value, leave
492  *   %NULL if not need.
493  *
494  * Get @start and @stop values from the @entry and write them into appropriate
495  * storages.
496  *
497  * Returns: %TRUE if all non-%NULL storage pointers were filled with appropriate
498  * values, %FALSE otherwise.
499  */
500 gboolean
501 gst_toc_entry_get_start_stop_times (const GstTocEntry * entry, gint64 * start,
502     gint64 * stop)
503 {
504   g_return_val_if_fail (entry != NULL, FALSE);
505
506   if (start != NULL)
507     *start = entry->start;
508   if (stop != NULL)
509     *stop = entry->stop;
510
511   return TRUE;
512 }
513
514 /**
515  * gst_toc_entry_set_loop:
516  * @entry: #GstTocEntry to set values.
517  * @loop_type: loop_type value to set.
518  * @repeat_count: repeat_count value to set.
519  *
520  * Set @loop_type and @repeat_count values for the @entry.
521  *
522  * Since: 1.4
523  */
524 void
525 gst_toc_entry_set_loop (GstTocEntry * entry, GstTocLoopType loop_type,
526     gint repeat_count)
527 {
528   g_return_if_fail (entry != NULL);
529
530   entry->loop_type = loop_type;
531   entry->repeat_count = repeat_count;
532 }
533
534 /**
535  * gst_toc_entry_get_loop:
536  * @entry: #GstTocEntry to get values from.
537  * @loop_type: (out) (allow-none): the storage for the loop_type
538  *             value, leave %NULL if not need.
539  * @repeat_count: (out) (allow-none): the storage for the repeat_count
540  *                value, leave %NULL if not need.
541  *
542  * Get @loop_type and @repeat_count values from the @entry and write them into
543  * appropriate storages. Loops are e.g. used by sampled instruments. GStreamer
544  * is not automatically applying the loop. The application can process this
545  * meta data and use it e.g. to send a seek-event to loop a section.
546  *
547  * Returns: %TRUE if all non-%NULL storage pointers were filled with appropriate
548  * values, %FALSE otherwise.
549  *
550  * Since: 1.4
551  */
552 gboolean
553 gst_toc_entry_get_loop (const GstTocEntry * entry, GstTocLoopType * loop_type,
554     gint * repeat_count)
555 {
556   g_return_val_if_fail (entry != NULL, FALSE);
557
558   if (loop_type != NULL)
559     *loop_type = entry->loop_type;
560   if (repeat_count != NULL)
561     *repeat_count = entry->repeat_count;
562
563   return TRUE;
564 }
565
566
567 /**
568  * gst_toc_entry_type_get_nick:
569  * @type: a #GstTocEntryType.
570  *
571  * Converts @type to a string representation.
572  *
573  * Returns: Returns a human-readable string for @type. This string is
574  *    only for debugging purpose and should not be displayed in a user
575  *    interface.
576  */
577 const gchar *
578 gst_toc_entry_type_get_nick (GstTocEntryType type)
579 {
580   switch (type) {
581     case GST_TOC_ENTRY_TYPE_ANGLE:
582       return "angle";
583     case GST_TOC_ENTRY_TYPE_VERSION:
584       return "version";
585     case GST_TOC_ENTRY_TYPE_EDITION:
586       return "edition";
587     case GST_TOC_ENTRY_TYPE_TITLE:
588       return "title";
589     case GST_TOC_ENTRY_TYPE_TRACK:
590       return "track";
591     case GST_TOC_ENTRY_TYPE_CHAPTER:
592       return "chapter";
593     default:
594       break;
595   }
596   return "invalid";
597 }
598
599 /**
600  * gst_toc_entry_get_entry_type:
601  * @entry: a #GstTocEntry
602  *
603  * Returns: @entry's entry type
604  */
605 GstTocEntryType
606 gst_toc_entry_get_entry_type (const GstTocEntry * entry)
607 {
608   g_return_val_if_fail (entry != NULL, GST_TOC_ENTRY_TYPE_INVALID);
609
610   return entry->type;
611 }
612
613 /**
614  * gst_toc_entry_is_alternative:
615  * @entry: a #GstTocEntry
616  *
617  * Returns: %TRUE if @entry's type is an alternative type, otherwise %FALSE
618  */
619 gboolean
620 gst_toc_entry_is_alternative (const GstTocEntry * entry)
621 {
622   g_return_val_if_fail (entry != NULL, FALSE);
623
624   return GST_TOC_ENTRY_TYPE_IS_ALTERNATIVE (entry->type);
625 }
626
627 /**
628  * gst_toc_entry_is_sequence:
629  * @entry: a #GstTocEntry
630  *
631  * Returns: %TRUE if @entry's type is a sequence type, otherwise %FALSE
632  */
633 gboolean
634 gst_toc_entry_is_sequence (const GstTocEntry * entry)
635 {
636   g_return_val_if_fail (entry != NULL, FALSE);
637
638   return GST_TOC_ENTRY_TYPE_IS_SEQUENCE (entry->type);
639 }
640
641 /**
642  * gst_toc_entry_get_uid:
643  * @entry: A #GstTocEntry instance
644  *
645  * Gets the UID of @entry.
646  *
647  * Returns: (transfer none): The UID of @entry
648  */
649 const gchar *
650 gst_toc_entry_get_uid (const GstTocEntry * entry)
651 {
652   g_return_val_if_fail (entry != NULL, NULL);
653
654   return entry->uid;
655 }
656
657 /**
658  * gst_toc_entry_append_sub_entry:
659  * @entry: A #GstTocEntry instance
660  * @subentry: (transfer full): A #GstTocEntry
661  *
662  * Appends the #GstTocEntry @subentry to @entry.
663  */
664 void
665 gst_toc_entry_append_sub_entry (GstTocEntry * entry, GstTocEntry * subentry)
666 {
667   g_return_if_fail (entry != NULL);
668   g_return_if_fail (subentry != NULL);
669   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (entry)));
670   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST
671           (subentry)));
672   g_return_if_fail (subentry->toc == NULL);
673   g_return_if_fail (subentry->parent == NULL);
674
675   entry->subentries = g_list_append (entry->subentries, subentry);
676   subentry->toc = entry->toc;
677   subentry->parent = entry;
678
679   GST_LOG ("appended %s subentry with uid %s to entry %s",
680       gst_toc_entry_type_get_nick (subentry->type), subentry->uid, entry->uid);
681 }
682
683 /**
684  * gst_toc_entry_get_sub_entries:
685  * @entry: A #GstTocEntry instance
686  *
687  * Gets the sub-entries of @entry.
688  *
689  * Returns: (transfer none) (element-type Gst.TocEntry): A #GList of #GstTocEntry of @entry
690  */
691 GList *
692 gst_toc_entry_get_sub_entries (const GstTocEntry * entry)
693 {
694   g_return_val_if_fail (entry != NULL, NULL);
695
696   return entry->subentries;
697 }
698
699 /**
700  * gst_toc_entry_set_tags:
701  * @entry: A #GstTocEntry instance
702  * @tags: (allow-none) (transfer full): A #GstTagList or %NULL
703  *
704  * Set a #GstTagList with tags for the complete @entry.
705  */
706 void
707 gst_toc_entry_set_tags (GstTocEntry * entry, GstTagList * tags)
708 {
709   g_return_if_fail (entry != NULL);
710   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (entry)));
711
712   if (entry->tags)
713     gst_tag_list_unref (entry->tags);
714   entry->tags = tags;
715 }
716
717 /**
718  * gst_toc_entry_merge_tags:
719  * @entry: A #GstTocEntry instance
720  * @tags: (allow-none): A #GstTagList or %NULL
721  * @mode: A #GstTagMergeMode
722  *
723  * Merge @tags into the existing tags of @entry using @mode.
724  */
725 void
726 gst_toc_entry_merge_tags (GstTocEntry * entry, GstTagList * tags,
727     GstTagMergeMode mode)
728 {
729   g_return_if_fail (entry != NULL);
730   g_return_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (entry)));
731
732   if (!entry->tags) {
733     entry->tags = gst_tag_list_ref (tags);
734   } else {
735     GstTagList *tmp = gst_tag_list_merge (entry->tags, tags, mode);
736     gst_tag_list_unref (entry->tags);
737     entry->tags = tmp;
738   }
739 }
740
741 /**
742  * gst_toc_entry_get_tags:
743  * @entry: A #GstTocEntry instance
744  *
745  * Gets the tags for @entry.
746  *
747  * Returns: (transfer none): A #GstTagList for @entry
748  */
749 GstTagList *
750 gst_toc_entry_get_tags (const GstTocEntry * entry)
751 {
752   g_return_val_if_fail (entry != NULL, NULL);
753
754   return entry->tags;
755 }
756
757 /**
758  * gst_toc_entry_get_toc:
759  * @entry: A #GstTocEntry instance
760  *
761  * Gets the parent #GstToc of @entry.
762  *
763  * Returns: (transfer none): The parent #GstToc of @entry
764  */
765 GstToc *
766 gst_toc_entry_get_toc (GstTocEntry * entry)
767 {
768   g_return_val_if_fail (entry != NULL, NULL);
769
770   return entry->toc;
771 }
772
773 /**
774  * gst_toc_entry_get_parent:
775  * @entry: A #GstTocEntry instance
776  *
777  * Gets the parent #GstTocEntry of @entry.
778  *
779  * Returns: (transfer none): The parent #GstTocEntry of @entry
780  */
781 GstTocEntry *
782 gst_toc_entry_get_parent (GstTocEntry * entry)
783 {
784   g_return_val_if_fail (entry != NULL, NULL);
785
786   return entry->parent;
787 }
788
789 #ifndef GST_DISABLE_GST_DEBUG
790 static void
791 gst_toc_dump_entries (GList * entries, guint depth)
792 {
793   GList *e;
794   gchar *indent;
795
796   indent = g_malloc0 (depth + 1);
797   memset (indent, ' ', depth);
798   for (e = entries; e != NULL; e = e->next) {
799     GstTocEntry *entry = e->data;
800
801     GST_TRACE ("%s+ %s (%s), %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT ", "
802         "tags: %" GST_PTR_FORMAT, indent, entry->uid,
803         gst_toc_entry_type_get_nick (entry->type),
804         GST_TIME_ARGS (entry->start), GST_TIME_ARGS (entry->stop), entry->tags);
805
806     if (entry->subentries != NULL)
807       gst_toc_dump_entries (entry->subentries, depth + 2);
808   }
809   g_free (indent);
810 }
811 #endif
812
813 void
814 gst_toc_dump (GstToc * toc)
815 {
816 #ifndef GST_DISABLE_GST_DEBUG
817   GST_TRACE ("        Toc %p, scope: %s, tags: %" GST_PTR_FORMAT, toc,
818       (toc->scope == GST_TOC_SCOPE_GLOBAL) ? "global" : "current", toc->tags);
819   gst_toc_dump_entries (toc->entries, 2);
820 #endif
821 }
822
823 void
824 _priv_gst_toc_initialize (void)
825 {
826   _gst_toc_type = gst_toc_get_type ();
827   _gst_toc_entry_type = gst_toc_entry_get_type ();
828 }