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

📄 configfile.c

📁 avs-s最新代码,包括编码器和解码器源码
💻 C
📖 第 1 页 / 共 3 页
字号:
*************************************************************************
* Function: Parses the character array buf and writes global variable sliceregion, 
    		which contains the information of sliceset's structure. 
* Input: buf
         buffer to be parsed
		 bufsize
         buffer size of buffer
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void ParseSliceSet (char *buf, int bufsize)
{
  char *items[MAX_ITEMS_TO_PARSE];
  int item     = 0;
  int InString = 0;
  int InItem   = 0;
  char *p      = buf;
  char *bufend = &buf[bufsize];
  int IntContent;
  int frmidx1 = -1;
  int frmidx2 = -1;
  int slice_flag;
  int regionnum = 0;
  int i;

  // Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
  // This is context insensitive and could be done most easily with lex(1).

  while (p < bufend)
  {
    switch (*p)
    {
      case 13:
        p++;
        break;
      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(!strcmp ("FRAMESTART", items[i]))
	  {
		  sscanf (items[i+2], "%d", &IntContent);
		  frmidx1 = IntContent;
		  i += 3;
		  sscanf (items[i+2], "%d", &IntContent);
		  frmidx2 = IntContent;
		  i += 3;
	  }
	  
	  if(frmidx1==-1 || frmidx2==-1)
	  {
		  snprintf (errortext, ET_SIZE, " The frame range for the slice set should be specified!");
		  error (errortext, 300);
	  }
	  
	  if(frmidx1 > frmidx2)
	  {
		  snprintf (errortext, ET_SIZE, " The begining frame_num of slice set should not be larger than the end frame_num!");
		  error (errortext, 300);
	  }

	  if(img->tr>=frmidx1 && img->tr<=frmidx2 || (frmidx1==0&&frmidx2==0))
		  slice_flag = 1;
	  else
		  slice_flag = 0;	  
	  
	  sscanf (items[i+2], "%d", &IntContent);

	  if(!strcmp ("SLICESETINDEX", items[i]) && slice_flag)
		  sliceregion[regionnum].slice_set_index = IntContent;
	  else if(!strcmp ("SLICEDeltaQP", items[i])  && slice_flag) {
		  sliceregion[regionnum].sliceqp = img->type==B_IMG ? input->qpB+IntContent : (img->type==INTRA_IMG?input->qp0+IntContent:input->qpN+IntContent);
		  sliceregion[regionnum].sliceqp = sliceregion[regionnum].sliceqp<0 ? 0 : sliceregion[regionnum].sliceqp>63 ? 63 : sliceregion[regionnum].sliceqp;
	  }
	  else if(!strcmp ("REGIONSTARTX", items[i]) && slice_flag)
		  sliceregion[regionnum].pos[0] = IntContent;
	  else if(!strcmp ("REGIONENDX", items[i]) && slice_flag)
		  sliceregion[regionnum].pos[1] = IntContent;
	  else if(!strcmp ("REGIONSTARTY", items[i]) && slice_flag)
		  sliceregion[regionnum].pos[2] = IntContent;
	  else if(!strcmp ("REGIONENDY", items[i]) && slice_flag)
		  sliceregion[regionnum++].pos[3] = IntContent;
  }
  
}

// Added by LiShao, Tsinghua, 20070327
static void ProfileCheck()
{
	switch (input->profile_id)
	{
	case 0x12://Surveillance Profile WANGJP
		{
			printf("\n Current Profile_ID is Surveillance Profile. \n");  
			if(input->chroma_format>2)
			{
				printf("\n Chroma_format invalid.\n");
				exit(-1);
			}
			else if(input->chroma_format==0)
			{
				printf("\n");
				printf("**************************Current chroma format is 4:0:0********************\n");
				printf("*                                                                          *\n");
				printf("*    此时根据输入序列的图像格式来设置encoder.cfg中的InputChromaFormat参数,*\n");
				printf("*编码端仍以4:2:0格式输出重建图像,输出象素的所有色度分量值均设置为128      *\n");
				printf("*                                                                          *\n");
				printf("****************************************************************************\n");
			}
			break;
		}
	case 0x20:
		{
			if(input->level_id!=0x08&&input->level_id!=0x10&&input->level_id!=0x20&&input->level_id!=0x22&&input->level_id!=0x40&&input->level_id!=0x42)
			{
				printf("\n Level_ID invalid or Unsupported. \n");
				exit(-1);
			}

			if(input->InterlaceCodingOption>1)	//if(input->InterlaceCodingOption>2) Modified by qihuafei, 20070926  
			{
				printf("\n The value of 'InterlaceCodingOption' is invalid! \n");
				exit(-1);
			}

			if(input->chroma_format!=1&&input->chroma_format!=2)
			{
				printf("\n Chroma_format invalid.\n");
				exit(-1);
			}

			//4:0:0 WANGJP START
			if(input->input_chroma_format==0)
			{
				printf("\n Chroma_format invalid(InputChromaFormat can't be set to 0).\n");
				exit(-1);
			}
			//WANGJP END
			break;
		}

	case 0x40: printf("\n Current Profile_ID is not 1.0 version. \n");  break;

	default: 
		{
			printf("\n Profile_ID invalid.\n"); 
			exit(-1);
		}
	}

}

// Added by LiShao, Tsinghua, 20070327
static void LevelCheck()
{
	float framerate[8]={24000/1001,24,25,30000/1001,30,50,60000/1001,60};
	if(input->frame_rate_code<1||input->frame_rate_code>15)
		{
			printf("\n Undefined frame_rate in all levels. \n");
			exit(0);
		}
	switch (input->level_id)
	{
	case 0x08:
		{
			if(input->img_width>176)
			{
				printf("\n Image Width exceeds level 1.0 restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>144)
				{
					printf("\n Image height exceeds level 1.0 restriction.\n");
					exit(-1);
				}
				else
				{
					if(input->frame_rate_code>5)
					{
						printf("\n Current frame_rate is not support in Level_1.0 .\n");
						exit(-1);
					}
					else 
					{
						if((long)(input->img_width)*(long)(input->img_height)*(framerate[input->frame_rate_code-1])>633600)
						{
							printf("\n Luma Sampling Rate invalid for level 1.0.\n");
							exit(-1);
						}
					}
				}

				if((long)(input->img_width)*(long)(input->img_height)/256>99)
				{
					printf("\n The number of macroblock per frame exceeds 99 in level 1.0.\n");
					exit(-1);
				}

				if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>2970)
				{
					printf(" \n The number of macroblock per second exceeds 2970 in level 1.0.\n");
					exit(-1);
				}

				if(input->chroma_format>1)//4:0:0 WANGJP
				//if(input->chroma_format!=1)
				{
					printf("\n In level 1.0 only format 4:2:0 is supported.\n");
					exit(-1);
				}

				break;
		}

	case 0x10:
		{
			if(input->img_width>352)
			{
				printf("\n Image Width exceeds level 2.0 restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>288)
					{
						printf("\n Image height exceeds level 2.0 restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_2.0 .\n");
							exit(-1);
						}
						else 
						{
							if((long)(input->img_width)*(long)(input->img_height)*(framerate[input->frame_rate_code-1])>2534400)
							{
								printf("\n Luma Sampling Rate invalid for level 2.0.\n");
								exit(-1);
							}
						}
					}
						
			if((long)(input->img_width)*(long)(input->img_height)/256>396)
			{
				printf("\n The number of macroblock per frame exceeds 396 in level 2.0.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>11880)
			{
				printf(" \n The number of macroblock per second exceeds 11880 in level 2.0.\n");
				exit(-1);
			}
			
			if(input->chroma_format>1)//4:0:0 WANGJP
			//if(input->chroma_format!=1)
			{
				printf("\n In level 2.0 only format 4:2:0 is supported.\n");
				exit(-1);
			}

			break;
		}

	case 0x20:
		{
			if(input->img_width>720)
			{
				printf("\n Image Width exceeds level 4.0's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>576)
					{
						printf("\n Imgage Height exceeds level 4.0's restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_4.0 .\n");
							exit(-1);
						}
						else
						{
							if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>10368000)
							{
								printf("\n Luma Sampling Rate invalid for level 4.0.\n");
								exit(-1);
							}		
						}
					}
		
			if((long)(input->img_width)*(long)(input->img_height)/256>4050)
			{
				printf(" \n The number of macroblock per frame exceeds 1,620 for Level_4.0.\n");
				exit(-1);
			}
			
			if((long)(input->img_width)*(long)(input->img_height)*framerate[input->frame_rate_code-1]/256>40500)
			{
				printf(" \n The number of macroblock per second exceeds 40500 in Level_4.0.\n");
				exit(-1);
			}
			
			if(input->chroma_format>1)//4:0:0 WANGJP
			//if(input->chroma_format!=1)
			{
				printf("\n In level 4.0 only format 4:2:0 is supported.\n");
				exit(-1);
			}

			break;
		}

		case 0x22:
		{
			if(input->img_width>720)
			{
				printf("\n Imgage Width exceeds level 4.2's restriction.\n");
				exit(-1);
			}
			else 
				if(input->img_height>576)
					{
						printf("\n Image Height exceeds level 4.2's restriction.\n");
						exit(-1);
					}
				else
					{
						if(input->frame_rate_code>5)
						{
							printf("\n Current frame_rate is not support in Level_4.2 .\n");
							exit(-1);
						}
						else
						{
							if((long)(input->img_width)*(long)(input->img_height)*(long)(framerate[input->frame_rate_code-1])>10368000)

⌨️ 快捷键说明

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