[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
[593] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncCu.cpp |
---|
| 35 | \brief Coding Unit (CU) encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <stdio.h> |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncCu.h" |
---|
| 41 | #include "TEncAnalyze.h" |
---|
| 42 | |
---|
| 43 | #include <cmath> |
---|
| 44 | #include <algorithm> |
---|
| 45 | using namespace std; |
---|
| 46 | |
---|
| 47 | //! \ingroup TLibEncoder |
---|
| 48 | //! \{ |
---|
| 49 | |
---|
| 50 | // ==================================================================================================================== |
---|
| 51 | // Constructor / destructor / create / destroy |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | \param uiTotalDepth total number of allowable depth |
---|
| 56 | \param uiMaxWidth largest CU width |
---|
| 57 | \param uiMaxHeight largest CU height |
---|
| 58 | */ |
---|
| 59 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight) |
---|
| 60 | { |
---|
| 61 | Int i; |
---|
| 62 | |
---|
| 63 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
| 64 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 65 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 66 | |
---|
| 67 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 68 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 69 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 70 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 71 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 72 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 73 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 74 | |
---|
| 75 | UInt uiNumPartitions; |
---|
| 76 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 77 | { |
---|
| 78 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
| 79 | UInt uiWidth = uiMaxWidth >> i; |
---|
| 80 | UInt uiHeight = uiMaxHeight >> i; |
---|
| 81 | |
---|
| 82 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 83 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 84 | |
---|
| 85 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 86 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 87 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 88 | |
---|
| 89 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 90 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 91 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 92 | |
---|
| 93 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | m_bEncodeDQP = false; |
---|
| 97 | |
---|
| 98 | // initialize partition order. |
---|
| 99 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
| 100 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
| 101 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
| 102 | |
---|
| 103 | // initialize conversion matrix from partition index to pel |
---|
| 104 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | Void TEncCu::destroy() |
---|
| 108 | { |
---|
| 109 | Int i; |
---|
| 110 | |
---|
| 111 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 112 | { |
---|
| 113 | if(m_ppcBestCU[i]) |
---|
| 114 | { |
---|
| 115 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
| 116 | } |
---|
| 117 | if(m_ppcTempCU[i]) |
---|
| 118 | { |
---|
| 119 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
| 120 | } |
---|
| 121 | if(m_ppcPredYuvBest[i]) |
---|
| 122 | { |
---|
| 123 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
| 124 | } |
---|
| 125 | if(m_ppcResiYuvBest[i]) |
---|
| 126 | { |
---|
| 127 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
| 128 | } |
---|
| 129 | if(m_ppcRecoYuvBest[i]) |
---|
| 130 | { |
---|
| 131 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
| 132 | } |
---|
| 133 | if(m_ppcPredYuvTemp[i]) |
---|
| 134 | { |
---|
| 135 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
| 136 | } |
---|
| 137 | if(m_ppcResiYuvTemp[i]) |
---|
| 138 | { |
---|
| 139 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
| 140 | } |
---|
| 141 | if(m_ppcRecoYuvTemp[i]) |
---|
| 142 | { |
---|
| 143 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
| 144 | } |
---|
| 145 | if(m_ppcOrigYuv[i]) |
---|
| 146 | { |
---|
| 147 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | if(m_ppcBestCU) |
---|
| 151 | { |
---|
| 152 | delete [] m_ppcBestCU; |
---|
| 153 | m_ppcBestCU = NULL; |
---|
| 154 | } |
---|
| 155 | if(m_ppcTempCU) |
---|
| 156 | { |
---|
| 157 | delete [] m_ppcTempCU; |
---|
| 158 | m_ppcTempCU = NULL; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | if(m_ppcPredYuvBest) |
---|
| 162 | { |
---|
| 163 | delete [] m_ppcPredYuvBest; |
---|
| 164 | m_ppcPredYuvBest = NULL; |
---|
| 165 | } |
---|
| 166 | if(m_ppcResiYuvBest) |
---|
| 167 | { |
---|
| 168 | delete [] m_ppcResiYuvBest; |
---|
| 169 | m_ppcResiYuvBest = NULL; |
---|
| 170 | } |
---|
| 171 | if(m_ppcRecoYuvBest) |
---|
| 172 | { |
---|
| 173 | delete [] m_ppcRecoYuvBest; |
---|
| 174 | m_ppcRecoYuvBest = NULL; |
---|
| 175 | } |
---|
| 176 | if(m_ppcPredYuvTemp) |
---|
| 177 | { |
---|
| 178 | delete [] m_ppcPredYuvTemp; |
---|
| 179 | m_ppcPredYuvTemp = NULL; |
---|
| 180 | } |
---|
| 181 | if(m_ppcResiYuvTemp) |
---|
| 182 | { |
---|
| 183 | delete [] m_ppcResiYuvTemp; |
---|
| 184 | m_ppcResiYuvTemp = NULL; |
---|
| 185 | } |
---|
| 186 | if(m_ppcRecoYuvTemp) |
---|
| 187 | { |
---|
| 188 | delete [] m_ppcRecoYuvTemp; |
---|
| 189 | m_ppcRecoYuvTemp = NULL; |
---|
| 190 | } |
---|
| 191 | if(m_ppcOrigYuv) |
---|
| 192 | { |
---|
| 193 | delete [] m_ppcOrigYuv; |
---|
| 194 | m_ppcOrigYuv = NULL; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** \param pcEncTop pointer of encoder class |
---|
| 199 | */ |
---|
| 200 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
| 201 | { |
---|
| 202 | m_pcEncCfg = pcEncTop; |
---|
| 203 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
| 204 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
| 205 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
| 206 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
| 207 | |
---|
| 208 | #if SVC_EXTENSION |
---|
| 209 | m_ppcTEncTop = pcEncTop->getLayerEnc(); |
---|
| 210 | for(UInt i=0 ; i< m_uhTotalDepth-1 ; i++) |
---|
| 211 | { |
---|
| 212 | m_ppcBestCU[i]->setLayerId(pcEncTop->getLayerId()); |
---|
| 213 | m_ppcTempCU[i]->setLayerId(pcEncTop->getLayerId()); |
---|
| 214 | } |
---|
| 215 | #endif |
---|
| 216 | |
---|
| 217 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
| 218 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
| 219 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
| 220 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
| 221 | |
---|
| 222 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
| 223 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
| 224 | |
---|
| 225 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | // ==================================================================================================================== |
---|
| 229 | // Public member functions |
---|
| 230 | // ==================================================================================================================== |
---|
| 231 | |
---|
| 232 | /** \param rpcCU pointer of CU data class |
---|
| 233 | */ |
---|
| 234 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
| 235 | { |
---|
| 236 | // initialize CU data |
---|
| 237 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 238 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 239 | |
---|
[494] | 240 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 241 | m_disableILP = xCheckTileSetConstraint(rpcCU); |
---|
| 242 | m_pcPredSearch->setDisableILP(m_disableILP); |
---|
| 243 | #endif |
---|
| 244 | |
---|
[313] | 245 | // analysis of CU |
---|
| 246 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
| 247 | |
---|
| 248 | #if ADAPTIVE_QP_SELECTION |
---|
| 249 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
| 250 | { |
---|
| 251 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
| 252 | { |
---|
| 253 | xLcuCollectARLStats( rpcCU); |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | #endif |
---|
[494] | 257 | |
---|
| 258 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 259 | xVerifyTileSetConstraint(rpcCU); |
---|
| 260 | #endif |
---|
[313] | 261 | } |
---|
| 262 | /** \param pcCU pointer of CU data class |
---|
| 263 | */ |
---|
| 264 | Void TEncCu::encodeCU ( TComDataCU* pcCU ) |
---|
| 265 | { |
---|
| 266 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
| 267 | { |
---|
| 268 | setdQPFlag(true); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | // Encode CU data |
---|
| 272 | xEncodeCU( pcCU, 0, 0 ); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | // ==================================================================================================================== |
---|
| 276 | // Protected member functions |
---|
| 277 | // ==================================================================================================================== |
---|
| 278 | /** Derive small set of test modes for AMP encoder speed-up |
---|
| 279 | *\param rpcBestCU |
---|
| 280 | *\param eParentPartSize |
---|
| 281 | *\param bTestAMP_Hor |
---|
| 282 | *\param bTestAMP_Ver |
---|
| 283 | *\param bTestMergeAMP_Hor |
---|
| 284 | *\param bTestMergeAMP_Ver |
---|
| 285 | *\returns Void |
---|
| 286 | */ |
---|
| 287 | #if AMP_ENC_SPEEDUP |
---|
| 288 | #if AMP_MRG |
---|
| 289 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
| 290 | #else |
---|
| 291 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
| 292 | #endif |
---|
| 293 | { |
---|
| 294 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
| 295 | { |
---|
| 296 | bTestAMP_Hor = true; |
---|
| 297 | } |
---|
| 298 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 299 | { |
---|
| 300 | bTestAMP_Ver = true; |
---|
| 301 | } |
---|
| 302 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
---|
| 303 | { |
---|
| 304 | bTestAMP_Hor = true; |
---|
| 305 | bTestAMP_Ver = true; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | #if AMP_MRG |
---|
| 309 | //! Utilizing the partition size of parent PU |
---|
| 310 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 311 | { |
---|
| 312 | bTestMergeAMP_Hor = true; |
---|
| 313 | bTestMergeAMP_Ver = true; |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
---|
| 317 | { |
---|
| 318 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
| 319 | { |
---|
| 320 | bTestMergeAMP_Hor = true; |
---|
| 321 | } |
---|
| 322 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 323 | { |
---|
| 324 | bTestMergeAMP_Ver = true; |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
---|
| 329 | { |
---|
| 330 | bTestMergeAMP_Hor = true; |
---|
| 331 | bTestMergeAMP_Ver = true; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | if ( rpcBestCU->getWidth(0) == 64 ) |
---|
| 335 | { |
---|
| 336 | bTestAMP_Hor = false; |
---|
| 337 | bTestAMP_Ver = false; |
---|
| 338 | } |
---|
| 339 | #else |
---|
| 340 | //! Utilizing the partition size of parent PU |
---|
| 341 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 342 | { |
---|
| 343 | bTestAMP_Hor = true; |
---|
| 344 | bTestAMP_Ver = true; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
| 348 | { |
---|
| 349 | bTestAMP_Hor = false; |
---|
| 350 | bTestAMP_Ver = false; |
---|
| 351 | } |
---|
| 352 | #endif |
---|
| 353 | } |
---|
| 354 | #endif |
---|
| 355 | |
---|
| 356 | // ==================================================================================================================== |
---|
| 357 | // Protected member functions |
---|
| 358 | // ==================================================================================================================== |
---|
| 359 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
---|
| 360 | *\param rpcBestCU |
---|
| 361 | *\param rpcTempCU |
---|
| 362 | *\param uiDepth |
---|
| 363 | *\returns Void |
---|
| 364 | * |
---|
| 365 | *- for loop of QP value to compress the current CU with all possible QP |
---|
| 366 | */ |
---|
| 367 | #if AMP_ENC_SPEEDUP |
---|
| 368 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
---|
| 369 | #else |
---|
| 370 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
| 371 | #endif |
---|
| 372 | { |
---|
| 373 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
| 374 | |
---|
| 375 | // get Original YUV data from picture |
---|
| 376 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
| 377 | |
---|
| 378 | // variable for Early CU determination |
---|
| 379 | Bool bSubBranch = true; |
---|
| 380 | |
---|
| 381 | // variable for Cbf fast mode PU decision |
---|
| 382 | Bool doNotBlockPu = true; |
---|
| 383 | Bool earlyDetectionSkipMode = false; |
---|
| 384 | |
---|
| 385 | Bool bBoundary = false; |
---|
| 386 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
| 387 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
| 388 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
| 389 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
| 390 | |
---|
| 391 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
| 392 | Int iMinQP; |
---|
| 393 | Int iMaxQP; |
---|
| 394 | Bool isAddLowestQP = false; |
---|
| 395 | |
---|
| 396 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 397 | { |
---|
| 398 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[442] | 399 | #if REPN_FORMAT_IN_VPS |
---|
[313] | 400 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 401 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
[442] | 402 | #else |
---|
| 403 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 404 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
[593] | 405 | #endif |
---|
[313] | 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | iMinQP = rpcTempCU->getQP(0); |
---|
| 410 | iMaxQP = rpcTempCU->getQP(0); |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 414 | { |
---|
| 415 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 416 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 417 | } |
---|
| 418 | |
---|
[593] | 419 | // transquant-bypass (TQB) processing loop variable initialisation --- |
---|
| 420 | |
---|
| 421 | const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels. |
---|
| 422 | |
---|
| 423 | if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) ) |
---|
| 424 | { |
---|
| 425 | isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. |
---|
| 426 | iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs |
---|
| 427 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
| 428 | { |
---|
| 429 | iMaxQP = iMinQP; |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
[313] | 433 | // If slice start or slice end is within this cu... |
---|
| 434 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
| 435 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
| 436 | Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
[442] | 437 | #if REPN_FORMAT_IN_VPS |
---|
| 438 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples() ); |
---|
| 439 | #else |
---|
[313] | 440 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
[442] | 441 | #endif |
---|
[313] | 442 | // We need to split, so don't try these modes. |
---|
| 443 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
| 444 | { |
---|
[540] | 445 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 446 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
| 447 | { |
---|
[593] | 448 | Int iQP = iBaseQP; |
---|
| 449 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
| 450 | |
---|
| 451 | if( bIsLosslessMode ) |
---|
| 452 | { |
---|
| 453 | iQP = lowestQP; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[540] | 457 | |
---|
| 458 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true ); |
---|
| 459 | } |
---|
| 460 | else |
---|
| 461 | { |
---|
| 462 | #endif |
---|
[313] | 463 | #if (ENCODER_FAST_MODE) |
---|
| 464 | Bool testInter = true; |
---|
| 465 | if (rpcBestCU->getLayerId() > 0) |
---|
| 466 | { |
---|
[442] | 467 | if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 468 | { |
---|
| 469 | testInter = false; |
---|
| 470 | } |
---|
| 471 | if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 472 | { |
---|
| 473 | testInter = false; |
---|
| 474 | } |
---|
[313] | 475 | } |
---|
| 476 | #endif |
---|
| 477 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 478 | { |
---|
[593] | 479 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
| 480 | |
---|
| 481 | if (bIsLosslessMode) |
---|
[313] | 482 | { |
---|
| 483 | iQP = lowestQP; |
---|
| 484 | } |
---|
| 485 | |
---|
[593] | 486 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 487 | |
---|
| 488 | // do inter modes, SKIP and 2Nx2N |
---|
| 489 | #if (ENCODER_FAST_MODE == 1) |
---|
| 490 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
| 491 | #else |
---|
| 492 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 493 | #endif |
---|
| 494 | { |
---|
| 495 | // 2Nx2N |
---|
| 496 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 497 | { |
---|
[593] | 498 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
| 499 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
[313] | 500 | } |
---|
| 501 | // SKIP |
---|
| 502 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
[593] | 503 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[442] | 504 | |
---|
[313] | 505 | #if (ENCODER_FAST_MODE == 2) |
---|
| 506 | if (testInter) |
---|
| 507 | { |
---|
| 508 | #endif |
---|
| 509 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 510 | { |
---|
| 511 | // 2Nx2N, NxN |
---|
[593] | 512 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
| 513 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[442] | 514 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
[313] | 515 | { |
---|
[442] | 516 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[313] | 517 | } |
---|
| 518 | } |
---|
| 519 | #if (ENCODER_FAST_MODE == 2) |
---|
[442] | 520 | } |
---|
[313] | 521 | #endif |
---|
| 522 | } |
---|
| 523 | |
---|
[593] | 524 | if (bIsLosslessMode) |
---|
[313] | 525 | { |
---|
| 526 | iQP = iMinQP; |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | if(!earlyDetectionSkipMode) |
---|
| 531 | { |
---|
| 532 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 533 | { |
---|
[593] | 534 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
| 535 | |
---|
| 536 | if (bIsLosslessMode) |
---|
[313] | 537 | { |
---|
| 538 | iQP = lowestQP; |
---|
| 539 | } |
---|
[593] | 540 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 541 | |
---|
| 542 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
| 543 | #if (ENCODER_FAST_MODE) |
---|
[442] | 544 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
[313] | 545 | #else |
---|
| 546 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 547 | #endif |
---|
| 548 | { |
---|
| 549 | // 2Nx2N, NxN |
---|
[442] | 550 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
[313] | 551 | { |
---|
[442] | 552 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) |
---|
[313] | 553 | { |
---|
[442] | 554 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
[593] | 555 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 556 | } |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | // 2NxN, Nx2N |
---|
| 560 | if(doNotBlockPu) |
---|
| 561 | { |
---|
| 562 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
[593] | 563 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 564 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 565 | { |
---|
| 566 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 567 | } |
---|
| 568 | } |
---|
| 569 | if(doNotBlockPu) |
---|
| 570 | { |
---|
| 571 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
[593] | 572 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 573 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
| 574 | { |
---|
| 575 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | #if 1 |
---|
| 580 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
| 581 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
| 582 | { |
---|
| 583 | #if AMP_ENC_SPEEDUP |
---|
| 584 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
| 585 | |
---|
| 586 | #if AMP_MRG |
---|
| 587 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
| 588 | |
---|
| 589 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
| 590 | #else |
---|
| 591 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
| 592 | #endif |
---|
| 593 | |
---|
| 594 | //! Do horizontal AMP |
---|
| 595 | if ( bTestAMP_Hor ) |
---|
| 596 | { |
---|
| 597 | if(doNotBlockPu) |
---|
| 598 | { |
---|
| 599 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
[593] | 600 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 601 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 602 | { |
---|
| 603 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | if(doNotBlockPu) |
---|
| 607 | { |
---|
| 608 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
[593] | 609 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 610 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 611 | { |
---|
| 612 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 613 | } |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | #if AMP_MRG |
---|
| 617 | else if ( bTestMergeAMP_Hor ) |
---|
| 618 | { |
---|
| 619 | if(doNotBlockPu) |
---|
| 620 | { |
---|
| 621 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
[593] | 622 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 623 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 624 | { |
---|
| 625 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 626 | } |
---|
| 627 | } |
---|
| 628 | if(doNotBlockPu) |
---|
| 629 | { |
---|
| 630 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
[593] | 631 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 632 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 633 | { |
---|
| 634 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 635 | } |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | #endif |
---|
| 639 | |
---|
| 640 | //! Do horizontal AMP |
---|
| 641 | if ( bTestAMP_Ver ) |
---|
| 642 | { |
---|
| 643 | if(doNotBlockPu) |
---|
| 644 | { |
---|
| 645 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
[593] | 646 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 647 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 648 | { |
---|
| 649 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | if(doNotBlockPu) |
---|
| 653 | { |
---|
| 654 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
[593] | 655 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 656 | } |
---|
| 657 | } |
---|
| 658 | #if AMP_MRG |
---|
| 659 | else if ( bTestMergeAMP_Ver ) |
---|
| 660 | { |
---|
| 661 | if(doNotBlockPu) |
---|
| 662 | { |
---|
| 663 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
[593] | 664 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 665 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 666 | { |
---|
| 667 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | if(doNotBlockPu) |
---|
| 671 | { |
---|
| 672 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
[593] | 673 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 674 | } |
---|
| 675 | } |
---|
| 676 | #endif |
---|
| 677 | |
---|
| 678 | #else |
---|
| 679 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
[593] | 680 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 681 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
[593] | 682 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 683 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
[593] | 684 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 685 | |
---|
| 686 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
[593] | 687 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 688 | |
---|
| 689 | #endif |
---|
| 690 | } |
---|
| 691 | #endif |
---|
| 692 | } |
---|
| 693 | |
---|
| 694 | // do normal intra modes |
---|
| 695 | // speedup for inter frames |
---|
| 696 | #if (ENCODER_FAST_MODE) |
---|
| 697 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
| 698 | !testInter || |
---|
| 699 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
| 700 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
| 701 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
| 702 | #else |
---|
| 703 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
| 704 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
| 705 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
| 706 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely |
---|
| 707 | #endif |
---|
| 708 | { |
---|
| 709 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
[593] | 710 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 711 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 712 | { |
---|
| 713 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
| 714 | { |
---|
| 715 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
[593] | 716 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 717 | } |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | // test PCM |
---|
| 722 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
| 723 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
| 724 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
| 725 | { |
---|
| 726 | UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2; |
---|
| 727 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
| 728 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
| 729 | { |
---|
| 730 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
[593] | 731 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 732 | } |
---|
| 733 | } |
---|
| 734 | #if (ENCODER_FAST_MODE) |
---|
[494] | 735 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 736 | if(pcPic->getLayerId() > 0 && !m_disableILP) |
---|
| 737 | #else |
---|
[313] | 738 | if(pcPic->getLayerId() > 0) |
---|
[494] | 739 | #endif |
---|
[313] | 740 | { |
---|
| 741 | for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++) |
---|
| 742 | { |
---|
| 743 | xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer)); |
---|
[593] | 744 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 745 | } |
---|
| 746 | } |
---|
| 747 | #endif |
---|
| 748 | |
---|
[593] | 749 | if (bIsLosslessMode) |
---|
[313] | 750 | { |
---|
| 751 | iQP = iMinQP; |
---|
| 752 | } |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | m_pcEntropyCoder->resetBits(); |
---|
| 757 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
| 758 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
| 759 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 760 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
| 761 | |
---|
| 762 | // Early CU determination |
---|
| 763 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
| 764 | { |
---|
| 765 | bSubBranch = false; |
---|
| 766 | } |
---|
| 767 | else |
---|
| 768 | { |
---|
| 769 | bSubBranch = true; |
---|
| 770 | } |
---|
[540] | 771 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 772 | } |
---|
| 773 | #endif |
---|
[313] | 774 | } |
---|
| 775 | else if(!(bSliceEnd && bInsidePicture)) |
---|
| 776 | { |
---|
| 777 | bBoundary = true; |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | // copy orginal YUV samples to PCM buffer |
---|
| 781 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
| 782 | { |
---|
| 783 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
| 784 | } |
---|
| 785 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 786 | { |
---|
| 787 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[442] | 788 | #if REPN_FORMAT_IN_VPS |
---|
| 789 | iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 790 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
| 791 | #else |
---|
[313] | 792 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 793 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
[593] | 794 | #endif |
---|
[313] | 795 | } |
---|
| 796 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 797 | { |
---|
| 798 | iMinQP = iBaseQP; |
---|
| 799 | iMaxQP = iBaseQP; |
---|
| 800 | } |
---|
| 801 | else |
---|
| 802 | { |
---|
| 803 | Int iStartQP; |
---|
| 804 | if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
| 805 | { |
---|
| 806 | iStartQP = rpcTempCU->getQP(0); |
---|
| 807 | } |
---|
| 808 | else |
---|
| 809 | { |
---|
| 810 | UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
| 811 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
| 812 | } |
---|
| 813 | iMinQP = iStartQP; |
---|
| 814 | iMaxQP = iStartQP; |
---|
| 815 | } |
---|
| 816 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 817 | { |
---|
| 818 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 819 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 820 | } |
---|
[593] | 821 | |
---|
| 822 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
[313] | 823 | { |
---|
[593] | 824 | iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here. |
---|
[313] | 825 | } |
---|
| 826 | |
---|
[593] | 827 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 828 | { |
---|
| 829 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
| 830 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
| 831 | |
---|
[313] | 832 | // further split |
---|
[442] | 833 | if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
[313] | 834 | { |
---|
| 835 | UChar uhNextDepth = uiDepth+1; |
---|
| 836 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
| 837 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
| 838 | |
---|
| 839 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
| 840 | { |
---|
| 841 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 842 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 843 | |
---|
| 844 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[442] | 845 | #if REPN_FORMAT_IN_VPS |
---|
| 846 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 847 | #else |
---|
[313] | 848 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[442] | 849 | #endif |
---|
[313] | 850 | { |
---|
[593] | 851 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
[313] | 852 | { |
---|
[593] | 853 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
[313] | 854 | } |
---|
[593] | 855 | else |
---|
| 856 | { |
---|
| 857 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
| 858 | } |
---|
[313] | 859 | |
---|
| 860 | #if AMP_ENC_SPEEDUP |
---|
| 861 | if ( rpcBestCU->isIntra(0) ) |
---|
| 862 | { |
---|
| 863 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
| 864 | } |
---|
| 865 | else |
---|
| 866 | { |
---|
| 867 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
| 868 | } |
---|
| 869 | #else |
---|
| 870 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
| 871 | #endif |
---|
| 872 | |
---|
| 873 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
| 874 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
| 875 | } |
---|
| 876 | else if (bInSlice) |
---|
| 877 | { |
---|
| 878 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
| 879 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
| 880 | } |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | if( !bBoundary ) |
---|
| 884 | { |
---|
| 885 | m_pcEntropyCoder->resetBits(); |
---|
| 886 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
| 887 | |
---|
| 888 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
[593] | 889 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 890 | } |
---|
| 891 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 892 | |
---|
| 893 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 894 | { |
---|
| 895 | Bool hasResidual = false; |
---|
| 896 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
| 897 | { |
---|
| 898 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && |
---|
| 899 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
| 900 | { |
---|
| 901 | hasResidual = true; |
---|
| 902 | break; |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | |
---|
| 906 | UInt uiTargetPartIdx; |
---|
| 907 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() ) |
---|
| 908 | { |
---|
| 909 | uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
| 910 | } |
---|
| 911 | else |
---|
| 912 | { |
---|
| 913 | uiTargetPartIdx = 0; |
---|
| 914 | } |
---|
| 915 | if ( hasResidual ) |
---|
| 916 | { |
---|
| 917 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 918 | m_pcEntropyCoder->resetBits(); |
---|
| 919 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
| 920 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[593] | 921 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 922 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 923 | #endif |
---|
| 924 | |
---|
| 925 | Bool foundNonZeroCbf = false; |
---|
| 926 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf ); |
---|
| 927 | assert( foundNonZeroCbf ); |
---|
| 928 | } |
---|
| 929 | else |
---|
| 930 | { |
---|
| 931 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | |
---|
[593] | 935 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 936 | |
---|
[313] | 937 | Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
| 938 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
| 939 | Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
| 940 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); |
---|
| 941 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
| 942 | { |
---|
| 943 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
| 944 | } |
---|
| 945 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
| 946 | } // with sub partitioned prediction. |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
| 950 | |
---|
| 951 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
| 952 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
| 953 | { |
---|
| 954 | return; |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | // Assert if Best prediction mode is NONE |
---|
| 958 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
| 959 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
| 960 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
| 961 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
| 962 | } |
---|
| 963 | |
---|
| 964 | /** finish encoding a cu and handle end-of-slice conditions |
---|
| 965 | * \param pcCU |
---|
| 966 | * \param uiAbsPartIdx |
---|
| 967 | * \param uiDepth |
---|
| 968 | * \returns Void |
---|
| 969 | */ |
---|
| 970 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 971 | { |
---|
| 972 | TComPic* pcPic = pcCU->getPic(); |
---|
| 973 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 974 | |
---|
| 975 | //Calculate end address |
---|
| 976 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
| 977 | |
---|
| 978 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 979 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
| 980 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 981 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[442] | 982 | #if REPN_FORMAT_IN_VPS |
---|
| 983 | UInt uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
| 984 | UInt uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
| 985 | #else |
---|
[313] | 986 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 987 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
[442] | 988 | #endif |
---|
[313] | 989 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
| 990 | { |
---|
| 991 | uiInternalAddress--; |
---|
| 992 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 993 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 994 | } |
---|
| 995 | uiInternalAddress++; |
---|
| 996 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
| 997 | { |
---|
| 998 | uiInternalAddress = 0; |
---|
| 999 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 1000 | } |
---|
| 1001 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 1002 | |
---|
| 1003 | // Encode slice finish |
---|
| 1004 | Bool bTerminateSlice = false; |
---|
| 1005 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
| 1006 | { |
---|
| 1007 | bTerminateSlice = true; |
---|
| 1008 | } |
---|
| 1009 | UInt uiGranularityWidth = g_uiMaxCUWidth; |
---|
| 1010 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1011 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1012 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
| 1013 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
| 1014 | |
---|
| 1015 | if(granularityBoundary) |
---|
| 1016 | { |
---|
| 1017 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
| 1018 | if (!bTerminateSlice) |
---|
| 1019 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | Int numberOfWrittenBits = 0; |
---|
| 1023 | if (m_pcBitCounter) |
---|
| 1024 | { |
---|
| 1025 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
| 1029 | UInt iGranularitySize = pcCU->getPic()->getNumPartInCU(); |
---|
| 1030 | Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
| 1031 | if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
| 1032 | { |
---|
| 1033 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
| 1034 | } |
---|
| 1035 | // Set slice end parameter |
---|
| 1036 | if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
| 1037 | { |
---|
| 1038 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
| 1039 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
| 1040 | return; |
---|
| 1041 | } |
---|
| 1042 | // Set dependent slice end parameter |
---|
| 1043 | if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) |
---|
| 1044 | { |
---|
| 1045 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
| 1046 | return; |
---|
| 1047 | } |
---|
| 1048 | if(granularityBoundary) |
---|
| 1049 | { |
---|
| 1050 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
| 1051 | pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits); |
---|
| 1052 | if (m_pcBitCounter) |
---|
| 1053 | { |
---|
| 1054 | m_pcEntropyCoder->resetBits(); |
---|
| 1055 | } |
---|
| 1056 | } |
---|
| 1057 | } |
---|
| 1058 | |
---|
| 1059 | /** Compute QP for each CU |
---|
| 1060 | * \param pcCU Target CU |
---|
| 1061 | * \param uiDepth CU depth |
---|
| 1062 | * \returns quantization parameter |
---|
| 1063 | */ |
---|
| 1064 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
| 1065 | { |
---|
| 1066 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
| 1067 | Int iQpOffset = 0; |
---|
| 1068 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
| 1069 | { |
---|
| 1070 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
| 1071 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
| 1072 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
| 1073 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
| 1074 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
| 1075 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
| 1076 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
| 1077 | |
---|
| 1078 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
| 1079 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
| 1080 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
| 1081 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
| 1082 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
| 1083 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
| 1084 | } |
---|
[442] | 1085 | #if REPN_FORMAT_IN_VPS |
---|
| 1086 | return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
| 1087 | #else |
---|
[313] | 1088 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
[442] | 1089 | #endif |
---|
[313] | 1090 | } |
---|
| 1091 | |
---|
| 1092 | /** encode a CU block recursively |
---|
| 1093 | * \param pcCU |
---|
| 1094 | * \param uiAbsPartIdx |
---|
| 1095 | * \param uiDepth |
---|
| 1096 | * \returns Void |
---|
| 1097 | */ |
---|
| 1098 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1099 | { |
---|
| 1100 | TComPic* pcPic = pcCU->getPic(); |
---|
| 1101 | |
---|
| 1102 | Bool bBoundary = false; |
---|
| 1103 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1104 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 1105 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1106 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
| 1107 | |
---|
| 1108 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
[540] | 1109 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1110 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
| 1111 | { |
---|
| 1112 | pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth); |
---|
| 1113 | } |
---|
| 1114 | #endif |
---|
[313] | 1115 | // If slice start is within this cu... |
---|
| 1116 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1117 | pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
| 1118 | // We need to split, so don't try these modes. |
---|
[442] | 1119 | #if REPN_FORMAT_IN_VPS |
---|
| 1120 | if(!bSliceStart&&( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1121 | #else |
---|
[313] | 1122 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[442] | 1123 | #endif |
---|
[313] | 1124 | { |
---|
| 1125 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1126 | } |
---|
| 1127 | else |
---|
| 1128 | { |
---|
| 1129 | bBoundary = true; |
---|
| 1130 | } |
---|
| 1131 | |
---|
| 1132 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
| 1133 | { |
---|
| 1134 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
| 1135 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1136 | { |
---|
| 1137 | setdQPFlag(true); |
---|
| 1138 | } |
---|
| 1139 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1140 | { |
---|
| 1141 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1142 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1143 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[442] | 1144 | #if REPN_FORMAT_IN_VPS |
---|
| 1145 | if(bInSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1146 | #else |
---|
[313] | 1147 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[442] | 1148 | #endif |
---|
[313] | 1149 | { |
---|
| 1150 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
| 1151 | } |
---|
| 1152 | } |
---|
| 1153 | return; |
---|
| 1154 | } |
---|
| 1155 | |
---|
| 1156 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1157 | { |
---|
| 1158 | setdQPFlag(true); |
---|
| 1159 | } |
---|
| 1160 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1161 | { |
---|
| 1162 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 1163 | } |
---|
| 1164 | if( !pcCU->getSlice()->isIntra() ) |
---|
| 1165 | { |
---|
| 1166 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 1170 | { |
---|
| 1171 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
| 1172 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1173 | return; |
---|
| 1174 | } |
---|
| 1175 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
| 1176 | |
---|
| 1177 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1178 | |
---|
| 1179 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
| 1180 | { |
---|
| 1181 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
| 1182 | |
---|
| 1183 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
| 1184 | { |
---|
| 1185 | // Encode slice finish |
---|
| 1186 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1187 | return; |
---|
| 1188 | } |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
| 1192 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
| 1193 | |
---|
| 1194 | // Encode Coefficients |
---|
| 1195 | Bool bCodeDQP = getdQPFlag(); |
---|
| 1196 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
| 1197 | setdQPFlag( bCodeDQP ); |
---|
| 1198 | |
---|
| 1199 | // --- write terminating bit --- |
---|
| 1200 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1201 | } |
---|
| 1202 | |
---|
| 1203 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
| 1204 | { |
---|
| 1205 | Int k, i, j, jj; |
---|
| 1206 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
| 1207 | |
---|
| 1208 | for( k = 0; k < 64; k += 8 ) |
---|
| 1209 | { |
---|
| 1210 | diff[k+0] = piOrg[0] ; |
---|
| 1211 | diff[k+1] = piOrg[1] ; |
---|
| 1212 | diff[k+2] = piOrg[2] ; |
---|
| 1213 | diff[k+3] = piOrg[3] ; |
---|
| 1214 | diff[k+4] = piOrg[4] ; |
---|
| 1215 | diff[k+5] = piOrg[5] ; |
---|
| 1216 | diff[k+6] = piOrg[6] ; |
---|
| 1217 | diff[k+7] = piOrg[7] ; |
---|
| 1218 | |
---|
| 1219 | piOrg += iStrideOrg; |
---|
| 1220 | } |
---|
| 1221 | |
---|
| 1222 | //horizontal |
---|
| 1223 | for (j=0; j < 8; j++) |
---|
| 1224 | { |
---|
| 1225 | jj = j << 3; |
---|
| 1226 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1227 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1228 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1229 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1230 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1231 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1232 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1233 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
| 1234 | |
---|
| 1235 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1236 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1237 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1238 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1239 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1240 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1241 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1242 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
| 1243 | |
---|
| 1244 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1245 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1246 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1247 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1248 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1249 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1250 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1251 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1252 | } |
---|
| 1253 | |
---|
| 1254 | //vertical |
---|
| 1255 | for (i=0; i < 8; i++) |
---|
| 1256 | { |
---|
| 1257 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1258 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1259 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1260 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1261 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1262 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1263 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1264 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
| 1265 | |
---|
| 1266 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1267 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1268 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1269 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1270 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1271 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1272 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1273 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
| 1274 | |
---|
| 1275 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1276 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1277 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1278 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1279 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1280 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1281 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1282 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1283 | } |
---|
| 1284 | |
---|
| 1285 | for (i = 0; i < 8; i++) |
---|
| 1286 | { |
---|
| 1287 | for (j = 0; j < 8; j++) |
---|
| 1288 | { |
---|
| 1289 | iSumHad += abs(m2[i][j]); |
---|
| 1290 | } |
---|
| 1291 | } |
---|
| 1292 | iSumHad -= abs(m2[0][0]); |
---|
| 1293 | iSumHad =(iSumHad+2)>>2; |
---|
| 1294 | return(iSumHad); |
---|
| 1295 | } |
---|
| 1296 | |
---|
| 1297 | Int TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height) |
---|
| 1298 | { |
---|
| 1299 | Int xBl, yBl; |
---|
| 1300 | const Int iBlkSize = 8; |
---|
| 1301 | |
---|
| 1302 | Pel* pOrgInit = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0); |
---|
| 1303 | Int iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride(); |
---|
| 1304 | Pel *pOrg; |
---|
| 1305 | |
---|
| 1306 | Int iSumHad = 0; |
---|
| 1307 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
| 1308 | { |
---|
| 1309 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
| 1310 | { |
---|
| 1311 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
| 1312 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
| 1313 | } |
---|
| 1314 | } |
---|
| 1315 | return(iSumHad); |
---|
| 1316 | } |
---|
| 1317 | |
---|
| 1318 | /** check RD costs for a CU block encoded with merge |
---|
| 1319 | * \param rpcBestCU |
---|
| 1320 | * \param rpcTempCU |
---|
| 1321 | * \returns Void |
---|
| 1322 | */ |
---|
[540] | 1323 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1324 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode, Bool bUseSkip ) |
---|
| 1325 | #else |
---|
[313] | 1326 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode ) |
---|
[540] | 1327 | #endif |
---|
[313] | 1328 | { |
---|
| 1329 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
| 1330 | TComMvField cMvFieldNeighbours[ 2 * MRG_MAX_NUM_CANDS ]; // double length for mv of both lists |
---|
| 1331 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
| 1332 | Int numValidMergeCand = 0; |
---|
[593] | 1333 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
[313] | 1334 | |
---|
| 1335 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
| 1336 | { |
---|
| 1337 | uhInterDirNeighbours[ui] = 0; |
---|
| 1338 | } |
---|
| 1339 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1340 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1341 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
| 1342 | |
---|
| 1343 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
| 1344 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
| 1345 | { |
---|
| 1346 | mergeCandBuffer[ui] = 0; |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | Bool bestIsSkip = false; |
---|
| 1350 | |
---|
| 1351 | UInt iteration; |
---|
| 1352 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
| 1353 | { |
---|
| 1354 | iteration = 1; |
---|
| 1355 | } |
---|
| 1356 | else |
---|
| 1357 | { |
---|
| 1358 | iteration = 2; |
---|
| 1359 | } |
---|
| 1360 | |
---|
[540] | 1361 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1362 | for( UInt uiNoResidual = bUseSkip?1:0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
| 1363 | #else |
---|
[313] | 1364 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
[540] | 1365 | #endif |
---|
[313] | 1366 | { |
---|
| 1367 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
| 1368 | { |
---|
| 1369 | #if REF_IDX_ME_ZEROMV |
---|
| 1370 | Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]); |
---|
| 1371 | if(bZeroMVILR) |
---|
| 1372 | { |
---|
| 1373 | #endif |
---|
[494] | 1374 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1375 | if (!(rpcTempCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP)) |
---|
| 1376 | { |
---|
| 1377 | #endif |
---|
[313] | 1378 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
| 1379 | { |
---|
| 1380 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
| 1381 | { |
---|
| 1382 | // set MC parameters |
---|
| 1383 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
[593] | 1384 | rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); |
---|
[313] | 1385 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1386 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1387 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1388 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1389 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1390 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1391 | |
---|
| 1392 | // do MC |
---|
| 1393 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
| 1394 | // estimate residual and encode everything |
---|
| 1395 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
| 1396 | m_ppcOrigYuv [uhDepth], |
---|
| 1397 | m_ppcPredYuvTemp[uhDepth], |
---|
| 1398 | m_ppcResiYuvTemp[uhDepth], |
---|
| 1399 | m_ppcResiYuvBest[uhDepth], |
---|
| 1400 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 1401 | (uiNoResidual? true:false)); |
---|
| 1402 | |
---|
| 1403 | |
---|
| 1404 | if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 ) |
---|
| 1405 | { |
---|
| 1406 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
| 1407 | mergeCandBuffer[uiMergeCand] = 1; |
---|
| 1408 | } |
---|
| 1409 | |
---|
| 1410 | rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); |
---|
| 1411 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
| 1412 | xCheckDQP( rpcTempCU ); |
---|
| 1413 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
[593] | 1414 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
[313] | 1415 | |
---|
| 1416 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
| 1417 | { |
---|
| 1418 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
| 1419 | } |
---|
| 1420 | } |
---|
[494] | 1421 | } |
---|
| 1422 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1423 | } |
---|
| 1424 | #endif |
---|
[313] | 1425 | #if REF_IDX_ME_ZEROMV |
---|
[494] | 1426 | } |
---|
[313] | 1427 | #endif |
---|
| 1428 | } |
---|
| 1429 | |
---|
| 1430 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 1431 | { |
---|
| 1432 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
| 1433 | { |
---|
| 1434 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
| 1435 | { |
---|
| 1436 | *earlyDetectionSkipMode = true; |
---|
| 1437 | } |
---|
| 1438 | else |
---|
| 1439 | { |
---|
| 1440 | Int absoulte_MV=0; |
---|
| 1441 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 1442 | { |
---|
| 1443 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 1444 | { |
---|
| 1445 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
| 1446 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
| 1447 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
| 1448 | absoulte_MV+=iHor+iVer; |
---|
| 1449 | } |
---|
| 1450 | } |
---|
| 1451 | |
---|
| 1452 | if(absoulte_MV == 0) |
---|
| 1453 | { |
---|
| 1454 | *earlyDetectionSkipMode = true; |
---|
| 1455 | } |
---|
| 1456 | } |
---|
| 1457 | } |
---|
| 1458 | } |
---|
| 1459 | } |
---|
| 1460 | } |
---|
| 1461 | |
---|
| 1462 | |
---|
| 1463 | #if AMP_MRG |
---|
| 1464 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
| 1465 | #else |
---|
| 1466 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
| 1467 | #endif |
---|
| 1468 | { |
---|
| 1469 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1470 | |
---|
| 1471 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 1472 | |
---|
| 1473 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1474 | |
---|
| 1475 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
| 1476 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 1477 | |
---|
| 1478 | #if AMP_MRG |
---|
| 1479 | rpcTempCU->setMergeAMP (true); |
---|
| 1480 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
| 1481 | #else |
---|
| 1482 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
| 1483 | #endif |
---|
| 1484 | |
---|
| 1485 | #if AMP_MRG |
---|
| 1486 | if ( !rpcTempCU->getMergeAMP() ) |
---|
| 1487 | { |
---|
| 1488 | return; |
---|
| 1489 | } |
---|
| 1490 | #endif |
---|
| 1491 | |
---|
| 1492 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 1493 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1494 | |
---|
| 1495 | xCheckDQP( rpcTempCU ); |
---|
| 1496 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1497 | } |
---|
| 1498 | |
---|
| 1499 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
| 1500 | { |
---|
| 1501 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1502 | |
---|
| 1503 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1504 | |
---|
| 1505 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
| 1506 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 1507 | |
---|
| 1508 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
| 1509 | UInt uiPreCalcDistC = 0; |
---|
| 1510 | if( !bSeparateLumaChroma ) |
---|
| 1511 | { |
---|
| 1512 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
| 1513 | } |
---|
| 1514 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
| 1515 | |
---|
| 1516 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
| 1517 | |
---|
| 1518 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
| 1519 | |
---|
| 1520 | m_pcEntropyCoder->resetBits(); |
---|
| 1521 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1522 | { |
---|
| 1523 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1524 | } |
---|
| 1525 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1526 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
| 1527 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
| 1528 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
| 1529 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
| 1530 | |
---|
| 1531 | // Encode Coefficients |
---|
| 1532 | Bool bCodeDQP = getdQPFlag(); |
---|
| 1533 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
| 1534 | setdQPFlag( bCodeDQP ); |
---|
| 1535 | |
---|
[593] | 1536 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[313] | 1537 | |
---|
| 1538 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[593] | 1539 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1540 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1541 | |
---|
| 1542 | xCheckDQP( rpcTempCU ); |
---|
| 1543 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
| 1544 | } |
---|
| 1545 | |
---|
| 1546 | /** Check R-D costs for a CU with PCM mode. |
---|
| 1547 | * \param rpcBestCU pointer to best mode CU data structure |
---|
| 1548 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
| 1549 | * \returns Void |
---|
| 1550 | * |
---|
| 1551 | * \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. |
---|
| 1552 | */ |
---|
| 1553 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
| 1554 | { |
---|
| 1555 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1556 | |
---|
| 1557 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1558 | |
---|
| 1559 | rpcTempCU->setIPCMFlag(0, true); |
---|
| 1560 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
| 1561 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 1562 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 1563 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
| 1564 | |
---|
| 1565 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
| 1566 | |
---|
[593] | 1567 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
[313] | 1568 | |
---|
| 1569 | m_pcEntropyCoder->resetBits(); |
---|
| 1570 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1571 | { |
---|
| 1572 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1573 | } |
---|
| 1574 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1575 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
| 1576 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
| 1577 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
| 1578 | |
---|
[593] | 1579 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[313] | 1580 | |
---|
| 1581 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[593] | 1582 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1583 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1584 | |
---|
| 1585 | xCheckDQP( rpcTempCU ); |
---|
| 1586 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
| 1587 | } |
---|
| 1588 | |
---|
| 1589 | /** check whether current try is the best with identifying the depth of current try |
---|
| 1590 | * \param rpcBestCU |
---|
| 1591 | * \param rpcTempCU |
---|
| 1592 | * \returns Void |
---|
| 1593 | */ |
---|
| 1594 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
| 1595 | { |
---|
| 1596 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
| 1597 | { |
---|
| 1598 | TComYuv* pcYuv; |
---|
| 1599 | // Change Information data |
---|
| 1600 | TComDataCU* pcCU = rpcBestCU; |
---|
| 1601 | rpcBestCU = rpcTempCU; |
---|
| 1602 | rpcTempCU = pcCU; |
---|
| 1603 | |
---|
| 1604 | // Change Prediction data |
---|
| 1605 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
| 1606 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
| 1607 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
| 1608 | |
---|
| 1609 | // Change Reconstruction data |
---|
| 1610 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
| 1611 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
| 1612 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
| 1613 | |
---|
| 1614 | pcYuv = NULL; |
---|
| 1615 | pcCU = NULL; |
---|
| 1616 | |
---|
[593] | 1617 | // store temp best CI for next CU coding |
---|
| 1618 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
[313] | 1619 | } |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
| 1623 | { |
---|
| 1624 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
| 1625 | |
---|
| 1626 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 1627 | { |
---|
| 1628 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
| 1629 | { |
---|
| 1630 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 1631 | m_pcEntropyCoder->resetBits(); |
---|
| 1632 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
| 1633 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[593] | 1634 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1635 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
| 1636 | #endif |
---|
| 1637 | } |
---|
| 1638 | else |
---|
| 1639 | { |
---|
| 1640 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
| 1641 | } |
---|
| 1642 | } |
---|
| 1643 | } |
---|
| 1644 | |
---|
| 1645 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
| 1646 | { |
---|
| 1647 | pDst->iN = pSrc->iN; |
---|
| 1648 | for (Int i = 0; i < pSrc->iN; i++) |
---|
| 1649 | { |
---|
| 1650 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
| 1651 | } |
---|
| 1652 | } |
---|
| 1653 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
| 1654 | { |
---|
| 1655 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 1656 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
| 1657 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1658 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1659 | pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
| 1660 | Bool bSliceEnd = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1661 | pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
[442] | 1662 | #if REPN_FORMAT_IN_VPS |
---|
| 1663 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1664 | #else |
---|
[313] | 1665 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[442] | 1666 | #endif |
---|
[313] | 1667 | { |
---|
| 1668 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
| 1669 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
| 1670 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
| 1671 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1672 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1673 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
| 1674 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
| 1675 | } |
---|
| 1676 | else |
---|
| 1677 | { |
---|
| 1678 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
| 1679 | |
---|
| 1680 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1681 | { |
---|
| 1682 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
| 1683 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
| 1684 | |
---|
| 1685 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && |
---|
| 1686 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[442] | 1687 | #if REPN_FORMAT_IN_VPS |
---|
| 1688 | if(bInSlice&&( uiSubCULPelX < pcSlice->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getPicHeightInLumaSamples() ) ) |
---|
| 1689 | #else |
---|
[313] | 1690 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[442] | 1691 | #endif |
---|
[313] | 1692 | { |
---|
| 1693 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
| 1694 | } |
---|
| 1695 | } |
---|
| 1696 | } |
---|
| 1697 | } |
---|
| 1698 | |
---|
| 1699 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
| 1700 | { |
---|
| 1701 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
| 1702 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
| 1703 | } |
---|
| 1704 | |
---|
| 1705 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
| 1706 | * \param pcCU pointer to current CU |
---|
| 1707 | * \param pcOrgYuv pointer to original sample array |
---|
| 1708 | * \returns Void |
---|
| 1709 | */ |
---|
| 1710 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
| 1711 | { |
---|
| 1712 | |
---|
| 1713 | UInt width = pCU->getWidth(0); |
---|
| 1714 | UInt height = pCU->getHeight(0); |
---|
| 1715 | |
---|
| 1716 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
| 1717 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
| 1718 | UInt srcStride = pOrgYuv->getStride(); |
---|
| 1719 | |
---|
| 1720 | for(Int y = 0; y < height; y++ ) |
---|
| 1721 | { |
---|
| 1722 | for(Int x = 0; x < width; x++ ) |
---|
| 1723 | { |
---|
| 1724 | pDstY[x] = pSrcY[x]; |
---|
| 1725 | } |
---|
| 1726 | pDstY += width; |
---|
| 1727 | pSrcY += srcStride; |
---|
| 1728 | } |
---|
| 1729 | |
---|
| 1730 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
| 1731 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
| 1732 | |
---|
| 1733 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
| 1734 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
| 1735 | |
---|
| 1736 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
| 1737 | UInt heightC = height >> 1; |
---|
| 1738 | UInt widthC = width >> 1; |
---|
| 1739 | |
---|
| 1740 | for(Int y = 0; y < heightC; y++ ) |
---|
| 1741 | { |
---|
| 1742 | for(Int x = 0; x < widthC; x++ ) |
---|
| 1743 | { |
---|
| 1744 | pDstCb[x] = pSrcCb[x]; |
---|
| 1745 | pDstCr[x] = pSrcCr[x]; |
---|
| 1746 | } |
---|
| 1747 | pDstCb += widthC; |
---|
| 1748 | pDstCr += widthC; |
---|
| 1749 | pSrcCb += srcStrideC; |
---|
| 1750 | pSrcCr += srcStrideC; |
---|
| 1751 | } |
---|
| 1752 | } |
---|
| 1753 | |
---|
| 1754 | #if ADAPTIVE_QP_SELECTION |
---|
| 1755 | /** Collect ARL statistics from one block |
---|
| 1756 | */ |
---|
| 1757 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
| 1758 | { |
---|
| 1759 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
| 1760 | { |
---|
| 1761 | Int u = abs( rpcCoeff[ n ] ); |
---|
| 1762 | Int absc = rpcArlCoeff[ n ]; |
---|
| 1763 | |
---|
| 1764 | if( u != 0 ) |
---|
| 1765 | { |
---|
| 1766 | if( u < LEVEL_RANGE ) |
---|
| 1767 | { |
---|
| 1768 | cSum[ u ] += ( Double )absc; |
---|
| 1769 | numSamples[ u ]++; |
---|
| 1770 | } |
---|
| 1771 | else |
---|
| 1772 | { |
---|
| 1773 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
| 1774 | numSamples[ LEVEL_RANGE ]++; |
---|
| 1775 | } |
---|
| 1776 | } |
---|
| 1777 | } |
---|
| 1778 | |
---|
| 1779 | return 0; |
---|
| 1780 | } |
---|
| 1781 | |
---|
[593] | 1782 | /** Collect ARL statistics from one LCU |
---|
| 1783 | * \param pcCU |
---|
| 1784 | */ |
---|
| 1785 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
| 1786 | { |
---|
| 1787 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
| 1788 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
| 1789 | |
---|
| 1790 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
| 1791 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
| 1792 | |
---|
| 1793 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
| 1794 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
| 1795 | |
---|
| 1796 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
| 1797 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
| 1798 | |
---|
| 1799 | // Collect stats to cSum[][] and numSamples[][] |
---|
| 1800 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
| 1801 | { |
---|
| 1802 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
| 1803 | |
---|
| 1804 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
| 1805 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
| 1806 | { |
---|
| 1807 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
| 1808 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
| 1809 | |
---|
| 1810 | pCoeffY += uiMinNumCoeffInCU; |
---|
| 1811 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
| 1812 | } |
---|
| 1813 | |
---|
| 1814 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
| 1815 | { |
---|
| 1816 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
| 1817 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
| 1818 | } |
---|
| 1819 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
| 1820 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
| 1821 | } |
---|
| 1822 | #endif |
---|
| 1823 | |
---|
| 1824 | #if SVC_EXTENSION |
---|
[494] | 1825 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1826 | Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU ) |
---|
| 1827 | { |
---|
| 1828 | Bool disableILP = false; |
---|
| 1829 | |
---|
| 1830 | if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0) |
---|
| 1831 | { |
---|
| 1832 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 2) |
---|
| 1833 | { |
---|
| 1834 | disableILP = true; |
---|
| 1835 | } |
---|
| 1836 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getAddr()) == 1) |
---|
| 1837 | { |
---|
| 1838 | Int currCUaddr = rpcCU->getAddr(); |
---|
| 1839 | Int frameWitdhInCU = rpcCU->getPic()->getPicSym()->getFrameWidthInCU(); |
---|
| 1840 | Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCU(); |
---|
| 1841 | Bool leftCUExists = (currCUaddr % frameWitdhInCU) > 0; |
---|
| 1842 | Bool aboveCUExists = (currCUaddr / frameWitdhInCU) > 0; |
---|
| 1843 | Bool rightCUExists = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1); |
---|
| 1844 | Bool belowCUExists = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1); |
---|
| 1845 | Int currTileSetIdx = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr); |
---|
| 1846 | // Check if CU is at tile set boundary |
---|
| 1847 | if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) || |
---|
| 1848 | (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) || |
---|
| 1849 | (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) || |
---|
| 1850 | (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) || |
---|
| 1851 | (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) || |
---|
| 1852 | (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) || |
---|
| 1853 | (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) || |
---|
| 1854 | (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) ) |
---|
| 1855 | { |
---|
| 1856 | disableILP = true; // Disable ILP in tile set boundary CU |
---|
| 1857 | } |
---|
| 1858 | } |
---|
| 1859 | } |
---|
| 1860 | |
---|
| 1861 | return disableILP; |
---|
| 1862 | } |
---|
| 1863 | |
---|
| 1864 | Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU ) |
---|
| 1865 | { |
---|
| 1866 | if (rpcCU->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getAddr()) >= 0 && |
---|
| 1867 | m_disableILP) |
---|
| 1868 | { |
---|
| 1869 | UInt numPartitions = rpcCU->getPic()->getNumPartInCU(); |
---|
| 1870 | for (UInt i = 0; i < numPartitions; i++) |
---|
| 1871 | { |
---|
| 1872 | if (!rpcCU->isIntra(i)) |
---|
| 1873 | { |
---|
| 1874 | for (UInt refList = 0; refList < 2; refList++) |
---|
| 1875 | { |
---|
| 1876 | if (rpcCU->getInterDir(i) & (1<<refList)) |
---|
| 1877 | { |
---|
| 1878 | TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList)); |
---|
| 1879 | if (mvField->getRefIdx(i) >= 0) |
---|
| 1880 | { |
---|
| 1881 | assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getLayerId()))); |
---|
| 1882 | } |
---|
| 1883 | } |
---|
| 1884 | } |
---|
| 1885 | } |
---|
| 1886 | } |
---|
| 1887 | } |
---|
| 1888 | } |
---|
| 1889 | #endif |
---|
| 1890 | |
---|
[313] | 1891 | #if (ENCODER_FAST_MODE) |
---|
| 1892 | Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId) |
---|
| 1893 | { |
---|
| 1894 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1895 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 1896 | #if SKIP_FLAG |
---|
| 1897 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1898 | #endif |
---|
| 1899 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N |
---|
| 1900 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
[593] | 1901 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagForceValue(), 0, uhDepth ); |
---|
[313] | 1902 | Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId ); |
---|
| 1903 | if(!exitILR) |
---|
| 1904 | { |
---|
| 1905 | return; |
---|
| 1906 | } |
---|
| 1907 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 1908 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1909 | xCheckDQP( rpcTempCU ); |
---|
| 1910 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1911 | return; |
---|
| 1912 | } |
---|
| 1913 | #endif |
---|
[593] | 1914 | #endif //SVC_EXTENSION |
---|
[313] | 1915 | //! \} |
---|