From patchwork Mon Apr 8 20:14:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47960 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3f98:b0:1a7:a0dc:8de5 with SMTP id ay24csp137169pzb; Mon, 8 Apr 2024 13:18:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUJS5l7gWTZg6XViZ/iZZFMaRrqlnijG8gaiFMYIHrLmw6UJo4KB1O1woFzVC1d36Z7NGeqdMhq4JprsCjUuLj9bzyUdANR9vPFog== X-Google-Smtp-Source: AGHT+IHhwtwl9kz5IlQia/ndlFfcZvnELa29WYgCu7sRCHGfwcM30T+rB1pQ3OrrkobJylsvb28L X-Received: by 2002:a17:907:9483:b0:a51:ce40:39e3 with SMTP id dm3-20020a170907948300b00a51ce4039e3mr3495961ejc.0.1712607481854; Mon, 08 Apr 2024 13:18:01 -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 gn39-20020a1709070d2700b00a51c9872c6asi2121495ejc.63.2024.04.08.13.18.01; Mon, 08 Apr 2024 13:18:01 -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=PoVrPHxl; 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 6196D68D469; Mon, 8 Apr 2024 23:16:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2092.outbound.protection.outlook.com [40.92.89.92]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BFBB168D448 for ; Mon, 8 Apr 2024 23:16:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J9sY7nx62D5G365TN974vfb9X/Lj9OSF897Yg2WDG0zkgWZjpvg5SE4UeBL8R73WRbnbASVBvD5bpSmKR43/FCobWtd1bGaPxZInqZ8cRVeLi3BzJksfDZECZqKzxA6hXA2f/EIguvI2aSP2YX2n5CGyfoUZk5uOP816bRGG50B4yCjMCeo+yvzpFzHFs+ZtdxQQL47VmhLi/JIuStiXvSDO8LCQyir3X1yKhOcI/QB8QBlo977WCIMuU0TfWh0GFfS22ZTFCi1TduzdxnG6oqgZRXKVBVg5O5XHFBP+LPr0rMuwv956t7fk6cNPUwGMNl6GH02rL3oia8eMK+5T6Q== 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=TkagonTbqZQVcS5Omu2gONxkh/mJj6hIocQbsBum90s=; b=AoqtJvmpcR/i8uVhrQgd5EPUIoLkiqOr+6C6uNjLNMvXD6Mi/hySwKh2yf5zONF/kixcOUJ0rkOkYvYQZITlTGzuIACevDafiyi3x/Zc15g+Eggd4P0lJhnrAvMc7RFdn/oCnhAG5+GxVgIySq7N2jaU3L6v/ziOs2epapff9obdXDnVMGf9LyOwc+uFK4WbcRk5WiWyGfxa5I32Iw5fNVWqhKGHUKtpGFNmR6AO9GaOoPlBxd32sySmmir0vSTcQKw4MgAK5RHK6x4haHwyzjzXPbWhUOQXmN/DKBUHmiLdarBjeZh5k/gNVVXoj+zRXO1ay6T0gnI51D9PJeurqw== 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=TkagonTbqZQVcS5Omu2gONxkh/mJj6hIocQbsBum90s=; b=PoVrPHxlTiwkOgQx/qNhWgqrg3jJRAxwx//ROLHG2L85RcwFnr9Kc7AWddwjNhePAoNdiaugLVO0mwUHH6/wbvnkIDT/125OrLSejZ0apKA6JGv8TifEUps1lwMerb9goM48z3xt/hmV5gwb/qjhp0fJtWtKQ85B8t7rdqxyR6+HTXOx00AbCRurSWZhlADzlK/JRjpIvHkJd7F1XrGSqAoFyAvqsE2FeHzhrVzYST2+0duigBiLX0DrTWCVfPgb/1VvGBKWx86bDu5RUfdAHWKMxRaplXZAPNXijot3fWarVKp7noW1w/ESV8I8P3600QntpTytO74uEBBCZb4Qyg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AM8P250MB0171.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:322::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Mon, 8 Apr 2024 20:16:16 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.042; Mon, 8 Apr 2024 20:16:16 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Apr 2024 22:14:04 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [4StgTiKMC/Skcgn65FD+H5q+GFRbko5Hm/8Mjym04tM=] X-ClientProxiedBy: ZR0P278CA0124.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:20::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240408201405.2136840-25-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AM8P250MB0171:EE_ X-MS-Office365-Filtering-Correlation-Id: 98d8be66-ccdf-4a97-1708-08dc5808bee5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZA4KtGKhuy8fx9xS+qYrmar/a2ejLOKx42K73bQcv5CItVT+cm5KZRY3TKvpKLa4cfUmcauzl7siLRyluxjRtaKqae1RlGYy5vIHY1oyiEHTduxyPwi/f2SkTMqvE6rMQT3+rtPTyOAjs2Y17H9L0IzH9GO6K//yHvXUEJy+b8VzUNMDvgoqXOfyuPv0Ngr4WMXsdaVLc42a1pzY55ndr1eZ2KLGNPADVGfC3DaKVFWfHd3awl+9BG3xKcvEHtefLy6gkvWKgYNNcwZrUhgkaPg8QMWIPo+Ur2Ua3OtFe+GlwlSByWsZQCM7XXH7uzZcfTzl+MLcKMLNTErQtep4q3KfhA3/cTE9f5AzjQoFPsE7VvIsTruZ3V4IHxuEwpVFfymtqNLDYjY864M8e0uKB6fXWxSu/03Q/O37F2YpAUzo2bADV5gG6AyiTDAwPcd1CH9D+dTjqZGmyNj22Z60v4YzSPJ1x2vWLymSFpWIF1ASaPbaqXKeZyh8zE0xJSG8qAG5U9e3H5xNzrFtxRUWpBq9BU6vTtGZCI+x7KtH4sjYjh6mGGcs00JPtFSFz/LVS6w6jSAlth55c4LR8KIOQ9RygYcnfAH6fvthe29J2qmsPdP0ScCOF77oMbIX7dJV X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X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zTaQIskLr2jDwJEY/Cc8OdyHS25V7Q9xNOrEyM6hpXCEZDUb32w96uTi18KWaPA6MR1qa4u7aP6hD41fUse/z4KW//bF2NEIqv8IWDLqTyCPWmtnyBOZrpHpSUuAktgGez4oWGbCIcj102fMSkZBSgWbYwUQ5Q3gwGmxWEakihFVvsBCRw/jlgLf+DPi4mjkidDSoTnLi8WpFQ01v8kENDLYJTO4lrW1El8PGngkrgVp+snbD4mVWY0BnQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98d8be66-ccdf-4a97-1708-08dc5808bee5 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2024 20:16:16.7226 (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: AM8P250MB0171 Subject: [FFmpeg-devel] [PATCH v2 26/27] avcodec/rkmppdec: Allocate AVDRMFrameDescriptor and frame ctx jointly 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: m7TTBVfNUjrL Avoids an allocation and therefore one error path. Signed-off-by: Andreas Rheinhardt --- libavcodec/rkmppdec.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index e137e7e820..47b076dbd8 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -301,12 +301,10 @@ static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) static void rkmpp_release_frame(void *opaque, uint8_t *data) { AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)data; - AVBufferRef *framecontextref = (AVBufferRef *)opaque; - RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data; + RKMPPFrameContext *framecontext = opaque; mpp_frame_deinit(&framecontext->frame); ff_refstruct_unref(&framecontext->decoder_ref); - av_buffer_unref(&framecontextref); av_free(desc); } @@ -315,12 +313,9 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; RKMPPDecoder *decoder = rk_context->decoder; - RKMPPFrameContext *framecontext = NULL; - AVBufferRef *framecontextref = NULL; int ret; MppFrame mppframe = NULL; MppBuffer buffer = NULL; - AVDRMFrameDescriptor *desc = NULL; AVDRMLayerDescriptor *layer = NULL; int mode; MppFrameFormat mppformat; @@ -409,11 +404,21 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) // now setup the frame buffer info buffer = mpp_frame_get_buffer(mppframe); if (buffer) { - desc = av_mallocz(sizeof(AVDRMFrameDescriptor)); - if (!desc) { + RKMPPFrameContext *framecontext; + AVDRMFrameDescriptor *desc; + // We allocate the descriptor in buf[0] jointly with a structure + // that will allow to hold additional information + // for properly releasing MPP frames and decoder. + struct { + AVDRMFrameDescriptor desc; + RKMPPFrameContext framecontext; + } *combined_desc = av_mallocz(sizeof(*combined_desc)); + if (!combined_desc) { ret = AVERROR(ENOMEM); goto fail; } + desc = &combined_desc->desc; + framecontext = &combined_desc->framecontext; desc->nb_objects = 1; desc->objects[0].fd = mpp_buffer_get_fd(buffer); @@ -432,23 +437,15 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) layer->planes[1].offset = layer->planes[0].pitch * mpp_frame_get_ver_stride(mppframe); layer->planes[1].pitch = layer->planes[0].pitch; - // we also allocate a struct in buf[0] that will allow to hold additionnal information - // for releasing properly MPP frames and decoder - framecontextref = av_buffer_allocz(sizeof(*framecontext)); - if (!framecontextref) { - ret = AVERROR(ENOMEM); - goto fail; - } - // MPP decoder needs to be closed only when all frames have been released. - framecontext = (RKMPPFrameContext *)framecontextref->data; framecontext->frame = mppframe; frame->data[0] = (uint8_t *)desc; frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), rkmpp_release_frame, - framecontextref, AV_BUFFER_FLAG_READONLY); + framecontext, AV_BUFFER_FLAG_READONLY); if (!frame->buf[0]) { + av_free(combined_desc); ret = AVERROR(ENOMEM); goto fail; } @@ -477,12 +474,6 @@ fail: if (mppframe) mpp_frame_deinit(&mppframe); - if (framecontextref) - av_buffer_unref(&framecontextref); - - if (desc) - av_free(desc); - return ret; }