📄 configfile.c
字号:
else
{ // Terminate non-strings once whitespace is found
*p++ = '\0';
InItem = 0;
}
break;
case '"': // Begin/End of String
*p++ = '\0';
if (!InString)
{
items[item++] = p;
InItem = ~InItem;
}
else
InItem = 0;
InString = ~InString; // Toggle
break;
default:
if (!InItem)
{
items[item++] = p;
InItem = ~InItem;
}
p++;
}
}
item--;
for (i=0; i<item; i+= 3)
{
if (0 > (MapIdx = ParameterNameToMapIndex (items[i])))
{
snprintf (errortext, ET_SIZE, " Parsing error in config file: Parameter Name '%s' not recognized.", items[i]);
error (errortext, 300);
}
if (strcmp ("=", items[i+1]))
{
snprintf (errortext, ET_SIZE, " Parsing error in config file: '=' expected as the second token in each line.");
error (errortext, 300);
}
// Now interprete the Value, context sensitive...
switch (Map[MapIdx].Type)
{
case 0: // Numerical
if (1 != sscanf (items[i+2], "%d", &IntContent))
{
snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]);
error (errortext, 300);
}
* (int *) (Map[MapIdx].Place) = IntContent;
printf (".");
break;
case 1:
strncpy ((char *) Map[MapIdx].Place, items [i+2], FILE_NAME_SIZE);
printf (".");
break;
case 2: // Numerical double
if (1 != sscanf (items[i+2], "%lf", &DoubleContent))
{
snprintf (errortext, ET_SIZE, " Parsing error: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+2]);
error (errortext, 300);
}
* (double *) (Map[MapIdx].Place) = DoubleContent;
printf (".");
break;
default:
assert ("Unknown value type in the map definition of configfile.h");
}
}
memcpy (input, &configinput, sizeof (InputParameters));
}
/*!
***********************************************************************
* \brief
* Returns the index number from Map[] for a given parameter name.
* \param s
* parameter name string
* \return
* the index number if the string is a valid parameter name, \n
* -1 for error
***********************************************************************
*/
static int ParameterNameToMapIndex (char *s)
{
int i = 0;
while (Map[i].TokenName != NULL)
if (0==strcmp (Map[i].TokenName, s))
return i;
else
i++;
return -1;
};
/*!
************************************************************************
* \brief
* calculate Ceil(Log2(uiVal))
************************************************************************
*/
unsigned CeilLog2( unsigned uiVal)
{
unsigned uiTmp = uiVal-1;
unsigned uiRet = 0;
while( uiTmp != 0 )
{
uiTmp >>= 1;
uiRet++;
}
return uiRet;
}
/*!
***********************************************************************
* \brief
* Checks the input parameters for consistency.
***********************************************************************
*/
static void PatchInp ()
{
int bitdepth_qp_scale = 6*(input->BitDepthLuma - 8);
// These variables are added for FMO
FILE * sgfile=NULL;
int i;
int frame_mb_only;
int mb_width, mb_height, mapunit_height;
// input->BitDepthChroma = input->BitDepthLuma;
input->LowPassForIntra8x8 = 1; //low pass is always used
// consistency check of QPs
if (input->qp0 > MAX_QP || input->qp0 < (MIN_QP - bitdepth_qp_scale))
{
snprintf(errortext, ET_SIZE, "Error in input parameter QPIlice. Check configuration file");
error (errortext, 400);
}
if (input->qpN > MAX_QP || input->qpN < (MIN_QP - bitdepth_qp_scale))
{
snprintf(errortext, ET_SIZE, "Error in input parameter QPPlice. Check configuration file");
error (errortext, 400);
}
if (input->qpB > MAX_QP || input->qpB < (MIN_QP - bitdepth_qp_scale))
{
snprintf(errortext, ET_SIZE, "Error in input parameter QPBSlice. Check configuration file");
error (errortext, 400);
}
if ((input->qpBSoffset + input->qpB > MAX_QP) || (input->qpBSoffset + input->qpB < (MIN_QP - bitdepth_qp_scale)))
{
snprintf(errortext, ET_SIZE, "Error in input parameter qpBSoffset. Check configuration file");
error (errortext, 400);
}
#ifdef _CHANGE_QP_
if (input->qp2start && (input->qpB2 > MAX_QP || input->qpB2 < (MIN_QP - bitdepth_qp_scale)))
{
snprintf(errortext, ET_SIZE, "Error in input parameter ChangeQPB. Check configuration file");
error (errortext, 400);
}
if (input->qp2start && (input->qp02 > MAX_QP || input->qp02 < (MIN_QP - bitdepth_qp_scale)))
{
snprintf(errortext, ET_SIZE, "Error in input parameter ChangeQIB. Check configuration file");
error (errortext, 400);
}
if (input->qp2start && (input->qpN2 > MAX_QP || input->qpN2 < (MIN_QP - bitdepth_qp_scale)))
{
snprintf(errortext, ET_SIZE, "Error in input parameter ChangeQPP. Check configuration file");
error (errortext, 400);
}
if (input->qp2start && ((input->qpBs2offset + input->qpB2 > MAX_QP) || (input->qpBs2offset + input->qpB2 < (MIN_QP - bitdepth_qp_scale))))
{
snprintf(errortext, ET_SIZE, "Error in input parameter ChangeQPBs. Check configuration file");
error (errortext, 400);
}
#endif
if (input->qpsp > MAX_QP || input->qpsp < (MIN_QP - bitdepth_qp_scale))
{
snprintf(errortext, ET_SIZE, "Error in input parameter quant_sp. Check configuration file");
error (errortext, 400);
}
if (input->qpsp_pred > MAX_QP || input->qpsp_pred < (MIN_QP - bitdepth_qp_scale))
{
snprintf(errortext, ET_SIZE, "Error in input parameter quant_sp_pred. Check configuration file");
error (errortext, 400);
}
if (input->sp_periodicity <0)
{
snprintf(errortext, ET_SIZE, "Error in input parameter sp_periodicity. Check configuration file");
error (errortext, 400);
}
if (input->FrameRate < 0.0 || input->FrameRate>100.0)
{
snprintf(errortext, ET_SIZE, "Error in input parameter FrameRate, check configuration file");
error (errortext, 400);
}
if (input->FrameRate == 0.0)
input->FrameRate = INIT_FRAME_RATE;
if (input->idr_enable < 0 || input->idr_enable > 1)
{
snprintf(errortext, ET_SIZE, "Error in input parameter IDRIntraEnable, check configuration file");
error (errortext, 400);
}
if (input->start_frame < 0 )
{
snprintf(errortext, ET_SIZE, "Error in input parameter StartFrame, Check configuration file.");
error (errortext, 400);
}
// consistency check num_ref_frames
if (input->num_ref_frames<1) input->num_ref_frames=1;
// consistency check size information
if (input->img_height % 16 != 0 || input->img_width % 16 != 0)
{
snprintf(errortext, ET_SIZE, "Unsupported image format x=%d,y=%d, must be a multiple of 16",input->img_width,input->img_height);
error (errortext, 400);
}
#ifdef _LEAKYBUCKET_
// consistency check for Number of Leaky Bucket parameters
if(input->NumberLeakyBuckets < 2 || input->NumberLeakyBuckets > 255)
{
snprintf(errortext, ET_SIZE, "Number of Leaky Buckets should be between 2 and 255 but is %d \n", input->NumberLeakyBuckets);
error(errortext, 400);
}
#endif
// check range of filter offsets
if (input->LFAlphaC0Offset > 6 || input->LFAlphaC0Offset < -6)
{
snprintf(errortext, ET_SIZE, "Error in input parameter LFAlphaC0Offset, check configuration file");
error (errortext, 400);
}
if (input->LFBetaOffset > 6 || input->LFBetaOffset < -6)
{
snprintf(errortext, ET_SIZE, "Error in input parameter LFBetaOffset, check configuration file");
error (errortext, 400);
}
// Set block sizes
input->blc_size[0][0]=16;
input->blc_size[0][1]=16;
input->blc_size[1][0]=16;
input->blc_size[1][1]=16;
input->blc_size[2][0]=16;
input->blc_size[2][1]= 8;
input->blc_size[3][0]= 8;
input->blc_size[3][1]=16;
input->blc_size[4][0]= 8;
input->blc_size[4][1]= 8;
input->blc_size[5][0]= 8;
input->blc_size[5][1]= 4;
input->blc_size[6][0]= 4;
input->blc_size[6][1]= 8;
input->blc_size[7][0]= 4;
input->blc_size[7][1]= 4;
// set proper log2_max_frame_num_minus4.
{
int storedBplus1 = (input->StoredBPictures ) ? input->successive_Bframe + 1: 1;
// log2_max_frame_num_minus4 = max( (int)(CeilLog2(input->no_frames * storedBplus1))-4, 0);
if (input->Log2MaxFrameNum < 4)
log2_max_frame_num_minus4 = max( (int)(CeilLog2(input->no_frames *storedBplus1 ))-4, 0);
else
log2_max_frame_num_minus4 = input->Log2MaxFrameNum - 4;
}
log2_max_pic_order_cnt_lsb_minus4 = max( (int)(CeilLog2( 2*input->no_frames * (input->jumpd + 1))) -4, 0);
if (input->partition_mode < 0 || input->partition_mode > 1)
{
snprintf(errortext, ET_SIZE, "Unsupported Partition mode, must be between 0 and 1");
error (errortext, 400);
}
if (input->of_mode < 0 || input->of_mode > 2)
{
snprintf(errortext, ET_SIZE, "Unsupported Output file mode, must be between 0 and 1");
error (errortext, 400);
}
// B picture consistency check
if(input->successive_Bframe > input->jumpd)
{
snprintf(errortext, ET_SIZE, "Number of B-frames %d can not exceed the number of frames skipped", input->successive_Bframe);
error (errortext, 400);
}
// Direct Mode consistency check
if(input->successive_Bframe && input->direct_spatial_mv_pred_flag != DIR_SPATIAL && input->direct_spatial_mv_pred_flag != DIR_TEMPORAL)
{
snprintf(errortext, ET_SIZE, "Unsupported direct mode=%d, use TEMPORAL=0 or SPATIAL=1", input->direct_spatial_mv_pred_flag);
error (errortext, 400);
}
if (input->PicInterlace>0 || input->MbInterlace>0)
{
if (input->directInferenceFlag==0)
printf("\nDirectInferenceFlag set to 1 due to interlace coding.");
input->directInferenceFlag=1;
}
if (input->PicInterlace>0)
{
if (input->IntraBottom!=0 && input->IntraBottom!=1)
{
snprintf(errortext, ET_SIZE, "Incorrect value %d for IntraBottom. Use 0 (disable) or 1 (enable).", input->IntraBottom);
error (errortext, 400);
}
}
// Cabac/UVLC consistency check
if (input->symbol_mode != UVLC && input->symbol_mode != CABAC)
{
snprintf (errortext, ET_SIZE, "Unsupported symbol mode=%d, use UVLC=0 or CABAC=1",input->symbol_mode);
error (errortext, 400);
}
// Open Files
if ((p_in=open(input->infile, OPENFLAGS_READ))==-1)
{
snprintf(errortext, ET_SIZE, "Input file %s does not exist",input->infile);
error (errortext, 500);
}
if (strlen (input->ReconFile) > 0 && (p_dec=open(input->ReconFile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -