g_type_init() is no longer required and deprecated in glib >= 2.35.0
[platform/upstream/gstreamer.git] / gst / gstevent.c
index f5418b3..188325d 100644 (file)
  * elements will use gst_pad_send_event() or gst_pad_push_event().
  * The event should be unreffed with gst_event_unref() if it has not been sent.
  *
- * Events that have been received can be parsed with their respective 
+ * Events that have been received can be parsed with their respective
  * gst_event_parse_*() functions. It is valid to pass %NULL for unwanted details.
  *
  * Events are passed between elements in parallel to the data stream. Some events
  * are serialized with buffers, others are not. Some events only travel downstream,
- * others only upstream. Some events can travel both upstream and downstream. 
- * 
+ * others only upstream. Some events can travel both upstream and downstream.
+ *
  * The events are used to signal special conditions in the datastream such as
  * EOS (end of stream) or the start of a new stream-segment.
  * Events are also used to flush the pipeline of any pending data.
  *
- * Most of the event API is used inside plugins. Applications usually only 
- * construct and use seek events. 
+ * Most of the event API is used inside plugins. Applications usually only
+ * construct and use seek events.
  * To do that gst_event_new_seek() is used to create a seek event. It takes
  * the needed parameters to specify seeking time and mode.
  * <example>
@@ -72,7 +72,7 @@
  *   </programlisting>
  * </example>
  *
- * Last reviewed on 2006-09-6 (0.10.10)
+ * Last reviewed on 2012-03-28 (0.11.3)
  */
 
 
@@ -110,9 +110,9 @@ static GstEventQuarks event_quarks[] = {
   {GST_EVENT_FLUSH_STOP, "flush-stop", 0},
   {GST_EVENT_STREAM_START, "stream-start", 0},
   {GST_EVENT_CAPS, "caps", 0},
-  {GST_EVENT_STREAM_CONFIG, "stream-config", 0},
   {GST_EVENT_SEGMENT, "segment", 0},
   {GST_EVENT_TAG, "tag", 0},
+  {GST_EVENT_TOC, "toc", 0},
   {GST_EVENT_BUFFERSIZE, "buffersize", 0},
   {GST_EVENT_SINK_MESSAGE, "sink-message", 0},
   {GST_EVENT_EOS, "eos", 0},
@@ -124,6 +124,7 @@ static GstEventQuarks event_quarks[] = {
   {GST_EVENT_LATENCY, "latency", 0},
   {GST_EVENT_STEP, "step", 0},
   {GST_EVENT_RECONFIGURE, "reconfigure", 0},
+  {GST_EVENT_TOC_SELECT, "toc-select", 0},
   {GST_EVENT_CUSTOM_UPSTREAM, "custom-upstream", 0},
   {GST_EVENT_CUSTOM_DOWNSTREAM, "custom-downstream", 0},
   {GST_EVENT_CUSTOM_DOWNSTREAM_OOB, "custom-downstream-oob", 0},
@@ -227,11 +228,10 @@ _gst_event_free (GstEvent * event)
     gst_structure_free (s);
   }
 
-  g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
+  g_slice_free1 (sizeof (GstEventImpl), event);
 }
 
-static void gst_event_init (GstEventImpl * event, gsize size,
-    GstEventType type);
+static void gst_event_init (GstEventImpl * event, GstEventType type);
 
 static GstEvent *
 _gst_event_copy (GstEvent * event)
@@ -241,7 +241,7 @@ _gst_event_copy (GstEvent * event)
 
   copy = g_slice_new0 (GstEventImpl);
 
-  gst_event_init (copy, sizeof (GstEventImpl), GST_EVENT_TYPE (event));
+  gst_event_init (copy, GST_EVENT_TYPE (event));
 
   GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
   GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
@@ -251,37 +251,24 @@ _gst_event_copy (GstEvent * event)
     GST_EVENT_STRUCTURE (copy) = gst_structure_copy (s);
     gst_structure_set_parent_refcount (GST_EVENT_STRUCTURE (copy),
         &copy->event.mini_object.refcount);
+  } else {
+    GST_EVENT_STRUCTURE (copy) = NULL;
   }
   return GST_EVENT_CAST (copy);
 }
 
 static void
-gst_event_init (GstEventImpl * event, gsize size, GstEventType type)
+gst_event_init (GstEventImpl * event, GstEventType type)
 {
-  gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size);
-
-  event->event.mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy;
-  event->event.mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free;
+  gst_mini_object_init (GST_MINI_OBJECT_CAST (event), 0, _gst_event_type,
+      (GstMiniObjectCopyFunction) _gst_event_copy, NULL,
+      (GstMiniObjectFreeFunction) _gst_event_free);
 
   GST_EVENT_TYPE (event) = type;
   GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE;
   GST_EVENT_SEQNUM (event) = gst_util_seqnum_next ();
 }
 
-static GstEvent *
-gst_event_new (GstEventType type)
-{
-  GstEventImpl *event;
-
-  event = g_slice_new0 (GstEventImpl);
-
-  GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
-      gst_event_type_get_name (type), type);
-
-  gst_event_init (event, sizeof (GstEventImpl), type);
-
-  return GST_EVENT_CAST (event);
-}
 
 /**
  * gst_event_new_custom:
@@ -305,23 +292,30 @@ gst_event_new (GstEventType type)
 GstEvent *
 gst_event_new_custom (GstEventType type, GstStructure * structure)
 {
-  GstEvent *event;
+  GstEventImpl *event;
+
+  event = g_slice_new0 (GstEventImpl);
+
+  GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
+      gst_event_type_get_name (type), type);
 
-  /* structure must not have a parent */
-  event = gst_event_new (type);
   if (structure) {
+    /* structure must not have a parent */
     if (!gst_structure_set_parent_refcount (structure,
-            &event->mini_object.refcount))
+            &event->event.mini_object.refcount))
       goto had_parent;
 
-    GST_EVENT_STRUCTURE (event) = structure;
   }
-  return event;
+  gst_event_init (event, type);
+
+  GST_EVENT_STRUCTURE (event) = structure;
+
+  return GST_EVENT_CAST (event);
 
   /* ERRORS */
 had_parent:
   {
-    gst_event_unref (event);
+    g_slice_free1 (sizeof (GstEventImpl), event);
     g_warning ("structure is already owned by another object");
     return NULL;
   }
@@ -389,8 +383,6 @@ gst_event_writable_structure (GstEvent * event)
  * check the name of a custom event.
  *
  * Returns: %TRUE if @name matches the name of the event structure.
- *
- * Since: 0.10.20
  */
 gboolean
 gst_event_has_name (GstEvent * event, const gchar * name)
@@ -423,8 +415,6 @@ gst_event_has_name (GstEvent * event, const gchar * name)
  * Returns: The event's sequence number.
  *
  * MT safe.
- *
- * Since: 0.10.22
  */
 guint32
 gst_event_get_seqnum (GstEvent * event)
@@ -446,8 +436,6 @@ gst_event_get_seqnum (GstEvent * event)
  * more information.
  *
  * MT safe.
- *
- * Since: 0.10.22
  */
 void
 gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
@@ -457,10 +445,6 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
   GST_EVENT_SEQNUM (event) = seqnum;
 }
 
-/* FIXME 0.11: It would be nice to have flush events
- * that don't reset the running time in the sinks
- */
-
 /**
  * gst_event_new_flush_start:
  *
@@ -468,9 +452,9 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
  * upstream and downstream and travels out-of-bounds with the dataflow.
  *
  * It marks pads as being flushing and will make them return
- * #GST_FLOW_WRONG_STATE when used for data flow with gst_pad_push(),
- * gst_pad_chain(), gst_pad_alloc_buffer(), gst_pad_get_range() and
- * gst_pad_pull_range(). Any event (except a #GST_EVENT_FLUSH_STOP) received
+ * #GST_FLOW_FLUSHING when used for data flow with gst_pad_push(),
+ * gst_pad_chain(), gst_pad_get_range() and gst_pad_pull_range().
+ * Any event (except a #GST_EVENT_FLUSH_STOP) received
  * on a flushing pad will return %FALSE immediately.
  *
  * Elements should unlock any blocking functions and exit their streaming
@@ -484,7 +468,7 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
 GstEvent *
 gst_event_new_flush_start (void)
 {
-  return gst_event_new (GST_EVENT_FLUSH_START);
+  return gst_event_new_custom (GST_EVENT_FLUSH_START, NULL);
 }
 
 /**
@@ -545,7 +529,7 @@ gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time)
  *
  * Create a new EOS event. The eos event can only travel downstream
  * synchronized with the buffer flow. Elements that receive the EOS
- * event on a pad can return #GST_FLOW_UNEXPECTED as a #GstFlowReturn
+ * event on a pad can return #GST_FLOW_EOS as a #GstFlowReturn
  * when data after the EOS event arrives.
  *
  * The EOS event will travel down to the sink elements in the pipeline
@@ -562,13 +546,13 @@ gst_event_parse_flush_stop (GstEvent * event, gboolean * reset_time)
 GstEvent *
 gst_event_new_eos (void)
 {
-  return gst_event_new (GST_EVENT_EOS);
+  return gst_event_new_custom (GST_EVENT_EOS, NULL);
 }
 
 /**
  * gst_event_new_gap:
- * @timestamp: the start time (pts) of a gap
- * @duration: the duration of the gap, or %GST_CLOCK_TIME_NONE
+ * @timestamp: the start time (pts) of the gap
+ * @duration: the duration of the gap
  *
  * Create a new GAP event. A gap event can be thought of as conceptually
  * equivalent to a buffer to signal that there is no data for a certain
@@ -584,12 +568,12 @@ gst_event_new_gap (GstClockTime timestamp, GstClockTime duration)
   GstEvent *event;
 
   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
+  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (duration), NULL);
 
   GST_CAT_TRACE (GST_CAT_EVENT, "creating gap %" GST_TIME_FORMAT " - "
       "%" GST_TIME_FORMAT " (duration: %" GST_TIME_FORMAT ")",
-      GST_TIME_ARGS (timestamp),
-      GST_TIME_ARGS (GST_CLOCK_TIME_IS_VALID (duration) ? (timestamp +
-              duration) : GST_CLOCK_TIME_NONE), GST_TIME_ARGS (duration));
+      GST_TIME_ARGS (timestamp), GST_TIME_ARGS (timestamp + duration),
+      GST_TIME_ARGS (duration));
 
   event = gst_event_new_custom (GST_EVENT_GAP,
       gst_structure_new_id (GST_QUARK (EVENT_GAP),
@@ -601,7 +585,9 @@ gst_event_new_gap (GstClockTime timestamp, GstClockTime duration)
 
 /**
  * gst_event_parse_gap:
- * @timestamp: (out): location where to store the start time (pts) of the gap
+ * @event: a #GstEvent of type #GST_EVENT_GAP
+ * @timestamp: (out) (allow-none): location where to store the
+ *     start time (pts) of the gap, or %NULL
  * @duration: (out) (allow-none): location where to store the duration of
  *     the gap, or %NULL
  *
@@ -652,7 +638,7 @@ gst_event_new_caps (GstCaps * caps)
 /**
  * gst_event_parse_caps:
  * @event: The event to parse
- * @caps: (out): A pointer to the caps
+ * @caps: (out) (transfer none): A pointer to the caps
  *
  * Get the caps from @event. The caps remains valid as long as @event remains
  * valid.
@@ -673,214 +659,6 @@ gst_event_parse_caps (GstEvent * event, GstCaps ** caps)
 }
 
 /**
- * gst_event_new_stream_config:
- * @flags: the stream config flags
- *
- * Create a new STREAM CONFIG event. The stream config event travels
- * downstream synchronized with the buffer flow and contains stream
- * configuration information for the stream, such as stream-headers
- * or codec-data. It is optional and should be sent after the CAPS
- * event.
- *
- * Returns: (transfer full): the new STREAM CONFIG event.
- */
-GstEvent *
-gst_event_new_stream_config (GstStreamConfigFlags flags)
-{
-  GstEvent *event;
-
-  GST_CAT_INFO (GST_CAT_EVENT, "creating stream info event, flags=0x%x", flags);
-
-  event = gst_event_new_custom (GST_EVENT_STREAM_CONFIG,
-      gst_structure_new_id (GST_QUARK (EVENT_STREAM_CONFIG),
-          GST_QUARK (FLAGS), GST_TYPE_STREAM_CONFIG_FLAGS, flags, NULL));
-
-  return event;
-}
-
-/**
- * gst_event_parse_stream_config:
- * @event: The event to parse
- * @flags: (out): a pointer to a variable to store the stream config flags
- *
- * Get the stream config flags from @event.
- */
-void
-gst_event_parse_stream_config (GstEvent * event, GstStreamConfigFlags * flags)
-{
-  GstStructure *structure;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG);
-
-  structure = GST_EVENT_STRUCTURE (event);
-  if (G_LIKELY (flags != NULL)) {
-    *flags =
-        g_value_get_enum (gst_structure_id_get_value (structure,
-            GST_QUARK (FLAGS)));
-  }
-}
-
-/**
- * gst_event_set_stream_config_codec_data:
- * @event: a stream config event
- * @buf: a #GstBuffer with codec data
- *
- * Set codec data on the stream info event to signal out of bound setup data
- * to downstream elements. Unlike stream headers, codec data contains data
- * that is required to interpret the data stream, but is not valid as-is
- * inside the data stream and thus can't just be prepended to or inserted
- * into the data stream.
- */
-void
-gst_event_set_stream_config_codec_data (GstEvent * event, GstBuffer * buf)
-{
-  GstStructure *s;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG);
-  g_return_if_fail (GST_IS_BUFFER (buf) && gst_buffer_get_size (buf) > 0);
-
-  s = GST_EVENT_STRUCTURE (event);
-  gst_structure_id_set (s, GST_QUARK (CODEC_DATA), GST_TYPE_BUFFER, buf, NULL);
-}
-
-/**
- * gst_event_set_stream_config_codec_data:
- * @event: a stream config event
- * @buf: (out) (transfer none): location where to store the #GstBuffer with codec data
- *
- * Extracts the codec data buffer from the stream info event. Will store
- * %NULL in @buf if the event contains no codec data. The buffer returned
- * will remain valid as long as @event remains valid. The caller should
- * acquire a referenceto to @buf if needed.
- */
-void
-gst_event_parse_stream_config_codec_data (GstEvent * event, GstBuffer ** buf)
-{
-  const GValue *val;
-  GstStructure *s;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG);
-  g_return_if_fail (buf != NULL);
-
-  s = GST_EVENT_STRUCTURE (event);
-  val = gst_structure_id_get_value (s, GST_QUARK (CODEC_DATA));
-  if (val != NULL)
-    *buf = g_value_get_boxed (val);
-  else
-    *buf = NULL;
-}
-
-/**
- * gst_event_add_stream_config_header:
- * @event: a stream config event
- * @buf: a #GstBuffer with stream header data
- *
- * Adds a stream header to the stream info event to signal stream headers to
- * to downstream elements such as multifilesink, tcpserversink etc. Stream
- * headers can be and should usually be prepended to the data stream at any
- * point in the stream (which requires a streamable format), e.g. to a new
- * client connecting, or when starting a new file segment. stream header
- * buffers will all be used together in the order they were added to the
- * stream config event. Stream headers are sent as buffers at the beginning
- * of the data flow in addition to the stream config event. Elements that
- * care about stream headers need to make sure that they don't insert or
- * interpret these header buffers twice if they interpret them.
- */
-void
-gst_event_add_stream_config_header (GstEvent * event, GstBuffer * buf)
-{
-  GstStructure *s;
-  GValue buf_val = { 0, };
-  GValue *val;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG);
-  g_return_if_fail (GST_IS_BUFFER (buf) && gst_buffer_get_size (buf) > 0);
-
-  g_value_init (&buf_val, GST_TYPE_BUFFER);
-  g_value_set_boxed (&buf_val, buf);
-
-  s = GST_EVENT_STRUCTURE (event);
-  val = (GValue *) gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS));
-  if (val == NULL) {
-    GValue new_array = { 0, };
-
-    g_value_init (&new_array, GST_TYPE_ARRAY);
-    gst_value_array_append_value (&new_array, &buf_val);
-    gst_structure_id_take_value (s, GST_QUARK (STREAM_HEADERS), &new_array);
-  } else {
-    gst_value_array_append_value (val, &buf_val);
-  }
-  g_value_unset (&buf_val);
-}
-
-/**
- * gst_event_get_n_stream_config_headers:
- * @event: a stream config event
- *
- * Extract the number of stream header buffers.
- *
- * Returns: the number of stream header buffers attached to the stream info
- * @event.
- */
-guint
-gst_event_get_n_stream_config_headers (GstEvent * event)
-{
-  const GValue *val;
-  GstStructure *s;
-  guint num = 0;
-
-  g_return_val_if_fail (GST_IS_EVENT (event), 0);
-  g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG, 0);
-
-  s = GST_EVENT_STRUCTURE (event);
-  val = gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS));
-
-  if (val != NULL)
-    num = gst_value_array_get_size (val);
-
-  return num;
-}
-
-/**
- * gst_event_parse_nth_stream_config_header:
- * @event: a stream config event
- * @index: number of the stream header to retrieve
- * @buf: (out) (transfer none): location where to store the n-th stream
- *     header #GstBuffer
- *
- * Retrieves the n-th stream header buffer attached to the stream config
- * event and stores it in @buf. Will store %NULL in @buf if there is no such
- * stream header.
- */
-void
-gst_event_parse_nth_stream_config_header (GstEvent * event, guint index,
-    GstBuffer ** buf)
-{
-  const GValue *val, *buf_val;
-  GstStructure *s;
-  GstBuffer *ret = NULL;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG);
-  g_return_if_fail (buf != NULL);
-
-  s = GST_EVENT_STRUCTURE (event);
-  val = gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS));
-
-  if (val != NULL) {
-    buf_val = gst_value_array_get_value (val, index);
-    if (buf_val != NULL)
-      ret = g_value_get_boxed (buf_val);
-  }
-
-  *buf = ret;
-}
-
-/**
  * gst_event_new_segment:
  * @segment: (transfer none): a #GstSegment
  *
@@ -991,14 +769,28 @@ gst_event_copy_segment (GstEvent * event, GstSegment * segment)
  *
  * Generates a metadata tag event from the given @taglist.
  *
+ * The scope of the taglist specifies if the taglist applies to the
+ * complete medium or only to this specific stream. As the tag event
+ * is a sticky event, elements should merge tags received from
+ * upstream with a given scope with their own tags with the same
+ * scope and create a new tag event from it.
+ *
  * Returns: (transfer full): a new #GstEvent
  */
 GstEvent *
 gst_event_new_tag (GstTagList * taglist)
 {
+  GstStructure *s;
+  GValue val = G_VALUE_INIT;
+  const gchar *names[] = { "GstTagList-stream", "GstTagList-global" };
+
   g_return_val_if_fail (taglist != NULL, NULL);
 
-  return gst_event_new_custom (GST_EVENT_TAG, (GstStructure *) taglist);
+  s = gst_structure_new_empty (names[gst_tag_list_get_scope (taglist)]);
+  g_value_init (&val, GST_TYPE_TAG_LIST);
+  g_value_take_boxed (&val, taglist);
+  gst_structure_id_take_value (s, GST_QUARK (TAGLIST), &val);
+  return gst_event_new_custom (GST_EVENT_TAG, s);
 }
 
 /**
@@ -1014,11 +806,16 @@ gst_event_new_tag (GstTagList * taglist)
 void
 gst_event_parse_tag (GstEvent * event, GstTagList ** taglist)
 {
+  const GValue *val;
+
   g_return_if_fail (GST_IS_EVENT (event));
   g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TAG);
 
+  val = gst_structure_id_get_value (GST_EVENT_STRUCTURE (event),
+      GST_QUARK (TAGLIST));
+
   if (taglist)
-    *taglist = (GstTagList *) GST_EVENT_STRUCTURE (event);
+    *taglist = (GstTagList *) g_value_get_boxed (val);
 }
 
 /* buffersize event */
@@ -1246,13 +1043,13 @@ gst_event_parse_qos (GstEvent * event, GstQOSType * type,
  * from the newly configured start position. 
  *
  * For negative rates, playback will start from the newly configured stop
- * position (if any). If the stop position if updated, it must be different from
- * -1 for negative rates.
+ * position (if any). If the stop position is updated, it must be different from
+ * -1 (#GST_CLOCK_TIME_NONE) for negative rates.
  *
  * It is not possible to seek relative to the current playback position, to do
  * this, PAUSE the pipeline, query the current playback position with
  * #GST_QUERY_POSITION and update the playback segment current position with a
- * #GST_SEEK_TYPE_SET to the desired position. 
+ * #GST_SEEK_TYPE_SET to the desired position.
  *
  * Returns: (transfer full): a new seek event.
  */
@@ -1377,8 +1174,6 @@ gst_event_new_navigation (GstStructure * structure)
  * the time format.
  *
  * Returns: (transfer full): a new #GstEvent
- *
- * Since: 0.10.12
  */
 GstEvent *
 gst_event_new_latency (GstClockTime latency)
@@ -1402,8 +1197,6 @@ gst_event_new_latency (GstClockTime latency)
  * @latency: (out): A pointer to store the latency in.
  *
  * Get the latency in the latency event.
- *
- * Since: 0.10.12
  */
 void
 gst_event_parse_latency (GstEvent * event, GstClockTime * latency)
@@ -1440,8 +1233,6 @@ gst_event_parse_latency (GstEvent * event, GstClockTime * latency)
  * part of a larger step operation.
  *
  * Returns: (transfer full): a new #GstEvent
- *
- * Since: 0.10.24
  */
 GstEvent *
 gst_event_new_step (GstFormat format, guint64 amount, gdouble rate,
@@ -1476,8 +1267,6 @@ gst_event_new_step (GstFormat format, guint64 amount, gdouble rate,
  *     boolean in
  *
  * Parse the step event.
- *
- * Since: 0.10.24
  */
 void
 gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
@@ -1516,8 +1305,6 @@ gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
  * or changing the topology of the pipeline.
  *
  * Returns: (transfer full): a new #GstEvent
- *
- * Since: 0.11.0
  */
 GstEvent *
 gst_event_new_reconfigure (void)
@@ -1533,19 +1320,20 @@ gst_event_new_reconfigure (void)
 
 /**
  * gst_event_new_sink_message:
+ * @name: a name for the event
  * @msg: (transfer none): the #GstMessage to be posted
  *
  * Create a new sink-message event. The purpose of the sink-message event is
  * to instruct a sink to post the message contained in the event synchronized
  * with the stream.
  *
- * Returns: (transfer full): a new #GstEvent
+ * @name is used to store multiple sticky events on one pad.
  *
- * Since: 0.10.26
+ * Returns: (transfer full): a new #GstEvent
  */
 /* FIXME 0.11: take ownership of msg for consistency? */
 GstEvent *
-gst_event_new_sink_message (GstMessage * msg)
+gst_event_new_sink_message (const gchar * name, GstMessage * msg)
 {
   GstEvent *event;
   GstStructure *structure;
@@ -1554,7 +1342,7 @@ gst_event_new_sink_message (GstMessage * msg)
 
   GST_CAT_INFO (GST_CAT_EVENT, "creating sink-message event");
 
-  structure = gst_structure_new_id (GST_QUARK (EVENT_SINK_MESSAGE),
+  structure = gst_structure_new_id (g_quark_from_string (name),
       GST_QUARK (MESSAGE), GST_TYPE_MESSAGE, msg, NULL);
   event = gst_event_new_custom (GST_EVENT_SINK_MESSAGE, structure);
 
@@ -1567,8 +1355,6 @@ gst_event_new_sink_message (GstMessage * msg)
  * @msg: (out) (transfer full): a pointer to store the #GstMessage in.
  *
  * Parse the sink-message event. Unref @msg after usage.
- *
- * Since: 0.10.26
  */
 void
 gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
@@ -1586,7 +1372,8 @@ gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
 }
 
 /**
- * gst_event_new_stream_start
+ * gst_event_new_stream_start:
+ * @stream_id: Identifier for this stream
  *
  * Create a new STREAM_START event. The stream start event can only
  * travel downstream synchronized with the buffer flow. It is expected
@@ -1599,10 +1386,215 @@ gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
  * combining multiple streams must ensure that this event is only forwarded
  * downstream once and not for every single input stream.
  *
+ * The @stream_id should be a unique string that consists of the upstream
+ * stream-id, / as separator and a unique stream-id for this specific
+ * stream. A new stream-id should only be created for a stream if the upstream
+ * stream is split into (potentially) multiple new streams, e.g. in a demuxer,
+ * but not for every single element in the pipeline.
+ * gst_pad_create_stream_id() or gst_pad_create_stream_id_printf() can be
+ * used to create a stream-id.
+ *
  * Returns: (transfer full): the new STREAM_START event.
  */
 GstEvent *
-gst_event_new_stream_start (void)
+gst_event_new_stream_start (const gchar * stream_id)
+{
+  GstStructure *s;
+
+  g_return_val_if_fail (stream_id != NULL, NULL);
+
+  s = gst_structure_new_id (GST_QUARK (EVENT_STREAM_START),
+      GST_QUARK (STREAM_ID), G_TYPE_STRING, stream_id, NULL);
+
+  return gst_event_new_custom (GST_EVENT_STREAM_START, s);
+}
+
+/**
+ * gst_event_parse_stream_start:
+ * @event: a stream-start event.
+ * @stream_id: (out): pointer to store the stream-id
+ *
+ * Parse a stream-id @event and store the result in the given @stream_id
+ * location. The string stored in @stream_id must not be modified and will
+ * remain valid only until @event gets freed. Make a copy if you want to
+ * modify it or store it for later use.
+ */
+void
+gst_event_parse_stream_start (GstEvent * event, const gchar ** stream_id)
+{
+  const GstStructure *structure;
+  const GValue *val;
+
+  g_return_if_fail (event != NULL);
+  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
+
+  structure = gst_event_get_structure (event);
+  val = gst_structure_id_get_value (structure, GST_QUARK (STREAM_ID));
+
+  if (stream_id)
+    *stream_id = g_value_get_string (val);
+}
+
+/**
+ * gst_event_new_toc:
+ * @toc: (transfer none): #GstToc structure.
+ * @updated: whether @toc was updated or not.
+ *
+ * Generate a TOC event from the given @toc. The purpose of the TOC event is to
+ * inform elements that some kind of the TOC was found.
+ *
+ * Returns: (transfer full): a new #GstEvent.
+ */
+GstEvent *
+gst_event_new_toc (GstToc * toc, gboolean updated)
+{
+  GstStructure *toc_struct;
+  GQuark id;
+
+  g_return_val_if_fail (toc != NULL, NULL);
+
+  GST_CAT_INFO (GST_CAT_EVENT, "creating toc event");
+
+  /* need different structure names so sticky_multi event stuff on pads
+   * works, i.e. both TOC events are kept around */
+  if (gst_toc_get_scope (toc) == GST_TOC_SCOPE_GLOBAL)
+    id = GST_QUARK (EVENT_TOC_GLOBAL);
+  else
+    id = GST_QUARK (EVENT_TOC_CURRENT);
+
+  toc_struct = gst_structure_new_id (id,
+      GST_QUARK (TOC), GST_TYPE_TOC, toc,
+      GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
+
+  return gst_event_new_custom (GST_EVENT_TOC, toc_struct);
+}
+
+/**
+ * gst_event_parse_toc:
+ * @event: a TOC event.
+ * @toc: (out) (transfer full): pointer to #GstToc structure.
+ * @updated: (out): pointer to store TOC updated flag.
+ *
+ * Parse a TOC @event and store the results in the given @toc and @updated locations.
+ */
+void
+gst_event_parse_toc (GstEvent * event, GstToc ** toc, gboolean * updated)
+{
+  const GstStructure *structure;
+
+  g_return_if_fail (event != NULL);
+  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC);
+  g_return_if_fail (toc != NULL);
+
+  structure = gst_event_get_structure (event);
+
+  gst_structure_id_get (structure,
+      GST_QUARK (TOC), GST_TYPE_TOC, toc,
+      GST_QUARK (UPDATED), G_TYPE_BOOLEAN, updated, NULL);
+}
+
+/**
+ * gst_event_new_toc_select:
+ * @uid: UID in the TOC to start playback from.
+ *
+ * Generate a TOC select event with the given @uid. The purpose of the
+ * TOC select event is to start playback based on the TOC's entry with the
+ * given @uid.
+ *
+ * Returns: a new #GstEvent.
+ */
+GstEvent *
+gst_event_new_toc_select (const gchar * uid)
 {
-  return gst_event_new (GST_EVENT_STREAM_START);
+  GstStructure *structure;
+
+  g_return_val_if_fail (uid != NULL, NULL);
+
+  GST_CAT_INFO (GST_CAT_EVENT, "creating toc select event for UID: %s", uid);
+
+  structure = gst_structure_new_id (GST_QUARK (EVENT_TOC_SELECT),
+      GST_QUARK (UID), G_TYPE_STRING, uid, NULL);
+
+  return gst_event_new_custom (GST_EVENT_TOC_SELECT, structure);
+}
+
+/**
+ * gst_event_parse_toc_select:
+ * @event: a TOC select event.
+ * @uid: (out): storage for the selection UID.
+ *
+ * Parse a TOC select @event and store the results in the given @uid location.
+ */
+void
+gst_event_parse_toc_select (GstEvent * event, gchar ** uid)
+{
+  const GstStructure *structure;
+  const GValue *val;
+
+  g_return_if_fail (event != NULL);
+  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_TOC_SELECT);
+
+  structure = gst_event_get_structure (event);
+  val = gst_structure_id_get_value (structure, GST_QUARK (UID));
+
+  if (uid != NULL)
+    *uid = g_strdup (g_value_get_string (val));
+
+}
+
+/**
+ * gst_event_new_segment_done:
+ * @format: The format of the position being done
+ * @position: The position of the segment being done
+ *
+ * Create a new segment-done event. This event is sent by elements that
+ * finish playback of a segment as a result of a segment seek.
+ *
+ * Returns: (transfer full): a new #GstEvent
+ */
+GstEvent *
+gst_event_new_segment_done (GstFormat format, gint64 position)
+{
+  GstEvent *event;
+  GstStructure *structure;
+
+  GST_CAT_INFO (GST_CAT_EVENT, "creating segment-done event");
+
+  structure = gst_structure_new_id (GST_QUARK (EVENT_SEGMENT_DONE),
+      GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
+      GST_QUARK (POSITION), G_TYPE_INT64, position, NULL);
+
+  event = gst_event_new_custom (GST_EVENT_SEGMENT_DONE, structure);
+
+  return event;
+}
+
+/**
+ * gst_event_parse_segment_done:
+ * @event: A valid #GstEvent of type GST_EVENT_SEGMENT_DONE.
+ * @format: (out): Result location for the format, or NULL
+ * @position: (out): Result location for the position, or NULL
+ *
+ * Extracts the position and format from the segment done message.
+ *
+ */
+void
+gst_event_parse_segment_done (GstEvent * event, GstFormat * format,
+    gint64 * position)
+{
+  const GstStructure *structure;
+  const GValue *val;
+
+  g_return_if_fail (event != NULL);
+  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT_DONE);
+
+  structure = gst_event_get_structure (event);
+
+  val = gst_structure_id_get_value (structure, GST_QUARK (FORMAT));
+  if (format != NULL)
+    *format = g_value_get_enum (val);
+
+  val = gst_structure_id_get_value (structure, GST_QUARK (POSITION));
+  if (position != NULL)
+    *position = g_value_get_int64 (val);
 }