📄 configfile.c
字号:
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);
printf ("\n\tParsing error in config file: Parameter Name '%s' not recognized.", items[i]);
continue;
}
if (strcasecmp ("=", items[i+1]))
{
snprintf (errortext, ET_SIZE, " Parsing error in config file: '=' expected as the second token in each line.");
error (errortext, 300);
}
// Now interpret 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:
error ("Unknown value type in the map definition of configfile.h",-1);
}
}
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==strcasecmp (Map[i].TokenName, s))
return i;
else
i++;
return -1;
}
/*!
***********************************************************************
* \brief
* Sets initial values for encoding parameters.
* \return
* -1 for error
***********************************************************************
*/
static int InitEncoderParams(void)
{
int i = 0;
while (Map[i].TokenName != NULL)
{
if (Map[i].Type == 0)
* (int *) (Map[i].Place) = (int) Map[i].Default;
else if (Map[i].Type == 2)
* (double *) (Map[i].Place) = Map[i].Default;
i++;
}
return -1;
}
/*!
***********************************************************************
* \brief
* Validates encoding parameters.
* \return
* -1 for error
***********************************************************************
*/
static int TestEncoderParams(int bitdepth_qp_scale)
{
int i = 0;
while (Map[i].TokenName != NULL)
{
if (Map[i].param_limits == 1)
{
if (Map[i].Type == 0)
{
if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit || * (int *) (Map[i].Place) > (int) Map[i].max_limit )
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, (int) Map[i].min_limit,(int)Map[i].max_limit );
error (errortext, 400);
}
}
else if (Map[i].Type == 2)
{
if ( * (double *) (Map[i].Place) < Map[i].min_limit || * (double *) (Map[i].Place) > Map[i].max_limit )
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%.2f, %.2f] range.", Map[i].TokenName,Map[i].min_limit ,Map[i].max_limit );
error (errortext, 400);
}
}
}
else if (Map[i].param_limits == 2)
{
if (Map[i].Type == 0)
{
if ( * (int *) (Map[i].Place) < (int) Map[i].min_limit )
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %d.", Map[i].TokenName, (int) Map[i].min_limit);
error (errortext, 400);
}
}
else if (Map[i].Type == 2)
{
if ( * (double *) (Map[i].Place) < Map[i].min_limit )
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should not be smaller than %2.f.", Map[i].TokenName,Map[i].min_limit);
error (errortext, 400);
}
}
}
else if (Map[i].param_limits == 3) // Only used for QPs
{
if (Map[i].Type == 0)
{
if ( * (int *) (Map[i].Place) < (int) (Map[i].min_limit - bitdepth_qp_scale) || * (int *) (Map[i].Place) > (int) Map[i].max_limit )
{
snprintf(errortext, ET_SIZE, "Error in input parameter %s. Check configuration file. Value should be in [%d, %d] range.", Map[i].TokenName, (int) (Map[i].min_limit - bitdepth_qp_scale),(int)Map[i].max_limit );
error (errortext, 400);
}
}
}
i++;
}
return -1;
}
/*!
***********************************************************************
* \brief
* Outputs encoding parameters.
* \return
* -1 for error
***********************************************************************
*/
static int DisplayEncoderParams(void)
{
int i = 0;
printf("******************************************************\n");
printf("* Encoder Parameters *\n");
printf("******************************************************\n");
while (Map[i].TokenName != NULL)
{
if (Map[i].Type == 0)
printf("Parameter %s = %d\n",Map[i].TokenName,* (int *) (Map[i].Place));
else if (Map[i].Type == 1)
printf("Parameter %s = ""%s""\n",Map[i].TokenName,(char *) (Map[i].Place));
else if (Map[i].Type == 2)
printf("Parameter %s = %.2f\n",Map[i].TokenName,* (double *) (Map[i].Place));
i++;
}
printf("******************************************************\n");
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
* read the slice group configuration file. Returns without action
* if type is not 0, 2 or 6
************************************************************************
*/
void read_slice_group_info()
{
FILE * sgfile=NULL;
int i;
int ret;
if ((input->slice_group_map_type != 0) && (input->slice_group_map_type != 2) && (input->slice_group_map_type != 6))
{
// nothing to do
return;
}
// do we have a file name (not only NULL character)
if (strlen (input->SliceGroupConfigFileName) <= 1)
error ("No slice group config file name specified", 500);
// open file
sgfile = fopen(input->SliceGroupConfigFileName,"r");
if ( NULL==sgfile )
{
snprintf(errortext, ET_SIZE, "Error opening slice group file %s", input->SliceGroupConfigFileName);
error (errortext, 500);
}
switch (input->slice_group_map_type)
{
case 0:
input->run_length_minus1=(int *)malloc(sizeof(int)*(input->num_slice_groups_minus1+1));
if ( NULL==input->run_length_minus1 )
{
fclose(sgfile);
no_mem_exit("PatchInp: input->run_length_minus1");
}
// each line contains one 'run_length_minus1' value
for(i=0;i<=input->num_slice_groups_minus1;i++)
{
ret = fscanf(sgfile,"%d",(input->run_length_minus1+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", i+1);
error (errortext, 500);
}
}
break;
case 2:
input->top_left=(int *)malloc(sizeof(int)*input->num_slice_groups_minus1);
input->bottom_right=(int *)malloc(sizeof(int)*input->num_slice_groups_minus1);
if (NULL==input->top_left)
{
fclose(sgfile);
no_mem_exit("PatchInp: input->top_left");
}
if (NULL==input->bottom_right)
{
fclose(sgfile);
no_mem_exit("PatchInp: input->bottom_right");
}
// every two lines contain 'top_left' and 'bottom_right' value
for(i=0;i<input->num_slice_groups_minus1;i++)
{
ret = fscanf(sgfile,"%d",(input->top_left+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", 2*i +1);
error (errortext, 500);
}
ret = fscanf(sgfile,"%d",(input->bottom_right+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", 2*i + 2);
error (errortext, 500);
}
}
break;
case 6:
{
int tmp;
int frame_mb_only;
int mb_width, mb_height, mapunit_height;
frame_mb_only = !(input->PicInterlace || input->MbInterlace);
mb_width= (input->img_width+img->auto_crop_right)>>4;
mb_height= (input->img_height+img->auto_crop_bottom)>>4;
mapunit_height=mb_height/(2-frame_mb_only);
input->slice_group_id=(byte * ) malloc(sizeof(byte)*mapunit_height*mb_width);
if (NULL==input->slice_group_id)
{
fclose(sgfile);
no_mem_exit("PatchInp: input->slice_group_id");
}
// each line contains slice_group_id for one Macroblock
for (i=0;i<mapunit_height*mb_width;i++)
{
ret = fscanf(sgfile,"%d", &tmp);
input->slice_group_id[i]= (byte) tmp;
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", i + 1);
error (errortext, 500);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -