From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Anton Khirnov <anton@khirnov.net>
Subject: [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API
Date: Mon, 24 Jan 2022 15:45:51 +0100
Message-ID: <AM7PR03MB6660B76BE556434478DA84078F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB666072F4E7572C4D4DB462358F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com>
From: Anton Khirnov <anton@khirnov.net>
---
libavcodec/avcodec.c | 17 ++++++-----------
libavcodec/decode.c | 24 +++++++++---------------
libavcodec/internal.h | 2 +-
3 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..4df834c708 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
avci->es.in_frame = av_frame_alloc();
avci->in_pkt = av_packet_alloc();
avci->last_pkt_props = av_packet_alloc();
- avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props));
+ avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
+ AV_FIFO_FLAG_AUTO_GROW);
if (!avci->buffer_frame || !avci->buffer_pkt ||
!avci->es.in_frame || !avci->in_pkt ||
!avci->last_pkt_props || !avci->pkt_props) {
@@ -399,13 +400,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
av_packet_unref(avci->buffer_pkt);
av_packet_unref(avci->last_pkt_props);
- while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
- av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, sizeof(*avci->last_pkt_props),
- NULL);
+ while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
av_packet_unref(avci->last_pkt_props);
- }
- av_fifo_reset(avci->pkt_props);
av_frame_unref(avci->es.in_frame);
av_packet_unref(avci->in_pkt);
@@ -464,12 +460,11 @@ av_cold int avcodec_close(AVCodecContext *avctx)
av_frame_free(&avci->buffer_frame);
av_packet_free(&avci->buffer_pkt);
if (avci->pkt_props) {
- while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
+ while (av_fifo_can_read(avci->pkt_props)) {
av_packet_unref(avci->last_pkt_props);
- av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
+ av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
}
- av_fifo_freep(&avci->pkt_props);
+ av_fifo_freep2(&avci->pkt_props);
}
av_packet_free(&avci->last_pkt_props);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..4023d2dd2e 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -165,26 +165,19 @@ static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
int ret = 0;
if (IS_EMPTY(avci->last_pkt_props)) {
- if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) {
- av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
- sizeof(*avci->last_pkt_props), NULL);
- } else
+ if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
return copy_packet_props(avci->last_pkt_props, pkt);
}
- if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) {
- ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt));
- if (ret < 0)
- return ret;
- }
-
ret = copy_packet_props(&tmp, pkt);
if (ret < 0)
return ret;
- av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL);
+ ret = av_fifo_write(avci->pkt_props, &tmp, 1);
+ if (ret < 0)
+ av_packet_unref(&tmp);
- return 0;
+ return ret;
}
static int decode_bsfs_init(AVCodecContext *avctx)
@@ -543,9 +536,10 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
avci->draining_done = 1;
if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
- IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props))
- av_fifo_generic_read(avci->pkt_props,
- avci->last_pkt_props, sizeof(*avci->last_pkt_props), NULL);
+ 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,
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 72ca1553f6..4e864535f1 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -149,7 +149,7 @@ typedef struct AVCodecInternal {
* for decoding.
*/
AVPacket *last_pkt_props;
- AVFifoBuffer *pkt_props;
+ AVFifo *pkt_props;
/**
* temporary buffer used for encoders to store their bitstream
--
2.32.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".
next prev parent reply other threads:[~2022-01-24 14:47 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 14:44 [FFmpeg-devel] [PATCH v2 00/31] New " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 01/31] avutil/fifo: Use av_fifo_generic_peek_at() for av_fifo_generic_peek() Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 02/31] lavu/fifo: disallow overly large fifo sizes Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 03/31] lavu/fifo: Add new AVFifo API based upon the notion of element size Andreas Rheinhardt
2022-02-05 7:55 ` Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 04/31] lavu/fifo: add a flag for automatically growing the FIFO as needed Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 05/31] lavu/tests/fifo: switch to the new API Andreas Rheinhardt
2022-01-24 14:45 ` Andreas Rheinhardt [this message]
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 08/31] lavc/cuviddec: do not reallocate the fifo unnecessarily Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 09/31] lavc/cuviddec: convert to the new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 10/31] lavc/libvorbisenc: switch to " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 11/31] lavc/libvpxenc: switch to the " Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 12/31] lavc/libvpxenc: remove unneeded context variable Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 13/31] lavc/nvenc: switch to the new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 14/31] lavc/qsvdec: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 15/31] lavc/qsvenc: switch to " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 16/31] avcodec/qsvenc: Reindent after the previous commit Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 17/31] lavf/dvenc: return an error on audio/video desync Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 18/31] lavf/dvenc: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 19/31] lavf/mpegenc: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 20/31] lavf/swfenc: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 21/31] lavf/udp: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 22/31] lavf/async: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 23/31] lavd/jack: switch to the " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 24/31] lavu/audio_fifo: drop an unnecessary include Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 25/31] lavu/audio_fifo: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 26/31] lavu/threadmessage: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 27/31] lavfi/qsvvpp: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 28/31] lavfi/vf_deshake_opencl: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 29/31] ffplay: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: " Andreas Rheinhardt
2022-01-24 14:46 ` [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old " Andreas Rheinhardt
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=AM7PR03MB6660B76BE556434478DA84078F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com \
--to=andreas.rheinhardt@outlook.com \
--cc=anton@khirnov.net \
--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