annotate lib/libavutil/fifo.h @ 2553:48708da03b7f

Party Creation UI logic separated from MainMenu
author a.parshin
date Wed, 13 May 2015 02:20:05 +0200
parents 992d2e6f907d
children
rev   line source
2134
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
1 /*
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
2 * This file is part of FFmpeg.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
3 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
4 * FFmpeg is free software; you can redistribute it and/or
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
7 * version 2.1 of the License, or (at your option) any later version.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
8 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
9 * FFmpeg is distributed in the hope that it will be useful,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
12 * Lesser General Public License for more details.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
13 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
15 * License along with FFmpeg; if not, write to the Free Software
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
17 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
18
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
19 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
20 * @file
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
21 * a very simple circular buffer FIFO implementation
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
22 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
23
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
24 #ifndef AVUTIL_FIFO_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
25 #define AVUTIL_FIFO_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
26
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
27 #include <stdint.h>
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
28 #include "avutil.h"
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
29 #include "attributes.h"
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
30
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
31 typedef struct AVFifoBuffer {
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
32 uint8_t *buffer;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
33 uint8_t *rptr, *wptr, *end;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
34 uint32_t rndx, wndx;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
35 } AVFifoBuffer;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
36
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
37 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
38 * Initialize an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
39 * @param size of FIFO
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
40 * @return AVFifoBuffer or NULL in case of memory allocation failure
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
41 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
42 AVFifoBuffer *av_fifo_alloc(unsigned int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
43
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
44 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
45 * Free an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
46 * @param f AVFifoBuffer to free
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
47 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
48 void av_fifo_free(AVFifoBuffer *f);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
49
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
50 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
51 * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
52 * @param f AVFifoBuffer to reset
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
53 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
54 void av_fifo_reset(AVFifoBuffer *f);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
55
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
56 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
57 * Return the amount of data in bytes in the AVFifoBuffer, that is the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
58 * amount of data you can read from it.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
59 * @param f AVFifoBuffer to read from
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
60 * @return size
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
61 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
62 int av_fifo_size(AVFifoBuffer *f);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
63
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
64 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
65 * Return the amount of space in bytes in the AVFifoBuffer, that is the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
66 * amount of data you can write into it.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
67 * @param f AVFifoBuffer to write into
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
68 * @return size
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
69 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
70 int av_fifo_space(AVFifoBuffer *f);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
71
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
72 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
73 * Feed data from an AVFifoBuffer to a user-supplied callback.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
74 * @param f AVFifoBuffer to read from
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
75 * @param buf_size number of bytes to read
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
76 * @param func generic read function
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
77 * @param dest data destination
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
78 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
79 int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int));
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
80
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
81 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
82 * Feed data from a user-supplied callback to an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
83 * @param f AVFifoBuffer to write to
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
84 * @param src data source; non-const since it may be used as a
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
85 * modifiable context by the function defined in func
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
86 * @param size number of bytes to write
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
87 * @param func generic write function; the first parameter is src,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
88 * the second is dest_buf, the third is dest_buf_size.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
89 * func must return the number of bytes written to dest_buf, or <= 0 to
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
90 * indicate no more data available to write.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
91 * If func is NULL, src is interpreted as a simple byte array for source data.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
92 * @return the number of bytes written to the FIFO
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
93 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
94 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
95
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
96 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
97 * Resize an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
98 * In case of reallocation failure, the old FIFO is kept unchanged.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
99 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
100 * @param f AVFifoBuffer to resize
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
101 * @param size new AVFifoBuffer size in bytes
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
102 * @return <0 for failure, >=0 otherwise
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
103 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
104 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
105
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
106 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
107 * Enlarge an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
108 * In case of reallocation failure, the old FIFO is kept unchanged.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
109 * The new fifo size may be larger than the requested size.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
110 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
111 * @param f AVFifoBuffer to resize
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
112 * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
113 * @return <0 for failure, >=0 otherwise
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
114 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
115 int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
116
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
117 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
118 * Read and discard the specified amount of data from an AVFifoBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
119 * @param f AVFifoBuffer to read from
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
120 * @param size amount of data to read in bytes
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
121 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
122 void av_fifo_drain(AVFifoBuffer *f, int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
123
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
124 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
125 * Return a pointer to the data stored in a FIFO buffer at a certain offset.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
126 * The FIFO buffer is not modified.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
127 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
128 * @param f AVFifoBuffer to peek at, f must be non-NULL
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
129 * @param offs an offset in bytes, its absolute value must be less
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
130 * than the used buffer size or the returned pointer will
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
131 * point outside to the buffer data.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
132 * The used buffer size can be checked with av_fifo_size().
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
133 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
134 static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
135 {
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
136 uint8_t *ptr = f->rptr + offs;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
137 if (ptr >= f->end)
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
138 ptr = f->buffer + (ptr - f->end);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
139 else if (ptr < f->buffer)
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
140 ptr = f->end - (f->buffer - ptr);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
141 return ptr;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
142 }
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
143
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
144 #endif /* AVUTIL_FIFO_H */