FFmpeg  4.0
formats.c
Go to the documentation of this file.
1 /*
2  * Filter layer - format negotiation
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
25 #include "libavutil/eval.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/parseutils.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "formats.h"
31 
32 #define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
33 
34 /**
35  * Add all refs from a to ret and destroy a.
36  */
37 #define MERGE_REF(ret, a, fmts, type, fail) \
38 do { \
39  type ***tmp; \
40  int i; \
41  \
42  if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
43  sizeof(*tmp)))) \
44  goto fail; \
45  ret->refs = tmp; \
46  \
47  for (i = 0; i < a->refcount; i ++) { \
48  ret->refs[ret->refcount] = a->refs[i]; \
49  *ret->refs[ret->refcount++] = ret; \
50  } \
51  \
52  av_freep(&a->refs); \
53  av_freep(&a->fmts); \
54  av_freep(&a); \
55 } while (0)
56 
57 /**
58  * Add all formats common for a and b to ret, copy the refs and destroy
59  * a and b.
60  */
61 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
62 do { \
63  int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
64  \
65  if (!(ret = av_mallocz(sizeof(*ret)))) \
66  goto fail; \
67  \
68  if (count) { \
69  if (!(ret->fmts = av_malloc_array(count, sizeof(*ret->fmts)))) \
70  goto fail; \
71  for (i = 0; i < a->nb; i++) \
72  for (j = 0; j < b->nb; j++) \
73  if (a->fmts[i] == b->fmts[j]) { \
74  if(k >= FFMIN(a->nb, b->nb)){ \
75  av_log(NULL, AV_LOG_ERROR, "Duplicate formats in %s detected\n", __FUNCTION__); \
76  av_free(ret->fmts); \
77  av_free(ret); \
78  return NULL; \
79  } \
80  ret->fmts[k++] = a->fmts[i]; \
81  } \
82  } \
83  ret->nb = k; \
84  /* check that there was at least one common format */ \
85  if (!ret->nb) \
86  goto fail; \
87  \
88  MERGE_REF(ret, a, fmts, type, fail); \
89  MERGE_REF(ret, b, fmts, type, fail); \
90 } while (0)
91 
93  enum AVMediaType type)
94 {
95  AVFilterFormats *ret = NULL;
96  int i, j;
97  int alpha1=0, alpha2=0;
98  int chroma1=0, chroma2=0;
99 
100  if (a == b)
101  return a;
102 
103  /* Do not lose chroma or alpha in merging.
104  It happens if both lists have formats with chroma (resp. alpha), but
105  the only formats in common do not have it (e.g. YUV+gray vs.
106  RGB+gray): in that case, the merging would select the gray format,
107  possibly causing a lossy conversion elsewhere in the graph.
108  To avoid that, pretend that there are no common formats to force the
109  insertion of a conversion filter. */
110  if (type == AVMEDIA_TYPE_VIDEO)
111  for (i = 0; i < a->nb_formats; i++)
112  for (j = 0; j < b->nb_formats; j++) {
113  const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
114  const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
115  alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
116  chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
117  if (a->formats[i] == b->formats[j]) {
118  alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
119  chroma1|= adesc->nb_components > 1;
120  }
121  }
122 
123  // If chroma or alpha can be lost through merging then do not merge
124  if (alpha2 > alpha1 || chroma2 > chroma1)
125  return NULL;
126 
127  MERGE_FORMATS(ret, a, b, formats, nb_formats, AVFilterFormats, fail);
128 
129  return ret;
130 fail:
131  if (ret) {
132  av_freep(&ret->refs);
133  av_freep(&ret->formats);
134  }
135  av_freep(&ret);
136  return NULL;
137 }
138 
141 {
142  AVFilterFormats *ret = NULL;
143 
144  if (a == b) return a;
145 
146  if (a->nb_formats && b->nb_formats) {
147  MERGE_FORMATS(ret, a, b, formats, nb_formats, AVFilterFormats, fail);
148  } else if (a->nb_formats) {
150  ret = a;
151  } else {
153  ret = b;
154  }
155 
156  return ret;
157 fail:
158  if (ret) {
159  av_freep(&ret->refs);
160  av_freep(&ret->formats);
161  }
162  av_freep(&ret);
163  return NULL;
164 }
165 
168 {
170  unsigned a_all = a->all_layouts + a->all_counts;
171  unsigned b_all = b->all_layouts + b->all_counts;
172  int ret_max, ret_nb = 0, i, j, round;
173 
174  if (a == b) return a;
175 
176  /* Put the most generic set in a, to avoid doing everything twice */
177  if (a_all < b_all) {
179  FFSWAP(unsigned, a_all, b_all);
180  }
181  if (a_all) {
182  if (a_all == 1 && !b_all) {
183  /* keep only known layouts in b; works also for b_all = 1 */
184  for (i = j = 0; i < b->nb_channel_layouts; i++)
185  if (KNOWN(b->channel_layouts[i]))
186  b->channel_layouts[j++] = b->channel_layouts[i];
187  /* Not optimal: the unknown layouts of b may become known after
188  another merge. */
189  if (!j)
190  return NULL;
191  b->nb_channel_layouts = j;
192  }
194  return b;
195  }
196 
197  ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
198  if (!(ret = av_mallocz(sizeof(*ret))) ||
199  !(ret->channel_layouts = av_malloc_array(ret_max,
200  sizeof(*ret->channel_layouts))))
201  goto fail;
202 
203  /* a[known] intersect b[known] */
204  for (i = 0; i < a->nb_channel_layouts; i++) {
205  if (!KNOWN(a->channel_layouts[i]))
206  continue;
207  for (j = 0; j < b->nb_channel_layouts; j++) {
208  if (a->channel_layouts[i] == b->channel_layouts[j]) {
209  ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
210  a->channel_layouts[i] = b->channel_layouts[j] = 0;
211  }
212  }
213  }
214  /* 1st round: a[known] intersect b[generic]
215  2nd round: a[generic] intersect b[known] */
216  for (round = 0; round < 2; round++) {
217  for (i = 0; i < a->nb_channel_layouts; i++) {
218  uint64_t fmt = a->channel_layouts[i], bfmt;
219  if (!fmt || !KNOWN(fmt))
220  continue;
222  for (j = 0; j < b->nb_channel_layouts; j++)
223  if (b->channel_layouts[j] == bfmt)
224  ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
225  }
226  /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
228  }
229  /* a[generic] intersect b[generic] */
230  for (i = 0; i < a->nb_channel_layouts; i++) {
231  if (KNOWN(a->channel_layouts[i]))
232  continue;
233  for (j = 0; j < b->nb_channel_layouts; j++)
234  if (a->channel_layouts[i] == b->channel_layouts[j])
235  ret->channel_layouts[ret_nb++] = a->channel_layouts[i];
236  }
237 
238  ret->nb_channel_layouts = ret_nb;
239  if (!ret->nb_channel_layouts)
240  goto fail;
243  return ret;
244 
245 fail:
246  if (ret) {
247  av_freep(&ret->refs);
248  av_freep(&ret->channel_layouts);
249  }
250  av_freep(&ret);
251  return NULL;
252 }
253 
254 int ff_fmt_is_in(int fmt, const int *fmts)
255 {
256  const int *p;
257 
258  for (p = fmts; *p != -1; p++) {
259  if (fmt == *p)
260  return 1;
261  }
262  return 0;
263 }
264 
265 #define MAKE_FORMAT_LIST(type, field, count_field) \
266  type *formats; \
267  int count = 0; \
268  if (fmts) \
269  for (count = 0; fmts[count] != -1; count++) \
270  ; \
271  formats = av_mallocz(sizeof(*formats)); \
272  if (!formats) \
273  return NULL; \
274  formats->count_field = count; \
275  if (count) { \
276  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
277  if (!formats->field) { \
278  av_freep(&formats); \
279  return NULL; \
280  } \
281  }
282 
284 {
286  while (count--)
287  formats->formats[count] = fmts[count];
288 
289  return formats;
290 }
291 
293 {
295  channel_layouts, nb_channel_layouts);
296  if (count)
297  memcpy(formats->channel_layouts, fmts,
298  sizeof(*formats->channel_layouts) * count);
299 
300  return formats;
301 }
302 
304 {
306  channel_layouts, nb_channel_layouts);
307  if (count)
308  memcpy(formats->channel_layouts, fmts,
309  sizeof(*formats->channel_layouts) * count);
310 
311  return formats;
312 }
313 
314 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
315 do { \
316  type *fmts; \
317  void *oldf = *f; \
318  \
319  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
320  unref_fn(f); \
321  return AVERROR(ENOMEM); \
322  } \
323  \
324  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
325  sizeof(*(*f)->list)); \
326  if (!fmts) { \
327  unref_fn(f); \
328  if (!oldf) \
329  av_freep(f); \
330  return AVERROR(ENOMEM); \
331  } \
332  \
333  (*f)->list = fmts; \
334  (*f)->list[(*f)->nb++] = fmt; \
335 } while (0)
336 
337 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
338 {
339  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
340  return 0;
341 }
342 
343 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
344 {
345  av_assert1(!(*l && (*l)->all_layouts));
346  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
347  return 0;
348 }
349 
351 {
352  AVFilterFormats *ret = NULL;
353 
354  if (type == AVMEDIA_TYPE_VIDEO) {
355  const AVPixFmtDescriptor *desc = NULL;
356  while ((desc = av_pix_fmt_desc_next(desc))) {
357  if (ff_add_format(&ret, av_pix_fmt_desc_get_id(desc)) < 0)
358  return NULL;
359  }
360  } else if (type == AVMEDIA_TYPE_AUDIO) {
361  enum AVSampleFormat fmt = 0;
362  while (av_get_sample_fmt_name(fmt)) {
363  if (ff_add_format(&ret, fmt) < 0)
364  return NULL;
365  fmt++;
366  }
367  }
368 
369  return ret;
370 }
371 
372 const int64_t avfilter_all_channel_layouts[] = {
373 #include "all_channel_layouts.inc"
374  -1
375 };
376 
377 // AVFilterFormats *avfilter_make_all_channel_layouts(void)
378 // {
379 // return avfilter_make_format64_list(avfilter_all_channel_layouts);
380 // }
381 
383 {
384  AVFilterFormats *ret = NULL;
385  int fmt;
386 
387  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
388  if (av_sample_fmt_is_planar(fmt))
389  if (ff_add_format(&ret, fmt) < 0)
390  return NULL;
391 
392  return ret;
393 }
394 
396 {
397  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
398  return ret;
399 }
400 
402 {
403  AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
404  if (!ret)
405  return NULL;
406  ret->all_layouts = 1;
407  return ret;
408 }
409 
411 {
412  AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
413  if (!ret)
414  return NULL;
415  ret->all_layouts = ret->all_counts = 1;
416  return ret;
417 }
418 
419 #define FORMATS_REF(f, ref, unref_fn) \
420  void *tmp; \
421  \
422  if (!f || !ref) \
423  return AVERROR(ENOMEM); \
424  \
425  tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
426  if (!tmp) { \
427  unref_fn(&f); \
428  return AVERROR(ENOMEM); \
429  } \
430  f->refs = tmp; \
431  f->refs[f->refcount++] = ref; \
432  *ref = f; \
433  return 0
434 
436 {
438 }
439 
441 {
442  FORMATS_REF(f, ref, ff_formats_unref);
443 }
444 
445 #define FIND_REF_INDEX(ref, idx) \
446 do { \
447  int i; \
448  for (i = 0; i < (*ref)->refcount; i ++) \
449  if((*ref)->refs[i] == ref) { \
450  idx = i; \
451  break; \
452  } \
453 } while (0)
454 
455 #define FORMATS_UNREF(ref, list) \
456 do { \
457  int idx = -1; \
458  \
459  if (!*ref || !(*ref)->refs) \
460  return; \
461  \
462  FIND_REF_INDEX(ref, idx); \
463  \
464  if (idx >= 0) \
465  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
466  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
467  \
468  if(!--(*ref)->refcount) { \
469  av_free((*ref)->list); \
470  av_free((*ref)->refs); \
471  av_free(*ref); \
472  } \
473  *ref = NULL; \
474 } while (0)
475 
477 {
478  FORMATS_UNREF(ref, formats);
479 }
480 
482 {
484 }
485 
486 #define FORMATS_CHANGEREF(oldref, newref) \
487 do { \
488  int idx = -1; \
489  \
490  FIND_REF_INDEX(oldref, idx); \
491  \
492  if (idx >= 0) { \
493  (*oldref)->refs[idx] = newref; \
494  *newref = *oldref; \
495  *oldref = NULL; \
496  } \
497 } while (0)
498 
500  AVFilterChannelLayouts **newref)
501 {
502  FORMATS_CHANGEREF(oldref, newref);
503 }
504 
506 {
507  FORMATS_CHANGEREF(oldref, newref);
508 }
509 
510 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn, list) \
511  int count = 0, i; \
512  \
513  if (!fmts) \
514  return AVERROR(ENOMEM); \
515  \
516  for (i = 0; i < ctx->nb_inputs; i++) { \
517  if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
518  int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts); \
519  if (ret < 0) { \
520  unref_fn(&fmts); \
521  av_freep(&fmts->list); \
522  av_freep(&fmts); \
523  return ret; \
524  } \
525  count++; \
526  } \
527  } \
528  for (i = 0; i < ctx->nb_outputs; i++) { \
529  if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
530  int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts); \
531  if (ret < 0) { \
532  unref_fn(&fmts); \
533  av_freep(&fmts->list); \
534  av_freep(&fmts); \
535  return ret; \
536  } \
537  count++; \
538  } \
539  } \
540  \
541  if (!count) { \
542  av_freep(&fmts->list); \
543  av_freep(&fmts->refs); \
544  av_freep(&fmts); \
545  } \
546  \
547  return 0;
548 
551 {
552  SET_COMMON_FORMATS(ctx, layouts, in_channel_layouts, out_channel_layouts,
554 }
555 
557  AVFilterFormats *samplerates)
558 {
559  SET_COMMON_FORMATS(ctx, samplerates, in_samplerates, out_samplerates,
561 }
562 
563 /**
564  * A helper for query_formats() which sets all links to the same list of
565  * formats. If there are no links hooked to this filter, the list of formats is
566  * freed.
567  */
569 {
570  SET_COMMON_FORMATS(ctx, formats, in_formats, out_formats,
571  ff_formats_ref, ff_formats_unref, formats);
572 }
573 
576 {
577  int ret;
578  enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type :
579  ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
581 
582  ret = ff_set_common_formats(ctx, ff_all_formats(type));
583  if (ret < 0)
584  return ret;
585  if (type == AVMEDIA_TYPE_AUDIO) {
587  if (ret < 0)
588  return ret;
590  if (ret < 0)
591  return ret;
592  }
593 
594  return 0;
595 }
596 
598 {
600 }
601 
603 {
605 }
606 
607 /* internal functions for parsing audio format arguments */
608 
609 int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
610 {
611  char *tail;
612  int pix_fmt = av_get_pix_fmt(arg);
613  if (pix_fmt == AV_PIX_FMT_NONE) {
614  pix_fmt = strtol(arg, &tail, 0);
615  if (*tail || !av_pix_fmt_desc_get(pix_fmt)) {
616  av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg);
617  return AVERROR(EINVAL);
618  }
619  }
620  *ret = pix_fmt;
621  return 0;
622 }
623 
624 int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx)
625 {
626  char *tail;
627  int sfmt = av_get_sample_fmt(arg);
628  if (sfmt == AV_SAMPLE_FMT_NONE) {
629  sfmt = strtol(arg, &tail, 0);
630  if (*tail || av_get_bytes_per_sample(sfmt)<=0) {
631  av_log(log_ctx, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg);
632  return AVERROR(EINVAL);
633  }
634  }
635  *ret = sfmt;
636  return 0;
637 }
638 
639 int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx)
640 {
641  AVRational r;
642  if(av_parse_ratio(&r, arg, INT_MAX, 0, log_ctx) < 0 ||r.num<=0 ||r.den<=0) {
643  av_log(log_ctx, AV_LOG_ERROR, "Invalid time base '%s'\n", arg);
644  return AVERROR(EINVAL);
645  }
646  *ret = r;
647  return 0;
648 }
649 
650 int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
651 {
652  char *tail;
653  double srate = av_strtod(arg, &tail);
654  if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
655  av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
656  return AVERROR(EINVAL);
657  }
658  *ret = srate;
659  return 0;
660 }
661 
662 int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
663  void *log_ctx)
664 {
665  int64_t chlayout;
666  int nb_channels;
667 
668  if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0) {
669  av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
670  return AVERROR(EINVAL);
671  }
672  if (!chlayout && !nret) {
673  av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
674  return AVERROR(EINVAL);
675  }
676  *ret = chlayout;
677  if (nret)
678  *nret = nb_channels;
679 
680  return 0;
681 }
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.
Definition: parseutils.c:45
#define NULL
Definition: coverity.c:32
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...
Definition: formats.c:549
static enum AVPixelFormat pix_fmt
#define FORMATS_UNREF(ref, list)
Definition: formats.c:455
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2363
const char * fmt
Definition: avisynth_c.h:769
int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
Parse a pixel format.
Definition: formats.c:609
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:65
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:499
const int64_t avfilter_all_channel_layouts[]
Definition: formats.c:372
int num
Numerator.
Definition: rational.h:59
const char * b
Definition: vf_curves.c:113
struct AVFilterChannelLayouts *** refs
references to this list
Definition: formats.h:92
int ff_query_formats_all_layouts(AVFilterContext *ctx)
Set the formats list to all known channel layouts.
Definition: formats.c:602
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:181
struct AVFilterFormats *** refs
references to this list
Definition: formats.h:69
static int default_query_formats_common(AVFilterContext *ctx, AVFilterChannelLayouts *(layouts)(void))
Definition: formats.c:574
int ff_fmt_is_in(int fmt, const int *fmts)
Tell if an integer is contained in the provided -1-terminated list of integers.
Definition: formats.c:254
#define av_log(a,...)
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:350
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Before After |formats |<------—.
Definition: formats.c:505
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
#define AVERROR(e)
Definition: error.h:43
const char * r
Definition: vf_curves.c:111
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.
Definition: formats.c:662
uint64_t * channel_layouts
list of channel layouts
Definition: formats.h:86
const char * arg
Definition: jacosubdec.c:66
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
static av_always_inline av_const double round(double x)
Definition: libm.h:444
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.
Definition: samplefmt.c:49
int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx)
Parse a sample format name or a corresponding integer representation.
Definition: formats.c:624
#define fail()
Definition: checkasm.h:116
char all_counts
accept any channel layout or count
Definition: formats.h:89
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2382
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
audio channel layout utility functions
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define MAKE_FORMAT_LIST(type, field, count_field)
Definition: formats.c:265
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
AVFormatContext * ctx
Definition: movenc.c:48
int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx)
Parse a time base.
Definition: formats.c:639
unsigned nb_formats
number of formats
Definition: formats.h:65
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:382
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (...
Definition: formats.c:401
A list of supported channel layouts.
Definition: formats.h:85
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:597
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:419
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:303
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
char all_layouts
accept any known channel layout
Definition: formats.h:88
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:486
AVFilterChannelLayouts * ff_merge_channel_layouts(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b)
Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates ...
Definition: formats.c:166
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.
Definition: formats.c:92
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:481
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:113
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:314
Rational number (pair of numerator and denominator).
Definition: rational.h:58
cl_device_type type
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:56
AVMediaType
Definition: avutil.h:199
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to...
Definition: formats.c:476
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn, list)
Definition: formats.c:510
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
#define KNOWN(l)
Definition: formats.c:32
AVFilterChannelLayouts * ff_make_formatu64_list(const uint64_t *fmts)
Definition: formats.c:292
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
common internal and external API header
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
int den
Denominator.
Definition: rational.h:60
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
Parse a sample rate.
Definition: formats.c:650
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
#define av_malloc_array(a, b)
formats
Definition: signature.h:48
#define FFSWAP(type, a, b)
Definition: common.h:99
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2291
int nb_channels
AVFilterFormats * ff_merge_samplerates(AVFilterFormats *a, AVFilterFormats *b)
Definition: formats.c:139
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
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 ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
simple arithmetic expression evaluator
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2370
int * formats
list of media formats
Definition: formats.h:66
#define MERGE_REF(ret, a, fmts, type, fail)
Add all refs from a to ret and destroy a.
Definition: formats.c:37
#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: formats.c:61