From b66f9145862b7f2a3f89b5745692306061907e07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 13 Dec 2009 12:45:22 +0000 Subject: [PATCH] matroska: fix language code writing and extraction Matroska uses three-letter ISO 639-2B codes, but GST_TAG_LANGUAGE is supposed to contain two-letter ISO 639-1 codes, so use new language code mapping functions in -base to convert between those two as needed. Fixes #505823. --- gst/matroska/matroska-demux.c | 7 ++++++- gst/matroska/matroska-mux.c | 25 ++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 8075653..f684410 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -1804,10 +1804,15 @@ gst_matroska_demux_add_stream (GstMatroskaDemux * demux) } if (context->language) { + const gchar *lang; + if (!list) list = gst_tag_list_new (); + + /* Matroska contains ISO 639-2B codes, we want ISO 639-1 */ + lang = gst_tag_get_language_code (context->language); gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, - GST_TAG_LANGUAGE_CODE, context->language, NULL); + GST_TAG_LANGUAGE_CODE, (lang) ? lang : context->language, NULL); } if (caps == NULL) { diff --git a/gst/matroska/matroska-mux.c b/gst/matroska/matroska-mux.c index 1d426c7..e59faab 100644 --- a/gst/matroska/matroska-mux.c +++ b/gst/matroska/matroska-mux.c @@ -49,6 +49,7 @@ #include #include +#include #include "matroska-mux.h" #include "matroska-ids.h" @@ -577,8 +578,11 @@ gst_matroska_mux_handle_sink_event (GstPad * pad, GstEvent * event) mux = GST_MATROSKA_MUX (gst_pad_get_parent (pad)); + /* FIXME: aren't we either leaking events here or doing a wrong unref? */ switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_TAG: + case GST_EVENT_TAG:{ + gchar *lang = NULL; + GST_DEBUG_OBJECT (mux, "received tag event"); gst_event_parse_tag (event, &list); @@ -586,14 +590,25 @@ gst_matroska_mux_handle_sink_event (GstPad * pad, GstEvent * event) g_assert (collect_pad); context = collect_pad->track; g_assert (context); - /* FIXME ? - * strictly speaking, the incoming language code may only be 639-1, so not - * 639-2 according to matroska specs, but it will have to do for now */ - gst_tag_list_get_string (list, GST_TAG_LANGUAGE_CODE, &context->language); + + /* Matroska wants ISO 639-2B code, taglist most likely contains 639-1 */ + if (gst_tag_list_get_string (list, GST_TAG_LANGUAGE_CODE, &lang)) { + const gchar *lang_code; + + lang_code = gst_tag_get_language_code_iso_639_2B (lang); + if (lang_code) { + GST_INFO_OBJECT (pad, "Setting language to '%s'", lang_code); + context->language = g_strdup (lang_code); + } else { + GST_WARNING_OBJECT (pad, "Did not get language code for '%s'", lang); + } + g_free (lang); + } gst_tag_setter_merge_tags (GST_TAG_SETTER (mux), list, gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (mux))); break; + } case GST_EVENT_NEWSEGMENT: /* We don't support NEWSEGMENT events */ ret = FALSE; -- 2.7.4