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