From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/5] Revert "avcodec/decode: use a packet list to store packet properties" Date: Sun, 4 Dec 2022 18:52:24 -0300 Message-ID: <20221204215227.4186-2-jamrial@gmail.com> (raw) In-Reply-To: <20221204215227.4186-1-jamrial@gmail.com> The idea behind last_pkt_props was to store the properties of the last packet fed to the decoder. Any sort of queueing required by decoders that consume several packets before they start outputting frames should be done by the decoders in question. An example of this is in the libdav1d wrapper. This is required to maintain its contents during flush, and for the following commits that will fix last_pkt_props in frame threading scenarios. This revers commit 022a12b306ab2096e6ac9fc9b149828a849d65b2. Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/avcodec.c | 10 --------- libavcodec/decode.c | 47 ++++++----------------------------------- libavcodec/internal.h | 1 - tests/ref/fate/flcl1905 | 2 +- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index a85d3c2309..efa76d2740 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -386,9 +386,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_frame_unref(avci->recon_frame); } else { av_packet_unref(avci->last_pkt_props); - while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0) - av_packet_unref(avci->last_pkt_props); - av_packet_unref(avci->in_pkt); avctx->pts_correction_last_pts = @@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avci->byte_buffer); av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); - if (avci->pkt_props) { - while (av_fifo_can_read(avci->pkt_props)) { - av_packet_unref(avci->last_pkt_props); - av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); - } - av_fifo_freep2(&avci->pkt_props); - } av_packet_free(&avci->last_pkt_props); av_packet_free(&avci->in_pkt); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6be2d3d6ed..c94d9aa33c 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -132,38 +132,16 @@ fail2: return 0; } -#define IS_EMPTY(pkt) (!(pkt)->data) - -static int copy_packet_props(AVPacket *dst, const AVPacket *src) -{ - int ret = av_packet_copy_props(dst, src); - if (ret < 0) - return ret; - - dst->size = src->size; // HACK: Needed for ff_decode_frame_props(). - dst->data = (void*)1; // HACK: Needed for IS_EMPTY(). - - return 0; -} - static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) { - AVPacket tmp = { 0 }; int ret = 0; - if (IS_EMPTY(avci->last_pkt_props)) { - if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0) - return copy_packet_props(avci->last_pkt_props, pkt); + av_packet_unref(avci->last_pkt_props); + if (pkt) { + ret = av_packet_copy_props(avci->last_pkt_props, pkt); + if (!ret) + avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_decode_frame_props(). } - - ret = copy_packet_props(&tmp, pkt); - if (ret < 0) - return ret; - - ret = av_fifo_write(avci->pkt_props, &tmp, 1); - if (ret < 0) - av_packet_unref(&tmp); - return ret; } @@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret >= pkt->size || ret < 0) { av_packet_unref(pkt); - av_packet_unref(avci->last_pkt_props); } else { int consumed = ret; @@ -578,8 +555,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { ret = codec->cb.receive_frame(avctx, frame); - if (ret != AVERROR(EAGAIN)) - av_packet_unref(avci->last_pkt_props); } else ret = decode_simple_receive_frame(avctx, frame); @@ -593,12 +568,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) return ok; } - if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && - IS_EMPTY(avci->last_pkt_props)) { - // May fail if the FIFO is empty. - av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); - } - if (!ret) { frame->best_effort_timestamp = guess_correct_pts(avctx, frame->pts, @@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { - AVPacket *pkt = avctx->internal->last_pkt_props; + const AVPacket *pkt = avctx->internal->last_pkt_props; static const struct { enum AVPacketSideDataType packet; enum AVFrameSideDataType frame; @@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); - avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), - AV_FIFO_FLAG_AUTO_GROW); - if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) + if (!avci->in_pkt || !avci->last_pkt_props) return AVERROR(ENOMEM); ret = decode_bsfs_init(avctx); diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 76a6ea6bc6..a283c52e01 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -88,7 +88,6 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - struct AVFifo *pkt_props; /** * temporary buffer used for encoders to store their bitstream diff --git a/tests/ref/fate/flcl1905 b/tests/ref/fate/flcl1905 index 59cee95459..4500117993 100644 --- a/tests/ref/fate/flcl1905 +++ b/tests/ref/fate/flcl1905 @@ -189,4 +189,4 @@ frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=744|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=372|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown packet|codec_type=audio|stream_index=0|pts=360448|pts_time=8.173424|dts=360448|dts_time=8.173424|duration=44|duration_time=0.000998|size=8|pos=65528|flags=K_ -frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=N/A|pkt_duration_time=N/A|duration=N/A|duration_time=N/A|pkt_pos=N/A|pkt_size=0|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown +frame|media_type=audio|stream_index=0|key_frame=1|pts=360448|pts_time=8.173424|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=360448|best_effort_timestamp_time=8.173424|pkt_duration=44|pkt_duration_time=0.000998|duration=44|duration_time=0.000998|pkt_pos=65528|pkt_size=8|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown -- 2.38.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:[~2022-12-04 21:53 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-04 21:52 [FFmpeg-devel] [PATCH 1/5] avcodec/binkaudio: clear pts when returning more than one frame per input packet James Almer 2022-12-04 21:52 ` James Almer [this message] 2022-12-05 21:26 ` [FFmpeg-devel] [PATCH 2/5] Revert "avcodec/decode: use a packet list to store packet properties" Michael Niedermayer 2022-12-06 0:03 ` [FFmpeg-devel] [PATCH 2/6] avcodec/wmadec: clear pts when returning a frame during flush James Almer 2022-12-06 8:27 ` Paul B Mahol 2022-12-06 11:42 ` James Almer 2022-12-04 21:52 ` [FFmpeg-devel] [PATCH 3/5] avcodec/decode: don't set last_pkt_props->size James Almer 2022-12-04 21:52 ` [FFmpeg-devel] [PATCH 4/5] avcodec/pthread_frame.c: keep the last_pkt_props from worker threads in sync with the user context James Almer 2022-12-04 21:52 ` [FFmpeg-devel] [PATCH 5/5] avcodec/mpeg4videodec: duplicate the last decoded frame when the last coded frame was skipped James Almer 2022-12-06 9:17 ` Andreas Rheinhardt 2022-12-06 11:21 ` James Almer 2022-12-12 11:37 ` James Almer
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=20221204215227.4186-2-jamrial@gmail.com \ --to=jamrial@gmail.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