aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/framequeue.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2025-07-06 10:03:46 +0200
committerMarton Balint <cus@passwd.hu>2025-07-14 22:03:36 +0200
commit71468e85ae720cb63aa9689f0d94e9e9689b9de9 (patch)
tree94b791807a25eb401dae1127dfb9b1d63995a12b /libavfilter/framequeue.c
parent35a6de137a39f274d5e01ed0e0e6c4f04d0aaf07 (diff)
downloadffmpeg-71468e85ae720cb63aa9689f0d94e9e9689b9de9.tar.gz
avfilter/framequeue: add support for limiting and tracking buffered frames in the queues
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavfilter/framequeue.c')
-rw-r--r--libavfilter/framequeue.c7
1 files changed, 7 insertions, 0 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++;