📄 bitstream.cpp
字号:
optional_custom_PCF = getbits (1);
if (optional_custom_PCF)
{
return;
//exit (-1);
}
De_mv_outside_frame = getbits (1);
long_vectors = (De_mv_outside_frame ? 1 : 0);
syntax_arith_coding = getbits (1);
adv_pred_mode = getbits (1);
De_mv_outside_frame = (adv_pred_mode ? 1 : De_mv_outside_frame);
De_overlapping_MC = (adv_pred_mode ? 1 : 0);
De_use_4mv = (adv_pred_mode ? 1 : 0);
pb_frame = 0;
advanced_intra_coding = getbits (1);
deblocking_filter_mode = getbits (1);
De_mv_outside_frame = (deblocking_filter_mode ? 1 : De_mv_outside_frame);
De_use_4mv = (deblocking_filter_mode ? 1 : De_use_4mv);
slice_structured_mode = getbits (1);
if (slice_structured_mode)
{
return;
//exit (-1);
}
reference_picture_selection_mode = getbits (1);
independently_segmented_decoding_mode = getbits (1);
if (independently_segmented_decoding_mode)
{
return;
//exit (-1);
}
alternative_inter_VLC_mode = getbits (1);
modified_quantization_mode = getbits (1);
tmp = getbits (4);
if (tmp != 8)
{ /* OPPTYPE : bit15=1, bit16,bit17,bit18=0 */
return;
//exit (-1);
}
}
if ((UFEP == 1) || (UFEP == 0))
{
if (UFEP == 0)
{
if (scalability_mode >= 3)
{
horizontal_size = De_lines[base_source_format];
vertical_size = De_pels[base_source_format];
mb_width = horizontal_size / 16;
mb_height = vertical_size / 16;
/* Need to store previous (reference layer) values
* for interpolation purposes, as the new values,
* i.e. of the spatially scaled layer, depend on
* the type of spatial scalability in use. */
ref_coded_picture_width = coded_picture_width = horizontal_size;
ref_coded_picture_height = coded_picture_height = vertical_size;
ref_chrom_width = chrom_width = coded_picture_width >> 1;
ref_chrom_height = chrom_height = coded_picture_height >> 1;
source_format = base_source_format;
}
}
/* MMPTYPE */
pict_type = getbits (3);
if (pict_type == PCT_IPB)
pb_frame = IM_PB_FRAMES;
else
pb_frame = 0;
if (PCT_B == pict_type)
{
true_B_frame = ON;
/* Allow motion over picture boundaries, regardless of whether or
* not UMV is turned on. */
De_mv_outside_frame = 1;
De_true_b_trb = temp_ref - prev_non_disposable_temp_ref;
if (De_true_b_trb < 0)
De_true_b_trb += 256;
}
else
{
true_B_frame = OFF;
prev_non_disposable_temp_ref = next_non_disposable_temp_ref;
next_non_disposable_temp_ref = temp_ref;
De_trd = temp_ref - prev_non_disposable_temp_ref;
if (De_trd < 0)
De_trd += 256;
}
reference_picture_resampling_mode = getbits (1);
if (reference_picture_resampling_mode)
{
return;
//exit (-1);
}
reduced_resolution_update_mode = getbits (1);
if (reduced_resolution_update_mode)
{
return;
//exit (-1);
}
De_rtype = getbits (1); /* rounding type */
tmp = getbits (3);
if (tmp != 1)
{ /* MPPTYPE : bit7,bit8=0 bit9=1 */
if (!De_quiet)
return;
//exit (-1);
}
}
else
{
/* UFEP is neither 001 nor 000 */
return;
//exit (-1);
}
tmp = getbits (1);
if (tmp)
{
return;
//exit (-1);
}
if (UFEP && (source_format == SF_CUSTOM))
{
/* Read custom picture format */
CP_PAR_code = getbits (4);
if (CP_PAR_code != PAR_CIF)
{
return;
//exit(-1);
}
tmp=getbits (9);
horizontal_size = (tmp + 1 ) * 4;
tmp = getbits (1);
if (!tmp)
{
return;
//exit (-1);
}
tmp = getbits (9);
vertical_size = tmp * 4;
if ((horizontal_size%16) || (vertical_size%16))
{
return;
//exit (-1);
}
if (CP_PAR_code == EXTENDED_PAR)
{
PAR_width = getbits (8);
PAR_height = getbits (8);
}
}
if (source_format != SF_CUSTOM)
{
horizontal_size = De_lines[source_format];
vertical_size = De_pels[source_format];
}
mb_width = horizontal_size / 16;
mb_height = vertical_size / 16;
/* Need to store previous (reference layer) values
* for interpolation purposes, as the new values,
* i.e. of the spatially scaled layer, depend on
* the type of spatial scalability in use. */
ref_coded_picture_width = coded_picture_width;
coded_picture_width = horizontal_size;
ref_coded_picture_height = coded_picture_height;
coded_picture_height = vertical_size;
ref_chrom_width = chrom_width;
chrom_width = coded_picture_width >> 1;
ref_chrom_height = chrom_height;
chrom_height = coded_picture_height >> 1;
if (optional_custom_PCF)
{
if (UFEP)
{
clock_conversion_code = getbits (1);
clock_divisor = getbits (7);
CP_clock_frequency = (int) (1800 / ((float) clock_divisor * (8 + clock_conversion_code)) * 1000);
}
/* regardless of the value of UFEP */
extended_temporal_reference = getbits (2);
temp_ref = (extended_temporal_reference << 8) + temp_ref;
if (PCT_B == pict_type)
{
De_true_b_trb = temp_ref - prev_non_disposable_temp_ref;
}
else
{
De_trd = temp_ref - prev_non_disposable_temp_ref;
}
if (De_trd < 0)
De_trd += 1024;
}
if (UFEP && long_vectors)
{
if (getbits(1))
{
unlimited_unrestricted_motion_vectors = 0;
}
else
{
flushbits(1);
unlimited_unrestricted_motion_vectors = 1;
}
}
if (UFEP && slice_structured_mode)
{
SSS_rectangular_slices = getbits (1);
SSS_arbitary_slice_ordering = getbits (1);
}
if ((pict_type == PCT_B) || (pict_type == PCT_EI) || (pict_type == PCT_EP))
{
/* optional temporal, SNR and spatial scalability mode in use */
enhancement_layer_num = getbits (4);
if (UFEP)
{
reference_layer_number = getbits (4);
}
if (1 != enhancement_layer_num)
{
if (source_format != base_source_format)
{
if (source_format != SF_CUSTOM)
{
scalability_mode = SPATIAL_SCALABILITY_HV;
}
else if (coded_picture_width != ref_coded_picture_width)
{
scalability_mode = SPATIAL_SCALABILITY_H;
}
else
{
scalability_mode = SPATIAL_SCALABILITY_V;
}
}
else
{
scalability_mode = SNR_SCALABILITY;
}
}
}
else
{
enhancement_layer_num = reference_layer_number = 1;
}
if (reference_picture_selection_mode)
{
if (UFEP)
{
MF_of_reference_picture_selection = getbits (3);
}
TRPI = getbits (1);
if (TRPI)
{
/* temporal reference for prediction exists */
temporal_reference_for_prediction = getbits (10);
}
if (showbits (1))
{
/* backward channel message exists */
/* BCM(backward channel message) is not implemented */
flushbits (1);
return;
//exit (-1);
}
else
{
/* BCM is not present */
BCI = getbits (2);
}
}
if (reference_picture_resampling_mode)
{
/* reading RPRP info is not implemented */
return;
//exit (-1);
}
pic_quant = getbits (5);
quant = pic_quant;
}
else
{
plus_type = 0;
De_rtype = 0;
source_format = tmp;
enhancement_layer_num = reference_layer_number = 1;
horizontal_size = De_lines[source_format];
vertical_size = De_pels[source_format];
mb_width = horizontal_size / 16;
mb_height = vertical_size / 16;
/* Need to store previous (reference layer) values
* for interpolation purposes, as the new values,
* i.e. of the spatially scaled layer, depend on
* the type of spatial scalability in use. */
/* ref_coded_picture_width = coded_picture_width = horizontal_size;
ref_coded_picture_height = coded_picture_height = vertical_size;
ref_chrom_width = chrom_width = coded_picture_width >> 1;
ref_chrom_height = chrom_height = coded_picture_height >> 1;
*/
true_B_frame = OFF;
prev_non_disposable_temp_ref = next_non_disposable_temp_ref;
next_non_disposable_temp_ref = temp_ref;
De_trd = temp_ref - prev_non_disposable_temp_ref;
if (De_trd < 0)
De_trd += 256;
pict_type = getbits (1);
De_mv_outside_frame = getbits (1);
long_vectors = (De_mv_outside_frame ? 1 : 0);
syntax_arith_coding = getbits (1);
adv_pred_mode = getbits (1);
De_mv_outside_frame = (adv_pred_mode ? 1 : De_mv_outside_frame);
De_overlapping_MC = (adv_pred_mode ? 1 : 0);
De_use_4mv = (adv_pred_mode ? 1 : 0);
pb_frame = getbits (1);
pic_quant = getbits (5);
quant = pic_quant;
tmp = getbits (1);
if (tmp)
{
return;
//exit (-1);
}
}
if (pb_frame)
{
if (optional_custom_PCF)
{
De_trb = getbits (5);
}
else
{
De_trb = getbits (3);
}
De_bquant = getbits (2);
}
else
{
De_trb = 0;
}
pei = getbits (1);
pspare:
if (pei)
{
/* extra info for possible future backward compatible additions */
if(source_format = SF_CUSTOM)
{
custwid = getbits (8); /* not used */
horizontal_size = (custwid + 1) << 3;
pei = getbits (1);
if (pei)
{
custhei = getbits(8);
vertical_size = custhei << 3;
}
pei = getbits(1);
if(pei)
goto pspare; /* keep on reading pspare until pei=0 */
}
else
{
getbits(8);
pei = getbits(1);
if(pei)
goto pspare;
}
}
if (verbose > 0)
{
/* $printf("picture header (byte %d)\n",(pos>>3)-4);$ */
if (verbose > 1)
{
/* $printf(" pict_type=%d\n",pict_type); printf("
* source_format=%d\n", source_format); printf("
* quant=%d\n",quant); if (syntax_arith_coding) printf(" SAC coding
* mode used \n"); if (De_mv_outside_frame) printf(" unrestricted
* motion vector mode used\n"); if (adv_pred_mode) printf("
* advanced prediction mode used\n");$ */
}
}
/* Need to store previous (reference layer) values
* for interpolation purposes, as the new values,
* i.e. of the spatially scaled layer, depend on
* the type of spatial scalability in use. */
ref_coded_picture_width = coded_picture_width = horizontal_size;
ref_coded_picture_height = coded_picture_height = vertical_size;
ref_chrom_width = chrom_width = coded_picture_width >> 1;
ref_chrom_height = chrom_height = coded_picture_height >> 1;
*ImageWidth=coded_picture_width;
*ImageHeight=coded_picture_height;
}
/* get the GOB header */
/* author: <guyc@ece.ubc.ca */
void CBitStream::getgobheader()
{
int BCI = 0;
/* GFID is not allowed to change unless PTYPE in picture header
* changes */
gfid = getbits (2);
/* NB: in error-prone environments the decoder can use this
* value to determine whether a picture header where the PTYPE
* has changed, has been lost */
/* we now use it and assume that a picture change is *
* from INTRA to INTER or INTER to INTRA only */
if (gfid != pgfid && newgob)
{
if (pict_type == PCT_INTRA)
pict_type = PCT_INTER;
else if (pict_type == PCT_INTER)
pict_type = PCT_INTRA;
}
quant = getbits (5);
/* Support for Annex N at the GOB level */
if (reference_picture_selection_mode)
{
TRI = getbits (1);
if (TRI)
{
/* Temporal reference of GOB */
temp_ref = optional_custom_PCF?getbits (10):getbits(8);
}
/* Temporal Reference for Prediction indication bit */
TRPI = getbits (1);
if (TRPI)
{
/* temporal reference for prediction exists */
temporal_reference_for_prediction = getbits (10);
}
if (showbits (1))
{
/* backward channel message exists */
/* BCM(backward channel message) is not implemented */
flushbits (1);
return;
//exit (-1);
}
else
{
/* BCM is not present */
BCI = getbits (2);
}
}
pgfid = gfid;
}
//////////////functions in gethdr.c end /////////
//////////////functions in getpic.c start ///////
static int STRENGTH[] = {1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12};
static int STRENGTH1[] = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
static int STRENGTH2[] = {1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
void CBitStream::getpicture (int *framenum, int gob,int *width,int *height)
{
unsigned char *tmp;
int i, store_pb, quality=0;
static int absolute_temp_ref = 0;
static int prev_temp_ref = 0;
int iWidth,iHeight;
iWidth=*width;iHeight=*height;
AT_TRACE1(4,"CBitStream:getPicture width = %d ,height = %d pict_type =%d\n" ,iWidth,iHeight,pict_type);
switch (pict_type)
{
case PCT_INTRA:
case PCT_INTER:
case PCT_PB:
case PCT_IPB:
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB picture\n");
De_enhance_pict = NO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -