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

Unified · Split

2 files
  1. doc/filters.texi +3 −0
  2. libavfilter/avfilter.c +46 −13
doc/filters.texi+3−0
@@ -287,6 +287,9 @@ sequential number of the input frame, starting from 0 · 286 unmodified lines
287the position in the file of the input frame, NAN if unknown287the position in the file of the input frame, NAN if unknown
288@end table288@end table
289 289
290Additionally, these filters support an @option{enable} command that can be used
291to re-define the expression.
292
290Like any other filtering option, the @option{enable} option follows the same293Like any other filtering option, the @option{enable} option follows the same
291rules.294rules.
292 295
libavfilter/avfilter.c+46−13
@@ -366,6 +366,49 @@ int ff_poll_frame(AVFilterLink *link) · 365 unmodified lines
366 return min;366 return min;
367}367}
368 368
369static const char *const var_names[] = { "t", "n", "pos", NULL };
370enum { VAR_T, VAR_N, VAR_POS, VAR_VARS_NB };
371
372static 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
369void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)412void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
370{413{
371 if (pts == AV_NOPTS_VALUE)414 if (pts == AV_NOPTS_VALUE)
@@ -381,6 +424,8 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha · 9 unmodified lines
381 if(!strcmp(cmd, "ping")){424 if(!strcmp(cmd, "ping")){
382 av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);425 av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
383 return 0;426 return 0;
427 }else if(!strcmp(cmd, "enable")) {
428 return set_enable_expr(filter, arg);
384 }else if(filter->filter->process_command) {429 }else if(filter->filter->process_command) {
385 return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);430 return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
386 }431 }
@@ -634,9 +679,6 @@ void avfilter_free(AVFilterContext *filter) · 247 unmodified lines
634 av_free(filter);679 av_free(filter);
635}680}
636 681
637static const char *const var_names[] = { "t", "n", "pos", NULL };
638enum { VAR_T, VAR_N, VAR_POS, VAR_VARS_NB };
639
640static int process_options(AVFilterContext *ctx, AVDictionary **options,682static int process_options(AVFilterContext *ctx, AVDictionary **options,
641 const char *args)683 const char *args)
642{684{
@@ -707,16 +749,7 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 64 unmodified lines
707 }749 }
708 750
709 if (ctx->enable_str) {751 if (ctx->enable_str) {
710 if (!(ctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)) {752 ret = set_enable_expr(ctx, ctx->enable_str);
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);
720 if (ret < 0)753 if (ret < 0)
721 return ret;754 return ret;
722 }755 }

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