FFmpeg
container_fifo.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVUTIL_CONTAINER_FIFO_H
20 #define AVUTIL_CONTAINER_FIFO_H
21 
22 #include <stddef.h>
23 
24 /**
25  * AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable
26  * structs (e.g. AVFrame or AVPacket). AVContainerFifo uses an internal pool of
27  * such containers to avoid allocating and freeing them repeatedly.
28  */
29 typedef struct AVContainerFifo AVContainerFifo;
30 
32  /**
33  * Signal to av_container_fifo_write() that it should make a new reference
34  * to data in src rather than consume its contents.
35  *
36  * @note you must handle this flag manually in your own fifo_transfer()
37  * callback
38  */
40 
41  /**
42  * This and all higher bits in flags may be set to any value by the caller
43  * and are guaranteed to be passed through to the fifo_transfer() callback
44  * and not be interpreted by AVContainerFifo code.
45  */
47 };
48 
49 /**
50  * Allocate a new AVContainerFifo for the container type defined by provided
51  * callbacks.
52  *
53  * @param opaque user data that will be passed to the callbacks provided to this
54  * function
55  * @param container_alloc allocate a new container instance and return a pointer
56  * to it, or NULL on failure
57  * @param container_reset reset the provided container instance to a clean state
58  * @param container_free free the provided container instance
59  * @param fifo_transfer Transfer the contents of container src to dst.
60  * @param flags currently unused
61  *
62  * @return newly allocated AVContainerFifo, or NULL on failure
63  */
66  void* (*container_alloc)(void *opaque),
67  void (*container_reset)(void *opaque, void *obj),
68  void (*container_free) (void *opaque, void *obj),
69  int (*fifo_transfer) (void *opaque, void *dst, void *src, unsigned flags),
70  unsigned flags);
71 
72 /**
73  * Allocate an AVContainerFifo instance for AVFrames.
74  *
75  * @param flags currently unused
76  */
78 
79 /**
80  * Free a AVContainerFifo and everything in it.
81  */
83 
84 /**
85  * Write the contents of obj to the FIFO.
86  *
87  * The fifo_transfer() callback previously provided to av_container_fifo_alloc()
88  * will be called with obj as src in order to perform the actual transfer.
89  */
90 int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags);
91 
92 /**
93  * Read the next available object from the FIFO into obj.
94  *
95  * The fifo_read() callback previously provided to av_container_fifo_alloc()
96  * will be called with obj as dst in order to perform the actual transfer.
97  */
98 int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags);
99 
100 /**
101  * Access objects stored in the FIFO without retrieving them. The
102  * fifo_transfer() callback will NOT be invoked and the FIFO state will not be
103  * modified.
104  *
105  * @param pobj Pointer to the object stored in the FIFO will be written here on
106  * success. The object remains owned by the FIFO and the caller may
107  * only access it as long as the FIFO is not modified.
108  * @param offset Position of the object to retrieve - 0 is the next item that
109  * would be read, 1 the one after, etc. Must be smaller than
110  * av_container_fifo_can_read().
111  *
112  * @retval 0 success, a pointer was written into pobj
113  * @retval AVERROR(EINVAL) invalid offset value
114  */
115 int av_container_fifo_peek(AVContainerFifo *cf, void **pobj, size_t offset);
116 
117 /**
118  * Discard the specified number of elements from the FIFO.
119  *
120  * @param nb_elems number of elements to discard, MUST NOT be larger than
121  * av_fifo_can_read(f)
122  */
123 void av_container_fifo_drain(AVContainerFifo *cf, size_t nb_elems);
124 
125 /**
126  * @return number of objects available for reading
127  */
129 
130 #endif // AVCODEC_CONTAINER_FIFO_H
AV_CONTAINER_FIFO_FLAG_REF
@ AV_CONTAINER_FIFO_FLAG_REF
Signal to av_container_fifo_write() that it should make a new reference to data in src rather than co...
Definition: container_fifo.h:39
av_container_fifo_peek
int av_container_fifo_peek(AVContainerFifo *cf, void **pobj, size_t offset)
Access objects stored in the FIFO without retrieving them.
Definition: container_fifo.c:137
AVContainerFifoFlags
AVContainerFifoFlags
Definition: container_fifo.h:31
AVContainerFifo
AVContainerFifo is a FIFO for "containers" - dynamically allocated reusable structs (e....
Definition: container_fifo.c:27
AVContainerFifo::opaque
void * opaque
Definition: container_fifo.c:31
av_container_fifo_alloc_avframe
AVContainerFifo * av_container_fifo_alloc_avframe(unsigned flags)
Allocate an AVContainerFifo instance for AVFrames.
Definition: container_fifo.c:215
AVContainerFifo::container_alloc
void *(* container_alloc)(void *opaque)
Definition: container_fifo.c:32
AVContainerFifo::container_free
void(* container_free)(void *opaque, void *obj)
Definition: container_fifo.c:34
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_container_fifo_drain
void av_container_fifo_drain(AVContainerFifo *cf, size_t nb_elems)
Discard the specified number of elements from the FIFO.
Definition: container_fifo.c:151
AVContainerFifo::fifo_transfer
int(* fifo_transfer)(void *opaque, void *dst, void *src, unsigned flags)
Definition: container_fifo.c:35
av_container_fifo_write
int av_container_fifo_write(AVContainerFifo *cf, void *obj, unsigned flags)
Write the contents of obj to the FIFO.
Definition: container_fifo.c:162
offset
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
Definition: writing_filters.txt:86
AVContainerFifo::container_reset
void(* container_reset)(void *opaque, void *obj)
Definition: container_fifo.c:33
av_container_fifo_free
void av_container_fifo_free(AVContainerFifo **cf)
Free a AVContainerFifo and everything in it.
Definition: container_fifo.c:101
av_container_fifo_alloc
AVContainerFifo * av_container_fifo_alloc(void *opaque, void *(*container_alloc)(void *opaque), void(*container_reset)(void *opaque, void *obj), void(*container_free)(void *opaque, void *obj), int(*fifo_transfer)(void *opaque, void *dst, void *src, unsigned flags), unsigned flags)
Allocate a new AVContainerFifo for the container type defined by provided callbacks.
Definition: container_fifo.c:64
av_container_fifo_can_read
size_t av_container_fifo_can_read(const AVContainerFifo *cf)
Definition: container_fifo.c:185
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AV_CONTAINER_FIFO_FLAG_USER
@ AV_CONTAINER_FIFO_FLAG_USER
This and all higher bits in flags may be set to any value by the caller and are guaranteed to be pass...
Definition: container_fifo.h:46
src
#define src
Definition: vp8dsp.c:248
av_container_fifo_read
int av_container_fifo_read(AVContainerFifo *cf, void *obj, unsigned flags)
Read the next available object from the FIFO into obj.
Definition: container_fifo.c:122