# HG changeset patch # User arpi_esp # Date 983739714 0 # Node ID 846535ace7a270df5122aab62030bb7512245c09 # Parent 25f148e9890af42d82f6efb643a7b3e1378460f4 libmpeg2-0.2.0 merge diff -r 25f148e9890a -r 846535ace7a2 DOCS/ChangeLog --- a/DOCS/ChangeLog Sun Mar 04 14:12:58 2001 +0000 +++ b/DOCS/ChangeLog Sun Mar 04 21:01:54 2001 +0000 @@ -12,7 +12,10 @@ *** 0.11 release is coming SOON!!! *** -v0.11-CVS: yeah, we moved to SourceForge CVS! +v0.11-pre26-CVS: + - updated libmpeg2 source to libmpeg2-0.2.0 version + +v0.11-pre25: yeah, we moved to SourceForge CVS! - DOCS updated (email address changed from arpi@* -> maillist) - LIRC fix, mplayer_lirc changed back to mplayer [Andreas Ackermann] - stream.c: unsigned int fixes, required for some strange .asf files diff -r 25f148e9890a -r 846535ace7a2 codecctrl.c --- a/codecctrl.c Sun Mar 04 14:12:58 2001 +0000 +++ b/codecctrl.c Sun Mar 04 21:01:54 2001 +0000 @@ -91,6 +91,12 @@ // fflush(control_fifo); } +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 +}; + + void mpeg_codec_controller(vo_functions_t *video_out){ //================== CODEC Controller: ========================== signal(SIGTERM,codec_ctrl_sighandler); // set our SIGTERM handler @@ -145,8 +151,9 @@ mpeg2_decode_data(video_out, videobuffer, videobuffer+len); t+=GetTimer(); send_cmd(control_fifo2,0); // FRAME_COMPLETED command - send_cmd(control_fifo2,picture->frame_rate); // fps + send_cmd(control_fifo2,frameratecode2framerate[picture->frame_rate_code]); // fps send_cmd(control_fifo2,100+picture->repeat_count);picture->repeat_count=0; +// send_cmd(control_fifo2,100); // FIXME! send_cmd(control_fifo2,t);t=0; } video_out->uninit(); diff -r 25f148e9890a -r 846535ace7a2 libmpeg2/Makefile --- a/libmpeg2/Makefile Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/Makefile Sun Mar 04 21:01:54 2001 +0000 @@ -3,8 +3,8 @@ 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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/attributes.h --- a/libmpeg2/attributes.h Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/attributes.h Sun Mar 04 21:01:54 2001 +0000 @@ -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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/decode.c --- a/libmpeg2/decode.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/decode.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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; + 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]; - 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; - +#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) { +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; - //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]; + stride[0]=picture->coded_picture_width; + stride[1]=stride[2]=stride[0]/2; - //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]; + output->draw_slice (src, stride, + picture->display_picture_width, + (y+16<=picture->display_picture_height) ? 16 : + picture->display_picture_height-y, + 0, y); - 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]; - - } 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 @@ 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 @@ 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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/header.c --- a/libmpeg2/header.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/header.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ 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_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 @@ 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 - - v_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; + return 1; /* missing marker_bit */ - picture->display_picture_width = (v_size >> 12); - picture->display_picture_height = (v_size & 0xfff); + height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; - h_size = ((v_size >> 12) + 15) & ~15; - v_size = ((v_size & 0xfff) + 15) & ~15; + picture->display_picture_width = (height >> 12); + picture->display_picture_height = (height & 0xfff); - if ((h_size > 768) || (v_size > 576)) - return 1; // size restrictions for MP@ML or MPEG1 + width = ((height >> 12) + 15) & ~15; + height = ((height & 0xfff) + 15) & ~15; - //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; + if ((width > 768) || (height > 576)) + return 1; /* size restrictions for MP@ML or MPEG1 */ - // this is not used by the decoder + picture->coded_picture_width = width; + picture->coded_picture_height = height; + + /* 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 @@ 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 @@ 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_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 @@ 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 @@ 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 @@ { 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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/idct.c --- a/libmpeg2/idct.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/idct.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/idct_mlib.c --- a/libmpeg2/idct_mlib.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/idct_mlib.c Sun Mar 04 21:01:54 2001 +0000 @@ -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_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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/idct_mmx.c --- a/libmpeg2/idct_mmx.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/idct_mmx.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ #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 @@ 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 @@ } -// 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 @@ 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 @@ // 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 @@ 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 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/mmx.h --- a/libmpeg2/mmx.h Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/mmx.h Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ #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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/motion_comp.c --- a/libmpeg2/motion_comp.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/motion_comp.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ #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 @@ } while (--height); \ } -// definitions of the actual mc functions +/* definitions of the actual mc functions */ MC_FUNC (put,) MC_FUNC (avg,) diff -r 25f148e9890a -r 846535ace7a2 libmpeg2/motion_comp_mlib.c --- a/libmpeg2/motion_comp_mlib.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/motion_comp_mlib.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/motion_comp_mmx.c --- a/libmpeg2/motion_comp_mmx.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/motion_comp_mmx.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 @@ 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_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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ -//CPU_MMXEXT/CPU_3DNOW adaptation layer +/* CPU_MMXEXT/CPU_3DNOW adaptation layer */ #define pavg_r2r(src,dest) \ do { \ @@ -545,7 +537,7 @@ } while (0) -//CPU_MMXEXT code +/* CPU_MMXEXT code */ static inline void MC_put1_8 (int height, uint8_t * dest, uint8_t * ref, diff -r 25f148e9890a -r 846535ace7a2 libmpeg2/mpeg2.h --- a/libmpeg2/mpeg2.h Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/mpeg2.h Sun Mar 04 21:01:54 2001 +0000 @@ -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, - * + * 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 +/* 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; -#include -#ifdef __OMS__ -#include -#else -#include "mm_accel.h" -#endif + /* 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; -//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 + /* ONLY for 0.2.0 release - will not stay there later */ + int frame_rate_code; +} mpeg2dec_t ; -//typedef struct mpeg2_config_s { -// //Bit flags that enable various things -// uint32_t flags; -//} mpeg2_config_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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/mpeg2_internal.h --- a/libmpeg2/mpeg2_internal.h Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/mpeg2_internal.h Sun Mar 04 21:01:54 2001 +0000 @@ -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 picture_s { - //-- 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 - int coded_picture_width; - int coded_picture_height; - - //-- picture header stuff -- - - //what type of picture this is (I,P,or B) D from MPEG-1 isn't supported - int picture_coding_type; - - //-- picture coding extension stuff -- - - //quantization factor for motion vectors - int f_code[2][2]; - //quantization factor for intra dc coefficients - int intra_dc_precision; - //top/bottom/both fields - int picture_structure; - //bool to indicate all predictions are frame based - int frame_pred_frame_dct; - //bool to indicate whether intra blocks have motion vectors - // (for concealment) - int concealment_motion_vectors; - //bit to indicate which quantization table to use - int q_scale_type; - //bool to use different vlc tables - int intra_vlc_format; - - //last macroblock in the picture - int last_mba; - //width of picture in macroblocks - int mb_width; - - //stuff derived from bitstream - - //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 - - int second_field; - - // MPEG1 - testing - uint8_t mpeg1; - - //these things are not needed by the decoder - //NOTICE : 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; - int display_picture_width; - int display_picture_height; -} 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 +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; - //Motion vectors - //The f_ and b_ correspond to the forward and backward motion - //predictors +typedef struct picture_s { + /* first, state that carries information from one macroblock to the */ + /* next inside a slice, and is never used outside of slice_process() */ + + /* 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 + /* predictor for DC coefficients in intra blocks */ int16_t dc_dct_pred[3]; - uint16_t quantizer_scale; // remove -} slice_t; + 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 */ + int coded_picture_width; + int coded_picture_height; + + /* picture header stuff */ + + /* what type of picture this is (I, P, B, D) */ + int picture_coding_type; + + /* picture coding extension stuff */ + + /* quantization factor for motion vectors */ + int f_code[2][2]; + /* quantization factor for intra dc coefficients */ + int intra_dc_precision; + /* top/bottom/both fields */ + int picture_structure; + /* bool to indicate all predictions are frame based */ + int frame_pred_frame_dct; + /* bool to indicate whether intra blocks have motion vectors */ + /* (for concealment) */ + int concealment_motion_vectors; + /* bit to indicate which quantization table to use */ + int q_scale_type; + /* bool to use different vlc tables */ + int intra_vlc_format; + /* used for DMV MC */ + int top_field_first; + + /* stuff derived from bitstream */ + + /* pointer to the zigzag scan we're supposed to be using */ + uint8_t * scan; + + struct vo_frame_s * current_frame; + struct vo_frame_s * forward_reference_frame; + struct vo_frame_s * backward_reference_frame; + + int second_field; + + int mpeg1; + + /* 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 repeat_first_field; + int progressive_frame; + int bitrate; + + // added by A'rpi/ESP-team + int display_picture_width; + int display_picture_height; + int pp_options; + int repeat_count; +} picture_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_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 -r 25f148e9890a -r 846535ace7a2 libmpeg2/slice.c --- a/libmpeg2/slice.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/slice.c Sun Mar 04 21:01:54 2001 +0000 @@ -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 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ #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 @@ #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 @@ #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 @@ #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 @@ #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 @@ #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 @@ i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -391,7 +388,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -736,10 +736,10 @@ bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // oddification + /* oddification */ val = (val - 1) | 1; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -758,11 +758,11 @@ 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]; @@ -775,7 +775,7 @@ } val = (val * quantizer_scale * quant_matrix[j]) / 16; - // oddification + /* oddification */ val = (val + ~SBITS (val, 1)) | 1; SATURATE (val); @@ -809,33 +809,34 @@ if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } - 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_non_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_mpeg1_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; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = -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) { @@ -852,7 +853,7 @@ entry_1: i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -860,10 +861,10 @@ bits += tab->len + 1; val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; - // oddification + /* oddification */ val = (val - 1) | 1; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -885,11 +886,11 @@ 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]; @@ -903,7 +904,7 @@ val = 2 * (val + SBITS (val, 1)) + 1; val = (val * quantizer_scale * quant_matrix[j]) / 32; - // oddification + /* oddification */ val = (val + ~SBITS (val, 1)) | 1; SATURATE (val); @@ -937,19 +938,19 @@ if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } - 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 inline int get_macroblock_address_increment (slice_t * slice) +static inline int get_macroblock_address_increment (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) MBAtab * tab; int mba; @@ -966,14 +967,14 @@ DUMPBITS (bit_buf, bits, tab->len); return mba + tab->mba; } else switch (UBITS (bit_buf, 11)) { - case 8: // macroblock_escape + case 8: /* macroblock_escape */ mba += 33; - // no break here on purpose - case 15: // macroblock_stuffing (MPEG1 only) + /* no break here on purpose */ + case 15: /* macroblock_stuffing (MPEG1 only) */ DUMPBITS (bit_buf, bits, 11); NEEDBITS (bit_buf, bits, bit_ptr); break; - default: // end of slice, or error + default: /* end of slice, or error */ return 0; } } @@ -983,43 +984,44 @@ #undef bit_ptr } -static inline void slice_intra_DCT (picture_t * picture, slice_t * slice, - int cc, uint8_t * dest, int stride) +static inline void slice_intra_DCT (picture_t * picture, int cc, + uint8_t * dest, int stride) { -#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) NEEDBITS (bit_buf, bits, bit_ptr); - //Get the intra DC coefficient and inverse quantize it + /* Get the intra DC coefficient and inverse quantize it */ if (cc == 0) - slice->dc_dct_pred[0] += get_luma_dc_dct_diff (slice); + picture->dc_dct_pred[0] += get_luma_dc_dct_diff (picture); else - slice->dc_dct_pred[cc] += get_chroma_dc_dct_diff (slice); - DCTblock[0] = slice->dc_dct_pred[cc] << (3 - picture->intra_dc_precision); + picture->dc_dct_pred[cc] += get_chroma_dc_dct_diff (picture); + picture->DCTblock[0] = + picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision); + memset (picture->DCTblock + 1, 0, 63 * sizeof (int16_t)); if (picture->mpeg1) { if (picture->picture_coding_type != D_TYPE) - get_mpeg1_intra_block (picture, slice, DCTblock); + get_mpeg1_intra_block (picture); } else if (picture->intra_vlc_format) - get_intra_block_B15 (picture, slice, DCTblock); + get_intra_block_B15 (picture); else - get_intra_block_B14 (picture, slice, DCTblock); - idct_block_copy (DCTblock, dest, stride); - memset (DCTblock, 0, sizeof (DCTblock)); + get_intra_block_B14 (picture); + idct_block_copy (picture->DCTblock, dest, stride); #undef bit_buf #undef bits #undef bit_ptr } -static inline void slice_non_intra_DCT (picture_t * picture, slice_t * slice, - uint8_t * dest, int stride) +static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest, + int stride) { + memset (picture->DCTblock, 0, 64 * sizeof (int16_t)); if (picture->mpeg1) - get_mpeg1_non_intra_block (picture, slice, DCTblock); + get_mpeg1_non_intra_block (picture); else - get_non_intra_block (picture, slice, DCTblock); - idct_block_add (DCTblock, dest, stride); - memset (DCTblock, 0, sizeof (DCTblock)); + get_non_intra_block (picture); + idct_block_add (picture->DCTblock, dest, stride); } static inline void motion_block (void (** table) (uint8_t *, uint8_t *, @@ -1058,22 +1060,24 @@ } -static void motion_mp1 (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_mp1 (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[0]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[0]); motion_y = bound_motion_vector (motion_y, motion->f_code[0]); motion->pmv[0][1] = motion_y; @@ -1083,14 +1087,14 @@ } motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_mp1_reuse (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_mp1_reuse (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { int motion_x, motion_y; @@ -1104,42 +1108,44 @@ } motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); } -static void motion_fr_frame (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_frame (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion->pmv[0][1] = motion_y; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_fr_field (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_field (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; int field_select; @@ -1147,143 +1153,147 @@ field_select = SBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, 1); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[0][1] = motion_y << 1; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset + (field_select & width), - width * 2, 8, 0); + motion->ref[0], offset + (field_select & stride), + stride * 2, 8, 0); NEEDBITS (bit_buf, bits, bit_ptr); field_select = SBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, 1); - motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[1][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[1][1] = motion_y << 1; - motion_block (table, motion_x, motion_y, dest, offset + width, - motion->ref[0], offset + (field_select & width), - width * 2, 8, 0); + motion_block (table, motion_x, motion_y, dest, offset + stride, + motion->ref[0], offset + (field_select & stride), + stride * 2, 8, 0); #undef bit_buf #undef bits #undef bit_ptr } -static int motion_dmv_top_field_first; -static void motion_fr_dmv (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_dmv (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; int dmv_x, dmv_y; int m; int other_x, other_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_x = get_dmv (slice); + dmv_x = get_dmv (picture); NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_y = get_dmv (slice); + dmv_y = get_dmv (picture); motion_block (mc_functions.put, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width * 2, 8, 0); + motion->ref[0], offset, stride * 2, 8, 0); - m = motion_dmv_top_field_first ? 1 : 3; + m = picture->top_field_first ? 1 : 3; other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; motion_block (mc_functions.avg, other_x, other_y, dest, offset, - motion->ref[0], offset + width, width * 2, 8, 0); + motion->ref[0], offset + stride, stride * 2, 8, 0); - motion_block (mc_functions.put, motion_x, motion_y, dest, offset + width, - motion->ref[0], offset + width, width * 2, 8, 0); + motion_block (mc_functions.put, motion_x, motion_y, dest, offset + stride, + motion->ref[0], offset + stride, stride * 2, 8, 0); - m = motion_dmv_top_field_first ? 3 : 1; + m = picture->top_field_first ? 3 : 1; other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; - motion_block (mc_functions.avg, other_x, other_y, dest, offset + width, - motion->ref[0], offset, width * 2, 8, 0); + motion_block (mc_functions.avg, other_x, other_y, dest, offset + stride, + motion->ref[0], offset, stride * 2, 8, 0); #undef bit_buf #undef bits #undef bit_ptr } -// like motion_frame, but reuse previous motion vectors -static void motion_fr_reuse (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +/* like motion_frame, but reuse previous motion vectors */ +static void motion_fr_reuse (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); } -// like motion_frame, but use null motion vectors -static void motion_fr_zero (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +/* like motion_frame, but use null motion vectors */ +static void motion_fr_zero (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { motion_block (table, 0, 0, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); } -// like motion_frame, but parsing without actual motion compensation -static void motion_fr_conceal (slice_t * slice, motion_t * motion) +/* like motion_frame, but parsing without actual motion compensation */ +static void motion_fr_conceal (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 tmp; NEEDBITS (bit_buf, bits, bit_ptr); - tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); - tmp = bound_motion_vector (tmp, motion->f_code[0]); - motion->pmv[1][0] = motion->pmv[0][0] = tmp; + tmp = (picture->f_motion.pmv[0][0] + + get_motion_delta (picture, picture->f_motion.f_code[0])); + tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]); + picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp; NEEDBITS (bit_buf, bits, bit_ptr); - tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); - tmp = bound_motion_vector (tmp, motion->f_code[1]); - motion->pmv[1][1] = motion->pmv[0][1] = tmp; + tmp = (picture->f_motion.pmv[0][1] + + get_motion_delta (picture, picture->f_motion.f_code[1])); + tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]); + picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp; - DUMPBITS (bit_buf, bits, 1); // remove marker_bit + DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ #undef bit_buf #undef bits #undef bit_ptr } -static void motion_fi_field (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fi_field (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; int field_select; @@ -1292,29 +1302,31 @@ DUMPBITS (bit_buf, bits, 1); NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion->pmv[0][1] = motion_y; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[field_select], offset, width, 16, 0); + motion->ref[field_select], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_fi_16x8 (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fi_16x8 (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; int field_select; @@ -1323,230 +1335,246 @@ DUMPBITS (bit_buf, bits, 1); NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[0][1] = motion_y; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[field_select], offset, width, 8, 0); + motion->ref[field_select], offset, stride, 8, 0); NEEDBITS (bit_buf, bits, bit_ptr); field_select = UBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, 1); NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[1][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[1][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[1][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion_y; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[field_select], offset, width, 8, 1); + motion->ref[field_select], offset, stride, 8, 1); #undef bit_buf #undef bits #undef bit_ptr } -static int current_field = 0; -static void motion_fi_dmv (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fi_dmv (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (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 motion_x, motion_y; int dmv_x, dmv_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_x = get_dmv (slice); + dmv_x = get_dmv (picture); NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion->pmv[0][1] = motion_y; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_y = get_dmv (slice); + dmv_y = get_dmv (picture); motion_block (mc_functions.put, motion_x, motion_y, dest, offset, - motion->ref[current_field], offset, width, 16, 0); + motion->ref[picture->current_field], offset, stride, 16, 0); motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x; motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y + - 2 * current_field - 1; + 2 * picture->current_field - 1; motion_block (mc_functions.avg, motion_x, motion_y, dest, offset, - motion->ref[!current_field], offset, width, 16, 0); + motion->ref[!picture->current_field], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_fi_reuse (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fi_reuse (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, - motion->ref[current_field], offset, width, 16, 0); + motion->ref[picture->current_field], offset, stride, 16, 0); } -static void motion_fi_zero (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fi_zero (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { motion_block (table, 0, 0, dest, offset, - motion->ref[current_field], offset, width, 16, 0); + motion->ref[picture->current_field], offset, stride, 16, 0); } -static void motion_fi_conceal (slice_t * slice, motion_t * motion) +static void motion_fi_conceal (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 tmp; NEEDBITS (bit_buf, bits, bit_ptr); - DUMPBITS (bit_buf, bits, 1); // remove field_select + DUMPBITS (bit_buf, bits, 1); /* remove field_select */ NEEDBITS (bit_buf, bits, bit_ptr); - tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); - tmp = bound_motion_vector (tmp, motion->f_code[0]); - motion->pmv[1][0] = motion->pmv[0][0] = tmp; + tmp = (picture->f_motion.pmv[0][0] + + get_motion_delta (picture, picture->f_motion.f_code[0])); + tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]); + picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp; NEEDBITS (bit_buf, bits, bit_ptr); - tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); - tmp = bound_motion_vector (tmp, motion->f_code[1]); - motion->pmv[1][1] = motion->pmv[0][1] = tmp; + tmp = (picture->f_motion.pmv[0][1] + + get_motion_delta (picture, picture->f_motion.f_code[1])); + tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]); + picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp; - DUMPBITS (bit_buf, bits, 1); // remove marker_bit + DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ #undef bit_buf #undef bits #undef bit_ptr } -#define MOTION(routine,direction,slice,dest,offset,stride) \ +#define MOTION(routine,direction) \ do { \ if ((direction) & MACROBLOCK_MOTION_FORWARD) \ - routine (&slice, &((slice).f_motion), dest, offset, stride, \ + routine (picture, &(picture->f_motion), dest, offset, stride, \ mc_functions.put); \ if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ - routine (&slice, &((slice).b_motion), dest, offset, stride, \ + routine (picture, &(picture->b_motion), dest, offset, stride, \ ((direction) & MACROBLOCK_MOTION_FORWARD ? \ mc_functions.avg : mc_functions.put)); \ } while (0) -#define CHECK_DISPLAY \ -do { \ - if (offset == width) { \ - slice.f_motion.ref[0][0] += 16 * offset; \ - slice.f_motion.ref[0][1] += 4 * offset; \ - slice.f_motion.ref[0][2] += 4 * offset; \ - slice.b_motion.ref[0][0] += 16 * offset; \ - slice.b_motion.ref[0][1] += 4 * offset; \ - slice.b_motion.ref[0][2] += 4 * offset; \ - dest[0] += 16 * offset; \ - dest[1] += 4 * offset; \ - dest[2] += 4 * offset; \ - offset = 0; ++ypos; \ - } \ +#define CHECK_DISPLAY \ +do { \ + if (offset == picture->coded_picture_width) { \ + picture->f_motion.ref[0][0] += 16 * stride; \ + picture->f_motion.ref[0][1] += 4 * stride; \ + picture->f_motion.ref[0][2] += 4 * stride; \ + picture->b_motion.ref[0][0] += 16 * stride; \ + picture->b_motion.ref[0][1] += 4 * stride; \ + picture->b_motion.ref[0][2] += 4 * stride; \ + do { /* just so we can use the break statement */ \ + if (picture->current_frame->copy) { \ + picture->current_frame->copy (picture->current_frame, \ + dest); \ + if (picture->picture_coding_type == B_TYPE) \ + break; \ + } \ + dest[0] += 16 * stride; \ + dest[1] += 4 * stride; \ + dest[2] += 4 * stride; \ + } while (0); \ + offset = 0; \ + } \ } while (0) int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer) { -#define bit_buf (slice.bitstream_buf) -#define bits (slice.bitstream_bits) -#define bit_ptr (slice.bitstream_ptr) - slice_t slice; +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int macroblock_modes; - int width; - int ypos=code-1; + int stride; uint8_t * dest[3]; int offset; uint8_t ** forward_ref[2]; - width = picture->coded_picture_width; - offset = ypos * width * 4; + stride = picture->coded_picture_width; + offset = (code - 1) * stride * 4; - forward_ref[0] = picture->forward_reference_frame; + forward_ref[0] = picture->forward_reference_frame->base; if (picture->picture_structure != FRAME_PICTURE) { offset <<= 1; - forward_ref[1] = picture->forward_reference_frame; - current_field = (picture->picture_structure == BOTTOM_FIELD); + forward_ref[1] = picture->forward_reference_frame->base; + picture->current_field = (picture->picture_structure == BOTTOM_FIELD); if ((picture->second_field) && (picture->picture_coding_type != B_TYPE)) forward_ref[picture->picture_structure == TOP_FIELD] = - picture->current_frame; - slice.f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + width; - slice.f_motion.ref[1][1] = forward_ref[1][1] + offset + (width >> 1); - slice.f_motion.ref[1][2] = forward_ref[1][2] + offset + (width >> 1); - slice.b_motion.ref[1][0] = - picture->backward_reference_frame[0] + offset * 4 + width; - slice.b_motion.ref[1][1] = - picture->backward_reference_frame[1] + offset + (width >> 1); - slice.b_motion.ref[1][2] = - picture->backward_reference_frame[2] + offset + (width >> 1); + picture->current_frame->base; + picture->f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + stride; + picture->f_motion.ref[1][1] = + forward_ref[1][1] + offset + (stride >> 1); + picture->f_motion.ref[1][2] = + forward_ref[1][2] + offset + (stride >> 1); + picture->b_motion.ref[1][0] = + picture->backward_reference_frame->base[0] + offset * 4 + stride; + picture->b_motion.ref[1][1] = + (picture->backward_reference_frame->base[1] + + offset + (stride >> 1)); + picture->b_motion.ref[1][2] = + (picture->backward_reference_frame->base[2] + + offset + (stride >> 1)); } - slice.f_motion.ref[0][0] = forward_ref[0][0] + offset * 4; - slice.f_motion.ref[0][1] = forward_ref[0][1] + offset; - slice.f_motion.ref[0][2] = forward_ref[0][2] + offset; - slice.f_motion.f_code[0] = picture->f_code[0][0]; - slice.f_motion.f_code[1] = picture->f_code[0][1]; - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; - slice.b_motion.ref[0][0] = - picture->backward_reference_frame[0] + offset * 4; - slice.b_motion.ref[0][1] = - picture->backward_reference_frame[1] + offset; - slice.b_motion.ref[0][2] = - picture->backward_reference_frame[2] + offset; - slice.b_motion.f_code[0] = picture->f_code[1][0]; - slice.b_motion.f_code[1] = picture->f_code[1][1]; - slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0; - slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0; + picture->f_motion.ref[0][0] = forward_ref[0][0] + offset * 4; + picture->f_motion.ref[0][1] = forward_ref[0][1] + offset; + picture->f_motion.ref[0][2] = forward_ref[0][2] + offset; + picture->f_motion.f_code[0] = picture->f_code[0][0]; + picture->f_motion.f_code[1] = picture->f_code[0][1]; + picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0; + picture->b_motion.ref[0][0] = + picture->backward_reference_frame->base[0] + offset * 4; + picture->b_motion.ref[0][1] = + picture->backward_reference_frame->base[1] + offset; + picture->b_motion.ref[0][2] = + picture->backward_reference_frame->base[2] + offset; + picture->b_motion.f_code[0] = picture->f_code[1][0]; + picture->b_motion.f_code[1] = picture->f_code[1][1]; + picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0; + picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0; - if ((! HACK_MODE) && (!picture->mpeg1) && + if ((picture->current_frame->copy) && (picture->picture_coding_type == B_TYPE)) offset = 0; - dest[0] = picture->current_frame[0] + offset * 4; - dest[1] = picture->current_frame[1] + offset; - dest[2] = picture->current_frame[2] + offset; + dest[0] = picture->current_frame->base[0] + offset * 4; + dest[1] = picture->current_frame->base[1] + offset; + dest[2] = picture->current_frame->base[2] + offset; switch (picture->picture_structure) { case BOTTOM_FIELD: - dest[0] += width; - dest[1] += width >> 1; - dest[2] += width >> 1; - // follow thru + dest[0] += stride; + dest[1] += stride >> 1; + dest[2] += stride >> 1; + /* follow thru */ case TOP_FIELD: - width <<= 1; + stride <<= 1; } - //reset intra dc predictor - slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= - 1<< (picture->intra_dc_precision + 7) ; + /* reset intra dc predictor */ + picture->dc_dct_pred[0] = picture->dc_dct_pred[1] = + picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7); - bitstream_init (&slice, buffer); + bitstream_init (picture, buffer); - slice.quantizer_scale = get_quantizer_scale (&slice, - picture->q_scale_type); + picture->quantizer_scale = get_quantizer_scale (picture); - //Ignore intra_slice and all the extra data + /* ignore intra_slice and all the extra data */ while (bit_buf & 0x80000000) { DUMPBITS (bit_buf, bits, 9); NEEDBITS (bit_buf, bits, bit_ptr); @@ -1554,20 +1582,16 @@ DUMPBITS (bit_buf, bits, 1); NEEDBITS (bit_buf, bits, bit_ptr); - offset = get_macroblock_address_increment (&slice) << 4; + offset = get_macroblock_address_increment (picture) << 4; while (1) { NEEDBITS (bit_buf, bits, bit_ptr); - macroblock_modes = - get_macroblock_modes (&slice, picture->picture_structure, - picture->picture_coding_type, - picture->frame_pred_frame_dct); + macroblock_modes = get_macroblock_modes (picture); - // maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? + /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */ if (macroblock_modes & MACROBLOCK_QUANT) - slice.quantizer_scale = - get_quantizer_scale (&slice, picture->q_scale_type); + picture->quantizer_scale = get_quantizer_scale (picture); if (macroblock_modes & MACROBLOCK_INTRA) { @@ -1575,39 +1599,35 @@ if (picture->concealment_motion_vectors) { if (picture->picture_structure == FRAME_PICTURE) - motion_fr_conceal (&slice, &slice.f_motion); + motion_fr_conceal (picture); else - motion_fi_conceal (&slice, &slice.f_motion); + motion_fi_conceal (picture); } else { - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; - slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0; - slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0; + picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0; + picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0; + picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0; } if (macroblock_modes & DCT_TYPE_INTERLACED) { - DCT_offset = width; - DCT_stride = width * 2; + DCT_offset = stride; + DCT_stride = stride * 2; } else { - DCT_offset = width * 8; - DCT_stride = width; + DCT_offset = stride * 8; + DCT_stride = stride; } - // Decode lum blocks - slice_intra_DCT (picture, &slice, 0, - dest[0] + offset, DCT_stride); - slice_intra_DCT (picture, &slice, 0, - dest[0] + offset + 8, DCT_stride); - slice_intra_DCT (picture, &slice, 0, - dest[0] + offset + DCT_offset, DCT_stride); - slice_intra_DCT (picture, &slice, 0, - dest[0] + offset + DCT_offset + 8, DCT_stride); + /* Decode lum blocks */ + slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride); + slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride); + slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset, + DCT_stride); + slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8, + DCT_stride); - // Decode chroma blocks - slice_intra_DCT (picture, &slice, 1, - dest[1] + (offset>>1), width>>1); - slice_intra_DCT (picture, &slice, 2, - dest[2] + (offset>>1), width>>1); + /* Decode chroma blocks */ + slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1); + slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1); if (picture->picture_coding_type == D_TYPE) { NEEDBITS (bit_buf, bits, bit_ptr); @@ -1617,121 +1637,108 @@ if (picture->mpeg1) { if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME) - MOTION (motion_mp1, macroblock_modes, slice, - dest, offset,width); + MOTION (motion_mp1, macroblock_modes); else { - // non-intra mb without forward mv in a P picture - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; - - MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice, - dest, offset, width); + /* non-intra mb without forward mv in a P picture */ + picture->f_motion.pmv[0][0] = 0; + picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = 0; + picture->f_motion.pmv[1][1] = 0; + MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD); } } else if (picture->picture_structure == FRAME_PICTURE) switch (macroblock_modes & MOTION_TYPE_MASK) { case MC_FRAME: - MOTION (motion_fr_frame, macroblock_modes, slice, - dest, offset, width); + MOTION (motion_fr_frame, macroblock_modes); break; case MC_FIELD: - MOTION (motion_fr_field, macroblock_modes, slice, - dest, offset, width); + MOTION (motion_fr_field, macroblock_modes); break; case MC_DMV: - motion_dmv_top_field_first = picture->top_field_first; - MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD, slice, - dest, offset, width); + MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD); break; case 0: - // non-intra mb without forward mv in a P picture - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; - - MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice, - dest, offset, width); + /* non-intra mb without forward mv in a P picture */ + picture->f_motion.pmv[0][0] = 0; + picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = 0; + picture->f_motion.pmv[1][1] = 0; + MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD); break; } else switch (macroblock_modes & MOTION_TYPE_MASK) { case MC_FIELD: - MOTION (motion_fi_field, macroblock_modes, slice, - dest, offset, width); + MOTION (motion_fi_field, macroblock_modes); break; case MC_16X8: - MOTION (motion_fi_16x8, macroblock_modes, slice, - dest, offset, width); + MOTION (motion_fi_16x8, macroblock_modes); break; case MC_DMV: - motion_dmv_top_field_first = picture->top_field_first; - MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD, slice, - dest, offset, width); + MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD); break; case 0: - // non-intra mb without forward mv in a P picture - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; - - MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD, slice, - dest, offset, width); + /* non-intra mb without forward mv in a P picture */ + picture->f_motion.pmv[0][0] = 0; + picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = 0; + picture->f_motion.pmv[1][1] = 0; + MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD); break; } - //6.3.17.4 Coded block pattern + /* 6.3.17.4 Coded block pattern */ if (macroblock_modes & MACROBLOCK_PATTERN) { int coded_block_pattern; int DCT_offset, DCT_stride; if (macroblock_modes & DCT_TYPE_INTERLACED) { - DCT_offset = width; - DCT_stride = width * 2; + DCT_offset = stride; + DCT_stride = stride * 2; } else { - DCT_offset = width * 8; - DCT_stride = width; + DCT_offset = stride * 8; + DCT_stride = stride; } - coded_block_pattern = get_coded_block_pattern (&slice); + coded_block_pattern = get_coded_block_pattern (picture); - // Decode lum blocks + /* Decode lum blocks */ if (coded_block_pattern & 0x20) - slice_non_intra_DCT (picture, &slice, - dest[0] + offset, DCT_stride); + slice_non_intra_DCT (picture, dest[0] + offset, + DCT_stride); if (coded_block_pattern & 0x10) - slice_non_intra_DCT (picture, &slice, - dest[0] + offset + 8, DCT_stride); + slice_non_intra_DCT (picture, dest[0] + offset + 8, + DCT_stride); if (coded_block_pattern & 0x08) - slice_non_intra_DCT (picture, &slice, + slice_non_intra_DCT (picture, dest[0] + offset + DCT_offset, DCT_stride); if (coded_block_pattern & 0x04) - slice_non_intra_DCT (picture, &slice, + slice_non_intra_DCT (picture, dest[0] + offset + DCT_offset + 8, DCT_stride); - // Decode chroma blocks + /* Decode chroma blocks */ if (coded_block_pattern & 0x2) - slice_non_intra_DCT (picture, &slice, - dest[1] + (offset>>1), width >> 1); + slice_non_intra_DCT (picture, dest[1] + (offset >> 1), + stride >> 1); if (coded_block_pattern & 0x1) - slice_non_intra_DCT (picture, &slice, - dest[2] + (offset>>1), width >> 1); + slice_non_intra_DCT (picture, dest[2] + (offset >> 1), + stride >> 1); } - slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= - 1 << (picture->intra_dc_precision + 7); + picture->dc_dct_pred[0] = picture->dc_dct_pred[1] = + picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7); } -// printf("[%d]",slice.quantizer_scale); -// printf("[%d,%d]",offset>>4,ypos); - quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale; - offset += 16; CHECK_DISPLAY; @@ -1742,47 +1749,38 @@ } else { int mba_inc; - mba_inc = get_macroblock_address_increment (&slice); + mba_inc = get_macroblock_address_increment (picture); if (!mba_inc) break; - //reset intra dc predictor on skipped block - slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= - 1<< (picture->intra_dc_precision + 7); + /* reset intra dc predictor on skipped block */ + picture->dc_dct_pred[0] = picture->dc_dct_pred[1] = + picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7); - //handling of skipped mb's differs between P_TYPE and B_TYPE - //pictures + /* handling of skipped mb's differs between P_TYPE and B_TYPE */ + /* pictures */ if (picture->picture_coding_type == P_TYPE) { - slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; - slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; + picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0; + picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0; do { if (picture->picture_structure == FRAME_PICTURE) - MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, - slice, dest, offset, width); + MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD); else - MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD, - slice, dest, offset, width); + MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD); - quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale; -// printf("[%d,%d]",offset>>4,ypos); offset += 16; CHECK_DISPLAY; } while (--mba_inc); } else { do { if (picture->mpeg1) - MOTION (motion_mp1_reuse, macroblock_modes, - slice, dest, offset, width); + MOTION (motion_mp1_reuse, macroblock_modes); else if (picture->picture_structure == FRAME_PICTURE) - MOTION (motion_fr_reuse, macroblock_modes, - slice, dest, offset, width); + MOTION (motion_fr_reuse, macroblock_modes); else - MOTION (motion_fi_reuse, macroblock_modes, - slice, dest, offset, width); + MOTION (motion_fi_reuse, macroblock_modes); - quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale; -// printf("[%d,%d]",offset>>4,ypos); offset += 16; CHECK_DISPLAY; } while (--mba_inc); diff -r 25f148e9890a -r 846535ace7a2 libmpeg2/stats.c --- a/libmpeg2/stats.c Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/stats.c Sun Mar 04 21:01:54 2001 +0000 @@ -1,6 +1,6 @@ /* * stats.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. * @@ -29,8 +29,8 @@ static int debug_level = -1; -// Determine is debug output is required. -// We could potentially have multiple levels of debug info +/* Determine is debug output is required. */ +/* We could potentially have multiple levels of debug info */ static int debug_is_on (void) { char * env_var; @@ -152,7 +152,7 @@ static void stats_slice (uint8_t code, uint8_t * buffer) { - //fprintf (stderr, " (slice %d)\n", code); + /* fprintf (stderr, " (slice %d)\n", code); */ } static void stats_sequence_extension (uint8_t * buffer) @@ -274,7 +274,6 @@ stats_sequence_error (buffer); break; case 0xb5: - //stats_extension (buffer); switch (buffer[0] >> 4) { case 1: stats_sequence_extension (buffer); diff -r 25f148e9890a -r 846535ace7a2 libmpeg2/vlc.h --- a/libmpeg2/vlc.h Sun Mar 04 14:12:58 2001 +0000 +++ b/libmpeg2/vlc.h Sun Mar 04 21:01:54 2001 +0000 @@ -1,6 +1,6 @@ /* * vlc.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. * @@ -25,14 +25,14 @@ bit_ptr += 2; \ } while (0) -static inline void bitstream_init (slice_t * slice, uint8_t * start) +static inline void bitstream_init (picture_t * picture, uint8_t * start) { - slice->bitstream_buf = 0; GETWORD (slice->bitstream_buf, 16, start); - slice->bitstream_ptr = start; - slice->bitstream_bits = 0; + picture->bitstream_buf = 0; GETWORD (picture->bitstream_buf, 16, start); + picture->bitstream_ptr = start; + picture->bitstream_bits = 0; } -// make sure that there are at least 16 valid bits in bit_buf +/* make sure that there are at least 16 valid bits in bit_buf */ #define NEEDBITS(bit_buf,bits,bit_ptr) \ do { \ if (bits > 0) { \ @@ -41,17 +41,17 @@ } \ } while (0) -// remove num valid bits from bit_buf +/* remove num valid bits from bit_buf */ #define DUMPBITS(bit_buf,bits,num) \ do { \ bit_buf <<= (num); \ bits += (num); \ } while (0) -// take num bits from the high part of bit_buf and zero extend them +/* take num bits from the high part of bit_buf and zero extend them */ #define UBITS(bit_buf,num) (((uint32_t)(bit_buf)) >> (32 - (num))) -// take num bits from the high part of bit_buf and sign extend them +/* take num bits from the high part of bit_buf and sign extend them */ #define SBITS(bit_buf,num) (((int32_t)(bit_buf)) >> (32 - (num))) typedef struct { diff -r 25f148e9890a -r 846535ace7a2 mplayer.c --- a/mplayer.c Sun Mar 04 14:12:58 2001 +0000 +++ b/mplayer.c Sun Mar 04 21:01:54 2001 +0000 @@ -29,6 +29,8 @@ #include "version.h" #include "config.h" +#include "libvo/video_out.h" + // CODECS: #include "mp3lib/mp3.h" #include "libac3/ac3.h" @@ -37,7 +39,6 @@ #include "loader.h" #include "wine/avifmt.h" -//#include "libvo/x11_common.h" // included from mpeg2.h #include "opendivx/decore.h" @@ -861,7 +862,7 @@ printf ("bad sequence header extension!\n"); return 1; } } - default_fps=picture->frame_rate*0.0001f; + default_fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate); printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", picture->mpeg1?"MPEG1":"MPEG2", @@ -989,6 +990,7 @@ double video_time_usage=0; double vout_time_usage=0; double audio_time_usage=0; +int grab_frames=0; #ifdef HAVE_LIRC lirc_mp_setup(); @@ -1495,11 +1497,17 @@ if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode else if(!i){ eof=1; break;} // EOF } + if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; if(!read_video_packet(d_video)){ eof=1; break;} // EOF //printf("read packet 0x%X, len=%d\n",i,videobuf_len); } if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug //printf("--- SEND %d bytes\n",videobuf_len); + if(grab_frames==1){ + FILE *f=fopen("grab.mpg","ab"); + fwrite(videobuffer,videobuf_len-4,1,f); + fclose(f); + } ++dbg_es_sent; //if(videobuf_len>4) my_write(data_fifo,(char*) &videobuf_len,4); @@ -1671,6 +1679,7 @@ case KEY_ESC: // ESC case KEY_ENTER: // ESC case 'q': exit_player("Quit"); + case 'g': grab_frames=2;break; // restart codec case 'k': kill(codec_pid,SIGKILL);break; // case 'k': kill(child_pid,SIGKILL);break;