00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _GLOBAL_H_
00015 #define _GLOBAL_H_
00016
00017 #include "win32.h"
00018 #include "defines.h"
00019 #include "parsetcommon.h"
00020 #include "ifunctions.h"
00021 #include "frame.h"
00022 #include "io_video.h"
00023 #include "io_image.h"
00024 #include "nalucommon.h"
00025 #include "params.h"
00026 #include "distortion.h"
00027 #include "lagrangian.h"
00028 #include "quant_params.h"
00029 #include "rc_types.h"
00030
00031
00032
00033
00034
00035
00036
00037 typedef struct inp_par_enc InputParameters;
00038
00039
00040 struct storable_picture;
00041 struct coding_state;
00042
00043 typedef struct image_structure
00044 {
00045 FrameFormat format;
00046 imgpel **data[3];
00047 } ImageStructure;
00048
00049
00050 typedef struct info_8x8
00051 {
00052 char mode;
00053 char pdir;
00054 char ref[2];
00055 char bipred;
00056 } Info8x8;
00057
00058 typedef struct search_window {
00059 int min_x;
00060 int max_x;
00061 int min_y;
00062 int max_y;
00063 } SearchWindow;
00064
00065
00066 typedef struct bit_counter
00067 {
00068 int mb_total;
00069 unsigned short mb_mode;
00070 unsigned short mb_inter;
00071 unsigned short mb_cbp;
00072 unsigned short mb_delta_quant;
00073 int mb_y_coeff;
00074 int mb_uv_coeff;
00075 int mb_cb_coeff;
00076 int mb_cr_coeff;
00077 int mb_stuffing;
00078 } BitCounter;
00079
00080
00081 typedef struct
00082 {
00083 struct img_par *p_Img;
00084 unsigned int Elow, Erange;
00085 unsigned int Ebuffer;
00086 unsigned int Ebits_to_go;
00087 unsigned int Echunks_outstanding;
00088 int Epbuf;
00089 byte *Ecodestrm;
00090 int *Ecodestrm_len;
00091 int C;
00092 int E;
00093 } EncodingEnvironment;
00094
00095 typedef EncodingEnvironment *EncodingEnvironmentPtr;
00096
00097
00098 typedef struct
00099 {
00100 unsigned long count;
00101 uint16 state;
00102 unsigned char MPS;
00103 } BiContextType;
00104
00105 typedef BiContextType *BiContextTypePtr;
00106
00107
00108
00109
00110
00111
00112
00113 typedef struct
00114 {
00115 BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX];
00116 BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
00117 BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
00118 BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
00119 } MotionInfoContexts;
00120
00121 typedef struct
00122 {
00123 BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
00124 BiContextType ipr_contexts [NUM_IPR_CTX];
00125 BiContextType cipr_contexts[NUM_CIPR_CTX];
00126 BiContextType cbp_contexts [3][NUM_CBP_CTX];
00127 BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
00128 BiContextType delta_qp_contexts [NUM_DELTA_QP_CTX];
00129 BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
00130 BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
00131 #if ENABLE_FIELD_CTX
00132 BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
00133 BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00134 BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00135 #else
00136 BiContextType map_contexts [1][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00137 BiContextType last_contexts[1][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00138 #endif
00139 } TextureInfoContexts;
00140
00141
00142
00143
00144 typedef struct pix_pos
00145 {
00146 int available;
00147 int mb_addr;
00148 short x;
00149 short y;
00150 short pos_x;
00151 short pos_y;
00152 } PixelPos;
00153
00154
00155 typedef struct
00156 {
00157 short mv_x;
00158 short mv_y;
00159 } MotionVector;
00160
00161
00162 typedef struct pic_motion_params
00163 {
00164 int64 *** ref_pic_id;
00165 int64 *** ref_id;
00166 short **** mv;
00167 char *** ref_idx;
00168 byte * mb_field;
00169 byte ** field_frame;
00170 } PicMotionParams;
00171
00172
00173
00174
00175 typedef struct
00176 {
00177 int slice_type;
00178 int display_no;
00179 int reference_idc;
00180 int slice_qp;
00181 int hierarchy_layer;
00182 int hierarchyPocDelta;
00183 } GOP_DATA;
00184
00185
00186 typedef struct DecRefPicMarking_s
00187 {
00188 int memory_management_control_operation;
00189 int difference_of_pic_nums_minus1;
00190 int long_term_pic_num;
00191 int long_term_frame_idx;
00192 int max_long_term_frame_idx_plus1;
00193 struct DecRefPicMarking_s *Next;
00194 } DecRefPicMarking_t;
00195
00196 typedef struct me_block
00197 {
00198 struct img_par *p_Img;
00199
00200 short pos_x_padded;
00201 short pos_y_padded;
00202
00203 short blocktype;
00204 short blocksize_x;
00205 short blocksize_y;
00206 short blocksize_cr_x;
00207 short blocksize_cr_y;
00208
00209 short block_x;
00210 short block_y;
00211
00212 short pos_x;
00213 short pos_y;
00214 short pos_x2;
00215 short pos_y2;
00216
00217 short pos_cr_x;
00218 short pos_cr_y;
00219
00220 char list;
00221 char ref_idx;
00222 MotionVector mv[2];
00223 PixelPos block[4];
00224 struct slice *p_slice;
00225 struct search_window searchRange;
00226 int cost;
00227 imgpel **orig_pic;
00228 Boolean ChromaMEEnable;
00229 int ChromaMEWeight;
00230
00231 int apply_weights;
00232 int apply_bi_weights;
00233
00234 int test8x8;
00235
00236 short weight_luma;
00237 short weight_cr[2];
00238 short offset_luma;
00239 short offset_cr[2];
00240
00241
00242 short weight1;
00243 short weight2;
00244 short offsetBi;
00245 short weight1_cr[2];
00246 short weight2_cr[2];
00247 short offsetBi_cr[2];
00248 int search_pos2;
00249 int search_pos4;
00250 int iteration_no;
00251
00252
00253 int (*computePredFPel) (struct storable_picture *, struct me_block *, int , MotionVector * );
00254 int (*computePredHPel) (struct storable_picture *, struct me_block *, int , MotionVector * );
00255 int (*computePredQPel) (struct storable_picture *, struct me_block *, int , MotionVector * );
00256 int (*computeBiPredFPel) (struct storable_picture *, struct storable_picture *, struct me_block *, int , MotionVector *, MotionVector *);
00257 int (*computeBiPredHPel) (struct storable_picture *, struct storable_picture *, struct me_block *, int , MotionVector *, MotionVector *);
00258 int (*computeBiPredQPel) (struct storable_picture *, struct storable_picture *, struct me_block *, int , MotionVector *, MotionVector *);
00259 } MEBlock;
00260
00261
00262 typedef struct syntaxelement
00263 {
00264 int type;
00265 int value1;
00266 int value2;
00267 int len;
00268 int inf;
00269 unsigned int bitpattern;
00270 int context;
00271
00272 #if TRACE
00273 #define TRACESTRING_SIZE 100
00274 char tracestring[TRACESTRING_SIZE];
00275 #endif
00276
00277
00278 void (*mapping)(int value1, int value2, int* len_ptr, int* info_ptr);
00279
00280 } SyntaxElement;
00281
00282
00283 struct macroblock
00284 {
00285 struct slice *p_slice;
00286 struct img_par *p_Img;
00287 InputParameters *p_Inp;
00288 int mbAddrX;
00289 short mb_type;
00290 short slice_nr;
00291 short mb_x;
00292 short mb_y;
00293 short block_x;
00294 short block_y;
00295
00296 short pix_x;
00297 short pix_y;
00298 short pix_c_x;
00299 short pix_c_y;
00300
00301 short opix_y;
00302 short opix_c_y;
00303
00304 short subblock_x;
00305 short subblock_y;
00306
00307 short list_offset;
00308
00309
00310 int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
00311 byte mbAvailA, mbAvailB, mbAvailC, mbAvailD;
00312
00313 short qp;
00314 short qpc[2];
00315 short qp_scaled[MAX_PLANE];
00316 short qpsp;
00317 int cbp;
00318 short prev_qp;
00319 short prev_dqp;
00320 int prev_cbp;
00321 int cr_cbp[3];
00322 int c_nzCbCr[3];
00323
00324 short i16offset;
00325
00326 BitCounter bits;
00327
00328 short ar_mode;
00329 short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2];
00330 char c_ipred_mode;
00331 char i16mode;
00332
00333 Info8x8 b8x8[4];
00334
00335 imgpel intra4x4_pred[3][17];
00336 imgpel intra8x8_pred[3][25];
00337
00338 char IntraChromaPredModeFlag;
00339 byte mb_field;
00340 byte is_field_mode;
00341 byte luma_transform_size_8x8_flag;
00342 byte temp_transform_size_8x8_flag;
00343 byte NoMbPartLessThan8x8Flag;
00344 byte valid_8x8;
00345 byte write_mb;
00346 byte is_intra_block;
00347
00348 char DFDisableIdc;
00349 char DFAlphaC0Offset;
00350 char DFBetaOffset;
00351
00352 int skip_flag;
00353
00354 char intra_pred_modes [MB_BLOCK_PARTITIONS];
00355 char intra_pred_modes8x8[MB_BLOCK_PARTITIONS];
00356
00357 int64 cbp_blk ;
00358 int64 cbp_bits[3];
00359 int64 cbp_bits_8x8[3];
00360
00361 double min_rdcost;
00362 double min_dcost;
00363 double min_rate;
00364
00365 short best_mode;
00366 char best_c_imode;
00367 short best_i16offset;
00368 int best_cbp;
00369
00370
00371 short ipmode_DPCM;
00372
00373
00374
00375 struct macroblock *mb_up;
00376 struct macroblock *mb_left;
00377 struct macroblock *PrevMB;
00378
00379
00380 void (*GetMVPredictor) (struct macroblock *currMB, PixelPos *block, short pmv[2], short ref_frame,
00381 char **refPic, short ***tmp_mv, int mb_x, int mb_y, int blockshape_x, int blockshape_y);
00382 int (*IntPelME) (struct macroblock *currMB, MotionVector *, struct me_block *mv_block, int, int);
00383 int (*BiPredME) (struct macroblock *currMB, int, MotionVector *, MotionVector *, MotionVector *, MotionVector *, struct me_block *, int, int, int);
00384 int (*SubPelBiPredME) (struct macroblock *currMB, struct me_block *, int list,
00385 MotionVector *pred_mv1, MotionVector *pred_mv2, MotionVector *mv1, MotionVector *mv2, int min_mcost, int* lambda_factor);
00386 int (*SubPelME) (struct macroblock *currMB,
00387 MotionVector *pred_mv, struct me_block *mv_block, int min_mcost, int* lambda_factor);
00388
00389 int (*trans_4x4) (struct macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra);
00390 int (*trans_16x16) (struct macroblock *currMB, ColorPlane pl);
00391 int (*trans_8x8) (struct macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra);
00392 int (*trans_cr_4x4[2])(struct macroblock *currMB, int uv,int i11);
00393
00394 void (*cbp_linfo_intra)(int cbp, int dummy, int *len,int *info);
00395 void (*cbp_linfo_inter)(int cbp, int dummy, int *len,int *info);
00396 };
00397
00398 typedef struct macroblock Macroblock;
00399
00400
00401 typedef struct
00402 {
00403 int buffer_size;
00404 int byte_pos;
00405 int bits_to_go;
00406
00407 int stored_byte_pos;
00408 int stored_bits_to_go;
00409 int byte_pos_skip;
00410 int bits_to_go_skip;
00411 int write_flag;
00412
00413 byte byte_buf;
00414 byte stored_byte_buf;
00415 byte byte_buf_skip;
00416 byte *streamBuffer;
00417
00418 #if TRACE
00419 Boolean trace_enabled;
00420 #endif
00421 } Bitstream;
00422
00423
00424
00425 typedef struct datapartition
00426 {
00427 struct slice *p_Slice;
00428 struct img_par *p_Img;
00429 InputParameters *p_Inp;
00430 Bitstream *bitstream;
00431 NALU_t *nal_unit;
00432 EncodingEnvironment ee_cabac;
00433 EncodingEnvironment ee_recode;
00434 } DataPartition;
00435
00436
00437
00438 typedef struct rd_data
00439 {
00440 double min_rdcost;
00441 double min_dcost;
00442 double min_rate;
00443
00444 imgpel ***rec_mb;
00445 int ****cofAC;
00446 int ***cofDC;
00447 int *****cofAC_new;
00448 short mb_type;
00449 int64 cbp_blk;
00450 int cbp;
00451 int prev_cbp;
00452 int mode;
00453 short i16offset;
00454 Boolean NoMbPartLessThan8x8Flag;
00455
00456 char c_ipred_mode;
00457 short qp;
00458 short prev_qp;
00459 short prev_dqp;
00460 byte luma_transform_size_8x8_flag;
00461 Info8x8 block;
00462 Info8x8 b8x8[4];
00463
00464
00465 short ******all_mv;
00466 short *******bipred_mv;
00467
00468 char intra_pred_modes[16];
00469 char intra_pred_modes8x8[16];
00470 char **ipredmode;
00471 char ***refar;
00472 } RD_DATA;
00473
00474
00475 typedef struct slice
00476 {
00477 struct img_par *p_Img;
00478 InputParameters *p_Inp;
00479 pic_parameter_set_rbsp_t *active_pps;
00480 seq_parameter_set_rbsp_t *active_sps;
00481
00482 int picture_id;
00483 int qp;
00484 int qs;
00485 short slice_type;
00486 unsigned int frame_num;
00487 unsigned int max_frame_num;
00488 signed int framepoc;
00489 signed int ThisPOC;
00490 short slice_nr;
00491 int model_number;
00492 char colour_plane_id;
00493 int lossless_qpprime_flag;
00494 int P444_joined;
00495 int disthres;
00496 int Transform8x8Mode;
00497
00498
00499 int UseRDOQuant;
00500 int RDOQ_QP_Num;
00501
00502 char num_ref_idx_active[2];
00503 int ref_pic_list_reordering_flag[2];
00504 int *reordering_of_pic_nums_idc[2];
00505 int *abs_diff_pic_num_minus1[2];
00506 int *long_term_pic_idx[2];
00507
00508 int width_blk;
00509 int height_blk;
00510
00511 PictureStructure structure;
00512 Boolean MbaffFrameFlag;
00513
00514 int start_mb_nr;
00515 int max_part_nr;
00516 int num_mb;
00517
00518 int cmp_cbp[3];
00519 int curr_cbp[2];
00520 char symbol_mode;
00521 short NoResidueDirect;
00522 short partition_mode;
00523 short idr_flag;
00524 int frame_no;
00525 unsigned int PicSizeInMbs;
00526 int num_blk8x8_uv;
00527 int nal_reference_idc;
00528 short bitdepth_luma;
00529 short bitdepth_chroma;
00530
00531
00532 DataPartition *partArr;
00533 MotionInfoContexts *mot_ctx;
00534 TextureInfoContexts *tex_ctx;
00535
00536 int mvscale[6][MAX_REFERENCE_PICTURES];
00537 char direct_spatial_mv_pred_flag;
00538
00539 char DFDisableIdc;
00540 char DFAlphaC0Offset;
00541 char DFBetaOffset;
00542
00543 byte weighted_prediction;
00544 byte weighted_bipred_idc;
00545
00546 short luma_log_weight_denom;
00547 short chroma_log_weight_denom;
00548 short wp_luma_round;
00549 short wp_chroma_round;
00550
00551 short max_num_references;
00552
00553
00554 short ******all_mv;
00555 short *******bipred_mv;
00556
00557 short ***wp_weight;
00558 short ***wp_offset;
00559 short ****wbp_weight;
00560
00561 int *****cofAC_new;
00562
00563 int ****cofAC;
00564 int *** cofDC;
00565
00566
00567 int diffy[16][16];
00568
00569 int64 cur_cbp_blk[MAX_PLANE];
00570 int coeff_cost_cr[MAX_PLANE];
00571
00572
00573 int **tblk16x16;
00574 int **tblk4x4;
00575 int ****i16blk4x4;
00576
00577 RD_DATA *rddata;
00578
00579
00580 RD_DATA rddata_trellis_best;
00581 RD_DATA rddata_trellis_curr;
00582
00583 RD_DATA rddata_top_frame_mb;
00584 RD_DATA rddata_bot_frame_mb;
00585 RD_DATA rddata_top_field_mb;
00586 RD_DATA rddata_bot_field_mb;
00587
00588 Boolean si_frame_indicator;
00589 Boolean sp2_frame_indicator;
00590
00591 char ***direct_ref_idx;
00592 char **direct_pdir;
00593
00594 MotionVector ****tmp_mv8;
00595 int ***motion_cost8;
00596 int deltaQPTable[9];
00597
00598
00599 struct est_bits_cabac *estBitsCabac;
00600 double norm_factor_4x4;
00601 double norm_factor_8x8;
00602
00603 imgpel ****mpr_4x4;
00604 imgpel ****mpr_8x8;
00605 imgpel ****mpr_16x16;
00606 imgpel ***mb_pred;
00607 int ***mb_rres;
00608 int ***mb_ores;
00609
00610
00611 char b8_ipredmode8x8[4][4];
00612 char b8_intra_pred_modes8x8[16];
00613 char b4_ipredmode[16];
00614 char b4_intra_pred_modes[16];
00615
00616 struct rdo_structure *p_RDO;
00617 struct colocated_params *p_colocated;
00618 struct epzs_params *p_EPZS;
00619
00620
00621 struct storable_picture **listX[6];
00622 char listXsize[6];
00623
00624
00625 int coeff[64];
00626 int coeff_ctr;
00627 int pos;
00628
00629
00630
00631 int (*Mode_Decision_for_4x4IntraBlocks) (Macroblock *currMB, int b8, int b4, double lambda, double* min_cost);
00632 int (*Mode_Decision_for_8x8IntraBlocks) (Macroblock *currMB, int b8, double lambda, double *min_cost);
00633 double (*rdcost_for_4x4_intra_blocks) (Macroblock *currMB, int *c_nz, int b8, int b4, int ipmode, double lambda, int mostProbableMode, double min_rdcost);
00634 double (*rdcost_for_8x8_intra_blocks) (Macroblock *currMB, int *c_nz, int b8, int ipmode, double lambda, double min_rdcost, int mostProbableMode);
00635 void (*Get_Direct_Motion_Vectors) (Macroblock *currMB);
00636 Boolean (*slice_too_big) (int bits_slice);
00637 void (*SetMotionVectorsMB) (Macroblock *currMB, struct pic_motion_params *motion);
00638 void (*encode_one_macroblock) (Macroblock *currMB);
00639 void (*set_stored_mb_parameters) (Macroblock *currMB);
00640 void (*set_ref_and_motion_vectors) (Macroblock *currMB, struct pic_motion_params *motion, Info8x8 *part, int block);
00641 int (*distI16x16) (Macroblock *currMB, imgpel **img_org, imgpel **pred_img, double min_cost);
00642 void (*compute_cost8x8) (struct img_par *p_Img, imgpel **cur_img, imgpel **prd_img, int pic_opix_x, int *cost, int min_cost);
00643 void (*compute_cost4x4) (struct img_par *p_Img, imgpel **cur_img, imgpel **prd_img, int pic_opix_x, int *cost, int min_cost);
00644 double (*find_sad_16x16) (Macroblock *currMB);
00645 void (*SetLagrangianMultipliers) (struct img_par *p_Img, InputParameters *p_Inp);
00646
00647
00648 void (*writeMB_typeInfo) (Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00649 void (*writeMB_Skip) (Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00650 void (*writeIntraPredMode) (SyntaxElement *se, DataPartition *dP);
00651 void (*writeB8_typeInfo) (SyntaxElement *se, DataPartition *dP);
00652 void (*writeRefFrame[6]) (SyntaxElement *se, DataPartition *dP);
00653 int (*writeMotionInfo2NAL) (Macroblock* currMB);
00654 int (*write_MB_layer) (Macroblock *currMB, int rdopt, int *coeff_rate);
00655 void (*writeMVD) (Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00656 void (*writeCBP) (Macroblock* currMB, SyntaxElement *se, DataPartition *dP);
00657 void (*writeDquant) (Macroblock* currMB, SyntaxElement *se, DataPartition *dP);
00658 void (*writeCIPredMode) (Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00659 void (*writeFieldModeInfo) (Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00660 void (*writeMB_transform_size)(Macroblock *currMB, SyntaxElement *se, DataPartition *dP);
00661 int (*writeCoeff16x16) (Macroblock* currMB, ColorPlane);
00662 int (*writeCoeff4x4_CAVLC) (Macroblock* currMB, int block_type, int b8, int b4, int param);
00663 void (*write_and_store_CBP_block_bit) (Macroblock* currMB, EncodingEnvironmentPtr eep_dp, int type, int cbp_bit, TextureInfoContexts* tex_ctx);
00664
00665
00666 void (*reset_coding_state) (Macroblock *currMB, struct coding_state *);
00667 void (*store_coding_state) (Macroblock *currMB, struct coding_state *);
00668
00669
00670 void (*poc_ref_pic_reorder_frame) ( struct slice *currSlice, struct storable_picture **list, unsigned num_ref_idx_lX_active,
00671 int *reordering_of_pic_nums_idc, int *abs_diff_pic_num_minus1, int *long_term_pic_idx, int list_no );
00672
00673
00674 int (*quant_4x4) (Macroblock *currMB, int **tblock, struct quant_methods *q_method);
00675 int (*quant_ac4x4cr) (Macroblock *currMB, int **tblock, struct quant_methods *q_method, int type);
00676 int (*quant_dc4x4) (Macroblock *currMB, int **tblock, int qp, int* DCLevel, int* DCRun, LevelQuantParams *q_params_4x4, const byte (*pos_scan)[2]);
00677 int (*quant_ac4x4) (Macroblock *currMB, int **tblock, struct quant_methods *q_method, int type);
00678 int (*quant_8x8) (Macroblock *currMB, int **tblock, struct quant_methods *q_method);
00679 int (*quant_8x8cavlc)(Macroblock *currMB, int **tblock, struct quant_methods *q_method, int*** cofAC);
00680
00681 int (*quant_dc_cr) (Macroblock *currMB, int **tblock, int qp, int* DCLevel, int* DCRun,
00682 LevelQuantParams *q_params_4x4, int **fadjust, const byte (*pos_scan)[2]);
00683 void (*rdoq_4x4) (Macroblock *currMB, int **tblock, struct quant_methods *q_method, int levelTrellis[16]);
00684
00685 void (*rdoq_dc) (Macroblock *currMB, int **tblock, int qp_per, int qp_rem, LevelQuantParams *q_params_4x4,
00686 const byte (*pos_scan)[2], int levelTrellis[16], int type);
00687
00688 void (*rdoq_ac4x4) (Macroblock *currMB, int **tblock , struct quant_methods *q_method, int levelTrellis[16], int type);
00689
00690 void (*rdoq_dc_cr) (Macroblock *currMB, int **tblock, int qp_per, int qp_rem, LevelQuantParams *q_params_4x4,
00691 const byte (*pos_scan)[2], int levelTrellis[16], int type);
00692
00693 void (*set_modes_and_reframe) (Macroblock *currMB, int b8, short* p_dir, int list_mode[2], char *list_ref_idx);
00694
00695 int64 (*getDistortion) ( Macroblock *currMB );
00696 } Slice;
00697
00698
00699 typedef struct distortion_metric
00700 {
00701 float value[3];
00702 float average[3];
00703 float avslice[NUM_SLICE_TYPES][3];
00704 } DistMetric;
00705
00706 typedef struct distortion_params
00707 {
00708 int frame_ctr;
00709 DistMetric metric[TOTAL_DIST_TYPES];
00710 } DistortionParams;
00711
00712 typedef struct picture
00713 {
00714 int no_slices;
00715 int bits_per_picture;
00716 struct slice *slices[MAXSLICEPERPICTURE];
00717
00718 DistMetric distortion;
00719 byte idr_flag;
00720 } Picture;
00721
00722
00723 typedef struct block_8x8_info
00724 {
00725 Info8x8 best[MAXMODE][4];
00726 } Block8x8Info;
00727
00728
00729 typedef struct img_par
00730 {
00731 InputParameters *p_Inp;
00732 pic_parameter_set_rbsp_t *active_pps;
00733 seq_parameter_set_rbsp_t *active_sps;
00734 struct sei_params *p_SEI;
00735 struct decoders *p_decs;
00736
00737 int number;
00738 int start_frame_no;
00739 int gop_number;
00740 int frm_number;
00741 int cur_frm_number;
00742 int last_idr_number;
00743 int idr_gop_number;
00744 int rewind_frame;
00745 int LevelIndex;
00746 int MaxVmvR[6];
00747 int MaxHmvR[6];
00748 int current_mb_nr;
00749 short current_slice_nr;
00750 short type;
00751 PictureStructure structure;
00752 int base_dist;
00753 int num_ref_frames;
00754 int max_num_references;
00755 int masterQP;
00756 int qp;
00757 int qpsp;
00758
00759
00760 struct search_window searchRange;
00761 ImageData imgData;
00762 ImageData imgData0;
00763 ImageData imgData1;
00764 ImageData imgData2;
00765
00766 struct image_structure imgSRC;
00767 struct image_structure imgREF;
00768 struct image_structure imgRGB_src;
00769 struct image_structure imgRGB_ref;
00770 int **imgY_sub_tmp;
00771 imgpel **imgY_com;
00772 imgpel ***imgUV_com;
00773
00774 imgpel **pCurImg;
00775
00776 imgpel **pImgOrg[MAX_PLANE];
00777
00778 Picture *p_frame_pic;
00779 Picture **frame_pic;
00780 Picture **field_pic;
00781 Picture *frame_pic_si;
00782
00783 byte *MapUnitToSliceGroupMap;
00784
00785 byte *buf;
00786 byte *ibuf;
00787
00788 #ifdef _LEAKYBUCKET_
00789 long *Bit_Buffer;
00790 unsigned long total_frame_buffer;
00791 #endif
00792
00793 unsigned int log2_max_frame_num_minus4;
00794 unsigned int log2_max_pic_order_cnt_lsb_minus4;
00795 unsigned int max_frame_num;
00796 unsigned int max_pic_order_cnt_lsb;
00797
00798 int64 me_tot_time;
00799 int64 tot_time;
00800 int64 me_time;
00801
00802 byte mixedModeEdgeFlag;
00803
00804 int *RefreshPattern;
00805 int *IntraMBs;
00806 int WalkAround;
00807 int NumberOfMBs;
00808 int NumberIntraPerPicture;
00809
00810 short start_me_refinement_hp;
00811 short start_me_refinement_qp;
00812
00813
00814 struct umhex_struct *p_UMHex;
00815 struct umhex_smp_struct *p_UMHexSMP;
00816 struct me_full_fast *p_ffast_me;
00817
00818 struct search_window *p_search_window;
00819
00820
00821 struct epzs_struct *sdiamond;
00822 struct epzs_struct *square;
00823 struct epzs_struct *ediamond;
00824 struct epzs_struct *ldiamond;
00825 struct epzs_struct *sbdiamond;
00826 struct epzs_struct *pmvfast;
00827
00828
00829
00830 int precalcUnaryLevelTab[128][MAX_PREC_COEFF];
00831 int AdaptRndWeight;
00832 int AdaptRndCrWeight;
00833
00834
00835
00836
00837
00838 byte MBPairIsField;
00839
00840
00841 byte **pixel_map;
00842 byte **refresh_map;
00843 int intras;
00844
00845 int RCMinQP;
00846 int RCMaxQP;
00847
00848 float framerate;
00849 int width;
00850 int width_padded;
00851 int width_blk;
00852 int width_cr;
00853 int height;
00854 int height_padded;
00855 int height_blk;
00856 int height_cr;
00857 int height_cr_frame;
00858 int size;
00859 int size_cr;
00860
00861 int is_v_block;
00862 int mb_y_upd;
00863 int mb_y_intra;
00864 char **ipredmode;
00865 char **ipredmode8x8;
00866 int cod_counter;
00867 int ***nz_coeff;
00868 int pix_x;
00869 int pix_y;
00870
00871
00872 imgpel min_IPCM_value;
00873
00874 int pic_bin_count;
00875
00876
00877 int ****ARCofAdj4x4;
00878 int ****ARCofAdj8x8;
00879
00880
00881 Picture *currentPicture;
00882 struct slice *currentSlice;
00883 Macroblock *mb_data;
00884 Block8x8Info *b8x8info;
00885 int *intra_block;
00886
00887 int frame_no;
00888 int fld_type;
00889 byte fld_flag;
00890 unsigned int rd_pass;
00891
00892 int redundant_coding;
00893 int key_frame;
00894 int redundant_ref_idx;
00895 int frm_no_in_file;
00896 double frame_interval;
00897
00898 int b_frame_to_code;
00899
00900 char DFDisableIdc;
00901 char DFAlphaC0Offset;
00902 char DFBetaOffset;
00903
00904 char direct_spatial_mv_pred_flag;
00905
00906 int pad_size_uv_x;
00907 int pad_size_uv_y;
00908 unsigned char chroma_mask_mv_y;
00909 unsigned char chroma_mask_mv_x;
00910 int chroma_shift_y, chroma_shift_x;
00911 int shift_cr_x, shift_cr_x2, shift_cr_y;
00912 int padded_size_x;
00913 int padded_size_x_m8x8;
00914 int padded_size_x_m4x4;
00915 int cr_padded_size_x;
00916 int cr_padded_size_x_m8;
00917 int cr_padded_size_x2;
00918 int cr_padded_size_x4;
00919
00920 int num_ref_idx_l0_active;
00921 int num_ref_idx_l1_active;
00922
00923 Boolean field_mode;
00924 Boolean top_field;
00925
00926 int buf_cycle;
00927
00928 int layer;
00929
00930 int AdaptiveRounding;
00931
00932 int redundant_pic_cnt;
00933
00934 Boolean MbaffFrameFlag;
00935
00936
00937 unsigned int pic_order_cnt_type;
00938
00939
00940 Boolean delta_pic_order_always_zero_flag;
00941 int offset_for_non_ref_pic;
00942 int offset_for_top_to_bottom_field;
00943 unsigned int num_ref_frames_in_pic_order_cnt_cycle;
00944 int offset_for_ref_frame[1];
00945
00946
00947
00948 unsigned int pic_order_cnt_lsb;
00949 int delta_pic_order_cnt_bottom;
00950
00951 int delta_pic_order_cnt[2];
00952
00953 int frm_iter;
00954
00955 unsigned int field_picture;
00956 signed int toppoc;
00957 signed int bottompoc;
00958 signed int framepoc;
00959 signed int ThisPOC;
00960 unsigned int frame_num;
00961 signed int start_tr_gop;
00962
00963 unsigned int PicWidthInMbs;
00964 unsigned int PicHeightInMapUnits;
00965 unsigned int FrameHeightInMbs;
00966 unsigned int PicSizeInMbs;
00967 unsigned int FrameSizeInMbs;
00968
00969
00970 Boolean bottom_field_pic_order_in_frame_present_flag;
00971
00972
00973
00974 int nal_reference_idc;
00975
00976 int adaptive_ref_pic_buffering_flag;
00977 int no_output_of_prior_pics_flag;
00978 Boolean long_term_reference_flag;
00979
00980 DecRefPicMarking_t *dec_ref_pic_marking_buffer;
00981 int* mvbits;
00982 int* refbits;
00983
00984
00985 int NumberofCodedMacroBlocks;
00986 int BasicUnitQP;
00987 int NumberofMBTextureBits;
00988 int NumberofMBHeaderBits;
00989 unsigned int BasicUnit;
00990 byte write_macroblock;
00991 byte bot_MB;
00992 int write_mbaff_frame;
00993
00994 int DeblockCall;
00995
00996 int last_pic_bottom_field;
00997 int last_has_mmco_5;
00998 int pre_frame_num;
00999
01000 int slice_group_change_cycle;
01001
01002 short bitdepth_luma;
01003 short bitdepth_chroma;
01004 int bitdepth_scale[2];
01005 int bitdepth_luma_qp_scale;
01006 int bitdepth_chroma_qp_scale;
01007 int bitdepth_lambda_scale;
01008 int max_bitCount;
01009 int max_qp_delta;
01010 int min_qp_delta;
01011
01012 LambdaParams **lambda;
01013 double **lambda_md;
01014 double ***lambda_me;
01015 int ***lambda_mf;
01016
01017 double **lambda_mf_factor;
01018
01019 imgpel dc_pred_value_comp[MAX_PLANE];
01020 imgpel dc_pred_value;
01021 int max_pel_value_comp [MAX_PLANE];
01022 int max_imgpel_value_comp_sq [MAX_PLANE];
01023 short max_imgpel_value;
01024
01025 int num_blk8x8_uv;
01026 int num_cdc_coeff;
01027 ColorFormat yuv_format;
01028 int P444_joined;
01029 int lossless_qpprime_flag;
01030 short mb_cr_size_x;
01031 short mb_cr_size_y;
01032 int mb_size[MAX_PLANE][2];
01033
01034 int chroma_qp_offset[2];
01035
01036 int auto_crop_right;
01037 int auto_crop_bottom;
01038
01039 short checkref;
01040 int last_valid_reference;
01041 int bytes_in_picture;
01042
01043 int AverageFrameQP;
01044 int SumFrameQP;
01045 int GopLevels;
01046
01047 int ChromaArrayType;
01048 Macroblock *mb_data_JV[MAX_PLANE];
01049 char colour_plane_id;
01050
01051 int lastIDRnumber;
01052 int lastIntraNumber;
01053 int lastINTRA;
01054 int last_ref_idc;
01055 int idr_refresh;
01056
01057 int p_dec;
01058 int frame_statistic_start;
01059 int initial_Bframes;
01060 int cabac_encoding;
01061
01062 unsigned int primary_pic_type;
01063
01064 int frameOffsetTotal[2][MAX_REFERENCE_PICTURES];
01065 int frameOffsetCount[2][MAX_REFERENCE_PICTURES];
01066 short frameOffset[2][MAX_REFERENCE_PICTURES];
01067 int frameOffsetAvail;
01068
01069 double *mb16x16_cost_frame;
01070 double mb16x16_cost;
01071
01072 int **lrec;
01073 int ***lrec_uv;
01074 Boolean si_frame_indicator;
01075 Boolean sp2_frame_indicator;
01076 int number_sp2_frames;
01077
01078 Boolean giRDOpt_B8OnlyFlag;
01079
01080 int frameNuminGOP;
01081
01082 imgpel **imgY_tmp;
01083 imgpel **imgUV_tmp[2];
01084
01085
01086 int Motion_Selected;
01087
01088
01089 int CbCr_predmode_8x8[4];
01090
01091 int ****motion_cost;
01092
01093 int*** initialized;
01094 int*** modelNumber;
01095
01096 int num_mb_per_slice;
01097 int number_of_slices;
01098
01099 int imgpel_abs_range;
01100 #if (JM_MEM_DISTORTION)
01101 int* imgpel_abs;
01102 int* imgpel_quad;
01103 #endif
01104
01105 GOP_DATA *gop_structure;
01106 byte *MBAmap;
01107 unsigned int PicSizeInMapUnits;
01108 int FirstMBInSlice[MAXSLICEGROUPIDS];
01109
01110 MotionVector* spiral_search;
01111 MotionVector* spiral_hpel_search;
01112 MotionVector* spiral_qpel_search;
01113
01114
01115 FILE *p_log;
01116
01117
01118 FILE *f_annexb;
01119
01120 FILE *f_rtp;
01121 int CurrentRTPTimestamp;
01122
01123 uint16 CurrentRTPSequenceNumber;
01124
01125
01126
01127 struct storable_picture **listX[6];
01128 char listXsize[6];
01129
01130 DistortionParams *p_Dist;
01131 struct stat_parameters *p_Stats;
01132 pic_parameter_set_rbsp_t *PicParSet[MAXPPS];
01133 struct decoded_picture_buffer *p_Dpb;
01134 struct frame_store *out_buffer;
01135 struct storable_picture *enc_picture;
01136 struct storable_picture **enc_frame_picture;
01137 struct storable_picture **enc_field_picture;
01138 struct storable_picture *enc_frame_picture_JV[MAX_PLANE];
01139 struct quant_params *p_Quant;
01140 struct scaling_list *p_QScale;
01141
01142
01143 RCGeneric *p_rc_gen;
01144 RCGeneric *p_rc_gen_init, *p_rc_gen_best;
01145 RCQuadratic *p_rc_quad;
01146 RCQuadratic *p_rc_quad_init, *p_rc_quad_best;
01147
01148 double entropy[128];
01149 double enorm [128];
01150 double probability[128];
01151
01152
01153 FILE *expSFile;
01154 struct exp_seq_info *expSeq;
01155
01156 struct wpx_object *pWPX;
01157
01158 #ifdef BEST_NZ_COEFF
01159 int gaaiMBAFF_NZCoeff[4][12];
01160 #endif
01161
01162 int offset_y, offset_cr;
01163 int wka0, wka1, wka2, wka3, wka4;
01164
01165
01166
01167 int (*updateQP) (struct img_par *p_Img, InputParameters *p_Inp, RCQuadratic *p_quad, RCGeneric *p_gen, int topfield);
01168 void (*rc_update_pict_frame_ptr)(struct img_par *p_Img, InputParameters *p_Inp, RCQuadratic *p_quad, RCGeneric *p_gen, int nbits);
01169 void (*rc_update_picture_ptr) (struct img_par *p_Img, InputParameters *p_Inp, int bits);
01170 void (*rc_init_pict_ptr) (struct img_par *p_Img, InputParameters *p_Inp, RCQuadratic *p_quad, RCGeneric *p_gen, int fieldpic, int topfield, int targetcomputation, float mult);
01171
01172
01173 void (*buf2img) (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int o_size_x, int o_size_y, int symbol_size_in_bytes, int bitshift);
01174 void (*getNeighbour) (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix);
01175 void (*get_mb_block_pos) (int mb_addr, short *x, short *y);
01176 int (*WriteNALU) (struct img_par *p_Img, NALU_t *n);
01177 void (*error_conceal_picture)(struct img_par *p_Img, struct storable_picture *enc_pic, int decoder);
01178
01179
01180 void (*OneComponentChromaPrediction4x4) (Macroblock *currMB, imgpel* , int , int , short*** , struct storable_picture *listX, int );
01181
01182
01183 void (*GetStrength) (byte Strength[16], Macroblock *MbQ, int dir,int edge, int mvlimit);
01184 void (*EdgeLoopLuma) (ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, int dir, int edge, int width);
01185 void (*EdgeLoopChroma)(imgpel** Img, byte Strength[16], Macroblock *MbQ, int dir, int edge, int width, int uv);
01186
01187
01188 void (*EstimateWPBSlice) (struct slice *currSlice);
01189 void (*EstimateWPPSlice) (struct slice *currSlice, int offset);
01190 int (*TestWPPSlice) (struct img_par *p_Img, InputParameters *p_Inp, int offset);
01191 int (*TestWPBSlice) (struct img_par *p_Img, InputParameters *p_Inp, int method);
01192
01193 int (*distortion4x4)(int*, int);
01194 int (*distortion8x8)(int*, int);
01195
01196
01197 int (*computeUniPred[6]) (struct storable_picture *ref1, struct me_block *, int , MotionVector * );
01198 int (*computeBiPred1[3]) (struct storable_picture *ref1, struct storable_picture *ref2, struct me_block*, int , MotionVector *, MotionVector *);
01199 int (*computeBiPred2[3]) (struct storable_picture *ref1, struct storable_picture *ref2, struct me_block*, int , MotionVector *, MotionVector *);
01200 } ImageParameters;
01201
01202
01203 typedef struct pic_motion_params2
01204 {
01205 int64 ref_pic_id;
01206 int64 ref_id;
01207 short mv[2];
01208 char ref_idx;
01209 byte mb_field;
01210 byte field_frame;
01211 } PicMotionParams2;
01212
01213 typedef struct
01214 {
01215 int mb_p8x8_cost;
01216 int smb_p8x8_cost[4];
01217 double smb_p8x8_rdcost[4];
01218 Info8x8 part[4];
01219
01220 int cbp8x8;
01221 int cbp_blk8x8;
01222 int cnt_nonz_8x8;
01223
01224 int **lrec;
01225 imgpel **mpr8x8;
01226 imgpel ***mpr8x8CbCr;
01227 imgpel **rec_mbY8x8;
01228 imgpel ***rec_mb8x8_cr;
01229 } RD_8x8DATA;
01230
01231 typedef struct
01232 {
01233 double lambda_md;
01234 double lambda_me[3];
01235 int lambda_mf[3];
01236 int best_mcost[2];
01237
01238 short valid[MAXMODE];
01239 short curr_mb_field;
01240 } RD_PARAMS;
01241
01242 typedef struct quant_params QuantParameters;
01243 typedef struct quant_methods QuantMethods;
01244 typedef struct scaling_list ScaleParameters;
01245 typedef struct rdo_structure RDOPTStructure;
01246
01247 typedef struct encoder_params
01248 {
01249 InputParameters *p_Inp;
01250 ImageParameters *p_Img;
01251 FILE *p_trace;
01252 int64 bufferSize;
01253 } EncoderParams;
01254
01255 extern EncoderParams *p_Enc;
01256
01257
01258
01259
01260
01261 extern void intrapred_16x16 (Macroblock *currMB, ColorPlane pl);
01262
01263
01264 extern void copyblock_sp (Macroblock *currMB, ColorPlane pl, int pos_mb1,int pos_mb2);
01265 extern int dct_chroma_sp (Macroblock *currMB, int uv,int i11);
01266 extern int dct_chroma_sp2 (Macroblock *currMB, int uv,int i11);
01267
01268
01269
01270 extern int GetDirectCostMB (Macroblock *currMB);
01271 extern int GetDirectCost8x8 (Macroblock *currMB, int, int*);
01272
01273 extern int picture_coding_decision (ImageParameters *p_Img, InputParameters *p_Inp, Picture *picture1, Picture *picture2, int qp);
01274
01275 extern void no_mem_exit (char *where);
01276 extern int get_mem_ACcoeff_new (int****** cofAC, int chroma);
01277 extern int get_mem_ACcoeff (ImageParameters *p_Img, int*****);
01278 extern int get_mem_DCcoeff (int****);
01279 extern void free_mem_ACcoeff (int****);
01280 extern void free_mem_ACcoeff_new (int***** cofAC);
01281 extern void free_mem_DCcoeff (int***);
01282
01283 #if TRACE
01284 extern void trace2out(SyntaxElement *se);
01285 extern void trace2out_cabac(SyntaxElement *se);
01286 #endif
01287
01288 extern void error(char *text, int code);
01289 extern void set_mbaff_parameters(Macroblock *currMB);
01290
01291
01292 extern int CalculateFrameNumber (ImageParameters *p_Img, InputParameters *p_Inp);
01293 extern int is_bipred_enabled (InputParameters *p_Inp, int mode);
01294 extern void update_qp (Macroblock *currMB);
01295 extern void select_plane (ImageParameters *p_Img, ColorPlane color_plane);
01296 extern void select_dct (Macroblock *currMB);
01297 extern void set_slice_type (ImageParameters *p_Img, InputParameters *p_Inp, int slice_type);
01298 extern void free_encoder_memory (ImageParameters *p_Img, InputParameters *p_Inp);
01299 extern void output_SP_coefficients (ImageParameters *p_Img, InputParameters *p_Inp);
01300 extern void read_SP_coefficients (ImageParameters *p_Img, InputParameters *p_Inp);
01301 extern void Init_redundant_frame (ImageParameters *p_Img, InputParameters *p_Inp);
01302 extern void Set_redundant_frame (ImageParameters *p_Img, InputParameters *p_Inp);
01303 extern void encode_one_redundant_frame (ImageParameters *p_Img, InputParameters *p_Inp);
01304
01305
01306
01307 typedef struct
01308 {
01309 imgpel ****luma;
01310 imgpel ****crcb[2];
01311 } SubImageContainer;
01312
01313
01314 extern void change_plane_JV ( ImageParameters *p_Img, int nplane );
01315 extern void make_frame_picture_JV( ImageParameters *p_Img, InputParameters *p_Inp );
01316
01317
01318
01319 short **PicPos;
01320 char errortext[ET_SIZE];
01321
01322 #endif
01323