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

📄 header.c

📁 AVS视频编解码器 能实现视频图像的高效率压缩 能在VC上高速运行
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the users without any
* license fee or royalty on an "as is" basis. The AVS disclaims
* any and all warranties, whether express, implied, or statutory,
* including any implied warranties of merchantability or of fitness
* for a particular purpose. In no event shall the contributors or 
* the AVS be liable for any incidental, punitive, or consequential
* damages of any kind whatsoever arising from the use of this program.
*
* This disclaimer of warranty extends to the user of this program
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The AVS does not represent or warrant that the program furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy is available from the AVS Web site at
* http://www.avs.org.cn
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
************************************************************************
*/

/*
*************************************************************************************
* File name: header.c
* Function: AVS Slice headers
*
*************************************************************************************
*/


#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "memalloc.h"
#include "global.h"
#include "elements.h"
#include "defines.h"
#include "vlc.h"
#include "header.h"
CameraParamters CameraParameter, *camera=&CameraParameter;
/*
*************************************************************************
* Function:sequence header  
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void SequenceHeader (char *buf,int startcodepos, int length)
{

	memcpy (currStream->streamBuffer, buf, length);
	currStream->code_len = currStream->bitstream_length = length;
	currStream->read_len = currStream->frame_bitoffset = (startcodepos+1)*8;
	
	//u_v(8, "stuffing bit"); //commented by cjw AVS Zhuhai 20070122
	profile_id                  = u_v  (8, "profile_id"  );
	level_id                    = u_v  (8, "level_id"    );
	progressive_sequence        = u_v  (1, "progressive_sequence"  );
	horizontal_size             = u_v  (14, "horizontal_size"  );
	vertical_size               = u_v  (14, "vertical_size"  );
	chroma_format               = u_v  (2, "chroma_format"  );
	sample_precision            = u_v  (3, "sample_precision"  );
	aspect_ratio_information    = u_v  (4, "aspect_ratio_information"  );
	frame_rate_code             = u_v  (4, "frame_rate_code"  );

	bit_rate_lower              = u_v  (18, "bit_rate_lower"  );
	u_v  (1, "marker bit"  );
	bit_rate_upper              = u_v  (12, "bit_rate_upper"  );
	low_delay                   = u_v  (1, "low_delay"  );
	u_v  (1, "marker bit"  );
	bbv_buffer_size = u_v(18,"bbv buffer size");

	u_v  (3,"reseved bits"  );
	
	img->width          = horizontal_size;
	img->height         = vertical_size;
	img->width_cr       = (img->width>>1);
	img->height_cr      = (img->height>>1);
	img->PicWidthInMbs  = img->width/MB_BLOCK_SIZE;
	img->PicHeightInMbs = img->height/MB_BLOCK_SIZE;
	img->PicSizeInMbs   = img->PicWidthInMbs * img->PicHeightInMbs;
	img->buf_cycle      = input->buf_cycle+1;
	img->max_mb_nr      =(img->width * img->height) / (MB_BLOCK_SIZE * MB_BLOCK_SIZE);
  
}


void video_edit_code_data(char *buf,int startcodepos, int length)
{
	currStream->frame_bitoffset = currStream->read_len = (startcodepos+1)*8;
	currStream->code_len = currStream->bitstream_length = length;
	memcpy (currStream->streamBuffer, buf, length);
	vec_flag = 1;
}
/*
*************************************************************************
* Function:I picture header  //sw
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void I_Picture_Header(char *buf,int startcodepos, int length)
{
	currStream->frame_bitoffset = currStream->read_len = (startcodepos+1)*8;
	currStream->code_len = currStream->bitstream_length = length;
	memcpy (currStream->streamBuffer, buf, length);
	
	bbv_delay = u_v(16,"bbv delay");
	
	time_code_flag       = u_v(1,"time_code_flag");
	if (time_code_flag)
		time_code        =u_v(24,"time_code");
	
	marker_bit            =u_v(1,"marker_bit");
	picture_distance         = u_v(8,"picture_distance");
	
	//xyji 12.23 
	if(low_delay)
	{
		bbv_check_times = ue_v("bbv check times");
	}
	
	progressive_frame    = u_v(1,"progressive_frame");
	if (!progressive_frame)
	{
		img->picture_structure   = u_v(1,"picture_structure");
	}else
	{
		img->picture_structure = 1;
	}
	
	top_field_first      = u_v(1,"top_field_first");
	repeat_first_field   = u_v(1,"repeat_first_field");
	fixed_picture_qp     = u_v(1,"fixed_picture_qp");
	picture_qp           = u_v(6,"picture_qp");
	
	//xyji 12.23  
	if(progressive_frame==0)  //according to m1658 by oliver 
	if(img->picture_structure == 0)
	{
		skip_mode_flag =u_v(1,"skip mode flag");
	}
	
	u_v(4,"reserved bits");

	loop_filter_disable = u_v(1,"loop_filter_disable");
	if (!loop_filter_disable)
	{
		loop_filter_parameter_flag = u_v(1,"loop_filter_parameter_flag");
		if (loop_filter_parameter_flag)
		{
			alpha_offset = se_v("alpha_offset");
			beta_offset  = se_v("beta_offset");
		}
	}
	
	img->qp                = picture_qp;
	img->pic_distance      = picture_distance;	
	img->type              = I_IMG;
  
}

/*
*************************************************************************
* Function:pb picture header 
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void PB_Picture_Header(char *buf,int startcodepos, int length)
{
	currStream->frame_bitoffset = currStream->read_len = (startcodepos+1)*8;
	currStream->code_len = currStream->bitstream_length = length;
	memcpy (currStream->streamBuffer, buf, length);
	
	bbv_delay = u_v(16,"bbv delay");  
	picture_coding_type       = u_v(2,"picture_coding_type");
	
	picture_distance         = u_v(8,"picture_distance");
	
	//xyji 12.23
	if(low_delay)
	{
		bbv_check_times = ue_v("bbv check times");
	}
	
	progressive_frame        = u_v(1,"progressive_frame");
	if (!progressive_frame)
	{
		img->picture_structure = u_v(1,"picture_structure");
		if (!img->picture_structure)
			img->advanced_pred_mode_disable = u_v(1,"advanced_pred_mode_disable");
	}else
		img->picture_structure   = 1;
	top_field_first        = u_v(1,"top_field_first");
	repeat_first_field     = u_v(1,"repeat_first_field");
	
	fixed_picture_qp       = u_v(1,"fixed_picture_qp");
	picture_qp             = u_v(6,"picture_qp");
	
	
	if (!(picture_coding_type==2 && img->picture_structure==1))
	{
		picture_reference_flag = u_v(1,"picture_reference_flag");
	}
	u_v(1, "no_forward_reference_flag");	// Added by cjw, 20070327
//	u_v(4,"reserved bits");					// Commented by cjw, 20070327
	u_v(3,"reserved bits");					// Added by cjw, 20070327
	
	skip_mode_flag      = u_v(1,"skip_mode_flag");
	loop_filter_disable = u_v(1,"loop_filter_disable");
	if (!loop_filter_disable)
	{
		loop_filter_parameter_flag = u_v(1,"loop_filter_parameter_flag");
		if (loop_filter_parameter_flag)
		{
			alpha_offset = se_v("alpha_offset");
			beta_offset  = se_v("beta_offset");
		}
	}
	
	img->qp                = picture_qp;
	
    if(picture_coding_type==1) {
        img->type = P_IMG;
        vec_flag = 0;       // M1956 by Grandview 2006.12.12
    } else {
        img->type = B_IMG;
    }
	
	img->pic_distance      = picture_distance;	
}
/*
*************************************************************************
* Function:decode extension and user data
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void extension_data(char *buf,int startcodepos, int length)
{
  int ext_ID;
	
  memcpy (currStream->streamBuffer, buf, length);
  currStream->code_len = currStream->bitstream_length = length;
  currStream->read_len = currStream->frame_bitoffset = (startcodepos+1)*8;
	
	ext_ID = u_v(4,"extension ID");
	
	switch (ext_ID)
	{
	case SEQUENCE_DISPLAY_EXTENSION_ID:
		sequence_display_extension();
		break;
	case COPYRIGHT_EXTENSION_ID:
		copyright_extension();
		break;
	case PICTURE_DISPLAY_EXTENSION_ID:
		picture_display_extension();
	case CAMERAPARAMETERS_EXTENSION_ID: 
		cameraparameters_extension();
		break;
	default:
		printf("reserved extension start code ID %d\n",ext_ID);
		break;
	}

}
/*
*************************************************************************
* Function: decode sequence display extension
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void sequence_display_extension()
{
	video_format      = u_v(3,"video format ID");
	video_range       = u_v(1,"video range");
	color_description = u_v(1,"color description");
	
	if (color_description)
	{
		color_primaries          = u_v(8,"color primaries");
		transfer_characteristics = u_v(8,"transfer characteristics");
		matrix_coefficients      = u_v(8,"matrix coefficients");
	}
	
	display_horizontal_size = u_v(14,"display_horizontaol_size");
	u_v  (1, "marker bit"  );
	display_vertical_size   = u_v(14,"display_vertical_size");
							u_v  (2, "reserved bits"  );
}

/*
*************************************************************************
* Function: decode picture display extension
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void picture_display_extension()
{
	int NumberOfFrameCentreOffsets;
	int i;
	
	if (progressive_sequence == 1) {
		if (repeat_first_field == 1){

⌨️ 快捷键说明

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