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