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 FF_REFSTRUCT_POOL_FLAG_NO_ZEROING
static int ff_mutex_init(AVMutex *mutex, const void *attr)
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
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
FFRefStructPool * ff_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
void(* free_cb)(FFRefStructOpaque opaque, void *obj)
static void * ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
A wrapper around ff_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
void(* free_entry_cb)(FFRefStructOpaque opaque, void *obj)
static void pool_free(FFRefStructPool *pool)
void * ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
RefStruct is an API for creating reference-counted objects with minimal overhead.
static int ff_mutex_unlock(AVMutex *mutex)
intptr_t atomic_uintptr_t
void(* reset_cb)(FFRefStructOpaque opaque, 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...
int ff_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
#define FF_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...
void(* free_cb)(FFRefStructOpaque opaque)
static void pool_unref(void *ref)
Hint: The content of pool_unref() and refstruct_pool_uninit() could currently be merged; they are onl...
const void * ff_refstruct_ref_c(const void *obj)
Analog of ff_refstruct_ref(), but for constant objects.
FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
atomic_uintptr_t refcount
The number of outstanding entries not in available_entries.
FFRefStructPool * ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, int(*init_cb)(FFRefStructOpaque opaque, void *obj), void(*reset_cb)(FFRefStructOpaque opaque, void *obj), void(*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void(*free_cb)(FFRefStructOpaque opaque))
Allocate an FFRefStructPool, potentially using complex callbacks.
static void pool_reset_entry(FFRefStructOpaque opaque, void *entry)
#define atomic_fetch_sub_explicit(object, operand, order)
#define atomic_load_explicit(object, order)
static int ff_mutex_destroy(AVMutex *mutex)
RefCount * available_entries
This is a linked list of available entries; the RefCount's opaque pointer is used as next pointer for...
static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool)
#define atomic_fetch_add_explicit(object, operand, order)
static void pool_free_entry(FFRefStructPool *pool, RefCount *ref)
static int ff_mutex_lock(AVMutex *mutex)
static void * get_userdata(void *buf)
#define FF_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 ...
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static FFRefStructPool * ff_refstruct_pool_alloc_ext(size_t size, unsigned flags, void *opaque, int(*init_cb)(FFRefStructOpaque opaque, void *obj), void(*reset_cb)(FFRefStructOpaque opaque, void *obj), void(*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void(*free_cb)(FFRefStructOpaque opaque))
A wrapper around ff_refstruct_pool_alloc_ext_c() for the common case of a non-const qualified opaque.
static RefCount * get_refcount(void *obj)
static int ref[MAX_W *MAX_W]
static const RefCount * cget_refcount(const void *obj)
#define FF_REFSTRUCT_FLAG_NO_ZEROING
If this flag is set in ff_refstruct_alloc_ext_c(), the object will not be initially zeroed.
int(* init_cb)(FFRefStructOpaque opaque, void *obj)
static void pool_return_entry(void *ref_)
#define flags(name, subs,...)
#define atomic_init(obj, value)
static void refcount_init(RefCount *ref, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void * ff_refstruct_pool_get(FFRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
static void refstruct_pool_uninit(FFRefStructOpaque unused, void *obj)
#define FF_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...