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

📄 mvvolvop.c

📁 优化过的xvid1.1.2源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "MVCommon.h"
#include "MVVolVop.h"
#include "MVBitstream.h"
#include "MVMb.h"
#include "MVVolVop.h"
#include "MVImage.h"
#include "MVMv.h"
#include "MVMc.h"

extern const uint32_t intra_dc_threshold_table[8];
extern const int32_t dquant_table[4];
//extern const uint32_t roundtab_79[4];
//extern const uint32_t roundtab_76[16];


int mavrix_read_vol(Bitstream * bs,
					 DECODER * dec,
					 uint32_t * rounding,
					 uint32_t * quant,
					 uint32_t * fcode_forward,
					 uint32_t * fcode_backward,
					 uint32_t * intra_dc_threshold,
					 WARPPOINTS *gmc_warp)
{
	uint32_t vol_ver_id;
	uint32_t time_incr = 0;
	int32_t time_increment = 0;
	uint32_t width, height;
	int resize = 0;
    int obmc;

    //if(mavrix_fine_start_code(bs)!= VIDOBJLAY_START_CODE)
	//   	return 0;

	//BitstreamSkip(bs, 32);	/* video_object_layer_start_code */
       BitstreamSkip(bs, 1);	/* random_accessible_vol */

       BitstreamSkip(bs, 8);   /* video_object_type_indication */

      if (BitstreamGetBit(bs))	/* is_object_layer_identifier */
	{
		vol_ver_id = BitstreamGetBits(bs, 4);	/* video_object_layer_verid */
		BitstreamSkip(bs, 3);	/* video_object_layer_priority */
	}
	else
	{
		vol_ver_id = dec->ver_id;
	}

	dec->aspect_ratio = BitstreamGetBits(bs, 4);
	if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR)	/* aspect_ratio_info */
	{
		dec->par_width = BitstreamGetBits(bs, 8);	/* par_width */
		dec->par_height = BitstreamGetBits(bs, 8);	/* par_height */
	}

	if (BitstreamGetBit(bs))	/* vol_control_parameters */
	{
		BitstreamSkip(bs, 2);	/* chroma_format */
		dec->low_delay = BitstreamGetBit(bs);	/* low_delay */
		if (BitstreamGetBit(bs))	/* vbv_parameters */
		{
			unsigned int bitrate;
			unsigned int buffer_size;
			unsigned int occupancy;

			bitrate = BitstreamGetBits(bs,15) << 15;	/* first_half_bit_rate */
			READ_MARKER();
			bitrate |= BitstreamGetBits(bs,15);		/* latter_half_bit_rate */
			READ_MARKER();

			buffer_size = BitstreamGetBits(bs, 15) << 3;	/* first_half_vbv_buffer_size */
			READ_MARKER();
			buffer_size |= BitstreamGetBits(bs, 3);		/* latter_half_vbv_buffer_size */

			occupancy = BitstreamGetBits(bs, 11) << 15;	/* first_half_vbv_occupancy */
			READ_MARKER();
			occupancy |= BitstreamGetBits(bs, 15);	/* latter_half_vbv_occupancy */
			READ_MARKER();

		}
	}
	else
	{
		dec->low_delay = dec->low_delay_default;
	}

	dec->shape = BitstreamGetBits(bs, 2);	/* video_object_layer_shape */

       /*wuhaibin 200701-12
	if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
	{
	      DPRINTF(XVID_DEBUG_ERROR,"non-rectangular shapes are not supported\n");
	}

	if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1)
	{
	     BitstreamSkip(bs, 4);	// video_object_layer_shape_extension 
       }*/

	READ_MARKER();

	/********************** for decode B-frame time ***********************/
	dec->time_inc_resolution = BitstreamGetBits(bs, 16);	/* vop_time_increment_resolution */
	if (dec->time_inc_resolution > 0)
	{
		dec->time_inc_bits = MAX(log2bin(dec->time_inc_resolution-1), 1);
	}
	else
	{
		/* for "old" xvid compatibility, set time_inc_bits = 1 */
		dec->time_inc_bits = 1;
	}

	READ_MARKER();

	if (BitstreamGetBit(bs))	/* fixed_vop_rate */
	{
		BitstreamSkip(bs, dec->time_inc_bits);	/* fixed_vop_time_increment */
	}

	//if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) //must 1
	//{
	//if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)//must 1
	//{


	READ_MARKER();
	width = BitstreamGetBits(bs, 13);	/* video_object_layer_width */
	READ_MARKER();
	height = BitstreamGetBits(bs, 13);	/* video_object_layer_height */
	READ_MARKER();

	if (dec->width != width || dec->height != height)
	{
		if (dec->fixed_dimensions)
		{
			return 0;
		}
		resize = 1;
		dec->width = width;
		dec->height = height;
	}

	dec->interlacing = BitstreamGetBit(bs); 

	obmc = BitstreamGetBit(bs);	/* obmc_disable */

	dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2));	/* sprite_enable */

	 if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC)
	{

		/*if (dec->sprite_enable != SPRITE_GMC)
		{
			
		}*/
		dec->sprite_warping_points = BitstreamGetBits(bs, 6);		/* no_of_sprite_warping_points */
		dec->sprite_warping_accuracy = BitstreamGetBits(bs, 2);		/* sprite_warping_accuracy */
		dec->sprite_brightness_change = BitstreamGetBits(bs, 1);		/* brightness_change */
		/*if (dec->sprite_enable != SPRITE_GMC)
		{
			low_latency_sprite_enable = BitstreamGetBits(bs, 1);		// low_latency_sprite_enable /
		}*/
	 }

	 /*if (vol_ver_id != 1 &&
		dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
	{
				BitstreamSkip(bs, 1);	// sadct_disable /
	}*/

	if (BitstreamGetBit(bs))	/* not_8_bit */
	{
		dec->quant_bits = BitstreamGetBits(bs, 4);	/* quant_precision */
		BitstreamSkip(bs, 4);	/* bits_per_pixel */
	}
	else
	{
		dec->quant_bits = 5;
	}

	/*if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) 
	{
					BitstreamSkip(bs, 1);	// no_gray_quant_update 
					BitstreamSkip(bs, 1);	// composition_method 
					BitstreamSkip(bs, 1);	// linear_composition 
	}*/

	dec->quant_type = BitstreamGetBit(bs);	/* quant_type */
	if (dec->quant_type)
	{
		if (BitstreamGetBit(bs))	/* load_intra_quant_mat */
		{
			uint8_t matrix[64];

	        	bs_get_matrix(bs, matrix);
			set_intra_matrix(dec->mpeg_quant_matrices, matrix);
		} 
		else
			set_intra_matrix(dec->mpeg_quant_matrices, get_default_intra_matrix());

		if (BitstreamGetBit(bs))	/* load_inter_quant_mat */
		{
			uint8_t matrix[64];

			bs_get_matrix(bs, matrix);
			set_inter_matrix(dec->mpeg_quant_matrices, matrix);
		} 
		else
			set_inter_matrix(dec->mpeg_quant_matrices, get_default_inter_matrix());

		/*if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) 
		{
		     return -1;
		}*/

	}                
              
	if (vol_ver_id != 1) 
	{
		dec->quarterpel = BitstreamGetBit(bs);	/* quarter_sample */
	}
	else
		dec->quarterpel = 0;

        dec->complexity_estimation_disable = BitstreamGetBit(bs);	/* complexity estimation disable */
	/*if (!dec->complexity_estimation_disable)
	{
			read_vol_complexity_estimation_header(bs, dec);
	}*/

	BitstreamSkip(bs, 1);	/* resync_marker_disable */
	if (BitstreamGetBit(bs))	/* data_partitioned */
	{
		BitstreamSkip(bs, 1);	/* reversible_vlc */
	}

	if (vol_ver_id != 1)
	{
		dec->newpred_enable = BitstreamGetBit(bs);
		if (dec->newpred_enable)	/* newpred_enable */
		{
        		BitstreamSkip(bs, 2);	/* requested_upstream_message_type */
			BitstreamSkip(bs, 1);	/* newpred_segment_type */
		}
		dec->reduced_resolution_enable = BitstreamGetBit(bs);	/* reduced_resolution_vop_enable */
	}
	else
	{
		dec->newpred_enable = 0;
		dec->reduced_resolution_enable = 0;
	}

	dec->scalability = BitstreamGetBit(bs);	/* scalability */

	return 1;	/* VOL */
}

int mavtrix_read_vop(Bitstream * bs,
			 DECODER * dec,
			 uint32_t * rounding,
			 uint32_t * quant,
			 uint32_t * fcode_forward,
			 uint32_t * fcode_backward,
			 uint32_t * intra_dc_threshold,
			 WARPPOINTS *gmc_warp)
{
	uint32_t coding_type;
	uint32_t time_incr = 0;
	int32_t time_increment = 0;
	int resize = 0;
	
       //if(mavrix_fine_start_code(bs)!= VOP_START_CODE)
	   //	return 0;
	   	
	//BitstreamSkip(bs, 32);	/* vop_start_code */

	coding_type = BitstreamGetBits(bs, 2);	/* vop_coding_type */

	/*********************** for decode B-frame time ***********************/
	while (BitstreamGetBit(bs) != 0)	/* time_base */
				time_incr++;

	READ_MARKER();

	if (dec->time_inc_bits)
	{
		time_increment = (BitstreamGetBits(bs, dec->time_inc_bits));	/* vop_time_increment */
	}

	if (coding_type != B_VOP)
	{
		dec->last_time_base = dec->time_base;
		dec->time_base += time_incr;
		dec->time = dec->time_base*dec->time_inc_resolution + time_increment;
		dec->time_pp = (int32_t)(dec->time - dec->last_non_b_time);
		dec->last_non_b_time = dec->time;
	}
	else
	{
		dec->time = (dec->last_time_base + time_incr)*dec->time_inc_resolution + time_increment;
		dec->time_bp = dec->time_pp - (int32_t)(dec->last_non_b_time - dec->time);
	}

	READ_MARKER();

	if (!BitstreamGetBit(bs))	/* vop_coded */
	{
		return N_VOP;
	}

	/*if (dec->newpred_enable)
	{
		int vop_id;
		int vop_id_for_prediction;

		vop_id = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));

		if (BitstreamGetBit(bs))	// vop_id_for_prediction_indication 
		{
			vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15));
		
		}
		READ_MARKER();
	}
       */
       
	if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
		( (coding_type == P_VOP) || (coding_type == S_VOP && dec->sprite_enable == SPRITE_GMC) ) ) 
	{
		*rounding = BitstreamGetBit(bs);	/* rounding_type */
	}

	/*if (dec->reduced_resolution_enable &&
           dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR &&
	     (coding_type == P_VOP || coding_type == I_VOP))
      {

	     if (BitstreamGetBit(bs));
					DPRINTF(XVID_DEBUG_ERROR, "RRV not supported (anymore)\n");
       }

	if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) 
	{
	    if(!(dec->sprite_enable == SPRITE_STATIC && coding_type == I_VOP))
	    {
			uint32_t width, height;
			uint32_t horiz_mc_ref, vert_mc_ref;

			width = BitstreamGetBits(bs, 13);
			READ_MARKER();
			height = BitstreamGetBits(bs, 13);
			READ_MARKER();
			horiz_mc_ref = BitstreamGetBits(bs, 13);
			READ_MARKER();
			vert_mc_ref = BitstreamGetBits(bs, 13);
			READ_MARKER();

          }

	   BitstreamSkip(bs, 1);	/// change_conv_ratio_disable 
	   if (BitstreamGetBit(bs))	// vop_constant_alpha 
	   {
			BitstreamSkip(bs, 8);	// vop_constant_alpha_value 
	   }
     }*/

     if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
     {

		if (!dec->complexity_estimation_disable)
		{
			//read_vop_complexity_estimation_header(bs, dec, coding_type);
		}

				/* intra_dc_vlc_threshold */
		*intra_dc_threshold =
			intra_dc_threshold_table[BitstreamGetBits(bs, 3)];

⌨️ 快捷键说明

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