📄 bitstream.c
字号:
BitstreamSkip(bs, 1); /* resync_marker_disable */ if (BitstreamGetBit(bs)) /* data_partitioned */ { DPRINTF(XVID_DEBUG_ERROR, "data_partitioned not supported\n"); BitstreamSkip(bs, 1); /* reversible_vlc */ } if (vol_ver_id != 1) { dec->newpred_enable = BitstreamGetBit(bs); if (dec->newpred_enable) /* newpred_enable */ { DPRINTF(XVID_DEBUG_HEADER, "+ newpred_enable\n"); BitstreamSkip(bs, 2); /* requested_upstream_message_type */ BitstreamSkip(bs, 1); /* newpred_segment_type */ } dec->reduced_resolution_enable = BitstreamGetBit(bs); /* reduced_resolution_vop_enable */ DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution_enable %i\n", dec->reduced_resolution_enable); } else { dec->newpred_enable = 0; dec->reduced_resolution_enable = 0; } dec->scalability = BitstreamGetBit(bs); /* scalability */ if (dec->scalability) { DPRINTF(XVID_DEBUG_ERROR, "scalability not supported\n"); BitstreamSkip(bs, 1); /* hierarchy_type */ BitstreamSkip(bs, 4); /* ref_layer_id */ BitstreamSkip(bs, 1); /* ref_layer_sampling_direc */ BitstreamSkip(bs, 5); /* hor_sampling_factor_n */ BitstreamSkip(bs, 5); /* hor_sampling_factor_m */ BitstreamSkip(bs, 5); /* vert_sampling_factor_n */ BitstreamSkip(bs, 5); /* vert_sampling_factor_m */ BitstreamSkip(bs, 1); /* enhancement_type */ if(dec->shape == VIDOBJLAY_SHAPE_BINARY /* && hierarchy_type==0 */) { BitstreamSkip(bs, 1); /* use_ref_shape */ BitstreamSkip(bs, 1); /* use_ref_texture */ BitstreamSkip(bs, 5); /* shape_hor_sampling_factor_n */ BitstreamSkip(bs, 5); /* shape_hor_sampling_factor_m */ BitstreamSkip(bs, 5); /* shape_vert_sampling_factor_n */ BitstreamSkip(bs, 5); /* shape_vert_sampling_factor_m */ } return -1; } } else /* dec->shape == BINARY_ONLY */ { if (vol_ver_id != 1) { dec->scalability = BitstreamGetBit(bs); /* scalability */ if (dec->scalability) { DPRINTF(XVID_DEBUG_ERROR, "scalability not supported\n"); BitstreamSkip(bs, 4); /* ref_layer_id */ BitstreamSkip(bs, 5); /* hor_sampling_factor_n */ BitstreamSkip(bs, 5); /* hor_sampling_factor_m */ BitstreamSkip(bs, 5); /* vert_sampling_factor_n */ BitstreamSkip(bs, 5); /* vert_sampling_factor_m */ return -1; } } BitstreamSkip(bs, 1); /* resync_marker_disable */ } return (resize ? -3 : -2 ); /* VOL */ } else if (start_code == GRPOFVOP_START_CODE) { DPRINTF(XVID_DEBUG_STARTCODE, "<group_of_vop>\n"); BitstreamSkip(bs, 32); { int hours, minutes, seconds; hours = BitstreamGetBits(bs, 5); minutes = BitstreamGetBits(bs, 6); READ_MARKER(); seconds = BitstreamGetBits(bs, 6); DPRINTF(XVID_DEBUG_HEADER, "time %ih%im%is\n", hours,minutes,seconds); } BitstreamSkip(bs, 1); /* closed_gov */ BitstreamSkip(bs, 1); /* broken_link */ } else if (start_code == VOP_START_CODE) { DPRINTF(XVID_DEBUG_STARTCODE, "<vop>\n"); BitstreamSkip(bs, 32); /* vop_start_code */ coding_type = BitstreamGetBits(bs, 2); /* vop_coding_type */ DPRINTF(XVID_DEBUG_HEADER, "coding_type %i\n", 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 */ } DPRINTF(XVID_DEBUG_HEADER, "time_base %i\n", time_incr); DPRINTF(XVID_DEBUG_HEADER, "time_increment %i\n", time_increment); DPRINTF(XVID_DEBUG_TIMECODE, "%c %i:%i\n", coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : coding_type == B_VOP ? 'B' : 'S', time_incr, 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); } DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", dec->time_pp); DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", dec->time_bp); READ_MARKER(); if (!BitstreamGetBit(bs)) /* vop_coded */ { DPRINTF(XVID_DEBUG_HEADER, "vop_coded==false\n"); 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)); DPRINTF(XVID_DEBUG_HEADER, "vop_id %i\n", vop_id); if (BitstreamGetBit(bs)) /* vop_id_for_prediction_indication */ { vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15)); DPRINTF(XVID_DEBUG_HEADER, "vop_id_for_prediction %i\n", vop_id_for_prediction); } READ_MARKER(); } /* fix a little bug by MinChen <chenm002@163.com> */ 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 */ DPRINTF(XVID_DEBUG_HEADER, "rounding %i\n", *rounding); } 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(); DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width); DPRINTF(XVID_DEBUG_HEADER, "height %i\n", height); DPRINTF(XVID_DEBUG_HEADER, "horiz_mc_ref %i\n", horiz_mc_ref); DPRINTF(XVID_DEBUG_HEADER, "vert_mc_ref %i\n", vert_mc_ref); } 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)]; dec->top_field_first = 0; dec->alternate_vertical_scan = 0; if (dec->interlacing) { dec->top_field_first = BitstreamGetBit(bs); DPRINTF(XVID_DEBUG_HEADER, "interlace top_field_first %i\n", dec->top_field_first); dec->alternate_vertical_scan = BitstreamGetBit(bs); DPRINTF(XVID_DEBUG_HEADER, "interlace alternate_vertical_scan %i\n", dec->alternate_vertical_scan); } } if ((dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable== SPRITE_GMC) && coding_type == S_VOP) { int i; for (i = 0 ; i < dec->sprite_warping_points; i++) { int length; int x = 0, y = 0; /* sprite code borowed from ffmpeg; thx Michael Niedermayer <michaelni@gmx.at> */ length = bs_get_spritetrajectory(bs); if(length){ x= BitstreamGetBits(bs, length); if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/ x = - (x ^ ((1 << length) - 1)); } READ_MARKER(); length = bs_get_spritetrajectory(bs); if(length){ y = BitstreamGetBits(bs, length); if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/ y = - (y ^ ((1 << length) - 1)); } READ_MARKER(); gmc_warp->duv[i].x = x; gmc_warp->duv[i].y = y; DPRINTF(XVID_DEBUG_HEADER,"sprite_warping_point[%i] xy=(%i,%i)\n", i, x, y); } if (dec->sprite_brightness_change) { /* XXX: brightness_change_factor() */ } if (dec->sprite_enable == SPRITE_STATIC) { /* XXX: todo */ } } if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) /* vop_quant */ *quant = 1; DPRINTF(XVID_DEBUG_HEADER, "quant %i\n", *quant); if (coding_type != I_VOP) { *fcode_forward = BitstreamGetBits(bs, 3); /* fcode_forward */ DPRINTF(XVID_DEBUG_HEADER, "fcode_forward %i\n", *fcode_forward); } if (coding_type == B_VOP) { *fcode_backward = BitstreamGetBits(bs, 3); /* fcode_backward */ DPRINTF(XVID_DEBUG_HEADER, "fcode_backward %i\n", *fcode_backward); } if (!dec->scalability) { if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && (coding_type != I_VOP)) { BitstreamSkip(bs, 1); /* vop_shape_coding_type */ } } return coding_type; } else if (start_code == USERDATA_START_CODE) { char tmp[256]; int i, version, build; char packed; BitstreamSkip(bs, 32); /* user_data_start_code */ memset(tmp, 0, 256); tmp[0] = BitstreamShowBits(bs, 8); for(i = 1; i < 256; i++){ tmp[i] = (BitstreamShowBits(bs, 16) & 0xFF); if(tmp[i] == 0) break; BitstreamSkip(bs, 8); } DPRINTF(XVID_DEBUG_STARTCODE, "<user_data>: %s\n", tmp); /* read xvid bitstream version */ if(strncmp(tmp, "XviD", 4) == 0) { if (tmp[strlen(tmp)-1] == 'C') { sscanf(tmp, "XviD%dC", &dec->bs_version); dec->cartoon_mode = 1; } else sscanf(tmp, "XviD%d", &dec->bs_version); DPRINTF(XVID_DEBUG_HEADER, "xvid bitstream version=%i\n", dec->bs_version); } /* divx detection */ i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); if (i < 2) i = sscanf(tmp, "DivX%db%d%c", &version, &build, &packed); if (i >= 2) { dec->packed_mode = (i == 3 && packed == 'p'); DPRINTF(XVID_DEBUG_HEADER, "divx version=%i, build=%i packed=%i\n", version, build, dec->packed_mode); } } else /* start_code == ? */ { if (BitstreamShowBits(bs, 24) == 0x000001) { DPRINTF(XVID_DEBUG_STARTCODE, "<unknown: %x>\n", BitstreamShowBits(bs, 32)); } BitstreamSkip(bs, 8); } }#if 0 DPRINTF("*** WARNING: no vop_start_code found");#endif return -1; /* ignore it */}/* write vol header*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -