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

Michael Niedermayer michaelni at gmx.at
Mon Aug 11 12:34:37 CEST 2014


On Mon, Aug 11, 2014 at 07:44:25AM +0200, Clément Bœsch wrote:
> On Mon, Aug 11, 2014 at 05:18:32AM +0200, 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$
> > + *
> 
> No meaning in FFmpeg/git

removed


> 
> > + ****************************************************************************/
> > +
> > +/*
> > + *  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.
> > + *
> > + ************************************************************************/
> > +
> 
> /**
>  * @file
>  * Walken IDCT
>  * Alternative idct implementations for decoding compatibility
>  *
>  * @author Skal
>  * @note this "C" version is not the original one, but is modified to
>  *       yield the same error profile than the MMX version.
>  */

ok copy and pasted that in


> 
> > +#include "xvididct.h"
> > +
> 
> > +
> > +#define XVID_DSP_CLIP_255(x)   ( ((x)&~255) ? ((-(x)) >> (8*sizeof((x))-1))&0xff : (x) )
> 
> Looks unused
> 
> > +
> > +#define ROW_SHIFT 11
> > +#define COL_SHIFT 6
> > +
> > +// #define FIX(x)   (int)((x) * (1<<ROW_SHIFT))
> > +#define Rnd0 65536 // 1<<(COL_SHIFT+ROW_SHIFT-1);
> > +#define Rnd1 3597  // FIX (1.75683487303);
> > +#define Rnd2 2260  // FIX (1.10355339059);
> > +#define Rnd3 1203  // FIX (0.587788325588);
> > +#define Rnd4 0
> > +#define Rnd5 120   // FIX (0.058658283817);
> > +#define Rnd6 512   // FIX (0.25);
> > +#define Rnd7 512   // FIX (0.25);
> 
> > +#undef FIX
> 
> Mot defined

Ill submit a patch to xvid about these, if they are accepted ill
merge them in our version


> 
> > +
> > +static const int Tab04[] = { 22725, 21407, 19266, 16384, 12873,  8867, 4520 };
> > +static const int Tab17[] = { 31521, 29692, 26722, 22725, 17855, 12299, 6270 };
> > +static const int Tab26[] = { 29692, 27969, 25172, 21407, 16819, 11585, 5906 };
> > +static const int Tab35[] = { 26722, 25172, 22654, 19266, 15137, 10426, 5315 };
> > +
> > +static int Idct_Row(short * In, const int * const Tab, int Rnd)
> > +{
> > +  const int C1 = Tab[0];
> > +  const int C2 = Tab[1];
> > +  const int C3 = Tab[2];
> > +  const int C4 = Tab[3];
> > +  const int C5 = Tab[4];
> > +  const int C6 = Tab[5];
> > +  const int C7 = Tab[6];
> > +
> > +  const int Right = In[5]|In[6]|In[7];
> > +  const int Left  = In[1]|In[2]|In[3];
> 
> > +  if (!(Right | In[4]))
> > +  {
> > +    const int K = C4*In[0] + Rnd;
> > +    if (Left)
> > +    {
> 
> If you could fix the style and indent to match FFmpeg one a little that
> would be great.

no, i cant
the file is from xvid, iam not going to fork the file and
maintain such fork because of whitespaces. Or OTOH hope that we wont
want to replace it by a future version from xvid one day ...

If someone else volunteers to maintain a reformated version, that
sure is fine with me i dont object at all but i can just offer to
maintain a largely unchanged version.


> 
> [...]
> > +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);
> > +}
> > +
> 
> So the function takes a destination buffer but still destroys the input block?

yes


> 
> >  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);
> 
> ... looks like misleading const

thats how the idct functions in xvid are, is there a problem with it?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140811/069f28ee/attachment.asc>


More information about the ffmpeg-devel mailing list