From patchwork Tue Mar 16 20:30:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26416 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 794BE4487CA for ; Tue, 16 Mar 2021 22:31:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 62D6D68B003; Tue, 16 Mar 2021 22:31:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB8E068AB4D for ; Tue, 16 Mar 2021 22:31:28 +0200 (EET) Received: by mail-ed1-f42.google.com with SMTP id h13so23124453eds.5 for ; Tue, 16 Mar 2021 13:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=SoHb4Ls+Lfo7W7AKw85jTG8pth4DVgL2QYwz2SF+ro0=; b=hCKlC1Uod7H42eIjLGNUrKvxgiAObZi1UNkNWB1t/9MRlIf/Hm+aek2PHkSaykBmSY Tlue1n8YcTId5tkIQwpRZNxglp1F6J5+mmwiNBWVCij3PqUbgDMzZwt2fxZBl+YdsDgQ 8uQWX0PB11yvAx1dc8ZsH8tiMhVU3euTaP8zULy4MVcHBkGYnKdHFKVJxdEEX9VJ5nbZ d86U+qUMsKbUkg8zzDD1SxZH8UAikhw29BHqCbw2W72okYNZc0rLFWf8Yo+3EH91RlSR r4YrsOlbl+/LfNKLcmE9SvnK8uOPXQu227tPwKSrRo/VX3xifoL+OsHZb0DRuDwLCFRW 21tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=SoHb4Ls+Lfo7W7AKw85jTG8pth4DVgL2QYwz2SF+ro0=; b=pehlp4Z8ZavYTBllnpUh/rstI1OfeLwhn73/TGD05qw+zMPMI7rfwpO8KhoHlUjRSU 75AG/MVy6JNjxDTsW5cOkXvNeC02wDKrgvSFxd+6UBjJUyfL2jEDMVK6V1YiGb49XGvc T3vqBo2g4qsMrhuhmwBbXq4ZUO8OMakYlJwq409QcJ9FaQ1/71j2I0+gER8m5lVxYnxh RNlUUui5QiCgCGd/iVPNET95NS/y7nS0IALBTST8Q6Fsev7oqH6PNQ1cr/QGOA0CTOHE Hz528/KIQv3QWxeSA8b9eF04ShPUvflBUAXLlQr1sclEWaxYkgDf2AjNVzdABy8lE7Wd t67w== X-Gm-Message-State: AOAM531aAFFYdC+hTWAAXmwnWb/rvL2wopB4F2ee+XbdCE16mlFNtxmI MzrrNxqYHZ7IJMIdEu2PGO6OhV34NXmWlg== X-Google-Smtp-Source: ABdhPJwo34giGPSZzjD+nT9Azy3c+8H617BUcDqsXZFqKUHg9aIkUB7q+7ejk6Zee/9aZVtp59uD2A== X-Received: by 2002:a05:6402:32d:: with SMTP id q13mr38421389edw.17.1615926688193; Tue, 16 Mar 2021 13:31:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id a22sm10281908ejr.89.2021.03.16.13.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:56 +0100 Message-Id: <20210316203100.528950-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210316203100.528950-1-andreas.rheinhardt@gmail.com> References: <20210316203100.528950-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] avcodec/utils: Perform sub_charenc/iconv checks before AVCodec.init() 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also move them to ff_decode_preinit(). Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 35 +++++++++++++++++++++++++++++++++++ libavcodec/utils.c | 40 ---------------------------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 5a00aeedae..cbd41c8cc8 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2031,6 +2031,41 @@ FF_ENABLE_DEPRECATION_WARNINGS avctx->codec->max_lowres); avctx->lowres = avctx->codec->max_lowres; } + if (avctx->sub_charenc) { + if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { + av_log(avctx, AV_LOG_ERROR, "Character encoding is only " + "supported with subtitles codecs\n"); + return AVERROR(EINVAL); + } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) { + av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, " + "subtitles character encoding will be ignored\n", + avctx->codec_descriptor->name); + avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING; + } else { + /* input character encoding is set for a text based subtitle + * codec at this point */ + if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC) + avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER; + + if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) { +#if CONFIG_ICONV + iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc); + if (cd == (iconv_t)-1) { + ret = AVERROR(errno); + av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context " + "with input character encoding \"%s\"\n", avctx->sub_charenc); + return ret; + } + iconv_close(cd); +#else + av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles " + "conversion needs a libavcodec built with iconv support " + "for this codec\n"); + return AVERROR(ENOSYS); +#endif + } + } + } avctx->pts_correction_num_faulty_pts = avctx->pts_correction_num_faulty_dts = 0; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 2bc556c1d9..3629813387 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -60,9 +60,6 @@ #include #include #include -#if CONFIG_ICONV -# include -#endif #include "libavutil/ffversion.h" const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION; @@ -786,43 +783,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ret = AVERROR(EINVAL); goto free_and_end; } - if (avctx->sub_charenc) { - if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { - av_log(avctx, AV_LOG_ERROR, "Character encoding is only " - "supported with subtitles codecs\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) { - av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, " - "subtitles character encoding will be ignored\n", - avctx->codec_descriptor->name); - avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING; - } else { - /* input character encoding is set for a text based subtitle - * codec at this point */ - if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC) - avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER; - - if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) { -#if CONFIG_ICONV - iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc); - if (cd == (iconv_t)-1) { - ret = AVERROR(errno); - av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context " - "with input character encoding \"%s\"\n", avctx->sub_charenc); - goto free_and_end; - } - iconv_close(cd); -#else - av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles " - "conversion needs a libavcodec built with iconv support " - "for this codec\n"); - ret = AVERROR(ENOSYS); - goto free_and_end; -#endif - } - } - } #if FF_API_AVCTX_TIMEBASE if (avctx->framerate.num > 0 && avctx->framerate.den > 0)