FFmpeg
Data Structures | Macros | Functions
refstruct.c File Reference
#include <stdatomic.h>
#include <stdint.h>
#include <string.h>
#include "refstruct.h"
#include "libavutil/avassert.h"
#include "libavutil/error.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"

Go to the source code of this file.

Data Structures

struct   RefCount
 
struct   FFRefStructPool
  FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API. More...
 

Macros

#define  ASSERT_LEVEL   0
 
#define  REFSTRUCT_CHECKED   (ASSERT_LEVEL >= 1)
 
#define  ff_assert(cond)   ((void)0)
 
#define  REFSTRUCT_COOKIE
 
#define  REFCOUNT_OFFSET   FFALIGN(sizeof(RefCount), ALIGN_64)
 
 

Functions

static RefCountget_refcount (void *obj)
 
static const RefCountcget_refcount (const void *obj)
 
static void *  get_userdata (void *buf)
 
static void  refcount_init (RefCount *ref, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
 
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. More...
 
void  ff_refstruct_unref (void *objp)
  Decrement the reference count of the underlying object and automatically free the object if there are no more references to it. More...
 
void *  ff_refstruct_ref (void *obj)
  Create a new reference to an object managed via this API, i.e. More...
 
const void *  ff_refstruct_ref_c (const void *obj)
  Analog of ff_refstruct_ref(), but for constant objects. More...
 
void  ff_refstruct_replace (void *dstp, const void *src)
  Ensure *dstp refers to the same object as src. More...
 
int  ff_refstruct_exclusive (const void *obj)
  Check whether the reference count of an object managed via this API is 1. More...
 
static void  pool_free (FFRefStructPool *pool)
 
static void  pool_free_entry (FFRefStructPool *pool, RefCount *ref)
 
static void  pool_return_entry (void *ref_)
 
static void  pool_reset_entry (FFRefStructOpaque opaque, void *entry)
 
static int  refstruct_pool_get_ext (void *datap, FFRefStructPool *pool)
 
  Get an object from the pool, reusing an old one from the pool when available. More...
 
static void  pool_unref (void *ref)
  Hint: The content of pool_unref() and refstruct_pool_uninit() could currently be merged; they are only separate functions in case we would ever introduce weak references. More...
 
static void  refstruct_pool_uninit (FFRefStructOpaque unused, void *obj)
 
  Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL) More...
 
FFRefStructPoolff_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. More...
 

Macro Definition Documentation

ASSERT_LEVEL

#define ASSERT_LEVEL   0

Definition at line 34 of file refstruct.c.

REFSTRUCT_CHECKED

#define REFSTRUCT_CHECKED   (ASSERT_LEVEL >= 1)

Definition at line 36 of file refstruct.c.

ff_assert

#define ff_assert (   cond )    ((void)0)

Definition at line 42 of file refstruct.c.

REFSTRUCT_COOKIE

#define REFSTRUCT_COOKIE
Value:
AV_NE((uint64_t)MKBETAG('R', 'e', 'f', 'S') << 32 | MKBETAG('t', 'r', 'u', 'c'), \
MKTAG('R', 'e', 'f', 'S') | (uint64_t)MKTAG('t', 'r', 'u', 'c') << 32)

Definition at line 45 of file refstruct.c.

REFCOUNT_OFFSET

#define REFCOUNT_OFFSET   FFALIGN(sizeof(RefCount), ALIGN_64)

Definition at line 51 of file refstruct.c.

COMMON_FLAGS

#define COMMON_FLAGS   FF_REFSTRUCT_POOL_FLAG_NO_ZEROING

Function Documentation

get_refcount()

static RefCount* get_refcount ( void *  obj )
static

Definition at line 70 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c(), ff_refstruct_ref(), ff_refstruct_ref_c(), ff_refstruct_unref(), pool_free(), and refstruct_pool_get_ext().

cget_refcount()

static const RefCount* cget_refcount ( const void *  obj )
static

Definition at line 77 of file refstruct.c.

Referenced by ff_refstruct_exclusive().

get_userdata()

static void* get_userdata ( void *  buf )
static

Definition at line 84 of file refstruct.c.

Referenced by ff_refstruct_alloc_ext_c(), pool_free_entry(), pool_unref(), and refstruct_pool_get_ext().

refcount_init()

static void refcount_init ( RefCountref,
FFRefStructOpaque  opaque,
void(*)(FFRefStructOpaque opaque, void *obj)  free_cb 
)
static

Definition at line 89 of file refstruct.c.

Referenced by ff_refstruct_alloc_ext_c().

ff_refstruct_alloc_ext_c()

void* ff_refstruct_alloc_ext_c ( size_t  size,
unsigned  flags,
FFRefStructOpaque  opaque,
void(*)(FFRefStructOpaque opaque, void *obj)  free_cb 
)

Allocate a refcounted object of usable size size managed via the RefStruct API.

By default (in the absence of flags to the contrary), the returned object is initially zeroed.

Parameters
size Desired usable size of the returned object.
flags A bitwise combination of FF_REFSTRUCT_FLAG_* flags.
opaque A pointer that will be passed to the free_cb callback.
free_cb A callback for freeing this object's content when its reference count reaches zero; it must not free the object itself.
Returns
A pointer to an object of the desired size or NULL on failure.

Definition at line 102 of file refstruct.c.

Referenced by cbs_alloc_content(), and ff_refstruct_alloc_ext().

ff_refstruct_unref()

void ff_refstruct_unref ( void *  objp )

Decrement the reference count of the underlying object and automatically free the object if there are no more references to it.

*objp == NULL is legal and a no-op.

Parameters
objp Pointer to a pointer that is either NULL or points to an object managed via this API. *objp is set to NULL on return.

Definition at line 120 of file refstruct.c.

Referenced by alloc_progress(), aps_decode_alf(), aps_decode_scaling(), av1_decode_free(), av1_frame_unref(), cbs_av1_close(), cbs_av1_write_obu(), cbs_clone_noncomplex_unit_content(), cbs_free_user_data_registered(), cbs_free_user_data_unregistered(), cbs_h264_close(), cbs_h264_flush(), cbs_h265_close(), cbs_h265_flush(), cbs_h266_flush(), cbs_read_fragment_content(), cbs_sei_delete_message(), cbs_unit_uninit(), decode_pps(), decode_sps(), ff_cbs_make_unit_writable(), ff_cbs_sei_free_message_list(), ff_codec_close(), ff_dovi_ctx_flush(), ff_dovi_ctx_unref(), ff_frame_thread_free(), ff_h264_decode_picture_parameter_set(), ff_h264_decode_seq_parameter_set(), ff_h264_ps_uninit(), ff_h264_unref_picture(), ff_hevc_decode_nal_pps(), ff_hevc_decode_nal_sps(), ff_hevc_decode_nal_vps(), ff_hevc_ps_uninit(), ff_hevc_unref_frame(), ff_mpeg_unref_picture(), ff_nvdec_decode_uninit(), ff_nvdec_start_frame_sep_ref(), ff_refstruct_pool_uninit(), ff_refstruct_replace(), ff_thread_get_ext_buffer(), ff_thread_release_ext_buffer(), ff_vk_decode_uninit(), ff_vvc_ctu_free_cus(), ff_vvc_frame_ps_free(), ff_vvc_ps_uninit(), ff_vvc_unref_frame(), nvdec_decoder_create(), nvdec_fdd_priv_free(), nvdec_unmap_mapped_frame(), pps_alloc(), pps_free(), remove_pps(), remove_sps(), remove_vps(), slices_free(), sps_alloc(), sps_free(), update_frame_pool(), vaapi_encode_discard(), vaapi_encode_get_coded_data(), vaapi_encode_issue(), vaapi_encode_output(), vp3_decode_end(), vp8_alloc_frame(), vp8_release_frame(), vp9_frame_unref(), vulkan_decode_bootstrap(), wavpack_decode_end(), and wv_dsd_reset().

ff_refstruct_ref()

void* ff_refstruct_ref ( void *  obj )

Create a new reference to an object managed via this API, i.e.

increment the reference count of the underlying object and return obj.

Returns
a pointer equal to obj.

Definition at line 140 of file refstruct.c.

Referenced by cbs_av1_write_obu(), ff_cbs_insert_unit_content(), ff_cbs_sei_add_message(), ff_nvdec_start_frame(), ff_thread_ref_frame(), get_current_frame(), hevc_ref_frame(), vaapi_encode_output(), and vp9_frame_ref().

ff_refstruct_ref_c()

const void* ff_refstruct_ref_c ( const void *  obj )

Analog of ff_refstruct_ref(), but for constant objects.

See also
ff_refstruct_ref()

Definition at line 149 of file refstruct.c.

Referenced by alloc_picture(), ff_h264_decode_picture_parameter_set(), and ff_refstruct_replace().

ff_refstruct_replace()

void ff_refstruct_replace ( void *  dstp,
const void *  src 
)

Ensure *dstp refers to the same object as src.

If *dstp is already equal to src, do nothing. Otherwise unreference *dstp and replace it with a new reference to src in case src != NULL (this involves incrementing the reference count of src's underlying object) or with NULL otherwise.

Parameters
dstp Pointer to a pointer that is either NULL or points to an object managed via this API.
src A pointer to an object managed via this API or NULL.

Definition at line 160 of file refstruct.c.

Referenced by aps_decode_alf(), aps_decode_scaling(), av1_frame_ref(), av1_receive_frame_internal(), cbs_av1_read_unit(), cbs_h2645_replace_ps(), decode_frame_ps(), decode_ph(), ff_dovi_ctx_replace(), ff_h264_update_thread_context(), ff_mpeg_ref_picture(), ff_thread_replace_frame(), ff_vk_update_thread_context(), ff_vvc_decode_aps(), ff_vvc_decode_sh(), h264_copy_picture_params(), h264_init_ps(), hevc_ref_frame(), parse_nal_units(), pps_alloc(), ref_frame(), slice_start(), sps_alloc(), update_context_from_thread(), and vp9_frame_ref().

ff_refstruct_exclusive()

int ff_refstruct_exclusive ( const void *  obj )

Check whether the reference count of an object managed via this API is 1.

Parameters
obj A pointer to an object managed via this API.
Returns
1 if the reference count of obj is 1; 0 otherwise.

Definition at line 174 of file refstruct.c.

Referenced by ff_cbs_make_unit_writable().

pool_free()

static void pool_free ( FFRefStructPoolpool )
static

Definition at line 208 of file refstruct.c.

Referenced by av_buffer_pool_init2(), pool_return_entry(), and pool_unref().

pool_free_entry()

static void pool_free_entry ( FFRefStructPoolpool,
RefCountref 
)
static

Definition at line 216 of file refstruct.c.

Referenced by pool_return_entry(), and refstruct_pool_uninit().

pool_return_entry()

static void pool_return_entry ( void *  ref_ )
static

Definition at line 223 of file refstruct.c.

Referenced by refstruct_pool_get_ext().

pool_reset_entry()

static void pool_reset_entry ( FFRefStructOpaque  opaque,
void *  entry 
)
static

Definition at line 243 of file refstruct.c.

Referenced by refstruct_pool_get_ext().

refstruct_pool_get_ext()

static int refstruct_pool_get_ext ( void *  datap,
FFRefStructPoolpool 
)
static

Definition at line 250 of file refstruct.c.

Referenced by ff_refstruct_pool_get().

ff_refstruct_pool_get()

void* ff_refstruct_pool_get ( FFRefStructPoolpool )

Get an object from the pool, reusing an old one from the pool when available.

Every call to this function must happen before ff_refstruct_pool_uninit(). Otherwise undefined behaviour may occur.

Parameters
pool the pool from which to get the object
Returns
a reference to the object on success, NULL on error.

Definition at line 297 of file refstruct.c.

Referenced by alloc_cu(), alloc_frame(), alloc_picture(), alloc_tu(), ff_nvdec_start_frame(), ff_nvdec_start_frame_sep_ref(), vaapi_encode_issue(), and vp9_frame_alloc().

pool_unref()

static void pool_unref ( void *  ref )
static

Hint: The content of pool_unref() and refstruct_pool_uninit() could currently be merged; they are only separate functions in case we would ever introduce weak references.

Definition at line 309 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c().

refstruct_pool_uninit()

static void refstruct_pool_uninit ( FFRefStructOpaque  unused,
void *  obj 
)
static

Definition at line 316 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext_c().

ff_refstruct_pool_alloc()

FFRefStructPool* ff_refstruct_pool_alloc ( size_t  size,
unsigned  flags 
)

Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)

Definition at line 335 of file refstruct.c.

Referenced by frame_context_init(), h264_init_context(), init_table_pools(), pic_arrays_init(), and vp9_frame_alloc().

ff_refstruct_pool_alloc_ext_c()

FFRefStructPool* ff_refstruct_pool_alloc_ext_c ( size_t  size,
unsigned  flags,
FFRefStructOpaque  opaque,
int(*)(FFRefStructOpaque opaque, void *obj)  init_cb,
void(*)(FFRefStructOpaque opaque, void *obj)  reset_cb,
void(*)(FFRefStructOpaque opaque, void *obj)  free_entry_cb,
void(*)(FFRefStructOpaque opaque)  free_cb 
)

Allocate an FFRefStructPool, potentially using complex callbacks.

Parameters
size size of the entries of the pool
flags a bitwise combination of FF_REFSTRUCT_POOL_FLAG_* flags
opaque A pointer that will be passed to the callbacks below.
init A callback that will be called directly after a new entry has been allocated. obj has already been zeroed unless the FF_REFSTRUCT_POOL_FLAG_NO_ZEROING flag is in use.
reset A callback that will be called after an entry has been returned to the pool and before it is reused.
free_entry A callback that will be called when an entry is freed after the pool has been marked as to be uninitialized.
free A callback that will be called when the pool itself is freed (after the last entry has been returned and freed).

Definition at line 340 of file refstruct.c.

Referenced by ff_refstruct_pool_alloc_ext().

AV_NE
#define AV_NE(be, le)
Definition: macros.h:33
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55

Generated on Thu Sep 26 2024 23:16:10 for FFmpeg by   doxygen 1.8.17

AltStyle によって変換されたページ (->オリジナル) /