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