1.定义posi_proc
void c_posi::posi_proc(param_t param_input, prei_t prei_out, posi_t & posi_out, c_fetch u_fetch)
{
if(prei_out.x==0 && prei_out.y==0 && param_input.frame_num == 0)
init();
load(param_input, prei_out);
fetch(u_fetch);
run();
dump();
update(posi_out);
}
2.定义init
void c_posi::init()
{
if (param.dump_mode_posi == 0)
;
else if (param.dump_mode_posi == 1)
init_hw_sim_dump();
else if (param.dump_mode_posi == 2)
init_hm_cc_dump();
else if (param.dump_mode_posi == 3)
init_debug_dump();
#ifdef DUMP_DEBUG_posi
init_dump_debug()
#endif
#ifdef DUMP_DATA_posi
init_data();
#endif
#ifdef DUMP_HWSIM_posi
init_hwsim();
#endif
}
3.定义load
void c_posi::load(param_t param_input, prei_t prei_out)
{
param = param_input;
posi_input = prei_out;
luma_64x64_mode = posi_input.luma_64x64_mode;
memcpy(luma_32x32_mode, posi_input.luma_32x32_mode, sizeof(posi_input.luma_32x32_mode));
memcpy(luma_16x16_mode, posi_input.luma_16x16_mode, sizeof(posi_input.luma_16x16_mode));
memcpy(luma_8x8_mode, posi_input.luma_8x8_mode, sizeof(posi_input.luma_8x8_mode));
memcpy(luma_4x4_mode, posi_input.luma_4x4_mode, sizeof(posi_input.luma_4x4_mode));
if (param.frame_num == 0 && posi_input.x == 0 && posi_input.y == 0)
{
pixel_line_org = new PIXEL[param.frame_mb_x_total * f_LCU_SIZE];
pixel_line = new PIXEL[param.frame_mb_x_total * f_LCU_SIZE];
pixel_line_u = new PIXEL[param.frame_mb_x_total * f_LCU_SIZE / 2];
pixel_line_v = new PIXEL[param.frame_mb_x_total * f_LCU_SIZE / 2];
}
if (posi_input.x > 0) {
for (int i = 1; i < f_LCU_SIZE + 1; i++) {
forg[i][0] = forg[i][f_LCU_SIZE];
frec[i][0] = frec[i][f_LCU_SIZE];
frec_u[(i + 1) / 2][0] = frec_u[(i + 1) / 2][f_LCU_SIZE / 2];
frec_v[(i + 1) / 2][0] = frec_v[(i + 1) / 2][f_LCU_SIZE / 2];
}
}
if (posi_input.y > 0) {
for (int i = 0; i < f_LCU_SIZE; i++) {
forg[0][i + 1] = pixel_line_org[posi_input.x * f_LCU_SIZE + i];
frec[0][i + 1] = pixel_line[posi_input.x * f_LCU_SIZE + i];
frec_u[0][i / 2 + 1] = pixel_line_u[posi_input.x * f_LCU_SIZE / 2 + i / 2];
frec_v[0][i / 2 + 1] = pixel_line_v[posi_input.x * f_LCU_SIZE / 2 + i / 2];
}
}
if (posi_input.y > 0 && posi_input.x > 0) {
forg[0][0] = pixel_topleft_org;
frec[0][0] = pixel_topleft;
frec_u[0][0] = pixel_topleft_u;
frec_v[0][0] = pixel_topleft_v;
}
if (posi_input.y > 0 && posi_input.x < param.frame_mb_x_total - 1) {
for (int i = 0; i < 32; i++) {
forg[0][f_LCU_SIZE + i + 1] = pixel_line_org[(posi_input.x + 1) * f_LCU_SIZE + i];
frec[0][f_LCU_SIZE + i + 1] = pixel_line[(posi_input.x + 1) * f_LCU_SIZE + i];
frec_u[0][f_LCU_SIZE / 2 + i / 2 + 1] = pixel_line_u[(posi_input.x + 1) * f_LCU_SIZE / 2 + i / 2];
frec_v[0][f_LCU_SIZE / 2 + i / 2 + 1] = pixel_line_v[(posi_input.x + 1) * f_LCU_SIZE / 2 + i / 2];
}
}
QP = posi_input.qp;
if (QP >= 30 && QP <= 43)
QPC = posi_QPC_TABLE[QP - 30];
else if (QP < 30)
QPC = QP;
else
QPC = QP - 6;
isXBoundry = (posi_input.x == param.frame_width / f_LCU_SIZE) && (param.frame_width % f_LCU_SIZE != 0);
isYBoundry = (posi_input.y == param.frame_height / f_LCU_SIZE) && (param.frame_height % f_LCU_SIZE != 0);
x_Boundry = param.frame_width % f_LCU_SIZE + (param.frame_width % f_LCU_SIZE == 0) * f_LCU_SIZE;
y_Boundry = param.frame_height % f_LCU_SIZE + (param.frame_height % f_LCU_SIZE == 0) * f_LCU_SIZE;
x_range = isXBoundry ? x_Boundry : f_LCU_SIZE;
y_range = isYBoundry ? y_Boundry : f_LCU_SIZE;
if (param.run_mode_posi == NOT_RUN) {
if (param.log_level >= 5)
cout << "# POSI[LOAD] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: NO" << endl;
} else if (param.run_mode_posi == PIPELINE_MODE) {
if (param.log_level >= 5)
cout << "# POSI[LOAD] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: PP" << endl;
} else if (param.run_mode_posi == CROSS_CHECK_MODE) {
if (param.log_level >= 5)
cout << "# POSI[LOAD] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: CC" << endl;
load_from_file();
} else {
if (param.log_level >= 5)
cout << "# POSI[LOAD] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: ERROR" << endl;
}
}
void c_posi::fetch(c_fetch u_fetch)
{
info_output.x = posi_input.x;
info_output.y = posi_input.y;
fetch_data = u_fetch.fetch_mb_proc(param, info_output);
for (int j = 0; j < f_LCU_SIZE; j++)
for (int i = 0; i < f_LCU_SIZE; i++) {
forg[i + 1][j + 1] = fetch_data.cur_mb.luma[i][j];
fenc[i][j] = fetch_data.cur_mb.luma[i][j];
}
for (int j = 0; j < f_LCU_SIZE / 2; j++)
for (int i = 0; i < f_LCU_SIZE / 2; i++) {
fenc_u[j][i] = fetch_data.cur_mb.cb[j][i];
fenc_v[j][i] = fetch_data.cur_mb.cr[j][i];
}
if (param.run_mode_posi == 0) {
if (param.log_level >= 5)
cout << "# POSI[FETCH] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: NO" << endl;
for (int j = 0; j < f_LCU_SIZE + 33; j++)
for (int i = 0; i < f_LCU_SIZE + 33; i++)
forg[i][j] = 0;
for (int j = 0; j < f_LCU_SIZE; j++)
for (int i = 0; i < f_LCU_SIZE; i++)
fenc[i][j] = 0;
for (int j = 0; j < f_LCU_SIZE / 2; j++)
for (int i = 0; i < f_LCU_SIZE / 2; i++) {
fenc_u[i][j] = 0;
fenc_v[i][j] = 0;
}
} else if (param.run_mode_posi == 1) {
if (param.log_level >= 5)
cout << "# POSI[FETCH] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: PP" << endl;
} else if (param.run_mode_posi == 2) {
if (param.log_level >= 5)
cout << "# POSI[FETCH] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: CC" << endl;
fetch_from_file();
} else {
if (param.log_level >= 5)
cout << "# POSI[FETCH] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: ERROR" << endl;
}
}
4.定义run
void c_posi::run()
{
if (param.run_mode_posi == NOT_RUN) {
if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: NO" << endl;
luma_64x64_mode = 1;
for (int i = 0; i < 4; i++)
luma_32x32_mode[i] = 1;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
luma_16x16_mode[i][j] = 1;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
for (int k = 0; k < 4; k++)
luma_8x8_mode[i][j][k] = 1;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
for (int k = 0; k < 4; k++)
for (int l = 0; l < 4; l++)
luma_4x4_mode[i][j][k][l] = 1;
} else if (param.run_method_posi == POSI_PRED_REC) {
if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: POSI_PRED_REC" << endl;
pred_rec();
} else if (param.run_method_posi == POSI_PRED_ORG) {
if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: POSI_PRED_ORG" << endl;
pred_org();
} else if (param.run_method_posi == POSI_PRED_ORG_NO_PREI) {
if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: POSI_PRED_ORG_NO_PREI" << endl;
posi_pred_org_no_prei();
} else if (param.run_method_posi == POSI_PRED_SATD_ORG) {
if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " Mode: POSI_PRED_SATD_ORG" << endl;
posi_pred_satd_org();
} else if (param.log_level >= 5)
cout << "# POSI[RUN] CTU[" << posi_input.x << "," << posi_input.y << "]"
<< " ERROR: Wrong Run Method" << endl;
}
5.定义dump
void c_posi::dump()
{
if (param.dump_mode_posi == 0)
;
else if (param.dump_mode_posi == 1)
posi_hw_sim_dump();
else if (param.dump_mode_posi == 2)
posi_hm_cc_dump();
else if (param.dump_mode_posi == 3)
posi_debug_dump();
}
6.定义update
void c_posi::update(posi_t &posi_out)
{
posi_output.name = "posi";
posi_output.x = posi_input.x;
posi_output.y = posi_input.y;
posi_output.qp = posi_input.qp;
posi_output.mb_type = INTRA_TYPE;
posi_output.luma_64x64_mode = luma_64x64_mode;
memcpy(posi_output.luma_32x32_mode, luma_32x32_mode, sizeof(posi_output.luma_32x32_mode));
memcpy(posi_output.luma_16x16_mode, luma_16x16_mode, sizeof(posi_output.luma_16x16_mode));
memcpy(posi_output.luma_8x8_mode, luma_8x8_mode, sizeof(posi_output.luma_8x8_mode));
memcpy(posi_output.luma_4x4_mode, luma_4x4_mode, sizeof(posi_output.luma_4x4_mode));
posi_output.chroma_32x32_mode = chroma_32x32_mode;
memcpy(posi_output.chroma_16x16_mode, chroma_16x16_mode, sizeof(posi_output.chroma_16x16_mode));
memcpy(posi_output.chroma_8x8_mode, chroma_8x8_mode, sizeof(posi_output.chroma_8x8_mode));
memcpy(posi_output.chroma_4x4_mode, chroma_4x4_mode, sizeof(posi_output.chroma_4x4_mode));
memcpy(posi_output.cbf, cbf, sizeof(cbf));
memcpy(posi_output.cbf_u, cbf_u, sizeof(cbf_u));
memcpy(posi_output.cbf_v, cbf_v, sizeof(cbf_v));
memcpy(posi_output.cbf4x4, cbf4x4, sizeof(cbf4x4));
posi_output.posi_cost = posi_cost;
pixel_topleft_org = pixel_line_org[(posi_input.x + 1) * f_LCU_SIZE - 1];
pixel_topleft = pixel_line[(posi_input.x + 1) * f_LCU_SIZE - 1];
pixel_topleft_u = pixel_line_u[(posi_input.x + 1) * f_LCU_SIZE / 2 - 1];
pixel_topleft_v = pixel_line_v[(posi_input.x + 1) * f_LCU_SIZE / 2 - 1];
for (int i = 1; i <= f_LCU_SIZE; i++) {
pixel_line_org[posi_input.x * f_LCU_SIZE + i - 1] = forg[f_LCU_SIZE][i];
pixel_line[posi_input.x * f_LCU_SIZE + i - 1] = frec[f_LCU_SIZE][i];
pixel_line_u[posi_input.x * f_LCU_SIZE / 2 + (i + 1) / 2 - 1] = frec_u[f_LCU_SIZE / 2][(i + 1) / 2];
pixel_line_v[posi_input.x * f_LCU_SIZE / 2 + (i + 1) / 2 - 1] = frec_v[f_LCU_SIZE / 2][(i + 1) / 2];
}
posi_out = posi_output;
}
c—posi类的声明
class c_posi
{
private:
prei_t posi_input;
param_t param;
posi_t posi_output;
int QP, QPC;
fetch_req_t info_output;
fetch_t fetch_data;
PIXEL fpred_pixel[f_LCU_SIZE][f_LCU_SIZE];
PIXEL fpred_u_pixel[f_LCU_SIZE][f_LCU_SIZE];
PIXEL fpred_v_pixel[f_LCU_SIZE][f_LCU_SIZE];
PIXEL fenc[f_LCU_SIZE][f_LCU_SIZE];
PIXEL fenc_u[f_LCU_SIZE / 2][f_LCU_SIZE / 2];
PIXEL fenc_v[f_LCU_SIZE / 2][f_LCU_SIZE / 2];
int16_t fres[f_LCU_SIZE][f_LCU_SIZE];
int16_t fres_u[f_LCU_SIZE / 2][f_LCU_SIZE / 2];
int16_t fres_v[f_LCU_SIZE / 2][f_LCU_SIZE / 2];
PIXEL frec[f_LCU_SIZE + 33][f_LCU_SIZE + 33];
PIXEL frec_u[f_LCU_SIZE / 2 + 17][f_LCU_SIZE / 2 + 17];
PIXEL frec_v[f_LCU_SIZE / 2 + 17][f_LCU_SIZE / 2 + 17];
PIXEL forg[f_LCU_SIZE + 33][f_LCU_SIZE + 33];
PIXEL forg_u[f_LCU_SIZE + 33][f_LCU_SIZE + 33];
PIXEL forg_v[f_LCU_SIZE + 33][f_LCU_SIZE + 33];
PIXEL *pixel_line_org;
PIXEL pixel_topleft_org;
PIXEL *pixel_line;
PIXEL *pixel_line_u;
PIXEL *pixel_line_v;
PIXEL pixel_topleft;
PIXEL pixel_topleft_u;
PIXEL pixel_topleft_v;
PIXEL refp[65][65];
PIXEL(*p)
[65];
PIXEL frefp[65][65];
PIXEL(*pf)
[65];
PIXEL frefp_u[65][65];
PIXEL frefp_v[65][65];
bool LCU_TL;
bool LCU_T;
bool LCU_TR;
bool LCU_L;
bool LCU_LD;
CtuType mb_type;
int8_t luma_64x64_mode;
int8_t luma_32x32_mode[4];
int8_t luma_16x16_mode[4][4];
int8_t luma_8x8_mode[4][4][4];
int8_t luma_4x4_mode[4][4][4][4];
int8_t chroma_32x32_mode;
int8_t chroma_16x16_mode[4];
int8_t chroma_8x8_mode[4][4];
int8_t chroma_4x4_mode[4][4][4];
uint32_t posi_cost;
uint32_t luma_64x64_cost;
uint32_t luma_32x32_cost[4];
uint32_t luma_16x16_cost[4][4];
uint32_t luma_8x8_cost[4][4][4];
uint32_t luma_4x4_cost[4][4][4][4];
uint32_t posi_chroma_cost;
uint32_t chroma_16x16_cost[4];
uint32_t chroma_8x8_cost[4][4];
uint32_t chroma_4x4_cost[4][4][4];
int8_t cbf[85];
int8_t cbf_u[85];
int8_t cbf_v[85];
int8_t cbf4x4[64][4];
bool isXBoundry, isYBoundry;
uint8_t x_Boundry;
uint8_t y_Boundry;
uint8_t x_range, y_range;
int K, B;
FILE *posi_sim_input_ori ;
FILE *posi_sim_input_info ;
FILE *posi_sim_input_mode ;
FILE *posi_sim_output_mode;
FILE *posi_sim_output_pt ;
FILE *posi_sim_output_cost;
FILE *posi_sim_output_pred64;
FILE *posi_sim_output_pred32;
FILE *posi_sim_output_pred16;
FILE *posi_sim_output_pred08;
FILE *posi_sim_output_pred04;
FILE *posi_hw;
#ifdef DUMP_DEBUG_posi
FILE *org_for_read;
FILE *posi_pred, *posi_pred_u, *posi_pred_v;
FILE *posi_res, *posi_res_u, *posi_res_v;
FILE *posi_rec, *posi_rec_u, *posi_rec_v;
FILE *posi_cbf;
#endif
#ifdef DUMP_DATA_posi
FILE *result_pred;
FILE *result_rec;
FILE *result_res;
FILE *result_org;
FILE *result_dct;
FILE *result_q;
FILE *result_idct;
FILE *result_md;
FILE *result_u_rec, *result_v_rec;
FILE *result_cbf;
FILE *result_coeff;
#endif
#ifdef DUMP_HWSIM_posi
FILE *org_mode;
FILE *fcur_mb_p32_hw;
FILE *md_decision_hw;
FILE *md_decision_hw_uv;
FILE *pre4x4_hw, *pre8x8_hw, *pre16x16_hw, *pre32x32_hw;
FILE *pre4x4_hw_u, *pre8x8_hw_u, *pre16x16_hw_u, *pre32x32_hw_u;
FILE *pre4x4_hw_v, *pre8x8_hw_v, *pre16x16_hw_v, *pre32x32_hw_v;
FILE *res4x4_hw, *res8x8_hw, *res16x16_hw, *res32x32_hw;
FILE *rsp4x4_hw, *rsp8x8_hw, *rsp16x16_hw, *rsp32x32_hw;
FILE *coe4x4_hw, *coe8x8_hw, *coe16x16_hw, *coe32x32_hw;
FILE *rec4x4_hw, *rec8x8_hw, *rec16x16_hw, *rec32x32_hw;
FILE *rec4x4_hw_u, *rec8x8_hw_u, *rec16x16_hw_u, *rec32x32_hw_u;
FILE *rec4x4_hw_v, *rec8x8_hw_v, *rec16x16_hw_v, *rec32x32_hw_v;
FILE *mb_position_hw;
FILE *rec4x4, *rec8x8, *rec16x16, *rec32x32;
FILE *pred_hw, *pred_hw_x;
#endif
void init();
void load(param_t param_input, prei_t prei_out);
void fetch(c_fetch u_fetch);
void run();
void update(posi_t & posi_out);
void dump();
void load_from_file();
void fetch_from_file();
void posi_pred_org_no_prei();
void org_predict();
void org_pred64x64();
void org_pred32x32(int idx32x32, int x, int y);
void org_pred16x16(int idx32x32, int idx16x16, int x, int y);
void org_pred8x8(int idx32x32, int idx16x16, int idx8x8, int x, int y);
void org_pred4x4(int idx32x32, int idx16x16, int idx8x8, int idx4x4, int x, int y);
void pred_org_no_prei_dump_mode();
void pred_org();
void rec_predict();
void rec_pred32x32(int idx32x32, int x, int y);
void rec_pred16x16(int idx32x32, int idx16x16, int x, int y);
void rec_pred8x8(int idx32x32, int idx16x16, int idx8x8, int x, int y);
void rec_pred4x4(int idx32x32, int idx16x16, int idx8x8, int idx4x4, int x, int y);
void pred_rec();
void pred64x64();
void pred32x32(int idx32x32, int x, int y);
void pred16x16(int idx32x32, int idx16x16, int x, int y);
void pred8x8(int idx32x32, int idx16x16, int idx8x8, int x, int y);
void pred4x4(int idx32x32, int idx16x16, int idx8x8, int idx4x4, int x, int y);
void posi_pred_satd_org();
void predict_satd_org();
void calc_satd_64x64(int8_t mode);
void calc_satd_32x32(int8_t mode, int i_32, int x_32, int y_32);
void calc_satd_16x16(int8_t mode, int i_32, int i_16, int x_16, int y_16);
void calc_satd_8x8(int8_t mode, int i_32, int i_16, int i_8, int x_8, int y_8);
void calc_satd_4x4(int8_t mode, int i_32, int i_16, int i_8, int i_4, int x_4, int y_4);
void choose_best_partition();
void update_partition();
void pred_init();
void LCU_neighbor();
void residual_generate(int x, int y, int block_size, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE], int16_t res[f_LCU_SIZE][f_LCU_SIZE]);
void residual_generate_uv(int x, int y, int block_size, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE], int16_t res[f_LCU_SIZE][f_LCU_SIZE], int idx);
void reconstruction(int x, int y, int block_size, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE], int16_t res[f_LCU_SIZE][f_LCU_SIZE], PIXEL rec[f_LCU_SIZE + 33][f_LCU_SIZE + 33]);
void TU_ref_substitution(int tu_x, int tu_y, int tu_size, PIXEL m_rec[f_LCU_SIZE + 33][f_LCU_SIZE + 33], bool uv_avail[33][33]);
void reference_filter(int tu_size, int mode);
void TU_luma_predict(int tu_x, int tu_y, int tu_size, int mode, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE]);
void TU_chroma_predict(int tu_x, int tu_y, int tu_size, int mode, int idx, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE]);
void Planar_predict(int tu_x, int tu_y, int tu_size, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE]);
void DC_predict(int tu_x, int tu_y, int tu_size, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE], int idx);
void Angular_predict(int tu_x, int tu_y, int tu_size, int mode, PIXEL pred[f_LCU_SIZE][f_LCU_SIZE], int idx);
void uv_ref_substitution(int tu_x, int tu_y, int tu_size, bool uv_avail[33][33], PIXEL rec[f_LCU_SIZE / 2 + 17][f_LCU_SIZE / 2 + 17]);
#ifdef posi_PRED_ORG
void pred_chroma(int tu_x, int tu_y, int tu_size, int8_t luma_mode);
#endif
#ifdef posi_PRED_REC
int pred_chroma(int tu_x, int tu_y, int tu_size, int8_t luma_mode, double *cost);
#endif
void cal_cbf(int x, int y, int tu_size, int idx, int16_t m_res[f_LCU_SIZE][f_LCU_SIZE], int8_t m_cbf[85]);
int8_t cal_4x4cbf(int x, int y, int16_t m_res[f_LCU_SIZE][f_LCU_SIZE]);
int8_t cal_4x4cbf_uv(int x, int y, int16_t m_res[f_LCU_SIZE / 2][f_LCU_SIZE / 2]);
uint32_t luma_SSE(int x, int y, int tu_size, PIXEL rec[f_LCU_SIZE + 33][f_LCU_SIZE + 33]);
void init_hw_sim_dump();
void init_hm_cc_dump();
void init_debug_dump();
void posi_hw_sim_dump();
void posi_hm_cc_dump();
void posi_debug_dump();
public:
void posi_proc(param_t param_input, prei_t prei_out, posi_t &posi_out, c_fetch u_fetch);
};