Go to the documentation of this file.
32 #define KNOWN(l) (!FF_LAYOUT2COUNT(l))
38 #define MERGE_REF_NO_ALLOC(ret, a, fmts) \
41 for (i = 0; i < a->refcount; i ++) { \
42 ret->refs[ret->refcount] = a->refs[i]; \
43 *ret->refs[ret->refcount++] = ret; \
51 #define MERGE_REF(ret, a, fmts, type, fail) \
55 if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
59 MERGE_REF_NO_ALLOC(ret, a, fmts); \
66 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
68 int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
71 if (!(ret = av_mallocz(sizeof(*ret)))) \
75 if (!(ret->fmts = av_malloc_array(count, sizeof(*ret->fmts)))) \
77 for (i = 0; i < a->nb; i++) \
78 for (j = 0; j < b->nb; j++) \
79 if (a->fmts[i] == b->fmts[j]) { \
80 if(k >= FFMIN(a->nb, b->nb)){ \
81 av_log(NULL, AV_LOG_ERROR, "Duplicate formats in %s detected\n", __FUNCTION__); \
86 ret->fmts[k++] = a->fmts[i]; \
94 tmp = av_realloc_array(NULL, a->refcount + b->refcount, sizeof(*tmp)); \
99 MERGE_REF_NO_ALLOC(ret, a, fmts); \
100 MERGE_REF_NO_ALLOC(ret, b, fmts); \
108 int alpha1=0, alpha2=0;
109 int chroma1=0, chroma2=0;
122 for (
i = 0;
i <
a->nb_formats;
i++)
123 for (j = 0; j <
b->nb_formats; j++) {
128 if (
a->formats[
i] ==
b->formats[j]) {
135 if (alpha2 > alpha1 || chroma2 > chroma1)
155 if (
a ==
b)
return a;
157 if (
a->nb_formats &&
b->nb_formats) {
159 }
else if (
a->nb_formats) {
181 unsigned a_all =
a->all_layouts +
a->all_counts;
182 unsigned b_all =
b->all_layouts +
b->all_counts;
183 int ret_max, ret_nb = 0,
i, j,
round;
185 if (
a ==
b)
return a;
190 FFSWAP(
unsigned, a_all, b_all);
193 if (a_all == 1 && !b_all) {
195 for (
i = j = 0;
i <
b->nb_channel_layouts;
i++)
196 if (
KNOWN(
b->channel_layouts[
i]))
197 b->channel_layouts[j++] =
b->channel_layouts[
i];
202 b->nb_channel_layouts = j;
208 ret_max =
a->nb_channel_layouts +
b->nb_channel_layouts;
211 sizeof(*
ret->channel_layouts))))
215 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
216 if (!
KNOWN(
a->channel_layouts[
i]))
218 for (j = 0; j <
b->nb_channel_layouts; j++) {
219 if (
a->channel_layouts[
i] ==
b->channel_layouts[j]) {
220 ret->channel_layouts[ret_nb++] =
a->channel_layouts[
i];
221 a->channel_layouts[
i] =
b->channel_layouts[j] = 0;
229 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
230 uint64_t fmt =
a->channel_layouts[
i], bfmt;
231 if (!fmt || !
KNOWN(fmt))
234 for (j = 0; j <
b->nb_channel_layouts; j++)
235 if (
b->channel_layouts[j] == bfmt)
236 ret->channel_layouts[ret_nb++] =
a->channel_layouts[
i];
242 for (
i = 0;
i <
a->nb_channel_layouts;
i++) {
243 if (
KNOWN(
a->channel_layouts[
i]))
245 for (j = 0; j <
b->nb_channel_layouts; j++)
246 if (
a->channel_layouts[
i] ==
b->channel_layouts[j])
247 ret->channel_layouts[ret_nb++] =
a->channel_layouts[
i];
250 ret->nb_channel_layouts = ret_nb;
251 if (!
ret->nb_channel_layouts)
275 for (p = fmts; *p != -1; p++) {
282 #define MAKE_FORMAT_LIST(type, field, count_field) \
286 for (count = 0; fmts[count] != -1; count++) \
288 formats = av_mallocz(sizeof(*formats)); \
291 formats->count_field = count; \
293 formats->field = av_malloc_array(count, sizeof(*formats->field)); \
294 if (!formats->field) { \
295 av_freep(&formats); \
304 formats->formats[count] = fmts[count];
314 memcpy(
formats->channel_layouts, fmts,
315 sizeof(*
formats->channel_layouts) * count);
325 memcpy(
formats->channel_layouts, fmts,
326 sizeof(*
formats->channel_layouts) * count);
331 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
335 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
336 return AVERROR(ENOMEM); \
339 fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
340 sizeof(*(*f)->list)); \
343 return AVERROR(ENOMEM); \
347 (*f)->list[(*f)->nb++] = fmt; \
387 unsigned nb_formats, fmt,
flags;
392 for (fmt = 0;; fmt++) {
399 (
desc->log2_chroma_w ||
desc->log2_chroma_h))
401 if ((
flags & (want | rej)) != want)
404 formats->formats[nb_formats] = fmt;
415 formats->nb_formats = nb_formats;
450 ret->all_layouts = 1;
459 ret->all_layouts =
ret->all_counts = 1;
463 #define FORMATS_REF(f, ref, unref_fn) \
467 return AVERROR(ENOMEM); \
469 tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
472 return AVERROR(ENOMEM); \
475 f->refs[f->refcount++] = ref; \
489 #define FIND_REF_INDEX(ref, idx) \
492 for (i = 0; i < (*ref)->refcount; i ++) \
493 if((*ref)->refs[i] == ref) { \
499 #define FORMATS_UNREF(ref, list) \
506 FIND_REF_INDEX(ref, idx); \
509 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
510 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
511 --(*ref)->refcount; \
513 if (!(*ref)->refcount) { \
514 av_free((*ref)->list); \
515 av_free((*ref)->refs); \
531 #define FORMATS_CHANGEREF(oldref, newref) \
535 FIND_REF_INDEX(oldref, idx); \
538 (*oldref)->refs[idx] = newref; \
555 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn) \
559 return AVERROR(ENOMEM); \
561 for (i = 0; i < ctx->nb_inputs; i++) { \
562 if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
563 int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts); \
570 for (i = 0; i < ctx->nb_outputs; i++) { \
571 if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
572 int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts); \
616 ctx->outputs &&
ctx->outputs[0] ?
ctx->outputs[0]->type :
666 sfmt = strtol(
arg, &tail, 0);
691 if (*tail || srate < 1 || (
int)srate != srate || srate > INT_MAX) {
709 if (!chlayout && !nret) {
A list of supported channel layouts.
AVPixelFormat
Pixel format.
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
#define FFSWAP(type, a, b)
enum MovChannelLayoutTag * layouts
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
#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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#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.
uint8_t nb_components
The number of components each pixel has, (1-4)
Rational number (pair of numerator and denominator).
int av_parse_ratio(AVRational *q, const char *str, int max, int log_offset, void *log_ctx)
Parse str and store the parsed ratio in q.
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
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
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
#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.
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
#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...
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.
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]
#define flags(name, subs,...)