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