Commit 023206d0 authored by Jean-Marc Dressler's avatar Jean-Marc Dressler

Il est 6 heure du matin et le parser ... parse !!!!!!!!
Ca � l'air de pas trop mal marcher. Parmis les bugs les plus sauvages
on trouve :
1) le DumpBits sans NeedBits (corrig� par un RemoveBits)
2) Une table � laquelle il manquait une ligne
3) le test de fin de boucle du d�codage des coef dct �tait mal plac�

Meuh, � toi de jouer

Stef & Polux
parent 8d158ef4
......@@ -164,7 +164,7 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
/******************************************************************************
* NeedBits : reads i_bits new bits in the bit stream and stores them in the
* <F4> bit buffer
* bit buffer
******************************************************************************
* - i_bits must be less or equal 32 !
* - There is something important to notice with that function : if the number
......@@ -214,6 +214,24 @@ static __inline__ void DumpBits32( bit_stream_t * p_bit_stream )
* need to call RealignBits() before).
*/
/******************************************************************************
* RemoveBits : removes i_bits bits from the bit buffer
******************************************************************************/
static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits )
{
NeedBits( p_bit_stream, i_bits );
DumpBits( p_bit_stream, i_bits );
}
/******************************************************************************
* RemoveBits32 : removes 32 bits from the bit buffer
******************************************************************************/
static __inline__ void RemoveBits32( bit_stream_t * p_bit_stream )
{
NeedBits( p_bit_stream, 32 );
DumpBits32( p_bit_stream );
}
/******************************************************************************
* ShowBits : return i_bits bits from the bit stream
******************************************************************************/
......
......@@ -60,7 +60,7 @@ typedef struct vpar_thread_s
/* Lookup tables */
#ifdef MPEG2_COMPLIANT
s16 pi_crop_buf[65536];
s16 pi_crop_buf[8192];
s16 * pi_crop;
#endif
lookup_t pl_mb_addr_inc[2048]; /* for macroblock
......@@ -71,8 +71,6 @@ typedef struct vpar_thread_s
lookup_t * pl_coded_pattern;
/* variable length codes for the structure dct_dc_size for intra blocks */
lookup_t * pppl_dct_dc_size[2][2];
/* structure to store the tables B14 & B15 */
dct_lookup_t * pppl_dct_coef[2][65536];
#ifdef STATS
/* Statistics */
......
......@@ -84,9 +84,9 @@ typedef struct lookup_s
typedef struct dct_lookup_s
{
int i_run;
int i_level;
int i_length;
char i_run;
char i_level;
char i_length;
} dct_lookup_t;
/*****************************************************************************
......
......@@ -43,7 +43,7 @@ typedef struct sequence_s
u32 i_height, i_width, i_size;
u32 i_mb_height, i_mb_width, i_mb_size;
unsigned int i_aspect_ratio;
double d_frame_rate;
float r_frame_rate;
boolean_t b_mpeg2;
boolean_t b_progressive;
unsigned int i_scalable_mode;
......
......@@ -276,7 +276,7 @@ static void DecodeMacroblock( vdec_thread_t *p_vdec, macroblock_t * p_mb )
}
/* chrominance */
for( i_b = 4; i_b < 4 + 2*p_mb->i_chroma_nb_blocks; i_b++ )
for( i_b = 4; i_b < 4 + p_mb->i_chroma_nb_blocks; i_b++ )
{
/*
* Inverse DCT (ISO/IEC 13818-2 section Annex A)
......
......@@ -231,12 +231,12 @@ static int InitThread( vpar_thread_t *p_vpar )
#if defined(MPEG2_COMPLIANT) && !defined(VDEC_DFT)
vpar_InitCrop( p_vpar );
#endif
InitMbAddrInc( p_vpar );
InitDCTTables( p_vpar );
InitPMBType( p_vpar );
InitBMBType( p_vpar );
InitCodedPattern( p_vpar );
InitDCTTables( p_vpar );
vpar_InitMbAddrInc( p_vpar );
vpar_InitDCTTables( p_vpar );
vpar_InitPMBType( p_vpar );
vpar_InitBMBType( p_vpar );
vpar_InitCodedPattern( p_vpar );
vpar_InitDCTTables( p_vpar );
/* Mark thread as running and return */
intf_DbgMsg("vpar debug: InitThread(%p) succeeded\n", p_vpar);
......
......@@ -161,7 +161,14 @@ lookup_t pl_dct_dc_chrom_init_table_2[32] =
{8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
};
/* Tables for ac DCT coefficients. There are cut in many parts to save space */
/*
* Structure to store the tables B14 & B15
* Is constructed from the tables below
*/
dct_lookup_t ppl_dct_coef[2][16384];
/* Tables for ac DCT coefficients. There are cut in many parts to save space */
/* Table B-14, DCT coefficients table zero,
* codes 0100 ... 1xxx (used for first (DC) coefficient)
*/
......@@ -208,6 +215,7 @@ dct_lookup_t pl_DCT_tab0[60] =
/* Table B-15, DCT coefficients table one,
* codes 000001xx ... 11111111
*/
#if 0
dct_lookup_t pl_DCT_tab0a[252] =
{
{DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6},
......@@ -274,6 +282,77 @@ dct_lookup_t pl_DCT_tab0a[252] =
{0,9,7}, {0,9,7}, {0,12,8}, {0,13,8},
{2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
};
#endif
dct_lookup_t pl_DCT_tab0a[252] =
{
{65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */
{7,1,7}, {7,1,7}, {8,1,7}, {8,1,7},
{6,1,7}, {6,1,7}, {2,2,7}, {2,2,7},
{0,7,6}, {0,7,6}, {0,7,6}, {0,7,6},
{0,6,6}, {0,6,6}, {0,6,6}, {0,6,6},
{4,1,6}, {4,1,6}, {4,1,6}, {4,1,6},
{5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
{1,5,8}, {11,1,8}, {0,11,8}, {0,10,8},
{13,1,8}, {12,1,8}, {3,2,8}, {1,4,8},
{2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
{2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
{1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
{1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
{3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
{3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
{64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, /* EOB */
{64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
{64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
{64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
{0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
{0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
{0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
{0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
{0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
{0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
{0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
{0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
{9,1,7}, {9,1,7}, {1,3,7}, {1,3,7},
{10,1,7}, {10,1,7}, {0,8,7}, {0,8,7},
{0,9,7}, {0,9,7}, {0,12,8}, {0,13,8},
{2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
};
/* Table B-14, DCT coefficients table zero,
* codes 0000001000 ... 0000001111
......@@ -360,9 +439,9 @@ void vpar_InitCrop( vpar_thread_t * p_vpar )
{
int i_dummy;
p_vpar->pi_crop = p_vpar->pi_crop_buf + 32768;
p_vpar->pi_crop = p_vpar->pi_crop_buf + 4096;
for( i_dummy = -32768; i_dummy < -2048; i_dummy++ )
for( i_dummy = -4096; i_dummy < -2048; i_dummy++ )
{
p_vpar->pi_crop[i_dummy] = -2048;
}
......@@ -370,7 +449,7 @@ void vpar_InitCrop( vpar_thread_t * p_vpar )
{
p_vpar->pi_crop[i_dummy] = i_dummy;
}
for( ; i_dummy < 32767; i_dummy++ )
for( ; i_dummy < 4095; i_dummy++ )
{
p_vpar->pi_crop[i_dummy] = 2047;
}
......@@ -381,7 +460,7 @@ void vpar_InitCrop( vpar_thread_t * p_vpar )
* InitMbAddrInc : Initialize the lookup table for mb_addr_inc
*****************************************************************************/
/* Fonction for filling up the lookup table for mb_addr_inc */
/* Function for filling up the lookup table for mb_addr_inc */
void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
int i_start, int i_end, int i_step,
int * pi_value, int i_length )
......@@ -398,8 +477,8 @@ void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
}
}
/* Fonction that initialize the table using the last one */
void InitMbAddrInc( vpar_thread_t * p_vpar )
/* Function that initialize the table using the last one */
void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
{
int i_dummy;
int i_value;
......@@ -462,7 +541,7 @@ static void __inline__ FillMBType( vpar_thread_t * p_vpar,
}
/* Fonction that fills the table for P MB_Type */
void InitPMBType( vpar_thread_t * p_vpar )
void vpar_InitPMBType( vpar_thread_t * p_vpar )
{
FillMBType( p_vpar, 0, 32, 64, MB_MOTION_FORWARD|MB_PATTERN, 1 );
FillMBType( p_vpar, 0, 16, 32, MB_PATTERN, 2 );
......@@ -477,7 +556,7 @@ void InitPMBType( vpar_thread_t * p_vpar )
}
/* Fonction that fills the table for B MB_Type */
void InitBMBType( vpar_thread_t * p_vpar )
void vpar_InitBMBType( vpar_thread_t * p_vpar )
{
FillMBType( p_vpar, 1, 48, 64, MB_MOTION_FORWARD
|MB_MOTION_BACKWARD|MB_PATTERN, 2 );
......@@ -503,7 +582,7 @@ void InitBMBType( vpar_thread_t * p_vpar )
* InitCodedPattern : Initialize the lookup table for decoding
* coded block pattern
*****************************************************************************/
void InitCodedPattern( vpar_thread_t * p_vpar )
void vpar_InitCodedPattern( vpar_thread_t * p_vpar )
{
p_vpar->pl_coded_pattern = (lookup_t*) pl_coded_pattern_init_table;
}
......@@ -514,57 +593,50 @@ void InitCodedPattern( vpar_thread_t * p_vpar )
*****************************************************************************/
/* First fonction for filling the table */
static void __inline__ FillDCTTable( vpar_thread_t * p_vpar,
dct_lookup_t * pl_DCT_tab,
int i_size, int i_intra, int i_dec, int i_off )
static void __inline__ FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p_tab_src,
int i_step, int i_nb_elem, int i_offset )
{
int i_dummy, i_dummy2;
int i_end;
i_end = i_size / sizeof(dct_lookup_t);
for( i_dummy = 0; i_dummy < i_end; i_dummy++ )
for( i_dummy=0 ; i_dummy < i_nb_elem ; i_dummy++ )
{
for( i_dummy2 = 0; i_dummy2 < ( 1 << i_dec ); i_dummy2++ )
for( i_dummy2=0 ; i_dummy2 < i_step ; i_dummy2++ )
{
p_vpar->pppl_dct_coef
[i_intra][( ( i_dummy + i_off ) << i_dec ) + i_dummy2] =
&pl_DCT_tab[i_dummy];
p_tab_dest[(i_dummy+i_offset)*i_step+i_dummy2] = p_tab_src[i_dummy];
}
}
}
/* Fonction that actually fills the table or create the pointers */
void InitDCTTables( vpar_thread_t * p_vpar )
void vpar_InitDCTTables( vpar_thread_t * p_vpar )
{
/* Tables are cut in two parts to reduce memory occupation */
p_vpar->pppl_dct_dc_size[0][0] = pl_dct_dc_lum_init_table_1;
p_vpar->pppl_dct_dc_size[0][1] = pl_dct_dc_lum_init_table_2;
p_vpar->pppl_dct_dc_size[1][0] = pl_dct_dc_chrom_init_table_1;
p_vpar->pppl_dct_dc_size[1][1] = pl_dct_dc_chrom_init_table_2;
memset( ppl_dct_coef[0], MB_ERROR, 16 );
memset( ppl_dct_coef[1], MB_ERROR, 16 );
/* For table B14 & B15, we have a pointer to tables */
/* We fill the table thanks to the fonction defined above */
FillDCTTable( p_vpar, pl_DCT_tab_dc, sizeof(pl_DCT_tab_dc),0, 12, 4 );
FillDCTTable( p_vpar, pl_DCT_tab_ac, sizeof(pl_DCT_tab_ac), 0, 12, 4 );
FillDCTTable( p_vpar, pl_DCT_tab0, sizeof(pl_DCT_tab0), 0, 8, 4 );
FillDCTTable( p_vpar, pl_DCT_tab1, sizeof(pl_DCT_tab1), 0, 6, 8 );
FillDCTTable( p_vpar, pl_DCT_tab2, sizeof(pl_DCT_tab2), 0, 4, 16 );
FillDCTTable( p_vpar, pl_DCT_tab3, sizeof(pl_DCT_tab3), 0, 3, 16 );
FillDCTTable( p_vpar, pl_DCT_tab4, sizeof(pl_DCT_tab4), 0, 2, 16 );
FillDCTTable( p_vpar, pl_DCT_tab5, sizeof(pl_DCT_tab5), 0, 1, 16 );
FillDCTTable( p_vpar, pl_DCT_tab6, sizeof(pl_DCT_tab6), 0, 0, 16 );
FillDCTTable( p_vpar, pl_DCT_tab_dc, sizeof(pl_DCT_tab_dc), 1, 12, 4 );
FillDCTTable( p_vpar, pl_DCT_tab_ac, sizeof(pl_DCT_tab_ac), 1, 12, 4 );
FillDCTTable( p_vpar, pl_DCT_tab0a, sizeof(pl_DCT_tab0a), 1, 8, 4 );
FillDCTTable( p_vpar, pl_DCT_tab1a, sizeof(pl_DCT_tab1a), 1, 6, 8);
FillDCTTable( p_vpar, pl_DCT_tab2, sizeof(pl_DCT_tab2), 1, 4, 16 );
FillDCTTable( p_vpar, pl_DCT_tab3, sizeof(pl_DCT_tab3), 1, 3, 16 );
FillDCTTable( p_vpar, pl_DCT_tab4, sizeof(pl_DCT_tab4), 1, 2, 16 );
FillDCTTable( p_vpar, pl_DCT_tab5, sizeof(pl_DCT_tab5), 1, 1, 16 );
FillDCTTable( p_vpar, pl_DCT_tab6, sizeof(pl_DCT_tab6), 1, 0, 16 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab0, 256, 60, 4 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab1, 64, 8, 8 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab2, 16, 16, 16 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab3, 8, 16, 16 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab4, 4, 16, 16 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab5, 2, 16, 16 );
FillDCTTable( ppl_dct_coef[0], pl_DCT_tab6, 1, 16, 16 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab0a, 256, 60, 4 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab1a, 64, 8, 8 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab2, 16, 16, 16 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab3, 8, 16, 16 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab4, 4, 16, 16 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab5, 2, 16, 16 );
FillDCTTable( ppl_dct_coef[1], pl_DCT_tab6, 1, 16, 16 );
}
/*
......@@ -596,19 +668,38 @@ void vpar_ParseMacroblock( vpar_thread_t * p_vpar, int * pi_mb_address,
/************* DEBUG *************/
static i_count = 0;
int i_inc;
boolean_t b_stop = 0;
i_inc = MacroblockAddressIncrement( p_vpar );
*pi_mb_address += i_inc;
//*pi_mb_address += MacroblockAddressIncrement( p_vpar );
//*pi_mb_address += MacroblockAddressIncrement( p_vpar );
b_stop = i_inc > 1;
fprintf( stderr, "inc : %d (%d)\n", *pi_mb_address, i_inc );
/*
if( i_count > 4 )
if( 0 )//i_count > 8 )
{
while(1);
exit(0);
}
i_count++;
*/
if( 0 )
//i_count == 249)
// i_count != *pi_mb_address)
//b_stop )
{
fprintf( stderr, "i_count = %d (%d)\n", i_count, i_inc );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x\n", GetBits( &p_vpar->bit_stream, 16 ) );
exit(0);
}
for( i_mb = i_mb_previous; i_mb < *pi_mb_address; i_mb++ )
{
/* Skipped macroblock (ISO/IEC 13818-2 7.6.6). */
......@@ -631,7 +722,7 @@ i_count++;
vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
{
p_vpar->picture.b_error = 1;
intf_ErrMsg("vpar error: macroblock list is empty !");
intf_ErrMsg("vpar error: macroblock list is empty !\n");
return;
}
......@@ -651,13 +742,13 @@ i_count++;
p_mb->ppi_field_select[0][0] = p_mb->ppi_field_select[0][1]
= ( p_vpar->picture.i_current_structure == BOTTOM_FIELD );
}
fprintf(stderr, "MB1\n");
//fprintf(stderr, "MB1\n");
/* Get a macroblock structure. */
if( (p_mb = p_vpar->picture.pp_mb[i_mb_base + *pi_mb_address] =
vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
{
p_vpar->picture.b_error = 1;
intf_ErrMsg("vpar error: macroblock list is empty !");
intf_ErrMsg("vpar error: macroblock list is empty !\n");
return;
}
......@@ -685,7 +776,7 @@ fprintf( stderr, "motion2 !\n" );
if( p_vpar->picture.b_concealment_mv && (p_vpar->mb.i_mb_type & MB_INTRA) )
{
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
}
if( p_vpar->mb.i_mb_type & MB_PATTERN )
......@@ -695,7 +786,7 @@ fprintf( stderr, "motion2 !\n" );
else
{
int pi_coded_block_pattern[2] = {0,
(1 << 4+2*p_vpar->sequence.i_chroma_nb_blocks) - 1};
(1 << 4+p_vpar->sequence.i_chroma_nb_blocks) - 1};
p_vpar->mb.i_coded_block_pattern = pi_coded_block_pattern
[p_vpar->mb.i_mb_type & MB_INTRA];
}
......@@ -705,12 +796,12 @@ fprintf( stderr, "motion2 !\n" );
/*
* Effectively decode blocks.
*/
fprintf(stderr, "MB2\n");
i_mask = 1 << (3 + 2*p_vpar->sequence.i_chroma_nb_blocks);
//fprintf(stderr, "MB2\n");
i_mask = 1 << (3 + p_vpar->sequence.i_chroma_nb_blocks);
/* luminance */
p_data1 = (elem_t*) p_mb->p_picture->p_y;
// + p_mb->i_l_x + p_mb->i_l_y*(p_vpar->sequence.i_width);
+ p_mb->i_l_x + p_mb->i_l_y*(p_vpar->sequence.i_width);
for( i_b = 0 ; i_b < 4 ; i_b++, i_mask >>= 1 )
{
......@@ -727,7 +818,7 @@ fprintf(stderr, "MB2\n");
/* Calculate block coordinates. */
p_mb->p_data[i_b] = p_data1
+ pi_y[p_vpar->mb.b_dct_type][i_b]
* p_vpar->sequence.i_chroma_width;
* p_vpar->sequence.i_width;
}
else
{
......@@ -735,9 +826,37 @@ fprintf(stderr, "MB2\n");
p_mb->pf_addb[i_b] = vdec_DummyBlock;
p_mb->pf_idct[i_b] = vdec_DummyIDCT;
}
if( 0 )
//i_count == 482 && i_b == 2 )
// i_count != *pi_mb_address)
//b_stop )
{
fprintf( stderr, "i_count = %d (%d)\n", i_count, i_inc );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%4x\n", GetBits( &p_vpar->bit_stream, 16 ) );
exit(0);
}
}
/* chrominance U */
/* chrominance */
p_data1 = (elem_t*) p_mb->p_picture->p_u
+ (p_mb->i_c_x >> pi_chroma_hor[p_vpar->sequence.i_chroma_format])
+ (p_mb->i_c_y >> pi_chroma_ver[p_vpar->sequence.i_chroma_format])
......@@ -754,7 +873,6 @@ fprintf(stderr, "MB2\n");
if( p_vpar->mb.i_coded_block_pattern & i_mask )
{
fprintf( stderr, "Merde !!!!\n" );
memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(elem_t) );
(*pppf_decode_block[p_vpar->sequence.b_mpeg2]
[p_vpar->mb.i_mb_type & MB_INTRA])
......@@ -790,8 +908,25 @@ fprintf(stderr, "MB2\n");
/* Reset MV predictors. */
bzero( p_vpar->slice.pppi_pmv, 8*sizeof(int) );
}
if( 0 )
//i_count == 249)
// i_count != *pi_mb_address)
//b_stop )
{
fprintf( stderr, "i_count = %d (%d)\n", i_count, i_inc );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x\n", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x ", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x", GetBits( &p_vpar->bit_stream, 16 ) );
fprintf( stderr, "%x\n", GetBits( &p_vpar->bit_stream, 16 ) );
exit(0);
}
}
/*****************************************************************************
* InitMacroblock : Initialize macroblock values
*****************************************************************************/
......@@ -843,7 +978,7 @@ static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
/* Test the presence of the escape character */
while( i_index == 8 )
{
DumpBits( &p_vpar->bit_stream, 11 );
RemoveBits( &p_vpar->bit_stream, 11 );
i_addr_inc += 33;
i_index = ShowBits( &p_vpar->bit_stream, 11 );
}
......@@ -852,7 +987,7 @@ static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
/* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
return i_addr_inc;
}
......@@ -873,11 +1008,11 @@ static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
p_vpar->mb.i_mb_type = (p_vpar->picture.pf_macroblock_type)( p_vpar );
p_mb->i_mb_type = p_vpar->mb.i_mb_type;
fprintf( stderr, "MB type : %d\n", p_mb->i_mb_type );
//fprintf( stderr, "MB type : %d\n", p_mb->i_mb_type );
/* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
* has to be dropped, take care if you use scalable streams. */
/* DumpBits( &p_vpar->bit_stream, 2 ); */
/* RemoveBits( &p_vpar->bit_stream, 2 ); */
if( !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
{
......@@ -943,7 +1078,6 @@ fprintf( stderr, "MB type : %d\n", p_mb->i_mb_type );
}
}
}
p_vpar->mb.b_dmv = p_vpar->mb.i_motion_type == MOTION_DMV;
}
......@@ -960,9 +1094,8 @@ int vpar_IMBType( vpar_thread_t * p_vpar )
{MB_QUANT|MB_INTRA, 2},
{MB_INTRA, 1},
{MB_INTRA, 1} };
fprintf( stderr, "i_type : %d\n", i_type );
/* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, pl_mb_Itype[i_type].i_length );
RemoveBits( &p_vpar->bit_stream, pl_mb_Itype[i_type].i_length );
return pl_mb_Itype[i_type].i_value;
}
......@@ -975,7 +1108,7 @@ int vpar_PMBType( vpar_thread_t * p_vpar )
int i_type = ShowBits( &p_vpar->bit_stream, 6 );
/* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[0][i_type].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[0][i_type].i_length );
/* return the value from the lookup table for P type */
return p_vpar->ppl_mb_type[0][i_type].i_value;
......@@ -990,7 +1123,7 @@ int vpar_BMBType( vpar_thread_t * p_vpar )
int i_type = ShowBits( &p_vpar->bit_stream, 6 );
/* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[1][i_type].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[1][i_type].i_length );
/* return the value from the lookup table for B type */
return p_vpar->ppl_mb_type[1][i_type].i_value;
......@@ -1019,7 +1152,7 @@ int vpar_CodedPattern420( vpar_thread_t * p_vpar )
int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
/* Trash the good number of bits read in the lookup table */
DumpBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
/* return the value from the vlc table */
return p_vpar->pl_coded_pattern[i_vlc].i_value;
......@@ -1035,7 +1168,7 @@ int vpar_CodedPattern422( vpar_thread_t * p_vpar )
/* Supplementary 2 bits long code for 422 format */
int i_coded_block_pattern_1;
DumpBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
i_coded_block_pattern_1 = GetBits( &p_vpar->bit_stream, 2 );
/* the code is just to be added to the value found in the table */
......@@ -1051,7 +1184,7 @@ int vpar_CodedPattern444( vpar_thread_t * p_vpar )
int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
int i_coded_block_pattern_2;
DumpBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
RemoveBits( &p_vpar->bit_stream, p_vpar->pl_coded_pattern[i_vlc].i_length );
i_coded_block_pattern_2 = GetBits( &p_vpar->bit_stream, 6 );
return p_vpar->pl_coded_pattern[i_vlc].i_value |
......@@ -1068,7 +1201,7 @@ static void vpar_DecodeMPEG1Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in
{
/* Remove end_of_macroblock (always 1, prevents startcode emulation)
* ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
}
}
......@@ -1082,7 +1215,7 @@ static void vpar_DecodeMPEG1Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb,
{
/* Remove end_of_macroblock (always 1, prevents startcode emulation)
* ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
}
}
......@@ -1091,6 +1224,7 @@ static void vpar_DecodeMPEG1Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb,
*****************************************************************************/
static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, int i_b )
{
#if 0
int i_dummy;
int i_code;
int i_nc;
......@@ -1104,12 +1238,7 @@ static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in
* except that we won't use exactly the same table B.14 note 3 & 4 */
/* Decoding of the coefficients */
#ifndef VDEC_DCT
i_nc = 1;
#else
i_nc = 0;
#endif
i_coef = 0;
b_intra = p_vpar->picture.b_intra_vlc_format;
......@@ -1117,7 +1246,7 @@ static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in
{
i_code = ShowBits( &p_vpar->bit_stream, 16 );
i_run = (*p_vpar->pppl_dct_coef[b_intra][i_code]).i_run;
DumpBits( &p_vpar->bit_stream,
RemoveBits( &p_vpar->bit_stream,
(*p_vpar->pppl_dct_coef[b_intra][i_code]).i_length );
switch( i_run )
{
......@@ -1152,6 +1281,7 @@ static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in
{
p_mb->pf_idct[i_b] = vdec_IDCT;
}
#endif
}
/*****************************************************************************
......@@ -1165,6 +1295,7 @@ static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb,
int i_coef;
int i_type;
int i_code;
int i_length;
int i_code5;
int i_select;
int i_offset;
......@@ -1173,26 +1304,23 @@ static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb,
int i_dct_dc_diff;
int i_run;
int i_level;
boolean_t b_intra;
boolean_t b_vlc_intra;
boolean_t b_sign;
/* Lookup Table for the chromatic component */
static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
fprintf( stderr, "%x\n", ShowBits( &p_vpar->bit_stream, 32 ) );
i_cc = pi_cc_index[i_b];
#if 0
/* Determine whether it is luminance or not (chrominance) */
i_type = ( i_cc + 1 ) >> 1;
//fprintf( stderr, "MPEG2\n" );
/* Decoding of the DC intra coefficient */
/* The nb of bits to parse depends on i_type */
i_code = ShowBits( &p_vpar->bit_stream, 9 + i_type );
/* To reduce memory occupation, there are two lookup tables
* See InitDCT above */
i_code5 = i_code >> 4;
i_code5 = i_code >> (4+i_type);
/* Shall we lookup in the first or in the second table ? */
i_select = ( i_code5 == 31 );
......@@ -1200,37 +1328,162 @@ fprintf( stderr, "%x\n", ShowBits( &p_vpar->bit_stream, 32 ) );
i_offset = 0x1f0 + ( i_type * 0x1f0 );
i_pos = ( i_code5 * ( ! i_select ) ) + ( ( i_code - i_offset ) * i_select );
i_dct_dc_size = p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_value;
#endif
if( i_b < 4 )
{
int code, size, length, dct_diff;
/* decode length */
code = ShowBits(&p_vpar->bit_stream, 5);
if (code<31)
{
size = pl_dct_dc_lum_init_table_1[code].i_value;
length = pl_dct_dc_lum_init_table_1[code].i_length;
RemoveBits(&p_vpar->bit_stream, length);
}
else
{
code = ShowBits(&p_vpar->bit_stream, 9) - 0x1f0;
size = pl_dct_dc_lum_init_table_2[code].i_value;
length = pl_dct_dc_lum_init_table_2[code].i_length;
RemoveBits( &p_vpar->bit_stream, length);
}
if (size==0)
dct_diff = 0;
else
{
dct_diff = GetBits( &p_vpar->bit_stream, size);
if ((dct_diff & (1<<(size-1)))==0)
dct_diff-= (1<<size) - 1;
}
i_dct_dc_diff = dct_diff;
}
else
{
int code, size, length, dct_diff;
/* decode length */
code = ShowBits(&p_vpar->bit_stream, 5);
if (code<31)
{
size = pl_dct_dc_chrom_init_table_1[code].i_value;
length = pl_dct_dc_chrom_init_table_1[code].i_length;
RemoveBits(&p_vpar->bit_stream, length);
}
else
{
code = ShowBits(&p_vpar->bit_stream, 10) - 0x3e0;
size = pl_dct_dc_chrom_init_table_2[code].i_value;
length = pl_dct_dc_chrom_init_table_2[code].i_length;
RemoveBits( &p_vpar->bit_stream, length);
}
if (size==0)
dct_diff = 0;
else
{
dct_diff = GetBits( &p_vpar->bit_stream, size);
if ((dct_diff & (1<<(size-1)))==0)
dct_diff-= (1<<size) - 1;
}
i_dct_dc_diff = dct_diff;
}
/* Dump the variable length code */
DumpBits( &p_vpar->bit_stream,
p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_length );
//RemoveBits( &p_vpar->bit_stream,
// p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_length );
/* Read the actual code with the good length */
i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size );
p_vpar->slice.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
#ifndef VDEC_DFT
p_mb->ppi_blocks[i_b][0] = ( p_vpar->slice.pi_dc_dct_pred[i_cc] <<
( 3 - p_vpar->picture.i_intra_dc_precision ) );
i_nc = 1;
#else
p_mb->ppi_blocks[i_b][0] = ( p_vpar->slice.pi_dc_dct_pred[i_cc] <<
( 11 - p_vpar->picture.i_intra_dc_precision ) );
i_nc = ( p_vpar->slice.pi_dc_dct_pred[i_cc] != 0 );
#endif
//fprintf( stderr, "coucou\n" );
/* Decoding of the AC coefficients */
i_coef = 0;
b_intra = p_vpar->picture.b_intra_vlc_format;
for( i_dummy = 1; i_dummy < 64; i_dummy++ )
b_vlc_intra = p_vpar->picture.b_intra_vlc_format;
for( i_dummy = 1; /*i_dummy < 64*/; i_dummy++ )
{
i_code = ShowBits( &p_vpar->bit_stream, 16 );
fprintf( stderr, "b_intra : %d\ni_code : %d\n", b_intra, i_code );
i_run = (*p_vpar->pppl_dct_coef[b_intra][i_code]).i_run;
DumpBits( &p_vpar->bit_stream,
(*p_vpar->pppl_dct_coef[b_intra][i_code]).i_length );
//fprintf( stderr, "glop\n" );
if( i_code >= 16384 )
{
if( b_vlc_intra )
{
i_run = pl_DCT_tab0a[(i_code>>8)-4].i_run;
i_level = pl_DCT_tab0a[(i_code>>8)-4].i_level;
i_length = pl_DCT_tab0a[(i_code>>8)-4].i_length;
//fprintf( stderr, "**********> %d, %d, %d *******\n", i_run, i_level, (i_code>>8)-4 );
}
else
{
i_run = pl_DCT_tab_ac[(i_code>>12)-4].i_run;
i_level = pl_DCT_tab_ac[(i_code>>12)-4].i_level;
i_length = pl_DCT_tab_ac[(i_code>>12)-4].i_length;
}
}
else
{
i_run = ppl_dct_coef[b_vlc_intra][i_code].i_run;
i_length = ppl_dct_coef[b_vlc_intra][i_code].i_length;
i_level = ppl_dct_coef[b_vlc_intra][i_code].i_level;
}
{
int code = i_code;
int intra_vlc_format = b_vlc_intra;
dct_lookup_t tab;
if (code>=16384 && !intra_vlc_format)
tab = pl_DCT_tab_ac[(code>>12)-4];
else if (code>=1024)
{
if (intra_vlc_format)
tab = pl_DCT_tab0a[(code>>8)-4];
else
tab = pl_DCT_tab0[(code>>8)-4];
}
else if (code>=512)
{
if (intra_vlc_format)
tab = pl_DCT_tab1a[(code>>6)-8];
else
tab = pl_DCT_tab1[(code>>6)-8];
}
else if (code>=256)
tab = pl_DCT_tab2[(code>>4)-16];
else if (code>=128)
tab = pl_DCT_tab3[(code>>3)-16];
else if (code>=64)
tab = pl_DCT_tab4[(code>>2)-16];
else if (code>=32)
tab = pl_DCT_tab5[(code>>1)-16];
else if (code>=16)
tab = pl_DCT_tab6[code-16];
else
{
fprintf( stderr, "invalid Huffman code in Decode_MPEG2_Intra_Block()\n");
}
if( (i_run != tab.i_run) || (i_length != tab.i_length) || (i_level != tab.i_level) )
{
fprintf( stderr, "ET M....... !!!\n" );
exit(0);
}
}
RemoveBits( &p_vpar->bit_stream, i_length );
switch( i_run )
{
case DCT_ESCAPE:
......@@ -1244,18 +1497,32 @@ fprintf( stderr, "b_intra : %d\ni_code : %d\n", b_intra, i_code );
i_nc ++;
break;
case DCT_EOB:
i_dummy = 64;
if( i_nc <= 1 )
{
p_mb->pf_idct[i_b] = vdec_SparseIDCT;
p_mb->pi_sparse_pos[i_b] = i_coef;
}
else
{
p_mb->pf_idct[i_b] = vdec_IDCT;
}
return;
break;
default:
i_level = (*p_vpar->pppl_dct_coef[b_intra][i_code]).i_level;
b_sign = GetBits( &p_vpar->bit_stream, 1 );
p_mb->ppi_blocks[i_b][i_dummy] = b_sign ? -i_level : i_level;
i_coef = i_dummy;
i_dummy += i_run;
i_nc ++;
}
// fprintf( stderr, "i_code : %d (%d), run : %d, %d, %d (%4x) ", i_code , b_vlc_intra,
// i_run, i_level, i_dummy, ShowBits( &p_vpar->bit_stream, 16 ) );
//fprintf( stderr, "- %4x\n",ShowBits( &p_vpar->bit_stream, 16 ) );
}
if( i_nc == 1 )
if( i_nc <= 1 )
{
p_mb->pf_idct[i_b] = vdec_SparseIDCT;
p_mb->pi_sparse_pos[i_b] = i_coef;
......@@ -1264,5 +1531,6 @@ fprintf( stderr, "b_intra : %d\ni_code : %d\n", b_intra, i_code );
{
p_mb->pf_idct[i_b] = vdec_IDCT;
}
//fprintf( stderr, "MPEG2 end\n" );
fprintf( stderr, "MPEG2 end (%d)\n", i_b );
exit(0);
}
......@@ -166,7 +166,7 @@ static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
{
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
}
}
......@@ -264,7 +264,7 @@ int vpar_NextSequenceHeader( vpar_thread_t * p_vpar )
NextStartCode( p_vpar );
if( ShowBits( &p_vpar->bit_stream, 32 ) == SEQUENCE_HEADER_CODE )
return 0;
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
}
return 1;
}
......@@ -320,7 +320,7 @@ int vpar_ParseHeader( vpar_thread_t * p_vpar )
static void SequenceHeader( vpar_thread_t * p_vpar )
{
#define RESERVED -1
static double d_frame_rate_table[16] =
static float r_frame_rate_table[16] =
{
0.0,
((23.0*1000.0)/1001.0),
......@@ -340,15 +340,15 @@ static void SequenceHeader( vpar_thread_t * p_vpar )
i_height_save = p_vpar->sequence.i_height;
i_width_save = p_vpar->sequence.i_width;
p_vpar->sequence.i_height = GetBits( &p_vpar->bit_stream, 12 );
p_vpar->sequence.i_width = GetBits( &p_vpar->bit_stream, 12 );
p_vpar->sequence.i_height = GetBits( &p_vpar->bit_stream, 12 );
p_vpar->sequence.i_aspect_ratio = GetBits( &p_vpar->bit_stream, 4 );
p_vpar->sequence.d_frame_rate =
d_frame_rate_table[ GetBits( &p_vpar->bit_stream, 4 ) ];
p_vpar->sequence.r_frame_rate =
r_frame_rate_table[ GetBits( &p_vpar->bit_stream, 4 ) ];
/* We don't need bit_rate_value, marker_bit, vbv_buffer_size,
* constrained_parameters_flag */
DumpBits( &p_vpar->bit_stream, 30 );
RemoveBits( &p_vpar->bit_stream, 30 );
/*
* Quantization matrices
......@@ -395,9 +395,9 @@ static void SequenceHeader( vpar_thread_t * p_vpar )
p_vpar->sequence.b_mpeg2 = 1;
/* Parse sequence_extension */
DumpBits32( &p_vpar->bit_stream );
RemoveBits32( &p_vpar->bit_stream );
/* extension_start_code_identifier, profile_and_level_indication */
DumpBits( &p_vpar->bit_stream, 12 );
RemoveBits( &p_vpar->bit_stream, 12 );
p_vpar->sequence.b_progressive = GetBits( &p_vpar->bit_stream, 1 );
p_vpar->sequence.i_chroma_format = GetBits( &p_vpar->bit_stream, 2 );
p_vpar->sequence.pf_decode_pattern = ppf_chroma_pattern
......@@ -405,11 +405,11 @@ static void SequenceHeader( vpar_thread_t * p_vpar )
p_vpar->sequence.i_width |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
p_vpar->sequence.i_height |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
/* bit_rate_extension, marker_bit, vbv_buffer_size_extension, low_delay */
DumpBits( &p_vpar->bit_stream, 22 );
RemoveBits( &p_vpar->bit_stream, 22 );
/* frame_rate_extension_n */
i_dummy = GetBits( &p_vpar->bit_stream, 2 );
/* frame_rate_extension_d */
p_vpar->sequence.d_frame_rate *= (i_dummy + 1)
p_vpar->sequence.r_frame_rate *= (i_dummy + 1)
/ (GetBits( &p_vpar->bit_stream, 5 ) + 1);
p_vpar->sequence.pf_decode_mv = vpar_MPEG2MotionVector;
......@@ -502,7 +502,7 @@ static void SequenceHeader( vpar_thread_t * p_vpar )
static void GroupHeader( vpar_thread_t * p_vpar )
{
/* Nothing to do, we don't care. */
DumpBits( &p_vpar->bit_stream, 27 );
RemoveBits( &p_vpar->bit_stream, 27 );
ExtensionAndUserData( p_vpar );
}
......@@ -521,35 +521,39 @@ static void PictureHeader( vpar_thread_t * p_vpar )
boolean_t b_parsable;
u32 i_dummy;
DumpBits( &p_vpar->bit_stream, 10 ); /* temporal_reference */
RemoveBits( &p_vpar->bit_stream, 10 ); /* temporal_reference */
p_vpar->picture.i_coding_type = GetBits( &p_vpar->bit_stream, 3 );
p_vpar->picture.pf_macroblock_type = ppf_macroblock_type
[p_vpar->picture.i_coding_type];
RemoveBits( &p_vpar->bit_stream, 16 ); /* vbv_delay */
DumpBits( &p_vpar->bit_stream, 16 ); /* vbv_delay */
if( p_vpar->picture.i_coding_type == P_CODING_TYPE || p_vpar->picture.i_coding_type == B_CODING_TYPE )
{
p_vpar->picture.pb_full_pel_vector[0] = GetBits( &p_vpar->bit_stream, 1 );
p_vpar->picture.i_forward_f_code = GetBits( &p_vpar->bit_stream, 3 );
}
if( p_vpar->picture.i_coding_type == B_CODING_TYPE )
{
p_vpar->picture.pb_full_pel_vector[1] = GetBits( &p_vpar->bit_stream, 1 );
p_vpar->picture.i_backward_f_code = GetBits( &p_vpar->bit_stream, 3 );
}
/* extra_information_picture */
while( GetBits( &p_vpar->bit_stream, 1 ) )
{
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
}
/*
* Picture Coding Extension
*/
NextStartCode( p_vpar );
if( ShowBits( &p_vpar->bit_stream, 16 ) == EXTENSION_START_CODE )
if( ShowBits( &p_vpar->bit_stream, 32 ) == EXTENSION_START_CODE )
{
/* Parse picture_coding_extension */
DumpBits32( &p_vpar->bit_stream );
RemoveBits32( &p_vpar->bit_stream );
/* extension_start_code_identifier */
DumpBits( &p_vpar->bit_stream, 4 );
RemoveBits( &p_vpar->bit_stream, 4 );
p_vpar->picture.ppi_f_code[0][0] = GetBits( &p_vpar->bit_stream, 4 );
p_vpar->picture.ppi_f_code[0][1] = GetBits( &p_vpar->bit_stream, 4 );
......@@ -568,7 +572,7 @@ static void PictureHeader( vpar_thread_t * p_vpar )
/* repeat_first_field (ISO/IEC 13818-2 6.3.10 is necessary to know
* the length of the picture_display_extension structure.
* chroma_420_type (obsolete) */
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
p_vpar->picture.b_progressive_frame = GetBits( &p_vpar->bit_stream, 1 );
/* composite_display_flag */
......@@ -576,7 +580,7 @@ static void PictureHeader( vpar_thread_t * p_vpar )
{
/* v_axis, field_sequence, sub_carrier, burst_amplitude,
* sub_carrier_phase */
DumpBits( &p_vpar->bit_stream, 20 );
RemoveBits( &p_vpar->bit_stream, 20 );
}
}
else
......@@ -708,7 +712,7 @@ static void PictureHeader( vpar_thread_t * p_vpar )
/* Picture data (ISO/IEC 13818-2 6.2.3.7). */
NextStartCode( p_vpar );
while( i_mb_address+i_mb_base < p_vpar->sequence.i_mb_size
&& !p_vpar->picture.b_error)
&& !p_vpar->picture.b_error && !p_vpar->b_die )
{
if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
< SLICE_START_CODE_MIN) ||
......@@ -718,23 +722,12 @@ static void PictureHeader( vpar_thread_t * p_vpar )
p_vpar->picture.b_error = 1;
break;
}
DumpBits32( &p_vpar->bit_stream );
RemoveBits32( &p_vpar->bit_stream );
/* Decode slice data. */
p_vpar->sequence.pf_slice_header( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255 );
}
/* Link referenced pictures for the decoder
* They are unlinked in vpar_ReleaseMacroblock() & vpar_DestroyMacroblock() */
if( p_vpar->sequence.p_forward != NULL )
{
vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
}
if( p_vpar->sequence.p_backward != NULL )
{
vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
}
if( p_vpar->picture.b_error )
{
/* Trash picture. */
......@@ -747,16 +740,6 @@ fprintf(stderr, "Image trashee\n");
ReferenceReplace( p_vpar, p_vpar->picture.i_coding_type, NULL );
vout_DestroyPicture( p_vpar->p_vout, P_picture );
/* Unlink referenced pictures */
if( p_vpar->sequence.p_forward != NULL )
{
vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
}
if( p_vpar->sequence.p_backward != NULL )
{
vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
}
/* Prepare context for the next picture. */
P_picture = NULL;
if( p_vpar->picture.i_current_structure == FRAME_STRUCTURE )
......@@ -772,6 +755,17 @@ fprintf(stderr, "Image decodee\n");
vpar_DecodeMacroblock( &p_vpar->vfifo, p_vpar->picture.pp_mb[i_mb] );
}
/* Link referenced pictures for the decoder
* They are unlinked in vpar_ReleaseMacroblock() & vpar_DestroyMacroblock() */
if( p_vpar->sequence.p_forward != NULL )
{
vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
}
if( p_vpar->sequence.p_backward != NULL )
{
vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
}
/* Prepare context for the next picture. */
P_picture = NULL;
p_vpar->picture.i_current_structure = 0;
......@@ -797,14 +791,13 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
if( GetBits( &p_vpar->bit_stream, 1 ) )
{
/* intra_slice, slice_id */
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
/* extra_information_slice */
while( GetBits( &p_vpar->bit_stream, 1 ) )
{
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
}
}
*pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
/* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). Why
......@@ -822,7 +815,7 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
i_mb_base );
i_mb_address_save = *pi_mb_address;
}
while( ShowBits( &p_vpar->bit_stream, 23 ) );
while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->b_die );
NextStartCode( p_vpar );
}
......@@ -843,7 +836,7 @@ static void SliceHeader01( vpar_thread_t * p_vpar,
int * pi_mb_address, int i_mb_base,
u32 i_vert_code )
{
DumpBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
}
......@@ -860,7 +853,7 @@ static void SliceHeader11( vpar_thread_t * p_vpar,
u32 i_vert_code )
{
i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
DumpBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
}
......@@ -875,7 +868,7 @@ static void ExtensionAndUserData( vpar_thread_t * p_vpar )
switch( ShowBits( &p_vpar->bit_stream, 32 ) )
{
case EXTENSION_START_CODE:
DumpBits32( &p_vpar->bit_stream );
RemoveBits32( &p_vpar->bit_stream );
switch( GetBits( &p_vpar->bit_stream, 4 ) )
{
case SEQUENCE_DISPLAY_EXTENSION_ID:
......@@ -904,7 +897,7 @@ static void ExtensionAndUserData( vpar_thread_t * p_vpar )
break;
case USER_DATA_START_CODE:
DumpBits32( &p_vpar->bit_stream );
RemoveBits32( &p_vpar->bit_stream );
/* Wait for the next start code */
break;
......@@ -923,14 +916,14 @@ static void SequenceDisplayExtension( vpar_thread_t * p_vpar )
{
/* We don't care sequence_display_extension. */
/* video_format */
DumpBits( &p_vpar->bit_stream, 3 );
RemoveBits( &p_vpar->bit_stream, 3 );
if( GetBits( &p_vpar->bit_stream, 1 ) )
{
/* Three bytes for color_desciption */
DumpBits( &p_vpar->bit_stream, 24 );
RemoveBits( &p_vpar->bit_stream, 24 );
}
/* display_horizontal and vertical_size and a marker_bit */
DumpBits( &p_vpar->bit_stream, 29 );
RemoveBits( &p_vpar->bit_stream, 29 );
}
......@@ -1011,14 +1004,14 @@ static void SequenceScalableExtension( vpar_thread_t * p_vpar )
/* The length of the structure depends on the value of the scalable_mode */
{
case 1:
DumpBits32( &p_vpar->bit_stream );
DumpBits( &p_vpar->bit_stream, 21 );
RemoveBits32( &p_vpar->bit_stream );
RemoveBits( &p_vpar->bit_stream, 21 );
break;
case 2:
DumpBits( &p_vpar->bit_stream, 12 );
RemoveBits( &p_vpar->bit_stream, 12 );
break;
default:
DumpBits( &p_vpar->bit_stream, 4 );
RemoveBits( &p_vpar->bit_stream, 4 );
}
}
......@@ -1037,7 +1030,7 @@ static void PictureDisplayExtension( vpar_thread_t * p_vpar )
p_vpar->picture.b_top_field_first
: ( p_vpar->picture.b_frame_structure + 1 ) +
p_vpar->picture.b_repeat_first_field;
DumpBits( &p_vpar->bit_stream, 34 * nb );
RemoveBits( &p_vpar->bit_stream, 34 * nb );
}
......@@ -1048,8 +1041,8 @@ static void PictureDisplayExtension( vpar_thread_t * p_vpar )
static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar )
{
/* That's scalable, so we trash it */
DumpBits32( &p_vpar->bit_stream );
DumpBits( &p_vpar->bit_stream, 16 );
RemoveBits32( &p_vpar->bit_stream );
RemoveBits( &p_vpar->bit_stream, 16 );
}
......@@ -1060,7 +1053,7 @@ static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar )
static void PictureTemporalScalableExtension( vpar_thread_t * p_vpar )
{
/* Scalable again, trashed again */
DumpBits( &p_vpar->bit_stream, 23 );
RemoveBits( &p_vpar->bit_stream, 23 );
}
......@@ -1077,14 +1070,14 @@ static void CopyrightExtension( vpar_thread_t * p_vpar )
/* An identifier compliant with ISO/CEI JTC 1/SC 29 */
p_vpar->sequence.b_original = GetBits( &p_vpar->bit_stream, 1 );
/* Reserved bits */
DumpBits( &p_vpar->bit_stream, 8 );
RemoveBits( &p_vpar->bit_stream, 8 );
/* The copyright_number is split in three parts */
/* first part */
i_copyright_nb_1 = GetBits( &p_vpar->bit_stream, 20 );
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
/* second part */
i_copyright_nb_2 = GetBits( &p_vpar->bit_stream, 22 );
DumpBits( &p_vpar->bit_stream, 1 );
RemoveBits( &p_vpar->bit_stream, 1 );
/* third part and sum */
p_vpar->sequence.i_copyright_nb = ( (u64)i_copyright_nb_1 << 44 ) +
( (u64)i_copyright_nb_2 << 22 ) +
......
......@@ -73,14 +73,14 @@ static __inline__ int vpar_MotionCode( vpar_thread_t * p_vpar )
if( (i_code = ShowBits(&p_vpar->bit_stream, 9)) >= 64 )
{
i_code >>= 6;
DumpBits( &p_vpar->bit_stream, p_mv_tab0[0].i_len );
RemoveBits( &p_vpar->bit_stream, p_mv_tab0[0].i_len );
return( GetBits(&p_vpar->bit_stream, 1) ? -p_mv_tab0[i_code].i_val : p_mv_tab0[i_code].i_val );
}
if( i_code >= 24 )
{
i_code >>= 3;
DumpBits( &p_vpar->bit_stream, p_mv_tab1[0].i_len );
RemoveBits( &p_vpar->bit_stream, p_mv_tab1[0].i_len );
return( GetBits(&p_vpar->bit_stream, 1) ? -p_mv_tab1[i_code].i_val : p_mv_tab1[i_code].i_val );
}
......@@ -91,7 +91,7 @@ static __inline__ int vpar_MotionCode( vpar_thread_t * p_vpar )
return 0;
}
DumpBits( &p_vpar->bit_stream, p_mv_tab2[0].i_len );
RemoveBits( &p_vpar->bit_stream, p_mv_tab2[0].i_len );
return( GetBits(&p_vpar->bit_stream, 1) ? -p_mv_tab2[i_code].i_val : p_mv_tab2[i_code].i_val );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment