]> git.sesse.net Git - ffmpeg/blob - libavfilter/avfilter.c
x86: Move some conditional code around to avoid unused variable warnings
[ffmpeg] / libavfilter / avfilter.c
1 /*
2  * filter layer
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 /* #define DEBUG */
23
24 #include "libavutil/avstring.h"
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/common.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/rational.h"
31 #include "libavutil/samplefmt.h"
32
33 #include "audio.h"
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "internal.h"
37 #include "video.h"
38
39 unsigned avfilter_version(void) {
40     return LIBAVFILTER_VERSION_INT;
41 }
42
43 const char *avfilter_configuration(void)
44 {
45     return LIBAV_CONFIGURATION;
46 }
47
48 const char *avfilter_license(void)
49 {
50 #define LICENSE_PREFIX "libavfilter license: "
51     return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
52 }
53
54 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
55                    AVFilterPad **pads, AVFilterLink ***links,
56                    AVFilterPad *newpad)
57 {
58     unsigned i;
59
60     idx = FFMIN(idx, *count);
61
62     *pads  = av_realloc(*pads,  sizeof(AVFilterPad)   * (*count + 1));
63     *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
64     memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad)   * (*count-idx));
65     memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx));
66     memcpy(*pads+idx, newpad, sizeof(AVFilterPad));
67     (*links)[idx] = NULL;
68
69     (*count)++;
70     for (i = idx+1; i < *count; i++)
71         if (*links[i])
72             (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
73 }
74
75 int avfilter_link(AVFilterContext *src, unsigned srcpad,
76                   AVFilterContext *dst, unsigned dstpad)
77 {
78     AVFilterLink *link;
79
80     if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad ||
81         src->outputs[srcpad]      || dst->inputs[dstpad])
82         return -1;
83
84     if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
85         av_log(src, AV_LOG_ERROR,
86                "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n",
87                src->name, srcpad, dst->name, dstpad);
88         return AVERROR(EINVAL);
89     }
90
91     src->outputs[srcpad] =
92     dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink));
93
94     link->src     = src;
95     link->dst     = dst;
96     link->srcpad  = &src->output_pads[srcpad];
97     link->dstpad  = &dst->input_pads[dstpad];
98     link->type    = src->output_pads[srcpad].type;
99     assert(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
100     link->format  = -1;
101
102     return 0;
103 }
104
105 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
106                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
107 {
108     int ret;
109     unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
110
111     av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
112            "between the filter '%s' and the filter '%s'\n",
113            filt->name, link->src->name, link->dst->name);
114
115     link->dst->inputs[dstpad_idx] = NULL;
116     if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
117         /* failed to link output filter to new filter */
118         link->dst->inputs[dstpad_idx] = link;
119         return ret;
120     }
121
122     /* re-hookup the link to the new destination filter we inserted */
123     link->dst = filt;
124     link->dstpad = &filt->input_pads[filt_srcpad_idx];
125     filt->inputs[filt_srcpad_idx] = link;
126
127     /* if any information on supported media formats already exists on the
128      * link, we need to preserve that */
129     if (link->out_formats)
130         ff_formats_changeref(&link->out_formats,
131                                    &filt->outputs[filt_dstpad_idx]->out_formats);
132     if (link->out_samplerates)
133         ff_formats_changeref(&link->out_samplerates,
134                                    &filt->outputs[filt_dstpad_idx]->out_samplerates);
135     if (link->out_channel_layouts)
136         ff_channel_layouts_changeref(&link->out_channel_layouts,
137                                      &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
138
139     return 0;
140 }
141
142 int avfilter_config_links(AVFilterContext *filter)
143 {
144     int (*config_link)(AVFilterLink *);
145     unsigned i;
146     int ret;
147
148     for (i = 0; i < filter->nb_inputs; i ++) {
149         AVFilterLink *link = filter->inputs[i];
150
151         if (!link) continue;
152
153         switch (link->init_state) {
154         case AVLINK_INIT:
155             continue;
156         case AVLINK_STARTINIT:
157             av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
158             return 0;
159         case AVLINK_UNINIT:
160             link->init_state = AVLINK_STARTINIT;
161
162             if ((ret = avfilter_config_links(link->src)) < 0)
163                 return ret;
164
165             if (!(config_link = link->srcpad->config_props)) {
166                 if (link->src->nb_inputs != 1) {
167                     av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
168                                                     "with more than one input "
169                                                     "must set config_props() "
170                                                     "callbacks on all outputs\n");
171                     return AVERROR(EINVAL);
172                 }
173             } else if ((ret = config_link(link)) < 0) {
174                 av_log(link->src, AV_LOG_ERROR,
175                        "Failed to configure output pad on %s\n",
176                        link->src->name);
177                 return ret;
178             }
179
180             if (link->time_base.num == 0 && link->time_base.den == 0)
181                 link->time_base = link->src && link->src->nb_inputs ?
182                     link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
183
184             if (link->type == AVMEDIA_TYPE_VIDEO) {
185                 if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
186                     link->sample_aspect_ratio = link->src->nb_inputs ?
187                         link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
188
189                 if (link->src->nb_inputs) {
190                     if (!link->w)
191                         link->w = link->src->inputs[0]->w;
192                     if (!link->h)
193                         link->h = link->src->inputs[0]->h;
194                 } else if (!link->w || !link->h) {
195                     av_log(link->src, AV_LOG_ERROR,
196                            "Video source filters must set their output link's "
197                            "width and height\n");
198                     return AVERROR(EINVAL);
199                 }
200             }
201
202             if ((config_link = link->dstpad->config_props))
203                 if ((ret = config_link(link)) < 0) {
204                     av_log(link->src, AV_LOG_ERROR,
205                            "Failed to configure input pad on %s\n",
206                            link->dst->name);
207                     return ret;
208                 }
209
210             link->init_state = AVLINK_INIT;
211         }
212     }
213
214     return 0;
215 }
216
217 void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
218 {
219     if (link->type == AVMEDIA_TYPE_VIDEO) {
220         av_dlog(ctx,
221                 "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
222                 link, link->w, link->h,
223                 av_get_pix_fmt_name(link->format),
224                 link->src ? link->src->filter->name : "",
225                 link->dst ? link->dst->filter->name : "",
226                 end ? "\n" : "");
227     } else {
228         char buf[128];
229         av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
230
231         av_dlog(ctx,
232                 "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
233                 link, link->sample_rate, buf,
234                 av_get_sample_fmt_name(link->format),
235                 link->src ? link->src->filter->name : "",
236                 link->dst ? link->dst->filter->name : "",
237                 end ? "\n" : "");
238     }
239 }
240
241 int ff_request_frame(AVFilterLink *link)
242 {
243     FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
244
245     if (link->srcpad->request_frame)
246         return link->srcpad->request_frame(link);
247     else if (link->src->inputs[0])
248         return ff_request_frame(link->src->inputs[0]);
249     else return -1;
250 }
251
252 int ff_poll_frame(AVFilterLink *link)
253 {
254     int i, min = INT_MAX;
255
256     if (link->srcpad->poll_frame)
257         return link->srcpad->poll_frame(link);
258
259     for (i = 0; i < link->src->nb_inputs; i++) {
260         int val;
261         if (!link->src->inputs[i])
262             return -1;
263         val = ff_poll_frame(link->src->inputs[i]);
264         min = FFMIN(min, val);
265     }
266
267     return min;
268 }
269
270 static AVFilter *first_filter;
271
272 AVFilter *avfilter_get_by_name(const char *name)
273 {
274     AVFilter *f = NULL;
275
276     if (!name)
277         return NULL;
278
279     while ((f = avfilter_next(f)))
280         if (!strcmp(f->name, name))
281             return f;
282
283     return NULL;
284 }
285
286 int avfilter_register(AVFilter *filter)
287 {
288     AVFilter **f = &first_filter;
289     while (*f)
290         f = &(*f)->next;
291     *f = filter;
292     filter->next = NULL;
293     return 0;
294 }
295
296 const AVFilter *avfilter_next(const AVFilter *prev)
297 {
298     return prev ? prev->next : first_filter;
299 }
300
301 #if FF_API_OLD_FILTER_REGISTER
302 AVFilter **av_filter_next(AVFilter **filter)
303 {
304     return filter ? &(*filter)->next : &first_filter;
305 }
306
307 void avfilter_uninit(void)
308 {
309 }
310 #endif
311
312 int avfilter_pad_count(const AVFilterPad *pads)
313 {
314     int count;
315
316     if (!pads)
317         return 0;
318
319     for(count = 0; pads->name; count ++) pads ++;
320     return count;
321 }
322
323 static const char *filter_name(void *p)
324 {
325     AVFilterContext *filter = p;
326     return filter->filter->name;
327 }
328
329 static void *filter_child_next(void *obj, void *prev)
330 {
331     AVFilterContext *ctx = obj;
332     if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
333         return ctx->priv;
334     return NULL;
335 }
336
337 static const AVClass *filter_child_class_next(const AVClass *prev)
338 {
339     AVFilter *f = NULL;
340
341     while (prev && (f = avfilter_next(f)))
342         if (f->priv_class == prev)
343             break;
344
345     while ((f = avfilter_next(f)))
346         if (f->priv_class)
347             return f->priv_class;
348
349     return NULL;
350 }
351
352 static const AVClass avfilter_class = {
353     .class_name = "AVFilter",
354     .item_name  = filter_name,
355     .version    = LIBAVUTIL_VERSION_INT,
356     .child_next = filter_child_next,
357     .child_class_next = filter_child_class_next,
358 };
359
360 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
361 {
362     AVFilterContext *ret;
363
364     if (!filter)
365         return NULL;
366
367     ret = av_mallocz(sizeof(AVFilterContext));
368     if (!ret)
369         return NULL;
370
371     ret->av_class = &avfilter_class;
372     ret->filter   = filter;
373     ret->name     = inst_name ? av_strdup(inst_name) : NULL;
374     if (filter->priv_size) {
375         ret->priv     = av_mallocz(filter->priv_size);
376         if (!ret->priv)
377             goto err;
378     }
379
380     if (filter->priv_class) {
381         *(const AVClass**)ret->priv = filter->priv_class;
382         av_opt_set_defaults(ret->priv);
383     }
384
385     ret->nb_inputs = avfilter_pad_count(filter->inputs);
386     if (ret->nb_inputs ) {
387         ret->input_pads   = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
388         if (!ret->input_pads)
389             goto err;
390         memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
391         ret->inputs       = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
392         if (!ret->inputs)
393             goto err;
394     }
395
396     ret->nb_outputs = avfilter_pad_count(filter->outputs);
397     if (ret->nb_outputs) {
398         ret->output_pads  = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
399         if (!ret->output_pads)
400             goto err;
401         memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
402         ret->outputs      = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
403         if (!ret->outputs)
404             goto err;
405     }
406 #if FF_API_FOO_COUNT
407     ret->output_count = ret->nb_outputs;
408     ret->input_count  = ret->nb_inputs;
409 #endif
410
411     return ret;
412
413 err:
414     av_freep(&ret->inputs);
415     av_freep(&ret->input_pads);
416     ret->nb_inputs = 0;
417     av_freep(&ret->outputs);
418     av_freep(&ret->output_pads);
419     ret->nb_outputs = 0;
420     av_freep(&ret->priv);
421     av_free(ret);
422     return NULL;
423 }
424
425 #if FF_API_AVFILTER_OPEN
426 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
427 {
428     *filter_ctx = ff_filter_alloc(filter, inst_name);
429     return *filter_ctx ? 0 : AVERROR(ENOMEM);
430 }
431 #endif
432
433 void avfilter_free(AVFilterContext *filter)
434 {
435     int i;
436     AVFilterLink *link;
437
438     if (filter->graph)
439         ff_filter_graph_remove_filter(filter->graph, filter);
440
441     if (filter->filter->uninit)
442         filter->filter->uninit(filter);
443
444     for (i = 0; i < filter->nb_inputs; i++) {
445         if ((link = filter->inputs[i])) {
446             if (link->src)
447                 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
448             ff_formats_unref(&link->in_formats);
449             ff_formats_unref(&link->out_formats);
450             ff_formats_unref(&link->in_samplerates);
451             ff_formats_unref(&link->out_samplerates);
452             ff_channel_layouts_unref(&link->in_channel_layouts);
453             ff_channel_layouts_unref(&link->out_channel_layouts);
454         }
455         av_freep(&link);
456     }
457     for (i = 0; i < filter->nb_outputs; i++) {
458         if ((link = filter->outputs[i])) {
459             if (link->dst)
460                 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
461             ff_formats_unref(&link->in_formats);
462             ff_formats_unref(&link->out_formats);
463             ff_formats_unref(&link->in_samplerates);
464             ff_formats_unref(&link->out_samplerates);
465             ff_channel_layouts_unref(&link->in_channel_layouts);
466             ff_channel_layouts_unref(&link->out_channel_layouts);
467         }
468         av_freep(&link);
469     }
470
471     if (filter->filter->priv_class)
472         av_opt_free(filter->priv);
473
474     av_freep(&filter->name);
475     av_freep(&filter->input_pads);
476     av_freep(&filter->output_pads);
477     av_freep(&filter->inputs);
478     av_freep(&filter->outputs);
479     av_freep(&filter->priv);
480     av_free(filter);
481 }
482
483 /* process a list of value1:value2:..., each value corresponding
484  * to subsequent AVOption, in the order they are declared */
485 static int process_unnamed_options(AVFilterContext *ctx, AVDictionary **options,
486                                    const char *args)
487 {
488     const AVOption *o = NULL;
489     const char *p = args;
490     char *val;
491
492     while (*p) {
493         o = av_opt_next(ctx->priv, o);
494         if (!o) {
495             av_log(ctx, AV_LOG_ERROR, "More options provided than "
496                    "this filter supports.\n");
497             return AVERROR(EINVAL);
498         }
499         if (o->type == AV_OPT_TYPE_CONST)
500             continue;
501
502         val = av_get_token(&p, ":");
503         if (!val)
504             return AVERROR(ENOMEM);
505
506         av_dict_set(options, o->name, val, 0);
507
508         av_freep(&val);
509         if (*p)
510             p++;
511     }
512
513     return 0;
514 }
515
516 #if FF_API_AVFILTER_INIT_FILTER
517 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
518 {
519     return avfilter_init_str(filter, args);
520 }
521 #endif
522
523 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
524 {
525     int ret = 0;
526
527     if (ctx->filter->priv_class) {
528         ret = av_opt_set_dict(ctx->priv, options);
529         if (ret < 0) {
530             av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n");
531             return ret;
532         }
533     }
534
535     if (ctx->filter->init)
536         ret = ctx->filter->init(ctx);
537     else if (ctx->filter->init_dict)
538         ret = ctx->filter->init_dict(ctx, options);
539
540     return ret;
541 }
542
543 int avfilter_init_str(AVFilterContext *filter, const char *args)
544 {
545     AVDictionary *options = NULL;
546     AVDictionaryEntry *e;
547     int ret=0;
548
549     if (args && *args) {
550         if (!filter->filter->priv_class) {
551             av_log(filter, AV_LOG_ERROR, "This filter does not take any "
552                    "options, but options were provided: %s.\n", args);
553             return AVERROR(EINVAL);
554         }
555
556 #if FF_API_OLD_FILTER_OPTS
557         if (!strcmp(filter->filter->name, "scale") &&
558             strchr(args, ':') < strchr(args, '=')) {
559             /* old w:h:flags=<flags> syntax */
560             char *copy = av_strdup(args);
561             char *p;
562
563             av_log(filter, AV_LOG_WARNING, "The <w>:<h>:flags=<flags> option "
564                    "syntax is deprecated. Use either <w>:<h>:<flags> or "
565                    "w=<w>:h=<h>:flags=<flags>.\n");
566
567             if (!copy) {
568                 ret = AVERROR(ENOMEM);
569                 goto fail;
570             }
571
572             p = strrchr(copy, ':');
573             if (p) {
574                 *p++ = 0;
575                 ret = av_dict_parse_string(&options, p, "=", ":", 0);
576             }
577             if (ret >= 0)
578                 ret = process_unnamed_options(filter, &options, copy);
579             av_freep(&copy);
580
581             if (ret < 0)
582                 goto fail;
583         } else
584 #endif
585
586         if (strchr(args, '=')) {
587             /* assume a list of key1=value1:key2=value2:... */
588             ret = av_dict_parse_string(&options, args, "=", ":", 0);
589             if (ret < 0)
590                 goto fail;
591 #if FF_API_OLD_FILTER_OPTS
592         } else if (!strcmp(filter->filter->name, "format")     ||
593                    !strcmp(filter->filter->name, "noformat")   ||
594                    !strcmp(filter->filter->name, "frei0r")     ||
595                    !strcmp(filter->filter->name, "frei0r_src") ||
596                    !strcmp(filter->filter->name, "ocv")) {
597             /* a hack for compatibility with the old syntax
598              * replace colons with |s */
599             char *copy = av_strdup(args);
600             char *p    = copy;
601             int nb_leading = 0; // number of leading colons to skip
602
603             if (!copy) {
604                 ret = AVERROR(ENOMEM);
605                 goto fail;
606             }
607
608             if (!strcmp(filter->filter->name, "frei0r") ||
609                 !strcmp(filter->filter->name, "ocv"))
610                 nb_leading = 1;
611             else if (!strcmp(filter->filter->name, "frei0r_src"))
612                 nb_leading = 3;
613
614             while (nb_leading--) {
615                 p = strchr(p, ':');
616                 if (!p) {
617                     p = copy + strlen(copy);
618                     break;
619                 }
620                 p++;
621             }
622
623             if (strchr(p, ':')) {
624                 av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
625                        "'|' to separate the list items.\n");
626             }
627
628             while ((p = strchr(p, ':')))
629                 *p++ = '|';
630
631             ret = process_unnamed_options(filter, &options, copy);
632             av_freep(&copy);
633
634             if (ret < 0)
635                 goto fail;
636 #endif
637         } else {
638             ret = process_unnamed_options(filter, &options, args);
639             if (ret < 0)
640                 goto fail;
641         }
642     }
643
644     ret = avfilter_init_dict(filter, &options);
645     if (ret < 0)
646         goto fail;
647
648     if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
649         av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
650         ret = AVERROR_OPTION_NOT_FOUND;
651         goto fail;
652     }
653
654 fail:
655     av_dict_free(&options);
656
657     return ret;
658 }
659
660 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
661 {
662     return pads[pad_idx].name;
663 }
664
665 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
666 {
667     return pads[pad_idx].type;
668 }
669
670 static int default_filter_frame(AVFilterLink *link, AVFrame *frame)
671 {
672     return ff_filter_frame(link->dst->outputs[0], frame);
673 }
674
675 int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
676 {
677     int (*filter_frame)(AVFilterLink *, AVFrame *);
678     AVFilterPad *dst = link->dstpad;
679     AVFrame *out;
680
681     FF_DPRINTF_START(NULL, filter_frame);
682     ff_dlog_link(NULL, link, 1);
683
684     if (!(filter_frame = dst->filter_frame))
685         filter_frame = default_filter_frame;
686
687     /* copy the frame if needed */
688     if (dst->needs_writable && !av_frame_is_writable(frame)) {
689         av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n");
690
691         switch (link->type) {
692         case AVMEDIA_TYPE_VIDEO:
693             out = ff_get_video_buffer(link, link->w, link->h);
694             break;
695         case AVMEDIA_TYPE_AUDIO:
696             out = ff_get_audio_buffer(link, frame->nb_samples);
697             break;
698         default: return AVERROR(EINVAL);
699         }
700         if (!out) {
701             av_frame_free(&frame);
702             return AVERROR(ENOMEM);
703         }
704         av_frame_copy_props(out, frame);
705
706         switch (link->type) {
707         case AVMEDIA_TYPE_VIDEO:
708             av_image_copy(out->data, out->linesize, frame->data, frame->linesize,
709                           frame->format, frame->width, frame->height);
710             break;
711         case AVMEDIA_TYPE_AUDIO:
712             av_samples_copy(out->extended_data, frame->extended_data,
713                             0, 0, frame->nb_samples,
714                             av_get_channel_layout_nb_channels(frame->channel_layout),
715                             frame->format);
716             break;
717         default: return AVERROR(EINVAL);
718         }
719
720         av_frame_free(&frame);
721     } else
722         out = frame;
723
724     return filter_frame(link, out);
725 }
726
727 const AVClass *avfilter_get_class(void)
728 {
729     return &avfilter_class;
730 }