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

📄 lencod.c

📁 Mobile IP VCEG的信道模拟程序
💻 C
📖 第 1 页 / 共 4 页
字号:
// *************************************************************************************
// *************************************************************************************
// Lencod.c	 H.26L encoder project main
//
// Main contributors (see contributors.h for copyright, address and affiliation details)
//
// Inge Lille-Lang鴜               <inge.lille-langoy@telenor.com>
// Rickard Sjoberg                 <rickard.sjoberg@era.ericsson.se>
// Stephan Wenger                  <stewe@cs.tu-berlin.de>
// Jani Lainema                    <jani.lainema@nokia.com>
// Byeong-Moon Jeon                <jeonbm@lge.com>
// Yoon-Seong Soh                  <yunsung@lge.com>
// Thomas Stockhammer              <stockhammer@ei.tum.de>
// Detlev Marpe                    <marpe@hhi.de>
// Guido Heising                   <heising@hhi.de> 
// *************************************************************************************
// *************************************************************************************

#include "contributors.h"

#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/timeb.h>
#include <stdlib.h>

#include "global.h"
#include "configfile.h"

#define TML 	"6"
#define VERSION "6.50"

InputParameters inputs, *input = &inputs;
ImageParameters images, *img   = &images;
StatParameters  stats,  *stat  = &stats;
SNRParameters   snrs,   *snr   = &snrs;


#ifdef _ADAPT_LAST_GROUP_
int initial_Bframes = 0;
#endif


int main(int argc,char **argv)
{
	p_dec = p_stat = p_log = p_datpart = p_trace = NULL;

	Configure (argc, argv);

	/* Initialize Image Parameters */
	init_img();

	/* Allocate Slice data struct */
	malloc_slice();

#ifdef _RD_OPT_
	/* create and init structure for rd-opt. mode decision */
	init_rdopt ();
#endif
#ifdef _FAST_FULL_ME_
	/* create arrays for fast full motion estimation */
	InitializeFastFullIntegerSearch	(input->search_range);
#endif

	/* Initialize Statistic Parameters */
	init_stat();

	/* allocate memory for frame buffers*/
	get_mem4global_buffers(); 

	/* Just some information which goes to the standard output */
	information_init(argv[1]);

	/* Write sequence header; open bitstream files */
	start_sequence();

	/* B pictures */
	Bframe_ctr=0;
	tot_time=0;                 // time for total encoding session 

#ifdef _ADAPT_LAST_GROUP_
	if (input->last_frame > 0)
	  input->no_frames = 1 + (input->last_frame + input->jumpd) / (input->jumpd + 1);
	initial_Bframes = input->successive_Bframe;
#endif

	for (img->number=0; img->number < input->no_frames; img->number++)
	{
		if (img->number == 0)           
			img->type = INTRA_IMG;				/* set image type for first image to I-frame */
		else                          
			img->type = INTER_IMG;				/* P-frame */

#ifdef _ADAPT_LAST_GROUP_
		if (input->successive_Bframe && input->last_frame && img->number+1 == input->no_frames)
		  {
		    int bi = (int)((float)(input->jumpd+1)/(input->successive_Bframe+1.0)+0.499999);
		    input->successive_Bframe = (input->last_frame-(img->number-1)*(input->jumpd+1))/bi-1;
		  }
#endif

		encode_one_frame(); /* encode one I- or P-frame */ 
		
		if ((input->successive_Bframe != 0) && (img->number > 0)) /* B-frame(s) to encode */
		{
			img->type = B_IMG;						/* set image type to B-frame */
			for(img->b_frame_to_code=1; img->b_frame_to_code<=input->successive_Bframe; img->b_frame_to_code++) 
				encode_one_frame();	 /* encode one B-frame */ 					
		}
	}

	/* terminate sequence */
	terminate_sequence();

#ifdef _FAST_FULL_ME_
	/* free arrays for fast full motion estimation */
	ClearFastFullIntegerSearch ();
#endif
#ifdef _RD_OPT_
	/* free structure for rd-opt. mode decision */
	clear_rdopt ();
#endif

	/* report everything */
	report();
	
	free_slice();

	/* free allocated memory for frame buffers*/
	free_mem4global_buffers(); 

	/* free image mem */
	free_img ();

	return 0; 
}


/************************************************************************
*
*  Name :       void init_img()
*
*  Description: Initializes the Image structure with appropriate parameters
*
*  Input      : Input Parameters struct inp_par *inp
*
*  Output     : Image Parameters struct img_par *img
*
************************************************************************/
void init_img()
{
    int i,j;

    img->no_multpred=input->no_multpred;
#ifdef _ADDITIONAL_REFERENCE_FRAME_
    img->buf_cycle = max (input->no_multpred, input->add_ref_frame+1);
#else
    img->buf_cycle = input->no_multpred;
#endif
    img->framerate=INIT_FRAME_RATE;   /* The basic frame rate (of the original sequence) */

    get_mem_mv (&(img->mv));
    get_mem_mv (&(img->p_fwMV));
    get_mem_mv (&(img->p_bwMV));
    get_mem_mv (&(img->all_mv));
    get_mem_mv (&(img->all_bmv));

	img->width    = input->img_width;
	img->height   = input->img_height;
	img->width_cr = input->img_width/2;
	img->height_cr= input->img_height/2;
 
		if(((img->mb_data) = (Macroblock *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL) 
			no_mem_exit(1);

 		if(((img->slice_numbers) = (int *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(int))) == NULL) 
			no_mem_exit(1);
 
 
		init(img);
    
    /* allocate memory for intra pred mode buffer for each block: img->ipredmode*/ 
    /* int  img->ipredmode[90][74]; */
    get_mem2Dint(&(img->ipredmode), img->width/BLOCK_SIZE+2, img->height/BLOCK_SIZE+2);

    /* Prediction mode is set to -1 outside the frame, indicating that no prediction can be made from this part*/
    for (i=0; i < img->width/BLOCK_SIZE + 2; i++)
    {
    	img->ipredmode[i][0] = -1;
    	img->ipredmode[i][img->height/BLOCK_SIZE + 1] = -1;
    }
    for (j=0; j < img->height/BLOCK_SIZE + 2; j++)
    {
    	img->ipredmode[0][j] = -1;
    	img->ipredmode[img->width/BLOCK_SIZE + 1][j] = -1;
    }

    img->mb_y_upd=0;

}


void free_img ()
{
  free_mem_mv (img->mv);
  free_mem_mv (img->p_fwMV);
  free_mem_mv (img->p_bwMV);
  free_mem_mv (img->all_mv);
  free_mem_mv (img->all_bmv);
}


/************************************************************************
*
*  Name :       void malloc_slice()
*
*  Description: Allocates the slice structure along with its dependent 
*				data structures
*
*  Input      : Input Parameters struct inp_par *inp,  struct img_par *img
*
************************************************************************/
void malloc_slice()
{
	int i;
	DataPartition *dataPart;
	Slice *currSlice;
	const int buffer_size = (img->width * img->height * 3)/2; /* DM 070301: The only assumption here is that we */
															  /* do not consider the case of data expansion. */
															  /* So this is a strictly conservative estimation	*/
															  /* of the size of the bitstream buffer for one frame */																												/* ~DM */

	switch(input->of_mode) /* init depending on NAL mode */
	{
		case PAR_OF_26L:
			/* Current File Format */
			img->currentSlice = (Slice *) calloc(1, sizeof(Slice));
			if ( (currSlice = img->currentSlice) == NULL)
			{
				fprintf(stderr, "Memory allocation for Slice datastruct in NAL-mode %d failed", input->of_mode);
				exit(1);
			}
			if (input->symbol_mode == CABAC)
			{
				/* create all context models */
				currSlice->mot_ctx = create_contexts_MotionInfo();
				currSlice->tex_ctx = create_contexts_TextureInfo();
			}

			switch(input->partition_mode)
			{
			case PAR_DP_1:
				currSlice->max_part_nr = 1;
				break;
			default:
				error("Data Partitioning Mode not supported!");
				break;
			}



			currSlice->partArr = (DataPartition *) calloc(currSlice->max_part_nr, sizeof(DataPartition));
			if (currSlice->partArr == NULL)
			{
				fprintf(stderr, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", input->of_mode);
				exit(1);
			}			
			for (i=0; i<currSlice->max_part_nr; i++) /* loop over all data partitions */
			{				
				dataPart = &(currSlice->partArr[i]);
				dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
				if (dataPart->bitstream == NULL)
				{
					fprintf(stderr, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", input->of_mode);
					exit(1);
				}
				dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));
				if (dataPart->bitstream->streamBuffer == NULL)
				{
					fprintf(stderr, "Memory allocation for bitstream buffer in NAL-mode %d failed", input->of_mode);
					exit(1);
				}
				/* Initialize storage of bitstream parameters */
				dataPart->bitstream->stored_bits_to_go = 8;
				dataPart->bitstream->stored_byte_pos = 0;
				dataPart->bitstream->stored_byte_buf = 0;
			}
			return;
		default: 
			fprintf(stderr, "Output File Mode %d not supported", input->of_mode);
			exit(1);
	}				
	
}



/************************************************************************
*
*  Name :       void free_slice()
*
*  Description: Memory frees of the Slice structure and of its dependent 
*				data structures
*
*  Input      : Input Parameters struct inp_par *inp,  struct img_par *img
*
************************************************************************/
void free_slice()
{
	int i;
	DataPartition *dataPart;
	Slice *currSlice = img->currentSlice;

	switch(input->of_mode) /* init depending on NAL mode */
	{
		case PAR_OF_26L:
			/* Current File Format */
			/* Remenber that we have two partitions for CABAC */
			for (i=0; i<currSlice->max_part_nr; i++) /* loop over all data partitions */
			{	
				dataPart = &(currSlice->partArr[i]);	
				if (dataPart->bitstream->streamBuffer != NULL)
					free(dataPart->bitstream->streamBuffer);
				if (dataPart->bitstream != NULL)
					free(dataPart->bitstream);
			}
			if (currSlice->partArr != NULL)
				free(currSlice->partArr);
			if (input->symbol_mode == CABAC)
			{
				/* delete all context models */
				delete_contexts_MotionInfo(currSlice->mot_ctx);
				delete_contexts_TextureInfo(currSlice->tex_ctx);
			}
			if (currSlice != NULL)
				free(img->currentSlice);
			break;
		default: 
			fprintf(stderr, "Output File Mode %d not supported", input->of_mode);
			exit(1);
	}				
	
}


/************************************************************************
*
*  Name :       void init_stat()
*
*  Description: Initializes the Image structure with appropriate parameters
*
*  Input      : Input Parameters struct inp_par *inp
*
*  Output     : Statistic Parameters struct stat_par *stat
*
************************************************************************/
void init_stat()
{
	int i;
	stat->mode_use_Bframe = (int *)malloc(sizeof(int)*41);
	stat->bit_use_mode_Bframe =  (int *)malloc(sizeof(int)*41);
	for(i=0; i<41; i++) 
		stat->mode_use_Bframe[i]=stat->bit_use_mode_Bframe[i]=0;
}

⌨️ 快捷键说明

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