[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncTop.cpp |
---|
| 35 | \brief encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TLibCommon/CommonDef.h" |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncPic.h" |
---|
[1029] | 41 | #include "TLibCommon/TComChromaFormat.h" |
---|
[313] | 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 |
---|
[1029] | 67 | if (g_hTrace == NULL) |
---|
| 68 | { |
---|
| 69 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
| 70 | } |
---|
[313] | 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 | |
---|
[442] | 81 | #if SVC_EXTENSION |
---|
[1226] | 82 | memset( m_cIlpPic, 0, sizeof(m_cIlpPic) ); |
---|
[313] | 83 | m_bMFMEnabledFlag = false; |
---|
[1030] | 84 | m_numRefLayerLocationOffsets = 0; |
---|
[442] | 85 | m_pocAdjustmentValue = 0; |
---|
[540] | 86 | #if NO_CLRAS_OUTPUT_FLAG |
---|
| 87 | m_noClrasOutputFlag = false; |
---|
| 88 | m_layerInitializedFlag = false; |
---|
| 89 | m_firstPicInLayerDecodedFlag = false; |
---|
| 90 | m_noOutputOfPriorPicsFlags = false; |
---|
| 91 | #endif |
---|
[903] | 92 | m_pocDecrementedInDPBFlag = false; |
---|
[494] | 93 | #endif //SVC_EXTENSION |
---|
[313] | 94 | } |
---|
| 95 | |
---|
| 96 | TEncTop::~TEncTop() |
---|
| 97 | { |
---|
| 98 | #if ENC_DEC_TRACE |
---|
[1029] | 99 | if (g_hTrace != stdout) |
---|
| 100 | { |
---|
| 101 | fclose( g_hTrace ); |
---|
| 102 | } |
---|
[313] | 103 | #endif |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | Void TEncTop::create () |
---|
| 107 | { |
---|
| 108 | #if !SVC_EXTENSION |
---|
| 109 | // initialize global variables |
---|
| 110 | initROM(); |
---|
| 111 | #endif |
---|
[442] | 112 | |
---|
[313] | 113 | // create processing unit classes |
---|
| 114 | #if SVC_EXTENSION |
---|
| 115 | m_cGOPEncoder. create( m_layerId ); |
---|
| 116 | #else |
---|
[1029] | 117 | m_cGOPEncoder. create( ); |
---|
[313] | 118 | #endif |
---|
[1290] | 119 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth ); |
---|
| 120 | m_cCuEncoder. create( m_maxTotalCUDepth, m_maxCUWidth, m_maxCUHeight, m_chromaFormatIDC ); |
---|
[313] | 121 | if (m_bUseSAO) |
---|
| 122 | { |
---|
[1316] | 123 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA], m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
---|
[1029] | 124 | m_cEncSAO.createEncData(getSaoCtuBoundary()); |
---|
[313] | 125 | } |
---|
| 126 | #if ADAPTIVE_QP_SELECTION |
---|
| 127 | if (m_bUseAdaptQpSelect) |
---|
| 128 | { |
---|
| 129 | m_cTrQuant.initSliceQpDelta(); |
---|
| 130 | } |
---|
| 131 | #endif |
---|
[1029] | 132 | |
---|
[1290] | 133 | m_cLoopFilter.create( m_maxTotalCUDepth ); |
---|
[1029] | 134 | |
---|
[313] | 135 | if ( m_RCEnableRateControl ) |
---|
| 136 | { |
---|
| 137 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
[1289] | 138 | m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
[313] | 139 | } |
---|
[595] | 140 | |
---|
[1290] | 141 | m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1]; |
---|
[313] | 142 | #if FAST_BIT_EST |
---|
[1290] | 143 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1]; |
---|
[313] | 144 | #else |
---|
[1290] | 145 | m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1]; |
---|
[313] | 146 | #endif |
---|
[595] | 147 | |
---|
[1290] | 148 | for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
[595] | 149 | { |
---|
| 150 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
[313] | 151 | #if FAST_BIT_EST |
---|
[595] | 152 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
[313] | 153 | #else |
---|
[595] | 154 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
[313] | 155 | #endif |
---|
[595] | 156 | |
---|
| 157 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
| 158 | { |
---|
| 159 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
[313] | 160 | #if FAST_BIT_EST |
---|
[595] | 161 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
[313] | 162 | #else |
---|
[595] | 163 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
[313] | 164 | #endif |
---|
[595] | 165 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
[313] | 166 | } |
---|
| 167 | } |
---|
[494] | 168 | |
---|
| 169 | #if LAYER_CTB |
---|
| 170 | memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) ); |
---|
| 171 | memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) ); |
---|
| 172 | memcpy(g_auiLayerRasterToPelX[m_layerId], g_auiRasterToPelX, sizeof( g_auiRasterToPelX ) ); |
---|
| 173 | memcpy(g_auiLayerRasterToPelY[m_layerId], g_auiRasterToPelY, sizeof( g_auiRasterToPelY ) ); |
---|
| 174 | #endif |
---|
[313] | 175 | } |
---|
| 176 | |
---|
| 177 | Void TEncTop::destroy () |
---|
| 178 | { |
---|
| 179 | // destroy processing unit classes |
---|
| 180 | m_cGOPEncoder. destroy(); |
---|
| 181 | m_cSliceEncoder. destroy(); |
---|
| 182 | m_cCuEncoder. destroy(); |
---|
[1235] | 183 | m_cEncSAO. destroyEncData(); |
---|
| 184 | m_cEncSAO. destroy(); |
---|
[313] | 185 | m_cLoopFilter. destroy(); |
---|
| 186 | m_cRateCtrl. destroy(); |
---|
[1372] | 187 | m_cSearch. destroy(); |
---|
[595] | 188 | Int iDepth; |
---|
[1290] | 189 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
[313] | 190 | { |
---|
[595] | 191 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
| 192 | { |
---|
| 193 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
| 194 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
[1290] | 198 | for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ ) |
---|
[595] | 199 | { |
---|
| 200 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
| 201 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | delete [] m_pppcRDSbacCoder; |
---|
| 205 | delete [] m_pppcBinCoderCABAC; |
---|
[1459] | 206 | |
---|
[442] | 207 | #if SVC_EXTENSION |
---|
[313] | 208 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
| 209 | { |
---|
| 210 | if(m_cIlpPic[i]) |
---|
| 211 | { |
---|
| 212 | m_cIlpPic[i]->destroy(); |
---|
| 213 | delete m_cIlpPic[i]; |
---|
| 214 | m_cIlpPic[i] = NULL; |
---|
| 215 | } |
---|
[442] | 216 | } |
---|
| 217 | #else |
---|
| 218 | // destroy ROM |
---|
| 219 | destroyROM(); |
---|
[313] | 220 | #endif |
---|
| 221 | return; |
---|
| 222 | } |
---|
| 223 | |
---|
[442] | 224 | Void TEncTop::init(Bool isFieldCoding) |
---|
[313] | 225 | { |
---|
| 226 | // initialize SPS |
---|
| 227 | xInitSPS(); |
---|
[1235] | 228 | xInitVPS(); |
---|
[1029] | 229 | |
---|
[1433] | 230 | #if U0132_TARGET_BITS_SATURATION |
---|
| 231 | if (m_RCCpbSaturationEnabled) |
---|
| 232 | { |
---|
| 233 | m_cRateCtrl.initHrdParam(m_cSPS.getVuiParameters()->getHrdParameters(), m_iFrameRate, m_RCInitialCpbFullness); |
---|
| 234 | } |
---|
| 235 | #endif |
---|
[1029] | 236 | m_cRdCost.setCostMode(m_costMode); |
---|
| 237 | |
---|
[313] | 238 | // initialize PPS |
---|
| 239 | xInitPPS(); |
---|
[442] | 240 | xInitRPS(isFieldCoding); |
---|
[313] | 241 | |
---|
| 242 | xInitPPSforTiles(); |
---|
| 243 | |
---|
| 244 | // initialize processing unit classes |
---|
| 245 | m_cGOPEncoder. init( this ); |
---|
| 246 | m_cSliceEncoder.init( this ); |
---|
| 247 | m_cCuEncoder. init( this ); |
---|
[1029] | 248 | |
---|
[313] | 249 | // initialize transform & quantization class |
---|
| 250 | m_pcCavlcCoder = getCavlcCoder(); |
---|
[1029] | 251 | |
---|
[313] | 252 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
[1029] | 253 | m_useRDOQ, |
---|
| 254 | m_useRDOQTS, |
---|
[1298] | 255 | #if T0196_SELECTIVE_RDOQ |
---|
| 256 | m_useSelectiveRDOQ, |
---|
| 257 | #endif |
---|
[1029] | 258 | true |
---|
[313] | 259 | ,m_useTransformSkipFast |
---|
[1029] | 260 | #if ADAPTIVE_QP_SELECTION |
---|
| 261 | ,m_bUseAdaptQpSelect |
---|
[313] | 262 | #endif |
---|
| 263 | ); |
---|
[1029] | 264 | |
---|
[313] | 265 | // initialize encoder search class |
---|
[1406] | 266 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_motionEstimationSearchMethod, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
[313] | 267 | |
---|
| 268 | m_iMaxRefPicNum = 0; |
---|
[1235] | 269 | |
---|
| 270 | xInitScalingLists(); |
---|
| 271 | |
---|
[313] | 272 | #if SVC_EXTENSION |
---|
| 273 | m_iSPSIdCnt ++; |
---|
| 274 | m_iPPSIdCnt ++; |
---|
| 275 | xInitILRP(); |
---|
| 276 | #endif |
---|
| 277 | } |
---|
| 278 | |
---|
[1235] | 279 | Void TEncTop::xInitScalingLists() |
---|
| 280 | { |
---|
| 281 | // Initialise scaling lists |
---|
| 282 | // The encoder will only use the SPS scaling lists. The PPS will never be marked present. |
---|
[1285] | 283 | const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] = |
---|
| 284 | { |
---|
| 285 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA), |
---|
| 286 | m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA) |
---|
| 287 | }; |
---|
[1235] | 288 | if(getUseScalingListId() == SCALING_LIST_OFF) |
---|
| 289 | { |
---|
[1307] | 290 | getTrQuant()->setFlatScalingList(maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
[1235] | 291 | getTrQuant()->setUseScalingList(false); |
---|
| 292 | m_cSPS.setScalingListPresentFlag(false); |
---|
| 293 | m_cPPS.setScalingListPresentFlag(false); |
---|
| 294 | } |
---|
| 295 | else if(getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
| 296 | { |
---|
| 297 | #if SVC_EXTENSION |
---|
| 298 | // inferring of the scaling list can be moved to the config file |
---|
| 299 | UInt refLayerId = 0; |
---|
| 300 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
| 301 | { |
---|
| 302 | m_cSPS.setInferScalingListFlag( true ); |
---|
| 303 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
---|
| 304 | m_cSPS.setScalingListPresentFlag( false ); |
---|
| 305 | m_cPPS.setInferScalingListFlag( false ); |
---|
| 306 | m_cPPS.setScalingListPresentFlag( false ); |
---|
| 307 | |
---|
| 308 | // infer the scaling list from the reference layer |
---|
[1502] | 309 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getBitDepths() ); |
---|
[1235] | 310 | } |
---|
| 311 | else |
---|
| 312 | { |
---|
| 313 | #endif |
---|
| 314 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
| 315 | m_cSPS.setScalingListPresentFlag(false); |
---|
| 316 | m_cPPS.setScalingListPresentFlag(false); |
---|
[1285] | 317 | |
---|
[1307] | 318 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
| 319 | #if SVC_EXTENSION |
---|
[1235] | 320 | } |
---|
| 321 | #endif |
---|
| 322 | getTrQuant()->setUseScalingList(true); |
---|
| 323 | } |
---|
| 324 | else if(getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
| 325 | { |
---|
| 326 | #if SVC_EXTENSION |
---|
| 327 | // inferring of the scaling list can be moved to the config file |
---|
| 328 | UInt refLayerId = 0; |
---|
| 329 | if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) ) |
---|
| 330 | { |
---|
| 331 | m_cSPS.setInferScalingListFlag( true ); |
---|
| 332 | m_cSPS.setScalingListRefLayerId( refLayerId ); |
---|
| 333 | m_cSPS.setScalingListPresentFlag( false ); |
---|
| 334 | m_cPPS.setInferScalingListFlag( false ); |
---|
| 335 | m_cPPS.setScalingListPresentFlag( false ); |
---|
| 336 | |
---|
| 337 | // infer the scaling list from the reference layer |
---|
[1502] | 338 | getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getBitDepths() ); |
---|
[1235] | 339 | } |
---|
| 340 | else |
---|
| 341 | { |
---|
| 342 | #endif |
---|
| 343 | m_cSPS.getScalingList().setDefaultScalingList (); |
---|
[1442] | 344 | if(m_cSPS.getScalingList().xParseScalingList(getScalingListFileName())) |
---|
[1235] | 345 | { |
---|
| 346 | Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string |
---|
| 347 | assert(bParsedScalingList); |
---|
| 348 | exit(1); |
---|
| 349 | } |
---|
| 350 | m_cSPS.getScalingList().checkDcOfMatrix(); |
---|
| 351 | m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList()); |
---|
| 352 | m_cPPS.setScalingListPresentFlag(false); |
---|
[1307] | 353 | getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths()); |
---|
[1235] | 354 | #if SVC_EXTENSION |
---|
| 355 | } |
---|
| 356 | #endif |
---|
| 357 | getTrQuant()->setUseScalingList(true); |
---|
| 358 | } |
---|
| 359 | else |
---|
| 360 | { |
---|
| 361 | printf("error : ScalingList == %d not supported\n",getUseScalingListId()); |
---|
| 362 | assert(0); |
---|
| 363 | } |
---|
| 364 | |
---|
[1309] | 365 | if (getUseScalingListId() != SCALING_LIST_OFF) |
---|
[1235] | 366 | { |
---|
[1309] | 367 | // Prepare delta's: |
---|
| 368 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
| 369 | { |
---|
| 370 | const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries. |
---|
[1235] | 371 | |
---|
[1309] | 372 | for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep) |
---|
| 373 | { |
---|
| 374 | m_cSPS.getScalingList().checkPredMode( sizeId, listId ); |
---|
| 375 | } |
---|
[1235] | 376 | } |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | |
---|
[313] | 380 | // ==================================================================================================================== |
---|
| 381 | // Public member functions |
---|
| 382 | // ==================================================================================================================== |
---|
| 383 | |
---|
| 384 | Void TEncTop::deletePicBuffer() |
---|
| 385 | { |
---|
| 386 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 387 | Int iSize = Int( m_cListPic.size() ); |
---|
[1029] | 388 | |
---|
[313] | 389 | for ( Int i = 0; i < iSize; i++ ) |
---|
| 390 | { |
---|
| 391 | TComPic* pcPic = *(iterPic++); |
---|
[1029] | 392 | |
---|
[313] | 393 | pcPic->destroy(); |
---|
| 394 | delete pcPic; |
---|
| 395 | pcPic = NULL; |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | /** |
---|
| 400 | - Application has picture buffer list with size of GOP + 1 |
---|
| 401 | - Picture buffer list acts like as ring buffer |
---|
| 402 | - End of the list has the latest picture |
---|
| 403 | . |
---|
| 404 | \param flush cause encoder to encode a partial GOP |
---|
| 405 | \param pcPicYuvOrg original YUV picture |
---|
[1260] | 406 | \param pcPicYuvTrueOrg |
---|
| 407 | \param snrCSC |
---|
[313] | 408 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
[1260] | 409 | \retval accessUnitsOut list of output access units |
---|
[313] | 410 | \retval iNumEncoded number of encoded pictures |
---|
| 411 | */ |
---|
| 412 | #if SVC_EXTENSION |
---|
[1029] | 413 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
[313] | 414 | { |
---|
| 415 | // compress GOP |
---|
| 416 | #if !RC_SHVC_HARMONIZATION |
---|
| 417 | if ( m_RCEnableRateControl ) |
---|
| 418 | { |
---|
| 419 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
| 420 | } |
---|
| 421 | #endif |
---|
| 422 | |
---|
| 423 | // compress GOP |
---|
[1029] | 424 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
[313] | 425 | |
---|
| 426 | #if !RC_SHVC_HARMONIZATION |
---|
| 427 | if ( m_RCEnableRateControl ) |
---|
| 428 | { |
---|
| 429 | m_cRateCtrl.destroyRCGOP(); |
---|
| 430 | } |
---|
| 431 | #endif |
---|
| 432 | |
---|
| 433 | m_uiNumAllPicCoded ++; |
---|
| 434 | } |
---|
| 435 | |
---|
[1029] | 436 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg ) |
---|
[313] | 437 | { |
---|
[1029] | 438 | if (pcPicYuvOrg != NULL) |
---|
[313] | 439 | { |
---|
| 440 | // get original YUV |
---|
| 441 | TComPic* pcPicCurr = NULL; |
---|
| 442 | xGetNewPicBuffer( pcPicCurr ); |
---|
| 443 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
[1029] | 444 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
[313] | 445 | |
---|
| 446 | // compute image characteristics |
---|
| 447 | if ( getUseAdaptiveQP() ) |
---|
| 448 | { |
---|
| 449 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | #else |
---|
[1029] | 454 | Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
[313] | 455 | { |
---|
[1029] | 456 | if (pcPicYuvOrg != NULL) |
---|
| 457 | { |
---|
[313] | 458 | // get original YUV |
---|
| 459 | TComPic* pcPicCurr = NULL; |
---|
[1029] | 460 | |
---|
[313] | 461 | xGetNewPicBuffer( pcPicCurr ); |
---|
| 462 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
[1029] | 463 | pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() ); |
---|
[313] | 464 | |
---|
| 465 | // compute image characteristics |
---|
| 466 | if ( getUseAdaptiveQP() ) |
---|
| 467 | { |
---|
| 468 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
| 469 | } |
---|
| 470 | } |
---|
[1029] | 471 | |
---|
| 472 | if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0))) |
---|
[313] | 473 | { |
---|
| 474 | iNumEncoded = 0; |
---|
| 475 | return; |
---|
| 476 | } |
---|
[1029] | 477 | |
---|
[313] | 478 | if ( m_RCEnableRateControl ) |
---|
| 479 | { |
---|
| 480 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | // compress GOP |
---|
[1029] | 484 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE); |
---|
[313] | 485 | |
---|
| 486 | if ( m_RCEnableRateControl ) |
---|
| 487 | { |
---|
| 488 | m_cRateCtrl.destroyRCGOP(); |
---|
| 489 | } |
---|
[1029] | 490 | |
---|
[313] | 491 | iNumEncoded = m_iNumPicRcvd; |
---|
| 492 | m_iNumPicRcvd = 0; |
---|
| 493 | m_uiNumAllPicCoded += iNumEncoded; |
---|
| 494 | } |
---|
| 495 | #endif |
---|
| 496 | |
---|
[442] | 497 | /**------------------------------------------------ |
---|
| 498 | Separate interlaced frame into two fields |
---|
| 499 | -------------------------------------------------**/ |
---|
[1029] | 500 | Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
---|
[442] | 501 | { |
---|
| 502 | if (!isTop) |
---|
| 503 | { |
---|
| 504 | org += stride; |
---|
| 505 | } |
---|
| 506 | for (Int y = 0; y < height>>1; y++) |
---|
| 507 | { |
---|
| 508 | for (Int x = 0; x < width; x++) |
---|
| 509 | { |
---|
| 510 | dstField[x] = org[x]; |
---|
| 511 | } |
---|
[1029] | 512 | |
---|
[442] | 513 | dstField += stride; |
---|
| 514 | org += stride*2; |
---|
| 515 | } |
---|
[1029] | 516 | |
---|
[442] | 517 | } |
---|
| 518 | |
---|
| 519 | #if SVC_EXTENSION |
---|
[1029] | 520 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff ) |
---|
[442] | 521 | { |
---|
[1029] | 522 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
[442] | 523 | { |
---|
[1029] | 524 | if (pcPicYuvOrg) |
---|
[442] | 525 | { |
---|
[1029] | 526 | /* -- field initialization -- */ |
---|
| 527 | const Bool isTopField=isTff==(fieldNum==0); |
---|
[540] | 528 | |
---|
[1029] | 529 | TComPic *pcField; |
---|
| 530 | xGetNewPicBuffer( pcField ); |
---|
| 531 | pcField->setReconMark (false); // where is this normally? |
---|
| 532 | |
---|
| 533 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
| 534 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
[442] | 535 | |
---|
[1029] | 536 | pcField->setTopField(isTopField); // interlaced requirement |
---|
[540] | 537 | |
---|
[1029] | 538 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
| 539 | { |
---|
| 540 | const ComponentID component = ComponentID(componentIndex); |
---|
| 541 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
[540] | 542 | |
---|
[1029] | 543 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
| 544 | pcField->getPicYuvOrg()->getAddr(component), |
---|
| 545 | pcPicYuvOrg->getStride(component), |
---|
| 546 | pcPicYuvOrg->getWidth(component), |
---|
| 547 | pcPicYuvOrg->getHeight(component), |
---|
| 548 | isTopField); |
---|
| 549 | |
---|
| 550 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
| 551 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
| 552 | pcPicYuvTrueOrg->getStride(component), |
---|
| 553 | pcPicYuvTrueOrg->getWidth(component), |
---|
| 554 | pcPicYuvTrueOrg->getHeight(component), |
---|
| 555 | isTopField); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | // compute image characteristics |
---|
| 559 | if ( getUseAdaptiveQP() ) |
---|
| 560 | { |
---|
| 561 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
| 562 | } |
---|
| 563 | } |
---|
[442] | 564 | } |
---|
| 565 | } |
---|
| 566 | |
---|
[1029] | 567 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ) |
---|
[442] | 568 | { |
---|
[1029] | 569 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
[442] | 570 | { |
---|
[1029] | 571 | if (pcPicYuvOrg) |
---|
| 572 | { |
---|
| 573 | if (fieldNum==1) // where is this normally? |
---|
| 574 | { |
---|
| 575 | TComPicYuv* rpcPicYuvRec; |
---|
[442] | 576 | |
---|
[1029] | 577 | // org. buffer |
---|
| 578 | 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. |
---|
| 579 | { |
---|
| 580 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
| 581 | } |
---|
| 582 | else |
---|
| 583 | { |
---|
| 584 | rpcPicYuvRec = new TComPicYuv; |
---|
[1290] | 585 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true); |
---|
[1029] | 586 | } |
---|
| 587 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
| 588 | } |
---|
[442] | 589 | } |
---|
[1029] | 590 | |
---|
| 591 | // compress GOP |
---|
| 592 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
[442] | 593 | } |
---|
| 594 | |
---|
| 595 | m_uiNumAllPicCoded ++; |
---|
| 596 | } |
---|
| 597 | #else |
---|
[1029] | 598 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
---|
[442] | 599 | { |
---|
[1029] | 600 | iNumEncoded = 0; |
---|
| 601 | |
---|
| 602 | for (Int fieldNum=0; fieldNum<2; fieldNum++) |
---|
[442] | 603 | { |
---|
[1029] | 604 | if (pcPicYuvOrg) |
---|
[442] | 605 | { |
---|
[1029] | 606 | |
---|
| 607 | /* -- field initialization -- */ |
---|
| 608 | const Bool isTopField=isTff==(fieldNum==0); |
---|
| 609 | |
---|
| 610 | TComPic *pcField; |
---|
| 611 | xGetNewPicBuffer( pcField ); |
---|
| 612 | pcField->setReconMark (false); // where is this normally? |
---|
| 613 | |
---|
| 614 | if (fieldNum==1) // where is this normally? |
---|
| 615 | { |
---|
| 616 | TComPicYuv* rpcPicYuvRec; |
---|
| 617 | |
---|
| 618 | // org. buffer |
---|
| 619 | 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. |
---|
| 620 | { |
---|
| 621 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
| 622 | } |
---|
| 623 | else |
---|
| 624 | { |
---|
| 625 | rpcPicYuvRec = new TComPicYuv; |
---|
[1290] | 626 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true); |
---|
[1029] | 627 | } |
---|
| 628 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous? |
---|
| 632 | pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally? |
---|
| 633 | |
---|
| 634 | pcField->setTopField(isTopField); // interlaced requirement |
---|
| 635 | |
---|
| 636 | for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++) |
---|
| 637 | { |
---|
| 638 | const ComponentID component = ComponentID(componentIndex); |
---|
| 639 | const UInt stride = pcPicYuvOrg->getStride(component); |
---|
| 640 | |
---|
| 641 | separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)), |
---|
| 642 | pcField->getPicYuvOrg()->getAddr(component), |
---|
| 643 | pcPicYuvOrg->getStride(component), |
---|
| 644 | pcPicYuvOrg->getWidth(component), |
---|
| 645 | pcPicYuvOrg->getHeight(component), |
---|
| 646 | isTopField); |
---|
| 647 | |
---|
| 648 | separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)), |
---|
| 649 | pcField->getPicYuvTrueOrg()->getAddr(component), |
---|
| 650 | pcPicYuvTrueOrg->getStride(component), |
---|
| 651 | pcPicYuvTrueOrg->getWidth(component), |
---|
| 652 | pcPicYuvTrueOrg->getHeight(component), |
---|
| 653 | isTopField); |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | // compute image characteristics |
---|
| 657 | if ( getUseAdaptiveQP() ) |
---|
| 658 | { |
---|
| 659 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) ); |
---|
| 660 | } |
---|
[442] | 661 | } |
---|
[1029] | 662 | |
---|
| 663 | if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) |
---|
[442] | 664 | { |
---|
[1029] | 665 | // compress GOP |
---|
| 666 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE); |
---|
| 667 | |
---|
| 668 | iNumEncoded += m_iNumPicRcvd; |
---|
| 669 | m_uiNumAllPicCoded += m_iNumPicRcvd; |
---|
| 670 | m_iNumPicRcvd = 0; |
---|
[442] | 671 | } |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | #endif |
---|
| 675 | |
---|
[313] | 676 | // ==================================================================================================================== |
---|
| 677 | // Protected member functions |
---|
| 678 | // ==================================================================================================================== |
---|
| 679 | |
---|
| 680 | /** |
---|
| 681 | - Application has picture buffer list with size of GOP + 1 |
---|
| 682 | - Picture buffer list acts like as ring buffer |
---|
| 683 | - End of the list has the latest picture |
---|
| 684 | . |
---|
| 685 | \retval rpcPic obtained picture buffer |
---|
| 686 | */ |
---|
| 687 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
| 688 | { |
---|
[1235] | 689 | // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic. |
---|
| 690 | |
---|
[313] | 691 | TComSlice::sortPicList(m_cListPic); |
---|
[1029] | 692 | |
---|
[1249] | 693 | |
---|
[313] | 694 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
| 695 | { |
---|
| 696 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 697 | Int iSize = Int( m_cListPic.size() ); |
---|
| 698 | for ( Int i = 0; i < iSize; i++ ) |
---|
| 699 | { |
---|
| 700 | rpcPic = *(iterPic++); |
---|
| 701 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
| 702 | { |
---|
| 703 | break; |
---|
| 704 | } |
---|
| 705 | } |
---|
| 706 | } |
---|
| 707 | else |
---|
| 708 | { |
---|
| 709 | if ( getUseAdaptiveQP() ) |
---|
| 710 | { |
---|
| 711 | TEncPic* pcEPic = new TEncPic; |
---|
| 712 | |
---|
| 713 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
[1200] | 714 | if( m_layerId > 0 ) |
---|
[313] | 715 | { |
---|
[1200] | 716 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
[313] | 717 | { |
---|
[1235] | 718 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
| 719 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
[873] | 720 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
[1235] | 721 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
[313] | 722 | |
---|
| 723 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
[1200] | 724 | |
---|
[1502] | 725 | const Int bitDepthLuma = m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA); |
---|
| 726 | const Int bitDepthChroma = m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA); |
---|
| 727 | const Int refBitDepthLuma = pcEncTopBase->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA); |
---|
| 728 | const Int refBitDepthChroma = pcEncTopBase->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA); |
---|
[644] | 729 | |
---|
[1287] | 730 | Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma ); |
---|
| 731 | |
---|
[901] | 732 | if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase ) |
---|
| 733 | { |
---|
| 734 | pcEPic->setEqualPictureSizeAndOffsetFlag( i, true ); |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths |
---|
[1212] | 738 | #if CGS_3D_ASYMLUT |
---|
[713] | 739 | || m_cPPS.getCGSFlag() > 0 |
---|
| 740 | #endif |
---|
| 741 | ) |
---|
[313] | 742 | { |
---|
| 743 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
---|
| 744 | |
---|
| 745 | //only for scalable extension |
---|
[815] | 746 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
[313] | 747 | } |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | |
---|
[1290] | 751 | pcEPic->create( m_cVPS, m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId); |
---|
[815] | 752 | #else //SVC_EXTENSION |
---|
[1290] | 753 | pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false); |
---|
[815] | 754 | #endif //SVC_EXTENSION |
---|
[313] | 755 | rpcPic = pcEPic; |
---|
| 756 | } |
---|
| 757 | else |
---|
| 758 | { |
---|
| 759 | rpcPic = new TComPic; |
---|
| 760 | |
---|
| 761 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
[1200] | 762 | if( m_layerId > 0 ) |
---|
[313] | 763 | { |
---|
[1200] | 764 | for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
[313] | 765 | { |
---|
[1235] | 766 | const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
| 767 | const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
[873] | 768 | Bool equalOffsets = scalEL.hasEqualOffset(altRL); |
---|
[1235] | 769 | Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
[313] | 770 | |
---|
| 771 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
[1200] | 772 | |
---|
[1502] | 773 | const Int bitDepthLuma = m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA); |
---|
| 774 | const Int bitDepthChroma = m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA); |
---|
| 775 | const Int refBitDepthLuma = m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA); |
---|
| 776 | const Int refBitDepthChroma = m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA); |
---|
[644] | 777 | |
---|
[1287] | 778 | Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma ); |
---|
| 779 | |
---|
[873] | 780 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths |
---|
| 781 | || !equalOffsets |
---|
| 782 | || !zeroPhase |
---|
[1212] | 783 | #if CGS_3D_ASYMLUT |
---|
[713] | 784 | || m_cPPS.getCGSFlag() > 0 |
---|
| 785 | #endif |
---|
[1200] | 786 | ) |
---|
[313] | 787 | { |
---|
| 788 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
---|
| 789 | |
---|
| 790 | //only for scalable extension |
---|
[815] | 791 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
[313] | 792 | } |
---|
| 793 | } |
---|
| 794 | } |
---|
| 795 | |
---|
[1503] | 796 | rpcPic->create( m_cSPS, m_cPPS, false, m_layerId ); |
---|
[815] | 797 | #else //SVC_EXTENSION |
---|
[1290] | 798 | rpcPic->create( m_cSPS, m_cPPS, false ); |
---|
[815] | 799 | #endif //SVC_EXTENSION |
---|
[313] | 800 | } |
---|
[1029] | 801 | |
---|
[313] | 802 | m_cListPic.pushBack( rpcPic ); |
---|
| 803 | } |
---|
| 804 | rpcPic->setReconMark (false); |
---|
[1029] | 805 | |
---|
[313] | 806 | m_iPOCLast++; |
---|
| 807 | m_iNumPicRcvd++; |
---|
[1029] | 808 | |
---|
[313] | 809 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
| 810 | // mark it should be extended |
---|
| 811 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
| 812 | } |
---|
| 813 | |
---|
[1235] | 814 | Void TEncTop::xInitVPS() |
---|
| 815 | { |
---|
| 816 | // The SPS must have already been set up. |
---|
| 817 | // set the VPS profile information. |
---|
| 818 | #if SVC_EXTENSION |
---|
| 819 | m_cVPS.setVpsVuiPresentFlag( true ); |
---|
| 820 | #else |
---|
| 821 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
| 822 | m_cVPS.setMaxOpSets(1); |
---|
| 823 | #endif |
---|
| 824 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
| 825 | m_cVPS.setNumHrdParameters( 0 ); |
---|
| 826 | |
---|
| 827 | m_cVPS.createHrdParamBuffer(); |
---|
| 828 | for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ ) |
---|
| 829 | { |
---|
| 830 | m_cVPS.setHrdOpSetIdx( 0, i ); |
---|
| 831 | m_cVPS.setCprmsPresentFlag( false, i ); |
---|
| 832 | // Set up HrdParameters here. |
---|
| 833 | } |
---|
| 834 | } |
---|
| 835 | |
---|
[313] | 836 | Void TEncTop::xInitSPS() |
---|
| 837 | { |
---|
| 838 | #if SVC_EXTENSION |
---|
[815] | 839 | m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false ); |
---|
[988] | 840 | m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers); |
---|
[1172] | 841 | |
---|
[830] | 842 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
[815] | 843 | { |
---|
| 844 | m_cSPS.setLayerId(0); // layer ID 0 for independent layers |
---|
| 845 | } |
---|
| 846 | else |
---|
| 847 | { |
---|
| 848 | m_cSPS.setLayerId(m_layerId); |
---|
| 849 | } |
---|
[494] | 850 | #endif //SVC_EXTENSION |
---|
[1172] | 851 | |
---|
[313] | 852 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
| 853 | profileTierLevel.setLevelIdc(m_level); |
---|
| 854 | profileTierLevel.setTierFlag(m_levelTier); |
---|
| 855 | profileTierLevel.setProfileIdc(m_profile); |
---|
| 856 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
| 857 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
| 858 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
| 859 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
| 860 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
[1029] | 861 | profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue); |
---|
| 862 | profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue); |
---|
| 863 | profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag); |
---|
[1356] | 864 | profileTierLevel.setOnePictureOnlyConstraintFlag(m_onePictureOnlyConstraintFlag); |
---|
[1029] | 865 | profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag); |
---|
| 866 | |
---|
[1287] | 867 | if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8)) |
---|
[313] | 868 | { |
---|
| 869 | /* The above constraint is equal to Profile::MAIN */ |
---|
| 870 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
| 871 | } |
---|
| 872 | if (m_profile == Profile::MAIN) |
---|
| 873 | { |
---|
| 874 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
| 875 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
| 876 | } |
---|
| 877 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
| 878 | /* XXX: may be a good idea to refactor the above into a function |
---|
| 879 | * that chooses the actual compatibility based upon options */ |
---|
| 880 | |
---|
[1290] | 881 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
| 882 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
| 883 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
| 884 | m_cSPS.setMaxCUWidth ( m_maxCUWidth ); |
---|
| 885 | m_cSPS.setMaxCUHeight ( m_maxCUHeight ); |
---|
| 886 | m_cSPS.setMaxTotalCUDepth ( m_maxTotalCUDepth ); |
---|
[494] | 887 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
---|
[1290] | 888 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize); |
---|
[313] | 889 | |
---|
[1290] | 890 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() ); |
---|
[313] | 891 | Int log2MinCUSize = 0; |
---|
| 892 | while(minCUSize > 1) |
---|
| 893 | { |
---|
| 894 | minCUSize >>= 1; |
---|
| 895 | log2MinCUSize++; |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
[1459] | 899 | |
---|
[313] | 900 | #if SVC_EXTENSION |
---|
| 901 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
| 902 | #endif |
---|
[1459] | 903 | |
---|
[313] | 904 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
| 905 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
| 906 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
| 907 | |
---|
| 908 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
| 909 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
| 910 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
| 911 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
[1029] | 912 | |
---|
[1235] | 913 | m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1)); |
---|
| 914 | |
---|
[313] | 915 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
[1284] | 916 | |
---|
[313] | 917 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
| 918 | |
---|
[1029] | 919 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
| 920 | { |
---|
[1203] | 921 | #if SVC_EXTENSION |
---|
[1290] | 922 | m_cSPS.setBitDepth (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) ); |
---|
[1287] | 923 | #if O0043_BEST_EFFORT_DECODING |
---|
[1290] | 924 | m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] ); |
---|
[1287] | 925 | #endif |
---|
[1290] | 926 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8))); |
---|
[442] | 927 | #else |
---|
[1290] | 928 | m_cSPS.setBitDepth (ChannelType(channelType), m_bitDepth[channelType] ); |
---|
[1287] | 929 | #if O0043_BEST_EFFORT_DECODING |
---|
| 930 | m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] ); |
---|
[442] | 931 | #endif |
---|
[1287] | 932 | m_cSPS.setQpBDOffset (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8))); |
---|
| 933 | #endif |
---|
[1284] | 934 | m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType] ); |
---|
[1029] | 935 | } |
---|
[313] | 936 | |
---|
| 937 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
| 938 | |
---|
| 939 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
| 940 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
[1029] | 941 | |
---|
[1252] | 942 | for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
[313] | 943 | { |
---|
[1288] | 944 | #if SVC_EXTENSION |
---|
| 945 | assert( i < MAX_TLAYER ); |
---|
| 946 | #endif |
---|
[313] | 947 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
| 948 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
| 949 | } |
---|
[1029] | 950 | |
---|
[313] | 951 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
[1235] | 952 | m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 ); |
---|
[313] | 953 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
[1029] | 954 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
[313] | 955 | |
---|
| 956 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
| 957 | { |
---|
| 958 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
[823] | 959 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag()); |
---|
[313] | 960 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
| 961 | pcVUI->setSarWidth(getSarWidth()); |
---|
| 962 | pcVUI->setSarHeight(getSarHeight()); |
---|
| 963 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
| 964 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
| 965 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
| 966 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
| 967 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
| 968 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
| 969 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
| 970 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
| 971 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
| 972 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
| 973 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
| 974 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
| 975 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
| 976 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
| 977 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
| 978 | pcVUI->setFieldSeqFlag(false); |
---|
| 979 | pcVUI->setHrdParametersPresentFlag(false); |
---|
| 980 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
| 981 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
| 982 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
| 983 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
| 984 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
| 985 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
| 986 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
| 987 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
| 988 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
| 989 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
| 990 | } |
---|
[1235] | 991 | m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS); |
---|
| 992 | assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS); |
---|
| 993 | for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++) |
---|
| 994 | { |
---|
| 995 | m_cSPS.setLtRefPicPocLsbSps(k, 0); |
---|
| 996 | m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0); |
---|
| 997 | } |
---|
[1433] | 998 | |
---|
| 999 | #if U0132_TARGET_BITS_SATURATION |
---|
| 1000 | if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() || getCpbSaturationEnabled() ) |
---|
| 1001 | #else |
---|
[1235] | 1002 | if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
[1433] | 1003 | #endif |
---|
[1235] | 1004 | { |
---|
[1348] | 1005 | xInitHrdParameters(); |
---|
[1235] | 1006 | } |
---|
| 1007 | if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) |
---|
| 1008 | { |
---|
| 1009 | m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
| 1010 | } |
---|
[1316] | 1011 | |
---|
| 1012 | // Set up SPS range extension settings |
---|
| 1013 | m_cSPS.getSpsRangeExtension().setTransformSkipRotationEnabledFlag(m_transformSkipRotationEnabledFlag); |
---|
| 1014 | m_cSPS.getSpsRangeExtension().setTransformSkipContextEnabledFlag(m_transformSkipContextEnabledFlag); |
---|
| 1015 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
---|
| 1016 | { |
---|
| 1017 | m_cSPS.getSpsRangeExtension().setRdpcmEnabledFlag(RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
---|
| 1018 | } |
---|
| 1019 | m_cSPS.getSpsRangeExtension().setExtendedPrecisionProcessingFlag(m_extendedPrecisionProcessingFlag); |
---|
| 1020 | m_cSPS.getSpsRangeExtension().setIntraSmoothingDisabledFlag( m_intraSmoothingDisabledFlag ); |
---|
| 1021 | m_cSPS.getSpsRangeExtension().setHighPrecisionOffsetsEnabledFlag(m_highPrecisionOffsetsEnabledFlag); |
---|
| 1022 | m_cSPS.getSpsRangeExtension().setPersistentRiceAdaptationEnabledFlag(m_persistentRiceAdaptationEnabledFlag); |
---|
| 1023 | m_cSPS.getSpsRangeExtension().setCabacBypassAlignmentEnabledFlag(m_cabacBypassAlignmentEnabledFlag); |
---|
[1502] | 1024 | |
---|
| 1025 | #if SVC_EXTENSION |
---|
| 1026 | m_cSPS.inferSPS( m_layerId, &m_cVPS ); |
---|
| 1027 | #endif |
---|
[313] | 1028 | } |
---|
| 1029 | |
---|
[1433] | 1030 | #if U0132_TARGET_BITS_SATURATION |
---|
| 1031 | // calculate scale value of bitrate and initial delay |
---|
| 1032 | Int calcScale(Int x) |
---|
| 1033 | { |
---|
| 1034 | UInt iMask = 0xffffffff; |
---|
| 1035 | Int ScaleValue = 32; |
---|
| 1036 | |
---|
| 1037 | while ((x&iMask) != 0) |
---|
| 1038 | { |
---|
| 1039 | ScaleValue--; |
---|
| 1040 | iMask = (iMask >> 1); |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | return ScaleValue; |
---|
| 1044 | } |
---|
| 1045 | #endif |
---|
[1348] | 1046 | Void TEncTop::xInitHrdParameters() |
---|
| 1047 | { |
---|
| 1048 | Bool useSubCpbParams = (getSliceMode() > 0) || (getSliceSegmentMode() > 0); |
---|
| 1049 | Int bitRate = getTargetBitrate(); |
---|
| 1050 | Bool isRandomAccess = getIntraPeriod() > 0; |
---|
[1433] | 1051 | # if U0132_TARGET_BITS_SATURATION |
---|
| 1052 | Int cpbSize = getCpbSize(); |
---|
[1348] | 1053 | |
---|
[1433] | 1054 | if( !getVuiParametersPresentFlag() && !getCpbSaturationEnabled() ) |
---|
| 1055 | #else |
---|
[1348] | 1056 | if( !getVuiParametersPresentFlag() ) |
---|
[1433] | 1057 | #endif |
---|
[1348] | 1058 | { |
---|
| 1059 | return; |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | TComVUI *vui = m_cSPS.getVuiParameters(); |
---|
| 1063 | TComHRD *hrd = vui->getHrdParameters(); |
---|
| 1064 | |
---|
| 1065 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
| 1066 | |
---|
| 1067 | #if SVC_EXTENSION |
---|
| 1068 | if( m_layerId > 0 ) |
---|
| 1069 | { |
---|
| 1070 | timingInfo->setTimingInfoPresentFlag( false ); |
---|
| 1071 | return; |
---|
| 1072 | } |
---|
| 1073 | #endif |
---|
| 1074 | |
---|
| 1075 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
| 1076 | switch( getFrameRate() ) |
---|
| 1077 | { |
---|
| 1078 | case 24: |
---|
| 1079 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
| 1080 | break; |
---|
| 1081 | case 25: |
---|
| 1082 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
| 1083 | break; |
---|
| 1084 | case 30: |
---|
| 1085 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
| 1086 | break; |
---|
| 1087 | case 50: |
---|
| 1088 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
| 1089 | break; |
---|
| 1090 | case 60: |
---|
| 1091 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
| 1092 | break; |
---|
| 1093 | default: |
---|
| 1094 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
| 1095 | break; |
---|
| 1096 | } |
---|
| 1097 | |
---|
| 1098 | Bool rateCnt = ( bitRate > 0 ); |
---|
| 1099 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
| 1100 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
| 1101 | hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams ); |
---|
| 1102 | |
---|
| 1103 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 1104 | { |
---|
| 1105 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
| 1106 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
| 1107 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
| 1108 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
| 1109 | } |
---|
| 1110 | else |
---|
| 1111 | { |
---|
| 1112 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
| 1113 | } |
---|
| 1114 | |
---|
[1433] | 1115 | #if U0132_TARGET_BITS_SATURATION |
---|
| 1116 | if (calcScale(bitRate) <= 6) |
---|
| 1117 | { |
---|
| 1118 | hrd->setBitRateScale(0); |
---|
| 1119 | } |
---|
| 1120 | else |
---|
| 1121 | { |
---|
| 1122 | hrd->setBitRateScale(calcScale(bitRate) - 6); |
---|
| 1123 | } |
---|
| 1124 | |
---|
| 1125 | if (calcScale(cpbSize) <= 4) |
---|
| 1126 | { |
---|
| 1127 | hrd->setCpbSizeScale(0); |
---|
| 1128 | } |
---|
| 1129 | else |
---|
| 1130 | { |
---|
| 1131 | hrd->setCpbSizeScale(calcScale(cpbSize) - 4); |
---|
| 1132 | } |
---|
| 1133 | #else |
---|
[1349] | 1134 | hrd->setBitRateScale( 4 ); // in units of 2^( 6 + 4 ) = 1,024 bps |
---|
| 1135 | hrd->setCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
[1433] | 1136 | #endif |
---|
| 1137 | |
---|
[1349] | 1138 | hrd->setDuCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit |
---|
[1348] | 1139 | |
---|
| 1140 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
| 1141 | if( isRandomAccess ) |
---|
| 1142 | { |
---|
| 1143 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
| 1144 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
| 1145 | } |
---|
| 1146 | else |
---|
| 1147 | { |
---|
| 1148 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
| 1149 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | // Note: parameters for all temporal layers are initialized with the same values |
---|
| 1153 | Int i, j; |
---|
| 1154 | UInt bitrateValue, cpbSizeValue; |
---|
| 1155 | UInt duCpbSizeValue; |
---|
| 1156 | UInt duBitRateValue = 0; |
---|
| 1157 | |
---|
| 1158 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
| 1159 | { |
---|
| 1160 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
| 1161 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
| 1162 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
| 1163 | hrd->setCpbCntMinus1( i, 0 ); |
---|
| 1164 | |
---|
[1349] | 1165 | //! \todo check for possible PTL violations |
---|
| 1166 | // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale ) |
---|
| 1167 | bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) ); // bitRate is in bits, so it needs to be scaled down |
---|
| 1168 | // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale ) |
---|
[1433] | 1169 | #if U0132_TARGET_BITS_SATURATION |
---|
| 1170 | cpbSizeValue = cpbSize / (1 << (4 + hrd->getCpbSizeScale()) ); // using bitRate results in 1 second CPB size |
---|
| 1171 | #else |
---|
[1349] | 1172 | cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) ); // using bitRate results in 1 second CPB size |
---|
[1433] | 1173 | #endif |
---|
[1349] | 1174 | |
---|
[1433] | 1175 | |
---|
[1349] | 1176 | // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know |
---|
[1348] | 1177 | // in how many DUs the slice segment settings will result |
---|
[1349] | 1178 | duCpbSizeValue = bitrateValue; |
---|
| 1179 | duBitRateValue = cpbSizeValue; |
---|
[1348] | 1180 | |
---|
| 1181 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
| 1182 | { |
---|
| 1183 | hrd->setBitRateValueMinus1( i, j, 0, ( bitrateValue - 1 ) ); |
---|
| 1184 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
| 1185 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) ); |
---|
[1360] | 1186 | hrd->setDuBitRateValueMinus1( i, j, 0, ( duBitRateValue - 1 ) ); |
---|
[1350] | 1187 | hrd->setCbrFlag( i, j, 0, false ); |
---|
[1348] | 1188 | |
---|
| 1189 | hrd->setBitRateValueMinus1( i, j, 1, ( bitrateValue - 1) ); |
---|
| 1190 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
| 1191 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( duCpbSizeValue - 1 ) ); |
---|
| 1192 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
[1350] | 1193 | hrd->setCbrFlag( i, j, 1, false ); |
---|
[1348] | 1194 | } |
---|
| 1195 | } |
---|
| 1196 | } |
---|
| 1197 | |
---|
[313] | 1198 | Void TEncTop::xInitPPS() |
---|
| 1199 | { |
---|
| 1200 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
| 1201 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
| 1202 | |
---|
[595] | 1203 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
[540] | 1204 | { |
---|
[595] | 1205 | bUseDQP = true; |
---|
[540] | 1206 | } |
---|
[313] | 1207 | |
---|
[1235] | 1208 | if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING) |
---|
| 1209 | { |
---|
| 1210 | bUseDQP=false; |
---|
| 1211 | } |
---|
[1029] | 1212 | |
---|
[1235] | 1213 | |
---|
| 1214 | if ( m_RCEnableRateControl ) |
---|
[313] | 1215 | { |
---|
| 1216 | m_cPPS.setUseDQP(true); |
---|
[1235] | 1217 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
| 1218 | } |
---|
| 1219 | else if(bUseDQP) |
---|
| 1220 | { |
---|
| 1221 | m_cPPS.setUseDQP(true); |
---|
[313] | 1222 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
| 1223 | } |
---|
| 1224 | else |
---|
| 1225 | { |
---|
| 1226 | m_cPPS.setUseDQP(false); |
---|
| 1227 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
| 1228 | } |
---|
| 1229 | |
---|
[1316] | 1230 | if ( m_diffCuChromaQpOffsetDepth >= 0 ) |
---|
[1029] | 1231 | { |
---|
[1316] | 1232 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(m_diffCuChromaQpOffsetDepth); |
---|
| 1233 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
| 1234 | m_cPPS.getPpsRangeExtension().setChromaQpOffsetListEntry(1, 6, 6); |
---|
[1029] | 1235 | /* todo, insert table entries from command line (NB, 0 should not be touched) */ |
---|
| 1236 | } |
---|
| 1237 | else |
---|
| 1238 | { |
---|
[1316] | 1239 | m_cPPS.getPpsRangeExtension().setDiffCuChromaQpOffsetDepth(0); |
---|
| 1240 | m_cPPS.getPpsRangeExtension().clearChromaQpOffsetList(); |
---|
[1029] | 1241 | } |
---|
[1316] | 1242 | m_cPPS.getPpsRangeExtension().setCrossComponentPredictionEnabledFlag(m_crossComponentPredictionEnabledFlag); |
---|
| 1243 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_LUMA, m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA ]); |
---|
| 1244 | m_cPPS.getPpsRangeExtension().setLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA]); |
---|
[1029] | 1245 | |
---|
| 1246 | m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset ); |
---|
| 1247 | m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset ); |
---|
| 1248 | |
---|
[1459] | 1249 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_entropyCodingSyncEnabledFlag ); |
---|
[313] | 1250 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
| 1251 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
| 1252 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
| 1253 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
| 1254 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
[1322] | 1255 | |
---|
[313] | 1256 | if ( getDeblockingFilterMetric() ) |
---|
| 1257 | { |
---|
| 1258 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
| 1259 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
[1029] | 1260 | } |
---|
[313] | 1261 | else |
---|
| 1262 | { |
---|
[1322] | 1263 | m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() ); |
---|
| 1264 | m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() ); |
---|
[313] | 1265 | } |
---|
[1235] | 1266 | |
---|
[1322] | 1267 | if (! m_cPPS.getPicDisableDeblockingFilterFlag()) |
---|
[1235] | 1268 | { |
---|
| 1269 | m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() ); |
---|
| 1270 | m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() ); |
---|
| 1271 | } |
---|
[1322] | 1272 | else |
---|
| 1273 | { |
---|
| 1274 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
| 1275 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | // deblockingFilterControlPresentFlag is true if any of the settings differ from the inferred values: |
---|
| 1279 | const Bool deblockingFilterControlPresentFlag = m_cPPS.getDeblockingFilterOverrideEnabledFlag() || |
---|
| 1280 | m_cPPS.getPicDisableDeblockingFilterFlag() || |
---|
| 1281 | m_cPPS.getDeblockingFilterBetaOffsetDiv2() != 0 || |
---|
| 1282 | m_cPPS.getDeblockingFilterTcOffsetDiv2() != 0; |
---|
| 1283 | |
---|
| 1284 | m_cPPS.setDeblockingFilterControlPresentFlag(deblockingFilterControlPresentFlag); |
---|
| 1285 | |
---|
[313] | 1286 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
| 1287 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
| 1288 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
[1029] | 1289 | |
---|
[1249] | 1290 | |
---|
[313] | 1291 | Int histogram[MAX_NUM_REF + 1]; |
---|
| 1292 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
| 1293 | { |
---|
| 1294 | histogram[i]=0; |
---|
| 1295 | } |
---|
[1029] | 1296 | for( Int i = 0; i < getGOPSize(); i++) |
---|
[313] | 1297 | { |
---|
| 1298 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
| 1299 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
| 1300 | } |
---|
[1029] | 1301 | |
---|
[313] | 1302 | Int maxHist=-1; |
---|
| 1303 | Int bestPos=0; |
---|
| 1304 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
| 1305 | { |
---|
| 1306 | if(histogram[i]>maxHist) |
---|
| 1307 | { |
---|
| 1308 | maxHist=histogram[i]; |
---|
| 1309 | bestPos=i; |
---|
| 1310 | } |
---|
| 1311 | } |
---|
| 1312 | assert(bestPos <= 15); |
---|
| 1313 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
| 1314 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
| 1315 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
| 1316 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
[1316] | 1317 | m_cPPS.getPpsRangeExtension().setLog2MaxTransformSkipBlockSize( m_log2MaxTransformSkipBlockSize ); |
---|
[1029] | 1318 | |
---|
| 1319 | if (m_sliceSegmentMode != NO_SLICES) |
---|
[313] | 1320 | { |
---|
| 1321 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
| 1322 | } |
---|
[1029] | 1323 | |
---|
[442] | 1324 | #if SVC_EXTENSION |
---|
[815] | 1325 | m_cPPS.setLayerId( m_layerId ); |
---|
| 1326 | |
---|
[830] | 1327 | if( !m_numDirectRefLayers && m_numAddLayerSets ) |
---|
[313] | 1328 | { |
---|
[815] | 1329 | m_cPPS.setLayerId(0); // layer ID 0 for independent layers |
---|
[313] | 1330 | } |
---|
[815] | 1331 | |
---|
| 1332 | if( m_layerId > 0 ) |
---|
[313] | 1333 | { |
---|
| 1334 | m_cPPS.setListsModificationPresentFlag(true); |
---|
[815] | 1335 | m_cPPS.setExtensionFlag(true); |
---|
[313] | 1336 | } |
---|
[815] | 1337 | else |
---|
| 1338 | { |
---|
| 1339 | m_cPPS.setListsModificationPresentFlag(false); |
---|
| 1340 | m_cPPS.setExtensionFlag(false); |
---|
| 1341 | } |
---|
[442] | 1342 | |
---|
[815] | 1343 | m_cPPS.setPPSId( m_iPPSIdCnt ); |
---|
| 1344 | m_cPPS.setSPSId( m_iSPSIdCnt ); |
---|
[1150] | 1345 | |
---|
| 1346 | if( m_crossLayerBLAFlag ) |
---|
[540] | 1347 | { |
---|
| 1348 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
| 1349 | } |
---|
[1150] | 1350 | |
---|
[1030] | 1351 | m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets); |
---|
| 1352 | for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++) |
---|
[849] | 1353 | { |
---|
[1030] | 1354 | m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]); |
---|
[849] | 1355 | m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
---|
| 1356 | m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i]; |
---|
[934] | 1357 | m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] ); |
---|
| 1358 | m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] ); |
---|
| 1359 | m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] ); |
---|
[1030] | 1360 | m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] ); |
---|
| 1361 | m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] ); |
---|
| 1362 | m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] ); |
---|
| 1363 | m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] ); |
---|
[849] | 1364 | } |
---|
[1212] | 1365 | #if CGS_3D_ASYMLUT |
---|
[713] | 1366 | m_cPPS.setCGSFlag( m_nCGSFlag ); |
---|
| 1367 | #endif |
---|
[815] | 1368 | m_cPPS.setPocResetInfoPresentFlag( true ); |
---|
| 1369 | m_cPPS.setExtensionFlag( true ); |
---|
| 1370 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
---|
| 1371 | #endif //SVC_EXTENSION |
---|
[313] | 1372 | } |
---|
| 1373 | |
---|
| 1374 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
[442] | 1375 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
[313] | 1376 | { |
---|
| 1377 | TComReferencePictureSet* rps; |
---|
[1029] | 1378 | |
---|
| 1379 | m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1); |
---|
[313] | 1380 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
| 1381 | |
---|
[1029] | 1382 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
[313] | 1383 | { |
---|
| 1384 | GOPEntry ge = getGOPEntry(i); |
---|
| 1385 | rps = rpsList->getReferencePictureSet(i); |
---|
| 1386 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
| 1387 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
| 1388 | Int numNeg = 0; |
---|
| 1389 | Int numPos = 0; |
---|
| 1390 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
| 1391 | { |
---|
| 1392 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
| 1393 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
| 1394 | if(ge.m_referencePics[j]>0) |
---|
| 1395 | { |
---|
| 1396 | numPos++; |
---|
| 1397 | } |
---|
| 1398 | else |
---|
| 1399 | { |
---|
| 1400 | numNeg++; |
---|
| 1401 | } |
---|
| 1402 | } |
---|
| 1403 | rps->setNumberOfNegativePictures(numNeg); |
---|
| 1404 | rps->setNumberOfPositivePictures(numPos); |
---|
| 1405 | |
---|
| 1406 | // handle inter RPS intialization from the config file. |
---|
| 1407 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
| 1408 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
[1235] | 1409 | TComReferencePictureSet* RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL; // get the reference RPS |
---|
[313] | 1410 | |
---|
| 1411 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
| 1412 | { |
---|
[1235] | 1413 | assert (RPSRef!=NULL); |
---|
[313] | 1414 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
| 1415 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
| 1416 | |
---|
| 1417 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
| 1418 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
| 1419 | Int count=0; |
---|
| 1420 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
| 1421 | { |
---|
| 1422 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
| 1423 | rps->setRefIdc(j, 0); |
---|
| 1424 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
| 1425 | { |
---|
[1029] | 1426 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
[313] | 1427 | { |
---|
| 1428 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
| 1429 | count++; |
---|
| 1430 | break; |
---|
| 1431 | } |
---|
| 1432 | } |
---|
| 1433 | } |
---|
| 1434 | if (count != rps->getNumberOfPictures()) |
---|
| 1435 | { |
---|
| 1436 | 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"); |
---|
| 1437 | rps->setInterRPSPrediction(0); |
---|
| 1438 | } |
---|
| 1439 | } |
---|
| 1440 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
| 1441 | { |
---|
[1235] | 1442 | assert (RPSRef!=NULL); |
---|
[313] | 1443 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
| 1444 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
| 1445 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1446 | { |
---|
| 1447 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
| 1448 | } |
---|
[1252] | 1449 | // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
[313] | 1450 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
| 1451 | numNeg = 0; |
---|
| 1452 | numPos = 0; |
---|
| 1453 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
| 1454 | |
---|
| 1455 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1456 | { |
---|
| 1457 | if (ge.m_refIdc[j]) |
---|
| 1458 | { |
---|
| 1459 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
| 1460 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
| 1461 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
| 1462 | if (deltaPOC<0) |
---|
| 1463 | { |
---|
| 1464 | numNeg++; |
---|
| 1465 | } |
---|
| 1466 | else |
---|
| 1467 | { |
---|
| 1468 | numPos++; |
---|
| 1469 | } |
---|
| 1470 | } |
---|
| 1471 | } |
---|
| 1472 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
| 1473 | { |
---|
| 1474 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1475 | rps->setNumberOfNegativePictures(numNeg); |
---|
[442] | 1476 | rps->setNumberOfPictures(numNeg+numPos); |
---|
[313] | 1477 | } |
---|
| 1478 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
| 1479 | { |
---|
| 1480 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1481 | rps->setNumberOfPositivePictures(numPos); |
---|
[442] | 1482 | rps->setNumberOfPictures(numNeg+numPos); |
---|
[313] | 1483 | } |
---|
| 1484 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
| 1485 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
| 1486 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
[1029] | 1487 | // check if Delta POC and Used are the same |
---|
[313] | 1488 | // print warning if they are not. |
---|
| 1489 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1490 | { |
---|
| 1491 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
| 1492 | { |
---|
| 1493 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
| 1494 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
| 1495 | } |
---|
| 1496 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
| 1497 | { |
---|
| 1498 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1499 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
| 1500 | } |
---|
| 1501 | } |
---|
| 1502 | } |
---|
| 1503 | } |
---|
[1029] | 1504 | //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. |
---|
| 1505 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
| 1506 | if (isFieldCoding) |
---|
[442] | 1507 | { |
---|
| 1508 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
| 1509 | rps->setNumberOfPictures(1); |
---|
| 1510 | rps->setNumberOfNegativePictures(1); |
---|
| 1511 | rps->setNumberOfPositivePictures(0); |
---|
| 1512 | rps->setNumberOfLongtermPictures(0); |
---|
| 1513 | rps->setDeltaPOC(0,-1); |
---|
| 1514 | rps->setPOC(0,0); |
---|
| 1515 | rps->setUsed(0,true); |
---|
| 1516 | rps->setInterRPSPrediction(false); |
---|
| 1517 | rps->setDeltaRIdxMinus1(0); |
---|
| 1518 | rps->setDeltaRPS(0); |
---|
| 1519 | rps->setNumRefIdc(0); |
---|
[1029] | 1520 | } |
---|
[313] | 1521 | } |
---|
| 1522 | |
---|
[1029] | 1523 | // This is a function that |
---|
| 1524 | // determines what Reference Picture Set to use |
---|
[313] | 1525 | // for a specific slice (with POC = POCCurr) |
---|
| 1526 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
| 1527 | { |
---|
| 1528 | slice->setRPSidx(GOPid); |
---|
[1029] | 1529 | |
---|
[313] | 1530 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
[1029] | 1531 | { |
---|
[313] | 1532 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
| 1533 | { |
---|
| 1534 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
| 1535 | if(POCIndex == 0) |
---|
| 1536 | { |
---|
| 1537 | POCIndex = m_uiIntraPeriod; |
---|
| 1538 | } |
---|
| 1539 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
| 1540 | { |
---|
| 1541 | slice->setRPSidx(extraNum); |
---|
| 1542 | } |
---|
| 1543 | } |
---|
| 1544 | else |
---|
| 1545 | { |
---|
| 1546 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
| 1547 | { |
---|
| 1548 | slice->setRPSidx(extraNum); |
---|
| 1549 | } |
---|
| 1550 | } |
---|
| 1551 | } |
---|
| 1552 | |
---|
[442] | 1553 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
| 1554 | { |
---|
| 1555 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
| 1556 | } |
---|
| 1557 | |
---|
[1366] | 1558 | const TComReferencePictureSet *rps = (slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
[1235] | 1559 | slice->setRPS(rps); |
---|
[313] | 1560 | } |
---|
| 1561 | |
---|
[1307] | 1562 | Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid ) |
---|
[313] | 1563 | { |
---|
[1029] | 1564 | Int rpsIdx = GOPid; |
---|
[313] | 1565 | |
---|
| 1566 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
[1029] | 1567 | { |
---|
[313] | 1568 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
| 1569 | { |
---|
| 1570 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
| 1571 | if(POCIndex == 0) |
---|
| 1572 | { |
---|
| 1573 | POCIndex = m_uiIntraPeriod; |
---|
| 1574 | } |
---|
| 1575 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
| 1576 | { |
---|
| 1577 | rpsIdx = extraNum; |
---|
| 1578 | } |
---|
| 1579 | } |
---|
| 1580 | else |
---|
| 1581 | { |
---|
| 1582 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
| 1583 | { |
---|
| 1584 | rpsIdx = extraNum; |
---|
| 1585 | } |
---|
| 1586 | } |
---|
| 1587 | } |
---|
| 1588 | |
---|
| 1589 | return rpsIdx; |
---|
| 1590 | } |
---|
| 1591 | |
---|
| 1592 | Void TEncTop::xInitPPSforTiles() |
---|
| 1593 | { |
---|
[823] | 1594 | m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag ); |
---|
| 1595 | m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
| 1596 | m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 ); |
---|
| 1597 | if( !m_tileUniformSpacingFlag ) |
---|
[313] | 1598 | { |
---|
[823] | 1599 | m_cPPS.setTileColumnWidth( m_tileColumnWidth ); |
---|
| 1600 | m_cPPS.setTileRowHeight( m_tileRowHeight ); |
---|
[313] | 1601 | } |
---|
| 1602 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
| 1603 | |
---|
| 1604 | // # substreams is "per tile" when tiles are independent. |
---|
| 1605 | } |
---|
| 1606 | |
---|
| 1607 | Void TEncCfg::xCheckGSParameters() |
---|
| 1608 | { |
---|
[1289] | 1609 | Int iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth; |
---|
| 1610 | Int iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight; |
---|
[313] | 1611 | UInt uiCummulativeColumnWidth = 0; |
---|
| 1612 | UInt uiCummulativeRowHeight = 0; |
---|
| 1613 | |
---|
| 1614 | //check the column relative parameters |
---|
| 1615 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
| 1616 | { |
---|
| 1617 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
| 1618 | exit( EXIT_FAILURE ); |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
| 1622 | { |
---|
| 1623 | printf( "The current picture can not have so many columns.\n" ); |
---|
| 1624 | exit( EXIT_FAILURE ); |
---|
| 1625 | } |
---|
| 1626 | |
---|
[823] | 1627 | if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag ) |
---|
[313] | 1628 | { |
---|
| 1629 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
| 1630 | { |
---|
[823] | 1631 | uiCummulativeColumnWidth += m_tileColumnWidth[i]; |
---|
[313] | 1632 | } |
---|
| 1633 | |
---|
| 1634 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
| 1635 | { |
---|
| 1636 | printf( "The width of the column is too large.\n" ); |
---|
| 1637 | exit( EXIT_FAILURE ); |
---|
| 1638 | } |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | //check the row relative parameters |
---|
| 1642 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
| 1643 | { |
---|
| 1644 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
| 1645 | exit( EXIT_FAILURE ); |
---|
| 1646 | } |
---|
| 1647 | |
---|
| 1648 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
| 1649 | { |
---|
| 1650 | printf( "The current picture can not have so many rows.\n" ); |
---|
| 1651 | exit( EXIT_FAILURE ); |
---|
| 1652 | } |
---|
| 1653 | |
---|
[823] | 1654 | if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag ) |
---|
[313] | 1655 | { |
---|
| 1656 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
[1246] | 1657 | { |
---|
[823] | 1658 | uiCummulativeRowHeight += m_tileRowHeight[i]; |
---|
[1246] | 1659 | } |
---|
[313] | 1660 | |
---|
| 1661 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
| 1662 | { |
---|
| 1663 | printf( "The height of the row is too large.\n" ); |
---|
| 1664 | exit( EXIT_FAILURE ); |
---|
| 1665 | } |
---|
| 1666 | } |
---|
| 1667 | } |
---|
| 1668 | |
---|
| 1669 | #if SVC_EXTENSION |
---|
[1048] | 1670 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx ) |
---|
[313] | 1671 | { |
---|
[1057] | 1672 | if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 ) |
---|
[313] | 1673 | { |
---|
| 1674 | return (TEncTop *)getLayerEnc( 0 ); |
---|
| 1675 | } |
---|
| 1676 | |
---|
[1057] | 1677 | return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) ); |
---|
[313] | 1678 | } |
---|
| 1679 | |
---|
| 1680 | Void TEncTop::xInitILRP() |
---|
| 1681 | { |
---|
[1235] | 1682 | if( m_layerId > 0 ) |
---|
[442] | 1683 | { |
---|
[1290] | 1684 | if( m_cIlpPic[0] == NULL ) |
---|
[442] | 1685 | { |
---|
[588] | 1686 | for (Int j=0; j < m_numDirectRefLayers; j++) |
---|
[442] | 1687 | { |
---|
[1029] | 1688 | m_cIlpPic[j] = new TComPic; |
---|
[1503] | 1689 | m_cIlpPic[j]->create(m_cSPS, m_cPPS, true, m_layerId); |
---|
[1029] | 1690 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++) |
---|
[442] | 1691 | { |
---|
[1029] | 1692 | m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i); |
---|
[442] | 1693 | } |
---|
| 1694 | } |
---|
| 1695 | } |
---|
[1009] | 1696 | |
---|
| 1697 | if( m_cVPS.getNumRefLayers( m_layerId ) == 0 ) |
---|
| 1698 | { |
---|
[1043] | 1699 | UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId ); |
---|
[1020] | 1700 | RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx)); |
---|
[1009] | 1701 | |
---|
| 1702 | if( m_cPPS.getLayerId() == 0 && |
---|
| 1703 | m_cSPS.getLayerId() == 0 && |
---|
[1020] | 1704 | repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() && |
---|
| 1705 | repFmt->getSeparateColourPlaneVpsFlag() == 0 && |
---|
| 1706 | repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() && |
---|
| 1707 | repFmt->getPicWidthVpsInLumaSamples() == m_cSPS.getPicWidthInLumaSamples() && |
---|
[1029] | 1708 | repFmt->getBitDepthVpsLuma() == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) && |
---|
| 1709 | repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) && |
---|
[1020] | 1710 | repFmt->getConformanceWindowVps().getWindowLeftOffset() == m_cSPS.getConformanceWindow().getWindowLeftOffset() && |
---|
| 1711 | repFmt->getConformanceWindowVps().getWindowRightOffset() == m_cSPS.getConformanceWindow().getWindowRightOffset() && |
---|
| 1712 | repFmt->getConformanceWindowVps().getWindowTopOffset() == m_cSPS.getConformanceWindow().getWindowTopOffset() && |
---|
| 1713 | repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() ) |
---|
[1009] | 1714 | { |
---|
| 1715 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1); |
---|
| 1716 | } |
---|
| 1717 | else |
---|
| 1718 | { |
---|
| 1719 | m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0); |
---|
| 1720 | } |
---|
| 1721 | } |
---|
[442] | 1722 | } |
---|
| 1723 | } |
---|
[540] | 1724 | |
---|
[1235] | 1725 | Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId) |
---|
[540] | 1726 | { |
---|
[1030] | 1727 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
[540] | 1728 | { |
---|
[1030] | 1729 | if (layerId == m_refLocationOffsetLayerId[i]) |
---|
[540] | 1730 | { |
---|
| 1731 | return m_scaledRefLayerWindow[i]; |
---|
| 1732 | } |
---|
| 1733 | } |
---|
| 1734 | |
---|
[1235] | 1735 | return Window(); |
---|
[540] | 1736 | } |
---|
[1090] | 1737 | |
---|
[1235] | 1738 | Window TEncTop::getRefLayerWindowForLayer(Int layerId) |
---|
[849] | 1739 | { |
---|
[1030] | 1740 | for (Int i = 0; i < m_numRefLayerLocationOffsets; i++) |
---|
[849] | 1741 | { |
---|
| 1742 | if (layerId == m_refLayerId[i]) |
---|
| 1743 | { |
---|
| 1744 | return m_refLayerWindow[i]; |
---|
| 1745 | } |
---|
| 1746 | } |
---|
| 1747 | |
---|
[1235] | 1748 | return Window(); |
---|
[849] | 1749 | } |
---|
[494] | 1750 | #endif //SVC_EXTENSION |
---|
[313] | 1751 | //! \} |
---|