From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F1AED47264 for ; Mon, 2 Oct 2023 18:13:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2841B68CCB9; Mon, 2 Oct 2023 21:12:55 +0300 (EEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D2F468CC34 for ; Mon, 2 Oct 2023 21:12:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6RI8QRHZ/OmOMvJWpLRUKOWvW9pN8nX9EoI03ciYzh6DMfobou2WLE8iFcHJXTplPAASPl/bqU801F/uQ7htbVspXaZwpqzBo7GI3zoyIVgphsrARn5GTM2O4h+t+eGdy4NAoYLS+EEX/4rLe7+4nojOxuHabQLVgWOetsCV1NulmG1sIzUwT1Oix28ePwF6E3IKNHnrV9trrURWFeXtMhupSDvCxyWK5Y+gnhQ47RhZvZ1Xsu5ZKi3eW98lHPVqLuoVvojPoDVzOZm/UxXIBP0IJDA4EGUFKRfinfPApq2SuxqPMFt1DUcjksCvNOONoZH9bG6LORTcn1a7ekX/w== 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=RLgkNl9SMKz/78x+4gs3unWIF4ICXCa/TUPMYVRJnHA=; b=caErYu0Dwi9L3T4XlNdlALVeYl55tCBlGQvO+3Q/XLo7aApY/MzjlxMVllSCtsXZ6rf6HDj1CcJiMIoslPIetwXStf8L8QjUgiIZOiOXz9cf/BGUwkV9Y0077mkifrWYCt2+I3tJZWFwGkpPxED0mY1F4I28HIfmbKHKVTMzXnMArz8E3IFJJvmHYnhv4t3NT8DOFlLngnHAcnhT10bhl4Bww++v1ZZqi3idCYN7bX7LE3DGaF82eEzMVCgxAOK8auvqYoEp3HyK3GdraauPFrGV2XLDmrJpu/5z60/A4vNMwWJ9/d3MPUHbNKGA4lwmjt1syRp5W+JsmNx0BTy9mQ== 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=RLgkNl9SMKz/78x+4gs3unWIF4ICXCa/TUPMYVRJnHA=; b=lSaOc41LfKKe/im2y82IPFyPR/gqlKdn+jhqkqMGCmWVwTvlARgk33v27GV0vPRt7MMJsAtK1HnrMnWIOCoF9huw4WByPoHdCTse7IAUXsaz/Kd099mx1D3ForVBE/aGrQi/vKh9GV5TM/vgF39e4IbkEnvvvAykvMiwwSezWgCrP2bYGneNBfOTBVLpFhQFLUF4s0uTA+0QtEuE3PxlzV5b4QxgLyPZBkL3ITV8QvQc+0kTErGTM3uLQxtXJvp9268ceOP8uGjx1a/WYqwrb4rA92etx1DXezN78IsEn1bZCjsrJTkX2IuYsA4CVgcftymyxNze3YuswT0hKcAYlw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:45 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:35 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [ZBAXo1rT9xX7Ljd7n/4liplEunT1dsSX] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d55ca4b-7963-4658-1106-08dbc3732d28 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zmCobcP2lB+i6y670tPMKnt9cGPO/q7j2IaukJugcxrEtCdMLH91dewBARlGWgj2oBgxw7DAd9x1sy1lUJ/fdIt2DjEdFRba6Uqarw4L88vGtHzo78NhNVPI3Jqw8j2qheXOND3u3rKqp+/Sby23HlUfQDaOrXnrhDRSs74TKcA5OSa2077x40K6Dv6xylb6PP4QZTRRae3q4wHGknzTt+91xvvt9r35QHsdHyru26gwUZmcWLlb+vStWmXACSTk9CYbfN3UzrJsXC2+Ki2I4ChR8RoZtFDj6Lsq7wghQiyb8pJS5KJp7NXiD5nAwmokwgxX51Yan46cni6hDzx3hCxvla5d4IyRkTTO6vzIxvVshXvlclEibx+50AU49DOl21zw4FUmPVyqAcYaBekHyR91qg9h58QqngKCBuFhKI450bDOuPQ71WjCoTj14l4RpO/QDhhahJScY/GodnQe8YdF5TBbBn0KZX8Cbkr7D/JwA316hD1JZFUEQLgC2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/2F?= =?us-ascii?Q?B9SxuIFg1Csw+92muheyRVxUPLPUCnXq1wsAIBJqP8AaDXbkIxhFZaqrSvrD?= =?us-ascii?Q?s1a1YUHPen2KQov8vIv3vF4Sx+veOo/9Yh1OsbzyfuT+GtVwcAtX7voPPuUp?= =?us-ascii?Q?CpGFDjPubCZcLSgEQpynlJYk+A1wZM5SoEV4NiFupaOgYwgbwUld4hovsRXV?= =?us-ascii?Q?0Jlmjdi4itC8oR5f25/tiBJioZc8bPRNODR0Ja5DT0ep5D2LEVNGsN8gjMLm?= =?us-ascii?Q?tZoyWinyLAemN3ic/zor9yfl78PUeT1dAWWy2LgtHhikXb07UmaXM+hIon9d?= =?us-ascii?Q?M32vHHr4uDUroYsNJGbDSNNP00cleA2m2M1QgPiC99mQ3I5CGQMtH6hU01DI?= =?us-ascii?Q?v8KZg3HEsxeITAJC6w234FjMgS0DyraAJMsVxfVIkOzfivOlgsWh8dMyzdrH?= =?us-ascii?Q?HrN3DOgJMeVc56CdskWK1j2aLB24F7HtDqJMjBp8nz8f2KAQ6IPtElrNiIdm?= =?us-ascii?Q?sqGio/FfW4cxCLgfSjaAqaewVy7nh435c/GJ/hcARb5qzUOUKohMrHgq0DSI?= =?us-ascii?Q?V2oqCp/IQ2LUB/TM7JsY?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d55ca4b-7963-4658-1106-08dbc3732d28 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:45.2647 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 46/49] avcodec/rkmppdec: Use RefStruct API for references to decoder itself 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Avoids boilerplate code when creating the context and avoids allocations and therefore whole error paths when creating references to it. Also avoids an indirection and improves type-safety. Signed-off-by: Andreas Rheinhardt --- libavcodec/rkmppdec.c | 46 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index 4cca65d8fb..dd0b9c5a4d 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -30,6 +30,7 @@ #include "codec_internal.h" #include "decode.h" #include "hwconfig.h" +#include "refstruct.h" #include "libavutil/buffer.h" #include "libavutil/common.h" #include "libavutil/frame.h" @@ -56,12 +57,12 @@ typedef struct { typedef struct { AVClass *av_class; - AVBufferRef *decoder_ref; + RKMPPDecoder *decoder; ///< RefStruct reference } RKMPPDecodeContext; typedef struct { MppFrame frame; - AVBufferRef *decoder_ref; + const RKMPPDecoder *decoder_ref; ///< RefStruct reference } RKMPPFrameContext; static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx) @@ -89,7 +90,7 @@ static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat) static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret; MppPacket packet; @@ -124,13 +125,13 @@ static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, in static int rkmpp_close_decoder(AVCodecContext *avctx) { RKMPPDecodeContext *rk_context = avctx->priv_data; - av_buffer_unref(&rk_context->decoder_ref); + ff_refstruct_unref(&rk_context->decoder); return 0; } -static void rkmpp_release_decoder(void *opaque, uint8_t *data) +static void rkmpp_release_decoder(FFRefStructOpaque unused, void *obj) { - RKMPPDecoder *decoder = (RKMPPDecoder *)data; + RKMPPDecoder *decoder = obj; if (decoder->mpi) { decoder->mpi->reset(decoder->ctx); @@ -145,8 +146,6 @@ static void rkmpp_release_decoder(void *opaque, uint8_t *data) av_buffer_unref(&decoder->frames_ref); av_buffer_unref(&decoder->device_ref); - - av_free(decoder); } static int rkmpp_init_decoder(AVCodecContext *avctx) @@ -161,19 +160,13 @@ static int rkmpp_init_decoder(AVCodecContext *avctx) avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME; // create a decoder and a ref to it - decoder = av_mallocz(sizeof(RKMPPDecoder)); + decoder = ff_refstruct_alloc_ext(sizeof(*decoder), 0, + NULL, rkmpp_release_decoder); if (!decoder) { ret = AVERROR(ENOMEM); goto fail; } - - rk_context->decoder_ref = av_buffer_create((uint8_t *)decoder, sizeof(*decoder), rkmpp_release_decoder, - NULL, AV_BUFFER_FLAG_READONLY); - if (!rk_context->decoder_ref) { - av_free(decoder); - ret = AVERROR(ENOMEM); - goto fail; - } + rk_context->decoder = decoder; av_log(avctx, AV_LOG_DEBUG, "Initializing RKMPP decoder.\n"); @@ -269,7 +262,7 @@ fail: static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret; // handle EOF @@ -311,7 +304,7 @@ static void rkmpp_release_frame(void *opaque, uint8_t *data) RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data; mpp_frame_deinit(&framecontext->frame); - av_buffer_unref(&framecontext->decoder_ref); + ff_refstruct_unref(&framecontext->decoder_ref); av_buffer_unref(&framecontextref); av_free(desc); @@ -320,7 +313,7 @@ static void rkmpp_release_frame(void *opaque, uint8_t *data) static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; RKMPPFrameContext *framecontext = NULL; AVBufferRef *framecontextref = NULL; int ret; @@ -448,11 +441,6 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) // MPP decoder needs to be closed only when all frames have been released. framecontext = (RKMPPFrameContext *)framecontextref->data; - framecontext->decoder_ref = av_buffer_ref(rk_context->decoder_ref); - if (!framecontext->decoder_ref) { - ret = AVERROR(ENOMEM); - goto fail; - } framecontext->frame = mppframe; frame->data[0] = (uint8_t *)desc; @@ -463,6 +451,7 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) ret = AVERROR(ENOMEM); goto fail; } + framecontext->decoder_ref = ff_refstruct_ref(rk_context->decoder); frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref); if (!frame->hw_frames_ctx) { @@ -487,9 +476,6 @@ fail: if (mppframe) mpp_frame_deinit(&mppframe); - if (framecontext) - av_buffer_unref(&framecontext->decoder_ref); - if (framecontextref) av_buffer_unref(&framecontextref); @@ -502,7 +488,7 @@ fail: static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret = MPP_NOK; AVPacket pkt = {0}; RK_S32 usedslots, freeslots; @@ -542,7 +528,7 @@ static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame) static void rkmpp_flush(AVCodecContext *avctx) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret = MPP_NOK; av_log(avctx, AV_LOG_DEBUG, "Flush.\n"); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".