Go to the documentation of this file.
31 #define KNOWN(l) (!FF_LAYOUT2COUNT(l))
36 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
41 if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
46 for (i = 0; i < a->refcount; i ++) { \
47 ret->refs[ret->refcount] = a->refs[i]; \
48 *ret->refs[ret->refcount++] = ret; \
63 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
65 int i, j, k = 0, skip = 0; \
67 if (empty_allowed) { \
68 if (!a->nb || !b->nb) { \
72 FFSWAP(type *, a, b); \
77 for (i = 0; i < a->nb; i++) \
78 for (j = 0; j < b->nb; j++) \
79 if (a->fmts[i] == b->fmts[j]) { \
82 a->fmts[k++] = a->fmts[i]; \
93 MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
100 int alpha1=0, alpha2=0;
101 int chroma1=0, chroma2=0;
116 for (
i = 0;
i <
a->nb_formats;
i++) {
118 for (j = 0; j <
b->nb_formats; j++) {
122 if (
a->formats[
i] ==
b->formats[j]) {
130 if (alpha2 > alpha1 || chroma2 > chroma1)
189 if (
a ==
b)
return 1;
219 unsigned a_all =
a->all_layouts +
a->all_counts;
220 unsigned b_all =
b->all_layouts +
b->all_counts;
221 int ret_max, ret_nb = 0,
i, j,
round;
225 if (
a ==
b)
return 1;
230 FFSWAP(
unsigned, a_all, b_all);
233 if (a_all == 1 && !b_all) {
235 for (
i = j = 0;
i <
b->nb_channel_layouts;
i++)
236 if (
KNOWN(
b->channel_layouts[
i]))
237 b->channel_layouts[j++] =
b->channel_layouts[
i];
242 b->nb_channel_layouts = j;
248 ret_max =
a->nb_channel_layouts +
b->nb_channel_layouts;
253 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
254 if (!
KNOWN(
a->channel_layouts[
i]))
256 for (j = 0; j <
b->nb_channel_layouts; j++) {
257 if (
a->channel_layouts[
i] ==
b->channel_layouts[j]) {
259 a->channel_layouts[
i] =
b->channel_layouts[j] = 0;
267 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
268 uint64_t fmt =
a->channel_layouts[
i], bfmt;
269 if (!fmt || !
KNOWN(fmt))
272 for (j = 0; j <
b->nb_channel_layouts; j++)
273 if (
b->channel_layouts[j] == bfmt)
280 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
281 if (
KNOWN(
a->channel_layouts[
i]))
283 for (j = 0; j <
b->nb_channel_layouts; j++)
284 if (
a->channel_layouts[
i] ==
b->channel_layouts[j])
293 if (
a->refcount >
b->refcount)
300 b->nb_channel_layouts = ret_nb;
333 .conversion_filter =
"scale",
334 .conversion_opts_offset = offsetof(
AVFilterGraph, scale_sws_opts),
340 .conversion_filter =
"aresample",
341 .conversion_opts_offset = offsetof(
AVFilterGraph, aresample_swr_opts),
346 switch (
link->type) {
349 default:
return NULL;
357 for (p = fmts; *p != -1; p++) {
364 #define MAKE_FORMAT_LIST(type, field, count_field) \
368 for (count = 0; fmts[count] != -1; count++) \
370 formats = av_mallocz(sizeof(*formats)); \
373 formats->count_field = count; \
375 formats->field = av_malloc_array(count, sizeof(*formats->field)); \
376 if (!formats->field) { \
377 av_freep(&formats); \
386 formats->formats[count] = fmts[count];
396 memcpy(
formats->channel_layouts, fmts,
397 sizeof(*
formats->channel_layouts) * count);
402 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
406 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
407 return AVERROR(ENOMEM); \
410 fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
411 sizeof(*(*f)->list)); \
414 return AVERROR(ENOMEM); \
418 (*f)->list[(*f)->nb++] = fmt; \
436 int fmts[2] = { fmt, -1 };
460 unsigned nb_formats, fmt,
flags;
465 for (fmt = 0;; fmt++) {
472 (
desc->log2_chroma_w ||
desc->log2_chroma_h))
474 if ((
flags & (want | rej)) != want)
477 formats->formats[nb_formats] = fmt;
487 formats->nb_formats = nb_formats;
522 ret->all_layouts = 1;
531 ret->all_layouts =
ret->all_counts = 1;
535 #define FORMATS_REF(f, ref, unref_fn) \
539 return AVERROR(ENOMEM); \
541 tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
544 return AVERROR(ENOMEM); \
547 f->refs[f->refcount++] = ref; \
561 #define FIND_REF_INDEX(ref, idx) \
564 for (i = 0; i < (*ref)->refcount; i ++) \
565 if((*ref)->refs[i] == ref) { \
571 #define FORMATS_UNREF(ref, list) \
578 FIND_REF_INDEX(ref, idx); \
581 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
582 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
583 --(*ref)->refcount; \
585 if (!(*ref)->refcount) { \
586 av_free((*ref)->list); \
587 av_free((*ref)->refs); \
603 #define FORMATS_CHANGEREF(oldref, newref) \
607 FIND_REF_INDEX(oldref, idx); \
610 (*oldref)->refs[idx] = newref; \
627 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
631 return AVERROR(ENOMEM); \
633 for (i = 0; i < ctx->nb_inputs; i++) { \
634 AVFilterLink *const link = ctx->inputs[i]; \
635 if (link && !link->outcfg.fmts && \
636 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
637 int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
643 for (i = 0; i < ctx->nb_outputs; i++) { \
644 AVFilterLink *const link = ctx->outputs[i]; \
645 if (link && !link->incfg.fmts && \
646 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
647 int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
654 if (!fmts->refcount) \
685 const int *samplerates)
718 switch (
f->formats_state) {
740 type =
ctx->nb_inputs ?
ctx->inputs [0]->type :
782 if (*tail || srate < 1 || (
int)srate != srate || srate > INT_MAX) {
800 if (!chlayout && !nret) {
839 return check_list(log,
"sample format", fmts);
A list of supported channel layouts.
AVPixelFormat
Pixel format.
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 default minimum maximum flags name is the option name
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
A link between two filters.
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
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
Callbacks and properties to describe the steps of a format negotiation.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
#define check(x, y, S, v)
uint64_t * channel_layouts
list of channel layouts
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static enum AVPixelFormat pix_fmt
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
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 link
uint8_t nb_components
The number of components each pixel has, (1-4)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
char all_layouts
accept any known channel layout
char all_counts
accept any channel layout or count
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
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
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
static av_always_inline av_const double round(double x)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
#define av_malloc_array(a, b)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVSampleFormat
Audio sample formats.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define FFSWAP(type, a, b)
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
static int ref[MAX_W *MAX_W]
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
int av_get_extended_channel_layout(const char *name, uint64_t *channel_layout, int *nb_channels)
Return a channel layout and the number of channels based on the specified name.
int nb_channel_layouts
number of channel layouts
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const uint16_t channel_layouts[7]
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
#define flags(name, subs,...)
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active