[PATCH] tsdemux: Add language code to taglist.

Julian Scheel julian at jusst.de
Tue Apr 10 06:30:07 PDT 2012


Reag the language codes for tracks from the mpegts descriptors and add it into
the pads taglist.
---
 gst/mpegtsdemux/tsdemux.c |   62 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c
index 3ae47f9..395cba5 100644
--- a/gst/mpegtsdemux/tsdemux.c
+++ b/gst/mpegtsdemux/tsdemux.c
@@ -35,6 +35,7 @@
 #include <string.h>
 
 #include <glib.h>
+#include <gst/tag/tag.h>
 
 #include "mpegtsbase.h"
 #include "tsdemux.h"
@@ -153,6 +154,8 @@ struct _TSDemuxStream
 
   /* Whether this stream needs to send a newsegment */
   gboolean need_newsegment;
+
+  GstTagList *taglist;
 };
 
 #define VIDEO_CAPS \
@@ -643,6 +646,43 @@ done:
   return ret;
 }
 
+static void
+gst_ts_demux_create_tags (TSDemuxStream * stream)
+{
+  guint8 *desc = NULL;
+  int i;
+
+  desc = mpegts_get_descriptor_from_stream ((MpegTSBaseStream *) stream,
+      DESC_ISO_639_LANGUAGE);
+  if (desc) {
+    if (!stream->taglist)
+      stream->taglist = gst_tag_list_new ();
+
+    for (i = 0; i < DESC_ISO_639_LANGUAGE_codes_n (desc); i++) {
+      const gchar *lc;
+      gchar lang_code[4];
+      gchar *language_n;
+
+      language_n = (gchar *)
+          DESC_ISO_639_LANGUAGE_language_code_nth (desc, i);
+
+      GST_LOG ("Add language code for stream: %s", language_n);
+
+      lang_code[0] = language_n[0];
+      lang_code[1] = language_n[1];
+      lang_code[2] = language_n[2];
+      lang_code[3] = 0;
+
+      /* descriptor contains ISO 639-2 code, we want the ISO 639-1 code */
+      lc = gst_tag_get_language_code (lang_code);
+      gst_tag_list_add (stream->taglist, GST_TAG_MERGE_REPLACE,
+          GST_TAG_LANGUAGE_CODE, (lc) ? lc : lang_code, NULL);
+    }
+
+    g_free (desc);
+  }
+}
+
 static GstPad *
 create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
     MpegTSBaseProgram * program)
@@ -654,6 +694,7 @@ create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
   guint8 *desc = NULL;
   GstPad *pad = NULL;
 
+  gst_ts_demux_create_tags (stream);
 
   GST_LOG ("Attempting to create pad for stream 0x%04x with stream_type %d",
       bstream->pid, bstream->stream_type);
@@ -1397,6 +1438,23 @@ gst_ts_demux_queue_data (GstTSDemux * demux, TSDemuxStream * stream,
 }
 
 static void
+gst_ts_demux_push_tags (GstTSDemux * demux, TSDemuxStream * stream)
+{
+  if (stream->taglist) {
+    gchar *str;
+    str = gst_structure_to_string ((GstStructure *) stream->taglist);
+
+    GST_DEBUG_OBJECT (demux, "Sending tags %s for pad %s:%s",
+        str, GST_DEBUG_PAD_NAME (stream->pad));
+    gst_element_found_tags_for_pad (GST_ELEMENT (demux), stream->pad,
+        stream->taglist);
+
+    stream->taglist = NULL;
+    g_free (str);
+  }
+}
+
+static void
 calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream)
 {
   MpegTSBase *base = (MpegTSBase *) demux;
@@ -1454,6 +1512,8 @@ calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream)
     demux->segment_event =
         gst_event_new_new_segment_full (FALSE, 1.0, 1.0, GST_FORMAT_TIME,
         firstts, GST_CLOCK_TIME_NONE, firstts);
+    if (!demux->segment_event)
+      return;
     GST_EVENT_SRC (demux->segment_event) = gst_object_ref (demux);
   }
 
@@ -1470,6 +1530,8 @@ push_new_segment:
     gst_pad_push_event (stream->pad, demux->segment_event);
   }
 
+  gst_ts_demux_push_tags (demux, stream);
+
   stream->need_newsegment = FALSE;
 }
 
-- 
1.7.10



More information about the gstreamer-devel mailing list