Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvdec/source/Lib/DecoderLib/CABACReader.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
/** \file     CABACReader.h
44
 *  \brief    Reader for low level syntax
45
 */
46
47
#pragma once
48
49
#include "BinDecoder.h"
50
51
#include "CommonLib/ContextModelling.h"
52
#include "CommonLib/UnitPartitioner.h"
53
54
namespace vvdec
55
{
56
57
class CABACReader
58
{
59
public:
60
0
  CABACReader()  = default;
61
0
  ~CABACReader() = default;
62
63
public:
64
65
  void        initCtxModels             ( Slice&                        slice );
66
  void        initBitstream             ( InputBitstream*               bitstream )
67
0
  {
68
0
    m_Bitstream = bitstream;
69
    // Add a byte to prevent readByteFlag from crossing the boundary
70
0
    m_Bitstream->inputZeroByte();
71
0
    m_BinDecoder.init( m_Bitstream );
72
0
  }
73
0
  const Ctx&  getCtx                    ()                                            const   { return m_BinDecoder.getCtx();  }
74
0
  void        setCtx                    ( const Ctx& ctx )                                    { m_BinDecoder.setCtx( ctx );    }
75
76
  // slice segment data (clause 7.3.8.1)
77
  bool        terminating_bit           ();
78
  void        remaining_bytes           ( bool                          noTrailingBytesExpected );
79
80
  // coding tree unit (clause 7.3.11.2)
81
  bool        coding_tree_unit          ( CodingStructure&              cs,     Slice* slice, const UnitArea& area, int (&qps)[2], unsigned  ctuRsAddr );
82
  bool        dt_implicit_qt_split      ( CodingStructure&              cs,     Partitioner& pL, CUCtx& cuCtxL, Partitioner& pC, CUCtx& cuCtxC );
83
84
  // sao (clause 7.3.11.3)
85
  void        sao                       ( CodingStructure&              cs,     unsigned        ctuRsAddr );
86
  void        readAlf                   ( CodingStructure&              cs,     unsigned        ctuRsAddr, const Partitioner& partitioner);
87
88
  short       readAlfCtuFilterIndex     ( CodingStructure&              cs,     unsigned        ctuRsAddr );
89
90
  // coding (quad)tree (clause 7.3.11.4)
91
  bool        coding_tree               ( CodingStructure&              cs,     Partitioner&    pm,       CUCtx& cuCtx );
92
  PartSplit   split_cu_mode             ( CodingStructure&              cs,     Partitioner&    pm );
93
  ModeType    mode_constraint           ( CodingStructure&              cs,     Partitioner&    pm,       const PartSplit splitMode );
94
95
  // coding unit (clause 7.3.11.5)
96
  bool        coding_unit               ( CodingUnit&                   cu,     Partitioner&    pm,       CUCtx& cuCtx );
97
  void        cu_skip_flag              ( CodingUnit&                   cu );
98
  void        pred_mode                 ( CodingUnit&                   cu );
99
  void        bdpcm_mode                ( CodingUnit&                   cu,     const ComponentID compID );
100
  void        cu_pred_data              ( CodingUnit&                   cu );
101
  void        cu_bcw_flag               ( CodingUnit&                   cu );
102
  void        extend_ref_line           ( CodingUnit&                   cu );
103
  void        intra_luma_pred_mode      ( CodingUnit&                   cu );
104
  bool        intra_chroma_lmc_mode     ( CodingUnit&               cu );
105
  void        intra_chroma_pred_mode    ( CodingUnit&               cu );
106
  void        cu_residual               ( CodingUnit&                   cu,     Partitioner&    pm,       CUCtx& cuCtx );
107
  void        rqt_root_cbf              ( CodingUnit&                   cu );
108
  void        adaptive_color_transform  ( CodingUnit&                   cu );
109
  void        sbt_mode                  ( CodingUnit&                   cu );
110
  void        mip_flag                  ( CodingUnit&                   cu );
111
  void        mip_pred_mode             ( CodingUnit&               cu );
112
  bool        end_of_ctu                ( CodingUnit&                   cu,     CUCtx&          cuCtx );
113
114
  // prediction unit (clause 7.3.11.7)
115
  void        prediction_unit           ( CodingUnit&               cu );
116
  void        general_merge_flag        ( CodingUnit&               cu );
117
  void        merge_data                ( CodingUnit&               cu );
118
  void        affine_flag               ( CodingUnit&                   cu );
119
  void        subblock_merge_flag       ( CodingUnit&                   cu );
120
  void        merge_idx                 ( CodingUnit&               cu );
121
  void        mmvd_merge_idx            ( CodingUnit&               cu );
122
  void        amvr_mode                 ( CodingUnit&                   cu );
123
  void        affine_amvr_mode          ( CodingUnit&                   cu );
124
  void        inter_pred_idc            ( CodingUnit&               cu );
125
  void        ref_idx                   ( CodingUnit&               cu,     RefPicList      eRefList );
126
  void        mvp_flag                  ( CodingUnit&               cu,     RefPicList      eRefList );
127
  void        ciip_flag                 ( CodingUnit&               cu );
128
  void        smvd_mode                 ( CodingUnit&               cu );
129
130
  // mvd coding (clause 7.3.11.8)
131
  void        mvd_coding( Mv &rMvd );
132
133
  // transform tree (clause 7.3.11.9)
134
  void        transform_tree            ( CodingStructure&              cs,     CodingUnit&     cu,       Partitioner&    pm,       CUCtx& cuCtx );
135
  bool        cbf_comp                  ( CodingUnit&                   cu,     const CompArea& area,     unsigned depth, const bool prevCbCbf = false, const bool useISP = false );
136
137
  // transform unit (clause 7.3.11.10)
138
  void        transform_unit            ( TransformUnit&                tu,     CUCtx&          cuCtx,    Partitioner&    pm );
139
  void        cu_qp_delta               ( CodingUnit&                   cu,     int             predQP, int8_t& qp );
140
  void        cu_chroma_qp_offset       ( CodingUnit&                   cu );
141
142
  // residual coding (clause 7.3.11.11)
143
  void        residual_coding           ( TransformUnit&                tu,     ComponentID     compID, CUCtx& cuCtx );
144
  void        ts_flag                   ( TransformUnit&                tu,     ComponentID     compID );
145
  void        mts_idx                   ( CodingUnit&                   cu,     CUCtx&          cuCtx  );
146
  void        residual_lfnst_mode       ( CodingUnit&                   cu,     CUCtx&          cuCtx  );
147
  void        isp_mode                  ( CodingUnit&                   cu );
148
  int         last_sig_coeff            ( CoeffCodingContext&           cctx,   TransformUnit& tu, ComponentID   compID );
149
  int         residual_coding_subblock  ( CoeffCodingContext&           cctx,   TCoeffSig*      coeff, const int stateTransTable, int& state, unsigned& signVal, int *&sigPos, unsigned &stateVal );
150
  void        residual_codingTS         ( TransformUnit&                tu,     ComponentID     compID );
151
  void        residual_coding_subblockTS( CoeffCodingContext&           cctx,   TCoeffSig*      coeff, CoeffSigBuf dstcoeff, int& maxX, int& maxY );
152
  void        joint_cb_cr               ( TransformUnit&                tu,     const int cbfMask );
153
154
private:
155
  unsigned    unary_max_symbol          ( unsigned ctxId0, unsigned ctxIdN, unsigned maxSymbol );
156
  unsigned    unary_max_eqprob          (                                   unsigned maxSymbol );
157
  unsigned    exp_golomb_eqprob         ( unsigned count );
158
#if ENABLE_TRACING
159
  unsigned    get_num_bits_read         () { return m_BinDecoder.getNumBitsRead(); }
160
#endif
161
  unsigned    code_unary_fixed          ( unsigned ctxId, unsigned unary_max, unsigned fixed );
162
163
  void        xReadTruncBinCode         ( uint32_t &symbol, uint32_t maxSymbol );
164
165
private:
166
  TCoeffSig       m_cffTmp [MAX_TU_SIZE_FOR_PROFILE * MAX_TU_SIZE_FOR_PROFILE];
167
168
  unsigned        m_signVal[256];
169
  int             m_numSig [256];
170
  unsigned        m_sub1   [256];
171
  CtxTpl          m_tplBuf [MAX_TU_SIZE_FOR_PROFILE * MAX_TU_SIZE_FOR_PROFILE];
172
  int             m_blkPos [MAX_TU_SIZE_FOR_PROFILE * MAX_TU_SIZE_FOR_PROFILE];
173
  BinDecoder      m_BinDecoder;
174
  InputBitstream* m_Bitstream = nullptr;
175
  Slice*          m_slice     = nullptr;
176
  Partitioner     m_partL, m_partC;
177
};
178
179
180
}