From 156ec7764eec11e78de6b7a17cef7679a9e30a63 Mon Sep 17 00:00:00 2001 From: arpi_esp Date: Sun, 4 Mar 2001 21:01:54 +0000 Subject: libmpeg2-0.2.0 merge git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@37 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpeg2/Makefile | 4 +- libmpeg2/attributes.h | 8 +- libmpeg2/decode.c | 174 ++++----- libmpeg2/header.c | 91 ++--- libmpeg2/idct.c | 5 +- libmpeg2/idct_mlib.c | 6 +- libmpeg2/idct_mmx.c | 57 ++- libmpeg2/mmx.h | 8 +- libmpeg2/motion_comp.c | 6 +- libmpeg2/motion_comp_mlib.c | 4 +- libmpeg2/motion_comp_mmx.c | 56 ++- libmpeg2/mpeg2.h | 92 +++-- libmpeg2/mpeg2_internal.h | 177 ++++----- libmpeg2/slice.c | 928 ++++++++++++++++++++++---------------------- libmpeg2/stats.c | 9 +- libmpeg2/vlc.h | 18 +- 16 files changed, 791 insertions(+), 852 deletions(-) (limited to 'libmpeg2') diff --git a/libmpeg2/Makefile b/libmpeg2/Makefile index f599aecfd2..ccc2e2595a 100644 --- a/libmpeg2/Makefile +++ b/libmpeg2/Makefile @@ -3,8 +3,8 @@ LIBNAME = libmpeg2.a include ../config.mak -SRCS = decode.c header.c idct.c idct_mmx.c motion_comp.c motion_comp_mmx.c slice.c stats.c -OBJS = decode.o header.o idct.o idct_mmx.o motion_comp.o motion_comp_mmx.o slice.o stats.o +SRCS = header.c idct.c idct_mmx.c motion_comp.c motion_comp_mmx.c slice.c stats.c decode.c +OBJS = header.o idct.o idct_mmx.o motion_comp.o motion_comp_mmx.o slice.o stats.o decode.o INCLUDE = -I. -I../libvo -I.. CFLAGS = $(OPTFLAGS) $(INCLUDE) -DMPG12PLAY diff --git a/libmpeg2/attributes.h b/libmpeg2/attributes.h index dfbf129411..3e14cab271 100644 --- a/libmpeg2/attributes.h +++ b/libmpeg2/attributes.h @@ -1,6 +1,6 @@ /* * attributes.h - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -19,11 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//use gcc attribs to align critical data structures - -/* maximum supported data alignment */ -#define ATTRIBUTE_ALIGNED_MAX 64 - +/* 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))) #else diff --git a/libmpeg2/decode.c b/libmpeg2/decode.c index e8bbb02112..9426f4ff59 100644 --- a/libmpeg2/decode.c +++ b/libmpeg2/decode.c @@ -3,8 +3,7 @@ /* mpeg2dec version: */ #define PACKAGE "mpeg2dec" -//#define VERSION "0.1.7-cvs" -#define VERSION "0.1.8-cvs" +#define VERSION "0.2.0-release" #include #include @@ -14,7 +13,8 @@ #include "config.h" -//#include "video_out.h" +#include "video_out.h" +#include #include "mpeg2.h" #include "mpeg2_internal.h" @@ -32,6 +32,9 @@ #include "mmx.h" #endif +#include "mm_accel.h" + + //this is where we keep the state of the decoder //picture_t picture_data; //picture_t *picture=&picture_data; @@ -48,7 +51,9 @@ mpeg2_config_t config; static int drop_flag = 0; static int drop_frame = 0; +#ifdef POSTPROC int quant_store[MBR+1][MBC+1]; // [Review] +#endif void mpeg2_init (void) { @@ -73,7 +78,7 @@ void mpeg2_init (void) picture=shmem_alloc(sizeof(picture_t)); // !!! NEW HACK :) !!! header_state_init (picture); - picture->repeat_count=0; +// picture->repeat_count=0; picture->pp_options=0; @@ -81,10 +86,13 @@ void mpeg2_init (void) motion_comp_init (); } +static vo_frame_t frames[3]; + void mpeg2_allocate_image_buffers (picture_t * picture) { int frame_size,buff_size; unsigned char *base=NULL; + int i; // height+1 requires for yuv2rgb_mmx code (it reads next line after last) frame_size = picture->coded_picture_width * (1+picture->coded_picture_height); @@ -92,56 +100,44 @@ void mpeg2_allocate_image_buffers (picture_t * picture) buff_size = frame_size + (frame_size/4)*2; // 4Y + 1U + 1V // allocate images in YV12 format - base = shmem_alloc(buff_size); - picture->throwaway_frame[0] = base; - picture->throwaway_frame[1] = base + frame_size * 5 / 4; - picture->throwaway_frame[2] = base + frame_size; - - base = shmem_alloc(buff_size); - picture->backward_reference_frame[0] = base; - picture->backward_reference_frame[1] = base + frame_size * 5 / 4; - picture->backward_reference_frame[2] = base + frame_size; - - base = shmem_alloc(buff_size); - picture->forward_reference_frame[0] = base; - picture->forward_reference_frame[1] = base + frame_size * 5 / 4; - picture->forward_reference_frame[2] = base + frame_size; + for(i=0;i<3;i++){ + base = shmem_alloc(buff_size); + frames[i].base[0] = base; + frames[i].base[1] = base + frame_size * 5 / 4; + frames[i].base[2] = base + frame_size; + frames[i].copy = NULL; + frames[i].vo = NULL; + frames[i].slice=0; + } + + picture->forward_reference_frame=&frames[0]; + picture->backward_reference_frame=&frames[1]; + picture->current_frame=&frames[2]; +#ifdef POSTPROC base = shmem_alloc(buff_size); picture->pp_frame[0] = base; picture->pp_frame[1] = base + frame_size * 5 / 4; picture->pp_frame[2] = base + frame_size; +#endif } -static void decode_reorder_frames (void) -{ - if (picture->picture_coding_type != B_TYPE) { - - //reuse the soon to be outdated forward reference frame - picture->current_frame[0] = picture->forward_reference_frame[0]; - picture->current_frame[1] = picture->forward_reference_frame[1]; - picture->current_frame[2] = picture->forward_reference_frame[2]; +static void copy_slice (vo_frame_t * frame, uint8_t ** src){ + vo_functions_t * output = frame->vo; + int stride[3]; + int y=frame->slice*16; - //make the backward reference frame the new forward reference frame - picture->forward_reference_frame[0] = - picture->backward_reference_frame[0]; - picture->forward_reference_frame[1] = - picture->backward_reference_frame[1]; - picture->forward_reference_frame[2] = - picture->backward_reference_frame[2]; + stride[0]=picture->coded_picture_width; + stride[1]=stride[2]=stride[0]/2; - picture->backward_reference_frame[0] = picture->current_frame[0]; - picture->backward_reference_frame[1] = picture->current_frame[1]; - picture->backward_reference_frame[2] = picture->current_frame[2]; + output->draw_slice (src, stride, + picture->display_picture_width, + (y+16<=picture->display_picture_height) ? 16 : + picture->display_picture_height-y, + 0, y); - } else { - - picture->current_frame[0] = picture->throwaway_frame[0]; - picture->current_frame[1] = picture->throwaway_frame[1]; - picture->current_frame[2] = picture->throwaway_frame[2]; - - } + ++frame->slice; } static int in_slice_flag=0; @@ -156,43 +152,27 @@ static int parse_chunk (vo_functions_t * output, int code, uint8_t * buffer) if (is_frame_done) { in_slice_flag = 0; - if(picture->picture_structure != FRAME_PICTURE) printf("Field! %d \n",picture->second_field); +// if(picture->picture_structure != FRAME_PICTURE) printf("Field! %d \n",picture->second_field); - if ( ((HACK_MODE == 2) || (picture->mpeg1)) - && ((picture->picture_structure == FRAME_PICTURE) || + if (((picture->picture_structure == FRAME_PICTURE) || (picture->second_field)) - ) { - uint8_t ** bar; - int stride[3]; - - if (picture->picture_coding_type == B_TYPE) - bar = picture->throwaway_frame; - else - bar = picture->forward_reference_frame; - - stride[0]=picture->coded_picture_width; - stride[1]=stride[2]=stride[0]/2; - - if(picture->pp_options){ - // apply OpenDivX postprocess filter - postprocess(bar, stride[0], - picture->pp_frame, stride[0], - picture->coded_picture_width, picture->coded_picture_height, - &quant_store[1][1], (MBC+1), picture->pp_options); - output->draw_slice (picture->pp_frame, stride, - picture->display_picture_width, - picture->display_picture_height, 0, 0); - } else { - output->draw_slice (bar, stride, + ) { +#if 1 + if (picture->picture_coding_type != B_TYPE) { + int stride[3]; + stride[0]=picture->coded_picture_width; + stride[1]=stride[2]=stride[0]/2; + output->draw_slice (picture->forward_reference_frame->base, + stride, picture->display_picture_width, picture->display_picture_height, 0, 0); } - - } +#endif + } #ifdef ARCH_X86 - if (config.flags & MM_ACCEL_X86_MMX) emms (); + if (config.flags & MM_ACCEL_X86_MMX) emms(); #endif - output->flip_page (); + output->flip_page(); } switch (code) { @@ -227,40 +207,32 @@ static int parse_chunk (vo_functions_t * output, int code, uint8_t * buffer) if (!(in_slice_flag)) { in_slice_flag = 1; - if(!(picture->second_field)) decode_reorder_frames (); +// if(!(picture->second_field)) decode_reorder_frames (); + + // set current_frame pointer: + if (picture->second_field){ +// vo_field (picture->current_frame, picture->picture_structure); + } else { + if (picture->picture_coding_type == B_TYPE){ + picture->current_frame = &frames[2]; + picture->current_frame->copy=copy_slice; + } else { + picture->current_frame = picture->forward_reference_frame; + picture->forward_reference_frame = picture->backward_reference_frame; + picture->backward_reference_frame = picture->current_frame; + picture->current_frame->copy=NULL; + } + } + + picture->current_frame->vo=output; + picture->current_frame->slice=0; + } if (!drop_frame) { - uint8_t ** bar; slice_process (picture, code, buffer); - if ((HACK_MODE < 2) && (!(picture->mpeg1))) { - uint8_t * foo[3]; - uint8_t ** bar; - //frame_t * bar; - int stride[3]; - int offset; - - if (picture->picture_coding_type == B_TYPE) - bar = picture->throwaway_frame; - else - bar = picture->forward_reference_frame; - - offset = (code-1) * 4 * picture->coded_picture_width; - if ((! HACK_MODE) && (picture->picture_coding_type == B_TYPE)) - offset = 0; - - foo[0] = bar[0] + 4 * offset; - foo[1] = bar[1] + offset; - foo[2] = bar[2] + offset; - - stride[0]=picture->coded_picture_width; - stride[1]=stride[2]=stride[0]/2; - - output->draw_slice (foo, stride, - picture->display_picture_width, 16, 0, (code-1)*16); - } #ifdef ARCH_X86 if (config.flags & MM_ACCEL_X86_MMX) emms (); #endif diff --git a/libmpeg2/header.c b/libmpeg2/header.c index 8f5b34359e..852ff541bd 100644 --- a/libmpeg2/header.c +++ b/libmpeg2/header.c @@ -1,6 +1,6 @@ /* * slice.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -26,7 +26,7 @@ #include "mpeg2_internal.h" #include "attributes.h" -// default intra quant matrix, in zig-zag order +/* default intra quant matrix, in zig-zag order */ static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = { 8, 16, 16, @@ -47,7 +47,7 @@ static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = { uint8_t scan_norm[64] ATTR_ALIGN(16) = { - // Zig-Zag scan pattern + /* Zig-Zag scan pattern */ 0, 1, 8,16, 9, 2, 3,10, 17,24,32,25,18,11, 4, 5, 12,19,26,33,40,48,41,34, @@ -60,7 +60,7 @@ uint8_t scan_norm[64] ATTR_ALIGN(16) = uint8_t scan_alt[64] ATTR_ALIGN(16) = { - // Alternate scan pattern + /* Alternate scan pattern */ 0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49, 41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43, 51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45, @@ -69,47 +69,34 @@ uint8_t scan_alt[64] ATTR_ALIGN(16) = void header_state_init (picture_t * picture) { - //FIXME we should set pointers to the real scan matrices here (mmx vs - //normal) instead of the ifdefs in header_process_picture_coding_extension - picture->scan = scan_norm; } -static const int frameratecode2framerate[16] = { - 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, - 60*10000, 0,0,0,0,0,0,0 -}; - int header_process_sequence_header (picture_t * picture, uint8_t * buffer) { - unsigned int h_size; - unsigned int v_size; + int width, height; int i; if ((buffer[6] & 0x20) != 0x20) - return 1; // missing marker_bit + return 1; /* missing marker_bit */ - v_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; + height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; - picture->display_picture_width = (v_size >> 12); - picture->display_picture_height = (v_size & 0xfff); + picture->display_picture_width = (height >> 12); + picture->display_picture_height = (height & 0xfff); - h_size = ((v_size >> 12) + 15) & ~15; - v_size = ((v_size & 0xfff) + 15) & ~15; + width = ((height >> 12) + 15) & ~15; + height = ((height & 0xfff) + 15) & ~15; - if ((h_size > 768) || (v_size > 576)) - return 1; // size restrictions for MP@ML or MPEG1 + if ((width > 768) || (height > 576)) + return 1; /* size restrictions for MP@ML or MPEG1 */ - //XXX this needs field fixups - picture->coded_picture_width = h_size; - picture->coded_picture_height = v_size; - picture->last_mba = ((h_size * v_size) >> 8) - 1; + picture->coded_picture_width = width; + picture->coded_picture_height = height; - // this is not used by the decoder + /* this is not used by the decoder */ picture->aspect_ratio_information = buffer[3] >> 4; picture->frame_rate_code = buffer[3] & 15; - picture->frame_rate = frameratecode2framerate[picture->frame_rate_code]; - picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6); if (buffer[7] & 2) { @@ -132,15 +119,15 @@ int header_process_sequence_header (picture_t * picture, uint8_t * buffer) picture->non_intra_quantizer_matrix[i] = 16; } - // MPEG1 - for testing only + /* MPEG1 - for testing only */ picture->mpeg1 = 1; picture->intra_dc_precision = 0; picture->frame_pred_frame_dct = 1; picture->q_scale_type = 0; picture->concealment_motion_vectors = 0; - //picture->alternate_scan = 0; + /* picture->alternate_scan = 0; */ picture->picture_structure = FRAME_PICTURE; - //picture->second_field = 0; + /* picture->second_field = 0; */ return 0; } @@ -148,28 +135,20 @@ int header_process_sequence_header (picture_t * picture, uint8_t * buffer) static int header_process_sequence_extension (picture_t * picture, uint8_t * buffer) { - // MPEG1 - for testing only - picture->mpeg1 = 0; + /* check chroma format, size extensions, marker bit */ + if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) || + ((buffer[3] & 0x01) != 0x01)) + return 1; - // check chroma format, size extensions, marker bit - if(((buffer[1]>>1)&3)!=1){ - printf("This CHROMA format not yet supported :(\n"); - return 1; - } - if ((buffer[1] & 1) || (buffer[2] & 0xe0)){ - printf("Big resolution video not yet supported :(\n"); - return 1; - } - if((buffer[3] & 0x01) != 0x01) return 1; // marker bit - - - // this is not used by the decoder + /* this is not used by the decoder */ picture->progressive_sequence = (buffer[1] >> 3) & 1; if (picture->progressive_sequence) picture->coded_picture_height = (picture->coded_picture_height + 31) & ~31; - picture->bitrate>>=1; // hack + + /* MPEG1 - for testing only */ + picture->mpeg1 = 0; return 0; } @@ -197,7 +176,7 @@ static int header_process_quant_matrix_extension (picture_t * picture, static int header_process_picture_coding_extension (picture_t * picture, uint8_t * buffer) { - //pre subtract 1 for use later in compute_motion_vector + /* pre subtract 1 for use later in compute_motion_vector */ picture->f_code[0][0] = (buffer[0] & 15) - 1; picture->f_code[0][1] = (buffer[1] >> 4) - 1; picture->f_code[1][0] = (buffer[1] & 15) - 1; @@ -210,12 +189,12 @@ static int header_process_picture_coding_extension (picture_t * picture, uint8_t picture->q_scale_type = (buffer[3] >> 4) & 1; picture->intra_vlc_format = (buffer[3] >> 3) & 1; - if (buffer[3] & 4) // alternate_scan + if (buffer[3] & 4) /* alternate_scan */ picture->scan = scan_alt; else picture->scan = scan_norm; - // these are not used by the decoder + /* these are not used by the decoder */ picture->top_field_first = buffer[3] >> 7; picture->repeat_first_field = (buffer[3] >> 1) & 1; picture->progressive_frame = buffer[4] >> 7; @@ -240,13 +219,13 @@ static int header_process_picture_coding_extension (picture_t * picture, uint8_t int header_process_extension (picture_t * picture, uint8_t * buffer) { switch (buffer[0] & 0xf0) { - case 0x10: // sequence extension + case 0x10: /* sequence extension */ return header_process_sequence_extension (picture, buffer); - case 0x30: // quant matrix extension + case 0x30: /* quant matrix extension */ return header_process_quant_matrix_extension (picture, buffer); - case 0x80: // picture coding extension + case 0x80: /* picture coding extension */ return header_process_picture_coding_extension (picture, buffer); } @@ -257,14 +236,14 @@ int header_process_picture_header (picture_t *picture, uint8_t * buffer) { picture->picture_coding_type = (buffer [1] >> 3) & 7; - // forward_f_code and backward_f_code - used in mpeg1 only + /* forward_f_code and backward_f_code - used in mpeg1 only */ picture->f_code[0][1] = (buffer[3] >> 2) & 1; picture->f_code[0][0] = (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1; picture->f_code[1][1] = (buffer[4] >> 6) & 1; picture->f_code[1][0] = ((buffer[4] >> 3) & 7) - 1; - // move in header_process_picture_header + /* move in header_process_picture_header */ picture->second_field = (picture->picture_structure != FRAME_PICTURE) && !(picture->second_field); diff --git a/libmpeg2/idct.c b/libmpeg2/idct.c index 7411e176dd..d78ad49e8d 100644 --- a/libmpeg2/idct.c +++ b/libmpeg2/idct.c @@ -1,6 +1,6 @@ /* * idct.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * Portions of this code are from the MPEG software simulation group * idct implementation. This code will be replaced with a new @@ -52,8 +52,7 @@ #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ - -// idct main entry point +/* idct main entry 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); diff --git a/libmpeg2/idct_mlib.c b/libmpeg2/idct_mlib.c index 055ee75fa6..876ab574a4 100644 --- a/libmpeg2/idct_mlib.c +++ b/libmpeg2/idct_mlib.c @@ -1,6 +1,6 @@ /* * idct_mlib.c - * Copyright (C) 1999 Håkan Hjort + * Copyright (C) 1999-2001 Håkan Hjort * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -38,8 +38,8 @@ 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) { - // Should we use mlib_VideoIDCT_IEEE_S16_S16 here ?? - // it's ~30% slower. + /* 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/libmpeg2/idct_mmx.c b/libmpeg2/idct_mmx.c index 03ea5d7580..6c5d2ed96e 100644 --- a/libmpeg2/idct_mmx.c +++ b/libmpeg2/idct_mmx.c @@ -1,6 +1,6 @@ /* * idct_mmx.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -37,7 +37,7 @@ #if 0 -// C row IDCT - its just here to document the MMXEXT and MMX versions +/* C row IDCT - its just here to document the MMXEXT and MMX versions */ static inline void idct_row (int16_t * row, int offset, int16_t * table, int32_t * rounder) { @@ -76,7 +76,7 @@ static inline void idct_row (int16_t * row, int offset, #endif -// MMXEXT row IDCT +/* MMXEXT row IDCT */ #define mmxext_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, -c4, -c2, \ c4, c6, c4, c6, \ @@ -155,7 +155,7 @@ static inline void mmxext_row_tail (int16_t * row, int store) movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0 pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4 - // slot + /* slot */ movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4 } @@ -188,7 +188,7 @@ static inline void mmxext_row_mid (int16_t * row, int store, } -// MMX row IDCT +/* MMX row IDCT */ #define mmx_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, c4, c6, \ c4, c6, -c4, -c2, \ @@ -276,7 +276,7 @@ static inline void mmx_row_tail (int16_t * row, int store) por_r2r (mm4, mm7); // mm7 = y7 y6 y5 y4 - // slot + /* slot */ movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4 } @@ -320,10 +320,10 @@ static inline void mmx_row_mid (int16_t * row, int store, // C column IDCT - its just here to document the MMXEXT and MMX versions static inline void idct_col (int16_t * col, int offset) { -// multiplication - as implemented on mmx +/* multiplication - as implemented on mmx */ #define F(c,x) (((c) * (x)) >> 16) -// saturation - it helps us handle torture test cases +/* saturation - it helps us handle torture test cases */ #define S(x) (((x)>32767) ? 32767 : ((x)<-32768) ? -32768 : (x)) int16_t x0, x1, x2, x3, x4, x5, x6, x7; @@ -344,25 +344,25 @@ static inline void idct_col (int16_t * col, int offset) u04 = S (x0 + x4); v04 = S (x0 - x4); - u26 = S (F (T2, x6) + x2); // -0.5 - v26 = S (F (T2, x2) - x6); // -0.5 + u26 = S (F (T2, x6) + x2); + v26 = S (F (T2, x2) - x6); a0 = S (u04 + u26); a1 = S (v04 + v26); a2 = S (v04 - v26); a3 = S (u04 - u26); - u17 = S (F (T1, x7) + x1); // -0.5 - v17 = S (F (T1, x1) - x7); // -0.5 - u35 = S (F (T3, x5) + x3); // -0.5 - v35 = S (F (T3, x3) - x5); // -0.5 + u17 = S (F (T1, x7) + x1); + v17 = S (F (T1, x1) - x7); + u35 = S (F (T3, x5) + x3); + v35 = S (F (T3, x3) - x5); b0 = S (u17 + u35); b3 = S (v17 - v35); u12 = S (u17 - u35); v12 = S (v17 + v35); - u12 = S (2 * F (C4, u12)); // -0.5 - v12 = S (2 * F (C4, v12)); // -0.5 + u12 = S (2 * F (C4, u12)); + v12 = S (2 * F (C4, v12)); b1 = S (u12 + v12); b2 = S (u12 - v12); @@ -400,7 +400,6 @@ static inline void idct_col (int16_t * col, int offset) static short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2}; static short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3}; static short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4}; - static mmx_t scratch0, scratch1; /* column code adapted from peter gubanov */ /* http://www.elecard.com/peter/idct.shtml */ @@ -428,7 +427,7 @@ static inline void idct_col (int16_t * col, int offset) paddsw_r2r (mm2, mm1); // mm1 = u17 pmulhw_r2r (mm6, mm7); // mm7 = (T3-1)*x5 - // slot + /* slot */ movq_r2r (mm4, mm2); // mm2 = T2 paddsw_r2r (mm3, mm5); // mm5 = T3*x3 @@ -448,7 +447,7 @@ static inline void idct_col (int16_t * col, int offset) psubsw_r2r (mm3, mm4); // mm4 = v26 paddsw_r2r (mm6, mm5); // mm5 = v12 - movq_r2m (mm0, scratch0); // save b3 + movq_r2m (mm0, *(col+offset+3*8)); // save b3 in scratch0 movq_r2r (mm1, mm6); // mm6 = u17 paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26 @@ -463,7 +462,7 @@ static inline void idct_col (int16_t * col, int offset) movq_m2r (*_C4, mm0); // mm0 = C4/2 psubsw_r2r (mm5, mm7); // mm7 = u12-v12 - movq_r2m (mm6, scratch1); // save b0 + movq_r2m (mm6, *(col+offset+5*8)); // save b0 in scratch1 pmulhw_r2r (mm0, mm1); // mm1 = b1/2 movq_r2r (mm4, mm6); // mm6 = v26 @@ -496,7 +495,7 @@ static inline void idct_col (int16_t * col, int offset) psraw_i2r (COL_SHIFT, mm4); // mm4 = y1 psubsw_r2r (mm1, mm6); // mm6 = a1-b1 - movq_m2r (scratch1, mm1); // mm1 = b0 + movq_m2r (*(col+offset+5*8), mm1); // mm1 = b0 psubsw_r2r (mm7, mm2); // mm2 = a2-b2 psraw_i2r (COL_SHIFT, mm6); // mm6 = y6 @@ -508,7 +507,7 @@ static inline void idct_col (int16_t * col, int offset) movq_r2m (mm3, *(col+offset+2*8)); // save y2 paddsw_r2r (mm1, mm5); // mm5 = a0+b0 - movq_m2r (scratch0, mm4); // mm4 = b3 + movq_m2r (*(col+offset+3*8), mm4); // mm4 = b3 psubsw_r2r (mm1, mm7); // mm7 = a0-b0 psraw_i2r (COL_SHIFT, mm5); // mm5 = y0 @@ -538,17 +537,17 @@ static int32_t rounder0[] ATTR_ALIGN(8) = rounder ((1 << (COL_SHIFT - 1)) - 0.5); static int32_t rounder4[] ATTR_ALIGN(8) = rounder (0); static int32_t rounder1[] ATTR_ALIGN(8) = - rounder (1.25683487303); // C1*(C1/C4+C1+C7)/2 + rounder (1.25683487303); /* C1*(C1/C4+C1+C7)/2 */ static int32_t rounder7[] ATTR_ALIGN(8) = - rounder (-0.25); // C1*(C7/C4+C7-C1)/2 + rounder (-0.25); /* C1*(C7/C4+C7-C1)/2 */ static int32_t rounder2[] ATTR_ALIGN(8) = - rounder (0.60355339059); // C2 * (C6+C2)/2 + rounder (0.60355339059); /* C2 * (C6+C2)/2 */ static int32_t rounder6[] ATTR_ALIGN(8) = - rounder (-0.25); // C2 * (C6-C2)/2 + rounder (-0.25); /* C2 * (C6-C2)/2 */ static int32_t rounder3[] ATTR_ALIGN(8) = - rounder (0.087788325588); // C3*(-C3/C4+C3+C5)/2 + rounder (0.087788325588); /* C3*(-C3/C4+C3+C5)/2 */ static int32_t rounder5[] ATTR_ALIGN(8) = - rounder (-0.441341716183); // C3*(-C5/C4+C5-C3)/2 + rounder (-0.441341716183); /* C3*(-C5/C4+C5-C3)/2 */ #define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid) \ @@ -693,7 +692,7 @@ void idct_mmx_init (void) extern uint8_t scan_alt[64]; int i, j; - // the mmx/mmxext idct uses a reordered input, so we patch scan tables + /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */ for (i = 0; i < 64; i++) { j = scan_norm[i]; diff --git a/libmpeg2/mmx.h b/libmpeg2/mmx.h index bab97b8b1f..ac23866690 100644 --- a/libmpeg2/mmx.h +++ b/libmpeg2/mmx.h @@ -1,6 +1,6 @@ /* * mmx.h - * Copyright (C) 1997-1999 H. Dietz and R. Fisher + * Copyright (C) 1997-2001 H. Dietz and R. Fisher * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -41,16 +41,16 @@ typedef union { #define mmx_i2r(op,imm,reg) \ __asm__ __volatile__ (#op " %0, %%" #reg \ : /* nothing */ \ - : "X" (imm) ) + : "i" (imm) ) #define mmx_m2r(op,mem,reg) \ __asm__ __volatile__ (#op " %0, %%" #reg \ : /* nothing */ \ - : "X" (mem)) + : "m" (mem)) #define mmx_r2m(op,reg,mem) \ __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ + : "=m" (mem) \ : /* nothing */ ) #define mmx_r2r(op,regs,regd) \ diff --git a/libmpeg2/motion_comp.c b/libmpeg2/motion_comp.c index 816335c6dc..52e4655362 100644 --- a/libmpeg2/motion_comp.c +++ b/libmpeg2/motion_comp.c @@ -1,6 +1,6 @@ /* * motion_comp.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -67,7 +67,7 @@ void motion_comp_init (void) #define put(predictor,i) dest[i] = predictor (i) #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i]) -// mc function template +/* mc function template */ #define MC_FUNC(op,xy) \ static void MC_##op##_##xy##16_c (uint8_t * dest, uint8_t * ref,\ @@ -111,7 +111,7 @@ static void MC_##op##_##xy##8_c (uint8_t * dest, uint8_t * ref, \ } while (--height); \ } -// definitions of the actual mc functions +/* definitions of the actual mc functions */ MC_FUNC (put,) MC_FUNC (avg,) diff --git a/libmpeg2/motion_comp_mlib.c b/libmpeg2/motion_comp_mlib.c index e079119eb9..91c0fb5a87 100644 --- a/libmpeg2/motion_comp_mlib.c +++ b/libmpeg2/motion_comp_mlib.c @@ -1,6 +1,6 @@ /* - * MC_mlib.c - * Copyright (C) 2000 Håkan Hjort + * motion_comp_mlib.c + * Copyright (C) 2000-2001 Håkan Hjort * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * diff --git a/libmpeg2/motion_comp_mmx.c b/libmpeg2/motion_comp_mmx.c index f635692045..51b40bac55 100644 --- a/libmpeg2/motion_comp_mmx.c +++ b/libmpeg2/motion_comp_mmx.c @@ -1,6 +1,6 @@ /* * motion_comp_mmx.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -33,7 +33,7 @@ #define CPU_3DNOW 1 -//MMX code - needs a rewrite +/* MMX code - needs a rewrite */ @@ -41,7 +41,7 @@ -// some rounding constants +/* some rounding constants */ mmx_t round1 = {0x0001000100010001LL}; mmx_t round4 = {0x0002000200020002LL}; @@ -55,16 +55,14 @@ mmx_t round4 = {0x0002000200020002LL}; static inline void mmx_zero_reg () { - // load 0 into mm0 + /* load 0 into mm0 */ pxor_r2r (mm0, mm0); } static inline void mmx_average_2_U8 (uint8_t * dest, uint8_t * src1, uint8_t * src2) { - // - // *dest = (*src1 + *src2 + 1)/ 2; - // + /* *dest = (*src1 + *src2 + 1)/ 2; */ movq_m2r (*src1, mm1); // load 8 src1 bytes movq_r2r (mm1, mm2); // copy 8 src1 bytes @@ -93,9 +91,7 @@ static inline void mmx_average_2_U8 (uint8_t * dest, static inline void mmx_interp_average_2_U8 (uint8_t * dest, uint8_t * src1, uint8_t * src2) { - // - // *dest = (*dest + (*src1 + *src2 + 1)/ 2 + 1)/ 2; - // + /* *dest = (*dest + (*src1 + *src2 + 1)/ 2 + 1)/ 2; */ movq_m2r (*dest, mm1); // load 8 dest bytes movq_r2r (mm1, mm2); // copy 8 dest bytes @@ -139,9 +135,7 @@ static inline void mmx_average_4_U8 (uint8_t * dest, uint8_t * src1, uint8_t * src2, uint8_t * src3, uint8_t * src4) { - // - // *dest = (*src1 + *src2 + *src3 + *src4 + 2)/ 4; - // + /* *dest = (*src1 + *src2 + *src3 + *src4 + 2)/ 4; */ movq_m2r (*src1, mm1); // load 8 src1 bytes movq_r2r (mm1, mm2); // copy 8 src1 bytes @@ -158,7 +152,7 @@ static inline void mmx_average_4_U8 (uint8_t * dest, paddw_r2r (mm3, mm1); // add lows paddw_r2r (mm4, mm2); // add highs - // now have partials in mm1 and mm2 + /* now have partials in mm1 and mm2 */ movq_m2r (*src3, mm3); // load 8 src3 bytes movq_r2r (mm3, mm4); // copy 8 src3 bytes @@ -178,7 +172,7 @@ static inline void mmx_average_4_U8 (uint8_t * dest, paddw_r2r (mm5, mm1); // add lows paddw_r2r (mm6, mm2); // add highs - // now have subtotal in mm1 and mm2 + /* now have subtotal in mm1 and mm2 */ paddw_m2r (round4, mm1); psraw_i2r (2, mm1); // /4 @@ -193,9 +187,7 @@ static inline void mmx_interp_average_4_U8 (uint8_t * dest, uint8_t * src1, uint8_t * src2, uint8_t * src3, uint8_t * src4) { - // - // *dest = (*dest + (*src1 + *src2 + *src3 + *src4 + 2)/ 4 + 1)/ 2; - // + /* *dest = (*dest + (*src1 + *src2 + *src3 + *src4 + 2)/ 4 + 1)/ 2; */ movq_m2r (*src1, mm1); // load 8 src1 bytes movq_r2r (mm1, mm2); // copy 8 src1 bytes @@ -212,7 +204,7 @@ static inline void mmx_interp_average_4_U8 (uint8_t * dest, paddw_r2r (mm3, mm1); // add lows paddw_r2r (mm4, mm2); // add highs - // now have partials in mm1 and mm2 + /* now have partials in mm1 and mm2 */ movq_m2r (*src3, mm3); // load 8 src3 bytes movq_r2r (mm3, mm4); // copy 8 src3 bytes @@ -237,7 +229,7 @@ static inline void mmx_interp_average_4_U8 (uint8_t * dest, paddw_m2r (round4, mm2); psraw_i2r (2, mm2); // /4 - // now have subtotal/4 in mm1 and mm2 + /* now have subtotal/4 in mm1 and mm2 */ movq_m2r (*dest, mm3); // load 8 dest bytes movq_r2r (mm3, mm4); // copy 8 dest bytes @@ -253,13 +245,13 @@ static inline void mmx_interp_average_4_U8 (uint8_t * dest, paddw_m2r (round1, mm2); psraw_i2r (1, mm2); // /2 - // now have end value in mm1 and mm2 + /* now have end value in mm1 and mm2 */ packuswb_r2r (mm2, mm1); // pack (w/ saturation) movq_r2m (mm1,*dest); // store result in dest } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_avg_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -289,7 +281,7 @@ static void MC_avg_8_mmx (uint8_t * dest, uint8_t * ref, MC_avg_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_put_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -323,9 +315,9 @@ static void MC_put_8_mmx (uint8_t * dest, uint8_t * ref, MC_put_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ -// Half pixel interpolation in the x direction +/* Half pixel interpolation in the x direction */ static inline void MC_avg_x_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) { @@ -354,7 +346,7 @@ static void MC_avg_x8_mmx (uint8_t * dest, uint8_t * ref, MC_avg_x_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_put_x_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -384,7 +376,7 @@ static void MC_put_x8_mmx (uint8_t * dest, uint8_t * ref, MC_put_x_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_avg_xy_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -418,7 +410,7 @@ static void MC_avg_xy8_mmx (uint8_t * dest, uint8_t * ref, MC_avg_xy_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_put_xy_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -451,7 +443,7 @@ static void MC_put_xy8_mmx (uint8_t * dest, uint8_t * ref, MC_put_xy_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_avg_y_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -484,7 +476,7 @@ static void MC_avg_y8_mmx (uint8_t * dest, uint8_t * ref, MC_avg_y_mmx (8, height, dest, ref, stride); } -//----------------------------------------------------------------------- +/*-----------------------------------------------------------------------*/ static inline void MC_put_y_mmx (int width, int height, uint8_t * dest, uint8_t * ref, int stride) @@ -526,7 +518,7 @@ MOTION_COMP_EXTERN (mmx) -//CPU_MMXEXT/CPU_3DNOW adaptation layer +/* CPU_MMXEXT/CPU_3DNOW adaptation layer */ #define pavg_r2r(src,dest) \ do { \ @@ -545,7 +537,7 @@ do { \ } while (0) -//CPU_MMXEXT code +/* CPU_MMXEXT code */ static inline void MC_put1_8 (int height, uint8_t * dest, uint8_t * ref, diff --git a/libmpeg2/mpeg2.h b/libmpeg2/mpeg2.h index 68f74289c8..c3bce07805 100644 --- a/libmpeg2/mpeg2.h +++ b/libmpeg2/mpeg2.h @@ -1,57 +1,71 @@ /* * mpeg2.h - * - * Copyright (C) Aaron Holtzman - Mar 2000 + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. - * + * * 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, or (at your option) - * any later version. - * + * 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 + * 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 GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, * + * 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 */ -#ifdef __OMS__ -#include -#ifndef vo_functions_t -#define vo_functions_t plugin_output_video_t -#endif -#else -//FIXME normally I wouldn't nest includes, but we'll leave this here until I get -//another chance to move things around -#include "video_out.h" -#endif - -#include -#ifdef __OMS__ -#include -#else -#include "mm_accel.h" -#endif - -//config flags -#define MPEG2_MLIB_ENABLE MM_ACCEL_MLIB -#define MPEG2_MMX_ENABLE MM_ACCEL_X86_MMX -#define MPEG2_3DNOW_ENABLE MM_ACCEL_X86_3DNOW -#define MPEG2_SSE_ENABLE MM_ACCEL_X86_MMXEXT - -//typedef struct mpeg2_config_s { -// //Bit flags that enable various things -// uint32_t flags; -//} mpeg2_config_t; +/* Structure for the mpeg2dec decoder */ + +typedef struct mpeg2dec_s { +// vo_instance_t * output; + + /* this is where we keep the state of the decoder */ + struct picture_s * picture; + + uint32_t shift; + int is_display_initialized; + int is_sequence_needed; + int drop_flag; + int drop_frame; + int in_slice; + + /* the maximum chunk size is determined by vbv_buffer_size */ + /* which is 224K for MP@ML streams. */ + /* (we make no pretenses of decoding anything more than that) */ + /* allocated in init - gcc has problems allocating such big structures */ + uint8_t * chunk_buffer; + /* pointer to current position in chunk_buffer */ + uint8_t * chunk_ptr; + /* last start code ? */ + uint8_t code; + + /* ONLY for 0.2.0 release - will not stay there later */ + int frame_rate_code; +} mpeg2dec_t ; + void mpeg2_init (void); //void mpeg2_allocate_image_buffers (picture_t * picture); int mpeg2_decode_data (vo_functions_t *, uint8_t * data_start, uint8_t * data_end); //void mpeg2_close (vo_functions_t *); void mpeg2_drop (int flag); + + + +/* initialize mpegdec with a opaque user pointer */ +//void mpeg2_init (mpeg2dec_t * mpeg2dec, uint32_t mm_accel +// ,vo_instance_t * output +// ); + +/* destroy everything which was allocated, shutdown the output */ +//void mpeg2_close (mpeg2dec_t * mpeg2dec); + +//int mpeg2_decode_data (mpeg2dec_t * mpeg2dec, +// uint8_t * data_start, uint8_t * data_end); + +//void mpeg2_drop (mpeg2dec_t * mpeg2dec, int flag); diff --git a/libmpeg2/mpeg2_internal.h b/libmpeg2/mpeg2_internal.h index 290bb22450..046f37159a 100644 --- a/libmpeg2/mpeg2_internal.h +++ b/libmpeg2/mpeg2_internal.h @@ -1,7 +1,6 @@ -#include /* * mpeg2_internal.h - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -20,20 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// hack mode - temporary -// 0 = decode B pictures in a small slice buffer, display slice per slice -// 1 = decode in a frame buffer, display slice per slice -// 2 = decode in a frame buffer, display whole frames -#define HACK_MODE 0 - -// macroblock modes +/* macroblock modes */ #define MACROBLOCK_INTRA 1 #define MACROBLOCK_PATTERN 2 #define MACROBLOCK_MOTION_BACKWARD 4 #define MACROBLOCK_MOTION_FORWARD 8 #define MACROBLOCK_QUANT 16 #define DCT_TYPE_INTERLACED 32 -// motion_type +/* motion_type */ #define MOTION_TYPE_MASK (3*64) #define MOTION_TYPE_BASE 64 #define MC_FIELD (1*64) @@ -41,151 +34,154 @@ #define MC_16X8 (2*64) #define MC_DMV (3*64) -//picture structure +/* picture structure */ #define TOP_FIELD 1 #define BOTTOM_FIELD 2 #define FRAME_PICTURE 3 -//picture coding type +/* picture coding type */ #define I_TYPE 1 #define P_TYPE 2 #define B_TYPE 3 #define D_TYPE 4 -//The picture struct contains all of the top level state -//information (ie everything except slice and macroblock -//state) +typedef struct motion_s { + uint8_t * ref[2][3]; + int pmv[2][2]; + int f_code[2]; +} motion_t; + +typedef struct vo_frame_s { + uint8_t * base[3]; /* pointer to 3 planes */ + void (* copy) (struct vo_frame_s * frame, uint8_t ** src); + void* vo; + int slice; +// void (* field) (struct vo_frame_s * frame, int flags); +// void (* draw) (struct vo_frame_s * frame); +// vo_instance_t * instance; +} vo_frame_t; + typedef struct picture_s { - //-- sequence header stuff -- + /* first, state that carries information from one macroblock to the */ + /* next inside a slice, and is never used outside of slice_process() */ + + /* DCT coefficients - should be kept aligned ! */ + int16_t DCTblock[64]; + + /* bit parsing stuff */ + uint32_t bitstream_buf; /* current 32 bit working set of buffer */ + int bitstream_bits; /* used bits in working set */ + uint8_t * bitstream_ptr; /* buffer with stream data */ + + /* Motion vectors */ + /* The f_ and b_ correspond to the forward and backward motion */ + /* predictors */ + motion_t b_motion; + motion_t f_motion; + + /* predictor for DC coefficients in intra blocks */ + int16_t dc_dct_pred[3]; + + int quantizer_scale; /* remove */ + int current_field; /* remove */ + + + /* now non-slice-specific information */ + + /* sequence header stuff */ uint8_t intra_quantizer_matrix [64]; uint8_t non_intra_quantizer_matrix [64]; - //The width and height of the picture snapped to macroblock units + /* The width and height of the picture snapped to macroblock units */ int coded_picture_width; int coded_picture_height; - //-- picture header stuff -- + /* picture header stuff */ - //what type of picture this is (I,P,or B) D from MPEG-1 isn't supported + /* what type of picture this is (I, P, B, D) */ int picture_coding_type; - //-- picture coding extension stuff -- + /* picture coding extension stuff */ - //quantization factor for motion vectors + /* quantization factor for motion vectors */ int f_code[2][2]; - //quantization factor for intra dc coefficients + /* quantization factor for intra dc coefficients */ int intra_dc_precision; - //top/bottom/both fields + /* top/bottom/both fields */ int picture_structure; - //bool to indicate all predictions are frame based + /* bool to indicate all predictions are frame based */ int frame_pred_frame_dct; - //bool to indicate whether intra blocks have motion vectors - // (for concealment) + /* bool to indicate whether intra blocks have motion vectors */ + /* (for concealment) */ int concealment_motion_vectors; - //bit to indicate which quantization table to use + /* bit to indicate which quantization table to use */ int q_scale_type; - //bool to use different vlc tables + /* bool to use different vlc tables */ int intra_vlc_format; + /* used for DMV MC */ + int top_field_first; - //last macroblock in the picture - int last_mba; - //width of picture in macroblocks - int mb_width; + /* stuff derived from bitstream */ - //stuff derived from bitstream - - //pointer to the zigzag scan we're supposed to be using + /* pointer to the zigzag scan we're supposed to be using */ uint8_t * scan; - //Pointer to the current planar frame buffer (Y,Cr,CB) - uint8_t * current_frame[3]; - //storage for reference frames plus a b-frame - uint8_t * forward_reference_frame[3]; - uint8_t * backward_reference_frame[3]; - uint8_t * throwaway_frame[3]; - uint8_t * pp_frame[3]; // postprocess - //uint8_t * throwaway_frame; - - int pp_options; // postprocess + struct vo_frame_s * current_frame; + struct vo_frame_s * forward_reference_frame; + struct vo_frame_s * backward_reference_frame; int second_field; - // MPEG1 - testing - uint8_t mpeg1; + int mpeg1; - //these things are not needed by the decoder - //NOTICE : this is a temporary interface, we will build a better one later. + /* these things are not needed by the decoder */ + /* this is a temporary interface, we will build a better one later. */ int aspect_ratio_information; int frame_rate_code; int progressive_sequence; - int top_field_first; // this one is actually used for DMV MC int repeat_first_field; int progressive_frame; - // added by A'rpi/ESP-team: - int repeat_count; int bitrate; - int frame_rate; + + // added by A'rpi/ESP-team int display_picture_width; int display_picture_height; + int pp_options; + int repeat_count; } picture_t; -typedef struct motion_s { - uint8_t * ref[2][3]; - int pmv[2][2]; - int f_code[2]; -} motion_t; - -// state that is carried from one macroblock to the next inside of a same slice -typedef struct slice_s { - // bit parsing stuff - uint32_t bitstream_buf; // current 32 bit working set of buffer - int bitstream_bits; // used bits in working set - uint8_t * bitstream_ptr; // buffer with stream data - - //Motion vectors - //The f_ and b_ correspond to the forward and backward motion - //predictors - motion_t b_motion; - motion_t f_motion; - - // predictor for DC coefficients in intra blocks - int16_t dc_dct_pred[3]; - - uint16_t quantizer_scale; // remove -} slice_t; - typedef struct mpeg2_config_s { - //Bit flags that enable various things + /* Bit flags that enable various things */ uint32_t flags; } mpeg2_config_t; -//The only global variable, -//the config struct +/* The only global variable, */ +/* the config struct */ extern mpeg2_config_t config; -// slice.c +/* 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); -// idct.c +/* idct.c */ void idct_init (void); -// idct_mlib.c +/* 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); -// idct_mmx.c +/* 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); -// motion_comp.c +/* motion_comp.c */ void motion_comp_init (void); typedef struct mc_functions_s @@ -208,13 +204,8 @@ extern mc_functions_t mc_functions_mmxext; extern mc_functions_t mc_functions_3dnow; extern mc_functions_t mc_functions_mlib; -// slice.c +/* slice.c */ int slice_process (picture_t *picture, uint8_t code, uint8_t * buffer); -// stats.c +/* stats.c */ void stats_header (uint8_t code, uint8_t * buffer); - -#define MBC 45 -#define MBR 36 -extern int quant_store[MBR+1][MBC+1]; // [Review] - diff --git a/libmpeg2/slice.c b/libmpeg2/slice.c index 13940b3387..5c235d86ca 100644 --- a/libmpeg2/slice.c +++ b/libmpeg2/slice.c @@ -1,6 +1,6 @@ /* * slice.c - * Copyright (C) 1999-2000 Aaron Holtzman + * Copyright (C) 1999-2001 Aaron Holtzman * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -24,6 +24,7 @@ #include #include +#include "video_out.h" #include "mpeg2_internal.h" #include "attributes.h" @@ -31,8 +32,6 @@ 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); -static int16_t DCTblock[64] ATTR_ALIGN(16); - #include "vlc.h" static int non_linear_quantizer_scale [] = { @@ -42,24 +41,23 @@ static int non_linear_quantizer_scale [] = { 56, 64, 72, 80, 88, 96, 104, 112 }; -static inline int get_macroblock_modes (slice_t * slice, int picture_structure, - int picture_coding_type, - int frame_pred_frame_dct) +static inline int get_macroblock_modes (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int macroblock_modes; MBtab * tab; - switch (picture_coding_type) { + switch (picture->picture_coding_type) { case I_TYPE: tab = MB_I + UBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if ((! frame_pred_frame_dct) && (picture_structure == FRAME_PICTURE)) { + if ((! (picture->frame_pred_frame_dct)) && + (picture->picture_structure == FRAME_PICTURE)) { macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; DUMPBITS (bit_buf, bits, 1); } @@ -72,13 +70,13 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if (picture_structure != FRAME_PICTURE) { + if (picture->picture_structure != FRAME_PICTURE) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; - } else if (frame_pred_frame_dct) { + } else if (picture->frame_pred_frame_dct) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) macroblock_modes |= MC_FRAME; return macroblock_modes; @@ -100,14 +98,14 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if (picture_structure != FRAME_PICTURE) { + if (picture->picture_structure != FRAME_PICTURE) { if (! (macroblock_modes & MACROBLOCK_INTRA)) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; - } else if (frame_pred_frame_dct) { - //if (! (macroblock_modes & MACROBLOCK_INTRA)) + } else if (picture->frame_pred_frame_dct) { + /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ macroblock_modes |= MC_FRAME; return macroblock_modes; } else { @@ -136,18 +134,18 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, #undef bit_ptr } -static inline int get_quantizer_scale (slice_t * slice, int q_scale_type) +static inline int get_quantizer_scale (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int quantizer_scale_code; quantizer_scale_code = UBITS (bit_buf, 5); DUMPBITS (bit_buf, bits, 5); - if (q_scale_type) + if (picture->q_scale_type) return non_linear_quantizer_scale [quantizer_scale_code]; else return quantizer_scale_code << 1; @@ -156,11 +154,11 @@ static inline int get_quantizer_scale (slice_t * slice, int q_scale_type) #undef bit_ptr } -static inline int get_motion_delta (slice_t * slice, int f_code) +static inline int get_motion_delta (picture_t * picture, int f_code) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int delta; int sign; @@ -226,11 +224,11 @@ static inline int bound_motion_vector (int vector, int f_code) #endif } -static inline int get_dmv (slice_t * slice) +static inline int get_dmv (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DMVtab * tab; @@ -242,11 +240,11 @@ static inline int get_dmv (slice_t * slice) #undef bit_ptr } -static inline int get_coded_block_pattern (slice_t * slice) +static inline int get_coded_block_pattern (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) CBPtab * tab; @@ -270,11 +268,11 @@ static inline int get_coded_block_pattern (slice_t * slice) #undef bit_ptr } -static inline int get_luma_dc_dct_diff (slice_t * slice) +static inline int get_luma_dc_dct_diff (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DCtab * tab; int size; int dc_diff; @@ -307,11 +305,11 @@ static inline int get_luma_dc_dct_diff (slice_t * slice) #undef bit_ptr } -static inline int get_chroma_dc_dct_diff (slice_t * slice) +static inline int get_chroma_dc_dct_diff (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DCtab * tab; int size; int dc_diff; @@ -344,35 +342,34 @@ static inline int get_chroma_dc_dct_diff (slice_t * slice) #undef bit_ptr } -#define SATURATE(val) \ -do { \ - if (val > 2047) \ - val = 2047; \ - else if (val < -2048) \ - val = -2048; \ +#define SATURATE(val) \ +do { \ + if ((uint32_t)(val + 2048) > 4095) \ + val = (val > 0) ? 2047 : -2048; \ } while (0) -static void get_intra_block_B14 (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_intra_block_B14 (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; + dest = picture->DCTblock; i = 0; mismatch = ~dest[0]; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -383,7 +380,7 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -391,7 +388,7 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -411,11 +408,11 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -456,36 +453,37 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_intra_block_B15 (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_intra_block_B15 (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; + dest = picture->DCTblock; i = 0; mismatch = ~dest[0]; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -503,7 +501,7 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -517,16 +515,16 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, } else { - // end of block. I commented out this code because if we - // dont exit here we will still exit at the later test :) + /* end of block. I commented out this code because if we */ + /* dont exit here we will still exit at the later test :) */ - //if (i >= 128) break; // end of block + /* if (i >= 128) break; */ /* end of block */ - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check against buffer overflow + break; /* illegal, check against buffer overflow */ j = scan[i]; @@ -568,36 +566,37 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 4); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_non_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_non_intra_block (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->non_intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = -1; mismatch = 1; + dest = picture->DCTblock; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); if (bit_buf >= 0x28000000) { @@ -614,7 +613,7 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, entry_1: i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -622,7 +621,7 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -645,11 +644,11 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -690,34 +689,35 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_mpeg1_intra_block (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = 0; + dest = picture->DCTblock; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -728,7 +728,7 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -736,10 +736,10 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice