[FFmpeg-devel] [PATCH 1/5] Change eval internal functions, ff_parse_expr() and ff_parse_and_eval_expr() interface.

Michael Niedermayer michaelni
Mon May 17 00:53:16 CEST 2010


On Sun, May 16, 2010 at 02:42:00AM +0200, Stefano Sabatini wrote:
> On date Friday 2010-05-14 00:22:56 +0200, Michael Niedermayer encoded:
> > On Thu, May 13, 2010 at 12:39:05AM +0200, Stefano Sabatini wrote:
> [...]
> > > > From 0096d85e5deec5deb7114dc5165d59e17d9e8391 Mon Sep 17 00:00:00 2001
> > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > > > Date: Tue, 6 Apr 2010 00:13:04 +0200
> > > > Subject: [PATCH 2/3] Change ff_parse_expr() and ff_parse_and_eval_expr() interface.
> > > > 
> > > > Make them print error messages using a log_ctx rather than set a
> > > > constant error string in the Parser. A log_level_offset is used to
> > > > change the log_level of the log_ctx, for example to silence eventual
> > > > errors issued when evaluating the expression.
> > > > 
> > > > Allow the error message to be more expressive, as it is not anymore a
> > > > generic const char * string.
> > > [...]
> > > 
> > > Ping.
> > 
> > what the patch does is not in line with the recent AVClass changes
> 
> Updated.
> 
> Two questions:
> Is it necessary to bump minor when adding an option to AVCodecContext?

its probably a good idea


> 
> Is OK to bump micro when changing the ff_parse_expr() and
> ff_parse_and_eval_expr()? (see the thread "[RFC] Updating internl API
> policy").
> 
> Regards.
> -- 
> FFmpeg = Fantastic Fantastic Miracolous Porno Evanescent Game

>  avcodec.h |    2 ++
>  options.c |    3 ++-
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 36819623adda80b556a3af3bc38843fadfd0f9e5  0002-Add-log_level_offset-to-AVCodecContext.patch
> >From 32e45b3c8e98924373eb9dbb69881799cfe80393 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> Date: Sun, 16 May 2010 02:00:00 +0200
> Subject: [PATCH 2/5] Add log_level_offset to AVCodecContext.

looks ok
[...]

>  eval.c        |   20 +++++++++++---------
>  eval.h        |    8 ++++----
>  opt.c         |    8 ++++----
>  ratecontrol.c |    6 +++---
>  4 files changed, 22 insertions(+), 20 deletions(-)
> 879d5e6184cb04db3a33e9c211f9813eda4c8c2e  0003-Change-ff_parse_expr-and-ff_parse_and_eval_expr-inte.patch
> >From 3e705aeb643890ac1c0b9bbe7e38abf4878b8c46 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> Date: Tue, 6 Apr 2010 00:13:04 +0200
> Subject: [PATCH 3/5] Change ff_parse_expr() and ff_parse_and_eval_expr() interface.
> 
> Make them print error messages using a log_ctx rather than set a
> constant error string in the Parser.
> 
> Allow the error message to be more expressive, as it is not anymore a
> generic const char * string, and reference the provided input.
> ---
>  libavcodec/eval.c        |   20 +++++++++++---------
>  libavcodec/eval.h        |    8 ++++----
>  libavcodec/opt.c         |    8 ++++----
>  libavcodec/ratecontrol.c |    6 +++---
>  4 files changed, 22 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/eval.c b/libavcodec/eval.c
> index 0eadf1c..8d0b8b4 100644
> --- a/libavcodec/eval.c
> +++ b/libavcodec/eval.c
> @@ -39,7 +39,7 @@ typedef struct Parser{
>      double (* const *func2)(void *, double a, double b); // NULL terminated
>      const char * const *func2_name;          // NULL terminated
>      void *opaque;
> -    const char **error;
> +    void *log_ctx;
>  #define VARS 10
>      double var[VARS];
>  } Parser;
> @@ -201,7 +201,7 @@ static AVExpr * parse_primary(Parser *p) {
>  
>      p->s= strchr(p->s, '(');
>      if(p->s==NULL){
> -        *p->error = "undefined constant or missing (";
> +        av_log(p->log_ctx, AV_LOG_ERROR, "undefined constant or missing (\n");
>          p->s= next;
>          ff_free_expr(d);
>          return NULL;
> @@ -211,7 +211,7 @@ static AVExpr * parse_primary(Parser *p) {
>          av_freep(&d);
>          d = parse_expr(p);
>          if(p->s[0] != ')'){
> -            *p->error = "missing )";
> +            av_log(p->log_ctx, AV_LOG_ERROR, "missing )\n");
>              ff_free_expr(d);
>              return NULL;
>          }
> @@ -224,7 +224,7 @@ static AVExpr * parse_primary(Parser *p) {
>          d->param[1] = parse_expr(p);
>      }
>      if(p->s[0] != ')'){
> -        *p->error = "missing )";
> +        av_log(p->log_ctx, AV_LOG_ERROR, "missing )\n");
>          ff_free_expr(d);
>          return NULL;
>      }
> @@ -273,7 +273,7 @@ static AVExpr * parse_primary(Parser *p) {
>              }
>          }
>  
> -        *p->error = "unknown function";
> +        av_log(p->log_ctx, AV_LOG_ERROR, "unknown function\n");
>          ff_free_expr(d);
>          return NULL;
>      }
> @@ -373,7 +373,8 @@ AVExpr *ff_parse_expr(const char *s,
>                        const char * const *const_name,
>                        const char * const *func1_name, double (* const *func1)(void *, double),
>                        const char * const *func2_name, double (* const *func2)(void *, double, double),
> -               const char **error){
> +                      void *log_ctx)
> +{
>      Parser p;
>      AVExpr *e = NULL;
>      char *w = av_malloc(strlen(s) + 1);
> @@ -393,7 +394,7 @@ AVExpr *ff_parse_expr(const char *s,
>      p.func1_name = func1_name;
>      p.func2      = func2;
>      p.func2_name = func2_name;
> -    p.error= error;
> +    p.log_ctx    = log_ctx;
>  
>      e = parse_expr(&p);
>      if (!verify_expr(e)) {
> @@ -417,8 +418,9 @@ double ff_parse_and_eval_expr(const char *s,
>                                const char * const *const_name, const double *const_value,
>                                const char * const *func1_name, double (* const *func1)(void *, double),
>                                const char * const *func2_name, double (* const *func2)(void *, double, double),
> -               void *opaque, const char **error){
> -    AVExpr *e = ff_parse_expr(s, const_name, func1_name, func1, func2_name, func2, error);
> +                              void *opaque, void *log_ctx)
> +{
> +    AVExpr *e = ff_parse_expr(s, const_name, func1_name, func1, func2_name, func2, log_ctx);
>      double d;
>      if (!e) return NAN;
>      d = ff_eval_expr(e, const_value, opaque);
> diff --git a/libavcodec/eval.h b/libavcodec/eval.h
> index 0803397..fbf0437 100644
> --- a/libavcodec/eval.h
> +++ b/libavcodec/eval.h
> @@ -40,14 +40,14 @@ typedef struct AVExpr AVExpr;
>   * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
>   * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
>   * @param opaque a pointer which will be passed to all functions from func1 and func2
> - * @param error pointer to a char* which is set to an error message if something goes wrong
> + * @param log_ctx logging context
>   * @return the value of the expression
>   */
>  double ff_parse_and_eval_expr(const char *s,
>                                const char * const *const_name, const double *const_value,
>                                const char * const *func1_name, double (* const *func1)(void *, double),
>                                const char * const *func2_name, double (* const *func2)(void *, double, double),
> -               void *opaque, const char **error);
> +                              void *opaque, void *log_ctx);
>  
>  /**
>   * Parses an expression.
> @@ -58,7 +58,7 @@ double ff_parse_and_eval_expr(const char *s,
>   * @param func1 NULL terminated array of function pointers for functions which take 1 argument
>   * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
>   * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
> - * @param error pointer to a char* which is set to an error message if something goes wrong
> + * @param log_ctx logging context
>   * @return AVExpr which must be freed with ff_free_expr() by the user when it is not needed anymore
>   *         NULL if anything went wrong
>   */
> @@ -66,7 +66,7 @@ AVExpr *ff_parse_expr(const char *s,
>                        const char * const *const_name,
>                        const char * const *func1_name, double (* const *func1)(void *, double),
>                        const char * const *func2_name, double (* const *func2)(void *, double, double),
> -               const char **error);
> +                      void *log_ctx);
>  
>  /**
>   * Evaluates a previously parsed expression.
> diff --git a/libavcodec/opt.c b/libavcodec/opt.c
> index f9cba05..844c0ec 100644

> --- a/libavcodec/opt.c
> +++ b/libavcodec/opt.c
> @@ -147,7 +147,6 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
>              char buf[256];
>              int cmd=0;
>              double d;
> -            const char *error = NULL;
>  
>              if(*val == '+' || *val == '-')
>                  cmd= *(val++);
> @@ -156,7 +155,9 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
>                  buf[i]= val[i];
>              buf[i]=0;
>  
> -            d = ff_parse_and_eval_expr(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
> +            av_set_int(obj, "log_level_offset", AV_LOG_DEBUG - AV_LOG_QUIET);
> +            d = ff_parse_and_eval_expr(buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, obj);
> +            av_set_int(obj, "log_level_offset", 0);
>              if(isnan(d)) {
>                  const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0);
>                  if(o_named && o_named->type == FF_OPT_TYPE_CONST)

that could be a seperate patch

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100517/9d54fcd8/attachment.pgp>



More information about the ffmpeg-devel mailing list