📄 macroblock.c
字号:
{
currMB->mb_type = I4MB;
for (i=0;i<4;i++) {currMB->b8mode[i]=IBLOCK; currMB->b8pdir[i]=-1; }
}
else if(mbmode==26)
{
currMB->mb_type=IPCM;
for (i=0;i<4;i++) {currMB->b8mode[i]=0; currMB->b8pdir[i]=-1; }
currMB->cbp= -1;
currMB->i16mode = 0;
}
else
{
currMB->mb_type = I16MB;
for (i=0;i<4;i++) {currMB->b8mode[i]=0; currMB->b8pdir[i]=-1; }
currMB->cbp= ICBPTAB[(mbmode-1)>>2];
currMB->i16mode = (mbmode-2) & 0x03;
}
}
/*!
************************************************************************
* \brief
* init macroblock I and P frames
************************************************************************
*/
void init_macroblock(struct img_par *img)
{
int i,j;
for (i=0;i<BLOCK_SIZE;i++)
{ // reset vectors and pred. modes
for(j=0;j<BLOCK_SIZE;j++)
{
dec_picture->mv[LIST_0][img->block_x+i][img->block_y+j][0]=0;
dec_picture->mv[LIST_0][img->block_x+i][img->block_y+j][1]=0;
dec_picture->mv[LIST_1][img->block_x+i][img->block_y+j][0]=0;
dec_picture->mv[LIST_1][img->block_x+i][img->block_y+j][1]=0;
img->ipredmode[img->block_x+i][img->block_y+j] = DC_PRED;
}
}
for (j=0; j<BLOCK_SIZE; j++)
for (i=0; i<BLOCK_SIZE; i++)
{
dec_picture->ref_idx[LIST_0][img->block_x+i][img->block_y+j] = -1;
dec_picture->ref_idx[LIST_1][img->block_x+i][img->block_y+j] = -1;
dec_picture->ref_pic_id[LIST_0][img->block_x+i][img->block_y+j] = INT64_MIN;
dec_picture->ref_pic_id[LIST_1][img->block_x+i][img->block_y+j] = INT64_MIN;
}
}
/*!
************************************************************************
* \brief
* Sets mode for 8x8 block
************************************************************************
*/
void SetB8Mode (struct img_par* img, Macroblock* currMB, int value, int i)
{
static const int p_v2b8 [ 5] = {4, 5, 6, 7, IBLOCK};
static const int p_v2pd [ 5] = {0, 0, 0, 0, -1};
static const int b_v2b8 [14] = {0, 4, 4, 4, 5, 6, 5, 6, 5, 6, 7, 7, 7, IBLOCK};
static const int b_v2pd [14] = {2, 0, 1, 2, 0, 0, 1, 1, 2, 2, 0, 1, 2, -1};
if (img->type==B_SLICE)
{
currMB->b8mode[i] = b_v2b8[value];
currMB->b8pdir[i] = b_v2pd[value];
}
else
{
currMB->b8mode[i] = p_v2b8[value];
currMB->b8pdir[i] = p_v2pd[value];
}
}
void reset_coeffs()
{
int i, j, iii, jjj;
// reset luma coeffs
for (i=0;i<BLOCK_SIZE;i++)
{
for (j=0;j<BLOCK_SIZE;j++)
for(iii=0;iii<BLOCK_SIZE;iii++)
for(jjj=0;jjj<BLOCK_SIZE;jjj++)
img->cof[i][j][iii][jjj]=0;
}
// reset chroma coeffs
for (j=4;j<(4+img->num_blk8x8_uv);j++)
{
for (i=0;i<4;i++)
for (iii=0;iii<4;iii++)
for (jjj=0;jjj<4;jjj++)
img->cof[i][j][iii][jjj]=0;
}
// CAVLC
for (i=0; i < 4; i++)
for (j=0; j < (4 + img->num_blk8x8_uv); j++)
img->nz_coeff[img->current_mb_nr][i][j]=0;
}
void field_flag_inference()
{
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
if (currMB->mbAvailA)
{
currMB->mb_field = img->mb_data[currMB->mbAddrA].mb_field;
}
else
{
// check top macroblock pair
if (currMB->mbAvailB)
{
currMB->mb_field = img->mb_data[currMB->mbAddrB].mb_field;
}
else
currMB->mb_field = 0;
}
}
/*!
************************************************************************
* \brief
* Get the syntax elements from the NAL
************************************************************************
*/
int read_one_macroblock(struct img_par *img,struct inp_par *inp)
{
int i;
SyntaxElement currSE;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
Slice *currSlice = img->currentSlice;
DataPartition *dP;
int *partMap = assignSE2partition[currSlice->dp_mode];
Macroblock *topMB = NULL;
int prevMbSkipped = 0;
int img_block_y;
int check_bottom, read_bottom, read_top;
if (img->MbaffFrameFlag)
{
if (img->current_mb_nr%2)
{
topMB= &img->mb_data[img->current_mb_nr-1];
if(!(img->type == B_SLICE))
prevMbSkipped = (topMB->mb_type == 0);
else
prevMbSkipped = (topMB->mb_type == 0 && topMB->cbp == 0);
}
else
prevMbSkipped = 0;
}
if (img->current_mb_nr%2 == 0)
currMB->mb_field = 0;
else
currMB->mb_field = img->mb_data[img->current_mb_nr-1].mb_field;
currMB->qp = img->qp ;
currSE.type = SE_MBTYPE;
// read MB mode *****************************************************************
dP = &(currSlice->partArr[partMap[currSE.type]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_ue;
if(img->type == I_SLICE || img->type == SI_SLICE)
{
// read MB aff
if (img->MbaffFrameFlag && img->current_mb_nr%2==0)
{
TRACE_STRING("mb_field_decoding_flag");
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
{
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
}
else
{
currSE.reading = readFieldModeInfo_CABAC;
dP->readSyntaxElement(&currSE,img,inp,dP);
}
currMB->mb_field = currSE.value1;
}
if(active_pps->entropy_coding_mode_flag == CABAC)
CheckAvailabilityOfNeighborsCABAC();
// read MB type
TRACE_STRING("mb_type");
currSE.reading = readMB_typeInfo_CABAC;
dP->readSyntaxElement(&currSE,img,inp,dP);
currMB->mb_type = currSE.value1;
if(!dP->bitstream->ei_flag)
currMB->ei_flag = 0;
}
// non I/SI-slice CABAC
else if (active_pps->entropy_coding_mode_flag == CABAC)
{
// read MB skipflag
if (img->MbaffFrameFlag && (img->current_mb_nr%2 == 0||prevMbSkipped))
field_flag_inference();
CheckAvailabilityOfNeighborsCABAC();
TRACE_STRING("mb_skip_flag");
currSE.reading = readMB_skip_flagInfo_CABAC;
dP->readSyntaxElement(&currSE,img,inp,dP);
currMB->mb_type = currSE.value1;
if (img->type==B_SLICE)
currMB->cbp = currSE.value2;
if(!dP->bitstream->ei_flag)
currMB->ei_flag = 0;
if ((img->type==B_SLICE) && currSE.value1==0 && currSE.value2==0)
img->cod_counter=0;
// read MB aff
if (img->MbaffFrameFlag)
{
check_bottom=read_bottom=read_top=0;
if (img->current_mb_nr%2==0)
{
check_bottom = (img->type!=B_SLICE)?
(currMB->mb_type == 0):
(currMB->mb_type == 0 && currMB->cbp == 0);
read_top = !check_bottom;
}
else
read_bottom = (img->type!=B_SLICE)?
(topMB->mb_type == 0 && currMB->mb_type != 0) :
((topMB->mb_type == 0 && topMB->cbp == 0) && (currMB->mb_type != 0 || currMB->cbp != 0));
if (read_bottom || read_top)
{
TRACE_STRING("mb_field_decoding_flag");
currSE.reading = readFieldModeInfo_CABAC;
dP->readSyntaxElement(&currSE,img,inp,dP);
currMB->mb_field = currSE.value1;
}
if (check_bottom)
check_next_mb_and_get_field_mode_CABAC(&currSE,img,inp,dP);
}
if(active_pps->entropy_coding_mode_flag == CABAC)
CheckAvailabilityOfNeighborsCABAC();
// read MB type
if (currMB->mb_type != 0 )
{
currSE.reading = readMB_typeInfo_CABAC;
TRACE_STRING("mb_type");
dP->readSyntaxElement(&currSE,img,inp,dP);
currMB->mb_type = currSE.value1;
if(!dP->bitstream->ei_flag)
currMB->ei_flag = 0;
}
}
// VLC Non-Intra
else
{
if(img->cod_counter == -1)
{
TRACE_STRING("mb_skip_run");
dP->readSyntaxElement(&currSE,img,inp,dP);
img->cod_counter = currSE.value1;
}
if (img->cod_counter==0)
{
// read MB aff
if ((img->MbaffFrameFlag) && ((img->current_mb_nr%2==0) || ((img->current_mb_nr%2) && prevMbSkipped)))
{
TRACE_STRING("mb_field_decoding_flag");
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
currMB->mb_field = currSE.value1;
}
// read MB type
TRACE_STRING("mb_type");
dP->readSyntaxElement(&currSE,img,inp,dP);
if(img->type == P_SLICE || img->type == SP_SLICE)
currSE.value1++;
currMB->mb_type = currSE.value1;
if(!dP->bitstream->ei_flag)
currMB->ei_flag = 0;
img->cod_counter--;
}
else
{
img->cod_counter--;
currMB->mb_type = 0;
currMB->ei_flag = 0;
// read field flag of bottom block
if(img->MbaffFrameFlag)
{
if(img->cod_counter == 0 && (img->current_mb_nr%2 == 0))
{
TRACE_STRING("mb_field_decoding_flag (of coded bottom mb)");
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
dP->bitstream->frame_bitoffset--;
currMB->mb_field = currSE.value1;
}
else if(img->cod_counter > 0 && (img->current_mb_nr%2 == 0))
{
// check left macroblock pair first
if (mb_is_available(img->current_mb_nr-2, img->current_mb_nr)&&((img->current_mb_nr%(img->PicWidthInMbs*2))!=0))
{
currMB->mb_field = img->mb_data[img->current_mb_nr-2].mb_field;
}
else
{
// check top macroblock pair
if (mb_is_available(img->current_mb_nr-2*img->PicWidthInMbs, img->current_mb_nr))
{
currMB->mb_field = img->mb_data[img->current_mb_nr-2*img->PicWidthInMbs].mb_field;
}
else
currMB->mb_field = 0;
}
}
}
}
}
dec_picture->mb_field[img->current_mb_nr] = currMB->mb_field;
img->siblock[img->mb_x][img->mb_y]=0;
if ((img->type==P_SLICE )) // inter frame
interpret_mb_mode_P(img);
else if (img->type==I_SLICE) // intra frame
interpret_mb_mode_I(img);
else if ((img->type==B_SLICE)) // B frame
interpret_mb_mode_B(img);
else if ((img->type==SP_SLICE)) // SP frame
interpret_mb_mode_P(img);
else if (img->type==SI_SLICE) // SI frame
interpret_mb_mode_SI(img);
if(img->MbaffFrameFlag)
{
if(currMB->mb_field)
{
img->num_ref_idx_l0_active <<=1;
img->num_ref_idx_l1_active <<=1;
}
}
//init NoMbPartLessThan8x8Flag
currMB->NoMbPartLessThan8x8Flag = (IS_DIRECT(currMB) && !(active_sps->direct_8x8_inference_flag))? 0: 1;
//====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST block modes ======
if (IS_P8x8 (currMB))
{
currSE.type = SE_MBTYPE;
dP = &(currSlice->partArr[partMap[SE_MBTYPE]]);
for (i=0; i<4; i++)
{
if (active_pps->entropy_coding_mode_flag ==UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_ue;
else currSE.reading = readB8_typeInfo_CABAC;
TRACE_STRING("sub_mb_type");
dP->readSyntaxElement (&currSE, img, inp, dP);
SetB8Mode (img, currMB, currSE.value1, i);
//set NoMbPartLessThan8x8Flag for P8x8 mode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -