From 14429f8fec231e1d6e0bfdb3f646e7461d11c736 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 6 Jan 2022 16:32:49 +0100 Subject: lavu/fifo: add a flag for automatically growing the FIFO as needed This will not increase the FIFO beyond 1MB, unless the caller explicitly specifies otherwise. --- libavutil/fifo.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'libavutil/fifo.h') diff --git a/libavutil/fifo.h b/libavutil/fifo.h index f455022e3c..55548fbeb4 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -48,13 +48,20 @@ typedef struct AVFifo AVFifo; */ typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems); +/** + * Automatically resize the FIFO on writes, so that the data fits. This + * automatic resizing happens up to a limit that can be modified with + * av_fifo_auto_grow_limit(). + */ +#define AV_FIFO_FLAG_AUTO_GROW (1 << 0) + /** * Allocate and initialize an AVFifo with a given element size. * * @param elems initial number of elements that can be stored in the FIFO * @param elem_size Size in bytes of a single element. Further operations on * the returned FIFO will implicitly use this element size. - * @param flags currently unused, must be 0 + * @param flags a combination of AV_FIFO_FLAG_* * * @return newly-allocated AVFifo on success, a negative error code on failure */ @@ -67,6 +74,12 @@ AVFifo *av_fifo_alloc2(size_t elems, size_t elem_size, */ size_t av_fifo_elem_size(const AVFifo *f); +/** + * Set the maximum size (in elements) to which the FIFO can be resized + * automatically. Has no effect unless AV_FIFO_FLAG_AUTO_GROW is used. + */ +void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems); + /** * @return number of elements available for reading from the given FIFO. */ -- cgit v1.2.3