| 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-2012, 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 TEncCu.cpp |
|---|
| 35 | \brief Coding Unit (CU) encoder class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include <stdio.h> |
|---|
| 39 | #include "TEncTop.h" |
|---|
| 40 | #include "TEncCu.h" |
|---|
| 41 | #include "TEncAnalyze.h" |
|---|
| 42 | |
|---|
| 43 | #include <cmath> |
|---|
| 44 | #include <algorithm> |
|---|
| 45 | using namespace std; |
|---|
| 46 | |
|---|
| 47 | //! \ingroup TLibEncoder |
|---|
| 48 | //! \{ |
|---|
| 49 | |
|---|
| 50 | // ==================================================================================================================== |
|---|
| 51 | // Constructor / destructor / create / destroy |
|---|
| 52 | // ==================================================================================================================== |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | \param uiTotalDepth total number of allowable depth |
|---|
| 56 | \param uiMaxWidth largest CU width |
|---|
| 57 | \param uiMaxHeight largest CU height |
|---|
| 58 | */ |
|---|
| 59 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
|---|
| 60 | { |
|---|
| 61 | Int i; |
|---|
| 62 | |
|---|
| 63 | m_uhTotalDepth = uhTotalDepth + 1; |
|---|
| 64 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
|---|
| 65 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
|---|
| 66 | |
|---|
| 67 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 68 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 69 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 70 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 71 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 72 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 73 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 74 | #if H3D_IVRP |
|---|
| 75 | m_ppcResPredTmp = new TComYuv*[m_uhTotalDepth-1]; |
|---|
| 76 | #endif |
|---|
| 77 | |
|---|
| 78 | #if HHI_MPI |
|---|
| 79 | m_puhDepthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
|---|
| 80 | m_puhWidthSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
|---|
| 81 | m_puhHeightSaved = new UChar[1ll<<( ( m_uhTotalDepth - 1 )<<1 )]; |
|---|
| 82 | #endif |
|---|
| 83 | |
|---|
| 84 | UInt uiNumPartitions; |
|---|
| 85 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
|---|
| 86 | { |
|---|
| 87 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
|---|
| 88 | UInt uiWidth = uiMaxWidth >> i; |
|---|
| 89 | UInt uiHeight = uiMaxHeight >> i; |
|---|
| 90 | |
|---|
| 91 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
|---|
| 92 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
|---|
| 93 | |
|---|
| 94 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
|---|
| 95 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
|---|
| 96 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
|---|
| 97 | |
|---|
| 98 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
|---|
| 99 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
|---|
| 100 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
|---|
| 101 | |
|---|
| 102 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
|---|
| 103 | #if H3D_IVRP |
|---|
| 104 | m_ppcResPredTmp [i] = new TComYuv; m_ppcResPredTmp [i]->create(uiWidth, uiHeight); |
|---|
| 105 | #endif |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | m_bEncodeDQP = false; |
|---|
| 109 | m_checkBurstIPCMFlag = false; |
|---|
| 110 | |
|---|
| 111 | // initialize partition order. |
|---|
| 112 | UInt* piTmp = &g_auiZscanToRaster[0]; |
|---|
| 113 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
|---|
| 114 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
|---|
| 115 | |
|---|
| 116 | // initialize conversion matrix from partition index to pel |
|---|
| 117 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
|---|
| 118 | initMotionReferIdx ( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | Void TEncCu::destroy() |
|---|
| 122 | { |
|---|
| 123 | Int i; |
|---|
| 124 | |
|---|
| 125 | #if HHI_MPI |
|---|
| 126 | delete[] m_puhDepthSaved; m_puhDepthSaved = NULL; |
|---|
| 127 | delete[] m_puhWidthSaved; m_puhWidthSaved = NULL; |
|---|
| 128 | delete[] m_puhHeightSaved; m_puhHeightSaved = NULL; |
|---|
| 129 | #endif |
|---|
| 130 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
|---|
| 131 | { |
|---|
| 132 | if(m_ppcBestCU[i]) |
|---|
| 133 | { |
|---|
| 134 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
|---|
| 135 | } |
|---|
| 136 | if(m_ppcTempCU[i]) |
|---|
| 137 | { |
|---|
| 138 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
|---|
| 139 | } |
|---|
| 140 | if(m_ppcPredYuvBest[i]) |
|---|
| 141 | { |
|---|
| 142 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
|---|
| 143 | } |
|---|
| 144 | if(m_ppcResiYuvBest[i]) |
|---|
| 145 | { |
|---|
| 146 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
|---|
| 147 | } |
|---|
| 148 | if(m_ppcRecoYuvBest[i]) |
|---|
| 149 | { |
|---|
| 150 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
|---|
| 151 | } |
|---|
| 152 | if(m_ppcPredYuvTemp[i]) |
|---|
| 153 | { |
|---|
| 154 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
|---|
| 155 | } |
|---|
| 156 | if(m_ppcResiYuvTemp[i]) |
|---|
| 157 | { |
|---|
| 158 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
|---|
| 159 | } |
|---|
| 160 | if(m_ppcRecoYuvTemp[i]) |
|---|
| 161 | { |
|---|
| 162 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
|---|
| 163 | } |
|---|
| 164 | if(m_ppcOrigYuv[i]) |
|---|
| 165 | { |
|---|
| 166 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
|---|
| 167 | } |
|---|
| 168 | #if H3D_IVRP |
|---|
| 169 | if(m_ppcResPredTmp[i]) |
|---|
| 170 | { |
|---|
| 171 | m_ppcResPredTmp [i]->destroy(); delete m_ppcResPredTmp[i]; m_ppcResPredTmp[i] = NULL; |
|---|
| 172 | } |
|---|
| 173 | #endif |
|---|
| 174 | } |
|---|
| 175 | if(m_ppcBestCU) |
|---|
| 176 | { |
|---|
| 177 | delete [] m_ppcBestCU; |
|---|
| 178 | m_ppcBestCU = NULL; |
|---|
| 179 | } |
|---|
| 180 | if(m_ppcTempCU) |
|---|
| 181 | { |
|---|
| 182 | delete [] m_ppcTempCU; |
|---|
| 183 | m_ppcTempCU = NULL; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | if(m_ppcPredYuvBest) |
|---|
| 187 | { |
|---|
| 188 | delete [] m_ppcPredYuvBest; |
|---|
| 189 | m_ppcPredYuvBest = NULL; |
|---|
| 190 | } |
|---|
| 191 | if(m_ppcResiYuvBest) |
|---|
| 192 | { |
|---|
| 193 | delete [] m_ppcResiYuvBest; |
|---|
| 194 | m_ppcResiYuvBest = NULL; |
|---|
| 195 | } |
|---|
| 196 | if(m_ppcRecoYuvBest) |
|---|
| 197 | { |
|---|
| 198 | delete [] m_ppcRecoYuvBest; |
|---|
| 199 | m_ppcRecoYuvBest = NULL; |
|---|
| 200 | } |
|---|
| 201 | if(m_ppcPredYuvTemp) |
|---|
| 202 | { |
|---|
| 203 | delete [] m_ppcPredYuvTemp; |
|---|
| 204 | m_ppcPredYuvTemp = NULL; |
|---|
| 205 | } |
|---|
| 206 | if(m_ppcResiYuvTemp) |
|---|
| 207 | { |
|---|
| 208 | delete [] m_ppcResiYuvTemp; |
|---|
| 209 | m_ppcResiYuvTemp = NULL; |
|---|
| 210 | } |
|---|
| 211 | if(m_ppcRecoYuvTemp) |
|---|
| 212 | { |
|---|
| 213 | delete [] m_ppcRecoYuvTemp; |
|---|
| 214 | m_ppcRecoYuvTemp = NULL; |
|---|
| 215 | } |
|---|
| 216 | if(m_ppcOrigYuv) |
|---|
| 217 | { |
|---|
| 218 | delete [] m_ppcOrigYuv; |
|---|
| 219 | m_ppcOrigYuv = NULL; |
|---|
| 220 | } |
|---|
| 221 | #if H3D_IVRP |
|---|
| 222 | if(m_ppcResPredTmp) |
|---|
| 223 | { |
|---|
| 224 | delete [] m_ppcResPredTmp; |
|---|
| 225 | m_ppcResPredTmp = NULL; |
|---|
| 226 | } |
|---|
| 227 | #endif |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | /** \param pcEncTop pointer of encoder class |
|---|
| 231 | */ |
|---|
| 232 | Void TEncCu::init( TEncTop* pcEncTop ) |
|---|
| 233 | { |
|---|
| 234 | m_pcEncCfg = pcEncTop; |
|---|
| 235 | m_pcPredSearch = pcEncTop->getPredSearch(); |
|---|
| 236 | m_pcTrQuant = pcEncTop->getTrQuant(); |
|---|
| 237 | m_pcBitCounter = pcEncTop->getBitCounter(); |
|---|
| 238 | m_pcRdCost = pcEncTop->getRdCost(); |
|---|
| 239 | |
|---|
| 240 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
|---|
| 241 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
|---|
| 242 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
|---|
| 243 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
|---|
| 244 | |
|---|
| 245 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
|---|
| 246 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
|---|
| 247 | |
|---|
| 248 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | // ==================================================================================================================== |
|---|
| 252 | // Public member functions |
|---|
| 253 | // ==================================================================================================================== |
|---|
| 254 | |
|---|
| 255 | /** \param rpcCU pointer of CU data class |
|---|
| 256 | */ |
|---|
| 257 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
|---|
| 258 | { |
|---|
| 259 | // initialize CU data |
|---|
| 260 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
|---|
| 261 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
|---|
| 262 | |
|---|
| 263 | // analysis of CU |
|---|
| 264 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
|---|
| 265 | |
|---|
| 266 | #if ADAPTIVE_QP_SELECTION |
|---|
| 267 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
|---|
| 268 | { |
|---|
| 269 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
|---|
| 270 | { |
|---|
| 271 | xLcuCollectARLStats( rpcCU); |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | #endif |
|---|
| 275 | } |
|---|
| 276 | /** \param pcCU pointer of CU data class, bForceTerminate when set to true terminates slice (default is false). |
|---|
| 277 | */ |
|---|
| 278 | Void TEncCu::encodeCU ( TComDataCU* pcCU, Bool bForceTerminate ) |
|---|
| 279 | { |
|---|
| 280 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
|---|
| 281 | { |
|---|
| 282 | setdQPFlag(true); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | TComPic* pcPic = pcCU->getPic(); |
|---|
| 286 | Bool checkBurstIPCMFlag = (pcPic->getSlice(0)->getSPS()->getUsePCM())? true : false; |
|---|
| 287 | |
|---|
| 288 | setCheckBurstIPCMFlag( checkBurstIPCMFlag ); |
|---|
| 289 | |
|---|
| 290 | pcCU->setNumSucIPCM(0); |
|---|
| 291 | pcCU->setLastCUSucIPCMFlag(false); |
|---|
| 292 | |
|---|
| 293 | // Encode CU data |
|---|
| 294 | xEncodeCU( pcCU, 0, 0 ); |
|---|
| 295 | |
|---|
| 296 | bool bTerminateSlice = bForceTerminate; |
|---|
| 297 | UInt uiCUAddr = pcCU->getAddr(); |
|---|
| 298 | /* If at the end of an LCU line but not at the end of a substream, perform CABAC flush */ |
|---|
| 299 | if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1) |
|---|
| 300 | { |
|---|
| 301 | Int iNumSubstreams = pcCU->getSlice()->getPPS()->getNumSubstreams(); |
|---|
| 302 | UInt uiWidthInLCUs = pcCU->getPic()->getPicSym()->getFrameWidthInCU(); |
|---|
| 303 | UInt uiCol = uiCUAddr % uiWidthInLCUs; |
|---|
| 304 | UInt uiLin = uiCUAddr / uiWidthInLCUs; |
|---|
| 305 | UInt uiTileStartLCU = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); |
|---|
| 306 | UInt uiTileLCUX = uiTileStartLCU % uiWidthInLCUs; |
|---|
| 307 | UInt uiTileLCUY = uiTileStartLCU / uiWidthInLCUs; |
|---|
| 308 | UInt uiTileWidth = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileWidth(); |
|---|
| 309 | UInt uiTileHeight = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileHeight(); |
|---|
| 310 | Int iNumSubstreamsPerTile = iNumSubstreams; |
|---|
| 311 | if (pcCU->getSlice()->getPPS()->getNumSubstreams() > 1) |
|---|
| 312 | { |
|---|
| 313 | iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles(); |
|---|
| 314 | } |
|---|
| 315 | if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight)) |
|---|
| 316 | { |
|---|
| 317 | m_pcEntropyCoder->encodeFlush(); |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | // ==================================================================================================================== |
|---|
| 323 | // Protected member functions |
|---|
| 324 | // ==================================================================================================================== |
|---|
| 325 | /** Derive small set of test modes for AMP encoder speed-up |
|---|
| 326 | *\param rpcBestCU |
|---|
| 327 | *\param eParentPartSize |
|---|
| 328 | *\param bTestAMP_Hor |
|---|
| 329 | *\param bTestAMP_Ver |
|---|
| 330 | *\param bTestMergeAMP_Hor |
|---|
| 331 | *\param bTestMergeAMP_Ver |
|---|
| 332 | *\returns Void |
|---|
| 333 | */ |
|---|
| 334 | #if AMP_ENC_SPEEDUP |
|---|
| 335 | #if AMP_MRG |
|---|
| 336 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
|---|
| 337 | #else |
|---|
| 338 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
|---|
| 339 | #endif |
|---|
| 340 | { |
|---|
| 341 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
|---|
| 342 | { |
|---|
| 343 | bTestAMP_Hor = true; |
|---|
| 344 | } |
|---|
| 345 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
|---|
| 346 | { |
|---|
| 347 | bTestAMP_Ver = true; |
|---|
| 348 | } |
|---|
| 349 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
|---|
| 350 | { |
|---|
| 351 | bTestAMP_Hor = true; |
|---|
| 352 | bTestAMP_Ver = true; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | #if AMP_MRG |
|---|
| 356 | //! Utilizing the partition size of parent PU |
|---|
| 357 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
|---|
| 358 | { |
|---|
| 359 | bTestMergeAMP_Hor = true; |
|---|
| 360 | bTestMergeAMP_Ver = true; |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
|---|
| 364 | { |
|---|
| 365 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
|---|
| 366 | { |
|---|
| 367 | bTestMergeAMP_Hor = true; |
|---|
| 368 | } |
|---|
| 369 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
|---|
| 370 | { |
|---|
| 371 | bTestMergeAMP_Ver = true; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
|---|
| 376 | { |
|---|
| 377 | bTestMergeAMP_Hor = true; |
|---|
| 378 | bTestMergeAMP_Ver = true; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | if ( rpcBestCU->getWidth(0) == 64 ) |
|---|
| 382 | { |
|---|
| 383 | bTestAMP_Hor = false; |
|---|
| 384 | bTestAMP_Ver = false; |
|---|
| 385 | } |
|---|
| 386 | #else |
|---|
| 387 | //! Utilizing the partition size of parent PU |
|---|
| 388 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
|---|
| 389 | { |
|---|
| 390 | bTestAMP_Hor = true; |
|---|
| 391 | bTestAMP_Ver = true; |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | if ( eParentPartSize == SIZE_2Nx2N ) |
|---|
| 395 | { |
|---|
| 396 | bTestAMP_Hor = false; |
|---|
| 397 | bTestAMP_Ver = false; |
|---|
| 398 | } |
|---|
| 399 | #endif |
|---|
| 400 | } |
|---|
| 401 | #endif |
|---|
| 402 | |
|---|
| 403 | // ==================================================================================================================== |
|---|
| 404 | // Protected member functions |
|---|
| 405 | // ==================================================================================================================== |
|---|
| 406 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
|---|
| 407 | *\param rpcBestCU |
|---|
| 408 | *\param rpcTempCU |
|---|
| 409 | *\param uiDepth |
|---|
| 410 | *\returns Void |
|---|
| 411 | * |
|---|
| 412 | *- for loop of QP value to compress the current CU with all possible QP |
|---|
| 413 | */ |
|---|
| 414 | #if AMP_ENC_SPEEDUP |
|---|
| 415 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
|---|
| 416 | #else |
|---|
| 417 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
|---|
| 418 | #endif |
|---|
| 419 | { |
|---|
| 420 | TComPic* pcPic = rpcBestCU->getPic(); |
|---|
| 421 | |
|---|
| 422 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 423 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
|---|
| 424 | TComPic *pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
|---|
| 425 | |
|---|
| 426 | Bool depthMapDetect = (pcTexture != NULL); |
|---|
| 427 | Bool bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE); |
|---|
| 428 | |
|---|
| 429 | #if HHI_QTLPC_RAU_OFF_C0160 |
|---|
| 430 | Bool rapPic = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
|---|
| 431 | #endif |
|---|
| 432 | |
|---|
| 433 | Bool bTry2NxN = true; |
|---|
| 434 | Bool bTryNx2N = true; |
|---|
| 435 | #endif |
|---|
| 436 | |
|---|
| 437 | // get Original YUV data from picture |
|---|
| 438 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
|---|
| 439 | |
|---|
| 440 | // variables for fast encoder decision |
|---|
| 441 | Bool bEarlySkip = false; |
|---|
| 442 | Bool bTrySplit = true; |
|---|
| 443 | Double fRD_Skip = MAX_DOUBLE; |
|---|
| 444 | |
|---|
| 445 | // variable for Early CU determination |
|---|
| 446 | Bool bSubBranch = true; |
|---|
| 447 | |
|---|
| 448 | // variable for Cbf fast mode PU decision |
|---|
| 449 | Bool doNotBlockPu = true; |
|---|
| 450 | |
|---|
| 451 | Bool bTrySplitDQP = true; |
|---|
| 452 | |
|---|
| 453 | static Double afCost [ MAX_CU_DEPTH ]; |
|---|
| 454 | static Int aiNum [ MAX_CU_DEPTH ]; |
|---|
| 455 | |
|---|
| 456 | if ( rpcBestCU->getAddr() == 0 ) |
|---|
| 457 | { |
|---|
| 458 | ::memset( afCost, 0, sizeof( afCost ) ); |
|---|
| 459 | ::memset( aiNum, 0, sizeof( aiNum ) ); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | Bool bBoundary = false; |
|---|
| 463 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
|---|
| 464 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
|---|
| 465 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
|---|
| 466 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
|---|
| 467 | |
|---|
| 468 | #if LGE_ILLUCOMP_B0045 |
|---|
| 469 | Bool bICEnabled = ( |
|---|
| 470 | #if !LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 471 | !rpcTempCU->getSlice()->getIsDepth() && |
|---|
| 472 | #endif |
|---|
| 473 | rpcTempCU->getSlice()->getViewId()); |
|---|
| 474 | |
|---|
| 475 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
|---|
| 476 | #endif |
|---|
| 477 | |
|---|
| 478 | #if HHI_INTERVIEW_SKIP |
|---|
| 479 | Bool bFullyRenderedSec = true ; |
|---|
| 480 | if( m_pcEncCfg->getInterViewSkip() ) |
|---|
| 481 | { |
|---|
| 482 | Pel* pUsedSamples ; |
|---|
| 483 | UInt uiStride ; |
|---|
| 484 | pUsedSamples = pcPic->getUsedPelsMap()->getLumaAddr( rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
|---|
| 485 | uiStride = pcPic->getUsedPelsMap()->getStride(); |
|---|
| 486 | |
|---|
| 487 | for ( Int y=0; y<m_ppcOrigYuv[uiDepth]->getHeight(); y++) |
|---|
| 488 | { |
|---|
| 489 | for ( Int x=0; x<m_ppcOrigYuv[uiDepth]->getWidth(); x++) |
|---|
| 490 | { |
|---|
| 491 | if( pUsedSamples[x] !=0 ) |
|---|
| 492 | { |
|---|
| 493 | bFullyRenderedSec = false ; |
|---|
| 494 | break ; |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | if ( !bFullyRenderedSec ) |
|---|
| 498 | { |
|---|
| 499 | break; |
|---|
| 500 | } |
|---|
| 501 | pUsedSamples += uiStride ; |
|---|
| 502 | } |
|---|
| 503 | } |
|---|
| 504 | else |
|---|
| 505 | { |
|---|
| 506 | bFullyRenderedSec = false ; |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
|---|
| 510 | if( bFullyRenderedSec ) |
|---|
| 511 | { |
|---|
| 512 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
|---|
| 513 | } |
|---|
| 514 | else |
|---|
| 515 | { |
|---|
| 516 | m_pcRdCost->setLambdaScale( 1 ); |
|---|
| 517 | } |
|---|
| 518 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 519 | #endif |
|---|
| 520 | |
|---|
| 521 | #endif |
|---|
| 522 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
|---|
| 523 | Int iMinQP; |
|---|
| 524 | Int iMaxQP; |
|---|
| 525 | #if LOSSLESS_CODING |
|---|
| 526 | Bool isAddLowestQP = false; |
|---|
| 527 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
|---|
| 528 | #endif |
|---|
| 529 | |
|---|
| 530 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 531 | { |
|---|
| 532 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
|---|
| 533 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
|---|
| 534 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
|---|
| 535 | #if LOSSLESS_CODING |
|---|
| 536 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
|---|
| 537 | { |
|---|
| 538 | isAddLowestQP = true; |
|---|
| 539 | iMinQP = iMinQP - 1; |
|---|
| 540 | |
|---|
| 541 | } |
|---|
| 542 | #endif |
|---|
| 543 | } |
|---|
| 544 | else |
|---|
| 545 | { |
|---|
| 546 | iMinQP = rpcTempCU->getQP(0); |
|---|
| 547 | iMaxQP = rpcTempCU->getQP(0); |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | // If slice start or slice end is within this cu... |
|---|
| 551 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
|---|
| 552 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
|---|
| 553 | Bool bSliceEnd = (pcSlice->getEntropySliceCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getEntropySliceCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
|---|
| 554 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
|---|
| 555 | // We need to split, so don't try these modes. |
|---|
| 556 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
|---|
| 557 | { |
|---|
| 558 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
|---|
| 559 | { |
|---|
| 560 | #if LOSSLESS_CODING |
|---|
| 561 | if (isAddLowestQP && (iQP == iMinQP)) |
|---|
| 562 | { |
|---|
| 563 | iQP = lowestQP; |
|---|
| 564 | } |
|---|
| 565 | #endif |
|---|
| 566 | // variables for fast encoder decision |
|---|
| 567 | bEarlySkip = false; |
|---|
| 568 | bTrySplit = true; |
|---|
| 569 | fRD_Skip = MAX_DOUBLE; |
|---|
| 570 | |
|---|
| 571 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 572 | |
|---|
| 573 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 574 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
|---|
| 575 | |
|---|
| 576 | #if HHI_QTLPC_RAU_OFF_C0160 |
|---|
| 577 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC()) |
|---|
| 578 | #else |
|---|
| 579 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC()) |
|---|
| 580 | #endif |
|---|
| 581 | { |
|---|
| 582 | TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU |
|---|
| 583 | UInt uiCUIdx = rpcBestCU->getZorderIdxInCU(); |
|---|
| 584 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitionned than the texture. |
|---|
| 585 | if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split. |
|---|
| 586 | { |
|---|
| 587 | bTrySplit = true; |
|---|
| 588 | bTryNx2N = true; |
|---|
| 589 | bTry2NxN = true; |
|---|
| 590 | } |
|---|
| 591 | else |
|---|
| 592 | { |
|---|
| 593 | bTrySplit = false; |
|---|
| 594 | bTryNx2N = false; |
|---|
| 595 | bTry2NxN = false; |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | #endif |
|---|
| 599 | |
|---|
| 600 | // do inter modes, SKIP and 2Nx2N |
|---|
| 601 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
|---|
| 602 | { |
|---|
| 603 | #if H3D_IVRP |
|---|
| 604 | #if MTK_MDIVRP_C0138 |
|---|
| 605 | Bool bResPredAvailable = false; |
|---|
| 606 | UInt uiResPrdId = 0; |
|---|
| 607 | #else |
|---|
| 608 | // check availability of residual prediction |
|---|
| 609 | Bool bResPredAvailable = false; |
|---|
| 610 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
|---|
| 611 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
|---|
| 612 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
|---|
| 613 | if( bResPredAllowed ) |
|---|
| 614 | { |
|---|
| 615 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, true , m_ppcResPredTmp[uiDepth] ); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
|---|
| 619 | #endif |
|---|
| 620 | { |
|---|
| 621 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
|---|
| 622 | #if LGE_ILLUCOMP_B0045 |
|---|
| 623 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
|---|
| 624 | { |
|---|
| 625 | Bool bICFlag = (uiICId ? true : false); |
|---|
| 626 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 627 | #endif |
|---|
| 628 | #endif |
|---|
| 629 | #if H3D_IVRP |
|---|
| 630 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 631 | #endif |
|---|
| 632 | // SKIP |
|---|
| 633 | #if HHI_INTERVIEW_SKIP |
|---|
| 634 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, bFullyRenderedSec ); |
|---|
| 635 | #else |
|---|
| 636 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU ); |
|---|
| 637 | #endif |
|---|
| 638 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 639 | |
|---|
| 640 | // fast encoder decision for early skip |
|---|
| 641 | if ( m_pcEncCfg->getUseFastEnc() ) |
|---|
| 642 | { |
|---|
| 643 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
|---|
| 644 | if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] ) |
|---|
| 645 | { |
|---|
| 646 | bEarlySkip = true; |
|---|
| 647 | bTrySplit = false; |
|---|
| 648 | } |
|---|
| 649 | } |
|---|
| 650 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
|---|
| 651 | if(bICFlag && rpcBestCU->getMergeFlag(0) && !rpcBestCU->getICFlag(0)) |
|---|
| 652 | { |
|---|
| 653 | bICEnabled = false; |
|---|
| 654 | break; |
|---|
| 655 | } |
|---|
| 656 | #endif |
|---|
| 657 | // 2Nx2N, NxN |
|---|
| 658 | if ( !bEarlySkip ) |
|---|
| 659 | { |
|---|
| 660 | #if H3D_IVRP |
|---|
| 661 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 662 | #endif |
|---|
| 663 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 664 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 665 | #endif |
|---|
| 666 | #if HHI_INTERVIEW_SKIP |
|---|
| 667 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFullyRenderedSec ); |
|---|
| 668 | |
|---|
| 669 | #else |
|---|
| 670 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
|---|
| 671 | #endif |
|---|
| 672 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 673 | if(m_pcEncCfg->getUseCbfFastMode()) |
|---|
| 674 | { |
|---|
| 675 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | #if LGE_ILLUCOMP_B0045 |
|---|
| 679 | } |
|---|
| 680 | #endif |
|---|
| 681 | #if H3D_IVRP |
|---|
| 682 | } // uiResPrdId |
|---|
| 683 | #endif |
|---|
| 684 | } // != I_SLICE |
|---|
| 685 | |
|---|
| 686 | #if LGE_ILLUCOMP_B0045_ENCSIMP |
|---|
| 687 | bICEnabled = rpcBestCU->getICFlag(0); |
|---|
| 688 | #endif |
|---|
| 689 | |
|---|
| 690 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 691 | |
|---|
| 692 | #if HHI_QTLPC_RAU_OFF_C0160 |
|---|
| 693 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC()) |
|---|
| 694 | #else |
|---|
| 695 | if(depthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC()) |
|---|
| 696 | #endif |
|---|
| 697 | { |
|---|
| 698 | bTrySplitDQP = bTrySplit; |
|---|
| 699 | } |
|---|
| 700 | else |
|---|
| 701 | { |
|---|
| 702 | #endif |
|---|
| 703 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 704 | { |
|---|
| 705 | if(iQP == iBaseQP) |
|---|
| 706 | { |
|---|
| 707 | bTrySplitDQP = bTrySplit; |
|---|
| 708 | } |
|---|
| 709 | } |
|---|
| 710 | else |
|---|
| 711 | { |
|---|
| 712 | bTrySplitDQP = bTrySplit; |
|---|
| 713 | } |
|---|
| 714 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 715 | } |
|---|
| 716 | #endif |
|---|
| 717 | |
|---|
| 718 | #if LOSSLESS_CODING |
|---|
| 719 | if (isAddLowestQP && (iQP == lowestQP)) |
|---|
| 720 | { |
|---|
| 721 | iQP = iMinQP; |
|---|
| 722 | } |
|---|
| 723 | #endif |
|---|
| 724 | } // end for iMinQP to iMaxQP |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
|---|
| 728 | { |
|---|
| 729 | #if LOSSLESS_CODING |
|---|
| 730 | if (isAddLowestQP && (iQP == iMinQP)) |
|---|
| 731 | { |
|---|
| 732 | iQP = lowestQP; |
|---|
| 733 | } |
|---|
| 734 | #endif |
|---|
| 735 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 736 | |
|---|
| 737 | // do inter modes, NxN, 2NxN, and Nx2N |
|---|
| 738 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
|---|
| 739 | { |
|---|
| 740 | #if H3D_IVRP |
|---|
| 741 | #if MTK_MDIVRP_C0138 |
|---|
| 742 | Bool bResPredAvailable = false; |
|---|
| 743 | UInt uiResPrdId = 0; |
|---|
| 744 | #else |
|---|
| 745 | // check availability of residual prediction |
|---|
| 746 | Bool bResPredAvailable = false; |
|---|
| 747 | Bool bResPredAllowed = (!rpcBestCU->getSlice()->getSPS()->isDepth () ); |
|---|
| 748 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getViewId () ); |
|---|
| 749 | bResPredAllowed = bResPredAllowed && ( rpcBestCU->getSlice()->getSPS()->getMultiviewResPredMode() ); |
|---|
| 750 | if( bResPredAllowed ) |
|---|
| 751 | { |
|---|
| 752 | bResPredAvailable = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] ); |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ ) |
|---|
| 756 | #endif |
|---|
| 757 | { |
|---|
| 758 | Bool bResPredFlag = ( uiResPrdId > 0 ); |
|---|
| 759 | #if LGE_ILLUCOMP_B0045 |
|---|
| 760 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
|---|
| 761 | { |
|---|
| 762 | Bool bICFlag = (uiICId ? true : false); |
|---|
| 763 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 764 | #endif |
|---|
| 765 | #endif |
|---|
| 766 | // 2Nx2N, NxN |
|---|
| 767 | if ( !bEarlySkip ) |
|---|
| 768 | { |
|---|
| 769 | |
|---|
| 770 | if(!( rpcBestCU->getSlice()->getSPS()->getDisInter4x4() && (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
|---|
| 771 | { |
|---|
| 772 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
|---|
| 773 | { |
|---|
| 774 | #if OL_QTLIMIT_PREDCODING_B0068 //try InterNxN |
|---|
| 775 | if(bTrySplit) |
|---|
| 776 | { |
|---|
| 777 | #endif |
|---|
| 778 | #if H3D_IVRP |
|---|
| 779 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 780 | #endif |
|---|
| 781 | #if HHI_INTERVIEW_SKIP |
|---|
| 782 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFullyRenderedSec ); |
|---|
| 783 | #else |
|---|
| 784 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
|---|
| 785 | #endif |
|---|
| 786 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 787 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 788 | } |
|---|
| 789 | #endif |
|---|
| 790 | } |
|---|
| 791 | } |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | { // 2NxN, Nx2N |
|---|
| 795 | #if OL_QTLIMIT_PREDCODING_B0068 //try Nx2N |
|---|
| 796 | if(bTryNx2N) |
|---|
| 797 | { |
|---|
| 798 | #endif |
|---|
| 799 | if(doNotBlockPu) |
|---|
| 800 | { |
|---|
| 801 | #if H3D_IVRP |
|---|
| 802 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 803 | #endif |
|---|
| 804 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 805 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 806 | #endif |
|---|
| 807 | #if HHI_INTERVIEW_SKIP |
|---|
| 808 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFullyRenderedSec ); |
|---|
| 809 | #else |
|---|
| 810 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
|---|
| 811 | #endif |
|---|
| 812 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 813 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
|---|
| 814 | { |
|---|
| 815 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 819 | } |
|---|
| 820 | #endif |
|---|
| 821 | |
|---|
| 822 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxN |
|---|
| 823 | if(bTry2NxN) |
|---|
| 824 | { |
|---|
| 825 | #endif |
|---|
| 826 | if(doNotBlockPu) |
|---|
| 827 | { |
|---|
| 828 | #if H3D_IVRP |
|---|
| 829 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 830 | #endif |
|---|
| 831 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 832 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 833 | #endif |
|---|
| 834 | #if HHI_INTERVIEW_SKIP |
|---|
| 835 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxN, bFullyRenderedSec ); |
|---|
| 836 | #else |
|---|
| 837 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
|---|
| 838 | #endif |
|---|
| 839 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 840 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
|---|
| 841 | { |
|---|
| 842 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 843 | } |
|---|
| 844 | } |
|---|
| 845 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 846 | } |
|---|
| 847 | #endif |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | #if 1 |
|---|
| 851 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
|---|
| 852 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
|---|
| 853 | { |
|---|
| 854 | #if AMP_ENC_SPEEDUP |
|---|
| 855 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
|---|
| 856 | |
|---|
| 857 | #if AMP_MRG |
|---|
| 858 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
|---|
| 859 | |
|---|
| 860 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
|---|
| 861 | #else |
|---|
| 862 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
|---|
| 863 | #endif |
|---|
| 864 | |
|---|
| 865 | //! Do horizontal AMP |
|---|
| 866 | if ( bTestAMP_Hor ) |
|---|
| 867 | { |
|---|
| 868 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxnU & 2NxnD |
|---|
| 869 | if(bTry2NxN) |
|---|
| 870 | { |
|---|
| 871 | #endif |
|---|
| 872 | if(doNotBlockPu) |
|---|
| 873 | { |
|---|
| 874 | #if H3D_IVRP |
|---|
| 875 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 876 | #endif |
|---|
| 877 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 878 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 879 | #endif |
|---|
| 880 | #if HHI_INTERVIEW_SKIP |
|---|
| 881 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
|---|
| 882 | #else |
|---|
| 883 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
|---|
| 884 | #endif |
|---|
| 885 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 886 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
|---|
| 887 | { |
|---|
| 888 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 889 | } |
|---|
| 890 | } |
|---|
| 891 | if(doNotBlockPu) |
|---|
| 892 | { |
|---|
| 893 | #if H3D_IVRP |
|---|
| 894 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 895 | #endif |
|---|
| 896 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 897 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 898 | #endif |
|---|
| 899 | #if HHI_INTERVIEW_SKIP |
|---|
| 900 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
|---|
| 901 | #else |
|---|
| 902 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
|---|
| 903 | #endif |
|---|
| 904 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 905 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
|---|
| 906 | { |
|---|
| 907 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 908 | } |
|---|
| 909 | } |
|---|
| 910 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 911 | } |
|---|
| 912 | #endif |
|---|
| 913 | } |
|---|
| 914 | #if AMP_MRG |
|---|
| 915 | else if ( bTestMergeAMP_Hor ) |
|---|
| 916 | { |
|---|
| 917 | #if OL_QTLIMIT_PREDCODING_B0068 //try 2NxnU & 2NxnD Merge |
|---|
| 918 | if(bTry2NxN) |
|---|
| 919 | { |
|---|
| 920 | #endif |
|---|
| 921 | if(doNotBlockPu) |
|---|
| 922 | { |
|---|
| 923 | #if H3D_IVRP |
|---|
| 924 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 925 | #endif |
|---|
| 926 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 927 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 928 | #endif |
|---|
| 929 | #if HHI_INTERVIEW_SKIP |
|---|
| 930 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec, true ); |
|---|
| 931 | #else |
|---|
| 932 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
|---|
| 933 | #endif |
|---|
| 934 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 935 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
|---|
| 936 | { |
|---|
| 937 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 938 | } |
|---|
| 939 | } |
|---|
| 940 | if(doNotBlockPu) |
|---|
| 941 | { |
|---|
| 942 | #if H3D_IVRP |
|---|
| 943 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 944 | #endif |
|---|
| 945 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 946 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 947 | #endif |
|---|
| 948 | #if HHI_INTERVIEW_SKIP |
|---|
| 949 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec, true ); |
|---|
| 950 | #else |
|---|
| 951 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
|---|
| 952 | #endif |
|---|
| 953 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 954 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
|---|
| 955 | { |
|---|
| 956 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 957 | } |
|---|
| 958 | } |
|---|
| 959 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 960 | } |
|---|
| 961 | #endif |
|---|
| 962 | } |
|---|
| 963 | #endif |
|---|
| 964 | |
|---|
| 965 | //! Do horizontal AMP |
|---|
| 966 | if ( bTestAMP_Ver ) |
|---|
| 967 | { |
|---|
| 968 | #if OL_QTLIMIT_PREDCODING_B0068 //try nLx2N & nRx2N |
|---|
| 969 | if(bTryNx2N) |
|---|
| 970 | { |
|---|
| 971 | #endif |
|---|
| 972 | if(doNotBlockPu) |
|---|
| 973 | { |
|---|
| 974 | #if H3D_IVRP |
|---|
| 975 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 976 | #endif |
|---|
| 977 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 978 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 979 | #endif |
|---|
| 980 | #if HHI_INTERVIEW_SKIP |
|---|
| 981 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
|---|
| 982 | #else |
|---|
| 983 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
|---|
| 984 | #endif |
|---|
| 985 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 986 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
|---|
| 987 | { |
|---|
| 988 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 989 | } |
|---|
| 990 | } |
|---|
| 991 | if(doNotBlockPu) |
|---|
| 992 | { |
|---|
| 993 | #if H3D_IVRP |
|---|
| 994 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 995 | #endif |
|---|
| 996 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 997 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 998 | #endif |
|---|
| 999 | #if HHI_INTERVIEW_SKIP |
|---|
| 1000 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
|---|
| 1001 | #else |
|---|
| 1002 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
|---|
| 1003 | #endif |
|---|
| 1004 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1005 | } |
|---|
| 1006 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 1007 | } |
|---|
| 1008 | #endif |
|---|
| 1009 | } |
|---|
| 1010 | #if AMP_MRG |
|---|
| 1011 | else if ( bTestMergeAMP_Ver ) |
|---|
| 1012 | { |
|---|
| 1013 | #if OL_QTLIMIT_PREDCODING_B0068 //try nLx2N & nRx2N (Merge) |
|---|
| 1014 | if(bTryNx2N) |
|---|
| 1015 | { |
|---|
| 1016 | #endif |
|---|
| 1017 | if(doNotBlockPu) |
|---|
| 1018 | { |
|---|
| 1019 | #if H3D_IVRP |
|---|
| 1020 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1021 | #endif |
|---|
| 1022 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 1023 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 1024 | #endif |
|---|
| 1025 | #if HHI_INTERVIEW_SKIP |
|---|
| 1026 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec, true ); |
|---|
| 1027 | #else |
|---|
| 1028 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
|---|
| 1029 | #endif |
|---|
| 1030 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1031 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
|---|
| 1032 | { |
|---|
| 1033 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
|---|
| 1034 | } |
|---|
| 1035 | } |
|---|
| 1036 | if(doNotBlockPu) |
|---|
| 1037 | { |
|---|
| 1038 | #if H3D_IVRP |
|---|
| 1039 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1040 | #endif |
|---|
| 1041 | #if FIX_LGE_ILLUCOMP_B0045 |
|---|
| 1042 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 1043 | #endif |
|---|
| 1044 | #if HHI_INTERVIEW_SKIP |
|---|
| 1045 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec, true ); |
|---|
| 1046 | #else |
|---|
| 1047 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
|---|
| 1048 | #endif |
|---|
| 1049 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1050 | } |
|---|
| 1051 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 1052 | } |
|---|
| 1053 | #endif |
|---|
| 1054 | } |
|---|
| 1055 | #endif |
|---|
| 1056 | |
|---|
| 1057 | #else |
|---|
| 1058 | #if H3D_IVRP |
|---|
| 1059 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1060 | #endif |
|---|
| 1061 | #if HHI_INTERVIEW_SKIP |
|---|
| 1062 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFullyRenderedSec ); |
|---|
| 1063 | #else |
|---|
| 1064 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
|---|
| 1065 | #endif |
|---|
| 1066 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1067 | #if H3D_IVRP |
|---|
| 1068 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1069 | #endif |
|---|
| 1070 | #if HHI_INTERVIEW_SKIP |
|---|
| 1071 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFullyRenderedSec ); |
|---|
| 1072 | #else |
|---|
| 1073 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
|---|
| 1074 | #endif |
|---|
| 1075 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1076 | #if H3D_IVRP |
|---|
| 1077 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1078 | #endif |
|---|
| 1079 | #if HHI_INTERVIEW_SKIP |
|---|
| 1080 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFullyRenderedSec ); |
|---|
| 1081 | #else |
|---|
| 1082 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
|---|
| 1083 | #endif |
|---|
| 1084 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1085 | #if H3D_IVRP |
|---|
| 1086 | rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag ); |
|---|
| 1087 | #endif |
|---|
| 1088 | #if HHI_INTERVIEW_SKIP |
|---|
| 1089 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFullyRenderedSec ); |
|---|
| 1090 | #else |
|---|
| 1091 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
|---|
| 1092 | #endif |
|---|
| 1093 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1094 | |
|---|
| 1095 | #endif |
|---|
| 1096 | } //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
|---|
| 1097 | #endif |
|---|
| 1098 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1099 | } |
|---|
| 1100 | #endif |
|---|
| 1101 | #if H3D_IVRP |
|---|
| 1102 | } // uiResPrdId |
|---|
| 1103 | #endif |
|---|
| 1104 | } // != I_SLICE |
|---|
| 1105 | |
|---|
| 1106 | // initialize PCM flag |
|---|
| 1107 | rpcTempCU->setIPCMFlag( 0, false); |
|---|
| 1108 | rpcTempCU->setIPCMFlagSubParts ( false, 0, uiDepth); //SUB_LCU_DQP |
|---|
| 1109 | |
|---|
| 1110 | // do normal intra modes |
|---|
| 1111 | if ( !bEarlySkip |
|---|
| 1112 | #if HHI_DEPTH_INTRA_SEARCH_RAU_C0160 |
|---|
| 1113 | || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
|---|
| 1114 | #endif |
|---|
| 1115 | ) |
|---|
| 1116 | { |
|---|
| 1117 | // speedup for inter frames |
|---|
| 1118 | #if HHI_INTERVIEW_SKIP |
|---|
| 1119 | if( ( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
|---|
| 1120 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
|---|
| 1121 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
|---|
| 1122 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 |
|---|
| 1123 | #if HHI_DEPTH_INTRA_SEARCH_RAU_C0160 |
|---|
| 1124 | || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
|---|
| 1125 | #endif |
|---|
| 1126 | ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely |
|---|
| 1127 | #else |
|---|
| 1128 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
|---|
| 1129 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
|---|
| 1130 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
|---|
| 1131 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 |
|---|
| 1132 | #if HHI_DEPTH_INTRA_SEARCH_RAU_C0160 |
|---|
| 1133 | || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
|---|
| 1134 | #endif |
|---|
| 1135 | ) // avoid very complex intra if it is unlikely |
|---|
| 1136 | #endif |
|---|
| 1137 | { |
|---|
| 1138 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1139 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
|---|
| 1140 | #endif |
|---|
| 1141 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
|---|
| 1142 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1143 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
|---|
| 1144 | { |
|---|
| 1145 | #if OL_QTLIMIT_PREDCODING_B0068 //Try IntraNxN |
|---|
| 1146 | if(bTrySplit) |
|---|
| 1147 | { |
|---|
| 1148 | #endif |
|---|
| 1149 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
|---|
| 1150 | { |
|---|
| 1151 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1152 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
|---|
| 1153 | #endif |
|---|
| 1154 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
|---|
| 1155 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1156 | } |
|---|
| 1157 | #if OL_QTLIMIT_PREDCODING_B0068 |
|---|
| 1158 | } |
|---|
| 1159 | #endif |
|---|
| 1160 | } |
|---|
| 1161 | } |
|---|
| 1162 | } |
|---|
| 1163 | |
|---|
| 1164 | // test PCM |
|---|
| 1165 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
|---|
| 1166 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
|---|
| 1167 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
|---|
| 1168 | { |
|---|
| 1169 | UInt uiRawBits = (g_uiBitDepth * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) * 3 / 2); |
|---|
| 1170 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
|---|
| 1171 | #if HHI_VSO |
|---|
| 1172 | Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
|---|
| 1173 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
|---|
| 1174 | #else |
|---|
| 1175 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
|---|
| 1176 | #endif |
|---|
| 1177 | { |
|---|
| 1178 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1179 | rpcTempCU->setICFlagSubParts(false, 0, 0, uiDepth); |
|---|
| 1180 | #endif |
|---|
| 1181 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
|---|
| 1182 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1183 | } |
|---|
| 1184 | } |
|---|
| 1185 | #if HHI_MPI |
|---|
| 1186 | if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
|---|
| 1187 | { |
|---|
| 1188 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1189 | for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++) |
|---|
| 1190 | { |
|---|
| 1191 | Bool bICFlag = (uiICId ? true : false); |
|---|
| 1192 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 1193 | #endif |
|---|
| 1194 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false ); |
|---|
| 1195 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1196 | #if FIX_ILLUCOMP_DEPTH |
|---|
| 1197 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
|---|
| 1198 | #endif |
|---|
| 1199 | xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false ); |
|---|
| 1200 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1201 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1202 | } |
|---|
| 1203 | #endif |
|---|
| 1204 | } |
|---|
| 1205 | #endif |
|---|
| 1206 | #if LOSSLESS_CODING |
|---|
| 1207 | if (isAddLowestQP && (iQP == lowestQP)) |
|---|
| 1208 | { |
|---|
| 1209 | iQP = iMinQP; |
|---|
| 1210 | } |
|---|
| 1211 | #endif |
|---|
| 1212 | } |
|---|
| 1213 | |
|---|
| 1214 | m_pcEntropyCoder->resetBits(); |
|---|
| 1215 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
|---|
| 1216 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
|---|
| 1217 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 1218 | { |
|---|
| 1219 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 1220 | } |
|---|
| 1221 | |
|---|
| 1222 | #if HHI_VSO |
|---|
| 1223 | if ( m_pcRdCost->getUseVSO() ) |
|---|
| 1224 | { |
|---|
| 1225 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
|---|
| 1226 | } |
|---|
| 1227 | else |
|---|
| 1228 | #endif |
|---|
| 1229 | { |
|---|
| 1230 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
|---|
| 1231 | } |
|---|
| 1232 | |
|---|
| 1233 | // accumulate statistics for early skip |
|---|
| 1234 | if ( m_pcEncCfg->getUseFastEnc() ) |
|---|
| 1235 | { |
|---|
| 1236 | if ( rpcBestCU->isSkipped(0) ) |
|---|
| 1237 | { |
|---|
| 1238 | Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ]; |
|---|
| 1239 | afCost[ iIdx ] += rpcBestCU->getTotalCost(); |
|---|
| 1240 | aiNum [ iIdx ] ++; |
|---|
| 1241 | } |
|---|
| 1242 | } |
|---|
| 1243 | |
|---|
| 1244 | // Early CU determination |
|---|
| 1245 | if( m_pcEncCfg->getUseEarlyCU() && ((*rpcBestCU->getPredictionMode()) == 0) ) |
|---|
| 1246 | { |
|---|
| 1247 | bSubBranch = false; |
|---|
| 1248 | } |
|---|
| 1249 | else |
|---|
| 1250 | { |
|---|
| 1251 | bSubBranch = true; |
|---|
| 1252 | } |
|---|
| 1253 | #if HHI_INTERVIEW_SKIP |
|---|
| 1254 | rpcBestCU->setRenderableSubParts(bFullyRenderedSec,0,rpcBestCU->getDepth( 0 )) ; |
|---|
| 1255 | #endif |
|---|
| 1256 | } |
|---|
| 1257 | else if(!(bSliceEnd && bInsidePicture)) |
|---|
| 1258 | { |
|---|
| 1259 | bBoundary = true; |
|---|
| 1260 | } |
|---|
| 1261 | |
|---|
| 1262 | #if LOSSLESS_CODING |
|---|
| 1263 | // copy orginal YUV samples to PCM buffer |
|---|
| 1264 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
|---|
| 1265 | { |
|---|
| 1266 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
|---|
| 1267 | } |
|---|
| 1268 | #endif |
|---|
| 1269 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 1270 | { |
|---|
| 1271 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
|---|
| 1272 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
|---|
| 1273 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
|---|
| 1274 | #if LOSSLESS_CODING |
|---|
| 1275 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
|---|
| 1276 | { |
|---|
| 1277 | isAddLowestQP = true; |
|---|
| 1278 | iMinQP = iMinQP - 1; |
|---|
| 1279 | } |
|---|
| 1280 | #endif |
|---|
| 1281 | } |
|---|
| 1282 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 1283 | { |
|---|
| 1284 | iMinQP = iBaseQP; |
|---|
| 1285 | iMaxQP = iBaseQP; |
|---|
| 1286 | } |
|---|
| 1287 | else |
|---|
| 1288 | { |
|---|
| 1289 | Int iStartQP; |
|---|
| 1290 | if( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getEntropySliceCurStartCUAddr()) |
|---|
| 1291 | { |
|---|
| 1292 | iStartQP = rpcTempCU->getQP(0); |
|---|
| 1293 | } |
|---|
| 1294 | else |
|---|
| 1295 | { |
|---|
| 1296 | UInt uiCurSliceStartPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
|---|
| 1297 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
|---|
| 1298 | } |
|---|
| 1299 | iMinQP = iStartQP; |
|---|
| 1300 | iMaxQP = iStartQP; |
|---|
| 1301 | } |
|---|
| 1302 | |
|---|
| 1303 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
|---|
| 1304 | { |
|---|
| 1305 | #if LOSSLESS_CODING |
|---|
| 1306 | if (isAddLowestQP && (iQP == iMinQP)) |
|---|
| 1307 | { |
|---|
| 1308 | iQP = lowestQP; |
|---|
| 1309 | } |
|---|
| 1310 | #endif |
|---|
| 1311 | rpcTempCU->initEstData( uiDepth, iQP ); |
|---|
| 1312 | |
|---|
| 1313 | // further split |
|---|
| 1314 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
|---|
| 1315 | { |
|---|
| 1316 | #if HHI_VSO |
|---|
| 1317 | // reset Model |
|---|
| 1318 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 1319 | { |
|---|
| 1320 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( ); |
|---|
| 1321 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( ); |
|---|
| 1322 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
|---|
| 1323 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
|---|
| 1324 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 1325 | } |
|---|
| 1326 | #endif |
|---|
| 1327 | UChar uhNextDepth = uiDepth+1; |
|---|
| 1328 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
|---|
| 1329 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
|---|
| 1330 | |
|---|
| 1331 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
|---|
| 1332 | { |
|---|
| 1333 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
|---|
| 1334 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
|---|
| 1335 | |
|---|
| 1336 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
|---|
| 1337 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 1338 | { |
|---|
| 1339 | if( m_bUseSBACRD ) |
|---|
| 1340 | { |
|---|
| 1341 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
|---|
| 1342 | { |
|---|
| 1343 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
|---|
| 1344 | } |
|---|
| 1345 | else |
|---|
| 1346 | { |
|---|
| 1347 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
|---|
| 1348 | } |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | #if AMP_ENC_SPEEDUP |
|---|
| 1352 | if ( rpcBestCU->isIntra(0) ) |
|---|
| 1353 | { |
|---|
| 1354 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
|---|
| 1355 | } |
|---|
| 1356 | else |
|---|
| 1357 | { |
|---|
| 1358 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
|---|
| 1359 | } |
|---|
| 1360 | #else |
|---|
| 1361 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
|---|
| 1362 | #endif |
|---|
| 1363 | |
|---|
| 1364 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
|---|
| 1365 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
|---|
| 1366 | |
|---|
| 1367 | #if HHI_VSO |
|---|
| 1368 | #endif |
|---|
| 1369 | } |
|---|
| 1370 | else if (bInSlice) |
|---|
| 1371 | { |
|---|
| 1372 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
|---|
| 1373 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
|---|
| 1374 | } |
|---|
| 1375 | } |
|---|
| 1376 | |
|---|
| 1377 | if( !bBoundary ) |
|---|
| 1378 | { |
|---|
| 1379 | m_pcEntropyCoder->resetBits(); |
|---|
| 1380 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
|---|
| 1381 | |
|---|
| 1382 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
|---|
| 1383 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 1384 | { |
|---|
| 1385 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 1386 | } |
|---|
| 1387 | } |
|---|
| 1388 | #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE |
|---|
| 1389 | if( bFullyRenderedSec ) |
|---|
| 1390 | { |
|---|
| 1391 | m_pcRdCost->setLambdaScale( m_pcEncCfg->getInterViewSkipLambdaScale() ); |
|---|
| 1392 | } |
|---|
| 1393 | else |
|---|
| 1394 | { |
|---|
| 1395 | m_pcRdCost->setLambdaScale( 1 ); |
|---|
| 1396 | } |
|---|
| 1397 | #endif |
|---|
| 1398 | |
|---|
| 1399 | #if HHI_VSO |
|---|
| 1400 | if ( m_pcRdCost->getUseVSO() ) |
|---|
| 1401 | { |
|---|
| 1402 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 1403 | } |
|---|
| 1404 | else |
|---|
| 1405 | #endif |
|---|
| 1406 | { |
|---|
| 1407 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 1408 | } |
|---|
| 1409 | |
|---|
| 1410 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
|---|
| 1411 | { |
|---|
| 1412 | Bool bHasRedisual = false; |
|---|
| 1413 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
|---|
| 1414 | { |
|---|
| 1415 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
|---|
| 1416 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
|---|
| 1417 | { |
|---|
| 1418 | bHasRedisual = true; |
|---|
| 1419 | break; |
|---|
| 1420 | } |
|---|
| 1421 | } |
|---|
| 1422 | |
|---|
| 1423 | UInt uiTargetPartIdx; |
|---|
| 1424 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
|---|
| 1425 | { |
|---|
| 1426 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
|---|
| 1427 | } |
|---|
| 1428 | else |
|---|
| 1429 | { |
|---|
| 1430 | uiTargetPartIdx = 0; |
|---|
| 1431 | } |
|---|
| 1432 | if ( bHasRedisual ) |
|---|
| 1433 | { |
|---|
| 1434 | #if !RDO_WITHOUT_DQP_BITS |
|---|
| 1435 | m_pcEntropyCoder->resetBits(); |
|---|
| 1436 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
|---|
| 1437 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
|---|
| 1438 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 1439 | { |
|---|
| 1440 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 1441 | } |
|---|
| 1442 | #if HHI_VSO |
|---|
| 1443 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
|---|
| 1444 | { |
|---|
| 1445 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 1446 | } |
|---|
| 1447 | else |
|---|
| 1448 | #endif |
|---|
| 1449 | { |
|---|
| 1450 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 1451 | } |
|---|
| 1452 | #endif |
|---|
| 1453 | } |
|---|
| 1454 | else |
|---|
| 1455 | { |
|---|
| 1456 | #if LOSSLESS_CODING |
|---|
| 1457 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
|---|
| 1458 | { |
|---|
| 1459 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
|---|
| 1460 | } |
|---|
| 1461 | #endif |
|---|
| 1462 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
|---|
| 1463 | } |
|---|
| 1464 | } |
|---|
| 1465 | |
|---|
| 1466 | if( m_bUseSBACRD ) |
|---|
| 1467 | { |
|---|
| 1468 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
|---|
| 1469 | } |
|---|
| 1470 | Bool bEntropyLimit=false; |
|---|
| 1471 | Bool bSliceLimit=false; |
|---|
| 1472 | bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
|---|
| 1473 | if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&m_pcEncCfg->getUseSBACRD()) |
|---|
| 1474 | { |
|---|
| 1475 | if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
|---|
| 1476 | { |
|---|
| 1477 | bEntropyLimit=true; |
|---|
| 1478 | } |
|---|
| 1479 | } |
|---|
| 1480 | else if(rpcBestCU->getSlice()->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE) |
|---|
| 1481 | { |
|---|
| 1482 | if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getEntropySliceArgument()) |
|---|
| 1483 | { |
|---|
| 1484 | bEntropyLimit=true; |
|---|
| 1485 | } |
|---|
| 1486 | } |
|---|
| 1487 | if(rpcBestCU->getDepth(0)>=rpcBestCU->getSlice()->getPPS()->getSliceGranularity()) |
|---|
| 1488 | { |
|---|
| 1489 | bSliceLimit=false; |
|---|
| 1490 | bEntropyLimit=false; |
|---|
| 1491 | } |
|---|
| 1492 | if(bSliceLimit||bEntropyLimit) |
|---|
| 1493 | { |
|---|
| 1494 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
|---|
| 1495 | } |
|---|
| 1496 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
|---|
| 1497 | } // with sub partitioned prediction. |
|---|
| 1498 | #if LOSSLESS_CODING |
|---|
| 1499 | if (isAddLowestQP && (iQP == lowestQP)) |
|---|
| 1500 | { |
|---|
| 1501 | iQP = iMinQP; |
|---|
| 1502 | } |
|---|
| 1503 | #endif |
|---|
| 1504 | } // SPLIT- QP Loop |
|---|
| 1505 | |
|---|
| 1506 | #if HHI_VSO |
|---|
| 1507 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 1508 | { |
|---|
| 1509 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
|---|
| 1510 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
|---|
| 1511 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
|---|
| 1512 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
|---|
| 1513 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 1514 | } |
|---|
| 1515 | #endif |
|---|
| 1516 | |
|---|
| 1517 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
|---|
| 1518 | |
|---|
| 1519 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
|---|
| 1520 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
|---|
| 1521 | { |
|---|
| 1522 | return; |
|---|
| 1523 | } |
|---|
| 1524 | |
|---|
| 1525 | // Assert if Best prediction mode is NONE |
|---|
| 1526 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
|---|
| 1527 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
|---|
| 1528 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
|---|
| 1529 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
|---|
| 1530 | } |
|---|
| 1531 | |
|---|
| 1532 | /** finish encoding a cu and handle end-of-slice conditions |
|---|
| 1533 | * \param pcCU |
|---|
| 1534 | * \param uiAbsPartIdx |
|---|
| 1535 | * \param uiDepth |
|---|
| 1536 | * \returns Void |
|---|
| 1537 | */ |
|---|
| 1538 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
|---|
| 1539 | { |
|---|
| 1540 | TComPic* pcPic = pcCU->getPic(); |
|---|
| 1541 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
|---|
| 1542 | |
|---|
| 1543 | //Calculate end address |
|---|
| 1544 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
|---|
| 1545 | |
|---|
| 1546 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
|---|
| 1547 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getEntropySliceCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
|---|
| 1548 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
|---|
| 1549 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
|---|
| 1550 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
|---|
| 1551 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
|---|
| 1552 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
|---|
| 1553 | { |
|---|
| 1554 | uiInternalAddress--; |
|---|
| 1555 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
|---|
| 1556 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
|---|
| 1557 | } |
|---|
| 1558 | uiInternalAddress++; |
|---|
| 1559 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
|---|
| 1560 | { |
|---|
| 1561 | uiInternalAddress = 0; |
|---|
| 1562 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
|---|
| 1563 | } |
|---|
| 1564 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
|---|
| 1565 | |
|---|
| 1566 | // Encode slice finish |
|---|
| 1567 | Bool bTerminateSlice = false; |
|---|
| 1568 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
|---|
| 1569 | { |
|---|
| 1570 | bTerminateSlice = true; |
|---|
| 1571 | } |
|---|
| 1572 | UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity()); |
|---|
| 1573 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1574 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1575 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
|---|
| 1576 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
|---|
| 1577 | |
|---|
| 1578 | if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 )))) |
|---|
| 1579 | { |
|---|
| 1580 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
|---|
| 1581 | if (!bTerminateSlice) |
|---|
| 1582 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| 1585 | Int numberOfWrittenBits = 0; |
|---|
| 1586 | if (m_pcBitCounter) |
|---|
| 1587 | { |
|---|
| 1588 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
|---|
| 1589 | } |
|---|
| 1590 | |
|---|
| 1591 | // Calculate slice end IF this CU puts us over slice bit size. |
|---|
| 1592 | unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU()>>(pcSlice->getPPS()->getSliceGranularity()<<1); |
|---|
| 1593 | int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
|---|
| 1594 | if(iGranularityEnd<=pcSlice->getEntropySliceCurStartCUAddr()) |
|---|
| 1595 | { |
|---|
| 1596 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
|---|
| 1597 | } |
|---|
| 1598 | // Set slice end parameter |
|---|
| 1599 | if(pcSlice->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
|---|
| 1600 | { |
|---|
| 1601 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
|---|
| 1602 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
|---|
| 1603 | return; |
|---|
| 1604 | } |
|---|
| 1605 | // Set entropy slice end parameter |
|---|
| 1606 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 1607 | { |
|---|
| 1608 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
|---|
| 1609 | UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded(); |
|---|
| 1610 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+uiBinsCoded>pcSlice->getEntropySliceArgument()) |
|---|
| 1611 | { |
|---|
| 1612 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
|---|
| 1613 | return; |
|---|
| 1614 | } |
|---|
| 1615 | } |
|---|
| 1616 | else |
|---|
| 1617 | { |
|---|
| 1618 | if(pcSlice->getEntropySliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_ENTROPY_SLICE&&!pcSlice->getFinalized()&&pcSlice->getEntropySliceCounter()+numberOfWrittenBits>pcSlice->getEntropySliceArgument()) |
|---|
| 1619 | { |
|---|
| 1620 | pcSlice->setEntropySliceCurEndCUAddr(iGranularityEnd); |
|---|
| 1621 | return; |
|---|
| 1622 | } |
|---|
| 1623 | } |
|---|
| 1624 | if(granularityBoundary) |
|---|
| 1625 | { |
|---|
| 1626 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
|---|
| 1627 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 1628 | { |
|---|
| 1629 | TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); |
|---|
| 1630 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+pppcRDSbacCoder->getBinsCoded()); |
|---|
| 1631 | pppcRDSbacCoder->setBinsCoded( 0 ); |
|---|
| 1632 | } |
|---|
| 1633 | else |
|---|
| 1634 | { |
|---|
| 1635 | pcSlice->setEntropySliceCounter(pcSlice->getEntropySliceCounter()+numberOfWrittenBits); |
|---|
| 1636 | } |
|---|
| 1637 | if (m_pcBitCounter) |
|---|
| 1638 | { |
|---|
| 1639 | m_pcEntropyCoder->resetBits(); |
|---|
| 1640 | } |
|---|
| 1641 | } |
|---|
| 1642 | } |
|---|
| 1643 | |
|---|
| 1644 | /** Compute QP for each CU |
|---|
| 1645 | * \param pcCU Target CU |
|---|
| 1646 | * \param uiDepth CU depth |
|---|
| 1647 | * \returns quantization parameter |
|---|
| 1648 | */ |
|---|
| 1649 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
|---|
| 1650 | { |
|---|
| 1651 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
|---|
| 1652 | Int iQpOffset = 0; |
|---|
| 1653 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
|---|
| 1654 | { |
|---|
| 1655 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
|---|
| 1656 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
|---|
| 1657 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
|---|
| 1658 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
|---|
| 1659 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
|---|
| 1660 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
|---|
| 1661 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
|---|
| 1662 | |
|---|
| 1663 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
|---|
| 1664 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
|---|
| 1665 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
|---|
| 1666 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
|---|
| 1667 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
|---|
| 1668 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
|---|
| 1669 | } |
|---|
| 1670 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
|---|
| 1671 | } |
|---|
| 1672 | |
|---|
| 1673 | /** encode a CU block recursively |
|---|
| 1674 | * \param pcCU |
|---|
| 1675 | * \param uiAbsPartIdx |
|---|
| 1676 | * \param uiDepth |
|---|
| 1677 | * \returns Void |
|---|
| 1678 | */ |
|---|
| 1679 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
|---|
| 1680 | { |
|---|
| 1681 | TComPic* pcPic = pcCU->getPic(); |
|---|
| 1682 | |
|---|
| 1683 | Bool bBoundary = false; |
|---|
| 1684 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1685 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
|---|
| 1686 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1687 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
|---|
| 1688 | |
|---|
| 1689 | if( getCheckBurstIPCMFlag() ) |
|---|
| 1690 | { |
|---|
| 1691 | pcCU->setLastCUSucIPCMFlag( checkLastCUSucIPCM( pcCU, uiAbsPartIdx )); |
|---|
| 1692 | pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) ); |
|---|
| 1693 | } |
|---|
| 1694 | |
|---|
| 1695 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
|---|
| 1696 | // If slice start is within this cu... |
|---|
| 1697 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
|---|
| 1698 | pcSlice->getEntropySliceCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
|---|
| 1699 | // We need to split, so don't try these modes. |
|---|
| 1700 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 1701 | { |
|---|
| 1702 | #if HHI_MPI |
|---|
| 1703 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 || uiDepth < pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
|---|
| 1704 | { |
|---|
| 1705 | #endif |
|---|
| 1706 | |
|---|
| 1707 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 1708 | |
|---|
| 1709 | #if HHI_MPI |
|---|
| 1710 | } |
|---|
| 1711 | #endif |
|---|
| 1712 | } |
|---|
| 1713 | else |
|---|
| 1714 | { |
|---|
| 1715 | bBoundary = true; |
|---|
| 1716 | } |
|---|
| 1717 | |
|---|
| 1718 | #if HHI_MPI |
|---|
| 1719 | if( uiDepth == pcCU->getTextureModeDepth( uiAbsPartIdx ) ) |
|---|
| 1720 | { |
|---|
| 1721 | xSaveDepthWidthHeight( pcCU ); |
|---|
| 1722 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uiDepth, g_uiMaxCUHeight>>uiDepth, uiAbsPartIdx, uiDepth ); |
|---|
| 1723 | pcCU->setDepthSubParts( uiDepth, uiAbsPartIdx ); |
|---|
| 1724 | |
|---|
| 1725 | if( ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 1726 | { |
|---|
| 1727 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 1728 | } |
|---|
| 1729 | |
|---|
| 1730 | if( !pcCU->getSlice()->isIntra() ) |
|---|
| 1731 | { |
|---|
| 1732 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
|---|
| 1733 | } |
|---|
| 1734 | |
|---|
| 1735 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
|---|
| 1736 | { |
|---|
| 1737 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
|---|
| 1738 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1739 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx, false, uiDepth ); |
|---|
| 1740 | #endif |
|---|
| 1741 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
|---|
| 1742 | xRestoreDepthWidthHeight( pcCU ); |
|---|
| 1743 | return; |
|---|
| 1744 | } |
|---|
| 1745 | |
|---|
| 1746 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
|---|
| 1747 | |
|---|
| 1748 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 1749 | |
|---|
| 1750 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
|---|
| 1751 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
|---|
| 1752 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1753 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx, false, uiDepth ); |
|---|
| 1754 | #endif |
|---|
| 1755 | xRestoreDepthWidthHeight( pcCU ); |
|---|
| 1756 | } |
|---|
| 1757 | #endif |
|---|
| 1758 | |
|---|
| 1759 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
|---|
| 1760 | { |
|---|
| 1761 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
|---|
| 1762 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
|---|
| 1763 | { |
|---|
| 1764 | setdQPFlag(true); |
|---|
| 1765 | } |
|---|
| 1766 | pcCU->setNumSucIPCM(0); |
|---|
| 1767 | pcCU->setLastCUSucIPCMFlag(false); |
|---|
| 1768 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
|---|
| 1769 | { |
|---|
| 1770 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1771 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
|---|
| 1772 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getEntropySliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getEntropySliceCurEndCUAddr(); |
|---|
| 1773 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 1774 | { |
|---|
| 1775 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
|---|
| 1776 | } |
|---|
| 1777 | } |
|---|
| 1778 | return; |
|---|
| 1779 | } |
|---|
| 1780 | |
|---|
| 1781 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
|---|
| 1782 | { |
|---|
| 1783 | setdQPFlag(true); |
|---|
| 1784 | } |
|---|
| 1785 | #if HHI_MPI |
|---|
| 1786 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
|---|
| 1787 | { |
|---|
| 1788 | #endif |
|---|
| 1789 | if( !pcCU->getSlice()->isIntra() ) |
|---|
| 1790 | { |
|---|
| 1791 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
|---|
| 1792 | } |
|---|
| 1793 | #if HHI_MPI |
|---|
| 1794 | } |
|---|
| 1795 | #endif |
|---|
| 1796 | |
|---|
| 1797 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
|---|
| 1798 | { |
|---|
| 1799 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 ); |
|---|
| 1800 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1801 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx |
|---|
| 1802 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1803 | , false, uiDepth |
|---|
| 1804 | #endif |
|---|
| 1805 | ); |
|---|
| 1806 | #endif |
|---|
| 1807 | #if H3D_IVRP && !MTK_MDIVRP_C0138 |
|---|
| 1808 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
|---|
| 1809 | #endif |
|---|
| 1810 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
|---|
| 1811 | return; |
|---|
| 1812 | } |
|---|
| 1813 | #if HHI_MPI |
|---|
| 1814 | if( pcCU->getTextureModeDepth( uiAbsPartIdx ) == -1 ) |
|---|
| 1815 | { |
|---|
| 1816 | #endif |
|---|
| 1817 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
|---|
| 1818 | |
|---|
| 1819 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
|---|
| 1820 | |
|---|
| 1821 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
|---|
| 1822 | { |
|---|
| 1823 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
|---|
| 1824 | |
|---|
| 1825 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
|---|
| 1826 | { |
|---|
| 1827 | // Encode slice finish |
|---|
| 1828 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
|---|
| 1829 | return; |
|---|
| 1830 | } |
|---|
| 1831 | } |
|---|
| 1832 | |
|---|
| 1833 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
|---|
| 1834 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
|---|
| 1835 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1836 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx |
|---|
| 1837 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 1838 | ,false, uiDepth |
|---|
| 1839 | #endif |
|---|
| 1840 | ); |
|---|
| 1841 | #endif |
|---|
| 1842 | #if H3D_IVRP && !MTK_MDIVRP_C0138 |
|---|
| 1843 | if( !pcCU->isIntra( uiAbsPartIdx ) ) |
|---|
| 1844 | { |
|---|
| 1845 | m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 ); |
|---|
| 1846 | } |
|---|
| 1847 | #endif |
|---|
| 1848 | #if HHI_MPI |
|---|
| 1849 | } |
|---|
| 1850 | #endif |
|---|
| 1851 | |
|---|
| 1852 | // Encode Coefficients |
|---|
| 1853 | Bool bCodeDQP = getdQPFlag(); |
|---|
| 1854 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
|---|
| 1855 | setdQPFlag( bCodeDQP ); |
|---|
| 1856 | |
|---|
| 1857 | // --- write terminating bit --- |
|---|
| 1858 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
|---|
| 1859 | } |
|---|
| 1860 | |
|---|
| 1861 | /** check RD costs for a CU block encoded with merge |
|---|
| 1862 | * \param rpcBestCU |
|---|
| 1863 | * \param rpcTempCU |
|---|
| 1864 | * \returns Void |
|---|
| 1865 | */ |
|---|
| 1866 | #if HHI_INTERVIEW_SKIP |
|---|
| 1867 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool bSkipRes ) |
|---|
| 1868 | #else |
|---|
| 1869 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
|---|
| 1870 | #endif |
|---|
| 1871 | { |
|---|
| 1872 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
|---|
| 1873 | #if H3D_IVMP |
|---|
| 1874 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
|---|
| 1875 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
|---|
| 1876 | #else |
|---|
| 1877 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists |
|---|
| 1878 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
|---|
| 1879 | #endif |
|---|
| 1880 | Int numValidMergeCand = 0; |
|---|
| 1881 | |
|---|
| 1882 | #if H3D_IVRP && !MTK_MDIVRP_C0138 |
|---|
| 1883 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
|---|
| 1884 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
|---|
| 1885 | #endif |
|---|
| 1886 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1887 | Bool bICFlag = rpcTempCU->getICFlag(0); |
|---|
| 1888 | #endif |
|---|
| 1889 | |
|---|
| 1890 | #if H3D_IVMP |
|---|
| 1891 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui ) |
|---|
| 1892 | #else |
|---|
| 1893 | for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS; ++ui ) |
|---|
| 1894 | #endif |
|---|
| 1895 | { |
|---|
| 1896 | uhInterDirNeighbours[ui] = 0; |
|---|
| 1897 | } |
|---|
| 1898 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
|---|
| 1899 | |
|---|
| 1900 | #if HHI_VSO |
|---|
| 1901 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 1902 | { |
|---|
| 1903 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
|---|
| 1904 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
|---|
| 1905 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
|---|
| 1906 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
|---|
| 1907 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 1908 | } |
|---|
| 1909 | #endif |
|---|
| 1910 | |
|---|
| 1911 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1912 | #if MERL_VSP_C0152 |
|---|
| 1913 | Int iVSPIndexTrue[3] = {-1, -1, -1}; |
|---|
| 1914 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue ); |
|---|
| 1915 | #else |
|---|
| 1916 | rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand ); |
|---|
| 1917 | #endif |
|---|
| 1918 | #if MTK_MDIVRP_C0138 |
|---|
| 1919 | Bool bResPredAvail = rpcTempCU->getResPredAvail(0); |
|---|
| 1920 | #endif |
|---|
| 1921 | |
|---|
| 1922 | Bool bestIsSkip = false; |
|---|
| 1923 | |
|---|
| 1924 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
|---|
| 1925 | { |
|---|
| 1926 | { |
|---|
| 1927 | TComYuv* pcPredYuvTemp = NULL; |
|---|
| 1928 | #if LOSSLESS_CODING |
|---|
| 1929 | UInt iteration; |
|---|
| 1930 | if ( rpcTempCU->isLosslessCoded(0)) |
|---|
| 1931 | { |
|---|
| 1932 | iteration = 1; |
|---|
| 1933 | } |
|---|
| 1934 | else |
|---|
| 1935 | { |
|---|
| 1936 | iteration = 2; |
|---|
| 1937 | } |
|---|
| 1938 | |
|---|
| 1939 | #if HHI_INTERVIEW_SKIP |
|---|
| 1940 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < iteration; ++uiNoResidual ) |
|---|
| 1941 | #else |
|---|
| 1942 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
|---|
| 1943 | #endif |
|---|
| 1944 | #else |
|---|
| 1945 | #if HHI_INTERVIEW_SKIP |
|---|
| 1946 | for( UInt uiNoResidual = (bSkipRes ? 1:0); uiNoResidual < 2; ++uiNoResidual ) |
|---|
| 1947 | #else |
|---|
| 1948 | for( UInt uiNoResidual = 0; uiNoResidual < 2; ++uiNoResidual ) |
|---|
| 1949 | #endif |
|---|
| 1950 | #endif |
|---|
| 1951 | { |
|---|
| 1952 | if( !(bestIsSkip && uiNoResidual == 0) ) |
|---|
| 1953 | { |
|---|
| 1954 | // set MC parameters |
|---|
| 1955 | rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1956 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1957 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1958 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1959 | #if MERL_VSP_C0152 |
|---|
| 1960 | { |
|---|
| 1961 | Int iVSPIdx = 0; |
|---|
| 1962 | Int numVSPIdx; |
|---|
| 1963 | numVSPIdx = 3; |
|---|
| 1964 | for (Int i = 0; i < numVSPIdx; i++) |
|---|
| 1965 | { |
|---|
| 1966 | if (iVSPIndexTrue[i] == uiMergeCand) |
|---|
| 1967 | { |
|---|
| 1968 | iVSPIdx = i+1; |
|---|
| 1969 | break; |
|---|
| 1970 | } |
|---|
| 1971 | } |
|---|
| 1972 | rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth ); |
|---|
| 1973 | } |
|---|
| 1974 | #endif |
|---|
| 1975 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
|---|
| 1976 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
|---|
| 1977 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
|---|
| 1978 | |
|---|
| 1979 | #if H3D_IVRP |
|---|
| 1980 | #if MTK_MDIVRP_C0138 |
|---|
| 1981 | rpcTempCU->setResPredAvailSubParts(bResPredAvail, 0, 0, uhDepth); |
|---|
| 1982 | #else |
|---|
| 1983 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
|---|
| 1984 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
|---|
| 1985 | #endif |
|---|
| 1986 | #endif |
|---|
| 1987 | #if LGE_ILLUCOMP_B0045 |
|---|
| 1988 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uhDepth); |
|---|
| 1989 | #endif |
|---|
| 1990 | |
|---|
| 1991 | // do MC |
|---|
| 1992 | #if HHI_INTERVIEW_SKIP |
|---|
| 1993 | if ( (uiNoResidual == 0) || bSkipRes ) |
|---|
| 1994 | #else |
|---|
| 1995 | if ( uiNoResidual == 0 ) |
|---|
| 1996 | #endif |
|---|
| 1997 | { |
|---|
| 1998 | #if MERL_VSP_C0152 |
|---|
| 1999 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2000 | #else |
|---|
| 2001 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
|---|
| 2002 | #endif |
|---|
| 2003 | #if MTK_MDIVRP_C0138 |
|---|
| 2004 | if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0)) |
|---|
| 2005 | { |
|---|
| 2006 | m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]); |
|---|
| 2007 | } |
|---|
| 2008 | #endif |
|---|
| 2009 | // save pred adress |
|---|
| 2010 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
|---|
| 2011 | |
|---|
| 2012 | } |
|---|
| 2013 | else |
|---|
| 2014 | { |
|---|
| 2015 | if( bestIsSkip) |
|---|
| 2016 | { |
|---|
| 2017 | #if MERL_VSP_C0152 |
|---|
| 2018 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2019 | #else |
|---|
| 2020 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
|---|
| 2021 | #endif |
|---|
| 2022 | #if MTK_MDIVRP_C0138 |
|---|
| 2023 | if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0)) |
|---|
| 2024 | { |
|---|
| 2025 | m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]); |
|---|
| 2026 | } |
|---|
| 2027 | #endif |
|---|
| 2028 | // save pred adress |
|---|
| 2029 | pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth]; |
|---|
| 2030 | } |
|---|
| 2031 | else |
|---|
| 2032 | { |
|---|
| 2033 | if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth]) |
|---|
| 2034 | { |
|---|
| 2035 | //adress changes take best (old temp) |
|---|
| 2036 | pcPredYuvTemp = m_ppcPredYuvBest[uhDepth]; |
|---|
| 2037 | } |
|---|
| 2038 | } |
|---|
| 2039 | } |
|---|
| 2040 | #if HHI_VSO |
|---|
| 2041 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 2042 | { //Reset |
|---|
| 2043 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
|---|
| 2044 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
|---|
| 2045 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
|---|
| 2046 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
|---|
| 2047 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 2048 | } |
|---|
| 2049 | #endif |
|---|
| 2050 | // estimate residual and encode everything |
|---|
| 2051 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
|---|
| 2052 | m_ppcOrigYuv [uhDepth], |
|---|
| 2053 | pcPredYuvTemp, |
|---|
| 2054 | m_ppcResiYuvTemp[uhDepth], |
|---|
| 2055 | m_ppcResiYuvBest[uhDepth], |
|---|
| 2056 | m_ppcRecoYuvTemp[uhDepth], |
|---|
| 2057 | #if H3D_IVRP |
|---|
| 2058 | m_ppcResPredTmp [uhDepth], |
|---|
| 2059 | #endif |
|---|
| 2060 | (uiNoResidual? true:false) ); |
|---|
| 2061 | Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1; |
|---|
| 2062 | |
|---|
| 2063 | Int orgQP = rpcTempCU->getQP( 0 ); |
|---|
| 2064 | xCheckDQP( rpcTempCU ); |
|---|
| 2065 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
|---|
| 2066 | rpcTempCU->initEstData( uhDepth, orgQP ); |
|---|
| 2067 | |
|---|
| 2068 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
|---|
| 2069 | { |
|---|
| 2070 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
|---|
| 2071 | } |
|---|
| 2072 | |
|---|
| 2073 | if (!bQtRootCbf) |
|---|
| 2074 | break; |
|---|
| 2075 | } |
|---|
| 2076 | } |
|---|
| 2077 | } |
|---|
| 2078 | } |
|---|
| 2079 | } |
|---|
| 2080 | |
|---|
| 2081 | #if AMP_MRG |
|---|
| 2082 | #if HHI_INTERVIEW_SKIP |
|---|
| 2083 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes, Bool bUseMRG) |
|---|
| 2084 | #else |
|---|
| 2085 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
|---|
| 2086 | #endif |
|---|
| 2087 | #else |
|---|
| 2088 | #if HHI_INTERVIEW_SKIP |
|---|
| 2089 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bSkipRes) |
|---|
| 2090 | #else |
|---|
| 2091 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
|---|
| 2092 | #endif |
|---|
| 2093 | #endif |
|---|
| 2094 | { |
|---|
| 2095 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
|---|
| 2096 | |
|---|
| 2097 | #if HHI_VSO |
|---|
| 2098 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 2099 | { |
|---|
| 2100 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
|---|
| 2101 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
|---|
| 2102 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
|---|
| 2103 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
|---|
| 2104 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 2105 | } |
|---|
| 2106 | #endif |
|---|
| 2107 | |
|---|
| 2108 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
|---|
| 2109 | |
|---|
| 2110 | #if H3D_IVRP |
|---|
| 2111 | Bool bResPrdAvail = rpcTempCU->getResPredAvail( 0 ); |
|---|
| 2112 | Bool bResPrdFlag = rpcTempCU->getResPredFlag ( 0 ); |
|---|
| 2113 | #endif |
|---|
| 2114 | |
|---|
| 2115 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
|---|
| 2116 | |
|---|
| 2117 | #if H3D_IVRP |
|---|
| 2118 | rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth ); |
|---|
| 2119 | rpcTempCU->setResPredFlagSubParts ( bResPrdFlag, 0, 0, uhDepth ); |
|---|
| 2120 | #endif |
|---|
| 2121 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
|---|
| 2122 | |
|---|
| 2123 | #if H3D_IVRP |
|---|
| 2124 | #if !LG_RESTRICTEDRESPRED_M24766 |
|---|
| 2125 | if( rpcTempCU->getResPredFlag( 0 ) ) |
|---|
| 2126 | { // subtract residual prediction from original in motion search |
|---|
| 2127 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ), true ); |
|---|
| 2128 | } |
|---|
| 2129 | #endif |
|---|
| 2130 | #endif |
|---|
| 2131 | |
|---|
| 2132 | #if AMP_MRG |
|---|
| 2133 | rpcTempCU->setMergeAMP (true); |
|---|
| 2134 | #if HHI_INTERVIEW_SKIP |
|---|
| 2135 | #if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138 |
|---|
| 2136 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG); |
|---|
| 2137 | #else |
|---|
| 2138 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG ); |
|---|
| 2139 | #endif |
|---|
| 2140 | #else |
|---|
| 2141 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
|---|
| 2142 | #endif |
|---|
| 2143 | #else |
|---|
| 2144 | #if HHI_INTERVIEW_SKIP |
|---|
| 2145 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes ); |
|---|
| 2146 | #else |
|---|
| 2147 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
|---|
| 2148 | #endif |
|---|
| 2149 | #endif |
|---|
| 2150 | |
|---|
| 2151 | #if H3D_IVRP |
|---|
| 2152 | #if !LG_RESTRICTEDRESPRED_M24766 |
|---|
| 2153 | if( rpcTempCU->getResPredFlag( 0 ) ) |
|---|
| 2154 | { // add residual prediction to original again |
|---|
| 2155 | m_ppcOrigYuv[uhDepth]->add( m_ppcResPredTmp [uhDepth], rpcTempCU->getWidth( 0 ), rpcTempCU->getHeight( 0 ) ); |
|---|
| 2156 | } |
|---|
| 2157 | #endif |
|---|
| 2158 | #endif |
|---|
| 2159 | |
|---|
| 2160 | #if AMP_MRG |
|---|
| 2161 | if ( !rpcTempCU->getMergeAMP() ) |
|---|
| 2162 | { |
|---|
| 2163 | return; |
|---|
| 2164 | } |
|---|
| 2165 | #endif |
|---|
| 2166 | |
|---|
| 2167 | #if HHI_INTERVIEW_SKIP |
|---|
| 2168 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
|---|
| 2169 | m_ppcOrigYuv[uhDepth], |
|---|
| 2170 | m_ppcPredYuvTemp[uhDepth], |
|---|
| 2171 | m_ppcResiYuvTemp[uhDepth], |
|---|
| 2172 | m_ppcResiYuvBest[uhDepth], |
|---|
| 2173 | m_ppcRecoYuvTemp[uhDepth], |
|---|
| 2174 | #if H3D_IVRP |
|---|
| 2175 | m_ppcResPredTmp [uhDepth], |
|---|
| 2176 | #endif |
|---|
| 2177 | bSkipRes ); |
|---|
| 2178 | #else |
|---|
| 2179 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
|---|
| 2180 | m_ppcOrigYuv[uhDepth], |
|---|
| 2181 | m_ppcPredYuvTemp[uhDepth], |
|---|
| 2182 | m_ppcResiYuvTemp[uhDepth], |
|---|
| 2183 | m_ppcResiYuvBest[uhDepth], |
|---|
| 2184 | m_ppcRecoYuvTemp[uhDepth], |
|---|
| 2185 | #if H3D_IVRP |
|---|
| 2186 | m_ppcResPredTmp [uhDepth], |
|---|
| 2187 | #endif |
|---|
| 2188 | false ); |
|---|
| 2189 | #endif |
|---|
| 2190 | #if HHI_VSO |
|---|
| 2191 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
|---|
| 2192 | { |
|---|
| 2193 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2194 | } |
|---|
| 2195 | else |
|---|
| 2196 | #endif |
|---|
| 2197 | { |
|---|
| 2198 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2199 | } |
|---|
| 2200 | |
|---|
| 2201 | xCheckDQP( rpcTempCU ); |
|---|
| 2202 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
|---|
| 2203 | } |
|---|
| 2204 | |
|---|
| 2205 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
|---|
| 2206 | { |
|---|
| 2207 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
|---|
| 2208 | |
|---|
| 2209 | #if HHI_VSO |
|---|
| 2210 | if( m_pcRdCost->getUseRenModel() ) |
|---|
| 2211 | { |
|---|
| 2212 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
|---|
| 2213 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
|---|
| 2214 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
|---|
| 2215 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
|---|
| 2216 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 2217 | } |
|---|
| 2218 | #endif |
|---|
| 2219 | |
|---|
| 2220 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
|---|
| 2221 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
|---|
| 2222 | |
|---|
| 2223 | Bool bSeparateLumaChroma = true; // choose estimation mode |
|---|
| 2224 | Dist uiPreCalcDistC = 0; |
|---|
| 2225 | if( !bSeparateLumaChroma ) |
|---|
| 2226 | { |
|---|
| 2227 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
|---|
| 2228 | } |
|---|
| 2229 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
|---|
| 2230 | |
|---|
| 2231 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2232 | |
|---|
| 2233 | #if RWTH_SDC_DLT_B0036 |
|---|
| 2234 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
|---|
| 2235 | #endif |
|---|
| 2236 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
|---|
| 2237 | |
|---|
| 2238 | m_pcEntropyCoder->resetBits(); |
|---|
| 2239 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
|---|
| 2240 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
|---|
| 2241 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
|---|
| 2242 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
|---|
| 2243 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
|---|
| 2244 | |
|---|
| 2245 | // Encode Coefficients |
|---|
| 2246 | Bool bCodeDQP = getdQPFlag(); |
|---|
| 2247 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
|---|
| 2248 | setdQPFlag( bCodeDQP ); |
|---|
| 2249 | |
|---|
| 2250 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
|---|
| 2251 | |
|---|
| 2252 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
|---|
| 2253 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 2254 | { |
|---|
| 2255 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 2256 | } |
|---|
| 2257 | #if HHI_VSO |
|---|
| 2258 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
|---|
| 2259 | { |
|---|
| 2260 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2261 | } |
|---|
| 2262 | else |
|---|
| 2263 | #endif |
|---|
| 2264 | { |
|---|
| 2265 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2266 | } |
|---|
| 2267 | |
|---|
| 2268 | xCheckDQP( rpcTempCU ); |
|---|
| 2269 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
|---|
| 2270 | } |
|---|
| 2271 | |
|---|
| 2272 | /** Check R-D costs for a CU with PCM mode. |
|---|
| 2273 | * \param rpcBestCU pointer to best mode CU data structure |
|---|
| 2274 | * \param rpcTempCU pointer to testing mode CU data structure |
|---|
| 2275 | * \returns Void |
|---|
| 2276 | * |
|---|
| 2277 | * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode. |
|---|
| 2278 | */ |
|---|
| 2279 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
|---|
| 2280 | { |
|---|
| 2281 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
|---|
| 2282 | |
|---|
| 2283 | rpcTempCU->setIPCMFlag(0, true); |
|---|
| 2284 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
|---|
| 2285 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
|---|
| 2286 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
|---|
| 2287 | |
|---|
| 2288 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
|---|
| 2289 | |
|---|
| 2290 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
|---|
| 2291 | |
|---|
| 2292 | m_pcEntropyCoder->resetBits(); |
|---|
| 2293 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
|---|
| 2294 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
|---|
| 2295 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
|---|
| 2296 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
|---|
| 2297 | |
|---|
| 2298 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
|---|
| 2299 | |
|---|
| 2300 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
|---|
| 2301 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 2302 | { |
|---|
| 2303 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 2304 | } |
|---|
| 2305 | #if HHI_VSO |
|---|
| 2306 | if ( m_pcRdCost->getUseVSO() ) |
|---|
| 2307 | { |
|---|
| 2308 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2309 | } |
|---|
| 2310 | else |
|---|
| 2311 | #endif |
|---|
| 2312 | { |
|---|
| 2313 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2314 | } |
|---|
| 2315 | |
|---|
| 2316 | xCheckDQP( rpcTempCU ); |
|---|
| 2317 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
|---|
| 2318 | } |
|---|
| 2319 | |
|---|
| 2320 | // check whether current try is the best |
|---|
| 2321 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
|---|
| 2322 | { |
|---|
| 2323 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
|---|
| 2324 | { |
|---|
| 2325 | TComYuv* pcYuv; |
|---|
| 2326 | UChar uhDepth = rpcBestCU->getDepth(0); |
|---|
| 2327 | |
|---|
| 2328 | // Change Information data |
|---|
| 2329 | TComDataCU* pcCU = rpcBestCU; |
|---|
| 2330 | rpcBestCU = rpcTempCU; |
|---|
| 2331 | rpcTempCU = pcCU; |
|---|
| 2332 | |
|---|
| 2333 | // Change Prediction data |
|---|
| 2334 | pcYuv = m_ppcPredYuvBest[uhDepth]; |
|---|
| 2335 | m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; |
|---|
| 2336 | m_ppcPredYuvTemp[uhDepth] = pcYuv; |
|---|
| 2337 | |
|---|
| 2338 | // Change Reconstruction data |
|---|
| 2339 | pcYuv = m_ppcRecoYuvBest[uhDepth]; |
|---|
| 2340 | m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; |
|---|
| 2341 | m_ppcRecoYuvTemp[uhDepth] = pcYuv; |
|---|
| 2342 | |
|---|
| 2343 | pcYuv = NULL; |
|---|
| 2344 | pcCU = NULL; |
|---|
| 2345 | |
|---|
| 2346 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
|---|
| 2347 | m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); |
|---|
| 2348 | } |
|---|
| 2349 | } |
|---|
| 2350 | |
|---|
| 2351 | /** check whether current try is the best with identifying the depth of current try |
|---|
| 2352 | * \param rpcBestCU |
|---|
| 2353 | * \param rpcTempCU |
|---|
| 2354 | * \returns Void |
|---|
| 2355 | */ |
|---|
| 2356 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
|---|
| 2357 | { |
|---|
| 2358 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
|---|
| 2359 | { |
|---|
| 2360 | TComYuv* pcYuv; |
|---|
| 2361 | // Change Information data |
|---|
| 2362 | TComDataCU* pcCU = rpcBestCU; |
|---|
| 2363 | rpcBestCU = rpcTempCU; |
|---|
| 2364 | rpcTempCU = pcCU; |
|---|
| 2365 | |
|---|
| 2366 | // Change Prediction data |
|---|
| 2367 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
|---|
| 2368 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
|---|
| 2369 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
|---|
| 2370 | |
|---|
| 2371 | // Change Reconstruction data |
|---|
| 2372 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
|---|
| 2373 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
|---|
| 2374 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
|---|
| 2375 | |
|---|
| 2376 | pcYuv = NULL; |
|---|
| 2377 | pcCU = NULL; |
|---|
| 2378 | |
|---|
| 2379 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
|---|
| 2380 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
|---|
| 2381 | } |
|---|
| 2382 | } |
|---|
| 2383 | |
|---|
| 2384 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
|---|
| 2385 | { |
|---|
| 2386 | UInt uiDepth = pcCU->getDepth( 0 ); |
|---|
| 2387 | |
|---|
| 2388 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 2389 | { |
|---|
| 2390 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
|---|
| 2391 | { |
|---|
| 2392 | #if !RDO_WITHOUT_DQP_BITS |
|---|
| 2393 | m_pcEntropyCoder->resetBits(); |
|---|
| 2394 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
|---|
| 2395 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
|---|
| 2396 | if(m_pcEncCfg->getUseSBACRD()) |
|---|
| 2397 | { |
|---|
| 2398 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
|---|
| 2399 | } |
|---|
| 2400 | |
|---|
| 2401 | // GT: Change here?? |
|---|
| 2402 | #if HHI_VSO |
|---|
| 2403 | if ( m_pcRdCost->getUseVSO() ) |
|---|
| 2404 | { |
|---|
| 2405 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
|---|
| 2406 | } |
|---|
| 2407 | else |
|---|
| 2408 | #endif |
|---|
| 2409 | { |
|---|
| 2410 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
|---|
| 2411 | } |
|---|
| 2412 | #endif |
|---|
| 2413 | } |
|---|
| 2414 | else |
|---|
| 2415 | { |
|---|
| 2416 | #if LOSSLESS_CODING |
|---|
| 2417 | if (( ( pcCU->getRefQP( 0 ) != pcCU->getQP( 0 )) ) && (pcCU->getSlice()->getSPS()->getUseLossless())) |
|---|
| 2418 | { |
|---|
| 2419 | pcCU->getTotalCost() = MAX_DOUBLE; |
|---|
| 2420 | } |
|---|
| 2421 | #endif |
|---|
| 2422 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
|---|
| 2423 | } |
|---|
| 2424 | } |
|---|
| 2425 | } |
|---|
| 2426 | |
|---|
| 2427 | /** Check whether the last CU shares the same root as the current CU and is IPCM or not. |
|---|
| 2428 | * \param pcCU |
|---|
| 2429 | * \param uiCurAbsPartIdx |
|---|
| 2430 | * \returns Bool |
|---|
| 2431 | */ |
|---|
| 2432 | Bool TEncCu::checkLastCUSucIPCM( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
|---|
| 2433 | { |
|---|
| 2434 | Bool lastCUSucIPCMFlag = false; |
|---|
| 2435 | |
|---|
| 2436 | UInt curDepth = pcCU->getDepth(uiCurAbsPartIdx); |
|---|
| 2437 | UInt shift = ((pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx())->getSPS()->getMaxCUDepth() - curDepth)<<1); |
|---|
| 2438 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
|---|
| 2439 | |
|---|
| 2440 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
|---|
| 2441 | if( pcSlice->getEntropySliceCurStartCUAddr() == ( pcCU->getSCUAddr() + uiCurAbsPartIdx ) ) |
|---|
| 2442 | { |
|---|
| 2443 | return false; |
|---|
| 2444 | } |
|---|
| 2445 | |
|---|
| 2446 | if(curDepth > 0 && startPartUnitIdx > 0) |
|---|
| 2447 | { |
|---|
| 2448 | Int lastValidPartIdx = pcCU->getLastValidPartIdx((Int) uiCurAbsPartIdx ); |
|---|
| 2449 | |
|---|
| 2450 | if( lastValidPartIdx >= 0 ) |
|---|
| 2451 | { |
|---|
| 2452 | if(( pcCU->getSliceStartCU( uiCurAbsPartIdx ) == pcCU->getSliceStartCU( (UInt) lastValidPartIdx )) |
|---|
| 2453 | && |
|---|
| 2454 | ( pcCU->getDepth( uiCurAbsPartIdx ) == pcCU->getDepth( (UInt) lastValidPartIdx )) |
|---|
| 2455 | && |
|---|
| 2456 | pcCU->getIPCMFlag( (UInt) lastValidPartIdx ) ) |
|---|
| 2457 | { |
|---|
| 2458 | lastCUSucIPCMFlag = true; |
|---|
| 2459 | } |
|---|
| 2460 | } |
|---|
| 2461 | } |
|---|
| 2462 | |
|---|
| 2463 | return lastCUSucIPCMFlag; |
|---|
| 2464 | } |
|---|
| 2465 | |
|---|
| 2466 | /** Count the number of successive IPCM CUs sharing the same root. |
|---|
| 2467 | * \param pcCU |
|---|
| 2468 | * \param uiCurAbsPartIdx |
|---|
| 2469 | * \returns Int |
|---|
| 2470 | */ |
|---|
| 2471 | Int TEncCu::countNumSucIPCM ( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) |
|---|
| 2472 | { |
|---|
| 2473 | Int numSucIPCM = 0; |
|---|
| 2474 | UInt CurDepth = pcCU->getDepth(uiCurAbsPartIdx); |
|---|
| 2475 | |
|---|
| 2476 | if( pcCU->getIPCMFlag(uiCurAbsPartIdx) ) |
|---|
| 2477 | { |
|---|
| 2478 | if(CurDepth == 0) |
|---|
| 2479 | { |
|---|
| 2480 | numSucIPCM = 1; |
|---|
| 2481 | } |
|---|
| 2482 | else |
|---|
| 2483 | { |
|---|
| 2484 | TComPic* pcPic = pcCU->getPic(); |
|---|
| 2485 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
|---|
| 2486 | UInt qNumParts = ( pcPic->getNumPartInCU() >> ((CurDepth-1)<<1) )>>2; |
|---|
| 2487 | |
|---|
| 2488 | Bool continueFlag = true; |
|---|
| 2489 | UInt absPartIdx = uiCurAbsPartIdx; |
|---|
| 2490 | UInt shift = ((pcSlice->getSPS()->getMaxCUDepth() - CurDepth)<<1); |
|---|
| 2491 | UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); |
|---|
| 2492 | |
|---|
| 2493 | for ( UInt partUnitIdx = startPartUnitIdx; partUnitIdx < 4 && continueFlag; partUnitIdx++, absPartIdx+=qNumParts ) |
|---|
| 2494 | { |
|---|
| 2495 | UInt lPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
|---|
| 2496 | UInt tPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
|---|
| 2497 | Bool inSliceFlag = ( pcCU->getSCUAddr()+absPartIdx+qNumParts>pcSlice->getEntropySliceCurStartCUAddr() ) && ( pcCU->getSCUAddr()+absPartIdx < pcSlice->getEntropySliceCurEndCUAddr()); |
|---|
| 2498 | |
|---|
| 2499 | if( inSliceFlag && ( lPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( tPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 2500 | { |
|---|
| 2501 | UInt uiDepth = pcCU->getDepth(absPartIdx); |
|---|
| 2502 | |
|---|
| 2503 | if( ( CurDepth == uiDepth) && pcCU->getIPCMFlag( absPartIdx ) ) |
|---|
| 2504 | { |
|---|
| 2505 | numSucIPCM++; |
|---|
| 2506 | } |
|---|
| 2507 | else |
|---|
| 2508 | { |
|---|
| 2509 | continueFlag = false; |
|---|
| 2510 | } |
|---|
| 2511 | } |
|---|
| 2512 | } |
|---|
| 2513 | } |
|---|
| 2514 | } |
|---|
| 2515 | |
|---|
| 2516 | return numSucIPCM; |
|---|
| 2517 | } |
|---|
| 2518 | |
|---|
| 2519 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
|---|
| 2520 | { |
|---|
| 2521 | pDst->iN = pSrc->iN; |
|---|
| 2522 | for (Int i = 0; i < pSrc->iN; i++) |
|---|
| 2523 | { |
|---|
| 2524 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
|---|
| 2525 | } |
|---|
| 2526 | } |
|---|
| 2527 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
|---|
| 2528 | { |
|---|
| 2529 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
|---|
| 2530 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
|---|
| 2531 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
|---|
| 2532 | Bool bSliceStart = pcSlice->getEntropySliceCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
|---|
| 2533 | pcSlice->getEntropySliceCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
|---|
| 2534 | Bool bSliceEnd = pcSlice->getEntropySliceCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
|---|
| 2535 | pcSlice->getEntropySliceCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
|---|
| 2536 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 2537 | { |
|---|
| 2538 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
|---|
| 2539 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
|---|
| 2540 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
|---|
| 2541 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
|---|
| 2542 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
|---|
| 2543 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
|---|
| 2544 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
|---|
| 2545 | } |
|---|
| 2546 | else |
|---|
| 2547 | { |
|---|
| 2548 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
|---|
| 2549 | |
|---|
| 2550 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
|---|
| 2551 | { |
|---|
| 2552 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
|---|
| 2553 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
|---|
| 2554 | |
|---|
| 2555 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getEntropySliceCurStartCUAddr() && |
|---|
| 2556 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getEntropySliceCurEndCUAddr(); |
|---|
| 2557 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 2558 | { |
|---|
| 2559 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
|---|
| 2560 | } |
|---|
| 2561 | } |
|---|
| 2562 | } |
|---|
| 2563 | } |
|---|
| 2564 | |
|---|
| 2565 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
|---|
| 2566 | { |
|---|
| 2567 | UInt uiCurrDepth = uiNextDepth - 1; |
|---|
| 2568 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
|---|
| 2569 | } |
|---|
| 2570 | |
|---|
| 2571 | #if LOSSLESS_CODING |
|---|
| 2572 | /** Function for filling the PCM buffer of a CU using its original sample array |
|---|
| 2573 | * \param pcCU pointer to current CU |
|---|
| 2574 | * \param pcOrgYuv pointer to original sample array |
|---|
| 2575 | * \returns Void |
|---|
| 2576 | */ |
|---|
| 2577 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
|---|
| 2578 | { |
|---|
| 2579 | |
|---|
| 2580 | UInt width = pCU->getWidth(0); |
|---|
| 2581 | UInt height = pCU->getHeight(0); |
|---|
| 2582 | |
|---|
| 2583 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
|---|
| 2584 | Pel* pDstY = pCU->getPCMSampleY(); |
|---|
| 2585 | UInt srcStride = pOrgYuv->getStride(); |
|---|
| 2586 | |
|---|
| 2587 | for(Int y = 0; y < height; y++ ) |
|---|
| 2588 | { |
|---|
| 2589 | for(Int x = 0; x < width; x++ ) |
|---|
| 2590 | { |
|---|
| 2591 | pDstY[x] = pSrcY[x]; |
|---|
| 2592 | } |
|---|
| 2593 | pDstY += width; |
|---|
| 2594 | pSrcY += srcStride; |
|---|
| 2595 | } |
|---|
| 2596 | |
|---|
| 2597 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
|---|
| 2598 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
|---|
| 2599 | |
|---|
| 2600 | Pel* pDstCb = pCU->getPCMSampleCb(); |
|---|
| 2601 | Pel* pDstCr = pCU->getPCMSampleCr();; |
|---|
| 2602 | |
|---|
| 2603 | UInt srcStrideC = pOrgYuv->getCStride(); |
|---|
| 2604 | UInt heightC = height >> 1; |
|---|
| 2605 | UInt widthC = width >> 1; |
|---|
| 2606 | |
|---|
| 2607 | for(Int y = 0; y < heightC; y++ ) |
|---|
| 2608 | { |
|---|
| 2609 | for(Int x = 0; x < widthC; x++ ) |
|---|
| 2610 | { |
|---|
| 2611 | pDstCb[x] = pSrcCb[x]; |
|---|
| 2612 | pDstCr[x] = pSrcCr[x]; |
|---|
| 2613 | } |
|---|
| 2614 | pDstCb += widthC; |
|---|
| 2615 | pDstCr += widthC; |
|---|
| 2616 | pSrcCb += srcStrideC; |
|---|
| 2617 | pSrcCr += srcStrideC; |
|---|
| 2618 | } |
|---|
| 2619 | } |
|---|
| 2620 | #endif |
|---|
| 2621 | |
|---|
| 2622 | #if ADAPTIVE_QP_SELECTION |
|---|
| 2623 | /** Collect ARL statistics from one block |
|---|
| 2624 | */ |
|---|
| 2625 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
|---|
| 2626 | { |
|---|
| 2627 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
|---|
| 2628 | { |
|---|
| 2629 | Int u = abs( rpcCoeff[ n ] ); |
|---|
| 2630 | Int absc = rpcArlCoeff[ n ]; |
|---|
| 2631 | |
|---|
| 2632 | if( u != 0 ) |
|---|
| 2633 | { |
|---|
| 2634 | if( u < LEVEL_RANGE ) |
|---|
| 2635 | { |
|---|
| 2636 | cSum[ u ] += ( Double )absc; |
|---|
| 2637 | numSamples[ u ]++; |
|---|
| 2638 | } |
|---|
| 2639 | else |
|---|
| 2640 | { |
|---|
| 2641 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
|---|
| 2642 | numSamples[ LEVEL_RANGE ]++; |
|---|
| 2643 | } |
|---|
| 2644 | } |
|---|
| 2645 | } |
|---|
| 2646 | |
|---|
| 2647 | return 0; |
|---|
| 2648 | } |
|---|
| 2649 | |
|---|
| 2650 | /** Collect ARL statistics from one LCU |
|---|
| 2651 | * \param pcCU |
|---|
| 2652 | */ |
|---|
| 2653 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
|---|
| 2654 | { |
|---|
| 2655 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
|---|
| 2656 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
|---|
| 2657 | |
|---|
| 2658 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
|---|
| 2659 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
|---|
| 2660 | |
|---|
| 2661 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
|---|
| 2662 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
|---|
| 2663 | |
|---|
| 2664 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
|---|
| 2665 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
|---|
| 2666 | |
|---|
| 2667 | // Collect stats to cSum[][] and numSamples[][] |
|---|
| 2668 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
|---|
| 2669 | { |
|---|
| 2670 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
|---|
| 2671 | |
|---|
| 2672 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
|---|
| 2673 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
|---|
| 2674 | { |
|---|
| 2675 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
|---|
| 2676 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
|---|
| 2677 | |
|---|
| 2678 | pCoeffY += uiMinNumCoeffInCU; |
|---|
| 2679 | pArlCoeffY += uiMinNumCoeffInCU; |
|---|
| 2680 | } |
|---|
| 2681 | |
|---|
| 2682 | for(Int u=1; u<LEVEL_RANGE;u++) |
|---|
| 2683 | { |
|---|
| 2684 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
|---|
| 2685 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
|---|
| 2686 | } |
|---|
| 2687 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
|---|
| 2688 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
|---|
| 2689 | } |
|---|
| 2690 | #endif |
|---|
| 2691 | |
|---|
| 2692 | #if HHI_MPI |
|---|
| 2693 | Void TEncCu::xCheckRDCostMvInheritance( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UChar uhTextureModeDepth, Bool bSkipResidual, Bool bRecursiveCall ) |
|---|
| 2694 | { |
|---|
| 2695 | assert( rpcTempCU->getSlice()->getIsDepth() ); |
|---|
| 2696 | TComDataCU *pcTextureCU = rpcTempCU->getSlice()->getTexturePic()->getCU( rpcTempCU->getAddr() ); |
|---|
| 2697 | |
|---|
| 2698 | const UChar uhDepth = rpcTempCU->getDepth( 0 ); |
|---|
| 2699 | const Int iQP = rpcTempCU->getQP( 0 ); |
|---|
| 2700 | assert( bRecursiveCall == ( uhDepth != uhTextureModeDepth ) ); |
|---|
| 2701 | |
|---|
| 2702 | #if !MTK_UNCONSTRAINED_MVI_B0083 |
|---|
| 2703 | if( uhDepth == uhTextureModeDepth ) |
|---|
| 2704 | { |
|---|
| 2705 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
|---|
| 2706 | { |
|---|
| 2707 | if( pcTextureCU->isIntra( rpcTempCU->getZorderIdxInCU() + ui ) ) |
|---|
| 2708 | { |
|---|
| 2709 | return; |
|---|
| 2710 | } |
|---|
| 2711 | } |
|---|
| 2712 | } |
|---|
| 2713 | #endif |
|---|
| 2714 | |
|---|
| 2715 | #if HHI_VSO |
|---|
| 2716 | if( m_pcRdCost->getUseRenModel() && !bRecursiveCall) |
|---|
| 2717 | { |
|---|
| 2718 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
|---|
| 2719 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
|---|
| 2720 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr(); |
|---|
| 2721 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
|---|
| 2722 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 2723 | } |
|---|
| 2724 | #endif |
|---|
| 2725 | |
|---|
| 2726 | Bool bSplit = uhDepth < pcTextureCU->getDepth( rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2727 | if( bSplit ) |
|---|
| 2728 | { |
|---|
| 2729 | const UChar uhNextDepth = uhDepth+1; |
|---|
| 2730 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
|---|
| 2731 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
|---|
| 2732 | |
|---|
| 2733 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
|---|
| 2734 | { |
|---|
| 2735 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
|---|
| 2736 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
|---|
| 2737 | |
|---|
| 2738 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
|---|
| 2739 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getEntropySliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getEntropySliceCurEndCUAddr(); |
|---|
| 2740 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
|---|
| 2741 | { |
|---|
| 2742 | if( m_bUseSBACRD ) |
|---|
| 2743 | { |
|---|
| 2744 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
|---|
| 2745 | { |
|---|
| 2746 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhDepth][CI_CURR_BEST]); |
|---|
| 2747 | } |
|---|
| 2748 | else |
|---|
| 2749 | { |
|---|
| 2750 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
|---|
| 2751 | } |
|---|
| 2752 | } |
|---|
| 2753 | |
|---|
| 2754 | xCheckRDCostMvInheritance( pcSubBestPartCU, pcSubTempPartCU, uhTextureModeDepth, bSkipResidual, true ); |
|---|
| 2755 | |
|---|
| 2756 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
|---|
| 2757 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
|---|
| 2758 | } |
|---|
| 2759 | else if (bInSlice) |
|---|
| 2760 | { |
|---|
| 2761 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
|---|
| 2762 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
|---|
| 2763 | } |
|---|
| 2764 | } |
|---|
| 2765 | |
|---|
| 2766 | if( uhDepth == uhTextureModeDepth ) |
|---|
| 2767 | { |
|---|
| 2768 | xAddMVISignallingBits( rpcTempCU ); |
|---|
| 2769 | } |
|---|
| 2770 | |
|---|
| 2771 | // DQP stuff |
|---|
| 2772 | { |
|---|
| 2773 | if( (g_uiMaxCUWidth>>uhDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
|---|
| 2774 | { |
|---|
| 2775 | TComPic *pcPic = rpcTempCU->getPic(); |
|---|
| 2776 | TComSlice *pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
|---|
| 2777 | Bool bHasRedisual = false; |
|---|
| 2778 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
|---|
| 2779 | { |
|---|
| 2780 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getEntropySliceCurStartCUAddr() ) && |
|---|
| 2781 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
|---|
| 2782 | { |
|---|
| 2783 | bHasRedisual = true; |
|---|
| 2784 | break; |
|---|
| 2785 | } |
|---|
| 2786 | } |
|---|
| 2787 | |
|---|
| 2788 | UInt uiTargetPartIdx; |
|---|
| 2789 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getEntropySliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getEntropySliceCurStartCUAddr() ) |
|---|
| 2790 | { |
|---|
| 2791 | uiTargetPartIdx = pcSlice->getEntropySliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
|---|
| 2792 | } |
|---|
| 2793 | else |
|---|
| 2794 | { |
|---|
| 2795 | uiTargetPartIdx = 0; |
|---|
| 2796 | } |
|---|
| 2797 | if ( ! bHasRedisual ) |
|---|
| 2798 | { |
|---|
| 2799 | #if LOSSLESS_CODING |
|---|
| 2800 | if (((rpcTempCU->getQP(uiTargetPartIdx) != rpcTempCU->getRefQP(uiTargetPartIdx)) ) && (rpcTempCU->getSlice()->getSPS()->getUseLossless())) |
|---|
| 2801 | { |
|---|
| 2802 | rpcTempCU->getTotalCost() = MAX_DOUBLE; |
|---|
| 2803 | } |
|---|
| 2804 | #endif |
|---|
| 2805 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uhDepth ); // set QP to default QP |
|---|
| 2806 | } |
|---|
| 2807 | } |
|---|
| 2808 | } |
|---|
| 2809 | |
|---|
| 2810 | if( m_bUseSBACRD ) |
|---|
| 2811 | { |
|---|
| 2812 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]); |
|---|
| 2813 | } |
|---|
| 2814 | } |
|---|
| 2815 | else |
|---|
| 2816 | { |
|---|
| 2817 | rpcTempCU->setTextureModeDepthSubParts( uhTextureModeDepth, 0, uhDepth ); |
|---|
| 2818 | rpcTempCU->copyTextureMotionDataFrom( pcTextureCU, uhDepth, rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2819 | #if FIX_MPI_B0065 |
|---|
| 2820 | UInt uiAbsPartIdx = rpcTempCU->getZorderIdxInCU(); |
|---|
| 2821 | if( rpcTempCU->getDepth(0) > pcTextureCU->getDepth(uiAbsPartIdx)) |
|---|
| 2822 | { |
|---|
| 2823 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
|---|
| 2824 | } |
|---|
| 2825 | else |
|---|
| 2826 | { |
|---|
| 2827 | PartSize partSize = pcTextureCU->getPartitionSize(uiAbsPartIdx); |
|---|
| 2828 | rpcTempCU->setPartSizeSubParts( partSize, 0, uhDepth ); |
|---|
| 2829 | } |
|---|
| 2830 | #else |
|---|
| 2831 | rpcTempCU->setPartSizeSubParts( SIZE_NxN, 0, uhDepth ); |
|---|
| 2832 | #endif |
|---|
| 2833 | for( UInt ui = 0; ui < rpcTempCU->getTotalNumPart(); ui++ ) |
|---|
| 2834 | { |
|---|
| 2835 | assert( rpcTempCU->getInterDir( ui ) != 0 ); |
|---|
| 2836 | assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE ); |
|---|
| 2837 | #if MERL_VSP_C0152 |
|---|
| 2838 | Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui); |
|---|
| 2839 | rpcTempCU->setVSPIndex( ui , vspIdx); |
|---|
| 2840 | #endif |
|---|
| 2841 | } |
|---|
| 2842 | |
|---|
| 2843 | rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth ); |
|---|
| 2844 | #if MERL_VSP_C0152 |
|---|
| 2845 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() ); |
|---|
| 2846 | #else |
|---|
| 2847 | m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
|---|
| 2848 | #endif |
|---|
| 2849 | // get Original YUV data from picture |
|---|
| 2850 | m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
|---|
| 2851 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
|---|
| 2852 | m_ppcOrigYuv[uhDepth], |
|---|
| 2853 | m_ppcPredYuvTemp[uhDepth], |
|---|
| 2854 | m_ppcResiYuvTemp[uhDepth], |
|---|
| 2855 | m_ppcResiYuvBest[uhDepth], |
|---|
| 2856 | m_ppcRecoYuvTemp[uhDepth], |
|---|
| 2857 | #if H3D_IVRP |
|---|
| 2858 | m_ppcResPredTmp [uhDepth], |
|---|
| 2859 | #endif |
|---|
| 2860 | bSkipResidual ); |
|---|
| 2861 | |
|---|
| 2862 | if( uhDepth == uhTextureModeDepth ) |
|---|
| 2863 | { |
|---|
| 2864 | xAddMVISignallingBits( rpcTempCU ); |
|---|
| 2865 | } |
|---|
| 2866 | xCheckDQP( rpcTempCU ); |
|---|
| 2867 | } |
|---|
| 2868 | |
|---|
| 2869 | #if HHI_VSO |
|---|
| 2870 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
|---|
| 2871 | { |
|---|
| 2872 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2873 | } |
|---|
| 2874 | else |
|---|
| 2875 | #endif |
|---|
| 2876 | { |
|---|
| 2877 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
|---|
| 2878 | } |
|---|
| 2879 | |
|---|
| 2880 | if( rpcTempCU->getPredictionMode( 0 ) == MODE_SKIP && uhDepth == uhTextureModeDepth ) |
|---|
| 2881 | { |
|---|
| 2882 | if( rpcTempCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uhDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
|---|
| 2883 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uhDepth ); // set QP to default QP |
|---|
| 2884 | } |
|---|
| 2885 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
|---|
| 2886 | rpcBestCU->copyToPic(uhDepth); // Copy Best data to Picture for next partition prediction. |
|---|
| 2887 | |
|---|
| 2888 | #if HHI_VSO |
|---|
| 2889 | if( !bSplit && bRecursiveCall && m_pcRdCost->getUseRenModel() ) |
|---|
| 2890 | { |
|---|
| 2891 | UInt uiWidth = m_ppcRecoYuvBest[uhDepth]->getWidth ( ); |
|---|
| 2892 | UInt uiHeight = m_ppcRecoYuvBest[uhDepth]->getHeight ( ); |
|---|
| 2893 | UInt uiSrcStride = m_ppcRecoYuvBest[uhDepth]->getStride ( ); |
|---|
| 2894 | Pel* piSrc = m_ppcRecoYuvBest[uhDepth]->getLumaAddr( 0 ); |
|---|
| 2895 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
|---|
| 2896 | } |
|---|
| 2897 | #endif |
|---|
| 2898 | } |
|---|
| 2899 | |
|---|
| 2900 | Void TEncCu::xAddMVISignallingBits( TComDataCU* pcCU ) |
|---|
| 2901 | { |
|---|
| 2902 | const UChar uhDepth = pcCU->getTextureModeDepth( 0 ); |
|---|
| 2903 | m_pcEntropyCoder->resetBits(); |
|---|
| 2904 | xSaveDepthWidthHeight( pcCU ); |
|---|
| 2905 | pcCU->setSizeSubParts( g_uiMaxCUWidth>>uhDepth, g_uiMaxCUHeight>>uhDepth, 0, uhDepth ); |
|---|
| 2906 | pcCU->setDepthSubParts( uhDepth, 0 ); |
|---|
| 2907 | pcCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); |
|---|
| 2908 | pcCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); |
|---|
| 2909 | pcCU->setMergeIndexSubParts( HHI_MPI_MERGE_POS, 0, 0, uhDepth ); |
|---|
| 2910 | |
|---|
| 2911 | // check for skip mode |
|---|
| 2912 | { |
|---|
| 2913 | Bool bAllZero = true; |
|---|
| 2914 | for( UInt ui = 0; ui < pcCU->getTotalNumPart(); ui++ ) |
|---|
| 2915 | { |
|---|
| 2916 | if( pcCU->getCbf( ui, TEXT_LUMA ) || pcCU->getCbf( ui, TEXT_CHROMA_U ) || pcCU->getCbf( ui, TEXT_CHROMA_V ) ) |
|---|
| 2917 | { |
|---|
| 2918 | bAllZero = false; |
|---|
| 2919 | break; |
|---|
| 2920 | } |
|---|
| 2921 | } |
|---|
| 2922 | if( bAllZero ) |
|---|
| 2923 | pcCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); |
|---|
| 2924 | } |
|---|
| 2925 | |
|---|
| 2926 | |
|---|
| 2927 | m_pcEntropyCoder->encodeSplitFlag( pcCU, 0, uhDepth, true ); |
|---|
| 2928 | m_pcEntropyCoder->encodeSkipFlag( pcCU, 0, true ); |
|---|
| 2929 | |
|---|
| 2930 | if( pcCU->isSkipped( 0 ) ) |
|---|
| 2931 | { |
|---|
| 2932 | m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true ); |
|---|
| 2933 | #if LGE_ILLUCOMP_B0045 |
|---|
| 2934 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true |
|---|
| 2935 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 2936 | , uhDepth |
|---|
| 2937 | #endif |
|---|
| 2938 | ); |
|---|
| 2939 | #endif |
|---|
| 2940 | } |
|---|
| 2941 | else |
|---|
| 2942 | { |
|---|
| 2943 | m_pcEntropyCoder->encodePredMode( pcCU, 0, true ); |
|---|
| 2944 | m_pcEntropyCoder->encodePartSize( pcCU, 0, uhDepth, true ); |
|---|
| 2945 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
|---|
| 2946 | m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); |
|---|
| 2947 | #if LGE_ILLUCOMP_B0045 |
|---|
| 2948 | m_pcEntropyCoder->encodeICFlag( pcCU, 0, true |
|---|
| 2949 | #if LGE_ILLUCOMP_DEPTH_C0046 |
|---|
| 2950 | , uhDepth |
|---|
| 2951 | #endif |
|---|
| 2952 | ); |
|---|
| 2953 | #endif |
|---|
| 2954 | } |
|---|
| 2955 | xRestoreDepthWidthHeight( pcCU ); |
|---|
| 2956 | |
|---|
| 2957 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); |
|---|
| 2958 | } |
|---|
| 2959 | |
|---|
| 2960 | Void TEncCu::xSaveDepthWidthHeight( TComDataCU* pcCU ) |
|---|
| 2961 | { |
|---|
| 2962 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
|---|
| 2963 | memcpy( m_puhDepthSaved, pcCU->getDepth(), iSizeInUchar ); |
|---|
| 2964 | memcpy( m_puhWidthSaved, pcCU->getWidth(), iSizeInUchar ); |
|---|
| 2965 | memcpy( m_puhHeightSaved, pcCU->getHeight(), iSizeInUchar ); |
|---|
| 2966 | } |
|---|
| 2967 | |
|---|
| 2968 | Void TEncCu::xRestoreDepthWidthHeight( TComDataCU* pcCU ) |
|---|
| 2969 | { |
|---|
| 2970 | const Int iSizeInUchar = sizeof( UChar ) * pcCU->getTotalNumPart(); |
|---|
| 2971 | memcpy( pcCU->getDepth(), m_puhDepthSaved, iSizeInUchar ); |
|---|
| 2972 | memcpy( pcCU->getWidth(), m_puhWidthSaved, iSizeInUchar ); |
|---|
| 2973 | memcpy( pcCU->getHeight(), m_puhHeightSaved, iSizeInUchar ); |
|---|
| 2974 | } |
|---|
| 2975 | #endif |
|---|
| 2976 | |
|---|
| 2977 | //! \} |
|---|