summaryrefslogtreecommitdiff
path: root/src/libmpeg2
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmpeg2')
-rw-r--r--src/libmpeg2/Makefile.am3
-rw-r--r--src/libmpeg2/decode.c58
-rw-r--r--src/libmpeg2/idct.c33
-rw-r--r--src/libmpeg2/idct_mlib.c5
-rw-r--r--src/libmpeg2/idct_mmx.c14
-rw-r--r--src/libmpeg2/mpeg2.h7
-rw-r--r--src/libmpeg2/mpeg2_internal.h43
-rw-r--r--src/libmpeg2/slice_xvmc.c2066
-rw-r--r--src/libmpeg2/xine_decoder.c4
9 files changed, 2210 insertions, 23 deletions
diff --git a/src/libmpeg2/Makefile.am b/src/libmpeg2/Makefile.am
index d84b43780..7e5dbeb15 100644
--- a/src/libmpeg2/Makefile.am
+++ b/src/libmpeg2/Makefile.am
@@ -21,10 +21,11 @@ xineplug_decode_mpeg2_la_SOURCES = \
motion_comp_mmx.c \
motion_comp_mlib.c \
slice.c \
+ slice_xvmc.c \
stats.c \
xine_decoder.c
xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB)
xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@
-noinst_HEADERS = vlc.h mpeg2.h mpeg2_internal.h
+noinst_HEADERS = vlc.h mpeg2.h mpeg2_internal.h
diff --git a/src/libmpeg2/decode.c b/src/libmpeg2/decode.c
index 0f9742fe4..a55c069a8 100644
--- a/src/libmpeg2/decode.c
+++ b/src/libmpeg2/decode.c
@@ -50,7 +50,8 @@
static void process_userdata(mpeg2dec_t *mpeg2dec, uint8_t *buffer);
-void mpeg2_init (mpeg2dec_t * mpeg2dec)
+void mpeg2_init (mpeg2dec_t * mpeg2dec,
+ xine_video_port_t * output)
{
static int do_init = 1;
uint32_t mm_accel;
@@ -71,11 +72,13 @@ void mpeg2_init (mpeg2dec_t * mpeg2dec)
(void**)&mpeg2dec->picture_base);
mpeg2dec->shift = 0xffffff00;
+ mpeg2dec->new_sequence = 0;
mpeg2dec->is_sequence_needed = 1;
mpeg2dec->is_wait_for_ip_frames = 2;
mpeg2dec->frames_to_drop = 0;
mpeg2dec->drop_frame = 0;
mpeg2dec->in_slice = 0;
+ mpeg2dec->output = output;
mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
mpeg2dec->code = 0xb4;
mpeg2dec->seek_mode = 0;
@@ -84,6 +87,13 @@ void mpeg2_init (mpeg2dec_t * mpeg2dec)
/* initialize substructures */
mpeg2_header_state_init (mpeg2dec->picture);
+
+ if( output->get_capabilities(output) & VO_CAP_XVMC_MOCOMP ) {
+ printf("libmpeg2: output port has XvMC capability\n");
+ mpeg2dec->frame_format = XINE_IMGFMT_XVMC;
+ } else {
+ mpeg2dec->frame_format = XINE_IMGFMT_YV12;
+ }
}
static inline void get_frame_duration (mpeg2dec_t * mpeg2dec, vo_frame_t *frame)
@@ -400,6 +410,11 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
break;
}
if (mpeg2dec->force_aspect) picture->aspect_ratio_information = mpeg2dec->force_aspect;
+
+ if (mpeg2dec->is_sequence_needed ) {
+ mpeg2dec->new_sequence = 1;
+ }
+
if (mpeg2dec->is_sequence_needed
|| (picture->frame_width != picture->coded_picture_width)
|| (picture->frame_height != picture->coded_picture_height)) {
@@ -465,7 +480,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
if (!(mpeg2dec->in_slice)) {
mpeg2dec->in_slice = 1;
-
+
if (picture->second_field) {
if (picture->current_frame)
picture->current_frame->field(picture->current_frame,
@@ -475,6 +490,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
} else {
int flags = VO_INTERLACED_FLAG | picture->picture_structure;
if (mpeg2dec->force_pan_scan) flags |= VO_PAN_SCAN_FLAG;
+ if (mpeg2dec->new_sequence) flags |= VO_NEW_SEQUENCE_FLAG;
if ( picture->current_frame &&
picture->current_frame != picture->backward_reference_frame &&
@@ -487,7 +503,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
picture->coded_picture_width,
picture->coded_picture_height,
get_aspect_ratio(mpeg2dec),
- XINE_IMGFMT_YV12,
+ mpeg2dec->frame_format,
flags);
else {
picture->current_frame =
@@ -495,7 +511,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
picture->coded_picture_width,
picture->coded_picture_height,
get_aspect_ratio(mpeg2dec),
- XINE_IMGFMT_YV12,
+ mpeg2dec->frame_format,
flags);
if (picture->forward_reference_frame &&
picture->forward_reference_frame != picture->backward_reference_frame)
@@ -505,6 +521,11 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
picture->backward_reference_frame;
picture->backward_reference_frame = picture->current_frame;
}
+ if(mpeg2dec->new_sequence)
+ {
+ picture->mc = picture->current_frame->macroblocks;
+ mpeg2dec->new_sequence = 0;
+ }
picture->current_frame->bad_frame = 1;
picture->current_frame->drawn = 0;
picture->current_frame->pts = mpeg2dec->pts;
@@ -512,6 +533,21 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
picture->current_frame->repeat_first_field = picture->repeat_first_field;
picture->current_frame->progressive_frame = picture->progressive_frame;
+ switch( picture->picture_coding_type ) {
+ case I_TYPE:
+ picture->current_frame->picture_coding_type = XINE_PICT_I_TYPE;
+ break;
+ case P_TYPE:
+ picture->current_frame->picture_coding_type = XINE_PICT_P_TYPE;
+ break;
+ case B_TYPE:
+ picture->current_frame->picture_coding_type = XINE_PICT_B_TYPE;
+ break;
+ case D_TYPE:
+ picture->current_frame->picture_coding_type = XINE_PICT_D_TYPE;
+ break;
+ }
+
#ifdef LOG
printf ("libmpeg2: decoding frame %d, type %s\n",
picture->current_frame->id, picture->picture_coding_type == I_TYPE ? "I" :
@@ -522,7 +558,17 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
}
if (!mpeg2dec->drop_frame && picture->current_frame != NULL) {
- mpeg2_slice (picture, code, buffer);
+#ifdef DEBUG_LOG
+ printf("slice target %08x past %08x future %08x\n",picture->current_frame,picture->forward_reference_frame,picture->backward_reference_frame);
+ fflush(stdout);
+#endif
+
+ if(picture->mc && picture->mc->xvmc_accel) {
+ mpeg2_xvmc_slice (picture, code, buffer);
+
+ } else {
+ mpeg2_slice (picture, code, buffer);
+ }
if( picture->v_offset > picture->limit_y ) {
picture->current_frame->bad_frame = 0;
@@ -796,6 +842,8 @@ void mpeg2_find_sequence_header (mpeg2dec_t * mpeg2dec,
if (mpeg2dec->is_sequence_needed) {
xine_event_t event;
xine_format_change_data_t data;
+
+ mpeg2dec->new_sequence = 1;
mpeg2dec->is_sequence_needed = 0;
picture->frame_width = picture->coded_picture_width;
diff --git a/src/libmpeg2/idct.c b/src/libmpeg2/idct.c
index 645fc03c1..d2b3ed866 100644
--- a/src/libmpeg2/idct.c
+++ b/src/libmpeg2/idct.c
@@ -55,9 +55,11 @@
#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
-/* idct main entry point */
+/* 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)])
@@ -260,8 +262,26 @@ static void mpeg2_idct_add_c (int16_t * block, uint8_t * dest, int stride)
} 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
@@ -269,13 +289,17 @@ void mpeg2_idct_init (uint32_t mm_accel)
#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_add = mpeg2_idct_add_mmx;
+ mpeg2_idct = mpeg2_idct_mmx;
+ mpeg2_zero_block = mpeg2_zero_block_mmx;
mpeg2_idct_mmx_init ();
} else
#endif
@@ -287,6 +311,7 @@ void mpeg2_idct_init (uint32_t mm_accel)
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
@@ -295,6 +320,7 @@ void mpeg2_idct_init (uint32_t mm_accel)
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");
@@ -314,7 +340,8 @@ void mpeg2_idct_init (uint32_t mm_accel)
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_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);
}
diff --git a/src/libmpeg2/idct_mlib.c b/src/libmpeg2/idct_mlib.c
index bfafd07b1..bb1aad9a8 100644
--- a/src/libmpeg2/idct_mlib.c
+++ b/src/libmpeg2/idct_mlib.c
@@ -54,4 +54,9 @@ void mpeg2_idct_add_mlib_non_ieee (int16_t * block, uint8_t * dest, int stride)
memset (block, 0, 64 * sizeof (uint16_t));
}
+void mpeg2_idct_mlib (int16_t * block)
+{
+ mlib_VideoIDCT_IEEE_S16_S16 (block, block);
+}
+
#endif
diff --git a/src/libmpeg2/idct_mmx.c b/src/libmpeg2/idct_mmx.c
index bee54e83b..78ab3c547 100644
--- a/src/libmpeg2/idct_mmx.c
+++ b/src/libmpeg2/idct_mmx.c
@@ -691,6 +691,10 @@ void mpeg2_idct_add_mmxext (int16_t * block, uint8_t * dest, int 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)
@@ -709,6 +713,16 @@ void mpeg2_idct_add_mmx (int16_t * block, uint8_t * dest, int 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)
{
extern uint8_t mpeg2_scan_norm[64];
diff --git a/src/libmpeg2/mpeg2.h b/src/libmpeg2/mpeg2.h
index 2fdbacdce..b6500d1ef 100644
--- a/src/libmpeg2/mpeg2.h
+++ b/src/libmpeg2/mpeg2.h
@@ -22,10 +22,14 @@
/* Structure for the mpeg2dec decoder */
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;
@@ -56,7 +60,8 @@ typedef struct mpeg2dec_s {
/* initialize mpegdec with a opaque user pointer */
-void mpeg2_init (mpeg2dec_t * mpeg2dec);
+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);
diff --git a/src/libmpeg2/mpeg2_internal.h b/src/libmpeg2/mpeg2_internal.h
index 5beea9844..069fc9dc1 100644
--- a/src/libmpeg2/mpeg2_internal.h
+++ b/src/libmpeg2/mpeg2_internal.h
@@ -21,13 +21,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "video_out.h"
+
/* macroblock modes */
-#define MACROBLOCK_INTRA 1
-#define MACROBLOCK_PATTERN 2
-#define MACROBLOCK_MOTION_BACKWARD 4
-#define MACROBLOCK_MOTION_FORWARD 8
-#define MACROBLOCK_QUANT 16
-#define DCT_TYPE_INTERLACED 32
+#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
@@ -37,16 +40,16 @@
#define MC_DMV (3*64)
/* picture structure */
-#define TOP_FIELD 1
-#define BOTTOM_FIELD 2
-#define FRAME_PICTURE 3
+#define TOP_FIELD VO_TOP_FIELD
+#define BOTTOM_FIELD VO_BOTTOM_FIELD
+#define FRAME_PICTURE VO_BOTH_FIELDS
-/* picture coding type */
+/* 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];
@@ -61,6 +64,17 @@ typedef struct picture_s {
/* 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 */
@@ -198,12 +212,16 @@ 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 */
@@ -236,5 +254,8 @@ extern mpeg2_mc_t mpeg2_mc_mlib;
/* slice.c */
void mpeg2_slice (picture_t * picture, int code, uint8_t * buffer);
+/* slice_xvmc.c */
+void mpeg2_xvmc_slice (picture_t * picture, int code, uint8_t * buffer);
+
/* stats.c */
void mpeg2_stats (int code, uint8_t * buffer);
diff --git a/src/libmpeg2/slice_xvmc.c b/src/libmpeg2/slice_xvmc.c
new file mode 100644
index 000000000..3e63bd77b
--- /dev/null
+++ b/src/libmpeg2/slice_xvmc.c
@@ -0,0 +1,2066 @@
+/*
+ * 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
+ * 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 <string.h> /* memcpy/memset, try to remove */
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xine_internal.h"
+#include "video_out.h"
+#include "mpeg2_internal.h"
+#include "xineutils.h"
+
+#include "attributes.h"
+
+
+#define MOTION_ACCEL XINE_VO_MOTION_ACCEL
+#define IDCT_ACCEL XINE_VO_IDCT_ACCEL
+#define SIGNED_INTRA XINE_VO_SIGNED_INTRA
+#define ACCEL (MOTION_ACCEL | IDCT_ACCEL)
+
+
+extern mpeg2_mc_t mpeg2_mc;
+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_cpu_state_save) (cpu_state_t * state);
+extern void (* mpeg2_cpu_state_restore) (cpu_state_t * state);
+extern void (* mpeg2_zero_block) (int16_t * block);
+
+#include "vlc.h"
+
+extern uint8_t mpeg2_scan_norm[64];
+extern uint8_t mpeg2_scan_alt[64];
+
+/* original (non-patched) scan tables */
+static uint8_t mpeg2_scan_norm_orig[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_orig[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
+};
+
+
+static int non_linear_quantizer_scale [] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 10, 12, 14, 16, 18, 20, 22,
+ 24, 28, 32, 36, 40, 44, 48, 52,
+ 56, 64, 72, 80, 88, 96, 104, 112
+};
+
+static inline int get_xvmc_macroblock_modes (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int macroblock_modes;
+ MBtab * tab;
+
+ switch (picture->picture_coding_type) {
+ case I_TYPE:
+
+ tab = MB_I + UBITS (bit_buf, 1);
+ DUMPBITS (bit_buf, bits, tab->len);
+ macroblock_modes = tab->modes;
+
+ if ((! (picture->frame_pred_frame_dct)) &&
+ (picture->picture_structure == FRAME_PICTURE)) {
+ macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+ DUMPBITS (bit_buf, bits, 1);
+ }
+
+ return macroblock_modes;
+
+ case P_TYPE:
+
+ tab = MB_P + UBITS (bit_buf, 5);
+ DUMPBITS (bit_buf, bits, tab->len);
+ macroblock_modes = tab->modes;
+
+ if (picture->picture_structure != FRAME_PICTURE) {
+ if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+ macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+ DUMPBITS (bit_buf, bits, 2);
+ }
+ return macroblock_modes;
+ } else if (picture->frame_pred_frame_dct) {
+ if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
+ macroblock_modes |= MC_FRAME;
+ return macroblock_modes;
+ } else {
+ if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+ macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+ DUMPBITS (bit_buf, bits, 2);
+ }
+ if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+ macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+ DUMPBITS (bit_buf, bits, 1);
+ }
+ return macroblock_modes;
+ }
+
+ case B_TYPE:
+
+ tab = MB_B + UBITS (bit_buf, 6);
+ DUMPBITS (bit_buf, bits, tab->len);
+ macroblock_modes = tab->modes;
+
+ if (picture->picture_structure != FRAME_PICTURE) {
+ if (! (macroblock_modes & MACROBLOCK_INTRA)) {
+ macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+ DUMPBITS (bit_buf, bits, 2);
+ }
+ return macroblock_modes;
+ } else if (picture->frame_pred_frame_dct) {
+ /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */
+ macroblock_modes |= MC_FRAME;
+ return macroblock_modes;
+ } else {
+ if (macroblock_modes & MACROBLOCK_INTRA)
+ goto intra;
+ macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+ DUMPBITS (bit_buf, bits, 2);
+ if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+ intra:
+ macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+ DUMPBITS (bit_buf, bits, 1);
+ }
+ return macroblock_modes;
+ }
+
+ case D_TYPE:
+
+ DUMPBITS (bit_buf, bits, 1);
+ return MACROBLOCK_INTRA;
+
+ default:
+ return 0;
+ }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_xvmc_quantizer_scale (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+
+ int quantizer_scale_code;
+
+ quantizer_scale_code = UBITS (bit_buf, 5);
+ DUMPBITS (bit_buf, bits, 5);
+
+ if (picture->q_scale_type)
+ return non_linear_quantizer_scale [quantizer_scale_code];
+ else
+ return quantizer_scale_code << 1;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_xvmc_motion_delta (picture_t * picture, int f_code)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+
+ int delta;
+ int sign;
+ MVtab * tab;
+
+ if (bit_buf & 0x80000000) {
+ DUMPBITS (bit_buf, bits, 1);
+ return 0;
+ } else if (bit_buf >= 0x0c000000) {
+
+ tab = MV_4 + UBITS (bit_buf, 4);
+ delta = (tab->delta << f_code) + 1;
+ bits += tab->len + f_code + 1;
+ bit_buf <<= tab->len;
+
+ sign = SBITS (bit_buf, 1);
+ bit_buf <<= 1;
+
+ if (f_code)
+ delta += UBITS (bit_buf, f_code);
+ bit_buf <<= f_code;
+
+ return (delta ^ sign) - sign;
+
+ } else {
+
+ tab = MV_10 + UBITS (bit_buf, 10);
+ delta = (tab->delta << f_code) + 1;
+ bits += tab->len + 1;
+ bit_buf <<= tab->len;
+
+ sign = SBITS (bit_buf, 1);
+ bit_buf <<= 1;
+
+ if (f_code) {
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ delta += UBITS (bit_buf, f_code);
+ DUMPBITS (bit_buf, bits, f_code);
+ }
+
+ return (delta ^ sign) - sign;
+
+ }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int bound_motion_vector (int vector, int f_code)
+{
+#if 1
+ unsigned int limit;
+ int sign;
+
+ limit = 16 << f_code;
+
+ if ((unsigned int)(vector + limit) < 2 * limit)
+ return vector;
+ else {
+ sign = ((int32_t)vector) >> 31;
+ return vector - ((2 * limit) ^ sign) + sign;
+ }
+#else
+ return ((int32_t)vector << (27 - f_code)) >> (27 - f_code);
+#endif
+}
+
+static inline int get_xvmc_dmv (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+
+ DMVtab * tab;
+
+ tab = DMV_2 + UBITS (bit_buf, 2);
+ DUMPBITS (bit_buf, bits, tab->len);
+ return tab->dmv;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_xvmc_coded_block_pattern (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+
+ CBPtab * tab;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ if (bit_buf >= 0x20000000) {
+
+ tab = CBP_7 + (UBITS (bit_buf, 7) - 16);
+ DUMPBITS (bit_buf, bits, tab->len);
+ return tab->cbp;
+
+ } else {
+
+ tab = CBP_9 + UBITS (bit_buf, 9);
+ DUMPBITS (bit_buf, bits, tab->len);
+ return tab->cbp;
+ }
+
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_xvmc_luma_dc_dct_diff (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ DCtab * tab;
+ int size;
+ int dc_diff;
+
+ if (bit_buf < 0xf8000000) {
+ tab = DC_lum_5 + UBITS (bit_buf, 5);
+ size = tab->size;
+ if (size) {
+ bits += tab->len + size;
+ bit_buf <<= tab->len;
+ dc_diff =
+ UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+ bit_buf <<= size;
+ return dc_diff;
+ } else {
+ DUMPBITS (bit_buf, bits, 3);
+ return 0;
+ }
+ } else {
+ tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0);
+ size = tab->size;
+ DUMPBITS (bit_buf, bits, tab->len);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+ DUMPBITS (bit_buf, bits, size);
+ return dc_diff;
+ }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_xvmc_chroma_dc_dct_diff (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ DCtab * tab;
+ int size;
+ int dc_diff;
+
+ if (bit_buf < 0xf8000000) {
+ tab = DC_chrom_5 + UBITS (bit_buf, 5);
+ size = tab->size;
+ if (size) {
+ bits += tab->len + size;
+ bit_buf <<= tab->len;
+ dc_diff =
+ UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+ bit_buf <<= size;
+ return dc_diff;
+ } else {
+ DUMPBITS (bit_buf, bits, 2);
+ return 0;
+ }
+ } else {
+ tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0);
+ size = tab->size;
+ DUMPBITS (bit_buf, bits, tab->len + 1);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+ DUMPBITS (bit_buf, bits, size);
+ return dc_diff;
+ }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+#define SATURATE(val) \
+do { \
+ if ((uint32_t)(val + 2048) > 4095) \
+ val = (val > 0) ? 2047 : -2048; \
+} while (0)
+
+static void get_xvmc_intra_block_B14 (picture_t * picture)
+{
+ int i;
+ int j;
+ int val;
+ uint8_t * scan = picture->scan;
+ uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+ int quantizer_scale = picture->quantizer_scale;
+ int mismatch;
+ DCTtab * tab;
+ uint32_t bit_buf;
+ int bits;
+ uint8_t * bit_ptr;
+ int16_t * dest;
+
+ dest = picture->mc->blockptr;
+
+ /* XvMC's IDCT must use non-patched scan tables */
+ if( picture->mc->xvmc_accel & IDCT_ACCEL ) {
+ if( scan == mpeg2_scan_norm )
+ scan = mpeg2_scan_norm_orig;
+ else
+ scan = mpeg2_scan_alt_orig;
+ }
+
+ i = 0;
+ mismatch = ~dest[0];
+
+ bit_buf = picture->bitstream_buf;
+ bits = picture->bitstream_bits;
+ bit_ptr = picture->bitstream_ptr;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ while (1) {
+ if (bit_buf >= 0x28000000) {
+
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
+
+ i += tab->run;
+ if (i >= 64)
+ break; /* end of block */
+
+ normal_code:
+ j = scan[i];
+ bit_buf <<= tab->len;
+ bits += tab->len + 1;
+ val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+ /* if (bitstream_get (1)) val = -val; */
+ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+ SATURATE (val);
+ dest[j] = val;
+ mismatch ^= val;
+
+ bit_buf <<= 1;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x04000000) {
+
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
+
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+
+ /* escape code */
+
+ i += UBITS (bit_buf << 6, 6) - 64;
+ if (i >= 64)
+ break; /* illegal, check needed to avoid buffer overflow */
+
+ j = scan[i];
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ val = (SBITS (bit_buf, 12) *
+ quantizer_scale * quant_matrix[j]) / 16;
+
+ SATURATE (val);
+ dest[j] = val;
+ mismatch ^= val;
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x02000000) {
+ tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00800000) {
+ tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00200000) {
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else {
+ tab = DCT_16 + UBITS (bit_buf, 16);
+ bit_buf <<= 16;
+ GETWORD (bit_buf, bits + 16, bit_ptr);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ }
+ break; /* illegal, check needed to avoid buffer overflow */
+ }
+
+ dest[63] ^= mismatch & 1;
+ DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ picture->bitstream_buf = bit_buf;
+ picture->bitstream_bits = bits;
+ picture->bitstream_ptr = bit_ptr;
+}
+
+static void get_xvmc_intra_block_B15 (picture_t * picture)
+{
+ int i;
+ int j;
+ int val;
+ uint8_t * scan = picture->scan;
+ uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+ int quantizer_scale = picture->quantizer_scale;
+ int mismatch;
+ DCTtab * tab;
+ uint32_t bit_buf;
+ int bits;
+ uint8_t * bit_ptr;
+ int16_t * dest;
+
+ dest = picture->mc->blockptr;
+
+ /* XvMC's IDCT must use non-patched scan tables */
+ if( picture->mc->xvmc_accel & IDCT_ACCEL ) {
+ if( scan == mpeg2_scan_norm )
+ scan = mpeg2_scan_norm_orig;
+ else
+ scan = mpeg2_scan_alt_orig;
+ }
+
+ i = 0;
+ mismatch = ~dest[0];
+
+ bit_buf = picture->bitstream_buf;
+ bits = picture->bitstream_bits;
+ bit_ptr = picture->bitstream_ptr;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ while (1) {
+ if (bit_buf >= 0x04000000) {
+
+ tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4);
+
+ i += tab->run;
+ if (i < 64) {
+
+ normal_code:
+ j = scan[i];
+ bit_buf <<= tab->len;
+ bits += tab->len + 1;
+ val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+ /* if (bitstream_get (1)) val = -val; */
+ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+ SATURATE (val);
+ dest[j] = val;
+ mismatch ^= val;
+
+ bit_buf <<= 1;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else {
+
+ /* end of block. I commented out this code because if we */
+ /* dont exit here we will still exit at the later test :) */
+
+ /* if (i >= 128) break; */ /* end of block */
+
+ /* escape code */
+
+ i += UBITS (bit_buf << 6, 6) - 64;
+ if (i >= 64)
+ break; /* illegal, check against buffer overflow */
+
+ j = scan[i];
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ val = (SBITS (bit_buf, 12) *
+ quantizer_scale * quant_matrix[j]) / 16;
+
+ SATURATE (val);
+
+ dest[j] = val;
+ mismatch ^= val;
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ }
+ } else if (bit_buf >= 0x02000000) {
+ tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00800000) {
+ tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00200000) {
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else {
+ tab = DCT_16 + UBITS (bit_buf, 16);
+ bit_buf <<= 16;
+ GETWORD (bit_buf, bits + 16, bit_ptr);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ }
+ break; /* illegal, check needed to avoid buffer overflow */
+ }
+
+ dest[63] ^= mismatch & 1;
+ DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
+ picture->bitstream_buf = bit_buf;
+ picture->bitstream_bits = bits;
+ picture->bitstream_ptr = bit_ptr;
+}
+
+static void get_xvmc_non_intra_block (picture_t * picture)
+{
+ int i;
+ int j;
+ int val;
+ uint8_t * scan = picture->scan;
+ uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
+ int quantizer_scale = picture->quantizer_scale;
+ int mismatch;
+ DCTtab * tab;
+ uint32_t bit_buf;
+ int bits;
+ uint8_t * bit_ptr;
+ int16_t * dest;
+
+ i = -1;
+ mismatch = 1;
+
+ dest = picture->mc->blockptr;
+
+ /* XvMC's IDCT must use non-patched scan tables */
+ if( picture->mc->xvmc_accel & IDCT_ACCEL ) {
+ if( scan == mpeg2_scan_norm )
+ scan = mpeg2_scan_norm_orig;
+ else
+ scan = mpeg2_scan_alt_orig;
+ }
+
+ bit_buf = picture->bitstream_buf;
+ bits = picture->bitstream_bits;
+ bit_ptr = picture->bitstream_ptr;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ if (bit_buf >= 0x28000000) {
+ tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
+ goto entry_1;
+ } else
+ goto entry_2;
+
+ while (1) {
+ if (bit_buf >= 0x28000000) {
+
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
+
+ entry_1:
+ i += tab->run;
+ if (i >= 64)
+ break; /* end of block */
+
+ normal_code:
+ j = scan[i];
+ bit_buf <<= tab->len;
+ bits += tab->len + 1;
+ val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
+
+ /* if (bitstream_get (1)) val = -val; */
+ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+ SATURATE (val);
+ dest[j] = val;
+ mismatch ^= val;
+
+ bit_buf <<= 1;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ }
+
+ entry_2:
+ if (bit_buf >= 0x04000000) {
+
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
+
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+
+ /* escape code */
+
+ i += UBITS (bit_buf << 6, 6) - 64;
+ if (i >= 64)
+ break; /* illegal, check needed to avoid buffer overflow */
+
+ j = scan[i];
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ val = 2 * (SBITS (bit_buf, 12) + SBITS (bit_buf, 1)) + 1;
+ val = (val * quantizer_scale * quant_matrix[j]) / 32;
+
+ SATURATE (val);
+ dest[j] = val;
+ mismatch ^= val;
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x02000000) {
+ tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00800000) {
+ tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00200000) {
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else {
+ tab = DCT_16 + UBITS (bit_buf, 16);
+ bit_buf <<= 16;
+ GETWORD (bit_buf, bits + 16, bit_ptr);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ }
+ break; /* illegal, check needed to avoid buffer overflow */
+ }
+
+ dest[63] ^= mismatch & 1;
+ DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ picture->bitstream_buf = bit_buf;
+ picture->bitstream_bits = bits;
+ picture->bitstream_ptr = bit_ptr;
+}
+
+static void get_xvmc_mpeg1_intra_block (picture_t * picture)
+{
+ int i;
+ int j;
+ int val;
+ uint8_t * scan = picture->scan;
+ uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+ int quantizer_scale = picture->quantizer_scale;
+ DCTtab * tab;
+ uint32_t bit_buf;
+ int bits;
+ uint8_t * bit_ptr;
+ int16_t * dest;
+
+ i = 0;
+
+ dest = picture->mc->blockptr;
+
+ /* XvMC's IDCT must use non-patched scan tables */
+ if( picture->mc->xvmc_accel & IDCT_ACCEL ) {
+ if( scan == mpeg2_scan_norm )
+ scan = mpeg2_scan_norm_orig;
+ else
+ scan = mpeg2_scan_alt_orig;
+ }
+
+ bit_buf = picture->bitstream_buf;
+ bits = picture->bitstream_bits;
+ bit_ptr = picture->bitstream_ptr;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ while (1) {
+ if (bit_buf >= 0x28000000) {
+
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
+
+ i += tab->run;
+ if (i >= 64)
+ break; /* end of block */
+
+ normal_code:
+ j = scan[i];
+ bit_buf <<= tab->len;
+ bits += tab->len + 1;
+ val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+ /* oddification */
+ val = (val - 1) | 1;
+
+ /* if (bitstream_get (1)) val = -val; */
+ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+ SATURATE (val);
+ dest[j] = val;
+
+ bit_buf <<= 1;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x04000000) {
+
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
+
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+
+ /* escape code */
+
+ i += UBITS (bit_buf << 6, 6) - 64;
+ if (i >= 64)
+ break; /* illegal, check needed to avoid buffer overflow */
+
+ j = scan[i];
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ val = SBITS (bit_buf, 8);
+ if (! (val & 0x7f)) {
+ DUMPBITS (bit_buf, bits, 8);
+ val = UBITS (bit_buf, 8) + 2 * val;
+ }
+ val = (val * quantizer_scale * quant_matrix[j]) / 16;
+
+ /* oddification */
+ val = (val + ~SBITS (val, 1)) | 1;
+
+ SATURATE (val);
+ dest[j] = val;
+
+ DUMPBITS (bit_buf, bits, 8);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x02000000) {
+ tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00800000) {
+ tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00200000) {
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else {
+ tab = DCT_16 + UBITS (bit_buf, 16);
+ bit_buf <<= 16;
+ GETWORD (bit_buf, bits + 16, bit_ptr);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ }
+ break; /* illegal, check needed to avoid buffer overflow */
+ }
+ DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ picture->bitstream_buf = bit_buf;
+ picture->bitstream_bits = bits;
+ picture->bitstream_ptr = bit_ptr;
+}
+
+static void get_xvmc_mpeg1_non_intra_block (picture_t * picture)
+{
+ int i;
+ int j;
+ int val;
+ uint8_t * scan = picture->scan;
+ uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
+ int quantizer_scale = picture->quantizer_scale;
+ DCTtab * tab;
+ uint32_t bit_buf;
+ int bits;
+ uint8_t * bit_ptr;
+ int16_t * dest;
+
+ i = -1;
+
+ dest = picture->mc->blockptr;
+
+ /* XvMC's IDCT must use non-patched scan tables */
+ if( picture->mc->xvmc_accel & IDCT_ACCEL ) {
+ if( scan == mpeg2_scan_norm )
+ scan = mpeg2_scan_norm_orig;
+ else
+ scan = mpeg2_scan_alt_orig;
+ }
+
+ bit_buf = picture->bitstream_buf;
+ bits = picture->bitstream_bits;
+ bit_ptr = picture->bitstream_ptr;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ if (bit_buf >= 0x28000000) {
+ tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
+ goto entry_1;
+ } else
+ goto entry_2;
+
+ while (1) {
+ if (bit_buf >= 0x28000000) {
+
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
+
+ entry_1:
+ i += tab->run;
+ if (i >= 64)
+ break; /* end of block */
+
+ normal_code:
+ j = scan[i];
+ bit_buf <<= tab->len;
+ bits += tab->len + 1;
+ val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
+
+ /* oddification */
+ val = (val - 1) | 1;
+
+ /* if (bitstream_get (1)) val = -val; */
+ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+ SATURATE (val);
+ dest[j] = val;
+
+ bit_buf <<= 1;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ }
+
+ entry_2:
+ if (bit_buf >= 0x04000000) {
+
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
+
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+
+ /* escape code */
+
+ i += UBITS (bit_buf << 6, 6) - 64;
+ if (i >= 64)
+ break; /* illegal, check needed to avoid buffer overflow */
+
+ j = scan[i];
+
+ DUMPBITS (bit_buf, bits, 12);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ val = SBITS (bit_buf, 8);
+ if (! (val & 0x7f)) {
+ DUMPBITS (bit_buf, bits, 8);
+ val = UBITS (bit_buf, 8) + 2 * val;
+ }
+ val = 2 * (val + SBITS (val, 1)) + 1;
+ val = (val * quantizer_scale * quant_matrix[j]) / 32;
+
+ /* oddification */
+ val = (val + ~SBITS (val, 1)) | 1;
+
+ SATURATE (val);
+ dest[j] = val;
+
+ DUMPBITS (bit_buf, bits, 8);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ continue;
+
+ } else if (bit_buf >= 0x02000000) {
+ tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00800000) {
+ tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else if (bit_buf >= 0x00200000) {
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ } else {
+ tab = DCT_16 + UBITS (bit_buf, 16);
+ bit_buf <<= 16;
+ GETWORD (bit_buf, bits + 16, bit_ptr);
+ i += tab->run;
+ if (i < 64)
+ goto normal_code;
+ }
+ break; /* illegal, check needed to avoid buffer overflow */
+ }
+ DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ picture->bitstream_buf = bit_buf;
+ picture->bitstream_bits = bits;
+ picture->bitstream_ptr = bit_ptr;
+}
+
+static inline void slice_xvmc_intra_DCT (picture_t * picture, int cc,
+ uint8_t * dest, int stride)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ /* Get the intra DC coefficient and inverse quantize it */
+
+ // printf("slice: slice_xvmc_intra_DCT cc=%d pred[0]=%d\n",cc,picture->dc_dct_pred[0]);
+ if (cc == 0)
+ picture->dc_dct_pred[0] += get_xvmc_luma_dc_dct_diff (picture);
+ else
+ picture->dc_dct_pred[cc] += get_xvmc_chroma_dc_dct_diff (picture);
+ //TODO conversion to signed format
+ // printf("slice: pred[0]=%d presision=%d\n",picture->dc_dct_pred[0],
+ // picture->intra_dc_precision);
+
+ mpeg2_zero_block(picture->mc->blockptr);
+
+ picture->mc->blockptr[0] =
+ picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision);
+ // memset (picture->mc->blockptr + 1, 0, 63 * sizeof (int16_t));
+ // TODO do we need to zero mem here?
+
+ if (picture->mpeg1) {
+ if (picture->picture_coding_type != D_TYPE)
+ get_xvmc_mpeg1_intra_block (picture);
+ } else if (picture->intra_vlc_format)
+ get_xvmc_intra_block_B15 (picture);
+ else
+ get_xvmc_intra_block_B14 (picture);
+
+ if((picture->mc->xvmc_accel & ACCEL) == MOTION_ACCEL) {
+ //motion_comp only no idct acceleration so do it in software
+ mpeg2_idct (picture->mc->blockptr);
+ }
+ picture->mc->blockptr += 64;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline void slice_xvmc_non_intra_DCT (picture_t * picture, uint8_t * dest,
+ int stride)
+{
+ mpeg2_zero_block(picture->mc->blockptr);
+
+ if (picture->mpeg1)
+ get_xvmc_mpeg1_non_intra_block (picture);
+ else
+ get_xvmc_non_intra_block (picture);
+
+ if((picture->mc->xvmc_accel & ACCEL) == MOTION_ACCEL) {
+ // motion comp only no idct acceleration so do it in sw
+ mpeg2_idct (picture->mc->blockptr);
+ }
+ picture->mc->blockptr += 64;
+}
+
+#define MOTION(table,ref,motion_x,motion_y,size,y) \
+ pos_x = 2 * picture->offset + motion_x; \
+ pos_y = 2 * picture->v_offset + motion_y + 2 * y; \
+ if ((pos_x > picture->limit_x) || (pos_y > picture->limit_y_ ## size)) \
+ return; \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ table[xy_half] (picture->dest[0] + y * picture->pitches[0] + \
+ picture->offset, ref[0] + (pos_x >> 1) + \
+ (pos_y >> 1) * picture->pitches[0], picture->pitches[0], \
+ size); \
+ motion_x /= 2; motion_y /= 2; \
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
+ table[4+xy_half] (picture->dest[1] + y/2 * picture->pitches[1] + \
+ (picture->offset >> 1), ref[1] + \
+ (((picture->offset + motion_x) >> 1) + \
+ ((((picture->v_offset + motion_y) >> 1) + y/2) * \
+ picture->pitches[1])), picture->pitches[1], size/2); \
+ table[4+xy_half] (picture->dest[2] + y/2 * picture->pitches[2] + \
+ (picture->offset >> 1), ref[2] + \
+ (((picture->offset + motion_x) >> 1) + \
+ ((((picture->v_offset + motion_y) >> 1) + y/2) * \
+ picture->pitches[2])), picture->pitches[2], size/2) \
+
+#define MOTION_FIELD(table,ref,motion_x,motion_y,dest_field,op,src_field) \
+
+static void motion_mp1 (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y;
+ unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_x = (motion->pmv[0][0] +
+ (get_xvmc_motion_delta (picture,
+ motion->f_code[0]) << motion->f_code[1]));
+ motion_x = bound_motion_vector (motion_x,
+ motion->f_code[0] + motion->f_code[1]);
+ motion->pmv[0][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = (motion->pmv[0][1] +
+ (get_xvmc_motion_delta (picture,
+ motion->f_code[0]) << motion->f_code[1]));
+ motion_y = bound_motion_vector (motion_y,
+ motion->f_code[0] + motion->f_code[1]);
+ motion->pmv[0][1] = motion_y;
+
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fr_frame (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y;
+ unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = motion->pmv[0][1] + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fr_field (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int),
+ int dir)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y, field;
+ // unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ field = UBITS (bit_buf, 1);
+ picture->XvMC_mv_field_sel[0][dir] = field;
+ DUMPBITS (bit_buf, bits, 1);
+
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[0][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = (motion->pmv[0][1] >> 1) + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
+ motion->pmv[0][1] = motion_y << 1;
+
+ // MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field);
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ field = UBITS (bit_buf, 1);
+ //TODO look at field select need bob (weave ok)
+ picture->XvMC_mv_field_sel[1][dir] = field;
+ DUMPBITS (bit_buf, bits, 1);
+
+ motion_x = motion->pmv[1][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = (motion->pmv[1][1] >> 1) + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
+ motion->pmv[1][1] = motion_y << 1;
+
+ // MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fr_dmv (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y, dmv_x, dmv_y;
+ unsigned int xy_half, offset;
+
+ // TODO field select ?? possible need to be 0
+ picture->XvMC_mv_field_sel[0][0] = picture->XvMC_mv_field_sel[1][0] = 0;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ dmv_x = get_xvmc_dmv (picture);
+
+ motion_y = (motion->pmv[0][1] >> 1) + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
+ dmv_y = get_xvmc_dmv (picture);
+
+ // m = picture->top_field_first ? 1 : 3;
+ // other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
+ // other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
+ // MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0);
+
+ // m = picture->top_field_first ? 3 : 1;
+ // other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
+ // other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
+ // MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);
+
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1);
+ offset = (picture->offset + (motion_x >> 1) +
+ (picture->v_offset + (motion_y & ~1)) * picture->pitches[0]);
+ mpeg2_mc.avg[xy_half]
+ (picture->dest[0] + picture->offset,
+ motion->ref[0][0] + offset, 2 * picture->pitches[0], 8);
+ mpeg2_mc.avg[xy_half]
+ (picture->dest[0] + picture->pitches[0] + picture->offset,
+ motion->ref[0][0] + picture->pitches[0] + offset,
+ 2 * picture->pitches[0], 8);
+ motion_x /= 2; motion_y /= 2;
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1);
+ offset = (((picture->offset + motion_x) >> 1) +
+ (((picture->v_offset >> 1) + (motion_y & ~1)) *
+ picture->pitches[1]));
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[1] + (picture->offset >> 1),
+ motion->ref[0][1] + offset, 2 * picture->pitches[1], 4);
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[1] + picture->pitches[1] + (picture->offset >> 1),
+ motion->ref[0][1] + picture->pitches[1] + offset,
+ 2 * picture->pitches[1], 4);
+ offset = (((picture->offset + motion_x) >> 1) +
+ (((picture->v_offset >> 1) + (motion_y & ~1)) *
+ picture->pitches[2]));
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[2] + (picture->offset >> 1),
+ motion->ref[0][2] + offset, 2 * picture->pitches[2], 4);
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[2] + picture->pitches[2] + (picture->offset >> 1),
+ motion->ref[0][2] + picture->pitches[2] + offset,
+ 2 * picture->pitches[2], 4);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_reuse (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+ int motion_x, motion_y;
+ unsigned int pos_x, pos_y, xy_half;
+
+ motion_x = motion->pmv[0][0];
+ motion_y = motion->pmv[0][1];
+
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0);
+}
+
+// TODO don't need this routine
+static void motion_zero (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+ if(picture->mc->xvmc_accel==0) {
+ table[0] (picture->dest[0] + picture->offset,
+ (motion->ref[0][0] + picture->offset +
+ picture->v_offset * picture->pitches[0]),
+ picture->pitches[0], 16);
+
+ table[4] (picture->dest[1] + (picture->offset >> 1),
+ motion->ref[0][1] + (picture->offset >> 1) +
+ (picture->v_offset >> 1) * picture->pitches[1],
+ picture->pitches[1], 8);
+ table[4] (picture->dest[2] + (picture->offset >> 1),
+ motion->ref[0][2] + (picture->offset >> 1) +
+ (picture->v_offset >> 1) * picture->pitches[2],
+ picture->pitches[2], 8);
+ }
+}
+
+/* like motion_frame, but parsing without actual motion compensation */
+static void motion_fr_conceal (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int tmp;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ tmp = (picture->f_motion.pmv[0][0] +
+ get_xvmc_motion_delta (picture, picture->f_motion.f_code[0]));
+ tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
+ picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ tmp = (picture->f_motion.pmv[0][1] +
+ get_xvmc_motion_delta (picture, picture->f_motion.f_code[1]));
+ tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
+ picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
+
+ DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_field (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y;
+ uint8_t ** ref_field;
+ unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
+
+ // TODO field select may need to do something here for bob (weave ok)
+ picture->XvMC_mv_field_sel[0][0] = picture->XvMC_mv_field_sel[1][0] = 0;
+
+ DUMPBITS (bit_buf, bits, 1);
+
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = motion->pmv[0][1] + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+
+ MOTION (table, ref_field, motion_x, motion_y, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y;
+ uint8_t ** ref_field;
+ unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
+
+ // TODO field select may need to do something here bob (weave ok)
+ picture->XvMC_mv_field_sel[0][0] = picture->XvMC_mv_field_sel[1][0] = 0;
+
+ DUMPBITS (bit_buf, bits, 1);
+
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[0][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = motion->pmv[0][1] + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+ motion->pmv[0][1] = motion_y;
+
+ MOTION (table, ref_field, motion_x, motion_y, 8, 0);
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
+
+ // TODO field select may need to do something here for bob (weave ok)
+ picture->XvMC_mv_field_sel[0][0] = picture->XvMC_mv_field_sel[1][0] = 0;
+
+ DUMPBITS (bit_buf, bits, 1);
+
+ motion_x = motion->pmv[1][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion_x;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_y = motion->pmv[1][1] + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+ motion->pmv[1][1] = motion_y;
+
+ MOTION (table, ref_field, motion_x, motion_y, 8, 8);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_dmv (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int motion_x, motion_y, other_x, other_y;
+ unsigned int pos_x, pos_y, xy_half;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ motion_x = motion->pmv[0][0] + get_xvmc_motion_delta (picture,
+ motion->f_code[0]);
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ other_x = ((motion_x + (motion_x > 0)) >> 1) + get_xvmc_dmv (picture);
+
+ motion_y = motion->pmv[0][1] + get_xvmc_motion_delta (picture,
+ motion->f_code[1]);
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+ other_y = (((motion_y + (motion_y > 0)) >> 1) + get_xvmc_dmv (picture) +
+ picture->dmv_offset);
+
+ // TODO field select may need to do something here for bob (weave ok)
+ picture->XvMC_mv_field_sel[0][0] = picture->XvMC_mv_field_sel[1][0] = 0;
+
+ MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0);
+ MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_conceal (picture_t * picture)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int tmp;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ DUMPBITS (bit_buf, bits, 1); /* remove field_select */
+
+ tmp = (picture->f_motion.pmv[0][0] +
+ get_xvmc_motion_delta (picture, picture->f_motion.f_code[0]));
+ tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
+ picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ tmp = (picture->f_motion.pmv[0][1] +
+ get_xvmc_motion_delta (picture, picture->f_motion.f_code[1]));
+ tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
+ picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
+
+ DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+#define MOTION_CALL(routine,direction) \
+do { \
+ if ((direction) & MACROBLOCK_MOTION_FORWARD) \
+ routine (picture, &(picture->f_motion), mpeg2_mc.put); \
+ if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
+ routine (picture, &(picture->b_motion), \
+ ((direction) & MACROBLOCK_MOTION_FORWARD ? \
+ mpeg2_mc.avg : mpeg2_mc.put)); \
+} while (0)
+
+#define NEXT_MACROBLOCK \
+do { \
+ picture->offset += 16; \
+ if (picture->offset == picture->coded_picture_width) { \
+ do { /* just so we can use the break statement */ \
+ if (picture->current_frame->copy) { \
+ picture->current_frame->copy (picture->current_frame, \
+ picture->dest); \
+ if (picture->picture_coding_type == B_TYPE) \
+ break; \
+ } \
+ picture->dest[0] += 16 * picture->pitches[0]; \
+ picture->dest[1] += 8 * picture->pitches[1]; \
+ picture->dest[2] += 8 * picture->pitches[2]; \
+ } while (0); \
+ picture->v_offset += 16; \
+ if (picture->v_offset > picture->limit_y) { \
+ if (mpeg2_cpu_state_restore) \
+ mpeg2_cpu_state_restore (&cpu_state); \
+ return; \
+ } \
+ picture->offset = 0; \
+ } \
+} while (0)
+
+static inline int slice_xvmc_init (picture_t * picture, int code)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ int offset, height;
+ struct vo_frame_s * forward_reference_frame;
+ struct vo_frame_s * backward_reference_frame;
+ MBAtab * mba;
+
+ offset = picture->picture_structure == BOTTOM_FIELD;
+ picture->pitches[0] = picture->current_frame->pitches[0];
+ picture->pitches[1] = picture->current_frame->pitches[1];
+ picture->pitches[2] = picture->current_frame->pitches[2];
+
+ if( picture->forward_reference_frame ) {
+ forward_reference_frame = picture->forward_reference_frame;
+ }
+ else {
+ /* return 1; */
+ forward_reference_frame = picture->current_frame;
+ }
+
+ if( picture->backward_reference_frame ) {
+ backward_reference_frame = picture->backward_reference_frame;
+ }
+ else {
+ /* return 1; */
+ backward_reference_frame = picture->current_frame;
+ }
+
+ picture->f_motion.ref[0][0] =
+ forward_reference_frame->base[0] + (offset ? picture->pitches[0] : 0);
+ picture->f_motion.ref[0][1] =
+ forward_reference_frame->base[1] + (offset ? picture->pitches[1] : 0);
+ picture->f_motion.ref[0][2] =
+ forward_reference_frame->base[2] + (offset ? picture->pitches[2] : 0);
+
+ picture->b_motion.ref[0][0] =
+ backward_reference_frame->base[0] + (offset ? picture->pitches[0] : 0);
+ picture->b_motion.ref[0][1] =
+ backward_reference_frame->base[1] + (offset ? picture->pitches[1] : 0);
+ picture->b_motion.ref[0][2] =
+ backward_reference_frame->base[2] + (offset ? picture->pitches[2] : 0);
+
+ if (picture->picture_structure != FRAME_PICTURE) {
+ uint8_t ** forward_ref;
+ int bottom_field;
+
+ bottom_field = (picture->picture_structure == BOTTOM_FIELD);
+ picture->dmv_offset = bottom_field ? 1 : -1;
+ picture->f_motion.ref2[0] = picture->f_motion.ref[bottom_field];
+ picture->f_motion.ref2[1] = picture->f_motion.ref[!bottom_field];
+ picture->b_motion.ref2[0] = picture->b_motion.ref[bottom_field];
+ picture->b_motion.ref2[1] = picture->b_motion.ref[!bottom_field];
+
+ forward_ref = forward_reference_frame->base;
+ if (picture->second_field && (picture->picture_coding_type != B_TYPE))
+ forward_ref = picture->current_frame->base;
+
+ picture->f_motion.ref[1][0] = forward_ref[0] + (bottom_field ? 0 : picture->pitches[0]);
+ picture->f_motion.ref[1][1] = forward_ref[1] + (bottom_field ? 0 : picture->pitches[1]);
+ picture->f_motion.ref[1][2] = forward_ref[2] + (bottom_field ? 0 : picture->pitches[2]);
+
+ picture->b_motion.ref[1][0] =
+ backward_reference_frame->base[0] + (bottom_field ? 0 : picture->pitches[0]);
+ picture->b_motion.ref[1][1] =
+ backward_reference_frame->base[1] + (bottom_field ? 0 : picture->pitches[1]);
+ picture->b_motion.ref[1][2] =
+ backward_reference_frame->base[2] + (bottom_field ? 0 : picture->pitches[2]);
+ }
+
+ 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;
+ picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
+ picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
+
+ picture->v_offset = (code - 1) * 16;
+ offset = (code - 1);
+ if (picture->current_frame->copy && picture->picture_coding_type == B_TYPE)
+ offset = 0;
+ else if (picture->picture_structure != FRAME_PICTURE)
+ offset = 2 * offset;
+
+ picture->dest[0] = picture->current_frame->base[0] + picture->pitches[0] * offset * 16;
+ picture->dest[1] = picture->current_frame->base[1] + picture->pitches[1] * offset * 8;
+ picture->dest[2] = picture->current_frame->base[2] + picture->pitches[2] * offset * 8;
+
+ height = picture->coded_picture_height;
+ switch (picture->picture_structure) {
+ case BOTTOM_FIELD:
+ picture->dest[0] += picture->pitches[0];
+ picture->dest[1] += picture->pitches[1];
+ picture->dest[2] += picture->pitches[2];
+ /* follow thru */
+ case TOP_FIELD:
+ picture->pitches[0] <<= 1;
+ picture->pitches[1] <<= 1;
+ picture->pitches[2] <<= 1;
+ height >>= 1;
+ }
+ picture->limit_x = 2 * picture->coded_picture_width - 32;
+ picture->limit_y_16 = 2 * height - 32;
+ picture->limit_y_8 = 2 * height - 16;
+ picture->limit_y = height - 16;
+
+ //TODO conversion to signed format signed format
+ if(picture->mc->xvmc_accel == MOTION_ACCEL) {
+ //Motion Comp only unsigned intra
+ // original:
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
+ } else {
+ //Motion Comp only signed intra MOTION_ACCEL+SIGNED_INTRA
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 0;
+ }
+
+ picture->quantizer_scale = get_xvmc_quantizer_scale (picture);
+
+ /* ignore intra_slice and all the extra data */
+ while (bit_buf & 0x80000000) {
+ DUMPBITS (bit_buf, bits, 9);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ }
+
+ /* decode initial macroblock address increment */
+ offset = 0;
+ while (1) {
+ if (bit_buf >= 0x08000000) {
+ mba = MBA_5 + (UBITS (bit_buf, 6) - 2);
+ break;
+ } else if (bit_buf >= 0x01800000) {
+ mba = MBA_11 + (UBITS (bit_buf, 12) - 24);
+ break;
+ } else switch (UBITS (bit_buf, 12)) {
+ case 8: /* macroblock_escape */
+ offset += 33;
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ case 15: /* macroblock_stuffing (MPEG1 only) */
+ bit_buf &= 0xfffff;
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ default: /* error */
+ return 1;
+ }
+ }
+ DUMPBITS (bit_buf, bits, mba->len + 1);
+ picture->offset = (offset + mba->mba) << 4;
+
+ while (picture->offset - picture->coded_picture_width >= 0) {
+ picture->offset -= picture->coded_picture_width;
+ if ((picture->current_frame->copy == NULL) ||
+ (picture->picture_coding_type != B_TYPE)) {
+ picture->dest[0] += 16 * picture->pitches[0];
+ picture->dest[1] += 8 * picture->pitches[1];
+ picture->dest[2] += 8 * picture->pitches[2];
+ }
+ picture->v_offset += 16;
+ }
+ if (picture->v_offset > picture->limit_y)
+ return 1;
+
+ return 0;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+void mpeg2_xvmc_slice (picture_t * picture, int code, uint8_t * buffer)
+{
+#define bit_buf (picture->bitstream_buf)
+#define bits (picture->bitstream_bits)
+#define bit_ptr (picture->bitstream_ptr)
+ cpu_state_t cpu_state;
+
+ bitstream_init (picture, buffer);
+
+ if (slice_xvmc_init (picture, code))
+ return;
+
+ if (mpeg2_cpu_state_save)
+ mpeg2_cpu_state_save (&cpu_state);
+
+ while (1) {
+ int macroblock_modes;
+ int mba_inc;
+ MBAtab * mba;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+
+ macroblock_modes = get_xvmc_macroblock_modes (picture); //macroblock_modes()
+ picture->XvMC_mb_type = macroblock_modes & 0x1F;
+ picture->XvMC_dct_type = (macroblock_modes & DCT_TYPE_INTERLACED)>>5;
+ picture->XvMC_motion_type = (macroblock_modes & MOTION_TYPE_MASK)>>6;
+
+ picture->XvMC_x = picture->offset/16;
+ picture->XvMC_y = picture->v_offset/16;
+
+ if((picture->XvMC_x == 0) && (picture->XvMC_y == 0)) {
+ picture->XvMC_mv_field_sel[0][0] =
+ picture->XvMC_mv_field_sel[1][0] =
+ picture->XvMC_mv_field_sel[0][1] =
+ picture->XvMC_mv_field_sel[1][1] = 0;
+ }
+
+ picture->XvMC_cbp = 0x3f; //TODO set for intra 4:2:0 6 blocks yyyyuv all enabled
+
+ /* maybe integrate MACROBLOCK_QUANT test into get_xvmc_macroblock_modes ? */
+ if (macroblock_modes & MACROBLOCK_QUANT)
+ picture->quantizer_scale = get_xvmc_quantizer_scale (picture);
+ if (macroblock_modes & MACROBLOCK_INTRA) {
+
+ int DCT_offset, DCT_stride;
+ int offset;
+ uint8_t * dest_y;
+
+ if (picture->concealment_motion_vectors) {
+ if (picture->picture_structure == FRAME_PICTURE)
+ motion_fr_conceal (picture);
+ else
+ motion_fi_conceal (picture);
+ } else {
+ 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;
+ picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
+ picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
+ }
+
+ if (macroblock_modes & DCT_TYPE_INTERLACED) {
+ DCT_offset = picture->pitches[0];
+ DCT_stride = picture->pitches[0] * 2;
+ } else {
+ DCT_offset = picture->pitches[0] * 8;
+ DCT_stride = picture->pitches[0];
+ }
+ offset = picture->offset;
+ dest_y = picture->dest[0] + offset;
+ // unravaled loop of 6 block(i) calls in macroblock()
+ slice_xvmc_intra_DCT (picture, 0, dest_y, DCT_stride);
+ slice_xvmc_intra_DCT (picture, 0, dest_y + 8, DCT_stride);
+ slice_xvmc_intra_DCT (picture, 0, dest_y + DCT_offset, DCT_stride);
+ slice_xvmc_intra_DCT (picture, 0, dest_y + DCT_offset + 8, DCT_stride);
+ slice_xvmc_intra_DCT (picture, 1, picture->dest[1] + (offset >> 1),
+ picture->pitches[1]);
+ slice_xvmc_intra_DCT (picture, 2, picture->dest[2] + (offset >> 1),
+ picture->pitches[2]);
+
+ if (picture->picture_coding_type == D_TYPE) {
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ DUMPBITS (bit_buf, bits, 1);
+ }
+ } else {
+ picture->XvMC_cbp = 0;
+
+ if (picture->picture_structure == FRAME_PICTURE)
+ switch (macroblock_modes & MOTION_TYPE_MASK) {
+ case MC_FRAME:
+ if (picture->mpeg1) {
+ MOTION_CALL (motion_mp1, macroblock_modes);
+ } else {
+ MOTION_CALL (motion_fr_frame, macroblock_modes);
+ }
+ break;
+
+ case MC_FIELD:
+ //MOTION_CALL (motion_fr_field, macroblock_modes);
+
+ if ((macroblock_modes) & MACROBLOCK_MOTION_FORWARD)
+ motion_fr_field(picture, &(picture->f_motion),
+ mpeg2_mc.put,0);
+ if ((macroblock_modes) & MACROBLOCK_MOTION_BACKWARD)
+ motion_fr_field(picture, &(picture->b_motion),
+ ((macroblock_modes) & MACROBLOCK_MOTION_FORWARD ?
+ mpeg2_mc.avg : mpeg2_mc.put),1);
+
+ break;
+
+ case MC_DMV:
+ MOTION_CALL (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
+ break;
+
+ case 0:
+ /* non-intra mb without forward mv in a P picture */
+ picture->f_motion.pmv[0][0] = 0;
+ picture->f_motion.pmv[0][1] = 0;
+ picture->f_motion.pmv[1][0] = 0;
+ picture->f_motion.pmv[1][1] = 0;
+ // MOTION_CALL (motion_zero, MACROBLOCK_MOTION_FORWARD);
+ break;
+ }
+ else
+ switch (macroblock_modes & MOTION_TYPE_MASK) {
+ case MC_FIELD:
+ MOTION_CALL (motion_fi_field, macroblock_modes);
+ break;
+
+ case MC_16X8:
+ MOTION_CALL (motion_fi_16x8, macroblock_modes);
+ break;
+
+ case MC_DMV:
+ MOTION_CALL (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
+ break;
+
+ case 0:
+ /* non-intra mb without forward mv in a P picture */
+ picture->f_motion.pmv[0][0] = 0;
+ picture->f_motion.pmv[0][1] = 0;
+ picture->f_motion.pmv[1][0] = 0;
+ picture->f_motion.pmv[1][1] = 0;
+ // MOTION_CALL (motion_zero, MACROBLOCK_MOTION_FORWARD);
+ break;
+ }
+
+ if (macroblock_modes & MACROBLOCK_PATTERN) {
+ int coded_block_pattern;
+ int DCT_offset, DCT_stride;
+ int offset;
+ uint8_t * dest_y;
+
+ if (macroblock_modes & DCT_TYPE_INTERLACED) {
+ DCT_offset = picture->pitches[0];
+ DCT_stride = picture->pitches[0] * 2;
+ } else {
+ DCT_offset = picture->pitches[0] * 8;
+ DCT_stride = picture->pitches[0];
+ }
+
+ picture->XvMC_cbp = coded_block_pattern = get_xvmc_coded_block_pattern (picture);
+ offset = picture->offset;
+ dest_y = picture->dest[0] + offset;
+ // TODO optimize not fully used for idct accel only mc.
+ if (coded_block_pattern & 0x20)
+ slice_xvmc_non_intra_DCT (picture, dest_y, DCT_stride); // cc0 luma 0
+ if (coded_block_pattern & 0x10)
+ slice_xvmc_non_intra_DCT (picture, dest_y + 8, DCT_stride); // cc0 luma 1
+ if (coded_block_pattern & 0x08)
+ slice_xvmc_non_intra_DCT (picture, dest_y + DCT_offset,
+ DCT_stride); // cc0 luma 2
+ if (coded_block_pattern & 0x04)
+ slice_xvmc_non_intra_DCT (picture, dest_y + DCT_offset + 8,
+ DCT_stride); // cc0 luma 3
+ if (coded_block_pattern & 0x2)
+ slice_xvmc_non_intra_DCT (picture,
+ picture->dest[1] + (offset >> 1),
+ picture->pitches[1]); // cc1 croma
+ if (coded_block_pattern & 0x1)
+ slice_xvmc_non_intra_DCT (picture,
+ picture->dest[2] + (offset >> 1),
+ picture->pitches[2]); // cc2 croma
+ }
+
+ if(picture->mc->xvmc_accel == MOTION_ACCEL) {
+ // original:
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 128 << picture->intra_dc_precision;
+
+ } else { // MOTION_ACCEL+SIGNED_INTRA
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 0;
+ }
+
+ }
+ picture->current_frame->proc_macro_block(picture->XvMC_x, picture->XvMC_y,
+ picture->XvMC_mb_type,
+ picture->XvMC_motion_type,
+ picture->XvMC_mv_field_sel,
+ picture->XvMC_dmvector,
+ picture->XvMC_cbp,
+ picture->XvMC_dct_type,
+ picture->current_frame,
+ picture->forward_reference_frame,
+ picture->backward_reference_frame,
+ picture->picture_structure,
+ picture->second_field,
+ picture->f_motion.pmv,
+ picture->b_motion.pmv);
+
+
+ NEXT_MACROBLOCK;
+
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ mba_inc = 0;
+ while (1) {
+ if (bit_buf >= 0x10000000) {
+ mba = MBA_5 + (UBITS (bit_buf, 5) - 2);
+ break;
+ } else if (bit_buf >= 0x03000000) {
+ mba = MBA_11 + (UBITS (bit_buf, 11) - 24);
+ break;
+ } else switch (UBITS (bit_buf, 11)) {
+ case 8: /* macroblock_escape */
+ mba_inc += 33;
+ /* pass through */
+ case 15: /* macroblock_stuffing (MPEG1 only) */
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ default: /* end of slice, or error */
+ if (mpeg2_cpu_state_restore)
+ mpeg2_cpu_state_restore (&cpu_state);
+ return;
+ }
+ }
+ DUMPBITS (bit_buf, bits, mba->len);
+ mba_inc += mba->mba;
+ if (mba_inc) {
+ //TODO conversion to signed format signed format
+ if(picture->mc->xvmc_accel == MOTION_ACCEL) {
+ // original:
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 128 << picture->intra_dc_precision;
+ } else { // MOTION_ACCEL+SIGNED_INTRA
+ picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
+ picture->dc_dct_pred[2] = 0;
+ }
+
+ picture->XvMC_cbp = 0;
+ 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 {
+ if(picture->mc->xvmc_accel) {
+
+ /* derive motion_type */
+ if(picture->picture_structure == FRAME_PICTURE) {
+ picture->XvMC_motion_type = XINE_MC_FRAME;
+ } else {
+ picture->XvMC_motion_type = XINE_MC_FIELD;
+ /* predict from field of same parity */
+ picture->XvMC_mv_field_sel[0][0] =
+ picture->XvMC_mv_field_sel[0][1] =
+ (picture->picture_structure==BOTTOM_FIELD);
+ }
+ picture->XvMC_mb_type = macroblock_modes & 0x1E;
+ picture->XvMC_x = picture->offset/16;
+ picture->XvMC_y = picture->v_offset/16;
+
+ picture->current_frame->proc_macro_block(picture->XvMC_x,picture->XvMC_y,
+ picture->XvMC_mb_type,
+ picture->XvMC_motion_type,
+ picture->XvMC_mv_field_sel,
+ picture->XvMC_dmvector,
+ picture->XvMC_cbp,
+ picture->XvMC_dct_type,
+ picture->current_frame,
+ 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_zero, MACROBLOCK_MOTION_FORWARD);
+ }
+ NEXT_MACROBLOCK;
+ } while (--mba_inc);
+ } else {
+ do {
+ if(picture->mc->xvmc_accel) {
+
+ /* derive motion_type */
+ if(picture->picture_structure == FRAME_PICTURE) {
+ picture->XvMC_motion_type = XINE_MC_FRAME;
+ } else {
+ picture->XvMC_motion_type = XINE_MC_FIELD;
+ /* predict from field of same parity */
+ picture->XvMC_mv_field_sel[0][0] =
+ picture->XvMC_mv_field_sel[0][1] =
+ (picture->picture_structure==BOTTOM_FIELD);
+ }
+
+ picture->XvMC_mb_type = macroblock_modes & 0x1E;
+
+ picture->XvMC_x = picture->offset/16;
+ picture->XvMC_y = picture->v_offset/16;
+
+ picture->current_frame->proc_macro_block(picture->XvMC_x,picture->XvMC_y,
+ picture->XvMC_mb_type,
+ picture->XvMC_motion_type,
+ picture->XvMC_mv_field_sel,
+ picture->XvMC_dmvector,
+ picture->XvMC_cbp,
+ picture->XvMC_dct_type,
+ picture->current_frame,
+ 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);
+ }
+ }
+ }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
diff --git a/src/libmpeg2/xine_decoder.c b/src/libmpeg2/xine_decoder.c
index 7b1313e85..5d2b91df7 100644
--- a/src/libmpeg2/xine_decoder.c
+++ b/src/libmpeg2/xine_decoder.c
@@ -17,7 +17,7 @@
* 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.49 2003/08/05 15:09:23 mroi Exp $
+ * $Id: xine_decoder.c,v 1.50 2003/10/06 21:52:43 miguelfreitas Exp $
*
* stuff needed to turn libmpeg2 into a xine decoder plugin
*/
@@ -137,7 +137,7 @@ static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stre
this->class = (mpeg2_class_t *) class_gen;
this->mpeg2.stream = stream;
- mpeg2_init (&this->mpeg2);
+ 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;