📄 parset.c
字号:
if (pps->slice_group_map_type == 0)
{
for (i=0; i<=pps->num_slice_groups_minus1; i++)
pps->run_length_minus1 [i] = ue_v ("PPS: run_length_minus1 [i]" , s);
}
else if (pps->slice_group_map_type == 2)
{
for (i=0; i<pps->num_slice_groups_minus1; i++)
{
//! JVT-F078: avoid reference of SPS by using ue(v) instead of u(v)
pps->top_left [i] = ue_v ("PPS: top_left [i]" , s);
pps->bottom_right [i] = ue_v ("PPS: bottom_right [i]" , s);
}
}
else if (pps->slice_group_map_type == 3 ||
pps->slice_group_map_type == 4 ||
pps->slice_group_map_type == 5)
{
pps->slice_group_change_direction_flag = u_1 ("PPS: slice_group_change_direction_flag" , s);
pps->slice_group_change_rate_minus1 = ue_v ("PPS: slice_group_change_rate_minus1" , s);
}
else if (pps->slice_group_map_type == 6)
{
if (pps->num_slice_groups_minus1+1 >4)
NumberBitsPerSliceGroupId = 3;
else if (pps->num_slice_groups_minus1+1 > 2)
NumberBitsPerSliceGroupId = 2;
else
NumberBitsPerSliceGroupId = 1;
//! JVT-F078, exlicitly signal number of MBs in the map
pps->num_slice_group_map_units_minus1 = ue_v ("PPS: num_slice_group_map_units_minus1" , s);
for (i=0; i<=pps->num_slice_group_map_units_minus1; i++)
pps->slice_group_id[i] = u_v (NumberBitsPerSliceGroupId, "slice_group_id[i]", s);
}
}
// 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);
if((SeqParSet[pps->seq_parameter_set_id].profile_idc==FREXT_HP ) ||
(SeqParSet[pps->seq_parameter_set_id].profile_idc==FREXT_Hi10P) ||
(SeqParSet[pps->seq_parameter_set_id].profile_idc==FREXT_Hi422) ||
(SeqParSet[pps->seq_parameter_set_id].profile_idc==FREXT_Hi444))
{
pps->cb_qp_index_offset = se_v ("PPS: chroma_qp_index_offset" , s); // HB 10062004
pps->chroma_qp_index_offset = pps->cb_qp_index_offset; // tchen 6-14-04
}
else
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);
// HB 10062004 start
if(more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) // more_data_in_rbsp()
{
//Fidelity Range Extensions Stuff
//if(pps->entropy_coding_mode_flag) //LW: read transform mode for BOTH UVLC & CABAC
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->cr_qp_index_offset = se_v ("PPS: second_chroma_qp_index_offset" , s);
}
// HB 10062004 end
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 (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;
// Fidelity Range Extensions stuff (part 1)
img->bitdepth_luma = sps->bit_depth_luma_minus8 + 8;
img->bitdepth_chroma = sps->bit_depth_chroma_minus8 + 8;
init_frext(img);
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->width = img->PicWidthInMbs * MB_BLOCK_SIZE;
img->height = img->FrameHeightInMbs * MB_BLOCK_SIZE;
if (img->yuv_format == YUV420)
{
img->width_cr = img->width /2;
img->height_cr = img->height / 2;
}
else if (img->yuv_format == YUV422)
{
img->width_cr = img->width /2;
img->height_cr = img->height;
}
else
{
//YUV444
img->width_cr = img->width;
img->height_cr = img->height;
}
init_global_buffers();
if (!img->no_output_of_prior_pics_flag)
{
flush_dpb();
}
init_dpb();
if (NULL!=Co_located)
{
free_collocated(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->AllowTransform8x8 = pps->transform_8x8_mode_flag;
if((img->profile_idc==FREXT_HP ) ||
(img->profile_idc==FREXT_Hi10P) ||
(img->profile_idc==FREXT_Hi422) ||
(img->profile_idc==FREXT_Hi444))
{
img->chroma_qp_offset[0] = active_pps->cb_qp_index_offset;
img->chroma_qp_offset[1] = active_pps->cr_qp_index_offset;
}
else
img->chroma_qp_offset[0] = img->chroma_qp_offset[1] = active_pps->chroma_qp_index_offset;
}
}
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 (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;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -