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