[FFmpeg-devel] [PATCH] avcodec: add C xvid IDCT support

James Almer jamrial at gmail.com
Mon Aug 11 05:36:56 CEST 2014


On 11/08/14 12:18 AM, Michael Niedermayer wrote:
> From: Pascal Massimino <pascal.massimino at gmail.com>
> 
> Thanks to Pascal Massimino and Michael Militzer for permission to use under LGPL
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/Makefile      |    2 +-
>  libavcodec/xvid_c_idct.c |  335 ++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/xvididct.c    |   60 +++++++++
>  libavcodec/xvididct.h    |    2 +
>  4 files changed, 398 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/xvid_c_idct.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 6873439..55b7b02 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -325,7 +325,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
>  OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
>  OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
>  OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
> -OBJS-$(CONFIG_MPEG4_DECODER)           += xvididct.o
> +OBJS-$(CONFIG_MPEG4_DECODER)           += xvididct.o xvid_c_idct.o
>  OBJS-$(CONFIG_MPL2_DECODER)            += mpl2dec.o ass.o
>  OBJS-$(CONFIG_MSMPEG4V1_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
>  OBJS-$(CONFIG_MSMPEG4V2_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
> diff --git a/libavcodec/xvid_c_idct.c b/libavcodec/xvid_c_idct.c
> new file mode 100644
> index 0000000..b15fb8e
> --- /dev/null
> +++ b/libavcodec/xvid_c_idct.c
> @@ -0,0 +1,335 @@
> +/*****************************************************************************
> + *
> + *  XVID MPEG-4 VIDEO CODEC
> + *  - Inverse DCT  -
> + *
> + *  Copyright (C) 2006-2011 Xvid Solutions GmbH
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser 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
> + *
> + * $Id$
> + *
> + ****************************************************************************/
> +
> +/*
> + *  Authors: Skal
> + *
> + *  Walken IDCT
> + *  Alternative idct implementations for decoding compatibility
> + *
> + *  NOTE: this "C" version is not the original one,
> + *  but is modified to yield the same error profile
> + *  than the MMX version.
> + *
> + ************************************************************************/

Is a separate file really necessary? The above copyright could be copied to xvididct.c just fine.
It's all lgpl code.

[...]

> diff --git a/libavcodec/xvididct.c b/libavcodec/xvididct.c
> index 8645af4..9b07518 100644
> --- a/libavcodec/xvididct.c
> +++ b/libavcodec/xvididct.c
> @@ -22,6 +22,59 @@
>  #include "idctdsp.h"
>  #include "xvididct.h"
>  
> +static void put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
> +                                 int line_size)
> +{
> +    int i;
> +
> +    /* read the pixels */
> +    for (i = 0; i < 8; i++) {
> +        pixels[0] = av_clip_uint8(block[0]);
> +        pixels[1] = av_clip_uint8(block[1]);
> +        pixels[2] = av_clip_uint8(block[2]);
> +        pixels[3] = av_clip_uint8(block[3]);
> +        pixels[4] = av_clip_uint8(block[4]);
> +        pixels[5] = av_clip_uint8(block[5]);
> +        pixels[6] = av_clip_uint8(block[6]);
> +        pixels[7] = av_clip_uint8(block[7]);
> +
> +        pixels += line_size;
> +        block  += 8;
> +    }
> +}
> +
> +static void add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels,
> +                                 int line_size)
> +{
> +    int i;
> +
> +    /* read the pixels */
> +    for (i = 0; i < 8; i++) {
> +        pixels[0] = av_clip_uint8(pixels[0] + block[0]);
> +        pixels[1] = av_clip_uint8(pixels[1] + block[1]);
> +        pixels[2] = av_clip_uint8(pixels[2] + block[2]);
> +        pixels[3] = av_clip_uint8(pixels[3] + block[3]);
> +        pixels[4] = av_clip_uint8(pixels[4] + block[4]);
> +        pixels[5] = av_clip_uint8(pixels[5] + block[5]);
> +        pixels[6] = av_clip_uint8(pixels[6] + block[6]);
> +        pixels[7] = av_clip_uint8(pixels[7] + block[7]);
> +        pixels   += line_size;
> +        block    += 8;
> +    }
> +}

Why the code duplication? These two functions are exact copies of the ones in idctdsp.
You could share the latter and use them here instead.

> +
> +static void idct_xvid_put(uint8_t *dest, int line_size, int16_t *block)
> +{
> +    ff_idct_xvid(block);
> +    put_pixels_clamped_c(block, dest, line_size);
> +}
> +
> +static void idct_xvid_add(uint8_t *dest, int line_size, int16_t *block)
> +{
> +    ff_idct_xvid(block);
> +    add_pixels_clamped_c(block, dest, line_size);
> +}
> +
>  av_cold void ff_xvididct_init(IDCTDSPContext *c, AVCodecContext *avctx)
>  {
>      const unsigned high_bit_depth = avctx->bits_per_raw_sample > 8;
> @@ -31,6 +84,13 @@ av_cold void ff_xvididct_init(IDCTDSPContext *c, AVCodecContext *avctx)
>            avctx->idct_algo == FF_IDCT_XVID))
>          return;
>  
> +    if (avctx->idct_algo == FF_IDCT_XVID) {
> +        c->idct_put  = idct_xvid_put;
> +        c->idct_add  = idct_xvid_add;
> +        c->idct      = ff_idct_xvid;
> +        c->perm_type = FF_IDCT_PERM_NONE;
> +    }
> +
>      if (ARCH_X86)
>          ff_xvididct_init_x86(c);
>  
> diff --git a/libavcodec/xvididct.h b/libavcodec/xvididct.h
> index 6678329..1b95cb7 100644
> --- a/libavcodec/xvididct.h
> +++ b/libavcodec/xvididct.h
> @@ -26,4 +26,6 @@ void ff_xvididct_init(IDCTDSPContext *c, AVCodecContext *avctx);
>  
>  void ff_xvididct_init_x86(IDCTDSPContext *c);
>  
> +void ff_idct_xvid(int16_t *const In);
> +
>  #endif /* AVCODEC_XVIDIDCT_H */
> 



More information about the ffmpeg-devel mailing list