编码主程序main

来源:百度文库 编辑:神马文学网 时间:2024/04/24 18:53:05
编码主程序main整个main函数分解

1.int M,N,n,np,nb;                            //Rate control
p_dec = p_in = -1;                           //(int) P_in: originalYUV file handle
                                                         //(int) P_dec: decoded image file handle
p_stat = p_log = p_trace = NULL;//(FILE *)P_start: status file for the last encoding session
                                                         //(FILE *)P_log: SNR file
                                                         //(FILE *)P_trace: Trace file
frame_statistic_start = 1;               //flag to indicate whether frame statistic start

2.Configure (argc, argv); 
                                                        //Parse the command line parameters and read the config files.
                                                        //all the parameters be put into input..and has been checked检查合理性..

3 Init_QMatrix();                           //Initialise Q matrix values.
//该函数:
//if(input->ScalingMatrixPresentFlag)
// content = GetConfigFileContent(input->QmatrixFile, 0);//将文本file内容取出到content内存
// if(content!='\0') ParseMatrix(content, strlen (content));//将INTRA4X4_LUMA、
//INTRA4X4_CHROMAU、INTRA4X4_CHROMAV、INTER4X4_LUMA、INTER4X4_CHROMAU、
//INTER4X4_CHROMAV、INTRA8X8_LUMA、INTER8X8_LUMA取出
// PatchMatrix();//Check Q Matrix values如果直接赋值是否可以省略??
// memset(UseDefaultScalingMatrix4x4Flag, 0, sizeof(short)*6);
// UseDefaultScalingMatrix8x8Flag[0]=UseDefaultScalingMatrix8x8Flag[1]=0;

4.AllocNalPayloadBuffer();   //Initializes NAL module (allocates NAL_Payload_buffer)
//该函数主要功能是分配大小是img_width * img_height * 4的空间to NAL_Payload_buffer
//*4防止溢出,函数先施放空间FreeNalPayloadBuffer(),再分配空间。

5.init_poc();                           //Initializes the POC structure with appropriate parameters.

6.GenerateParameterSets();
//generates a sequence and picture parameter set
//and stores these in global active_sps and active_pps
7.init_img();
//Initializes the Image structure with appropriate parameters.
8.frame_pic = malloc_picture();
if (input->PicInterlace != FRAME_CODING)
{
top_pic = malloc_picture();
bottom_pic = malloc_picture();
}

9.init_rdopt ();

if (input->PyramidCoding )
{
init_gop_structure();
if (input->PyramidCoding == 3)
{
interpret_gop_structure();
}
else
{
create_pyramid();
}
}

10.init_dpb(input);
init_out_buffer();

11.enc_picture = enc_frame_picture = enc_top_picture = enc_bottom_picture = NULL;

12.init_global_buffers();

13.create_context_memory ();

14.Init_Motion_Search_Module ();

15.information_init();

16.//Rate control
if(input->RCEnable)
rc_init_seq();
if(input->FMEnable)
DefineThreshold();

17.Bframe_ctr=0;                  // B pictures
18.tot_time=0;                      // time for total encoding session

19.#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

20.PatchInputNoFrames();

21.// Write sequence header (with parameter sets)
stats->bit_ctr_parametersets = 0;
stats->bit_slice = start_sequence();
stats->bit_ctr_parametersets += stats->bit_ctr_parametersets_n;
start_frame_no_in_this_IGOP = 0;

22.for (img->number=0; img->number < input->no_frames; img->number++)//main
{}

23.terminate_sequence();// terminate sequence

24.flush_dpb();

25.close(p_in);
if (-1!=p_dec) close(p_dec);
if (p_trace) fclose(p_trace);

26.Clear_Motion_Search_Module ();

27.RandomIntraUninit();

28.FmoUninit();

29.if (input->PyramidCoding) clear_gop_structure ();


30.clear_rdopt (); // free structure for rd-opt. mode decision

31.#ifdef _LEAKYBUCKET_
calc_buffer();
#endif

32.report(); // report everything

33.free_picture (frame_pic);
if (top_pic) free_picture (top_pic);
if (bottom_pic) free_picture (bottom_pic);

34.free_dpb();

35.free_collocated(Co_located);

36.uninit_out_buffer();

37.free_global_buffers();

38.free_img ();                           // free image mem

39.free_context_memory ();

40.FreeNalPayloadBuffer();

41.FreeParameterSets();
42.return 0;                               //encode JM73_FME version