FFmpeg 7.1.1
|
A generic FIFO API. More...
Files | |
file | fifo.h |
A generic FIFO API. | |
Macros | |
#define | AV_FIFO_FLAG_AUTO_GROW (1 << 0) |
Automatically resize the FIFO on writes, so that the data fits. | |
Typedefs | |
typedef struct AVFifo | AVFifo |
typedef int | AVFifoCB(void *opaque, void *buf, size_t *nb_elems) |
Callback for writing or reading from a FIFO, passed to (and invoked from) the av_fifo_*_cb() functions. | |
Functions | |
AVFifo * | av_fifo_alloc2 (size_t elems, size_t elem_size, unsigned int flags) |
Allocate and initialize an AVFifo with a given element size. | |
size_t | av_fifo_elem_size (const AVFifo *f) |
void | av_fifo_auto_grow_limit (AVFifo *f, size_t max_elems) |
Set the maximum size (in elements) to which the FIFO can be resized automatically. | |
size_t | av_fifo_can_read (const AVFifo *f) |
size_t | av_fifo_can_write (const AVFifo *f) |
int | av_fifo_grow2 (AVFifo *f, size_t inc) |
Enlarge an AVFifo. | |
int | av_fifo_write (AVFifo *f, const void *buf, size_t nb_elems) |
Write data into a FIFO. | |
int | av_fifo_write_from_cb (AVFifo *f, AVFifoCB read_cb, void *opaque, size_t *nb_elems) |
Write data from a user-provided callback into a FIFO. | |
int | av_fifo_read (AVFifo *f, void *buf, size_t nb_elems) |
Read data from a FIFO. | |
int | av_fifo_read_to_cb (AVFifo *f, AVFifoCB write_cb, void *opaque, size_t *nb_elems) |
Feed data from a FIFO into a user-provided callback. | |
int | av_fifo_peek (const AVFifo *f, void *buf, size_t nb_elems, size_t offset) |
Read data from a FIFO without modifying FIFO state. | |
int | av_fifo_peek_to_cb (const AVFifo *f, AVFifoCB write_cb, void *opaque, size_t *nb_elems, size_t offset) |
Feed data from a FIFO into a user-provided callback. | |
void | av_fifo_drain2 (AVFifo *f, size_t size) |
Discard the specified amount of data from an AVFifo. | |
void | av_fifo_reset2 (AVFifo *f) |
void | av_fifo_freep2 (AVFifo **f) |
Free an AVFifo and reset pointer to NULL. | |
A generic FIFO API.
#define AV_FIFO_FLAG_AUTO_GROW (1 << 0) |
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().
typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems) |
Callback for writing or reading from a FIFO, passed to (and invoked from) the av_fifo_*_cb() functions.
It may be invoked multiple times from a single av_fifo_*_cb() call and may process less data than the maximum size indicated by nb_elems.
opaque | the opaque pointer provided to the av_fifo_*_cb() function |
buf | the buffer for reading or writing the data, depending on which av_fifo_*_cb function is called |
nb_elems | On entry contains the maximum number of elements that can be read from / written into buf. On success, the callback should update it to contain the number of elements actually written. |
AVFifo * av_fifo_alloc2 | ( | size_t | elems, |
size_t | elem_size, | ||
unsigned int | flags | ||
) |
Allocate and initialize an AVFifo with a given element size.
elems | initial number of elements that can be stored in the FIFO |
elem_size | Size in bytes of a single element. Further operations on the returned FIFO will implicitly use this element size. |
flags | a combination of AV_FIFO_FLAG_* |
size_t av_fifo_elem_size | ( | const AVFifo * | f | ) |
void av_fifo_auto_grow_limit | ( | AVFifo * | f, |
size_t | max_elems | ||
) |
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.
size_t av_fifo_can_read | ( | const AVFifo * | f | ) |
size_t av_fifo_can_write | ( | const AVFifo * | f | ) |
In other words, this number of elements or less is guaranteed to fit into the FIFO. More data may be written when the AV_FIFO_FLAG_AUTO_GROW flag was specified at FIFO creation, but this may involve memory allocation, which can fail.
int av_fifo_grow2 | ( | AVFifo * | f, |
size_t | inc | ||
) |
Enlarge an AVFifo.
On success, the FIFO will be large enough to hold exactly inc + av_fifo_can_read() + av_fifo_can_write() elements. In case of failure, the old FIFO is kept unchanged.
f | AVFifo to resize |
inc | number of elements to allocate for, in addition to the current allocated size |
int av_fifo_write | ( | AVFifo * | f, |
const void * | buf, | ||
size_t | nb_elems | ||
) |
Write data into a FIFO.
In case nb_elems > av_fifo_can_write(f) and the AV_FIFO_FLAG_AUTO_GROW flag was not specified at FIFO creation, nothing is written and an error is returned.
Calling function is guaranteed to succeed if nb_elems <= av_fifo_can_write(f).
f | the FIFO buffer |
buf | Data to be written. nb_elems * av_fifo_elem_size(f) bytes will be read from buf on success. |
nb_elems | number of elements to write into FIFO |
Write data from a user-provided callback into a FIFO.
f | the FIFO buffer |
read_cb | Callback supplying the data to the FIFO. May be called multiple times. |
opaque | opaque user data to be provided to read_cb |
nb_elems | Should point to the maximum number of elements that can be written. Will be updated to contain the number of elements actually written. |
int av_fifo_read | ( | AVFifo * | f, |
void * | buf, | ||
size_t | nb_elems | ||
) |
Read data from a FIFO.
In case nb_elems > av_fifo_can_read(f), nothing is read and an error is returned.
f | the FIFO buffer |
buf | Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes will be written into buf on success. |
nb_elems | number of elements to read from FIFO |
Feed data from a FIFO into a user-provided callback.
f | the FIFO buffer |
write_cb | Callback the data will be supplied to. May be called multiple times. |
opaque | opaque user data to be provided to write_cb |
nb_elems | Should point to the maximum number of elements that can be read. Will be updated to contain the total number of elements actually sent to the callback. |
int av_fifo_peek | ( | const AVFifo * | f, |
void * | buf, | ||
size_t | nb_elems, | ||
size_t | offset | ||
) |
Read data from a FIFO without modifying FIFO state.
Returns an error if an attempt is made to peek to nonexistent elements (i.e. if offset + nb_elems is larger than av_fifo_can_read(f)).
f | the FIFO buffer |
buf | Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes will be written into buf. |
nb_elems | number of elements to read from FIFO |
offset | number of initial elements to skip. |
int av_fifo_peek_to_cb | ( | const AVFifo * | f, |
AVFifoCB | write_cb, | ||
void * | opaque, | ||
size_t * | nb_elems, | ||
size_t | offset | ||
) |
Feed data from a FIFO into a user-provided callback.
f | the FIFO buffer |
write_cb | Callback the data will be supplied to. May be called multiple times. |
opaque | opaque user data to be provided to write_cb |
nb_elems | Should point to the maximum number of elements that can be read. Will be updated to contain the total number of elements actually sent to the callback. |
offset | number of initial elements to skip; offset + *nb_elems must not be larger than av_fifo_can_read(f). |
void av_fifo_drain2 | ( | AVFifo * | f, |
size_t | size | ||
) |
Discard the specified amount of data from an AVFifo.
size | number of elements to discard, MUST NOT be larger than av_fifo_can_read(f) |
void av_fifo_reset2 | ( | AVFifo * | f | ) |
void av_fifo_freep2 | ( | AVFifo ** | f | ) |
Free an AVFifo and reset pointer to NULL.
f | Pointer to an AVFifo to free. *f == NULL is allowed. |