📄 macroblock.c
字号:
currMB->NoMbPartLessThan8x8Flag &= (currMB->b8mode[i]==0 && active_sps->direct_8x8_inference_flag) ||
(currMB->b8mode[i]==4);
}
//--- init macroblock data ---
init_macroblock (img);
readMotionInfoFromNAL (img, inp);
}
//============= Transform Size Flag for INTRA MBs =============
//-------------------------------------------------------------
//transform size flag for INTRA_4x4 and INTRA_8x8 modes
if (currMB->mb_type == I4MB && img->AllowTransform8x8)
{
currSE.type = SE_TRANSFORM_SIZE_FLAG;
dP = &(currSlice->partArr[partMap[SE_TRANSFORM_SIZE_FLAG]]);
currSE.reading = readMB_transform_size_flag_CABAC;
TRACE_STRING("transform size 8x8 flag");
// read UVLC transform_size_8x8_flag
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
{
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
}
else
{
dP->readSyntaxElement(&currSE,img,inp,dP);
}
currMB->luma_transform_size_8x8_flag = currSE.value1;
if (currMB->luma_transform_size_8x8_flag)
{
currMB->mb_type = I8MB;
for (i=0;i<4;i++) {currMB->b8mode[i]=I8MB; currMB->b8pdir[i]=-1; }
}
}
else
{
currMB->luma_transform_size_8x8_flag = 0;
}
if(active_pps->constrained_intra_pred_flag && (img->type==P_SLICE|| img->type==B_SLICE)) // inter frame
{
if( !IS_INTRA(currMB) )
{
img->intra_block[img->current_mb_nr] = 0;
}
}
//! TO for Error Concelament
//! If we have an INTRA Macroblock and we lost the partition
//! which contains the intra coefficients Copy MB would be better
//! than just a grey block.
//! Seems to be a bit at the wrong place to do this right here, but for this case
//! up to now there is no other way.
dP = &(currSlice->partArr[partMap[SE_CBP_INTRA]]);
if(IS_INTRA (currMB) && dP->bitstream->ei_flag && img->number)
{
currMB->mb_type = 0;
currMB->ei_flag = 1;
for (i=0;i<4;i++) {currMB->b8mode[i]=currMB->b8pdir[i]=0; }
}
dP = &(currSlice->partArr[partMap[currSE.type]]);
//! End TO
//--- init macroblock data ---
if (!IS_P8x8 (currMB))
init_macroblock (img);
if (IS_DIRECT (currMB) && img->cod_counter >= 0)
{
currMB->cbp = 0;
reset_coeffs();
if (active_pps->entropy_coding_mode_flag ==CABAC)
img->cod_counter=-1;
return DECODE_MB;
}
if (IS_COPY (currMB)) //keep last macroblock
{
int i, j, k, pmv[2];
int zeroMotionAbove;
int zeroMotionLeft;
PixelPos mb_a, mb_b;
int a_mv_y = 0;
int a_ref_idx = 0;
int b_mv_y = 0;
int b_ref_idx = 0;
int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? img->current_mb_nr%2 ? 4 : 2 : 0;
getLuma4x4Neighbour(img->current_mb_nr,0,0,-1, 0,&mb_a);
getLuma4x4Neighbour(img->current_mb_nr,0,0, 0,-1,&mb_b);
if (mb_a.available)
{
a_mv_y = dec_picture->mv[LIST_0][mb_a.pos_x][mb_a.pos_y][1];
a_ref_idx = dec_picture->ref_idx[LIST_0][mb_a.pos_x][mb_a.pos_y];
if (currMB->mb_field && !img->mb_data[mb_a.mb_addr].mb_field)
{
a_mv_y /=2;
a_ref_idx *=2;
}
if (!currMB->mb_field && img->mb_data[mb_a.mb_addr].mb_field)
{
a_mv_y *=2;
a_ref_idx >>=1;
}
}
if (mb_b.available)
{
b_mv_y = dec_picture->mv[LIST_0][mb_b.pos_x][mb_b.pos_y][1];
b_ref_idx = dec_picture->ref_idx[LIST_0][mb_b.pos_x][mb_b.pos_y];
if (currMB->mb_field && !img->mb_data[mb_b.mb_addr].mb_field)
{
b_mv_y /=2;
b_ref_idx *=2;
}
if (!currMB->mb_field && img->mb_data[mb_b.mb_addr].mb_field)
{
b_mv_y *=2;
b_ref_idx >>=1;
}
}
zeroMotionLeft = !mb_a.available ? 1 : a_ref_idx==0 && dec_picture->mv[LIST_0][mb_a.pos_x][mb_a.pos_y][0]==0 && a_mv_y==0 ? 1 : 0;
zeroMotionAbove = !mb_b.available ? 1 : b_ref_idx==0 && dec_picture->mv[LIST_0][mb_b.pos_x][mb_b.pos_y][0]==0 && b_mv_y==0 ? 1 : 0;
currMB->cbp = 0;
reset_coeffs();
img_block_y = img->block_y;
if (zeroMotionAbove || zeroMotionLeft)
{
for(i=0;i<BLOCK_SIZE;i++)
for(j=0;j<BLOCK_SIZE;j++)
for (k=0;k<2;k++)
dec_picture->mv[LIST_0][img->block_x+i][img->block_y+j][k] = 0;
}
else
{
SetMotionVectorPredictor (img, pmv, pmv+1, 0, LIST_0, dec_picture->ref_idx, dec_picture->mv, 0, 0, 16, 16);
for(i=0;i<BLOCK_SIZE;i++)
for(j=0;j<BLOCK_SIZE;j++)
for (k=0;k<2;k++)
{
dec_picture->mv[LIST_0][img->block_x+i][img_block_y+j][k] = pmv[k];
}
}
for(i=0;i<BLOCK_SIZE;i++)
for(j=0;j<BLOCK_SIZE;j++)
{
dec_picture->ref_idx[LIST_0][img->block_x+i][img_block_y+j] = 0;
dec_picture->ref_pic_id[LIST_0][img->block_x+i][img_block_y+j] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][dec_picture->ref_idx[LIST_0][img->block_x+i][img_block_y+j]];
}
return DECODE_MB;
}
if(currMB->mb_type!=IPCM)
{
// intra prediction modes for a macroblock 4x4 **********************************************
read_ipred_modes(img,inp);
// read inter frame vector data *********************************************************
if (IS_INTERMV (currMB) && (!IS_P8x8(currMB)))
{
readMotionInfoFromNAL (img, inp);
}
// read CBP and Coeffs ***************************************************************
readCBPandCoeffsFromNAL (img,inp);
}
else
{
//read pcm_alignment_zero_bit and pcm_byte[i]
// here dP is assigned with the same dP as SE_MBTYPE, because IPCM syntax is in the
// same category as MBTYPE
dP = &(currSlice->partArr[partMap[SE_MBTYPE]]);
readIPCMcoeffsFromNAL(img,inp,dP);
}
return DECODE_MB;
}
/*!
************************************************************************
* \brief
* Initialize decoding engine after decoding an IPCM macroblock
* (for IPCM CABAC 28/11/2003)
*
* \author
* Dong Wang <Dong.Wang@bristol.ac.uk>
************************************************************************
*/
void init_decoding_engine_IPCM(struct img_par *img)
{
Slice *currSlice = img->currentSlice;
Bitstream *currStream;
int ByteStartPosition;
int PartitionNumber;
int i;
if(currSlice->dp_mode==PAR_DP_1)
PartitionNumber=1;
else if(currSlice->dp_mode==PAR_DP_3)
PartitionNumber=3;
else
{
printf("Partition Mode is not supported\n");
exit(1);
}
for(i=0;i<PartitionNumber;i++)
{
currStream = currSlice->partArr[i].bitstream;
ByteStartPosition = currStream->read_len;
arideco_start_decoding (&currSlice->partArr[i].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
}
}
/*!
************************************************************************
* \brief
* Read IPCM pcm_alignment_zero_bit and pcm_byte[i] from stream to img->cof
* (for IPCM CABAC and IPCM CAVLC 28/11/2003)
*
* \author
* Dong Wang <Dong.Wang@bristol.ac.uk>
************************************************************************
*/
void readIPCMcoeffsFromNAL(struct img_par *img, struct inp_par *inp, struct datapartition *dP)
{
SyntaxElement currSE;
int i,j;
//For CABAC, we don't need to read bits to let stream byte aligned
// because we have variable for integer bytes position
if(active_pps->entropy_coding_mode_flag == CABAC)
{
//read luma and chroma IPCM coefficients
currSE.len=8;
for(i=0;i<16;i++)
for(j=0;j<16;j++)
{
readIPCMBytes_CABAC(&currSE, dP->bitstream);
img->cof[i/4][j/4][i%4][j%4]=currSE.value1;
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
readIPCMBytes_CABAC(&currSE, dP->bitstream);
img->cof[i/4][j/4+4][i%4][j%4]=currSE.value1;
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
readIPCMBytes_CABAC(&currSE, dP->bitstream);
img->cof[i/4+2][j/4+4][i%4][j%4]=currSE.value1;
}
//If the decoded MB is IPCM MB, decoding engine is initialized
// here the decoding engine is directly initialized without checking End of Slice
// The reason is that, whether current MB is the last MB in slice or not, there is
// at least one 'end of slice' syntax after this MB. So when fetching bytes in this
// initialisation process, we can guarantee there is bits available in bitstream.
init_decoding_engine_IPCM(img);
}
else
{
//read bits to let stream byte aligned
if((dP->bitstream->frame_bitoffset)%8!=0)
{
currSE.len=8-(dP->bitstream->frame_bitoffset)%8;
readSyntaxElement_FLC(&currSE, dP->bitstream);
}
//read luma and chroma IPCM coefficients
currSE.len=8;
TRACE_STRING("pcm_byte");
for(i=0;i<16;i++)
for(j=0;j<16;j++)
{
readSyntaxElement_FLC(&currSE, dP->bitstream);
img->cof[i/4][j/4][i%4][j%4]=currSE.value1;
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
readSyntaxElement_FLC(&currSE, dP->bitstream);
img->cof[i/4][j/4+4][i%4][j%4]=currSE.value1;
}
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
readSyntaxElement_FLC(&currSE, dP->bitstream);
img->cof[i/4+2][j/4+4][i%4][j%4]=currSE.value1;
}
}
}
void read_ipred_modes(struct img_par *img,struct inp_par *inp)
{
int b8,i,j,bi,bj,bx,by,dec;
SyntaxElement currSE;
Slice *currSlice;
DataPartition *dP;
int *partMap;
Macroblock *currMB;
int ts, ls;
int mostProbableIntraPredMode;
int upIntraPredMode;
int leftIntraPredMode;
int IntraChromaPredModeFlag;
int bs_x, bs_y;
int ii,jj;
PixelPos left_block;
PixelPos top_block;
currMB = &img->mb_data[img->current_mb_nr];
IntraChromaPredModeFlag = IS_INTRA(currMB);
currSlice = img->currentSlice;
partMap = assignSE2partition[currSlice->dp_mode];
currSE.type = SE_INTRAPREDMODE;
TRACE_STRING("intra4x4_pred_mode");
dP = &(currSlice->partArr[partMap[currSE.type]]);
if (!(active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag))
currSE.reading = readIntraPredMode_CABAC;
for(b8=0;b8<4;b8++) //loop 8x8 blocks
{
if((currMB->b8mode[b8]==IBLOCK )||(currMB->b8mode[b8]==I8MB))
{
bs_x = bs_y = (currMB->b8mode[b8] == I8MB)?8:4;
IntraChromaPredModeFlag = 1;
ii=(bs_x>>2);
jj=(bs_y>>2);
for(j=0;j<2;j+=jj) //loop subblocks
for(i=0;i<2;i+=ii)
{
//get from stream
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
readSyntaxElement_Intra4x4PredictionMode(&currSE,img,inp,dP);
else
{
currSE.context=(b8<<2)+(j<<1)+i;
dP->readSyntaxElement(&currSE,img,inp,dP);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -