Libav
avfilter.c
Go to the documentation of this file.
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 #include "libavutil/avstring.h"
24 #include "libavutil/common.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/rational.h"
30 #include "libavutil/samplefmt.h"
31 
32 #include "audio.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 #include "video.h"
37 
38 unsigned avfilter_version(void)
39 {
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  link = av_mallocz(sizeof(*link));
92  if (!link)
93  return AVERROR(ENOMEM);
94 
95  src->outputs[srcpad] = dst->inputs[dstpad] = link;
96 
97  link->src = src;
98  link->dst = dst;
99  link->srcpad = &src->output_pads[srcpad];
100  link->dstpad = &dst->input_pads[dstpad];
101  link->type = src->output_pads[srcpad].type;
102  assert(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
103  link->format = -1;
104 
105  return 0;
106 }
107 
109  unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
110 {
111  int ret;
112  unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
113 
114  av_log(link->dst, AV_LOG_VERBOSE, "auto-inserting filter '%s' "
115  "between the filter '%s' and the filter '%s'\n",
116  filt->name, link->src->name, link->dst->name);
117 
118  link->dst->inputs[dstpad_idx] = NULL;
119  if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
120  /* failed to link output filter to new filter */
121  link->dst->inputs[dstpad_idx] = link;
122  return ret;
123  }
124 
125  /* re-hookup the link to the new destination filter we inserted */
126  link->dst = filt;
127  link->dstpad = &filt->input_pads[filt_srcpad_idx];
128  filt->inputs[filt_srcpad_idx] = link;
129 
130  /* if any information on supported media formats already exists on the
131  * link, we need to preserve that */
132  if (link->out_formats)
134  &filt->outputs[filt_dstpad_idx]->out_formats);
135  if (link->out_samplerates)
137  &filt->outputs[filt_dstpad_idx]->out_samplerates);
138  if (link->out_channel_layouts)
140  &filt->outputs[filt_dstpad_idx]->out_channel_layouts);
141 
142  return 0;
143 }
144 
146 {
147  int (*config_link)(AVFilterLink *);
148  unsigned i;
149  int ret;
150 
151  for (i = 0; i < filter->nb_inputs; i ++) {
152  AVFilterLink *link = filter->inputs[i];
153 
154  if (!link) continue;
155 
156  switch (link->init_state) {
157  case AVLINK_INIT:
158  continue;
159  case AVLINK_STARTINIT:
160  av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
161  return 0;
162  case AVLINK_UNINIT:
163  link->init_state = AVLINK_STARTINIT;
164 
165  if ((ret = avfilter_config_links(link->src)) < 0)
166  return ret;
167 
168  if (!(config_link = link->srcpad->config_props)) {
169  if (link->src->nb_inputs != 1) {
170  av_log(link->src, AV_LOG_ERROR, "Source filters and filters "
171  "with more than one input "
172  "must set config_props() "
173  "callbacks on all outputs\n");
174  return AVERROR(EINVAL);
175  }
176  } else if ((ret = config_link(link)) < 0) {
177  av_log(link->src, AV_LOG_ERROR,
178  "Failed to configure output pad on %s\n",
179  link->src->name);
180  return ret;
181  }
182 
183  if (link->time_base.num == 0 && link->time_base.den == 0)
184  link->time_base = link->src && link->src->nb_inputs ?
185  link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
186 
187  if (link->type == AVMEDIA_TYPE_VIDEO) {
188  if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den)
189  link->sample_aspect_ratio = link->src->nb_inputs ?
190  link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
191 
192  if (link->src->nb_inputs) {
193  if (!link->w)
194  link->w = link->src->inputs[0]->w;
195  if (!link->h)
196  link->h = link->src->inputs[0]->h;
197  } else if (!link->w || !link->h) {
198  av_log(link->src, AV_LOG_ERROR,
199  "Video source filters must set their output link's "
200  "width and height\n");
201  return AVERROR(EINVAL);
202  }
203  }
204 
205  if ((config_link = link->dstpad->config_props))
206  if ((ret = config_link(link)) < 0) {
207  av_log(link->dst, AV_LOG_ERROR,
208  "Failed to configure input pad on %s\n",
209  link->dst->name);
210  return ret;
211  }
212 
213  link->init_state = AVLINK_INIT;
214  }
215  }
216 
217  return 0;
218 }
219 
220 void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
221 {
222  if (link->type == AVMEDIA_TYPE_VIDEO) {
223  av_dlog(ctx,
224  "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
225  link, link->w, link->h,
227  link->src ? link->src->filter->name : "",
228  link->dst ? link->dst->filter->name : "",
229  end ? "\n" : "");
230  } else {
231  char buf[128];
232  av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
233 
234  av_dlog(ctx,
235  "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
236  link, link->sample_rate, buf,
238  link->src ? link->src->filter->name : "",
239  link->dst ? link->dst->filter->name : "",
240  end ? "\n" : "");
241  }
242 }
243 
245 {
247 
248  if (link->srcpad->request_frame)
249  return link->srcpad->request_frame(link);
250  else if (link->src->inputs[0])
251  return ff_request_frame(link->src->inputs[0]);
252  else return -1;
253 }
254 
256 {
257  int i, min = INT_MAX;
258 
259  if (link->srcpad->poll_frame)
260  return link->srcpad->poll_frame(link);
261 
262  for (i = 0; i < link->src->nb_inputs; i++) {
263  int val;
264  if (!link->src->inputs[i])
265  return -1;
266  val = ff_poll_frame(link->src->inputs[i]);
267  min = FFMIN(min, val);
268  }
269 
270  return min;
271 }
272 
274 
275 #if !FF_API_NOCONST_GET_NAME
276 const
277 #endif
279 {
280  const AVFilter *f = NULL;
281 
282  if (!name)
283  return NULL;
284 
285  while ((f = avfilter_next(f)))
286  if (!strcmp(f->name, name))
287  return f;
288 
289  return NULL;
290 }
291 
293 {
294  AVFilter **f = &first_filter;
295  while (*f)
296  f = &(*f)->next;
297  *f = filter;
298  filter->next = NULL;
299  return 0;
300 }
301 
302 const AVFilter *avfilter_next(const AVFilter *prev)
303 {
304  return prev ? prev->next : first_filter;
305 }
306 
307 #if FF_API_OLD_FILTER_REGISTER
308 AVFilter **av_filter_next(AVFilter **filter)
309 {
310  return filter ? &(*filter)->next : &first_filter;
311 }
312 
313 void avfilter_uninit(void)
314 {
315 }
316 #endif
317 
319 {
320  int count;
321 
322  if (!pads)
323  return 0;
324 
325  for (count = 0; pads->name; count++)
326  pads++;
327  return count;
328 }
329 
330 static const char *filter_name(void *p)
331 {
332  AVFilterContext *filter = p;
333  return filter->filter->name;
334 }
335 
336 static void *filter_child_next(void *obj, void *prev)
337 {
338  AVFilterContext *ctx = obj;
339  if (!prev && ctx->filter && ctx->filter->priv_class && ctx->priv)
340  return ctx->priv;
341  return NULL;
342 }
343 
344 static const AVClass *filter_child_class_next(const AVClass *prev)
345 {
346  const AVFilter *f = NULL;
347 
348  while (prev && (f = avfilter_next(f)))
349  if (f->priv_class == prev)
350  break;
351 
352  while ((f = avfilter_next(f)))
353  if (f->priv_class)
354  return f->priv_class;
355 
356  return NULL;
357 }
358 
359 #define OFFSET(x) offsetof(AVFilterContext, x)
360 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
361 static const AVOption avfilter_options[] = {
362  { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
363  { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
364  { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .unit = "thread_type" },
365  { NULL },
366 };
367 
368 static const AVClass avfilter_class = {
369  .class_name = "AVFilter",
370  .item_name = filter_name,
371  .version = LIBAVUTIL_VERSION_INT,
372  .child_next = filter_child_next,
373  .child_class_next = filter_child_class_next,
375 };
376 
377 static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
378  int *ret, int nb_jobs)
379 {
380  int i;
381 
382  for (i = 0; i < nb_jobs; i++) {
383  int r = func(ctx, arg, i, nb_jobs);
384  if (ret)
385  ret[i] = r;
386  }
387  return 0;
388 }
389 
390 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
391 {
392  AVFilterContext *ret;
393 
394  if (!filter)
395  return NULL;
396 
397  ret = av_mallocz(sizeof(AVFilterContext));
398  if (!ret)
399  return NULL;
400 
401  ret->av_class = &avfilter_class;
402  ret->filter = filter;
403  ret->name = inst_name ? av_strdup(inst_name) : NULL;
404  if (filter->priv_size) {
405  ret->priv = av_mallocz(filter->priv_size);
406  if (!ret->priv)
407  goto err;
408  }
409 
410  av_opt_set_defaults(ret);
411  if (filter->priv_class) {
412  *(const AVClass**)ret->priv = filter->priv_class;
414  }
415 
416  ret->internal = av_mallocz(sizeof(*ret->internal));
417  if (!ret->internal)
418  goto err;
420 
421  ret->nb_inputs = avfilter_pad_count(filter->inputs);
422  if (ret->nb_inputs ) {
423  ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
424  if (!ret->input_pads)
425  goto err;
426  memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs);
427  ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs);
428  if (!ret->inputs)
429  goto err;
430  }
431 
432  ret->nb_outputs = avfilter_pad_count(filter->outputs);
433  if (ret->nb_outputs) {
434  ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs);
435  if (!ret->output_pads)
436  goto err;
437  memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs);
438  ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs);
439  if (!ret->outputs)
440  goto err;
441  }
442 #if FF_API_FOO_COUNT
444  ret->output_count = ret->nb_outputs;
445  ret->input_count = ret->nb_inputs;
447 #endif
448 
449  return ret;
450 
451 err:
452  av_freep(&ret->inputs);
453  av_freep(&ret->input_pads);
454  ret->nb_inputs = 0;
455  av_freep(&ret->outputs);
456  av_freep(&ret->output_pads);
457  ret->nb_outputs = 0;
458  av_freep(&ret->priv);
459  av_freep(&ret->internal);
460  av_free(ret);
461  return NULL;
462 }
463 
464 #if FF_API_AVFILTER_OPEN
465 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
466 {
467  *filter_ctx = ff_filter_alloc(filter, inst_name);
468  return *filter_ctx ? 0 : AVERROR(ENOMEM);
469 }
470 #endif
471 
472 static void free_link(AVFilterLink *link)
473 {
474  if (!link)
475  return;
476 
477  if (link->src)
478  link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
479  if (link->dst)
480  link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
481 
488  av_freep(&link);
489 }
490 
492 {
493  int i;
494 
495  if (filter->graph)
496  ff_filter_graph_remove_filter(filter->graph, filter);
497 
498  if (filter->filter->uninit)
499  filter->filter->uninit(filter);
500 
501  for (i = 0; i < filter->nb_inputs; i++) {
502  free_link(filter->inputs[i]);
503  }
504  for (i = 0; i < filter->nb_outputs; i++) {
505  free_link(filter->outputs[i]);
506  }
507 
508  if (filter->filter->priv_class)
509  av_opt_free(filter->priv);
510 
511  av_freep(&filter->name);
512  av_freep(&filter->input_pads);
513  av_freep(&filter->output_pads);
514  av_freep(&filter->inputs);
515  av_freep(&filter->outputs);
516  av_freep(&filter->priv);
517  av_freep(&filter->internal);
518  av_free(filter);
519 }
520 
521 /* process a list of value1:value2:..., each value corresponding
522  * to subsequent AVOption, in the order they are declared */
524  const char *args)
525 {
526  const AVOption *o = NULL;
527  const char *p = args;
528  char *val;
529 
530  while (*p) {
531  o = av_opt_next(ctx->priv, o);
532  if (!o) {
533  av_log(ctx, AV_LOG_ERROR, "More options provided than "
534  "this filter supports.\n");
535  return AVERROR(EINVAL);
536  }
537  if (o->type == AV_OPT_TYPE_CONST)
538  continue;
539 
540  val = av_get_token(&p, ":");
541  if (!val)
542  return AVERROR(ENOMEM);
543 
544  av_dict_set(options, o->name, val, 0);
545 
546  av_freep(&val);
547  if (*p)
548  p++;
549  }
550 
551  return 0;
552 }
553 
554 #if FF_API_AVFILTER_INIT_FILTER
555 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
556 {
557  return avfilter_init_str(filter, args);
558 }
559 #endif
560 
562 {
563  int ret = 0;
564 
565  ret = av_opt_set_dict(ctx, options);
566  if (ret < 0) {
567  av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
568  return ret;
569  }
570 
573  ctx->graph->internal->thread_execute) {
576  } else {
577  ctx->thread_type = 0;
578  }
579 
580  if (ctx->filter->priv_class) {
581  ret = av_opt_set_dict(ctx->priv, options);
582  if (ret < 0) {
583  av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n");
584  return ret;
585  }
586  }
587 
588  if (ctx->filter->init)
589  ret = ctx->filter->init(ctx);
590  else if (ctx->filter->init_dict)
591  ret = ctx->filter->init_dict(ctx, options);
592 
593  return ret;
594 }
595 
596 int avfilter_init_str(AVFilterContext *filter, const char *args)
597 {
600  int ret = 0;
601 
602  if (args && *args) {
603  if (!filter->filter->priv_class) {
604  av_log(filter, AV_LOG_ERROR, "This filter does not take any "
605  "options, but options were provided: %s.\n", args);
606  return AVERROR(EINVAL);
607  }
608 
609 #if FF_API_OLD_FILTER_OPTS
610  if (!strcmp(filter->filter->name, "scale") &&
611  strchr(args, ':') && strchr(args, ':') < strchr(args, '=')) {
612  /* old w:h:flags=<flags> syntax */
613  char *copy = av_strdup(args);
614  char *p;
615 
616  av_log(filter, AV_LOG_WARNING, "The <w>:<h>:flags=<flags> option "
617  "syntax is deprecated. Use either <w>:<h>:<flags> or "
618  "w=<w>:h=<h>:flags=<flags>.\n");
619 
620  if (!copy) {
621  ret = AVERROR(ENOMEM);
622  goto fail;
623  }
624 
625  p = strrchr(copy, ':');
626  if (p) {
627  *p++ = 0;
628  ret = av_dict_parse_string(&options, p, "=", ":", 0);
629  }
630  if (ret >= 0)
631  ret = process_unnamed_options(filter, &options, copy);
632  av_freep(&copy);
633 
634  if (ret < 0)
635  goto fail;
636  } else
637 #endif
638 
639  if (strchr(args, '=')) {
640  /* assume a list of key1=value1:key2=value2:... */
641  ret = av_dict_parse_string(&options, args, "=", ":", 0);
642  if (ret < 0)
643  goto fail;
644 #if FF_API_OLD_FILTER_OPTS
645  } else if (!strcmp(filter->filter->name, "format") ||
646  !strcmp(filter->filter->name, "noformat") ||
647  !strcmp(filter->filter->name, "frei0r") ||
648  !strcmp(filter->filter->name, "frei0r_src") ||
649  !strcmp(filter->filter->name, "ocv")) {
650  /* a hack for compatibility with the old syntax
651  * replace colons with |s */
652  char *copy = av_strdup(args);
653  char *p = copy;
654  int nb_leading = 0; // number of leading colons to skip
655 
656  if (!copy) {
657  ret = AVERROR(ENOMEM);
658  goto fail;
659  }
660 
661  if (!strcmp(filter->filter->name, "frei0r") ||
662  !strcmp(filter->filter->name, "ocv"))
663  nb_leading = 1;
664  else if (!strcmp(filter->filter->name, "frei0r_src"))
665  nb_leading = 3;
666 
667  while (nb_leading--) {
668  p = strchr(p, ':');
669  if (!p) {
670  p = copy + strlen(copy);
671  break;
672  }
673  p++;
674  }
675 
676  if (strchr(p, ':')) {
677  av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
678  "'|' to separate the list items.\n");
679  }
680 
681  while ((p = strchr(p, ':')))
682  *p++ = '|';
683 
684  ret = process_unnamed_options(filter, &options, copy);
685  av_freep(&copy);
686 
687  if (ret < 0)
688  goto fail;
689 #endif
690  } else {
691  ret = process_unnamed_options(filter, &options, args);
692  if (ret < 0)
693  goto fail;
694  }
695  }
696 
697  ret = avfilter_init_dict(filter, &options);
698  if (ret < 0)
699  goto fail;
700 
701  if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
702  av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
704  goto fail;
705  }
706 
707 fail:
708  av_dict_free(&options);
709 
710  return ret;
711 }
712 
713 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
714 {
715  return pads[pad_idx].name;
716 }
717 
718 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
719 {
720  return pads[pad_idx].type;
721 }
722 
723 static int default_filter_frame(AVFilterLink *link, AVFrame *frame)
724 {
725  return ff_filter_frame(link->dst->outputs[0], frame);
726 }
727 
729 {
730  int (*filter_frame)(AVFilterLink *, AVFrame *);
731  AVFilterPad *dst = link->dstpad;
732  AVFrame *out = NULL;
733  int ret;
734 
736  ff_dlog_link(NULL, link, 1);
737 
738  if (!(filter_frame = dst->filter_frame))
740 
741  /* copy the frame if needed */
742  if (dst->needs_writable && !av_frame_is_writable(frame)) {
743  av_log(link->dst, AV_LOG_DEBUG, "Copying data in avfilter.\n");
744 
745  switch (link->type) {
746  case AVMEDIA_TYPE_VIDEO:
747  out = ff_get_video_buffer(link, link->w, link->h);
748  break;
749  case AVMEDIA_TYPE_AUDIO:
750  out = ff_get_audio_buffer(link, frame->nb_samples);
751  break;
752  default:
753  ret = AVERROR(EINVAL);
754  goto fail;
755  }
756  if (!out) {
757  ret = AVERROR(ENOMEM);
758  goto fail;
759  }
760 
761  ret = av_frame_copy_props(out, frame);
762  if (ret < 0)
763  goto fail;
764 
765  switch (link->type) {
766  case AVMEDIA_TYPE_VIDEO:
767  av_image_copy(out->data, out->linesize, frame->data, frame->linesize,
768  frame->format, frame->width, frame->height);
769  break;
770  case AVMEDIA_TYPE_AUDIO:
772  0, 0, frame->nb_samples,
774  frame->format);
775  break;
776  default:
777  ret = AVERROR(EINVAL);
778  goto fail;
779  }
780 
781  av_frame_free(&frame);
782  } else
783  out = frame;
784 
785  return filter_frame(link, out);
786 
787 fail:
788  av_frame_free(&out);
789  av_frame_free(&frame);
790  return ret;
791 }
792 
794 {
795  return &avfilter_class;
796 }
int(* poll_frame)(AVFilterLink *link)
Frame poll callback.
Definition: internal.h:86
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
Definition: avfilter.c:390
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
int thread_type
Type of multithreading allowed for filters in this graph.
Definition: avfilter.h:969
static int default_filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: avfilter.c:723
AVOption.
Definition: opt.h:234
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:491
static const char * filter_name(void *p)
Definition: avfilter.c:330
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
Main libavfilter public API header.
int(* init)(AVFilterContext *ctx)
Filter initialization function.
Definition: avfilter.h:495
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:325
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:544
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:718
int num
numerator
Definition: rational.h:44
#define LIBAV_CONFIGURATION
Definition: config.h:4
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:47
#define LIBAVFILTER_VERSION_INT
Definition: version.h:36
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
int thread_type
Type of multithreading being allowed/used.
Definition: avfilter.h:604
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
Definition: avfilter.h:558
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:586
const char * name
Pad name.
Definition: internal.h:42
int priv_size
size of private data to allocate for the filter
Definition: avfilter.h:546
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:571
char * name
name of this filter instance
Definition: avfilter.h:568
const char * name
Definition: opt.h:235
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:728
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:75
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:577
void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
Definition: avfilter.c:220
const char * avfilter_license(void)
Return the libavfilter license.
Definition: avfilter.c:48
uint8_t
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: internal.h:95
AVOptions.
const struct AVOption * option
a pointer to the first option specified in the class if any or NULL
Definition: log.h:51
const char * name
int flags
A combination of AVFILTER_FLAG_*.
Definition: avfilter.h:464
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
int avfilter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:145
const AVFilter * avfilter_next(const AVFilter *prev)
Iterate over all registered filters.
Definition: avfilter.c:302
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
Definition: avfilter.h:520
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
Definition: lzo.c:79
static void free_link(AVFilterLink *link)
Definition: avfilter.c:472
#define r
Definition: input.c:51
const OptionDef options[]
Definition: avconv_opt.c:2183
A filter pad used for either input or output.
Definition: internal.h:36
static const AVClass avfilter_class
Definition: avfilter.c:368
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:570
int width
width and height of the video frame
Definition: frame.h:174
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Before After |formats |<------—.
Definition: formats.c:331
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
int( avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A function pointer passed to the AVFilterGraph::execute callback to be executed multiple times...
Definition: avfilter.h:923
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:57
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
unsigned nb_outputs
number of output pads
Definition: avfilter.h:582
unsigned avfilter_version(void)
Return the LIBAVFILTER_VERSION_INT constant.
Definition: avfilter.c:38
void * priv
private data for use by the filter
Definition: avfilter.h:584
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:415
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: internal.h:75
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:170
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
const AVOption * av_opt_next(void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:37
int(* init_dict)(AVFilterContext *ctx, AVDictionary **options)
Should be set instead of init by the filters that want to pass a dictionary of AVOptions to nested co...
Definition: avfilter.h:508
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
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:47
#define LIBAV_LICENSE
Definition: config.h:5
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:267
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:121
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:381
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:278
common internal API header
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
static void * filter_child_next(void *obj, void *prev)
Definition: avfilter.c:336
audio channel layout utility functions
unsigned nb_inputs
number of input pads
Definition: avfilter.h:575
#define FFMIN(a, b)
Definition: common.h:57
static AVFilter * first_filter
Definition: avfilter.c:273
static const AVOption avfilter_options[]
Definition: avfilter.c:361
int needs_writable
The filter expects writable frames from its input link, duplicating data buffers if needed...
Definition: internal.h:127
static int process_unnamed_options(AVFilterContext *ctx, AVDictionary **options, const char *args)
Definition: avfilter.c:523
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:596
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:441
const AVClass * avfilter_get_class(void)
Definition: avfilter.c:793
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:108
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:186
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add to a dictionary.
Definition: dict.c:147
NULL
Definition: eval.c:55
const AVClass * priv_class
A class for the private data, used to declare filter private AVOptions.
Definition: avfilter.h:459
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:240
AVFilterGraphInternal * internal
Opaque object for libavfilter internal use.
Definition: avfilter.h:981
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:309
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:677
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:213
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:68
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:307
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:187
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:68
Describe the class of an AVClass context structure.
Definition: log.h:33
Filter definition.
Definition: avfilter.h:421
rational number numerator/denominator
Definition: rational.h:43
struct AVFilter * next
Used by the filter registration system.
Definition: avfilter.h:552
AVMediaType
Definition: avutil.h:185
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:302
const char * name
Filter name.
Definition: avfilter.h:425
const char * avfilter_configuration(void)
Return the libavfilter build-time configuration.
Definition: avfilter.c:43
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:713
#define FLAGS
Definition: avfilter.c:360
#define LICENSE_PREFIX
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_amix.c:459
#define OFFSET(x)
Definition: avfilter.c:359
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:609
static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:377
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
Definition: avfilter.c:561
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:657
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:76
common internal and external API header
rational numbers
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
static int request_frame(AVFilterLink *outlink)
Definition: af_amix.c:392
char * key
Definition: dict.h:75
int den
denominator
Definition: rational.h:45
avfilter_execute_func * execute
Definition: internal.h:137
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
Definition: avfiltergraph.c:89
avfilter_execute_func * thread_execute
Definition: internal.h:133
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:56
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
int avfilter_register(AVFilter *filter)
Register a filter.
Definition: avfilter.c:292
enum AVOptionType type
Definition: opt.h:248
const AVClass * av_class
needed for av_log()
Definition: avfilter.h:564
An instance of a filter.
Definition: avfilter.h:563
int avfilter_pad_count(const AVFilterPad *pads)
Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
Definition: avfilter.c:318
#define FF_DPRINTF_START(ctx, func)
Definition: internal.h:148
int height
Definition: frame.h:174
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:449
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:111
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:62
void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, AVFilterPad **pads, AVFilterLink ***links, AVFilterPad *newpad)
Insert a new pad.
Definition: avfilter.c:54
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:244
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:1540
static const AVClass * filter_child_class_next(const AVClass *prev)
Definition: avfilter.c:344
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:169
int ff_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
Definition: avfilter.c:255
float min
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:179
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:566
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.