Go to the documentation of this file.
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;
218 unsigned a_all =
a->all_layouts +
a->all_counts;
219 unsigned b_all =
b->all_layouts +
b->all_counts;
220 int ret_max, ret_nb = 0,
i, j,
round;
224 if (
a ==
b)
return 1;
229 FFSWAP(
unsigned, a_all, b_all);
232 if (a_all == 1 && !b_all) {
234 for (
i = j = 0;
i <
b->nb_channel_layouts;
i++)
235 if (
KNOWN(&
b->channel_layouts[
i]) &&
i != j++) {
244 b->nb_channel_layouts = j;
250 ret_max =
a->nb_channel_layouts +
b->nb_channel_layouts;
255 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
256 if (!
KNOWN(&
a->channel_layouts[
i]))
258 for (j = 0; j <
b->nb_channel_layouts; j++) {
272 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
277 for (j = 0; j <
b->nb_channel_layouts; j++)
288 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
289 if (
KNOWN(&
a->channel_layouts[
i]))
291 for (j = 0; j <
b->nb_channel_layouts; j++)
304 if (
a->refcount >
b->refcount)
311 b->nb_channel_layouts = ret_nb;
350 #define PRINT_NAME(type, type_name) \
351 static void print_##type_name(AVBPrint *bp, const void *fmtsp) \
353 const AVFilterFormats *fmts = fmtsp; \
354 for (int i = 0; i < fmts->nb_formats; i++) { \
355 const char *name = av_##type_name(fmts->formats[i]); \
356 av_bprint_chars(bp, ' ', i ? 1 : 0); \
357 av_bprint_append_data(bp, name, name ? strlen(name) : 0); \
370 for (
int i = 0;
i <
layouts->nb_channel_layouts;
i++) {
379 for (
int i = 0;
i <
rates->nb_formats;
i++)
383 #define CONVERSION_FILTER_SWSCALE \
384 .conversion_filter = "scale", \
385 .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
387 #define CONVERSION_FILTER_ARESAMPLE \
388 .conversion_filter = "aresample", \
389 .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
393 .name =
"Pixel formats",
397 .print_list = print_get_pix_fmt_name,
401 .name =
"Color spaces",
405 .print_list = print_color_space_name,
409 .name =
"Color ranges",
413 .print_list = print_color_range_name,
417 .name =
"Alpha modes",
421 .print_list = print_alpha_mode_name,
422 .conversion_filter =
"premultiply_dynamic",
428 .name =
"Channel layouts",
436 .name =
"Sample rates",
444 .name =
"Sample formats",
448 .print_list = print_get_sample_fmt_name,
465 switch (
link->type) {
468 default:
return NULL;
481 #define MAKE_FORMAT_LIST(type, field, count_field) \
485 for (count = 0; fmts[count] != -1; count++) \
487 formats = av_mallocz(sizeof(*formats)); \
490 formats->count_field = count; \
492 formats->field = av_malloc_array(count, sizeof(*formats->field)); \
493 if (!formats->field) { \
494 av_freep(&formats); \
499 #define MAKE_FORMAT_LIST_TYPE(name, type) \
500 AVFilterFormats *ff_make_ ## name ## _list(const type* fmts) \
502 MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats); \
504 formats->formats[count] = (int)fmts[count]; \
517 for (count = 0; fmts[count].nb_channels; count++)
530 for (
int i = 0;
i < count;
i++) {
540 for (
int i = 0;
i < count;
i++)
548 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
552 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
553 return AVERROR(ENOMEM); \
556 fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
557 sizeof(*(*f)->list)); \
560 return AVERROR(ENOMEM); \
564 ASSIGN_FMT(f, fmt, list, nb); \
567 #define ASSIGN_FMT(f, fmt, list, nb) \
569 (*f)->list[(*f)->nb++] = fmt; \
579 #define ASSIGN_FMT(f, fmt, list, nb) \
582 memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
583 ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
599 int fmts[2] = { fmt, -1 };
623 unsigned nb_formats, fmt,
flags;
628 for (fmt = 0;; fmt++) {
635 (
desc->log2_chroma_w ||
desc->log2_chroma_h))
637 if ((
flags & (want | rej)) != want)
640 formats->formats[nb_formats] = fmt;
650 formats->nb_formats = nb_formats;
685 ret->all_layouts = 1;
694 ret->all_layouts =
ret->all_counts = 1;
744 #define FORMATS_REF(f, ref, unref_fn) \
748 return AVERROR(ENOMEM); \
750 tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs)); \
753 return AVERROR(ENOMEM); \
756 f->refs[f->refcount++] = ref; \
770 #define FIND_REF_INDEX(ref, idx) \
773 for (i = 0; i < (*ref)->refcount; i ++) \
774 if((*ref)->refs[i] == ref) { \
780 #define FORMATS_UNREF(ref, list) \
787 FIND_REF_INDEX(ref, idx); \
790 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
791 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
792 --(*ref)->refcount; \
794 if (!(*ref)->refcount) { \
795 FREE_LIST(ref, list); \
796 av_free((*ref)->list); \
797 av_free((*ref)->refs); \
803 #define FREE_LIST(ref, list) do { } while(0)
810 #define FREE_LIST(ref, list) \
812 for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
813 av_channel_layout_uninit(&(*ref)->list[i]); \
821 #define FORMATS_CHANGEREF(oldref, newref) \
825 FIND_REF_INDEX(oldref, idx); \
828 (*oldref)->refs[idx] = newref; \
845 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
849 return AVERROR(ENOMEM); \
851 for (i = 0; i < ctx->nb_inputs; i++) { \
852 AVFilterLink *const link = ctx->inputs[i]; \
853 if (link && !link->outcfg.fmts && \
854 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
855 int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
861 for (i = 0; i < ctx->nb_outputs; i++) { \
862 AVFilterLink *const link = ctx->outputs[i]; \
863 if (link && !link->incfg.fmts && \
864 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
865 int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
872 if (!fmts->refcount) \
903 const int *samplerates)
921 const int *color_spaces)
939 const int *color_ranges)
957 const int *alpha_modes)
998 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
1001 return AVERROR(ENOMEM); \
1003 for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
1004 const AVFilterLink *const link = ctx->inputs[i]; \
1005 if (!cfg_in[i]->fmts && \
1006 (media_type == AVMEDIA_TYPE_UNKNOWN || \
1007 link->type == media_type)) { \
1008 int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
1014 for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
1015 const AVFilterLink *const link = ctx->outputs[i]; \
1016 if (!cfg_out[i]->fmts && \
1017 (media_type == AVMEDIA_TYPE_UNKNOWN || \
1018 link->type == media_type)) { \
1019 int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
1026 if (!fmts->refcount) \
1067 const int *samplerates)
1091 const int *color_spaces)
1115 const int *color_ranges)
1139 const int *alpha_modes)
1191 switch (
f->formats_state) {
1216 ctx->nb_outputs ?
ctx->outputs[0]->type :
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
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
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
enum MovChannelLayoutTag * layouts
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCOL_SPC_NB
Not part of ABI.
int nb_channels
Number of channels in this layout.
A link between two filters.
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
@ AVCOL_RANGE_NB
Not part of ABI.
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)
#define check(x, y, S, v)
#define flags(name, subs,...)
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
static const FFFilter * fffilter(const AVFilter *f)
#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 AVFormatContext * ctx
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
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
uint8_t nb_components
The number of components each pixel has, (1-4)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
AVAlphaMode
Correlation between the alpha channel and color values.
An AVChannelLayout holds information about the channel layout of audio data.
#define i(width, name, range_min, range_max)
AVChannelLayout * channel_layouts
list of channel layouts
char all_layouts
accept any known channel layout
char all_counts
accept any channel layout or count
@ AVALPHA_MODE_NB
Not part of ABI.
@ 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
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
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.
#define av_malloc_array(a, b)
AVColorSpace
YUV colorspace type.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVSampleFormat
Audio sample formats.
void * av_calloc(size_t nmemb, size_t size)
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
#define FFSWAP(type, a, b)
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
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_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int nb_channel_layouts
number of channel layouts
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_FUNC2
formats.query_func2 active.
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
AVColorRange
Visual content value range.