FFmpeg
Loading...
Searching...
No Matches
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
48static 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 {"max_buffered_frames" , "maximum number of buffered frames allowed", OFFSET(max_buffered_frames),
60 AV_OPT_TYPE_UINT, {.i64 = 0}, 0, UINT_MAX, F|V|A },
61 { NULL },
62};
63
64static const AVClass filtergraph_class = {
65 .class_name = "AVFilterGraph",
66 .item_name = av_default_item_name,
67 .version = LIBAVUTIL_VERSION_INT,
68 .option = filtergraph_options,
69 .category = AV_CLASS_CATEGORY_FILTER,
70};
71
72#if !HAVE_THREADS
76
78{
79 graph->p.thread_type = 0;
80 graph->p.nb_threads = 1;
81 return 0;
82}
83#endif
84
86{
87 FFFilterGraph *graph = av_mallocz(sizeof(*graph));
88 AVFilterGraph *ret;
89
90 if (!graph)
91 return NULL;
92
93 ret = &graph->p;
97
98 return ret;
99}
100
102{
103 int i, j;
104 for (i = 0; i < graph->nb_filters; i++) {
105 if (graph->filters[i] == filter) {
107 graph->filters[graph->nb_filters - 1]);
108 graph->nb_filters--;
109 filter->graph = NULL;
110 for (j = 0; j<filter->nb_outputs; j++)
111 if (filter->outputs[j])
112 ff_filter_link(filter->outputs[j])->graph = NULL;
113
114 return;
115 }
116 }
117}
118
120{
121 AVFilterGraph *graph = *graphp;
122 FFFilterGraph *graphi = fffiltergraph(graph);
123
124 if (!graph)
125 return;
126
127 while (graph->nb_filters)
128 avfilter_free(graph->filters[0]);
129
130 ff_graph_thread_free(graphi);
131
132 av_freep(&graphi->sink_links);
133
134 av_opt_free(graph);
135
136 av_freep(&graph->filters);
137 av_freep(graphp);
138}
139
141 const char *name, const char *args, void *opaque,
142 AVFilterGraph *graph_ctx)
143{
144 int ret;
145
146 *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
147 if (!*filt_ctx)
148 return AVERROR(ENOMEM);
149
150 ret = avfilter_init_str(*filt_ctx, args);
151 if (ret < 0)
152 goto fail;
153
154 return 0;
155
156fail:
157 avfilter_free(*filt_ctx);
158 *filt_ctx = NULL;
159 return ret;
160}
161
166
168 const AVFilter *filter,
169 const char *name)
170{
172 FFFilterGraph *graphi = fffiltergraph(graph);
173
174 if (graph->thread_type && !graphi->thread_execute) {
175 if (graph->execute) {
176 graphi->thread_execute = graph->execute;
177 } else {
178 int ret = ff_graph_thread_init(graphi);
179 if (ret < 0) {
180 av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
181 return NULL;
182 }
183 }
184 }
185
186 filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
187 if (!filters)
188 return NULL;
189 graph->filters = filters;
190
192 if (!s)
193 return NULL;
194
195 graph->filters[graph->nb_filters++] = s;
196
197 s->graph = graph;
198
199 return s;
200}
201
202/**
203 * Check for the validity of graph.
204 *
205 * A graph is considered valid if all its input and output pads are
206 * connected.
207 *
208 * @return >= 0 in case of success, a negative value otherwise
209 */
210static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
211{
213 int i, j;
214
215 for (i = 0; i < graph->nb_filters; i++) {
216 const AVFilterPad *pad;
217 filt = graph->filters[i];
218
219 for (j = 0; j < filt->nb_inputs; j++) {
220 if (!filt->inputs[j] || !filt->inputs[j]->src) {
221 pad = &filt->input_pads[j];
222 av_log(log_ctx, AV_LOG_ERROR,
223 "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
224 pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
225 return AVERROR(EINVAL);
226 }
227 }
228
229 for (j = 0; j < filt->nb_outputs; j++) {
230 if (!filt->outputs[j] || !filt->outputs[j]->dst) {
231 pad = &filt->output_pads[j];
232 av_log(log_ctx, AV_LOG_ERROR,
233 "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
234 pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
235 return AVERROR(EINVAL);
236 }
237 }
238 }
239
240 return 0;
241}
242
243/**
244 * Configure all the links of graphctx.
245 *
246 * @return >= 0 in case of success, a negative value otherwise
247 */
248static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
249{
251 int i, ret;
252
253 for (i = 0; i < graph->nb_filters; i++) {
254 filt = graph->filters[i];
255
256 if (!filt->nb_outputs) {
257 if ((ret = ff_filter_config_links(filt)))
258 return ret;
259 }
260 }
261
262 return 0;
263}
264
265static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
266{
268 AVFilterLink *l;
269 unsigned i, j;
270 int ret;
271
272 for (i = 0; i < graph->nb_filters; i++) {
273 f = graph->filters[i];
274 for (j = 0; j < f->nb_outputs; j++) {
275 l = f->outputs[j];
276 if (l->type == AVMEDIA_TYPE_VIDEO) {
277 ret = av_image_check_size2(l->w, l->h, INT64_MAX, l->format, 0, f);
278 if (ret < 0)
279 return ret;
280 }
281 }
282 }
283 return 0;
284}
285
287{
288 int i;
289
290 for (i = 0; i < graph->nb_filters; i++)
291 if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
292 return graph->filters[i];
293
294 return NULL;
295}
296
298{
299 int ret;
300
301 switch (link->type) {
302
304 if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 ||
305 (ret = ff_formats_check_color_spaces(log, cfg->color_spaces)) < 0 ||
306 (ret = ff_formats_check_color_ranges(log, cfg->color_ranges)) < 0 ||
307 (ret = ff_formats_check_alpha_modes(log, cfg->alpha_modes)) < 0)
308 return ret;
309 break;
310
312 if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
313 (ret = ff_formats_check_sample_rates(log, cfg->samplerates)) < 0 ||
314 (ret = ff_formats_check_channel_layouts(log, cfg->channel_layouts)) < 0)
315 return ret;
316 break;
317
318 default:
319 av_assert0(!"reached");
320 }
321 return 0;
322}
323
324/**
325 * Check the validity of the formats / etc. lists set by query_formats().
326 *
327 * In particular, check they do not contain any redundant element.
328 */
330{
331 unsigned i;
332 int ret;
333
334 for (i = 0; i < ctx->nb_inputs; i++) {
335 ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
336 if (ret < 0)
337 return ret;
338 }
339 for (i = 0; i < ctx->nb_outputs; i++) {
340 ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
341 if (ret < 0)
342 return ret;
343 }
344 return 0;
345}
346
348{
349 const FFFilter *const filter = fffilter(ctx->filter);
350 int ret;
351
352 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
353 if ((ret = filter->formats.query_func(ctx)) < 0) {
354 if (ret != AVERROR(EAGAIN))
355 av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
356 ctx->name, av_err2str(ret));
357 return ret;
358 }
359 } else if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
360 AVFilterFormatsConfig *cfg_in_stack[64], *cfg_out_stack[64];
361 AVFilterFormatsConfig **cfg_in_dyn = NULL, **cfg_out_dyn = NULL;
362 AVFilterFormatsConfig **cfg_in, **cfg_out;
363
364 if (ctx->nb_inputs > FF_ARRAY_ELEMS(cfg_in_stack)) {
365 cfg_in_dyn = av_malloc_array(ctx->nb_inputs, sizeof(*cfg_in_dyn));
366 if (!cfg_in_dyn)
367 return AVERROR(ENOMEM);
368 cfg_in = cfg_in_dyn;
369 } else
370 cfg_in = ctx->nb_inputs ? cfg_in_stack : NULL;
371
372 for (unsigned i = 0; i < ctx->nb_inputs; i++) {
373 AVFilterLink *l = ctx->inputs[i];
374 cfg_in[i] = &l->outcfg;
375 }
376
377 if (ctx->nb_outputs > FF_ARRAY_ELEMS(cfg_out_stack)) {
378 cfg_out_dyn = av_malloc_array(ctx->nb_outputs, sizeof(*cfg_out_dyn));
379 if (!cfg_out_dyn) {
380 av_freep(&cfg_in_dyn);
381 return AVERROR(ENOMEM);
382 }
383 cfg_out = cfg_out_dyn;
384 } else
385 cfg_out = ctx->nb_outputs ? cfg_out_stack : NULL;
386
387 for (unsigned i = 0; i < ctx->nb_outputs; i++) {
388 AVFilterLink *l = ctx->outputs[i];
389 cfg_out[i] = &l->incfg;
390 }
391
392 ret = filter->formats.query_func2(ctx, cfg_in, cfg_out);
393 av_freep(&cfg_in_dyn);
394 av_freep(&cfg_out_dyn);
395 if (ret < 0) {
396 if (ret != AVERROR(EAGAIN))
397 av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
398 ctx->name, av_err2str(ret));
399 return ret;
400 }
401 }
402
403 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC ||
404 filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
406 if (ret < 0)
407 return ret;
408 }
409
411}
412
414{
415 int i;
416
417 for (i = 0; i < f->nb_inputs; i++) {
418 if (!f->inputs[i]->outcfg.formats)
419 return 0;
420 if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO &&
421 !(f->inputs[i]->outcfg.color_ranges &&
422 f->inputs[i]->outcfg.color_spaces &&
423 f->inputs[i]->outcfg.alpha_modes))
424 return 0;
425 if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO &&
426 !(f->inputs[i]->outcfg.samplerates &&
427 f->inputs[i]->outcfg.channel_layouts))
428 return 0;
429 }
430 for (i = 0; i < f->nb_outputs; i++) {
431 if (!f->outputs[i]->incfg.formats)
432 return 0;
433 if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO &&
434 !(f->outputs[i]->incfg.color_ranges &&
435 f->outputs[i]->incfg.color_spaces &&
436 f->outputs[i]->incfg.alpha_modes))
437 return 0;
438 if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO &&
439 !(f->outputs[i]->incfg.samplerates &&
440 f->outputs[i]->incfg.channel_layouts))
441 return 0;
442 }
443 return 1;
444}
445
446static void print_link_formats(void *log_ctx, int level, const AVFilterLink *l,
447 const AVFilterFormatsMerger *mergers[],
448 int nb_mergers)
449{
450 if (av_log_get_level() < level)
451 return;
452
453 AVBPrint bp;
455
456 av_log(log_ctx, level, "Link '%s.%s' -> '%s.%s':\n",
457 l->src->name, l->srcpad->name, l->dst->name, l->dstpad->name);
458
459 for (unsigned i = 0; i < nb_mergers; i++) {
460 const AVFilterFormatsMerger *m = mergers[i];
461 av_log(log_ctx, level, " %s:\n", m->name);
462 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->incfg));
463 if (av_bprint_is_complete(&bp))
464 av_log(log_ctx, level, " src: %s\n", bp.str);
465 av_bprint_clear(&bp);
466
467 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->outcfg));
468 if (av_bprint_is_complete(&bp))
469 av_log(log_ctx, level, " dst: %s\n", bp.str);
470 av_bprint_clear(&bp);
471 }
472
474}
475
476static void print_filter_formats(void *log_ctx, int level, const AVFilterContext *f)
477{
478 if (av_log_get_level() < level)
479 return;
480
481 AVBPrint bp;
483
484 av_log(log_ctx, level, "Filter '%s' formats:\n", f->name);
485 for (int i = 0; i < f->nb_inputs; i++) {
486 const AVFilterLink *in = f->inputs[i];
488 av_log(log_ctx, level, " in[%d] '%s':\n", i, f->input_pads[i].name);
489
490 for (unsigned i = 0; i < neg->nb_mergers; i++) {
491 const AVFilterFormatsMerger *m = &neg->mergers[i];
492 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, in->outcfg));
493 if (av_bprint_is_complete(&bp))
494 av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
495 av_bprint_clear(&bp);
496 }
497 }
498
499 for (int i = 0; i < f->nb_outputs; i++) {
500 const AVFilterLink *out = f->outputs[i];
502 av_log(log_ctx, level, " out[%d] '%s':\n", i, f->output_pads[i].name);
503
504 for (unsigned i = 0; i < neg->nb_mergers; i++) {
505 const AVFilterFormatsMerger *m = &neg->mergers[i];
506 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, out->incfg));
507 if (av_bprint_is_complete(&bp))
508 av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
509 av_bprint_clear(&bp);
510 }
511 }
512
514}
515
516/**
517 * Perform one round of query_formats() and merging formats lists on the
518 * filter graph.
519 * @return >=0 if all links formats lists could be queried and merged;
520 * AVERROR(EAGAIN) some progress was made in the queries or merging
521 * and a later call may succeed;
522 * AVERROR(EIO) (may be changed) plus a log message if no progress
523 * was made and the negotiation is stuck;
524 * a negative error code if some other error happened
525 */
526static int query_formats(AVFilterGraph *graph, void *log_ctx)
527{
528 int i, j, k, ret;
529 int converter_count = 0;
530 int count_queried = 0; /* successful calls to query_formats() */
531 int count_merged = 0; /* successful merge of formats lists */
532 int count_already_merged = 0; /* lists already merged */
533 int count_delayed = 0; /* lists that need to be merged later */
534
535 for (i = 0; i < graph->nb_filters; i++) {
536 AVFilterContext *f = graph->filters[i];
537 if (formats_declared(f))
538 continue;
539 ret = filter_query_formats(f);
540 if (ret < 0 && ret != AVERROR(EAGAIN))
541 return ret;
542 /* note: EAGAIN could indicate a partial success, not counted yet */
543 if (ret >= 0) {
545 count_queried++;
546 }
547 }
548
549 /* go through and merge as many format lists as possible */
550retry:
551 for (i = 0; i < graph->nb_filters; i++) {
552 AVFilterContext *filter = graph->filters[i];
553
554 for (j = 0; j < filter->nb_inputs; j++) {
555 AVFilterLink *link = filter->inputs[j];
556 const AVFilterNegotiation *neg;
557 AVFilterContext *conv[4];
558 const AVFilterFormatsMerger *mergers[4]; /* triggered mergers */
559 const char *conv_filters[4], *conv_opts[4] = {0};
560 unsigned neg_step, num_conv = 0, num_mergers = 0;
561
562 if (!link)
563 continue;
564
565 neg = ff_filter_get_negotiation(link);
566 av_assert0(neg);
567 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
568 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
569 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
570 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
571 if (a && b && a != b && !m->can_merge(a, b)) {
572 for (k = 0; k < num_conv; k++) {
573 if (!strcmp(conv_filters[k], m->conversion_filter))
574 break;
575 }
576 if (k == num_conv) {
577 av_assert1(num_conv < FF_ARRAY_ELEMS(conv_filters));
578 conv_filters[num_conv] = m->conversion_filter;
580 conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
581 num_conv++;
582 }
583 av_assert1(num_mergers < FF_ARRAY_ELEMS(mergers));
584 mergers[num_mergers++] = m;
585 }
586 }
587 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
588 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
589 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
590 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
591 if (!(a && b)) {
592 count_delayed++;
593 } else if (a == b) {
594 count_already_merged++;
595 } else if (!num_conv) {
596 count_merged++;
597 ret = m->merge(a, b);
598 if (ret < 0)
599 return ret;
600 if (!ret) {
601 mergers[num_mergers++] = m;
602 conv_filters[num_conv] = m->conversion_filter;
604 conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
605 num_conv++;
606 }
607 }
608 }
609
610 /**
611 * Couldn't merge format lists; auto-insert conversion filters
612 * in reverse order to keep the order consistent with the list
613 * of mergers, since they are prepended onto the existing link
614 */
615 for (k = num_conv - 1; k >= 0; k--) {
616 const AVFilter *filter;
617 char inst_name[30];
618
619 if (fffiltergraph(graph)->disable_auto_convert) {
620 av_log(log_ctx, AV_LOG_ERROR,
621 "The filters '%s' and '%s' do not have a common format "
622 "and automatic conversion is disabled.\n",
623 link->src->name, link->dst->name);
624 print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
625 return AVERROR(EINVAL);
626 }
627
628 if (!(filter = avfilter_get_by_name(conv_filters[k]))) {
629 av_log(log_ctx, AV_LOG_ERROR,
630 "'%s' filter not present, cannot convert formats.\n",
631 conv_filters[k]);
632 print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
633 return AVERROR(EINVAL);
634 }
635 snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
636 conv_filters[k], converter_count++);
637 ret = avfilter_graph_create_filter(&conv[k], filter, inst_name,
638 conv_opts[k], NULL, graph);
639 if (ret < 0)
640 return ret;
641 if ((ret = avfilter_insert_filter(link, conv[k], 0, 0)) < 0)
642 return ret;
643
644 if ((ret = filter_query_formats(conv[k])) < 0)
645 return ret;
646 }
647
648 /* preemptively settle formats of auto filters */
649 for (k = 0; k < num_conv; k++) {
650 AVFilterLink *inlink = conv[k]->inputs[0];
651 AVFilterLink *outlink = conv[k]->outputs[0];
652 av_assert0( inlink->incfg.formats->refcount > 0);
653 av_assert0( inlink->outcfg.formats->refcount > 0);
654 av_assert0(outlink->incfg.formats->refcount > 0);
655 av_assert0(outlink->outcfg.formats->refcount > 0);
656 if (outlink->type == AVMEDIA_TYPE_VIDEO) {
657 av_assert0( inlink-> incfg.color_spaces->refcount > 0);
658 av_assert0( inlink->outcfg.color_spaces->refcount > 0);
659 av_assert0(outlink-> incfg.color_spaces->refcount > 0);
660 av_assert0(outlink->outcfg.color_spaces->refcount > 0);
661 av_assert0( inlink-> incfg.color_ranges->refcount > 0);
662 av_assert0( inlink->outcfg.color_ranges->refcount > 0);
663 av_assert0(outlink-> incfg.color_ranges->refcount > 0);
664 av_assert0(outlink->outcfg.color_ranges->refcount > 0);
665 av_assert0( inlink-> incfg.alpha_modes->refcount > 0);
666 av_assert0( inlink->outcfg.alpha_modes->refcount > 0);
667 av_assert0(outlink-> incfg.alpha_modes->refcount > 0);
668 av_assert0(outlink->outcfg.alpha_modes->refcount > 0);
669 } else if (outlink->type == AVMEDIA_TYPE_AUDIO) {
670 av_assert0( inlink-> incfg.samplerates->refcount > 0);
671 av_assert0( inlink->outcfg.samplerates->refcount > 0);
672 av_assert0(outlink-> incfg.samplerates->refcount > 0);
673 av_assert0(outlink->outcfg.samplerates->refcount > 0);
674 av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
676 av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
678 }
679
680#define MERGE(merger, link) \
681 ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
682 FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
683
684 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
685 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
686 if (strcmp(m->conversion_filter, conv_filters[k]))
687 continue;
688 if ((ret = MERGE(m, inlink)) <= 0 ||
689 (ret = MERGE(m, outlink)) <= 0) {
690 if (ret < 0)
691 return ret;
692 av_log(log_ctx, AV_LOG_ERROR,
693 "Impossible to convert between the formats supported by the filter "
694 "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
695 print_link_formats(log_ctx, AV_LOG_ERROR, inlink, &m, 1);
696 print_link_formats(log_ctx, AV_LOG_ERROR, outlink, &m, 1);
697 return AVERROR(ENOSYS);
698 } else {
699 count_merged += 2;
700 }
701 }
702 }
703
704 /* if there is an auto filter, we may need another round to fully
705 * settle formats due to possible cross-incompatibilities between
706 * the auto filters themselves, or between the auto filters and
707 * a different attribute of the filter they are modifying */
708 if (num_conv)
709 goto retry;
710 }
711 }
712
713 av_log(graph, AV_LOG_DEBUG, "query_formats: "
714 "%d queried, %d merged, %d already done, %d delayed\n",
715 count_queried, count_merged, count_already_merged, count_delayed);
716 if (count_delayed) {
717 AVBPrint bp;
718
719 /* if count_queried > 0, one filter at least did set its formats,
720 that will give additional information to its neighbour;
721 if count_merged > 0, one pair of formats lists at least was merged,
722 that will give additional information to all connected filters;
723 in both cases, progress was made and a new round must be done */
724 if (count_queried || count_merged)
725 return AVERROR(EAGAIN);
727 for (i = 0; i < graph->nb_filters; i++)
728 if (!formats_declared(graph->filters[i]))
729 av_bprintf(&bp, "%s%s", bp.len ? ", " : "",
730 graph->filters[i]->name);
731 av_log(graph, AV_LOG_ERROR,
732 "The following filters could not choose their formats: %s\n"
733 "Consider inserting the (a)format filter near their input or "
734 "output.\n", bp.str);
735 return AVERROR(EIO);
736 }
737 return 0;
738}
739
740static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
741{
742 int score = 0;
743
744 if (av_sample_fmt_is_planar(dst_fmt) != av_sample_fmt_is_planar(src_fmt))
745 score ++;
746
747 if (av_get_bytes_per_sample(dst_fmt) < av_get_bytes_per_sample(src_fmt)) {
748 score += 100 * (av_get_bytes_per_sample(src_fmt) - av_get_bytes_per_sample(dst_fmt));
749 }else
750 score += 10 * (av_get_bytes_per_sample(dst_fmt) - av_get_bytes_per_sample(src_fmt));
751
754 score += 20;
755
758 score += 2;
759
760 return score;
761}
762
764 enum AVSampleFormat src_fmt)
765{
766 int score1, score2;
767
768 score1 = get_fmt_score(dst_fmt1, src_fmt);
769 score2 = get_fmt_score(dst_fmt2, src_fmt);
770
771 return score1 < score2 ? dst_fmt1 : dst_fmt2;
772}
773
775{
777 if (!desc)
778 return 0;
779 if (desc->nb_components < 3)
780 return 0; /* Grayscale is explicitly full-range in swscale */
782 return !(desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL |
784}
785
786
788{
789 switch (fmt) {
795 return 1;
796 default:
797 return 0;
798 }
799}
800
802{
803 if (!link || !link->incfg.formats)
804 return 0;
805
806 if (link->type == AVMEDIA_TYPE_VIDEO) {
807 if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
808 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
809 int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
811 int i;
812 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
813 enum AVPixelFormat p = link->incfg.formats->formats[i];
814 best= av_find_best_pix_fmt_of_2(best, p, ref->format, has_alpha, NULL);
815 }
816 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s alpha:%d\n",
818 av_get_pix_fmt_name(ref->format), has_alpha);
819 link->incfg.formats->formats[0] = best;
820 }
821 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
822 if(ref && ref->type == AVMEDIA_TYPE_AUDIO){
824 int i;
825 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
826 enum AVSampleFormat p = link->incfg.formats->formats[i];
827 best = find_best_sample_fmt_of_2(best, p, ref->format);
828 }
829 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s\n",
831 av_get_sample_fmt_name(ref->format));
832 link->incfg.formats->formats[0] = best;
833 }
834 }
835
836 link->incfg.formats->nb_formats = 1;
837 link->format = link->incfg.formats->formats[0];
838
839 if (link->type == AVMEDIA_TYPE_VIDEO) {
840 enum AVPixelFormat swfmt = link->format;
842 // FIXME: this is a hack - we'd like to use the sw_format of
843 // link->hw_frames_ctx here, but it is not yet available.
844 // To make this work properly we will need to either reorder
845 // things so that it is available here or somehow negotiate
846 // sw_format separately.
847 swfmt = AV_PIX_FMT_YUV420P;
848 }
849
851 if (!ff_fmt_is_regular_yuv(swfmt)) {
852 /* These fields are explicitly documented as affecting YUV only,
853 * so set them to sane values for other formats. */
854 if (desc->flags & AV_PIX_FMT_FLAG_FLOAT)
856 else
860 } else {
862 }
863 } else {
864 if (!link->incfg.color_spaces->nb_formats) {
865 av_log(link->src, AV_LOG_ERROR, "Cannot select color space for"
866 " the link between filters %s and %s.\n", link->src->name,
867 link->dst->name);
868 return AVERROR(EINVAL);
869 }
870 link->incfg.color_spaces->nb_formats = 1;
871 link->colorspace = link->incfg.color_spaces->formats[0];
872
873 if (ff_fmt_is_forced_full_range(swfmt)) {
875 } else {
876 if (!link->incfg.color_ranges->nb_formats) {
877 av_log(link->src, AV_LOG_ERROR, "Cannot select color range for"
878 " the link between filters %s and %s.\n", link->src->name,
879 link->dst->name);
880 return AVERROR(EINVAL);
881 }
882 link->incfg.color_ranges->nb_formats = 1;
883 link->color_range = link->incfg.color_ranges->formats[0];
884 }
885 }
886
887 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) {
888 if (!link->incfg.alpha_modes->nb_formats) {
889 av_log(link->src, AV_LOG_ERROR, "Cannot select alpha mode for"
890 " the link between filters %s and %s.\n", link->src->name,
891 link->dst->name);
892 return AVERROR(EINVAL);
893 }
894 link->incfg.alpha_modes->nb_formats = 1;
895 link->alpha_mode = link->incfg.alpha_modes->formats[0];
896 } else {
898 }
899 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
900 int ret;
901
902 if (!link->incfg.samplerates->nb_formats) {
903 av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
904 " the link between filters %s and %s.\n", link->src->name,
905 link->dst->name);
906 return AVERROR(EINVAL);
907 }
908 link->incfg.samplerates->nb_formats = 1;
909 link->sample_rate = link->incfg.samplerates->formats[0];
910
911 if (link->incfg.channel_layouts->all_layouts) {
912 av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
913 " the link between filters %s and %s.\n", link->src->name,
914 link->dst->name);
915 if (!link->incfg.channel_layouts->all_counts)
916 av_log(link->src, AV_LOG_ERROR, "Unknown channel layouts not "
917 "supported, try specifying a channel layout using "
918 "'aformat=channel_layouts=something'.\n");
919 return AVERROR(EINVAL);
920 }
923 if (ret < 0)
924 return ret;
925 }
926
939
940 return 0;
941}
942
943#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
944do { \
945 for (i = 0; i < filter->nb_inputs; i++) { \
946 AVFilterLink *link = filter->inputs[i]; \
947 fmt_type fmt; \
948 \
949 if (!link->outcfg.list || link->outcfg.list->nb != 1) \
950 continue; \
951 fmt = link->outcfg.list->var[0]; \
952 \
953 for (j = 0; j < filter->nb_outputs; j++) { \
954 AVFilterLink *out_link = filter->outputs[j]; \
955 list_type *fmts; \
956 \
957 if (link->type != out_link->type || \
958 out_link->incfg.list->nb == 1) \
959 continue; \
960 fmts = out_link->incfg.list; \
961 \
962 if (!out_link->incfg.list->nb) { \
963 if ((ret = add_format(&out_link->incfg.list, fmt)) < 0)\
964 return ret; \
965 ret = 1; \
966 break; \
967 } \
968 \
969 for (k = 0; k < out_link->incfg.list->nb; k++) \
970 if (fmts->var[k] == fmt) { \
971 fmts->var[0] = fmt; \
972 fmts->nb = 1; \
973 ret = 1; \
974 break; \
975 } \
976 } \
977 } \
978} while (0)
979
981{
982 int i, j, k, ret = 0;
983
985 nb_formats, ff_add_format);
986 REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
987 nb_formats, ff_add_format);
988 REDUCE_FORMATS(int, AVFilterFormats, color_spaces, formats,
989 nb_formats, ff_add_format);
990 REDUCE_FORMATS(int, AVFilterFormats, color_ranges, formats,
991 nb_formats, ff_add_format);
992 REDUCE_FORMATS(int, AVFilterFormats, alpha_modes, formats,
993 nb_formats, ff_add_format);
994
995 /* reduce channel layouts */
996 for (i = 0; i < filter->nb_inputs; i++) {
997 AVFilterLink *inlink = filter->inputs[i];
998 const AVChannelLayout *fmt;
999
1000 if (!inlink->outcfg.channel_layouts ||
1002 continue;
1003 fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
1004
1005 for (j = 0; j < filter->nb_outputs; j++) {
1006 AVFilterLink *outlink = filter->outputs[j];
1008
1009 fmts = outlink->incfg.channel_layouts;
1010 if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
1011 continue;
1012
1013 if (fmts->all_layouts &&
1014 (KNOWN(fmt) || fmts->all_counts)) {
1015 /* Turn the infinite list into a singleton */
1016 fmts->all_layouts = fmts->all_counts = 0;
1017 ret = ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt);
1018 if (ret < 0)
1019 return ret;
1020 ret = 1;
1021 break;
1022 }
1023
1024 for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
1025 if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
1026 ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
1027 if (ret < 0)
1028 return ret;
1029 fmts->nb_channel_layouts = 1;
1030 ret = 1;
1031 break;
1032 }
1033 }
1034 }
1035 }
1036
1037 return ret;
1038}
1039
1041{
1042 int i, reduced, ret;
1043
1044 do {
1045 reduced = 0;
1046
1047 for (i = 0; i < graph->nb_filters; i++) {
1048 if ((ret = reduce_formats_on_filter(graph->filters[i])) < 0)
1049 return ret;
1050 reduced |= ret;
1051 }
1052 } while (reduced);
1053
1054 return 0;
1055}
1056
1058{
1059 AVFilterLink *link = NULL;
1060 int sample_rate;
1061 int i, j;
1062
1063 for (i = 0; i < filter->nb_inputs; i++) {
1064 link = filter->inputs[i];
1065
1066 if (link->type == AVMEDIA_TYPE_AUDIO &&
1067 link->outcfg.samplerates->nb_formats== 1)
1068 break;
1069 }
1070 if (i == filter->nb_inputs)
1071 return;
1072
1073 sample_rate = link->outcfg.samplerates->formats[0];
1074
1075 for (i = 0; i < filter->nb_outputs; i++) {
1076 AVFilterLink *outlink = filter->outputs[i];
1077 int best_idx, best_diff = INT_MAX;
1078
1079 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1080 outlink->incfg.samplerates->nb_formats < 2)
1081 continue;
1082
1083 for (j = 0; j < outlink->incfg.samplerates->nb_formats; j++) {
1084 int diff = abs(sample_rate - outlink->incfg.samplerates->formats[j]);
1085
1086 av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
1087
1088 if (diff < best_diff) {
1089 best_diff = diff;
1090 best_idx = j;
1091 }
1092 }
1093 FFSWAP(int, outlink->incfg.samplerates->formats[0],
1094 outlink->incfg.samplerates->formats[best_idx]);
1095 }
1096}
1097
1099{
1100 int i;
1101
1102 for (i = 0; i < graph->nb_filters; i++)
1104}
1105
1106#define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
1107#define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
1108#define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
1109#define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
1110#define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
1111#define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
1112#define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
1113
1114/* allowable substitutions for channel pairs when comparing layouts,
1115 * ordered by priority for both values */
1139
1141{
1142 AVFilterLink *link = NULL;
1143 int i, j, k;
1144
1145 for (i = 0; i < filter->nb_inputs; i++) {
1146 link = filter->inputs[i];
1147
1148 if (link->type == AVMEDIA_TYPE_AUDIO &&
1150 break;
1151 }
1152 if (i == filter->nb_inputs)
1153 return;
1154
1155 for (i = 0; i < filter->nb_outputs; i++) {
1156 AVFilterLink *outlink = filter->outputs[i];
1157 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
1158
1159 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1161 continue;
1162
1163 for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
1164 AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 };
1165 int in_channels;
1166 int out_channels;
1167 int count_diff;
1168 int matched_channels, extra_channels;
1169 int score = 100000;
1170
1172 av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]);
1173 in_channels = in_chlayout.nb_channels;
1174 out_channels = out_chlayout.nb_channels;
1175 count_diff = out_channels - in_channels;
1176 if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
1177 /* Compute score in case the input or output layout encodes
1178 a channel count; in this case the score is not altered by
1179 the computation afterwards, as in_chlayout and
1180 out_chlayout have both been set to 0 */
1181 if (!KNOWN(&in_chlayout))
1182 in_channels = FF_LAYOUT2COUNT(&in_chlayout);
1183 if (!KNOWN(&out_chlayout))
1184 out_channels = FF_LAYOUT2COUNT(&out_chlayout);
1185 score -= 10000 + FFABS(out_channels - in_channels) +
1186 (in_channels > out_channels ? 10000 : 0);
1187 av_channel_layout_uninit(&in_chlayout);
1188 av_channel_layout_uninit(&out_chlayout);
1189 /* Let the remaining computation run, even if the score
1190 value is not altered */
1191 }
1192
1193 /* channel substitution */
1194 for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
1195 uint64_t cmp0 = ch_subst[k][0];
1196 uint64_t cmp1 = ch_subst[k][1];
1197 if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
1198 !av_channel_layout_subset(&out_chlayout, cmp0) &&
1199 av_channel_layout_subset(&out_chlayout, cmp1) &&
1200 !av_channel_layout_subset(& in_chlayout, cmp1)) {
1201 av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
1202 av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
1203 /* add score for channel match, minus a deduction for
1204 having to do the substitution */
1205 score += 10 * av_popcount64(cmp1) - 2;
1206 }
1207 }
1208
1209 /* no penalty for LFE channel mismatch */
1212 score += 10;
1215
1216 matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
1217 extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
1218 score += 10 * matched_channels - 5 * extra_channels;
1219
1220 if (score > best_score ||
1221 (count_diff < best_count_diff && score == best_score)) {
1222 best_score = score;
1223 best_idx = j;
1224 best_count_diff = count_diff;
1225 }
1226 }
1227 av_assert0(best_idx >= 0);
1229 outlink->incfg.channel_layouts->channel_layouts[best_idx]);
1230 }
1231
1232}
1233
1235{
1236 int i;
1237
1238 for (i = 0; i < graph->nb_filters; i++)
1240}
1241
1243{
1244 AVFilterLink *link = NULL;
1245 int format, bps;
1246 int i, j;
1247
1248 for (i = 0; i < filter->nb_inputs; i++) {
1249 link = filter->inputs[i];
1250
1251 if (link->type == AVMEDIA_TYPE_AUDIO &&
1252 link->outcfg.formats->nb_formats == 1)
1253 break;
1254 }
1255 if (i == filter->nb_inputs)
1256 return;
1257
1258 format = link->outcfg.formats->formats[0];
1260
1261 for (i = 0; i < filter->nb_outputs; i++) {
1262 AVFilterLink *outlink = filter->outputs[i];
1263 int best_idx = -1, best_score = INT_MIN;
1264
1265 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1266 outlink->incfg.formats->nb_formats < 2)
1267 continue;
1268
1269 for (j = 0; j < outlink->incfg.formats->nb_formats; j++) {
1270 int out_format = outlink->incfg.formats->formats[j];
1271 int out_bps = av_get_bytes_per_sample(out_format);
1272 int score;
1273
1274 if (av_get_packed_sample_fmt(out_format) == format ||
1275 av_get_planar_sample_fmt(out_format) == format) {
1276 best_idx = j;
1277 break;
1278 }
1279
1280 /* for s32 and float prefer double to prevent loss of information */
1281 if (bps == 4 && out_bps == 8) {
1282 best_idx = j;
1283 break;
1284 }
1285
1286 /* prefer closest higher or equal bps */
1287 score = -abs(out_bps - bps);
1288 if (out_bps >= bps)
1289 score += INT_MAX/2;
1290
1291 if (score > best_score) {
1292 best_score = score;
1293 best_idx = j;
1294 }
1295 }
1296 av_assert0(best_idx >= 0);
1297 FFSWAP(int, outlink->incfg.formats->formats[0],
1298 outlink->incfg.formats->formats[best_idx]);
1299 }
1300}
1301
1303{
1304 int i;
1305
1306 for (i = 0; i < graph->nb_filters; i++)
1308
1309}
1310
1311static int pick_formats(AVFilterGraph *graph)
1312{
1313 int i, j, ret;
1314 int change;
1315
1316 do{
1317 change = 0;
1318 for (i = 0; i < graph->nb_filters; i++) {
1319 AVFilterContext *filter = graph->filters[i];
1320 if (filter->nb_inputs){
1321 for (j = 0; j < filter->nb_inputs; j++){
1322 if (filter->inputs[j]->incfg.formats && filter->inputs[j]->incfg.formats->nb_formats == 1) {
1323 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1324 return ret;
1325 change = 1;
1326 }
1327 }
1328 }
1329 if (filter->nb_outputs){
1330 for (j = 0; j < filter->nb_outputs; j++){
1331 if (filter->outputs[j]->incfg.formats && filter->outputs[j]->incfg.formats->nb_formats == 1) {
1332 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1333 return ret;
1334 change = 1;
1335 }
1336 }
1337 }
1338 if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
1339 for (j = 0; j < filter->nb_outputs; j++) {
1340 if (filter->outputs[j]->format<0) {
1341 if ((ret = pick_format(filter->outputs[j], filter->inputs[0])) < 0)
1342 return ret;
1343 change = 1;
1344 }
1345 }
1346 }
1347 }
1348 }while(change);
1349
1350 for (i = 0; i < graph->nb_filters; i++) {
1351 AVFilterContext *filter = graph->filters[i];
1352
1353 for (j = 0; j < filter->nb_inputs; j++)
1354 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1355 return ret;
1356 for (j = 0; j < filter->nb_outputs; j++)
1357 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1358 return ret;
1359 }
1360 return 0;
1361}
1362
1363/**
1364 * Configure the formats of all the links in the graph.
1365 */
1366static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
1367{
1368 int ret;
1369
1370 /* find supported formats from sub-filters, and merge along links */
1371 while ((ret = query_formats(graph, log_ctx)) == AVERROR(EAGAIN))
1372 av_log(graph, AV_LOG_DEBUG, "query_formats not finished\n");
1373 if (ret < 0)
1374 return ret;
1375
1376 /* Once everything is merged, it's possible that we'll still have
1377 * multiple valid media format choices. We try to minimize the amount
1378 * of format conversion inside filters */
1379 if ((ret = reduce_formats(graph)) < 0)
1380 return ret;
1381
1382 /* for audio filters, ensure the best format, sample rate and channel layout
1383 * is selected */
1384 swap_sample_fmts(graph);
1385 swap_samplerates(graph);
1386 swap_channel_layouts(graph);
1387
1388 if ((ret = pick_formats(graph)) < 0)
1389 return ret;
1390
1391 return 0;
1392}
1393
1394static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
1395{
1396 unsigned i, j;
1397 int sink_links_count = 0, n = 0;
1399 FilterLinkInternal **sinks;
1400
1401 for (i = 0; i < graph->nb_filters; i++) {
1402 f = graph->filters[i];
1403 for (j = 0; j < f->nb_inputs; j++) {
1404 ff_link_internal(f->inputs[j])->age_index = -1;
1405 }
1406 for (j = 0; j < f->nb_outputs; j++) {
1407 ff_link_internal(f->outputs[j])->age_index = -1;
1408 }
1409 if (!f->nb_outputs) {
1410 if (f->nb_inputs > INT_MAX - sink_links_count)
1411 return AVERROR(EINVAL);
1412 sink_links_count += f->nb_inputs;
1413 }
1414 }
1415 sinks = av_calloc(sink_links_count, sizeof(*sinks));
1416 if (!sinks)
1417 return AVERROR(ENOMEM);
1418 for (i = 0; i < graph->nb_filters; i++) {
1419 f = graph->filters[i];
1420 if (!f->nb_outputs) {
1421 for (j = 0; j < f->nb_inputs; j++) {
1422 sinks[n] = ff_link_internal(f->inputs[j]);
1423 sinks[n]->age_index = n;
1424 n++;
1425 }
1426 }
1427 }
1428 av_assert0(n == sink_links_count);
1429 fffiltergraph(graph)->sink_links = sinks;
1430 fffiltergraph(graph)->sink_links_count = sink_links_count;
1431 return 0;
1432}
1433
1434int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
1435{
1436 int ret;
1437
1438 if (graphctx->max_buffered_frames)
1440 if ((ret = graph_check_validity(graphctx, log_ctx)))
1441 return ret;
1442 if ((ret = graph_config_formats(graphctx, log_ctx)))
1443 return ret;
1444 if ((ret = graph_config_links(graphctx, log_ctx)))
1445 return ret;
1446 if ((ret = graph_check_links(graphctx, log_ctx)))
1447 return ret;
1448 if ((ret = graph_config_pointers(graphctx, log_ctx)))
1449 return ret;
1450
1451 return 0;
1452}
1453
1454int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
1455{
1456 int i, r = AVERROR(ENOSYS);
1457
1458 if (!graph)
1459 return r;
1460
1462 r = avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
1463 if (r != AVERROR(ENOSYS))
1464 return r;
1465 }
1466
1467 if (res_len && res)
1468 res[0] = 0;
1469
1470 for (i = 0; i < graph->nb_filters; i++) {
1471 AVFilterContext *filter = graph->filters[i];
1472 if (!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)) {
1473 r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
1474 if (r != AVERROR(ENOSYS)) {
1475 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1476 return r;
1477 }
1478 }
1479 }
1480
1481 return r;
1482}
1483
1484int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
1485{
1486 int i;
1487
1488 if(!graph)
1489 return 0;
1490
1491 for (i = 0; i < graph->nb_filters; i++) {
1492 AVFilterContext *filter = graph->filters[i];
1494 if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
1495 AVFilterCommand **queue = &ctxi->command_queue, *next;
1496 while (*queue && (*queue)->time <= ts)
1497 queue = &(*queue)->next;
1498 next = *queue;
1499 *queue = av_mallocz(sizeof(AVFilterCommand));
1500 if (!*queue)
1501 return AVERROR(ENOMEM);
1502
1503 (*queue)->command = av_strdup(command);
1504 (*queue)->arg = av_strdup(arg);
1505 (*queue)->time = ts;
1506 (*queue)->flags = flags;
1507 (*queue)->next = next;
1509 return 0;
1510 }
1511 }
1512
1513 return 0;
1514}
1515
1517 FilterLinkInternal *li, int index)
1518{
1519 FilterLinkInternal **links = graph->sink_links;
1520
1521 av_assert0(index >= 0);
1522
1523 while (index) {
1524 int parent = (index - 1) >> 1;
1525 if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
1526 break;
1527 links[index] = links[parent];
1528 links[index]->age_index = index;
1529 index = parent;
1530 }
1531 links[index] = li;
1532 li->age_index = index;
1533}
1534
1536 FilterLinkInternal *li, int index)
1537{
1538 FilterLinkInternal **links = graph->sink_links;
1539
1540 av_assert0(index >= 0);
1541
1542 while (1) {
1543 int child = 2 * index + 1;
1544 if (child >= graph->sink_links_count)
1545 break;
1546 if (child + 1 < graph->sink_links_count &&
1547 links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
1548 child++;
1549 if (li->l.current_pts_us < links[child]->l.current_pts_us)
1550 break;
1551 links[index] = links[child];
1552 links[index]->age_index = index;
1553 index = child;
1554 }
1555 links[index] = li;
1556 li->age_index = index;
1557}
1558
1560{
1561 FFFilterGraph *graphi = fffiltergraph(graph);
1562
1563 heap_bubble_up (graphi, li, li->age_index);
1564 heap_bubble_down(graphi, li, li->age_index);
1565}
1566
1568{
1569 FFFilterGraph *graphi = fffiltergraph(graph);
1570 FilterLinkInternal *oldesti = graphi->sink_links[0];
1571 AVFilterLink *oldest = &oldesti->l.pub;
1572 int64_t frame_count;
1573 int r;
1574
1575 while (graphi->sink_links_count) {
1576 oldesti = graphi->sink_links[0];
1577 oldest = &oldesti->l.pub;
1578 if (fffilter(oldest->dst->filter)->activate) {
1581 if (r != AVERROR_EOF)
1582 return r;
1583 } else {
1584 r = ff_request_frame(oldest);
1585 }
1586 if (r != AVERROR_EOF)
1587 break;
1588 av_log(oldest->dst, AV_LOG_DEBUG, "EOF on sink link %s:%s.\n",
1589 oldest->dst->name,
1590 oldest->dstpad->name);
1591 /* EOF: remove the link from the heap */
1592 if (oldesti->age_index < --graphi->sink_links_count)
1593 heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
1594 oldesti->age_index);
1595 oldesti->age_index = -1;
1596 }
1597 if (!graphi->sink_links_count)
1598 return AVERROR_EOF;
1599 av_assert1(!fffilter(oldest->dst->filter)->activate);
1600 av_assert1(oldesti->age_index >= 0);
1601 frame_count = oldesti->l.frame_count_out;
1602 while (frame_count == oldesti->l.frame_count_out) {
1603 r = ff_filter_graph_run_once(graph);
1605 r = 0;
1606 if (r == AVERROR(EAGAIN) &&
1607 !oldesti->frame_wanted_out && !oldesti->frame_blocked_in &&
1608 !oldesti->status_in)
1609 (void)ff_request_frame(oldest);
1610 else if (r < 0)
1611 return r;
1612 }
1613 return 0;
1614}
1615
1617{
1618 FFFilterContext *ctxi;
1619 unsigned i;
1620
1621 av_assert0(graph->nb_filters);
1622 ctxi = fffilterctx(graph->filters[0]);
1623 for (i = 1; i < graph->nb_filters; i++) {
1624 FFFilterContext *ctxi_other = fffilterctx(graph->filters[i]);
1625
1626 if (ctxi_other->ready > ctxi->ready)
1627 ctxi = ctxi_other;
1628 }
1629
1630 if (!ctxi->ready)
1631 return AVERROR(EAGAIN);
1632 return ff_filter_activate(&ctxi->p);
1633}
static const char *const format[]
Definition af_aiir.c:444
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
static const int8_t filt[NUMTAPS *2]
Definition af_earwax.c:40
#define A(x)
Definition vpx_arith.h:28
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define V
Definition avdct.c:32
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
Definition avfilter.c:701
int ff_filter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition avfilter.c:328
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition avfilter.c:483
int ff_filter_activate(AVFilterContext *filter)
Definition avfilter.c:1451
Main libavfilter public API header.
static FFFilterContext * fffilterctx(AVFilterContext *ctx)
static FFFilterGraph * fffiltergraph(AVFilterGraph *graph)
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format)
#define CH_SIDE_PAIR
static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
Check for the validity of graph.
static void heap_bubble_down(FFFilterGraph *graph, FilterLinkInternal *li, int index)
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
static int reduce_formats_on_filter(AVFilterContext *filter)
int ff_filter_graph_run_once(AVFilterGraph *graph)
Run one round of processing on a filter graph.
static void print_link_formats(void *log_ctx, int level, const AVFilterLink *l, const AVFilterFormatsMerger *mergers[], int nb_mergers)
static const uint64_t ch_subst[][2]
static void swap_channel_layouts_on_filter(AVFilterContext *filter)
static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
static void swap_sample_fmts(AVFilterGraph *graph)
static void heap_bubble_up(FFFilterGraph *graph, FilterLinkInternal *li, int index)
void ff_avfilter_graph_update_heap(AVFilterGraph *graph, FilterLinkInternal *li)
Update the position of a link in the age heap.
static int query_formats(AVFilterGraph *graph, void *log_ctx)
Perform one round of query_formats() and merging formats lists on the filter graph.
static int formats_declared(AVFilterContext *f)
static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
static void swap_samplerates_on_filter(AVFilterContext *filter)
void ff_graph_thread_free(FFFilterGraph *graph)
static void swap_channel_layouts(AVFilterGraph *graph)
#define CH_DIRECT_PAIR
static int filter_check_formats(AVFilterContext *ctx)
Check the validity of the formats / etc.
#define CH_WIDE_PAIR
#define MERGE(merger, link)
static void print_filter_formats(void *log_ctx, int level, const AVFilterContext *f)
static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
Configure all the links of graphctx.
static enum AVSampleFormat find_best_sample_fmt_of_2(enum AVSampleFormat dst_fmt1, enum AVSampleFormat dst_fmt2, enum AVSampleFormat src_fmt)
int ff_graph_thread_init(FFFilterGraph *graph)
#define CH_CENTER_PAIR
static int reduce_formats(AVFilterGraph *graph)
int ff_fmt_is_forced_full_range(enum AVPixelFormat fmt)
Returns true if a YUV pixel format is forced full range (i.e.
static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
Configure the formats of all the links in the graph.
static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
static int pick_formats(AVFilterGraph *graph)
#define OFFSET(x)
static int filter_query_formats(AVFilterContext *ctx)
#define CH_FRONT_PAIR
#define CH_BACK_PAIR
static void swap_sample_fmts_on_filter(AVFilterContext *filter)
static int pick_format(AVFilterLink *link, AVFilterLink *ref)
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...
static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
static void swap_samplerates(AVFilterGraph *graph)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:122
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:69
AVBPrint public header.
#define AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_AUTOMATIC
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
static const AVClass filtergraph_class
Definition bsfgraph.c:40
static const AVOption filtergraph_options[]
Definition bsfgraph.c:34
memory buffer sink API for audio and video
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define av_popcount64
Definition common.h:157
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define abs(x)
#define F(x)
static CheckasmConfig cfg
Definition checkasm.c:74
const AVFilterNegotiation * ff_filter_get_negotiation(const AVFilterLink *link)
Definition formats.c:462
int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample rates list.
Definition formats.c:1264
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:1170
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition formats.c:571
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition formats.c:807
int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid pixel formats list.
Definition formats.c:1254
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition formats.c:588
int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample formats list.
Definition formats.c:1259
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:1271
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:795
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition formats.c:1282
int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
Check that fmts is a valid channel layouts list.
Definition formats.c:1299
int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for alpha modes.
Definition formats.c:1287
#define FF_LAYOUT2COUNT(l)
Decode a channel count encoded as a channel layout.
Definition formats.h:108
#define KNOWN(l)
Definition formats.h:111
void ff_framequeue_global_init(FFFrameQueueGlobal *fqg)
Init a global structure.
Definition framequeue.c:31
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ 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:275
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition opt.h:334
#define AV_CH_BACK_CENTER
#define AV_CH_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY
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:135
#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:85
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition avfilter.c:960
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:282
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition avfilter.c:800
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition allfilters.c:654
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.
AVFilterContext * avfilter_graph_get_filter(AVFilterGraph *graph, const char *name)
Get a filter instance identified by instance name from graph.
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
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:610
void avfilter_graph_free(AVFilterGraph **graphp)
Free a graph, destroy its links, and set *graph to NULL.
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
Definition avfilter.h:270
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.
int avfilter_graph_request_oldest(AVFilterGraph *graph)
Request a frame on the oldest sink link.
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.
#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:441
#define AVFILTER_CMD_FLAG_FAST
Only execute command when its fast (like a video out that supports contrast adjustment in hw)
Definition avfilter.h:442
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
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.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
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...
@ AV_CHAN_LOW_FREQUENCY
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:235
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:227
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
int av_log_get_level(void)
Get the current log level.
Definition log.c:471
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:217
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
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition samplefmt.c:114
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:108
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
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
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
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition samplefmt.h:59
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition opt.c:2025
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1754
int index
Definition gxfenc.c:90
int a
misc image utilities
#define r
Definition input.c:42
#define b
Definition input.c:43
const char * arg
Definition jacosubdec.c:65
#define FFERROR_BUFFERSRC_EMPTY
Definition filters.h:35
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition filters.h:230
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition filters.h:231
static const FFFilter * fffilter(const AVFilter *f)
Definition filters.h:464
#define FF_FIELD_AT(type, off, obj)
Access a field in a structure by its offset.
Definition internal.h:79
const char * desc
Definition libsvtav1.c:83
@ AV_CLASS_CATEGORY_FILTER
Definition log.h:36
#define FFSWAP(type, a, b)
Definition macros.h:52
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
unsigned bps
Definition movenc.c:2074
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
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:3380
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:3739
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
Definition pixdesc.h:163
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition pixdesc.h:120
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:817
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ 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_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
@ 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_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
@ 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
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:709
const char * name
Definition qsvenc.c:142
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
An AVChannelLayout holds information about the channel layout of audio data.
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
union AVChannelLayout::@162063043056170047076125117143030261346263330336 u
Details about which channels are present in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
A list of supported channel layouts.
Definition formats.h:85
char all_layouts
accept any known channel layout
Definition formats.h:88
char all_counts
accept any channel layout or count
Definition formats.h:89
AVChannelLayout * channel_layouts
list of channel layouts
Definition formats.h:86
int nb_channel_layouts
number of channel layouts
Definition formats.h:87
unsigned refcount
number of references to this list
Definition formats.h:91
struct AVFilterCommand * next
double time
time expressed in seconds
An instance of a filter.
Definition avfilter.h:273
char * name
name of this filter instance
Definition avfilter.h:278
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:281
const AVFilter * filter
the AVFilter of which this is an instance
Definition avfilter.h:276
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
Lists of formats / etc.
Definition avfilter.h:120
AVFilterFormats * color_spaces
Lists of supported YUV color metadata, only for YUV video.
Definition avfilter.h:140
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition avfilter.h:125
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition avfilter.h:135
AVFilterFormats * alpha_modes
List of supported alpha modes, only for video with an alpha channel.
Definition avfilter.h:146
AVFilterFormats * color_ranges
AVColorRange.
Definition avfilter.h:141
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition avfilter.h:130
unsigned conversion_opts_offset
Definition formats.h:569
int(* merge)(void *a, void *b)
Definition formats.h:565
const char * name
Definition formats.h:563
int(* can_merge)(const void *a, const void *b)
Definition formats.h:566
void(* print_list)(struct AVBPrint *bp, const void *fmts)
Definition formats.h:567
const char * conversion_filter
Definition formats.h:568
A list of supported formats for one end of a filter link.
Definition formats.h:64
int * formats
list of media formats
Definition formats.h:66
unsigned refcount
number of references to this list
Definition formats.h:68
unsigned nb_formats
number of formats
Definition formats.h:65
unsigned nb_filters
Definition avfilter.h:564
AVFilterContext ** filters
Definition avfilter.h:563
unsigned max_buffered_frames
Sets the maximum number of buffered frames in the filtergraph combined.
Definition avfilter.h:618
int thread_type
Type of multithreading allowed for filters in this graph.
Definition avfilter.h:580
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:608
int nb_threads
Maximum number of threads used by filters in this graph.
Definition avfilter.h:587
const AVClass * av_class
Definition avfilter.h:562
Callbacks and properties to describe the steps of a format negotiation.
Definition formats.h:657
unsigned nb_mergers
Definition formats.h:658
const AVFilterFormatsMerger * mergers
Definition formats.h:659
A filter pad used for either input or output.
Definition filters.h:40
enum AVMediaType type
AVFilterPad type.
Definition filters.h:51
const char * name
Pad name.
Definition filters.h:46
Filter definition.
Definition avfilter.h:215
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
int age_index
Index in the age array.
struct AVFilterCommand * command_queue
AVFilterContext p
The public AVFilterContext.
unsigned ready
Ready status of the filter.
avfilter_execute_func * thread_execute
AVFilterGraph p
The public AVFilterGraph.
FFFrameQueueGlobal frame_queues
struct FilterLinkInternal ** sink_links
unsigned disable_auto_convert
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition filters.h:461
size_t max_queued
Maximum number of allowed frames in the queues combined.
Definition framequeue.h:49
int frame_wanted_out
True if a frame is currently wanted on the output of this filter.
int age_index
Index in the age array.
int status_in
Link input status.
int frame_blocked_in
If set, the source filter can not generate a frame as is.
uint8_t level
Definition svq3.c:208
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
static int ref[MAX_W *MAX_W]
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)