⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macroblock1.c

📁 另一个版本的x264的decoder
💻 C
📖 第 1 页 / 共 5 页
字号:
	if( h->mb.i_cbp_chroma &0x03 )    /* Chroma DC residual present */		{				//printf(" \nbefore_dc 0 chroma %d  %d",h->cabac.s->i_left,*s->p);		block_residual_read_cabac( h, 3, 0, h->dct.chroma_dc[0], 4 );	//	printf(" \nbefore_dc 1 chroma %d  %d",h->cabac.s->i_left,*s->p);		block_residual_read_cabac( h, 3, 1, h->dct.chroma_dc[1], 4 );				//	printf(" \nafter_dc 1 chroma %d  %d",h->cabac.s->i_left,*s->p);		if( array_non_zero_count( h->dct.chroma_dc[0], 4 ) > 0 )			i_cbp_dc |= 0x02;		if( array_non_zero_count( h->dct.chroma_dc[1], 4 ) > 0 )			i_cbp_dc |= 0x04;						}	else		{		for ( j=0; j < 2; j++)			{						//array_zero_set( h->dct.chroma_dc[j], 4 );						}		}	/* store cbp for CABAC */	h->mb.cbp[h->mb.i_mb_xy] = (i_cbp_dc << 8) | (h->mb.i_cbp_chroma << 4) | h->mb.i_cbp_luma;	for( i = 0; i < 8; i++ )		{		if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */			{		//	printf("\n");			//array_zero_set( h->dct.block[16+i].residual_ac, 15 );		//	printf(" \nbefore_ac chroma %d  %d  %d",h->cabac.s->i_left,*s->p,i);			block_residual_read_cabac( h, 4, i, h->dct.block[16+i].residual_ac, 15 );		//	printf(" \nafter_ac chroma %d  %d %d",h->cabac.s->i_left,*s->p,i);			//h->dct.block[16+i].luma4x4[0] = h->dct.chroma_dc[i>>2][i&0x03];			}		else			{			h->mb.cache.non_zero_count[x264_scan8[16+i]] = 0;			//array_zero_set( h->dct.block[16+i].residual_ac, 15 );			}		}	}	else		{		h->mb.i_qp = h->pps->i_pic_init_qp + h->sh.i_qp_delta;		for( i = 0; i < 16; i++ )			{			//h->mb.block[i].i_non_zero_count = 0;			h->mb.cache.non_zero_count[x264_scan8[i]] = 0;			//array_zero_set( h->dct.block[i].luma4x4, 16 );			}		//array_zero_set( h->dct.chroma_dc[0], 4 );		//array_zero_set( h->dct.chroma_dc[1], 4 );		for( i = 0; i < 8; i++ )			{		//	array_zero_set( h->dct.block[16+i].residual_ac, 15 );			//h->mb.block[16+i].i_non_zero_count = 0;			h->mb.cache.non_zero_count[x264_scan8[16+i]] = 0;			}				/* store cbp for CABAC */		h->mb.cbp[h->mb.i_mb_xy] = (i_cbp_dc << 8) | (h->mb.i_cbp_chroma << 4) | h->mb.i_cbp_luma;		}				     //fprintf( stderr, "mb read type=%d\n", h->mb.i_type );    return 0;}static int bs_read_vlc( bs_t *s, x264_vlc_table_t *table ){    int i_nb_bits;    int i_value = 0;    int i_bits;    int i_index;    int i_level = 0;    i_index = bs_show( s, table->i_lookup_bits );    if( i_index >= table->i_lookup )    {        return( -1 );    }    i_value = table->lookup[i_index].i_value;    i_bits  = table->lookup[i_index].i_size;    while( i_bits < 0 )    {        i_level++;        if( i_level > 5 )        {            return( -1 );        // FIXME what to do ?        }        bs_skip( s, table->i_lookup_bits );        i_nb_bits = -i_bits;        i_index = bs_show( s, i_nb_bits ) + i_value;        if( i_index >= table->i_lookup )        {            return( -1 );        }        i_value = table->lookup[i_index].i_value;        i_bits  = table->lookup[i_index].i_size;    }    bs_skip( s, i_bits );    return( i_value );}static int block_residual_read_cavlc( x264_t *h, bs_t *s,                                      int i_idx, int *l, int i_count ){    int i;    int level[16], run[16];    int i_coeff;    int i_total, i_trailing;    int i_suffix_length;    int i_zero_left;    for( i = 0; i < i_count; i++ )    {        l[i] = 0;    }    /* total/trailing */    if( i_idx == BLOCK_INDEX_CHROMA_DC )    {        int i_tt;        if( ( i_tt = bs_read_vlc( s, h->x264_coeff_token_lookup[4] )) < 0 )        {            return -1;        }        i_total = i_tt / 4;        i_trailing = i_tt % 4;    }    else    {        /* x264_mb_predict_non_zero_code return 0 <-> (16+16+1)>>1 = 16 */        static const int ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3 };        int nC;        int i_tt;        if( i_idx == BLOCK_INDEX_LUMA_DC )        {            nC = x264_mb_predict_non_zero_code( h, 0 );        }        else        {            nC = x264_mb_predict_non_zero_code( h, i_idx );        }        if( ( i_tt = bs_read_vlc( s, h->x264_coeff_token_lookup[ct_index[nC]] ) ) < 0 )        {            return -1;        }        i_total = i_tt / 4;        i_trailing = i_tt % 4;    }    if( i_idx >= 0 )    {		h->mb.cache.non_zero_count[x264_scan8[i_idx]] = i_total;    }    if( i_total <= 0 )    {        return 0;    }    i_suffix_length = i_total > 10 && i_trailing < 3 ? 1 : 0;    for( i = 0; i < i_trailing; i++ )    {        level[i] = 1 - 2 * bs_read1( s );    }    for( ; i < i_total; i++ )    {        int i_prefix;        int i_level_code;        i_prefix = bs_read_vlc( s, h->x264_level_prefix_lookup );        if( i_prefix == -1 )        {            return -1;        }        else if( i_prefix < 14 )        {            if( i_suffix_length > 0 )            {                i_level_code = (i_prefix << i_suffix_length) + bs_read( s, i_suffix_length );            }            else            {                i_level_code = i_prefix;            }        }        else if( i_prefix == 14 )        {            if( i_suffix_length > 0 )            {                i_level_code = (i_prefix << i_suffix_length) + bs_read( s, i_suffix_length );            }            else            {                i_level_code = i_prefix + bs_read( s, 4 );            }        }        else /* if( i_prefix == 15 ) */        {            i_level_code = (i_prefix << i_suffix_length) + bs_read( s, 12 );            if( i_suffix_length == 0 )            {                i_level_code += 15;            }        }        if( i == i_trailing && i_trailing < 3 )        {            i_level_code += 2;        }        /* Optimise */        level[i] = i_level_code&0x01 ? -((i_level_code+1)/2) : (i_level_code+2)/2;        if( i_suffix_length == 0 )        {            i_suffix_length++;        }        if( abs( level[i] ) > ( 3 << ( i_suffix_length - 1 ) ) && i_suffix_length < 6 )        {            i_suffix_length++;        }    }    if( i_total < i_count )    {        if( i_idx == BLOCK_INDEX_CHROMA_DC )        {            i_zero_left = bs_read_vlc( s, h->x264_total_zeros_dc_lookup[i_total-1] );        }        else        {            i_zero_left = bs_read_vlc( s, h->x264_total_zeros_lookup[i_total-1] );        }        if( i_zero_left < 0 )        {            return -1;        }    }    else    {        i_zero_left = 0;    }    for( i = 0; i < i_total - 1; i++ )    {        if( i_zero_left <= 0 )        {            break;        }        run[i] = bs_read_vlc( s, h->x264_run_before_lookup[X264_MIN( i_zero_left - 1, 6 )] );        if( run[i] < 0 )        {            return -1;        }        i_zero_left -= run[i];    }    if( i_zero_left < 0 )    {        return -1;    }    for( ; i < i_total - 1; i++ )    {        run[i] = 0;    }    run[i_total-1] = i_zero_left;    i_coeff = -1;    for( i = i_total - 1; i >= 0; i-- )    {        i_coeff += run[i] + 1;        l[i_coeff] = level[i];    }    return 0;}int x264_macroblock_read_cavlc( x264_t *h, bs_t *s ){    int i_mb_i_offset;    int i_mb_p_offset;    int b_sub_ref0 = 0;    int i_type;    int i;#ifdef PROFILE    int64_t count;	h->type_cycles = 0;	h->residual_cycles = 0;	count = x264_get_ts();#endif    /* read the mb type */    switch( h->sh.i_type )    {        case SLICE_TYPE_I:            i_mb_p_offset = 0;  /* shut up gcc */            i_mb_i_offset = 0;            break;        case SLICE_TYPE_P:            i_mb_p_offset = 0;            i_mb_i_offset = 5;            break;        case SLICE_TYPE_B:            i_mb_p_offset = 23;            i_mb_i_offset = 23;// + 5;            break;        default:            fprintf( stderr, "internal error or slice unsupported\n" );            return -1;    }    i_type = bs_read_ue( s );	//x264_log(h, X264_LOG_DEBUG, "mb_type %d\n", i_type );	//printf("mb_type %d\n", i_type );    if( i_type < i_mb_i_offset )    {        if( i_type < i_mb_p_offset )        {			h->mb.i_partition = x264_b_mb_type_info[i_type].partition;            h->mb.i_type =      x264_b_mb_type_info[i_type].type;			// for ffmpeg code			h->mb.i_partition_count = b_mb_type_info[i_type].partition_count;            h->mb.i_mb_type =         b_mb_type_info[i_type].type;        }        else        {            i_type -= i_mb_p_offset;			h->mb.i_partition = x264_p_mb_type_info[i_type].partition;            h->mb.i_type =      x264_p_mb_type_info[i_type].type;			b_sub_ref0 = i_type == 4 ? 1 : 0;			// for ffmpeg code			h->mb.i_partition_count = p_mb_type_info[i_type].partition_count;            h->mb.i_mb_type =         p_mb_type_info[i_type].type;					        }    }    else    {        i_type -= i_mb_i_offset;        if( i_type == 0 )        {            h->mb.i_type = I_4x4;        }        else if( i_type < 25 )        {            h->mb.i_type = I_16x16;            h->mb.i_intra16x16_pred_mode = (i_type - 1)%4;            h->mb.i_cbp_chroma = ( (i_type-1) / 4 )%3;            h->mb.i_cbp_luma   = ((i_type-1) / 12) ? 0x0f : 0x00;        }        else if( i_type == 25 )        {            h->mb.i_type = I_PCM;        }        else        {            fprintf( stderr, "invalid mb type (%d)\n", i_type );            return -1;        }    }    if( h->mb.i_type == I_PCM )    {        return x264_macroblock_decode_ipcm( h, s );    }    if( IS_INTRA( h->mb.i_type ) )    {        if( h->mb.i_type == I_4x4 )        {            for( i = 0; i < 16; i++ )            {				                int b_coded;				int i_predicted_mode;				int i_mode;                b_coded = bs_read1( s );				i_predicted_mode = x264_mb_predict_intra4x4_mode( h, i );                if( b_coded )                {                    i_mode = i_predicted_mode;					                }                else                {                                        int rem_mode = bs_read( s, 3 );                    if( rem_mode >= i_predicted_mode )                    {                        i_mode = rem_mode + 1;                    }                    else                    {                        i_mode = rem_mode;                    }                }				//x264_log(h, X264_LOG_DEBUG, "coded %d predicted_mode %d i_mode %d\n", b_coded,i_predicted_mode,i_mode);				//printf("coded %d predicted_mode %d i_mode %d\n", b_coded,i_predicted_mode,i_mode);				h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = i_mode;            }        }        h->mb.i_chroma_pred_mode = bs_read_ue( s );		getchar();    }    else if( h->mb.i_type == P_8x8 || h->mb.i_type == B_8x8)    {				int sub_partition_count[4], list;		int ref_count[2];		ref_count[0] = h->sh.i_num_ref_idx_l0_active - 1;		ref_count[1] = h->sh.i_num_ref_idx_l1_active - 1;		if(h->sh.i_type == SLICE_TYPE_B)		{			for( i = 0; i < 4; i++ )			{				int i_sub_partition;				i_sub_partition = bs_read_ue( s );				h->mb.i_sub_partition[i] = x264_b_sub_mb_type_info[i_sub_partition].partition;				// for ffmpeg code				sub_partition_count[i] = b_sub_mb_type_info[i_sub_partition].partition_count;				h->mb.i_sub_mb_type[i] = b_sub_mb_type_info[i_sub_partition].type;			}			/* direct mode not work for 8x8 */			if( FF_IS_DIRECT(h->mb.i_sub_mb_type[0]) || FF_IS_DIRECT(h->mb.i_sub_mb_type[1])               || FF_IS_DIRECT(h->mb.i_sub_mb_type[2]) || FF_IS_DIRECT(h->mb.i_sub_mb_type[3]) ) 			{				x264_mb_predict_mv_direct( h );			}		}		else 		{			for( i = 0; i < 4; i++ )			{				int i_sub_partition;				i_sub_partition = bs_read_ue( s );				h->mb.i_sub_partition[i] = x264_p_sub_mb_type_info[i_sub_partition].partition;				// for ffmpeg code				sub_partition_count[i] = p_sub_mb_type_info[i_sub_partition].partition_count;				h->mb.i_sub_mb_type[i] = p_sub_mb_type_info[i_sub_partition].type;						}		}        		for(list = 0; list < 2; list++)		{						//if(ref_count == 0) continue;			for( i = 0; i < 4; i++ )			{				int i_ref;				if(FF_IS_DIRECT(h->mb.i_sub_mb_type[i])) 				{					//FIXME: need update ref_cache?					continue;				}				if (b_sub_ref0)				{					i_ref = 0;				}				else if (FF_IS_DIR(h->mb.i_sub_mb_type[i], 0, list))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -