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