Commit 6a7b7ae7 authored by Stéphane Borel's avatar Stéphane Borel

* Fonction de d�codage des Blocs MPEG2intra.
* Correction d'erreurs sur la gestion des tables de lookup
parent 77fdd47e
/******************************************************************************* /*****************************************************************************
* video_decoder.h : video decoder thread * video_decoder.h : video decoder thread
* (c)1999 VideoLAN * (c)1999 VideoLAN
******************************************************************************* *****************************************************************************
******************************************************************************* *****************************************************************************
* Requires: * Requires:
* "config.h" * "config.h"
* "common.h" * "common.h"
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
* "video.h" * "video.h"
* "video_output.h" * "video_output.h"
* "decoder_fifo.h" * "decoder_fifo.h"
*******************************************************************************/ *****************************************************************************/
/******************************************************************************* /*****************************************************************************
* vdec_thread_t: video decoder thread descriptor * vdec_thread_t: video decoder thread descriptor
******************************************************************************* *****************************************************************************
* ?? * ??
*******************************************************************************/ *****************************************************************************/
typedef struct vdec_thread_s typedef struct vdec_thread_s
{ {
/* Thread properties and locks */ /* Thread properties and locks */
...@@ -33,26 +33,19 @@ typedef struct vdec_thread_s ...@@ -33,26 +33,19 @@ typedef struct vdec_thread_s
/*??*/ /*??*/
// int *pi_status; // int *pi_status;
/* Input properties */ /* Input properties */
decoder_fifo_t fifo; /* PES input fifo */ struct vpar_thread_s * p_vpar; /* video_parser thread */
/* The bit stream structure handles the PES stream at the bit level */
bit_stream_t bit_stream;
/* Output properties */
vout_thread_t * p_vout; /* video output thread */
int i_stream; /* video stream id */
/* Lookup tables */
#ifdef MPEG2_COMPLIANT
u8 pi_crop_buf[VDEC_CROPRANGE];
u8 * pi_crop,
#endif
#ifdef STATS #ifdef STATS
/* Statistics */ /* Statistics */
count_t c_loops; /* number of loops */ count_t c_loops; /* number of loops */
count_t c_idle_loops; /* number of idle loops */ count_t c_idle_loops; /* number of idle loops */
count_t c_pictures; /* number of pictures read */
count_t c_i_pictures; /* number of I pictures read */
count_t c_p_pictures; /* number of P pictures read */
count_t c_b_pictures; /* number of B pictures read */
count_t c_decoded_pictures; /* number of pictures decoded */ count_t c_decoded_pictures; /* number of pictures decoded */
count_t c_decoded_i_pictures; /* number of I pictures decoded */ count_t c_decoded_i_pictures; /* number of I pictures decoded */
count_t c_decoded_p_pictures; /* number of P pictures decoded */ count_t c_decoded_p_pictures; /* number of P pictures decoded */
...@@ -60,17 +53,22 @@ typedef struct vdec_thread_s ...@@ -60,17 +53,22 @@ typedef struct vdec_thread_s
#endif #endif
} vdec_thread_t; } vdec_thread_t;
/******************************************************************************* /* Move this somewhere else ASAP !! */
#define data_t short
/*****************************************************************************
* Function pointers
*****************************************************************************/
typedef void (*f_addb_t)( vdec_thread_t*, elem_t*, data_t*, int );
/*****************************************************************************
* Prototypes * Prototypes
*******************************************************************************/ *****************************************************************************/
struct vpar_thread_s;
/* Thread management functions */ /* Thread management functions */
p_vdec_thread_t vdec_CreateThread ( /* video_cfg_t *p_cfg, */ input_thread_t *p_input /*, vdec_thread_t * vdec_CreateThread ( struct vpar_thread_s *p_vpar /*, int *pi_status */ );
vout_thread_t *p_vout, int *pi_status */ );
void vdec_DestroyThread ( vdec_thread_t *p_vdec /*, int *pi_status */ ); void vdec_DestroyThread ( vdec_thread_t *p_vdec /*, int *pi_status */ );
void vdec_AddBlock( vdec_thread_t*, elem_t*, data_t*, int );
/* Time management functions */ void vdec_CopyBlock( vdec_thread_t*, elem_t*, data_t*, int );
/* ?? */ void vdec_DummyBlock( vdec_thread_t*, elem_t*, data_t*, int );
/* Dynamic thread settings */
/* ?? */
...@@ -65,12 +65,14 @@ typedef struct vpar_thread_s ...@@ -65,12 +65,14 @@ typedef struct vpar_thread_s
#endif #endif
lookup_t pl_mb_addr_inc[2048]; /* for macroblock lookup_t pl_mb_addr_inc[2048]; /* for macroblock
address increment */ address increment */
/* variable length codes for the structure dct_dc_size */
lookup_t pppl_dct_dc_size[2][2][32];
/* tables for macroblock types 0=P 1=B */ /* tables for macroblock types 0=P 1=B */
lookup_t pl_mb_type[2][64]; lookup_t ppl_mb_type[2][64];
/* table for coded_block_pattern */ /* table for coded_block_pattern */
lookup_t pl_coded_pattern[512]; lookup_t pl_coded_pattern[512];
/* variable length codes for the structure dct_dc_size for intra blocks */
lookup_t pppl_dct_dc_size[2][2][32];
/* structure to store the tables B14 & B15 */
dct_lookup_t *ppl_dct_coef[10];
#ifdef STATS #ifdef STATS
/* Statistics */ /* Statistics */
......
...@@ -45,7 +45,7 @@ typedef struct macroblock_s ...@@ -45,7 +45,7 @@ typedef struct macroblock_s
/* AddBlock information */ /* AddBlock information */
f_addb_t pf_addb[12]; /* pointer to the Add function */ f_addb_t pf_addb[12]; /* pointer to the Add function */
data_t * p_data[12]; /* pointer to the position data_t p_data[12]; /* pointer to the position
* in the final picture */ * in the final picture */
int i_addb_l_stride, i_addb_c_stride; int i_addb_l_stride, i_addb_c_stride;
} macroblock_t; } macroblock_t;
...@@ -67,9 +67,9 @@ typedef struct ...@@ -67,9 +67,9 @@ typedef struct
int i_l_x, i_l_y, i_c_x, i_c_y; int i_l_x, i_l_y, i_c_x, i_c_y;
} macroblock_parsing_t; } macroblock_parsing_t;
/****************************************************************************** /*****************************************************************************
* lookup_t : entry type for lookup tables * * lookup_t : entry type for lookup tables *
******************************************************************************/ *****************************************************************************/
typedef struct lookup_s typedef struct lookup_s
{ {
...@@ -77,6 +77,17 @@ typedef struct lookup_s ...@@ -77,6 +77,17 @@ typedef struct lookup_s
int i_length; int i_length;
} lookup_t; } lookup_t;
/******************************************************************************
* ac_lookup_t : special entry type for lookup tables about ac coefficients
*****************************************************************************/
typedef struct dct_lookup_s
{
int i_run;
int i_level;
int i_length;
} dct_lookup_t;
/***************************************************************************** /*****************************************************************************
* Standard codes * Standard codes
*****************************************************************************/ *****************************************************************************/
...@@ -104,6 +115,17 @@ typedef struct lookup_s ...@@ -104,6 +115,17 @@ typedef struct lookup_s
#define SCAN_ZIGZAG 0 #define SCAN_ZIGZAG 0
#define SCAN_ALT 1 #define SCAN_ALT 1
/* Constant for block decoding */
#define DCT_EOB 64
#define DCT_ESCAPE 65
/*****************************************************************************
* Constants
*****************************************************************************/
extern int * pi_default_intra_quant;
extern int * pi_default_nonintra_quant;
extern u8 pi_scan[2][64];
/***************************************************************************** /*****************************************************************************
* Prototypes * Prototypes
*****************************************************************************/ *****************************************************************************/
......
...@@ -230,6 +230,7 @@ static int InitThread( vpar_thread_t *p_vpar ) ...@@ -230,6 +230,7 @@ static int InitThread( vpar_thread_t *p_vpar )
InitPMBType( p_vpar ); InitPMBType( p_vpar );
InitBMBType( p_vpar ); InitBMBType( p_vpar );
InitCodedPattern( p_vpar ); InitCodedPattern( p_vpar );
InitDCTTables( p_vpar );
/* Mark thread as running and return */ /* Mark thread as running and return */
intf_DbgMsg("vpar debug: InitThread(%p) succeeded\n", p_vpar); intf_DbgMsg("vpar debug: InitThread(%p) succeeded\n", p_vpar);
......
...@@ -56,8 +56,9 @@ static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb, ...@@ -56,8 +56,9 @@ static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb,
/* /*
* Initialisation tables * Initialisation tables
*/ */
/* Table for coded_block_pattern resolution */
lookup_t pl_coded_pattern_init_table[512] = lookup_t pl_coded_pattern_init_table[512] =
{ {MB_ERROR, 0}, {MB_ERROR, 0}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9}, { {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}, {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}, {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
{38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8}, {38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8},
...@@ -122,7 +123,230 @@ lookup_t pl_coded_pattern_init_table[512] = ...@@ -122,7 +123,230 @@ lookup_t pl_coded_pattern_init_table[512] =
{60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
{60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3} }; {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3} };
/* Tables for dc DCT coefficients
* Tables are cut in two parts to reduce memory occupation
*/
/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
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},
{4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}
};
/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
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},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
{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] =
{ {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},
{3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
};
/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
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},
{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 */
/* Table B-14, DCT coefficients table zero,
* codes 0100 ... 1xxx (used for first (DC) coefficient)
*/
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},
{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] =
{
{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 */
{0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}
};
/* Table B-14, DCT coefficients table zero,
* codes 000001xx ... 00111xxx
*/
dct_lookup_t pl_DCT_tab0[60] =
{
{DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6},
/* Escape */
{2,2,7}, {2,2,7}, {9,1,7}, {9,1,7},
{0,4,7}, {0,4,7}, {8,1,7}, {8,1,7},
{7,1,6}, {7,1,6}, {7,1,6}, {7,1,6},
{6,1,6}, {6,1,6}, {6,1,6}, {6,1,6},
{1,2,6}, {1,2,6}, {1,2,6}, {1,2,6},
{5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
{13,1,8}, {0,6,8}, {12,1,8}, {11,1,8},
{3,2,8}, {1,3,8}, {0,5,8}, {10,1,8},
{0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
{0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
{4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
{4,1,5}, {4,1,5}, {4,1,5}, {4,1,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}
};
/* Table B-15, DCT coefficients table one,
* codes 000001xx ... 11111111
*/
dct_lookup_t pl_DCT_tab0a[252] =
{
{DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,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},
{DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4}, /* EOB */
{DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4},
{DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4},
{DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,0,4}, {DCT_EOB,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,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
*/
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] =
{
{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] =
{
{0,11,12}, {8,2,12}, {4,3,12}, {0,10,12},
{2,4,12}, {7,2,12}, {21,1,12}, {20,1,12},
{0,9,12}, {19,1,12}, {18,1,12}, {1,5,12},
{3,3,12}, {0,8,12}, {6,2,12}, {17,1,12}
};
/* Table B-14/15, DCT coefficients table zero / one,
* codes 0000000010000 ... 0000000011111
*/
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},
{0,14,13}, {0,13,13}, {0,12,13}, {26,1,13},
{25,1,13}, {24,1,13}, {23,1,13}, {22,1,13}
};
/* Table B-14/15, DCT coefficients table zero / one,
* codes 00000000010000 ... 00000000011111
*/
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},
{0,23,14}, {0,22,14}, {0,21,14}, {0,20,14},
{0,19,14}, {0,18,14}, {0,17,14}, {0,16,14}
};
/* Table B-14/15, DCT coefficients table zero / one,
* codes 000000000010000 ... 000000000011111
*/
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},
{0,32,15}, {1,14,15}, {1,13,15}, {1,12,15},
{1,11,15}, {1,10,15}, {1,9,15}, {1,8,15}
};
/* Table B-14/15, DCT coefficients table zero / one,
* codes 0000000000010000 ... 0000000000011111
*/
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},
{13,2,16}, {12,2,16}, {11,2,16}, {31,1,16},
{30,1,16}, {29,1,16}, {28,1,16}, {27,1,16}
};
/* /*
* Initialization of lookup tables * Initialization of lookup tables
*/ */
...@@ -154,7 +378,7 @@ void vpar_InitCrop( vpar_thread_t * p_vpar ) ...@@ -154,7 +378,7 @@ void vpar_InitCrop( vpar_thread_t * p_vpar )
#endif #endif
/***************************************************************************** /*****************************************************************************
* InitMbAddrInc : Initialize the lookup table for mb_addr_inc * * InitMbAddrInc : Initialize the lookup table for mb_addr_inc
*****************************************************************************/ *****************************************************************************/
/* Fonction for filling up the lookup table for mb_addr_inc */ /* Fonction for filling up the lookup table for mb_addr_inc */
...@@ -211,55 +435,10 @@ void InitMbAddrInc( vpar_thread_t * p_vpar ) ...@@ -211,55 +435,10 @@ void InitMbAddrInc( vpar_thread_t * p_vpar )
FillMbAddrIncTable( p_vpar, 36, 48, 2, pi_value, 10 ); FillMbAddrIncTable( p_vpar, 36, 48, 2, pi_value, 10 );
FillMbAddrIncTable( p_vpar, 24, 36, 1, pi_value, 11 ); FillMbAddrIncTable( p_vpar, 24, 36, 1, pi_value, 11 );
} }
/*****************************************************************************
* InitDCT : Initialize tables giving the length of the dct coefficient
* from the vlc code
*****************************************************************************/
void InitDCTTables( vpar_thread_t * p_vpar )
{
#if 0
/* Tables are cut in two parts to reduce memory occupation */
/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
p_vpar->pppl_dct_dc_size[0][0] =
{ {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},
{4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}
};
/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
p_vpar->pppl_dct_dc_lum_size[1][0] =
{ {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},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
{MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}
};
/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
p_vpar->pppl_dct_dc_chrom_size[0][1] =
{ {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},
{3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
};
/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
p_vpar->pppl_dct_dc_size[1][1] =
{ {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},
{8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
};
#endif
}
/***************************************************************************** /*****************************************************************************
* Init*MBType : Initialize lookup table for the Macroblock type * Init*MBType : Initialize lookup table for the Macroblock type
* ***************************************************************************/ *****************************************************************************/
/* Fonction for filling up the tables */ /* Fonction for filling up the tables */
static void __inline__ FillMBType( vpar_thread_t * p_vpar, static void __inline__ FillMBType( vpar_thread_t * p_vpar,
...@@ -273,8 +452,8 @@ static void __inline__ FillMBType( vpar_thread_t * p_vpar, ...@@ -273,8 +452,8 @@ static void __inline__ FillMBType( vpar_thread_t * p_vpar,
for( i_dummy = i_start ; i_dummy < i_end ; i_dummy++ ) for( i_dummy = i_start ; i_dummy < i_end ; i_dummy++ )
{ {
p_vpar->pl_mb_type[i_mb_type][i_dummy].i_value = i_value; p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_value = i_value;
p_vpar->pl_mb_type[i_mb_type][i_dummy].i_length = i_length; p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_length = i_length;
} }
} }
...@@ -287,10 +466,10 @@ void InitPMBType( vpar_thread_t * p_vpar ) ...@@ -287,10 +466,10 @@ void InitPMBType( vpar_thread_t * p_vpar )
FillMBType( p_vpar, 0, 6, 8, MB_INTRA, 5 ); FillMBType( p_vpar, 0, 6, 8, MB_INTRA, 5 );
FillMBType( p_vpar, 0, 4, 6, MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN, 5 ); FillMBType( p_vpar, 0, 4, 6, MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN, 5 );
FillMBType( p_vpar, 0, 2, 4, MB_QUANT|MB_PATTERN, 5 ); FillMBType( p_vpar, 0, 2, 4, MB_QUANT|MB_PATTERN, 5 );
p_vpar->pl_mb_type[0][1].i_value = MB_QUANT|MB_INTRA; p_vpar->ppl_mb_type[0][1].i_value = MB_QUANT|MB_INTRA;
p_vpar->pl_mb_type[0][1].i_length = 6; p_vpar->ppl_mb_type[0][1].i_length = 6;
p_vpar->pl_mb_type[0][0].i_value = MB_ERROR; p_vpar->ppl_mb_type[0][0].i_value = MB_ERROR;
p_vpar->pl_mb_type[0][0].i_length = 0; p_vpar->ppl_mb_type[0][0].i_length = 0;
} }
/* Fonction that fills the table for B MB_Type */ /* Fonction that fills the table for B MB_Type */
...@@ -306,14 +485,14 @@ void InitBMBType( vpar_thread_t * p_vpar ) ...@@ -306,14 +485,14 @@ void InitBMBType( vpar_thread_t * p_vpar )
FillMBType( p_vpar, 1, 6, 8, MB_INTRA, 5 ); FillMBType( p_vpar, 1, 6, 8, MB_INTRA, 5 );
FillMBType( p_vpar, 1, 4, 6, MB_QUANT|MB_MOTION_FORWARD FillMBType( p_vpar, 1, 4, 6, MB_QUANT|MB_MOTION_FORWARD
|MB_MOTION_BACKWARD|MB_PATTERN, 5 ); |MB_MOTION_BACKWARD|MB_PATTERN, 5 );
p_vpar->pl_mb_type[1][3].i_value = MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN; p_vpar->ppl_mb_type[1][3].i_value = MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN;
p_vpar->pl_mb_type[1][3].i_length = 6; p_vpar->ppl_mb_type[1][3].i_length = 6;
p_vpar->pl_mb_type[1][2].i_value = MB_QUANT|MB_MOTION_BACKWARD|MB_PATTERN; p_vpar->ppl_mb_type[1][2].i_value = MB_QUANT|MB_MOTION_BACKWARD|MB_PATTERN;
p_vpar->pl_mb_type[1][2].i_length = 6; p_vpar->ppl_mb_type[1][2].i_length = 6;
p_vpar->pl_mb_type[1][1].i_value = MB_QUANT|MB_INTRA; p_vpar->ppl_mb_type[1][1].i_value = MB_QUANT|MB_INTRA;
p_vpar->pl_mb_type[1][1].i_length = 6; p_vpar->ppl_mb_type[1][1].i_length = 6;
p_vpar->pl_mb_type[1][0].i_value =MB_ERROR; p_vpar->ppl_mb_type[1][0].i_value =MB_ERROR;
p_vpar->pl_mb_type[1][0].i_length = 0; p_vpar->ppl_mb_type[1][0].i_length = 0;
} }
/***************************************************************************** /*****************************************************************************
...@@ -326,6 +505,38 @@ void InitCodedPattern( vpar_thread_t * p_vpar ) ...@@ -326,6 +505,38 @@ void InitCodedPattern( vpar_thread_t * p_vpar )
sizeof(pl_coded_pattern_init_table) ); sizeof(pl_coded_pattern_init_table) );
} }
/*****************************************************************************
* InitDCT : Initialize tables giving the length of the dct coefficient
* from the vlc code
*****************************************************************************/
void InitDCTTables( vpar_thread_t * p_vpar )
{
/* Tables are cut in two parts to reduce memory occupation */
memcpy( p_vpar->pppl_dct_dc_size[0][0], pl_dct_dc_lum_init_table_1,
sizeof( pl_dct_dc_lum_init_table_1 ) );
memcpy( p_vpar->pppl_dct_dc_size[0][1], pl_dct_dc_lum_init_table_2,
sizeof( pl_dct_dc_lum_init_table_2 ) );
memcpy( p_vpar->pppl_dct_dc_size[1][0], pl_dct_dc_chrom_init_table_1,
sizeof( pl_dct_dc_chrom_init_table_1 ) );
memcpy( p_vpar->pppl_dct_dc_size[1][1], pl_dct_dc_chrom_init_table_2,
sizeof( pl_dct_dc_chrom_init_table_2 ) );
/* For table B14 & B15, we have a pointer to tables */
memcpy( p_vpar->ppl_dct_coef[0], pl_DCT_tab_dc, sizeof( pl_DCT_tab_dc ) );
memcpy( p_vpar->ppl_dct_coef[1], pl_DCT_tab_ac, sizeof( pl_DCT_tab_ac ) );
memcpy( p_vpar->ppl_dct_coef[2], pl_DCT_tab0, sizeof( pl_DCT_tab0 ) );
memcpy( p_vpar->ppl_dct_coef[3], pl_DCT_tab1, sizeof( pl_DCT_tab1 ) );
memcpy( p_vpar->ppl_dct_coef[4], pl_DCT_tab2, sizeof( pl_DCT_tab2 ) );
memcpy( p_vpar->ppl_dct_coef[5], pl_DCT_tab3, sizeof( pl_DCT_tab3 ) );
memcpy( p_vpar->ppl_dct_coef[6], pl_DCT_tab4, sizeof( pl_DCT_tab4 ) );
memcpy( p_vpar->ppl_dct_coef[7], pl_DCT_tab5, sizeof( pl_DCT_tab5 ) );
memcpy( p_vpar->ppl_dct_coef[8], pl_DCT_tab6, sizeof( pl_DCT_tab6 ) );
memcpy( p_vpar->ppl_dct_coef[9], pl_DCT_tab0a, sizeof( pl_DCT_tab0a ) );
memcpy( p_vpar->ppl_dct_coef[10], pl_DCT_tab1a, sizeof( pl_DCT_tab1a ) );
}
/* /*
* Macroblock parsing functions * Macroblock parsing functions
*/ */
...@@ -700,9 +911,9 @@ int vpar_PMBType( vpar_thread_t * p_vpar ) ...@@ -700,9 +911,9 @@ int vpar_PMBType( vpar_thread_t * p_vpar )
/* Testing on 6 bits */ /* Testing on 6 bits */
int i_type = ShowBits( &p_vpar->bit_stream, 6 ); int i_type = ShowBits( &p_vpar->bit_stream, 6 );
/* Dump the good number of bits */ /* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, p_vpar->pl_mb_type[0][i_type].i_length ); DumpBits( &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 the value from the lookup table for P type */
return p_vpar->pl_mb_type[0][i_type].i_value; return p_vpar->ppl_mb_type[0][i_type].i_value;
} }
/***************************************************************************** /*****************************************************************************
...@@ -713,9 +924,9 @@ int vpar_BMBType( vpar_thread_t * p_vpar ) ...@@ -713,9 +924,9 @@ int vpar_BMBType( vpar_thread_t * p_vpar )
/* Testing on 6 bits */ /* Testing on 6 bits */
int i_type = ShowBits( &p_vpar->bit_stream, 6 ); int i_type = ShowBits( &p_vpar->bit_stream, 6 );
/* Dump the good number of bits */ /* Dump the good number of bits */
DumpBits( &p_vpar->bit_stream, p_vpar->pl_mb_type[1][i_type].i_length ); DumpBits( &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 the value from the lookup table for B type */
return p_vpar->pl_mb_type[1][i_type].i_value; return p_vpar->ppl_mb_type[1][i_type].i_value;
} }
/***************************************************************************** /*****************************************************************************
...@@ -735,8 +946,11 @@ int vpar_DMBType( vpar_thread_t * p_vpar ) ...@@ -735,8 +946,11 @@ int vpar_DMBType( vpar_thread_t * p_vpar )
*****************************************************************************/ *****************************************************************************/
int vpar_CodedPattern420( vpar_thread_t * p_vpar ) int vpar_CodedPattern420( vpar_thread_t * p_vpar )
{ {
/* Take the max 9 bits length vlc code for testing */
int i_vlc = ShowBits( &p_vpar->bit_stream, 9 ); 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 ); DumpBits( &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; return p_vpar->pl_coded_pattern[i_vlc].i_value;
} }
...@@ -745,7 +959,14 @@ int vpar_CodedPattern420( vpar_thread_t * p_vpar ) ...@@ -745,7 +959,14 @@ int vpar_CodedPattern420( vpar_thread_t * p_vpar )
*****************************************************************************/ *****************************************************************************/
int vpar_CodedPattern422( vpar_thread_t * p_vpar ) int vpar_CodedPattern422( vpar_thread_t * p_vpar )
{ {
/* pomper dans Berkeley + attention ! y'a 2 bits en plus en MPEG2 */ int i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
/* 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 );
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 */
return p_vpar->pl_coded_pattern[i_vlc].i_value |
(i_coded_block_pattern_1 << 6);
} }
/***************************************************************************** /*****************************************************************************
...@@ -753,7 +974,12 @@ int vpar_CodedPattern422( vpar_thread_t * p_vpar ) ...@@ -753,7 +974,12 @@ int vpar_CodedPattern422( vpar_thread_t * p_vpar )
*****************************************************************************/ *****************************************************************************/
int vpar_CodedPattern444( vpar_thread_t * p_vpar ) int vpar_CodedPattern444( vpar_thread_t * p_vpar )
{ {
/* pomper dans Berkeley + attention ! y'a 4 bits en plus en MPEG2 */ 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 );
i_coded_block_pattern_2 = GetBits( &p_vpar->bit_stream, 6 );
return p_vpar->pl_coded_pattern[i_vlc].i_value |
( i_coded_block_pattern_2 << 6 );
} }
/***************************************************************************** /*****************************************************************************
...@@ -804,34 +1030,115 @@ static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in ...@@ -804,34 +1030,115 @@ static void vpar_DecodeMPEG2Non( vpar_thread_t * p_vpar, macroblock_t * p_mb, in
*****************************************************************************/ *****************************************************************************/
static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb, int i_b ) static void vpar_DecodeMPEG2Intra( vpar_thread_t * p_vpar, macroblock_t * p_mb, int i_b )
{ {
int i_dummy;
int i_nc;
int i_cc;
int i_coef;
int i_type;
int i_code;
int i_code5;
int i_select;
int i_offset;
int i_pos;
int i_dct_dc_size;
int i_dct_dc_diff;
int i_run;
int i_level;
int i_2b;
int i_4b;
boolean_t b_sign;
/* Lookup Table for the chromatic component */ /* Lookup Table for the chromatic component */
static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 }; static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
int i_cc = pi_cc_index[i_b]; /* Lookup table for the offset in the tables for ac coef decoding */
static lookup_t pl_offset_table[8] = { { 12, 4 }, { 8, 4 }, { 6, 8 },
{ 4, 16 }, { 3, 16 }, { 2, 16 },
{ 1, 16 }, { 0, 16 } };
i_cc = pi_cc_index[i_b];
/* Determine whether it is luminance or not (chrominance) */ /* Determine whether it is luminance or not (chrominance) */
int i_type = ( i_cc + 1 ) / 2; i_type = ( i_cc + 1 ) >> 1;
/* Decoding of the DC intra coefficient */ /* Decoding of the DC intra coefficient */
/* The nb of bits to parse depends on i_type */ /* The nb of bits to parse depends on i_type */
int i_code = ShowBits( &p_vpar->bit_stream, 9 + i_type ); i_code = ShowBits( &p_vpar->bit_stream, 9 + i_type );
/* To reduce memory occupation, there are two lookup tables /* To reduce memory occupation, there are two lookup tables
* See InitDCT above */ * See InitDCT above */
int i_code5 = i_code >> 4; i_code5 = i_code >> 4;
/* Shall we lookup in the first or in the second table ? */ /* Shall we lookup in the first or in the second table ? */
int i_select = ( i_code5 - 1 ) / 31; i_select = ( i_code5 - 1 ) / 31;
/* Offset value for looking in the second table */ /* Offset value for looking in the second table */
int i_offset = 0x1f0 + ( i_type * 0x1f0 ); i_offset = 0x1f0 + ( i_type * 0x1f0 );
int i_pos = i_code5 * ( ! i_select ) + i_pos = ( i_code5 * ( ! i_select ) ) + ( ( i_code - i_offset ) * 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;
int i_dct_dc_size;
int i_dct_dc_diff;
i_dct_dc_size = p_vpar->pppl_dct_dc_size[i_select][i_type][i_pos].i_value;
/* Dump the variable length code */ /* Dump the variable length code */
DumpBits( &p_vpar->bit_stream, DumpBits( &p_vpar->bit_stream,
p_vpar->pppl_dct_dc_size[i_select][i_type][i_pos].i_length ); 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 ); 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; 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
/* Decoding of the AC coefficients */ /* Decoding of the AC coefficients */
//int i_dummy = 1; i_coef = 0;
for( i_dummy = 1; i_dummy < 64; i_dummy++ )
{
i_code = ShowBits( &p_vpar->bit_stream, 16 );
i_2b = ! ( i_code >> 14 );
i_4b = ! ( ( i_code & 0x3C00 ) >> 10 );
/* Will contain the number of table to use in ppl_dct_coef */
i_select = i_2b + i_4b + ( i_code & 0x0200 ) + ( i_code & 0x0100 ) +
( i_code & 0x0080 ) + ( i_code & 0x0040 ) +
( i_code & 0x0020 ) + ( i_code & 0x0010 );
/* Shall we use B15 table or not */
i_type = p_vpar->picture.b_intra_vlc_format & ( ( i_select & 3 ) >> 1 );
i_select += (i_type * 7 );
i_offset = ( i_code >> pl_offset_table[i_select].i_value ) -
pl_offset_table[i_select].i_length;
i_run = ( * ( p_vpar->ppl_dct_coef[i_select]
+ ( i_offset * sizeof(dct_lookup_t) ) ) ).i_run;
DumpBits( &p_vpar->bit_stream,
( * ( p_vpar->ppl_dct_coef[i_select]
+ ( i_offset * sizeof(dct_lookup_t) ) ) ).i_length );
switch( i_run )
{
case DCT_ESCAPE:
i_run = GetBits( &p_vpar->bit_stream, 6 );
i_level = GetBits( &p_vpar->bit_stream, 12 );
p_mb->ppi_blocks[i_b][i_dummy] = ( b_sign = ( i_level > 2047 ) )
? ( -4096 + i_level )
: i_level;
i_coef = i_dummy;
i_dummy += i_run;
i_nc ++;
break;
case DCT_EOB:
i_dummy = 64;
break;
default:
i_level = ( * ( p_vpar->ppl_dct_coef[i_select]
+ ( i_offset * sizeof(dct_lookup_t) ) ) ).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 ++;
}
}
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;
}
} }
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