📄 lencod.c
字号:
free_collocated(Co_located);
uninit_out_buffer();
free_global_buffers();
// free image mem
free_img ();
free_context_memory ();
FreeNalPayloadBuffer();
FreeParameterSets();
return 0; //encode JM73_FME version
}
/*!
***********************************************************************
* \brief
* Terminates and reports statistics on error.
*
***********************************************************************
*/
void report_stats_on_error()
{
input->no_frames=img->number-1;
terminate_sequence();
flush_dpb();
fclose(p_in);
if (p_dec)
fclose(p_dec);
if (p_trace)
fclose(p_trace);
Clear_Motion_Search_Module ();
RandomIntraUninit();
FmoUninit();
// free structure for rd-opt. mode decision
clear_rdopt ();
#ifdef _LEAKYBUCKET_
calc_buffer();
#endif
// report everything
report();
free_picture (frame_pic);
if (top_pic)
free_picture (top_pic);
if (bottom_pic)
free_picture (bottom_pic);
free_dpb();
free_collocated(Co_located);
uninit_out_buffer();
free_global_buffers();
// free image mem
free_img ();
free_context_memory ();
FreeNalPayloadBuffer();
FreeParameterSets();
}
/*!
***********************************************************************
* \brief
* Initializes the POC structure with appropriate parameters.
*
***********************************************************************
*/
void init_poc()
{
// if(input->no_frames > (1<<15))error("too many frames",-998);
//the following should probably go in sequence parameters
// frame poc's increase by 2, field poc's by 1
img->pic_order_cnt_type=input->pic_order_cnt_type;
img->delta_pic_order_always_zero_flag=0;
img->num_ref_frames_in_pic_order_cnt_cycle= 1;
if (input->StoredBPictures)
{
img->offset_for_non_ref_pic = 0;
img->offset_for_ref_frame[0] = 2;
}
else
{
img->offset_for_non_ref_pic = -2*(input->successive_Bframe);
img->offset_for_ref_frame[0] = 2*(input->successive_Bframe+1);
}
if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
img->offset_for_top_to_bottom_field=0;
else
img->offset_for_top_to_bottom_field=1;
//the following should probably go in picture parameters
// img->pic_order_present_flag=0; //img->delta_pic_order_cnt[1] not sent
// POC200301
if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
{
img->pic_order_present_flag=0;
img->delta_pic_order_cnt_bottom = 0;
}
else
{
img->pic_order_present_flag=1;
img->delta_pic_order_cnt_bottom = 1;
}
}
/*!
***********************************************************************
* \brief
* Initializes the img->nz_coeff
* \par Input:
* none
* \par Output:
* none
* \ side effects
* sets omg->nz_coef[][][][] to -1
***********************************************************************
*/
void CAVLC_init()
{
unsigned int i, k, l;
for (i=0;i < img->PicSizeInMbs; i++)
for (k=0;k<4;k++)
for (l=0;l<6;l++)
img->nz_coeff[i][k][l]=-1;
}
/*!
***********************************************************************
* \brief
* Initializes the Image structure with appropriate parameters.
* \par Input:
* Input Parameters struct inp_par *inp
* \par Output:
* Image Parameters struct img_par *img
***********************************************************************
*/
void init_img()
{
int i,j;
img->num_reference_frames = active_sps->num_ref_frames;
img->max_num_references = active_sps->frame_mbs_only_flag ? active_sps->num_ref_frames : 2 * active_sps->num_ref_frames;
img->buf_cycle = input->num_reference_frames;
img->DeblockCall = 0;
// img->framerate=INIT_FRAME_RATE; // The basic frame rate (of the original sequence)
img->framerate=input->FrameRate; // The basic frame rate (of the original sequence)
get_mem_mv (&(img->pred_mv));
get_mem_mv (&(img->all_mv));
get_mem_ACcoeff (&(img->cofAC));
get_mem_DCcoeff (&(img->cofDC));
if(input->MbInterlace)
{
get_mem_mv (&(rddata_top_frame_mb.pred_mv));
get_mem_mv (&(rddata_top_frame_mb.all_mv));
get_mem_mv (&(rddata_bot_frame_mb.pred_mv));
get_mem_mv (&(rddata_bot_frame_mb.all_mv));
get_mem_mv (&(rddata_top_field_mb.pred_mv));
get_mem_mv (&(rddata_top_field_mb.all_mv));
get_mem_mv (&(rddata_bot_field_mb.pred_mv));
get_mem_mv (&(rddata_bot_field_mb.all_mv));
get_mem_ACcoeff (&(rddata_top_frame_mb.cofAC));
get_mem_DCcoeff (&(rddata_top_frame_mb.cofDC));
get_mem_ACcoeff (&(rddata_bot_frame_mb.cofAC));
get_mem_DCcoeff (&(rddata_bot_frame_mb.cofDC));
get_mem_ACcoeff (&(rddata_top_field_mb.cofAC));
get_mem_DCcoeff (&(rddata_top_field_mb.cofDC));
get_mem_ACcoeff (&(rddata_bot_field_mb.cofAC));
get_mem_DCcoeff (&(rddata_bot_field_mb.cofDC));
}
if ((img->quad = (int*)calloc (511, sizeof(int))) == NULL)
no_mem_exit ("init_img: img->quad");
img->quad+=255;
for (i=0; i < 256; ++i)
{
img->quad[i]=img->quad[-i]=i*i;
}
img->width = input->img_width;
img->height = input->img_height;
img->width_cr = input->img_width/2;
img->height_cr= input->img_height/2;
img->PicWidthInMbs = input->img_width/MB_BLOCK_SIZE;
img->FrameHeightInMbs = input->img_height/MB_BLOCK_SIZE;
img->FrameSizeInMbs = img->PicWidthInMbs * img->FrameHeightInMbs;
img->PicHeightInMapUnits = ( active_sps->frame_mbs_only_flag ? img->FrameHeightInMbs : img->FrameHeightInMbs/2 );
if(((img->mb_data) = (Macroblock *) calloc(img->FrameSizeInMbs,sizeof(Macroblock))) == NULL)
no_mem_exit("init_img: img->mb_data");
if(input->UseConstrainedIntraPred)
{
if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs,sizeof(int))) == NULL)
no_mem_exit("init_img: img->intra_block");
}
get_mem2Dint(&(img->ipredmode), img->width/BLOCK_SIZE, img->height/BLOCK_SIZE); //need two extra rows at right and bottom
if(input->MbInterlace)
{
get_mem2Dint(&(rddata_top_frame_mb.ipredmode), img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
get_mem2Dint(&(rddata_bot_frame_mb.ipredmode), img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
get_mem2Dint(&(rddata_top_field_mb.ipredmode), img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
get_mem2Dint(&(rddata_bot_field_mb.ipredmode), img->width/BLOCK_SIZE, img->height/BLOCK_SIZE);
}
// CAVLC mem
get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 6);
CAVLC_init();
for (i=0; i < img->width/BLOCK_SIZE; i++)
for (j=0; j < img->height/BLOCK_SIZE; j++)
{
img->ipredmode[i][j]=-1;
}
img->mb_y_upd=0;
RandomIntraInit (img->width/16, img->height/16, input->RandomIntraMBRefresh);
InitSEIMessages(); // Tian Dong (Sept 2002)
// Initialize filtering parameters. If sending parameters, the offsets are
// multiplied by 2 since inputs are taken in "div 2" format.
// If not sending paramters, all fields are cleared
if (input->LFSendParameters)
{
input->LFAlphaC0Offset <<= 1;
input->LFBetaOffset <<= 1;
}
else
{
input->LFDisableIdc = 0;
input->LFAlphaC0Offset = 0;
input->LFBetaOffset = 0;
}
}
/*!
***********************************************************************
* \brief
* Free the Image structures
* \par Input:
* Image Parameters struct img_par *img
***********************************************************************
*/
void free_img ()
{
CloseSEIMessages(); // Tian Dong (Sept 2002)
free_mem_mv (img->pred_mv);
free_mem_mv (img->all_mv);
free_mem_ACcoeff (img->cofAC);
free_mem_DCcoeff (img->cofDC);
free (img->quad-255);
}
/*!
************************************************************************
* \brief
* Allocates the picture structure along with its dependent
* data structures
* \return
* Pointer to a Picture
************************************************************************
*/
Picture *malloc_picture()
{
Picture *pic;
if ((pic = calloc (1, sizeof (Picture))) == NULL) no_mem_exit ("malloc_picture: Picture structure");
//! Note: slice structures are allocated as needed in code_a_picture
return pic;
}
/*!
************************************************************************
* \brief
* Frees a picture
* \param
* pic: POinter to a Picture to be freed
************************************************************************
*/
void free_picture(Picture *pic)
{
if (pic != NULL)
{
free_slice_list(pic);
free (pic);
}
}
/*!
************************************************************************
* \brief
* Reports the gathered information to appropriate outputs
* \par Input:
* struct inp_par *inp, \n
* struct img_par *img, \n
* struct stat_par *stat, \n
* struct stat_par *stat \n
*
* \par Output:
* None
************************************************************************
*/
void report()
{
int bit_use[NUM_PIC_TYPE][2] ;
int i,j;
char name[20];
int total_bits;
float frame_rate;
float mean_motion_info_bit_use[2];
#ifndef WIN32
time_t now;
struct tm *l_time;
char string[1000];
#else
char timebuf[128];
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -