📄 global.h
字号:
/*!
************************************************************************
* \file
* global.h
* \brief
* global definitions for for H.26L decoder.
* \author
* Copyright (C) 1999 Telenor Satellite Services,Norway
* Ericsson Radio Systems, Sweden
*
* Inge Lille-Langoy <inge.lille-langoy@telenor.com>
*
* Telenor Satellite Services
* Keysers gt.13 tel.: +47 23 13 86 98
* N-0130 Oslo,Norway fax.: +47 22 77 79 80
*
* Rickard Sjoberg <rickard.sjoberg@era.ericsson.se>
*
* Ericsson Radio Systems
* KI/ERA/T/VV
* 164 80 Stockholm, Sweden
*
************************************************************************
*/
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include <stdio.h> //!< for FILE
#include "defines.h"
#include "parsetcommon.h"
typedef unsigned char byte; //!< 8 bit unsigned
typedef int int32;
typedef unsigned int u_int32;
typedef __int64 int64;
# define INT64_MIN (-9223372036854775807i64 - 1i64)
/***********************************************************************
* T y p e d e f i n i t i o n s f o r T M L
***********************************************************************
*/
//! Data Partitioning Modes
typedef enum
{
PAR_DP_1, //<! no data partitioning is supported
PAR_DP_3, //<! data partitioning with 3 partitions
} PAR_DP_TYPE;
//! Output File Types
typedef enum
{
PAR_OF_ANNEXB, //<! Current TML description
PAR_OF_RTP, //<! RTP Packet Output format
} PAR_OF_TYPE;
//! definition of H.26L syntax elements
typedef enum {
SE_HEADER,
SE_PTYPE,
SE_MBTYPE,
SE_REFFRAME,
SE_INTRAPREDMODE,
SE_MVD,
SE_CBP_INTRA,
SE_LUM_DC_INTRA,
SE_CHR_DC_INTRA,
SE_LUM_AC_INTRA,
SE_CHR_AC_INTRA,
SE_CBP_INTER,
SE_LUM_DC_INTER,
SE_CHR_DC_INTER,
SE_LUM_AC_INTER,
SE_CHR_AC_INTER,
SE_DELTA_QUANT_INTER,
SE_DELTA_QUANT_INTRA,
SE_BFRAME,
SE_EOS,
SE_MAX_ELEMENTS //!< number of maximum syntax elements, this MUST be the last one!
} SE_type; // substituting the definitions in element.h
typedef enum {
INTER_MB,
INTRA_MB_4x4,
INTRA_MB_16x16
} IntraInterDecision;
typedef enum {
UVLC,
CABAC
} SymbolMode;
typedef enum {
P_SLICE = 0,
B_SLICE,
I_SLICE,
SP_SLICE,
SI_SLICE
} SliceType;
//*********************** end of data type definition for CABAC *******************
/***********************************************************************
* N e w D a t a t y p e s f o r T M L
***********************************************************************
*/
struct img_par;
/*! Buffer structure for decoded referenc picture marking commands */
typedef struct DecRefPicMarking_s
{
int memory_management_control_operation;
int difference_of_pic_nums_minus1;
int long_term_pic_num;
int long_term_frame_idx;
int max_long_term_frame_idx_plus1;
struct DecRefPicMarking_s *Next;
} DecRefPicMarking_t;
//! Syntaxelement
typedef struct syntaxelement
{
int type; //!< type of syntax element for data part.
int value1; //!< numerical value of syntax element
int value2; //!< for blocked symbols, e.g. run/level
int len; //!< length of code
int inf; //!< info part of UVLC code
unsigned int bitpattern; //!< UVLC bitpattern
//! for mapping of UVLC to syntaxElement
void (*mapping)(int len, int info, int *value1, int *value2);
} SyntaxElement;
//! Macroblock
typedef struct macroblock
{
int qp;
int slice_nr;
int delta_quant; //!< for rate control
struct macroblock *mb_available_up; //!< pointer to neighboring MB (CABAC)
struct macroblock *mb_available_left; //!< pointer to neighboring MB (CABAC)
// some storage of macroblock syntax elements for global access
int mb_type;
int mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2]; //!< indices correspond to [forw,backw][block_y][block_x][x,y]
int cbp, cbp_blk ;
int i16mode;
int b8mode[4];
int b8pdir[4];
int ei_flag;
int LFDisableIdc;
int LFAlphaC0Offset;
int LFBetaOffset;
int c_ipred_mode; //!< chroma intra prediction mode
int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
int mbAvailA, mbAvailB, mbAvailC, mbAvailD;
} Macroblock;
//! Bitstream
typedef struct
{
// UVLC Decoding
int frame_bitoffset; //!< actual position in the codebuffer, bit-oriented, UVLC only
int bitstream_length; //!< over codebuffer lnegth, byte oriented, UVLC only
// ErrorConcealment
byte *streamBuffer; //!< actual codebuffer for read bytes
int ei_flag; //!< error indication, 0: no error, else unspecified error
} Bitstream;
//! DataPartition
typedef struct datapartition
{
Bitstream *bitstream;
int (*readSyntaxElement)(SyntaxElement *, struct datapartition *);
/*!< virtual function;
actual method depends on chosen data partition and
entropy coding method */
} DataPartition;
//! Slice
typedef struct
{
int ei_flag; //!< 0 if the partArr[0] contains valid information
int qp;
int picture_type; //!< picture type
int start_mb_nr; //!< MUST be set by NAL even in case of ei_flag == 1
int max_part_nr;
int dp_mode; //!< data partioning mode
int next_header;
DataPartition *partArr; //!< array of partitions
int ref_pic_list_reordering_flag_l0;
int *remapping_of_pic_nums_idc_l0;
int *abs_diff_pic_num_minus1_l0;
int *long_term_pic_idx_l0;
int (*readSlice)(struct img_par *);
int LFDisableIdc; //!< Disable loop filter on slice
int LFAlphaC0Offset; //!< Alpha and C0 offset for filtering slice
int LFBetaOffset; //!< Beta offset for filtering slice
int pic_parameter_set_id; //!<the ID of the picture parameter set the slice is reffering to
} Slice;
//****************************** ~DM ***********************************
// image parameters
typedef struct img_par
{
int number; //<! frame number
unsigned current_mb_nr; // bitstream order
unsigned num_dec_mb;
int current_slice_nr;
int *intra_block;
int tr; //<! temporal reference, 8 bit, wrapps at 255
int tr_old; //<! old temporal reference, for detection of a new frame, added by WYK
int qp; //<! quant for the current frame
int direct_type; //<! 1 for Spatial Direct, 0 for Temporal
int type; //<! image type INTER/INTRA
int width;
int height;
int width_cr; //<! width chroma
int height_cr; //<! height chroma
int mb_y;
int mb_x;
int block_y;
int pix_y;
int pix_x;
int pix_c_y;
int block_x;
int pix_c_x;
int allrefzero;
int mpr[16][16]; //<! predicted block
int m7[16][16]; //<! final 4x4 block. Extended to 16x16 for ABT
int cof[4][6][4][4]; //<! correction coefficients from predicted
int cofu[4];
int **ipredmode; //<! prediction type [90][74]
int quad[256];
int constrained_intra_pred_flag; //<! if 1, prediction only from other Intra MBs
int ***nz_coeff;
int cod_counter; //<! Current count of number of skipped macroblocks in a row
int structure; //<! Identify picture structure type
int pstruct_next_P;
Slice *currentSlice; //<! pointer to current Slice data struct
Macroblock *mb_data; //<! array containing all MBs of a whole frame
// for signalling to the neighbour logic that this is a deblocker call
int DeblockCall;
DecRefPicMarking_t *dec_ref_pic_marking_buffer; //<! stores the memory management control operations
int disposable_flag; //!< flag for disposable frame, 1:disposable
int num_ref_idx_l0_active; //!< number of forward reference
int slice_group_change_cycle;
// JVT-D101
//int redundant_slice_flag;
int redundant_pic_cnt;
unsigned int pre_frame_num; //!< store the frame_num in the last decoded slice. For detecting gap in frame_num.
// End JVT-D101
// POC200301: from unsigned int to int
int toppoc; //poc for this top field // POC200301
int bottompoc; //poc of bottom field of frame
int framepoc; //poc of this frame // POC200301
unsigned int frame_num; //frame_num for this frame
unsigned int field_pic_flag;
//the following should probably go in sequence parameters
unsigned int pic_order_cnt_type;
// for poc mode 1, POC200301
unsigned int delta_pic_order_always_zero_flag;
int offset_for_non_ref_pic;
int offset_for_top_to_bottom_field;
unsigned int num_ref_frames_in_pic_order_cnt_cycle;
int offset_for_ref_frame[MAXnum_ref_frames_in_pic_order_cnt_cycle];
// POC200301
//the following is for slice header syntax elements of poc
// for poc mode 0.
unsigned int pic_order_cnt_lsb;
int delta_pic_order_cnt_bottom;
// for poc mode 1.
int delta_pic_order_cnt[3];
// ////////////////////////
// for POC mode 0:
signed int PrevPicOrderCntMsb;
unsigned int PrevPicOrderCntLsb;
signed int PicOrderCntMsb;
// for POC mode 1:
unsigned int AbsFrameNum;
signed int ExpectedPicOrderCnt, PicOrderCntCycleCnt, FrameNumInPicOrderCntCycle;
unsigned int PreviousFrameNum, FrameNumOffset;
int ExpectedDeltaPerPicOrderCntCycle;
int ThisPOC;
int PreviousFrameNumOffset;
// /////////////////////////
//weighted prediction
unsigned int weighted_pred_flag;
unsigned int weighted_bipred_idc;
unsigned int luma_log2_weight_denom;
unsigned int chroma_log2_weight_denom;
int ***wp_weight; // weight in [list][index][component] order
int ***wp_offset; // offset in [list][index][component] order
int wp_round_luma;
int wp_round_chroma;
unsigned int apply_weights;
unsigned int pic_order_present_flag;
int idr_flag;
int nal_reference_idc; //!< nal_reference_idc from NAL unit
int idr_pic_id;
int MaxFrameNum;
unsigned PicWidthInMbs;
unsigned PicHeightInMapUnits;
unsigned FrameHeightInMbs;
unsigned PicHeightInMbs;
unsigned PicSizeInMbs;
unsigned FrameSizeInMbs;
int no_output_of_prior_pics_flag;
int long_term_reference_flag;
int adaptive_ref_pic_buffering_flag;
int last_has_mmco_5;
} ImageParameters;
extern ImageParameters *img;
typedef struct pix_pos
{
int available;
int mb_addr;
int x;
int y;
int pos_x;
int pos_y;
} PixelPos;
static const int block_mode[4][4] = {{1,3,2,3},{5,9,7,9},{4,8,6,8},{5,9,7,9}};
/* block_mode indicate the position of (dy,dx)
* (0,0)(0,1)(0,2)(0,3) |1 3 2 3|
* (1,0)(1,1)(1,2)(1,3) |5 9 7 9|
* (2,0)(2,1)(2,2)(2,3) |4 8 6 8|
* (3,0)(3,1)(3,2)(3,3) |5 9 7 9|
*1: dx=dy=0 fullpel position, no interpolation is needed
*2: dy=0, dx=2, which means only horizontal interpolation at 1/2 pixel is needed
*3: dy=0, dx=1,3, which means horizontal interpolation at 1/4 pixel is needed
*4: dy=2, dx=0, which means only vertical interpolation 1/2 pixel is needed
*5: dy=1,3,dx=0, which means vertical interpolation at 1/4 pixel is needed
*6: dy=2, dx=2, which means both vertical and horizontal interpolation at 1/2 pixel are needed
*7: dy=1,3,dx=2, which means both horizontal interpolation at 1/2 pixel and vertical interpolation at 1/4 pixel are needed
*8: dy=2, dx=1,3, which means both vertical interpolation at 1/2 pixel and horizontal interpolation at 1/4 pixel are needed
*9: dy=dx=1,3 Diagonal interpolation, which means both vertical and horizontal interpolation at 1/4 pixel are needed
*/
void malloc_slice(struct img_par *img);
void free_slice(struct img_par *img);
int decode_one_frame(struct img_par *img);
void init_frame(struct img_par *img);
void DeblockFrame(struct img_par *img, byte **imgY, byte ***imgUV ) ;
int read_new_slice();
void start_macroblock(struct img_par *img, int CurrentMBInScanOrder);
void read_one_macroblock(struct img_par *img);
void read_ipred_modes(struct img_par *img);
int decode_one_macroblock(struct img_par *img);
Boolean exit_macroblock(struct img_par *img, int eos_bit);
void decode_ipcm_mb(struct img_par *img);
void readMotionInfoFromNAL (struct img_par *img);
void readCBPandCoeffsFromNAL(struct img_par *img);
void readIPCMcoeffsFromNAL(struct img_par *img, struct datapartition *dP);
void itrans(struct img_par *img,int ioff,int joff,int i0,int j0);
int intrapred(struct img_par *img,int ioff,int joff,int i4,int j4);
void itrans_2(struct img_par *img);
int intrapred_luma_16x16(struct img_par *img,int predmode);
void intrapred_chroma(struct img_par *img, int uv);
// NAL functions TML/CABAC bitstream
int uvlc_startcode_follows(struct img_par *img, int dummy);
void error(char *text, int code);
// dynamic mem allocation
int init_global_buffers(struct img_par *img);
void free_global_buffers(struct img_par *img);
#define PAYLOAD_TYPE_IDERP 8
int RBSPtoSODB(byte *streamBuffer, int last_byte_pos);
int EBSPtoRBSP(byte *streamBuffer, int end_bytepos);
void reset_wp_params(struct img_par *img);
void FreePartition (DataPartition *dp, int n);
DataPartition *AllocPartition(int n);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -