31 #include "libavutil/avstring.h"
32 #include "libavutil/imgutils.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/parseutils.h"
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);
81 void *sym = dlsym(s->
dl_handle, sym_name);
92 f0r_param_color_t col;
93 f0r_param_position_t pos;
100 if (!strcmp(param,
"y"))
val.d = 1.0;
101 else if (!strcmp(param,
"n"))
val.d = 0.0;
105 case F0R_PARAM_DOUBLE:
107 if (*tail ||
val.d == HUGE_VAL)
111 case F0R_PARAM_COLOR:
112 if (sscanf(param,
"%f/%f/%f", &
val.col.r, &
val.col.g, &
val.col.b) != 3) {
115 val.col.r = rgba[0] / 255.0;
116 val.col.g = rgba[1] / 255.0;
117 val.col.b = rgba[2] / 255.0;
121 case F0R_PARAM_POSITION:
122 if (sscanf(param,
"%lf/%lf", &
val.pos.x, &
val.pos.y) != 2)
145 f0r_param_info_t info;
163 "idx:%d name:'%s' type:%s explanation:'%s' ",
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",
178 f0r_param_color_t col;
179 f0r_param_position_t pos;
186 case F0R_PARAM_DOUBLE:
188 s->get_param_value(s->instance, v, i);
191 case F0R_PARAM_COLOR:
193 s->get_param_value(s->instance, v, i);
196 case F0R_PARAM_POSITION:
198 s->get_param_value(s->instance, v, i);
203 s->get_param_value(s->instance, v, i);
220 *handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
226 const char *dl_name,
int type)
231 f0r_plugin_info_t *pi;
241 if ((path =
av_strdup(getenv(
"FREI0R_PATH")))) {
243 const char *separator =
";";
245 const char *separator =
":";
247 char *p, *ptr = NULL;
248 for (p = path; p =
av_strtok(p, separator, &ptr); p = NULL) {
268 if (!s->
dl_handle && (path = getenv(
"HOME"))) {
269 char *prefix =
av_asprintf(
"%s/.frei0r-1/lib/", path);
292 if (!(f0r_init =
load_sym(ctx,
"f0r_init" )) ||
293 !(f0r_get_plugin_info =
load_sym(ctx,
"f0r_get_plugin_info")) ||
303 if (f0r_init() < 0) {
310 if (pi->plugin_type != type) {
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");
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);
371 if (s->
plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
373 }
else if (s->
plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
403 (
const uint32_t *)in->
data[0],
404 (uint32_t *)out->
data[0]);
411 #define OFFSET(x) offsetof(Frei0rContext, x)
412 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
446 .priv_class = &frei0r_class,
447 .
inputs = avfilter_vf_frei0r_inputs,
448 .
outputs = avfilter_vf_frei0r_outputs,
521 .
name =
"frei0r_src",
524 .priv_class = &frei0r_src_class,
529 .
outputs = avfilter_vsrc_frei0r_src_outputs,
const char const char void * val
AVFilter avfilter_vsrc_frei0r_src
static const AVOption frei0r_src_options[]
static av_cold int filter_init(AVFilterContext *ctx)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
f0r_plugin_info_t plugin_info
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...
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.
static const AVFilterPad avfilter_vf_frei0r_outputs[]
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
const char * name
Pad name.
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...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const AVOption frei0r_options[]
f0r_get_param_value_f get_param_value
void(* f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
static int query_formats(AVFilterContext *ctx)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static av_cold void uninit(AVFilterContext *ctx)
double strtod(const char *, char **)
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
static double av_q2d(AVRational a)
Convert rational to double.
#define AV_LOG_VERBOSE
Detailed information.
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type)
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
void(* f0r_get_plugin_info_f)(f0r_plugin_info_t *info)
f0r_instance_t(* f0r_construct_f)(unsigned int width, unsigned int height)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVPixelFormat
Pixel format.
int w
agreed upon image width
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...
static int source_config_props(AVFilterLink *outlink)
f0r_get_param_info_f get_param_info
void(* f0r_deinit_f)(void)
static int config_input_props(AVFilterLink *inlink)
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)
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
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)
typedef void(RENAME(mix_any_func_type))
f0r_construct_f construct
static const AVFilterPad avfilter_vf_frei0r_inputs[]
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
BYTE int const BYTE int int int height
void(* f0r_get_param_info_f)(f0r_param_info_t *info, int param_index)
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
rational number numerator/denominator
void(* f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index)
offset must point to AVRational
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
offset must point to two consecutive integers
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.
void(* f0r_destruct_f)(f0r_instance_t instance)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const char const char * params
f0r_set_param_value_f set_param_value
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()...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static void * load_sym(AVFilterContext *ctx, const char *sym_name)
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
AVFilter avfilter_vf_frei0r
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)
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
void(* f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe)
static int source_request_frame(AVFilterLink *outlink)
static av_cold int source_init(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.