[FFmpeg-devel] [PATCH] Port mp=eq/eq2 to FFmpeg

James Almer jamrial at gmail.com
Mon Jan 19 00:14:06 CET 2015


On 18/01/15 7:34 PM, arwa arif wrote:
> +static int initialize(AVFilterContext *ctx)
> +{
> +    EQ2Context *eq2 = ctx->priv;
> +    int i;
> +
> +    set_gamma(eq2);
> +    set_contrast(eq2);
> +    set_brightness(eq2);
> +    set_saturation(eq2);
> +
> +    if (IS_FILTER_EQ(ctx->filter)) {
> +        eq2->param[0].contrast += 1.0;
> +        eq2->param[1].adjust = NULL;
> +        eq2->param[2].adjust = NULL;
> +    }
> +
> +    for (i = 0; i < 3; i++) {
> +        eq2->param[i].c = (eq2->param[i].contrast) * 65536.0;
> +        eq2->param[i].b = (eq2->param[i].brightness + 1.0) * 255.5 - 128.0 - (eq2->param[i].contrast) * 128.0;
> +    }
> +
> +    eq2->param->process = process_c;

This doesn't look right.

> +
> +    if (ARCH_X86)
> +    {
> +        ff_eq_init_x86;
> +    }

if (ARCH_X86)
    ff_eq_init_x86(eq2);

> +
> +    return 0;
> +}

[...]

> diff --git a/libavfilter/x86/vf_eq.c b/libavfilter/x86/vf_eq.c
> new file mode 100644
> index 0000000..ac693bb
> --- /dev/null
> +++ b/libavfilter/x86/vf_eq.c
> @@ -0,0 +1,94 @@
> +/*
> + *
> + * Original MPlayer filters by Richard Felker.
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include "libavutil/attributes.h"
> +#include "libavutil/cpu.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/x86/asm.h"
> +#include "libavfilter/vf_eq.h"
> +
> +#if HAVE_MMX && HAVE_6REGS

#if HAVE_MMX_INLINE && HAVE_6REGS

> +static void process_MMX(EQ2Parameters *param, uint8_t *dst, int dst_stride,
> +                        uint8_t *src, int src_stride, int w, int h)
> +{
> +        int i;
> +        int pel;
> +        int dstep = dst_stride - w;
> +        int sstep = src_stride - w;
> +        short brvec[4];
> +        short contvec[4];
> +
> +        brvec[0] = brvec[1] = brvec[2] = brvec[3] = param->b;
> +        contvec[0] = contvec[1] = contvec[2] = contvec[3] = param->c;
> +
> +        while (h--) {
> +                __asm__ volatile (
> +                        "movq (%5), %%mm3      \n\t"
> +                        "movq (%6), %%mm4      \n\t"
> +                        "pxor %%mm0, %%mm0     \n\t"
> +                        "movl %4, %%eax        \n\t"
> +                        //ASMALIGN(4)

Why is this commented out? If the ASMALIGN define isn't available here, then use 
".p2align 4 \n\t"

> +                        "1:                    \n\t"
> +                        "movq (%0), %%mm1      \n\t"
> +                        "movq (%0), %%mm2      \n\t"
> +                        "punpcklbw %%mm0, %%mm1\n\t"
> +                        "punpckhbw %%mm0, %%mm2\n\t"
> +                        "psllw $4, %%mm1       \n\t"
> +                        "psllw $4, %%mm2       \n\t"
> +                        "pmulhw %%mm4, %%mm1   \n\t"
> +                        "pmulhw %%mm4, %%mm2   \n\t"
> +                        "paddw %%mm3, %%mm1    \n\t"
> +                        "paddw %%mm3, %%mm2    \n\t"
> +                        "packuswb %%mm2, %%mm1 \n\t"
> +                        "add $8, %0            \n\t"
> +                        "movq %%mm1, (%1)      \n\t"
> +                        "add $8, %1            \n\t"
> +                        "decl %%eax            \n\t"
> +                        "jnz 1b                \n\t"
> +                        : "=r" (src), "=r" (dst)
> +                        : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec)
> +                        : "%eax"
> +                );
> +
> +                for (i = w&7; i; i--) {
> +                        pel = ((*src++ * param->c) >> 12) + param->b;
> +                        if (pel & 768) 
> +                            pel = (-pel) >> 31;
> +                        *dst++ = pel;
> +                }
> +
> +                src += sstep;
> +                dst += dstep;
> +        }
> +        __asm__ volatile ( "emms \n\t" ::: "memory" );
> +}
> +#endif
> +
> +av_cold void ff_eq_init_x86(EQ2Context *eq2)
> +{
> +#if HAVE_MMX_INLINE

Check for HAVE_6REGS here as well.

> +    int cpu_flags = av_get_cpu_flags();
> +
> +    if (cpu_flags & AV_CPU_FLAG_MMX) {
> +        eq2->param->process = process_MMX;

Again, this looks wrong.

> +    }
> +#endif
> +}


More information about the ffmpeg-devel mailing list