From patchwork Sat Feb 9 17:39:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 12012 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D7BC544822F for ; Sat, 9 Feb 2019 19:39:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B839168A7FD; Sat, 9 Feb 2019 19:39:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f195.google.com (mail-it1-f195.google.com [209.85.166.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24C2268A39E for ; Sat, 9 Feb 2019 19:39:26 +0200 (EET) Received: by mail-it1-f195.google.com with SMTP id f18so5737784itb.5 for ; Sat, 09 Feb 2019 09:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=5K5YsElat+04vhA2aj2MvNrNBeJR/tfQJsp+D+ToWHE=; b=Paueec1lhprOva52ip/vbyAnfacXEGJe6i3I8YALhgQ/HAO1VjOLUrG0ltoglIzZBX 0DesCddBnJyjzhIomlZ8SWtAfofX7QYaLY7ZGf0onimyf++u+hO/krGPaqprSIzU7ofn nEoUh8e5g2vc0GK8W+H5OOnGmhBkmcBSAN4jKiUw7oaS0uVxklIOTnmAduxIeNTCsnmT KGiEipXeuy0jbshE4J90SMYc98YJnoTHzV/l1mYKl7bCxk2fganUWxbpI4+wvhK+vxNV GhNNy0tod3G3woUeQ0aSIncx0uXVVr5kXoADUEE1oSxsjKcTH5Q4FKZycTY1IOUo8D6E 3wkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=5K5YsElat+04vhA2aj2MvNrNBeJR/tfQJsp+D+ToWHE=; b=qkBGB4iHE8uk8AXndjGJrq1/+vVCINh5NMvwkz1slf27mypRnI8cqMvw0O2i6iqKM5 b9jf71KHRiazujVa9cOaZrNuUleDnHgDbmPFmPC6nmvnp+q0geC4Tv3rptK2Lth8ATSM HZvjwlM0eCQvWC+QZf49XoVUzNW9p3NAekkQctBzgBMWv/X8cHxzxWFe1G5NobEX7V3d KA8PkHoNx1x/gMOfPyCDmdwRXXQg/Fwr1xnGaLfD7LANXl4paNcIMBOKKawY2cv3NExb A+iYd5SDkhvUcC5ZYhyVt80CHlHIZtzT9uhDI/0dFGQ0mBSWORTaE5rTyqC68JCU9fBc E0Pg== X-Gm-Message-State: AHQUAuaonzXMUgRbzzLS4vh84HDMRJsMBaLd6vQ+WA3i/BukevPZlucs JrOOQ0B8tXVZaMyT+Gs9LLSf7wYCAwGv3a67vQ/vzQ== X-Google-Smtp-Source: AHgI3IZUcMLPUl3qPRGtpw013F52WrGBdIH+7knEOR1vdZLU3v96k04BvGPqUiO0g0kpUKWbmq5k/jFIpYeA2zdJXew= X-Received: by 2002:a5d:9455:: with SMTP id x21mr307000ior.250.1549733963932; Sat, 09 Feb 2019 09:39:23 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:c890:0:0:0:0:0 with HTTP; Sat, 9 Feb 2019 09:39:22 -0800 (PST) In-Reply-To: References: From: Carl Eugen Hoyos Date: Sat, 9 Feb 2019 18:39:22 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavf/mpegts: Convert service name and service provider to utf-8 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2019-02-09 17:42 GMT+01:00, Marton Balint : > On Sat, 9 Feb 2019, Carl Eugen Hoyos wrote: > >> From 9033f0a18727a7a576c4cc06b9985d6d922d46ad Mon Sep 17 00:00:00 2001 >> From: Carl Eugen Hoyos >> Date: Sat, 9 Feb 2019 00:49:51 +0100 >> Subject: [PATCH] lavf/mpegts: Convert service_name and service_provider to >> utf-8. >> >> Fixes ticket #6320. >> --- >> libavformat/mpegts.c | 48 >> ++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 48 insertions(+) >> >> Diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c >> Index b04fd7b..1e27500 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 >> +#endif >> >> /* maximum size in which we look for synchronization if >> * synchronization is lost */ >> @@ -674,6 +677,51 @@ 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) { >> + char iso8859[] = "ISO-8859-00"; >> + 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", "ISO-10646", "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) { >> + if (p[2] < 10) { >> + iso8859[9] += p[2]; >> + iso8859[10] = 0; >> + } else { >> + iso8859[9]++; >> + iso8859[10] += p[2] - 10; >> + } > > I think this would be much more readable: > > char iso8859[16]; > snprintf(iso8859, sizeof(iso8859), "ISO-8859-%d", p[2]); Definitely, new patch attached. Thank you, Carl Eugen From 8ef77f9fb36c85247a9514fe18f4b48fd23f405c Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sat, 9 Feb 2019 18:38:13 +0100 Subject: [PATCH] lavf/mpegts: Convert service_name and service_provider to utf-8. Fixes ticket #6320. --- libavformat/mpegts.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index b04fd7b..108514c 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 +#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", "ISO-10646", "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; -- 1.7.10.4