00001
00026 #ifndef _GLOBAL_H_
00027 #define _GLOBAL_H_
00028
00029 #include <stdlib.h>
00030 #include <stdarg.h>
00031 #include <string.h>
00032 #include <assert.h>
00033 #include <time.h>
00034 #include <sys/timeb.h>
00035
00036 #include "win32.h"
00037 #include "defines.h"
00038 #include "ifunctions.h"
00039 #include "parsetcommon.h"
00040
00041
00042 pic_parameter_set_rbsp_t *active_pps;
00043 seq_parameter_set_rbsp_t *active_sps;
00044
00045
00046 imgpel **imgY_ref;
00047 imgpel ***imgUV_ref;
00048
00049 int **PicPos;
00050 int ReMapRef[20];
00051
00052 int Bframe_ctr;
00053 int frame_no;
00054
00055 int g_nFrame;
00056
00057
00058 int TopFieldForSkip_Y[16][16];
00059 int TopFieldForSkip_UV[2][16][16];
00060
00061 #define ET_SIZE 300
00062 char errortext[ET_SIZE];
00063
00064
00065
00066
00067
00068
00070 typedef enum {
00071 YUV_UNKNOWN = -1,
00072 YUV400 = 0,
00073 YUV420 = 1,
00074 YUV422 = 2,
00075 YUV444 = 3,
00076 } ColorFormat;
00077
00079 typedef enum
00080 {
00081 PAR_DP_1,
00082 PAR_DP_3
00083 } PAR_DP_TYPE;
00084
00085
00087 typedef enum
00088 {
00089 PAR_OF_ANNEXB,
00090 PAR_OF_RTP
00091 } PAR_OF_TYPE;
00092
00093
00095 typedef enum
00096 {
00097 SE_HEADER,
00098 SE_PTYPE,
00099 SE_MBTYPE,
00100 SE_REFFRAME,
00101 SE_INTRAPREDMODE,
00102 SE_MVD,
00103 SE_CBP_INTRA,
00104 SE_LUM_DC_INTRA,
00105 SE_CHR_DC_INTRA,
00106 SE_LUM_AC_INTRA,
00107 SE_CHR_AC_INTRA,
00108 SE_CBP_INTER,
00109 SE_LUM_DC_INTER,
00110 SE_CHR_DC_INTER,
00111 SE_LUM_AC_INTER,
00112 SE_CHR_AC_INTER,
00113 SE_DELTA_QUANT_INTER,
00114 SE_DELTA_QUANT_INTRA,
00115 SE_BFRAME,
00116 SE_EOS,
00117 SE_MAX_ELEMENTS
00118 } SE_type;
00119
00120
00121 typedef enum
00122 {
00123 INTER_MB,
00124 INTRA_MB_4x4,
00125 INTRA_MB_16x16
00126 } IntraInterDecision;
00127
00128 typedef enum
00129 {
00130 BITS_HEADER = 0,
00131 BITS_TOTAL_MB = 1,
00132 BITS_MB_MODE = 2,
00133 BITS_INTER_MB = 3,
00134 BITS_CBP_MB = 4,
00135 BITS_COEFF_Y_MB = 5,
00136 BITS_COEFF_CB_MB = 6,
00137 BITS_COEFF_CR_MB = 7,
00138 BITS_DELTA_QUANT_MB = 8,
00139 BITS_STUFFING = 9,
00140 MAX_BITCOUNTER_MB = 10
00141 } BitCountType;
00142
00143 typedef enum
00144 {
00145 NO_SLICES,
00146 FIXED_MB,
00147 FIXED_RATE,
00148 CALL_BACK
00149 } SliceMode;
00150
00151 typedef enum
00152 {
00153 UVLC,
00154 CABAC
00155 } SymbolMode;
00156
00157 typedef enum
00158 {
00159 LIST_0 = 0,
00160 LIST_1 = 1,
00161 BI_PRED = 2
00162 } Lists;
00163
00164
00165 typedef enum
00166 {
00167 FRAME,
00168 TOP_FIELD,
00169 BOTTOM_FIELD
00170 } PictureStructure;
00171
00172 typedef enum
00173 {
00174
00175 PLANE_Y = 0,
00176 PLANE_U = 1,
00177 PLANE_V = 2,
00178
00179 PLANE_G = 0,
00180 PLANE_B = 1,
00181 PLANE_R = 2
00182 } ColorPlane;
00183
00184
00185 typedef enum
00186 {
00187 P_SLICE = 0,
00188 B_SLICE,
00189 I_SLICE,
00190 SP_SLICE,
00191 SI_SLICE
00192 } SliceType;
00193
00194 typedef enum
00195 {
00196 IS_LUMA = 0,
00197 IS_CHROMA = 1
00198 } Component_Type;
00199
00200 typedef enum
00201 {
00202 LumaComp = 0,
00203 CrComp = 1,
00204 CbComp = 2
00205 } Color_Component;
00206
00207
00208
00209
00210
00211
00213 typedef struct
00214 {
00215 unsigned int Drange;
00216 unsigned int Dvalue;
00217 int DbitsLeft;
00218 byte *Dcodestrm;
00219 int *Dcodestrm_len;
00220 } DecodingEnvironment;
00221
00222 typedef DecodingEnvironment *DecodingEnvironmentPtr;
00223
00225 typedef struct
00226 {
00227 unsigned short state;
00228 unsigned char MPS;
00229 unsigned char dummy;
00230 } BiContextType;
00231
00232 typedef BiContextType *BiContextTypePtr;
00233
00234
00235
00236
00237
00238
00239
00240 #define NUM_MB_TYPE_CTX 11
00241 #define NUM_B8_TYPE_CTX 9
00242 #define NUM_MV_RES_CTX 10
00243 #define NUM_REF_NO_CTX 6
00244 #define NUM_DELTA_QP_CTX 4
00245 #define NUM_MB_AFF_CTX 4
00246 #define NUM_TRANSFORM_SIZE_CTX 3
00247
00248
00249 typedef struct
00250 {
00251 BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX];
00252 BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
00253 BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
00254 BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
00255 BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX];
00256 BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
00257 BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
00258 } MotionInfoContexts;
00259
00260 #define NUM_IPR_CTX 2
00261 #define NUM_CIPR_CTX 4
00262 #define NUM_CBP_CTX 4
00263 #define NUM_BCBP_CTX 4
00264 #define NUM_MAP_CTX 15
00265 #define NUM_LAST_CTX 15
00266 #define NUM_ONE_CTX 5
00267 #define NUM_ABS_CTX 5
00268
00269
00270 typedef struct
00271 {
00272 BiContextType ipr_contexts [NUM_IPR_CTX];
00273 BiContextType cipr_contexts[NUM_CIPR_CTX];
00274 BiContextType cbp_contexts [3][NUM_CBP_CTX];
00275 BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
00276 BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00277 BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00278 BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
00279 BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
00280 } TextureInfoContexts;
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 struct img_par;
00291 struct inp_par;
00292 struct stat_par;
00293
00295 typedef struct DecRefPicMarking_s
00296 {
00297 int memory_management_control_operation;
00298 int difference_of_pic_nums_minus1;
00299 int long_term_pic_num;
00300 int long_term_frame_idx;
00301 int max_long_term_frame_idx_plus1;
00302 struct DecRefPicMarking_s *Next;
00303 } DecRefPicMarking_t;
00304
00306 typedef struct macroblock
00307 {
00308 int qp;
00309 int qpc[2];
00310 int qp_scaled[MAX_PLANE];
00311 Boolean is_lossless;
00312
00313 short slice_nr;
00314 short delta_quant;
00315
00316 struct macroblock *mb_available_up;
00317 struct macroblock *mb_available_left;
00318
00319
00320 int mb_type;
00321 short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2];
00322 int cbp;
00323 int64 cbp_blk [3];
00324 int64 cbp_bits [3];
00325 int64 cbp_bits_8x8[3];
00326
00327 int i16mode;
00328 char b8mode[4];
00329 char b8pdir[4];
00330 char ei_flag;
00331 char dpl_flag;
00332
00333 int DFDisableIdc;
00334 int DFAlphaC0Offset;
00335 int DFBetaOffset;
00336
00337 int c_ipred_mode;
00338 byte mb_field;
00339
00340 int skip_flag;
00341
00342 int mbAddrX;
00343 int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
00344 int mbAvailA, mbAvailB, mbAvailC, mbAvailD;
00345
00346 int luma_transform_size_8x8_flag;
00347 int NoMbPartLessThan8x8Flag;
00348 } Macroblock;
00349
00351 typedef struct syntaxelement
00352 {
00353 int type;
00354 int value1;
00355 int value2;
00356 int len;
00357 int inf;
00358 unsigned int bitpattern;
00359 int context;
00360 int k;
00361
00362 #if TRACE
00363 #define TRACESTRING_SIZE 100
00364 char tracestring[TRACESTRING_SIZE];
00365 #endif
00366
00368 void (*mapping)(int len, int info, int *value1, int *value2);
00370 void (*reading)(Macroblock *currMB, struct syntaxelement *, struct img_par *img, DecodingEnvironmentPtr);
00371
00372 } SyntaxElement;
00373
00374
00376 typedef struct
00377 {
00378
00379 int read_len;
00380 int code_len;
00381
00382 int frame_bitoffset;
00383 int bitstream_length;
00384
00385 byte *streamBuffer;
00386 int ei_flag;
00387 } Bitstream;
00388
00390 typedef struct datapartition
00391 {
00392
00393 Bitstream *bitstream;
00394 DecodingEnvironment de_cabac;
00395
00396 int (*readSyntaxElement)(SyntaxElement *, struct img_par *, struct datapartition *);
00400 } DataPartition;
00401
00403 typedef struct
00404 {
00405 int ei_flag;
00406 int qp;
00407 int slice_qp_delta;
00408 int qs;
00409 int slice_qs_delta;
00410 int picture_type;
00411 PictureStructure structure;
00412 int start_mb_nr;
00413 int max_part_nr;
00414 int dp_mode;
00415 int next_header;
00416
00417 DataPartition *partArr;
00418 MotionInfoContexts *mot_ctx;
00419 TextureInfoContexts *tex_ctx;
00420
00421 int ref_pic_list_reordering_flag_l0;
00422 int *reordering_of_pic_nums_idc_l0;
00423 int *abs_diff_pic_num_minus1_l0;
00424 int *long_term_pic_idx_l0;
00425 int ref_pic_list_reordering_flag_l1;
00426 int *reordering_of_pic_nums_idc_l1;
00427 int *abs_diff_pic_num_minus1_l1;
00428 int *long_term_pic_idx_l1;
00429
00430 int (*readSlice)(struct img_par *, struct inp_par *);
00431
00432 int DFDisableIdc;
00433 int DFAlphaC0Offset;
00434 int DFBetaOffset;
00435
00436 int pic_parameter_set_id;
00437
00438 int dpB_NotPresent;
00439 int dpC_NotPresent;
00440 } Slice;
00441
00442
00443
00444
00445 typedef struct img_par
00446 {
00447 int number;
00448 unsigned int current_mb_nr;
00449 unsigned int num_dec_mb;
00450 int current_slice_nr;
00451 int *intra_block;
00452 int tr;
00453 int qp;
00454 int qpsp;
00455 int sp_switch;
00456 int direct_spatial_mv_pred_flag;
00457 int type;
00458 int width;
00459 int height;
00460 int width_cr;
00461 int width_cr_m1;
00462 int height_cr;
00463 int mb_x;
00464 int mb_y;
00465 int block_x;
00466 int block_y;
00467 int block_y_aff;
00468 int pix_x;
00469 int pix_y;
00470 int pix_c_x;
00471 int pix_c_y;
00472
00473 int allrefzero;
00474
00475 int mvscale[6][MAX_REFERENCE_PICTURES];
00476 imgpel ***mb_pred;
00477 imgpel ***mb_rec;
00478 int ***mb_rres;
00479 int ***cof;
00480 int ***fcf;
00481
00482 int cofu[16];
00483 byte **ipredmode;
00484 byte ****nz_coeff;
00485 int **siblock;
00486 int cod_counter;
00487
00488 int newframe;
00489
00490 int structure;
00491
00492
00493 Slice *currentSlice;
00494 Macroblock *mb_data;
00495 Macroblock *mb_data_JV[MAX_PLANE];
00496 int colour_plane_id;
00497 int ChromaArrayType;
00498
00499 int subblock_x;
00500 int subblock_y;
00501 int is_intra_block;
00502 int is_v_block;
00503
00504
00505 int MbaffFrameFlag;
00506
00507
00508 int DeblockCall;
00509
00510 DecRefPicMarking_t *dec_ref_pic_marking_buffer;
00511
00512 int num_ref_idx_l0_active;
00513 int num_ref_idx_l1_active;
00514
00515 int slice_group_change_cycle;
00516
00517 int redundant_pic_cnt;
00518
00519 int explicit_B_prediction;
00520
00521 unsigned int pre_frame_num;
00522
00523
00524
00525 int toppoc;
00526 int bottompoc;
00527 int framepoc;
00528 unsigned int frame_num;
00529 unsigned int field_pic_flag;
00530 byte bottom_field_flag;
00531
00532
00533
00534 unsigned int pic_order_cnt_lsb;
00535 int delta_pic_order_cnt_bottom;
00536
00537 int delta_pic_order_cnt[3];
00538
00539
00540
00541 signed int PrevPicOrderCntMsb;
00542 unsigned int PrevPicOrderCntLsb;
00543 signed int PicOrderCntMsb;
00544
00545
00546 unsigned int AbsFrameNum;
00547 signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle;
00548 unsigned int PreviousFrameNum, FrameNumOffset;
00549 int ExpectedDeltaPerPicOrderCntCycle;
00550 int PreviousPOC, ThisPOC;
00551 int PreviousFrameNumOffset;
00552
00553
00554
00555 unsigned int luma_log2_weight_denom;
00556 unsigned int chroma_log2_weight_denom;
00557 int ***wp_weight;
00558 int ***wp_offset;
00559 int ****wbp_weight;
00560 int wp_round_luma;
00561 int wp_round_chroma;
00562 unsigned int apply_weights;
00563
00564 int idr_flag;
00565 int nal_reference_idc;
00566
00567 int idr_pic_id;
00568
00569 int MaxFrameNum;
00570
00571 unsigned int PicWidthInMbs;
00572 unsigned int PicHeightInMapUnits;
00573 unsigned int FrameHeightInMbs;
00574 unsigned int PicHeightInMbs;
00575 unsigned int PicSizeInMbs;
00576 unsigned int FrameSizeInMbs;
00577 unsigned int oldFrameSizeInMbs;
00578
00579 int no_output_of_prior_pics_flag;
00580 int long_term_reference_flag;
00581 int adaptive_ref_pic_buffering_flag;
00582
00583 int last_has_mmco_5;
00584 int last_pic_bottom_field;
00585
00586 int model_number;
00587
00588
00589 int pic_unit_bitsize_on_disk;
00590 int bitdepth_luma;
00591 int bitdepth_chroma;
00592 int bitdepth_scale[2];
00593 int bitdepth_luma_qp_scale;
00594 int bitdepth_chroma_qp_scale;
00595 unsigned int dc_pred_value_comp[MAX_PLANE];
00596 int max_imgpel_value_comp[MAX_PLANE];
00597 int Transform8x8Mode;
00598 int profile_idc;
00599 int yuv_format;
00600 int lossless_qpprime_flag;
00601 int num_blk8x8_uv;
00602 int num_uv_blocks;
00603 int num_cdc_coeff;
00604 int mb_cr_size_x;
00605 int mb_cr_size_y;
00606 int mb_cr_size_x_blk;
00607 int mb_cr_size_y_blk;
00608 int mb_size[3][2];
00609 int mb_size_blk[3][2];
00610 int mb_size_shift[3][2];
00611
00612 int max_vmv_r;
00613 int max_mb_vmv_r;
00614
00615 int idr_psnr_number;
00616 int psnr_number;
00617
00618
00619 TIME_T start_time;
00620 TIME_T end_time;
00621
00622
00623 int last_ref_pic_poc;
00624 int ref_poc_gap;
00625 int poc_gap;
00626 int conceal_mode;
00627 int earlier_missing_poc;
00628 unsigned int frame_to_conceal;
00629 int IDR_concealment_flag;
00630 int conceal_slice_type;
00631
00632
00633 int recovery_point;
00634 int recovery_point_found;
00635 int recovery_frame_cnt;
00636 int recovery_frame_num;
00637 int recovery_poc;
00638
00639 int separate_colour_plane_flag;
00640 } ImageParameters;
00641
00642 extern ImageParameters *img;
00643 extern struct snr_par *snr;
00644
00645
00646 struct snr_par
00647 {
00648 int frame_ctr;
00649 float snr[3];
00650 float snr1[3];
00651 float snra[3];
00652 float sse[3];
00653 float msse[3];
00654 };
00655
00656 int64 tot_time;
00657
00658
00659 struct inp_par
00660 {
00661 char infile[FILE_NAME_SIZE];
00662 char outfile[FILE_NAME_SIZE];
00663 char reffile[FILE_NAME_SIZE];
00664 int FileFormat;
00665 int ref_offset;
00666 int poc_scale;
00667 int write_uv;
00668 int silent;
00669 int intra_profile_deblocking;
00670
00671 #ifdef _LEAKYBUCKET_
00672 unsigned long R_decoder;
00673 unsigned long B_decoder;
00674 unsigned long F_decoder;
00675 char LeakyBucketParamFile[100];
00676 #endif
00677
00678
00679 int conceal_mode;
00680 int ref_poc_gap;
00681 int poc_gap;
00682 };
00683
00684 extern struct inp_par *params;
00685
00686 typedef struct pix_pos
00687 {
00688 int available;
00689 int mb_addr;
00690 int x;
00691 int y;
00692 int pos_x;
00693 int pos_y;
00694 } PixelPos;
00695
00696 typedef struct old_slice_par
00697 {
00698 unsigned field_pic_flag;
00699 unsigned frame_num;
00700 int nal_ref_idc;
00701 unsigned pic_oder_cnt_lsb;
00702 int delta_pic_oder_cnt_bottom;
00703 int delta_pic_order_cnt[2];
00704 byte idr_flag;
00705 int idr_pic_id;
00706 int pps_id;
00707 byte bottom_field_flag;
00708 } OldSliceParams;
00709
00710 extern OldSliceParams old_slice;
00711
00712
00713 int p_out;
00714 int p_ref;
00715
00716 FILE *p_log;
00717
00718 #if TRACE
00719 FILE *p_trace;
00720 #endif
00721
00722
00723 unsigned int previous_frame_num;
00724 int ref_flag[17];
00725
00726 int Is_primary_correct;
00727 int Is_redundant_correct;
00728 int redundant_slice_ref_idx;
00729
00730
00731 void init_conf(struct inp_par *inp, char *config_filename);
00732 void report(struct inp_par *inp, ImageParameters *img, struct snr_par *snr);
00733 void init(ImageParameters *img);
00734
00735 void malloc_slice(struct inp_par *inp, ImageParameters *img);
00736 void free_slice(ImageParameters *img);
00737
00738
00739 int (*nal_startcode_follows) (Slice*, int );
00740
00741
00742 void reset_ec_flags(void);
00743
00744 void error(char *text, int code);
00745
00746
00747 int init_global_buffers(void);
00748 void free_global_buffers(void);
00749
00750 int RBSPtoSODB(byte *streamBuffer, int last_byte_pos);
00751 int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos);
00752
00753 void FreePartition (DataPartition *dp, int n);
00754 DataPartition *AllocPartition(int n);
00755
00756 void tracebits(const char *trace_str, int len, int info,int value1);
00757 void tracebits2(const char *trace_str, int len, int info);
00758
00759 unsigned CeilLog2 ( unsigned uiVal);
00760 unsigned CeilLog2_sf( unsigned uiVal);
00761
00762
00763 int ipmode_DPCM;
00764
00765
00766 void change_plane_JV( int nplane );
00767 void make_frame_picture_JV(void);
00768
00769 #endif
00770
00771