/* The copyright in this software is being made available under the BSD * License, included below. This software may be subject to other third party * and contributor rights, including patent rights, and no such rights are * granted under this license. * * Copyright (c) 2010-2015, ITU/ISO/IEC * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /** \file TEncSearch.h \brief encoder search class (header) */ #ifndef __TENCSEARCH__ #define __TENCSEARCH__ // Include files #include "TLibCommon/TComYuv.h" #include "TLibCommon/TComMotionInfo.h" #include "TLibCommon/TComPattern.h" #include "TLibCommon/TComPrediction.h" #include "TLibCommon/TComTrQuant.h" #include "TLibCommon/TComPic.h" #include "TLibCommon/TComRectangle.h" #include "TEncEntropy.h" #include "TEncSbac.h" #include "TEncCfg.h" //! \ingroup TLibEncoder //! \{ class TEncCu; // ==================================================================================================================== // Class definition // ==================================================================================================================== static const UInt MAX_NUM_REF_LIST_ADAPT_SR=2; static const UInt MAX_IDX_ADAPT_SR=33; static const UInt NUM_MV_PREDICTORS=3; /// encoder search class class TEncSearch : public TComPrediction { private: TCoeff** m_ppcQTTempCoeff[MAX_NUM_COMPONENT /* 0->Y, 1->Cb, 2->Cr*/]; TCoeff* m_pcQTTempCoeff[MAX_NUM_COMPONENT]; #if ADAPTIVE_QP_SELECTION TCoeff** m_ppcQTTempArlCoeff[MAX_NUM_COMPONENT]; TCoeff* m_pcQTTempArlCoeff[MAX_NUM_COMPONENT]; #endif UChar* m_puhQTTempTrIdx; UChar* m_puhQTTempCbf[MAX_NUM_COMPONENT]; TComYuv* m_pcQTTempTComYuv; TComYuv m_tmpYuvPred; // To be used in xGetInterPredictionError() to avoid constant memory allocation/deallocation Char* m_phQTTempCrossComponentPredictionAlpha[MAX_NUM_COMPONENT]; Pel* m_pSharedPredTransformSkip[MAX_NUM_COMPONENT]; TCoeff* m_pcQTTempTUCoeff[MAX_NUM_COMPONENT]; UChar* m_puhQTTempTransformSkipFlag[MAX_NUM_COMPONENT]; TComYuv m_pcQTTempTransformSkipTComYuv; #if ADAPTIVE_QP_SELECTION TCoeff* m_ppcQTTempTUArlCoeff[MAX_NUM_COMPONENT]; #endif protected: // interface to option TEncCfg* m_pcEncCfg; // interface to classes TComTrQuant* m_pcTrQuant; TComRdCost* m_pcRdCost; TEncEntropy* m_pcEntropyCoder; // ME parameters Int m_iSearchRange; Int m_bipredSearchRange; // Search range for bi-prediction Int m_iFastSearch; #if NH_MV Bool m_vertRestriction; #endif Int m_aaiAdaptSR[MAX_NUM_REF_LIST_ADAPT_SR][MAX_IDX_ADAPT_SR]; TComMv m_cSrchRngLT; TComMv m_cSrchRngRB; TComMv m_acMvPredictors[NUM_MV_PREDICTORS]; // Left, Above, AboveRight. enum MVP_DIR first NUM_MV_PREDICTORS entries are suitable for accessing. // RD computation TEncSbac*** m_pppcRDSbacCoder; TEncSbac* m_pcRDGoOnSbacCoder; DistParam m_cDistParam; // Misc. Pel* m_pTempPel; const UInt* m_puiDFilter; #if NH_3D_VSO // M17 TComYuv m_cYuvRecTemp; #endif // AMVP cost computation // UInt m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS]; UInt m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1]; //th array bounds TComMv m_integerMv2Nx2N[NUM_REF_PIC_LIST_01][MAX_NUM_REF]; public: TEncSearch(); virtual ~TEncSearch(); Void init( TEncCfg* pcEncCfg, TComTrQuant* pcTrQuant, Int iSearchRange, Int bipredSearchRange, Int iFastSearch, const UInt maxCUWidth, const UInt maxCUHeight, const UInt maxTotalCUDepth, TEncEntropy* pcEntropyCoder, TComRdCost* pcRdCost, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder ); protected: /// sub-function for motion vector refinement used in fractional-pel accuracy Distortion xPatternRefinement( TComPattern* pcPatternKey, TComMv baseRefMv, Int iFrac, TComMv& rcMvFrac, Bool bAllowUseOfHadamard ); typedef struct { Pel* piRefY; Int iYStride; Int iBestX; Int iBestY; UInt uiBestRound; UInt uiBestDistance; Distortion uiBestSad; UChar ucPointNr; } IntTZSearchStruct; // sub-functions for ME __inline Void xTZSearchHelp ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, const Int iSearchX, const Int iSearchY, const UChar ucPointNr, const UInt uiDistance ); __inline Void xTZ2PointSearch ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB ); __inline Void xTZ8PointSquareSearch ( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist ); __inline Void xTZ8PointDiamondSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStrukt, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist ); Void xGetInterPredictionError( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, Distortion& ruiSAD, Bool Hadamard ); public: Void estIntraPredLumaQT ( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, TComYuv* pcRecoYuv, Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE] #if H_3D_DIM , Bool bOnlyIVP #endif DEBUG_STRING_FN_DECLARE(sDebug)); Void estIntraPredChromaQT ( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, TComYuv* pcRecoYuv, Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE] DEBUG_STRING_FN_DECLARE(sDebug)); #if H_3D Void estIntraPredDIS ( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, TComYuv* pcRecoYuv, UInt& ruiDistC, Bool bLumaOnly ); #endif /// encoder estimation - inter prediction (non-skip) Void predInterSearch ( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv* pcPredYuv, TComYuv* pcResiYuv, TComYuv* pcRecoYuv #if H_3D_FAST_TEXTURE_ENCODING Bool bFMD, #endif DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseRes = false #if AMP_MRG ,Bool bUseMRG = false #endif ); /// encode residual and compute rd-cost for inter mode Void encodeResAndCalcRdInterCU( TComDataCU* pcCU, TComYuv* pcYuvOrg, TComYuv* pcYuvPred, TComYuv* pcYuvResi, TComYuv* pcYuvResiBest, TComYuv* pcYuvRec, Bool bSkipResidual DEBUG_STRING_FN_DECLARE(sDebug) ); #if H_3D_INTER_SDC Void encodeResAndCalcRdInterSDCCU( TComDataCU* pcCU, TComYuv* pcOrg, TComYuv* pcPred, TComYuv* pcResi, TComYuv* pcRec, Int uiOffset, const UInt uiDepth ); #endif /// set ME search range Void setAdaptiveSearchRange ( Int iDir, Int iRefIdx, Int iSearchRange) { assert(iDir < MAX_NUM_REF_LIST_ADAPT_SR && iRefIdx