diff options
author | Carl Eugen Hoyos <ceffmpeg@gmail.com> | 2019-02-09 18:38:13 +0100 |
---|---|---|
committer | Carl Eugen Hoyos <ceffmpeg@gmail.com> | 2019-02-09 23:49:51 +0100 |
commit | 5c515b5f7d64fb1fccc3e99cd50f01bfbdd2a794 (patch) | |
tree | 45d5c60c3576bba39b87c6822909e0fb59d485a6 /libavformat/mpegts.c | |
parent | 5b32f94b97dffa0e84c2af3d6778bd3319f52f95 (diff) | |
download | ffmpeg-5c515b5f7d64fb1fccc3e99cd50f01bfbdd2a794.tar.gz |
lavf/mpegts: Convert service_name and service_provider to utf-8.
Fixes ticket #6320.
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r-- | libavformat/mpegts.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b04fd7b4f4..f5a87c87cb 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -37,6 +37,9 @@ #include "avio_internal.h" #include "mpeg.h" #include "isom.h" +#if CONFIG_ICONV +#include <iconv.h> +#endif /* maximum size in which we look for synchronization if * synchronization is lost */ @@ -674,6 +677,47 @@ static char *getstr8(const uint8_t **pp, const uint8_t *p_end) return NULL; if (len > p_end - p) return NULL; +#if CONFIG_ICONV + if (len && *p < 0x20) { + const char *encodings[] = { + "ISO6937", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", + "ISO-8859-8", "ISO-8859-9", "ISO-8859-10", "ISO-8859-11", + "", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15", "", "", "", "", + "", "ISO-10646", "KSC_5601", "GB2312", "UCS-2BE", "UTF-8", "", "", + "", "", "", "", "", "", "", "" + }; + iconv_t cd; + char *in, *out; + size_t inlen = len - 1, outlen = inlen * 6 + 1; + if (len >= 3 && p[0] == 0x10 && !p[1] && p[2] && p[2] <= 0xf && p[2] != 0xc) { + char iso8859[12]; + snprintf(iso8859, sizeof(iso8859), "ISO-8859-%d", p[2]); + inlen -= 2; + in = (char *)p + 3; + cd = iconv_open("UTF-8", iso8859); + } else { + in = (char *)p + 1; + cd = iconv_open("UTF-8", encodings[*p]); + } + if (cd == (iconv_t)-1) + goto no_iconv; + str = out = av_malloc(outlen); + if (!str) { + iconv_close(cd); + return NULL; + } + if (iconv(cd, &in, &inlen, &out, &outlen) == -1) { + iconv_close(cd); + av_freep(&str); + goto no_iconv; + } + iconv_close(cd); + *out = 0; + *pp = p + len; + return str; + } +no_iconv: +#endif str = av_malloc(len + 1); if (!str) return NULL; |