FFmpeg  4.2.2
Data Structures | Macros | Typedefs | Functions
fifo.h File Reference
#include <stdint.h>
#include "avutil.h"
#include "attributes.h"

Go to the source code of this file.

Data Structures

struct  AVFifoBuffer
 

Macros

#define AV_FIFO_FLAG_AUTO_GROW   (1 << 0)
 

Typedefs

typedef struct AVFifo AVFifo
 
typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems)
 

Functions

AVFifoBufferav_fifo_alloc (unsigned int size)
 Initialize an AVFifoBuffer. More...
 
AVFifoBufferav_fifo_alloc_array (size_t nmemb, size_t size)
 Initialize an AVFifoBuffer. More...
 
void av_fifo_free (AVFifoBuffer *f)
 Free an AVFifoBuffer. More...
 
void av_fifo_freep (AVFifoBuffer **f)
 Free an AVFifoBuffer and reset pointer to NULL. More...
 
void av_fifo_reset (AVFifoBuffer *f)
 Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied. More...
 
int av_fifo_size (const AVFifoBuffer *f)
 Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from it. More...
 
int av_fifo_space (const AVFifoBuffer *f)
 Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write into it. More...
 
int av_fifo_generic_peek_at (AVFifoBuffer *f, void *dest, int offset, int buf_size, void(*func)(void *, void *, int))
 Feed data at specific position from an AVFifoBuffer to a user-supplied callback. More...
 
int av_fifo_generic_peek (AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
 Feed data from an AVFifoBuffer to a user-supplied callback. More...
 
int av_fifo_generic_read (AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
 Feed data from an AVFifoBuffer to a user-supplied callback. More...
 
int av_fifo_generic_write (AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
 Feed data from a user-supplied callback to an AVFifoBuffer. More...
 
int av_fifo_realloc2 (AVFifoBuffer *f, unsigned int size)
 Resize an AVFifoBuffer. More...
 
int av_fifo_grow (AVFifoBuffer *f, unsigned int additional_space)
 Enlarge an AVFifoBuffer. More...
 
void av_fifo_drain (AVFifoBuffer *f, int size)
 Read and discard the specified amount of data from an AVFifoBuffer. More...
 
static uint8_t * av_fifo_peek2 (const AVFifoBuffer *f, int offs)
 Return a pointer to the data stored in a FIFO buffer at a certain offset. More...
 
void av_fifo_drain2 (AVFifo *f, size_t size)
 Discard the specified amount of data from an AVFifo. More...
 
int av_fifo_read (AVFifo *f, void *buf, size_t nb_elems)
 Read data from a FIFO. More...
 
int av_fifo_grow2 (AVFifo *f, size_t inc)
 Enlarge an AVFifo. More...
 
size_t av_fifo_can_read (const AVFifo *f)
 Free an AVFifo and reset pointer to NULL. More...
 
size_t av_fifo_can_write (const AVFifo *f)
 
void av_fifo_freep2 (AVFifo **f)
 
int av_fifo_write (AVFifo *f, const void *buf, size_t nb_elems)
 Write data into a FIFO. More...
 
AVFifoav_fifo_alloc2 (size_t elems, size_t elem_size, unsigned int flags)
 Allocate and initialize an AVFifo with a given element size. More...
 

Detailed Description

a very simple circular buffer FIFO implementation

Definition in file fifo.h.

Macro Definition Documentation

◆ AV_FIFO_FLAG_AUTO_GROW

#define AV_FIFO_FLAG_AUTO_GROW   (1 << 0)

Definition at line 236 of file fifo.h.

Typedef Documentation

◆ AVFifo

typedef struct AVFifo AVFifo

Definition at line 30 of file fifo.h.

◆ AVFifoCB

typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems)

Definition at line 44 of file fifo.h.

Function Documentation

◆ av_fifo_alloc()

AVFifoBuffer* av_fifo_alloc ( unsigned int  size)

Initialize an AVFifoBuffer.

Parameters
sizeof FIFO
Returns
AVFifoBuffer or NULL in case of memory allocation failure

◆ av_fifo_alloc_array()

AVFifoBuffer* av_fifo_alloc_array ( size_t  nmemb,
size_t  size 
)

Initialize an AVFifoBuffer.

Parameters
nmembnumber of elements
sizesize of the single element
Returns
AVFifoBuffer or NULL in case of memory allocation failure

◆ av_fifo_free()

void av_fifo_free ( AVFifoBuffer f)

Free an AVFifoBuffer.

Parameters
fAVFifoBuffer to free

◆ av_fifo_freep()

void av_fifo_freep ( AVFifoBuffer **  f)

Free an AVFifoBuffer and reset pointer to NULL.

Parameters
fAVFifoBuffer to free

◆ av_fifo_reset()

void av_fifo_reset ( AVFifoBuffer f)

Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.

Parameters
fAVFifoBuffer to reset

◆ av_fifo_size()

int av_fifo_size ( const AVFifoBuffer f)

Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from it.

Parameters
fAVFifoBuffer to read from
Returns
size

◆ av_fifo_space()

int av_fifo_space ( const AVFifoBuffer f)

Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write into it.

Parameters
fAVFifoBuffer to write into
Returns
size

◆ av_fifo_generic_peek_at()

int av_fifo_generic_peek_at ( AVFifoBuffer f,
void *  dest,
int  offset,
int  buf_size,
void(*)(void *, void *, int)  func 
)

Feed data at specific position from an AVFifoBuffer to a user-supplied callback.

Similar as av_fifo_gereric_read but without discarding data.

Parameters
fAVFifoBuffer to read from
offsetoffset from current read position
buf_sizenumber of bytes to read
funcgeneric read function
destdata destination

◆ av_fifo_generic_peek()

int av_fifo_generic_peek ( AVFifoBuffer f,
void *  dest,
int  buf_size,
void(*)(void *, void *, int)  func 
)

Feed data from an AVFifoBuffer to a user-supplied callback.

Similar as av_fifo_gereric_read but without discarding data.

Parameters
fAVFifoBuffer to read from
buf_sizenumber of bytes to read
funcgeneric read function
destdata destination

◆ av_fifo_generic_read()

int av_fifo_generic_read ( AVFifoBuffer f,
void *  dest,
int  buf_size,
void(*)(void *, void *, int)  func 
)

Feed data from an AVFifoBuffer to a user-supplied callback.

Parameters
fAVFifoBuffer to read from
buf_sizenumber of bytes to read
funcgeneric read function
destdata destination

◆ av_fifo_generic_write()

int av_fifo_generic_write ( AVFifoBuffer f,
void *  src,
int  size,
int(*)(void *, void *, int)  func 
)

Feed data from a user-supplied callback to an AVFifoBuffer.

Parameters
fAVFifoBuffer to write to
srcdata source; non-const since it may be used as a modifiable context by the function defined in func
sizenumber of bytes to write
funcgeneric write function; the first parameter is src, the second is dest_buf, the third is dest_buf_size. func must return the number of bytes written to dest_buf, or <= 0 to indicate no more data available to write. If func is NULL, src is interpreted as a simple byte array for source data.
Returns
the number of bytes written to the FIFO

◆ av_fifo_realloc2()

int av_fifo_realloc2 ( AVFifoBuffer f,
unsigned int  size 
)

Resize an AVFifoBuffer.

In case of reallocation failure, the old FIFO is kept unchanged.

Parameters
fAVFifoBuffer to resize
sizenew AVFifoBuffer size in bytes
Returns
<0 for failure, >=0 otherwise

◆ av_fifo_grow()

int av_fifo_grow ( AVFifoBuffer f,
unsigned int  additional_space 
)

Enlarge an AVFifoBuffer.

In case of reallocation failure, the old FIFO is kept unchanged. The new fifo size may be larger than the requested size.

Parameters
fAVFifoBuffer to resize
additional_spacethe amount of space in bytes to allocate in addition to av_fifo_size()
Returns
<0 for failure, >=0 otherwise

◆ av_fifo_drain()

void av_fifo_drain ( AVFifoBuffer f,
int  size 
)

Read and discard the specified amount of data from an AVFifoBuffer.

Parameters
fAVFifoBuffer to read from
sizeamount of data to read in bytes

◆ av_fifo_peek2()

static uint8_t* av_fifo_peek2 ( const AVFifoBuffer f,
int  offs 
)
inlinestatic

Return a pointer to the data stored in a FIFO buffer at a certain offset.

The FIFO buffer is not modified.

Parameters
fAVFifoBuffer to peek at, f must be non-NULL
offsan offset in bytes, its absolute value must be less than the used buffer size or the returned pointer will point outside to the buffer data. The used buffer size can be checked with av_fifo_size().

Definition at line 170 of file fifo.h.

◆ av_fifo_drain2()

void av_fifo_drain2 ( AVFifo f,
size_t  size 
)

Discard the specified amount of data from an AVFifo.

Parameters
sizenumber of elements to discard, MUST NOT be larger than av_fifo_can_read(f)

◆ av_fifo_read()

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.

Parameters
fthe FIFO buffer
bufBuffer to store the data. nb_elems * av_fifo_elem_size(f) bytes will be written into buf on success.
nb_elemsnumber of elements to read from FIFO
Returns
a non-negative number on success, a negative error code on failure

◆ av_fifo_grow2()

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.

Parameters
fAVFifo to resize
incnumber of elements to allocate for, in addition to the current allocated size
Returns
a non-negative number on success, a negative error code on failure

◆ av_fifo_can_read()

size_t av_fifo_can_read ( const AVFifo f)

Free an AVFifo and reset pointer to NULL.

Parameters
fPointer to an AVFifo to free. *f == NULL is allowed.
Returns
number of elements available for reading from the given FIFO.

◆ av_fifo_can_write()

size_t av_fifo_can_write ( const AVFifo f)
Returns
Number of elements that can be written into the given FIFO without growing it.

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.

◆ av_fifo_freep2()

void av_fifo_freep2 ( AVFifo **  f)

◆ av_fifo_write()

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).

Parameters
fthe FIFO buffer
bufData to be written. nb_elems * av_fifo_elem_size(f) bytes will be read from buf on success.
nb_elemsnumber of elements to write into FIFO
Returns
a non-negative number on success, a negative error code on failure

◆ av_fifo_alloc2()

AVFifo* av_fifo_alloc2 ( size_t  elems,
size_t  elem_size,
unsigned int  flags 
)

Allocate and initialize an AVFifo with a given element size.

Parameters
elemsinitial number of elements that can be stored in the FIFO
elem_sizeSize in bytes of a single element. Further operations on the returned FIFO will implicitly use this element size.
flagsa combination of AV_FIFO_FLAG_*
Returns
newly-allocated AVFifo on success, a negative error code on failure