📄 image.c
字号:
if (non_conforming_stream)
printf("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture'\n");
else
error("RefPicList0[ num_ref_idx_l0_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500);
}
// that's a definition
listXsize[0] = img->num_ref_idx_l0_active;
}
if (currSliceType == B_SLICE)
{
if (currSlice->ref_pic_list_reordering_flag_l1)
{
reorder_ref_pic_list(listX[1], &listXsize[1],
img->num_ref_idx_l1_active - 1,
currSlice->reordering_of_pic_nums_idc_l1,
currSlice->abs_diff_pic_num_minus1_l1,
currSlice->long_term_pic_idx_l1);
}
if (no_reference_picture == listX[1][img->num_ref_idx_l1_active-1])
{
if (non_conforming_stream)
printf("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture'\n");
else
error("RefPicList1[ num_ref_idx_l1_active_minus1 ] is equal to 'no reference picture', invalid bitstream",500);
}
// that's a definition
listXsize[1] = img->num_ref_idx_l1_active;
}
free_ref_pic_list_reordering_buffer(currSlice);
}
/*!
************************************************************************
* \brief
* initialize ref_pic_num array
************************************************************************
*/
//void set_ref_pic_num()
//{
// int i,j;
//
// int slice_id=img->current_slice_nr;
//
// for (i=0;i<listXsize[LIST_0];i++)
// {
// dec_picture->ref_pic_num [slice_id][LIST_0][i]=listX[LIST_0][i]->poc * 2 + ((listX[LIST_0][i]->structure==BOTTOM_FIELD)?1:0) ;
// dec_picture->frm_ref_pic_num [slice_id][LIST_0][i]=listX[LIST_0][i]->frame_poc * 2;
// dec_picture->top_ref_pic_num [slice_id][LIST_0][i]=listX[LIST_0][i]->top_poc * 2;
// dec_picture->bottom_ref_pic_num [slice_id][LIST_0][i]=listX[LIST_0][i]->bottom_poc * 2 + 1;
// //printf("POCS %d %d %d %d ",listX[LIST_0][i]->frame_poc,listX[LIST_0][i]->bottom_poc,listX[LIST_0][i]->top_poc,listX[LIST_0][i]->poc);
// //printf("refid %d %d %d %d\n",(int) dec_picture->frm_ref_pic_num[LIST_0][i],(int) dec_picture->top_ref_pic_num[LIST_0][i],(int) dec_picture->bottom_ref_pic_num[LIST_0][i],(int) dec_picture->ref_pic_num[LIST_0][i]);
// }
//
// for (i=0;i<listXsize[LIST_1];i++)
// {
// dec_picture->ref_pic_num [slice_id][LIST_1][i]=listX[LIST_1][i]->poc *2 + ((listX[LIST_1][i]->structure==BOTTOM_FIELD)?1:0);
// dec_picture->frm_ref_pic_num [slice_id][LIST_1][i]=listX[LIST_1][i]->frame_poc * 2;
// dec_picture->top_ref_pic_num [slice_id][LIST_1][i]=listX[LIST_1][i]->top_poc * 2;
// dec_picture->bottom_ref_pic_num [slice_id][LIST_1][i]=listX[LIST_1][i]->bottom_poc * 2 + 1;
// }
//
// if (!active_sps->frame_mbs_only_flag)
// {
// if (img->structure==FRAME)
// for (j=2;j<6;j++)
// for (i=0;i<listXsize[j];i++)
// {
// dec_picture->ref_pic_num [slice_id][j][i] = listX[j][i]->poc * 2 + ((listX[j][i]->structure==BOTTOM_FIELD)?1:0);
// dec_picture->frm_ref_pic_num [slice_id][j][i] = listX[j][i]->frame_poc * 2 ;
// dec_picture->top_ref_pic_num [slice_id][j][i] = listX[j][i]->top_poc * 2 ;
// dec_picture->bottom_ref_pic_num [slice_id][j][i] = listX[j][i]->bottom_poc * 2 + 1;
// }
// }
//
//}
/******************************* new functions defined for x900 parser. ***********************************/
/*!
************************************************************************
* \brief
* Returns the size of the NALU (bits between start codes in case of
* Annex B.
*
* \return
* 0 if there is nothing any more to read (EOF)
* -1 in case of any error
*
************************************************************************
*/
int get_next_nalu(NALU_t *nalu)
{
int ret;
ret=GetAnnexbNALU (nalu);
//In some cases, zero_byte shall be present. If current NALU is a VCL NALU, we can't tell
//whether it is the first VCL NALU at this point, so only non-VCL NAL unit is checked here.
CheckZeroByteNonVCL(nalu, &ret);
NALUtoRBSP(nalu);
return ret;
}
extern FILE *fref_lists;
int parse_current_slice(NALU_t *nalu)
{
int ret;
int current_header = 0;
int BitsUsedByHeader;
Slice *currSlice = img->currentSlice;
Bitstream *currStream;
switch (nalu->nal_unit_type)
{
case NALU_TYPE_SLICE:
case NALU_TYPE_IDR:
if (img->recovery_point || nalu->nal_unit_type == NALU_TYPE_IDR)
{
if (img->recovery_point_found == 0)
{
if (nalu->nal_unit_type != NALU_TYPE_IDR)
{
printf("Warning: Decoding does not start with an IDR picture.\n");
non_conforming_stream = 1;
}
else
non_conforming_stream = 0;
}
img->recovery_point_found = 1;
}
if (img->recovery_point_found == 0)
break;
img->idr_flag = (nalu->nal_unit_type == NALU_TYPE_IDR);
img->nal_reference_idc = nalu->nal_reference_idc;
currSlice->dp_mode = PAR_DP_1;
currSlice->max_part_nr = 1;
currSlice->ei_flag = 0;
currStream = currSlice->partArr[0].bitstream;
currStream->ei_flag = 0;
currStream->frame_bitoffset = currStream->read_len = 0;
memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
// Some syntax of the Slice Header depends on the parameter set, which depends on
// the parameter set ID of the SLice header. Hence, read the pic_parameter_set_id
// of the slice header first, then setup the active parameter sets, and then read
// the rest of the slice header
BitsUsedByHeader = FirstPartOfSliceHeader();
UseParameterSet (currSlice->pic_parameter_set_id);
BitsUsedByHeader+= RestOfSliceHeader ();
// FmoInit (active_pps, active_sps);
// AssignQuantParam (active_pps, active_sps);
// if primary slice is replaced with redundant slice, set the correct image type
// if(img->redundant_pic_cnt && Is_primary_correct==0 && Is_redundant_correct)
// {
// dec_picture->slice_type=img->type;
// }
if(is_new_picture())
{
init_picture(img, input);
current_header = SOP;
//check zero_byte if it is also the first NAL unit in the access unit
CheckZeroByteVCL(nalu, &ret);
}
else
current_header = SOS;
init_lists(img->type, img->currentSlice->structure);
reorder_lists (img->type, img->currentSlice);
if (img->structure==FRAME)
{
init_mbaff_lists();
}
// From here on, active_sps, active_pps and the slice header are valid
if (img->MbaffFrameFlag)
img->current_mb_nr = currSlice->start_mb_nr << 1;
else
img->current_mb_nr = currSlice->start_mb_nr;
img->recovery_point = 0;
break;
case NALU_TYPE_SEI:
//fprintf(img->fpinfo, "SEI:\n");
// printf ("read_new_slice: Found NALU_TYPE_SEI, len %d\n", nalu->len);
InterpretSEIMessage(nalu->buf,nalu->len,img);
break;
case NALU_TYPE_PPS:
ProcessPPS(nalu);
break;
case NALU_TYPE_SPS:
ProcessSPS(nalu);
break;
case NALU_TYPE_AUD:
// printf ("read_new_slice: Found 'Access Unit Delimiter' NAL unit, len %d, ignored\n", nalu->len);
break;
case NALU_TYPE_EOSEQ:
// printf ("read_new_slice: Found 'End of Sequence' NAL unit, len %d, ignored\n", nalu->len);
break;
case NALU_TYPE_EOSTREAM:
// printf ("read_new_slice: Found 'End of Stream' NAL unit, len %d, ignored\n", nalu->len);
break;
case NALU_TYPE_FILL:
printf ("read_new_slice: Found NALU_TYPE_FILL, len %d\n", nalu->len);
printf ("Skipping these filling bits, proceeding w/ next NALU\n");
break;
default:
printf ("Found NALU type %d, len %d undefined, ignore NALU, moving on\n", nalu->nal_unit_type, nalu->len);
}
return current_header;
}
void config_slice(unsigned char *nalu_start, unsigned int phy, unsigned int nalu_size)
{
int field_pic_flag;
int bottom_field_flag;
int count;
int data;
int j;
StorablePicture *ref_picture, *col_picture;
// set dec_picture->PastlistX0.
dec_picture->PastlistXsize0 = listXsize[0];
if (listXsize[0] > 0)
{
for(j=0; j<listXsize[0]; j++)
{
ref_picture = listX[0][j];
if (ref_picture->structure == FRAME)
{
dec_picture->PastlistX0[j].poc_bottom_field = ref_picture->bottom_poc * 2 + 1;
dec_picture->PastlistX0[j].poc_top_field = ref_picture->top_poc * 2;
}
else
{
if (ref_picture->structure == TOP_FIELD)
data = ref_picture->top_poc * 2;
else if (ref_picture->structure == BOTTOM_FIELD)
data = ref_picture->bottom_poc * 2 + 1;
dec_picture->PastlistX0[j].poc_bottom_field = data;
dec_picture->PastlistX0[j].poc_top_field = data;
}
field_pic_flag = !(ref_picture->coded_frame);
bottom_field_flag = (ref_picture->structure == BOTTOM_FIELD);
data = (ref_picture->pic_num & 0xffff) |
((ref_picture->MbaffFrameFlag & 0x01) << 16) |
(bottom_field_flag << 17) |
(field_pic_flag << 18) |
((ref_picture->is_long_term & 0x01) << 19);
dec_picture->PastlistX0[j].ref_pic_parameter = data;
}
}
// set dec_picture->PastlistX1.
dec_picture->PastlistXsize1 = listXsize[1];
if (listXsize[1] > 0)
{
for(j=0; j<listXsize[1]; j++)
{
ref_picture = listX[1][j];
if (ref_picture->structure == FRAME)
{
dec_picture->PastlistX1[j].poc_bottom_field = ref_picture->bottom_poc * 2 + 1;
dec_picture->PastlistX1[j].poc_top_field = ref_picture->top_poc * 2;
}
else
{
if (ref_picture->structure == TOP_FIELD)
data = ref_picture->top_poc * 2;
else if (ref_picture->structure == BOTTOM_FIELD)
data = ref_picture->bottom_poc * 2 + 1;
dec_picture->PastlistX1[j].poc_bottom_field = data;
dec_picture->PastlistX1[j].poc_top_field = data;
}
field_pic_flag = !(ref_picture->coded_frame);
bottom_field_flag = (ref_picture->structure == BOTTOM_FIELD);
data = (ref_picture->pic_num & 0xffff) |
((ref_picture->MbaffFrameFlag & 0x01) << 16) |
(bottom_field_flag << 17) |
(field_pic_flag << 18) |
((ref_picture->is_long_term & 0x01) << 19);
dec_picture->PastlistX1[j].ref_pic_parameter = data;
}
}
/******************* source bitstream *******************/
// bs_source_addr
write_reg(0x20, (int) phy);
// num_words
write_reg(0x44, nalu_size / 4);
/******************* memory address for current slice ********************/
// decoded_pic_luma_addr
data = dec_picture->pic_mem_idx; // top and bottom field use the same frame memory address.
write_reg(0x24|0x01, data|0x010000);
// decoded_pic_chroma_addr
data = dec_picture->pic_mem_idx; // chroma have a offset to the frame memory address.
write_reg(0x28|0x01, data|0x020000);
// mv_addr
data = dec_picture->pic_mem_idx;
write_reg(0x40|0x01, data|0x030000);
// ff_addr
data = dec_picture->pic_mem_idx;
write_reg(0xf0|0x01, data|0x040000);
/******************* ref_list0 *******************/
if (listXsize[0] > 0)
{
// ref_list_refresh_0
write_reg(0xc0, 0x1);
write_reg(0xc0, 0x0);
for(j=0; j<listXsize[0]; j++)
{
ref_picture = listX[0][j];
// poc_bottom_field_0, poc_top_field_0
switch(ref_picture->structure)
{
case FRAME:
// why top_poc and bottom_poc treated as such?
data = ref_picture->bottom_poc * 2 + 1;
write_reg(0xc4, data);
data = ref_picture->top_poc * 2;
write_reg(0xc8, data);
break;
case TOP_FIELD:
data = ref_picture->top_poc * 2;
write_reg(0xc4, data);
write_reg(0xc8, data);
break;
default:
data = ref_picture->bottom_poc * 2 + 1;
write_reg(0xc4, data);
write_reg(0xc8, data);
break;
}
// ref_pic_parameter_0
field_pic_flag = !(ref_picture->coded_frame);
bottom_field_flag = (ref_picture->structure == BOTTOM_FIELD);
data = (ref_picture->pic_num & 0xffff) |
((ref_picture->MbaffFrameFlag & 0x01) << 16) |
(bottom_field_flag << 17) |
(field_pic_flag << 18) |
((ref_picture->is_long_term & 0x01) << 19);
write_reg(0xcc, data);
// ref_pic_luma_addr_0
if (ref_picture->pic_mem_idx >= 0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -