[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncGOP.cpp |
---|
| 35 | \brief GOP encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <list> |
---|
| 39 | #include <algorithm> |
---|
| 40 | #include <functional> |
---|
| 41 | |
---|
| 42 | #include "TEncTop.h" |
---|
| 43 | #include "TEncGOP.h" |
---|
| 44 | #include "TEncAnalyze.h" |
---|
| 45 | #include "libmd5/MD5.h" |
---|
| 46 | #include "TLibCommon/SEI.h" |
---|
| 47 | #include "TLibCommon/NAL.h" |
---|
| 48 | #include "NALwrite.h" |
---|
| 49 | #include <time.h> |
---|
| 50 | #include <math.h> |
---|
| 51 | |
---|
| 52 | using namespace std; |
---|
| 53 | //! \ingroup TLibEncoder |
---|
| 54 | //! \{ |
---|
| 55 | |
---|
| 56 | // ==================================================================================================================== |
---|
| 57 | // Constructor / destructor / initialization / destroy |
---|
| 58 | // ==================================================================================================================== |
---|
| 59 | Int getLSB(Int poc, Int maxLSB) |
---|
| 60 | { |
---|
| 61 | if (poc >= 0) |
---|
| 62 | { |
---|
| 63 | return poc % maxLSB; |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | return (maxLSB - ((-poc) % maxLSB)) % maxLSB; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | TEncGOP::TEncGOP() |
---|
| 72 | { |
---|
| 73 | m_iLastIDR = 0; |
---|
| 74 | m_iGopSize = 0; |
---|
| 75 | m_iNumPicCoded = 0; //Niko |
---|
| 76 | m_bFirst = true; |
---|
| 77 | |
---|
| 78 | m_pcCfg = NULL; |
---|
| 79 | m_pcSliceEncoder = NULL; |
---|
| 80 | m_pcListPic = NULL; |
---|
| 81 | |
---|
| 82 | m_pcEntropyCoder = NULL; |
---|
| 83 | m_pcCavlcCoder = NULL; |
---|
| 84 | m_pcSbacCoder = NULL; |
---|
| 85 | m_pcBinCABAC = NULL; |
---|
| 86 | |
---|
| 87 | m_bSeqFirst = true; |
---|
| 88 | |
---|
| 89 | m_bRefreshPending = 0; |
---|
| 90 | m_pocCRA = 0; |
---|
| 91 | m_numLongTermRefPicSPS = 0; |
---|
| 92 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
| 93 | ::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag)); |
---|
| 94 | m_cpbRemovalDelay = 0; |
---|
| 95 | m_lastBPSEI = 0; |
---|
| 96 | xResetNonNestedSEIPresentFlags(); |
---|
| 97 | xResetNestedSEIPresentFlags(); |
---|
| 98 | #if SVC_UPSAMPLING |
---|
| 99 | m_pcPredSearch = NULL; |
---|
| 100 | #endif |
---|
| 101 | return; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | TEncGOP::~TEncGOP() |
---|
| 105 | { |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /** Create list to contain pointers to LCU start addresses of slice. |
---|
| 109 | */ |
---|
| 110 | #if SVC_EXTENSION |
---|
| 111 | Void TEncGOP::create( UInt layerId ) |
---|
| 112 | { |
---|
| 113 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
| 114 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
| 115 | m_layerId = layerId; |
---|
| 116 | } |
---|
| 117 | #else |
---|
| 118 | Void TEncGOP::create() |
---|
| 119 | { |
---|
| 120 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
| 121 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
| 122 | } |
---|
| 123 | #endif |
---|
| 124 | |
---|
| 125 | Void TEncGOP::destroy() |
---|
| 126 | { |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | Void TEncGOP::init ( TEncTop* pcTEncTop ) |
---|
| 130 | { |
---|
| 131 | m_pcEncTop = pcTEncTop; |
---|
| 132 | m_pcCfg = pcTEncTop; |
---|
| 133 | m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); |
---|
| 134 | m_pcListPic = pcTEncTop->getListPic(); |
---|
| 135 | |
---|
| 136 | m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); |
---|
| 137 | m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); |
---|
| 138 | m_pcSbacCoder = pcTEncTop->getSbacCoder(); |
---|
| 139 | m_pcBinCABAC = pcTEncTop->getBinCABAC(); |
---|
| 140 | m_pcLoopFilter = pcTEncTop->getLoopFilter(); |
---|
| 141 | m_pcBitCounter = pcTEncTop->getBitCounter(); |
---|
| 142 | |
---|
| 143 | //--Adaptive Loop filter |
---|
| 144 | m_pcSAO = pcTEncTop->getSAO(); |
---|
| 145 | m_pcRateCtrl = pcTEncTop->getRateCtrl(); |
---|
| 146 | m_lastBPSEI = 0; |
---|
| 147 | m_totalCoded = 0; |
---|
| 148 | |
---|
| 149 | #if SVC_EXTENSION |
---|
| 150 | m_ppcTEncTop = pcTEncTop->getLayerEnc(); |
---|
| 151 | #endif |
---|
| 152 | #if SVC_UPSAMPLING |
---|
| 153 | m_pcPredSearch = pcTEncTop->getPredSearch(); ///< encoder search class |
---|
| 154 | #endif |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | SEIActiveParameterSets* TEncGOP::xCreateSEIActiveParameterSets (TComSPS *sps) |
---|
| 158 | { |
---|
| 159 | SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); |
---|
| 160 | seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); |
---|
| 161 | seiActiveParameterSets->m_fullRandomAccessFlag = false; |
---|
| 162 | seiActiveParameterSets->m_noParamSetUpdateFlag = false; |
---|
| 163 | seiActiveParameterSets->numSpsIdsMinus1 = 0; |
---|
| 164 | seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); |
---|
| 165 | seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId(); |
---|
| 166 | return seiActiveParameterSets; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | #if M0043_LAYERS_PRESENT_SEI |
---|
| 170 | SEILayersPresent* TEncGOP::xCreateSEILayersPresent () |
---|
| 171 | { |
---|
| 172 | UInt i = 0; |
---|
| 173 | SEILayersPresent *seiLayersPresent = new SEILayersPresent(); |
---|
| 174 | seiLayersPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId(); |
---|
| 175 | seiLayersPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers(); |
---|
| 176 | for ( ; i < seiLayersPresent->m_vpsMaxLayers; i++) |
---|
| 177 | { |
---|
| 178 | seiLayersPresent->m_layerPresentFlag[i] = true; |
---|
| 179 | } |
---|
| 180 | for ( ; i < MAX_LAYERS; i++) |
---|
| 181 | { |
---|
| 182 | seiLayersPresent->m_layerPresentFlag[i] = false; |
---|
| 183 | } |
---|
| 184 | return seiLayersPresent; |
---|
| 185 | } |
---|
| 186 | #endif |
---|
| 187 | |
---|
| 188 | SEIFramePacking* TEncGOP::xCreateSEIFramePacking() |
---|
| 189 | { |
---|
| 190 | SEIFramePacking *seiFramePacking = new SEIFramePacking(); |
---|
| 191 | seiFramePacking->m_arrangementId = m_pcCfg->getFramePackingArrangementSEIId(); |
---|
| 192 | seiFramePacking->m_arrangementCancelFlag = 0; |
---|
| 193 | seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType(); |
---|
| 194 | assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) ); |
---|
| 195 | seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx(); |
---|
| 196 | seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation(); |
---|
| 197 | seiFramePacking->m_spatialFlippingFlag = 0; |
---|
| 198 | seiFramePacking->m_frame0FlippedFlag = 0; |
---|
| 199 | seiFramePacking->m_fieldViewsFlag = (seiFramePacking->m_arrangementType == 2); |
---|
| 200 | seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && m_iNumPicCoded&1); |
---|
| 201 | seiFramePacking->m_frame0SelfContainedFlag = 0; |
---|
| 202 | seiFramePacking->m_frame1SelfContainedFlag = 0; |
---|
| 203 | seiFramePacking->m_frame0GridPositionX = 0; |
---|
| 204 | seiFramePacking->m_frame0GridPositionY = 0; |
---|
| 205 | seiFramePacking->m_frame1GridPositionX = 0; |
---|
| 206 | seiFramePacking->m_frame1GridPositionY = 0; |
---|
| 207 | seiFramePacking->m_arrangementReservedByte = 0; |
---|
| 208 | seiFramePacking->m_arrangementPersistenceFlag = true; |
---|
| 209 | seiFramePacking->m_upsampledAspectRatio = 0; |
---|
| 210 | return seiFramePacking; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | SEIDisplayOrientation* TEncGOP::xCreateSEIDisplayOrientation() |
---|
| 214 | { |
---|
| 215 | SEIDisplayOrientation *seiDisplayOrientation = new SEIDisplayOrientation(); |
---|
| 216 | seiDisplayOrientation->cancelFlag = false; |
---|
| 217 | seiDisplayOrientation->horFlip = false; |
---|
| 218 | seiDisplayOrientation->verFlip = false; |
---|
| 219 | seiDisplayOrientation->anticlockwiseRotation = m_pcCfg->getDisplayOrientationSEIAngle(); |
---|
| 220 | return seiDisplayOrientation; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | SEIToneMappingInfo* TEncGOP::xCreateSEIToneMappingInfo() |
---|
| 224 | { |
---|
| 225 | SEIToneMappingInfo *seiToneMappingInfo = new SEIToneMappingInfo(); |
---|
| 226 | seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId(); |
---|
| 227 | seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag(); |
---|
| 228 | seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag(); |
---|
| 229 | |
---|
| 230 | seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth(); |
---|
| 231 | assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14); |
---|
| 232 | seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth(); |
---|
| 233 | assert( seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17 ); |
---|
| 234 | seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID(); |
---|
| 235 | assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4); |
---|
| 236 | |
---|
| 237 | switch( seiToneMappingInfo->m_modelId) |
---|
| 238 | { |
---|
| 239 | case 0: |
---|
| 240 | { |
---|
| 241 | seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue(); |
---|
| 242 | seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue(); |
---|
| 243 | break; |
---|
| 244 | } |
---|
| 245 | case 1: |
---|
| 246 | { |
---|
| 247 | seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint(); |
---|
| 248 | seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth(); |
---|
| 249 | break; |
---|
| 250 | } |
---|
| 251 | case 2: |
---|
| 252 | { |
---|
| 253 | UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth); |
---|
| 254 | seiToneMappingInfo->m_startOfCodedInterval.resize(num); |
---|
| 255 | Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva(); |
---|
| 256 | if(ptmp) |
---|
| 257 | { |
---|
| 258 | for(int i=0; i<num;i++) |
---|
| 259 | { |
---|
| 260 | seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i]; |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | break; |
---|
| 264 | } |
---|
| 265 | case 3: |
---|
| 266 | { |
---|
| 267 | seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots(); |
---|
| 268 | seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots); |
---|
| 269 | seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots); |
---|
| 270 | Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue(); |
---|
| 271 | Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue(); |
---|
| 272 | if(ptmpcoded&&ptmptarget) |
---|
| 273 | { |
---|
| 274 | for(int i=0; i<(seiToneMappingInfo->m_numPivots);i++) |
---|
| 275 | { |
---|
| 276 | seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i]; |
---|
| 277 | seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i]; |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | break; |
---|
| 281 | } |
---|
| 282 | case 4: |
---|
| 283 | { |
---|
| 284 | seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc(); |
---|
| 285 | seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue(); |
---|
| 286 | assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 ); |
---|
| 287 | seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag(); |
---|
| 288 | seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator(); |
---|
| 289 | seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc(); |
---|
| 290 | seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite(); |
---|
| 291 | seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel(); |
---|
| 292 | assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 ); |
---|
| 293 | seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue(); |
---|
| 294 | seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue(); |
---|
| 295 | assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue ); |
---|
| 296 | seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue(); |
---|
| 297 | assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue ); |
---|
| 298 | break; |
---|
| 299 | } |
---|
| 300 | default: |
---|
| 301 | { |
---|
| 302 | assert(!"Undefined SEIToneMapModelId"); |
---|
| 303 | break; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | return seiToneMappingInfo; |
---|
| 307 | } |
---|
| 308 | |
---|
[442] | 309 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 310 | SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets() |
---|
| 311 | { |
---|
| 312 | SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets(); |
---|
| 313 | seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false; |
---|
| 314 | seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false; |
---|
| 315 | if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag) |
---|
| 316 | { |
---|
| 317 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1; |
---|
| 318 | if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1) |
---|
| 319 | { |
---|
| 320 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag(); |
---|
| 321 | } |
---|
| 322 | else |
---|
| 323 | { |
---|
| 324 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false; |
---|
| 325 | } |
---|
| 326 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0; |
---|
| 327 | for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++) |
---|
| 328 | { |
---|
| 329 | seiInterLayerConstrainedTileSets->m_ilctsId[i] = i; |
---|
| 330 | seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0; |
---|
| 331 | for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++) |
---|
| 332 | { |
---|
| 333 | seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j] = m_pcCfg->getTopLeftTileIndex(i); |
---|
| 334 | seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i); |
---|
| 335 | } |
---|
| 336 | seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i); |
---|
| 337 | if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag) |
---|
| 338 | { |
---|
| 339 | seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false; |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | return seiInterLayerConstrainedTileSets; |
---|
| 345 | } |
---|
| 346 | #endif |
---|
| 347 | |
---|
[313] | 348 | Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps) |
---|
| 349 | { |
---|
| 350 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 351 | |
---|
| 352 | if(m_pcCfg->getActiveParameterSetsSEIEnabled()) |
---|
| 353 | { |
---|
| 354 | SEIActiveParameterSets *sei = xCreateSEIActiveParameterSets (sps); |
---|
| 355 | |
---|
| 356 | //nalu = NALUnit(NAL_UNIT_SEI); |
---|
| 357 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 358 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 359 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 360 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 361 | delete sei; |
---|
| 362 | m_activeParameterSetSEIPresentInAU = true; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | #if M0043_LAYERS_PRESENT_SEI |
---|
| 366 | if(m_pcCfg->getLayersPresentSEIEnabled()) |
---|
| 367 | { |
---|
| 368 | SEILayersPresent *sei = xCreateSEILayersPresent (); |
---|
| 369 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 370 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 371 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 372 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 373 | delete sei; |
---|
| 374 | } |
---|
| 375 | #endif |
---|
| 376 | |
---|
| 377 | if(m_pcCfg->getFramePackingArrangementSEIEnabled()) |
---|
| 378 | { |
---|
| 379 | SEIFramePacking *sei = xCreateSEIFramePacking (); |
---|
| 380 | |
---|
| 381 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
| 382 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 383 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 384 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 385 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 386 | delete sei; |
---|
| 387 | } |
---|
| 388 | if (m_pcCfg->getDisplayOrientationSEIAngle()) |
---|
| 389 | { |
---|
| 390 | SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation(); |
---|
| 391 | |
---|
| 392 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
| 393 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 394 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 395 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 396 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 397 | delete sei; |
---|
| 398 | } |
---|
| 399 | if(m_pcCfg->getToneMappingInfoSEIEnabled()) |
---|
| 400 | { |
---|
| 401 | SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo (); |
---|
| 402 | |
---|
| 403 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI); |
---|
| 404 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 405 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 406 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 407 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 408 | delete sei; |
---|
| 409 | } |
---|
[442] | 410 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 411 | if(m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled()) |
---|
| 412 | { |
---|
| 413 | SEIInterLayerConstrainedTileSets *sei = xCreateSEIInterLayerConstrainedTileSets (); |
---|
| 414 | |
---|
| 415 | nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_pcCfg->getNumLayer()-1); // For highest layer |
---|
| 416 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 417 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
| 418 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 419 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 420 | delete sei; |
---|
| 421 | } |
---|
| 422 | #endif |
---|
[313] | 423 | } |
---|
| 424 | |
---|
| 425 | // ==================================================================================================================== |
---|
| 426 | // Public member functions |
---|
| 427 | // ==================================================================================================================== |
---|
| 428 | #if SVC_EXTENSION |
---|
[442] | 429 | Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff) |
---|
[313] | 430 | #else |
---|
[442] | 431 | Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff) |
---|
[313] | 432 | #endif |
---|
| 433 | { |
---|
| 434 | TComPic* pcPic; |
---|
| 435 | TComPicYuv* pcPicYuvRecOut; |
---|
| 436 | TComSlice* pcSlice; |
---|
| 437 | TComOutputBitstream *pcBitstreamRedirect; |
---|
| 438 | pcBitstreamRedirect = new TComOutputBitstream; |
---|
| 439 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
| 440 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
| 441 | TEncSbac* pcSbacCoders = NULL; |
---|
| 442 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
| 443 | |
---|
[442] | 444 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField ); |
---|
[313] | 445 | |
---|
| 446 | m_iNumPicCoded = 0; |
---|
| 447 | SEIPictureTiming pictureTimingSEI; |
---|
| 448 | Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled(); |
---|
| 449 | // Initialize Scalable Nesting SEI with single layer values |
---|
| 450 | SEIScalableNesting scalableNestingSEI; |
---|
| 451 | scalableNestingSEI.m_bitStreamSubsetFlag = 1; // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1 |
---|
| 452 | scalableNestingSEI.m_nestingOpFlag = 0; |
---|
| 453 | scalableNestingSEI.m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 |
---|
| 454 | scalableNestingSEI.m_allLayersFlag = 0; |
---|
| 455 | scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 |
---|
| 456 | scalableNestingSEI.m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 |
---|
| 457 | scalableNestingSEI.m_nestingLayerId[0] = 0; |
---|
| 458 | scalableNestingSEI.m_callerOwnsSEIs = true; |
---|
| 459 | Int picSptDpbOutputDuDelay = 0; |
---|
| 460 | UInt *accumBitsDU = NULL; |
---|
| 461 | UInt *accumNalsDU = NULL; |
---|
| 462 | SEIDecodingUnitInfo decodingUnitInfoSEI; |
---|
| 463 | #if SVC_EXTENSION |
---|
| 464 | for ( Int iGOPid=iPicIdInGOP; iGOPid < iPicIdInGOP+1; iGOPid++ ) |
---|
| 465 | #else |
---|
| 466 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
| 467 | #endif |
---|
| 468 | { |
---|
| 469 | UInt uiColDir = 1; |
---|
| 470 | //-- For time output for each slice |
---|
| 471 | long iBeforeTime = clock(); |
---|
| 472 | |
---|
| 473 | //select uiColDir |
---|
| 474 | Int iCloseLeft=1, iCloseRight=-1; |
---|
| 475 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
| 476 | { |
---|
| 477 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
| 478 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
| 479 | { |
---|
| 480 | iCloseRight=iRef; |
---|
| 481 | } |
---|
| 482 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
| 483 | { |
---|
| 484 | iCloseLeft=iRef; |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | if(iCloseRight>-1) |
---|
| 488 | { |
---|
| 489 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 490 | } |
---|
| 491 | if(iCloseLeft<1) |
---|
| 492 | { |
---|
| 493 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
| 494 | while(iCloseLeft<0) |
---|
| 495 | { |
---|
| 496 | iCloseLeft+=m_iGopSize; |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | Int iLeftQP=0, iRightQP=0; |
---|
| 500 | for(Int i=0; i<m_iGopSize; i++) |
---|
| 501 | { |
---|
| 502 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
| 503 | { |
---|
| 504 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 505 | } |
---|
| 506 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
| 507 | { |
---|
| 508 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
| 512 | { |
---|
| 513 | uiColDir=0; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
[442] | 517 | Int iTimeOffset; |
---|
| 518 | Int pocCurr; |
---|
| 519 | |
---|
| 520 | if(iPOCLast == 0) //case first frame or first top field |
---|
[313] | 521 | { |
---|
| 522 | pocCurr=0; |
---|
| 523 | iTimeOffset = 1; |
---|
| 524 | } |
---|
[442] | 525 | else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value |
---|
| 526 | { |
---|
| 527 | pocCurr = 1; |
---|
| 528 | iTimeOffset = 1; |
---|
| 529 | } |
---|
| 530 | else |
---|
| 531 | { |
---|
| 532 | pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField; |
---|
| 533 | iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
| 534 | } |
---|
| 535 | |
---|
[313] | 536 | if(pocCurr>=m_pcCfg->getFramesToBeEncoded()) |
---|
| 537 | { |
---|
| 538 | continue; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
| 542 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && ((m_layerId == 1 && pocCurr < m_pcEncTop->getAdaptiveResolutionChange()) || |
---|
| 543 | (m_layerId == 0 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())) ) |
---|
| 544 | { |
---|
| 545 | continue; |
---|
| 546 | } |
---|
| 547 | #endif |
---|
| 548 | |
---|
| 549 | if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
| 550 | { |
---|
| 551 | m_iLastIDR = pocCurr; |
---|
| 552 | } |
---|
| 553 | // start a new access unit: create an entry in the list of output access units |
---|
| 554 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
| 555 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
[442] | 556 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField ); |
---|
[313] | 557 | |
---|
| 558 | // Slice data initialization |
---|
| 559 | pcPic->clearSliceBuffer(); |
---|
| 560 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
| 561 | m_pcSliceEncoder->setSliceIdx(0); |
---|
| 562 | pcPic->setCurrSliceIdx(0); |
---|
| 563 | #if SVC_EXTENSION |
---|
| 564 | pcPic->setLayerId( m_layerId ); |
---|
[442] | 565 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField ); |
---|
[313] | 566 | #else |
---|
[442] | 567 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField ); |
---|
[313] | 568 | #endif |
---|
| 569 | |
---|
[442] | 570 | //Set Frame/Field coding |
---|
| 571 | pcSlice->getPic()->setField(isField); |
---|
| 572 | |
---|
| 573 | #if POC_RESET_FLAG |
---|
| 574 | if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files. |
---|
| 575 | { |
---|
| 576 | // Subtract POC adjustment value until now. |
---|
| 577 | pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() ); |
---|
| 578 | } |
---|
| 579 | else |
---|
| 580 | { |
---|
| 581 | // Check if this is the first slice in the picture |
---|
| 582 | // In the encoder, the POC values are copied along with copySliceInfo, so we only need |
---|
| 583 | // to do this for the first slice. |
---|
| 584 | Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue(); |
---|
| 585 | if( pcSlice->getSliceIdx() == 0 ) |
---|
| 586 | { |
---|
| 587 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 588 | |
---|
| 589 | // Iterate through all picture in DPB |
---|
| 590 | while( iterPic != rcListPic.end() ) |
---|
| 591 | { |
---|
| 592 | TComPic *dpbPic = *iterPic; |
---|
| 593 | if( dpbPic->getPOC() == pocCurr ) |
---|
| 594 | { |
---|
| 595 | if( dpbPic->getReconMark() ) |
---|
| 596 | { |
---|
| 597 | assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) ); |
---|
| 598 | } |
---|
| 599 | } |
---|
| 600 | // Check if the picture pointed to by iterPic is either used for reference or |
---|
| 601 | // needed for output, are in the same layer, and not the current picture. |
---|
| 602 | if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) ) |
---|
| 603 | && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() ) |
---|
| 604 | && ( dpbPic->getReconMark() ) |
---|
| 605 | ) |
---|
| 606 | { |
---|
| 607 | for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--) |
---|
| 608 | { |
---|
| 609 | TComSlice *slice = dpbPic->getSlice(i); |
---|
| 610 | TComReferencePictureSet *rps = slice->getRPS(); |
---|
| 611 | slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue ); |
---|
| 612 | |
---|
| 613 | // Also adjust the POC value stored in the RPS of each such slice |
---|
| 614 | for(Int j = rps->getNumberOfPictures(); j >= 0; j--) |
---|
| 615 | { |
---|
| 616 | rps->setPOC( j, rps->getPOC(j) - pocAdjustValue ); |
---|
| 617 | } |
---|
| 618 | // Also adjust the value of refPOC |
---|
| 619 | for(Int k = 0; k < 2; k++) // For List 0 and List 1 |
---|
| 620 | { |
---|
| 621 | RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
| 622 | for(Int j = 0; j < slice->getNumRefIdx(list); j++) |
---|
| 623 | { |
---|
| 624 | slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j); |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | iterPic++; |
---|
| 630 | } |
---|
| 631 | m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
| 632 | } |
---|
| 633 | pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue ); |
---|
| 634 | pcSlice->setPOC( 0 ); |
---|
| 635 | } |
---|
| 636 | #endif |
---|
[313] | 637 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
| 638 | if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange()) |
---|
| 639 | { |
---|
| 640 | pcSlice->setActiveNumILRRefIdx(0); |
---|
| 641 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
| 642 | #if M0457_COL_PICTURE_SIGNALING |
---|
| 643 | pcSlice->setMFMEnabledFlag(false); |
---|
[345] | 644 | #if !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 645 | pcSlice->setAltColIndicationFlag(false); |
---|
| 646 | #endif |
---|
[345] | 647 | #endif |
---|
[313] | 648 | } |
---|
| 649 | #endif |
---|
| 650 | |
---|
| 651 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
| 652 | pcSlice->setNumSamplePredRefLayers( m_pcEncTop->getNumSamplePredRefLayers() ); |
---|
| 653 | pcSlice->setInterLayerSamplePredOnlyFlag( 0 ); |
---|
| 654 | if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 ) |
---|
| 655 | { |
---|
| 656 | if( m_pcEncTop->getIlSampleOnlyPred() > 0 ) |
---|
| 657 | { |
---|
| 658 | pcSlice->setInterLayerSamplePredOnlyFlag( true ); |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | #endif |
---|
| 662 | |
---|
[442] | 663 | #if IL_SL_SIGNALLING_N0371 |
---|
| 664 | m_pcEncTop->getScalingList()->setLayerId( m_layerId ); |
---|
| 665 | #endif |
---|
| 666 | |
---|
[313] | 667 | pcSlice->setLastIDR(m_iLastIDR); |
---|
| 668 | pcSlice->setSliceIdx(0); |
---|
| 669 | //set default slice level flag to the same as SPS level flag |
---|
| 670 | pcSlice->setLFCrossSliceBoundaryFlag( pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() ); |
---|
| 671 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
| 672 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
| 673 | { |
---|
[442] | 674 | #if IL_SL_SIGNALLING_N0371 |
---|
| 675 | m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId ); |
---|
| 676 | #else |
---|
[313] | 677 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
[442] | 678 | #endif |
---|
[313] | 679 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
| 680 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
| 681 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
| 682 | } |
---|
| 683 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
| 684 | { |
---|
[442] | 685 | #if IL_SL_SIGNALLING_N0371 |
---|
| 686 | pcSlice->getScalingList()->setLayerId( m_layerId ); |
---|
| 687 | #endif |
---|
| 688 | |
---|
| 689 | #if IL_SL_SIGNALLING_N0371 |
---|
| 690 | pcSlice->setDefaultScalingList ( m_layerId ); |
---|
| 691 | #else |
---|
[313] | 692 | pcSlice->setDefaultScalingList (); |
---|
[442] | 693 | #endif |
---|
| 694 | |
---|
[313] | 695 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
| 696 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
| 697 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 698 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 699 | } |
---|
| 700 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
| 701 | { |
---|
[442] | 702 | #if IL_SL_SIGNALLING_N0371 |
---|
| 703 | pcSlice->getScalingList()->setLayerId( m_layerId ); |
---|
| 704 | #endif |
---|
| 705 | |
---|
[313] | 706 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
| 707 | { |
---|
[442] | 708 | #if IL_SL_SIGNALLING_N0371 |
---|
| 709 | pcSlice->setDefaultScalingList ( m_layerId ); |
---|
| 710 | #else |
---|
[313] | 711 | pcSlice->setDefaultScalingList (); |
---|
[442] | 712 | #endif |
---|
[313] | 713 | } |
---|
[442] | 714 | #if IL_SL_SIGNALLING_N0371 |
---|
| 715 | pcSlice->getScalingList()->checkDcOfMatrix( m_layerId ); |
---|
| 716 | #else |
---|
[313] | 717 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
[442] | 718 | #endif |
---|
[313] | 719 | m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
[442] | 720 | |
---|
| 721 | #if IL_SL_SIGNALLING_N0371 |
---|
| 722 | if( m_layerId > 0 ) |
---|
| 723 | { |
---|
| 724 | m_pcEncTop->getSPS()->setPredScalingListFlag (true); |
---|
| 725 | m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 ); |
---|
| 726 | } |
---|
| 727 | #endif |
---|
| 728 | |
---|
[313] | 729 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
[442] | 730 | |
---|
| 731 | #if IL_SL_SIGNALLING_N0371 |
---|
| 732 | if( m_layerId > 0 ) |
---|
| 733 | { |
---|
| 734 | m_pcEncTop->getPPS()->setPredScalingListFlag (false); |
---|
| 735 | m_pcEncTop->getPPS()->setScalingListRefLayerId( 0 ); |
---|
| 736 | } |
---|
| 737 | #endif |
---|
| 738 | |
---|
[313] | 739 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
| 740 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
| 741 | } |
---|
| 742 | else |
---|
| 743 | { |
---|
| 744 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
| 745 | assert(0); |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') |
---|
| 749 | { |
---|
| 750 | pcSlice->setSliceType(P_SLICE); |
---|
| 751 | } |
---|
| 752 | // Set the nal unit type |
---|
| 753 | pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR)); |
---|
| 754 | #if SVC_EXTENSION |
---|
[467] | 755 | if (m_layerId > 0) |
---|
| 756 | { |
---|
[466] | 757 | Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1]; |
---|
| 758 | Int activeNumILRRefIdxTmp = 0; |
---|
[467] | 759 | |
---|
[313] | 760 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
| 761 | { |
---|
| 762 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
| 763 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
| 764 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic(); |
---|
| 765 | #else |
---|
| 766 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic(); |
---|
| 767 | #endif |
---|
| 768 | pcSlice->setBaseColPic( *cListPic, refLayerIdc ); |
---|
| 769 | |
---|
[442] | 770 | // Apply temporal layer restriction to inter-layer prediction |
---|
[484] | 771 | #if O0225_MAX_TID_FOR_REF_LAYERS |
---|
| 772 | Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId(),m_layerId); |
---|
| 773 | #else |
---|
[442] | 774 | Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId()); |
---|
[484] | 775 | #endif |
---|
[442] | 776 | if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) ) |
---|
| 777 | { |
---|
| 778 | interLayerPredLayerIdcTmp[activeNumILRRefIdxTmp++] = refLayerIdc; // add picture to the list of valid inter-layer pictures |
---|
| 779 | } |
---|
| 780 | else |
---|
| 781 | { |
---|
| 782 | continue; // ILP is not valid due to temporal layer restriction |
---|
| 783 | } |
---|
| 784 | |
---|
[313] | 785 | const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc); |
---|
| 786 | |
---|
| 787 | Int widthBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(); |
---|
| 788 | Int heightBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(); |
---|
| 789 | |
---|
| 790 | Int widthEL = pcPic->getPicYuvRec()->getWidth() - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); |
---|
| 791 | Int heightEL = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); |
---|
| 792 | |
---|
| 793 | g_mvScalingFactor[refLayerIdc][0] = widthEL == widthBL ? 4096 : Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL); |
---|
| 794 | g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL); |
---|
| 795 | |
---|
| 796 | g_posScalingFactor[refLayerIdc][0] = ((widthBL << 16) + (widthEL >> 1)) / widthEL; |
---|
| 797 | g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL; |
---|
| 798 | |
---|
| 799 | #if SVC_UPSAMPLING |
---|
| 800 | if( pcPic->isSpatialEnhLayer(refLayerIdc)) |
---|
[442] | 801 | { |
---|
[464] | 802 | #if O0215_PHASE_ALIGNMENT |
---|
[489] | 803 | #if O0194_JOINT_US_BITSHIFT |
---|
| 804 | m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() ); |
---|
| 805 | #else |
---|
[464] | 806 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() ); |
---|
[489] | 807 | #endif |
---|
[464] | 808 | #else |
---|
[489] | 809 | #if O0194_JOINT_US_BITSHIFT |
---|
| 810 | m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) ); |
---|
| 811 | #else |
---|
[313] | 812 | m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) ); |
---|
[464] | 813 | #endif |
---|
[489] | 814 | #endif |
---|
[313] | 815 | } |
---|
| 816 | else |
---|
| 817 | { |
---|
| 818 | pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() ); |
---|
| 819 | } |
---|
| 820 | pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) ); |
---|
| 821 | #endif |
---|
| 822 | } |
---|
| 823 | |
---|
[442] | 824 | // Update the list of active inter-layer pictures |
---|
| 825 | for ( Int i = 0; i < activeNumILRRefIdxTmp; i++) |
---|
[313] | 826 | { |
---|
[442] | 827 | pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i ); |
---|
[313] | 828 | } |
---|
[442] | 829 | pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp ); |
---|
| 830 | if ( pcSlice->getActiveNumILRRefIdx() == 0 ) |
---|
| 831 | { |
---|
| 832 | // No valid inter-layer pictures -> disable inter-layer prediction |
---|
| 833 | pcSlice->setInterLayerPredEnabledFlag(false); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | if( pocCurr % m_pcCfg->getIntraPeriod() == 0 ) |
---|
| 837 | { |
---|
| 838 | #if N0147_IRAP_ALIGN_FLAG |
---|
| 839 | if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag()) |
---|
| 840 | { |
---|
| 841 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
| 842 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
| 843 | if(picLayer0) |
---|
| 844 | { |
---|
| 845 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
| 846 | } |
---|
| 847 | else |
---|
| 848 | { |
---|
| 849 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
| 850 | } |
---|
| 851 | } |
---|
| 852 | else |
---|
| 853 | #endif |
---|
| 854 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
[345] | 855 | |
---|
[442] | 856 | #if IDR_ALIGNMENT |
---|
| 857 | TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic(); |
---|
| 858 | TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() ); |
---|
| 859 | if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
| 860 | { |
---|
| 861 | pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType()); |
---|
| 862 | } |
---|
| 863 | else |
---|
| 864 | { |
---|
| 865 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); |
---|
| 866 | } |
---|
| 867 | #endif |
---|
| 868 | } |
---|
| 869 | |
---|
| 870 | if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
[313] | 871 | { |
---|
[442] | 872 | pcSlice->setSliceType(I_SLICE); |
---|
[313] | 873 | } |
---|
[442] | 874 | else if( !m_pcEncTop->getElRapSliceTypeB() ) |
---|
| 875 | { |
---|
| 876 | if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && |
---|
| 877 | (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && |
---|
| 878 | pcSlice->getSliceType() == B_SLICE ) |
---|
| 879 | { |
---|
| 880 | pcSlice->setSliceType(P_SLICE); |
---|
| 881 | } |
---|
| 882 | } |
---|
[313] | 883 | } |
---|
[442] | 884 | #endif //#if SVC_EXTENSION |
---|
[313] | 885 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 886 | { |
---|
[442] | 887 | if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R && |
---|
| 888 | !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE)) |
---|
| 889 | // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker) |
---|
[313] | 890 | { |
---|
| 891 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); |
---|
| 892 | } |
---|
| 893 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R) |
---|
| 894 | { |
---|
| 895 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N); |
---|
| 896 | } |
---|
| 897 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R) |
---|
| 898 | { |
---|
| 899 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N); |
---|
| 900 | } |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | // Do decoding refresh marking if any |
---|
| 904 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
| 905 | m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); |
---|
| 906 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
| 907 | |
---|
| 908 | #if FIX1071 |
---|
| 909 | if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) |
---|
| 910 | { |
---|
| 911 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); |
---|
| 912 | } |
---|
| 913 | #else |
---|
| 914 | if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) |
---|
| 915 | { |
---|
| 916 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS()); |
---|
| 917 | } |
---|
| 918 | #endif |
---|
| 919 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
| 920 | |
---|
| 921 | if(pcSlice->getTLayer() > 0) |
---|
| 922 | { |
---|
| 923 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) |
---|
| 924 | { |
---|
[442] | 925 | #if ALIGN_TSA_STSA_PICS |
---|
| 926 | if( pcSlice->getLayerId() > 0 ) |
---|
| 927 | { |
---|
| 928 | Bool oneRefLayerTSA = false, oneRefLayerNotTSA = false; |
---|
| 929 | for( Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
| 930 | { |
---|
| 931 | TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
| 932 | TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC()); |
---|
| 933 | if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) ) |
---|
| 934 | { |
---|
| 935 | if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) || |
---|
| 936 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R ) |
---|
| 937 | ) |
---|
| 938 | { |
---|
| 939 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 940 | { |
---|
| 941 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
| 942 | } |
---|
| 943 | else |
---|
| 944 | { |
---|
| 945 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R ); |
---|
| 946 | } |
---|
| 947 | oneRefLayerTSA = true; |
---|
| 948 | } |
---|
| 949 | else |
---|
| 950 | { |
---|
| 951 | oneRefLayerNotTSA = true; |
---|
| 952 | } |
---|
| 953 | } |
---|
| 954 | } |
---|
| 955 | assert( !( oneRefLayerNotTSA && oneRefLayerTSA ) ); // Only one variable should be true - failure of this assert means |
---|
| 956 | // that two independent reference layers that are not dependent on |
---|
| 957 | // each other, but are reference for current layer have inconsistency |
---|
| 958 | if( oneRefLayerNotTSA /*&& !oneRefLayerTSA*/ ) // No reference layer is TSA - set current as TRAIL |
---|
| 959 | { |
---|
| 960 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 961 | { |
---|
| 962 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N ); |
---|
| 963 | } |
---|
| 964 | else |
---|
| 965 | { |
---|
| 966 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R ); |
---|
| 967 | } |
---|
| 968 | } |
---|
| 969 | else // This means there is no reference layer picture for current picture in this AU |
---|
| 970 | { |
---|
| 971 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 972 | { |
---|
| 973 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
| 974 | } |
---|
| 975 | else |
---|
| 976 | { |
---|
| 977 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R ); |
---|
| 978 | } |
---|
| 979 | } |
---|
| 980 | } |
---|
| 981 | #else |
---|
[313] | 982 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 983 | { |
---|
| 984 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
| 985 | } |
---|
| 986 | else |
---|
| 987 | { |
---|
| 988 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R); |
---|
| 989 | } |
---|
[442] | 990 | #endif |
---|
[313] | 991 | } |
---|
| 992 | else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic)) |
---|
| 993 | { |
---|
| 994 | Bool isSTSA=true; |
---|
| 995 | for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++) |
---|
| 996 | { |
---|
| 997 | Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId; |
---|
| 998 | if(lTid==pcSlice->getTLayer()) |
---|
| 999 | { |
---|
| 1000 | TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii); |
---|
| 1001 | for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++) |
---|
| 1002 | { |
---|
| 1003 | if(nRPS->getUsed(jj)) |
---|
| 1004 | { |
---|
| 1005 | Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj); |
---|
| 1006 | Int kk=0; |
---|
| 1007 | for(kk=0;kk<m_pcCfg->getGOPSize();kk++) |
---|
| 1008 | { |
---|
| 1009 | if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc) |
---|
| 1010 | break; |
---|
| 1011 | } |
---|
| 1012 | Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId; |
---|
| 1013 | if(tTid >= pcSlice->getTLayer()) |
---|
| 1014 | { |
---|
| 1015 | isSTSA=false; |
---|
| 1016 | break; |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | } |
---|
| 1020 | } |
---|
| 1021 | } |
---|
| 1022 | if(isSTSA==true) |
---|
| 1023 | { |
---|
[442] | 1024 | #if ALIGN_TSA_STSA_PICS |
---|
| 1025 | if( pcSlice->getLayerId() > 0 ) |
---|
| 1026 | { |
---|
| 1027 | Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false; |
---|
| 1028 | for( Int i = 0; i < pcSlice->getLayerId(); i++) |
---|
| 1029 | { |
---|
| 1030 | TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic(); |
---|
| 1031 | TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC()); |
---|
| 1032 | if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) ) |
---|
| 1033 | { |
---|
| 1034 | if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) || |
---|
| 1035 | ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R ) |
---|
| 1036 | ) |
---|
| 1037 | { |
---|
| 1038 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 1039 | { |
---|
| 1040 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
| 1041 | } |
---|
| 1042 | else |
---|
| 1043 | { |
---|
| 1044 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R ); |
---|
| 1045 | } |
---|
| 1046 | oneRefLayerSTSA = true; |
---|
| 1047 | } |
---|
| 1048 | else |
---|
| 1049 | { |
---|
| 1050 | oneRefLayerNotSTSA = true; |
---|
| 1051 | } |
---|
| 1052 | } |
---|
| 1053 | } |
---|
| 1054 | assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means |
---|
| 1055 | // that two independent reference layers that are not dependent on |
---|
| 1056 | // each other, but are reference for current layer have inconsistency |
---|
| 1057 | if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ ) // No reference layer is STSA - set current as TRAIL |
---|
| 1058 | { |
---|
| 1059 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 1060 | { |
---|
| 1061 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N ); |
---|
| 1062 | } |
---|
| 1063 | else |
---|
| 1064 | { |
---|
| 1065 | pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R ); |
---|
| 1066 | } |
---|
| 1067 | } |
---|
| 1068 | else // This means there is no reference layer picture for current picture in this AU |
---|
| 1069 | { |
---|
| 1070 | if(pcSlice->getTemporalLayerNonReferenceFlag() ) |
---|
| 1071 | { |
---|
| 1072 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
| 1073 | } |
---|
| 1074 | else |
---|
| 1075 | { |
---|
| 1076 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R ); |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | } |
---|
| 1080 | #else |
---|
[313] | 1081 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
| 1082 | { |
---|
| 1083 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
| 1084 | } |
---|
| 1085 | else |
---|
| 1086 | { |
---|
| 1087 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R); |
---|
| 1088 | } |
---|
[442] | 1089 | #endif |
---|
[313] | 1090 | } |
---|
| 1091 | } |
---|
| 1092 | } |
---|
| 1093 | arrangeLongtermPicturesInRPS(pcSlice, rcListPic); |
---|
| 1094 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 1095 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
| 1096 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
| 1097 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
| 1098 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
| 1099 | |
---|
[442] | 1100 | #if SVC_EXTENSION |
---|
[313] | 1101 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
| 1102 | { |
---|
| 1103 | #if RESTR_CHK |
---|
[442] | 1104 | #if POC_RESET_FLAG |
---|
| 1105 | if ( pocCurr > 0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
| 1106 | #else |
---|
| 1107 | if (pcSlice->getPOC()>0 && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL()) |
---|
| 1108 | #endif |
---|
[313] | 1109 | { |
---|
| 1110 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
| 1111 | pcSlice->setActiveNumILRRefIdx(0); |
---|
| 1112 | pcSlice->setInterLayerPredEnabledFlag(0); |
---|
| 1113 | #else |
---|
| 1114 | pcSlice->setNumILRRefIdx(0); |
---|
| 1115 | #endif |
---|
| 1116 | } |
---|
| 1117 | #endif |
---|
| 1118 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
| 1119 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
| 1120 | { |
---|
| 1121 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx()); |
---|
| 1122 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx()); |
---|
| 1123 | } |
---|
| 1124 | else |
---|
| 1125 | { |
---|
| 1126 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx()); |
---|
| 1127 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx()); |
---|
| 1128 | } |
---|
| 1129 | #else |
---|
| 1130 | if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) |
---|
| 1131 | { |
---|
| 1132 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx()); |
---|
| 1133 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumILRRefIdx()); |
---|
| 1134 | } |
---|
| 1135 | else |
---|
| 1136 | { |
---|
| 1137 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getNumILRRefIdx()); |
---|
| 1138 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getNumILRRefIdx()); |
---|
| 1139 | } |
---|
| 1140 | #endif |
---|
| 1141 | } |
---|
[442] | 1142 | #endif //SVC_EXTENSION |
---|
[313] | 1143 | |
---|
| 1144 | #if ADAPTIVE_QP_SELECTION |
---|
| 1145 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
| 1146 | #endif |
---|
| 1147 | |
---|
[442] | 1148 | #if SVC_EXTENSION |
---|
[352] | 1149 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 1150 | if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
| 1151 | #else |
---|
| 1152 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
| 1153 | #endif |
---|
| 1154 | { |
---|
| 1155 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
| 1156 | } |
---|
| 1157 | |
---|
| 1158 | // Set reference list |
---|
| 1159 | if(m_layerId == 0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) ) |
---|
| 1160 | { |
---|
| 1161 | pcSlice->setRefPicList( rcListPic); |
---|
| 1162 | } |
---|
[442] | 1163 | |
---|
[313] | 1164 | if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) |
---|
| 1165 | { |
---|
[460] | 1166 | pcSlice->setILRPic( m_pcEncTop->getIlpList() ); |
---|
[313] | 1167 | #if REF_IDX_MFM |
---|
| 1168 | #if M0457_COL_PICTURE_SIGNALING |
---|
| 1169 | if( pcSlice->getMFMEnabledFlag() ) |
---|
| 1170 | #else |
---|
| 1171 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
| 1172 | #endif |
---|
| 1173 | { |
---|
| 1174 | pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic()); |
---|
[345] | 1175 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 1176 | pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice)); |
---|
| 1177 | #endif |
---|
| 1178 | } |
---|
[442] | 1179 | #else |
---|
| 1180 | // Set reference list |
---|
| 1181 | pcSlice->setRefPicList ( rcListPic ); |
---|
| 1182 | #endif //SVC_EXTENSION |
---|
[313] | 1183 | pcSlice->setRefPicListModificationSvc(); |
---|
| 1184 | pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList()); |
---|
| 1185 | |
---|
| 1186 | #if REF_IDX_MFM |
---|
| 1187 | #if M0457_COL_PICTURE_SIGNALING |
---|
[345] | 1188 | #if REMOVE_COL_PICTURE_SIGNALING |
---|
[352] | 1189 | if( pcSlice->getMFMEnabledFlag() ) |
---|
[345] | 1190 | #else |
---|
[313] | 1191 | if( pcSlice->getMFMEnabledFlag() && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) ) |
---|
[345] | 1192 | #endif |
---|
[313] | 1193 | #else |
---|
| 1194 | if( pcSlice->getSPS()->getMFMEnabledFlag() ) |
---|
| 1195 | #endif |
---|
| 1196 | { |
---|
| 1197 | Bool found = false; |
---|
| 1198 | UInt ColFromL0Flag = pcSlice->getColFromL0Flag(); |
---|
| 1199 | UInt ColRefIdx = pcSlice->getColRefIdx(); |
---|
[462] | 1200 | |
---|
[313] | 1201 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
| 1202 | { |
---|
[459] | 1203 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) |
---|
| 1204 | #if MFM_ENCCONSTRAINT |
---|
[462] | 1205 | && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true |
---|
[459] | 1206 | #endif |
---|
| 1207 | ) |
---|
[313] | 1208 | { |
---|
| 1209 | ColRefIdx = colIdx; |
---|
| 1210 | found = true; |
---|
| 1211 | break; |
---|
| 1212 | } |
---|
| 1213 | } |
---|
| 1214 | |
---|
| 1215 | if( found == false ) |
---|
| 1216 | { |
---|
| 1217 | ColFromL0Flag = 1 - ColFromL0Flag; |
---|
| 1218 | for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) |
---|
| 1219 | { |
---|
[459] | 1220 | if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) |
---|
| 1221 | #if MFM_ENCCONSTRAINT |
---|
[462] | 1222 | && pcSlice->getBaseColPic( *m_ppcTEncTop[pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->getLayerId()]->getListPic() )->checkSameRefInfo() == true |
---|
[459] | 1223 | #endif |
---|
| 1224 | ) |
---|
[313] | 1225 | { |
---|
| 1226 | ColRefIdx = colIdx; |
---|
| 1227 | found = true; |
---|
| 1228 | break; |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | if(found == true) |
---|
| 1234 | { |
---|
| 1235 | pcSlice->setColFromL0Flag(ColFromL0Flag); |
---|
| 1236 | pcSlice->setColRefIdx(ColRefIdx); |
---|
| 1237 | } |
---|
| 1238 | } |
---|
| 1239 | #endif |
---|
| 1240 | } |
---|
[442] | 1241 | #else //SVC_EXTENSION |
---|
| 1242 | // Set reference list |
---|
| 1243 | pcSlice->setRefPicList ( rcListPic ); |
---|
| 1244 | #endif //#if SVC_EXTENSION |
---|
[313] | 1245 | |
---|
| 1246 | // Slice info. refinement |
---|
| 1247 | if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) ) |
---|
| 1248 | { |
---|
| 1249 | pcSlice->setSliceType ( P_SLICE ); |
---|
| 1250 | } |
---|
| 1251 | |
---|
| 1252 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
| 1253 | if (pcSlice->getSliceType() == B_SLICE && m_pcEncTop->getIlSampleOnlyPred() == 0) |
---|
| 1254 | #else |
---|
| 1255 | if (pcSlice->getSliceType() == B_SLICE) |
---|
| 1256 | #endif |
---|
| 1257 | { |
---|
[442] | 1258 | #if !SVC_EXTENSION |
---|
[313] | 1259 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
| 1260 | #endif |
---|
| 1261 | Bool bLowDelay = true; |
---|
| 1262 | Int iCurrPOC = pcSlice->getPOC(); |
---|
| 1263 | Int iRefIdx = 0; |
---|
| 1264 | |
---|
| 1265 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
| 1266 | { |
---|
| 1267 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 1268 | { |
---|
| 1269 | bLowDelay = false; |
---|
| 1270 | } |
---|
| 1271 | } |
---|
| 1272 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
| 1273 | { |
---|
| 1274 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
| 1275 | { |
---|
| 1276 | bLowDelay = false; |
---|
| 1277 | } |
---|
| 1278 | } |
---|
| 1279 | |
---|
| 1280 | pcSlice->setCheckLDC(bLowDelay); |
---|
| 1281 | } |
---|
| 1282 | else |
---|
| 1283 | { |
---|
| 1284 | pcSlice->setCheckLDC(true); |
---|
| 1285 | } |
---|
| 1286 | |
---|
| 1287 | uiColDir = 1-uiColDir; |
---|
| 1288 | |
---|
| 1289 | //------------------------------------------------------------- |
---|
| 1290 | pcSlice->setRefPOCList(); |
---|
| 1291 | |
---|
| 1292 | pcSlice->setList1IdxToList0Idx(); |
---|
| 1293 | |
---|
| 1294 | if (m_pcEncTop->getTMVPModeId() == 2) |
---|
| 1295 | { |
---|
| 1296 | if (iGOPid == 0) // first picture in SOP (i.e. forward B) |
---|
| 1297 | { |
---|
| 1298 | pcSlice->setEnableTMVPFlag(0); |
---|
| 1299 | } |
---|
| 1300 | else |
---|
| 1301 | { |
---|
| 1302 | // Note: pcSlice->getColFromL0Flag() is assumed to be always 0 and getcolRefIdx() is always 0. |
---|
| 1303 | pcSlice->setEnableTMVPFlag(1); |
---|
| 1304 | } |
---|
| 1305 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
| 1306 | } |
---|
| 1307 | else if (m_pcEncTop->getTMVPModeId() == 1) |
---|
| 1308 | { |
---|
| 1309 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
| 1310 | #if SVC_EXTENSION |
---|
| 1311 | if( pcSlice->getIdrPicFlag() ) |
---|
| 1312 | { |
---|
| 1313 | pcSlice->setEnableTMVPFlag(0); |
---|
| 1314 | } |
---|
| 1315 | else |
---|
| 1316 | #endif |
---|
| 1317 | pcSlice->setEnableTMVPFlag(1); |
---|
| 1318 | } |
---|
| 1319 | else |
---|
| 1320 | { |
---|
| 1321 | pcSlice->getSPS()->setTMVPFlagsPresent(0); |
---|
| 1322 | pcSlice->setEnableTMVPFlag(0); |
---|
| 1323 | } |
---|
| 1324 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
| 1325 | // Slice compression |
---|
| 1326 | if (m_pcCfg->getUseASR()) |
---|
| 1327 | { |
---|
| 1328 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
| 1329 | } |
---|
| 1330 | |
---|
| 1331 | Bool bGPBcheck=false; |
---|
| 1332 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
| 1333 | { |
---|
| 1334 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 1335 | { |
---|
| 1336 | bGPBcheck=true; |
---|
| 1337 | Int i; |
---|
| 1338 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 1339 | { |
---|
| 1340 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 1341 | { |
---|
| 1342 | bGPBcheck=false; |
---|
| 1343 | break; |
---|
| 1344 | } |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | if(bGPBcheck) |
---|
| 1349 | { |
---|
| 1350 | pcSlice->setMvdL1ZeroFlag(true); |
---|
| 1351 | } |
---|
| 1352 | else |
---|
| 1353 | { |
---|
| 1354 | pcSlice->setMvdL1ZeroFlag(false); |
---|
| 1355 | } |
---|
| 1356 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
| 1357 | |
---|
| 1358 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 1359 | Double lambda = 0.0; |
---|
| 1360 | Int actualHeadBits = 0; |
---|
| 1361 | Int actualTotalBits = 0; |
---|
| 1362 | Int estimatedBits = 0; |
---|
| 1363 | Int tmpBitsBeforeWriting = 0; |
---|
| 1364 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
| 1365 | { |
---|
| 1366 | Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid ); |
---|
| 1367 | if ( pcPic->getSlice(0)->getSliceType() == I_SLICE ) |
---|
| 1368 | { |
---|
| 1369 | frameLevel = 0; |
---|
| 1370 | } |
---|
| 1371 | m_pcRateCtrl->initRCPic( frameLevel ); |
---|
| 1372 | estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); |
---|
| 1373 | |
---|
| 1374 | Int sliceQP = m_pcCfg->getInitialQP(); |
---|
[442] | 1375 | #if POC_RESET_FLAG |
---|
| 1376 | if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
| 1377 | #else |
---|
[313] | 1378 | if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
[442] | 1379 | #endif |
---|
[313] | 1380 | { |
---|
| 1381 | Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 ); |
---|
| 1382 | Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames ); |
---|
| 1383 | Double dQPFactor = 0.57*dLambda_scale; |
---|
| 1384 | Int SHIFT_QP = 12; |
---|
| 1385 | Int bitdepth_luma_qp_scale = 0; |
---|
| 1386 | Double qp_temp = (Double) sliceQP + bitdepth_luma_qp_scale - SHIFT_QP; |
---|
| 1387 | lambda = dQPFactor*pow( 2.0, qp_temp/3.0 ); |
---|
| 1388 | } |
---|
| 1389 | else if ( frameLevel == 0 ) // intra case, but use the model |
---|
| 1390 | { |
---|
| 1391 | #if RATE_CONTROL_INTRA |
---|
| 1392 | m_pcSliceEncoder->calCostSliceI(pcPic); |
---|
| 1393 | #endif |
---|
| 1394 | if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case |
---|
| 1395 | { |
---|
| 1396 | Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); |
---|
| 1397 | #if RATE_CONTROL_INTRA |
---|
| 1398 | bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); |
---|
| 1399 | #else |
---|
| 1400 | bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits ); |
---|
| 1401 | #endif |
---|
| 1402 | if ( bits < 200 ) |
---|
| 1403 | { |
---|
| 1404 | bits = 200; |
---|
| 1405 | } |
---|
| 1406 | m_pcRateCtrl->getRCPic()->setTargetBits( bits ); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
| 1410 | #if RATE_CONTROL_INTRA |
---|
| 1411 | m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); |
---|
| 1412 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
| 1413 | #else |
---|
| 1414 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
| 1415 | #endif |
---|
| 1416 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
| 1417 | } |
---|
| 1418 | else // normal case |
---|
| 1419 | { |
---|
| 1420 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
| 1421 | #if RATE_CONTROL_INTRA |
---|
| 1422 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); |
---|
| 1423 | #else |
---|
| 1424 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
| 1425 | #endif |
---|
| 1426 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
| 1427 | } |
---|
| 1428 | |
---|
[442] | 1429 | #if REPN_FORMAT_IN_VPS |
---|
| 1430 | sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
| 1431 | #else |
---|
[313] | 1432 | sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
[442] | 1433 | #endif |
---|
[313] | 1434 | m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP ); |
---|
| 1435 | |
---|
| 1436 | m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); |
---|
| 1437 | } |
---|
| 1438 | #endif |
---|
| 1439 | |
---|
| 1440 | UInt uiNumSlices = 1; |
---|
| 1441 | |
---|
| 1442 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
| 1443 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
| 1444 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1445 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[442] | 1446 | #if REPN_FORMAT_IN_VPS |
---|
| 1447 | UInt uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
| 1448 | UInt uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
| 1449 | #else |
---|
[313] | 1450 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 1451 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
[442] | 1452 | #endif |
---|
[313] | 1453 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
| 1454 | { |
---|
| 1455 | uiInternalAddress--; |
---|
| 1456 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1457 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 1458 | } |
---|
| 1459 | uiInternalAddress++; |
---|
| 1460 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
| 1461 | { |
---|
| 1462 | uiInternalAddress = 0; |
---|
| 1463 | uiExternalAddress++; |
---|
| 1464 | } |
---|
| 1465 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
| 1466 | |
---|
| 1467 | UInt uiCummulativeTileWidth; |
---|
| 1468 | UInt uiCummulativeTileHeight; |
---|
| 1469 | Int p, j; |
---|
| 1470 | UInt uiEncCUAddr; |
---|
| 1471 | |
---|
| 1472 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
| 1473 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
| 1474 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
| 1475 | |
---|
| 1476 | //create the TComTileArray |
---|
| 1477 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
| 1478 | |
---|
| 1479 | if( pcSlice->getPPS()->getUniformSpacingFlag() == 1 ) |
---|
| 1480 | { |
---|
| 1481 | //set the width for each tile |
---|
| 1482 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 1483 | { |
---|
| 1484 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
| 1485 | { |
---|
| 1486 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
| 1487 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
| 1488 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
| 1489 | } |
---|
| 1490 | } |
---|
| 1491 | |
---|
| 1492 | //set the height for each tile |
---|
| 1493 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 1494 | { |
---|
| 1495 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
| 1496 | { |
---|
| 1497 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
| 1498 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
| 1499 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
| 1500 | } |
---|
| 1501 | } |
---|
| 1502 | } |
---|
| 1503 | else |
---|
| 1504 | { |
---|
| 1505 | //set the width for each tile |
---|
| 1506 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
| 1507 | { |
---|
| 1508 | uiCummulativeTileWidth = 0; |
---|
| 1509 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
| 1510 | { |
---|
| 1511 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
| 1512 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
| 1513 | } |
---|
| 1514 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | //set the height for each tile |
---|
| 1518 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
| 1519 | { |
---|
| 1520 | uiCummulativeTileHeight = 0; |
---|
| 1521 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
| 1522 | { |
---|
| 1523 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
| 1524 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
| 1525 | } |
---|
| 1526 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
| 1527 | } |
---|
| 1528 | } |
---|
| 1529 | //intialize each tile of the current picture |
---|
| 1530 | pcPic->getPicSym()->xInitTiles(); |
---|
| 1531 | |
---|
[442] | 1532 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 1533 | if (m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled()) |
---|
| 1534 | { |
---|
| 1535 | xBuildTileSetsMap(pcPic->getPicSym()); |
---|
| 1536 | } |
---|
| 1537 | #endif |
---|
| 1538 | |
---|
[313] | 1539 | // Allocate some coders, now we know how many tiles there are. |
---|
| 1540 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
| 1541 | |
---|
| 1542 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
| 1543 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
| 1544 | { |
---|
| 1545 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
| 1546 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
| 1547 | } |
---|
| 1548 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 1549 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
| 1550 | |
---|
| 1551 | // Allocate some coders, now we know how many tiles there are. |
---|
| 1552 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
| 1553 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
| 1554 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
| 1555 | |
---|
| 1556 | UInt startCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
| 1557 | UInt startCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
| 1558 | pcSlice->setSliceCurStartCUAddr( startCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
| 1559 | m_storedStartCUAddrForEncodingSlice.clear(); |
---|
| 1560 | |
---|
| 1561 | UInt startCUAddrSliceSegmentIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
| 1562 | UInt startCUAddrSliceSegment = 0; // used to keep track of current Dependent slice's starting CU addr. |
---|
| 1563 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); // Setting "start CU addr" for current Dependent slice |
---|
| 1564 | |
---|
| 1565 | m_storedStartCUAddrForEncodingSliceSegment.clear(); |
---|
| 1566 | UInt nextCUAddr = 0; |
---|
| 1567 | m_storedStartCUAddrForEncodingSlice.push_back (nextCUAddr); |
---|
| 1568 | startCUAddrSliceIdx++; |
---|
| 1569 | m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr); |
---|
| 1570 | startCUAddrSliceSegmentIdx++; |
---|
| 1571 | #if AVC_BASE |
---|
| 1572 | if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) |
---|
| 1573 | { |
---|
| 1574 | pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() ); |
---|
[493] | 1575 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
| 1576 | // Calculate for the base layer to be used in EL as Inter layer reference |
---|
| 1577 | m_pcSliceEncoder->estimateILWpParam( pcSlice ); |
---|
| 1578 | #endif |
---|
[313] | 1579 | #if AVC_SYNTAX |
---|
| 1580 | pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES ); |
---|
| 1581 | #endif |
---|
| 1582 | return; |
---|
| 1583 | } |
---|
| 1584 | #endif |
---|
| 1585 | |
---|
| 1586 | while(nextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
| 1587 | { |
---|
| 1588 | pcSlice->setNextSlice ( false ); |
---|
| 1589 | pcSlice->setNextSliceSegment( false ); |
---|
| 1590 | assert(pcPic->getNumAllocatedSlice() == startCUAddrSliceIdx); |
---|
| 1591 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
| 1592 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
| 1593 | |
---|
| 1594 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextSliceSegment()); |
---|
| 1595 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU)) |
---|
| 1596 | { |
---|
| 1597 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 1598 | // Reconstruction slice |
---|
| 1599 | m_storedStartCUAddrForEncodingSlice.push_back(startCUAddrSlice); |
---|
| 1600 | startCUAddrSliceIdx++; |
---|
| 1601 | // Dependent slice |
---|
| 1602 | if (startCUAddrSliceSegmentIdx>0 && m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx-1] != startCUAddrSlice) |
---|
| 1603 | { |
---|
| 1604 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSlice); |
---|
| 1605 | startCUAddrSliceSegmentIdx++; |
---|
| 1606 | } |
---|
| 1607 | |
---|
| 1608 | if (startCUAddrSlice < uiRealEndAddress) |
---|
| 1609 | { |
---|
| 1610 | pcPic->allocateNewSlice(); |
---|
| 1611 | pcPic->setCurrSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
| 1612 | m_pcSliceEncoder->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
| 1613 | pcSlice = pcPic->getSlice ( startCUAddrSliceIdx-1 ); |
---|
| 1614 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
| 1615 | pcSlice->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
| 1616 | pcSlice->setSliceCurStartCUAddr ( startCUAddrSlice ); |
---|
| 1617 | pcSlice->setSliceSegmentCurStartCUAddr ( startCUAddrSlice ); |
---|
| 1618 | pcSlice->setSliceBits(0); |
---|
[467] | 1619 | #if SVC_EXTENSION |
---|
| 1620 | // copy reference list modification info from the first slice, assuming that this information is the same across all slices in the picture |
---|
| 1621 | memcpy( pcSlice->getRefPicListModification(), pcPic->getSlice(0)->getRefPicListModification(), sizeof(TComRefPicListModification) ); |
---|
| 1622 | #endif |
---|
[313] | 1623 | uiNumSlices ++; |
---|
| 1624 | } |
---|
| 1625 | } |
---|
| 1626 | else if (pcSlice->isNextSliceSegment() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)) |
---|
| 1627 | { |
---|
| 1628 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
| 1629 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSliceSegment); |
---|
| 1630 | startCUAddrSliceSegmentIdx++; |
---|
| 1631 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); |
---|
| 1632 | } |
---|
| 1633 | else |
---|
| 1634 | { |
---|
| 1635 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
| 1636 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
| 1637 | } |
---|
| 1638 | |
---|
| 1639 | nextCUAddr = (startCUAddrSlice > startCUAddrSliceSegment) ? startCUAddrSlice : startCUAddrSliceSegment; |
---|
| 1640 | } |
---|
| 1641 | m_storedStartCUAddrForEncodingSlice.push_back( pcSlice->getSliceCurEndCUAddr()); |
---|
| 1642 | startCUAddrSliceIdx++; |
---|
| 1643 | m_storedStartCUAddrForEncodingSliceSegment.push_back(pcSlice->getSliceCurEndCUAddr()); |
---|
| 1644 | startCUAddrSliceSegmentIdx++; |
---|
| 1645 | |
---|
| 1646 | pcSlice = pcPic->getSlice(0); |
---|
| 1647 | |
---|
| 1648 | // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas |
---|
| 1649 | if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) |
---|
| 1650 | { |
---|
| 1651 | m_pcSAO->resetStats(); |
---|
| 1652 | m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); |
---|
| 1653 | } |
---|
| 1654 | |
---|
| 1655 | //-- Loop filter |
---|
| 1656 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 1657 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
| 1658 | if ( m_pcCfg->getDeblockingFilterMetric() ) |
---|
| 1659 | { |
---|
| 1660 | dblMetric(pcPic, uiNumSlices); |
---|
| 1661 | } |
---|
| 1662 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 1663 | |
---|
| 1664 | pcSlice = pcPic->getSlice(0); |
---|
| 1665 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 1666 | { |
---|
| 1667 | std::vector<Bool> LFCrossSliceBoundaryFlag; |
---|
| 1668 | for(Int s=0; s< uiNumSlices; s++) |
---|
| 1669 | { |
---|
| 1670 | LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) ); |
---|
| 1671 | } |
---|
| 1672 | m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1); |
---|
| 1673 | pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
| 1674 | } |
---|
| 1675 | |
---|
| 1676 | |
---|
| 1677 | pcSlice = pcPic->getSlice(0); |
---|
| 1678 | |
---|
| 1679 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 1680 | { |
---|
| 1681 | m_pcSAO->createPicSaoInfo(pcPic); |
---|
| 1682 | } |
---|
| 1683 | |
---|
| 1684 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
| 1685 | // Set entropy coder |
---|
| 1686 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 1687 | |
---|
| 1688 | /* write various header sets. */ |
---|
| 1689 | if ( m_bSeqFirst ) |
---|
| 1690 | { |
---|
| 1691 | #if SVC_EXTENSION |
---|
[442] | 1692 | #if VPS_NUH_LAYER_ID |
---|
| 1693 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
| 1694 | #else |
---|
[313] | 1695 | OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId); |
---|
[442] | 1696 | #endif |
---|
[313] | 1697 | #if AVC_BASE |
---|
| 1698 | if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) ) |
---|
| 1699 | #else |
---|
| 1700 | if( m_layerId == 0 ) |
---|
| 1701 | #endif |
---|
| 1702 | { |
---|
| 1703 | #else |
---|
| 1704 | OutputNALUnit nalu(NAL_UNIT_VPS); |
---|
| 1705 | #endif |
---|
[461] | 1706 | #if VPS_EXTN_OFFSET_CALC |
---|
| 1707 | OutputNALUnit tempNalu(NAL_UNIT_VPS, 0, 0 ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0. |
---|
| 1708 | m_pcEntropyCoder->setBitstream(&tempNalu.m_Bitstream); |
---|
| 1709 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); // Use to calculate the VPS extension offset |
---|
| 1710 | #endif |
---|
[313] | 1711 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1712 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); |
---|
| 1713 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1714 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1715 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 1716 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 1717 | #endif |
---|
| 1718 | #if SVC_EXTENSION |
---|
| 1719 | } |
---|
| 1720 | #endif |
---|
| 1721 | |
---|
| 1722 | #if SVC_EXTENSION |
---|
| 1723 | nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId); |
---|
[442] | 1724 | #if IL_SL_SIGNALLING_N0371 |
---|
| 1725 | pcSlice->getSPS()->setVPS( pcSlice->getVPS() ); |
---|
| 1726 | #endif |
---|
[313] | 1727 | #else |
---|
| 1728 | nalu = NALUnit(NAL_UNIT_SPS); |
---|
| 1729 | #endif |
---|
| 1730 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1731 | if (m_bSeqFirst) |
---|
| 1732 | { |
---|
| 1733 | pcSlice->getSPS()->setNumLongTermRefPicSPS(m_numLongTermRefPicSPS); |
---|
| 1734 | for (Int k = 0; k < m_numLongTermRefPicSPS; k++) |
---|
| 1735 | { |
---|
| 1736 | pcSlice->getSPS()->setLtRefPicPocLsbSps(k, m_ltRefPicPocLsbSps[k]); |
---|
| 1737 | pcSlice->getSPS()->setUsedByCurrPicLtSPSFlag(k, m_ltRefPicUsedByCurrPicFlag[k]); |
---|
| 1738 | } |
---|
| 1739 | } |
---|
| 1740 | if( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
| 1741 | { |
---|
| 1742 | UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1); |
---|
| 1743 | UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 ); |
---|
| 1744 | if( pcPic->getNumCUsInFrame() % maxCU != 0 || numDU == 0 ) |
---|
| 1745 | { |
---|
| 1746 | numDU ++; |
---|
| 1747 | } |
---|
| 1748 | pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->setNumDU( numDU ); |
---|
| 1749 | pcSlice->getSPS()->setHrdParameters( m_pcCfg->getFrameRate(), numDU, m_pcCfg->getTargetBitrate(), ( m_pcCfg->getIntraPeriod() > 0 ) ); |
---|
| 1750 | } |
---|
| 1751 | if( m_pcCfg->getBufferingPeriodSEIEnabled() || m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
| 1752 | { |
---|
| 1753 | pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
| 1754 | } |
---|
| 1755 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
| 1756 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1757 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1758 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 1759 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 1760 | #endif |
---|
| 1761 | |
---|
| 1762 | #if SVC_EXTENSION |
---|
| 1763 | nalu = NALUnit(NAL_UNIT_PPS, 0, m_layerId); |
---|
| 1764 | #else |
---|
| 1765 | nalu = NALUnit(NAL_UNIT_PPS); |
---|
| 1766 | #endif |
---|
| 1767 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1768 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
| 1769 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1770 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1771 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 1772 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 1773 | #endif |
---|
| 1774 | |
---|
| 1775 | xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS()); |
---|
| 1776 | |
---|
| 1777 | m_bSeqFirst = false; |
---|
| 1778 | } |
---|
| 1779 | |
---|
| 1780 | if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP |
---|
| 1781 | { |
---|
| 1782 | Int SOPcurrPOC = pocCurr; |
---|
| 1783 | |
---|
| 1784 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 1785 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 1786 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1787 | |
---|
| 1788 | SEISOPDescription SOPDescriptionSEI; |
---|
| 1789 | SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId(); |
---|
| 1790 | |
---|
| 1791 | UInt i = 0; |
---|
| 1792 | UInt prevEntryId = iGOPid; |
---|
| 1793 | for (j = iGOPid; j < m_iGopSize; j++) |
---|
| 1794 | { |
---|
| 1795 | Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC; |
---|
| 1796 | if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded()) |
---|
| 1797 | { |
---|
| 1798 | SOPcurrPOC += deltaPOC; |
---|
| 1799 | SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR); |
---|
| 1800 | SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; |
---|
| 1801 | SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); |
---|
| 1802 | SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC; |
---|
| 1803 | |
---|
| 1804 | prevEntryId = j; |
---|
| 1805 | i++; |
---|
| 1806 | } |
---|
| 1807 | } |
---|
| 1808 | |
---|
| 1809 | SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1; |
---|
| 1810 | |
---|
| 1811 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS()); |
---|
| 1812 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1813 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1814 | |
---|
| 1815 | writeSOP = false; |
---|
| 1816 | } |
---|
| 1817 | |
---|
| 1818 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
| 1819 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 1820 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 1821 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
| 1822 | { |
---|
| 1823 | if( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) |
---|
| 1824 | { |
---|
| 1825 | UInt numDU = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumDU(); |
---|
| 1826 | pictureTimingSEI.m_numDecodingUnitsMinus1 = ( numDU - 1 ); |
---|
| 1827 | pictureTimingSEI.m_duCommonCpbRemovalDelayFlag = false; |
---|
| 1828 | |
---|
| 1829 | if( pictureTimingSEI.m_numNalusInDuMinus1 == NULL ) |
---|
| 1830 | { |
---|
| 1831 | pictureTimingSEI.m_numNalusInDuMinus1 = new UInt[ numDU ]; |
---|
| 1832 | } |
---|
| 1833 | if( pictureTimingSEI.m_duCpbRemovalDelayMinus1 == NULL ) |
---|
| 1834 | { |
---|
| 1835 | pictureTimingSEI.m_duCpbRemovalDelayMinus1 = new UInt[ numDU ]; |
---|
| 1836 | } |
---|
| 1837 | if( accumBitsDU == NULL ) |
---|
| 1838 | { |
---|
| 1839 | accumBitsDU = new UInt[ numDU ]; |
---|
| 1840 | } |
---|
| 1841 | if( accumNalsDU == NULL ) |
---|
| 1842 | { |
---|
| 1843 | accumNalsDU = new UInt[ numDU ]; |
---|
| 1844 | } |
---|
| 1845 | } |
---|
[442] | 1846 | pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the . |
---|
| 1847 | #if POC_RESET_FLAG |
---|
| 1848 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded; |
---|
| 1849 | #else |
---|
[313] | 1850 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded; |
---|
[442] | 1851 | #endif |
---|
[313] | 1852 | Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2; |
---|
| 1853 | pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
| 1854 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
| 1855 | { |
---|
| 1856 | picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
| 1857 | } |
---|
| 1858 | } |
---|
| 1859 | |
---|
| 1860 | if( ( m_pcCfg->getBufferingPeriodSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) && |
---|
| 1861 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 1862 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 1863 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
| 1864 | { |
---|
| 1865 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 1866 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 1867 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1868 | |
---|
| 1869 | SEIBufferingPeriod sei_buffering_period; |
---|
| 1870 | |
---|
| 1871 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
---|
| 1872 | sei_buffering_period.m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
| 1873 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
| 1874 | sei_buffering_period.m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
| 1875 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
| 1876 | |
---|
| 1877 | Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale(); |
---|
| 1878 | |
---|
| 1879 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
---|
| 1880 | uiInitialCpbRemovalDelay -= uiTmp; |
---|
| 1881 | uiInitialCpbRemovalDelay -= uiTmp / ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
---|
| 1882 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
| 1883 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
| 1884 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
| 1885 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
| 1886 | |
---|
| 1887 | sei_buffering_period.m_rapCpbParamsPresentFlag = 0; |
---|
| 1888 | //for the concatenation, it can be set to one during splicing. |
---|
| 1889 | sei_buffering_period.m_concatenationFlag = 0; |
---|
| 1890 | //since the temporal layer HRD is not ready, we assumed it is fixed |
---|
| 1891 | sei_buffering_period.m_auCpbRemovalDelayDelta = 1; |
---|
| 1892 | sei_buffering_period.m_cpbDelayOffset = 0; |
---|
| 1893 | sei_buffering_period.m_dpbDelayOffset = 0; |
---|
| 1894 | |
---|
| 1895 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS()); |
---|
| 1896 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1897 | { |
---|
| 1898 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
| 1899 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU; // Insert BP SEI after APS SEI |
---|
| 1900 | AccessUnit::iterator it; |
---|
| 1901 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
| 1902 | { |
---|
| 1903 | it++; |
---|
| 1904 | } |
---|
| 1905 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 1906 | m_bufferingPeriodSEIPresentInAU = true; |
---|
| 1907 | } |
---|
| 1908 | |
---|
| 1909 | if (m_pcCfg->getScalableNestingSEIEnabled()) |
---|
| 1910 | { |
---|
| 1911 | OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI); |
---|
| 1912 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 1913 | m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream); |
---|
| 1914 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
| 1915 | scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period); |
---|
| 1916 | m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
| 1917 | writeRBSPTrailingBits(naluTmp.m_Bitstream); |
---|
| 1918 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
| 1919 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU; // Insert BP SEI after non-nested APS, BP and PT SEIs |
---|
| 1920 | AccessUnit::iterator it; |
---|
| 1921 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
| 1922 | { |
---|
| 1923 | it++; |
---|
| 1924 | } |
---|
| 1925 | accessUnit.insert(it, new NALUnitEBSP(naluTmp)); |
---|
| 1926 | m_nestedBufferingPeriodSEIPresentInAU = true; |
---|
| 1927 | } |
---|
| 1928 | |
---|
| 1929 | m_lastBPSEI = m_totalCoded; |
---|
| 1930 | m_cpbRemovalDelay = 0; |
---|
| 1931 | } |
---|
| 1932 | m_cpbRemovalDelay ++; |
---|
| 1933 | if( ( m_pcEncTop->getRecoveryPointSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) ) |
---|
| 1934 | { |
---|
| 1935 | if( m_pcEncTop->getGradualDecodingRefreshInfoEnabled() && !pcSlice->getRapPicFlag() ) |
---|
| 1936 | { |
---|
| 1937 | // Gradual decoding refresh SEI |
---|
| 1938 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 1939 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 1940 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1941 | |
---|
| 1942 | SEIGradualDecodingRefreshInfo seiGradualDecodingRefreshInfo; |
---|
| 1943 | seiGradualDecodingRefreshInfo.m_gdrForegroundFlag = true; // Indicating all "foreground" |
---|
| 1944 | |
---|
| 1945 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, pcSlice->getSPS() ); |
---|
| 1946 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1947 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1948 | } |
---|
| 1949 | // Recovery point SEI |
---|
| 1950 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 1951 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 1952 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 1953 | |
---|
| 1954 | SEIRecoveryPoint sei_recovery_point; |
---|
| 1955 | sei_recovery_point.m_recoveryPocCnt = 0; |
---|
[442] | 1956 | #if POC_RESET_FLAG |
---|
| 1957 | sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false); |
---|
| 1958 | #else |
---|
[313] | 1959 | sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false); |
---|
[442] | 1960 | #endif |
---|
[313] | 1961 | sei_recovery_point.m_brokenLinkFlag = false; |
---|
| 1962 | |
---|
| 1963 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() ); |
---|
| 1964 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 1965 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 1966 | } |
---|
| 1967 | |
---|
| 1968 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
| 1969 | m_pcEntropyCoder->setBitstream(NULL); |
---|
| 1970 | |
---|
| 1971 | startCUAddrSliceIdx = 0; |
---|
| 1972 | startCUAddrSlice = 0; |
---|
| 1973 | |
---|
| 1974 | startCUAddrSliceSegmentIdx = 0; |
---|
| 1975 | startCUAddrSliceSegment = 0; |
---|
| 1976 | nextCUAddr = 0; |
---|
| 1977 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
| 1978 | |
---|
| 1979 | Int processingState = (pcSlice->getSPS()->getUseSAO())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
| 1980 | Bool skippedSlice=false; |
---|
| 1981 | while (nextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
| 1982 | { |
---|
| 1983 | switch(processingState) |
---|
| 1984 | { |
---|
| 1985 | case ENCODE_SLICE: |
---|
| 1986 | { |
---|
| 1987 | pcSlice->setNextSlice ( false ); |
---|
| 1988 | pcSlice->setNextSliceSegment( false ); |
---|
| 1989 | if (nextCUAddr == m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]) |
---|
| 1990 | { |
---|
| 1991 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
| 1992 | if(startCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
| 1993 | { |
---|
| 1994 | pcSlice->checkColRefIdx(startCUAddrSliceIdx, pcPic); |
---|
| 1995 | } |
---|
| 1996 | pcPic->setCurrSliceIdx(startCUAddrSliceIdx); |
---|
| 1997 | m_pcSliceEncoder->setSliceIdx(startCUAddrSliceIdx); |
---|
| 1998 | assert(startCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
| 1999 | // Reconstruction slice |
---|
| 2000 | pcSlice->setSliceCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 2001 | pcSlice->setSliceCurEndCUAddr ( m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx+1 ] ); |
---|
| 2002 | // Dependent slice |
---|
| 2003 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 2004 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
| 2005 | |
---|
| 2006 | pcSlice->setNextSlice ( true ); |
---|
| 2007 | |
---|
| 2008 | startCUAddrSliceIdx++; |
---|
| 2009 | startCUAddrSliceSegmentIdx++; |
---|
| 2010 | } |
---|
| 2011 | else if (nextCUAddr == m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]) |
---|
| 2012 | { |
---|
| 2013 | // Dependent slice |
---|
| 2014 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
| 2015 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
| 2016 | |
---|
| 2017 | pcSlice->setNextSliceSegment( true ); |
---|
| 2018 | |
---|
| 2019 | startCUAddrSliceSegmentIdx++; |
---|
| 2020 | } |
---|
[442] | 2021 | #if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING |
---|
[313] | 2022 | pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers()); |
---|
| 2023 | #endif |
---|
| 2024 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
| 2025 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
| 2026 | UInt uiDummyStartCUAddr; |
---|
| 2027 | UInt uiDummyBoundingCUAddr; |
---|
| 2028 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
| 2029 | |
---|
| 2030 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
| 2031 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
| 2032 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 2033 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
[442] | 2034 | |
---|
| 2035 | #if REPN_FORMAT_IN_VPS |
---|
| 2036 | uiWidth = pcSlice->getPicWidthInLumaSamples(); |
---|
| 2037 | uiHeight = pcSlice->getPicHeightInLumaSamples(); |
---|
| 2038 | #else |
---|
[313] | 2039 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
| 2040 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
[442] | 2041 | #endif |
---|
[313] | 2042 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
| 2043 | { |
---|
| 2044 | uiInternalAddress--; |
---|
| 2045 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 2046 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
| 2047 | } |
---|
| 2048 | uiInternalAddress++; |
---|
| 2049 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
| 2050 | { |
---|
| 2051 | uiInternalAddress = 0; |
---|
| 2052 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
| 2053 | } |
---|
| 2054 | UInt endAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
| 2055 | if(endAddress<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
| 2056 | { |
---|
| 2057 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
| 2058 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
| 2059 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
| 2060 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
| 2061 | if(pcSlice->isNextSlice()) |
---|
| 2062 | { |
---|
| 2063 | skippedSlice=true; |
---|
| 2064 | } |
---|
| 2065 | continue; |
---|
| 2066 | } |
---|
| 2067 | if(skippedSlice) |
---|
| 2068 | { |
---|
| 2069 | pcSlice->setNextSlice ( true ); |
---|
| 2070 | pcSlice->setNextSliceSegment( false ); |
---|
| 2071 | } |
---|
| 2072 | skippedSlice=false; |
---|
| 2073 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
| 2074 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 2075 | { |
---|
| 2076 | pcSubstreamsOut[ui].clear(); |
---|
| 2077 | } |
---|
| 2078 | |
---|
| 2079 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 2080 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2081 | /* start slice NALunit */ |
---|
| 2082 | #if SVC_EXTENSION |
---|
| 2083 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), m_layerId ); |
---|
| 2084 | #else |
---|
| 2085 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() ); |
---|
| 2086 | #endif |
---|
| 2087 | Bool sliceSegment = (!pcSlice->isNextSlice()); |
---|
| 2088 | if (!sliceSegment) |
---|
| 2089 | { |
---|
| 2090 | uiOneBitstreamPerSliceLength = 0; // start of a new slice |
---|
| 2091 | } |
---|
| 2092 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 2093 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 2094 | tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 2095 | #endif |
---|
[442] | 2096 | |
---|
[313] | 2097 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
[442] | 2098 | |
---|
[313] | 2099 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 2100 | actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
---|
| 2101 | #endif |
---|
| 2102 | |
---|
| 2103 | // is it needed? |
---|
| 2104 | { |
---|
| 2105 | if (!sliceSegment) |
---|
| 2106 | { |
---|
| 2107 | pcBitstreamRedirect->writeAlignOne(); |
---|
| 2108 | } |
---|
| 2109 | else |
---|
| 2110 | { |
---|
| 2111 | // We've not completed our slice header info yet, do the alignment later. |
---|
| 2112 | } |
---|
| 2113 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 2114 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
| 2115 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2116 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
| 2117 | { |
---|
| 2118 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 2119 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2120 | } |
---|
| 2121 | } |
---|
| 2122 | |
---|
| 2123 | if(pcSlice->isNextSlice()) |
---|
| 2124 | { |
---|
| 2125 | // set entropy coder for writing |
---|
| 2126 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
| 2127 | { |
---|
| 2128 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
| 2129 | { |
---|
| 2130 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 2131 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2132 | } |
---|
| 2133 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
| 2134 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
| 2135 | } |
---|
| 2136 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2137 | // File writing |
---|
| 2138 | if (!sliceSegment) |
---|
| 2139 | { |
---|
| 2140 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
| 2141 | } |
---|
| 2142 | else |
---|
| 2143 | { |
---|
| 2144 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 2145 | } |
---|
| 2146 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
| 2147 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
| 2148 | |
---|
| 2149 | } |
---|
| 2150 | pcSlice->setFinalized(true); |
---|
| 2151 | |
---|
| 2152 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
| 2153 | |
---|
| 2154 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
| 2155 | pcSlice->setTileLocationCount ( 0 ); |
---|
| 2156 | m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut); |
---|
| 2157 | |
---|
| 2158 | { |
---|
| 2159 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
| 2160 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
| 2161 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
| 2162 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
| 2163 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
| 2164 | if (iNumSubstreams > 1) |
---|
| 2165 | { |
---|
| 2166 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
| 2167 | } |
---|
| 2168 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 2169 | { |
---|
| 2170 | // Flush all substreams -- this includes empty ones. |
---|
| 2171 | // Terminating bit and flush. |
---|
| 2172 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
| 2173 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
| 2174 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
| 2175 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
| 2176 | |
---|
| 2177 | pcSubstreamsOut[ui].writeByteAlignment(); // Byte-alignment in slice_data() at end of sub-stream |
---|
| 2178 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
| 2179 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
| 2180 | |
---|
| 2181 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams)&& ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
| 2182 | if (bNextSubstreamInNewTile) |
---|
| 2183 | { |
---|
| 2184 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
| 2185 | } |
---|
| 2186 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
| 2187 | { |
---|
| 2188 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3); |
---|
| 2189 | } |
---|
| 2190 | } |
---|
| 2191 | |
---|
| 2192 | // Complete the slice header info. |
---|
| 2193 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 2194 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
| 2195 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
| 2196 | |
---|
| 2197 | // Substreams... |
---|
| 2198 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
| 2199 | Int offs = 0; |
---|
| 2200 | Int nss = pcSlice->getPPS()->getNumSubstreams(); |
---|
| 2201 | if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
| 2202 | { |
---|
| 2203 | // 1st line present for WPP. |
---|
| 2204 | offs = pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()/pcSlice->getPic()->getFrameWidthInCU(); |
---|
| 2205 | nss = pcSlice->getNumEntryPointOffsets()+1; |
---|
| 2206 | } |
---|
| 2207 | for ( UInt ui = 0 ; ui < nss; ui++ ) |
---|
| 2208 | { |
---|
| 2209 | pcOut->addSubstream(&pcSubstreamsOut[ui+offs]); |
---|
| 2210 | } |
---|
| 2211 | } |
---|
| 2212 | |
---|
| 2213 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
| 2214 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
| 2215 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
| 2216 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
| 2217 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple dependent slices) then buffer it. |
---|
| 2218 | // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list. |
---|
| 2219 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
| 2220 | xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); |
---|
| 2221 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 2222 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 2223 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
| 2224 | #endif |
---|
| 2225 | bNALUAlignedWrittenToList = true; |
---|
| 2226 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
| 2227 | |
---|
| 2228 | if (!bNALUAlignedWrittenToList) |
---|
| 2229 | { |
---|
| 2230 | { |
---|
| 2231 | nalu.m_Bitstream.writeAlignZero(); |
---|
| 2232 | } |
---|
| 2233 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
| 2234 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
| 2235 | } |
---|
| 2236 | |
---|
| 2237 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
| 2238 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 2239 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 2240 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) && |
---|
| 2241 | ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) ) |
---|
| 2242 | { |
---|
| 2243 | UInt numNalus = 0; |
---|
| 2244 | UInt numRBSPBytes = 0; |
---|
| 2245 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 2246 | { |
---|
| 2247 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
| 2248 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
| 2249 | { |
---|
| 2250 | numRBSPBytes += numRBSPBytes_nal; |
---|
| 2251 | numNalus ++; |
---|
| 2252 | } |
---|
| 2253 | } |
---|
| 2254 | accumBitsDU[ pcSlice->getSliceIdx() ] = ( numRBSPBytes << 3 ); |
---|
| 2255 | accumNalsDU[ pcSlice->getSliceIdx() ] = numNalus; // SEI not counted for bit count; hence shouldn't be counted for # of NALUs - only for consistency |
---|
| 2256 | } |
---|
| 2257 | processingState = ENCODE_SLICE; |
---|
| 2258 | } |
---|
| 2259 | break; |
---|
| 2260 | case EXECUTE_INLOOPFILTER: |
---|
| 2261 | { |
---|
| 2262 | // set entropy coder for RD |
---|
| 2263 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
| 2264 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
| 2265 | { |
---|
| 2266 | m_pcEntropyCoder->resetEntropy(); |
---|
| 2267 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
| 2268 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); |
---|
| 2269 | SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
| 2270 | |
---|
| 2271 | #if SAO_CHROMA_LAMBDA |
---|
| 2272 | #if SAO_ENCODING_CHOICE |
---|
| 2273 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); |
---|
| 2274 | #else |
---|
| 2275 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
| 2276 | #endif |
---|
| 2277 | #else |
---|
| 2278 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); |
---|
| 2279 | #endif |
---|
| 2280 | m_pcSAO->endSaoEnc(); |
---|
| 2281 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
| 2282 | } |
---|
| 2283 | #if SAO_RDO |
---|
| 2284 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
| 2285 | #endif |
---|
| 2286 | processingState = ENCODE_SLICE; |
---|
| 2287 | |
---|
| 2288 | for(Int s=0; s< uiNumSlices; s++) |
---|
| 2289 | { |
---|
| 2290 | if (pcSlice->getSPS()->getUseSAO()) |
---|
| 2291 | { |
---|
| 2292 | pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
| 2293 | } |
---|
| 2294 | } |
---|
| 2295 | } |
---|
| 2296 | break; |
---|
| 2297 | default: |
---|
| 2298 | { |
---|
| 2299 | printf("Not a supported encoding state\n"); |
---|
| 2300 | assert(0); |
---|
| 2301 | exit(-1); |
---|
| 2302 | } |
---|
| 2303 | } |
---|
| 2304 | } // end iteration over slices |
---|
| 2305 | |
---|
| 2306 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 2307 | { |
---|
| 2308 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 2309 | { |
---|
| 2310 | m_pcSAO->destroyPicSaoInfo(); |
---|
| 2311 | } |
---|
| 2312 | pcPic->destroyNonDBFilterInfo(); |
---|
| 2313 | } |
---|
| 2314 | |
---|
| 2315 | pcPic->compressMotion(); |
---|
| 2316 | |
---|
| 2317 | //-- For time output for each slice |
---|
| 2318 | Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 2319 | |
---|
| 2320 | const Char* digestStr = NULL; |
---|
| 2321 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
| 2322 | { |
---|
| 2323 | /* calculate MD5sum for entire reconstructed picture */ |
---|
| 2324 | SEIDecodedPictureHash sei_recon_picture_digest; |
---|
| 2325 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
| 2326 | { |
---|
| 2327 | sei_recon_picture_digest.method = SEIDecodedPictureHash::MD5; |
---|
| 2328 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
| 2329 | digestStr = digestToString(sei_recon_picture_digest.digest, 16); |
---|
| 2330 | } |
---|
| 2331 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
| 2332 | { |
---|
| 2333 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CRC; |
---|
| 2334 | calcCRC(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
| 2335 | digestStr = digestToString(sei_recon_picture_digest.digest, 2); |
---|
| 2336 | } |
---|
| 2337 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
| 2338 | { |
---|
| 2339 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CHECKSUM; |
---|
| 2340 | calcChecksum(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
| 2341 | digestStr = digestToString(sei_recon_picture_digest.digest, 4); |
---|
| 2342 | } |
---|
| 2343 | #if SVC_EXTENSION |
---|
| 2344 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId); |
---|
| 2345 | #else |
---|
| 2346 | OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer()); |
---|
| 2347 | #endif |
---|
| 2348 | |
---|
| 2349 | /* write the SEI messages */ |
---|
| 2350 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 2351 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, pcSlice->getSPS()); |
---|
| 2352 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2353 | |
---|
| 2354 | accessUnit.insert(accessUnit.end(), new NALUnitEBSP(nalu)); |
---|
| 2355 | } |
---|
| 2356 | if (m_pcCfg->getTemporalLevel0IndexSEIEnabled()) |
---|
| 2357 | { |
---|
| 2358 | SEITemporalLevel0Index sei_temporal_level0_index; |
---|
| 2359 | if (pcSlice->getRapPicFlag()) |
---|
| 2360 | { |
---|
| 2361 | m_tl0Idx = 0; |
---|
| 2362 | m_rapIdx = (m_rapIdx + 1) & 0xFF; |
---|
| 2363 | } |
---|
| 2364 | else |
---|
| 2365 | { |
---|
| 2366 | m_tl0Idx = (m_tl0Idx + (pcSlice->getTLayer() ? 0 : 1)) & 0xFF; |
---|
| 2367 | } |
---|
| 2368 | sei_temporal_level0_index.tl0Idx = m_tl0Idx; |
---|
| 2369 | sei_temporal_level0_index.rapIdx = m_rapIdx; |
---|
| 2370 | |
---|
| 2371 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); |
---|
| 2372 | |
---|
| 2373 | /* write the SEI messages */ |
---|
| 2374 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 2375 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, pcSlice->getSPS()); |
---|
| 2376 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2377 | |
---|
| 2378 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
| 2379 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
| 2380 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 2381 | } |
---|
| 2382 | |
---|
| 2383 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
| 2384 | |
---|
[442] | 2385 | //In case of field coding, compute the interlaced PSNR for both fields |
---|
| 2386 | if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff))) |
---|
| 2387 | { |
---|
| 2388 | //get complementary top field |
---|
| 2389 | TComPic* pcPicTop; |
---|
| 2390 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 2391 | while ((*iterPic)->getPOC() != pcPic->getPOC()-1) |
---|
| 2392 | { |
---|
| 2393 | iterPic ++; |
---|
| 2394 | } |
---|
| 2395 | pcPicTop = *(iterPic); |
---|
| 2396 | xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
| 2397 | } |
---|
| 2398 | |
---|
[313] | 2399 | if (digestStr) |
---|
| 2400 | { |
---|
| 2401 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
| 2402 | { |
---|
| 2403 | printf(" [MD5:%s]", digestStr); |
---|
| 2404 | } |
---|
| 2405 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
| 2406 | { |
---|
| 2407 | printf(" [CRC:%s]", digestStr); |
---|
| 2408 | } |
---|
| 2409 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
| 2410 | { |
---|
| 2411 | printf(" [Checksum:%s]", digestStr); |
---|
| 2412 | } |
---|
| 2413 | } |
---|
| 2414 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 2415 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
| 2416 | { |
---|
| 2417 | #if !M0036_RC_IMPROVEMENT |
---|
| 2418 | Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage(); |
---|
| 2419 | #endif |
---|
| 2420 | Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); |
---|
| 2421 | Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); |
---|
| 2422 | if ( avgLambda < 0.0 ) |
---|
| 2423 | { |
---|
| 2424 | avgLambda = lambda; |
---|
| 2425 | } |
---|
| 2426 | #if M0036_RC_IMPROVEMENT |
---|
| 2427 | #if RATE_CONTROL_INTRA |
---|
| 2428 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); |
---|
| 2429 | #else |
---|
| 2430 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda ); |
---|
| 2431 | #endif |
---|
| 2432 | #else |
---|
| 2433 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage ); |
---|
| 2434 | #endif |
---|
| 2435 | m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); |
---|
| 2436 | |
---|
| 2437 | m_pcRateCtrl->getRCSeq()->updateAfterPic( actualTotalBits ); |
---|
| 2438 | if ( pcSlice->getSliceType() != I_SLICE ) |
---|
| 2439 | { |
---|
| 2440 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( actualTotalBits ); |
---|
| 2441 | } |
---|
| 2442 | else // for intra picture, the estimated bits are used to update the current status in the GOP |
---|
| 2443 | { |
---|
| 2444 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); |
---|
| 2445 | } |
---|
| 2446 | } |
---|
| 2447 | #else |
---|
| 2448 | if(m_pcCfg->getUseRateCtrl()) |
---|
| 2449 | { |
---|
| 2450 | UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1]; |
---|
| 2451 | m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType()); |
---|
| 2452 | } |
---|
| 2453 | #endif |
---|
| 2454 | |
---|
| 2455 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
| 2456 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
| 2457 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
| 2458 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
| 2459 | { |
---|
| 2460 | TComVUI *vui = pcSlice->getSPS()->getVuiParameters(); |
---|
| 2461 | TComHRD *hrd = vui->getHrdParameters(); |
---|
| 2462 | |
---|
| 2463 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 2464 | { |
---|
| 2465 | Int i; |
---|
| 2466 | UInt64 ui64Tmp; |
---|
| 2467 | UInt uiPrev = 0; |
---|
| 2468 | UInt numDU = ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); |
---|
| 2469 | UInt *pCRD = &pictureTimingSEI.m_duCpbRemovalDelayMinus1[0]; |
---|
| 2470 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
| 2471 | |
---|
| 2472 | for( i = 0; i < numDU; i ++ ) |
---|
| 2473 | { |
---|
| 2474 | pictureTimingSEI.m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( accumNalsDU[ i ] - 1 ) : ( accumNalsDU[ i ] - accumNalsDU[ i - 1] - 1 ); |
---|
| 2475 | } |
---|
| 2476 | |
---|
| 2477 | if( numDU == 1 ) |
---|
| 2478 | { |
---|
| 2479 | pCRD[ 0 ] = 0; /* don't care */ |
---|
| 2480 | } |
---|
| 2481 | else |
---|
| 2482 | { |
---|
| 2483 | pCRD[ numDU - 1 ] = 0;/* by definition */ |
---|
| 2484 | UInt tmp = 0; |
---|
| 2485 | UInt accum = 0; |
---|
| 2486 | |
---|
| 2487 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 2488 | { |
---|
| 2489 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 2490 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 2491 | { |
---|
| 2492 | tmp ++; |
---|
| 2493 | } |
---|
| 2494 | } |
---|
| 2495 | uiPrev = 0; |
---|
| 2496 | |
---|
| 2497 | UInt flag = 0; |
---|
| 2498 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
| 2499 | { |
---|
| 2500 | flag = 0; |
---|
| 2501 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
| 2502 | |
---|
| 2503 | if( (UInt)ui64Tmp > maxDiff ) |
---|
| 2504 | { |
---|
| 2505 | if(uiPrev >= maxDiff - tmp) |
---|
| 2506 | { |
---|
| 2507 | ui64Tmp = uiPrev + 1; |
---|
| 2508 | flag = 1; |
---|
| 2509 | } |
---|
| 2510 | else ui64Tmp = maxDiff - tmp + 1; |
---|
| 2511 | } |
---|
| 2512 | pCRD[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
| 2513 | if( (Int)pCRD[ i ] < 0 ) |
---|
| 2514 | { |
---|
| 2515 | pCRD[ i ] = 0; |
---|
| 2516 | } |
---|
| 2517 | else if (tmp > 0 && flag == 1) |
---|
| 2518 | { |
---|
| 2519 | tmp --; |
---|
| 2520 | } |
---|
| 2521 | accum += pCRD[ i ] + 1; |
---|
| 2522 | uiPrev = accum; |
---|
| 2523 | } |
---|
| 2524 | } |
---|
| 2525 | } |
---|
| 2526 | if( m_pcCfg->getPictureTimingSEIEnabled() ) |
---|
| 2527 | { |
---|
| 2528 | { |
---|
| 2529 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
| 2530 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
[442] | 2531 | pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0; |
---|
[313] | 2532 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS()); |
---|
| 2533 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2534 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
| 2535 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
| 2536 | + m_bufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
| 2537 | AccessUnit::iterator it; |
---|
| 2538 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
| 2539 | { |
---|
| 2540 | it++; |
---|
| 2541 | } |
---|
| 2542 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 2543 | m_pictureTimingSEIPresentInAU = true; |
---|
| 2544 | } |
---|
| 2545 | if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI |
---|
| 2546 | { |
---|
| 2547 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
| 2548 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 2549 | scalableNestingSEI.m_nestedSEIs.clear(); |
---|
| 2550 | scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI); |
---|
| 2551 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); |
---|
| 2552 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2553 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
| 2554 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
| 2555 | + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
| 2556 | AccessUnit::iterator it; |
---|
| 2557 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
| 2558 | { |
---|
| 2559 | it++; |
---|
| 2560 | } |
---|
| 2561 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 2562 | m_nestedPictureTimingSEIPresentInAU = true; |
---|
| 2563 | } |
---|
| 2564 | } |
---|
| 2565 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 2566 | { |
---|
| 2567 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
| 2568 | for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ ) |
---|
| 2569 | { |
---|
| 2570 | OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); |
---|
| 2571 | |
---|
| 2572 | SEIDecodingUnitInfo tempSEI; |
---|
| 2573 | tempSEI.m_decodingUnitIdx = i; |
---|
| 2574 | tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1; |
---|
| 2575 | tempSEI.m_dpbOutputDuDelayPresentFlag = false; |
---|
| 2576 | tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay; |
---|
| 2577 | |
---|
| 2578 | AccessUnit::iterator it; |
---|
| 2579 | // Insert the first one in the right location, before the first slice |
---|
| 2580 | if(i == 0) |
---|
| 2581 | { |
---|
| 2582 | // Insert before the first slice. |
---|
| 2583 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
| 2584 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2585 | |
---|
| 2586 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
| 2587 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
| 2588 | + m_bufferingPeriodSEIPresentInAU |
---|
| 2589 | + m_pictureTimingSEIPresentInAU; // Insert DU info SEI after APS, BP and PT SEI |
---|
| 2590 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
| 2591 | { |
---|
| 2592 | it++; |
---|
| 2593 | } |
---|
| 2594 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 2595 | } |
---|
| 2596 | else |
---|
| 2597 | { |
---|
| 2598 | Int ctr; |
---|
| 2599 | // For the second decoding unit onwards we know how many NALUs are present |
---|
| 2600 | for (ctr = 0, it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 2601 | { |
---|
| 2602 | if(ctr == accumNalsDU[ i - 1 ]) |
---|
| 2603 | { |
---|
| 2604 | // Insert before the first slice. |
---|
| 2605 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
| 2606 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
| 2607 | |
---|
| 2608 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
| 2609 | break; |
---|
| 2610 | } |
---|
| 2611 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
| 2612 | { |
---|
| 2613 | ctr++; |
---|
| 2614 | } |
---|
| 2615 | } |
---|
| 2616 | } |
---|
| 2617 | } |
---|
| 2618 | } |
---|
| 2619 | } |
---|
| 2620 | xResetNonNestedSEIPresentFlags(); |
---|
| 2621 | xResetNestedSEIPresentFlags(); |
---|
| 2622 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
| 2623 | |
---|
| 2624 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
| 2625 | pcPicYuvRecOut->setReconstructed(true); |
---|
| 2626 | #endif |
---|
| 2627 | |
---|
| 2628 | pcPic->setReconMark ( true ); |
---|
| 2629 | m_bFirst = false; |
---|
| 2630 | m_iNumPicCoded++; |
---|
| 2631 | m_totalCoded ++; |
---|
| 2632 | /* logging: insert a newline at end of picture period */ |
---|
| 2633 | printf("\n"); |
---|
| 2634 | fflush(stdout); |
---|
| 2635 | |
---|
| 2636 | delete[] pcSubstreamsOut; |
---|
| 2637 | } |
---|
| 2638 | #if !RATE_CONTROL_LAMBDA_DOMAIN |
---|
| 2639 | if(m_pcCfg->getUseRateCtrl()) |
---|
| 2640 | { |
---|
| 2641 | m_pcRateCtrl->updateRCGOPStatus(); |
---|
| 2642 | } |
---|
| 2643 | #endif |
---|
| 2644 | delete pcBitstreamRedirect; |
---|
| 2645 | |
---|
| 2646 | if( accumBitsDU != NULL) delete accumBitsDU; |
---|
| 2647 | if( accumNalsDU != NULL) delete accumNalsDU; |
---|
| 2648 | |
---|
| 2649 | #if SVC_EXTENSION |
---|
[442] | 2650 | assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) ); |
---|
[313] | 2651 | #else |
---|
[442] | 2652 | assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) ); |
---|
[313] | 2653 | #endif |
---|
| 2654 | } |
---|
| 2655 | |
---|
| 2656 | #if !SVC_EXTENSION |
---|
[442] | 2657 | Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField) |
---|
[313] | 2658 | { |
---|
| 2659 | assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic()); |
---|
| 2660 | |
---|
| 2661 | |
---|
| 2662 | //--CFG_KDY |
---|
[442] | 2663 | if(isField) |
---|
| 2664 | { |
---|
| 2665 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
| 2666 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
| 2667 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
| 2668 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2); |
---|
| 2669 | } |
---|
| 2670 | else |
---|
| 2671 | { |
---|
| 2672 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
| 2673 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
| 2674 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
| 2675 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
| 2676 | } |
---|
[313] | 2677 | |
---|
| 2678 | //-- all |
---|
| 2679 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
| 2680 | m_gcAnalyzeAll.printOut('a'); |
---|
| 2681 | |
---|
| 2682 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
| 2683 | m_gcAnalyzeI.printOut('i'); |
---|
| 2684 | |
---|
| 2685 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
| 2686 | m_gcAnalyzeP.printOut('p'); |
---|
| 2687 | |
---|
| 2688 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
| 2689 | m_gcAnalyzeB.printOut('b'); |
---|
| 2690 | |
---|
| 2691 | #if _SUMMARY_OUT_ |
---|
| 2692 | m_gcAnalyzeAll.printSummaryOut(); |
---|
| 2693 | #endif |
---|
| 2694 | #if _SUMMARY_PIC_ |
---|
| 2695 | m_gcAnalyzeI.printSummary('I'); |
---|
| 2696 | m_gcAnalyzeP.printSummary('P'); |
---|
| 2697 | m_gcAnalyzeB.printSummary('B'); |
---|
| 2698 | #endif |
---|
| 2699 | |
---|
[442] | 2700 | if(isField) |
---|
| 2701 | { |
---|
| 2702 | //-- interlaced summary |
---|
| 2703 | m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate()); |
---|
| 2704 | printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" ); |
---|
| 2705 | m_gcAnalyzeAll_in.printOutInterlaced('a', m_gcAnalyzeAll.getBits()); |
---|
| 2706 | |
---|
| 2707 | #if _SUMMARY_OUT_ |
---|
| 2708 | m_gcAnalyzeAll_in.printSummaryOutInterlaced(); |
---|
| 2709 | #endif |
---|
| 2710 | } |
---|
| 2711 | |
---|
[313] | 2712 | printf("\nRVM: %.3lf\n" , xCalculateRVM()); |
---|
| 2713 | } |
---|
| 2714 | #endif |
---|
| 2715 | |
---|
| 2716 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
| 2717 | { |
---|
| 2718 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
| 2719 | Bool bCalcDist = false; |
---|
| 2720 | m_pcLoopFilter->setCfg(m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
| 2721 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 2722 | |
---|
| 2723 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
| 2724 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2725 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
| 2726 | pcSlice = pcPic->getSlice(0); |
---|
| 2727 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 2728 | { |
---|
| 2729 | std::vector<Bool> LFCrossSliceBoundaryFlag(1, true); |
---|
| 2730 | std::vector<Int> sliceStartAddress; |
---|
| 2731 | sliceStartAddress.push_back(0); |
---|
| 2732 | sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU()); |
---|
| 2733 | pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag); |
---|
| 2734 | } |
---|
| 2735 | |
---|
| 2736 | if( pcSlice->getSPS()->getUseSAO()) |
---|
| 2737 | { |
---|
| 2738 | pcPic->destroyNonDBFilterInfo(); |
---|
| 2739 | } |
---|
| 2740 | |
---|
| 2741 | m_pcEntropyCoder->resetEntropy (); |
---|
| 2742 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
| 2743 | |
---|
| 2744 | if (!bCalcDist) |
---|
| 2745 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
| 2746 | } |
---|
| 2747 | |
---|
| 2748 | // ==================================================================================================================== |
---|
| 2749 | // Protected member functions |
---|
| 2750 | // ==================================================================================================================== |
---|
| 2751 | |
---|
[442] | 2752 | |
---|
| 2753 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField ) |
---|
| 2754 | { |
---|
| 2755 | assert( iNumPicRcvd > 0 ); |
---|
| 2756 | // Exception for the first frames |
---|
| 2757 | if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField && (iPOCLast == 0)) ) |
---|
| 2758 | { |
---|
| 2759 | m_iGopSize = 1; |
---|
| 2760 | } |
---|
| 2761 | else |
---|
| 2762 | { |
---|
| 2763 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
| 2764 | } |
---|
| 2765 | assert (m_iGopSize > 0); |
---|
| 2766 | |
---|
| 2767 | return; |
---|
| 2768 | } |
---|
| 2769 | |
---|
[313] | 2770 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
| 2771 | { |
---|
| 2772 | assert( iNumPicRcvd > 0 ); |
---|
| 2773 | // Exception for the first frame |
---|
| 2774 | if ( iPOCLast == 0 ) |
---|
| 2775 | { |
---|
| 2776 | m_iGopSize = 1; |
---|
| 2777 | } |
---|
| 2778 | else |
---|
| 2779 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
| 2780 | |
---|
| 2781 | assert (m_iGopSize > 0); |
---|
| 2782 | |
---|
| 2783 | return; |
---|
| 2784 | } |
---|
| 2785 | |
---|
| 2786 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
| 2787 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
| 2788 | Int iNumPicRcvd, |
---|
| 2789 | Int iTimeOffset, |
---|
| 2790 | TComPic*& rpcPic, |
---|
| 2791 | TComPicYuv*& rpcPicYuvRecOut, |
---|
[442] | 2792 | Int pocCurr, |
---|
| 2793 | Bool isField) |
---|
[313] | 2794 | { |
---|
| 2795 | Int i; |
---|
| 2796 | // Rec. output |
---|
| 2797 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
[442] | 2798 | |
---|
| 2799 | if (isField) |
---|
[313] | 2800 | { |
---|
[442] | 2801 | for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ ) |
---|
| 2802 | { |
---|
| 2803 | iterPicYuvRec--; |
---|
| 2804 | } |
---|
[313] | 2805 | } |
---|
[442] | 2806 | else |
---|
| 2807 | { |
---|
| 2808 | for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ ) |
---|
| 2809 | { |
---|
| 2810 | iterPicYuvRec--; |
---|
| 2811 | } |
---|
| 2812 | } |
---|
[313] | 2813 | |
---|
[442] | 2814 | if (isField) |
---|
| 2815 | { |
---|
| 2816 | if(pocCurr == 1) |
---|
| 2817 | { |
---|
| 2818 | iterPicYuvRec++; |
---|
| 2819 | } |
---|
| 2820 | } |
---|
[313] | 2821 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
| 2822 | |
---|
| 2823 | // Current pic. |
---|
| 2824 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 2825 | while (iterPic != rcListPic.end()) |
---|
| 2826 | { |
---|
| 2827 | rpcPic = *(iterPic); |
---|
| 2828 | rpcPic->setCurrSliceIdx(0); |
---|
| 2829 | if (rpcPic->getPOC() == pocCurr) |
---|
| 2830 | { |
---|
| 2831 | break; |
---|
| 2832 | } |
---|
| 2833 | iterPic++; |
---|
| 2834 | } |
---|
| 2835 | |
---|
| 2836 | assert( rpcPic != NULL ); |
---|
| 2837 | assert( rpcPic->getPOC() == pocCurr ); |
---|
| 2838 | |
---|
| 2839 | return; |
---|
| 2840 | } |
---|
| 2841 | |
---|
| 2842 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
| 2843 | { |
---|
| 2844 | Int x, y; |
---|
| 2845 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
| 2846 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
| 2847 | UInt uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8); |
---|
| 2848 | Int iTemp; |
---|
| 2849 | |
---|
| 2850 | Int iStride = pcPic0->getStride(); |
---|
| 2851 | Int iWidth = pcPic0->getWidth(); |
---|
| 2852 | Int iHeight = pcPic0->getHeight(); |
---|
| 2853 | |
---|
| 2854 | UInt64 uiTotalDiff = 0; |
---|
| 2855 | |
---|
| 2856 | for( y = 0; y < iHeight; y++ ) |
---|
| 2857 | { |
---|
| 2858 | for( x = 0; x < iWidth; x++ ) |
---|
| 2859 | { |
---|
| 2860 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 2861 | } |
---|
| 2862 | pSrc0 += iStride; |
---|
| 2863 | pSrc1 += iStride; |
---|
| 2864 | } |
---|
| 2865 | |
---|
| 2866 | uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); |
---|
| 2867 | iHeight >>= 1; |
---|
| 2868 | iWidth >>= 1; |
---|
| 2869 | iStride >>= 1; |
---|
| 2870 | |
---|
| 2871 | pSrc0 = pcPic0->getCbAddr(); |
---|
| 2872 | pSrc1 = pcPic1->getCbAddr(); |
---|
| 2873 | |
---|
| 2874 | for( y = 0; y < iHeight; y++ ) |
---|
| 2875 | { |
---|
| 2876 | for( x = 0; x < iWidth; x++ ) |
---|
| 2877 | { |
---|
| 2878 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 2879 | } |
---|
| 2880 | pSrc0 += iStride; |
---|
| 2881 | pSrc1 += iStride; |
---|
| 2882 | } |
---|
| 2883 | |
---|
| 2884 | pSrc0 = pcPic0->getCrAddr(); |
---|
| 2885 | pSrc1 = pcPic1->getCrAddr(); |
---|
| 2886 | |
---|
| 2887 | for( y = 0; y < iHeight; y++ ) |
---|
| 2888 | { |
---|
| 2889 | for( x = 0; x < iWidth; x++ ) |
---|
| 2890 | { |
---|
| 2891 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
| 2892 | } |
---|
| 2893 | pSrc0 += iStride; |
---|
| 2894 | pSrc1 += iStride; |
---|
| 2895 | } |
---|
| 2896 | |
---|
| 2897 | return uiTotalDiff; |
---|
| 2898 | } |
---|
| 2899 | |
---|
| 2900 | #if VERBOSE_RATE |
---|
| 2901 | static const Char* nalUnitTypeToString(NalUnitType type) |
---|
| 2902 | { |
---|
| 2903 | switch (type) |
---|
| 2904 | { |
---|
[442] | 2905 | case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; |
---|
| 2906 | case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; |
---|
[313] | 2907 | case NAL_UNIT_CODED_SLICE_TLA_R: return "TLA_R"; |
---|
[442] | 2908 | case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; |
---|
| 2909 | case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; |
---|
| 2910 | case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N"; |
---|
[313] | 2911 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: return "BLA_W_LP"; |
---|
| 2912 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL"; |
---|
[442] | 2913 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP"; |
---|
[313] | 2914 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL"; |
---|
[442] | 2915 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP"; |
---|
| 2916 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
[313] | 2917 | case NAL_UNIT_CODED_SLICE_RADL_R: return "RADL_R"; |
---|
| 2918 | case NAL_UNIT_CODED_SLICE_RASL_R: return "RASL_R"; |
---|
[442] | 2919 | case NAL_UNIT_VPS: return "VPS"; |
---|
| 2920 | case NAL_UNIT_SPS: return "SPS"; |
---|
| 2921 | case NAL_UNIT_PPS: return "PPS"; |
---|
| 2922 | case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD"; |
---|
| 2923 | case NAL_UNIT_EOS: return "EOS"; |
---|
| 2924 | case NAL_UNIT_EOB: return "EOB"; |
---|
| 2925 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
[313] | 2926 | case NAL_UNIT_PREFIX_SEI: return "SEI"; |
---|
| 2927 | case NAL_UNIT_SUFFIX_SEI: return "SEI"; |
---|
[442] | 2928 | default: return "UNK"; |
---|
[313] | 2929 | } |
---|
| 2930 | } |
---|
| 2931 | #endif |
---|
| 2932 | |
---|
| 2933 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
| 2934 | { |
---|
| 2935 | Int x, y; |
---|
| 2936 | UInt64 uiSSDY = 0; |
---|
| 2937 | UInt64 uiSSDU = 0; |
---|
| 2938 | UInt64 uiSSDV = 0; |
---|
| 2939 | |
---|
| 2940 | Double dYPSNR = 0.0; |
---|
| 2941 | Double dUPSNR = 0.0; |
---|
| 2942 | Double dVPSNR = 0.0; |
---|
| 2943 | |
---|
| 2944 | //===== calculate PSNR ===== |
---|
| 2945 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
| 2946 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
| 2947 | Int iStride = pcPicD->getStride(); |
---|
| 2948 | |
---|
| 2949 | Int iWidth; |
---|
| 2950 | Int iHeight; |
---|
| 2951 | |
---|
| 2952 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
| 2953 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
| 2954 | |
---|
| 2955 | Int iSize = iWidth*iHeight; |
---|
| 2956 | |
---|
| 2957 | for( y = 0; y < iHeight; y++ ) |
---|
| 2958 | { |
---|
| 2959 | for( x = 0; x < iWidth; x++ ) |
---|
| 2960 | { |
---|
| 2961 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2962 | uiSSDY += iDiff * iDiff; |
---|
| 2963 | } |
---|
| 2964 | pOrg += iStride; |
---|
| 2965 | pRec += iStride; |
---|
| 2966 | } |
---|
| 2967 | |
---|
| 2968 | iHeight >>= 1; |
---|
| 2969 | iWidth >>= 1; |
---|
| 2970 | iStride >>= 1; |
---|
| 2971 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
| 2972 | pRec = pcPicD->getCbAddr(); |
---|
| 2973 | |
---|
| 2974 | for( y = 0; y < iHeight; y++ ) |
---|
| 2975 | { |
---|
| 2976 | for( x = 0; x < iWidth; x++ ) |
---|
| 2977 | { |
---|
| 2978 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2979 | uiSSDU += iDiff * iDiff; |
---|
| 2980 | } |
---|
| 2981 | pOrg += iStride; |
---|
| 2982 | pRec += iStride; |
---|
| 2983 | } |
---|
| 2984 | |
---|
| 2985 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
| 2986 | pRec = pcPicD->getCrAddr(); |
---|
| 2987 | |
---|
| 2988 | for( y = 0; y < iHeight; y++ ) |
---|
| 2989 | { |
---|
| 2990 | for( x = 0; x < iWidth; x++ ) |
---|
| 2991 | { |
---|
| 2992 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
| 2993 | uiSSDV += iDiff * iDiff; |
---|
| 2994 | } |
---|
| 2995 | pOrg += iStride; |
---|
| 2996 | pRec += iStride; |
---|
| 2997 | } |
---|
| 2998 | |
---|
| 2999 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
| 3000 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
| 3001 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize; |
---|
| 3002 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize / 4.0; |
---|
| 3003 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
| 3004 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
| 3005 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
| 3006 | |
---|
| 3007 | /* calculate the size of the access unit, excluding: |
---|
| 3008 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
| 3009 | * - SEI NAL units |
---|
| 3010 | */ |
---|
| 3011 | UInt numRBSPBytes = 0; |
---|
| 3012 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 3013 | { |
---|
| 3014 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
| 3015 | #if VERBOSE_RATE |
---|
| 3016 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
| 3017 | #endif |
---|
| 3018 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
| 3019 | { |
---|
| 3020 | numRBSPBytes += numRBSPBytes_nal; |
---|
| 3021 | } |
---|
| 3022 | } |
---|
| 3023 | |
---|
| 3024 | UInt uibits = numRBSPBytes * 8; |
---|
| 3025 | m_vRVM_RP.push_back( uibits ); |
---|
| 3026 | |
---|
| 3027 | //===== add PSNR ===== |
---|
| 3028 | #if SVC_EXTENSION |
---|
| 3029 | m_gcAnalyzeAll[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3030 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
| 3031 | if (pcSlice->isIntra()) |
---|
| 3032 | { |
---|
| 3033 | m_gcAnalyzeI[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3034 | } |
---|
| 3035 | if (pcSlice->isInterP()) |
---|
| 3036 | { |
---|
| 3037 | m_gcAnalyzeP[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3038 | } |
---|
| 3039 | if (pcSlice->isInterB()) |
---|
| 3040 | { |
---|
| 3041 | m_gcAnalyzeB[m_layerId].addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3042 | } |
---|
| 3043 | #else |
---|
| 3044 | m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3045 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
| 3046 | if (pcSlice->isIntra()) |
---|
| 3047 | { |
---|
| 3048 | m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3049 | } |
---|
| 3050 | if (pcSlice->isInterP()) |
---|
| 3051 | { |
---|
| 3052 | m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3053 | } |
---|
| 3054 | if (pcSlice->isInterB()) |
---|
| 3055 | { |
---|
| 3056 | m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
| 3057 | } |
---|
| 3058 | #endif |
---|
| 3059 | |
---|
| 3060 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
| 3061 | if (!pcSlice->isReferenced()) c += 32; |
---|
| 3062 | |
---|
| 3063 | #if SVC_EXTENSION |
---|
| 3064 | #if ADAPTIVE_QP_SELECTION |
---|
| 3065 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
| 3066 | pcSlice->getPOC(), |
---|
| 3067 | pcSlice->getLayerId(), |
---|
| 3068 | pcSlice->getTLayer(), |
---|
| 3069 | c, |
---|
| 3070 | pcSlice->getSliceQpBase(), |
---|
| 3071 | pcSlice->getSliceQp(), |
---|
| 3072 | uibits ); |
---|
| 3073 | #else |
---|
| 3074 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
| 3075 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 3076 | pcSlice->getLayerId(), |
---|
| 3077 | pcSlice->getTLayer(), |
---|
| 3078 | c, |
---|
| 3079 | pcSlice->getSliceQp(), |
---|
| 3080 | uibits ); |
---|
| 3081 | #endif |
---|
| 3082 | #else |
---|
| 3083 | #if ADAPTIVE_QP_SELECTION |
---|
| 3084 | printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
| 3085 | pcSlice->getPOC(), |
---|
| 3086 | pcSlice->getTLayer(), |
---|
| 3087 | c, |
---|
| 3088 | pcSlice->getSliceQpBase(), |
---|
| 3089 | pcSlice->getSliceQp(), |
---|
| 3090 | uibits ); |
---|
| 3091 | #else |
---|
| 3092 | printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
| 3093 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
| 3094 | pcSlice->getTLayer(), |
---|
| 3095 | c, |
---|
| 3096 | pcSlice->getSliceQp(), |
---|
| 3097 | uibits ); |
---|
| 3098 | #endif |
---|
| 3099 | #endif |
---|
| 3100 | |
---|
| 3101 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
| 3102 | printf(" [ET %5.0f ]", dEncTime ); |
---|
| 3103 | |
---|
| 3104 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 3105 | { |
---|
| 3106 | printf(" [L%d ", iRefList); |
---|
| 3107 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 3108 | { |
---|
[442] | 3109 | #if SVC_EXTENSION |
---|
| 3110 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
[313] | 3111 | if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) ) |
---|
| 3112 | { |
---|
[442] | 3113 | printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() ); |
---|
[313] | 3114 | } |
---|
| 3115 | else |
---|
[442] | 3116 | { |
---|
| 3117 | printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
| 3118 | } |
---|
[313] | 3119 | #endif |
---|
[442] | 3120 | if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() ) |
---|
| 3121 | { |
---|
| 3122 | printf( "c" ); |
---|
| 3123 | } |
---|
| 3124 | |
---|
| 3125 | printf( " " ); |
---|
| 3126 | #else |
---|
[313] | 3127 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
[442] | 3128 | #endif |
---|
[313] | 3129 | } |
---|
| 3130 | printf("]"); |
---|
| 3131 | } |
---|
| 3132 | } |
---|
| 3133 | |
---|
[442] | 3134 | |
---|
| 3135 | Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff) |
---|
| 3136 | { |
---|
| 3137 | |
---|
| 3138 | for (Int y = 0; y < height; y++) |
---|
| 3139 | { |
---|
| 3140 | for (Int x = 0; x < width; x++) |
---|
| 3141 | { |
---|
| 3142 | dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x]; |
---|
| 3143 | dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x]; |
---|
| 3144 | } |
---|
| 3145 | top += stride; |
---|
| 3146 | bottom += stride; |
---|
| 3147 | dst += stride*2; |
---|
| 3148 | } |
---|
| 3149 | } |
---|
| 3150 | |
---|
| 3151 | Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime ) |
---|
| 3152 | { |
---|
| 3153 | Int x, y; |
---|
| 3154 | |
---|
| 3155 | UInt64 uiSSDY_in = 0; |
---|
| 3156 | UInt64 uiSSDU_in = 0; |
---|
| 3157 | UInt64 uiSSDV_in = 0; |
---|
| 3158 | |
---|
| 3159 | Double dYPSNR_in = 0.0; |
---|
| 3160 | Double dUPSNR_in = 0.0; |
---|
| 3161 | Double dVPSNR_in = 0.0; |
---|
| 3162 | |
---|
| 3163 | /*------ INTERLACED PSNR -----------*/ |
---|
| 3164 | |
---|
| 3165 | /* Luma */ |
---|
| 3166 | |
---|
| 3167 | Pel* pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr(); |
---|
| 3168 | Pel* pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr(); |
---|
| 3169 | Pel* pRecTop = pcPicRecTop->getLumaAddr(); |
---|
| 3170 | Pel* pRecBottom = pcPicRecBottom->getLumaAddr(); |
---|
| 3171 | |
---|
| 3172 | Int iWidth; |
---|
| 3173 | Int iHeight; |
---|
| 3174 | Int iStride; |
---|
| 3175 | |
---|
| 3176 | iWidth = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0); |
---|
| 3177 | iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1); |
---|
| 3178 | iStride = pcPicOrgTop->getPicYuvOrg()->getStride(); |
---|
| 3179 | Int iSize = iWidth*iHeight; |
---|
| 3180 | bool isTff = pcPicOrgTop->isTopField(); |
---|
| 3181 | |
---|
| 3182 | TComPicYuv* pcOrgInterlaced = new TComPicYuv; |
---|
[475] | 3183 | #if AUXILIARY_PICTURES |
---|
| 3184 | pcOrgInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 3185 | #else |
---|
[442] | 3186 | pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
[475] | 3187 | #endif |
---|
[442] | 3188 | |
---|
| 3189 | TComPicYuv* pcRecInterlaced = new TComPicYuv; |
---|
[475] | 3190 | #if AUXILIARY_PICTURES |
---|
| 3191 | pcRecInterlaced->create( iWidth, iHeight << 1, pcPicOrgTop->getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 3192 | #else |
---|
[442] | 3193 | pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
[475] | 3194 | #endif |
---|
[442] | 3195 | |
---|
| 3196 | Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr(); |
---|
| 3197 | Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr(); |
---|
| 3198 | |
---|
| 3199 | //=== Interlace fields ==== |
---|
| 3200 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3201 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3202 | |
---|
| 3203 | //===== calculate PSNR ===== |
---|
| 3204 | for( y = 0; y < iHeight << 1; y++ ) |
---|
| 3205 | { |
---|
| 3206 | for( x = 0; x < iWidth; x++ ) |
---|
| 3207 | { |
---|
| 3208 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
| 3209 | uiSSDY_in += iDiff * iDiff; |
---|
| 3210 | } |
---|
| 3211 | pOrgInterlaced += iStride; |
---|
| 3212 | pRecInterlaced += iStride; |
---|
| 3213 | } |
---|
| 3214 | |
---|
| 3215 | /*Chroma*/ |
---|
| 3216 | |
---|
| 3217 | iHeight >>= 1; |
---|
| 3218 | iWidth >>= 1; |
---|
| 3219 | iStride >>= 1; |
---|
| 3220 | |
---|
| 3221 | pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr(); |
---|
| 3222 | pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr(); |
---|
| 3223 | pRecTop = pcPicRecTop->getCbAddr(); |
---|
| 3224 | pRecBottom = pcPicRecBottom->getCbAddr(); |
---|
| 3225 | pOrgInterlaced = pcOrgInterlaced->getCbAddr(); |
---|
| 3226 | pRecInterlaced = pcRecInterlaced->getCbAddr(); |
---|
| 3227 | |
---|
| 3228 | //=== Interlace fields ==== |
---|
| 3229 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3230 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3231 | |
---|
| 3232 | //===== calculate PSNR ===== |
---|
| 3233 | for( y = 0; y < iHeight << 1; y++ ) |
---|
| 3234 | { |
---|
| 3235 | for( x = 0; x < iWidth; x++ ) |
---|
| 3236 | { |
---|
| 3237 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
| 3238 | uiSSDU_in += iDiff * iDiff; |
---|
| 3239 | } |
---|
| 3240 | pOrgInterlaced += iStride; |
---|
| 3241 | pRecInterlaced += iStride; |
---|
| 3242 | } |
---|
| 3243 | |
---|
| 3244 | pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr(); |
---|
| 3245 | pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr(); |
---|
| 3246 | pRecTop = pcPicRecTop->getCrAddr(); |
---|
| 3247 | pRecBottom = pcPicRecBottom->getCrAddr(); |
---|
| 3248 | pOrgInterlaced = pcOrgInterlaced->getCrAddr(); |
---|
| 3249 | pRecInterlaced = pcRecInterlaced->getCrAddr(); |
---|
| 3250 | |
---|
| 3251 | //=== Interlace fields ==== |
---|
| 3252 | reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3253 | reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff); |
---|
| 3254 | |
---|
| 3255 | //===== calculate PSNR ===== |
---|
| 3256 | for( y = 0; y < iHeight << 1; y++ ) |
---|
| 3257 | { |
---|
| 3258 | for( x = 0; x < iWidth; x++ ) |
---|
| 3259 | { |
---|
| 3260 | Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] ); |
---|
| 3261 | uiSSDV_in += iDiff * iDiff; |
---|
| 3262 | } |
---|
| 3263 | pOrgInterlaced += iStride; |
---|
| 3264 | pRecInterlaced += iStride; |
---|
| 3265 | } |
---|
| 3266 | |
---|
| 3267 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
| 3268 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
| 3269 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2; |
---|
| 3270 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0; |
---|
| 3271 | dYPSNR_in = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 ); |
---|
| 3272 | dUPSNR_in = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 ); |
---|
| 3273 | dVPSNR_in = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 ); |
---|
| 3274 | |
---|
| 3275 | /* calculate the size of the access unit, excluding: |
---|
| 3276 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
| 3277 | * - SEI NAL units |
---|
| 3278 | */ |
---|
| 3279 | UInt numRBSPBytes = 0; |
---|
| 3280 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
| 3281 | { |
---|
| 3282 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
| 3283 | |
---|
| 3284 | if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) |
---|
| 3285 | numRBSPBytes += numRBSPBytes_nal; |
---|
| 3286 | } |
---|
| 3287 | |
---|
| 3288 | UInt uibits = numRBSPBytes * 8 ; |
---|
| 3289 | |
---|
| 3290 | //===== add PSNR ===== |
---|
| 3291 | m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits); |
---|
| 3292 | |
---|
| 3293 | printf("\n Interlaced frame %d: [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in ); |
---|
| 3294 | |
---|
| 3295 | pcOrgInterlaced->destroy(); |
---|
| 3296 | delete pcOrgInterlaced; |
---|
| 3297 | pcRecInterlaced->destroy(); |
---|
| 3298 | delete pcRecInterlaced; |
---|
| 3299 | } |
---|
| 3300 | |
---|
[313] | 3301 | /** Function for deciding the nal_unit_type. |
---|
| 3302 | * \param pocCurr POC of the current picture |
---|
| 3303 | * \returns the nal unit type of the picture |
---|
| 3304 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
| 3305 | */ |
---|
| 3306 | NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR) |
---|
| 3307 | { |
---|
| 3308 | if (pocCurr == 0) |
---|
| 3309 | { |
---|
| 3310 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
| 3311 | } |
---|
| 3312 | if (pocCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
| 3313 | { |
---|
| 3314 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
| 3315 | { |
---|
| 3316 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
| 3317 | } |
---|
| 3318 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
| 3319 | { |
---|
| 3320 | return NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
---|
| 3321 | } |
---|
| 3322 | } |
---|
| 3323 | if(m_pocCRA>0) |
---|
| 3324 | { |
---|
| 3325 | if(pocCurr<m_pocCRA) |
---|
| 3326 | { |
---|
| 3327 | // All leading pictures are being marked as TFD pictures here since current encoder uses all |
---|
| 3328 | // reference pictures while encoding leading pictures. An encoder can ensure that a leading |
---|
| 3329 | // picture can be still decodable when random accessing to a CRA/CRANT/BLA/BLANT picture by |
---|
| 3330 | // controlling the reference pictures used for encoding that leading picture. Such a leading |
---|
| 3331 | // picture need not be marked as a TFD picture. |
---|
| 3332 | return NAL_UNIT_CODED_SLICE_RASL_R; |
---|
| 3333 | } |
---|
| 3334 | } |
---|
| 3335 | if (lastIDR>0) |
---|
| 3336 | { |
---|
| 3337 | if (pocCurr < lastIDR) |
---|
| 3338 | { |
---|
| 3339 | return NAL_UNIT_CODED_SLICE_RADL_R; |
---|
| 3340 | } |
---|
| 3341 | } |
---|
| 3342 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
| 3343 | } |
---|
| 3344 | |
---|
| 3345 | Double TEncGOP::xCalculateRVM() |
---|
| 3346 | { |
---|
| 3347 | Double dRVM = 0; |
---|
| 3348 | |
---|
| 3349 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFramesToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
| 3350 | { |
---|
| 3351 | // calculate RVM only for lowdelay configurations |
---|
| 3352 | std::vector<Double> vRL , vB; |
---|
| 3353 | size_t N = m_vRVM_RP.size(); |
---|
| 3354 | vRL.resize( N ); |
---|
| 3355 | vB.resize( N ); |
---|
| 3356 | |
---|
| 3357 | Int i; |
---|
| 3358 | Double dRavg = 0 , dBavg = 0; |
---|
| 3359 | vB[RVM_VCEGAM10_M] = 0; |
---|
| 3360 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 3361 | { |
---|
| 3362 | vRL[i] = 0; |
---|
| 3363 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
| 3364 | vRL[i] += m_vRVM_RP[j]; |
---|
| 3365 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
| 3366 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
| 3367 | dRavg += m_vRVM_RP[i]; |
---|
| 3368 | dBavg += vB[i]; |
---|
| 3369 | } |
---|
| 3370 | |
---|
| 3371 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
| 3372 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
| 3373 | |
---|
| 3374 | Double dSigamB = 0; |
---|
| 3375 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
| 3376 | { |
---|
| 3377 | Double tmp = vB[i] - dBavg; |
---|
| 3378 | dSigamB += tmp * tmp; |
---|
| 3379 | } |
---|
| 3380 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
| 3381 | |
---|
| 3382 | Double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
| 3383 | |
---|
| 3384 | dRVM = dSigamB / dRavg * f; |
---|
| 3385 | } |
---|
| 3386 | |
---|
| 3387 | return( dRVM ); |
---|
| 3388 | } |
---|
| 3389 | |
---|
| 3390 | /** Attaches the input bitstream to the stream in the output NAL unit |
---|
| 3391 | Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
| 3392 | * \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu |
---|
| 3393 | * \param rNalu target NAL unit |
---|
| 3394 | */ |
---|
| 3395 | Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData) |
---|
| 3396 | { |
---|
| 3397 | // Byte-align |
---|
| 3398 | rNalu.m_Bitstream.writeByteAlignment(); // Slice header byte-alignment |
---|
| 3399 | |
---|
| 3400 | // Perform bitstream concatenation |
---|
| 3401 | if (codedSliceData->getNumberOfWrittenBits() > 0) |
---|
| 3402 | { |
---|
| 3403 | rNalu.m_Bitstream.addSubstream(codedSliceData); |
---|
| 3404 | } |
---|
| 3405 | |
---|
| 3406 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
| 3407 | |
---|
| 3408 | codedSliceData->clear(); |
---|
| 3409 | } |
---|
| 3410 | |
---|
| 3411 | // Function will arrange the long-term pictures in the decreasing order of poc_lsb_lt, |
---|
| 3412 | // and among the pictures with the same lsb, it arranges them in increasing delta_poc_msb_cycle_lt value |
---|
| 3413 | Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic) |
---|
| 3414 | { |
---|
| 3415 | TComReferencePictureSet *rps = pcSlice->getRPS(); |
---|
| 3416 | if(!rps->getNumberOfLongtermPictures()) |
---|
| 3417 | { |
---|
| 3418 | return; |
---|
| 3419 | } |
---|
| 3420 | |
---|
| 3421 | // Arrange long-term reference pictures in the correct order of LSB and MSB, |
---|
| 3422 | // and assign values for pocLSBLT and MSB present flag |
---|
| 3423 | Int longtermPicsPoc[MAX_NUM_REF_PICS], longtermPicsLSB[MAX_NUM_REF_PICS], indices[MAX_NUM_REF_PICS]; |
---|
| 3424 | Int longtermPicsMSB[MAX_NUM_REF_PICS]; |
---|
| 3425 | Bool mSBPresentFlag[MAX_NUM_REF_PICS]; |
---|
| 3426 | ::memset(longtermPicsPoc, 0, sizeof(longtermPicsPoc)); // Store POC values of LTRP |
---|
| 3427 | ::memset(longtermPicsLSB, 0, sizeof(longtermPicsLSB)); // Store POC LSB values of LTRP |
---|
| 3428 | ::memset(longtermPicsMSB, 0, sizeof(longtermPicsMSB)); // Store POC LSB values of LTRP |
---|
| 3429 | ::memset(indices , 0, sizeof(indices)); // Indices to aid in tracking sorted LTRPs |
---|
| 3430 | ::memset(mSBPresentFlag , 0, sizeof(mSBPresentFlag)); // Indicate if MSB needs to be present |
---|
| 3431 | |
---|
| 3432 | // Get the long-term reference pictures |
---|
| 3433 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
| 3434 | Int i, ctr = 0; |
---|
| 3435 | Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC(); |
---|
| 3436 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
| 3437 | { |
---|
| 3438 | longtermPicsPoc[ctr] = rps->getPOC(i); // LTRP POC |
---|
| 3439 | longtermPicsLSB[ctr] = getLSB(longtermPicsPoc[ctr], maxPicOrderCntLSB); // LTRP POC LSB |
---|
| 3440 | indices[ctr] = i; |
---|
| 3441 | longtermPicsMSB[ctr] = longtermPicsPoc[ctr] - longtermPicsLSB[ctr]; |
---|
| 3442 | } |
---|
| 3443 | Int numLongPics = rps->getNumberOfLongtermPictures(); |
---|
| 3444 | assert(ctr == numLongPics); |
---|
| 3445 | |
---|
| 3446 | // Arrange pictures in decreasing order of MSB; |
---|
| 3447 | for(i = 0; i < numLongPics; i++) |
---|
| 3448 | { |
---|
| 3449 | for(Int j = 0; j < numLongPics - 1; j++) |
---|
| 3450 | { |
---|
| 3451 | if(longtermPicsMSB[j] < longtermPicsMSB[j+1]) |
---|
| 3452 | { |
---|
| 3453 | std::swap(longtermPicsPoc[j], longtermPicsPoc[j+1]); |
---|
| 3454 | std::swap(longtermPicsLSB[j], longtermPicsLSB[j+1]); |
---|
| 3455 | std::swap(longtermPicsMSB[j], longtermPicsMSB[j+1]); |
---|
| 3456 | std::swap(indices[j] , indices[j+1] ); |
---|
| 3457 | } |
---|
| 3458 | } |
---|
| 3459 | } |
---|
| 3460 | |
---|
| 3461 | for(i = 0; i < numLongPics; i++) |
---|
| 3462 | { |
---|
| 3463 | // Check if MSB present flag should be enabled. |
---|
| 3464 | // Check if the buffer contains any pictures that have the same LSB. |
---|
| 3465 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
| 3466 | TComPic* pcPic; |
---|
| 3467 | while ( iterPic != rcListPic.end() ) |
---|
| 3468 | { |
---|
| 3469 | pcPic = *iterPic; |
---|
| 3470 | if( (getLSB(pcPic->getPOC(), maxPicOrderCntLSB) == longtermPicsLSB[i]) && // Same LSB |
---|
| 3471 | (pcPic->getSlice(0)->isReferenced()) && // Reference picture |
---|
| 3472 | (pcPic->getPOC() != longtermPicsPoc[i]) ) // Not the LTRP itself |
---|
| 3473 | { |
---|
| 3474 | mSBPresentFlag[i] = true; |
---|
| 3475 | break; |
---|
| 3476 | } |
---|
| 3477 | iterPic++; |
---|
| 3478 | } |
---|
| 3479 | } |
---|
| 3480 | |
---|
| 3481 | // tempArray for usedByCurr flag |
---|
| 3482 | Bool tempArray[MAX_NUM_REF_PICS]; ::memset(tempArray, 0, sizeof(tempArray)); |
---|
| 3483 | for(i = 0; i < numLongPics; i++) |
---|
| 3484 | { |
---|
| 3485 | tempArray[i] = rps->getUsed(indices[i]); |
---|
| 3486 | } |
---|
| 3487 | // Now write the final values; |
---|
| 3488 | ctr = 0; |
---|
| 3489 | Int currMSB = 0, currLSB = 0; |
---|
| 3490 | // currPicPoc = currMSB + currLSB |
---|
| 3491 | currLSB = getLSB(pcSlice->getPOC(), maxPicOrderCntLSB); |
---|
| 3492 | currMSB = pcSlice->getPOC() - currLSB; |
---|
| 3493 | |
---|
| 3494 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
| 3495 | { |
---|
| 3496 | rps->setPOC (i, longtermPicsPoc[ctr]); |
---|
| 3497 | rps->setDeltaPOC (i, - pcSlice->getPOC() + longtermPicsPoc[ctr]); |
---|
| 3498 | rps->setUsed (i, tempArray[ctr]); |
---|
| 3499 | rps->setPocLSBLT (i, longtermPicsLSB[ctr]); |
---|
| 3500 | rps->setDeltaPocMSBCycleLT (i, (currMSB - (longtermPicsPoc[ctr] - longtermPicsLSB[ctr])) / maxPicOrderCntLSB); |
---|
| 3501 | rps->setDeltaPocMSBPresentFlag(i, mSBPresentFlag[ctr]); |
---|
| 3502 | |
---|
| 3503 | assert(rps->getDeltaPocMSBCycleLT(i) >= 0); // Non-negative value |
---|
| 3504 | } |
---|
| 3505 | for(i = rps->getNumberOfPictures() - 1, ctr = 1; i >= offset; i--, ctr++) |
---|
| 3506 | { |
---|
| 3507 | for(Int j = rps->getNumberOfPictures() - 1 - ctr; j >= offset; j--) |
---|
| 3508 | { |
---|
| 3509 | // Here at the encoder we know that we have set the full POC value for the LTRPs, hence we |
---|
| 3510 | // don't have to check the MSB present flag values for this constraint. |
---|
| 3511 | assert( rps->getPOC(i) != rps->getPOC(j) ); // If assert fails, LTRP entry repeated in RPS!!! |
---|
| 3512 | } |
---|
| 3513 | } |
---|
| 3514 | } |
---|
| 3515 | |
---|
| 3516 | /** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
| 3517 | * \param accessUnit Access Unit of the current picture |
---|
| 3518 | * This function finds the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
| 3519 | */ |
---|
| 3520 | Int TEncGOP::xGetFirstSeiLocation(AccessUnit &accessUnit) |
---|
| 3521 | { |
---|
| 3522 | // Find the location of the first SEI message |
---|
| 3523 | AccessUnit::iterator it; |
---|
| 3524 | Int seiStartPos = 0; |
---|
| 3525 | for(it = accessUnit.begin(); it != accessUnit.end(); it++, seiStartPos++) |
---|
| 3526 | { |
---|
| 3527 | if ((*it)->isSei() || (*it)->isVcl()) |
---|
| 3528 | { |
---|
| 3529 | break; |
---|
| 3530 | } |
---|
| 3531 | } |
---|
| 3532 | // assert(it != accessUnit.end()); // Triggers with some legit configurations |
---|
| 3533 | return seiStartPos; |
---|
| 3534 | } |
---|
| 3535 | |
---|
[442] | 3536 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
| 3537 | Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym) |
---|
| 3538 | { |
---|
| 3539 | Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU(); |
---|
| 3540 | |
---|
| 3541 | for (Int i = 0; i < numCUs; i++) |
---|
| 3542 | { |
---|
| 3543 | picSym->setTileSetIdxMap(i, -1, 0, false); |
---|
| 3544 | } |
---|
| 3545 | |
---|
| 3546 | for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++) |
---|
| 3547 | { |
---|
| 3548 | TComTile* topLeftTile = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i)); |
---|
| 3549 | TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i)); |
---|
| 3550 | Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1; |
---|
| 3551 | Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU(); |
---|
| 3552 | Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1; |
---|
| 3553 | Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU(); |
---|
| 3554 | assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU); |
---|
| 3555 | for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++) |
---|
| 3556 | { |
---|
| 3557 | for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++) |
---|
| 3558 | { |
---|
| 3559 | picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false); |
---|
| 3560 | } |
---|
| 3561 | } |
---|
| 3562 | } |
---|
| 3563 | |
---|
| 3564 | if (m_pcCfg->getSkippedTileSetPresentFlag()) |
---|
| 3565 | { |
---|
| 3566 | Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage(); |
---|
| 3567 | for (Int i = 0; i < numCUs; i++) |
---|
| 3568 | { |
---|
| 3569 | if (picSym->getTileSetIdxMap(i) < 0) |
---|
| 3570 | { |
---|
| 3571 | picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true); |
---|
| 3572 | } |
---|
| 3573 | } |
---|
| 3574 | } |
---|
| 3575 | } |
---|
| 3576 | #endif |
---|
| 3577 | |
---|
[313] | 3578 | Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices ) |
---|
| 3579 | { |
---|
| 3580 | TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); |
---|
| 3581 | Pel* Rec = pcPicYuvRec->getLumaAddr( 0 ); |
---|
| 3582 | Pel* tempRec = Rec; |
---|
| 3583 | Int stride = pcPicYuvRec->getStride(); |
---|
| 3584 | UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize(); |
---|
| 3585 | UInt maxTBsize = (1<<log2maxTB); |
---|
| 3586 | const UInt minBlockArtSize = 8; |
---|
| 3587 | const UInt picWidth = pcPicYuvRec->getWidth(); |
---|
| 3588 | const UInt picHeight = pcPicYuvRec->getHeight(); |
---|
| 3589 | const UInt noCol = (picWidth>>log2maxTB); |
---|
| 3590 | const UInt noRows = (picHeight>>log2maxTB); |
---|
| 3591 | assert(noCol > 1); |
---|
| 3592 | assert(noRows > 1); |
---|
| 3593 | UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64)); |
---|
| 3594 | UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64)); |
---|
| 3595 | UInt colIdx = 0; |
---|
| 3596 | UInt rowIdx = 0; |
---|
| 3597 | Pel p0, p1, p2, q0, q1, q2; |
---|
| 3598 | |
---|
| 3599 | Int qp = pcPic->getSlice(0)->getSliceQp(); |
---|
| 3600 | Int bitdepthScale = 1 << (g_bitDepthY-8); |
---|
| 3601 | Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale; |
---|
| 3602 | const Int thr2 = (beta>>2); |
---|
| 3603 | const Int thr1 = 2*bitdepthScale; |
---|
| 3604 | UInt a = 0; |
---|
| 3605 | |
---|
| 3606 | memset(colSAD, 0, noCol*sizeof(UInt64)); |
---|
| 3607 | memset(rowSAD, 0, noRows*sizeof(UInt64)); |
---|
| 3608 | |
---|
| 3609 | if (maxTBsize > minBlockArtSize) |
---|
| 3610 | { |
---|
| 3611 | // Analyze vertical artifact edges |
---|
| 3612 | for(Int c = maxTBsize; c < picWidth; c += maxTBsize) |
---|
| 3613 | { |
---|
| 3614 | for(Int r = 0; r < picHeight; r++) |
---|
| 3615 | { |
---|
| 3616 | p2 = Rec[c-3]; |
---|
| 3617 | p1 = Rec[c-2]; |
---|
| 3618 | p0 = Rec[c-1]; |
---|
| 3619 | q0 = Rec[c]; |
---|
| 3620 | q1 = Rec[c+1]; |
---|
| 3621 | q2 = Rec[c+2]; |
---|
| 3622 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
| 3623 | if ( thr1 < a && a < thr2) |
---|
| 3624 | { |
---|
| 3625 | colSAD[colIdx] += abs(p0 - q0); |
---|
| 3626 | } |
---|
| 3627 | Rec += stride; |
---|
| 3628 | } |
---|
| 3629 | colIdx++; |
---|
| 3630 | Rec = tempRec; |
---|
| 3631 | } |
---|
| 3632 | |
---|
| 3633 | // Analyze horizontal artifact edges |
---|
| 3634 | for(Int r = maxTBsize; r < picHeight; r += maxTBsize) |
---|
| 3635 | { |
---|
| 3636 | for(Int c = 0; c < picWidth; c++) |
---|
| 3637 | { |
---|
| 3638 | p2 = Rec[c + (r-3)*stride]; |
---|
| 3639 | p1 = Rec[c + (r-2)*stride]; |
---|
| 3640 | p0 = Rec[c + (r-1)*stride]; |
---|
| 3641 | q0 = Rec[c + r*stride]; |
---|
| 3642 | q1 = Rec[c + (r+1)*stride]; |
---|
| 3643 | q2 = Rec[c + (r+2)*stride]; |
---|
| 3644 | a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); |
---|
| 3645 | if (thr1 < a && a < thr2) |
---|
| 3646 | { |
---|
| 3647 | rowSAD[rowIdx] += abs(p0 - q0); |
---|
| 3648 | } |
---|
| 3649 | } |
---|
| 3650 | rowIdx++; |
---|
| 3651 | } |
---|
| 3652 | } |
---|
| 3653 | |
---|
| 3654 | UInt64 colSADsum = 0; |
---|
| 3655 | UInt64 rowSADsum = 0; |
---|
| 3656 | for(Int c = 0; c < noCol-1; c++) |
---|
| 3657 | { |
---|
| 3658 | colSADsum += colSAD[c]; |
---|
| 3659 | } |
---|
| 3660 | for(Int r = 0; r < noRows-1; r++) |
---|
| 3661 | { |
---|
| 3662 | rowSADsum += rowSAD[r]; |
---|
| 3663 | } |
---|
| 3664 | |
---|
| 3665 | colSADsum <<= 10; |
---|
| 3666 | rowSADsum <<= 10; |
---|
| 3667 | colSADsum /= (noCol-1); |
---|
| 3668 | colSADsum /= picHeight; |
---|
| 3669 | rowSADsum /= (noRows-1); |
---|
| 3670 | rowSADsum /= picWidth; |
---|
| 3671 | |
---|
| 3672 | UInt64 avgSAD = ((colSADsum + rowSADsum)>>1); |
---|
| 3673 | avgSAD >>= (g_bitDepthY-8); |
---|
| 3674 | |
---|
| 3675 | if ( avgSAD > 2048 ) |
---|
| 3676 | { |
---|
| 3677 | avgSAD >>= 9; |
---|
| 3678 | Int offset = Clip3(2,6,(Int)avgSAD); |
---|
| 3679 | for (Int i=0; i<uiNumSlices; i++) |
---|
| 3680 | { |
---|
| 3681 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); |
---|
| 3682 | pcPic->getSlice(i)->setDeblockingFilterDisable(false); |
---|
| 3683 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset ); |
---|
| 3684 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset ); |
---|
| 3685 | } |
---|
| 3686 | } |
---|
| 3687 | else |
---|
| 3688 | { |
---|
| 3689 | for (Int i=0; i<uiNumSlices; i++) |
---|
| 3690 | { |
---|
| 3691 | pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); |
---|
| 3692 | pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
| 3693 | pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
| 3694 | pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
| 3695 | } |
---|
| 3696 | } |
---|
| 3697 | |
---|
| 3698 | free(colSAD); |
---|
| 3699 | free(rowSAD); |
---|
| 3700 | } |
---|
| 3701 | |
---|
[345] | 3702 | #if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 3703 | TComPic* TEncGOP::getMotionPredIlp(TComSlice* pcSlice) |
---|
| 3704 | { |
---|
| 3705 | TComPic* ilpPic = NULL; |
---|
| 3706 | Int activeMotionPredReflayerIdx = 0; |
---|
| 3707 | |
---|
| 3708 | for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
| 3709 | { |
---|
| 3710 | UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i); |
---|
| 3711 | if( m_pcEncTop->getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) ) |
---|
| 3712 | { |
---|
| 3713 | if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx()) |
---|
| 3714 | { |
---|
| 3715 | ilpPic = m_pcEncTop->getIlpList()[refLayerIdc]; |
---|
| 3716 | break; |
---|
| 3717 | } |
---|
| 3718 | else |
---|
| 3719 | { |
---|
| 3720 | activeMotionPredReflayerIdx++; |
---|
| 3721 | } |
---|
| 3722 | } |
---|
| 3723 | } |
---|
| 3724 | |
---|
| 3725 | assert(ilpPic != NULL); |
---|
| 3726 | |
---|
| 3727 | return ilpPic; |
---|
| 3728 | } |
---|
| 3729 | #endif |
---|
| 3730 | |
---|
| 3731 | //! \} |
---|