From patchwork Tue Mar 16 20:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26415 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 7D6434487CA for ; Tue, 16 Mar 2021 22:31:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 475EE68AFB5; Tue, 16 Mar 2021 22:31:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E507968AF1C for ; Tue, 16 Mar 2021 22:31:07 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id e19so74440596ejt.3 for ; Tue, 16 Mar 2021 13:31:07 -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:reply-to:mime-version :content-transfer-encoding; bh=ueQ/0tQfDEDxUsWvRLV+24lLJLm7egnEDHpBWUDM9+Q=; b=aeueLgem2gJijs3+bfwI8nTyAXRok0wV9TxSaffhWO5yxigy0kpmyXuSCKz+kz6mRE V4SzzvAq690E0mtoO3Dkf2rKUZJZ+BN1MmIRFCi/l2pJUEH5LMbT2ThV6ZwXVEmObhGb t0Vje72uZb53Ra5QNlZmU2zzAi4xrhrnBc24NogC/RUhLNwhEYGT+qOsdYOD5+loixot Iajlo0d+JIQMUWAzcHmjOjYrnxDS6jVumJFsCD+wREMyIPVAETj4TSUm2eZ6KNybXWDN Z0t6AxSrSClC0ZEOh+MnFsfbmgZjbODfU9+RVuy97QeKCouPpJv1EZ28PVUMfV733/bH JU2A== 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:reply-to :mime-version:content-transfer-encoding; bh=ueQ/0tQfDEDxUsWvRLV+24lLJLm7egnEDHpBWUDM9+Q=; b=rEBI4Aj2D/uJrq+yGk9vI6cgRgQye0thJ3+C4XpbwcOhe8nlyVqhWxvnAU23tNazHZ 9sQh9O4QQaUcupCgfFtp5wylW3O6TC6NdzGNtd2vQ6ypcek3CqzJye393khY9tfyb7BS 1X50lIsgo+ERp9VkXI7ABShBDpbpgBmFDd2OP0/vOtc1MuGi6obDT2iv6auJZ+e6AiG9 2dlqRN3ZqQxQ5kqjSlylgPHa/KEoZpL9b2sqh3qMO9HYLfVBoutQJzMo0M2dIEFzihuM ut2tGTG06naw0efw8+nECBiZB3mO31Y6Ve7EIMABwnDRkbOn31DqShLdLRaHA9mXm31V le3A== X-Gm-Message-State: AOAM530qZ4GQW9VO7NRajegUo/dUa+HUlNsmJYRV1XI99qa4GEiv46/I gKwS9Dcu3lkfMha1qHEppB70w8BvDi71cA== X-Google-Smtp-Source: ABdhPJwLHv1xkJQAMf1kw7ioF36+ji3VVFFeWm4Xi6z2xS06uMphKq/B+Ef6rA+E5/RCHKxLHufQxw== X-Received: by 2002:a17:906:4117:: with SMTP id j23mr32444384ejk.10.1615926667231; Tue, 16 Mar 2021 13:31:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:55 +0100 Message-Id: <20210316203100.528950-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] avcodec/utils: Check earlier for codec id/type mismatch 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" These fields can't be set via AVOptions, ergo one can check them before having allocated anything. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 71dbcb19d8..2bc556c1d9 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -564,6 +564,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (!codec) codec = avctx->codec; + if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && + avctx->codec_id == AV_CODEC_ID_NONE) { + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + } + if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type && + avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { + av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); + return AVERROR(EINVAL); + } + avctx->codec = codec; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -682,18 +694,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code goto free_and_end; } - avctx->codec = codec; - if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && - avctx->codec_id == AV_CODEC_ID_NONE) { - avctx->codec_type = codec->type; - avctx->codec_id = codec->id; - } - if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type - && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { - av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } avctx->frame_number = 0; avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); 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) From patchwork Tue Mar 16 20:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26417 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 703D54487CA for ; Tue, 16 Mar 2021 22:31:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 53EAB68B018; Tue, 16 Mar 2021 22:31:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFBFA68AB4D for ; Tue, 16 Mar 2021 22:31:29 +0200 (EET) Received: by mail-ed1-f53.google.com with SMTP id dm8so23151595edb.2 for ; Tue, 16 Mar 2021 13:31:29 -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=Ig4p3oL9r4fywjprxMA0e01fN5n9scNyhBRN+YqphVA=; b=eguSPF+liNRhg0+u0O5Yia5XbDjmGMYpEY7HXFUVi6S3pl/UktbKrbQyx2kLGJvPl0 StGhoh5c4lo0sOOX6H4gtfxo27P8p3ebrtoUNVStVoKn8i1/l+wIAwgRDqIwxifuFGZS LJSuuF1MgOer0q4QHZroJoUaAzhnauJj7Ha3fmVLn1SWX7bhCFFbt7Q3PRrUwhGM/Ltl QHbJjx7q2Ujg3gB5FZma1G+TZslrpzxvDLBszqv97cmK+3RSsmVxcPWhXlfJTXRv6pbg yOX67C/uhJqfmPVygJQYLQ8sZ7u8gJfI2ka36tLqxIYoDEjNllQ9TxU+wLMWQ1GDZnzW cBWw== 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=Ig4p3oL9r4fywjprxMA0e01fN5n9scNyhBRN+YqphVA=; b=cFlDfJHZKxZc2TvS8mtJ4HHOk5g/fg+44aUSuksBspJxNVPJROil6l/pAZ2C8lOb+A rwU4RpRZbo7C0EveiRPTZJD5K8ugbjxU6NH+glEzzJcCgVRy8algYPRNyMaOY8skWfmT SVi81H14uB7onMkJ61zKA0puxurV6+Fx7p+FZJmsdSyIhW3bbYhK/Jd68mFwqiSHyksf I2gN/hTnkVsGN8FJsf/RD4GhfR8buaMPcrRF+XksgUZle3Z748ND+vngJ5ph7mpUofKt QsLdHGCn2Ihkv1dJ3UDenzW3Pz80hY1fjsMZxkWJ0/jz0KiTX17BMt89SF3rICT/036/ z40g== X-Gm-Message-State: AOAM531NL4xZ2RpGrrnpcIswmXAy/p4VFOuWPBIRHzq+JZwkiug0WlTE 59RVjCKeEv71W/AFHJRVUevTTjnE18prAA== X-Google-Smtp-Source: ABdhPJyCsLvR/TfZqrUzqsSji0zLOwmN6xsIhZpl8DveAcn/+j03yEWOBG97yjDZThmlkyBCV4z70g== X-Received: by 2002:a05:6402:180b:: with SMTP id g11mr37629460edy.195.1615926689110; Tue, 16 Mar 2021 13:31:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:57 +0100 Message-Id: <20210316203100.528950-3-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 3/6] avcodec/utils: Sanitize options before using them 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" This is how it is supposed to happen, yet when using frame threading, the codec's init function has been called before preinit. This can lead to crashes when e.g. using unsupported lowres values for decoders together with frame threading. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 3629813387..7d4ad113df 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -716,6 +716,13 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avctx->time_base.den = avctx->sample_rate; } + if (av_codec_is_encoder(avctx->codec)) + ret = ff_encode_preinit(avctx); + else + ret = ff_decode_preinit(avctx); + if (ret < 0) + goto free_and_end; + if (!HAVE_THREADS) av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n"); @@ -737,13 +744,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) avctx->thread_count = 1; - if (av_codec_is_encoder(avctx->codec)) - ret = ff_encode_preinit(avctx); - else - ret = ff_decode_preinit(avctx); - if (ret < 0) - goto free_and_end; - if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME) || avci->frame_thread_encoder)) { ret = avctx->codec->init(avctx); From patchwork Tue Mar 16 20:30:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26418 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 87FB14487CA for ; Tue, 16 Mar 2021 22:31:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C5EB68B042; Tue, 16 Mar 2021 22:31:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B50C868B012 for ; Tue, 16 Mar 2021 22:31:30 +0200 (EET) Received: by mail-ej1-f50.google.com with SMTP id mm21so74300209ejb.12 for ; Tue, 16 Mar 2021 13:31:30 -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=UAljzxoDn8344Q5VxVp5IXa5i3WeB/T9emoU5U+YEEs=; b=Z2/H3EYvFkr3HmbUsinb6bpnYpGClJieY2pnB05q9HaUUwYzorq9zoWHFjm4VH3DT8 UlxXhyVagdX82TUo2e2xSJ01/h9dkIAgaSP+IetBpYbEWVbCD6wcofFjWKh7UAq0qXAb o4vwL8cUozP95Wf1hiuAggPA/fRyNH62D2ZMPcIjCAN4pEN3DNC4q3NXMiu1vj9B9kpG /s1mzZriK6HlD5h33boC/stslP6k5fmv7zqNMjav1qegNo/ak5wxGogIDncgs+ob2no2 GZnmCNvxMUOP0UL8r18Rq0r5xlXO5TT+Uu8WkQaslgnb4vkWY/s6WZkiiI2ViL/9fXxM xuIg== 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=UAljzxoDn8344Q5VxVp5IXa5i3WeB/T9emoU5U+YEEs=; b=KxKyD4Gt1VbuEmPcEFrtbHZGTFq/YUABJbmw3eb+48KHSLT1txTVg10RMZ7RR7PdnH cO55UhC62lbeMruDXtUaVS86vRha33jYfl6ti0188sV5cOYAkTXtiEyzy/AjMT8eD4Lj 76NLNucZ6Zlg2WH0wLxp7eSRi+Vaj7QXAjVUGoLXi/fmLT0Dy9ZhbOwQHn+wPlABNtY7 AMKLnFsgt844z1wYWd8zt/EsDt9gvtgEMmSWGuREckGlrp5/HA2GgNQ4V24dNjiLTFdf BfRBNZxdjacl70xwoS6hECQTEcAKknIhZSgxaWOf9UVwGad+X19mUkGdxsnMgKhBwByE URyw== X-Gm-Message-State: AOAM530nh6TeAj/C34mtBDYQS3J/Vx4mnT5gXgzMYgTqGotVa6WkuMBu 173gLQWLqYi4dtcXk7Oyw7tTH31fb8kimg== X-Google-Smtp-Source: ABdhPJxqcqs/WdtmP54bqu9+YWhWWc823gWmYsYYIuzGbgKiw8LKIkKn0WS4/+OvoDmrrL+mRz1WBg== X-Received: by 2002:a17:906:4107:: with SMTP id j7mr15608533ejk.185.1615926689989; Tue, 16 Mar 2021 13:31:29 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:58 +0100 Message-Id: <20210316203100.528950-4-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 4/6] avcodec/utils: Move decoder channel count check to ff_decode_preinit 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" Signed-off-by: Andreas Rheinhardt --- I actually wonder why this flag is not used for encoders. Several of them explicitly check for invalid channel values. libavcodec/decode.c | 5 +++++ libavcodec/utils.c | 8 -------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index cbd41c8cc8..390147908d 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2026,6 +2026,11 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif + if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->channels == 0 && + !(avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) { + av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n"); + return AVERROR(EINVAL); + } if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) { av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n", avctx->codec->max_lowres); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7d4ad113df..77f98c951b 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -671,14 +671,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ret = AVERROR(EINVAL); goto free_and_end; } - if (av_codec_is_decoder(codec) && - codec->type == AVMEDIA_TYPE_AUDIO && - !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF) && - avctx->channels == 0) { - av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } if (avctx->sample_rate < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate); From patchwork Tue Mar 16 20:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26419 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 8DE684487CA for ; Tue, 16 Mar 2021 22:31:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 77F3C68B046; Tue, 16 Mar 2021 22:31:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 598B468B027 for ; Tue, 16 Mar 2021 22:31:31 +0200 (EET) Received: by mail-ed1-f45.google.com with SMTP id e7so23117931edu.10 for ; Tue, 16 Mar 2021 13:31:31 -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=V2O8mJndySAqvWrcVscrHLamm5crmc8BHIFbuFF/RkI=; b=MgfovKndDyvvejeg6pOOlCTLcuAl8y33RD71I9JqYRFGJfgOr+wSyHqCwP7LZPWLET 7u/TnlvOSmfLsFLJmiA4aPHdTMswUSn/7kiBqUD4LiBSnUvXqX8YUQNT0ek312c/JOzQ dHcYlRsNOYz/l34ITCIiOgbJ+CZTnj9ys6rszycv9EZ2RJUgjYKHsqme2TgeQSGLybO0 +XEZc0/hvu5NrSRp9BtiZxLCMLGxzMzAd4yAagmkOyAddajOtTOb4G+YyQRa4Pnks77e 1eIanMvTGtp69PYMQIs6XV5FiWHzbdqQb49nn8TmpLcl+Vs8F7778Yz0Qy96M/F2YKos HT4A== 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=V2O8mJndySAqvWrcVscrHLamm5crmc8BHIFbuFF/RkI=; b=BomjzUZPJ5Ct9SP3fDoHkIXkEG7dRFyV79FlPB1rhhR94vDmzckjgEqebO7UbYku/i cwatUpp6I1uBcN+EpZL6edQcg+Yb9ZGVXmig6uAt7IcO0JqNQBO6XGrKyjxgAf+7dVEg oq5ONlmAbw3HFCkgtwTNsdgAzh4+dD+rnun0Yp6Wn75zbsvOUgyNLYd9dLXmiQLtJKfK b0YYtFVdleQXYQ8/Y0CDBSW4o/S3gXNyTVQMaz4T0RObmnBshbWh6h1isJxrQ97cNJdM 9eP09HPDFl3/UorwFRaG/x1ljORuy3Bu1gdMw9HKscYYyFzAnMhbt577+2jFrOxmHnaS eXlw== X-Gm-Message-State: AOAM530RKkFKer4tKFnq+33qaeBtUPDvMnyi6zXARHK2gnnpyt4Gt2BD ikxnHg9Aldg1rDwXzLiDZ5pvfyXSvpjLfg== X-Google-Smtp-Source: ABdhPJxZHoQ909t86yv0DzhBNgS5vixLPk5wY/q6z3mlLxSwD8zm2UaDIVc3Kqueggc1ERDdVXe8Tw== X-Received: by 2002:a50:e702:: with SMTP id a2mr38898714edn.3.1615926690765; Tue, 16 Mar 2021 13:31:30 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:30:59 +0100 Message-Id: <20210316203100.528950-5-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 5/6] avcodec/options: Remove always-true check 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" Added in dc51a72ba45fbefb9f1c6c3ca5a5b2388d69b2da, yet even back then the check was always true as the AVCodecContext has already been memset to zero before that. Signed-off-by: Andreas Rheinhardt --- libavcodec/options.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index 61689b48d9..53f13dab37 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -140,12 +140,10 @@ static int init_context_defaults(AVCodecContext *s, const AVCodec *codec) s->reordered_opaque = AV_NOPTS_VALUE; if(codec && codec->priv_data_size){ - if(!s->priv_data){ s->priv_data= av_mallocz(codec->priv_data_size); if (!s->priv_data) { return AVERROR(ENOMEM); } - } if(codec->priv_class){ *(const AVClass**)s->priv_data = codec->priv_class; av_opt_set_defaults(s->priv_data); From patchwork Tue Mar 16 20:31:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26420 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 CFA2F4487CA for ; Tue, 16 Mar 2021 22:31:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B48FC68B04C; Tue, 16 Mar 2021 22:31:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 65BB668B021 for ; Tue, 16 Mar 2021 22:31:32 +0200 (EET) Received: by mail-ej1-f46.google.com with SMTP id mm21so74300339ejb.12 for ; Tue, 16 Mar 2021 13:31:32 -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=TP7ELip2zL7UOVix7E5HodB5KAbue8+24+asyP8+/gs=; b=uK5mHuOGBGgEAsJ5wxZAqEzUzBMHjR2qm35NT2hsRkP3Nbt/HPlMntv/vHKZSx1XRK EW4wJLWpOb99FtYgSa0Iqo2ppPI1r0lQFaZzmyODXMGe52h/xsQrLWd62VbUpwYNyJUB KFpNIbYMJJ+PFATEm8LSErZcR9oGWiH63EJPAiHsIASOsU8qWQ2KUrA21qAQkmn0X0j+ HEgxe3+ZdVs4eGGSIcUJ7efrzKzthqnykWVZH/deqkfWvHcf8/7HXmlyjoKFOEG/3p2c 8Nj8Bv3PhO3ltqD03nVZoupELwxHJCz0KKQUPDa5oeZeeA+BiKabS88KN5A9wU0/S3Gf ZqZA== 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=TP7ELip2zL7UOVix7E5HodB5KAbue8+24+asyP8+/gs=; b=KIOzFBv9Y7nlgJr/Y/IoXNQq7FGf3FfWJKPvphxeDY+l9Q6Cq0py7L4w5V0uRL0g5i OhJG+2ZTmni1ZrNq0ngBxKBetpIbQoHtUB5dYNGsRBWM1C39xsc9oM+Ulu8WSJKItEHF zpieQ8f2E4zVi2R+NhsC3MWEAr4T0+CJ4DknzmxcPP/tWbkqYLWQQyyMQPgi9sOrjHrn 3QPhGcgansgk5F86ZpEbHF98fCcjixS8axsJfZG9ck5oIUWMJxXyCXWQPcBX1ESkzpBK dAdTOU4QznWfSoOk+TlxWxpPHBxPgSueS9/PrdhN1BscThM6vyQmA/hMzx7FyXE2ISZ9 VWrg== X-Gm-Message-State: AOAM5306c+siAyWIG/GyVb2HwR6mrvpcT9LjmDIYkkioVGVyPhq7dUiC vUjOTqWK1wqfFK6GFCH12Fxy780+mRzrsQ== X-Google-Smtp-Source: ABdhPJzVEHaXULDAKiOG+fW3DWdcJ/eJkWIF2Y5Olqnq+VndDrw0I+K9oXgwBd314NfKikDBzyEs1A== X-Received: by 2002:a17:906:8443:: with SMTP id e3mr31091255ejy.370.1615926691602; Tue, 16 Mar 2021 13:31:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 13:31:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Mar 2021 21:31:00 +0100 Message-Id: <20210316203100.528950-6-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 6/6] avcodec/options: Reindent after previous commit 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/options.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index 53f13dab37..58c7ce8d62 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -140,10 +140,9 @@ static int init_context_defaults(AVCodecContext *s, const AVCodec *codec) s->reordered_opaque = AV_NOPTS_VALUE; if(codec && codec->priv_data_size){ - s->priv_data= av_mallocz(codec->priv_data_size); - if (!s->priv_data) { - return AVERROR(ENOMEM); - } + s->priv_data = av_mallocz(codec->priv_data_size); + if (!s->priv_data) + return AVERROR(ENOMEM); if(codec->priv_class){ *(const AVClass**)s->priv_data = codec->priv_class; av_opt_set_defaults(s->priv_data);