📄 parset.c
字号:
/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2001, International Telecommunications Union, Geneva
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the user without any
* license fee or royalty on an "as is" basis. The ITU disclaims
* any and all warranties, whether express, implied, or
* statutory, including any implied warranties of merchantability
* or of fitness for a particular purpose. In no event shall the
* contributor or the ITU be liable for any incidental, punitive, or
* consequential damages of any kind whatsoever arising from the
* use of these programs.
*
* This disclaimer of warranty extends to the user of these programs
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The ITU does not represent or warrant that the programs furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of ITU-T Recommendations, including
* shareware, may be subject to royalty fees to patent holders.
* Information regarding the ITU-T patent policy is available from
* the ITU Web site at http://www.itu.int.
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE ITU-T PATENT POLICY.
************************************************************************
*/
/*!
**************************************************************************************
* \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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <malloc.h>
#include <string.h>
#include "contributors.h"
#include "parsetcommon.h"
#include "nalu.h"
#include "parset.h"
#include "fmo.h"
#include "global.h"
#include "vlc.h"
// Local helpers
static int IdentifyProfile();
static int IdentifyLevel();
static int IdentifyNumRefFrames();
static int GenerateVUISequenceParameters();
/*!
*************************************************************************************
* \brief
* int GenerateSeq_parameter_set_NALU ();
*
* \param
* None. Uses the global variables through FillParameterSetStructures()
*
* \return
* A NALU containing the Sequence ParameterSet
*
*************************************************************************************
*/
NALU_t *GenerateSeq_parameter_set_NALU ()
{
seq_parameter_set_rbsp_t *sps = NULL;
pic_parameter_set_rbsp_t *pps = NULL;
NALU_t *n = AllocNALU(64000);
int RBSPlen = 0;
int NALUlen;
byte rbsp[MAXRBSPSIZE];
sps = AllocSPS();
pps = AllocPPS();
FillParameterSetStructures (sps, pps);
RBSPlen = GenerateSeq_parameter_set_rbsp (sps, rbsp);
NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_SPS, NALU_PRIORITY_HIGHEST, 0, 1);
n->startcodeprefix_len = 4;
FreeSPS (sps);
FreePPS (pps);
return n;
}
/*!
*************************************************************************************
* \brief
* NALU_t *GeneratePic_parameter_set_NALU ();
*
* \param
* None. Uses the global variables through FillParameterSetStructures()
*
* \return
* A NALU containing the Picture Parameter Set
*
*************************************************************************************
*/
NALU_t *GeneratePic_parameter_set_NALU()
{
seq_parameter_set_rbsp_t *sps = NULL;
pic_parameter_set_rbsp_t *pps = NULL;
NALU_t *n = AllocNALU(64000);
int RBSPlen = 0;
int NALUlen;
byte rbsp[MAXRBSPSIZE];
sps = AllocSPS();
pps = AllocPPS();
FillParameterSetStructures (sps, pps);
RBSPlen = GeneratePic_parameter_set_rbsp (pps, rbsp);
NALUlen = RBSPtoNALU (rbsp, n, RBSPlen, NALU_TYPE_PPS, NALU_PRIORITY_HIGHEST, 0, 1);
n->startcodeprefix_len = 4;
FreeSPS (sps);
FreePPS (pps);
return n;
}
/*!
************************************************************************
* \brief
* FillParameterSetStructures: extracts info from global variables and
* generates a picture and sequence parameter set structure
*
* \par Input:
* seq_parameter_set_rbsp_t *sps, Sequence parameter set to be filled
* pic_parameter_set_rbsp_t *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;
// *************************************************************************
// 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();
sps->more_than_one_slice_group_allowed_flag = (input->FmoType!=0);
// no out of order slice support
sps->arbitrary_slice_order_allowed_flag = 0;
sps->redundant_slices_allowed_flag = (input->redundant_slice_flag);
// Parameter Set ID hardcoded to zero
sps->seq_parameter_set_id = 0;
//! 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; // POC200301
sps->pic_order_cnt_type = img->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;
// This is the only one used, because num_ref_frames_in_pic_order_cnt_cycle
// is hard coded to 1.
sps->offset_for_ref_frame[0] = img->offset_for_ref_frame[0];
// End of POC stuff
// Number of Reference Frames
sps->num_ref_frames = IdentifyNumRefFrames();
//required_frame_num_update_behaviour_flag hardcoded to zero
sps->required_frame_num_update_behaviour_flag = FALSE; // double check
sps->frame_mbs_only_flag = (input->InterlaceCodingOption == FRAME_CODING);
// 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 = (input->InterlaceCodingOption == MB_CODING);
sps->direct_8x8_inference_flag = FALSE;
// Sequence VUI not implemented, signalled as not present
sps->vui_parameters_present_flag = FALSE;
// *************************************************************************
// Picture Parameter Set
// *************************************************************************
pps->seq_parameter_set_id = 0;
pps->pic_parameter_set_id = 0;
pps->entropy_coding_mode = (input->symbol_mode==UVLC?0:1);
// JVT-Fxxx (by Stephan Wenger, make this flag unconditional
pps->pic_order_present_flag = img->pic_order_present_flag;
// Begin FMO stuff
pps->num_slice_groups_minus1 = input->num_slice_groups_minus1;
if (pps->num_slice_groups_minus1 > 0)
switch (input->mb_allocation_map_type)
{
case 0:
pps->slice_group_map_type = 6; // This implementation always uses the fully flexible map
printf ("Param.c: FMO type 0 not yet signalled, using 6 instead\n");
goto FMOTYPE6;
// This code should work as soon as the re-generation of the MBAmap in
// the decoder does its job
// pps->mb_slice_group_map_type = 0; // according to the draft
// for (i=0; i< pps->num_slice_groups_minus1+1; i++)
// pps->run_length[i] = img->width/16; // Line interleaving
break;
case 1:
pps->slice_group_map_type = 6; // This implementation always uses the fully flexible map
printf ("Param.c: FMO type 1 not yet signalled, using 6 instead\n");
goto FMOTYPE6;
// This code should work as soon as the re-generation of the MBAmap in
// the decoder does its job
// pps->mb_slice_group_map_type = 1; // according to the draft
break;
case 2:
assert(pps->num_slice_groups_minus1 == 1); // restriction of the config file
for(i=0; i<pps->num_slice_groups_minus1; i++)
{
pps->top_left[i] = input->top_left_mb;
pps->bottom_right[i] = input->bottom_right_mb;
}
break;
case 3:
case 4:
case 5:
pps->slice_group_change_direction_flag = input->slice_group_change_direction;
pps->slice_group_change_rate_minus1 = input->slice_group_change_rate_minus1;
break;
case 6:
FMOTYPE6:
pps->slice_group_map_type = 6; // This implementation always uses the fully flexible map
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -