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