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/imgutils.h"
31 #include "libavutil/mem.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 "filters.h"
40 #include "formats.h"
41 #include "framequeue.h"
42 #include "video.h"
43 
44 #define OFFSET(x) offsetof(AVFilterGraph, x)
45 #define F AV_OPT_FLAG_FILTERING_PARAM
46 #define V AV_OPT_FLAG_VIDEO_PARAM
47 #define A AV_OPT_FLAG_AUDIO_PARAM
48 static const AVOption filtergraph_options[] = {
49  { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
50  { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, F|V|A, .unit = "thread_type" },
51  { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = F|V|A, .unit = "thread_type" },
52  { "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT,
53  { .i64 = 0 }, 0, INT_MAX, F|V|A, .unit = "threads"},
54  {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"},
55  {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
56  AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V },
57  {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
58  AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|A },
59  { NULL },
60 };
61 
62 static const AVClass filtergraph_class = {
63  .class_name = "AVFilterGraph",
64  .item_name = av_default_item_name,
65  .version = LIBAVUTIL_VERSION_INT,
66  .option = filtergraph_options,
67  .category = AV_CLASS_CATEGORY_FILTER,
68 };
69 
70 #if !HAVE_THREADS
72 {
73 }
74 
76 {
77  graph->p.thread_type = 0;
78  graph->p.nb_threads = 1;
79  return 0;
80 }
81 #endif
82 
84 {
85  FFFilterGraph *graph = av_mallocz(sizeof(*graph));
87 
88  if (!graph)
89  return NULL;
90 
91  ret = &graph->p;
92  ret->av_class = &filtergraph_class;
95 
96  return ret;
97 }
98 
100 {
101  int i, j;
102  for (i = 0; i < graph->nb_filters; i++) {
103  if (graph->filters[i] == filter) {
104  FFSWAP(AVFilterContext*, graph->filters[i],
105  graph->filters[graph->nb_filters - 1]);
106  graph->nb_filters--;
107  filter->graph = NULL;
108  for (j = 0; j<filter->nb_outputs; j++)
109  if (filter->outputs[j])
110  ff_filter_link(filter->outputs[j])->graph = NULL;
111 
112  return;
113  }
114  }
115 }
116 
118 {
119  AVFilterGraph *graph = *graphp;
120  FFFilterGraph *graphi = fffiltergraph(graph);
121 
122  if (!graph)
123  return;
124 
125  while (graph->nb_filters)
126  avfilter_free(graph->filters[0]);
127 
128  ff_graph_thread_free(graphi);
129 
130  av_freep(&graphi->sink_links);
131 
132  av_opt_free(graph);
133 
134  av_freep(&graph->filters);
135  av_freep(graphp);
136 }
137 
139  const char *name, const char *args, void *opaque,
140  AVFilterGraph *graph_ctx)
141 {
142  int ret;
143 
144  *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
145  if (!*filt_ctx)
146  return AVERROR(ENOMEM);
147 
148  ret = avfilter_init_str(*filt_ctx, args);
149  if (ret < 0)
150  goto fail;
151 
152  return 0;
153 
154 fail:
155  avfilter_free(*filt_ctx);
156  *filt_ctx = NULL;
157  return ret;
158 }
159 
161 {
163 }
164 
166  const AVFilter *filter,
167  const char *name)
168 {
170  FFFilterGraph *graphi = fffiltergraph(graph);
171 
172  if (graph->thread_type && !graphi->thread_execute) {
173  if (graph->execute) {
174  graphi->thread_execute = graph->execute;
175  } else {
176  int ret = ff_graph_thread_init(graphi);
177  if (ret < 0) {
178  av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
179  return NULL;
180  }
181  }
182  }
183 
184  filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
185  if (!filters)
186  return NULL;
187  graph->filters = filters;
188 
190  if (!s)
191  return NULL;
192 
193  graph->filters[graph->nb_filters++] = s;
194 
195  s->graph = graph;
196 
197  return s;
198 }
199 
200 /**
201  * Check for the validity of graph.
202  *
203  * A graph is considered valid if all its input and output pads are
204  * connected.
205  *
206  * @return >= 0 in case of success, a negative value otherwise
207  */
208 static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
209 {
211  int i, j;
212 
213  for (i = 0; i < graph->nb_filters; i++) {
214  const AVFilterPad *pad;
215  filt = graph->filters[i];
216 
217  for (j = 0; j < filt->nb_inputs; j++) {
218  if (!filt->inputs[j] || !filt->inputs[j]->src) {
219  pad = &filt->input_pads[j];
220  av_log(log_ctx, AV_LOG_ERROR,
221  "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
222  pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
223  return AVERROR(EINVAL);
224  }
225  }
226 
227  for (j = 0; j < filt->nb_outputs; j++) {
228  if (!filt->outputs[j] || !filt->outputs[j]->dst) {
229  pad = &filt->output_pads[j];
230  av_log(log_ctx, AV_LOG_ERROR,
231  "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
232  pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
233  return AVERROR(EINVAL);
234  }
235  }
236  }
237 
238  return 0;
239 }
240 
241 /**
242  * Configure all the links of graphctx.
243  *
244  * @return >= 0 in case of success, a negative value otherwise
245  */
246 static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
247 {
249  int i, ret;
250 
251  for (i = 0; i < graph->nb_filters; i++) {
252  filt = graph->filters[i];
253 
254  if (!filt->nb_outputs) {
256  return ret;
257  }
258  }
259 
260  return 0;
261 }
262 
263 static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
264 {
266  AVFilterLink *l;
267  unsigned i, j;
268  int ret;
269 
270  for (i = 0; i < graph->nb_filters; i++) {
271  f = graph->filters[i];
272  for (j = 0; j < f->nb_outputs; j++) {
273  l = f->outputs[j];
274  if (l->type == AVMEDIA_TYPE_VIDEO) {
275  ret = av_image_check_size2(l->w, l->h, INT64_MAX, l->format, 0, f);
276  if (ret < 0)
277  return ret;
278  }
279  }
280  }
281  return 0;
282 }
283 
285 {
286  int i;
287 
288  for (i = 0; i < graph->nb_filters; i++)
289  if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
290  return graph->filters[i];
291 
292  return NULL;
293 }
294 
296 {
297  int ret;
298 
299  switch (link->type) {
300 
301  case AVMEDIA_TYPE_VIDEO:
302  if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 ||
305  return ret;
306  break;
307 
308  case AVMEDIA_TYPE_AUDIO:
309  if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
312  return ret;
313  break;
314 
315  default:
316  av_assert0(!"reached");
317  }
318  return 0;
319 }
320 
321 /**
322  * Check the validity of the formats / etc. lists set by query_formats().
323  *
324  * In particular, check they do not contain any redundant element.
325  */
327 {
328  unsigned i;
329  int ret;
330 
331  for (i = 0; i < ctx->nb_inputs; i++) {
332  ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
333  if (ret < 0)
334  return ret;
335  }
336  for (i = 0; i < ctx->nb_outputs; i++) {
337  ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
338  if (ret < 0)
339  return ret;
340  }
341  return 0;
342 }
343 
345 {
346  const FFFilter *const filter = fffilter(ctx->filter);
347  int ret;
348 
349  if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
350  if ((ret = filter->formats.query_func(ctx)) < 0) {
351  if (ret != AVERROR(EAGAIN))
352  av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
353  ctx->name, av_err2str(ret));
354  return ret;
355  }
356  } else if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
357  AVFilterFormatsConfig *cfg_in_stack[64], *cfg_out_stack[64];
358  AVFilterFormatsConfig **cfg_in_dyn = NULL, **cfg_out_dyn = NULL;
359  AVFilterFormatsConfig **cfg_in, **cfg_out;
360 
361  if (ctx->nb_inputs > FF_ARRAY_ELEMS(cfg_in_stack)) {
362  cfg_in_dyn = av_malloc_array(ctx->nb_inputs, sizeof(*cfg_in_dyn));
363  if (!cfg_in_dyn)
364  return AVERROR(ENOMEM);
365  cfg_in = cfg_in_dyn;
366  } else
367  cfg_in = ctx->nb_inputs ? cfg_in_stack : NULL;
368 
369  for (unsigned i = 0; i < ctx->nb_inputs; i++) {
370  AVFilterLink *l = ctx->inputs[i];
371  cfg_in[i] = &l->outcfg;
372  }
373 
374  if (ctx->nb_outputs > FF_ARRAY_ELEMS(cfg_out_stack)) {
375  cfg_out_dyn = av_malloc_array(ctx->nb_outputs, sizeof(*cfg_out_dyn));
376  if (!cfg_out_dyn) {
377  av_freep(&cfg_in_dyn);
378  return AVERROR(ENOMEM);
379  }
380  cfg_out = cfg_out_dyn;
381  } else
382  cfg_out = ctx->nb_outputs ? cfg_out_stack : NULL;
383 
384  for (unsigned i = 0; i < ctx->nb_outputs; i++) {
385  AVFilterLink *l = ctx->outputs[i];
386  cfg_out[i] = &l->incfg;
387  }
388 
389  ret = filter->formats.query_func2(ctx, cfg_in, cfg_out);
390  av_freep(&cfg_in_dyn);
391  av_freep(&cfg_out_dyn);
392  if (ret < 0) {
393  if (ret != AVERROR(EAGAIN))
394  av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
395  ctx->name, av_err2str(ret));
396  return ret;
397  }
398  }
399 
400  if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC ||
401  filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
403  if (ret < 0)
404  return ret;
405  }
406 
408 }
409 
411 {
412  int i;
413 
414  for (i = 0; i < f->nb_inputs; i++) {
415  if (!f->inputs[i]->outcfg.formats)
416  return 0;
417  if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO &&
418  !(f->inputs[i]->outcfg.color_ranges &&
419  f->inputs[i]->outcfg.color_spaces))
420  return 0;
421  if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO &&
422  !(f->inputs[i]->outcfg.samplerates &&
423  f->inputs[i]->outcfg.channel_layouts))
424  return 0;
425  }
426  for (i = 0; i < f->nb_outputs; i++) {
427  if (!f->outputs[i]->incfg.formats)
428  return 0;
429  if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO &&
430  !(f->outputs[i]->incfg.color_ranges &&
431  f->outputs[i]->incfg.color_spaces))
432  return 0;
433  if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO &&
434  !(f->outputs[i]->incfg.samplerates &&
435  f->outputs[i]->incfg.channel_layouts))
436  return 0;
437  }
438  return 1;
439 }
440 
441 /**
442  * Perform one round of query_formats() and merging formats lists on the
443  * filter graph.
444  * @return >=0 if all links formats lists could be queried and merged;
445  * AVERROR(EAGAIN) some progress was made in the queries or merging
446  * and a later call may succeed;
447  * AVERROR(EIO) (may be changed) plus a log message if no progress
448  * was made and the negotiation is stuck;
449  * a negative error code if some other error happened
450  */
451 static int query_formats(AVFilterGraph *graph, void *log_ctx)
452 {
453  int i, j, ret;
454  int converter_count = 0;
455  int count_queried = 0; /* successful calls to query_formats() */
456  int count_merged = 0; /* successful merge of formats lists */
457  int count_already_merged = 0; /* lists already merged */
458  int count_delayed = 0; /* lists that need to be merged later */
459 
460  for (i = 0; i < graph->nb_filters; i++) {
461  AVFilterContext *f = graph->filters[i];
462  if (formats_declared(f))
463  continue;
465  if (ret < 0 && ret != AVERROR(EAGAIN))
466  return ret;
467  /* note: EAGAIN could indicate a partial success, not counted yet */
468  count_queried += ret >= 0;
469  }
470 
471  /* go through and merge as many format lists as possible */
472  for (i = 0; i < graph->nb_filters; i++) {
473  AVFilterContext *filter = graph->filters[i];
474 
475  for (j = 0; j < filter->nb_inputs; j++) {
476  AVFilterLink *link = filter->inputs[j];
477  const AVFilterNegotiation *neg;
478  unsigned neg_step;
479  int convert_needed = 0;
480 
481  if (!link)
482  continue;
483 
485  av_assert0(neg);
486  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
487  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
488  void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
489  void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
490  if (a && b && a != b && !m->can_merge(a, b)) {
491  convert_needed = 1;
492  break;
493  }
494  }
495  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
496  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
497  void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
498  void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
499  if (!(a && b)) {
500  count_delayed++;
501  } else if (a == b) {
502  count_already_merged++;
503  } else if (!convert_needed) {
504  count_merged++;
505  ret = m->merge(a, b);
506  if (ret < 0)
507  return ret;
508  if (!ret)
509  convert_needed = 1;
510  }
511  }
512 
513  if (convert_needed) {
515  const AVFilter *filter;
516  AVFilterLink *inlink, *outlink;
517  char inst_name[30];
518  const char *opts;
519 
520  if (fffiltergraph(graph)->disable_auto_convert) {
521  av_log(log_ctx, AV_LOG_ERROR,
522  "The filters '%s' and '%s' do not have a common format "
523  "and automatic conversion is disabled.\n",
524  link->src->name, link->dst->name);
525  return AVERROR(EINVAL);
526  }
527 
528  /* couldn't merge format lists. auto-insert conversion filter */
530  av_log(log_ctx, AV_LOG_ERROR,
531  "'%s' filter not present, cannot convert formats.\n",
532  neg->conversion_filter);
533  return AVERROR(EINVAL);
534  }
535  snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
536  neg->conversion_filter, converter_count++);
537  opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph);
538  ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph);
539  if (ret < 0)
540  return ret;
541  if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0)
542  return ret;
543 
544  if ((ret = filter_query_formats(convert)) < 0)
545  return ret;
546 
547  inlink = convert->inputs[0];
548  outlink = convert->outputs[0];
549  av_assert0( inlink->incfg.formats->refcount > 0);
550  av_assert0( inlink->outcfg.formats->refcount > 0);
551  av_assert0(outlink->incfg.formats->refcount > 0);
552  av_assert0(outlink->outcfg.formats->refcount > 0);
553  if (outlink->type == AVMEDIA_TYPE_VIDEO) {
554  av_assert0( inlink-> incfg.color_spaces->refcount > 0);
555  av_assert0( inlink->outcfg.color_spaces->refcount > 0);
556  av_assert0(outlink-> incfg.color_spaces->refcount > 0);
557  av_assert0(outlink->outcfg.color_spaces->refcount > 0);
558  av_assert0( inlink-> incfg.color_ranges->refcount > 0);
559  av_assert0( inlink->outcfg.color_ranges->refcount > 0);
560  av_assert0(outlink-> incfg.color_ranges->refcount > 0);
561  av_assert0(outlink->outcfg.color_ranges->refcount > 0);
562  } else if (outlink->type == AVMEDIA_TYPE_AUDIO) {
563  av_assert0( inlink-> incfg.samplerates->refcount > 0);
564  av_assert0( inlink->outcfg.samplerates->refcount > 0);
565  av_assert0(outlink-> incfg.samplerates->refcount > 0);
566  av_assert0(outlink->outcfg.samplerates->refcount > 0);
567  av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
568  av_assert0( inlink->outcfg.channel_layouts->refcount > 0);
569  av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
570  av_assert0(outlink->outcfg.channel_layouts->refcount > 0);
571  }
572 #define MERGE(merger, link) \
573  ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
574  FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
575  for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
576  const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
577  if ((ret = MERGE(m, inlink)) <= 0 ||
578  (ret = MERGE(m, outlink)) <= 0) {
579  if (ret < 0)
580  return ret;
581  av_log(log_ctx, AV_LOG_ERROR,
582  "Impossible to convert between the formats supported by the filter "
583  "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
584  return AVERROR(ENOSYS);
585  }
586  }
587  }
588  }
589  }
590 
591  av_log(graph, AV_LOG_DEBUG, "query_formats: "
592  "%d queried, %d merged, %d already done, %d delayed\n",
593  count_queried, count_merged, count_already_merged, count_delayed);
594  if (count_delayed) {
595  AVBPrint bp;
596 
597  /* if count_queried > 0, one filter at least did set its formats,
598  that will give additional information to its neighbour;
599  if count_merged > 0, one pair of formats lists at least was merged,
600  that will give additional information to all connected filters;
601  in both cases, progress was made and a new round must be done */
602  if (count_queried || count_merged)
603  return AVERROR(EAGAIN);
605  for (i = 0; i < graph->nb_filters; i++)
606  if (!formats_declared(graph->filters[i]))
607  av_bprintf(&bp, "%s%s", bp.len ? ", " : "",
608  graph->filters[i]->name);
609  av_log(graph, AV_LOG_ERROR,
610  "The following filters could not choose their formats: %s\n"
611  "Consider inserting the (a)format filter near their input or "
612  "output.\n", bp.str);
613  return AVERROR(EIO);
614  }
615  return 0;
616 }
617 
618 static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
619 {
620  int score = 0;
621 
622  if (av_sample_fmt_is_planar(dst_fmt) != av_sample_fmt_is_planar(src_fmt))
623  score ++;
624 
625  if (av_get_bytes_per_sample(dst_fmt) < av_get_bytes_per_sample(src_fmt)) {
626  score += 100 * (av_get_bytes_per_sample(src_fmt) - av_get_bytes_per_sample(dst_fmt));
627  }else
628  score += 10 * (av_get_bytes_per_sample(dst_fmt) - av_get_bytes_per_sample(src_fmt));
629 
632  score += 20;
633 
636  score += 2;
637 
638  return score;
639 }
640 
642  enum AVSampleFormat src_fmt)
643 {
644  int score1, score2;
645 
646  score1 = get_fmt_score(dst_fmt1, src_fmt);
647  score2 = get_fmt_score(dst_fmt2, src_fmt);
648 
649  return score1 < score2 ? dst_fmt1 : dst_fmt2;
650 }
651 
653 {
655  if (!desc)
656  return 0;
657  if (desc->nb_components < 3)
658  return 0; /* Grayscale is explicitly full-range in swscale */
660  return !(desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL |
662 }
663 
664 
666 {
667  switch (fmt) {
668  case AV_PIX_FMT_YUVJ420P:
669  case AV_PIX_FMT_YUVJ422P:
670  case AV_PIX_FMT_YUVJ444P:
671  case AV_PIX_FMT_YUVJ440P:
672  case AV_PIX_FMT_YUVJ411P:
673  return 1;
674  default:
675  return 0;
676  }
677 }
678 
680 {
681  if (!link || !link->incfg.formats)
682  return 0;
683 
684  if (link->type == AVMEDIA_TYPE_VIDEO) {
685  if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
686  //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
687  int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
688  enum AVPixelFormat best= AV_PIX_FMT_NONE;
689  int i;
690  for (i = 0; i < link->incfg.formats->nb_formats; i++) {
691  enum AVPixelFormat p = link->incfg.formats->formats[i];
692  best= av_find_best_pix_fmt_of_2(best, p, ref->format, has_alpha, NULL);
693  }
694  av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s alpha:%d\n",
695  av_get_pix_fmt_name(best), link->incfg.formats->nb_formats,
696  av_get_pix_fmt_name(ref->format), has_alpha);
697  link->incfg.formats->formats[0] = best;
698  }
699  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
700  if(ref && ref->type == AVMEDIA_TYPE_AUDIO){
702  int i;
703  for (i = 0; i < link->incfg.formats->nb_formats; i++) {
704  enum AVSampleFormat p = link->incfg.formats->formats[i];
705  best = find_best_sample_fmt_of_2(best, p, ref->format);
706  }
707  av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s\n",
708  av_get_sample_fmt_name(best), link->incfg.formats->nb_formats,
709  av_get_sample_fmt_name(ref->format));
710  link->incfg.formats->formats[0] = best;
711  }
712  }
713 
714  link->incfg.formats->nb_formats = 1;
715  link->format = link->incfg.formats->formats[0];
716 
717  if (link->type == AVMEDIA_TYPE_VIDEO) {
718  enum AVPixelFormat swfmt = link->format;
720  // FIXME: this is a hack - we'd like to use the sw_format of
721  // link->hw_frames_ctx here, but it is not yet available.
722  // To make this work properly we will need to either reorder
723  // things so that it is available here or somehow negotiate
724  // sw_format separately.
725  swfmt = AV_PIX_FMT_YUV420P;
726  }
727 
728  if (!ff_fmt_is_regular_yuv(swfmt)) {
730  /* These fields are explicitly documented as affecting YUV only,
731  * so set them to sane values for other formats. */
732  if (desc->flags & AV_PIX_FMT_FLAG_FLOAT)
734  else
736  if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ)) {
738  } else {
740  }
741  } else {
742  if (!link->incfg.color_spaces->nb_formats) {
743  av_log(link->src, AV_LOG_ERROR, "Cannot select color space for"
744  " the link between filters %s and %s.\n", link->src->name,
745  link->dst->name);
746  return AVERROR(EINVAL);
747  }
748  link->incfg.color_spaces->nb_formats = 1;
749  link->colorspace = link->incfg.color_spaces->formats[0];
750 
751  if (ff_fmt_is_forced_full_range(swfmt)) {
753  } else {
754  if (!link->incfg.color_ranges->nb_formats) {
755  av_log(link->src, AV_LOG_ERROR, "Cannot select color range for"
756  " the link between filters %s and %s.\n", link->src->name,
757  link->dst->name);
758  return AVERROR(EINVAL);
759  }
760  link->incfg.color_ranges->nb_formats = 1;
761  link->color_range = link->incfg.color_ranges->formats[0];
762  }
763  }
764  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
765  int ret;
766 
767  if (!link->incfg.samplerates->nb_formats) {
768  av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
769  " the link between filters %s and %s.\n", link->src->name,
770  link->dst->name);
771  return AVERROR(EINVAL);
772  }
773  link->incfg.samplerates->nb_formats = 1;
774  link->sample_rate = link->incfg.samplerates->formats[0];
775 
776  if (link->incfg.channel_layouts->all_layouts) {
777  av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
778  " the link between filters %s and %s.\n", link->src->name,
779  link->dst->name);
780  if (!link->incfg.channel_layouts->all_counts)
781  av_log(link->src, AV_LOG_ERROR, "Unknown channel layouts not "
782  "supported, try specifying a channel layout using "
783  "'aformat=channel_layouts=something'.\n");
784  return AVERROR(EINVAL);
785  }
786  link->incfg.channel_layouts->nb_channel_layouts = 1;
787  ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]);
788  if (ret < 0)
789  return ret;
790  }
791 
792  ff_formats_unref(&link->incfg.formats);
793  ff_formats_unref(&link->outcfg.formats);
794  ff_formats_unref(&link->incfg.samplerates);
795  ff_formats_unref(&link->outcfg.samplerates);
796  ff_channel_layouts_unref(&link->incfg.channel_layouts);
797  ff_channel_layouts_unref(&link->outcfg.channel_layouts);
798  ff_formats_unref(&link->incfg.color_spaces);
799  ff_formats_unref(&link->outcfg.color_spaces);
800  ff_formats_unref(&link->incfg.color_ranges);
801  ff_formats_unref(&link->outcfg.color_ranges);
802 
803  return 0;
804 }
805 
806 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
807 do { \
808  for (i = 0; i < filter->nb_inputs; i++) { \
809  AVFilterLink *link = filter->inputs[i]; \
810  fmt_type fmt; \
811  \
812  if (!link->outcfg.list || link->outcfg.list->nb != 1) \
813  continue; \
814  fmt = link->outcfg.list->var[0]; \
815  \
816  for (j = 0; j < filter->nb_outputs; j++) { \
817  AVFilterLink *out_link = filter->outputs[j]; \
818  list_type *fmts; \
819  \
820  if (link->type != out_link->type || \
821  out_link->incfg.list->nb == 1) \
822  continue; \
823  fmts = out_link->incfg.list; \
824  \
825  if (!out_link->incfg.list->nb) { \
826  if ((ret = add_format(&out_link->incfg.list, fmt)) < 0)\
827  return ret; \
828  ret = 1; \
829  break; \
830  } \
831  \
832  for (k = 0; k < out_link->incfg.list->nb; k++) \
833  if (fmts->var[k] == fmt) { \
834  fmts->var[0] = fmt; \
835  fmts->nb = 1; \
836  ret = 1; \
837  break; \
838  } \
839  } \
840  } \
841 } while (0)
842 
844 {
845  int i, j, k, ret = 0;
846 
848  nb_formats, ff_add_format);
849  REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
850  nb_formats, ff_add_format);
851  REDUCE_FORMATS(int, AVFilterFormats, color_spaces, formats,
852  nb_formats, ff_add_format);
853  REDUCE_FORMATS(int, AVFilterFormats, color_ranges, formats,
854  nb_formats, ff_add_format);
855 
856  /* reduce channel layouts */
857  for (i = 0; i < filter->nb_inputs; i++) {
858  AVFilterLink *inlink = filter->inputs[i];
859  const AVChannelLayout *fmt;
860 
861  if (!inlink->outcfg.channel_layouts ||
862  inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
863  continue;
864  fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
865 
866  for (j = 0; j < filter->nb_outputs; j++) {
867  AVFilterLink *outlink = filter->outputs[j];
869 
870  fmts = outlink->incfg.channel_layouts;
871  if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
872  continue;
873 
874  if (fmts->all_layouts &&
875  (KNOWN(fmt) || fmts->all_counts)) {
876  /* Turn the infinite list into a singleton */
877  fmts->all_layouts = fmts->all_counts = 0;
879  if (ret < 0)
880  return ret;
881  ret = 1;
882  break;
883  }
884 
885  for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
886  if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
887  ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
888  if (ret < 0)
889  return ret;
890  fmts->nb_channel_layouts = 1;
891  ret = 1;
892  break;
893  }
894  }
895  }
896  }
897 
898  return ret;
899 }
900 
901 static int reduce_formats(AVFilterGraph *graph)
902 {
903  int i, reduced, ret;
904 
905  do {
906  reduced = 0;
907 
908  for (i = 0; i < graph->nb_filters; i++) {
909  if ((ret = reduce_formats_on_filter(graph->filters[i])) < 0)
910  return ret;
911  reduced |= ret;
912  }
913  } while (reduced);
914 
915  return 0;
916 }
917 
919 {
921  int sample_rate;
922  int i, j;
923 
924  for (i = 0; i < filter->nb_inputs; i++) {
925  link = filter->inputs[i];
926 
927  if (link->type == AVMEDIA_TYPE_AUDIO &&
928  link->outcfg.samplerates->nb_formats== 1)
929  break;
930  }
931  if (i == filter->nb_inputs)
932  return;
933 
934  sample_rate = link->outcfg.samplerates->formats[0];
935 
936  for (i = 0; i < filter->nb_outputs; i++) {
937  AVFilterLink *outlink = filter->outputs[i];
938  int best_idx, best_diff = INT_MAX;
939 
940  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
941  outlink->incfg.samplerates->nb_formats < 2)
942  continue;
943 
944  for (j = 0; j < outlink->incfg.samplerates->nb_formats; j++) {
945  int diff = abs(sample_rate - outlink->incfg.samplerates->formats[j]);
946 
947  av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
948 
949  if (diff < best_diff) {
950  best_diff = diff;
951  best_idx = j;
952  }
953  }
954  FFSWAP(int, outlink->incfg.samplerates->formats[0],
955  outlink->incfg.samplerates->formats[best_idx]);
956  }
957 }
958 
959 static void swap_samplerates(AVFilterGraph *graph)
960 {
961  int i;
962 
963  for (i = 0; i < graph->nb_filters; i++)
965 }
966 
967 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
968 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
969 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
970 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
971 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
972 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
973 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
974 
975 /* allowable substitutions for channel pairs when comparing layouts,
976  * ordered by priority for both values */
977 static const uint64_t ch_subst[][2] = {
999 };
1000 
1002 {
1003  AVFilterLink *link = NULL;
1004  int i, j, k;
1005 
1006  for (i = 0; i < filter->nb_inputs; i++) {
1007  link = filter->inputs[i];
1008 
1009  if (link->type == AVMEDIA_TYPE_AUDIO &&
1010  link->outcfg.channel_layouts->nb_channel_layouts == 1)
1011  break;
1012  }
1013  if (i == filter->nb_inputs)
1014  return;
1015 
1016  for (i = 0; i < filter->nb_outputs; i++) {
1017  AVFilterLink *outlink = filter->outputs[i];
1018  int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
1019 
1020  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1022  continue;
1023 
1024  for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
1025  AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 };
1026  int in_channels;
1027  int out_channels;
1028  int count_diff;
1029  int matched_channels, extra_channels;
1030  int score = 100000;
1031 
1032  av_channel_layout_copy(&in_chlayout, &link->outcfg.channel_layouts->channel_layouts[0]);
1033  av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]);
1034  in_channels = in_chlayout.nb_channels;
1035  out_channels = out_chlayout.nb_channels;
1036  count_diff = out_channels - in_channels;
1037  if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
1038  /* Compute score in case the input or output layout encodes
1039  a channel count; in this case the score is not altered by
1040  the computation afterwards, as in_chlayout and
1041  out_chlayout have both been set to 0 */
1042  if (!KNOWN(&in_chlayout))
1043  in_channels = FF_LAYOUT2COUNT(&in_chlayout);
1044  if (!KNOWN(&out_chlayout))
1045  out_channels = FF_LAYOUT2COUNT(&out_chlayout);
1046  score -= 10000 + FFABS(out_channels - in_channels) +
1047  (in_channels > out_channels ? 10000 : 0);
1048  av_channel_layout_uninit(&in_chlayout);
1049  av_channel_layout_uninit(&out_chlayout);
1050  /* Let the remaining computation run, even if the score
1051  value is not altered */
1052  }
1053 
1054  /* channel substitution */
1055  for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
1056  uint64_t cmp0 = ch_subst[k][0];
1057  uint64_t cmp1 = ch_subst[k][1];
1058  if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
1059  !av_channel_layout_subset(&out_chlayout, cmp0) &&
1060  av_channel_layout_subset(&out_chlayout, cmp1) &&
1061  !av_channel_layout_subset(& in_chlayout, cmp1)) {
1062  av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
1063  av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
1064  /* add score for channel match, minus a deduction for
1065  having to do the substitution */
1066  score += 10 * av_popcount64(cmp1) - 2;
1067  }
1068  }
1069 
1070  /* no penalty for LFE channel mismatch */
1073  score += 10;
1076 
1077  matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
1078  extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
1079  score += 10 * matched_channels - 5 * extra_channels;
1080 
1081  if (score > best_score ||
1082  (count_diff < best_count_diff && score == best_score)) {
1083  best_score = score;
1084  best_idx = j;
1085  best_count_diff = count_diff;
1086  }
1087  }
1088  av_assert0(best_idx >= 0);
1090  outlink->incfg.channel_layouts->channel_layouts[best_idx]);
1091  }
1092 
1093 }
1094 
1096 {
1097  int i;
1098 
1099  for (i = 0; i < graph->nb_filters; i++)
1101 }
1102 
1104 {
1105  AVFilterLink *link = NULL;
1106  int format, bps;
1107  int i, j;
1108 
1109  for (i = 0; i < filter->nb_inputs; i++) {
1110  link = filter->inputs[i];
1111 
1112  if (link->type == AVMEDIA_TYPE_AUDIO &&
1113  link->outcfg.formats->nb_formats == 1)
1114  break;
1115  }
1116  if (i == filter->nb_inputs)
1117  return;
1118 
1119  format = link->outcfg.formats->formats[0];
1121 
1122  for (i = 0; i < filter->nb_outputs; i++) {
1123  AVFilterLink *outlink = filter->outputs[i];
1124  int best_idx = -1, best_score = INT_MIN;
1125 
1126  if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1127  outlink->incfg.formats->nb_formats < 2)
1128  continue;
1129 
1130  for (j = 0; j < outlink->incfg.formats->nb_formats; j++) {
1131  int out_format = outlink->incfg.formats->formats[j];
1132  int out_bps = av_get_bytes_per_sample(out_format);
1133  int score;
1134 
1135  if (av_get_packed_sample_fmt(out_format) == format ||
1136  av_get_planar_sample_fmt(out_format) == format) {
1137  best_idx = j;
1138  break;
1139  }
1140 
1141  /* for s32 and float prefer double to prevent loss of information */
1142  if (bps == 4 && out_bps == 8) {
1143  best_idx = j;
1144  break;
1145  }
1146 
1147  /* prefer closest higher or equal bps */
1148  score = -abs(out_bps - bps);
1149  if (out_bps >= bps)
1150  score += INT_MAX/2;
1151 
1152  if (score > best_score) {
1153  best_score = score;
1154  best_idx = j;
1155  }
1156  }
1157  av_assert0(best_idx >= 0);
1158  FFSWAP(int, outlink->incfg.formats->formats[0],
1159  outlink->incfg.formats->formats[best_idx]);
1160  }
1161 }
1162 
1163 static void swap_sample_fmts(AVFilterGraph *graph)
1164 {
1165  int i;
1166 
1167  for (i = 0; i < graph->nb_filters; i++)
1169 
1170 }
1171 
1172 static int pick_formats(AVFilterGraph *graph)
1173 {
1174  int i, j, ret;
1175  int change;
1176 
1177  do{
1178  change = 0;
1179  for (i = 0; i < graph->nb_filters; i++) {
1180  AVFilterContext *filter = graph->filters[i];
1181  if (filter->nb_inputs){
1182  for (j = 0; j < filter->nb_inputs; j++){
1183  if (filter->inputs[j]->incfg.formats && filter->inputs[j]->incfg.formats->nb_formats == 1) {
1184  if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1185  return ret;
1186  change = 1;
1187  }
1188  }
1189  }
1190  if (filter->nb_outputs){
1191  for (j = 0; j < filter->nb_outputs; j++){
1192  if (filter->outputs[j]->incfg.formats && filter->outputs[j]->incfg.formats->nb_formats == 1) {
1193  if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1194  return ret;
1195  change = 1;
1196  }
1197  }
1198  }
1199  if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
1200  for (j = 0; j < filter->nb_outputs; j++) {
1201  if (filter->outputs[j]->format<0) {
1202  if ((ret = pick_format(filter->outputs[j], filter->inputs[0])) < 0)
1203  return ret;
1204  change = 1;
1205  }
1206  }
1207  }
1208  }
1209  }while(change);
1210 
1211  for (i = 0; i < graph->nb_filters; i++) {
1212  AVFilterContext *filter = graph->filters[i];
1213 
1214  for (j = 0; j < filter->nb_inputs; j++)
1215  if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1216  return ret;
1217  for (j = 0; j < filter->nb_outputs; j++)
1218  if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1219  return ret;
1220  }
1221  return 0;
1222 }
1223 
1224 /**
1225  * Configure the formats of all the links in the graph.
1226  */
1227 static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
1228 {
1229  int ret;
1230 
1231  /* find supported formats from sub-filters, and merge along links */
1232  while ((ret = query_formats(graph, log_ctx)) == AVERROR(EAGAIN))
1233  av_log(graph, AV_LOG_DEBUG, "query_formats not finished\n");
1234  if (ret < 0)
1235  return ret;
1236 
1237  /* Once everything is merged, it's possible that we'll still have
1238  * multiple valid media format choices. We try to minimize the amount
1239  * of format conversion inside filters */
1240  if ((ret = reduce_formats(graph)) < 0)
1241  return ret;
1242 
1243  /* for audio filters, ensure the best format, sample rate and channel layout
1244  * is selected */
1245  swap_sample_fmts(graph);
1246  swap_samplerates(graph);
1247  swap_channel_layouts(graph);
1248 
1249  if ((ret = pick_formats(graph)) < 0)
1250  return ret;
1251 
1252  return 0;
1253 }
1254 
1255 static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
1256 {
1257  unsigned i, j;
1258  int sink_links_count = 0, n = 0;
1259  AVFilterContext *f;
1260  FilterLinkInternal **sinks;
1261 
1262  for (i = 0; i < graph->nb_filters; i++) {
1263  f = graph->filters[i];
1264  for (j = 0; j < f->nb_inputs; j++) {
1265  ff_link_internal(f->inputs[j])->age_index = -1;
1266  }
1267  for (j = 0; j < f->nb_outputs; j++) {
1268  ff_link_internal(f->outputs[j])->age_index = -1;
1269  }
1270  if (!f->nb_outputs) {
1271  if (f->nb_inputs > INT_MAX - sink_links_count)
1272  return AVERROR(EINVAL);
1273  sink_links_count += f->nb_inputs;
1274  }
1275  }
1276  sinks = av_calloc(sink_links_count, sizeof(*sinks));
1277  if (!sinks)
1278  return AVERROR(ENOMEM);
1279  for (i = 0; i < graph->nb_filters; i++) {
1280  f = graph->filters[i];
1281  if (!f->nb_outputs) {
1282  for (j = 0; j < f->nb_inputs; j++) {
1283  sinks[n] = ff_link_internal(f->inputs[j]);
1284  sinks[n]->age_index = n;
1285  n++;
1286  }
1287  }
1288  }
1289  av_assert0(n == sink_links_count);
1290  fffiltergraph(graph)->sink_links = sinks;
1291  fffiltergraph(graph)->sink_links_count = sink_links_count;
1292  return 0;
1293 }
1294 
1295 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
1296 {
1297  int ret;
1298 
1299  if ((ret = graph_check_validity(graphctx, log_ctx)))
1300  return ret;
1301  if ((ret = graph_config_formats(graphctx, log_ctx)))
1302  return ret;
1303  if ((ret = graph_config_links(graphctx, log_ctx)))
1304  return ret;
1305  if ((ret = graph_check_links(graphctx, log_ctx)))
1306  return ret;
1307  if ((ret = graph_config_pointers(graphctx, log_ctx)))
1308  return ret;
1309 
1310  return 0;
1311 }
1312 
1313 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
1314 {
1315  int i, r = AVERROR(ENOSYS);
1316 
1317  if (!graph)
1318  return r;
1319 
1321  r = avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
1322  if (r != AVERROR(ENOSYS))
1323  return r;
1324  }
1325 
1326  if (res_len && res)
1327  res[0] = 0;
1328 
1329  for (i = 0; i < graph->nb_filters; i++) {
1330  AVFilterContext *filter = graph->filters[i];
1331  if (!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)) {
1332  r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
1333  if (r != AVERROR(ENOSYS)) {
1334  if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1335  return r;
1336  }
1337  }
1338  }
1339 
1340  return r;
1341 }
1342 
1343 int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
1344 {
1345  int i;
1346 
1347  if(!graph)
1348  return 0;
1349 
1350  for (i = 0; i < graph->nb_filters; i++) {
1351  AVFilterContext *filter = graph->filters[i];
1353  if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
1354  AVFilterCommand **queue = &ctxi->command_queue, *next;
1355  while (*queue && (*queue)->time <= ts)
1356  queue = &(*queue)->next;
1357  next = *queue;
1358  *queue = av_mallocz(sizeof(AVFilterCommand));
1359  if (!*queue)
1360  return AVERROR(ENOMEM);
1361 
1362  (*queue)->command = av_strdup(command);
1363  (*queue)->arg = av_strdup(arg);
1364  (*queue)->time = ts;
1365  (*queue)->flags = flags;
1366  (*queue)->next = next;
1368  return 0;
1369  }
1370  }
1371 
1372  return 0;
1373 }
1374 
1375 static void heap_bubble_up(FFFilterGraph *graph,
1376  FilterLinkInternal *li, int index)
1377 {
1378  FilterLinkInternal **links = graph->sink_links;
1379 
1380  av_assert0(index >= 0);
1381 
1382  while (index) {
1383  int parent = (index - 1) >> 1;
1384  if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
1385  break;
1386  links[index] = links[parent];
1387  links[index]->age_index = index;
1388  index = parent;
1389  }
1390  links[index] = li;
1391  li->age_index = index;
1392 }
1393 
1394 static void heap_bubble_down(FFFilterGraph *graph,
1395  FilterLinkInternal *li, int index)
1396 {
1397  FilterLinkInternal **links = graph->sink_links;
1398 
1399  av_assert0(index >= 0);
1400 
1401  while (1) {
1402  int child = 2 * index + 1;
1403  if (child >= graph->sink_links_count)
1404  break;
1405  if (child + 1 < graph->sink_links_count &&
1406  links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
1407  child++;
1408  if (li->l.current_pts_us < links[child]->l.current_pts_us)
1409  break;
1410  links[index] = links[child];
1411  links[index]->age_index = index;
1412  index = child;
1413  }
1414  links[index] = li;
1415  li->age_index = index;
1416 }
1417 
1419 {
1420  FFFilterGraph *graphi = fffiltergraph(graph);
1421 
1422  heap_bubble_up (graphi, li, li->age_index);
1423  heap_bubble_down(graphi, li, li->age_index);
1424 }
1425 
1427 {
1428  FFFilterGraph *graphi = fffiltergraph(graph);
1429  FilterLinkInternal *oldesti = graphi->sink_links[0];
1430  AVFilterLink *oldest = &oldesti->l.pub;
1431  int64_t frame_count;
1432  int r;
1433 
1434  while (graphi->sink_links_count) {
1435  oldesti = graphi->sink_links[0];
1436  oldest = &oldesti->l.pub;
1437  if (fffilter(oldest->dst->filter)->activate) {
1440  if (r != AVERROR_EOF)
1441  return r;
1442  } else {
1443  r = ff_request_frame(oldest);
1444  }
1445  if (r != AVERROR_EOF)
1446  break;
1447  av_log(oldest->dst, AV_LOG_DEBUG, "EOF on sink link %s:%s.\n",
1448  oldest->dst->name,
1449  oldest->dstpad->name);
1450  /* EOF: remove the link from the heap */
1451  if (oldesti->age_index < --graphi->sink_links_count)
1452  heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
1453  oldesti->age_index);
1454  oldesti->age_index = -1;
1455  }
1456  if (!graphi->sink_links_count)
1457  return AVERROR_EOF;
1458  av_assert1(!fffilter(oldest->dst->filter)->activate);
1459  av_assert1(oldesti->age_index >= 0);
1460  frame_count = oldesti->l.frame_count_out;
1461  while (frame_count == oldesti->l.frame_count_out) {
1462  r = ff_filter_graph_run_once(graph);
1463  if (r == AVERROR(EAGAIN) &&
1464  !oldesti->frame_wanted_out && !oldesti->frame_blocked_in &&
1465  !oldesti->status_in)
1466  (void)ff_request_frame(oldest);
1467  else if (r < 0)
1468  return r;
1469  }
1470  return 0;
1471 }
1472 
1474 {
1475  FFFilterContext *ctxi;
1476  unsigned i;
1477 
1478  av_assert0(graph->nb_filters);
1479  ctxi = fffilterctx(graph->filters[0]);
1480  for (i = 1; i < graph->nb_filters; i++) {
1481  FFFilterContext *ctxi_other = fffilterctx(graph->filters[i]);
1482 
1483  if (ctxi_other->ready > ctxi->ready)
1484  ctxi = ctxi_other;
1485  }
1486 
1487  if (!ctxi->ready)
1488  return AVERROR(EAGAIN);
1489  return ff_filter_activate(&ctxi->p);
1490 }
formats
formats
Definition: signature.h:47
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:631
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:464
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:697
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:119
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:45
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:1678
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:90
r
const char * r
Definition: vf_curves.c:127
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_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: filters.h:228
opt.h
AVFilterGraph::nb_threads
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:610
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:124
ch_subst
static const uint64_t ch_subst[][2]
Definition: avfiltergraph.c:977
REDUCE_FORMATS
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format)
Definition: avfiltergraph.c:806
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:157
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3244
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:142
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:1106
int64_t
long long int64_t
Definition: coverity.c:34
FFFilterGraph
Definition: avfilter_internal.h:134
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:344
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:1438
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:708
swap_sample_fmts
static void swap_sample_fmts(AVFilterGraph *graph)
Definition: avfiltergraph.c:1163
pixdesc.h
AVFilterNegotiation::conversion_filter
const char * conversion_filter
Definition: formats.h:563
graph_check_validity
static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
Check for the validity of graph.
Definition: avfiltergraph.c:208
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:728
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:673
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:451
AVOption
AVOption.
Definition: opt.h:429
FFFilterGraph::sink_links
struct FilterLinkInternal ** sink_links
Definition: avfilter_internal.h:140
b
#define b
Definition: input.c:41
pick_formats
static int pick_formats(AVFilterGraph *graph)
Definition: avfiltergraph.c:1172
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:491
FilterLinkInternal::l
FilterLink l
Definition: avfilter_internal.h:35
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:652
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
pick_format
static int pick_format(AVFilterLink *link, AVFilterLink *ref)
Definition: avfiltergraph.c:679
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:1473
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:351
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
video.h
AVChannelLayout::u
union AVChannelLayout::@432 u
Details about which channels are present in this layout.
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:652
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:715
convert
static void convert(float y, float u, float v, float *b, float *g, float *r)
Definition: exr.c:963
swap_samplerates
static void swap_samplerates(AVFilterGraph *graph)
Definition: avfiltergraph.c:959
FF_LAYOUT2COUNT
#define FF_LAYOUT2COUNT(l)
Decode a channel count encoded as a channel layout.
Definition: formats.h:108
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:462
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graphp)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:117
FilterLinkInternal
Definition: avfilter_internal.h:34
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:618
ff_fmt_is_forced_full_range
int ff_fmt_is_forced_full_range(enum AVPixelFormat fmt)
Returns true if a YUV pixel format is forced full range (i.e.
Definition: avfiltergraph.c:665
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)
A convenience wrapper that allocates and initializes a filter in a single step.
Definition: avfiltergraph.c:138
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:165
fail
#define fail()
Definition: checkasm.h:193
avfilter_graph_alloc
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:83
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:75
reduce_formats
static int reduce_formats(AVFilterGraph *graph)
Definition: avfiltergraph.c:901
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:293
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:1227
OFFSET
#define OFFSET(x)
Definition: avfiltergraph.c:44
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1949
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:819
FFFilterContext::p
AVFilterContext p
The public AVFilterContext.
Definition: avfilter_internal.h:99
AVFILTER_THREAD_SLICE
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
Definition: avfilter.h:254
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:560
FFFilterGraph::sink_links_count
int sink_links_count
Definition: avfilter_internal.h:141
heap_bubble_up
static void heap_bubble_up(FFFilterGraph *graph, FilterLinkInternal *li, int index)
Definition: avfiltergraph.c:1375
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: filters.h:38
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:561
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
ff_filter_config_links
int ff_filter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:336
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:843
avassert.h
FFFilterGraph::thread_execute
avfilter_execute_func * thread_execute
Definition: avfilter_internal.h:146
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
MERGE
#define MERGE(merger, link)
FFFilter
Definition: filters.h:265
AV_CH_LOW_FREQUENCY
#define AV_CH_LOW_FREQUENCY
Definition: channel_layout.h:178
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:84
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
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:624
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:252
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:55
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
filters.h
filtergraph_options
static const AVOption filtergraph_options[]
Definition: avfiltergraph.c:48
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVFilterFormatsConfig::color_spaces
AVFilterFormats * color_spaces
Lists of supported YUV color metadata, only for YUV video.
Definition: avfilter.h:129
CH_DIRECT_PAIR
#define CH_DIRECT_PAIR
Definition: avfiltergraph.c:972
graph_config_pointers
static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
Definition: avfiltergraph.c:1255
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:562
command
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:1195
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:74
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:637
opts
AVDictionary * opts
Definition: movenc.c:51
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
FFFilter::activate
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: filters.h:459
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
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:1295
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:160
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:586
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:262
fffiltergraph
static FFFilterGraph * fffiltergraph(AVFilterGraph *graph)
Definition: avfilter_internal.h:150
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:284
avfilter_graph_request_oldest
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
Definition: avfiltergraph.c:1426
graph_config_links
static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
Configure all the links of graphctx.
Definition: avfiltergraph.c:246
abs
#define abs(x)
Definition: cuda_runtime.h:35
avfilter_internal.h
AVFilterGraph
Definition: avfilter.h:584
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:177
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:694
index
int index
Definition: gxfenc.c:90
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:109
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
FFFilterContext::command_queue
struct AVFilterCommand * command_queue
Definition: avfilter_internal.h:118
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:1111
ff_graph_thread_free
void ff_graph_thread_free(FFFilterGraph *graph)
Definition: avfiltergraph.c:71
f
f
Definition: af_crystalizer.c:122
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:1123
CH_BACK_PAIR
#define CH_BACK_PAIR
Definition: avfiltergraph.c:973
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:1025
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
FilterLinkInternal::age_index
int age_index
Index in the age array.
Definition: avfilter_internal.h:80
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:1418
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:131
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:122
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:609
bps
unsigned bps
Definition: movenc.c:1880
CH_CENTER_PAIR
#define CH_CENTER_PAIR
Definition: avfiltergraph.c:967
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:1343
AVFilterChannelLayouts::channel_layouts
AVChannelLayout * channel_layouts
list of channel layouts
Definition: formats.h:86
FFFilterGraph::frame_queues
FFFrameQueueGlobal frame_queues
Definition: avfilter_internal.h:147
AVFilterChannelLayouts::all_layouts
char all_layouts
accept any known channel layout
Definition: formats.h:88
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:497
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:1146
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:166
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:641
AVFilterFormatsConfig::color_ranges
AVFilterFormats * color_ranges
AVColorRange.
Definition: avfilter.h:130
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:809
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:971
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:49
filter_link_check_formats
static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
Definition: avfiltergraph.c:295
CH_FRONT_PAIR
#define CH_FRONT_PAIR
Definition: avfiltergraph.c:968
swap_sample_fmts_on_filter
static void swap_sample_fmts_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:1103
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:1116
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:143
fffilterctx
static FFFilterContext * fffilterctx(AVFilterContext *ctx)
Definition: avfilter_internal.h:121
swap_channel_layouts_on_filter
static void swap_channel_layouts_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:1001
graph_check_links
static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
Definition: avfiltergraph.c:263
AVFilterCommand
Definition: avfilter_internal.h:126
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
FilterLinkInternal::status_in
int status_in
Link input status.
Definition: avfilter_internal.h:56
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:183
V
#define V
Definition: avfiltergraph.c:46
FilterLinkInternal::frame_wanted_out
int frame_wanted_out
True if a frame is currently wanted on the output of this filter.
Definition: avfilter_internal.h:75
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:256
AVFilterGraph::thread_type
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:603
filt
static const int8_t filt[NUMTAPS *2]
Definition: af_earwax.c:40
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:654
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
swap_channel_layouts
static void swap_channel_layouts(AVFilterGraph *graph)
Definition: avfiltergraph.c:1095
ff_formats_check_color_ranges
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition: formats.c:1134
AVFilter
Filter definition.
Definition: avfilter.h:199
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:465
FFFilterContext::ready
unsigned ready
Ready status of the filter.
Definition: avfilter_internal.h:111
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: filters.h:49
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:80
AVFilterNegotiation::conversion_opts_offset
unsigned conversion_opts_offset
Definition: formats.h:564
CH_SIDE_PAIR
#define CH_SIDE_PAIR
Definition: avfiltergraph.c:971
heap_bubble_down
static void heap_bubble_down(FFFilterGraph *graph, FilterLinkInternal *li, int index)
Definition: avfiltergraph.c:1394
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:229
formats_declared
static int formats_declared(AVFilterContext *f)
Definition: avfiltergraph.c:410
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:3523
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:865
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:99
CH_WIDE_PAIR
#define CH_WIDE_PAIR
Definition: avfiltergraph.c:970
ff_framequeue_global_init
void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
Init a global structure.
Definition: framequeue.c:31
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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:442
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
FFFilterContext
Definition: avfilter_internal.h:95
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
KNOWN
#define KNOWN(l)
Definition: formats.h:111
FFFilterGraph::p
AVFilterGraph p
The public AVFilterGraph.
Definition: avfilter_internal.h:138
AVFilterContext
An instance of a filter.
Definition: avfilter.h:257
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:449
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:79
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
mem.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:114
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:811
A
#define A
Definition: avfiltergraph.c:47
swap_samplerates_on_filter
static void swap_samplerates_on_filter(AVFilterContext *filter)
Definition: avfiltergraph.c:918
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
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:1313
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:85
AVFilterGraph::nb_filters
unsigned nb_filters
Definition: avfilter.h:587
AVFilterContext::filter
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:260
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
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:326
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:62
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
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:3164
AVFilterCommand::time
double time
time expressed in seconds
Definition: avfilter_internal.h:127