Add new TOC and TOC select events
authorAlexander Saprykin <xelfium@gmail.com>
Wed, 14 Mar 2012 16:40:32 +0000 (20:40 +0400)
committerStefan Sauer <ensonic@users.sf.net>
Mon, 2 Apr 2012 08:49:38 +0000 (10:49 +0200)
gst/gstevent.c
gst/gstevent.h
gst/gstquark.c
gst/gstquark.h

index 8c323aa..498ef95 100644 (file)
@@ -114,6 +114,7 @@ static GstEventQuarks event_quarks[] = {
   {GST_EVENT_EOS, "eos", 0},
   {GST_EVENT_NEWSEGMENT, "newsegment", 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_QOS, "qos", 0},
@@ -121,6 +122,7 @@ static GstEventQuarks event_quarks[] = {
   {GST_EVENT_NAVIGATION, "navigation", 0},
   {GST_EVENT_LATENCY, "latency", 0},
   {GST_EVENT_STEP, "step", 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},
@@ -1303,3 +1305,112 @@ gst_event_parse_sink_message (GstEvent * event, GstMessage ** msg)
         GST_MESSAGE (gst_value_dup_mini_object (gst_structure_id_get_value
             (event->structure, GST_QUARK (MESSAGE))));
 }
+
+/**
+ * gst_event_new_toc:
+ * @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 (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_id_new (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));
+
+}
index 20e8ef0..2321be5 100644 (file)
@@ -31,6 +31,7 @@
 #include <gst/gstclock.h>
 #include <gst/gststructure.h>
 #include <gst/gsttaglist.h>
+#include <gst/gsttoc.h>
 
 G_BEGIN_DECLS
 
@@ -94,6 +95,8 @@ typedef enum {
  *                          send messages that should be emitted in sync with
  *                          rendering.
  *                          Since: 0.10.26
+ * @GST_EVENT_TOC: An event which indicates that a new table of contents (TOC)
+                   was found or updated. Since: 0.10.37
  * @GST_EVENT_QOS: A quality message. Used to indicate to upstream elements
  *                 that the downstream elements should adjust their processing
  *                 rate.
@@ -106,6 +109,8 @@ typedef enum {
  *                     Since: 0.10.12
  * @GST_EVENT_STEP: A request for stepping through the media. Sinks will usually
  *                  execute the step operation. Since: 0.10.24
+ * @GST_EVENT_TOC_SELECT: A request for a new playback position based on TOC
+ *                        entry's UID. Since 0.10.37
  * @GST_EVENT_CUSTOM_UPSTREAM: Upstream custom event
  * @GST_EVENT_CUSTOM_DOWNSTREAM: Downstream custom event that travels in the
  *                        data flow.
@@ -134,12 +139,14 @@ typedef enum {
   GST_EVENT_TAG                   = GST_EVENT_MAKE_TYPE (7, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
   GST_EVENT_BUFFERSIZE            = GST_EVENT_MAKE_TYPE (8, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
   GST_EVENT_SINK_MESSAGE          = GST_EVENT_MAKE_TYPE (9, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
+  GST_EVENT_TOC                   = GST_EVENT_MAKE_TYPE (10, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
   /* upstream events */
   GST_EVENT_QOS                   = GST_EVENT_MAKE_TYPE (15, FLAG(UPSTREAM)),
   GST_EVENT_SEEK                  = GST_EVENT_MAKE_TYPE (16, FLAG(UPSTREAM)),
   GST_EVENT_NAVIGATION            = GST_EVENT_MAKE_TYPE (17, FLAG(UPSTREAM)),
   GST_EVENT_LATENCY               = GST_EVENT_MAKE_TYPE (18, FLAG(UPSTREAM)),
   GST_EVENT_STEP                  = GST_EVENT_MAKE_TYPE (19, FLAG(UPSTREAM)),
+  GST_EVENT_TOC_SELECT            = GST_EVENT_MAKE_TYPE (20, FLAG(UPSTREAM)),
 
   /* custom events start here */
   GST_EVENT_CUSTOM_UPSTREAM       = GST_EVENT_MAKE_TYPE (32, FLAG(UPSTREAM)),
@@ -487,6 +494,11 @@ void            gst_event_parse_new_segment_full (GstEvent *event,
 GstEvent*       gst_event_new_tag               (GstTagList *taglist) G_GNUC_MALLOC;
 void            gst_event_parse_tag             (GstEvent *event, GstTagList **taglist);
 
+/* TOC event */
+GstEvent*      gst_event_new_toc                (GstToc *toc, gboolean updated);
+void           gst_event_parse_toc              (GstEvent *event, GstToc **toc, gboolean *updated);
+
+
 /* buffer */
 GstEvent *      gst_event_new_buffer_size       (GstFormat format, gint64 minsize, gint64 maxsize,
                                                  gboolean async) G_GNUC_MALLOC;
@@ -524,6 +536,10 @@ GstEvent*       gst_event_new_step              (GstFormat format, guint64 amoun
 void            gst_event_parse_step            (GstEvent *event, GstFormat *format, guint64 *amount,
                                                  gdouble *rate, gboolean *flush, gboolean *intermediate);
 
+/* TOC select event */
+GstEvent*       gst_event_new_toc_select        (const gchar *uid);
+void            gst_event_parse_toc_select      (GstEvent *event, gchar **uid);
+
 G_END_DECLS
 
 #endif /* __GST_EVENT_H__ */
index 91a2012..f8b54da 100644 (file)
@@ -50,7 +50,7 @@ static const gchar *_quark_strings[] = {
   "intermediate", "GstMessageStepStart", "active", "eos", "sink-message",
   "message", "GstMessageQOS", "running-time", "stream-time", "jitter",
   "quality", "processed", "dropped", "buffering-ranges", "GstMessageProgress",
-  "code", "text", "percent", "timeout"
+  "code", "text", "percent", "timeout", "toc-select", "uid"
 };
 
 GQuark _priv_gst_quark_table[GST_QUARK_MAX];
index 6e16ee5..b3cfb45 100644 (file)
@@ -132,8 +132,10 @@ typedef enum _GstQuarkId
   GST_QUARK_TEXT = 103,
   GST_QUARK_PERCENT = 104,
   GST_QUARK_TIMEOUT = 105,
+  GST_QUARK_EVENT_TOC_SELECT = 106,
+  GST_QUARK_UID = 107,
 
-  GST_QUARK_MAX = 106
+  GST_QUARK_MAX = 108
 } GstQuarkId;
 
 extern GQuark _priv_gst_quark_table[GST_QUARK_MAX];