mpegts: Add functions to send sections as events
authorJesper Larsen <jesper.larsen@ixonos.com>
Thu, 31 Oct 2013 12:47:23 +0000 (13:47 +0100)
committerJesper Larsen <jesper.larsen@ixonos.com>
Thu, 6 Feb 2014 13:00:33 +0000 (14:00 +0100)
Added function that enables the user to send a GstMpegTsSection as
an event to a GstElement. (i.e. mpegtsmux)

gst-libs/gst/mpegts/gstmpegtssection.c
gst-libs/gst/mpegts/gstmpegtssection.h

index 054a077..334ff57 100644 (file)
@@ -257,20 +257,9 @@ gst_message_parse_mpegts_section (GstMessage * message)
   return section;
 }
 
-/**
- * gst_message_new_mpegts_section:
- * @parent: (transfer none): The creator of the message
- * @section: (transfer none): The #GstMpegTsSection to put in a message
- *
- * Creates a new #GstMessage for a @GstMpegTsSection.
- *
- * Returns: (transfer full): The new #GstMessage to be posted, or %NULL if the
- * section is not valid.
- */
-GstMessage *
-gst_message_new_mpegts_section (GstObject * parent, GstMpegTsSection * section)
+static GstStructure *
+_mpegts_section_get_structure (GstMpegTsSection * section)
 {
-  GstMessage *msg;
   GstStructure *st;
   GQuark quark;
 
@@ -303,7 +292,7 @@ gst_message_new_mpegts_section (GstObject * parent, GstMpegTsSection * section)
       quark = QUARK_TOT;
       break;
     default:
-      GST_DEBUG ("Creating message for unknown GstMpegTsSection");
+      GST_DEBUG ("Creating structure for unknown GstMpegTsSection");
       quark = QUARK_SECTION;
       break;
   }
@@ -311,11 +300,96 @@ gst_message_new_mpegts_section (GstObject * parent, GstMpegTsSection * section)
   st = gst_structure_new_id (quark, QUARK_SECTION, MPEG_TYPE_TS_SECTION,
       section, NULL);
 
+  return st;
+}
+
+/**
+ * gst_message_new_mpegts_section:
+ * @parent: (transfer none): The creator of the message
+ * @section: (transfer none): The #GstMpegTsSection to put in a message
+ *
+ * Creates a new #GstMessage for a @GstMpegTsSection.
+ *
+ * Returns: (transfer full): The new #GstMessage to be posted, or %NULL if the
+ * section is not valid.
+ */
+GstMessage *
+gst_message_new_mpegts_section (GstObject * parent, GstMpegTsSection * section)
+{
+  GstMessage *msg;
+  GstStructure *st;
+
+  st = _mpegts_section_get_structure (section);
+
   msg = gst_message_new_element (parent, st);
 
   return msg;
 }
 
+static GstEvent *
+_mpegts_section_get_event (GstMpegTsSection * section)
+{
+  GstStructure *structure;
+  GstEvent *event;
+
+  structure = _mpegts_section_get_structure (section);
+
+  event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, structure);
+
+  return event;
+}
+
+/**
+ * gst_event_parse_mpegts_section:
+ * @event: (transfer none): #GstEvent containing a #GstMpegTsSection
+ *
+ * Extracts the #GstMpegTsSection contained in the @event #GstEvent
+ *
+ * Returns: (transfer full): The extracted #GstMpegTsSection
+ */
+GstMpegTsSection *
+gst_event_parse_mpegts_section (GstEvent * event)
+{
+  const GstStructure *structure;
+  GstMpegTsSection *section;
+
+  structure = gst_event_get_structure (event);
+
+  if (!gst_structure_id_get (structure, QUARK_SECTION, MPEG_TYPE_TS_SECTION,
+          &section, NULL))
+    return NULL;
+
+  return section;
+}
+
+/**
+ * gst_mpegts_section_send_event:
+ * @element: (transfer none): The #GstElement to send to section event to
+ * @section: (transfer none): The #GstMpegTsSection to put in the event
+ *
+ * Creates a custom #GstEvent with a @GstMpegTsSection.
+ * The #GstEvent is sent to the @element #GstElement.
+ *
+ * Returns: %TRUE if the event is sent
+ */
+gboolean
+gst_mpegts_section_send_event (GstMpegTsSection * section, GstElement * element)
+{
+  GstEvent *event;
+
+  g_return_val_if_fail (section != NULL, FALSE);
+  g_return_val_if_fail (element != NULL, FALSE);
+
+  event = _mpegts_section_get_event (section);
+
+  if (!gst_element_send_event (element, event)) {
+    gst_event_unref (event);
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
 static GstMpegTsPatProgram *
 _mpegts_pat_program_copy (GstMpegTsPatProgram * orig)
 {
@@ -761,9 +835,9 @@ _packetize_common_section (GstMpegTsSection * section, gsize length)
   /* reserved                         - 2  bit
      version_number                   - 5  bit uimsbf
      current_next_indicator           - 1  bit */
-  *data++ =
-      0xC0 | ((section->version_number & 0x1F) << 1) | (section->
-      current_next_indicator & 0x01);
+  *data++ = 0xC0 |
+      ((section->version_number & 0x1F) << 1) |
+      (section->current_next_indicator & 0x01);
 
   /* section_number                   - 8  bit uimsbf */
   *data++ = section->section_number;
index 077a074..72d59dc 100644 (file)
@@ -360,6 +360,8 @@ GPtrArray *gst_mpegts_section_get_tsdt (GstMpegTsSection *section);
 #define gst_mpegts_section_unref(section) (gst_mini_object_unref (GST_MINI_OBJECT_CAST (section)))
 
 GstMessage *gst_message_new_mpegts_section (GstObject *parent, GstMpegTsSection *section);
+gboolean gst_mpegts_section_send_event (GstMpegTsSection * section, GstElement * element);
+GstMpegTsSection *gst_event_parse_mpegts_section (GstEvent * event);
 
 GstMpegTsSection *gst_message_parse_mpegts_section (GstMessage *message);