Go to the documentation of this file.
19 #include <stdatomic.h>
32 #ifndef REFSTRUCT_CHECKED
34 #define ASSERT_LEVEL 0
36 #define REFSTRUCT_CHECKED (ASSERT_LEVEL >= 1)
40 #define ff_assert(cond) av_assert0(cond)
42 #define ff_assert(cond) ((void)0)
45 #define REFSTRUCT_COOKIE AV_NE((uint64_t)MKBETAG('R', 'e', 'f', 'S') << 32 | MKBETAG('t', 'r', 'u', 'c'), \
46 MKTAG('R', 'e', 'f', 'S') | (uint64_t)MKTAG('t', 'r', 'u', 'c') << 32)
48 #if __STDC_VERSION__ >= 201112L && !defined(_MSC_VER)
49 #define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX(ALIGN_64, _Alignof(max_align_t)))
51 #define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), ALIGN_64)
94 ref->free_cb = free_cb;
115 memset(obj, 0,
size);
125 memcpy(&obj, objp,
sizeof(obj));
128 memcpy(objp, &(
void *){
NULL },
sizeof(obj));
133 ref->free_cb(
ref->opaque, obj);
163 memcpy(&
dst, dstp,
sizeof(
dst));
170 memcpy(dstp, &
dst,
sizeof(
dst));
254 memcpy(datap, &(
void *){
NULL },
sizeof(
void*));
262 ref->opaque.nc = pool;
292 memcpy(datap, &
ret,
sizeof(
ret));
329 void *next =
entry->opaque.nc;
361 #define COMMON_FLAGS AV_REFSTRUCT_POOL_FLAG_NO_ZEROING
static void pool_free_entry(AVRefStructPool *pool, RefCount *ref)
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
void(* free_entry_cb)(AVRefStructOpaque opaque, void *obj)
RefStruct is an API for creating reference-counted objects with minimal overhead.
void(* free_cb)(AVRefStructOpaque opaque, void *obj)
void(* reset_cb)(AVRefStructOpaque opaque, void *obj)
int av_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
static int ff_mutex_unlock(AVMutex *mutex)
RefCount * available_entries
This is a linked list of available entries; the RefCount's opaque pointer is used as next pointer for...
intptr_t atomic_uintptr_t
static void refstruct_pool_uninit(AVRefStructOpaque unused, void *obj)
atomic_uintptr_t refcount
An uintptr_t is big enough to hold the address of every reference, so no overflow can happen when inc...
#define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
static int refstruct_pool_get_ext(void *datap, AVRefStructPool *pool)
static void pool_unref(void *ref)
Hint: The content of pool_unref() and refstruct_pool_uninit() could currently be merged; they are onl...
void * av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
int(* init_cb)(AVRefStructOpaque opaque, void *obj)
void(* free_cb)(AVRefStructOpaque opaque)
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
#define AV_REFSTRUCT_FLAG_NO_ZEROING
If this flag is set in av_refstruct_alloc_ext_c(), the object will not be initially zeroed.
static AVRefStructPool * av_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
A wrapper around av_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
#define AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR
If this flag is set and both init_cb and free_entry_cb callbacks are provided, then free_cb will be c...
static void refcount_init(RefCount *ref, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
#define atomic_fetch_sub_explicit(object, operand, order)
#define atomic_load_explicit(object, order)
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)
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
#define AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR
If this flag is set and both init_cb and reset_cb callbacks are provided, then reset_cb will be calle...
static int ff_mutex_lock(AVMutex *mutex)
static void * get_userdata(void *buf)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
AVRefStructPool * av_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
static void pool_reset_entry(AVRefStructOpaque opaque, void *entry)
const void * av_refstruct_ref_c(const void *obj)
Analog of av_refstruct_ref(), but for constant objects.
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static RefCount * get_refcount(void *obj)
static int ref[MAX_W *MAX_W]
static const RefCount * cget_refcount(const void *obj)
static void pool_return_entry(void *ref_)
#define flags(name, subs,...)
static void pool_free(AVRefStructPool *pool)
#define atomic_init(obj, value)
AVRefStructPool * av_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, int(*init_cb)(AVRefStructOpaque opaque, void *obj), void(*reset_cb)(AVRefStructOpaque opaque, void *obj), void(*free_entry_cb)(AVRefStructOpaque opaque, void *obj), void(*free_cb)(AVRefStructOpaque opaque))
Allocate an AVRefStructPool, potentially using complex callbacks.
atomic_uintptr_t refcount
The number of outstanding entries not in available_entries.