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 E5C5947186 for ; Sun, 7 Jul 2024 10:22:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A283768DAB2; Sun, 7 Jul 2024 13:21:58 +0300 (EEST) Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2CCB968DA0B for ; Sun, 7 Jul 2024 13:21:45 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1720347698; bh=YYhKZruBp3xZtVuQF6mSbBJegtSqBbGPBNgqAMx50Bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F1gTki/fH2c5ixXRFM25kk2e5h0zHKgwMf9Oi5swCt7Yeb9cMA9HKuPK8E+80eDIP 38SAokdoKiqAHQF8YOLB6hz3jlhLyeeCtj/myCXLY2CiG+BXg49mQWBU3EPrceufOI +9fsJOExnzMBsfn4b7KiQJxevNLAPspg4AFoLDtg= Received: from ZHILIZHAO-MB1.tencent.com ([113.116.28.29]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id 5633A86C; Sun, 07 Jul 2024 18:21:35 +0800 X-QQ-mid: xmsmtpt1720347697t0ojlxb7u Message-ID: X-QQ-XMAILINFO: OIy020LZxBBEUSnxjNELh/1AClYWiOQgTFwd/AfFUAhjogWI76R1+/18RWw8aH 0pB9qBTTYK8pgkPdg5SAT/u19d7cyL14TAbdozsJ/1oRDcouD7NutYmd7mzPGE/z+oqP/vaZGxYf 6NyY4DcHYtIynicBZvKVZI3av+vxwcKBeKqIN5K9aHzq8Q5Zz0kPvOWk/qtXGuRyDZZrI5DnAdI8 Yn8MUf1d6XdkZswLFiCtsXW0GkVroQSCFzCTA7iKU61k2bPfunElqjCE0++xwicyCe9SQFjOVGBp GQ0rZElbIXPkrU8RsX7D+if7Xy2dR5tnxdFvA4/WXyXI22Kest9wc/RdFzbFkDwbVR8uhvv1SMRH dRk4jUggPrvc3SEmw9obJ8zYj4yxX2ExUXxY1wpMYhZJeaiVt3xTrAQmM+T/6pznKhWvOzCCFvIc WVtDTeBIHq90hRwSlGSGz16ZDt7bBX91qxMopteMjZt2gacH3sA9l+/mFqYpvNXvXu3+TwwOJfxx ir5LhsiHZaGhbyD6AAr6GbhkZ5zbcPdOhBZ/l26f+MV3o6J0MRoS/nr0oDgOwT2bNhQUYHYUP2Fh ugik7mj7eRH+qzidD+nLgUQp31QZTUGfAVePnBJdW3ZimydG9P5S238EOV09b3FncJq2N7R7XnF9 3+GM1vgYpKulM+aFhwgjp3uLsIVCYvHBk365S/tZysSZww2uf90bdXSjo3Ka5DvQJSZ1oPnAN8vT tQx85G8lsqac/TxwoIc93y7GonnufRmkqIrfUtgMa1WfUGVyBZ81qFR4/yP0vJJtcve5DQvMHfMx SuwciJGYWnAPm9Al7ClimwdVYAurBF4HK5Jr8/pAFwwtTM43eJOajqx6RLV/DigmQqH7xqA/ny8P HAANUgCj+8mw092VMFjfHFHbSEPgJd5zk1Ofi0PN3fwOG3JZRGN0RoXJ4nkAD1JHVg0x4tkawcKR xnpLySku3+NkMhNfZCWZLdRhLfSYpbd4oxmR/STP9xGyIr1ni4rbCEq0WKgfITkuUhH15y6og= X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 Jul 2024 18:21:34 +0800 X-OQ-MSGID: <20240707102134.93935-5-quinkblack@foxmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240707102134.93935-1-quinkblack@foxmail.com> References: <20240707102134.93935-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/videotoolboxenc: Put ExtraSEI inside BufNode directly 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: Zhao Zhili 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: From: Zhao Zhili Reduce error path and simplify the code. --- libavcodec/videotoolboxenc.c | 60 +++++++++++++----------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 9bb9b0b457..bd0b55275f 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -227,7 +227,7 @@ typedef struct ExtraSEI { typedef struct BufNode { CMSampleBufferRef cm_buffer; - ExtraSEI *sei; + ExtraSEI sei; AVBufferRef *frame_buf; struct BufNode* next; } BufNode; @@ -281,6 +281,18 @@ typedef struct VTEncContext { int max_ref_frames; } VTEncContext; +static void vtenc_free_buf_node(BufNode *info) +{ + if (!info) + return; + + av_free(info->sei.data); + if (info->cm_buffer) + CFRelease(info->cm_buffer); + av_buffer_unref(&info->frame_buf); + av_free(info); +} + static int vt_dump_encoder(AVCodecContext *avctx) { VTEncContext *vtctx = avctx->priv_data; @@ -388,7 +400,7 @@ static void vtenc_reset(VTEncContext *vtctx) } } -static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI **sei) +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI *sei) { BufNode *info; @@ -426,14 +438,12 @@ static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, E pthread_mutex_unlock(&vtctx->lock); *buf = info->cm_buffer; + info->cm_buffer = NULL; if (sei && *buf) { *sei = info->sei; - } else if (info->sei) { - if (info->sei->data) av_free(info->sei->data); - av_free(info->sei); + info->sei = (ExtraSEI) {0}; } - av_free(info); - + vtenc_free_buf_node(info); return 0; } @@ -715,23 +725,6 @@ static int set_extradata(AVCodecContext *avctx, CMSampleBufferRef sample_buffer) return 0; } -static void vtenc_free_buf_node(BufNode *info) -{ - if (!info) - return; - - if (info->sei) { - av_free(info->sei->data); - av_free(info->sei); - } - - if (info->cm_buffer) - CFRelease(info->cm_buffer); - - av_buffer_unref(&info->frame_buf); - av_free(info); -} - static void vtenc_output_callback( void *ctx, void *sourceFrameCtx, @@ -2589,7 +2582,6 @@ static int vtenc_send_frame(AVCodecContext *avctx, CVPixelBufferRef cv_img = NULL; AVFrameSideData *side_data = NULL; BufNode *node = av_mallocz(sizeof(*node)); - ExtraSEI *sei = NULL; int status; if (!node) @@ -2606,15 +2598,8 @@ static int vtenc_send_frame(AVCodecContext *avctx, #if CONFIG_ATSC_A53 side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC); if (vtctx->a53_cc && side_data && side_data->size) { - sei = av_mallocz(sizeof(*sei)); - if (!sei) { - status = AVERROR(ENOMEM); - goto out; - } - node->sei = sei; - status = ff_alloc_a53_sei(frame, 0, &sei->data, &sei->size); + status = ff_alloc_a53_sei(frame, 0, &node->sei.data, &node->sei.size); if (status < 0) { - av_free(sei); goto out; } } @@ -2659,7 +2644,7 @@ static av_cold int vtenc_frame( bool get_frame; int status; CMSampleBufferRef buf = NULL; - ExtraSEI *sei = NULL; + ExtraSEI sei = {0}; if (frame) { status = vtenc_send_frame(avctx, vtctx, frame); @@ -2700,11 +2685,8 @@ static av_cold int vtenc_frame( if (status) goto end_nopkt; if (!buf) goto end_nopkt; - status = vtenc_cm_to_avpacket(avctx, buf, pkt, sei); - if (sei) { - if (sei->data) av_free(sei->data); - av_free(sei); - } + status = vtenc_cm_to_avpacket(avctx, buf, pkt, sei.data ? &sei : NULL); + av_free(sei.data); CFRelease(buf); if (status) goto end_nopkt; -- 2.42.0 _______________________________________________ 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".