char *sample_rate_str;
int sample_rate;
int64_t chlayout;
+ char *chlayout_str;
int nb_channels;
int64_t pts;
AVExpr *expr[8];
#define OFFSET(x) offsetof(EvalContext, x)
-static const AVOption eval_options[]= {
+static const AVOption aevalsrc_options[]= {
{ "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
{ "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX },
{ "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX },
{ "duration", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
{ "d", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
+ { "channel_layout", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
+ { "c", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
{NULL},
};
-static const char *eval_get_name(void *ctx)
-{
- return "aevalsrc";
-}
-
-static const AVClass eval_class = {
- "AEvalSrcContext",
- eval_get_name,
- eval_options
-};
+AVFILTER_DEFINE_CLASS(aevalsrc);
-static int init(AVFilterContext *ctx, const char *args, void *opaque)
+static int init(AVFilterContext *ctx, const char *args)
{
EvalContext *eval = ctx->priv;
char *args1 = av_strdup(args);
char *expr, *buf, *bufptr;
int ret, i;
- eval->class = &eval_class;
+ eval->class = &aevalsrc_class;
av_opt_set_defaults(eval);
/* parse expressions */
buf = args1;
i = 0;
while (expr = av_strtok(buf, ":", &bufptr)) {
- if (i >= 8) {
- av_log(ctx, AV_LOG_ERROR,
- "More than 8 expressions provided, unsupported.\n");
- ret = AVERROR(EINVAL);
- return ret;
- }
ret = av_expr_parse(&eval->expr[i], expr, var_names,
NULL, NULL, NULL, NULL, 0, ctx);
if (ret < 0)
}
buf = NULL;
}
-
- /* guess channel layout from nb expressions/channels */
eval->nb_channels = i;
- eval->chlayout = av_get_default_channel_layout(eval->nb_channels);
- if (!eval->chlayout) {
- av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n",
- eval->nb_channels);
- ret = AVERROR(EINVAL);
- goto end;
- }
if (bufptr && (ret = av_set_options_string(eval, bufptr, "=", ":")) < 0)
goto end;
+ if (eval->chlayout_str) {
+ int n;
+ ret = ff_parse_channel_layout(&eval->chlayout, eval->chlayout_str, ctx);
+ if (ret < 0)
+ goto end;
+
+ n = av_get_channel_layout_nb_channels(eval->chlayout);
+ if (n != eval->nb_channels) {
+ av_log(ctx, AV_LOG_ERROR,
+ "Mismatch between the specified number of channels '%d' "
+ "and the number of channels '%d' in the specified channel layout '%s'\n",
+ eval->nb_channels, n, eval->chlayout_str);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+ } else {
+ /* guess channel layout from nb expressions/channels */
+ eval->chlayout = av_get_default_channel_layout(eval->nb_channels);
+ if (!eval->chlayout) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n",
+ eval->nb_channels);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+ }
+
if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx)))
goto end;
av_expr_free(eval->expr[i]);
eval->expr[i] = NULL;
}
+ av_freep(&eval->chlayout_str);
av_freep(&eval->duration_str);
av_freep(&eval->sample_rate_str);
}
av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout);
- av_log(outlink->src, AV_LOG_INFO,
+ av_log(outlink->src, AV_LOG_VERBOSE,
"sample_rate:%d chlayout:%s duration:%f\n",
eval->sample_rate, buf, eval->duration);
int64_t chlayouts[] = { eval->chlayout, -1 };
int sample_rates[] = { eval->sample_rate, -1 };
- avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts));
+ ff_set_common_formats (ctx, ff_make_format_list(sample_fmts));
ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
- ff_set_common_samplerates(ctx, avfilter_make_format_list(sample_rates));
+ ff_set_common_samplerates(ctx, ff_make_format_list(sample_rates));
return 0;
}
eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate;
for (j = 0; j < eval->nb_channels; j++) {
- *((double *) samplesref->data[j] + i) =
+ *((double *) samplesref->extended_data[j] + i) =
av_expr_eval(eval->expr[j], eval->var_values, NULL);
}
}