Path: blob/a-new-beginning/libavutil.xcframework/ios-arm64-simulator/libavutil.framework/Headers/fifo.h
2 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718/**19* @file20* @ingroup lavu_fifo21* A generic FIFO API22*/2324#ifndef AVUTIL_FIFO_H25#define AVUTIL_FIFO_H2627#include <stddef.h>28#include <stdint.h>2930#include "attributes.h"31#include "version.h"3233/**34* @defgroup lavu_fifo AVFifo35* @ingroup lavu_data36*37* @{38* A generic FIFO API39*/4041typedef struct AVFifo AVFifo;4243/**44* Callback for writing or reading from a FIFO, passed to (and invoked from) the45* av_fifo_*_cb() functions. It may be invoked multiple times from a single46* av_fifo_*_cb() call and may process less data than the maximum size indicated47* by nb_elems.48*49* @param opaque the opaque pointer provided to the av_fifo_*_cb() function50* @param buf the buffer for reading or writing the data, depending on which51* av_fifo_*_cb function is called52* @param nb_elems On entry contains the maximum number of elements that can be53* read from / written into buf. On success, the callback should54* update it to contain the number of elements actually written.55*56* @return 0 on success, a negative error code on failure (will be returned from57* the invoking av_fifo_*_cb() function)58*/59typedef int AVFifoCB(void *opaque, void *buf, size_t *nb_elems);6061/**62* Automatically resize the FIFO on writes, so that the data fits. This63* automatic resizing happens up to a limit that can be modified with64* av_fifo_auto_grow_limit().65*/66#define AV_FIFO_FLAG_AUTO_GROW (1 << 0)6768/**69* Allocate and initialize an AVFifo with a given element size.70*71* @param elems initial number of elements that can be stored in the FIFO72* @param elem_size Size in bytes of a single element. Further operations on73* the returned FIFO will implicitly use this element size.74* @param flags a combination of AV_FIFO_FLAG_*75*76* @return newly-allocated AVFifo on success, a negative error code on failure77*/78AVFifo *av_fifo_alloc2(size_t elems, size_t elem_size,79unsigned int flags);8081/**82* @return Element size for FIFO operations. This element size is set at83* FIFO allocation and remains constant during its lifetime84*/85size_t av_fifo_elem_size(const AVFifo *f);8687/**88* Set the maximum size (in elements) to which the FIFO can be resized89* automatically. Has no effect unless AV_FIFO_FLAG_AUTO_GROW is used.90*/91void av_fifo_auto_grow_limit(AVFifo *f, size_t max_elems);9293/**94* @return number of elements available for reading from the given FIFO.95*/96size_t av_fifo_can_read(const AVFifo *f);9798/**99* @return Number of elements that can be written into the given FIFO without100* growing it.101*102* In other words, this number of elements or less is guaranteed to fit103* into the FIFO. More data may be written when the104* AV_FIFO_FLAG_AUTO_GROW flag was specified at FIFO creation, but this105* may involve memory allocation, which can fail.106*/107size_t av_fifo_can_write(const AVFifo *f);108109/**110* Enlarge an AVFifo.111*112* On success, the FIFO will be large enough to hold exactly113* inc + av_fifo_can_read() + av_fifo_can_write()114* elements. In case of failure, the old FIFO is kept unchanged.115*116* @param f AVFifo to resize117* @param inc number of elements to allocate for, in addition to the current118* allocated size119* @return a non-negative number on success, a negative error code on failure120*/121int av_fifo_grow2(AVFifo *f, size_t inc);122123/**124* Write data into a FIFO.125*126* In case nb_elems > av_fifo_can_write(f) and the AV_FIFO_FLAG_AUTO_GROW flag127* was not specified at FIFO creation, nothing is written and an error128* is returned.129*130* Calling function is guaranteed to succeed if nb_elems <= av_fifo_can_write(f).131*132* @param f the FIFO buffer133* @param buf Data to be written. nb_elems * av_fifo_elem_size(f) bytes will be134* read from buf on success.135* @param nb_elems number of elements to write into FIFO136*137* @return a non-negative number on success, a negative error code on failure138*/139int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems);140141/**142* Write data from a user-provided callback into a FIFO.143*144* @param f the FIFO buffer145* @param read_cb Callback supplying the data to the FIFO. May be called146* multiple times.147* @param opaque opaque user data to be provided to read_cb148* @param nb_elems Should point to the maximum number of elements that can be149* written. Will be updated to contain the number of elements150* actually written.151*152* @return non-negative number on success, a negative error code on failure153*/154int av_fifo_write_from_cb(AVFifo *f, AVFifoCB read_cb,155void *opaque, size_t *nb_elems);156157/**158* Read data from a FIFO.159*160* In case nb_elems > av_fifo_can_read(f), nothing is read and an error161* is returned.162*163* @param f the FIFO buffer164* @param buf Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes165* will be written into buf on success.166* @param nb_elems number of elements to read from FIFO167*168* @return a non-negative number on success, a negative error code on failure169*/170int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems);171172/**173* Feed data from a FIFO into a user-provided callback.174*175* @param f the FIFO buffer176* @param write_cb Callback the data will be supplied to. May be called177* multiple times.178* @param opaque opaque user data to be provided to write_cb179* @param nb_elems Should point to the maximum number of elements that can be180* read. Will be updated to contain the total number of elements181* actually sent to the callback.182*183* @return non-negative number on success, a negative error code on failure184*/185int av_fifo_read_to_cb(AVFifo *f, AVFifoCB write_cb,186void *opaque, size_t *nb_elems);187188/**189* Read data from a FIFO without modifying FIFO state.190*191* Returns an error if an attempt is made to peek to nonexistent elements192* (i.e. if offset + nb_elems is larger than av_fifo_can_read(f)).193*194* @param f the FIFO buffer195* @param buf Buffer to store the data. nb_elems * av_fifo_elem_size(f) bytes196* will be written into buf.197* @param nb_elems number of elements to read from FIFO198* @param offset number of initial elements to skip.199*200* @return a non-negative number on success, a negative error code on failure201*/202int av_fifo_peek(AVFifo *f, void *buf, size_t nb_elems, size_t offset);203204/**205* Feed data from a FIFO into a user-provided callback.206*207* @param f the FIFO buffer208* @param write_cb Callback the data will be supplied to. May be called209* multiple times.210* @param opaque opaque user data to be provided to write_cb211* @param nb_elems Should point to the maximum number of elements that can be212* read. Will be updated to contain the total number of elements213* actually sent to the callback.214* @param offset number of initial elements to skip; offset + *nb_elems must not215* be larger than av_fifo_can_read(f).216*217* @return a non-negative number on success, a negative error code on failure218*/219int av_fifo_peek_to_cb(AVFifo *f, AVFifoCB write_cb, void *opaque,220size_t *nb_elems, size_t offset);221222/**223* Discard the specified amount of data from an AVFifo.224* @param size number of elements to discard, MUST NOT be larger than225* av_fifo_can_read(f)226*/227void av_fifo_drain2(AVFifo *f, size_t size);228229/*230* Empty the AVFifo.231* @param f AVFifo to reset232*/233void av_fifo_reset2(AVFifo *f);234235/**236* Free an AVFifo and reset pointer to NULL.237* @param f Pointer to an AVFifo to free. *f == NULL is allowed.238*/239void av_fifo_freep2(AVFifo **f);240241242#if FF_API_FIFO_OLD_API243typedef struct AVFifoBuffer {244uint8_t *buffer;245uint8_t *rptr, *wptr, *end;246uint32_t rndx, wndx;247} AVFifoBuffer;248249/**250* Initialize an AVFifoBuffer.251* @param size of FIFO252* @return AVFifoBuffer or NULL in case of memory allocation failure253* @deprecated use av_fifo_alloc2()254*/255attribute_deprecated256AVFifoBuffer *av_fifo_alloc(unsigned int size);257258/**259* Initialize an AVFifoBuffer.260* @param nmemb number of elements261* @param size size of the single element262* @return AVFifoBuffer or NULL in case of memory allocation failure263* @deprecated use av_fifo_alloc2()264*/265attribute_deprecated266AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);267268/**269* Free an AVFifoBuffer.270* @param f AVFifoBuffer to free271* @deprecated use the AVFifo API with av_fifo_freep2()272*/273attribute_deprecated274void av_fifo_free(AVFifoBuffer *f);275276/**277* Free an AVFifoBuffer and reset pointer to NULL.278* @param f AVFifoBuffer to free279* @deprecated use the AVFifo API with av_fifo_freep2()280*/281attribute_deprecated282void av_fifo_freep(AVFifoBuffer **f);283284/**285* Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.286* @param f AVFifoBuffer to reset287* @deprecated use av_fifo_reset2() with the new AVFifo-API288*/289attribute_deprecated290void av_fifo_reset(AVFifoBuffer *f);291292/**293* Return the amount of data in bytes in the AVFifoBuffer, that is the294* amount of data you can read from it.295* @param f AVFifoBuffer to read from296* @return size297* @deprecated use av_fifo_can_read() with the new AVFifo-API298*/299attribute_deprecated300int av_fifo_size(const AVFifoBuffer *f);301302/**303* Return the amount of space in bytes in the AVFifoBuffer, that is the304* amount of data you can write into it.305* @param f AVFifoBuffer to write into306* @return size307* @deprecated use av_fifo_can_write() with the new AVFifo-API308*/309attribute_deprecated310int av_fifo_space(const AVFifoBuffer *f);311312/**313* Feed data at specific position from an AVFifoBuffer to a user-supplied callback.314* Similar as av_fifo_gereric_read but without discarding data.315* @param f AVFifoBuffer to read from316* @param offset offset from current read position317* @param buf_size number of bytes to read318* @param func generic read function319* @param dest data destination320*321* @return a non-negative number on success, a negative error code on failure322*323* @deprecated use the new AVFifo-API with av_fifo_peek() when func == NULL,324* av_fifo_peek_to_cb() otherwise325*/326attribute_deprecated327int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int buf_size, void (*func)(void*, void*, int));328329/**330* Feed data from an AVFifoBuffer to a user-supplied callback.331* Similar as av_fifo_gereric_read but without discarding data.332* @param f AVFifoBuffer to read from333* @param buf_size number of bytes to read334* @param func generic read function335* @param dest data destination336*337* @return a non-negative number on success, a negative error code on failure338*339* @deprecated use the new AVFifo-API with av_fifo_peek() when func == NULL,340* av_fifo_peek_to_cb() otherwise341*/342attribute_deprecated343int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));344345/**346* Feed data from an AVFifoBuffer to a user-supplied callback.347* @param f AVFifoBuffer to read from348* @param buf_size number of bytes to read349* @param func generic read function350* @param dest data destination351*352* @return a non-negative number on success, a negative error code on failure353*354* @deprecated use the new AVFifo-API with av_fifo_read() when func == NULL,355* av_fifo_read_to_cb() otherwise356*/357attribute_deprecated358int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));359360/**361* Feed data from a user-supplied callback to an AVFifoBuffer.362* @param f AVFifoBuffer to write to363* @param src data source; non-const since it may be used as a364* modifiable context by the function defined in func365* @param size number of bytes to write366* @param func generic write function; the first parameter is src,367* the second is dest_buf, the third is dest_buf_size.368* func must return the number of bytes written to dest_buf, or <= 0 to369* indicate no more data available to write.370* If func is NULL, src is interpreted as a simple byte array for source data.371* @return the number of bytes written to the FIFO or a negative error code on failure372*373* @deprecated use the new AVFifo-API with av_fifo_write() when func == NULL,374* av_fifo_write_from_cb() otherwise375*/376attribute_deprecated377int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));378379/**380* Resize an AVFifoBuffer.381* In case of reallocation failure, the old FIFO is kept unchanged.382*383* @param f AVFifoBuffer to resize384* @param size new AVFifoBuffer size in bytes385* @return <0 for failure, >=0 otherwise386*387* @deprecated use the new AVFifo-API with av_fifo_grow2() to increase FIFO size,388* decreasing FIFO size is not supported389*/390attribute_deprecated391int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);392393/**394* Enlarge an AVFifoBuffer.395* In case of reallocation failure, the old FIFO is kept unchanged.396* The new fifo size may be larger than the requested size.397*398* @param f AVFifoBuffer to resize399* @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()400* @return <0 for failure, >=0 otherwise401*402* @deprecated use the new AVFifo-API with av_fifo_grow2(); note that unlike403* this function it adds to the allocated size, rather than to the used size404*/405attribute_deprecated406int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);407408/**409* Read and discard the specified amount of data from an AVFifoBuffer.410* @param f AVFifoBuffer to read from411* @param size amount of data to read in bytes412*413* @deprecated use the new AVFifo-API with av_fifo_drain2()414*/415attribute_deprecated416void av_fifo_drain(AVFifoBuffer *f, int size);417418#if FF_API_FIFO_PEEK2419/**420* Return a pointer to the data stored in a FIFO buffer at a certain offset.421* The FIFO buffer is not modified.422*423* @param f AVFifoBuffer to peek at, f must be non-NULL424* @param offs an offset in bytes, its absolute value must be less425* than the used buffer size or the returned pointer will426* point outside to the buffer data.427* The used buffer size can be checked with av_fifo_size().428* @deprecated use the new AVFifo-API with av_fifo_peek() or av_fifo_peek_to_cb()429*/430attribute_deprecated431static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)432{433uint8_t *ptr = f->rptr + offs;434if (ptr >= f->end)435ptr = f->buffer + (ptr - f->end);436else if (ptr < f->buffer)437ptr = f->end - (f->buffer - ptr);438return ptr;439}440#endif441#endif442443/**444* @}445*/446447#endif /* AVUTIL_FIFO_H */448449450