2010-09-24 03:32:22 +03:00
|
|
|
/*
|
2010-11-28 12:22:58 +02:00
|
|
|
* Copyright (c) 2010 Stefano Sabatini
|
2010-09-24 03:32:22 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* frei0r wrapper
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <frei0r.h>
|
2012-08-16 14:24:26 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
2021-09-05 16:34:37 +02:00
|
|
|
#include "compat/w32dlfcn.h"
|
2010-09-27 19:23:43 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2014-02-22 19:46:25 +03:00
|
|
|
#include "libavutil/common.h"
|
2015-11-01 05:34:15 +02:00
|
|
|
#include "libavutil/eval.h"
|
2022-06-20 12:30:01 +02:00
|
|
|
#include "libavutil/getenv_utf8.h"
|
2011-02-07 15:37:08 +02:00
|
|
|
#include "libavutil/imgutils.h"
|
2012-08-16 14:24:26 +03:00
|
|
|
#include "libavutil/internal.h"
|
2011-07-05 01:42:31 +03:00
|
|
|
#include "libavutil/mathematics.h"
|
2012-08-16 14:24:26 +03:00
|
|
|
#include "libavutil/mem.h"
|
2013-02-25 23:21:29 +03:00
|
|
|
#include "libavutil/opt.h"
|
2011-02-07 15:37:08 +02:00
|
|
|
#include "libavutil/parseutils.h"
|
2010-09-24 03:32:22 +03:00
|
|
|
#include "avfilter.h"
|
2012-05-30 11:12:55 +03:00
|
|
|
#include "formats.h"
|
2012-06-12 21:12:42 +03:00
|
|
|
#include "internal.h"
|
2012-05-30 12:20:32 +03:00
|
|
|
#include "video.h"
|
2010-09-24 03:32:22 +03:00
|
|
|
|
|
|
|
typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height);
|
|
|
|
typedef void (*f0r_destruct_f)(f0r_instance_t instance);
|
|
|
|
typedef void (*f0r_deinit_f)(void);
|
|
|
|
typedef int (*f0r_init_f)(void);
|
|
|
|
typedef void (*f0r_get_plugin_info_f)(f0r_plugin_info_t *info);
|
|
|
|
typedef void (*f0r_get_param_info_f)(f0r_param_info_t *info, int param_index);
|
|
|
|
typedef void (*f0r_update_f)(f0r_instance_t instance, double time, const uint32_t *inframe, uint32_t *outframe);
|
|
|
|
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);
|
|
|
|
typedef void (*f0r_set_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
|
|
|
|
typedef void (*f0r_get_param_value_f)(f0r_instance_t instance, f0r_param_t param, int param_index);
|
|
|
|
|
|
|
|
typedef struct Frei0rContext {
|
2013-02-25 23:21:29 +03:00
|
|
|
const AVClass *class;
|
2010-09-24 03:32:22 +03:00
|
|
|
f0r_update_f update;
|
|
|
|
void *dl_handle; /* dynamic library handle */
|
|
|
|
f0r_instance_t instance;
|
|
|
|
f0r_plugin_info_t plugin_info;
|
|
|
|
|
|
|
|
f0r_get_param_info_f get_param_info;
|
|
|
|
f0r_get_param_value_f get_param_value;
|
|
|
|
f0r_set_param_value_f set_param_value;
|
|
|
|
f0r_construct_f construct;
|
|
|
|
f0r_destruct_f destruct;
|
|
|
|
f0r_deinit_f deinit;
|
2013-02-25 23:21:29 +03:00
|
|
|
|
|
|
|
char *dl_name;
|
|
|
|
char *params;
|
2013-07-26 18:24:55 +03:00
|
|
|
AVRational framerate;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
|
|
|
/* only used by the source */
|
|
|
|
int w, h;
|
|
|
|
AVRational time_base;
|
|
|
|
uint64_t pts;
|
2010-09-24 03:32:22 +03:00
|
|
|
} Frei0rContext;
|
|
|
|
|
|
|
|
static void *load_sym(AVFilterContext *ctx, const char *sym_name)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
|
|
|
void *sym = dlsym(s->dl_handle, sym_name);
|
2010-09-24 03:32:22 +03:00
|
|
|
if (!sym)
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module.\n", sym_name);
|
2010-09-24 03:32:22 +03:00
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
union {
|
|
|
|
double d;
|
|
|
|
f0r_param_color_t col;
|
|
|
|
f0r_param_position_t pos;
|
2019-04-23 23:09:01 +02:00
|
|
|
f0r_param_string str;
|
2010-09-24 03:32:22 +03:00
|
|
|
} val;
|
|
|
|
char *tail;
|
|
|
|
uint8_t rgba[4];
|
|
|
|
|
|
|
|
switch (info.type) {
|
|
|
|
case F0R_PARAM_BOOL:
|
|
|
|
if (!strcmp(param, "y")) val.d = 1.0;
|
|
|
|
else if (!strcmp(param, "n")) val.d = 0.0;
|
|
|
|
else goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F0R_PARAM_DOUBLE:
|
2015-11-01 05:34:15 +02:00
|
|
|
val.d = av_strtod(param, &tail);
|
2010-09-24 03:32:22 +03:00
|
|
|
if (*tail || val.d == HUGE_VAL)
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F0R_PARAM_COLOR:
|
|
|
|
if (sscanf(param, "%f/%f/%f", &val.col.r, &val.col.g, &val.col.b) != 3) {
|
2010-11-13 16:37:48 +02:00
|
|
|
if (av_parse_color(rgba, param, -1, ctx) < 0)
|
2010-09-24 03:32:22 +03:00
|
|
|
goto fail;
|
|
|
|
val.col.r = rgba[0] / 255.0;
|
|
|
|
val.col.g = rgba[1] / 255.0;
|
|
|
|
val.col.b = rgba[2] / 255.0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F0R_PARAM_POSITION:
|
|
|
|
if (sscanf(param, "%lf/%lf", &val.pos.x, &val.pos.y) != 2)
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2018-08-29 12:29:16 +02:00
|
|
|
case F0R_PARAM_STRING:
|
2019-04-23 23:09:01 +02:00
|
|
|
val.str = param;
|
2018-08-29 12:29:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
s->set_param_value(s->instance, &val, index);
|
2010-09-24 03:32:22 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'.\n",
|
2010-09-24 03:32:22 +03:00
|
|
|
param, info.name);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_params(AVFilterContext *ctx, const char *params)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
int i;
|
|
|
|
|
2013-05-03 18:03:12 +03:00
|
|
|
if (!params)
|
|
|
|
return 0;
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
for (i = 0; i < s->plugin_info.num_params; i++) {
|
2010-09-24 03:32:22 +03:00
|
|
|
f0r_param_info_t info;
|
|
|
|
char *param;
|
|
|
|
int ret;
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
s->get_param_info(&info, i);
|
2010-09-24 03:32:22 +03:00
|
|
|
|
|
|
|
if (*params) {
|
2013-02-25 23:21:29 +03:00
|
|
|
if (!(param = av_get_token(¶ms, "|")))
|
2010-09-24 03:32:22 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2013-10-04 12:16:35 +03:00
|
|
|
if (*params)
|
|
|
|
params++; /* skip ':' */
|
2010-09-24 03:32:22 +03:00
|
|
|
ret = set_param(ctx, info, i, param);
|
|
|
|
av_free(param);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-16 12:45:25 +03:00
|
|
|
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
|
2010-09-24 03:32:22 +03:00
|
|
|
{
|
2012-11-16 12:45:25 +03:00
|
|
|
char *path = av_asprintf("%s%s%s", prefix, name, SLIBSUF);
|
|
|
|
if (!path)
|
|
|
|
return AVERROR(ENOMEM);
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'.\n", path);
|
2012-11-16 12:45:25 +03:00
|
|
|
*handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
|
|
|
|
av_free(path);
|
|
|
|
return 0;
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
2010-11-30 22:14:36 +02:00
|
|
|
static av_cold int frei0r_init(AVFilterContext *ctx,
|
|
|
|
const char *dl_name, int type)
|
2010-09-24 03:32:22 +03:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
f0r_init_f f0r_init;
|
|
|
|
f0r_get_plugin_info_f f0r_get_plugin_info;
|
|
|
|
f0r_plugin_info_t *pi;
|
2010-11-30 22:14:36 +02:00
|
|
|
char *path;
|
2012-11-16 12:45:25 +03:00
|
|
|
int ret = 0;
|
2014-02-22 19:46:25 +03:00
|
|
|
int i;
|
|
|
|
static const char* const frei0r_pathlist[] = {
|
|
|
|
"/usr/local/lib/frei0r-1/",
|
|
|
|
"/usr/lib/frei0r-1/",
|
|
|
|
"/usr/local/lib64/frei0r-1/",
|
|
|
|
"/usr/lib64/frei0r-1/"
|
|
|
|
};
|
2010-09-24 03:32:22 +03:00
|
|
|
|
2013-02-25 23:21:29 +03:00
|
|
|
if (!dl_name) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2012-10-29 20:07:19 +03:00
|
|
|
/* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
|
2022-06-20 12:30:01 +02:00
|
|
|
if (path = getenv_dup("FREI0R_PATH")) {
|
2012-10-11 02:28:55 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char *separator = ";";
|
|
|
|
#else
|
|
|
|
const char *separator = ":";
|
|
|
|
#endif
|
2010-09-24 03:32:22 +03:00
|
|
|
char *p, *ptr = NULL;
|
2012-10-29 20:44:27 +03:00
|
|
|
for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) {
|
|
|
|
/* add additional trailing slash in case it is missing */
|
|
|
|
char *p1 = av_asprintf("%s/", p);
|
|
|
|
if (!p1) {
|
2012-11-16 12:58:37 +03:00
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto check_path_end;
|
2012-10-29 20:44:27 +03:00
|
|
|
}
|
2013-05-16 16:21:31 +03:00
|
|
|
ret = load_path(ctx, &s->dl_handle, p1, dl_name);
|
2012-10-29 20:44:27 +03:00
|
|
|
av_free(p1);
|
2012-11-16 12:58:37 +03:00
|
|
|
if (ret < 0)
|
|
|
|
goto check_path_end;
|
2013-05-16 16:21:31 +03:00
|
|
|
if (s->dl_handle)
|
2010-09-24 03:32:22 +03:00
|
|
|
break;
|
2012-10-29 20:44:27 +03:00
|
|
|
}
|
2012-11-16 12:58:37 +03:00
|
|
|
|
|
|
|
check_path_end:
|
2010-09-24 03:32:22 +03:00
|
|
|
av_free(path);
|
2012-11-16 12:58:37 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
2022-06-20 12:30:01 +02:00
|
|
|
if (!s->dl_handle && (path = getenv_utf8("HOME"))) {
|
2012-10-29 20:33:11 +03:00
|
|
|
char *prefix = av_asprintf("%s/.frei0r-1/lib/", path);
|
2022-06-20 12:30:01 +02:00
|
|
|
if (!prefix) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto home_path_end;
|
|
|
|
}
|
2013-05-16 16:21:31 +03:00
|
|
|
ret = load_path(ctx, &s->dl_handle, prefix, dl_name);
|
2012-10-29 20:33:11 +03:00
|
|
|
av_free(prefix);
|
2022-06-20 12:30:01 +02:00
|
|
|
|
|
|
|
home_path_end:
|
|
|
|
freeenv_utf8(path);
|
2012-11-16 12:45:25 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-22 19:46:25 +03:00
|
|
|
for (i = 0; !s->dl_handle && i < FF_ARRAY_ELEMS(frei0r_pathlist); i++) {
|
|
|
|
ret = load_path(ctx, &s->dl_handle, frei0r_pathlist[i], dl_name);
|
2014-02-05 03:24:19 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-18 22:44:36 +03:00
|
|
|
if (!s->dl_handle) {
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'.\n", dl_name);
|
2010-09-24 03:32:22 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
|
|
|
|
!(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
|
2013-03-18 22:44:36 +03:00
|
|
|
!(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
|
|
|
|
!(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
|
|
|
|
!(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
|
|
|
|
!(s->update = load_sym(ctx, "f0r_update" )) ||
|
|
|
|
!(s->construct = load_sym(ctx, "f0r_construct" )) ||
|
|
|
|
!(s->destruct = load_sym(ctx, "f0r_destruct" )) ||
|
|
|
|
!(s->deinit = load_sym(ctx, "f0r_deinit" )))
|
2010-09-24 03:32:22 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
|
|
|
|
if (f0r_init() < 0) {
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module.\n");
|
2010-09-24 03:32:22 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
f0r_get_plugin_info(&s->plugin_info);
|
|
|
|
pi = &s->plugin_info;
|
2010-11-30 22:14:36 +02:00
|
|
|
if (pi->plugin_type != type) {
|
2010-09-24 03:32:22 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
2014-02-27 15:41:57 +03:00
|
|
|
"Invalid type '%s' for this plugin\n",
|
2010-11-30 22:14:36 +02:00
|
|
|
pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
|
2010-09-24 03:32:22 +03:00
|
|
|
pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" :
|
|
|
|
pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" :
|
|
|
|
pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2012-06-25 07:31:38 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE,
|
2010-09-24 03:32:22 +03:00
|
|
|
"name:%s author:'%s' explanation:'%s' color_model:%s "
|
|
|
|
"frei0r_version:%d version:%d.%d num_params:%d\n",
|
|
|
|
pi->name, pi->author, pi->explanation,
|
|
|
|
pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" :
|
|
|
|
pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" :
|
|
|
|
pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown",
|
|
|
|
pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 10:26:39 +03:00
|
|
|
static av_cold int filter_init(AVFilterContext *ctx)
|
2010-11-30 22:14:36 +02:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_FILTER);
|
2010-11-30 22:14:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 03:32:22 +03:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
|
|
|
|
|
|
|
if (s->destruct && s->instance)
|
|
|
|
s->destruct(s->instance);
|
|
|
|
if (s->deinit)
|
|
|
|
s->deinit();
|
|
|
|
if (s->dl_handle)
|
|
|
|
dlclose(s->dl_handle);
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int config_input_props(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
|
2013-03-18 23:31:54 +03:00
|
|
|
if (s->destruct && s->instance)
|
|
|
|
s->destruct(s->instance);
|
2013-03-18 22:44:36 +03:00
|
|
|
if (!(s->instance = s->construct(inlink->w, inlink->h))) {
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
|
2010-09-24 03:32:22 +03:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
return set_params(ctx, s->params);
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
AVFilterFormats *formats = NULL;
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2010-09-24 03:32:22 +03:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
if (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_format(&formats, AV_PIX_FMT_BGRA)) < 0)
|
|
|
|
return ret;
|
2013-03-18 22:44:36 +03:00
|
|
|
} else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_format(&formats, AV_PIX_FMT_RGBA)) < 0)
|
|
|
|
return ret;
|
2010-09-24 03:32:22 +03:00
|
|
|
} else { /* F0R_COLOR_MODEL_PACKED32 */
|
2012-10-06 13:10:34 +03:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = {
|
2020-11-14 20:10:39 +02:00
|
|
|
AV_PIX_FMT_BGRA, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_NONE
|
2010-09-24 03:32:22 +03:00
|
|
|
};
|
2012-05-30 11:12:55 +03:00
|
|
|
formats = ff_make_format_list(pix_fmts);
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!formats)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2015-04-03 19:55:18 +02:00
|
|
|
return ff_set_common_formats(ctx, formats);
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
2010-09-24 03:32:22 +03:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = inlink->dst->priv;
|
2010-09-24 03:32:22 +03:00
|
|
|
AVFilterLink *outlink = inlink->dst->outputs[0];
|
2022-08-24 10:44:39 +02:00
|
|
|
/* align parameter is the line alignment, not the buffer alignment.
|
|
|
|
* frei0r expects line size to be width*4 so we want an align of 1
|
|
|
|
* to ensure lines aren't padded out. */
|
|
|
|
AVFrame *out = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 1);
|
2022-04-11 13:49:05 +02:00
|
|
|
if (!out)
|
|
|
|
goto fail;
|
2012-11-28 21:45:48 +03:00
|
|
|
|
2022-04-11 13:49:05 +02:00
|
|
|
av_frame_copy_props(out, in);
|
|
|
|
|
|
|
|
if (in->linesize[0] != out->linesize[0]) {
|
2022-08-24 10:44:39 +02:00
|
|
|
AVFrame *in2 = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 1);
|
2022-04-11 13:49:05 +02:00
|
|
|
if (!in2)
|
|
|
|
goto fail;
|
|
|
|
av_frame_copy(in2, in);
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_free(&in);
|
2022-04-11 13:49:05 +02:00
|
|
|
in = in2;
|
2012-11-28 21:45:48 +03:00
|
|
|
}
|
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
s->update(s->instance, in->pts * av_q2d(inlink->time_base) * 1000,
|
2012-11-28 21:45:48 +03:00
|
|
|
(const uint32_t *)in->data[0],
|
|
|
|
(uint32_t *)out->data[0]);
|
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_free(&in);
|
2012-11-28 21:45:48 +03:00
|
|
|
|
|
|
|
return ff_filter_frame(outlink, out);
|
2022-04-11 13:49:05 +02:00
|
|
|
fail:
|
|
|
|
av_frame_free(&in);
|
|
|
|
av_frame_free(&out);
|
|
|
|
return AVERROR(ENOMEM);
|
2010-09-24 03:32:22 +03:00
|
|
|
}
|
|
|
|
|
2020-11-19 12:53:10 +02:00
|
|
|
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
|
|
|
|
char *res, int res_len, int flags)
|
|
|
|
{
|
|
|
|
Frei0rContext *s = ctx->priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return set_params(ctx, s->params);
|
|
|
|
}
|
|
|
|
|
2013-02-25 23:21:29 +03:00
|
|
|
#define OFFSET(x) offsetof(Frei0rContext, x)
|
2013-04-12 16:47:16 +03:00
|
|
|
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
|
2020-11-19 12:53:10 +02:00
|
|
|
#define TFLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
|
2013-05-27 14:19:49 +03:00
|
|
|
static const AVOption frei0r_options[] = {
|
2013-02-25 23:21:29 +03:00
|
|
|
{ "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
|
2020-11-19 12:53:10 +02:00
|
|
|
{ "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = TFLAGS },
|
2013-09-07 15:13:50 +03:00
|
|
|
{ NULL }
|
2013-02-25 23:21:29 +03:00
|
|
|
};
|
|
|
|
|
2013-05-27 14:19:49 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(frei0r);
|
2013-02-25 23:21:29 +03:00
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vf_frei0r_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_input_props,
|
2012-11-28 21:45:48 +03:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-24 16:14:01 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_frei0r_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vf_frei0r = {
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "frei0r",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
|
|
|
|
.init = filter_init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.priv_size = sizeof(Frei0rContext),
|
|
|
|
.priv_class = &frei0r_class,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(avfilter_vf_frei0r_inputs),
|
|
|
|
FILTER_OUTPUTS(avfilter_vf_frei0r_outputs),
|
2021-09-27 12:07:35 +02:00
|
|
|
FILTER_QUERY_FUNC(query_formats),
|
2020-11-19 12:53:10 +02:00
|
|
|
.process_command = process_command,
|
2021-02-05 14:14:43 +02:00
|
|
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
|
2010-09-24 03:32:22 +03:00
|
|
|
};
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-13 10:26:39 +03:00
|
|
|
static av_cold int source_init(AVFilterContext *ctx)
|
2010-11-30 22:14:36 +02:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-07-26 18:24:55 +03:00
|
|
|
s->time_base.num = s->framerate.den;
|
|
|
|
s->time_base.den = s->framerate.num;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
return frei0r_init(ctx, s->dl_name, F0R_PLUGIN_TYPE_SOURCE);
|
2010-11-30 22:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int source_config_props(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = ctx->priv;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
|
2010-11-30 22:14:36 +02:00
|
|
|
return AVERROR(EINVAL);
|
2013-03-18 22:44:36 +03:00
|
|
|
outlink->w = s->w;
|
|
|
|
outlink->h = s->h;
|
|
|
|
outlink->time_base = s->time_base;
|
2015-01-17 15:46:21 +02:00
|
|
|
outlink->frame_rate = av_inv_q(s->time_base);
|
2012-03-10 05:02:05 +03:00
|
|
|
outlink->sample_aspect_ratio = (AVRational){1,1};
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 23:31:54 +03:00
|
|
|
if (s->destruct && s->instance)
|
|
|
|
s->destruct(s->instance);
|
2013-03-18 22:44:36 +03:00
|
|
|
if (!(s->instance = s->construct(outlink->w, outlink->h))) {
|
2014-02-27 15:41:57 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance.\n");
|
2010-11-30 22:14:36 +02:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2014-02-27 14:06:15 +03:00
|
|
|
if (!s->params) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "frei0r filter parameters not set.\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
return set_params(ctx, s->params);
|
2010-11-30 22:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int source_request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
Frei0rContext *s = outlink->src->priv;
|
2022-08-24 10:44:39 +02:00
|
|
|
AVFrame *frame = ff_default_get_video_buffer2(outlink, outlink->w, outlink->h, 1);
|
2012-07-15 10:47:01 +03:00
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
if (!frame)
|
2012-07-15 12:16:53 +03:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
frame->sample_aspect_ratio = (AVRational) {1, 1};
|
2013-03-18 22:44:36 +03:00
|
|
|
frame->pts = s->pts++;
|
2022-10-11 10:47:42 +02:00
|
|
|
frame->duration = 1;
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
s->update(s->instance, av_rescale_q(frame->pts, s->time_base, (AVRational){1,1000}),
|
2012-11-28 10:41:07 +03:00
|
|
|
NULL, (uint32_t *)frame->data[0]);
|
2010-11-30 22:14:36 +02:00
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
return ff_filter_frame(outlink, frame);
|
2010-11-30 22:14:36 +02:00
|
|
|
}
|
|
|
|
|
2013-05-27 14:19:49 +03:00
|
|
|
static const AVOption frei0r_src_options[] = {
|
2013-07-26 20:16:26 +03:00
|
|
|
{ "size", "Dimensions of the generated video.", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str = "320x240" }, .flags = FLAGS },
|
2016-06-09 05:00:22 +02:00
|
|
|
{ "framerate", NULL, OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, .flags = FLAGS },
|
2013-02-25 23:21:29 +03:00
|
|
|
{ "filter_name", NULL, OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
|
|
|
|
{ "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2013-05-27 14:19:49 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(frei0r_src);
|
2013-02-25 23:21:29 +03:00
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vsrc_frei0r_src_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.request_frame = source_request_frame,
|
|
|
|
.config_props = source_config_props
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vsrc_frei0r_src = {
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "frei0r_src",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
|
|
|
|
.priv_size = sizeof(Frei0rContext),
|
|
|
|
.priv_class = &frei0r_src_class,
|
|
|
|
.init = source_init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.inputs = NULL,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_OUTPUTS(avfilter_vsrc_frei0r_src_outputs),
|
2021-09-27 12:07:35 +02:00
|
|
|
FILTER_QUERY_FUNC(query_formats),
|
2010-11-30 22:14:36 +02:00
|
|
|
};
|