📄 mae_fe.c
字号:
int64 int_fraction; double fraction, return_val; whole_number = mae_abs64(num) >> fraction_prec; int_fraction = mae_abs64(num) & (int64)(pow(2, (double)fraction_prec)-1); // int_fraction = abs(num) & 0x7f; fraction = (double)int_fraction / (double)pow(2, (double)fraction_prec); //printf("num:%d whole_number:%d int_frac:%d frac:%f \n", num, whole_number, int_fraction, fraction); return_val= fraction + (double)whole_number; return_val = (num >> (fraction_prec + whole_number_prec - 1)) ? return_val*-1 : return_val; return return_val;}int64 gen_con_int(short exp, short sub){ double arg; double temp; arg = (exp*PI)/sub; temp = 1/ (2*cos(arg)); // printf("exp:%d sub:%d temp:%f arg:%f\n", exp, sub, arg, temp); return ( double_to_fixed(temp));}void lee_1d_idct_int(int64 X0, int64 X1, int64 X2, int64 X3, int64 X4, int64 X5, int64 X6, int64 X7, int64 *x){ //pass in the X array //return the IDCT of X in x //x is an array 8 long of ints int64 Xh0, Xh1, Xh2, Xh3, Xh4, Xh5, Xh6, Xh7; int64 I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19; int64 I20, I21, I22, I23, I24, I25, I26; //perform Lee's 1-D IDCT // printf("X's (double): %f %f %f %f %f %f %f %f \n", fixed_to_double(X0), fixed_to_double(X1), fixed_to_double(X2), fixed_to_double(X3), // fixed_to_double(X4), fixed_to_double(X5), fixed_to_double(X6), fixed_to_double(X7) ); // printf("X's: %lld %lld %lld %lld %lld %lld %lld %lld \n", X0, X1, X2, X3, X4, X5, X6, X7); //create X hats Xh0 = mult("IDCT:> Xh0=...",double_to_fixed((1/(sqrt(2.0)*2))), X0); Xh1 = mult("IDCT:> Xh1=...",X1 , double_to_fixed(0.5)); Xh2 = mult("IDCT:> Xh2=...",X2 , double_to_fixed(0.5)); Xh3 = mult("IDCT:> Xh3=...",X3 , double_to_fixed(0.5)); Xh4 = mult("IDCT:> Xh4=...",X4 , double_to_fixed(0.5)); Xh5 = mult("IDCT:> Xh5=...",X5 , double_to_fixed(0.5)); Xh6 = mult("IDCT:> Xh6=...",X6 , double_to_fixed(0.5)); Xh7 = mult("IDCT:> Xh7=...",X7 , double_to_fixed(0.5)); // printf("Xh's (double): %f %f %f %f %f %f %f %f \n", fixed_to_double(Xh0), fixed_to_double(Xh1), fixed_to_double(Xh2), fixed_to_double(Xh3), // fixed_to_double(Xh4), fixed_to_double(Xh5), fixed_to_double(Xh6), fixed_to_double(Xh7) ); // printf("Xh's: %lld %lld %lld %lld %lld %lld %lld %lld \n", Xh0, Xh1, Xh2, Xh3, Xh4, Xh5, Xh6, Xh7); // printf("X0:%d con:%d aswr:%d \n", X0, double_to_fixed(1/(sqrt(2.0)*2)), (double_to_fixed((1/(sqrt(2.0)*2))) * X0) >> prec); // printf("Xh's scaled up 1x: %f %f %f %f %f %f %f %f \n", fixed_to_double(Xh0), fixed_to_double(Xh1), fixed_to_double(Xh2), fixed_to_double(Xh3), // fixed_to_double(Xh4), fixed_to_double(Xh5), fixed_to_double(Xh6), fixed_to_double(Xh7)); //Now go through the flow graph and create the intermediate vals as needed... I0 = add("IDCT:> Xh5 + Xh3",Xh5 , Xh3); I1 = add("IDCT:> Xh1 + Xh3",Xh1 , Xh3); I2 = add("IDCT:> Xh5 + Xh7",Xh5 , Xh7); I3 = mult("IDCT:> Xh4 * gen_con_int(1, 4)", Xh4 , gen_con_int(1, 4)); I4 = mult("IDCT:> (Xh2 + Xh6) * gen_con_int(1, 4)", add("IDCT:> Xh2 + Xh6", Xh2 , Xh6) , gen_con_int(1, 4)); I5 = mult("IDCT:> I0 * gen_con_int(1, 4)", I0 , gen_con_int(1, 4)); I6 = mult("IDCT:> (I1 + I2) * gen_con_int(1, 4)", add("IDCT:> I1 + I2",I1 , I2) ,gen_con_int(1, 4)); // printf("I0:%lld I1:%lld I2:%lld I3:%lld I4':%lld I4:%lld I5:%lld I6':%lld I6:%lld\n", I0, I1, I2, I3, (Xh2 + Xh6), I4, I5, (I1 + I2), I6); // printf("gen_con_int(1, 4):%d \n", gen_con_int(1, 4)); // printf("I3:I6: %f %f %f %f\n", (double)I3/(double)prec_pow, (double)I4/(double)prec_pow, (double)I5/(double)prec_pow, (double)I6/(double)prec_pow); I7 = I3 * -1; I8 = I4 * -1; I9 = I5 * -1; I10 = I6 * -1; I11 = add("IDCT:> Xh0 + I3", Xh0 , I3); I12 = add("IDCT:> Xh0 + I7", Xh0 , I7); I13 = mult("IDCT:> (Xh2 + I4) * gen_con_int(1, 8)", add("IDCT:> Xh2 + I4",Xh2 , I4) , gen_con_int(1, 8)); I14 = mult("IDCT:> (I8 + Xh2) * gen_con_int(3, 8)", add("IDCT:> I8 + Xh2",I8 , Xh2) , gen_con_int(3, 8)); I15 = add("IDCT:> Xh1 + I5", Xh1 , I5); I16 = add("IDCT:> Xh1 + I9", Xh1 , I9); I17 = mult("IDCT:> (I1 + I6) * gen_con_int(1, 8)", add("IDCT:> I1 + I6", I1 , I6), gen_con_int(1, 8)); I18 = mult("IDCT:> (I1 + I10) * gen_con_int(3, 8)", add("IDCT:> I1 + I10", I1 , I10) , gen_con_int(3, 8)); // fprintf(stderr, "I11:%lld I12:%lld I13':%lld I13:%lld I14':%lld I14:%lld I15:%lld I16:%lld I17':%lld I17:%lld I18':%lld I18:%lld\n", // I11, I12, (Xh2 + I4), I13, (I8 + Xh2), I14, I15, I16, (I1 + I6), I17, (I1 + I10), I18); I19 = add("IDCT:> I11 + I13", I11 , I13); I20 = add("IDCT:> I12 + I14", I12 , I14); I21 = add("IDCT:> I11 + (I13*-1)", I11 , (I13*-1)); I22 = add("IDCT:> I12 + (I14*-1)", I12 , (I14*-1)); I23 = mult("IDCT:> (I15 + I17) * gen_con_int(1, 16)", add("IDCT:> I15 + I17", I15 , I17) , gen_con_int(1, 16)); I24 = mult("IDCT:> (I16 + I18) * gen_con_int(3, 16)", add("IDCT:> I16 + I18", I16 , I18) , gen_con_int(3, 16)); I25 = mult("IDCT:> (I15 - I17) * gen_con_int(7, 16)", add("IDCT:> I15 - I17", I15 ,(I17*-1)) , gen_con_int(7, 16)); I26 = mult("IDCT:> (I16 - I18) * gen_con_int(5, 16)", add("IDCT:> I16 - I18", I16 , (I18*-1)) , gen_con_int(5, 16)); // fprintf(stderr, "I19:%lld I20:%lld I21:%lld I22:%lld I23':%lld I23:%lld I24':%lld I24:%lld I25':%lld I25:%lld I26':%lld I26:%lld\n", // I19, I20, I21, I22, (I15 + I17), I23, (I16 + I18), I24, (I15 +(I17*-1)), I25, (I16 + (I18*-1)), I26); x[0] = add("IDCT:> I19 + I23", I19 , I23); x[1] = add("IDCT:> I20 + I24", I20 , I24); x[3] = add("IDCT:> I21 , I25", I21 , I25); x[2] = add("IDCT:> I22 + I26", I22 , I26); x[7] = add("IDCT:> I19 + (I23*-1)", I19 , (I23*-1)); x[6] = add("IDCT:> I20 + (I24*-1)", I20 , (I24*-1)); x[4] = add("IDCT:> I21 + (I25*-1)", I21 , (I25*-1)); x[5] = add("IDCT:> I22 + (I26*-1)", I22 , (I26*-1)); // printf("x's:%lld %lld %lld %lld %lld %lld %lld %lld\n", x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]); //printf("x's: %d %d %d %d %d %d %d %d \n", x[0]/prec_pow, x[1]/prec_pow, x[2]/prec_pow, x[3]/prec_pow, // x[4]/prec_pow, x[5]/prec_pow, x[6]/prec_pow, x[7]/prec_pow);}void lee_idct_2d_fixed_point(int64 *dblock, int32 *dst_block, int block_number, uint32 exp_bc){ int i, cnt; int64 idct_1d[8]; int64 v; RTL_printf("\nhex Intermediate Lee Matrix\n"); for (i=0; i<8; i++) { lee_1d_idct_int(dblock[8*i+0], dblock[8*i+1], dblock[8*i+2], dblock[8*i+3], dblock[8*i+4], dblock[8*i+5], dblock[8*i+6], dblock[8*i+7], idct_1d); for(cnt=0; cnt<8; cnt++){ dblock[8*i+cnt] = idct_1d[cnt]; RTL_printf("%llx ", dblock[8*i+cnt]); // TB intermediate checker tb[tb_in][block_number].data[(i*8) + cnt] = idct_1d[cnt]; } RTL_printf("\n"); } tb[tb_in][block_number].bn = block_number; if(block_number == (int)(exp_bc-1)) { tb_in = !tb_in; } // Transpose operation is integrated into address mapping RTL_printf("\nwhole number IDCT result\n"); for (i=0; i<8; i++){ lee_1d_idct_int(dblock[8*0+i], dblock[8*1+i], dblock[8*2+i], dblock[8*3+i], dblock[8*4+i], dblock[8*5+i], dblock[8*6+i], dblock[8*7+i], idct_1d); for(cnt=0; cnt<8; cnt++){ double d; // Pre-saturation intermediate checker presat[presat_in][block_number].data[(i*8) + cnt] = (int64)floor(fixed_to_double(idct_1d[cnt])); d = fixed_to_double(idct_1d[cnt]); v = (int64) ((d >= 0) ? (d + .5) : (d - .5)); dst_block[(8*cnt)+i] = (int32) ((v<-256) ? -256 : ((v>255) ? 255 : v)); // Don't forget to remove all instances of sat_block //sat_block[(8*cnt)+i] = ((v<-256) ? -256 : ((v>255) ? 255 : v)); //dst_block[(8*cnt)+i] = (uint8)((sat_block[(8*cnt)+i] + 256)/2); // Pre-saturation intermediate checker postsat[postsat_in][block_number].data[(i*8) + cnt] = dst_block[(8*cnt)+i]; RTL_printf("0x%llx ", v); } RTL_printf("\n"); } presat[presat_in][block_number].bn = block_number; postsat[postsat_in][block_number].bn = block_number; if(block_number == (int32) (exp_bc-1)) { presat_in = !presat_in; } if(block_number == (int32) (exp_bc-1)) { postsat_in = !postsat_in; } }void perform_iquant(mae_fe_config * mae_fe_cfg, mae_fe_mb * mb_in, int64 *fixed_point_block, int block_number, int8 *w_matrix, uint32 blk_mbmode){ //Perform Iquant as descriibed by our spec int cnt; int64 a1, a2, a3, a4, a5; int64 a5_temp, a5_add_one; int64 mis = 0; uint32 exp_bc; uint64 mask = UINT64(0xffffffffffffffff); int32 cbp = (mb_in->cbp >> (7-block_number)) & 0x1; uint32 blk_xformsize; int64 neg_iqadd2; exp_bc = mae_fe_cfg->bc ? 8 : 6; blk_xformsize = (mb_in->xformsize>>(14 - 2*block_number)) & 0x3; for(cnt=0; cnt<64; cnt++){ //deal with intra DC coeficients if((cnt==0) && (blk_mbmode==MBM_INTRA)){ if(block_number <= 3){ //luma fixed_point_block[0] = mult("IQuant:> block_data * dc_luma", fixed_point_block[0] , double_to_fixed((double)mb_in->dcluma)); } else { //chroma fixed_point_block[0] = mult("IQuant:> block_data * dc_chroma", fixed_point_block[0] , double_to_fixed((double)mb_in->dcchroma)); } }else { //deal with all other coeficients a1 = fixed_sign_extend(fixed_point_block[cnt] << mae_fe_cfg->iqmul1); if(a1<0) a2 = a1 - double_to_fixed((double)mb_in->iqadd1); else a2 = a1 + double_to_fixed((double)mb_in->iqadd1); a3 = mult("IQuant:> a2 * w_matrix[i]", a2 , double_to_fixed((double)w_matrix[cnt])); a4 = mult("IQuant:> a3 * iq_mul2", a3, double_to_fixed((double)mb_in->iqmul2)); // printf("\nfixed_point_block:%lld a1:%lld a2:%lld a3:%lld a4:%lld a5:%lld\n", fixed_point_block[cnt], a1, a2, a3, a4, a5); mask = ~(UINT64(0xffffffffffffffff) << mb_in->iqdiv3); a5_temp = add("IQuant:> a4 + iq_add2", a4 , double_to_fixed((double)mb_in->iqadd2)); if (mae_fe_cfg->codstyl) { if((is_pos(fixed_point_block[cnt])) && (fixed_point_block[cnt] != 0)) a5_temp = add("IQuant:> a4 + iq_add2", a4 , double_to_fixed((double)mb_in->iqadd2)); else if (fixed_point_block[cnt] == 0) a5_temp = a4; else { neg_iqadd2 = mult("IQuant:> iq_add2 * -1", double_to_fixed(-1), double_to_fixed((double)mb_in->iqadd2)); a5_temp = add("IQuant:> a4 - iq_add2", a4 , neg_iqadd2); } } a5_add_one = ( (a5_temp & (mask << fraction_prec)) && !(is_pos(a5_temp)) ); a5 = add("IQuant:> a5_temp >> mb_in->iqdiv3 + a5_add_one", (a5_temp >> mb_in->iqdiv3) , double_to_fixed((double)a5_add_one)); /* if(cnt==1) { log_printf("a1 = %llx, fixed_point_block[1] = %llx, iqmul1 = %x\n", a1>>14, fixed_point_block[1]>>14, mae_fe_cfg->iqmul1); log_printf("a2 = %llx, iqadd1 = %x\n", a2>>14, mb_in->iqadd1); log_printf("a3 = %llx, w_matrix[1] = %x\n", a3>>14, w_matrix[1]); log_printf("a4 = %llx, iqmul2 = %x\n", a4>>14, mb_in->iqmul2); log_printf("a5_temp = %llx, iq_add2 = %x, mask = %llx, neg_iqadd2 = %llx\n", a5_temp>>14, mb_in->iqadd2, mask, neg_iqadd2); log_printf("a5 = %llx, iqdiv3 = %x, a5_add_one = %llx\n", a5>>14, mb_in->iqdiv3, a5_add_one);} */ fixed_point_block[cnt] = a5 & ~(int64)(pow(2, (double)fraction_prec)-1); } // Saturation if(mae_fe_cfg->satiq) { fixed_point_block[cnt] = ((fixed_to_double(fixed_point_block[cnt])) > 2047.0) ? double_to_fixed((double)2047) : ((fixed_to_double(fixed_point_block[cnt])) < -2048.0) ? double_to_fixed((double)-2048) : fixed_point_block[cnt]; } // Mismatch control - checks for odd/even mis = mis + (int64)fixed_to_double(fixed_point_block[cnt]); // intermediate checker iq_buf[iq_in][block_number].data[cnt] = fixed_point_block[cnt]; }//end for(cnt... // This works because there should be no fraction at this point if((mae_fe_cfg->mis) && !(mis%2) && cbp){ fixed_point_block[63] = (((int64)fixed_to_double(fixed_point_block[63]))%2) ? add("IQuant:> F[7,7] mismatch control", fixed_point_block[63], double_to_fixed((double)-1)) : add("IQuant:> F[7,7] mismatch control", fixed_point_block[63], double_to_fixed((double)1)); iq_buf[iq_in][block_number].data[63] = fixed_point_block[63]; } iq_buf[iq_in][block_number].bn = block_number; iq_buf[iq_in][block_number].blk_xformsize = (mb_in->xformsize>>(14 - 2*block_number)) & 0x3; if(block_number == (int32) (exp_bc-1)) { iq_in = !iq_in; }}static int cmodel_initialized = 0;void cmodel_init_global() { memset(&gCM, 0, sizeof(struct GlobalCModelInfo)); cmodel_initialized = 1;}void cmodel_check_global() { if (!cmodel_initialized) { printf("ERROR cmodel_init_global() was not called! Please update your player!\n"); exit(1); }}void fe_process_mb(mae_fe_config * mae_fe_cfg, mae_fe_mb * mb_in, uint8 *cur_y_frame, uint8 *cur_cb_frame, uint8 *cur_cr_frame, uint32 mb_num){ //This routine will process the macroblock and write the data to the current frame //The front end config register is obtained directly from the class int c,x,y; unsigned int i,j; uint32 bn; int16 * block; int16 non_cb[64]; int64 fixed_point_block[64]; int32 dst_block[64]; int32 wmv9_block[64]; int16 wmv9_idct_block[64]; // uint32 *dst_block_ptr; int16 *dst_ptr; uint8 *src_ptr; uint32 linesize, xpos, ypos, ps_linesize; uint8 *wm; MAEContext s; uint32 blk_mbmode, y_mbmode, uv_mbmode; uint32 blk_xformsize; int32 raw_pixel; uint8 sat_pixel;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -