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 | void ff_framequeue_global_init(FFFrameQueueGlobal *fqg) | 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 | static void check_consistency(FFFrameQueue *fq) | 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 | 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 | ||
| 54 | void ff_framequeue_free(FFFrameQueue *fq) | 57 | void 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++; |
| @@ -40,11 +40,18 @@ typedef struct FFFrameBucket { · 39 unmodified lines | |||
| 40 | * | 40 | * |
| 41 | * This structure is intended to allow implementing global control of the | 41 | * 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 | */ |
| 46 | typedef struct FFFrameQueueGlobal { | 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 | } FFFrameQueueGlobal; | 55 | } FFFrameQueueGlobal; |
| 49 | 56 | ||
| 50 | /** | 57 | /** |
| @@ -52,6 +59,11 @@ typedef struct FFFrameQueueGlobal { · 1 unmodified line | |||
| 52 | */ | 59 | */ |
| 53 | typedef struct FFFrameQueue { | 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 | * Array of allocated buckets, used as a circular buffer. | 68 | * Array of allocated buckets, used as a circular buffer. |
| 57 | */ | 69 | */ |