/*! ************************************************************************************** * \brief * Allocate memory for error resilient RDO. ************************************************************************************** */ int allocate_errdo_mem(VideoParameters *p_Vid, InputParameters *p_Inp) { int memory_size = 0; //allocate shared memory for all algorithms p_Vid->p_decs = (Decoders *) malloc(sizeof(Decoders)); memory_size += get_mem3Dint(&p_Vid->p_decs->res_img, MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); memory_size += get_mem3Dint(&p_Vid->p_decs->res_mb_best8x8, MAX_PLANE, MB_BLOCK_SIZE, MB_BLOCK_SIZE); p_Vid->p_decs->RCD_bestY_mb = NULL; p_Vid->p_decs->RCD_bestY_b8x8 = NULL; p_Vid->p_decs->MVCD_bestY_mb = NULL; p_Vid->p_decs->MVCD_bestY_b8x8 = NULL; p_Vid->p_decs->flag_bestY_mb = NULL; p_Vid->p_decs->flag_bestY_b8x8 = NULL; p_Vid->p_decs->flag_wo_res = NULL; p_Vid->p_decs->flag_wo_res_bestY_b8x8 = NULL; p_Vid->p_decs->trans_dist_bestY_mb = NULL; p_Vid->p_decs->trans_dist_bestY_b8x8 = NULL; p_Vid->p_decs->trans_dist_wo_res = NULL; //it is used for P8x8, where residual may be set to 0 p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8 = NULL; //it is used for P8x8, where residual may be set to 0 p_Vid->p_decs->trans_err_bestY_mb = NULL; p_Vid->p_decs->trans_err_bestY_b8x8 = NULL; p_Vid->p_decs->trans_err_wo_res = NULL; //it is used for P8x8, where residual may be set to 0 p_Vid->p_decs->trans_err_wo_res_bestY_b8x8 = NULL; //it is used for P8x8, where residual may be set to 0 p_Vid->p_decs->dec_mb_pred = NULL; p_Vid->p_decs->dec_mbY_best = NULL; p_Vid->p_decs->dec_mb_pred_best8x8 = NULL; p_Vid->p_decs->dec_mbY_best8x8 = NULL; p_Vid->p_decs->first_moment_bestY_mb = NULL; p_Vid->p_decs->first_moment_bestY_b8x8 = NULL; p_Vid->p_decs->first_moment_pred_bestY_b8x8 = NULL; p_Vid->p_decs->first_moment_pred = NULL; p_Vid->p_decs->second_moment_bestY_mb = NULL; p_Vid->p_decs->second_moment_bestY_b8x8 = NULL; p_Vid->p_decs->second_moment_pred_bestY_b8x8 = NULL; p_Vid->p_decs->second_moment_pred = NULL; //Zhifeng 090630 switch (p_Inp->de) { case LLN: //allocate memory for lln algorithm memory_size += get_mem3Dpel(&p_Vid->p_decs->dec_mb_pred, p_Inp->NoOfDecoders, MB_BLOCK_SIZE, MB_BLOCK_SIZE); memory_size += get_mem3Dpel(&p_Vid->p_decs->dec_mbY_best, p_Inp->NoOfDecoders, MB_BLOCK_SIZE, MB_BLOCK_SIZE); memory_size += get_mem4Dpel(&p_Vid->p_decs->dec_mbY_best8x8, 2, p_Inp->NoOfDecoders, MB_BLOCK_SIZE, MB_BLOCK_SIZE); memory_size += get_mem4Dpel(&p_Vid->p_decs->dec_mb_pred_best8x8, 2, p_Inp->NoOfDecoders, MB_BLOCK_SIZE, MB_BLOCK_SIZE); break; default: ; } return memory_size; }
// same change as in get_mem2Dint int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns ) { int j; if(((*array4D) = (int****)calloc(idx,sizeof(int**))) == NULL) no_mem_exit("get_mem4Dint: array4D"); for(j=0;j<idx;j++) get_mem3Dint( (*array4D)+j, frames, rows, columns ) ; return idx*frames*rows*columns*sizeof(int); }
/*! ************************************************************************ * \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() { int memory_size=0; if (global_init_done) { free_global_buffers(); } // allocate memory for reference frame in find_snr 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->FrameSizeInMbs, sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: img->mb_data"); if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode), 4*img->PicWidthInMbs , 4*img->FrameHeightInMbs); memory_size += get_mem2Dint(&(img->field_anchor),4*img->FrameHeightInMbs, 4*img->PicWidthInMbs); memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 6); memory_size += get_mem2Dint(&(img->siblock),img->PicWidthInMbs , img->FrameHeightInMbs); global_init_done = 1; img->oldFrameSizeInMbs = img->FrameSizeInMbs; return (memory_size); }
// same change as in get_mem2Dint int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns) { int j; if(((*array4D) = (int****) h264_malloc(idx*sizeof(int**))) == NULL) { printf("get_mem4Dint: array4D"); exit(0); } for(j=0;j<idx;j++) { get_mem3Dint( (*array4D)+j, frames, rows, columns) ; } return idx*frames*rows*columns*sizeof(int); }
/*! ************************************************************************ * \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 *----------------------------------------------------------------------- * Function Argument List Changed [Removing Global Variables] * Input parameters added are * - h264_decoder* dec_params * * <*****@*****.**> *********************************************************************** */ int init_global_buffers_baseline( h264_decoder* dec_params ) { ImageParameters* img = dec_params->img; int memory_size=0; int quad_range, i; if (dec_params->global_init_done) { free_global_buffers_baseline( dec_params ); } if(((img->slice_nr) = (char *) h264_malloc(img->FrameSizeInMbs * sizeof(char))) == NULL) { printf("init_global_buffers: img->slice_nr"); exit(0); } if(((img->ei_flag) = (char *) h264_malloc(img->FrameSizeInMbs * sizeof(char))) == NULL) { printf("init_global_buffers: img->ei_flag"); exit(0); } /////////////////////////////////////////////////////////////////////////////////// // Initializations for the new mb_data structure inside the ImageParam structure // /////////////////////////////////////////////////////////////////////////////////// if((img->mb_data1.cbp_blk = (short*) h264_malloc(img->FrameSizeInMbs*sizeof(short))) == NULL) { printf("init_global_buffers: img->mb_data1->cbp_blk"); exit(0); } if((img->mb_data1.LFAlphaC0Offset = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.LFAlphaC0Offset"); exit(0); } if((img->mb_data1.LFBetaOffset = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.LFBetaC0Offset"); exit(0); } if((img->mb_data1.LFDisableIdc = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.LFDisableIdc"); exit(0); } if((img->mb_data1.mb_type = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.mb_type"); exit(0); } if((img->mb_data1.partition = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.partition"); exit(0); } if((img->mb_data1.mbAvailA = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.mbAvailA"); exit(0); } if((img->mb_data1.mbAvailB = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.mbAvailB"); exit(0); } if((img->mb_data1.NoMbPartLessThan8x8Flag = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.NoMbPartLessThan8x8Flag"); exit(0); } if((img->mb_data1.qp = (char*) h264_malloc(img->FrameSizeInMbs*sizeof(char))) == NULL) { printf("init_global_buffers: img->mb_data1.qp"); exit(0); } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// if(((dec_params->img->intra_block) = (int*)h264_malloc(dec_params->img->FrameSizeInMbs * sizeof(int))) == NULL) { printf("init_global_buffers: img->intra_block"); exit(0); } memory_size += get_mem2D(&(dec_params->img->ipredmode), dec_params->img->FrameWidthInMbs<<2 , dec_params->img->FrameHeightInMbs<<2); memory_size += get_mem3Dint(&(dec_params->img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(dec_params->img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(dec_params->img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); // dec_params->img->nz_coeff = h264_malloc ((dec_params->img->FrameSizeInMbs<<5)*sizeof(char)); dec_params->img->nz_coeff1 = (char *)h264_malloc ((dec_params->img->FrameSizeInMbs*24)*sizeof(char)); // dec_params->img->nz_coeff1[1] = dec_params->img->nz_coeff1[0] + dec_params->img->FrameSizeInMbs*16; // dec_params->img->nz_coeff1[2] = dec_params->img->nz_coeff1[1] + dec_params->img->FrameSizeInMbs*4; memory_size += (dec_params->img->FrameSizeInMbs<<5)*sizeof(char); quad_range = (MAX_IMGPEL_VALUE + 1) <<1; //if ((dec_params->img->quad = (int*)calloc (quad_range, sizeof(int))) == NULL) /* if ((dec_params->img->quad = (int*) h264_malloc (quad_range * sizeof(int))) == NULL) { printf("init_img: img->quad"); exit(0); } for (i=0; i < quad_range>>1; ++i) { dec_params->img->quad[i]=i*i; } */ // create all context models dec_params->mot_ctx = (MotionInfoContexts *)create_contexts_MotionInfo(); dec_params->tex_ctx = (TextureInfoContexts *)create_contexts_TextureInfo(); dec_params->global_init_done = 1; // dec_params->img->oldFrameSizeInMbs = dec_params->img->FrameSizeInMbs; return (memory_size); }
/*! ************************************************************************ * \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 memory_size=0; if (global_init_done) { free_global_buffers(inp, img); } 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 } // allocate memory for reference frame in find_snr 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 #ifndef STATIC_ALLOC 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->intra_block) = (int*)calloc((img->width/MB_BLOCK_SIZE) * (img->height/MB_BLOCK_SIZE),sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode),img->width/BLOCK_SIZE , img->height/BLOCK_SIZE); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 6); memory_size += get_mem2Dint(&(img->siblock),img->width/MB_BLOCK_SIZE , img->height/MB_BLOCK_SIZE); #else // ipredmode memory_size += (1920/BLOCK_SIZE) * (1088/BLOCK_SIZE) * sizeof(int); // CAVLC mem // nz_coeff memory_size += (1920/MB_BLOCK_SIZE) * (1088/MB_BLOCK_SIZE) * 4 * 6 * sizeof(int); // siblock memory_size += (176/MB_BLOCK_SIZE) * (144/MB_BLOCK_SIZE) * sizeof(int); #endif memory_size += get_mem2Dint(&(img->field_anchor),img->height/BLOCK_SIZE,img->width/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); if (img->structure != FRAME) { img->height /= 2; // reset height for normal variables img->height_cr /= 2; // reset height for normal variables } global_init_done = 1; return (memory_size); }
/*! ************************************************************************ * \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() { int memory_size=0; int quad_range, i; if (global_init_done) { free_global_buffers(); } // allocate memory for reference frame in find_snr memory_size += get_mem2Dpel(&imgY_ref, img->height, img->width); if (active_sps->chroma_format_idc != YUV400) memory_size += get_mem3Dpel(&imgUV_ref, 2, img->height_cr, img->width_cr); else imgUV_ref=NULL; // allocate memory in structure img if(((img->mb_data) = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL) no_mem_exit("init_global_buffers: img->mb_data"); if(((img->intra_block) = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL) no_mem_exit("init_global_buffers: img->intra_block"); memory_size += get_mem2Dint(&(img->ipredmode), 4*img->PicWidthInMbs , 4*img->FrameHeightInMbs); memory_size += get_mem2Dint(&(img->field_anchor),4*img->FrameHeightInMbs, 4*img->PicWidthInMbs); memory_size += get_mem3Dint(&(img->wp_weight), 2, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem3Dint(&(img->wp_offset), 6, MAX_REFERENCE_PICTURES, 3); memory_size += get_mem4Dint(&(img->wbp_weight), 6, MAX_REFERENCE_PICTURES, MAX_REFERENCE_PICTURES, 3); // CAVLC mem memory_size += get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 4 + img->num_blk8x8_uv); memory_size += get_mem2Dint(&(img->siblock),img->PicWidthInMbs , img->FrameHeightInMbs); if(img->max_imgpel_value > img->max_imgpel_value_uv || active_sps->chroma_format_idc == YUV400) quad_range = (img->max_imgpel_value + 1) * 2; else quad_range = (img->max_imgpel_value_uv + 1) * 2; if ((img->quad = (int*)calloc (quad_range, sizeof(int))) == NULL) no_mem_exit ("init_img: img->quad"); for (i=0; i < quad_range/2; ++i) { img->quad[i]=i*i; } #ifdef ADAPTIVE_FILTER memory_size += get_mem2Ddouble (&tmp_coef, 21, 16); #endif #ifdef ADAPTIVE_LOOP_FILTER memory_size += InitALFGlobalBuffers(); #endif global_init_done = 1; img->oldFrameSizeInMbs = img->FrameSizeInMbs; return (memory_size); }