Go to the documentation of this file.
33 #define AUTO_GROW_DEFAULT_BYTES (1024 * 1024)
67 f->nb_elems = nb_elems;
68 f->elem_size = elem_size;
79 f->auto_grow_limit = max_elems;
89 if (
f->offset_w <=
f->offset_r && !
f->is_empty)
90 return f->nb_elems -
f->offset_r +
f->offset_w;
91 return f->offset_w -
f->offset_r;
103 if (inc > SIZE_MAX -
f->nb_elems)
113 if (
f->offset_w <=
f->offset_r && !
f->is_empty) {
115 memcpy(
tmp +
f->nb_elems *
f->elem_size,
tmp,
copy *
f->elem_size);
116 if (copy < f->offset_w) {
118 (
f->offset_w -
copy) *
f->elem_size);
121 f->offset_w =
copy == inc ? 0 :
f->nb_elems +
copy;
132 const size_t need_grow = to_write > can_write ? to_write - can_write : 0;
138 can_grow =
f->auto_grow_limit >
f->nb_elems ?
139 f->auto_grow_limit -
f->nb_elems : 0;
142 const size_t inc = (need_grow < can_grow / 2 ) ? need_grow * 2 : can_grow;
152 size_t to_write = *nb_elems;
160 offset_w =
f->offset_w;
162 while (to_write > 0) {
163 size_t len =
FFMIN(
f->nb_elems - offset_w, to_write);
164 uint8_t *wptr =
f->buffer + offset_w *
f->elem_size;
171 memcpy(wptr, buf,
len *
f->elem_size);
172 buf +=
len *
f->elem_size;
175 if (offset_w >=
f->nb_elems)
179 f->offset_w = offset_w;
181 if (*nb_elems != to_write)
183 *nb_elems -= to_write;
194 void *opaque,
size_t *nb_elems)
202 size_t to_read = *nb_elems;
203 size_t offset_r =
f->offset_r;
212 if (offset_r >=
f->nb_elems -
offset)
213 offset_r -=
f->nb_elems -
offset;
217 while (to_read > 0) {
218 size_t len =
FFMIN(
f->nb_elems - offset_r, to_read);
219 uint8_t *rptr =
f->buffer + offset_r *
f->elem_size;
226 memcpy(buf, rptr,
len *
f->elem_size);
227 buf +=
len *
f->elem_size;
230 if (offset_r >=
f->nb_elems)
235 *nb_elems -= to_read;
248 void *opaque,
size_t *nb_elems)
261 size_t *nb_elems,
size_t offset)
271 if (cur_size ==
size)
274 if (
f->offset_r >=
f->nb_elems -
size)
275 f->offset_r -=
f->nb_elems -
size;
282 f->offset_r =
f->offset_w = 0;
295 #if FF_API_FIFO_OLD_API
297 #define OLD_FIFO_SIZE_MAX (size_t)FFMIN3(INT_MAX, UINT32_MAX, SIZE_MAX)
316 f->end =
f->buffer + nmemb *
size;
344 f->wptr =
f->rptr =
f->buffer;
345 f->wndx =
f->rndx = 0;
350 return (uint32_t)(
f->wndx -
f->rndx);
360 unsigned int old_size =
f->end -
f->buffer;
365 if (old_size < new_size) {
366 size_t offset_r =
f->rptr -
f->buffer;
367 size_t offset_w =
f->wptr -
f->buffer;
378 const size_t copy =
FFMIN(new_size - old_size, offset_w);
380 if (
copy < offset_w) {
384 offset_w = old_size +
copy;
388 f->end =
f->buffer + new_size;
389 f->rptr =
f->buffer + offset_r;
390 f->wptr =
f->buffer + offset_w;
397 unsigned int old_size =
f->end -
f->buffer;
411 int (*
func)(
void *,
void *,
int))
414 uint32_t wndx=
f->wndx;
415 uint8_t *wptr=
f->wptr;
443 uint8_t *rptr =
f->rptr;
449 rptr +=
offset - (
f->end -
f->buffer);
453 while (buf_size > 0) {
457 rptr -=
f->end -
f->buffer;
463 memcpy(dest, rptr,
len);
464 dest = (uint8_t *)dest +
len;
475 void (*
func)(
void *,
void *,
int))
481 void (*
func)(
void *,
void *,
int))
491 memcpy(dest,
f->rptr,
len);
492 dest = (uint8_t *)dest +
len;
496 }
while (buf_size > 0);
505 if (
f->rptr >=
f->end)
506 f->rptr -=
f->end -
f->buffer;
AVFifoBuffer * av_fifo_alloc_array(size_t nmemb, size_t size)
Initialize an AVFifoBuffer.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
#define FF_ENABLE_DEPRECATION_WARNINGS
size_t av_fifo_can_write(const AVFifo *f)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
#define OLD_FIFO_SIZE_MAX
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.
void av_fifo_drain(AVFifoBuffer *f, int size)
Discard data from the FIFO.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_grow2(AVFifo *f, size_t inc)
Enlarge an AVFifo.
int av_fifo_peek_to_cb(AVFifo *f, AVFifoCB write_cb, void *opaque, size_t *nb_elems, size_t offset)
Feed data from a FIFO into a user-provided callback.
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() function...
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
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.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
Enlarge an AVFifoBuffer.
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.
size_t av_fifo_can_read(const AVFifo *f)
size_t av_fifo_elem_size(const AVFifo *f)
void av_fifo_reset2(AVFifo *f)
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.
static void copy(const float *p1, float *p2, const int length)
static int read_cb(void *opaque, void *buf, size_t *nb_elems)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define AUTO_GROW_DEFAULT_BYTES
int av_fifo_peek(AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int fifo_write_common(AVFifo *f, const uint8_t *buf, size_t *nb_elems, AVFifoCB read_cb, void *opaque)
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element 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 ...
static int fifo_check_space(AVFifo *f, size_t to_write)
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
#define FF_DISABLE_DEPRECATION_WARNINGS
static int fifo_peek_common(const AVFifo *f, uint8_t *buf, size_t *nb_elems, size_t offset, AVFifoCB write_cb, void *opaque)
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 int...
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.
static int write_cb(void *opaque, void *buf, size_t *nb_elems)
#define flags(name, subs,...)
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
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.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.