FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vf_frei0r.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Stefano Sabatini
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file
22  * frei0r wrapper
23  */
24 
25 #include <dlfcn.h>
26 #include <frei0r.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include "config.h"
31 #include "libavutil/avstring.h"
32 #include "libavutil/common.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/mathematics.h"
36 #include "libavutil/mem.h"
37 #include "libavutil/opt.h"
38 #include "libavutil/parseutils.h"
39 #include "avfilter.h"
40 #include "formats.h"
41 #include "internal.h"
42 #include "video.h"
43 
44 typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height);
45 typedef void (*f0r_destruct_f)(f0r_instance_t instance);
46 typedef void (*f0r_deinit_f)(void);
47 typedef int (*f0r_init_f)(void);
48 typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info);
49 typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index);
50 typedef void (*f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe);
51 typedef void (*f0r_update2_f)(f0r_instance_t instance, double time, const uint32_t *inframe1, const uint32_t *inframe2, const uint32_t *inframe3, uint32_t *outframe);
52 typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
53 typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
54 
55 typedef struct Frei0rContext {
56  const AVClass *class;
58  void *dl_handle; /* dynamic library handle */
59  f0r_instance_t instance;
60  f0r_plugin_info_t plugin_info;
61 
68 
69  char *dl_name;
70  char *params;
72 
73  /* only used by the source */
74  int w, h;
76  uint64_t pts;
78 
79 static void *load_sym(AVFilterContext *ctx, const char *sym_name)
80 {
81  Frei0rContext *s = ctx->priv;
82  void *sym = dlsym(s->dl_handle, sym_name);
83  if (!sym)
84  av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module.\n", sym_name);
85  return sym;
86 }
87 
88 static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
89 {
90  Frei0rContext *s = ctx->priv;
91  union {
92  double d;
93  f0r_param_color_t col;
94  f0r_param_position_t pos;
95  } val;
96  char *tail;
97  uint8_t rgba[4];
98 
99  switch (info.type) {
100  case F0R_PARAM_BOOL:
101  if (!strcmp(param, "y")) val.d = 1.0;
102  else if (!strcmp(param, "n")) val.d = 0.0;
103  else goto fail;
104  break;
105 
106  case F0R_PARAM_DOUBLE:
107  val.d = strtod(param, &tail);
108  if (*tail || val.d == HUGE_VAL)
109  goto fail;
110  break;
111 
112  case F0R_PARAM_COLOR:
113  if (sscanf(param, "%f/%f/%f", &val.col.r, &val.col.g, &val.col.b) != 3) {
114  if (av_parse_color(rgba, param, -1, ctx) < 0)
115  goto fail;
116  val.col.r = rgba[0] / 255.0;
117  val.col.g = rgba[1] / 255.0;
118  val.col.b = rgba[2] / 255.0;
119  }
120  break;
121 
122  case F0R_PARAM_POSITION:
123  if (sscanf(param, "%lf/%lf", &val.pos.x, &val.pos.y) != 2)
124  goto fail;
125  break;
126  }
127 
128  s->set_param_value(s->instance, &val, index);
129  return 0;
130 
131 fail:
132  av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'.\n",
133  param, info.name);
134  return AVERROR(EINVAL);
135 }
136 
137 static int set_params(AVFilterContext *ctx, const char *params)
138 {
139  Frei0rContext *s = ctx->priv;
140  int i;
141 
142  if (!params)
143  return 0;
144 
145  for (i = 0; i < s->plugin_info.num_params; i++) {
146  f0r_param_info_t info;
147  char *param;
148  int ret;
149 
150  s->get_param_info(&info, i);
151 
152  if (*params) {
153  if (!(param = av_get_token(&params, "|")))
154  return AVERROR(ENOMEM);
155  if (*params)
156  params++; /* skip ':' */
157  ret = set_param(ctx, info, i, param);
158  av_free(param);
159  if (ret < 0)
160  return ret;
161  }
162 
163  av_log(ctx, AV_LOG_VERBOSE,
164  "idx:%d name:'%s' type:%s explanation:'%s' ",
165  i, info.name,
166  info.type == F0R_PARAM_BOOL ? "bool" :
167  info.type == F0R_PARAM_DOUBLE ? "double" :
168  info.type == F0R_PARAM_COLOR ? "color" :
169  info.type == F0R_PARAM_POSITION ? "position" :
170  info.type == F0R_PARAM_STRING ? "string" : "unknown",
171  info.explanation);
172 
173 #ifdef DEBUG
174  av_log(ctx, AV_LOG_DEBUG, "value:");
175  switch (info.type) {
176  void *v;
177  double d;
178  char str[128];
179  f0r_param_color_t col;
180  f0r_param_position_t pos;
181 
182  case F0R_PARAM_BOOL:
183  v = &d;
184  s->get_param_value(s->instance, v, i);
185  av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
186  break;
187  case F0R_PARAM_DOUBLE:
188  v = &d;
189  s->get_param_value(s->instance, v, i);
190  av_log(ctx, AV_LOG_DEBUG, "%f", d);
191  break;
192  case F0R_PARAM_COLOR:
193  v = &col;
194  s->get_param_value(s->instance, v, i);
195  av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
196  break;
197  case F0R_PARAM_POSITION:
198  v = &pos;
199  s->get_param_value(s->instance, v, i);
200  av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
201  break;
202  default: /* F0R_PARAM_STRING */
203  v = str;
204  s->get_param_value(s->instance, v, i);
205  av_log(ctx, AV_LOG_DEBUG, "'%s'", str);
206  break;
207  }
208 #endif
209  av_log(ctx, AV_LOG_VERBOSE, ".\n");
210  }
211 
212  return 0;
213 }
214 
215 static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
216 {
217  char *path = av_asprintf("%s%s%s", prefix, name, SLIBSUF);
218  if (!path)
219  return AVERROR(ENOMEM);
220  av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'.\n", path);
221  *handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
222  av_free(path);
223  return 0;
224 }
225 
227  const char *dl_name, int type)
228 {
229  Frei0rContext *s = ctx->priv;
230  f0r_init_f f0r_init;
231  f0r_get_plugin_info_f f0r_get_plugin_info;
232  f0r_plugin_info_t *pi;
233  char *path;
234  int ret = 0;
235  int i;
236  static const char* const frei0r_pathlist[] = {
237  "/usr/local/lib/frei0r-1/",
238  "/usr/lib/frei0r-1/",
239  "/usr/local/lib64/frei0r-1/",
240  "/usr/lib64/frei0r-1/"
241  };
242 
243  if (!dl_name) {
244  av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
245  return AVERROR(EINVAL);
246  }
247 
248  /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
249  if ((path = av_strdup(getenv("FREI0R_PATH")))) {
250 #ifdef _WIN32
251  const char *separator = ";";
252 #else
253  const char *separator = ":";
254 #endif
255  char *p, *ptr = NULL;
256  for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) {
257  /* add additional trailing slash in case it is missing */
258  char *p1 = av_asprintf("%s/", p);
259  if (!p1) {
260  ret = AVERROR(ENOMEM);
261  goto check_path_end;
262  }
263  ret = load_path(ctx, &s->dl_handle, p1, dl_name);
264  av_free(p1);
265  if (ret < 0)
266  goto check_path_end;
267  if (s->dl_handle)
268  break;
269  }
270 
271  check_path_end:
272  av_free(path);
273  if (ret < 0)
274  return ret;
275  }
276  if (!s->dl_handle && (path = getenv("HOME"))) {
277  char *prefix = av_asprintf("%s/.frei0r-1/lib/", path);
278  if (!prefix)
279  return AVERROR(ENOMEM);
280  ret = load_path(ctx, &s->dl_handle, prefix, dl_name);
281  av_free(prefix);
282  if (ret < 0)
283  return ret;
284  }
285  for (i = 0; !s->dl_handle && i < FF_ARRAY_ELEMS(frei0r_pathlist); i++) {
286  ret = load_path(ctx, &s->dl_handle, frei0r_pathlist[i], dl_name);
287  if (ret < 0)
288  return ret;
289  }
290  if (!s->dl_handle) {
291  av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'.\n", dl_name);
292  return AVERROR(EINVAL);
293  }
294 
295  if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
296  !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
297  !(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
298  !(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
299  !(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
300  !(s->update = load_sym(ctx, "f0r_update" )) ||
301  !(s->construct = load_sym(ctx, "f0r_construct" )) ||
302  !(s->destruct = load_sym(ctx, "f0r_destruct" )) ||
303  !(s->deinit = load_sym(ctx, "f0r_deinit" )))
304  return AVERROR(EINVAL);
305 
306  if (f0r_init() < 0) {
307  av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module.\n");
308  return AVERROR(EINVAL);
309  }
310 
311  f0r_get_plugin_info(&s->plugin_info);
312  pi = &s->plugin_info;
313  if (pi->plugin_type != type) {
314  av_log(ctx, AV_LOG_ERROR,
315  "Invalid type '%s' for this plugin\n",
316  pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
317  pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
318  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
319  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
320  return AVERROR(EINVAL);
321  }
322 
323  av_log(ctx, AV_LOG_VERBOSE,
324  "name:%s author:'%s' explanation:'%s' color_model:%s "
325  "frei0r_version:%d version:%d.%d num_params:%d\n",
326  pi->name, pi->author, pi->explanation,
327  pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
328  pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
329  pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
330  pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
331 
332  return 0;
333 }
334 
336 {
337  Frei0rContext *s = ctx->priv;
338 
339  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_FILTER);
340 }
341 
342 static av_cold void uninit(AVFilterContext *ctx)
343 {
344  Frei0rContext *s = ctx->priv;
345 
346  if (s->destruct && s->instance)
347  s->destruct(s->instance);
348  if (s->deinit)
349  s->deinit();
350  if (s->dl_handle)
351  dlclose(s->dl_handle);
352 }
353 
354 static int config_input_props(AVFilterLink *inlink)
355 {
356  AVFilterContext *ctx = inlink->dst;
357  Frei0rContext *s = ctx->priv;
358 
359  if (s->destruct && s->instance)
360  s->destruct(s->instance);
361  if (!(s->instance = s->construct(inlink->w, inlink->h))) {
362  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
363  return AVERROR(EINVAL);
364  }
365 
366  return set_params(ctx, s->params);
367 }
368 
370 {
371  Frei0rContext *s = ctx->priv;
373 
374  if (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
375  ff_add_format(&formats, AV_PIX_FMT_BGRA);
376  } else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
377  ff_add_format(&formats, AV_PIX_FMT_RGBA);
378  } else { /* F0R_COLOR_MODEL_PACKED32 */
379  static const enum AVPixelFormat pix_fmts[] = {
381  };
382  formats = ff_make_format_list(pix_fmts);
383  }
384 
385  if (!formats)
386  return AVERROR(ENOMEM);
387 
388  ff_set_common_formats(ctx, formats);
389  return 0;
390 }
391 
392 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
393 {
394  Frei0rContext *s = inlink->dst->priv;
395  AVFilterLink *outlink = inlink->dst->outputs[0];
396  AVFrame *out;
397 
398  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
399  if (!out) {
400  av_frame_free(&in);
401  return AVERROR(ENOMEM);
402  }
403  av_frame_copy_props(out, in);
404 
405  s->update(s->instance, in->pts * av_q2d(inlink->time_base) * 1000,
406  (const uint32_t *)in->data[0],
407  (uint32_t *)out->data[0]);
408 
409  av_frame_free(&in);
410 
411  return ff_filter_frame(outlink, out);
412 }
413 
414 #define OFFSET(x) offsetof(Frei0rContext, x)
415 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
416 static const AVOption frei0r_options[] = {
417  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
418  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
419  { NULL }
420 };
421 
422 AVFILTER_DEFINE_CLASS(frei0r);
423 
425  {
426  .name = "default",
427  .type = AVMEDIA_TYPE_VIDEO,
428  .config_props = config_input_props,
429  .filter_frame = filter_frame,
430  },
431  { NULL }
432 };
433 
435  {
436  .name = "default",
437  .type = AVMEDIA_TYPE_VIDEO,
438  },
439  { NULL }
440 };
441 
443  .name = "frei0r",
444  .description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
445  .query_formats = query_formats,
446  .init = filter_init,
447  .uninit = uninit,
448  .priv_size = sizeof(Frei0rContext),
449  .priv_class = &frei0r_class,
450  .inputs = avfilter_vf_frei0r_inputs,
451  .outputs = avfilter_vf_frei0r_outputs,
452 };
453 
455 {
456  Frei0rContext *s = ctx->priv;
457 
458  s->time_base.num = s->framerate.den;
459  s->time_base.den = s->framerate.num;
460 
461  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_SOURCE);
462 }
463 
464 static int source_config_props(AVFilterLink *outlink)
465 {
466  AVFilterContext *ctx = outlink->src;
467  Frei0rContext *s = ctx->priv;
468 
469  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
470  return AVERROR(EINVAL);
471  outlink->w = s->w;
472  outlink->h = s->h;
473  outlink->time_base = s->time_base;
474  outlink->frame_rate = av_inv_q(s->time_base);
475  outlink->sample_aspect_ratio = (AVRational){1,1};
476 
477  if (s->destruct && s->instance)
478  s->destruct(s->instance);
479  if (!(s->instance = s->construct(outlink->w, outlink->h))) {
480  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
481  return AVERROR(EINVAL);
482  }
483  if (!s->params) {
484  av_log(ctx, AV_LOG_ERROR, "frei0r filter parameters not set.\n");
485  return AVERROR(EINVAL);
486  }
487 
488  return set_params(ctx, s->params);
489 }
490 
491 static int source_request_frame(AVFilterLink *outlink)
492 {
493  Frei0rContext *s = outlink->src->priv;
494  AVFrame *frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
495 
496  if (!frame)
497  return AVERROR(ENOMEM);
498 
499  frame->sample_aspect_ratio = (AVRational) {1, 1};
500  frame->pts = s->pts++;
501 
502  s->update(s->instance, av_rescale_q(frame->pts, s->time_base, (AVRational){1,1000}),
503  NULL, (uint32_t *)frame->data[0]);
504 
505  return ff_filter_frame(outlink, frame);
506 }
507 
508 static const AVOption frei0r_src_options[] = {
509  { "size", "Dimensions of the generated video.", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str = "320x240" }, .flags = FLAGS },
510  { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, .flags = FLAGS },
511  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
512  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
513  { NULL },
514 };
515 
516 AVFILTER_DEFINE_CLASS(frei0r_src);
517 
519  {
520  .name = "default",
521  .type = AVMEDIA_TYPE_VIDEO,
522  .request_frame = source_request_frame,
523  .config_props = source_config_props
524  },
525  { NULL }
526 };
527 
529  .name = "frei0r_src",
530  .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
531  .priv_size = sizeof(Frei0rContext),
532  .priv_class = &frei0r_src_class,
533  .init = source_init,
534  .uninit = uninit,
536  .inputs = NULL,
537  .outputs = avfilter_vsrc_frei0r_src_outputs,
538 };
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:672
float v
const char * s
Definition: avisynth_c.h:669
static const AVOption frei0r_src_options[]
Definition: vf_frei0r.c:508
static av_cold int filter_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:335
#define FLAGS
Definition: vf_frei0r.c:415
AVFilter ff_vf_frei0r
Definition: vf_frei0r.c:442
char * dl_name
Definition: vf_frei0r.c:69
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
AVOption.
Definition: opt.h:255
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:246
Main libavfilter public API header.
memory handling functions
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int num
numerator
Definition: rational.h:44
f0r_plugin_info_t plugin_info
Definition: vf_frei0r.c:60
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-> in
#define FF_ARRAY_ELEMS(a)
char * params
Definition: vf_frei0r.c:70
static enum AVSampleFormat formats[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
static const AVFilterPad avfilter_vf_frei0r_outputs[]
Definition: vf_frei0r.c:434
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:294
const char * name
Pad name.
Definition: internal.h:67
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
static const AVOption frei0r_options[]
Definition: vf_frei0r.c:416
f0r_get_param_value_f get_param_value
Definition: vf_frei0r.c:63
void(* f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Definition: vf_frei0r.c:53
uint8_t
#define av_cold
Definition: attributes.h:74
AVOptions.
static int query_formats(AVFilterContext *ctx)
Definition: vf_frei0r.c:369
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:249
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_frei0r.c:342
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
static AVFrame * frame
double strtod(const char *, char **)
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:80
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:191
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
Definition: vf_frei0r.c:226
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:539
#define av_log(a,...)
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:344
A filter pad used for either input or output.
Definition: internal.h:61
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:147
AVFILTER_DEFINE_CLASS(frei0r)
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
Definition: vf_frei0r.c:215
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
Definition: vf_frei0r.c:48
AVRational time_base
Definition: vf_frei0r.c:75
f0r_instance_t(* f0r_construct_f)(unsigned int width, unsigned int height)
Definition: vf_frei0r.c:44
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
#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:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:196
GLenum GLint * params
Definition: opengl_enc.c:114
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
Definition: vf_frei0r.c:518
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:334
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
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:149
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
AVFilter ff_vsrc_frei0r_src
Definition: vf_frei0r.c:528
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
void * dl_handle
Definition: vf_frei0r.c:58
common internal API header
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:241
uint64_t pts
Definition: vf_frei0r.c:76
ret
Definition: avfilter.c:974
static int source_config_props(AVFilterLink *outlink)
Definition: vf_frei0r.c:464
f0r_get_param_info_f get_param_info
Definition: vf_frei0r.c:62
void(* f0r_deinit_f)(void)
Definition: vf_frei0r.c:46
f0r_destruct_f destruct
Definition: vf_frei0r.c:66
f0r_update_f update
Definition: vf_frei0r.c:57
static int config_input_props(AVFilterLink *inlink)
Definition: vf_frei0r.c:354
static int set_params(AVFilterContext *ctx, const char *params)
Definition: vf_frei0r.c:137
#define SLIBSUF
Definition: config.h:14
void(* f0r_update2_f)(f0r_instance_t instance, double time, const uint32_t *inframe1, const uint32_t *inframe2, const uint32_t *inframe3, uint32_t *outframe)
Definition: vf_frei0r.c:51
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:265
AVRational framerate
Definition: vf_frei0r.c:71
f0r_construct_f construct
Definition: vf_frei0r.c:65
static const AVFilterPad avfilter_vf_frei0r_inputs[]
Definition: vf_frei0r.c:424
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:244
GLint GLenum type
Definition: opengl_enc.c:105
BYTE int const BYTE int int int height
Definition: avisynth_c.h:714
#define OFFSET(x)
Definition: vf_frei0r.c:414
void(* f0r_get_param_info_f)(f0r_param_info_t *info, int param_index)
Definition: vf_frei0r.c:49
f0r_instance_t instance
Definition: vf_frei0r.c:59
Describe the class of an AVClass context structure.
Definition: log.h:66
Filter definition.
Definition: avfilter.h:470
int index
Definition: gxfenc.c:89
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:237
rational number numerator/denominator
Definition: rational.h:43
void(* f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Definition: vf_frei0r.c:52
offset must point to AVRational
Definition: opt.h:235
const char * name
Filter name.
Definition: avfilter.h:474
offset must point to two consecutive integers
Definition: opt.h:232
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
void(* f0r_destruct_f)(f0r_instance_t instance)
Definition: vf_frei0r.c:45
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:133
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:174
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:184
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
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_frei0r.c:392
int(* f0r_init_f)(void)
Definition: vf_frei0r.c:47
common internal and external API header
f0r_set_param_value_f set_param_value
Definition: vf_frei0r.c:64
static void * load_sym(AVFilterContext *ctx, const char *sym_name)
Definition: vf_frei0r.c:79
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
Definition: vf_frei0r.c:88
int den
denominator
Definition: rational.h:45
#define av_free(p)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
void(* f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe)
Definition: vf_frei0r.c:50
An instance of a filter.
Definition: avfilter.h:633
static int source_request_frame(AVFilterLink *outlink)
Definition: vf_frei0r.c:491
f0r_deinit_f deinit
Definition: vf_frei0r.c:67
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
static av_cold int source_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:454
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:463
const char * name
Definition: opengl_enc.c:103
static int width