vdr/xine-lib-vdr/src/libmpeg2 Makefile.am Makefile.in cpu_state.c decode.c header.c idct.c idct_altivec.c idct_mlib.c idct_mlib.h idct_mmx.c motion_comp.c motion_comp_altivec.c motion_comp_mlib.c motion_comp_mmx.c motion_comp_vis.c mpeg2.h mpeg2_internal.h slice.c slice_xvmc.c slice_xvmc_vld.c stats.c vis.h vlc.h xine_decoder.c xvmc.h xvmc_vld.h

Darren Salt pkg-vdr-dvb-changes@lists.alioth.debian.org
Mon, 04 Apr 2005 22:32:51 +0000


Update of /cvsroot/pkg-vdr-dvb/vdr/xine-lib-vdr/src/libmpeg2
In directory haydn:/tmp/cvs-serv3673/src/libmpeg2

Added Files:
	Makefile.am Makefile.in cpu_state.c decode.c header.c idct.c 
	idct_altivec.c idct_mlib.c idct_mlib.h idct_mmx.c 
	motion_comp.c motion_comp_altivec.c motion_comp_mlib.c 
	motion_comp_mmx.c motion_comp_vis.c mpeg2.h mpeg2_internal.h 
	slice.c slice_xvmc.c slice_xvmc_vld.c stats.c vis.h vlc.h 
	xine_decoder.c xvmc.h xvmc_vld.h 
Log Message:
Import of VDR-patched xine-lib.

--- NEW FILE: motion_comp_mmx.c ---
/*
 * motion_comp_mmx.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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
[...973 lines suppressed...]
{
    MC_avg4_8 (height, dest, ref, stride, CPU_3DNOW);
}

static void MC_put_xy_16_3dnow (uint8_t * dest, uint8_t * ref,
				int stride, int height)
{
    MC_put4_16 (height, dest, ref, stride, CPU_3DNOW);
}

static void MC_put_xy_8_3dnow (uint8_t * dest, uint8_t * ref,
			       int stride, int height)
{
    MC_put4_8 (height, dest, ref, stride, CPU_3DNOW);
}


MPEG2_MC_EXTERN (3dnow)

#endif

--- NEW FILE: idct_mmx.c ---
/*
 * idct_mmx.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#ifdef ARCH_X86

#include <inttypes.h>

#include "mpeg2_internal.h"
#include "xineutils.h"

#define ROW_SHIFT 11
#define COL_SHIFT 6

#define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT)))
#define rounder(bias) {round (bias), round (bias)}


#if 0
/* C row IDCT - its just here to document the MMXEXT and MMX versions */
static inline void idct_row (int16_t * row, int offset,
			     int16_t * table, int32_t * rounder)
{
    int C1, C2, C3, C4, C5, C6, C7;
    int a0, a1, a2, a3, b0, b1, b2, b3;

    row += offset;

    C1 = table[1];
    C2 = table[2];
    C3 = table[3];
    C4 = table[4];
    C5 = table[5];
    C6 = table[6];
    C7 = table[7];

    a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + *rounder;
    a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + *rounder;
    a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + *rounder;
    a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + *rounder;

    b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
    b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
    b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
    b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];

    row[0] = (a0 + b0) >> ROW_SHIFT;
    row[1] = (a1 + b1) >> ROW_SHIFT;
    row[2] = (a2 + b2) >> ROW_SHIFT;
    row[3] = (a3 + b3) >> ROW_SHIFT;
    row[4] = (a3 - b3) >> ROW_SHIFT;
    row[5] = (a2 - b2) >> ROW_SHIFT;
    row[6] = (a1 - b1) >> ROW_SHIFT;
    row[7] = (a0 - b0) >> ROW_SHIFT;
}
#endif


/* MMXEXT row IDCT */

#define mmxext_table(c1,c2,c3,c4,c5,c6,c7)	{  c4,  c2, -c4, -c2,	\
						   c4,  c6,  c4,  c6,	\
						   c1,  c3, -c1, -c5,	\
						   c5,  c7,  c3, -c7,	\
						   c4, -c6,  c4, -c6,	\
						  -c4,  c2,  c4, -c2,	\
						   c5, -c1,  c3, -c1,	\
						   c7,  c3,  c7, -c5 }

static inline void mmxext_row_head (int16_t * row, int offset, int16_t * table)
{
    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0

    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0

    movq_m2r (*table, mm3);		// mm3 = -C2 -C4 C2 C4
    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1

    movq_m2r (*(table+4), mm4);		// mm4 = C6 C4 C6 C4
    pmaddwd_r2r (mm0, mm3);		// mm3 = -C4*x4-C2*x6 C4*x0+C2*x2

    pshufw_r2r (mm2, mm2, 0x4e);	// mm2 = x2 x0 x6 x4
}

static inline void mmxext_row (int16_t * table, int32_t * rounder)
{
    movq_m2r (*(table+8), mm1);		// mm1 = -C5 -C1 C3 C1
    pmaddwd_r2r (mm2, mm4);		// mm4 = C4*x0+C6*x2 C4*x4+C6*x6

    pmaddwd_m2r (*(table+16), mm0);	// mm0 = C4*x4-C6*x6 C4*x0-C6*x2
    pshufw_r2r (mm6, mm6, 0x4e);	// mm6 = x3 x1 x7 x5

    movq_m2r (*(table+12), mm7);	// mm7 = -C7 C3 C7 C5
    pmaddwd_r2r (mm5, mm1);		// mm1 = -C1*x5-C5*x7 C1*x1+C3*x3

    paddd_m2r (*rounder, mm3);		// mm3 += rounder
    pmaddwd_r2r (mm6, mm7);		// mm7 = C3*x1-C7*x3 C5*x5+C7*x7

    pmaddwd_m2r (*(table+20), mm2);	// mm2 = C4*x0-C2*x2 -C4*x4+C2*x6
    paddd_r2r (mm4, mm3);		// mm3 = a1 a0 + rounder

    pmaddwd_m2r (*(table+24), mm5);	// mm5 = C3*x5-C1*x7 C5*x1-C1*x3
    movq_r2r (mm3, mm4);		// mm4 = a1 a0 + rounder

    pmaddwd_m2r (*(table+28), mm6);	// mm6 = C7*x1-C5*x3 C7*x5+C3*x7
    paddd_r2r (mm7, mm1);		// mm1 = b1 b0

    paddd_m2r (*rounder, mm0);		// mm0 += rounder
    psubd_r2r (mm1, mm3);		// mm3 = a1-b1 a0-b0 + rounder

    psrad_i2r (ROW_SHIFT, mm3);		// mm3 = y6 y7
    paddd_r2r (mm4, mm1);		// mm1 = a1+b1 a0+b0 + rounder

    paddd_r2r (mm2, mm0);		// mm0 = a3 a2 + rounder
    psrad_i2r (ROW_SHIFT, mm1);		// mm1 = y1 y0

    paddd_r2r (mm6, mm5);		// mm5 = b3 b2
    movq_r2r (mm0, mm4);		// mm4 = a3 a2 + rounder

    paddd_r2r (mm5, mm0);		// mm0 = a3+b3 a2+b2 + rounder
    psubd_r2r (mm5, mm4);		// mm4 = a3-b3 a2-b2 + rounder
}

static inline void mmxext_row_tail (int16_t * row, int store)
{
    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2

    psrad_i2r (ROW_SHIFT, mm4);		// mm4 = y4 y5

    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0

    packssdw_r2r (mm3, mm4);		// mm4 = y6 y7 y4 y5

    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
    pshufw_r2r (mm4, mm4, 0xb1);	// mm4 = y7 y6 y5 y4

    /* slot */

    movq_r2m (mm4, *(row+store+4));	// save y7 y6 y5 y4
}

static inline void mmxext_row_mid (int16_t * row, int store,
				   int offset, int16_t * table)
{
    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2

    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
    psrad_i2r (ROW_SHIFT, mm4);		// mm4 = y4 y5

    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1

    packssdw_r2r (mm3, mm4);		// mm4 = y6 y7 y4 y5
    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0

    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
    pshufw_r2r (mm4, mm4, 0xb1);	// mm4 = y7 y6 y5 y4

    movq_m2r (*table, mm3);		// mm3 = -C2 -C4 C2 C4
    movq_r2m (mm4, *(row+store+4));	// save y7 y6 y5 y4

    pmaddwd_r2r (mm0, mm3);		// mm3 = -C4*x4-C2*x6 C4*x0+C2*x2

    movq_m2r (*(table+4), mm4);		// mm4 = C6 C4 C6 C4
    pshufw_r2r (mm2, mm2, 0x4e);	// mm2 = x2 x0 x6 x4
}


/* MMX row IDCT */

#define mmx_table(c1,c2,c3,c4,c5,c6,c7)	{  c4,  c2,  c4,  c6,	\
					   c4,  c6, -c4, -c2,	\
					   c1,  c3,  c3, -c7,	\
					   c5,  c7, -c1, -c5,	\
					   c4, -c6,  c4, -c2,	\
					  -c4,  c2,  c4, -c6,	\
					   c5, -c1,  c7, -c5,	\
					   c7,  c3,  c3, -c1 }

static inline void mmx_row_head (int16_t * row, int offset, int16_t * table)
{
    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0

    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0

    movq_m2r (*table, mm3);		// mm3 = C6 C4 C2 C4
    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1

    punpckldq_r2r (mm0, mm0);		// mm0 = x2 x0 x2 x0

    movq_m2r (*(table+4), mm4);		// mm4 = -C2 -C4 C6 C4
    pmaddwd_r2r (mm0, mm3);		// mm3 = C4*x0+C6*x2 C4*x0+C2*x2

    movq_m2r (*(table+8), mm1);		// mm1 = -C7 C3 C3 C1
    punpckhdq_r2r (mm2, mm2);		// mm2 = x6 x4 x6 x4
}

static inline void mmx_row (int16_t * table, int32_t * rounder)
{
    pmaddwd_r2r (mm2, mm4);		// mm4 = -C4*x4-C2*x6 C4*x4+C6*x6
    punpckldq_r2r (mm5, mm5);		// mm5 = x3 x1 x3 x1

    pmaddwd_m2r (*(table+16), mm0);	// mm0 = C4*x0-C2*x2 C4*x0-C6*x2
    punpckhdq_r2r (mm6, mm6);		// mm6 = x7 x5 x7 x5

    movq_m2r (*(table+12), mm7);	// mm7 = -C5 -C1 C7 C5
    pmaddwd_r2r (mm5, mm1);		// mm1 = C3*x1-C7*x3 C1*x1+C3*x3

    paddd_m2r (*rounder, mm3);		// mm3 += rounder
    pmaddwd_r2r (mm6, mm7);		// mm7 = -C1*x5-C5*x7 C5*x5+C7*x7

    pmaddwd_m2r (*(table+20), mm2);	// mm2 = C4*x4-C6*x6 -C4*x4+C2*x6
    paddd_r2r (mm4, mm3);		// mm3 = a1 a0 + rounder

    pmaddwd_m2r (*(table+24), mm5);	// mm5 = C7*x1-C5*x3 C5*x1-C1*x3
    movq_r2r (mm3, mm4);		// mm4 = a1 a0 + rounder

    pmaddwd_m2r (*(table+28), mm6);	// mm6 = C3*x5-C1*x7 C7*x5+C3*x7
    paddd_r2r (mm7, mm1);		// mm1 = b1 b0

    paddd_m2r (*rounder, mm0);		// mm0 += rounder
    psubd_r2r (mm1, mm3);		// mm3 = a1-b1 a0-b0 + rounder

    psrad_i2r (ROW_SHIFT, mm3);		// mm3 = y6 y7
    paddd_r2r (mm4, mm1);		// mm1 = a1+b1 a0+b0 + rounder

    paddd_r2r (mm2, mm0);		// mm0 = a3 a2 + rounder
    psrad_i2r (ROW_SHIFT, mm1);		// mm1 = y1 y0

    paddd_r2r (mm6, mm5);		// mm5 = b3 b2
    movq_r2r (mm0, mm7);		// mm7 = a3 a2 + rounder

    paddd_r2r (mm5, mm0);		// mm0 = a3+b3 a2+b2 + rounder
    psubd_r2r (mm5, mm7);		// mm7 = a3-b3 a2-b2 + rounder
}

static inline void mmx_row_tail (int16_t * row, int store)
{
    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2

    psrad_i2r (ROW_SHIFT, mm7);		// mm7 = y4 y5

    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0

    packssdw_r2r (mm3, mm7);		// mm7 = y6 y7 y4 y5

    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
    movq_r2r (mm7, mm4);		// mm4 = y6 y7 y4 y5

    pslld_i2r (16, mm7);		// mm7 = y7 0 y5 0

    psrld_i2r (16, mm4);		// mm4 = 0 y6 0 y4

    por_r2r (mm4, mm7);			// mm7 = y7 y6 y5 y4

    /* slot */

    movq_r2m (mm7, *(row+store+4));	// save y7 y6 y5 y4
}

static inline void mmx_row_mid (int16_t * row, int store,
				int offset, int16_t * table)
{
    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2

    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
    psrad_i2r (ROW_SHIFT, mm7);		// mm7 = y4 y5

    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1

    packssdw_r2r (mm3, mm7);		// mm7 = y6 y7 y4 y5
    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0

    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
    movq_r2r (mm7, mm1);		// mm1 = y6 y7 y4 y5

    punpckldq_r2r (mm0, mm0);		// mm0 = x2 x0 x2 x0
    psrld_i2r (16, mm7);		// mm7 = 0 y6 0 y4

    movq_m2r (*table, mm3);		// mm3 = C6 C4 C2 C4
    pslld_i2r (16, mm1);		// mm1 = y7 0 y5 0

    movq_m2r (*(table+4), mm4);		// mm4 = -C2 -C4 C6 C4
    por_r2r (mm1, mm7);			// mm7 = y7 y6 y5 y4

    movq_m2r (*(table+8), mm1);		// mm1 = -C7 C3 C3 C1
    punpckhdq_r2r (mm2, mm2);		// mm2 = x6 x4 x6 x4

    movq_r2m (mm7, *(row+store+4));	// save y7 y6 y5 y4
    pmaddwd_r2r (mm0, mm3);		// mm3 = C4*x0+C6*x2 C4*x0+C2*x2
}


#if 0
// C column IDCT - its just here to document the MMXEXT and MMX versions
static inline void idct_col (int16_t * col, int offset)
{
/* multiplication - as implemented on mmx */
#define F(c,x) (((c) * (x)) >> 16)

/* saturation - it helps us handle torture test cases */
#define S(x) (((x)>32767) ? 32767 : ((x)<-32768) ? -32768 : (x))

    int16_t x0, x1, x2, x3, x4, x5, x6, x7;
    int16_t y0, y1, y2, y3, y4, y5, y6, y7;
    int16_t a0, a1, a2, a3, b0, b1, b2, b3;
    int16_t u04, v04, u26, v26, u17, v17, u35, v35, u12, v12;

    col += offset;

    x0 = col[0*8];
    x1 = col[1*8];
    x2 = col[2*8];
    x3 = col[3*8];
    x4 = col[4*8];
    x5 = col[5*8];
    x6 = col[6*8];
    x7 = col[7*8];

    u04 = S (x0 + x4);
    v04 = S (x0 - x4);
    u26 = S (F (T2, x6) + x2);
    v26 = S (F (T2, x2) - x6);

    a0 = S (u04 + u26);
    a1 = S (v04 + v26);
    a2 = S (v04 - v26);
    a3 = S (u04 - u26);

    u17 = S (F (T1, x7) + x1);
    v17 = S (F (T1, x1) - x7);
    u35 = S (F (T3, x5) + x3);
    v35 = S (F (T3, x3) - x5);

    b0 = S (u17 + u35);
    b3 = S (v17 - v35);
    u12 = S (u17 - u35);
    v12 = S (v17 + v35);
    u12 = S (2 * F (C4, u12));
    v12 = S (2 * F (C4, v12));
    b1 = S (u12 + v12);
    b2 = S (u12 - v12);

    y0 = S (a0 + b0) >> COL_SHIFT;
    y1 = S (a1 + b1) >> COL_SHIFT;
    y2 = S (a2 + b2) >> COL_SHIFT;
    y3 = S (a3 + b3) >> COL_SHIFT;

    y4 = S (a3 - b3) >> COL_SHIFT;
    y5 = S (a2 - b2) >> COL_SHIFT;
    y6 = S (a1 - b1) >> COL_SHIFT;
    y7 = S (a0 - b0) >> COL_SHIFT;

    col[0*8] = y0;
    col[1*8] = y1;
    col[2*8] = y2;
    col[3*8] = y3;
    col[4*8] = y4;
    col[5*8] = y5;
    col[6*8] = y6;
    col[7*8] = y7;
}
#endif


// MMX column IDCT
static inline void idct_col (int16_t * col, int offset)
{
#define T1 13036
#define T2 27146
#define T3 43790
#define C4 23170

    static short _T1[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
    static short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
    static short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
    static short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4};

    /* column code adapted from peter gubanov */
    /* http://www.elecard.com/peter/idct.shtml */

    movq_m2r (*_T1, mm0);		// mm0 = T1

    movq_m2r (*(col+offset+1*8), mm1);	// mm1 = x1
    movq_r2r (mm0, mm2);		// mm2 = T1

    movq_m2r (*(col+offset+7*8), mm4);	// mm4 = x7
    pmulhw_r2r (mm1, mm0);		// mm0 = T1*x1

    movq_m2r (*_T3, mm5);		// mm5 = T3
    pmulhw_r2r (mm4, mm2);		// mm2 = T1*x7

    movq_m2r (*(col+offset+5*8), mm6);	// mm6 = x5
    movq_r2r (mm5, mm7);		// mm7 = T3-1

    movq_m2r (*(col+offset+3*8), mm3);	// mm3 = x3
    psubsw_r2r (mm4, mm0);		// mm0 = v17

    movq_m2r (*_T2, mm4);		// mm4 = T2
    pmulhw_r2r (mm3, mm5);		// mm5 = (T3-1)*x3

    paddsw_r2r (mm2, mm1);		// mm1 = u17
    pmulhw_r2r (mm6, mm7);		// mm7 = (T3-1)*x5

    /* slot */

    movq_r2r (mm4, mm2);		// mm2 = T2
    paddsw_r2r (mm3, mm5);		// mm5 = T3*x3

    pmulhw_m2r (*(col+offset+2*8), mm4);// mm4 = T2*x2
    paddsw_r2r (mm6, mm7);		// mm7 = T3*x5

    psubsw_r2r (mm6, mm5);		// mm5 = v35
    paddsw_r2r (mm3, mm7);		// mm7 = u35

    movq_m2r (*(col+offset+6*8), mm3);	// mm3 = x6
    movq_r2r (mm0, mm6);		// mm6 = v17

    pmulhw_r2r (mm3, mm2);		// mm2 = T2*x6
    psubsw_r2r (mm5, mm0);		// mm0 = b3

    psubsw_r2r (mm3, mm4);		// mm4 = v26
    paddsw_r2r (mm6, mm5);		// mm5 = v12

    movq_r2m (mm0, *(col+offset+3*8));	// save b3 in scratch0
    movq_r2r (mm1, mm6);		// mm6 = u17

    paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26
    paddsw_r2r (mm7, mm6);		// mm6 = b0

    psubsw_r2r (mm7, mm1);		// mm1 = u12
    movq_r2r (mm1, mm7);		// mm7 = u12

    movq_m2r (*(col+offset+0*8), mm3);	// mm3 = x0
    paddsw_r2r (mm5, mm1);		// mm1 = u12+v12

    movq_m2r (*_C4, mm0);		// mm0 = C4/2
    psubsw_r2r (mm5, mm7);		// mm7 = u12-v12

    movq_r2m (mm6, *(col+offset+5*8));	// save b0 in scratch1
    pmulhw_r2r (mm0, mm1);		// mm1 = b1/2

    movq_r2r (mm4, mm6);		// mm6 = v26
    pmulhw_r2r (mm0, mm7);		// mm7 = b2/2

    movq_m2r (*(col+offset+4*8), mm5);	// mm5 = x4
    movq_r2r (mm3, mm0);		// mm0 = x0

    psubsw_r2r (mm5, mm3);		// mm3 = v04
    paddsw_r2r (mm5, mm0);		// mm0 = u04

    paddsw_r2r (mm3, mm4);		// mm4 = a1
    movq_r2r (mm0, mm5);		// mm5 = u04

    psubsw_r2r (mm6, mm3);		// mm3 = a2
    paddsw_r2r (mm2, mm5);		// mm5 = a0

    paddsw_r2r (mm1, mm1);		// mm1 = b1
    psubsw_r2r (mm2, mm0);		// mm0 = a3

    paddsw_r2r (mm7, mm7);		// mm7 = b2
    movq_r2r (mm3, mm2);		// mm2 = a2

    movq_r2r (mm4, mm6);		// mm6 = a1
    paddsw_r2r (mm7, mm3);		// mm3 = a2+b2

    psraw_i2r (COL_SHIFT, mm3);		// mm3 = y2
    paddsw_r2r (mm1, mm4);		// mm4 = a1+b1

    psraw_i2r (COL_SHIFT, mm4);		// mm4 = y1
    psubsw_r2r (mm1, mm6);		// mm6 = a1-b1

    movq_m2r (*(col+offset+5*8), mm1);	// mm1 = b0
    psubsw_r2r (mm7, mm2);		// mm2 = a2-b2

    psraw_i2r (COL_SHIFT, mm6);		// mm6 = y6
    movq_r2r (mm5, mm7);		// mm7 = a0

    movq_r2m (mm4, *(col+offset+1*8));	// save y1
    psraw_i2r (COL_SHIFT, mm2);		// mm2 = y5

    movq_r2m (mm3, *(col+offset+2*8));	// save y2
    paddsw_r2r (mm1, mm5);		// mm5 = a0+b0

    movq_m2r (*(col+offset+3*8), mm4);	// mm4 = b3
    psubsw_r2r (mm1, mm7);		// mm7 = a0-b0

    psraw_i2r (COL_SHIFT, mm5);		// mm5 = y0
    movq_r2r (mm0, mm3);		// mm3 = a3

    movq_r2m (mm2, *(col+offset+5*8));	// save y5
    psubsw_r2r (mm4, mm3);		// mm3 = a3-b3

    psraw_i2r (COL_SHIFT, mm7);		// mm7 = y7
    paddsw_r2r (mm0, mm4);		// mm4 = a3+b3

    movq_r2m (mm5, *(col+offset+0*8));	// save y0
    psraw_i2r (COL_SHIFT, mm3);		// mm3 = y4

    movq_r2m (mm6, *(col+offset+6*8));	// save y6
    psraw_i2r (COL_SHIFT, mm4);		// mm4 = y3

    movq_r2m (mm7, *(col+offset+7*8));	// save y7

    movq_r2m (mm3, *(col+offset+4*8));	// save y4

    movq_r2m (mm4, *(col+offset+3*8));	// save y3
}


static int32_t rounder0[] ATTR_ALIGN(8) =
    rounder ((1 << (COL_SHIFT - 1)) - 0.5);
static int32_t rounder4[] ATTR_ALIGN(8) = rounder (0);
static int32_t rounder1[] ATTR_ALIGN(8) =
    rounder (1.25683487303);	/* C1*(C1/C4+C1+C7)/2 */
static int32_t rounder7[] ATTR_ALIGN(8) =
    rounder (-0.25);		/* C1*(C7/C4+C7-C1)/2 */
static int32_t rounder2[] ATTR_ALIGN(8) =
    rounder (0.60355339059);	/* C2 * (C6+C2)/2 */
static int32_t rounder6[] ATTR_ALIGN(8) =
    rounder (-0.25);		/* C2 * (C6-C2)/2 */
static int32_t rounder3[] ATTR_ALIGN(8) =
    rounder (0.087788325588);	/* C3*(-C3/C4+C3+C5)/2 */
static int32_t rounder5[] ATTR_ALIGN(8) =
    rounder (-0.441341716183);	/* C3*(-C5/C4+C5-C3)/2 */


#define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid)	\
static inline void idct (int16_t * block)				\
{									\
    static int16_t table04[] ATTR_ALIGN(16) =				\
	table (22725, 21407, 19266, 16384, 12873,  8867, 4520);		\
    static int16_t table17[] ATTR_ALIGN(16) =				\
	table (31521, 29692, 26722, 22725, 17855, 12299, 6270);		\
    static int16_t table26[] ATTR_ALIGN(16) =				\
	table (29692, 27969, 25172, 21407, 16819, 11585, 5906);		\
    static int16_t table35[] ATTR_ALIGN(16) =				\
	table (26722, 25172, 22654, 19266, 15137, 10426, 5315);		\
									\
    idct_row_head (block, 0*8, table04);				\
    idct_row (table04, rounder0);					\
    idct_row_mid (block, 0*8, 4*8, table04);				\
    idct_row (table04, rounder4);					\
    idct_row_mid (block, 4*8, 1*8, table17);				\
    idct_row (table17, rounder1);					\
    idct_row_mid (block, 1*8, 7*8, table17);				\
    idct_row (table17, rounder7);					\
    idct_row_mid (block, 7*8, 2*8, table26);				\
    idct_row (table26, rounder2);					\
    idct_row_mid (block, 2*8, 6*8, table26);				\
    idct_row (table26, rounder6);					\
    idct_row_mid (block, 6*8, 3*8, table35);				\
    idct_row (table35, rounder3);					\
    idct_row_mid (block, 3*8, 5*8, table35);				\
    idct_row (table35, rounder5);					\
    idct_row_tail (block, 5*8);						\
									\
    idct_col (block, 0);						\
    idct_col (block, 4);						\
}


#define COPY_MMX(offset,r0,r1,r2)	\
do {					\
    movq_m2r (*(block+offset), r0);	\
    dest += stride;			\
    movq_m2r (*(block+offset+4), r1);	\
    movq_r2m (r2, *dest);		\
    packuswb_r2r (r1, r0);		\
} while (0)

static void block_copy (int16_t * block, uint8_t * dest, int stride)
{
    movq_m2r (*(block+0*8), mm0);
    movq_m2r (*(block+0*8+4), mm1);
    movq_m2r (*(block+1*8), mm2);
    packuswb_r2r (mm1, mm0);
    movq_m2r (*(block+1*8+4), mm3);
    movq_r2m (mm0, *dest);
    packuswb_r2r (mm3, mm2);
    COPY_MMX (2*8, mm0, mm1, mm2);
    COPY_MMX (3*8, mm2, mm3, mm0);
    COPY_MMX (4*8, mm0, mm1, mm2);
    COPY_MMX (5*8, mm2, mm3, mm0);
    COPY_MMX (6*8, mm0, mm1, mm2);
    COPY_MMX (7*8, mm2, mm3, mm0);
    movq_r2m (mm2, *(dest+stride));
}


#define ADD_MMX(offset,r1,r2,r3,r4)	\
do {					\
    movq_m2r (*(dest+2*stride), r1);	\
    packuswb_r2r (r4, r3);		\
    movq_r2r (r1, r2);			\
    dest += stride;			\
    movq_r2m (r3, *dest);		\
    punpcklbw_r2r (mm0, r1);		\
    paddsw_m2r (*(block+offset), r1);	\
    punpckhbw_r2r (mm0, r2);		\
    paddsw_m2r (*(block+offset+4), r2);	\
} while (0)

static void block_add (int16_t * block, uint8_t * dest, int stride)
{
    movq_m2r (*dest, mm1);
    pxor_r2r (mm0, mm0);
    movq_m2r (*(dest+stride), mm3);
    movq_r2r (mm1, mm2);
    punpcklbw_r2r (mm0, mm1);
    movq_r2r (mm3, mm4);
    paddsw_m2r (*(block+0*8), mm1);
    punpckhbw_r2r (mm0, mm2);
    paddsw_m2r (*(block+0*8+4), mm2);
    punpcklbw_r2r (mm0, mm3);
    paddsw_m2r (*(block+1*8), mm3);
    packuswb_r2r (mm2, mm1);
    punpckhbw_r2r (mm0, mm4);
    movq_r2m (mm1, *dest);
    paddsw_m2r (*(block+1*8+4), mm4);
    ADD_MMX (2*8, mm1, mm2, mm3, mm4);
    ADD_MMX (3*8, mm3, mm4, mm1, mm2);
    ADD_MMX (4*8, mm1, mm2, mm3, mm4);
    ADD_MMX (5*8, mm3, mm4, mm1, mm2);
    ADD_MMX (6*8, mm1, mm2, mm3, mm4);
    ADD_MMX (7*8, mm3, mm4, mm1, mm2);
    packuswb_r2r (mm4, mm3);
    movq_r2m (mm3, *(dest+stride));
}

static inline void block_zero (int16_t * block)   {       
  pxor_r2r (mm0, mm0);
  movq_r2m (mm0, *(block+0*4));
  movq_r2m (mm0, *(block+1*4));       
  movq_r2m (mm0, *(block+2*4));       
  movq_r2m (mm0, *(block+3*4));       
  movq_r2m (mm0, *(block+4*4));       
  movq_r2m (mm0, *(block+5*4));       
  movq_r2m (mm0, *(block+6*4));       
  movq_r2m (mm0, *(block+7*4));       
  movq_r2m (mm0, *(block+8*4));       
  movq_r2m (mm0, *(block+9*4));       
  movq_r2m (mm0, *(block+10*4));       
  movq_r2m (mm0, *(block+11*4));       
  movq_r2m (mm0, *(block+12*4));       
  movq_r2m (mm0, *(block+13*4));       
  movq_r2m (mm0, *(block+14*4));       
  movq_r2m (mm0, *(block+15*4));   
}

declare_idct (mmxext_idct, mmxext_table,
	      mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)

void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride)
{
    mmxext_idct (block);
    block_copy (block, dest, stride);
    block_zero (block);
}

void mpeg2_idct_add_mmxext (int16_t * block, uint8_t * dest, int stride)
{
    mmxext_idct (block);
    block_add (block, dest, stride);
    block_zero (block);
}

void mpeg2_idct_mmxext (int16_t * block)
{
    mmxext_idct (block);
}

declare_idct (mmx_idct, mmx_table,
	      mmx_row_head, mmx_row, mmx_row_tail, mmx_row_mid)

void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride)
{
    mmx_idct (block);
    block_copy (block, dest, stride);
    block_zero (block);
}

void mpeg2_idct_add_mmx (int16_t * block, uint8_t * dest, int stride)
{
    mmx_idct (block);
    block_add (block, dest, stride);
    block_zero (block);
}

void mpeg2_idct_mmx (int16_t * block)
{
    mmx_idct (block);
}

void mpeg2_zero_block_mmx (int16_t * block)
{
    block_zero (block);
}

void mpeg2_idct_mmx_init (void)
{
    int i, j;

    /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */

    for (i = 0; i < 64; i++) {
	j = mpeg2_scan_norm[i];
	mpeg2_scan_norm[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
	j = mpeg2_scan_alt[i];
	mpeg2_scan_alt[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
    }
}

#endif

--- NEW FILE: mpeg2.h ---
/*
 * mpeg2.h
 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* Structure for the mpeg2dec decoder */

#ifndef MPEG2_H
#define MPEG2_H

typedef struct mpeg2dec_s {
    xine_video_port_t * output;
    uint32_t frame_format;

    /* this is where we keep the state of the decoder */
    struct picture_s * picture, *picture_base;
    
    uint32_t shift;
    int new_sequence;
    int is_sequence_needed;
    int is_wait_for_ip_frames;
    int frames_to_drop, drop_frame;
    int in_slice;
    int seek_mode, is_frame_needed;

    /* the maximum chunk size is determined by vbv_buffer_size */
    /* which is 224K for MP@ML streams. */
    /* (we make no pretenses of decoding anything more than that) */
    /* allocated in init - gcc has problems allocating such big structures */
    uint8_t * chunk_buffer, *chunk_base;
    /* pointer to current position in chunk_buffer */
    uint8_t * chunk_ptr;
    /* last start code ? */
    uint8_t code;
    uint32_t chunk_size;

    int64_t pts;
    uint32_t rff_pattern; 
    int force_aspect;
    int force_pan_scan;

    xine_stream_t *stream;
    
    /* a spu decoder for possible closed captions */
    spu_decoder_t *cc_dec;
    int xvmc_last_slice_code;
    unsigned xxmc_mb_pic_height;
} mpeg2dec_t ;


/* initialize mpegdec with a opaque user pointer */
void mpeg2_init (mpeg2dec_t * mpeg2dec, 
		 xine_video_port_t * output);

/* destroy everything which was allocated, shutdown the output */
void mpeg2_close (mpeg2dec_t * mpeg2dec);

int mpeg2_decode_data (mpeg2dec_t * mpeg2dec,
		       uint8_t * data_start, uint8_t * data_end, 
		       uint64_t pts);

void mpeg2_find_sequence_header (mpeg2dec_t * mpeg2dec,
				 uint8_t * data_start, uint8_t * data_end);

void mpeg2_flush (mpeg2dec_t * mpeg2dec);
void mpeg2_reset (mpeg2dec_t * mpeg2dec);
void mpeg2_discontinuity (mpeg2dec_t * mpeg2dec);

/* Not needed, it is defined as static in decode.c, and no-one else called it
 * currently
 */
/* void process_userdata(mpeg2dec_t *mpeg2dec, uint8_t *buffer); */

#endif

--- NEW FILE: Makefile.am ---
include $(top_srcdir)/misc/Makefile.common

AM_CFLAGS = $(LIBMPEG2_CFLAGS)

libdir = $(XINE_PLUGINDIR)

lib_LTLIBRARIES = xineplug_decode_mpeg2.la

xineplug_decode_mpeg2_la_SOURCES = \
	cpu_state.c \
	decode.c \
	header.c \
	idct.c \
	idct_altivec.c \
	idct_mlib.c \
	idct_mmx.c \
	motion_comp.c \
	motion_comp_altivec.c \
	motion_comp_mmx.c \
	motion_comp_mlib.c \
	motion_comp_vis.c \
	slice.c \
	slice_xvmc.c \
	slice_xvmc_vld.c \
	stats.c \
	xine_decoder.c

xineplug_decode_mpeg2_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB)
xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@

noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h

--- NEW FILE: vlc.h ---
/*
 * vlc.h
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define GETWORD(bit_buf,shift,bit_ptr)				\
do {								\
    bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift);	\
    bit_ptr += 2;						\
} while (0)

static inline void bitstream_init (picture_t * picture, uint8_t * start)
{
    picture->bitstream_buf =
	(start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3];
    picture->bitstream_ptr = start + 4;
    picture->bitstream_bits = -16;
}

/* make sure that there are at least 16 valid bits in bit_buf */
#define NEEDBITS(bit_buf,bits,bit_ptr)		\
do {						\
    if (bits > 0) {				\
	GETWORD (bit_buf, bits, bit_ptr);	\
	bits -= 16;				\
    }						\
} while (0)

/* remove num valid bits from bit_buf */
#define DUMPBITS(bit_buf,bits,num)	\
do {					\
    bit_buf <<= (num);			\
    bits += (num);			\
} while (0)

/* take num bits from the high part of bit_buf and zero extend them */
#define UBITS(bit_buf,num) (((uint32_t)(bit_buf)) >> (32 - (num)))

/* take num bits from the high part of bit_buf and sign extend them */
#define SBITS(bit_buf,num) (((int32_t)(bit_buf)) >> (32 - (num)))

typedef struct {
    uint8_t modes;
    uint8_t len;
} MBtab;

typedef struct {
    uint8_t delta;
    uint8_t len;
} MVtab;

typedef struct {
    int8_t dmv;
    uint8_t len;
} DMVtab;

typedef struct {
    uint8_t cbp;
    uint8_t len;
} CBPtab;

typedef struct {
    uint8_t size;
    uint8_t len;
} DCtab;

typedef struct {
    uint8_t run;
    uint8_t level;
    uint8_t len;
} DCTtab;

typedef struct {
    uint8_t mba;
    uint8_t len;
} MBAtab;


#define INTRA MACROBLOCK_INTRA
#define QUANT MACROBLOCK_QUANT

static MBtab MB_I [] = {
    {INTRA|QUANT, 2}, {INTRA, 1}
};

#define MC MACROBLOCK_MOTION_FORWARD
#define CODED MACROBLOCK_PATTERN

static MBtab MB_P [] = {
    {INTRA|QUANT, 6}, {CODED|QUANT, 5}, {MC|CODED|QUANT, 5}, {INTRA,    5},
    {MC,          3}, {MC,          3}, {MC,             3}, {MC,       3},
    {CODED,       2}, {CODED,       2}, {CODED,          2}, {CODED,    2},
    {CODED,       2}, {CODED,       2}, {CODED,          2}, {CODED,    2},
    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1}
};

#define FWD MACROBLOCK_MOTION_FORWARD
#define BWD MACROBLOCK_MOTION_BACKWARD
#define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD

static MBtab MB_B [] = {
    {0,                 0}, {INTRA|QUANT,       6},
    {BWD|CODED|QUANT,   6}, {FWD|CODED|QUANT,   6},
    {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
					{INTRA,       5}, {INTRA,       5},
    {FWD,         4}, {FWD,         4}, {FWD,         4}, {FWD,         4},
    {FWD|CODED,   4}, {FWD|CODED,   4}, {FWD|CODED,   4}, {FWD|CODED,   4},
    {BWD,         3}, {BWD,         3}, {BWD,         3}, {BWD,         3},
    {BWD,         3}, {BWD,         3}, {BWD,         3}, {BWD,         3},
    {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3},
    {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3},
    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}
};

#undef INTRA
#undef QUANT
#undef MC
#undef CODED
#undef FWD
#undef BWD
#undef INTER


static MVtab MV_4 [] = {
    { 3, 6}, { 2, 4}, { 1, 3}, { 1, 3}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}
};

static MVtab MV_10 [] = {
    { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10},
    { 0,10}, { 0,10}, { 0,10}, { 0,10}, {15,10}, {14,10}, {13,10}, {12,10},
    {11,10}, {10,10}, { 9, 9}, { 9, 9}, { 8, 9}, { 8, 9}, { 7, 9}, { 7, 9},
    { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7},
    { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7},
    { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}
};


static DMVtab DMV_2 [] = {
    { 0, 1}, { 0, 1}, { 1, 2}, {-1, 2}
};


static CBPtab CBP_7 [] = {
    {0x22, 7}, {0x12, 7}, {0x0a, 7}, {0x06, 7},
    {0x21, 7}, {0x11, 7}, {0x09, 7}, {0x05, 7},
    {0x3f, 6}, {0x3f, 6}, {0x03, 6}, {0x03, 6},
    {0x24, 6}, {0x24, 6}, {0x18, 6}, {0x18, 6},
    {0x3e, 5}, {0x3e, 5}, {0x3e, 5}, {0x3e, 5},
    {0x02, 5}, {0x02, 5}, {0x02, 5}, {0x02, 5},
    {0x3d, 5}, {0x3d, 5}, {0x3d, 5}, {0x3d, 5},
    {0x01, 5}, {0x01, 5}, {0x01, 5}, {0x01, 5},
    {0x38, 5}, {0x38, 5}, {0x38, 5}, {0x38, 5},
    {0x34, 5}, {0x34, 5}, {0x34, 5}, {0x34, 5},
    {0x2c, 5}, {0x2c, 5}, {0x2c, 5}, {0x2c, 5},
    {0x1c, 5}, {0x1c, 5}, {0x1c, 5}, {0x1c, 5},
    {0x28, 5}, {0x28, 5}, {0x28, 5}, {0x28, 5},
    {0x14, 5}, {0x14, 5}, {0x14, 5}, {0x14, 5},
    {0x30, 5}, {0x30, 5}, {0x30, 5}, {0x30, 5},
    {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5},
    {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
    {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
    {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
    {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
    {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
    {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
    {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
    {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}
};

static CBPtab CBP_9 [] = {
    {0,    0}, {0x00, 9}, {0x27, 9}, {0x1b, 9},
    {0x3b, 9}, {0x37, 9}, {0x2f, 9}, {0x1f, 9},
    {0x3a, 8}, {0x3a, 8}, {0x36, 8}, {0x36, 8},
    {0x2e, 8}, {0x2e, 8}, {0x1e, 8}, {0x1e, 8},
    {0x39, 8}, {0x39, 8}, {0x35, 8}, {0x35, 8},
    {0x2d, 8}, {0x2d, 8}, {0x1d, 8}, {0x1d, 8},
    {0x26, 8}, {0x26, 8}, {0x1a, 8}, {0x1a, 8},
    {0x25, 8}, {0x25, 8}, {0x19, 8}, {0x19, 8},
    {0x2b, 8}, {0x2b, 8}, {0x17, 8}, {0x17, 8},
    {0x33, 8}, {0x33, 8}, {0x0f, 8}, {0x0f, 8},
    {0x2a, 8}, {0x2a, 8}, {0x16, 8}, {0x16, 8},
    {0x32, 8}, {0x32, 8}, {0x0e, 8}, {0x0e, 8},
    {0x29, 8}, {0x29, 8}, {0x15, 8}, {0x15, 8},
    {0x31, 8}, {0x31, 8}, {0x0d, 8}, {0x0d, 8},
    {0x23, 8}, {0x23, 8}, {0x13, 8}, {0x13, 8},
    {0x0b, 8}, {0x0b, 8}, {0x07, 8}, {0x07, 8}
};


static DCtab DC_lum_5 [] = {
    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
    {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
    {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}
};

static DCtab DC_chrom_5 [] = {
    {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
    {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}
};

static DCtab DC_long [] = {
    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
    {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, { 7, 6}, { 7, 6},
    {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9}
};


static DCTtab DCT_16 [] = {
    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
    {  2,18, 0}, {  2,17, 0}, {  2,16, 0}, {  2,15, 0},
    {  7, 3, 0}, { 17, 2, 0}, { 16, 2, 0}, { 15, 2, 0},
    { 14, 2, 0}, { 13, 2, 0}, { 12, 2, 0}, { 32, 1, 0},
    { 31, 1, 0}, { 30, 1, 0}, { 29, 1, 0}, { 28, 1, 0}
};

static DCTtab DCT_15 [] = {
    {  1,40,15}, {  1,39,15}, {  1,38,15}, {  1,37,15},
    {  1,36,15}, {  1,35,15}, {  1,34,15}, {  1,33,15},
    {  1,32,15}, {  2,14,15}, {  2,13,15}, {  2,12,15},
    {  2,11,15}, {  2,10,15}, {  2, 9,15}, {  2, 8,15},
    {  1,31,14}, {  1,31,14}, {  1,30,14}, {  1,30,14},
    {  1,29,14}, {  1,29,14}, {  1,28,14}, {  1,28,14},
    {  1,27,14}, {  1,27,14}, {  1,26,14}, {  1,26,14},
    {  1,25,14}, {  1,25,14}, {  1,24,14}, {  1,24,14},
    {  1,23,14}, {  1,23,14}, {  1,22,14}, {  1,22,14},
    {  1,21,14}, {  1,21,14}, {  1,20,14}, {  1,20,14},
    {  1,19,14}, {  1,19,14}, {  1,18,14}, {  1,18,14},
    {  1,17,14}, {  1,17,14}, {  1,16,14}, {  1,16,14}
};

static DCTtab DCT_13 [] = {
    { 11, 2,13}, { 10, 2,13}, {  6, 3,13}, {  4, 4,13},
    {  3, 5,13}, {  2, 7,13}, {  2, 6,13}, {  1,15,13},
    {  1,14,13}, {  1,13,13}, {  1,12,13}, { 27, 1,13},
    { 26, 1,13}, { 25, 1,13}, { 24, 1,13}, { 23, 1,13},
    {  1,11,12}, {  1,11,12}, {  9, 2,12}, {  9, 2,12},
    {  5, 3,12}, {  5, 3,12}, {  1,10,12}, {  1,10,12},
    {  3, 4,12}, {  3, 4,12}, {  8, 2,12}, {  8, 2,12},
    { 22, 1,12}, { 22, 1,12}, { 21, 1,12}, { 21, 1,12},
    {  1, 9,12}, {  1, 9,12}, { 20, 1,12}, { 20, 1,12},
    { 19, 1,12}, { 19, 1,12}, {  2, 5,12}, {  2, 5,12},
    {  4, 3,12}, {  4, 3,12}, {  1, 8,12}, {  1, 8,12},
    {  7, 2,12}, {  7, 2,12}, { 18, 1,12}, { 18, 1,12}
};

static DCTtab DCT_B14_10 [] = {
    { 17, 1,10}, {  6, 2,10}, {  1, 7,10}, {  3, 3,10},
    {  2, 4,10}, { 16, 1,10}, { 15, 1,10}, {  5, 2,10}
};

static DCTtab DCT_B14_8 [] = {
    { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
    {  3, 2, 7}, {  3, 2, 7}, { 10, 1, 7}, { 10, 1, 7},
    {  1, 4, 7}, {  1, 4, 7}, {  9, 1, 7}, {  9, 1, 7},
    {  8, 1, 6}, {  8, 1, 6}, {  8, 1, 6}, {  8, 1, 6},
    {  7, 1, 6}, {  7, 1, 6}, {  7, 1, 6}, {  7, 1, 6},
    {  2, 2, 6}, {  2, 2, 6}, {  2, 2, 6}, {  2, 2, 6},
    {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6},
    { 14, 1, 8}, {  1, 6, 8}, { 13, 1, 8}, { 12, 1, 8},
    {  4, 2, 8}, {  2, 3, 8}, {  1, 5, 8}, { 11, 1, 8}
};

static DCTtab DCT_B14AC_5 [] = {
		 {  1, 3, 5}, {  5, 1, 5}, {  4, 1, 5},
    {  1, 2, 4}, {  1, 2, 4}, {  3, 1, 4}, {  3, 1, 4},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
    {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}
};

static DCTtab DCT_B14DC_5 [] = {
		 {  1, 3, 5}, {  5, 1, 5}, {  4, 1, 5},
    {  1, 2, 4}, {  1, 2, 4}, {  3, 1, 4}, {  3, 1, 4},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1},
    {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1},
    {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1},
    {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}
};

static DCTtab DCT_B15_10 [] = {
    {  6, 2, 9}, {  6, 2, 9}, { 15, 1, 9}, { 15, 1, 9},
    {  3, 4,10}, { 17, 1,10}, { 16, 1, 9}, { 16, 1, 9}
};

static DCTtab DCT_B15_8 [] = {
    { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
    {  8, 1, 7}, {  8, 1, 7}, {  9, 1, 7}, {  9, 1, 7},
    {  7, 1, 7}, {  7, 1, 7}, {  3, 2, 7}, {  3, 2, 7},
    {  1, 7, 6}, {  1, 7, 6}, {  1, 7, 6}, {  1, 7, 6},
    {  1, 6, 6}, {  1, 6, 6}, {  1, 6, 6}, {  1, 6, 6},
    {  5, 1, 6}, {  5, 1, 6}, {  5, 1, 6}, {  5, 1, 6},
    {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6},
    {  2, 5, 8}, { 12, 1, 8}, {  1,11, 8}, {  1,10, 8},
    { 14, 1, 8}, { 13, 1, 8}, {  4, 2, 8}, {  2, 4, 8},
    {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5},
    {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5},
    {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5},
    {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5},
    {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5},
    {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
    {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5},
    {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5},
    {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5},
    {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5},
    { 10, 1, 7}, { 10, 1, 7}, {  2, 3, 7}, {  2, 3, 7},
    { 11, 1, 7}, { 11, 1, 7}, {  1, 8, 7}, {  1, 8, 7},
    {  1, 9, 7}, {  1, 9, 7}, {  1,12, 8}, {  1,13, 8},
    {  3, 3, 8}, {  5, 2, 8}, {  1,14, 8}, {  1,15, 8}
};


static MBAtab MBA_5 [] = {
		    {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
    {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
    {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1},
    {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}
};

static MBAtab MBA_11 [] = {
    {32, 11}, {31, 11}, {30, 11}, {29, 11},
    {28, 11}, {27, 11}, {26, 11}, {25, 11},
    {24, 11}, {23, 11}, {22, 11}, {21, 11},
    {20, 10}, {20, 10}, {19, 10}, {19, 10},
    {18, 10}, {18, 10}, {17, 10}, {17, 10},
    {16, 10}, {16, 10}, {15, 10}, {15, 10},
    {14,  8}, {14,  8}, {14,  8}, {14,  8},
    {14,  8}, {14,  8}, {14,  8}, {14,  8},
    {13,  8}, {13,  8}, {13,  8}, {13,  8},
    {13,  8}, {13,  8}, {13,  8}, {13,  8},
    {12,  8}, {12,  8}, {12,  8}, {12,  8},
    {12,  8}, {12,  8}, {12,  8}, {12,  8},
    {11,  8}, {11,  8}, {11,  8}, {11,  8},
    {11,  8}, {11,  8}, {11,  8}, {11,  8},
    {10,  8}, {10,  8}, {10,  8}, {10,  8},
    {10,  8}, {10,  8}, {10,  8}, {10,  8},
    { 9,  8}, { 9,  8}, { 9,  8}, { 9,  8},
    { 9,  8}, { 9,  8}, { 9,  8}, { 9,  8},
    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
    { 7,  7}, { 7,  7}, { 7,  7}, { 7,  7},
    { 7,  7}, { 7,  7}, { 7,  7}, { 7,  7},
    { 7,  7}, { 7,  7}, { 7,  7}, { 7,  7},
    { 7,  7}, { 7,  7}, { 7,  7}, { 7,  7}
};

--- NEW FILE: motion_comp.c ---
/*
 * motion_comp.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdio.h>
#include <inttypes.h>

#include "mpeg2_internal.h"
#include "xineutils.h"

mpeg2_mc_t mpeg2_mc;

void mpeg2_mc_init (uint32_t mm_accel)
{
#ifdef LIBMPEG2_MLIB
    if (mm_accel & MM_ACCEL_MLIB) {
#ifdef LOG
	fprintf (stderr, "Using mediaLib for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_mlib;
    }
#endif

#ifdef ARCH_X86
    if (mm_accel & MM_ACCEL_X86_MMXEXT) {
#ifdef LOG
	fprintf (stderr, "Using MMXEXT for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_mmxext;
    } else if (mm_accel & MM_ACCEL_X86_3DNOW) {
#ifdef LOG
	fprintf (stderr, "Using 3DNOW for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_3dnow;
    } else if (mm_accel & MM_ACCEL_X86_MMX) {
#ifdef LOG
	fprintf (stderr, "Using MMX for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_mmx;
    } else
#endif
#if defined (ARCH_PPC) && defined (ENABLE_ALTIVEC)
    if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
#ifdef LOG
	fprintf (stderr, "Using altivec for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_altivec;
    } else
#endif
#ifdef ARCH_SPARC
    if (mm_accel & MM_ACCEL_SPARC_VIS) {
#ifdef LOG
	fprintf (stderr, "Using VIS for motion compensation\n");
#endif
	mpeg2_mc = mpeg2_mc_vis;
    } else
#endif
    {
#ifdef LOG
	fprintf (stderr, "No accelerated motion compensation found\n");
#endif
	mpeg2_mc = mpeg2_mc_c;
    }
}

#define avg2(a,b) ((a+b+1)>>1)
#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)

#define predict_o(i) (ref[i])
#define predict_x(i) (avg2 (ref[i], ref[i+1]))
#define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
#define predict_xy(i) (avg4 (ref[i], ref[i+1], \
			     (ref+stride)[i], (ref+stride)[i+1]))

#define put(predictor,i) dest[i] = predictor (i)
#define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])

/* mc function template */

#define MC_FUNC(op,xy)							\
static void MC_##op##_##xy##_16_c (uint8_t * dest, uint8_t * ref,	\
				 int stride, int height)		\
{									\
    do {								\
	op (predict_##xy, 0);						\
	op (predict_##xy, 1);						\
	op (predict_##xy, 2);						\
	op (predict_##xy, 3);						\
	op (predict_##xy, 4);						\
	op (predict_##xy, 5);						\
	op (predict_##xy, 6);						\
	op (predict_##xy, 7);						\
	op (predict_##xy, 8);						\
	op (predict_##xy, 9);						\
	op (predict_##xy, 10);						\
	op (predict_##xy, 11);						\
	op (predict_##xy, 12);						\
	op (predict_##xy, 13);						\
	op (predict_##xy, 14);						\
	op (predict_##xy, 15);						\
	ref += stride;							\
	dest += stride;							\
    } while (--height);							\
}									\
static void MC_##op##_##xy##_8_c (uint8_t * dest, uint8_t * ref,	\
				int stride, int height)			\
{									\
    do {								\
	op (predict_##xy, 0);						\
	op (predict_##xy, 1);						\
	op (predict_##xy, 2);						\
	op (predict_##xy, 3);						\
	op (predict_##xy, 4);						\
	op (predict_##xy, 5);						\
	op (predict_##xy, 6);						\
	op (predict_##xy, 7);						\
	ref += stride;							\
	dest += stride;							\
    } while (--height);							\
}

/* definitions of the actual mc functions */

MC_FUNC (put,o)
MC_FUNC (avg,o)
MC_FUNC (put,x)
MC_FUNC (avg,x)
MC_FUNC (put,y)
MC_FUNC (avg,y)
MC_FUNC (put,xy)
MC_FUNC (avg,xy)

MPEG2_MC_EXTERN (c)

--- NEW FILE: xvmc_vld.h ---
/*
 * Copyright (c) 2004 The Unichrome project. All rights reserved.
 *
 * This program 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, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTIES OR REPRESENTATIONS; 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
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 */

#ifndef _XVMC_VLD_H
#define _XVMC_VLD_H

#include "accel_xvmc.h"
#include "xvmc.h"

extern void mpeg2_xxmc_slice( mpeg2dec_t *mpeg2dec, picture_t *picture, 
			      int code, uint8_t *buffer); 
extern void mpeg2_xxmc_choose_coding(mpeg2dec_t *mpeg2dec, picture_t *picture, 
				     double aspect_ratio, int flags); 

extern void mpeg2_xxmc_vld_frame_complete(mpeg2dec_t *mpeg2dec, picture_t *picture, int code);


#endif

--- NEW FILE: header.c ---
/*
 * header.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
#define LOG_PAN_SCAN
*/

#include "config.h"

#include <stdio.h>  /* For printf debugging */
#include <inttypes.h>

#include "mpeg2_internal.h"
#include "attributes.h"

/* default intra quant matrix, in zig-zag order */
static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
    8,
    16, 16,
    19, 16, 19,
    22, 22, 22, 22,
    22, 22, 26, 24, 26,
    27, 27, 27, 26, 26, 26,
    26, 27, 27, 27, 29, 29, 29,
    34, 34, 34, 29, 29, 29, 27, 27,
    29, 29, 32, 32, 34, 34, 37,
    38, 37, 35, 35, 34, 35,
    38, 38, 40, 40, 40,
    48, 48, 46, 46,
    56, 56, 58,
    69, 69,
    83
};

uint8_t mpeg2_scan_norm[64] ATTR_ALIGN(16) =
{
    /* Zig-Zag scan pattern */
     0, 1, 8,16, 9, 2, 3,10,
    17,24,32,25,18,11, 4, 5,
    12,19,26,33,40,48,41,34,
    27,20,13, 6, 7,14,21,28,
    35,42,49,56,57,50,43,36,
    29,22,15,23,30,37,44,51,
    58,59,52,45,38,31,39,46,
    53,60,61,54,47,55,62,63
};

uint8_t mpeg2_scan_alt[64] ATTR_ALIGN(16) =
{
    /* Alternate scan pattern */
    0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
    41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
    51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
    53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
};

/* count must be between 1 and 32 */
static uint32_t get_bits(uint8_t *buffer, uint32_t count, uint32_t *bit_position) {
  uint32_t byte_offset;
  uint32_t bit_offset;
  uint32_t bit_mask;
  uint32_t bit_bite;
  uint32_t result=0;
  if (count == 0) return 0; 
  do {
    byte_offset = *bit_position >> 3;  /* Div 8 */
    bit_offset = 8 - (*bit_position & 0x7); /* Bits got 87654321 */
    bit_mask = ((1 << (bit_offset)) - 1);
    bit_bite = bit_offset;
    if (count < bit_offset) {
      bit_mask ^=  ((1 << (bit_offset-count)) - 1);
      bit_bite = count;
    }
    /*
    printf("Byte=0x%02x Bitmask=0x%04x byte_offset=%u bit_offset=%u bit_byte=%u count=%u\n",buffer[byte_offset], bit_mask, byte_offset, bit_offset, bit_bite,count);
    */
    result = (result << bit_bite) | ((buffer[byte_offset] & bit_mask) >> (bit_offset-bit_bite));
    *bit_position+=bit_bite;
    count-=bit_bite;
  } while ((count > 0) && (byte_offset<50) ); 
  return result;
}

void mpeg2_header_state_init (picture_t * picture)
{
    picture->scan = mpeg2_scan_norm;
    picture->load_intra_quantizer_matrix = 1;
    picture->load_non_intra_quantizer_matrix = 1;
}

int mpeg2_header_sequence (picture_t * picture, uint8_t * buffer)
{
    int width, height;
    int i;

    if ((buffer[6] & 0x20) != 0x20)
	return 1;	/* missing marker_bit */

    height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];

    picture->display_width = width = (height >> 12);
    picture->display_height = height = (height & 0xfff);
    
    width = (width + 15) & ~15;
    height = (height + 15) & ~15;

    if ((width > 1920) || (height > 1152))
	return 1;	/* size restrictions for MP@HL */

    picture->coded_picture_width = width;
    picture->coded_picture_height = height;

    /* this is not used by the decoder */
    picture->aspect_ratio_information = buffer[3] >> 4;
    picture->frame_rate_code = buffer[3] & 15;
    picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);

    if (buffer[7] & 2) {
	for (i = 0; i < 64; i++)
	    picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
		(buffer[i+7] << 7) | (buffer[i+8] >> 1);
	buffer += 64;
    } else
	for (i = 0; i < 64; i++)
	    picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
		default_intra_quantizer_matrix [i];

    if (buffer[7] & 1)
	for (i = 0; i < 64; i++)
	    picture->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
		buffer[i+8];
    else
	for (i = 0; i < 64; i++)
	    picture->non_intra_quantizer_matrix[i] = 16;
    picture->load_intra_quantizer_matrix = 1;
    picture->load_non_intra_quantizer_matrix = 1;
    /* MPEG1 - for testing only */
    picture->mpeg1 = 1;
    picture->intra_dc_precision = 0;
    picture->frame_pred_frame_dct = 1;
    picture->q_scale_type = 0;
    picture->concealment_motion_vectors = 0;
    /* picture->alternate_scan = 0; */
    picture->picture_structure = FRAME_PICTURE;
    /* picture->second_field = 0; */

    return 0;
}

static int sequence_extension (picture_t * picture, uint8_t * buffer)
{
    /* check chroma format, size extensions, marker bit */
    if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) ||
	((buffer[3] & 0x01) != 0x01))
	return 1;

    /* this is not used by the decoder */
    picture->progressive_sequence = (buffer[1] >> 3) & 1;

    picture->low_delay = buffer[5] & 0x80;

    if (!picture->progressive_sequence)
	picture->coded_picture_height =
	    (picture->coded_picture_height + 31) & ~31;
    
    
    /* printf ("libmpeg2: low_delay : %d\n", picture->low_delay); */

/*
    printf ("libmpeg2: sequence extension+5 : %08x (%d)\n",
	    buffer[5], buffer[5] % 0x80);
 */

    picture->frame_rate_ext_n = buffer[5] & 0x31;
    picture->frame_rate_ext_d = (buffer[5] >> 2) & 0x03;
    
    /* MPEG1 - for testing only */
    picture->mpeg1 = 0;

    return 0;
}

static int quant_matrix_extension (picture_t * picture, uint8_t * buffer)
{
    int i;

    if (buffer[0] & 8) {
	for (i = 0; i < 64; i++)
	    picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
		(buffer[i] << 5) | (buffer[i+1] >> 3);
	buffer += 64;
    }

    if (buffer[0] & 4)
	for (i = 0; i < 64; i++)
	    picture->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
		(buffer[i] << 6) | (buffer[i+1] >> 2);

    return 0;
}

static int picture_coding_extension (picture_t * picture, uint8_t * buffer)
{
    /* pre subtract 1 for use later in compute_motion_vector */
    picture->f_motion.f_code[0] = (buffer[0] & 15) - 1;
    picture->f_motion.f_code[1] = (buffer[1] >> 4) - 1;
    picture->b_motion.f_code[0] = (buffer[1] & 15) - 1;
    picture->b_motion.f_code[1] = (buffer[2] >> 4) - 1;

    picture->intra_dc_precision = (buffer[2] >> 2) & 3;
    picture->picture_structure = buffer[2] & 3;
    picture->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
    picture->concealment_motion_vectors = (buffer[3] >> 5) & 1;
    picture->q_scale_type = (buffer[3] >> 4) & 1;
    picture->intra_vlc_format = (buffer[3] >> 3) & 1;

    if (buffer[3] & 4)	/* alternate_scan */
	picture->scan = mpeg2_scan_alt;
    else
	picture->scan = mpeg2_scan_norm;

    /* these are not used by the decoder */
    picture->top_field_first = buffer[3] >> 7;
    picture->repeat_first_field = (buffer[3] >> 1) & 1;
    picture->progressive_frame = buffer[4] >> 7;

    return 0;
}

static int sequence_display_extension (picture_t * picture, uint8_t * buffer) {
  /* FIXME: implement. */
  uint32_t bit_position;
  uint32_t padding;
  
  bit_position = 0; 
  padding = get_bits(buffer, 4, &bit_position);
  picture->video_format = get_bits(buffer, 3, &bit_position);
  picture->colour_description = get_bits(buffer, 1, &bit_position);
  if(picture->colour_description) {
  picture->colour_primatives = get_bits(buffer, 8, &bit_position);
  picture->transfer_characteristics = get_bits(buffer, 8, &bit_position);
  picture->matrix_coefficients = get_bits(buffer, 8, &bit_position);
  }
  picture->display_horizontal_size = get_bits(buffer, 14, &bit_position);
  padding = get_bits(buffer, 1, &bit_position);
  picture->display_vertical_size = get_bits(buffer, 14, &bit_position);

#ifdef LOG_PAN_SCAN
  printf("Sequence_display_extension\n");
  printf("     video_format: %u\n", picture->video_format);
  printf("     colour_description: %u\n", picture->colour_description);
  if(picture->colour_description) {
  printf("     colour_primatives: %u\n", picture->colour_primatives);
  printf("     transfer_characteristics %u\n", picture->transfer_characteristics);
  printf("     matrix_coefficients %u\n", picture->matrix_coefficients);
  }
  printf("     display_horizontal_size %u\n", picture->display_horizontal_size);
  printf("     display_vertical_size %u\n", picture->display_vertical_size);
#endif

  return 0;
}

static int picture_display_extension (picture_t * picture, uint8_t * buffer) {
  uint32_t bit_position;
  uint32_t padding;

#ifdef LOG_PAN_SCAN     
    printf ("libmpeg2: picture_display_extension\n");
#endif
  
  bit_position = 0; 
  padding = get_bits(buffer, 4, &bit_position);
  picture->frame_centre_horizontal_offset = get_bits(buffer, 16, &bit_position);
  padding = get_bits(buffer, 1, &bit_position);
  picture->frame_centre_vertical_offset = get_bits(buffer, 16, &bit_position);
  padding = get_bits(buffer, 1, &bit_position);

#ifdef LOG_PAN_SCAN
  printf("Pan & Scan centre (x,y) = (%u, %u)\n",  
    picture->frame_centre_horizontal_offset,
    picture->frame_centre_vertical_offset);
#endif

  return 0;
}

int mpeg2_header_extension (picture_t * picture, uint8_t * buffer)
{
    switch (buffer[0] & 0xf0) {
    case 0x00:	/* reserved */
        return 0;

    case 0x10:	/* sequence extension */
	return sequence_extension (picture, buffer);

    case 0x20:	/* sequence display extension for Pan & Scan */
	return sequence_display_extension (picture, buffer);

    case 0x30:	/* quant matrix extension */
	return quant_matrix_extension (picture, buffer);

    case 0x40:	/* copyright extension */
        return 0;

    case 0x50:	/* sequence scalable extension */
        return 0;

    case 0x60:	/* reserved */
        return 0;

    case 0x70:	/* picture display extension for Pan & Scan */
	return picture_display_extension (picture, buffer);

    case 0x80:	/* picture coding extension */
	return picture_coding_extension (picture, buffer);

    case 0x90:	/* picture spacial scalable extension */
        return 0;

    case 0xA0:	/* picture temporal scalable extension */
        return 0;

    case 0xB0:	/* camera parameters extension */
        return 0;

    case 0xC0:	/* ITU-T extension */
        return 0;

    case 0xD0:	/* reserved */
        return 0;

    case 0xE0:	/* reserved */
        return 0;

    case 0xF0:	/* reserved */
        return 0;
    }

    return 0;
}

int mpeg2_header_group_of_pictures (picture_t * picture, uint8_t * buffer) {
  uint32_t bit_position;
  uint32_t padding;
  bit_position = 0;
  
  picture->drop_frame_flag = get_bits(buffer, 1, &bit_position);
  picture->time_code_hours = get_bits(buffer, 5, &bit_position);
  picture->time_code_minutes = get_bits(buffer, 6, &bit_position);
  padding = get_bits(buffer, 1, &bit_position);
  picture->time_code_seconds = get_bits(buffer, 6, &bit_position);
  picture->time_code_pictures = get_bits(buffer, 6, &bit_position);
  picture->closed_gop = get_bits(buffer, 1, &bit_position);
  picture->broken_link = get_bits(buffer, 1, &bit_position);

#ifdef LOG_PAN_SCAN     
  printf("Group of pictures\n");
  printf("     drop_frame_flag: %u\n", picture->drop_frame_flag);
  printf("     time_code: HH:MM:SS:Pictures %02u:%02u:%02u:%02u\n", 
         picture->time_code_hours,
         picture->time_code_minutes,
         picture->time_code_seconds,
         picture->time_code_pictures);
  printf("     closed_gop: %u\n", picture->closed_gop);
  printf("     bloken_link: %u\n", picture->broken_link);
#endif

  return 0;
}

int mpeg2_header_picture (picture_t * picture, uint8_t * buffer)
{
    picture->picture_coding_type = (buffer [1] >> 3) & 7;
    picture->vbv_delay = ((buffer[1] << 13) | (buffer[2] << 5) |
			  (buffer[3] >> 3)) & 0xffff;

    /* forward_f_code and backward_f_code - used in mpeg1 only */
    picture->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
    picture->f_motion.f_code[0] =
	(((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
    picture->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
    picture->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;

    /* move in header_process_picture_header */
        picture->second_field =
            (picture->picture_structure != FRAME_PICTURE) &&
            !(picture->second_field);

    return 0;
}

--- NEW FILE: idct.c ---
/*
 * idct.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * Portions of this code are from the MPEG software simulation group
 * idct implementation. This code will be replaced with a new
 * implementation soon.
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**********************************************************/
/* inverse two dimensional DCT, Chen-Wang algorithm */
/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
/* 32-bit integer arithmetic (8 bit coefficients) */
/* 11 mults, 29 adds per DCT */
/* sE, 18.8.91 */
/**********************************************************/
/* coefficients extended to 12 bit for IEEE1180-1990 */
/* compliance sE, 2.1.94 */
/**********************************************************/

/* this code assumes >> to be a two's-complement arithmetic */
/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "mpeg2_internal.h"
#include "xineutils.h"

#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
#define W7 565  /* 2048*sqrt (2)*cos (7*pi/16) */

/* idct main entry points  */
void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
void (* mpeg2_idct_add) (int16_t * block, uint8_t * dest, int stride);
void (* mpeg2_idct) (int16_t * block);
void (*	mpeg2_zero_block) (int16_t * block);

static uint8_t clip_lut[1024];
#define CLIP(i) ((clip_lut+384)[ (i)])

/* row (horizontal) IDCT
 *
 * 7 pi 1
 * dst[k] = sum c[l] * src[l] * cos ( -- * ( k + - ) * l )
 * l=0 8 2
 *
 * where: c[0] = 128
 * c[1..7] = 128*sqrt (2)
 */

static void inline idct_row (int16_t * block)
{
    int x0, x1, x2, x3, x4, x5, x6, x7, x8;

    x1 = block[4] << 11;
    x2 = block[6];
    x3 = block[2];
    x4 = block[1];
    x5 = block[7];
    x6 = block[5];
    x7 = block[3];

    /* shortcut */
    if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
	block[0] = block[1] = block[2] = block[3] = block[4] =
	    block[5] = block[6] = block[7] = block[0]<<3;
	return;
    }

    x0 = (block[0] << 11) + 128; /* for proper rounding in the fourth stage */

    /* first stage */
    x8 = W7 * (x4 + x5);
    x4 = x8 + (W1 - W7) * x4;
    x5 = x8 - (W1 + W7) * x5;
    x8 = W3 * (x6 + x7);
    x6 = x8 - (W3 - W5) * x6;
    x7 = x8 - (W3 + W5) * x7;
 
    /* second stage */
    x8 = x0 + x1;
    x0 -= x1;
    x1 = W6 * (x3 + x2);
    x2 = x1 - (W2 + W6) * x2;
    x3 = x1 + (W2 - W6) * x3;
    x1 = x4 + x6;
    x4 -= x6;
    x6 = x5 + x7;
    x5 -= x7;
 
    /* third stage */
    x7 = x8 + x3;
    x8 -= x3;
    x3 = x0 + x2;
    x0 -= x2;
    x2 = (181 * (x4 + x5) + 128) >> 8;
    x4 = (181 * (x4 - x5) + 128) >> 8;
 
    /* fourth stage */
    block[0] = (x7 + x1) >> 8;
    block[1] = (x3 + x2) >> 8;
    block[2] = (x0 + x4) >> 8;
    block[3] = (x8 + x6) >> 8;
    block[4] = (x8 - x6) >> 8;
    block[5] = (x0 - x4) >> 8;
    block[6] = (x3 - x2) >> 8;
    block[7] = (x7 - x1) >> 8;
}

/* column (vertical) IDCT
 *
 * 7 pi 1
 * dst[8*k] = sum c[l] * src[8*l] * cos ( -- * ( k + - ) * l )
 * l=0 8 2
 *
 * where: c[0] = 1/1024
 * c[1..7] = (1/1024)*sqrt (2)
 */

static void inline idct_col (int16_t *block)
{
    int x0, x1, x2, x3, x4, x5, x6, x7, x8;

    /* shortcut */
    x1 = block [8*4] << 8;
    x2 = block [8*6];
    x3 = block [8*2];
    x4 = block [8*1];
    x5 = block [8*7];
    x6 = block [8*5];
    x7 = block [8*3];

#if 0
    if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
	block[8*0] = block[8*1] = block[8*2] = block[8*3] = block[8*4] =
	    block[8*5] = block[8*6] = block[8*7] = (block[8*0] + 32) >> 6;
	return;
    }
#endif

    x0 = (block[8*0] << 8) + 8192;

    /* first stage */
    x8 = W7 * (x4 + x5) + 4;
    x4 = (x8 + (W1 - W7) * x4) >> 3;
    x5 = (x8 - (W1 + W7) * x5) >> 3;
    x8 = W3 * (x6 + x7) + 4;
    x6 = (x8 - (W3 - W5) * x6) >> 3;
    x7 = (x8 - (W3 + W5) * x7) >> 3;
 
    /* second stage */
    x8 = x0 + x1;
    x0 -= x1;
    x1 = W6 * (x3 + x2) + 4;
    x2 = (x1 - (W2 + W6) * x2) >> 3;
    x3 = (x1 + (W2 - W6) * x3) >> 3;
    x1 = x4 + x6;
    x4 -= x6;
    x6 = x5 + x7;
    x5 -= x7;
 
    /* third stage */
    x7 = x8 + x3;
    x8 -= x3;
    x3 = x0 + x2;
    x0 -= x2;
    x2 = (181 * (x4 + x5) + 128) >> 8;
    x4 = (181 * (x4 - x5) + 128) >> 8;
 
    /* fourth stage */
    block[8*0] = (x7 + x1) >> 14;
    block[8*1] = (x3 + x2) >> 14;
    block[8*2] = (x0 + x4) >> 14;
    block[8*3] = (x8 + x6) >> 14;
    block[8*4] = (x8 - x6) >> 14;
    block[8*5] = (x0 - x4) >> 14;
    block[8*6] = (x3 - x2) >> 14;
    block[8*7] = (x7 - x1) >> 14;
}

static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest, int stride)
{
    int i;

    for (i = 0; i < 8; i++)
	idct_row (block + 8 * i);

    for (i = 0; i < 8; i++)
	idct_col (block + i);

    i = 8;
    do {
	dest[0] = CLIP (block[0]);
	dest[1] = CLIP (block[1]);
	dest[2] = CLIP (block[2]);
	dest[3] = CLIP (block[3]);
	dest[4] = CLIP (block[4]);
	dest[5] = CLIP (block[5]);
	dest[6] = CLIP (block[6]);
	dest[7] = CLIP (block[7]);

	block[0] = 0;   block[1] = 0;   block[2] = 0;   block[3] = 0;
	block[4] = 0;   block[5] = 0;   block[6] = 0;   block[7] = 0;

	dest += stride;
	block += 8;
    } while (--i);
}

static void mpeg2_idct_add_c (int16_t * block, uint8_t * dest, int stride)
{
    int i;

    for (i = 0; i < 8; i++)
	idct_row (block + 8 * i);

    for (i = 0; i < 8; i++)
	idct_col (block + i);

    i = 8;
    do {
	dest[0] = CLIP (block[0] + dest[0]);
	dest[1] = CLIP (block[1] + dest[1]);
	dest[2] = CLIP (block[2] + dest[2]);
	dest[3] = CLIP (block[3] + dest[3]);
	dest[4] = CLIP (block[4] + dest[4]);
	dest[5] = CLIP (block[5] + dest[5]);
	dest[6] = CLIP (block[6] + dest[6]);
	dest[7] = CLIP (block[7] + dest[7]);

	block[0] = 0;   block[1] = 0;   block[2] = 0;   block[3] = 0;
	block[4] = 0;   block[5] = 0;   block[6] = 0;   block[7] = 0;

	dest += stride;
	block += 8;
    } while (--i);
}

static void mpeg2_idct_c (int16_t * block)
{
    int i;

    for (i = 0; i < 8; i++)
	idct_row (block + 8 * i);

    for (i = 0; i < 8; i++)
	idct_col (block + i);
}

static void mpeg2_zero_block_c (int16_t * wblock)
{
  memset( wblock, 0, sizeof(int16_t) * 64 );
}

void mpeg2_idct_init (uint32_t mm_accel)
{
    mpeg2_zero_block = mpeg2_zero_block_c;

#ifdef ARCH_X86
    if (mm_accel & MM_ACCEL_X86_MMXEXT) {
#ifdef LOG
	fprintf (stderr, "Using MMXEXT for IDCT transform\n");
#endif
	mpeg2_idct_copy = mpeg2_idct_copy_mmxext;
	mpeg2_idct_add = mpeg2_idct_add_mmxext;
	mpeg2_idct     = mpeg2_idct_mmxext;
	mpeg2_zero_block = mpeg2_zero_block_mmx;
	mpeg2_idct_mmx_init ();
    } else if (mm_accel & MM_ACCEL_X86_MMX) {
#ifdef LOG
	fprintf (stderr, "Using MMX for IDCT transform\n");
#endif
	mpeg2_idct_copy = mpeg2_idct_copy_mmx;
	mpeg2_idct_add  = mpeg2_idct_add_mmx;
	mpeg2_idct      = mpeg2_idct_mmx;
	mpeg2_zero_block = mpeg2_zero_block_mmx;
	mpeg2_idct_mmx_init ();
    } else
#endif
#if defined (ARCH_PPC) && defined (ENABLE_ALTIVEC)
    if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
#ifdef LOG
	fprintf (stderr, "Using altivec for IDCT transform\n");
#endif
	mpeg2_idct_copy = mpeg2_idct_copy_altivec;
	mpeg2_idct_add = mpeg2_idct_add_altivec;
	mpeg2_idct_altivec_init ();
	mpeg2_idct       = mpeg2_idct_c;
    } else
#endif
#ifdef LIBMPEG2_MLIB
    if (mm_accel & MM_ACCEL_MLIB) {
	char * env_var;

	env_var = getenv ("MLIB_NON_IEEE");

	mpeg2_idct = mpeg2_idct_mlib;
	if (env_var == NULL) {
#ifdef LOG
	    fprintf (stderr, "Using mlib for IDCT transform\n");
#endif
	    mpeg2_idct_add = mpeg2_idct_add_mlib;
	} else {
	    fprintf (stderr, "Using non-IEEE mlib for IDCT transform\n");
	    mpeg2_idct_add = mpeg2_idct_add_mlib_non_ieee;
	}
	mpeg2_idct_copy = mpeg2_idct_copy_mlib_non_ieee;
    } else
#endif
    {
	int i;

#ifdef LOG
	fprintf (stderr, "No accelerated IDCT transform found\n");
#endif
	mpeg2_idct_copy = mpeg2_idct_copy_c;
	mpeg2_idct_add  = mpeg2_idct_add_c;
	mpeg2_idct      = mpeg2_idct_c;
	for (i = -384; i < 640; i++)
	    clip_lut[i+384] = (i < 0) ? 0 : ((i > 255) ? 255 : i);
    }
}

--- NEW FILE: vis.h ---
/*
 * vis.h
 * Copyright (C) 2003 David S. Miller <davem@redhat.com>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* You may be asking why I hard-code the instruction opcodes and don't
 * use the normal VIS assembler mnenomics for the VIS instructions.
 *
 * The reason is that Sun, in their infinite wisdom, decided that a binary
 * using a VIS instruction will cause it to be marked (in the ELF headers)
 * as doing so, and this prevents the OS from loading such binaries if the
 * current cpu doesn't have VIS.  There is no way to easily override this
 * behavior of the assembler that I am aware of.
 *
 * This totally defeats what libmpeg2 is trying to do which is allow a
 * single binary to be created, and then detect the availability of VIS
 * at runtime.
 *
 * I'm not saying that tainting the binary by default is bad, rather I'm
 * saying that not providing a way to override this easily unnecessarily
 * ties people's hands.
 *
 * Thus, we do the opcode encoding by hand and output 32-bit words in
 * the assembler to keep the binary from becoming tainted.
 */

#define vis_opc_base	((0x1 << 31) | (0x36 << 19))
#define vis_opf(X)	((X) << 5)
#define vis_sreg(X)	(X)
#define vis_dreg(X)	(((X)&0x1f)|((X)>>5))
#define vis_rs1_s(X)	(vis_sreg(X) << 14)
#define vis_rs1_d(X)	(vis_dreg(X) << 14)
#define vis_rs2_s(X)	(vis_sreg(X) << 0)
#define vis_rs2_d(X)	(vis_dreg(X) << 0)
#define vis_rd_s(X)	(vis_sreg(X) << 25)
#define vis_rd_d(X)	(vis_dreg(X) << 25)

#define vis_ss2s(opf,rs1,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_s(rs1) | \
                                       vis_rs2_s(rs2) | \
                                       vis_rd_s(rd)))

#define vis_dd2d(opf,rs1,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_d(rs1) | \
                                       vis_rs2_d(rs2) | \
                                       vis_rd_d(rd)))

#define vis_ss2d(opf,rs1,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_s(rs1) | \
                                       vis_rs2_s(rs2) | \
                                       vis_rd_d(rd)))

#define vis_sd2d(opf,rs1,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_s(rs1) | \
                                       vis_rs2_d(rs2) | \
                                       vis_rd_d(rd)))

#define vis_d2s(opf,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs2_d(rs2) | \
                                       vis_rd_s(rd)))

#define vis_s2d(opf,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs2_s(rs2) | \
                                       vis_rd_d(rd)))

#define vis_d12d(opf,rs1,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_d(rs1) | \
                                       vis_rd_d(rd)))

#define vis_d22d(opf,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs2_d(rs2) | \
                                       vis_rd_d(rd)))

#define vis_s12s(opf,rs1,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs1_s(rs1) | \
                                       vis_rd_s(rd)))

#define vis_s22s(opf,rs2,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rs2_s(rs2) | \
                                       vis_rd_s(rd)))

#define vis_s(opf,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rd_s(rd)))

#define vis_d(opf,rd) \
	__asm__ __volatile__ (".word %0" \
			      : : "i" (vis_opc_base | vis_opf(opf) | \
                                       vis_rd_d(rd)))

#define vis_r2m(op,rd,mem) \
	__asm__ __volatile__ (#op "\t%%f" #rd ", [%0]" : : "r" (&(mem)) )

#define vis_r2m_2(op,rd,mem1,mem2) \
	__asm__ __volatile__ (#op "\t%%f" #rd ", [%0 + %1]" : : "r" (mem1), "r" (mem2) )

#define vis_m2r(op,mem,rd) \
	__asm__ __volatile__ (#op "\t[%0], %%f" #rd : : "r" (&(mem)) )

#define vis_m2r_2(op,mem1,mem2,rd) \
	__asm__ __volatile__ (#op "\t[%0 + %1], %%f" #rd : : "r" (mem1), "r" (mem2) )

static inline void vis_set_gsr(unsigned int _val)
{
	register unsigned int val asm("g1");

	val = _val;
	__asm__ __volatile__(".word 0xa7804000"
			     : : "r" (val));
}

#define VIS_GSR_ALIGNADDR_MASK	0x0000007
#define VIS_GSR_ALIGNADDR_SHIFT	0
#define VIS_GSR_SCALEFACT_MASK	0x0000078
#define VIS_GSR_SCALEFACT_SHIFT	3

#define vis_ld32(mem,rs1)		vis_m2r(ld, mem, rs1)
#define vis_ld32_2(mem1,mem2,rs1)	vis_m2r_2(ld, mem1, mem2, rs1)
#define vis_st32(rs1,mem)		vis_r2m(st, rs1, mem)
#define vis_st32_2(rs1,mem1,mem2)	vis_r2m_2(st, rs1, mem1, mem2)
#define vis_ld64(mem,rs1)		vis_m2r(ldd, mem, rs1)
#define vis_ld64_2(mem1,mem2,rs1)	vis_m2r_2(ldd, mem1, mem2, rs1)
#define vis_st64(rs1,mem)		vis_r2m(std, rs1, mem)
#define vis_st64_2(rs1,mem1,mem2)	vis_r2m_2(std, rs1, mem1, mem2)

#define vis_ldblk(mem, rd) \
do {	register void *__mem asm("g1"); \
	__mem = &(mem); \
	__asm__ __volatile__(".word 0xc1985e00 | %1" \
			     : \
			     : "r" (__mem), \
			       "i" (vis_rd_d(rd)) \
			     : "memory"); \
} while (0)

#define vis_stblk(rd, mem) \
do {	register void *__mem asm("g1"); \
	__mem = &(mem); \
	__asm__ __volatile__(".word 0xc1b85e00 | %1" \
			     : \
			     : "r" (__mem), \
			       "i" (vis_rd_d(rd)) \
			     : "memory"); \
} while (0)

#define vis_membar_storestore()	\
	__asm__ __volatile__(".word 0x8143e008" : : : "memory")

#define vis_membar_sync()	\
	__asm__ __volatile__(".word 0x8143e040" : : : "memory")

/* 16 and 32 bit partitioned addition and subtraction.  The normal
 * versions perform 4 16-bit or 2 32-bit additions or subtractions.
 * The 's' versions perform 2 16-bit or 2 32-bit additions or
 * subtractions.
 */

#define vis_padd16(rs1,rs2,rd)		vis_dd2d(0x50, rs1, rs2, rd)
#define vis_padd16s(rs1,rs2,rd)		vis_ss2s(0x51, rs1, rs2, rd)
#define vis_padd32(rs1,rs2,rd)		vis_dd2d(0x52, rs1, rs2, rd)
#define vis_padd32s(rs1,rs2,rd)		vis_ss2s(0x53, rs1, rs2, rd)
#define vis_psub16(rs1,rs2,rd)		vis_dd2d(0x54, rs1, rs2, rd)
#define vis_psub16s(rs1,rs2,rd)		vis_ss2s(0x55, rs1, rs2, rd)
#define vis_psub32(rs1,rs2,rd)		vis_dd2d(0x56, rs1, rs2, rd)
#define vis_psub32s(rs1,rs2,rd)		vis_ss2s(0x57, rs1, rs2, rd)

/* Pixel formatting instructions.  */

#define vis_pack16(rs2,rd)		vis_d2s( 0x3b,      rs2, rd)
#define vis_pack32(rs1,rs2,rd)		vis_dd2d(0x3a, rs1, rs2, rd)
#define vis_packfix(rs2,rd)		vis_d2s( 0x3d,      rs2, rd)
#define vis_expand(rs2,rd)		vis_s2d( 0x4d,      rs2, rd)
#define vis_pmerge(rs1,rs2,rd)		vis_ss2d(0x4b, rs1, rs2, rd)

/* Partitioned multiply instructions.  */

#define vis_mul8x16(rs1,rs2,rd)		vis_sd2d(0x31, rs1, rs2, rd)
#define vis_mul8x16au(rs1,rs2,rd)	vis_ss2d(0x33, rs1, rs2, rd)
#define vis_mul8x16al(rs1,rs2,rd)	vis_ss2d(0x35, rs1, rs2, rd)
#define vis_mul8sux16(rs1,rs2,rd)	vis_dd2d(0x36, rs1, rs2, rd)
#define vis_mul8ulx16(rs1,rs2,rd)	vis_dd2d(0x37, rs1, rs2, rd)
#define vis_muld8sux16(rs1,rs2,rd)	vis_ss2d(0x38, rs1, rs2, rd)
#define vis_muld8ulx16(rs1,rs2,rd)	vis_ss2d(0x39, rs1, rs2, rd)

/* Alignment instructions.  */

static inline void *vis_alignaddr(void *_ptr)
{
	register void *ptr asm("g1");

	ptr = _ptr;

	__asm__ __volatile__(".word %2"
			     : "=&r" (ptr)
			     : "0" (ptr),
			       "i" (vis_opc_base | vis_opf(0x18) |
				    vis_rs1_s(1) |
				    vis_rs2_s(0) |
				    vis_rd_s(1)));

	return ptr;
}

static inline void vis_alignaddr_g0(void *_ptr)
{
	register void *ptr asm("g1");

	ptr = _ptr;

	__asm__ __volatile__(".word %2"
			     : "=&r" (ptr)
			     : "0" (ptr),
			       "i" (vis_opc_base | vis_opf(0x18) |
				    vis_rs1_s(1) |
				    vis_rs2_s(0) |
				    vis_rd_s(0)));
}

static inline void *vis_alignaddrl(void *_ptr)
{
	register void *ptr asm("g1");

	ptr = _ptr;

	__asm__ __volatile__(".word %2"
			     : "=&r" (ptr)
			     : "0" (ptr),
			       "i" (vis_opc_base | vis_opf(0x19) |
				    vis_rs1_s(1) |
				    vis_rs2_s(0) |
				    vis_rd_s(1)));

	return ptr;
}

static inline void vis_alignaddrl_g0(void *_ptr)
{
	register void *ptr asm("g1");

	ptr = _ptr;

	__asm__ __volatile__(".word %2"
			     : "=&r" (ptr)
			     : "0" (ptr),
			       "i" (vis_opc_base | vis_opf(0x19) |
				    vis_rs1_s(1) |
				    vis_rs2_s(0) |
				    vis_rd_s(0)));
}

#define vis_faligndata(rs1,rs2,rd)	vis_dd2d(0x48, rs1, rs2, rd)

/* Logical operate instructions.  */

#define vis_fzero(rd)			vis_d(   0x60,           rd)
#define vis_fzeros(rd)			vis_s(   0x61,           rd)
#define vis_fone(rd)			vis_d(   0x7e,           rd)
#define vis_fones(rd)			vis_s(   0x7f,           rd)
#define vis_src1(rs1,rd)		vis_d12d(0x74, rs1,      rd)
#define vis_src1s(rs1,rd)		vis_s12s(0x75, rs1,      rd)
#define vis_src2(rs2,rd)		vis_d22d(0x78,      rs2, rd)
#define vis_src2s(rs2,rd)		vis_s22s(0x79,      rs2, rd)
#define vis_not1(rs1,rd)		vis_d12d(0x6a, rs1,      rd)
#define vis_not1s(rs1,rd)		vis_s12s(0x6b, rs1,      rd)
#define vis_not2(rs2,rd)		vis_d22d(0x66,      rs2, rd)
#define vis_not2s(rs2,rd)		vis_s22s(0x67,      rs2, rd)
#define vis_or(rs1,rs2,rd)		vis_dd2d(0x7c, rs1, rs2, rd)
#define vis_ors(rs1,rs2,rd)		vis_ss2s(0x7d, rs1, rs2, rd)
#define vis_nor(rs1,rs2,rd)		vis_dd2d(0x62, rs1, rs2, rd)
#define vis_nors(rs1,rs2,rd)		vis_ss2s(0x63, rs1, rs2, rd)
#define vis_and(rs1,rs2,rd)		vis_dd2d(0x70, rs1, rs2, rd)
#define vis_ands(rs1,rs2,rd)		vis_ss2s(0x71, rs1, rs2, rd)
#define vis_nand(rs1,rs2,rd)		vis_dd2d(0x6e, rs1, rs2, rd)
#define vis_nands(rs1,rs2,rd)		vis_ss2s(0x6f, rs1, rs2, rd)
#define vis_xor(rs1,rs2,rd)		vis_dd2d(0x6c, rs1, rs2, rd)
#define vis_xors(rs1,rs2,rd)		vis_ss2s(0x6d, rs1, rs2, rd)
#define vis_xnor(rs1,rs2,rd)		vis_dd2d(0x72, rs1, rs2, rd)
#define vis_xnors(rs1,rs2,rd)		vis_ss2s(0x73, rs1, rs2, rd)
#define vis_ornot1(rs1,rs2,rd)		vis_dd2d(0x7a, rs1, rs2, rd)
#define vis_ornot1s(rs1,rs2,rd)		vis_ss2s(0x7b, rs1, rs2, rd)
#define vis_ornot2(rs1,rs2,rd)		vis_dd2d(0x76, rs1, rs2, rd)
#define vis_ornot2s(rs1,rs2,rd)		vis_ss2s(0x77, rs1, rs2, rd)
#define vis_andnot1(rs1,rs2,rd)		vis_dd2d(0x68, rs1, rs2, rd)
#define vis_andnot1s(rs1,rs2,rd)	vis_ss2s(0x69, rs1, rs2, rd)
#define vis_andnot2(rs1,rs2,rd)		vis_dd2d(0x64, rs1, rs2, rd)
#define vis_andnot2s(rs1,rs2,rd)	vis_ss2s(0x65, rs1, rs2, rd)

/* Pixel component distance.  */

#define vis_pdist(rs1,rs2,rd)		vis_dd2d(0x3e, rs1, rs2, rd)

--- NEW FILE: cpu_state.c ---
/*
 * cpu_state.c
 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdlib.h>
#include <inttypes.h>

#include "mpeg2_internal.h"
#include "xineutils.h"

void (* mpeg2_cpu_state_save) (cpu_state_t * state) = NULL;
void (* mpeg2_cpu_state_restore) (cpu_state_t * state) = NULL;

#ifdef ARCH_X86
static void state_restore_mmx (cpu_state_t * state)
{
    emms ();
}
#endif

#if defined (ARCH_PPC) && defined (ENABLE_ALTIVEC)

#ifndef HOST_OS_DARWIN

static void state_save_altivec (cpu_state_t * state)
{
    asm ("						\n"
	"	li		%r9,  16		\n"
	"	stvx		%v20, 0,    %r3		\n"
	"	li		%r11, 32		\n"
	"	stvx		%v21, %r9,  %r3		\n"
	"	li		%r9,  48		\n"
	"	stvx		%v22, %r11, %r3		\n"
	"	li		%r11, 64		\n"
	"	stvx		%v23, %r9,  %r3		\n"
	"	li		%r9,  80		\n"
	"	stvx		%v24, %r11, %r3		\n"
	"	li		%r11, 96		\n"
	"	stvx		%v25, %r9,  %r3		\n"
	"	li		%r9,  112		\n"
	"	stvx		%v26, %r11, %r3		\n"
	"	li		%r11, 128		\n"
	"	stvx		%v27, %r9,  %r3		\n"
	"	li		%r9,  144		\n"
	"	stvx		%v28, %r11, %r3		\n"
	"	li		%r11, 160		\n"
	"	stvx		%v29, %r9,  %r3		\n"
	"	li		%r9,  176		\n"
	"	stvx		%v30, %r11, %r3		\n"
	"	stvx		%v31, %r9,  %r3		\n"
	 );
}

static void state_restore_altivec (cpu_state_t * state)
{
    asm ("						\n"
	"	li		%r9,  16		\n"
	"	lvx		%v20, 0,    %r3		\n"
	"	li		%r11, 32		\n"
	"	lvx		%v21, %r9,  %r3		\n"
	"	li		%r9,  48		\n"
	"	lvx		%v22, %r11, %r3		\n"
	"	li		%r11, 64		\n"
	"	lvx		%v23, %r9,  %r3		\n"
	"	li		%r9,  80		\n"
	"	lvx		%v24, %r11, %r3		\n"
	"	li		%r11, 96		\n"
	"	lvx		%v25, %r9,  %r3		\n"
	"	li		%r9,  112		\n"
	"	lvx		%v26, %r11, %r3		\n"
	"	li		%r11, 128		\n"
	"	lvx		%v27, %r9,  %r3		\n"
	"	li		%r9,  144		\n"
	"	lvx		%v28, %r11, %r3		\n"
	"	li		%r11, 160		\n"
	"	lvx		%v29, %r9,  %r3		\n"
	"	li		%r9,  176		\n"
	"	lvx		%v30, %r11, %r3		\n"
	"	lvx		%v31, %r9,  %r3		\n"
	 );
}

#else /* HOST_OS_DARWIN */

#define LI(a,b) "li r" #a "," #b "\n\t"
#define STVX0(a,b,c) "stvx v" #a ",0,r" #c "\n\t"
#define STVX(a,b,c) "stvx v" #a ",r" #b ",r" #c "\n\t"
#define LVX0(a,b,c) "lvx v" #a ",0,r" #c "\n\t"
#define LVX(a,b,c) "lvx v" #a ",r" #b ",r" #c "\n\t"

static void state_save_altivec (cpu_state_t * state)
{
    asm (LI (9, 16)
	 STVX0 (20, 0, 3)
	 LI (11, 32)
	 STVX (21, 9, 3)
	 LI (9, 48)
	 STVX (22, 11, 3)
	 LI (11, 64)
	 STVX (23, 9, 3)
	 LI (9, 80)
	 STVX (24, 11, 3)
	 LI (11, 96)
	 STVX (25, 9, 3)
	 LI (9, 112)
	 STVX (26, 11, 3)
	 LI (11, 128)
	 STVX (27, 9, 3)
	 LI (9, 144)
	 STVX (28, 11, 3)
	 LI (11, 160)
	 STVX (29, 9, 3)
	 LI (9, 176)
	 STVX (30, 11, 3)
	 STVX (31, 9, 3));
}

static void state_restore_altivec (cpu_state_t * state)
{
    asm (LI (9, 16)
	 LVX0 (20, 0, 3)
	 LI (11, 32)
	 LVX (21, 9, 3)
	 LI (9, 48)
	 LVX (22, 11, 3)
	 LI (11, 64)
	 LVX (23, 9, 3)
	 LI (9, 80)
	 LVX (24, 11, 3)
	 LI (11, 96)
	 LVX (25, 9, 3)
	 LI (9, 112)
	 LVX (26, 11, 3)
	 LI (11, 128)
	 LVX (27, 9, 3)
	 LI (9, 144)
	 LVX (28, 11, 3)
	 LI (11, 160)
	 LVX (29, 9, 3)
	 LI (9, 176)
	 LVX (30, 11, 3)
	 LVX (31, 9, 3));
}
#endif /* HOST_OS_DARWIN */

#endif /* defined (ARCH_PPC) && defined (ENABLE_ALTIVEC) */

void mpeg2_cpu_state_init (uint32_t mm_accel)
{
#ifdef ARCH_X86
    if (mm_accel & MM_ACCEL_X86_MMX) {
	mpeg2_cpu_state_restore = state_restore_mmx;
    }
#endif
#if defined (ARCH_PPC) && defined (ENABLE_ALTIVEC)
    if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
	mpeg2_cpu_state_save = state_save_altivec;
	mpeg2_cpu_state_restore = state_restore_altivec;
    }
#endif
}


--- NEW FILE: stats.c ---
/*
 * stats.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "mpeg2_internal.h"

static int debug_level = -1;

/* Determine is debug output is required. */
/* We could potentially have multiple levels of debug info */
static int debug_is_on (void)
{
    char * env_var;
	
    if (debug_level < 0) {
	env_var = getenv ("MPEG2_DEBUG");

	if (env_var)
	    debug_level = 1;
	else
	    debug_level = 0;
    }
	
    return debug_level;
}

static void stats_picture (uint8_t * buffer)
{
    static char * picture_coding_type_str [8] = {
	"Invalid picture type",
	"I-type",
	"P-type",
	"B-type",
	"D (very bad)",
	"Invalid","Invalid","Invalid"
    };

    int picture_coding_type;
    int temporal_reference;
    int vbv_delay;

    temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
    picture_coding_type = (buffer [1] >> 3) & 7;
    vbv_delay = ((buffer[1] << 13) | (buffer[2] << 5) |
		 (buffer[3] >> 3)) & 0xffff;

    fprintf (stderr, " (picture) %s temporal_reference %d, vbv_delay %d\n",
	     picture_coding_type_str [picture_coding_type],
	     temporal_reference, vbv_delay);
}

static void stats_user_data (uint8_t * buffer)
{
    fprintf (stderr, " (user_data)\n");
}

static void stats_sequence (uint8_t * buffer)
{
    static char * aspect_ratio_information_str[8] = {
	"Invalid Aspect Ratio",
	"1:1",
	"4:3",
	"16:9",
	"2.21:1",
	"Invalid Aspect Ratio",
	"Invalid Aspect Ratio",
	"Invalid Aspect Ratio"
    };
    static char * frame_rate_str[16] = {
	"Invalid frame_rate_code",
	"23.976", "24", "25" , "29.97",
	"30" , "50", "59.94", "60" ,
	"Invalid frame_rate_code", "Invalid frame_rate_code",
	"Invalid frame_rate_code", "Invalid frame_rate_code",
	"Invalid frame_rate_code", "Invalid frame_rate_code",
	"Invalid frame_rate_code"
    };

    int horizontal_size;
    int vertical_size;
    int aspect_ratio_information;
    int frame_rate_code;
    int bit_rate_value;
    int vbv_buffer_size_value;
    int constrained_parameters_flag;
    int load_intra_quantizer_matrix;
    int load_non_intra_quantizer_matrix;

    vertical_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
    horizontal_size = vertical_size >> 12;
    vertical_size &= 0xfff;
    aspect_ratio_information = buffer[3] >> 4;
    frame_rate_code = buffer[3] & 15;
    bit_rate_value = (buffer[4] << 10) | (buffer[5] << 2) | (buffer[6] >> 6);
    vbv_buffer_size_value = ((buffer[6] << 5) | (buffer[7] >> 3)) & 0x3ff;
    constrained_parameters_flag = buffer[7] & 4;
    load_intra_quantizer_matrix = buffer[7] & 2;
    if (load_intra_quantizer_matrix)
	buffer += 64;
    load_non_intra_quantizer_matrix = buffer[7] & 1;

    fprintf (stderr, " (seq) %dx%d %s, %s fps, %5.0f kbps, VBV %d kB%s%s%s\n",
	     horizontal_size, vertical_size,
	     aspect_ratio_information_str [aspect_ratio_information],
	     frame_rate_str [frame_rate_code],
	     bit_rate_value * 400.0 / 1000.0,
	     2 * vbv_buffer_size_value,
	     constrained_parameters_flag ? " , CP":"",
	     load_intra_quantizer_matrix ? " , Custom Intra Matrix":"",
	     load_non_intra_quantizer_matrix ? " , Custom Non-Intra Matrix":"");
}

static void stats_sequence_error (uint8_t * buffer)
{
    fprintf (stderr, " (sequence_error)\n");
}

static void stats_sequence_end (uint8_t * buffer)
{
    fprintf (stderr, " (sequence_end)\n");
}

static void stats_group (uint8_t * buffer)
{
    fprintf (stderr, " (group)%s%s\n",
	     (buffer[4] & 0x40) ? " closed_gop" : "",
	     (buffer[4] & 0x20) ? " broken_link" : "");
}

static void stats_slice (int code, uint8_t * buffer)
{
    /* fprintf (stderr, " (slice %d)\n", code); */
}

static void stats_sequence_extension (uint8_t * buffer)
{
    static char * chroma_format_str[4] = {
	"Invalid Chroma Format",
	"4:2:0 Chroma",
	"4:2:2 Chroma",
	"4:4:4 Chroma"
    };

    int progressive_sequence;
    int chroma_format;

    progressive_sequence = (buffer[1] >> 3) & 1;
    chroma_format = (buffer[1] >> 1) & 3;

    fprintf (stderr, " (seq_ext) progressive_sequence %d, %s\n",
	     progressive_sequence, chroma_format_str [chroma_format]);
}

static void stats_sequence_display_extension (uint8_t * buffer)
{
    fprintf (stderr, " (sequence_display_extension)\n");
}

static void stats_quant_matrix_extension (uint8_t * buffer)
{
    fprintf (stderr, " (quant_matrix_extension)\n");
}

static void stats_copyright_extension (uint8_t * buffer)
{
    fprintf (stderr, " (copyright_extension)\n");
}


static void stats_sequence_scalable_extension (uint8_t * buffer)
{
    fprintf (stderr, " (sequence_scalable_extension)\n");
}

static void stats_picture_display_extension (uint8_t * buffer)
{
    fprintf (stderr, " (picture_display_extension)\n");
}

static void stats_picture_coding_extension (uint8_t * buffer)
{
    static char * picture_structure_str[4] = {
	"Invalid Picture Structure",
	"Top field",
	"Bottom field",
	"Frame Picture"
    };

    int f_code[2][2];
    int intra_dc_precision;
    int picture_structure;
    int top_field_first;
    int frame_pred_frame_dct;
    int concealment_motion_vectors;
    int q_scale_type;
    int intra_vlc_format;
    int alternate_scan;
    int repeat_first_field;
    int progressive_frame;

    f_code[0][0] = buffer[0] & 15;
    f_code[0][1] = buffer[1] >> 4;
    f_code[1][0] = buffer[1] & 15;
    f_code[1][1] = buffer[2] >> 4;
    intra_dc_precision = (buffer[2] >> 2) & 3;
    picture_structure = buffer[2] & 3;
    top_field_first = buffer[3] >> 7;
    frame_pred_frame_dct = (buffer[3] >> 6) & 1;
    concealment_motion_vectors = (buffer[3] >> 5) & 1;
    q_scale_type = (buffer[3] >> 4) & 1;
    intra_vlc_format = (buffer[3] >> 3) & 1;
    alternate_scan = (buffer[3] >> 2) & 1;
    repeat_first_field = (buffer[3] >> 1) & 1;
    progressive_frame = buffer[4] >> 7;

    fprintf (stderr,
	     " (pic_ext) %s\n", picture_structure_str [picture_structure]);
    fprintf (stderr,
	     " (pic_ext) forward horizontal f_code % d, forward vertical f_code % d\n",
	     f_code[0][0], f_code[0][1]);
    fprintf (stderr,
	     " (pic_ext) backward horizontal f_code % d, backward vertical f_code % d\n", 
	     f_code[1][0], f_code[1][1]);
    fprintf (stderr,
	     " (pic_ext) intra_dc_precision %d, top_field_first %d, frame_pred_frame_dct %d\n",
	     intra_dc_precision, top_field_first, frame_pred_frame_dct);
    fprintf (stderr,
	     " (pic_ext) concealment_motion_vectors %d, q_scale_type %d, intra_vlc_format %d\n",
	     concealment_motion_vectors, q_scale_type, intra_vlc_format);
    fprintf (stderr,
	     " (pic_ext) alternate_scan %d, repeat_first_field %d, progressive_frame %d\n",
	     alternate_scan, repeat_first_field, progressive_frame);
}

void mpeg2_stats (int code, uint8_t * buffer)
{
    if (! (debug_is_on ()))
	return;

    switch (code) {
    case 0x00:
	stats_picture (buffer);
	break;
    case 0xb2:
	stats_user_data (buffer);
	break;
    case 0xb3:
	stats_sequence (buffer);
	break;
    case 0xb4:
	stats_sequence_error (buffer);
	break;
    case 0xb5:
	switch (buffer[0] >> 4) {
	case 1:
	    stats_sequence_extension (buffer);
	    break;
	case 2:
	    stats_sequence_display_extension (buffer);
	    break;
	case 3:
	    stats_quant_matrix_extension (buffer);
	    break;
	case 4:
	    stats_copyright_extension (buffer);
	    break;
	case 5:
	    stats_sequence_scalable_extension (buffer);
	    break;
	case 7:
	    stats_picture_display_extension (buffer);
	    break;
	case 8:
	    stats_picture_coding_extension (buffer);
	    break;
	default:
	    fprintf (stderr, " (unknown extension %#x)\n", buffer[0] >> 4);
	}
	break;
    case 0xb7:
	stats_sequence_end (buffer);
	break;
    case 0xb8:
	stats_group (buffer);
	break;
    default:
	if (code < 0xb0)
	    stats_slice (code, buffer);
	else
	    fprintf (stderr, " (unknown start code %#02x)\n", code);
    }
}

--- NEW FILE: mpeg2_internal.h ---
/*
 * mpeg2_internal.h
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "video_out.h"
#include "accel_xvmc.h"

/* macroblock modes */
#define MACROBLOCK_INTRA            XINE_MACROBLOCK_INTRA
#define MACROBLOCK_PATTERN          XINE_MACROBLOCK_PATTERN
#define MACROBLOCK_MOTION_BACKWARD  XINE_MACROBLOCK_MOTION_BACKWARD
#define MACROBLOCK_MOTION_FORWARD   XINE_MACROBLOCK_MOTION_FORWARD
#define MACROBLOCK_QUANT            XINE_MACROBLOCK_QUANT
#define DCT_TYPE_INTERLACED         XINE_MACROBLOCK_DCT_TYPE_INTERLACED

/* motion_type */
#define MOTION_TYPE_MASK (3*64)
#define MOTION_TYPE_BASE 64
#define MC_FIELD (1*64)
#define MC_FRAME (2*64)
#define MC_16X8 (2*64)
#define MC_DMV (3*64)

/* picture structure */
#define TOP_FIELD     VO_TOP_FIELD
#define BOTTOM_FIELD  VO_BOTTOM_FIELD
#define FRAME_PICTURE VO_BOTH_FIELDS

/* picture coding type (mpeg2 header) */
#define I_TYPE 1
#define P_TYPE 2
#define B_TYPE 3
#define D_TYPE 4
               
typedef struct motion_s {
    uint8_t * ref[2][3];
    uint8_t ** ref2[2];
    int pmv[2][2];
    int f_code[2];
} motion_t;

typedef struct picture_s {
    /* first, state that carries information from one macroblock to the */
    /* next inside a slice, and is never used outside of mpeg2_slice() */

    /* DCT coefficients - should be kept aligned ! */
    int16_t DCTblock[64];

    /* XvMC DCT block and macroblock data for XvMC acceleration */
    xine_macroblocks_t *mc;
    int XvMC_mb_type;
    int XvMC_mv_field_sel[2][2];
    int XvMC_x;
    int XvMC_y;
    int XvMC_motion_type;
    int XvMC_dmvector[2];
    int XvMC_cbp;
    int XvMC_dct_type;

    /* bit parsing stuff */
    uint32_t bitstream_buf;	/* current 32 bit working set of buffer */
    int bitstream_bits;		/* used bits in working set */
    uint8_t * bitstream_ptr;	/* buffer with stream data */

    uint8_t * dest[3];
    int pitches[3];
    int offset;
    unsigned int limit_x;
    unsigned int limit_y_16;
    unsigned int limit_y_8;
    unsigned int limit_y;

    /* Motion vectors */
    /* The f_ and b_ correspond to the forward and backward motion */
    /* predictors */
    motion_t b_motion;
    motion_t f_motion;

    /* predictor for DC coefficients in intra blocks */
    int16_t dc_dct_pred[3];

    int quantizer_scale;	/* remove */
    int current_field;		/* remove */
    int dmv_offset;		/* remove */
    unsigned int v_offset;		/* remove */


    /* now non-slice-specific information */

    /* sequence header stuff */
    uint8_t intra_quantizer_matrix [64];
    uint8_t non_intra_quantizer_matrix [64];
    int load_intra_quantizer_matrix;
    int load_non_intra_quantizer_matrix;

    /* The width and height of the picture snapped to macroblock units */
    int coded_picture_width;
    int coded_picture_height;
    
    /* The width and height as it appears on header sequence */
    unsigned int display_width, display_height;

    /* picture header stuff */

    /* what type of picture this is (I, P, B, D) */
    int picture_coding_type;

    int vbv_delay;
    int low_delay;
	
    /* picture coding extension stuff */
	
    /* quantization factor for intra dc coefficients */
    int intra_dc_precision;
    /* top/bottom/both fields */
    int picture_structure;
    /* bool to indicate all predictions are frame based */
    int frame_pred_frame_dct;
    /* bool to indicate whether intra blocks have motion vectors */
    /* (for concealment) */
    int concealment_motion_vectors;
    /* bit to indicate which quantization table to use */
    int q_scale_type;
    /* bool to use different vlc tables */
    int intra_vlc_format;
    /* used for DMV MC */
    int top_field_first;

    /* stuff derived from bitstream */

    /* pointer to the zigzag scan we're supposed to be using */
    uint8_t * scan;

    struct vo_frame_s * current_frame;
    struct vo_frame_s * forward_reference_frame;
    struct vo_frame_s * backward_reference_frame;

    int frame_width, frame_height;

    int second_field;

    int mpeg1;

    int skip_non_intra_dct;

    /* these things are not needed by the decoder */
    /* this is a temporary interface, we will build a better one later. */
    int aspect_ratio_information;
    int frame_rate_code;
    int progressive_sequence;
    int repeat_first_field;
    int progressive_frame;
    uint32_t frame_centre_horizontal_offset;
    uint32_t frame_centre_vertical_offset;
    uint32_t video_format;
    uint32_t colour_description;
    uint32_t colour_primatives;
    uint32_t transfer_characteristics;
    uint32_t matrix_coefficients;
    uint32_t display_horizontal_size;
    uint32_t display_vertical_size;
    uint32_t drop_frame_flag;
    uint32_t time_code_hours;
    uint32_t time_code_minutes;
    uint32_t time_code_seconds;
    uint32_t time_code_pictures;
    uint32_t closed_gop;
    uint32_t broken_link;

    int bitrate;
    int frame_rate_ext_n;
    int frame_rate_ext_d;

} picture_t;

typedef struct cpu_state_s {
#ifdef ARCH_PPC
    uint8_t regv[12*16];
#endif
    int dummy;
} cpu_state_t;

/* cpu_state.c */
extern void (* mpeg2_cpu_state_save) (cpu_state_t * state);
extern void (* mpeg2_cpu_state_restore) (cpu_state_t * state);
void mpeg2_cpu_state_init (uint32_t mm_accel);

/* header.c */
extern uint8_t mpeg2_scan_norm[64];
extern uint8_t mpeg2_scan_alt[64];
void mpeg2_header_state_init (picture_t * picture);
int mpeg2_header_picture (picture_t * picture, uint8_t * buffer);
int mpeg2_header_sequence (picture_t * picture, uint8_t * buffer);
int mpeg2_header_extension (picture_t * picture, uint8_t * buffer);
int mpeg2_header_group_of_pictures (picture_t * picture, uint8_t * buffer);

/* idct.c */
extern void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
extern void (* mpeg2_idct_add) (int16_t * block, uint8_t * dest, int stride);
extern void (* mpeg2_idct) (int16_t * block);
extern void (* mpeg2_zero_block) (int16_t * block);
void mpeg2_idct_init (uint32_t mm_accel);

/* idct_mlib.c */
void mpeg2_idct_add_mlib (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_copy_mlib_non_ieee (int16_t * block, uint8_t * dest,
				    int stride);
void mpeg2_idct_add_mlib_non_ieee (int16_t * block, uint8_t * dest,
				   int stride);
void mpeg2_idct_mlib (int16_t * block);

/* idct_mmx.c */
void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_add_mmxext (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_mmxext (int16_t * block);
void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_add_mmx (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_mmx (int16_t * block);
void mpeg2_zero_block_mmx (int16_t * block);
void mpeg2_idct_mmx_init (void);

/* idct_altivec.c */
#ifndef HOST_OS_DARWIN
void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride);
void mpeg2_idct_add_altivec (int16_t * block, uint8_t * dest, int stride);
#else /* HOST_OS_DARWIN */
# ifdef ENABLE_ALTIVEC
void mpeg2_idct_copy_altivec (vector signed short * block, unsigned char * dest,
			      int stride);
void mpeg2_idct_add_altivec (vector signed short * block, unsigned char * dest,
			     int stride);
# else /* ! ENABLE_ALTIVEC */
void mpeg2_idct_copy_altivec (signed short * block, unsigned char * dest,
			      int stride);
void mpeg2_idct_add_altivec (signed short * block, unsigned char * dest,
			     int stride);
# endif /* ENABLE_ALTIVEC */
#endif /* HOST_OS_DARWIN */
void mpeg2_idct_altivec_init (void);

/* motion_comp.c */
void mpeg2_mc_init (uint32_t mm_accel);

typedef struct mpeg2_mc_s {
    void (* put [8]) (uint8_t * dst, uint8_t *, int32_t, int32_t);
    void (* avg [8]) (uint8_t * dst, uint8_t *, int32_t, int32_t);
} mpeg2_mc_t;

#define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = {			  \
    {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
     MC_put_o_8_##x,  MC_put_x_8_##x,  MC_put_y_8_##x,  MC_put_xy_8_##x}, \
    {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
     MC_avg_o_8_##x,  MC_avg_x_8_##x,  MC_avg_y_8_##x,  MC_avg_xy_8_##x}  \
};

extern mpeg2_mc_t mpeg2_mc;
extern mpeg2_mc_t mpeg2_mc_c;
extern mpeg2_mc_t mpeg2_mc_mmx;
extern mpeg2_mc_t mpeg2_mc_mmxext;
extern mpeg2_mc_t mpeg2_mc_3dnow;
extern mpeg2_mc_t mpeg2_mc_altivec;
extern mpeg2_mc_t mpeg2_mc_mlib;
extern mpeg2_mc_t mpeg2_mc_vis;

/* slice.c */
void mpeg2_slice (picture_t * picture, int code, uint8_t * buffer);

/* stats.c */
void mpeg2_stats (int code, uint8_t * buffer);



--- NEW FILE: slice_xvmc.c ---
/*
 * slice_xvmc.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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
[...2005 lines suppressed...]
					 picture->forward_reference_frame,
					 picture->backward_reference_frame,
					 picture->picture_structure,
					 picture->second_field,
				         picture->f_motion.pmv,
				         picture->b_motion.pmv);
		    } else {
		        MOTION_CALL (motion_reuse, macroblock_modes);
		    }
		    NEXT_MACROBLOCK;
		} while (--mba_inc);
	    }
	}
    }
    mpeg2dec->xvmc_last_slice_code++;
#undef bit_buf
#undef bits
#undef bit_ptr
}


--- NEW FILE: xvmc.h ---
/*
 * mpeg2_internal.h
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _XVMC_H
#include "mpeg2.h"

/* slice_xvmc.c */
void mpeg2_xvmc_slice (mpeg2dec_t *mpeg2dec, picture_t * picture, int code, uint8_t * buffer);

#endif

--- NEW FILE: idct_altivec.c ---
/*
 * idct_altivec.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#if defined (ARCH_PPC) && defined (ENABLE_ALTIVEC)

#include <inttypes.h>

#include "mpeg2_internal.h"
#include "xineutils.h"

#ifndef HOST_OS_DARWIN

/*
 * The asm code is generated with:
 *
 * gcc-2.95 -fvec -D__ALTIVEC__	-O9 -fomit-frame-pointer -mregnames -S
 *	idct_altivec.c
 *
 * awk '{args=""; len=split ($2, arg, ",");
 *	for (i=1; i<=len; i++) { a=arg[i]; if (i<len) a=a",";
 *				 args = args sprintf ("%-6s", a) }
 *	printf ("\t\"\t%-16s%-24s\\n\"\n", $1, args) }' idct_altivec.s |
 * unexpand -a
 *
 * I then do some simple trimming on the function prolog/trailers
 */

void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride)
{
    asm ("						\n"
	"#	stwu		%r1,  -128(%r1)		\n"
	"#	mflr		%r0			\n"
	"#	stw		%r0,  132(%r1)		\n"
	"#	addi		%r0,  %r1,  128		\n"
	"#	bl		_savev25		\n"

	"	addi		%r9,  %r3,  112		\n"
	"	vspltish	%v25, 4			\n"
	"	vxor		%v13, %v13, %v13	\n"
	"	lis		%r10, constants@ha	\n"
	"	lvx		%v1,  0,    %r9		\n"
	"	la		%r10, constants@l(%r10) \n"
	"	lvx		%v5,  0,    %r3		\n"
	"	addi		%r9,  %r3,  16		\n"
	"	lvx		%v8,  0,    %r10	\n"
	"	addi		%r11, %r10, 32		\n"
	"	lvx		%v12, 0,    %r9		\n"
	"	lvx		%v6,  0,    %r11	\n"
	"	addi		%r8,  %r3,  48		\n"
	"	vslh		%v1,  %v1,  %v25	\n"
	"	addi		%r9,  %r3,  80		\n"
	"	lvx		%v11, 0,    %r8		\n"
	"	vslh		%v5,  %v5,  %v25	\n"
	"	lvx		%v0,  0,    %r9		\n"
	"	addi		%r11, %r10, 64		\n"
	"	vsplth		%v3,  %v8,  2		\n"
	"	lvx		%v7,  0,    %r11	\n"
	"	addi		%r9,  %r3,  96		\n"
	"	vslh		%v12, %v12, %v25	\n"
	"	vmhraddshs	%v27, %v1,  %v6,  %v13	\n"
	"	addi		%r8,  %r3,  32		\n"
	"	vsplth		%v2,  %v8,  5		\n"
	"	lvx		%v1,  0,    %r9		\n"
	"	vslh		%v11, %v11, %v25	\n"
	"	addi		%r3,  %r3,  64		\n"
	"	lvx		%v9,  0,    %r8		\n"
	"	addi		%r9,  %r10, 48		\n"
	"	vslh		%v0,  %v0,  %v25	\n"
	"	lvx		%v4,  0,    %r9		\n"
	"	vmhraddshs	%v31, %v12, %v6,  %v13	\n"
	"	addi		%r10, %r10, 16		\n"
	"	vmhraddshs	%v30, %v0,  %v7,  %v13	\n"
	"	lvx		%v10, 0,    %r3		\n"
	"	vsplth		%v19, %v8,  3		\n"
	"	vmhraddshs	%v15, %v11, %v7,  %v13	\n"
	"	lvx		%v12, 0,    %r10	\n"
	"	vsplth		%v6,  %v8,  4		\n"
	"	vslh		%v1,  %v1,  %v25	\n"
	"	vsplth		%v11, %v8,  1		\n"
	"	li		%r9,  4			\n"
	"	vslh		%v9,  %v9,  %v25	\n"
	"	vsplth		%v7,  %v8,  0		\n"
	"	vmhraddshs	%v18, %v1,  %v4,  %v13	\n"
	"	vspltw		%v8,  %v8,  3		\n"
	"	vsubshs		%v0,  %v13, %v27	\n"
	"	vmhraddshs	%v1,  %v9,  %v4,  %v13	\n"
	"	vmhraddshs	%v17, %v3,  %v31, %v0	\n"
	"	vmhraddshs	%v4,  %v2,  %v15, %v30	\n"
	"	vslh		%v10, %v10, %v25	\n"
	"	vmhraddshs	%v9,  %v5,  %v12, %v13	\n"
	"	vspltish	%v25, 6			\n"
	"	vmhraddshs	%v5,  %v10, %v12, %v13	\n"
	"	vmhraddshs	%v28, %v19, %v30, %v15	\n"
	"	vmhraddshs	%v27, %v3,  %v27, %v31	\n"
	"	vsubshs		%v0,  %v13, %v18	\n"
	"	vmhraddshs	%v18, %v11, %v18, %v1	\n"
	"	vaddshs		%v30, %v17, %v4		\n"
	"	vmhraddshs	%v12, %v11, %v1,  %v0	\n"
	"	vsubshs		%v4,  %v17, %v4		\n"
	"	vaddshs		%v10, %v9,  %v5		\n"
	"	vsubshs		%v17, %v27, %v28	\n"
	"	vaddshs		%v27, %v27, %v28	\n"
	"	vsubshs		%v1,  %v9,  %v5		\n"
	"	vaddshs		%v28, %v10, %v18	\n"
	"	vsubshs		%v18, %v10, %v18	\n"
	"	vaddshs		%v10, %v1,  %v12	\n"
	"	vsubshs		%v1,  %v1,  %v12	\n"
	"	vsubshs		%v12, %v17, %v4		\n"
	"	vaddshs		%v4,  %v17, %v4		\n"
	"	vmhraddshs	%v5,  %v7,  %v12, %v1	\n"
	"	vmhraddshs	%v26, %v6,  %v4,  %v10	\n"
	"	vmhraddshs	%v29, %v6,  %v12, %v1	\n"
	"	vmhraddshs	%v14, %v7,  %v4,  %v10	\n"
	"	vsubshs		%v12, %v18, %v30	\n"
	"	vaddshs		%v9,  %v28, %v27	\n"
	"	vaddshs		%v16, %v18, %v30	\n"
	"	vsubshs		%v10, %v28, %v27	\n"
	"	vmrglh		%v31, %v9,  %v12	\n"
	"	vmrglh		%v30, %v5,  %v26	\n"
	"	vmrglh		%v15, %v14, %v29	\n"
	"	vmrghh		%v5,  %v5,  %v26	\n"
	"	vmrglh		%v27, %v16, %v10	\n"
	"	vmrghh		%v9,  %v9,  %v12	\n"
	"	vmrghh		%v18, %v16, %v10	\n"
	"	vmrghh		%v1,  %v14, %v29	\n"
	"	vmrglh		%v14, %v9,  %v5		\n"
	"	vmrglh		%v16, %v31, %v30	\n"
	"	vmrglh		%v10, %v15, %v27	\n"
	"	vmrghh		%v9,  %v9,  %v5		\n"
	"	vmrghh		%v26, %v15, %v27	\n"
	"	vmrglh		%v27, %v16, %v10	\n"
	"	vmrghh		%v12, %v1,  %v18	\n"
	"	vmrglh		%v29, %v1,  %v18	\n"
	"	vsubshs		%v0,  %v13, %v27	\n"
	"	vmrghh		%v5,  %v31, %v30	\n"
	"	vmrglh		%v31, %v9,  %v12	\n"
	"	vmrglh		%v30, %v5,  %v26	\n"
	"	vmrglh		%v15, %v14, %v29	\n"
	"	vmhraddshs	%v17, %v3,  %v31, %v0	\n"
	"	vmrghh		%v18, %v16, %v10	\n"
	"	vmhraddshs	%v27, %v3,  %v27, %v31	\n"
	"	vmhraddshs	%v4,  %v2,  %v15, %v30	\n"
	"	vmrghh		%v1,  %v14, %v29	\n"
	"	vmhraddshs	%v28, %v19, %v30, %v15	\n"
	"	vmrghh		%v0,  %v9,  %v12	\n"
	"	vsubshs		%v13, %v13, %v18	\n"
	"	vmrghh		%v5,  %v5,  %v26	\n"
	"	vmhraddshs	%v18, %v11, %v18, %v1	\n"
	"	vaddshs		%v9,  %v0,  %v8		\n"
	"	vaddshs		%v30, %v17, %v4		\n"
	"	vmhraddshs	%v12, %v11, %v1,  %v13	\n"
	"	vsubshs		%v4,  %v17, %v4		\n"
	"	vaddshs		%v10, %v9,  %v5		\n"
	"	vsubshs		%v17, %v27, %v28	\n"
	"	vaddshs		%v27, %v27, %v28	\n"
	"	vsubshs		%v1,  %v9,  %v5		\n"
	"	vaddshs		%v28, %v10, %v18	\n"
	"	vsubshs		%v18, %v10, %v18	\n"
	"	vaddshs		%v10, %v1,  %v12	\n"
	"	vsubshs		%v1,  %v1,  %v12	\n"
	"	vsubshs		%v12, %v17, %v4		\n"
	"	vaddshs		%v4,  %v17, %v4		\n"
	"	vaddshs		%v9,  %v28, %v27	\n"
	"	vmhraddshs	%v14, %v7,  %v4,  %v10	\n"
	"	vsrah		%v9,  %v9,  %v25	\n"
	"	vmhraddshs	%v5,  %v7,  %v12, %v1	\n"
	"	vpkshus		%v0,  %v9,  %v9		\n"
	"	vmhraddshs	%v29, %v6,  %v12, %v1	\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	vaddshs		%v16, %v18, %v30	\n"
	"	vsrah		%v31, %v14, %v25	\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	vsrah		%v15, %v16, %v25	\n"
	"	vpkshus		%v0,  %v31, %v31	\n"
	"	vsrah		%v1,  %v5,  %v25	\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	vsubshs		%v12, %v18, %v30	\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	vmhraddshs	%v26, %v6,  %v4,  %v10	\n"
	"	vpkshus		%v0,  %v1,  %v1		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	vsrah		%v5,  %v12, %v25	\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	vsrah		%v30, %v29, %v25	\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	vsubshs		%v10, %v28, %v27	\n"
	"	vpkshus		%v0,  %v15, %v15	\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	vsrah		%v18, %v26, %v25	\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	vsrah		%v27, %v10, %v25	\n"
	"	vpkshus		%v0,  %v5,  %v5		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	vpkshus		%v0,  %v30, %v30	\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	vpkshus		%v0,  %v18, %v18	\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	stvewx		%v0,  %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	vpkshus		%v0,  %v27, %v27	\n"
	"	stvewx		%v0,  0,    %r4		\n"
	"	stvewx		%v0,  %r9,  %r4		\n"

	"#	addi		%r0,  %r1,  128		\n"
	"#	bl		_restv25		\n"
	"#	lwz		%r0,  132(%r1)		\n"
	"#	mtlr		%r0			\n"
	"#	la		%r1,  128(%r1)		\n"
        "       vxor            %v1,  %v1,  %v1         \n"
        "       addi            %r9,  %r3,  16          \n"
        "       stvx            %v1,  0,    %r3         \n"
        "       stvx            %v1,  0,    %r9         \n"
        "       addi            %r11, %r3,  32          \n"
        "       stvx            %v1,  0,    %r11        \n" 
        "       addi            %r9,  %r3,  48          \n" 
        "       stvx            %v1,  0,    %r9         \n" 
        "       addi            %r11, %r3,  -64         \n" 
        "       stvx            %v1,  0,    %r11        \n" 
        "       addi            %r9,  %r3,  -48         \n" 
        "       stvx            %v1,  0,    %r9         \n" 
        "       addi            %r11, %r3,  -32         \n" 
        "       stvx            %v1,  0,    %r11        \n" 
        "       addi            %r3,  %r3,  -16         \n" 
        "       stvx            %v1,  0,    %r3         \n"
	 );
}

void mpeg2_idct_add_altivec (int16_t * block, uint8_t * dest, int stride)
{
    asm ("						\n"
	"#	stwu		%r1,  -192(%r1)		\n"
	"#	mflr		%r0			\n"
	"#	stw		%r0,  196(%r1)		\n"
	"#	addi		%r0,  %r1,  192		\n"
	"#	bl		_savev21		\n"

	"	addi		%r9,  %r3,  112		\n"
	"	vspltish	%v21, 4			\n"
	"	vxor		%v1,  %v1,  %v1		\n"
	"	lvx		%v13, 0,    %r9		\n"
	"	lis		%r10, constants@ha	\n"
	"	vspltisw	%v3,  -1		\n"
	"	la		%r10, constants@l(%r10) \n"
	"	lvx		%v5,  0,    %r3		\n"
	"	addi		%r9,  %r3,  16		\n"
	"	lvx		%v8,  0,    %r10	\n"
	"	lvx		%v12, 0,    %r9		\n"
	"	addi		%r11, %r10, 32		\n"
	"	lvx		%v6,  0,    %r11	\n"
	"	addi		%r8,  %r3,  48		\n"
	"	vslh		%v13, %v13, %v21	\n"
	"	addi		%r9,  %r3,  80		\n"
	"	lvx		%v11, 0,    %r8		\n"
	"	vslh		%v5,  %v5,  %v21	\n"
	"	lvx		%v0,  0,    %r9		\n"
	"	addi		%r11, %r10, 64		\n"
	"	vsplth		%v2,  %v8,  2		\n"
	"	lvx		%v7,  0,    %r11	\n"
	"	vslh		%v12, %v12, %v21	\n"
	"	addi		%r9,  %r3,  96		\n"
	"	vmhraddshs	%v24, %v13, %v6,  %v1	\n"
	"	addi		%r8,  %r3,  32		\n"
	"	vsplth		%v17, %v8,  5		\n"
	"	lvx		%v13, 0,    %r9		\n"
	"	vslh		%v11, %v11, %v21	\n"
	"	addi		%r3,  %r3,  64		\n"
	"	lvx		%v10, 0,    %r8		\n"
	"	vslh		%v0,  %v0,  %v21	\n"
	"	addi		%r9,  %r10, 48		\n"
	"	vmhraddshs	%v31, %v12, %v6,  %v1	\n"
	"	lvx		%v4,  0,    %r9		\n"
	"	addi		%r10, %r10, 16		\n"
	"	vmhraddshs	%v26, %v0,  %v7,  %v1	\n"
	"	lvx		%v9,  0,    %r3		\n"
	"	vsplth		%v16, %v8,  3		\n"
	"	vmhraddshs	%v22, %v11, %v7,  %v1	\n"
	"	lvx		%v6,  0,    %r10	\n"
	"	lvsl		%v19, 0,    %r4		\n"
	"	vsubshs		%v12, %v1,  %v24	\n"
	"	lvsl		%v0,  %r5,  %r4		\n"
	"	vsplth		%v11, %v8,  1		\n"
	"	vslh		%v10, %v10, %v21	\n"
	"	vmrghb		%v19, %v3,  %v19	\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vslh		%v13, %v13, %v21	\n"
	"	vmrghb		%v3,  %v3,  %v0		\n"
	"	li		%r9,  4			\n"
	"	vmhraddshs	%v14, %v2,  %v31, %v12	\n"
	"	vsplth		%v7,  %v8,  0		\n"
	"	vmhraddshs	%v23, %v13, %v4,  %v1	\n"
	"	vsplth		%v18, %v8,  4		\n"
	"	vmhraddshs	%v27, %v10, %v4,  %v1	\n"
	"	vspltw		%v8,  %v8,  3		\n"
	"	vmhraddshs	%v12, %v17, %v22, %v26	\n"
	"	vperm		%v15, %v15, %v1,  %v19	\n"
	"	vslh		%v9,  %v9,  %v21	\n"
	"	vmhraddshs	%v10, %v5,  %v6,  %v1	\n"
	"	vspltish	%v21, 6			\n"
	"	vmhraddshs	%v30, %v9,  %v6,  %v1	\n"
	"	vmhraddshs	%v26, %v16, %v26, %v22	\n"
	"	vmhraddshs	%v24, %v2,  %v24, %v31	\n"
	"	vmhraddshs	%v31, %v11, %v23, %v27	\n"
	"	vsubshs		%v0,  %v1,  %v23	\n"
	"	vaddshs		%v23, %v14, %v12	\n"
	"	vmhraddshs	%v9,  %v11, %v27, %v0	\n"
	"	vsubshs		%v12, %v14, %v12	\n"
	"	vaddshs		%v6,  %v10, %v30	\n"
	"	vsubshs		%v14, %v24, %v26	\n"
	"	vaddshs		%v24, %v24, %v26	\n"
	"	vsubshs		%v13, %v10, %v30	\n"
	"	vaddshs		%v26, %v6,  %v31	\n"
	"	vsubshs		%v31, %v6,  %v31	\n"
	"	vaddshs		%v6,  %v13, %v9		\n"
	"	vsubshs		%v13, %v13, %v9		\n"
	"	vsubshs		%v9,  %v14, %v12	\n"
	"	vaddshs		%v12, %v14, %v12	\n"
	"	vmhraddshs	%v30, %v7,  %v9,  %v13	\n"
	"	vmhraddshs	%v25, %v18, %v12, %v6	\n"
	"	vmhraddshs	%v28, %v18, %v9,  %v13	\n"
	"	vmhraddshs	%v29, %v7,  %v12, %v6	\n"
	"	vaddshs		%v10, %v26, %v24	\n"
	"	vsubshs		%v5,  %v31, %v23	\n"
	"	vsubshs		%v13, %v26, %v24	\n"
	"	vaddshs		%v4,  %v31, %v23	\n"
	"	vmrglh		%v26, %v30, %v25	\n"
	"	vmrglh		%v31, %v10, %v5		\n"
	"	vmrglh		%v22, %v29, %v28	\n"
	"	vmrghh		%v30, %v30, %v25	\n"
	"	vmrglh		%v24, %v4,  %v13	\n"
	"	vmrghh		%v10, %v10, %v5		\n"
	"	vmrghh		%v23, %v4,  %v13	\n"
	"	vmrghh		%v27, %v29, %v28	\n"
	"	vmrglh		%v29, %v10, %v30	\n"
	"	vmrglh		%v4,  %v31, %v26	\n"
	"	vmrglh		%v13, %v22, %v24	\n"
	"	vmrghh		%v10, %v10, %v30	\n"
	"	vmrghh		%v25, %v22, %v24	\n"
	"	vmrglh		%v24, %v4,  %v13	\n"
	"	vmrghh		%v5,  %v27, %v23	\n"
	"	vmrglh		%v28, %v27, %v23	\n"
	"	vsubshs		%v0,  %v1,  %v24	\n"
	"	vmrghh		%v30, %v31, %v26	\n"
	"	vmrglh		%v31, %v10, %v5		\n"
	"	vmrglh		%v26, %v30, %v25	\n"
	"	vmrglh		%v22, %v29, %v28	\n"
	"	vmhraddshs	%v14, %v2,  %v31, %v0	\n"
	"	vmrghh		%v23, %v4,  %v13	\n"
	"	vmhraddshs	%v24, %v2,  %v24, %v31	\n"
	"	vmhraddshs	%v12, %v17, %v22, %v26	\n"
	"	vmrghh		%v27, %v29, %v28	\n"
	"	vmhraddshs	%v26, %v16, %v26, %v22	\n"
	"	vmrghh		%v0,  %v10, %v5		\n"
	"	vmhraddshs	%v31, %v11, %v23, %v27	\n"
	"	vmrghh		%v30, %v30, %v25	\n"
	"	vsubshs		%v13, %v1,  %v23	\n"
	"	vaddshs		%v10, %v0,  %v8		\n"
	"	vaddshs		%v23, %v14, %v12	\n"
	"	vsubshs		%v12, %v14, %v12	\n"
	"	vaddshs		%v6,  %v10, %v30	\n"
	"	vsubshs		%v14, %v24, %v26	\n"
	"	vmhraddshs	%v9,  %v11, %v27, %v13	\n"
	"	vaddshs		%v24, %v24, %v26	\n"
	"	vaddshs		%v26, %v6,  %v31	\n"
	"	vsubshs		%v13, %v10, %v30	\n"
	"	vaddshs		%v10, %v26, %v24	\n"
	"	vsubshs		%v31, %v6,  %v31	\n"
	"	vaddshs		%v6,  %v13, %v9		\n"
	"	vsrah		%v10, %v10, %v21	\n"
	"	vsubshs		%v13, %v13, %v9		\n"
	"	vaddshs		%v0,  %v15, %v10	\n"
	"	vsubshs		%v9,  %v14, %v12	\n"
	"	vaddshs		%v12, %v14, %v12	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	vaddshs		%v4,  %v31, %v23	\n"
	"	vmhraddshs	%v29, %v7,  %v12, %v6	\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	vsubshs		%v5,  %v31, %v23	\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vmhraddshs	%v30, %v7,  %v9,  %v13	\n"
	"	vsrah		%v22, %v4,  %v21	\n"
	"	vperm		%v15, %v15, %v1,  %v3	\n"
	"	vmhraddshs	%v28, %v18, %v9,  %v13	\n"
	"	vsrah		%v31, %v29, %v21	\n"
	"	vsubshs		%v13, %v26, %v24	\n"
	"	vaddshs		%v0,  %v15, %v31	\n"
	"	vsrah		%v27, %v30, %v21	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	vsrah		%v30, %v5,  %v21	\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	vsrah		%v26, %v28, %v21	\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	vmhraddshs	%v25, %v18, %v12, %v6	\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	vsrah		%v24, %v13, %v21	\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v19	\n"
	"	vsrah		%v23, %v25, %v21	\n"
	"	vaddshs		%v0,  %v15, %v27	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v3	\n"
	"	vaddshs		%v0,  %v15, %v22	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v19	\n"
	"	vaddshs		%v0,  %v15, %v30	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v3	\n"
	"	vaddshs		%v0,  %v15, %v26	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v19	\n"
	"	vaddshs		%v0,  %v15, %v23	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"
	"	add		%r4,  %r4,  %r5		\n"
	"	lvx		%v15, 0,    %r4		\n"
	"	vperm		%v15, %v15, %v1,  %v3	\n"
	"	vaddshs		%v0,  %v15, %v24	\n"
	"	vpkshus		%v15, %v0,  %v0		\n"
	"	stvewx		%v15, 0,    %r4		\n"
	"	stvewx		%v15, %r9,  %r4		\n"

	"#	addi		%r0,  %r1,  192		\n"
	"#	bl		_restv21		\n"
	"#	lwz		%r0,  196(%r1)		\n"
	"#	mtlr		%r0			\n"
	"#	la		%r1,  192(%r1)		\n"
        "       addi            %r9,  %r3,  16          \n"
        "       stvx            %v1,  0,    %r3         \n"
        "       stvx            %v1,  0,    %r9         \n"
        "       addi            %r11, %r3,  32          \n" 
        "       stvx            %v1,  0,    %r11        \n" 
        "       addi            %r9,  %r3,  48          \n" 
        "       stvx            %v1,  0,    %r9         \n" 
        "       addi            %r11, %r3,  -64         \n" 
        "       stvx            %v1,  0,    %r11        \n" 
        "       addi            %r9,  %r3,  -48         \n" 
        "       stvx            %v1,  0,    %r9         \n" 
        "       addi            %r11, %r3,  -32         \n"  
        "       stvx            %v1,  0,    %r11        \n"   
        "       addi            %r3,  %r3,  -16         \n"   
        "       stvx            %v1,  0,    %r3         \n"
	 );
}

static int16_t constants[5][8] ATTR_ALIGN(16) = {
    {23170, 13573, 6518, 21895, -23170, -21895, 32, 31},
    {16384, 22725, 21407, 19266, 16384, 19266, 21407, 22725},
    {22725, 31521, 29692, 26722, 22725, 26722, 29692, 31521},
    {21407, 29692, 27969, 25172, 21407, 25172, 27969, 29692},
    {19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722}
};

void mpeg2_idct_altivec_init (void)
{
    int i, j;

    i = constants[0][0];	/* just pretending - keeps gcc happy */

    /* the altivec idct uses a transposed input, so we patch scan tables */
    for (i = 0; i < 64; i++) {
	j = mpeg2_scan_norm[i];
	mpeg2_scan_norm[i] = (j >> 3) | ((j & 7) << 3);
	j = mpeg2_scan_alt[i];
	mpeg2_scan_alt[i] = (j >> 3) | ((j & 7) << 3);
    }
}

#else	/* HOST_OS_DARWIN */

#define vector_s16_t vector signed short
#define vector_u16_t vector unsigned short
#define vector_s8_t vector signed char
#define vector_u8_t vector unsigned char
#define vector_s32_t vector signed int
#define vector_u32_t vector unsigned int

#define IDCT_HALF					\
    /* 1st stage */					\
    t1 = vec_mradds (a1, vx7, vx1 );			\
    t8 = vec_mradds (a1, vx1, vec_subs (zero, vx7));	\
    t7 = vec_mradds (a2, vx5, vx3);			\
    t3 = vec_mradds (ma2, vx3, vx5);			\
							\
    /* 2nd stage */					\
    t5 = vec_adds (vx0, vx4);				\
    t0 = vec_subs (vx0, vx4);				\
    t2 = vec_mradds (a0, vx6, vx2);			\
    t4 = vec_mradds (a0, vx2, vec_subs (zero,vx6));	\
    t6 = vec_adds (t8, t3);				\
    t3 = vec_subs (t8, t3);				\
    t8 = vec_subs (t1, t7);				\
    t1 = vec_adds (t1, t7);				\
							\
    /* 3rd stage */					\
    t7 = vec_adds (t5, t2);				\
    t2 = vec_subs (t5, t2);				\
    t5 = vec_adds (t0, t4);				\
    t0 = vec_subs (t0, t4);				\
    t4 = vec_subs (t8, t3);				\
    t3 = vec_adds (t8, t3);				\
							\
    /* 4th stage */					\
    vy0 = vec_adds (t7, t1);				\
    vy7 = vec_subs (t7, t1);				\
    vy1 = vec_mradds (c4, t3, t5);			\
    vy6 = vec_mradds (mc4, t3, t5);			\
    vy2 = vec_mradds (c4, t4, t0);			\
    vy5 = vec_mradds (mc4, t4, t0);			\
    vy3 = vec_adds (t2, t6);				\
    vy4 = vec_subs (t2, t6);

#define IDCT								\
    vector_s16_t vx0, vx1, vx2, vx3, vx4, vx5, vx6, vx7;		\
    vector_s16_t vy0, vy1, vy2, vy3, vy4, vy5, vy6, vy7;		\
    vector_s16_t a0, a1, a2, ma2, c4, mc4, zero, bias;			\
    vector_s16_t t0, t1, t2, t3, t4, t5, t6, t7, t8;			\
    vector_u16_t shift;							\
									\
    c4 = vec_splat (constants[0], 0);					\
    a0 = vec_splat (constants[0], 1);					\
    a1 = vec_splat (constants[0], 2);					\
    a2 = vec_splat (constants[0], 3);					\
    mc4 = vec_splat (constants[0], 4);					\
    ma2 = vec_splat (constants[0], 5);					\
    bias = (vector_s16_t)vec_splat ((vector_s32_t)constants[0], 3);	\
									\
    zero = vec_splat_s16 (0);						\
    shift = vec_splat_u16 (4);						\
									\
    vx0 = vec_mradds (vec_sl (block[0], shift), constants[1], zero);	\
    vx1 = vec_mradds (vec_sl (block[1], shift), constants[2], zero);	\
    vx2 = vec_mradds (vec_sl (block[2], shift), constants[3], zero);	\
    vx3 = vec_mradds (vec_sl (block[3], shift), constants[4], zero);	\
    vx4 = vec_mradds (vec_sl (block[4], shift), constants[1], zero);	\
    vx5 = vec_mradds (vec_sl (block[5], shift), constants[4], zero);	\
    vx6 = vec_mradds (vec_sl (block[6], shift), constants[3], zero);	\
    vx7 = vec_mradds (vec_sl (block[7], shift), constants[2], zero);	\
									\
    IDCT_HALF								\
									\
    vx0 = vec_mergeh (vy0, vy4);					\
    vx1 = vec_mergel (vy0, vy4);					\
    vx2 = vec_mergeh (vy1, vy5);					\
    vx3 = vec_mergel (vy1, vy5);					\
    vx4 = vec_mergeh (vy2, vy6);					\
    vx5 = vec_mergel (vy2, vy6);					\
    vx6 = vec_mergeh (vy3, vy7);					\
    vx7 = vec_mergel (vy3, vy7);					\
									\
    vy0 = vec_mergeh (vx0, vx4);					\
    vy1 = vec_mergel (vx0, vx4);					\
    vy2 = vec_mergeh (vx1, vx5);					\
    vy3 = vec_mergel (vx1, vx5);					\
    vy4 = vec_mergeh (vx2, vx6);					\
    vy5 = vec_mergel (vx2, vx6);					\
    vy6 = vec_mergeh (vx3, vx7);					\
    vy7 = vec_mergel (vx3, vx7);					\
									\
    vx0 = vec_adds (vec_mergeh (vy0, vy4), bias);			\
    vx1 = vec_mergel (vy0, vy4);					\
    vx2 = vec_mergeh (vy1, vy5);					\
    vx3 = vec_mergel (vy1, vy5);					\
    vx4 = vec_mergeh (vy2, vy6);					\
    vx5 = vec_mergel (vy2, vy6);					\
    vx6 = vec_mergeh (vy3, vy7);					\
    vx7 = vec_mergel (vy3, vy7);					\
									\
    IDCT_HALF								\
									\
    shift = vec_splat_u16 (6);						\
    vx0 = vec_sra (vy0, shift);						\
    vx1 = vec_sra (vy1, shift);						\
    vx2 = vec_sra (vy2, shift);						\
    vx3 = vec_sra (vy3, shift);						\
    vx4 = vec_sra (vy4, shift);						\
    vx5 = vec_sra (vy5, shift);						\
    vx6 = vec_sra (vy6, shift);						\
    vx7 = vec_sra (vy7, shift);

static vector_s16_t constants[5] = {
    (vector_s16_t)(23170, 13573, 6518, 21895, -23170, -21895, 32, 31),
    (vector_s16_t)(16384, 22725, 21407, 19266, 16384, 19266, 21407, 22725),
    (vector_s16_t)(22725, 31521, 29692, 26722, 22725, 26722, 29692, 31521),
    (vector_s16_t)(21407, 29692, 27969, 25172, 21407, 25172, 27969, 29692),
    (vector_s16_t)(19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722)
};

void mpeg2_idct_copy_altivec (vector_s16_t * block, unsigned char * dest,
			      int stride)
{
    vector_u8_t tmp;

    IDCT

#define COPY(dest,src)						\
    tmp = vec_packsu (src, src);				\
    vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest);	\
    vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);

    COPY (dest, vx0)	dest += stride;
    COPY (dest, vx1)	dest += stride;
    COPY (dest, vx2)	dest += stride;
    COPY (dest, vx3)	dest += stride;
    COPY (dest, vx4)	dest += stride;
    COPY (dest, vx5)	dest += stride;
    COPY (dest, vx6)	dest += stride;
    COPY (dest, vx7)
    memset (block, 0, 64 * sizeof (signed short));
}

void mpeg2_idct_add_altivec (vector_s16_t * block, unsigned char * dest,
			     int stride)
{
    vector_u8_t tmp;
    vector_s16_t tmp2, tmp3;
    vector_u8_t perm0;
    vector_u8_t perm1;
    vector_u8_t p0, p1, p;

    IDCT

    p0 = vec_lvsl (0, dest);
    p1 = vec_lvsl (stride, dest);
    p = vec_splat_u8 (-1);
    perm0 = vec_mergeh (p, p0);
    perm1 = vec_mergeh (p, p1);

#define ADD(dest,src,perm)						\
    /* *(uint64_t *)&tmp = *(uint64_t *)dest; */			\
    tmp = vec_ld (0, dest);						\
    tmp2 = (vector_s16_t)vec_perm (tmp, (vector_u8_t)zero, perm);	\
    tmp3 = vec_adds (tmp2, src);					\
    tmp = vec_packsu (tmp3, tmp3);					\
    vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest);		\
    vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);

    ADD (dest, vx0, perm0)	dest += stride;
    ADD (dest, vx1, perm1)	dest += stride;
    ADD (dest, vx2, perm0)	dest += stride;
    ADD (dest, vx3, perm1)	dest += stride;
    ADD (dest, vx4, perm0)	dest += stride;
    ADD (dest, vx5, perm1)	dest += stride;
    ADD (dest, vx6, perm0)	dest += stride;
    ADD (dest, vx7, perm1)
    memset (block, 0, 64 * sizeof (signed short));
}

void mpeg2_idct_altivec_init (void)
{
    int i, j;

    /* the altivec idct uses a transposed input, so we patch scan tables */
    for (i = 0; i < 64; i++) {
	j = mpeg2_scan_norm[i];
	mpeg2_scan_norm[i] = (j >> 3) | ((j & 7) << 3);
	j = mpeg2_scan_alt[i];
	mpeg2_scan_alt[i] = (j >> 3) | ((j & 7) << 3);
    }
}

#endif	/* HOST_OS_DARWIN */

#endif	/* ARCH_PPC && ENABLED_ALTIVEC */


--- NEW FILE: motion_comp_mlib.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: motion_comp_altivec.c ---
/*
 * motion_comp_altivec.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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
[...1992 lines suppressed...]
    vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest);
    vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
    dest += stride;
    A = vec_perm (ref0, ref1, perm0A);
    B = vec_perm (ref0, ref1, perm0B);
    avg0 = vec_avg (A, B);
    xor0 = vec_xor (A, B);
    tmp = vec_avg (prev, vec_sub (vec_avg (avg0, avg1),
				  vec_and (vec_and (ones, vec_or (xor0, xor1)),
					   vec_xor (avg0, avg1))));
    vec_ste ((vector_u32_t)tmp, 0, (unsigned int *)dest);
    vec_ste ((vector_u32_t)tmp, 4, (unsigned int *)dest);
}

MPEG2_MC_EXTERN (altivec)

#endif /* ENABLE_ALTIVEC */

#endif	/* HOST_OS_DARWIN */


--- NEW FILE: slice.c ---
/*
 * slice.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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
[...1794 lines suppressed...]
	    if (picture->picture_coding_type == P_TYPE) {
		picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
		picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;

		do {
		    MOTION_CALL (motion_zero, MACROBLOCK_MOTION_FORWARD);
		    NEXT_MACROBLOCK;
		} while (--mba_inc);
	    } else {
		do {
		    MOTION_CALL (motion_reuse, macroblock_modes);
		    NEXT_MACROBLOCK;
		} while (--mba_inc);
	    }
	}
    }
#undef bit_buf
#undef bits
#undef bit_ptr
}

--- NEW FILE: decode.c ---
 /*
 * decode.c
 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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
[...985 lines suppressed...]

      _x_stream_info_set(mpeg2dec->stream, XINE_STREAM_INFO_VIDEO_WIDTH,
        mpeg2dec->picture->display_width);
      _x_stream_info_set(mpeg2dec->stream, XINE_STREAM_INFO_VIDEO_HEIGHT,
        mpeg2dec->picture->display_height);
    }
    
    if (mpeg2dec->cc_dec) {
      buf_element_t buf;
      
      buf.type = BUF_SPU_CC;
      buf.content = &buffer[2];
      buf.pts = mpeg2dec->pts;
      buf.size = find_end(buffer) - &buffer[2];
      buf.decoder_flags = 0;
      
      mpeg2dec->cc_dec->decode_data(mpeg2dec->cc_dec, &buf);
    }
  }
}

--- NEW FILE: idct_mlib.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: Makefile.in ---
# Makefile.in generated by automake 1.9.3 from Makefile.am.
# @configure_input@

# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004  Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@


SOURCES = $(xineplug_decode_mpeg2_la_SOURCES)

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
	$(srcdir)/Makefile.in $(top_srcdir)/misc/Makefile.common
subdir = src/libmpeg2
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/_xine.m4 $(top_srcdir)/m4/aa.m4 \
	$(top_srcdir)/m4/alsa.m4 $(top_srcdir)/m4/arts.m4 \
	$(top_srcdir)/m4/as.m4 $(top_srcdir)/m4/caca.m4 \
	$(top_srcdir)/m4/codeset.m4 $(top_srcdir)/m4/directx.m4 \
	$(top_srcdir)/m4/dl.m4 $(top_srcdir)/m4/dvdnav.m4 \
	$(top_srcdir)/m4/esd.m4 $(top_srcdir)/m4/ffmpeg.m4 \
	$(top_srcdir)/m4/freetype2.m4 $(top_srcdir)/m4/gettext.m4 \
	$(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \
	$(top_srcdir)/m4/irixal.m4 $(top_srcdir)/m4/lcmessage.m4 \
	$(top_srcdir)/m4/libFLAC.m4 $(top_srcdir)/m4/libfame.m4 \
	$(top_srcdir)/m4/ogg.m4 $(top_srcdir)/m4/opengl.m4 \
	$(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/progtest.m4 \
	$(top_srcdir)/m4/sdl.m4 $(top_srcdir)/m4/speex.m4 \
	$(top_srcdir)/m4/theora.m4 $(top_srcdir)/m4/vorbis.m4 \
	$(top_srcdir)/m4/xv.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
    *) f=$$p;; \
  esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = $(top_builddir)/src/xine-engine/libxine.la
xineplug_decode_mpeg2_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
	$(am__DEPENDENCIES_2)
am_xineplug_decode_mpeg2_la_OBJECTS = cpu_state.lo decode.lo header.lo \
	idct.lo idct_altivec.lo idct_mlib.lo idct_mmx.lo \
	motion_comp.lo motion_comp_altivec.lo motion_comp_mmx.lo \
	motion_comp_mlib.lo motion_comp_vis.lo slice.lo slice_xvmc.lo \
	slice_xvmc_vld.lo stats.lo xine_decoder.lo
xineplug_decode_mpeg2_la_OBJECTS =  \
	$(am_xineplug_decode_mpeg2_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
	$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
	$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(xineplug_decode_mpeg2_la_SOURCES)
DIST_SOURCES = $(xineplug_decode_mpeg2_la_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
AAINFO = @AAINFO@
AALIB_CFLAGS = @AALIB_CFLAGS@
AALIB_CONFIG = @AALIB_CONFIG@
AALIB_LIBS = @AALIB_LIBS@
ACLOCAL = @ACLOCAL@
ACLOCAL_DIR = @ACLOCAL_DIR@
ALLOCA = @ALLOCA@
ALSA_CFLAGS = @ALSA_CFLAGS@
ALSA_LIBS = @ALSA_LIBS@
ALSA_STATIC_LIB = @ALSA_STATIC_LIB@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
ARTS_CFLAGS = @ARTS_CFLAGS@
ARTS_CONFIG = @ARTS_CONFIG@
ARTS_LIBS = @ARTS_LIBS@
AS = @AS@
ASFLAGS = @ASFLAGS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_ASF_FALSE = @BUILD_ASF_FALSE@
BUILD_ASF_TRUE = @BUILD_ASF_TRUE@
BUILD_DHA_KMOD_FALSE = @BUILD_DHA_KMOD_FALSE@
BUILD_DHA_KMOD_TRUE = @BUILD_DHA_KMOD_TRUE@
BUILD_FAAD_FALSE = @BUILD_FAAD_FALSE@
BUILD_FAAD_TRUE = @BUILD_FAAD_TRUE@
BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@
CACA_CFLAGS = @CACA_CFLAGS@
CACA_CONFIG = @CACA_CONFIG@
CACA_LIBS = @CACA_LIBS@
CATALOGS = @CATALOGS@
CATOBJEXT = @CATOBJEXT@
CC = @CC@
CCAS = @CCAS@
CCASCOMPILE = @CCASCOMPILE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DATADIRNAME = @DATADIRNAME@
DEBUG_CFLAGS = @DEBUG_CFLAGS@
DEFS = @DEFS@
DEPCOMP = @DEPCOMP@
DEPDIR = @DEPDIR@
DEPMOD = @DEPMOD@
DIRECTFB_CFLAGS = @DIRECTFB_CFLAGS@
DIRECTFB_LIBS = @DIRECTFB_LIBS@
DIRECTX_AUDIO_LIBS = @DIRECTX_AUDIO_LIBS@
DIRECTX_CPPFLAGS = @DIRECTX_CPPFLAGS@
DIRECTX_VIDEO_LIBS = @DIRECTX_VIDEO_LIBS@
DLLTOOL = @DLLTOOL@
DVDNAV_CFLAGS = @DVDNAV_CFLAGS@
DVDNAV_CONFIG = @DVDNAV_CONFIG@
DVDNAV_LIBS = @DVDNAV_LIBS@
DYNAMIC_LD_LIBS = @DYNAMIC_LD_LIBS@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_VCD_FALSE = @ENABLE_VCD_FALSE@
ENABLE_VCD_TRUE = @ENABLE_VCD_TRUE@
ESD_CFLAGS = @ESD_CFLAGS@
ESD_CONFIG = @ESD_CONFIG@
ESD_LIBS = @ESD_LIBS@
EXEEXT = @EXEEXT@
EXTRA_X_CFLAGS = @EXTRA_X_CFLAGS@
EXTRA_X_LIBS = @EXTRA_X_LIBS@
F77 = @F77@
FFLAGS = @FFLAGS@
FFMPEG_CPPFLAGS = @FFMPEG_CPPFLAGS@
FFMPEG_LIBS = @FFMPEG_LIBS@
FIG2DEV = @FIG2DEV@
FREETYPE_CONFIG = @FREETYPE_CONFIG@
FT2_CFLAGS = @FT2_CFLAGS@
FT2_LIBS = @FT2_LIBS@
GENCAT = @GENCAT@
GLIBC21 = @GLIBC21@
GLUT_LIBS = @GLUT_LIBS@
GLU_LIBS = @GLU_LIBS@
GMOFILES = @GMOFILES@
GMSGFMT = @GMSGFMT@
GNOME_VFS_CFLAGS = @GNOME_VFS_CFLAGS@
GNOME_VFS_LIBS = @GNOME_VFS_LIBS@
GOOM_LIBS = @GOOM_LIBS@
HAVE_AA_FALSE = @HAVE_AA_FALSE@
HAVE_AA_TRUE = @HAVE_AA_TRUE@
HAVE_ALSA09_FALSE = @HAVE_ALSA09_FALSE@
HAVE_ALSA09_TRUE = @HAVE_ALSA09_TRUE@
HAVE_ALSA_FALSE = @HAVE_ALSA_FALSE@
HAVE_ALSA_TRUE = @HAVE_ALSA_TRUE@
HAVE_ARMV4L_FALSE = @HAVE_ARMV4L_FALSE@
HAVE_ARMV4L_TRUE = @HAVE_ARMV4L_TRUE@
HAVE_ARTS_FALSE = @HAVE_ARTS_FALSE@
HAVE_ARTS_TRUE = @HAVE_ARTS_TRUE@
HAVE_BSDI_CDROM = @HAVE_BSDI_CDROM@
HAVE_CACA_FALSE = @HAVE_CACA_FALSE@
HAVE_CACA_TRUE = @HAVE_CACA_TRUE@
HAVE_CDROM_IOCTLS_FALSE = @HAVE_CDROM_IOCTLS_FALSE@
HAVE_CDROM_IOCTLS_TRUE = @HAVE_CDROM_IOCTLS_TRUE@
HAVE_COREAUDIO_FALSE = @HAVE_COREAUDIO_FALSE@
HAVE_COREAUDIO_TRUE = @HAVE_COREAUDIO_TRUE@
HAVE_DARWIN_CDROM = @HAVE_DARWIN_CDROM@
HAVE_DIRECTFB_FALSE = @HAVE_DIRECTFB_FALSE@
HAVE_DIRECTFB_TRUE = @HAVE_DIRECTFB_TRUE@
HAVE_DIRECTX_FALSE = @HAVE_DIRECTX_FALSE@
HAVE_DIRECTX_TRUE = @HAVE_DIRECTX_TRUE@
HAVE_DVDNAV_FALSE = @HAVE_DVDNAV_FALSE@
HAVE_DVDNAV_TRUE = @HAVE_DVDNAV_TRUE@
HAVE_DXR3_FALSE = @HAVE_DXR3_FALSE@
HAVE_DXR3_TRUE = @HAVE_DXR3_TRUE@
HAVE_ESD_FALSE = @HAVE_ESD_FALSE@
HAVE_ESD_TRUE = @HAVE_ESD_TRUE@
HAVE_FB_FALSE = @HAVE_FB_FALSE@
HAVE_FB_TRUE = @HAVE_FB_TRUE@
HAVE_FFMMX_FALSE = @HAVE_FFMMX_FALSE@
HAVE_FFMMX_TRUE = @HAVE_FFMMX_TRUE@
HAVE_FFMPEG_FALSE = @HAVE_FFMPEG_FALSE@
HAVE_FFMPEG_TRUE = @HAVE_FFMPEG_TRUE@
HAVE_FIG2DEV_FALSE = @HAVE_FIG2DEV_FALSE@
HAVE_FIG2DEV_TRUE = @HAVE_FIG2DEV_TRUE@
HAVE_FLAC_FALSE = @HAVE_FLAC_FALSE@
HAVE_FLAC_TRUE = @HAVE_FLAC_TRUE@
HAVE_FREEBSD_CDROM = @HAVE_FREEBSD_CDROM@
HAVE_GNOME_VFS_FALSE = @HAVE_GNOME_VFS_FALSE@
HAVE_GNOME_VFS_TRUE = @HAVE_GNOME_VFS_TRUE@
HAVE_IRIXAL_FALSE = @HAVE_IRIXAL_FALSE@
HAVE_IRIXAL_TRUE = @HAVE_IRIXAL_TRUE@
HAVE_LIBFAME_FALSE = @HAVE_LIBFAME_FALSE@
HAVE_LIBFAME_TRUE = @HAVE_LIBFAME_TRUE@
HAVE_LIBMNG_FALSE = @HAVE_LIBMNG_FALSE@
HAVE_LIBMNG_TRUE = @HAVE_LIBMNG_TRUE@
HAVE_LIBPNG_FALSE = @HAVE_LIBPNG_FALSE@
HAVE_LIBPNG_TRUE = @HAVE_LIBPNG_TRUE@
HAVE_LIBRTE_FALSE = @HAVE_LIBRTE_FALSE@
HAVE_LIBRTE_TRUE = @HAVE_LIBRTE_TRUE@
HAVE_LIBSMBCLIENT_FALSE = @HAVE_LIBSMBCLIENT_FALSE@
HAVE_LIBSMBCLIENT_TRUE = @HAVE_LIBSMBCLIENT_TRUE@
HAVE_LINUX_CDROM = @HAVE_LINUX_CDROM@
HAVE_LINUX_FALSE = @HAVE_LINUX_FALSE@
HAVE_LINUX_TRUE = @HAVE_LINUX_TRUE@
HAVE_MACOSX_VIDEO_FALSE = @HAVE_MACOSX_VIDEO_FALSE@
HAVE_MACOSX_VIDEO_TRUE = @HAVE_MACOSX_VIDEO_TRUE@
HAVE_MLIB_FALSE = @HAVE_MLIB_FALSE@
HAVE_MLIB_TRUE = @HAVE_MLIB_TRUE@
HAVE_OPENGL_FALSE = @HAVE_OPENGL_FALSE@
HAVE_OPENGL_TRUE = @HAVE_OPENGL_TRUE@
HAVE_OSS_FALSE = @HAVE_OSS_FALSE@
HAVE_OSS_TRUE = @HAVE_OSS_TRUE@
HAVE_POLYPAUDIO_FALSE = @HAVE_POLYPAUDIO_FALSE@
HAVE_POLYPAUDIO_TRUE = @HAVE_POLYPAUDIO_TRUE@
HAVE_SDL_FALSE = @HAVE_SDL_FALSE@
HAVE_SDL_TRUE = @HAVE_SDL_TRUE@
HAVE_SGMLTOOLS_FALSE = @HAVE_SGMLTOOLS_FALSE@
HAVE_SGMLTOOLS_TRUE = @HAVE_SGMLTOOLS_TRUE@
HAVE_SOLARIS_CDROM = @HAVE_SOLARIS_CDROM@
HAVE_SPEEX_FALSE = @HAVE_SPEEX_FALSE@
HAVE_SPEEX_TRUE = @HAVE_SPEEX_TRUE@
HAVE_STK_FALSE = @HAVE_STK_FALSE@
HAVE_STK_TRUE = @HAVE_STK_TRUE@
HAVE_SUNAUDIO_FALSE = @HAVE_SUNAUDIO_FALSE@
HAVE_SUNAUDIO_TRUE = @HAVE_SUNAUDIO_TRUE@
HAVE_SUNDGA_FALSE = @HAVE_SUNDGA_FALSE@
HAVE_SUNDGA_TRUE = @HAVE_SUNDGA_TRUE@
HAVE_SUNFB_FALSE = @HAVE_SUNFB_FALSE@
HAVE_SUNFB_TRUE = @HAVE_SUNFB_TRUE@
HAVE_SYNCFB_FALSE = @HAVE_SYNCFB_FALSE@
HAVE_SYNCFB_TRUE = @HAVE_SYNCFB_TRUE@
HAVE_THEORA_FALSE = @HAVE_THEORA_FALSE@
HAVE_THEORA_TRUE = @HAVE_THEORA_TRUE@
HAVE_V4L_FALSE = @HAVE_V4L_FALSE@
HAVE_V4L_TRUE = @HAVE_V4L_TRUE@
HAVE_VCDNAV_FALSE = @HAVE_VCDNAV_FALSE@
HAVE_VCDNAV_TRUE = @HAVE_VCDNAV_TRUE@
HAVE_VIDIX_FALSE = @HAVE_VIDIX_FALSE@
HAVE_VIDIX_TRUE = @HAVE_VIDIX_TRUE@
HAVE_VLDXVMC_FALSE = @HAVE_VLDXVMC_FALSE@
HAVE_VLDXVMC_TRUE = @HAVE_VLDXVMC_TRUE@
HAVE_VORBIS_FALSE = @HAVE_VORBIS_FALSE@
HAVE_VORBIS_TRUE = @HAVE_VORBIS_TRUE@
HAVE_W32DLL_FALSE = @HAVE_W32DLL_FALSE@
HAVE_W32DLL_TRUE = @HAVE_W32DLL_TRUE@
HAVE_WIN32_CDROM = @HAVE_WIN32_CDROM@
HAVE_X11_FALSE = @HAVE_X11_FALSE@
HAVE_X11_TRUE = @HAVE_X11_TRUE@
HAVE_XVMC_FALSE = @HAVE_XVMC_FALSE@
HAVE_XVMC_TRUE = @HAVE_XVMC_TRUE@
HAVE_XV_FALSE = @HAVE_XV_FALSE@
HAVE_XV_TRUE = @HAVE_XV_TRUE@
HAVE_XXMC_FALSE = @HAVE_XXMC_FALSE@
HAVE_XXMC_TRUE = @HAVE_XXMC_TRUE@
HAVE_ZLIB_FALSE = @HAVE_ZLIB_FALSE@
HAVE_ZLIB_TRUE = @HAVE_ZLIB_TRUE@
HOST_OS_DARWIN_FALSE = @HOST_OS_DARWIN_FALSE@
HOST_OS_DARWIN_TRUE = @HOST_OS_DARWIN_TRUE@
INCLUDED_INTL_FALSE = @INCLUDED_INTL_FALSE@
INCLUDED_INTL_TRUE = @INCLUDED_INTL_TRUE@
INCLUDES = @INCLUDES@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_M4_FALSE = @INSTALL_M4_FALSE@
INSTALL_M4_TRUE = @INSTALL_M4_TRUE@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INSTOBJEXT = @INSTOBJEXT@
INTLBISON = @INTLBISON@
INTLDIR = @INTLDIR@
INTLLIBS = @INTLLIBS@
INTLOBJS = @INTLOBJS@
INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@
IRIXAL_CFLAGS = @IRIXAL_CFLAGS@
IRIXAL_LIBS = @IRIXAL_LIBS@
IRIXAL_STATIC_LIB = @IRIXAL_STATIC_LIB@
KSTAT_LIBS = @KSTAT_LIBS@
LDFLAGS = @LDFLAGS@
LIBCDIO_CFLAGS = @LIBCDIO_CFLAGS@
LIBCDIO_LIBS = @LIBCDIO_LIBS@
LIBFAME_CFLAGS = @LIBFAME_CFLAGS@
LIBFAME_CONFIG = @LIBFAME_CONFIG@
LIBFAME_LIBS = @LIBFAME_LIBS@
LIBFFMPEG_CFLAGS = @LIBFFMPEG_CFLAGS@
LIBFLAC_CFLAGS = @LIBFLAC_CFLAGS@
LIBFLAC_LIBS = @LIBFLAC_LIBS@
LIBICONV = @LIBICONV@
LIBISO9660_LIBS = @LIBISO9660_LIBS@
LIBMODPLUG_CFLAGS = @LIBMODPLUG_CFLAGS@
LIBMODPLUG_LIBS = @LIBMODPLUG_LIBS@
LIBMPEG2_CFLAGS = @LIBMPEG2_CFLAGS@
LIBNAME = @LIBNAME@
LIBOBJS = @LIBOBJS@
LIBPNG_CONFIG = @LIBPNG_CONFIG@
LIBS = @LIBS@
LIBSMBCLIENT_LIBS = @LIBSMBCLIENT_LIBS@
LIBSTK_CFLAGS = @LIBSTK_CFLAGS@
LIBSTK_LIBS = @LIBSTK_LIBS@
LIBTOOL = $(SHELL) $(top_builddir)/libtool-nofpic
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIBVCDINFO_LIBS = @LIBVCDINFO_LIBS@
LIBVCD_CFLAGS = @LIBVCD_CFLAGS@
LIBVCD_LIBS = @LIBVCD_LIBS@
LIBVCD_SYSDEP = @LIBVCD_SYSDEP@
LINUX_CDROM_TIMEOUT = @LINUX_CDROM_TIMEOUT@
LINUX_INCLUDE = @LINUX_INCLUDE@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_REVISION = @LT_REVISION@
MAKEINFO = @MAKEINFO@
MKINSTALLDIRS = @MKINSTALLDIRS@
MKNOD = @MKNOD@
MLIB_CFLAGS = @MLIB_CFLAGS@
MLIB_LIBS = @MLIB_LIBS@
MNG_LIBS = @MNG_LIBS@
MSGFMT = @MSGFMT@
NET_LIBS = @NET_LIBS@
OBJC = @OBJC@
OBJCDEPMODE = @OBJCDEPMODE@
OBJCFLAGS = @OBJCFLAGS@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OGG_CFLAGS = @OGG_CFLAGS@
OGG_LIBS = @OGG_LIBS@
OPENGL_CFLAGS = @OPENGL_CFLAGS@
OPENGL_LIBS = @OPENGL_LIBS@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PASS1_CFLAGS = @PASS1_CFLAGS@
PASS2_CFLAGS = @PASS2_CFLAGS@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PNG_CFLAGS = @PNG_CFLAGS@
PNG_LIBS = @PNG_LIBS@
POFILES = @POFILES@
POLYPAUDIO_CFLAGS = @POLYPAUDIO_CFLAGS@
POLYPAUDIO_LIBS = @POLYPAUDIO_LIBS@
POSUB = @POSUB@
PPC_ARCH_FALSE = @PPC_ARCH_FALSE@
PPC_ARCH_TRUE = @PPC_ARCH_TRUE@
RANLIB = @RANLIB@
RT_LIBS = @RT_LIBS@
SDL_CFLAGS = @SDL_CFLAGS@
SDL_CONFIG = @SDL_CONFIG@
SDL_LIBS = @SDL_LIBS@
SET_MAKE = @SET_MAKE@
SGMLTOOLS = @SGMLTOOLS@
SHELL = @SHELL@
SPEC_VERSION = @SPEC_VERSION@
SPEEX_CFLAGS = @SPEEX_CFLAGS@
SPEEX_LIBS = @SPEEX_LIBS@
STATIC = @STATIC@
STRIP = @STRIP@
SUNDGA_CFLAGS = @SUNDGA_CFLAGS@
SUNDGA_LIBS = @SUNDGA_LIBS@
TAR_NAME = @TAR_NAME@
THEORAENC_LIBS = @THEORAENC_LIBS@
THEORAFILE_LIBS = @THEORAFILE_LIBS@
THEORA_CFLAGS = @THEORA_CFLAGS@
THEORA_LIBS = @THEORA_LIBS@
THREAD_CFLAGS = @THREAD_CFLAGS@
THREAD_CFLAGS_CONFIG = @THREAD_CFLAGS_CONFIG@
THREAD_INCLUDES = @THREAD_INCLUDES@
THREAD_LIBS = @THREAD_LIBS@
THREAD_LIBS_CONFIG = @THREAD_LIBS_CONFIG@
USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
VORBISENC_LIBS = @VORBISENC_LIBS@
VORBISFILE_LIBS = @VORBISFILE_LIBS@
VORBIS_CFLAGS = @VORBIS_CFLAGS@
VORBIS_LIBS = @VORBIS_LIBS@
W32DLL_DEP = @W32DLL_DEP@
W32_NO_OPTIMIZE = @W32_NO_OPTIMIZE@
WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
WIN32_FALSE = @WIN32_FALSE@
WIN32_TRUE = @WIN32_TRUE@
XGETTEXT = @XGETTEXT@
XINE_ACFLAGS = @XINE_ACFLAGS@
XINE_BIN_AGE = @XINE_BIN_AGE@
XINE_BUILD_CC = @XINE_BUILD_CC@
XINE_BUILD_DATE = @XINE_BUILD_DATE@
XINE_BUILD_OS = @XINE_BUILD_OS@
XINE_CONFIG_PREFIX = @XINE_CONFIG_PREFIX@
XINE_DATADIR = @XINE_DATADIR@
XINE_FONTDIR = @XINE_FONTDIR@
XINE_FONTPATH = @XINE_FONTPATH@
XINE_IFACE_AGE = @XINE_IFACE_AGE@
XINE_LOCALEDIR = @XINE_LOCALEDIR@
XINE_LOCALEPATH = @XINE_LOCALEPATH@
XINE_MAJOR = @XINE_MAJOR@
XINE_MINOR = @XINE_MINOR@
XINE_PLUGINDIR = @XINE_PLUGINDIR@
XINE_PLUGINPATH = @XINE_PLUGINPATH@
XINE_PLUGIN_MIN_SYMS = @XINE_PLUGIN_MIN_SYMS@
XINE_SCRIPTPATH = @XINE_SCRIPTPATH@
XINE_SUB = @XINE_SUB@
XVMC_LIB = @XVMC_LIB@
XV_LIB = @XV_LIB@
XXMC_LIB = @XXMC_LIB@
X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
ZLIB_INCLUDES = @ZLIB_INCLUDES@
ZLIB_LIBS = @ZLIB_LIBS@
ZLIB_LIBS_CONFIG = @ZLIB_LIBS_CONFIG@
ac_ct_AR = @ac_ct_AR@
ac_ct_AS = @ac_ct_AS@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DLLTOOL = @ac_ct_DLLTOOL@
ac_ct_F77 = @ac_ct_F77@
ac_ct_OBJDUMP = @ac_ct_OBJDUMP@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__fastdepOBJC_FALSE = @am__fastdepOBJC_FALSE@
am__fastdepOBJC_TRUE = @am__fastdepOBJC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = $(XINE_PLUGINDIR)
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
w32_path = @w32_path@
XINE_LIB = $(top_builddir)/src/xine-engine/libxine.la
AM_CFLAGS = $(LIBMPEG2_CFLAGS)
lib_LTLIBRARIES = xineplug_decode_mpeg2.la
xineplug_decode_mpeg2_la_SOURCES = \
	cpu_state.c \
	decode.c \
	header.c \
	idct.c \
	idct_altivec.c \
	idct_mlib.c \
	idct_mmx.c \
	motion_comp.c \
	motion_comp_altivec.c \
	motion_comp_mmx.c \
	motion_comp_mlib.c \
	motion_comp_vis.c \
	slice.c \
	slice_xvmc.c \
	slice_xvmc_vld.c \
	stats.c \
	xine_decoder.c

xineplug_decode_mpeg2_la_LIBADD = $(MLIB_LIBS) $(XINE_LIB)
xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@
noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h
all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(top_srcdir)/misc/Makefile.common $(am__configure_deps)
	@for dep in $?; do \
	  case '$(am__configure_deps)' in \
	    *$$dep*) \
	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
		&& exit 0; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/libmpeg2/Makefile'; \
	cd $(top_srcdir) && \
	  $(AUTOMAKE) --gnu  src/libmpeg2/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
	esac;

$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh

$(top_srcdir)/configure:  $(am__configure_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
	@$(NORMAL_INSTALL)
	test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    f=$(am__strip_dir) \
	    echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
	    $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
	  else :; fi; \
	done

uninstall-libLTLIBRARIES:
	@$(NORMAL_UNINSTALL)
	@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  p=$(am__strip_dir) \
	  echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
	  $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
	done

clean-libLTLIBRARIES:
	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
	  test "$$dir" != "$$p" || dir=.; \
	  echo "rm -f \"$${dir}/so_locations\""; \
	  rm -f "$${dir}/so_locations"; \
	done
xineplug_decode_mpeg2.la: $(xineplug_decode_mpeg2_la_OBJECTS) $(xineplug_decode_mpeg2_la_DEPENDENCIES) 
	$(LINK) -rpath $(libdir) $(xineplug_decode_mpeg2_la_LDFLAGS) $(xineplug_decode_mpeg2_la_OBJECTS) $(xineplug_decode_mpeg2_la_LIBADD) $(LIBS)

mostlyclean-compile:
	-rm -f *.$(OBJEXT)

distclean-compile:
	-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu_state.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/decode.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/header.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idct.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idct_altivec.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idct_mlib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idct_mmx.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motion_comp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motion_comp_altivec.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motion_comp_mlib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motion_comp_mmx.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motion_comp_vis.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slice.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slice_xvmc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slice_xvmc_vld.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stats.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xine_decoder.Plo@am__quote@

.c.o:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c $<

.c.obj:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`

.c.lo:
@am__fastdepCC_TRUE@	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:
	-rm -f libtool
uninstall-info-am:

ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	mkid -fID $$unique
tags: TAGS

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
	  test -n "$$unique" || unique=$$empty_fix; \
	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
	    $$tags $$unique; \
	fi
ctags: CTAGS
CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(CTAGS_ARGS)$$tags$$unique" \
	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
	     $$tags $$unique

GTAGS:
	here=`$(am__cd) $(top_builddir) && pwd` \
	  && cd $(top_srcdir) \
	  && gtags -i $(GTAGS_ARGS) $$here

distclean-tags:
	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags

distdir: $(DISTFILES)
	$(mkdir_p) $(distdir)/../../misc
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkdir_p) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
installdirs:
	for dir in "$(DESTDIR)$(libdir)"; do \
	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
	done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	  `test -z '$(STRIP)' || \
	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install

clean-generic:

distclean-generic:
	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
clean: clean-am

clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
	mostlyclean-am

distclean: distclean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
	distclean-libtool distclean-tags

dvi: dvi-am

dvi-am:

html: html-am

info: info-am

info-am:

install-data-am:
	@$(NORMAL_INSTALL)
	$(MAKE) $(AM_MAKEFLAGS) install-data-hook

install-exec-am: install-libLTLIBRARIES

install-info: install-info-am

install-man:

installcheck-am:

maintainer-clean: maintainer-clean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES
	@$(NORMAL_INSTALL)
	$(MAKE) $(AM_MAKEFLAGS) uninstall-hook

.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
	clean-libLTLIBRARIES clean-libtool ctags distclean \
	distclean-compile distclean-generic distclean-libtool \
	distclean-tags distdir dvi dvi-am html html-am info info-am \
	install install-am install-data install-data-am \
	install-data-hook install-exec install-exec-am install-info \
	install-info-am install-libLTLIBRARIES install-man \
	install-strip installcheck installcheck-am installdirs \
	maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
	pdf pdf-am ps ps-am tags uninstall uninstall-am uninstall-hook \
	uninstall-info-am uninstall-libLTLIBRARIES


$(XINE_LIB):
	@cd $(top_srcdir)/src/xine-engine && $(MAKE)

install-data-hook:
	@if test $$MAKELEVEL -le 4 ; then \
	  if test -x "$(top_srcdir)/post-install.sh" ; then \
	    $(top_srcdir)/post-install.sh ; \
	  fi \
	fi

pass1:
	@$(MAKE) MULTIPASS_CFLAGS="$(PASS1_CFLAGS)"

pass2:
	@$(MAKE) MULTIPASS_CFLAGS="$(PASS2_CFLAGS)"

debug:
	@$(MAKE) CFLAGS="$(DEBUG_CFLAGS)"

install-debug: debug
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
	@list='$(SUBDIRS)'; for subdir in $$list; do \
	  (cd $$subdir && $(MAKE) $@) || exit; \
	done;
	$(MAKE) $(AM_MAKEFLAGS) install-data-hook

install-includeHEADERS: $(include_HEADERS)
	@$(NORMAL_INSTALL)
	$(install_sh) -d $(DESTDIR)$(includedir)/xine
	@list='$(include_HEADERS)'; for p in $$list; do \
	  if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
	  echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/xine/$$p"; \
	  $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/xine/$$p; \
	done

uninstall-includeHEADERS:
	@$(NORMAL_UNINSTALL)
	list='$(include_HEADERS)'; for p in $$list; do \
	  rm -f $(DESTDIR)$(includedir)/xine/$$p; \
	done

uninstall-hook:
	@if echo '$(libdir)' | egrep ^'$(XINE_PLUGINDIR)' >/dev/null; then \
	  list='$(lib_LTLIBRARIES)'; for p in $$list; do \
	    p="`echo $$p | sed -e 's/\.la$$/\.so/g;s|^.*/||'`"; \
	    echo " rm -f $(DESTDIR)$(libdir)/$$p"; \
	    rm -f $(DESTDIR)$(libdir)/$$p; \
	  done; \
	fi

mostlyclean-generic:
	-rm -f *~ \#* .*~ .\#*

maintainer-clean-generic:
	-@echo "This command is intended for maintainers to use;"
	-@echo "it deletes files that may require special tools to rebuild."
	-rm -f Makefile.in
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: xine_decoder.c ---
/* 
 * Copyright (C) 2000-2003 the xine project
 * 
 * This file is part of xine, a free video player.
 * 
 * xine 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.
 * 
 * xine 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 * $Id: xine_decoder.c,v 1.1 2005/04/04 22:32:48 dsalt-guest Exp $
 *
 * stuff needed to turn libmpeg2 into a xine decoder plugin
 */


#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define LOG_MODULE "mpeg2_decoder"
#define LOG_VERBOSE
/*
#define LOG
*/

#include "xine_internal.h"
#include "video_out.h"
#include "mpeg2.h"
#include "mpeg2_internal.h"
#include "buffer.h"

typedef struct {
  video_decoder_class_t   decoder_class;
} mpeg2_class_t;


typedef struct mpeg2dec_decoder_s {
  video_decoder_t  video_decoder;
  mpeg2dec_t       mpeg2;
  mpeg2_class_t   *class;
  xine_stream_t   *stream;
} mpeg2dec_decoder_t;

static void mpeg2dec_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
  mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen;

  lprintf ("decode_data, flags=0x%08x ...\n", buf->decoder_flags);

  /* handle aspect hints from xine-dvdnav */
  if (buf->decoder_flags & BUF_FLAG_SPECIAL) {
    if (buf->decoder_info[1] == BUF_SPECIAL_ASPECT) {
      this->mpeg2.force_aspect = buf->decoder_info[2];
      if (buf->decoder_info[3] == 0x1 && buf->decoder_info[2] == 3)
	/* letterboxing is denied, we have to do pan&scan */
	this->mpeg2.force_pan_scan = 1;
      else
	this->mpeg2.force_pan_scan = 0;
    }
    return;
  }
  
  if (buf->decoder_flags & BUF_FLAG_PREVIEW) {
    mpeg2_find_sequence_header (&this->mpeg2, buf->content, buf->content + buf->size);
  } else {
    
    mpeg2_decode_data (&this->mpeg2, buf->content, buf->content + buf->size,
		       buf->pts);
  }

  lprintf ("decode_data...done\n");
}

static void mpeg2dec_flush (video_decoder_t *this_gen) {
  mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen;

  lprintf ("flush\n");

  mpeg2_flush (&this->mpeg2);
}

static void mpeg2dec_reset (video_decoder_t *this_gen) {
  mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen;

  mpeg2_reset (&this->mpeg2);
}

static void mpeg2dec_discontinuity (video_decoder_t *this_gen) {
  mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen;

  mpeg2_discontinuity (&this->mpeg2);
}

static void mpeg2dec_dispose (video_decoder_t *this_gen) {

  mpeg2dec_decoder_t *this = (mpeg2dec_decoder_t *) this_gen;

  lprintf ("close\n");

  mpeg2_close (&this->mpeg2);

  this->stream->video_out->close(this->stream->video_out, this->stream);

  free (this);
}

static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) {
  mpeg2dec_decoder_t *this ;

  this = (mpeg2dec_decoder_t *) xine_xmalloc (sizeof (mpeg2dec_decoder_t));

  this->video_decoder.decode_data         = mpeg2dec_decode_data;
  this->video_decoder.flush               = mpeg2dec_flush;
  this->video_decoder.reset               = mpeg2dec_reset;
  this->video_decoder.discontinuity       = mpeg2dec_discontinuity;
  this->video_decoder.dispose             = mpeg2dec_dispose;
  this->stream                            = stream;
  this->class                             = (mpeg2_class_t *) class_gen;
  this->mpeg2.stream = stream;

  mpeg2_init (&this->mpeg2, stream->video_out);
  stream->video_out->open(stream->video_out, stream);
  this->mpeg2.force_aspect = this->mpeg2.force_pan_scan = 0;

  return &this->video_decoder;
}

/*
 * mpeg2 plugin class
 */

static char *get_identifier (video_decoder_class_t *this) {
  return "mpeg2dec";
}

static char *get_description (video_decoder_class_t *this) {
  return "mpeg2 based video decoder plugin";
}

static void dispose_class (video_decoder_class_t *this) {
  free (this);
}

static void *init_plugin (xine_t *xine, void *data) {

  mpeg2_class_t *this;

  this = (mpeg2_class_t *) xine_xmalloc (sizeof (mpeg2_class_t));

  this->decoder_class.open_plugin     = open_plugin;
  this->decoder_class.get_identifier  = get_identifier;
  this->decoder_class.get_description = get_description;
  this->decoder_class.dispose         = dispose_class;

  return this;
}
/*
 * exported plugin catalog entry
 */

static uint32_t supported_types[] = { BUF_VIDEO_MPEG, 0 };

static decoder_info_t dec_info_mpeg2 = {
  supported_types,     /* supported types */
  7                    /* priority        */
};

plugin_info_t xine_plugin_info[] = {
  /* type, API, "name", version, special_info, init_function */  
  { PLUGIN_VIDEO_DECODER, 18, "mpeg2", XINE_VERSION_CODE, &dec_info_mpeg2, init_plugin },
  { PLUGIN_NONE, 0, "", 0, NULL, NULL }
};

--- NEW FILE: motion_comp_vis.c ---
/*
 * motion_comp_vis.c
 * Copyright (C) 2003 David S. Miller <davem@redhat.com>
 *
 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
 * See http://libmpeg2.sourceforge.net/ for updates.
 *
 * mpeg2dec 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.
 *
 * mpeg2dec 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 this program; if not, write to the Free Software
[...2020 lines suppressed...]
		vis_padd16(REF_S6, TMP24, TMP14);

		vis_padd16(TMP12, TMP26, TMP12);

		vis_padd16(TMP14, TMP28, TMP14);

		vis_padd16(TMP12, REF_0, TMP12);

		vis_padd16(TMP14, REF_2, TMP14);
		vis_pack16(TMP12, DST_2);

		vis_pack16(TMP14, DST_3);
		vis_st64(DST_2, dest[0]);
		dest += stride;
	} while (--height);
}

MPEG2_MC_EXTERN(vis);

#endif  /* defined(ARCH_SPARC) && defined(ENABLE_VIS) */

--- NEW FILE: idct_mlib.h ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: slice_xvmc_vld.c ---
/*
 * Copyright (c) 2004 The Unichrome project. All rights reserved.
 *
 * This program 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, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTIES OR REPRESENTATIONS; 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
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 */

#include "xine_internal.h"
#include "video_out.h"
#include "mpeg2.h"
#include "mpeg2_internal.h"
#include "xvmc_vld.h"

static uint8_t zig_zag_scan[64] ATTR_ALIGN(16) =
{
    /* Zig-Zag scan pattern */
     0, 1, 8,16, 9, 2, 3,10,
    17,24,32,25,18,11, 4, 5,
    12,19,26,33,40,48,41,34,
    27,20,13, 6, 7,14,21,28,
    35,42,49,56,57,50,43,36,
    29,22,15,23,30,37,44,51,
    58,59,52,45,38,31,39,46,
    53,60,61,54,47,55,62,63
};

static uint8_t alternate_scan [64] ATTR_ALIGN(16) =
{
    /* Alternate scan pattern */
    0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
    41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
    51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
    53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
};




void mpeg2_xxmc_choose_coding(mpeg2dec_t *mpeg2dec, picture_t *picture,
			      double aspect_ratio, int flags) 
{
  int
    decoder_format = mpeg2dec->frame_format; 

  if (picture->current_frame) {
    if (XINE_IMGFMT_XXMC == decoder_format) {
      xine_xxmc_t *xxmc = (xine_xxmc_t *) 
	picture->current_frame->accel_data;
      
      /*
       * Make a request for acceleration type and mpeg coding from
       * the output plugin.
       */
      
      xxmc->fallback_format = XINE_IMGFMT_YV12;
      xxmc->acceleration = XINE_XVMC_ACCEL_VLD| XINE_XVMC_ACCEL_IDCT
	| XINE_XVMC_ACCEL_MOCOMP ;

      /*
       * Standard MOCOMP / IDCT XvMC implementation for interlaced streams 
       * is buggy. The bug is inherited from the old XvMC driver. Don't use it until
       * it has been fixed. (A volunteer ?)
       */

      if ( picture->picture_structure != 3 ) {
	xxmc->acceleration &= ~( XINE_XVMC_ACCEL_IDCT | XINE_XVMC_ACCEL_MOCOMP );
      } 

      xxmc->mpeg = (picture->mpeg1) ? XINE_XVMC_MPEG_1:XINE_XVMC_MPEG_2;
      xxmc->proc_xxmc_update_frame (picture->current_frame->driver, 
				    picture->current_frame,
				    picture->coded_picture_width,
				    picture->coded_picture_height,
				    aspect_ratio,
				    XINE_IMGFMT_XXMC,flags);
    }
  }
}
  

void mpeg2_xxmc_slice( mpeg2dec_t *mpeg2dec, picture_t *picture, int code,
		       uint8_t *buffer) 
{
  vo_frame_t
    *frame = picture->current_frame;
  xine_xxmc_t 
    *xxmc = (xine_xxmc_t *) frame->accel_data;
  xine_vld_frame_t 
    *vft = &xxmc->vld_frame;
  unsigned
    mb_frame_height;
  int 
    i;
  const uint8_t *
    scan_pattern;
  float
    ms_per_slice;

  if (1 == code) {
    frame->bad_frame = 1;

    /*
     * Check that first field went through OK. Otherwise,
     * indicate bad frame. 
     */
    
    if (picture->second_field) {
      mpeg2dec->xvmc_last_slice_code = (xxmc->decoded) ? 0 : -1;
      xxmc->decoded = 0;
    } else {
      mpeg2dec->xvmc_last_slice_code = 0;
    }

    mb_frame_height =
      (!(picture->mpeg1) && (picture->progressive_sequence)) ?
      2*((picture->coded_picture_height+31) >> 5) :
      (picture->coded_picture_height+15) >> 4;
    mpeg2dec->xxmc_mb_pic_height = (picture->picture_structure == FRAME_PICTURE ) ?
      mb_frame_height : mb_frame_height >> 1;

    ms_per_slice = 1000. / (90000. * mb_frame_height) * frame->duration;
    xxmc->sleep = 1. / (ms_per_slice * 0.45); 
    if (xxmc->sleep < 1.) xxmc->sleep = 1.;

    if (picture->mpeg1) {
      vft->mv_ranges[0][0] = picture->b_motion.f_code[0];
      vft->mv_ranges[0][1] = picture->b_motion.f_code[0];
      vft->mv_ranges[1][0] = picture->f_motion.f_code[0];
      vft->mv_ranges[1][1] = picture->f_motion.f_code[0];
    } else {
      vft->mv_ranges[0][0] = picture->b_motion.f_code[0];
      vft->mv_ranges[0][1] = picture->b_motion.f_code[1];
      vft->mv_ranges[1][0] = picture->f_motion.f_code[0];
      vft->mv_ranges[1][1] = picture->f_motion.f_code[1];
    }

    vft->picture_structure = picture->picture_structure;
    vft->picture_coding_type = picture->picture_coding_type;
    vft->mpeg_coding = (picture->mpeg1) ? 0 : 1;
    vft->progressive_sequence = picture->progressive_sequence;
    vft->scan = (picture->scan == mpeg2_scan_alt);
    vft->pred_dct_frame = picture->frame_pred_frame_dct;
    vft->concealment_motion_vectors = 
      picture->concealment_motion_vectors;
    vft->q_scale_type = picture->q_scale_type;
    vft->intra_vlc_format = picture->intra_vlc_format;
    vft->intra_dc_precision = picture->intra_dc_precision;
    vft->second_field = picture->second_field;

    /*
     * Translation of libmpeg2's Q-matrix layout to VLD XvMC's. 
     * Errors here will give
     * blocky artifacts and sometimes wrong colors.
     */

    scan_pattern = (vft->scan) ? alternate_scan : zig_zag_scan;

    if ((vft->load_intra_quantizer_matrix = picture->load_intra_quantizer_matrix)) {
      for (i=0; i<64; ++i) {
	vft->intra_quantizer_matrix[scan_pattern[i]] = 
	  picture->intra_quantizer_matrix[picture->scan[i]]; 
      }
    }      

    if ((vft->load_non_intra_quantizer_matrix = picture->load_non_intra_quantizer_matrix)) {
      for (i=0; i<64; ++i) {
	vft->non_intra_quantizer_matrix[scan_pattern[i]] = 
	  picture->non_intra_quantizer_matrix[picture->scan[i]];
      }
    }

    picture->load_intra_quantizer_matrix = 0;
    picture->load_non_intra_quantizer_matrix = 0;
    vft->forward_reference_frame = picture->forward_reference_frame;
    vft->backward_reference_frame = picture->backward_reference_frame;
    xxmc->proc_xxmc_begin( frame ); 
    if (xxmc->result != 0) {
      xxmc->proc_xxmc_flush( frame );
      mpeg2dec->xvmc_last_slice_code=-1;
    }
  }
  
  if ((code == mpeg2dec->xvmc_last_slice_code + 1) &&
      code <= mpeg2dec->xxmc_mb_pic_height) {

    /*
     * Send this slice to the output plugin. May stall for a long
     * time in proc_slice;
     */

    frame->bad_frame = 1;
    xxmc->slice_data_size = mpeg2dec->chunk_size;
    xxmc->slice_data = mpeg2dec->chunk_buffer;
    xxmc->slice_code = code;
    
    xxmc->proc_xxmc_slice( frame );       
    if (xxmc->result != 0) {
	xxmc->proc_xxmc_flush( frame );
	mpeg2dec->xvmc_last_slice_code=-1;
	return;
    }
    
    if (code == mpeg2dec->xxmc_mb_pic_height) {

	/*
	 * We've encountered the last slice of this frame.
	 * Release the decoder for a new frame and, if all
	 * went well, tell libmpeg2 that we are ready. 
	 */

      mpeg2_xxmc_vld_frame_complete(mpeg2dec,picture,code); 
      return;
    } else {

	/*
	 * Keep track of slices.
	 */ 

	mpeg2dec->xvmc_last_slice_code++;
      }

    } else  {

    /*
     * An error has occured.
     */

    lprintf("libmpeg2: VLD XvMC: Slice error.\n");
    mpeg2dec->xvmc_last_slice_code = -1;
    xxmc->proc_xxmc_flush( frame );
    return;
  }
}

void mpeg2_xxmc_vld_frame_complete(mpeg2dec_t *mpeg2dec, picture_t *picture, int code) 
{
  vo_frame_t
    *frame = picture->current_frame;
  xine_xxmc_t 
    *xxmc = (xine_xxmc_t *) frame->accel_data;
  
  if (xxmc->decoded) return;
  if (mpeg2dec->xvmc_last_slice_code >= 1) {
    xxmc->proc_xxmc_flush( frame );
    if (xxmc->result) {
      mpeg2dec->xvmc_last_slice_code=-1;
      return;
    }
    xxmc->decoded = 1;
    mpeg2dec->xvmc_last_slice_code++;
    if (picture->picture_structure == 3 || picture->second_field) {
      if (xxmc->result == 0) 
	frame->bad_frame = 0;
    } 
  }
}