From patchwork Mon Oct 11 15:36:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31058 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp3821658ioa; Mon, 11 Oct 2021 08:37:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxmpMO5DTTGg7dRrW7Ck9B6Fccf+H8ZqmcvyV0CdtfVBjJAUvXUEjofZzAC7iy3Jpaf+S1 X-Received: by 2002:a50:9347:: with SMTP id n7mr41110336eda.249.1633966649994; Mon, 11 Oct 2021 08:37:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l7si2052586ejn.77.2021.10.11.08.37.29; Mon, 11 Oct 2021 08:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=kjM2RJ8e; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AC792687F4A; Mon, 11 Oct 2021 18:37:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2051.outbound.protection.outlook.com [40.92.90.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 292D2687F4A for ; Mon, 11 Oct 2021 18:37:04 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f/va+RptOZVl8m/S60wCwbiIu2T7u0cTc9bI0LLuAt9/pX13fsKRUGxoE4ffKLEU3sYMfJQongd70IetJaK1Rg9RTMojrP1qrTqwc4NdidpFtv7tqsz+8f2luN+v2f811KMQuSJWFCG03IEtFfJcIo+iVeYYfJNeb7g4qynm7hYhVarjc9YMxaWyik+DmX+zyGFhSNPbHwXi/osFXd89KNGxKP50AVVU4ACGjQikg7nngV779hl3di/bkPq71jxbHT2VauYVpzhnAFa4FL8EdktMEhmL5NdU8hpdKhfcXOOlPHpuW2O8sWw8/vXeMEBTcfMvsfRELjoaTjcq1eAs1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ySyjwGLPdOP/ETQGOaP290qb8uKx3XREmBs4EGzJnJA=; b=YlsLWDNPfyfHwd/DKq/59bG+cDGVmh4AfGA/qQ+C2BwsuGay0GcvkbSBN4VIFPCKKyFi6pGFurwALnLaEtBSDL26306rrw3q3AAvqeCXDDmKV9RUICEh2f3gW2OvHoVq0u96HFW1I/WomP7eIcK9q88t7qUDkVjlLTXHMLD0bU/OTWXhnCSw4WBPJjYG2q0O7lgCUjL6QbIWF7bUWo+ew3eDUazd63OYpMdZajfomCfuHORmI2fExJPnjD9zKWvzpGHFUcsGVuDPsfDo84dZX+mddpqr3DGTlEWK4jo+6ArqsFbKwyqrf7xv2doVh0rgNzBZ/otfiypIqHkZkgssRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ySyjwGLPdOP/ETQGOaP290qb8uKx3XREmBs4EGzJnJA=; b=kjM2RJ8eBZoOBsr2f+71ybEnR/4D15YEYeCMomelae0JL7o3Vd+fpVgqlzd4YDu9SIx0eJRtS8qAPQP2LZsFdNhhsstMSxSOmxyegbzLE8E1HpIaJv9BDTxGhTnRph8qkCSA0FD8WERMNA03fuLPrl4MqzZKJeE5mvAlZKebX5KTeEubTFUhb0VK4lCOQj/oSZ2t8pImuoMULmc5cigOGIFtRzx9QsnAx7JV7XL/+7m5lDyldoK6xH6bth5KV+OzWi+5hA9mbX5UF/OjZq0B2KYg8uKUaX9LqQWjhRa9UaSA6hQVw22185OOlyIhImTfHWp4jMZHQ+0DGqBSKzTWpQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM5PR03MB2932.eurprd03.prod.outlook.com (2603:10a6:206:24::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Mon, 11 Oct 2021 15:36:58 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%9]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 15:36:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Oct 2021 17:36:42 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [f+Sio6Dl4m+1+qJab2VPYaDapni3Jblb] X-ClientProxiedBy: AM5PR0601CA0070.eurprd06.prod.outlook.com (2603:10a6:206::35) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211011153649.1961025-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.193.170.49) by AM5PR0601CA0070.eurprd06.prod.outlook.com (2603:10a6:206::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Mon, 11 Oct 2021 15:36:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e4111dfd-d18e-41aa-ceb2-08d98cccf653 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiS6+TXmMYPOjHmO66YJyNLlhhlG4ZCOycODT0BkXsYaclVuxvZLfpSncpFBvBhYaRIYuqRKJg6pAVw8HBkqVPG1ThY4SDJBAE3BktxR42VQDu0ELyfBn11t8kO6hyvWgjxIXvyKu4NV3TNf/VWntjS+Y9lwDbVTbLMv3DzSaL3kxps5+zllqSqdIPjOXN+BQsFUq3pquaOicHxpVEtVhEtpKksDMfKb1RL33tZyH1OpfWU9PKLjcre8H5+zV3pB4zN+0KWrjEN/sCXRR0JiRaB4XJpq3UVkc5BONrUpgiwmC/6ZOQ0tYaBIPyydD3fYF6OO89ff799H4ueYHtQg+p9obqOpe0DhqRey6QjK+rpiIuRagXng4Z19RBGHvpSjeUL+KJ2CRrDOaJwKSq+RGgfiNlDUaUm2nkMpXsN493XLCu9yS/00hobUlnBkCCl2vTtJ/uuxiLzzILstuRzQrZlsa2U4aDXsl9HiYQX5KCvqg9yd5I/IshoI2NiGY9pvcYr+i1Potpw6ulQYTL2wJCyuu0ChBCcbk+IouPE69R3k2+nrlVLTDlL63GKPzyBTvPaw+GVtJlCQ3ywS9AUzKYrOA8x1Dhk8WBQZ7PZ7t1QeBLXWqNbjCSD8YGUt0LVn7CvldhJFZkIuV+LV6uRWe6aKbovuY88DjrFgz8GxZgdAjP4C6BYIkWzdJ3FY6CJhh7PXOqjALlKY0JKioArllVWDrHDhvBhoS63TzPE+RADJsemz5qWSXz/1TN3/Lj3zfBI= X-MS-TrafficTypeDiagnostic: AM5PR03MB2932: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uco+/ZWKBYYNjGe4QT9DDahux9SggdjFo1TJFTMr1ehEModkNRPuF+yzF/vvByc86GsnuXN83KVxaeyTkGC7ilRJcoq70JgqWKNNx8H1A6o30mfZDF1VEM1ozijvPs5yn0eqspevrU082BVZTHTi6E95HY+207Z0LD3+iNRT1EED/S2mUjLnmBGtz07mxoj3b2Bay8/dUHLtmyqcTtjnH2YscCgveO6y8aGLJCMMt9/fRNygJwX7Q9w/SMXtCYrDKSbNbfyIKIk4DFJh9SrFa4X7RF07VRff7SHHjW5wwPq86NcSVv4OUpCS+NmS0OgAWtIngTRHbsECXqkppirPjT1CufpsTrJ3jfNe0uaeoBb4iUWNb8xuXd4yfexc/CdTVErhu1jT8Vyz2032b+fq8bP/yrVWJ+xlH1QJ+QHd4+etVqg6b7HcOPhlJ6cgNjNb X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VqQzoj70jsakeL/vxA8QFqzTjbKNMZxpYvgwV/WNVof8hEuoILKy9jG8R4p9miNKmeaDHgT7tsxeuMV/KC8/fdsQJQ2C6aWecGGcF4XGurOu8sd3rEy/34KprKOMVQ+CKgPXMLzMFVEWBM5bTlWVlg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4111dfd-d18e-41aa-ceb2-08d98cccf653 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2021 15:36:58.5531 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB2932 Subject: [FFmpeg-devel] [PATCH 03/10] avcodec/internal: Allow receive_frame codecs to use decode_simple pkt X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: DhzzkdjnH8JX Decoders implementing the receive_frame API currently mostly use stack packets to temporarily hold the packet they receive from ff_decode_get_packet(). This role directly parallels the role of in_pkt, the spare packet used in decode_simple_internal for the decoders implementing the traditional decoding API. Said packet is unused by the generic code for the decoders implementing the receive_frame API, so allow them to use it to fulfill the function it already fulfills for the traditional API for both APIs. There is only one caveat in this: The packet is automatically unreferenced in avcodec_flush_buffers(). But this is actually positive as it means the decoders don't have to do this themselves (in case the packet is preserved between receive_frame calls). Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.c | 8 ++++---- libavcodec/decode.c | 3 +-- libavcodec/internal.h | 14 +++++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index ff3d73e237..c00a9b2af8 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -181,11 +181,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_alloc(); avci->es.in_frame = av_frame_alloc(); - avci->ds.in_pkt = av_packet_alloc(); + avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props)); if (!avci->buffer_frame || !avci->buffer_pkt || - !avci->es.in_frame || !avci->ds.in_pkt || + !avci->es.in_frame || !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; @@ -408,7 +408,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_fifo_reset(avci->pkt_props); av_frame_unref(avci->es.in_frame); - av_packet_unref(avci->ds.in_pkt); + av_packet_unref(avci->in_pkt); if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) ff_thread_flush(avctx); @@ -473,7 +473,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) } av_packet_free(&avci->last_pkt_props); - av_packet_free(&avci->ds.in_pkt); + av_packet_free(&avci->in_pkt); av_frame_free(&avci->es.in_frame); av_buffer_unref(&avci->pool); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 294c040716..c44724d150 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -296,8 +296,7 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { AVCodecInternal *avci = avctx->internal; - DecodeSimpleContext *ds = &avci->ds; - AVPacket *pkt = ds->in_pkt; + AVPacket *const pkt = avci->in_pkt; int got_frame, actual_got_frame; int ret; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index b6180f15a5..a62f8dbd4e 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -112,10 +112,6 @@ # define STRIDE_ALIGN 8 #endif -typedef struct DecodeSimpleContext { - AVPacket *in_pkt; -} DecodeSimpleContext; - typedef struct EncodeSimpleContext { AVFrame *in_frame; } EncodeSimpleContext; @@ -137,7 +133,15 @@ typedef struct AVCodecInternal { void *thread_ctx; - DecodeSimpleContext ds; + /** + * This packet is used to hold the packet given to decoders + * implementing the .decode API; it is unused by the generic + * code for decoders implementing the .receive_frame API and + * may be freely used (but not freed) by them with the caveat + * that the packet will be unreferenced generically in + * avcodec_flush_buffers(). + */ + AVPacket *in_pkt; AVBSFContext *bsf; /**