source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.h @ 1390

Last change on this file since 1390 was 1372, checked in by seregin, 10 years ago

port rev 4490

  • Property svn:eol-style set to native
File size: 23.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncSearch.h
35    \brief    encoder search class (header)
36*/
37
38#ifndef __TENCSEARCH__
39#define __TENCSEARCH__
40
41// Include files
42#include "TLibCommon/TComYuv.h"
43#include "TLibCommon/TComMotionInfo.h"
44#include "TLibCommon/TComPattern.h"
45#include "TLibCommon/TComPrediction.h"
46#include "TLibCommon/TComTrQuant.h"
47#include "TLibCommon/TComPic.h"
48#include "TLibCommon/TComRectangle.h"
49#include "TEncEntropy.h"
50#include "TEncSbac.h"
51#include "TEncCfg.h"
52
53
54//! \ingroup TLibEncoder
55//! \{
56
57class TEncCu;
58
59// ====================================================================================================================
60// Class definition
61// ====================================================================================================================
62
63static const UInt MAX_NUM_REF_LIST_ADAPT_SR=2;
64static const UInt MAX_IDX_ADAPT_SR=33;
65static const UInt NUM_MV_PREDICTORS=3;
66
67/// encoder search class
68class TEncSearch : public TComPrediction
69{
70private:
71  TCoeff**        m_ppcQTTempCoeff[MAX_NUM_COMPONENT /* 0->Y, 1->Cb, 2->Cr*/];
72  TCoeff*         m_pcQTTempCoeff[MAX_NUM_COMPONENT];
73#if ADAPTIVE_QP_SELECTION
74  TCoeff**        m_ppcQTTempArlCoeff[MAX_NUM_COMPONENT];
75  TCoeff*         m_pcQTTempArlCoeff[MAX_NUM_COMPONENT];
76#endif
77  UChar*          m_puhQTTempTrIdx;
78  UChar*          m_puhQTTempCbf[MAX_NUM_COMPONENT];
79
80  TComYuv*        m_pcQTTempTComYuv;
81  TComYuv         m_tmpYuvPred; // To be used in xGetInterPredictionError() to avoid constant memory allocation/deallocation
82
83  Char*           m_phQTTempCrossComponentPredictionAlpha[MAX_NUM_COMPONENT];
84  Pel*            m_pSharedPredTransformSkip[MAX_NUM_COMPONENT];
85  TCoeff*         m_pcQTTempTUCoeff[MAX_NUM_COMPONENT];
86  UChar*          m_puhQTTempTransformSkipFlag[MAX_NUM_COMPONENT];
87  TComYuv         m_pcQTTempTransformSkipTComYuv;
88#if ADAPTIVE_QP_SELECTION
89  TCoeff*         m_ppcQTTempTUArlCoeff[MAX_NUM_COMPONENT];
90#endif
91
92protected:
93  // interface to option
94  TEncCfg*        m_pcEncCfg;
95
96  // interface to classes
97  TComTrQuant*    m_pcTrQuant;
98  TComRdCost*     m_pcRdCost;
99  TEncEntropy*    m_pcEntropyCoder;
100
101  // ME parameters
102  Int             m_iSearchRange;
103  Int             m_bipredSearchRange; // Search range for bi-prediction
104  Int             m_iFastSearch;
105  Int             m_aaiAdaptSR[MAX_NUM_REF_LIST_ADAPT_SR][MAX_IDX_ADAPT_SR];
106  TComMv          m_cSrchRngLT;
107  TComMv          m_cSrchRngRB;
108  TComMv          m_acMvPredictors[NUM_MV_PREDICTORS]; // Left, Above, AboveRight. enum MVP_DIR first NUM_MV_PREDICTORS entries are suitable for accessing.
109
110  // RD computation
111  TEncSbac***     m_pppcRDSbacCoder;
112  TEncSbac*       m_pcRDGoOnSbacCoder;
113  DistParam       m_cDistParam;
114
115  // Misc.
116  Pel*            m_pTempPel;
117  const UInt*     m_puiDFilter;
118
119  // AMVP cost computation
120  // UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS];
121  UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1]; //th array bounds
122
123  TComMv          m_integerMv2Nx2N[NUM_REF_PIC_LIST_01][MAX_NUM_REF];
124
125  Bool            m_isInitialized;
126
127#if SVC_EXTENSION
128#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
129  Bool            m_disableILP;
130#endif
131#endif
132
133public:
134  TEncSearch();
135  virtual ~TEncSearch();
136
137  Void init(TEncCfg*      pcEncCfg,
138            TComTrQuant*  pcTrQuant,
139            Int           iSearchRange,
140            Int           bipredSearchRange,
141            Int           iFastSearch,
142            const UInt    maxCUWidth,
143            const UInt    maxCUHeight,
144            const UInt    maxTotalCUDepth,
145            TEncEntropy*  pcEntropyCoder,
146            TComRdCost*   pcRdCost,
147            TEncSbac***   pppcRDSbacCoder,
148            TEncSbac*     pcRDGoOnSbacCoder );
149
150  Void destroy();
151
152protected:
153
154  /// sub-function for motion vector refinement used in fractional-pel accuracy
155  Distortion  xPatternRefinement( TComPattern* pcPatternKey,
156                                  TComMv baseRefMv,
157                                  Int iFrac, TComMv& rcMvFrac, Bool bAllowUseOfHadamard
158                                 );
159
160  typedef struct
161  {
162    Pel*        piRefY;
163    Int         iYStride;
164    Int         iBestX;
165    Int         iBestY;
166    UInt        uiBestRound;
167    UInt        uiBestDistance;
168    Distortion  uiBestSad;
169    UChar       ucPointNr;
170  } IntTZSearchStruct;
171
172  // sub-functions for ME
173  __inline Void xTZSearchHelp         ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, const Int iSearchX, const Int iSearchY, const UChar ucPointNr, const UInt uiDistance );
174  __inline Void xTZ2PointSearch       ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB );
175  __inline Void xTZ8PointSquareSearch ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist );
176  __inline Void xTZ8PointDiamondSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist );
177
178  Void xGetInterPredictionError( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, Distortion& ruiSAD, Bool Hadamard );
179
180public:
181  Void  estIntraPredLumaQT      ( TComDataCU* pcCU,
182                                  TComYuv*    pcOrgYuv,
183                                  TComYuv*    pcPredYuv,
184                                  TComYuv*    pcResiYuv,
185                                  TComYuv*    pcRecoYuv,
186                                  Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]
187                                  DEBUG_STRING_FN_DECLARE(sDebug));
188
189  Void  estIntraPredChromaQT    ( TComDataCU* pcCU,
190                                  TComYuv*    pcOrgYuv,
191                                  TComYuv*    pcPredYuv,
192                                  TComYuv*    pcResiYuv,
193                                  TComYuv*    pcRecoYuv,
194                                  Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]
195                                  DEBUG_STRING_FN_DECLARE(sDebug));
196
197  /// encoder estimation - inter prediction (non-skip)
198#if SVC_EXTENSION
199  Bool predInterSearch          ( TComDataCU* pcCU,
200#else
201  Void predInterSearch          ( TComDataCU* pcCU,
202#endif
203                                  TComYuv*    pcOrgYuv,
204                                  TComYuv*    pcPredYuv,
205                                  TComYuv*    pcResiYuv,
206                                  TComYuv*    pcRecoYuv
207                                  DEBUG_STRING_FN_DECLARE(sDebug),
208                                  Bool        bUseRes = false
209#if AMP_MRG
210                                 ,Bool        bUseMRG = false
211#endif
212                                );
213
214  /// encode residual and compute rd-cost for inter mode
215  Void encodeResAndCalcRdInterCU( TComDataCU* pcCU,
216                                  TComYuv*    pcYuvOrg,
217                                  TComYuv*    pcYuvPred,
218                                  TComYuv*    pcYuvResi,
219                                  TComYuv*    pcYuvResiBest,
220                                  TComYuv*    pcYuvRec,
221                                  Bool        bSkipResidual
222                                  DEBUG_STRING_FN_DECLARE(sDebug) );
223
224  /// set ME search range
225  Void setAdaptiveSearchRange   ( Int iDir, Int iRefIdx, Int iSearchRange) { assert(iDir < MAX_NUM_REF_LIST_ADAPT_SR && iRefIdx<Int(MAX_IDX_ADAPT_SR)); m_aaiAdaptSR[iDir][iRefIdx] = iSearchRange; }
226
227  Void xEncPCM    (TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piOrg, Pel* piPCM, Pel* piPred, Pel* piResi, Pel* piReco, UInt uiStride, UInt uiWidth, UInt uiHeight, const ComponentID compID );
228  Void IPCMSearch (TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* rpcPredYuv, TComYuv* rpcResiYuv, TComYuv* rpcRecoYuv );
229
230#if SVC_EXTENSION
231#if ENCODER_FAST_MODE
232  Bool predInterSearchILRUni    ( TComDataCU* pcCU, TComYuv*    pcOrgYuv, TComYuv*&   rpcPredYuv, TComYuv*&   rpcResiYuv, TComYuv*&   rpcRecoYuv, UInt        refLayerId );
233#endif 
234#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
235  Void setDisableILP(Bool a) {m_disableILP = a;}
236#endif
237#endif //SVC_EXTENSION
238
239protected:
240
241  // -------------------------------------------------------------------------------------------------------------------
242  // Intra search
243  // -------------------------------------------------------------------------------------------------------------------
244
245  Void  xEncSubdivCbfQT           ( TComTU      &rTu,
246                                    Bool         bLuma,
247                                    Bool         bChroma );
248
249  Void  xEncCoeffQT               ( TComTU &rTu,
250                                    ComponentID  component,
251                                    Bool         bRealCoeff );
252  Void  xEncIntraHeader           ( TComDataCU*  pcCU,
253                                    UInt         uiTrDepth,
254                                    UInt         uiAbsPartIdx,
255                                    Bool         bLuma,
256                                    Bool         bChroma );
257  UInt  xGetIntraBitsQT           ( TComTU &rTu,
258                                    Bool         bLuma,
259                                    Bool         bChroma,
260                                    Bool         bRealCoeff );
261
262  UInt  xGetIntraBitsQTChroma    ( TComTU &rTu,
263                                   ComponentID compID,
264                                   Bool          bRealCoeff );
265
266  Void  xIntraCodingTUBlock       (       TComYuv*      pcOrgYuv,
267                                          TComYuv*      pcPredYuv,
268                                          TComYuv*      pcResiYuv,
269                                          Pel           resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE],
270                                    const Bool          checkCrossCPrediction,
271                                          Distortion&   ruiDist,
272                                    const ComponentID   compID,
273                                          TComTU        &rTu
274                                    DEBUG_STRING_FN_DECLARE(sTest)
275                                         ,Int           default0Save1Load2 = 0
276                                   );
277
278  Void  xRecurIntraCodingLumaQT   ( TComYuv*    pcOrgYuv,
279                                    TComYuv*    pcPredYuv,
280                                    TComYuv*    pcResiYuv,
281                                    Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE],
282                                    Distortion& ruiDistY,
283#if HHI_RQT_INTRA_SPEEDUP
284                                    Bool         bCheckFirst,
285#endif
286                                    Double&      dRDCost,
287                                    TComTU      &rTu
288                                    DEBUG_STRING_FN_DECLARE(sDebug));
289
290  Void  xSetIntraResultLumaQT     ( TComYuv*     pcRecoYuv,
291                                    TComTU &rTu);
292
293  Void xStoreCrossComponentPredictionResult  (       Pel    *pResiLuma,
294                                               const Pel    *pBestLuma,
295                                                     TComTU &rTu,
296                                               const Int     xOffset,
297                                               const Int     yOffset,
298                                               const Int     strideResi,
299                                               const Int     strideBest );
300
301  Char xCalcCrossComponentPredictionAlpha    (       TComTU &rTu,
302                                               const ComponentID compID,
303                                               const Pel*        piResiL,
304                                               const Pel*        piResiC,
305                                               const Int         width,
306                                               const Int         height,
307                                               const Int         strideL,
308                                               const Int         strideC );
309
310  Void  xRecurIntraChromaCodingQT ( TComYuv*    pcOrgYuv,
311                                    TComYuv*    pcPredYuv,
312                                    TComYuv*    pcResiYuv,
313                                    Pel         resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE],
314                                    Distortion& ruiDist,
315                                    TComTU      &rTu
316                                    DEBUG_STRING_FN_DECLARE(sDebug));
317
318  Void  xSetIntraResultChromaQT   ( TComYuv*    pcRecoYuv, TComTU &rTu);
319
320  Void  xStoreIntraResultQT       ( const ComponentID compID, TComTU &rTu);
321  Void  xLoadIntraResultQT        ( const ComponentID compID, TComTU &rTu);
322
323
324  // -------------------------------------------------------------------------------------------------------------------
325  // Inter search (AMP)
326  // -------------------------------------------------------------------------------------------------------------------
327
328  Void xEstimateMvPredAMVP        ( TComDataCU* pcCU,
329                                    TComYuv*    pcOrgYuv,
330                                    UInt        uiPartIdx,
331                                    RefPicList  eRefPicList,
332                                    Int         iRefIdx,
333                                    TComMv&     rcMvPred,
334                                    Bool        bFilled = false
335                                  , Distortion* puiDistBiP = NULL
336                                     );
337
338  Void xCheckBestMVP              ( TComDataCU* pcCU,
339                                    RefPicList  eRefPicList,
340                                    TComMv      cMv,
341                                    TComMv&     rcMvPred,
342                                    Int&        riMVPIdx,
343                                    UInt&       ruiBits,
344                                    Distortion& ruiCost );
345
346  Distortion xGetTemplateCost    ( TComDataCU*  pcCU,
347                                    UInt        uiPartAddr,
348                                    TComYuv*    pcOrgYuv,
349                                    TComYuv*    pcTemplateCand,
350                                    TComMv      cMvCand,
351                                    Int         iMVPIdx,
352                                    Int         iMVPNum,
353                                    RefPicList  eRefPicList,
354                                    Int         iRefIdx,
355                                    Int         iSizeX,
356                                    Int         iSizeY
357                                   );
358
359
360  Void xCopyAMVPInfo              ( AMVPInfo*   pSrc, AMVPInfo* pDst );
361  UInt xGetMvpIdxBits             ( Int iIdx, Int iNum );
362  Void xGetBlkBits                ( PartSize  eCUMode, Bool bPSlice, Int iPartIdx,  UInt uiLastMode, UInt uiBlkBit[3]);
363
364  Void xMergeEstimation           ( TComDataCU*  pcCU,
365                                    TComYuv*     pcYuvOrg,
366                                    Int          iPartIdx,
367                                    UInt&        uiInterDir,
368                                    TComMvField* pacMvField,
369                                    UInt&        uiMergeIndex,
370                                    Distortion&  ruiCost,
371                                    TComMvField* cMvFieldNeighbours,
372                                    UChar*       uhInterDirNeighbours,
373                                    Int&         numValidMergeCand
374                                   );
375
376  Void xRestrictBipredMergeCand   ( TComDataCU*     pcCU,
377                                    UInt            puIdx,
378                                    TComMvField*    mvFieldNeighbours,
379                                    UChar*          interDirNeighbours,
380                                    Int             numValidMergeCand );
381
382
383  // -------------------------------------------------------------------------------------------------------------------
384  // motion estimation
385  // -------------------------------------------------------------------------------------------------------------------
386
387  Void xMotionEstimation          ( TComDataCU*  pcCU,
388                                    TComYuv*     pcYuvOrg,
389                                    Int          iPartIdx,
390                                    RefPicList   eRefPicList,
391                                    TComMv*      pcMvPred,
392                                    Int          iRefIdxPred,
393                                    TComMv&      rcMv,
394                                    UInt&        ruiBits,
395                                    Distortion&  ruiCost,
396                                    Bool         bBi = false  );
397
398  Void xTZSearch                  ( TComDataCU*  pcCU,
399                                    TComPattern* pcPatternKey,
400                                    Pel*         piRefY,
401                                    Int          iRefStride,
402                                    TComMv*      pcMvSrchRngLT,
403                                    TComMv*      pcMvSrchRngRB,
404                                    TComMv&      rcMv,
405                                    Distortion&  ruiSAD,
406                                    const TComMv *pIntegerMv2Nx2NPred
407                                    );
408
409  Void xTZSearchSelective         ( TComDataCU*  pcCU,
410                                    TComPattern* pcPatternKey,
411                                    Pel*         piRefY,
412                                    Int          iRefStride,
413                                    TComMv*      pcMvSrchRngLT,
414                                    TComMv*      pcMvSrchRngRB,
415                                    TComMv&      rcMv,
416                                    Distortion&  ruiSAD,
417                                    const TComMv *pIntegerMv2Nx2NPred
418                                    );
419
420  Void xSetSearchRange            ( TComDataCU*  pcCU,
421                                    TComMv&      cMvPred,
422                                    Int          iSrchRng,
423                                    TComMv&      rcMvSrchRngLT,
424                                    TComMv&      rcMvSrchRngRB );
425
426  Void xPatternSearchFast         ( TComDataCU*  pcCU,
427                                    TComPattern* pcPatternKey,
428                                    Pel*         piRefY,
429                                    Int          iRefStride,
430                                    TComMv*      pcMvSrchRngLT,
431                                    TComMv*      pcMvSrchRngRB,
432                                    TComMv&      rcMv,
433                                    Distortion&  ruiSAD,
434                                    const TComMv* pIntegerMv2Nx2NPred
435                                  );
436
437  Void xPatternSearch             ( TComPattern* pcPatternKey,
438                                    Pel*         piRefY,
439                                    Int          iRefStride,
440                                    TComMv*      pcMvSrchRngLT,
441                                    TComMv*      pcMvSrchRngRB,
442                                    TComMv&      rcMv,
443                                    Distortion&  ruiSAD );
444
445  Void xPatternSearchFracDIF      (
446                                    Bool         bIsLosslessCoded,
447                                    TComPattern* pcPatternKey,
448                                    Pel*         piRefY,
449                                    Int          iRefStride,
450                                    TComMv*      pcMvInt,
451                                    TComMv&      rcMvHalf,
452                                    TComMv&      rcMvQter,
453                                    Distortion&  ruiCost
454                                   );
455
456  Void xExtDIFUpSamplingH( TComPattern* pcPattern );
457  Void xExtDIFUpSamplingQ( TComPattern* pcPatternKey, TComMv halfPelRef );
458
459  // -------------------------------------------------------------------------------------------------------------------
460  // T & Q & Q-1 & T-1
461  // -------------------------------------------------------------------------------------------------------------------
462
463
464  Void xEncodeInterResidualQT( const ComponentID compID, TComTU &rTu );
465  Void xEstimateInterResidualQT( TComYuv* pcResi, Double &rdCost, UInt &ruiBits, Distortion &ruiDist, Distortion *puiZeroDist, TComTU &rTu DEBUG_STRING_FN_DECLARE(sDebug) );
466  Void xSetInterResidualQTData( TComYuv* pcResi, Bool bSpatial, TComTU &rTu  );
467
468  UInt  xModeBitsIntra ( TComDataCU* pcCU, UInt uiMode, UInt uiPartOffset, UInt uiDepth, const ChannelType compID );
469  UInt  xUpdateCandList( UInt uiMode, Double uiCost, UInt uiFastCandNum, UInt * CandModeList, Double * CandCostList );
470
471  // -------------------------------------------------------------------------------------------------------------------
472  // compute symbol bits
473  // -------------------------------------------------------------------------------------------------------------------
474
475  Void xAddSymbolBitsInter       ( TComDataCU*   pcCU,
476                                   UInt&         ruiBits);
477
478  Void  setWpScalingDistParam( TComDataCU* pcCU, Int iRefIdx, RefPicList eRefPicListCur );
479  inline  Void  setDistParamComp( ComponentID compIdx )  { m_cDistParam.compIdx = compIdx; }
480
481#if SVC_EXTENSION && REF_IDX_ME_ZEROMV
482  Void xPatternSearchFracDIFMv0  ( TComPattern*  pcPatternKey,
483                                   Pel*          piRefY,
484                                   Int           iRefStride,
485                                   TComMv*       pcMvInt,
486                                   TComMv&       rcMvHalf,
487                                   TComMv&       rcMvQter,
488                                   UInt&         ruiCost     );
489#endif //SVC_EXTENSION 
490
491};// END CLASS DEFINITION TEncSearch
492
493//! \}
494
495#endif // __TENCSEARCH__
Note: See TracBrowser for help on using the repository browser.