gstfunnel: avoid access of freed pad
[platform/upstream/gstreamer.git] / gst / gstmessage.c
index 6b8b2c0..ae03f99 100644 (file)
@@ -480,13 +480,17 @@ gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
 GstMessage *
 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
 {
+  GstStructure *s;
   GstMessage *message;
+  GValue val = G_VALUE_INIT;
 
-  g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
-
-  message =
-      gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
+  g_return_val_if_fail (GST_IS_TAG_LIST (tag_list), NULL);
 
+  s = gst_structure_new_id_empty (GST_QUARK (MESSAGE_TAG));
+  g_value_init (&val, GST_TYPE_TAG_LIST);
+  g_value_take_boxed (&val, tag_list);
+  gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
+  message = gst_message_new_custom (GST_MESSAGE_TAG, src, s);
   return message;
 }
 
@@ -553,7 +557,7 @@ gst_message_new_state_changed (GstObject * src,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STATE_CHANGED),
       GST_QUARK (OLD_STATE), GST_TYPE_STATE, (gint) oldstate,
       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) newstate,
       GST_QUARK (PENDING_STATE), GST_TYPE_STATE, (gint) pending, NULL);
@@ -866,24 +870,26 @@ gst_message_new_async_start (GstObject * src)
 /**
  * gst_message_new_async_done:
  * @src: (transfer none): The object originating the message.
- * @reset_time: if the running_time should be reset
+ * @running_time: the desired running_time
  *
  * The message is posted when elements completed an ASYNC state change.
- * @reset_time is set to TRUE when the element requests a new running_time
- * before going to PLAYING.
+ * @running_time contains the time of the desired running_time when this
+ * elements goes to PLAYING. A value of #GST_CLOCK_TIME_NONE for @running_time
+ * means that the element has no clock interaction and thus doesn't care about
+ * the running_time of the pipeline.
  *
  * Returns: (transfer full): The new async_done message.
  *
  * MT safe.
  */
 GstMessage *
-gst_message_new_async_done (GstObject * src, gboolean reset_time)
+gst_message_new_async_done (GstObject * src, GstClockTime running_time)
 {
   GstMessage *message;
   GstStructure *structure;
 
   structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
-      GST_QUARK (RESET_TIME), G_TYPE_BOOLEAN, reset_time, NULL);
+      GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
   message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
 
   return message;
@@ -1004,7 +1010,7 @@ gst_message_has_name (GstMessage * message, const gchar * name)
  *       gst_message_parse_tag (msg, &tags);
  *       g_print ("Got tags from element %s\n", GST_OBJECT_NAME (msg->src));
  *       handle_tags (tags);
- *       gst_tag_list_free (tags);
+ *       gst_tag_list_unref (tags);
  *       break;
  *     }
  *     ...
@@ -1017,16 +1023,12 @@ gst_message_has_name (GstMessage * message, const gchar * name)
 void
 gst_message_parse_tag (GstMessage * message, GstTagList ** tag_list)
 {
-  GstStructure *ret;
-
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TAG);
   g_return_if_fail (tag_list != NULL);
 
-  ret = gst_structure_copy (GST_MESSAGE_STRUCTURE (message));
-  gst_structure_remove_field (ret, "source-pad");
-
-  *tag_list = (GstTagList *) ret;
+  gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
+      GST_QUARK (TAGLIST), GST_TYPE_TAG_LIST, tag_list, NULL);
 }
 
 /**
@@ -1542,14 +1544,14 @@ gst_message_parse_duration (GstMessage * message, GstFormat * format,
 /**
  * gst_message_parse_async_done:
  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
- * @reset_time: (out): Result location for the reset_time or NULL
+ * @running_time: (out): Result location for the running_time or NULL
  *
- * Extract the reset_time from the async_done message.
+ * Extract the running_time from the async_done message.
  *
  * MT safe.
  */
 void
-gst_message_parse_async_done (GstMessage * message, gboolean * reset_time)
+gst_message_parse_async_done (GstMessage * message, GstClockTime * running_time)
 {
   GstStructure *structure;
 
@@ -1557,10 +1559,10 @@ gst_message_parse_async_done (GstMessage * message, gboolean * reset_time)
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
 
   structure = GST_MESSAGE_STRUCTURE (message);
-  if (reset_time)
-    *reset_time =
-        g_value_get_boolean (gst_structure_id_get_value (structure,
-            GST_QUARK (RESET_TIME)));
+  if (running_time)
+    *running_time =
+        g_value_get_uint64 (gst_structure_id_get_value (structure,
+            GST_QUARK (RUNNING_TIME)));
 }
 
 /**
@@ -2210,7 +2212,7 @@ gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
  * @toc: (out): return location for the TOC.
  * @updated: (out): return location for the updated flag.
  *
- * Extract the TOC from the #GstMessage. The TOC returned in the
+ * Extract thef TOC from the #GstMessage. The TOC returned in the
  * output argument is a copy; the caller must free it with
  * gst_toc_free() when done.
  *
@@ -2231,3 +2233,52 @@ gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
     *updated =
         __gst_toc_structure_get_updated (GST_MESSAGE_STRUCTURE (message));
 }
+
+/**
+ * gst_message_new_reset_time:
+ * @src: (transfer none): The object originating the message.
+ * @running_time: the requested running-time
+ *
+ * This message is posted when the pipeline running-time should be reset to
+ * @running_time, like after a flushing seek.
+ *
+ * Returns: (transfer full): The new reset_time message.
+ *
+ * MT safe.
+ */
+GstMessage *
+gst_message_new_reset_time (GstObject * src, GstClockTime running_time)
+{
+  GstMessage *message;
+  GstStructure *structure;
+
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_RESET_TIME),
+      GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
+  message = gst_message_new_custom (GST_MESSAGE_RESET_TIME, src, structure);
+
+  return message;
+}
+
+/**
+ * gst_message_parse_reset_time:
+ * @message: A valid #GstMessage of type GST_MESSAGE_RESET_TIME.
+ * @running_time: (out): Result location for the running_time or NULL
+ *
+ * Extract the running-time from the RESET_TIME message.
+ *
+ * MT safe.
+ */
+void
+gst_message_parse_reset_time (GstMessage * message, GstClockTime * running_time)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_IS_MESSAGE (message));
+  g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_RESET_TIME);
+
+  structure = GST_MESSAGE_STRUCTURE (message);
+  if (running_time)
+    *running_time =
+        g_value_get_uint64 (gst_structure_id_get_value (structure,
+            GST_QUARK (RUNNING_TIME)));
+}