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