aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar diego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-09-13 17:31:45 +0000
committerGravatar diego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-09-13 17:31:45 +0000
commitbbcccf2d197e4c127ed0de311cbcb5c0f82b4c9a (patch)
treeac15cc30cc25c2edd74b5b8a734c507557fd6e13
parent26972b8895117a6857b14928e30d978e30e57aaa (diff)
Update internal libmpeg2 copy to version 0.5.1.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27604 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--Changelog1
-rw-r--r--Copyright4
-rw-r--r--libmpeg2/alloc.c8
-rw-r--r--libmpeg2/alpha_asm.h6
-rw-r--r--libmpeg2/attributes.h5
-rw-r--r--libmpeg2/cpu_accel.c262
-rw-r--r--libmpeg2/cpu_state.c6
-rw-r--r--libmpeg2/decode.c40
-rw-r--r--libmpeg2/header.c224
-rw-r--r--libmpeg2/idct.c2
-rw-r--r--libmpeg2/idct_alpha.c2
-rw-r--r--libmpeg2/idct_altivec.c2
-rw-r--r--libmpeg2/idct_mmx.c6
-rw-r--r--libmpeg2/mmx.h5
-rw-r--r--libmpeg2/motion_comp_arm.c18
-rw-r--r--libmpeg2/motion_comp_arm_s.S3
-rw-r--r--libmpeg2/motion_comp_mmx.c6
-rw-r--r--libmpeg2/mpeg2.h17
-rw-r--r--libmpeg2/mpeg2_internal.h19
-rw-r--r--libmpeg2/slice.c56
-rw-r--r--libmpeg2/vis.h5
-rw-r--r--libmpeg2/vlc.h13
22 files changed, 421 insertions, 289 deletions
diff --git a/Changelog b/Changelog
index 80226b871d..f67276f635 100644
--- a/Changelog
+++ b/Changelog
@@ -56,6 +56,7 @@ MPlayer (1.0)
libmpeg2:
* enable Alpha/ARM optimizations in libmpeg2
* SSE2-optimized IDCT routines from upstream libmpeg2
+ * libmpeg2 updated to version 0.5.1
Drivers:
* replace PolypAudio by PulseAudio (-ao pulse)
diff --git a/Copyright b/Copyright
index 3589e06be9..47ae48b2d0 100644
--- a/Copyright
+++ b/Copyright
@@ -61,11 +61,11 @@ Copyright: 1998, 1999 Eric Smith <eric@brouhaha.com>
License: GNU General Public License
Name: libmpeg2
-Version: 0.4.1 + patches
+Version: 0.5.1 + patches
Homepage: http://libmpeg2.sourceforge.net/
Directory: libmpeg2
Copyright: 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- 2000-2003 Michel Lespinasse <walken@zoy.org>
+ 2000-2004 Michel Lespinasse <walken@zoy.org>
2002-2003 Falk Hueffner <falk@debian.org>
2003 David S. Miller <davem@redhat.com>
2003 Regis Duchesne <hpreg@zoy.org>
diff --git a/libmpeg2/alloc.c b/libmpeg2/alloc.c
index 0698937bce..71bc18b692 100644
--- a/libmpeg2/alloc.c
+++ b/libmpeg2/alloc.c
@@ -62,9 +62,9 @@ void mpeg2_free (void * buf)
free (*(((void **)buf) - 1));
}
-void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t),
- int free (void *))
+void mpeg2_malloc_hooks (void * alloc_func (unsigned, mpeg2_alloc_t),
+ int free_func (void *))
{
- malloc_hook = malloc;
- free_hook = free;
+ malloc_hook = alloc_func;
+ free_hook = free_func;
}
diff --git a/libmpeg2/alpha_asm.h b/libmpeg2/alpha_asm.h
index bf1081f249..1a296301da 100644
--- a/libmpeg2/alpha_asm.h
+++ b/libmpeg2/alpha_asm.h
@@ -20,8 +20,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef ALPHA_ASM_H
-#define ALPHA_ASM_H
+#ifndef LIBMPEG2_ALPHA_ASM_H
+#define LIBMPEG2_ALPHA_ASM_H
#include <inttypes.h>
@@ -178,4 +178,4 @@ struct unaligned_long { uint64_t l; } __attribute__((packed));
#error "Unknown compiler!"
#endif
-#endif /* ALPHA_ASM_H */
+#endif /* LIBMPEG2_ALPHA_ASM_H */
diff --git a/libmpeg2/attributes.h b/libmpeg2/attributes.h
index eefbc0dd1b..e005eef1c3 100644
--- a/libmpeg2/attributes.h
+++ b/libmpeg2/attributes.h
@@ -21,6 +21,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef LIBMPEG2_ATTRIBUTES_H
+#define LIBMPEG2_ATTRIBUTES_H
+
/* use gcc attribs to align critical data structures */
#ifdef ATTRIBUTE_ALIGNED_MAX
#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
@@ -35,3 +38,5 @@
#define likely(x) (x)
#define unlikely(x) (x)
#endif
+
+#endif /* LIBMPEG2_ATTRIBUTES_H */
diff --git a/libmpeg2/cpu_accel.c b/libmpeg2/cpu_accel.c
index 54b57f18a2..104ac2cfdf 100644
--- a/libmpeg2/cpu_accel.c
+++ b/libmpeg2/cpu_accel.c
@@ -1,6 +1,6 @@
/*
* cpu_accel.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 2000-2004 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"
-#include "cpudetect.h"
#include <inttypes.h>
@@ -34,21 +33,26 @@
#include "attributes.h"
#include "mpeg2_internal.h"
-#ifdef ACCEL_DETECT
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-
-/* MPlayer imports libmpeg2 as decoder, which detects MMX / 3DNow!
- * instructions via assembly. However, it is regarded as duplicated work
- * in MPlayer, so that we enforce using MPlayer's implementation.
- */
-#define MPLAYER_CPUDETECT
+#include "cpudetect.h"
-static inline uint32_t arch_accel (void)
+#if defined(ARCH_X86) || defined(ARCH_X86_64)
+static inline uint32_t arch_accel (uint32_t accel)
{
-#if !defined(MPLAYER_CPUDETECT)
- uint32_t eax, ebx, ecx, edx;
- int AMD;
- uint32_t caps;
+/* Use MPlayer CPU detection instead of libmpeg2 variant. */
+#if 0
+ if (accel & (MPEG2_ACCEL_X86_3DNOW | MPEG2_ACCEL_X86_MMXEXT))
+ accel |= MPEG2_ACCEL_X86_MMX;
+
+ if (accel & (MPEG2_ACCEL_X86_SSE2 | MPEG2_ACCEL_X86_SSE3))
+ accel |= MPEG2_ACCEL_X86_MMXEXT;
+
+ if (accel & (MPEG2_ACCEL_X86_SSE3))
+ accel |= MPEG2_ACCEL_X86_SSE2;
+
+#ifdef ACCEL_DETECT
+ if (accel & MPEG2_ACCEL_DETECT) {
+ uint32_t eax, ebx, ecx, edx;
+ int AMD;
#if defined(__x86_64__) || (!defined(PIC) && !defined(__PIC__))
#define cpuid(op,eax,ebx,ecx,edx) \
@@ -59,7 +63,7 @@ static inline uint32_t arch_accel (void)
"=d" (edx) \
: "a" (op) \
: "cc")
-#else /* PIC version : save ebx (not needed on x86_64) */
+#else /* PIC version : save ebx (not needed on x86_64) */
#define cpuid(op,eax,ebx,ecx,edx) \
__asm__ ("pushl %%ebx\n\t" \
"cpuid\n\t" \
@@ -74,70 +78,79 @@ static inline uint32_t arch_accel (void)
#endif
#ifndef __x86_64__ /* x86_64 supports the cpuid op */
- __asm__ ("pushf\n\t"
- "pushf\n\t"
- "pop %0\n\t"
- "movl %0,%1\n\t"
- "xorl $0x200000,%0\n\t"
- "push %0\n\t"
- "popf\n\t"
- "pushf\n\t"
- "pop %0\n\t"
- "popf"
- : "=r" (eax),
- "=r" (ebx)
- :
- : "cc");
-
- if (eax == ebx) /* no cpuid */
- return 0;
+ __asm__ ("pushf\n\t"
+ "pushf\n\t"
+ "pop %0\n\t"
+ "movl %0,%1\n\t"
+ "xorl $0x200000,%0\n\t"
+ "push %0\n\t"
+ "popf\n\t"
+ "pushf\n\t"
+ "pop %0\n\t"
+ "popf"
+ : "=r" (eax),
+ "=r" (ebx)
+ :
+ : "cc");
+
+ if (eax == ebx) /* no cpuid */
+ return accel;
#endif
- cpuid (0x00000000, eax, ebx, ecx, edx);
- if (!eax) /* vendor string only */
- return 0;
+ cpuid (0x00000000, eax, ebx, ecx, edx);
+ if (!eax) /* vendor string only */
+ return accel;
+
+ AMD = (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65);
- AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
+ cpuid (0x00000001, eax, ebx, ecx, edx);
+ if (! (edx & 0x00800000)) /* no MMX */
+ return accel;
- cpuid (0x00000001, eax, ebx, ecx, edx);
- if (! (edx & 0x00800000)) /* no MMX */
- return 0;
+ accel |= MPEG2_ACCEL_X86_MMX;
+ if (edx & 0x02000000) /* SSE - identical to AMD MMX ext. */
+ accel |= MPEG2_ACCEL_X86_MMXEXT;
- caps = MPEG2_ACCEL_X86_MMX;
- if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
- caps = MPEG2_ACCEL_X86_MMX | MPEG2_ACCEL_X86_MMXEXT;
+ if (edx & 0x04000000) /* SSE2 */
+ accel |= MPEG2_ACCEL_X86_SSE2;
- cpuid (0x80000000, eax, ebx, ecx, edx);
- if (eax < 0x80000001) /* no extended capabilities */
- return caps;
+ if (ecx & 0x00000001) /* SSE3 */
+ accel |= MPEG2_ACCEL_X86_SSE3;
- cpuid (0x80000001, eax, ebx, ecx, edx);
+ cpuid (0x80000000, eax, ebx, ecx, edx);
+ if (eax < 0x80000001) /* no extended capabilities */
+ return accel;
- if (edx & 0x80000000)
- caps |= MPEG2_ACCEL_X86_3DNOW;
+ cpuid (0x80000001, eax, ebx, ecx, edx);
- if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
- caps |= MPEG2_ACCEL_X86_MMXEXT;
+ if (edx & 0x80000000)
+ accel |= MPEG2_ACCEL_X86_3DNOW;
+
+ if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
+ accel |= MPEG2_ACCEL_X86_MMXEXT;
+ }
+#endif /* ACCEL_DETECT */
- return caps;
-#else /* MPLAYER_CPUDETECT: Use MPlayer's CPU capability property. */
- caps = 0;
+ return accel;
+
+#else /* 0 */
+ accel = 0;
if (gCpuCaps.hasMMX)
- caps |= MPEG2_ACCEL_X86_MMX;
+ accel |= MPEG2_ACCEL_X86_MMX;
if (gCpuCaps.hasSSE2)
- caps |= MPEG2_ACCEL_X86_SSE2;
+ accel |= MPEG2_ACCEL_X86_SSE2;
if (gCpuCaps.hasMMX2)
- caps |= MPEG2_ACCEL_X86_MMXEXT;
+ accel |= MPEG2_ACCEL_X86_MMXEXT;
if (gCpuCaps.has3DNow)
- caps |= MPEG2_ACCEL_X86_3DNOW;
+ accel |= MPEG2_ACCEL_X86_3DNOW;
- return caps;
+ return accel;
-#endif /* MPLAYER_CPUDETECT */
+#endif /* 0 */
}
#endif /* ARCH_X86 || ARCH_X86_64 */
-#if defined(ARCH_PPC) || defined(ARCH_SPARC)
+#if defined(ACCEL_DETECT) && (defined(ARCH_PPC) || defined(ARCH_SPARC))
#include <signal.h>
#include <setjmp.h>
@@ -154,96 +167,117 @@ static RETSIGTYPE sigill_handler (int sig)
canjump = 0;
siglongjmp (jmpbuf, 1);
}
+#endif /* ACCEL_DETECT && (ARCH_PPC || ARCH_SPARC) */
#ifdef ARCH_PPC
-static uint32_t arch_accel (void)
+static uint32_t arch_accel (uint32_t accel)
{
- static RETSIGTYPE (* oldsig) (int);
+#ifdef ACCEL_DETECT
+ if ((accel & (MPEG2_ACCEL_PPC_ALTIVEC | MPEG2_ACCEL_DETECT)) ==
+ MPEG2_ACCEL_DETECT) {
+ static RETSIGTYPE (* oldsig) (int);
- oldsig = signal (SIGILL, sigill_handler);
- if (sigsetjmp (jmpbuf, 1)) {
- signal (SIGILL, oldsig);
- return 0;
- }
+ oldsig = signal (SIGILL, sigill_handler);
+ if (sigsetjmp (jmpbuf, 1)) {
+ signal (SIGILL, oldsig);
+ return accel;
+ }
- canjump = 1;
+ canjump = 1;
#if defined(__APPLE_CC__) /* apple */
#define VAND(a,b,c) "vand v" #a ",v" #b ",v" #c "\n\t"
-#else /* gnu */
+#else /* gnu */
#define VAND(a,b,c) "vand " #a "," #b "," #c "\n\t"
#endif
- asm volatile ("mtspr 256, %0\n\t"
- VAND (0, 0, 0)
- :
- : "r" (-1));
+ asm volatile ("mtspr 256, %0\n\t"
+ VAND (0, 0, 0)
+ :
+ : "r" (-1));
- canjump = 0;
+ canjump = 0;
+ accel |= MPEG2_ACCEL_PPC_ALTIVEC;
+
+ signal (SIGILL, oldsig);
+ }
+#endif /* ACCEL_DETECT */
- signal (SIGILL, oldsig);
- return MPEG2_ACCEL_PPC_ALTIVEC;
+ return accel;
}
#endif /* ARCH_PPC */
#ifdef ARCH_SPARC
-static uint32_t arch_accel (void)
+static uint32_t arch_accel (uint32_t accel)
{
- static RETSIGTYPE (* oldsig) (int);
+ if (accel & MPEG2_ACCEL_SPARC_VIS2)
+ accel |= MPEG2_ACCEL_SPARC_VIS;
- oldsig = signal (SIGILL, sigill_handler);
- if (sigsetjmp (jmpbuf, 1)) {
- signal (SIGILL, oldsig);
- return 0;
- }
+#ifdef ACCEL_DETECT
+ if ((accel & (MPEG2_ACCEL_SPARC_VIS2 | MPEG2_ACCEL_DETECT)) ==
+ MPEG2_ACCEL_DETECT) {
+ static RETSIGTYPE (* oldsig) (int);
- canjump = 1;
+ oldsig = signal (SIGILL, sigill_handler);
+ if (sigsetjmp (jmpbuf, 1)) {
+ signal (SIGILL, oldsig);
+ return accel;
+ }
- /* pdist %f0, %f0, %f0 */
- __asm__ __volatile__(".word\t0x81b007c0");
+ canjump = 1;
- canjump = 0;
+ /* pdist %f0, %f0, %f0 */
+ __asm__ __volatile__(".word\t0x81b007c0");
- if (sigsetjmp (jmpbuf, 1)) {
- signal (SIGILL, oldsig);
- return MPEG2_ACCEL_SPARC_VIS;
- }
+ canjump = 0;
+ accel |= MPEG2_ACCEL_SPARC_VIS;
- canjump = 1;
+ if (sigsetjmp (jmpbuf, 1)) {
+ signal (SIGILL, oldsig);
+ return accel;
+ }
- /* edge8n %g0, %g0, %g0 */
- __asm__ __volatile__(".word\t0x81b00020");
+ canjump = 1;
- canjump = 0;
+ /* edge8n %g0, %g0, %g0 */
+ __asm__ __volatile__(".word\t0x81b00020");
+
+ canjump = 0;
+ accel |= MPEG2_ACCEL_SPARC_VIS2;
+
+ signal (SIGILL, oldsig);
+ }
+#endif /* ACCEL_DETECT */
- signal (SIGILL, oldsig);
- return MPEG2_ACCEL_SPARC_VIS | MPEG2_ACCEL_SPARC_VIS2;
+ return accel;
}
#endif /* ARCH_SPARC */
-#endif /* ARCH_PPC || ARCH_SPARC */
#ifdef ARCH_ALPHA
-static uint32_t arch_accel (void)
+static inline uint32_t arch_accel (uint32_t accel)
{
- uint64_t no_mvi;
+ if (accel & MPEG2_ACCEL_ALPHA_MVI)
+ accel |= MPEG2_ACCEL_ALPHA;
+
+#ifdef ACCEL_DETECT
+ if (accel & MPEG2_ACCEL_DETECT) {
+ uint64_t no_mvi;
+
+ asm volatile ("amask %1, %0"
+ : "=r" (no_mvi)
+ : "rI" (256)); /* AMASK_MVI */
+ accel |= no_mvi ? MPEG2_ACCEL_ALPHA : (MPEG2_ACCEL_ALPHA |
+ MPEG2_ACCEL_ALPHA_MVI);
+ }
+#endif /* ACCEL_DETECT */
- asm volatile ("amask %1, %0"
- : "=r" (no_mvi)
- : "rI" (256)); /* AMASK_MVI */
- return no_mvi ? MPEG2_ACCEL_ALPHA : (MPEG2_ACCEL_ALPHA |
- MPEG2_ACCEL_ALPHA_MVI);
+ return accel;
}
#endif /* ARCH_ALPHA */
-#endif /* ACCEL_DETECT */
-uint32_t mpeg2_detect_accel (void)
+uint32_t mpeg2_detect_accel (uint32_t accel)
{
- uint32_t accel;
-
- accel = 0;
-#ifdef ACCEL_DETECT
#if defined (ARCH_X86) || defined (ARCH_X86_64) || defined (ARCH_PPC) || defined (ARCH_ALPHA) || defined (ARCH_SPARC)
- accel = arch_accel ();
-#endif
+ accel = arch_accel (accel);
#endif
return accel;
}
diff --git a/libmpeg2/cpu_state.c b/libmpeg2/cpu_state.c
index 5b773b245e..2f2f64a987 100644
--- a/libmpeg2/cpu_state.c
+++ b/libmpeg2/cpu_state.c
@@ -19,10 +19,6 @@
* 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
- *
- * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
- * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
- * $Id$
*/
#include "config.h"
@@ -54,7 +50,7 @@ static void state_restore_mmx (cpu_state_t * state)
#define STVX(a,b,c) "stvx v" #a ",r" #b ",r" #c "\n\t"
#define LVX0(a,b,c) "lvx v" #a ",0,r" #c "\n\t"
#define LVX(a,b,c) "lvx v" #a ",r" #b ",r" #c "\n\t"
-#else /* gnu */
+#else /* gnu */
#define LI(a,b) "li " #a "," #b "\n\t"
#define STVX0(a,b,c) "stvx " #a ",0," #c "\n\t"
#define STVX(a,b,c) "stvx " #a "," #b "," #c "\n\t"
diff --git a/libmpeg2/decode.c b/libmpeg2/decode.c
index d9ae05c9a8..f30b86b740 100644
--- a/libmpeg2/decode.c
+++ b/libmpeg2/decode.c
@@ -135,20 +135,20 @@ static inline mpeg2_state_t seek_chunk (mpeg2dec_t * mpeg2dec)
}
mpeg2dec->bytes_since_tag += skipped;
mpeg2dec->code = mpeg2dec->buf_start[-1];
- return (mpeg2_state_t)-1;
+ return STATE_INTERNAL_NORETURN;
}
mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
{
- while (mpeg2dec->code != 0xb3 &&
- ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
- mpeg2dec->code) || mpeg2dec->sequence.width == (unsigned)-1))
+ while (!(mpeg2dec->code == 0xb3 ||
+ ((mpeg2dec->code == 0xb7 || mpeg2dec->code == 0xb8 ||
+ !mpeg2dec->code) && mpeg2dec->sequence.width != (unsigned)-1)))
if (seek_chunk (mpeg2dec) == STATE_BUFFER)
return STATE_BUFFER;
mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
mpeg2dec->user_data_len = 0;
- return (mpeg2dec->code ? mpeg2_parse_header (mpeg2dec) :
- mpeg2_header_picture_start (mpeg2dec));
+ return ((mpeg2dec->code == 0xb7) ?
+ mpeg2_header_end (mpeg2dec) : mpeg2_parse_header (mpeg2dec));
}
#define RECEIVED(code,state) (((state) << 8) + (code))
@@ -161,7 +161,7 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
mpeg2_state_t state;
state = mpeg2dec->action (mpeg2dec);
- if ((int)state >= 0)
+ if ((int)state > (int)STATE_INTERNAL_NORETURN)
return state;
}
@@ -200,22 +200,18 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
return STATE_BUFFER;
}
+ mpeg2dec->action = mpeg2_seek_header;
switch (mpeg2dec->code) {
case 0x00:
- mpeg2dec->action = mpeg2_header_picture_start;
return mpeg2dec->state;
- case 0xb7:
- mpeg2dec->action = mpeg2_header_end;
- break;
case 0xb3:
+ case 0xb7:
case 0xb8:
- mpeg2dec->action = mpeg2_parse_header;
- break;
+ return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
default:
mpeg2dec->action = seek_chunk;
return STATE_INVALID;
}
- return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
}
mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
@@ -262,7 +258,6 @@ mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
/* state transition after a sequence header */
case RECEIVED (0x00, STATE_SEQUENCE):
- mpeg2dec->action = mpeg2_header_picture_start;
case RECEIVED (0xb8, STATE_SEQUENCE):
mpeg2_header_sequence_finalize (mpeg2dec);
break;
@@ -270,7 +265,6 @@ mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
/* other legal state transitions */
case RECEIVED (0x00, STATE_GOP):
mpeg2_header_gop_finalize (mpeg2dec);
- mpeg2dec->action = mpeg2_header_picture_start;
break;
case RECEIVED (0x01, STATE_PICTURE):
case RECEIVED (0x01, STATE_PICTURE_2ND):
@@ -362,8 +356,8 @@ void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
mpeg2dec->fbuf[1]->buf[2]=buf[2];
mpeg2dec->fbuf[1]->id=NULL;
}
-// printf("libmpeg2: FBUF 0:%p 1:%p 2:%p\n",
-// mpeg2dec->fbuf[0]->buf[0],mpeg2dec->fbuf[1]->buf[0],mpeg2dec->fbuf[2]->buf[0]);
+// printf("libmpeg2: FBUF 0:%p 1:%p 2:%p\n",
+// mpeg2dec->fbuf[0]->buf[0],mpeg2dec->fbuf[1]->buf[0],mpeg2dec->fbuf[2]->buf[0]);
}
void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf)
@@ -398,12 +392,10 @@ void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2)
uint32_t mpeg2_accel (uint32_t accel)
{
if (!mpeg2_accels) {
- if (accel & MPEG2_ACCEL_DETECT)
- accel |= mpeg2_detect_accel ();
- mpeg2_accels = accel |= MPEG2_ACCEL_DETECT;
- mpeg2_cpu_state_init (accel);
- mpeg2_idct_init (accel);
- mpeg2_mc_init (accel);
+ mpeg2_accels = mpeg2_detect_accel (accel) | MPEG2_ACCEL_DETECT;
+ mpeg2_cpu_state_init (mpeg2_accels);
+ mpeg2_idct_init (mpeg2_accels);
+ mpeg2_mc_init (mpeg2_accels);
}
return mpeg2_accels & ~MPEG2_ACCEL_DETECT;
}
diff --git a/libmpeg2/header.c b/libmpeg2/header.c
index ae8b228a63..040651d20e 100644
--- a/libmpeg2/header.c
+++ b/libmpeg2/header.c
@@ -246,7 +246,7 @@ static int sequence_ext (mpeg2dec_t * mpeg2dec)
sequence->vbv_buffer_size |= buffer[4] << 21;
sequence->frame_period =
- sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>2)&3)+1);
+ sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>5)&3)+1);
mpeg2dec->ext_state = SEQ_DISPLAY_EXT;
@@ -257,12 +257,11 @@ static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
- uint32_t flags;
- flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
- ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT));
+ sequence->flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
+ ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT));
if (buffer[0] & 1) {
- flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
+ sequence->flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
sequence->colour_primaries = buffer[1];
sequence->transfer_characteristics = buffer[2];
sequence->matrix_coefficients = buffer[3];
@@ -281,6 +280,17 @@ static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
return 0;
}
+static inline void simplify (unsigned int * u, unsigned int * v)
+{
+ unsigned int a, b, tmp;
+
+ a = *u; b = *v;
+ while (a) { /* find greatest common divisor */
+ tmp = a; a = b % tmp; b = tmp;
+ }
+ *u /= b; *v /= b;
+}
+
static inline void finalize_sequence (mpeg2_sequence_t * sequence)
{
int width;
@@ -317,8 +327,10 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
sequence->pixel_width = 64; sequence->pixel_height = 45; return;
case 6: /* 720x480 16:9 */
sequence->pixel_width = 32; sequence->pixel_height = 27; return;
- case 12: /* 720*480 4:3 */
- sequence->pixel_width = 8; sequence->pixel_height = 9; return;
+ case 8: /* BT.601 625 lines 4:3 */
+ sequence->pixel_width = 59; sequence->pixel_height = 54; return;
+ case 12: /* BT.601 525 lines 4:3 */
+ sequence->pixel_width = 10; sequence->pixel_height = 11; return;
default:
height = 88 * sequence->pixel_width + 1171;
width = 2000;
@@ -327,22 +339,89 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
sequence->pixel_width = width;
sequence->pixel_height = height;
- while (width) { /* find greatest common divisor */
- int tmp = width;
- width = height % tmp;
- height = tmp;
+ simplify (&sequence->pixel_width, &sequence->pixel_height);
+}
+
+int mpeg2_guess_aspect (const mpeg2_sequence_t * sequence,
+ unsigned int * pixel_width,
+ unsigned int * pixel_height)
+{
+ static struct {
+ unsigned int width, height;
+ } video_modes[] = {
+ {720, 576}, /* 625 lines, 13.5 MHz (D1, DV, DVB, DVD) */
+ {704, 576}, /* 625 lines, 13.5 MHz (1/1 D1, DVB, DVD, 4CIF) */
+ {544, 576}, /* 625 lines, 10.125 MHz (DVB, laserdisc) */
+ {528, 576}, /* 625 lines, 10.125 MHz (3/4 D1, DVB, laserdisc) */
+ {480, 576}, /* 625 lines, 9 MHz (2/3 D1, DVB, SVCD) */
+ {352, 576}, /* 625 lines, 6.75 MHz (D2, 1/2 D1, CVD, DVB, DVD) */
+ {352, 288}, /* 625 lines, 6.75 MHz, 1 field (D4, VCD, DVB, DVD, CIF) */
+ {176, 144}, /* 625 lines, 3.375 MHz, half field (QCIF) */
+ {720, 486}, /* 525 lines, 13.5 MHz (D1) */
+ {704, 486}, /* 525 lines, 13.5 MHz */
+ {720, 480}, /* 525 lines, 13.5 MHz (DV, DSS, DVD) */
+ {704, 480}, /* 525 lines, 13.5 MHz (1/1 D1, ATSC, DVD) */
+ {544, 480}, /* 525 lines. 10.125 MHz (DSS, laserdisc) */
+ {528, 480}, /* 525 lines. 10.125 MHz (3/4 D1, laserdisc) */
+ {480, 480}, /* 525 lines, 9 MHz (2/3 D1, SVCD) */
+ {352, 480}, /* 525 lines, 6.75 MHz (D2, 1/2 D1, CVD, DVD) */
+ {352, 240} /* 525 lines. 6.75 MHz, 1 field (D4, VCD, DSS, DVD) */
+ };
+ unsigned int width, height, pix_width, pix_height, i, DAR_16_9;
+
+ *pixel_width = sequence->pixel_width;
+ *pixel_height = sequence->pixel_height;
+ width = sequence->picture_width;
+ height = sequence->picture_height;
+ for (i = 0; i < sizeof (video_modes) / sizeof (video_modes[0]); i++)
+ if (width == video_modes[i].width && height == video_modes[i].height)
+ break;
+ if (i == sizeof (video_modes) / sizeof (video_modes[0]) ||
+ (sequence->pixel_width == 1 && sequence->pixel_height == 1) ||
+ width != sequence->display_width || height != sequence->display_height)
+ return 0;
+
+ for (pix_height = 1; height * pix_height < 480; pix_height <<= 1);
+ height *= pix_height;
+ for (pix_width = 1; width * pix_width <= 352; pix_width <<= 1);
+ width *= pix_width;
+
+ if (! (sequence->flags & SEQ_FLAG_MPEG2)) {
+ static unsigned int mpeg1_check[2][2] = {{11, 54}, {27, 45}};
+ DAR_16_9 = (sequence->pixel_height == 27 ||
+ sequence->pixel_height == 45);
+ if (width < 704 ||
+ sequence->pixel_height != mpeg1_check[DAR_16_9][height == 576])
+ return 0;
+ } else {
+ DAR_16_9 = (3 * sequence->picture_width * sequence->pixel_width >
+ 4 * sequence->picture_height * sequence->pixel_height);
+ switch (width) {
+ case 528: case 544: pix_width *= 4; pix_height *= 3; break;
+ case 480: pix_width *= 3; pix_height *= 2; break;
+ }
+ }
+ if (DAR_16_9) {
+ pix_width *= 4; pix_height *= 3;
+ }
+ if (height == 576) {
+ pix_width *= 59; pix_height *= 54;
+ } else {
+ pix_width *= 10; pix_height *= 11;
}
- sequence->pixel_width /= height;
- sequence->pixel_height /= height;
+ *pixel_width = pix_width;
+ *pixel_height = pix_height;
+ simplify (pixel_width, pixel_height);
+ return (height == 576) ? 1 : 2;
}
-static void copy_matrix (mpeg2dec_t * mpeg2dec, int index)
+static void copy_matrix (mpeg2dec_t * mpeg2dec, int idx)
{
- if (memcmp (mpeg2dec->quantizer_matrix[index],
- mpeg2dec->new_quantizer_matrix[index], 64)) {
- memcpy (mpeg2dec->quantizer_matrix[index],
- mpeg2dec->new_quantizer_matrix[index], 64);
- mpeg2dec->scaled[index] = -1;
+ if (memcmp (mpeg2dec->quantizer_matrix[idx],
+ mpeg2dec->new_quantizer_matrix[idx], 64)) {
+ memcpy (mpeg2dec->quantizer_matrix[idx],
+ mpeg2dec->new_quantizer_matrix[idx], 64);
+ mpeg2dec->scaled[idx] = -1;
}
}
@@ -392,31 +471,30 @@ void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
(sequence->chroma_height == sequence->height));
if (mpeg2dec->sequence.width != (unsigned)-1) {
- unsigned int new_byte_rate;
-
/*
* According to 6.1.1.6, repeat sequence headers should be
- * identical to the original. However some DVDs dont respect
- * that and have different bitrates in the repeat sequence
- * headers. So we'll ignore that in the comparison and still
- * consider these as repeat sequence headers.
- *
- * However, be careful not to alter the current sequence when
- * returning STATE_INVALID_END.
+ * identical to the original. However some encoders do not
+ * respect that and change various fields (including bitrate
+ * and aspect ratio) in the repeat sequence headers. So we
+ * choose to be as conservative as possible and only restart
+ * the decoder if the width, height, chroma_width,
+ * chroma_height or low_delay flag are modified.
*/
- new_byte_rate = sequence->byte_rate;
- sequence->byte_rate = mpeg2dec->sequence.byte_rate;
- if (memcmp (&(mpeg2dec->sequence), sequence,
- sizeof (mpeg2_sequence_t))) {
+ if (sequence->width != mpeg2dec->sequence.width ||
+ sequence->height != mpeg2dec->sequence.height ||
+ sequence->chroma_width != mpeg2dec->sequence.chroma_width ||
+ sequence->chroma_height != mpeg2dec->sequence.chroma_height ||
+ ((sequence->flags ^ mpeg2dec->sequence.flags) &
+ SEQ_FLAG_LOW_DELAY)) {
decoder->stride_frame = sequence->width;
- sequence->byte_rate = new_byte_rate;
mpeg2_header_end (mpeg2dec);
mpeg2dec->action = invalid_end_action;
mpeg2dec->state = STATE_INVALID_END;
return;
}
- sequence->byte_rate = new_byte_rate;
- mpeg2dec->state = STATE_SEQUENCE_REPEATED;
+ mpeg2dec->state = (memcmp (&(mpeg2dec->sequence), sequence,
+ sizeof (mpeg2_sequence_t)) ?
+ STATE_SEQUENCE_MODIFIED : STATE_SEQUENCE_REPEATED);
} else
decoder->stride_frame = sequence->width;
mpeg2dec->sequence = *sequence;
@@ -468,62 +546,53 @@ void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type)
}
}
-mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
+int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
{
+ uint8_t * buffer = mpeg2dec->chunk_start;
mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
+ mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ int type;
mpeg2dec->state = ((mpeg2dec->state != STATE_SLICE_1ST) ?
STATE_PICTURE : STATE_PICTURE_2ND);
- picture->flags = 0;
+ mpeg2dec->ext_state = PIC_CODING_EXT;
+
+ picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
+
+ type = (buffer [1] >> 3) & 7;
+ if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) {
+ /* forward_f_code and backward_f_code - used in mpeg1 only */
+ decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
+ decoder->f_motion.f_code[0] =
+ (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
+ decoder->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
+ decoder->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
+ }
+
+ picture->flags = PIC_FLAG_PROGRESSIVE_FRAME | type;
picture->tag = picture->tag2 = 0;
if (mpeg2dec->num_tags) {
- if (mpeg2dec->bytes_since_tag >= 4) {
+ if (mpeg2dec->bytes_since_tag >= mpeg2dec->chunk_ptr - buffer + 4) {
mpeg2dec->num_tags = 0;
picture->tag = mpeg2dec->tag_current;
picture->tag2 = mpeg2dec->tag2_current;
- picture->flags = PIC_FLAG_TAGS;
+ picture->flags |= PIC_FLAG_TAGS;
} else if (mpeg2dec->num_tags > 1) {
mpeg2dec->num_tags = 1;
picture->tag = mpeg2dec->tag_previous;
picture->tag2 = mpeg2dec->tag2_previous;
- picture->flags = PIC_FLAG_TAGS;
+ picture->flags |= PIC_FLAG_TAGS;
}
}
+ picture->nb_fields = 2;
picture->display_offset[0].x = picture->display_offset[1].x =
picture->display_offset[2].x = mpeg2dec->display_offset_x;
picture->display_offset[0].y = picture->display_offset[1].y =
picture->display_offset[2].y = mpeg2dec->display_offset_y;
- return mpeg2_parse_header (mpeg2dec);
-}
-
-int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
-{
- uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
- int type;
-
- type = (buffer [1] >> 3) & 7;
- mpeg2dec->ext_state = PIC_CODING_EXT;
-
- picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
-
- picture->flags |= type;
-
- if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) {
- /* forward_f_code and backward_f_code - used in mpeg1 only */
- decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
- decoder->f_motion.f_code[0] =
- (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
- decoder->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
- decoder->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
- }
/* XXXXXX decode extra_information_picture as well */
- picture->nb_fields = 2;
-
- mpeg2dec->q_scale_type = 0;
+ decoder->q_scale_type = 0;
decoder->intra_dc_precision = 7;
decoder->frame_pred_frame_dct = 1;
decoder->concealment_motion_vectors = 0;
@@ -570,10 +639,11 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
decoder->top_field_first = buffer[3] >> 7;
decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1;
- mpeg2dec->q_scale_type = buffer[3] & 16;
+ decoder->q_scale_type = buffer[3] & 16;
decoder->intra_vlc_format = (buffer[3] >> 3) & 1;
decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm;
- flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
+ if (!(buffer[4] & 0x80))
+ flags &= ~PIC_FLAG_PROGRESSIVE_FRAME;
if (buffer[4] & 0x40)
flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) &
PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
@@ -794,7 +864,7 @@ int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec)
return 0;
}
-static void prescale (mpeg2dec_t * mpeg2dec, int index)
+static void prescale (mpeg2dec_t * mpeg2dec, int idx)
{
static int non_linear_scale [] = {
0, 1, 2, 3, 4, 5, 6, 7,
@@ -805,14 +875,14 @@ static void prescale (mpeg2dec_t * mpeg2dec, int index)
int i, j, k;
mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
- if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) {
- mpeg2dec->scaled[index] = mpeg2dec->q_scale_type;
+ if (mpeg2dec->scaled[idx] != decoder->q_scale_type) {
+ mpeg2dec->scaled[idx] = decoder->q_scale_type;
for (i = 0; i < 32; i++) {
- k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1);
+ k = decoder->q_scale_type ? non_linear_scale[i] : (i << 1);
decoder->quantizer_scales[i] = k;
for (j = 0; j < 64; j++)
- decoder->quantizer_prescale[index][i][j] =
- k * mpeg2dec->quantizer_matrix[index][j];
+ decoder->quantizer_prescale[idx][i][j] =
+ k * mpeg2dec->quantizer_matrix[idx][j];
}
}
}
@@ -864,7 +934,7 @@ mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec)
mpeg2dec->fbuf[b_type]->buf);
}
mpeg2dec->action = NULL;
- return (mpeg2_state_t)-1;
+ return STATE_INTERNAL_NORETURN;
}
static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec)
diff --git a/libmpeg2/idct.c b/libmpeg2/idct.c
index e3f88dad30..82049df4bc 100644
--- a/libmpeg2/idct.c
+++ b/libmpeg2/idct.c
@@ -283,8 +283,6 @@ void mpeg2_idct_init (uint32_t accel)
} else
#endif
{
- extern uint8_t mpeg2_scan_norm[64];
- extern uint8_t mpeg2_scan_alt[64];
int i, j;
mpeg2_idct_copy = mpeg2_idct_copy_c;
diff --git a/libmpeg2/idct_alpha.c b/libmpeg2/idct_alpha.c
index 007185bf18..bc2f886492 100644
--- a/libmpeg2/idct_alpha.c
+++ b/libmpeg2/idct_alpha.c
@@ -364,8 +364,6 @@ void mpeg2_idct_add_alpha (const int last, int16_t * block,
void mpeg2_idct_alpha_init (void)
{
- extern uint8_t mpeg2_scan_norm[64];
- extern uint8_t mpeg2_scan_alt[64];
int i, j;
for (i = 0; i < 64; i++) {
diff --git a/libmpeg2/idct_altivec.c b/libmpeg2/idct_altivec.c
index 381ef069f0..b5b395a205 100644
--- a/libmpeg2/idct_altivec.c
+++ b/libmpeg2/idct_altivec.c
@@ -272,8 +272,6 @@ void mpeg2_idct_add_altivec (const int last, int16_t * const _block,
void mpeg2_idct_altivec_init (void)
{
- extern uint8_t mpeg2_scan_norm[64];
- extern uint8_t mpeg2_scan_alt[64];
int i, j;
/* the altivec idct uses a transposed input, so we patch scan tables */
diff --git a/libmpeg2/idct_mmx.c b/libmpeg2/idct_mmx.c
index a682284dab..50f8f18c3e 100644
--- a/libmpeg2/idct_mmx.c
+++ b/libmpeg2/idct_mmx.c
@@ -19,10 +19,6 @@
* 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
- *
- * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
- * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
- * $Id$
*/
#include "config.h"
@@ -1294,8 +1290,6 @@ void mpeg2_idct_add_mmx (const int last, int16_t * const block,
void mpeg2_idct_mmx_init (void)
{
- 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 */
diff --git a/libmpeg2/mmx.h b/libmpeg2/mmx.h
index fcb92870d2..c62be1f581 100644
--- a/libmpeg2/mmx.h
+++ b/libmpeg2/mmx.h
@@ -21,6 +21,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef LIBMPEG2_MMX_H
+#define LIBMPEG2_MMX_H
+
/*
* The type of an value that fits in an MMX register (note that long
* long constant values MUST be suffixed by LL and unsigned long long
@@ -285,3 +288,5 @@ typedef union {
#define pshufw_r2r(regs,regd,imm) mmx_r2ri(pshufw, regs, regd, imm)
#define sfence() __asm__ __volatile__ ("sfence\n\t")
+
+#endif /* LIBMPEG2_MMX_H */
diff --git a/libmpeg2/motion_comp_arm.c b/libmpeg2/motion_comp_arm.c
index c83d57d676..0111f7f8d3 100644
--- a/libmpeg2/motion_comp_arm.c
+++ b/libmpeg2/motion_comp_arm.c
@@ -16,7 +16,7 @@
* 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
+ * along with mpeg2dec; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
@@ -30,12 +30,12 @@
#include "attributes.h"
#include "mpeg2_internal.h"
-#define avg2(a,b) ((a+b+1)>>1)
+#define avg2(a,b) ((a+b+1)>>1)
#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
-#define predict_o(i) (ref[i])
-#define predict_x(i) (avg2 (ref[i], ref[i+1]))
-#define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
+#define predict_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]))
@@ -67,7 +67,7 @@ static void inline MC_##op##_##xy##_16_c (uint8_t * dest, const uint8_t * ref, \
op (predict_##xy, 15); \
ref += stride; \
dest += stride; \
- } while (--height); \
+ } while (--height); \
} \
static void MC_##op##_##xy##_8_c (uint8_t * dest, const uint8_t * ref, \
const int stride, int height) \
@@ -83,13 +83,11 @@ static void MC_##op##_##xy##_8_c (uint8_t * dest, const uint8_t * ref, \
op (predict_##xy, 7); \
ref += stride; \
dest += stride; \
- } while (--height); \
+ } while (--height); \
} \
/* definitions of the actual mc functions */
-MC_FUNC (put,o)
MC_FUNC (avg,o)
-MC_FUNC (put,x)
MC_FUNC (avg,x)
MC_FUNC (put,y)
MC_FUNC (avg,y)
@@ -117,7 +115,7 @@ static void MC_put_xy_16_arm (uint8_t * dest, const uint8_t * ref,
}
extern void MC_put_o_8_arm (uint8_t * dest, const uint8_t * ref,
- int stride, int height);
+ int stride, int height);
extern void MC_put_x_8_arm (uint8_t * dest, const uint8_t * ref,
int stride, int height);
diff --git a/libmpeg2/motion_comp_arm_s.S b/libmpeg2/motion_comp_arm_s.S
index fd71fb3b83..f6c3d7df8e 100644
--- a/libmpeg2/motion_comp_arm_s.S
+++ b/libmpeg2/motion_comp_arm_s.S
@@ -15,9 +15,10 @@
@ 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
+@ along with mpeg2dec; if not, write to the Free Software
@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
.text
@ ----------------------------------------------------------------
diff --git a/libmpeg2/motion_comp_mmx.c b/libmpeg2/motion_comp_mmx.c
index 964695570a..fc265f4f99 100644
--- a/libmpeg2/motion_comp_mmx.c
+++ b/libmpeg2/motion_comp_mmx.c
@@ -19,10 +19,6 @@
* 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
- *
- * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
- * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
- * $Id$
*/
#include "config.h"
@@ -67,7 +63,7 @@ static mmx_t round4 = {0x0002000200020002LL};
* unrolling will help
*/
-static inline void mmx_zero_reg ()
+static inline void mmx_zero_reg (void)
{
/* load 0 into mm0 */
pxor_r2r (mm0, mm0);
diff --git a/libmpeg2/mpeg2.h b/libmpeg2/mpeg2.h
index 08933b5843..8eef2ce716 100644
--- a/libmpeg2/mpeg2.h
+++ b/libmpeg2/mpeg2.h
@@ -1,6 +1,6 @@
/*
* mpeg2.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
+ * Copyright (C) 2000-2004 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.
@@ -25,11 +25,11 @@
* $Id$
*/
-#ifndef MPEG2_H
-#define MPEG2_H
+#ifndef LIBMPEG2_MPEG2_H
+#define LIBMPEG2_MPEG2_H
#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
-#define MPEG2_RELEASE MPEG2_VERSION (0, 4, 1) /* 0.4.1 */
+#define MPEG2_RELEASE MPEG2_VERSION (0, 5, 1) /* 0.5.1 */
#define SEQ_FLAG_MPEG2 1
#define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
@@ -132,7 +132,8 @@ typedef enum {
STATE_SLICE = 7,
STATE_END = 8,
STATE_INVALID = 9,
- STATE_INVALID_END = 10
+ STATE_INVALID_END = 10,
+ STATE_SEQUENCE_MODIFIED = 11
} mpeg2_state_t;
typedef struct mpeg2_convert_init_s {
@@ -160,6 +161,7 @@ void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf);
#define MPEG2_ACCEL_X86_3DNOW 2
#define MPEG2_ACCEL_X86_MMXEXT 4
#define MPEG2_ACCEL_X86_SSE2 8
+#define MPEG2_ACCEL_X86_SSE3 16
#define MPEG2_ACCEL_PPC_ALTIVEC 1
#define MPEG2_ACCEL_ALPHA 1
#define MPEG2_ACCEL_ALPHA_MVI 2
@@ -187,6 +189,9 @@ void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2);
void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]);
void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer);
+int mpeg2_guess_aspect (const mpeg2_sequence_t * sequence,
+ unsigned int * pixel_width,
+ unsigned int * pixel_height);
typedef enum {
MPEG2_ALLOC_MPEG2DEC = 0,
@@ -201,4 +206,4 @@ void mpeg2_free (void * buf);
void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t),
int free (void *));
-#endif /* MPEG2_H */
+#endif /* LIBMPEG2_MPEG2_H */
diff --git a/libmpeg2/mpeg2_internal.h b/libmpeg2/mpeg2_internal.h
index 04a31f6926..ee4fc32062 100644
--- a/libmpeg2/mpeg2_internal.h
+++ b/libmpeg2/mpeg2_internal.h
@@ -25,6 +25,11 @@
* $Id$
*/
+#ifndef LIBMPEG2_MPEG2_INTERNAL_H
+#define LIBMPEG2_MPEG2_INTERNAL_H
+
+#define STATE_INTERNAL_NORETURN ((mpeg2_state_t)-1)
+
/* macroblock modes */
#define MACROBLOCK_INTRA 1
#define MACROBLOCK_PATTERN 2
@@ -149,6 +154,9 @@ struct mpeg2_decoder_s {
int mpeg1;
+ /* XXX: stuff due to xine shit */
+ int8_t q_scale_type;
+
int quantizer_scales[32];
int quantizer_scale;
char* quant_store;
@@ -220,7 +228,8 @@ struct mpeg2dec_s {
int16_t display_offset_x, display_offset_y;
int copy_matrix;
- int8_t q_scale_type, scaled[4];
+ int8_t scaled[4]; /* XXX: MOVED */
+ //int8_t q_scale_type, scaled[4];
uint8_t quantizer_matrix[4][64];
uint8_t new_quantizer_matrix[4][64];
@@ -236,7 +245,7 @@ typedef struct {
} cpu_state_t;
/* cpu_accel.c */
-uint32_t mpeg2_detect_accel (void);
+uint32_t mpeg2_detect_accel (uint32_t accel);
/* cpu_state.c */
void mpeg2_cpu_state_init (uint32_t accel);
@@ -262,7 +271,9 @@ mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec);
void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
/* idct.c */
-void mpeg2_idct_init (uint32_t accel);
+extern void mpeg2_idct_init (uint32_t accel);
+extern uint8_t mpeg2_scan_norm[64];
+extern uint8_t mpeg2_scan_alt[64];
/* idct_mmx.c */
void mpeg2_idct_copy_sse2 (int16_t * block, uint8_t * dest, int stride);
@@ -315,3 +326,5 @@ extern mpeg2_mc_t mpeg2_mc_alpha;
extern mpeg2_mc_t mpeg2_mc_vis;
extern mpeg2_mc_t mpeg2_mc_arm;
extern mpeg2_mc_t mpeg2_mc_iwmmxt;
+
+#endif /* LIBMPEG2_MPEG2_INTERNAL_H */
diff --git a/libmpeg2/slice.c b/libmpeg2/slice.c
index 4d778a7026..99fcf95c22 100644
--- a/libmpeg2/slice.c
+++ b/libmpeg2/slice.c
@@ -450,7 +450,7 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
break; /* illegal, check needed to avoid buffer overflow */
}
dest[63] ^= mismatch & 16;
- DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
@@ -508,7 +508,7 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
} else {
/* end of block. I commented out this code because if we */
- /* dont exit here we will still exit at the later test :) */
+ /* do not exit here we will still exit at the later test :) */
/* if (i >= 128) break; */ /* end of block */
@@ -560,7 +560,7 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
break; /* illegal, check needed to avoid buffer overflow */
}
dest[63] ^= mismatch & 16;
- DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
+ DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
@@ -681,7 +681,7 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
break; /* illegal, check needed to avoid buffer overflow */
}
dest[63] ^= mismatch & 16;
- DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
@@ -799,7 +799,7 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
}
break; /* illegal, check needed to avoid buffer overflow */
}
- DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
@@ -926,7 +926,7 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
}
break; /* illegal, check needed to avoid buffer overflow */
}
- DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
+ DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
@@ -1569,18 +1569,24 @@ do { \
#define NEXT_MACROBLOCK \
do { \
- if(decoder->quant_store) { \
- if (decoder->picture_structure == TOP_FIELD) \
- decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
- +(decoder->offset>>4)] = decoder->quantizer_scale; \
- else if (decoder->picture_structure == BOTTOM_FIELD) \
- decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
- + decoder->quant_stride \
- +(decoder->offset>>4)] = decoder->quantizer_scale; \
- else \
- decoder->quant_store[decoder->quant_stride*(decoder->v_offset>>4) \
- +(decoder->offset>>4)] = decoder->quantizer_scale; \
- } \
+ if(decoder->quant_store) { \
+ if (decoder->picture_structure == TOP_FIELD) \
+ decoder->quant_store[2 * decoder->quant_stride \
+ * (decoder->v_offset >> 4) \
+ + (decoder->offset >> 4)] \
+ = decoder->quantizer_scale; \
+ else if (decoder->picture_structure == BOTTOM_FIELD) \
+ decoder->quant_store[2 * decoder->quant_stride \
+ * (decoder->v_offset >> 4) \
+ + decoder->quant_stride \
+ + (decoder->offset >> 4)] \
+ = decoder->quantizer_scale; \
+ else \
+ decoder->quant_store[decoder->quant_stride \
+ * (decoder->v_offset >> 4) \
+ + (decoder->offset >> 4)] \
+ = decoder->quantizer_scale; \
+ } \
decoder->offset += 16; \
if (decoder->offset == decoder->width) { \
do { /* just so we can use the break statement */ \
@@ -1604,6 +1610,10 @@ do { \
} \
} while (0)
+/**
+ * Dummy motion decoding function, to avoid calling NULL in
+ * case of malformed streams.
+ */
static void motion_dummy (mpeg2_decoder_t * const decoder,
motion_t * const motion,
mpeg2_mc_fct * const * const table)
@@ -1668,7 +1678,7 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
if (decoder->mpeg1) {
decoder->motion_parser[0] = motion_zero_420;
decoder->motion_parser[MC_FIELD] = motion_dummy;
- decoder->motion_parser[MC_FRAME] = motion_mp1;
+ decoder->motion_parser[MC_FRAME] = motion_mp1;
decoder->motion_parser[MC_DMV] = motion_dummy;
decoder->motion_parser[4] = motion_reuse_420;
} else if (decoder->picture_structure == FRAME_PICTURE) {
@@ -1894,6 +1904,14 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
motion_parser_t * parser;
+ if ( ((macroblock_modes >> MOTION_TYPE_SHIFT) < 0)
+ || ((macroblock_modes >> MOTION_TYPE_SHIFT) >=
+ (int)(sizeof(decoder->motion_parser)
+ / sizeof(decoder->motion_parser[0])))
+ ) {
+ break; // Illegal !
+ }
+
parser =
decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT];
MOTION_CALL (parser, macroblock_modes);
diff --git a/libmpeg2/vis.h b/libmpeg2/vis.h
index 69dd49075b..8324c3eb2e 100644
--- a/libmpeg2/vis.h
+++ b/libmpeg2/vis.h
@@ -41,6 +41,9 @@
* the assembler to keep the binary from becoming tainted.
*/
+#ifndef LIBMPEG2_VIS_H
+#define LIBMPEG2_VIS_H
+
#define vis_opc_base ((0x1 << 31) | (0x36 << 19))
#define vis_opf(X) ((X) << 5)
#define vis_sreg(X) (X)
@@ -326,3 +329,5 @@ static inline void vis_alignaddrl_g0(void *_ptr)
/* Pixel component distance. */
#define vis_pdist(rs1,rs2,rd) vis_dd2d(0x3e, rs1, rs2, rd)
+
+#endif /* LIBMPEG2_VIS_H */
diff --git a/libmpeg2/vlc.h b/libmpeg2/vlc.h
index 7098ee0f9b..b3a868e54b 100644
--- a/libmpeg2/vlc.h
+++ b/libmpeg2/vlc.h
@@ -21,6 +21,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef LIBMPEG2_VLC_H
+#define LIBMPEG2_VLC_H
+
#define GETWORD(bit_buf,shift,bit_ptr) \
do { \
bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
@@ -121,7 +124,7 @@ static const MBtab MB_P [] = {
#define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD
static const MBtab MB_B [] = {
- {0, 0}, {INTRA|QUANT, 6},
+ {0, 6}, {INTRA|QUANT, 6},
{BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6},
{INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
{INTRA, 5}, {INTRA, 5},
@@ -201,7 +204,7 @@ static const CBPtab CBP_7 [] = {
};
static const CBPtab CBP_9 [] = {
- {0, 0}, {0x00, 9}, {0x39, 9}, {0x36, 9},
+ {0, 9}, {0x00, 9}, {0x39, 9}, {0x36, 9},
{0x37, 9}, {0x3b, 9}, {0x3d, 9}, {0x3e, 9},
{0x17, 8}, {0x17, 8}, {0x1b, 8}, {0x1b, 8},
{0x1d, 8}, {0x1d, 8}, {0x1e, 8}, {0x1e, 8},
@@ -289,7 +292,7 @@ static const DCTtab DCT_B14_10 [] = {
};
static const DCTtab DCT_B14_8 [] = {
- { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
+ { 65, 0,12}, { 65, 0,12}, { 65, 0,12}, { 65, 0,12},
{ 3, 2, 7}, { 3, 2, 7}, { 10, 1, 7}, { 10, 1, 7},
{ 1, 4, 7}, { 1, 4, 7}, { 9, 1, 7}, { 9, 1, 7},
{ 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6},
@@ -326,7 +329,7 @@ static const DCTtab DCT_B15_10 [] = {
};
static const DCTtab DCT_B15_8 [] = {
- { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
+ { 65, 0,12}, { 65, 0,12}, { 65, 0,12}, { 65, 0,12},
{ 8, 1, 7}, { 8, 1, 7}, { 9, 1, 7}, { 9, 1, 7},
{ 7, 1, 7}, { 7, 1, 7}, { 3, 2, 7}, { 3, 2, 7},
{ 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6},
@@ -427,3 +430,5 @@ static const MBAtab MBA_11 [] = {
{ 7, 7}, { 7, 7}, { 7, 7}, { 7, 7},
{ 7, 7}, { 7, 7}, { 7, 7}, { 7, 7}
};
+
+#endif /* LIBMPEG2_VLC_H */