FFmpeg  2.1.1
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/imgutils.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/parseutils.h"
38 #include "avfilter.h"
39 #include "formats.h"
40 #include "internal.h"
41 #include "video.h"
42 
43 typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height);
44 typedef void (*f0r_destruct_f)(f0r_instance_t instance);
45 typedef void (*f0r_deinit_f)(void);
46 typedef int (*f0r_init_f)(void);
47 typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info);
48 typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index);
49 typedef void (*f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe);
50 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);
51 typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
52 typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
53 
54 typedef struct Frei0rContext {
55  const AVClass *class;
57  void *dl_handle; /* dynamic library handle */
58  f0r_instance_t instance;
59  f0r_plugin_info_t plugin_info;
60 
67 
68  char *dl_name;
69  char *params;
71 
72  /* only used by the source */
73  int w, h;
75  uint64_t pts;
77 
78 static void *load_sym(AVFilterContext *ctx, const char *sym_name)
79 {
80  Frei0rContext *s = ctx->priv;
81  void *sym = dlsym(s->dl_handle, sym_name);
82  if (!sym)
83  av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module\n", sym_name);
84  return sym;
85 }
86 
87 static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
88 {
89  Frei0rContext *s = ctx->priv;
90  union {
91  double d;
92  f0r_param_color_t col;
93  f0r_param_position_t pos;
94  } val;
95  char *tail;
96  uint8_t rgba[4];
97 
98  switch (info.type) {
99  case F0R_PARAM_BOOL:
100  if (!strcmp(param, "y")) val.d = 1.0;
101  else if (!strcmp(param, "n")) val.d = 0.0;
102  else goto fail;
103  break;
104 
105  case F0R_PARAM_DOUBLE:
106  val.d = strtod(param, &tail);
107  if (*tail || val.d == HUGE_VAL)
108  goto fail;
109  break;
110 
111  case F0R_PARAM_COLOR:
112  if (sscanf(param, "%f/%f/%f", &val.col.r, &val.col.g, &val.col.b) != 3) {
113  if (av_parse_color(rgba, param, -1, ctx) < 0)
114  goto fail;
115  val.col.r = rgba[0] / 255.0;
116  val.col.g = rgba[1] / 255.0;
117  val.col.b = rgba[2] / 255.0;
118  }
119  break;
120 
121  case F0R_PARAM_POSITION:
122  if (sscanf(param, "%lf/%lf", &val.pos.x, &val.pos.y) != 2)
123  goto fail;
124  break;
125  }
126 
127  s->set_param_value(s->instance, &val, index);
128  return 0;
129 
130 fail:
131  av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'\n",
132  param, info.name);
133  return AVERROR(EINVAL);
134 }
135 
136 static int set_params(AVFilterContext *ctx, const char *params)
137 {
138  Frei0rContext *s = ctx->priv;
139  int i;
140 
141  if (!params)
142  return 0;
143 
144  for (i = 0; i < s->plugin_info.num_params; i++) {
145  f0r_param_info_t info;
146  char *param;
147  int ret;
148 
149  s->get_param_info(&info, i);
150 
151  if (*params) {
152  if (!(param = av_get_token(&params, "|")))
153  return AVERROR(ENOMEM);
154  if (*params)
155  params++; /* skip ':' */
156  ret = set_param(ctx, info, i, param);
157  av_free(param);
158  if (ret < 0)
159  return ret;
160  }
161 
162  av_log(ctx, AV_LOG_VERBOSE,
163  "idx:%d name:'%s' type:%s explanation:'%s' ",
164  i, info.name,
165  info.type == F0R_PARAM_BOOL ? "bool" :
166  info.type == F0R_PARAM_DOUBLE ? "double" :
167  info.type == F0R_PARAM_COLOR ? "color" :
168  info.type == F0R_PARAM_POSITION ? "position" :
169  info.type == F0R_PARAM_STRING ? "string" : "unknown",
170  info.explanation);
171 
172 #ifdef DEBUG
173  av_log(ctx, AV_LOG_DEBUG, "value:");
174  switch (info.type) {
175  void *v;
176  double d;
177  char s[128];
178  f0r_param_color_t col;
179  f0r_param_position_t pos;
180 
181  case F0R_PARAM_BOOL:
182  v = &d;
183  s->get_param_value(s->instance, v, i);
184  av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
185  break;
186  case F0R_PARAM_DOUBLE:
187  v = &d;
188  s->get_param_value(s->instance, v, i);
189  av_log(ctx, AV_LOG_DEBUG, "%f", d);
190  break;
191  case F0R_PARAM_COLOR:
192  v = &col;
193  s->get_param_value(s->instance, v, i);
194  av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
195  break;
196  case F0R_PARAM_POSITION:
197  v = &pos;
198  s->get_param_value(s->instance, v, i);
199  av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
200  break;
201  default: /* F0R_PARAM_STRING */
202  v = s;
203  s->get_param_value(s->instance, v, i);
204  av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s);
205  break;
206  }
207 #endif
208  av_log(ctx, AV_LOG_VERBOSE, "\n");
209  }
210 
211  return 0;
212 }
213 
214 static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
215 {
216  char *path = av_asprintf("%s%s%s", prefix, name, SLIBSUF);
217  if (!path)
218  return AVERROR(ENOMEM);
219  av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'\n", path);
220  *handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
221  av_free(path);
222  return 0;
223 }
224 
226  const char *dl_name, int type)
227 {
228  Frei0rContext *s = ctx->priv;
229  f0r_init_f f0r_init;
230  f0r_get_plugin_info_f f0r_get_plugin_info;
231  f0r_plugin_info_t *pi;
232  char *path;
233  int ret = 0;
234 
235  if (!dl_name) {
236  av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
237  return AVERROR(EINVAL);
238  }
239 
240  /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
241  if ((path = av_strdup(getenv("FREI0R_PATH")))) {
242 #ifdef _WIN32
243  const char *separator = ";";
244 #else
245  const char *separator = ":";
246 #endif
247  char *p, *ptr = NULL;
248  for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) {
249  /* add additional trailing slash in case it is missing */
250  char *p1 = av_asprintf("%s/", p);
251  if (!p1) {
252  ret = AVERROR(ENOMEM);
253  goto check_path_end;
254  }
255  ret = load_path(ctx, &s->dl_handle, p1, dl_name);
256  av_free(p1);
257  if (ret < 0)
258  goto check_path_end;
259  if (s->dl_handle)
260  break;
261  }
262 
263  check_path_end:
264  av_free(path);
265  if (ret < 0)
266  return ret;
267  }
268  if (!s->dl_handle && (path = getenv("HOME"))) {
269  char *prefix = av_asprintf("%s/.frei0r-1/lib/", path);
270  if (!prefix)
271  return AVERROR(ENOMEM);
272  ret = load_path(ctx, &s->dl_handle, prefix, dl_name);
273  av_free(prefix);
274  if (ret < 0)
275  return ret;
276  }
277  if (!s->dl_handle) {
278  ret = load_path(ctx, &s->dl_handle, "/usr/local/lib/frei0r-1/", dl_name);
279  if (ret < 0)
280  return ret;
281  }
282  if (!s->dl_handle) {
283  ret = load_path(ctx, &s->dl_handle, "/usr/lib/frei0r-1/", dl_name);
284  if (ret < 0)
285  return ret;
286  }
287  if (!s->dl_handle) {
288  av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'\n", dl_name);
289  return AVERROR(EINVAL);
290  }
291 
292  if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
293  !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
294  !(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
295  !(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
296  !(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
297  !(s->update = load_sym(ctx, "f0r_update" )) ||
298  !(s->construct = load_sym(ctx, "f0r_construct" )) ||
299  !(s->destruct = load_sym(ctx, "f0r_destruct" )) ||
300  !(s->deinit = load_sym(ctx, "f0r_deinit" )))
301  return AVERROR(EINVAL);
302 
303  if (f0r_init() < 0) {
304  av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module\n");
305  return AVERROR(EINVAL);
306  }
307 
308  f0r_get_plugin_info(&s->plugin_info);
309  pi = &s->plugin_info;
310  if (pi->plugin_type != type) {
311  av_log(ctx, AV_LOG_ERROR,
312  "Invalid type '%s' for the plugin\n",
313  pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
314  pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
315  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
316  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
317  return AVERROR(EINVAL);
318  }
319 
320  av_log(ctx, AV_LOG_VERBOSE,
321  "name:%s author:'%s' explanation:'%s' color_model:%s "
322  "frei0r_version:%d version:%d.%d num_params:%d\n",
323  pi->name, pi->author, pi->explanation,
324  pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
325  pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
326  pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
327  pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
328 
329  return 0;
330 }
331 
333 {
334  Frei0rContext *s = ctx->priv;
335 
336  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_FILTER);
337 }
338 
339 static av_cold void uninit(AVFilterContext *ctx)
340 {
341  Frei0rContext *s = ctx->priv;
342 
343  if (s->destruct && s->instance)
344  s->destruct(s->instance);
345  if (s->deinit)
346  s->deinit();
347  if (s->dl_handle)
348  dlclose(s->dl_handle);
349 }
350 
351 static int config_input_props(AVFilterLink *inlink)
352 {
353  AVFilterContext *ctx = inlink->dst;
354  Frei0rContext *s = ctx->priv;
355 
356  if (s->destruct && s->instance)
357  s->destruct(s->instance);
358  if (!(s->instance = s->construct(inlink->w, inlink->h))) {
359  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
360  return AVERROR(EINVAL);
361  }
362 
363  return set_params(ctx, s->params);
364 }
365 
367 {
368  Frei0rContext *s = ctx->priv;
369  AVFilterFormats *formats = NULL;
370 
371  if (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
372  ff_add_format(&formats, AV_PIX_FMT_BGRA);
373  } else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
374  ff_add_format(&formats, AV_PIX_FMT_RGBA);
375  } else { /* F0R_COLOR_MODEL_PACKED32 */
376  static const enum AVPixelFormat pix_fmts[] = {
378  };
379  formats = ff_make_format_list(pix_fmts);
380  }
381 
382  if (!formats)
383  return AVERROR(ENOMEM);
384 
385  ff_set_common_formats(ctx, formats);
386  return 0;
387 }
388 
389 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
390 {
391  Frei0rContext *s = inlink->dst->priv;
392  AVFilterLink *outlink = inlink->dst->outputs[0];
393  AVFrame *out;
394 
395  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
396  if (!out) {
397  av_frame_free(&in);
398  return AVERROR(ENOMEM);
399  }
400  av_frame_copy_props(out, in);
401 
402  s->update(s->instance, in->pts * av_q2d(inlink->time_base) * 1000,
403  (const uint32_t *)in->data[0],
404  (uint32_t *)out->data[0]);
405 
406  av_frame_free(&in);
407 
408  return ff_filter_frame(outlink, out);
409 }
410 
411 #define OFFSET(x) offsetof(Frei0rContext, x)
412 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
413 static const AVOption frei0r_options[] = {
414  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
415  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
416  { NULL }
417 };
418 
419 AVFILTER_DEFINE_CLASS(frei0r);
420 
422  {
423  .name = "default",
424  .type = AVMEDIA_TYPE_VIDEO,
425  .config_props = config_input_props,
426  .filter_frame = filter_frame,
427  },
428  { NULL }
429 };
430 
432  {
433  .name = "default",
434  .type = AVMEDIA_TYPE_VIDEO,
435  },
436  { NULL }
437 };
438 
440  .name = "frei0r",
441  .description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
442  .query_formats = query_formats,
443  .init = filter_init,
444  .uninit = uninit,
445  .priv_size = sizeof(Frei0rContext),
446  .priv_class = &frei0r_class,
447  .inputs = avfilter_vf_frei0r_inputs,
448  .outputs = avfilter_vf_frei0r_outputs,
449 };
450 
452 {
453  Frei0rContext *s = ctx->priv;
454 
455  s->time_base.num = s->framerate.den;
456  s->time_base.den = s->framerate.num;
457 
458  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_SOURCE);
459 }
460 
461 static int source_config_props(AVFilterLink *outlink)
462 {
463  AVFilterContext *ctx = outlink->src;
464  Frei0rContext *s = ctx->priv;
465 
466  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
467  return AVERROR(EINVAL);
468  outlink->w = s->w;
469  outlink->h = s->h;
470  outlink->time_base = s->time_base;
471  outlink->sample_aspect_ratio = (AVRational){1,1};
472 
473  if (s->destruct && s->instance)
474  s->destruct(s->instance);
475  if (!(s->instance = s->construct(outlink->w, outlink->h))) {
476  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
477  return AVERROR(EINVAL);
478  }
479 
480  return set_params(ctx, s->params);
481 }
482 
483 static int source_request_frame(AVFilterLink *outlink)
484 {
485  Frei0rContext *s = outlink->src->priv;
486  AVFrame *frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
487 
488  if (!frame)
489  return AVERROR(ENOMEM);
490 
491  frame->sample_aspect_ratio = (AVRational) {1, 1};
492  frame->pts = s->pts++;
493 
494  s->update(s->instance, av_rescale_q(frame->pts, s->time_base, (AVRational){1,1000}),
495  NULL, (uint32_t *)frame->data[0]);
496 
497  return ff_filter_frame(outlink, frame);
498 }
499 
500 static const AVOption frei0r_src_options[] = {
501  { "size", "Dimensions of the generated video.", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str = "320x240" }, .flags = FLAGS },
502  { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, .flags = FLAGS },
503  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
504  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
505  { NULL },
506 };
507 
508 AVFILTER_DEFINE_CLASS(frei0r_src);
509 
511  {
512  .name = "default",
513  .type = AVMEDIA_TYPE_VIDEO,
514  .request_frame = source_request_frame,
515  .config_props = source_config_props
516  },
517  { NULL }
518 };
519 
521  .name = "frei0r_src",
522  .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
523  .priv_size = sizeof(Frei0rContext),
524  .priv_class = &frei0r_src_class,
525  .init = source_init,
526  .uninit = uninit,
528  .inputs = NULL,
529  .outputs = avfilter_vsrc_frei0r_src_outputs,
530 };
const char * name
Definition: avisynth_c.h:675
const char const char void * val
Definition: avisynth_c.h:671
float v
const char * s
Definition: avisynth_c.h:668
AVFilter avfilter_vsrc_frei0r_src
Definition: vf_frei0r.c:520
static const AVOption frei0r_src_options[]
Definition: vf_frei0r.c:500
static av_cold int filter_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:332
#define FLAGS
Definition: vf_frei0r.c:412
char * dl_name
Definition: vf_frei0r.c:68
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
AVOption.
Definition: opt.h:253
const char * name
Filter name.
Definition: avfilter.h:468
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
Definition: mem.c:256
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:59
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
char * params
Definition: vf_frei0r.c:69
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
Pixel format.
Definition: avcodec.h:4533
#define av_cold
Definition: avcodec.h:653
static const AVFilterPad avfilter_vf_frei0r_outputs[]
Definition: vf_frei0r.c:431
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:294
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: avcodec.h:4562
const char * name
Pad name.
Definition: internal.h:66
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:148
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
static const AVOption frei0r_options[]
Definition: vf_frei0r.c:413
f0r_get_param_value_f get_param_value
Definition: vf_frei0r.c:62
void(* f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Definition: vf_frei0r.c:52
uint8_t
static int query_formats(AVFilterContext *ctx)
Definition: vf_frei0r.c:366
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:182
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_frei0r.c:339
double strtod(const char *, char **)
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: avcodec.h:4564
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
Definition: vf_frei0r.c:225
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:531
static AVFrame * frame
Definition: demuxing.c:51
A filter pad used for either input or output.
Definition: internal.h:60
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
Definition: vf_frei0r.c:214
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
Definition: vf_frei0r.c:47
AVRational time_base
Definition: vf_frei0r.c:74
f0r_instance_t(* f0r_construct_f)(unsigned int width, unsigned int height)
Definition: vf_frei0r.c:43
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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 NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
Definition: vf_frei0r.c:510
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:330
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
void * dl_handle
Definition: vf_frei0r.c:57
goto fail
Definition: avfilter.c:963
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:231
uint64_t pts
Definition: vf_frei0r.c:75
ret
Definition: avfilter.c:961
static int source_config_props(AVFilterLink *outlink)
Definition: vf_frei0r.c:461
f0r_get_param_info_f get_param_info
Definition: vf_frei0r.c:61
void(* f0r_deinit_f)(void)
Definition: vf_frei0r.c:45
f0r_destruct_f destruct
Definition: vf_frei0r.c:65
f0r_update_f update
Definition: vf_frei0r.c:56
static int config_input_props(AVFilterLink *inlink)
Definition: vf_frei0r.c:351
size_t char * av_asprintf(const char *fmt,...) av_printf_format(1
Print arguments following specified format into a large enough auto allocated buffer.
static int set_params(AVFilterContext *ctx, const char *params)
Definition: vf_frei0r.c:136
Main libavfilter public API header.
#define SLIBSUF
Definition: config.h:12
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
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:50
static int width
Definition: utils.c:158
typedef void(RENAME(mix_any_func_type))
AVRational framerate
Definition: vf_frei0r.c:70
f0r_construct_f construct
Definition: vf_frei0r.c:64
static const AVFilterPad avfilter_vf_frei0r_inputs[]
Definition: vf_frei0r.c:421
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:177
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
#define OFFSET(x)
Definition: vf_frei0r.c:411
void(* f0r_get_param_info_f)(f0r_param_info_t *info, int param_index)
Definition: vf_frei0r.c:48
f0r_instance_t instance
Definition: vf_frei0r.c:58
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
int index
Definition: gxfenc.c:89
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
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:51
offset must point to AVRational
Definition: opt.h:233
offset must point to two consecutive integers
Definition: opt.h:230
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:343
#define type
void(* f0r_destruct_f)(f0r_instance_t instance)
Definition: vf_frei0r.c:44
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_frei0r.c:389
const char const char * params
Definition: avisynth_c.h:675
int(* f0r_init_f)(void)
Definition: vf_frei0r.c:46
f0r_set_param_value_f set_param_value
Definition: vf_frei0r.c:63
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:183
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: avcodec.h:4565
static void * load_sym(AVFilterContext *ctx, const char *sym_name)
Definition: vf_frei0r.c:78
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
Definition: vf_frei0r.c:87
int den
denominator
Definition: rational.h:45
AVFilter avfilter_vf_frei0r
Definition: vf_frei0r.c:439
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: avcodec.h:4563
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:49
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
static int source_request_frame(AVFilterLink *outlink)
Definition: vf_frei0r.c:483
f0r_deinit_f deinit
Definition: vf_frei0r.c:66
internal API functions
static av_cold int source_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:451
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107