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