📄 lencod.c
字号:
*/
void init_poc()
{
int i;
if(input->no_frames > (1<<15))error("too many frames",-998);
if(input->no_multpred >= MAX_NO_POC_FRAMES)error("NumberReferenceFrames too large",-999);
for(i=0; i<MAX_NO_POC_FRAMES; i++){toprefpoc[i] = bottomrefpoc[i] = 1<<29;} //init with large
//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; // POC200301
img->num_ref_frames_in_pic_order_cnt_cycle=1;
img->delta_pic_order_always_zero_flag=0;
img->offset_for_non_ref_pic = -2*(input->successive_Bframe);
if (input->InterlaceCodingOption==FRAME_CODING)
img->offset_for_top_to_bottom_field=0;
else
img->offset_for_top_to_bottom_field=1;
img->offset_for_ref_frame[0] = 2*(input->successive_Bframe+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->InterlaceCodingOption==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
* Pushes values onto the POC ref arrays toprefpoc[] & bottomrefpoc[]
*
***********************************************************************
*/
void push_poc(unsigned int topvalue, unsigned int bottomvalue, unsigned int ref_frame_ind )
{
int i;
static int current_is_ref = 0; //indicates if current top value is for a ref frame
if(current_is_ref){
for(i=MAX_NO_POC_FRAMES-1; i>0; i--){ //move all the data down by one
toprefpoc[i] = toprefpoc[i-1] ;
bottomrefpoc[i] = bottomrefpoc[i-1] ;
}
}
toprefpoc[0] = topvalue; //put new data
bottomrefpoc[0] = bottomvalue;
current_is_ref = ref_frame_ind; //new data type
}
/*!
***********************************************************************
* \brief
* Initializes the img->nz_coeff
* \par Input:
* none
* \par Output:
* none
* \ side effects
* sets omg->nz_coef[][][][] to -1
***********************************************************************
*/
void CAVLC_init()
{
int i, j, k, l;
for (i=0;i < img->width/MB_BLOCK_SIZE; i++)
for (j=0; j < img->height/MB_BLOCK_SIZE; j++)
for (k=0;k<4;k++)
for (l=0;l<6;l++)
img->nz_coeff[i][j][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,size_x,size_y;
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->lindex=0;
img->max_lindex=0;
img->framerate=INIT_FRAME_RATE; // The basic frame rate (of the original sequence)
if(input->InterlaceCodingOption != FRAME_CODING)
img->buf_cycle *= 2;
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));
get_mem_mv (&(img->abp_all_dmv));
get_mem_ACcoeff (&(img->cofAC));
get_mem_DCcoeff (&(img->cofDC));
if(input->InterlaceCodingOption >= MB_CODING)
{
get_mem_mv (&(img->mv_top));
get_mem_mv (&(img->p_fwMV_top));
get_mem_mv (&(img->p_bwMV_top));
get_mem_mv (&(img->all_mv_top));
get_mem_mv (&(img->all_bmv_top));
get_mem_mv (&(img->mv_bot));
get_mem_mv (&(img->p_fwMV_bot));
get_mem_mv (&(img->p_bwMV_bot));
get_mem_mv (&(img->all_mv_bot));
get_mem_mv (&(img->all_bmv_bot));
get_mem_mv (&(rddata_top_frame_mb.mv));
get_mem_mv (&(rddata_top_frame_mb.p_fwMV));
get_mem_mv (&(rddata_top_frame_mb.p_bwMV));
get_mem_mv (&(rddata_top_frame_mb.all_mv));
get_mem_mv (&(rddata_top_frame_mb.all_bmv));
get_mem_mv (&(rddata_bot_frame_mb.mv));
get_mem_mv (&(rddata_bot_frame_mb.p_fwMV));
get_mem_mv (&(rddata_bot_frame_mb.p_bwMV));
get_mem_mv (&(rddata_bot_frame_mb.all_mv));
get_mem_mv (&(rddata_bot_frame_mb.all_bmv));
get_mem_mv (&(rddata_top_field_mb.mv));
get_mem_mv (&(rddata_top_field_mb.p_fwMV));
get_mem_mv (&(rddata_top_field_mb.p_bwMV));
get_mem_mv (&(rddata_top_field_mb.all_mv));
get_mem_mv (&(rddata_top_field_mb.all_bmv));
get_mem_mv (&(rddata_bot_field_mb.mv));
get_mem_mv (&(rddata_bot_field_mb.p_fwMV));
get_mem_mv (&(rddata_bot_field_mb.p_bwMV));
get_mem_mv (&(rddata_bot_field_mb.all_mv));
get_mem_mv (&(rddata_bot_field_mb.all_bmv));
get_mem_mv (&(img->abp_all_dmv_top));
get_mem_mv (&(img->abp_all_dmv_bot));
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(input->InterlaceCodingOption != FRAME_CODING)
img->buf_cycle /= 2;
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) // fix from TML1 / TML2 sw, truncation removed
{
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;
if(((img->mb_data) = (Macroblock *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL)
no_mem_exit("init_img: img->mb_data");
if(input->UseConstrainedIntraPred)
{
if(((img->intra_block) = (int**)calloc((j=(img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE)),sizeof(int))) == NULL)
no_mem_exit("init_img: img->intra_block");
for (i=0; i<j; i++)
{
if ((img->intra_block[i] = (int*)calloc(4, sizeof(int))) == NULL)
no_mem_exit ("init_img: img->intra_block");
}
}
// allocate memory for intra pred mode buffer for each block: img->ipredmode
// int img->ipredmode[90][74];
size_x=img->width/BLOCK_SIZE+3;
size_y=img->height/BLOCK_SIZE+3;
get_mem2Dint(&(img->ipredmode), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3); //need two extra rows at right and bottom
if(input->InterlaceCodingOption >= MB_CODING)
{
get_mem2Dint(&(img->ipredmode_top), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
get_mem2Dint(&(img->ipredmode_bot), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
get_mem2Dint(&(rddata_top_frame_mb.ipredmode), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
get_mem2Dint(&(rddata_bot_frame_mb.ipredmode), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
get_mem2Dint(&(rddata_top_field_mb.ipredmode), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
get_mem2Dint(&(rddata_bot_field_mb.ipredmode), img->width/BLOCK_SIZE+3, img->height/BLOCK_SIZE+3);
}
// CAVLC mem
if((img->nz_coeff = (int****)calloc(img->width/MB_BLOCK_SIZE,sizeof(int***))) == NULL)
no_mem_exit("get_mem4global_buffers: nzcoeff");
for(j=0;j<img->width/MB_BLOCK_SIZE;j++)
{
get_mem3Dint(&(img->nz_coeff[j]), img->height/MB_BLOCK_SIZE, 4, 6);
}
CAVLC_init();
// 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+1; i++)
{
// img->ipredmode[i][0]=-1;
// img->ipredmode[i][size_y-2]=-1;
// img->ipredmode[i][size_y-1]=-1;
img->ipredmode[i+1][0]=-1;
img->ipredmode[i+1][img->height/BLOCK_SIZE+1]=-1;
}
for (j=0; j < img->height/BLOCK_SIZE+1; j++)
{
// img->ipredmode[0][j]=-1;
// img->ipredmode[size_x-2][j]=-1;
// img->ipredmode[size_x-1][j]=-1;
img->ipredmode[0][j+1]=-1;
img->ipredmode[img->width/BLOCK_SIZE+1][j+1]=-1;
}
img->ipredmode[0][0]=-1;
if(input->InterlaceCodingOption >= MB_CODING)
{
for (i=0; i < img->width/BLOCK_SIZE+1; i++)
{
img->ipredmode_top[i+1][0]=-1;
img->ipredmode_top[i+1][img->height/BLOCK_SIZE+1]=-1;
img->ipredmode_bot[i+1][0]=-1;
img->ipredmode_bot[i+1][img->height/BLOCK_SIZE+1]=-1;
}
for (j=0; j < img->height/BLOCK_SIZE+1; j++)
{
img->ipredmode_top[0][j+1]=-1;
img->ipredmode_top[img->width/BLOCK_SIZE+1][j+1]=-1;
img->ipredmode_bot[0][j+1]=-1;
img->ipredmode_bot[img->width/BLOCK_SIZE+1][j+1]=-1;
}
img->ipredmode_top[0][0]=-1;
img->ipredmode_bot[0][0]=-1;
}
img->mb_y_upd=0;
RandomIntraInit (img->width/16, img->height/16, input->RandomIntraMBRefresh);
FmoInit (img->width/16, img->height/16, input->num_slice_groups_minus1, input->FmoType, NULL);
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->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);
free_mem_mv (img->abp_all_dmv);
if(input->InterlaceCodingOption >= MB_CODING)
{
free_mem_mv (img->abp_all_dmv_top);
free_mem_mv (img->abp_all_dmv_bot);
}
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -