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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3245>
This commit is contained in:
A. Wilcox 2022-10-21 22:46:16 -05:00 committed by GStreamer Marge Bot
parent 6a2a5fd44c
commit f4bdc79a07
2 changed files with 41 additions and 20 deletions

View file

@ -296,7 +296,7 @@ guint8 *
dvb_text_from_utf8 (const gchar * text, gsize * out_size) dvb_text_from_utf8 (const gchar * text, gsize * out_size)
{ {
GError *error = NULL; GError *error = NULL;
gchar *out_text; gchar *out_text = NULL;
guint8 *out_buffer; guint8 *out_buffer;
guint encoding; guint encoding;
GIConv giconv = (GIConv) - 1; 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 */ /* We test character maps one-by-one. Start with the default */
encoding = _ICONV_ISO6937; encoding = _ICONV_ISO6937;
giconv = _get_iconv (_ICONV_UTF8, encoding); 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) { if (out_text) {
GST_DEBUG ("Using default ISO6937 encoding"); GST_DEBUG ("Using default ISO6937 encoding");

View file

@ -71,6 +71,16 @@ static const guint8 stt_data_check[] = {
0xc0, 0x00, 0xc4, 0x86, 0x56, 0xa5 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) GST_START_TEST (test_scte_sit)
{ {
GstMpegtsSCTESIT *sit; GstMpegtsSCTESIT *sit;
@ -397,10 +407,12 @@ GST_START_TEST (test_mpegts_nit)
fail_if (data == NULL); fail_if (data == NULL);
for (i = 0; i < data_size; i++) { if (_has_iso6937_iconv ()) {
if (data[i] != nit_data_check[i]) for (i = 0; i < data_size; i++) {
fail ("0x%X != 0x%X in byte %d of NIT section", data[i], if (data[i] != nit_data_check[i])
nit_data_check[i], 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 */ /* 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); fail_if (data == NULL);
for (i = 0; i < data_size; i++) { if (_has_iso6937_iconv ()) {
if (data[i] != sdt_data_check[i]) for (i = 0; i < data_size; i++) {
fail ("0x%X != 0x%X in byte %d of SDT section", data[i], if (data[i] != sdt_data_check[i])
sdt_data_check[i], 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 */ /* 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 */ /* Check creation of descriptor */
desc = gst_mpegts_descriptor_from_dvb_network_name ("Name"); desc = gst_mpegts_descriptor_from_dvb_network_name ("Name");
fail_if (desc == NULL); fail_if (desc == NULL);
fail_unless (desc->length == 4); if (_has_iso6937_iconv ())
fail_unless (desc->length == 4);
fail_unless (desc->tag == 0x40); fail_unless (desc->tag == 0x40);
for (i = 0; i < 6; i++) { if (_has_iso6937_iconv ()) {
if (desc->data[i] != network_name_descriptor[i]) for (i = 0; i < 6; i++) {
fail ("0x%X != 0x%X in byte %d of network name descriptor", if (desc->data[i] != network_name_descriptor[i])
desc->data[i], network_name_descriptor[i], 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 */ /* Check parsing of descriptor */
@ -623,13 +640,16 @@ GST_START_TEST (test_mpegts_dvb_descriptors)
desc = gst_mpegts_descriptor_from_dvb_service desc = gst_mpegts_descriptor_from_dvb_service
(GST_DVB_SERVICE_DIGITAL_TELEVISION, "Name", "Provider"); (GST_DVB_SERVICE_DIGITAL_TELEVISION, "Name", "Provider");
fail_if (desc == NULL); fail_if (desc == NULL);
fail_unless (desc->length == 15); if (_has_iso6937_iconv ())
fail_unless (desc->length == 15);
fail_unless (desc->tag == 0x48); fail_unless (desc->tag == 0x48);
for (i = 0; i < 17; i++) { if (_has_iso6937_iconv ()) {
if (desc->data[i] != service_descriptor[i]) for (i = 0; i < 17; i++) {
fail ("0x%X != 0x%X in byte %d of service descriptor", if (desc->data[i] != service_descriptor[i])
desc->data[i], service_descriptor[i], 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 */ /* Check parsing of descriptor with data */