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 #include "types.h"
00041 #include "io_image.h"
00042 #include "frame.h"
00043 #include "distortion.h"
00044 #include "io_video.h"
00045
00046
00047 int **PicPos;
00048
00049 #define ET_SIZE 300
00050 char errortext[ET_SIZE];
00051
00052
00053
00054
00055
00056
00057 typedef enum
00058 {
00059 LumaComp = 0,
00060 CrComp = 1,
00061 CbComp = 2
00062 } Color_Component;
00063
00064
00065
00066
00067
00068
00069 typedef struct pix_pos
00070 {
00071 int available;
00072 int mb_addr;
00073 short x;
00074 short y;
00075 short pos_x;
00076 short pos_y;
00077 } PixelPos;
00078
00080 typedef struct
00081 {
00082 unsigned int Drange;
00083 unsigned int Dvalue;
00084 int DbitsLeft;
00085 byte *Dcodestrm;
00086 int *Dcodestrm_len;
00087 } DecodingEnvironment;
00088
00089 typedef DecodingEnvironment *DecodingEnvironmentPtr;
00090
00092 typedef struct motion_params
00093 {
00094 int64 *** ref_pic_id;
00095 short **** mv;
00096 char *** ref_idx;
00097 byte ** moving_block;
00098 } MotionParams;
00099
00101 typedef struct
00102 {
00103 uint16 state;
00104 unsigned char MPS;
00105 unsigned char dummy;
00106 } BiContextType;
00107
00108 typedef BiContextType *BiContextTypePtr;
00109
00110
00111
00112
00113
00114
00115
00116 #define NUM_MB_TYPE_CTX 11
00117 #define NUM_B8_TYPE_CTX 9
00118 #define NUM_MV_RES_CTX 10
00119 #define NUM_REF_NO_CTX 6
00120 #define NUM_DELTA_QP_CTX 4
00121 #define NUM_MB_AFF_CTX 4
00122 #define NUM_TRANSFORM_SIZE_CTX 3
00123
00124
00125 struct storable_picture;
00126 struct datapartition;
00127 struct syntaxelement;
00128
00129 typedef struct
00130 {
00131 BiContextType mb_type_contexts [3][NUM_MB_TYPE_CTX];
00132 BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
00133 BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
00134 BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
00135 BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX];
00136 BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
00137 } MotionInfoContexts;
00138
00139 #define NUM_IPR_CTX 2
00140 #define NUM_CIPR_CTX 4
00141 #define NUM_CBP_CTX 4
00142 #define NUM_BCBP_CTX 4
00143 #define NUM_MAP_CTX 15
00144 #define NUM_LAST_CTX 15
00145 #define NUM_ONE_CTX 5
00146 #define NUM_ABS_CTX 5
00147
00148
00149 typedef struct
00150 {
00151 BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
00152 BiContextType ipr_contexts [NUM_IPR_CTX];
00153 BiContextType cipr_contexts[NUM_CIPR_CTX];
00154 BiContextType cbp_contexts [3][NUM_CBP_CTX];
00155 BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
00156 BiContextType map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX];
00157 BiContextType last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX];
00158 BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
00159 BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
00160 } TextureInfoContexts;
00161
00162
00163
00164
00165
00166
00167
00168
00169
00171 typedef struct DecRefPicMarking_s
00172 {
00173 int memory_management_control_operation;
00174 int difference_of_pic_nums_minus1;
00175 int long_term_pic_num;
00176 int long_term_frame_idx;
00177 int max_long_term_frame_idx_plus1;
00178 struct DecRefPicMarking_s *Next;
00179 } DecRefPicMarking_t;
00180
00181
00183 typedef struct pic_motion_params2
00184 {
00185 int64 ref_pic_id;
00186 int64 ref_id;
00187 short mv[2];
00188 char ref_idx;
00189 byte mb_field;
00190 byte field_frame;
00191 } PicMotionParams2;
00192
00194 typedef struct
00195 {
00196 short mv_x;
00197 short mv_y;
00198 } MotionVector;
00199
00201 typedef struct macroblock
00202 {
00203 struct slice *p_Slice;
00204 struct img_par *p_Img;
00205 struct inp_par *p_Inp;
00206 int mbAddrX;
00207 int mb_x;
00208 int mb_y;
00209 int block_x;
00210 int block_y;
00211 int block_y_aff;
00212 int pix_x;
00213 int pix_y;
00214 int pix_c_x;
00215 int pix_c_y;
00216
00217 int subblock_x;
00218 int subblock_y;
00219
00220 int qp;
00221 int qpc[2];
00222 int qp_scaled[MAX_PLANE];
00223 Boolean is_lossless;
00224 Boolean is_intra_block;
00225 Boolean is_v_block;
00226
00227 short slice_nr;
00228 short delta_quant;
00229
00230 struct macroblock *mb_up;
00231 struct macroblock *mb_left;
00232
00233
00234 int mb_type;
00235 short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2];
00236 int cbp;
00237 int64 cbp_blk [3];
00238 int64 cbp_bits [3];
00239 int64 cbp_bits_8x8[3];
00240
00241 int i16mode;
00242 char b8mode[4];
00243 char b8pdir[4];
00244 char ei_flag;
00245 char dpl_flag;
00246 char ipmode_DPCM;
00247
00248 short DFDisableIdc;
00249 short DFAlphaC0Offset;
00250 short DFBetaOffset;
00251
00252 char c_ipred_mode;
00253 Boolean mb_field;
00254
00255 char skip_flag;
00256
00257 int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
00258 Boolean mbAvailA, mbAvailB, mbAvailC, mbAvailD;
00259
00260 Boolean luma_transform_size_8x8_flag;
00261 Boolean NoMbPartLessThan8x8Flag;
00262
00263 void (*itrans_4x4)(struct macroblock *currMB, ColorPlane pl, int ioff, int joff);
00264 void (*itrans_8x8)(struct macroblock *currMB, ColorPlane pl, int ioff, int joff);
00265
00266 void (*GetMVPredictor) (struct macroblock *currMB, PixelPos *block,
00267 short pmv[2], short ref_frame, char **refPic, short ***tmp_mv, int mb_x, int mb_y, int blockshape_x, int blockshape_y);
00268
00269 int (*read_and_store_CBP_block_bit) (struct macroblock *currMB, DecodingEnvironmentPtr dep_dp, int type);
00270 char (*readRefPictureIdx) (struct macroblock *currMB, struct syntaxelement *currSE, struct datapartition *dP, char b8mode, int list);
00271
00272 } Macroblock;
00273
00275 typedef struct syntaxelement
00276 {
00277 int type;
00278 int value1;
00279 int value2;
00280 int len;
00281 int inf;
00282 unsigned int bitpattern;
00283 int context;
00284 int k;
00285
00286 #if TRACE
00287 #define TRACESTRING_SIZE 100
00288 char tracestring[TRACESTRING_SIZE];
00289 #endif
00290
00292 void (*mapping)(int len, int info, int *value1, int *value2);
00294 void (*reading)(Macroblock *currMB, struct syntaxelement *, DecodingEnvironmentPtr);
00295 } SyntaxElement;
00296
00297
00299 typedef struct
00300 {
00301
00302 int read_len;
00303 int code_len;
00304
00305 int frame_bitoffset;
00306 int bitstream_length;
00307
00308 byte *streamBuffer;
00309 int ei_flag;
00310 } Bitstream;
00311
00313 typedef struct datapartition
00314 {
00315
00316 Bitstream *bitstream;
00317 DecodingEnvironment de_cabac;
00318
00319 int (*readSyntaxElement)(SyntaxElement *, struct img_par *, struct datapartition *);
00323 } DataPartition;
00324
00326 typedef struct slice
00327 {
00328 struct img_par *p_Img;
00329 struct inp_par *p_Inp;
00330 pic_parameter_set_rbsp_t *active_pps;
00331 seq_parameter_set_rbsp_t *active_sps;
00332
00333 struct colocated_params *p_colocated;
00334 struct colocated_params *Co_located_JV[MAX_PLANE];
00335
00336 int MbaffFrameFlag;
00337 int direct_spatial_mv_pred_flag;
00338 int num_ref_idx_l0_active;
00339 int num_ref_idx_l1_active;
00340
00341 int ei_flag;
00342 int qp;
00343 int slice_qp_delta;
00344 int qs;
00345 int slice_qs_delta;
00346 int slice_type;
00347 int model_number;
00348 PictureStructure structure;
00349 int start_mb_nr;
00350 int max_part_nr;
00351 int dp_mode;
00352 int next_header;
00353 int last_dquant;
00354
00355
00356 DataPartition *partArr;
00357 MotionInfoContexts *mot_ctx;
00358 TextureInfoContexts *tex_ctx;
00359
00360 int mvscale[6][MAX_REFERENCE_PICTURES];
00361
00362 int ref_pic_list_reordering_flag_l0;
00363 int *reordering_of_pic_nums_idc_l0;
00364 int *abs_diff_pic_num_minus1_l0;
00365 int *long_term_pic_idx_l0;
00366 int ref_pic_list_reordering_flag_l1;
00367 int *reordering_of_pic_nums_idc_l1;
00368 int *abs_diff_pic_num_minus1_l1;
00369 int *long_term_pic_idx_l1;
00370
00371
00372 short DFDisableIdc;
00373 short DFAlphaC0Offset;
00374 short DFBetaOffset;
00375
00376 int pic_parameter_set_id;
00377
00378 int dpB_NotPresent;
00379 int dpC_NotPresent;
00380
00381 imgpel ***mb_pred;
00382 imgpel ***mb_rec;
00383 int ***mb_rres;
00384 int ***cof;
00385 int ***fcf;
00386
00387 int cofu[16];
00388
00389 imgpel **tmp_block_l0;
00390 imgpel **tmp_block_l1;
00391 int **tmp_res;
00392
00393
00394 int InvLevelScale4x4_Intra[3][6][4][4];
00395 int InvLevelScale4x4_Inter[3][6][4][4];
00396 int InvLevelScale8x8_Intra[3][6][8][8];
00397 int InvLevelScale8x8_Inter[3][6][8][8];
00398
00399 int *qmatrix[12];
00400
00401
00402 int coeff[64];
00403 int coeff_ctr;
00404 int pos;
00405
00406
00407
00408 unsigned int apply_weights;
00409 unsigned int luma_log2_weight_denom;
00410 unsigned int chroma_log2_weight_denom;
00411 int ***wp_weight;
00412 int ***wp_offset;
00413 int ****wbp_weight;
00414 int wp_round_luma;
00415 int wp_round_chroma;
00416
00417
00418 void (*read_CBP_and_coeffs_from_NAL) (Macroblock *currMB);
00419 int (*decode_one_component ) (Macroblock *currMB, ColorPlane curr_plane, imgpel **currImg, struct storable_picture *dec_picture, struct motion_params *colocated, int list_offset);
00420 int (*readSlice ) (struct img_par *, struct inp_par *);
00421 int (*nal_startcode_follows ) (struct slice*, int );
00422 void (*read_motion_info_from_NAL) (Macroblock *currMB);
00423 void (*read_one_macroblock ) (Macroblock *currMB);
00424 void (*interpret_mb_mode ) (Macroblock *currMB);
00425
00426 void (*linfo_cbp_intra) (int len,int info,int *cbp, int *dummy);
00427 void (*linfo_cbp_inter) (int len,int info,int *cbp, int *dummy);
00428 } Slice;
00429
00430
00431
00432
00433 typedef struct img_par
00434 {
00435 struct inp_par *p_Inp;
00436 pic_parameter_set_rbsp_t *active_pps;
00437 seq_parameter_set_rbsp_t *active_sps;
00438 seq_parameter_set_rbsp_t SeqParSet[MAXSPS];
00439 pic_parameter_set_rbsp_t PicParSet[MAXPPS];
00440
00441 struct sei_params *p_SEI;
00442
00443 struct old_slice_par *old_slice;
00444 struct snr_par *snr;
00445 int number;
00446 unsigned int current_mb_nr;
00447 unsigned int num_dec_mb;
00448 short current_slice_nr;
00449 int *intra_block;
00450
00451 int qp;
00452
00453 int sp_switch;
00454 int type;
00455 int width;
00456 int height;
00457 int width_cr;
00458 int height_cr;
00459 int mb_x;
00460 int mb_y;
00461 int block_x;
00462 int block_y;
00463 int pix_c_x;
00464 int pix_c_y;
00465
00466 int allrefzero;
00467
00468 byte **ipredmode;
00469 byte ****nz_coeff;
00470 int **siblock;
00471 int cod_counter;
00472
00473 int newframe;
00474 int structure;
00475
00476 Slice *currentSlice;
00477 Macroblock *mb_data;
00478 Macroblock *mb_data_JV[MAX_PLANE];
00479 int colour_plane_id;
00480 int ChromaArrayType;
00481
00482
00483 int MbaffFrameFlag;
00484
00485
00486 int DeblockCall;
00487 byte mixedModeEdgeFlag;
00488
00489
00490
00491
00492 struct concealment_node *concealment_head;
00493 struct concealment_node *concealment_end;
00494
00495 DecRefPicMarking_t *dec_ref_pic_marking_buffer;
00496
00497 int num_ref_idx_l0_active;
00498 int num_ref_idx_l1_active;
00499
00500 int slice_group_change_cycle;
00501
00502 int redundant_pic_cnt;
00503
00504 unsigned int pre_frame_num;
00505 int non_conforming_stream;
00506
00507
00508
00509 int toppoc;
00510 int bottompoc;
00511 int framepoc;
00512 unsigned int frame_num;
00513 unsigned int field_pic_flag;
00514 byte bottom_field_flag;
00515
00516
00517
00518 unsigned int pic_order_cnt_lsb;
00519 int delta_pic_order_cnt_bottom;
00520
00521 int delta_pic_order_cnt[3];
00522
00523
00524
00525 signed int PrevPicOrderCntMsb;
00526 unsigned int PrevPicOrderCntLsb;
00527 signed int PicOrderCntMsb;
00528
00529
00530 unsigned int AbsFrameNum;
00531 signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle;
00532 unsigned int PreviousFrameNum, FrameNumOffset;
00533 int ExpectedDeltaPerPicOrderCntCycle;
00534 int PreviousPOC, ThisPOC;
00535 int PreviousFrameNumOffset;
00536
00537
00538 int idr_flag;
00539 int nal_reference_idc;
00540
00541 int idr_pic_id;
00542
00543 int MaxFrameNum;
00544
00545 unsigned int PicWidthInMbs;
00546 unsigned int PicHeightInMapUnits;
00547 unsigned int FrameHeightInMbs;
00548 unsigned int PicHeightInMbs;
00549 unsigned int PicSizeInMbs;
00550 unsigned int FrameSizeInMbs;
00551 unsigned int oldFrameSizeInMbs;
00552
00553 int no_output_of_prior_pics_flag;
00554 int long_term_reference_flag;
00555 int adaptive_ref_pic_buffering_flag;
00556
00557 int last_has_mmco_5;
00558 int last_pic_bottom_field;
00559
00560
00561 int pic_unit_bitsize_on_disk;
00562 short bitdepth_luma;
00563 short bitdepth_chroma;
00564 int bitdepth_scale[2];
00565 int bitdepth_luma_qp_scale;
00566 int bitdepth_chroma_qp_scale;
00567 unsigned int dc_pred_value_comp[MAX_PLANE];
00568 int max_imgpel_value_comp[MAX_PLANE];
00569 int Transform8x8Mode;
00570 int profile_idc;
00571 int yuv_format;
00572 int lossless_qpprime_flag;
00573 int num_blk8x8_uv;
00574 int num_uv_blocks;
00575 int num_cdc_coeff;
00576 int mb_cr_size_x;
00577 int mb_cr_size_y;
00578 int mb_cr_size_x_blk;
00579 int mb_cr_size_y_blk;
00580 int mb_size[3][2];
00581 int mb_size_blk[3][2];
00582 int mb_size_shift[3][2];
00583
00584 int max_vmv_r;
00585 int max_mb_vmv_r;
00586
00587 int idr_psnr_number;
00588 int psnr_number;
00589
00590
00591 TIME_T start_time;
00592 TIME_T end_time;
00593
00594
00595 int last_ref_pic_poc;
00596 int ref_poc_gap;
00597 int poc_gap;
00598 int conceal_mode;
00599 int earlier_missing_poc;
00600 unsigned int frame_to_conceal;
00601 int IDR_concealment_flag;
00602 int conceal_slice_type;
00603
00604
00605 int recovery_point;
00606 int recovery_point_found;
00607 int recovery_frame_cnt;
00608 int recovery_frame_num;
00609 int recovery_poc;
00610
00611 int separate_colour_plane_flag;
00612 int pic_unit_size_on_disk;
00613
00614 byte *buf;
00615 byte *ibuf;
00616
00617 ImageData imgData;
00618 ImageData imgData0;
00619 ImageData imgData1;
00620 ImageData imgData2;
00621
00622 int frame_number;
00623 int init_bl_done;
00624
00625
00626 unsigned int previous_frame_num;
00627 int ref_flag[17];
00628
00629 int Is_primary_correct;
00630 int Is_redundant_correct;
00631 int redundant_slice_ref_idx;
00632
00633
00634 int64 tot_time;
00635
00636
00637 int p_out;
00638 int p_ref;
00639
00640
00641 int LastAccessUnitExists;
00642 int NALUCount;
00643
00644
00645 int ipmode_DPCM;
00646
00647
00648 int Bframe_ctr;
00649 int frame_no;
00650
00651 int g_nFrame;
00652 Boolean global_init_done;
00653
00654
00655 imgpel **imgY_ref;
00656 imgpel ***imgUV_ref;
00657
00658 int *qp_per_matrix;
00659 int *qp_rem_matrix;
00660
00661 struct frame_store *last_out_fs;
00662 int pocs_in_dpb[100];
00663
00664
00665 struct storable_picture *dec_picture;
00666 struct storable_picture *dec_picture_JV[MAX_PLANE];
00667 struct storable_picture *no_reference_picture;
00668 struct storable_picture **listX[6];
00669
00670
00671 struct object_buffer *erc_object_list;
00672 struct ercVariables_s *erc_errorVar;
00673
00674 int erc_mvperMB;
00675 struct img_par *erc_img;
00676 int ec_flag[SE_MAX_ELEMENTS];
00677
00678 struct annex_b_struct *annex_b;
00679 struct sBitsFile *bitsfile;
00680
00681
00682 struct frame_store *out_buffer;
00683
00684 struct storable_picture *pending_output;
00685 int pending_output_state;
00686 int recovery_flag;
00687
00688 int BitStreamFile;
00689
00690 struct decoded_picture_buffer *p_Dpb;
00691
00692 char listXsize[6];
00693
00694 char cslice_type[9];
00695
00696 int *MbToSliceGroupMap;
00697 int *MapUnitToSliceGroupMap;
00698 int NumberOfSliceGroups;
00699
00700 #if (ENABLE_OUTPUT_TONEMAPPING)
00701 struct tone_mapping_struct_s *seiToneMapping;
00702 #endif
00703
00704
00705 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);
00706 void (*getNeighbour) (Macroblock *currMB, int xN, int yN, int mb_size[2], PixelPos *pix);
00707 void (*get_mb_block_pos) (int mb_addr, short *x, short *y);
00708 void (*GetStrength) (byte Strength[16], Macroblock *MbQ, int dir,int edge, int mvlimit, struct storable_picture *p);
00709 void (*EdgeLoopLuma) (ColorPlane pl, imgpel** Img, byte Strength[16], Macroblock *MbQ, int dir, int edge, struct storable_picture *p);
00710 void (*EdgeLoopChroma) (imgpel** Img, byte Strength[16], Macroblock *MbQ, int dir, int edge, int uv, struct storable_picture *p);
00711 void (*img2buf) (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes, int crop_left, int crop_right, int crop_top, int crop_bottom);
00712 } ImageParameters;
00713
00714
00715 typedef struct snr_par
00716 {
00717 int frame_ctr;
00718 float snr[3];
00719 float snr1[3];
00720 float snra[3];
00721 float sse[3];
00722 float msse[3];
00723 } SNRParameters;
00724
00725
00726 typedef struct inp_par
00727 {
00728 char infile[FILE_NAME_SIZE];
00729 char outfile[FILE_NAME_SIZE];
00730 char reffile[FILE_NAME_SIZE];
00731
00732 int FileFormat;
00733 int ref_offset;
00734 int poc_scale;
00735 int write_uv;
00736 int silent;
00737 int intra_profile_deblocking;
00738
00739
00740 FrameFormat source;
00741 FrameFormat output;
00742
00743 int ProcessInput;
00744 VideoDataFile input_file1;
00745 VideoDataFile input_file2;
00746 VideoDataFile input_file3;
00747
00748
00749 #ifdef _LEAKYBUCKET_
00750 unsigned long R_decoder;
00751 unsigned long B_decoder;
00752 unsigned long F_decoder;
00753 char LeakyBucketParamFile[FILE_NAME_SIZE];
00754 #endif
00755
00756
00757 int conceal_mode;
00758 int ref_poc_gap;
00759 int poc_gap;
00760
00761
00762 int start_frame;
00763 } InputParameters;
00764
00765 typedef struct old_slice_par
00766 {
00767 unsigned field_pic_flag;
00768 unsigned frame_num;
00769 int nal_ref_idc;
00770 unsigned pic_oder_cnt_lsb;
00771 int delta_pic_oder_cnt_bottom;
00772 int delta_pic_order_cnt[2];
00773 byte bottom_field_flag;
00774 byte idr_flag;
00775 int idr_pic_id;
00776 int pps_id;
00777 } OldSliceParams;
00778
00779 typedef struct decoder_params
00780 {
00781 InputParameters *p_Inp;
00782 ImageParameters *p_Img;
00783 int64 bufferSize;
00784 int UsedBits;
00785 FILE *p_trace;
00786 int bitcounter;
00787 } DecoderParams;
00788
00789 extern DecoderParams *p_Dec;
00790
00791
00792
00793 extern void error(char *text, int code);
00794
00795
00796 extern int init_global_buffers(ImageParameters *p_Img);
00797 extern void free_global_buffers(ImageParameters *p_Img);
00798
00799 extern int RBSPtoSODB(byte *streamBuffer, int last_byte_pos);
00800 extern int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos);
00801
00802 void FreePartition (DataPartition *dp, int n);
00803 DataPartition *AllocPartition(int n);
00804
00805 void tracebits(const char *trace_str, int len, int info,int value1);
00806 void tracebits2(const char *trace_str, int len, int info);
00807
00808 unsigned CeilLog2 ( unsigned uiVal);
00809 unsigned CeilLog2_sf( unsigned uiVal);
00810
00811
00812 extern void change_plane_JV( ImageParameters *p_Img, int nplane );
00813 extern void make_frame_picture_JV(ImageParameters *p_Img);
00814
00815
00816 #endif
00817
00818