📄 parset.c
字号:
/*!
**************************************************************************************
* \file
* parset.c
* \brief
* Picture and Sequence Parameter set generation and handling
* \date 25 November 2002
* \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 "global.h"
#include "contributors.h"
#include "mbuffer.h"
#include "parset.h"
#include "vlc.h"
// Local helpers
static int IdentifyProfile();
static int IdentifyLevel();
static int IdentifyNumRefFrames();
static int GenerateVUISequenceParameters();
extern ColocatedParams *Co_located;
/*!
*************************************************************************************
* \brief
* generates a sequence and picture parameter set and stores these in global
* active_sps and active_pps
*
* \return
* A NALU containing the Sequence ParameterSet
*
*************************************************************************************
*/
void GenerateParameterSets ()
{
seq_parameter_set_rbsp_t *sps = NULL;
pic_parameter_set_rbsp_t *pps = NULL;
sps = AllocSPS();
pps = AllocPPS();
FillParameterSetStructures (sps, pps);
active_sps = sps;
active_pps = pps;
}
/*!
*************************************************************************************
* \brief
* frees global parameter sets active_sps and active_pps
*
* \return
* A NALU containing the Sequence ParameterSet
*
*************************************************************************************
*/
void FreeParameterSets ()
{
FreeSPS (active_sps);
FreePPS (active_pps);
}
/*!
*************************************************************************************
* \brief
* int GenerateSeq_parameter_set_NALU ();
*
* \note
* Uses the global variables through FillParameterSetStructures()
*
* \return
* A NALU containing the Sequence ParameterSet
*
*************************************************************************************
*/
NALU_t *GenerateSeq_parameter_set_NALU ()
{
NALU_t *n = AllocNALU(64000);
int RBSPlen = 0;
int NALUlen;
byte rbsp[MAXRBSPSIZE];
RBSPlen = GenerateSeq_parameter_set_rbsp (active_sps, rbsp);
NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_SPS, NALU_PRIORITY_HIGHEST, 0, 1);
n->startcodeprefix_len = 4;
return n;
}
/*!
*************************************************************************************
* \brief
* NALU_t *GeneratePic_parameter_set_NALU ();
*
* \note
* Uses the global variables through FillParameterSetStructures()
*
* \return
* A NALU containing the Picture Parameter Set
*
*************************************************************************************
*/
NALU_t *GeneratePic_parameter_set_NALU()
{
NALU_t *n = AllocNALU(64000);
int RBSPlen = 0;
int NALUlen;
byte rbsp[MAXRBSPSIZE];
RBSPlen = GeneratePic_parameter_set_rbsp (active_pps, rbsp);
NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_PPS, NALU_PRIORITY_HIGHEST, 0, 1);
n->startcodeprefix_len = 4;
return n;
}
/*!
************************************************************************
* \brief
* FillParameterSetStructures: extracts info from global variables and
* generates a picture and sequence parameter set structure
*
* \param sps
* Sequence parameter set to be filled
* \param pps
* Picture parameter set to be filled
* \par
* Function reads all kinds of values from several global variables,
* including input-> and image-> and fills in the sps and pps. Many
* values are current hard-coded to defaults, especially most of the
* VUI stuff. Currently, the sps and pps structures are fixed length
* with the exception of the fully flexible FMO map (mode 6). This
* mode is not supported. Hence, the function does not need to
* allocate memory for the FMOmap, the pointer slice_group_id is
* always NULL. If one wants to implement FMO mode 6, one would need
* to malloc the memory for the map here, and the caller would need
* to free it after use.
*
* \par
* Limitations
* Currently, the encoder does not support multiple parameter sets,
* primarily because the config file does not support it. Hence the
* pic_parameter_set_id and the seq_parameter_set_id are always zero.
* If one day multiple parameter sets are implemented, it would
* make sense to break this function into two, one for the picture and
* one for the sequence.
* Currently, FMO is not supported
* The following pps and sps elements seem not to be used in the encoder
* or decoder and, hence, a guessed default value is conveyed:
*
* pps->num_ref_idx_l0_active_minus1 = img->num_ref_pic_active_fwd_minus1;
* pps->num_ref_idx_l1_active_minus1 = img->num_ref_pic_active_bwd_minus1;
* pps->chroma_qp_index_offset = 0;
* sps->required_frame_num_update_behaviour_flag = FALSE;
* sps->direct_temporal_constrained_flag = FALSE;
*
* \par
* Regarding the QP
* The previous software versions coded the absolute QP only in the
* slice header. This is kept, and the offset in the PPS is coded
* even if we could save bits by intelligently using this field.
*
************************************************************************
*/
void FillParameterSetStructures (seq_parameter_set_rbsp_t *sps,
pic_parameter_set_rbsp_t *pps)
{
unsigned i;
int frext_profile = ((IdentifyProfile()==FREXT_HP) ||
(IdentifyProfile()==FREXT_Hi10P) ||
(IdentifyProfile()==FREXT_Hi422) ||
(IdentifyProfile()==FREXT_Hi444));
// *************************************************************************
// Sequence Parameter Set
// *************************************************************************
assert (sps != NULL);
assert (pps != NULL);
// Profile and Level should be calculated using the info from the config
// file. Calculation is hidden in IndetifyProfile() and IdentifyLevel()
sps->profile_idc = IdentifyProfile();
sps->level_idc = IdentifyLevel();
// needs to be set according to profile
sps->constrained_set0_flag = 0;
sps->constrained_set1_flag = 0;
sps->constrained_set2_flag = 0;
sps->constrained_set3_flag = 0;
// Parameter Set ID hard coded to zero
sps->seq_parameter_set_id = 0;
// Fidelity Range Extensions stuff
sps->bit_depth_luma_minus8 = input->BitDepthLuma - 8;
sps->bit_depth_chroma_minus8 = input->BitDepthChroma - 8;
img->lossless_qpprime_flag = input->lossless_qpprime_y_zero_flag & (sps->profile_idc==FREXT_Hi444);
img->residue_transform_flag = input->residue_transform_flag;
//! POC stuff:
//! The following values are hard-coded in init_poc(). Apparently,
//! the poc implementation covers only a subset of the poc functionality.
//! Here, the same subset is implemented. Changes in the POC stuff have
//! also to be reflected here
sps->log2_max_frame_num_minus4 = log2_max_frame_num_minus4;
sps->log2_max_pic_order_cnt_lsb_minus4 = log2_max_pic_order_cnt_lsb_minus4;
sps->pic_order_cnt_type = input->pic_order_cnt_type;
sps->num_ref_frames_in_pic_order_cnt_cycle = img->num_ref_frames_in_pic_order_cnt_cycle;
sps->delta_pic_order_always_zero_flag = img->delta_pic_order_always_zero_flag;
sps->offset_for_non_ref_pic = img->offset_for_non_ref_pic;
sps->offset_for_top_to_bottom_field = img->offset_for_top_to_bottom_field;
for (i=0; i<img->num_ref_frames_in_pic_order_cnt_cycle; i++)
{
sps->offset_for_ref_frame[i] = img->offset_for_ref_frame[i];
}
// End of POC stuff
// Number of Reference Frames
sps->num_ref_frames = IdentifyNumRefFrames();
//required_frame_num_update_behaviour_flag hardcoded to zero
sps->gaps_in_frame_num_value_allowed_flag = FALSE; // double check
sps->frame_mbs_only_flag = !(input->PicInterlace || input->MbInterlace);
// Picture size, finally a simple one :-)
sps->pic_width_in_mbs_minus1 = (input->img_width/16) -1;
sps->pic_height_in_map_units_minus1 = ((input->img_height/16)/ (2 - sps->frame_mbs_only_flag)) - 1;
// a couple of flags, simple
sps->mb_adaptive_frame_field_flag = (FRAME_CODING != input->MbInterlace);
sps->direct_8x8_inference_flag = input->directInferenceFlag;
// Sequence VUI not implemented, signalled as not present
sps->vui_parameters_present_flag = (input->rgb_input_flag && input->yuv_format==3);
{
int PicWidthInMbs, PicHeightInMapUnits, FrameHeightInMbs;
int width, height;
PicWidthInMbs = (sps->pic_width_in_mbs_minus1 +1);
PicHeightInMapUnits = (sps->pic_height_in_map_units_minus1 +1);
FrameHeightInMbs = ( 2 - sps->frame_mbs_only_flag ) * PicHeightInMapUnits;
width = PicWidthInMbs * MB_BLOCK_SIZE;
height = FrameHeightInMbs * MB_BLOCK_SIZE;
Co_located = alloc_colocated (width, height,sps->mb_adaptive_frame_field_flag);
}
// *************************************************************************
// Picture Parameter Set
// *************************************************************************
pps->seq_parameter_set_id = 0;
pps->pic_parameter_set_id = 0;
pps->entropy_coding_mode_flag = (input->symbol_mode==UVLC?0:1);
// Fidelity Range Extensions stuff
if(frext_profile)
{
pps->transform_8x8_mode_flag = input->AllowTransform8x8 ? 1:0;
sps->seq_scaling_matrix_present_flag = (input->ScalingMatrixPresentFlag&1);
for(i=0; i<8; i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -