| @@ -366,6 +366,49 @@ int ff_poll_frame(AVFilterLink *link) · 365 unmodified lines |
| 366 | return min; | 366 | return min; |
| 367 | } | 367 | } |
| 368 | | 368 | |
| | 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 | |
| 369 | void ff_update_link_current_pts(AVFilterLink *link, int64_t pts) | 412 | void 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 | |
| 637 | static const char *const var_names[] = { "t", "n", "pos", NULL }; | | |
| 638 | enum { VAR_T, VAR_N, VAR_POS, VAR_VARS_NB }; | | |
| 639 | | | |
| 640 | static int process_options(AVFilterContext *ctx, AVDictionary **options, | 682 | static 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 | } |