1 --- include/attributes.h 2006-06-16 20:12:26.000000000 +0200
2 +++ libmpeg2/attributes.h 2006-06-16 20:12:50.000000000 +0200
4 #ifdef ATTRIBUTE_ALIGNED_MAX
5 #define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
7 -#define ATTR_ALIGN(align)
8 +#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((16 < align) ? 16 : align)))
11 #ifdef HAVE_BUILTIN_EXPECT
12 --- libmpeg2/cpu_accel.c 2006-06-16 20:12:26.000000000 +0200
13 +++ libmpeg2/cpu_accel.c 2006-06-16 20:12:50.000000000 +0200
18 +#include "cpudetect.h"
23 #include "mpeg2_internal.h"
27 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
29 +/* MPlayer imports libmpeg2 as decoder, which detects MMX / 3DNow!
30 + * instructions via assembly. However, it is regarded as duplicaed work
31 + * in MPlayer, so that we enforce to use MPlayer's implementation.
33 +#define USE_MPLAYER_CPUDETECT
35 static inline uint32_t arch_accel (void)
37 +#if !defined(USE_MPLAYER_CPUDETECT)
38 uint32_t eax, ebx, ecx, edx;
42 caps |= MPEG2_ACCEL_X86_MMXEXT;
45 +#else /* USE_MPLAYER_CPUDETECT: Use MPlayer's cpu capability property */
47 + if (gCpuCaps.hasMMX)
48 + caps |= MPEG2_ACCEL_X86_MMX;
49 + if (gCpuCaps.hasSSE2)
50 + caps |= MPEG2_ACCEL_X86_SSE2;
51 + if (gCpuCaps.hasMMX2)
52 + caps |= MPEG2_ACCEL_X86_MMXEXT;
53 + if (gCpuCaps.has3DNow)
54 + caps |= MPEG2_ACCEL_X86_3DNOW;
58 +#endif /* USE_MPLAYER_CPUDETECT */
60 -#endif /* ARCH_X86 */
61 +#endif /* ARCH_X86 || ARCH_X86_64 */
63 -#if defined(ARCH_PPC) || defined(ARCH_SPARC)
64 +#if defined(ARCH_PPC) || (defined(ARCH_SPARC) && defined(HAVE_VIS))
72 -#ifdef HAVE_ALTIVEC_H /* gnu */
73 -#define VAND(a,b,c) "vand " #a "," #b "," #c "\n\t"
75 +#if defined( __APPLE_CC__ ) && defined( __APPLE_ALTIVEC__ ) /* apple */
76 #define VAND(a,b,c) "vand v" #a ",v" #b ",v" #c "\n\t"
78 +#define VAND(a,b,c) "vand " #a "," #b "," #c "\n\t"
80 asm volatile ("mtspr 256, %0\n\t"
84 static inline uint32_t arch_accel (void)
86 +#ifdef CAN_COMPILE_ALPHA_MVI
89 asm volatile ("amask %1, %0"
91 : "rI" (256)); /* AMASK_MVI */
92 return no_mvi ? MPEG2_ACCEL_ALPHA : (MPEG2_ACCEL_ALPHA |
93 MPEG2_ACCEL_ALPHA_MVI);
95 + return MPEG2_ACCEL_ALPHA;
98 #endif /* ARCH_ALPHA */
99 #endif /* ACCEL_DETECT */
104 -#if defined (ARCH_X86) || defined (ARCH_PPC) || defined (ARCH_ALPHA) || defined (ARCH_SPARC)
105 +#if defined (ARCH_X86) || defined (ARCH_X86_64) || defined (ARCH_PPC) || defined (ARCH_ALPHA) || defined (ARCH_SPARC)
106 accel = arch_accel ();
109 --- libmpeg2/cpu_state.c 2006-06-16 20:12:26.000000000 +0200
110 +++ libmpeg2/cpu_state.c 2006-06-16 20:12:50.000000000 +0200
113 #include "attributes.h"
114 #include "mpeg2_internal.h"
116 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
120 void (* mpeg2_cpu_state_save) (cpu_state_t * state) = NULL;
121 void (* mpeg2_cpu_state_restore) (cpu_state_t * state) = NULL;
124 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
125 static void state_restore_mmx (cpu_state_t * state)
132 +#if defined(ARCH_PPC) && defined(HAVE_ALTIVEC)
133 -#ifdef HAVE_ALTIVEC_H /* gnu */
134 -#define LI(a,b) "li " #a "," #b "\n\t"
135 -#define STVX0(a,b,c) "stvx " #a ",0," #c "\n\t"
136 -#define STVX(a,b,c) "stvx " #a "," #b "," #c "\n\t"
137 -#define LVX0(a,b,c) "lvx " #a ",0," #c "\n\t"
138 -#define LVX(a,b,c) "lvx " #a "," #b "," #c "\n\t"
140 +#if defined( __APPLE_CC__ ) && defined( __APPLE_ALTIVEC__ ) /* apple */
141 #define LI(a,b) "li r" #a "," #b "\n\t"
142 #define STVX0(a,b,c) "stvx v" #a ",0,r" #c "\n\t"
143 #define STVX(a,b,c) "stvx v" #a ",r" #b ",r" #c "\n\t"
144 #define LVX0(a,b,c) "lvx v" #a ",0,r" #c "\n\t"
145 #define LVX(a,b,c) "lvx v" #a ",r" #b ",r" #c "\n\t"
147 +#define LI(a,b) "li " #a "," #b "\n\t"
148 +#define STVX0(a,b,c) "stvx " #a ",0," #c "\n\t"
149 +#define STVX(a,b,c) "stvx " #a "," #b "," #c "\n\t"
150 +#define LVX0(a,b,c) "lvx " #a ",0," #c "\n\t"
151 +#define LVX(a,b,c) "lvx " #a "," #b "," #c "\n\t"
154 static void state_save_altivec (cpu_state_t * state)
155 @@ -115,12 +119,12 @@
157 void mpeg2_cpu_state_init (uint32_t accel)
160 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
161 if (accel & MPEG2_ACCEL_X86_MMX) {
162 mpeg2_cpu_state_restore = state_restore_mmx;
166 +#if defined(ARCH_PPC) && defined(HAVE_ALTIVEC)
167 if (accel & MPEG2_ACCEL_PPC_ALTIVEC) {
168 mpeg2_cpu_state_save = state_save_altivec;
169 mpeg2_cpu_state_restore = state_restore_altivec;
170 --- libmpeg2/decode.c 2006-06-16 20:12:26.000000000 +0200
171 +++ libmpeg2/decode.c 2006-06-16 20:12:50.000000000 +0200
173 fbuf->buf[1] = buf[1];
174 fbuf->buf[2] = buf[2];
176 + // HACK! FIXME! At first I frame, copy pointers to prediction frame too!
177 + if (mpeg2dec->custom_fbuf && !mpeg2dec->fbuf[1]->buf[0]){
178 + mpeg2dec->fbuf[1]->buf[0]=buf[0];
179 + mpeg2dec->fbuf[1]->buf[1]=buf[1];
180 + mpeg2dec->fbuf[1]->buf[2]=buf[2];
181 + mpeg2dec->fbuf[1]->id=NULL;
183 +// printf("libmpeg2: FBUF 0:%p 1:%p 2:%p\n",
184 +// mpeg2dec->fbuf[0]->buf[0],mpeg2dec->fbuf[1]->buf[0],mpeg2dec->fbuf[2]->buf[0]);
187 void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf)
188 --- libmpeg2/header.c 2006-06-16 20:12:26.000000000 +0200
189 +++ libmpeg2/header.c 2006-06-16 20:12:50.000000000 +0200
191 mpeg2dec->decoder.convert = NULL;
192 mpeg2dec->decoder.convert_id = NULL;
193 mpeg2dec->picture = mpeg2dec->pictures;
194 + memset(&mpeg2dec->fbuf_alloc[0].fbuf, 0, sizeof(mpeg2_fbuf_t));
195 + memset(&mpeg2dec->fbuf_alloc[1].fbuf, 0, sizeof(mpeg2_fbuf_t));
196 + memset(&mpeg2dec->fbuf_alloc[2].fbuf, 0, sizeof(mpeg2_fbuf_t));
197 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
198 mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
199 mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
201 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) {
202 picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
203 flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
204 + flags |= (buffer[3] & 2) ? PIC_FLAG_REPEAT_FIRST_FIELD : 0;
206 picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
209 mpeg2dec->scaled[index] = mpeg2dec->q_scale_type;
210 for (i = 0; i < 32; i++) {
211 k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1);
212 + decoder->quantizer_scales[i] = k;
213 for (j = 0; j < 64; j++)
214 decoder->quantizer_prescale[index][i][j] =
215 k * mpeg2dec->quantizer_matrix[index][j];
216 --- libmpeg2/idct.c 2006-06-16 20:12:26.000000000 +0200
217 +++ libmpeg2/idct.c 2006-06-16 20:12:50.000000000 +0200
218 @@ -239,12 +239,15 @@
220 void mpeg2_idct_init (uint32_t accel)
224 if (accel & MPEG2_ACCEL_X86_MMXEXT) {
225 mpeg2_idct_copy = mpeg2_idct_copy_mmxext;
226 mpeg2_idct_add = mpeg2_idct_add_mmxext;
227 mpeg2_idct_mmx_init ();
228 - } else if (accel & MPEG2_ACCEL_X86_MMX) {
232 + if (accel & MPEG2_ACCEL_X86_MMX) {
233 mpeg2_idct_copy = mpeg2_idct_copy_mmx;
234 mpeg2_idct_add = mpeg2_idct_add_mmx;
235 mpeg2_idct_mmx_init ();
236 @@ -254,11 +261,14 @@
240 +#ifdef CAN_COMPILE_ALPHA_MVI
241 if (accel & MPEG2_ACCEL_ALPHA_MVI) {
242 mpeg2_idct_copy = mpeg2_idct_copy_mvi;
243 mpeg2_idct_add = mpeg2_idct_add_mvi;
244 mpeg2_idct_alpha_init ();
245 - } else if (accel & MPEG2_ACCEL_ALPHA) {
248 + if (accel & MPEG2_ACCEL_ALPHA) {
251 mpeg2_idct_copy = mpeg2_idct_copy_alpha;
252 --- libmpeg2/idct_alpha.c 2006-06-16 20:12:26.000000000 +0200
253 +++ libmpeg2/idct_alpha.c 2006-06-16 20:12:50.000000000 +0200
255 block[8*7] = (a0 - b0) >> 17;
258 +#ifdef CAN_COMPILE_ALPHA_MVI
259 void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, const int stride)
263 stq (p7, dest + 7 * stride);
268 void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, const int stride)
270 --- libmpeg2/idct_mmx.c 2006-06-16 20:12:26.000000000 +0200
271 +++ libmpeg2/idct_mmx.c 2006-06-16 20:12:50.000000000 +0200
277 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
279 #include <inttypes.h>
281 --- libmpeg2/motion_comp.c 2006-06-16 20:12:26.000000000 +0200
282 +++ libmpeg2/motion_comp.c 2006-06-16 20:12:50.000000000 +0200
285 void mpeg2_mc_init (uint32_t accel)
289 if (accel & MPEG2_ACCEL_X86_MMXEXT)
290 mpeg2_mc = mpeg2_mc_mmxext;
291 - else if (accel & MPEG2_ACCEL_X86_3DNOW)
295 + if (accel & MPEG2_ACCEL_X86_3DNOW)
296 mpeg2_mc = mpeg2_mc_3dnow;
297 - else if (accel & MPEG2_ACCEL_X86_MMX)
301 + if (accel & MPEG2_ACCEL_X86_MMX)
302 mpeg2_mc = mpeg2_mc_mmx;
306 +#if defined(ARCH_PPC) && defined(HAVE_ALTIVEC)
307 if (accel & MPEG2_ACCEL_PPC_ALTIVEC)
308 mpeg2_mc = mpeg2_mc_altivec;
311 mpeg2_mc = mpeg2_mc_alpha;
315 +#if defined(ARCH_SPARC) && defined(HAVE_VIS)
316 if (accel & MPEG2_ACCEL_SPARC_VIS)
317 mpeg2_mc = mpeg2_mc_vis;
319 --- libmpeg2/motion_comp_mmx.c 2006-06-16 20:12:26.000000000 +0200
320 +++ libmpeg2/motion_comp_mmx.c 2006-06-16 20:12:50.000000000 +0200
326 +#if defined(ARCH_X86) || defined(ARCH_X86_64)
328 #include <inttypes.h>
330 --- include/mpeg2.h 2006-06-16 20:12:26.000000000 +0200
331 +++ libmpeg2/mpeg2.h 2006-06-16 20:12:50.000000000 +0200
333 #define PIC_FLAG_COMPOSITE_DISPLAY 32
334 #define PIC_FLAG_SKIP 64
335 #define PIC_FLAG_TAGS 128
336 +#define PIC_FLAG_REPEAT_FIRST_FIELD 256
337 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
339 typedef struct mpeg2_picture_s {
341 #define MPEG2_ACCEL_X86_MMX 1
342 #define MPEG2_ACCEL_X86_3DNOW 2
343 #define MPEG2_ACCEL_X86_MMXEXT 4
344 +#define MPEG2_ACCEL_X86_SSE2 8
345 #define MPEG2_ACCEL_PPC_ALTIVEC 1
346 #define MPEG2_ACCEL_ALPHA 1
347 #define MPEG2_ACCEL_ALPHA_MVI 2
348 --- libmpeg2/mpeg2_internal.h 2006-06-16 20:12:26.000000000 +0200
349 +++ libmpeg2/mpeg2_internal.h 2006-06-16 20:12:50.000000000 +0200
356 + int quantizer_scales[32];
357 + int quantizer_scale;
364 int8_t q_scale_type, scaled[4];
365 uint8_t quantizer_matrix[4][64];
366 uint8_t new_quantizer_matrix[4][64];
369 + unsigned char *pending_buffer;
370 + int pending_length;
374 --- libmpeg2/slice.c 2006-06-16 20:12:26.000000000 +0200
375 +++ libmpeg2/slice.c 2006-06-16 20:12:50.000000000 +0200
378 quantizer_scale_code = UBITS (bit_buf, 5);
379 DUMPBITS (bit_buf, bits, 5);
380 + decoder->quantizer_scale = decoder->quantizer_scales[quantizer_scale_code];
382 decoder->quantizer_matrix[0] =
383 decoder->quantizer_prescale[0][quantizer_scale_code];
384 @@ -1568,6 +1569,18 @@
386 #define NEXT_MACROBLOCK \
388 + if(decoder->quant_store) { \
389 + if (decoder->picture_structure == TOP_FIELD) \
390 + decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
391 + +(decoder->offset>>4)] = decoder->quantizer_scale; \
392 + else if (decoder->picture_structure == BOTTOM_FIELD) \
393 + decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
394 + + decoder->quant_stride \
395 + +(decoder->offset>>4)] = decoder->quantizer_scale; \
397 + decoder->quant_store[decoder->quant_stride*(decoder->v_offset>>4) \
398 + +(decoder->offset>>4)] = decoder->quantizer_scale; \
400 decoder->offset += 16; \
401 if (decoder->offset == decoder->width) { \
402 do { /* just so we can use the break statement */ \
403 @@ -1604,6 +1604,12 @@
407 +static void motion_dummy (mpeg2_decoder_t * const decoder,
408 + motion_t * const motion,
409 + mpeg2_mc_fct * const * const table)
413 void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
414 uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3])
416 @@ -1661,7 +1667,9 @@
418 if (decoder->mpeg1) {
419 decoder->motion_parser[0] = motion_zero_420;
420 + decoder->motion_parser[MC_FIELD] = motion_dummy;
421 decoder->motion_parser[MC_FRAME] = motion_mp1;
422 + decoder->motion_parser[MC_DMV] = motion_dummy;
423 decoder->motion_parser[4] = motion_reuse_420;
424 } else if (decoder->picture_structure == FRAME_PICTURE) {
425 if (decoder->chroma_format == 0) {
426 --- libmpeg2/idct.c 2006-06-16 20:12:26.000000000 +0200
427 +++ libmpeg2/idct.c 2006-06-16 20:12:50.000000000 +0200
429 mpeg2_idct_mmx_init ();
433 +#if defined(ARCH_PPC) && defined(HAVE_ALTIVEC)
434 if (accel & MPEG2_ACCEL_PPC_ALTIVEC) {
435 mpeg2_idct_copy = mpeg2_idct_copy_altivec;
436 mpeg2_idct_add = mpeg2_idct_add_altivec;
437 --- libmpeg2/idct_altivec.c 2004/08/02 11:26:43 12933
438 +++ libmpeg2/idct_altivec.c 2005/05/15 20:11:34 15484
440 typedef vector signed int vector_s32_t;
441 typedef vector unsigned int vector_u32_t;
443 -#if defined(HAVE_ALTIVEC_H) && (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
444 +#if defined( HAVE_ALTIVEC_H ) && !defined( __APPLE_ALTIVEC__ ) && (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
445 /* work around gcc <3.3 vec_mergel bug */
446 static inline vector_s16_t my_vec_mergel (vector_s16_t const A,
447 vector_s16_t const B)
449 #define vec_mergel my_vec_mergel
452 -#ifdef HAVE_ALTIVEC_H /* gnu */
453 -#define VEC_S16(a,b,c,d,e,f,g,h) {a, b, c, d, e, f, g, h}
455 +#if defined( __APPLE_CC__ ) && defined( __APPLE_ALTIVEC__ ) /* apple */
456 #define VEC_S16(a,b,c,d,e,f,g,h) (vector_s16_t) (a, b, c, d, e, f, g, h)
458 +#define VEC_S16(a,b,c,d,e,f,g,h) {a, b, c, d, e, f, g, h}
461 static const vector_s16_t constants ATTR_ALIGN(16) =