| 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-2015, 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 TEncTop.cpp |
|---|
| 35 | \brief encoder class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include "TLibCommon/CommonDef.h" |
|---|
| 39 | #include "TEncTop.h" |
|---|
| 40 | #include "TEncPic.h" |
|---|
| 41 | #include "TLibCommon/TComChromaFormat.h" |
|---|
| 42 | #if FAST_BIT_EST |
|---|
| 43 | #include "TLibCommon/ContextModel.h" |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | //! \ingroup TLibEncoder |
|---|
| 47 | //! \{ |
|---|
| 48 | #if SVC_EXTENSION |
|---|
| 49 | Int TEncTop::m_iSPSIdCnt = 0; |
|---|
| 50 | Int TEncTop::m_iPPSIdCnt = 0; |
|---|
| 51 | TComVPS TEncCfg::m_cVPS; |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | // ==================================================================================================================== |
|---|
| 55 | // Constructor / destructor / create / destroy |
|---|
| 56 | // ==================================================================================================================== |
|---|
| 57 | |
|---|
| 58 | TEncTop::TEncTop() |
|---|
| 59 | { |
|---|
| 60 | m_iPOCLast = -1; |
|---|
| 61 | m_iNumPicRcvd = 0; |
|---|
| 62 | m_uiNumAllPicCoded = 0; |
|---|
| 63 | m_pppcRDSbacCoder = NULL; |
|---|
| 64 | m_pppcBinCoderCABAC = NULL; |
|---|
| 65 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
|---|
| 66 | #if ENC_DEC_TRACE |
|---|
| 67 | if (g_hTrace == NULL) |
|---|
| 68 | { |
|---|
| 69 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
|---|
| 70 | } |
|---|
| 71 | g_bJustDoIt = g_bEncDecTraceDisable; |
|---|
| 72 | g_nSymbolCounter = 0; |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | m_iMaxRefPicNum = 0; |
|---|
| 76 | |
|---|
| 77 | #if FAST_BIT_EST |
|---|
| 78 | ContextModel::buildNextStateTable(); |
|---|
| 79 | #endif |
|---|
| 80 | |
|---|
| 81 | #if SVC_EXTENSION |
|---|
| 82 | memset( m_cIlpPic, 0, sizeof(m_cIlpPic) ); |
|---|
| 83 | m_bMFMEnabledFlag = false; |
|---|
| 84 | m_numRefLayerLocationOffsets = 0; |
|---|
| 85 | m_pocAdjustmentValue = 0; |
|---|
| 86 | #if NO_CLRAS_OUTPUT_FLAG |
|---|
| 87 | m_noClrasOutputFlag = false; |
|---|
| 88 | m_layerInitializedFlag = false; |
|---|
| 89 | m_firstPicInLayerDecodedFlag = false; |
|---|
| 90 | m_noOutputOfPriorPicsFlags = false; |
|---|
| 91 | #endif |
|---|
| 92 | m_pocDecrementedInDPBFlag = false; |
|---|
| 93 | #endif //SVC_EXTENSION |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | TEncTop::~TEncTop() |
|---|
| 97 | { |
|---|
| 98 | #if ENC_DEC_TRACE |
|---|
| 99 | if (g_hTrace != stdout) |
|---|
| 100 | { |
|---|
| 101 | fclose( g_hTrace ); |
|---|
| 102 | } |
|---|
| 103 | #endif |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | Void TEncTop::create () |
|---|
| 107 | { |
|---|
| 108 | #if !SVC_EXTENSION |
|---|
| 109 | // initialize global variables |
|---|
| 110 | initROM(); |
|---|
| 111 | #endif |
|---|
| 112 | |
|---|
| 113 | // create processing unit classes |
|---|
| 114 | #if SVC_EXTENSION |
|---|
| 115 | m_cGOPEncoder. create( m_layerId ); |
|---|
| 116 | #else |
|---|
| 117 | m_cGOPEncoder. create( ); |
|---|
| 118 | #endif |
|---|
| 119 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
|---|
| 120 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, m_chromaFormatIDC ); |
|---|
| 121 | if (m_bUseSAO) |
|---|
| 122 | { |
|---|
| 123 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA], m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA] ); |
|---|
| 124 | #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK |
|---|
| 125 | m_cEncSAO.createEncData(getSaoCtuBoundary()); |
|---|
| 126 | #else |
|---|
| 127 | m_cEncSAO.createEncData(); |
|---|
| 128 | #endif |
|---|
| 129 | } |
|---|
| 130 | #if ADAPTIVE_QP_SELECTION |
|---|
| 131 | if (m_bUseAdaptQpSelect) |
|---|
| 132 | { |
|---|
| 133 | m_cTrQuant.initSliceQpDelta(); |
|---|
| 134 | } |
|---|
| 135 | #endif |
|---|
| 136 | |
|---|
| 137 | m_cLoopFilter.create( g_uiMaxCUDepth ); |
|---|
| 138 | |
|---|
| 139 | if ( m_RCEnableRateControl ) |
|---|
| 140 | { |
|---|
| 141 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
|---|
| 142 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
|---|
| 146 | #if FAST_BIT_EST |
|---|
| 147 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
|---|
| 148 | #else |
|---|
| 149 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
|---|
| 150 | #endif |
|---|
| 151 | |
|---|
| 152 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
|---|
| 153 | { |
|---|
| 154 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
|---|
| 155 | #if FAST_BIT_EST |
|---|
| 156 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
|---|
| 157 | #else |
|---|
| 158 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
|---|
| 159 | #endif |
|---|
| 160 | |
|---|
| 161 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
|---|
| 162 | { |
|---|
| 163 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
|---|
| 164 | #if FAST_BIT_EST |
|---|
| 165 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
|---|
| 166 | #else |
|---|
| 167 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
|---|
| 168 | #endif |
|---|
| 169 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | #if LAYER_CTB |
|---|
| 174 | memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) ); |
|---|
| 175 | memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) ); |
|---|
| 176 | memcpy(g_auiLayerRasterToPelX[m_layerId], g_auiRasterToPelX, sizeof( g_auiRasterToPelX ) ); |
|---|
| 177 | memcpy(g_auiLayerRasterToPelY[m_layerId], g_auiRasterToPelY, sizeof( g_auiRasterToPelY ) ); |
|---|
| 178 | #endif |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | Void TEncTop::destroy () |
|---|
| 182 | { |
|---|
| 183 | // destroy processing unit classes |
|---|
| 184 | m_cGOPEncoder. destroy(); |
|---|
| 185 | m_cSliceEncoder. destroy(); |
|---|
| 186 | m_cCuEncoder. destroy(); |
|---|
| 187 | m_cEncSAO. destroyEncData(); |
|---|
| 188 | m_cEncSAO. destroy(); |
|---|
| 189 | m_cLoopFilter. destroy(); |
|---|
| 190 | m_cRateCtrl. destroy(); |
|---|
| 191 | Int iDepth; |
|---|
| 192 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
|---|
| 193 | { |
|---|
| 194 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
|---|
| 195 | { |
|---|
| 196 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
|---|
| 197 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
|---|
| 202 | { |
|---|
| 203 | delete [] m_pppcRDSbacCoder[iDepth]; |
|---|
| 204 | delete [] m_pppcBinCoderCABAC[iDepth]; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | delete [] m_pppcRDSbacCoder; |
|---|
| 208 | delete [] m_pppcBinCoderCABAC; |
|---|
| 209 | |
|---|
| 210 | #if SVC_EXTENSION |
|---|
| 211 | for(Int i=0; i<MAX_NUM_REF; i++) |
|---|
| 212 | { |
|---|
| 213 | if(m_cIlpPic[i]) |
|---|
| 214 | { |
|---|
| 215 | m_cIlpPic[i]->destroy(); |
|---|
| 216 | delete m_cIlpPic[i]; |
|---|
| 217 | m_cIlpPic[i] = NULL; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | #else |
|---|
| 221 | // destroy ROM |
|---|
| 222 | destroyROM(); |
|---|
| 223 | #endif |
|---|
| 224 | return; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | Void TEncTop::init(Bool isFieldCoding) |
|---|
| 228 | { |
|---|
| 229 | // initialize SPS |
|---|
| 230 | xInitSPS(); |
|---|
| 231 | xInitVPS(); |
|---|
| 232 | |
|---|
| 233 | m_cRdCost.setCostMode(m_costMode); |
|---|
| 234 | |
|---|
| 235 | // initialize PPS |
|---|
| 236 | xInitPPS(); |
|---|
| 237 | xInitRPS(isFieldCoding); |
|---|
| 238 | |
|---|
| 239 | xInitPPSforTiles(); |
|---|
| 240 | |
|---|
| 241 | // initialize processing unit classes |
|---|
| 242 | m_cGOPEncoder. init( this ); |
|---|
| 243 | m_cSliceEncoder.init( this ); |
|---|
| 244 | m_cCuEncoder. init( this ); |
|---|
| 245 | |
|---|
| 246 | // initialize transform & quantization class |
|---|
| 247 | m_pcCavlcCoder = getCavlcCoder(); |
|---|
| 248 | |
|---|
| 249 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
|---|
| 250 | m_useRDOQ, |
|---|
| 251 | m_useRDOQTS, |
|---|
| 252 | true |
|---|
| 253 | ,m_useTransformSkipFast |
|---|
| 254 | #if ADAPTIVE_QP_SELECTION |
|---|
| 255 | ,m_bUseAdaptQpSelect |
|---|
| 256 | #endif |
|---|
| 257 | ); |
|---|
| 258 | |
|---|
| 259 | // initialize encoder search class |
|---|
| 260 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
|---|
| 261 | |
|---|
| 262 | m_iMaxRefPicNum = 0; |
|---|
| 263 | |
|---|
| 264 | xInitScalingLists(); |
|---|
| 265 | |
|---|
| 266 | #if SVC_EXTENSION |
|---|
| 267 | m_iSPSIdCnt ++; |
|---|
| 268 | m_iPPSIdCnt ++; |
|---|
| 269 | xInitILRP(); |
|---|
| 270 | #endif |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | Void TEncTop::xInitScalingLists() |
|---|
| 274 | { |
|---|
| 275 | // Initialise scaling lists |
|---|
| 276 | // The encoder will only use the SPS scaling lists. The PPS will never be marked present. |
|---|
| 277 | |
|---|
| 278 | if(getUseScalingListId() == SCALING_LIST_OFF) |
|---|
| 279 | { |
|---|
| 280 | #if SVC_EXTENSION |
|---|
| 281 | getTrQuant()->setFlatScalingList(m_cVPS.getChromaFormatIdc(&m_cSPS, m_layerId)); |
|---|
| 282 | #else |
|---|
| 283 | getTrQuant()->setFlatScalingList(m_cSPS.getChromaFormatIdc()); |
|---|
| 284 | #endif |
|---|
| 285 | getTrQuant()->setUseScalingList(false); |
|---|
| 286 | m_cSPS.setScalingListPresentFlag(false); |
|---|
| 287 | m_cPPS.setScalingListPresentFlag(false); |
|---|
| 288 | } |
|---|
| 289 | else if(getUseScalingListId() == SCALING_LIST_DEFAULT) |
|---|
| 290 | { |
|---|
| 291 | #if SVC_EXTENSION |
|---|
| 292 | // inferring of the scaling list can be moved to the config file |
|---|
| 293 | UInt refLayerId = 0; |
|---|
| 294 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
|---|
| 295 | { |
|---|
| 296 | m_cSPS.setInferScalingListFlag( true ); |
|---|
| 297 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
|---|
| 298 | m_cSPS.setScalingListPresentFlag( false ); |
|---|
| 299 | m_cPPS.setInferScalingListFlag( false ); |
|---|
| 300 | m_cPPS.setScalingListPresentFlag( false ); |
|---|
| 301 | |
|---|
| 302 | // infer the scaling list from the reference layer |
|---|
| 303 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() ); |
|---|
| 304 | } |
|---|
| 305 | else |
|---|
| 306 | { |
|---|
| 307 | #endif |
|---|
| 308 | m_cSPS.getScalingList().setDefaultScalingList (); |
|---|
| 309 | m_cSPS.setScalingListPresentFlag(false); |
|---|
| 310 | m_cPPS.setScalingListPresentFlag(false); |
|---|
| 311 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc()); |
|---|
| 312 | #if SVC_EXTENSION |
|---|
| 313 | } |
|---|
| 314 | #endif |
|---|
| 315 | getTrQuant()->setUseScalingList(true); |
|---|
| 316 | } |
|---|
| 317 | else if(getUseScalingListId() == SCALING_LIST_FILE_READ) |
|---|
| 318 | { |
|---|
| 319 | #if SVC_EXTENSION |
|---|
| 320 | // inferring of the scaling list can be moved to the config file |
|---|
| 321 | UInt refLayerId = 0; |
|---|
| 322 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
|---|
| 323 | { |
|---|
| 324 | m_cSPS.setInferScalingListFlag( true ); |
|---|
| 325 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
|---|
| 326 | m_cSPS.setScalingListPresentFlag( false ); |
|---|
| 327 | m_cPPS.setInferScalingListFlag( false ); |
|---|
| 328 | m_cPPS.setScalingListPresentFlag( false ); |
|---|
| 329 | |
|---|
| 330 | // infer the scaling list from the reference layer |
|---|
| 331 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() ); |
|---|
| 332 | } |
|---|
| 333 | else |
|---|
| 334 | { |
|---|
| 335 | #endif |
|---|
| 336 | m_cSPS.getScalingList().setDefaultScalingList (); |
|---|
| 337 | if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile())) |
|---|
| 338 | { |
|---|
| 339 | Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string |
|---|
| 340 | assert(bParsedScalingList); |
|---|
| 341 | exit(1); |
|---|
| 342 | } |
|---|
| 343 | m_cSPS.getScalingList().checkDcOfMatrix(); |
|---|
| 344 | m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList()); |
|---|
| 345 | m_cPPS.setScalingListPresentFlag(false); |
|---|
| 346 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc()); |
|---|
| 347 | #if SVC_EXTENSION |
|---|
| 348 | } |
|---|
| 349 | #endif |
|---|
| 350 | getTrQuant()->setUseScalingList(true); |
|---|
| 351 | } |
|---|
| 352 | else |
|---|
| 353 | { |
|---|
| 354 | printf("error : ScalingList == %d not supported\n",getUseScalingListId()); |
|---|
| 355 | assert(0); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | // Prepare delta's: |
|---|
| 359 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 360 | { |
|---|
| 361 | const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries. |
|---|
| 362 | |
|---|
| 363 | for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep) |
|---|
| 364 | { |
|---|
| 365 | m_cSPS.getScalingList().checkPredMode( sizeId, listId ); |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | // ==================================================================================================================== |
|---|
| 372 | // Public member functions |
|---|
| 373 | // ==================================================================================================================== |
|---|
| 374 | |
|---|
| 375 | Void TEncTop::deletePicBuffer() |
|---|
| 376 | { |
|---|
| 377 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
|---|
| 378 | Int iSize = Int( m_cListPic.size() ); |
|---|
| 379 | |
|---|
| 380 | for ( Int i = 0; i < iSize; i++ ) |
|---|
| 381 | { |
|---|
| 382 | TComPic* pcPic = *(iterPic++); |
|---|
| 383 | |
|---|
| 384 | pcPic->destroy(); |
|---|
| 385 | delete pcPic; |
|---|
| 386 | pcPic = NULL; |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | /** |
|---|
| 391 | - Application has picture buffer list with size of GOP + 1 |
|---|
| 392 | - Picture buffer list acts like as ring buffer |
|---|
| 393 | - End of the list has the latest picture |
|---|
| 394 | . |
|---|
| 395 | \param flush cause encoder to encode a partial GOP |
|---|
| 396 | \param pcPicYuvOrg original YUV picture |
|---|
| 397 | \param pcPicYuvTrueOrg |
|---|
| 398 | \param snrCSC |
|---|
| 399 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
|---|
| 400 | \retval accessUnitsOut list of output access units |
|---|
| 401 | \retval iNumEncoded number of encoded pictures |
|---|
| 402 | */ |
|---|
| 403 | #if SVC_EXTENSION |
|---|
| 404 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
|---|
| 405 | { |
|---|
| 406 | // compress GOP |
|---|
| 407 | #if !RC_SHVC_HARMONIZATION |
|---|
| 408 | if ( m_RCEnableRateControl ) |
|---|
| 409 | { |
|---|
| 410 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
|---|
| 411 | } |
|---|
| 412 | #endif |
|---|
| 413 | |
|---|
| 414 | // compress GOP |
|---|
| 415 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
|---|
| 416 | |
|---|
| 417 | #if !RC_SHVC_HARMONIZATION |
|---|
| 418 | if ( m_RCEnableRateControl ) |
|---|
| 419 | { |
|---|
| 420 | m_cRateCtrl.destroyRCGOP(); |
|---|
| 421 | } |
|---|
| 422 | #endif |
|---|
| 423 | |
|---|
| 424 | m_uiNumAllPicCoded ++; |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ) |
|---|
| 428 | { |
|---|
| 429 | if (pcPicYuvOrg != NULL) |
|---|
| 430 | { |
|---|
| 431 | // get original YUV |
|---|
| 432 | TComPic* pcPicCurr = NULL; |
|---|
| 433 | xGetNewPicBuffer( pcPicCurr ); |
|---|
| 434 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
|---|
| 435 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
|---|
| 436 | |
|---|
| 437 | // compute image characteristics |
|---|
| 438 | if ( getUseAdaptiveQP() ) |
|---|
| 439 | { |
|---|
| 440 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | #else |
|---|
| 445 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
|---|
| 446 | { |
|---|
| 447 | if (pcPicYuvOrg != NULL) |
|---|
| 448 | { |
|---|
| 449 | // get original YUV |
|---|
| 450 | TComPic* pcPicCurr = NULL; |
|---|
| 451 | |
|---|
| 452 | xGetNewPicBuffer( pcPicCurr ); |
|---|
| 453 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
|---|
| 454 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
|---|
| 455 | |
|---|
| 456 | // compute image characteristics |
|---|
| 457 | if ( getUseAdaptiveQP() ) |
|---|
| 458 | { |
|---|
| 459 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0))) |
|---|
| 464 | { |
|---|
| 465 | iNumEncoded = 0; |
|---|
| 466 | return; |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | if ( m_RCEnableRateControl ) |
|---|
| 470 | { |
|---|
| 471 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | // compress GOP |
|---|
| 475 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
|---|
| 476 | |
|---|
| 477 | if ( m_RCEnableRateControl ) |
|---|
| 478 | { |
|---|
| 479 | m_cRateCtrl.destroyRCGOP(); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | iNumEncoded = m_iNumPicRcvd; |
|---|
| 483 | m_iNumPicRcvd = 0; |
|---|
| 484 | m_uiNumAllPicCoded += iNumEncoded; |
|---|
| 485 | } |
|---|
| 486 | #endif |
|---|
| 487 | |
|---|
| 488 | /**------------------------------------------------ |
|---|
| 489 | Separate interlaced frame into two fields |
|---|
| 490 | -------------------------------------------------**/ |
|---|
| 491 | Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
|---|
| 492 | { |
|---|
| 493 | if (!isTop) |
|---|
| 494 | { |
|---|
| 495 | org += stride; |
|---|
| 496 | } |
|---|
| 497 | for (Int y = 0; y < height>>1; y++) |
|---|
| 498 | { |
|---|
| 499 | for (Int x = 0; x < width; x++) |
|---|
| 500 | { |
|---|
| 501 | dstField[x] = org[x]; |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | dstField += stride; |
|---|
| 505 | org += stride*2; |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | #if SVC_EXTENSION |
|---|
| 511 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ) |
|---|
| 512 | { |
|---|
| 513 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
|---|
| 514 | { |
|---|
| 515 | if (pcPicYuvOrg) |
|---|
| 516 | { |
|---|
| 517 | /* -- field initialization -- */ |
|---|
| 518 | const Bool isTopField=isTff==(fieldNum==0); |
|---|
| 519 | |
|---|
| 520 | TComPic *pcField; |
|---|
| 521 | xGetNewPicBuffer( pcField ); |
|---|
| 522 | pcField->setReconMark (false); // where is this normally? |
|---|
| 523 | |
|---|
| 524 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
|---|
| 525 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
|---|
| 526 | |
|---|
| 527 | pcField->setTopField(isTopField); // interlaced requirement |
|---|
| 528 | |
|---|
| 529 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
|---|
| 530 | { |
|---|
| 531 | const ComponentID component = ComponentID(componentIndex); |
|---|
| 532 | const UInt stride = pcPicYuvOrg->getStride(component); |
|---|
| 533 | |
|---|
| 534 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
|---|
| 535 | pcField->getPicYuvOrg()->getAddr(component), |
|---|
| 536 | pcPicYuvOrg->getStride(component), |
|---|
| 537 | pcPicYuvOrg->getWidth(component), |
|---|
| 538 | pcPicYuvOrg->getHeight(component), |
|---|
| 539 | isTopField); |
|---|
| 540 | |
|---|
| 541 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
|---|
| 542 | pcField->getPicYuvTrueOrg()->getAddr(component), |
|---|
| 543 | pcPicYuvTrueOrg->getStride(component), |
|---|
| 544 | pcPicYuvTrueOrg->getWidth(component), |
|---|
| 545 | pcPicYuvTrueOrg->getHeight(component), |
|---|
| 546 | isTopField); |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | // compute image characteristics |
|---|
| 550 | if ( getUseAdaptiveQP() ) |
|---|
| 551 | { |
|---|
| 552 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
|---|
| 553 | } |
|---|
| 554 | } |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ) |
|---|
| 559 | { |
|---|
| 560 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
|---|
| 561 | { |
|---|
| 562 | if (pcPicYuvOrg) |
|---|
| 563 | { |
|---|
| 564 | if (fieldNum==1) // where is this normally? |
|---|
| 565 | { |
|---|
| 566 | TComPicYuv* rpcPicYuvRec; |
|---|
| 567 | |
|---|
| 568 | // org. buffer |
|---|
| 569 | if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. |
|---|
| 570 | { |
|---|
| 571 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
|---|
| 572 | } |
|---|
| 573 | else |
|---|
| 574 | { |
|---|
| 575 | rpcPicYuvRec = new TComPicYuv; |
|---|
| 576 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); |
|---|
| 577 | } |
|---|
| 578 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
|---|
| 579 | } |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | // compress GOP |
|---|
| 583 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | m_uiNumAllPicCoded ++; |
|---|
| 587 | } |
|---|
| 588 | #else |
|---|
| 589 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
|---|
| 590 | { |
|---|
| 591 | iNumEncoded = 0; |
|---|
| 592 | |
|---|
| 593 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
|---|
| 594 | { |
|---|
| 595 | if (pcPicYuvOrg) |
|---|
| 596 | { |
|---|
| 597 | |
|---|
| 598 | /* -- field initialization -- */ |
|---|
| 599 | const Bool isTopField=isTff==(fieldNum==0); |
|---|
| 600 | |
|---|
| 601 | TComPic *pcField; |
|---|
| 602 | xGetNewPicBuffer( pcField ); |
|---|
| 603 | pcField->setReconMark (false); // where is this normally? |
|---|
| 604 | |
|---|
| 605 | if (fieldNum==1) // where is this normally? |
|---|
| 606 | { |
|---|
| 607 | TComPicYuv* rpcPicYuvRec; |
|---|
| 608 | |
|---|
| 609 | // org. buffer |
|---|
| 610 | if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. |
|---|
| 611 | { |
|---|
| 612 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
|---|
| 613 | } |
|---|
| 614 | else |
|---|
| 615 | { |
|---|
| 616 | rpcPicYuvRec = new TComPicYuv; |
|---|
| 617 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth); |
|---|
| 618 | } |
|---|
| 619 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
|---|
| 623 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
|---|
| 624 | |
|---|
| 625 | pcField->setTopField(isTopField); // interlaced requirement |
|---|
| 626 | |
|---|
| 627 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
|---|
| 628 | { |
|---|
| 629 | const ComponentID component = ComponentID(componentIndex); |
|---|
| 630 | const UInt stride = pcPicYuvOrg->getStride(component); |
|---|
| 631 | |
|---|
| 632 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
|---|
| 633 | pcField->getPicYuvOrg()->getAddr(component), |
|---|
| 634 | pcPicYuvOrg->getStride(component), |
|---|
| 635 | pcPicYuvOrg->getWidth(component), |
|---|
| 636 | pcPicYuvOrg->getHeight(component), |
|---|
| 637 | isTopField); |
|---|
| 638 | |
|---|
| 639 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
|---|
| 640 | pcField->getPicYuvTrueOrg()->getAddr(component), |
|---|
| 641 | pcPicYuvTrueOrg->getStride(component), |
|---|
| 642 | pcPicYuvTrueOrg->getWidth(component), |
|---|
| 643 | pcPicYuvTrueOrg->getHeight(component), |
|---|
| 644 | isTopField); |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | // compute image characteristics |
|---|
| 648 | if ( getUseAdaptiveQP() ) |
|---|
| 649 | { |
|---|
| 650 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
|---|
| 651 | } |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) |
|---|
| 655 | { |
|---|
| 656 | // compress GOP |
|---|
| 657 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
|---|
| 658 | |
|---|
| 659 | iNumEncoded += m_iNumPicRcvd; |
|---|
| 660 | m_uiNumAllPicCoded += m_iNumPicRcvd; |
|---|
| 661 | m_iNumPicRcvd = 0; |
|---|
| 662 | } |
|---|
| 663 | } |
|---|
| 664 | } |
|---|
| 665 | #endif |
|---|
| 666 | |
|---|
| 667 | // ==================================================================================================================== |
|---|
| 668 | // Protected member functions |
|---|
| 669 | // ==================================================================================================================== |
|---|
| 670 | |
|---|
| 671 | /** |
|---|
| 672 | - Application has picture buffer list with size of GOP + 1 |
|---|
| 673 | - Picture buffer list acts like as ring buffer |
|---|
| 674 | - End of the list has the latest picture |
|---|
| 675 | . |
|---|
| 676 | \retval rpcPic obtained picture buffer |
|---|
| 677 | */ |
|---|
| 678 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
|---|
| 679 | { |
|---|
| 680 | // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic. |
|---|
| 681 | |
|---|
| 682 | TComSlice::sortPicList(m_cListPic); |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
|---|
| 686 | { |
|---|
| 687 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
|---|
| 688 | Int iSize = Int( m_cListPic.size() ); |
|---|
| 689 | for ( Int i = 0; i < iSize; i++ ) |
|---|
| 690 | { |
|---|
| 691 | rpcPic = *(iterPic++); |
|---|
| 692 | if(rpcPic->getSlice(0)->isReferenced() == false) |
|---|
| 693 | { |
|---|
| 694 | break; |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | else |
|---|
| 699 | { |
|---|
| 700 | if ( getUseAdaptiveQP() ) |
|---|
| 701 | { |
|---|
| 702 | TEncPic* pcEPic = new TEncPic; |
|---|
| 703 | |
|---|
| 704 | #if SVC_EXTENSION //Temporal solution, should be modified |
|---|
| 705 | if( m_layerId > 0 ) |
|---|
| 706 | { |
|---|
| 707 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
|---|
| 708 | { |
|---|
| 709 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 710 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 711 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
|---|
| 712 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 713 | |
|---|
| 714 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
|---|
| 715 | |
|---|
| 716 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
|---|
| 717 | Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] ); |
|---|
| 718 | |
|---|
| 719 | if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase ) |
|---|
| 720 | { |
|---|
| 721 | pcEPic->setEqualPictureSizeAndOffsetFlag( i, true ); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths |
|---|
| 725 | #if CGS_3D_ASYMLUT |
|---|
| 726 | || m_cPPS.getCGSFlag() > 0 |
|---|
| 727 | #endif |
|---|
| 728 | #if LAYER_CTB |
|---|
| 729 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
|---|
| 730 | #endif |
|---|
| 731 | ) |
|---|
| 732 | { |
|---|
| 733 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
|---|
| 734 | |
|---|
| 735 | //only for scalable extension |
|---|
| 736 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | pcEPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId); |
|---|
| 742 | #else //SVC_EXTENSION |
|---|
| 743 | pcEPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1, false); |
|---|
| 744 | #endif //SVC_EXTENSION |
|---|
| 745 | rpcPic = pcEPic; |
|---|
| 746 | } |
|---|
| 747 | else |
|---|
| 748 | { |
|---|
| 749 | rpcPic = new TComPic; |
|---|
| 750 | |
|---|
| 751 | #if SVC_EXTENSION //Temporal solution, should be modified |
|---|
| 752 | if( m_layerId > 0 ) |
|---|
| 753 | { |
|---|
| 754 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
|---|
| 755 | { |
|---|
| 756 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 757 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 758 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
|---|
| 759 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
|---|
| 760 | |
|---|
| 761 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
|---|
| 762 | |
|---|
| 763 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
|---|
| 764 | Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] ); |
|---|
| 765 | |
|---|
| 766 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths |
|---|
| 767 | || !equalOffsets |
|---|
| 768 | || !zeroPhase |
|---|
| 769 | #if CGS_3D_ASYMLUT |
|---|
| 770 | || m_cPPS.getCGSFlag() > 0 |
|---|
| 771 | #endif |
|---|
| 772 | #if LAYER_CTB |
|---|
| 773 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
|---|
| 774 | #endif |
|---|
| 775 | ) |
|---|
| 776 | { |
|---|
| 777 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
|---|
| 778 | |
|---|
| 779 | //only for scalable extension |
|---|
| 780 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
|---|
| 781 | } |
|---|
| 782 | } |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | rpcPic->create( m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false, m_layerId ); |
|---|
| 786 | #else //SVC_EXTENSION |
|---|
| 787 | rpcPic->create( m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, false ); |
|---|
| 788 | #endif //SVC_EXTENSION |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | m_cListPic.pushBack( rpcPic ); |
|---|
| 792 | } |
|---|
| 793 | rpcPic->setReconMark (false); |
|---|
| 794 | |
|---|
| 795 | m_iPOCLast++; |
|---|
| 796 | m_iNumPicRcvd++; |
|---|
| 797 | |
|---|
| 798 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
|---|
| 799 | // mark it should be extended |
|---|
| 800 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | Void TEncTop::xInitVPS() |
|---|
| 804 | { |
|---|
| 805 | // The SPS must have already been set up. |
|---|
| 806 | // set the VPS profile information. |
|---|
| 807 | #if SVC_EXTENSION |
|---|
| 808 | m_cVPS.setVpsVuiPresentFlag( true ); |
|---|
| 809 | #else |
|---|
| 810 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
|---|
| 811 | m_cVPS.setMaxOpSets(1); |
|---|
| 812 | #endif |
|---|
| 813 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
|---|
| 814 | m_cVPS.setNumHrdParameters( 0 ); |
|---|
| 815 | |
|---|
| 816 | m_cVPS.createHrdParamBuffer(); |
|---|
| 817 | for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ ) |
|---|
| 818 | { |
|---|
| 819 | m_cVPS.setHrdOpSetIdx( 0, i ); |
|---|
| 820 | m_cVPS.setCprmsPresentFlag( false, i ); |
|---|
| 821 | // Set up HrdParameters here. |
|---|
| 822 | } |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | Void TEncTop::xInitSPS() |
|---|
| 826 | { |
|---|
| 827 | #if SVC_EXTENSION |
|---|
| 828 | m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false ); |
|---|
| 829 | m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers); |
|---|
| 830 | |
|---|
| 831 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
|---|
| 832 | { |
|---|
| 833 | m_cSPS.setLayerId(0); // layer ID 0 for independent layers |
|---|
| 834 | } |
|---|
| 835 | else |
|---|
| 836 | { |
|---|
| 837 | m_cSPS.setLayerId(m_layerId); |
|---|
| 838 | } |
|---|
| 839 | #endif //SVC_EXTENSION |
|---|
| 840 | |
|---|
| 841 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
|---|
| 842 | profileTierLevel.setLevelIdc(m_level); |
|---|
| 843 | profileTierLevel.setTierFlag(m_levelTier); |
|---|
| 844 | profileTierLevel.setProfileIdc(m_profile); |
|---|
| 845 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
|---|
| 846 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
|---|
| 847 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
|---|
| 848 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
|---|
| 849 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
|---|
| 850 | profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue); |
|---|
| 851 | profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue); |
|---|
| 852 | profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag); |
|---|
| 853 | profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag); |
|---|
| 854 | |
|---|
| 855 | if ((m_profile == Profile::MAIN10) && (g_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (g_bitDepth[CHANNEL_TYPE_CHROMA] == 8)) |
|---|
| 856 | { |
|---|
| 857 | /* The above constraint is equal to Profile::MAIN */ |
|---|
| 858 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
|---|
| 859 | } |
|---|
| 860 | if (m_profile == Profile::MAIN) |
|---|
| 861 | { |
|---|
| 862 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
|---|
| 863 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
|---|
| 864 | } |
|---|
| 865 | /* XXX: should Main be marked as compatible with still picture? */ |
|---|
| 866 | /* XXX: may be a good idea to refactor the above into a function |
|---|
| 867 | * that chooses the actual compatibility based upon options */ |
|---|
| 868 | |
|---|
| 869 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
|---|
| 870 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
|---|
| 871 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
|---|
| 872 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
|---|
| 873 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
|---|
| 874 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
|---|
| 875 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
|---|
| 876 | |
|---|
| 877 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth ); |
|---|
| 878 | Int log2MinCUSize = 0; |
|---|
| 879 | while(minCUSize > 1) |
|---|
| 880 | { |
|---|
| 881 | minCUSize >>= 1; |
|---|
| 882 | log2MinCUSize++; |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
|---|
| 886 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth-getMaxCUDepthOffset(m_cSPS.getChromaFormatIdc(), m_cSPS.getQuadtreeTULog2MinSize())); |
|---|
| 887 | #if SVC_EXTENSION |
|---|
| 888 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
|---|
| 889 | #endif |
|---|
| 890 | |
|---|
| 891 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
|---|
| 892 | m_cSPS.setUsePCM ( m_usePCM ); |
|---|
| 893 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
|---|
| 894 | |
|---|
| 895 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
|---|
| 896 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
|---|
| 897 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
|---|
| 898 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
|---|
| 899 | |
|---|
| 900 | m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1)); |
|---|
| 901 | |
|---|
| 902 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
|---|
| 903 | |
|---|
| 904 | m_cSPS.setUseAMP ( m_useAMP ); |
|---|
| 905 | |
|---|
| 906 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
|---|
| 907 | { |
|---|
| 908 | #if SVC_EXTENSION |
|---|
| 909 | m_cSPS.setBitDepth (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) ); |
|---|
| 910 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8))); |
|---|
| 911 | #else |
|---|
| 912 | m_cSPS.setBitDepth (ChannelType(channelType), g_bitDepth[channelType] ); |
|---|
| 913 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (g_bitDepth[channelType] - 8))); |
|---|
| 914 | #endif |
|---|
| 915 | m_cSPS.setPCMBitDepth (ChannelType(channelType), g_PCMBitDepth[channelType] ); |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | m_cSPS.setUseExtendedPrecision(m_useExtendedPrecision); |
|---|
| 919 | m_cSPS.setUseHighPrecisionPredictionWeighting(m_useHighPrecisionPredictionWeighting); |
|---|
| 920 | |
|---|
| 921 | m_cSPS.setUseSAO( m_bUseSAO ); |
|---|
| 922 | m_cSPS.setUseResidualRotation(m_useResidualRotation); |
|---|
| 923 | m_cSPS.setUseSingleSignificanceMapContext(m_useSingleSignificanceMapContext); |
|---|
| 924 | m_cSPS.setUseGolombRiceParameterAdaptation(m_useGolombRiceParameterAdaptation); |
|---|
| 925 | m_cSPS.setAlignCABACBeforeBypass(m_alignCABACBeforeBypass); |
|---|
| 926 | |
|---|
| 927 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
|---|
| 928 | { |
|---|
| 929 | m_cSPS.setUseResidualDPCM(RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]); |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
|---|
| 933 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
|---|
| 934 | |
|---|
| 935 | for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
|---|
| 936 | { |
|---|
| 937 | #if SVC_EXTENSION |
|---|
| 938 | assert(i < MAX_TLAYER); |
|---|
| 939 | #endif |
|---|
| 940 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
|---|
| 941 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
|---|
| 945 | m_cSPS.setDisableIntraReferenceSmoothing( m_disableIntraReferenceSmoothing ); |
|---|
| 946 | m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 ); |
|---|
| 947 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
|---|
| 948 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
|---|
| 949 | |
|---|
| 950 | if (m_cSPS.getVuiParametersPresentFlag()) |
|---|
| 951 | { |
|---|
| 952 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
|---|
| 953 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag()); |
|---|
| 954 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
|---|
| 955 | pcVUI->setSarWidth(getSarWidth()); |
|---|
| 956 | pcVUI->setSarHeight(getSarHeight()); |
|---|
| 957 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
|---|
| 958 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
|---|
| 959 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
|---|
| 960 | pcVUI->setVideoFormat(getVideoFormat()); |
|---|
| 961 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
|---|
| 962 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
|---|
| 963 | pcVUI->setColourPrimaries(getColourPrimaries()); |
|---|
| 964 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
|---|
| 965 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
|---|
| 966 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
|---|
| 967 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
|---|
| 968 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
|---|
| 969 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
|---|
| 970 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
|---|
| 971 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
|---|
| 972 | pcVUI->setFieldSeqFlag(false); |
|---|
| 973 | pcVUI->setHrdParametersPresentFlag(false); |
|---|
| 974 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
|---|
| 975 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
|---|
| 976 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
|---|
| 977 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
|---|
| 978 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
|---|
| 979 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
|---|
| 980 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
|---|
| 981 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
|---|
| 982 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
|---|
| 983 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
|---|
| 984 | } |
|---|
| 985 | m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS); |
|---|
| 986 | assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS); |
|---|
| 987 | for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++) |
|---|
| 988 | { |
|---|
| 989 | m_cSPS.setLtRefPicPocLsbSps(k, 0); |
|---|
| 990 | m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0); |
|---|
| 991 | } |
|---|
| 992 | if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
|---|
| 993 | { |
|---|
| 994 | Bool useDUParameters = (getSliceMode() > 0) || (getSliceSegmentMode() > 0); |
|---|
| 995 | m_cSPS.setHrdParameters( getFrameRate(), useDUParameters, getTargetBitrate(), ( getIntraPeriod() > 0 ) ); |
|---|
| 996 | } |
|---|
| 997 | if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
|---|
| 998 | { |
|---|
| 999 | m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true ); |
|---|
| 1000 | } |
|---|
| 1001 | } |
|---|
| 1002 | |
|---|
| 1003 | Void TEncTop::xInitPPS() |
|---|
| 1004 | { |
|---|
| 1005 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
|---|
| 1006 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
|---|
| 1007 | |
|---|
| 1008 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
|---|
| 1009 | { |
|---|
| 1010 | bUseDQP = true; |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING) |
|---|
| 1014 | { |
|---|
| 1015 | bUseDQP=false; |
|---|
| 1016 | } |
|---|
| 1017 | |
|---|
| 1018 | |
|---|
| 1019 | if ( m_RCEnableRateControl ) |
|---|
| 1020 | { |
|---|
| 1021 | m_cPPS.setUseDQP(true); |
|---|
| 1022 | m_cPPS.setMaxCuDQPDepth( 0 ); |
|---|
| 1023 | } |
|---|
| 1024 | else if(bUseDQP) |
|---|
| 1025 | { |
|---|
| 1026 | m_cPPS.setUseDQP(true); |
|---|
| 1027 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
|---|
| 1028 | } |
|---|
| 1029 | else |
|---|
| 1030 | { |
|---|
| 1031 | m_cPPS.setUseDQP(false); |
|---|
| 1032 | m_cPPS.setMaxCuDQPDepth( 0 ); |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | if ( m_maxCUChromaQpAdjustmentDepth >= 0 ) |
|---|
| 1036 | { |
|---|
| 1037 | m_cPPS.setMaxCuChromaQpAdjDepth(m_maxCUChromaQpAdjustmentDepth); |
|---|
| 1038 | m_cPPS.setChromaQpAdjTableAt(1, 6, 6); |
|---|
| 1039 | /* todo, insert table entries from command line (NB, 0 should not be touched) */ |
|---|
| 1040 | } |
|---|
| 1041 | else |
|---|
| 1042 | { |
|---|
| 1043 | m_cPPS.setMaxCuChromaQpAdjDepth(0); |
|---|
| 1044 | m_cPPS.clearChromaQpAdjTable(); |
|---|
| 1045 | } |
|---|
| 1046 | |
|---|
| 1047 | m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset ); |
|---|
| 1048 | m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset ); |
|---|
| 1049 | |
|---|
| 1050 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
|---|
| 1051 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
|---|
| 1052 | m_cPPS.setUseWP( m_useWeightedPred ); |
|---|
| 1053 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
|---|
| 1054 | m_cPPS.setUseCrossComponentPrediction(m_useCrossComponentPrediction); |
|---|
| 1055 | m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_LUMA, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA ]); |
|---|
| 1056 | m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA]); |
|---|
| 1057 | m_cPPS.setOutputFlagPresentFlag( false ); |
|---|
| 1058 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
|---|
| 1059 | if ( getDeblockingFilterMetric() ) |
|---|
| 1060 | { |
|---|
| 1061 | m_cPPS.setDeblockingFilterControlPresentFlag (true); |
|---|
| 1062 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
|---|
| 1063 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
|---|
| 1064 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
|---|
| 1065 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
|---|
| 1066 | } |
|---|
| 1067 | else |
|---|
| 1068 | { |
|---|
| 1069 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
|---|
| 1070 | |
|---|
| 1071 | if (m_cPPS.getDeblockingFilterControlPresentFlag()) |
|---|
| 1072 | { |
|---|
| 1073 | m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() ); |
|---|
| 1074 | m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() ); |
|---|
| 1075 | } |
|---|
| 1076 | } |
|---|
| 1077 | |
|---|
| 1078 | if (m_cPPS.getDeblockingFilterControlPresentFlag() && ! m_cPPS.getPicDisableDeblockingFilterFlag()) |
|---|
| 1079 | { |
|---|
| 1080 | m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() ); |
|---|
| 1081 | m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() ); |
|---|
| 1082 | } |
|---|
| 1083 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
|---|
| 1084 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
|---|
| 1085 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
|---|
| 1086 | |
|---|
| 1087 | |
|---|
| 1088 | Int histogram[MAX_NUM_REF + 1]; |
|---|
| 1089 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
|---|
| 1090 | { |
|---|
| 1091 | histogram[i]=0; |
|---|
| 1092 | } |
|---|
| 1093 | for( Int i = 0; i < getGOPSize(); i++) |
|---|
| 1094 | { |
|---|
| 1095 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
|---|
| 1096 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
|---|
| 1097 | } |
|---|
| 1098 | |
|---|
| 1099 | Int maxHist=-1; |
|---|
| 1100 | Int bestPos=0; |
|---|
| 1101 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
|---|
| 1102 | { |
|---|
| 1103 | if(histogram[i]>maxHist) |
|---|
| 1104 | { |
|---|
| 1105 | maxHist=histogram[i]; |
|---|
| 1106 | bestPos=i; |
|---|
| 1107 | } |
|---|
| 1108 | } |
|---|
| 1109 | assert(bestPos <= 15); |
|---|
| 1110 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
|---|
| 1111 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
|---|
| 1112 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
|---|
| 1113 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
|---|
| 1114 | m_cPPS.setTransformSkipLog2MaxSize( m_transformSkipLog2MaxSize ); |
|---|
| 1115 | |
|---|
| 1116 | if (m_sliceSegmentMode != NO_SLICES) |
|---|
| 1117 | { |
|---|
| 1118 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
|---|
| 1119 | } |
|---|
| 1120 | |
|---|
| 1121 | #if SVC_EXTENSION |
|---|
| 1122 | m_cPPS.setLayerId( m_layerId ); |
|---|
| 1123 | |
|---|
| 1124 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
|---|
| 1125 | { |
|---|
| 1126 | m_cPPS.setLayerId(0); // layer ID 0 for independent layers |
|---|
| 1127 | } |
|---|
| 1128 | |
|---|
| 1129 | if( m_layerId > 0 ) |
|---|
| 1130 | { |
|---|
| 1131 | m_cPPS.setListsModificationPresentFlag(true); |
|---|
| 1132 | m_cPPS.setExtensionFlag(true); |
|---|
| 1133 | } |
|---|
| 1134 | else |
|---|
| 1135 | { |
|---|
| 1136 | m_cPPS.setListsModificationPresentFlag(false); |
|---|
| 1137 | m_cPPS.setExtensionFlag(false); |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | m_cPPS.setPPSId( m_iPPSIdCnt ); |
|---|
| 1141 | m_cPPS.setSPSId( m_iSPSIdCnt ); |
|---|
| 1142 | |
|---|
| 1143 | if( m_crossLayerBLAFlag ) |
|---|
| 1144 | { |
|---|
| 1145 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
|---|
| 1146 | } |
|---|
| 1147 | |
|---|
| 1148 | m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets); |
|---|
| 1149 | for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++) |
|---|
| 1150 | { |
|---|
| 1151 | m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]); |
|---|
| 1152 | m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
|---|
| 1153 | m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i]; |
|---|
| 1154 | m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] ); |
|---|
| 1155 | m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] ); |
|---|
| 1156 | m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] ); |
|---|
| 1157 | m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] ); |
|---|
| 1158 | m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] ); |
|---|
| 1159 | m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] ); |
|---|
| 1160 | m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] ); |
|---|
| 1161 | } |
|---|
| 1162 | #if CGS_3D_ASYMLUT |
|---|
| 1163 | m_cPPS.setCGSFlag( m_nCGSFlag ); |
|---|
| 1164 | #endif |
|---|
| 1165 | m_cPPS.setPocResetInfoPresentFlag( true ); |
|---|
| 1166 | m_cPPS.setExtensionFlag( true ); |
|---|
| 1167 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
|---|
| 1168 | #endif //SVC_EXTENSION |
|---|
| 1169 | } |
|---|
| 1170 | |
|---|
| 1171 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
|---|
| 1172 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
|---|
| 1173 | { |
|---|
| 1174 | TComReferencePictureSet* rps; |
|---|
| 1175 | |
|---|
| 1176 | m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1); |
|---|
| 1177 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
|---|
| 1178 | |
|---|
| 1179 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
|---|
| 1180 | { |
|---|
| 1181 | GOPEntry ge = getGOPEntry(i); |
|---|
| 1182 | rps = rpsList->getReferencePictureSet(i); |
|---|
| 1183 | rps->setNumberOfPictures(ge.m_numRefPics); |
|---|
| 1184 | rps->setNumRefIdc(ge.m_numRefIdc); |
|---|
| 1185 | Int numNeg = 0; |
|---|
| 1186 | Int numPos = 0; |
|---|
| 1187 | for( Int j = 0; j < ge.m_numRefPics; j++) |
|---|
| 1188 | { |
|---|
| 1189 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
|---|
| 1190 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
|---|
| 1191 | if(ge.m_referencePics[j]>0) |
|---|
| 1192 | { |
|---|
| 1193 | numPos++; |
|---|
| 1194 | } |
|---|
| 1195 | else |
|---|
| 1196 | { |
|---|
| 1197 | numNeg++; |
|---|
| 1198 | } |
|---|
| 1199 | } |
|---|
| 1200 | rps->setNumberOfNegativePictures(numNeg); |
|---|
| 1201 | rps->setNumberOfPositivePictures(numPos); |
|---|
| 1202 | |
|---|
| 1203 | // handle inter RPS intialization from the config file. |
|---|
| 1204 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
|---|
| 1205 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
|---|
| 1206 | TComReferencePictureSet* RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL; // get the reference RPS |
|---|
| 1207 | |
|---|
| 1208 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
|---|
| 1209 | { |
|---|
| 1210 | assert (RPSRef!=NULL); |
|---|
| 1211 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
|---|
| 1212 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
|---|
| 1213 | |
|---|
| 1214 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
|---|
| 1215 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
|---|
| 1216 | Int count=0; |
|---|
| 1217 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
|---|
| 1218 | { |
|---|
| 1219 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
|---|
| 1220 | rps->setRefIdc(j, 0); |
|---|
| 1221 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
|---|
| 1222 | { |
|---|
| 1223 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
|---|
| 1224 | { |
|---|
| 1225 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
|---|
| 1226 | count++; |
|---|
| 1227 | break; |
|---|
| 1228 | } |
|---|
| 1229 | } |
|---|
| 1230 | } |
|---|
| 1231 | if (count != rps->getNumberOfPictures()) |
|---|
| 1232 | { |
|---|
| 1233 | printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file. Setting Inter RPS to false for this RPS.\n"); |
|---|
| 1234 | rps->setInterRPSPrediction(0); |
|---|
| 1235 | } |
|---|
| 1236 | } |
|---|
| 1237 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
|---|
| 1238 | { |
|---|
| 1239 | assert (RPSRef!=NULL); |
|---|
| 1240 | rps->setDeltaRPS(ge.m_deltaRPS); |
|---|
| 1241 | rps->setNumRefIdc(ge.m_numRefIdc); |
|---|
| 1242 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
|---|
| 1243 | { |
|---|
| 1244 | rps->setRefIdc(j, ge.m_refIdc[j]); |
|---|
| 1245 | } |
|---|
| 1246 | #if WRITE_BACK |
|---|
| 1247 | // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones |
|---|
| 1248 | // computed from the RefIdc. A warning is printed if they are not identical. |
|---|
| 1249 | numNeg = 0; |
|---|
| 1250 | numPos = 0; |
|---|
| 1251 | TComReferencePictureSet RPSTemp; // temporary variable |
|---|
| 1252 | |
|---|
| 1253 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
|---|
| 1254 | { |
|---|
| 1255 | if (ge.m_refIdc[j]) |
|---|
| 1256 | { |
|---|
| 1257 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
|---|
| 1258 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
|---|
| 1259 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
|---|
| 1260 | if (deltaPOC<0) |
|---|
| 1261 | { |
|---|
| 1262 | numNeg++; |
|---|
| 1263 | } |
|---|
| 1264 | else |
|---|
| 1265 | { |
|---|
| 1266 | numPos++; |
|---|
| 1267 | } |
|---|
| 1268 | } |
|---|
| 1269 | } |
|---|
| 1270 | if (numNeg != rps->getNumberOfNegativePictures()) |
|---|
| 1271 | { |
|---|
| 1272 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
|---|
| 1273 | rps->setNumberOfNegativePictures(numNeg); |
|---|
| 1274 | rps->setNumberOfPictures(numNeg+numPos); |
|---|
| 1275 | } |
|---|
| 1276 | if (numPos != rps->getNumberOfPositivePictures()) |
|---|
| 1277 | { |
|---|
| 1278 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
|---|
| 1279 | rps->setNumberOfPositivePictures(numPos); |
|---|
| 1280 | rps->setNumberOfPictures(numNeg+numPos); |
|---|
| 1281 | } |
|---|
| 1282 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
|---|
| 1283 | RPSTemp.setNumberOfNegativePictures(numNeg); |
|---|
| 1284 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
|---|
| 1285 | // check if Delta POC and Used are the same |
|---|
| 1286 | // print warning if they are not. |
|---|
| 1287 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
|---|
| 1288 | { |
|---|
| 1289 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
|---|
| 1290 | { |
|---|
| 1291 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
|---|
| 1292 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
|---|
| 1293 | } |
|---|
| 1294 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
|---|
| 1295 | { |
|---|
| 1296 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
|---|
| 1297 | rps->setUsed(j,RPSTemp.getUsed(j)); |
|---|
| 1298 | } |
|---|
| 1299 | } |
|---|
| 1300 | #endif |
|---|
| 1301 | } |
|---|
| 1302 | } |
|---|
| 1303 | //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. |
|---|
| 1304 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
|---|
| 1305 | if (isFieldCoding) |
|---|
| 1306 | { |
|---|
| 1307 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
|---|
| 1308 | rps->setNumberOfPictures(1); |
|---|
| 1309 | rps->setNumberOfNegativePictures(1); |
|---|
| 1310 | rps->setNumberOfPositivePictures(0); |
|---|
| 1311 | rps->setNumberOfLongtermPictures(0); |
|---|
| 1312 | rps->setDeltaPOC(0,-1); |
|---|
| 1313 | rps->setPOC(0,0); |
|---|
| 1314 | rps->setUsed(0,true); |
|---|
| 1315 | rps->setInterRPSPrediction(false); |
|---|
| 1316 | rps->setDeltaRIdxMinus1(0); |
|---|
| 1317 | rps->setDeltaRPS(0); |
|---|
| 1318 | rps->setNumRefIdc(0); |
|---|
| 1319 | } |
|---|
| 1320 | } |
|---|
| 1321 | |
|---|
| 1322 | // This is a function that |
|---|
| 1323 | // determines what Reference Picture Set to use |
|---|
| 1324 | // for a specific slice (with POC = POCCurr) |
|---|
| 1325 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
|---|
| 1326 | { |
|---|
| 1327 | slice->setRPSidx(GOPid); |
|---|
| 1328 | |
|---|
| 1329 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
|---|
| 1330 | { |
|---|
| 1331 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
|---|
| 1332 | { |
|---|
| 1333 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
|---|
| 1334 | if(POCIndex == 0) |
|---|
| 1335 | { |
|---|
| 1336 | POCIndex = m_uiIntraPeriod; |
|---|
| 1337 | } |
|---|
| 1338 | if(POCIndex == m_GOPList[extraNum].m_POC) |
|---|
| 1339 | { |
|---|
| 1340 | slice->setRPSidx(extraNum); |
|---|
| 1341 | } |
|---|
| 1342 | } |
|---|
| 1343 | else |
|---|
| 1344 | { |
|---|
| 1345 | if(POCCurr==m_GOPList[extraNum].m_POC) |
|---|
| 1346 | { |
|---|
| 1347 | slice->setRPSidx(extraNum); |
|---|
| 1348 | } |
|---|
| 1349 | } |
|---|
| 1350 | } |
|---|
| 1351 | |
|---|
| 1352 | if(POCCurr == 1 && slice->getPic()->isField()) |
|---|
| 1353 | { |
|---|
| 1354 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
|---|
| 1355 | } |
|---|
| 1356 | |
|---|
| 1357 | TComReferencePictureSet *rps=slice->getLocalRPS(); |
|---|
| 1358 | (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
|---|
| 1359 | slice->setRPS(rps); |
|---|
| 1360 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
|---|
| 1361 | } |
|---|
| 1362 | |
|---|
| 1363 | Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ) |
|---|
| 1364 | { |
|---|
| 1365 | Int rpsIdx = GOPid; |
|---|
| 1366 | |
|---|
| 1367 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
|---|
| 1368 | { |
|---|
| 1369 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
|---|
| 1370 | { |
|---|
| 1371 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
|---|
| 1372 | if(POCIndex == 0) |
|---|
| 1373 | { |
|---|
| 1374 | POCIndex = m_uiIntraPeriod; |
|---|
| 1375 | } |
|---|
| 1376 | if(POCIndex == m_GOPList[extraNum].m_POC) |
|---|
| 1377 | { |
|---|
| 1378 | rpsIdx = extraNum; |
|---|
| 1379 | } |
|---|
| 1380 | } |
|---|
| 1381 | else |
|---|
| 1382 | { |
|---|
| 1383 | if(POCCurr==m_GOPList[extraNum].m_POC) |
|---|
| 1384 | { |
|---|
| 1385 | rpsIdx = extraNum; |
|---|
| 1386 | } |
|---|
| 1387 | } |
|---|
| 1388 | } |
|---|
| 1389 | |
|---|
| 1390 | return rpsIdx; |
|---|
| 1391 | } |
|---|
| 1392 | |
|---|
| 1393 | Void TEncTop::xInitPPSforTiles() |
|---|
| 1394 | { |
|---|
| 1395 | m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag ); |
|---|
| 1396 | m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 ); |
|---|
| 1397 | m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 ); |
|---|
| 1398 | if( !m_tileUniformSpacingFlag ) |
|---|
| 1399 | { |
|---|
| 1400 | m_cPPS.setTileColumnWidth( m_tileColumnWidth ); |
|---|
| 1401 | m_cPPS.setTileRowHeight( m_tileRowHeight ); |
|---|
| 1402 | } |
|---|
| 1403 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
|---|
| 1404 | |
|---|
| 1405 | // # substreams is "per tile" when tiles are independent. |
|---|
| 1406 | } |
|---|
| 1407 | |
|---|
| 1408 | Void TEncCfg::xCheckGSParameters() |
|---|
| 1409 | { |
|---|
| 1410 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
|---|
| 1411 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
|---|
| 1412 | UInt uiCummulativeColumnWidth = 0; |
|---|
| 1413 | UInt uiCummulativeRowHeight = 0; |
|---|
| 1414 | |
|---|
| 1415 | //check the column relative parameters |
|---|
| 1416 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
|---|
| 1417 | { |
|---|
| 1418 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
|---|
| 1419 | exit( EXIT_FAILURE ); |
|---|
| 1420 | } |
|---|
| 1421 | |
|---|
| 1422 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
|---|
| 1423 | { |
|---|
| 1424 | printf( "The current picture can not have so many columns.\n" ); |
|---|
| 1425 | exit( EXIT_FAILURE ); |
|---|
| 1426 | } |
|---|
| 1427 | |
|---|
| 1428 | if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag ) |
|---|
| 1429 | { |
|---|
| 1430 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
|---|
| 1431 | { |
|---|
| 1432 | uiCummulativeColumnWidth += m_tileColumnWidth[i]; |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
|---|
| 1436 | { |
|---|
| 1437 | printf( "The width of the column is too large.\n" ); |
|---|
| 1438 | exit( EXIT_FAILURE ); |
|---|
| 1439 | } |
|---|
| 1440 | } |
|---|
| 1441 | |
|---|
| 1442 | //check the row relative parameters |
|---|
| 1443 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
|---|
| 1444 | { |
|---|
| 1445 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
|---|
| 1446 | exit( EXIT_FAILURE ); |
|---|
| 1447 | } |
|---|
| 1448 | |
|---|
| 1449 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
|---|
| 1450 | { |
|---|
| 1451 | printf( "The current picture can not have so many rows.\n" ); |
|---|
| 1452 | exit( EXIT_FAILURE ); |
|---|
| 1453 | } |
|---|
| 1454 | |
|---|
| 1455 | if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag ) |
|---|
| 1456 | { |
|---|
| 1457 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
|---|
| 1458 | { |
|---|
| 1459 | uiCummulativeRowHeight += m_tileRowHeight[i]; |
|---|
| 1460 | } |
|---|
| 1461 | |
|---|
| 1462 | if( uiCummulativeRowHeight >= iHeightInCU ) |
|---|
| 1463 | { |
|---|
| 1464 | printf( "The height of the row is too large.\n" ); |
|---|
| 1465 | exit( EXIT_FAILURE ); |
|---|
| 1466 | } |
|---|
| 1467 | } |
|---|
| 1468 | } |
|---|
| 1469 | |
|---|
| 1470 | #if SVC_EXTENSION |
|---|
| 1471 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx ) |
|---|
| 1472 | { |
|---|
| 1473 | if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 ) |
|---|
| 1474 | { |
|---|
| 1475 | return (TEncTop *)getLayerEnc( 0 ); |
|---|
| 1476 | } |
|---|
| 1477 | |
|---|
| 1478 | return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) ); |
|---|
| 1479 | } |
|---|
| 1480 | |
|---|
| 1481 | Void TEncTop::xInitILRP() |
|---|
| 1482 | { |
|---|
| 1483 | RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) ); |
|---|
| 1484 | Int bitDepthY,bitDepthC; |
|---|
| 1485 | |
|---|
| 1486 | bitDepthY = repFormat->getBitDepthVpsLuma(); |
|---|
| 1487 | bitDepthC = repFormat->getBitDepthVpsChroma(); |
|---|
| 1488 | |
|---|
| 1489 | if( m_layerId > 0 ) |
|---|
| 1490 | { |
|---|
| 1491 | g_bitDepth[CHANNEL_TYPE_LUMA] = bitDepthY; |
|---|
| 1492 | g_bitDepth[CHANNEL_TYPE_CHROMA] = bitDepthC; |
|---|
| 1493 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
|---|
| 1494 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
|---|
| 1495 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
|---|
| 1496 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
|---|
| 1497 | |
|---|
| 1498 | if (m_cIlpPic[0] == NULL) |
|---|
| 1499 | { |
|---|
| 1500 | for (Int j=0; j < m_numDirectRefLayers; j++) |
|---|
| 1501 | { |
|---|
| 1502 | m_cIlpPic[j] = new TComPic; |
|---|
| 1503 | m_cIlpPic[j]->create(m_cVPS, m_cSPS, m_cPPS, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true, m_layerId); |
|---|
| 1504 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++) |
|---|
| 1505 | { |
|---|
| 1506 | m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i); |
|---|
| 1507 | } |
|---|
| 1508 | } |
|---|
| 1509 | } |
|---|
| 1510 | |
|---|
| 1511 | if( m_cVPS.getNumRefLayers( m_layerId ) == 0 ) |
|---|
| 1512 | { |
|---|
| 1513 | UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId ); |
|---|
| 1514 | RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx)); |
|---|
| 1515 | |
|---|
| 1516 | if( m_cPPS.getLayerId() == 0 && |
|---|
| 1517 | m_cSPS.getLayerId() == 0 && |
|---|
| 1518 | repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() && |
|---|
| 1519 | repFmt->getSeparateColourPlaneVpsFlag() == 0 && |
|---|
| 1520 | repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() && |
|---|
| 1521 | repFmt->getPicWidthVpsInLumaSamples() == m_cSPS.getPicWidthInLumaSamples() && |
|---|
| 1522 | repFmt->getBitDepthVpsLuma() == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) && |
|---|
| 1523 | repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) && |
|---|
| 1524 | repFmt->getConformanceWindowVps().getWindowLeftOffset() == m_cSPS.getConformanceWindow().getWindowLeftOffset() && |
|---|
| 1525 | repFmt->getConformanceWindowVps().getWindowRightOffset() == m_cSPS.getConformanceWindow().getWindowRightOffset() && |
|---|
| 1526 | repFmt->getConformanceWindowVps().getWindowTopOffset() == m_cSPS.getConformanceWindow().getWindowTopOffset() && |
|---|
| 1527 | repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() ) |
|---|
| 1528 | { |
|---|
| 1529 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1); |
|---|
| 1530 | } |
|---|
| 1531 | else |
|---|
| 1532 | { |
|---|
| 1533 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0); |
|---|
| 1534 | } |
|---|
| 1535 | } |
|---|
| 1536 | } |
|---|
| 1537 | } |
|---|
| 1538 | |
|---|
| 1539 | Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId) |
|---|
| 1540 | { |
|---|
| 1541 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
|---|
| 1542 | { |
|---|
| 1543 | if (layerId == m_refLocationOffsetLayerId[i]) |
|---|
| 1544 | { |
|---|
| 1545 | return m_scaledRefLayerWindow[i]; |
|---|
| 1546 | } |
|---|
| 1547 | } |
|---|
| 1548 | |
|---|
| 1549 | return Window(); |
|---|
| 1550 | } |
|---|
| 1551 | |
|---|
| 1552 | Window TEncTop::getRefLayerWindowForLayer(Int layerId) |
|---|
| 1553 | { |
|---|
| 1554 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
|---|
| 1555 | { |
|---|
| 1556 | if (layerId == m_refLayerId[i]) |
|---|
| 1557 | { |
|---|
| 1558 | return m_refLayerWindow[i]; |
|---|
| 1559 | } |
|---|
| 1560 | } |
|---|
| 1561 | |
|---|
| 1562 | return Window(); |
|---|
| 1563 | } |
|---|
| 1564 | #endif //SVC_EXTENSION |
|---|
| 1565 | //! \} |
|---|