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

Showing the changes to libavfilter (2 of 2 files). Show all

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
30 30
31void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)31void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
32{32{
33 fqg->max_queued = SIZE_MAX;
34 fqg->queued = 0;
33}35}
34 36
35static void check_consistency(FFFrameQueue *fq)37static void check_consistency(FFFrameQueue *fq)
@@ -49,6 +51,7 @@ void ff_framequeue_init(FFFrameQueue *fq, FFFrameQueueGlobal *fqg) · 13 unmodified lines
49{51{
50 fq->queue = &fq->first_bucket;52 fq->queue = &fq->first_bucket;
51 fq->allocated = 1;53 fq->allocated = 1;
54 fq->global = fqg;
52}55}
53 56
54void ff_framequeue_free(FFFrameQueue *fq)57void ff_framequeue_free(FFFrameQueue *fq)
@@ -66,6 +69,8 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame) · 11 unmodified lines
66 FFFrameBucket *b;69 FFFrameBucket *b;
67 70
68 check_consistency(fq);71 check_consistency(fq);
72 if (fq->global->queued >= fq->global->max_queued)
73 return AVERROR(ENOMEM);
69 if (fq->queued == fq->allocated) {74 if (fq->queued == fq->allocated) {
70 if (fq->allocated == 1) {75 if (fq->allocated == 1) {
71 size_t na = 8;76 size_t na = 8;
@@ -89,6 +94,7 @@ int ff_framequeue_add(FFFrameQueue *fq, AVFrame *frame) · 17 unmodified lines
89 b = bucket(fq, fq->queued);94 b = bucket(fq, fq->queued);
90 b->frame = frame;95 b->frame = frame;
91 fq->queued++;96 fq->queued++;
97 fq->global->queued++;
92 fq->total_frames_head++;98 fq->total_frames_head++;
93 fq->total_samples_head += frame->nb_samples;99 fq->total_samples_head += frame->nb_samples;
94 check_consistency(fq);100 check_consistency(fq);
@@ -103,6 +109,7 @@ AVFrame *ff_framequeue_take(FFFrameQueue *fq) · 8 unmodified lines
103 av_assert1(fq->queued);109 av_assert1(fq->queued);
104 b = bucket(fq, 0);110 b = bucket(fq, 0);
105 fq->queued--;111 fq->queued--;
112 fq->global->queued--;
106 fq->tail++;113 fq->tail++;
107 fq->tail &= fq->allocated - 1;114 fq->tail &= fq->allocated - 1;
108 fq->total_frames_tail++;115 fq->total_frames_tail++;
libavfilter/framequeue.h+15−3
@@ -40,11 +40,18 @@ typedef struct FFFrameBucket { · 39 unmodified lines
40 *40 *
41 * This structure is intended to allow implementing global control of the41 * This structure is intended to allow implementing global control of the
42 * frame queues, including memory consumption caps.42 * frame queues, including memory consumption caps.
43 *
44 * It is currently empty.
45 */43 */
46typedef struct FFFrameQueueGlobal {44typedef 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;
48} FFFrameQueueGlobal;55} FFFrameQueueGlobal;
49 56
50/**57/**
@@ -52,6 +59,11 @@ typedef struct FFFrameQueueGlobal { · 1 unmodified line
52 */59 */
53typedef struct FFFrameQueue {60typedef struct FFFrameQueue {
54 61
62 /**
63 * Pointer to the global frame queue struct holding statistics and limits
64 */
65 FFFrameQueueGlobal *global;
66
55 /**67 /**
56 * Array of allocated buckets, used as a circular buffer.68 * Array of allocated buckets, used as a circular buffer.
57 */69 */

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