📄 macroblock.c
字号:
{
mbmode=2;
for(i=0;i<4;i++)
{
b8mode[i]=2;
b8pdir[i]=offset2pdir16x8 [mbtype][i/2];
}
}
else
{
mbmode=3;
for(i=0;i<4;i++)
{
b8mode[i]=3;
b8pdir[i]=offset2pdir8x16 [mbtype][i%2];
}
}
currMB->mb_type = mbmode;
}
/*!
************************************************************************
* \brief
* Interpret the mb mode for SI-Frames
************************************************************************
*/
void interpret_mb_mode_SI(struct img_par *img)
{
int i;
const int ICBPTAB[6] = {0,16,32,15,31,47};
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int mbmode = currMB->mb_type;
if (mbmode==0)
{
currMB->mb_type = SI4MB;
for (i=0;i<4;i++)
{
currMB->b8mode[i]=IBLOCK;
currMB->b8pdir[i]=-1;
}
img->siblock[img->mb_x][img->mb_y]=1;
}
else if (mbmode==1)
{
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_y+j][img->block_x+i][0]=0;
dec_picture->mv[LIST_0][img->block_y+j][img->block_x+i][1]=0;
dec_picture->mv[LIST_1][img->block_y+j][img->block_x+i][0]=0;
dec_picture->mv[LIST_1][img->block_y+j][img->block_x+i][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_y+j][img->block_x+i] = -1;
dec_picture->ref_idx[LIST_1][img->block_y+j][img->block_x+i] = -1;
dec_picture->ref_pic_id[LIST_0][img->block_y+j][img->block_x+i] = INT64_MIN;
dec_picture->ref_pic_id[LIST_1][img->block_y+j][img->block_x+i] = 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;
}
}
void set_chroma_qp(Macroblock* currMB)
{
int i;
for (i=0; i<2; i++)
{
currMB->qpc[i] = Clip3 ( -img->bitdepth_chroma_qp_scale, 51, currMB->qp + dec_picture->chroma_qp_offset[i] );
currMB->qpc[i] = currMB->qpc[i] < 0 ? currMB->qpc[i] : QP_SCALE_CR[currMB->qpc[i]];
}
}
/*!
************************************************************************
* \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;
#ifdef ADAPTIVE_FD_SD_CODING
int j;
for (i=0;i<16;i++)
{
for (j=0;j<16;j++)
{
currMB->quantizer_indices[j][i]=0;
}
}
for (i=0;i<2;i++)
{
for (j=0;j<2;j++)
{
currMB->SD_or_FD [j][i]=0;
}
}
currMB->SD_or_FD_t8x8=0;
currMB->written_SD_Coding_on_off=0;
#endif
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->skip_flag;
}
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 ;
for (i=0; i<2; i++)
{
currMB->qpc[i] = Clip3 ( -img->bitdepth_chroma_qp_scale, 51, img->qp + dec_picture->chroma_qp_offset[i] );
currMB->qpc[i] = currMB->qpc[i] < 0 ? currMB->qpc[i] : QP_SCALE_CR[currMB->qpc[i]];
}
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 skip_flag
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;
currMB->skip_flag = !(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 = currMB->skip_flag;
read_top = !check_bottom;
}
else
{
read_bottom = (topMB->skip_flag && (!currMB->skip_flag));
}
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);
}
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--;
currMB->skip_flag = 0;
}
else
{
img->cod_counter--;
currMB->mb_type = 0;
currMB->ei_flag = 0;
currMB->skip_flag = 1;
// read field flag of bottom block
if(img->MbaffFrameFlag)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -