📄 parset.c
字号:
/*!
************************************************************************
* \file
* parset.c
* \brief
* Parameter Sets
* \author
* Main contributors (see contributors.h for copyright, address and affiliation details)
* - Stephan Wenger <stewe@cs.tu-berlin.de>
*
***********************************************************************
*/
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "global.h"
#include "parsetcommon.h"
#include "parset.h"
#include "nalu.h"
#include "memalloc.h"
#include "vlc.h"
#include "mbuffer.h"
// #include "erc_api.h"
#if TRACE
#define SYMTRACESTRING(s) strncpy(sym->tracestring,s,TRACESTRING_SIZE)
#else
#define SYMTRACESTRING(s) // do nothing
#endif
const byte ZZ_SCAN[16] =
{ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
};
const byte ZZ_SCAN8[64] =
{ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
};
extern int UsedBits; // for internal statistics, is adjusted by se_v, ue_v, u_1
extern ColocatedParams *Co_located;
extern int quant_intra_default[16];
extern int quant_inter_default[16];
extern int quant8_intra_default[64];
extern int quant8_inter_default[64];
seq_parameter_set_rbsp_t SeqParSet[MAXSPS];
pic_parameter_set_rbsp_t PicParSet[MAXPPS];
extern StorablePicture* dec_picture;
extern void init_frext(struct img_par *img);
// syntax for scaling list matrix values
void Scaling_List(int *scalingList, int sizeOfScalingList, Boolean *UseDefaultScalingMatrix, Bitstream *s)
{
int j, scanj;
int delta_scale, lastScale, nextScale;
lastScale = 8;
nextScale = 8;
for(j=0; j<sizeOfScalingList; j++)
{
scanj = (sizeOfScalingList==16) ? ZZ_SCAN[j]:ZZ_SCAN8[j];
if(nextScale!=0)
{
delta_scale = se_v ( " : delta_sl " , s);
nextScale = (lastScale + delta_scale + 256) % 256;
*UseDefaultScalingMatrix = (Boolean) (scanj==0 && nextScale==0);
}
scalingList[scanj] = (nextScale==0) ? lastScale:nextScale;
lastScale = scalingList[scanj];
}
}
// fill sps with content of p
int InterpretSPS (DataPartition *p, seq_parameter_set_rbsp_t *sps)
{
unsigned i;
int reserved_zero;
Bitstream *s = p->bitstream;
assert (p != NULL);
assert (p->bitstream != NULL);
assert (p->bitstream->streamBuffer != 0);
assert (sps != NULL);
UsedBits = 0;
sps->profile_idc = u_v (8, "SPS: profile_idc" , s);
if ((sps->profile_idc!=66 ) &&
(sps->profile_idc!=77 ) &&
(sps->profile_idc!=88 ) &&
(sps->profile_idc!=100 ) &&
(sps->profile_idc!=110 ) &&
(sps->profile_idc!=122 ) &&
(sps->profile_idc!=144 ))
{
return UsedBits;
}
sps->constrained_set0_flag = u_1 ( "SPS: constrained_set0_flag" , s);
sps->constrained_set1_flag = u_1 ( "SPS: constrained_set1_flag" , s);
sps->constrained_set2_flag = u_1 ( "SPS: constrained_set2_flag" , s);
sps->constrained_set3_flag = u_1 ( "SPS: constrained_set3_flag" , s);
reserved_zero = u_v (4, "SPS: reserved_zero_4bits" , s);
assert (reserved_zero==0);
sps->level_idc = u_v (8, "SPS: level_idc" , s);
sps->seq_parameter_set_id = ue_v ("SPS: seq_parameter_set_id" , s);
// output to h264_view.txt
//fprintf(img->fpinfo, "SPS: profile_idc (%3d)\n", sps->profile_idc);
//fprintf(img->fpinfo, "SPS: constrained_set0_flag (%3d)\n", sps->constrained_set0_flag);
//fprintf(img->fpinfo, "SPS: constrained_set1_flag (%3d)\n", sps->constrained_set1_flag);
//fprintf(img->fpinfo, "SPS: constrained_set2_flag (%3d)\n", sps->constrained_set2_flag);
//fprintf(img->fpinfo, "SPS: constrained_set3_flag (%3d)\n", sps->constrained_set3_flag);
//fprintf(img->fpinfo, "SPS: reserved_zero_4bits (%3d)\n", reserved_zero);
//fprintf(img->fpinfo, "SPS: level_idc (%3d)\n", sps->level_idc);
//fprintf(img->fpinfo, "SPS: seq_parameter_set_id (%3d)\n", sps->seq_parameter_set_id);
// Fidelity Range Extensions stuff
sps->chroma_format_idc = 1;
sps->bit_depth_luma_minus8 = 0;
sps->bit_depth_chroma_minus8 = 0;
img->lossless_qpprime_flag = 0;
if((sps->profile_idc==FREXT_HP ) ||
(sps->profile_idc==FREXT_Hi10P) ||
(sps->profile_idc==FREXT_Hi422) ||
(sps->profile_idc==FREXT_Hi444))
{
sps->chroma_format_idc = ue_v ("SPS: chroma_format_idc" , s);
//fprintf(img->fpinfo, "SPS: chroma_format_idc (%3d)\n", sps->chroma_format_idc);
// Residue Color Transform
if(sps->chroma_format_idc == 3)
{
i = u_1 ("SPS: residue_transform_flag" , s);
//fprintf(img->fpinfo, "SPS: residue_transform_flag (%3d)\n", i);
if (i==1)
{
// error ("[Deprecated High444 Profile] residue_transform_flag = 1 is no longer supported", 1000);
}
}
sps->bit_depth_luma_minus8 = ue_v ("SPS: bit_depth_luma_minus8" , s);
sps->bit_depth_chroma_minus8 = ue_v ("SPS: bit_depth_chroma_minus8" , s);
img->lossless_qpprime_flag = u_1 ("SPS: lossless_qpprime_y_zero_flag" , s);
//fprintf(img->fpinfo, "SPS: bit_depth_luma_minus8 (%3d)\n", sps->bit_depth_luma_minus8);
//fprintf(img->fpinfo, "SPS: bit_depth_chroma_minus8 (%3d)\n", sps->bit_depth_chroma_minus8);
//fprintf(img->fpinfo, "SPS: lossless_qpprime_y_zero_flag (%3d)\n", img->lossless_qpprime_flag);
sps->seq_scaling_matrix_present_flag = u_1 ( "SPS: seq_scaling_matrix_present_flag" , s);
//fprintf(img->fpinfo, "SPS: seq_scaling_matrix_present_flag (%3d)\n", sps->seq_scaling_matrix_present_flag);
if(sps->seq_scaling_matrix_present_flag)
{
for(i=0; i<8; i++)
{
sps->seq_scaling_list_present_flag[i] = u_1 ( "SPS: seq_scaling_list_present_flag" , s);
if(sps->seq_scaling_list_present_flag[i])
{
if(i<6)
Scaling_List(sps->ScalingList4x4[i], 16, &sps->UseDefaultScalingMatrix4x4Flag[i], s);
else
Scaling_List(sps->ScalingList8x8[i-6], 64, &sps->UseDefaultScalingMatrix8x8Flag[i-6], s);
}
}
}
}
sps->log2_max_frame_num_minus4 = ue_v ("SPS: log2_max_frame_num_minus4" , s);
sps->pic_order_cnt_type = ue_v ("SPS: pic_order_cnt_type" , s);
//fprintf(img->fpinfo, "SPS: log2_max_frame_num_minus4 (%3d)\n", sps->log2_max_frame_num_minus4);
//fprintf(img->fpinfo, "SPS: pic_order_cnt_type (%3d)\n", sps->pic_order_cnt_type);
if (sps->pic_order_cnt_type == 0)
{
sps->log2_max_pic_order_cnt_lsb_minus4 = ue_v ("SPS: log2_max_pic_order_cnt_lsb_minus4" , s);
//fprintf(img->fpinfo, "SPS: log2_max_pic_order_cnt_lsb_minus4 (%3d)\n", sps->log2_max_pic_order_cnt_lsb_minus4);
}
else if (sps->pic_order_cnt_type == 1)
{
sps->delta_pic_order_always_zero_flag = u_1 ("SPS: delta_pic_order_always_zero_flag" , s);
sps->offset_for_non_ref_pic = se_v ("SPS: offset_for_non_ref_pic" , s);
sps->offset_for_top_to_bottom_field = se_v ("SPS: offset_for_top_to_bottom_field" , s);
sps->num_ref_frames_in_pic_order_cnt_cycle = ue_v ("SPS: num_ref_frames_in_pic_order_cnt_cycle" , s);
//fprintf(img->fpinfo, "SPS: delta_pic_order_always_zero_flag (%3d)\n", sps->delta_pic_order_always_zero_flag);
//fprintf(img->fpinfo, "SPS: offset_for_non_ref_pic (%3d)\n", sps->offset_for_non_ref_pic);
//fprintf(img->fpinfo, "SPS: offset_for_top_to_bottom_field (%3d)\n", sps->offset_for_top_to_bottom_field);
//fprintf(img->fpinfo, "SPS: num_ref_frames_in_pic_order_cnt_cycle (%3d)\n", sps->num_ref_frames_in_pic_order_cnt_cycle);
for(i=0; i<sps->num_ref_frames_in_pic_order_cnt_cycle; i++)
sps->offset_for_ref_frame[i] = se_v ("SPS: offset_for_ref_frame[i]" , s);
}
sps->num_ref_frames = ue_v ("SPS: num_ref_frames" , s);
sps->gaps_in_frame_num_value_allowed_flag = u_1 ("SPS: gaps_in_frame_num_value_allowed_flag" , s);
sps->pic_width_in_mbs_minus1 = ue_v ("SPS: pic_width_in_mbs_minus1" , s);
sps->pic_height_in_map_units_minus1 = ue_v ("SPS: pic_height_in_map_units_minus1" , s);
sps->frame_mbs_only_flag = u_1 ("SPS: frame_mbs_only_flag" , s);
//fprintf(img->fpinfo, "SPS: num_ref_frames (%3d)\n", sps->num_ref_frames);
//fprintf(img->fpinfo, "SPS: gaps_in_frame_num_value_allowed_flag (%3d)\n", sps->gaps_in_frame_num_value_allowed_flag);
//fprintf(img->fpinfo, "SPS: pic_width_in_mbs_minus1 (%3d)\n", sps->pic_width_in_mbs_minus1);
//fprintf(img->fpinfo, "SPS: pic_height_in_map_units_minus1 (%3d)\n", sps->pic_height_in_map_units_minus1);
//fprintf(img->fpinfo, "SPS: frame_mbs_only_flag (%3d)\n", sps->frame_mbs_only_flag);
if (!sps->frame_mbs_only_flag)
{
sps->mb_adaptive_frame_field_flag = u_1 ("SPS: mb_adaptive_frame_field_flag" , s);
//fprintf(img->fpinfo, "SPS: mb_adaptive_frame_field_flag (%3d)\n", sps->mb_adaptive_frame_field_flag);
}
sps->direct_8x8_inference_flag = u_1 ("SPS: direct_8x8_inference_flag" , s);
sps->frame_cropping_flag = u_1 ("SPS: frame_cropping_flag" , s);
//fprintf(img->fpinfo, "SPS: direct_8x8_inference_flag (%3d)\n", sps->direct_8x8_inference_flag);
//fprintf(img->fpinfo, "SPS: frame_cropping_flag (%3d)\n", sps->frame_cropping_flag);
if (sps->frame_cropping_flag)
{
sps->frame_cropping_rect_left_offset = ue_v ("SPS: frame_cropping_rect_left_offset" , s);
sps->frame_cropping_rect_right_offset = ue_v ("SPS: frame_cropping_rect_right_offset" , s);
sps->frame_cropping_rect_top_offset = ue_v ("SPS: frame_cropping_rect_top_offset" , s);
sps->frame_cropping_rect_bottom_offset = ue_v ("SPS: frame_cropping_rect_bottom_offset" , s);
//fprintf(img->fpinfo, "SPS: frame_cropping_rect_left_offset (%3d)\n", sps->frame_cropping_rect_left_offset);
//fprintf(img->fpinfo, "SPS: frame_cropping_rect_right_offset (%3d)\n", sps->frame_cropping_rect_right_offset);
//fprintf(img->fpinfo, "SPS: frame_cropping_rect_top_offset (%3d)\n", sps->frame_cropping_rect_top_offset);
//fprintf(img->fpinfo, "SPS: frame_cropping_rect_bottom_offset (%3d)\n", sps->frame_cropping_rect_bottom_offset);
}
sps->vui_parameters_present_flag = (Boolean) u_1 ("SPS: vui_parameters_present_flag" , s);
//fprintf(img->fpinfo, "SPS: vui_parameters_present_flag (%3d)\n", sps->vui_parameters_present_flag);
InitVUI(sps);
ReadVUI(p, sps);
sps->Valid = TRUE;
return UsedBits;
}
void InitVUI(seq_parameter_set_rbsp_t *sps)
{
sps->vui_seq_parameters.matrix_coefficients = 2;
}
int ReadVUI(DataPartition *p, seq_parameter_set_rbsp_t *sps)
{
Bitstream *s = p->bitstream;
if (sps->vui_parameters_present_flag)
{
sps->vui_seq_parameters.aspect_ratio_info_present_flag = u_1 ("VUI: aspect_ratio_info_present_flag" , s);
if (sps->vui_seq_parameters.aspect_ratio_info_present_flag)
{
sps->vui_seq_parameters.aspect_ratio_idc = u_v ( 8, "VUI: aspect_ratio_idc" , s);
if (255==sps->vui_seq_parameters.aspect_ratio_idc)
{
sps->vui_seq_parameters.sar_width = u_v (16, "VUI: sar_width" , s);
sps->vui_seq_parameters.sar_height = u_v (16, "VUI: sar_height" , s);
}
}
sps->vui_seq_parameters.overscan_info_present_flag = u_1 ("VUI: overscan_info_present_flag" , s);
if (sps->vui_seq_parameters.overscan_info_present_flag)
{
sps->vui_seq_parameters.overscan_appropriate_flag = u_1 ("VUI: overscan_appropriate_flag" , s);
}
sps->vui_seq_parameters.video_signal_type_present_flag = u_1 ("VUI: video_signal_type_present_flag" , s);
if (sps->vui_seq_parameters.video_signal_type_present_flag)
{
sps->vui_seq_parameters.video_format = u_v ( 3,"VUI: video_format" , s);
sps->vui_seq_parameters.video_full_range_flag = u_1 ( "VUI: video_full_range_flag" , s);
sps->vui_seq_parameters.colour_description_present_flag = u_1 ( "VUI: color_description_present_flag" , s);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -