From: Zhao Zhili <quinkblack@foxmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Zhao Zhili <zhilizhao@tencent.com> Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/videotoolboxenc: Put ExtraSEI inside BufNode directly Date: Sun, 7 Jul 2024 18:21:34 +0800 Message-ID: <tencent_F5D3A90FAEB6A546F30F6843F3E7737A1505@qq.com> (raw) In-Reply-To: <20240707102134.93935-1-quinkblack@foxmail.com> From: Zhao Zhili <zhilizhao@tencent.com> 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".
prev parent reply other threads:[~2024-07-07 10:22 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <20240707102134.93935-1-quinkblack@foxmail.com> 2024-07-07 10:21 ` [FFmpeg-devel] [PATCH 2/5] avcodec/videotoolboxenc: Remove unused variable Zhao Zhili 2024-07-07 10:21 ` [FFmpeg-devel] [PATCH 3/5] avcodec/videotoolboxenc: Use BufNode as sourceFrameRefcon Zhao Zhili 2024-07-07 10:21 ` [FFmpeg-devel] [PATCH 4/5] avcodec/videotoolboxenc: Fix concurrent access to CVPixelBufferRef Zhao Zhili 2024-07-07 10:21 ` Zhao Zhili [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_F5D3A90FAEB6A546F30F6843F3E7737A1505@qq.com \ --to=quinkblack@foxmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=zhilizhao@tencent.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git