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
49static const AVOption filtergraph_options[] = {
50 { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
51 { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, F|V|A, .unit = "thread_type" },
52 { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = F|V|A, .unit = "thread_type" },
53 { "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT,
54 { .i64 = 0 }, 0, INT_MAX, F|V|A, .unit = "threads"},
55 {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"},
56 {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
57 AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V },
58 {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
59 AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|A },
60#if FF_API_MAX_BUFFERED_FRAMES
61 {"max_buffered_frames" , "maximum number of buffered frames allowed", OFFSET(max_buffered_frames),
62 AV_OPT_TYPE_UINT, {.i64 = 0}, 0, UINT_MAX, F|V|A|AV_OPT_FLAG_DEPRECATED },
63#endif
64 { NULL },
65};
67
68static const AVClass filtergraph_class = {
69 .class_name = "AVFilterGraph",
70 .item_name = av_default_item_name,
71 .version = LIBAVUTIL_VERSION_INT,
72 .option = filtergraph_options,
73 .category = AV_CLASS_CATEGORY_FILTER,
74};
75
76#if !HAVE_THREADS
80
82{
83 graph->p.thread_type = 0;
84 graph->p.nb_threads = 1;
85 return 0;
86}
87#endif
88
90{
91 FFFilterGraph *graph = av_mallocz(sizeof(*graph));
93
94 if (!graph)
95 return NULL;
96
97 ret = &graph->p;
98 ret->av_class = &filtergraph_class;
100 for (int i = 0; i < FF_ARRAY_ELEMS(graph->frame_queues); i++)
102
103 return ret;
104}
105
107{
108 int i, j;
109 for (i = 0; i < graph->nb_filters; i++) {
110 if (graph->filters[i] == filter) {
112 graph->filters[graph->nb_filters - 1]);
113 graph->nb_filters--;
114 filter->graph = NULL;
115 for (j = 0; j<filter->nb_outputs; j++)
116 if (filter->outputs[j])
117 ff_filter_link(filter->outputs[j])->graph = NULL;
118
119 return;
120 }
121 }
122}
123
125{
126 AVFilterGraph *graph = *graphp;
127 FFFilterGraph *graphi = fffiltergraph(graph);
128
129 if (!graph)
130 return;
131
132 while (graph->nb_filters)
133 avfilter_free(graph->filters[0]);
134
135 ff_graph_thread_free(graphi);
136
137 av_freep(&graphi->sink_links);
138
139 av_opt_free(graph);
140
141 av_freep(&graph->filters);
142 av_freep(graphp);
143}
144
146 const char *name, const char *args, void *opaque,
147 AVFilterGraph *graph_ctx)
148{
149 int ret;
150
151 *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
152 if (!*filt_ctx)
153 return AVERROR(ENOMEM);
154
155 ret = avfilter_init_str(*filt_ctx, args);
156 if (ret < 0)
157 goto fail;
158
159 return 0;
160
161fail:
162 avfilter_free(*filt_ctx);
163 *filt_ctx = NULL;
164 return ret;
165}
166
171
173 enum AVMediaType type,
174 unsigned frames)
175{
176 FFFilterGraph *graphi = fffiltergraph(graph);
178 return AVERROR(EINVAL);
179
180 FFFrameQueueGlobal *fqg = &graphi->frame_queues[type];
181 size_t max_queued = frames ? frames : SIZE_MAX;
182 if (fqg->queued > max_queued)
183 return AVERROR(EINVAL);
184 fqg->max_queued = max_queued;
185 graphi->max_queued_set[type] = 1;
186 return 0;
187}
188
190 const AVFilter *filter,
191 const char *name)
192{
194 FFFilterGraph *graphi = fffiltergraph(graph);
195
196 if (graph->thread_type && !graphi->thread_execute) {
197 if (graph->execute) {
198 graphi->thread_execute = graph->execute;
199 } else {
200 int ret = ff_graph_thread_init(graphi);
201 if (ret < 0) {
202 av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
203 return NULL;
204 }
205 }
206 }
207
208 filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
209 if (!filters)
210 return NULL;
211 graph->filters = filters;
212
214 if (!s)
215 return NULL;
216
217 graph->filters[graph->nb_filters++] = s;
218
219 s->graph = graph;
220
221 return s;
222}
223
224/**
225 * Check for the validity of graph.
226 *
227 * A graph is considered valid if all its input and output pads are
228 * connected.
229 *
230 * @return >= 0 in case of success, a negative value otherwise
231 */
232static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
233{
235 int i, j;
236
237 for (i = 0; i < graph->nb_filters; i++) {
238 const AVFilterPad *pad;
239 filt = graph->filters[i];
240
241 for (j = 0; j < filt->nb_inputs; j++) {
242 if (!filt->inputs[j] || !filt->inputs[j]->src) {
243 pad = &filt->input_pads[j];
244 av_log(log_ctx, AV_LOG_ERROR,
245 "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
246 pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
247 return AVERROR(EINVAL);
248 }
249 }
250
251 for (j = 0; j < filt->nb_outputs; j++) {
252 if (!filt->outputs[j] || !filt->outputs[j]->dst) {
253 pad = &filt->output_pads[j];
254 av_log(log_ctx, AV_LOG_ERROR,
255 "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
256 pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
257 return AVERROR(EINVAL);
258 }
259 }
260 }
261
262 return 0;
263}
264
265/**
266 * Configure all the links of graphctx.
267 *
268 * @return >= 0 in case of success, a negative value otherwise
269 */
270static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
271{
273 int i, ret;
274
275 for (i = 0; i < graph->nb_filters; i++) {
276 filt = graph->filters[i];
277
278 if (!filt->nb_outputs) {
280 return ret;
281 }
282 }
283
284 return 0;
285}
286
287static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
288{
290 AVFilterLink *l;
291 unsigned i, j;
292 int ret;
293
294 for (i = 0; i < graph->nb_filters; i++) {
295 f = graph->filters[i];
296 for (j = 0; j < f->nb_outputs; j++) {
297 l = f->outputs[j];
298 if (l->type == AVMEDIA_TYPE_VIDEO) {
299 ret = av_image_check_size2(l->w, l->h, INT64_MAX, l->format, 0, f);
300 if (ret < 0)
301 return ret;
302 }
303 }
304 }
305 return 0;
306}
307
309{
310 int i;
311
312 for (i = 0; i < graph->nb_filters; i++)
313 if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
314 return graph->filters[i];
315
316 return NULL;
317}
318
320{
321 int ret;
322
323 switch (link->type) {
324
326 if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 ||
327 (ret = ff_formats_check_color_spaces(log, cfg->color_spaces)) < 0 ||
328 (ret = ff_formats_check_color_ranges(log, cfg->color_ranges)) < 0 ||
329 (ret = ff_formats_check_alpha_modes(log, cfg->alpha_modes)) < 0 ||
330 (ret = ff_formats_check_chroma_locations(log, cfg->chroma_locations)) < 0)
331 return ret;
332 break;
333
335 if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
336 (ret = ff_formats_check_sample_rates(log, cfg->samplerates)) < 0 ||
337 (ret = ff_formats_check_channel_layouts(log, cfg->channel_layouts)) < 0)
338 return ret;
339 break;
340
341 default:
342 av_assert0(!"reached");
343 }
344 return 0;
345}
346
347/**
348 * Check the validity of the formats / etc. lists set by query_formats().
349 *
350 * In particular, check they do not contain any redundant element.
351 */
353{
354 unsigned i;
355 int ret;
356
357 for (i = 0; i < ctx->nb_inputs; i++) {
358 ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
359 if (ret < 0)
360 return ret;
361 }
362 for (i = 0; i < ctx->nb_outputs; i++) {
363 ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
364 if (ret < 0)
365 return ret;
366 }
367 return 0;
368}
369
371{
372 const FFFilter *const filter = fffilter(ctx->filter);
373 int ret;
374
375 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
376 if ((ret = filter->formats.query_func(ctx)) < 0) {
377 if (ret != AVERROR(EAGAIN))
378 av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
379 ctx->name, av_err2str(ret));
380 return ret;
381 }
382 } else if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
383 AVFilterFormatsConfig *cfg_in_stack[64], *cfg_out_stack[64];
384 AVFilterFormatsConfig **cfg_in_dyn = NULL, **cfg_out_dyn = NULL;
385 AVFilterFormatsConfig **cfg_in, **cfg_out;
386
387 if (ctx->nb_inputs > FF_ARRAY_ELEMS(cfg_in_stack)) {
388 cfg_in_dyn = av_malloc_array(ctx->nb_inputs, sizeof(*cfg_in_dyn));
389 if (!cfg_in_dyn)
390 return AVERROR(ENOMEM);
391 cfg_in = cfg_in_dyn;
392 } else
393 cfg_in = ctx->nb_inputs ? cfg_in_stack : NULL;
394
395 for (unsigned i = 0; i < ctx->nb_inputs; i++) {
396 AVFilterLink *l = ctx->inputs[i];
397 cfg_in[i] = &l->outcfg;
398 }
399
400 if (ctx->nb_outputs > FF_ARRAY_ELEMS(cfg_out_stack)) {
401 cfg_out_dyn = av_malloc_array(ctx->nb_outputs, sizeof(*cfg_out_dyn));
402 if (!cfg_out_dyn) {
403 av_freep(&cfg_in_dyn);
404 return AVERROR(ENOMEM);
405 }
406 cfg_out = cfg_out_dyn;
407 } else
408 cfg_out = ctx->nb_outputs ? cfg_out_stack : NULL;
409
410 for (unsigned i = 0; i < ctx->nb_outputs; i++) {
411 AVFilterLink *l = ctx->outputs[i];
412 cfg_out[i] = &l->incfg;
413 }
414
415 ret = filter->formats.query_func2(ctx, cfg_in, cfg_out);
416 av_freep(&cfg_in_dyn);
417 av_freep(&cfg_out_dyn);
418 if (ret < 0) {
419 if (ret != AVERROR(EAGAIN))
420 av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
421 ctx->name, av_err2str(ret));
422 return ret;
423 }
424 }
425
426 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC ||
427 filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
429 if (ret < 0)
430 return ret;
431 }
432
434}
435
437{
438 int i;
439
440 for (i = 0; i < f->nb_inputs; i++) {
441 if (!f->inputs[i]->outcfg.formats)
442 return 0;
443 if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO &&
444 !(f->inputs[i]->outcfg.color_ranges &&
445 f->inputs[i]->outcfg.color_spaces &&
446 f->inputs[i]->outcfg.alpha_modes &&
447 f->inputs[i]->outcfg.chroma_locations))
448 return 0;
449 if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO &&
450 !(f->inputs[i]->outcfg.samplerates &&
451 f->inputs[i]->outcfg.channel_layouts))
452 return 0;
453 }
454 for (i = 0; i < f->nb_outputs; i++) {
455 if (!f->outputs[i]->incfg.formats)
456 return 0;
457 if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO &&
458 !(f->outputs[i]->incfg.color_ranges &&
459 f->outputs[i]->incfg.color_spaces &&
460 f->outputs[i]->incfg.alpha_modes &&
461 f->outputs[i]->incfg.chroma_locations))
462 return 0;
463 if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO &&
464 !(f->outputs[i]->incfg.samplerates &&
465 f->outputs[i]->incfg.channel_layouts))
466 return 0;
467 }
468 return 1;
469}
470
471static void print_link_formats(void *log_ctx, int level, const AVFilterLink *l,
472 const AVFilterFormatsMerger *mergers[],
473 int nb_mergers)
474{
475 if (av_log_get_level() < level)
476 return;
477
478 AVBPrint bp;
480
481 av_log(log_ctx, level, "Link '%s.%s' -> '%s.%s':\n",
482 l->src->name, l->srcpad->name, l->dst->name, l->dstpad->name);
483
484 for (unsigned i = 0; i < nb_mergers; i++) {
485 const AVFilterFormatsMerger *m = mergers[i];
486 av_log(log_ctx, level, " %s:\n", m->name);
487 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->incfg));
488 if (av_bprint_is_complete(&bp))
489 av_log(log_ctx, level, " src: %s\n", bp.str);
490 av_bprint_clear(&bp);
491
492 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->outcfg));
493 if (av_bprint_is_complete(&bp))
494 av_log(log_ctx, level, " dst: %s\n", bp.str);
495 av_bprint_clear(&bp);
496 }
497
499}
500
501static void print_filter_formats(void *log_ctx, int level, const AVFilterContext *f)
502{
503 if (av_log_get_level() < level)
504 return;
505
506 AVBPrint bp;
508
509 av_log(log_ctx, level, "Filter '%s' formats:\n", f->name);
510 for (int i = 0; i < f->nb_inputs; i++) {
511 const AVFilterLink *in = f->inputs[i];
513 av_log(log_ctx, level, " in[%d] '%s':\n", i, f->input_pads[i].name);
514
515 for (unsigned i = 0; i < neg->nb_mergers; i++) {
516 const AVFilterFormatsMerger *m = &neg->mergers[i];
517 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, in->outcfg));
518 if (av_bprint_is_complete(&bp))
519 av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
520 av_bprint_clear(&bp);
521 }
522 }
523
524 for (int i = 0; i < f->nb_outputs; i++) {
525 const AVFilterLink *out = f->outputs[i];
527 av_log(log_ctx, level, " out[%d] '%s':\n", i, f->output_pads[i].name);
528
529 for (unsigned i = 0; i < neg->nb_mergers; i++) {
530 const AVFilterFormatsMerger *m = &neg->mergers[i];
531 m->print_list(&bp, FF_FIELD_AT(void *, m->offset, out->incfg));
532 if (av_bprint_is_complete(&bp))
533 av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
534 av_bprint_clear(&bp);
535 }
536 }
537
539}
540
541/**
542 * Perform one round of query_formats() and merging formats lists on the
543 * filter graph.
544 * @return >=0 if all links formats lists could be queried and merged;
545 * AVERROR(EAGAIN) some progress was made in the queries or merging
546 * and a later call may succeed;
547 * AVERROR(EIO) (may be changed) plus a log message if no progress
548 * was made and the negotiation is stuck;
549 * a negative error code if some other error happened
550 */
551static int query_formats(AVFilterGraph *graph, void *log_ctx)
552{
553 int i, j, k, ret;
554 int converter_count = 0;
555 int count_queried = 0; /* successful calls to query_formats() */
556 int count_merged = 0; /* successful merge of formats lists */
557 int count_already_merged = 0; /* lists already merged */
558 int count_delayed = 0; /* lists that need to be merged later */
559
560 for (i = 0; i < graph->nb_filters; i++) {
561 AVFilterContext *f = graph->filters[i];
562 if (formats_declared(f))
563 continue;
565 if (ret < 0 && ret != AVERROR(EAGAIN))
566 return ret;
567 /* note: EAGAIN could indicate a partial success, not counted yet */
568 if (ret >= 0) {
570 count_queried++;
571 }
572 }
573
574 /* go through and merge as many format lists as possible */
575retry:
576 for (i = 0; i < graph->nb_filters; i++) {
577 AVFilterContext *filter = graph->filters[i];
578
579 for (j = 0; j < filter->nb_inputs; j++) {
580 AVFilterLink *link = filter->inputs[j];
581 const AVFilterNegotiation *neg;
582 AVFilterContext *conv[4];
583 const AVFilterFormatsMerger *mergers[4]; /* triggered mergers */
584 const char *conv_filters[4], *conv_opts[4] = {0};
585 unsigned neg_step, num_conv = 0, num_mergers = 0;
586
587 if (!link)
588 continue;
589
590 neg = ff_filter_get_negotiation(link);
591 av_assert0(neg);
592 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
593 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
594 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
595 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
596 if (a && b && a != b && !m->can_merge(a, b)) {
597 for (k = 0; k < num_conv; k++) {
598 if (!strcmp(conv_filters[k], m->conversion_filter))
599 break;
600 }
601 if (k == num_conv) {
602 av_assert1(num_conv < FF_ARRAY_ELEMS(conv_filters));
603 conv_filters[num_conv] = m->conversion_filter;
605 conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
606 num_conv++;
607 }
608 av_assert1(num_mergers < FF_ARRAY_ELEMS(mergers));
609 mergers[num_mergers++] = m;
610 }
611 }
612 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
613 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
614 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
615 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
616 if (!(a && b)) {
617 count_delayed++;
618 } else if (a == b) {
619 count_already_merged++;
620 } else if (!num_conv) {
621 count_merged++;
622 ret = m->merge(a, b);
623 if (ret < 0)
624 return ret;
625 if (!ret) {
626 mergers[num_mergers++] = m;
627 conv_filters[num_conv] = m->conversion_filter;
629 conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
630 num_conv++;
631 }
632 }
633 }
634
635 /**
636 * Couldn't merge format lists; auto-insert conversion filters
637 * in reverse order to keep the order consistent with the list
638 * of mergers, since they are prepended onto the existing link
639 */
640 for (k = num_conv - 1; k >= 0; k--) {
641 const AVFilter *filter;
642 char inst_name[30];
643
644 if (fffiltergraph(graph)->disable_auto_convert) {
645 av_log(log_ctx, AV_LOG_ERROR,
646 "The filters '%s' and '%s' do not have a common format "
647 "and automatic conversion is disabled.\n",
648 link->src->name, link->dst->name);
649 print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
650 return AVERROR(EINVAL);
651 }
652
653 if (!(filter = avfilter_get_by_name(conv_filters[k]))) {
654 av_log(log_ctx, AV_LOG_ERROR,
655 "'%s' filter not present, cannot convert formats.\n",
656 conv_filters[k]);
657 print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
658 return AVERROR(EINVAL);
659 }
660 snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
661 conv_filters[k], converter_count++);
662 ret = avfilter_graph_create_filter(&conv[k], filter, inst_name,
663 conv_opts[k], NULL, graph);
664 if (ret < 0)
665 return ret;
666 if ((ret = avfilter_insert_filter(link, conv[k], 0, 0)) < 0)
667 return ret;
668
669 if ((ret = filter_query_formats(conv[k])) < 0)
670 return ret;
671 }
672
673 /* preemptively settle formats of auto filters */
674 for (k = 0; k < num_conv; k++) {
675 AVFilterLink *inlink = conv[k]->inputs[0];
676 AVFilterLink *outlink = conv[k]->outputs[0];
677 av_assert0( inlink->incfg.formats->refcount > 0);
678 av_assert0( inlink->outcfg.formats->refcount > 0);
679 av_assert0(outlink->incfg.formats->refcount > 0);
680 av_assert0(outlink->outcfg.formats->refcount > 0);
681 if (outlink->type == AVMEDIA_TYPE_VIDEO) {
682 av_assert0( inlink-> incfg.color_spaces->refcount > 0);
683 av_assert0( inlink->outcfg.color_spaces->refcount > 0);
684 av_assert0(outlink-> incfg.color_spaces->refcount > 0);
685 av_assert0(outlink->outcfg.color_spaces->refcount > 0);
686 av_assert0( inlink-> incfg.color_ranges->refcount > 0);
687 av_assert0( inlink->outcfg.color_ranges->refcount > 0);
688 av_assert0(outlink-> incfg.color_ranges->refcount > 0);
689 av_assert0(outlink->outcfg.color_ranges->refcount > 0);
690 av_assert0( inlink-> incfg.alpha_modes->refcount > 0);
691 av_assert0( inlink->outcfg.alpha_modes->refcount > 0);
692 av_assert0(outlink-> incfg.alpha_modes->refcount > 0);
693 av_assert0(outlink->outcfg.alpha_modes->refcount > 0);
694 av_assert0( inlink-> incfg.chroma_locations->refcount > 0);
696 av_assert0(outlink-> incfg.chroma_locations->refcount > 0);
698 } else if (outlink->type == AVMEDIA_TYPE_AUDIO) {
699 av_assert0( inlink-> incfg.samplerates->refcount > 0);
700 av_assert0( inlink->outcfg.samplerates->refcount > 0);
701 av_assert0(outlink-> incfg.samplerates->refcount > 0);
702 av_assert0(outlink->outcfg.samplerates->refcount > 0);
703 av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
705 av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
707 }
708
709#define MERGE(merger, link) \
710 ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
711 FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
712
713 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
714 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
715 if (strcmp(m->conversion_filter, conv_filters[k]))
716 continue;
717 if ((ret = MERGE(m, inlink)) <= 0 ||
718 (ret = MERGE(m, outlink)) <= 0) {
719 if (ret < 0)
720 return ret;
721 av_log(log_ctx, AV_LOG_ERROR,
722 "Impossible to convert between the formats supported by the filter "
723 "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
724 print_link_formats(log_ctx, AV_LOG_ERROR, inlink, &m, 1);
725 print_link_formats(log_ctx, AV_LOG_ERROR, outlink, &m, 1);
726 return AVERROR(ENOSYS);
727 } else {
728 count_merged += 2;
729 }
730 }
731 }
732
733 /* if there is an auto filter, we may need another round to fully
734 * settle formats due to possible cross-incompatibilities between
735 * the auto filters themselves, or between the auto filters and
736 * a different attribute of the filter they are modifying */
737 if (num_conv)
738 goto retry;
739 }
740 }
741
742 av_log(graph, AV_LOG_DEBUG, "query_formats: "
743 "%d queried, %d merged, %d already done, %d delayed\n",
744 count_queried, count_merged, count_already_merged, count_delayed);
745 if (count_delayed) {
746 AVBPrint bp;
747
748 /* if count_queried > 0, one filter at least did set its formats,
749 that will give additional information to its neighbour;
750 if count_merged > 0, one pair of formats lists at least was merged,
751 that will give additional information to all connected filters;
752 in both cases, progress was made and a new round must be done */
753 if (count_queried || count_merged)
754 return AVERROR(EAGAIN);
756 for (i = 0; i < graph->nb_filters; i++)
757 if (!formats_declared(graph->filters[i]))
758 av_bprintf(&bp, "%s%s", bp.len ? ", " : "",
759 graph->filters[i]->name);
760 av_log(graph, AV_LOG_ERROR,
761 "The following filters could not choose their formats: %s\n"
762 "Consider inserting the (a)format filter near their input or "
763 "output.\n", bp.str);
764 return AVERROR(EIO);
765 }
766 return 0;
767}
768
769static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
770{
771 int score = 0;
772
773 if (av_sample_fmt_is_planar(dst_fmt) != av_sample_fmt_is_planar(src_fmt))
774 score ++;
775
776 if (av_get_bytes_per_sample(dst_fmt) < av_get_bytes_per_sample(src_fmt)) {
777 score += 100 * (av_get_bytes_per_sample(src_fmt) - av_get_bytes_per_sample(dst_fmt));
778 }else
779 score += 10 * (av_get_bytes_per_sample(dst_fmt) - av_get_bytes_per_sample(src_fmt));
780
783 score += 20;
784
787 score += 2;
788
789 return score;
790}
791
793 enum AVSampleFormat src_fmt)
794{
795 int score1, score2;
796
797 score1 = get_fmt_score(dst_fmt1, src_fmt);
798 score2 = get_fmt_score(dst_fmt2, src_fmt);
799
800 return score1 < score2 ? dst_fmt1 : dst_fmt2;
801}
802
804{
806 if (!desc)
807 return 0;
808 if (desc->nb_components < 3)
809 return 0; /* Grayscale is explicitly full-range in swscale */
811 return !(desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL |
813}
814
815
817{
818 switch (fmt) {
824 return 1;
825 default:
826 return 0;
827 }
828}
829
831{
832 if (!link || !link->incfg.formats)
833 return 0;
834
835 if (link->type == AVMEDIA_TYPE_VIDEO) {
836 if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
837 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
838 int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
840 int i;
841 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
842 enum AVPixelFormat p = link->incfg.formats->formats[i];
843 best= av_find_best_pix_fmt_of_2(best, p, ref->format, has_alpha, NULL);
844 }
845 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s alpha:%d\n",
847 av_get_pix_fmt_name(ref->format), has_alpha);
848 link->incfg.formats->formats[0] = best;
849 }
850 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
851 if(ref && ref->type == AVMEDIA_TYPE_AUDIO){
853 int i;
854 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
855 enum AVSampleFormat p = link->incfg.formats->formats[i];
856 best = find_best_sample_fmt_of_2(best, p, ref->format);
857 }
858 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s\n",
860 av_get_sample_fmt_name(ref->format));
861 link->incfg.formats->formats[0] = best;
862 }
863 }
864
865 link->incfg.formats->nb_formats = 1;
866 link->format = link->incfg.formats->formats[0];
867
868 if (link->type == AVMEDIA_TYPE_VIDEO) {
869 enum AVPixelFormat swfmt = link->format;
871 // FIXME: this is a hack - we'd like to use the sw_format of
872 // link->hw_frames_ctx here, but it is not yet available.
873 // To make this work properly we will need to either reorder
874 // things so that it is available here or somehow negotiate
875 // sw_format separately.
876 swfmt = AV_PIX_FMT_YUV420P;
877 }
878
880 if (!ff_fmt_is_regular_yuv(swfmt)) {
881 /* These fields are explicitly documented as affecting YUV only,
882 * so set them to sane values for other formats. */
883 if (desc->flags & AV_PIX_FMT_FLAG_FLOAT)
885 else
889 } else {
891 }
892 } else {
893 if (!link->incfg.color_spaces->nb_formats) {
894 av_log(link->src, AV_LOG_ERROR, "Cannot select color space for"
895 " the link between filters %s and %s.\n", link->src->name,
896 link->dst->name);
897 return AVERROR(EINVAL);
898 }
899 link->incfg.color_spaces->nb_formats = 1;
900 link->colorspace = link->incfg.color_spaces->formats[0];
901
902 if (ff_fmt_is_forced_full_range(swfmt)) {
904 } else {
905 if (!link->incfg.color_ranges->nb_formats) {
906 av_log(link->src, AV_LOG_ERROR, "Cannot select color range for"
907 " the link between filters %s and %s.\n", link->src->name,
908 link->dst->name);
909 return AVERROR(EINVAL);
910 }
911 link->incfg.color_ranges->nb_formats = 1;
912 link->color_range = link->incfg.color_ranges->formats[0];
913 }
914 }
915
916 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) {
917 if (!link->incfg.alpha_modes->nb_formats) {
918 av_log(link->src, AV_LOG_ERROR, "Cannot select alpha mode for"
919 " the link between filters %s and %s.\n", link->src->name,
920 link->dst->name);
921 return AVERROR(EINVAL);
922 }
923 link->incfg.alpha_modes->nb_formats = 1;
924 link->alpha_mode = link->incfg.alpha_modes->formats[0];
925 } else {
927 }
928
929 if (desc->log2_chroma_w || desc->log2_chroma_h) {
930 if (!link->incfg.chroma_locations->nb_formats) {
931 av_log(link->src, AV_LOG_ERROR, "Cannot select chroma location"
932 " for the link between filters %s and %s.\n", link->src->name,
933 link->dst->name);
934 return AVERROR(EINVAL);
935 }
938 } else {
939 /* Chroma location is meaningless without subsampled chroma. */
941 }
942 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
943 int ret;
944
945 if (!link->incfg.samplerates->nb_formats) {
946 av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
947 " the link between filters %s and %s.\n", link->src->name,
948 link->dst->name);
949 return AVERROR(EINVAL);
950 }
951 link->incfg.samplerates->nb_formats = 1;
952 link->sample_rate = link->incfg.samplerates->formats[0];
953
954 if (link->incfg.channel_layouts->all_layouts) {
955 av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
956 " the link between filters %s and %s.\n", link->src->name,
957 link->dst->name);
958 if (!link->incfg.channel_layouts->all_counts)
959 av_log(link->src, AV_LOG_ERROR, "Unknown channel layouts not "
960 "supported, try specifying a channel layout using "
961 "'aformat=channel_layouts=something'.\n");
962 return AVERROR(EINVAL);
963 }
966 if (ret < 0)
967 return ret;
968 }
969
984
985 return 0;
986}
987
988#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
989do { \
990 for (i = 0; i < filter->nb_inputs; i++) { \
991 AVFilterLink *link = filter->inputs[i]; \
992 fmt_type fmt; \
993 \
994 if (!link->outcfg.list || link->outcfg.list->nb != 1) \
995 continue; \
996 fmt = link->outcfg.list->var[0]; \
997 \
998 for (j = 0; j < filter->nb_outputs; j++) { \
999 AVFilterLink *out_link = filter->outputs[j]; \
1000 list_type *fmts; \
1001 \
1002 if (link->type != out_link->type || \
1003 out_link->incfg.list->nb == 1) \
1004 continue; \
1005 fmts = out_link->incfg.list; \
1006 \
1007 if (!out_link->incfg.list->nb) { \
1008 if ((ret = add_format(&out_link->incfg.list, fmt)) < 0)\
1009 return ret; \
1010 ret = 1; \
1011 break; \
1012 } \
1013 \
1014 for (k = 0; k < out_link->incfg.list->nb; k++) \
1015 if (fmts->var[k] == fmt) { \
1016 fmts->var[0] = fmt; \
1017 fmts->nb = 1; \
1018 ret = 1; \
1019 break; \
1020 } \
1021 } \
1022 } \
1023} while (0)
1024
1026{
1027 int i, j, k, ret = 0;
1028
1030 nb_formats, ff_add_format);
1031 REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
1032 nb_formats, ff_add_format);
1033 REDUCE_FORMATS(int, AVFilterFormats, color_spaces, formats,
1034 nb_formats, ff_add_format);
1035 REDUCE_FORMATS(int, AVFilterFormats, color_ranges, formats,
1036 nb_formats, ff_add_format);
1037 REDUCE_FORMATS(int, AVFilterFormats, alpha_modes, formats,
1038 nb_formats, ff_add_format);
1039 REDUCE_FORMATS(int, AVFilterFormats, chroma_locations, formats,
1040 nb_formats, ff_add_format);
1041
1042 /* reduce channel layouts */
1043 for (i = 0; i < filter->nb_inputs; i++) {
1044 AVFilterLink *inlink = filter->inputs[i];
1045 const AVChannelLayout *fmt;
1046
1047 if (!inlink->outcfg.channel_layouts ||
1049 continue;
1050 fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
1051
1052 for (j = 0; j < filter->nb_outputs; j++) {
1053 AVFilterLink *outlink = filter->outputs[j];
1055
1056 fmts = outlink->incfg.channel_layouts;
1057 if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
1058 continue;
1059
1060 if (fmts->all_layouts &&
1061 (KNOWN(fmt) || fmts->all_counts)) {
1062 /* Turn the infinite list into a singleton */
1063 fmts->all_layouts = fmts->all_counts = 0;
1065 if (ret < 0)
1066 return ret;
1067 ret = 1;
1068 break;
1069 }
1070
1071 for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
1072 if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
1073 ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
1074 if (ret < 0)
1075 return ret;
1076 fmts->nb_channel_layouts = 1;
1077 ret = 1;
1078 break;
1079 }
1080 }
1081 }
1082 }
1083
1084 return ret;
1085}
1086
1088{
1089 int i, reduced, ret;
1090
1091 do {
1092 reduced = 0;
1093
1094 for (i = 0; i < graph->nb_filters; i++) {
1095 if ((ret = reduce_formats_on_filter(graph->filters[i])) < 0)
1096 return ret;
1097 reduced |= ret;
1098 }
1099 } while (reduced);
1100
1101 return 0;
1102}
1103
1105{
1106 AVFilterLink *link = NULL;
1107 int sample_rate;
1108 int i, j;
1109
1110 for (i = 0; i < filter->nb_inputs; i++) {
1111 link = filter->inputs[i];
1112
1113 if (link->type == AVMEDIA_TYPE_AUDIO &&
1114 link->outcfg.samplerates->nb_formats== 1)
1115 break;
1116 }
1117 if (i == filter->nb_inputs)
1118 return;
1119
1120 sample_rate = link->outcfg.samplerates->formats[0];
1121
1122 for (i = 0; i < filter->nb_outputs; i++) {
1123 AVFilterLink *outlink = filter->outputs[i];
1124 int best_idx, best_diff = INT_MAX;
1125
1126 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1127 outlink->incfg.samplerates->nb_formats < 2)
1128 continue;
1129
1130 for (j = 0; j < outlink->incfg.samplerates->nb_formats; j++) {
1131 int diff = abs(sample_rate - outlink->incfg.samplerates->formats[j]);
1132
1133 av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
1134
1135 if (diff < best_diff) {
1136 best_diff = diff;
1137 best_idx = j;
1138 }
1139 }
1140 FFSWAP(int, outlink->incfg.samplerates->formats[0],
1141 outlink->incfg.samplerates->formats[best_idx]);
1142 }
1143}
1144
1146{
1147 int i;
1148
1149 for (i = 0; i < graph->nb_filters; i++)
1151}
1152
1153#define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
1154#define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
1155#define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
1156#define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
1157#define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
1158#define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
1159#define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
1160
1161/* allowable substitutions for channel pairs when comparing layouts,
1162 * ordered by priority for both values */
1186
1188{
1189 AVFilterLink *link = NULL;
1190 int i, j, k;
1191
1192 for (i = 0; i < filter->nb_inputs; i++) {
1193 link = filter->inputs[i];
1194
1195 if (link->type == AVMEDIA_TYPE_AUDIO &&
1197 break;
1198 }
1199 if (i == filter->nb_inputs)
1200 return;
1201
1202 for (i = 0; i < filter->nb_outputs; i++) {
1203 AVFilterLink *outlink = filter->outputs[i];
1204 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
1205
1206 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1208 continue;
1209
1210 for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
1211 AVChannelLayout in_chlayout = link->outcfg.channel_layouts->channel_layouts[0];
1212 AVChannelLayout out_chlayout = outlink->incfg.channel_layouts->channel_layouts[j];
1213 int in_channels;
1214 int out_channels;
1215 int count_diff;
1216 int matched_channels, extra_channels;
1217 int score = 100000;
1218
1219 in_channels = in_chlayout.nb_channels;
1220 out_channels = out_chlayout.nb_channels;
1221 count_diff = out_channels - in_channels;
1222 if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
1223 /* Compute score in case the input or output layout encodes
1224 a channel count; in this case the score is not altered by
1225 the computation afterwards, as in_chlayout and
1226 out_chlayout have both been set to 0 */
1227 if (!KNOWN(&in_chlayout))
1228 in_channels = FF_LAYOUT2COUNT(&in_chlayout);
1229 if (!KNOWN(&out_chlayout))
1230 out_channels = FF_LAYOUT2COUNT(&out_chlayout);
1231 score -= 10000 + FFABS(out_channels - in_channels) +
1232 (in_channels > out_channels ? 10000 : 0);
1233 in_chlayout = (AVChannelLayout){ 0 };
1234 out_chlayout = (AVChannelLayout){ 0 };
1235 /* Let the remaining computation run, even if the score
1236 value is not altered */
1237 }
1238
1239 /* channel substitution */
1240 for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
1241 uint64_t cmp0 = ch_subst[k][0];
1242 uint64_t cmp1 = ch_subst[k][1];
1243 if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
1244 !av_channel_layout_subset(&out_chlayout, cmp0) &&
1245 av_channel_layout_subset(&out_chlayout, cmp1) &&
1246 !av_channel_layout_subset(& in_chlayout, cmp1)) {
1247 av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
1248 av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
1249 /* add score for channel match, minus a deduction for
1250 having to do the substitution */
1251 score += 10 * av_popcount64(cmp1) - 2;
1252 }
1253 }
1254
1255 /* no penalty for LFE channel mismatch */
1258 score += 10;
1261
1262 matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
1263 extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
1264 score += 10 * matched_channels - 5 * extra_channels;
1265
1266 if (score > best_score ||
1267 (count_diff < best_count_diff && score == best_score)) {
1268 best_score = score;
1269 best_idx = j;
1270 best_count_diff = count_diff;
1271 }
1272 }
1273 av_assert0(best_idx >= 0);
1275 outlink->incfg.channel_layouts->channel_layouts[best_idx]);
1276 }
1277
1278}
1279
1281{
1282 int i;
1283
1284 for (i = 0; i < graph->nb_filters; i++)
1286}
1287
1289{
1290 AVFilterLink *link = NULL;
1291 int format, bps;
1292 int i, j;
1293
1294 for (i = 0; i < filter->nb_inputs; i++) {
1295 link = filter->inputs[i];
1296
1297 if (link->type == AVMEDIA_TYPE_AUDIO &&
1298 link->outcfg.formats->nb_formats == 1)
1299 break;
1300 }
1301 if (i == filter->nb_inputs)
1302 return;
1303
1304 format = link->outcfg.formats->formats[0];
1306
1307 for (i = 0; i < filter->nb_outputs; i++) {
1308 AVFilterLink *outlink = filter->outputs[i];
1309 int best_idx = -1, best_score = INT_MIN;
1310
1311 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1312 outlink->incfg.formats->nb_formats < 2)
1313 continue;
1314
1315 for (j = 0; j < outlink->incfg.formats->nb_formats; j++) {
1316 int out_format = outlink->incfg.formats->formats[j];
1317 int out_bps = av_get_bytes_per_sample(out_format);
1318 int score;
1319
1320 if (av_get_packed_sample_fmt(out_format) == format ||
1321 av_get_planar_sample_fmt(out_format) == format) {
1322 best_idx = j;
1323 break;
1324 }
1325
1326 /* for s32 and float prefer double to prevent loss of information */
1327 if (bps == 4 && out_bps == 8) {
1328 best_idx = j;
1329 break;
1330 }
1331
1332 /* prefer closest higher or equal bps */
1333 score = -abs(out_bps - bps);
1334 if (out_bps >= bps)
1335 score += INT_MAX/2;
1336
1337 if (score > best_score) {
1338 best_score = score;
1339 best_idx = j;
1340 }
1341 }
1342 av_assert0(best_idx >= 0);
1343 FFSWAP(int, outlink->incfg.formats->formats[0],
1344 outlink->incfg.formats->formats[best_idx]);
1345 }
1346}
1347
1349{
1350 int i;
1351
1352 for (i = 0; i < graph->nb_filters; i++)
1354
1355}
1356
1357static int pick_formats(AVFilterGraph *graph)
1358{
1359 int i, j, ret;
1360 int change;
1361
1362 do{
1363 change = 0;
1364 for (i = 0; i < graph->nb_filters; i++) {
1365 AVFilterContext *filter = graph->filters[i];
1366 if (filter->nb_inputs){
1367 for (j = 0; j < filter->nb_inputs; j++){
1368 if (filter->inputs[j]->incfg.formats && filter->inputs[j]->incfg.formats->nb_formats == 1) {
1369 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1370 return ret;
1371 change = 1;
1372 }
1373 }
1374 }
1375 if (filter->nb_outputs){
1376 for (j = 0; j < filter->nb_outputs; j++){
1377 if (filter->outputs[j]->incfg.formats && filter->outputs[j]->incfg.formats->nb_formats == 1) {
1378 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1379 return ret;
1380 change = 1;
1381 }
1382 }
1383 }
1384 if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
1385 for (j = 0; j < filter->nb_outputs; j++) {
1386 if (filter->outputs[j]->format<0) {
1387 if ((ret = pick_format(filter->outputs[j], filter->inputs[0])) < 0)
1388 return ret;
1389 change = 1;
1390 }
1391 }
1392 }
1393 }
1394 }while(change);
1395
1396 for (i = 0; i < graph->nb_filters; i++) {
1397 AVFilterContext *filter = graph->filters[i];
1398
1399 for (j = 0; j < filter->nb_inputs; j++)
1400 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1401 return ret;
1402 for (j = 0; j < filter->nb_outputs; j++)
1403 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1404 return ret;
1405 }
1406 return 0;
1407}
1408
1409/**
1410 * Configure the formats of all the links in the graph.
1411 */
1412static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
1413{
1414 int ret;
1415
1416 /* find supported formats from sub-filters, and merge along links */
1417 while ((ret = query_formats(graph, log_ctx)) == AVERROR(EAGAIN))
1418 av_log(graph, AV_LOG_DEBUG, "query_formats not finished\n");
1419 if (ret < 0)
1420 return ret;
1421
1422 /* Once everything is merged, it's possible that we'll still have
1423 * multiple valid media format choices. We try to minimize the amount
1424 * of format conversion inside filters */
1425 if ((ret = reduce_formats(graph)) < 0)
1426 return ret;
1427
1428 /* for audio filters, ensure the best format, sample rate and channel layout
1429 * is selected */
1430 swap_sample_fmts(graph);
1431 swap_samplerates(graph);
1432 swap_channel_layouts(graph);
1433
1434 if ((ret = pick_formats(graph)) < 0)
1435 return ret;
1436
1437 return 0;
1438}
1439
1440static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
1441{
1442 unsigned i, j;
1443 int sink_links_count = 0, n = 0;
1445 FilterLinkInternal **sinks;
1446
1447 for (i = 0; i < graph->nb_filters; i++) {
1448 f = graph->filters[i];
1449 for (j = 0; j < f->nb_inputs; j++) {
1450 ff_link_internal(f->inputs[j])->age_index = -1;
1451 }
1452 for (j = 0; j < f->nb_outputs; j++) {
1453 ff_link_internal(f->outputs[j])->age_index = -1;
1454 }
1455 if (!f->nb_outputs) {
1456 if (f->nb_inputs > INT_MAX - sink_links_count)
1457 return AVERROR(EINVAL);
1458 sink_links_count += f->nb_inputs;
1459 }
1460 }
1461 sinks = av_calloc(sink_links_count, sizeof(*sinks));
1462 if (!sinks)
1463 return AVERROR(ENOMEM);
1464 for (i = 0; i < graph->nb_filters; i++) {
1465 f = graph->filters[i];
1466 if (!f->nb_outputs) {
1467 for (j = 0; j < f->nb_inputs; j++) {
1468 sinks[n] = ff_link_internal(f->inputs[j]);
1469 sinks[n]->age_index = n;
1470 n++;
1471 }
1472 }
1473 }
1474 av_assert0(n == sink_links_count);
1475 fffiltergraph(graph)->sink_links = sinks;
1476 fffiltergraph(graph)->sink_links_count = sink_links_count;
1477 return 0;
1478}
1479
1480int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
1481{
1482 FFFilterGraph *graphi = fffiltergraph(graphctx);
1483 int ret;
1484
1485 size_t max_queued = SIZE_MAX;
1486#if FF_API_MAX_BUFFERED_FRAMES
1488 if (graphctx->max_buffered_frames)
1489 max_queued = graphctx->max_buffered_frames;
1491#endif
1492
1493 for (int i = 0; i < FF_ARRAY_ELEMS(graphi->frame_queues); i++) {
1494 /* only infer the value from graphctx->max_buffered_frames if it was
1495 * not already set by avfilter_graph_set_max_buffered_frames() */
1496 if (!graphi->max_queued_set[i])
1497 graphi->frame_queues[i].max_queued = max_queued;
1498 }
1499 if ((ret = graph_check_validity(graphctx, log_ctx)))
1500 return ret;
1501 if ((ret = graph_config_formats(graphctx, log_ctx)))
1502 return ret;
1503 if ((ret = graph_config_links(graphctx, log_ctx)))
1504 return ret;
1505 if ((ret = graph_check_links(graphctx, log_ctx)))
1506 return ret;
1507 if ((ret = graph_config_pointers(graphctx, log_ctx)))
1508 return ret;
1509
1510 return 0;
1511}
1512
1513int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
1514{
1515 int i, r = AVERROR(ENOSYS);
1516
1517 if (!graph)
1518 return r;
1519
1521 r = avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
1522 if (r != AVERROR(ENOSYS))
1523 return r;
1524 }
1525
1526 if (res_len && res)
1527 res[0] = 0;
1528
1529 for (i = 0; i < graph->nb_filters; i++) {
1530 AVFilterContext *filter = graph->filters[i];
1531 if (!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)) {
1532 r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
1533 if (r != AVERROR(ENOSYS)) {
1534 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1535 return r;
1536 }
1537 }
1538 }
1539
1540 return r;
1541}
1542
1543int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
1544{
1545 int i;
1546
1547 if(!graph)
1548 return 0;
1549
1550 for (i = 0; i < graph->nb_filters; i++) {
1551 AVFilterContext *filter = graph->filters[i];
1553 if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
1554 AVFilterCommand **queue = &ctxi->command_queue, *next;
1555 while (*queue && (*queue)->time <= ts)
1556 queue = &(*queue)->next;
1557 next = *queue;
1558 *queue = av_mallocz(sizeof(AVFilterCommand));
1559 if (!*queue)
1560 return AVERROR(ENOMEM);
1561
1562 (*queue)->command = av_strdup(command);
1563 (*queue)->arg = av_strdup(arg);
1564 (*queue)->time = ts;
1565 (*queue)->flags = flags;
1566 (*queue)->next = next;
1568 return 0;
1569 }
1570 }
1571
1572 return 0;
1573}
1574
1576 FilterLinkInternal *li, int index)
1577{
1578 FilterLinkInternal **links = graph->sink_links;
1579
1580 av_assert0(index >= 0);
1581
1582 while (index) {
1583 int parent = (index - 1) >> 1;
1584 if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
1585 break;
1586 links[index] = links[parent];
1587 links[index]->age_index = index;
1588 index = parent;
1589 }
1590 links[index] = li;
1591 li->age_index = index;
1592}
1593
1595 FilterLinkInternal *li, int index)
1596{
1597 FilterLinkInternal **links = graph->sink_links;
1598
1599 av_assert0(index >= 0);
1600
1601 while (1) {
1602 int child = 2 * index + 1;
1603 if (child >= graph->sink_links_count)
1604 break;
1605 if (child + 1 < graph->sink_links_count &&
1606 links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
1607 child++;
1608 if (li->l.current_pts_us < links[child]->l.current_pts_us)
1609 break;
1610 links[index] = links[child];
1611 links[index]->age_index = index;
1612 index = child;
1613 }
1614 links[index] = li;
1615 li->age_index = index;
1616}
1617
1619{
1620 FFFilterGraph *graphi = fffiltergraph(graph);
1621
1622 heap_bubble_up (graphi, li, li->age_index);
1623 heap_bubble_down(graphi, li, li->age_index);
1624}
1625
1627{
1628 FFFilterGraph *graphi = fffiltergraph(graph);
1629 FilterLinkInternal *oldesti = graphi->sink_links[0];
1630 AVFilterLink *oldest = &oldesti->l.pub;
1631 int64_t frame_count;
1632 int r;
1633
1634 while (graphi->sink_links_count) {
1635 oldesti = graphi->sink_links[0];
1636 oldest = &oldesti->l.pub;
1637 if (fffilter(oldest->dst->filter)->activate) {
1640 if (r != AVERROR_EOF)
1641 return r;
1642 } else {
1643 r = ff_request_frame(oldest);
1644 }
1645 if (r != AVERROR_EOF)
1646 break;
1647 av_log(oldest->dst, AV_LOG_DEBUG, "EOF on sink link %s:%s.\n",
1648 oldest->dst->name,
1649 oldest->dstpad->name);
1650 /* EOF: remove the link from the heap */
1651 if (oldesti->age_index < --graphi->sink_links_count)
1652 heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
1653 oldesti->age_index);
1654 oldesti->age_index = -1;
1655 }
1656 if (!graphi->sink_links_count)
1657 return AVERROR_EOF;
1658 av_assert1(!fffilter(oldest->dst->filter)->activate);
1659 av_assert1(oldesti->age_index >= 0);
1660 frame_count = oldesti->l.frame_count_out;
1661 while (frame_count == oldesti->l.frame_count_out) {
1662 r = ff_filter_graph_run_once(graph);
1664 r = 0;
1665 if (r == AVERROR(EAGAIN) &&
1666 !oldesti->frame_wanted_out && !oldesti->frame_blocked_in &&
1667 !oldesti->status_in)
1668 (void)ff_request_frame(oldest);
1669 else if (r < 0)
1670 return r;
1671 }
1672 return 0;
1673}
1674
1676{
1677 FFFilterContext *ctxi;
1678 unsigned i;
1679
1680 av_assert0(graph->nb_filters);
1681 ctxi = fffilterctx(graph->filters[0]);
1682 for (i = 1; i < graph->nb_filters; i++) {
1683 FFFilterContext *ctxi_other = fffilterctx(graph->filters[i]);
1684
1685 if (ctxi_other->ready > ctxi->ready)
1686 ctxi = ctxi_other;
1687 }
1688
1689 if (!ctxi->ready)
1690 return AVERROR(EAGAIN);
1691 return ff_filter_activate(&ctxi->p);
1692}
static const char *const format[]
Definition af_aiir.c:445
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
static const int8_t filt[NUMTAPS *2]
Definition af_earwax.c:40
static FILE * out
static int frames
static AVFormatContext * ctx
#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:710
int ff_filter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition avfilter.c:334
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition avfilter.c:492
int ff_filter_activate(AVFilterContext *filter)
Definition avfilter.c:1458
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:121
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
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
int ret
Definition ffplay.c:391
const AVFilterNegotiation * ff_filter_get_negotiation(const AVFilterLink *link)
Definition formats.c:471
int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample rates list.
Definition formats.c:1330
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:1233
int ff_formats_check_chroma_locations(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for chroma locations.
Definition formats.c:1358
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition formats.c:580
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition formats.c:827
int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid pixel formats list.
Definition formats.c:1320
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition formats.c:597
int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample formats list.
Definition formats.c:1325
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:1337
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:815
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition formats.c:1348
int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
Check that fmts is a valid channel layouts list.
Definition formats.c:1370
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:1353
#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
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
Definition opt.h:385
@ 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:138
#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:86
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition avfilter.c:971
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:285
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition avfilter.c:811
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:657
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:619
int avfilter_graph_set_max_buffered_frames(AVFilterGraph *graph, enum AVMediaType type, unsigned frames)
Set the maximum number of combined buffered frames of a given media type in the filtergraph.
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:276
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:452
#define AVFILTER_CMD_FLAG_FAST
Only execute command when its fast (like a video out that supports contrast adjustment in hw)
Definition avfilter.h:453
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.
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:234
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:226
#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_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#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:247
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:318
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
AVMediaType
Definition avutil.h:198
@ 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:115
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:109
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition samplefmt.c:78
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition samplefmt.c:87
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:52
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:2042
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1771
int index
Definition gxfenc.c:90
int a
misc image utilities
#define r
Definition input.c:42
#define b
Definition input.c:43
enum MPFType type
Definition jpegmpfenc.c:55
const char * arg
Definition jacosubdec.c:66
#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:245
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition filters.h:246
static const FFFilter * fffilter(const AVFilter *f)
Definition filters.h:479
#define FF_FIELD_AT(type, off, obj)
Access a field in a structure by its offset.
Definition internal.h:88
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition internal.h:71
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition internal.h:72
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:370
Memory handling functions.
unsigned bps
Definition movenc.c:2129
#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:3404
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:3763
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#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
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:808
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:754
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:788
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:822
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:712
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
const char * name
Definition qsvenc.c:142
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
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
An instance of a filter.
Definition avfilter.h:279
char * name
name of this filter instance
Definition avfilter.h:284
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:287
const AVFilter * filter
the AVFilter of which this is an instance
Definition avfilter.h:282
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:291
Lists of formats / etc.
Definition avfilter.h:120
AVFilterFormats * chroma_locations
List of supported chroma sample locations, only for video with subsampled chroma.
Definition avfilter.h:152
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:616
int(* merge)(void *a, void *b)
Definition formats.h:612
const char * name
Definition formats.h:610
int(* can_merge)(const void *a, const void *b)
Definition formats.h:613
void(* print_list)(struct AVBPrint *bp, const void *fmts)
Definition formats.h:614
const char * conversion_filter
Definition formats.h:615
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:575
AVFilterContext ** filters
Definition avfilter.h:574
int thread_type
Type of multithreading allowed for filters in this graph.
Definition avfilter.h:591
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:619
int nb_threads
Maximum number of threads used by filters in this graph.
Definition avfilter.h:598
Callbacks and properties to describe the steps of a format negotiation.
Definition formats.h:704
unsigned nb_mergers
Definition formats.h:705
const AVFilterFormatsMerger * mergers
Definition formats.h:706
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:221
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[AVMEDIA_TYPE_NB]
uint8_t max_queued_set[AVMEDIA_TYPE_NB]
struct FilterLinkInternal ** sink_links
unsigned disable_auto_convert
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition filters.h:476
Structure to hold global options and statistics for frame queues.
Definition framequeue.h:44
size_t queued
Total number of queued frames in the queues combined.
Definition framequeue.h:54
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]
AVThreadMessageQueue * queue
Definition swscale.c:141
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)