2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVUTIL_CONTAINER_FIFO_H
20 #define AVUTIL_CONTAINER_FIFO_H
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.
29 typedef struct AVContainerFifo AVContainerFifo
;
31 enum AVContainerFifoFlags
{
33 * Signal to av_container_fifo_write() that it should make a new reference
34 * to data in src rather than consume its contents.
36 * @note you must handle this flag manually in your own fifo_transfer()
39 AV_CONTAINER_FIFO_FLAG_REF
= (1 << 0),
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.
46 AV_CONTAINER_FIFO_FLAG_USER
= (1 << 16),
50 * Allocate a new AVContainerFifo for the container type defined by provided
53 * @param opaque user data that will be passed to the callbacks provided to this
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
62 * @return newly allocated AVContainerFifo, or NULL on failure
65 av_container_fifo_alloc(void *opaque
,
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
),
73 * Allocate an AVContainerFifo instance for AVFrames.
75 * @param flags currently unused
77 AVContainerFifo
*av_container_fifo_alloc_avframe(unsigned flags
);
80 * Free a AVContainerFifo and everything in it.
82 void av_container_fifo_free(AVContainerFifo
**cf
);
85 * Write the contents of obj to the FIFO.
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.
90 int av_container_fifo_write(AVContainerFifo
*cf
, void *obj
, unsigned flags
);
93 * Read the next available object from the FIFO into obj.
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.
98 int av_container_fifo_read(AVContainerFifo
*cf
, void *obj
, unsigned flags
);
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
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().
112 * @retval 0 success, a pointer was written into pobj
113 * @retval AVERROR(EINVAL) invalid offset value
115 int av_container_fifo_peek(AVContainerFifo
*cf
, void **pobj
, size_t offset
);
118 * Discard the specified number of elements from the FIFO.
120 * @param nb_elems number of elements to discard, MUST NOT be larger than
121 * av_fifo_can_read(f)
123 void av_container_fifo_drain(AVContainerFifo
*cf
, size_t nb_elems
);
126 * @return number of objects available for reading
128 size_t av_container_fifo_can_read(const AVContainerFifo
*cf
);
130 #endif // AVCODEC_CONTAINER_FIFO_H