Libav
Macros | Functions
formats.c File Reference
#include "libavutil/common.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "internal.h"
#include "formats.h"

Go to the source code of this file.

Macros

#define MERGE_REF(ret, a, fmts, type, fail)
 Add all refs from a to ret and destroy a. More...
 
#define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail)
 Add all formats common for a and b to ret, copy the refs and destroy a and b. More...
 
#define ADD_FORMAT(f, fmt, type, list, nb)
 
#define FORMATS_REF(f, ref)
 
#define FIND_REF_INDEX(ref, idx)
 
#define FORMATS_UNREF(ref, list)
 
#define FORMATS_CHANGEREF(oldref, newref)
 
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list)
 

Functions

AVFilterFormatsff_merge_formats (AVFilterFormats *a, AVFilterFormats *b)
 Return a format list which contains the intersection of the formats of a and b. More...
 
AVFilterFormatsff_merge_samplerates (AVFilterFormats *a, AVFilterFormats *b)
 
AVFilterChannelLayoutsff_merge_channel_layouts (AVFilterChannelLayouts *a, AVFilterChannelLayouts *b)
 Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates of a and b. More...
 
int ff_fmt_is_in (int fmt, const int *fmts)
 Tell is a format is contained in the provided list terminated by -1. More...
 
AVFilterFormatsff_make_format_list (const int *fmts)
 Create a list of supported formats. More...
 
int ff_add_format (AVFilterFormats **avff, int fmt)
 Add fmt to the list of media formats contained in *avff. More...
 
int ff_add_channel_layout (AVFilterChannelLayouts **l, uint64_t channel_layout)
 
AVFilterFormatsff_all_formats (enum AVMediaType type)
 Return a list of all formats supported by Libav for the given media type. More...
 
AVFilterFormatsff_planar_sample_fmts (void)
 Construct a formats list containing all planar sample formats. More...
 
AVFilterFormatsff_all_samplerates (void)
 
AVFilterChannelLayoutsff_all_channel_layouts (void)
 Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout/sample rate. More...
 
void ff_channel_layouts_ref (AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
 Add *ref as a new reference to f. More...
 
void ff_formats_ref (AVFilterFormats *f, AVFilterFormats **ref)
 Add *ref as a new reference to formats. More...
 
void ff_formats_unref (AVFilterFormats **ref)
 If *ref is non-NULL, remove *ref as a reference to the format list it currently points to, deallocates that list if this was the last reference, and sets *ref to NULL. More...
 
void ff_channel_layouts_unref (AVFilterChannelLayouts **ref)
 Remove a reference to a channel layouts list. More...
 
void ff_channel_layouts_changeref (AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
 
void ff_formats_changeref (AVFilterFormats **oldref, AVFilterFormats **newref)
 Before After


|formats |<------—. More...

 
void ff_set_common_channel_layouts (AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
 A helper for query_formats() which sets all links to the same list of channel layouts/sample rates. More...
 
void ff_set_common_samplerates (AVFilterContext *ctx, AVFilterFormats *samplerates)
 
void ff_set_common_formats (AVFilterContext *ctx, AVFilterFormats *formats)
 A helper for query_formats() which sets all links to the same list of formats. More...
 
int ff_default_query_formats (AVFilterContext *ctx)
 

Macro Definition Documentation

#define MERGE_REF (   ret,
  a,
  fmts,
  type,
  fail 
)
Value:
do { \
type ***tmp; \
int i; \
if (!(tmp = av_realloc(ret->refs, \
sizeof(*tmp) * (ret->refcount + a->refcount)))) \
goto fail; \
ret->refs = tmp; \
for (i = 0; i < a->refcount; i ++) { \
ret->refs[ret->refcount] = a->refs[i]; \
*ret->refs[ret->refcount++] = ret; \
} \
av_freep(&a->refs); \
av_freep(&a->fmts); \
} while (0)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
if(ac->has_optimized_func)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
for(j=16;j >0;--j)

Add all refs from a to ret and destroy a.

Definition at line 31 of file formats.c.

Referenced by ff_merge_channel_layouts(), and ff_merge_samplerates().

#define MERGE_FORMATS (   ret,
  a,
  b,
  fmts,
  nb,
  type,
  fail 
)
Value:
do { \
int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
if (!(ret = av_mallocz(sizeof(*ret)))) \
goto fail; \
if (count) { \
if (!(ret->fmts = av_malloc(sizeof(*ret->fmts) * count))) \
goto fail; \
for (i = 0; i < a->nb; i++) \
for (j = 0; j < b->nb; j++) \
if (a->fmts[i] == b->fmts[j]) \
ret->fmts[k++] = a->fmts[i]; \
\
ret->nb = k; \
} \
/* check that there was at least one common format */ \
if (!ret->nb) \
goto fail; \
MERGE_REF(ret, a, fmts, type, fail); \
MERGE_REF(ret, b, fmts, type, fail); \
} while (0)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define b
Definition: input.c:52
#define FFMIN(a, b)
Definition: common.h:57
if(ac->has_optimized_func)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
for(j=16;j >0;--j)
#define MERGE_REF(ret, a, fmts, type, fail)
Add all refs from a to ret and destroy a.
Definition: formats.c:31

Add all formats common for a and b to ret, copy the refs and destroy a and b.

Definition at line 55 of file formats.c.

Referenced by ff_merge_channel_layouts(), ff_merge_formats(), and ff_merge_samplerates().

#define ADD_FORMAT (   f,
  fmt,
  type,
  list,
  nb 
)
Value:
do { \
type *fmts; \
if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) \
return AVERROR(ENOMEM); \
\
fmts = av_realloc((*f)->list, \
sizeof(*(*f)->list) * ((*f)->nb + 1));\
if (!fmts) \
return AVERROR(ENOMEM); \
\
(*f)->list = fmts; \
(*f)->list[(*f)->nb++] = fmt; \
return 0; \
} while (0)
#define AVERROR(e)
Definition: error.h:43
return
if(ac->has_optimized_func)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205

Definition at line 182 of file formats.c.

Referenced by ff_add_channel_layout(), and ff_add_format().

#define FORMATS_REF (   f,
  ref 
)
Value:
do { \
*ref = f; \
f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
f->refs[f->refcount-1] = ref; \
} while (0)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117

Definition at line 254 of file formats.c.

Referenced by ff_channel_layouts_ref(), and ff_formats_ref().

#define FIND_REF_INDEX (   ref,
  idx 
)
Value:
do { \
int i; \
for (i = 0; i < (*ref)->refcount; i ++) \
if((*ref)->refs[i] == ref) { \
idx = i; \
break; \
} \
} while (0)
for(j=16;j >0;--j)

Definition at line 271 of file formats.c.

#define FORMATS_UNREF (   ref,
  list 
)
Value:
do { \
int idx = -1; \
if (!*ref) \
FIND_REF_INDEX(ref, idx); \
if (idx >= 0) \
memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
if(!--(*ref)->refcount) { \
av_free((*ref)->list); \
av_free((*ref)->refs); \
av_free(*ref); \
} \
*ref = NULL; \
} while (0)
#define FIND_REF_INDEX(ref, idx)
Definition: formats.c:271
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
return
if(ac->has_optimized_func)
NULL
Definition: eval.c:55

Definition at line 281 of file formats.c.

Referenced by ff_channel_layouts_unref(), and ff_formats_unref().

#define FORMATS_CHANGEREF (   oldref,
  newref 
)
Value:
do { \
int idx = -1; \
FIND_REF_INDEX(oldref, idx); \
if (idx >= 0) { \
(*oldref)->refs[idx] = newref; \
*newref = *oldref; \
*oldref = NULL; \
} \
} while (0)
#define FIND_REF_INDEX(ref, idx)
Definition: formats.c:271
if(ac->has_optimized_func)
NULL
Definition: eval.c:55

Definition at line 312 of file formats.c.

Referenced by ff_channel_layouts_changeref(), and ff_formats_changeref().

#define SET_COMMON_FORMATS (   ctx,
  fmts,
  in_fmts,
  out_fmts,
  ref,
  list 
)
Value:
{ \
int count = 0, i; \
for (i = 0; i < ctx->nb_inputs; i++) { \
if (ctx->inputs[i]) { \
ref(fmts, &ctx->inputs[i]->out_fmts); \
count++; \
} \
} \
for (i = 0; i < ctx->nb_outputs; i++) { \
if (ctx->outputs[i]) { \
ref(fmts, &ctx->outputs[i]->in_fmts); \
count++; \
} \
} \
if (!count) { \
av_freep(&fmts->list); \
av_freep(&fmts->refs); \
av_freep(&fmts); \
} \
}
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
if(ac->has_optimized_func)
for(j=16;j >0;--j)

Definition at line 336 of file formats.c.

Referenced by ff_set_common_channel_layouts(), ff_set_common_formats(), and ff_set_common_samplerates().

Function Documentation

AVFilterFormats* ff_merge_formats ( AVFilterFormats a,
AVFilterFormats b 
)

Return a format list which contains the intersection of the formats of a and b.

Also, all the references of a, all the references of b, and a and b themselves will be deallocated.

If a and b do not share any common formats, neither is modified, and NULL is returned.

Definition at line 80 of file formats.c.

Referenced by query_formats().

AVFilterFormats* ff_merge_samplerates ( AVFilterFormats a,
AVFilterFormats b 
)

Definition at line 99 of file formats.c.

Referenced by query_formats().

AVFilterChannelLayouts* ff_merge_channel_layouts ( AVFilterChannelLayouts a,
AVFilterChannelLayouts b 
)

Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates of a and b.

Also, all the references of a, all the references of b, and a and b themselves will be deallocated.

If a and b do not share any common elements, neither is modified, and NULL is returned.

Definition at line 126 of file formats.c.

Referenced by query_formats().

int ff_fmt_is_in ( int  fmt,
const int *  fmts 
)

Tell is a format is contained in the provided list terminated by -1.

Definition at line 154 of file formats.c.

Referenced by config_props().

AVFilterFormats* ff_make_format_list ( const int *  fmts)

Create a list of supported formats.

This is intended for use in AVFilter->query_formats().

Parameters
fmtslist of media formats, terminated by -1
Returns
the format list, with no existing references

Definition at line 165 of file formats.c.

Referenced by query_formats().

int ff_add_format ( AVFilterFormats **  avff,
int  fmt 
)

Add fmt to the list of media formats contained in *avff.

If *avff is NULL the function allocates the filter formats struct and puts its pointer in *avff.

Returns
a non negative value in case of success, or a negative value corresponding to an AVERROR code in case of error

Definition at line 199 of file formats.c.

Referenced by ff_all_formats(), ff_planar_sample_fmts(), init(), query_formats(), and reduce_formats_on_filter().

int ff_add_channel_layout ( AVFilterChannelLayouts **  l,
uint64_t  channel_layout 
)
AVFilterFormats* ff_all_formats ( enum AVMediaType  type)

Return a list of all formats supported by Libav for the given media type.

Definition at line 209 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

AVFilterFormats* ff_planar_sample_fmts ( void  )

Construct a formats list containing all planar sample formats.

Definition at line 230 of file formats.c.

Referenced by channelmap_query_formats(), join_query_formats(), and query_formats().

AVFilterFormats* ff_all_samplerates ( void  )
AVFilterChannelLayouts* ff_all_channel_layouts ( void  )

Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout/sample rate.

Definition at line 248 of file formats.c.

Referenced by channelmap_query_formats(), ff_default_query_formats(), join_query_formats(), and query_formats().

void ff_channel_layouts_ref ( AVFilterChannelLayouts f,
AVFilterChannelLayouts **  ref 
)

Add *ref as a new reference to f.

Definition at line 261 of file formats.c.

Referenced by channelmap_query_formats(), ff_set_common_channel_layouts(), join_query_formats(), and query_formats().

void ff_formats_ref ( AVFilterFormats formats,
AVFilterFormats **  ref 
)

Add *ref as a new reference to formats.

That is the pointers will point like in the ascii art below:


|formats |<-----—. | ____ | ____|___________________ | |refs| | | __|_ | |* * | | | | | | AVFilterLink | |* *------—>|*ref| | |____| | | |____| |________| |________________________

Definition at line 266 of file formats.c.

Referenced by ff_set_common_formats(), ff_set_common_samplerates(), and query_formats().

void ff_formats_unref ( AVFilterFormats **  ref)

If *ref is non-NULL, remove *ref as a reference to the format list it currently points to, deallocates that list if this was the last reference, and sets *ref to NULL.

Before After ________ ________ NULL |formats |<-----—. |formats | ^ | ____ | ____|________________ | ____ | ____|________________ | |refs| | | __|_ | |refs| | | __|_ | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink | |* *------—>|*ref| | |* | | | |*ref| | |____| | | |____| | |____| | | |____| |________| |_____________________ |________| |_____________________

Definition at line 302 of file formats.c.

Referenced by free_link(), pick_format(), and query_formats().

void ff_channel_layouts_unref ( AVFilterChannelLayouts **  ref)

Remove a reference to a channel layouts list.

Definition at line 307 of file formats.c.

Referenced by free_link(), and pick_format().

void ff_channel_layouts_changeref ( AVFilterChannelLayouts **  oldref,
AVFilterChannelLayouts **  newref 
)

Definition at line 325 of file formats.c.

Referenced by avfilter_insert_filter().

void ff_formats_changeref ( AVFilterFormats **  oldref,
AVFilterFormats **  newref 
)

Before After


|formats |<------—.

|formats |<------—. | ____ | ___|___ | ____ | ___|___ | |refs| | | | | | |refs| | | | | NULL | |* *------—>|*oldref| | |* *------—>|*newref| ^ | |* * | | |_______| | |* * | | |_______| ___|___ | |____| | | |____| | | | | |________| |________| |*oldref| |_______|

Definition at line 331 of file formats.c.

Referenced by avfilter_insert_filter().

void ff_set_common_channel_layouts ( AVFilterContext ctx,
AVFilterChannelLayouts layouts 
)

A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.

If there are no links hooked to this filter, the list is freed.

Definition at line 360 of file formats.c.

Referenced by ff_default_query_formats(), and query_formats().

void ff_set_common_samplerates ( AVFilterContext ctx,
AVFilterFormats samplerates 
)
void ff_set_common_formats ( AVFilterContext ctx,
AVFilterFormats formats 
)

A helper for query_formats() which sets all links to the same list of formats.

If there are no links hooked to this filter, the list of formats is freed.

Definition at line 379 of file formats.c.

Referenced by channelmap_query_formats(), ff_default_query_formats(), join_query_formats(), and query_formats().

int ff_default_query_formats ( AVFilterContext ctx)

Definition at line 385 of file formats.c.

Referenced by main(), and query_formats().