mpegtsmux: write language descriptor when language is available
authorThiago Santos <thiagoss@osg.samsung.com>
Tue, 19 Apr 2016 13:27:43 +0000 (10:27 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Wed, 27 Apr 2016 02:45:34 +0000 (23:45 -0300)
Adds a new function to mpegts lib to create a iso639 language
descriptor from a language and use it in mpegtsmux to add
a language descriptor to audio streams that have a language set.

https://bugzilla.gnome.org/show_bug.cgi?id=763647

gst-libs/gst/mpegts/gstmpegtsdescriptor.c
gst-libs/gst/mpegts/gstmpegtsdescriptor.h
gst/mpegtsmux/tsmux/tsmuxstream.c
gst/mpegtsmux/tsmux/tsmuxstream.h

index d4817d24c68b6f92cee5ba1c3a0e23f3749a15b7..a49ce2a2c81a1eda60d46a8c9169e0052ca7e77c 100644 (file)
@@ -1039,6 +1039,30 @@ gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegtsDescriptor *
   return descriptor->length / 4;
 }
 
+/**
+ * gst_mpegts_descriptor_from_iso_639_language:
+ * @language: (transfer none): ISO-639-2 language 3-char code
+ *
+ * Creates a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegtsDescriptor with
+ * a single language
+ *
+ * Return: #GstMpegtsDescriptor, %NULL on failure
+ */
+GstMpegtsDescriptor *
+gst_mpegts_descriptor_from_iso_639_language (const gchar * language)
+{
+  GstMpegtsDescriptor *descriptor;
+
+  g_return_val_if_fail (language != NULL, NULL);
+
+  descriptor = _new_descriptor (GST_MTS_DESC_ISO_639_LANGUAGE, 4 + 4);  /* a language takes 4 bytes */
+
+  memcpy (descriptor->data + 2, language, 3);
+  descriptor->data[2 + 3] = 0;  /* set audio type to undefined */
+
+  return descriptor;
+}
+
 /**
  * gst_mpegts_descriptor_parse_logical_channel:
  * @descriptor: a %GST_MTS_DESC_DTG_LOGICAL_CHANNEL #GstMpegtsDescriptor
index af56be0faa5ef3c0e242cebc25b1342129f2ccc8..33d46f5db0de383b0f855a43e9534351c6ae1293 100644 (file)
@@ -313,6 +313,7 @@ gboolean gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegtsDescri
                                                            guint idx, gchar **lang,
                                                            GstMpegtsIso639AudioType *audio_type);
 guint gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegtsDescriptor *descriptor);
+GstMpegtsDescriptor * gst_mpegts_descriptor_from_iso_639_language (const gchar * language);
 
 
 
index 6b7c17eb73ff87004e9bd79e68ad6b38cfd07f26..48879074c764bf4436563b6b49f3eb5b8744a30a 100644 (file)
@@ -148,6 +148,7 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
     case TSMUX_ST_AUDIO_MPEG1:
     case TSMUX_ST_AUDIO_MPEG2:
       /* FIXME: Assign sequential IDs? */
+      stream->is_audio = TRUE;
       stream->id = 0xC0;
       stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
       break;
@@ -163,12 +164,15 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
           stream->is_video_stream = TRUE;
           break;
         case TSMUX_ST_PS_AUDIO_LPCM:
+          stream->is_audio = TRUE;
           stream->id_extended = 0x80;
           break;
         case TSMUX_ST_PS_AUDIO_AC3:
+          stream->is_audio = TRUE;
           stream->id_extended = 0x71;
           break;
         case TSMUX_ST_PS_AUDIO_DTS:
+          stream->is_audio = TRUE;
           stream->id_extended = 0x82;
           break;
         default:
@@ -204,6 +208,7 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
     case TSMUX_ST_PS_OPUS:
       /* FIXME: assign sequential extended IDs? */
       stream->id = 0xBD;
+      stream->is_audio = TRUE;
       stream->stream_type = TSMUX_ST_PRIVATE_DATA;
       stream->is_opus = TRUE;
       stream->pi.flags |= TSMUX_PACKET_FLAG_PES_FULL_HEADER;
@@ -732,7 +737,13 @@ tsmux_stream_get_es_descrs (TsMuxStream * stream,
   g_return_if_fail (stream != NULL);
   g_return_if_fail (pmt_stream != NULL);
 
-  /* Based on the stream type, write out any descriptors to go in the 
+  if (stream->is_audio && stream->language) {
+    descriptor = gst_mpegts_descriptor_from_iso_639_language (stream->language);
+    g_ptr_array_add (pmt_stream->descriptors, descriptor);
+    descriptor = NULL;
+  }
+
+  /* Based on the stream type, write out any descriptors to go in the
    * PMT ES_info field */
   /* tag (registration_descriptor), length, format_identifier */
   switch (stream->stream_type) {
index 73b2a88128c73a761692340d80341b1e90425fa3..2766718ed2c4d3c220955c6dcdaab3dc38f60f77 100644 (file)
@@ -211,6 +211,7 @@ struct TsMuxStream {
   gchar language[4];
 
   gboolean is_meta;
+  gboolean is_audio;
 
   /* Opus */
   gboolean is_opus;