From 7cb434e42f95590ed5e57d925cdf51e44a94d930 Mon Sep 17 00:00:00 2001 From: Jesper Larsen Date: Sat, 5 Oct 2013 14:45:31 +0200 Subject: [PATCH] mpegts: Add ISO 639 parsing functions https://bugzilla.gnome.org/show_bug.cgi?id=709180 --- gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 55 +++++++++++++++++++++++++++++++ gst-libs/gst/mpegts/gstmpegtsdescriptor.h | 7 ++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index 16a7741..aca1ece 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -635,6 +635,61 @@ gst_mpegts_descriptor_parse_iso_639_language (const GstMpegTsDescriptor * } /** + * gst_mpegts_descriptor_parse_iso_639_language_idx: + * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegTsDescriptor + * @idx: Table id of the language to parse + * @lang (out) (transfer none): 4-byte gchar array to hold the language code + * @audio_type: (out) (transfer none): the #GstMpegTsIso639AudioType to set + * + * Extracts the iso 639-2 language information from specific table id in @descriptor. + * + * Note: Use #gst_tag_get_language_code if you want to get the the + * ISO 639-1 language code from the returned ISO 639-2 one. + * + * Returns: %TRUE if parsing succeeded, else %FALSE. + */ +gboolean +gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegTsDescriptor * + descriptor, guint idx, gchar (*lang)[4], + GstMpegTsIso639AudioType * audio_type) +{ + guint8 *data; + + g_return_val_if_fail (descriptor != NULL && descriptor->data != NULL, FALSE); + g_return_val_if_fail (lang != NULL, FALSE); + g_return_val_if_fail (descriptor->tag == GST_MTS_DESC_ISO_639_LANGUAGE, + FALSE); + g_return_val_if_fail (audio_type != NULL, FALSE); + g_return_val_if_fail (descriptor->length / 4 > idx, FALSE); + + data = (guint8 *) descriptor->data + 2 + idx * 4; + + memcpy (lang, data, 3); + *lang[3] = 0; + + data += 3; + + *audio_type = *data; + + return TRUE; +} + +/** + * gst_mpegts_descriptor_parse_iso_639_language_nb: + * @descriptor: a %GST_MTS_DESC_ISO_639_LANGUAGE #GstMpegTsDescriptor + * + * Returns: The number of languages in @descriptor + */ +guint +gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegTsDescriptor * + descriptor) +{ + g_return_val_if_fail (descriptor != NULL && descriptor->data != NULL, 0); + + return descriptor->length / 4; +} + +/** * gst_mpegts_descriptor_parse_logical_channel: * @descriptor: a %GST_MTS_DESC_DTG_LOGICAL_CHANNEL #GstMpegTsDescriptor * @res: (out) (transfer none): the #GstMpegTsLogicalChannelDescriptor to fill diff --git a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h index c976cc1..506880a 100644 --- a/gst-libs/gst/mpegts/gstmpegtsdescriptor.h +++ b/gst-libs/gst/mpegts/gstmpegtsdescriptor.h @@ -275,9 +275,6 @@ typedef enum { GST_MPEGTS_AUDIO_TYPE_VISUAL_IMPAIRED_COMMENTARY } GstMpegTsIso639AudioType; -/* FIXME: Make two methods. One for getting the number of languages, - * and the other for getting the (allocated, null-terminated) language - * and audio type */ typedef struct _GstMpegTsISO639LanguageDescriptor GstMpegTsISO639LanguageDescriptor; struct _GstMpegTsISO639LanguageDescriptor { @@ -288,6 +285,10 @@ struct _GstMpegTsISO639LanguageDescriptor gboolean gst_mpegts_descriptor_parse_iso_639_language (const GstMpegTsDescriptor *descriptor, GstMpegTsISO639LanguageDescriptor *res); +gboolean gst_mpegts_descriptor_parse_iso_639_language_idx (const GstMpegTsDescriptor *descriptor, + guint idx, gchar (*lang)[4], + GstMpegTsIso639AudioType *audio_type); +guint gst_mpegts_descriptor_parse_iso_639_language_nb (const GstMpegTsDescriptor *descriptor); -- 2.7.4