baseparse: add API for subclass to set tags
authorTim-Philipp Müller <tim@centricular.com>
Sun, 16 Aug 2015 09:15:56 +0000 (10:15 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Sun, 16 Aug 2015 13:32:23 +0000 (14:32 +0100)
This is needed so that we can do proper tag handling
all around, and combine the upstream tags with the
tags set by the subclass and any extra tags the
base class may want to add.

API: gst_base_parse_merge_tags()

https://bugzilla.gnome.org/show_bug.cgi?id=679768

docs/libs/gstreamer-libs-sections.txt
libs/gst/base/gstbaseparse.c
libs/gst/base/gstbaseparse.h
win32/common/libgstbase.def

index 8d50c60..6819fed 100644 (file)
@@ -199,6 +199,7 @@ gst_adapter_get_type
 GstBaseParse
 GstBaseParseClass
 
+gst_base_parse_merge_tags
 gst_base_parse_set_duration
 gst_base_parse_set_average_bitrate
 gst_base_parse_set_min_frame_size
index ed4a34c..30995f5 100644 (file)
@@ -362,6 +362,8 @@ struct _GstBaseParsePrivate
 
   /* Tag handling (stream tags only, global tags are passed through as-is) */
   GstTagList *upstream_tags;
+  GstTagList *parser_tags;
+  GstTagMergeMode parser_tags_merge_mode;
   gboolean tags_changed;
 };
 
@@ -874,6 +876,12 @@ gst_base_parse_reset (GstBaseParse * parse)
 
   gst_base_parse_set_upstream_tags (parse, NULL);
 
+  if (parse->priv->parser_tags) {
+    gst_tag_list_unref (parse->priv->parser_tags);
+    parse->priv->parser_tags = NULL;
+  }
+  parse->priv->parser_tags_merge_mode = GST_TAG_MERGE_APPEND;
+
   parse->priv->new_frame = TRUE;
 
   parse->priv->first_buffer = TRUE;
@@ -4705,3 +4713,47 @@ gst_base_parse_set_ts_at_offset (GstBaseParse * parse, gsize offset)
   if (GST_CLOCK_TIME_IS_VALID (dts) && (parse->priv->prev_dts != dts))
     parse->priv->prev_dts = parse->priv->next_dts = dts;
 }
+
+/**
+ * gst_base_parse_merge_tags:
+ * @parse: a #GstBaseParse
+ * @tags: (allow-none): a #GstTagList to merge, or NULL to unset
+ *     previously-set tags
+ * @mode: the #GstTagMergeMode to use, usually #GST_TAG_MERGE_REPLACE
+ *
+ * Sets the parser subclass's tags and how they should be merged with any
+ * upstream stream tags. This will override any tags previously-set
+ * with gst_base_parse_merge_tags().
+ *
+ * Note that this is provided for convenience, and the subclass is
+ * not required to use this and can still do tag handling on its own.
+ *
+ * Since: 1.6
+ */
+void
+gst_base_parse_merge_tags (GstBaseParse * parse, GstTagList * tags,
+    GstTagMergeMode mode)
+{
+  g_return_if_fail (GST_IS_BASE_PARSE (parse));
+  g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
+  g_return_if_fail (tags == NULL || mode != GST_TAG_MERGE_UNDEFINED);
+
+  GST_OBJECT_LOCK (parse);
+
+  if (tags != parse->priv->parser_tags) {
+    if (parse->priv->parser_tags) {
+      gst_tag_list_unref (parse->priv->parser_tags);
+      parse->priv->parser_tags = NULL;
+      parse->priv->parser_tags_merge_mode = GST_TAG_MERGE_APPEND;
+    }
+    if (tags) {
+      parse->priv->parser_tags = gst_tag_list_ref (tags);
+      parse->priv->parser_tags_merge_mode = mode;
+    }
+
+    GST_DEBUG_OBJECT (parse, "setting parser tags to %" GST_PTR_FORMAT, tags);
+    parse->priv->tags_changed = TRUE;
+  }
+
+  GST_OBJECT_UNLOCK (parse);
+}
index 66c3d04..94522cc 100644 (file)
@@ -345,6 +345,10 @@ gboolean        gst_base_parse_add_index_entry (GstBaseParse * parse,
 void            gst_base_parse_set_ts_at_offset (GstBaseParse *parse,
                                                  gsize offset);
 
+void            gst_base_parse_merge_tags       (GstBaseParse  * parse,
+                                                 GstTagList    * tags,
+                                                 GstTagMergeMode mode);
+
 G_END_DECLS
 
 #endif /* __GST_BASE_PARSE_H__ */
index 6a12e06..ff25b51 100644 (file)
@@ -33,6 +33,7 @@ EXPORTS
        gst_base_parse_frame_init
        gst_base_parse_frame_new
        gst_base_parse_get_type
+       gst_base_parse_merge_tags
        gst_base_parse_push_frame
        gst_base_parse_set_average_bitrate
        gst_base_parse_set_duration