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