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
00026
00027
00028
00029
00030
00031 typedef enum
00032 {
00033
00034 PLANE_Y = 0,
00035 PLANE_U = 1,
00036 PLANE_V = 2,
00037
00038 PLANE_G = 0,
00039 PLANE_B = 1,
00040 PLANE_R = 2,
00041 } ColorPlane;
00042
00043
00044 enum {
00045 LIST_0 = 0,
00046 LIST_1 = 1,
00047 BI_PRED = 2,
00048 BI_PRED_L0 = 3,
00049 BI_PRED_L1 = 4
00050 };
00051
00052 enum {
00053 ERROR_SAD = 0,
00054 ERROR_SSE = 1,
00055 ERROR_SATD = 2,
00056 ERROR_PSATD = 3
00057 };
00058
00059 enum {
00060 ME_Y_ONLY = 0,
00061 ME_YUV_FP = 1,
00062 ME_YUV_FP_SP = 2
00063 };
00064
00065 enum {
00066 DISTORTION_MSE = 0
00067 };
00068
00069
00070 typedef enum
00071 {
00072 PAR_DP_1,
00073 PAR_DP_3
00074 } PAR_DP_TYPE;
00075
00076
00077
00078 typedef enum
00079 {
00080 PAR_OF_ANNEXB,
00081 PAR_OF_RTP
00082 } PAR_OF_TYPE;
00083
00084
00085 typedef enum
00086 {
00087 FRAME_CODING,
00088 FIELD_CODING,
00089 ADAPTIVE_CODING,
00090 FRAME_MB_PAIR_CODING
00091 } CodingType;
00092
00093
00094 typedef enum
00095 {
00096 SE_HEADER,
00097 SE_PTYPE,
00098 SE_MBTYPE,
00099 SE_REFFRAME,
00100 SE_INTRAPREDMODE,
00101 SE_MVD,
00102 SE_CBP,
00103 SE_LUM_DC_INTRA,
00104 SE_CHR_DC_INTRA,
00105 SE_LUM_AC_INTRA,
00106 SE_CHR_AC_INTRA,
00107 SE_LUM_DC_INTER,
00108 SE_CHR_DC_INTER,
00109 SE_LUM_AC_INTER,
00110 SE_CHR_AC_INTER,
00111 SE_DELTA_QUANT,
00112 SE_BFRAME,
00113 SE_EOS,
00114 SE_MAX_ELEMENTS
00115 } SE_type;
00116
00117
00118 typedef enum
00119 {
00120 INTER_MB,
00121 INTRA_MB_4x4,
00122 INTRA_MB_16x16
00123 } IntraInterDecision;
00124
00125
00126 typedef enum
00127 {
00128 BITS_HEADER,
00129 BITS_TOTAL_MB,
00130 BITS_MB_MODE,
00131 BITS_INTER_MB,
00132 BITS_CBP_MB,
00133 BITS_COEFF_Y_MB,
00134 BITS_COEFF_UV_MB,
00135 BITS_COEFF_CB_MB,
00136 BITS_COEFF_CR_MB,
00137 BITS_DELTA_QUANT_MB,
00138 BITS_STUFFING,
00139 MAX_BITCOUNTER_MB
00140 } BitCountType;
00141
00142
00143 typedef enum
00144 {
00145 NO_SLICES,
00146 FIXED_MB,
00147 FIXED_RATE,
00148 CALL_BACK,
00149 } SliceMode;
00150
00151
00152 typedef enum
00153 {
00154 CAVLC,
00155 CABAC
00156 } SymbolMode;
00157
00158 typedef enum
00159 {
00160 FULL_SEARCH = -1,
00161 FAST_FULL_SEARCH = 0,
00162 UM_HEX = 1,
00163 UM_HEX_SIMPLE = 2,
00164 EPZS = 3,
00165 } SearchType;
00166
00167
00168 typedef enum
00169 {
00170 FRAME,
00171 TOP_FIELD,
00172 BOTTOM_FIELD
00173 } PictureStructure;
00174
00175 typedef enum
00176 {
00177 P_SLICE = 0,
00178 B_SLICE = 1,
00179 I_SLICE = 2,
00180 SP_SLICE = 3,
00181 SI_SLICE = 4,
00182 NUM_SLICE_TYPES = 5
00183 } SliceType;
00184
00185
00186 typedef enum
00187 {
00188 F_PEL,
00189 H_PEL,
00190 Q_PEL
00191 } MELevel;
00192
00193 typedef enum
00194 {
00195 FAST_ACCESS = 0,
00196 UMV_ACCESS = 1
00197 } REF_ACCESS_TYPE;
00198
00199 typedef enum
00200 {
00201 IS_LUMA = 0,
00202 IS_CHROMA = 1
00203 } Component_Type;
00204
00205 typedef enum
00206 {
00207 RC_MODE_0 = 0,
00208 RC_MODE_1 = 1,
00209 RC_MODE_2 = 2,
00210 RC_MODE_3 = 3
00211 } RCModeType;
00212
00213
00214
00215
00216
00217
00218
00219 typedef struct
00220 {
00221 unsigned int Elow, Erange;
00222 unsigned int Ebuffer;
00223 unsigned int Ebits_to_go;
00224 unsigned int Echunks_outstanding;
00225 int Epbuf;
00226 byte *Ecodestrm;
00227 int *Ecodestrm_len;
00228 int C;
00229 int E;
00230 } EncodingEnvironment;
00231
00232 typedef EncodingEnvironment *EncodingEnvironmentPtr;
00233
00234
00235 typedef struct
00236 {
00237 unsigned long count;
00238 unsigned short state;
00239 unsigned char MPS;
00240 } BiContextType;
00241
00242 typedef BiContextType *BiContextTypePtr;
00243
00244
00245
00246
00247
00248
00249
00250
00251 #define NUM_MB_TYPE_CTX 11
00252 #define NUM_B8_TYPE_CTX 9
00253 #define NUM_MV_RES_CTX 10
00254 #define NUM_REF_NO_CTX 6
00255 #define NUM_DELTA_QP_CTX 4
00256 #define NUM_MB_AFF_CTX 4
00257
00258 #define NUM_TRANSFORM_SIZE_CTX 3
00259
00260 typedef struct
00261 {
00262 BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX];
00263 BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
00264 BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
00265 BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
00266 BiContextType delta_qp_contexts [NUM_DELTA_QP_CTX];
00267 #if ENABLE_FIELD_CTX
00268 BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
00269 #endif
00270 BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
00271 } MotionInfoContexts;
00272
00273
00274 #define NUM_IPR_CTX 2
00275 #define NUM_CIPR_CTX 4
00276 #define NUM_CBP_CTX 4
00277 #define NUM_BCBP_CTX 4
00278 #define NUM_MAP_CTX 15
00279 #define NUM_LAST_CTX 15
00280 #define NUM_ONE_CTX 5
00281 #define NUM_ABS_CTX 5
00282
00283
00284 typedef struct
00285 {
00286 BiContextType ipr_contexts [NUM_IPR_CTX];
00287 BiContextType cipr_contexts[NUM_CIPR_CTX];
00288 BiContextType cbp_contexts [3][NUM_CBP_CTX];
00289 BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
00290 #if ENABLE_FIELD_CTX
00291 BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00292 BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00293 #else
00294 BiContextType map_contexts [1][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00295 BiContextType last_contexts[1][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00296 #endif
00297 BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
00298 BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
00299 } TextureInfoContexts;
00300
00301
00302
00303
00304 typedef struct pix_pos
00305 {
00306 int available;
00307 int mb_addr;
00308 int x;
00309 int y;
00310 int pos_x;
00311 int pos_y;
00312 } PixelPos;
00313
00314
00315 typedef struct DecRefPicMarking_s
00316 {
00317 int memory_management_control_operation;
00318 int difference_of_pic_nums_minus1;
00319 int long_term_pic_num;
00320 int long_term_frame_idx;
00321 int max_long_term_frame_idx_plus1;
00322 struct DecRefPicMarking_s *Next;
00323 } DecRefPicMarking_t;
00324
00325
00326 typedef struct syntaxelement
00327 {
00328 int type;
00329 int value1;
00330 int value2;
00331 int len;
00332 int inf;
00333 unsigned int bitpattern;
00334 int context;
00335
00336 #if TRACE
00337 #define TRACESTRING_SIZE 100
00338 char tracestring[TRACESTRING_SIZE];
00339 #endif
00340
00341
00342 void (*mapping)(int value1, int value2, int* len_ptr, int* info_ptr);
00343
00344 } SyntaxElement;
00345
00346
00347 typedef struct macroblock
00348 {
00349 int mb_nr;
00350 int mb_type;
00351 short slice_nr;
00352 short delta_qp;
00353 int qp;
00354 int qpc[2];
00355 int qp_scaled[MAX_PLANE];
00356 int qpsp ;
00357 int bitcounter[MAX_BITCOUNTER_MB];
00358
00359 int ar_mode;
00360 short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2];
00361 int cbp ;
00362 short b8mode[4];
00363 short b8pdir[4];
00364 int c_ipred_mode;
00365 char IntraChromaPredModeFlag;
00366
00367 byte mb_field;
00368 int is_field_mode;
00369 int list_offset;
00370
00371 int mbAddrA, mbAddrB, mbAddrC, mbAddrD, mbAddrX;
00372 int mbAvailA, mbAvailB, mbAvailC, mbAvailD;
00373
00374 int all_blk_8x8;
00375 int luma_transform_size_8x8_flag;
00376 int NoMbPartLessThan8x8Flag;
00377 int DFDisableIdc;
00378 int DFAlphaC0Offset;
00379 int DFBetaOffset;
00380
00381 int skip_flag;
00382
00383 char intra_pred_modes [MB_BLOCK_PARTITIONS];
00384 char intra_pred_modes8x8[MB_BLOCK_PARTITIONS];
00385
00386 int64 cbp_blk ;
00387 int64 cbp_bits[3];
00388 int64 cbp_bits_8x8[3];
00389
00390 short bipred_me[4];
00391
00392
00393 double actj;
00394 int prev_qp;
00395 int prev_dqp;
00396 int prev_cbp;
00397 Boolean valid_8x8;
00398 Boolean write_mb;
00399
00400
00401 struct macroblock *mb_available_up;
00402 struct macroblock *mb_available_left;
00403 struct macroblock *PrevMB;
00404
00405 } Macroblock;
00406
00407
00408
00409 typedef struct
00410 {
00411 int buffer_size;
00412 int byte_pos;
00413 int bits_to_go;
00414
00415 int stored_byte_pos;
00416 int stored_bits_to_go;
00417 int byte_pos_skip;
00418 int bits_to_go_skip;
00419 int write_flag;
00420
00421 byte byte_buf;
00422 byte stored_byte_buf;
00423 byte byte_buf_skip;
00424 byte *streamBuffer;
00425
00426 #if TRACE
00427 Boolean trace_enabled;
00428 #endif
00429 } Bitstream;
00430
00431
00432 typedef struct datapartition
00433 {
00434 Bitstream *bitstream;
00435 NALU_t *nal_unit;
00436 EncodingEnvironment ee_cabac;
00437 EncodingEnvironment ee_recode;
00438 } DataPartition;
00439
00440
00441 typedef struct
00442 {
00443 int picture_id;
00444 int qp;
00445 int qs;
00446 int picture_type;
00447 int start_mb_nr;
00448 int max_part_nr;
00449 int num_mb;
00450
00451 int ref_pic_list_reordering_flag_l0;
00452 int *reordering_of_pic_nums_idc_l0;
00453 int *abs_diff_pic_num_minus1_l0;
00454 int *long_term_pic_idx_l0;
00455 int ref_pic_list_reordering_flag_l1;
00456 int *reordering_of_pic_nums_idc_l1;
00457 int *abs_diff_pic_num_minus1_l1;
00458 int *long_term_pic_idx_l1;
00459 int field_ctx[3][2];
00460
00461 int symbol_mode;
00462
00463 Boolean (*slice_too_big)(int bits_slice);
00464
00465 DataPartition *partArr;
00466 MotionInfoContexts *mot_ctx;
00467 TextureInfoContexts *tex_ctx;
00468
00469 } Slice;
00470
00471 #define MAXSLICEPERPICTURE 100
00472
00473 enum {
00474 SSE = 0,
00475 SSE_RGB = 1,
00476 PSNR = 2,
00477 PSNR_RGB = 3,
00478 SSIM = 4,
00479 SSIM_RGB = 5,
00480 MS_SSIM = 6,
00481 MS_SSIM_RGB = 7,
00482 TOTAL_DIST_TYPES = 8
00483 } distortion_types;
00484
00485
00486 typedef struct
00487 {
00488 float value[3];
00489 float average[3];
00490 float avslice[NUM_SLICE_TYPES][3];
00491 } DistMetric;
00492
00493 typedef struct
00494 {
00495 int frame_ctr;
00496 DistMetric metric[TOTAL_DIST_TYPES];
00497 } DistortionParams;
00498
00499 typedef struct
00500 {
00501 int no_slices;
00502 int bits_per_picture;
00503 Slice *slices[MAXSLICEPERPICTURE];
00504
00505 DistMetric distortion;
00506 byte idr_flag;
00507 } Picture;
00508
00509 Picture *p_frame_pic;
00510 Picture **frame_pic;
00511 Picture **field_pic;
00512 Picture *frame_pic_si;
00513
00514 #ifdef _LEAKYBUCKET_
00515 long *Bit_Buffer;
00516 unsigned long total_frame_buffer;
00517 #endif
00518
00519
00520 ImageData imgData1;
00521 ImageData imgData;
00522 imgpel **pImgOrg[MAX_PLANE];
00523 imgpel **pCurImg;
00524 int **imgY_sub_tmp;
00525
00526 int **PicPos;
00527 unsigned int log2_max_frame_num_minus4;
00528 unsigned int log2_max_pic_order_cnt_lsb_minus4;
00529 unsigned int max_frame_num;
00530 unsigned int max_pic_order_cnt_lsb;
00531
00532
00533 int64 me_tot_time, me_time;
00534 pic_parameter_set_rbsp_t *active_pps;
00535 seq_parameter_set_rbsp_t *active_sps;
00536
00537
00538 int dsr_new_search_range;
00539
00540
00541
00542 byte MBPairIsField;
00543
00544
00545
00546 int ***wp_weight;
00547 int ***wp_offset;
00548 int ****wbp_weight;
00549 int luma_log_weight_denom;
00550 int chroma_log_weight_denom;
00551 int wp_luma_round;
00552 int wp_chroma_round;
00553
00554 imgpel **imgY_com;
00555 imgpel ***imgUV_com;
00556
00557 char ***direct_ref_idx;
00558 char **direct_pdir;
00559
00560
00561 byte **pixel_map;
00562 byte **refresh_map;
00563 int intras;
00564
00565 int64 tot_time;
00566
00567 #define ET_SIZE 300
00568 char errortext[ET_SIZE];
00569
00570
00571 char b8_ipredmode8x8[4][4], b8_intra_pred_modes8x8[16];
00572
00573
00574 typedef struct
00575 {
00576 double md;
00577 double me[3];
00578 int mf[3];
00579 } LambdaParams;
00580
00581
00582 typedef struct
00583 {
00584 int aspect_ratio_info_present_flag;
00585 int aspect_ratio_idc;
00586 int sar_width;
00587 int sar_height;
00588 int overscan_info_present_flag;
00589 int overscan_appropriate_flag;
00590 int video_signal_type_present_flag;
00591 int video_format;
00592 int video_full_range_flag;
00593 int colour_description_present_flag;
00594 int colour_primaries;
00595 int transfer_characteristics;
00596 int matrix_coefficients;
00597 int chroma_location_info_present_flag;
00598 int chroma_sample_loc_type_top_field;
00599 int chroma_sample_loc_type_bottom_field;
00600 int timing_info_present_flag;
00601 int num_units_in_tick;
00602 int time_scale;
00603 int fixed_frame_rate_flag;
00604 int nal_hrd_parameters_present_flag;
00605 int nal_cpb_cnt_minus1;
00606 int nal_bit_rate_scale;
00607 int nal_cpb_size_scale;
00608 int nal_bit_rate_value_minus1;
00609 int nal_cpb_size_value_minus1;
00610 int nal_vbr_cbr_flag;
00611 int nal_initial_cpb_removal_delay_length_minus1;
00612 int nal_cpb_removal_delay_length_minus1;
00613 int nal_dpb_output_delay_length_minus1;
00614 int nal_time_offset_length;
00615 int vcl_hrd_parameters_present_flag;
00616 int vcl_cpb_cnt_minus1;
00617 int vcl_bit_rate_scale;
00618 int vcl_cpb_size_scale;
00619 int vcl_bit_rate_value_minus1;
00620 int vcl_cpb_size_value_minus1;
00621 int vcl_vbr_cbr_flag;
00622 int vcl_initial_cpb_removal_delay_length_minus1;
00623 int vcl_cpb_removal_delay_length_minus1;
00624 int vcl_dpb_output_delay_length_minus1;
00625 int vcl_time_offset_length;
00626 int low_delay_hrd_flag;
00627 int pic_struct_present_flag;
00628 int bitstream_restriction_flag;
00629 int motion_vectors_over_pic_boundaries_flag;
00630 int max_bytes_per_pic_denom;
00631 int max_bits_per_mb_denom;
00632 int log2_max_mv_length_vertical;
00633 int log2_max_mv_length_horizontal;
00634 int num_reorder_frames;
00635 int max_dec_frame_buffering;
00636 } VUIParameters;
00637
00638
00639 typedef struct
00640 {
00641 short best8x8mode [4];
00642 char best8x8pdir [MAXMODE][4];
00643 char best8x8l0ref [MAXMODE][4];
00644 char best8x8l1ref [MAXMODE][4];
00645 short bipred8x8me [MAXMODE][4];
00646 } Block8x8Info;
00647
00648
00649
00650 typedef struct
00651 {
00652 int ProfileIDC;
00653 int LevelIDC;
00654 int IntraProfile;
00655
00656 int no_frm_base;
00657 int no_frames;
00658 int qp[2][NUM_SLICE_TYPES];
00659 int qpsp[2];
00660 int frame_skip;
00661 int jumpd;
00662
00663 int DisableSubpelME;
00664 int search_range;
00665
00666 int num_ref_frames;
00667 int P_List0_refs;
00668 int B_List0_refs;
00669 int B_List1_refs;
00670 int Log2MaxFNumMinus4;
00671 int Log2MaxPOCLsbMinus4;
00672
00673
00674 FrameFormat source;
00675 FrameFormat output;
00676 int rgb_input_flag;
00677 int is_interleaved;
00678 int src_resize;
00679 int src_BitDepthRescale;
00680 int yuv_format;
00681 int intra_upd;
00682
00683
00684
00685 int blc_size[8][2];
00686 int part_size[8][2];
00687
00688 int slice_mode;
00689 int slice_argument;
00690 int UseConstrainedIntraPred;
00691 int infile_header;
00692 VideoDataFile input_file1;
00693 char outfile [FILE_NAME_SIZE];
00694 char ReconFile [FILE_NAME_SIZE];
00695 char TraceFile [FILE_NAME_SIZE];
00696 char StatsFile [FILE_NAME_SIZE];
00697 char QmatrixFile [FILE_NAME_SIZE];
00698 int ProcessInput;
00699 int EnableOpenGOP;
00700 int EnableIDRGOP;
00701 int grayscale;
00702
00703 int idr_period;
00704 int intra_period;
00705 int intra_delay;
00706 int adaptive_idr_period;
00707 int adaptive_intra_period;
00708
00709 int start_frame;
00710
00711 int GenerateMultiplePPS;
00712 int GenerateSEIMessage;
00713 char SEIMessageText[INPUT_TEXT_SIZE];
00714
00715 int ResendSPS;
00716 int ResendPPS;
00717
00718 int SendAUD;
00719 int skip_gl_stats;
00720
00721
00722 int NumberBFrames;
00723 int PReplaceBSlice;
00724 int qpBRSOffset[2];
00725 int direct_spatial_mv_pred_flag;
00726 int directInferenceFlag;
00727
00728 int BiPredMotionEstimation;
00729 int BiPredSearch[4];
00730 int BiPredMERefinements;
00731 int BiPredMESearchRange;
00732 int BiPredMESubPel;
00733
00734
00735 int sp_periodicity;
00736
00737 int si_frame_indicator;
00738 int sp2_frame_indicator;
00739 int sp_output_indicator;
00740 char sp_output_filename[FILE_NAME_SIZE];
00741 char sp2_input_filename1[FILE_NAME_SIZE];
00742 char sp2_input_filename2[FILE_NAME_SIZE];
00743
00744
00745 int WeightedPrediction;
00746 int WeightedBiprediction;
00747 int WPMethod;
00748 int WPIterMC;
00749 int WPMCPrecision;
00750 int WPMCPrecFullRef;
00751 int WPMCPrecBSlice;
00752 int EnhancedBWeightSupport;
00753 int ChromaWeightSupport;
00754 int UseWeightedReferenceME;
00755 int RDPictureDecision;
00756 int RDPictureIntra;
00757 int RDPSliceWeightOnly;
00758 int RDPSliceBTest;
00759 int RDBSliceWeightOnly;
00760 int SkipIntraInInterSlices;
00761 int BRefPictures;
00762 int HierarchicalCoding;
00763 int HierarchyLevelQPEnable;
00764 char ExplicitHierarchyFormat[INPUT_TEXT_SIZE];
00765
00766 int ExplicitSeqCoding;
00767 char ExplicitSeqFile[FILE_NAME_SIZE];
00768 int ReferenceReorder;
00769 int PocMemoryManagement;
00770
00771 int symbol_mode;
00772 int of_mode;
00773 int partition_mode;
00774
00775 int InterSearch[2][8];
00776
00777 int DisableIntra4x4;
00778 int DisableIntra16x16;
00779 int FastMDEnable;
00780 int FastIntraMD;
00781 int FastIntra4x4;
00782 int FastIntra16x16;
00783 int FastIntra8x8;
00784 int FastIntraChroma;
00785 int DisableIntraInInter;
00786 int IntraDisableInterOnly;
00787 int Intra4x4ParDisable;
00788 int Intra4x4DiagDisable;
00789 int Intra4x4DirDisable;
00790 int Intra16x16ParDisable;
00791 int Intra16x16PlaneDisable;
00792 int ChromaIntraDisable;
00793
00794 int EnableIPCM;
00795
00796 double FrameRate;
00797
00798 int chroma_qp_index_offset;
00799 int full_search;
00800 int last_frame;
00801
00802 int qp2start;
00803
00804 int rdopt;
00805 int Distortion[TOTAL_DIST_TYPES];
00806 double VisualResWavPSNR;
00807 int SSIMOverlapSize;
00808 int DistortionYUVtoRGB;
00809 int CtxAdptLagrangeMult;
00810 int FastCrIntraDecision;
00811 int disthres;
00812 int nobskip;
00813
00814 #ifdef _LEAKYBUCKET_
00815 int NumberLeakyBuckets;
00816 char LeakyBucketRateFile[FILE_NAME_SIZE];
00817 char LeakyBucketParamFile[FILE_NAME_SIZE];
00818 #endif
00819
00820 int PicInterlace;
00821 int MbInterlace;
00822 int IntraBottom;
00823
00824
00825 int LossRateA;
00826 int LossRateB;
00827 int LossRateC;
00828 int NoOfDecoders;
00829 int ErrorConcealment;
00830 int RestrictRef;
00831 int NumFramesInELSubSeq;
00832
00833 int RandomIntraMBRefresh;
00834
00835
00836 int ChromaMCBuffer;
00837 int ChromaMEEnable;
00838 int ChromaMEWeight;
00839 int MEErrorMetric[3];
00840 int ModeDecisionMetric;
00841 int SkipDeBlockNonRef;
00842
00843
00844 int DFSendParameters;
00845 int DFDisableIdc[2][NUM_SLICE_TYPES];
00846 int DFAlpha [2][NUM_SLICE_TYPES];
00847 int DFBeta [2][NUM_SLICE_TYPES];
00848
00849 int SparePictureOption;
00850 int SPDetectionThreshold;
00851 int SPPercentageThreshold;
00852
00853
00854 char SliceGroupConfigFileName[FILE_NAME_SIZE];
00855 int num_slice_groups_minus1;
00856 int slice_group_map_type;
00857
00858 int *top_left;
00859 int *bottom_right;
00860 byte *slice_group_id;
00861 int *run_length_minus1;
00862
00863 int slice_group_change_direction_flag;
00864 int slice_group_change_rate_minus1;
00865 int slice_group_change_cycle;
00866
00867 int redundant_pic_flag;
00868 int pic_order_cnt_type;
00869
00870 int context_init_method;
00871 int model_number;
00872 int Transform8x8Mode;
00873 int ReportFrameStats;
00874 int DisplayEncParams;
00875 int Verbose;
00876
00877
00878 int RCEnable;
00879 int bit_rate;
00880 int SeinitialQP;
00881 unsigned int basicunit;
00882 int channel_type;
00883 int RCUpdateMode;
00884 double RCIoverPRatio;
00885 double RCBoverPRatio;
00886 double RCISliceBitRatio;
00887 double RCBSliceBitRatio[RC_MAX_TEMPORAL_LEVELS];
00888 int RCMinQP[NUM_SLICE_TYPES];
00889 int RCMaxQP[NUM_SLICE_TYPES];
00890 int RCMaxQPChange;
00891
00892
00893 int UseMVLimits;
00894 int SetMVXLimit;
00895 int SetMVYLimit;
00896
00897
00898 SearchType SearchMode;
00899
00900
00901 int UMHexDSR;
00902 int UMHexScale;
00903
00904
00905 int EPZSPattern;
00906 int EPZSDual;
00907 int EPZSFixed;
00908 int EPZSTemporal;
00909 int EPZSSpatialMem;
00910 int EPZSBlockType;
00911 int EPZSMinThresScale;
00912 int EPZSMaxThresScale;
00913 int EPZSMedThresScale;
00914 int EPZSSubPelGrid;
00915 int EPZSGrid;
00916 int EPZSSubPelME;
00917 int EPZSSubPelMEBiPred;
00918 int EPZSSubPelThresScale;
00919
00920
00921 int UseExplicitLambdaParams;
00922 int UpdateLambdaChromaME;
00923 double LambdaWeight[6];
00924 double FixedLambda[6];
00925
00926 char QOffsetMatrixFile[FILE_NAME_SIZE];
00927 int OffsetMatrixPresentFlag;
00928
00929 int AdaptiveRounding;
00930 int AdaptRoundingFixed;
00931 int AdaptRndPeriod;
00932 int AdaptRndChroma;
00933 int AdaptRndWFactor [2][NUM_SLICE_TYPES];
00934 int AdaptRndCrWFactor[2][NUM_SLICE_TYPES];
00935
00936
00937
00938 int ScalingMatrixPresentFlag;
00939 int ScalingListPresentFlag[12];
00940
00941 int cb_qp_index_offset;
00942 int cr_qp_index_offset;
00943
00944 int LosslessCoding;
00945
00946
00947 int EarlySkipEnable;
00948 int SelectiveIntraEnable;
00949 int DisposableP;
00950 int DispPQPOffset;
00951
00952
00953 int NumRedundantHierarchy;
00954 int PrimaryGOPLength;
00955 int NumRefPrimary;
00956
00957
00958 int ToneMappingSEIPresentFlag;
00959 char ToneMappingFile[FILE_NAME_SIZE];
00960
00961 int separate_colour_plane_flag;
00962 double WeightY;
00963 double WeightCb;
00964 double WeightCr;
00965 int UseRDOQuant;
00966 int RDOQ_DC;
00967 int RDOQ_CR;
00968 int RDOQ_DC_CR;
00969 int RDOQ_QP_Num;
00970 int RDOQ_CP_Mode;
00971 int RDOQ_CP_MV;
00972 int RDOQ_Fast;
00973
00974 int EnableVUISupport;
00975
00976 VUIParameters VUI;
00977
00978
00979 } InputParameters;
00980
00981
00982 typedef struct
00983 {
00984 int number;
00985 int start_frame_no;
00986 int gop_number;
00987 int frm_number;
00988 int cur_frm_number;
00989 int last_idr_number;
00990 int idr_gop_number;
00991 int rewind_frame;
00992 int pn;
00993 int LevelIndex;
00994 int MaxVmvR[6];
00995 int MaxHmvR[6];
00996 int current_mb_nr;
00997 int current_slice_nr;
00998 int type;
00999 int structure;
01000 int base_dist;
01001 int num_ref_frames;
01002 int max_num_references;
01003 int masterQP;
01004 int qp;
01005 int qpsp;
01006
01007 int RCMinQP;
01008 int RCMaxQP;
01009
01010 float framerate;
01011 int width;
01012 int width_padded;
01013 int width_blk;
01014 int width_cr;
01015 int height;
01016 int height_padded;
01017 int height_blk;
01018 int height_cr;
01019 int height_cr_frame;
01020 int size;
01021 int size_cr;
01022 int subblock_x;
01023 int subblock_y;
01024 int is_intra_block;
01025 int is_v_block;
01026 int mb_y_upd;
01027 int mb_y_intra;
01028 int block_c_x;
01029 char **ipredmode;
01030 char **ipredmode8x8;
01031 int cod_counter;
01032 int ***nz_coeff;
01033
01034 int mb_x;
01035 int mb_y;
01036 int block_x;
01037 int block_y;
01038 int pix_x;
01039 int pix_y;
01040 int pix_c_x;
01041 int pix_c_y;
01042
01043 int opix_x;
01044 int opix_y;
01045 int opix_c_x;
01046 int opix_c_y;
01047
01048 int ***mb_rres;
01049 int ***mb_ores;
01050 int **curr_res;
01051 imgpel ****mpr_4x4;
01052 imgpel ****mpr_8x8;
01053 imgpel ****mpr_16x16;
01054 imgpel ***mb_pred;
01055 imgpel **curr_prd;
01056 imgpel min_IPCM_value;
01057
01058 int ****cofAC;
01059 int *****cofAC_new;
01060 int *** cofDC;
01061
01062
01063 int ****ARCofAdj4x4;
01064 int ****ARCofAdj8x8;
01065
01066 Picture *currentPicture;
01067 Slice *currentSlice;
01068 Macroblock *mb_data;
01069 Block8x8Info *b8x8info;
01070 int *quad;
01071 int *intra_block;
01072
01073 int frame_no;
01074 int fld_type;
01075 byte fld_flag;
01076 unsigned int rd_pass;
01077
01078 int frm_no_in_file;
01079 double frame_interval;
01080
01081 int b_frame_to_code;
01082 int fw_mb_mode;
01083 int bw_mb_mode;
01084
01085 short****** pred_mv;
01086 short****** all_mv;
01087 short******* bipred_mv;
01088
01089 int DFDisableIdc;
01090 int DFAlphaC0Offset;
01091 int DFBetaOffset;
01092
01093 int direct_spatial_mv_pred_flag;
01094
01095 int num_ref_idx_active_list[2];
01096 int num_ref_idx_l0_active;
01097 int num_ref_idx_l1_active;
01098
01099 byte field_mode;
01100 byte top_field;
01101 int mvscale[6][MAX_REFERENCE_PICTURES];
01102 int buf_cycle;
01103 int i16offset;
01104
01105 int layer;
01106
01107 int NoResidueDirect;
01108 int AdaptiveRounding;
01109
01110 int redundant_pic_cnt;
01111
01112 int MbaffFrameFlag;
01113
01114
01115 unsigned int pic_order_cnt_type;
01116
01117
01118 Boolean delta_pic_order_always_zero_flag;
01119 int offset_for_non_ref_pic;
01120 int offset_for_top_to_bottom_field;
01121 unsigned int num_ref_frames_in_pic_order_cnt_cycle;
01122 int offset_for_ref_frame[1];
01123
01124
01125
01126 unsigned int pic_order_cnt_lsb;
01127 int delta_pic_order_cnt_bottom;
01128
01129 int delta_pic_order_cnt[2];
01130
01131 int frm_iter;
01132
01133 unsigned int field_picture;
01134 signed int toppoc;
01135 signed int bottompoc;
01136 signed int framepoc;
01137 signed int ThisPOC;
01138 unsigned int frame_num;
01139 signed int start_tr_gop;
01140
01141 unsigned int PicWidthInMbs;
01142 unsigned int PicHeightInMapUnits;
01143 unsigned int FrameHeightInMbs;
01144 unsigned int PicSizeInMbs;
01145 unsigned int FrameSizeInMbs;
01146
01147
01148 Boolean pic_order_present_flag;
01149
01150
01151
01152 int nal_reference_idc;
01153
01154 int adaptive_ref_pic_buffering_flag;
01155 int no_output_of_prior_pics_flag;
01156 int long_term_reference_flag;
01157
01158 DecRefPicMarking_t *dec_ref_pic_marking_buffer;
01159
01160 int model_number;
01161
01162
01163 int NumberofCodedMacroBlocks;
01164 int BasicUnitQP;
01165 int NumberofMBTextureBits;
01166 int NumberofMBHeaderBits;
01167 unsigned int BasicUnit;
01168 byte write_macroblock;
01169 byte bot_MB;
01170 int write_mbaff_frame;
01171
01172 int DeblockCall;
01173
01174 int last_pic_bottom_field;
01175 int last_has_mmco_5;
01176 int pre_frame_num;
01177
01178 int slice_group_change_cycle;
01179
01180 int pic_unit_size_on_disk;
01181 int out_unit_size_on_disk;
01182 int bitdepth_luma;
01183 int bitdepth_chroma;
01184 int bitdepth_scale[2];
01185 int bitdepth_luma_qp_scale;
01186 int bitdepth_chroma_qp_scale;
01187 int bitdepth_lambda_scale;
01188 int max_bitCount;
01189 int max_qp_delta;
01190 int min_qp_delta;
01191
01192 LambdaParams **lambda;
01193 double **lambda_md;
01194 double ***lambda_me;
01195 int ***lambda_mf;
01196
01197 double **lambda_mf_factor;
01198
01199 unsigned int dc_pred_value_comp[MAX_PLANE];
01200 unsigned int dc_pred_value;
01201 int max_imgpel_value_comp [MAX_PLANE];
01202 int max_imgpel_value_comp_sq [MAX_PLANE];
01203 int max_imgpel_value;
01204
01205 int num_blk8x8_uv;
01206 int num_cdc_coeff;
01207 int yuv_format;
01208 int P444_joined;
01209 int lossless_qpprime_flag;
01210 int mb_cr_size_x;
01211 int mb_cr_size_y;
01212 int mb_size[MAX_PLANE][2];
01213
01214 int chroma_qp_offset[2];
01215
01216 int auto_crop_right;
01217 int auto_crop_bottom;
01218
01219 short checkref;
01220 int last_valid_reference;
01221 int bytes_in_picture;
01222
01223 int AverageFrameQP;
01224 int SumFrameQP;
01225 int GopLevels;
01226
01227 int ChromaArrayType;
01228 Macroblock *mb_data_JV[MAX_PLANE];
01229 int colour_plane_id;
01230
01231 int lastIDRnumber;
01232 int lastIntraNumber;
01233 int lastINTRA;
01234 int last_ref_idc;
01235 int idr_refresh;
01236
01237 unsigned int primary_pic_type;
01238
01239 int frameOffsetTotal[2][MAX_REFERENCE_PICTURES];
01240 int frameOffsetCount[2][MAX_REFERENCE_PICTURES];
01241 int frameOffset[2][MAX_REFERENCE_PICTURES];
01242 int frameOffsetAvail;
01243
01244 } ImageParameters;
01245
01246
01247
01248 typedef struct pic_motion_params2
01249 {
01250 int64 ref_pic_id;
01251 int64 ref_id;
01252 short mv[2];
01253 char ref_idx;
01254 byte mb_field;
01255 byte field_frame;
01256 } PicMotionParams2;
01257
01258
01259 typedef struct
01260 {
01261 short mv_x;
01262 short mv_y;
01263 } MotionVector;
01264
01265
01266
01267 typedef struct
01268 {
01269 double min_rdcost;
01270 double min_dcost;
01271
01272 imgpel **rec_mbY;
01273 imgpel ***rec_mb_cr;
01274 int ****cofAC;
01275 int ***cofDC;
01276 int *****cofAC_new;
01277 int mb_type;
01278 int cbp;
01279 int mode;
01280 int i16offset;
01281 int c_ipred_mode;
01282 int luma_transform_size_8x8_flag;
01283 int NoMbPartLessThan8x8Flag;
01284
01285 int qp;
01286 int prev_qp;
01287 int prev_dqp;
01288 int prev_cbp;
01289 short delta_qp;
01290 short b8mode[4], b8pdir[4];
01291
01292 int64 cbp_blk;
01293 short ******pred_mv;
01294 short ******all_mv;
01295
01296 char intra_pred_modes[16];
01297 char intra_pred_modes8x8[16];
01298 char **ipredmode;
01299 char ***refar;
01300 } RD_DATA;
01301
01302
01303
01304
01305 typedef struct
01306 {
01307 int slice_type;
01308 int display_no;
01309 int reference_idc;
01310 int slice_qp;
01311 int hierarchy_layer;
01312 int hierarchyPocDelta;
01313 } GOP_DATA;
01314
01315
01316 typedef struct
01317 {
01318 double smb_p8x8_rdcost[4];
01319 int mb_p8x8_cost;
01320 int smb_p8x8_cost[4];
01321 int cbp8x8;
01322 int cbp_blk8x8;
01323 int cnt_nonz_8x8;
01324 short part8x8mode[4];
01325 short part8x8bipred[4];
01326 char part8x8pdir[4];
01327 char part8x8l0ref[4];
01328 char part8x8l1ref[4];
01329 int **lrec;
01330 imgpel **mpr8x8;
01331 imgpel ***mpr8x8CbCr;
01332 imgpel **rec_mbY8x8;
01333 imgpel ***rec_mb8x8_cr;
01334 } RD_8x8DATA;
01335
01336
01337 typedef struct
01338 {
01339 double lambda_md;
01340 double lambda_me[3];
01341 int lambda_mf[3];
01342 int best_mcost[2];
01343
01344 short valid[MAXMODE];
01345 short list_offset[2];
01346 short curr_mb_field;
01347 } RD_PARAMS;
01348
01349 GOP_DATA *gop_structure;
01350 RD_DATA *rdopt;
01351 RD_DATA rddata_top_frame_mb, rddata_bot_frame_mb;
01352 RD_DATA rddata_top_field_mb, rddata_bot_field_mb;
01353
01354 RD_DATA rddata_trellis_best, rddata_trellis_curr;
01355 short *****tmp_mv8, *****tmp_pmv8;
01356 int ***motion_cost8;
01357
01358 extern InputParameters *params;
01359 extern ImageParameters *img;
01360
01361 extern DistortionParams *dist;
01362
01363
01364 FILE *p_log;
01365 FILE *p_trace;
01366 int p_dec;
01367
01368 int coeff_cost_cr[MAX_PLANE];
01369 int cmp_cbp[3], i16x16mode, curr_cbp[2];
01370 int64 cur_cbp_blk[MAX_PLANE];
01371 int CbCr_predmode_8x8[4];
01372
01373
01374
01375
01376
01377
01378 void intrapred_4x4 (Macroblock *currMB, ColorPlane pl, int CurrPixX,int CurrPixY, int *left_available, int *up_available, int *all_available);
01379 void intrapred_16x16 (Macroblock *currMB, ColorPlane pl);
01380
01381 int (*pDCT_4x4) (Macroblock *currMB, ColorPlane pl, int block_x, int block_y, int *coeff_cost, int intra, int is_cavlc);
01382 int (*pDCT_16x16) (Macroblock *currMB, ColorPlane pl, int, int is_cavlc);
01383 int (*pDCT_8x8) (Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra);
01384 int (*dct_cr_4x4[2])(Macroblock *currMB, int uv,int i11, int is_cavlc);
01385
01386 int dct_8x8 (Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra);
01387 int dct_8x8_cavlc (Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra);
01388 int dct_8x8_ls (Macroblock *currMB, ColorPlane pl, int b8, int *coeff_cost, int intra);
01389
01390 void copyblock_sp (Macroblock *currMB, ColorPlane pl, int pos_mb1,int pos_mb2);
01391 int dct_chroma_sp (Macroblock *currMB, int uv,int i11, int is_cavlc);
01392 int dct_chroma_sp2 (Macroblock *currMB, int uv,int i11, int is_cavlc);
01393
01394
01395 int distortion4x4(int*);
01396 int distortion8x8(int*);
01397
01398 extern int* refbits;
01399 extern int**** motion_cost;
01400 double *mb16x16_cost_frame;
01401
01402 void FindSkipModeMotionVector (Macroblock *currMB);
01403 void Get_Direct_Motion_Vectors (Macroblock *currMB);
01404 void PartitionMotionSearch (Macroblock *currMB, int, int, int*);
01405 int BIDPartitionCost (Macroblock *currMB, int, int, char[2], int);
01406 int BPredPartitionCost (Macroblock *currMB, int, int, short, short, int, int);
01407 int GetDirectCostMB (Macroblock *currMB, int bslice);
01408 int GetDirectCost8x8 (Macroblock *currMB, int, int*);
01409
01410
01411 void poc_based_ref_management_frame_pic(int current_pic_num);
01412 void poc_based_ref_management_field_pic(int current_pic_num);
01413
01414 int picture_coding_decision (Picture *picture1, Picture *picture2, int qp);
01415
01416 unsigned CeilLog2( unsigned uiVal);
01417
01418
01419
01420 int init_global_buffers(void);
01421 void free_global_buffers(void);
01422 void no_mem_exit (char *where);
01423
01424 void free_img (void);
01425
01426 int get_mem_ACcoeff_new (int****** cofAC, int chroma);
01427 int get_mem_ACcoeff (int*****);
01428 int get_mem_DCcoeff (int****);
01429 void free_mem_ACcoeff (int****);
01430 void free_mem_ACcoeff_new (int***** cofAC);
01431 void free_mem_DCcoeff (int***);
01432
01433 #if TRACE
01434 void trace2out(SyntaxElement *se);
01435 void trace2out_cabac(SyntaxElement *se);
01436 #endif
01437
01438 void error(char *text, int code);
01439
01440 byte field_flag_inference(Macroblock *currMB);
01441 void set_mbaff_parameters(Macroblock *currMB);
01442
01443
01444 void UpdatePixelMap(void);
01445
01446 int64 compute_SSE(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, int ySize, int xSize);
01447
01448 int CalculateFrameNumber(ImageParameters *img);
01449
01450 void encode_one_macroblock_low (Slice *currSlice, Macroblock *currMB);
01451 void encode_one_macroblock_high (Slice *currSlice, Macroblock *currMB);
01452 void encode_one_macroblock_highfast (Slice *currSlice, Macroblock *currMB);
01453 void encode_one_macroblock_highloss (Slice *currSlice, Macroblock *currMB);
01454 void (*encode_one_macroblock) (Slice *currSlice, Macroblock *currMB);
01455
01456 int is_bipred_enabled(int mode);
01457
01458 void update_qp (ImageParameters *img, Macroblock *currMB);
01459 void select_plane (ColorPlane color_plane);
01460 void select_dct (ImageParameters *img, Macroblock *currMB);
01461
01462 void store_coding_state_cs_cm(Slice *currSlice, Macroblock *currMB);
01463 void reset_coding_state_cs_cm(Slice *currSlice, Macroblock *currMB);
01464
01465 void set_slice_type(ImageParameters *img, int slice_type);
01466
01467 void free_encoder_memory(ImageParameters *img);
01468
01469 int check_for_SI16(void);
01470 int **lrec ;
01471 int ***lrec_uv;
01472 int si_frame_indicator;
01473
01474 int sp2_frame_indicator;
01475 int number_sp2_frames;
01476
01477 void output_SP_coefficients(void);
01478 void read_SP_coefficients(void);
01479
01480 int giRDOpt_B8OnlyFlag;
01481
01482 #ifdef BEST_NZ_COEFF
01483 int gaaiMBAFF_NZCoeff[4][12];
01484 #endif
01485
01486
01487 imgpel **imgY_tmp;
01488 imgpel **imgUV_tmp[2];
01489 int frameNuminGOP;
01490 int redundant_coding;
01491 int key_frame;
01492 int redundant_ref_idx;
01493 void Init_redundant_frame(void);
01494 void Set_redundant_frame(void);
01495 void encode_one_redundant_frame(void);
01496
01497 int img_pad_size_uv_x;
01498 int img_pad_size_uv_y;
01499
01500 unsigned char chroma_mask_mv_y;
01501 unsigned char chroma_mask_mv_x;
01502 int chroma_shift_y, chroma_shift_x;
01503 int shift_cr_x, shift_cr_x2, shift_cr_y;
01504 int img_padded_size_x;
01505 int img_padded_size_x2;
01506 int img_padded_size_x4;
01507 int img_padded_size_x_m8;
01508 int img_padded_size_x_m8x8;
01509 int img_padded_size_x_m4x4;
01510 int img_cr_padded_size_x;
01511 int img_cr_padded_size_x_m8;
01512 int img_cr_padded_size_x2;
01513 int img_cr_padded_size_x4;
01514
01515
01516 typedef struct
01517 {
01518 imgpel ****luma;
01519 imgpel ****crcb[2];
01520 } SubImageContainer;
01521
01522 int start_me_refinement_hp;
01523 int start_me_refinement_qp;
01524
01525
01526 int ipmode_DPCM;
01527 int lossless_res[4][4];
01528
01529
01530 void change_plane_JV( int nplane );
01531 void make_frame_picture_JV(void);
01532
01533 int Motion_Selected;
01534 int Intra_Selected;
01535
01536 #endif
01537