FFmpeg
avfiltergraph.c
Go to the documentation of this file.
1 /*
2  * filter graphs
3  * Copyright (c) 2008 Vitor Sessak
4  * Copyright (c) 2007 Bobby Bingham
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config.h"
24 
25 #include <string.h>
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/bprint.h"
30 #include "libavutil/hwcontext.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 
35 
36 #include "avfilter.h"
37 #include "avfilter_internal.h"
38 #include "buffersink.h"
39 #include "formats.h"
40 #include "framequeue.h"
41 #include "internal.h"
42 
43 #define OFFSET(x) offsetof(AVFilterGraph, x)
44 #define F AV_OPT_FLAG_FILTERING_PARAM
45 #define V AV_OPT_FLAG_VIDEO_PARAM
46 #define A AV_OPT_FLAG_AUDIO_PARAM
47 static const AVOption filtergraph_options[] = {
48  { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
49  { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, F|V|A, .unit = "thread_type" },
50  { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = F|V|A, .unit = "thread_type" },
51  { "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT,
52  { .i64 = 0 }, 0, INT_MAX, F|V|A, .unit = "threads"},
53  {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"},
54  {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
55  AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V },
56  {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
57  AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|A },
58  { NULL },
59 };
60 
61 static const AVClass filtergraph_class = {
62  .class_name = "AVFilterGraph",
63  .item_name = av_default_item_name,
64  .version = LIBAVUTIL_VERSION_INT,
65  .option = filtergraph_options,
66  .category = AV_CLASS_CATEGORY_FILTER,
67 };
68 
69 #if !HAVE_THREADS
71 {
72 }
73 
75 {
76  graph->p.thread_type = 0;
77  graph->p.nb_threads = 1;
78  return 0;
79 }
80 #endif
81 
83 {
84  FFFilterGraph *graph = av_mallocz(sizeof(*graph));
86 
87  if (!graph)
88  return NULL;
89 
90  ret = &graph->p;
91  ret->av_class = &filtergraph_class;
94 
95  return ret;
96 }
97 
99 {
100  int i, j;
101  for (i = 0; i < graph->nb_filters; i++) {
102  if (graph->filters[i] == filter) {
103  FFSWAP(AVFilterContext*, graph->filters[i],
104  graph->filters[graph->nb_filters - 1]);
105  graph->nb_filters--;
106  filter->graph = NULL;
107  for (j = 0; j<filter->nb_outputs; j++)
108  if (filter->outputs[j])
109  filter->outputs[j]->graph = NULL;
110 
111  return;
112  }
113  }
114 }
115 
117 {
118  AVFilterGraph *graph = *graphp;
119  FFFilterGraph *graphi = fffiltergraph(graph);
120 
121  if (!graph)
122  return;
123 
124  while (graph->nb_filters)
125  avfilter_free(graph->filters[0]);
126 
127  ff_graph_thread_free(graphi);
128 
129  av_freep(&graphi->sink_links);
130 
131  av_opt_free(graph);
132 
133  av_freep(&graph->filters);
134  av_freep(graphp);
135 }
136 
138  const char *name, const char *args, void *opaque,
139  AVFilterGraph *graph_ctx)
140 {
141  int ret;
142 
143  *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
144  if (!*filt_ctx)
145  return AVERROR(ENOMEM);
146 
147  ret = avfilter_init_str(*filt_ctx, args);
148  if (ret < 0)
149  goto fail;
150 
151  return 0;
152 
153 fail:
154  avfilter_free(*filt_ctx);
155  *filt_ctx = NULL;
156  return ret;
157 }
158 
160 {
162 }
163 
165  const AVFilter *filter,
166  const char *name)
167 {
169  FFFilterGraph *graphi = fffiltergraph(graph);
170 
171  if (graph->thread_type && !graphi->thread_execute) {
172  if (graph->execute) {
173  graphi->thread_execute = graph->execute;
174  } else {
175  int ret = ff_graph_thread_init(graphi);
176  if (ret < 0) {
177  av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
178  return NULL;
179  }
180  }
181  }
182 
183  filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
184  if (!filters)
185  return NULL;
186  graph->filters = filters;
187 
189  if (!s)
190  return NULL;
191 
192  graph->filters[graph->nb_filters++] = s;
193 
194  s->graph = graph;
195 
196  return s;
197 }
198 
199 /**
200  * Check for the validity of graph.
201  *
202  * A graph is considered valid if all its input and output pads are
203  * connected.
204  *
205  * @return >= 0 in case of success, a negative value otherwise
206  */
207 static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
208 {
210  int i, j;
211 
212  for (i = 0; i < graph->nb_filters; i++) {
213  const AVFilterPad *pad;
214  filt = graph->filters[i];
215 
216  for (j = 0; j < filt->nb_inputs; j++) {
217  if (!filt->inputs[j] || !filt->inputs[j]->src) {
218  pad = &filt->input_pads[j];
219  av_log(log_ctx, AV_LOG_ERROR,
220  "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
221  pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
222  return AVERROR(EINVAL);
223  }
224  }
225 
226  for (j = 0; j < filt->nb_outputs; j++) {
227  if (!filt->outputs[j] || !filt->outputs[j]->dst) {
228  pad = &filt->output_pads[j];
229  av_log(log_ctx, AV_LOG_ERROR,
230  "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
231  pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
232  return AVERROR(EINVAL);
233  }
234  }
235  }
236 
237  return 0;
238 }
239 
240 /**
241  * Configure all the links of graphctx.
242  *
243  * @return >= 0 in case of success, a negative value otherwise
244  */
245 static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
246 {
248  int i, ret;
249 
250  for (i = 0; i < graph->nb_filters; i++) {
251  filt = graph->filters[i];
252 
253  if (!filt->nb_outputs) {
254  if ((ret = avfilter_config_links(filt)))
255  return ret;
256  }
257  }
258 
259  return 0;
260 }
261 
262 static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
263 {
265  AVFilterLink *l;
266  unsigned i, j;
267  int ret;
268 
269  for (i = 0; i < graph->nb_filters; i++) {
270  f = graph->filters[i];
271  for (j = 0; j < f->nb_outputs; j++) {
272  l = f->outputs[j];
273  if (l->type == AVMEDIA_TYPE_VIDEO) {
274  ret = av_image_check_size2(l->w, l->h, INT64_MAX, l->format, 0, f);
275  if (ret < 0)
276  return ret;
277  }
278  }
279  }
280  return 0;
281 }
282 
284 {
285  int i;
286 
287  for (i = 0; i < graph->nb_filters; i++)
288  if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
289  return graph->filters[i];
290 
291  return NULL;
292 }
293 
295 {
296  int ret;
297 
298  switch (link->type) {
299 
300  case AVMEDIA_TYPE_VIDEO:
301  if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 ||
304  return ret;
305  break;
306 
307  case AVMEDIA_TYPE_AUDIO:
308  if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
311  return ret;
312  break;
313 
314  default:
315  av_assert0(!"reached");
316  }
317  return 0;
318 }
319 
320 /**
321  * Check the validity of the formats / etc. lists set by query_formats().
322  *
323  * In particular, check they do not contain any redundant element.
324  */
326 {
327  unsigned i;
328  int ret;
329 
330  for (i = 0; i < ctx->nb_inputs; i++) {
331  ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
332  if (ret < 0)
333  return ret;
334  }
335  for (i = 0; i < ctx->nb_outputs; i++) {
336  ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
337  if (ret < 0)
338  return ret;
339  }
340  return 0;
341 }
342 
344 {
345  int ret;
346 
347  if (ctx->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
348  if ((ret = ctx->filter->formats.query_func(ctx)) < 0) {
349  if (ret != AVERROR(EAGAIN))
350  av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
351  ctx->name, av_err2str(ret));
352  return ret;
353  }
354 
356  if (ret < 0)
357  return ret;
358  }
359 
361 }
362 
364 {
365  int i;
366 
367  for (i = 0; i < f->nb_inputs; i++) {
368  if (!f->inputs[i]->outcfg.formats)
369  return 0;
370  if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO &&
371  !(f->inputs[i]->outcfg.color_ranges &&
372  f->inputs[i]->outcfg.color_spaces))
373  return 0;
374  if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO &&
375  !(f->inputs[i]->outcfg.samplerates &&
376  f->inputs[i]->outcfg.channel_layouts))
377  return 0;
378  }
379  for (i = 0; i < f->nb_outputs; i++) {
380  if (!f->outputs[i]->incfg.formats)
381  return 0;
382  if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO &&
383  !(f->outputs[i]->incfg.color_ranges &&
384  f->outputs[i]->incfg.color_spaces))
385  return 0;
386  if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO &&
387  !(f->outputs[i]->incfg.samplerates &&
388  f->outputs[i]->incfg.channel_layouts))
389  return 0;
390  }
391  return 1;
392 }
393 
394 /**
395  * Perform one round of query_formats() and merging formats lists on the
396  * filter graph.
397  * @return >=0 if all links formats lists could be queried and merged;
398  * AVERROR(EAGAIN) some progress was made in the queries or merging
399  * and a later call may succeed;
400  * AVERROR(EIO) (may be changed) plus a log message if no progress
401  * was made and the negotiation is stuck;
402  * a negative error code if some other error happened
403  */
404 static int query_formats(AVFilterGraph *graph, void *log_ctx)
405 {
406  int i, j, ret;
407  int converter_count = 0;
408  int count_queried = 0; /* successful calls to query_formats() */
409  int count_merged = 0; /* successful merge of formats lists */
410  int count_already_merged = 0; /* lists already merged */
411  int count_delayed = 0; /* lists that need to be merged later */
412 
413  for (i = 0; i < graph->nb_filters; i++) {
414  AVFilterContext *f = graph->filters[i];
415  if (formats_declared(f))
416  continue;
418  if (ret < 0 && ret != AVERROR(EAGAIN))
419  return ret;
420  /* note: EAGAIN could indicate a partial success, not counted yet */
421  count_queried += ret >= 0;
422  }
423 
424  /* go through and merge as many format lists as possible */
425  for (i = 0; i < graph->nb_filters; i++) {
426  AVFilterContext *filter = graph->filters[i];
427 
428  for (j = 0; j < filter->nb_inputs; j++) {
429  AVFilterLink *link = filter->inputs[j];
430  const AVFilterNegotiation *neg;
431  unsigned neg_step;
432  int convert_needed = 0;
433 
434  if (!link)
435  continue;
436 
438  av_assert0(neg);
439  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
440  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
441  void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
442  void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
443  if (a && b && a != b && !m->can_merge(a, b)) {
444  convert_needed = 1;
445  break;
446  }
447  }
448  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
449  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
450  void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
451  void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
452  if (!(a && b)) {
453  count_delayed++;
454  } else if (a == b) {
455  count_already_merged++;
456  } else if (!convert_needed) {
457  count_merged++;
458  ret = m->merge(a, b);
459  if (ret < 0)
460  return ret;
461  if (!ret)
462  convert_needed = 1;
463  }
464  }
465 
466  if (convert_needed) {
468  const AVFilter *filter;
469  AVFilterLink *inlink, *outlink;
470  char inst_name[30];
471  const char *opts;
472 
473  if (fffiltergraph(graph)->disable_auto_convert) {
474  av_log(log_ctx, AV_LOG_ERROR,
475  "The filters '%s' and '%s' do not have a common format "
476  "and automatic conversion is disabled.\n",
477  link->src->name, link->dst->name);
478  return AVERROR(EINVAL);
479  }
480 
481  /* couldn't merge format lists. auto-insert conversion filter */
483  av_log(log_ctx, AV_LOG_ERROR,
484  "'%s' filter not present, cannot convert formats.\n",
485  neg->conversion_filter);
486  return AVERROR(EINVAL);
487  }
488  snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
489  neg->conversion_filter, converter_count++);
490  opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph);
491  ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph);
492  if (ret < 0)
493  return ret;
494  if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0)
495  return ret;
496 
497  if ((ret = filter_query_formats(convert)) < 0)
498  return ret;
499 
500  inlink = convert->inputs[0];
501  outlink = convert->outputs[0];
502  av_assert0( inlink->incfg.formats->refcount > 0);
503  av_assert0( inlink->outcfg.formats->refcount > 0);
504  av_assert0(outlink->incfg.formats->refcount > 0);
505  av_assert0(outlink->outcfg.formats->refcount > 0);
506  if (outlink->type == AVMEDIA_TYPE_VIDEO) {
507  av_assert0( inlink-> incfg.color_spaces->refcount > 0);
508  av_assert0( inlink->outcfg.color_spaces->refcount > 0);
509  av_assert0(outlink-> incfg.color_spaces->refcount > 0);
510  av_assert0(outlink->outcfg.color_spaces->refcount > 0);
511  av_assert0( inlink-> incfg.color_ranges->refcount > 0);
512  av_assert0( inlink->outcfg.color_ranges->refcount > 0);
513  av_assert0(outlink-> incfg.color_ranges->refcount > 0);
514  av_assert0(outlink->outcfg.color_ranges->refcount > 0);
515  } else if (outlink->type == AVMEDIA_TYPE_AUDIO) {
516  av_assert0( inlink-> incfg.samplerates->refcount > 0);
517  av_assert0( inlink->outcfg.samplerates->refcount > 0);
518  av_assert0(outlink-> incfg.samplerates->refcount > 0);
519  av_assert0(outlink->outcfg.samplerates->refcount > 0);
520  av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
521  av_assert0( inlink->outcfg.channel_layouts->refcount > 0);
522  av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
523  av_assert0(outlink->outcfg.channel_layouts->refcount > 0);
524  }
525 #define MERGE(merger, link) \
526  ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
527  FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
528  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
529  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
530  if ((ret = MERGE(m, inlink)) <= 0 ||
531  (ret = MERGE(m, outlink)) <= 0) {
532  if (ret < 0)
533  return ret;
534  av_log(log_ctx, AV_LOG_ERROR,
535  "Impossible to convert between the formats supported by the filter "
536  "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
537  return AVERROR(ENOSYS);
538  }
539  }
540  }
541  }
542  }
543 
544  av_log(graph, AV_LOG_DEBUG, "query_formats: "
545  "%d queried, %d merged, %d already done, %d delayed\n",
546  count_queried, count_merged, count_already_merged, count_delayed);
547  if (count_delayed) {
548  AVBPrint bp;
549 
550  /* if count_queried > 0, one filter at least did set its formats,
551  that will give additional information to its neighbour;
552  if count_merged > 0, one pair of formats lists at least was merged,
553  that will give additional information to all connected filters;
554  in both cases, progress was made and a new round must be done */
555  if (count_queried || count_merged)
556  return AVERROR(EAGAIN);
558  for (i = 0; i < graph->nb_filters; i++)
559  if (!formats_declared(graph->filters[i]))
560  av_bprintf(&bp, "%s%s", bp.len ? ", " : "",
561  graph->filters[i]->name);
562  av_log(graph, AV_LOG_ERROR,
563  "The following filters could not choose their formats: %s\n"
564  "Consider inserting the (a)format filter near their input or "
565  "output.\n", bp.str);
566  return AVERROR(EIO);
567  }
568  return 0;
569 }
570 
571 static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
572 {
573  int score = 0;
574 
575  if (av_sample_fmt_is_planar(dst_fmt) != av_sample_fmt_is_planar(src_fmt))
576  score ++;
577 
578  if (av_get_bytes_per_sample(dst_fmt) < av_get_bytes_per_sample(src_fmt)) {
579  score += 100 * (av_get_bytes_per_sample(src_fmt) - av_get_bytes_per_sample(dst_fmt));
580  }else
581  score += 10 * (av_get_bytes_per_sample(dst_fmt) - av_get_bytes_per_sample(src_fmt));
582 
585  score += 20;
586 
589  score += 2;
590 
591  return score;
592 }
593 
595  enum AVSampleFormat src_fmt)
596 {
597  int score1, score2;
598 
599  score1 = get_fmt_score(dst_fmt1, src_fmt);
600  score2 = get_fmt_score(dst_fmt2, src_fmt);
601 
602  return score1 < score2 ? dst_fmt1 : dst_fmt2;
603 }
604 
606 {
608  if (!desc)
609  return 0;
610  if (desc->nb_components < 3)
611  return 0; /* Grayscale is explicitly full-range in swscale */
615  return 0;
616 
617  switch (fmt) {
618  case AV_PIX_FMT_YUVJ420P:
619  case AV_PIX_FMT_YUVJ422P:
620  case AV_PIX_FMT_YUVJ444P:
621  case AV_PIX_FMT_YUVJ440P:
622  case AV_PIX_FMT_YUVJ411P:
623  return 0;
624  default:
625  return 1;
626  }
627 }
628 
630 {
631  if (!link || !link->incfg.formats)
632  return 0;
633 
634  if (link->type == AVMEDIA_TYPE_VIDEO) {
635  if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
636  //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
637  int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
638  enum AVPixelFormat best= AV_PIX_FMT_NONE;
639  int i;
640  for (i = 0; i < link->incfg.formats->nb_formats; i++) {
641  enum AVPixelFormat p = link->incfg.formats->formats[i];
642  best= av_find_best_pix_fmt_of_2(best, p, ref->format, has_alpha, NULL);
643  }
644  av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s alpha:%d\n",
645  av_get_pix_fmt_name(best), link->incfg.formats->nb_formats,
646  av_get_pix_fmt_name(ref->format), has_alpha);
647  link->incfg.formats->formats[0] = best;
648  }
649  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
650  if(ref && ref->type == AVMEDIA_TYPE_AUDIO){
652  int i;
653  for (i = 0; i < link->incfg.formats->nb_formats; i++) {
654  enum AVSampleFormat p = link->incfg.formats->formats[i];
655  best = find_best_sample_fmt_of_2(best, p, ref->format);
656  }
657  av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s\n",
658  av_get_sample_fmt_name(best), link->incfg.formats->nb_formats,
659  av_get_sample_fmt_name(ref->format));
660  link->incfg.formats->formats[0] = best;
661  }
662  }
663 
664  link->incfg.formats->nb_formats = 1;
665  link->format = link->incfg.formats->formats[0];
666 
667  if (link->type == AVMEDIA_TYPE_VIDEO) {
668  enum AVPixelFormat swfmt = link->format;
670  // FIXME: this is a hack - we'd like to use the sw_format of
671  // link->hw_frames_ctx here, but it is not yet available.
672  // To make this work properly we will need to either reorder
673  // things so that it is available here or somehow negotiate
674  // sw_format separately.
675  swfmt = AV_PIX_FMT_YUV420P;
676  }
677 
678  if (!ff_fmt_is_regular_yuv(swfmt)) {
680  /* These fields are explicitly documented as affecting YUV only,
681  * so set them to sane values for other formats. */
682  if (desc->flags & AV_PIX_FMT_FLAG_FLOAT)
684  else
686  if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ)) {
688  } else {
690  }
691  } else {
692  if (!link->incfg.color_spaces->nb_formats) {
693  av_log(link->src, AV_LOG_ERROR, "Cannot select color space for"
694  " the link between filters %s and %s.\n", link->src->name,
695  link->dst->name);
696  return AVERROR(EINVAL);
697  }
698  link->incfg.color_spaces->nb_formats = 1;
699  link->colorspace = link->incfg.color_spaces->formats[0];
700 
701  if (!link->incfg.color_ranges->nb_formats) {
702  av_log(link->src, AV_LOG_ERROR, "Cannot select color range for"
703  " the link between filters %s and %s.\n", link->src->name,
704  link->dst->name);
705  return AVERROR(EINVAL);
706  }
707  link->incfg.color_ranges->nb_formats = 1;
708  link->color_range = link->incfg.color_ranges->formats[0];
709  }
710  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
711  int ret;
712 
713  if (!link->incfg.samplerates->nb_formats) {
714  av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
715  " the link between filters %s and %s.\n", link->src->name,
716  link->dst->name);
717  return AVERROR(EINVAL);
718  }
719  link->incfg.samplerates->nb_formats = 1;
720  link->sample_rate = link->incfg.samplerates->formats[0];
721 
722  if (link->incfg.channel_layouts->all_layouts) {
723  av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
724  " the link between filters %s and %s.\n", link->src->name,
725  link->dst->name);
726  if (!link->incfg.channel_layouts->all_counts)
727  av_log(link->src, AV_LOG_ERROR, "Unknown channel layouts not "
728  "supported, try specifying a channel layout using "
729  "'aformat=channel_layouts=something'.\n");
730  return AVERROR(EINVAL);
731  }
732  link->incfg.channel_layouts->nb_channel_layouts = 1;
733  ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]);
734  if (ret < 0)
735  return ret;
736 #if FF_API_OLD_CHANNEL_LAYOUT
739  link->ch_layout.u.mask : 0;
741 #endif
742  }
743 
744  ff_formats_unref(&link->incfg.formats);
745  ff_formats_unref(&link->outcfg.formats);
746  ff_formats_unref(&link->incfg.samplerates);
747  ff_formats_unref(&link->outcfg.samplerates);
748  ff_channel_layouts_unref(&link->incfg.channel_layouts);
749  ff_channel_layouts_unref(&link->outcfg.channel_layouts);
750  ff_formats_unref(&link->incfg.color_spaces);
751  ff_formats_unref(&link->outcfg.color_spaces);
752  ff_formats_unref(&link->incfg.color_ranges);
753  ff_formats_unref(&link->outcfg.color_ranges);
754 
755  return 0;
756 }
757 
758 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
759 do { \
760  for (i = 0; i < filter->nb_inputs; i++) { \
761  AVFilterLink *link = filter->inputs[i]; \
762  fmt_type fmt; \
763  \
764  if (!link->outcfg.list || link->outcfg.list->nb != 1) \
765  continue; \
766  fmt = link->outcfg.list->var[0]; \
767  \
768  for (j = 0; j < filter->nb_outputs; j++) { \
769  AVFilterLink *out_link = filter->outputs[j]; \
770  list_type *fmts; \
771  \
772  if (link->type != out_link->type || \
773  out_link->incfg.list->nb == 1) \
774  continue; \
775  fmts = out_link->incfg.list; \
776  \
777  if (!out_link->incfg.list->nb) { \
778  if ((ret = add_format(&out_link->incfg.list, fmt)) < 0)\
779  return ret; \
780  ret = 1; \
781  break; \
782  } \
783  \
784  for (k = 0; k < out_link->incfg.list->nb; k++) \
785  if (fmts->var[k] == fmt) { \
786  fmts->var[0] = fmt; \
787  fmts->nb = 1; \
788  ret = 1; \
789  break; \
790  } \
791  } \
792  } \
793 } while (0)
794 
796 {
797  int i, j, k, ret = 0;
798 
800  nb_formats, ff_add_format);
801  REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
802  nb_formats, ff_add_format);
803 
804  /* reduce channel layouts */
805  for (i = 0; i < filter->nb_inputs; i++) {
806  AVFilterLink *inlink = filter->inputs[i];
807  const AVChannelLayout *fmt;
808 
809  if (!inlink->outcfg.channel_layouts ||
810  inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
811  continue;
812  fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
813 
814  for (j = 0; j < filter->nb_outputs; j++) {
815  AVFilterLink *outlink = filter->outputs[j];
817 
818  fmts = outlink->incfg.channel_layouts;
819  if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
820  continue;
821 
822  if (fmts->all_layouts &&
823  (KNOWN(fmt) || fmts->all_counts)) {
824  /* Turn the infinite list into a singleton */
825  fmts->all_layouts = fmts->all_counts = 0;
827  if (ret < 0)
828  return ret;
829  ret = 1;
830  break;
831  }
832 
833  for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
834  if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
835  ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
836  if (ret < 0)
837  return ret;
838  fmts->nb_channel_layouts = 1;
839  ret = 1;
840  break;
841  }
842  }
843  }
844  }
845 
846  return ret;
847 }
848 
849 static int reduce_formats(AVFilterGraph *graph)
850 {
851  int i, reduced, ret;
852 
853  do {
854  reduced = 0;
855 
856  for (i = 0; i < graph->nb_filters; i++) {
857  if ((ret = reduce_formats_on_filter(graph->filters[i])) < 0)
858  return ret;
859  reduced |= ret;
860  }
861  } while (reduced);
862 
863  return 0;
864 }
865 
867 {
869  int sample_rate;
870  int i, j;
871 
872  for (i = 0; i < filter->nb_inputs; i++) {
873  link = filter->inputs[i];
874 
875  if (link->type == AVMEDIA_TYPE_AUDIO &&
876  link->outcfg.samplerates->nb_formats== 1)
877  break;
878  }
879  if (i == filter->nb_inputs)
880  return;
881 
882  sample_rate = link->outcfg.samplerates->formats[0];
883 
884  for (i = 0; i < filter->nb_outputs; i++) {
885  AVFilterLink *outlink = filter->outputs[i];
886  int best_idx, best_diff = INT_MAX;
887 
888  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
889  outlink->incfg.samplerates->nb_formats < 2)
890  continue;
891 
892  for (j = 0; j < outlink->incfg.samplerates->nb_formats; j++) {
893  int diff = abs(sample_rate - outlink->incfg.samplerates->formats[j]);
894 
895  av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
896 
897  if (diff < best_diff) {
898  best_diff = diff;
899  best_idx = j;
900  }
901  }
902  FFSWAP(int, outlink->incfg.samplerates->formats[0],
903  outlink->incfg.samplerates->formats[best_idx]);
904  }
905 }
906 
907 static void swap_samplerates(AVFilterGraph *graph)
908 {
909  int i;
910 
911  for (i = 0; i < graph->nb_filters; i++)
913 }
914 
916 {
918  enum AVColorSpace csp;
919  int i;
920 
921  for (i = 0; i < filter->nb_inputs; i++) {
922  link = filter->inputs[i];
923  if (link->type == AVMEDIA_TYPE_VIDEO &&
924  link->outcfg.color_spaces->nb_formats == 1)
925  break;
926  }
927  if (i == filter->nb_inputs)
928  return;
929 
930  csp = link->outcfg.color_spaces->formats[0];
931 
932  for (i = 0; i < filter->nb_outputs; i++) {
933  AVFilterLink *outlink = filter->outputs[i];
934  if (outlink->type != AVMEDIA_TYPE_VIDEO)
935  continue;
936  /* there is no meaningful 'score' between different yuv matrices,
937  * so just prioritize an exact match if it exists */
938  for (int j = 0; j < outlink->incfg.color_spaces->nb_formats; j++) {
939  if (csp == outlink->incfg.color_spaces->formats[j]) {
940  FFSWAP(int, outlink->incfg.color_spaces->formats[0],
941  outlink->incfg.color_spaces->formats[j]);
942  break;
943  }
944  }
945  }
946 }
947 
948 static void swap_color_spaces(AVFilterGraph *graph)
949 {
950  for (int i = 0; i < graph->nb_filters; i++)
952 }
953 
955 {
957  enum AVColorRange range;
958  int i;
959 
960  for (i = 0; i < filter->nb_inputs; i++) {
961  link = filter->inputs[i];
962  if (link->type == AVMEDIA_TYPE_VIDEO &&
963  link->outcfg.color_ranges->nb_formats == 1)
964  break;
965  }
966  if (i == filter->nb_inputs)
967  return;
968 
969  range = link->outcfg.color_ranges->formats[0];
970 
971  for (i = 0; i < filter->nb_outputs; i++) {
972  AVFilterLink *outlink = filter->outputs[i];
973  if (outlink->type != AVMEDIA_TYPE_VIDEO)
974  continue;
975  for (int j = 0; j < outlink->incfg.color_ranges->nb_formats; j++) {
976  if (range == outlink->incfg.color_ranges->formats[j]) {
977  FFSWAP(int, outlink->incfg.color_ranges->formats[0],
978  outlink->incfg.color_ranges->formats[j]);
979  break;
980  }
981  }
982  }
983 }
984 
985 static void swap_color_ranges(AVFilterGraph *graph)
986 {
987  for (int i = 0; i < graph->nb_filters; i++)
989 }
990 
991 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
992 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
993 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
994 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
995 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
996 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
997 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
998 
999 /* allowable substitutions for channel pairs when comparing layouts,
1000  * ordered by priority for both values */
1001 static const uint64_t ch_subst[][2] = {
1023 };
1024 
1026 {
1027  AVFilterLink *link = NULL;
1028  int i, j, k;
1029 
1030  for (i = 0; i < filter->nb_inputs; i++) {
1031  link = filter->inputs[i];
1032 
1033  if (link->type == AVMEDIA_TYPE_AUDIO &&
1034  link->outcfg.channel_layouts->nb_channel_layouts == 1)
1035  break;
1036  }
1037  if (i == filter->nb_inputs)
1038  return;
1039 
1040  for (i = 0; i < filter->nb_outputs; i++) {
1041  AVFilterLink *outlink = filter->outputs[i];
1042  int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
1043 
1044  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1046  continue;
1047 
1048  for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
1049  AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 };
1050  int in_channels;
1051  int out_channels;
1052  int count_diff;
1053  int matched_channels, extra_channels;
1054  int score = 100000;
1055 
1056  av_channel_layout_copy(&in_chlayout, &link->outcfg.channel_layouts->channel_layouts[0]);
1057  av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]);
1058  in_channels = in_chlayout.nb_channels;
1059  out_channels = out_chlayout.nb_channels;
1060  count_diff = out_channels - in_channels;
1061  if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
1062  /* Compute score in case the input or output layout encodes
1063  a channel count; in this case the score is not altered by
1064  the computation afterwards, as in_chlayout and
1065  out_chlayout have both been set to 0 */
1066  if (!KNOWN(&in_chlayout))
1067  in_channels = FF_LAYOUT2COUNT(&in_chlayout);
1068  if (!KNOWN(&out_chlayout))
1069  out_channels = FF_LAYOUT2COUNT(&out_chlayout);
1070  score -= 10000 + FFABS(out_channels - in_channels) +
1071  (in_channels > out_channels ? 10000 : 0);
1072  av_channel_layout_uninit(&in_chlayout);
1073  av_channel_layout_uninit(&out_chlayout);
1074  /* Let the remaining computation run, even if the score
1075  value is not altered */
1076  }
1077 
1078  /* channel substitution */
1079  for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
1080  uint64_t cmp0 = ch_subst[k][0];
1081  uint64_t cmp1 = ch_subst[k][1];
1082  if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
1083  !av_channel_layout_subset(&out_chlayout, cmp0) &&
1084  av_channel_layout_subset(&out_chlayout, cmp1) &&
1085  !av_channel_layout_subset(& in_chlayout, cmp1)) {
1086  av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
1087  av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
1088  /* add score for channel match, minus a deduction for
1089  having to do the substitution */
1090  score += 10 * av_popcount64(cmp1) - 2;
1091  }
1092  }
1093 
1094  /* no penalty for LFE channel mismatch */
1097  score += 10;
1100 
1101  matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
1102  extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
1103  score += 10 * matched_channels - 5 * extra_channels;
1104 
1105  if (score > best_score ||
1106  (count_diff < best_count_diff && score == best_score)) {
1107  best_score = score;
1108  best_idx = j;
1109  best_count_diff = count_diff;
1110  }
1111  }
1112  av_assert0(best_idx >= 0);
1114  outlink->incfg.channel_layouts->channel_layouts[best_idx]);
1115  }
1116 
1117 }
1118 
1120 {
1121  int i;
1122 
1123  for (i = 0; i < graph->nb_filters; i++)
1125 }
1126 
1128 {
1129  AVFilterLink *link = NULL;
1130  int format, bps;
1131  int i, j;
1132 
1133  for (i = 0; i < filter->nb_inputs; i++) {
1134  link = filter->inputs[i];
1135 
1136  if (link->type == AVMEDIA_TYPE_AUDIO &&
1137  link->outcfg.formats->nb_formats == 1)
1138  break;
1139  }
1140  if (i == filter->nb_inputs)
1141  return;
1142 
1143  format = link->outcfg.formats->formats[0];
1145 
1146  for (i = 0; i < filter->nb_outputs; i++) {
1147  AVFilterLink *outlink = filter->outputs[i];
1148  int best_idx = -1, best_score = INT_MIN;
1149 
1150  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1151  outlink->incfg.formats->nb_formats < 2)
1152  continue;
1153 
1154  for (j = 0; j < outlink->incfg.formats->nb_formats; j++) {
1155  int out_format = outlink->incfg.formats->formats[j];
1156  int out_bps = av_get_bytes_per_sample(out_format);
1157  int score;
1158 
1159  if (av_get_packed_sample_fmt(out_format) == format ||
1160  av_get_planar_sample_fmt(out_format) == format) {
1161  best_idx = j;
1162  break;
1163  }
1164 
1165  /* for s32 and float prefer double to prevent loss of information */
1166  if (bps == 4 && out_bps == 8) {
1167  best_idx = j;
1168  break;
1169  }
1170 
1171  /* prefer closest higher or equal bps */
1172  score = -abs(out_bps - bps);
1173  if (out_bps >= bps)
1174  score += INT_MAX/2;
1175 
1176  if (score > best_score) {
1177  best_score = score;
1178  best_idx = j;
1179  }
1180  }
1181  av_assert0(best_idx >= 0);
1182  FFSWAP(int, outlink->incfg.formats->formats[0],
1183  outlink->incfg.formats->formats[best_idx]);
1184  }
1185 }
1186 
1187 static void swap_sample_fmts(AVFilterGraph *graph)
1188 {
1189  int i;
1190 
1191  for (i = 0; i < graph->nb_filters; i++)
1193 
1194 }
1195 
1196 static int pick_formats(AVFilterGraph *graph)
1197 {
1198  int i, j, ret;
1199  int change;
1200 
1201  do{
1202  change = 0;
1203  for (i = 0; i < graph->nb_filters; i++) {
1204  AVFilterContext *filter = graph->filters[i];
1205  if (filter->nb_inputs){
1206  for (j = 0; j < filter->nb_inputs; j++){
1207  if (filter->inputs[j]->incfg.formats && filter->inputs[j]->incfg.formats->nb_formats == 1) {
1208  if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1209  return ret;
1210  change = 1;
1211  }
1212  }
1213  }
1214  if (filter->nb_outputs){
1215  for (j = 0; j < filter->nb_outputs; j++){
1216  if (filter->outputs[j]->incfg.formats && filter->outputs[j]->incfg.formats->nb_formats == 1) {
1217  if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1218  return ret;
1219  change = 1;
1220  }
1221  }
1222  }
1223  if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
1224  for (j = 0; j < filter->nb_outputs; j++) {
1225  if (filter->outputs[j]->format<0) {
1226  if ((ret = pick_format(filter->outputs[j], filter->inputs[0])) < 0)
1227  return ret;
1228  change = 1;
1229  }
1230  }
1231  }
1232  }
1233  }while(change);
1234 
1235  for (i = 0; i < graph->nb_filters; i++) {
1236  AVFilterContext *filter = graph->filters[i];
1237 
1238  for (j = 0; j < filter->nb_inputs; j++)
1239  if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1240  return ret;
1241  for (j = 0; j < filter->nb_outputs; j++)
1242  if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1243  return ret;
1244  }
1245  return 0;
1246 }
1247 
1248 /**
1249  * Configure the formats of all the links in the graph.
1250  */
1251 static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
1252 {
1253  int ret;
1254 
1255  /* find supported formats from sub-filters, and merge along links */
1256  while ((ret = query_formats(graph, log_ctx)) == AVERROR(EAGAIN))
1257  av_log(graph, AV_LOG_DEBUG, "query_formats not finished\n");
1258  if (ret < 0)
1259  return ret;
1260 
1261  /* Once everything is merged, it's possible that we'll still have
1262  * multiple valid media format choices. We try to minimize the amount
1263  * of format conversion inside filters */
1264  if ((ret = reduce_formats(graph)) < 0)
1265  return ret;
1266 
1267  /* for video filters, ensure that the best colorspace metadata is selected */
1268  swap_color_spaces(graph);
1269  swap_color_ranges(graph);
1270 
1271  /* for audio filters, ensure the best format, sample rate and channel layout
1272  * is selected */
1273  swap_sample_fmts(graph);
1274  swap_samplerates(graph);
1275  swap_channel_layouts(graph);
1276 
1277  if ((ret = pick_formats(graph)) < 0)
1278  return ret;
1279 
1280  return 0;
1281 }
1282 
1283 static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
1284 {
1285  unsigned i, j;
1286  int sink_links_count = 0, n = 0;
1287  AVFilterContext *f;
1288  FilterLinkInternal **sinks;
1289 
1290  for (i = 0; i < graph->nb_filters; i++) {
1291  f = graph->filters[i];
1292  for (j = 0; j < f->nb_inputs; j++) {
1293  f->inputs[j]->graph = graph;
1294  ff_link_internal(f->inputs[j])->age_index = -1;
1295  }
1296  for (j = 0; j < f->nb_outputs; j++) {
1297  f->outputs[j]->graph = graph;
1298  ff_link_internal(f->outputs[j])->age_index = -1;
1299  }
1300  if (!f->nb_outputs) {
1301  if (f->nb_inputs > INT_MAX - sink_links_count)
1302  return AVERROR(EINVAL);
1303  sink_links_count += f->nb_inputs;
1304  }
1305  }
1306  sinks = av_calloc(sink_links_count, sizeof(*sinks));
1307  if (!sinks)
1308  return AVERROR(ENOMEM);
1309  for (i = 0; i < graph->nb_filters; i++) {
1310  f = graph->filters[i];
1311  if (!f->nb_outputs) {
1312  for (j = 0; j < f->nb_inputs; j++) {
1313  sinks[n] = ff_link_internal(f->inputs[j]);
1314  sinks[n]->age_index = n;
1315  n++;
1316  }
1317  }
1318  }
1319  av_assert0(n == sink_links_count);
1320  fffiltergraph(graph)->sink_links = sinks;
1321  fffiltergraph(graph)->sink_links_count = sink_links_count;
1322  return 0;
1323 }
1324 
1325 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
1326 {
1327  int ret;
1328 
1329  if ((ret = graph_check_validity(graphctx, log_ctx)))
1330  return ret;
1331  if ((ret = graph_config_formats(graphctx, log_ctx)))
1332  return ret;
1333  if ((ret = graph_config_links(graphctx, log_ctx)))
1334  return ret;
1335  if ((ret = graph_check_links(graphctx, log_ctx)))
1336  return ret;
1337  if ((ret = graph_config_pointers(graphctx, log_ctx)))
1338  return ret;
1339 
1340  return 0;
1341 }
1342 
1343 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
1344 {
1345  int i, r = AVERROR(ENOSYS);
1346 
1347  if (!graph)
1348  return r;
1349 
1351  r = avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
1352  if (r != AVERROR(ENOSYS))
1353  return r;
1354  }
1355 
1356  if (res_len && res)
1357  res[0] = 0;
1358 
1359  for (i = 0; i < graph->nb_filters; i++) {
1360  AVFilterContext *filter = graph->filters[i];
1361  if (!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)) {
1362  r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
1363  if (r != AVERROR(ENOSYS)) {
1364  if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1365  return r;
1366  }
1367  }
1368  }
1369 
1370  return r;
1371 }
1372 
1373 int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
1374 {
1375  int i;
1376 
1377  if(!graph)
1378  return 0;
1379 
1380  for (i = 0; i < graph->nb_filters; i++) {
1381  AVFilterContext *filter = graph->filters[i];
1382  if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
1383  AVFilterCommand **queue = &filter->command_queue, *next;
1384  while (*queue && (*queue)->time <= ts)
1385  queue = &(*queue)->next;
1386  next = *queue;
1387  *queue = av_mallocz(sizeof(AVFilterCommand));
1388  if (!*queue)
1389  return AVERROR(ENOMEM);
1390 
1391  (*queue)->command = av_strdup(command);
1392  (*queue)->arg = av_strdup(arg);
1393  (*queue)->time = ts;
1394  (*queue)->flags = flags;
1395  (*queue)->next = next;
1397  return 0;
1398  }
1399  }
1400 
1401  return 0;
1402 }
1403 
1404 static void heap_bubble_up(FFFilterGraph *graph,
1405  FilterLinkInternal *li, int index)
1406 {
1407  FilterLinkInternal **links = graph->sink_links;
1408 
1409  av_assert0(index >= 0);
1410 
1411  while (index) {
1412  int parent = (index - 1) >> 1;
1413  if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
1414  break;
1415  links[index] = links[parent];
1416  links[index]->age_index = index;
1417  index = parent;
1418  }
1419  links[index] = li;
1420  li->age_index = index;
1421 }
1422 
1423 static void heap_bubble_down(FFFilterGraph *graph,
1424  FilterLinkInternal *li, int index)
1425 {
1426  FilterLinkInternal **links = graph->sink_links;
1427 
1428  av_assert0(index >= 0);
1429 
1430  while (1) {
1431  int child = 2 * index + 1;
1432  if (child >= graph->sink_links_count)
1433  break;
1434  if (child + 1 < graph->sink_links_count &&
1435  links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
1436  child++;
1437  if (li->l.current_pts_us < links[child]->l.current_pts_us)
1438  break;
1439  links[index] = links[child];
1440  links[index]->age_index = index;
1441  index = child;
1442  }
1443  links[index] = li;
1444  li->age_index = index;
1445 }
1446 
1448 {
1449  FFFilterGraph *graphi = fffiltergraph(graph);
1450 
1451  heap_bubble_up (graphi, li, li->age_index);
1452  heap_bubble_down(graphi, li, li->age_index);
1453 }
1454 
1456 {
1457  FFFilterGraph *graphi = fffiltergraph(graph);
1458  FilterLinkInternal *oldesti = graphi->sink_links[0];
1459  AVFilterLink *oldest = &oldesti->l;
1460  int64_t frame_count;
1461  int r;
1462 
1463  while (graphi->sink_links_count) {
1464  oldesti = graphi->sink_links[0];
1465  oldest = &oldesti->l;
1466  if (oldest->dst->filter->activate) {
1469  if (r != AVERROR_EOF)
1470  return r;
1471  } else {
1472  r = ff_request_frame(oldest);
1473  }
1474  if (r != AVERROR_EOF)
1475  break;
1476  av_log(oldest->dst, AV_LOG_DEBUG, "EOF on sink link %s:%s.\n",
1477  oldest->dst->name,
1478  oldest->dstpad->name);
1479  /* EOF: remove the link from the heap */
1480  if (oldesti->age_index < --graphi->sink_links_count)
1481  heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
1482  oldesti->age_index);
1483  oldesti->age_index = -1;
1484  }
1485  if (!graphi->sink_links_count)
1486  return AVERROR_EOF;
1487  av_assert1(!oldest->dst->filter->activate);
1488  av_assert1(oldesti->age_index >= 0);
1489  frame_count = oldest->frame_count_out;
1490  while (frame_count == oldest->frame_count_out) {
1491  r = ff_filter_graph_run_once(graph);
1492  if (r == AVERROR(EAGAIN) &&
1493  !oldest->frame_wanted_out && !oldesti->frame_blocked_in &&
1494  !oldesti->status_in)
1495  ff_request_frame(oldest);
1496  else if (r < 0)
1497  return r;
1498  }
1499  return 0;
1500 }
1501 
1503 {
1505  unsigned i;
1506 
1507  av_assert0(graph->nb_filters);
1508  filter = graph->filters[0];
1509  for (i = 1; i < graph->nb_filters; i++)
1510  if (graph->filters[i]->ready > filter->ready)
1511  filter = graph->filters[i];
1512  if (!filter->ready)
1513  return AVERROR(EAGAIN);
1514  return ff_filter_activate(filter);
1515 }
formats
formats
Definition: signature.h:48
AVFilterGraph::execute
avfilter_execute_func * execute
This callback may be set by the caller immediately after allocating the graph and before adding any f...
Definition: avfilter.h:882
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVFILTER_CMD_FLAG_ONE
#define AVFILTER_CMD_FLAG_ONE
Stop once a filter understood the command (for target=all for example), fast filters are favored auto...
Definition: avfilter.h:708
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:656
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:522
name
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
Definition: writing_filters.txt:88
F
#define F
Definition: avfiltergraph.c:44
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:82
r
const char * r
Definition: vf_curves.c:126
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
opt.h
AVFilterGraph::nb_threads
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:856
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1459
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:527
ch_subst
static const uint64_t ch_subst[][2]
Definition: avfiltergraph.c:1001
REDUCE_FORMATS
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format)
Definition: avfiltergraph.c:758
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
av_popcount64
#define av_popcount64
Definition: common.h:155
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2968
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
av_buffersink_get_frame_flags
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:151
ff_formats_check_pixel_formats
int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid pixel formats list.
Definition: formats.c:1026
FFFilterGraph
Definition: avfilter_internal.h:95
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
filter_query_formats
static int filter_query_formats(AVFilterContext *ctx)
Definition: avfiltergraph.c:343
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
normalize.log
log
Definition: normalize.py:21
ff_filter_activate
int ff_filter_activate(AVFilterContext *filter)
Definition: avfilter.c:1371
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:667
swap_sample_fmts
static void swap_sample_fmts(AVFilterGraph *graph)
Definition: avfiltergraph.c:1187
pixdesc.h
AVFilterNegotiation::conversion_filter
const char * conversion_filter
Definition: formats.h:479
graph_check_validity
static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
Check for the validity of graph.
Definition: avfiltergraph.c:207
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:687
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:867
query_formats
static int query_formats(AVFilterGraph *graph, void *log_ctx)
Perform one round of query_formats() and merging formats lists on the filter graph.
Definition: avfiltergraph.c:404
AVOption
AVOption.
Definition: opt.h:251
FFFilterGraph::sink_links
struct FilterLinkInternal ** sink_links
Definition: avfilter_internal.h:101
b
#define b
Definition: input.c:41
pick_formats
static int pick_formats(AVFilterGraph *graph)
Definition: avfiltergraph.c:1196
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:451
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:614
pick_format
static int pick_format(AVFilterLink *link, AVFilterLink *ref)
Definition: avfiltergraph.c:629
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
ff_filter_graph_run_once
int ff_filter_graph_run_once(AVFilterGraph *graph)
Run one round of processing on a filter graph.
Definition: avfiltergraph.c:1502
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:318
AVFilterFormats::formats
int * formats
list of media formats
Definition: formats.h:66
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:345
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
ff_fmt_is_regular_yuv
int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt)
Returns true if a pixel format is "regular YUV", which includes all pixel formats that are affected b...
Definition: avfiltergraph.c:605
sample_rate
sample_rate
Definition: ffmpeg_filter.c:424
ff_filter_alloc
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
Definition: avfilter.c:672
convert
static void convert(float y, float u, float v, float *b, float *g, float *r)
Definition: exr.c:959
swap_samplerates
static void swap_samplerates(AVFilterGraph *graph)
Definition: avfiltergraph.c:907
FF_LAYOUT2COUNT
#define FF_LAYOUT2COUNT(l)
Decode a channel count encoded as a channel layout.
Definition: formats.h:108
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graphp)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:116
FilterLinkInternal
Definition: avfilter_internal.h:33
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
get_fmt_score
static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
Definition: avfiltergraph.c:571
avfilter_graph_create_filter
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
Definition: avfiltergraph.c:137
avfilter_graph_alloc_filter
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
Definition: avfiltergraph.c:164
fail
#define fail()
Definition: checkasm.h:179
avfilter_graph_alloc
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:82
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
ff_graph_thread_init
int ff_graph_thread_init(FFFilterGraph *graph)
Definition: avfiltergraph.c:74
reduce_formats
static int reduce_formats(AVFilterGraph *graph)
Definition: avfiltergraph.c:849
avfilter_insert_filter
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
Insert a filter in the middle of an existing link.
Definition: avfilter.c:275
graph_config_formats
static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
Configure the formats of all the links in the graph.
Definition: avfiltergraph.c:1251
OFFSET
#define OFFSET(x)
Definition: avfiltergraph.c:43
avfilter_config_links
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:318
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
AVFILTER_THREAD_SLICE
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
Definition: avfilter.h:404
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:476
FFFilterGraph::sink_links_count
int sink_links_count
Definition: avfilter_internal.h:102
heap_bubble_up
static void heap_bubble_up(FFFilterGraph *graph, FilterLinkInternal *li, int index)
Definition: avfiltergraph.c:1404
av_image_check_size2
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:289
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:477
av_get_planar_sample_fmt
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:86
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:283
reduce_formats_on_filter
static int reduce_formats_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:795
avassert.h
FFFilterGraph::thread_execute
avfilter_execute_func * thread_execute
Definition: avfilter_internal.h:107
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
MERGE
#define MERGE(merger, link)
AVFrame::channel_layout
attribute_deprecated uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:575
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:171
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:86
AV_BUFFERSINK_FLAG_PEEK
#define AV_BUFFERSINK_FLAG_PEEK
Tell av_buffersink_get_buffer_ref() to read video/samples buffer reference, but not remove it from th...
Definition: buffersink.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
swap_color_ranges_on_filter
static void swap_color_ranges_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:954
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
avfilter_process_command
int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
Make the filter instance process a command.
Definition: avfilter.c:583
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_channel_layout_from_mask
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:421
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:54
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:114
filtergraph_options
static const AVOption filtergraph_options[]
Definition: avfiltergraph.c:47
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVFilterFormatsConfig::color_spaces
AVFilterFormats * color_spaces
Lists of supported YUV color metadata, only for YUV video.
Definition: avfilter.h:532
CH_DIRECT_PAIR
#define CH_DIRECT_PAIR
Definition: avfiltergraph.c:996
graph_config_pointers
static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
Definition: avfiltergraph.c:1283
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
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:51
AVFilterNegotiation::mergers
const AVFilterFormatsMerger * mergers
Definition: formats.h:478
command
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:1191
link
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
Definition: filter_design.txt:23
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
arg
const char * arg
Definition: jacosubdec.c:67
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
AVFilter::activate
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: avfilter.h:393
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:629
opts
AVDictionary * opts
Definition: movenc.c:50
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avfilter_graph_config
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
Definition: avfiltergraph.c:1325
NULL
#define NULL
Definition: coverity.c:32
ff_filter_get_negotiation
const AVFilterNegotiation * ff_filter_get_negotiation(AVFilterLink *link)
Definition: formats.c:397
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
avfilter_graph_set_auto_convert
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
Definition: avfiltergraph.c:159
framequeue.h
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
AVFilterGraph::filters
AVFilterContext ** filters
Definition: avfilter.h:832
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
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:504
AVFilterContext::name
char * name
name of this filter instance
Definition: avfilter.h:414
fffiltergraph
static FFFilterGraph * fffiltergraph(AVFilterGraph *graph)
Definition: avfilter_internal.h:111
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
avfilter_graph_get_filter
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, const char *name)
Get a filter instance identified by instance name from graph.
Definition: avfiltergraph.c:283
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1719
avfilter_graph_request_oldest
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
Definition: avfiltergraph.c:1455
graph_config_links
static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
Configure all the links of graphctx.
Definition: avfiltergraph.c:245
abs
#define abs(x)
Definition: cuda_runtime.h:35
avfilter_internal.h
AVFilterGraph
Definition: avfilter.h:830
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:170
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:521
AVFilterFormats::refcount
unsigned refcount
number of references to this list
Definition: formats.h:68
ff_channel_layouts_unref
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:729
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:653
index
int index
Definition: gxfenc.c:89
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:512
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
ff_formats_check_sample_formats
int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample formats list.
Definition: formats.c:1031
swap_color_spaces_on_filter
static void swap_color_spaces_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:915
ff_graph_thread_free
void ff_graph_thread_free(FFFilterGraph *graph)
Definition: avfiltergraph.c:70
f
f
Definition: af_crystalizer.c:121
ff_formats_check_color_spaces
int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for YUV colorspace metadata.
Definition: formats.c:1043
CH_BACK_PAIR
#define CH_BACK_PAIR
Definition: avfiltergraph.c:997
ff_default_query_formats
int ff_default_query_formats(AVFilterContext *ctx)
Sets all remaining unset filter lists for all inputs/outputs to their corresponding ff_all_*() lists.
Definition: formats.c:878
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:313
FilterLinkInternal::age_index
int age_index
Index in the age array.
Definition: avfilter_internal.h:72
ff_avfilter_graph_update_heap
void ff_avfilter_graph_update_heap(AVFilterGraph *graph, FilterLinkInternal *li)
Update the position of a link in the age heap.
Definition: avfiltergraph.c:1447
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
AVFilterCommand::next
struct AVFilterCommand * next
Definition: avfilter_internal.h:92
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:567
bps
unsigned bps
Definition: movenc.c:1787
CH_CENTER_PAIR
#define CH_CENTER_PAIR
Definition: avfiltergraph.c:991
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:53
avfilter_graph_queue_command
int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
Queue a command for one or more filter instances.
Definition: avfiltergraph.c:1373
AVFilterChannelLayouts::channel_layouts
AVChannelLayout * channel_layouts
list of channel layouts
Definition: formats.h:86
FFFilterGraph::frame_queues
FFFrameQueueGlobal frame_queues
Definition: avfilter_internal.h:108
AVFilterChannelLayouts::all_layouts
char all_layouts
accept any known channel layout
Definition: formats.h:88
swap_color_spaces
static void swap_color_spaces(AVFilterGraph *graph)
Definition: avfiltergraph.c:948
AVFilterChannelLayouts::all_counts
char all_counts
accept any channel layout or count
Definition: formats.h:89
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
ff_formats_check_channel_layouts
int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
Check that fmts is a valid channel layouts list.
Definition: formats.c:1066
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:164
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
find_best_sample_fmt_of_2
static enum AVSampleFormat find_best_sample_fmt_of_2(enum AVSampleFormat dst_fmt1, enum AVSampleFormat dst_fmt2, enum AVSampleFormat src_fmt)
Definition: avfiltergraph.c:594
AVFilterFormatsConfig::color_ranges
AVFilterFormats * color_ranges
AVColorRange.
Definition: avfilter.h:533
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:118
swap_color_ranges
static void swap_color_ranges(AVFilterGraph *graph)
Definition: avfiltergraph.c:985
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:1003
internal.h
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:933
buffersink.h
FilterLinkInternal::frame_blocked_in
int frame_blocked_in
If set, the source filter can not generate a frame as is.
Definition: avfilter_internal.h:48
filter_link_check_formats
static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
Definition: avfiltergraph.c:294
CH_FRONT_PAIR
#define CH_FRONT_PAIR
Definition: avfiltergraph.c:992
swap_sample_fmts_on_filter
static void swap_sample_fmts_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:1127
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:717
bprint.h
ff_formats_check_sample_rates
int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample rates list.
Definition: formats.c:1036
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:245
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
FFFilterGraph::disable_auto_convert
unsigned disable_auto_convert
Definition: avfilter_internal.h:104
swap_channel_layouts_on_filter
static void swap_channel_layouts_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:1025
graph_check_links
static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
Definition: avfiltergraph.c:262
AVFilterCommand
Definition: avfilter_internal.h:87
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:613
FilterLinkInternal::status_in
int status_in
Link input status.
Definition: avfilter_internal.h:55
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:176
V
#define V
Definition: avfiltergraph.c:45
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:107
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:254
AVFilterGraph::thread_type
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:849
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:39
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:616
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
swap_channel_layouts
static void swap_channel_layouts(AVFilterGraph *graph)
Definition: avfiltergraph.c:1119
ff_formats_check_color_ranges
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition: formats.c:1054
AVFilter
Filter definition.
Definition: avfilter.h:166
AVFILTER_CMD_FLAG_FAST
#define AVFILTER_CMD_FLAG_FAST
Only execute command when its fast (like a video out that supports contrast adjustment in hw)
Definition: avfilter.h:709
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:44
links
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 links
Definition: filter_design.txt:14
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVFilterNegotiation::conversion_opts_offset
unsigned conversion_opts_offset
Definition: formats.h:480
CH_SIDE_PAIR
#define CH_SIDE_PAIR
Definition: avfiltergraph.c:995
heap_bubble_down
static void heap_bubble_down(FFFilterGraph *graph, FilterLinkInternal *li, int index)
Definition: avfiltergraph.c:1423
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
formats_declared
static int formats_declared(AVFilterContext *f)
Definition: avfiltergraph.c:363
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
av_find_best_pix_fmt_of_2
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Compute what kind of losses will occur when converting from one specific pixel format to another.
Definition: pixdesc.c:3247
channel_layout.h
av_channel_layout_subset
uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask)
Find out what channels from a given set are present in a channel layout, without regard for their pos...
Definition: channel_layout.c:1059
AV_PIX_FMT_FLAG_XYZ
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
Definition: pixdesc.h:163
ff_filter_graph_remove_filter
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
Definition: avfiltergraph.c:98
CH_WIDE_PAIR
#define CH_WIDE_PAIR
Definition: avfiltergraph.c:994
ff_framequeue_global_init
void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
Init a global structure.
Definition: framequeue.c:30
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:662
av_get_packed_sample_fmt
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition: samplefmt.c:77
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
KNOWN
#define KNOWN(l)
Definition: formats.h:111
FFFilterGraph::p
AVFilterGraph p
The public AVFilterGraph.
Definition: avfilter_internal.h:99
AVFilterContext
An instance of a filter.
Definition: avfilter.h:409
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:669
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVFilterChannelLayouts::nb_channel_layouts
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
FilterLinkInternal::l
AVFilterLink l
Definition: avfilter_internal.h:34
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:517
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
avfilter_free
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:769
A
#define A
Definition: avfiltergraph.c:46
swap_samplerates_on_filter
static void swap_samplerates_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:866
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
FF_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: internal.h:152
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
hwcontext.h
avfilter_graph_send_command
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
Send a command to one or more filter instances.
Definition: avfiltergraph.c:1343
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FF_FIELD_AT
#define FF_FIELD_AT(type, off, obj)
Access a field in a structure by its offset.
Definition: internal.h:95
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:833
AVFilterContext::filter
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:412
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVFilterChannelLayouts::refcount
unsigned refcount
number of references to this list
Definition: formats.h:91
filter_check_formats
static int filter_check_formats(AVFilterContext *ctx)
Check the validity of the formats / etc.
Definition: avfiltergraph.c:325
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:652
AV_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:120
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
filtergraph_class
static const AVClass filtergraph_class
Definition: avfiltergraph.c:61
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
AVChannelLayout::u
union AVChannelLayout::@345 u
Details about which channels are present in this layout.
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
AVFilterContext::ready
unsigned ready
Ready status of the filter.
Definition: avfilter.h:483
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2888
AVFilterCommand::time
double time
time expressed in seconds
Definition: avfilter_internal.h:88