History

avfilter/framequeue: add support for limiting and tracking buffered frames in the queues

Marton Balint committed 1 year ago

Commit 71468e81 parent 35a6de12 files · +22 −3Browse files

Unified · Split

2 files
  1. libavfilter/framequeue.c +7 −0
  2. libavfilter/framequeue.h +15 −3
libavfilter/framequeue.c+7−0
@@ -30,6 +30,8 @@ static inline FFFrameBucket *bucket(FFFrameQueue *fq, size_t idx) · 29 unmodified lines
3030
3131 void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
3232 {
33+ fqg->max_queued = SIZE_MAX;
34+ fqg->queued = 0;
3335 }
3436
3537 static void check_consistency(FFFrameQueue *fq)
@@ -49,6 +51,7 @@ void ff_framequeue_init(FFFrameQueue *fq, FFFrameQueueGlobal *fqg) · 13 unmodified lines
4951 {
5052 fq->queue = &fq->first_bucket;
5153 fq->allocated = 1;
54+ fq->global = fqg;
5255 }
5356
5457 void ff_framequeue_free(FFFrameQueue *fq)
@@ -66,6 +69,8 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame) · 11 unmodified lines
6669 FFFrameBucket *b;
6770
6871 check_consistency(fq);
72+ if (fq->global->queued >= fq->global->max_queued)
73+ return AVERROR(ENOMEM);
6974 if (fq->queued == fq->allocated) {
7075 if (fq->allocated == 1) {
7176 size_t na = 8;
@@ -89,6 +94,7 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame) · 17 unmodified lines
8994 b = bucket(fq, fq->queued);
9095 b->frame = frame;
9196 fq->queued++;
97+ fq->global->queued++;
9298 fq->total_frames_head++;
9399 fq->total_samples_head += frame->nb_samples;
94100 check_consistency(fq);
@@ -103,6 +109,7 @@ AVFrame *ff_framequeue_take(FFFrameQueue *fq) · 8 unmodified lines
103109 av_assert1(fq->queued);
104110 b = bucket(fq, 0);
105111 fq->queued--;
112+ fq->global->queued--;
106113 fq->tail++;
107114 fq->tail &= fq->allocated - 1;
108115 fq->total_frames_tail++;
libavfilter/framequeue.h+15−3
@@ -40,11 +40,18 @@ typedef struct FFFrameBucket { · 39 unmodified lines
4040 *
4141 * This structure is intended to allow implementing global control of the
4242 * frame queues, including memory consumption caps.
43− *
44− * It is currently empty.
4543 */
4644 typedef struct FFFrameQueueGlobal {
47− char dummy; /* C does not allow empty structs */
45+
46+ /**
47+ * Maximum number of allowed frames in the queues combined.
48+ */
49+ size_t max_queued;
50+
51+ /**
52+ * Total number of queued frames in the queues combined.
53+ */
54+ size_t queued;
4855 } FFFrameQueueGlobal;
4956
5057 /**
@@ -52,6 +59,11 @@ typedef struct FFFrameQueueGlobal { · 1 unmodified line
5259 */
5360 typedef struct FFFrameQueue {
5461
62+ /**
63+ * Pointer to the global frame queue struct holding statistics and limits
64+ */
65+ FFFrameQueueGlobal *global;
66+
5567 /**
5668 * Array of allocated buckets, used as a circular buffer.
5769 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t