FFmpeg: libavfilter/vf_frei0r.c Source File
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 <frei0r.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include "config.h"
45
52 typedef void (*
f0r_update_f)(f0r_instance_t instance,
double time,
const uint32_t *inframe, uint32_t *outframe);
53 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);
56
63
70
74
75 /* only used by the source */
80
82 {
84 void *sym = dlsym(
s->dl_handle, sym_name);
85 if (!sym)
87 return sym;
88 }
89
91 {
93 union {
95 f0r_param_color_t col;
96 f0r_param_position_t
pos;
97 f0r_param_string str;
99 char *tail;
100 uint8_t rgba[4];
101
103 case F0R_PARAM_BOOL:
104 if (!strcmp(param,
"y"))
val.d = 1.0;
105 else if (!strcmp(param,
"n"))
val.d = 0.0;
107 break;
108
109 case F0R_PARAM_DOUBLE:
111 if (*tail ||
val.d == HUGE_VAL)
113 break;
114
115 case F0R_PARAM_COLOR:
116 if (sscanf(param,
"%f/%f/%f", &
val.col.r, &
val.col.g, &
val.col.b) != 3) {
119 val.col.r = rgba[0] / 255.0;
120 val.col.g = rgba[1] / 255.0;
121 val.col.b = rgba[2] / 255.0;
122 }
123 break;
124
125 case F0R_PARAM_POSITION:
126 if (sscanf(param,
"%lf/%lf", &
val.pos.x, &
val.pos.y) != 2)
128 break;
129
130 case F0R_PARAM_STRING:
132 break;
133 }
134
136 return 0;
137
142 }
143
145 {
148
149 if (!params)
150 return 0;
151
152 for (
i = 0;
i <
s->plugin_info.num_params;
i++) {
153 f0r_param_info_t
info;
154 char *param;
156
157 s->get_param_info(&
info,
i);
158
159 if (*params) {
162 if (*params)
163 params++; /* skip ':' */
168 }
169 }
170
171 return 0;
172 }
173
175 {
177 if (!path)
180 *handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
182 return 0;
183 }
184
186 const char *dl_name,
int type)
187 {
191 f0r_plugin_info_t *pi;
192 char *path;
195 static const char* const frei0r_pathlist[] = {
196 "/usr/local/lib/frei0r-1/",
197 "/usr/lib/frei0r-1/",
198 "/usr/local/lib64/frei0r-1/",
199 "/usr/lib64/frei0r-1/"
200 };
201
202 if (!dl_name) {
205 }
206
207 /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
209 #ifdef _WIN32
210 const char *separator = ";";
211 #else
212 const char *separator = ":";
213 #endif
214 char *p, *ptr =
NULL;
215 for (p = path; p =
av_strtok(p, separator, &ptr); p =
NULL) {
216 /* add additional trailing slash in case it is missing */
218 if (!p1) {
220 goto check_path_end;
221 }
225 goto check_path_end;
227 break;
228 }
229
230 check_path_end:
234 }
236 char *prefix =
av_asprintf(
"%s/.frei0r-1/lib/", path);
237 if (!prefix) {
239 goto home_path_end;
240 }
243
244 home_path_end:
248 }
253 }
257 }
258
260 !(f0r_get_plugin_info =
load_sym(
ctx,
"f0r_get_plugin_info")) ||
261 !(
s->get_param_info =
load_sym(
ctx,
"f0r_get_param_info" )) ||
262 !(
s->get_param_value =
load_sym(
ctx,
"f0r_get_param_value")) ||
263 !(
s->set_param_value =
load_sym(
ctx,
"f0r_set_param_value")) ||
269
270 if (f0r_init() < 0) {
273 }
274
275 f0r_get_plugin_info(&
s->plugin_info);
276 pi = &
s->plugin_info;
277 if (pi->plugin_type !=
type) {
279 "Invalid type '%s' for this plugin\n",
280 pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
281 pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
282 pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
283 pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
285 }
286
288 "name:%s author:'%s' explanation:'%s' color_model:%s "
289 "frei0r_version:%d version:%d.%d num_params:%d\n",
290 pi->name, pi->author, pi->explanation,
291 pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
292 pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
293 pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
294 pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
295
296 return 0;
297 }
298
300 {
302
304 }
305
307 {
309
310 if (
s->destruct &&
s->instance)
311 s->destruct(
s->instance);
315 dlclose(
s->dl_handle);
316 }
317
319 {
322
323 if (
s->destruct &&
s->instance)
324 s->destruct(
s->instance);
328 }
329
331 }
332
334 {
338
339 if (
s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
342 }
else if (
s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
345 } else { /* F0R_COLOR_MODEL_PACKED32 */
348 };
350 }
351
354
356 }
357
359 {
362 /* align parameter is the line alignment, not the buffer alignment.
363 * frei0r expects line size to be width*4 so we want an align of 1
364 * to ensure lines aren't padded out. */
368
370
373 if (!in2)
377 in = in2;
378 }
379
381 (
const uint32_t *)in->
data[0],
382 (uint32_t *)
out->data[0]);
383
385
391 }
392
394 char *res,
int res_len,
int flags)
395 {
398
402
404 }
405
406 #define OFFSET(x) offsetof(Frei0rContext, x)
407 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
408 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
413 };
414
416
418 {
423 },
424 };
425
432 .priv_class = &frei0r_class,
438 };
439
441 {
443
444 s->time_base.num =
s->framerate.den;
445 s->time_base.den =
s->framerate.num;
446
448 }
449
451 {
454
462
463 if (
s->destruct &&
s->instance)
464 s->destruct(
s->instance);
465 if (!(
s->instance =
s->construct(outlink->
w, outlink->
h))) {
468 }
472 }
473
475 }
476
478 {
481
484
488
491
493 }
494
501 };
502
504
506 {
511 },
512 };
513
515 .
name =
"frei0r_src",
518 .priv_class = &frei0r_src_class,
524 };
AVFrame * ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
static void * load_sym(AVFilterContext *ctx, const char *sym_name)
AVPixelFormat
Pixel format.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
void(* f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t duration
Duration of the frame, in the same units as pts.
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.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
char * av_asprintf(const char *fmt,...)
static av_cold void uninit(AVFilterContext *ctx)
static int set_params(AVFilterContext *ctx, const char *params)
AVFILTER_DEFINE_CLASS(frei0r)
static av_cold int source_init(AVFilterContext *ctx)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
void(* f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
#define FILTER_QUERY_FUNC(func)
#define AV_LOG_VERBOSE
Detailed information.
static void freeenv_utf8(char *var)
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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)
void * priv
private data for use by the filter
static int source_request_frame(AVFilterLink *outlink)
f0r_plugin_info_t plugin_info
static double val(void *priv, double ch)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
f0r_instance_t(* f0r_construct_f)(unsigned int width, unsigned int height)
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
const AVFilter ff_vf_frei0r
static int source_config_props(AVFilterLink *outlink)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
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().
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
f0r_get_param_info_f get_param_info
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
static enum AVPixelFormat pix_fmts[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
f0r_get_param_value_f get_param_value
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int config_input_props(AVFilterLink *inlink)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
static char * getenv_utf8(const char *varname)
static av_cold int filter_init(AVFilterContext *ctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
int(* init)(AVBSFContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
void(* f0r_destruct_f)(f0r_instance_t instance)
static const AVOption frei0r_options[]
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
static int query_formats(AVFilterContext *ctx)
static char * getenv_dup(const char *varname)
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
#define i(width, name, range_min, range_max)
void(* f0r_get_param_info_f)(f0r_param_info_t *info, int param_index)
int w
agreed upon image width
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
f0r_construct_f construct
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
int h
agreed upon image height
void(* f0r_deinit_f)(void)
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...
const AVFilter ff_vsrc_frei0r_src
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
void(* f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe)
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
#define FILTER_OUTPUTS(array)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
f0r_set_param_value_f set_param_value
static const AVFilterPad avfilter_vf_frei0r_inputs[]
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...
static const AVOption frei0r_src_options[]
Generated on Thu Sep 26 2024 23:15:37 for FFmpeg by
doxygen
1.8.17