Exemplo n.º 1
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate Q matrix arrays
 ***********************************************************************
 */
void allocate_QOffsets ()
{
  int max_qp_per_luma = (3 + 6*(input->BitDepthLuma) - MIN_QP)/6 + 1;
  int max_qp_per_cr = (3 + 6*(input->BitDepthChroma) - MIN_QP)/6 + 1;
  int max_qp_per = imax(max_qp_per_luma,max_qp_per_cr);
  get_mem4Dint(&LevelOffset4x4Luma,      2, max_qp_per, 4, 4);
  get_mem5Dint(&LevelOffset4x4Chroma, 2, 2, max_qp_per, 4, 4);
  get_mem4Dint(&LevelOffset8x8Luma,      2, max_qp_per, 8, 8);

  get_mem2Dshort(&OffsetList4x4input, 15, 16);
  get_mem2Dshort(&OffsetList8x8input,  5, 64);
  get_mem2Dshort(&OffsetList4x4, 15, 16);
  get_mem2Dshort(&OffsetList8x8,  5, 64);

}
Exemplo n.º 2
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate Q matrix arrays
 ***********************************************************************
 */
void allocate_QMatrix ()
{
  int bitdepth_qp_scale = 6*(input->BitDepthLuma - 8);
  int i;

  if ((qp_per_matrix = (int*)malloc((MAX_QP + 1 +  bitdepth_qp_scale)*sizeof(int))) == NULL)
    no_mem_exit("init_global_buffers: qp_per_matrix");
  if ((qp_rem_matrix = (int*)malloc((MAX_QP + 1 +  bitdepth_qp_scale)*sizeof(int))) == NULL)
    no_mem_exit("init_global_buffers: qp_per_matrix");

  for (i = 0; i < MAX_QP + bitdepth_qp_scale + 1; i++)
  {
    qp_per_matrix[i] = i / 6;
    qp_rem_matrix[i] = i % 6;
  }

  get_mem4Dint(&LevelScale4x4Luma,      2, 6, 4, 4);
  get_mem5Dint(&LevelScale4x4Chroma, 2, 2, 6, 4, 4);
  get_mem4Dint(&LevelScale8x8Luma,      2, 6, 8, 8);

  get_mem4Dint(&InvLevelScale4x4Luma,      2, 6, 4, 4);
  get_mem5Dint(&InvLevelScale4x4Chroma, 2, 2, 6, 4, 4);
  get_mem4Dint(&InvLevelScale8x8Luma,      2, 6, 8, 8);
}
Exemplo n.º 3
0
/*!
 ************************************************************************
 * \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);
}
Exemplo n.º 4
0
/*!
 ************************************************************************
 * \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);
}
Exemplo n.º 5
0
/*!
 ************************************************************************
 * \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);
}
Exemplo n.º 6
0
/*!
************************************************************************
* \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);
}