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/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
0
  void resetUniMvList               () { m_uniMvListIdx = 0; m_uniMvListSize = 0; }
183
184
  BlkUniMvInfoBuffer()
185
0
  {
186
0
    m_uniMvListIdx = 0;
187
0
    m_uniMvListSize = 0;
188
0
  }
189
190
  ~BlkUniMvInfoBuffer()
191
0
  {
192
0
    m_uniMvListIdx = 0;
193
0
    m_uniMvListSize = 0;
194
0
  }
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 EncReshape;
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
0
  {
227
0
    m_affMVListMaxSize = 0;
228
0
    m_affMVList = nullptr;
229
0
    m_affMVListIdx = 0;
230
0
    m_affMVListSize = 0;
231
0
  }
232
233
  void init( bool bLowDelay )
234
0
  {
235
0
    m_affMVListMaxSize = bLowDelay ? AFFINE_ME_LIST_SIZE_LD : AFFINE_ME_LIST_SIZE;
236
0
    if( !m_affMVList)
237
0
    {
238
0
      m_affMVList = new AffineMVInfo[m_affMVListMaxSize];
239
0
    }
240
0
    m_affMVListIdx = 0;
241
0
    m_affMVListSize = 0;
242
0
  }
243
244
  ~AffineProfList()
245
0
  {
246
0
    if( m_affMVList)
247
0
    {
248
0
      delete[] m_affMVList;
249
0
      m_affMVList = nullptr;
250
0
    }
251
0
    m_affMVListIdx = 0;
252
0
    m_affMVListSize = 0;
253
0
  }
254
255
0
  void resetAffineMVList() { m_affMVListIdx = 0; m_affMVListSize = 0; }
256
  bool savePrevAffMVInfo(int idx, AffineMVInfo &tmpMVInfo )
257
0
  {
258
0
    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
0
    return false;
265
0
  }
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
  IbcBvCand*        m_defaultCachedBvs;
352
  std::unordered_map< Position, std::unordered_map< Size, BlkRecord> > m_ctuRecord;
353
  CompStorage       m_orgResiCb[4], m_orgResiCr[4];   // 0:std, 1-3:jointCbCr
354
355
protected:
356
  // interface to option
357
  const VVEncCfg*   m_pcEncCfg;
358
359
  // interface to classes
360
  TrQuant*          m_pcTrQuant;
361
  EncReshape*       m_pcReshape;
362
363
  // ME parameters
364
  int               m_iSearchRange;
365
  int               m_bipredSearchRange; // Search range for bi-prediction
366
  vvencMESearchMethod m_motionEstimationSearchMethod;
367
  int               m_motionEstimationSearchMethodSCC;
368
  int               m_aaiAdaptSR[MAX_NUM_REF_LIST_ADAPT_SR][MAX_IDX_ADAPT_SR];
369
370
  // RD computation
371
  CABACWriter*      m_CABACEstimator;
372
  CtxCache*         m_CtxCache;
373
  DistParam         m_cDistParam;
374
  RdCost*           m_pcRdCost;
375
376
  Distortion        m_hevcCost;
377
  EncAffineMotion   m_affineMotion;
378
  PelStorage        m_tmpAffiStorage;
379
  Pel*              m_tmpAffiError;
380
  Pel*              m_tmpAffiDeri[2];
381
  MotionInfo        m_subPuMiBuf[(MAX_CU_SIZE * MAX_CU_SIZE) >> (MIN_CU_LOG2 << 1)];
382
  // Misc.
383
  Pel*              m_pTempPel;
384
385
  // AMVP cost computation
386
  uint32_t          m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1];
387
  Distortion        m_estMinDistSbt[NUMBER_SBT_MODE + 1]; // estimated minimum SSE value of the PU if using a SBT mode
388
  uint8_t           m_sbtRdoOrder[NUMBER_SBT_MODE];       // order of SBT mode in RDO
389
  bool              m_skipSbtAll;                         // to skip all SBT modes for the current PU
390
391
  BcwMotionParam    m_uniMotions;
392
  uint8_t           m_estWeightIdxBits[BCW_NUM] = { 4, 3, 1, 2, 4 };
393
  bool              m_affineModeSelected;
394
395
public:
396
  ReuseUniMv*         m_ReuseUniMv;
397
  BlkUniMvInfoBuffer* m_BlkUniMvInfoBuffer;
398
  AffineProfList*     m_AffineProfList;
399
  bool                m_clipMvInSubPic;
400
401
public:
402
  InterSearch();
403
  virtual ~InterSearch();
404
405
  void init                         ( const VVEncCfg& encCfg, TrQuant* pTrQuant, RdCost* pRdCost, EncModeCtrl* pModeCtrl, CodingStructure **pSaveCS );
406
  void setCtuEncRsrc                ( CABACWriter* cabacEstimator, CtxCache* ctxCache, ReuseUniMv* pReuseUniMv, BlkUniMvInfoBuffer* pBlkUniMvInfoBuffer, AffineProfList* pAffineProfList, IbcBvCand* pCachedBvs );
407
408
  void destroy                      ();
409
410
  /// encoder estimation - inter prediction (non-skip)
411
  bool predInterSearch              ( CodingUnit& cu, Partitioner& partitioner, double& bestCostInter);
412
413
  /// set ME search range
414
  void encodeResAndCalcRdInterCU    ( CodingStructure &cs, Partitioner &partitioner, const bool skipResidual );
415
416
  void setSearchRange               ( const Slice* slice, const VVEncCfg& encCfg );
417
418
  void resetSavedAffineMotion       ();
419
  void storeAffineMotion            ( Mv acAffineMv[2][3], int16_t affineRefIdx[2], EAffineModel affineType, int BcwIdx);
420
  void loadGlobalUniMvs             ( const Area& lumaArea, const PreCalcValues& pcv);
421
422
  uint8_t    skipSbtByRDCost        ( int width, int height, int mtDepth, uint8_t sbtIdx, uint8_t sbtPos, double bestCost, Distortion distSbtOff, double costSbtOff, bool rootCbfSbtOff );
423
0
  bool       getSkipSbtAll          ()                            const { return m_skipSbtAll; }
424
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]; }
425
0
  Distortion getEstDistSbt          ( uint8_t sbtMode)            const { return m_estMinDistSbt[sbtMode]; }
426
0
  void       initSbtRdoOrder        ( uint8_t sbtMode )                 { m_sbtRdoOrder[0] = sbtMode; m_estMinDistSbt[0] = m_estMinDistSbt[sbtMode]; }
427
428
  void       getBestSbt             ( CodingStructure* tempCS, CodingUnit* cu, uint8_t& histBestSbt, Distortion& curPuSse, uint8_t sbtAllowed, bool doPreAnalyzeResi, bool mtsAllowed );
429
  bool       predIBCSearch          (CodingUnit& cu, Partitioner& partitioner);
430
  bool       searchBvIBC            (const CodingUnit& pu, int xPos, int yPos, int width, int height, int picWidth, int picHeight, int xBv, int yBv, int ctuSize) const;
431
432
0
  void       resetCtuRecordIBC      () { m_ctuRecord.clear(); }
433
434
0
  void       resetBufferedUniMotions() { m_uniMotions.reset(); }
435
0
  uint8_t    getWeightIdxBits       ( uint8_t bcwIdx ) { return m_estWeightIdxBits[bcwIdx]; }
436
0
  void       setAffineModeSelected  ( bool flag ) { m_affineModeSelected = flag; }
437
438
private:
439
  void       xCalcMinDistSbt        ( CodingStructure &cs, const CodingUnit& cu, const uint8_t sbtAllowed );
440
  /// sub-function for motion vector refinement used in fractional-pel accuracy
441
  Distortion xPatternRefinement     ( const CPelBuf* pcPatternKey, Mv baseRefMv, int iFrac, Mv& rcMvFrac, Distortion& uiDistBest, int& patternId, CPelBuf* pattern, bool useAltHpelIf );
442
443
   typedef struct
444
   {
445
     int left;
446
     int right;
447
     int top;
448
     int bottom;
449
   } SearchRange;
450
451
  typedef struct
452
  {
453
    SearchRange     searchRange;
454
    const CPelBuf*  pcPatternKey;
455
    const Pel*      piRefY;
456
    int             iRefStride;
457
    int             iBestX;
458
    int             iBestY;
459
    uint32_t        uiBestRound;
460
    uint32_t        uiBestDistance;
461
    Distortion      uiBestSad;
462
    uint8_t         ucPointNr;
463
    int             subShiftMode;
464
    unsigned        imvShift;
465
    bool            useAltHpelIf;
466
    bool            zeroMV;
467
  } TZSearchStruct;
468
469
  // sub-functions for ME
470
  inline void xTZSearchHelp         ( TZSearchStruct& rcStruct, const int iSearchX, const int iSearchY, const uint8_t ucPointNr, const uint32_t uiDistance );
471
  inline void xTZ2PointSearch       ( TZSearchStruct& rcStruct );
472
  inline void xTZ4PointSquareSearch ( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist );
473
  inline void xTZ8PointSquareSearch ( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist );
474
  inline void xTZ8PointDiamondSearch( TZSearchStruct& rcStruct, const int iStartX, const int iStartY, const int iDist, const bool bCheckCornersAtDist1 );
475
476
  // -------------------------------------------------------------------------------------------------------------------
477
  // Inter search (AMP)
478
  // -------------------------------------------------------------------------------------------------------------------
479
480
  void       xEstimateMvPredAMVP  ( CodingUnit& cu, CPelUnitBuf& origBuf, RefPicList refPicList, int iRefIdx, Mv& rcMvPred, AMVPInfo& amvpInfo, Distortion& distBiP );
481
  void       xCheckBestMVP        ( RefPicList refPicList, const Mv& cMv, Mv& rcMvPred, int& riMVPIdx, AMVPInfo& amvpInfo, uint32_t&  ruiBits, Distortion& ruiCost, const uint8_t imv);
482
  Distortion xGetTemplateCost     ( const CodingUnit& cu, CPelUnitBuf& origBuf, PelUnitBuf& predBuf, Mv cMvCand, int iMVPIdx, int iMVPNum, RefPicList refPicList, int iRefIdx );
483
484
  void       xCopyAMVPInfo        ( AMVPInfo* pSrc, AMVPInfo* pDst );
485
  uint32_t   xGetMvpIdxBits       ( int iIdx, int iNum );
486
  void       xGetBlkBits          ( bool bPSlice, int iPartIdx,  uint32_t uiLastMode, uint32_t uiBlkBit[3]);
487
488
489
  // -------------------------------------------------------------------------------------------------------------------
490
  // motion estimation
491
  // -------------------------------------------------------------------------------------------------------------------
492
493
  void xMotionEstimation          ( CodingUnit&           cu,
494
                                    CPelUnitBuf&          origBuf,
495
                                    RefPicList            refPicList,
496
                                    Mv&                   rcMvPred,
497
                                    int                   iRefIdxPred,
498
                                    Mv&                   rcMv,
499
                                    int&                  riMVPIdx,
500
                                    uint32_t&             ruiBits,
501
                                    Distortion&           ruiCost,
502
                                    const AMVPInfo&       amvpInfo,
503
                                    bool                  bBi = false
504
                                  );
505
506
  void xTZSearch( const CodingUnit& cu,
507
                                    RefPicList            refPicList,
508
                                    int                   iRefIdxPred,
509
                                    TZSearchStruct&       cStruct,
510
                                    Mv&                   rcMv,
511
                                    Distortion&           ruiSAD,
512
                                    const bool            bExtendedSettings,
513
                                    const bool            bFastSettings = false
514
                                  );
515
516
  void xClipMvSearch              ( Mv& rcMv, const Position& pos, const struct Size& size, const PreCalcValues& pcv, const int ifpLines );
517
518
  void xClipMvToFppLine           ( Mv& mv, const int yB, const int nH, const int ifpLines, const PreCalcValues& pcv );
519
  void xCheckAndClipMvToFppLine   ( Mv& mv, const int yB, const int nH, const int ifpLines, const PreCalcValues& pcv );
520
  void xSetSearchRange            ( const CodingUnit& cu,
521
                                    const Mv&             cMvPred,
522
                                    const int             iSrchRng,
523
                                    SearchRange&          sr                                  
524
                                  );
525
526
  void xPatternSearchFast         ( const CodingUnit&     cu,
527
                                    RefPicList            refPicList,
528
                                    int                   iRefIdxPred,
529
                                    TZSearchStruct&       cStruct,
530
                                    Mv&                   rcMv,
531
                                    Distortion&           ruiSAD
532
                                  );
533
534
  void xPatternSearch             ( TZSearchStruct&       cStruct,
535
                                    Mv&                   rcMv,
536
                                    Distortion&           ruiSAD
537
                                  );
538
539
  void xPatternSearchIntRefine    ( CodingUnit&         cu,
540
                                    TZSearchStruct&     cStruct,
541
                                    Mv&                 rcMv,
542
                                    Mv&                 rcMvPred,
543
                                    int&                riMVPIdx,
544
                                    uint32_t&           uiBits,
545
                                    Distortion&         ruiCost,
546
                                    const AMVPInfo&     amvpInfo,
547
                                    double              fWeight
548
                                  );
549
550
  void xPatternSearchFracDIF      ( const CodingUnit&     cu,
551
                                    RefPicList            refPicList,
552
                                    int                   iRefIdx,
553
                                    TZSearchStruct&       cStruct,
554
                                    const Mv&             rcMvInt,
555
                                    Mv&                   rcMvHalf,
556
                                    Mv&                   rcMvQter,
557
                                    Distortion&           ruiCost
558
                                  );
559
560
  void xPredAffineInterSearch     ( CodingUnit&           cu,
561
                                    CPelUnitBuf&          origBuf,
562
                                    int                   puIdx,
563
                                    uint32_t&             lastMode,
564
                                    Distortion&           affineCost,
565
                                    Mv                    hevcMv[2][MAX_REF_PICS],
566
                                    Mv                    mvAffine4Para[2][MAX_REF_PICS][3],
567
                                    int                   refIdx4Para[2],
568
                                    uint8_t               BcwIdx = BCW_DEFAULT,
569
                                    bool                  enforceBcwPred = false,
570
                                    uint32_t              BcwIdxBits = 0
571
                                  );
572
573
  void  xAffineMotionEstimation  ( CodingUnit&           cu,
574
                                   CPelUnitBuf&          origBuf,
575
                                   RefPicList            refPicList,
576
                                   Mv                    acMvPred[3],
577
                                   int                   iRefIdxPred,
578
                                   Mv                    acMv[3],
579
                                   uint32_t&             ruiBits,
580
                                   Distortion&           ruiCost,
581
                                   int&                  mvpIdx,
582
                                   const AffineAMVPInfo& aamvpi,
583
                                   bool                  bBi = false
584
                                 );
585
586
  bool        xEstimateAffineAMVP     ( CodingUnit& cu, AffineAMVPInfo& affineAMVPInfo, CPelUnitBuf& origBuf, RefPicList refPicList, int iRefIdx, Mv acMvPred[3], Distortion& distBiP);
587
588
  Distortion  xGetAffineTemplateCost  ( CodingUnit& cu, CPelUnitBuf& origBuf, PelUnitBuf& predBuf, Mv acMvCand[3], int iMVPIdx, int iMVPNum, RefPicList refPicList, int iRefIdx);
589
  void        xCopyAffineAMVPInfo     ( AffineAMVPInfo& src, AffineAMVPInfo& dst );
590
  void        xCheckBestAffineMVP     ( CodingUnit& cu, AffineAMVPInfo &affineAMVPInfo, RefPicList refPicList, Mv acMv[3], Mv acMvPred[3], int& riMVPIdx, uint32_t& ruiBits, Distortion& ruiCost );
591
  uint32_t    xCalcAffineMVBits       ( CodingUnit& cu, Mv mvCand[3], Mv mvPred[3]);
592
593
  Distortion  xGetSymCost             ( const CodingUnit& cu, CPelUnitBuf& origBuf, RefPicList eCurRefPicList, const MvField& cCurMvField, MvField& cTarMvField , int BcwIdx );
594
  Distortion  xSymRefineMvSearch      ( CodingUnit& cu, CPelUnitBuf& origBuf, Mv& rcMvCurPred, Mv& rcMvTarPred, RefPicList refPicList,
595
                                        MvField& rCurMvField, MvField& rTarMvField, Distortion uiMinCost, int searchPattern, int nSearchStepShift, uint32_t uiMaxSearchRounds, int BcwIdx );
596
  void        xSymMotionEstimation    ( CodingUnit& cu, CPelUnitBuf& origBuf, Mv& rcMvCurPred, Mv& rcMvTarPred, RefPicList refPicList, MvField& rCurMvField, MvField& rTarMvField, Distortion& ruiCost, int BcwIdx );
597
  double      xGetMEDistortionWeight  ( uint8_t BcwIdx, RefPicList refPicList);
598
599
  void xSymMvdCheckBestMvp            ( CodingUnit& cu,  CPelUnitBuf& origBuf, Mv curMv, RefPicList curRefList, AMVPInfo amvpInfo[2][MAX_REF_PICS], 
600
                                        int32_t BcwIdx, Mv cMvPredSym[2], int32_t mvpIdxSym[2], Distortion& bestCost, bool skip );
601
602
  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 );
603
  bool xReadBufferedUniMv             ( CodingUnit& cu, RefPicList eRefPicList, int32_t iRefIdx, Mv& pcMvPred, Mv& rcMv, uint32_t& ruiBits, Distortion& ruiCost);
604
605
  void xExtDIFUpSamplingH             ( CPelBuf* pcPattern, bool useAltHpelIf);
606
  void xExtDIFUpSamplingQ             ( CPelBuf* pcPatternKey, Mv halfPelRef, int& patternId );
607
608
  void xEncodeInterResidualQT         ( CodingStructure &cs, Partitioner &partitioner, const ComponentID compID );
609
  void xEstimateInterResidualQT       ( CodingStructure &cs, Partitioner &partitioner, Distortion *puiZeroDist = NULL );
610
  uint64_t xGetSymbolFracBitsInter    ( CodingStructure &cs, Partitioner &partitioner );
611
  void  xSetIntraSearchRangeIBC       ( CodingUnit& pu, int iRoiWidth, int iRoiHeight, Mv& rcMvSrchRngLT, Mv& rcMvSrchRngRB);
612
  void  xIBCEstimation                ( CodingUnit& cu, PelUnitBuf& origBuf, Mv* pcMvPred, Mv& rcMv, Distortion& ruiCost );
613
  void  xIBCSearchMVCandUpdate        ( Distortion  uiSad, int x, int y, Distortion* uiSadBestCand, Mv* cMVCand);
614
  int   xIBCSearchMVChromaRefine      ( CodingUnit& cu, int iRoiWidth, int iRoiHeight, int cuPelX, int cuPelY, Distortion* uiSadBestCand, Mv* cMVCand);
615
  void  xIntraPatternSearchIBC        ( CodingUnit& pu, TZSearchStruct& cStruct, Mv& rcMv, Distortion& ruiCost, Mv* cMvSrchRngLT, Mv* cMvSrchRngRB, Mv* pcMvPred);
616
};// END CLASS DEFINITION EncSearch
617
618
} // namespace vvenc
619
620
//! \}
621