History

lavfi: add 'enable' command injection to filters supporting timeline.

Clément Bœsch committed 13 years ago

Commit 38853161 parent fdd93ea2 files · +49 −13Browse files

Showing the changes to libavfilter/avfilter.c (1 of 2 files). Show all

Unified · Split

libavfilter/avfilter.c+46−13
@@ -366,6 +366,49 @@ int ff_poll_frame(AVFilterLink *link) · 365 unmodified lines
366366 return min;
367367 }
368368
369+static const char *const var_names[] = { "t", "n", "pos", NULL };
370+enum { VAR_T, VAR_N, VAR_POS, VAR_VARS_NB };
371+
372+static int set_enable_expr(AVFilterContext *ctx, const char *expr)
373+{
374+ int ret;
375+ char *expr_dup;
376+ AVExpr *old = ctx->enable;
377+
378+ if (!(ctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)) {
379+ av_log(ctx, AV_LOG_ERROR, "Timeline ('enable' option) not supported "
380+ "with filter '%s'\n", ctx->filter->name);
381+ return AVERROR_PATCHWELCOME;
382+ }
383+
384+ expr_dup = av_strdup(expr);
385+ if (!expr_dup)
386+ return AVERROR(ENOMEM);
387+
388+ if (!ctx->var_values) {
389+ ctx->var_values = av_calloc(VAR_VARS_NB, sizeof(*ctx->var_values));
390+ if (!ctx->var_values) {
391+ av_free(expr_dup);
392+ return AVERROR(ENOMEM);
393+ }
394+ }
395+
396+ ret = av_expr_parse((AVExpr**)&ctx->enable, expr_dup, var_names,
397+ NULL, NULL, NULL, NULL, 0, ctx->priv);
398+ if (ret < 0) {
399+ av_log(ctx->priv, AV_LOG_ERROR,
400+ "Error when evaluating the expression '%s' for enable\n",
401+ expr_dup);
402+ av_free(expr_dup);
403+ return ret;
404+ }
405+
406+ av_expr_free(old);
407+ av_free(ctx->enable_str);
408+ ctx->enable_str = expr_dup;
409+ return 0;
410+}
411+
369412 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
370413 {
371414 if (pts == AV_NOPTS_VALUE)
@@ -381,6 +424,8 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha · 9 unmodified lines
381424 if(!strcmp(cmd, "ping")){
382425 av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
383426 return 0;
427+ }else if(!strcmp(cmd, "enable")) {
428+ return set_enable_expr(filter, arg);
384429 }else if(filter->filter->process_command) {
385430 return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
386431 }
@@ -634,9 +679,6 @@ void avfilter_free(AVFilterContext *filter) · 247 unmodified lines
634679 av_free(filter);
635680 }
636681
637−static const char *const var_names[] = { "t", "n", "pos", NULL };
638−enum { VAR_T, VAR_N, VAR_POS, VAR_VARS_NB };
639−
640682 static int process_options(AVFilterContext *ctx, AVDictionary **options,
641683 const char *args)
642684 {
@@ -707,16 +749,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 64 unmodified lines
707749 }
708750
709751 if (ctx->enable_str) {
710− if (!(ctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)) {
711− av_log(ctx, AV_LOG_ERROR, "Timeline ('enable' option) not supported "
712− "with filter '%s'\n", ctx->filter->name);
713− return AVERROR_PATCHWELCOME;
714− }
715− ctx->var_values = av_calloc(VAR_VARS_NB, sizeof(*ctx->var_values));
716− if (!ctx->var_values)
717− return AVERROR(ENOMEM);
718− ret = av_expr_parse((AVExpr**)&ctx->enable, ctx->enable_str, var_names,
719− NULL, NULL, NULL, NULL, 0, ctx->priv);
752+ ret = set_enable_expr(ctx, ctx->enable_str);
720753 if (ret < 0)
721754 return ret;
722755 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t