#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "avformat.h"
+#include "internal.h"
typedef struct ModPlugContext {
const AVClass *class;
int fsize; ///< constant frame size
int linesize; ///< line size in bytes
char *color_eval; ///< color eval user input expression
- int eval_err; ///< 1 if eval failed once, otherwise 0 (used to disable video)
+ AVExpr *expr; ///< parsed color eval expression
} ModPlugContext;
static const char *var_names[] = {
- "E", "PHI", "PI",
"x", "y",
"w", "h",
"t",
};
enum var_name {
- VAR_E, VAR_PHI, VAR_PI,
VAR_X, VAR_Y,
VAR_W, VAR_H,
VAR_TIME,
#define OFFSET(x) offsetof(ModPlugContext, x)
#define D AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- {"noise_reduction", "Enable noise reduction 0(off)-1(on)", OFFSET(noise_reduction), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
- {"reverb_depth", "Reverb level 0(quiet)-100(loud)", OFFSET(reverb_depth), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
- {"reverb_delay", "Reverb delay in ms, usually 40-200ms", OFFSET(reverb_delay), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
- {"bass_amount", "XBass level 0(quiet)-100(loud)", OFFSET(bass_amount), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
- {"bass_range", "XBass cutoff in Hz 10-100", OFFSET(bass_range), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
- {"surround_depth", "Surround level 0(quiet)-100(heavy)", OFFSET(surround_depth), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
- {"surround_delay", "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {"noise_reduction", "Enable noise reduction 0(off)-1(on)", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
+ {"reverb_depth", "Reverb level 0(quiet)-100(loud)", OFFSET(reverb_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"reverb_delay", "Reverb delay in ms, usually 40-200ms", OFFSET(reverb_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {"bass_amount", "XBass level 0(quiet)-100(loud)", OFFSET(bass_amount), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"bass_range", "XBass cutoff in Hz 10-100", OFFSET(bass_range), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_depth", "Surround level 0(quiet)-100(heavy)", OFFSET(surround_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_delay", "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
{"max_size", "Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)",
- OFFSET(max_size), FF_OPT_TYPE_INT, {.dbl = FF_MODPLUG_DEF_FILE_SIZE}, 0, FF_MODPLUG_MAX_FILE_SIZE, D},
- {"video_stream_expr", "Color formula", OFFSET(color_eval), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D},
- {"video_stream", "Make demuxer output a video stream", OFFSET(video_stream), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
- {"video_stream_w", "Video stream width in char (one char = 8x8px)", OFFSET(w), FF_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
- {"video_stream_h", "Video stream height in char (one char = 8x8px)", OFFSET(h), FF_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
- {"video_stream_ptxt", "Print speed, tempo, order, ... in video stream", OFFSET(print_textinfo), FF_OPT_TYPE_INT, {.dbl = 1}, 0, 1, D},
+ OFFSET(max_size), AV_OPT_TYPE_INT, {.dbl = FF_MODPLUG_DEF_FILE_SIZE}, 0, FF_MODPLUG_MAX_FILE_SIZE, D},
+ {"video_stream_expr", "Color formula", OFFSET(color_eval), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D},
+ {"video_stream", "Make demuxer output a video stream", OFFSET(video_stream), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
+ {"video_stream_w", "Video stream width in char (one char = 8x8px)", OFFSET(w), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
+ {"video_stream_h", "Video stream height in char (one char = 8x8px)", OFFSET(h), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D},
+ {"video_stream_ptxt", "Print speed, tempo, order, ... in video stream", OFFSET(print_textinfo), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, D},
{NULL},
};
"but demuxing is likely to fail due to incomplete buffer\n",
sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz);
}
+
+ if (modplug->color_eval) {
+ int r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names,
+ NULL, NULL, NULL, NULL, 0, s);
+ if (r < 0)
+ return r;
+ }
+
modplug->buf = av_malloc(modplug->max_size);
if (!modplug->buf)
return AVERROR(ENOMEM);
if (!modplug->f)
return AVERROR_INVALIDDATA;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
- av_set_pts_info(st, 64, 1, 1000);
+ avpriv_set_pts_info(st, 64, 1, 1000);
st->duration = ModPlug_GetLength(modplug->f);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_PCM_S16LE;
modplug->ts_per_packet = 1000*AUDIO_PKT_SIZE / (4*44100.);
if (modplug->video_stream) {
- AVStream *vst = av_new_stream(s, 1);
+ AVStream *vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
- av_set_pts_info(vst, 64, 1, 1000);
+ avpriv_set_pts_info(vst, 64, 1, 1000);
vst->duration = st->duration;
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = CODEC_ID_XBIN;
if (modplug->video_switch) {
double var_values[VAR_VARS_NB];
- var_values[VAR_E ] = M_E;
- var_values[VAR_PHI ] = M_PHI;
- var_values[VAR_PI ] = M_PI;
var_values[VAR_W ] = modplug->w;
var_values[VAR_H ] = modplug->h;
var_values[VAR_TIME ] = modplug->packet_count * modplug->ts_per_packet;
PRINT_INFO(5, "ts", VAR_TIME);
}
- if (modplug->color_eval && !modplug->eval_err) {
+ if (modplug->expr) {
int x, y;
for (y = 0; y < modplug->h; y++) {
for (x = 0; x < modplug->w; x++) {
double color;
-
var_values[VAR_X] = x;
var_values[VAR_Y] = y;
- if (av_expr_parse_and_eval(&color, modplug->color_eval,
- var_names, var_values,
- NULL, NULL, NULL, NULL, NULL, 0, s) < 0) {
- av_log(s, AV_LOG_ERROR,
- "Error while evaluating the expression '%s' with x=%d y=%d\n",
- modplug->color_eval, x, y);
- modplug->eval_err = 1;
- return 0;
- }
+ color = av_expr_eval(modplug->expr, var_values, NULL);
pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4;
}
}