📄 macroblock.c
字号:
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 ---
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))
{
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;
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;
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 )
{
IntraChromaPredModeFlag = 1;
for(j=0;j<2;j++) //loop subblocks
for(i=0;i<2;i++)
{
//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);
}
bx = ((b8&1)<<1) + i;
by = (b8&2) + j;
getLuma4x4Neighbour(img->current_mb_nr, bx, by, -1, 0, &left_block);
getLuma4x4Neighbour(img->current_mb_nr, bx, by, 0, -1, &top_block);
//get from array and decode
bi = img->block_x + bx;
bj = img->block_y + by;
if (active_pps->constrained_intra_pred_flag)
{
left_block.available = left_block.available ? img->intra_block[left_block.mb_addr] : 0;
top_block.available = top_block.available ? img->intra_block[top_block.mb_addr] : 0;
}
// !! KS: not sure if the follwing is still correct...
ts=ls=0; // Check to see if the neighboring block is SI
if (IS_OLDINTRA(currMB) && img->type == SI_SLICE) // need support for MBINTLC1
{
if (left_block.available)
if (img->siblock [left_block.pos_x][left_block.pos_y])
ls=1;
if (top_block.available)
if (img->siblock [top_block.pos_x][top_block.pos_y])
ts=1;
}
upIntraPredMode = (top_block.available &&(ts == 0)) ? img->ipredmode[top_block.pos_x ][top_block.pos_y ] : -1;
leftIntraPredMode = (left_block.available &&(ls == 0)) ? img->ipredmode[left_block.pos_x][left_block.pos_y] : -1;
mostProbableIntraPredMode = (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED : upIntraPredMode < leftIntraPredMode ? upIntraPredMode : leftIntraPredMode;
dec = (currSE.value1 == -1) ? mostProbableIntraPredMode : currSE.value1 + (currSE.value1 >= mostProbableIntraPredMode);
//set
img->ipredmode[bi][bj]=dec;
}
}
}
if (IntraChromaPredModeFlag)
{
currSE.type = SE_INTRAPREDMODE;
TRACE_STRING("intra_chroma_pred_mode");
dP = &(currSlice->partArr[partMap[currSE.type]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_ue;
else currSE.reading = readCIPredMode_CABAC;
dP->readSyntaxElement(&currSE,img,inp,dP);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -