doxygen: drop another pointless star from pointer variable name
[libav.git] / libavutil / fifo.h
CommitLineData
f5a90186 1/*
2912e87a 2 * This file is part of Libav.
f5a90186 3 *
2912e87a 4 * Libav is free software; you can redistribute it and/or
f5a90186
DB
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 *
2912e87a 9 * Libav is distributed in the hope that it will be useful,
f5a90186
DB
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
2912e87a 15 * License along with Libav; if not, write to the Free Software
f5a90186
DB
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
1faf7dc8 19/**
ba87f080 20 * @file
89c9ff50 21 * a very simple circular buffer FIFO implementation
1faf7dc8
DB
22 */
23
98790382
SS
24#ifndef AVUTIL_FIFO_H
25#define AVUTIL_FIFO_H
f5a478f6 26
99545457 27#include <stdint.h>
f2011ed2 28#include "avutil.h"
99545457 29
f5a478f6
RS
30typedef struct AVFifoBuffer {
31 uint8_t *buffer;
32 uint8_t *rptr, *wptr, *end;
0a71e78c 33 uint32_t rndx, wndx;
f5a478f6
RS
34} AVFifoBuffer;
35
1faf7dc8 36/**
49bd8e4b 37 * Initialize an AVFifoBuffer.
1faf7dc8 38 * @param size of FIFO
b9bd6589 39 * @return AVFifoBuffer or NULL in case of memory allocation failure
1faf7dc8 40 */
41dd680d 41AVFifoBuffer *av_fifo_alloc(unsigned int size);
1faf7dc8
DB
42
43/**
49bd8e4b 44 * Free an AVFifoBuffer.
0138a8de 45 * @param f AVFifoBuffer to free
1faf7dc8 46 */
f5a478f6 47void av_fifo_free(AVFifoBuffer *f);
1faf7dc8
DB
48
49/**
49bd8e4b 50 * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
0138a8de 51 * @param f AVFifoBuffer to reset
32b936d0
RD
52 */
53void av_fifo_reset(AVFifoBuffer *f);
54
55/**
49bd8e4b 56 * Return the amount of data in bytes in the AVFifoBuffer, that is the
82ffe191 57 * amount of data you can read from it.
0138a8de 58 * @param f AVFifoBuffer to read from
1faf7dc8
DB
59 * @return size
60 */
f5a478f6 61int av_fifo_size(AVFifoBuffer *f);
1faf7dc8
DB
62
63/**
49bd8e4b 64 * Return the amount of space in bytes in the AVFifoBuffer, that is the
7b09db35 65 * amount of data you can write into it.
0138a8de 66 * @param f AVFifoBuffer to write into
7b09db35
OG
67 * @return size
68 */
69int av_fifo_space(AVFifoBuffer *f);
70
71/**
49bd8e4b 72 * Feed data from an AVFifoBuffer to a user-supplied callback.
0138a8de 73 * @param f AVFifoBuffer to read from
82ffe191 74 * @param buf_size number of bytes to read
0138a8de
DB
75 * @param func generic read function
76 * @param dest data destination
1faf7dc8 77 */
3898eed8 78int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
1faf7dc8 79
49cec199 80/**
49bd8e4b 81 * Feed data from a user-supplied callback to an AVFifoBuffer.
0138a8de
DB
82 * @param f AVFifoBuffer to write to
83 * @param src data source; non-const since it may be used as a
33147993 84 * modifiable context by the function defined in func
49cec199 85 * @param size number of bytes to write
0138a8de 86 * @param func generic write function; the first parameter is src,
89c9ff50 87 * the second is dest_buf, the third is dest_buf_size.
49cec199
BA
88 * func must return the number of bytes written to dest_buf, or <= 0 to
89 * indicate no more data available to write.
95c76e11 90 * If func is NULL, src is interpreted as a simple byte array for source data.
89c9ff50 91 * @return the number of bytes written to the FIFO
49cec199 92 */
95c76e11 93int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
1faf7dc8 94
1faf7dc8 95/**
49bd8e4b 96 * Resize an AVFifoBuffer.
0138a8de 97 * @param f AVFifoBuffer to resize
8257b835 98 * @param size new AVFifoBuffer size in bytes
89c9ff50 99 * @return <0 for failure, >=0 otherwise
8257b835
SS
100 */
101int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
102
103/**
49bd8e4b 104 * Read and discard the specified amount of data from an AVFifoBuffer.
0138a8de 105 * @param f AVFifoBuffer to read from
82ffe191 106 * @param size amount of data to read in bytes
1faf7dc8 107 */
f5a478f6
RS
108void av_fifo_drain(AVFifoBuffer *f, int size);
109
f2011ed2
SS
110/**
111 * Return a pointer to the data stored in a FIFO buffer at a certain offset.
112 * The FIFO buffer is not modified.
113 *
fa19c5c2 114 * @param f AVFifoBuffer to peek at, f must be non-NULL
f2011ed2
SS
115 * @param offs an offset in bytes, its absolute value must be less
116 * than the used buffer size or the returned pointer will
117 * point outside to the buffer data.
118 * The used buffer size can be checked with av_fifo_size().
119 */
120static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
f5a478f6
RS
121{
122 uint8_t *ptr = f->rptr + offs;
123 if (ptr >= f->end)
f2011ed2
SS
124 ptr = f->buffer + (ptr - f->end);
125 else if (ptr < f->buffer)
126 ptr = f->end - (f->buffer - ptr);
127 return ptr;
f5a478f6 128}
f2011ed2
SS
129
130#if FF_API_AV_FIFO_PEEK
131/**
132 * @deprecated Use av_fifo_peek2() instead.
133 */
134attribute_deprecated
135static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
136{
137 return *av_fifo_peek2(f, offs);
138}
139#endif
140
98790382 141#endif /* AVUTIL_FIFO_H */