Although the entropy decoding process is not very complex, it is annoying to have too many documents and functions involved, so a little bit of tidying up
Entropy decoding generally, it is necessary to initialize the context mode in the first place.
In HEVC
Because it is a class structure, in the declaration of the object, the basic completion of the general initialization work, the following detailed introduction:
Contains all the context patterns in the class Tdecsbac, but there are two corresponding structures in HM
Contextmodel M_contextmodels[max_num_ctx_mod];//< altogether 512 elements of the Int m_numcontextmodels; Contextmodel3dbuffer M_ccusplitflagscmodel; Contextmodel3dbuffer M_ccuskipflagscmodel; Contextmodel3dbuffer M_ccumergeflagextscmodel; Contextmodel3dbuffer M_ccumergeidxextscmodel; Contextmodel3dbuffer M_ccupartsizescmodel; Contextmodel3dbuffer M_ccupredmodescmodel; Contextmodel3dbuffer M_ccuintrapredscmodel;
Contextmodel M_contextmodels[max_num_ctx_mod]; HEVC has 512 context modes altogether
Then m_numcontextmodels this class member variable to record how many context patterns each syntax element has
The Contextmodel3dbuffer type corresponds to the context pattern of each syntax element
Two more important variables in the M_numcontextmodels
UChar m_ucstate; < current slice in the corresponding state stateuint m_binscoded; < current number of bin, specific not very clear, follow-up continue to explain
Contextmodel3dbuffer
contextmodel* M_contextmodel; < array of context models const UINT M_sizex; < X size of 3D buffer const UINT m_sizexy; < X times Y size of 3D buffer const UINT m_sizexyz; < total size of 3D buffer
There are 512 context modes, in each 3D mode, Contextmodel points to the pattern in 512, and three size variables are corresponding to how many patterns are in a syntax element,
Then the corresponding Contextmodel is obtained by the specific offset.
Initialization
Initialize the object when it is created
<span style= "COLOR: #ff0000;" >ContextModel3DBuffer::ContextModel3DBuffer</span> (UINT uisizez, uint uisizey, uint Uisizex, Contextmodel * Baseptr, Int &count): M_sizex (Uisizex), m_sizexy (Uisizex * Uisizey), m_sizexyz (Uisizex * Uisizey * UiSizeZ) { Allocate 3D buffer M_contextmodel = baseptr; Count + = m_sizexyz;}
<span style= "color: #ff0000;" >tdecsbac::tdecsbac () </span>//new structure Here:m_pcbitstream (0), M_pctdecbini F (NULL), M_numcontextmodels (0), M_ccusplitflagscmodel (1, 1, num_split_flag_ctx, M_contextmodels + m_numcontext Models, M_numcontextmodels), M_ccuskipflagscmodel (1, 1, NUM_SKIP_ Flag_ctx, M_contextmodels + m_numcontextmodels, m_numcontextmodels), M_ccumergeflagextscmodel (1, 1, num_merge_flag_ext_ctx, M_contextmodels + M_NUMCONTEXTMO Dels, M_numcontextmodels), M_ccumergeidxextscmodel (1, 1, num_merge_i Dx_ext_ctx, M_contextmodels + m_numcontextmodels, m_numcontextmodels), M_ccupartsizescmodel (1, 1, num_part_size_ctx, M_contextmodels + m_numcont Extmodels, M_numcontextmodels), M_ccupredmodescmodel (1, 1, NUM_PR Ed_mode_ctx, M_contextmodels + m_numcontextmodels, m_numcontextmodels), M_ccuintrapredscmodel (1, 1, num_adi_ctx, M_contextmodels + M_numcontex TModels, M_numcontextmodels), M_ccuchromapredscmodel (1, 1, Num_chro Ma_pred_ctx, M_contextmodels + m_numcontextmodels, m_numcontextmodels)
Complete the size of the context pattern contained in the corresponding Contextmodel and each syntax element in the Contextmodel3dbuffer pattern
The next initialization is initialized at the beginning of a slice, where the initialization is primarily the initial dissolve code environment
Mainly includes information such as range,mps in arithmetic coding.
Function entry:
Void Tdecslice: M in:d ecompressslice (tcominputbitstream** ppcsubstreams, tcompic* pcpic, tdecsbac* pcSbacDecoder) _pcentropydecoder->setentropydecoder (Pcsbacdecoder ); < polymorphic information is encoded in Cabac m_pcentropydecoder->setbitstream (ppcsubstreams[0]),//< sets the corresponding bitstream information m_ Pcentropydecoder->resetentropy (pcslice);//< Initial dissolve code environment
In the function
<pre name= "code" class= "CPP" >void tdecsbac::resetentropy (tcomslice* pslice) {Slicetype Slicetype = pSlice-> Getslicetype (); Int QP = PSLICE->GETSLICEQP (); if (Pslice->getpps ()->getcabacinitpresentflag () && Pslice->getcabacinitflag ())//xt? {switch (slicetype) {case P_slice://Change initialization table to B_slice initialization slic EType = B_slice; Break Case B_slice://Change initialization table to P_slice initialization slicetype = P_slice; Break Default://should not occur assert (0); Break }} m_ccusplitflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_split_flag); M_ccuskipflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_skip_flag); M_ccumergeflagextscmodel.initbuffer (Slicetype, QP, (uchar*) init_merge_flag_ext); M_ccumergeidxextscmodel.initbuffer (Slicetype, QP, (uchar*)Init_merge_idx_ext); M_ccupartsizescmodel.initbuffer (Slicetype, QP, (uchar*) init_part_size); M_ccupredmodescmodel.initbuffer (Slicetype, QP, (uchar*) init_pred_mode); M_ccuintrapredscmodel.initbuffer (Slicetype, QP, (uchar*) init_intra_pred_mode); M_ccuchromapredscmodel.initbuffer (Slicetype, QP, (uchar*) init_chroma_pred_mode); M_ccuinterdirscmodel.initbuffer (Slicetype, QP, (uchar*) init_inter_dir); M_ccumvdscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_MVD); M_ccurefpicscmodel.initbuffer (Slicetype, QP, (uchar*) init_ref_pic); M_ccudeltaqpscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_DQP); M_ccuqtcbfscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_QT_CBF); M_ccuqtrootcbfscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_QT_ROOT_CBF); M_ccusigcoeffgroupscmodel.initbuffer (Slicetype, QP, (uchar*) init_sig_cg_flag); M_ccusigscmodel.initbuffer (Slicetype, QP, (uchar*) init_sig_flag); M_ccuctxlastx.initbuffer (Slicetype, QP, (uchar*) init_last); M_ccuctxlasty.initbuffer (Slicetype, QP, (uchar*) init_last); M_ccuonescmodel.initbuffer (Slicetype, QP, (uchar*) init_one_flag); M_ccuabsscmodel.initbuffer (Slicetype, QP, (uchar*) init_abs_flag); M_cmvpidxscmodel.initbuffer (Slicetype, QP, (uchar*) init_mvp_idx); M_csaomergescmodel.initbuffer (Slicetype, QP, (uchar*) init_sao_merge_flag); M_csaotypeidxscmodel.initbuffer (Slicetype, QP, (uchar*) init_sao_type_idx); M_ccutranssubdivflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_trans_subdiv_flag); M_ctransformskipscmodel.initbuffer (Slicetype, QP, (uchar*) init_transformskip_flag); M_cutransquantbypassflagscmodel.iniTbuffer (Slicetype, QP, (uchar*) init_cu_transquant_bypass_flag); M_explicitrdpcmflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_explicit_rdpcm_flag); M_explicitrdpcmdirscmodel.initbuffer (Slicetype, QP, (uchar*) init_explicit_rdpcm_dir); M_cintrabcpredflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_intrabc_pred_flag); M_ccrosscomponentpredictionscmodel.initbuffer (Slicetype, QP, (uchar*) init_cross_component_prediction); M_chromaqpadjflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_chroma_qp_adj_flag); M_chromaqpadjidcscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_CHROMA_QP_ADJ_IDC); M_ccucolourtransformflagscmodel.initbuffer (Slicetype, QP, (uchar*) Init_colour_trans); M_cintrabcbvdscmodel.initbuffer (Slicetype, QP, (uchar*) INIT_INTRABC_BVD); M_pltmodeflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_pltmode_flag); M_spointscmodel.initbuffer (Slicetype, QP, (uchar*) init_spoint); M_ccopytoprunscmodel.initbuffer (Slicetype, QP, (uchar*) init_top_run); M_crunscmodel.initbuffer (Slicetype, QP, (uchar*) init_run); M_pltsharingmodeflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_plt_reuse_flag); M_pltscanrotationmodeflagscmodel.initbuffer (Slicetype, QP, (uchar*) init_scan_rotation_flag); for (UInt statisticindex = 0; Statisticindex < rext__golomb_rice_adaptation_statistics_sets; statisticindex++) {m _golombriceadaptationstatistics[statisticindex] = 0; } m_pctdecbinif->start ();}
Where the initialization of the Buffur
Void Contextmodel3dbuffer::initbuffer (Slicetype slicetype, Int qp, uchar* ctxmodel) { Ctxmodel + = Slicetype * M_sizeX YZ; for (Int n = 0; n < m_sizexyz; n++) { m_contextmodel[n].init (QP, ctxmodel[n]); m_contextmodel[n].setbinscoded (0);} }
The incoming Ctxmodel is a pre-known table that initializes the state and bin variables for each contextmodel through Init
Initializing the decoding environment in arithmetic decoding in the start () function
Tdecbincabac::start () { assert (m_pctcombitstream->getnumbitsuntilbytealigned () = = 0); #if rext__decoder_ Debug_bit_statistics Tcomcodingstatistics::updatecabacstat (stats__cabac_initialisation, 510, 0); #endif M_uirange = 510; m_bitsneeded =-8; M_uivalue = (M_pctcombitstream->readbyte () << 8); M_uivalue |= m_pctcombitstream->readbyte ();}
HEVC Entropy decoding Code Analysis-code decoding process (2)