From 85cafac6af27a3f46cd7ffcce1ff503810cafc11 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Sat, 25 Dec 2010 15:22:42 +0000 Subject: [PATCH] oggstream: implement tag extraction for Kate streams This will mainly allow Totem to know the language of those streams, so the subtitle selection menu gets properly filled out. https://bugzilla.gnome.org/show_bug.cgi?id=638005 --- ext/ogg/gstoggstream.c | 53 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/ext/ogg/gstoggstream.c b/ext/ogg/gstoggstream.c index 783364a20c..c9e2cc5841 100644 --- a/ext/ogg/gstoggstream.c +++ b/ext/ogg/gstoggstream.c @@ -1758,6 +1758,57 @@ packet_duration_kate (GstOggStream * pad, ogg_packet * packet) return duration; } +static void +extract_tags_kate (GstOggStream * pad, ogg_packet * packet) +{ + GstTagList *list = NULL; + + if (packet->bytes <= 0) + return; + + switch (packet->packet[0]) { + case 0x80:{ + const gchar *canonical; + char language[16]; + + if (packet->bytes < 64) { + GST_WARNING ("Kate ID header packet is less than 64 bytes, ignored"); + break; + } + + /* the language tag is 16 bytes at offset 32, ensure NUL terminator */ + memcpy (language, packet->packet + 32, 16); + language[15] = 0; + + /* language is an ISO 639-1 code or RFC 3066 language code, we + * truncate to ISO 639-1 */ + g_strdelimit (language, NULL, '\0'); + canonical = gst_tag_get_language_code_iso_639_1 (language); + if (canonical) { + list = gst_tag_list_new_full (GST_TAG_LANGUAGE_CODE, canonical, NULL); + } else { + GST_WARNING ("Unknown or invalid language code %s, ignored", language); + } + break; + } + case 0x81: + tag_list_from_vorbiscomment_packet (packet, + (const guint8 *) "\201kate\0\0\0\0", 9, &list); + break; + default: + break; + } + + if (list) { + if (pad->taglist) { + /* ensure the comment packet cannot override the category/language + from the identification header */ + gst_tag_list_insert (pad->taglist, list, GST_TAG_MERGE_KEEP_ALL); + } else + pad->taglist = list; + } +} + /* *INDENT-OFF* */ /* indent hates our freedoms */ @@ -1903,7 +1954,7 @@ const GstOggMap mappers[] = { is_header_count, packet_duration_kate, NULL, - NULL + extract_tags_kate }, { "BBCD\0", 5, 13,