2010-09-24 02:32:22 +02:00
|
|
|
/*
|
2010-11-28 11:22:58 +01:00
|
|
|
* Copyright (c) 2010 Stefano Sabatini
|
2010-09-24 02:32:22 +02: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DEBUG */
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <frei0r.h>
|
2012-08-16 13:24:26 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
2010-09-27 18:23:43 +02:00
|
|
|
#include "libavutil/avstring.h"
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/imgutils.h"
|
2012-08-16 13:24:26 +02:00
|
|
|
#include "libavutil/internal.h"
|
2011-07-05 00:42:31 +02:00
|
|
|
#include "libavutil/mathematics.h"
|
2012-08-16 13:24:26 +02:00
|
|
|
#include "libavutil/mem.h"
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/parseutils.h"
|
2010-09-24 02:32:22 +02:00
|
|
|
#include "avfilter.h"
|
2012-05-30 10:12:55 +02:00
|
|
|
#include "formats.h"
|
2012-06-12 20:12:42 +02:00
|
|
|
#include "internal.h"
|
2012-05-30 11:20:32 +02:00
|
|
|
#include "video.h"
|
2010-09-24 02:32:22 +02: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 {
|
|
|
|
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;
|
|
|
|
char params[256];
|
2010-11-30 21:14:36 +01:00
|
|
|
|
|
|
|
/* only used by the source */
|
|
|
|
int w, h;
|
|
|
|
AVRational time_base;
|
|
|
|
uint64_t pts;
|
2010-09-24 02:32:22 +02:00
|
|
|
} Frei0rContext;
|
|
|
|
|
|
|
|
static void *load_sym(AVFilterContext *ctx, const char *sym_name)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
void *sym = dlsym(frei0r->dl_handle, sym_name);
|
|
|
|
if (!sym)
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not find symbol '%s' in loaded module\n", sym_name);
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_param(AVFilterContext *ctx, f0r_param_info_t info, int index, char *param)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
union {
|
|
|
|
double d;
|
|
|
|
f0r_param_color_t col;
|
|
|
|
f0r_param_position_t pos;
|
|
|
|
} 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:
|
|
|
|
val.d = strtod(param, &tail);
|
|
|
|
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 15:37:48 +01:00
|
|
|
if (av_parse_color(rgba, param, -1, ctx) < 0)
|
2010-09-24 02:32:22 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
frei0r->set_param_value(frei0r->instance, &val, index);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for parameter '%s'\n",
|
|
|
|
param, info.name);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_params(AVFilterContext *ctx, const char *params)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < frei0r->plugin_info.num_params; i++) {
|
|
|
|
f0r_param_info_t info;
|
|
|
|
char *param;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
frei0r->get_param_info(&info, i);
|
|
|
|
|
|
|
|
if (*params) {
|
|
|
|
if (!(param = av_get_token(¶ms, ":")))
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
params++; /* skip ':' */
|
|
|
|
ret = set_param(ctx, info, i, param);
|
|
|
|
av_free(param);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE,
|
2010-09-24 02:32:22 +02:00
|
|
|
"idx:%d name:'%s' type:%s explanation:'%s' ",
|
|
|
|
i, info.name,
|
|
|
|
info.type == F0R_PARAM_BOOL ? "bool" :
|
|
|
|
info.type == F0R_PARAM_DOUBLE ? "double" :
|
|
|
|
info.type == F0R_PARAM_COLOR ? "color" :
|
|
|
|
info.type == F0R_PARAM_POSITION ? "position" :
|
|
|
|
info.type == F0R_PARAM_STRING ? "string" : "unknown",
|
|
|
|
info.explanation);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "value:");
|
2010-09-24 02:32:22 +02:00
|
|
|
switch (info.type) {
|
|
|
|
void *v;
|
|
|
|
double d;
|
|
|
|
char s[128];
|
|
|
|
f0r_param_color_t col;
|
|
|
|
f0r_param_position_t pos;
|
|
|
|
|
|
|
|
case F0R_PARAM_BOOL:
|
|
|
|
v = &d;
|
|
|
|
frei0r->get_param_value(frei0r->instance, v, i);
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "%s", d >= 0.5 && d <= 1.0 ? "y" : "n");
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
|
|
|
case F0R_PARAM_DOUBLE:
|
|
|
|
v = &d;
|
|
|
|
frei0r->get_param_value(frei0r->instance, v, i);
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "%f", d);
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
|
|
|
case F0R_PARAM_COLOR:
|
|
|
|
v = &col;
|
|
|
|
frei0r->get_param_value(frei0r->instance, v, i);
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "%f/%f/%f", col.r, col.g, col.b);
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
|
|
|
case F0R_PARAM_POSITION:
|
|
|
|
v = &pos;
|
|
|
|
frei0r->get_param_value(frei0r->instance, v, i);
|
2012-12-31 00:29:36 +01:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "%f/%f", pos.x, pos.y);
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
|
|
|
default: /* F0R_PARAM_STRING */
|
|
|
|
v = s;
|
|
|
|
frei0r->get_param_value(frei0r->instance, v, i);
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "'%s'\n", s);
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "\n");
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-16 10:45:25 +01:00
|
|
|
static int load_path(AVFilterContext *ctx, void **handle_ptr, const char *prefix, const char *name)
|
2010-09-24 02:32:22 +02:00
|
|
|
{
|
2012-11-16 10:45:25 +01:00
|
|
|
char *path = av_asprintf("%s%s%s", prefix, name, SLIBSUF);
|
|
|
|
if (!path)
|
|
|
|
return AVERROR(ENOMEM);
|
2010-09-24 02:32:22 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Looking for frei0r effect in '%s'\n", path);
|
2012-11-16 10:45:25 +01:00
|
|
|
*handle_ptr = dlopen(path, RTLD_NOW|RTLD_LOCAL);
|
|
|
|
av_free(path);
|
|
|
|
return 0;
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
|
|
|
|
2010-11-30 21:14:36 +01:00
|
|
|
static av_cold int frei0r_init(AVFilterContext *ctx,
|
|
|
|
const char *dl_name, int type)
|
2010-09-24 02:32:22 +02:00
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
f0r_init_f f0r_init;
|
|
|
|
f0r_get_plugin_info_f f0r_get_plugin_info;
|
|
|
|
f0r_plugin_info_t *pi;
|
2010-11-30 21:14:36 +01:00
|
|
|
char *path;
|
2012-11-16 10:45:25 +01:00
|
|
|
int ret = 0;
|
2010-09-24 02:32:22 +02:00
|
|
|
|
2012-10-29 18:07:19 +01:00
|
|
|
/* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */
|
2010-09-24 02:32:22 +02:00
|
|
|
if ((path = av_strdup(getenv("FREI0R_PATH")))) {
|
2012-10-11 01:28:55 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char *separator = ";";
|
|
|
|
#else
|
|
|
|
const char *separator = ":";
|
|
|
|
#endif
|
2010-09-24 02:32:22 +02:00
|
|
|
char *p, *ptr = NULL;
|
2012-10-29 18:44:27 +01: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 10:58:37 +01:00
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto check_path_end;
|
2012-10-29 18:44:27 +01:00
|
|
|
}
|
2012-11-16 10:45:25 +01:00
|
|
|
ret = load_path(ctx, &frei0r->dl_handle, p1, dl_name);
|
2012-10-29 18:44:27 +01:00
|
|
|
av_free(p1);
|
2012-11-16 10:58:37 +01:00
|
|
|
if (ret < 0)
|
|
|
|
goto check_path_end;
|
2012-10-29 18:44:27 +01:00
|
|
|
if (frei0r->dl_handle)
|
2010-09-24 02:32:22 +02:00
|
|
|
break;
|
2012-10-29 18:44:27 +01:00
|
|
|
}
|
2012-11-16 10:58:37 +01:00
|
|
|
|
|
|
|
check_path_end:
|
2010-09-24 02:32:22 +02:00
|
|
|
av_free(path);
|
2012-11-16 10:58:37 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
2010-09-24 11:15:27 +02:00
|
|
|
if (!frei0r->dl_handle && (path = getenv("HOME"))) {
|
2012-10-29 18:33:11 +01:00
|
|
|
char *prefix = av_asprintf("%s/.frei0r-1/lib/", path);
|
|
|
|
if (!prefix)
|
|
|
|
return AVERROR(ENOMEM);
|
2012-11-16 10:45:25 +01:00
|
|
|
ret = load_path(ctx, &frei0r->dl_handle, prefix, dl_name);
|
2012-10-29 18:33:11 +01:00
|
|
|
av_free(prefix);
|
2012-11-16 10:45:25 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (!frei0r->dl_handle) {
|
|
|
|
ret = load_path(ctx, &frei0r->dl_handle, "/usr/local/lib/frei0r-1/", dl_name);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (!frei0r->dl_handle) {
|
|
|
|
ret = load_path(ctx, &frei0r->dl_handle, "/usr/lib/frei0r-1/", dl_name);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
|
|
|
if (!frei0r->dl_handle) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'\n", dl_name);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(f0r_init = load_sym(ctx, "f0r_init" )) ||
|
|
|
|
!(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) ||
|
|
|
|
!(frei0r->get_param_info = load_sym(ctx, "f0r_get_param_info" )) ||
|
|
|
|
!(frei0r->get_param_value = load_sym(ctx, "f0r_get_param_value")) ||
|
|
|
|
!(frei0r->set_param_value = load_sym(ctx, "f0r_set_param_value")) ||
|
|
|
|
!(frei0r->update = load_sym(ctx, "f0r_update" )) ||
|
|
|
|
!(frei0r->construct = load_sym(ctx, "f0r_construct" )) ||
|
|
|
|
!(frei0r->destruct = load_sym(ctx, "f0r_destruct" )) ||
|
|
|
|
!(frei0r->deinit = load_sym(ctx, "f0r_deinit" )))
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
|
|
|
|
if (f0r_init() < 0) {
|
2012-09-01 16:52:34 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module\n");
|
2010-09-24 02:32:22 +02:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
f0r_get_plugin_info(&frei0r->plugin_info);
|
|
|
|
pi = &frei0r->plugin_info;
|
2010-11-30 21:14:36 +01:00
|
|
|
if (pi->plugin_type != type) {
|
2010-09-24 02:32:22 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
2010-11-30 21:14:36 +01:00
|
|
|
"Invalid type '%s' for the plugin\n",
|
|
|
|
pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" :
|
2010-09-24 02:32:22 +02: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 06:31:38 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE,
|
2010-09-24 02:32:22 +02: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;
|
|
|
|
}
|
|
|
|
|
2012-06-21 07:55:56 +02:00
|
|
|
static av_cold int filter_init(AVFilterContext *ctx, const char *args)
|
2010-11-30 21:14:36 +01:00
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
2010-11-30 21:14:41 +01:00
|
|
|
char dl_name[1024], c;
|
2010-11-30 21:14:36 +01:00
|
|
|
*frei0r->params = 0;
|
|
|
|
|
|
|
|
if (args)
|
2010-11-30 21:14:41 +01:00
|
|
|
sscanf(args, "%1023[^:=]%c%255c", dl_name, &c, frei0r->params);
|
2010-11-30 21:14:36 +01:00
|
|
|
|
|
|
|
return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_FILTER);
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:32:22 +02:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
|
2010-11-26 00:51:37 +01:00
|
|
|
if (frei0r->destruct && frei0r->instance)
|
2010-09-24 02:32:22 +02:00
|
|
|
frei0r->destruct(frei0r->instance);
|
|
|
|
if (frei0r->deinit)
|
|
|
|
frei0r->deinit();
|
|
|
|
if (frei0r->dl_handle)
|
|
|
|
dlclose(frei0r->dl_handle);
|
|
|
|
|
|
|
|
memset(frei0r, 0, sizeof(*frei0r));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_input_props(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
|
|
|
|
if (!(frei0r->instance = frei0r->construct(inlink->w, inlink->h))) {
|
2012-09-01 16:52:34 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
|
2010-09-24 02:32:22 +02:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_params(ctx, frei0r->params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
AVFilterFormats *formats = NULL;
|
|
|
|
|
|
|
|
if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
|
2012-10-06 12:10:34 +02:00
|
|
|
ff_add_format(&formats, AV_PIX_FMT_BGRA);
|
2010-09-24 02:32:22 +02:00
|
|
|
} else if (frei0r->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
|
2012-10-06 12:10:34 +02:00
|
|
|
ff_add_format(&formats, AV_PIX_FMT_RGBA);
|
2010-09-24 02:32:22 +02:00
|
|
|
} else { /* F0R_COLOR_MODEL_PACKED32 */
|
2012-10-06 12:10:34 +02:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = {
|
|
|
|
AV_PIX_FMT_BGRA, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_ARGB, AV_PIX_FMT_NONE
|
2010-09-24 02:32:22 +02:00
|
|
|
};
|
2012-05-30 10:12:55 +02:00
|
|
|
formats = ff_make_format_list(pix_fmts);
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!formats)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2012-05-30 10:12:55 +02:00
|
|
|
ff_set_common_formats(ctx, formats);
|
2010-09-24 02:32:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 19:45:48 +01:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
|
2010-09-24 02:32:22 +02:00
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = inlink->dst->priv;
|
|
|
|
AVFilterLink *outlink = inlink->dst->outputs[0];
|
2012-11-28 19:45:48 +01:00
|
|
|
AVFilterBufferRef *out;
|
|
|
|
|
|
|
|
out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
|
|
|
|
if (!out) {
|
|
|
|
avfilter_unref_bufferp(&in);
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
avfilter_copy_buffer_ref_props(out, in);
|
|
|
|
|
|
|
|
frei0r->update(frei0r->instance, in->pts * av_q2d(inlink->time_base) * 1000,
|
|
|
|
(const uint32_t *)in->data[0],
|
|
|
|
(uint32_t *)out->data[0]);
|
|
|
|
|
|
|
|
avfilter_unref_bufferp(&in);
|
|
|
|
|
|
|
|
return ff_filter_frame(outlink, out);
|
2010-09-24 02:32:22 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
static const AVFilterPad avfilter_vf_frei0r_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_input_props,
|
2012-11-28 19:45:48 +01:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-24 15:14:01 +02:00
|
|
|
.min_perms = AV_PERM_READ
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_frei0r_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-09-24 02:32:22 +02:00
|
|
|
AVFilter avfilter_vf_frei0r = {
|
|
|
|
.name = "frei0r",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Apply a frei0r effect."),
|
|
|
|
|
|
|
|
.query_formats = query_formats,
|
2010-11-30 21:14:36 +01:00
|
|
|
.init = filter_init,
|
2010-09-24 02:32:22 +02:00
|
|
|
.uninit = uninit,
|
|
|
|
|
|
|
|
.priv_size = sizeof(Frei0rContext),
|
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
.inputs = avfilter_vf_frei0r_inputs,
|
|
|
|
|
|
|
|
.outputs = avfilter_vf_frei0r_outputs,
|
2010-09-24 02:32:22 +02:00
|
|
|
};
|
2010-11-30 21:14:36 +01:00
|
|
|
|
2012-06-21 07:55:56 +02:00
|
|
|
static av_cold int source_init(AVFilterContext *ctx, const char *args)
|
2010-11-30 21:14:36 +01:00
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
char dl_name[1024], c;
|
|
|
|
char frame_size[128] = "";
|
|
|
|
char frame_rate[128] = "";
|
|
|
|
AVRational frame_rate_q;
|
|
|
|
|
|
|
|
memset(frei0r->params, 0, sizeof(frei0r->params));
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
sscanf(args, "%127[^:]:%127[^:]:%1023[^:=]%c%255c",
|
|
|
|
frame_size, frame_rate, dl_name, &c, frei0r->params);
|
|
|
|
|
|
|
|
if (av_parse_video_size(&frei0r->w, &frei0r->h, frame_size) < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", frame_size);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2012-06-20 19:17:25 +02:00
|
|
|
if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0) {
|
2010-11-30 21:14:36 +01:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", frame_rate);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
frei0r->time_base.num = frame_rate_q.den;
|
|
|
|
frei0r->time_base.den = frame_rate_q.num;
|
|
|
|
|
|
|
|
return frei0r_init(ctx, dl_name, F0R_PLUGIN_TYPE_SOURCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int source_config_props(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
Frei0rContext *frei0r = ctx->priv;
|
|
|
|
|
|
|
|
if (av_image_check_size(frei0r->w, frei0r->h, 0, ctx) < 0)
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
outlink->w = frei0r->w;
|
|
|
|
outlink->h = frei0r->h;
|
|
|
|
outlink->time_base = frei0r->time_base;
|
2012-03-10 03:02:05 +01:00
|
|
|
outlink->sample_aspect_ratio = (AVRational){1,1};
|
2010-11-30 21:14:36 +01:00
|
|
|
|
|
|
|
if (!(frei0r->instance = frei0r->construct(outlink->w, outlink->h))) {
|
2012-09-01 16:52:34 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Impossible to load frei0r instance\n");
|
2010-11-30 21:14:36 +01:00
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_params(ctx, frei0r->params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int source_request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
Frei0rContext *frei0r = outlink->src->priv;
|
2012-05-30 10:31:48 +02:00
|
|
|
AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
|
2012-07-15 09:47:01 +02:00
|
|
|
|
2012-07-15 11:16:53 +02:00
|
|
|
if (!picref)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2011-04-29 13:12:39 +02:00
|
|
|
picref->video->sample_aspect_ratio = (AVRational) {1, 1};
|
2010-11-30 21:14:36 +01:00
|
|
|
picref->pts = frei0r->pts++;
|
|
|
|
picref->pos = -1;
|
|
|
|
|
|
|
|
frei0r->update(frei0r->instance, av_rescale_q(picref->pts, frei0r->time_base, (AVRational){1,1000}),
|
|
|
|
NULL, (uint32_t *)picref->data[0]);
|
|
|
|
|
2012-11-28 19:45:48 +01:00
|
|
|
return ff_filter_frame(outlink, picref);
|
2010-11-30 21:14:36 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 15:14:01 +02: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
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-11-30 21:14:36 +01:00
|
|
|
AVFilter avfilter_vsrc_frei0r_src = {
|
|
|
|
.name = "frei0r_src",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Generate a frei0r source."),
|
|
|
|
|
|
|
|
.priv_size = sizeof(Frei0rContext),
|
|
|
|
.init = source_init,
|
|
|
|
.uninit = uninit,
|
|
|
|
|
|
|
|
.query_formats = query_formats,
|
|
|
|
|
2012-09-16 13:58:49 +02:00
|
|
|
.inputs = NULL,
|
2010-11-30 21:14:36 +01:00
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
.outputs = avfilter_vsrc_frei0r_src_outputs,
|
2010-11-30 21:14:36 +01:00
|
|
|
};
|