📄 umc_base_bitstream.h
字号:
//// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2004 - 2005 Intel Corporation. All Rights Reserved.//#ifndef C3BS_H__#define C3BS_H__#include "umc_h264_pub.h"// ---------------------------------------------------------------------------// CBaseBitstream - bitstream base class// ---------------------------------------------------------------------------namespace UMC{typedef struct CABAC_CONTEXT{ unsigned short pStateIdx; // (unsigned short int) probability state index bool valMPS; // bool value of most probable symbol} CABAC_CONTEXT;enum // Syntax element type{ MB_SKIP_FLAG_P_SP = 0, MB_SKIP_FLAG_B = 1, MB_FIELD_DECODING_FLAG = 2, MB_TYPE_SI = 3, MB_TYPE_I = 4, MB_TYPE_P_SP = 5, MB_TYPE_B = 6, CODED_BLOCK_PATTERN_LUMA = 7, CODED_BLOCK_PATTERN_CHROMA = 8, MB_QP_DELTA = 9, PREV_INTRA4X4_PRED_MODE_FLAG = 10, REM_INTRA4X4_PRED_MODE = 11, INTRA_CHROMA_PRED_MODE = 12, REF_IDX_L0 = 13, REF_IDX_L1 = 14, MVD_L0_0 = 15, MVD_L1_0 = 16, MVD_L0_1 = 17, MVD_L1_1 = 18, SUB_MB_TYPE_P_SP = 19, SUB_MB_TYPE_B = 20, MAIN_SYNTAX_ELEMENT_NUMBER};// See table 9-30 of H.264 standardenum // Syntax element type{ CODED_BLOCK_FLAG = 0, SIGNIFICANT_COEFF_FLAG = 1, LAST_SIGNIFICANT_COEFF_FLAG = 2, COEFF_ABS_LEVEL_MINUS1 = 3, SYNTAX_ELEMENT_NUMBER};// See table 9-32 of H.264 standardenum // Context block category{ BLOCK_LUMA_DC_LEVELS = 0, BLOCK_LUMA_AC_LEVELS = 1, BLOCK_LUMA_LEVELS = 2, BLOCK_CHROMA_DC_LEVELS = 3, BLOCK_CHROMA_AC_LEVELS = 4, BLOCK_CATEGORY_NUMBER};// See table 9-11 of H.264 standardconst long ctxIdxOffset[MAIN_SYNTAX_ELEMENT_NUMBER] ={ 11, 24, 70, 0, 3, 14, 27, 73, 77, 60, 68, 69, 64, 54, 54, 40, 40, 47, 47, 21, 36,};// See table 9-24 of H.264 standardconst long ctxIdxOffsetFrameCoded[SYNTAX_ELEMENT_NUMBER] ={ 85, 105, 166, 227,};// See table 9-24 of H.264 standardconst long ctxIdxOffsetFieldCoded[SYNTAX_ELEMENT_NUMBER] ={ 85, 277, 338, 227,};// See table 9-30 of H.264 standardconst long ctxIdxBlockCatOffset[SYNTAX_ELEMENT_NUMBER][BLOCK_CATEGORY_NUMBER] ={ {0, 4, 8, 12, 16}, {0, 15, 29, 44, 47}, {0, 15, 29, 44, 47}, {0, 10, 20, 30, 39},};// Range tableconst Ipp8u rangeTabLPS[64][4]={ { 128, 176, 208, 240}, { 128, 167, 197, 227}, { 128, 158, 187, 216}, { 123, 150, 178, 205}, { 116, 142, 169, 195}, { 111, 135, 160, 185}, { 105, 128, 152, 175}, { 100, 122, 144, 166}, { 95, 116, 137, 158}, { 90, 110, 130, 150}, { 85, 104, 123, 142}, { 81, 99, 117, 135}, { 77, 94, 111, 128}, { 73, 89, 105, 122}, { 69, 85, 100, 116}, { 66, 80, 95, 110}, { 62, 76, 90, 104}, { 59, 72, 86, 99}, { 56, 69, 81, 94}, { 53, 65, 77, 89}, { 51, 62, 73, 85}, { 48, 59, 69, 80}, { 46, 56, 66, 76}, { 43, 53, 63, 72}, { 41, 50, 59, 69}, { 39, 48, 56, 65}, { 37, 45, 54, 62}, { 35, 43, 51, 59}, { 33, 41, 48, 56}, { 32, 39, 46, 53}, { 30, 37, 43, 50}, { 29, 35, 41, 48}, { 27, 33, 39, 45}, { 26, 31, 37, 43}, { 24, 30, 35, 41}, { 23, 28, 33, 39}, { 22, 27, 32, 37}, { 21, 26, 30, 35}, { 20, 24, 29, 33}, { 19, 23, 27, 31}, { 18, 22, 26, 30}, { 17, 21, 25, 28}, { 16, 20, 23, 27}, { 15, 19, 22, 25}, { 14, 18, 21, 24}, { 14, 17, 20, 23}, { 13, 16, 19, 22}, { 12, 15, 18, 21}, { 12, 14, 17, 20}, { 11, 14, 16, 19}, { 11, 13, 15, 18}, { 10, 12, 15, 17}, { 10, 12, 14, 16}, { 9, 11, 13, 15}, { 9, 11, 12, 14}, { 8, 10, 12, 14}, { 8, 9, 11, 13}, { 7, 9, 11, 12}, { 7, 9, 10, 12}, { 7, 8, 10, 11}, { 6, 8, 9, 11}, { 6, 7, 9, 10}, { 6, 7, 8, 9}, { 2, 2, 2, 2}};const unsigned short transIdxMPS[64] ={ 1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50, 51,52,53,54,55,56,57,58,59,60, 61,62,62,63};const unsigned short transIdxLPS[64] ={ 0, 0, 1, 2, 2, 4, 4, 5, 6, 7, 8, 9, 9,11,11,12,13,13,15,15, 16,16,18,18,19,19,21,21,22,22, 23,24,24,25,26,26,27,27,28,29, 29,30,30,30,31,32,32,33,33,33, 34,34,35,35,35,36,36,36,37,37, 37,38,38,63};#define ENC_B_BITS (10)#define ENC_FULL_RANGE (1 << (ENC_B_BITS-0))#define ENC_HALF_RANGE (1 << (ENC_B_BITS-1))#define ENC_QUARTER_RANGE (1 << (ENC_B_BITS-2))class CBaseBitstream{ protected: // m_pbs points to the current position of the buffer. Ipp8u* m_pbs; // m_pbsBase points to the first byte of the buffer. Ipp8u* m_pbsBase; // Indicates the bit position (0 to 7) in the byte pointed by m_pbs. Ipp32u m_bitOffset; // Indicates if the associated buffer is locally owned by the object. // If true, the destructor will need to take care of deallocation. // Note: This is always false in our current usage of the bitstream // objects in the codec. bool m_localBs; // Maximum buffer size in bytes. Ipp32u m_maxBsSize; Ipp64s bits_encoded; public: CABAC_CONTEXT context_array[400]; // (CABAC_CONTEXT []) array of cabac context(s) long m_lcodIRange; // (long) arithmetic encoding engine variable long m_lcodIOffset; // (long) arithmetic encoding engine variable long m_nRegister; long m_nReadyBits; long m_nOutstandingBits; long m_nSymCnt; void ResetBitStream_CABAC(void); void WriteByte_CABAC(void); void WriteBits_CABAC(long lNum,long code); void WriteBit_CABAC(bool code); void WriteOutstandingBit_CABAC(bool code); void TerminateEncode_CABAC(void); // Initialize CABAC decoding engine void InitializeEncodingEngine_CABAC(void); // Initialize CABAC context(s) in intra slices void InitializeContextVariablesIntra_CABAC(long SliceQPy); // Initialize CABAC context(s) in inter slices void InitializeContextVariablesInter_CABAC(long SliceQPy, long cabac_init_idc); // Encode block coefficient value nimus one //long EncodeCoeffAbsLevelMinus1_CABAC(long ctxIdxOffset, long &numDecodAbsLevelEq1, long &numDecodAbsLevelGt1,long code); // Encode single bin from stream void EncodeSingleBin_CABAC(long ctxIdx,bool code); void EncodeBypass_CABAC(bool code); void EncodeFinalSingleBin_CABAC(bool code); //unary binarization void EncodeUnaryRepresentedSymbol_CABAC(long ctxBase, long ctxIdx, long code,long suppremum=0x7fffffff); //Exp Golomb binarization void EncodeExGRepresentedSymbol_CABAC(long code,long log2ex); void EncodeExGRepresentedLevels_CABAC(long ctxIdx, long code); void EncodeExGRepresentedMVS_CABAC(long ctxIdx, long code,long supp); // Default constructor. CBaseBitstream(); // Destructor. virtual ~CBaseBitstream(); // Constructs a new object. Sets base pointer to point to the // bitstream buffer with given buffer size. CBaseBitstream( Ipp8u* const pbs, const Ipp32u maxsize); // Returns the size of the bitstream data in bytes based on the // current position of the buffer pointer, m_pbs. Ipp32u GetBsSize(); // Returns the bit position of the buffer pointer relative to the // beginning of the buffer. Ipp32u GetBsOffset(); // Returns the base pointer to the beginning of the bitstream. Ipp8u* GetBsBase(); // Returns the maximum bitstream size. Ipp32u GetMaxBsSize(); // Checks if read/write passed the maximum buffer size. bool CheckBsLimit(); // Encoder Specific Methods --------------------------------------------- // Resets pointer to the beginning and clears the bitstream buffer. virtual void Reset(); // Assigns new position to the buffer pointer. This is only // used to maintain the bitstream state when calling an assembly // routine that accesses the bitstream. void SetState( Ipp8u* const pbs, const Ipp32u bitOffset); // Obtains current position of the buffer pointer. This is only // used to maintain the bitstream state when calling an assembly // routine that accesses the bitstream. void GetState( Ipp8u** pbs, Ipp32u* bitOffset); // Advances buffer pointer with given number of bits. This is only // used to maintain the bitstream state when calling an assembly // routine that accesses the bitstream. void UpdateState( const Ipp32u nbits); // Clears the bitstream buffer. void ClearBs(); // Appends bits into the bitstream buffer. void PutBits( Ipp32u code, Ipp32u length); void PutByteAligned(Ipp8u byte); //////////////////////////////////////////// // Functions needed for new unified VLC code //////////////////////////////////////////// // Writes one general VLC code to the bitstream void PutVLCBits( const Ipp32u val, const Ipp32u len);// This macro is used to convert a signed VLC code into an// unsigned VLC code, ready to pipe into PutVLCCode below.// This saves having another function for that purpose and// should be faster.#define SIGNED_VLC_CODE(code) (2*ABS(code) - (code > 0)) // Writes one general VLC code to the bitstream // without knowing the code length... Costs a // bit more, so don't use it if you implicitly // know the length of the code you're writing. // Returns the length of the code written. Ipp32u PutVLCCode( const Ipp32u val); // Write RBSP Trailing Bits to Byte Align void WriteTrailingBits();// Convert Length and Info to VLC code number#define LENGTH_INFO_TO_N(length, info) \ ((1 << (length)) + (info) - 1) // Add zero bits to byte-align the buffer. void ByteAlignWithZeros(); // Add one bits to byte-align the buffer. void ByteAlignWithOnes(); // Decoder Specific Methods --------------------------------------------- // Resets pointer to point to a new bitstream. virtual void Reset( Ipp8u* const pb, const Ipp32u maxsize); Ipp64s GetBitsEncoded();};} //namespace UMC#endif // C3BS_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -