FFmpeg
Macros | Functions
formats.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/pixdesc.h"
#include "libavutil/parseutils.h"
#include "avfilter.h"
#include "internal.h"
#include "formats.h"

Go to the source code of this file.

Macros

#define KNOWN(l)   (!FF_LAYOUT2COUNT(l)) /* for readability */
 
#define MERGE_REF_NO_ALLOC(ret, a, fmts)
 Add all refs from a to ret and destroy a. More...
 
#define MERGE_REF(ret, a, fmts, type, fail)
 
#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 MAKE_FORMAT_LIST(type, field, count_field)
 
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
 
#define FORMATS_REF(f, ref, unref_fn)
 
#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_fn, unref_fn)
 

Functions

AVFilterFormatsff_merge_formats (AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type)
 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 if an integer is contained in the provided -1-terminated list of integers. More...
 
AVFilterFormatsff_make_format_list (const int *fmts)
 Create a list of supported formats. More...
 
AVFilterChannelLayoutsff_make_formatu64_list (const uint64_t *fmts)
 
AVFilterChannelLayoutsavfilter_make_format64_list (const int64_t *fmts)
 
int ff_add_format (AVFilterFormats **avff, int64_t 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 FFmpeg for the given media type. More...
 
int ff_formats_pixdesc_filter (AVFilterFormats **rfmts, unsigned want, unsigned rej)
 Construct a formats list containing all pixel formats with certain properties. 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 (with known disposition)/sample rate. More...
 
AVFilterChannelLayoutsff_all_channel_counts (void)
 Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition. More...
 
int ff_channel_layouts_ref (AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
 Add *ref as a new reference to f. More...
 
int 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)
 
int 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...
 
int ff_set_common_samplerates (AVFilterContext *ctx, AVFilterFormats *samplerates)
 
int ff_set_common_formats (AVFilterContext *ctx, AVFilterFormats *formats)
 A helper for query_formats() which sets all links to the same list of formats. More...
 
static int default_query_formats_common (AVFilterContext *ctx, AVFilterChannelLayouts *(layouts)(void))
 
int ff_default_query_formats (AVFilterContext *ctx)
 
int ff_query_formats_all_layouts (AVFilterContext *ctx)
 Set the formats list to all known channel layouts. More...
 
int ff_parse_pixel_format (enum AVPixelFormat *ret, const char *arg, void *log_ctx)
 Parse a pixel format. More...
 
int ff_parse_sample_format (int *ret, const char *arg, void *log_ctx)
 Parse a sample format name or a corresponding integer representation. More...
 
int ff_parse_time_base (AVRational *ret, const char *arg, void *log_ctx)
 Parse a time base. More...
 
int ff_parse_sample_rate (int *ret, const char *arg, void *log_ctx)
 Parse a sample rate. More...
 
int ff_parse_channel_layout (int64_t *ret, int *nret, const char *arg, void *log_ctx)
 Parse a channel layout or a corresponding integer representation. More...
 

Macro Definition Documentation

◆ KNOWN

#define KNOWN (   l)    (!FF_LAYOUT2COUNT(l)) /* for readability */

Definition at line 32 of file formats.c.

◆ MERGE_REF_NO_ALLOC

#define MERGE_REF_NO_ALLOC (   ret,
  a,
  fmts 
)
Value:
do { \
int i; \
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); \
av_freep(&a); \
} while (0)

Add all refs from a to ret and destroy a.

ret->refs must have enough spare room left for this.

Definition at line 38 of file formats.c.

◆ MERGE_REF

#define MERGE_REF (   ret,
  a,
  fmts,
  type,
  fail 
)
Value:
do { \
type ***tmp; \
if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
sizeof(*tmp)))) \
goto fail; \
ret->refs = tmp; \
MERGE_REF_NO_ALLOC(ret, a, fmts); \
} while (0)

Definition at line 51 of file formats.c.

◆ MERGE_FORMATS

#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.

Definition at line 66 of file formats.c.

◆ MAKE_FORMAT_LIST

#define MAKE_FORMAT_LIST (   type,
  field,
  count_field 
)
Value:
int count = 0; \
if (fmts) \
for (count = 0; fmts[count] != -1; count++) \
; \
formats = av_mallocz(sizeof(*formats)); \
if (!formats) \
return NULL; \
formats->count_field = count; \
if (count) { \
formats->field = av_malloc_array(count, sizeof(*formats->field)); \
if (!formats->field) { \
av_freep(&formats); \
return NULL; \
} \
}

Definition at line 282 of file formats.c.

◆ ADD_FORMAT

#define ADD_FORMAT (   f,
  fmt,
  unref_fn,
  type,
  list,
  nb 
)
Value:
do { \
type *fmts; \
if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
return AVERROR(ENOMEM); \
} \
\
fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
sizeof(*(*f)->list)); \
if (!fmts) { \
unref_fn(f); \
return AVERROR(ENOMEM); \
} \
\
(*f)->list = fmts; \
(*f)->list[(*f)->nb++] = fmt; \
} while (0)

Definition at line 331 of file formats.c.

◆ FORMATS_REF

#define FORMATS_REF (   f,
  ref,
  unref_fn 
)
Value:
void *tmp; \
if (!f || !ref) \
return AVERROR(ENOMEM); \
\
tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
if (!tmp) { \
unref_fn(&f); \
return AVERROR(ENOMEM); \
} \
f->refs = tmp; \
f->refs[f->refcount++] = ref; \
*ref = f; \
return 0

Definition at line 463 of file formats.c.

◆ FIND_REF_INDEX

#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)

Definition at line 489 of file formats.c.

◆ FORMATS_UNREF

#define FORMATS_UNREF (   ref,
  list 
)
Value:
do { \
int idx = -1; \
if (!ref || !*ref) \
return; \
if (idx >= 0) { \
memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
--(*ref)->refcount; \
} \
if (!(*ref)->refcount) { \
av_free((*ref)->list); \
av_free((*ref)->refs); \
av_free(*ref); \
} \
*ref = NULL; \
} while (0)

Definition at line 499 of file formats.c.

◆ FORMATS_CHANGEREF

#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)

Definition at line 531 of file formats.c.

◆ SET_COMMON_FORMATS

#define SET_COMMON_FORMATS (   ctx,
  fmts,
  in_fmts,
  out_fmts,
  ref_fn,
  unref_fn 
)
Value:
int count = 0, i; \
if (!fmts) \
return AVERROR(ENOMEM); \
for (i = 0; i < ctx->nb_inputs; i++) { \
if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts); \
if (ret < 0) { \
return ret; \
} \
count++; \
} \
} \
for (i = 0; i < ctx->nb_outputs; i++) { \
if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts); \
if (ret < 0) { \
return ret; \
} \
count++; \
} \
} \
if (!count) { \
unref_fn(&fmts); \
} \
\
return 0;

Definition at line 555 of file formats.c.

Function Documentation

◆ ff_merge_formats()

AVFilterFormats* ff_merge_formats ( AVFilterFormats a,
AVFilterFormats b,
enum AVMediaType  type 
)

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 103 of file formats.c.

Referenced by can_merge_formats(), and query_formats().

◆ ff_merge_samplerates()

AVFilterFormats* ff_merge_samplerates ( AVFilterFormats a,
AVFilterFormats b 
)

Definition at line 150 of file formats.c.

Referenced by can_merge_formats(), and query_formats().

◆ ff_merge_channel_layouts()

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 177 of file formats.c.

Referenced by query_formats().

◆ ff_fmt_is_in()

int ff_fmt_is_in ( int  fmt,
const int fmts 
)

Tell if an integer is contained in the provided -1-terminated list of integers.

This is useful for determining (for instance) if an AVPixelFormat is in an array of supported formats.

Parameters
fmtprovided format
fmts-1-terminated list of formats
Returns
1 if present, 0 if absent

Definition at line 271 of file formats.c.

Referenced by config_input(), config_input_main(), config_input_overlay(), config_out_props(), and config_props().

◆ ff_make_format_list()

AVFilterFormats* ff_make_format_list ( const int fmts)

◆ ff_make_formatu64_list()

AVFilterChannelLayouts* ff_make_formatu64_list ( const uint64_t *  fmts)

Definition at line 309 of file formats.c.

◆ avfilter_make_format64_list()

AVFilterChannelLayouts* avfilter_make_format64_list ( const int64_t *  fmts)

Definition at line 320 of file formats.c.

Referenced by movie_query_formats(), and query_formats().

◆ ff_add_format()

int ff_add_format ( AVFilterFormats **  avff,
int64_t  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 350 of file formats.c.

Referenced by asink_query_formats(), ff_all_formats(), ff_draw_supported_pixel_formats(), ff_planar_sample_fmts(), hwupload_query_formats(), init(), query_formats(), reduce_formats_on_filter(), and vsink_query_formats().

◆ ff_add_channel_layout()

int ff_add_channel_layout ( AVFilterChannelLayouts **  l,
uint64_t  channel_layout 
)

◆ ff_all_formats()

AVFilterFormats* ff_all_formats ( enum AVMediaType  type)

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

Definition at line 363 of file formats.c.

Referenced by default_query_formats_common(), filter_query_formats(), hwmap_query_formats(), and query_formats().

◆ ff_formats_pixdesc_filter()

int ff_formats_pixdesc_filter ( AVFilterFormats **  rfmts,
unsigned  want,
unsigned  rej 
)

Construct a formats list containing all pixel formats with certain properties.

Definition at line 385 of file formats.c.

Referenced by hwdownload_query_formats(), and query_formats().

◆ ff_planar_sample_fmts()

AVFilterFormats* ff_planar_sample_fmts ( void  )

Construct a formats list containing all planar sample formats.

Definition at line 426 of file formats.c.

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

◆ ff_all_samplerates()

AVFilterFormats* ff_all_samplerates ( void  )

◆ ff_all_channel_layouts()

AVFilterChannelLayouts* ff_all_channel_layouts ( void  )

Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (with known disposition)/sample rate.

Definition at line 445 of file formats.c.

Referenced by ff_query_formats_all_layouts(), filter_query_formats(), join_query_formats(), and query_formats().

◆ ff_all_channel_counts()

AVFilterChannelLayouts* ff_all_channel_counts ( void  )

Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.

Definition at line 454 of file formats.c.

Referenced by aeval_query_formats(), asink_query_formats(), channelmap_query_formats(), ff_default_query_formats(), and query_formats().

◆ ff_channel_layouts_ref()

int ff_channel_layouts_ref ( AVFilterChannelLayouts f,
AVFilterChannelLayouts **  ref 
)

◆ ff_formats_ref()

int 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 484 of file formats.c.

Referenced by cudaupload_query_formats(), deint_cuda_query_formats(), ff_set_common_formats(), ff_set_common_samplerates(), ff_vaapi_vpp_query_formats(), hwdownload_query_formats(), hwmap_query_formats(), hwupload_query_formats(), movie_query_formats(), overlay_qsv_query_formats(), query_formats(), and query_formats_src().

◆ ff_formats_unref()

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 521 of file formats.c.

Referenced by ff_add_format(), ff_formats_ref(), ff_set_common_formats(), ff_set_common_samplerates(), free_link(), init(), pick_format(), query_formats(), reduce_formats_on_filter(), and uninit().

◆ ff_channel_layouts_unref()

void ff_channel_layouts_unref ( AVFilterChannelLayouts **  ref)

Remove a reference to a channel layouts list.

Definition at line 526 of file formats.c.

Referenced by ff_add_channel_layout(), ff_channel_layouts_ref(), ff_set_common_channel_layouts(), free_link(), init(), pick_format(), and uninit().

◆ ff_channel_layouts_changeref()

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

Definition at line 544 of file formats.c.

Referenced by avfilter_insert_filter().

◆ ff_formats_changeref()

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

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

Definition at line 550 of file formats.c.

Referenced by avfilter_insert_filter().

◆ ff_set_common_channel_layouts()

int 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 586 of file formats.c.

Referenced by aeval_query_formats(), asink_query_formats(), default_query_formats_common(), filter_query_formats(), and query_formats().

◆ ff_set_common_samplerates()

int ff_set_common_samplerates ( AVFilterContext ctx,
AVFilterFormats samplerates 
)

◆ ff_set_common_formats()

int ff_set_common_formats ( AVFilterContext ctx,
AVFilterFormats formats 
)

◆ default_query_formats_common()

static int default_query_formats_common ( AVFilterContext ctx,
AVFilterChannelLayouts layouts)(void 
)
static

Definition at line 611 of file formats.c.

Referenced by ff_default_query_formats(), and ff_query_formats_all_layouts().

◆ ff_default_query_formats()

int ff_default_query_formats ( AVFilterContext ctx)

Definition at line 634 of file formats.c.

Referenced by main(), query_formats(), and vsink_query_formats().

◆ ff_query_formats_all_layouts()

int ff_query_formats_all_layouts ( AVFilterContext ctx)

Set the formats list to all known channel layouts.

This function behaves like ff_default_query_formats(), except it only accepts known channel layouts. It should only be used with audio filters.

Definition at line 639 of file formats.c.

◆ ff_parse_pixel_format()

int ff_parse_pixel_format ( enum AVPixelFormat ret,
const char *  arg,
void *  log_ctx 
)

Parse a pixel format.

Parameters
retpixel format pointer to where the value should be written
argstring to parse
log_ctxlog context
Returns
>= 0 in case of success, a negative AVERROR code on error

Definition at line 646 of file formats.c.

Referenced by init().

◆ ff_parse_sample_format()

int ff_parse_sample_format ( int ret,
const char *  arg,
void *  log_ctx 
)

Parse a sample format name or a corresponding integer representation.

Parameters
retinteger pointer to where the value should be written
argstring to parse
log_ctxlog context
Returns
>= 0 in case of success, a negative AVERROR code on error

Definition at line 661 of file formats.c.

◆ ff_parse_time_base()

int ff_parse_time_base ( AVRational ret,
const char *  arg,
void *  log_ctx 
)

Parse a time base.

Parameters
retunsigned AVRational pointer to where the value should be written
argstring to parse
log_ctxlog context
Returns
>= 0 in case of success, a negative AVERROR code on error

Definition at line 676 of file formats.c.

◆ ff_parse_sample_rate()

int ff_parse_sample_rate ( int ret,
const char *  arg,
void *  log_ctx 
)

Parse a sample rate.

Parameters
retunsigned integer pointer to where the value should be written
argstring to parse
log_ctxlog context
Returns
>= 0 in case of success, a negative AVERROR code on error

Definition at line 687 of file formats.c.

Referenced by init().

◆ ff_parse_channel_layout()

int ff_parse_channel_layout ( int64_t *  ret,
int nret,
const char *  arg,
void *  log_ctx 
)

Parse a channel layout or a corresponding integer representation.

Parameters
ret64bit integer pointer to where the value should be written.
nretinteger pointer to the number of channels; if not NULL, then unknown channel layouts are accepted
argstring to parse
log_ctxlog context
Returns
>= 0 in case of success, a negative AVERROR code on error

Definition at line 699 of file formats.c.

Referenced by init(), and main().

formats
formats
Definition: signature.h:48
FIND_REF_INDEX
#define FIND_REF_INDEX(ref, idx)
Definition: formats.c:489
AVERROR
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
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
fail
#define fail()
Definition: checkasm.h:123
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:48
f
#define f(width, name)
Definition: cbs_vp9.c:255
if
if(ret)
Definition: filter_design.txt:179
NULL
#define NULL
Definition: coverity.c:32
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
a
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
Definition: undefined.txt:41
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
ret
ret
Definition: filter_design.txt:187
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35