📄 bitstream.cpp
字号:
if (0 == UFEP && plus_type)
{
De_mv_outside_frame = De_prev_mv_outside_frame;
deblocking_filter_mode = De_prev_df;
adv_pred_mode = De_prev_adv_pred;
De_overlapping_MC = De_prev_obmc;
De_use_4mv = De_prev_4mv;
long_vectors = De_prev_long_vectors;
syntax_arith_coding = De_prev_sac;
advanced_intra_coding = De_prev_aic;
slice_structured_mode = De_prev_slice_struct;
reference_picture_selection_mode = De_prev_rps;
independently_segmented_decoding_mode = De_prev_isd;
alternative_inter_VLC_mode = De_prev_aivlc;
modified_quantization_mode = De_prev_mq;
}
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB 1\n");
for (i = 0; i < 3; i++)
{
tmp = prev_frame[i];
prev_I_P_frame[i] = prev_frame[i] = next_I_P_frame[i];
next_I_P_frame[i] = current_frame[i] = tmp;
}
/* if the picture header is missing, assume temp_ref increments */
/* not done yet*/
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB 2\n");
/* Annex N: get the correct reference picture for prediction */
if (reference_picture_selection_mode)
{
if (-1 == (quality = get_reference_picture()))
break;
if (quality > 256)
{
stop_decoder = 1;
break;
}
}
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB 3\n");
if ((De_mv_outside_frame) && (*framenum > 0))
{
make_edge_image (prev_I_P_frame[0], edgeframe[0], coded_picture_width,
coded_picture_height, 32);
make_edge_image (prev_I_P_frame[1], edgeframe[1], chrom_width, chrom_height, 16);
make_edge_image (prev_I_P_frame[2], edgeframe[2], chrom_width, chrom_height, 16);
}
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB 4\n");
get_I_P_MBs (*framenum, gob,&iWidth,&iHeight);
*width=iWidth;*height=iHeight;
store_pb = pb_frame;
pb_frame = 0;
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB 5\n");
if (deblocking_filter_mode)
edge_filter (current_frame[0], current_frame[1], current_frame[2],
coded_picture_width, coded_picture_height);
pb_frame = store_pb;
if (pb_frame)
{
if (deblocking_filter_mode)
edge_filter(bframe[0],bframe[1],bframe[2],
coded_picture_width,coded_picture_height);
}
AT_TRACE1(4,"CBitStream::getPicture decode PCT_IPB save picture picture\n");
/***********************Save picture here*************************/
PictureDisplay(&localframenum);
if (reference_picture_selection_mode)
store_picture((pict_type == PCT_INTRA) ? 0 : quality);
if (1 == UFEP)
{
De_prev_mv_outside_frame = De_mv_outside_frame;
De_prev_sac = syntax_arith_coding;
De_prev_adv_pred = adv_pred_mode;
De_prev_aic = advanced_intra_coding;
De_prev_df = deblocking_filter_mode;
De_prev_slice_struct = slice_structured_mode;
De_prev_rps = reference_picture_selection_mode;
De_prev_isd = independently_segmented_decoding_mode;
De_prev_aivlc = alternative_inter_VLC_mode;
De_prev_mq = modified_quantization_mode;
De_prev_long_vectors = long_vectors;
De_prev_obmc = De_overlapping_MC;
De_prev_4mv = De_use_4mv;
}
break;
case PCT_B:
AT_TRACE1(4,"CBitStream::getPicture decode B picture\n");
if (enhancement_layer_num > 1)
De_enhance_pict = YES;
else
De_enhance_pict = NO;
for (i = 0; i < 3; i++)
{
current_frame[i] = bframe[i];
}
/* Forward prediction */
make_edge_image (prev_I_P_frame[0], edgeframe[0], coded_picture_width,
coded_picture_height, 32);
make_edge_image (prev_I_P_frame[1], edgeframe[1], chrom_width, chrom_height, 16);
make_edge_image (prev_I_P_frame[2], edgeframe[2], chrom_width, chrom_height, 16);
/* Backward prediction */
make_edge_image (next_I_P_frame[0], nextedgeframe[0], coded_picture_width,
coded_picture_height, 32);
make_edge_image (next_I_P_frame[1], nextedgeframe[1], chrom_width, chrom_height, 16);
make_edge_image (next_I_P_frame[2], nextedgeframe[2], chrom_width, chrom_height, 16);
get_B_MBs (*framenum,&iWidth,&iHeight);
*width=iWidth;*height=iHeight;
PictureDisplay(&localframenum);
break;
case PCT_EI:
case PCT_EP:
AT_TRACE1(4,"CBitStream::getPicture decode EP picture\n");
De_enhance_pict = YES;
if (!De_enhancement_layer_init[enhancement_layer_num-2])
{
init_enhancement_layer(enhancement_layer_num-2);
De_enhancement_layer_init[enhancement_layer_num-2] = ON;
}
for (i = 0; i < 3; i++)
{
tmp = De_prev_enhancement_frame[enhancement_layer_num-2][i];
De_prev_enhancement_frame[enhancement_layer_num-2][i] =
De_current_enhancement_frame[enhancement_layer_num-2][i];
De_current_enhancement_frame[enhancement_layer_num-2][i] = tmp;
}
if (scalability_mode >= 3)
{
De_UpsampleReferenceLayerPicture();
De_curr_reference_frame[0] = De_upsampled_reference_frame[0];
De_curr_reference_frame[1] = De_upsampled_reference_frame[1];
De_curr_reference_frame[2] = De_upsampled_reference_frame[2];
}
else
{
De_curr_reference_frame[0] = current_frame[0];
De_curr_reference_frame[1] = current_frame[1];
De_curr_reference_frame[2] = current_frame[2];
}
make_edge_image (De_prev_enhancement_frame[enhancement_layer_num-2][0],
De_enhance_edgeframe[enhancement_layer_num-2][0],
coded_picture_width, coded_picture_height, 32);
make_edge_image (De_prev_enhancement_frame[enhancement_layer_num-2][1],
De_enhance_edgeframe[enhancement_layer_num-2][1],
chrom_width, chrom_height, 16);
make_edge_image (De_prev_enhancement_frame[enhancement_layer_num-2][2],
De_enhance_edgeframe[enhancement_layer_num-2][2],
chrom_width, chrom_height, 16);
get_EI_EP_MBs (*framenum,&iWidth,&iHeight);
*width=iWidth;*height=iHeight;
if (deblocking_filter_mode)
edge_filter (De_current_enhancement_frame[enhancement_layer_num-2][0],
De_current_enhancement_frame[enhancement_layer_num-2][1],
De_current_enhancement_frame[enhancement_layer_num-2][2],
coded_picture_width, coded_picture_height);
store_one (enhance_recon_file_name[enhancement_layer_num-2],
De_current_enhancement_frame[enhancement_layer_num-2],
0, coded_picture_width, vertical_size);
break;
default:
AT_TRACE1(4,"CBitStream::getPicture decode break\n");
break;
}
}
/* decode all macroblocks of the current picture */
static int change_of_quant_tab_10[32] = {0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3};
static int change_of_quant_tab_11[32] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, -5};
void CBitStream::get_I_P_MBs (int framenum, int gob,int *width, int *height)
{
AT_TRACE1(4,"CBitStream::get_I_P_MBs (int framenum =%d, int gob=%d,width =%d,height=%d)\n",framenum,gob,*width,*height);
int comp;
int MBA, MBAmax;
int bx, by;
int COD = 0, MCBPC, CBPY, CBP = 0, CBPB = 0, MODB = 0, Mode = 0, DQUANT;
int COD_index, CBPY_index, MODB_index, DQUANT_index, MCBPC_index;
int INTRADC_index, YCBPB_index, UVCBPB_index, mvdbx_index, mvdby_index;
int mvx = 0, mvy = 0, mvy_index, mvx_index, pmv0, pmv1, xpos, ypos, i, k;
int mvdbx = 0, mvdby = 0, pmvdbx, pmvdby, YCBPB, UVCBPB, gobheader_read;
int startmv, stopmv, offset, bsize, last_done = 0, pCBP = 0, pCBPB = 0, pCOD = 0, pMODB = 0;
int DQ_tab[4] = {-1, -2, 1, 2};
short *bp;
int long_vectors_bak;
int tmp = 0;
int pnewgob = 0;
/* Error concealment variables */
int pypos = 0;
int start_mb_row_missing, number_of_mb_rows_missing;
/* variables used in advanced intra coding mode */
int INTRA_AC_DC = 0, INTRA_AC_DC_index;
short *store_qcoeff;
int quality=0;
int decode_last_mb = 0;
int dont_reconstruct_next_mb;
int iWidth,iHeight;
/* number of macroblocks per picture */
MBAmax = mb_width * mb_height;
gob -= 1; /* 1 was added in getheader() */
MBA = 0; /* macroblock address */
newgob = 0;
xpos = ypos = 0;
/* mark De_MV's above the picture */
/* for (i = 1; i < mb_width + 1; i++)
{
for (k = 0; k < 5; k++)
{
De_MV[0][k][0][i] = NO_VEC;
De_MV[1][k][0][i] = NO_VEC;
}
De_modemap[0][i] = MODE_INTRA;
}
*/
for (i = 1; i < mb_width + 1; i++)
{
De_MV[0][0][0][i] = NO_VEC;
De_MV[0][1][0][i] = NO_VEC;
De_MV[0][2][0][i] = NO_VEC;
De_MV[0][3][0][i] = NO_VEC;
De_MV[0][4][0][i] = NO_VEC;
De_MV[1][0][0][i] = NO_VEC;
De_MV[1][1][0][i] = NO_VEC;
De_MV[1][2][0][i] = NO_VEC;
De_MV[1][3][0][i] = NO_VEC;
De_MV[1][4][0][i] = NO_VEC;
//for (k = 0; k < 5; k++)
//{
// De_MV[0][k][0][i] = NO_VEC;
// De_MV[1][k][0][i] = NO_VEC;
//}
De_modemap[0][i] = MODE_INTRA;
}
/* zero De_MV's on the sides of the picture */
for (i = 0; i < mb_height + 1; i++)
{
for (k = 0; k < 5; k++)
{
De_MV[0][k][i][0] = 0;
De_MV[1][k][i][0] = 0;
De_MV[0][k][i][mb_width + 1] = 0;
De_MV[1][k][i][mb_width + 1] = 0;
}
De_modemap[i][0] = MODE_INTRA;
De_modemap[i][mb_width + 1] = MODE_INTRA;
}
AT_TRACE1(4,"CBitStream::get_I_P_MBs 1\n");
/* initialize the qcoeff used in advanced intra coding */
if (advanced_intra_coding)
{
/* store the qcoeff for the frame */
if ((store_qcoeff = (short *) calloc (64 * MBAmax * blk_cnt, sizeof (short))) == 0)
{
return;
//exit (-1);
}
}
fault = 0;
gobheader_read = 0;
/* if a gob with GN != 0 was present as the first gob
* of a picture, decode the rest of the gob header */
AT_TRACE1(4,"CBitStream::get_I_P_MBs 2\n");
if (gob) goto getgobhrd;
AT_TRACE1(4,"CBitStream::get_I_P_MBs 3\n");
for (;;)
{
if (MBA >= MBAmax)
{
/* all macroblocks decoded */
memcpy(De_anchorframemodemap,De_modemap,(sizeof(int)*(MBR+1)*(MBC+2)) );
return;
}
resync:
/* This version of the decoder does not resync on every possible
* error, and it does not do all possible error checks. It is not
* difficult to make it much more error robust, but I do not think it
* is necessary to include this in the freely available version. */
AT_TRACE1(4,"CBitStream::get_I_P_MBs resync\n");
if (fault)
{
startcode (); /* sync on new startcode */
fault = 0;
}
if (!(showbits (22) >> 6))
{
/* startcode */
startcode ();
/* in case of byte aligned start code, ie. PSTUF, GSTUF or ESTUF is
* used */
if (showbits (22) == (32 | SE_CODE))
{
/* end of sequence */
if (!(syntax_arith_coding && MBA < MBAmax))
{
return;
}
}
else if ((showbits (22) == PSC << 5))
{
/* new picture */
/* conceal the last mb row */
if (concealment && MBA < MBAmax)
{
/* store the missing GOB number for error concealment */
AT_TRACE1(4,"CBitStream::get_I_P_MBs resync concealment MBAmax=%d,MBA=%d,mb_width=%d\n",MBAmax,MBA,mb_width);
number_of_mb_rows_missing = (MBAmax - MBA) / mb_width ;
start_mb_row_missing = MBA / mb_width;
decode_last_mb = 1;
pypos = ypos;
}
else if (!(syntax_arith_coding && MBA < MBAmax))
{
return;
}
}
else
{
if (!(syntax_arith_coding && MBA % mb_width))
{
if (syntax_arith_coding)
{
/* SAC hack to finish GOBs which end with MBs coded with no
* bits. */
gob = (showbits (22) & 31);
if (gob * mb_width != MBA)
goto finish_gob;
}
gob = getheader (&iWidth, &iHeight) - 1;
*width=iWidth; *height=iHeight;
if (gob > mb_height)
{
return;
}
/* Get the remaining of the GOB header:
this should be the complete gob header to facilitate the integration
of the slice structure and the syntax of Annex N and the BCM.
This will be changed when Slices are implemented */
/* if the first sync of a picture in not GN 0, start here */
getgobhrd:
getgobheader();
/* Get the reference picture for prediction corresponding to TRP
in the GOB header. Only the reference GOB is needed, but it is
simpler to get the whole reference picture.
This should be changed to save time */
if (reference_picture_selection_mode)
{
if (-1 == (quality = get_reference_picture()))
break;
if (quality > 256)
{
stop_decoder = 1;
break;
}
if ((De_mv_outside_frame) && (framenum > 0))
{
make_edge_image (prev_I_P_frame[0], edgeframe[0], coded_picture_width,
coded_picture_height, 32);
make_edge_image (prev_I_P_frame[1], edgeframe[1], chrom_width, chrom_height, 16);
make_edge_image (prev_I_P_frame[2], edgeframe[2], chrom_width, chrom_height, 16);
}
}
/* if some data is loss due to (channel) errors,
* decode the last (delayed) macroblock */
if (concealment && (gob * mb_width != MBA))
{
/* if we are missing the last gob of the previous frame and
* the first gob of the current frame, framenum should be
* incremented */
/* store the missing GOB number for error concealment */
if (gob - MBA / mb_width < 0)
{
++framenum;
number_of_mb_rows_missing = (MBAmax - MBA) / mb_width ;
}
else
number_of_mb_rows_missing = gob - MBA / mb_width ;
start_mb_row_missing = MBA / mb_width;
decode_last_mb = 1;
pypos = ypos;
}
xpos = 0;
ypos = gob;
MBA = ypos * mb_width;
newgob = 1;
gobheader_read = 1;
if (syntax_arith_coding)
decoder_reset (); /* init. arithmetic decoder buffer after
* gob */
}
}
}
if (decode_last_mb)
{
if (!start_mb_row_missing)
{
/* the first gob is missing, we don't need to decode the last MB */
goto conceal_gob;
}
else
{
xpos = 0;
ypos = ++pypos;
COD = 1;
goto reconstruct_mb;
}
}
dont_reconstruct_next_mb = 0;
finish_gob:
/* SAC specific label */
if (!gobheader_read)
{
xpos = MBA % mb_width;
ypos = MBA / mb_width;
if (xpos == 0 && ypos > 0)
newgob = 0;
}
else
{
gobheader_read = 0;
}
read_cod:
AT_TRACE1(4,"CBitStream::get_I_P_MBs read_cod\n");
if (syntax_arith_coding)
{
if (pict_type == PCT_INTER || pict_type == PCT_IPB)
{
COD_index = decode_a_symbol (De_cumf_COD);
COD = De_codtab[COD_index];
}
else
{
COD = 0; /* COD not used in I-pictures, set to zero */
coded_map[ypos + 1][xpos + 1] = 1;
}
}
else
{
if (PCT_INTER == pict_type || PCT_IPB == pict_type)
{
COD = showbits (1);
}
else
{
COD = 0; /* Intra picture -> not skipped */
coded_map[ypos + 1][xpos + 1] = 1;
}
}
if (!COD)
{
/* COD == 0 --> not skipped */
if (syntax_arith_coding)
{
if (pict_type == PCT_INTER || pict_type == PCT_IPB)
{
if (plus_type)
{
MCBPC_index = decode_a_symbol (De_cumf_MCBPC_4MVQ);
MCBPC = De_mcbpctab_4mvq[MCBPC_index];
}
else
{
MCBPC_index = decode_a_symbol (De_cumf_MCBPC_no4MVQ);
MCBPC = De_mcbpctab[MCBPC_index];
}
}
else
{
MCBPC_index = decode_a_symbol (De_cumf_MCBPC_intra);
MCBPC = De_mcbpc_intratab[MCBPC_index];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -