Commit badbd241 authored by Paul B Mahol's avatar Paul B Mahol

lavfi/aevalsrc: use AV_OPT_TYPE_DURATION

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 1e89f749
...@@ -58,8 +58,7 @@ typedef struct { ...@@ -58,8 +58,7 @@ typedef struct {
AVExpr *expr[8]; AVExpr *expr[8];
char *exprs; char *exprs;
int nb_samples; ///< number of samples per requested frame int nb_samples; ///< number of samples per requested frame
char *duration_str; ///< total duration of the generated audio int64_t duration;
double duration;
uint64_t n; uint64_t n;
double var_values[VAR_VARS_NB]; double var_values[VAR_VARS_NB];
} EvalContext; } EvalContext;
...@@ -73,8 +72,8 @@ static const AVOption aevalsrc_options[]= { ...@@ -73,8 +72,8 @@ static const AVOption aevalsrc_options[]= {
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS }, { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
{ "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "duration", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "duration", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
{ "d", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "d", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
{ "channel_layout", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "channel_layout", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{ "c", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "c", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
{NULL}, {NULL},
...@@ -135,16 +134,6 @@ static int init(AVFilterContext *ctx) ...@@ -135,16 +134,6 @@ static int init(AVFilterContext *ctx)
if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx))) if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx)))
goto end; goto end;
eval->duration = -1;
if (eval->duration_str) {
int64_t us = -1;
if ((ret = av_parse_time(&us, eval->duration_str, 1)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", eval->duration_str);
goto end;
}
eval->duration = (double)us / 1000000;
}
eval->n = 0; eval->n = 0;
end: end:
...@@ -162,7 +151,6 @@ static av_cold void uninit(AVFilterContext *ctx) ...@@ -162,7 +151,6 @@ static av_cold void uninit(AVFilterContext *ctx)
eval->expr[i] = NULL; eval->expr[i] = NULL;
} }
av_freep(&eval->chlayout_str); av_freep(&eval->chlayout_str);
av_freep(&eval->duration_str);
av_freep(&eval->sample_rate_str); av_freep(&eval->sample_rate_str);
} }
...@@ -179,7 +167,7 @@ static int config_props(AVFilterLink *outlink) ...@@ -179,7 +167,7 @@ static int config_props(AVFilterLink *outlink)
av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout); av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout);
av_log(outlink->src, AV_LOG_VERBOSE, av_log(outlink->src, AV_LOG_VERBOSE,
"sample_rate:%d chlayout:%s duration:%f\n", "sample_rate:%d chlayout:%s duration:%"PRId64"\n",
eval->sample_rate, buf, eval->duration); eval->sample_rate, buf, eval->duration);
return 0; return 0;
...@@ -204,7 +192,7 @@ static int request_frame(AVFilterLink *outlink) ...@@ -204,7 +192,7 @@ static int request_frame(AVFilterLink *outlink)
EvalContext *eval = outlink->src->priv; EvalContext *eval = outlink->src->priv;
AVFrame *samplesref; AVFrame *samplesref;
int i, j; int i, j;
double t = eval->n * (double)1/eval->sample_rate; int64_t t = av_rescale(eval->n, AV_TIME_BASE, eval->sample_rate);
if (eval->duration >= 0 && t >= eval->duration) if (eval->duration >= 0 && t >= eval->duration)
return AVERROR_EOF; return AVERROR_EOF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment