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

📄 p642.c

📁 h261协议的h261编码码,lib_261.h里面提供了详细的接口和说明.
💻 C
📖 第 1 页 / 共 3 页
字号:
EFUNC*/

//void PrintFrame()
//{
//  BEGIN("PrintFrame");
//  int i;
//
//  printf("*** Frame ID: %x ***\n",CFrame2);
//  if (CFrame2)
//    {
//      printf("NumberComponents %d\n",
//	     CFrame2->NumberComponents);
//      for(i=0;i<CFrame2->NumberComponents;i++)
//	{
//	  printf("Component: FilePrefix: %s FileSuffix: %s\n",
//		 ((*CFrame2->ComponentFilePrefix[i]) ?
//		  CFrame2->ComponentFilePrefix[i] : "Null"),
//		 ((*CFrame2->ComponentFileSuffix[i]) ?
//		  CFrame2->ComponentFileSuffix[i] : "Null"));
//	  printf("Height: %d  Width: %d\n",
//		 CFrame2->Height[i],CFrame2->Width[i]);
//	  printf("HorizontalFrequency: %d  VerticalFrequency: %d\n",
//		 CFrame2->hf[i],CFrame2->vf[i]);
//	  InstallIob2(i);
//	  PrintIob();
//	}
//    }
//}

/*BFUNC

MakeImage2() makes an image structure and installs it as the current
image.

EFUNC*/

void MakeImage2()
{
  BEGIN("MakeImage2");

  if(!CImage2)
  {
	  if (!(CImage2 = MakeStructure(IMAGE)))
	  {
		  WHEREAMI();
		  printf("Cannot make an image structure.\n");
	  }
  }
  CImage2->StreamFileName = NULL;
  CImage2->p64Mode = 0;
  CImage2->Height = 0;
  CImage2->Width = 0;
}

/*BFUNC

MakeFrame2() makes a frame structure and installs it as the current
frame structure.

EFUNC*/

void MakeFrame2()
{
  BEGIN("MakeFrame2");
  int i;

  if(!CFrame2)
  {
	  if (!(CFrame2 = MakeStructure(FRAME)))
	  {
		  WHEREAMI();
		  printf("Cannot make an frame structure.\n");
	  }
  }
  else
  {
	  for(i=0;i<MAXIMUM_SOURCES;i++)
	  {
		  if(CFrame2->Iob2[i])
		  {
			  if(CFrame2->Iob2[i]->mem)
			  {
				  FREE(CFrame2->Iob2[i]->mem->data);
			  }
			  FREE(CFrame2->Iob2[i]->mem);
		  }
		  FREE(CFrame2->Iob2[i]);
	  }
  }
  CFrame2->NumberComponents = 3;
  for(i=0;i<MAXIMUM_SOURCES;i++)
    {
      CFrame2->Height[i] = 0;
      CFrame2->Width[i] = 0;
      CFrame2->hf[i] = 1;
      CFrame2->vf[i] = 1;
      *CFrame2->ComponentFileName[i]='\0';
      *CFrame2->ComponentFilePrefix[i]='\0';
      *CFrame2->ComponentFileSuffix[i]='\0';
	  CFrame2->yuv2[i] = '\0';
    }
}

/*BFUNC

MakeFstore2() makes and installs the frame stores for the motion
estimation and compensation.

EFUNC*/


void MakeFstore2()
{
	int i;
	if(!CFS2)///////////////////////////////////qjz
	{
		//CFS2 = (FSTORE *) malloc(sizeof(FSTORE));
		CFS2 = (FSTORE *) calloc(sizeof(FSTORE),1);
	}////////////////////qjz
	else
	{
		for(i=0;i<MAXIMUM_SOURCES;i++)
		{
			if( CFS2->fs[i] )
			{
				if( CFS2->fs[i]->mem )
				{
					if(CFS2->fs[i]->mem->data)
					{
						free(CFS2->fs[i]->mem->data); CFS2->fs[i]->mem->data = NULL;
					}
					free(CFS2->fs[i]->mem); CFS2->fs[i]->mem = NULL;
				}
				free(CFS2->fs[i]);
				CFS2->fs[i] = NULL;
			}
		}        
	}

	CFS2->NumberComponents = 0;

	if( !OFS2 )
	{
		//OFS2 = (FSTORE *) malloc(sizeof(FSTORE));
		OFS2 = (FSTORE *) calloc(sizeof(FSTORE),1);
	}
	else
	{
		for(i=0;i<MAXIMUM_SOURCES;i++)
		{
			if(OFS2->fs[i])
			{
				if(OFS2->fs[i]->mem)
				{
					if(OFS2->fs[i]->mem->data)
					{
						free(OFS2->fs[i]->mem->data);	OFS2->fs[i]->mem->data = NULL;
					}
					free(OFS2->fs[i]->mem);				OFS2->fs[i]->mem = NULL;
				}
				free(OFS2->fs[i]);
				OFS2->fs[i] = NULL;
			}
			
		}
	}
	OFS2->NumberComponents = 0;
}

/*BFUNC

MakeStat_en() makes the statistics structure to hold all of the current
statistics. (CStat2 and RStat2).

EFUNC*/


//void MakeStat_en()
//{
//	FREE(CStat2);
//	CStat2 = MakeStructure(STAT);
//	FREE(RStat2);
//	RStat2 = MakeStructure(STAT);
//}

/*BFUNC

MakeRate_en() makes some statistics and book-keeping structures for
advanced rate tracking through the frames.

EFUNC*/

//void MakeRate_en()
//{
//	FREE(RCStore2);
//	RCStore2 = (RATE *) calloc(NumberFrames2,sizeof(RATE));
//}

/*BFUNC

SetCCITT2() sets the CImage2 and CFrame2 parameters for CCITT coding.

EFUNC*/

void SetCCITT2()
{
	BEGIN("SetCCITT2");
	int i;
	//if (*CFrame2->ComponentFilePrefix[0]=='\0')
	//{
	//	WHEREAMI();
	//	printf("A file prefix should be specified.\n");
	//	exit(ERROR_BOUNDS);
	//}
	//for(i=0;i<3;i++)
	//{
	//	if (*CFrame2->ComponentFilePrefix[i]=='\0')
	//	{
	//		strcpy(CFrame2->ComponentFilePrefix[i],CFrame2->ComponentFilePrefix[0]);
	//	}
	//	if (*CFrame2->ComponentFileSuffix[i]=='\0')
	//	{
	//		strcpy(CFrame2->ComponentFileSuffix[i],BlockV2[i]);
	//	}
	//}
	CFS2->NumberComponents = 3;
	OFS2->NumberComponents = 3;
	CFrame2->NumberComponents = 3;
	CFrame2->hf[0] = 2;
	CFrame2->vf[0] = 2;
	CFrame2->hf[1] = 1;
	CFrame2->vf[1] = 1;
	CFrame2->hf[2] = 1;
	CFrame2->vf[2] = 1;
	//switch(ImageType2)
	//{
	//case IT_NTSC:
	//	NumberGOB2 = 10;  /* Parameters for NTSC design */
	//	NumberMDU2 = 33;
	//	CImage2->Width = 352;
	//	CImage2->Height = 240;
	//	CFrame2->Width[0] = 352;
	//	CFrame2->Height[0] = 240;
	//	CFrame2->Width[1] = 176;
	//	CFrame2->Height[1] = 120;
	//	CFrame2->Width[2] = 176;
	//	CFrame2->Height[2] = 120;
	//	break;
	//case IT_CIF:
	//	NumberGOB2 = 12;  /* Parameters for NTSC design */
	//	NumberMDU2 = 33;
	//	CImage2->Width = 352;
	//	CImage2->Height = 288;
	//	CFrame2->Width[0] = 352;
	//	CFrame2->Height[0] = 288;
	//	CFrame2->Width[1] = 176;
	//	CFrame2->Height[1] = 144;
	//	CFrame2->Width[2] = 176;
	//	CFrame2->Height[2] = 144;
	//	break;
	//case IT_QCIF:
		NumberGOB2 = 3;  /* Parameters for NTSC design */
		NumberMDU2 = 33;
		CImage2->Width = 176;
		CImage2->Height = 144;
		CFrame2->Width[0] = 176;
		CFrame2->Height[0] = 144;
		CFrame2->Width[1] = 88;
		CFrame2->Height[1] = 72;
		CFrame2->Width[2] = 88;
		CFrame2->Height[2] = 72;
	//	break;
	//default:
	//	WHEREAMI();
	//	printf("Unknown ImageType2: %d\n",ImageType2);
	//	exit(ERROR_BOUNDS);
	//	break;
	//}

	//yuv2 = (unsigned char *) calloc(sizeof(char) * ( CImage2->Width * CImage2->Height + CImage2->Width * CImage2->Height /2 ));
	//if( yuv2 ) 
	//	exit(1);

	if(!LastIntra2)
		LastIntra2 = (unsigned char **) calloc(NumberGOB2,sizeof(unsigned char *));
	for(i=0;i<NumberGOB2;i++)
	{
		/* Should be assigned to all zeroes */
		if(!LastIntra2[i])
			LastIntra2[i] = (unsigned char *) calloc(NumberMDU2,sizeof(unsigned char));
		memset(LastIntra2[i],0,NumberMDU2);  /* just in case */
	}
}

/*BFUNC

Help() prints out help information about the p64 program.

EFUNC*/

//void Help()
//{
//  BEGIN("Help");
//
//  printf("p64  [-d [-c]] [-NTSC] [-CIF] [-QCIF]\n");
//  printf("     [-a StartNumber] [-b EndNumber]\n");
//  printf("     [-f FrameRate2] [-k FrameskipNumber] [-o] [-p]\n");
//  printf("     [-i MCSearchLimit] [-q Quantization] [-v] [-y]\n");
//  printf("     [-r Target Rate2] [-x Target Filesize]\n");
//  printf("     [-s StreamFile] [-z ComponentFileSuffix i]\n");
//  printf("     ComponentFilePrefix1 [ComponentFilePrefix2 ComponentFilePrefix3]\n");
//  printf("-NTSC (352x240)  -CIF (352x288) -QCIF (176x144) base filesizes.\n");
//  printf("-a is the start filename index. [inclusive] Defaults to 0.\n");
//  printf("-b is the end filename index. [inclusive] Defaults to 0.\n");
//  printf("-c forces cif large-frame decoding (can be used with all input modes).\n");
//  printf("-d enables the decoder\n");
//  printf("-f gives the frame rate (default 30).\n");
//  printf("-i gives the MC search area: between 1 and 31 (default 15).\n");
//  printf("-k is the frame skip index. Frames/s = FrameRate2/FrameSkip2.\n");
//  printf("-o enables the interpreter.\n");
//  printf("-p enables parity checking (disabled for 1992 CCITT specs).\n");
//  printf("-q denotes Quantization, between 1 and 31.\n");
//  printf("-r gives the target rate in bps.\n");
//  printf("-s denotes StreamFile, which defaults to ComponentFilePrefix1.p64\n");
//  printf("-v denotes verbose mode, showing quantization changes.\n");
//  printf("-x gives the target filesize in kilobits. (overrides -r option.)\n");
//  printf("-y enables Reference DCT.\n");
//  printf("-z gives the ComponentFileSuffixes (repeatable).\n");
//}

/*BFUNC

MakeFileNames2() creates the filenames for the component files
from the appropriate prefix and suffix commands.

EFUNC*/

void MakeFileNames2()
{
	BEGIN("MakeFileNames2");
	//int i;
    

	//CFrame2->yuv_y = &yuv2[0];
	//CFrame2->yuv_u = &yuv2[ CFrame2->Height[0] * CFrame2->Width[0] ];
	//CFrame2->yuv_v = &yuv2[ CFrame2->Height[1] * CFrame2->Width[1] ];

	//begin
	CFrame2->yuv2[0] = &yuv2[0];
	CFrame2->yuv2[1] = &yuv2[ CFrame2->Height[0] * CFrame2->Width[0] ];
	CFrame2->yuv2[2] = &yuv2[ CFrame2->Height[0] * CFrame2->Width[0] + CFrame2->Height[1] * CFrame2->Width[1] ];
	//end

	//for(i=0;i<3;i++)
 //   {
	//	sprintf(CFrame2->ComponentFileName[i],"%s%d%s",
	//		CFrame2->ComponentFilePrefix[i],
	//		CurrentFrame2,
	//		CFrame2->ComponentFileSuffix[i]);        
	//}
}

/*BFUNC

VerifyFiles_en() checks to see if the component files are present and
of the correct length.

EFUNC*/

//void VerifyFiles_en()
//{
//  BEGIN("VerifyFiles_en");
//  int i,FileSize;
//  //FILE *test;
//  unsigned char *test_data;
//  
//  for(i=0;i<CFrame2->NumberComponents;i++)
//  {
//	  //if ((test = fopen(CFrame2->ComponentFileName[i],"r")) == NULL)
//	  //if ((test = fopen(CFrame2->ComponentFileName[i],"rb2")) == NULL)
//	  //{
//		 // WHEREAMI();
//		 // printf("Cannot Open FileName %s\n",CFrame2->ComponentFileName[i]);
//		 // exit(ERROR_BOUNDS);
//	  //}
//	  //fseek(test,0,2);
//	  //FileSize = ftell(test);
//   //   rewind(test);
//	  //begin
//	  test_data = CFrame2->yuv2[i];
//	  FileSize = CFrame2->Height[i] * CFrame2->Width[i];
//	  //end
//      if (CFrame2->Height[i] == 0)
//	  {
//		  if (CFrame2->Width[i] == 0)
//		  {
//			  WHEREAMI();
//			  printf("Bad File Specification for file %s\n",CFrame2->ComponentFileName[i]);
//		  }
//		  else
//		  {
//			  CFrame2->Height[i] = FileSize / CFrame2->Width[i];
//			  printf("Autosizing Height to %d\n",CFrame2->Height[i]);
//		  }
//	  }
//      if (FileSize != CFrame2->Width[i] * CFrame2->Height[i]) 
//	  {
//		  WHEREAMI();
//		  printf("Inaccurate File Sizes: Estimated %d: %s: %d \n",
//			  CFrame2->Width[i] * CFrame2->Height[i],CFrame2->ComponentFileName[i],FileSize);
//		  exit(ERROR_BOUNDS);
//	  }
//	  //fclose(test);
//  }
//}

/*END*/

//编码
//void h261Encoder(unsigned char * _yuv, unsigned char * _data, int imageType)
//{
//	int i = 0;
//	BEGIN("h261Encoder");
///*	int i,p,s;  */  
//	yuv2 = _yuv;
//	data2 = _data;
//	CurrentMDU2 = 0;
//
//	for(i=0;i<10;i++)
//	{
//		memset(inputbuf2[i], 0, 64*sizeof(int));
//	}
//	memset(output2, 0, 64*sizeof(int));
//	i=0;
//	count2 = 0;
//
//	//init
//	//if(i == 0)
//	//{
//		MakeImage2();   /* Initialize storage */
//		MakeFrame2();
//		MakeFstore2();
//		inithuff2();    /* Put Huffman tables on */
//		initmc_en();      /* Put Motion Comp stuff on */
//		//i=0;
//	//}
//	CurrentFrame2 = 0;
//	StartFrame2 = CurrentFrame2;
//	LastFrame2 = 0;
//	//strcpy(CFrame2->ComponentFilePrefix[0],"short");
//	//CImage2->StreamFileName = "qjz.p64";
//
//	ImageType2 = imageType;
//	switch(ImageType2)
//	{
//	case IT_NTSC:
//		PType2=0x04;
//		PSpareEnable2=1;
//		PSpare2=0x8c;
//		break;
//	case IT_CIF:
//		PType2=0x04;
//		break;
//	case IT_QCIF:
//		PType2=0x00;//ImageType2 = IT_QCIF;
//		break;
//	default:
//		WHEREAMI();
//		printf("Image Type not supported: %d\n",ImageType2);
//		break;
//	}
//
//	SetCCITT2();
//	NumberFrames2 = LastFrame2-CurrentFrame2+1;
//	p64EncodeSequence_en();
//
//}


//解码
void h261Decoder2(unsigned char * _data, unsigned char * _yuv, unsigned int *_count2)
{
	BEGIN("h261Decoder2");

	int i =0;
	data2 = _data;
	yuv2 = _yuv;
	count2 = *_count2;

	CurrentMDU2=0;


	for(i=0;i<10;i++)
	{
		memset(inputbuf2[i], 0, 64*sizeof(int));
	}
	memset(output2, 0, 64*sizeof(int));
	i=0;



	//if(i == 0)
	//{
		MakeImage2();   /* Initialize storage */
		MakeFrame2();
		MakeFstore2();
		inithuff2();    /* Put Huffman tables on */
		//initmc_en();      /* Put Motion Comp stuff on */
		//i=0;
	//}

	CImage2->p64Mode |= P_DECODER;//-d
	//CImage2->StreamFileName = str;//-s
	//strcpy(CFrame2->ComponentFilePrefix[0],"short");

	ImageType2 = IT_QCIF;

	switch(ImageType2)
	{
	case IT_NTSC:
		PType2=0x04;
		PSpareEnable2=1;
		PSpare2=0x8c;
		break;
	case IT_CIF:
		PType2=0x04;
		break;
	case IT_QCIF:
		PType2=0x00;//ImageType2 = IT_QCIF;
		break;
	default:
		WHEREAMI();
		printf("Image Type not supported: %d\n",ImageType2);
		break;
	}


	p64DecodeSequence2();

}

void freeMemory2()
{
	int i=0;

	//IMAGE
    FREE(CImage2);

	//FRAME
	if(CFrame2)
	{
		for(i=0;i<MAXIMUM_SOURCES;i++)
		{
			if(CFrame2->Iob2[i])
			{
				if(CFrame2->Iob2[i]->mem)
				{
					FREE(CFrame2->Iob2[i]->mem->data);
				}
				FREE(CFrame2->Iob2[i]->mem);
			}
			FREE(CFrame2->Iob2[i]);
		}
		FREE(CFrame2);
	}

	//FSTORE
	if(CFS2)
	{
		for(i=0;i<MAXIMUM_SOURCES;i++)
		{
			if( CFS2->fs[i] )
			{
				if( CFS2->fs[i]->mem )
				{
					if(CFS2->fs[i]->mem->data)
					{
						FREE(CFS2->fs[i]->mem->data);
					}
					FREE(CFS2->fs[i]->mem);
				}
				FREE(CFS2->fs[i]);
			}
		}
		FREE(CFS2);
	}

	if(OFS2)
	{
		for(i=0;i<MAXIMUM_SOURCES;i++)
		{
			if( OFS2->fs[i] )
			{
				if( OFS2->fs[i]->mem )
				{
					if(OFS2->fs[i]->mem->data)
					{
						FREE(OFS2->fs[i]->mem->data);
					}
					FREE(OFS2->fs[i]->mem);
				}
				FREE(OFS2->fs[i]);
			}
		}
		FREE(OFS2);
	}

	//STAT
    FREE(CStat2);
	FREE(RStat2);

	//RATE
	FREE(RCStore2);

	//Huffman
	freeHuffman2();

	//BLOCK
	//freeBLOCK2();
}

⌨️ 快捷键说明

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