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