From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Anton Khirnov <anton@khirnov.net>
Subject: [FFmpeg-devel] [PATCH v2 30/31] ffmpeg: switch to new FIFO API
Date: Mon, 24 Jan 2022 15:46:15 +0100
Message-ID: <AM7PR03MB6660696120CF40641373BD0A8F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB666072F4E7572C4D4DB462358F5E9@AM7PR03MB6660.eurprd03.prod.outlook.com>
From: Anton Khirnov <anton@khirnov.net>
---
fftools/ffmpeg.c | 69 ++++++++++++++++-------------------------
fftools/ffmpeg.h | 6 ++--
fftools/ffmpeg_filter.c | 14 ++++-----
fftools/ffmpeg_opt.c | 4 +--
4 files changed, 37 insertions(+), 56 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d134b025f..d909fa58a7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -527,23 +527,17 @@ static void ffmpeg_cleanup(int ret)
for (j = 0; j < fg->nb_inputs; j++) {
InputFilter *ifilter = fg->inputs[j];
struct InputStream *ist = ifilter->ist;
+ AVFrame *frame;
- while (av_fifo_size(ifilter->frame_queue)) {
- AVFrame *frame;
- av_fifo_generic_read(ifilter->frame_queue, &frame,
- sizeof(frame), NULL);
+ while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0)
av_frame_free(&frame);
- }
- av_fifo_freep(&ifilter->frame_queue);
+ av_fifo_freep2(&ifilter->frame_queue);
av_freep(&ifilter->displaymatrix);
if (ist->sub2video.sub_queue) {
- while (av_fifo_size(ist->sub2video.sub_queue)) {
- AVSubtitle sub;
- av_fifo_generic_read(ist->sub2video.sub_queue,
- &sub, sizeof(sub), NULL);
+ AVSubtitle sub;
+ while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
avsubtitle_free(&sub);
- }
- av_fifo_freep(&ist->sub2video.sub_queue);
+ av_fifo_freep2(&ist->sub2video.sub_queue);
}
av_buffer_unref(&ifilter->hw_frames_ctx);
av_freep(&ifilter->name);
@@ -608,12 +602,10 @@ static void ffmpeg_cleanup(int ret)
avcodec_parameters_free(&ost->ref_par);
if (ost->muxing_queue) {
- while (av_fifo_size(ost->muxing_queue)) {
- AVPacket *pkt;
- av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+ AVPacket *pkt;
+ while (av_fifo_read(ost->muxing_queue, &pkt, 1) >= 0)
av_packet_free(&pkt);
- }
- av_fifo_freep(&ost->muxing_queue);
+ av_fifo_freep2(&ost->muxing_queue);
}
av_freep(&output_streams[i]);
@@ -749,11 +741,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
if (!of->header_written) {
AVPacket *tmp_pkt;
/* the muxer is not initialized yet, buffer the packet */
- if (!av_fifo_space(ost->muxing_queue)) {
- size_t cur_size = av_fifo_size(ost->muxing_queue);
+ if (!av_fifo_can_write(ost->muxing_queue)) {
+ size_t cur_size = av_fifo_can_read(ost->muxing_queue);
unsigned int are_we_over_size =
(ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold;
- size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX;
+ size_t limit = are_we_over_size ? ost->max_muxing_queue_size : SIZE_MAX;
size_t new_size = FFMIN(2 * cur_size, limit);
if (new_size <= cur_size) {
@@ -762,7 +754,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
ost->file_index, ost->st->index);
exit_program(1);
}
- ret = av_fifo_realloc2(ost->muxing_queue, new_size);
+ ret = av_fifo_grow2(ost->muxing_queue, new_size - cur_size);
if (ret < 0)
exit_program(1);
}
@@ -774,7 +766,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
exit_program(1);
av_packet_move_ref(tmp_pkt, pkt);
ost->muxing_queue_data_size += tmp_pkt->size;
- av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);
+ av_fifo_write(ost->muxing_queue, &tmp_pkt, 1);
return;
}
@@ -2195,15 +2187,11 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_ref
if (!tmp)
return AVERROR(ENOMEM);
- if (!av_fifo_space(ifilter->frame_queue)) {
- ret = av_fifo_realloc2(ifilter->frame_queue, 2 * av_fifo_size(ifilter->frame_queue));
- if (ret < 0) {
- av_frame_free(&tmp);
- return ret;
- }
- }
- av_fifo_generic_write(ifilter->frame_queue, &tmp, sizeof(tmp), NULL);
- return 0;
+ ret = av_fifo_write(ifilter->frame_queue, &tmp, 1);
+ if (ret < 0)
+ av_frame_free(&tmp);
+
+ return ret;
}
ret = reap_filters(1);
@@ -2526,15 +2514,13 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
sub2video_update(ist, INT64_MIN, &subtitle);
} else if (ist->nb_filters) {
if (!ist->sub2video.sub_queue)
- ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));
+ ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
if (!ist->sub2video.sub_queue)
exit_program(1);
- if (!av_fifo_space(ist->sub2video.sub_queue)) {
- ret = av_fifo_realloc2(ist->sub2video.sub_queue, 2 * av_fifo_size(ist->sub2video.sub_queue));
- if (ret < 0)
- exit_program(1);
- }
- av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL);
+
+ ret = av_fifo_write(ist->sub2video.sub_queue, &subtitle, 1);
+ if (ret < 0)
+ exit_program(1);
free_sub = 0;
}
@@ -2976,14 +2962,13 @@ static int check_init_output_file(OutputFile *of, int file_index)
/* flush the muxing queues */
for (i = 0; i < of->ctx->nb_streams; i++) {
OutputStream *ost = output_streams[of->ost_index + i];
+ AVPacket *pkt;
/* try to improve muxing time_base (only possible if nothing has been written yet) */
- if (!av_fifo_size(ost->muxing_queue))
+ if (!av_fifo_can_read(ost->muxing_queue))
ost->mux_timebase = ost->st->time_base;
- while (av_fifo_size(ost->muxing_queue)) {
- AVPacket *pkt;
- av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+ while (av_fifo_read(ost->muxing_queue, &pkt, 1) >= 0) {
ost->muxing_queue_data_size -= pkt->size;
write_packet(of, pkt, ost, 1);
av_packet_free(&pkt);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9b200b806a..81ec4d5970 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -241,7 +241,7 @@ typedef struct InputFilter {
uint8_t *name;
enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video
- AVFifoBuffer *frame_queue;
+ AVFifo *frame_queue;
// parameters configured for this input
int format;
@@ -355,7 +355,7 @@ typedef struct InputStream {
struct sub2video {
int64_t last_pts;
int64_t end_pts;
- AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init
+ AVFifo *sub_queue; ///< queue of AVSubtitle* before filter init
AVFrame *frame;
int w, h;
unsigned int initialize; ///< marks if sub2video_update should force an initialization
@@ -555,7 +555,7 @@ typedef struct OutputStream {
int max_muxing_queue_size;
/* the packets are buffered here until the muxer is ready to be initialized */
- AVFifoBuffer *muxing_queue;
+ AVFifo *muxing_queue;
/*
* The size of the AVPackets' buffers in queue.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1f6cba2c04..41d87377c7 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -178,7 +178,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
ifilter->graph = fg;
ifilter->format = -1;
- ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
exit_program(1);
@@ -286,7 +286,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ifilter->type = ist->st->codecpar->codec_type;
ifilter->name = describe_filter_link(fg, in, 1);
- ifilter->frame_queue = av_fifo_alloc(8 * sizeof(AVFrame*));
+ ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
exit_program(1);
@@ -1106,9 +1106,8 @@ int configure_filtergraph(FilterGraph *fg)
}
for (i = 0; i < fg->nb_inputs; i++) {
- while (av_fifo_size(fg->inputs[i]->frame_queue)) {
- AVFrame *tmp;
- av_fifo_generic_read(fg->inputs[i]->frame_queue, &tmp, sizeof(tmp), NULL);
+ AVFrame *tmp;
+ while (av_fifo_read(fg->inputs[i]->frame_queue, &tmp, 1) >= 0) {
ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
av_frame_free(&tmp);
if (ret < 0)
@@ -1129,9 +1128,8 @@ int configure_filtergraph(FilterGraph *fg)
for (i = 0; i < fg->nb_inputs; i++) {
InputStream *ist = fg->inputs[i]->ist;
if (ist->sub2video.sub_queue && ist->sub2video.frame) {
- while (av_fifo_size(ist->sub2video.sub_queue)) {
- AVSubtitle tmp;
- av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
+ AVSubtitle tmp;
+ while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
sub2video_update(ist, INT64_MIN, &tmp);
avsubtitle_free(&tmp);
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 9c820ab73f..3102851885 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1589,8 +1589,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->max_muxing_queue_size = 128;
MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
- ost->max_muxing_queue_size = FFMIN(ost->max_muxing_queue_size, INT_MAX / sizeof(ost->pkt));
- ost->max_muxing_queue_size *= sizeof(ost->pkt);
ost->muxing_queue_data_size = 0;
@@ -1617,7 +1615,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
}
ost->last_mux_dts = AV_NOPTS_VALUE;
- ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
+ ost->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
if (!ost->muxing_queue)
exit_program(1);
--
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:51 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 ` [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API Andreas Rheinhardt
2022-01-24 14:45 ` [FFmpeg-devel] [PATCH v2 07/31] lavc/amfenc: " 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 ` Andreas Rheinhardt [this message]
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=AM7PR03MB6660696120CF40641373BD0A8F5E9@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