📄 ldecod.c
字号:
currSlice->mot_ctx = create_contexts_MotionInfo();
currSlice->tex_ctx = create_contexts_TextureInfo();
}
currSlice->max_part_nr = 3; //! assume data partitioning (worst case) for the following mallocs()
currSlice->partArr = AllocPartition(currSlice->max_part_nr);
}
/*!
************************************************************************
* \brief
* Memory frees of the Slice structure and of its dependent
* data structures
*
* \par Input:
* Input Parameters struct inp_par *inp, struct img_par *img
************************************************************************
*/
void free_slice(struct inp_par *inp, struct img_par *img)
{
Slice *currSlice = img->currentSlice;
FreePartition (currSlice->partArr, 3);
// if (inp->symbol_mode == CABAC)
if (1)
{
// delete all context models
delete_contexts_MotionInfo(currSlice->mot_ctx);
delete_contexts_TextureInfo(currSlice->tex_ctx);
}
free(img->currentSlice);
currSlice = NULL;
}
/*!
************************************************************************
* \brief
* Dynamic memory allocation of frame size related global buffers
* buffers are defined in global.h, allocated memory must be freed in
* void free_global_buffers()
*
* \par Input:
* Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* \par Output:
* Number of allocated bytes
***********************************************************************
*/
int init_global_buffers(struct inp_par *inp, struct img_par *img)
{
int i,j;
int memory_size=0;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no_frm;
extern int *last_P_no_fld;
#endif
img->buf_cycle = inp->buf_cycle+1;
img->buf_cycle *= 2;
if (img->structure != FRAME)
{
img->height *= 2; // set height to frame (twice of field) for normal variables
img->height_cr *= 2; // set height to frame (twice of field) for normal variables
}
#ifdef _ADAPT_LAST_GROUP_
if ((last_P_no_frm = (int*)malloc(2*img->buf_cycle*sizeof(int))) == NULL)
no_mem_exit("get_mem4global_buffers: last_P_no_frm");
if ((last_P_no_fld = (int*)malloc(2*img->buf_cycle*sizeof(int))) == NULL)
no_mem_exit("get_mem4global_buffers: last_P_no_fld");
#endif
// allocate memory for encoding frame buffers: imgY, imgUV
// byte imgY[288][352];
// byte imgUV[2][144][176];
memory_size += get_mem2D(&imgY_frm, img->height, img->width); // processing memory in frame mode
memory_size += get_mem3D(&imgUV_frm, 2, img->height_cr, img->width_cr); // processing memory in frame mode
memory_size += get_mem2D(&imgY_top, img->height/2, img->width); // processing memory in field mode
memory_size += get_mem3D(&imgUV_top, 2, img->height_cr/2, img->width_cr); // processing memory in field mode
memory_size += get_mem2D(&imgY_bot, img->height/2, img->width); // processing memory in field mode
memory_size += get_mem3D(&imgUV_bot, 2, img->height_cr/2, img->width_cr); // processing memory in field mode
// allocate memory for multiple ref. frame buffers: mref, mcref
// rows and cols for croma component mcef[ref][croma][4x][4y] are switched
// compared to luma mref[ref][4y][4x] for whatever reason
// number of reference frames increased by one for next P-frame
alloc_mref(img);
// allocate memory for imgY_prev
memory_size += get_mem2D(&imgY_prev, img->height, img->width);
memory_size += get_mem3D(&imgUV_prev, 2, img->height_cr, img->width_cr);
// allocate memory for reference frames of each block: refFrArr
// int refFrArr[72][88];
memory_size += get_mem2Dint(&refFrArr_frm, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&refFrArr_top, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&refFrArr_bot, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
// allocate memory for collocated motion stationarity - int could be replaced with boolean
memory_size += get_mem2Dint(&moving_block_frm, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&moving_block_top, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&moving_block_bot, img->height/BLOCK_SIZE, img->width/BLOCK_SIZE);
// allocate memory for reference frame in find_snr
// byte imgY_ref[288][352];
// byte imgUV_ref[2][144][176];
memory_size += get_mem2D(&imgY_ref, img->height, img->width);
memory_size += get_mem3D(&imgUV_ref, 2, img->height_cr, img->width_cr);
// allocate memory in structure img
if(((img->mb_data) = (Macroblock *) calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL)
no_mem_exit("init_global_buffers: img->mb_data");
// if(img->UseConstrainedIntraPred)
if (1) // Always alloc the memory -- we don't know what the parset will tell us later
{
if(((img->intra_block) = (int**)calloc((j=(img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE)),sizeof(int))) == NULL)
no_mem_exit("init_global_buffers: img->intra_block");
for (i=0; i<j; i++)
{
if ((img->intra_block[i] = (int*)calloc(4, sizeof(int))) == NULL)
no_mem_exit ("init_global_buffers: img->intra_block");
}
}
// img => int mv[92][72][3]
memory_size += get_mem3Dint(&(img->mv_frm),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->mv_top),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->mv_bot),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// img => int ipredmode[90][74]
memory_size += get_mem2Dint(&(img->ipredmode),img->width/BLOCK_SIZE +2 , img->height/BLOCK_SIZE +2);
// int dfMV[92][72][3];
memory_size += get_mem3Dint(&(img->dfMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int dbMV[92][72][3];
memory_size += get_mem3Dint(&(img->dbMV),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int fw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->fw_refFrArr_frm),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int bw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->bw_refFrArr_frm),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int fw_mv[92][72][3];
memory_size += get_mem3Dint(&(img->fw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int bw_mv[92][72][3];
memory_size += get_mem3Dint(&(img->bw_mv),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
// int fw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->fw_refFrArr_top),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int bw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->bw_refFrArr_top),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int fw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->fw_refFrArr_bot),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
// int bw_refFrArr[72][88];
memory_size += get_mem2Dint(&(img->bw_refFrArr_bot),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&(img->ipredmode_frm),img->width/BLOCK_SIZE +2 , img->height/BLOCK_SIZE +2);
memory_size += get_mem2Dint(&(img->ipredmode_top),img->width/BLOCK_SIZE +2 , (img->height /2)/BLOCK_SIZE +2);
memory_size += get_mem2Dint(&(img->ipredmode_bot),img->width/BLOCK_SIZE +2 , (img->height /2)/BLOCK_SIZE +2);
memory_size += get_mem3Dint(&(img->fw_mv_frm),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->fw_mv_top),img->width/BLOCK_SIZE +4, (img->height/2)/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->fw_mv_bot),img->width/BLOCK_SIZE +4, (img->height/2)/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->bw_mv_frm),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->bw_mv_top),img->width/BLOCK_SIZE +4, (img->height/2)/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->bw_mv_bot),img->width/BLOCK_SIZE +4, (img->height/2)/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->dfMV_top),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->dbMV_top),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->dfMV_bot),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem3Dint(&(img->dbMV_bot),img->width/BLOCK_SIZE +4, img->height/BLOCK_SIZE,3);
memory_size += get_mem2Dint(&(img->field_anchor),img->height/BLOCK_SIZE,img->width/BLOCK_SIZE);
memory_size += get_mem2Dint(&(field_mb), img->height/MB_BLOCK_SIZE, img->width/MB_BLOCK_SIZE);
memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3);
memory_size += get_mem3Dint(&(img->wp_offset), 2, MAX_REFERENCE_PICTURES, 3);
memory_size += get_mem4Dint(&(img->wbp_weight), 2, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 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++)
{
memory_size += get_mem3Dint(&(img->nz_coeff[j]), img->height/MB_BLOCK_SIZE, 4, 6);
}
memory_size += get_mem2Dint(&(img->siblock),img->width/MB_BLOCK_SIZE , img->height/MB_BLOCK_SIZE);
if (img->structure != FRAME)
{
img->height /= 2; // reset height for normal variables
img->height_cr /= 2; // reset height for normal variables
}
img->buf_cycle = inp->buf_cycle+1;
return (memory_size);
}
/*!
************************************************************************
* \brief
* Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int init_global_buffers()
*
* \par Input:
* Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
*
* \par Output:
* none
*
************************************************************************
*/
void free_global_buffers(struct inp_par *inp, struct img_par *img)
{
int i,j;
#ifdef _ADAPT_LAST_GROUP_
extern int *last_P_no_frm;
extern int *last_P_no_fld;
free (last_P_no_frm);
free (last_P_no_fld);
#endif
free_mem2D(imgY_frm);
free_mem2D(imgY_top);
free_mem2D(imgY_bot);
free_mem3D(imgUV_frm,2);
free_mem3D(imgUV_top,2);
free_mem3D(imgUV_bot,2);
free_mem2D(imgY_prev);
free_mem3D(imgUV_prev,2);
// free multiple ref frame buffers
free (mref_frm);
free (mcef_frm);
free (mref_fld);
free (mcef_fld);
free (parity_fld);
free (chroma_vector_adjustment);
free_mem2Dint(refFrArr_frm);
free_mem2Dint(refFrArr_top);
free_mem2Dint(refFrArr_bot);
free_mem2Dint(moving_block_frm);
free_mem2Dint(moving_block_top);
free_mem2Dint(moving_block_bot);
free_mem2D (imgY_ref);
free_mem3D (imgUV_ref,2);
// free_mem2D (imgY_tmp);
// free_mem3D (imgUV_tmp,2);
// CAVLC free mem
for(j=0;j<img->width/MB_BLOCK_SIZE;j++)
{
free_mem3Dint(img->nz_coeff[j], img->height/MB_BLOCK_SIZE);
}
if (img->nz_coeff !=NULL) free(img->nz_coeff );
free_mem2Dint(img->siblock);
// free mem, allocated for structure img
if (img->mb_data != NULL) free(img->mb_data);
// if(img->UseConstrainedIntraPred)
if (1) // uncnonditionally allocated since introdiuction of par sets
{
j = (img->width/16)*(img->height/16);
for (i=0; i<j; i++)
{
free (img->intra_block[i]);
}
free (img->intra_block);
}
free_mem3Dint(img->mv_frm,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->mv_top,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->mv_bot,img->width/BLOCK_SIZE + 4);
free_mem2Dint (img->ipredmode);
free_mem3Dint(img->dfMV,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dbMV,img->width/BLOCK_SIZE + 4);
free_mem2Dint(img->fw_refFrArr_frm);
free_mem2Dint(img->bw_refFrArr_frm);
free_mem2Dint(img->fw_refFrArr_top);
free_mem2Dint(img->bw_refFrArr_top);
free_mem2Dint(img->fw_refFrArr_bot);
free_mem2Dint(img->bw_refFrArr_bot);
free_mem3Dint(img->fw_mv,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->bw_mv,img->width/BLOCK_SIZE + 4);
free_mem2Dint (img->ipredmode_frm);
free_mem2Dint (img->ipredmode_top);
free_mem2Dint (img->ipredmode_bot);
free_mem3Dint(img->fw_mv_frm,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->fw_mv_top,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->fw_mv_bot,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->bw_mv_frm,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->bw_mv_top,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->bw_mv_bot,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dfMV_top,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dbMV_top,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dfMV_bot,img->width/BLOCK_SIZE + 4);
free_mem3Dint(img->dbMV_bot,img->width/BLOCK_SIZE + 4);
free_mem2Dint(img->field_anchor);
free_mem2Dint(field_mb);
free_mem3Dint(img->wp_weight, 2);
free_mem3Dint(img->wp_offset, 2);
free_mem4Dint(img->wbp_weight, 2, MAX_REFERENCE_PICTURES);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -