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

📄 bitstream.c

📁 xvid解码的精简版本.非常好的版本,节省了分离xvid源代码的过程
💻 C
📖 第 1 页 / 共 3 页
字号:
			if (e->interpolate_mc_q) BitstreamSkip(bs, 8);	/* */			if (e->sadct)		BitstreamSkip(bs, 8);	/* */			if (e->quarterpel)	BitstreamSkip(bs, 8);	/* */		}		if (coding_type == S_VOP && dec->sprite_enable == SPRITE_STATIC) {			if (e->intra_blocks) BitstreamSkip(bs, 8);	/* */			if (e->not_coded_blocks) BitstreamSkip(bs, 8);	/* */			if (e->dct_coefs)	BitstreamSkip(bs, 8);	/* */			if (e->dct_lines)	BitstreamSkip(bs, 8);	/* */			if (e->vlc_symbols)	BitstreamSkip(bs, 8);	/* */			if (e->vlc_bits)	BitstreamSkip(bs, 8);	/* */			if (e->inter_blocks) BitstreamSkip(bs, 8);	/* */			if (e->inter4v_blocks)	BitstreamSkip(bs, 8);	/* */			if (e->apm)			BitstreamSkip(bs, 8);	/* */			if (e->npm)			BitstreamSkip(bs, 8);	/* */			if (e->forw_back_mc_q)	BitstreamSkip(bs, 8);	/* */			if (e->halfpel2)	BitstreamSkip(bs, 8);	/* */			if (e->halfpel4)	BitstreamSkip(bs, 8);	/* */			if (e->interpolate_mc_q) BitstreamSkip(bs, 8);	/* */		}	}}/*decode headersreturns coding_type, or -1 if error*/#define VIDOBJ_START_CODE_MASK		0x0000001f#define VIDOBJLAY_START_CODE_MASK	0x0000000fintBitstreamReadHeaders(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 coding_type;	uint32_t start_code;	uint32_t time_incr = 0;	int32_t time_increment = 0;	int resize = 0;	while ((BitstreamPos(bs) >> 3) + 4 <= bs->length) {		BitstreamByteAlign(bs);		start_code = BitstreamShowBits(bs, 32);		if (start_code == VISOBJSEQ_START_CODE) {			int profile;			DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object_sequence>\n");			BitstreamSkip(bs, 32);	/* visual_object_sequence_start_code */			profile = BitstreamGetBits(bs, 8);	/* profile_and_level_indication */			DPRINTF(XVID_DEBUG_HEADER, "profile_and_level_indication %i\n", profile);		} else if (start_code == VISOBJSEQ_STOP_CODE) {			BitstreamSkip(bs, 32);	/* visual_object_sequence_stop_code */			DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n");		} else if (start_code == VISOBJ_START_CODE) {			int visobj_ver_id;			DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n");			BitstreamSkip(bs, 32);	/* visual_object_start_code */			if (BitstreamGetBit(bs))	/* is_visual_object_identified */			{				visobj_ver_id = BitstreamGetBits(bs, 4);	/* visual_object_ver_id */				DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id);				BitstreamSkip(bs, 3);	/* visual_object_priority */			} else {				visobj_ver_id = 1;			}			if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO)	/* visual_object_type */			{				DPRINTF(XVID_DEBUG_ERROR, "visual_object_type != video\n");				return -1;			}			BitstreamSkip(bs, 4);			/* video_signal_type */			if (BitstreamGetBit(bs))	/* video_signal_type */			{				DPRINTF(XVID_DEBUG_HEADER,"+ video_signal_type\n");				BitstreamSkip(bs, 3);	/* video_format */				BitstreamSkip(bs, 1);	/* video_range */				if (BitstreamGetBit(bs))	/* color_description */				{					DPRINTF(XVID_DEBUG_HEADER,"+ color_description");					BitstreamSkip(bs, 8);	/* color_primaries */					BitstreamSkip(bs, 8);	/* transfer_characteristics */					BitstreamSkip(bs, 8);	/* matrix_coefficients */				}			}		} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) {			DPRINTF(XVID_DEBUG_STARTCODE, "<video_object>\n");			DPRINTF(XVID_DEBUG_HEADER, "vo id %i\n", start_code & VIDOBJ_START_CODE_MASK);			BitstreamSkip(bs, 32);	/* video_object_start_code */		} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) {			DPRINTF(XVID_DEBUG_STARTCODE, "<video_object_layer>\n");			DPRINTF(XVID_DEBUG_HEADER, "vol id %i\n", start_code & VIDOBJLAY_START_CODE_MASK);			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 */			{				DPRINTF(XVID_DEBUG_HEADER, "+ is_object_layer_identifier\n");				vol_ver_id = BitstreamGetBits(bs, 4);	/* video_object_layer_verid */				DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id);				BitstreamSkip(bs, 3);	/* video_object_layer_priority */			} else {				vol_ver_id = 1;			}			dec->aspect_ratio = BitstreamGetBits(bs, 4);			if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR)	/* aspect_ratio_info */			{				DPRINTF(XVID_DEBUG_HEADER, "+ aspect_ratio_info\n");				dec->par_width = BitstreamGetBits(bs, 8);	/* par_width */				dec->par_height = BitstreamGetBits(bs, 8);	/* par_height */			}			if (BitstreamGetBit(bs))	/* vol_control_parameters */			{				DPRINTF(XVID_DEBUG_HEADER, "+ vol_control_parameters\n");				BitstreamSkip(bs, 2);	/* chroma_format */				dec->low_delay = BitstreamGetBit(bs);	/* low_delay */				DPRINTF(XVID_DEBUG_HEADER, "low_delay %i\n", dec->low_delay);				if (BitstreamGetBit(bs))	/* vbv_parameters */				{					unsigned int bitrate;					unsigned int buffer_size;					unsigned int occupancy;					DPRINTF(XVID_DEBUG_HEADER,"+ vbv_parameters\n");					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();					DPRINTF(XVID_DEBUG_HEADER,"bitrate %d (unit=400 bps)\n", bitrate);					DPRINTF(XVID_DEBUG_HEADER,"buffer_size %d (unit=16384 bits)\n", buffer_size);					DPRINTF(XVID_DEBUG_HEADER,"occupancy %d (unit=64 bits)\n", occupancy);				}			}else{				dec->low_delay = dec->low_delay_default;			}			dec->shape = BitstreamGetBits(bs, 2);	/* video_object_layer_shape */			DPRINTF(XVID_DEBUG_HEADER, "shape %i\n", dec->shape);			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 */			DPRINTF(XVID_DEBUG_HEADER,"vop_time_increment_resolution %i\n", dec->time_inc_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 */			{				DPRINTF(XVID_DEBUG_HEADER, "+ fixed_vop_rate\n");				BitstreamSkip(bs, dec->time_inc_bits);	/* fixed_vop_time_increment */			}			if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {				if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) {					uint32_t width, height;					READ_MARKER();					width = BitstreamGetBits(bs, 13);	/* video_object_layer_width */					READ_MARKER();					height = BitstreamGetBits(bs, 13);	/* video_object_layer_height */					READ_MARKER();					DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width);					DPRINTF(XVID_DEBUG_HEADER, "height %i\n", height);					if (dec->width != width || dec->height != height)					{						if (dec->fixed_dimensions)						{							DPRINTF(XVID_DEBUG_ERROR, "decoder width/height does not match bitstream\n");							return -1;						}						resize = 1;						dec->width = width;						dec->height = height;					}				}				dec->interlacing = BitstreamGetBit(bs);				DPRINTF(XVID_DEBUG_HEADER, "interlacing %i\n", dec->interlacing);				if (!BitstreamGetBit(bs))	/* obmc_disable */				{					DPRINTF(XVID_DEBUG_ERROR, "obmc_disabled==false not supported\n");					/* TODO */					/* fucking divx4.02 has this enabled */				}				dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2));	/* sprite_enable */				if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC)				{					int low_latency_sprite_enable;					if (dec->sprite_enable != SPRITE_GMC)					{						int sprite_width;						int sprite_height;						int sprite_left_coord;						int sprite_top_coord;						sprite_width = BitstreamGetBits(bs, 13);		/* sprite_width */						READ_MARKER();						sprite_height = BitstreamGetBits(bs, 13);	/* sprite_height */						READ_MARKER();						sprite_left_coord = BitstreamGetBits(bs, 13);	/* sprite_left_coordinate */						READ_MARKER();						sprite_top_coord = BitstreamGetBits(bs, 13);	/* sprite_top_coordinate */						READ_MARKER();					}					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 */				{					DPRINTF(XVID_DEBUG_HEADER, "not_8_bit==true (ignored)\n");					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 */				DPRINTF(XVID_DEBUG_HEADER, "quant_type %i\n", dec->quant_type);				if (dec->quant_type) {					if (BitstreamGetBit(bs))	/* load_intra_quant_mat */					{						uint8_t matrix[64];						DPRINTF(XVID_DEBUG_HEADER, "load_intra_quant_mat\n");						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];						DPRINTF(XVID_DEBUG_HEADER, "load_inter_quant_mat\n");						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) {						DPRINTF(XVID_DEBUG_ERROR, "greyscale matrix not supported\n");						return -1;					}				}				if (vol_ver_id != 1) {					dec->quarterpel = BitstreamGetBit(bs);	/* quarter_sample */					DPRINTF(XVID_DEBUG_HEADER,"quarterpel %i\n", dec->quarterpel);				}				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);				}

⌨️ 快捷键说明

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