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

📄 bitstream.c

📁 avs源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	for(i=4;i<k;i++)
		write_n_bit(pORABS,SequenceHeader[i],8);
	write_n_bit(pORABS,SequenceHeader[k],j);
	write_align_stuff(pORABS);

	//fwrite(SequenceHeader,1,(bitscount)/8,f);
	free(bitstream);
	
  return bitscount;
}


int WriteSequenceEnd()
{
	write_start_code(pORABS, 0xb1);
	return 32;
}

/*
*************************************************************************
* Function:Write sequence display extension information
* Input:
* Output:
* Return: sequence display extension information lenght
* Attention:
*************************************************************************
*/


int WriteSequenceDisplayExtension()
{
	Bitstream *bitstream;
	byte SequenceDisplayExtension[MAXHEADERSIZE];
	int  bitscount=0;
	int  stuffbits;
	int  i,j,k;
	
	if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL)
		no_mem_exit("Sequence Display Extension: bitstream");
	input->video_format=1;
	input->video_range=1;
	input->display_horizontal_size=1920;
	input->display_vertical_size=1280;
	
	bitstream->streamBuffer = SequenceDisplayExtension;
	bitstream->bits_to_go = 8;
	
	bitscount+=u_v(32,"sequence display extension start code",0x1b5,bitstream);
	bitscount+=u_v(4,"extension id",2,bitstream);
	bitscount+=u_v(3,"video format",input->video_format,bitstream);
	bitscount+=u_v(1,"video range",input->video_range,bitstream);
	bitscount+=u_v(1,"color description",input->color_description,bitstream);
	
	if(input->color_description)
	{
		bitscount+=u_v(8,"color primaries",input->color_primaries,bitstream);
		bitscount+=u_v(8,"transfer characteristics",input->transfer_characteristics,bitstream);
		bitscount+=u_v(8,"matrix coefficients",input->matrix_coefficients,bitstream);
	}
	
	bitscount+=u_v(14,"display horizontal size",input->display_horizontal_size,bitstream);
	//xyji 12.23
	bitscount+=u_v(1,"marker bit",1,bitstream);
	bitscount+=u_v(14,"display vertical size", input->display_vertical_size,bitstream);
	//xyji 12.23
	bitscount+=u_v(2,"reserved bits",0,bitstream);
	
	k = bitscount >> 3;
	j = bitscount % 8;

	stuffbits = 8-(bitscount%8);
	
	if (stuffbits<8)
	{
		bitscount+=u_v(stuffbits,"stuff bits for byte align",0,bitstream);
	}
	
		write_start_code(pORABS, 0xb5);
	for(i=4;i<k;i++)
		write_n_bit(pORABS,SequenceDisplayExtension[i],8);
	write_n_bit(pORABS,SequenceDisplayExtension[k],j);
	write_align_stuff(pORABS);
	//	fwrite(SequenceDisplayExtension,1,bitscount/8,f);

	free(bitstream);
	
  return bitscount;
}

/*
*************************************************************************
* Function:Write copyright extension information
* Input:
* Output:
* Return: copyright extension information lenght
* Attention:
*************************************************************************
*/
int WriteCopyrightExtension()
{
  Bitstream *bitstream;
  byte CopyrightExtension[MAXHEADERSIZE];
  int  bitscount=0;
  int  stuffbits;
  int  i,j,k;
  
  if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL)
    no_mem_exit("Copyright Extension: bitstream");
  
  bitstream->streamBuffer = CopyrightExtension;
  bitstream->bits_to_go = 8;
  
  bitscount+=u_v(32,"copyright extension start code",0x1b5,bitstream);
  bitscount+=u_v(4,"extension id",4,bitstream);
  bitscount+=u_v(1,"copyright flag",cp->copyright_flag,bitstream);
  bitscount+=u_v(8,"copyright id",cp->copyright_id,bitstream);
  bitscount+=u_v(1,"original or copy",cp->original_or_copy,bitstream);

  bitscount+=u_v(7,"reserved_bits",0,bitstream);
  bitscount+=u_v(1,"marker bit", 1,bitstream);
  
  bitscount+=u_v(20,"copyright number 1",cp->copyright_number,bitstream);
  bitscount+=u_v(1,"marker bit", 1,bitstream);
  bitscount+=u_v(22,"copyright number 2",cp->copyright_number,bitstream);
  bitscount+=u_v(1,"marker bit", 1,bitstream);
  bitscount+=u_v(22,"copyright number 3",cp->copyright_number,bitstream);

  k = bitscount >> 3;
  j = bitscount % 8;

  stuffbits = 8-(bitscount%8);
  
  if (stuffbits<8)
  {
    bitscount+=u_v(stuffbits,"stuff bits for byte align",0,bitstream);
  }
  
  	write_start_code(pORABS, 0xb5);
	for(i=4;i<k;i++)
		write_n_bit(pORABS,CopyrightExtension[i],8);
	write_n_bit(pORABS,CopyrightExtension[k],j);
	write_align_stuff(pORABS);
	//	fwrite(CopyrightExtension,1,bitscount/8,f);

  free(bitstream);
  
  return bitscount;
}


/*
*************************************************************************
* Function:Write camera parameter extension information
* Input:
* Output:
* Return: camera parameter  extension information lenght
* Attention:
*************************************************************************
*/
int WriteCameraParametersExtension()
{
  Bitstream *bitstream;
  byte CameraParametersExtension[MAXHEADERSIZE];
  int  bitscount=0;
  int  stuffbits;
	int  i,j,k;
  
  if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL)
    no_mem_exit("Camera Parameters Extension: bitstream");
  
  bitstream->streamBuffer = CameraParametersExtension;
  bitstream->bits_to_go = 8;
  
  bitscount+=u_v(32,"camera parameters extension start code",0x1b5,bitstream);
  bitscount+=u_v(4,"extension id",11,bitstream);
  bitscount+=u_v(1,"reserved_bits",0,bitstream);
  bitscount+=u_v(7,"camera id",camera->camera_id, bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"height_of_image_device",camera->height_of_image_device,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);
  
  bitscount+=u_v(22,"focal_length",camera->focal_length,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"f_number",camera->f_number,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"vertical_angle_of_view",camera->vertical_angle_of_view,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);
  
  bitscount+=u_v(16,"camera_position_x_upper",camera->camera_direction_x,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);
  bitscount+=u_v(16,"camera_position_x_lower",camera->camera_direction_x,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(16,"camera_position_y_upper",camera->camera_direction_y,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(16,"camera_position_y_lower",camera->camera_direction_y,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(16,"camera_position_z_upper",camera->camera_direction_z,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);
  bitscount+=u_v(16,"camera_position_z_lower",camera->camera_direction_z,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"camera_direction_x",camera->camera_direction_x,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"camera_direction_y",camera->camera_direction_y,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"camera_direction_z",camera->camera_direction_z,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"image_plane_vertical_x",camera->image_plane_vertical_x,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"image_plane_vertical_y",camera->image_plane_vertical_y,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);

  bitscount+=u_v(22,"image_plane_vertical_z",camera->image_plane_vertical_z,bitstream);
  bitscount+=u_v(1,"marker bit",1, bitstream);
  
  bitscount+=u_v(32,"reserved_bits",0,bitstream);
  
  k = bitscount >> 3;
  j = bitscount % 8;

  stuffbits = 8-(bitscount%8);
  
  if (stuffbits<8)
  {
    bitscount+=u_v(stuffbits,"stuff bits for byte align",0,bitstream);
  }
  
  write_start_code(pORABS, 0xb5);
	for(i=4;i<k;i++)
		write_n_bit(pORABS,CameraParametersExtension[i],8);
	write_n_bit(pORABS,CameraParametersExtension[k],j);
	write_align_stuff(pORABS);
//	fwrite(CameraParametersExtension,1,bitscount/8,f);

  free(bitstream);
  
  return bitscount;
}

/*
*************************************************************************
* Function:Write user data
* Input:
* Output:
* Return: user data length
* Attention:
*************************************************************************
*/

int WriteUserData(char *userdata)
{
  Bitstream *bitstream;
  byte UserData[MAXHEADERSIZE];
  int  bitscount=0;
  
  if ((bitstream=calloc(1, sizeof(Bitstream)))==NULL) no_mem_exit("User data: bitstream");
  bitstream->streamBuffer = UserData;
  bitstream->bits_to_go = 8;
  
  bitscount += u_v(32,"user data start code", 0x1b2,bitstream);
	write_start_code(pORABS, 0xb2);
	while (*userdata)
	{
		write_n_bit(pORABS,*userdata,8);
		bitscount += u_v(8,"user data", *userdata++,bitstream);
	}
	write_align_stuff(pORABS);
//	fwrite(UserData,1,bitscount/8,f);
  free(bitstream);
  
  return bitscount;
}

/*
*************************************************************************
* Function:Write bit steam to file
* Input:
* Output:
* Return: none
* Attention:
*************************************************************************
*/

void WriteBitstreamtoFile()
{
	int n, i;
	n = currBitStream->byte_pos;
	// deleted by jlzheng 6.30
/*	if(currBitStream->streamBuffer[0]==0 && currBitStream->streamBuffer[1]==0 && currBitStream->streamBuffer[2]==1)
	{
		write_start_code(pORABS, currBitStream->streamBuffer[3]);
		for(i=4;i<n;i++)
		{
			
			write_n_bit(pORABS, currBitStream->streamBuffer[i],8);
		}
	}
	else
	{ 
		for(i=0;i<n;i++)
			write_n_bit(pORABS, currBitStream->streamBuffer[i],8);
	}*/   
	  
	// added by jlzheng 6.30
   for(i=0;i<n;i++)
   {
    if(currBitStream->streamBuffer[i]==0 && currBitStream->streamBuffer[i+1]==0 && currBitStream->streamBuffer[i+2]==1)	
      {
		write_start_code(pORABS, currBitStream->streamBuffer[i+3]);
		i=i+4;
	  }                                      

		write_n_bit(pORABS, currBitStream->streamBuffer[i],8);
   }    


//   write_align_stuff(pORABS);       //commented by cjw AVS 20070204
    
	//bytecount = fwrite(currBitStream->streamBuffer,1,currBitStream->byte_pos,f);
	stat->bit_ctr += 8*n;
}
#endif

/////////////////////////////////////////////////////////////////////////////////////////////
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void error(char *text, int code)
{
	fprintf(stderr, "%s\n", text);
	exit(code);
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
int start_sequence()
{
	int len = 0;
	char id_string[255] = "AVS test stream";
	if(img->number==0)		//Added by cjw, 20070327
		OpenBitStreamFile(input->outfile);
	len = WriteSequenceHeader();
	len += WriteSequenceDisplayExtension();
	len += WriteCopyrightExtension();
	len += WriteCameraParametersExtension();
	if (strlen(id_string) > 1)
		len += WriteUserData(id_string);
	return len;
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:Mainly flushing of everything Add termination symbol, etc.
*************************************************************************
*/
int terminate_sequence()
{
	int len;
	len = WriteSequenceEnd();
	CloseBitStreamFile();
	return len;   // make lint happy
}
 

⌨️ 快捷键说明

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