- GstTocEntry *ret, *subentry;
- const GValue *val;
- const GstStructure *subentry_struct;
- GstTagList *list;
- GstStructure *st;
- gint count, i;
- const gchar *uid;
- guint chapters_count = 0, editions_count = 0;
-
- g_return_val_if_fail (entry != NULL, NULL);
- g_return_val_if_fail (gst_structure_id_has_field_typed (entry,
- GST_QUARK (UID), G_TYPE_STRING), NULL);
- g_return_val_if_fail (gst_structure_id_has_field_typed (entry,
- GST_QUARK (TYPE), GST_TYPE_TOC_ENTRY_TYPE), NULL);
-
- val = gst_structure_id_get_value (entry, GST_QUARK (UID));
- uid = g_value_get_string (val);
-
- ret = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, uid);
-
- gst_structure_get_enum (entry, g_quark_to_string (GST_QUARK (TYPE)),
- GST_TYPE_TOC_ENTRY_TYPE, (gint *) & (ret->type));
-
- if (gst_structure_id_has_field_typed (entry,
- GST_QUARK (SUB_ENTRIES), GST_TYPE_ARRAY)) {
- count = gst_toc_entry_structure_n_subentries (entry);
-
- for (i = 0; i < count; ++i) {
- subentry_struct = gst_toc_entry_structure_nth_subentry (entry, i);
- subentry = gst_toc_entry_from_structure (subentry_struct, level + 1);
-
- /* skip empty editions */
- if (G_UNLIKELY (subentry->type == GST_TOC_ENTRY_TYPE_EDITION
- && subentry->subentries == NULL)) {
- g_warning
- ("Empty edition found while deserializing TOC from GstStructure, skipping");
- continue;
- }
-
- if (subentry->type == GST_TOC_ENTRY_TYPE_EDITION)
- ++editions_count;
- else
- ++chapters_count;
-
- /* check for mixed content */
- if (G_UNLIKELY (chapters_count > 0 && editions_count > 0)) {
- g_critical
- ("Mixed editions and chapters in the TOC contents, the TOC is broken");
- gst_toc_entry_free (subentry);
- gst_toc_entry_free (ret);
- return NULL;
- }
-
- if (G_UNLIKELY (subentry == NULL)) {
- gst_toc_entry_free (ret);
- return NULL;
- }
-
- ret->subentries = g_list_prepend (ret->subentries, subentry);
- }
-
- ret->subentries = g_list_reverse (ret->subentries);
- }