From patchwork Thu Mar 4 15:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26088 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 529C54490A6 for ; Thu, 4 Mar 2021 17:42:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2611D68A71F; Thu, 4 Mar 2021 17:42:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 17E5468A429 for ; Thu, 4 Mar 2021 17:42:44 +0200 (EET) Received: by mail-ej1-f49.google.com with SMTP id jt13so50337228ejb.0 for ; Thu, 04 Mar 2021 07:42:44 -0800 (PST) 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=xwnDrXwcubXo9nXmgWMKm0MJq3q274EbJe6KXgwfbXU=; b=bJz5RLTga6amNf5fdcCVqnmSPLvsurm63+wFUsdLMHU6d5qe0xfrqHG8t+ayvkiwyg +P6BNCuodsJpIDt+Dm97/JJFoHseBou7crrVbQ+ybDwgBY8KOXBYfOf9r+r3/QeLMjz+ TUMQgQ/xaLrT0Z3SwLont0LDtuyhIo/4CIjofOHNOLplgfYe2kLw3ox2kx7qgMIi+WSN XE1MqZuHF1W5u+NOqP/ZrWVF3nqEwbJpbW9s5lXFNeyCn2Zj7yOaPVDqgcdUC0xvrE6J sQzzhIZyOZNbEsZlngmVDHqoM18+ieqpZO2x8sLk6HvP26sJkz/kS1wiWuvLVQXGczqW eVrw== 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=xwnDrXwcubXo9nXmgWMKm0MJq3q274EbJe6KXgwfbXU=; b=tyr6APMvpp/8xGZTMAoIzTIbE6Xo3yLTCC39zQtUxgIj+aAeM11A3HNdeE/A2ISok4 g1gIWwGsnvMsMV95ZfwzG2uBJ4OlrRIojFUUDjef+uEwaa6L0NgXeRguvf5VElCITll4 1PsHs0dW5wjJKc9FpH2ai6OLL7fSTr9g0mNJy/ZXdqFmYhCj2x0+OMn1lpPX9ap7T+1G fWuNDqaeGi41V7GN7bzzEOiVvHtUB46kMoV2PHOrDCYpL385aa12I5m89HcIgsvIV9Yl aM+6o10gBHMY9ARoCeuxCFrQsREVvlISM33vM7A9FAAut8js0qQkbvX0qRa6j5C2awLS xqwA== X-Gm-Message-State: AOAM53118IIqXxNexcXLzsKFHVuAk1l1uy7FmfMgCW0cKsk9Un+FfDk/ GIlZuMw/5VcVhQqohP+WNNsESiwyhQY= X-Google-Smtp-Source: ABdhPJx56E3ecLPFeyDkm31P+mSdZ2Lbs0+DNZQHle29gSke5M6GF7hXSuDlAHG0Oo5BhlOMNFfbLQ== X-Received: by 2002:a17:906:2bce:: with SMTP id n14mr4715709ejg.171.1614872563346; Thu, 04 Mar 2021 07:42:43 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:42:42 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:26 +0100 Message-Id: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] avcodec/decode: constify the source packet parameter in extract_packet_props() 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: James Almer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: James Almer Signed-off-by: James Almer --- libavcodec/decode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index d445ac75b0..5e5d0c7066 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -144,7 +144,7 @@ fail2: #define IS_EMPTY(pkt) (!(pkt)->data) -static int copy_packet_props(AVPacket *dst, AVPacket *src) +static int copy_packet_props(AVPacket *dst, const AVPacket *src) { int ret = av_packet_copy_props(dst, src); if (ret < 0) @@ -156,7 +156,7 @@ static int copy_packet_props(AVPacket *dst, AVPacket *src) return 0; } -static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt) +static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) { AVPacket tmp = { 0 }; int ret = 0; From patchwork Thu Mar 4 15:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26089 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 72726449EC7 for ; Thu, 4 Mar 2021 17:43:12 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4FE6D68AB0E; Thu, 4 Mar 2021 17:43:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1EB46897E3 for ; Thu, 4 Mar 2021 17:43:05 +0200 (EET) Received: by mail-ej1-f51.google.com with SMTP id hs11so50285816ejc.1 for ; Thu, 04 Mar 2021 07:43:05 -0800 (PST) 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=5VfzIOCVBgr+KLQbzDu3KvkB2iozuoUuw5bSLZnVa8k=; b=emoeliCBLsdsL6IE02SsoT/mR76HNqhNW6j6SVjsBUSQv64+QDxPk804PGtbIs7YEK +PNBseHvldEgEKag+HlDuNT2BCKt+Lf4ufwS4kA91fL3WwPUtnQj/z7rFywuumPSM9Um HKKuumXXPbY7FdyAfj5eFKhIU+VxtwrZeBT7PshQdfp/jQNXPQ//KGZcvcep2ivJ+xXV M9viv9s8/9RcAGEB1NJ7Adh8xckzo5omlvLCu/JthHb3hjEG3nW1wzSNbFzsK8HNcFUB BKMFmxqsUj4vmrhjjqNf0qH8+71xJTYfm6wt9NiKgaA2fImC5S6UCEwMdHRDwk/K4j2Q 1i6Q== 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=5VfzIOCVBgr+KLQbzDu3KvkB2iozuoUuw5bSLZnVa8k=; b=A5a1ddjPIAcgk1JMQSvdNkBAAqQlWDFITZ06oc3LlFE3Zwgp1meZI1Frg97mHWgMdf CW9E+vqh9HCgkJzH0dhG5FwCrT+lKZl0OT0hiLXFZZUOioCk16joA7qdw0oaziXtHzFR dT7dQg9RaypYsOgGmO/9OMjpgF3vllTIN9aF9zMfCBpgEZQheC8iPY3blKoAf0RZwH42 81uezeCVNGb4gnb7hKJOKLJ0i4drY35UnPrfRg//vb2Lm+UnjPXp4no9ZtlZ8JdMN95e YhC+KXYNwgcRKzYz0d0xPBfF8QpKPM7PmObbOKAbmtIRl5x+8gWojOtQ4TGj2KghVSLZ DDCQ== X-Gm-Message-State: AOAM533KKF4JsfO2THvhJtTm7ZDewHAjklkF+LkTX9NQR4gA8wfyWSLC 0UBTSzsM/nNGM2/1THysmr5CsFPE2Os= X-Google-Smtp-Source: ABdhPJx8xPilJmaDTDXJu+leJwkWKcTwObUTZJpun97aWQbRQ0WFq83uWQGQF8cEK6U8KyEhqjJfDg== X-Received: by 2002:a17:906:3b41:: with SMTP id h1mr4676380ejf.506.1614872585077; Thu, 04 Mar 2021 07:43:05 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:04 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:27 +0100 Message-Id: <20210304154233.934640-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] avcodec/decode: Return early upon failure 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" Allows to remove one level of indentation. Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 5e5d0c7066..db6ee9cb04 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1043,9 +1043,9 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, AVPacket pkt_recoded = *avpkt; ret = recode_subtitle(avctx, &pkt_recoded, avpkt); - if (ret < 0) { - *got_sub_ptr = 0; - } else { + if (ret < 0) + return ret; + ret = extract_packet_props(avctx->internal, &pkt_recoded); if (ret < 0) return ret; @@ -1099,7 +1099,6 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, av_packet_unref(&pkt_recoded); } - } if (*got_sub_ptr) avctx->frame_number++; From patchwork Thu Mar 4 15:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26090 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 939A5449EC7 for ; Thu, 4 Mar 2021 17:43:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E85968AB3A; Thu, 4 Mar 2021 17:43:13 +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 9231E6897E3 for ; Thu, 4 Mar 2021 17:43:06 +0200 (EET) Received: by mail-ej1-f46.google.com with SMTP id hs11so50285903ejc.1 for ; Thu, 04 Mar 2021 07:43:06 -0800 (PST) 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=SooP/5F5ZO8I+Tp8kDQc2JR/i9rp6Pg6p0/mQ6xsnpU=; b=PKiSQij7sSMVa8ehHwl3pJc0/FcbY3g0Jx1IuAqK1tUTuVeW9x7kcYrK2zpKk6EOpW V0BRpmesC+/fGkI8UkUgUNfRIYLeh9Snr/lMZmY2/faHFQUOolxYcc3Qvaii2ubkM4M0 3e+tzeEEuNLVazUajtRmKmafqzIP9hyKniE+1OhI0MBolTxot4AhFU28x3g0fNNVaIbn nqQCI3JrddY/zfHymZoYzKaDOYuzw/wRWagQ+rNb4dONxHRoIoB8C71kydLG3SU6m/OZ UMh9gR7beNQWfdaB0bSOUQ1UyaeK7oL4PzA/OFbye36RGpMD3EsJ5ridGxubCr+S1mFO lTwg== 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=SooP/5F5ZO8I+Tp8kDQc2JR/i9rp6Pg6p0/mQ6xsnpU=; b=tSen4EL8Rjah7vhCQmFSfwIn7gg4CZQ7Egj6SlsA3D2gfbQgh7rWthQiIEYjcwuQV3 TFaPhvQjJIa/IXntwzM+Kmtgrwt3xHseS5TG46aYl80IbDzg0+qZXGTsG1G507q6Q78K iHjyXUlLb1EIqdEgQAsxmyRW6JwTqIi26JPJk6kbavDx+YNB2S0ZrlVLJFLy79CCQirm T4HU4iN4DE29x5z85F04Hl0UtGxptEuZ5RWkmlLxDx11eqJm4BWFEeekyCha8VkBKzDp K+6CabMsE2U9lEYp7gl1IlHgRHorrkmI/fotQi9C3JsoV2fzikXQ6hZszE0fAsjLNtHk yWoQ== X-Gm-Message-State: AOAM5315Z7LS71D8i/2a2NKphZI+xdQC09RitWb5TTZ9DSUotRqh62W0 cIBQFwYljnbaENM54jD4GOSUux+mo/w= X-Google-Smtp-Source: ABdhPJwYHrsuzMs8EdN5AzTLUf6MGG07P6PATuHwCnAXtlULuvKD9WcpGJH1pKR0hFTzgNC6dJvUdw== X-Received: by 2002:a17:907:119b:: with SMTP id uz27mr4829096ejb.464.1614872585891; Thu, 04 Mar 2021 07:43:05 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:05 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:28 +0100 Message-Id: <20210304154233.934640-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] avcodec/decode: Check size before opening iconv 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" Avoids closing iconv when the size check fails. Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index db6ee9cb04..c976795311 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -884,18 +884,17 @@ static int recode_subtitle(AVCodecContext *avctx, return 0; #if CONFIG_ICONV - cd = iconv_open("UTF-8", avctx->sub_charenc); - av_assert0(cd != (iconv_t)-1); - inb = inpkt->data; inl = inpkt->size; if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) { av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n"); - ret = AVERROR(ENOMEM); - goto end; + return AVERROR(ERANGE); } + cd = iconv_open("UTF-8", avctx->sub_charenc); + av_assert0(cd != (iconv_t)-1); + ret = av_new_packet(&tmp, inl * UTF8_MAX_BYTES); if (ret < 0) goto end; From patchwork Thu Mar 4 15:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26091 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 89700449EC7 for ; Thu, 4 Mar 2021 17:43:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FB6C68AB76; Thu, 4 Mar 2021 17:43:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 950F468AAF0 for ; Thu, 4 Mar 2021 17:43:07 +0200 (EET) Received: by mail-ej1-f44.google.com with SMTP id lr13so50251829ejb.8 for ; Thu, 04 Mar 2021 07:43:07 -0800 (PST) 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=NgCbWrQSaAphlTaYg7g8c4vxU6seTy2PbByF/Sc2trM=; b=Y/HqHCmsj7bI3ak0L+8wAoi4eslAPZNinF+LmfAOkKe2G2uybfgadxWJGplWkRjDhP OWbeyeZB6qyAXKM4djLT3EdEucGNgkhvcC+J+zz/2m7YcWv54iqP0Yvj1vnzHXdMzpSf VIsj1eZUEyEWlbui316aLYUyF4Cc/heXV26sSEktS+b8p/H0vn5SLI8Kzm7RRCHTBo61 RZZT+jnWIigRF0/0Cf+raSXNNQfZfROLd0bMJQUh7/EXpbX/lTZlAc5eLcxQLRhKz6kg ZLwr25Z5On4lp36Sw7RxSzTDyW5RdXUwMs6UNql2H+hqnomflGin9+5uhp5OVJCH3SH0 /YVg== 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=NgCbWrQSaAphlTaYg7g8c4vxU6seTy2PbByF/Sc2trM=; b=SmMZRYJLjNU9mpXmwEwpNRpRxXa5YwaJDnSmy81KcgXTUvau4Yyg5+BLjJikWgbHJQ I3jegiNSVNCcjeaTGmzHJHoFmwUfRcfhQq+QiPyO7tQYPmm/WVXxlqNYPs4UtEZrJ0Sa MMubXAQC6gexeZLyaBNQ2UcGVH3zB/OjZ5rwS+wA4qQjqxS3w2CGFSAOYWZU90n2SqWT fPqEvtEJJUOl72xaOXY5J/k1eAQ455BL7krxW6xHighATA8XPDtRXuCgy3pZHHwN8NKj HVYNGsqShosVDkuyKdrG0ilIJZtuUffhr8d63h+vn5NUks47XRzsGejxj2+x8lrUu1A5 x39A== X-Gm-Message-State: AOAM5319KCCFiw/SExKSlvqGl7b960COiOyPjUef+El1+rkc/bGtTeHF FuNygz7EqtMIiHK2gmF85NIj7xQ5sxY= X-Google-Smtp-Source: ABdhPJzV5GTBhtpY2pvogddCFD3Gg50fb/YHRGeQWcTdcEBdp+sI01zHWxAzWRwr4UdweySo75DAdA== X-Received: by 2002:a17:906:3fc3:: with SMTP id k3mr4951410ejj.522.1614872586640; Thu, 04 Mar 2021 07:43:06 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:06 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:29 +0100 Message-Id: <20210304154233.934640-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] avcodec: Constify some AVPackets 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 --- Of all the decoders using the simple decode API (i.e. with .decode set) only imm5 seems to modify its input packet (which is fine given that it is not the user-supplied reference); libfdk_aac's API is not const-correct, so as-is it is not compatible with constifiying the AVPacket in the .decode function, yet this is easily fixable. libavcodec/aacdec_template.c | 3 ++- libavcodec/audiotoolboxdec.c | 3 ++- libavcodec/bitpacked.c | 6 +++--- libavcodec/dsddec.c | 4 ++-- libavcodec/flashsv.c | 2 +- libavcodec/movtextdec.c | 10 +++++----- libavcodec/pgxdec.c | 6 +++--- libavcodec/pixlet.c | 2 +- libavcodec/pngdec.c | 2 +- libavcodec/rasc.c | 14 +++++++------- libavcodec/tiff.c | 3 ++- libavcodec/vp8.c | 2 +- 12 files changed, 30 insertions(+), 27 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index aa89f7cbb8..7b78566993 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -3216,7 +3216,8 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data, } static int aac_decode_frame_int(AVCodecContext *avctx, void *data, - int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt) + int *got_frame_ptr, GetBitContext *gb, + const AVPacket *avpkt) { AACContext *ac = avctx->priv_data; ChannelElement *che = NULL, *che_prev = NULL; diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c index 1f3f7f5ac5..8f9a8d5c27 100644 --- a/libavcodec/audiotoolboxdec.c +++ b/libavcodec/audiotoolboxdec.c @@ -296,7 +296,8 @@ static int ffat_set_extradata(AVCodecContext *avctx) return 0; } -static av_cold int ffat_create_decoder(AVCodecContext *avctx, AVPacket *pkt) +static av_cold int ffat_create_decoder(AVCodecContext *avctx, + const AVPacket *pkt) { ATDecodeContext *at = avctx->priv_data; OSStatus status; diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c index 952ba73a32..23e82c69b5 100644 --- a/libavcodec/bitpacked.c +++ b/libavcodec/bitpacked.c @@ -33,12 +33,12 @@ struct BitpackedContext { int (*decode)(AVCodecContext *avctx, AVFrame *frame, - AVPacket *pkt); + const AVPacket *pkt); }; /* For this format, it's a simple passthrough */ static int bitpacked_decode_uyvy422(AVCodecContext *avctx, AVFrame *frame, - AVPacket *avpkt) + const AVPacket *avpkt) { int ret; @@ -56,7 +56,7 @@ static int bitpacked_decode_uyvy422(AVCodecContext *avctx, AVFrame *frame, } static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame, - AVPacket *avpkt) + const AVPacket *avpkt) { uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20; uint64_t packet_size = (uint64_t)avpkt->size * 8; diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c index 9814c9eb82..21d1d9f5de 100644 --- a/libavcodec/dsddec.c +++ b/libavcodec/dsddec.c @@ -66,7 +66,7 @@ static av_cold int decode_init(AVCodecContext *avctx) typedef struct ThreadData { AVFrame *frame; - AVPacket *avpkt; + const AVPacket *avpkt; } ThreadData; static int dsd_channel(AVCodecContext *avctx, void *tdata, int j, int threadnr) @@ -75,7 +75,7 @@ static int dsd_channel(AVCodecContext *avctx, void *tdata, int j, int threadnr) DSDContext *s = avctx->priv_data; ThreadData *td = tdata; AVFrame *frame = td->frame; - AVPacket *avpkt = td->avpkt; + const AVPacket *avpkt = td->avpkt; int src_next, src_stride; float *dst = ((float **)frame->extended_data)[j]; diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c index f55cb0feeb..9481f80f0b 100644 --- a/libavcodec/flashsv.c +++ b/libavcodec/flashsv.c @@ -179,7 +179,7 @@ static int flashsv2_prime(FlashSVContext *s, uint8_t *src, int size) return 0; } -static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt, +static int flashsv_decode_block(AVCodecContext *avctx, const AVPacket *avpkt, GetBitContext *gb, int block_size, int width, int height, int x_pos, int y_pos, int blk_idx) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index ad790bf44c..7adc16d262 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -117,7 +117,7 @@ typedef struct { typedef struct { uint32_t type; size_t base_size; - int (*decode)(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt); + int (*decode)(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt); } Box; static void mov_text_cleanup(MovTextContext *m) @@ -240,14 +240,14 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m) return 0; } -static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) +static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { m->box_flags |= TWRP_BOX; m->w.wrap_flag = bytestream_get_byte(&tsmb); return 0; } -static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) +static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { m->box_flags |= HLIT_BOX; m->h.hlit_start = bytestream_get_be16(&tsmb); @@ -255,14 +255,14 @@ static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) return 0; } -static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) +static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { m->box_flags |= HCLR_BOX; bytestream_get_buffer(&tsmb, m->c.hlit_color, 4); return 0; } -static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt) +static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { int i; int style_entries = bytestream_get_be16(&tsmb); diff --git a/libavcodec/pgxdec.c b/libavcodec/pgxdec.c index 5c735894ab..65b2929283 100644 --- a/libavcodec/pgxdec.c +++ b/libavcodec/pgxdec.c @@ -95,7 +95,7 @@ error: } #define WRITE_FRAME(D, PIXEL, suffix) \ - static inline void write_frame_ ##D(AVPacket *avpkt, AVFrame *frame, GetByteContext *g, \ + static inline void write_frame_ ##D(AVFrame *frame, GetByteContext *g, \ int width, int height, int sign, int depth) \ { \ int i, j; \ @@ -151,9 +151,9 @@ static int pgx_decode_frame(AVCodecContext *avctx, void *data, p->key_frame = 1; avctx->bits_per_raw_sample = depth; if (bpp == 8) - write_frame_8(avpkt, p, &g, width, height, sign, depth); + write_frame_8(p, &g, width, height, sign, depth); else if (bpp == 16) - write_frame_16(avpkt, p, &g, width, height, sign, depth); + write_frame_16(p, &g, width, height, sign, depth); *got_frame = 1; return 0; } diff --git a/libavcodec/pixlet.c b/libavcodec/pixlet.c index 42acd683fa..ad9d830af7 100644 --- a/libavcodec/pixlet.c +++ b/libavcodec/pixlet.c @@ -525,7 +525,7 @@ static void postprocess_chroma(AVFrame *frame, int w, int h, int depth) } static int decode_plane(AVCodecContext *avctx, int plane, - AVPacket *avpkt, AVFrame *frame) + const AVPacket *avpkt, AVFrame *frame) { PixletContext *ctx = avctx->priv_data; ptrdiff_t stride = frame->linesize[plane] / 2; diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index cece08ebca..a5a71ef161 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1179,7 +1179,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, } static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, - AVFrame *p, AVPacket *avpkt) + AVFrame *p, const AVPacket *avpkt) { const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE); AVDictionary **metadatap = NULL; diff --git a/libavcodec/rasc.c b/libavcodec/rasc.c index 706940bf5f..207d50c452 100644 --- a/libavcodec/rasc.c +++ b/libavcodec/rasc.c @@ -112,7 +112,7 @@ static int init_frames(AVCodecContext *avctx) } static int decode_fint(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; @@ -171,7 +171,7 @@ static int decode_fint(AVCodecContext *avctx, return 0; } -static int decode_zlib(AVCodecContext *avctx, AVPacket *avpkt, +static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size, unsigned uncompressed_size) { RASCContext *s = avctx->priv_data; @@ -205,7 +205,7 @@ static int decode_zlib(AVCodecContext *avctx, AVPacket *avpkt, } static int decode_move(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; @@ -329,7 +329,7 @@ static int decode_move(AVCodecContext *avctx, len--; static int decode_dlta(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; @@ -471,7 +471,7 @@ static int decode_dlta(AVCodecContext *avctx, } static int decode_kfrm(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; @@ -534,7 +534,7 @@ static int decode_kfrm(AVCodecContext *avctx, } static int decode_mous(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; @@ -574,7 +574,7 @@ static int decode_mous(AVCodecContext *avctx, } static int decode_mpos(AVCodecContext *avctx, - AVPacket *avpkt, unsigned size) + const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; GetByteContext *gb = &s->gb; diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index d1e908fd43..9cd2876851 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -964,7 +964,8 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, return 0; } -static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt) +static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame, + const AVPacket *avpkt) { TiffContext *s = avctx->priv_data; int tile_idx; diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 89c48e6cb1..d16e7b6aa3 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -2622,7 +2622,7 @@ static int vp8_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, static av_always_inline int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, - AVPacket *avpkt, int is_vp7) + const AVPacket *avpkt, int is_vp7) { VP8Context *s = avctx->priv_data; int ret, i, referenced, num_jobs; From patchwork Thu Mar 4 15:42:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26092 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 9C7D1449EC7 for ; Thu, 4 Mar 2021 17:43:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 868F568AB95; Thu, 4 Mar 2021 17:43:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F72568AB3A for ; Thu, 4 Mar 2021 17:43:08 +0200 (EET) Received: by mail-ej1-f41.google.com with SMTP id r17so50205964ejy.13 for ; Thu, 04 Mar 2021 07:43:08 -0800 (PST) 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=50w3qM06uMvk63JA16dzbYb0KGfzaMooQ/t2xDiPj/c=; b=m6StDpGnhUZ2HopfE3r3FiixS3R5ztE7TtbMuVI5Cm6gGAIEPYL8Va6nZJJ8mQVqum EVhUHzEvVcgbkpJa90CI4Rq2ZOKcgiqCZbJrp82TSg/1O/5/1e3u25HX73syZn3nDV/s 8GWgxCDd+jW9xxLtx3CCBaE8pbu8j587+L0J2RoxKeEiSdpJwmsWJWBR/rCzJ5mo41Us KMWi4eZ33JMQLqOa8oycUuqQrJgGsBJwBu8+J8x+11sYLpnYr2N61KZ5RMkZcfWvFHbr AaeRV9BNjjIi6AZ7fk0xD4N5OBaVyqfMQtRDdfcqHpDkrwYE4pEa0I7aee+3qDY1F66d ZZEQ== 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=50w3qM06uMvk63JA16dzbYb0KGfzaMooQ/t2xDiPj/c=; b=Z+V0hKViJHLCqwDwX6uDFGAo4f7sMtS5JBL07hvxzUKsZm8vvprir2nic1ycsFIf0j UwlOdKwK2gYVXlF77Lb/3wMlak56UdcXseHeNYZ0qOYVDf6nQRXS2wgbZzjFU0cewu92 Tpg9w5SJHSVqqsgSfxw1WbjiOF0rNVyInTSgd6Tw7Yn4mJAXgUDOSlsFkg/20dCjR4p9 hNRAKjrUAxtwKrLGwxYhnmmGYBLeOivpE4FTaz54RRzsfHfrji83bJUWoLX0vZuEakGw ArBI8O7W7BcrkXb7tbaVFkWz3rrX/eo0JqLdpQmnZWzKeMTu5H1Of+MjVUhp3s+rb+Kr clFw== X-Gm-Message-State: AOAM53385JHCD/NAVU3QGzUFllgaPn7yQxNJgq2/E2MGsnbHrLm3BC4L 0Neh8rCQy9qb69kpzbi3IJ3u66JBoRI= X-Google-Smtp-Source: ABdhPJyxkjEj1Eut6OmIT9G3lanS+vwYGNH79ou5ZvsrP74+99fe84BWXyOwXQUcKRDT2/pIfW4itQ== X-Received: by 2002:a17:906:260a:: with SMTP id h10mr4992141ejc.392.1614872587464; Thu, 04 Mar 2021 07:43:07 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:07 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:30 +0100 Message-Id: <20210304154233.934640-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avcodec/decode: Avoid stack packets when decoding subtitles 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" Use AVCodecInternal.buffer_pkt (previously only used in avcodec_send_packet) instead of stack packets when decoding subtitles. Also stop sharing side-data between packets and use the user-supplied packet directly for decoding when possible (no subtitle decoder ever modifies the packet it is given). Signed-off-by: Andreas Rheinhardt --- Is it actually intentional that even in case of invalid UTF-8 got_sub_ptr is not reset and frame_number incremented? libavcodec/decode.c | 57 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index c976795311..84c4039836 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -869,19 +869,20 @@ static void get_subtitle_defaults(AVSubtitle *sub) } #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */ -static int recode_subtitle(AVCodecContext *avctx, - AVPacket *outpkt, const AVPacket *inpkt) +static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt, + const AVPacket *inpkt, AVPacket *buf_pkt) { #if CONFIG_ICONV iconv_t cd = (iconv_t)-1; int ret = 0; char *inb, *outb; size_t inl, outl; - AVPacket tmp; #endif - if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) + if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) { + *outpkt = inpkt; return 0; + } #if CONFIG_ICONV inb = inpkt->data; @@ -895,28 +896,31 @@ static int recode_subtitle(AVCodecContext *avctx, cd = iconv_open("UTF-8", avctx->sub_charenc); av_assert0(cd != (iconv_t)-1); - ret = av_new_packet(&tmp, inl * UTF8_MAX_BYTES); + ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES); + if (ret < 0) + goto end; + ret = av_packet_copy_props(buf_pkt, inpkt); if (ret < 0) goto end; - outpkt->buf = tmp.buf; - outpkt->data = tmp.data; - outpkt->size = tmp.size; - outb = outpkt->data; - outl = outpkt->size; + outb = buf_pkt->data; + outl = buf_pkt->size; if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 || iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 || - outl >= outpkt->size || inl != 0) { + outl >= buf_pkt->size || inl != 0) { ret = FFMIN(AVERROR(errno), -1); av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" " "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc); - av_packet_unref(&tmp); goto end; } - outpkt->size -= outl; - memset(outpkt->data + outpkt->size, 0, outl); + buf_pkt->size -= outl; + memset(buf_pkt->data + buf_pkt->size, 0, outl); + *outpkt = buf_pkt; + ret = 0; end: + if (ret < 0) + av_packet_unref(buf_pkt); if (cd != (iconv_t)-1) iconv_close(cd); return ret; @@ -1039,20 +1043,21 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, get_subtitle_defaults(sub); if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) { - AVPacket pkt_recoded = *avpkt; + AVCodecInternal *avci = avctx->internal; + const AVPacket *pkt; - ret = recode_subtitle(avctx, &pkt_recoded, avpkt); + ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt); if (ret < 0) return ret; - ret = extract_packet_props(avctx->internal, &pkt_recoded); - if (ret < 0) - return ret; + ret = extract_packet_props(avctx->internal, pkt); + if (ret < 0) + goto cleanup; if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); - ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded); + ret = avctx->codec->decode(avctx, sub, got_sub_ptr, (AVPacket*)pkt); av_assert1((ret >= 0) >= !!*got_sub_ptr && !!*got_sub_ptr >= !!sub->num_rects); @@ -1091,16 +1096,12 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, } } - if (avpkt->data != pkt_recoded.data) { // did we recode? - /* prevent from destroying side data from original packet */ - pkt_recoded.side_data = NULL; - pkt_recoded.side_data_elems = 0; - - av_packet_unref(&pkt_recoded); - } - if (*got_sub_ptr) avctx->frame_number++; + + cleanup: + if (pkt == avci->buffer_pkt) // did we recode? + av_packet_unref(avci->buffer_pkt); } return ret; From patchwork Thu Mar 4 15:42:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26093 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 6652A449EC7 for ; Thu, 4 Mar 2021 17:43:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A71E68ABAC; Thu, 4 Mar 2021 17:43:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D78386897E3 for ; Thu, 4 Mar 2021 17:43:08 +0200 (EET) Received: by mail-ej1-f48.google.com with SMTP id dx17so22673031ejb.2 for ; Thu, 04 Mar 2021 07:43:08 -0800 (PST) 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=RedLFedI4b3rTYy8DxfRvzFCdnEUKOEDg5A4EfQgzFQ=; b=AWQy9Lnmr1W9EmxUWi9w1DhcUlGdMj0Qy34ZaLU+7a9IR49Kfl+xQdguZWMoFrxHve HvUkG/Imq8upBkrq5i+36GakYBzdAwpDv2TXcaky081FomQTbs6IeK9I0J0vBojeJ+vM niy80o0ECA7FPbqM41rYq4HHLofM1ocTBrS5CW6if6qacJBMU6/oBszqTlt4rcUYZXFB LxlU7UUwyNcBzF0rBIdTravkMkiU7dB9wFBUDoVJvRMeH3DDKqwUBbJcB7LKeu8gZ5TC olZ4tFaQoNl4wtxVDjQnh628wHPR2UUHErtIKG0LyvHyaUJ7ZNjRz1ngF1LJ7pLoAIc8 On1Q== 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=RedLFedI4b3rTYy8DxfRvzFCdnEUKOEDg5A4EfQgzFQ=; b=VC4WhsEgRUhm8BTHCgDi5R+ys4GDmiFl9dzPxr0Ek7zRLtBivcd+gEnMk1zU/kkKuY EGrVeonP0Y+EcTgUfl790erR8S9HmeJyNdiI6Hq/sjp9cUW210oNvL/hpLkfMAf1rx9k pda2/LspszMOB38v/yylLvsKz5qigI+BnWO+wybVCOzeDjhugbaMD7+xTM0m7ZKsD2jN 2uteyJxq6/OHaMj3vjKpTROPLRX1PoM0UB/TfIpVHNR5BXD9Tt9G+zbGXR/lUNh70DDQ iVaC5GuIusxFP3s9jAlHwsnuGUW/Oy4S6hpTbSlmOj6bsolNjUmNuygx1dUI6UIZPHFD CVNQ== X-Gm-Message-State: AOAM530D7IDTPEfxVgzp9hwLTVeyqVE9nxXSr42W5TBpbtILKEpWzbbG v5hO5haAipucXq2yXwytsrMAf/yKL0I= X-Google-Smtp-Source: ABdhPJw+7vTLlrkBccvyW2Tk58edk6Be8P9C4axPick38iLol/kz+hXfTq/+3H85Tb1Ci3/qoucNlg== X-Received: by 2002:a17:906:ae96:: with SMTP id md22mr4735323ejb.409.1614872588182; Thu, 04 Mar 2021 07:43:08 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:07 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:31 +0100 Message-Id: <20210304154233.934640-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/8] avcodec/decode: Don't needlessly copy side-data for subtitles 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" AVCodecInternal.last_pkt_props is not used when decoding subtitles; ergo it makes no sense to set it at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 84c4039836..04cb050dc7 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1050,10 +1050,6 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, if (ret < 0) return ret; - ret = extract_packet_props(avctx->internal, pkt); - if (ret < 0) - goto cleanup; - if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); @@ -1099,7 +1095,6 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, if (*got_sub_ptr) avctx->frame_number++; - cleanup: if (pkt == avci->buffer_pkt) // did we recode? av_packet_unref(avci->buffer_pkt); } From patchwork Thu Mar 4 15:42:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26094 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 76735449EC7 for ; Thu, 4 Mar 2021 17:43:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5DA5468AB96; Thu, 4 Mar 2021 17:43:18 +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 D448A68AB1E for ; Thu, 4 Mar 2021 17:43:09 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id ci14so31215950ejc.7 for ; Thu, 04 Mar 2021 07:43:09 -0800 (PST) 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=/VbDG3QofzXCB98AasbKaeVlhFzEqCra/4N7gNtKDfQ=; b=p+hq0y9MKqdbT4DXUU0/gTz7u29GfTuIXSYz5SvshsgMcouRnHCTLklr9VKPJ5ZCJn e9kT8Cg4JCTDye3rYTFPyCVaRDqnkLtqH5AdUMdpYMvAOXG0NRgGfErk5lvKnC4IJ7i+ SWWFw+fG3mP7HLT62+PDQdw1nWeE5X259lRbFHLLYvOX0ffKrJi2JVvIWpoy/+EjMbgL NZlUwG2/YK2FtcyEhlfNlrtEFhelEjNjucQierzMsprNiRknWGa8qxoYupBJXYMZl81N +LyTmdPM+9cCcMjZsrTriYJxRypofqbaYah1UOBaQWM3Ap+Td+GzQVA70hJis3UkIQT0 xBcg== 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=/VbDG3QofzXCB98AasbKaeVlhFzEqCra/4N7gNtKDfQ=; b=Q42RHcrOz7LttZRAKJyd+DMiY55xz8XU0CO1B/90/7scBdcBk+NuIf/GKc4WKYTveO FcUQDDgie1gPf7cBmcfAQbJdj/44EFeO20Vj421yPXjwy3hZqOvpm7HH5oMtRxKf8ieU EGfS4HP3eW2nPXDrSbIo1u1mxB8/jxe4Tcb/Xd2h0F7axhAZTp37HsRxx9m/QhZKAZLl /WBbnuS4a7PQo0MTnBIhX4DADqz93tNfSp1wNI73Bpa9fLtLlIsCBLbRvBTeIrwIZPaB GEuYn850BNxJMxLwrI47zAo7NQUbhmSEqk4ttEgWZB+43ysfquscgRqKZrcOtG7qwfAy NLwQ== X-Gm-Message-State: AOAM533oYKk37E5wGYLHb+qFD+H3qA9O1W3obAj6ryURlR932oV9NkQY wynNYb3r0C0CCjnnLZ4S3p/rYuP29sQ= X-Google-Smtp-Source: ABdhPJy8GN8u1Spsn79aKj1odUi7/FppejGVNHGmM9zgkomhyKtLSH+R7Vm/9H5z2tle0GFf/rgUeQ== X-Received: by 2002:a17:906:16ca:: with SMTP id t10mr4930930ejd.85.1614872589070; Thu, 04 Mar 2021 07:43:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:32 +0100 Message-Id: <20210304154233.934640-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/8] avcodec/decode: Reindent after previous commits 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/decode.c | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 04cb050dc7..db0030bfd6 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1050,47 +1050,47 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, if (ret < 0) return ret; - if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE) - sub->pts = av_rescale_q(avpkt->pts, - avctx->pkt_timebase, AV_TIME_BASE_Q); + if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE) + sub->pts = av_rescale_q(avpkt->pts, + avctx->pkt_timebase, AV_TIME_BASE_Q); ret = avctx->codec->decode(avctx, sub, got_sub_ptr, (AVPacket*)pkt); - av_assert1((ret >= 0) >= !!*got_sub_ptr && - !!*got_sub_ptr >= !!sub->num_rects); + av_assert1((ret >= 0) >= !!*got_sub_ptr && + !!*got_sub_ptr >= !!sub->num_rects); #if FF_API_ASS_TIMING - if (avctx->sub_text_format == FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS - && *got_sub_ptr && sub->num_rects) { - const AVRational tb = avctx->pkt_timebase.num ? avctx->pkt_timebase - : avctx->time_base; - int err = convert_sub_to_old_ass_form(sub, avpkt, tb); - if (err < 0) - ret = err; - } + if (avctx->sub_text_format == FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS + && *got_sub_ptr && sub->num_rects) { + const AVRational tb = avctx->pkt_timebase.num ? avctx->pkt_timebase + : avctx->time_base; + int err = convert_sub_to_old_ass_form(sub, avpkt, tb); + if (err < 0) + ret = err; + } #endif - if (sub->num_rects && !sub->end_display_time && avpkt->duration && - avctx->pkt_timebase.num) { - AVRational ms = { 1, 1000 }; - sub->end_display_time = av_rescale_q(avpkt->duration, - avctx->pkt_timebase, ms); - } + if (sub->num_rects && !sub->end_display_time && avpkt->duration && + avctx->pkt_timebase.num) { + AVRational ms = { 1, 1000 }; + sub->end_display_time = av_rescale_q(avpkt->duration, + avctx->pkt_timebase, ms); + } - if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) - sub->format = 0; - else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) - sub->format = 1; - - for (i = 0; i < sub->num_rects; i++) { - if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE && - sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) { - av_log(avctx, AV_LOG_ERROR, - "Invalid UTF-8 in decoded subtitles text; " - "maybe missing -sub_charenc option\n"); - avsubtitle_free(sub); - ret = AVERROR_INVALIDDATA; - break; - } + if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) + sub->format = 0; + else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) + sub->format = 1; + + for (i = 0; i < sub->num_rects; i++) { + if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE && + sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) { + av_log(avctx, AV_LOG_ERROR, + "Invalid UTF-8 in decoded subtitles text; " + "maybe missing -sub_charenc option\n"); + avsubtitle_free(sub); + ret = AVERROR_INVALIDDATA; + break; } + } if (*got_sub_ptr) avctx->frame_number++; From patchwork Thu Mar 4 15:42:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26095 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 66AD2449EC7 for ; Thu, 4 Mar 2021 17:43:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5281768ABC8; Thu, 4 Mar 2021 17:43:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7A5868AB90 for ; Thu, 4 Mar 2021 17:43:10 +0200 (EET) Received: by mail-ed1-f46.google.com with SMTP id h10so35386975edl.6 for ; Thu, 04 Mar 2021 07:43:10 -0800 (PST) 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=QpFhXEWhKW38DTvZ2+OfP8JAKLiEeaP+DXC5cNvJLzE=; b=SfmYN2xB7Gr8s9QbgJ0e3kzjSdIM57aEEHkL5FQLVppQ37yJ3sQ2CG1sr/6J0NH7dh B+P6Z9UVjCycSEPUbZOXD+2FRN9zd1k8uEyQ0ysFZsQfGe/HmhS/tTak7yxk73XsnuHE cNIfqwyD/ufmsLxOxL+oT6Q8xA3sqBuOPmMvOrJCBadwyrsm/F1O3MraiA/TJf0vG1jt S+FNBHE1FEMS7p+1PeCbBycZ5zCZFJ87jmmOqmt6v8xDSbHbpf8Y2bGlxsQZlnczIzdW 3OMgJGmGaI+2Pindo8a3FqfSxYziyFYXZ10RmNpWPo7dsetnIWjJhP0VIGWdfS+42r7/ r7+Q== 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=QpFhXEWhKW38DTvZ2+OfP8JAKLiEeaP+DXC5cNvJLzE=; b=c3Xoy2MSZePAoNKijxkPQJYZYLlXCuW4RaiQCSgRhkYMhesdWlJJ4xv7niRmh0xyYF nLxZcSqggGkYlEovIn6V2AXN7cEJAC/cwW6S2/T9//+xXMgXvLBoe9T+K05mqFjEvFyX HBagt7GH5ORdDZe96T1iznQz75lpmxG/UA91cM2lDmXyUrs9GyoVQzW1W+6MhEU2XwTK V3EOdvOx9bkCwnTLCUShdg69ebkfmW21rM4uH10SXM1DCZNNrqb0HoiSaLb+fZ3Z6U0A OUu1QFX6cSQ/QXblJHTod+1zqKPL6axmKzvDGTdhOfgV/e4fLcVFHPEJyBuwcK67aqFQ FTzQ== X-Gm-Message-State: AOAM5327/84fVSKPC90+ENqhfLH8hIl/cDwLP59OJcVhk/WmgXqo3iMj yqQjQaTxuMN0C6ABuaGJ5Nen0Y9Lo60= X-Google-Smtp-Source: ABdhPJxLHW6gppCtnTzff6Bjc6qZu4sONGnGkB6jdCDqrxRnrYxZ/3cvNCv0k/CgmX5OIEsjAa1iKw== X-Received: by 2002:a05:6402:3083:: with SMTP id de3mr5000140edb.241.1614872590008; Thu, 04 Mar 2021 07:43:10 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y24sm22673391eds.23.2021.03.04.07.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:43:09 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Mar 2021 16:42:33 +0100 Message-Id: <20210304154233.934640-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> References: <20210304154233.934640-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] avcodec/qsvdec: Make functions used only here static, remove header 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" Forgotten after d78ecf10bd745cb69a71b32419e0661bfdcfb1fd. (Also mark some AVPackets as const.) Signed-off-by: Andreas Rheinhardt --- libavcodec/Makefile | 1 - libavcodec/qsvdec.c | 83 +++++++++++++++++++++++++++++++------------ libavcodec/qsvdec.h | 86 --------------------------------------------- 3 files changed, 60 insertions(+), 110 deletions(-) delete mode 100644 libavcodec/qsvdec.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b7e456b59f..3607001639 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1204,7 +1204,6 @@ SKIPHEADERS-$(CONFIG_MEDIAFOUNDATION) += mf_utils.h SKIPHEADERS-$(CONFIG_NVDEC) += nvdec.h SKIPHEADERS-$(CONFIG_NVENC) += nvenc.h SKIPHEADERS-$(CONFIG_QSV) += qsv.h qsv_internal.h -SKIPHEADERS-$(CONFIG_QSVDEC) += qsvdec.h SKIPHEADERS-$(CONFIG_QSVENC) += qsvenc.h SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_decode.h vaapi_hevc.h vaapi_encode.h diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index d10f90a0db..5f2e641373 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -21,18 +21,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include #include "libavutil/common.h" +#include "libavutil/fifo.h" +#include "libavutil/frame.h" #include "libavutil/hwcontext.h" #include "libavutil/hwcontext_qsv.h" #include "libavutil/mem.h" #include "libavutil/log.h" #include "libavutil/opt.h" -#include "libavutil/pixdesc.h" #include "libavutil/pixfmt.h" #include "libavutil/time.h" #include "libavutil/imgutils.h" @@ -40,11 +42,49 @@ #include "avcodec.h" #include "internal.h" #include "decode.h" +#include "hwconfig.h" #include "qsv.h" #include "qsv_internal.h" -#include "qsvdec.h" -const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = { +typedef struct QSVContext { + // the session used for decoding + mfxSession session; + + // the session we allocated internally, in case the caller did not provide + // one + QSVSession internal_qs; + + QSVFramesContext frames_ctx; + + /** + * a linked list of frames currently being used by QSV + */ + QSVFrame *work_frames; + + AVFifoBuffer *async_fifo; + int zero_consume_run; + int buffered_count; + int reinit_flag; + + enum AVPixelFormat orig_pix_fmt; + uint32_t fourcc; + mfxFrameInfo frame_info; + AVBufferPool *pool; + + int initialized; + + // options set by the caller + int async_depth; + int iopattern; + int gpu_copy; + + char *load_plugins; + + mfxExtBuffer **ext_buffers; + int nb_ext_buffers; +} QSVContext; + +static const AVCodecHWConfigInternal *const qsv_hw_configs[] = { &(const AVCodecHWConfigInternal) { .public = { .pix_fmt = AV_PIX_FMT_QSV, @@ -57,7 +97,8 @@ const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = { NULL }; -static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool) +static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, + AVBufferPool *pool) { int ret = 0; @@ -255,7 +296,9 @@ static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide return 0; } -static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param) +static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, + const AVPacket *avpkt, enum AVPixelFormat pix_fmt, + mfxVideoParam *param) { int ret; @@ -299,7 +342,7 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame) int ret; if (q->pool) - ret = ff_qsv_get_continuous_buffer(avctx, frame->frame, q->pool); + ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool); else ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF); @@ -400,7 +443,7 @@ static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf) static int qsv_decode(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, - AVPacket *avpkt) + const AVPacket *avpkt) { QSVFrame *out_frame; mfxFrameSurface1 *insurf; @@ -531,7 +574,7 @@ FF_ENABLE_DEPRECATION_WARNINGS return bs.DataOffset; } -int ff_qsv_decode_close(QSVContext *q) +static void qsv_decode_close_qsvcontext(QSVContext *q) { QSVFrame *cur = q->work_frames; @@ -563,12 +606,10 @@ int ff_qsv_decode_close(QSVContext *q) av_buffer_unref(&q->frames_ctx.hw_frames_ctx); av_buffer_unref(&q->frames_ctx.mids_buf); av_buffer_pool_uninit(&q->pool); - - return 0; } -int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, - AVFrame *frame, int *got_frame, AVPacket *pkt) +static int qsv_process_data(AVCodecContext *avctx, QSVContext *q, + AVFrame *frame, int *got_frame, const AVPacket *pkt) { int ret; mfxVideoParam param = { 0 }; @@ -629,12 +670,6 @@ reinit_fail: return ret; } -void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q) -{ - q->orig_pix_fmt = AV_PIX_FMT_NONE; - q->initialized = 0; -} - enum LoadPlugin { LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_SW, @@ -669,7 +704,7 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx) av_freep(&s->qsv.load_plugins); - ff_qsv_decode_close(&s->qsv); + qsv_decode_close_qsvcontext(&s->qsv); qsv_clear_buffers(s); @@ -754,7 +789,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data, if (s->buffer_pkt.size <= 0) { /* no more data */ if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket)) - return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt); + return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt); /* in progress of reinit, no read from fifo and keep the buffer_pkt */ if (!s->qsv.reinit_flag) { av_packet_unref(&s->buffer_pkt); @@ -762,7 +797,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data, } } - ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt); + ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt); if (ret < 0){ /* Drop buffer_pkt when failed to decode the packet. Otherwise, the decoder will keep decoding the failure packet. */ @@ -784,7 +819,9 @@ static void qsv_decode_flush(AVCodecContext *avctx) QSVDecContext *s = avctx->priv_data; qsv_clear_buffers(s); - ff_qsv_decode_flush(avctx, &s->qsv); + + s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE; + s->qsv.initialized = 0; } #define OFFSET(x) offsetof(QSVDecContext, x) @@ -814,7 +851,7 @@ AVCodec ff_##x##_qsv_decoder = { \ AV_PIX_FMT_P010, \ AV_PIX_FMT_QSV, \ AV_PIX_FMT_NONE }, \ - .hw_configs = ff_qsv_hw_configs, \ + .hw_configs = qsv_hw_configs, \ .wrapper_name = "qsv", \ }; \ diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h deleted file mode 100644 index f3b7344cba..0000000000 --- a/libavcodec/qsvdec.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Intel MediaSDK QSV utility functions - * - * copyright (c) 2013 Luca Barbato - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_QSVDEC_H -#define AVCODEC_QSVDEC_H - -#include -#include - -#include - -#include "libavutil/fifo.h" -#include "libavutil/frame.h" -#include "libavutil/pixfmt.h" - -#include "avcodec.h" -#include "hwconfig.h" -#include "qsv_internal.h" - -typedef struct QSVContext { - // the session used for decoding - mfxSession session; - - // the session we allocated internally, in case the caller did not provide - // one - QSVSession internal_qs; - - QSVFramesContext frames_ctx; - - /** - * a linked list of frames currently being used by QSV - */ - QSVFrame *work_frames; - - AVFifoBuffer *async_fifo; - int zero_consume_run; - int buffered_count; - int reinit_flag; - - enum AVPixelFormat orig_pix_fmt; - uint32_t fourcc; - mfxFrameInfo frame_info; - AVBufferPool *pool; - - int initialized; - - // options set by the caller - int async_depth; - int iopattern; - int gpu_copy; - - char *load_plugins; - - mfxExtBuffer **ext_buffers; - int nb_ext_buffers; -} QSVContext; - -extern const AVCodecHWConfigInternal *const ff_qsv_hw_configs[]; - -int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, - AVFrame *frame, int *got_frame, AVPacket *pkt); - -void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q); - -int ff_qsv_decode_close(QSVContext *q); - -#endif /* AVCODEC_QSVDEC_H */