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);
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;
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
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
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.
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.
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.
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 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_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
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_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)
static int inc(int num, int period)
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
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.
static int fifo_check_space(AVFifo *f, size_t to_write)
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
static int fifo_peek_common(const AVFifo *f, uint8_t *buf, size_t *nb_elems, size_t offset, AVFifoCB write_cb, void *opaque)
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.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.