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