Path: blob/master/dep/ffmpeg/include/libavcodec/container_fifo.h
5196 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#ifndef AVUTIL_CONTAINER_FIFO_H19#define AVUTIL_CONTAINER_FIFO_H2021#include <stddef.h>2223/**24* AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable25* structs (e.g. AVFrame or AVPacket). AVContainerFifo uses an internal pool of26* such containers to avoid allocating and freeing them repeatedly.27*/28typedef struct AVContainerFifo AVContainerFifo;2930enum AVContainerFifoFlags {31/**32* Signal to av_container_fifo_write() that it should make a new reference33* to data in src rather than consume its contents.34*35* @note you must handle this flag manually in your own fifo_transfer()36* callback37*/38AV_CONTAINER_FIFO_FLAG_REF = (1 << 0),3940/**41* This and all higher bits in flags may be set to any value by the caller42* and are guaranteed to be passed through to the fifo_transfer() callback43* and not be interpreted by AVContainerFifo code.44*/45AV_CONTAINER_FIFO_FLAG_USER = (1 << 16),46};4748/**49* Allocate a new AVContainerFifo for the container type defined by provided50* callbacks.51*52* @param opaque user data that will be passed to the callbacks provided to this53* function54* @param container_alloc allocate a new container instance and return a pointer55* to it, or NULL on failure56* @param container_reset reset the provided container instance to a clean state57* @param container_free free the provided container instance58* @param fifo_transfer Transfer the contents of container src to dst.59* @param flags currently unused60*61* @return newly allocated AVContainerFifo, or NULL on failure62*/63AVContainerFifo*64av_container_fifo_alloc(void *opaque,65void* (*container_alloc)(void *opaque),66void (*container_reset)(void *opaque, void *obj),67void (*container_free) (void *opaque, void *obj),68int (*fifo_transfer) (void *opaque, void *dst, void *src, unsigned flags),69unsigned flags);7071/**72* Allocate an AVContainerFifo instance for AVFrames.73*74* @param flags currently unused75*/76AVContainerFifo *av_container_fifo_alloc_avframe(unsigned flags);7778/**79* Free a AVContainerFifo and everything in it.80*/81void av_container_fifo_free(AVContainerFifo **cf);8283/**84* Write the contents of obj to the FIFO.85*86* The fifo_transfer() callback previously provided to av_container_fifo_alloc()87* will be called with obj as src in order to perform the actual transfer.88*/89int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags);9091/**92* Read the next available object from the FIFO into obj.93*94* The fifo_read() callback previously provided to av_container_fifo_alloc()95* will be called with obj as dst in order to perform the actual transfer.96*/97int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags);9899/**100* Access objects stored in the FIFO without retrieving them. The101* fifo_transfer() callback will NOT be invoked and the FIFO state will not be102* modified.103*104* @param pobj Pointer to the object stored in the FIFO will be written here on105* success. The object remains owned by the FIFO and the caller may106* only access it as long as the FIFO is not modified.107* @param offset Position of the object to retrieve - 0 is the next item that108* would be read, 1 the one after, etc. Must be smaller than109* av_container_fifo_can_read().110*111* @retval 0 success, a pointer was written into pobj112* @retval AVERROR(EINVAL) invalid offset value113*/114int av_container_fifo_peek(AVContainerFifo *cf, void **pobj, size_t offset);115116/**117* Discard the specified number of elements from the FIFO.118*119* @param nb_elems number of elements to discard, MUST NOT be larger than120* av_fifo_can_read(f)121*/122void av_container_fifo_drain(AVContainerFifo *cf, size_t nb_elems);123124/**125* @return number of objects available for reading126*/127size_t av_container_fifo_can_read(const AVContainerFifo *cf);128129#endif // AVCODEC_CONTAINER_FIFO_H130131132