FFmpeg
buffer_internal.h
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 #ifndef AVUTIL_BUFFER_INTERNAL_H
20 #define AVUTIL_BUFFER_INTERNAL_H
21 
22 #include <stdatomic.h>
23 #include <stdint.h>
24 
25 #include "internal.h"
26 #include "buffer.h"
27 #include "thread.h"
28 
29 /**
30  * The buffer was av_realloc()ed, so it is reallocatable.
31  */
32 #define BUFFER_FLAG_REALLOCATABLE (1 << 0)
33 /**
34  * The AVBuffer structure is part of a larger structure
35  * and should not be freed.
36  */
37 #define BUFFER_FLAG_NO_FREE (1 << 1)
38 
39 struct AVBuffer {
40  uint8_t *data; /**< data described by this buffer */
41  size_t size; /**< size of data in bytes */
42 
43  /**
44  * number of existing AVBufferRef instances referring to this buffer
45  */
47 
48  /**
49  * a callback for freeing the data
50  */
51  void (*free)(void *opaque, uint8_t *data);
52 
53  /**
54  * an opaque pointer, to be used by the freeing callback
55  */
56  void *opaque;
57 
58  /**
59  * A combination of AV_BUFFER_FLAG_*
60  */
61  int flags;
62 
63  /**
64  * A combination of BUFFER_FLAG_*
65  */
67 };
68 
69 typedef struct BufferPoolEntry {
70  uint8_t *data;
71 
72  /*
73  * Backups of the original opaque/free of the AVBuffer corresponding to
74  * data. They will be used to free the buffer when the pool is freed.
75  */
76  void *opaque;
77  void (*free)(void *opaque, uint8_t *data);
78 
81 
82  /*
83  * An AVBuffer structure to (re)use as AVBuffer for subsequent uses
84  * of this BufferPoolEntry.
85  */
88 
89 struct AVBufferPool {
92 
93  /*
94  * This is used to track when the pool is to be freed.
95  * The pointer to the pool itself held by the caller is considered to
96  * be one reference. Each buffer requested by the caller increases refcount
97  * by one, returning the buffer to the pool decreases it by one.
98  * refcount reaches zero when the buffer has been uninited AND all the
99  * buffers have been released, then it's safe to free the pool and all
100  * the buffers in it.
101  */
103 
104  size_t size;
105  void *opaque;
106  AVBufferRef* (*alloc)(size_t size);
107  AVBufferRef* (*alloc2)(void *opaque, size_t size);
108  void (*pool_free)(void *opaque);
109 };
110 
111 #endif /* AVUTIL_BUFFER_INTERNAL_H */
AVBufferPool::mutex
AVMutex mutex
Definition: buffer_internal.h:90
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:89
thread.h
AVBufferPool::size
size_t size
Definition: buffer_internal.h:104
BufferPoolEntry::data
uint8_t * data
Definition: buffer_internal.h:70
AVBufferPool::refcount
atomic_uint refcount
Definition: buffer_internal.h:102
AVBuffer::flags
int flags
A combination of AV_BUFFER_FLAG_*.
Definition: buffer_internal.h:61
AVBufferPool::opaque
void * opaque
Definition: buffer_internal.h:105
AVMutex
#define AVMutex
Definition: thread.h:164
BufferPoolEntry::pool
AVBufferPool * pool
Definition: buffer_internal.h:79
AVBuffer::free
void(* free)(void *opaque, uint8_t *data)
a callback for freeing the data
Definition: buffer_internal.h:51
BufferPoolEntry::buffer
AVBuffer buffer
Definition: buffer_internal.h:86
AVBuffer::size
size_t size
size of data in bytes
Definition: buffer_internal.h:41
AVBuffer::flags_internal
int flags_internal
A combination of BUFFER_FLAG_*.
Definition: buffer_internal.h:66
AVBuffer::opaque
void * opaque
an opaque pointer, to be used by the freeing callback
Definition: buffer_internal.h:56
AVBufferPool::pool_free
void(* pool_free)(void *opaque)
Definition: buffer_internal.h:108
AVBuffer::data
uint8_t * data
data described by this buffer
Definition: buffer_internal.h:40
BufferPoolEntry::free
void(* free)(void *opaque, uint8_t *data)
Definition: buffer_internal.h:77
BufferPoolEntry
Definition: buffer_internal.h:69
buffer.h
BufferPoolEntry::opaque
void * opaque
Definition: buffer_internal.h:76
AVBuffer
A reference counted buffer type.
Definition: buffer_internal.h:39
internal.h
AVBufferPool::pool
BufferPoolEntry * pool
Definition: buffer_internal.h:91
BufferPoolEntry::next
struct BufferPoolEntry * next
Definition: buffer_internal.h:80
atomic_uint
intptr_t atomic_uint
Definition: stdatomic.h:56
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVBuffer::refcount
atomic_uint refcount
number of existing AVBufferRef instances referring to this buffer
Definition: buffer_internal.h:46