⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configfile.c

📁 G729、h263、h264、MPEG4四种最流行的音频和视频标准的压缩和解压算法的源代码.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
      case '#':                 // Found comment
        *p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string
        while (*p != '\n' && p < bufend)  // Skip till EOL or EOF, whichever comes first
          p++;
        InString = 0;
        InItem = 0;
        break;
      case '\n':
        InItem = 0;
        InString = 0;
        *p++='\0';
        break;
      case ' ':
      case '\t':              // Skip whitespace, leave state unchanged
        if (InString)
          p++;
        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:
        strcpy ((char *) Map[MapIdx].Place, items [i+2]);
        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 ()
{


  // These variables are added for FMO
  FILE * sgfile=NULL;
  int i;
  int frame_mb_only;
  int mb_width, mb_height, mapunit_height;

	
  // consistency check of QPs
  if (input->qp0 > MAX_QP || input->qp0 < MIN_QP)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter quant_0,check configuration file");
    error (errortext, 400);
  }

  if (input->qpN > MAX_QP || input->qpN < MIN_QP)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter quant_n,check configuration file");
    error (errortext, 400);
  }

  if (input->qpB > MAX_QP || input->qpB < MIN_QP)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter quant_B,check configuration file");
    error (errortext, 400);
  }
#ifdef _CHANGE_QP_
  if (input->qp2start && (input->qpB2 > MAX_QP || input->qpB2 < MIN_QP))
  {
    snprintf(errortext, ET_SIZE, "Error input parameter ChangeQPB,check configuration file");
    error (errortext, 400);
  }

  if (input->qp2start && (input->qp02 > MAX_QP || input->qp02 < MIN_QP))
  {
    snprintf(errortext, ET_SIZE, "Error input parameter ChangeQIB,check configuration file");
    error (errortext, 400);
  }

  if (input->qp2start && (input->qpN2 > MAX_QP || input->qpN2 < MIN_QP))
  {
    snprintf(errortext, ET_SIZE, "Error input parameter ChangeQPP,check configuration file");
    error (errortext, 400);
  }


#endif
  if (input->qpsp > MAX_QP || input->qpsp < MIN_QP)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter quant_sp,check configuration file");
    error (errortext, 400);
  }
  if (input->qpsp_pred > MAX_QP || input->qpsp_pred < MIN_QP)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter quant_sp_pred,check configuration file");
    error (errortext, 400);
  }
  if (input->sp_periodicity <0)
  {
    snprintf(errortext, ET_SIZE, "Error input parameter sp_periodicity,check configuration file");
    error (errortext, 400);
  }
  if (input->FrameRate < 0 || input->FrameRate>100)   
  {
    snprintf(errortext, ET_SIZE, "Error in input parameter FrameRate, check configuration file");
    error (errortext, 400);
  }
  if (input->FrameRate == 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 StartFrane, Check configuration file.");
    error (errortext, 400);
  }

  // consistency check num_reference_frames
  if (input->num_reference_frames<1) input->num_reference_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 input parameter LFAlphaC0Offset, check configuration file");
    error (errortext, 400);
  }

  if (input->LFBetaOffset > 6 || input->LFBetaOffset < -6)
  {
    snprintf(errortext, ET_SIZE, "Error 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(1+ input->no_frames *storedBplus1 ))-4, 0);
  
//    log2_max_frame_num_minus4 = 0;
  }

  log2_max_pic_order_cnt_lsb_minus4 = max( (int)(CeilLog2(1+2*input->no_frames * (input->successive_Bframe + 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_type != DIR_SPATIAL && input->direct_type != DIR_TEMPORAL)
  {
    snprintf(errortext, ET_SIZE, "Unsupported direct mode=%d, use TEMPORAL=0 or SPATIAL=1", input->direct_type);
    error (errortext, 400);
  }

  if (input->PicInterlace>0 || input->MbInterlace>0)
  {
    if (input->directInferenceFlag==0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -