Libav
vf_frei0r.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Stefano Sabatini
3  * This file is part of Libav.
4  *
5  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
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;
70  char *size;
71  char *framerate;
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  for (i = 0; i < s->plugin_info.num_params; i++) {
143  f0r_param_info_t info;
144  char *param;
145  int ret;
146 
147  s->get_param_info(&info, i);
148 
149  if (*params) {
150  if (!(param = av_get_token(&params, "|")))
151  return AVERROR(ENOMEM);
152  if (*params)
153  params++; /* skip ':' */
154  ret = set_param(ctx, info, i, param);
155  av_free(param);
156  if (ret < 0)
157  return ret;
158  }
159 
160  av_log(ctx, AV_LOG_VERBOSE,
161  "idx:%d name:'%s' type:%s explanation:'%s' ",
162  i, info.name,
163  info.type == F0R_PARAM_BOOL ? "bool" :
164  info.type == F0R_PARAM_DOUBLE ? "double" :
165  info.type == F0R_PARAM_COLOR ? "color" :
166  info.type == F0R_PARAM_POSITION ? "position" :
167  info.type == F0R_PARAM_STRING ? "string" : "unknown",
168  info.explanation);
169 
170 #ifdef DEBUG
171  av_log(ctx, AV_LOG_DEBUG, "value:");
172  switch (info.type) {
173  void *v;
174  double d;
175  char s[128];
176  f0r_param_color_t col;
177  f0r_param_position_t pos;
178 
179  case F0R_PARAM_BOOL:
180  v = &d;
181  s->get_param_value(s->instance, v, i);
182  av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
183  break;
184  case F0R_PARAM_DOUBLE:
185  v = &d;
186  s->get_param_value(s->instance, v, i);
187  av_log(ctx, AV_LOG_DEBUG, "%f", d);
188  break;
189  case F0R_PARAM_COLOR:
190  v = &col;
191  s->get_param_value(s->instance, v, i);
192  av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
193  break;
194  case F0R_PARAM_POSITION:
195  v = &pos;
196  s->get_param_value(s->instance, v, i);
197  av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
198  break;
199  default: /* F0R_PARAM_STRING */
200  v = s;
201  s->get_param_value(s->instance, v, i);
202  av_log(ctx, AV_LOG_DEBUG, "'%s'", s);
203  break;
204  }
205 #endif
206  av_log(ctx, AV_LOG_VERBOSE, ".\n");
207  }
208 
209  return 0;
210 }
211 
212 static void *load_path(AVFilterContext *ctx, const char *prefix, const char *name)
213 {
214  char path[1024];
215 
216  snprintf(path, sizeof(path), "%s%s%s", prefix, name, SLIBSUF);
217  av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'.\n", path);
218  return dlopen(path, RTLD_NOW|RTLD_LOCAL);
219 }
220 
222  const char *dl_name, int type)
223 {
224  Frei0rContext *s = ctx->priv;
225  f0r_init_f f0r_init;
226  f0r_get_plugin_info_f f0r_get_plugin_info;
227  f0r_plugin_info_t *pi;
228  char *path;
229 
230  if (!dl_name) {
231  av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
232  return AVERROR(EINVAL);
233  }
234 
235  /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */
236  if (path = getenv("FREI0R_PATH")) {
237  while(*path) {
238  char *ptr = av_get_token((const char **)&path, ":");
239  if (!ptr)
240  return AVERROR(ENOMEM);
241  s->dl_handle = load_path(ctx, ptr, dl_name);
242  av_freep(&ptr);
243  if (s->dl_handle)
244  break; /* found */
245  if (*path)
246  path++; /* skip ':' */
247  }
248  }
249  if (!s->dl_handle && (path = getenv("HOME"))) {
250  char prefix[1024];
251  snprintf(prefix, sizeof(prefix), "%s/.frei0r-1/lib/", path);
252  s->dl_handle = load_path(ctx, prefix, dl_name);
253  }
254  if (!s->dl_handle)
255  s->dl_handle = load_path(ctx, "/usr/local/lib/frei0r-1/", dl_name);
256  if (!s->dl_handle)
257  s->dl_handle = load_path(ctx, "/usr/lib/frei0r-1/", dl_name);
258  if (!s->dl_handle) {
259  av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'.\n", dl_name);
260  return AVERROR(EINVAL);
261  }
262 
263  if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
264  !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
265  !(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
266  !(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
267  !(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
268  !(s->update = load_sym(ctx, "f0r_update" )) ||
269  !(s->construct = load_sym(ctx, "f0r_construct" )) ||
270  !(s->destruct = load_sym(ctx, "f0r_destruct" )) ||
271  !(s->deinit = load_sym(ctx, "f0r_deinit" )))
272  return AVERROR(EINVAL);
273 
274  if (f0r_init() < 0) {
275  av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module.\n");
276  return AVERROR(EINVAL);
277  }
278 
279  f0r_get_plugin_info(&s->plugin_info);
280  pi = &s->plugin_info;
281  if (pi->plugin_type != type) {
282  av_log(ctx, AV_LOG_ERROR,
283  "Invalid type '%s' for this plugin\n",
284  pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
285  pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
286  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
287  pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
288  return AVERROR(EINVAL);
289  }
290 
291  av_log(ctx, AV_LOG_VERBOSE,
292  "name:%s author:'%s' explanation:'%s' color_model:%s "
293  "frei0r_version:%d version:%d.%d num_params:%d\n",
294  pi->name, pi->author, pi->explanation,
295  pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
296  pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
297  pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
298  pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
299 
300  return 0;
301 }
302 
304 {
305  Frei0rContext *s = ctx->priv;
306 
307  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_FILTER);
308 }
309 
310 static av_cold void uninit(AVFilterContext *ctx)
311 {
312  Frei0rContext *s = ctx->priv;
313 
314  if (s->destruct && s->instance)
315  s->destruct(s->instance);
316  if (s->deinit)
317  s->deinit();
318  if (s->dl_handle)
319  dlclose(s->dl_handle);
320 }
321 
322 static int config_input_props(AVFilterLink *inlink)
323 {
324  AVFilterContext *ctx = inlink->dst;
325  Frei0rContext *s = ctx->priv;
326 
327  if (s->destruct && s->instance)
328  s->destruct(s->instance);
329  if (!(s->instance = s->construct(inlink->w, inlink->h))) {
330  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
331  return AVERROR(EINVAL);
332  }
333 
334  return set_params(ctx, s->params);
335 }
336 
338 {
339  Frei0rContext *s = ctx->priv;
341 
342  if (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
343  ff_add_format(&formats, AV_PIX_FMT_BGRA);
344  } else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
345  ff_add_format(&formats, AV_PIX_FMT_RGBA);
346  } else { /* F0R_COLOR_MODEL_PACKED32 */
347  static const enum AVPixelFormat pix_fmts[] = {
349  };
350  formats = ff_make_format_list(pix_fmts);
351  }
352 
353  if (!formats)
354  return AVERROR(ENOMEM);
355 
356  ff_set_common_formats(ctx, formats);
357  return 0;
358 }
359 
360 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
361 {
362  Frei0rContext *s = inlink->dst->priv;
363  AVFilterLink *outlink = inlink->dst->outputs[0];
364  AVFrame *out;
365 
366  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
367  if (!out) {
368  av_frame_free(&in);
369  return AVERROR(ENOMEM);
370  }
371  av_frame_copy_props(out, in);
372 
373  s->update(s->instance, in->pts * av_q2d(inlink->time_base) * 1000,
374  (const uint32_t *)in->data[0],
375  (uint32_t *)out->data[0]);
376 
377  av_frame_free(&in);
378 
379  return ff_filter_frame(outlink, out);
380 }
381 
382 #define OFFSET(x) offsetof(Frei0rContext, x)
383 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM
384 static const AVOption filter_options[] = {
385  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
386  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
387  { NULL },
388 };
389 
390 static const AVClass filter_class = {
391  .class_name = "frei0r",
392  .item_name = av_default_item_name,
393  .option = filter_options,
394  .version = LIBAVUTIL_VERSION_INT,
395 };
396 
398  {
399  .name = "default",
400  .type = AVMEDIA_TYPE_VIDEO,
401  .config_props = config_input_props,
402  .filter_frame = filter_frame,
403  },
404  { NULL }
405 };
406 
408  {
409  .name = "default",
410  .type = AVMEDIA_TYPE_VIDEO,
411  },
412  { NULL }
413 };
414 
416  .name = "frei0r",
417  .description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
418 
419  .query_formats = query_formats,
420  .init = filter_init,
421  .uninit = uninit,
422 
423  .priv_size = sizeof(Frei0rContext),
424  .priv_class = &filter_class,
425 
426  .inputs = avfilter_vf_frei0r_inputs,
427 
428  .outputs = avfilter_vf_frei0r_outputs,
429 };
430 
432 {
433  Frei0rContext *s = ctx->priv;
434  AVRational frame_rate_q;
435 
436  if (av_parse_video_size(&s->w, &s->h, s->size) < 0) {
437  av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'.\n", s->size);
438  return AVERROR(EINVAL);
439  }
440 
441  if (av_parse_video_rate(&frame_rate_q, s->framerate) < 0 ||
442  frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
443  av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'.\n", s->framerate);
444  return AVERROR(EINVAL);
445  }
446  s->time_base.num = frame_rate_q.den;
447  s->time_base.den = frame_rate_q.num;
448 
449  return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_SOURCE);
450 }
451 
452 static int source_config_props(AVFilterLink *outlink)
453 {
454  AVFilterContext *ctx = outlink->src;
455  Frei0rContext *s = ctx->priv;
456 
457  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
458  return AVERROR(EINVAL);
459  outlink->w = s->w;
460  outlink->h = s->h;
461  outlink->time_base = s->time_base;
462 
463  if (s->destruct && s->instance)
464  s->destruct(s->instance);
465  if (!(s->instance = s->construct(outlink->w, outlink->h))) {
466  av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
467  return AVERROR(EINVAL);
468  }
469  if (!s->params) {
470  av_log(ctx, AV_LOG_ERROR, "frei0r filter parameters not set.\n");
471  return AVERROR(EINVAL);
472  }
473 
474  return set_params(ctx, s->params);
475 }
476 
477 static int source_request_frame(AVFilterLink *outlink)
478 {
479  Frei0rContext *s = outlink->src->priv;
480  AVFrame *frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
481 
482  if (!frame)
483  return AVERROR(ENOMEM);
484 
485  frame->sample_aspect_ratio = (AVRational) {1, 1};
486  frame->pts = s->pts++;
487 
488  s->update(s->instance, av_rescale_q(frame->pts, s->time_base, (AVRational){1,1000}),
489  NULL, (uint32_t *)frame->data[0]);
490 
491  return ff_filter_frame(outlink, frame);
492 }
493 
494 static const AVOption src_options[] = {
495  { "size", "Dimensions of the generated video.", OFFSET(size), AV_OPT_TYPE_STRING, { .str = "" }, .flags = FLAGS },
496  { "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = FLAGS },
497  { "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
498  { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
499  { NULL },
500 };
501 
502 static const AVClass src_class = {
503  .class_name = "frei0r_src",
504  .item_name = av_default_item_name,
505  .option = src_options,
506  .version = LIBAVUTIL_VERSION_INT,
507 };
508 
510  {
511  .name = "default",
512  .type = AVMEDIA_TYPE_VIDEO,
513  .request_frame = source_request_frame,
514  .config_props = source_config_props
515  },
516  { NULL }
517 };
518 
520  .name = "frei0r_src",
521  .description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
522 
523  .priv_size = sizeof(Frei0rContext),
524  .priv_class = &src_class,
525  .init = source_init,
526  .uninit = uninit,
527 
529 
530  .inputs = NULL,
531 
532  .outputs = avfilter_vsrc_frei0r_src_outputs,
533 };
int size
static av_cold int filter_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:303
#define FLAGS
Definition: vf_frei0r.c:383
AVFilter ff_vf_frei0r
Definition: vf_frei0r.c:415
char * dl_name
Definition: vf_frei0r.c:68
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:122
AVOption.
Definition: opt.h:234
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:95
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:232
Main libavfilter public API header.
memory handling functions
int num
numerator
Definition: rational.h:44
f0r_plugin_info_t plugin_info
Definition: vf_frei0r.c:59
static const AVOption src_options[]
Definition: vf_frei0r.c:494
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
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:104
static const AVFilterPad avfilter_vf_frei0r_outputs[]
Definition: vf_frei0r.c:407
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
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
const char * name
Pad name.
Definition: internal.h:42
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:733
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
#define av_cold
Definition: attributes.h:66
AVOptions.
static int query_formats(AVFilterContext *ctx)
Definition: vf_frei0r.c:337
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_frei0r.c:310
const char * name
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:97
double strtod(const char *, char **)
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
#define SLIBSUF
Definition: config.h:11
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:139
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
Definition: vf_frei0r.c:221
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:379
char * framerate
Definition: vf_frei0r.c:71
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:300
A filter pad used for either input or output.
Definition: internal.h:36
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:129
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
Definition: vf_frei0r.c:47
AVRational time_base
Definition: vf_frei0r.c:75
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: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
#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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:98
void * priv
private data for use by the filter
Definition: avfilter.h:584
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
Definition: vf_frei0r.c:509
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:95
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
char * size
Definition: vf_frei0r.c:70
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
AVFilter ff_vsrc_frei0r_src
Definition: vf_frei0r.c:519
void * dl_handle
Definition: vf_frei0r.c:57
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:222
static void * load_path(AVFilterContext *ctx, const char *prefix, const char *name)
Definition: vf_frei0r.c:212
uint64_t pts
Definition: vf_frei0r.c:76
static int source_config_props(AVFilterLink *outlink)
Definition: vf_frei0r.c:452
f0r_get_param_info_f get_param_info
Definition: vf_frei0r.c:61
static const AVClass src_class
Definition: vf_frei0r.c:502
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:322
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static int set_params(AVFilterContext *ctx, const char *params)
Definition: vf_frei0r.c:137
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
NULL
Definition: eval.c:55
static int width
Definition: utils.c:156
av_default_item_name
Definition: dnxhdenc.c:52
f0r_construct_f construct
Definition: vf_frei0r.c:64
static const AVFilterPad avfilter_vf_frei0r_inputs[]
Definition: vf_frei0r.c:397
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:206
#define OFFSET(x)
Definition: vf_frei0r.c:382
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:33
Filter definition.
Definition: avfilter.h:421
int index
Definition: gxfenc.c:72
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:221
static const AVClass filter_class
Definition: vf_frei0r.c:390
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
const char * name
Filter name.
Definition: avfilter.h:425
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
void(* f0r_destruct_f)(f0r_instance_t instance)
Definition: vf_frei0r.c:44
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
int height
Definition: gxfenc.c:72
static const AVOption filter_options[]
Definition: vf_frei0r.c:384
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:360
int(* f0r_init_f)(void)
Definition: vf_frei0r.c:46
f0r_set_param_value_f set_param_value
Definition: vf_frei0r.c:63
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
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
int ff_add_format(AVFilterFormats **avff, int fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:199
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
An instance of a filter.
Definition: avfilter.h:563
static int source_request_frame(AVFilterLink *outlink)
Definition: vf_frei0r.c:477
f0r_deinit_f deinit
Definition: vf_frei0r.c:66
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
static av_cold int source_init(AVFilterContext *ctx)
Definition: vf_frei0r.c:431
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367