[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncCu.cpp |
---|
| 35 | \brief Coding Unit (CU) encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <stdio.h> |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncCu.h" |
---|
| 41 | #include "TEncAnalyze.h" |
---|
[1029] | 42 | #include "TLibCommon/Debug.h" |
---|
[313] | 43 | |
---|
| 44 | #include <cmath> |
---|
| 45 | #include <algorithm> |
---|
| 46 | using namespace std; |
---|
| 47 | |
---|
[1029] | 48 | |
---|
[313] | 49 | //! \ingroup TLibEncoder |
---|
| 50 | //! \{ |
---|
| 51 | |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | // Constructor / destructor / create / destroy |
---|
| 54 | // ==================================================================================================================== |
---|
| 55 | |
---|
| 56 | /** |
---|
[1260] | 57 | \param uhTotalDepth total number of allowable depth |
---|
[313] | 58 | \param uiMaxWidth largest CU width |
---|
| 59 | \param uiMaxHeight largest CU height |
---|
[1260] | 60 | \param chromaFormat chroma format |
---|
[313] | 61 | */ |
---|
[1029] | 62 | Void TEncCu::create(UChar uhTotalDepth, UInt uiMaxWidth, UInt uiMaxHeight, ChromaFormat chromaFormat) |
---|
[313] | 63 | { |
---|
| 64 | Int i; |
---|
[1029] | 65 | |
---|
[313] | 66 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
| 67 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 68 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
[1029] | 69 | |
---|
[313] | 70 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 71 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 72 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 73 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 74 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 75 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 76 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
[1029] | 77 | |
---|
[313] | 78 | UInt uiNumPartitions; |
---|
| 79 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 80 | { |
---|
| 81 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
| 82 | UInt uiWidth = uiMaxWidth >> i; |
---|
| 83 | UInt uiHeight = uiMaxHeight >> i; |
---|
[1029] | 84 | |
---|
| 85 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 86 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( chromaFormat, uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 87 | |
---|
| 88 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 89 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 90 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 91 | |
---|
| 92 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 93 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 94 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight, chromaFormat); |
---|
| 95 | |
---|
| 96 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight, chromaFormat); |
---|
[313] | 97 | } |
---|
| 98 | |
---|
[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 | |
---|
[1289] | 418 | if ( (pps.getTransquantBypassEnableFlag()) ) |
---|
[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()); |
---|
[1369] | 429 | const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() ); |
---|
| 430 | |
---|
| 431 | if ( !bBoundary ) |
---|
[313] | 432 | { |
---|
[540] | 433 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 434 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
| 435 | { |
---|
[595] | 436 | Int iQP = iBaseQP; |
---|
| 437 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
| 438 | |
---|
| 439 | if( bIsLosslessMode ) |
---|
| 440 | { |
---|
| 441 | iQP = lowestQP; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[540] | 445 | |
---|
| 446 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true ); |
---|
| 447 | } |
---|
| 448 | else |
---|
| 449 | { |
---|
| 450 | #endif |
---|
[1029] | 451 | #if ENCODER_FAST_MODE |
---|
[313] | 452 | Bool testInter = true; |
---|
[1483] | 453 | if( rpcBestCU->getPic()->getLayerId() > 0 ) |
---|
[313] | 454 | { |
---|
[442] | 455 | if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 456 | { |
---|
| 457 | testInter = false; |
---|
| 458 | } |
---|
| 459 | if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) |
---|
| 460 | { |
---|
| 461 | testInter = false; |
---|
| 462 | } |
---|
[313] | 463 | } |
---|
| 464 | #endif |
---|
| 465 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 466 | { |
---|
[595] | 467 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); |
---|
| 468 | |
---|
| 469 | if (bIsLosslessMode) |
---|
[313] | 470 | { |
---|
| 471 | iQP = lowestQP; |
---|
| 472 | } |
---|
| 473 | |
---|
[1316] | 474 | m_cuChromaQpOffsetIdxPlus1 = 0; |
---|
[1029] | 475 | if (pcSlice->getUseChromaQpAdj()) |
---|
| 476 | { |
---|
| 477 | /* Pre-estimation of chroma QP based on input block activity may be performed |
---|
| 478 | * here, using for example m_ppcOrigYuv[uiDepth] */ |
---|
| 479 | /* To exercise the current code, the index used for adjustment is based on |
---|
| 480 | * block position |
---|
| 481 | */ |
---|
[1289] | 482 | Int lgMinCuSize = sps.getLog2MinCodingBlockSize() + |
---|
[1316] | 483 | std::max<Int>(0, sps.getLog2DiffMaxMinCodingBlockSize()-Int(pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth())); |
---|
| 484 | m_cuChromaQpOffsetIdxPlus1 = ((uiLPelX >> lgMinCuSize) + (uiTPelY >> lgMinCuSize)) % (pps.getPpsRangeExtension().getChromaQpOffsetListLen() + 1); |
---|
[1029] | 485 | } |
---|
| 486 | |
---|
[595] | 487 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 488 | |
---|
| 489 | // do inter modes, SKIP and 2Nx2N |
---|
[1029] | 490 | #if ENCODER_FAST_MODE == 1 |
---|
[313] | 491 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
| 492 | #else |
---|
| 493 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 494 | #endif |
---|
| 495 | { |
---|
| 496 | // 2Nx2N |
---|
| 497 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 498 | { |
---|
[1029] | 499 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 500 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N |
---|
[313] | 501 | } |
---|
| 502 | // SKIP |
---|
[1029] | 503 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
[595] | 504 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[442] | 505 | |
---|
[1029] | 506 | #if ENCODER_FAST_MODE == 2 |
---|
[313] | 507 | if (testInter) |
---|
| 508 | { |
---|
| 509 | #endif |
---|
| 510 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 511 | { |
---|
| 512 | // 2Nx2N, NxN |
---|
[1029] | 513 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 514 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[442] | 515 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
[313] | 516 | { |
---|
[442] | 517 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[313] | 518 | } |
---|
| 519 | } |
---|
[1029] | 520 | #if ENCODER_FAST_MODE == 2 |
---|
[442] | 521 | } |
---|
[313] | 522 | #endif |
---|
| 523 | } |
---|
| 524 | |
---|
[1029] | 525 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
[313] | 526 | { |
---|
| 527 | iQP = iMinQP; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | if(!earlyDetectionSkipMode) |
---|
| 532 | { |
---|
| 533 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 534 | { |
---|
[1029] | 535 | const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); // If lossless, then iQP is irrelevant for subsequent modules. |
---|
[595] | 536 | |
---|
| 537 | if (bIsLosslessMode) |
---|
[313] | 538 | { |
---|
| 539 | iQP = lowestQP; |
---|
| 540 | } |
---|
[1029] | 541 | |
---|
[595] | 542 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 543 | |
---|
| 544 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
[1029] | 545 | #if ENCODER_FAST_MODE |
---|
[442] | 546 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) |
---|
[313] | 547 | #else |
---|
| 548 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 549 | #endif |
---|
| 550 | { |
---|
| 551 | // 2Nx2N, NxN |
---|
[1290] | 552 | |
---|
[442] | 553 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
[313] | 554 | { |
---|
[1290] | 555 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() && doNotBlockPu) |
---|
[313] | 556 | { |
---|
[1029] | 557 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 558 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 559 | } |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | if(doNotBlockPu) |
---|
| 563 | { |
---|
[1029] | 564 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 565 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 566 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
| 567 | { |
---|
| 568 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | if(doNotBlockPu) |
---|
| 572 | { |
---|
[1029] | 573 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 574 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 575 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
| 576 | { |
---|
| 577 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
[1290] | 582 | if(sps.getUseAMP() && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
[313] | 583 | { |
---|
[1029] | 584 | #if AMP_ENC_SPEEDUP |
---|
[313] | 585 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
| 586 | |
---|
| 587 | #if AMP_MRG |
---|
| 588 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
| 589 | |
---|
| 590 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
| 591 | #else |
---|
| 592 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
| 593 | #endif |
---|
| 594 | |
---|
| 595 | //! Do horizontal AMP |
---|
| 596 | if ( bTestAMP_Hor ) |
---|
| 597 | { |
---|
| 598 | if(doNotBlockPu) |
---|
| 599 | { |
---|
[1029] | 600 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 601 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 602 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 603 | { |
---|
| 604 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | if(doNotBlockPu) |
---|
| 608 | { |
---|
[1029] | 609 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 610 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 611 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 612 | { |
---|
| 613 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | #if AMP_MRG |
---|
[1029] | 618 | else if ( bTestMergeAMP_Hor ) |
---|
[313] | 619 | { |
---|
| 620 | if(doNotBlockPu) |
---|
| 621 | { |
---|
[1029] | 622 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
[595] | 623 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 624 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
| 625 | { |
---|
| 626 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | if(doNotBlockPu) |
---|
| 630 | { |
---|
[1029] | 631 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
[595] | 632 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 633 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
| 634 | { |
---|
| 635 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | #endif |
---|
| 640 | |
---|
| 641 | //! Do horizontal AMP |
---|
| 642 | if ( bTestAMP_Ver ) |
---|
| 643 | { |
---|
| 644 | if(doNotBlockPu) |
---|
| 645 | { |
---|
[1029] | 646 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 647 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 648 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 649 | { |
---|
| 650 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 651 | } |
---|
| 652 | } |
---|
| 653 | if(doNotBlockPu) |
---|
| 654 | { |
---|
[1029] | 655 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[595] | 656 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 657 | } |
---|
| 658 | } |
---|
| 659 | #if AMP_MRG |
---|
| 660 | else if ( bTestMergeAMP_Ver ) |
---|
| 661 | { |
---|
| 662 | if(doNotBlockPu) |
---|
| 663 | { |
---|
[1029] | 664 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
[595] | 665 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 666 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
| 667 | { |
---|
| 668 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | if(doNotBlockPu) |
---|
| 672 | { |
---|
[1029] | 673 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N DEBUG_STRING_PASS_INTO(sDebug), true ); |
---|
[595] | 674 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 675 | } |
---|
| 676 | } |
---|
| 677 | #endif |
---|
| 678 | |
---|
| 679 | #else |
---|
| 680 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
[595] | 681 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 682 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
[595] | 683 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 684 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
[595] | 685 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 686 | |
---|
| 687 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
[595] | 688 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 689 | |
---|
| 690 | #endif |
---|
[1029] | 691 | } |
---|
[313] | 692 | } |
---|
| 693 | |
---|
| 694 | // do normal intra modes |
---|
[1029] | 695 | // speedup for inter frames |
---|
| 696 | Double intraCost = 0.0; |
---|
| 697 | |
---|
[1311] | 698 | if((rpcBestCU->getSlice()->getSliceType() == I_SLICE) || |
---|
[1029] | 699 | #if ENCODER_FAST_MODE |
---|
[1311] | 700 | rpcBestCU->getPredictionMode(0) == NUMBER_OF_PREDICTION_MODES || // if there is no valid inter prediction |
---|
| 701 | !testInter || |
---|
[313] | 702 | #endif |
---|
[1311] | 703 | ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( |
---|
| 704 | (rpcBestCU->getCbf( 0, COMPONENT_Y ) != 0) || |
---|
| 705 | ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) || |
---|
| 706 | ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) // avoid very complex intra if it is unlikely |
---|
| 707 | ))) |
---|
[815] | 708 | { |
---|
[1029] | 709 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, intraCost, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
[815] | 710 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[1290] | 711 | if( uiDepth == sps.getLog2DiffMaxMinCodingBlockSize() ) |
---|
[313] | 712 | { |
---|
[1289] | 713 | if( rpcTempCU->getWidth(0) > ( 1 << sps.getQuadtreeTULog2MinSize() ) ) |
---|
[313] | 714 | { |
---|
[1029] | 715 | Double tmpIntraCost; |
---|
| 716 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, tmpIntraCost, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug) ); |
---|
| 717 | intraCost = std::min(intraCost, tmpIntraCost); |
---|
[595] | 718 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 719 | } |
---|
| 720 | } |
---|
[815] | 721 | } |
---|
[313] | 722 | |
---|
| 723 | // test PCM |
---|
[1289] | 724 | if(sps.getUsePCM() |
---|
| 725 | && rpcTempCU->getWidth(0) <= (1<<sps.getPCMLog2MaxSize()) |
---|
| 726 | && rpcTempCU->getWidth(0) >= (1<<sps.getPCMLog2MinSize()) ) |
---|
[313] | 727 | { |
---|
[1289] | 728 | UInt uiRawBits = getTotalBits(rpcBestCU->getWidth(0), rpcBestCU->getHeight(0), rpcBestCU->getPic()->getChromaFormat(), sps.getBitDepths().recon); |
---|
[313] | 729 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
| 730 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
| 731 | { |
---|
| 732 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
[595] | 733 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 734 | } |
---|
| 735 | } |
---|
[1029] | 736 | #if ENCODER_FAST_MODE |
---|
[494] | 737 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
[815] | 738 | if(pcPic->getLayerId() > 0 && !m_disableILP) |
---|
[494] | 739 | #else |
---|
[815] | 740 | if(pcPic->getLayerId() > 0) |
---|
[494] | 741 | #endif |
---|
[815] | 742 | { |
---|
| 743 | for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++) |
---|
| 744 | { |
---|
| 745 | xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getVPS()->getRefLayerId( pcSlice->getLayerId(), pcSlice->getInterLayerPredLayerIdc(refLayer) ) ); |
---|
| 746 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
| 747 | } |
---|
[313] | 748 | } |
---|
| 749 | #endif |
---|
| 750 | |
---|
[1029] | 751 | if (bIsLosslessMode) // Restore loop variable if lossless mode was searched. |
---|
[313] | 752 | { |
---|
| 753 | iQP = iMinQP; |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | } |
---|
| 757 | |
---|
[1369] | 758 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE ) |
---|
[313] | 759 | { |
---|
[1369] | 760 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
| 761 | m_pcEntropyCoder->resetBits(); |
---|
| 762 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
| 763 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
| 764 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 765 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
| 766 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
[313] | 767 | } |
---|
[1369] | 768 | |
---|
[540] | 769 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 770 | } |
---|
| 771 | #endif |
---|
[313] | 772 | } |
---|
| 773 | |
---|
[1369] | 774 | // copy original YUV samples to PCM buffer |
---|
| 775 | if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
[313] | 776 | { |
---|
| 777 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
| 778 | } |
---|
[1029] | 779 | |
---|
[1290] | 780 | if( uiDepth == pps.getMaxCuDQPDepth() ) |
---|
[313] | 781 | { |
---|
| 782 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
[1289] | 783 | iMinQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP-idQP ); |
---|
| 784 | iMaxQP = Clip3( -sps.getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQP+idQP ); |
---|
[313] | 785 | } |
---|
[1290] | 786 | else if( uiDepth < pps.getMaxCuDQPDepth() ) |
---|
[313] | 787 | { |
---|
| 788 | iMinQP = iBaseQP; |
---|
| 789 | iMaxQP = iBaseQP; |
---|
| 790 | } |
---|
| 791 | else |
---|
| 792 | { |
---|
[1029] | 793 | const Int iStartQP = rpcTempCU->getQP(0); |
---|
[313] | 794 | iMinQP = iStartQP; |
---|
| 795 | iMaxQP = iStartQP; |
---|
| 796 | } |
---|
[1029] | 797 | |
---|
[313] | 798 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 799 | { |
---|
| 800 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 801 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 802 | } |
---|
[595] | 803 | |
---|
| 804 | if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) |
---|
[815] | 805 | { |
---|
[1029] | 806 | iMaxQP = iMinQP; // If all TUs are forced into using transquant bypass, do not loop here. |
---|
[815] | 807 | } |
---|
[313] | 808 | |
---|
[1369] | 809 | const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) ); |
---|
| 810 | |
---|
| 811 | if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary)) |
---|
[595] | 812 | { |
---|
[1369] | 813 | // further split |
---|
| 814 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 815 | { |
---|
| 816 | const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. |
---|
[1029] | 817 | |
---|
[1369] | 818 | rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[595] | 819 | |
---|
[313] | 820 | UChar uhNextDepth = uiDepth+1; |
---|
| 821 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
| 822 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
[1029] | 823 | DEBUG_STRING_NEW(sTempDebug) |
---|
[313] | 824 | |
---|
| 825 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
| 826 | { |
---|
| 827 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 828 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 829 | |
---|
[1289] | 830 | if( ( pcSubBestPartCU->getCUPelX() < sps.getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < sps.getPicHeightInLumaSamples() ) ) |
---|
[313] | 831 | { |
---|
[595] | 832 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
[313] | 833 | { |
---|
[595] | 834 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
[313] | 835 | } |
---|
[595] | 836 | else |
---|
| 837 | { |
---|
| 838 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
| 839 | } |
---|
[313] | 840 | |
---|
| 841 | #if AMP_ENC_SPEEDUP |
---|
[1029] | 842 | DEBUG_STRING_NEW(sChild) |
---|
[1369] | 843 | if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) ) |
---|
[313] | 844 | { |
---|
[1029] | 845 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES ); |
---|
[313] | 846 | } |
---|
| 847 | else |
---|
| 848 | { |
---|
[1029] | 849 | |
---|
| 850 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), rpcBestCU->getPartitionSize(0) ); |
---|
[313] | 851 | } |
---|
[1029] | 852 | DEBUG_STRING_APPEND(sTempDebug, sChild) |
---|
[313] | 853 | #else |
---|
| 854 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
| 855 | #endif |
---|
| 856 | |
---|
| 857 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
| 858 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
| 859 | } |
---|
[1029] | 860 | else |
---|
[313] | 861 | { |
---|
| 862 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
| 863 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
| 864 | } |
---|
| 865 | } |
---|
| 866 | |
---|
[1314] | 867 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
[313] | 868 | if( !bBoundary ) |
---|
| 869 | { |
---|
| 870 | m_pcEntropyCoder->resetBits(); |
---|
| 871 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
| 872 | |
---|
| 873 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
[595] | 874 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 875 | } |
---|
| 876 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 877 | |
---|
[1290] | 878 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[313] | 879 | { |
---|
| 880 | Bool hasResidual = false; |
---|
| 881 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
| 882 | { |
---|
[1029] | 883 | if( ( rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Y) |
---|
| 884 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cb) && (numberValidComponents > COMPONENT_Cb)) |
---|
| 885 | || (rpcTempCU->getCbf(uiBlkIdx, COMPONENT_Cr) && (numberValidComponents > COMPONENT_Cr)) ) ) |
---|
[313] | 886 | { |
---|
| 887 | hasResidual = true; |
---|
| 888 | break; |
---|
| 889 | } |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | if ( hasResidual ) |
---|
| 893 | { |
---|
| 894 | m_pcEntropyCoder->resetBits(); |
---|
[1370] | 895 | m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false ); |
---|
[313] | 896 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[595] | 897 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 898 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 899 | |
---|
| 900 | Bool foundNonZeroCbf = false; |
---|
[1370] | 901 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf ); |
---|
[313] | 902 | assert( foundNonZeroCbf ); |
---|
| 903 | } |
---|
| 904 | else |
---|
| 905 | { |
---|
[1370] | 906 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
[313] | 907 | } |
---|
| 908 | } |
---|
| 909 | |
---|
[1314] | 910 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[595] | 911 | |
---|
[1346] | 912 | // If the configuration being tested exceeds the maximum number of bytes for a slice / slice-segment, then |
---|
| 913 | // a proper RD evaluation cannot be performed. Therefore, termination of the |
---|
| 914 | // slice/slice-segment must be made prior to this CTU. |
---|
| 915 | // This can be achieved by forcing the decision to be that of the rpcTempCU. |
---|
| 916 | // The exception is each slice / slice-segment must have at least one CTU. |
---|
[1369] | 917 | if (rpcBestCU->getTotalCost()!=MAX_DOUBLE) |
---|
[313] | 918 | { |
---|
[1369] | 919 | const Bool isEndOfSlice = pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
| 920 | && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3) |
---|
| 921 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()) |
---|
| 922 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
| 923 | const Bool isEndOfSliceSegment = pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
| 924 | && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3) |
---|
| 925 | && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()); |
---|
| 926 | // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice. |
---|
| 927 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
| 928 | { |
---|
| 929 | rpcBestCU->getTotalCost()=MAX_DOUBLE; |
---|
| 930 | } |
---|
[313] | 931 | } |
---|
[1029] | 932 | |
---|
| 933 | 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] | 934 | // with sub partitioned prediction. |
---|
[1029] | 935 | } |
---|
[313] | 936 | } |
---|
| 937 | |
---|
[1029] | 938 | DEBUG_STRING_APPEND(sDebug_, sDebug); |
---|
| 939 | |
---|
[313] | 940 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
| 941 | |
---|
[1307] | 942 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getCtuRsAddr(), rpcBestCU->getZorderIdxInCtu(), uiDepth, uiDepth ); // Copy Yuv data to picture Yuv |
---|
[1029] | 943 | if (bBoundary) |
---|
[313] | 944 | { |
---|
| 945 | return; |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | // Assert if Best prediction mode is NONE |
---|
| 949 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
[1029] | 950 | assert( rpcBestCU->getPartitionSize ( 0 ) != NUMBER_OF_PART_SIZES ); |
---|
| 951 | assert( rpcBestCU->getPredictionMode( 0 ) != NUMBER_OF_PREDICTION_MODES ); |
---|
| 952 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
[313] | 953 | } |
---|
| 954 | |
---|
| 955 | /** finish encoding a cu and handle end-of-slice conditions |
---|
| 956 | * \param pcCU |
---|
| 957 | * \param uiAbsPartIdx |
---|
[1029] | 958 | * \param uiDepth |
---|
[313] | 959 | * \returns Void |
---|
| 960 | */ |
---|
[1307] | 961 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
[313] | 962 | { |
---|
| 963 | TComPic* pcPic = pcCU->getPic(); |
---|
| 964 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 965 | |
---|
| 966 | //Calculate end address |
---|
[1029] | 967 | const Int currentCTUTsAddr = pcPic->getPicSym()->getCtuRsToTsAddrMap(pcCU->getCtuRsAddr()); |
---|
| 968 | const Bool isLastSubCUOfCtu = pcCU->isLastSubCUOfCtu(uiAbsPartIdx); |
---|
| 969 | if ( isLastSubCUOfCtu ) |
---|
[313] | 970 | { |
---|
| 971 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
[1029] | 972 | // i.e. when the slice segment CurEnd CTU address is the current CTU address+1. |
---|
| 973 | if (pcSlice->getSliceSegmentCurEndCtuTsAddr() != currentCTUTsAddr+1) |
---|
[313] | 974 | { |
---|
[1029] | 975 | m_pcEntropyCoder->encodeTerminatingBit( 0 ); |
---|
[313] | 976 | } |
---|
| 977 | } |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | /** Compute QP for each CU |
---|
| 981 | * \param pcCU Target CU |
---|
| 982 | * \param uiDepth CU depth |
---|
| 983 | * \returns quantization parameter |
---|
| 984 | */ |
---|
| 985 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
| 986 | { |
---|
| 987 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
| 988 | Int iQpOffset = 0; |
---|
| 989 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
| 990 | { |
---|
| 991 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
| 992 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
| 993 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
| 994 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
| 995 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
| 996 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
| 997 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
| 998 | |
---|
| 999 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
| 1000 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
| 1001 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
| 1002 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
| 1003 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
| 1004 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
| 1005 | } |
---|
[1029] | 1006 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), MAX_QP, iBaseQp+iQpOffset ); |
---|
[313] | 1007 | } |
---|
| 1008 | |
---|
| 1009 | /** encode a CU block recursively |
---|
| 1010 | * \param pcCU |
---|
| 1011 | * \param uiAbsPartIdx |
---|
[1029] | 1012 | * \param uiDepth |
---|
[313] | 1013 | * \returns Void |
---|
| 1014 | */ |
---|
| 1015 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1016 | { |
---|
[1289] | 1017 | TComPic *const pcPic = pcCU->getPic(); |
---|
| 1018 | TComSlice *const pcSlice = pcCU->getSlice(); |
---|
| 1019 | const TComSPS &sps =*(pcSlice->getSPS()); |
---|
| 1020 | const TComPPS &pps =*(pcSlice->getPPS()); |
---|
[1029] | 1021 | |
---|
[1289] | 1022 | const UInt maxCUWidth = sps.getMaxCUWidth(); |
---|
| 1023 | const UInt maxCUHeight = sps.getMaxCUHeight(); |
---|
[1029] | 1024 | |
---|
[1289] | 1025 | Bool bBoundary = false; |
---|
| 1026 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1027 | const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1; |
---|
| 1028 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1029 | const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1; |
---|
| 1030 | |
---|
[540] | 1031 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1032 | if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange()) |
---|
| 1033 | { |
---|
| 1034 | pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth); |
---|
| 1035 | } |
---|
| 1036 | #endif |
---|
[1029] | 1037 | |
---|
[1289] | 1038 | if( ( uiRPelX < sps.getPicWidthInLumaSamples() ) && ( uiBPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
[313] | 1039 | { |
---|
| 1040 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1041 | } |
---|
| 1042 | else |
---|
| 1043 | { |
---|
| 1044 | bBoundary = true; |
---|
| 1045 | } |
---|
[1029] | 1046 | |
---|
[1290] | 1047 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() ) ) || bBoundary ) |
---|
[313] | 1048 | { |
---|
[1029] | 1049 | UInt uiQNumParts = ( pcPic->getNumPartitionsInCtu() >> (uiDepth<<1) )>>2; |
---|
[1290] | 1050 | if( uiDepth == pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[313] | 1051 | { |
---|
| 1052 | setdQPFlag(true); |
---|
| 1053 | } |
---|
[1029] | 1054 | |
---|
[1316] | 1055 | if( uiDepth == pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
[1029] | 1056 | { |
---|
| 1057 | setCodeChromaQpAdjFlag(true); |
---|
| 1058 | } |
---|
| 1059 | |
---|
[313] | 1060 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1061 | { |
---|
| 1062 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1063 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
[1203] | 1064 | |
---|
[1289] | 1065 | if( ( uiLPelX < sps.getPicWidthInLumaSamples() ) && ( uiTPelY < sps.getPicHeightInLumaSamples() ) ) |
---|
[313] | 1066 | { |
---|
| 1067 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
| 1068 | } |
---|
| 1069 | } |
---|
| 1070 | return; |
---|
| 1071 | } |
---|
[1029] | 1072 | |
---|
[1290] | 1073 | if( uiDepth <= pps.getMaxCuDQPDepth() && pps.getUseDQP()) |
---|
[313] | 1074 | { |
---|
| 1075 | setdQPFlag(true); |
---|
| 1076 | } |
---|
[1029] | 1077 | |
---|
[1316] | 1078 | if( uiDepth <= pps.getPpsRangeExtension().getDiffCuChromaQpOffsetDepth() && pcSlice->getUseChromaQpAdj()) |
---|
[1029] | 1079 | { |
---|
| 1080 | setCodeChromaQpAdjFlag(true); |
---|
| 1081 | } |
---|
| 1082 | |
---|
[1289] | 1083 | if (pps.getTransquantBypassEnableFlag()) |
---|
[313] | 1084 | { |
---|
| 1085 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 1086 | } |
---|
[1029] | 1087 | |
---|
[1289] | 1088 | if( !pcSlice->isIntra() ) |
---|
[313] | 1089 | { |
---|
| 1090 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 1091 | } |
---|
[1029] | 1092 | |
---|
[313] | 1093 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 1094 | { |
---|
| 1095 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
[1307] | 1096 | finishCU(pcCU,uiAbsPartIdx); |
---|
[313] | 1097 | return; |
---|
| 1098 | } |
---|
[1029] | 1099 | |
---|
[313] | 1100 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
| 1101 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
[1029] | 1102 | |
---|
[313] | 1103 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
| 1104 | { |
---|
| 1105 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
| 1106 | |
---|
| 1107 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
| 1108 | { |
---|
| 1109 | // Encode slice finish |
---|
[1307] | 1110 | finishCU(pcCU,uiAbsPartIdx); |
---|
[313] | 1111 | return; |
---|
| 1112 | } |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
| 1116 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
[1029] | 1117 | |
---|
[313] | 1118 | // Encode Coefficients |
---|
| 1119 | Bool bCodeDQP = getdQPFlag(); |
---|
[1029] | 1120 | Bool codeChromaQpAdj = getCodeChromaQpAdjFlag(); |
---|
| 1121 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj ); |
---|
| 1122 | setCodeChromaQpAdjFlag( codeChromaQpAdj ); |
---|
[313] | 1123 | setdQPFlag( bCodeDQP ); |
---|
| 1124 | |
---|
| 1125 | // --- write terminating bit --- |
---|
[1307] | 1126 | finishCU(pcCU,uiAbsPartIdx); |
---|
[313] | 1127 | } |
---|
| 1128 | |
---|
[1029] | 1129 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
[313] | 1130 | { |
---|
| 1131 | Int k, i, j, jj; |
---|
| 1132 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
| 1133 | |
---|
| 1134 | for( k = 0; k < 64; k += 8 ) |
---|
| 1135 | { |
---|
| 1136 | diff[k+0] = piOrg[0] ; |
---|
| 1137 | diff[k+1] = piOrg[1] ; |
---|
| 1138 | diff[k+2] = piOrg[2] ; |
---|
| 1139 | diff[k+3] = piOrg[3] ; |
---|
| 1140 | diff[k+4] = piOrg[4] ; |
---|
| 1141 | diff[k+5] = piOrg[5] ; |
---|
| 1142 | diff[k+6] = piOrg[6] ; |
---|
| 1143 | diff[k+7] = piOrg[7] ; |
---|
[1029] | 1144 | |
---|
[313] | 1145 | piOrg += iStrideOrg; |
---|
| 1146 | } |
---|
[1029] | 1147 | |
---|
[313] | 1148 | //horizontal |
---|
| 1149 | for (j=0; j < 8; j++) |
---|
| 1150 | { |
---|
| 1151 | jj = j << 3; |
---|
| 1152 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1153 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1154 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1155 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1156 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1157 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1158 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1159 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
[1029] | 1160 | |
---|
[313] | 1161 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1162 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1163 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1164 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1165 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1166 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1167 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1168 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
[1029] | 1169 | |
---|
[313] | 1170 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1171 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1172 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1173 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1174 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1175 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1176 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1177 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1178 | } |
---|
[1029] | 1179 | |
---|
[313] | 1180 | //vertical |
---|
| 1181 | for (i=0; i < 8; i++) |
---|
| 1182 | { |
---|
| 1183 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1184 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1185 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1186 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1187 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1188 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1189 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1190 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
[1029] | 1191 | |
---|
[313] | 1192 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1193 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1194 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1195 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1196 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1197 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1198 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1199 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
[1029] | 1200 | |
---|
[313] | 1201 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1202 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1203 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1204 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1205 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1206 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1207 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1208 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1209 | } |
---|
[1029] | 1210 | |
---|
[313] | 1211 | for (i = 0; i < 8; i++) |
---|
| 1212 | { |
---|
| 1213 | for (j = 0; j < 8; j++) |
---|
| 1214 | { |
---|
| 1215 | iSumHad += abs(m2[i][j]); |
---|
| 1216 | } |
---|
| 1217 | } |
---|
| 1218 | iSumHad -= abs(m2[0][0]); |
---|
| 1219 | iSumHad =(iSumHad+2)>>2; |
---|
| 1220 | return(iSumHad); |
---|
| 1221 | } |
---|
| 1222 | |
---|
[1029] | 1223 | Int TEncCu::updateCtuDataISlice(TComDataCU* pCtu, Int width, Int height) |
---|
[313] | 1224 | { |
---|
[1029] | 1225 | Int xBl, yBl; |
---|
[313] | 1226 | const Int iBlkSize = 8; |
---|
| 1227 | |
---|
[1029] | 1228 | Pel* pOrgInit = pCtu->getPic()->getPicYuvOrg()->getAddr(COMPONENT_Y, pCtu->getCtuRsAddr(), 0); |
---|
| 1229 | Int iStrideOrig = pCtu->getPic()->getPicYuvOrg()->getStride(COMPONENT_Y); |
---|
[313] | 1230 | Pel *pOrg; |
---|
| 1231 | |
---|
| 1232 | Int iSumHad = 0; |
---|
| 1233 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
| 1234 | { |
---|
| 1235 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
| 1236 | { |
---|
[1029] | 1237 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
[313] | 1238 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
| 1239 | } |
---|
| 1240 | } |
---|
| 1241 | return(iSumHad); |
---|
| 1242 | } |
---|
| 1243 | |
---|
| 1244 | /** check RD costs for a CU block encoded with merge |
---|
| 1245 | * \param rpcBestCU |
---|
| 1246 | * \param rpcTempCU |
---|
[1260] | 1247 | * \param earlyDetectionSkipMode |
---|
[313] | 1248 | */ |
---|
[540] | 1249 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
[1029] | 1250 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode, Bool bUseSkip ) |
---|
[540] | 1251 | #else |
---|
[1029] | 1252 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU DEBUG_STRING_FN_DECLARE(sDebug), Bool *earlyDetectionSkipMode ) |
---|
[540] | 1253 | #endif |
---|
[313] | 1254 | { |
---|
| 1255 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
[1369] | 1256 | if(getFastDeltaQp()) |
---|
| 1257 | { |
---|
| 1258 | return; // never check merge in fast deltaqp mode |
---|
| 1259 | } |
---|
[1029] | 1260 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
[313] | 1261 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
| 1262 | Int numValidMergeCand = 0; |
---|
[595] | 1263 | const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); |
---|
[313] | 1264 | |
---|
| 1265 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
| 1266 | { |
---|
| 1267 | uhInterDirNeighbours[ui] = 0; |
---|
| 1268 | } |
---|
| 1269 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[1029] | 1270 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
[313] | 1271 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
| 1272 | |
---|
| 1273 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
| 1274 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
| 1275 | { |
---|
| 1276 | mergeCandBuffer[ui] = 0; |
---|
| 1277 | } |
---|
| 1278 | |
---|
| 1279 | Bool bestIsSkip = false; |
---|
| 1280 | |
---|
| 1281 | UInt iteration; |
---|
| 1282 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
| 1283 | { |
---|
| 1284 | iteration = 1; |
---|
| 1285 | } |
---|
[1029] | 1286 | else |
---|
[313] | 1287 | { |
---|
| 1288 | iteration = 2; |
---|
| 1289 | } |
---|
[1029] | 1290 | DEBUG_STRING_NEW(bestStr) |
---|
[313] | 1291 | |
---|
[540] | 1292 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1293 | for( UInt uiNoResidual = bUseSkip?1:0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
| 1294 | #else |
---|
[313] | 1295 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
[540] | 1296 | #endif |
---|
[313] | 1297 | { |
---|
| 1298 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
| 1299 | { |
---|
| 1300 | #if REF_IDX_ME_ZEROMV |
---|
| 1301 | Bool bZeroMVILR = rpcTempCU->xCheckZeroMVILRMerge(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]); |
---|
| 1302 | if(bZeroMVILR) |
---|
| 1303 | { |
---|
| 1304 | #endif |
---|
[494] | 1305 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1306 | if (!(rpcTempCU->isInterLayerReference(uhInterDirNeighbours[uiMergeCand], cMvFieldNeighbours[0 + 2*uiMergeCand], cMvFieldNeighbours[1 + 2*uiMergeCand]) && m_disableILP)) |
---|
| 1307 | { |
---|
| 1308 | #endif |
---|
[313] | 1309 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
| 1310 | { |
---|
| 1311 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
| 1312 | { |
---|
[1029] | 1313 | DEBUG_STRING_NEW(tmpStr) |
---|
[313] | 1314 | // set MC parameters |
---|
[1029] | 1315 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1316 | rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); |
---|
[1316] | 1317 | rpcTempCU->setChromaQpAdjSubParts( bTransquantBypassFlag ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
[1029] | 1318 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1319 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1320 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
| 1321 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to CTU level |
---|
[313] | 1322 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1323 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
[1029] | 1324 | |
---|
[313] | 1325 | // do MC |
---|
| 1326 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
| 1327 | // estimate residual and encode everything |
---|
| 1328 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
[1029] | 1329 | m_ppcOrigYuv [uhDepth], |
---|
| 1330 | m_ppcPredYuvTemp[uhDepth], |
---|
| 1331 | m_ppcResiYuvTemp[uhDepth], |
---|
| 1332 | m_ppcResiYuvBest[uhDepth], |
---|
| 1333 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 1334 | (uiNoResidual != 0) DEBUG_STRING_PASS_INTO(tmpStr) ); |
---|
| 1335 | |
---|
[1335] | 1336 | #if DEBUG_STRING |
---|
[1029] | 1337 | DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
| 1338 | #endif |
---|
| 1339 | |
---|
| 1340 | if ((uiNoResidual == 0) && (rpcTempCU->getQtRootCbf(0) == 0)) |
---|
[313] | 1341 | { |
---|
| 1342 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
| 1343 | mergeCandBuffer[uiMergeCand] = 1; |
---|
| 1344 | } |
---|
[1029] | 1345 | |
---|
[313] | 1346 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
| 1347 | xCheckDQP( rpcTempCU ); |
---|
[1029] | 1348 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr)); |
---|
| 1349 | |
---|
[595] | 1350 | rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); |
---|
[1029] | 1351 | |
---|
[313] | 1352 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
| 1353 | { |
---|
| 1354 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
| 1355 | } |
---|
| 1356 | } |
---|
[494] | 1357 | } |
---|
| 1358 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1359 | } |
---|
| 1360 | #endif |
---|
[313] | 1361 | #if REF_IDX_ME_ZEROMV |
---|
[494] | 1362 | } |
---|
[313] | 1363 | #endif |
---|
[1029] | 1364 | } |
---|
[313] | 1365 | |
---|
[1029] | 1366 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
[313] | 1367 | { |
---|
[1029] | 1368 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
[313] | 1369 | { |
---|
[1029] | 1370 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
[313] | 1371 | { |
---|
[1029] | 1372 | *earlyDetectionSkipMode = true; |
---|
| 1373 | } |
---|
[1406] | 1374 | else if(m_pcEncCfg->getMotionEstimationSearchMethod() != MESEARCH_SELECTIVE) |
---|
[1029] | 1375 | { |
---|
| 1376 | Int absoulte_MV=0; |
---|
| 1377 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
[313] | 1378 | { |
---|
[1029] | 1379 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
| 1380 | { |
---|
| 1381 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
| 1382 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
| 1383 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
| 1384 | absoulte_MV+=iHor+iVer; |
---|
| 1385 | } |
---|
[313] | 1386 | } |
---|
| 1387 | |
---|
[1029] | 1388 | if(absoulte_MV == 0) |
---|
| 1389 | { |
---|
| 1390 | *earlyDetectionSkipMode = true; |
---|
| 1391 | } |
---|
[313] | 1392 | } |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | } |
---|
[1029] | 1396 | DEBUG_STRING_APPEND(sDebug, bestStr) |
---|
[313] | 1397 | } |
---|
| 1398 | |
---|
| 1399 | |
---|
| 1400 | #if AMP_MRG |
---|
[1029] | 1401 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug), Bool bUseMRG) |
---|
[313] | 1402 | #else |
---|
| 1403 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
| 1404 | #endif |
---|
| 1405 | { |
---|
[1029] | 1406 | DEBUG_STRING_NEW(sTest) |
---|
| 1407 | |
---|
[1369] | 1408 | if(getFastDeltaQp()) |
---|
| 1409 | { |
---|
| 1410 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
| 1411 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
| 1412 | if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
| 1413 | { |
---|
| 1414 | return; // only check necessary 2Nx2N Inter in fast deltaqp mode |
---|
| 1415 | } |
---|
| 1416 | } |
---|
| 1417 | |
---|
[1248] | 1418 | // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); |
---|
[313] | 1419 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[1029] | 1420 | |
---|
[313] | 1421 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
| 1422 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
[1316] | 1423 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uhDepth ); |
---|
[313] | 1424 | |
---|
[815] | 1425 | #if SVC_EXTENSION |
---|
[313] | 1426 | #if AMP_MRG |
---|
| 1427 | rpcTempCU->setMergeAMP (true); |
---|
[1029] | 1428 | 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] | 1429 | #else |
---|
| 1430 | Bool ret = m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
| 1431 | #endif |
---|
| 1432 | |
---|
| 1433 | if( !ret ) |
---|
| 1434 | { |
---|
| 1435 | return; |
---|
| 1436 | } |
---|
| 1437 | #else |
---|
| 1438 | #if AMP_MRG |
---|
| 1439 | rpcTempCU->setMergeAMP (true); |
---|
[1029] | 1440 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] DEBUG_STRING_PASS_INTO(sTest), false, bUseMRG ); |
---|
| 1441 | #else |
---|
[313] | 1442 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
| 1443 | #endif |
---|
[815] | 1444 | #endif |
---|
[313] | 1445 | |
---|
| 1446 | #if AMP_MRG |
---|
| 1447 | if ( !rpcTempCU->getMergeAMP() ) |
---|
| 1448 | { |
---|
| 1449 | return; |
---|
| 1450 | } |
---|
| 1451 | #endif |
---|
| 1452 | |
---|
[1029] | 1453 | 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] | 1454 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1455 | |
---|
[1335] | 1456 | #if DEBUG_STRING |
---|
[1029] | 1457 | DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->getPredictionMode(0))); |
---|
| 1458 | #endif |
---|
| 1459 | |
---|
[313] | 1460 | xCheckDQP( rpcTempCU ); |
---|
[1029] | 1461 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
[313] | 1462 | } |
---|
| 1463 | |
---|
[1029] | 1464 | Void TEncCu::xCheckRDCostIntra( TComDataCU *&rpcBestCU, |
---|
| 1465 | TComDataCU *&rpcTempCU, |
---|
| 1466 | Double &cost, |
---|
| 1467 | PartSize eSize |
---|
| 1468 | DEBUG_STRING_FN_DECLARE(sDebug) ) |
---|
[313] | 1469 | { |
---|
[1029] | 1470 | DEBUG_STRING_NEW(sTest) |
---|
| 1471 | |
---|
[1369] | 1472 | if(getFastDeltaQp()) |
---|
| 1473 | { |
---|
| 1474 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
| 1475 | const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u); |
---|
| 1476 | if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize) |
---|
| 1477 | { |
---|
| 1478 | return; // only check necessary 2Nx2N Intra in fast deltaqp mode |
---|
| 1479 | } |
---|
| 1480 | } |
---|
| 1481 | |
---|
[313] | 1482 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
[1029] | 1483 | |
---|
[313] | 1484 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1485 | |
---|
| 1486 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
| 1487 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
[1316] | 1488 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
[1029] | 1489 | |
---|
| 1490 | Pel resiLuma[NUMBER_OF_STORED_RESIDUAL_TYPES][MAX_CU_SIZE * MAX_CU_SIZE]; |
---|
| 1491 | |
---|
[1243] | 1492 | m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
[313] | 1493 | |
---|
[1029] | 1494 | m_ppcRecoYuvTemp[uiDepth]->copyToPicComponent(COMPONENT_Y, rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getCtuRsAddr(), rpcTempCU->getZorderIdxInCtu() ); |
---|
| 1495 | |
---|
| 1496 | if (rpcBestCU->getPic()->getChromaFormat()!=CHROMA_400) |
---|
| 1497 | { |
---|
[1243] | 1498 | m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma DEBUG_STRING_PASS_INTO(sTest) ); |
---|
[1029] | 1499 | } |
---|
| 1500 | |
---|
[313] | 1501 | m_pcEntropyCoder->resetBits(); |
---|
[1029] | 1502 | |
---|
[313] | 1503 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1504 | { |
---|
| 1505 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1506 | } |
---|
[1029] | 1507 | |
---|
[313] | 1508 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1509 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
| 1510 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
[1029] | 1511 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 ); |
---|
[313] | 1512 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
| 1513 | |
---|
| 1514 | // Encode Coefficients |
---|
| 1515 | Bool bCodeDQP = getdQPFlag(); |
---|
[1029] | 1516 | Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag(); |
---|
| 1517 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag ); |
---|
| 1518 | setCodeChromaQpAdjFlag( codeChromaQpAdjFlag ); |
---|
[313] | 1519 | setdQPFlag( bCodeDQP ); |
---|
[1029] | 1520 | |
---|
[595] | 1521 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[1029] | 1522 | |
---|
[313] | 1523 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[595] | 1524 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1525 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[1029] | 1526 | |
---|
[313] | 1527 | xCheckDQP( rpcTempCU ); |
---|
[1029] | 1528 | |
---|
| 1529 | cost = rpcTempCU->getTotalCost(); |
---|
| 1530 | |
---|
| 1531 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest)); |
---|
[313] | 1532 | } |
---|
| 1533 | |
---|
[1029] | 1534 | |
---|
| 1535 | /** Check R-D costs for a CU with PCM mode. |
---|
[313] | 1536 | * \param rpcBestCU pointer to best mode CU data structure |
---|
| 1537 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
| 1538 | * \returns Void |
---|
[1029] | 1539 | * |
---|
[313] | 1540 | * \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. |
---|
| 1541 | */ |
---|
| 1542 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
| 1543 | { |
---|
[1369] | 1544 | if(getFastDeltaQp()) |
---|
| 1545 | { |
---|
| 1546 | const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS()); |
---|
| 1547 | const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u); |
---|
| 1548 | if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize) |
---|
| 1549 | { |
---|
| 1550 | return; // only check necessary PCM in fast deltaqp mode |
---|
| 1551 | } |
---|
| 1552 | } |
---|
| 1553 | |
---|
[313] | 1554 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1555 | |
---|
| 1556 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 1557 | |
---|
| 1558 | rpcTempCU->setIPCMFlag(0, true); |
---|
| 1559 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
| 1560 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 1561 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
| 1562 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
[1316] | 1563 | rpcTempCU->setChromaQpAdjSubParts( rpcTempCU->getCUTransquantBypass(0) ? 0 : m_cuChromaQpOffsetIdxPlus1, 0, uiDepth ); |
---|
[313] | 1564 | |
---|
| 1565 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
| 1566 | |
---|
[595] | 1567 | m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
[313] | 1568 | |
---|
| 1569 | m_pcEntropyCoder->resetBits(); |
---|
[1029] | 1570 | |
---|
[313] | 1571 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1572 | { |
---|
| 1573 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 1574 | } |
---|
[1029] | 1575 | |
---|
[313] | 1576 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 1577 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
| 1578 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
| 1579 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
| 1580 | |
---|
[595] | 1581 | m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[313] | 1582 | |
---|
| 1583 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[595] | 1584 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1585 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1586 | |
---|
| 1587 | xCheckDQP( rpcTempCU ); |
---|
[1029] | 1588 | DEBUG_STRING_NEW(a) |
---|
| 1589 | DEBUG_STRING_NEW(b) |
---|
| 1590 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(a) DEBUG_STRING_PASS_INTO(b)); |
---|
[313] | 1591 | } |
---|
| 1592 | |
---|
| 1593 | /** check whether current try is the best with identifying the depth of current try |
---|
| 1594 | * \param rpcBestCU |
---|
| 1595 | * \param rpcTempCU |
---|
[1260] | 1596 | * \param uiDepth |
---|
[313] | 1597 | */ |
---|
[1029] | 1598 | 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] | 1599 | { |
---|
| 1600 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
| 1601 | { |
---|
| 1602 | TComYuv* pcYuv; |
---|
| 1603 | // Change Information data |
---|
| 1604 | TComDataCU* pcCU = rpcBestCU; |
---|
| 1605 | rpcBestCU = rpcTempCU; |
---|
| 1606 | rpcTempCU = pcCU; |
---|
| 1607 | |
---|
| 1608 | // Change Prediction data |
---|
| 1609 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
| 1610 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
| 1611 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
| 1612 | |
---|
| 1613 | // Change Reconstruction data |
---|
| 1614 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
| 1615 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
| 1616 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
| 1617 | |
---|
| 1618 | pcYuv = NULL; |
---|
| 1619 | pcCU = NULL; |
---|
| 1620 | |
---|
[595] | 1621 | // store temp best CI for next CU coding |
---|
| 1622 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
[1029] | 1623 | |
---|
| 1624 | |
---|
[1335] | 1625 | #if DEBUG_STRING |
---|
[1029] | 1626 | DEBUG_STRING_SWAP(sParent, sTest) |
---|
| 1627 | const PredMode predMode=rpcBestCU->getPredictionMode(0); |
---|
| 1628 | if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo) |
---|
| 1629 | { |
---|
| 1630 | std::stringstream ss(stringstream::out); |
---|
| 1631 | ss <<"###: " << (predMode==MODE_INTRA?"Intra ":"Inter ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl; |
---|
| 1632 | sParent+=ss.str(); |
---|
| 1633 | } |
---|
| 1634 | #endif |
---|
[313] | 1635 | } |
---|
| 1636 | } |
---|
| 1637 | |
---|
| 1638 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
| 1639 | { |
---|
| 1640 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
| 1641 | |
---|
[1289] | 1642 | const TComPPS &pps = *(pcCU->getSlice()->getPPS()); |
---|
[1290] | 1643 | if ( pps.getUseDQP() && uiDepth <= pps.getMaxCuDQPDepth() ) |
---|
[313] | 1644 | { |
---|
[1029] | 1645 | if ( pcCU->getQtRootCbf( 0) ) |
---|
[313] | 1646 | { |
---|
| 1647 | m_pcEntropyCoder->resetBits(); |
---|
| 1648 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
| 1649 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
[595] | 1650 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
[313] | 1651 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
| 1652 | } |
---|
| 1653 | else |
---|
| 1654 | { |
---|
| 1655 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
| 1656 | } |
---|
| 1657 | } |
---|
| 1658 | } |
---|
| 1659 | |
---|
| 1660 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
| 1661 | { |
---|
| 1662 | pDst->iN = pSrc->iN; |
---|
| 1663 | for (Int i = 0; i < pSrc->iN; i++) |
---|
| 1664 | { |
---|
| 1665 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
| 1666 | } |
---|
| 1667 | } |
---|
[1307] | 1668 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth ) |
---|
[313] | 1669 | { |
---|
[1029] | 1670 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
| 1671 | UInt uiSrcBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiSrcDepth); |
---|
| 1672 | UInt uiBlkWidth = rpcPic->getNumPartInCtuWidth() >> (uiDepth); |
---|
| 1673 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1674 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInCtuWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 1675 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
| 1676 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
[313] | 1677 | |
---|
[1029] | 1678 | m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
[313] | 1679 | } |
---|
| 1680 | |
---|
| 1681 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
| 1682 | { |
---|
| 1683 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
| 1684 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
[1029] | 1685 | m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx); |
---|
[313] | 1686 | } |
---|
| 1687 | |
---|
[1029] | 1688 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
[1260] | 1689 | * \param pCU pointer to current CU |
---|
| 1690 | * \param pOrgYuv pointer to original sample array |
---|
[313] | 1691 | */ |
---|
[1029] | 1692 | Void TEncCu::xFillPCMBuffer ( TComDataCU* pCU, TComYuv* pOrgYuv ) |
---|
[313] | 1693 | { |
---|
[1029] | 1694 | const ChromaFormat format = pCU->getPic()->getChromaFormat(); |
---|
| 1695 | const UInt numberValidComponents = getNumberValidComponents(format); |
---|
| 1696 | for (UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++) |
---|
[313] | 1697 | { |
---|
[1029] | 1698 | const ComponentID component = ComponentID(componentIndex); |
---|
[313] | 1699 | |
---|
[1029] | 1700 | const UInt width = pCU->getWidth(0) >> getComponentScaleX(component, format); |
---|
| 1701 | const UInt height = pCU->getHeight(0) >> getComponentScaleY(component, format); |
---|
[313] | 1702 | |
---|
[1029] | 1703 | Pel *source = pOrgYuv->getAddr(component, 0, width); |
---|
| 1704 | Pel *destination = pCU->getPCMSample(component); |
---|
[313] | 1705 | |
---|
[1029] | 1706 | const UInt sourceStride = pOrgYuv->getStride(component); |
---|
[313] | 1707 | |
---|
[1029] | 1708 | for (Int line = 0; line < height; line++) |
---|
[313] | 1709 | { |
---|
[1029] | 1710 | for (Int column = 0; column < width; column++) |
---|
| 1711 | { |
---|
| 1712 | destination[column] = source[column]; |
---|
| 1713 | } |
---|
| 1714 | |
---|
| 1715 | source += sourceStride; |
---|
| 1716 | destination += width; |
---|
[313] | 1717 | } |
---|
| 1718 | } |
---|
| 1719 | } |
---|
| 1720 | |
---|
| 1721 | #if ADAPTIVE_QP_SELECTION |
---|
| 1722 | /** Collect ARL statistics from one block |
---|
| 1723 | */ |
---|
[1029] | 1724 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, TCoeff* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
[313] | 1725 | { |
---|
| 1726 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
| 1727 | { |
---|
[1029] | 1728 | TCoeff u = abs( rpcCoeff[ n ] ); |
---|
| 1729 | TCoeff absc = rpcArlCoeff[ n ]; |
---|
[313] | 1730 | |
---|
| 1731 | if( u != 0 ) |
---|
| 1732 | { |
---|
| 1733 | if( u < LEVEL_RANGE ) |
---|
| 1734 | { |
---|
| 1735 | cSum[ u ] += ( Double )absc; |
---|
| 1736 | numSamples[ u ]++; |
---|
| 1737 | } |
---|
[1029] | 1738 | else |
---|
[313] | 1739 | { |
---|
| 1740 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
| 1741 | numSamples[ LEVEL_RANGE ]++; |
---|
| 1742 | } |
---|
| 1743 | } |
---|
| 1744 | } |
---|
| 1745 | |
---|
| 1746 | return 0; |
---|
| 1747 | } |
---|
| 1748 | |
---|
[1260] | 1749 | //! Collect ARL statistics from one CTU |
---|
[1029] | 1750 | Void TEncCu::xCtuCollectARLStats(TComDataCU* pCtu ) |
---|
[595] | 1751 | { |
---|
[1260] | 1752 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to data type and quantization output |
---|
| 1753 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to data type and quantization output |
---|
[595] | 1754 | |
---|
[1029] | 1755 | TCoeff* pCoeffY = pCtu->getCoeff(COMPONENT_Y); |
---|
| 1756 | TCoeff* pArlCoeffY = pCtu->getArlCoeff(COMPONENT_Y); |
---|
[1289] | 1757 | const TComSPS &sps = *(pCtu->getSlice()->getSPS()); |
---|
[595] | 1758 | |
---|
[1290] | 1759 | 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. |
---|
| 1760 | const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; // NOTE: ed - what is this? |
---|
[595] | 1761 | |
---|
| 1762 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
| 1763 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
| 1764 | |
---|
| 1765 | // Collect stats to cSum[][] and numSamples[][] |
---|
[1029] | 1766 | for(Int i = 0; i < pCtu->getTotalNumPart(); i ++ ) |
---|
[595] | 1767 | { |
---|
[1029] | 1768 | UInt uiTrIdx = pCtu->getTransformIdx(i); |
---|
[595] | 1769 | |
---|
[1029] | 1770 | if(pCtu->isInter(i) && pCtu->getCbf( i, COMPONENT_Y, uiTrIdx ) ) |
---|
[595] | 1771 | { |
---|
| 1772 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
| 1773 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
[1029] | 1774 | |
---|
[595] | 1775 | pCoeffY += uiMinNumCoeffInCU; |
---|
| 1776 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
| 1777 | } |
---|
| 1778 | |
---|
| 1779 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
| 1780 | { |
---|
| 1781 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
| 1782 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
| 1783 | } |
---|
| 1784 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
| 1785 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
| 1786 | } |
---|
| 1787 | #endif |
---|
| 1788 | |
---|
| 1789 | #if SVC_EXTENSION |
---|
[494] | 1790 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1791 | Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU ) |
---|
| 1792 | { |
---|
| 1793 | Bool disableILP = false; |
---|
| 1794 | |
---|
[1483] | 1795 | if (rpcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0) |
---|
[494] | 1796 | { |
---|
[1029] | 1797 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 2) |
---|
[494] | 1798 | { |
---|
| 1799 | disableILP = true; |
---|
| 1800 | } |
---|
[1029] | 1801 | if (rpcCU->getPic()->getPicSym()->getTileSetType(rpcCU->getCtuRsAddr()) == 1) |
---|
[494] | 1802 | { |
---|
[1029] | 1803 | Int currCUaddr = rpcCU->getCtuRsAddr(); |
---|
| 1804 | Int frameWitdhInCU = rpcCU->getPic()->getPicSym()->getFrameWidthInCtus(); |
---|
| 1805 | Int frameHeightInCU = rpcCU->getPic()->getPicSym()->getFrameHeightInCtus(); |
---|
[494] | 1806 | Bool leftCUExists = (currCUaddr % frameWitdhInCU) > 0; |
---|
| 1807 | Bool aboveCUExists = (currCUaddr / frameWitdhInCU) > 0; |
---|
| 1808 | Bool rightCUExists = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1); |
---|
| 1809 | Bool belowCUExists = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1); |
---|
| 1810 | Int currTileSetIdx = rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr); |
---|
| 1811 | // Check if CU is at tile set boundary |
---|
| 1812 | if ( (leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-1) != currTileSetIdx) || |
---|
| 1813 | (leftCUExists && aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) || |
---|
| 1814 | (aboveCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) || |
---|
| 1815 | (aboveCUExists && rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) || |
---|
| 1816 | (rightCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+1) != currTileSetIdx) || |
---|
| 1817 | (rightCUExists && belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) || |
---|
| 1818 | (belowCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) || |
---|
| 1819 | (belowCUExists && leftCUExists && rpcCU->getPic()->getPicSym()->getTileSetIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) ) |
---|
| 1820 | { |
---|
| 1821 | disableILP = true; // Disable ILP in tile set boundary CU |
---|
| 1822 | } |
---|
| 1823 | } |
---|
| 1824 | } |
---|
| 1825 | |
---|
| 1826 | return disableILP; |
---|
| 1827 | } |
---|
| 1828 | |
---|
| 1829 | Void TEncCu::xVerifyTileSetConstraint( TComDataCU*& rpcCU ) |
---|
| 1830 | { |
---|
[1483] | 1831 | if( rpcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1) && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && |
---|
| 1832 | rpcCU->getPic()->getPicSym()->getTileSetIdxMap(rpcCU->getCtuRsAddr()) >= 0 && m_disableILP ) |
---|
[494] | 1833 | { |
---|
[1029] | 1834 | UInt numPartitions = rpcCU->getPic()->getNumPartitionsInCtu(); |
---|
[494] | 1835 | for (UInt i = 0; i < numPartitions; i++) |
---|
| 1836 | { |
---|
| 1837 | if (!rpcCU->isIntra(i)) |
---|
| 1838 | { |
---|
| 1839 | for (UInt refList = 0; refList < 2; refList++) |
---|
| 1840 | { |
---|
| 1841 | if (rpcCU->getInterDir(i) & (1<<refList)) |
---|
| 1842 | { |
---|
| 1843 | TComCUMvField *mvField = rpcCU->getCUMvField(RefPicList(refList)); |
---|
| 1844 | if (mvField->getRefIdx(i) >= 0) |
---|
| 1845 | { |
---|
[1483] | 1846 | assert(!(rpcCU->getSlice()->getRefPic(RefPicList(refList), mvField->getRefIdx(i))->isILR(rpcCU->getPic()->getLayerId()))); |
---|
[494] | 1847 | } |
---|
| 1848 | } |
---|
| 1849 | } |
---|
| 1850 | } |
---|
| 1851 | } |
---|
| 1852 | } |
---|
| 1853 | } |
---|
| 1854 | #endif |
---|
| 1855 | |
---|
[1029] | 1856 | #if ENCODER_FAST_MODE |
---|
[313] | 1857 | Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId) |
---|
| 1858 | { |
---|
| 1859 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 1860 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
| 1861 | #if SKIP_FLAG |
---|
| 1862 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1863 | #endif |
---|
| 1864 | rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N |
---|
| 1865 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
[595] | 1866 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagForceValue(), 0, uhDepth ); |
---|
[313] | 1867 | Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId ); |
---|
| 1868 | if(!exitILR) |
---|
| 1869 | { |
---|
| 1870 | return; |
---|
| 1871 | } |
---|
| 1872 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 1873 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1874 | xCheckDQP( rpcTempCU ); |
---|
| 1875 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
| 1876 | return; |
---|
| 1877 | } |
---|
| 1878 | #endif |
---|
[595] | 1879 | #endif //SVC_EXTENSION |
---|
[313] | 1880 | //! \} |
---|