From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 4/9] avcodec/libxevd: Deduplicate code Date: Tue, 27 Feb 2024 20:58:32 +0100 Message-ID: <AS8P250MB074461A4FA465E6F5B5E6AC58F592@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB0744C151DFBF003F282F0AAD8F592@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The ownership semantics of the pkt_au packet seem crazy; I have no clue when ownership has actually passed to libxevd (or rather: when one can expect to get an image with this packet attached returned from the decoder). Furthermore, given that libxevd sees this just as an opaque pointer (without free callback), we will leak AVPackets still stuck in libxevd if a user closes this decoder with the decoder not flushed. I don't know how libxevd behaves on errors; if it discard a frame in case of error, the associated packet will leak. Trying to compile doesn't work unless one overrides dangling-pointer warnings (which are treated as errors by the build system), so I don't expect anything good from them. libavcodec/libxevd.c | 160 +++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 99 deletions(-) diff --git a/libavcodec/libxevd.c b/libavcodec/libxevd.c index 0553ebfb06..33fd18f74d 100644 --- a/libavcodec/libxevd.c +++ b/libavcodec/libxevd.c @@ -252,6 +252,65 @@ static av_cold int libxevd_init(AVCodecContext *avctx) return 0; } +static int libxevd_return_frame(AVCodecContext *avctx, AVFrame *frame, + XEVD_IMGB *imgb, AVPacket **pkt_au) +{ + int ret; + + AVPacket* pkt_au_imgb = (AVPacket*)imgb->pdata[0]; + if(!pkt_au_imgb) { + av_log(avctx, AV_LOG_ERROR, "Invalid data needed to fill frame properties\n"); + + if (pkt_au) + av_packet_free(pkt_au); + av_frame_unref(frame); + + imgb->release(imgb); + imgb = NULL; + + return AVERROR_INVALIDDATA; + } + + // got frame + ret = libxevd_image_copy(avctx, imgb, frame); + if(ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Image copying error\n"); + + av_packet_free(&pkt_au_imgb); + av_frame_unref(frame); + + imgb->release(imgb); + imgb = NULL; + + return ret; + } + + // use ff_decode_frame_props_from_pkt() to fill frame properties + ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt_au_imgb); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props_from_pkt error\n"); + + av_packet_free(&pkt_au_imgb); + av_frame_unref(frame); + + imgb->release(imgb); + imgb = NULL; + + return ret; + } + + frame->pkt_dts = imgb->ts[XEVD_TS_DTS]; + frame->pts = imgb->ts[XEVD_TS_PTS]; + + av_packet_free(&pkt_au_imgb); + + // xevd_pull uses pool of objects of type XEVD_IMGB. + // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed + imgb->release(imgb); + imgb = NULL; + + return 0; +} /** * Decode frame with decoupled packet/frame dataflow * @@ -361,56 +420,7 @@ static int libxevd_receive_frame(AVCodecContext *avctx, AVFrame *frame) return AVERROR(EAGAIN); } } else { - // got frame - AVPacket* pkt_au_imgb = (AVPacket*)imgb->pdata[0]; - if(!pkt_au_imgb) { - av_log(avctx, AV_LOG_ERROR, "Invalid data needed to fill frame properties\n"); - - av_packet_free(&pkt_au); - av_frame_unref(frame); - - imgb->release(imgb); - imgb = NULL; - - return AVERROR_INVALIDDATA; - } - - ret = libxevd_image_copy(avctx, imgb, frame); - if(ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Image copying error\n"); - - av_packet_free(&pkt_au_imgb); - av_frame_unref(frame); - - imgb->release(imgb); - imgb = NULL; - - return ret; - } - - // use ff_decode_frame_props_from_pkt() to fill frame properties - ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt_au_imgb); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props_from_pkt error\n"); - - av_packet_free(&pkt_au_imgb); - av_frame_unref(frame); - - imgb->release(imgb); - imgb = NULL; - - return ret; - } - - frame->pkt_dts = imgb->ts[XEVD_TS_DTS]; - frame->pts = imgb->ts[XEVD_TS_PTS]; - - av_packet_free(&pkt_au_imgb); - - // xevd_pull uses pool of objects of type XEVD_IMGB. - // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed - imgb->release(imgb); - imgb = NULL; + return libxevd_return_frame(avctx, frame, imgb, &pkt_au); } } } @@ -428,61 +438,13 @@ static int libxevd_receive_frame(AVCodecContext *avctx, AVFrame *frame) return AVERROR_EXTERNAL; } else { // XEVD_OK - AVPacket* pkt_au_imgb; if (!imgb) { av_log(avctx, AV_LOG_ERROR, "Invalid decoded image data\n"); return AVERROR_EXTERNAL; } - pkt_au_imgb = (AVPacket*)imgb->pdata[0]; - if(!pkt_au_imgb) { - av_log(avctx, AV_LOG_ERROR, "Invalid data needed to fill frame properties\n"); - - imgb->release(imgb); - imgb = NULL; - - av_frame_unref(frame); - - return AVERROR_INVALIDDATA; - } - - // got frame - ret = libxevd_image_copy(avctx, imgb, frame); - if(ret < 0) { - av_packet_free(&pkt_au_imgb); - av_frame_unref(frame); - - imgb->release(imgb); - imgb = NULL; - - return ret; - } - // use ff_decode_frame_props_from_pkt() to fill frame properties - ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt_au_imgb); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props_from_pkt error\n"); - - av_packet_free(&pkt_au_imgb); - av_frame_unref(frame); - - imgb->release(imgb); - imgb = NULL; - - return ret; - } - - frame->pkt_dts = imgb->ts[XEVD_TS_DTS]; - frame->pts = imgb->ts[XEVD_TS_PTS]; - - av_packet_free(&pkt_au_imgb); - - // xevd_pull uses pool of objects of type XEVD_IMGB. - // The pool size is equal MAX_PB_SIZE (26), so release object when it is no more needed - imgb->release(imgb); - imgb = NULL; - - return 0; + return libxevd_return_frame(avctx, frame, imgb, NULL); } } -- 2.40.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".
next prev parent reply other threads:[~2024-02-27 19:57 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <CGME20240227194657eucas1p1332e4d035ca55a684ef190a5ea1946ee@eucas1p1.samsung.com> 2024-02-27 19:48 ` [FFmpeg-devel] [PATCH 1/9] avcodec/libxevd: Remove FF_CODEC_CAP_SETS_PKT_DTS cap Andreas Rheinhardt 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 2/9] avcodec/libxevd: Set AV_CODEC_CAP_DR1 Andreas Rheinhardt 2024-03-06 10:37 ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 3/9] avcodec/libxevd: Avoid cloning AVPacket Andreas Rheinhardt 2024-02-27 19:58 ` Andreas Rheinhardt [this message] 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 5/9] avcodec/libxevd: Reindent after the previous commit Andreas Rheinhardt 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 6/9] avcodec/libxevd: Remove useless AVClass Andreas Rheinhardt 2024-03-06 10:38 ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 7/9] avcodec/libxevd: Use CODEC_LONG_NAME() Andreas Rheinhardt 2024-03-06 10:38 ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 8/9] avcodec/libxevd: Improve included headers a bit Andreas Rheinhardt 2024-02-27 19:58 ` [FFmpeg-devel] [PATCH 9/9] avcodec/libxevd: Fix "if (ret = ff_foo() < 0)" precedence problem Andreas Rheinhardt 2024-02-29 9:36 ` [FFmpeg-devel] [PATCH 1/9] avcodec/libxevd: Remove FF_CODEC_CAP_SETS_PKT_DTS cap Andreas Rheinhardt 2024-03-06 10:38 ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics 2024-03-06 10:37 ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
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=AS8P250MB074461A4FA465E6F5B5E6AC58F592@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /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