📄 lencod.c
字号:
{
img->offset_for_top_to_bottom_field = 0;
img->pic_order_present_flag = FALSE;
img->delta_pic_order_cnt_bottom = 0;
}
else
{
img->offset_for_top_to_bottom_field = 1;
img->pic_order_present_flag = TRUE;
img->delta_pic_order_cnt_bottom = 1;
}
}
/*!
***********************************************************************
* \brief
* Initializes the img->nz_coeff
* \par Input:
* none
* \par Output:
* none
* \ side effects
* sets omg->nz_coef[][][][] to -1
***********************************************************************
*/
void CAVLC_init(void)
{
unsigned int i, k, l;
for (i = 0; i < img->PicSizeInMbs; i++)
for (k = 0; k < 4; k++)
for (l = 0; l < (4 + (unsigned int)img->num_blk8x8_uv); l++)
img->nz_coeff[i][k][l] = 0;
}
/*!
***********************************************************************
* \brief
* Initializes the Image structure with appropriate parameters.
* \par Input:
* Input Parameters struct inp_par *inp
* \par Output:
* Image Parameters ImageParameters *img
***********************************************************************
*/
static void init_img( ImageParameters *img, InputParameters *params)
{
int i, j;
int byte_abs_range;
static int mb_width_cr[4] = {0,8, 8,16};
static int mb_height_cr[4]= {0,8,16,16};
// Color format
img->yuv_format = params->yuv_format;
img->P444_joined = (img->yuv_format == YUV444 && !IS_INDEPENDENT(params));
//pel bitdepth init
img->bitdepth_luma = params->output.bit_depth[0];
img->bitdepth_scale[0] = 1 << (img->bitdepth_luma - 8);
img->bitdepth_lambda_scale = 2 * (img->bitdepth_luma - 8);
img->bitdepth_luma_qp_scale = 3 * img->bitdepth_lambda_scale;
img->dc_pred_value_comp[0] = 1<<(img->bitdepth_luma - 1);
img->max_imgpel_value_comp[0] = (1<<img->bitdepth_luma) - 1;
img->max_imgpel_value_comp_sq[0] = img->max_imgpel_value_comp[0] * img->max_imgpel_value_comp[0];
img->dc_pred_value = img->dc_pred_value_comp[0]; // set defaults
img->max_imgpel_value = img->max_imgpel_value_comp[0];
img->mb_size[0][0] = img->mb_size[0][1] = MB_BLOCK_SIZE;
// Initialization for RC QP parameters (could be placed in ratectl.c)
img->RCMinQP = params->RCMinQP[P_SLICE];
img->RCMaxQP = params->RCMaxQP[P_SLICE];
// Set current residue & prediction array pointers
img->curr_res = img->mb_rres[0];
img->curr_prd = img->mb_pred[0];
if (img->yuv_format != YUV400)
{
img->bitdepth_chroma = params->output.bit_depth[1];
img->bitdepth_scale[1] = 1 << (img->bitdepth_chroma - 8);
img->dc_pred_value_comp[1] = 1<<(img->bitdepth_chroma - 1);
img->dc_pred_value_comp[2] = img->dc_pred_value_comp[1];
img->max_imgpel_value_comp[1] = (1<<img->bitdepth_chroma) - 1;
img->max_imgpel_value_comp[2] = img->max_imgpel_value_comp[1];
img->max_imgpel_value_comp_sq[1] = img->max_imgpel_value_comp[1] * img->max_imgpel_value_comp[1];
img->max_imgpel_value_comp_sq[2] = img->max_imgpel_value_comp[2] * img->max_imgpel_value_comp[2];
img->num_blk8x8_uv = (1<<img->yuv_format)&(~(0x1));
img->num_cdc_coeff = img->num_blk8x8_uv << 1;
img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = (img->yuv_format == YUV420 || img->yuv_format == YUV422) ? 8 : 16;
img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = (img->yuv_format == YUV444 || img->yuv_format == YUV422) ? 16 : 8;
img->bitdepth_chroma_qp_scale = 6*(img->bitdepth_chroma - 8);
img->chroma_qp_offset[0] = active_pps->cb_qp_index_offset;
img->chroma_qp_offset[1] = active_pps->cr_qp_index_offset;
}
else
{
img->bitdepth_chroma = 0;
img->bitdepth_scale[1] = 0;
img->max_imgpel_value_comp[1] = 0;
img->max_imgpel_value_comp[2] = img->max_imgpel_value_comp[1];
img->max_imgpel_value_comp_sq[1] = img->max_imgpel_value_comp[1] * img->max_imgpel_value_comp[1];
img->max_imgpel_value_comp_sq[2] = img->max_imgpel_value_comp[2] * img->max_imgpel_value_comp[2];
img->num_blk8x8_uv = 0;
img->num_cdc_coeff = 0;
img->mb_size[1][0] = img->mb_size[2][0] = img->mb_cr_size_x = 0;
img->mb_size[1][1] = img->mb_size[2][1] = img->mb_cr_size_y = 0;
img->bitdepth_chroma_qp_scale = 0;
img->bitdepth_chroma_qp_scale = 0;
img->chroma_qp_offset[0] = 0;
img->chroma_qp_offset[1] = 0;
}
//img->pic_unit_size_on_disk = (imax(img->bitdepth_luma , img->bitdepth_chroma) > 8) ? 16 : 8;
img->pic_unit_size_on_disk = (imax(params->source.bit_depth[0], params->source.bit_depth[1]) > 8) ? 16 : 8;
img->out_unit_size_on_disk = (imax(params->output.bit_depth[0], params->output.bit_depth[1]) > 8) ? 16 : 8;
img->max_bitCount = 128 + 256 * img->bitdepth_luma + 2 * img->mb_cr_size_y * img->mb_cr_size_x * img->bitdepth_chroma;
//img->max_bitCount = (128 + 256 * img->bitdepth_luma + 2 *img->mb_cr_size_y * img->mb_cr_size_x * img->bitdepth_chroma)*2;
img->max_qp_delta = (25 + (img->bitdepth_luma_qp_scale>>1));
img->min_qp_delta = img->max_qp_delta + 1;
img->num_ref_frames = active_sps->num_ref_frames;
img->max_num_references = active_sps->frame_mbs_only_flag ? active_sps->num_ref_frames : 2 * active_sps->num_ref_frames;
img->buf_cycle = params->num_ref_frames;
img->base_dist = params->jumpd;
// Intra/IDR related parameters
img->lastIntraNumber = 0;
img->lastINTRA = 0;
img->lastIDRnumber = 0;
img->last_ref_idc = 0;
img->idr_refresh = 0;
img->idr_gop_number = 0;
img->rewind_frame = 0;
img->DeblockCall = 0;
img->framerate = (float) params->FrameRate; // The basic frame rate (of the original sequence)
// Allocate proper memory space for different parameters (i.e. MVs, coefficients, etc)
if (!params->IntraProfile)
{
get_mem_mv (&(img->pred_mv));
get_mem_mv (&(img->all_mv));
if (params->BiPredMotionEstimation)
{
get_mem_bipred_mv(&(img->bipred_mv));
}
}
get_mem_ACcoeff (&(img->cofAC));
get_mem_DCcoeff (&(img->cofDC));
if (params->AdaptiveRounding)
{
get_mem3Dint(&(img->fadjust4x4), 4, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
get_mem3Dint(&(img->fadjust8x8), 3, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
if (img->yuv_format != 0)
{
get_mem4Dint(&(img->fadjust4x4Cr), 2, 4, img->mb_cr_size_y, img->mb_cr_size_x);
get_mem4Dint(&(img->fadjust8x8Cr), 2, 3, img->mb_cr_size_y, img->mb_cr_size_x);
}
}
if(params->MbInterlace)
{
if (!params->IntraProfile)
{
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_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));
if ( params->MbInterlace != FRAME_MB_PAIR_CODING )
{
if (!params->IntraProfile)
{
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_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 (params->UseRDOQuant && params->RDOQ_QP_Num > 1)
{
get_mem_ACcoeff (&(rddata_trellis_curr.cofAC));
get_mem_DCcoeff (&(rddata_trellis_curr.cofDC));
get_mem_ACcoeff (&(rddata_trellis_best.cofAC));
get_mem_DCcoeff (&(rddata_trellis_best.cofDC));
if (!params->IntraProfile)
{
get_mem_mv (&(rddata_trellis_curr.pred_mv));
get_mem_mv (&(rddata_trellis_curr.all_mv));
get_mem_mv (&(rddata_trellis_best.pred_mv));
get_mem_mv (&(rddata_trellis_best.all_mv));
if (params->Transform8x8Mode && params->RDOQ_CP_MV)
{
get_mem5Dshort(&tmp_mv8, 2, img->max_num_references, 4, 4, 2);
get_mem5Dshort(&tmp_pmv8, 2, img->max_num_references, 4, 4, 2);
get_mem3Dint (&motion_cost8, 2, img->max_num_references, 4);
}
}
}
byte_abs_range = (imax(img->max_imgpel_value_comp[0], img->max_imgpel_value_comp[1]) + 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 = (params->output.width + img->auto_crop_right);
img->height = (params->output.height + img->auto_crop_bottom);
img->width_blk = img->width / BLOCK_SIZE;
img->height_blk = img->height / BLOCK_SIZE;
img->width_padded = img->width + 2 * IMG_PAD_SIZE;
img->height_padded = img->height + 2 * IMG_PAD_SIZE;
if (img->yuv_format != YUV400)
{
img->width_cr = img->width * mb_width_cr [img->yuv_format] / 16;
img->height_cr= img->height * mb_height_cr[img->yuv_format] / 16;
}
else
{
img->width_cr = 0;
img->height_cr= 0;
}
img->height_cr_frame = img->height_cr;
img->size = img->width * img->height;
img->size_cr = img->width_cr * img->height_cr;
img->PicWidthInMbs = img->width / MB_BLOCK_SIZE;
img->FrameHeightInMbs = img->height / MB_BLOCK_SIZE;
img->FrameSizeInMbs = img->PicWidthInMbs * img->FrameHeightInMbs;
img->PicHeightInMapUnits = ( active_sps->frame_mbs_only_flag ? img->FrameHeightInMbs : img->FrameHeightInMbs/2 );
if ((img->b8x8info = (Block8x8Info *) calloc(1, sizeof(Block8x8Info))) == NULL)
no_mem_exit("init_img: img->block8x8info");
if( IS_INDEPENDENT(params) )
{
for( i = 0; i < MAX_PLANE; i++ ){
if ((img->mb_data_JV[i] = (Macroblock *) calloc(img->FrameSizeInMbs,sizeof(Macroblock))) == NULL)
no_mem_exit("init_img: img->mb_data_JV");
}
img->mb_data = NULL;
}
else
{
if ((img->mb_data = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
no_mem_exit("init_img: img->mb_data");
}
if (params->UseConstrainedIntraPred)
{
if ((img->intra_block = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL)
no_mem_exit("init_img: img->intra_block");
}
if (params->CtxAdptLagrangeMult == 1)
{
if ((mb16x16_cost_frame = (double*)calloc(img->FrameSizeInMbs, sizeof(double))) == NULL)
{
no_mem_exit("init mb16x16_cost_frame");
}
}
get_mem2D((byte***)&(img->ipredmode), img->height_blk, img->width_blk); //need two extra rows at right and bottom
get_mem2D((byte***)&(img->ipredmode8x8), img->height_blk, img->width_blk); // help storage for ipredmode 8x8, inserted by YV
memset(&(img->ipredmode[0][0]) , -1, img->height_blk * img->width_blk *sizeof(char));
memset(&(img->ipredmode8x8[0][0]), -1, img->height_blk * img->width_blk *sizeof(char));
get_mem2D((byte***)&(rddata_top_frame_mb.ipredmode), img->height_blk, img->width_blk);
get_mem2D((byte***)&(rddata_trellis_curr.ipredmode), img->height_blk, img->width_blk);
get_mem2D((byte***)&(rddata_trellis_best.ipredmode), img->height_blk, img->width_blk);
if (params->MbInterlace)
{
get_mem2D((byte***)&(rddata_bot_frame_mb.ipredmode), img->height_blk, img->width_blk);
get_mem2D((byte***)&(rddata_top_field_mb.ipredmode), img->height_blk, img->width_blk);
get_mem2D((byte***)&(rddata_bot_field_mb.ipredmode), img->height_blk, img->width_blk);
}
// CAVLC mem
get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 4+img->num_blk8x8_uv);
CAVLC_init();
get_mem2Dolm (&(img->lambda), 10, 52 + img->bitdepth_luma_qp_scale, img->bitdepth_luma_qp_scale);
get_mem2Dodouble (&(img->lambda_md), 10, 52 + img->bitdepth_luma_qp_scale, img->bitdepth_luma_qp_scale);
get_mem3Dodouble (&(img->lambda_me), 10, 52 + img->bitdepth_luma_qp_scale, 3, img->bitdepth_luma_qp_scale);
get_mem3Doint (&(img->lambda_mf), 10, 52 + img->bitdepth_luma_qp_scale, 3, img->bitdepth_luma_qp_scale);
if (params->CtxAdptLagrangeMult == 1)
{
get_mem2Dodouble(&(img->lambda_mf_factor), 10, 52 + img->bitdepth_luma_qp_scale, img->bitdepth_luma_qp_scale);
}
img->b_frame_to_code = 0;
img->GopLevels = (params->successive_Bframe) ? 1 : 0;
img->mb_y_upd=0;
RandomIntraInit (img->PicWidthInMbs, img->FrameHeightInMbs, params->RandomIntraMBRefresh);
InitSEIMessages();
initInput(¶ms->source, ¶ms->output);
// Allocate I/O Frame memory
if (AllocateFrameMemory(img, params->source.size))
no_mem_exit("AllocateFrameMemory: buf");
// 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 (params->DFSendParameters)
{
for (j = 0; j < 2; j++)
{
for (i = 0; i < NUM_SLICE_TYPES; i++)
{
params->DFAlpha[j][i] <<= 1;
params->DFBeta [j][i] <<= 1;
}
}
}
else
{
for (j = 0; j < 2; j++)
{
for (i = 0; i < NUM_SLICE_TYPES; i++)
{
params->DFDisableIdc[j][i] = 0;
params->DFAlpha [j][i] = 0;
params->DFBeta [j][i] = 0;
}
}
}
img->ChromaArrayType = params->separate_colour_plane_flag ? 0 : params->yuv_format;
if (params->RDPictureDecision)
img->frm_iter = 3;
else
img->frm_iter = 1;
}
/*!
***********************************************************************
* \brief
* Free the Image structures
* \par Input:
* Image Parameters ImageParameters *img
***********************************************************************
*/
void free_img ()
{
// Delete Frame memory
DeleteFrameMemory();
CloseSEIMessages();
if (!params->IntraProfile)
{
free_mem_mv (img->pred_mv);
free_mem_mv (img->all_mv);
if (params->BiPredMotionEstimation)
{
free_mem_bipred_mv (img->bipred_mv);
}
}
free_mem_ACcoeff (img->cofAC);
free_mem_DCcoeff (img->cofDC);
if (params->AdaptiveRounding)
{
free_mem3Dint(img->fadjust4x4);
free_mem3Dint(img->fadjust8x8);
if (img->yuv_format != 0)
{
free_mem4Dint(img->fadjust4x4Cr);
free_mem4Dint(img->fadjust8x8Cr);
}
}
if (params->MbInterlace)
{
if (!params->IntraProfile)
{
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_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);
if ( params->MbInterlace != FRAME_MB_PAIR_CODING )
{
if (!params->IntraProfile)
{
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_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 (params->UseRDOQuant && params->RDOQ_QP_Num > 1)
{
free_mem_ACcoeff (rddata_trellis_curr.cofAC);
free_mem_DCcoeff (rddata_trellis_curr.cofDC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -