docs: convert NULL, TRUE, and FALSE to %NULL, %TRUE, and %FALSE
[platform/upstream/gstreamer.git] / gst / gstevent.c
index 4693c35..386a1eb 100644 (file)
@@ -51,9 +51,7 @@
  * 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>
- * <title>performing a seek on a pipeline</title>
- *   <programlisting>
+ * |[
  *   GstEvent *event;
  *   gboolean result;
  *   ...
  *   if (!result)
  *     g_warning ("seek failed");
  *   ...
- *   </programlisting>
- * </example>
- *
- * Last reviewed on 2012-03-28 (0.11.3)
+ * ]|
  */
 
 
@@ -93,6 +88,7 @@ typedef struct
   GstEvent event;
 
   GstStructure *structure;
+  gint64 running_time_offset;
 } GstEventImpl;
 
 #define GST_EVENT_STRUCTURE(e)  (((GstEventImpl *)(e))->structure)
@@ -116,7 +112,6 @@ static GstEventQuarks event_quarks[] = {
   {GST_EVENT_BUFFERSIZE, "buffersize", 0},
   {GST_EVENT_SINK_MESSAGE, "sink-message", 0},
   {GST_EVENT_EOS, "eos", 0},
-  {GST_EVENT_CONTEXT, "context", 0},
   {GST_EVENT_SEGMENT_DONE, "segment-done", 0},
   {GST_EVENT_GAP, "gap", 0},
   {GST_EVENT_QOS, "qos", 0},
@@ -255,6 +250,10 @@ _gst_event_copy (GstEvent * event)
   } else {
     GST_EVENT_STRUCTURE (copy) = NULL;
   }
+
+  ((GstEventImpl *) copy)->running_time_offset =
+      ((GstEventImpl *) event)->running_time_offset;
+
   return GST_EVENT_CAST (copy);
 }
 
@@ -268,6 +267,7 @@ gst_event_init (GstEventImpl * event, GstEventType type)
   GST_EVENT_TYPE (event) = type;
   GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE;
   GST_EVENT_SEQNUM (event) = gst_util_seqnum_next ();
+  event->running_time_offset = 0;
 }
 
 
@@ -351,7 +351,7 @@ gst_event_get_structure (GstEvent * event)
  * Returns: The structure of the event. The structure is still
  * owned by the event, which means that you should not free it and
  * that the pointer becomes invalid when you free the event.
- * This function checks if @event is writable and will never return NULL.
+ * This function checks if @event is writable and will never return %NULL.
  *
  * MT safe.
  */
@@ -447,6 +447,54 @@ gst_event_set_seqnum (GstEvent * event, guint32 seqnum)
 }
 
 /**
+ * gst_event_get_running_time_offset:
+ * @event: A #GstEvent.
+ *
+ * Retrieve the accumulated running time offset of the event.
+ *
+ * Events passing through #GstPads that have a running time
+ * offset set via gst_pad_set_offset() will get their offset
+ * adjusted according to the pad's offset.
+ *
+ * If the event contains any information that related to the
+ * running time, this information will need to be updated
+ * before usage with this offset.
+ *
+ * Returns: The event's running time offset
+ *
+ * MT safe.
+ *
+ * Since: 1.4
+ */
+gint64
+gst_event_get_running_time_offset (GstEvent * event)
+{
+  g_return_val_if_fail (GST_IS_EVENT (event), 0);
+
+  return ((GstEventImpl *) event)->running_time_offset;
+}
+
+/**
+ * gst_event_set_running_time_offset:
+ * @event: A #GstEvent.
+ * @offset: A the new running time offset
+ *
+ * Set the running time offset of a event. See
+ * gst_event_get_running_time_offset() for more information.
+ *
+ * MT safe.
+ *
+ * Since: 1.4
+ */
+void
+gst_event_set_running_time_offset (GstEvent * event, gint64 offset)
+{
+  g_return_if_fail (GST_IS_EVENT (event));
+
+  ((GstEventImpl *) event)->running_time_offset = offset;
+}
+
+/**
  * gst_event_new_flush_start:
  *
  * Allocate a new flush start event. The flush start event can be sent
@@ -482,7 +530,7 @@ gst_event_new_flush_start (void)
  * pads accept data again.
  *
  * Elements can process this event synchronized with the dataflow since
- * the preceeding FLUSH_START event stopped the dataflow.
+ * the preceding FLUSH_START event stopped the dataflow.
  *
  * This event is typically generated to complete a seek and to resume
  * dataflow.
@@ -935,7 +983,7 @@ gst_event_parse_buffer_size (GstEvent * event, GstFormat * format,
  * increasing value.
  *
  * The upstream element can use the @diff and @timestamp values to decide
- * whether to process more buffers. For possitive @diff, all buffers with
+ * whether to process more buffers. For positive @diff, all buffers with
  * timestamp <= @timestamp + @diff will certainly arrive late in the sink
  * as well. A (negative) @diff value so that @timestamp + @diff would yield a
  * result smaller than 0 is not allowed.
@@ -980,6 +1028,8 @@ gst_event_new_qos (GstQOSType type, gdouble proportion,
  *
  * Get the type, proportion, diff and timestamp in the qos event. See
  * gst_event_new_qos() for more information about the different QoS values.
+ *
+ * @timestamp will be adjusted for any pad offsets of pads it was passing through.
  */
 void
 gst_event_parse_qos (GstEvent * event, GstQOSType * type,
@@ -1003,10 +1053,18 @@ gst_event_parse_qos (GstEvent * event, GstQOSType * type,
     *diff =
         g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (DIFF)));
-  if (timestamp)
+  if (timestamp) {
+    gint64 offset = gst_event_get_running_time_offset (event);
+
     *timestamp =
         g_value_get_uint64 (gst_structure_id_get_value (structure,
             GST_QUARK (TIMESTAMP)));
+    /* Catch underflows */
+    if (*timestamp > -offset)
+      *timestamp += offset;
+    else
+      *timestamp = 0;
+  }
 }
 
 /**
@@ -1098,9 +1156,9 @@ gst_event_new_seek (gdouble rate, GstFormat format, GstSeekFlags flags,
  * @format: (out): result location for the stream format
  * @flags:  (out): result location for the #GstSeekFlags
  * @start_type: (out): result location for the #GstSeekType of the start position
- * @start: (out): result location for the start postion expressed in @format
+ * @start: (out): result location for the start position expressed in @format
  * @stop_type:  (out): result location for the #GstSeekType of the stop position
- * @stop: (out): result location for the stop postion expressed in @format
+ * @stop: (out): result location for the stop position expressed in @format
  *
  * Parses a seek @event and stores the results in the given result locations.
  */
@@ -1299,7 +1357,7 @@ gst_event_parse_step (GstEvent * event, GstFormat * format, guint64 * amount,
 /**
  * gst_event_new_reconfigure:
 
- * Create a new reconfigure event. The purpose of the reconfingure event is
+ * Create a new reconfigure event. The purpose of the reconfigure event is
  * to travel upstream and make elements renegotiate their caps or reconfigure
  * their buffer pools. This is useful when changing properties on elements
  * or changing the topology of the pipeline.
@@ -1474,6 +1532,57 @@ gst_event_parse_stream_flags (GstEvent * event, GstStreamFlags * flags)
 }
 
 /**
+ * gst_event_set_group_id:
+ * @event: a stream-start event
+ * @group_id: the group id to set
+ *
+ * All streams that have the same group id are supposed to be played
+ * together, i.e. all streams inside a container file should have the
+ * same group id but different stream ids. The group id should change
+ * each time the stream is started, resulting in different group ids
+ * each time a file is played for example.
+ *
+ * Use gst_util_group_id_next() to get a new group id.
+ *
+ * Since: 1.2
+ */
+void
+gst_event_set_group_id (GstEvent * event, guint group_id)
+{
+  g_return_if_fail (event != NULL);
+  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START);
+  g_return_if_fail (gst_event_is_writable (event));
+
+  gst_structure_id_set (GST_EVENT_STRUCTURE (event),
+      GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
+}
+
+/**
+ * gst_event_parse_group_id:
+ * @event: a stream-start event
+ * @group_id: (out): address of variable where to store the group id
+ *
+ * Returns: %TRUE if a group id was set on the event and could be parsed,
+ *   %FALSE otherwise.
+ *
+ * Since: 1.2
+ */
+gboolean
+gst_event_parse_group_id (GstEvent * event, guint * group_id)
+{
+  g_return_val_if_fail (event != NULL, FALSE);
+  g_return_val_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START,
+      FALSE);
+
+  if (group_id) {
+    return gst_structure_id_get (GST_EVENT_STRUCTURE (event),
+        GST_QUARK (GROUP_ID), G_TYPE_UINT, group_id, NULL);
+  }
+
+  return TRUE;
+}
+
+/**
  * gst_event_new_toc:
  * @toc: (transfer none): #GstToc structure.
  * @updated: whether @toc was updated or not.
@@ -1610,8 +1719,8 @@ gst_event_new_segment_done (GstFormat format, gint64 position)
 /**
  * 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
+ * @format: (out) (allow-none): Result location for the format, or %NULL
+ * @position: (out) (allow-none): Result location for the position, or %NULL
  *
  * Extracts the position and format from the segment done message.
  *
@@ -1636,56 +1745,3 @@ gst_event_parse_segment_done (GstEvent * event, GstFormat * format,
   if (position != NULL)
     *position = g_value_get_int64 (val);
 }
-
-/**
- * gst_event_new_context:
- * @context: (transfer full): the #GstContext
- *
- * Create a new context event. The purpose of the context event is
- * to pass a pipeline-local context to downstream elements.
- *
- * Returns: (transfer full): a new #GstEvent
- *
- * Since: 1.2
- */
-GstEvent *
-gst_event_new_context (GstContext * context)
-{
-  GstEvent *event;
-  GstStructure *structure;
-
-  g_return_val_if_fail (context != NULL, NULL);
-
-  GST_CAT_INFO (GST_CAT_EVENT, "creating context event");
-
-  structure = gst_structure_new_id (GST_QUARK (EVENT_SEEK),
-      GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
-  event = gst_event_new_custom (GST_EVENT_CONTEXT, structure);
-  gst_context_unref (context);
-
-  return event;
-}
-
-/**
- * gst_event_parse_context:
- * @event: The event to query
- * @context: (out) (transfer full): a pointer to store the #GstContext in.
- *
- * Parse the context event. Unref @context after usage.
- *
- * Since: 1.2
- */
-void
-gst_event_parse_context (GstEvent * event, GstContext ** context)
-{
-  const GstStructure *structure;
-
-  g_return_if_fail (GST_IS_EVENT (event));
-  g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_CONTEXT);
-
-  structure = GST_EVENT_STRUCTURE (event);
-  if (context)
-    *context =
-        GST_CONTEXT (g_value_dup_boxed (gst_structure_id_get_value
-            (structure, GST_QUARK (CONTEXT))));
-}