#include "vpar_synchro.h"
#include "video_parser.h"
+
/*
* Local prototypes
*/
-static __inline__ void InitMacroblock( vpar_thread_t * p_vpar,
- macroblock_t * p_mb );
-static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar );
-static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
- macroblock_t * p_mb );
typedef void (*f_decode_block_t)( vpar_thread_t *, macroblock_t *, int );
static void vpar_DecodeMPEG1Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, int i_b );
static void vpar_DecodeMPEG1Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb, int i_b );
* Initialisation tables
*/
/* Table for coded_block_pattern resolution */
-lookup_t pl_coded_pattern_init_table[512] =
+static lookup_t pl_coded_pattern_init_table[512] =
{ {MB_ERROR, 0}, {0, 9}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
{58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
{57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
*/
/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
-lookup_t pl_dct_dc_lum_init_table_1[32] =
+static lookup_t pl_dct_dc_lum_init_table_1[32] =
{ {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
{0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
};
/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
-lookup_t pl_dct_dc_lum_init_table_2[32] =
+static lookup_t pl_dct_dc_lum_init_table_2[32] =
{ {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
{8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
};
/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
-lookup_t pl_dct_dc_chrom_init_table_1[32] =
+static lookup_t pl_dct_dc_chrom_init_table_1[32] =
{ {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
{1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
};
/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
-lookup_t pl_dct_dc_chrom_init_table_2[32] =
+static lookup_t pl_dct_dc_chrom_init_table_2[32] =
{ {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
{6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
{7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
/* Table B-14, DCT coefficients table zero,
* codes 0100 ... 1xxx (used for first (DC) coefficient)
*/
-dct_lookup_t pl_DCT_tab_dc[12] =
+static dct_lookup_t pl_DCT_tab_dc[12] =
{
{0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
{0,1,1}, {0,1,1}, {0,1,1}, {0,1,1},
/* Table B-14, DCT coefficients table zero,
* codes 0100 ... 1xxx (used for all other coefficients)
*/
-dct_lookup_t pl_DCT_tab_ac[12] =
+static dct_lookup_t pl_DCT_tab_ac[12] =
{
{0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
{DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, /* EOB */
/* Table B-14, DCT coefficients table zero,
* codes 000001xx ... 00111xxx
*/
-dct_lookup_t pl_DCT_tab0[60] =
+static dct_lookup_t pl_DCT_tab0[60] =
{
{DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6},
/* Escape */
/* Table B-15, DCT coefficients table one,
* codes 000001xx ... 11111111
*/
-dct_lookup_t pl_DCT_tab0a[252] =
+static 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},
{2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
};
-
-
-
/* Table B-14, DCT coefficients table zero,
* codes 0000001000 ... 0000001111
*/
-dct_lookup_t pl_DCT_tab1[8] =
+static dct_lookup_t pl_DCT_tab1[8] =
{
{16,1,10}, {5,2,10}, {0,7,10}, {2,3,10},
{1,4,10}, {15,1,10}, {14,1,10}, {4,2,10}
/* Table B-15, DCT coefficients table one,
* codes 000000100x ... 000000111x
*/
-dct_lookup_t pl_DCT_tab1a[8] =
+static dct_lookup_t pl_DCT_tab1a[8] =
{
{5,2,9}, {5,2,9}, {14,1,9}, {14,1,9},
{2,4,10}, {16,1,10}, {15,1,9}, {15,1,9}
/* Table B-14/15, DCT coefficients table zero / one,
* codes 000000010000 ... 000000011111
*/
-dct_lookup_t pl_DCT_tab2[16] =
+static dct_lookup_t pl_DCT_tab2[16] =
{
{0,11,12}, {8,2,12}, {4,3,12}, {0,10,12},
{2,4,12}, {7,2,12}, {21,1,12}, {20,1,12},
/* Table B-14/15, DCT coefficients table zero / one,
* codes 0000000010000 ... 0000000011111
*/
-dct_lookup_t pl_DCT_tab3[16] =
+static dct_lookup_t pl_DCT_tab3[16] =
{
{10,2,13}, {9,2,13}, {5,3,13}, {3,4,13},
{2,5,13}, {1,7,13}, {1,6,13}, {0,15,13},
/* Table B-14/15, DCT coefficients table zero / one,
* codes 00000000010000 ... 00000000011111
*/
-dct_lookup_t pl_DCT_tab4[16] =
+static dct_lookup_t pl_DCT_tab4[16] =
{
{0,31,14}, {0,30,14}, {0,29,14}, {0,28,14},
{0,27,14}, {0,26,14}, {0,25,14}, {0,24,14},
/* Table B-14/15, DCT coefficients table zero / one,
* codes 000000000010000 ... 000000000011111
*/
-dct_lookup_t pl_DCT_tab5[16] =
+static dct_lookup_t pl_DCT_tab5[16] =
{
{0,40,15}, {0,39,15}, {0,38,15}, {0,37,15},
{0,36,15}, {0,35,15}, {0,34,15}, {0,33,15},
/* Table B-14/15, DCT coefficients table zero / one,
* codes 0000000000010000 ... 0000000000011111
*/
-dct_lookup_t pl_DCT_tab6[16] =
+static dct_lookup_t pl_DCT_tab6[16] =
{
{1,18,16}, {1,17,16}, {1,16,16}, {1,15,16},
{6,3,16}, {16,2,16}, {15,2,16}, {14,2,16},
*****************************************************************************/
/* Function for filling up the lookup table for mb_addr_inc */
-void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
+static void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
int i_start, int i_end, int i_step,
int * pi_value, int i_length )
{
* Macroblock parsing functions
*/
+/*****************************************************************************
+ * InitMacroblock : Initialize macroblock values
+ *****************************************************************************/
+static __inline__ void InitMacroblock( vpar_thread_t * p_vpar,
+ macroblock_t * p_mb )
+{
+ static f_chroma_motion_t pf_chroma_motion[4] =
+ { NULL, vdec_Motion420, vdec_Motion422, vdec_Motion444 };
+
+ p_mb->p_picture = p_vpar->picture.p_picture;
+ p_mb->i_structure = p_vpar->picture.i_structure;
+ p_mb->i_current_structure = p_vpar->picture.i_current_structure;
+ p_mb->i_l_x = p_vpar->mb.i_l_x;
+ p_mb->i_l_y = p_vpar->mb.i_l_y;
+ p_mb->i_c_x = p_vpar->mb.i_c_x;
+ p_mb->i_c_y = p_vpar->mb.i_c_y;
+ p_mb->i_chroma_nb_blocks = p_vpar->sequence.i_chroma_nb_blocks;
+ p_mb->pf_chroma_motion = pf_chroma_motion[p_vpar->sequence.i_chroma_format];
+ p_mb->b_P_coding_type = ( p_vpar->picture.i_coding_type == P_CODING_TYPE );
+
+ if( (p_vpar->picture.i_coding_type == P_CODING_TYPE) ||
+ (p_vpar->picture.i_coding_type == B_CODING_TYPE) )
+ p_mb->p_forward = p_vpar->sequence.p_forward;
+ if( p_vpar->picture.i_coding_type == B_CODING_TYPE )
+ p_mb->p_backward = p_vpar->sequence.p_backward;
+
+ p_mb->i_addb_l_stride = (p_mb->i_l_stride = p_vpar->picture.i_l_stride) - 8;
+ p_mb->i_addb_c_stride = (p_mb->i_c_stride = p_vpar->picture.i_c_stride) - 8;
+
+ /* Update macroblock real position. */
+ p_vpar->mb.i_l_x += 16;
+ p_vpar->mb.i_l_y += (p_vpar->mb.i_l_x / p_vpar->sequence.i_width)
+ * (2 - p_vpar->picture.b_frame_structure) * 16;
+ p_vpar->mb.i_l_x %= p_vpar->sequence.i_width;
+
+ p_vpar->mb.i_c_x += p_vpar->sequence.i_chroma_mb_width;
+ p_vpar->mb.i_c_y += (p_vpar->mb.i_c_x / p_vpar->sequence.i_chroma_width)
+ * (2 - p_vpar->picture.b_frame_structure)
+ * p_vpar->sequence.i_chroma_mb_height;
+ p_vpar->mb.i_c_x %= p_vpar->sequence.i_chroma_width;
+}
+
+/*****************************************************************************
+ * MacroblockAddressIncrement : Get the macroblock_address_increment field
+ *****************************************************************************/
+static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
+{
+ int i_addr_inc = 0;
+ /* Index in the lookup table mb_addr_inc */
+ int i_index = ShowBits( &p_vpar->bit_stream, 11 );
+
+ /* Test the presence of the escape character */
+ while( i_index == 8 )
+ {
+ RemoveBits( &p_vpar->bit_stream, 11 );
+ i_addr_inc += 33;
+ i_index = ShowBits( &p_vpar->bit_stream, 11 );
+ }
+
+ /* Affect the value from the lookup table */
+ i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
+
+ /* Dump the good number of bits */
+ RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
+
+ return i_addr_inc;
+}
+
+/*****************************************************************************
+ * MacroblockModes : Get the macroblock_modes structure
+ *****************************************************************************/
+static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
+ macroblock_t * p_mb )
+{
+ static f_motion_t pf_motion[2][4] =
+ { {NULL, vdec_MotionFieldField, vdec_MotionField16x8, vdec_MotionFieldDMV},
+ {NULL, vdec_MotionFrameField, vdec_MotionFrameFrame, vdec_MotionFrameDMV} };
+ static int ppi_mv_count[2][4] = { {0, 1, 2, 1}, {0, 2, 1, 1} };
+ static int ppi_mv_format[2][4] = { {0, 1, 1, 1}, {0, 1, 2, 1} };
+
+ /* Get macroblock_type. */
+ 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;
+
+ /* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
+ * has to be dropped, take care if you use scalable streams. */
+ /* RemoveBits( &p_vpar->bit_stream, 2 ); */
+
+ if( !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
+ {
+ /* If mb_type has neither MOTION_FORWARD nor MOTION_BACKWARD, this
+ * is useless, but also harmless. */
+ p_vpar->mb.i_motion_type = MOTION_FRAME;
+ }
+ else
+ {
+ if( p_vpar->picture.i_structure == FRAME_STRUCTURE
+ && p_vpar->picture.b_frame_pred_frame_dct )
+ {
+ p_vpar->mb.i_motion_type = MOTION_FRAME;
+ }
+ else
+ {
+ p_vpar->mb.i_motion_type = GetBits( &p_vpar->bit_stream, 2 );
+ }
+ }
+
+ if( p_mb->b_P_coding_type && !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD|MB_INTRA)) )
+ {
+ /* Special No-MC macroblock in P pictures (7.6.3.5). */
+ memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
+ memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
+
+ p_vpar->mb.i_motion_type = MOTION_FRAME;
+ p_mb->ppi_field_select[0][0] = ( p_vpar->picture.i_current_structure == BOTTOM_FIELD );
+ }
+
+ if( p_vpar->mb.i_mb_type & MB_INTRA )
+ {
+ /* For the intra macroblocks, we use an empty motion
+ * compensation function */
+ p_mb->pf_motion = vdec_MotionDummy;
+ }
+ else
+ {
+ p_mb->pf_motion = pf_motion[p_vpar->picture.b_frame_structure]
+ [p_vpar->mb.i_motion_type];
+ }
+ p_vpar->mb.i_mv_count = ppi_mv_count[p_vpar->picture.b_frame_structure]
+ [p_vpar->mb.i_motion_type];
+ p_vpar->mb.i_mv_format = ppi_mv_format[p_vpar->picture.b_frame_structure]
+ [p_vpar->mb.i_motion_type];
+
+ p_vpar->mb.b_dct_type = 0;
+ if( (p_vpar->picture.i_structure == FRAME_STRUCTURE) &&
+ (!p_vpar->picture.b_frame_pred_frame_dct) &&
+ (p_vpar->mb.i_mb_type & (MB_PATTERN|MB_INTRA)) )
+ {
+ if( (p_vpar->mb.b_dct_type = GetBits( &p_vpar->bit_stream, 1 )) )
+ {
+ /* The DCT is coded on fields. Jump one line between each
+ * sample. */
+ p_mb->i_addb_l_stride <<= 1;
+ p_mb->i_addb_l_stride += 8;
+ /* With CHROMA_420, the DCT is necessarily frame-coded. */
+ if( p_vpar->sequence.i_chroma_format != CHROMA_420 )
+ {
+ p_mb->i_addb_c_stride <<= 1;
+ p_mb->i_addb_c_stride += 8;
+ }
+ }
+ }
+ p_vpar->mb.b_dmv = p_vpar->mb.i_motion_type == MOTION_DMV;
+}
+
/*****************************************************************************
* vpar_ParseMacroblock : Parse the next macroblock
*****************************************************************************/
static int pi_x[12] = {0,8,0,8,0,0,0,0,8,8,8,8};
static int pi_y[2][12] = { {0,0,8,8,0,0,8,8,0,0,8,8},
{0,0,1,1,0,0,1,1,0,0,1,1} };
- static int pi_chroma_hor[4] = { 0, 1, 1, 0 };
- static int pi_chroma_ver[4] = { 0, 1, 0, 0 };
int i_mb, i_b, i_mask;
macroblock_t * p_mb;
yuv_data_t * p_data2;
/************* DEBUG *************/
- static int i_count = 0;
int i_inc;
- boolean_t b_stop = 0;
+ static int i_count;
+i_count++;
i_inc = MacroblockAddressIncrement( p_vpar );
-
*pi_mb_address += i_inc;
-
//*pi_mb_address += MacroblockAddressIncrement( p_vpar );
- b_stop = i_inc > 1;
- fprintf( stderr, "inc : %d (%d)\n", *pi_mb_address, i_inc );
-if( 0 )//i_count > 8 )
-{
- 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++ )
+ for( i_mb = i_mb_previous + 1; i_mb < *pi_mb_address; i_mb++ )
{
/* Skipped macroblock (ISO/IEC 13818-2 7.6.6). */
static int pi_dc_dct_reinit[4] = {128,256,512,1024};
- static f_motion_t pf_motion_skipped[4] = {NULL, vdec_MotionField,
- vdec_MotionField, vdec_MotionFrame};
-
+ static f_motion_t pf_motion_skipped[4] = {NULL, vdec_MotionFieldField,
+ vdec_MotionFieldField, vdec_MotionFrameFrame};
+fprintf(stderr, "On sauuuute !\n");
/* Reset DC predictors (7.2.1). */
p_vpar->slice.pi_dc_dct_pred[0] = p_vpar->slice.pi_dc_dct_pred[1]
= p_vpar->slice.pi_dc_dct_pred[2]
if( p_vpar->picture.i_coding_type == P_CODING_TYPE )
{
/* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
- bzero( p_vpar->slice.pppi_pmv, 8*sizeof(int) );
+ memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
}
if( (p_mb = p_vpar->picture.pp_mb[i_mb_base + i_mb] =
/* Motion type is picture structure. */
p_mb->pf_motion = pf_motion_skipped[p_vpar->picture.i_structure];
+ p_mb->i_mb_type = MB_MOTION_FORWARD;
/* Set the field we use for motion compensation */
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");
+
/* Get a macroblock structure. */
if( (p_mb = p_vpar->picture.pp_mb[i_mb_base + *pi_mb_address] =
vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
if( p_vpar->mb.i_mb_type & MB_MOTION_FORWARD )
{
-fprintf( stderr, "motion !\n" );
+//fprintf( stderr, "motion !\n" );
(*p_vpar->sequence.pf_decode_mv)( p_vpar, p_mb, 0 );
}
if( p_vpar->mb.i_mb_type & MB_MOTION_BACKWARD )
{
-fprintf( stderr, "motion2 !\n" );
+//fprintf( stderr, "motion2 !\n" );
(*p_vpar->sequence.pf_decode_mv)( p_vpar, p_mb, 1 );
}
{
RemoveBits( &p_vpar->bit_stream, 1 );
}
+if( 0 )
+ //i_count == 1231 &&
+ // i_count != *pi_mb_address)
+ //p_vpar->picture.i_coding_type == P_CODING_TYPE )
+{
+ fprintf( stderr, "i_count = %d (%d)\n", i_count, p_vpar->mb.i_mb_type );
+ 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);
+}
if( p_vpar->mb.i_mb_type & MB_PATTERN )
{
- (*p_vpar->sequence.pf_decode_pattern)( p_vpar );
+ p_vpar->mb.i_coded_block_pattern = (*p_vpar->sequence.pf_decode_pattern)( p_vpar );
+//fprintf( stderr, "pattern : %d\n", p_vpar->mb.i_coded_block_pattern );
}
else
{
p_vpar->mb.i_coded_block_pattern = pi_coded_block_pattern
[p_vpar->mb.i_mb_type & MB_INTRA];
}
-
pf_addb = ppf_addb_intra[p_vpar->mb.i_mb_type & MB_INTRA];
/*
* Effectively decode blocks.
*/
-//fprintf(stderr, "MB2\n");
+
i_mask = 1 << (3 + p_vpar->sequence.i_chroma_nb_blocks);
/* luminance */
{
if( p_vpar->mb.i_coded_block_pattern & i_mask )
{
- memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(elem_t) );
+ memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) );
(*pppf_decode_block[p_vpar->sequence.b_mpeg2]
[p_vpar->mb.i_mb_type & MB_INTRA])
( p_vpar, p_mb, i_b );
/* 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_width;
+ * p_vpar->sequence.i_width
+ + pi_x[i_b];
}
else
{
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 */
p_data1 = 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])
+ + p_mb->i_c_x
+ + p_mb->i_c_y
* (p_vpar->sequence.i_chroma_width);
p_data2 = p_mb->p_picture->p_v
- + (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])
+ + p_mb->i_c_x
+ + p_mb->i_c_y
* (p_vpar->sequence.i_chroma_width);
for( i_b = 4; i_b < 4 + p_vpar->sequence.i_chroma_nb_blocks;
if( p_vpar->mb.i_coded_block_pattern & i_mask )
{
- memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(elem_t) );
+ memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) );
(*pppf_decode_block[p_vpar->sequence.b_mpeg2]
[p_vpar->mb.i_mb_type & MB_INTRA])
( p_vpar, p_mb, i_b );
/* Calculate block coordinates. */
p_mb->p_data[i_b] = pp_data[i_b & 1]
+ pi_y[p_vpar->mb.b_dct_type][i_b]
- * p_vpar->sequence.i_chroma_width;
+ * p_vpar->sequence.i_chroma_width
+ + pi_x[i_b];
}
else
{
else if( !p_vpar->picture.b_concealment_mv )
{
/* Reset MV predictors. */
- bzero( p_vpar->slice.pppi_pmv, 8*sizeof(int) );
+ memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
+ }
+
+ if( p_mb->b_P_coding_type && !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD|MB_INTRA)) )
+ {
+ p_mb->i_mb_type |= MB_MOTION_FORWARD;
}
+/*
+if( p_vpar->picture.i_coding_type != I_CODING_TYPE )//!(p_mb->b_P_coding_type & MB_INTRA) )
+{
+ p_mb->i_mb_type |= MB_MOTION_FORWARD;
+}
+*/
if( 0 )
//i_count == 249)
// i_count != *pi_mb_address)
}
}
-
-/*****************************************************************************
- * InitMacroblock : Initialize macroblock values
- *****************************************************************************/
-static __inline__ void InitMacroblock( vpar_thread_t * p_vpar,
- macroblock_t * p_mb )
-{
- static f_chroma_motion_t pf_chroma_motion[4] =
- { NULL, vdec_Motion420, vdec_Motion422, vdec_Motion444 };
-
- p_mb->p_picture = p_vpar->picture.p_picture;
- p_mb->i_structure = p_vpar->picture.i_structure;
- p_mb->i_current_structure = p_vpar->picture.i_current_structure;
- p_mb->i_l_x = p_vpar->mb.i_l_x;
- p_mb->i_l_y = p_vpar->mb.i_l_y;
- p_mb->i_c_x = p_vpar->mb.i_c_x;
- p_mb->i_c_y = p_vpar->mb.i_c_y;
- p_mb->i_chroma_nb_blocks = p_vpar->sequence.i_chroma_nb_blocks;
- p_mb->pf_chroma_motion = pf_chroma_motion[p_vpar->sequence.i_chroma_format];
- p_mb->b_P_coding_type = ( p_vpar->picture.i_coding_type == P_CODING_TYPE );
-
- p_mb->p_forward = p_vpar->sequence.p_forward;
- p_mb->p_backward = p_vpar->sequence.p_backward;
-
- p_mb->i_addb_l_stride = p_mb->i_l_stride = p_vpar->picture.i_l_stride;
- p_mb->i_addb_c_stride = p_mb->i_c_stride = p_vpar->picture.i_c_stride;
-
- /* Update macroblock real position. */
- p_vpar->mb.i_l_x += 16;
- p_vpar->mb.i_l_y += (p_vpar->mb.i_l_x / p_vpar->sequence.i_width)
- * (2 - p_vpar->picture.b_frame_structure) * 16;
- p_vpar->mb.i_l_x %= p_vpar->sequence.i_width;
-
- p_vpar->mb.i_c_x += p_vpar->sequence.i_chroma_mb_width;
- p_vpar->mb.i_c_y += (p_vpar->mb.i_c_x / p_vpar->sequence.i_chroma_width)
- * (2 - p_vpar->picture.b_frame_structure)
- * p_vpar->sequence.i_chroma_mb_height;
- p_vpar->mb.i_c_x %= p_vpar->sequence.i_chroma_width;
-}
-
-/*****************************************************************************
- * MacroblockAddressIncrement : Get the macroblock_address_increment field
- *****************************************************************************/
-static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
-{
- int i_addr_inc = 0;
- /* Index in the lookup table mb_addr_inc */
- int i_index = ShowBits( &p_vpar->bit_stream, 11 );
-
- /* Test the presence of the escape character */
- while( i_index == 8 )
- {
- RemoveBits( &p_vpar->bit_stream, 11 );
- i_addr_inc += 33;
- i_index = ShowBits( &p_vpar->bit_stream, 11 );
- }
-
- /* Affect the value from the lookup table */
- i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
-
- /* Dump the good number of bits */
- RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
-
- return i_addr_inc;
-}
-
-/*****************************************************************************
- * MacroblockModes : Get the macroblock_modes structure
- *****************************************************************************/
-static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
- macroblock_t * p_mb )
-{
- static f_motion_t pf_motion[2][4] =
- { {NULL, vdec_FieldFieldRecon, vdec_Field16x8Recon, vdec_FieldDMVRecon},
- {NULL, vdec_FrameFieldRecon, vdec_FrameFrameRecon, vdec_FrameDMVRecon} };
- static int ppi_mv_count[2][4] = { {0, 1, 2, 1}, {0, 2, 1, 1} };
- static int ppi_mv_format[2][4] = { {0, 1, 1, 1}, {0, 1, 2, 1} };
-
- /* Get macroblock_type. */
- 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 );
-
- /* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
- * has to be dropped, take care if you use scalable streams. */
- /* RemoveBits( &p_vpar->bit_stream, 2 ); */
-
- if( !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
- {
- /* If mb_type has neither MOTION_FORWARD nor MOTION_BACKWARD, this
- * is useless, but also harmless. */
- p_vpar->mb.i_motion_type = MOTION_FRAME;
- }
- else
- {
- if( p_vpar->picture.i_structure == FRAME_STRUCTURE
- && p_vpar->picture.b_frame_pred_frame_dct )
- {
- p_vpar->mb.i_motion_type = MOTION_FRAME;
- }
- else
- {
- p_vpar->mb.i_motion_type = GetBits( &p_vpar->bit_stream, 2 );
- }
- }
-
- if( p_mb->b_P_coding_type && !(p_vpar->mb.i_mb_type & (MB_MOTION_FORWARD|MB_INTRA)) )
- {
- /* Special No-MC macroblock in P pictures (7.6.3.5). */
- memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
- memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
-
- p_vpar->mb.i_motion_type = MOTION_FRAME;
- p_mb->ppi_field_select[0][0] = ( p_vpar->picture.i_current_structure == BOTTOM_FIELD );
- }
-
- if( p_vpar->mb.i_mb_type & MB_INTRA )
- {
- /* For the intra macroblocks, we use an empty motion
- * compensation function */
- p_mb->pf_motion = vdec_DummyRecon;
- }
- else
- {
- p_mb->pf_motion = pf_motion[p_vpar->picture.b_frame_structure]
- [p_vpar->mb.i_motion_type];
- }
- p_vpar->mb.i_mv_count = ppi_mv_count[p_vpar->picture.b_frame_structure]
- [p_vpar->mb.i_motion_type];
- p_vpar->mb.i_mv_format = ppi_mv_format[p_vpar->picture.b_frame_structure]
- [p_vpar->mb.i_motion_type];
-
- p_vpar->mb.b_dct_type = 0;
- if( (p_vpar->picture.i_structure == FRAME_STRUCTURE) &&
- (!p_vpar->picture.b_frame_pred_frame_dct) &&
- (p_vpar->mb.i_mb_type & (MB_PATTERN|MB_INTRA)) )
- {
- if( (p_vpar->mb.b_dct_type = GetBits( &p_vpar->bit_stream, 1 )) )
- {
- /* The DCT is coded on fields. Jump one line between each
- * sample. */
- p_mb->i_addb_l_stride <<= 1;
- p_mb->i_addb_l_stride += 8;
- /* With CHROMA_420, the DCT is necessarily frame-coded. */
- if( p_vpar->sequence.i_chroma_format != CHROMA_420 )
- {
- p_mb->i_addb_c_stride <<= 1;
- p_mb->i_addb_c_stride += 8;
- }
- }
- }
- p_vpar->mb.b_dmv = p_vpar->mb.i_motion_type == MOTION_DMV;
-}
-
/*****************************************************************************
* vpar_IMBType : macroblock_type in I pictures
*****************************************************************************/
/* Testing on 6 bits */
int i_type = ShowBits( &p_vpar->bit_stream, 6 );
+#if 0
+/* Table B-3, macroblock_type in P-pictures, codes 001..1xx */
+static lookup_t PMBtab0[8] = {
+ {-1,0},
+ {MB_MOTION_FORWARD,3},
+ {MB_PATTERN,2}, {MB_PATTERN,2},
+ {MB_MOTION_FORWARD|MB_PATTERN,1},
+ {MB_MOTION_FORWARD|MB_PATTERN,1},
+ {MB_MOTION_FORWARD|MB_PATTERN,1},
+ {MB_MOTION_FORWARD|MB_PATTERN,1}
+};
+
+/* Table B-3, macroblock_type in P-pictures, codes 000001..00011x */
+static lookup_t PMBtab1[8] = {
+ {-1,0},
+ {MB_QUANT|MB_INTRA,6},
+ {MB_QUANT|MB_PATTERN,5}, {MB_QUANT|MB_PATTERN,5},
+ {MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN,5}, {MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN,5},
+ {MB_INTRA,5}, {MB_INTRA,5}
+};
+
+
+ if(i_type >= 8)
+ {
+ i_type >>= 3;
+ RemoveBits( &p_vpar->bit_stream,PMBtab0[i_type].i_length );
+ return PMBtab0[i_type].i_value;
+ }
+
+ if (i_type==0)
+ {
+ printf("Invalid P macroblock_type code\n");
+ return -1;
+ }
+ RemoveBits( &p_vpar->bit_stream,PMBtab1[i_type].i_length );
+ return PMBtab1[i_type].i_value;
+#endif
/* Dump the good number of bits */
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;
}
/* Lookup Table for the chromatic component */
static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
-
+
i_cc = pi_cc_index[i_b];
/* Determine whether it is luminance or not (chrominance) */
i_length = pl_DCT_tab_ac[(i_code>>12)-4].i_length;
}
}
+ else if( i_code >= 1024 )
+ {
+ i_run = pl_DCT_tab0[(i_code>>8)-4].i_run;
+ i_length = pl_DCT_tab0[(i_code>>8)-4].i_length;
+ i_level = pl_DCT_tab0[(i_code>>8)-4].i_level;
+ }
else
{
i_run = ppl_dct_coef[0][i_code].i_run;
i_coef = i_parse;
i_parse += i_run;
i_nc ++;
-
+
+if( i_parse >= 64 )
+{
+ break;
+}
+
i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
i_level = ( i_level *
p_vpar->slice.i_quantizer_scale *
ppi_quant[i_type][i_pos] ) >> 5;
- p_mb->ppi_blocks[i_b][i_parse] = b_sign ? -i_level : i_level;
+ p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
}
-fprintf( stderr, "MPEG2 end (%d)\n", i_b );
+fprintf( stderr, "Non intra MPEG2 end (%d)\n", i_b );
exit(0);
-
+//p_vpar->picture.b_error = 1;
}
/*****************************************************************************
int i_nc;
int i_cc;
int i_coef;
- int i_type;
+ int i_type, i_quant_type;
int i_code;
int i_length;
int i_pos;
/* Lookup Table for the chromatic component */
static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
-
i_cc = pi_cc_index[i_b];
/* Determine whether it is luminance or not (chrominance) */
i_type = ( i_cc + 1 ) >> 1;
+ i_quant_type = i_type | (p_vpar->sequence.i_chroma_format == CHROMA_420);
/* Give a pointer to the quantization matrices for intra blocks */
ppi_quant[0] = p_vpar->sequence.intra_quant.pi_matrix;
// i_run, i_level, i_parse, ShowBits( &p_vpar->bit_stream, 16 ) );
//fprintf( stderr, "- %4x\n",ShowBits( &p_vpar->bit_stream, 16 ) );
-
+if( i_parse >= 64 )
+{
+ fprintf( stderr, "Beuhh dans l'intra decode (%d)\n", i_b );
+ break;
+}
i_coef = i_parse;
i_parse += i_run;
i_nc ++;
i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
i_level = ( i_level *
p_vpar->slice.i_quantizer_scale *
- ppi_quant[i_type][i_pos] ) >> 4;
- p_mb->ppi_blocks[i_b][i_parse] = b_sign ? -i_level : i_level;
+ ppi_quant[i_quant_type][i_pos] ) >> 4;
+ p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
}
fprintf( stderr, "MPEG2 end (%d)\n", i_b );
exit(0);
+//p_vpar->b_error = 1;
}