Coverage Report

Created: 2026-10-28 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/EncoderLib/InterSearch.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     InterSearch.h
43
    \brief    inter search class (header)
44
 */
45
46
#pragma once
47
48
#include "CABACWriter.h"
49
#include "CommonLib/MotionInfo.h"
50
#include "CommonLib/InterPrediction.h"
51
#include "CommonLib/TrQuant.h"
52
#include "CommonLib/Unit.h"
53
#include "CommonLib/UnitPartitioner.h"
54
#include "CommonLib/RdCost.h"
55
#include "CommonLib/CommonDef.h"
56
#include "CommonLib/AffineGradientSearch.h"
57
#include "BvSearchOps.h"
58
59
#include <unordered_map>
60
#include <vector>
61
62
//! \ingroup EncoderLib
63
//! \{
64
65
namespace vvenc {
66
67
// ====================================================================================================================
68
// Class definition
69
// ====================================================================================================================
70
71
static const uint32_t MAX_NUM_REF_LIST_ADAPT_SR = 2;
72
static const uint32_t MAX_IDX_ADAPT_SR          = MAX_REF_PICS;
73
static const uint32_t NUM_MV_PREDICTORS         = 3;
74
75
struct ModeInfo
76
{
77
  uint32_t mergeCand;
78
  bool     isRegularMerge;
79
  bool     isMMVD;
80
  bool     isCIIP;
81
  bool     isBioOrDmvr;
82
  bool     isAffine;
83
0
  ModeInfo() {}
84
85
  ModeInfo(const uint32_t mergeCand, const bool isRegularMerge, const bool isMMVD, const bool isCIIP, const bool BioOrDmvr, const bool Affine) :
86
0
    mergeCand(mergeCand), isRegularMerge(isRegularMerge), isMMVD(isMMVD), isCIIP(isCIIP), isBioOrDmvr(BioOrDmvr), isAffine(Affine) {}
87
};
88
89
struct BlkUniMvInfo
90
{
91
  Mv uniMvs[2][MAX_REF_PICS];
92
  int x, y, w, h;
93
};
94
95
struct BlkRecord
96
{
97
  std::unordered_map<Mv, Distortion> bvRecord;
98
};
99
100
struct BlkUniMvInfoBuffer
101
{
102
0
  const BlkUniMvInfo* getBlkUniMvInfo(int i) const { return &m_uniMvList[(m_uniMvListIdx - 1 - i + m_uniMvListMaxSize) % (m_uniMvListMaxSize)]; }
103
0
        BlkUniMvInfo* getBlkUniMvInfo(int i)       { return &m_uniMvList[(m_uniMvListIdx - 1 - i + m_uniMvListMaxSize) % (m_uniMvListMaxSize)]; }
104
105
  void insertUniMvCands( const Area& blkArea, const Mv* cMvTemp)
106
0
  {
107
0
    BlkUniMvInfo* curMvInfo = m_uniMvList + m_uniMvListIdx;
108
0
    int j = 0;
109
0
    for (; j < m_uniMvListSize; j++)
110
0
    {
111
0
      BlkUniMvInfo* prevMvInfo = getBlkUniMvInfo( j );
112
0
      if ((blkArea.x == prevMvInfo->x) && (blkArea.y == prevMvInfo->y) && (blkArea.width == prevMvInfo->w) && (blkArea.height == prevMvInfo->h))
113
0
      {
114
0
        break;
115
0
      }
116
0
    }
117
118
//    DTRACE( g_trace_ctx, D_TMP, "%d unimv insert %d, %d [%d %d] \n", g_trace_ctx->getChannelCounter(D_TMP), blkArea.x, blkArea.y, blkArea.width, blkArea.height );
119
0
    if (j < m_uniMvListSize)
120
0
    {
121
0
      curMvInfo = getBlkUniMvInfo( j );
122
0
    }
123
124
0
    ::memcpy(curMvInfo->uniMvs, cMvTemp, 2 * MAX_REF_PICS * sizeof(Mv));
125
0
    if (j == m_uniMvListSize)  // new element
126
0
    {
127
0
      curMvInfo->x = blkArea.x;
128
0
      curMvInfo->y = blkArea.y;
129
0
      curMvInfo->w = blkArea.width;
130
0
      curMvInfo->h = blkArea.height;
131
0
      m_uniMvListSize = std::min(m_uniMvListSize + 1, m_uniMvListMaxSize);
132
0
      m_uniMvListIdx = (m_uniMvListIdx + 1) % (m_uniMvListMaxSize);
133
0
    }
134
0
  }
135
136
  void savePrevUniMvInfo(const CompArea& blkArea, BlkUniMvInfo &tmpUniMvInfo, bool& isUniMvInfoSaved)
137
0
  {
138
0
    int j = 0;
139
0
    const BlkUniMvInfo* curMvInfo = nullptr;
140
0
    for (; j < m_uniMvListSize; j++)
141
0
    {
142
0
      curMvInfo = getBlkUniMvInfo( j );
143
0
      if ((blkArea.x == curMvInfo->x) && (blkArea.y == curMvInfo->y) && (blkArea.width == curMvInfo->w) && (blkArea.height == curMvInfo->h))
144
0
      {
145
0
        break;
146
0
      }
147
0
    }
148
149
0
    if (j < m_uniMvListSize)
150
0
    {
151
//      DTRACE( g_trace_ctx, D_TMP, "%d unimv save %d, %d [%d %d] \n", g_trace_ctx->getChannelCounter(D_TMP), curMvInfo->x, curMvInfo->y, curMvInfo->w, curMvInfo->h );
152
0
      isUniMvInfoSaved = true;
153
0
      tmpUniMvInfo = *curMvInfo;
154
0
    }
155
0
  }
156
157
  void addUniMvInfo( const BlkUniMvInfo &tmpUniMVInfo)
158
0
  {
159
0
    int j = 0;
160
0
    BlkUniMvInfo* curMvInfo = nullptr;
161
0
    for (; j < m_uniMvListSize; j++)
162
0
    {
163
0
      curMvInfo = getBlkUniMvInfo( j );
164
0
      if ((tmpUniMVInfo.x == curMvInfo->x) && (tmpUniMVInfo.y == curMvInfo->y) && (tmpUniMVInfo.w == curMvInfo->w) && (tmpUniMVInfo.h == curMvInfo->h))
165
0
      {
166
0
        break;
167
0
      }
168
0
    }
169
170
//    DTRACE( g_trace_ctx, D_TMP, "%d unimv add %d, %d [%d %d] \n", g_trace_ctx->getChannelCounter(D_TMP), tmpUniMVInfo.x, tmpUniMVInfo.y, tmpUniMVInfo.w, tmpUniMVInfo.h );
171
0
    if (j < m_uniMvListSize)
172
0
    {
173
0
      *curMvInfo = tmpUniMVInfo;
174
0
    }
175
0
    else
176
0
    {
177
0
      m_uniMvList[m_uniMvListIdx] = tmpUniMVInfo;
178
0
      m_uniMvListIdx = (m_uniMvListIdx + 1) % m_uniMvListMaxSize;
179
0
      m_uniMvListSize = std::min(m_uniMvListSize + 1, m_uniMvListMaxSize);
180
0
    }
181
0
  }
182
183
5.38k
  void resetUniMvList               () { m_uniMvListIdx = 0; m_uniMvListSize = 0; }
184
185
  BlkUniMvInfoBuffer()
186
10.7k
  {
187
10.7k
    m_uniMvListIdx = 0;
188
10.7k
    m_uniMvListSize = 0;
189
10.7k
  }
190
191
  ~BlkUniMvInfoBuffer()
192
10.7k
  {
193
10.7k
    m_uniMvListIdx = 0;
194
10.7k
    m_uniMvListSize = 0;
195
10.7k
  }
196
197
  static constexpr int m_uniMvListMaxSize = 15;
198
  BlkUniMvInfo         m_uniMvList[m_uniMvListMaxSize];
199
  int                  m_uniMvListIdx;
200
  int                  m_uniMvListSize;
201
};
202
203
class EncPicture;
204
class EncModeCtrl;
205
class EncCu;
206
207
struct AffineMVInfo
208
{
209
  Mv  affMVs[2][MAX_REF_PICS][3];
210
  int x, y, w, h;
211
};
212
213
typedef struct
214
{
215
  Mv acMvAffine4Para[2][3];
216
  Mv acMvAffine6Para[2][3];
217
  int16_t affine4ParaRefIdx[2];
218
  int16_t affine6ParaRefIdx[2];
219
  bool affine4ParaAvail;
220
  bool affine6ParaAvail;
221
} EncAffineMotion;
222
223
struct AffineProfList
224
{
225
  AffineProfList()
226
10.7k
  {
227
10.7k
    m_affMVListMaxSize = 0;
228
10.7k
    m_affMVList = nullptr;
229
10.7k
    m_affMVListIdx = 0;
230
10.7k
    m_affMVListSize = 0;
231
10.7k
  }
232
233
  void init( bool bLowDelay )
234
10.7k
  {
235
10.7k
    m_affMVListMaxSize = bLowDelay ? AFFINE_ME_LIST_SIZE_LD : AFFINE_ME_LIST_SIZE;
236
10.7k
    if( !m_affMVList)
237
10.7k
    {
238
10.7k
      m_affMVList = new AffineMVInfo[m_affMVListMaxSize];
239
10.7k
    }
240
10.7k
    m_affMVListIdx = 0;
241
10.7k
    m_affMVListSize = 0;
242
10.7k
  }
243
244
  ~AffineProfList()
245
10.7k
  {
246
10.7k
    if( m_affMVList)
247
10.7k
    {
248
10.7k
      delete[] m_affMVList;
249
10.7k
      m_affMVList = nullptr;
250
10.7k
    }
251
10.7k
    m_affMVListIdx = 0;
252
10.7k
    m_affMVListSize = 0;
253
10.7k
  }
254
255
5.38k
  void resetAffineMVList() { m_affMVListIdx = 0; m_affMVListSize = 0; }
256
  bool savePrevAffMVInfo(int idx, AffineMVInfo &tmpMVInfo )
257
85.6k
  {
258
85.6k
    if( m_affMVListSize > idx)
259
0
    {
260
0
      tmpMVInfo = m_affMVList[(m_affMVListIdx - 1 - idx + m_affMVListMaxSize) % m_affMVListMaxSize];
261
0
      return true;
262
0
    }
263
264
85.6k
    return false;
265
85.6k
  }
266
267
  void addAffMVInfo(AffineMVInfo &tmpMVInfo)
268
0
  {
269
0
    int j = 0;
270
0
    AffineMVInfo *prevInfo = nullptr;
271
0
    for (; j < m_affMVListSize; j++)
272
0
    {
273
0
      prevInfo = m_affMVList + ((m_affMVListIdx - j - 1 + m_affMVListMaxSize) % (m_affMVListMaxSize));
274
0
      if ((tmpMVInfo.x == prevInfo->x) && (tmpMVInfo.y == prevInfo->y) && (tmpMVInfo.w == prevInfo->w) && (tmpMVInfo.h == prevInfo->h))
275
0
      {
276
0
        break;
277
0
      }
278
0
    }
279
0
    if (j < m_affMVListSize)
280
0
    {
281
0
      *prevInfo = tmpMVInfo;
282
0
    }
283
0
    else
284
0
    {
285
0
      m_affMVList[m_affMVListIdx] = tmpMVInfo;
286
0
      m_affMVListIdx = (m_affMVListIdx + 1) % m_affMVListMaxSize;
287
0
      m_affMVListSize = std::min(m_affMVListSize + 1, m_affMVListMaxSize);
288
0
    }
289
0
  }
290
291
  void insert( const AffineMVInfo& cMvTemp, const Area& area )
292
0
  {
293
0
    AffineMVInfo *affMVInfo = m_affMVList + m_affMVListIdx;
294
295
    //check;
296
0
    int j = 0;
297
0
    for (; j < m_affMVListSize; j++)
298
0
    {
299
0
      AffineMVInfo *prevMvInfo = m_affMVList + ((m_affMVListIdx - j - 1 + m_affMVListMaxSize) % (m_affMVListMaxSize));
300
0
      if ((area.x == prevMvInfo->x) && (area.y == prevMvInfo->y) && (area.width == prevMvInfo->w) && (area.height == prevMvInfo->h))
301
0
      {
302
0
        break;
303
0
      }
304
0
    }
305
0
    if (j < m_affMVListSize)
306
0
    {
307
0
      affMVInfo = m_affMVList + ((m_affMVListIdx - j - 1 + m_affMVListMaxSize) % (m_affMVListMaxSize));
308
0
    }
309
310
0
    ::memcpy(affMVInfo->affMVs, cMvTemp.affMVs, sizeof(cMvTemp.affMVs));
311
312
0
    if (j == m_affMVListSize)
313
0
    {
314
0
      affMVInfo->x = area.x;
315
0
      affMVInfo->y = area.y;
316
0
      affMVInfo->w = area.width;
317
0
      affMVInfo->h = area.height;
318
0
      m_affMVListSize = std::min(m_affMVListSize + 1, m_affMVListMaxSize);
319
0
      m_affMVListIdx = (m_affMVListIdx + 1) % (m_affMVListMaxSize);
320
0
    }
321
0
  }
322
323
  AffineMVInfo*   m_affMVList;
324
  int             m_affMVListIdx;
325
  int             m_affMVListSize;
326
  int             m_affMVListMaxSize;
327
};
328
329
struct ReuseUniMv
330
{
331
  Mv*             m_reusedUniMVs[6][6][32][32];
332
333
  ReuseUniMv();
334
  ~ReuseUniMv();
335
  void resetReusedUniMvs();
336
};
337
338
/// encoder search class
339
class InterSearch : public InterPrediction, AffineGradientSearch
340
{
341
private:
342
  EncModeCtrl*      m_modeCtrl;
343
344
  PelStorage        m_tmpPredStorage[NUM_REF_PIC_LIST_01];
345
  PelStorage        m_tmpStorageLCU;
346
  CodingStructure** m_pSaveCS;
347
348
  ClpRng            m_lumaClpRng;
349
  Mv                m_acBVs[2 * IBC_NUM_CANDIDATES];
350
  unsigned int      m_numBVs;
351
  BvSearchOps       m_bvSearchOps;
352
  std::vector<unsigned> m_bvBits;   // the block vector bits of one line of search positions
353
  IbcBvCand*        m_defaultCachedBvs;
354
  std::unordered_map< Position, std::unordered_map< Size, BlkRecord> > m_ctuRecord;
355
  CompStorage       m_orgResiCb[4], m_orgResiCr[4];   // 0:std, 1-3:jointCbCr
356
357
protected:
358
  // interface to option
359
  const VVEncCfg*   m_pcEncCfg;
360
361
  // interface to classes
362
  TrQuant*          m_pcTrQuant;
363
364
  // ME parameters
365
  int               m_iSearchRange;
366
  int               m_bipredSearchRange; // Search range for bi-prediction
367
  vvencMESearchMethod m_motionEstimationSearchMethod;
368
  int               m_motionEstimationSearchMethodSCC;
369
  int               m_aaiAdaptSR[MAX_NUM_REF_LIST_ADAPT_SR][MAX_IDX_ADAPT_SR];
370
371
  // RD computation
372
  CABACWriter*      m_CABACEstimator;
373
  CtxCache*         m_CtxCache;
374
  DistParam         m_cDistParam;
375
  RdCost*           m_pcRdCost;
376
377
  Distortion        m_hevcCost;
378
  EncAffineMotion   m_affineMotion;
379
  PelStorage        m_tmpAffiStorage;
380
  Pel*              m_tmpAffiError;
381
  Pel*              m_tmpAffiDeri[2];
382
  MotionInfo        m_subPuMiBuf[(MAX_CU_SIZE * MAX_CU_SIZE) >> (MIN_CU_LOG2 << 1)];
383
  // Misc.
384
  Pel*              m_pTempPel;
385
386
  // AMVP cost computation
387
  uint32_t          m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1];
388
  Distortion        m_estMinDistSbt[NUMBER_SBT_MODE + 1]; // estimated minimum SSE value of the PU if using a SBT mode
389
  uint8_t           m_sbtRdoOrder[NUMBER_SBT_MODE];       // order of SBT mode in RDO
390
  bool              m_skipSbtAll;                         // to skip all SBT modes for the current PU
391
392
  BcwMotionParam    m_uniMotions;
393
  uint8_t           m_estWeightIdxBits[BCW_NUM] = { 4, 3, 1, 2, 4 };
394
  bool              m_affineModeSelected;
395
396
public:
397
  ReuseUniMv*         m_ReuseUniMv;
398
  BlkUniMvInfoBuffer* m_BlkUniMvInfoBuffer;
399
  AffineProfList*     m_AffineProfList;
400
  bool                m_clipMvInSubPic;
401
402
public:
403
  InterSearch();
404
  virtual ~InterSearch();
405
406
  void init                         ( const VVEncCfg& encCfg, TrQuant* pTrQuant, RdCost* pRdCost, EncModeCtrl* pModeCtrl, CodingStructure **pSaveCS );
407
  void setCtuEncRsrc                ( CABACWriter* cabacEstimator, CtxCache* ctxCache, ReuseUniMv* pReuseUniMv, BlkUniMvInfoBuffer* pBlkUniMvInfoBuffer, AffineProfList* pAffineProfList, IbcBvCand* pCachedBvs );
408
409
  void destroy                      ();
410
411
  /// encoder estimation - inter prediction (non-skip)
412
  bool predInterSearch              ( CodingUnit& cu, Partitioner& partitioner, double& bestCostInter);
413
414
  /// set ME search range
415
  void encodeResAndCalcRdInterCU    ( CodingStructure &cs, Partitioner &partitioner, const bool skipResidual );
416
417
  void setSearchRange               ( const Slice* slice, const VVEncCfg& encCfg );
418
419
  void resetSavedAffineMotion       ();
420
  void storeAffineMotion            ( Mv acAffineMv[2][3], int16_t affineRefIdx[2], EAffineModel affineType, int BcwIdx);
421
  void loadGlobalUniMvs             ( const Area& lumaArea, const PreCalcValues& pcv);
422
423
  uint8_t    skipSbtByRDCost        ( int width, int height, int mtDepth, uint8_t sbtIdx, uint8_t sbtPos, double bestCost, Distortion distSbtOff, double costSbtOff, bool rootCbfSbtOff );
424
0
  bool       getSkipSbtAll          ()                            const { return m_skipSbtAll; }
425
0
  uint8_t    getSbtRdoOrder         ( uint8_t idx )               const { assert( m_sbtRdoOrder[idx] < NUMBER_SBT_MODE ); assert( (uint32_t)( m_estMinDistSbt[m_sbtRdoOrder[idx]] >> 2 ) < ( MAX_UINT >> 1 ) ); return m_sbtRdoOrder[idx]; }
426
0
  Distortion getEstDistSbt          ( uint8_t sbtMode)            const { return m_estMinDistSbt[sbtMode]; }
427
0
  void       initSbtRdoOrder        ( uint8_t sbtMode )                 { m_sbtRdoOrder[0] = sbtMode; m_estMinDistSbt[0] = m_estMinDistSbt[sbtMode]; }
428
429
  void       getBestSbt             ( CodingStructure* tempCS, CodingUnit* cu, uint8_t& histBestSbt, Distortion& curPuSse, uint8_t sbtAllowed, bool doPreAnalyzeResi, bool mtsAllowed );
430
  bool       predIBCSearch          (CodingUnit& cu, Partitioner& partitioner);
431
  bool       searchBvIBC            (const CodingUnit& pu, int xPos, int yPos, int width, int height, int picWidth, int picHeight, int xBv, int yBv, int ctuSize) const;
432
433
4.97k
  void       resetCtuRecordIBC      () { m_ctuRecord.clear(); }
434
435
0
  void       resetBufferedUniMotions() { m_uniMotions.reset(); }
436
0
  uint8_t    getWeightIdxBits       ( uint8_t bcwIdx ) { return m_estWeightIdxBits[bcwIdx]; }
437
0
  void       setAffineModeSelected  ( bool flag ) { m_affineModeSelected = flag; }
438
439
private:
440
  unsigned   xMergeCandLists        ( Mv* dst, unsigned dn, const unsigned dstTotalLength, const Mv* src, const unsigned sn ) const;
441
  // the IBC block vector bits of the count search positions ( x0 + i * xStep, y ) or ( x, y0 + i * yStep ), valid up
442
  // to the next call
443
  const unsigned* xGetBvBitsRow     ( const int x0, const int xStep, const int count, const int y, const bool useIMV );
444
  const unsigned* xGetBvBitsColumn  ( const int x, const int y0, const int yStep, const int count, const bool useIMV );
445
  void       xCalcMinDistSbt        ( CodingStructure &cs, const CodingUnit& cu, const uint8_t sbtAllowed );
446
  /// sub-function for motion vector refinement used in fractional-pel accuracy
447
  Distortion xPatternRefinement     ( const CPelBuf* pcPatternKey, Mv baseRefMv, int iFrac, Mv& rcMvFrac, Distortion& uiDistBest, int& patternId, CPelBuf* pattern, bool useAltHpelIf );
448
449
   typedef struct
450
   {
451
     int left;
452
     int right;
453
     int top;
454
     int bottom;
455
   } SearchRange;
456
457
  typedef struct
458
  {
459
    SearchRange     searchRange;
460
    const CPelBuf*  pcPatternKey;
461
    const Pel*      piRefY;
462
    int             iRefStride;
463
    int             iBestX;
464
    int             iBestY;
465
    uint32_t        uiBestRound;
466
    uint32_t        uiBestDistance;
467
    Distortion      uiBestSad;
468
    uint8_t         ucPointNr;
469
    int             subShiftMode;
470
    unsigned        imvShift;
471
    bool            useAltHpelIf;
472
    bool            zeroMV;
473
  } TZSearchStruct;
474
475
  // sub-functions for ME
476
  inline void xTZSearchHelp         ( TZSearchStruct& rcStruct, const int iSearchX, const int iSearchY, const uint8_t ucPointNr, const uint32_t uiDistance );
477
  inline void xTZ2PointSearch       ( TZSearchStruct& rcStruct );
478
  inline void xTZ4PointSquareSearch ( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist );
479
  inline void xTZ8PointSquareSearch ( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist );
480
  inline void xTZ8PointDiamondSearch( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist, const bool bCheckCornersAtDist1 );
481
482
  // -------------------------------------------------------------------------------------------------------------------
483
  // Inter search (AMP)
484
  // -------------------------------------------------------------------------------------------------------------------
485
486
  void       xEstimateMvPredAMVP  ( CodingUnit& cu, CPelUnitBuf& origBuf, RefPicList refPicList, int iRefIdx, Mv& rcMvPred, AMVPInfo& amvpInfo, Distortion& distBiP );
487
  void       xCheckBestMVP        ( RefPicList refPicList, const Mv& cMv, Mv& rcMvPred, int& riMVPIdx, AMVPInfo& amvpInfo, uint32_t&  ruiBits, Distortion& ruiCost, const uint8_t imv);
488
  Distortion xGetTemplateCost     ( const CodingUnit& cu, CPelUnitBuf& origBuf, PelUnitBuf& predBuf, Mv cMvCand, int iMVPIdx, int iMVPNum, RefPicList refPicList, int iRefIdx );
489
490
  void       xCopyAMVPInfo        ( AMVPInfo* pSrc, AMVPInfo* pDst );
491
  uint32_t   xGetMvpIdxBits       ( int iIdx, int iNum );
492
  void       xGetBlkBits          ( bool bPSlice, int iPartIdx,  uint32_t uiLastMode, uint32_t uiBlkBit[3]);
493
494
495
  // -------------------------------------------------------------------------------------------------------------------
496
  // motion estimation
497
  // -------------------------------------------------------------------------------------------------------------------
498
499
  void xMotionEstimation          ( CodingUnit&           cu,
500
                                    CPelUnitBuf&          origBuf,
501
                                    RefPicList            refPicList,
502
                                    Mv&                   rcMvPred,
503
                                    int                   iRefIdxPred,
504
                                    Mv&                   rcMv,
505
                                    int&                  riMVPIdx,
506
                                    uint32_t&             ruiBits,
507
                                    Distortion&           ruiCost,
508
                                    const AMVPInfo&       amvpInfo,
509
                                    bool                  bBi = false
510
                                  );
511
512
  void xTZSearch( const CodingUnit& cu,
513
                                    RefPicList            refPicList,
514
                                    int                   iRefIdxPred,
515
                                    TZSearchStruct&       cStruct,
516
                                    Mv&                   rcMv,
517
                                    Distortion&           ruiSAD,
518
                                    const bool            bExtendedSettings,
519
                                    const bool            bFastSettings = false
520
                                  );
521
522
  void xClipMvSearch              ( Mv& rcMv, const Position& pos, const struct Size& size, const PreCalcValues& pcv, const int ifpLines );
523
524
  void xClipMvToFppLine           ( Mv& mv, const int yB, const int nH, const int ifpLines, const PreCalcValues& pcv );
525
  void xCheckAndClipMvToFppLine   ( Mv& mv, const int yB, const int nH, const int ifpLines, const PreCalcValues& pcv );
526
  void xSetSearchRange            ( const CodingUnit& cu,
527
                                    const Mv&             cMvPred,
528
                                    const int             iSrchRng,
529
                                    SearchRange&          sr                                  
530
                                  );
531
532
  void xPatternSearchFast         ( const CodingUnit&     cu,
533
                                    RefPicList            refPicList,
534
                                    int                   iRefIdxPred,
535
                                    TZSearchStruct&       cStruct,
536
                                    Mv&                   rcMv,
537
                                    Distortion&           ruiSAD
538
                                  );
539
540
  void xPatternSearch             ( TZSearchStruct&       cStruct,
541
                                    Mv&                   rcMv,
542
                                    Distortion&           ruiSAD
543
                                  );
544
545
  void xPatternSearchIntRefine    ( CodingUnit&         cu,
546
                                    TZSearchStruct&     cStruct,
547
                                    Mv&                 rcMv,
548
                                    Mv&                 rcMvPred,
549
                                    int&                riMVPIdx,
550
                                    uint32_t&           uiBits,
551
                                    Distortion&         ruiCost,
552
                                    const AMVPInfo&     amvpInfo,
553
                                    double              fWeight
554
                                  );
555
556
  void xPatternSearchFracDIF      ( const CodingUnit&     cu,
557
                                    RefPicList            refPicList,
558
                                    int                   iRefIdx,
559
                                    TZSearchStruct&       cStruct,
560
                                    const Mv&             rcMvInt,
561
                                    Mv&                   rcMvHalf,
562
                                    Mv&                   rcMvQter,
563
                                    Distortion&           ruiCost
564
                                  );
565
566
  void xPredAffineInterSearch     ( CodingUnit&           cu,
567
                                    CPelUnitBuf&          origBuf,
568
                                    int                   puIdx,
569
                                    uint32_t&             lastMode,
570
                                    Distortion&           affineCost,
571
                                    Mv                    hevcMv[2][MAX_REF_PICS],
572
                                    Mv                    mvAffine4Para[2][MAX_REF_PICS][3],
573
                                    int                   refIdx4Para[2],
574
                                    uint8_t               BcwIdx = BCW_DEFAULT,
575
                                    bool                  enforceBcwPred = false,
576
                                    uint32_t              BcwIdxBits = 0
577
                                  );
578
579
  void  xAffineMotionEstimation  ( CodingUnit&           cu,
580
                                   CPelUnitBuf&          origBuf,
581
                                   RefPicList            refPicList,
582
                                   Mv                    acMvPred[3],
583
                                   int                   iRefIdxPred,
584
                                   Mv                    acMv[3],
585
                                   uint32_t&             ruiBits,
586
                                   Distortion&           ruiCost,
587
                                   int&                  mvpIdx,
588
                                   const AffineAMVPInfo& aamvpi,
589
                                   bool                  bBi = false
590
                                 );
591
592
  bool        xEstimateAffineAMVP     ( CodingUnit& cu, AffineAMVPInfo& affineAMVPInfo, CPelUnitBuf& origBuf, RefPicList refPicList, int iRefIdx, Mv acMvPred[3], Distortion& distBiP);
593
594
  Distortion  xGetAffineTemplateCost  ( CodingUnit& cu, CPelUnitBuf& origBuf, PelUnitBuf& predBuf, Mv acMvCand[3], int iMVPIdx, int iMVPNum, RefPicList refPicList, int iRefIdx);
595
  void        xCopyAffineAMVPInfo     ( AffineAMVPInfo& src, AffineAMVPInfo& dst );
596
  void        xCheckBestAffineMVP     ( CodingUnit& cu, AffineAMVPInfo &affineAMVPInfo, RefPicList refPicList, Mv acMv[3], Mv acMvPred[3], int& riMVPIdx, uint32_t& ruiBits, Distortion& ruiCost );
597
  uint32_t    xCalcAffineMVBits       ( CodingUnit& cu, Mv mvCand[3], Mv mvPred[3]);
598
599
  Distortion  xGetSymCost             ( const CodingUnit& cu, CPelUnitBuf& origBuf, RefPicList eCurRefPicList, const MvField& cCurMvField, MvField& cTarMvField , int BcwIdx );
600
  Distortion  xSymRefineMvSearch      ( CodingUnit& cu, CPelUnitBuf& origBuf, Mv& rcMvCurPred, Mv& rcMvTarPred, RefPicList refPicList,
601
                                        MvField& rCurMvField, MvField& rTarMvField, Distortion uiMinCost, int searchPattern, int nSearchStepShift, uint32_t uiMaxSearchRounds, int BcwIdx );
602
  void        xSymMotionEstimation    ( CodingUnit& cu, CPelUnitBuf& origBuf, Mv& rcMvCurPred, Mv& rcMvTarPred, RefPicList refPicList, MvField& rCurMvField, MvField& rTarMvField, Distortion& ruiCost, int BcwIdx );
603
  double      xGetMEDistortionWeight  ( uint8_t BcwIdx, RefPicList refPicList);
604
605
  void xSymMvdCheckBestMvp            ( CodingUnit& cu,  CPelUnitBuf& origBuf, Mv curMv, RefPicList curRefList, AMVPInfo amvpInfo[2][MAX_REF_PICS], 
606
                                        int32_t BcwIdx, Mv cMvPredSym[2], int32_t mvpIdxSym[2], Distortion& bestCost, bool skip );
607
608
  bool xReadBufferedAffineUniMv       ( CodingUnit& cu, RefPicList eRefPicList, int32_t iRefIdx, Mv acMvPred[3], Mv acMv[3], uint32_t& ruiBits, Distortion& ruiCost, int& mvpIdx, const AffineAMVPInfo& aamvpi );
609
  bool xReadBufferedUniMv             ( CodingUnit& cu, RefPicList eRefPicList, int32_t iRefIdx, Mv& pcMvPred, Mv& rcMv, uint32_t& ruiBits, Distortion& ruiCost);
610
611
  void xExtDIFUpSamplingH             ( CPelBuf* pcPattern, bool useAltHpelIf);
612
  void xExtDIFUpSamplingQ             ( CPelBuf* pcPatternKey, Mv halfPelRef, int& patternId );
613
614
  void xEncodeInterResidualQT         ( CodingStructure &cs, Partitioner &partitioner, const ComponentID compID );
615
  void xEstimateInterResidualQT       ( CodingStructure &cs, Partitioner &partitioner, Distortion *puiZeroDist = NULL );
616
  uint64_t xGetSymbolFracBitsInter    ( CodingStructure &cs, Partitioner &partitioner );
617
  void  xSetIntraSearchRangeIBC       ( CodingUnit& pu, int iRoiWidth, int iRoiHeight, Mv& rcMvSrchRngLT, Mv& rcMvSrchRngRB);
618
  void  xIBCEstimation                ( CodingUnit& cu, PelUnitBuf& origBuf, Mv* pcMvPred, Mv& rcMv, Distortion& ruiCost );
619
  void  xIBCSearchMVCandUpdate        ( Distortion  uiSad, int x, int y, Distortion* uiSadBestCand, Mv* cMVCand);
620
  int   xIBCSearchMVChromaRefine      ( CodingUnit& cu, int iRoiWidth, int iRoiHeight, int cuPelX, int cuPelY, Distortion* uiSadBestCand, Mv* cMVCand);
621
  void  xIntraPatternSearchIBC        ( CodingUnit& pu, TZSearchStruct& cStruct, Mv& rcMv, Distortion& ruiCost, Mv* cMvSrchRngLT, Mv* cMvSrchRngRB, Mv* pcMvPred);
622
};// END CLASS DEFINITION EncSearch
623
624
} // namespace vvenc
625
626
//! \}
627