FFmpeg
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  * ret->refs must have enough spare room left for this.
37  */
38 #define MERGE_REF_NO_ALLOC(ret, a, fmts) \
39 do { \
40  int i; \
41  for (i = 0; i < a->refcount; i ++) { \
42  ret->refs[ret->refcount] = a->refs[i]; \
43  *ret->refs[ret->refcount++] = ret; \
44  } \
45  \
46  av_freep(&a->refs); \
47  av_freep(&a->fmts); \
48  av_freep(&a); \
49 } while (0)
50 
51 #define MERGE_REF(ret, a, fmts, type, fail) \
52 do { \
53  type ***tmp; \
54  \
55  if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
56  sizeof(*tmp)))) \
57  goto fail; \
58  ret->refs = tmp; \
59  MERGE_REF_NO_ALLOC(ret, a, fmts); \
60 } while (0)
61 
62 /**
63  * Add all formats common for a and b to ret, copy the refs and destroy
64  * a and b.
65  */
66 #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
67 do { \
68  int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
69  type ***tmp; \
70  \
71  if (!(ret = av_mallocz(sizeof(*ret)))) \
72  goto fail; \
73  \
74  if (count) { \
75  if (!(ret->fmts = av_malloc_array(count, sizeof(*ret->fmts)))) \
76  goto fail; \
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__); \
82  av_free(ret->fmts); \
83  av_free(ret); \
84  return NULL; \
85  } \
86  ret->fmts[k++] = a->fmts[i]; \
87  } \
88  } \
89  ret->nb = k; \
90  /* check that there was at least one common format */ \
91  if (!ret->nb) \
92  goto fail; \
93  \
94  tmp = av_realloc_array(NULL, a->refcount + b->refcount, sizeof(*tmp)); \
95  if (!tmp) \
96  goto fail; \
97  ret->refs = tmp; \
98  \
99  MERGE_REF_NO_ALLOC(ret, a, fmts); \
100  MERGE_REF_NO_ALLOC(ret, b, fmts); \
101 } while (0)
102 
104  enum AVMediaType type)
105 {
107  int i, j;
108  int alpha1=0, alpha2=0;
109  int chroma1=0, chroma2=0;
110 
111  if (a == b)
112  return a;
113 
114  /* Do not lose chroma or alpha in merging.
115  It happens if both lists have formats with chroma (resp. alpha), but
116  the only formats in common do not have it (e.g. YUV+gray vs.
117  RGB+gray): in that case, the merging would select the gray format,
118  possibly causing a lossy conversion elsewhere in the graph.
119  To avoid that, pretend that there are no common formats to force the
120  insertion of a conversion filter. */
121  if (type == AVMEDIA_TYPE_VIDEO)
122  for (i = 0; i < a->nb_formats; i++)
123  for (j = 0; j < b->nb_formats; j++) {
124  const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
125  const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
126  alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
127  chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
128  if (a->formats[i] == b->formats[j]) {
129  alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
130  chroma1|= adesc->nb_components > 1;
131  }
132  }
133 
134  // If chroma or alpha can be lost through merging then do not merge
135  if (alpha2 > alpha1 || chroma2 > chroma1)
136  return NULL;
137 
138  MERGE_FORMATS(ret, a, b, formats, nb_formats, AVFilterFormats, fail);
139 
140  return ret;
141 fail:
142  if (ret) {
143  av_freep(&ret->refs);
144  av_freep(&ret->formats);
145  }
146  av_freep(&ret);
147  return NULL;
148 }
149 
152 {
154 
155  if (a == b) return a;
156 
157  if (a->nb_formats && b->nb_formats) {
158  MERGE_FORMATS(ret, a, b, formats, nb_formats, AVFilterFormats, fail);
159  } else if (a->nb_formats) {
161  ret = a;
162  } else {
164  ret = b;
165  }
166 
167  return ret;
168 fail:
169  if (ret) {
170  av_freep(&ret->refs);
171  av_freep(&ret->formats);
172  }
173  av_freep(&ret);
174  return NULL;
175 }
176 
179 {
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;
184 
185  if (a == b) return a;
186 
187  /* Put the most generic set in a, to avoid doing everything twice */
188  if (a_all < b_all) {
190  FFSWAP(unsigned, a_all, b_all);
191  }
192  if (a_all) {
193  if (a_all == 1 && !b_all) {
194  /* keep only known layouts in b; works also for b_all = 1 */
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];
198  /* Not optimal: the unknown layouts of b may become known after
199  another merge. */
200  if (!j)
201  return NULL;
202  b->nb_channel_layouts = j;
203  }
205  return b;
206  }
207 
208  ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
209  if (!(ret = av_mallocz(sizeof(*ret))) ||
210  !(ret->channel_layouts = av_malloc_array(ret_max,
211  sizeof(*ret->channel_layouts))))
212  goto fail;
213 
214  /* a[known] intersect b[known] */
215  for (i = 0; i < a->nb_channel_layouts; i++) {
216  if (!KNOWN(a->channel_layouts[i]))
217  continue;
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;
222  break;
223  }
224  }
225  }
226  /* 1st round: a[known] intersect b[generic]
227  2nd round: a[generic] intersect b[known] */
228  for (round = 0; round < 2; round++) {
229  for (i = 0; i < a->nb_channel_layouts; i++) {
230  uint64_t fmt = a->channel_layouts[i], bfmt;
231  if (!fmt || !KNOWN(fmt))
232  continue;
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];
237  }
238  /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
240  }
241  /* a[generic] intersect b[generic] */
242  for (i = 0; i < a->nb_channel_layouts; i++) {
243  if (KNOWN(a->channel_layouts[i]))
244  continue;
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];
248  }
249 
250  ret->nb_channel_layouts = ret_nb;
251  if (!ret->nb_channel_layouts)
252  goto fail;
253 
254  ret->refs = av_realloc_array(NULL, a->refcount + b->refcount,
255  sizeof(*ret->refs));
256  if (!ret->refs)
257  goto fail;
260  return ret;
261 
262 fail:
263  if (ret) {
264  av_freep(&ret->refs);
265  av_freep(&ret->channel_layouts);
266  }
267  av_freep(&ret);
268  return NULL;
269 }
270 
271 int ff_fmt_is_in(int fmt, const int *fmts)
272 {
273  const int *p;
274 
275  for (p = fmts; *p != -1; p++) {
276  if (fmt == *p)
277  return 1;
278  }
279  return 0;
280 }
281 
282 #define MAKE_FORMAT_LIST(type, field, count_field) \
283  type *formats; \
284  int count = 0; \
285  if (fmts) \
286  for (count = 0; fmts[count] != -1; count++) \
287  ; \
288  formats = av_mallocz(sizeof(*formats)); \
289  if (!formats) \
290  return NULL; \
291  formats->count_field = count; \
292  if (count) { \
293  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
294  if (!formats->field) { \
295  av_freep(&formats); \
296  return NULL; \
297  } \
298  }
299 
301 {
303  while (count--)
304  formats->formats[count] = fmts[count];
305 
306  return formats;
307 }
308 
310 {
312  channel_layouts, nb_channel_layouts);
313  if (count)
314  memcpy(formats->channel_layouts, fmts,
315  sizeof(*formats->channel_layouts) * count);
316 
317  return formats;
318 }
319 
321 {
323  channel_layouts, nb_channel_layouts);
324  if (count)
325  memcpy(formats->channel_layouts, fmts,
326  sizeof(*formats->channel_layouts) * count);
327 
328  return formats;
329 }
330 
331 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
332 do { \
333  type *fmts; \
334  \
335  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
336  return AVERROR(ENOMEM); \
337  } \
338  \
339  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
340  sizeof(*(*f)->list)); \
341  if (!fmts) { \
342  unref_fn(f); \
343  return AVERROR(ENOMEM); \
344  } \
345  \
346  (*f)->list = fmts; \
347  (*f)->list[(*f)->nb++] = fmt; \
348 } while (0)
349 
350 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
351 {
352  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
353  return 0;
354 }
355 
356 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
357 {
358  av_assert1(!(*l && (*l)->all_layouts));
359  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
360  return 0;
361 }
362 
364 {
366 
367  if (type == AVMEDIA_TYPE_VIDEO) {
368  const AVPixFmtDescriptor *desc = NULL;
369  while ((desc = av_pix_fmt_desc_next(desc))) {
371  return NULL;
372  }
373  } else if (type == AVMEDIA_TYPE_AUDIO) {
374  enum AVSampleFormat fmt = 0;
375  while (av_get_sample_fmt_name(fmt)) {
376  if (ff_add_format(&ret, fmt) < 0)
377  return NULL;
378  fmt++;
379  }
380  }
381 
382  return ret;
383 }
384 
385 int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej)
386 {
387  unsigned nb_formats, fmt, flags;
389 
390  while (1) {
391  nb_formats = 0;
392  for (fmt = 0;; fmt++) {
394  if (!desc)
395  break;
396  flags = desc->flags;
397  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
398  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
399  (desc->log2_chroma_w || desc->log2_chroma_h))
401  if ((flags & (want | rej)) != want)
402  continue;
403  if (formats)
404  formats->formats[nb_formats] = fmt;
405  nb_formats++;
406  }
407  if (formats) {
408  av_assert0(formats->nb_formats == nb_formats);
409  *rfmts = formats;
410  return 0;
411  }
412  formats = av_mallocz(sizeof(*formats));
413  if (!formats)
414  return AVERROR(ENOMEM);
415  formats->nb_formats = nb_formats;
416  if (nb_formats) {
417  formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
418  if (!formats->formats) {
419  av_freep(&formats);
420  return AVERROR(ENOMEM);
421  }
422  }
423  }
424 }
425 
427 {
429  int fmt;
430 
431  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
432  if (av_sample_fmt_is_planar(fmt))
433  if (ff_add_format(&ret, fmt) < 0)
434  return NULL;
435 
436  return ret;
437 }
438 
440 {
441  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
442  return ret;
443 }
444 
446 {
448  if (!ret)
449  return NULL;
450  ret->all_layouts = 1;
451  return ret;
452 }
453 
455 {
457  if (!ret)
458  return NULL;
459  ret->all_layouts = ret->all_counts = 1;
460  return ret;
461 }
462 
463 #define FORMATS_REF(f, ref, unref_fn) \
464  void *tmp; \
465  \
466  if (!f || !ref) \
467  return AVERROR(ENOMEM); \
468  \
469  tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
470  if (!tmp) { \
471  unref_fn(&f); \
472  return AVERROR(ENOMEM); \
473  } \
474  f->refs = tmp; \
475  f->refs[f->refcount++] = ref; \
476  *ref = f; \
477  return 0
478 
480 {
482 }
483 
485 {
487 }
488 
489 #define FIND_REF_INDEX(ref, idx) \
490 do { \
491  int i; \
492  for (i = 0; i < (*ref)->refcount; i ++) \
493  if((*ref)->refs[i] == ref) { \
494  idx = i; \
495  break; \
496  } \
497 } while (0)
498 
499 #define FORMATS_UNREF(ref, list) \
500 do { \
501  int idx = -1; \
502  \
503  if (!ref || !*ref) \
504  return; \
505  \
506  FIND_REF_INDEX(ref, idx); \
507  \
508  if (idx >= 0) { \
509  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
510  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
511  --(*ref)->refcount; \
512  } \
513  if (!(*ref)->refcount) { \
514  av_free((*ref)->list); \
515  av_free((*ref)->refs); \
516  av_free(*ref); \
517  } \
518  *ref = NULL; \
519 } while (0)
520 
522 {
524 }
525 
527 {
529 }
530 
531 #define FORMATS_CHANGEREF(oldref, newref) \
532 do { \
533  int idx = -1; \
534  \
535  FIND_REF_INDEX(oldref, idx); \
536  \
537  if (idx >= 0) { \
538  (*oldref)->refs[idx] = newref; \
539  *newref = *oldref; \
540  *oldref = NULL; \
541  } \
542 } while (0)
543 
545  AVFilterChannelLayouts **newref)
546 {
547  FORMATS_CHANGEREF(oldref, newref);
548 }
549 
551 {
552  FORMATS_CHANGEREF(oldref, newref);
553 }
554 
555 #define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn) \
556  int count = 0, i; \
557  \
558  if (!fmts) \
559  return AVERROR(ENOMEM); \
560  \
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); \
564  if (ret < 0) { \
565  return ret; \
566  } \
567  count++; \
568  } \
569  } \
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); \
573  if (ret < 0) { \
574  return ret; \
575  } \
576  count++; \
577  } \
578  } \
579  \
580  if (!count) { \
581  unref_fn(&fmts); \
582  } \
583  \
584  return 0;
585 
588 {
589  SET_COMMON_FORMATS(ctx, layouts, in_channel_layouts, out_channel_layouts,
591 }
592 
594  AVFilterFormats *samplerates)
595 {
596  SET_COMMON_FORMATS(ctx, samplerates, in_samplerates, out_samplerates,
598 }
599 
600 /**
601  * A helper for query_formats() which sets all links to the same list of
602  * formats. If there are no links hooked to this filter, the list of formats is
603  * freed.
604  */
606 {
607  SET_COMMON_FORMATS(ctx, formats, in_formats, out_formats,
609 }
610 
613 {
614  int ret;
615  enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type :
616  ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
618 
620  if (ret < 0)
621  return ret;
622  if (type == AVMEDIA_TYPE_AUDIO) {
624  if (ret < 0)
625  return ret;
627  if (ret < 0)
628  return ret;
629  }
630 
631  return 0;
632 }
633 
635 {
637 }
638 
640 {
642 }
643 
644 /* internal functions for parsing audio format arguments */
645 
646 int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
647 {
648  char *tail;
649  int pix_fmt = av_get_pix_fmt(arg);
650  if (pix_fmt == AV_PIX_FMT_NONE) {
651  pix_fmt = strtol(arg, &tail, 0);
652  if (*tail || !av_pix_fmt_desc_get(pix_fmt)) {
653  av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg);
654  return AVERROR(EINVAL);
655  }
656  }
657  *ret = pix_fmt;
658  return 0;
659 }
660 
661 int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx)
662 {
663  char *tail;
664  int sfmt = av_get_sample_fmt(arg);
665  if (sfmt == AV_SAMPLE_FMT_NONE) {
666  sfmt = strtol(arg, &tail, 0);
667  if (*tail || av_get_bytes_per_sample(sfmt)<=0) {
668  av_log(log_ctx, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg);
669  return AVERROR(EINVAL);
670  }
671  }
672  *ret = sfmt;
673  return 0;
674 }
675 
676 int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx)
677 {
678  AVRational r;
679  if(av_parse_ratio(&r, arg, INT_MAX, 0, log_ctx) < 0 ||r.num<=0 ||r.den<=0) {
680  av_log(log_ctx, AV_LOG_ERROR, "Invalid time base '%s'\n", arg);
681  return AVERROR(EINVAL);
682  }
683  *ret = r;
684  return 0;
685 }
686 
687 int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
688 {
689  char *tail;
690  double srate = av_strtod(arg, &tail);
691  if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
692  av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
693  return AVERROR(EINVAL);
694  }
695  *ret = srate;
696  return 0;
697 }
698 
699 int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
700  void *log_ctx)
701 {
702  int64_t chlayout;
703  int nb_channels;
704 
705  if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0) {
706  av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
707  return AVERROR(EINVAL);
708  }
709  if (!chlayout && !nret) {
710  av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
711  return AVERROR(EINVAL);
712  }
713  *ret = chlayout;
714  if (nret)
715  *nret = nb_channels;
716 
717  return 0;
718 }
formats
formats
Definition: signature.h:48
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
r
const char * r
Definition: vf_curves.c:114
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:300
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: formats.c:66
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
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.
Definition: formats.c:586
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:479
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
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: formats.c:385
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:454
pixdesc.h
SET_COMMON_FORMATS
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn)
Definition: formats.c:555
b
#define b
Definition: input.c:41
av_pix_fmt_desc_next
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2556
MERGE_REF
#define MERGE_REF(ret, a, fmts, type, fail)
Definition: formats.c:51
default_query_formats_common
static int default_query_formats_common(AVFilterContext *ctx, AVFilterChannelLayouts *(layouts)(void))
Definition: formats.c:611
FORMATS_UNREF
#define FORMATS_UNREF(ref, list)
Definition: formats.c:499
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
fail
#define fail()
Definition: checkasm.h:123
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:140
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
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: formats.c:363
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.
Definition: formats.c:661
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
ff_set_common_formats
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:605
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:356
ff_query_formats_all_layouts
int ff_query_formats_all_layouts(AVFilterContext *ctx)
Set the formats list to all known channel layouts.
Definition: formats.c:639
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:198
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:484
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:177
ctx
AVFormatContext * ctx
Definition: movenc.c:48
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:40
av_get_sample_fmt_name
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
f
#define f(width, name)
Definition: cbs_vp9.c:255
arg
const char * arg
Definition: jacosubdec.c:66
ff_formats_changeref
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Definition: formats.c:550
NULL
#define NULL
Definition: coverity.c:32
MAKE_FORMAT_LIST
#define MAKE_FORMAT_LIST(type, field, count_field)
Definition: formats.c:282
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MERGE_REF_NO_ALLOC
#define MERGE_REF_NO_ALLOC(ret, a, fmts)
Add all refs from a to ret and destroy a.
Definition: formats.c:38
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:350
parseutils.h
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.
Definition: formats.c:271
av_parse_ratio
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
ff_parse_time_base
int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx)
Parse a time base.
Definition: formats.c:676
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
ff_channel_layouts_unref
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:526
av_get_channel_layout_nb_channels
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: channel_layout.c:220
eval.h
desc
const char * desc
Definition: nvenc.c:79
AVMediaType
AVMediaType
Definition: avutil.h:199
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:232
ff_default_query_formats
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:634
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.
Definition: formats.c:699
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AVFilterChannelLayouts::all_layouts
char all_layouts
accept any known channel layout
Definition: formats.h:88
KNOWN
#define KNOWN(l)
Definition: formats.c:32
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
av_pix_fmt_desc_get_id
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2568
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:445
ADD_FORMAT
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:331
internal.h
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,...
Definition: formats.c:521
FORMATS_REF
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:463
avfilter_make_format64_list
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:320
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
av_get_sample_fmt
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
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
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 ...
Definition: formats.c:177
common.h
FORMATS_CHANGEREF
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:531
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
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.
Definition: formats.c:103
ff_make_formatu64_list
AVFilterChannelLayouts * ff_make_formatu64_list(const uint64_t *fmts)
Definition: formats.c:309
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
ff_planar_sample_fmts
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:426
ret
ret
Definition: filter_design.txt:187
av_strtod
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
FF_COUNT2LAYOUT
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2477
ff_merge_samplerates
AVFilterFormats * ff_merge_samplerates(AVFilterFormats *a, AVFilterFormats *b)
Definition: formats.c:150
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:439
channel_layout.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
av_get_extended_channel_layout
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.
Definition: channel_layout.c:155
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:113
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ff_parse_sample_rate
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
Parse a sample rate.
Definition: formats.c:687
ff_parse_pixel_format
int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
Parse a pixel format.
Definition: formats.c:646
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:593
ff_channel_layouts_changeref
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:544
nb_channels
int nb_channels
Definition: channel_layout.c:76