Re: [FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

2015-03-20 Thread Stefano Sabatini
On date Tuesday 2015-03-17 12:46:32 +0100, Michael Niedermayer encoded:
> On Sun, Mar 15, 2015 at 02:59:58PM +0100, Stefano Sabatini wrote:
> > On date Friday 2015-03-13 20:05:35 +0100, Michael Niedermayer encoded:
> > > On Fri, Mar 13, 2015 at 05:16:53PM +0100, Stefano Sabatini wrote:
> > > > ---
> > > >  libavfilter/vf_eq.c | 56 
> > > > ++---
> > > >  1 file changed, 15 insertions(+), 41 deletions(-)
> > > 
> > > i would be more in favor of a function than a macro but LGTM either
> > > way, macros are harder to debug and all kind of line number based
> > > outputs are basically useless with multiline macros, be that
> > > static analyzers of dynamic ...
> > > 
> > > 
> > > 
> > > set_param(cmd, "gamma_g", &eq->gamma_g_pexp, args, ctx, eq, &ret);
> > > set_param(cmd, "gamma_r", &eq->gamma_r_pexp, args, ctx, eq, &ret);
> > > if (ret < 0)
> > 
> > Up.
> > -- 
> > FFmpeg = Fantastic Fundamental Miracolous Patchable Elitarian Gargoyle
> 
> >  vf_eq.c |   66 
> > ++--
> >  1 file changed, 23 insertions(+), 43 deletions(-)
> > 3adede32119e8d758297b2a29a92b98cb17d1010  
> > 0001-lavfi-eq-factorize-code-in-process_command.patch
> > From ee2157da84a30e043dfa55cf25a86ef751451bba Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini 
> > Date: Fri, 13 Mar 2015 16:45:08 +0100
> > Subject: [PATCH] lavfi/eq: factorize code in process_command()
> 
> LGTM

Applied, thanks.
-- 
FFmpeg = Faithless & Free Magnificient Portable Explosive Gadget
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

2015-03-17 Thread Michael Niedermayer
On Sun, Mar 15, 2015 at 02:59:58PM +0100, Stefano Sabatini wrote:
> On date Friday 2015-03-13 20:05:35 +0100, Michael Niedermayer encoded:
> > On Fri, Mar 13, 2015 at 05:16:53PM +0100, Stefano Sabatini wrote:
> > > ---
> > >  libavfilter/vf_eq.c | 56 
> > > ++---
> > >  1 file changed, 15 insertions(+), 41 deletions(-)
> > 
> > i would be more in favor of a function than a macro but LGTM either
> > way, macros are harder to debug and all kind of line number based
> > outputs are basically useless with multiline macros, be that
> > static analyzers of dynamic ...
> > 
> > 
> > 
> > set_param(cmd, "gamma_g", &eq->gamma_g_pexp, args, ctx, eq, &ret);
> > set_param(cmd, "gamma_r", &eq->gamma_r_pexp, args, ctx, eq, &ret);
> > if (ret < 0)
> 
> Up.
> -- 
> FFmpeg = Fantastic Fundamental Miracolous Patchable Elitarian Gargoyle

>  vf_eq.c |   66 
> ++--
>  1 file changed, 23 insertions(+), 43 deletions(-)
> 3adede32119e8d758297b2a29a92b98cb17d1010  
> 0001-lavfi-eq-factorize-code-in-process_command.patch
> From ee2157da84a30e043dfa55cf25a86ef751451bba Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini 
> Date: Fri, 13 Mar 2015 16:45:08 +0100
> Subject: [PATCH] lavfi/eq: factorize code in process_command()

LGTM

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

2015-03-15 Thread Stefano Sabatini
On date Friday 2015-03-13 20:05:35 +0100, Michael Niedermayer encoded:
> On Fri, Mar 13, 2015 at 05:16:53PM +0100, Stefano Sabatini wrote:
> > ---
> >  libavfilter/vf_eq.c | 56 
> > ++---
> >  1 file changed, 15 insertions(+), 41 deletions(-)
> 
> i would be more in favor of a function than a macro but LGTM either
> way, macros are harder to debug and all kind of line number based
> outputs are basically useless with multiline macros, be that
> static analyzers of dynamic ...
> 
> 
> 
> set_param(cmd, "gamma_g", &eq->gamma_g_pexp, args, ctx, eq, &ret);
> set_param(cmd, "gamma_r", &eq->gamma_r_pexp, args, ctx, eq, &ret);
> if (ret < 0)

Up.
-- 
FFmpeg = Fantastic Fundamental Miracolous Patchable Elitarian Gargoyle
>From ee2157da84a30e043dfa55cf25a86ef751451bba Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Fri, 13 Mar 2015 16:45:08 +0100
Subject: [PATCH] lavfi/eq: factorize code in process_command()

---
 libavfilter/vf_eq.c | 66 +++--
 1 file changed, 23 insertions(+), 43 deletions(-)

diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
index a370032..5ce59cb 100644
--- a/libavfilter/vf_eq.c
+++ b/libavfilter/vf_eq.c
@@ -276,54 +276,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 return ff_filter_frame(outlink, out);
 }
 
+static inline int set_param(AVExpr **pexpr, const char *args, const char *cmd,
+void (*set_fn)(EQContext *eq), AVFilterContext *ctx)
+{
+EQContext *eq = ctx->priv;
+int ret;
+if ((ret = set_expr(pexpr, args, cmd, ctx)) < 0)
+return ret;
+set_fn(eq);
+return 0;
+}
+
 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
char *res, int res_len, int flags)
 {
 EQContext *eq = ctx->priv;
-int ret;
 
-if (!strcmp(cmd, "contrast")) {
-ret = set_expr(&eq->contrast_pexpr, args, cmd, ctx);
-set_contrast(eq);
-return ret;
-}
-else if (!strcmp(cmd, "brightness")) {
-ret = set_expr(&eq->brightness_pexpr, args, cmd, ctx);
-set_brightness(eq);
-return ret;
-}
-else if (!strcmp(cmd, "saturation")) {
-ret = set_expr(&eq->saturation_pexpr, args, cmd, ctx);
-set_saturation(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma")) {
-ret = set_expr(&eq->gamma_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_r")) {
-ret = set_expr(&eq->gamma_r_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_g")) {
-ret = set_expr(&eq->gamma_g_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_b")) {
-ret = set_expr(&eq->gamma_b_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_weight")) {
-ret = set_expr(&eq->gamma_weight_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else
-return AVERROR(ENOSYS);
+#define SET_PARAM(param_name, set_fn_name)  \
+if (!strcmp(cmd, #param_name)) return set_param(&eq->param_name##_pexpr, args, cmd, set_##set_fn_name, ctx);
+
+ SET_PARAM(contrast, contrast)
+else SET_PARAM(brightness, brightness)
+else SET_PARAM(saturation, saturation)
+else SET_PARAM(gamma, gamma)
+else SET_PARAM(gamma_r, gamma)
+else SET_PARAM(gamma_g, gamma)
+else SET_PARAM(gamma_b, gamma)
+else SET_PARAM(gamma_weight, gamma)
+else return AVERROR(ENOSYS);
 }
 
 static const AVFilterPad eq_inputs[] = {
-- 
1.8.3.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

2015-03-13 Thread Michael Niedermayer
On Fri, Mar 13, 2015 at 05:16:53PM +0100, Stefano Sabatini wrote:
> ---
>  libavfilter/vf_eq.c | 56 
> ++---
>  1 file changed, 15 insertions(+), 41 deletions(-)

i would be more in favor of a function than a macro but LGTM either
way, macros are harder to debug and all kind of line number based
outputs are basically useless with multiline macros, be that
static analyzers of dynamic ...



set_param(cmd, "gamma_g", &eq->gamma_g_pexp, args, ctx, eq, &ret);
set_param(cmd, "gamma_r", &eq->gamma_r_pexp, args, ctx, eq, &ret);
if (ret < 0)


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

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

2015-03-13 Thread Stefano Sabatini
---
 libavfilter/vf_eq.c | 56 ++---
 1 file changed, 15 insertions(+), 41 deletions(-)

diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
index 980e9ca..e1aa206 100644
--- a/libavfilter/vf_eq.c
+++ b/libavfilter/vf_eq.c
@@ -282,48 +282,22 @@ static int process_command(AVFilterContext *ctx, const 
char *cmd, const char *ar
 EQContext *eq = ctx->priv;
 int ret;
 
-if (!strcmp(cmd, "contrast")) {
-ret = set_expr(&eq->contrast_pexpr, args, cmd, ctx);
-set_contrast(eq);
-return ret;
-}
-else if (!strcmp(cmd, "brightness")) {
-ret = set_expr(&eq->brightness_pexpr, args, cmd, ctx);
-set_brightness(eq);
-return ret;
-}
-else if (!strcmp(cmd, "saturation")) {
-ret = set_expr(&eq->saturation_pexpr, args, cmd, ctx);
-set_saturation(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma")) {
-ret = set_expr(&eq->gamma_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_r")) {
-ret = set_expr(&eq->gamma_r_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
+#define SET_PARAM(param_name, set_name) \
+if (!strcmp(cmd, #param_name)) {\
+ret = set_expr(&eq->param_name##_pexpr, args, cmd, ctx);\
+set_##set_name(eq); \
+return ret; \
 }
-else if (!strcmp(cmd, "gamma_g")) {
-ret = set_expr(&eq->gamma_g_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_b")) {
-ret = set_expr(&eq->gamma_b_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else if (!strcmp(cmd, "gamma_weight")) {
-ret = set_expr(&eq->gamma_weight_pexpr, args, cmd, ctx);
-set_gamma(eq);
-return ret;
-}
-else
-return AVERROR(ENOSYS);
+
+ SET_PARAM(contrast, contrast)
+else SET_PARAM(brightness, brightness)
+else SET_PARAM(saturation, saturation)
+else SET_PARAM(gamma, gamma)
+else SET_PARAM(gamma_r, gamma)
+else SET_PARAM(gamma_g, gamma)
+else SET_PARAM(gamma_b, gamma)
+else SET_PARAM(gamma_weight, gamma)
+else return AVERROR(ENOSYS);
 }
 
 static const AVFilterPad eq_inputs[] = {
-- 
1.8.3.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel