global.h
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:25k
源码类别:

Audio

开发平台:

Visual C++

  1. /*!
  2.  ************************************************************************
  3.  *  file
  4.  *     global.h
  5.  *  brief
  6.  *     global definitions for H.264 decoder.
  7.  *  author
  8.  *     Copyright (C) 1999  Telenor Satellite Services,Norway
  9.  *                         Ericsson Radio Systems, Sweden
  10.  *
  11.  *     Inge Lille-Langoy               <inge.lille-langoy@telenor.com>
  12.  *
  13.  *     Telenor Satellite Services
  14.  *     Keysers gt.13                       tel.:   +47 23 13 86 98
  15.  *     N-0130 Oslo,Norway                  fax.:   +47 22 77 79 80
  16.  *
  17.  *     Rickard Sjoberg                 <rickard.sjoberg@era.ericsson.se>
  18.  *
  19.  *     Ericsson Radio Systems
  20.  *     KI/ERA/T/VV
  21.  *     164 80 Stockholm, Sweden
  22.  *
  23.  ************************************************************************
  24.  */
  25. #ifndef _GLOBAL_H_
  26. #define _GLOBAL_H_
  27. #include <stdlib.h>
  28. #include <stdarg.h>
  29. #include <string.h>
  30. #include <assert.h>
  31. #include <time.h>
  32. #include <sys/timeb.h>
  33. #include "win32.h"
  34. #include "defines.h"
  35. #include "ifunctions.h"
  36. #include "parsetcommon.h"
  37. #define FILE_NAME_SIZE 255
  38. typedef unsigned char  byte;                     //!<  8 bit unsigned
  39. #if (IMGTYPE == 1)
  40.   typedef unsigned short imgpel;                 //!<  Pixel type definition (16 bit for FRExt)
  41. #else
  42.   typedef unsigned char  imgpel;                 //!<  Pixel type definition (8 bit without FRExt)
  43. #endif
  44. pic_parameter_set_rbsp_t *active_pps;
  45. seq_parameter_set_rbsp_t *active_sps;
  46. // global picture format dependent buffers, memory allocation in decod.c
  47. imgpel **imgY_ref;                              //!< reference frame find snr
  48. imgpel ***imgUV_ref;
  49. int **PicPos;
  50. int  ReMapRef[20];
  51. // B pictures
  52. int  Bframe_ctr;
  53. int  frame_no;
  54. int  g_nFrame;
  55. // For MB level frame/field coding
  56. int  TopFieldForSkip_Y[16][16];
  57. int  TopFieldForSkip_UV[2][16][16];
  58. #define ET_SIZE 300      //!< size of error text buffer
  59. char errortext[ET_SIZE]; //!< buffer for error message for exit with error()
  60. /***********************************************************************
  61.  * T y p e    d e f i n i t i o n s    f o r    T M L
  62.  ***********************************************************************
  63.  */
  64. //! Data Partitioning Modes
  65. typedef enum
  66. {
  67.   PAR_DP_1,    //!< no data partitioning is supported
  68.   PAR_DP_3     //!< data partitioning with 3 partitions
  69. } PAR_DP_TYPE;
  70. //! Output File Types
  71. typedef enum
  72. {
  73.   PAR_OF_ANNEXB,   //!< Current TML description
  74.   PAR_OF_RTP       //!< RTP Packet Output format
  75. } PAR_OF_TYPE;
  76. //! definition of H.264 syntax elements
  77. typedef enum 
  78. {
  79.   SE_HEADER,
  80.   SE_PTYPE,
  81.   SE_MBTYPE,
  82.   SE_REFFRAME,
  83.   SE_INTRAPREDMODE,
  84.   SE_MVD,
  85.   SE_CBP_INTRA,
  86.   SE_LUM_DC_INTRA,
  87.   SE_CHR_DC_INTRA,
  88.   SE_LUM_AC_INTRA,
  89.   SE_CHR_AC_INTRA,
  90.   SE_CBP_INTER,
  91.   SE_LUM_DC_INTER,
  92.   SE_CHR_DC_INTER,
  93.   SE_LUM_AC_INTER,
  94.   SE_CHR_AC_INTER,
  95.   SE_DELTA_QUANT_INTER,
  96.   SE_DELTA_QUANT_INTRA,
  97.   SE_BFRAME,
  98.   SE_EOS,
  99.   SE_MAX_ELEMENTS //!< number of maximum syntax elements, this MUST be the last one!
  100. } SE_type;        // substituting the definitions in element.h
  101. typedef enum 
  102. {
  103.   INTER_MB,
  104.   INTRA_MB_4x4,
  105.   INTRA_MB_16x16
  106. } IntraInterDecision;
  107. typedef enum
  108. {
  109.   BITS_HEADER         = 0,
  110.   BITS_TOTAL_MB       = 1,
  111.   BITS_MB_MODE        = 2,
  112.   BITS_INTER_MB       = 3,
  113.   BITS_CBP_MB         = 4,
  114.   BITS_COEFF_Y_MB     = 5,
  115.   BITS_COEFF_CB_MB    = 6,  
  116.   BITS_COEFF_CR_MB    = 7,
  117.   BITS_DELTA_QUANT_MB = 8,
  118.   BITS_STUFFING       = 9,
  119.   MAX_BITCOUNTER_MB   = 10
  120. } BitCountType;
  121. typedef enum 
  122. {
  123.   NO_SLICES,
  124.   FIXED_MB,
  125.   FIXED_RATE,
  126.   CALL_BACK
  127. } SliceMode;
  128. typedef enum 
  129. {
  130.   UVLC,
  131.   CABAC
  132. } SymbolMode;
  133. typedef enum 
  134. {
  135.   LIST_0  = 0,
  136.   LIST_1  = 1,
  137.   BI_PRED = 2
  138. } Lists;
  139. typedef enum 
  140. {
  141.   FRAME,
  142.   TOP_FIELD,
  143.   BOTTOM_FIELD
  144. } PictureStructure;           //!< New enum for field processing
  145. typedef enum
  146. {
  147.   // YUV
  148.   PLANE_Y = 0,  // PLANE_Y
  149.   PLANE_U = 1,  // PLANE_Cb
  150.   PLANE_V = 2,  // PLANE_Cr
  151.   // RGB
  152.   PLANE_G = 0,
  153.   PLANE_B = 1,
  154.   PLANE_R = 2
  155. } ColorPlane;
  156. typedef enum 
  157. {
  158.   P_SLICE = 0,
  159.   B_SLICE,
  160.   I_SLICE,
  161.   SP_SLICE,
  162.   SI_SLICE
  163. } SliceType;
  164. typedef enum
  165. {
  166.   IS_LUMA = 0,
  167.   IS_CHROMA = 1
  168. } Component_Type;
  169. typedef enum
  170. {
  171.   LumaComp = 0,
  172.   CrComp = 1,
  173.   CbComp = 2
  174. } Color_Component;
  175. /***********************************************************************
  176.  * D a t a    t y p e s   f o r  C A B A C
  177.  ***********************************************************************
  178.  */
  179. //! struct to characterize the state of the arithmetic coding engine
  180. typedef struct
  181. {
  182.   unsigned int    Drange;
  183.   unsigned int    Dvalue;
  184.   int             DbitsLeft;
  185.   byte            *Dcodestrm;
  186.   int             *Dcodestrm_len;
  187. } DecodingEnvironment;
  188. typedef DecodingEnvironment *DecodingEnvironmentPtr;
  189. //! struct for context management
  190. typedef struct
  191. {
  192.   unsigned short state;         // index into state-table CP
  193.   unsigned char  MPS;           // Least Probable Symbol 0/1 CP
  194.   unsigned char dummy;          // for alignment
  195. } BiContextType;
  196. typedef BiContextType *BiContextTypePtr;
  197. /**********************************************************************
  198.  * C O N T E X T S   F O R   T M L   S Y N T A X   E L E M E N T S
  199.  **********************************************************************
  200.  */
  201. #define NUM_MB_TYPE_CTX  11
  202. #define NUM_B8_TYPE_CTX  9
  203. #define NUM_MV_RES_CTX   10
  204. #define NUM_REF_NO_CTX   6
  205. #define NUM_DELTA_QP_CTX 4
  206. #define NUM_MB_AFF_CTX 4
  207. #define NUM_TRANSFORM_SIZE_CTX 3
  208. typedef struct
  209. {
  210.   BiContextType mb_type_contexts [4][NUM_MB_TYPE_CTX];
  211.   BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
  212.   BiContextType mv_res_contexts  [2][NUM_MV_RES_CTX];
  213.   BiContextType ref_no_contexts  [2][NUM_REF_NO_CTX];
  214.   BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX];
  215.   BiContextType mb_aff_contexts  [NUM_MB_AFF_CTX];
  216.   BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
  217. } MotionInfoContexts;
  218. #define NUM_IPR_CTX    2
  219. #define NUM_CIPR_CTX   4
  220. #define NUM_CBP_CTX    4
  221. #define NUM_BCBP_CTX   4
  222. #define NUM_MAP_CTX   15
  223. #define NUM_LAST_CTX  15
  224. #define NUM_ONE_CTX    5
  225. #define NUM_ABS_CTX    5
  226. typedef struct
  227. {
  228.   BiContextType  ipr_contexts [NUM_IPR_CTX];
  229.   BiContextType  cipr_contexts[NUM_CIPR_CTX];
  230.   BiContextType  cbp_contexts [3][NUM_CBP_CTX];
  231.   BiContextType  bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
  232.   BiContextType  map_contexts [2][NUM_BLOCK_TYPES][NUM_MAP_CTX];
  233.   BiContextType  last_contexts[2][NUM_BLOCK_TYPES][NUM_LAST_CTX];
  234.   BiContextType  one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
  235.   BiContextType  abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
  236. } TextureInfoContexts;
  237. //*********************** end of data type definition for CABAC *******************
  238. /***********************************************************************
  239.  * N e w   D a t a    t y p e s   f o r    T M L
  240.  ***********************************************************************
  241.  */
  242. struct img_par;
  243. struct inp_par;
  244. struct stat_par;
  245. /*! Buffer structure for decoded referenc picture marking commands */
  246. typedef struct DecRefPicMarking_s
  247. {
  248.   int memory_management_control_operation;
  249.   int difference_of_pic_nums_minus1;
  250.   int long_term_pic_num;
  251.   int long_term_frame_idx;
  252.   int max_long_term_frame_idx_plus1;
  253.   struct DecRefPicMarking_s *Next;
  254. } DecRefPicMarking_t;
  255. //! Syntaxelement
  256. typedef struct syntaxelement
  257. {
  258.   int           type;                  //!< type of syntax element for data part.
  259.   int           value1;                //!< numerical value of syntax element
  260.   int           value2;                //!< for blocked symbols, e.g. run/level
  261.   int           len;                   //!< length of code
  262.   int           inf;                   //!< info part of UVLC code
  263.   unsigned int  bitpattern;            //!< UVLC bitpattern
  264.   int           context;               //!< CABAC context
  265.   int           k;                     //!< CABAC context for coeff_count,uv
  266. #if TRACE
  267.   #define       TRACESTRING_SIZE 100           //!< size of trace string
  268.   char          tracestring[TRACESTRING_SIZE]; //!< trace string
  269. #endif
  270.   //! for mapping of UVLC to syntaxElement
  271.   void    (*mapping)(int len, int info, int *value1, int *value2);
  272.   //! used for CABAC: refers to actual coding method of each individual syntax element type
  273.   void  (*reading)(struct syntaxelement *, struct img_par *img, DecodingEnvironmentPtr);
  274. } SyntaxElement;
  275. //! Macroblock
  276. typedef struct macroblock
  277. {
  278.   int           qp;                    //!< QP luma
  279.   int           qpc[2];                //!< QP chroma
  280.   int           qp_scaled[MAX_PLANE];  //!< QP scaled for all comps.
  281.   short         slice_nr;
  282.   short         delta_quant;          //!< for rate control
  283.   struct macroblock   *mb_available_up;   //!< pointer to neighboring MB (CABAC)
  284.   struct macroblock   *mb_available_left; //!< pointer to neighboring MB (CABAC)
  285.   // some storage of macroblock syntax elements for global access
  286.   int           mb_type;
  287.   short         mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2];      //!< indices correspond to [forw,backw][block_y][block_x][x,y]
  288.   int           cbp;
  289.   int64         cbp_blk ;
  290.   int64         cbp_blk_CbCr[2]; 
  291.   int64         cbp_bits    [3];
  292.   int64         cbp_bits_8x8[3];
  293.   int           i16mode;
  294.   char          b8mode[4];
  295.   char          b8pdir[4];
  296.   char          ei_flag;             //!< error indicator flag that enables concealment
  297.   char          dpl_flag;            //!< error indicator flag that signals a missing data partition
  298.   int           DFDisableIdc;
  299.   int           DFAlphaC0Offset;
  300.   int           DFBetaOffset;
  301.   int           c_ipred_mode;       //!< chroma intra prediction mode
  302.   byte          mb_field;
  303.   int           skip_flag;
  304.   int mbAddrX;
  305.   int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
  306.   int mbAvailA, mbAvailB, mbAvailC, mbAvailD;
  307.   int           luma_transform_size_8x8_flag;
  308.   int           NoMbPartLessThan8x8Flag;
  309. } Macroblock;
  310. //! Bitstream
  311. typedef struct
  312. {
  313.   // CABAC Decoding
  314.   int           read_len;           //!< actual position in the codebuffer, CABAC only
  315.   int           code_len;           //!< overall codebuffer length, CABAC only
  316.   // UVLC Decoding
  317.   int           frame_bitoffset;    //!< actual position in the codebuffer, bit-oriented, UVLC only
  318.   int           bitstream_length;   //!< over codebuffer lnegth, byte oriented, UVLC only
  319.   // ErrorConcealment
  320.   byte          *streamBuffer;      //!< actual codebuffer for read bytes
  321.   int           ei_flag;            //!< error indication, 0: no error, else unspecified error
  322. } Bitstream;
  323. //! DataPartition
  324. typedef struct datapartition
  325. {
  326.   Bitstream           *bitstream;
  327.   DecodingEnvironment de_cabac;
  328.   int     (*readSyntaxElement)(SyntaxElement *, struct img_par *, struct datapartition *);
  329.           /*!< virtual function;
  330.                actual method depends on chosen data partition and
  331.                entropy coding method  */
  332. } DataPartition;
  333. //! Slice
  334. typedef struct
  335. {
  336.   int                 ei_flag;       //!< 0 if the partArr[0] contains valid information
  337.   int                 qp;
  338.   int                 slice_qp_delta;
  339.   int                 qs;
  340.   int                 slice_qs_delta;
  341.   int                 picture_type;  //!< picture type
  342.   PictureStructure    structure;     //!< Identify picture structure type
  343.   int                 start_mb_nr;   //!< MUST be set by NAL even in case of ei_flag == 1
  344.   int                 max_part_nr;
  345.   int                 dp_mode;       //!< data partitioning mode
  346.   int                 next_header;
  347. //  int                 last_mb_nr;    //!< only valid when entropy coding == CABAC
  348.   DataPartition       *partArr;      //!< array of partitions
  349.   MotionInfoContexts  *mot_ctx;      //!< pointer to struct of context models for use in CABAC
  350.   TextureInfoContexts *tex_ctx;      //!< pointer to struct of context models for use in CABAC
  351.   int                 ref_pic_list_reordering_flag_l0;
  352.   int                 *reordering_of_pic_nums_idc_l0;
  353.   int                 *abs_diff_pic_num_minus1_l0;
  354.   int                 *long_term_pic_idx_l0;
  355.   int                 ref_pic_list_reordering_flag_l1;
  356.   int                 *reordering_of_pic_nums_idc_l1;
  357.   int                 *abs_diff_pic_num_minus1_l1;
  358.   int                 *long_term_pic_idx_l1;
  359.   int     (*readSlice)(struct img_par *, struct inp_par *);
  360.   int                 DFDisableIdc;     //!< Disable deblocking filter on slice
  361.   int                 DFAlphaC0Offset;  //!< Alpha and C0 offset for filtering slice
  362.   int                 DFBetaOffset;     //!< Beta offset for filtering slice
  363.   int                 pic_parameter_set_id;   //!<the ID of the picture parameter set the slice is reffering to
  364.   int                 dpB_NotPresent;    //!< non-zero, if data partition B is lost
  365.   int                 dpC_NotPresent;    //!< non-zero, if data partition C is lost
  366. } Slice;
  367. //****************************** ~DM ***********************************
  368. // image parameters
  369. typedef struct img_par
  370. {
  371.   int number;                                 //!< frame number
  372.   unsigned int current_mb_nr; // bitstream order
  373.   unsigned int num_dec_mb;
  374.   int current_slice_nr;
  375.   int *intra_block;
  376.   int tr;                                     //!< temporal reference, 8 bit, wrapps at 255
  377.   int qp;                                     //!< quant for the current frame
  378.   int qpsp;                                   //!< quant for SP-picture predicted frame
  379.   int sp_switch;                              //!< 1 for switching sp, 0 for normal sp
  380.   int direct_spatial_mv_pred_flag;            //!< 1 for Spatial Direct, 0 for Temporal
  381.   int type;                                   //!< image type INTER/INTRA
  382.   int width;
  383.   int height;
  384.   int width_cr;                               //!< width chroma
  385.   int width_cr_m1;                               //!< width chroma
  386.   int height_cr;                              //!< height chroma
  387.   int mb_x;
  388.   int mb_y;
  389.   int block_x;
  390.   int block_y;
  391.   int block_y_aff;
  392.   int pix_x;
  393.   int pix_y;
  394.   int pix_c_x;
  395.   int pix_c_y;
  396.   int allrefzero;
  397.   
  398.   int mvscale[6][MAX_REFERENCE_PICTURES];
  399.   imgpel mb_pred[MAX_PLANE][16][16];     //!< predicted block
  400.   int    mb_rres[MAX_PLANE][16][16];     //!< residual macroblock
  401.   int    cof[MAX_PLANE][16][16];     //!< transformed coefficients 
  402.   int    fcf[MAX_PLANE][16][16];     //!< transformed coefficients 
  403.   
  404.   int cofu[16];
  405.   byte **ipredmode;                  //!< prediction type [90][74]
  406.   int ****nz_coeff;
  407.   int **siblock;
  408.   int cod_counter;                   //!< Current count of number of skipped macroblocks in a row
  409.   int newframe;
  410.   int structure;                     //!< Identify picture structure type
  411.   // B pictures
  412.   Slice      *currentSlice;          //!< pointer to current Slice data struct
  413.   Macroblock *mb_data;               //!< array containing all MBs of a whole frame
  414.   Macroblock *mb_data_JV[MAX_PLANE]; //!< mb_data to be used for 4:4:4 independent mode
  415.   int colour_plane_id;               //!< colour_plane_id of the current coded slice
  416.   int ChromaArrayType;
  417.   int subblock_x;
  418.   int subblock_y;
  419.   int is_intra_block;
  420.   int is_v_block;
  421.   // For MB level frame/field coding
  422.   int MbaffFrameFlag;
  423.   // for signalling to the neighbour logic that this is a deblocker call
  424.   int DeblockCall;
  425.   DecRefPicMarking_t *dec_ref_pic_marking_buffer;                    //!< stores the memory management control operations
  426.   int num_ref_idx_l0_active;             //!< number of forward reference
  427.   int num_ref_idx_l1_active;             //!< number of backward reference
  428.   int slice_group_change_cycle;
  429.   int redundant_pic_cnt;
  430.   int explicit_B_prediction;
  431.   unsigned int pre_frame_num;           //!< store the frame_num in the last decoded slice. For detecting gap in frame_num.
  432.   // End JVT-D101
  433.   // POC200301: from unsigned int to int
  434.            int toppoc;      //poc for this top field // POC200301
  435.            int bottompoc;   //poc of bottom field of frame
  436.            int framepoc;    //poc of this frame // POC200301
  437.   unsigned int frame_num;   //frame_num for this frame
  438.   unsigned int field_pic_flag;
  439.   byte         bottom_field_flag;
  440.   //the following is for slice header syntax elements of poc
  441.   // for poc mode 0.
  442.   unsigned int pic_order_cnt_lsb;
  443.            int delta_pic_order_cnt_bottom;
  444.   // for poc mode 1.
  445.            int delta_pic_order_cnt[3];
  446.   // ////////////////////////
  447.   // for POC mode 0:
  448.     signed int PrevPicOrderCntMsb;
  449.   unsigned int PrevPicOrderCntLsb;
  450.     signed int PicOrderCntMsb;
  451.   // for POC mode 1:
  452.   unsigned int AbsFrameNum;
  453.     signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle;
  454.   unsigned int PreviousFrameNum, FrameNumOffset;
  455.            int ExpectedDeltaPerPicOrderCntCycle;
  456.            int PreviousPOC, ThisPOC;
  457.            int PreviousFrameNumOffset;
  458.   // /////////////////////////
  459.   //weighted prediction
  460.   unsigned int luma_log2_weight_denom;
  461.   unsigned int chroma_log2_weight_denom;
  462.   int ***wp_weight;  // weight in [list][index][component] order
  463.   int ***wp_offset;  // offset in [list][index][component] order
  464.   int ****wbp_weight; //weight in [list][fw_index][bw_index][component] order
  465.   int wp_round_luma;
  466.   int wp_round_chroma;
  467.   unsigned int apply_weights;
  468.   int idr_flag;
  469.   int nal_reference_idc;                       //!< nal_reference_idc from NAL unit
  470.   int idr_pic_id;
  471.   int MaxFrameNum;
  472.   unsigned int PicWidthInMbs;
  473.   unsigned int PicHeightInMapUnits;
  474.   unsigned int FrameHeightInMbs;
  475.   unsigned int PicHeightInMbs;
  476.   unsigned int PicSizeInMbs;
  477.   unsigned int FrameSizeInMbs;
  478.   unsigned int oldFrameSizeInMbs;
  479.   int no_output_of_prior_pics_flag;
  480.   int long_term_reference_flag;
  481.   int adaptive_ref_pic_buffering_flag;
  482.   int last_has_mmco_5;
  483.   int last_pic_bottom_field;
  484.   int model_number;
  485.   // Fidelity Range Extensions Stuff
  486.   int pic_unit_bitsize_on_disk;
  487.   int bitdepth_luma;
  488.   int bitdepth_chroma;
  489.   int bitdepth_scale[2];
  490.   int bitdepth_luma_qp_scale;
  491.   int bitdepth_chroma_qp_scale;
  492.   unsigned int dc_pred_value_comp[MAX_PLANE]; //!< component value for DC prediction (depends on component pel bit depth)
  493.   int max_imgpel_value_comp[MAX_PLANE];       //!< max value that one picture element (pixel) can take (depends on pic_unit_bitdepth)
  494.   int Transform8x8Mode;
  495.   int profile_idc;
  496.   int yuv_format;
  497.   int lossless_qpprime_flag;
  498.   int num_blk8x8_uv;
  499.   int num_uv_blocks;
  500.   int num_cdc_coeff;
  501.   int mb_cr_size_x;
  502.   int mb_cr_size_y;
  503.   int mb_cr_size_x_blk;
  504.   int mb_cr_size_y_blk;
  505.   int mb_size[3][2];                         //!< component macroblock dimensions
  506.   int mb_size_blk[3][2];                     //!< component macroblock dimensions 
  507.   int mb_size_shift[3][2];
  508.   
  509.   int max_vmv_r;                             //!< maximum vertical motion vector range in luma quarter frame pixel units for the current level_idc
  510.   int max_mb_vmv_r;                          //!< maximum vertical motion vector range in luma quarter pixel units for the current level_idc
  511.   int idr_psnr_number;
  512.   int psnr_number;
  513.   // Timing related variables
  514.   TIME_T start_time;
  515.   TIME_T end_time;
  516.   // picture error concealment
  517.   int last_ref_pic_poc;
  518.   int ref_poc_gap;
  519.   int poc_gap;
  520.   int conceal_mode;
  521.   int earlier_missing_poc;
  522.   unsigned int frame_to_conceal;
  523.   int IDR_concealment_flag;
  524.   int conceal_slice_type;
  525.   // random access point decoding
  526.   int recovery_point;
  527.   int recovery_point_found;
  528.   int recovery_frame_cnt;
  529.   int recovery_frame_num;
  530.   int recovery_poc;
  531.   int  separate_colour_plane_flag;
  532. } ImageParameters;
  533. extern ImageParameters *img;
  534. extern struct snr_par  *snr;
  535. // signal to noise ratio parameters
  536. struct snr_par
  537. {
  538.   int   frame_ctr;
  539.   float snr[3];                                //!< current SNR (component)
  540.   float snr1[3];                               //!< SNR (dB) first frame (component)
  541.   float snra[3];                               //!< Average component SNR (dB) remaining frames
  542.   float sse[3];                                //!< component SSE 
  543.   float msse[3];                                //!< Average component SSE 
  544. };
  545. time_t tot_time;
  546. // input parameters from configuration file
  547. struct inp_par
  548. {
  549.   char infile[FILE_NAME_SIZE];                       //!< H.264 inputfile
  550.   char outfile[FILE_NAME_SIZE];                      //!< Decoded YUV 4:2:0 output
  551.   char reffile[FILE_NAME_SIZE];                      //!< Optional YUV 4:2:0 reference file for SNR measurement
  552.   int FileFormat;                         //!< File format of the Input file, PAR_OF_ANNEXB or PAR_OF_RTP
  553.   int ref_offset;
  554.   int poc_scale;
  555.   int write_uv;
  556.   int silent;
  557.   int intra_profile_deblocking;               //!< Loop filter usage determined by flags and parameters in bitstream 
  558. #ifdef _LEAKYBUCKET_
  559.   unsigned long R_decoder;                //!< Decoder Rate in HRD Model
  560.   unsigned long B_decoder;                //!< Decoder Buffer size in HRD model
  561.   unsigned long F_decoder;                //!< Decoder Initial buffer fullness in HRD model
  562.   char LeakyBucketParamFile[100];         //!< LeakyBucketParamFile
  563. #endif
  564.   // picture error concealment
  565.   int conceal_mode;
  566.   int ref_poc_gap;
  567.   int poc_gap;
  568. };
  569. extern struct inp_par *params;
  570. typedef struct pix_pos
  571. {
  572.   int  available;
  573.   int  mb_addr;
  574.   int  x;
  575.   int  y;
  576.   int  pos_x;
  577.   int  pos_y;
  578. } PixelPos;
  579. typedef struct old_slice_par
  580. {
  581.    unsigned field_pic_flag;   
  582.    unsigned frame_num;
  583.    int nal_ref_idc;
  584.    unsigned pic_oder_cnt_lsb;
  585.    int delta_pic_oder_cnt_bottom;
  586.    int delta_pic_order_cnt[2];
  587.    byte idr_flag;
  588.    int idr_pic_id;
  589.    int pps_id;
  590.    byte bottom_field_flag;
  591. } OldSliceParams;
  592. extern OldSliceParams old_slice;
  593. // files
  594. int p_out;                    //!< file descriptor to output YUV file
  595. //FILE *p_out2;                    //!< pointer to debug output YUV file
  596. int p_ref;                    //!< pointer to input original reference YUV file file
  597. FILE *p_log;                    //!< SNR file
  598. #if TRACE
  599. FILE *p_trace;
  600. #endif
  601. // Redundant slices
  602. unsigned int previous_frame_num; //!< frame number of previous slice
  603. int ref_flag[17];                //!< 0: i-th previous frame is incorrect
  604.                                  //!< non-zero: i-th previous frame is correct
  605. int Is_primary_correct;          //!< if primary frame is correct, 0: incorrect
  606. int Is_redundant_correct;        //!< if redundant frame is correct, 0:incorrect
  607. int redundant_slice_ref_idx;     //!< reference index of redundant slice
  608. void Error_tracking(void);
  609. // prototypes
  610. void init_conf(struct inp_par *inp, char *config_filename);
  611. void report(struct inp_par *inp, ImageParameters *img, struct snr_par *snr);
  612. void init(ImageParameters *img);
  613. void malloc_slice(struct inp_par *inp, ImageParameters *img);
  614. void free_slice(ImageParameters *img);
  615. int  decode_one_frame(ImageParameters *img,struct inp_par *inp, struct snr_par *snr);
  616. void init_picture(ImageParameters *img, struct inp_par *inp);
  617. void exit_picture(void);
  618. int  read_new_slice(void);
  619. void decode_one_slice(ImageParameters *img, struct inp_par *inp);
  620. void start_macroblock     (ImageParameters *img, Macroblock **currMB);
  621. void read_one_macroblock  (ImageParameters *img, Macroblock *currMB);
  622. Boolean  exit_macroblock  (ImageParameters *img, int eos_bit);
  623. void concealIPCMcoeffs    (ImageParameters *img);
  624. void SetMotionVectorPredictor (ImageParameters  *img, Macroblock *currMB, short pmv[2], char ref_frame, byte list, 
  625.                                char ***refPic, short ****tmp_mv, 
  626.                                int mb_x, int mb_y, int blockshape_x, int blockshape_y);
  627. int  intrapred_luma_16x16(ImageParameters *img, Macroblock *currMB, ColorPlane pl, int predmode);
  628. void intrapred_chroma    (ImageParameters *img, Macroblock *currMB, int uv);
  629. // SLICE function pointers
  630. int  (*nal_startcode_follows) (Slice*, int );
  631. // NAL functions TML/CABAC bitstream
  632. int  uvlc_startcode_follows(Slice *currSlice, int dummy);
  633. int  cabac_startcode_follows(Slice *currSlice, int eos_bit);
  634. void free_Partition(Bitstream *currStream);
  635. // ErrorConcealment
  636. void reset_ec_flags(void);
  637. void error(char *text, int code);
  638. int  is_new_picture(void);
  639. void init_old_slice(void);
  640. // dynamic mem allocation
  641. int  init_global_buffers(void);
  642. void free_global_buffers(void);
  643. void frame_postprocessing(ImageParameters *img);
  644. void field_postprocessing(ImageParameters *img);
  645. void decode_slice(ImageParameters *img,struct inp_par *inp, int current_header);
  646. int RBSPtoSODB(byte *streamBuffer, int last_byte_pos);
  647. int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos);
  648. int peekSyntaxElement_UVLC(SyntaxElement *sym, ImageParameters *img, struct datapartition *dP);
  649. void fill_wp_params(ImageParameters *img);
  650. void reset_wp_params(ImageParameters *img);
  651. void FreePartition (DataPartition *dp, int n);
  652. DataPartition *AllocPartition(int n);
  653. void tracebits2(const char *trace_str, int len, int info);
  654. void init_decoding_engine_IPCM(ImageParameters *img);
  655. void readIPCM_CABAC(struct datapartition *dP);
  656. unsigned CeilLog2( unsigned uiVal);
  657. unsigned CeilLog2_sf( unsigned uiVal);
  658. //For residual DPCM
  659. int ipmode_DPCM;
  660. // For 4:4:4 independent mode
  661. void change_plane_JV( int nplane );
  662. void make_frame_picture_JV(void);
  663. #endif