gstfunnel: avoid access of freed pad
[platform/upstream/gstreamer.git] / gst / gstmessage.c
index 423ebc2..ae03f99 100644 (file)
@@ -32,7 +32,7 @@
  *
  * Messages are posted by objects in the pipeline and are passed to the
  * application using the #GstBus.
-
+ *
  * The basic use pattern of posting a message on a #GstBus is as follows:
  *
  * <example>
 #include "gstquark.h"
 
 
-#define GST_MESSAGE_SEQNUM(e) ((GstMessage*)e)->abidata.ABI.seqnum
-
-static void gst_message_finalize (GstMessage * message);
-static GstMessage *_gst_message_copy (GstMessage * message);
-
-static GstMiniObjectClass *parent_class = NULL;
-
-void
-_gst_message_initialize (void)
+typedef struct
 {
-  GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
+  GstMessage message;
 
-  /* the GstMiniObject types need to be class_ref'd once before it can be
-   * done from multiple threads;
-   * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
-  g_type_class_ref (gst_message_get_type ());
-}
+  GstStructure *structure;
+} GstMessageImpl;
+
+#define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure)
 
 typedef struct
 {
@@ -113,9 +104,33 @@ static GstMessageQuarks message_quarks[] = {
   {GST_MESSAGE_STEP_START, "step-start", 0},
   {GST_MESSAGE_QOS, "qos", 0},
   {GST_MESSAGE_PROGRESS, "progress", 0},
+  {GST_MESSAGE_TOC, "toc", 0},
   {0, NULL, 0}
 };
 
+static GType _gst_message_type = 0;
+GST_DEFINE_MINI_OBJECT_TYPE (GstMessage, gst_message);
+
+void
+_priv_gst_message_initialize (void)
+{
+  gint i;
+
+  GST_CAT_INFO (GST_CAT_GST_INIT, "init messages");
+
+  /* the GstMiniObject types need to be class_ref'd once before it can be
+   * done from multiple threads;
+   * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
+  gst_message_get_type ();
+
+  for (i = 0; message_quarks[i].name; i++) {
+    message_quarks[i].quark =
+        g_quark_from_static_string (message_quarks[i].name);
+  }
+
+  _gst_message_type = gst_message_get_type ();
+}
+
 /**
  * gst_message_type_get_name:
  * @type: the message type
@@ -156,39 +171,11 @@ gst_message_type_to_quark (GstMessageType type)
   return 0;
 }
 
-#define _do_init \
-{ \
-  gint i; \
-  \
-  for (i = 0; message_quarks[i].name; i++) { \
-    message_quarks[i].quark = \
-        g_quark_from_static_string (message_quarks[i].name); \
-  } \
-}
-
-G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
-    _do_init);
-
-static void
-gst_message_class_init (GstMessageClass * klass)
-{
-  parent_class = g_type_class_peek_parent (klass);
-
-  klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
-  klass->mini_object_class.finalize =
-      (GstMiniObjectFinalizeFunction) gst_message_finalize;
-}
-
 static void
-gst_message_init (GstMessage * message)
+_gst_message_free (GstMessage * message)
 {
-  GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
-  GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
-}
+  GstStructure *structure;
 
-static void
-gst_message_finalize (GstMessage * message)
-{
   g_return_if_fail (message != NULL);
 
   GST_CAT_LOG (GST_CAT_MESSAGE, "finalize message %p, %s from %s", message,
@@ -199,53 +186,76 @@ gst_message_finalize (GstMessage * message)
     GST_MESSAGE_SRC (message) = NULL;
   }
 
-  if (message->lock) {
+  if (message->lock.p) {
     GST_MESSAGE_LOCK (message);
     GST_MESSAGE_SIGNAL (message);
     GST_MESSAGE_UNLOCK (message);
   }
 
-  if (message->structure) {
-    gst_structure_set_parent_refcount (message->structure, NULL);
-    gst_structure_free (message->structure);
+  structure = GST_MESSAGE_STRUCTURE (message);
+  if (structure) {
+    gst_structure_set_parent_refcount (structure, NULL);
+    gst_structure_free (structure);
   }
 
-/*   GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (message)); */
+  g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
 }
 
+static void
+gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
+    GstObject * src);
+
 static GstMessage *
 _gst_message_copy (GstMessage * message)
 {
-  GstMessage *copy;
+  GstMessageImpl *copy;
+  GstStructure *structure;
 
   GST_CAT_LOG (GST_CAT_MESSAGE, "copy message %p, %s from %s", message,
       GST_MESSAGE_TYPE_NAME (message),
       GST_OBJECT_NAME (GST_MESSAGE_SRC (message)));
 
-  copy = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
+  copy = g_slice_new0 (GstMessageImpl);
 
-  /* FIXME, need to copy relevant data from the miniobject. */
-  //memcpy (copy, message, sizeof (GstMessage));
+  gst_message_init (copy, sizeof (GstMessageImpl), GST_MESSAGE_TYPE (message),
+      GST_MESSAGE_SRC (message));
 
-  GST_MESSAGE_GET_LOCK (copy) = GST_MESSAGE_GET_LOCK (message);
-  GST_MESSAGE_COND (copy) = GST_MESSAGE_COND (message);
-  GST_MESSAGE_TYPE (copy) = GST_MESSAGE_TYPE (message);
   GST_MESSAGE_TIMESTAMP (copy) = GST_MESSAGE_TIMESTAMP (message);
   GST_MESSAGE_SEQNUM (copy) = GST_MESSAGE_SEQNUM (message);
 
-  if (GST_MESSAGE_SRC (message)) {
-    GST_MESSAGE_SRC (copy) = gst_object_ref (GST_MESSAGE_SRC (message));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  if (structure) {
+    GST_MESSAGE_STRUCTURE (copy) = gst_structure_copy (structure);
+    gst_structure_set_parent_refcount (GST_MESSAGE_STRUCTURE (copy),
+        &copy->message.mini_object.refcount);
+  } else {
+    GST_MESSAGE_STRUCTURE (copy) = NULL;
   }
 
-  if (message->structure) {
-    copy->structure = gst_structure_copy (message->structure);
-    gst_structure_set_parent_refcount (copy->structure,
-        &copy->mini_object.refcount);
-  }
+  return GST_MESSAGE_CAST (copy);
+}
 
-  return copy;
+static void
+gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type,
+    GstObject * src)
+{
+  gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type,
+      size);
+
+  message->message.mini_object.copy =
+      (GstMiniObjectCopyFunction) _gst_message_copy;
+  message->message.mini_object.free =
+      (GstMiniObjectFreeFunction) _gst_message_free;
+
+  GST_MESSAGE_TYPE (message) = type;
+  if (src)
+    gst_object_ref (src);
+  GST_MESSAGE_SRC (message) = src;
+  GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
+  GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
 }
 
+
 /**
  * gst_message_new_custom:
  * @type: The #GstMessageType to distinguish messages
@@ -265,29 +275,33 @@ GstMessage *
 gst_message_new_custom (GstMessageType type, GstObject * src,
     GstStructure * structure)
 {
-  GstMessage *message;
+  GstMessageImpl *message;
 
-  message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
+  message = g_slice_new0 (GstMessageImpl);
 
   GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
       (src ? GST_OBJECT_NAME (src) : "NULL"), message,
       gst_message_type_get_name (type));
 
-  message->type = type;
-
-  if (src)
-    gst_object_ref (src);
-  message->src = src;
-
   if (structure) {
-    gst_structure_set_parent_refcount (structure,
-        &message->mini_object.refcount);
+    /* structure must not have a parent */
+    if (!gst_structure_set_parent_refcount (structure,
+            &message->message.mini_object.refcount))
+      goto had_parent;
   }
-  message->structure = structure;
+  gst_message_init (message, sizeof (GstMessageImpl), type, src);
 
-  GST_MESSAGE_SEQNUM (message) = gst_util_seqnum_next ();
+  GST_MESSAGE_STRUCTURE (message) = structure;
 
-  return message;
+  return GST_MESSAGE_CAST (message);
+
+  /* ERRORS */
+had_parent:
+  {
+    g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
+    g_warning ("structure is already owned by another object");
+    return NULL;
+  }
 }
 
 /**
@@ -387,8 +401,8 @@ gst_message_new_error (GstObject * src, GError * error, const gchar * debug)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_ERROR),
-      GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_ERROR),
+      GST_QUARK (GERROR), G_TYPE_ERROR, error,
       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
   message = gst_message_new_custom (GST_MESSAGE_ERROR, src, structure);
 
@@ -414,8 +428,8 @@ gst_message_new_warning (GstObject * src, GError * error, const gchar * debug)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_WARNING),
-      GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_WARNING),
+      GST_QUARK (GERROR), G_TYPE_ERROR, error,
       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
   message = gst_message_new_custom (GST_MESSAGE_WARNING, src, structure);
 
@@ -443,8 +457,8 @@ gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_INFO),
-      GST_QUARK (GERROR), GST_TYPE_G_ERROR, error,
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_INFO),
+      GST_QUARK (GERROR), G_TYPE_ERROR, error,
       GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
   message = gst_message_new_custom (GST_MESSAGE_INFO, src, structure);
 
@@ -466,46 +480,17 @@ gst_message_new_info (GstObject * src, GError * error, const gchar * debug)
 GstMessage *
 gst_message_new_tag (GstObject * src, GstTagList * tag_list)
 {
-  GstMessage *message;
-
-  g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
-
-  message =
-      gst_message_new_custom (GST_MESSAGE_TAG, src, (GstStructure *) tag_list);
-
-  return message;
-}
-
-/**
- * gst_message_new_tag_full:
- * @src: (transfer none): the object originating the message.
- * @pad: (transfer none): the originating pad for the tag.
- * @tag_list: (transfer full): the tag list for the message.
- *
- * Create a new tag message. The message will take ownership of the tag list.
- * The message is posted by elements that discovered a new taglist.
- *
- * MT safe.
- *
- * Returns: (transfer full): the new tag message.
- *
- * Since: 0.10.24
- */
-GstMessage *
-gst_message_new_tag_full (GstObject * src, GstPad * pad, GstTagList * tag_list)
-{
-  GstMessage *message;
   GstStructure *s;
+  GstMessage *message;
+  GValue val = G_VALUE_INIT;
 
-  g_return_val_if_fail (GST_IS_STRUCTURE (tag_list), NULL);
-  g_return_val_if_fail (pad == NULL || GST_IS_PAD (pad), NULL);
-
-  s = (GstStructure *) tag_list;
-  if (pad)
-    gst_structure_set (s, "source-pad", GST_TYPE_PAD, pad, NULL);
+  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;
 }
 
@@ -539,7 +524,7 @@ gst_message_new_buffering (GstObject * src, gint percent)
 
   g_return_val_if_fail (percent >= 0 && percent <= 100, NULL);
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_BUFFERING),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_BUFFERING),
       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent,
       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
@@ -572,7 +557,7 @@ gst_message_new_state_changed (GstObject * src,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (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);
@@ -627,7 +612,7 @@ gst_message_new_clock_provide (GstObject * src, GstClock * clock,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_PROVIDE),
       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock,
       GST_QUARK (READY), G_TYPE_BOOLEAN, ready, NULL);
   message = gst_message_new_custom (GST_MESSAGE_CLOCK_PROVIDE, src, structure);
@@ -657,7 +642,7 @@ gst_message_new_clock_lost (GstObject * src, GstClock * clock)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_CLOCK_LOST),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_CLOCK_LOST),
       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
   message = gst_message_new_custom (GST_MESSAGE_CLOCK_LOST, src, structure);
 
@@ -682,7 +667,7 @@ gst_message_new_new_clock (GstObject * src, GstClock * clock)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_NEW_CLOCK),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_NEW_CLOCK),
       GST_QUARK (CLOCK), GST_TYPE_CLOCK, clock, NULL);
   message = gst_message_new_custom (GST_MESSAGE_NEW_CLOCK, src, structure);
 
@@ -719,7 +704,7 @@ gst_message_new_structure_change (GstObject * src, GstStructureChangeType type,
   /* g_return_val_if_fail (GST_PAD_DIRECTION (src) == GST_PAD_SINK, NULL); */
   g_return_val_if_fail (GST_IS_ELEMENT (owner), NULL);
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STRUCTURE_CHANGE),
       GST_QUARK (TYPE), GST_TYPE_STRUCTURE_CHANGE_TYPE, type,
       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner,
       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy, NULL);
@@ -752,7 +737,7 @@ gst_message_new_segment_start (GstObject * src, GstFormat format,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_START),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_START),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_START, src, structure);
@@ -782,7 +767,7 @@ gst_message_new_segment_done (GstObject * src, GstFormat format,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_SEGMENT_DONE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_SEGMENT_DONE),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
   message = gst_message_new_custom (GST_MESSAGE_SEGMENT_DONE, src, structure);
@@ -854,7 +839,7 @@ gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_DURATION),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
   message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
@@ -865,27 +850,19 @@ gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration)
 /**
  * gst_message_new_async_start:
  * @src: (transfer none): The object originating the message.
- * @new_base_time: if a new base_time should be set on the element
  *
- * This message is posted by elements when they start an ASYNC state change. 
- * @new_base_time is set to TRUE when the element lost its state when it was
- * PLAYING.
+ * This message is posted by elements when they start an ASYNC state change.
  *
  * Returns: (transfer full): The new async_start message.
  *
  * MT safe.
- *
- * Since: 0.10.13
  */
 GstMessage *
-gst_message_new_async_start (GstObject * src, gboolean new_base_time)
+gst_message_new_async_start (GstObject * src)
 {
   GstMessage *message;
-  GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_ASYNC_START),
-      GST_QUARK (NEW_BASE_TIME), G_TYPE_BOOLEAN, new_base_time, NULL);
-  message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, structure);
+  message = gst_message_new_custom (GST_MESSAGE_ASYNC_START, src, NULL);
 
   return message;
 }
@@ -893,21 +870,27 @@ gst_message_new_async_start (GstObject * src, gboolean new_base_time)
 /**
  * gst_message_new_async_done:
  * @src: (transfer none): The object originating the message.
+ * @running_time: the desired running_time
  *
  * The message is posted when elements completed an ASYNC state change.
+ * @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.
- *
- * Since: 0.10.13
  */
 GstMessage *
-gst_message_new_async_done (GstObject * src)
+gst_message_new_async_done (GstObject * src, GstClockTime running_time)
 {
   GstMessage *message;
+  GstStructure *structure;
 
-  message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, NULL);
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_ASYNC_DONE),
+      GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time, NULL);
+  message = gst_message_new_custom (GST_MESSAGE_ASYNC_DONE, src, structure);
 
   return message;
 }
@@ -956,7 +939,7 @@ gst_message_new_request_state (GstObject * src, GstState state)
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_REQUEST_STATE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_REQUEST_STATE),
       GST_QUARK (NEW_STATE), GST_TYPE_STATE, (gint) state, NULL);
   message = gst_message_new_custom (GST_MESSAGE_REQUEST_STATE, src, structure);
 
@@ -980,7 +963,33 @@ gst_message_get_structure (GstMessage * message)
 {
   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
 
-  return message->structure;
+  return GST_MESSAGE_STRUCTURE (message);
+}
+
+/**
+ * gst_message_has_name:
+ * @message: The #GstMessage.
+ * @name: name to check
+ *
+ * Checks if @message has the given @name. This function is usually used to
+ * check the name of a custom message.
+ *
+ * Returns: %TRUE if @name matches the name of the message structure.
+ *
+ * Since: 0.10.20
+ */
+gboolean
+gst_message_has_name (GstMessage * message, const gchar * name)
+{
+  GstStructure *structure;
+
+  g_return_val_if_fail (GST_IS_MESSAGE (message), FALSE);
+
+  structure = GST_MESSAGE_STRUCTURE (message);
+  if (structure == NULL)
+    return FALSE;
+
+  return gst_structure_has_name (structure, name);
 }
 
 /**
@@ -1001,7 +1010,7 @@ gst_message_get_structure (GstMessage * message)
  *       gst_message_parse_tag (msg, &amp;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;
  *     }
  *     ...
@@ -1014,58 +1023,12 @@ gst_message_get_structure (GstMessage * message)
 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 (message->structure);
-  gst_structure_remove_field (ret, "source-pad");
-
-  *tag_list = (GstTagList *) ret;
-}
-
-/**
- * gst_message_parse_tag_full:
- * @message: A valid #GstMessage of type GST_MESSAGE_TAG.
- * @pad: (out callee-allocates): location where the originating pad is stored,
- *     unref after usage
- * @tag_list: (out callee-allocates): return location for the tag-list.
- *
- * Extracts the tag list from the GstMessage. The tag list returned in the
- * output argument is a copy; the caller must free it when done.
- *
- * MT safe.
- *
- * Since: 0.10.24
- */
-void
-gst_message_parse_tag_full (GstMessage * message, GstPad ** pad,
-    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 (message->structure);
-
-  if (gst_structure_has_field (ret, "source-pad") && pad) {
-    const GValue *v;
-
-    v = gst_structure_get_value (ret, "source-pad");
-    if (v && G_VALUE_HOLDS (v, GST_TYPE_PAD))
-      *pad = g_value_dup_object (v);
-    else
-      *pad = NULL;
-  } else if (pad) {
-    *pad = NULL;
-  }
-  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);
 }
 
 /**
@@ -1087,8 +1050,9 @@ gst_message_parse_buffering (GstMessage * message, gint * percent)
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
 
   if (percent)
-    *percent = g_value_get_int (gst_structure_id_get_value (message->structure,
-            GST_QUARK (BUFFER_PERCENT)));
+    *percent =
+        g_value_get_int (gst_structure_id_get_value (GST_MESSAGE_STRUCTURE
+            (message), GST_QUARK (BUFFER_PERCENT)));
 }
 
 /**
@@ -1109,7 +1073,7 @@ gst_message_set_buffering_stats (GstMessage * message, GstBufferingMode mode,
 {
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
 
-  gst_structure_id_set (message->structure,
+  gst_structure_id_set (GST_MESSAGE_STRUCTURE (message),
       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
@@ -1134,21 +1098,24 @@ gst_message_parse_buffering_stats (GstMessage * message,
     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
     gint64 * buffering_left)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_BUFFERING);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (mode)
     *mode = (GstBufferingMode)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (BUFFERING_MODE)));
   if (avg_in)
-    *avg_in = g_value_get_int (gst_structure_id_get_value (message->structure,
+    *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
             GST_QUARK (AVG_IN_RATE)));
   if (avg_out)
-    *avg_out = g_value_get_int (gst_structure_id_get_value (message->structure,
+    *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
             GST_QUARK (AVG_OUT_RATE)));
   if (buffering_left)
     *buffering_left =
-        g_value_get_int64 (gst_structure_id_get_value (message->structure,
+        g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (BUFFERING_LEFT)));
 }
 
@@ -1186,20 +1153,23 @@ void
 gst_message_parse_state_changed (GstMessage * message,
     GstState * oldstate, GstState * newstate, GstState * pending)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (oldstate)
     *oldstate = (GstState)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (OLD_STATE)));
   if (newstate)
     *newstate = (GstState)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (NEW_STATE)));
   if (pending)
     *pending = (GstState)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (PENDING_STATE)));
 }
 
@@ -1220,18 +1190,19 @@ gst_message_parse_clock_provide (GstMessage * message, GstClock ** clock,
     gboolean * ready)
 {
   const GValue *clock_gvalue;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_PROVIDE);
 
-  clock_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
   g_return_if_fail (clock_gvalue != NULL);
   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
 
   if (ready)
     *ready =
-        g_value_get_boolean (gst_structure_id_get_value (message->structure,
+        g_value_get_boolean (gst_structure_id_get_value (structure,
             GST_QUARK (READY)));
   if (clock)
     *clock = (GstClock *) g_value_get_object (clock_gvalue);
@@ -1251,12 +1222,13 @@ void
 gst_message_parse_clock_lost (GstMessage * message, GstClock ** clock)
 {
   const GValue *clock_gvalue;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_CLOCK_LOST);
 
-  clock_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
   g_return_if_fail (clock_gvalue != NULL);
   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
 
@@ -1279,12 +1251,13 @@ void
 gst_message_parse_new_clock (GstMessage * message, GstClock ** clock)
 {
   const GValue *clock_gvalue;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEW_CLOCK);
 
-  clock_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (CLOCK));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  clock_gvalue = gst_structure_id_get_value (structure, GST_QUARK (CLOCK));
   g_return_if_fail (clock_gvalue != NULL);
   g_return_if_fail (G_VALUE_TYPE (clock_gvalue) == GST_TYPE_CLOCK);
 
@@ -1312,24 +1285,25 @@ gst_message_parse_structure_change (GstMessage * message,
     GstStructureChangeType * type, GstElement ** owner, gboolean * busy)
 {
   const GValue *owner_gvalue;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STRUCTURE_CHANGE);
 
-  owner_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
   g_return_if_fail (owner_gvalue != NULL);
   g_return_if_fail (G_VALUE_TYPE (owner_gvalue) == GST_TYPE_ELEMENT);
 
   if (type)
     *type = (GstStructureChangeType)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (TYPE)));
   if (owner)
     *owner = (GstElement *) g_value_get_object (owner_gvalue);
   if (busy)
     *busy =
-        g_value_get_boolean (gst_structure_id_get_value (message->structure,
+        g_value_get_boolean (gst_structure_id_get_value (structure,
             GST_QUARK (BUSY)));
 }
 
@@ -1371,14 +1345,15 @@ gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
 {
   const GValue *error_gvalue;
   GError *error_val;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
 
-  error_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
   g_return_if_fail (error_gvalue != NULL);
-  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
+  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
 
   error_val = (GError *) g_value_get_boxed (error_gvalue);
   if (error_val)
@@ -1388,7 +1363,7 @@ gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
 
   if (debug)
     *debug =
-        g_value_dup_string (gst_structure_id_get_value (message->structure,
+        g_value_dup_string (gst_structure_id_get_value (structure,
             GST_QUARK (DEBUG)));
 }
 
@@ -1410,14 +1385,15 @@ gst_message_parse_warning (GstMessage * message, GError ** gerror,
 {
   const GValue *error_gvalue;
   GError *error_val;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
 
-  error_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
   g_return_if_fail (error_gvalue != NULL);
-  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
+  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
 
   error_val = (GError *) g_value_get_boxed (error_gvalue);
   if (error_val)
@@ -1427,7 +1403,7 @@ gst_message_parse_warning (GstMessage * message, GError ** gerror,
 
   if (debug)
     *debug =
-        g_value_dup_string (gst_structure_id_get_value (message->structure,
+        g_value_dup_string (gst_structure_id_get_value (structure,
             GST_QUARK (DEBUG)));
 }
 
@@ -1450,14 +1426,15 @@ gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
 {
   const GValue *error_gvalue;
   GError *error_val;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
 
-  error_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (GERROR));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR));
   g_return_if_fail (error_gvalue != NULL);
-  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == GST_TYPE_G_ERROR);
+  g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
 
   error_val = (GError *) g_value_get_boxed (error_gvalue);
   if (error_val)
@@ -1467,7 +1444,7 @@ gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
 
   if (debug)
     *debug =
-        g_value_dup_string (gst_structure_id_get_value (message->structure,
+        g_value_dup_string (gst_structure_id_get_value (structure,
             GST_QUARK (DEBUG)));
 }
 
@@ -1485,16 +1462,19 @@ void
 gst_message_parse_segment_start (GstMessage * message, GstFormat * format,
     gint64 * position)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_START);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (format)
     *format = (GstFormat)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (position)
     *position =
-        g_value_get_int64 (gst_structure_id_get_value (message->structure,
+        g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (POSITION)));
 }
 
@@ -1512,16 +1492,19 @@ void
 gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
     gint64 * position)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_SEGMENT_DONE);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (format)
     *format = (GstFormat)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (position)
     *position =
-        g_value_get_int64 (gst_structure_id_get_value (message->structure,
+        g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (POSITION)));
 }
 
@@ -1542,40 +1525,44 @@ void
 gst_message_parse_duration (GstMessage * message, GstFormat * format,
     gint64 * duration)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (format)
     *format = (GstFormat)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (duration)
     *duration =
-        g_value_get_int64 (gst_structure_id_get_value (message->structure,
+        g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (DURATION)));
 }
 
 /**
- * gst_message_parse_async_start:
+ * gst_message_parse_async_done:
  * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.
- * @new_base_time: (out): Result location for the new_base_time or NULL
+ * @running_time: (out): Result location for the running_time or NULL
  *
- * Extract the new_base_time from the async_start message. 
+ * Extract the running_time from the async_done message.
  *
  * MT safe.
- *
- * Since: 0.10.13
  */
 void
-gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
+gst_message_parse_async_done (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_ASYNC_START);
+  g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ASYNC_DONE);
 
-  if (new_base_time)
-    *new_base_time =
-        g_value_get_boolean (gst_structure_id_get_value (message->structure,
-            GST_QUARK (NEW_BASE_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)));
 }
 
 /**
@@ -1592,12 +1579,15 @@ gst_message_parse_async_start (GstMessage * message, gboolean * new_base_time)
 void
 gst_message_parse_request_state (GstMessage * message, GstState * state)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_REQUEST_STATE);
 
+  structure = GST_MESSAGE_STRUCTURE (message);
   if (state)
     *state = (GstState)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (NEW_STATE)));
 }
 
@@ -1623,7 +1613,7 @@ gst_message_new_stream_status (GstObject * src, GstStreamStatusType type,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_STREAM_STATUS),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STREAM_STATUS),
       GST_QUARK (TYPE), GST_TYPE_STREAM_STATUS_TYPE, (gint) type,
       GST_QUARK (OWNER), GST_TYPE_ELEMENT, owner, NULL);
   message = gst_message_new_custom (GST_MESSAGE_STREAM_STATUS, src, structure);
@@ -1650,17 +1640,18 @@ gst_message_parse_stream_status (GstMessage * message,
     GstStreamStatusType * type, GstElement ** owner)
 {
   const GValue *owner_gvalue;
+  GstStructure *structure;
 
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
 
-  owner_gvalue =
-      gst_structure_id_get_value (message->structure, GST_QUARK (OWNER));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  owner_gvalue = gst_structure_id_get_value (structure, GST_QUARK (OWNER));
   g_return_if_fail (owner_gvalue != NULL);
 
   if (type)
     *type = (GstStreamStatusType)
-        g_value_get_enum (gst_structure_id_get_value (message->structure,
+        g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (TYPE)));
   if (owner)
     *owner = (GstElement *) g_value_get_object (owner_gvalue);
@@ -1680,10 +1671,13 @@ void
 gst_message_set_stream_status_object (GstMessage * message,
     const GValue * object)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS);
 
-  gst_structure_id_set_value (message->structure, GST_QUARK (OBJECT), object);
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_set_value (structure, GST_QUARK (OBJECT), object);
 }
 
 /**
@@ -1702,12 +1696,14 @@ const GValue *
 gst_message_get_stream_status_object (GstMessage * message)
 {
   const GValue *result;
+  GstStructure *structure;
 
   g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
   g_return_val_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STREAM_STATUS,
       NULL);
 
-  result = gst_structure_id_get_value (message->structure, GST_QUARK (OBJECT));
+  structure = GST_MESSAGE_STRUCTURE (message);
+  result = gst_structure_id_get_value (structure, GST_QUARK (OBJECT));
 
   return result;
 }
@@ -1743,7 +1739,7 @@ gst_message_new_step_done (GstObject * src, GstFormat format, guint64 amount,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_DONE),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_DONE),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
@@ -1778,10 +1774,13 @@ gst_message_parse_step_done (GstMessage * message, GstFormat * format,
     guint64 * amount, gdouble * rate, gboolean * flush, gboolean * intermediate,
     guint64 * duration, gboolean * eos)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_DONE);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
@@ -1825,7 +1824,7 @@ gst_message_new_step_start (GstObject * src, gboolean active, GstFormat format,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_STEP_START),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_STEP_START),
       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
@@ -1858,10 +1857,13 @@ gst_message_parse_step_start (GstMessage * message, gboolean * active,
     GstFormat * format, guint64 * amount, gdouble * rate, gboolean * flush,
     gboolean * intermediate)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STEP_START);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (ACTIVE), G_TYPE_BOOLEAN, active,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (AMOUNT), G_TYPE_UINT64, amount,
@@ -1906,7 +1908,7 @@ gst_message_new_qos (GstObject * src, gboolean live, guint64 running_time,
   GstMessage *message;
   GstStructure *structure;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_QOS),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_QOS),
       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
@@ -1942,10 +1944,13 @@ void
 gst_message_set_qos_values (GstMessage * message, gint64 jitter,
     gdouble proportion, gint quality)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
 
-  gst_structure_id_set (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_set (structure,
       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
@@ -1976,10 +1981,13 @@ void
 gst_message_set_qos_stats (GstMessage * message, GstFormat format,
     guint64 processed, guint64 dropped)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
 
-  gst_structure_id_set (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_set (structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
@@ -2013,10 +2021,13 @@ gst_message_parse_qos (GstMessage * message, gboolean * live,
     guint64 * running_time, guint64 * stream_time, guint64 * timestamp,
     guint64 * duration)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
       GST_QUARK (RUNNING_TIME), G_TYPE_UINT64, running_time,
       GST_QUARK (STREAM_TIME), G_TYPE_UINT64, stream_time,
@@ -2045,10 +2056,13 @@ void
 gst_message_parse_qos_values (GstMessage * message, gint64 * jitter,
     gdouble * proportion, gint * quality)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (JITTER), G_TYPE_INT64, jitter,
       GST_QUARK (PROPORTION), G_TYPE_DOUBLE, proportion,
       GST_QUARK (QUALITY), G_TYPE_INT, quality, NULL);
@@ -2080,10 +2094,13 @@ void
 gst_message_parse_qos_stats (GstMessage * message, GstFormat * format,
     guint64 * processed, guint64 * dropped)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_QOS);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (PROCESSED), G_TYPE_UINT64, processed,
       GST_QUARK (DROPPED), G_TYPE_UINT64, dropped, NULL);
@@ -2120,7 +2137,7 @@ gst_message_new_progress (GstObject * src, GstProgressType type,
   if (type == GST_PROGRESS_TYPE_START || type == GST_PROGRESS_TYPE_CONTINUE)
     percent = 0;
 
-  structure = gst_structure_id_new (GST_QUARK (MESSAGE_PROGRESS),
+  structure = gst_structure_new_id (GST_QUARK (MESSAGE_PROGRESS),
       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
       GST_QUARK (CODE), G_TYPE_STRING, code,
       GST_QUARK (TEXT), G_TYPE_STRING, text,
@@ -2146,11 +2163,122 @@ void
 gst_message_parse_progress (GstMessage * message, GstProgressType * type,
     gchar ** code, gchar ** text)
 {
+  GstStructure *structure;
+
   g_return_if_fail (GST_IS_MESSAGE (message));
   g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_PROGRESS);
 
-  gst_structure_id_get (message->structure,
+  structure = GST_MESSAGE_STRUCTURE (message);
+  gst_structure_id_get (structure,
       GST_QUARK (TYPE), GST_TYPE_PROGRESS_TYPE, type,
       GST_QUARK (CODE), G_TYPE_STRING, code,
       GST_QUARK (TEXT), G_TYPE_STRING, text, NULL);
 }
+
+/**
+ * gst_message_new_toc:
+ * @src: the object originating the message.
+ * @toc: #GstToc structure for the message.
+ * @updated: whether TOC was updated or not.
+ *
+ * Create a new TOC message. The message is posted by elements
+ * that discovered or updated a TOC.
+ *
+ * Returns: a new TOC message.
+ *
+ * MT safe.
+ *
+ * Since: 0.10.37
+ */
+GstMessage *
+gst_message_new_toc (GstObject * src, GstToc * toc, gboolean updated)
+{
+  GstStructure *toc_struct;
+
+  g_return_val_if_fail (toc != NULL, NULL);
+
+  toc_struct = __gst_toc_to_structure (toc);
+
+  if (G_LIKELY (toc_struct != NULL)) {
+    __gst_toc_structure_set_updated (toc_struct, updated);
+    return gst_message_new_custom (GST_MESSAGE_TOC, src, toc_struct);
+  } else
+    return NULL;
+}
+
+/**
+ * gst_message_parse_toc:
+ * @message: a valid #GstMessage of type GST_MESSAGE_TOC.
+ * @toc: (out): return location for the TOC.
+ * @updated: (out): return location for the updated flag.
+ *
+ * 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.
+ *
+ * MT safe.
+ *
+ * Since: 0.10.37
+ */
+void
+gst_message_parse_toc (GstMessage * message, GstToc ** toc, gboolean * updated)
+{
+  g_return_if_fail (GST_IS_MESSAGE (message));
+  g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_TOC);
+  g_return_if_fail (toc != NULL);
+
+  *toc = __gst_toc_from_structure (GST_MESSAGE_STRUCTURE (message));
+
+  if (updated != NULL)
+    *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)));
+}