Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/EncoderLib/IntraSearch.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) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC 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
/** \file     IntraSearch.h
43
    \brief    intra search class (header)
44
*/
45
46
#pragma once
47
48
#include "CABACWriter.h"
49
#include "CommonLib/IntraPrediction.h"
50
#include "CommonLib/TrQuant.h"
51
#include "CommonLib/Unit.h"
52
#include "CommonLib/RdCost.h"
53
#include "CommonLib/CommonDef.h"
54
55
//! \ingroup EncoderLib
56
//! \{
57
58
namespace vvenc {
59
60
// ====================================================================================================================
61
// Class definition
62
// ====================================================================================================================
63
class EncPicture;
64
class EncCu;
65
66
/// encoder search class
67
class IntraSearch : public IntraPrediction
68
{
69
private:
70
71
  struct ModeInfo
72
  {
73
    bool     mipFlg;    // CU::mipFlag
74
    bool     mipTrFlg;  // CU::mipTransposeFlag
75
    int8_t   mRefId;    // CU::multiRefIdx
76
    uint8_t  ispMod;    // CU::ispMode
77
    uint8_t  modeId;    // CU::intraDir[CH_L]
78
79
0
    ModeInfo() : mipFlg( false ), mipTrFlg( false ), mRefId( 0 ), ispMod( NOT_INTRA_SUBPARTITIONS ), modeId( 0 ) {}
80
0
    ModeInfo( const bool mipf, const bool miptf, const int8_t mrid, const uint8_t ispm, const uint8_t mode ) : mipFlg( mipf ), mipTrFlg( miptf ), mRefId( mrid ), ispMod( ispm ), modeId( mode ) {}
81
0
    bool operator==( const ModeInfo cmp ) const { return ( 0 == ::memcmp( this, &cmp, sizeof( ModeInfo ) ) ); }
82
  };
83
84
  CodingStructure*    m_pTempCS;
85
  CodingStructure*    m_pBestCS;
86
  CodingStructure**   m_pSaveCS;
87
  bool                m_saveCuCostInSCIPU;
88
  uint8_t             m_numCuInSCIPU;
89
  Area                m_cuAreaInSCIPU[NUM_INTER_CU_INFO_SAVE];
90
  double              m_cuCostInSCIPU[NUM_INTER_CU_INFO_SAVE];
91
  CompStorage         m_orgResiCb[5], m_orgResiCr[5]; // 0:std, 1-3:jointCbCr, 4:crossComp
92
  std::vector<ModeInfo>
93
                      m_parentCandList;
94
95
protected:
96
  // interface to option
97
  const VVEncCfg* m_pcEncCfg;
98
99
  // interface to classes
100
  TrQuant*        m_pcTrQuant;
101
  RdCost*         m_pcRdCost;
102
  // RD computation
103
  CABACWriter*    m_CABACEstimator;
104
  CtxCache*       m_CtxCache;
105
106
  SortedPelUnitBufs<SORTED_BUFS> *m_SortedPelUnitBufs;
107
public:
108
  IntraSearch();
109
  ~IntraSearch();
110
111
  struct ISPTestedModesInfo
112
  {
113
    int                                         numTotalParts[2];
114
    int                                         bestModeSoFar;
115
    ISPType                                     bestSplitSoFar;
116
    double                                      bestCost[2];
117
    bool                                        splitIsFinished[2];
118
    int                                         subTuCounter;
119
    PartSplit                                   IspType;
120
    bool                                        relatedCuIsValid;
121
    bool                                        intraWasTested;
122
    int                                         bestIntraMode;
123
    bool                                        isIntra;
124
    int                                         bestBefore[3];
125
    // set everything to default values
126
    void clear()
127
0
    {
128
0
      for (int splitIdx = 0; splitIdx < NUM_INTRA_SUBPARTITIONS_MODES - 1; splitIdx++)
129
0
      {
130
0
        numTotalParts[splitIdx] = 0;
131
0
        splitIsFinished[splitIdx] = false;
132
0
        bestCost[splitIdx] = MAX_DOUBLE;
133
0
      }
134
0
      bestModeSoFar = -1;
135
0
      bestSplitSoFar = NOT_INTRA_SUBPARTITIONS;
136
0
      subTuCounter = -1;
137
0
      IspType = TU_NO_ISP;
138
0
    }
139
    void init(const int numTotalPartsHor, const int numTotalPartsVer, bool n)
140
0
    {
141
0
      if (n)
142
0
      {
143
0
        intraWasTested = false;
144
0
        relatedCuIsValid = false;
145
0
        bestIntraMode = 0;
146
0
        isIntra   = false;
147
0
        std::memset(bestBefore,0, sizeof(bestBefore));
148
0
        clear();
149
0
      }
150
0
      else
151
0
      {
152
0
        const int horSplit = HOR_INTRA_SUBPARTITIONS - 1, verSplit = VER_INTRA_SUBPARTITIONS - 1;
153
0
        numTotalParts[horSplit] = numTotalPartsHor;
154
0
        numTotalParts[verSplit] = numTotalPartsVer;
155
0
        splitIsFinished[horSplit] = (numTotalParts[horSplit] == 0);
156
0
        splitIsFinished[verSplit] = (numTotalParts[verSplit] == 0);
157
0
        subTuCounter = -1;
158
0
        IspType = TU_NO_ISP;
159
0
      }
160
0
    }
161
  };
162
163
  ISPTestedModesInfo m_ispTestedModes[ NUM_LFNST_NUM_PER_SET ];
164
165
  void init                       ( const VVEncCfg &encCfg, TrQuant *pTrQuant, RdCost *pRdCost, SortedPelUnitBufs<SORTED_BUFS> *pSortedPelUnitBufs, XUCache &unitCache);
166
  void setCtuEncRsrc              ( CABACWriter* cabacEstimator, CtxCache* ctxCache );
167
  void destroy                    ();
168
169
0
  CodingStructure  **getSaveCSBuf () { return m_pSaveCS; }
170
171
0
  bool getSaveCuCostInSCIPU       ()               { return m_saveCuCostInSCIPU; }
172
0
  void setSaveCuCostInSCIPU       ( bool b )       { m_saveCuCostInSCIPU = b;  }
173
0
  void setNumCuInSCIPU            ( uint8_t i )    { m_numCuInSCIPU = i; }
174
  void saveCuAreaCostInSCIPU      ( Area area, double cost );
175
  void initCuAreaCostInSCIPU      ();
176
177
  bool estIntraPredLumaQT         ( CodingUnit &cu, Partitioner &pm, double bestCost = MAX_DOUBLE);
178
  void estIntraPredChromaQT       ( CodingUnit& cu, Partitioner& partitioner, const double maxCostAllowed );
179
180
private:
181
  double    xFindInterCUCost          ( CodingUnit &cu );
182
  void      xPreCheckMTS              ( TransformUnit &tu, std::vector<TrMode> *trModes, const int maxCand, PelUnitBuf *pPred, const ComponentID& compID = COMP_Y);
183
  void      xEstimateLumaRdModeList   ( int& numModesForFullRD,
184
                                        static_vector<ModeInfo, FAST_UDI_MAX_RDMODE_NUM>& RdModeList,
185
                                        static_vector<ModeInfo, FAST_UDI_MAX_RDMODE_NUM>& HadModeList,
186
                                        static_vector<double, FAST_UDI_MAX_RDMODE_NUM>& CandCostList,
187
                                        static_vector<double, FAST_UDI_MAX_RDMODE_NUM>& CandHadList, CodingUnit& cu, bool testMip);
188
189
  // -------------------------------------------------------------------------------------------------------------------
190
  // Intra search
191
  // -------------------------------------------------------------------------------------------------------------------
192
  uint64_t  xFracModeBitsIntraLuma    ( const CodingUnit& cu, const unsigned* mpmLst );
193
194
  void      xEncIntraHeader           ( CodingStructure &cs, Partitioner& pm, const bool luma );
195
  void      xEncSubdivCbfQT           ( CodingStructure &cs, Partitioner& pm, const bool luma );
196
  uint64_t  xGetIntraFracBitsQT       ( CodingStructure &cs, Partitioner &pm, const bool luma, CUCtx *cuCtx = nullptr );
197
198
  uint64_t  xGetIntraFracBitsQTChroma ( const TransformUnit& tu, const ComponentID compID, CUCtx *cuCtx );
199
200
  void     xEncCoeffQT                ( CodingStructure& cs, Partitioner& pm, const ComponentID compID, CUCtx* cuCtx = nullptr, const int subTuIdx = -1, const PartSplit ispType = TU_NO_ISP );
201
202
  void      xIntraCodingTUBlock       ( TransformUnit &tu, const ComponentID compID, const bool checkCrossCPrediction, Distortion &ruiDist, uint32_t *numSig = nullptr, PelUnitBuf *pPred = nullptr, const bool loadTr = false);
203
  ChromaCbfs xIntraChromaCodingQT     ( CodingStructure& cs, Partitioner& pm );
204
  void     xIntraCodingLumaQT         ( CodingStructure& cs, Partitioner& pm, PelUnitBuf* pPred, const double bestCostSoFar, int numMode, bool disableMTS);
205
  double   xTestISP                   ( CodingStructure& cs, Partitioner& pm, double bestCostSoFar, PartSplit ispType, bool& splitcbf, uint64_t& singleFracBits, Distortion& singleDistLuma, CUCtx& cuCtx);
206
  int      xSpeedUpISP                ( int speed, bool& testISP, int mode, int& noISP, int& endISP, CodingUnit& cu, static_vector<ModeInfo, FAST_UDI_MAX_RDMODE_NUM>& RdModeList,const ModeInfo& bestPUMode, int bestISP, int bestLfnstIdx);
207
  void     xSpeedUpIntra              ( double bestcost, int& EndMode, int& speedIntra, CodingUnit& cu);
208
209
  template<typename T, size_t N, int M>
210
  void      xReduceHadCandList        ( static_vector<T, N>& candModeList, static_vector<double, N>& candCostList, SortedPelUnitBufs<M>& sortedPelBuffer, int& numModesForFullRD, const double thresholdHadCost, const double* mipHadCost, const CodingUnit& cu, const bool fastMip);
211
212
};// END CLASS DEFINITION EncSearch
213
214
} // namespace vvenc
215
216
//! \}
217