📄 sei.c
字号:
offset ++;
#ifdef PRINT_RESERVED_INFO
printf("reserved_sei_message_payload_byte = %d\n", payload_byte);
#endif
}
#ifdef PRINT_RESERVED_INFO
#undef PRINT_RESERVED_INFO
#endif
}
/*!
************************************************************************
* \brief
* Interpret the Buffering period SEI message
* \param payload
* a pointer that point to the sei payload
* \param size
* the size of the sei message
* \param img
* the image pointer
*
************************************************************************
*/
void interpret_buffering_period_info( byte* payload, int size, ImageParameters *img )
{
int seq_parameter_set_id, initial_cpb_removal_delay, initial_cpb_removal_delay_offset;
unsigned int k;
Bitstream* buf;
seq_parameter_set_rbsp_t *sps;
buf = malloc(sizeof(Bitstream));
buf->bitstream_length = size;
buf->streamBuffer = payload;
buf->frame_bitoffset = 0;
UsedBits = 0;
seq_parameter_set_id = ue_v("SEI: seq_parameter_set_id" , buf);
sps = &SeqParSet[seq_parameter_set_id];
activate_sps(sps);
#ifdef PRINT_BUFFERING_PERIOD_INFO
printf("Buffering period SEI message\n");
printf("seq_parameter_set_id = %d\n", seq_parameter_set_id);
#endif
// Note: NalHrdBpPresentFlag and CpbDpbDelaysPresentFlag can also be set "by some means not specified in this Recommendation | International Standard"
if (sps->vui_parameters_present_flag)
{
if (sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
{
for (k=0; k<sps->vui_seq_parameters.nal_hrd_parameters.cpb_cnt_minus1+1; k++)
{
initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf);
initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf);
#ifdef PRINT_BUFFERING_PERIOD_INFO
printf("nal initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay);
printf("nal initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset);
#endif
}
}
if (sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
{
for (k=0; k<sps->vui_seq_parameters.vcl_hrd_parameters.cpb_cnt_minus1+1; k++)
{
initial_cpb_removal_delay = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay" , buf);
initial_cpb_removal_delay_offset = u_v(sps->vui_seq_parameters.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1+1, "SEI: initial_cpb_removal_delay_offset" , buf);
#ifdef PRINT_BUFFERING_PERIOD_INFO
printf("vcl initial_cpb_removal_delay[%d] = %d\n", k, initial_cpb_removal_delay);
printf("vcl initial_cpb_removal_delay_offset[%d] = %d\n", k, initial_cpb_removal_delay_offset);
#endif
}
}
}
free (buf);
#ifdef PRINT_BUFFERING_PERIOD_INFO
#undef PRINT_BUFFERING_PERIOD_INFO
#endif
}
/*!
************************************************************************
* \brief
* Interpret the Picture timing SEI message
* \param payload
* a pointer that point to the sei payload
* \param size
* the size of the sei message
* \param img
* the image pointer
*
************************************************************************
*/
void interpret_picture_timing_info( byte* payload, int size, ImageParameters *img )
{
int cpb_removal_delay, dpb_output_delay, picture_structure_present_flag, picture_structure;
int clock_time_stamp_flag;
int ct_type, nuit_field_based_flag, counting_type, full_timestamp_flag, discontinuity_flag, cnt_dropped_flag, nframes;
int seconds_value, minutes_value, hours_value, seconds_flag, minutes_flag, hours_flag, time_offset;
int NumClockTs = 0;
int i;
int cpb_removal_len = 24;
int dpb_output_len = 24;
Boolean CpbDpbDelaysPresentFlag;
Bitstream* buf;
if (NULL==active_sps)
{
fprintf (stderr, "Warning: no active SPS, timing SEI cannot be parsed\n");
return;
}
buf = malloc(sizeof(Bitstream));
buf->bitstream_length = size;
buf->streamBuffer = payload;
buf->frame_bitoffset = 0;
UsedBits = 0;
#ifdef PRINT_PCITURE_TIMING_INFO
printf("Picture timing SEI message\n");
#endif
// CpbDpbDelaysPresentFlag can also be set "by some means not specified in this Recommendation | International Standard"
CpbDpbDelaysPresentFlag = (Boolean) (active_sps->vui_parameters_present_flag
&& ( (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag != 0)
||(active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag != 0)));
if (CpbDpbDelaysPresentFlag )
{
if (active_sps->vui_parameters_present_flag)
{
if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
{
cpb_removal_len = active_sps->vui_seq_parameters.nal_hrd_parameters.cpb_removal_delay_length_minus1 + 1;
dpb_output_len = active_sps->vui_seq_parameters.nal_hrd_parameters.dpb_output_delay_length_minus1 + 1;
}
else if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
{
cpb_removal_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.cpb_removal_delay_length_minus1 + 1;
dpb_output_len = active_sps->vui_seq_parameters.vcl_hrd_parameters.dpb_output_delay_length_minus1 + 1;
}
}
if ((active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)||
(active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag))
{
cpb_removal_delay = u_v(cpb_removal_len, "SEI: cpb_removal_delay" , buf);
dpb_output_delay = u_v(dpb_output_len, "SEI: dpb_output_delay" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("cpb_removal_delay = %d\n",cpb_removal_delay);
printf("dpb_output_delay = %d\n",dpb_output_delay);
#endif
}
}
if (!active_sps->vui_parameters_present_flag)
{
picture_structure_present_flag = 0;
}
else
{
picture_structure_present_flag = active_sps->vui_seq_parameters.pic_struct_present_flag;
}
if (picture_structure_present_flag)
{
picture_structure = u_v(4, "SEI: pic_struct" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("picture_structure = %d\n",picture_structure);
#endif
switch (picture_structure)
{
case 0:
case 1:
case 2:
NumClockTs = 1;
break;
case 3:
case 4:
case 7:
NumClockTs = 2;
break;
case 5:
case 6:
case 8:
NumClockTs = 3;
break;
default:
error("reserved picture_structure used (can't determine NumClockTs)", 500);
}
for (i=0; i<NumClockTs; i++)
{
clock_time_stamp_flag = u_1("SEI: clock_time_stamp_flag" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("clock_time_stamp_flag = %d\n",clock_time_stamp_flag);
#endif
if (clock_time_stamp_flag)
{
ct_type = u_v(2, "SEI: ct_type" , buf);
nuit_field_based_flag = u_1( "SEI: nuit_field_based_flag" , buf);
counting_type = u_v(5, "SEI: counting_type" , buf);
full_timestamp_flag = u_1( "SEI: full_timestamp_flag" , buf);
discontinuity_flag = u_1( "SEI: discontinuity_flag" , buf);
cnt_dropped_flag = u_1( "SEI: cnt_dropped_flag" , buf);
nframes = u_v(8, "SEI: nframes" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("ct_type = %d\n",ct_type);
printf("nuit_field_based_flag = %d\n",nuit_field_based_flag);
printf("full_timestamp_flag = %d\n",full_timestamp_flag);
printf("discontinuity_flag = %d\n",discontinuity_flag);
printf("cnt_dropped_flag = %d\n",cnt_dropped_flag);
printf("nframes = %d\n",nframes);
#endif
if (full_timestamp_flag)
{
seconds_value = u_v(6, "SEI: seconds_value" , buf);
minutes_value = u_v(6, "SEI: minutes_value" , buf);
hours_value = u_v(5, "SEI: hours_value" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("seconds_value = %d\n",seconds_value);
printf("minutes_value = %d\n",minutes_value);
printf("hours_value = %d\n",hours_value);
#endif
}
else
{
seconds_flag = u_1( "SEI: seconds_flag" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("seconds_flag = %d\n",seconds_flag);
#endif
if (seconds_flag)
{
seconds_value = u_v(6, "SEI: seconds_value" , buf);
minutes_flag = u_1( "SEI: minutes_flag" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("seconds_value = %d\n",seconds_value);
printf("minutes_flag = %d\n",minutes_flag);
#endif
if(minutes_flag)
{
minutes_value = u_v(6, "SEI: minutes_value" , buf);
hours_flag = u_1( "SEI: hours_flag" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("minutes_value = %d\n",minutes_value);
printf("hours_flag = %d\n",hours_flag);
#endif
if(hours_flag)
{
hours_value = u_v(5, "SEI: hours_value" , buf);
#ifdef PRINT_PCITURE_TIMING_INFO
printf("hours_value = %d\n",hours_value);
#endif
}
}
}
}
{
int time_offset_length;
if (active_sps->vui_seq_parameters.vcl_hrd_parameters_present_flag)
time_offset_length = active_sps->vui_seq_parameters.vcl_hrd_parameters.time_offset_length;
else if (active_sps->vui_seq_parameters.nal_hrd_parameters_present_flag)
time_offset_length = active_sps->vui_seq_parameters.nal_hrd_parameters.time_offset_length;
else
time_offset_length = 24;
if (time_offset_length)
time_offset = i_v(time_offset_length, "SEI: time_offset" , buf);
else
time_offset = 0;
#ifdef PRINT_PCITURE_TIMING_INFO
printf("time_offset = %d\n",time_offset);
#endif
}
}
}
}
free (buf);
#ifdef PRINT_PCITURE_TIMING_INFO
#undef PRINT_PCITURE_TIMING_INFO
#endif
}
/*!
************************************************************************
* \brief
* Interpret the HDR tone-mapping SEI message (JVT-T060)
* \param payload
* a pointer that point to the sei payload
* \param size
* the size of the sei message
* \param img
* the image pointer
*
************************************************************************
*/
typedef struct
{
unsigned int tone_map_id;
unsigned char tone_map_cancel_flag;
unsigned int tone_map_repetition_period;
unsigned char coded_data_bit_depth;
unsigned char sei_bit_depth;
unsigned int model_id;
// variables for model 0
int min_value;
int max_value;
// variables for model 1
int sigmoid_midpoint;
int sigmoid_width;
// variables for model 2
int start_of_coded_interval[1<<MAX_SEI_BIT_DEPTH];
// variables for model 3
int num_pivots;
int coded_pivot_value[MAX_NUM_PIVOTS];
int sei_pivot_value[MAX_NUM_PIVOTS];
} tone_mapping_struct_tmp;
void interpret_tone_mapping( byte* payload, int size, ImageParameters *img )
{
tone_mapping_struct_tmp seiToneMappingTmp;
Bitstream* buf;
int i = 0, max_coded_num, max_output_num;
memset (&seiToneMappingTmp, 0, sizeof (tone_mapping_struct_tmp));
buf = malloc(sizeof(Bitstream));
buf->bitstream_length = size;
buf->streamBuffer = payload;
buf->frame_bitoffset = 0;
seiToneMappingTmp.tone_map_id = ue_v("SEI: tone_map_id", buf);
seiToneMappingTmp.tone_map_cancel_flag = u_1("SEI: tone_map_cancel_flag", buf);
#ifdef PRINT_TONE_MAPPING
printf("Tone-mapping SEI message\n");
printf("tone_map_id = %d\n", seiToneMappingTmp.tone_map_id);
if (seiToneMappingTmp.tone_map_id != 0)
printf("WARNING! Tone_map_id != 0, print the SEI message info only. The tone mapping is actually applied only when Tone_map_id==0\n\n");
printf("tone_map_cancel_flag = %d\n", seiToneMappingTmp.tone_map_cancel_flag);
#endif
if (!seiToneMappingTmp.tone_map_cancel_flag)
{
seiToneMappingTmp.tone_map_repetition_period = ue_v( "SEI: tone_map_repetition_period", buf);
seiToneMappingTmp.coded_data_bit_depth = u_v (8,"SEI: coded_data_bit_depth" , buf);
seiToneMappingTmp.sei_bit_depth = u_v (8,"SEI: sei_bit_depth" , buf);
seiToneMappingTmp.model_id = ue_v( "SEI: model_id" , buf);
#ifdef PRINT_TONE_MAPPING
printf("tone_map_repetition_period = %d\n", seiToneMappingTmp.tone_map_repetition_period);
printf("coded_data_bit_depth = %d\n", seiToneMappingTmp.coded_data_bit_depth);
printf("sei_bit_depth = %d\n", seiToneMappingTmp.sei_bit_depth);
printf("model_id = %d\n", seiToneMappingTmp.model_id);
#endif
max_coded_num = 1<<seiToneMappingTmp.coded_data_bit_depth;
max_output_num = 1<<seiToneMappingTmp.sei_bit_depth;
if (seiToneMappingTmp.model_id == 0)
{ // linear mapping with clipping
seiToneMappingTmp.min_value = u_v (32,"SEI: min_value", buf);
seiToneMappingTmp.max_value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -