📄 parset.c
字号:
// End of FMO stuff
pps->num_ref_idx_l0_active_minus1 = ue_v ("PPS: num_ref_idx_l0_active_minus1" , s);
pps->num_ref_idx_l1_active_minus1 = ue_v ("PPS: num_ref_idx_l1_active_minus1" , s);
pps->weighted_pred_flag = u_1 ("PPS: weighted prediction flag" , s);
pps->weighted_bipred_idc = u_v ( 2, "PPS: weighted_bipred_idc" , s);
pps->pic_init_qp_minus26 = se_v ("PPS: pic_init_qp_minus26" , s);
pps->pic_init_qs_minus26 = se_v ("PPS: pic_init_qs_minus26" , s);
pps->chroma_qp_index_offset = se_v ("PPS: chroma_qp_index_offset" , s);
pps->deblocking_filter_control_present_flag = u_1 ("PPS: deblocking_filter_control_present_flag" , s);
pps->constrained_intra_pred_flag = u_1 ("PPS: constrained_intra_pred_flag" , s);
pps->redundant_pic_cnt_present_flag = u_1 ("PPS: redundant_pic_cnt_present_flag" , s);
if(more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) // more_data_in_rbsp()
{
//Fidelity Range Extensions Stuff
pps->transform_8x8_mode_flag = u_1 ("PPS: transform_8x8_mode_flag" , s);
pps->pic_scaling_matrix_present_flag = u_1 ("PPS: pic_scaling_matrix_present_flag" , s);
if(pps->pic_scaling_matrix_present_flag)
{
for(i=0; i<(6+((unsigned)pps->transform_8x8_mode_flag<<1)); i++)
{
pps->pic_scaling_list_present_flag[i]= u_1 ("PPS: pic_scaling_list_present_flag" , s);
if(pps->pic_scaling_list_present_flag[i])
{
if(i<6)
Scaling_List(pps->ScalingList4x4[i], 16, &pps->UseDefaultScalingMatrix4x4Flag[i], s);
else
Scaling_List(pps->ScalingList8x8[i-6], 64, &pps->UseDefaultScalingMatrix8x8Flag[i-6], s);
}
}
}
pps->second_chroma_qp_index_offset = se_v ("PPS: second_chroma_qp_index_offset" , s);
}
else
{
pps->second_chroma_qp_index_offset = pps->chroma_qp_index_offset;
}
pps->Valid = TRUE;
return UsedBits;
}
void PPSConsistencyCheck (pic_parameter_set_rbsp_t *pps)
{
printf ("Consistency checking a picture parset, to be implemented\n");
// if (pps->seq_parameter_set_id invalid then do something)
}
void SPSConsistencyCheck (seq_parameter_set_rbsp_t *sps)
{
printf ("Consistency checking a sequence parset, to be implemented\n");
}
void MakePPSavailable (int id, pic_parameter_set_rbsp_t *pps)
{
assert (pps->Valid == TRUE);
if (PicParSet[id].Valid == TRUE && PicParSet[id].slice_group_id != NULL)
free (PicParSet[id].slice_group_id);
memcpy (&PicParSet[id], pps, sizeof (pic_parameter_set_rbsp_t));
if ((PicParSet[id].slice_group_id = calloc (PicParSet[id].num_slice_group_map_units_minus1+1, sizeof(int))) == NULL)
no_mem_exit ("MakePPSavailable: Cannot calloc slice_group_id");
memcpy (PicParSet[id].slice_group_id, pps->slice_group_id, (pps->num_slice_group_map_units_minus1+1)*sizeof(int));
}
void MakeSPSavailable (int id, seq_parameter_set_rbsp_t *sps)
{
assert (sps->Valid == TRUE);
memcpy (&SeqParSet[id], sps, sizeof (seq_parameter_set_rbsp_t));
}
void ProcessSPS (NALU_t *nalu)
{
DataPartition *dp = AllocPartition(1);
seq_parameter_set_rbsp_t *sps = AllocSPS();
int dummy;
memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1);
dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1);
dp->bitstream->ei_flag = 0;
dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0;
dummy = InterpretSPS (dp, sps);
if (sps->Valid)
{
if (active_sps)
{
if (sps->seq_parameter_set_id == active_sps->seq_parameter_set_id)
{
if (!sps_is_equal(sps, active_sps))
{
if (dec_picture)
{
// this may only happen on slice loss
exit_picture();
}
active_sps=NULL;
}
}
}
// SPSConsistencyCheck (pps);
MakeSPSavailable (sps->seq_parameter_set_id, sps);
img->profile_idc = sps->profile_idc; //ADD-VG
}
FreePartition (dp, 1);
FreeSPS (sps);
}
void ProcessPPS (NALU_t *nalu)
{
DataPartition *dp;
pic_parameter_set_rbsp_t *pps;
int dummy;
dp = AllocPartition(1);
pps = AllocPPS();
memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1);
dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1);
dp->bitstream->ei_flag = 0;
dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0;
dummy = InterpretPPS (dp, pps);
// PPSConsistencyCheck (pps);
if (active_pps)
{
if (pps->pic_parameter_set_id == active_pps->pic_parameter_set_id)
{
if (!pps_is_equal(pps, active_pps))
{
if (dec_picture)
{
// this may only happen on slice loss
exit_picture();
}
active_pps = NULL;
}
}
}
MakePPSavailable (pps->pic_parameter_set_id, pps);
FreePartition (dp, 1);
FreePPS (pps);
}
void activate_sps (seq_parameter_set_rbsp_t *sps)
{
if (active_sps != sps)
{
if (dec_picture)
{
// this may only happen on slice loss
exit_picture();
}
active_sps = sps;
img->bitdepth_chroma = 0;
img->width_cr = 0;
img->height_cr = 0;
// Fidelity Range Extensions stuff (part 1)
img->bitdepth_luma = sps->bit_depth_luma_minus8 + 8;
if (sps->chroma_format_idc != YUV400)
img->bitdepth_chroma = sps->bit_depth_chroma_minus8 + 8;
img->MaxFrameNum = 1<<(sps->log2_max_frame_num_minus4+4);
img->PicWidthInMbs = (sps->pic_width_in_mbs_minus1 +1);
img->PicHeightInMapUnits = (sps->pic_height_in_map_units_minus1 +1);
img->FrameHeightInMbs = ( 2 - sps->frame_mbs_only_flag ) * img->PicHeightInMapUnits;
img->FrameSizeInMbs = img->PicWidthInMbs * img->FrameHeightInMbs;
img->yuv_format=sps->chroma_format_idc;
img->width = img->PicWidthInMbs * MB_BLOCK_SIZE;
img->height = img->FrameHeightInMbs * MB_BLOCK_SIZE;
if (sps->chroma_format_idc == YUV420)
{
img->width_cr = img->width /2;
img->height_cr = img->height / 2;
}
else if (sps->chroma_format_idc == YUV422)
{
img->width_cr = img->width /2;
img->height_cr = img->height;
}
else if (sps->chroma_format_idc == YUV444)
{
//YUV444
img->width_cr = img->width;
img->height_cr = img->height;
}
init_frext(img);
init_global_buffers();
if (!img->no_output_of_prior_pics_flag)
{
flush_dpb();
}
init_dpb();
if (NULL!=Co_located)
{
free_colocated(Co_located);
}
Co_located = alloc_colocated (img->width, img->height,sps->mb_adaptive_frame_field_flag);
ercInit(img->width, img->height, 1);
}
}
void activate_pps(pic_parameter_set_rbsp_t *pps)
{
if (active_pps != pps)
{
if (dec_picture)
{
// this may only happen on slice loss
exit_picture();
}
active_pps = pps;
// Fidelity Range Extensions stuff (part 2)
img->Transform8x8Mode = pps->transform_8x8_mode_flag;
}
}
void UseParameterSet (int PicParsetId)
{
seq_parameter_set_rbsp_t *sps = &SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id];
pic_parameter_set_rbsp_t *pps = &PicParSet[PicParsetId];
int i;
if (PicParSet[PicParsetId].Valid != TRUE)
printf ("Trying to use an invalid (uninitialized) Picture Parameter Set with ID %d, expect the unexpected...\n", PicParsetId);
if (SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id].Valid != TRUE)
printf ("PicParset %d references an invalid (uninitialized) Sequence Parameter Set with ID %d, expect the unexpected...\n", PicParsetId, PicParSet[PicParsetId].seq_parameter_set_id);
sps = &SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id];
// In theory, and with a well-designed software, the lines above
// are everything necessary. In practice, we need to patch many values
// in img-> (but no more in inp-> -- these have been taken care of)
// Sequence Parameter Set Stuff first
// printf ("Using Picture Parameter set %d and associated Sequence Parameter Set %d\n", PicParsetId, PicParSet[PicParsetId].seq_parameter_set_id);
if ((int) sps->pic_order_cnt_type < 0 || sps->pic_order_cnt_type > 2) // != 1
{
printf ("invalid sps->pic_order_cnt_type = %d\n", sps->pic_order_cnt_type);
error ("pic_order_cnt_type != 1", -1000);
}
if (sps->pic_order_cnt_type == 1)
{
if(sps->num_ref_frames_in_pic_order_cnt_cycle >= MAXnum_ref_frames_in_pic_order_cnt_cycle)
{
error("num_ref_frames_in_pic_order_cnt_cycle too large",-1011);
}
}
activate_sps(sps);
activate_pps(pps);
// currSlice->dp_mode is set by read_new_slice (NALU first byte available there)
if (pps->entropy_coding_mode_flag == UVLC)
{
nal_startcode_follows = uvlc_startcode_follows;
for (i=0; i<3; i++)
{
img->currentSlice->partArr[i].readSyntaxElement = readSyntaxElement_UVLC;
}
}
else
{
nal_startcode_follows = cabac_startcode_follows;
for (i=0; i<3; i++)
{
img->currentSlice->partArr[i].readSyntaxElement = readSyntaxElement_CABAC;
}
}
}
/*!
************************************************************************
* \brief
* Allocates a stand-alone partition structure. Structure should
* be freed by FreePartition();
* data structures
*
* \par Input:
* n: number of partitions in the array
* \par return
* pointer to DataPartition Structure, zero-initialized
************************************************************************
*/
DataPartition *AllocPartition(int n)
{
DataPartition *partArr, *dataPart;
int i;
partArr = (DataPartition *) calloc(n, sizeof(DataPartition));
if (partArr == NULL)
{
snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Data Partition failed");
error(errortext, 100);
}
for (i=0; i<n; i++) // loop over all data partitions
{
dataPart = &(partArr[i]);
dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
if (dataPart->bitstream == NULL)
{
snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for Bitstream failed");
error(errortext, 100);
}
dataPart->bitstream->streamBuffer = (byte *) calloc(MAX_CODED_FRAME_SIZE, sizeof(byte));
if (dataPart->bitstream->streamBuffer == NULL)
{
snprintf(errortext, ET_SIZE, "AllocPartition: Memory allocation for streamBuffer failed");
error(errortext, 100);
}
}
return partArr;
}
/*!
***********************************************************************
* \brief
* Initilize FREXT variables
***********************************************************************
*/
void init_frext(struct img_par *img) //!< image parameters
{
//pel bitdepth init
img->bitdepth_luma_qp_scale = 6*(img->bitdepth_luma - 8);
if(img->bitdepth_luma > img->bitdepth_chroma || active_sps->chroma_format_idc == YUV400)
img->pic_unit_bitsize_on_disk = (img->bitdepth_luma > 8)? 16:8;
else
img->pic_unit_bitsize_on_disk = (img->bitdepth_chroma > 8)? 16:8;
img->dc_pred_value = 1<<(img->bitdepth_luma - 1);
img->max_imgpel_value = (1<<img->bitdepth_luma) - 1;
if (active_sps->chroma_format_idc != YUV400)
{
//for chrominance part
img->bitdepth_chroma_qp_scale = 6*(img->bitdepth_chroma - 8);
img->max_imgpel_value_uv = (1<<img->bitdepth_chroma) - 1;
img->num_blk8x8_uv = (1<<active_sps->chroma_format_idc)&(~(0x1));
img->num_cdc_coeff = img->num_blk8x8_uv<<1;
img->mb_cr_size_x = (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422)? 8:16;
img->mb_cr_size_y = (active_sps->chroma_format_idc==YUV444 || active_sps->chroma_format_idc==YUV422)? 16:8;
// Residue Color Transform
if(img->residue_transform_flag)
img->bitdepth_chroma_qp_scale += 6;
}
else
{
img->bitdepth_chroma_qp_scale = 0;
img->max_imgpel_value_uv = 0;
img->num_blk8x8_uv = 0;
img->num_cdc_coeff = 0;
img->mb_cr_size_x = 0;
img->mb_cr_size_y = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -