📄 md_highfast.c
字号:
else // if (enc_mb.valid[P8x8])
{
tr4x4.mb_p8x8_cost = INT_MAX;
}
}
else // if (!intra)
{
min_cost = INT_MAX;
}
//========= C H O O S E B E S T M A C R O B L O C K M O D E =========
//-------------------------------------------------------------------------
{
// store_coding_state (currMB, cs_cm);
if (!inter_skip)
{
int mb_available_up;
int mb_available_left;
int mb_available_up_left;
if(img->type!=I_SLICE)
{
min_rdcost = RDCost16;
best_mode = mode16;
}
else
min_rdcost = max_rdcost;
// if Fast High mode, compute inter modes separate process for inter/intra
max_index = ((!intra && params->SelectiveIntraEnable ) ? 5 : 9);
if (((img->yuv_format != YUV400) && !IS_INDEPENDENT(params)) && max_index != 5)
{
// precompute all new chroma intra prediction modes
IntraChromaPrediction(currMB, &mb_available_up, &mb_available_left, &mb_available_up_left);
if (params->FastCrIntraDecision)
{
IntraChromaRDDecision(currMB, enc_mb);
min_chroma_pred_mode = (short) currMB->c_ipred_mode;
max_chroma_pred_mode = (short) currMB->c_ipred_mode;
}
else
{
min_chroma_pred_mode = DC_PRED_8;
max_chroma_pred_mode = PLANE_8;
}
}
else
{
min_chroma_pred_mode = DC_PRED_8;
max_chroma_pred_mode = DC_PRED_8;
}
for (currMB->c_ipred_mode=min_chroma_pred_mode; currMB->c_ipred_mode<=max_chroma_pred_mode; currMB->c_ipred_mode++)
{
// bypass if c_ipred_mode is not allowed
if ( (img->yuv_format != YUV400) &&
( ((!intra || !params->IntraDisableInterOnly) && params->ChromaIntraDisable == 1 && currMB->c_ipred_mode!=DC_PRED_8)
|| (currMB->c_ipred_mode == VERT_PRED_8 && !mb_available_up)
|| (currMB->c_ipred_mode == HOR_PRED_8 && !mb_available_left)
|| (currMB->c_ipred_mode == PLANE_8 && (!mb_available_left || !mb_available_up || !mb_available_up_left))))
continue;
//===== GET BEST MACROBLOCK MODE =====
for (ctr16x16=0, index=0; index < max_index; index++)
{
mode = mb_mode_table[index];
if (img->yuv_format != YUV400)
{
i16mode = 0;
// RDcost of mode 1 in P-slice and mode 0, 1 in B-slice are already available
if(((bslice && mode == 0) || (!islice && mode == 1)))
continue;
}
//--- for INTER16x16 check all prediction directions ---
if (mode==1 && bslice)
{
update_prediction_for_mode16x16(b8x8info, ctr16x16, &index);
ctr16x16++;
}
// Skip intra modes in inter slices if best mode is inter <P8x8 with cbp equal to 0
if (params->SkipIntraInInterSlices && !intra && mode >= I4MB && best_mode <=3 && currMB->cbp == 0)
continue;
// check if weights are in valid range for biprediction.
if (bslice && active_pps->weighted_bipred_idc == 1 && mode < P8x8)
{
int cur_blk, cur_comp;
int weight_sum;
Boolean invalid_mode = FALSE;
for (cur_blk = 0; cur_blk < 4; cur_blk ++)
{
if (b8x8info->best8x8pdir[mode][cur_blk] == 2)
{
for (cur_comp = 0; cur_comp < (active_sps->chroma_format_idc == YUV400 ? 1 : 3) ; cur_comp ++)
{
best8x8l0ref = (int) b8x8info->best8x8l0ref[mode][cur_blk];
best8x8l1ref = (int) b8x8info->best8x8l1ref[mode][cur_blk];
weight_sum = wbp_weight[0][best8x8l0ref][best8x8l1ref][cur_comp] + wbp_weight[1][best8x8l0ref][best8x8l1ref][cur_comp];
if (weight_sum < -128 || weight_sum > 127)
{
invalid_mode = TRUE;
break;
}
}
if (invalid_mode == TRUE)
break;
}
}
if (invalid_mode == TRUE)
continue;
}
if (enc_mb.valid[mode])
compute_mode_RD_cost(mode, currMB, &enc_mb, &min_rdcost, &min_dcost, &min_rate, i16mode, bslice, &inter_skip, is_cavlc);
}// for (ctr16x16=0, index=0; index<max_index; index++)
}// for (currMB->c_ipred_mode=DC_PRED_8; currMB->c_ipred_mode<=max_chroma_pred_mode; currMB->c_ipred_mode++)
// Selective Intra Coding
if(img->type!=I_SLICE && params->SelectiveIntraEnable && !IS_FREXT_PROFILE(params->ProfileIDC))
{
fast_mode_intra_decision(currMB, &intra_skip, min_rate);
if(!intra_skip)
{
// precompute all new chroma intra prediction modes
if ((img->yuv_format != YUV400) && !IS_INDEPENDENT(params))
{
// precompute all new chroma intra prediction modes
IntraChromaPrediction(currMB, &mb_available_up, &mb_available_left, &mb_available_up_left);
if (params->FastCrIntraDecision)
{
IntraChromaRDDecision(currMB, enc_mb);
min_chroma_pred_mode = currMB->c_ipred_mode;
max_chroma_pred_mode = currMB->c_ipred_mode;
}
else
{
min_chroma_pred_mode = DC_PRED_8;
max_chroma_pred_mode = PLANE_8;
}
}
else
{
min_chroma_pred_mode = DC_PRED_8;
max_chroma_pred_mode = DC_PRED_8;
}
max_index = 9;
for (currMB->c_ipred_mode=min_chroma_pred_mode; currMB->c_ipred_mode<=max_chroma_pred_mode; currMB->c_ipred_mode++)
{
// bypass if c_ipred_mode is not allowed
if ( (img->yuv_format != YUV400) &&
( ((!intra || !params->IntraDisableInterOnly) && params->ChromaIntraDisable == 1 && currMB->c_ipred_mode!=DC_PRED_8)
|| (currMB->c_ipred_mode == VERT_PRED_8 && !mb_available_up)
|| (currMB->c_ipred_mode == HOR_PRED_8 && !mb_available_left)
|| (currMB->c_ipred_mode == PLANE_8 && (!mb_available_left || !mb_available_up || !mb_available_up_left))))
continue;
//===== GET BEST MACROBLOCK MODE =====
for (index = 5; index < max_index; index++)
{
mode = mb_mode_table[index];
// Skip intra modes in inter slices if best mode is inter <P8x8 with cbp equal to 0
if (params->SkipIntraInInterSlices && !intra && mode >= I4MB && best_mode <=3 && currMB->cbp == 0)
continue;
if (img->yuv_format != YUV400)
{
i16mode = 0;
// RDcost of mode 1 in P-slice and mode 0, 1 in B-slice are already available
if(((bslice && mode == 0) || (!islice && mode == 1)))
continue;
}
if (enc_mb.valid[mode])
compute_mode_RD_cost(mode, currMB, &enc_mb, &min_rdcost, &min_dcost, &min_rate, i16mode, bslice, &inter_skip, is_cavlc);
} // for (index = 5; index < max_index; index++)
}
}
}
}
#ifdef BEST_NZ_COEFF
for (j=0;j<4;j++)
for (i=0; i<(4+img->num_blk8x8_uv); i++)
img->nz_coeff[img->current_mb_nr][j][i] = gaaiMBAFF_NZCoeff[j][i];
#endif
}
intra1 = IS_INTRA(currMB);
//===== S E T F I N A L M A C R O B L O C K P A R A M E T E R S ======
//---------------------------------------------------------------------------
update_qp_cbp_tmp(currMB, cbp, best_mode);
set_stored_macroblock_parameters (currMB);
// Rate control
if(params->RCEnable && params->RCUpdateMode <= MAX_RC_MODE)
rc_store_mad(currMB);
update_qp_cbp(currMB, best_mode);
rdopt->min_rdcost = min_rdcost;
rdopt->min_dcost = min_dcost;
if ( (img->MbaffFrameFlag)
&& (img->current_mb_nr%2)
&& (currMB->mb_type ? 0:((bslice) ? !currMB->cbp:1)) // bottom is skip
&& (prevMB->mb_type ? 0:((bslice) ? !prevMB->cbp:1))
&& !(field_flag_inference(currMB) == enc_mb.curr_mb_field)) // top is skip
{
rdopt->min_rdcost = 1e30; // don't allow coding of a MB pair as skip if wrong inference
}
//===== Decide if this MB will restrict the reference frames =====
if (params->RestrictRef)
update_refresh_map(intra, intra1, currMB);
if(params->SearchMode == UM_HEX)
{
UMHEX_skip_intrabk_SAD(best_mode, listXsize[enc_mb.list_offset[LIST_0]]);
}
else if(params->SearchMode == UM_HEX_SIMPLE)
{
smpUMHEX_skip_intrabk_SAD(best_mode, listXsize[enc_mb.list_offset[LIST_0]]);
}
//--- constrain intra prediction ---
if(params->UseConstrainedIntraPred && (img->type==P_SLICE || img->type==B_SLICE))
{
img->intra_block[img->current_mb_nr] = IS_INTRA(currMB);
}
}
/*!
*************************************************************************************
* \brief
* Fast intra decision
*************************************************************************************
*/
static void fast_mode_intra_decision(Macroblock *currMB, short *intra_skip, double min_rate)
{
int i;
int mb_available_up, mb_available_left, mb_available_up_left;
long SBE;
double AR = 0, ABE = 0;
PixelPos up; //!< pixel position p(0,-1)
PixelPos left[2]; //!< pixel positions p(-1, -1..0)
getNeighbour(currMB, 0 , -1 , img->mb_size[IS_LUMA], &up);
getNeighbour(currMB, -1 , -1 , img->mb_size[IS_LUMA], &left[0]);
getNeighbour(currMB, -1 , 0 , img->mb_size[IS_LUMA], &left[1]);
mb_available_up = up.available;
mb_available_up_left = left[0].available;
mb_available_left = left[1].available;
AR=(1.0/384)*min_rate;
SBE = 0;
if( (img->mb_y != (int)img->FrameHeightInMbs-1) && (img->mb_x != (int)img->PicWidthInMbs-1) && mb_available_left && mb_available_up)
{
for(i = 0; i < MB_BLOCK_SIZE; i++)
{
SBE += iabs(pCurImg[img->opix_y][img->opix_x+i] - enc_picture->imgY[img->pix_y-1][img->pix_x+i]);
SBE += iabs(pCurImg[img->opix_y+i][img->opix_x] - enc_picture->imgY[img->pix_y+i][img->pix_x-1]);
}
for(i = 0; i < 8; i++)
{
SBE += iabs(pImgOrg[1][img->opix_c_y][img->opix_c_x+i] - enc_picture->imgUV[0][img->pix_c_y-1][img->pix_c_x+i]);
SBE += iabs(pImgOrg[1][img->opix_c_y+i][img->opix_c_x] - enc_picture->imgUV[0][img->pix_c_y+i][img->pix_c_x-1]);
SBE += iabs(pImgOrg[2][img->opix_c_y][img->opix_c_x+i] - enc_picture->imgUV[1][img->pix_c_y-1][img->pix_c_x+i]);
SBE += iabs(pImgOrg[2][img->opix_c_y+i][img->opix_c_x] - enc_picture->imgUV[1][img->pix_c_y+i][img->pix_c_x-1]);
}
ABE = 1.0/64 * SBE;
}
else // Image boundary
{
ABE = 0;
}
if(AR <= ABE)
{
*intra_skip = 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -