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

📄 configfile.c

📁 压缩JM12.3d的完整的全部C语言的代码文档,用于嵌入式系统的压缩编解码
💻 C
📖 第 1 页 / 共 4 页
字号:
    }

    if ( input->HierarchicalCoding && input->RCUpdateMode != RC_MODE_2 && input->RCUpdateMode != RC_MODE_3 )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode=2 or 3 for hierarchical B-picture coding.");
      error (errortext, 500);
    }

    if ( (input->RCUpdateMode != RC_MODE_1) && (input->intra_period == 1) )
    {
      snprintf(errortext, ET_SIZE, "Use RCUpdateMode=1 for all-I_SLICE coding.");
      error (errortext, 500);
    }
  }

  if ((input->successive_Bframe)&&(input->BRefPictures)&&(input->idr_period)&&(input->pic_order_cnt_type!=0))
  {
    error("Stored B pictures combined with IDR pictures only supported in Picture Order Count type 0\n",-1000);
  }

  if( !input->direct_spatial_mv_pred_flag && input->num_ref_frames<2 && input->successive_Bframe >0)
    error("temporal direct needs at least 2 ref frames\n",-1000);

  // frext
  if(input->Transform8x8Mode && input->sp_periodicity /*SP-frames*/)
  {
    snprintf(errortext, ET_SIZE, "\nThe new 8x8 mode is not implemented for sp-frames.");
    error (errortext, 500);
  }

  if(input->Transform8x8Mode && ( input->ProfileIDC<FREXT_HP && input->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nTransform8x8Mode may be used only with ProfileIDC %d to %d.", FREXT_HP, FREXT_Hi444);
    error (errortext, 500);
  }
  if(input->ScalingMatrixPresentFlag && ( input->ProfileIDC<FREXT_HP && input->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nScalingMatrixPresentFlag may be used only with ProfileIDC %d to %d.", FREXT_HP, FREXT_Hi444);
    error (errortext, 500);
  }

  if(input->yuv_format==YUV422 && ( input->ProfileIDC < FREXT_Hi422 && input->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nFRExt Profile(YUV Format) Error!\nYUV422 can be used only with ProfileIDC %d or %d\n",FREXT_Hi422, FREXT_Hi444);
    error (errortext, 500);
  }
  if(input->yuv_format==YUV444 && ( input->ProfileIDC < FREXT_Hi444 && input->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nFRExt Profile(YUV Format) Error!\nYUV444 can be used only with ProfileIDC %d.\n",FREXT_Hi444);
    error (errortext, 500);
  }

  if (input->successive_Bframe && ((input->BiPredMotionEstimation) && (input->search_range < input->BiPredMESearchRange)))
  {
    snprintf(errortext, ET_SIZE, "\nBiPredMESearchRange must be smaller or equal SearchRange.");
    error (errortext, 500);
  }

  // check consistency
  if ( input->ChromaMEEnable && !(input->ChromaMCBuffer) ) {
    snprintf(errortext, ET_SIZE, "\nChromaMCBuffer must be set to 1 if ChromaMEEnable is set.");
    error (errortext, 500);
  }

  if ( input->ChromaMEEnable && input->yuv_format ==  YUV400) {
    snprintf(errortext, ET_SIZE, "\nChromaMEEnable cannot be used with YUV400 color format.");
    input->ChromaMEEnable = 0;
  }

  if (input->EnableOpenGOP && input->PicInterlace)
  {
    snprintf(errortext, ET_SIZE, "Open GOP currently not supported for Field coded pictures.");
    error (errortext, 500);
  }

  if (input->EnableOpenGOP)
    input->ReferenceReorder = 1;

  if (input->redundant_pic_flag)
  {
    if (input->PicInterlace || input->MbInterlace)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with interlaced tools.");
      error (errortext, 500);
    }
    if (input->RDPictureDecision)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with RDPictureDecision.");
      error (errortext, 500);
    }
    if (input->successive_Bframe)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures cannot be used with B frames.");
      error (errortext, 500);
    }
    if (input->PrimaryGOPLength < (1 << input->NumRedundantHierarchy))
    {
      snprintf(errortext, ET_SIZE, "PrimaryGOPLength must be equal or greater than 2^NumRedundantHierarchy.");
      error (errortext, 500);
    }
    if (input->num_ref_frames < input->PrimaryGOPLength)
    {
      snprintf(errortext, ET_SIZE, "NumberReferenceFrames must be greater than or equal to PrimaryGOPLength.");
      error (errortext, 500);
    }
  }

  if (input->num_ref_frames == 1 && input->successive_Bframe)
  {
    fprintf( stderr, "\nWarning: B slices used but only one reference allocated within reference buffer.\n");
    fprintf( stderr, "         Performance may be considerably compromised! \n");
    fprintf( stderr, "         2 or more references recommended for use with B slices.\n");
  }
  if ((input->HierarchicalCoding || input->BRefPictures) && input->successive_Bframe)
  {
    fprintf( stderr, "\nWarning: Hierarchical coding or Referenced B slices used.\n");
    fprintf( stderr, "         Make sure that you have allocated enough references\n");
    fprintf( stderr, "         in reference buffer to achieve best performance.\n");
  }

  ProfileCheck();
  LevelCheck();
}

void PatchInputNoFrames(void)
{
  // 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);
}

static void ProfileCheck(void)
{
  if((input->ProfileIDC != 66 ) &&
     (input->ProfileIDC != 77 ) &&
     (input->ProfileIDC != 88 ) &&
     (input->ProfileIDC != FREXT_HP    ) &&
     (input->ProfileIDC != FREXT_Hi10P ) &&
     (input->ProfileIDC != FREXT_Hi422 ) &&
     (input->ProfileIDC != FREXT_Hi444 ) &&
     (input->ProfileIDC != FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "Profile must be baseline(66)/main(77)/extended(88) or FRExt (%d to %d).", FREXT_HP,FREXT_Hi444);
    error (errortext, 500);
  }

  if ((input->partition_mode) && (input->symbol_mode==CABAC))
  {
    snprintf(errortext, ET_SIZE, "Data partitioning and CABAC is not supported in any profile.");
    error (errortext, 500);
  }

  if (input->redundant_pic_flag)
  {
    if (input->ProfileIDC != 66)
    {
      snprintf(errortext, ET_SIZE, "Redundant pictures are only allowed in Baseline profile.");
      error (errortext, 500);
    }
  }

  if (input->partition_mode)
  {
    if (input->ProfileIDC != 88)
    {
      snprintf(errortext, ET_SIZE, "Data partitioning is only allowed in extended profile.");
      error (errortext, 500);
    }
  }

  if (input->ChromaIntraDisable && input->FastCrIntraDecision)
  {
    fprintf( stderr, "\n----------------------------------------------------------------------------------\n");
    fprintf( stderr, "\n Warning: ChromaIntraDisable and FastCrIntraDecision cannot be combined together.\n Using only Chroma Intra DC mode.\n");
    fprintf( stderr, "\n----------------------------------------------------------------------------------\n");
    input->FastCrIntraDecision=0;
  }

  // baseline
  if (input->ProfileIDC == 66 )
  {
    if ((input->successive_Bframe || input->BRefPictures==2) && input->PReplaceBSlice == 0)
    {
      snprintf(errortext, ET_SIZE, "B slices are not allowed in baseline.");
      error (errortext, 500);
    }
    if (input->sp_periodicity)
    {
      snprintf(errortext, ET_SIZE, "SP pictures are not allowed in baseline.");
      error (errortext, 500);
    }
    if (input->WeightedPrediction)
    {
      snprintf(errortext, ET_SIZE, "Weighted prediction is not allowed in baseline.");
      error (errortext, 500);
    }
    if (input->WeightedBiprediction)
    {
      snprintf(errortext, ET_SIZE, "Weighted prediction is not allowed in baseline.");
      error (errortext, 500);
    }
    if (input->symbol_mode == CABAC)
    {
      snprintf(errortext, ET_SIZE, "CABAC is not allowed in baseline.");
      error (errortext, 500);
    }
  }

  // main
  if (input->ProfileIDC == 77 )
  {
    if (input->sp_periodicity)
    {
      snprintf(errortext, ET_SIZE, "SP pictures are not allowed in main.");
      error (errortext, 500);
    }
    if (input->num_slice_groups_minus1)
    {
      snprintf(errortext, ET_SIZE, "num_slice_groups_minus1>0 (FMO) is not allowed in main.");
      error (errortext, 500);
    }
  }

  // extended
  if (input->ProfileIDC == 88 )
  {
    if (!input->directInferenceFlag)
    {
      snprintf(errortext, ET_SIZE, "direct_8x8_inference flag must be equal to 1 in extended.");
      error (errortext, 500);
    }

    if (input->symbol_mode == CABAC)
    {
      snprintf(errortext, ET_SIZE, "CABAC is not allowed in extended.");
      error (errortext, 500);
    }
  }

  //FRExt
  if (input->IntraProfile && ( input->ProfileIDC<FREXT_HP && input->ProfileIDC!=FREXT_CAVLC444 ))
  {
    snprintf(errortext, ET_SIZE, "\nAllIntraProfile is allowed only with ProfileIDC %d to %d.", FREXT_HP, FREXT_Hi444);
    error (errortext, 500);
  }

  if (input->IntraProfile && !input->idr_period) 
  {
    snprintf(errortext, ET_SIZE, "\nAllIntraProfile requires IDRPeriod >= 1.");
    error (errortext, 500);
  }

  if (input->IntraProfile && input->intra_period != 1) 
  {
    snprintf(errortext, ET_SIZE, "\nAllIntraProfile requires IntraPeriod equal 1.");
    error (errortext, 500);
  }

  if (input->IntraProfile && input->num_ref_frames) 
  {
    fprintf( stderr, "\nWarning: Setting NumberReferenceFrames to 0 in IntraProfile.\n\n");
      input->num_ref_frames = 0;
  }

  if (input->IntraProfile == 0 && input->num_ref_frames == 0) 
  {
    snprintf(errortext, ET_SIZE, "\nProfiles other than IntraProfile require NumberReferenceFrames > 0.");
    error (errortext, 500);
  }

  if ( input->separate_colour_plane_flag )
  {
    if( ( input->ProfileIDC != FREXT_Hi444 ) && ( input->ProfileIDC != FREXT_CAVLC444 ) )
    {
      snprintf(errortext, ET_SIZE, "\nseparate_colour_plane_flag is allowed in FREXT_CAVLC444/FREXT_Hi444.");
      error (errortext, 500);
    }

    if ( input->ChromaMEEnable )
    {
      snprintf(errortext, ET_SIZE, "\nChromaMEEnable is not allowed in Frext4:4:4Independent_mode.");
      error (errortext, 500);
    }
  }

  if ( input->ProfileIDC == FREXT_CAVLC444 )
  {
    if ( input->symbol_mode != UVLC )
    {
      snprintf(errortext, ET_SIZE, "\nUVLC is not allowed in FREXT_CAVLC444.");
      error (errortext, 500);
    }
    if ( !input->IntraProfile )
    {
      snprintf(errortext, ET_SIZE, "\nFREXT_CAVLC444 must be IntraProfile.");
      error (errortext, 500);
    }
  }
}


// Level Limit             -  -  -  -  -  -  -  -  -  1b  10  11   12   13   -  -  -  -  -  -  20   21   22    -  -  -  -  -  -  -
unsigned int  MaxFs [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 99, 396, 396, 396, 0, 0, 0, 0, 0, 0, 396, 792, 1620, 0, 0, 0, 0, 0, 0, 0,  
//                        30    31    32    -  -  -  -  -  -  -  40    41    42    -  -  -  -  -  -  -  50     51
                          1620, 3600, 5120, 0, 0, 0, 0, 0, 0, 0, 8192, 8192, 8704, 0, 0, 0, 0, 0, 0, 0, 22080, 36864 };

unsigned getMaxFs (unsigned int levelIdc)
{
  unsigned int ret;

  if ( (levelIdc < 9) || (levelIdc > 51))
    error ("getMaxFs: Unknown LevelIdc", 500);

  // in Baseline, Main and Extended: Level 1b is specified with LevelIdc==11 and constrained_set3_flag == 1

  ret = MaxFs[levelIdc];

  if ( 0 == ret )
    error ("getMaxFs: Unknown LevelIdc", 500);

  return ret;
}

static void LevelCheck(void)
{
  unsigned int PicSizeInMbs = ( (input->img_width + img->auto_crop_right) * (input->img_height + img->auto_crop_bottom) ) >> 8;

  if ( (input->LevelIDC>=30) && (input->directInferenceFlag==0))
  {
    fprintf( stderr, "\nWarning: LevelIDC 3.0 and above require direct_8x8_inference to be set to 1. Please check your settings.\n");
    input->directInferenceFlag=1;
  }
  if ( ((input->LevelIDC<21) || (input->LevelIDC>41)) && (input->PicInterlace > 0 || input->MbInterlace > 0) )
  {
    snprintf(errortext, ET_SIZE, "\nInterlace modes only supported for LevelIDC in the range of 21 and 41. Please check your settings.\n");
    error (errortext, 500);
  }

  if ( PicSizeInMbs > getMaxFs(input->LevelIDC) )
  {
    snprintf(errortext, ET_SIZE, "\nPicSizeInMbs exceeds maximum allowed size at specified LevelIdc %d\n", input->LevelIDC);
    error (errortext, 500);
  }
  
  if (input->IntraProfile && (PicSizeInMbs > 1620) && input->slice_mode != 1) 
  {
    error ("\nIntraProfile with PicSizeInMbs > 1620 requires SliceMode equal 1.", 500);
  }

  if (input->IntraProfile && (PicSizeInMbs > 1620) && ((unsigned int)input->slice_argument > (  getMaxFs(input->LevelIDC) >> 2 ) ) )
  {
    //when PicSizeInMbs is greater than 1620, the number of macroblocks in any coded slice shall not exceed MaxFS / 4
    snprintf(errortext, ET_SIZE, "\nIntraProfile requires SliceArgument smaller or equal to 1/4 MaxFs at specified LevelIdc %d.", input->LevelIDC);
    error (errortext, 500);
  }
}

⌨️ 快捷键说明

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