Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/4] avfilter/framequeue: add support for limiting and tracking buffered frames in the queues
@ 2025-07-06 22:00 Marton Balint
  2025-07-06 22:00 ` [FFmpeg-devel] [PATCH 2/4] avfilter/avfilter: add AVFilterGraph->max_buffered_frames to limit buffered frames Marton Balint
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marton Balint @ 2025-07-06 22:00 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavfilter/framequeue.c |  7 +++++++
 libavfilter/framequeue.h | 18 +++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/libavfilter/framequeue.c b/libavfilter/framequeue.c
index 79255fe532..3363406ba7 100644
--- a/libavfilter/framequeue.c
+++ b/libavfilter/framequeue.c
@@ -30,6 +30,8 @@ static inline FFFrameBucket *bucket(FFFrameQueue *fq, size_t idx)
 
 void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
 {
+    fqg->max_queued = SIZE_MAX;
+    fqg->queued = 0;
 }
 
 static void check_consistency(FFFrameQueue *fq)
@@ -49,6 +51,7 @@ void ff_framequeue_init(FFFrameQueue *fq, FFFrameQueueGlobal *fqg)
 {
     fq->queue = &fq->first_bucket;
     fq->allocated = 1;
+    fq->global = fqg;
 }
 
 void ff_framequeue_free(FFFrameQueue *fq)
@@ -66,6 +69,8 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame)
     FFFrameBucket *b;
 
     check_consistency(fq);
+    if (fq->global->queued >= fq->global->max_queued)
+        return AVERROR(ENOMEM);
     if (fq->queued == fq->allocated) {
         if (fq->allocated == 1) {
             size_t na = 8;
@@ -89,6 +94,7 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame)
     b = bucket(fq, fq->queued);
     b->frame = frame;
     fq->queued++;
+    fq->global->queued++;
     fq->total_frames_head++;
     fq->total_samples_head += frame->nb_samples;
     check_consistency(fq);
@@ -103,6 +109,7 @@ AVFrame *ff_framequeue_take(FFFrameQueue *fq)
     av_assert1(fq->queued);
     b = bucket(fq, 0);
     fq->queued--;
+    fq->global->queued--;
     fq->tail++;
     fq->tail &= fq->allocated - 1;
     fq->total_frames_tail++;
diff --git a/libavfilter/framequeue.h b/libavfilter/framequeue.h
index c49d872e85..405a43c65d 100644
--- a/libavfilter/framequeue.h
+++ b/libavfilter/framequeue.h
@@ -40,11 +40,18 @@ typedef struct FFFrameBucket {
  *
  * This structure is intended to allow implementing global control of the
  * frame queues, including memory consumption caps.
- *
- * It is currently empty.
  */
 typedef struct FFFrameQueueGlobal {
-    char dummy; /* C does not allow empty structs */
+
+    /**
+     * Maximum number of allowed frames in the queues combined.
+     */
+    size_t max_queued;
+
+    /**
+     * Total number of queued frames in the queues combined.
+     */
+    size_t queued;
 } FFFrameQueueGlobal;
 
 /**
@@ -52,6 +59,11 @@ typedef struct FFFrameQueueGlobal {
  */
 typedef struct FFFrameQueue {
 
+    /**
+     * Pointer to the global frame queue struct holding statistics and limits
+     */
+    FFFrameQueueGlobal *global;
+
     /**
      * Array of allocated buckets, used as a circular buffer.
      */
-- 
2.43.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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-06 22:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-06 22:00 [FFmpeg-devel] [PATCH 1/4] avfilter/framequeue: add support for limiting and tracking buffered frames in the queues Marton Balint
2025-07-06 22:00 ` [FFmpeg-devel] [PATCH 2/4] avfilter/avfilter: add AVFilterGraph->max_buffered_frames to limit buffered frames Marton Balint
2025-07-06 22:00 ` [FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg: add support for setting maximum buffered frames in a filtergraph Marton Balint
2025-07-06 22:00 ` [FFmpeg-devel] [PATCH 4/4] tests/fate: add fate test for excessive frame buffering when using filters Marton Balint

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