📄 global.h
字号:
/*!
************************************************************************
* \file
* global.h
* \brief
* global definitions for H.264 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>
#include <stdarg.h>
#include <time.h>
//#include <sys/timeb.h>
#include "win32.h"
#include "defines.h"
#include "ifunctions.h"
#include "parsetcommon.h"
typedef unsigned char byte; //!< 8 bit unsigned
#if (IMGTYPE == 1)
typedef unsigned short imgpel; //!< Pixel type definition (16 bit for FRExt)
#else
typedef unsigned char imgpel; //!< Pixel type definition (8 bit without FRExt)
#endif
pic_parameter_set_rbsp_t *active_pps;
seq_parameter_set_rbsp_t *active_sps;
// global picture format dependent buffers, memory allocation in decod.c
//imgpel **imgY_ref; //!< reference frame find snr
//imgpel ***imgUV_ref;
int **PicPos;
int ReMapRef[20];
// B pictures
//int Bframe_ctr;
int frame_no;
//int g_nFrame;
// For MB level frame/field coding
int TopFieldForSkip_Y[16][16];
int TopFieldForSkip_UV[2][16][16];
int InvLevelScale4x4Luma_Intra[6][4][4];
int InvLevelScale4x4Chroma_Intra[2][6][4][4];
int InvLevelScale4x4Luma_Inter[6][4][4];
int InvLevelScale4x4Chroma_Inter[2][6][4][4];
int InvLevelScale8x8Luma_Intra[6][8][8];
int InvLevelScale8x8Luma_Inter[6][8][8];
int *qmatrix[8];
#define ET_SIZE 300 //!< size of error text buffer
char errortext[ET_SIZE]; //!< buffer for error message for exit with error()
/***********************************************************************
* 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.264 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
{
BITS_TOTAL_MB,
BITS_HEADER_MB,
BITS_INTER_MB,
BITS_CBP_MB,
BITS_COEFF_Y_MB,
BITS_COEFF_UV_MB,
MAX_BITCOUNTER_MB
} BitCountType;
typedef enum
{
NO_SLICES,
FIXED_MB,
FIXED_RATE,
CALL_BACK
} SliceMode;
typedef enum
{
UVLC,
CABAC
} SymbolMode;
typedef enum
{
LIST_0=0,
LIST_1=1
} Lists;
typedef enum
{
FRAME,
TOP_FIELD,
BOTTOM_FIELD
} PictureStructure; //!< New enum for field processing
typedef enum
{
P_SLICE = 0,
B_SLICE,
I_SLICE,
SP_SLICE,
SI_SLICE
} SliceType;
typedef enum
{
IS_LUMA = 0,
IS_CHROMA = 1
} Component_Type;
typedef enum
{
LumaComp = 0,
CrComp = 1,
CbComp = 2
} Color_Component;
/***********************************************************************
* D a t a t y p e s f o r C A B A C
***********************************************************************
*/
//! struct to characterize the state of the arithmetic coding engine
typedef struct
{
unsigned int Drange;
unsigned int Dvalue;
int DbitsLeft;
byte *Dcodestrm;
int *Dcodestrm_len;
} DecodingEnvironment;
typedef DecodingEnvironment *DecodingEnvironmentPtr;
//! struct for context management
typedef struct
{
unsigned short state; // index into state-table CP
unsigned char MPS; // Least Probable Symbol 0/1 CP
unsigned char dummy; // for alignment
} BiContextType;
typedef BiContextType *BiContextTypePtr;
/**********************************************************************
* 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
**********************************************************************
*/
#define NUM_MB_TYPE_CTX 11
#define NUM_B8_TYPE_CTX 9
#define NUM_MV_RES_CTX 10
#define NUM_REF_NO_CTX 6
#define NUM_DELTA_QP_CTX 4
#define NUM_MB_AFF_CTX 4
#define NUM_TRANSFORM_SIZE_CTX 3
typedef struct
{
BiContextType mb_type_contexts [4][NUM_MB_TYPE_CTX];
BiContextType b8_type_contexts [2][NUM_B8_TYPE_CTX];
BiContextType mv_res_contexts [2][NUM_MV_RES_CTX];
BiContextType ref_no_contexts [2][NUM_REF_NO_CTX];
BiContextType delta_qp_contexts[NUM_DELTA_QP_CTX];
BiContextType mb_aff_contexts [NUM_MB_AFF_CTX];
BiContextType transform_size_contexts [NUM_TRANSFORM_SIZE_CTX];
} MotionInfoContexts;
#define NUM_IPR_CTX 2
#define NUM_CIPR_CTX 4
#define NUM_CBP_CTX 4
#define NUM_BCBP_CTX 4
#define NUM_MAP_CTX 15
#define NUM_LAST_CTX 15
#define NUM_ONE_CTX 5
#define NUM_ABS_CTX 5
typedef struct
{
BiContextType ipr_contexts [NUM_IPR_CTX];
BiContextType cipr_contexts[NUM_CIPR_CTX];
BiContextType cbp_contexts [3][NUM_CBP_CTX];
BiContextType bcbp_contexts[NUM_BLOCK_TYPES][NUM_BCBP_CTX];
BiContextType map_contexts [NUM_BLOCK_TYPES][NUM_MAP_CTX];
BiContextType last_contexts[NUM_BLOCK_TYPES][NUM_LAST_CTX];
BiContextType one_contexts [NUM_BLOCK_TYPES][NUM_ONE_CTX];
BiContextType abs_contexts [NUM_BLOCK_TYPES][NUM_ABS_CTX];
BiContextType fld_map_contexts [NUM_BLOCK_TYPES][NUM_MAP_CTX];
BiContextType fld_last_contexts[NUM_BLOCK_TYPES][NUM_LAST_CTX];
} TextureInfoContexts;
//*********************** 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
***********************************************************************
*/
/* following datas' value actually calaulated from width and height, here just demo its usage */
#define PIC_MEMORY_BASE 0x00200000
#define MV_MEMORY_BASE 0x015b0000
#define FF_MEMORY_BASE 0x019ac000
#define Y_BANK 0x0005c000
#define UV_BANK 0x0002e000
#define MV_BANK 0x00015180
#define FF_BANK 0x00000200
typedef enum
{
NOACTION,
OCCUPY,
DISPLAY,
RELEASE,
RESTART,
} OperationType; //!< New enum for Memory Operation.
typedef enum
{
IS_FRAME,
IS_FIELD
} FrameFieldFlag; //!< New enum for Memory Operation.
typedef struct MemoryOperation_s
{
OperationType action;
int memory_start;
FrameFieldFlag frame_field;
}MemoryOperation_t;
#define MAX_MEMORY_OPERATION_ITEMS 128
MemoryOperation_t memory_operation[MAX_MEMORY_OPERATION_ITEMS];
unsigned int memory_operation_size;
typedef struct Register_s
{
int address;
int data;
}Register_t;
#define MAX_WRITE_REG_ITEMS 512
Register_t h264_reg[MAX_WRITE_REG_ITEMS];
unsigned int h264_reg_size;
void write_reg(int address, int data);
struct img_par;
struct inp_par;
struct stat_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
int context; //!< CABAC context
int k; //!< CABAC context for coeff_count,uv
#if TRACE
#define TRACESTRING_SIZE 100 //!< size of trace string
char tracestring[TRACESTRING_SIZE]; //!< trace string
#endif
//! for mapping of UVLC to syntaxElement
void (*mapping)(int len, int info, int *value1, int *value2);
//! used for CABAC: refers to actual coding method of each individual syntax element type
void (*reading)(struct syntaxelement *, struct img_par *, DecodingEnvironmentPtr);
} SyntaxElement;
//! Macroblock
typedef struct macroblock
{
int qp; //!< QP luma
int qpc[2]; //!< QP chroma
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;
int64 cbp_blk ;
int64 cbp_bits;
int is_skip;
int i16mode;
char b8mode[4];
char b8pdir[4];
int ei_flag;
int LFDisableIdc;
int LFAlphaC0Offset;
int LFBetaOffset;
int c_ipred_mode; //!< chroma intra prediction mode
int mb_field;
int skip_flag;
int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
int mbAvailA, mbAvailB, mbAvailC, mbAvailD;
int luma_transform_size_8x8_flag;
int NoMbPartLessThan8x8Flag;
} Macroblock;
//! Bitstream
typedef struct
{
// CABAC Decoding
int read_len; //!< actual position in the codebuffer, CABAC only
int code_len; //!< overall codebuffer length, CABAC only
// 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;
DecodingEnvironment de_cabac;
int (*readSyntaxElement)(SyntaxElement *, struct img_par *, 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 slice_qp_delta;
int picture_type; //!< picture type
PictureStructure structure; //!< Identify picture structure type
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -