FFmpeg: libavutil/buffer.c Source File
Go to the documentation of this file. 1 /*
2 * This file is part of FFmpeg.
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdatomic.h>
20 #include <stdint.h>
21 #include <string.h>
22
28
30 void (*free)(
void *opaque, uint8_t *
data),
31 void *opaque,
int flags)
32 {
34
39
41
43
47
51
53 }
54
56 void (*free)(
void *opaque, uint8_t *
data),
57 void *opaque,
int flags)
58 {
61 if (!buf)
63
68 }
70 }
71
73 {
75 }
76
78 {
81
85
89
91 }
92
94 {
98
101 }
102
104 {
106
109
111
113
115 }
116
118 {
120
122
126 } else
128
130 /* b->free below might already free the structure containing *b,
131 * so we have to read the flag now to avoid use-after-free. */
133 b->free(
b->opaque,
b->data);
134 if (free_avbuffer)
136 }
137 }
138
140 {
141 if (!buf || !*buf)
142 return;
143
145 }
146
148 {
150 return 0;
151
153 }
154
156 {
158 }
159
161 {
163 }
164
166 {
168
170 return 0;
171
173 if (!newbuf)
175
177
179
180 return 0;
181 }
182
184 {
188
189 if (!buf) {
190 /* allocate a new buffer with av_realloc(), so it will be reallocatable
191 * later */
195
197 if (!buf) {
200 }
201
203 *pbuf = buf;
204
205 return 0;
207 return 0;
208
211 /* cannot realloc, allocate a new reallocable buffer and copy data */
213
217
219
221 return 0;
222 }
223
227
230 return 0;
231 }
232
234 {
237
240 return 0;
241 }
242
244 /* make sure the data pointers match */
247 return 0;
248 }
249
253
256 return 0;
257 }
258
262 {
264 if (!pool)
266
270 }
271
277
279
280 return pool;
281 }
282
284 {
286 if (!pool)
288
292 }
293
296
298
299 return pool;
300 }
301
303 {
307
310 }
311 }
312
313 /*
314 * This function gets called when the pool has been uninited and
315 * all the buffers returned to it.
316 */
318 {
321
324
326 }
327
329 {
331
332 if (!ppool || !*ppool)
333 return;
334 pool = *ppool;
336
340
343 }
344
346 {
349
354
357 }
358
359 /* allocate a new buffer and override its free() callback so that
360 * it is returned to the pool on free */
362 {
365
367
372
374 if (!buf) {
377 }
378
383
384 ret->buffer->opaque = buf;
386
388 }
389
391 {
394
397 if (buf) {
405 }
406 } else {
408 }
410
413
415 }
416
418 {
422 }
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
uint8_t * data
The data buffer.
static void pool_free(FFRefStructPool *pool)
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define BUFFER_FLAG_REALLOCATABLE
The buffer was av_realloc()ed, so it is reallocatable.
static int ff_mutex_unlock(AVMutex *mutex)
int flags
A combination of AV_BUFFER_FLAG_*.
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static void pool_release_buffer(void *opaque, uint8_t *data)
void av_buffer_default_free(void *opaque, uint8_t *data)
Default free callback, which calls av_free() on the buffer data.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void(* free)(void *opaque, uint8_t *data)
a callback for freeing the data
size_t size
size of data in bytes
#define atomic_load(object)
#define BUFFER_FLAG_NO_FREE
The AVBuffer structure is part of a larger structure and should not be freed.
int flags_internal
A combination of BUFFER_FLAG_*.
static void buffer_pool_free(AVBufferPool *pool)
void * opaque
an opaque pointer, to be used by the freeing callback
void(* pool_free)(void *opaque)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
uint8_t * data
data described by this buffer
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
void(* free)(void *opaque, uint8_t *data)
static AVBufferRef * pool_alloc_buffer(AVBufferPool *pool)
static AVBufferRef * buffer_create(AVBuffer *buf, uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
#define atomic_fetch_sub_explicit(object, operand, order)
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
static int ff_mutex_destroy(AVMutex *mutex)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define atomic_fetch_add_explicit(object, operand, order)
AVBufferRef *(* alloc)(size_t size)
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
int av_buffer_get_ref_count(const AVBufferRef *buf)
static int ff_mutex_lock(AVMutex *mutex)
void * av_buffer_pool_buffer_get_opaque(const AVBufferRef *ref)
Query the original opaque parameter of an allocated buffer in the pool.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
size_t size
Size of data in bytes.
A reference counted buffer type.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
struct BufferPoolEntry * next
int av_buffer_is_writable(const AVBufferRef *buf)
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static void buffer_pool_flush(AVBufferPool *pool)
static int ref[MAX_W *MAX_W]
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
void * av_buffer_get_opaque(const AVBufferRef *buf)
A reference to a data buffer.
AVBufferRef *(* alloc2)(void *opaque, size_t size)
#define flags(name, subs,...)
#define atomic_init(obj, value)
atomic_uint refcount
number of existing AVBufferRef instances referring to this buffer
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Generated on Fri Aug 22 2025 13:59:38 for FFmpeg by
doxygen
1.8.17