summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 = (buffe