summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libmpeg2/Makefile.am2
-rw-r--r--src/libmpeg2/cpu_state.c115
-rw-r--r--src/libmpeg2/decode.c155
-rw-r--r--src/libmpeg2/header.c103
-rw-r--r--src/libmpeg2/idct.c107
-rw-r--r--src/libmpeg2/idct_altivec.c26
-rw-r--r--src/libmpeg2/idct_mlib.c18
-rw-r--r--src/libmpeg2/idct_mmx.c27
-rw-r--r--src/libmpeg2/motion_comp.c132
-rw-r--r--src/libmpeg2/motion_comp_altivec.c38
-rw-r--r--src/libmpeg2/motion_comp_mlib.c71
-rw-r--r--src/libmpeg2/motion_comp_mmx.c188
-rw-r--r--src/libmpeg2/mpeg2_internal.h124
-rw-r--r--src/libmpeg2/slice.c842
-rw-r--r--src/libmpeg2/stats.c9
-rw-r--r--src/libmpeg2/vlc.h11
16 files changed, 1045 insertions, 923 deletions
diff --git a/src/libmpeg2/Makefile.am b/src/libmpeg2/Makefile.am
index 3184f001f..37c5a9b53 100644
--- a/src/libmpeg2/Makefile.am
+++ b/src/libmpeg2/Makefile.am
@@ -15,7 +15,7 @@ lib_LTLIBRARIES = xineplug_decode_mpeg2.la
xineplug_decode_mpeg2_la_SOURCES = slice.c header.c stats.c idct.c \
motion_comp.c decode.c idct_mmx.c motion_comp_mmx.c \
idct_mlib.c motion_comp_mlib.c idct_altivec.c \
- motion_comp_altivec.c xine_decoder.c
+ motion_comp_altivec.c cpu_state.c xine_decoder.c
xineplug_decode_mpeg2_la_LDFLAGS = -avoid-version -module
noinst_HEADERS = vlc.h mpeg2.h mpeg2_internal.h
diff --git a/src/libmpeg2/cpu_state.c b/src/libmpeg2/cpu_state.c
new file mode 100644
index 000000000..5a93c6181
--- /dev/null
+++ b/src/libmpeg2/cpu_state.c
@@ -0,0 +1,115 @@
+/*
+ * cpu_state.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 <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
+
+#ifdef ARCH_PPC
+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"
+ );
+}
+#endif
+
+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
+#ifdef ARCH_PPC
+ if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
+ mpeg2_cpu_state_save = state_save_altivec;
+ mpeg2_cpu_state_restore = state_restore_altivec;
+ }
+#endif
+}
diff --git a/src/libmpeg2/decode.c b/src/libmpeg2/decode.c
index f5fdab2b0..2c2020ee9 100644
--- a/src/libmpeg2/decode.c
+++ b/src/libmpeg2/decode.c
@@ -1,8 +1,10 @@
/*
* decode.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -44,9 +46,8 @@
#define LOG
*/
-#define BUFFER_SIZE (224 * 1024)
-
-mpeg2_config_t config;
+/* #define BUFFER_SIZE (224 * 1024) */
+#define BUFFER_SIZE (1194 * 1024) /* new buffer size for mpeg2dec 0.2.1 */
static void process_userdata(mpeg2dec_t *mpeg2dec, uint8_t *buffer);
@@ -54,12 +55,14 @@ void mpeg2_init (mpeg2dec_t * mpeg2dec,
vo_instance_t * output)
{
static int do_init = 1;
+ uint32_t mm_accel;
if (do_init) {
do_init = 0;
- config.flags = xine_mm_accel();
- idct_init ();
- motion_comp_init ();
+ mm_accel = xine_mm_accel();
+ mpeg2_cpu_state_init (mm_accel);
+ mpeg2_idct_init (mm_accel);
+ mpeg2_mc_init (mm_accel);
}
if( !mpeg2dec->chunk_buffer )
@@ -81,8 +84,8 @@ void mpeg2_init (mpeg2dec_t * mpeg2dec,
memset (mpeg2dec->picture, 0, sizeof (picture_t));
- /* initialize supstructures */
- header_state_init (mpeg2dec->picture);
+ /* initialize substructures */
+ mpeg2_header_state_init (mpeg2dec->picture);
}
static inline void get_frame_duration (mpeg2dec_t * mpeg2dec, vo_frame_t *frame)
@@ -141,11 +144,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
{
picture_t * picture;
int is_frame_done;
-/*
- if (code >= 0xb0) {
- printf ("libmpeg2: parse_chunk 0x%02x\n", code);
- }
-*/
+
/* wait for sequence_header_code */
if (mpeg2dec->is_sequence_needed) {
if (code != 0xb3) {
@@ -159,7 +158,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
return 0;
}
- stats_header (code, buffer);
+ mpeg2_stats (code, buffer);
picture = mpeg2dec->picture;
is_frame_done = mpeg2dec->in_slice && ((!code) || (code >= 0xb0));
@@ -167,51 +166,32 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
if (is_frame_done) {
mpeg2dec->in_slice = 0;
- if ( picture->current_frame && ((picture->picture_structure == FRAME_PICTURE) ||
- (picture->second_field)) ) {
-
- if (!mpeg2dec->drop_frame)
- picture->current_frame->bad_frame = 0;
-#ifdef LOG
- printf ("libmpeg2: drawing frame %d type %s: %s\n",
- picture->current_frame->id,
- picture->picture_coding_type == I_TYPE ? "I" :
- picture->picture_coding_type == P_TYPE ? "P" : "B",
- picture->current_frame->bad_frame ? "BAD" : "good");
-#endif
- if (picture->picture_coding_type == B_TYPE) {
+ if (((picture->picture_structure == FRAME_PICTURE) ||
+ (picture->second_field)) &&
+ (!(mpeg2dec->drop_frame))) {
+
+ if (picture->picture_coding_type == B_TYPE) {
+ if( picture->current_frame && !picture->current_frame->drawn ) {
+ picture->current_frame->bad_frame = 0;
/* hack against wrong mpeg1 pts */
if (picture->mpeg1)
- picture->current_frame->pts = 0;
+ picture->current_frame->pts = 0;
- if( !picture->current_frame->drawn )
- mpeg2dec->frames_to_drop = picture->current_frame->draw (picture->current_frame);
+ mpeg2dec->frames_to_drop = picture->current_frame->draw (picture->current_frame);
picture->current_frame->drawn = 1;
-
- if( picture->current_frame == picture->backward_reference_frame )
- picture->backward_reference_frame = NULL;
-
- picture->current_frame->free (picture->current_frame);
-
- picture->current_frame = NULL;
- picture->throwaway_frame = NULL;
- } else if (picture->forward_reference_frame && !picture->forward_reference_frame->drawn) {
- get_frame_duration(mpeg2dec, picture->forward_reference_frame);
- mpeg2dec->frames_to_drop = picture->forward_reference_frame->draw (picture->forward_reference_frame);
- picture->forward_reference_frame->drawn = 1;
}
-
-#ifdef ARCH_X86
- if (config.flags & MM_ACCEL_X86_MMX)
- emms ();
-#endif
+ } else if (picture->forward_reference_frame && !picture->forward_reference_frame->drawn) {
+ get_frame_duration(mpeg2dec, picture->forward_reference_frame);
+ mpeg2dec->frames_to_drop = picture->forward_reference_frame->draw (picture->forward_reference_frame);
+ picture->forward_reference_frame->drawn = 1;
+ }
}
}
switch (code) {
case 0x00: /* picture_start_code */
- if (header_process_picture_header (picture, buffer)) {
+ if (mpeg2_header_picture (picture, buffer)) {
fprintf (stderr, "bad picture header\n");
exit (1);
}
@@ -291,8 +271,8 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
break;
case 0xb3: /* sequence_header_code */
- if (header_process_sequence_header (picture, buffer)) {
- printf ("libmpeg2: bad sequence header\n");
+ if (mpeg2_header_sequence (picture, buffer)) {
+ fprintf (stderr, "bad sequence header\n");
/* exit (1); */
} else if (mpeg2dec->is_sequence_needed
|| (picture->frame_width != picture->coded_picture_width)
@@ -331,9 +311,9 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
break;
case 0xb5: /* extension_start_code */
- if (header_process_extension (picture, buffer)) {
- printf ("libmpeg2: bad extension\n");
- exit (1);
+ if (mpeg2_header_extension (picture, buffer)) {
+ fprintf (stderr, "bad extension\n");
+ exit (1);
}
break;
@@ -342,7 +322,7 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
printf ("libmpeg2: sequence end code not handled\n");
#endif
case 0xb8: /* group of pictures start code */
- if (header_process_group_of_pictures (picture, buffer)) {
+ if (mpeg2_header_group_of_pictures (picture, buffer)) {
printf ("libmpeg2: bad group of pictures\n");
exit (1);
}
@@ -363,8 +343,14 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
else
mpeg2dec->drop_frame = 1;
} else {
+ if ( picture->current_frame &&
+ picture->current_frame != picture->backward_reference_frame &&
+ picture->current_frame != picture->forward_reference_frame ) {
+ picture->current_frame->free (picture->current_frame);
+ }
+
if (picture->picture_coding_type == B_TYPE)
- picture->throwaway_frame = picture->current_frame =
+ picture->current_frame =
mpeg2dec->output->get_frame (mpeg2dec->output,
picture->coded_picture_width,
picture->coded_picture_height,
@@ -404,14 +390,8 @@ static inline int parse_chunk (mpeg2dec_t * mpeg2dec, int code,
}
if (!(mpeg2dec->drop_frame)) {
- if (slice_process (picture, code, buffer) == 1) {
+ mpeg2_slice (picture, code, buffer);
picture->current_frame->bad_frame = 0;
- }
-
-#ifdef ARCH_X86
- if (config.flags & MM_ACCEL_X86_MMX)
- emms ();
-#endif
}
}
@@ -433,11 +413,6 @@ static inline uint8_t * copy_chunk (mpeg2dec_t * mpeg2dec,
if (limit > end)
limit = end;
- /*
- printf ("libmpeg2: copy chunk current %08x\n", current );
- printf ("libmpeg2: copy chunk end %08x\n", end); fflush(stdout);
- */
-
while (1) {
byte = *current++;
@@ -539,25 +514,38 @@ void mpeg2_close (mpeg2dec_t * mpeg2dec)
dont remove any picture->*->free() below. doing so will cause buffer
leak, and we only have about 15 of them.
*/
+
+ if ( picture->current_frame ) {
+ if( !picture->current_frame->drawn ) {
+ printf ("libmpeg2: blasting out current frame on close\n");
+ picture->current_frame->pts = 0;
+ get_frame_duration(mpeg2dec, picture->current_frame);
+ picture->current_frame->draw (picture->current_frame);
+ picture->current_frame->drawn = 1;
+ }
+
+ if( picture->current_frame != picture->backward_reference_frame &&
+ picture->current_frame != picture->forward_reference_frame ) {
+ picture->current_frame->free (picture->current_frame);
+ }
+ picture->current_frame = NULL;
+ }
+
if (picture->forward_reference_frame) {
picture->forward_reference_frame->free (picture->forward_reference_frame);
+ picture->forward_reference_frame = NULL;
}
- if (picture->throwaway_frame) {
- printf ("libmpeg2: blasting out throwaway frame on close\n");
- picture->throwaway_frame->pts = 0;
- get_frame_duration(mpeg2dec, picture->throwaway_frame);
- picture->throwaway_frame->draw (picture->throwaway_frame);
- picture->throwaway_frame->free (picture->throwaway_frame);
- }
-
if (picture->backward_reference_frame) {
- printf ("libmpeg2: blasting out backward reference frame on close\n");
- picture->backward_reference_frame->pts = 0;
- get_frame_duration(mpeg2dec, picture->backward_reference_frame);
- if( !picture->backward_reference_frame->drawn)
+ if( !picture->backward_reference_frame->drawn) {
+ printf ("libmpeg2: blasting out backward reference frame on close\n");
+ picture->backward_reference_frame->pts = 0;
+ get_frame_duration(mpeg2dec, picture->backward_reference_frame);
picture->backward_reference_frame->draw (picture->backward_reference_frame);
+ picture->backward_reference_frame->drawn = 1;
+ }
picture->backward_reference_frame->free (picture->backward_reference_frame);
+ picture->backward_reference_frame = NULL;
}
if ( mpeg2dec->chunk_buffer ) {
@@ -587,11 +575,10 @@ void mpeg2_find_sequence_header (mpeg2dec_t * mpeg2dec,
/* printf ("looking for sequence header... %02x\n", code); */
- stats_header (code, mpeg2dec->chunk_buffer);
+ mpeg2_stats (code, mpeg2dec->chunk_buffer);
if (code == 0xb3) { /* sequence_header_code */
-
- if (header_process_sequence_header (picture, mpeg2dec->chunk_buffer)) {
+ if (mpeg2_header_sequence (picture, mpeg2dec->chunk_buffer)) {
printf ("libmpeg2: bad sequence header\n");
continue;
}
@@ -616,7 +603,7 @@ void mpeg2_find_sequence_header (mpeg2dec_t * mpeg2dec,
xine_send_event(mpeg2dec->xine, &notify_event.event);
}
} else if (code == 0xb5) { /* extension_start_code */
- if (header_process_extension (picture, mpeg2dec->chunk_buffer)) {
+ if (mpeg2_header_extension (picture, mpeg2dec->chunk_buffer)) {
printf ("libmpeg2: bad extension\n");
continue ;
}
diff --git a/src/libmpeg2/header.c b/src/libmpeg2/header.c
index 21157d3c4..44e7695f0 100644
--- a/src/libmpeg2/header.c
+++ b/src/libmpeg2/header.c
@@ -1,8 +1,10 @@
/*
- * slice.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -50,7 +52,7 @@ static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
83
};
-uint8_t scan_norm[64] ATTR_ALIGN(16) =
+uint8_t mpeg2_scan_norm[64] ATTR_ALIGN(16) =
{
/* Zig-Zag scan pattern */
0, 1, 8,16, 9, 2, 3,10,
@@ -63,7 +65,7 @@ uint8_t scan_norm[64] ATTR_ALIGN(16) =
53,60,61,54,47,55,62,63
};
-uint8_t scan_alt[64] ATTR_ALIGN(16) =
+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,
@@ -99,31 +101,26 @@ static uint32_t get_bits(uint8_t *buffer, uint32_t count, uint32_t *bit_position
return result;
}
-
-
-void header_state_init (picture_t * picture)
+void mpeg2_header_state_init (picture_t * picture)
{
- picture->scan = scan_norm;
+ picture->scan = mpeg2_scan_norm;
}
-int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
+int mpeg2_header_sequence (picture_t * picture, uint8_t * buffer)
{
int width, height;
int i;
- if ((buffer[6] & 0x20) != 0x20) {
+ if ((buffer[6] & 0x20) != 0x20)
return 1; /* missing marker_bit */
- }
height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
width = ((height >> 12) + 15) & ~15;
height = ((height & 0xfff) + 15) & ~15;
- if ((width > 768) || (height > 576)) {
- /* printf ("%d x %d\n", width, height); */
- /*return 1;*/ /* size restrictions for MP@ML or MPEG1 */
- }
+ if ((width > 1920) || (height > 1152))
+ return 1; /* size restrictions for MP@HL */
picture->coded_picture_width = width;
picture->coded_picture_height = height;
@@ -131,27 +128,25 @@ int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
/* 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); */
+ 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[scan_norm[i]] =
+ picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
(buffer[i+7] << 7) | (buffer[i+8] >> 1);
buffer += 64;
- } else {
+ } else
for (i = 0; i < 64; i++)
- picture->intra_quantizer_matrix[scan_norm[i]] =
+ picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
default_intra_quantizer_matrix [i];
- }
- if (buffer[7] & 1) {
+ if (buffer[7] & 1)
for (i = 0; i < 64; i++)
- picture->non_intra_quantizer_matrix[scan_norm[i]] =
+ picture->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
buffer[i+8];
- } else {
+ else
for (i = 0; i < 64; i++)
picture->non_intra_quantizer_matrix[i] = 16;
- }
/* MPEG1 - for testing only */
picture->mpeg1 = 1;
@@ -162,13 +157,11 @@ int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
/* picture->alternate_scan = 0; */
picture->picture_structure = FRAME_PICTURE;
/* picture->second_field = 0; */
- picture->last_mba = ((width * height) >> 8) - 1;
return 0;
}
-static int header_process_sequence_extension (picture_t * picture,
- uint8_t * buffer)
+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) ||
@@ -180,10 +173,10 @@ static int header_process_sequence_extension (picture_t * picture,
picture->low_delay = buffer[5] & 0x80;
- if (picture->progressive_sequence)
+ if (!picture->progressive_sequence)
picture->coded_picture_height =
(picture->coded_picture_height + 31) & ~31;
-
+
/* printf ("libmpeg2: low_delay : %d\n", picture->low_delay); */
/*
@@ -197,35 +190,27 @@ static int header_process_sequence_extension (picture_t * picture,
return 0;
}
-static int header_process_quant_matrix_extension (picture_t * picture,
- uint8_t * buffer)
+static int quant_matrix_extension (picture_t * picture, uint8_t * buffer)
{
int i;
-#ifdef LOG_PAN_SCAN
- printf ("libmpeg2: quant_matrix extension\n");
-#endif
if (buffer[0] & 8) {
for (i = 0; i < 64; i++)
- picture->intra_quantizer_matrix[scan_norm[i]] =
+ picture->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
(buffer[i] << 5) | (buffer[i+1] >> 3);
buffer += 64;
}
- if (buffer[0] & 4) {
+ if (buffer[0] & 4)
for (i = 0; i < 64; i++)
- picture->non_intra_quantizer_matrix[scan_norm[i]] =
+ picture->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
(buffer[i] << 6) | (buffer[i+1] >> 2);
- }
return 0;
}
-static int header_process_picture_coding_extension (picture_t * picture, uint8_t * buffer)
+static int picture_coding_extension (picture_t * picture, uint8_t * buffer)
{
-/*
- printf ("libmpeg2: picture_coding_extension\n");
- */
/* 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;
@@ -240,9 +225,9 @@ static int header_process_picture_coding_extension (picture_t * picture, uint8_t
picture->intra_vlc_format = (buffer[3] >> 3) & 1;
if (buffer[3] & 4) /* alternate_scan */
- picture->scan = scan_alt;
+ picture->scan = mpeg2_scan_alt;
else
- picture->scan = scan_norm;
+ picture->scan = mpeg2_scan_norm;
/* these are not used by the decoder */
picture->top_field_first = buffer[3] >> 7;
@@ -252,10 +237,11 @@ static int header_process_picture_coding_extension (picture_t * picture, uint8_t
return 0;
}
-static int header_process_sequence_display_extension (picture_t * picture, uint8_t * buffer) {
+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);
@@ -268,6 +254,7 @@ static int header_process_sequence_display_extension (picture_t * picture, uint8
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);
@@ -284,12 +271,14 @@ static int header_process_sequence_display_extension (picture_t * picture, uint8
return 0;
}
-static int header_process_picture_display_extension (picture_t * picture, uint8_t * buffer) {
+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);
@@ -302,27 +291,24 @@ static int header_process_picture_display_extension (picture_t * picture, uint8_
picture->frame_centre_horizontal_offset,
picture->frame_centre_vertical_offset);
#endif
-// printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
-// close(stdout);
-// _exit(0);
return 0;
}
-int header_process_extension (picture_t * picture, uint8_t * buffer)
+int mpeg2_header_extension (picture_t * picture, uint8_t * buffer)
{
switch (buffer[0] & 0xf0) {
case 0x00: /* reserved */
return 0;
case 0x10: /* sequence extension */
- return header_process_sequence_extension (picture, buffer);
+ return sequence_extension (picture, buffer);
case 0x20: /* sequence display extension for Pan & Scan */
- return header_process_sequence_display_extension (picture, buffer);
+ return sequence_display_extension (picture, buffer);
case 0x30: /* quant matrix extension */
- return header_process_quant_matrix_extension (picture, buffer);
+ return quant_matrix_extension (picture, buffer);
case 0x40: /* copyright extension */
return 0;
@@ -334,10 +320,10 @@ int header_process_extension (picture_t * picture, uint8_t * buffer)
return 0;
case 0x70: /* picture display extension for Pan & Scan */
- return header_process_picture_display_extension (picture, buffer);
+ return picture_display_extension (picture, buffer);
case 0x80: /* picture coding extension */
- return header_process_picture_coding_extension (picture, buffer);
+ return picture_coding_extension (picture, buffer);
case 0x90: /* picture spacial scalable extension */
return 0;
@@ -364,10 +350,11 @@ int header_process_extension (picture_t * picture, uint8_t * buffer)
return 0;
}
-int header_process_group_of_pictures (picture_t * picture, uint8_t * buffer) {
+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);
@@ -392,7 +379,7 @@ int header_process_group_of_pictures (picture_t * picture, uint8_t * buffer) {
return 0;
}
-int header_process_picture_header (picture_t *picture, uint8_t * buffer)
+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) |
@@ -412,5 +399,3 @@ int header_process_picture_header (picture_t *picture, uint8_t * buffer)
return 0;
}
-
-
diff --git a/src/libmpeg2/idct.c b/src/libmpeg2/idct.c
index 0b77a62ed..1c577aa5f 100644
--- a/src/libmpeg2/idct.c
+++ b/src/libmpeg2/idct.c
@@ -1,12 +1,14 @@
/*
* idct.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -40,6 +42,7 @@
#include "config.h"
#include <stdio.h>
+#include <stdlib.h>
#include <inttypes.h>
#include "mpeg2_internal.h"
@@ -53,56 +56,12 @@
#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
/* idct main entry point */
-void (*idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
-void (*idct_block_add) (int16_t * block, uint8_t * dest, int stride);
-
-static void idct_block_copy_c (int16_t *block, uint8_t * dest, int stride);
-static void idct_block_add_c (int16_t *block, uint8_t * dest, int stride);
+void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
+void (* mpeg2_idct_add) (int16_t * block, uint8_t * dest, int stride);
static uint8_t clip_lut[1024];
#define CLIP(i) ((clip_lut+384)[ (i)])
-void idct_init (void)
-{
-#ifdef ARCH_X86
- if (config.flags & MM_ACCEL_X86_MMXEXT) {
- fprintf (stderr, "Using MMXEXT for IDCT transform\n");
- idct_block_copy = idct_block_copy_mmxext;
- idct_block_add = idct_block_add_mmxext;
- idct_mmx_init ();
- } else if (config.flags & MM_ACCEL_X86_MMX) {
- fprintf (stderr, "Using MMX for IDCT transform\n");
- idct_block_copy = idct_block_copy_mmx;
- idct_block_add = idct_block_add_mmx;
- idct_mmx_init ();
- } else
-#endif
-#ifdef LIBMPEG2_MLIB
- if (config.flags & MM_ACCEL_MLIB) {
- fprintf (stderr, "Using mlib for IDCT transform\n");
- idct_block_copy = idct_block_copy_mlib;
- idct_block_add = idct_block_add_mlib;
- } else
-#endif
-#ifdef ENABLE_ALTIVEC
- if (config.flags & MM_ACCEL_PPC_ALTIVEC) {
- fprintf (stderr, "Using altivec for IDCT transform\n");
- idct_block_copy = idct_block_copy_altivec;
- idct_block_add = idct_block_add_altivec;
- idct_altivec_init ();
- } else
-#endif
- {
- int i;
-
- fprintf (stderr, "No accelerated IDCT transform found\n");
- idct_block_copy = idct_block_copy_c;
- idct_block_add = idct_block_add_c;
- for (i = -384; i < 640; i++)
- clip_lut[i+384] = (i < 0) ? 0 : ((i > 255) ? 255 : i);
- }
-}
-
/* row (horizontal) IDCT
*
* 7 pi 1
@@ -243,7 +202,7 @@ static void inline idct_col (int16_t *block)
block[8*7] = (x7 - x1) >> 14;
}
-void idct_block_copy_c (int16_t * block, uint8_t * dest, int stride)
+static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest, int stride)
{
int i;
@@ -269,7 +228,7 @@ void idct_block_copy_c (int16_t * block, uint8_t * dest, int stride)
} while (--i);
}
-void idct_block_add_c (int16_t * block, uint8_t * dest, int stride)
+static void mpeg2_idct_add_c (int16_t * block, uint8_t * dest, int stride)
{
int i;
@@ -294,3 +253,53 @@ void idct_block_add_c (int16_t * block, uint8_t * dest, int stride)
block += 8;
} while (--i);
}
+
+void mpeg2_idct_init (uint32_t mm_accel)
+{
+#ifdef ARCH_X86
+ if (mm_accel & MM_ACCEL_X86_MMXEXT) {
+ fprintf (stderr, "Using MMXEXT for IDCT transform\n");
+ mpeg2_idct_copy = mpeg2_idct_copy_mmxext;
+ mpeg2_idct_add = mpeg2_idct_add_mmxext;
+ mpeg2_idct_mmx_init ();
+ } else if (mm_accel & MM_ACCEL_X86_MMX) {
+ fprintf (stderr, "Using MMX for IDCT transform\n");
+ mpeg2_idct_copy = mpeg2_idct_copy_mmx;
+ mpeg2_idct_add = mpeg2_idct_add_mmx;
+ mpeg2_idct_mmx_init ();
+ } else
+#endif
+#ifdef ARCH_PPC
+ if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
+ fprintf (stderr, "Using altivec for IDCT transform\n");
+ mpeg2_idct_copy = mpeg2_idct_copy_altivec;
+ mpeg2_idct_add = mpeg2_idct_add_altivec;
+ mpeg2_idct_altivec_init ();
+ } else
+#endif
+#ifdef LIBMPEG2_MLIB
+ if (mm_accel & MM_ACCEL_MLIB) {
+ char * env_var;
+
+ env_var = getenv ("MLIB_NON_IEEE");
+
+ if (env_var == NULL) {
+ fprintf (stderr, "Using mlib for IDCT transform\n");
+ 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;
+
+ fprintf (stderr, "No accelerated IDCT transform found\n");
+ mpeg2_idct_copy = mpeg2_idct_copy_c;
+ mpeg2_idct_add = mpeg2_idct_add_c;
+ for (i = -384; i < 640; i++)
+ clip_lut[i+384] = (i < 0) ? 0 : ((i > 255) ? 255 : i);
+ }
+}
diff --git a/src/libmpeg2/idct_altivec.c b/src/libmpeg2/idct_altivec.c
index 96be2ebc3..1d20f56b4 100644
--- a/src/libmpeg2/idct_altivec.c
+++ b/src/libmpeg2/idct_altivec.c
@@ -1,6 +1,6 @@
/*
* idct_altivec.c
- * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
+ * 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.
@@ -26,7 +26,6 @@
#include "config.h"
#ifdef ARCH_PPC
-#ifdef ENABLE_ALTIVEC
#include <inttypes.h>
@@ -56,7 +55,7 @@ static int16_t constants[5][8] ATTR_ALIGN(16) = {
* I then do some simple trimming on the function prolog/trailers
*/
-void idct_block_copy_altivec (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride)
{
asm (" \n"
"# stwu %r1, -128(%r1) \n"
@@ -247,7 +246,7 @@ void idct_block_copy_altivec (int16_t * block, uint8_t * dest, int stride)
);
}
-void idct_block_add_altivec (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_add_altivec (int16_t * block, uint8_t * dest, int stride)
{
asm (" \n"
"# stwu %r1, -192(%r1) \n"
@@ -467,24 +466,23 @@ void idct_block_add_altivec (int16_t * block, uint8_t * dest, int stride)
);
}
-void idct_altivec_init (void)
+void mpeg2_idct_altivec_init (void)
{
- extern uint8_t scan_norm[64];
- extern uint8_t scan_alt[64];
+ extern uint8_t mpeg2_scan_norm[64];
+ extern uint8_t mpeg2_scan_alt[64];
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 = scan_norm[i];
- scan_norm[i] = (j >> 3) | ((j & 7) << 3);
- j = scan_alt[i];
- scan_alt[i] = (j >> 3) | ((j & 7) << 3);
+ 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 /* ENABLE_ALTIVEC */
#endif /* ARCH_PPC */
#else /* __ALTIVEC__ */
@@ -607,7 +605,7 @@ static vector_s16_t constants[5] = {
(vector_s16_t)(19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722)
};
-void idct_block_copy_altivec (vector_s16_t * block, unsigned char * dest,
+void mpeg2_idct_copy_altivec (vector_s16_t * block, unsigned char * dest,
int stride)
{
vector_u8_t tmp;
@@ -629,7 +627,7 @@ void idct_block_copy_altivec (vector_s16_t * block, unsigned char * dest,
COPY (dest, vx7)
}
-void idct_block_add_altivec (vector_s16_t * block, unsigned char * dest,
+void mpeg2_idct_add_altivec (vector_s16_t * block, unsigned char * dest,
int stride)
{
vector_u8_t tmp;
diff --git a/src/libmpeg2/idct_mlib.c b/src/libmpeg2/idct_mlib.c
index 876ab574a..18097f51c 100644
--- a/src/libmpeg2/idct_mlib.c
+++ b/src/libmpeg2/idct_mlib.c
@@ -1,8 +1,9 @@
/*
* idct_mlib.c
- * Copyright (C) 1999-2001 Håkan Hjort <d95hjort@dtek.chalmers.se>
+ * Copyright (C) 1999-2002 Håkan Hjort <d95hjort@dtek.chalmers.se>
*
* 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
@@ -23,23 +24,28 @@
#ifdef LIBMPEG2_MLIB
-#include <inttypes.h>
#include <mlib_types.h>
#include <mlib_status.h>
#include <mlib_sys.h>
#include <mlib_video.h>
+#include <inttypes.h>
#include "mpeg2_internal.h"
-void idct_block_copy_mlib (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_add_mlib (int16_t * block, uint8_t * dest, int stride)
+{
+ mlib_VideoIDCT_IEEE_S16_S16 (block, block);
+ mlib_VideoAddBlock_U8_S16 (dest, block, stride);
+}
+
+void mpeg2_idct_copy_mlib_non_ieee (int16_t * block, uint8_t * dest,
+ int stride)
{
mlib_VideoIDCT8x8_U8_S16 (dest, block, stride);
}
-void idct_block_add_mlib (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_add_mlib_non_ieee (int16_t * block, uint8_t * dest, int stride)
{
- /* Should we use mlib_VideoIDCT_IEEE_S16_S16 here ?? */
- /* it's ~30% slower. */
mlib_VideoIDCT8x8_S16_S16 (block, block);
mlib_VideoAddBlock_U8_S16 (dest, block, stride);
}
diff --git a/src/libmpeg2/idct_mmx.c b/src/libmpeg2/idct_mmx.c
index 8741d838e..d8822f6d9 100644
--- a/src/libmpeg2/idct_mmx.c
+++ b/src/libmpeg2/idct_mmx.c
@@ -1,8 +1,10 @@
/*
* idct_mmx.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -656,13 +658,13 @@ static void block_add (int16_t * block, uint8_t * dest, int stride)
declare_idct (mmxext_idct, mmxext_table,
mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)
-void idct_block_copy_mmxext (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride)
{
mmxext_idct (block);
block_copy (block, dest, stride);
}
-void idct_block_add_mmxext (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_add_mmxext (int16_t * block, uint8_t * dest, int stride)
{
mmxext_idct (block);
block_add (block, dest, stride);
@@ -672,32 +674,31 @@ void idct_block_add_mmxext (int16_t * block, uint8_t * dest, int stride)
declare_idct (mmx_idct, mmx_table,
mmx_row_head, mmx_row, mmx_row_tail, mmx_row_mid)
-void idct_block_copy_mmx (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride)
{
mmx_idct (block);
block_copy (block, dest, stride);
}
-void idct_block_add_mmx (int16_t * block, uint8_t * dest, int stride)
+void mpeg2_idct_add_mmx (int16_t * block, uint8_t * dest, int stride)
{
mmx_idct (block);
block_add (block, dest, stride);
}
-
-void idct_mmx_init (void)
+void mpeg2_idct_mmx_init (void)
{
- extern uint8_t scan_norm[64];
- extern uint8_t scan_alt[64];
+ extern uint8_t mpeg2_scan_norm[64];
+ extern uint8_t mpeg2_scan_alt[64];
int i, j;
/* the mmx/mmxext idct uses a reordered input, so we patch scan tables */
for (i = 0; i < 64; i++) {
- j = scan_norm[i];
- scan_norm[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
- j = scan_alt[i];
- scan_alt[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
+ 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);
}
}
diff --git a/src/libmpeg2/motion_comp.c b/src/libmpeg2/motion_comp.c
index 9ea10c532..446766eae 100644
--- a/src/libmpeg2/motion_comp.c
+++ b/src/libmpeg2/motion_comp.c
@@ -1,8 +1,10 @@
/*
* motion_comp.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -25,102 +27,102 @@
#include <inttypes.h>
#include "mpeg2_internal.h"
-#include "xineutils.h"
+#include "mm_accel.h"
-mc_functions_t mc_functions;
+mpeg2_mc_t mpeg2_mc;
-void motion_comp_init (void)
+void mpeg2_mc_init (uint32_t mm_accel)
{
-
#ifdef ARCH_X86
- if (config.flags & MM_ACCEL_X86_MMXEXT) {
+ if (mm_accel & MM_ACCEL_X86_MMXEXT) {
fprintf (stderr, "Using MMXEXT for motion compensation\n");
- mc_functions = mc_functions_mmxext;
- } else if (config.flags & MM_ACCEL_X86_3DNOW) {
+ mpeg2_mc = mpeg2_mc_mmxext;
+ } else if (mm_accel & MM_ACCEL_X86_3DNOW) {
fprintf (stderr, "Using 3DNOW for motion compensation\n");
- mc_functions = mc_functions_3dnow;
- } else if (config.flags & MM_ACCEL_X86_MMX) {
+ mpeg2_mc = mpeg2_mc_3dnow;
+ } else if (mm_accel & MM_ACCEL_X86_MMX) {
fprintf (stderr, "Using MMX for motion compensation\n");
- mc_functions = mc_functions_mmx;
+ mpeg2_mc = mpeg2_mc_mmx;
} else
#endif
-#ifdef LIBMPEG2_MLIB
- if (config.flags & MM_ACCEL_MLIB) {
- fprintf (stderr, "Using mlib for motion compensation\n");
- mc_functions = mc_functions_mlib;
+#ifdef ARCH_PPC
+ if (mm_accel & MM_ACCEL_PPC_ALTIVEC) {
+ fprintf (stderr, "Using altivec for motion compensation\n");
+ mpeg2_mc = mpeg2_mc_altivec;
} else
#endif
-#ifdef ENABLE_ALTIVEC
- if (config.flags & MM_ACCEL_PPC_ALTIVEC) {
- fprintf (stderr, "Using altivec for motion compensation\n");
- mc_functions = mc_functions_altivec;
+#ifdef LIBMPEG2_MLIB
+ if (mm_accel & MM_ACCEL_MLIB) {
+ fprintf (stderr, "Using mlib for motion compensation\n");
+ mpeg2_mc = mpeg2_mc_mlib;
} else
#endif
{
fprintf (stderr, "No accelerated motion compensation found\n");
- mc_functions = mc_functions_c;
+ 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_(i) (ref[i])
+#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 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); \
+#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,)
-MC_FUNC (avg,)
+MC_FUNC (put,o)
+MC_FUNC (avg,o)
MC_FUNC (put,x)
MC_FUNC (avg,x)
MC_FUNC (put,y)
@@ -128,4 +130,4 @@ MC_FUNC (avg,y)
MC_FUNC (put,xy)
MC_FUNC (avg,xy)
-MOTION_COMP_EXTERN (c)
+MPEG2_MC_EXTERN (c)
diff --git a/src/libmpeg2/motion_comp_altivec.c b/src/libmpeg2/motion_comp_altivec.c
index e4b3a234c..2b7e75405 100644
--- a/src/libmpeg2/motion_comp_altivec.c
+++ b/src/libmpeg2/motion_comp_altivec.c
@@ -1,6 +1,6 @@
/*
* motion_comp_altivec.c
- * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
+ * 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.
@@ -26,7 +26,6 @@
#include "config.h"
#ifdef ARCH_PPC
-#ifdef ENABLE_ALTIVEC
#include <inttypes.h>
@@ -46,7 +45,7 @@
* unexpand -a
*/
-static void MC_put_16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_o_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -82,7 +81,7 @@ static void MC_put_16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_o_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -133,7 +132,7 @@ static void MC_put_8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_x16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_x_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -179,7 +178,7 @@ static void MC_put_x16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_x8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_x_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -241,7 +240,7 @@ static void MC_put_x8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_y16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_y_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -285,7 +284,7 @@ static void MC_put_y16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_y8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_y_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -344,7 +343,7 @@ static void MC_put_y8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_xy16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_xy_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -425,7 +424,7 @@ static void MC_put_xy16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_put_xy8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_put_xy_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -522,7 +521,7 @@ static void MC_put_xy8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_o_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -566,7 +565,7 @@ static void MC_avg_16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_o_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -625,7 +624,7 @@ static void MC_avg_8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_x16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_x_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -679,7 +678,7 @@ static void MC_avg_x16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_x8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_x_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -749,7 +748,7 @@ static void MC_avg_x8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_y16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_y_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -802,7 +801,7 @@ static void MC_avg_y16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_y8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_y_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -869,7 +868,7 @@ static void MC_avg_y8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_xy16_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_xy_16_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -959,7 +958,7 @@ static void MC_avg_xy16_altivec (uint8_t * dest, uint8_t * ref,
);
}
-static void MC_avg_xy8_altivec (uint8_t * dest, uint8_t * ref,
+static void MC_avg_xy_8_altivec (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
asm (" \n"
@@ -1064,9 +1063,8 @@ static void MC_avg_xy8_altivec (uint8_t * dest, uint8_t * ref,
);
}
-MOTION_COMP_EXTERN (altivec)
+MPEG2_MC_EXTERN (altivec)
-#endif /* ENABLE_ALTIVEC */
#endif /* ARCH_PPC */
#else /* __ALTIVEC__ */
diff --git a/src/libmpeg2/motion_comp_mlib.c b/src/libmpeg2/motion_comp_mlib.c
index 91c0fb5a8..eaf27d9f2 100644
--- a/src/libmpeg2/motion_comp_mlib.c
+++ b/src/libmpeg2/motion_comp_mlib.c
@@ -1,8 +1,9 @@
/*
* motion_comp_mlib.c
- * Copyright (C) 2000-2001 Håkan Hjort <d95hjort@dtek.chalmers.se>
+ * Copyright (C) 2000-2002 Håkan Hjort <d95hjort@dtek.chalmers.se>
*
* 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
@@ -23,16 +24,16 @@
#ifdef LIBMPEG2_MLIB
-#include <inttypes.h>
#include <mlib_types.h>
#include <mlib_status.h>
#include <mlib_sys.h>
#include <mlib_video.h>
+#include <inttypes.h>
#include "mpeg2_internal.h"
-static void MC_put_16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoCopyRef_U8_U8_16x16 (dest, ref, stride);
@@ -40,8 +41,8 @@ static void MC_put_16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoCopyRef_U8_U8_16x8 (dest, ref, stride);
}
-static void MC_put_x16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpX_U8_U8_16x16 (dest, ref, stride, stride);
@@ -49,8 +50,8 @@ static void MC_put_x16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpX_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_put_y16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpY_U8_U8_16x16 (dest, ref, stride, stride);
@@ -58,8 +59,8 @@ static void MC_put_y16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpY_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_put_xy16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpXY_U8_U8_16x16 (dest, ref, stride, stride);
@@ -67,8 +68,8 @@ static void MC_put_xy16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpXY_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_put_8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoCopyRef_U8_U8_8x8 (dest, ref, stride);
@@ -76,8 +77,8 @@ static void MC_put_8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoCopyRef_U8_U8_8x4 (dest, ref, stride);
}
-static void MC_put_x8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpX_U8_U8_8x8 (dest, ref, stride, stride);
@@ -85,8 +86,8 @@ static void MC_put_x8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpX_U8_U8_8x4 (dest, ref, stride, stride);
}
-static void MC_put_y8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpY_U8_U8_8x8 (dest, ref, stride, stride);
@@ -94,8 +95,8 @@ static void MC_put_y8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpY_U8_U8_8x4 (dest, ref, stride, stride);
}
-static void MC_put_xy8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpXY_U8_U8_8x8 (dest, ref, stride, stride);
@@ -103,8 +104,8 @@ static void MC_put_xy8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpXY_U8_U8_8x4 (dest, ref, stride, stride);
}
-static void MC_avg_16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoCopyRefAve_U8_U8_16x16 (dest, ref, stride);
@@ -112,8 +113,8 @@ static void MC_avg_16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoCopyRefAve_U8_U8_16x8 (dest, ref, stride);
}
-static void MC_avg_x16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpAveX_U8_U8_16x16 (dest, ref, stride, stride);
@@ -121,8 +122,8 @@ static void MC_avg_x16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveX_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_avg_y16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpAveY_U8_U8_16x16 (dest, ref, stride, stride);
@@ -130,8 +131,8 @@ static void MC_avg_y16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveY_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_avg_xy16_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_16_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 16)
mlib_VideoInterpAveXY_U8_U8_16x16 (dest, ref, stride, stride);
@@ -139,8 +140,8 @@ static void MC_avg_xy16_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveXY_U8_U8_16x8 (dest, ref, stride, stride);
}
-static void MC_avg_8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoCopyRefAve_U8_U8_8x8 (dest, ref, stride);
@@ -148,8 +149,8 @@ static void MC_avg_8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoCopyRefAve_U8_U8_8x4 (dest, ref, stride);
}
-static void MC_avg_x8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpAveX_U8_U8_8x8 (dest, ref, stride, stride);
@@ -157,8 +158,8 @@ static void MC_avg_x8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveX_U8_U8_8x4 (dest, ref, stride, stride);
}
-static void MC_avg_y8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpAveY_U8_U8_8x8 (dest, ref, stride, stride);
@@ -166,8 +167,8 @@ static void MC_avg_y8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveY_U8_U8_8x4 (dest, ref, stride, stride);
}
-static void MC_avg_xy8_mlib (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_8_mlib (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
if (height == 8)
mlib_VideoInterpAveXY_U8_U8_8x8 (dest, ref, stride, stride);
@@ -175,6 +176,6 @@ static void MC_avg_xy8_mlib (uint8_t * dest, uint8_t * ref,
mlib_VideoInterpAveXY_U8_U8_8x4 (dest, ref, stride, stride);
}
-MOTION_COMP_EXTERN (mlib)
+MPEG2_MC_EXTERN (mlib)
#endif
diff --git a/src/libmpeg2/motion_comp_mmx.c b/src/libmpeg2/motion_comp_mmx.c
index 29bd78cbf..a1a5d3b54 100644
--- a/src/libmpeg2/motion_comp_mmx.c
+++ b/src/libmpeg2/motion_comp_mmx.c
@@ -1,8 +1,10 @@
/*
* motion_comp_mmx.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -34,15 +36,9 @@
/* MMX code - needs a rewrite */
-
-
-
-
-
-
/* some rounding constants */
-mmx_t round1 = {0x0001000100010001LL};
-mmx_t round4 = {0x0002000200020002LL};
+static mmx_t round1 = {0x0001000100010001LL};
+static mmx_t round4 = {0x0002000200020002LL};
/*
* This code should probably be compiled with loop unrolling
@@ -268,14 +264,14 @@ static inline void MC_avg_mmx (int width, int height,
} while (--height);
}
-static void MC_avg_16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_mmx (16, height, dest, ref, stride);
}
-static void MC_avg_8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_mmx (8, height, dest, ref, stride);
}
@@ -302,14 +298,14 @@ static inline void MC_put_mmx (int width, int height,
} while (--height);
}
-static void MC_put_16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_mmx (16, height, dest, ref, stride);
}
-static void MC_put_8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_mmx (8, height, dest, ref, stride);
}
@@ -333,14 +329,14 @@ static inline void MC_avg_x_mmx (int width, int height,
} while (--height);
}
-static void MC_avg_x16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_x_mmx (16, height, dest, ref, stride);
}
-static void MC_avg_x8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_x_mmx (8, height, dest, ref, stride);
}
@@ -363,14 +359,14 @@ static inline void MC_put_x_mmx (int width, int height,
} while (--height);
}
-static void MC_put_x16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_x_mmx (16, height, dest, ref, stride);
}
-static void MC_put_x8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_x_mmx (8, height, dest, ref, stride);
}
@@ -397,14 +393,14 @@ static inline void MC_avg_xy_mmx (int width, int height,
} while (--height);
}
-static void MC_avg_xy16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_xy_mmx (16, height, dest, ref, stride);
}
-static void MC_avg_xy8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_xy_mmx (8, height, dest, ref, stride);
}
@@ -430,14 +426,14 @@ static inline void MC_put_xy_mmx (int width, int height,
} while (--height);
}
-static void MC_put_xy16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_xy_mmx (16, height, dest, ref, stride);
}
-static void MC_put_xy8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_xy_mmx (8, height, dest, ref, stride);
}
@@ -463,14 +459,14 @@ static inline void MC_avg_y_mmx (int width, int height,
} while (--height);
}
-static void MC_avg_y16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_y_mmx (16, height, dest, ref, stride);
}
-static void MC_avg_y8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg_y_mmx (8, height, dest, ref, stride);
}
@@ -496,20 +492,20 @@ static inline void MC_put_y_mmx (int width, int height,
} while (--height);
}
-static void MC_put_y16_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_16_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_y_mmx (16, height, dest, ref, stride);
}
-static void MC_put_y8_mmx (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_8_mmx (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put_y_mmx (8, height, dest, ref, stride);
}
-MOTION_COMP_EXTERN (mmx)
+MPEG2_MC_EXTERN (mmx)
@@ -813,204 +809,204 @@ static inline void MC_avg4_16 (int height, uint8_t * dest, uint8_t * ref,
} while (--height);
}
-static void MC_avg_16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg1_16 (height, dest, ref, stride, CPU_MMXEXT);
}
-static void MC_avg_8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg1_8 (height, dest, ref, stride, CPU_MMXEXT);
}
-static void MC_put_16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put1_16 (height, dest, ref, stride);
}
-static void MC_put_8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put1_8 (height, dest, ref, stride);
}
-static void MC_avg_x16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg2_16 (height, dest, ref, stride, 1, CPU_MMXEXT);
}
-static void MC_avg_x8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_x_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg2_8 (height, dest, ref, stride, 1, CPU_MMXEXT);
}
-static void MC_put_x16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put2_16 (height, dest, ref, stride, 1, CPU_MMXEXT);
}
-static void MC_put_x8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_x_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put2_8 (height, dest, ref, stride, 1, CPU_MMXEXT);
}
-static void MC_avg_y16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg2_16 (height, dest, ref, stride, stride, CPU_MMXEXT);
}
-static void MC_avg_y8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_y_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg2_8 (height, dest, ref, stride, stride, CPU_MMXEXT);
}
-static void MC_put_y16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put2_16 (height, dest, ref, stride, stride, CPU_MMXEXT);
}
-static void MC_put_y8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_y_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put2_8 (height, dest, ref, stride, stride, CPU_MMXEXT);
}
-static void MC_avg_xy16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg4_16 (height, dest, ref, stride, CPU_MMXEXT);
}
-static void MC_avg_xy8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_xy_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg4_8 (height, dest, ref, stride, CPU_MMXEXT);
}
-static void MC_put_xy16_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_16_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put4_16 (height, dest, ref, stride, CPU_MMXEXT);
}
-static void MC_put_xy8_mmxext (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_xy_8_mmxext (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put4_8 (height, dest, ref, stride, CPU_MMXEXT);
}
-MOTION_COMP_EXTERN (mmxext)
+MPEG2_MC_EXTERN (mmxext)
-static void MC_avg_16_3dnow (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_16_3dnow (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg1_16 (height, dest, ref, stride, CPU_3DNOW);
}
-static void MC_avg_8_3dnow (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_avg_o_8_3dnow (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_avg1_8 (height, dest, ref, stride, CPU_3DNOW);
}
-static void MC_put_16_3dnow (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_16_3dnow (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put1_16 (height, dest, ref, stride);
}
-static void MC_put_8_3dnow (uint8_t * dest, uint8_t * ref,
- int stride, int height)
+static void MC_put_o_8_3dnow (uint8_t * dest, uint8_t * ref,
+ int stride, int height)
{
MC_put1_8 (height, dest, ref, stride);
}
-static void MC_avg_x16_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_x_16_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg2_16 (height, dest, ref, stride, 1, CPU_3DNOW);
}
-static void MC_avg_x8_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_x_8_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg2_8 (height, dest, ref, stride, 1, CPU_3DNOW);
}
-static void MC_put_x16_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_put_x_16_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_put2_16 (height, dest, ref, stride, 1, CPU_3DNOW);
}
-static void MC_put_x8_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_put_x_8_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_put2_8 (height, dest, ref, stride, 1, CPU_3DNOW);
}
-static void MC_avg_y16_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_y_16_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg2_16 (height, dest, ref, stride, stride, CPU_3DNOW);
}
-static void MC_avg_y8_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_y_8_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg2_8 (height, dest, ref, stride, stride, CPU_3DNOW);
}
-static void MC_put_y16_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_put_y_16_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_put2_16 (height, dest, ref, stride, stride, CPU_3DNOW);
}
-static void MC_put_y8_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_put_y_8_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_put2_8 (height, dest, ref, stride, stride, CPU_3DNOW);
}
-static void MC_avg_xy16_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_xy_16_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg4_16 (height, dest, ref, stride, CPU_3DNOW);
}
-static void MC_avg_xy8_3dnow (uint8_t * dest, uint8_t * ref,
+static void MC_avg_xy_8_3dnow (uint8_t * dest, uint8_t * ref,
int stride, int height)
{
MC_avg4_8 (height, dest, ref, stride, CPU_3DNOW);
}
-static void MC_put_xy16_3dnow (uint8_t * dest, uint8_t * ref,
+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_xy8_3dnow (uint8_t * dest, uint8_t * ref,
+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);
}
-MOTION_COMP_EXTERN (3dnow)
+MPEG2_MC_EXTERN (3dnow)
#endif
diff --git a/src/libmpeg2/mpeg2_internal.h b/src/libmpeg2/mpeg2_internal.h
index 767be0093..adbd5e8fa 100644
--- a/src/libmpeg2/mpeg2_internal.h
+++ b/src/libmpeg2/mpeg2_internal.h
@@ -1,8 +1,10 @@
/*
* mpeg2_internal.h
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -47,13 +49,14 @@
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 slice_process() */
+ /* next inside a slice, and is never used outside of mpeg2_slice() */
/* DCT coefficients - should be kept aligned ! */
int16_t DCTblock[64];
@@ -63,6 +66,15 @@ typedef struct picture_s {
int bitstream_bits; /* used bits in working set */
uint8_t * bitstream_ptr; /* buffer with stream data */
+ uint8_t * dest[3];
+ int offset;
+ int stride;
+ int uv_stride;
+ 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 */
@@ -74,7 +86,8 @@ typedef struct picture_s {
int quantizer_scale; /* remove */
int current_field; /* remove */
- int v_offset; /* remove */
+ int dmv_offset; /* remove */
+ unsigned int v_offset; /* remove */
/* now non-slice-specific information */
@@ -110,8 +123,6 @@ typedef struct picture_s {
int q_scale_type;
/* bool to use different vlc tables */
int intra_vlc_format;
- /* last macroblock in the picture */
- int last_mba;
/* used for DMV MC */
int top_field_first;
@@ -123,7 +134,6 @@ typedef struct picture_s {
struct vo_frame_s * current_frame;
struct vo_frame_s * forward_reference_frame;
struct vo_frame_s * backward_reference_frame;
- struct vo_frame_s * throwaway_frame;
int frame_width, frame_height;
@@ -140,7 +150,6 @@ typedef struct picture_s {
int progressive_sequence;
int repeat_first_field;
int progressive_frame;
- /*int bitrate; */
uint32_t frame_centre_horizontal_offset;
uint32_t frame_centre_vertical_offset;
uint32_t video_format;
@@ -158,75 +167,72 @@ typedef struct picture_s {
uint32_t closed_gop;
uint32_t broken_link;
+ int bitrate;
} picture_t;
-typedef struct mpeg2_config_s {
- /* Bit flags that enable various things */
- uint32_t flags;
-} mpeg2_config_t;
-
-/* The only global variable, */
-/* the config struct */
-extern mpeg2_config_t config;
+typedef struct cpu_state_s {
+#ifdef ARCH_PPC
+ uint8_t regv[12*16];
+#endif
+ int dummy;
+} cpu_state_t;
+/* cpu_state.c */
+void mpeg2_cpu_state_init (uint32_t mm_accel);
-
-/* slice.c */
-void header_state_init (picture_t * picture);
-int header_process_picture_header (picture_t * picture, uint8_t * buffer);
-int header_process_sequence_header (picture_t * picture, uint8_t * buffer);
-int header_process_extension (picture_t * picture, uint8_t * buffer);
-int header_process_group_of_pictures (picture_t * picture, uint8_t * buffer);
+/* header.c */
+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 */
-void idct_init (void);
+void mpeg2_idct_init (uint32_t mm_accel);
/* idct_mlib.c */
-void idct_block_copy_mlib (int16_t * block, uint8_t * dest, int stride);
-void idct_block_add_mlib (int16_t * block, uint8_t * dest, int stride);
+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);
/* idct_mmx.c */
-void idct_block_copy_mmxext (int16_t *block, uint8_t * dest, int stride);
-void idct_block_add_mmxext (int16_t *block, uint8_t * dest, int stride);
-void idct_block_copy_mmx (int16_t *block, uint8_t * dest, int stride);
-void idct_block_add_mmx (int16_t *block, uint8_t * dest, int stride);
-void idct_mmx_init (void);
+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_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_init (void);
-#ifdef ENABLE_ALTIVEC
/* idct_altivec.c */
-void idct_block_copy_altivec (int16_t * block, uint8_t * dest, int stride);
-void idct_block_add_altivec (int16_t * block, uint8_t * dest, int stride);
-void idct_altivec_init (void);
-#endif
+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);
+void mpeg2_idct_altivec_init (void);
/* motion_comp.c */
-void motion_comp_init (void);
-
-typedef struct mc_functions_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);
-} mc_functions_t;
-
-#define MOTION_COMP_EXTERN(x) mc_functions_t mc_functions_##x = \
-{ \
- {MC_put_16_##x, MC_put_x16_##x, MC_put_y16_##x, MC_put_xy16_##x, \
- MC_put_8_##x, MC_put_x8_##x, MC_put_y8_##x, MC_put_xy8_##x}, \
- {MC_avg_16_##x, MC_avg_x16_##x, MC_avg_y16_##x, MC_avg_xy16_##x, \
- MC_avg_8_##x, MC_avg_x8_##x, MC_avg_y8_##x, MC_avg_xy8_##x} \
+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 mc_functions_t mc_functions_c;
-extern mc_functions_t mc_functions_mmx;
-extern mc_functions_t mc_functions_mmxext;
-extern mc_functions_t mc_functions_3dnow;
-#ifdef ENABLE_ALTIVEC
-extern mc_functions_t mc_functions_altivec;
-#endif
-extern mc_functions_t mc_functions_mlib;
+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;
/* slice.c */
-int slice_process (picture_t *picture, uint8_t code, uint8_t * buffer);
+void mpeg2_slice (picture_t * picture, int code, uint8_t * buffer);
/* stats.c */
-void stats_header (uint8_t code, uint8_t * buffer);
+void mpeg2_stats (int code, uint8_t * buffer);
diff --git a/src/libmpeg2/slice.c b/src/libmpeg2/slice.c
index 3cd547f24..555b10782 100644
--- a/src/libmpeg2/slice.c
+++ b/src/libmpeg2/slice.c
@@ -1,8 +1,10 @@
/*
* slice.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -28,9 +30,11 @@
#include "mpeg2_internal.h"
#include "attributes.h"
-extern mc_functions_t mc_functions;
-extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
-extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride);
+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_cpu_state_save) (cpu_state_t * state);
+extern void (* mpeg2_cpu_state_restore) (cpu_state_t * state);
#include "vlc.h"
@@ -210,17 +214,19 @@ static inline int get_motion_delta (picture_t * picture, int f_code)
static inline int bound_motion_vector (int vector, int f_code)
{
#if 1
- int limit;
+ unsigned int limit;
+ int sign;
limit = 16 << f_code;
- if (vector >= limit)
- return vector - 2*limit;
- else if (vector < -limit)
- return vector + 2*limit;
- else return vector;
+ if ((unsigned int)(vector + limit) < 2 * limit)
+ return vector;
+ else {
+ sign = ((int32_t)vector) >> 31;
+ return vector - ((2 * limit) ^ sign) + sign;
+ }
#else
- return (vector << (27 - f_code)) >> (27 - f_code);
+ return ((int32_t)vector << (27 - f_code)) >> (27 - f_code);
#endif
}
@@ -252,7 +258,7 @@ static inline int get_coded_block_pattern (picture_t * picture)
if (bit_buf >= 0x20000000) {
- tab = CBP_7 - 16 + UBITS (bit_buf, 7);
+ tab = CBP_7 + (UBITS (bit_buf, 7) - 16);
DUMPBITS (bit_buf, bits, tab->len);
return tab->cbp;
@@ -292,7 +298,7 @@ static inline int get_luma_dc_dct_diff (picture_t * picture)
return 0;
}
} else {
- tab = DC_long - 0x1e0 + UBITS (bit_buf, 9);
+ tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0);
size = tab->size;
DUMPBITS (bit_buf, bits, tab->len);
NEEDBITS (bit_buf, bits, bit_ptr);
@@ -329,7 +335,7 @@ static inline int get_chroma_dc_dct_diff (picture_t * picture)
return 0;
}
} else {
- tab = DC_long - 0x3e0 + UBITS (bit_buf, 10);
+ tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0);
size = tab->size;
DUMPBITS (bit_buf, bits, tab->len + 1);
NEEDBITS (bit_buf, bits, bit_ptr);
@@ -376,7 +382,7 @@ static void get_intra_block_B14 (picture_t * picture)
while (1) {
if (bit_buf >= 0x28000000) {
- tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
i += tab->run;
if (i >= 64)
@@ -402,7 +408,7 @@ static void get_intra_block_B14 (picture_t * picture)
} else if (bit_buf >= 0x04000000) {
- tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64)
@@ -431,17 +437,17 @@ static void get_intra_block_B14 (picture_t * picture)
continue;
} else if (bit_buf >= 0x02000000) {
- tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+ 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 - 16 + UBITS (bit_buf, 13);
+ 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 - 16 + UBITS (bit_buf, 15);
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
@@ -490,7 +496,7 @@ static void get_intra_block_B15 (picture_t * picture)
while (1) {
if (bit_buf >= 0x04000000) {
- tab = DCT_B15_8 - 4 + UBITS (bit_buf, 8);
+ tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64) {
@@ -544,17 +550,17 @@ static void get_intra_block_B15 (picture_t * picture)
}
} else if (bit_buf >= 0x02000000) {
- tab = DCT_B15_10 - 8 + UBITS (bit_buf, 10);
+ 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 - 16 + UBITS (bit_buf, 13);
+ 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 - 16 + UBITS (bit_buf, 15);
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
@@ -600,7 +606,7 @@ static void get_non_intra_block (picture_t * picture)
NEEDBITS (bit_buf, bits, bit_ptr);
if (bit_buf >= 0x28000000) {
- tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
goto entry_1;
} else
goto entry_2;
@@ -608,7 +614,7 @@ static void get_non_intra_block (picture_t * picture)
while (1) {
if (bit_buf >= 0x28000000) {
- tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
entry_1:
i += tab->run;
@@ -638,7 +644,7 @@ static void get_non_intra_block (picture_t * picture)
entry_2:
if (bit_buf >= 0x04000000) {
- tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64)
@@ -667,17 +673,17 @@ static void get_non_intra_block (picture_t * picture)
continue;
} else if (bit_buf >= 0x02000000) {
- tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+ 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 - 16 + UBITS (bit_buf, 13);
+ 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 - 16 + UBITS (bit_buf, 15);
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
@@ -724,7 +730,7 @@ static void get_mpeg1_intra_block (picture_t * picture)
while (1) {
if (bit_buf >= 0x28000000) {
- tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
i += tab->run;
if (i >= 64)
@@ -752,7 +758,7 @@ static void get_mpeg1_intra_block (picture_t * picture)
} else if (bit_buf >= 0x04000000) {
- tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64)
@@ -787,17 +793,17 @@ static void get_mpeg1_intra_block (picture_t * picture)
continue;
} else if (bit_buf >= 0x02000000) {
- tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+ 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 - 16 + UBITS (bit_buf, 13);
+ 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 - 16 + UBITS (bit_buf, 15);
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
@@ -840,7 +846,7 @@ static void get_mpeg1_non_intra_block (picture_t * picture)
NEEDBITS (bit_buf, bits, bit_ptr);
if (bit_buf >= 0x28000000) {
- tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
goto entry_1;
} else
goto entry_2;
@@ -848,7 +854,7 @@ static void get_mpeg1_non_intra_block (picture_t * picture)
while (1) {
if (bit_buf >= 0x28000000) {
- tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+ tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
entry_1:
i += tab->run;
@@ -880,7 +886,7 @@ static void get_mpeg1_non_intra_block (picture_t * picture)
entry_2:
if (bit_buf >= 0x04000000) {
- tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+ tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64)
@@ -916,17 +922,17 @@ static void get_mpeg1_non_intra_block (picture_t * picture)
continue;
} else if (bit_buf >= 0x02000000) {
- tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+ 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 - 16 + UBITS (bit_buf, 13);
+ 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 - 16 + UBITS (bit_buf, 15);
+ tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
@@ -946,35 +952,6 @@ static void get_mpeg1_non_intra_block (picture_t * picture)
picture->bitstream_ptr = bit_ptr;
}
-#define GET_MACROBLOCK_ADDRESS_INCREMENT(increment) \
-do { \
- MBAtab * tab; \
- \
- increment = 0; \
- \
- while (1) { \
- if (bit_buf >= 0x10000000) { \
- tab = MBA_5 - 2 + UBITS (bit_buf, 5); \
- break; \
- } else if (bit_buf >= 0x03000000) { \
- tab = MBA_11 - 24 + UBITS (bit_buf, 11); \
- break; \
- } else switch (UBITS (bit_buf, 11)) { \
- case 8: /* macroblock_escape */ \
- increment += 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 */ \
- return (mba >= picture->last_mba); \
- } \
- } \
- DUMPBITS (bit_buf, bits, tab->len); \
- increment += tab->mba; \
-} while (0)
-
static inline void slice_intra_DCT (picture_t * picture, int cc,
uint8_t * dest, int stride)
{
@@ -998,7 +975,7 @@ static inline void slice_intra_DCT (picture_t * picture, int cc,
get_intra_block_B15 (picture);
else
get_intra_block_B14 (picture);
- idct_block_copy (picture->DCTblock, dest, stride);
+ mpeg2_idct_copy (picture->DCTblock, dest, stride);
#undef bit_buf
#undef bits
#undef bit_ptr
@@ -1007,124 +984,97 @@ static inline void slice_intra_DCT (picture_t * picture, int cc,
static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest,
int stride)
{
- if (!picture->skip_non_intra_dct)
- memset (picture->DCTblock, 0, 64 * sizeof (int16_t));
+ memset (picture->DCTblock, 0, 64 * sizeof (int16_t));
if (picture->mpeg1)
get_mpeg1_non_intra_block (picture);
else
- get_non_intra_block (picture);
- if (!picture->skip_non_intra_dct)
- idct_block_add (picture->DCTblock, dest, stride);
+ get_non_intra_block (picture);
+ mpeg2_idct_add (picture->DCTblock, dest, stride);
}
-#define MOTION_Y(table,offset_x,offset_y,motion_x,motion_y, \
- dest,src,offset_dest,offset_src,stride,height) \
-do { \
- int xy_half; \
- int total_offset; \
- \
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
- total_offset = ((offset_y + (motion_y >> 1)) * stride + \
- offset_x + (motion_x >> 1) + (offset_src)); \
- table[xy_half] (dest[0] + offset_x + (offset_dest), \
- src[0] + total_offset, stride, height); \
-} while (0)
-
-#define MOTION_UV(table,offset_x,offset_y,motion_x,motion_y, \
- dest,src,offset_dest,offset_src,stride,height) \
-do { \
- int xy_half; \
- int total_offset; \
- \
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
- total_offset = (((offset_y + motion_y) >> 1) * (stride) + \
- ((offset_x + motion_x) >> 1) + (offset_src)); \
- table[4+xy_half] (dest[1] + (offset_x >> 1) + (offset_dest), \
- src[1] + total_offset, stride, height); \
- table[4+xy_half] (dest[2] + (offset_x >> 1) + (offset_dest), \
- src[2] + total_offset, stride, height); \
-} while (0)
-
-static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
- int32_t, int32_t),
- int x_offset, int y_offset, int mb_y_8_offset,
- int src_field, int dest_field,
- int x_pred, int y_pred,
- uint8_t * dest[3], uint8_t * src[3],
- int stride, int height)
-{
- MOTION_Y (table, x_offset, y_offset, x_pred, y_pred, dest, src,
- dest_field + mb_y_8_offset*8*stride, src_field, stride, height);
-
- x_pred /= 2;
- y_pred /= 2;
- stride >>= 1;
- height >>= 1;
-
- MOTION_UV (table, x_offset, y_offset, x_pred, y_pred, dest, src,
- (dest_field >> 1) + mb_y_8_offset*4*stride, src_field >> 1,
- stride, height);
-}
+#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->stride + picture->offset, \
+ ref[0] + (pos_x >> 1) + (pos_y >> 1) * picture->stride, \
+ picture->stride, size); \
+ motion_x /= 2; motion_y /= 2; \
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
+ offset = (((picture->offset + motion_x) >> 1) + \
+ ((((picture->v_offset + motion_y) >> 1) + y/2) * \
+ picture->uv_stride)); \
+ table[4+xy_half] (picture->dest[1] + y/2 * picture->uv_stride + \
+ (picture->offset >> 1), ref[1] + offset, \
+ picture->uv_stride, size/2); \
+ table[4+xy_half] (picture->dest[2] + y/2 * picture->uv_stride + \
+ (picture->offset >> 1), ref[2] + offset, \
+ picture->uv_stride, size/2)
+
+#define MOTION_FIELD(table,ref,motion_x,motion_y,dest_field,op,src_field) \
+ pos_x = 2 * picture->offset + motion_x; \
+ pos_y = picture->v_offset + motion_y; \
+ if ((pos_x > picture->limit_x) || (pos_y > picture->limit_y)) \
+ return; \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ table[xy_half] (picture->dest[0] + dest_field * picture->stride + \
+ picture->offset, \
+ (ref[0] + (pos_x >> 1) + \
+ ((pos_y op) + src_field) * picture->stride), \
+ 2 * picture->stride, 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 op) + src_field) * \
+ picture->uv_stride)); \
+ table[4+xy_half] (picture->dest[1] + dest_field * picture->uv_stride + \
+ (picture->offset >> 1), ref[1] + offset, \
+ 2 * picture->uv_stride, 4); \
+ table[4+xy_half] (picture->dest[2] + dest_field * picture->uv_stride + \
+ (picture->offset >> 1), ref[2] + offset, \
+ 2 * picture->uv_stride, 4)
static void motion_mp1 (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
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, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
- motion_x = motion->pmv[0][0] + get_motion_delta (picture,
- motion->f_code[0]);
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+ motion_x = (motion->pmv[0][0] +
+ (get_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_motion_delta (picture,
- motion->f_code[0]);
- motion_y = bound_motion_vector (motion_y, motion->f_code[0]);
+ motion_y = (motion->pmv[0][1] +
+ (get_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;
- if (motion->f_code[1]) {
- motion_x <<= 1;
- motion_y <<= 1;
- }
-
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y, dest, motion->ref[0], stride, 16);
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0);
#undef bit_buf
#undef bits
#undef bit_ptr
}
-static void motion_mp1_reuse (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
- void (** table) (uint8_t *, uint8_t *, int, int))
-{
- int motion_x, motion_y;
-
- motion_x = motion->pmv[0][0];
- motion_y = motion->pmv[0][1];
-
- if (motion->f_code[1]) {
- motion_x <<= 1;
- motion_y <<= 1;
- }
-
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y, dest, motion->ref[0], stride, 16);
-}
-
static void motion_fr_frame (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
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, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[0][0] + get_motion_delta (picture,
@@ -1138,25 +1088,23 @@ static void motion_fr_frame (picture_t * picture, motion_t * motion,
motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y, dest, motion->ref[0], stride, 16);
+ 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,
- uint8_t * dest[3], int offset, int stride,
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;
- int field_select;
+ int motion_x, motion_y, field;
+ unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
- field_select = SBITS (bit_buf, 1);
+ field = UBITS (bit_buf, 1);
DUMPBITS (bit_buf, bits, 1);
motion_x = motion->pmv[0][0] + get_motion_delta (picture,
@@ -1170,12 +1118,10 @@ static void motion_fr_field (picture_t * picture, motion_t * motion,
/* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
motion->pmv[0][1] = motion_y << 1;
- motion_block (table, offset, picture->v_offset >> 1,
- 0, (field_select & stride), 0,
- motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
+ MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field);
NEEDBITS (bit_buf, bits, bit_ptr);
- field_select = SBITS (bit_buf, 1);
+ field = UBITS (bit_buf, 1);
DUMPBITS (bit_buf, bits, 1);
motion_x = motion->pmv[1][0] + get_motion_delta (picture,
@@ -1189,84 +1135,106 @@ static void motion_fr_field (picture_t * picture, motion_t * motion,
/* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
motion->pmv[1][1] = motion_y << 1;
- motion_block (table, offset, picture->v_offset >> 1,
- 0, (field_select & stride), stride,
- motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
+ 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,
- uint8_t * dest[3], int offset, int stride,
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;
- int dmv_x, dmv_y;
- int m;
- int other_x, other_y;
+ int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y;
+ unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[0][0] + get_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_dmv (picture);
- NEEDBITS (bit_buf, bits, bit_ptr);
motion_y = (motion->pmv[0][1] >> 1) + get_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;
-
- NEEDBITS (bit_buf, bits, bit_ptr);
dmv_y = get_dmv (picture);
- motion_block (mc_functions.put, offset, picture->v_offset >> 1, 0, 0, 0,
- motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
-
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_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, stride, 0,
- other_x, other_y, dest, motion->ref[0], stride * 2, 8);
-
- motion_block (mc_functions.put, offset, picture->v_offset >> 1,
- 0, stride, stride,
- motion_x, motion_y, dest, motion->ref[0], stride * 2, 8);
+ 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_block (mc_functions.avg, offset, picture->v_offset >> 1, 0, 0, stride,
- other_x, other_y, dest, motion->ref[0], stride * 2, 8);
+ 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->stride);
+ mpeg2_mc.avg[xy_half]
+ (picture->dest[0] + picture->offset,
+ motion->ref[0][0] + offset, 2 * picture->stride, 8);
+ mpeg2_mc.avg[xy_half]
+ (picture->dest[0] + picture->stride + picture->offset,
+ motion->ref[0][0] + picture->stride + offset, 2 * picture->stride, 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->uv_stride));
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[1] + (picture->offset >> 1),
+ motion->ref[0][1] + offset, 2 * picture->uv_stride, 4);
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[1] + picture->uv_stride + (picture->offset >> 1),
+ motion->ref[0][1] + picture->uv_stride + offset,
+ 2 * picture->uv_stride, 4);
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[2] + (picture->offset >> 1),
+ motion->ref[0][2] + offset, 2 * picture->uv_stride, 4);
+ mpeg2_mc.avg[4+xy_half]
+ (picture->dest[2] + picture->uv_stride + (picture->offset >> 1),
+ motion->ref[0][2] + picture->uv_stride + offset,
+ 2 * picture->uv_stride, 4);
#undef bit_buf
#undef bits
#undef bit_ptr
}
-/* like motion_frame, but reuse previous motion vectors */
-static void motion_fr_reuse (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
- void (** table) (uint8_t *, uint8_t *, int, int))
+static void motion_reuse (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
{
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion->pmv[0][0], motion->pmv[0][1],
- dest, motion->ref[0], stride, 16);
+ int motion_x, motion_y;
+ unsigned int pos_x, pos_y, xy_half, offset;
+
+ motion_x = motion->pmv[0][0];
+ motion_y = motion->pmv[0][1];
+
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0);
}
-/* like motion_frame, but use null motion vectors */
-static void motion_fr_zero (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
- void (** table) (uint8_t *, uint8_t *, int, int))
+static void motion_zero (picture_t * picture, motion_t * motion,
+ void (** table) (uint8_t *, uint8_t *, int, int))
{
- motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
- dest, motion->ref[0], stride, 16);
+ unsigned int offset;
+
+ table[0] (picture->dest[0] + picture->offset,
+ (motion->ref[0][0] + picture->offset +
+ picture->v_offset * picture->stride),
+ picture->stride, 16);
+
+ offset = ((picture->offset >> 1) +
+ (picture->v_offset >> 1) * picture->uv_stride);
+ table[4] (picture->dest[1] + (picture->offset >> 1),
+ motion->ref[0][1] + offset, picture->uv_stride, 8);
+ table[4] (picture->dest[2] + (picture->offset >> 1),
+ motion->ref[0][2] + offset, picture->uv_stride, 8);
}
/* like motion_frame, but parsing without actual motion compensation */
@@ -1296,20 +1264,19 @@ static void motion_fr_conceal (picture_t * picture)
}
static void motion_fi_field (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
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;
- int field_select;
+ uint8_t ** ref_field;
+ unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
- field_select = UBITS (bit_buf, 1);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
DUMPBITS (bit_buf, bits, 1);
- NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[0][0] + get_motion_delta (picture,
motion->f_code[0]);
motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
@@ -1321,29 +1288,26 @@ static void motion_fi_field (picture_t * picture, motion_t * motion,
motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y,
- dest, motion->ref[field_select], stride, 16);
+ 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,
- uint8_t * dest[3], int offset, int stride,
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;
- int field_select;
+ uint8_t ** ref_field;
+ unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
- field_select = UBITS (bit_buf, 1);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
DUMPBITS (bit_buf, bits, 1);
- NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[0][0] + get_motion_delta (picture,
motion->f_code[0]);
motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
@@ -1355,15 +1319,12 @@ static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
motion->pmv[0][1] = motion_y;
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y,
- dest, motion->ref[field_select], stride, 8);
+ MOTION (table, ref_field, motion_x, motion_y, 8, 0);
NEEDBITS (bit_buf, bits, bit_ptr);
- field_select = UBITS (bit_buf, 1);
+ ref_field = motion->ref2[UBITS (bit_buf, 1)];
DUMPBITS (bit_buf, bits, 1);
- NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[1][0] + get_motion_delta (picture,
motion->f_code[0]);
motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
@@ -1375,74 +1336,43 @@ static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
motion->pmv[1][1] = motion_y;
- motion_block (table, offset, picture->v_offset+8, 1, 0, 0,
- motion_x, motion_y,
- dest, motion->ref[field_select], stride, 8);
+ 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,
- uint8_t * dest[3], int offset, int stride,
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;
- int dmv_x, dmv_y;
+ int motion_x, motion_y, other_x, other_y;
+ unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
motion_x = motion->pmv[0][0] + get_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_dmv (picture);
+ other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (picture);
- NEEDBITS (bit_buf, bits, bit_ptr);
motion_y = motion->pmv[0][1] + get_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_dmv (picture) +
+ picture->dmv_offset);
- NEEDBITS (bit_buf, bits, bit_ptr);
- dmv_y = get_dmv (picture);
-
- motion_block (mc_functions.put, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y,
- dest, motion->ref[picture->current_field], stride, 16);
-
- motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
- motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
- 2 * picture->current_field - 1;
- motion_block (mc_functions.avg, offset, picture->v_offset, 0, 0, 0,
- motion_x, motion_y,
- dest, motion->ref[!picture->current_field], stride, 16);
+ 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_reuse (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
- void (** table) (uint8_t *, uint8_t *, int, int))
-{
- motion_block (table, offset, picture->v_offset, 0, 0, 0,
- motion->pmv[0][0], motion->pmv[0][1],
- dest, motion->ref[picture->current_field], stride, 16);
-}
-
-static void motion_fi_zero (picture_t * picture, motion_t * motion,
- uint8_t * dest[3], int offset, int stride,
- void (** table) (uint8_t *, uint8_t *, int, int))
-{
- motion_block (table, offset, picture->v_offset, 0, 0, 0, 0, 0,
- dest, motion->ref[picture->current_field], stride, 16);
-}
-
static void motion_fi_conceal (picture_t * picture)
{
#define bit_buf (picture->bitstream_buf)
@@ -1453,7 +1383,6 @@ static void motion_fi_conceal (picture_t * picture)
NEEDBITS (bit_buf, bits, bit_ptr);
DUMPBITS (bit_buf, bits, 1); /* remove field_select */
- NEEDBITS (bit_buf, bits, bit_ptr);
tmp = (picture->f_motion.pmv[0][0] +
get_motion_delta (picture, picture->f_motion.f_code[0]));
tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
@@ -1471,118 +1400,146 @@ static void motion_fi_conceal (picture_t * picture)
#undef bit_ptr
}
-#define MOTION(routine,direction) \
-do { \
- if ((direction) & MACROBLOCK_MOTION_FORWARD) \
- routine (picture, &(picture->f_motion), dest, offset, stride, \
- mc_functions.put); \
- if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
- routine (picture, &(picture->b_motion), dest, offset, stride, \
- ((direction) & MACROBLOCK_MOTION_FORWARD ? \
- mc_functions.avg : mc_functions.put)); \
+#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 CHECK_DISPLAY \
+#define NEXT_MACROBLOCK \
do { \
- if (offset == picture->coded_picture_width) { \
+ 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, \
- dest); \
+ picture->dest); \
if (picture->picture_coding_type == B_TYPE) \
break; \
} \
- dest[0] += 16 * stride; \
- dest[1] += 4 * stride; \
- dest[2] += 4 * stride; \
+ picture->dest[0] += 16 * picture->stride; \
+ picture->dest[1] += 4 * picture->stride; \
+ picture->dest[2] += 4 * picture->stride; \
} while (0); \
- if (! (picture->mpeg1)) \
- return (mba >= picture->last_mba); \
picture->v_offset += 16; \
- if (picture->v_offset >= picture->coded_picture_height) \
- return 1; \
- offset = 0; \
+ if (picture->v_offset > picture->limit_y) { \
+ if (mpeg2_cpu_state_restore) \
+ mpeg2_cpu_state_restore (&cpu_state); \
+ return; \
+ } \
+ picture->offset = 0; \
} \
} while (0)
-int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
+static inline int slice_init (picture_t * picture, int code)
{
#define bit_buf (picture->bitstream_buf)
#define bits (picture->bitstream_bits)
#define bit_ptr (picture->bitstream_ptr)
- int macroblock_modes;
- int stride;
- uint8_t * dest[3];
- int offset;
- uint8_t ** forward_ref[2];
- int mba;
+ int offset, stride, height;
+ struct vo_frame_s * forward_reference_frame;
+ struct vo_frame_s * backward_reference_frame;
+ MBAtab * mba;
stride = picture->coded_picture_width;
- mba = (code-1) * (stride >> 4);
- offset = (code - 1) * stride * 4;
- picture->v_offset = (code - 1) * 16;
+ offset = picture->picture_structure == BOTTOM_FIELD ? stride : 0;
+
+ if( picture->forward_reference_frame ) {
+ forward_reference_frame = picture->forward_reference_frame;
+ }
+ else {
+ forward_reference_frame = picture->current_frame;
+ }
+
+ if( picture->backward_reference_frame ) {
+ backward_reference_frame = picture->backward_reference_frame;
+ }
+ else {
+ backward_reference_frame = picture->current_frame;
+ }
+
+ picture->f_motion.ref[0][0] =
+ forward_reference_frame->base[0] + offset;
+ picture->f_motion.ref[0][1] =
+ forward_reference_frame->base[1] + (offset >> 1);
+ picture->f_motion.ref[0][2] =
+ forward_reference_frame->base[2] + (offset >> 1);
+
+ picture->b_motion.ref[0][0] =
+ backward_reference_frame->base[0] + offset;
+ picture->b_motion.ref[0][1] =
+ backward_reference_frame->base[1] + (offset >> 1);
+ picture->b_motion.ref[0][2] =
+ backward_reference_frame->base[2] + (offset >> 1);
+
+ 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];
+ offset = bottom_field ? 0 : stride;
+
+ 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] + offset;
+ picture->f_motion.ref[1][1] = forward_ref[1] + (offset >> 1);
+ picture->f_motion.ref[1][2] = forward_ref[2] + (offset >> 1);
- if (picture->forward_reference_frame) {
- forward_ref[0] = picture->forward_reference_frame->base;
- if (picture->picture_structure != FRAME_PICTURE) {
- forward_ref[1] = picture->forward_reference_frame->base;
- offset <<= 1;
- picture->current_field = (picture->picture_structure == BOTTOM_FIELD);
- if ((picture->second_field) &&
- (picture->picture_coding_type != B_TYPE))
- forward_ref[picture->picture_structure == TOP_FIELD] =
- picture->current_frame->base;
-
- picture->f_motion.ref[1][0] = forward_ref[1][0] + stride;
- picture->f_motion.ref[1][1] = forward_ref[1][1] + (stride >> 1);
- picture->f_motion.ref[1][2] = forward_ref[1][2] + (stride >> 1);
-
picture->b_motion.ref[1][0] =
- picture->backward_reference_frame->base[0] + stride;
+ backward_reference_frame->base[0] + offset;
picture->b_motion.ref[1][1] =
- picture->backward_reference_frame->base[1] + (stride >> 1);
+ backward_reference_frame->base[1] + (offset >> 1);
picture->b_motion.ref[1][2] =
- picture->backward_reference_frame->base[2] + (stride >> 1);
- }
-
- picture->f_motion.ref[0][0] = forward_ref[0][0];
- picture->f_motion.ref[0][1] = forward_ref[0][1];
- picture->f_motion.ref[0][2] = forward_ref[0][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.ref[0][0] = picture->backward_reference_frame->base[0];
- picture->b_motion.ref[0][1] = picture->backward_reference_frame->base[1];
- picture->b_motion.ref[0][2] = picture->backward_reference_frame->base[2];
-
- 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;
+ backward_reference_frame->base[2] + (offset >> 1);
}
- if ((picture->current_frame->copy) &&
- (picture->picture_coding_type == B_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;
+ 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) * stride;
+ offset <<= picture->picture_structure == FRAME_PICTURE ? 2 : 3;
+ if (picture->current_frame->copy && picture->picture_coding_type == B_TYPE)
offset = 0;
- dest[0] = picture->current_frame->base[0] + offset * 4;
- dest[1] = picture->current_frame->base[1] + offset;
- dest[2] = picture->current_frame->base[2] + offset;
+ picture->dest[0] = picture->current_frame->base[0] + offset * 4;
+ picture->dest[1] = picture->current_frame->base[1] + offset;
+ picture->dest[2] = picture->current_frame->base[2] + offset;
+ height = picture->coded_picture_height;
switch (picture->picture_structure) {
case BOTTOM_FIELD:
- dest[0] += stride;
- dest[1] += stride >> 1;
- dest[2] += stride >> 1;
+ picture->dest[0] += stride;
+ picture->dest[1] += stride >> 1;
+ picture->dest[2] += stride >> 1;
/* follow thru */
case TOP_FIELD:
stride <<= 1;
+ height >>= 1;
}
+ picture->stride = stride;
+ picture->uv_stride = stride >> 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;
picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
- bitstream_init (picture, buffer);
-
picture->quantizer_scale = get_quantizer_scale (picture);
/* ignore intra_slice and all the extra data */
@@ -1590,15 +1547,72 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
DUMPBITS (bit_buf, bits, 9);
NEEDBITS (bit_buf, bits, bit_ptr);
}
- DUMPBITS (bit_buf, bits, 1);
- NEEDBITS (bit_buf, bits, bit_ptr);
- GET_MACROBLOCK_ADDRESS_INCREMENT (offset);
- mba += offset;
- offset <<= 4;
+ /* 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 * stride;
+ picture->dest[1] += 4 * stride;
+ picture->dest[2] += 4 * stride;
+ }
+ 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_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_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);
@@ -1611,6 +1625,8 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
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)
@@ -1625,22 +1641,23 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
}
if (macroblock_modes & DCT_TYPE_INTERLACED) {
- DCT_offset = stride;
- DCT_stride = stride * 2;
+ DCT_offset = picture->stride;
+ DCT_stride = picture->stride * 2;
} else {
- DCT_offset = stride * 8;
- DCT_stride = stride;
+ DCT_offset = picture->stride * 8;
+ DCT_stride = picture->stride;
}
- slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride);
- slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride);
- slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset,
- DCT_stride);
- slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8,
- DCT_stride);
-
- slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1);
- slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1);
+ offset = picture->offset;
+ dest_y = picture->dest[0] + offset;
+ slice_intra_DCT (picture, 0, dest_y, DCT_stride);
+ slice_intra_DCT (picture, 0, dest_y + 8, DCT_stride);
+ slice_intra_DCT (picture, 0, dest_y + DCT_offset, DCT_stride);
+ slice_intra_DCT (picture, 0, dest_y + DCT_offset + 8, DCT_stride);
+ slice_intra_DCT (picture, 1, picture->dest[1] + (offset >> 1),
+ picture->uv_stride);
+ slice_intra_DCT (picture, 2, picture->dest[2] + (offset >> 1),
+ picture->uv_stride);
if (picture->picture_coding_type == D_TYPE) {
NEEDBITS (bit_buf, bits, bit_ptr);
@@ -1648,29 +1665,21 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
}
} else {
- if (picture->mpeg1) {
- if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME)
- MOTION (motion_mp1, macroblock_modes);
- else {
- /* 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 (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
- }
- } else if (picture->picture_structure == FRAME_PICTURE)
+ if (picture->picture_structure == FRAME_PICTURE)
switch (macroblock_modes & MOTION_TYPE_MASK) {
case MC_FRAME:
- MOTION (motion_fr_frame, macroblock_modes);
+ if (picture->mpeg1)
+ MOTION_CALL (motion_mp1, macroblock_modes);
+ else
+ MOTION_CALL (motion_fr_frame, macroblock_modes);
break;
case MC_FIELD:
- MOTION (motion_fr_field, macroblock_modes);
+ MOTION_CALL (motion_fr_field, macroblock_modes);
break;
case MC_DMV:
- MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
+ MOTION_CALL (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
break;
case 0:
@@ -1679,21 +1688,21 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
picture->f_motion.pmv[0][1] = 0;
picture->f_motion.pmv[1][0] = 0;
picture->f_motion.pmv[1][1] = 0;
- MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
+ MOTION_CALL (motion_zero, MACROBLOCK_MOTION_FORWARD);
break;
}
else
switch (macroblock_modes & MOTION_TYPE_MASK) {
case MC_FIELD:
- MOTION (motion_fi_field, macroblock_modes);
+ MOTION_CALL (motion_fi_field, macroblock_modes);
break;
case MC_16X8:
- MOTION (motion_fi_16x8, macroblock_modes);
+ MOTION_CALL (motion_fi_16x8, macroblock_modes);
break;
case MC_DMV:
- MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
+ MOTION_CALL (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
break;
case 0:
@@ -1702,88 +1711,96 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
picture->f_motion.pmv[0][1] = 0;
picture->f_motion.pmv[1][0] = 0;
picture->f_motion.pmv[1][1] = 0;
- MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
+ 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 = stride;
- DCT_stride = stride * 2;
+ DCT_offset = picture->stride;
+ DCT_stride = picture->stride * 2;
} else {
- DCT_offset = stride * 8;
- DCT_stride = stride;
+ DCT_offset = picture->stride * 8;
+ DCT_stride = picture->stride;
}
coded_block_pattern = get_coded_block_pattern (picture);
-
+
+ offset = picture->offset;
+ dest_y = picture->dest[0] + offset;
if (coded_block_pattern & 0x20)
- slice_non_intra_DCT (picture, dest[0] + offset,
- DCT_stride);
+ slice_non_intra_DCT (picture, dest_y, DCT_stride);
if (coded_block_pattern & 0x10)
- slice_non_intra_DCT (picture, dest[0] + offset + 8,
- DCT_stride);
+ slice_non_intra_DCT (picture, dest_y + 8, DCT_stride);
if (coded_block_pattern & 0x08)
- slice_non_intra_DCT (picture,
- dest[0] + offset + DCT_offset,
+ slice_non_intra_DCT (picture, dest_y + DCT_offset,
DCT_stride);
if (coded_block_pattern & 0x04)
- slice_non_intra_DCT (picture,
- dest[0] + offset + DCT_offset + 8,
+ slice_non_intra_DCT (picture, dest_y + DCT_offset + 8,
DCT_stride);
-
if (coded_block_pattern & 0x2)
- slice_non_intra_DCT (picture, dest[1] + (offset >> 1),
- stride >> 1);
+ slice_non_intra_DCT (picture,
+ picture->dest[1] + (offset >> 1),
+ picture->uv_stride);
if (coded_block_pattern & 0x1)
- slice_non_intra_DCT (picture, dest[2] + (offset >> 1),
- stride >> 1);
+ slice_non_intra_DCT (picture,
+ picture->dest[2] + (offset >> 1),
+ picture->uv_stride);
}
picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
- picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
+ picture->dc_dct_pred[2] = 128 << picture->intra_dc_precision;
}
- mba++;
- offset += 16;
- CHECK_DISPLAY;
+ NEXT_MACROBLOCK;
NEEDBITS (bit_buf, bits, bit_ptr);
- GET_MACROBLOCK_ADDRESS_INCREMENT (mba_inc);
+ 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) {
picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
- picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
+ picture->dc_dct_pred[2] = 128 << picture->intra_dc_precision;
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->picture_structure == FRAME_PICTURE)
- MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
- else
- MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
-
- mba++;
- offset += 16;
- CHECK_DISPLAY;
+ MOTION_CALL (motion_zero, MACROBLOCK_MOTION_FORWARD);
+ NEXT_MACROBLOCK;
} while (--mba_inc);
} else {
do {
- if (picture->mpeg1)
- MOTION (motion_mp1_reuse, macroblock_modes);
- else if (picture->picture_structure == FRAME_PICTURE)
- MOTION (motion_fr_reuse, macroblock_modes);
- else
- MOTION (motion_fi_reuse, macroblock_modes);
-
- mba++;
- offset += 16;
- CHECK_DISPLAY;
+ MOTION_CALL (motion_reuse, macroblock_modes);
+ NEXT_MACROBLOCK;
} while (--mba_inc);
}
}
@@ -1791,7 +1808,4 @@ int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
#undef bit_buf
#undef bits
#undef bit_ptr
-
- return (mba >= picture->last_mba);
-
}
diff --git a/src/libmpeg2/stats.c b/src/libmpeg2/stats.c
index d62edb412..04de526f1 100644
--- a/src/libmpeg2/stats.c
+++ b/src/libmpeg2/stats.c
@@ -1,8 +1,10 @@
/*
* stats.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -28,7 +30,6 @@
#include "mpeg2_internal.h"
static int debug_level = -1;
-//static int debug_level = 1;
/* Determine is debug output is required. */
/* We could potentially have multiple levels of debug info */
@@ -151,7 +152,7 @@ static void stats_group (uint8_t * buffer)
(buffer[4] & 0x20) ? " broken_link" : "");
}
-static void stats_slice (uint8_t code, uint8_t * buffer)
+static void stats_slice (int code, uint8_t * buffer)
{
/* fprintf (stderr, " (slice %d)\n", code); */
}
@@ -256,7 +257,7 @@ static void stats_picture_coding_extension (uint8_t * buffer)
alternate_scan, repeat_first_field, progressive_frame);
}
-void stats_header (uint8_t code, uint8_t * buffer)
+void mpeg2_stats (int code, uint8_t * buffer)
{
if (! (debug_is_on ()))
return;
diff --git a/src/libmpeg2/vlc.h b/src/libmpeg2/vlc.h
index ed2e04f88..1e11e1424 100644
--- a/src/libmpeg2/vlc.h
+++ b/src/libmpeg2/vlc.h
@@ -1,8 +1,10 @@
/*
* vlc.h
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * 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
@@ -27,9 +29,10 @@ do { \
static inline void bitstream_init (picture_t * picture, uint8_t * start)
{
- picture->bitstream_buf = 0; GETWORD (picture->bitstream_buf, 16, start);
- picture->bitstream_ptr = start;
- picture->bitstream_bits = 0;
+ 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 */