event: add name to sticky_multi events
[platform/upstream/gstreamer.git] / gst / gstevent.c
index 8d624a1..63e4e92 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)
  */
 
 
@@ -113,6 +113,7 @@ static GstEventQuarks event_quarks[] = {
   {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 +125,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},
@@ -452,10 +454,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:
  *
@@ -464,8 +462,8 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
  *
  * It marks pads as being flushing and will make them return
  * #GST_FLOW_FLUSHING 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_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
@@ -540,7 +538,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
@@ -596,6 +594,7 @@ gst_event_new_gap (GstClockTime timestamp, GstClockTime duration)
 
 /**
  * gst_event_parse_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
@@ -675,7 +674,7 @@ gst_event_parse_caps (GstEvent * event, GstCaps ** caps)
  * 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
+ * or setup-data. It is optional and should be sent after the CAPS
  * event.
  *
  * Returns: (transfer full): the new STREAM CONFIG event.
@@ -718,18 +717,18 @@ gst_event_parse_stream_config (GstEvent * event, GstStreamConfigFlags * flags)
 }
 
 /**
- * gst_event_set_stream_config_codec_data:
+ * gst_event_set_stream_config_setup_data:
  * @event: a stream config event
- * @buf: a #GstBuffer with codec data
+ * @buf: a #GstBuffer with setup 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
+ * Set setup data on the stream info event to signal out of bound setup data
+ * to downstream elements. Unlike stream headers, setup 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)
+gst_event_set_stream_config_setup_data (GstEvent * event, GstBuffer * buf)
 {
   GstStructure *s;
 
@@ -738,35 +737,41 @@ gst_event_set_stream_config_codec_data (GstEvent * event, GstBuffer * buf)
   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_structure_id_set (s, GST_QUARK (SETUP_DATA), GST_TYPE_BUFFER, buf, NULL);
 }
 
 /**
- * gst_event_set_stream_config_codec_data:
+ * gst_event_parse_stream_config_setup_data:
  * @event: a stream config event
- * @buf: (out) (transfer none): location where to store the #GstBuffer with codec data
+ * @buf: (out) (transfer none): location where to store the #GstBuffer with setup 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
+ * Extracts the setup data buffer from the stream info event. Will store
+ * %NULL in @buf if the event contains no setup data. The buffer returned
  * will remain valid as long as @event remains valid. The caller should
- * acquire a referenceto to @buf if needed.
+ * acquire a reference to to @buf if needed.
+ *
+ * Returns: TRUE if @event contained setup data and @buf has been set,
+ *     otherwise FALSE.
  */
-void
-gst_event_parse_stream_config_codec_data (GstEvent * event, GstBuffer ** buf)
+gboolean
+gst_event_parse_stream_config_setup_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);
+  g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
+  g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG,
+      FALSE);
+  g_return_val_if_fail (buf != NULL, FALSE);
 
   s = GST_EVENT_STRUCTURE (event);
-  val = gst_structure_id_get_value (s, GST_QUARK (CODEC_DATA));
+  val = gst_structure_id_get_value (s, GST_QUARK (SETUP_DATA));
   if (val != NULL)
     *buf = g_value_get_boxed (val);
   else
     *buf = NULL;
+
+  return (*buf != NULL);
 }
 
 /**
@@ -851,8 +856,11 @@ gst_event_get_n_stream_config_headers (GstEvent * event)
  * 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.
+ *
+ * Returns: TRUE if @event contained a stream header at @index and @buf has
+ *    been set, otherwise FALSE.
  */
-void
+gboolean
 gst_event_parse_nth_stream_config_header (GstEvent * event, guint index,
     GstBuffer ** buf)
 {
@@ -860,9 +868,10 @@ gst_event_parse_nth_stream_config_header (GstEvent * event, guint index,
   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);
+  g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
+  g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_CONFIG,
+      FALSE);
+  g_return_val_if_fail (buf != NULL, FALSE);
 
   s = GST_EVENT_STRUCTURE (event);
   val = gst_structure_id_get_value (s, GST_QUARK (STREAM_HEADERS));
@@ -874,6 +883,7 @@ gst_event_parse_nth_stream_config_header (GstEvent * event, guint index,
   }
 
   *buf = ret;
+  return (ret != NULL);
 }
 
 /**
@@ -982,19 +992,30 @@ gst_event_copy_segment (GstEvent * event, GstSegment * segment)
 
 /**
  * gst_event_new_tag:
+ * @name: (transfer none): the name of the event
  * @taglist: (transfer full): metadata list. The event will take ownership
  *     of the taglist.
  *
  * Generates a metadata tag event from the given @taglist.
  *
+ * Since the TAG event has the %GST_EVENT_TYPE_STICKY_MULTI flag set, the
+ * @name will be used to keep track of multiple tag events.
+ *
  * Returns: (transfer full): a new #GstEvent
  */
 GstEvent *
-gst_event_new_tag (GstTagList * taglist)
+gst_event_new_tag (const gchar * name, GstTagList * taglist)
 {
+  GstStructure *s;
+  GValue val = G_VALUE_INIT;
+
   g_return_val_if_fail (taglist != NULL, NULL);
 
-  return gst_event_new_custom (GST_EVENT_TAG, (GstStructure *) taglist);
+  s = gst_structure_new_empty (name);
+  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);
 }
 
 /**
@@ -1010,11 +1031,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 */
@@ -1242,13 +1268,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.
  */
@@ -1529,19 +1555,22 @@ 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.
  *
+ * @name is used to store multiple sticky events on one pad.
+ *
  * Returns: (transfer full): a new #GstEvent
  *
  * Since: 0.10.26
  */
 /* 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;
@@ -1550,7 +1579,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);
 
@@ -1602,3 +1631,113 @@ gst_event_new_stream_start (void)
 {
   return gst_event_new_custom (GST_EVENT_STREAM_START, NULL);
 }
+
+/**
+ * gst_event_new_toc:
+ * @name: a name for the event
+ * @toc: #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: a new #GstEvent.
+ *
+ * Since: 0.10.37
+ */
+GstEvent *
+gst_event_new_toc (const gchar * name, GstToc * toc, gboolean updated)
+{
+  GstStructure *toc_struct;
+
+  g_return_val_if_fail (toc != NULL, NULL);
+
+  GST_CAT_INFO (GST_CAT_EVENT, "creating toc event");
+
+  toc_struct = __gst_toc_to_structure (toc);
+
+  if (G_LIKELY (toc_struct != NULL)) {
+    __gst_toc_structure_set_updated (toc_struct, updated);
+    return gst_event_new_custom (GST_EVENT_TOC, toc_struct);
+  } else
+    return NULL;
+}
+
+/**
+ * gst_event_parse_toc:
+ * @event: a TOC event.
+ * @toc: (out): 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.
+ *
+ * Since: 0.10.37
+ */
+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);
+  *toc = __gst_toc_from_structure (structure);
+
+  if (updated != NULL)
+    *updated = __gst_toc_structure_get_updated (structure);
+}
+
+/**
+ * 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.
+ *
+ * Since: 0.10.37
+ */
+GstEvent *
+gst_event_new_toc_select (const gchar * uid)
+{
+  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.
+ *
+ * Since: 0.10.37
+ */
+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));
+
+}