From 9cc00bf2c9b61236a3d65906ae7dbcb3fb8ef4fe Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 19 Apr 2016 10:27:43 -0300 Subject: [PATCH] mpegtsmux: write language descriptor when language is available 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 | 24 +++++++++++++++++++++++ gst-libs/gst/mpegts/gstmpegtsdescriptor.h | 1 + gst/mpegtsmux/tsmux/tsmuxstream.c | 13 +++++++++++- gst/mpegtsmux/tsmux/tsmuxstream.h | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index d4817d24c6..a49ce2a2c8 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -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 diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index af56be0faa..33d46f5db0 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -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); diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.c b/gst/mpegtsmux/tsmux/tsmuxstream.c index 6b7c17eb73..48879074c7 100644 --- a/gst/mpegtsmux/tsmux/tsmuxstream.c +++ b/gst/mpegtsmux/tsmux/tsmuxstream.c @@ -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) { diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.h b/gst/mpegtsmux/tsmux/tsmuxstream.h index 73b2a88128..2766718ed2 100644 --- a/gst/mpegtsmux/tsmux/tsmuxstream.h +++ b/gst/mpegtsmux/tsmux/tsmuxstream.h @@ -211,6 +211,7 @@ struct TsMuxStream { gchar language[4]; gboolean is_meta; + gboolean is_audio; /* Opus */ gboolean is_opus; -- 2.34.1