Coverage Report

Created: 2026-08-13 07:23

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