Merge commit '96a47364d1cf346a5d0437e054b1b10d44d8d969'
authorJames Almer <jamrial@gmail.com>
Sat, 21 Oct 2017 18:40:14 +0000 (15:40 -0300)
committerJames Almer <jamrial@gmail.com>
Sat, 21 Oct 2017 18:40:14 +0000 (15:40 -0300)
* commit '96a47364d1cf346a5d0437e054b1b10d44d8d969':
  lavfi: Drop deprecated non-const filter retrieval

Merged-by: James Almer <jamrial@gmail.com>
1  2 
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/avfiltergraph.c
libavfilter/version.h

@@@ -483,103 -290,9 +483,100 @@@ int ff_poll_frame(AVFilterLink *link
      return min;
  }
  
 +static const char *const var_names[] = {
 +    "t",
 +    "n",
 +    "pos",
 +    "w",
 +    "h",
 +    NULL
 +};
 +
 +enum {
 +    VAR_T,
 +    VAR_N,
 +    VAR_POS,
 +    VAR_W,
 +    VAR_H,
 +    VAR_VARS_NB
 +};
 +
 +static int set_enable_expr(AVFilterContext *ctx, const char *expr)
 +{
 +    int ret;
 +    char *expr_dup;
 +    AVExpr *old = ctx->enable;
 +
 +    if (!(ctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)) {
 +        av_log(ctx, AV_LOG_ERROR, "Timeline ('enable' option) not supported "
 +               "with filter '%s'\n", ctx->filter->name);
 +        return AVERROR_PATCHWELCOME;
 +    }
 +
 +    expr_dup = av_strdup(expr);
 +    if (!expr_dup)
 +        return AVERROR(ENOMEM);
 +
 +    if (!ctx->var_values) {
 +        ctx->var_values = av_calloc(VAR_VARS_NB, sizeof(*ctx->var_values));
 +        if (!ctx->var_values) {
 +            av_free(expr_dup);
 +            return AVERROR(ENOMEM);
 +        }
 +    }
 +
 +    ret = av_expr_parse((AVExpr**)&ctx->enable, expr_dup, var_names,
 +                        NULL, NULL, NULL, NULL, 0, ctx->priv);
 +    if (ret < 0) {
 +        av_log(ctx->priv, AV_LOG_ERROR,
 +               "Error when evaluating the expression '%s' for enable\n",
 +               expr_dup);
 +        av_free(expr_dup);
 +        return ret;
 +    }
 +
 +    av_expr_free(old);
 +    av_free(ctx->enable_str);
 +    ctx->enable_str = expr_dup;
 +    return 0;
 +}
 +
 +void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
 +{
 +    if (pts == AV_NOPTS_VALUE)
 +        return;
 +    link->current_pts = pts;
 +    link->current_pts_us = av_rescale_q(pts, link->time_base, AV_TIME_BASE_Q);
 +    /* TODO use duration */
 +    if (link->graph && link->age_index >= 0)
 +        ff_avfilter_graph_update_heap(link->graph, link);
 +}
 +
 +int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
 +{
 +    if(!strcmp(cmd, "ping")){
 +        char local_res[256] = {0};
 +
 +        if (!res) {
 +            res = local_res;
 +            res_len = sizeof(local_res);
 +        }
 +        av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
 +        if (res == local_res)
 +            av_log(filter, AV_LOG_INFO, "%s", res);
 +        return 0;
 +    }else if(!strcmp(cmd, "enable")) {
 +        return set_enable_expr(filter, arg);
 +    }else if(filter->filter->process_command) {
 +        return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
 +    }
 +    return AVERROR(ENOSYS);
 +}
 +
  static AVFilter *first_filter;
 +static AVFilter **last_filter = &first_filter;
  
- #if !FF_API_NOCONST_GET_NAME
- const
- #endif
- AVFilter *avfilter_get_by_name(const char *name)
+ const AVFilter *avfilter_get_by_name(const char *name)
  {
      const AVFilter *f = NULL;
  
Simple merge
@@@ -447,52 -276,24 +447,52 @@@ static int query_formats(AVFilterGraph 
              if (!link)
                  continue;
  
 -            if (link->in_formats != link->out_formats &&
 -                !ff_merge_formats(link->in_formats,
 -                                        link->out_formats))
 -                convert_needed = 1;
 -            if (link->type == AVMEDIA_TYPE_AUDIO) {
 -                if (link->in_channel_layouts != link->out_channel_layouts &&
 -                    !ff_merge_channel_layouts(link->in_channel_layouts,
 -                                              link->out_channel_layouts))
 -                    convert_needed = 1;
 -                if (link->in_samplerates != link->out_samplerates &&
 -                    !ff_merge_samplerates(link->in_samplerates,
 -                                          link->out_samplerates))
 +            if (link->in_formats != link->out_formats
 +                && link->in_formats && link->out_formats)
 +                if (!can_merge_formats(link->in_formats, link->out_formats,
 +                                      link->type, 0))
                      convert_needed = 1;
 +            if (link->type == AVMEDIA_TYPE_AUDIO) {
 +                if (link->in_samplerates != link->out_samplerates
 +                    && link->in_samplerates && link->out_samplerates)
 +                    if (!can_merge_formats(link->in_samplerates,
 +                                           link->out_samplerates,
 +                                           0, 1))
 +                        convert_needed = 1;
 +            }
 +
 +#define MERGE_DISPATCH(field, statement)                                     \
 +            if (!(link->in_ ## field && link->out_ ## field)) {              \
 +                count_delayed++;                                             \
 +            } else if (link->in_ ## field == link->out_ ## field) {          \
 +                count_already_merged++;                                      \
 +            } else if (!convert_needed) {                                    \
 +                count_merged++;                                              \
 +                statement                                                    \
              }
  
 +            if (link->type == AVMEDIA_TYPE_AUDIO) {
 +                MERGE_DISPATCH(channel_layouts,
 +                    if (!ff_merge_channel_layouts(link->in_channel_layouts,
 +                                                  link->out_channel_layouts))
 +                        convert_needed = 1;
 +                )
 +                MERGE_DISPATCH(samplerates,
 +                    if (!ff_merge_samplerates(link->in_samplerates,
 +                                              link->out_samplerates))
 +                        convert_needed = 1;
 +                )
 +            }
 +            MERGE_DISPATCH(formats,
 +                if (!ff_merge_formats(link->in_formats, link->out_formats,
 +                                      link->type))
 +                    convert_needed = 1;
 +            )
 +#undef MERGE_DISPATCH
 +
              if (convert_needed) {
                  AVFilterContext *convert;
-                 AVFilter *filter;
+                 const AVFilter *filter;
                  AVFilterLink *inlink, *outlink;
                  char scale_args[256];
                  char inst_name[30];
   * the public API and may change, break or disappear at any time.
   */
  
- #ifndef FF_API_NOCONST_GET_NAME
- #define FF_API_NOCONST_GET_NAME             (LIBAVFILTER_VERSION_MAJOR < 7)
- #endif
 +#ifndef FF_API_OLD_FILTER_OPTS_ERROR
 +#define FF_API_OLD_FILTER_OPTS_ERROR        (LIBAVFILTER_VERSION_MAJOR < 8)
 +#endif
 +#ifndef FF_API_LAVR_OPTS
 +#define FF_API_LAVR_OPTS                    (LIBAVFILTER_VERSION_MAJOR < 8)
 +#endif
 +
  #endif /* AVFILTER_VERSION_H */