📄 lencod.c
字号:
get_mem_mv (&(img->pred_mv));
get_mem_mv (&(img->all_mv));
if (input->BiPredMotionEstimation)
{
get_mem_mv (&(img->bipred_mv1));
get_mem_mv (&(img->bipred_mv2));
}
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->max_imgpel_value > img->max_imgpel_value_uv)
byte_abs_range = (img->max_imgpel_value + 1) * 2;
else
byte_abs_range = (img->max_imgpel_value_uv + 1) * 2;
if ((img->quad = (int*)calloc (byte_abs_range, sizeof(int))) == NULL)
no_mem_exit ("init_img: img->quad");
img->quad+=byte_abs_range/2;
for (i=0; i < byte_abs_range/2; ++i)
{
img->quad[i]=img->quad[-i]=i*i;
}
img->width = (input->img_width+img->auto_crop_right);
img->height = (input->img_height+img->auto_crop_bottom);
if (img->yuv_format != YUV400)
{
img->width_cr = img->width/(16/mb_width_cr[img->yuv_format]);
img->height_cr= img->height/(16/mb_height_cr[img->yuv_format]);
input->img_width_cr = input->img_width/(16/mb_width_cr[img->yuv_format]);
input->img_height_cr = input->img_height/(16/mb_height_cr[img->yuv_format]);
}
else
{
img->width_cr = 0;
img->height_cr= 0;
input->img_width_cr = 0;
input->img_height_cr = 0;
}
img->height_cr_frame = img->height_cr;
img->PicWidthInMbs = (input->img_width+img->auto_crop_right)/MB_BLOCK_SIZE;
img->FrameHeightInMbs = (input->img_height+img->auto_crop_bottom)/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_mem2D((byte***)&(img->ipredmode), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE); //need two extra rows at right and bottom
get_mem2D((byte***)&(img->ipredmode8x8), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE); // help storage for ipredmode 8x8, inserted by YV
get_mem2D((byte***)&(rddata_top_frame_mb.ipredmode), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
if(input->MbInterlace)
{
get_mem2D((byte***)&(rddata_bot_frame_mb.ipredmode), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
get_mem2D((byte***)&(rddata_top_field_mb.ipredmode), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
get_mem2D((byte***)&(rddata_bot_field_mb.ipredmode), img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
}
// CAVLC mem
get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 4+img->num_blk8x8_uv);
get_mem2Ddb_offset(&(img->lambda_md), 10, 52 + img->bitdepth_luma_qp_scale,img->bitdepth_luma_qp_scale);
get_mem2Ddb_offset(&(img->lambda_me), 10, 52 + img->bitdepth_luma_qp_scale,img->bitdepth_luma_qp_scale);
get_mem2Dint_offset(&(img->lambda_mf), 10, 52 + img->bitdepth_luma_qp_scale,img->bitdepth_luma_qp_scale);
//get_mem2Ddouble(&(img->lambda_md), 10, 52 + img->bitdepth_luma_qp_scale);
CAVLC_init();
for (i=0; i < img->width/BLOCK_SIZE; i++)
for (j=0; j < img->height/BLOCK_SIZE; j++)
{
img->ipredmode[j][i]=-1;
img->ipredmode8x8[j][i]=-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 parameters, 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);
if (input->BiPredMotionEstimation)
{
free_mem_mv (img->bipred_mv1);
free_mem_mv (img->bipred_mv2);
}
free_mem_ACcoeff (img->cofAC);
free_mem_DCcoeff (img->cofDC);
if(input->MbInterlace)
{
free_mem_mv (rddata_top_frame_mb.pred_mv);
free_mem_mv (rddata_top_frame_mb.all_mv);
free_mem_mv (rddata_bot_frame_mb.pred_mv);
free_mem_mv (rddata_bot_frame_mb.all_mv);
free_mem_mv (rddata_top_field_mb.pred_mv);
free_mem_mv (rddata_top_field_mb.all_mv);
free_mem_mv (rddata_bot_field_mb.pred_mv);
free_mem_mv (rddata_bot_field_mb.all_mv);
free_mem_ACcoeff (rddata_top_frame_mb.cofAC);
free_mem_DCcoeff (rddata_top_frame_mb.cofDC);
free_mem_ACcoeff (rddata_bot_frame_mb.cofAC);
free_mem_DCcoeff (rddata_bot_frame_mb.cofDC);
free_mem_ACcoeff (rddata_top_field_mb.cofAC);
free_mem_DCcoeff (rddata_top_field_mb.cofDC);
free_mem_ACcoeff (rddata_bot_field_mb.cofAC);
free_mem_DCcoeff (rddata_bot_field_mb.cofDC);
}
if(img->max_imgpel_value > img->max_imgpel_value_uv)
free (img->quad-(img->max_imgpel_value + 1));
else
free (img->quad-(img->max_imgpel_value_uv + 1));
if(input->MbInterlace)
{
free_mem2D((byte**)rddata_bot_frame_mb.ipredmode);
free_mem2D((byte**)rddata_top_field_mb.ipredmode);
free_mem2D((byte**)rddata_bot_field_mb.ipredmode);
}
}
/*!
************************************************************************
* \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 frame statistical data to a stats file
************************************************************************
*/
void report_frame_statistic()
{
FILE *p_stat_frm = NULL;
static int last_mode_use[NUM_PIC_TYPE][MAXMODE];
static int last_b8_mode_0[NUM_PIC_TYPE][2];
static int last_mode_chroma_use[4];
static int last_bit_ctr_n = 0;
int i;
char name[20];
int bitcounter;
#ifndef WIN32
time_t now;
struct tm *l_time;
char string[1000];
#else
char timebuf[128];
#endif
// write to log file
if ((p_stat_frm=fopen("stat_frame.dat","r"))==0) // check if file exist
{
if ((p_stat_frm=fopen("stat_frame.dat","a"))==NULL) // append new statistic at the end
{
snprintf(errortext, ET_SIZE, "Error open file %s \n","stat_frame.dat.dat");
error(errortext, 500);
}
else // Create header for new log file
{
fprintf(p_stat_frm," --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_stat_frm,"| Encoder statistics. This file is generated during first encoding session, new sessions will be appended |\n");
fprintf(p_stat_frm," --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
}
}
else
{
fclose (p_stat_frm);
if ((p_stat_frm=fopen("stat_frame.dat","a"))==NULL) // File exist,just open for appending
{
snprintf(errortext, ET_SIZE, "Error open file %s \n","stat_frame.dat.dat");
error(errortext, 500);
}
}
if (frame_statistic_start)
{
fprintf(p_stat_frm,"| ver | Date | Time | Sequence |Frm | QP |P/MbInt| Bits | SNRY | SNRU | SNRV | I4 | I8 | I16 | IC0 | IC1 | IC2 | IC3 | PI4 | PI8 | PI16 | P0 | P1 | P2 | P3 | P1*8*| P1*4*| P2*8*| P2*4*| P3*8*| P3*4*| P8 | P8:4 | P4*8*| P4*4*| P8:5 | P8:6 | P8:7 | BI4 | BI8 | BI16 | B0 | B1 | B2 | B3 | B0*8*| B0*4*| B1*8*| B1*4*| B2*8*| B2*4*| B3*8*| B3*4*| B8 | B8:0 |B80*8*|B80*4*| B8:4 | B4*8*| B4*4*| B8:5 | B8:6 | B8:7 |\n");
fprintf(p_stat_frm," --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n");
}
//report
fprintf(p_stat_frm,"|%4s/%s", VERSION, EXT_VERSION);
#ifdef WIN32
_strdate( timebuf );
fprintf(p_stat_frm,"| %1.5s |",timebuf );
_strtime( timebuf);
fprintf(p_stat_frm," % 1.5s |",timebuf);
#else
now = time ((time_t *) NULL); // Get the system time and put it into 'now' as 'calender time'
time (&now);
l_time = localtime (&now);
strftime (string, sizeof string, "%d-%b-%Y", l_time);
fprintf(p_stat_frm,"| %1.5s |",string );
strftime (string, sizeof string, "%H:%M:%S", l_time);
fprintf(p_stat_frm," %1.5s |",string );
#endif
for (i=0;i<20;i++)
name[i]=input->infile[i+max(0,(int) (strlen(input->infile)-20))]; // write last part of path, max 20 chars
fprintf(p_stat_frm,"%20.20s|",name);
fprintf(p_stat_frm,"%3d |",frame_no);
fprintf(p_stat_frm,"%3d |",img->qp);
fprintf(p_stat_frm," %d/%d |",input->PicInterlace, input->MbInterlace);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -