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
21 * A very simple circular buffer FIFO implementation.
27 typedef struct AVFifoBuffer
{
29 uint8_t *rptr
, *wptr
, *end
;
33 * Initializes a FIFO *.
34 * @param *f FIFO buffer
36 * @return <0 for failure >=0 otherwise
38 int av_fifo_init(AVFifoBuffer
*f
, int size
);
42 * @param *f FIFO buffer
44 void av_fifo_free(AVFifoBuffer
*f
);
47 * Returns the size of a FIFO *.
48 * @param *f FIFO buffer
51 int av_fifo_size(AVFifoBuffer
*f
);
54 * Reads the data from the FIFO *.
55 * @param *f FIFO buffer
56 * @param *buf data destination
57 * @param buf_size data size
58 * @return -1 if not enough data
60 int av_fifo_read(AVFifoBuffer
*f
, uint8_t *buf
, int buf_size
);
63 * Reads the data from the FIFO *.
64 * @param *f FIFO buffer
65 * @param buf_size data size
66 * @param *func generic read function
67 * @param *dest data destination
68 * @return -1 if not enough data
70 int av_fifo_generic_read(AVFifoBuffer
*f
, int buf_size
, void (*func
)(void*, void*, int), void* dest
);
73 * Writes the data in the FIFO *.
74 * @param *f FIFO buffer
75 * @param *buf data source
76 * @param size data size
78 void av_fifo_write(AVFifoBuffer
*f
, const uint8_t *buf
, int size
);
82 * @param *f FIFO buffer
83 * @param size data size
85 void av_fifo_realloc(AVFifoBuffer
*f
, unsigned int size
);
88 * Discards the data from the FIFO *.
89 * @param *f FIFO buffer
90 * @param size data size
92 void av_fifo_drain(AVFifoBuffer
*f
, int size
);
95 * Returns a pointer with circular offset from FIFO's read pointer.
96 * @param *f FIFO buffer
98 * @return ptr=rptr+offs if rptr+offs<end else rptr+offs -(end-begin)
100 static inline uint8_t av_fifo_peek(AVFifoBuffer
*f
, int offs
)
102 uint8_t *ptr
= f
->rptr
+ offs
;
104 ptr
-= f
->end
- f
->buffer
;