Go to the documentation of this file.
27 #define _XOPEN_SOURCE 600
34 #include <stdatomic.h>
48 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
49 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
50 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
51 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
52 #define free AV_JOIN(MALLOC_PREFIX, free)
54 void *malloc(
size_t size);
55 void *memalign(
size_t align,
size_t size);
56 int posix_memalign(
void **ptr,
size_t align,
size_t size);
57 void *realloc(
void *ptr,
size_t size);
64 #define ALIGN (HAVE_AVX512 ? 64 : (HAVE_AVX ? 32 : 16))
81 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow)
82 if (__builtin_mul_overflow(
a,
b, &t))
88 if ((
a |
b) >= ((
size_t)1 << (
sizeof(
size_t) * 4)) &&
a && t /
a !=
b)
102 #if HAVE_POSIX_MEMALIGN
106 #elif HAVE_ALIGNED_MALLOC
145 #if CONFIG_MEMORY_POISONING
158 #if HAVE_ALIGNED_MALLOC
163 #if CONFIG_MEMORY_POISONING
194 memcpy(&
val, ptr,
sizeof(
val));
202 memcpy(ptr, &
val,
sizeof(
val));
214 #if FF_API_AV_MALLOCZ_ARRAY
236 memcpy(&
val, ptr,
sizeof(
val));
238 memcpy(ptr, &
val,
sizeof(
val));
247 #if HAVE_ALIGNED_MALLOC
267 memset(ptr, 0,
size);
283 size_t len = strlen(
s) + 1;
298 end = memchr(
s, 0,
len);
317 memcpy(ptr, p,
size);
325 memcpy(&
tab, tab_ptr,
sizeof(
tab));
329 memcpy(tab_ptr, &
tab,
sizeof(
tab));
339 memcpy(&
tab, tab_ptr,
sizeof(
tab));
343 memcpy(tab_ptr, &
tab,
sizeof(
tab));
351 const uint8_t *elem_data)
353 uint8_t *tab_elem_data =
NULL;
356 tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
358 memcpy(tab_elem_data, elem_data, elem_size);
359 else if (CONFIG_MEMORY_POISONING)
365 return tab_elem_data;
390 uint32_t
a = v << 8 | v >> 16;
391 uint32_t
b = v << 16 | v >> 8;
392 uint32_t
c = v << 24 | v;
395 uint32_t
a = v | v << 24;
396 uint32_t
b = v >> 8 | v << 16;
397 uint32_t
c = v >> 16 | v << 8;
431 uint64_t v2= v + ((uint64_t)v<<32);
456 const uint8_t *
src = &dst[-back];
461 memset(dst, *
src, cnt);
462 }
else if (back == 2) {
464 }
else if (back == 3) {
466 }
else if (back == 4) {
471 while (cnt > blocklen) {
472 memcpy(dst,
src, blocklen);
477 memcpy(dst,
src, cnt);
508 if (min_size <= *
size)
513 if (min_size > max_size) {
518 min_size =
FFMIN(max_size,
FFMAX(min_size + min_size / 16 + 32, min_size));
532 static inline void fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
537 memcpy(&
val, ptr,
sizeof(
val));
538 if (min_size <= *
size) {
545 if (min_size > max_size) {
550 min_size =
FFMIN(max_size,
FFMAX(min_size + min_size / 16 + 32, min_size));
553 memcpy(ptr, &
val,
sizeof(
val));
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
#define FF_DYNARRAY_ADD(av_size_max, av_elt_size, av_array, av_size, av_success, av_failure)
Add an element to a dynamic array.
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 * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
#define ATOMIC_VAR_INIT(value)
static void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate, reallocate, or free a block of memory.
static void fill16(uint8_t *dst, int len)
static const struct twinvq_data tab
static double val(void *priv, double ch)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
void * av_malloc_array(size_t nmemb, size_t size)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
void av_freep(void *arg)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void fill24(uint8_t *dst, int len)
and forward the result(frame or status change) to the corresponding input. If nothing is possible
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
#define atomic_load_explicit(object, order)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
static void fill32(uint8_t *dst, int len)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
void * av_mallocz_array(size_t nmemb, size_t size)
#define atomic_store_explicit(object, desired, order)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
void av_free(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static atomic_size_t max_alloc_size
static int size_mult(size_t a, size_t b, size_t *r)
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
char * av_strdup(const char *s)
Duplicate a string.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.