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