annotate lib/libavutil/buffer.h @ 2562:b8a56afc6ba1

new var no_actors, lights_flag, debug_lights, StationaryLights and MobileLights
author Ritor1
date Sun, 17 May 2015 22:42:13 +0600
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 * @ingroup lavu_buffer
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
22 * refcounted data buffer API
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
23 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
24
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
25 #ifndef AVUTIL_BUFFER_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
26 #define AVUTIL_BUFFER_H
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
27
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
28 #include <stdint.h>
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
29
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
30 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
31 * @defgroup lavu_buffer AVBuffer
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
32 * @ingroup lavu_data
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
33 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
34 * @{
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
35 * AVBuffer is an API for reference-counted data buffers.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
36 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
37 * There are two core objects in this API -- AVBuffer and AVBufferRef. AVBuffer
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
38 * represents the data buffer itself; it is opaque and not meant to be accessed
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
39 * by the caller directly, but only through AVBufferRef. However, the caller may
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
40 * e.g. compare two AVBuffer pointers to check whether two different references
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
41 * are describing the same data buffer. AVBufferRef represents a single
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
42 * reference to an AVBuffer and it is the object that may be manipulated by the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
43 * caller directly.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
44 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
45 * There are two functions provided for creating a new AVBuffer with a single
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
46 * reference -- av_buffer_alloc() to just allocate a new buffer, and
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
47 * av_buffer_create() to wrap an existing array in an AVBuffer. From an existing
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
48 * reference, additional references may be created with av_buffer_ref().
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
49 * Use av_buffer_unref() to free a reference (this will automatically free the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
50 * data once all the references are freed).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
51 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
52 * The convention throughout this API and the rest of FFmpeg is such that the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
53 * buffer is considered writable if there exists only one reference to it (and
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
54 * it has not been marked as read-only). The av_buffer_is_writable() function is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
55 * provided to check whether this is true and av_buffer_make_writable() will
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
56 * automatically create a new writable buffer when necessary.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
57 * Of course nothing prevents the calling code from violating this convention,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
58 * however that is safe only when all the existing references are under its
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
59 * control.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
60 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
61 * @note Referencing and unreferencing the buffers is thread-safe and thus
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
62 * may be done from multiple threads simultaneously without any need for
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
63 * additional locking.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
64 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
65 * @note Two different references to the same buffer can point to different
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
66 * parts of the buffer (i.e. their AVBufferRef.data will not be equal).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
67 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
68
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
69 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
70 * A reference counted buffer type. It is opaque and is meant to be used through
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
71 * references (AVBufferRef).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
72 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
73 typedef struct AVBuffer AVBuffer;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
74
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
75 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
76 * A reference to a data buffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
77 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
78 * The size of this struct is not a part of the public ABI and it is not meant
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
79 * to be allocated directly.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
80 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
81 typedef struct AVBufferRef {
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
82 AVBuffer *buffer;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
83
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
84 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
85 * The data buffer. It is considered writable if and only if
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
86 * this is the only reference to the buffer, in which case
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
87 * av_buffer_is_writable() returns 1.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
88 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
89 uint8_t *data;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
90 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
91 * Size of data in bytes.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
92 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
93 int size;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
94 } AVBufferRef;
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 * Allocate an AVBuffer of the given size using av_malloc().
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
98 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
99 * @return an AVBufferRef of given size or NULL when out of memory
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
100 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
101 AVBufferRef *av_buffer_alloc(int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
102
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
103 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
104 * Same as av_buffer_alloc(), except the returned buffer will be initialized
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
105 * to zero.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
106 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
107 AVBufferRef *av_buffer_allocz(int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
108
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
109 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
110 * Always treat the buffer as read-only, even when it has only one
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
111 * reference.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
112 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
113 #define AV_BUFFER_FLAG_READONLY (1 << 0)
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
114
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
115 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
116 * Create an AVBuffer from an existing array.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
117 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
118 * If this function is successful, data is owned by the AVBuffer. The caller may
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
119 * only access data through the returned AVBufferRef and references derived from
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
120 * it.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
121 * If this function fails, data is left untouched.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
122 * @param data data array
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
123 * @param size size of data in bytes
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
124 * @param free a callback for freeing this buffer's data
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
125 * @param opaque parameter to be got for processing or passed to free
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
126 * @param flags a combination of AV_BUFFER_FLAG_*
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
127 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
128 * @return an AVBufferRef referring to data on success, NULL on failure.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
129 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
130 AVBufferRef *av_buffer_create(uint8_t *data, int size,
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
131 void (*free)(void *opaque, uint8_t *data),
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
132 void *opaque, int flags);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
133
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
134 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
135 * Default free callback, which calls av_free() on the buffer data.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
136 * This function is meant to be passed to av_buffer_create(), not called
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
137 * directly.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
138 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
139 void av_buffer_default_free(void *opaque, uint8_t *data);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
140
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
141 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
142 * Create a new reference to an AVBuffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
143 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
144 * @return a new AVBufferRef referring to the same AVBuffer as buf or NULL on
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
145 * failure.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
146 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
147 AVBufferRef *av_buffer_ref(AVBufferRef *buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
148
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
149 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
150 * Free a given reference and automatically free the buffer if there are no more
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
151 * references to it.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
152 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
153 * @param buf the reference to be freed. The pointer is set to NULL on return.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
154 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
155 void av_buffer_unref(AVBufferRef **buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
156
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
157 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
158 * @return 1 if the caller may write to the data referred to by buf (which is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
159 * true if and only if buf is the only reference to the underlying AVBuffer).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
160 * Return 0 otherwise.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
161 * A positive answer is valid until av_buffer_ref() is called on buf.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
162 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
163 int av_buffer_is_writable(const AVBufferRef *buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
164
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
165 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
166 * @return the opaque parameter set by av_buffer_create.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
167 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
168 void *av_buffer_get_opaque(const AVBufferRef *buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
169
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
170 int av_buffer_get_ref_count(const AVBufferRef *buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
171
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
172 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
173 * Create a writable reference from a given buffer reference, avoiding data copy
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
174 * if possible.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
175 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
176 * @param buf buffer reference to make writable. On success, buf is either left
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
177 * untouched, or it is unreferenced and a new writable AVBufferRef is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
178 * written in its place. On failure, buf is left untouched.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
179 * @return 0 on success, a negative AVERROR on failure.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
180 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
181 int av_buffer_make_writable(AVBufferRef **buf);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
182
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
183 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
184 * Reallocate a given buffer.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
185 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
186 * @param buf a buffer reference to reallocate. On success, buf will be
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
187 * unreferenced and a new reference with the required size will be
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
188 * written in its place. On failure buf will be left untouched. *buf
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
189 * may be NULL, then a new buffer is allocated.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
190 * @param size required new buffer size.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
191 * @return 0 on success, a negative AVERROR on failure.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
192 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
193 * @note the buffer is actually reallocated with av_realloc() only if it was
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
194 * initially allocated through av_buffer_realloc(NULL) and there is only one
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
195 * reference to it (i.e. the one passed to this function). In all other cases
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
196 * a new buffer is allocated and the data is copied.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
197 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
198 int av_buffer_realloc(AVBufferRef **buf, int size);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
199
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
200 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
201 * @}
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
202 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
203
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
204 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
205 * @defgroup lavu_bufferpool AVBufferPool
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
206 * @ingroup lavu_data
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
207 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
208 * @{
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
209 * AVBufferPool is an API for a lock-free thread-safe pool of AVBuffers.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
210 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
211 * Frequently allocating and freeing large buffers may be slow. AVBufferPool is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
212 * meant to solve this in cases when the caller needs a set of buffers of the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
213 * same size (the most obvious use case being buffers for raw video or audio
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
214 * frames).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
215 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
216 * At the beginning, the user must call av_buffer_pool_init() to create the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
217 * buffer pool. Then whenever a buffer is needed, call av_buffer_pool_get() to
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
218 * get a reference to a new buffer, similar to av_buffer_alloc(). This new
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
219 * reference works in all aspects the same way as the one created by
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
220 * av_buffer_alloc(). However, when the last reference to this buffer is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
221 * unreferenced, it is returned to the pool instead of being freed and will be
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
222 * reused for subsequent av_buffer_pool_get() calls.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
223 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
224 * When the caller is done with the pool and no longer needs to allocate any new
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
225 * buffers, av_buffer_pool_uninit() must be called to mark the pool as freeable.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
226 * Once all the buffers are released, it will automatically be freed.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
227 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
228 * Allocating and releasing buffers with this API is thread-safe as long as
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
229 * either the default alloc callback is used, or the user-supplied one is
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
230 * thread-safe.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
231 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
232
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
233 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
234 * The buffer pool. This structure is opaque and not meant to be accessed
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
235 * directly. It is allocated with av_buffer_pool_init() and freed with
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
236 * av_buffer_pool_uninit().
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
237 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
238 typedef struct AVBufferPool AVBufferPool;
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
239
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
240 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
241 * Allocate and initialize a buffer pool.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
242 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
243 * @param size size of each buffer in this pool
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
244 * @param alloc a function that will be used to allocate new buffers when the
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
245 * pool is empty. May be NULL, then the default allocator will be used
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
246 * (av_buffer_alloc()).
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
247 * @return newly created buffer pool on success, NULL on error.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
248 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
249 AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
250
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
251 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
252 * Mark the pool as being available for freeing. It will actually be freed only
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
253 * once all the allocated buffers associated with the pool are released. Thus it
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
254 * is safe to call this function while some of the allocated buffers are still
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
255 * in use.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
256 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
257 * @param pool pointer to the pool to be freed. It will be set to NULL.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
258 * @see av_buffer_pool_can_uninit()
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
259 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
260 void av_buffer_pool_uninit(AVBufferPool **pool);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
261
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
262 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
263 * Allocate a new AVBuffer, reusing an old buffer from the pool when available.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
264 * This function may be called simultaneously from multiple threads.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
265 *
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
266 * @return a reference to the new buffer on success, NULL on error.
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
267 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
268 AVBufferRef *av_buffer_pool_get(AVBufferPool *pool);
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
269
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
270 /**
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
271 * @}
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
272 */
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
273
992d2e6f907d preparation for libavcodec
zipi
parents:
diff changeset
274 #endif /* AVUTIL_BUFFER_H */