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

📄 configfile.c

📁 H.264编码解码器源码(c语言).zip
💻 C
📖 第 1 页 / 共 2 页
字号:

    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;
      default:
        assert ("Unknown value type in the map definition of configfile.h");
    }
  }
  memcpy (input, &configinput, sizeof (InputParameters));
  PatchInp();
}

/*!
 ***********************************************************************
 * \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
 *    Checks the input parameters for consistency.
 ***********************************************************************
 */
static void PatchInp ()
{

  // 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);
  }

  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);
  }
  // consistency check Search_range

/*  if (input->search_range > 39)   // StW
  {
    snprintf(errortext, ET_SIZE, "Error in input parameter search_range, 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;

  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->partition_mode == 1 && input->UseConstrainedIntraPred == 0)
  {
    printf ("Why this???");
    snprintf(errortext, ET_SIZE, "For Partition mode 1 UseConstrainedIntraPred must be set to 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);
  }

  // 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=fopen(input->infile,"rb"))==NULL)
  {
    snprintf(errortext, ET_SIZE, "Input file %s does not exist",input->infile);
    error (errortext, 500);
  }

  if (strlen (input->ReconFile) > 0 && (p_dec=fopen(input->ReconFile, "wb"))==NULL)
  {
    snprintf(errortext, ET_SIZE, "Error open file %s", input->ReconFile);
    error (errortext, 500);
  }

  if (strlen (input->TraceFile) > 0 && (p_trace=fopen(input->TraceFile,"w"))==NULL)
  {
    snprintf(errortext, ET_SIZE, "Error open file %s", input->TraceFile);
    error (errortext, 500);
  }

  // frame/field consistency check
  if (input->InterlaceCodingOption != FRAME_CODING && input->InterlaceCodingOption != ADAPTIVE_CODING && input->InterlaceCodingOption != FIELD_CODING
    && input->InterlaceCodingOption != MB_CODING)
  {
    snprintf (errortext, ET_SIZE, "Unsupported InterlaceCodingOption=%d, use frame based coding=0 or adaptive=1 or field based coding=2",input->InterlaceCodingOption);
    error (errortext, 400);
  }
   
  if (input->InterlaceCodingOption != FRAME_CODING)
  {
    if (input->img_height % 32 != 0 )
    { 
      snprintf(errortext, ET_SIZE, "Unsupported image format y=%d, must be a multiple of 32 for adaptive frame/field",input->img_height);
      error (errortext, 400);
    }
  }

  if ((!input->rdopt)&&(input->InterlaceCodingOption==MB_CODING))
  {
    snprintf(errortext, ET_SIZE, "MB AFF is not compatible with non-rd-optimized coding.");
    error (errortext, 500);
  }


  // Tian Dong: May 31, 2002
  // The number of frames in one sub-seq in enhanced layer should not exceed
  // the number of reference frame number.
  if ( input->NumFramesInELSubSeq >= input->num_reference_frames || input->NumFramesInELSubSeq < 0 )
  {
    snprintf(errortext, ET_SIZE, "NumFramesInELSubSeq (%d) is out of range [0,%d).", input->NumFramesInELSubSeq, input->num_reference_frames);
    error (errortext, 500);
  }
  // Tian Dong: Enhanced GOP is not supported in bitstream mode. September, 2002
  if ( input->NumFramesInELSubSeq > 0 && input->of_mode == PAR_OF_ANNEXB )
  {
    snprintf(errortext, ET_SIZE, "Enhanced GOP is not supported in bitstream mode and RTP mode yet.");
    error (errortext, 500);
  }
  // Tian Dong (Sept 2002)
  // The AFF is not compatible with spare picture for the time being.
  if (input->InterlaceCodingOption != FRAME_CODING && input->SparePictureOption == TRUE)
  {
    snprintf(errortext, ET_SIZE, "The AFF is not compatible with spare picture.");
    error (errortext, 500);
  }

  // Only the RTP mode is compatible with spare picture for the time being.
  if (input->of_mode != PAR_OF_RTP && input->SparePictureOption == TRUE)
  {
    snprintf(errortext, ET_SIZE, "Only RTP output mode is compatible with spare picture features.");
    error (errortext, 500);
  }
  if (input->StoredBPictures > 0)
  {
    if (input->direct_type != DIR_SPATIAL)
    {
      input->direct_type = DIR_SPATIAL;
      printf("Stored B Picture coding is not supported for temporal direct mode currently. Using spatial direct mode.");
    }
  }
  if( (input->StoredBPictures || input->WeightedBiprediction > 0) && input->successive_Bframe && input->direct_type == DIR_TEMPORAL)
  {
    printf("Weighted bi-prediction coding is not supported for temporal direct mode currently.");
    input->direct_type = DIR_SPATIAL;
  }
  if( (input->WeightedPrediction > 0 || input->WeightedBiprediction > 0) && input->InterlaceCodingOption == MB_CODING )
  {
    printf("Weighted prediction coding is not supported for MB AFF currently.");
    error (errortext, 500);
  }
  if ( input->NumFramesInELSubSeq > 0 && input->WeightedPrediction > 0)
  {
    snprintf(errortext, ET_SIZE, "Enhanced GOP is not supported in weighted prediction coding mode yet.");
    error (errortext, 500);
  }

  // JVT-D095, JVT-D097
  input->mb_allocation_map_type = input->FmoType;
  if(input->num_slice_groups_minus1 > 0)
  {
    if(input->mb_allocation_map_type >= 3)
      input->num_slice_groups_minus1 = input->num_slice_groups_minus1 = 1;
  }
  // End JVT-D095, JVT-D097

}

void PatchInputNoFrames()
{
  // Tian Dong: May 31, 2002
  // If the frames are grouped into two layers, "FramesToBeEncoded" in the config file
  // will give the number of frames which are in the base layer. Here we let input->no_frames
  // be the total frame numbers.
  input->no_frames = 1+ (input->no_frames-1) * (input->NumFramesInELSubSeq+1);
  if ( input->NumFrameIn2ndIGOP )
    input->NumFrameIn2ndIGOP = 1+(input->NumFrameIn2ndIGOP-1) * (input->NumFramesInELSubSeq+1);
  FirstFrameIn2ndIGOP = input->no_frames;
}

⌨️ 快捷键说明

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