📄 header.c
字号:
Slice *currSlice = img->currentSlice;
int dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER];
DataPartition *partition = &(currSlice->partArr[dP_nr]);
Bitstream *currStream = partition->bitstream;
int luma_weight_flag_l0, luma_weight_flag_l1, chroma_weight_flag_l0, chroma_weight_flag_l1;
int i,j;
img->luma_log2_weight_denom = ue_v ("SH: luma_log2_weight_denom", currStream);
img->wp_round_luma = img->luma_log2_weight_denom ? 1<<(img->luma_log2_weight_denom - 1): 0;
if ( 0 != active_sps->chroma_format_idc)
{
img->chroma_log2_weight_denom = ue_v ("SH: chroma_log2_weight_denom", currStream);
img->wp_round_chroma = img->chroma_log2_weight_denom ? 1<<(img->chroma_log2_weight_denom - 1): 0;
}
reset_wp_params(img);
for (i=0; i<img->num_ref_idx_l0_active; i++)
{
luma_weight_flag_l0 = u_1("SH: luma_weight_flag_l0", currStream);
if (luma_weight_flag_l0)
{
img->wp_weight[0][i][0] = se_v ("SH: luma_weight_l0", currStream);
img->wp_offset[0][i][0] = se_v ("SH: luma_offset_l0", currStream);
}
else
{
img->wp_weight[0][i][0] = 1<<img->luma_log2_weight_denom;
img->wp_offset[0][i][0] = 0;
}
if (active_sps->chroma_format_idc != 0)
{
chroma_weight_flag_l0 = u_1 ("SH: chroma_weight_flag_l0", currStream);
for (j=1; j<3; j++)
{
if (chroma_weight_flag_l0)
{
img->wp_weight[0][i][j] = se_v("SH: chroma_weight_l0", currStream);
img->wp_offset[0][i][j] = se_v("SH: chroma_offset_l0", currStream);
}
else
{
img->wp_weight[0][i][j] = 1<<img->chroma_log2_weight_denom;
img->wp_offset[0][i][j] = 0;
}
}
}
}
if ((img->type == B_SLICE) && active_pps->weighted_bipred_idc == 1)
{
for (i=0; i<img->num_ref_idx_l1_active; i++)
{
luma_weight_flag_l1 = u_1("SH: luma_weight_flag_l1", currStream);
if (luma_weight_flag_l1)
{
img->wp_weight[1][i][0] = se_v ("SH: luma_weight_l1", currStream);
img->wp_offset[1][i][0] = se_v ("SH: luma_offset_l1", currStream);
}
else
{
img->wp_weight[1][i][0] = 1<<img->luma_log2_weight_denom;
img->wp_offset[1][i][0] = 0;
}
if (active_sps->chroma_format_idc != 0)
{
chroma_weight_flag_l1 = u_1 ("SH: chroma_weight_flag_l1", currStream);
for (j=1; j<3; j++)
{
if (chroma_weight_flag_l1)
{
img->wp_weight[1][i][j] = se_v("SH: chroma_weight_l1", currStream);
img->wp_offset[1][i][j] = se_v("SH: chroma_offset_l1", currStream);
}
else
{
img->wp_weight[1][i][j] = 1<<img->chroma_log2_weight_denom;
img->wp_offset[1][i][j] = 0;
}
}
}
}
}
}
/*!
************************************************************************
* \brief
* read the memory control operations
************************************************************************
*/
void dec_ref_pic_marking(Bitstream *currStream)
{
int val;
DecRefPicMarking_t *tmp_drpm,*tmp_drpm2;
// free old buffer content
while (img->dec_ref_pic_marking_buffer)
{
tmp_drpm=img->dec_ref_pic_marking_buffer;
img->dec_ref_pic_marking_buffer=tmp_drpm->Next;
free (tmp_drpm);
}
if (img->idr_flag)
{
img->no_output_of_prior_pics_flag = u_1("SH: no_output_of_prior_pics_flag", currStream);
img->long_term_reference_flag = u_1("SH: long_term_reference_flag", currStream);
}
else
{
img->adaptive_ref_pic_buffering_flag = u_1("SH: adaptive_ref_pic_buffering_flag", currStream);
if (img->adaptive_ref_pic_buffering_flag)
{
// read Memory Management Control Operation
do
{
tmp_drpm=(DecRefPicMarking_t*)calloc (1,sizeof (DecRefPicMarking_t));
tmp_drpm->Next=NULL;
val = tmp_drpm->memory_management_control_operation = ue_v("SH: memory_management_control_operation", currStream);
if ((val==1)||(val==3))
{
tmp_drpm->difference_of_pic_nums_minus1 = ue_v("SH: difference_of_pic_nums_minus1", currStream);
}
if (val==2)
{
tmp_drpm->long_term_pic_num = ue_v("SH: long_term_pic_num", currStream);
}
if ((val==3)||(val==6))
{
tmp_drpm->long_term_frame_idx = ue_v("SH: long_term_frame_idx", currStream);
}
if (val==4)
{
tmp_drpm->max_long_term_frame_idx_plus1 = ue_v("SH: max_long_term_pic_idx_plus1", currStream);
}
// add command
if (img->dec_ref_pic_marking_buffer==NULL)
{
img->dec_ref_pic_marking_buffer=tmp_drpm;
}
else
{
tmp_drpm2=img->dec_ref_pic_marking_buffer;
while (tmp_drpm2->Next!=NULL) tmp_drpm2=tmp_drpm2->Next;
tmp_drpm2->Next=tmp_drpm;
}
}while (val != 0);
}
}
}
/*!
************************************************************************
* \brief
* To calculate the poc values
* based upon JVT-F100d2
* POC200301: Until Jan 2003, this function will calculate the correct POC
* values, but the management of POCs in buffered pictures may need more work.
* \return
* none
************************************************************************
*/
void decode_poc(struct img_par *img)
{
int i;
// for POC mode 0:
unsigned int MaxPicOrderCntLsb = (1<<(active_sps->log2_max_pic_order_cnt_lsb_minus4+4));
switch ( active_sps->pic_order_cnt_type )
{
case 0: // POC MODE 0
// 1st
if(img->idr_flag)
{
img->PrevPicOrderCntMsb = 0;
img->PrevPicOrderCntLsb = 0;
}
else
{
if (img->last_has_mmco_5)
{
if (img->last_pic_bottom_field)
{
img->PrevPicOrderCntMsb = 0;
img->PrevPicOrderCntLsb = 0;
}
else
{
img->PrevPicOrderCntMsb = 0;
img->PrevPicOrderCntLsb = img->toppoc;
}
}
}
// Calculate the MSBs of current picture
if( img->pic_order_cnt_lsb < img->PrevPicOrderCntLsb &&
( img->PrevPicOrderCntLsb - img->pic_order_cnt_lsb ) >= ( MaxPicOrderCntLsb / 2 ) )
img->PicOrderCntMsb = img->PrevPicOrderCntMsb + MaxPicOrderCntLsb;
else if ( img->pic_order_cnt_lsb > img->PrevPicOrderCntLsb &&
( img->pic_order_cnt_lsb - img->PrevPicOrderCntLsb ) > ( MaxPicOrderCntLsb / 2 ) )
img->PicOrderCntMsb = img->PrevPicOrderCntMsb - MaxPicOrderCntLsb;
else
img->PicOrderCntMsb = img->PrevPicOrderCntMsb;
// 2nd
if(img->field_pic_flag==0)
{ //frame pix
img->toppoc = img->PicOrderCntMsb + img->pic_order_cnt_lsb;
img->bottompoc = img->toppoc + img->delta_pic_order_cnt_bottom;
img->ThisPOC = img->framepoc = (img->toppoc < img->bottompoc)? img->toppoc : img->bottompoc; // POC200301
}
else if (img->bottom_field_flag==0)
{ //top field
img->ThisPOC= img->toppoc = img->PicOrderCntMsb + img->pic_order_cnt_lsb;
}
else
{ //bottom field
img->ThisPOC= img->bottompoc = img->PicOrderCntMsb + img->pic_order_cnt_lsb;
}
img->framepoc=img->ThisPOC;
if ( img->frame_num!=img->PreviousFrameNum)
img->PreviousFrameNum=img->frame_num;
if(img->nal_reference_idc)
{
img->PrevPicOrderCntLsb = img->pic_order_cnt_lsb;
img->PrevPicOrderCntMsb = img->PicOrderCntMsb;
}
break;
case 1: // POC MODE 1
// 1st
if(img->idr_flag)
{
img->FrameNumOffset=0; // first pix of IDRGOP,
img->delta_pic_order_cnt[0]=0; //ignore first delta
if(img->frame_num)
error("frame_num not equal to zero in IDR picture", -1020);
}
else
{
if (img->last_has_mmco_5)
{
img->PreviousFrameNumOffset = 0;
img->PreviousFrameNum = 0;
}
if (img->frame_num<img->PreviousFrameNum)
{ //not first pix of IDRGOP
img->FrameNumOffset = img->PreviousFrameNumOffset + img->MaxFrameNum;
}
else
{
img->FrameNumOffset = img->PreviousFrameNumOffset;
}
}
// 2nd
if(active_sps->num_ref_frames_in_pic_order_cnt_cycle)
img->AbsFrameNum = img->FrameNumOffset+img->frame_num;
else
img->AbsFrameNum=0;
if( (!img->nal_reference_idc) && img->AbsFrameNum>0)
img->AbsFrameNum--;
// 3rd
img->ExpectedDeltaPerPicOrderCntCycle=0;
if(active_sps->num_ref_frames_in_pic_order_cnt_cycle)
for(i=0;i<(int) active_sps->num_ref_frames_in_pic_order_cnt_cycle;i++)
img->ExpectedDeltaPerPicOrderCntCycle += active_sps->offset_for_ref_frame[i];
if(img->AbsFrameNum)
{
img->PicOrderCntCycleCnt = (img->AbsFrameNum-1)/active_sps->num_ref_frames_in_pic_order_cnt_cycle;
img->FrameNumInPicOrderCntCycle = (img->AbsFrameNum-1)%active_sps->num_ref_frames_in_pic_order_cnt_cycle;
img->ExpectedPicOrderCnt = img->PicOrderCntCycleCnt*img->ExpectedDeltaPerPicOrderCntCycle;
for(i=0;i<=(int)img->FrameNumInPicOrderCntCycle;i++)
img->ExpectedPicOrderCnt += active_sps->offset_for_ref_frame[i];
}
else
img->ExpectedPicOrderCnt=0;
if(!img->nal_reference_idc)
img->ExpectedPicOrderCnt += active_sps->offset_for_non_ref_pic;
if(img->field_pic_flag==0)
{ //frame pix
img->toppoc = img->ExpectedPicOrderCnt + img->delta_pic_order_cnt[0];
img->bottompoc = img->toppoc + active_sps->offset_for_top_to_bottom_field + img->delta_pic_order_cnt[1];
img->ThisPOC = img->framepoc = (img->toppoc < img->bottompoc)? img->toppoc : img->bottompoc; // POC200301
}
else if (img->bottom_field_flag==0)
{ //top field
img->ThisPOC = img->toppoc = img->ExpectedPicOrderCnt + img->delta_pic_order_cnt[0];
}
else
{ //bottom field
img->ThisPOC = img->bottompoc = img->ExpectedPicOrderCnt + active_sps->offset_for_top_to_bottom_field + img->delta_pic_order_cnt[0];
}
img->framepoc=img->ThisPOC;
img->PreviousFrameNum=img->frame_num;
img->PreviousFrameNumOffset=img->FrameNumOffset;
break;
case 2: // POC MODE 2
if(img->idr_flag) // IDR picture
{
img->FrameNumOffset=0; // first pix of IDRGOP,
img->ThisPOC = img->framepoc = img->toppoc = img->bottompoc = 0;
if(img->frame_num)
error("frame_num not equal to zero in IDR picture", -1020);
}
else
{
if (img->last_has_mmco_5)
{
img->PreviousFrameNum = 0;
img->PreviousFrameNumOffset = 0;
}
if (img->frame_num<img->PreviousFrameNum)
img->FrameNumOffset = img->PreviousFrameNumOffset + img->MaxFrameNum;
else
img->FrameNumOffset = img->PreviousFrameNumOffset;
img->AbsFrameNum = img->FrameNumOffset+img->frame_num;
if(!img->nal_reference_idc)
img->ThisPOC = (2*img->AbsFrameNum - 1);
else
img->ThisPOC = (2*img->AbsFrameNum);
if (img->field_pic_flag==0)
img->toppoc = img->bottompoc = img->framepoc = img->ThisPOC;
else if (img->bottom_field_flag==0)
img->toppoc = img->framepoc = img->ThisPOC;
else img->bottompoc = img->framepoc = img->ThisPOC;
}
img->PreviousFrameNum=img->frame_num;
img->PreviousFrameNumOffset=img->FrameNumOffset;
break;
default:
//error must occurs
assert( 1==0 );
break;
}
}
/*!
************************************************************************
* \brief
* A little helper for the debugging of POC code
* \return
* none
************************************************************************
*/
int dumppoc(struct img_par *img) {
printf ("\nPOC locals...\n");
printf ("toppoc %d\n", img->toppoc);
printf ("bottompoc %d\n", img->bottompoc);
printf ("frame_num %d\n", img->frame_num);
printf ("field_pic_flag %d\n", img->field_pic_flag);
printf ("bottom_field_flag %d\n", img->bottom_field_flag);
printf ("POC SPS\n");
printf ("log2_max_frame_num_minus4 %d\n", active_sps->log2_max_frame_num_minus4); // POC200301
printf ("log2_max_pic_order_cnt_lsb_minus4 %d\n", active_sps->log2_max_pic_order_cnt_lsb_minus4);
printf ("pic_order_cnt_type %d\n", active_sps->pic_order_cnt_type);
printf ("num_ref_frames_in_pic_order_cnt_cycle %d\n", active_sps->num_ref_frames_in_pic_order_cnt_cycle);
printf ("delta_pic_order_always_zero_flag %d\n", active_sps->delta_pic_order_always_zero_flag);
printf ("offset_for_non_ref_pic %d\n", active_sps->offset_for_non_ref_pic);
printf ("offset_for_top_to_bottom_field %d\n", active_sps->offset_for_top_to_bottom_field);
printf ("offset_for_ref_frame[0] %d\n", active_sps->offset_for_ref_frame[0]);
printf ("offset_for_ref_frame[1] %d\n", active_sps->offset_for_ref_frame[1]);
printf ("POC in SLice Header\n");
printf ("pic_order_present_flag %d\n", active_pps->pic_order_present_flag);
printf ("delta_pic_order_cnt[0] %d\n", img->delta_pic_order_cnt[0]);
printf ("delta_pic_order_cnt[1] %d\n", img->delta_pic_order_cnt[1]);
printf ("delta_pic_order_cnt[2] %d\n", img->delta_pic_order_cnt[2]);
printf ("idr_flag %d\n", img->idr_flag);
printf ("MaxFrameNum %d\n", img->MaxFrameNum);
return 0;
}
/*!
************************************************************************
* \brief
* return the poc of img as per (8-1) JVT-F100d2
* POC200301
************************************************************************
*/
int picture_order(struct img_par *img)
{
if (img->field_pic_flag==0) // is a frame
return img->framepoc;
else if (img->bottom_field_flag==0) // top field
return img->toppoc;
else // bottom field
return img->bottompoc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -