[5] | 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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
[56] | 34 | /** \file TEncCu.cpp |
---|
| 35 | \brief Coding Unit (CU) encoder class |
---|
[2] | 36 | */ |
---|
| 37 | |
---|
| 38 | #include <stdio.h> |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncCu.h" |
---|
| 41 | #include "TEncAnalyze.h" |
---|
| 42 | |
---|
[56] | 43 | #include <cmath> |
---|
| 44 | #include <algorithm> |
---|
| 45 | using namespace std; |
---|
| 46 | |
---|
| 47 | //! \ingroup TLibEncoder |
---|
| 48 | //! \{ |
---|
| 49 | |
---|
[2] | 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; |
---|
[56] | 62 | |
---|
[2] | 63 | m_uhTotalDepth = uhTotalDepth + 1; |
---|
| 64 | m_ppcBestCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 65 | m_ppcTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
[608] | 66 | |
---|
| 67 | #if H_3D_ARP |
---|
[443] | 68 | m_ppcWeightedTempCU = new TComDataCU*[m_uhTotalDepth-1]; |
---|
| 69 | #endif |
---|
[608] | 70 | |
---|
[2] | 71 | m_ppcPredYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 72 | m_ppcResiYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 73 | m_ppcRecoYuvBest = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 74 | m_ppcPredYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 75 | m_ppcResiYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 76 | m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1]; |
---|
| 77 | m_ppcOrigYuv = new TComYuv*[m_uhTotalDepth-1]; |
---|
[56] | 78 | |
---|
[2] | 79 | UInt uiNumPartitions; |
---|
| 80 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 81 | { |
---|
| 82 | uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 ); |
---|
| 83 | UInt uiWidth = uiMaxWidth >> i; |
---|
| 84 | UInt uiHeight = uiMaxHeight >> i; |
---|
[56] | 85 | |
---|
| 86 | m_ppcBestCU[i] = new TComDataCU; m_ppcBestCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
| 87 | m_ppcTempCU[i] = new TComDataCU; m_ppcTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
[608] | 88 | |
---|
| 89 | #if H_3D_ARP |
---|
[443] | 90 | m_ppcWeightedTempCU[i] = new TComDataCU; m_ppcWeightedTempCU[i]->create( uiNumPartitions, uiWidth, uiHeight, false, uiMaxWidth >> (m_uhTotalDepth - 1) ); |
---|
[608] | 91 | #endif |
---|
| 92 | |
---|
[2] | 93 | m_ppcPredYuvBest[i] = new TComYuv; m_ppcPredYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 94 | m_ppcResiYuvBest[i] = new TComYuv; m_ppcResiYuvBest[i]->create(uiWidth, uiHeight); |
---|
| 95 | m_ppcRecoYuvBest[i] = new TComYuv; m_ppcRecoYuvBest[i]->create(uiWidth, uiHeight); |
---|
[56] | 96 | |
---|
[2] | 97 | m_ppcPredYuvTemp[i] = new TComYuv; m_ppcPredYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 98 | m_ppcResiYuvTemp[i] = new TComYuv; m_ppcResiYuvTemp[i]->create(uiWidth, uiHeight); |
---|
| 99 | m_ppcRecoYuvTemp[i] = new TComYuv; m_ppcRecoYuvTemp[i]->create(uiWidth, uiHeight); |
---|
[56] | 100 | |
---|
[2] | 101 | m_ppcOrigYuv [i] = new TComYuv; m_ppcOrigYuv [i]->create(uiWidth, uiHeight); |
---|
| 102 | } |
---|
[56] | 103 | |
---|
| 104 | m_bEncodeDQP = false; |
---|
[655] | 105 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 106 | #if !M0036_RC_IMPROVEMENT |
---|
[608] | 107 | m_LCUPredictionSAD = 0; |
---|
| 108 | m_addSADDepth = 0; |
---|
| 109 | m_temporalSAD = 0; |
---|
| 110 | #endif |
---|
[655] | 111 | #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 112 | m_LCUPredictionSAD = 0; |
---|
| 113 | m_addSADDepth = 0; |
---|
| 114 | m_temporalSAD = 0; |
---|
| 115 | m_spatialSAD = 0; |
---|
| 116 | #endif |
---|
| 117 | #endif |
---|
| 118 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 |
---|
| 119 | m_LCUPredictionSAD = 0; |
---|
| 120 | m_addSADDepth = 0; |
---|
| 121 | m_temporalSAD = 0; |
---|
| 122 | m_spatialSAD = 0; |
---|
| 123 | #endif |
---|
[2] | 124 | |
---|
| 125 | // initialize partition order. |
---|
| 126 | UInt* piTmp = &g_auiZscanToRaster[0]; |
---|
| 127 | initZscanToRaster( m_uhTotalDepth, 1, 0, piTmp); |
---|
| 128 | initRasterToZscan( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
[56] | 129 | |
---|
[2] | 130 | // initialize conversion matrix from partition index to pel |
---|
| 131 | initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | Void TEncCu::destroy() |
---|
| 135 | { |
---|
| 136 | Int i; |
---|
[56] | 137 | |
---|
[2] | 138 | for( i=0 ; i<m_uhTotalDepth-1 ; i++) |
---|
| 139 | { |
---|
| 140 | if(m_ppcBestCU[i]) |
---|
| 141 | { |
---|
| 142 | m_ppcBestCU[i]->destroy(); delete m_ppcBestCU[i]; m_ppcBestCU[i] = NULL; |
---|
| 143 | } |
---|
| 144 | if(m_ppcTempCU[i]) |
---|
| 145 | { |
---|
| 146 | m_ppcTempCU[i]->destroy(); delete m_ppcTempCU[i]; m_ppcTempCU[i] = NULL; |
---|
| 147 | } |
---|
[608] | 148 | #if H_3D_ARP |
---|
| 149 | if(m_ppcWeightedTempCU[i]) |
---|
| 150 | { |
---|
| 151 | m_ppcWeightedTempCU[i]->destroy(); delete m_ppcWeightedTempCU[i]; m_ppcWeightedTempCU[i] = NULL; |
---|
| 152 | } |
---|
| 153 | #endif |
---|
[2] | 154 | if(m_ppcPredYuvBest[i]) |
---|
| 155 | { |
---|
| 156 | m_ppcPredYuvBest[i]->destroy(); delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] = NULL; |
---|
| 157 | } |
---|
| 158 | if(m_ppcResiYuvBest[i]) |
---|
| 159 | { |
---|
| 160 | m_ppcResiYuvBest[i]->destroy(); delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] = NULL; |
---|
| 161 | } |
---|
| 162 | if(m_ppcRecoYuvBest[i]) |
---|
| 163 | { |
---|
| 164 | m_ppcRecoYuvBest[i]->destroy(); delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] = NULL; |
---|
| 165 | } |
---|
| 166 | if(m_ppcPredYuvTemp[i]) |
---|
| 167 | { |
---|
| 168 | m_ppcPredYuvTemp[i]->destroy(); delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] = NULL; |
---|
| 169 | } |
---|
| 170 | if(m_ppcResiYuvTemp[i]) |
---|
| 171 | { |
---|
| 172 | m_ppcResiYuvTemp[i]->destroy(); delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] = NULL; |
---|
| 173 | } |
---|
| 174 | if(m_ppcRecoYuvTemp[i]) |
---|
| 175 | { |
---|
| 176 | m_ppcRecoYuvTemp[i]->destroy(); delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] = NULL; |
---|
| 177 | } |
---|
| 178 | if(m_ppcOrigYuv[i]) |
---|
| 179 | { |
---|
| 180 | m_ppcOrigYuv[i]->destroy(); delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] = NULL; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | if(m_ppcBestCU) |
---|
| 184 | { |
---|
| 185 | delete [] m_ppcBestCU; |
---|
| 186 | m_ppcBestCU = NULL; |
---|
| 187 | } |
---|
| 188 | if(m_ppcTempCU) |
---|
| 189 | { |
---|
| 190 | delete [] m_ppcTempCU; |
---|
| 191 | m_ppcTempCU = NULL; |
---|
| 192 | } |
---|
[608] | 193 | |
---|
| 194 | #if H_3D_ARP |
---|
| 195 | if(m_ppcWeightedTempCU) |
---|
| 196 | { |
---|
| 197 | delete [] m_ppcWeightedTempCU; |
---|
| 198 | m_ppcWeightedTempCU = NULL; |
---|
| 199 | } |
---|
| 200 | #endif |
---|
[2] | 201 | if(m_ppcPredYuvBest) |
---|
| 202 | { |
---|
| 203 | delete [] m_ppcPredYuvBest; |
---|
| 204 | m_ppcPredYuvBest = NULL; |
---|
| 205 | } |
---|
| 206 | if(m_ppcResiYuvBest) |
---|
| 207 | { |
---|
| 208 | delete [] m_ppcResiYuvBest; |
---|
| 209 | m_ppcResiYuvBest = NULL; |
---|
| 210 | } |
---|
| 211 | if(m_ppcRecoYuvBest) |
---|
| 212 | { |
---|
| 213 | delete [] m_ppcRecoYuvBest; |
---|
| 214 | m_ppcRecoYuvBest = NULL; |
---|
| 215 | } |
---|
| 216 | if(m_ppcPredYuvTemp) |
---|
| 217 | { |
---|
| 218 | delete [] m_ppcPredYuvTemp; |
---|
| 219 | m_ppcPredYuvTemp = NULL; |
---|
| 220 | } |
---|
| 221 | if(m_ppcResiYuvTemp) |
---|
| 222 | { |
---|
| 223 | delete [] m_ppcResiYuvTemp; |
---|
| 224 | m_ppcResiYuvTemp = NULL; |
---|
| 225 | } |
---|
| 226 | if(m_ppcRecoYuvTemp) |
---|
| 227 | { |
---|
| 228 | delete [] m_ppcRecoYuvTemp; |
---|
| 229 | m_ppcRecoYuvTemp = NULL; |
---|
| 230 | } |
---|
| 231 | if(m_ppcOrigYuv) |
---|
| 232 | { |
---|
| 233 | delete [] m_ppcOrigYuv; |
---|
| 234 | m_ppcOrigYuv = NULL; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | /** \param pcEncTop pointer of encoder class |
---|
| 239 | */ |
---|
| 240 | Void TEncCu::init( TEncTop* pcEncTop ) |
---|
| 241 | { |
---|
| 242 | m_pcEncCfg = pcEncTop; |
---|
| 243 | m_pcPredSearch = pcEncTop->getPredSearch(); |
---|
| 244 | m_pcTrQuant = pcEncTop->getTrQuant(); |
---|
| 245 | m_pcBitCounter = pcEncTop->getBitCounter(); |
---|
| 246 | m_pcRdCost = pcEncTop->getRdCost(); |
---|
[56] | 247 | |
---|
[2] | 248 | m_pcEntropyCoder = pcEncTop->getEntropyCoder(); |
---|
| 249 | m_pcCavlcCoder = pcEncTop->getCavlcCoder(); |
---|
| 250 | m_pcSbacCoder = pcEncTop->getSbacCoder(); |
---|
| 251 | m_pcBinCABAC = pcEncTop->getBinCABAC(); |
---|
[56] | 252 | |
---|
[2] | 253 | m_pppcRDSbacCoder = pcEncTop->getRDSbacCoder(); |
---|
| 254 | m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); |
---|
[56] | 255 | |
---|
[2] | 256 | m_bUseSBACRD = pcEncTop->getUseSBACRD(); |
---|
[608] | 257 | m_pcRateCtrl = pcEncTop->getRateCtrl(); |
---|
[2] | 258 | } |
---|
| 259 | |
---|
| 260 | // ==================================================================================================================== |
---|
| 261 | // Public member functions |
---|
| 262 | // ==================================================================================================================== |
---|
| 263 | |
---|
| 264 | /** \param rpcCU pointer of CU data class |
---|
| 265 | */ |
---|
| 266 | Void TEncCu::compressCU( TComDataCU*& rpcCU ) |
---|
| 267 | { |
---|
[56] | 268 | // initialize CU data |
---|
| 269 | m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 270 | m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); |
---|
| 271 | |
---|
[655] | 272 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 273 | #if !M0036_RC_IMPROVEMENT |
---|
[608] | 274 | m_addSADDepth = 0; |
---|
| 275 | m_LCUPredictionSAD = 0; |
---|
| 276 | m_temporalSAD = 0; |
---|
| 277 | #endif |
---|
[655] | 278 | #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 279 | m_LCUPredictionSAD = 0; |
---|
| 280 | m_addSADDepth = 0; |
---|
| 281 | m_temporalSAD = 0; |
---|
| 282 | m_spatialSAD = 0; |
---|
| 283 | #endif |
---|
| 284 | #endif |
---|
| 285 | #if KWU_RC_MADPRED_E0227 |
---|
| 286 | m_LCUPredictionSAD = 0; |
---|
| 287 | m_addSADDepth = 0; |
---|
| 288 | m_temporalSAD = 0; |
---|
| 289 | m_spatialSAD = 0; |
---|
| 290 | #endif |
---|
[608] | 291 | |
---|
[56] | 292 | // analysis of CU |
---|
| 293 | xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); |
---|
| 294 | |
---|
| 295 | #if ADAPTIVE_QP_SELECTION |
---|
| 296 | if( m_pcEncCfg->getUseAdaptQpSelect() ) |
---|
[2] | 297 | { |
---|
[56] | 298 | if(rpcCU->getSlice()->getSliceType()!=I_SLICE) //IIII |
---|
| 299 | { |
---|
| 300 | xLcuCollectARLStats( rpcCU); |
---|
| 301 | } |
---|
[2] | 302 | } |
---|
[56] | 303 | #endif |
---|
| 304 | } |
---|
[608] | 305 | /** \param pcCU pointer of CU data class |
---|
[56] | 306 | */ |
---|
[608] | 307 | Void TEncCu::encodeCU ( TComDataCU* pcCU ) |
---|
[56] | 308 | { |
---|
| 309 | if ( pcCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 310 | { |
---|
[56] | 311 | setdQPFlag(true); |
---|
| 312 | } |
---|
[2] | 313 | |
---|
[56] | 314 | // Encode CU data |
---|
| 315 | xEncodeCU( pcCU, 0, 0 ); |
---|
[2] | 316 | } |
---|
| 317 | |
---|
[56] | 318 | // ==================================================================================================================== |
---|
| 319 | // Protected member functions |
---|
| 320 | // ==================================================================================================================== |
---|
| 321 | /** Derive small set of test modes for AMP encoder speed-up |
---|
| 322 | *\param rpcBestCU |
---|
| 323 | *\param eParentPartSize |
---|
| 324 | *\param bTestAMP_Hor |
---|
| 325 | *\param bTestAMP_Ver |
---|
| 326 | *\param bTestMergeAMP_Hor |
---|
| 327 | *\param bTestMergeAMP_Ver |
---|
| 328 | *\returns Void |
---|
| 329 | */ |
---|
| 330 | #if AMP_ENC_SPEEDUP |
---|
| 331 | #if AMP_MRG |
---|
| 332 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver) |
---|
| 333 | #else |
---|
| 334 | Void TEncCu::deriveTestModeAMP (TComDataCU *&rpcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver) |
---|
| 335 | #endif |
---|
[2] | 336 | { |
---|
[56] | 337 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
[2] | 338 | { |
---|
[56] | 339 | bTestAMP_Hor = true; |
---|
[2] | 340 | } |
---|
[56] | 341 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
[2] | 342 | { |
---|
[56] | 343 | bTestAMP_Ver = true; |
---|
| 344 | } |
---|
| 345 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->getMergeFlag(0) == false && rpcBestCU->isSkipped(0) == false ) |
---|
| 346 | { |
---|
| 347 | bTestAMP_Hor = true; |
---|
| 348 | bTestAMP_Ver = true; |
---|
| 349 | } |
---|
[2] | 350 | |
---|
[56] | 351 | #if AMP_MRG |
---|
| 352 | //! Utilizing the partition size of parent PU |
---|
| 353 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 354 | { |
---|
| 355 | bTestMergeAMP_Hor = true; |
---|
| 356 | bTestMergeAMP_Ver = true; |
---|
[2] | 357 | } |
---|
[56] | 358 | |
---|
| 359 | if ( eParentPartSize == SIZE_NONE ) //! if parent is intra |
---|
[2] | 360 | { |
---|
[56] | 361 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2NxN ) |
---|
[2] | 362 | { |
---|
[56] | 363 | bTestMergeAMP_Hor = true; |
---|
[2] | 364 | } |
---|
[56] | 365 | else if ( rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
[2] | 366 | { |
---|
[56] | 367 | bTestMergeAMP_Ver = true; |
---|
[2] | 368 | } |
---|
| 369 | } |
---|
| 370 | |
---|
[56] | 371 | if ( rpcBestCU->getPartitionSize(0) == SIZE_2Nx2N && rpcBestCU->isSkipped(0) == false ) |
---|
| 372 | { |
---|
| 373 | bTestMergeAMP_Hor = true; |
---|
| 374 | bTestMergeAMP_Ver = true; |
---|
| 375 | } |
---|
[2] | 376 | |
---|
[56] | 377 | if ( rpcBestCU->getWidth(0) == 64 ) |
---|
| 378 | { |
---|
| 379 | bTestAMP_Hor = false; |
---|
| 380 | bTestAMP_Ver = false; |
---|
| 381 | } |
---|
| 382 | #else |
---|
| 383 | //! Utilizing the partition size of parent PU |
---|
| 384 | if ( eParentPartSize >= SIZE_2NxnU && eParentPartSize <= SIZE_nRx2N ) |
---|
| 385 | { |
---|
| 386 | bTestAMP_Hor = true; |
---|
| 387 | bTestAMP_Ver = true; |
---|
| 388 | } |
---|
[2] | 389 | |
---|
[56] | 390 | if ( eParentPartSize == SIZE_2Nx2N ) |
---|
| 391 | { |
---|
| 392 | bTestAMP_Hor = false; |
---|
| 393 | bTestAMP_Ver = false; |
---|
| 394 | } |
---|
| 395 | #endif |
---|
[2] | 396 | } |
---|
[56] | 397 | #endif |
---|
[2] | 398 | |
---|
| 399 | // ==================================================================================================================== |
---|
| 400 | // Protected member functions |
---|
| 401 | // ==================================================================================================================== |
---|
[56] | 402 | /** Compress a CU block recursively with enabling sub-LCU-level delta QP |
---|
| 403 | *\param rpcBestCU |
---|
| 404 | *\param rpcTempCU |
---|
| 405 | *\param uiDepth |
---|
| 406 | *\returns Void |
---|
| 407 | * |
---|
| 408 | *- for loop of QP value to compress the current CU with all possible QP |
---|
| 409 | */ |
---|
| 410 | #if AMP_ENC_SPEEDUP |
---|
| 411 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth, PartSize eParentPartSize ) |
---|
| 412 | #else |
---|
[2] | 413 | Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
[56] | 414 | #endif |
---|
[2] | 415 | { |
---|
| 416 | TComPic* pcPic = rpcBestCU->getPic(); |
---|
| 417 | |
---|
[608] | 418 | #if H_3D_QTLPC |
---|
| 419 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
| 420 | TComPic *pcTexture = rpcBestCU->getSlice()->getTexturePic(); |
---|
[189] | 421 | |
---|
| 422 | Bool depthMapDetect = (pcTexture != NULL); |
---|
| 423 | Bool bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE); |
---|
| 424 | |
---|
[608] | 425 | Bool rapPic = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA); |
---|
[296] | 426 | |
---|
[608] | 427 | Bool bTry2NxN = true; |
---|
| 428 | Bool bTryNx2N = true; |
---|
[115] | 429 | #endif |
---|
[2] | 430 | // get Original YUV data from picture |
---|
| 431 | m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() ); |
---|
| 432 | |
---|
| 433 | // variables for fast encoder decision |
---|
[655] | 434 | #if H_3D_QTLPC |
---|
| 435 | Bool bTrySplit = true; |
---|
| 436 | Bool bTrySplitDQP = true; |
---|
| 437 | #endif |
---|
[2] | 438 | |
---|
[56] | 439 | // variable for Early CU determination |
---|
| 440 | Bool bSubBranch = true; |
---|
| 441 | |
---|
| 442 | // variable for Cbf fast mode PU decision |
---|
| 443 | Bool doNotBlockPu = true; |
---|
[608] | 444 | Bool earlyDetectionSkipMode = false; |
---|
[56] | 445 | |
---|
[622] | 446 | #if H_3D_VSP |
---|
[608] | 447 | DisInfo DvInfo; |
---|
| 448 | DvInfo.bDV = false; |
---|
| 449 | DvInfo.m_acNBDV.setZero(); |
---|
| 450 | DvInfo.m_aVIdxCan = 0; |
---|
| 451 | #if H_3D_NBDV_REF |
---|
| 452 | DvInfo.m_acDoNBDV.setZero(); |
---|
| 453 | #endif |
---|
| 454 | #endif |
---|
[2] | 455 | Bool bBoundary = false; |
---|
| 456 | UInt uiLPelX = rpcBestCU->getCUPelX(); |
---|
| 457 | UInt uiRPelX = uiLPelX + rpcBestCU->getWidth(0) - 1; |
---|
| 458 | UInt uiTPelY = rpcBestCU->getCUPelY(); |
---|
| 459 | UInt uiBPelY = uiTPelY + rpcBestCU->getHeight(0) - 1; |
---|
| 460 | |
---|
[56] | 461 | Int iBaseQP = xComputeQP( rpcBestCU, uiDepth ); |
---|
| 462 | Int iMinQP; |
---|
| 463 | Int iMaxQP; |
---|
| 464 | Bool isAddLowestQP = false; |
---|
| 465 | Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
| 466 | |
---|
| 467 | if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
[2] | 468 | { |
---|
[56] | 469 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
| 470 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 471 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
| 472 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 473 | { |
---|
[56] | 474 | isAddLowestQP = true; |
---|
| 475 | iMinQP = iMinQP - 1; |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | else |
---|
| 479 | { |
---|
| 480 | iMinQP = rpcTempCU->getQP(0); |
---|
| 481 | iMaxQP = rpcTempCU->getQP(0); |
---|
| 482 | } |
---|
| 483 | |
---|
[608] | 484 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 485 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 486 | { |
---|
| 487 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 488 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 489 | } |
---|
| 490 | #else |
---|
| 491 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
| 492 | { |
---|
| 493 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
| 494 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 495 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 496 | } |
---|
| 497 | #endif |
---|
| 498 | #if H_3D_IC |
---|
| 499 | Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ); |
---|
| 500 | bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC(); |
---|
| 501 | #endif |
---|
[56] | 502 | // If slice start or slice end is within this cu... |
---|
| 503 | TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); |
---|
[608] | 504 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); |
---|
| 505 | Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); |
---|
[56] | 506 | Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
| 507 | // We need to split, so don't try these modes. |
---|
| 508 | if(!bSliceEnd && !bSliceStart && bInsidePicture ) |
---|
| 509 | { |
---|
[655] | 510 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 511 | Bool bIVFMerge = false; |
---|
| 512 | Int iIVFMaxD = 0; |
---|
| 513 | Bool bFMD = false; |
---|
| 514 | #endif |
---|
[56] | 515 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 516 | { |
---|
| 517 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
[2] | 518 | { |
---|
[56] | 519 | iQP = lowestQP; |
---|
[2] | 520 | } |
---|
[56] | 521 | // variables for fast encoder decision |
---|
[655] | 522 | #if H_3D_QTLPC |
---|
[608] | 523 | bTrySplit = true; |
---|
[655] | 524 | #endif |
---|
[2] | 525 | |
---|
[56] | 526 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[608] | 527 | #if H_3D_QTLPC |
---|
[116] | 528 | //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU |
---|
[296] | 529 | |
---|
[608] | 530 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL()) |
---|
[116] | 531 | { |
---|
[189] | 532 | TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU |
---|
| 533 | UInt uiCUIdx = rpcBestCU->getZorderIdxInCU(); |
---|
| 534 | assert(pcTextureCU->getDepth(uiCUIdx) >= uiDepth); //Depth cannot be more partitionned than the texture. |
---|
| 535 | if (pcTextureCU->getDepth(uiCUIdx) > uiDepth || pcTextureCU->getPartitionSize(uiCUIdx) == SIZE_NxN) //Texture was split. |
---|
[116] | 536 | { |
---|
| 537 | bTrySplit = true; |
---|
[189] | 538 | bTryNx2N = true; |
---|
| 539 | bTry2NxN = true; |
---|
[116] | 540 | } |
---|
[189] | 541 | else |
---|
[116] | 542 | { |
---|
| 543 | bTrySplit = false; |
---|
[189] | 544 | bTryNx2N = false; |
---|
| 545 | bTry2NxN = false; |
---|
[116] | 546 | } |
---|
| 547 | } |
---|
[115] | 548 | #endif |
---|
[608] | 549 | |
---|
| 550 | #if H_3D_NBDV |
---|
[443] | 551 | if( rpcTempCU->getSlice()->getSliceType() != I_SLICE ) |
---|
| 552 | { |
---|
[608] | 553 | #if H_3D_ARP && H_3D_IV_MERGE |
---|
| 554 | if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) || rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) ) |
---|
| 555 | #else |
---|
| 556 | #if H_3D_ARP |
---|
| 557 | if( rpcTempCU->getSlice()->getVPS()->getUseAdvRP(rpcTempCU->getSlice()->getLayerId()) ) |
---|
[443] | 558 | #else |
---|
[608] | 559 | #if H_3D_IV_MERGE |
---|
| 560 | if( rpcTempCU->getSlice()->getVPS()->getIvMvPredFlag(rpcTempCU->getSlice()->getLayerId()) ) |
---|
| 561 | #else |
---|
| 562 | if (0) |
---|
[443] | 563 | #endif |
---|
[608] | 564 | #endif |
---|
| 565 | #endif |
---|
| 566 | { |
---|
[443] | 567 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
| 568 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
[608] | 569 | #if H_3D_NBDV_REF |
---|
| 570 | if(rpcTempCU->getSlice()->getVPS()->getDepthRefinementFlag( rpcTempCU->getSlice()->getLayerIdInVps())) |
---|
| 571 | DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo, true); |
---|
| 572 | else |
---|
| 573 | #endif |
---|
| 574 | DvInfo.bDV = rpcTempCU->getDisMvpCandNBDV(&DvInfo); |
---|
| 575 | |
---|
[443] | 576 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 577 | rpcBestCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 578 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
| 579 | } |
---|
[608] | 580 | } |
---|
[655] | 581 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 582 | if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth()) |
---|
| 583 | { |
---|
| 584 | PartSize ePartTemp = rpcTempCU->getPartitionSize(0); |
---|
| 585 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 586 | rpcTempCU->getIVNStatus( 0, &DvInfo, bIVFMerge, iIVFMaxD); |
---|
| 587 | rpcTempCU->setPartSizeSubParts( ePartTemp, 0, uiDepth ); |
---|
| 588 | } |
---|
[443] | 589 | #endif |
---|
| 590 | #endif |
---|
[56] | 591 | // do inter modes, SKIP and 2Nx2N |
---|
| 592 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
[2] | 593 | { |
---|
[608] | 594 | #if H_3D_IC |
---|
| 595 | for( UInt uiICId = 0; uiICId < ( bICEnabled ? 2 : 1 ); uiICId++ ) |
---|
[443] | 596 | { |
---|
[608] | 597 | Bool bICFlag = uiICId ? true : false; |
---|
[443] | 598 | #endif |
---|
[608] | 599 | // 2Nx2N |
---|
| 600 | if(m_pcEncCfg->getUseEarlySkipDetection()) |
---|
[56] | 601 | { |
---|
[608] | 602 | #if H_3D_IC |
---|
| 603 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
[56] | 604 | #endif |
---|
[655] | 605 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 606 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N |
---|
| 607 | #else |
---|
| 608 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N |
---|
[189] | 609 | #endif |
---|
[622] | 610 | #if H_3D_VSP |
---|
[608] | 611 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[5] | 612 | #endif |
---|
[608] | 613 | } |
---|
| 614 | // SKIP |
---|
| 615 | #if H_3D_IC |
---|
| 616 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
[2] | 617 | #endif |
---|
[608] | 618 | xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N |
---|
[655] | 619 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 620 | bFMD = bIVFMerge && rpcBestCU->isSkipped(0); |
---|
| 621 | #endif |
---|
| 622 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 623 | #if H_3D_VSP |
---|
[608] | 624 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 625 | #endif |
---|
| 626 | |
---|
| 627 | if(!m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 628 | { |
---|
[116] | 629 | // 2Nx2N, NxN |
---|
[608] | 630 | #if H_3D_IC |
---|
[296] | 631 | rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth); |
---|
| 632 | #endif |
---|
[655] | 633 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 634 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[2] | 635 | #else |
---|
[608] | 636 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[2] | 637 | #endif |
---|
[622] | 638 | #if H_3D_VSP |
---|
[608] | 639 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 640 | #endif |
---|
[116] | 641 | if(m_pcEncCfg->getUseCbfFastMode()) |
---|
| 642 | { |
---|
| 643 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 644 | } |
---|
[608] | 645 | } |
---|
| 646 | #if H_3D_IC |
---|
| 647 | } |
---|
[189] | 648 | #endif |
---|
[608] | 649 | } |
---|
[56] | 650 | |
---|
[655] | 651 | #if H_3D_QTLPC |
---|
[608] | 652 | if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL()) |
---|
[116] | 653 | { |
---|
| 654 | bTrySplitDQP = bTrySplit; |
---|
| 655 | } |
---|
[189] | 656 | #endif |
---|
[56] | 657 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
| 658 | { |
---|
| 659 | iQP = iMinQP; |
---|
| 660 | } |
---|
[608] | 661 | } |
---|
| 662 | |
---|
| 663 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 664 | if ( uiDepth <= m_addSADDepth ) |
---|
| 665 | { |
---|
| 666 | m_LCUPredictionSAD += m_temporalSAD; |
---|
| 667 | m_addSADDepth = uiDepth; |
---|
| 668 | } |
---|
[5] | 669 | #endif |
---|
[655] | 670 | #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 671 | if ( uiDepth <= m_addSADDepth ) |
---|
| 672 | { |
---|
| 673 | m_LCUPredictionSAD += m_temporalSAD; |
---|
| 674 | m_addSADDepth = uiDepth; |
---|
| 675 | } |
---|
| 676 | #endif |
---|
| 677 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 |
---|
| 678 | if ( uiDepth <= m_addSADDepth ) |
---|
| 679 | { |
---|
| 680 | m_LCUPredictionSAD += m_temporalSAD; |
---|
| 681 | m_addSADDepth = uiDepth; |
---|
| 682 | } |
---|
| 683 | #endif |
---|
| 684 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ |
---|
| 685 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
| 686 | { |
---|
| 687 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
| 688 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 689 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 690 | } |
---|
| 691 | #endif |
---|
[56] | 692 | |
---|
[608] | 693 | #if H_3D_DIM_ENC |
---|
| 694 | if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) |
---|
[56] | 695 | { |
---|
[608] | 696 | earlyDetectionSkipMode = false; |
---|
| 697 | } |
---|
[56] | 698 | #endif |
---|
[2] | 699 | |
---|
[608] | 700 | if(!earlyDetectionSkipMode) |
---|
| 701 | { |
---|
| 702 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
[2] | 703 | { |
---|
[608] | 704 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
[443] | 705 | { |
---|
[608] | 706 | iQP = lowestQP; |
---|
[443] | 707 | } |
---|
[608] | 708 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 709 | |
---|
| 710 | // do inter modes, NxN, 2NxN, and Nx2N |
---|
| 711 | if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) |
---|
[2] | 712 | { |
---|
[116] | 713 | // 2Nx2N, NxN |
---|
[608] | 714 | if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) |
---|
[116] | 715 | { |
---|
[608] | 716 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu |
---|
| 717 | #if H_3D_QTLPC |
---|
| 718 | && bTrySplit |
---|
| 719 | #endif |
---|
| 720 | ) |
---|
[116] | 721 | { |
---|
[655] | 722 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 723 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD ); |
---|
[115] | 724 | #else |
---|
[608] | 725 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
[115] | 726 | #endif |
---|
[608] | 727 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 728 | #if H_3D_VSP |
---|
[608] | 729 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[116] | 730 | #endif |
---|
[608] | 731 | } |
---|
[116] | 732 | } |
---|
[56] | 733 | |
---|
[608] | 734 | // 2NxN, Nx2N |
---|
| 735 | if(doNotBlockPu |
---|
| 736 | #if H_3D_QTLPC |
---|
| 737 | && bTryNx2N |
---|
[115] | 738 | #endif |
---|
[608] | 739 | ) |
---|
| 740 | { |
---|
[655] | 741 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 742 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD ); |
---|
[115] | 743 | #else |
---|
[608] | 744 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); |
---|
[115] | 745 | #endif |
---|
[608] | 746 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 747 | #if H_3D_VSP |
---|
[608] | 748 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[115] | 749 | #endif |
---|
[608] | 750 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N ) |
---|
[116] | 751 | { |
---|
[608] | 752 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | if(doNotBlockPu |
---|
| 756 | #if H_3D_QTLPC |
---|
| 757 | && bTry2NxN |
---|
[115] | 758 | #endif |
---|
[608] | 759 | ) |
---|
| 760 | { |
---|
[655] | 761 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 762 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD ); |
---|
| 763 | #else |
---|
| 764 | xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); |
---|
[115] | 765 | #endif |
---|
[608] | 766 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 767 | #if H_3D_VSP |
---|
[608] | 768 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[296] | 769 | #endif |
---|
[608] | 770 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN) |
---|
| 771 | { |
---|
| 772 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[115] | 773 | } |
---|
| 774 | } |
---|
[56] | 775 | |
---|
| 776 | #if 1 |
---|
[116] | 777 | //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) |
---|
| 778 | if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) |
---|
| 779 | { |
---|
[56] | 780 | #if AMP_ENC_SPEEDUP |
---|
[116] | 781 | Bool bTestAMP_Hor = false, bTestAMP_Ver = false; |
---|
[56] | 782 | |
---|
| 783 | #if AMP_MRG |
---|
[116] | 784 | Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; |
---|
[56] | 785 | |
---|
[116] | 786 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); |
---|
[2] | 787 | #else |
---|
[116] | 788 | deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); |
---|
[56] | 789 | #endif |
---|
| 790 | |
---|
[116] | 791 | //! Do horizontal AMP |
---|
| 792 | if ( bTestAMP_Hor ) |
---|
| 793 | { |
---|
[608] | 794 | if(doNotBlockPu |
---|
| 795 | #if H_3D_QTLPC |
---|
| 796 | && bTry2NxN |
---|
| 797 | #endif |
---|
| 798 | ) |
---|
[116] | 799 | { |
---|
[655] | 800 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 801 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD ); |
---|
| 802 | #else |
---|
| 803 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
[115] | 804 | #endif |
---|
[608] | 805 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 806 | #if H_3D_VSP |
---|
[608] | 807 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 808 | #endif |
---|
| 809 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
[116] | 810 | { |
---|
[608] | 811 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | if(doNotBlockPu |
---|
| 815 | #if H_3D_QTLPC |
---|
| 816 | && bTry2NxN |
---|
[115] | 817 | #endif |
---|
[608] | 818 | ) |
---|
| 819 | { |
---|
[655] | 820 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 821 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD ); |
---|
[115] | 822 | #else |
---|
[608] | 823 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
[115] | 824 | #endif |
---|
[608] | 825 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 826 | #if H_3D_VSP |
---|
[608] | 827 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 828 | #endif |
---|
| 829 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
[116] | 830 | { |
---|
[608] | 831 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[116] | 832 | } |
---|
[115] | 833 | } |
---|
| 834 | } |
---|
[56] | 835 | #if AMP_MRG |
---|
[116] | 836 | else if ( bTestMergeAMP_Hor ) |
---|
| 837 | { |
---|
[608] | 838 | if(doNotBlockPu |
---|
| 839 | #if H_3D_QTLPC |
---|
| 840 | && bTry2NxN |
---|
| 841 | #endif |
---|
| 842 | ) |
---|
[116] | 843 | { |
---|
[655] | 844 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 845 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true ); |
---|
| 846 | #else |
---|
| 847 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); |
---|
[115] | 848 | #endif |
---|
[608] | 849 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 850 | #if H_3D_VSP |
---|
[608] | 851 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 852 | #endif |
---|
| 853 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) |
---|
[116] | 854 | { |
---|
[608] | 855 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 856 | } |
---|
| 857 | } |
---|
| 858 | if(doNotBlockPu |
---|
| 859 | #if H_3D_QTLPC |
---|
| 860 | && bTry2NxN |
---|
[115] | 861 | #endif |
---|
[608] | 862 | ) |
---|
| 863 | { |
---|
[655] | 864 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 865 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true ); |
---|
[115] | 866 | #else |
---|
[608] | 867 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); |
---|
[115] | 868 | #endif |
---|
[608] | 869 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 870 | #if H_3D_VSP |
---|
[608] | 871 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 872 | #endif |
---|
| 873 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) |
---|
[116] | 874 | { |
---|
[608] | 875 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
[116] | 876 | } |
---|
[115] | 877 | } |
---|
| 878 | } |
---|
| 879 | #endif |
---|
[2] | 880 | |
---|
[116] | 881 | //! Do horizontal AMP |
---|
| 882 | if ( bTestAMP_Ver ) |
---|
| 883 | { |
---|
[608] | 884 | if(doNotBlockPu |
---|
| 885 | #if H_3D_QTLPC |
---|
| 886 | && bTryNx2N |
---|
| 887 | #endif |
---|
| 888 | ) |
---|
[116] | 889 | { |
---|
[655] | 890 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 891 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD ); |
---|
| 892 | #else |
---|
| 893 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
[115] | 894 | #endif |
---|
[608] | 895 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 896 | #if H_3D_VSP |
---|
[608] | 897 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 898 | #endif |
---|
| 899 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
[116] | 900 | { |
---|
[608] | 901 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | if(doNotBlockPu |
---|
| 905 | #if H_3D_QTLPC |
---|
| 906 | && bTryNx2N |
---|
[115] | 907 | #endif |
---|
[608] | 908 | ) |
---|
| 909 | { |
---|
[655] | 910 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 911 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD ); |
---|
[115] | 912 | #else |
---|
[608] | 913 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
[115] | 914 | #endif |
---|
[608] | 915 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 916 | #if H_3D_VSP |
---|
[608] | 917 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[115] | 918 | #endif |
---|
[116] | 919 | } |
---|
[115] | 920 | } |
---|
[56] | 921 | #if AMP_MRG |
---|
[116] | 922 | else if ( bTestMergeAMP_Ver ) |
---|
| 923 | { |
---|
[608] | 924 | if(doNotBlockPu |
---|
| 925 | #if H_3D_QTLPC |
---|
| 926 | && bTryNx2N |
---|
| 927 | #endif |
---|
| 928 | ) |
---|
[116] | 929 | { |
---|
[655] | 930 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 931 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true ); |
---|
| 932 | #else |
---|
| 933 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); |
---|
[115] | 934 | #endif |
---|
[608] | 935 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 936 | #if H_3D_VSP |
---|
[608] | 937 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
| 938 | #endif |
---|
| 939 | if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) |
---|
[116] | 940 | { |
---|
[608] | 941 | doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; |
---|
| 942 | } |
---|
| 943 | } |
---|
| 944 | if(doNotBlockPu |
---|
| 945 | #if H_3D_QTLPC |
---|
| 946 | && bTryNx2N |
---|
[115] | 947 | #endif |
---|
[608] | 948 | ) |
---|
| 949 | { |
---|
[655] | 950 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 951 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true ); |
---|
[115] | 952 | #else |
---|
[608] | 953 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); |
---|
[115] | 954 | #endif |
---|
[608] | 955 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 956 | #if H_3D_VSP |
---|
[608] | 957 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[115] | 958 | #endif |
---|
[116] | 959 | } |
---|
[115] | 960 | } |
---|
[56] | 961 | #endif |
---|
[2] | 962 | |
---|
[56] | 963 | #else |
---|
[608] | 964 | #if H_3D_QTLPC |
---|
| 965 | if (bTry2NxN) |
---|
| 966 | { |
---|
[5] | 967 | #endif |
---|
[608] | 968 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); |
---|
| 969 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 970 | #if H_3D_VSP |
---|
[608] | 971 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[56] | 972 | #endif |
---|
[608] | 973 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); |
---|
| 974 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 975 | #if H_3D_VSP |
---|
[608] | 976 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[56] | 977 | #endif |
---|
[608] | 978 | #if H_3D_QTLPC |
---|
| 979 | } |
---|
| 980 | if (bTryNx2N) |
---|
| 981 | { |
---|
[56] | 982 | #endif |
---|
[608] | 983 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); |
---|
| 984 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 985 | #if H_3D_VSP |
---|
[608] | 986 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[56] | 987 | #endif |
---|
[608] | 988 | xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); |
---|
| 989 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[622] | 990 | #if H_3D_VSP |
---|
[608] | 991 | rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); |
---|
[56] | 992 | #endif |
---|
[608] | 993 | #if H_3D_QTLPC |
---|
| 994 | } |
---|
[56] | 995 | #endif |
---|
[2] | 996 | |
---|
[56] | 997 | #endif |
---|
[608] | 998 | } |
---|
[56] | 999 | #endif |
---|
[608] | 1000 | } |
---|
[655] | 1001 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1002 | if(!bFMD) |
---|
| 1003 | { |
---|
[189] | 1004 | #endif |
---|
[608] | 1005 | // do normal intra modes |
---|
[655] | 1006 | |
---|
[608] | 1007 | // speedup for inter frames |
---|
| 1008 | if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || |
---|
| 1009 | rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || |
---|
| 1010 | rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || |
---|
| 1011 | rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 |
---|
| 1012 | #if H_3D_DIM_ENC |
---|
| 1013 | || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) |
---|
[189] | 1014 | #endif |
---|
[608] | 1015 | ) // avoid very complex intra if it is unlikely |
---|
[2] | 1016 | { |
---|
[608] | 1017 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); |
---|
[655] | 1018 | |
---|
| 1019 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 1020 | if ( uiDepth <= m_addSADDepth ) |
---|
| 1021 | { |
---|
| 1022 | m_LCUPredictionSAD += m_spatialSAD; |
---|
| 1023 | m_addSADDepth = uiDepth; |
---|
| 1024 | } |
---|
| 1025 | #endif |
---|
| 1026 | #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 1027 | if ( uiDepth <= m_addSADDepth ) |
---|
| 1028 | { |
---|
| 1029 | m_LCUPredictionSAD += m_spatialSAD; |
---|
| 1030 | m_addSADDepth = uiDepth; |
---|
| 1031 | } |
---|
| 1032 | #endif |
---|
| 1033 | |
---|
| 1034 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 |
---|
| 1035 | if ( uiDepth <= m_addSADDepth ) |
---|
| 1036 | { |
---|
| 1037 | m_LCUPredictionSAD += m_spatialSAD; |
---|
| 1038 | m_addSADDepth = uiDepth; |
---|
| 1039 | } |
---|
| 1040 | #endif |
---|
[608] | 1041 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 1042 | if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
[116] | 1043 | { |
---|
[608] | 1044 | #if H_3D_QTLPC //Try IntraNxN |
---|
| 1045 | if(bTrySplit) |
---|
[116] | 1046 | { |
---|
[189] | 1047 | #endif |
---|
[608] | 1048 | if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) |
---|
| 1049 | { |
---|
| 1050 | xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); |
---|
| 1051 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 1052 | } |
---|
| 1053 | #if H_3D_QTLPC |
---|
[116] | 1054 | } |
---|
[608] | 1055 | #endif |
---|
[56] | 1056 | } |
---|
[2] | 1057 | } |
---|
[608] | 1058 | // test PCM |
---|
| 1059 | if(pcPic->getSlice(0)->getSPS()->getUsePCM() |
---|
| 1060 | && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) |
---|
| 1061 | && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) |
---|
| 1062 | { |
---|
| 1063 | UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2; |
---|
| 1064 | UInt uiBestBits = rpcBestCU->getTotalBits(); |
---|
| 1065 | #if H_3D_VSO // M7 |
---|
| 1066 | Double dRDCostTemp = m_pcRdCost->getUseVSO() ? m_pcRdCost->calcRdCostVSO(uiRawBits, 0) : m_pcRdCost->calcRdCost(uiRawBits, 0); |
---|
| 1067 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > dRDCostTemp )) |
---|
[56] | 1068 | #else |
---|
[608] | 1069 | if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) |
---|
[56] | 1070 | #endif |
---|
[608] | 1071 | { |
---|
| 1072 | xCheckIntraPCM (rpcBestCU, rpcTempCU); |
---|
| 1073 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
| 1074 | } |
---|
| 1075 | } |
---|
[655] | 1076 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1077 | } |
---|
[189] | 1078 | #endif |
---|
[608] | 1079 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
[296] | 1080 | { |
---|
[608] | 1081 | iQP = iMinQP; |
---|
[296] | 1082 | } |
---|
[56] | 1083 | } |
---|
[2] | 1084 | } |
---|
| 1085 | |
---|
| 1086 | m_pcEntropyCoder->resetBits(); |
---|
| 1087 | m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); |
---|
| 1088 | rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
[56] | 1089 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1090 | { |
---|
| 1091 | rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1092 | } |
---|
[2] | 1093 | |
---|
[608] | 1094 | #if H_3D_VSO // M8 |
---|
| 1095 | if ( m_pcRdCost->getUseVSO() ) |
---|
| 1096 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
[2] | 1097 | else |
---|
[5] | 1098 | #endif |
---|
[608] | 1099 | rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); |
---|
[2] | 1100 | |
---|
[56] | 1101 | // Early CU determination |
---|
[608] | 1102 | if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) ) |
---|
[2] | 1103 | { |
---|
[56] | 1104 | bSubBranch = false; |
---|
[2] | 1105 | } |
---|
[56] | 1106 | else |
---|
| 1107 | { |
---|
| 1108 | bSubBranch = true; |
---|
| 1109 | } |
---|
[655] | 1110 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1111 | if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0)) |
---|
| 1112 | { |
---|
| 1113 | bSubBranch = false; |
---|
| 1114 | } |
---|
[2] | 1115 | #endif |
---|
| 1116 | } |
---|
[56] | 1117 | else if(!(bSliceEnd && bInsidePicture)) |
---|
[2] | 1118 | { |
---|
| 1119 | bBoundary = true; |
---|
[608] | 1120 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT |
---|
| 1121 | m_addSADDepth++; |
---|
| 1122 | #endif |
---|
[2] | 1123 | } |
---|
| 1124 | |
---|
[56] | 1125 | // copy orginal YUV samples to PCM buffer |
---|
| 1126 | if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false)) |
---|
[2] | 1127 | { |
---|
[56] | 1128 | xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]); |
---|
| 1129 | } |
---|
| 1130 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 1131 | { |
---|
| 1132 | Int idQP = m_pcEncCfg->getMaxDeltaQP(); |
---|
| 1133 | iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); |
---|
| 1134 | iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); |
---|
| 1135 | if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() ) |
---|
[2] | 1136 | { |
---|
[56] | 1137 | isAddLowestQP = true; |
---|
| 1138 | iMinQP = iMinQP - 1; |
---|
[2] | 1139 | } |
---|
[56] | 1140 | } |
---|
| 1141 | else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
| 1142 | { |
---|
| 1143 | iMinQP = iBaseQP; |
---|
| 1144 | iMaxQP = iBaseQP; |
---|
| 1145 | } |
---|
| 1146 | else |
---|
| 1147 | { |
---|
| 1148 | Int iStartQP; |
---|
[608] | 1149 | if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
[56] | 1150 | { |
---|
| 1151 | iStartQP = rpcTempCU->getQP(0); |
---|
| 1152 | } |
---|
| 1153 | else |
---|
| 1154 | { |
---|
[608] | 1155 | UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
[56] | 1156 | iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); |
---|
| 1157 | } |
---|
| 1158 | iMinQP = iStartQP; |
---|
| 1159 | iMaxQP = iStartQP; |
---|
| 1160 | } |
---|
[608] | 1161 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 1162 | if ( m_pcEncCfg->getUseRateCtrl() ) |
---|
| 1163 | { |
---|
| 1164 | iMinQP = m_pcRateCtrl->getRCQP(); |
---|
| 1165 | iMaxQP = m_pcRateCtrl->getRCQP(); |
---|
| 1166 | } |
---|
| 1167 | #else |
---|
| 1168 | if(m_pcEncCfg->getUseRateCtrl()) |
---|
| 1169 | { |
---|
| 1170 | Int qp = m_pcRateCtrl->getUnitQP(); |
---|
| 1171 | iMinQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 1172 | iMaxQP = Clip3( MIN_QP, MAX_QP, qp); |
---|
| 1173 | } |
---|
| 1174 | #endif |
---|
[56] | 1175 | for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) |
---|
| 1176 | { |
---|
[116] | 1177 | if (isAddLowestQP && (iQP == iMinQP)) |
---|
| 1178 | { |
---|
| 1179 | iQP = lowestQP; |
---|
| 1180 | } |
---|
[56] | 1181 | rpcTempCU->initEstData( uiDepth, iQP ); |
---|
[2] | 1182 | |
---|
[56] | 1183 | // further split |
---|
[655] | 1184 | #if H_3D_QTLPC |
---|
[56] | 1185 | if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
[655] | 1186 | #else |
---|
| 1187 | if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth ) |
---|
| 1188 | #endif |
---|
[2] | 1189 | { |
---|
[608] | 1190 | #if H_3D_VSO // M9 |
---|
[56] | 1191 | // reset Model |
---|
| 1192 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1193 | { |
---|
[81] | 1194 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth ( ); |
---|
| 1195 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight( ); |
---|
| 1196 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr( 0 ); |
---|
| 1197 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride(); |
---|
| 1198 | m_pcRdCost->setRenModelData( m_ppcBestCU[uiDepth], 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[56] | 1199 | } |
---|
| 1200 | #endif |
---|
[608] | 1201 | |
---|
[56] | 1202 | UChar uhNextDepth = uiDepth+1; |
---|
| 1203 | TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth]; |
---|
| 1204 | TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth]; |
---|
[2] | 1205 | |
---|
[56] | 1206 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ ) |
---|
[2] | 1207 | { |
---|
[56] | 1208 | pcSubBestPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 1209 | pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. |
---|
| 1210 | |
---|
[608] | 1211 | Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[56] | 1212 | if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[2] | 1213 | { |
---|
[56] | 1214 | if( m_bUseSBACRD ) |
---|
[2] | 1215 | { |
---|
[56] | 1216 | if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer |
---|
| 1217 | { |
---|
| 1218 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
| 1219 | } |
---|
| 1220 | else |
---|
| 1221 | { |
---|
| 1222 | m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); |
---|
| 1223 | } |
---|
[2] | 1224 | } |
---|
[56] | 1225 | |
---|
| 1226 | #if AMP_ENC_SPEEDUP |
---|
| 1227 | if ( rpcBestCU->isIntra(0) ) |
---|
| 1228 | { |
---|
| 1229 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, SIZE_NONE ); |
---|
| 1230 | } |
---|
[2] | 1231 | else |
---|
| 1232 | { |
---|
[56] | 1233 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth, rpcBestCU->getPartitionSize(0) ); |
---|
[2] | 1234 | } |
---|
[56] | 1235 | #else |
---|
| 1236 | xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth ); |
---|
| 1237 | #endif |
---|
[2] | 1238 | |
---|
[56] | 1239 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); // Keep best part data to current temporary data. |
---|
| 1240 | xCopyYuv2Tmp( pcSubBestPartCU->getTotalNumPart()*uiPartUnitIdx, uhNextDepth ); |
---|
| 1241 | } |
---|
| 1242 | else if (bInSlice) |
---|
[2] | 1243 | { |
---|
[56] | 1244 | pcSubBestPartCU->copyToPic( uhNextDepth ); |
---|
| 1245 | rpcTempCU->copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth ); |
---|
[2] | 1246 | } |
---|
| 1247 | } |
---|
| 1248 | |
---|
[56] | 1249 | if( !bBoundary ) |
---|
| 1250 | { |
---|
| 1251 | m_pcEntropyCoder->resetBits(); |
---|
| 1252 | m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth, true ); |
---|
[2] | 1253 | |
---|
[56] | 1254 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits |
---|
| 1255 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1256 | { |
---|
| 1257 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1258 | } |
---|
| 1259 | } |
---|
| 1260 | |
---|
[608] | 1261 | #if H_3D_VSO // M10 |
---|
[56] | 1262 | if ( m_pcRdCost->getUseVSO() ) |
---|
| 1263 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 1264 | else |
---|
[5] | 1265 | #endif |
---|
[608] | 1266 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[2] | 1267 | |
---|
[56] | 1268 | if( (g_uiMaxCUWidth>>uiDepth) == rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() && rpcTempCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1269 | { |
---|
[608] | 1270 | Bool hasResidual = false; |
---|
[56] | 1271 | for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) |
---|
| 1272 | { |
---|
[608] | 1273 | if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && |
---|
| 1274 | ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) |
---|
[56] | 1275 | { |
---|
[608] | 1276 | hasResidual = true; |
---|
[56] | 1277 | break; |
---|
| 1278 | } |
---|
| 1279 | } |
---|
[2] | 1280 | |
---|
[56] | 1281 | UInt uiTargetPartIdx; |
---|
[608] | 1282 | if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() ) |
---|
[56] | 1283 | { |
---|
[608] | 1284 | uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); |
---|
[56] | 1285 | } |
---|
| 1286 | else |
---|
| 1287 | { |
---|
| 1288 | uiTargetPartIdx = 0; |
---|
| 1289 | } |
---|
[608] | 1290 | if ( hasResidual ) |
---|
[56] | 1291 | { |
---|
| 1292 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 1293 | m_pcEntropyCoder->resetBits(); |
---|
| 1294 | m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); |
---|
| 1295 | rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
| 1296 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 1297 | { |
---|
| 1298 | rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 1299 | } |
---|
[608] | 1300 | #if H_3D_VSO // M11 |
---|
| 1301 | if ( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
| 1302 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[56] | 1303 | else |
---|
[5] | 1304 | #endif |
---|
[608] | 1305 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[56] | 1306 | #endif |
---|
[608] | 1307 | |
---|
| 1308 | Bool foundNonZeroCbf = false; |
---|
| 1309 | rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), rpcTempCU, 0, uiDepth, foundNonZeroCbf ); |
---|
| 1310 | assert( foundNonZeroCbf ); |
---|
[56] | 1311 | } |
---|
| 1312 | else |
---|
| 1313 | { |
---|
| 1314 | rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP |
---|
| 1315 | } |
---|
| 1316 | } |
---|
[2] | 1317 | |
---|
[56] | 1318 | if( m_bUseSBACRD ) |
---|
| 1319 | { |
---|
| 1320 | m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 1321 | } |
---|
[608] | 1322 | Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES |
---|
| 1323 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); |
---|
| 1324 | Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES |
---|
| 1325 | && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); |
---|
| 1326 | if(isEndOfSlice||isEndOfSliceSegment) |
---|
[56] | 1327 | { |
---|
| 1328 | rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; |
---|
| 1329 | } |
---|
| 1330 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction |
---|
| 1331 | } // with sub partitioned prediction. |
---|
[116] | 1332 | if (isAddLowestQP && (iQP == lowestQP)) |
---|
| 1333 | { |
---|
| 1334 | iQP = iMinQP; |
---|
| 1335 | } |
---|
[608] | 1336 | } |
---|
[56] | 1337 | |
---|
[608] | 1338 | |
---|
| 1339 | #if H_3D_VSO // M12 |
---|
[56] | 1340 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1341 | { |
---|
[116] | 1342 | UInt uiWidth = m_ppcRecoYuvBest[uiDepth]->getWidth ( ); |
---|
| 1343 | UInt uiHeight = m_ppcRecoYuvBest[uiDepth]->getHeight ( ); |
---|
| 1344 | Pel* piSrc = m_ppcRecoYuvBest[uiDepth]->getLumaAddr( 0 ); |
---|
| 1345 | UInt uiSrcStride = m_ppcRecoYuvBest[uiDepth]->getStride ( ); |
---|
| 1346 | m_pcRdCost->setRenModelData( rpcBestCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[56] | 1347 | } |
---|
| 1348 | #endif |
---|
| 1349 | |
---|
[2] | 1350 | rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. |
---|
| 1351 | |
---|
[56] | 1352 | xCopyYuv2Pic( rpcBestCU->getPic(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU(), uiDepth, uiDepth, rpcBestCU, uiLPelX, uiTPelY ); // Copy Yuv data to picture Yuv |
---|
| 1353 | if( bBoundary ||(bSliceEnd && bInsidePicture)) |
---|
| 1354 | { |
---|
[2] | 1355 | return; |
---|
[56] | 1356 | } |
---|
[2] | 1357 | |
---|
| 1358 | // Assert if Best prediction mode is NONE |
---|
| 1359 | // Selected mode's RD-cost must be not MAX_DOUBLE. |
---|
| 1360 | assert( rpcBestCU->getPartitionSize ( 0 ) != SIZE_NONE ); |
---|
| 1361 | assert( rpcBestCU->getPredictionMode( 0 ) != MODE_NONE ); |
---|
| 1362 | assert( rpcBestCU->getTotalCost ( ) != MAX_DOUBLE ); |
---|
| 1363 | } |
---|
| 1364 | |
---|
[56] | 1365 | /** finish encoding a cu and handle end-of-slice conditions |
---|
| 1366 | * \param pcCU |
---|
| 1367 | * \param uiAbsPartIdx |
---|
| 1368 | * \param uiDepth |
---|
| 1369 | * \returns Void |
---|
| 1370 | */ |
---|
| 1371 | Void TEncCu::finishCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1372 | { |
---|
| 1373 | TComPic* pcPic = pcCU->getPic(); |
---|
| 1374 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1375 | |
---|
| 1376 | //Calculate end address |
---|
| 1377 | UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; |
---|
| 1378 | |
---|
[608] | 1379 | UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 1380 | UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
[56] | 1381 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1382 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1383 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 1384 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
| 1385 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
| 1386 | { |
---|
| 1387 | uiInternalAddress--; |
---|
| 1388 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1389 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1390 | } |
---|
| 1391 | uiInternalAddress++; |
---|
| 1392 | if(uiInternalAddress==pcCU->getPic()->getNumPartInCU()) |
---|
| 1393 | { |
---|
| 1394 | uiInternalAddress = 0; |
---|
| 1395 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 1396 | } |
---|
| 1397 | UInt uiRealEndAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 1398 | |
---|
| 1399 | // Encode slice finish |
---|
| 1400 | Bool bTerminateSlice = false; |
---|
| 1401 | if (uiCUAddr+(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1)) == uiRealEndAddress) |
---|
| 1402 | { |
---|
| 1403 | bTerminateSlice = true; |
---|
| 1404 | } |
---|
[608] | 1405 | UInt uiGranularityWidth = g_uiMaxCUWidth; |
---|
[56] | 1406 | uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1407 | uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1408 | Bool granularityBoundary=((uiPosX+pcCU->getWidth(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosX+pcCU->getWidth(uiAbsPartIdx)==uiWidth)) |
---|
| 1409 | &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); |
---|
| 1410 | |
---|
[608] | 1411 | if(granularityBoundary) |
---|
[56] | 1412 | { |
---|
| 1413 | // The 1-terminating bit is added to all streams, so don't add it here when it's 1. |
---|
| 1414 | if (!bTerminateSlice) |
---|
| 1415 | m_pcEntropyCoder->encodeTerminatingBit( bTerminateSlice ? 1 : 0 ); |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | Int numberOfWrittenBits = 0; |
---|
| 1419 | if (m_pcBitCounter) |
---|
| 1420 | { |
---|
| 1421 | numberOfWrittenBits = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 1422 | } |
---|
| 1423 | |
---|
| 1424 | // Calculate slice end IF this CU puts us over slice bit size. |
---|
[608] | 1425 | UInt iGranularitySize = pcCU->getPic()->getNumPartInCU(); |
---|
| 1426 | Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; |
---|
| 1427 | if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
[56] | 1428 | { |
---|
| 1429 | iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); |
---|
| 1430 | } |
---|
| 1431 | // Set slice end parameter |
---|
[608] | 1432 | if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) |
---|
[56] | 1433 | { |
---|
[608] | 1434 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
[56] | 1435 | pcSlice->setSliceCurEndCUAddr(iGranularityEnd); |
---|
| 1436 | return; |
---|
| 1437 | } |
---|
[608] | 1438 | // Set dependent slice end parameter |
---|
| 1439 | if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) |
---|
[56] | 1440 | { |
---|
[608] | 1441 | pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); |
---|
| 1442 | return; |
---|
[56] | 1443 | } |
---|
| 1444 | if(granularityBoundary) |
---|
| 1445 | { |
---|
| 1446 | pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); |
---|
[608] | 1447 | pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits); |
---|
[56] | 1448 | if (m_pcBitCounter) |
---|
| 1449 | { |
---|
| 1450 | m_pcEntropyCoder->resetBits(); |
---|
| 1451 | } |
---|
| 1452 | } |
---|
| 1453 | } |
---|
| 1454 | |
---|
| 1455 | /** Compute QP for each CU |
---|
| 1456 | * \param pcCU Target CU |
---|
| 1457 | * \param uiDepth CU depth |
---|
| 1458 | * \returns quantization parameter |
---|
| 1459 | */ |
---|
| 1460 | Int TEncCu::xComputeQP( TComDataCU* pcCU, UInt uiDepth ) |
---|
| 1461 | { |
---|
| 1462 | Int iBaseQp = pcCU->getSlice()->getSliceQp(); |
---|
| 1463 | Int iQpOffset = 0; |
---|
| 1464 | if ( m_pcEncCfg->getUseAdaptiveQP() ) |
---|
| 1465 | { |
---|
| 1466 | TEncPic* pcEPic = dynamic_cast<TEncPic*>( pcCU->getPic() ); |
---|
| 1467 | UInt uiAQDepth = min( uiDepth, pcEPic->getMaxAQDepth()-1 ); |
---|
| 1468 | TEncPicQPAdaptationLayer* pcAQLayer = pcEPic->getAQLayer( uiAQDepth ); |
---|
| 1469 | UInt uiAQUPosX = pcCU->getCUPelX() / pcAQLayer->getAQPartWidth(); |
---|
| 1470 | UInt uiAQUPosY = pcCU->getCUPelY() / pcAQLayer->getAQPartHeight(); |
---|
| 1471 | UInt uiAQUStride = pcAQLayer->getAQPartStride(); |
---|
| 1472 | TEncQPAdaptationUnit* acAQU = pcAQLayer->getQPAdaptationUnit(); |
---|
| 1473 | |
---|
| 1474 | Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0); |
---|
| 1475 | Double dAvgAct = pcAQLayer->getAvgActivity(); |
---|
| 1476 | Double dCUAct = acAQU[uiAQUPosY * uiAQUStride + uiAQUPosX].getActivity(); |
---|
| 1477 | Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct); |
---|
| 1478 | Double dQpOffset = log(dNormAct) / log(2.0) * 6.0; |
---|
| 1479 | iQpOffset = Int(floor( dQpOffset + 0.49999 )); |
---|
| 1480 | } |
---|
| 1481 | return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset ); |
---|
| 1482 | } |
---|
| 1483 | |
---|
[2] | 1484 | /** encode a CU block recursively |
---|
| 1485 | * \param pcCU |
---|
| 1486 | * \param uiAbsPartIdx |
---|
[56] | 1487 | * \param uiDepth |
---|
[2] | 1488 | * \returns Void |
---|
| 1489 | */ |
---|
| 1490 | Void TEncCu::xEncodeCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1491 | { |
---|
| 1492 | TComPic* pcPic = pcCU->getPic(); |
---|
[56] | 1493 | |
---|
[2] | 1494 | Bool bBoundary = false; |
---|
| 1495 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1496 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 1497 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1498 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
[608] | 1499 | |
---|
| 1500 | #if H_MV_ENC_DEC_TRAC |
---|
| 1501 | DTRACE_CU_S("=========== coding_quadtree ===========\n") |
---|
| 1502 | DTRACE_CU("x0", uiLPelX) |
---|
| 1503 | DTRACE_CU("x1", uiTPelY) |
---|
| 1504 | DTRACE_CU("log2CbSize", g_uiMaxCUWidth>>uiDepth) |
---|
| 1505 | DTRACE_CU("cqtDepth" , uiDepth) |
---|
| 1506 | #endif |
---|
[443] | 1507 | |
---|
[56] | 1508 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
| 1509 | // If slice start is within this cu... |
---|
[608] | 1510 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 1511 | pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); |
---|
[56] | 1512 | // We need to split, so don't try these modes. |
---|
| 1513 | if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
[2] | 1514 | { |
---|
[56] | 1515 | m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth ); |
---|
[2] | 1516 | } |
---|
| 1517 | else |
---|
| 1518 | { |
---|
| 1519 | bBoundary = true; |
---|
| 1520 | } |
---|
[56] | 1521 | |
---|
[2] | 1522 | if( ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) ) && ( uiDepth < (g_uiMaxCUDepth-g_uiAddCUDepth) ) ) || bBoundary ) |
---|
| 1523 | { |
---|
| 1524 | UInt uiQNumParts = ( pcPic->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
[56] | 1525 | if( (g_uiMaxCUWidth>>uiDepth) == pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1526 | { |
---|
| 1527 | setdQPFlag(true); |
---|
| 1528 | } |
---|
[2] | 1529 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 1530 | { |
---|
| 1531 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
| 1532 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
[608] | 1533 | Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[56] | 1534 | if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
| 1535 | { |
---|
[2] | 1536 | xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 ); |
---|
[56] | 1537 | } |
---|
[2] | 1538 | } |
---|
| 1539 | return; |
---|
| 1540 | } |
---|
[56] | 1541 | |
---|
[608] | 1542 | #if H_MV_ENC_DEC_TRAC |
---|
| 1543 | DTRACE_CU_S("=========== coding_unit ===========\n") |
---|
| 1544 | #endif |
---|
| 1545 | |
---|
[56] | 1546 | if( (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() && pcCU->getSlice()->getPPS()->getUseDQP()) |
---|
| 1547 | { |
---|
| 1548 | setdQPFlag(true); |
---|
| 1549 | } |
---|
[608] | 1550 | if (pcCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 1551 | { |
---|
| 1552 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx ); |
---|
| 1553 | } |
---|
[5] | 1554 | if( !pcCU->getSlice()->isIntra() ) |
---|
[2] | 1555 | { |
---|
| 1556 | m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx ); |
---|
| 1557 | } |
---|
[56] | 1558 | |
---|
[2] | 1559 | if( pcCU->isSkipped( uiAbsPartIdx ) ) |
---|
| 1560 | { |
---|
[608] | 1561 | #if H_MV_ENC_DEC_TRAC |
---|
| 1562 | DTRACE_PU_S("=========== prediction_unit ===========\n") |
---|
| 1563 | DTRACE_PU("x0", uiLPelX) |
---|
| 1564 | DTRACE_PU("x1", uiTPelY) |
---|
[115] | 1565 | #endif |
---|
[608] | 1566 | m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); |
---|
| 1567 | #if H_3D_IC |
---|
| 1568 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
[296] | 1569 | #endif |
---|
[608] | 1570 | #if H_3D_ARP |
---|
| 1571 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
[443] | 1572 | #endif |
---|
[56] | 1573 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
[2] | 1574 | return; |
---|
| 1575 | } |
---|
[56] | 1576 | m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx ); |
---|
[608] | 1577 | |
---|
[56] | 1578 | m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth ); |
---|
[608] | 1579 | |
---|
[56] | 1580 | if (pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) |
---|
| 1581 | { |
---|
| 1582 | m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx ); |
---|
[2] | 1583 | |
---|
[56] | 1584 | if(pcCU->getIPCMFlag(uiAbsPartIdx)) |
---|
| 1585 | { |
---|
| 1586 | // Encode slice finish |
---|
| 1587 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
| 1588 | return; |
---|
| 1589 | } |
---|
| 1590 | } |
---|
[2] | 1591 | |
---|
[56] | 1592 | // prediction Info ( Intra : direction mode, Inter : Mv, reference idx ) |
---|
| 1593 | m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx ); |
---|
[608] | 1594 | #if H_3D_IC |
---|
| 1595 | m_pcEntropyCoder->encodeICFlag ( pcCU, uiAbsPartIdx ); |
---|
[189] | 1596 | #endif |
---|
[608] | 1597 | #if H_3D_ARP |
---|
| 1598 | m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx ); |
---|
[296] | 1599 | #endif |
---|
[655] | 1600 | #if H_3D_INTER_SDC |
---|
[608] | 1601 | m_pcEntropyCoder->encodeInterSDCFlag( pcCU, uiAbsPartIdx, false ); |
---|
[5] | 1602 | #endif |
---|
[608] | 1603 | |
---|
[2] | 1604 | // Encode Coefficients |
---|
[56] | 1605 | Bool bCodeDQP = getdQPFlag(); |
---|
| 1606 | m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, pcCU->getWidth (uiAbsPartIdx), pcCU->getHeight(uiAbsPartIdx), bCodeDQP ); |
---|
| 1607 | setdQPFlag( bCodeDQP ); |
---|
[2] | 1608 | |
---|
[56] | 1609 | // --- write terminating bit --- |
---|
| 1610 | finishCU(pcCU,uiAbsPartIdx,uiDepth); |
---|
[2] | 1611 | } |
---|
| 1612 | |
---|
[608] | 1613 | #if RATE_CONTROL_INTRA |
---|
| 1614 | Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) |
---|
| 1615 | { |
---|
| 1616 | Int k, i, j, jj; |
---|
| 1617 | Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0; |
---|
| 1618 | |
---|
| 1619 | for( k = 0; k < 64; k += 8 ) |
---|
| 1620 | { |
---|
| 1621 | diff[k+0] = piOrg[0] ; |
---|
| 1622 | diff[k+1] = piOrg[1] ; |
---|
| 1623 | diff[k+2] = piOrg[2] ; |
---|
| 1624 | diff[k+3] = piOrg[3] ; |
---|
| 1625 | diff[k+4] = piOrg[4] ; |
---|
| 1626 | diff[k+5] = piOrg[5] ; |
---|
| 1627 | diff[k+6] = piOrg[6] ; |
---|
| 1628 | diff[k+7] = piOrg[7] ; |
---|
| 1629 | |
---|
| 1630 | piOrg += iStrideOrg; |
---|
| 1631 | } |
---|
| 1632 | |
---|
| 1633 | //horizontal |
---|
| 1634 | for (j=0; j < 8; j++) |
---|
| 1635 | { |
---|
| 1636 | jj = j << 3; |
---|
| 1637 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1638 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1639 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1640 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1641 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1642 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1643 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1644 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
| 1645 | |
---|
| 1646 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1647 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1648 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1649 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1650 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1651 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1652 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1653 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
| 1654 | |
---|
| 1655 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1656 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1657 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1658 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1659 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1660 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1661 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1662 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1663 | } |
---|
| 1664 | |
---|
| 1665 | //vertical |
---|
| 1666 | for (i=0; i < 8; i++) |
---|
| 1667 | { |
---|
| 1668 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1669 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1670 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1671 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1672 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1673 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1674 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1675 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
| 1676 | |
---|
| 1677 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1678 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1679 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1680 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1681 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1682 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1683 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1684 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
| 1685 | |
---|
| 1686 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1687 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1688 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1689 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1690 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1691 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1692 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1693 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1694 | } |
---|
| 1695 | |
---|
| 1696 | for (i = 0; i < 8; i++) |
---|
| 1697 | { |
---|
| 1698 | for (j = 0; j < 8; j++) |
---|
| 1699 | { |
---|
| 1700 | iSumHad += abs(m2[i][j]); |
---|
| 1701 | } |
---|
| 1702 | } |
---|
| 1703 | iSumHad -= abs(m2[0][0]); |
---|
| 1704 | iSumHad =(iSumHad+2)>>2; |
---|
| 1705 | return(iSumHad); |
---|
| 1706 | } |
---|
| 1707 | |
---|
| 1708 | Int TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height) |
---|
| 1709 | { |
---|
| 1710 | Int xBl, yBl; |
---|
| 1711 | const Int iBlkSize = 8; |
---|
| 1712 | |
---|
| 1713 | Pel* pOrgInit = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0); |
---|
| 1714 | Int iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride(); |
---|
| 1715 | Pel *pOrg; |
---|
| 1716 | |
---|
| 1717 | Int iSumHad = 0; |
---|
| 1718 | for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize) |
---|
| 1719 | { |
---|
| 1720 | for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize) |
---|
| 1721 | { |
---|
| 1722 | pOrg = pOrgInit + iStrideOrig*yBl + xBl; |
---|
| 1723 | iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig); |
---|
| 1724 | } |
---|
| 1725 | } |
---|
| 1726 | return(iSumHad); |
---|
| 1727 | } |
---|
| 1728 | #endif |
---|
| 1729 | |
---|
[2] | 1730 | /** check RD costs for a CU block encoded with merge |
---|
| 1731 | * \param rpcBestCU |
---|
| 1732 | * \param rpcTempCU |
---|
| 1733 | * \returns Void |
---|
| 1734 | */ |
---|
[608] | 1735 | Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode ) |
---|
[2] | 1736 | { |
---|
| 1737 | assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE ); |
---|
[608] | 1738 | #if H_3D_IV_MERGE |
---|
[56] | 1739 | TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists |
---|
| 1740 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1741 | #else |
---|
[608] | 1742 | TComMvField cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists |
---|
[2] | 1743 | UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS]; |
---|
[56] | 1744 | #endif |
---|
| 1745 | Int numValidMergeCand = 0; |
---|
[2] | 1746 | |
---|
[608] | 1747 | for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) |
---|
[2] | 1748 | { |
---|
| 1749 | uhInterDirNeighbours[ui] = 0; |
---|
| 1750 | } |
---|
| 1751 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[608] | 1752 | #if H_3D_IC |
---|
| 1753 | Bool bICFlag = rpcTempCU->getICFlag( 0 ); |
---|
| 1754 | #endif |
---|
| 1755 | #if H_3D_VSO // M1 //nececcary here? |
---|
[2] | 1756 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1757 | { |
---|
[81] | 1758 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
| 1759 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
| 1760 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
| 1761 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
| 1762 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[2] | 1763 | } |
---|
[5] | 1764 | #endif |
---|
[2] | 1765 | |
---|
| 1766 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
[608] | 1767 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
| 1768 | |
---|
| 1769 | #if H_3D_VSP |
---|
| 1770 | Int vspFlag[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1771 | memset(vspFlag, 0, sizeof(Int)*MRG_MAX_NUM_CANDS_MEM); |
---|
| 1772 | InheritedVSPDisInfo inheritedVSPDisInfo[MRG_MAX_NUM_CANDS_MEM]; |
---|
| 1773 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, vspFlag,inheritedVSPDisInfo, numValidMergeCand ); |
---|
[443] | 1774 | #else |
---|
[608] | 1775 | rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); |
---|
[443] | 1776 | #endif |
---|
[608] | 1777 | |
---|
| 1778 | #if H_3D_IV_MERGE |
---|
| 1779 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS_MEM]; |
---|
[296] | 1780 | #else |
---|
[608] | 1781 | Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; |
---|
[296] | 1782 | #endif |
---|
[608] | 1783 | for( UInt ui = 0; ui < numValidMergeCand; ++ui ) |
---|
| 1784 | { |
---|
| 1785 | mergeCandBuffer[ui] = 0; |
---|
| 1786 | } |
---|
[2] | 1787 | |
---|
[56] | 1788 | Bool bestIsSkip = false; |
---|
[608] | 1789 | |
---|
| 1790 | UInt iteration; |
---|
| 1791 | if ( rpcTempCU->isLosslessCoded(0)) |
---|
[443] | 1792 | { |
---|
[608] | 1793 | iteration = 1; |
---|
| 1794 | } |
---|
| 1795 | else |
---|
[2] | 1796 | { |
---|
[608] | 1797 | iteration = 2; |
---|
| 1798 | } |
---|
| 1799 | |
---|
| 1800 | #if H_3D_ARP |
---|
| 1801 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
| 1802 | if( nARPWMax < 0 || !rpcTempCU->getDvInfo(0).bDV ) |
---|
| 1803 | { |
---|
| 1804 | nARPWMax = 0; |
---|
| 1805 | } |
---|
| 1806 | for( Int nARPW=nARPWMax; nARPW >= 0 ; nARPW-- ) |
---|
| 1807 | { |
---|
| 1808 | memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS*sizeof(Int) ); |
---|
| 1809 | #endif |
---|
| 1810 | for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual ) |
---|
| 1811 | { |
---|
| 1812 | for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) |
---|
| 1813 | { |
---|
| 1814 | #if H_3D_IC |
---|
| 1815 | if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() ) |
---|
[443] | 1816 | { |
---|
[608] | 1817 | if( bICFlag && uiMergeCand == 0 ) |
---|
| 1818 | { |
---|
| 1819 | continue; |
---|
| 1820 | } |
---|
[443] | 1821 | } |
---|
| 1822 | #endif |
---|
[608] | 1823 | if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1)) |
---|
| 1824 | { |
---|
[56] | 1825 | if( !(bestIsSkip && uiNoResidual == 0) ) |
---|
| 1826 | { |
---|
| 1827 | // set MC parameters |
---|
[608] | 1828 | rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1829 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
[56] | 1830 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level |
---|
[608] | 1831 | #if H_3D_IC |
---|
| 1832 | rpcTempCU->setICFlagSubParts( bICFlag, 0, 0, uhDepth ); |
---|
[443] | 1833 | #endif |
---|
[608] | 1834 | #if H_3D_ARP |
---|
| 1835 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
| 1836 | #endif |
---|
[56] | 1837 | rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1838 | rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
[608] | 1839 | #if H_3D_VSP |
---|
| 1840 | rpcTempCU->setVSPFlagSubParts( vspFlag[uiMergeCand], 0, 0, uhDepth ); |
---|
| 1841 | rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth ); |
---|
[443] | 1842 | #endif |
---|
[56] | 1843 | rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level |
---|
| 1844 | rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
| 1845 | rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level |
---|
[2] | 1846 | |
---|
[608] | 1847 | #if H_3D_ARP |
---|
| 1848 | if( nARPW ) |
---|
[443] | 1849 | { |
---|
[608] | 1850 | Bool bSignalflag[2] = { true, true }; |
---|
| 1851 | for( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
[443] | 1852 | { |
---|
| 1853 | Int iRefIdx = cMvFieldNeighbours[uiRefListIdx + 2*uiMergeCand].getRefIdx(); |
---|
| 1854 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
[608] | 1855 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
| 1856 | { |
---|
[443] | 1857 | bSignalflag[uiRefListIdx] = false; |
---|
[608] | 1858 | } |
---|
[443] | 1859 | } |
---|
[608] | 1860 | if( !bSignalflag[0] && !bSignalflag[1] ) |
---|
[443] | 1861 | { |
---|
| 1862 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
| 1863 | } |
---|
| 1864 | } |
---|
| 1865 | #endif |
---|
[608] | 1866 | // do MC |
---|
| 1867 | m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] ); |
---|
| 1868 | // estimate residual and encode everything |
---|
| 1869 | #if H_3D_VSO //M2 |
---|
| 1870 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1871 | { //Reset |
---|
| 1872 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
| 1873 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
| 1874 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
| 1875 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
| 1876 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 1877 | } |
---|
[2] | 1878 | #endif |
---|
[608] | 1879 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, |
---|
| 1880 | m_ppcOrigYuv [uhDepth], |
---|
| 1881 | m_ppcPredYuvTemp[uhDepth], |
---|
| 1882 | m_ppcResiYuvTemp[uhDepth], |
---|
| 1883 | m_ppcResiYuvBest[uhDepth], |
---|
| 1884 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 1885 | (uiNoResidual? true:false)); |
---|
| 1886 | |
---|
| 1887 | |
---|
| 1888 | if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 ) |
---|
| 1889 | { |
---|
| 1890 | // If no residual when allowing for one, then set mark to not try case where residual is forced to 0 |
---|
| 1891 | mergeCandBuffer[uiMergeCand] = 1; |
---|
| 1892 | } |
---|
| 1893 | |
---|
| 1894 | rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); |
---|
[655] | 1895 | #if H_3D_INTER_SDC |
---|
[608] | 1896 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
[296] | 1897 | #endif |
---|
[608] | 1898 | Int orgQP = rpcTempCU->getQP( 0 ); |
---|
| 1899 | xCheckDQP( rpcTempCU ); |
---|
| 1900 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
[655] | 1901 | #if H_3D_INTER_SDC |
---|
[608] | 1902 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual ) |
---|
| 1903 | { |
---|
| 1904 | if( rpcTempCU != rpcTempCUPre ) |
---|
[296] | 1905 | { |
---|
[608] | 1906 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
| 1907 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
[296] | 1908 | } |
---|
[608] | 1909 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 1910 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
| 1911 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
| 1912 | #if H_3D_VSO //M2 |
---|
| 1913 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 1914 | { //Reset |
---|
| 1915 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth (); |
---|
| 1916 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight (); |
---|
| 1917 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr (); |
---|
| 1918 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride (); |
---|
| 1919 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 1920 | } |
---|
[296] | 1921 | #endif |
---|
[608] | 1922 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
| 1923 | m_ppcOrigYuv[uhDepth], |
---|
| 1924 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
| 1925 | m_ppcResiYuvTemp[uhDepth], |
---|
| 1926 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 1927 | uhDepth ); |
---|
[2] | 1928 | |
---|
[608] | 1929 | xCheckDQP( rpcTempCU ); |
---|
| 1930 | xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth ); |
---|
[56] | 1931 | } |
---|
[296] | 1932 | #endif |
---|
[608] | 1933 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
| 1934 | |
---|
| 1935 | if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) |
---|
| 1936 | { |
---|
[655] | 1937 | #if H_3D_INTER_SDC |
---|
[608] | 1938 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) ) |
---|
| 1939 | { |
---|
| 1940 | bestIsSkip = !rpcBestCU->getSDCFlag( 0 ) && ( rpcBestCU->getQtRootCbf(0) == 0 ); |
---|
| 1941 | } |
---|
| 1942 | else |
---|
| 1943 | { |
---|
[296] | 1944 | #endif |
---|
[608] | 1945 | bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0; |
---|
[655] | 1946 | #if H_3D_INTER_SDC |
---|
[608] | 1947 | } |
---|
[5] | 1948 | #endif |
---|
[608] | 1949 | } |
---|
| 1950 | } |
---|
| 1951 | } |
---|
| 1952 | } |
---|
[2] | 1953 | |
---|
[608] | 1954 | if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) |
---|
| 1955 | { |
---|
| 1956 | if(rpcBestCU->getQtRootCbf( 0 ) == 0) |
---|
| 1957 | { |
---|
| 1958 | if( rpcBestCU->getMergeFlag( 0 )) |
---|
| 1959 | { |
---|
| 1960 | *earlyDetectionSkipMode = true; |
---|
| 1961 | } |
---|
| 1962 | else |
---|
| 1963 | { |
---|
| 1964 | Int absoulte_MV=0; |
---|
| 1965 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
| 1966 | { |
---|
| 1967 | if ( rpcBestCU->getSlice()->getNumRefIdx( RefPicList( uiRefListIdx ) ) > 0 ) |
---|
[56] | 1968 | { |
---|
[608] | 1969 | TComCUMvField* pcCUMvField = rpcBestCU->getCUMvField(RefPicList( uiRefListIdx )); |
---|
| 1970 | Int iHor = pcCUMvField->getMvd( 0 ).getAbsHor(); |
---|
| 1971 | Int iVer = pcCUMvField->getMvd( 0 ).getAbsVer(); |
---|
| 1972 | absoulte_MV+=iHor+iVer; |
---|
[56] | 1973 | } |
---|
[608] | 1974 | } |
---|
[2] | 1975 | |
---|
[608] | 1976 | if(absoulte_MV == 0) |
---|
| 1977 | { |
---|
| 1978 | *earlyDetectionSkipMode = true; |
---|
[56] | 1979 | } |
---|
[2] | 1980 | } |
---|
| 1981 | } |
---|
| 1982 | } |
---|
[608] | 1983 | } |
---|
| 1984 | #if H_3D_ARP |
---|
| 1985 | } |
---|
[443] | 1986 | #endif |
---|
[2] | 1987 | } |
---|
| 1988 | |
---|
[608] | 1989 | |
---|
[56] | 1990 | #if AMP_MRG |
---|
[655] | 1991 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 1992 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG) |
---|
[56] | 1993 | #else |
---|
| 1994 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bUseMRG) |
---|
| 1995 | #endif |
---|
| 1996 | #else |
---|
[2] | 1997 | Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize ) |
---|
| 1998 | #endif |
---|
[608] | 1999 | { |
---|
[655] | 2000 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2001 | if(!(bFMD && (ePartSize == SIZE_2Nx2N))) //have motion estimation or merge check |
---|
| 2002 | { |
---|
[56] | 2003 | #endif |
---|
[2] | 2004 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
[608] | 2005 | #if H_3D_ARP |
---|
| 2006 | Int iLayerId = rpcTempCU->getSlice()->getLayerId(); |
---|
[443] | 2007 | Bool bFirstTime = true; |
---|
[608] | 2008 | Int nARPWMax = rpcTempCU->getSlice()->getARPStepNum() - 1; |
---|
| 2009 | |
---|
| 2010 | if( nARPWMax < 0 || ePartSize != SIZE_2Nx2N || !rpcTempCU->getDvInfo(0).bDV ) |
---|
| 2011 | { |
---|
[443] | 2012 | nARPWMax = 0; |
---|
[608] | 2013 | } |
---|
| 2014 | |
---|
| 2015 | for( Int nARPW = 0; nARPW <= nARPWMax; nARPW++ ) |
---|
[443] | 2016 | { |
---|
[608] | 2017 | if( bFirstTime == false && rpcTempCU->getSlice()->getVPS()->getUseAdvRP( iLayerId ) ) |
---|
| 2018 | { |
---|
[443] | 2019 | rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) ); |
---|
[608] | 2020 | } |
---|
| 2021 | #endif |
---|
| 2022 | #if H_3D_VSO // M3 |
---|
[2] | 2023 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2024 | { |
---|
[81] | 2025 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
| 2026 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
| 2027 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
| 2028 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
| 2029 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[2] | 2030 | } |
---|
[608] | 2031 | #endif |
---|
[2] | 2032 | |
---|
| 2033 | rpcTempCU->setDepthSubParts( uhDepth, 0 ); |
---|
[56] | 2034 | |
---|
[608] | 2035 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 2036 | |
---|
| 2037 | rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); |
---|
| 2038 | rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); |
---|
| 2039 | rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); |
---|
[56] | 2040 | |
---|
[608] | 2041 | #if H_3D_ARP |
---|
| 2042 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
[5] | 2043 | #endif |
---|
[56] | 2044 | |
---|
[608] | 2045 | #if H_3D_ARP |
---|
| 2046 | if( bFirstTime == false && nARPWMax ) |
---|
[443] | 2047 | { |
---|
[608] | 2048 | rpcTempCU->copyPartFrom( m_ppcWeightedTempCU[uhDepth] , 0 , uhDepth ); |
---|
| 2049 | rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth ); |
---|
| 2050 | |
---|
[443] | 2051 | m_pcPredSearch->motionCompensation( rpcTempCU , m_ppcPredYuvTemp[uhDepth] ); |
---|
[608] | 2052 | |
---|
[443] | 2053 | if(rpcTempCU->getPartitionSize(0)==SIZE_2Nx2N) |
---|
| 2054 | { |
---|
[608] | 2055 | Bool bSignalflag[2] = { true, true }; |
---|
[443] | 2056 | for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
| 2057 | { |
---|
| 2058 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
| 2059 | Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0); |
---|
[608] | 2060 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
| 2061 | { |
---|
[443] | 2062 | bSignalflag[uiRefListIdx] = false; |
---|
[608] | 2063 | } |
---|
[443] | 2064 | } |
---|
[608] | 2065 | if( !bSignalflag[0] && !bSignalflag[1] ) |
---|
| 2066 | { |
---|
[443] | 2067 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
[608] | 2068 | } |
---|
[443] | 2069 | } |
---|
| 2070 | } |
---|
| 2071 | else |
---|
| 2072 | { |
---|
| 2073 | bFirstTime = false; |
---|
| 2074 | #endif |
---|
[56] | 2075 | #if AMP_MRG |
---|
| 2076 | rpcTempCU->setMergeAMP (true); |
---|
[655] | 2077 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2078 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG ); |
---|
[56] | 2079 | #else |
---|
| 2080 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], false, bUseMRG ); |
---|
| 2081 | #endif |
---|
| 2082 | #else |
---|
[2] | 2083 | m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); |
---|
| 2084 | #endif |
---|
[608] | 2085 | #if H_3D_ARP |
---|
| 2086 | if( nARPWMax ) |
---|
[443] | 2087 | { |
---|
| 2088 | m_ppcWeightedTempCU[uhDepth]->copyPartFrom( rpcTempCU , 0 , uhDepth ); |
---|
[608] | 2089 | |
---|
| 2090 | Bool bSignalflag[2] = { true, true }; |
---|
| 2091 | for(UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx ++ ) |
---|
[443] | 2092 | { |
---|
[608] | 2093 | RefPicList eRefList = uiRefListIdx ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
| 2094 | Int iRefIdx = rpcTempCU->getCUMvField(eRefList)->getRefIdx(0); |
---|
| 2095 | if( iRefIdx < 0 || rpcTempCU->getSlice()->getPOC() == rpcTempCU->getSlice()->getRefPOC(eRefList, iRefIdx) ) |
---|
[443] | 2096 | { |
---|
[608] | 2097 | bSignalflag[uiRefListIdx] = false; |
---|
[443] | 2098 | } |
---|
| 2099 | } |
---|
[608] | 2100 | if( !bSignalflag[0] && !bSignalflag[1]) |
---|
| 2101 | { |
---|
| 2102 | rpcTempCU->setARPWSubParts( 0 , 0 , uhDepth ); |
---|
| 2103 | } |
---|
[443] | 2104 | } |
---|
| 2105 | } |
---|
| 2106 | #endif |
---|
[56] | 2107 | |
---|
| 2108 | #if AMP_MRG |
---|
| 2109 | if ( !rpcTempCU->getMergeAMP() ) |
---|
[2] | 2110 | { |
---|
[608] | 2111 | #if H_3D_ARP |
---|
| 2112 | if( nARPWMax ) |
---|
| 2113 | { |
---|
[443] | 2114 | continue; |
---|
[608] | 2115 | } |
---|
[443] | 2116 | else |
---|
| 2117 | #endif |
---|
[2] | 2118 | return; |
---|
| 2119 | } |
---|
| 2120 | #endif |
---|
[56] | 2121 | |
---|
[655] | 2122 | #if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227) |
---|
[608] | 2123 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2124 | { |
---|
| 2125 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2126 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2127 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2128 | m_temporalSAD = (Int)SAD; |
---|
| 2129 | } |
---|
[56] | 2130 | #endif |
---|
[655] | 2131 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 |
---|
| 2132 | if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2133 | { |
---|
| 2134 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2135 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2136 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2137 | m_temporalSAD = (Int)SAD; |
---|
| 2138 | } |
---|
| 2139 | #endif |
---|
[608] | 2140 | |
---|
| 2141 | m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); |
---|
| 2142 | |
---|
| 2143 | |
---|
| 2144 | #if H_3D_VSO // M4 |
---|
[2] | 2145 | if( m_pcRdCost->getUseLambdaScaleVSO() ) |
---|
| 2146 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2147 | else |
---|
[5] | 2148 | #endif |
---|
[608] | 2149 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[655] | 2150 | #if H_3D_INTER_SDC |
---|
[608] | 2151 | TComDataCU *rpcTempCUPre = rpcTempCU; |
---|
| 2152 | #endif |
---|
| 2153 | xCheckDQP( rpcTempCU ); |
---|
| 2154 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
[655] | 2155 | #if H_3D_INTER_SDC |
---|
[608] | 2156 | if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() ) |
---|
[2] | 2157 | { |
---|
[608] | 2158 | if( rpcTempCU != rpcTempCUPre ) |
---|
| 2159 | { |
---|
| 2160 | Int orgQP = rpcBestCU->getQP( 0 ); |
---|
| 2161 | rpcTempCU->initEstData( uhDepth, orgQP ); |
---|
| 2162 | rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth ); |
---|
| 2163 | } |
---|
| 2164 | rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); |
---|
| 2165 | rpcTempCU->setTrIdxSubParts( 0, 0, uhDepth ); |
---|
| 2166 | rpcTempCU->setCbfSubParts( 1, 1, 1, 0, uhDepth ); |
---|
| 2167 | #if H_3D_VSO // M3 |
---|
| 2168 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2169 | { |
---|
| 2170 | UInt uiWidth = m_ppcOrigYuv[uhDepth]->getWidth ( ); |
---|
| 2171 | UInt uiHeight = m_ppcOrigYuv[uhDepth]->getHeight( ); |
---|
| 2172 | Pel* piSrc = m_ppcOrigYuv[uhDepth]->getLumaAddr( ); |
---|
| 2173 | UInt uiSrcStride = m_ppcOrigYuv[uhDepth]->getStride(); |
---|
| 2174 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
| 2175 | } |
---|
| 2176 | #endif |
---|
[2] | 2177 | |
---|
[608] | 2178 | m_pcPredSearch->encodeResAndCalcRdInterSDCCU( rpcTempCU, |
---|
| 2179 | m_ppcOrigYuv[uhDepth], |
---|
| 2180 | ( rpcTempCU != rpcTempCUPre ) ? m_ppcPredYuvBest[uhDepth] : m_ppcPredYuvTemp[uhDepth], |
---|
| 2181 | m_ppcResiYuvTemp[uhDepth], |
---|
| 2182 | m_ppcRecoYuvTemp[uhDepth], |
---|
| 2183 | uhDepth ); |
---|
| 2184 | |
---|
[56] | 2185 | xCheckDQP( rpcTempCU ); |
---|
| 2186 | xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); |
---|
[443] | 2187 | } |
---|
| 2188 | #endif |
---|
[608] | 2189 | #if H_3D_ARP |
---|
| 2190 | } |
---|
| 2191 | #endif |
---|
[655] | 2192 | #if H_3D_FAST_TEXTURE_ENCODING |
---|
[608] | 2193 | } |
---|
| 2194 | #endif |
---|
[2] | 2195 | } |
---|
| 2196 | |
---|
| 2197 | Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) |
---|
| 2198 | { |
---|
| 2199 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
[56] | 2200 | |
---|
[608] | 2201 | #if H_3D_VSO // M5 |
---|
[2] | 2202 | if( m_pcRdCost->getUseRenModel() ) |
---|
| 2203 | { |
---|
[81] | 2204 | UInt uiWidth = m_ppcOrigYuv[uiDepth]->getWidth (); |
---|
| 2205 | UInt uiHeight = m_ppcOrigYuv[uiDepth]->getHeight (); |
---|
| 2206 | Pel* piSrc = m_ppcOrigYuv[uiDepth]->getLumaAddr(); |
---|
| 2207 | UInt uiSrcStride = m_ppcOrigYuv[uiDepth]->getStride (); |
---|
| 2208 | m_pcRdCost->setRenModelData( rpcTempCU, 0, piSrc, uiSrcStride, uiWidth, uiHeight ); |
---|
[2] | 2209 | } |
---|
[5] | 2210 | #endif |
---|
[2] | 2211 | |
---|
[608] | 2212 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 2213 | |
---|
[2] | 2214 | rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); |
---|
| 2215 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
[608] | 2216 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
[56] | 2217 | |
---|
[2] | 2218 | Bool bSeparateLumaChroma = true; // choose estimation mode |
---|
[608] | 2219 | UInt uiPreCalcDistC = 0; |
---|
[2] | 2220 | if( !bSeparateLumaChroma ) |
---|
| 2221 | { |
---|
| 2222 | m_pcPredSearch->preestChromaPredMode( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth] ); |
---|
| 2223 | } |
---|
| 2224 | m_pcPredSearch ->estIntraPredQT ( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC, bSeparateLumaChroma ); |
---|
| 2225 | |
---|
| 2226 | m_ppcRecoYuvTemp[uiDepth]->copyToPicLuma(rpcTempCU->getPic()->getPicYuvRec(), rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU() ); |
---|
[56] | 2227 | |
---|
[608] | 2228 | #if H_3D_DIM_SDC |
---|
[189] | 2229 | if( !rpcTempCU->getSDCFlag( 0 ) ) |
---|
| 2230 | #endif |
---|
[2] | 2231 | m_pcPredSearch ->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], uiPreCalcDistC ); |
---|
[56] | 2232 | |
---|
[2] | 2233 | m_pcEntropyCoder->resetBits(); |
---|
[608] | 2234 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 2235 | { |
---|
| 2236 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 2237 | } |
---|
[2] | 2238 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 2239 | m_pcEntropyCoder->encodePredMode( rpcTempCU, 0, true ); |
---|
| 2240 | m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true ); |
---|
| 2241 | m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0, true ); |
---|
[56] | 2242 | m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true ); |
---|
[2] | 2243 | |
---|
| 2244 | // Encode Coefficients |
---|
[56] | 2245 | Bool bCodeDQP = getdQPFlag(); |
---|
| 2246 | m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, rpcTempCU->getWidth (0), rpcTempCU->getHeight(0), bCodeDQP ); |
---|
| 2247 | setdQPFlag( bCodeDQP ); |
---|
| 2248 | |
---|
[2] | 2249 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
[56] | 2250 | |
---|
[2] | 2251 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
[56] | 2252 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 2253 | { |
---|
| 2254 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2255 | } |
---|
[608] | 2256 | |
---|
| 2257 | #if H_3D_VSO // M6 |
---|
| 2258 | if( m_pcRdCost->getUseLambdaScaleVSO()) |
---|
| 2259 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
[2] | 2260 | else |
---|
[5] | 2261 | #endif |
---|
[56] | 2262 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2263 | |
---|
[655] | 2264 | #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 2265 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2266 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2267 | { |
---|
| 2268 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2269 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2270 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2271 | m_spatialSAD = (Int)SAD; |
---|
| 2272 | } |
---|
| 2273 | #endif |
---|
| 2274 | #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 |
---|
| 2275 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2276 | if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2277 | { |
---|
| 2278 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2279 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2280 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2281 | m_spatialSAD = (Int)SAD; |
---|
| 2282 | } |
---|
| 2283 | #endif |
---|
| 2284 | #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 |
---|
| 2285 | UChar uhDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2286 | if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) |
---|
| 2287 | { |
---|
| 2288 | UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), |
---|
| 2289 | m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), |
---|
| 2290 | rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); |
---|
| 2291 | m_spatialSAD = (Int)SAD; |
---|
| 2292 | } |
---|
| 2293 | #endif |
---|
[56] | 2294 | xCheckDQP( rpcTempCU ); |
---|
| 2295 | xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); |
---|
| 2296 | } |
---|
[2] | 2297 | |
---|
[56] | 2298 | /** Check R-D costs for a CU with PCM mode. |
---|
| 2299 | * \param rpcBestCU pointer to best mode CU data structure |
---|
| 2300 | * \param rpcTempCU pointer to testing mode CU data structure |
---|
| 2301 | * \returns Void |
---|
| 2302 | * |
---|
| 2303 | * \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. |
---|
| 2304 | */ |
---|
| 2305 | Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) |
---|
| 2306 | { |
---|
| 2307 | UInt uiDepth = rpcTempCU->getDepth( 0 ); |
---|
| 2308 | |
---|
[608] | 2309 | rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); |
---|
| 2310 | |
---|
[56] | 2311 | rpcTempCU->setIPCMFlag(0, true); |
---|
| 2312 | rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); |
---|
| 2313 | rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); |
---|
| 2314 | rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); |
---|
[608] | 2315 | rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); |
---|
| 2316 | rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); |
---|
[56] | 2317 | |
---|
| 2318 | m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); |
---|
| 2319 | |
---|
| 2320 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); |
---|
| 2321 | |
---|
| 2322 | m_pcEntropyCoder->resetBits(); |
---|
[608] | 2323 | if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) |
---|
| 2324 | { |
---|
| 2325 | m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); |
---|
| 2326 | } |
---|
[56] | 2327 | m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); |
---|
| 2328 | m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); |
---|
| 2329 | m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); |
---|
| 2330 | m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); |
---|
| 2331 | |
---|
| 2332 | if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); |
---|
| 2333 | |
---|
| 2334 | rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 2335 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 2336 | { |
---|
| 2337 | rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2338 | } |
---|
[608] | 2339 | #if H_3D_VSO // M44 |
---|
[56] | 2340 | if ( m_pcRdCost->getUseVSO() ) |
---|
| 2341 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2342 | else |
---|
| 2343 | #endif |
---|
| 2344 | rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); |
---|
| 2345 | |
---|
| 2346 | xCheckDQP( rpcTempCU ); |
---|
[2] | 2347 | xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); |
---|
| 2348 | } |
---|
| 2349 | |
---|
[56] | 2350 | /** check whether current try is the best with identifying the depth of current try |
---|
| 2351 | * \param rpcBestCU |
---|
| 2352 | * \param rpcTempCU |
---|
| 2353 | * \returns Void |
---|
| 2354 | */ |
---|
| 2355 | Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) |
---|
[2] | 2356 | { |
---|
[56] | 2357 | if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) |
---|
| 2358 | { |
---|
| 2359 | TComYuv* pcYuv; |
---|
| 2360 | // Change Information data |
---|
| 2361 | TComDataCU* pcCU = rpcBestCU; |
---|
| 2362 | rpcBestCU = rpcTempCU; |
---|
| 2363 | rpcTempCU = pcCU; |
---|
[2] | 2364 | |
---|
[56] | 2365 | // Change Prediction data |
---|
| 2366 | pcYuv = m_ppcPredYuvBest[uiDepth]; |
---|
| 2367 | m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; |
---|
| 2368 | m_ppcPredYuvTemp[uiDepth] = pcYuv; |
---|
[2] | 2369 | |
---|
[56] | 2370 | // Change Reconstruction data |
---|
| 2371 | pcYuv = m_ppcRecoYuvBest[uiDepth]; |
---|
| 2372 | m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; |
---|
| 2373 | m_ppcRecoYuvTemp[uiDepth] = pcYuv; |
---|
[2] | 2374 | |
---|
[56] | 2375 | pcYuv = NULL; |
---|
| 2376 | pcCU = NULL; |
---|
[2] | 2377 | |
---|
[56] | 2378 | if( m_bUseSBACRD ) // store temp best CI for next CU coding |
---|
| 2379 | m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); |
---|
| 2380 | } |
---|
| 2381 | } |
---|
| 2382 | |
---|
| 2383 | Void TEncCu::xCheckDQP( TComDataCU* pcCU ) |
---|
| 2384 | { |
---|
| 2385 | UInt uiDepth = pcCU->getDepth( 0 ); |
---|
| 2386 | |
---|
| 2387 | if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) |
---|
[2] | 2388 | { |
---|
[56] | 2389 | if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) |
---|
| 2390 | { |
---|
| 2391 | #if !RDO_WITHOUT_DQP_BITS |
---|
| 2392 | m_pcEntropyCoder->resetBits(); |
---|
| 2393 | m_pcEntropyCoder->encodeQP( pcCU, 0, false ); |
---|
| 2394 | pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits |
---|
| 2395 | if(m_pcEncCfg->getUseSBACRD()) |
---|
| 2396 | { |
---|
| 2397 | pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); |
---|
| 2398 | } |
---|
[608] | 2399 | #if H_3D_VSO // M45 |
---|
| 2400 | if ( m_pcRdCost->getUseVSO() ) |
---|
| 2401 | pcCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
[56] | 2402 | else |
---|
| 2403 | #endif |
---|
| 2404 | pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); |
---|
| 2405 | #endif |
---|
[2] | 2406 | } |
---|
[56] | 2407 | else |
---|
[2] | 2408 | { |
---|
[56] | 2409 | pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP |
---|
[2] | 2410 | } |
---|
[56] | 2411 | } |
---|
| 2412 | } |
---|
| 2413 | |
---|
[2] | 2414 | Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) |
---|
| 2415 | { |
---|
| 2416 | pDst->iN = pSrc->iN; |
---|
| 2417 | for (Int i = 0; i < pSrc->iN; i++) |
---|
| 2418 | { |
---|
| 2419 | pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; |
---|
| 2420 | } |
---|
| 2421 | } |
---|
[56] | 2422 | Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) |
---|
| 2423 | { |
---|
| 2424 | UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; |
---|
| 2425 | UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; |
---|
| 2426 | TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); |
---|
[608] | 2427 | Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 2428 | pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
| 2429 | Bool bSliceEnd = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && |
---|
| 2430 | pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); |
---|
[56] | 2431 | if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
| 2432 | { |
---|
| 2433 | UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; |
---|
| 2434 | UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); |
---|
| 2435 | UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); |
---|
| 2436 | UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 2437 | UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; |
---|
| 2438 | UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; |
---|
| 2439 | m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); |
---|
| 2440 | } |
---|
| 2441 | else |
---|
| 2442 | { |
---|
| 2443 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; |
---|
[2] | 2444 | |
---|
[56] | 2445 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) |
---|
| 2446 | { |
---|
| 2447 | UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); |
---|
| 2448 | UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); |
---|
| 2449 | |
---|
[608] | 2450 | Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && |
---|
| 2451 | rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
[56] | 2452 | if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) |
---|
| 2453 | { |
---|
| 2454 | xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv |
---|
| 2455 | } |
---|
| 2456 | } |
---|
| 2457 | } |
---|
[2] | 2458 | } |
---|
| 2459 | |
---|
| 2460 | Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) |
---|
| 2461 | { |
---|
| 2462 | UInt uiCurrDepth = uiNextDepth - 1; |
---|
| 2463 | m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); |
---|
| 2464 | } |
---|
| 2465 | |
---|
[56] | 2466 | /** Function for filling the PCM buffer of a CU using its original sample array |
---|
| 2467 | * \param pcCU pointer to current CU |
---|
| 2468 | * \param pcOrgYuv pointer to original sample array |
---|
| 2469 | * \returns Void |
---|
| 2470 | */ |
---|
| 2471 | Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) |
---|
| 2472 | { |
---|
| 2473 | |
---|
| 2474 | UInt width = pCU->getWidth(0); |
---|
| 2475 | UInt height = pCU->getHeight(0); |
---|
| 2476 | |
---|
| 2477 | Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); |
---|
| 2478 | Pel* pDstY = pCU->getPCMSampleY(); |
---|
| 2479 | UInt srcStride = pOrgYuv->getStride(); |
---|
| 2480 | |
---|
| 2481 | for(Int y = 0; y < height; y++ ) |
---|
| 2482 | { |
---|
| 2483 | for(Int x = 0; x < width; x++ ) |
---|
| 2484 | { |
---|
| 2485 | pDstY[x] = pSrcY[x]; |
---|
| 2486 | } |
---|
| 2487 | pDstY += width; |
---|
| 2488 | pSrcY += srcStride; |
---|
| 2489 | } |
---|
| 2490 | |
---|
| 2491 | Pel* pSrcCb = pOrgYuv->getCbAddr(); |
---|
| 2492 | Pel* pSrcCr = pOrgYuv->getCrAddr();; |
---|
| 2493 | |
---|
| 2494 | Pel* pDstCb = pCU->getPCMSampleCb(); |
---|
| 2495 | Pel* pDstCr = pCU->getPCMSampleCr();; |
---|
| 2496 | |
---|
| 2497 | UInt srcStrideC = pOrgYuv->getCStride(); |
---|
| 2498 | UInt heightC = height >> 1; |
---|
| 2499 | UInt widthC = width >> 1; |
---|
| 2500 | |
---|
| 2501 | for(Int y = 0; y < heightC; y++ ) |
---|
| 2502 | { |
---|
| 2503 | for(Int x = 0; x < widthC; x++ ) |
---|
| 2504 | { |
---|
| 2505 | pDstCb[x] = pSrcCb[x]; |
---|
| 2506 | pDstCr[x] = pSrcCr[x]; |
---|
| 2507 | } |
---|
| 2508 | pDstCb += widthC; |
---|
| 2509 | pDstCr += widthC; |
---|
| 2510 | pSrcCb += srcStrideC; |
---|
| 2511 | pSrcCr += srcStrideC; |
---|
| 2512 | } |
---|
| 2513 | } |
---|
| 2514 | |
---|
| 2515 | #if ADAPTIVE_QP_SELECTION |
---|
| 2516 | /** Collect ARL statistics from one block |
---|
| 2517 | */ |
---|
| 2518 | Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) |
---|
| 2519 | { |
---|
| 2520 | for( Int n = 0; n < NumCoeffInCU; n++ ) |
---|
| 2521 | { |
---|
| 2522 | Int u = abs( rpcCoeff[ n ] ); |
---|
| 2523 | Int absc = rpcArlCoeff[ n ]; |
---|
| 2524 | |
---|
| 2525 | if( u != 0 ) |
---|
| 2526 | { |
---|
| 2527 | if( u < LEVEL_RANGE ) |
---|
| 2528 | { |
---|
| 2529 | cSum[ u ] += ( Double )absc; |
---|
| 2530 | numSamples[ u ]++; |
---|
| 2531 | } |
---|
| 2532 | else |
---|
| 2533 | { |
---|
| 2534 | cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); |
---|
| 2535 | numSamples[ LEVEL_RANGE ]++; |
---|
| 2536 | } |
---|
| 2537 | } |
---|
| 2538 | } |
---|
| 2539 | |
---|
| 2540 | return 0; |
---|
| 2541 | } |
---|
| 2542 | |
---|
| 2543 | /** Collect ARL statistics from one LCU |
---|
| 2544 | * \param pcCU |
---|
| 2545 | */ |
---|
| 2546 | Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) |
---|
| 2547 | { |
---|
| 2548 | Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output |
---|
| 2549 | UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output |
---|
| 2550 | |
---|
| 2551 | TCoeff* pCoeffY = rpcCU->getCoeffY(); |
---|
| 2552 | Int* pArlCoeffY = rpcCU->getArlCoeffY(); |
---|
| 2553 | |
---|
| 2554 | UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; |
---|
| 2555 | UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; |
---|
| 2556 | |
---|
| 2557 | memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); |
---|
| 2558 | memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); |
---|
| 2559 | |
---|
| 2560 | // Collect stats to cSum[][] and numSamples[][] |
---|
| 2561 | for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) |
---|
| 2562 | { |
---|
| 2563 | UInt uiTrIdx = rpcCU->getTransformIdx(i); |
---|
| 2564 | |
---|
| 2565 | if(rpcCU->getPredictionMode(i) == MODE_INTER) |
---|
| 2566 | if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) |
---|
| 2567 | { |
---|
| 2568 | xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); |
---|
| 2569 | }//Note that only InterY is processed. QP rounding is based on InterY data only. |
---|
| 2570 | |
---|
| 2571 | pCoeffY += uiMinNumCoeffInCU; |
---|
| 2572 | pArlCoeffY += uiMinNumCoeffInCU; |
---|
| 2573 | } |
---|
| 2574 | |
---|
| 2575 | for(Int u=1; u<LEVEL_RANGE;u++) |
---|
| 2576 | { |
---|
| 2577 | m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; |
---|
| 2578 | m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; |
---|
| 2579 | } |
---|
| 2580 | m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; |
---|
| 2581 | m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; |
---|
| 2582 | } |
---|
| 2583 | #endif |
---|
| 2584 | //! \} |
---|