From f4bdc79a078c17461de39f36e0c1456422803f31 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 21 Oct 2022 22:46:16 -0500 Subject: [PATCH] mpegts: Handle when iconv doesn't support ISO 6937 Systems like musl libc don't support ISO 6937 in iconv. This ensures that the MPEG-TS plugin can cope with that. There is existing support in the plugin for other methods, so it seems to have been the original intent anyway. Fixes: #1314 Part-of: --- .../gst-libs/gst/mpegts/gstmpegtsdescriptor.c | 5 +- .../gst-plugins-bad/tests/check/libs/mpegts.c | 56 +++++++++++++++------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gstmpegtsdescriptor.c b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gstmpegtsdescriptor.c index e6b18c1..9d2232a 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gstmpegtsdescriptor.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/mpegts/gstmpegtsdescriptor.c @@ -296,7 +296,7 @@ guint8 * dvb_text_from_utf8 (const gchar * text, gsize * out_size) { GError *error = NULL; - gchar *out_text; + gchar *out_text = NULL; guint8 *out_buffer; guint encoding; GIConv giconv = (GIConv) - 1; @@ -304,7 +304,8 @@ dvb_text_from_utf8 (const gchar * text, gsize * out_size) /* We test character maps one-by-one. Start with the default */ encoding = _ICONV_ISO6937; giconv = _get_iconv (_ICONV_UTF8, encoding); - out_text = g_convert_with_iconv (text, -1, giconv, NULL, out_size, &error); + if (giconv != (GIConv) - 1) + out_text = g_convert_with_iconv (text, -1, giconv, NULL, out_size, &error); if (out_text) { GST_DEBUG ("Using default ISO6937 encoding"); diff --git a/subprojects/gst-plugins-bad/tests/check/libs/mpegts.c b/subprojects/gst-plugins-bad/tests/check/libs/mpegts.c index 55682f9..f8fc6f0 100644 --- a/subprojects/gst-plugins-bad/tests/check/libs/mpegts.c +++ b/subprojects/gst-plugins-bad/tests/check/libs/mpegts.c @@ -71,6 +71,16 @@ static const guint8 stt_data_check[] = { 0xc0, 0x00, 0xc4, 0x86, 0x56, 0xa5 }; +static gboolean +_has_iso6937_iconv (void) +{ + gboolean supported; + GIConv test = g_iconv_open ("iso6937", "utf-8"); + supported = (test != (GIConv) - 1); + g_iconv_close (test); + return supported; +} + GST_START_TEST (test_scte_sit) { GstMpegtsSCTESIT *sit; @@ -397,10 +407,12 @@ GST_START_TEST (test_mpegts_nit) fail_if (data == NULL); - for (i = 0; i < data_size; i++) { - if (data[i] != nit_data_check[i]) - fail ("0x%X != 0x%X in byte %d of NIT section", data[i], - nit_data_check[i], i); + if (_has_iso6937_iconv ()) { + for (i = 0; i < data_size; i++) { + if (data[i] != nit_data_check[i]) + fail ("0x%X != 0x%X in byte %d of NIT section", data[i], + nit_data_check[i], i); + } } /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */ @@ -486,10 +498,12 @@ GST_START_TEST (test_mpegts_sdt) fail_if (data == NULL); - for (i = 0; i < data_size; i++) { - if (data[i] != sdt_data_check[i]) - fail ("0x%X != 0x%X in byte %d of SDT section", data[i], - sdt_data_check[i], i); + if (_has_iso6937_iconv ()) { + for (i = 0; i < data_size; i++) { + if (data[i] != sdt_data_check[i]) + fail ("0x%X != 0x%X in byte %d of SDT section", data[i], + sdt_data_check[i], i); + } } /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */ @@ -594,13 +608,16 @@ GST_START_TEST (test_mpegts_dvb_descriptors) /* Check creation of descriptor */ desc = gst_mpegts_descriptor_from_dvb_network_name ("Name"); fail_if (desc == NULL); - fail_unless (desc->length == 4); + if (_has_iso6937_iconv ()) + fail_unless (desc->length == 4); fail_unless (desc->tag == 0x40); - for (i = 0; i < 6; i++) { - if (desc->data[i] != network_name_descriptor[i]) - fail ("0x%X != 0x%X in byte %d of network name descriptor", - desc->data[i], network_name_descriptor[i], i); + if (_has_iso6937_iconv ()) { + for (i = 0; i < 6; i++) { + if (desc->data[i] != network_name_descriptor[i]) + fail ("0x%X != 0x%X in byte %d of network name descriptor", + desc->data[i], network_name_descriptor[i], i); + } } /* Check parsing of descriptor */ @@ -623,13 +640,16 @@ GST_START_TEST (test_mpegts_dvb_descriptors) desc = gst_mpegts_descriptor_from_dvb_service (GST_DVB_SERVICE_DIGITAL_TELEVISION, "Name", "Provider"); fail_if (desc == NULL); - fail_unless (desc->length == 15); + if (_has_iso6937_iconv ()) + fail_unless (desc->length == 15); fail_unless (desc->tag == 0x48); - for (i = 0; i < 17; i++) { - if (desc->data[i] != service_descriptor[i]) - fail ("0x%X != 0x%X in byte %d of service descriptor", - desc->data[i], service_descriptor[i], i); + if (_has_iso6937_iconv ()) { + for (i = 0; i < 17; i++) { + if (desc->data[i] != service_descriptor[i]) + fail ("0x%X != 0x%X in byte %d of service descriptor", + desc->data[i], service_descriptor[i], i); + } } /* Check parsing of descriptor with data */ -- 2.7.4