| 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-2015, 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 | #include "TLibCommon/CommonDef.h" |
|---|
| 35 | #include "TLibCommon/SEI.h" |
|---|
| 36 | #include "TEncGOP.h" |
|---|
| 37 | #include "TEncTop.h" |
|---|
| 38 | |
|---|
| 39 | //! \ingroup TLibEncoder |
|---|
| 40 | //! \{ |
|---|
| 41 | |
|---|
| 42 | Void SEIEncoder::initSEIActiveParameterSets (SEIActiveParameterSets *seiActiveParameterSets, const TComVPS *vps, const TComSPS *sps) |
|---|
| 43 | { |
|---|
| 44 | assert (m_isInitialized); |
|---|
| 45 | assert (seiActiveParameterSets!=NULL); |
|---|
| 46 | assert (vps!=NULL); |
|---|
| 47 | assert (sps!=NULL); |
|---|
| 48 | |
|---|
| 49 | seiActiveParameterSets->activeVPSId = vps->getVPSId(); |
|---|
| 50 | seiActiveParameterSets->m_selfContainedCvsFlag = false; |
|---|
| 51 | seiActiveParameterSets->m_noParameterSetUpdateFlag = false; |
|---|
| 52 | #if R0247_SEI_ACTIVE |
|---|
| 53 | seiActiveParameterSets->numSpsIdsMinus1 = m_pcCfg->getNumLayer()-1; |
|---|
| 54 | seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); |
|---|
| 55 | seiActiveParameterSets->layerSpsIdx.resize(seiActiveParameterSets->numSpsIdsMinus1+ 1); |
|---|
| 56 | for (Int c=0; c <= seiActiveParameterSets->numSpsIdsMinus1; c++) |
|---|
| 57 | { |
|---|
| 58 | seiActiveParameterSets->activeSeqParameterSetId[c] = c; |
|---|
| 59 | } |
|---|
| 60 | for (Int c=1; c <= seiActiveParameterSets->numSpsIdsMinus1; c++) |
|---|
| 61 | { |
|---|
| 62 | seiActiveParameterSets->layerSpsIdx[c] = c; |
|---|
| 63 | } |
|---|
| 64 | #else |
|---|
| 65 | seiActiveParameterSets->numSpsIdsMinus1 = 0; |
|---|
| 66 | seiActiveParameterSets->activeSeqParameterSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); |
|---|
| 67 | seiActiveParameterSets->activeSeqParameterSetId[0] = sps->getSPSId(); |
|---|
| 68 | #endif |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | Void SEIEncoder::initSEIFramePacking(SEIFramePacking *seiFramePacking, Int currPicNum) |
|---|
| 72 | { |
|---|
| 73 | assert (m_isInitialized); |
|---|
| 74 | assert (seiFramePacking!=NULL); |
|---|
| 75 | |
|---|
| 76 | seiFramePacking->m_arrangementId = m_pcCfg->getFramePackingArrangementSEIId(); |
|---|
| 77 | seiFramePacking->m_arrangementCancelFlag = 0; |
|---|
| 78 | seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType(); |
|---|
| 79 | assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) ); |
|---|
| 80 | seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx(); |
|---|
| 81 | seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation(); |
|---|
| 82 | seiFramePacking->m_spatialFlippingFlag = 0; |
|---|
| 83 | seiFramePacking->m_frame0FlippedFlag = 0; |
|---|
| 84 | seiFramePacking->m_fieldViewsFlag = (seiFramePacking->m_arrangementType == 2); |
|---|
| 85 | seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && (currPicNum&1) ); |
|---|
| 86 | seiFramePacking->m_frame0SelfContainedFlag = 0; |
|---|
| 87 | seiFramePacking->m_frame1SelfContainedFlag = 0; |
|---|
| 88 | seiFramePacking->m_frame0GridPositionX = 0; |
|---|
| 89 | seiFramePacking->m_frame0GridPositionY = 0; |
|---|
| 90 | seiFramePacking->m_frame1GridPositionX = 0; |
|---|
| 91 | seiFramePacking->m_frame1GridPositionY = 0; |
|---|
| 92 | seiFramePacking->m_arrangementReservedByte = 0; |
|---|
| 93 | seiFramePacking->m_arrangementPersistenceFlag = true; |
|---|
| 94 | seiFramePacking->m_upsampledAspectRatio = 0; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | Void SEIEncoder::initSEISegmentedRectFramePacking(SEISegmentedRectFramePacking *seiSegmentedRectFramePacking) |
|---|
| 98 | { |
|---|
| 99 | assert (m_isInitialized); |
|---|
| 100 | assert (seiSegmentedRectFramePacking!=NULL); |
|---|
| 101 | |
|---|
| 102 | seiSegmentedRectFramePacking->m_arrangementCancelFlag = m_pcCfg->getSegmentedRectFramePackingArrangementSEICancel(); |
|---|
| 103 | seiSegmentedRectFramePacking->m_contentInterpretationType = m_pcCfg->getSegmentedRectFramePackingArrangementSEIType(); |
|---|
| 104 | seiSegmentedRectFramePacking->m_arrangementPersistenceFlag = m_pcCfg->getSegmentedRectFramePackingArrangementSEIPersistence(); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | Void SEIEncoder::initSEIDisplayOrientation(SEIDisplayOrientation* seiDisplayOrientation) |
|---|
| 108 | { |
|---|
| 109 | assert (m_isInitialized); |
|---|
| 110 | assert (seiDisplayOrientation!=NULL); |
|---|
| 111 | |
|---|
| 112 | seiDisplayOrientation->cancelFlag = false; |
|---|
| 113 | seiDisplayOrientation->horFlip = false; |
|---|
| 114 | seiDisplayOrientation->verFlip = false; |
|---|
| 115 | seiDisplayOrientation->anticlockwiseRotation = m_pcCfg->getDisplayOrientationSEIAngle(); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | Void SEIEncoder::initSEIToneMappingInfo(SEIToneMappingInfo *seiToneMappingInfo) |
|---|
| 119 | { |
|---|
| 120 | assert (m_isInitialized); |
|---|
| 121 | assert (seiToneMappingInfo!=NULL); |
|---|
| 122 | |
|---|
| 123 | seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId(); |
|---|
| 124 | seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag(); |
|---|
| 125 | seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag(); |
|---|
| 126 | |
|---|
| 127 | seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth(); |
|---|
| 128 | assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14); |
|---|
| 129 | seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth(); |
|---|
| 130 | assert(seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17); |
|---|
| 131 | seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID(); |
|---|
| 132 | assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4); |
|---|
| 133 | |
|---|
| 134 | switch( seiToneMappingInfo->m_modelId) |
|---|
| 135 | { |
|---|
| 136 | case 0: |
|---|
| 137 | { |
|---|
| 138 | seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue(); |
|---|
| 139 | seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue(); |
|---|
| 140 | break; |
|---|
| 141 | } |
|---|
| 142 | case 1: |
|---|
| 143 | { |
|---|
| 144 | seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint(); |
|---|
| 145 | seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth(); |
|---|
| 146 | break; |
|---|
| 147 | } |
|---|
| 148 | case 2: |
|---|
| 149 | { |
|---|
| 150 | UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth); |
|---|
| 151 | seiToneMappingInfo->m_startOfCodedInterval.resize(num); |
|---|
| 152 | Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva(); |
|---|
| 153 | if(ptmp) |
|---|
| 154 | { |
|---|
| 155 | for(Int i=0; i<num;i++) |
|---|
| 156 | { |
|---|
| 157 | seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i]; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | break; |
|---|
| 161 | } |
|---|
| 162 | case 3: |
|---|
| 163 | { |
|---|
| 164 | seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots(); |
|---|
| 165 | seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots); |
|---|
| 166 | seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots); |
|---|
| 167 | Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue(); |
|---|
| 168 | Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue(); |
|---|
| 169 | if(ptmpcoded&&ptmptarget) |
|---|
| 170 | { |
|---|
| 171 | for(Int i=0; i<(seiToneMappingInfo->m_numPivots);i++) |
|---|
| 172 | { |
|---|
| 173 | seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i]; |
|---|
| 174 | seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i]; |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | break; |
|---|
| 178 | } |
|---|
| 179 | case 4: |
|---|
| 180 | { |
|---|
| 181 | seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc(); |
|---|
| 182 | seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue(); |
|---|
| 183 | assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 ); |
|---|
| 184 | seiToneMappingInfo->m_exposureIndexIdc = m_pcCfg->getTMISEIExposurIndexIdc(); |
|---|
| 185 | seiToneMappingInfo->m_exposureIndexValue = m_pcCfg->getTMISEIExposurIndexValue(); |
|---|
| 186 | assert( seiToneMappingInfo->m_exposureIndexValue !=0 ); |
|---|
| 187 | seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag(); |
|---|
| 188 | seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator(); |
|---|
| 189 | seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc(); |
|---|
| 190 | seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite(); |
|---|
| 191 | seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel(); |
|---|
| 192 | assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 ); |
|---|
| 193 | seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue(); |
|---|
| 194 | seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue(); |
|---|
| 195 | assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue ); |
|---|
| 196 | seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue(); |
|---|
| 197 | assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue ); |
|---|
| 198 | break; |
|---|
| 199 | } |
|---|
| 200 | default: |
|---|
| 201 | { |
|---|
| 202 | assert(!"Undefined SEIToneMapModelId"); |
|---|
| 203 | break; |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | Void SEIEncoder::initSEISOPDescription(SEISOPDescription *sopDescriptionSEI, TComSlice *slice, Int picInGOP, Int lastIdr, Int currGOPSize) |
|---|
| 209 | { |
|---|
| 210 | assert (m_isInitialized); |
|---|
| 211 | assert (sopDescriptionSEI != NULL); |
|---|
| 212 | assert (slice != NULL); |
|---|
| 213 | |
|---|
| 214 | Int sopCurrPOC = slice->getPOC(); |
|---|
| 215 | sopDescriptionSEI->m_sopSeqParameterSetId = slice->getSPS()->getSPSId(); |
|---|
| 216 | |
|---|
| 217 | Int i = 0; |
|---|
| 218 | Int prevEntryId = picInGOP; |
|---|
| 219 | for (Int j = picInGOP; j < currGOPSize; j++) |
|---|
| 220 | { |
|---|
| 221 | Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC; |
|---|
| 222 | if ((sopCurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded()) |
|---|
| 223 | { |
|---|
| 224 | sopCurrPOC += deltaPOC; |
|---|
| 225 | sopDescriptionSEI->m_sopDescVclNaluType[i] = m_pcEncGOP->getNalUnitType(sopCurrPOC, lastIdr, slice->getPic()->isField()); |
|---|
| 226 | sopDescriptionSEI->m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; |
|---|
| 227 | sopDescriptionSEI->m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(sopCurrPOC, j); |
|---|
| 228 | sopDescriptionSEI->m_sopDescPocDelta[i] = deltaPOC; |
|---|
| 229 | |
|---|
| 230 | prevEntryId = j; |
|---|
| 231 | i++; |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | sopDescriptionSEI->m_numPicsInSopMinus1 = i - 1; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | Void SEIEncoder::initSEIBufferingPeriod(SEIBufferingPeriod *bufferingPeriodSEI, TComSlice *slice) |
|---|
| 239 | { |
|---|
| 240 | assert (m_isInitialized); |
|---|
| 241 | assert (bufferingPeriodSEI != NULL); |
|---|
| 242 | assert (slice != NULL); |
|---|
| 243 | |
|---|
| 244 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
|---|
| 245 | bufferingPeriodSEI->m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
|---|
| 246 | bufferingPeriodSEI->m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
|---|
| 247 | bufferingPeriodSEI->m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
|---|
| 248 | bufferingPeriodSEI->m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
|---|
| 249 | |
|---|
| 250 | Double dTmp = (Double)slice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)slice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale(); |
|---|
| 251 | |
|---|
| 252 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
|---|
| 253 | uiInitialCpbRemovalDelay -= uiTmp; |
|---|
| 254 | uiInitialCpbRemovalDelay -= uiTmp / ( slice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
|---|
| 255 | bufferingPeriodSEI->m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
|---|
| 256 | bufferingPeriodSEI->m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
|---|
| 257 | bufferingPeriodSEI->m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
|---|
| 258 | bufferingPeriodSEI->m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
|---|
| 259 | |
|---|
| 260 | bufferingPeriodSEI->m_rapCpbParamsPresentFlag = 0; |
|---|
| 261 | //for the concatenation, it can be set to one during splicing. |
|---|
| 262 | bufferingPeriodSEI->m_concatenationFlag = 0; |
|---|
| 263 | //since the temporal layer HRD is not ready, we assumed it is fixed |
|---|
| 264 | bufferingPeriodSEI->m_auCpbRemovalDelayDelta = 1; |
|---|
| 265 | bufferingPeriodSEI->m_cpbDelayOffset = 0; |
|---|
| 266 | bufferingPeriodSEI->m_dpbDelayOffset = 0; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | //! initialize scalable nesting SEI message. |
|---|
| 270 | //! Note: The SEI message structures input into this function will become part of the scalable nesting SEI and will be |
|---|
| 271 | //! automatically freed, when the nesting SEI is disposed. |
|---|
| 272 | Void SEIEncoder::initSEIScalableNesting(SEIScalableNesting *scalableNestingSEI, SEIMessages &nestedSEIs) |
|---|
| 273 | { |
|---|
| 274 | assert (m_isInitialized); |
|---|
| 275 | assert (scalableNestingSEI != NULL); |
|---|
| 276 | |
|---|
| 277 | scalableNestingSEI->m_bitStreamSubsetFlag = 1; // If the nested SEI messages are picture buffering SEI messages, picture timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1 |
|---|
| 278 | scalableNestingSEI->m_nestingOpFlag = 0; |
|---|
| 279 | scalableNestingSEI->m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 |
|---|
| 280 | scalableNestingSEI->m_allLayersFlag = 0; |
|---|
| 281 | scalableNestingSEI->m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 |
|---|
| 282 | scalableNestingSEI->m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 |
|---|
| 283 | scalableNestingSEI->m_nestingLayerId[0] = 0; |
|---|
| 284 | |
|---|
| 285 | scalableNestingSEI->m_nestedSEIs.clear(); |
|---|
| 286 | for (SEIMessages::iterator it=nestedSEIs.begin(); it!=nestedSEIs.end(); it++) |
|---|
| 287 | { |
|---|
| 288 | scalableNestingSEI->m_nestedSEIs.push_back((*it)); |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | Void SEIEncoder::initSEIRecoveryPoint(SEIRecoveryPoint *recoveryPointSEI, TComSlice *slice) |
|---|
| 293 | { |
|---|
| 294 | assert (m_isInitialized); |
|---|
| 295 | assert (recoveryPointSEI != NULL); |
|---|
| 296 | assert (slice != NULL); |
|---|
| 297 | |
|---|
| 298 | recoveryPointSEI->m_recoveryPocCnt = 0; |
|---|
| 299 | #if SVC_EXTENSION |
|---|
| 300 | recoveryPointSEI->m_exactMatchingFlag = ( slice->getPocValueBeforeReset() == 0 ) ? (true) : (false); |
|---|
| 301 | #else |
|---|
| 302 | recoveryPointSEI->m_exactMatchingFlag = ( slice->getPOC() == 0 ) ? (true) : (false); |
|---|
| 303 | #endif |
|---|
| 304 | recoveryPointSEI->m_brokenLinkFlag = false; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | //! calculate hashes for entire reconstructed picture |
|---|
| 308 | Void SEIEncoder::initDecodedPictureHashSEI(SEIDecodedPictureHash *decodedPictureHashSEI, TComPic *pcPic, std::string &rHashString, const BitDepths &bitDepths) |
|---|
| 309 | { |
|---|
| 310 | assert (m_isInitialized); |
|---|
| 311 | assert (decodedPictureHashSEI!=NULL); |
|---|
| 312 | assert (pcPic!=NULL); |
|---|
| 313 | |
|---|
| 314 | decodedPictureHashSEI->method = m_pcCfg->getDecodedPictureHashSEIType(); |
|---|
| 315 | switch (m_pcCfg->getDecodedPictureHashSEIType()) |
|---|
| 316 | { |
|---|
| 317 | case HASHTYPE_MD5: |
|---|
| 318 | { |
|---|
| 319 | UInt numChar=calcMD5(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths); |
|---|
| 320 | rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar); |
|---|
| 321 | } |
|---|
| 322 | break; |
|---|
| 323 | case HASHTYPE_CRC: |
|---|
| 324 | { |
|---|
| 325 | UInt numChar=calcCRC(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths); |
|---|
| 326 | rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar); |
|---|
| 327 | } |
|---|
| 328 | break; |
|---|
| 329 | case HASHTYPE_CHECKSUM: |
|---|
| 330 | default: |
|---|
| 331 | { |
|---|
| 332 | UInt numChar=calcChecksum(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths); |
|---|
| 333 | rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar); |
|---|
| 334 | } |
|---|
| 335 | break; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | Void SEIEncoder::initTemporalLevel0IndexSEI(SEITemporalLevel0Index *temporalLevel0IndexSEI, TComSlice *slice) |
|---|
| 340 | { |
|---|
| 341 | assert (m_isInitialized); |
|---|
| 342 | assert (temporalLevel0IndexSEI!=NULL); |
|---|
| 343 | assert (slice!=NULL); |
|---|
| 344 | |
|---|
| 345 | if (slice->getRapPicFlag()) |
|---|
| 346 | { |
|---|
| 347 | m_tl0Idx = 0; |
|---|
| 348 | m_rapIdx = (m_rapIdx + 1) & 0xFF; |
|---|
| 349 | } |
|---|
| 350 | else |
|---|
| 351 | { |
|---|
| 352 | m_tl0Idx = (m_tl0Idx + (slice->getTLayer() ? 0 : 1)) & 0xFF; |
|---|
| 353 | } |
|---|
| 354 | temporalLevel0IndexSEI->tl0Idx = m_tl0Idx; |
|---|
| 355 | temporalLevel0IndexSEI->rapIdx = m_rapIdx; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | Void SEIEncoder::initSEITempMotionConstrainedTileSets (SEITempMotionConstrainedTileSets *sei, const TComPPS *pps) |
|---|
| 359 | { |
|---|
| 360 | assert (m_isInitialized); |
|---|
| 361 | assert (sei!=NULL); |
|---|
| 362 | assert (pps!=NULL); |
|---|
| 363 | |
|---|
| 364 | if(pps->getTilesEnabledFlag()) |
|---|
| 365 | { |
|---|
| 366 | sei->m_mc_all_tiles_exact_sample_value_match_flag = false; |
|---|
| 367 | sei->m_each_tile_one_tile_set_flag = false; |
|---|
| 368 | sei->m_limited_tile_set_display_flag = false; |
|---|
| 369 | sei->setNumberOfTileSets((pps->getNumTileColumnsMinus1() + 1) * (pps->getNumTileRowsMinus1() + 1)); |
|---|
| 370 | |
|---|
| 371 | for(Int i=0; i < sei->getNumberOfTileSets(); i++) |
|---|
| 372 | { |
|---|
| 373 | sei->tileSetData(i).m_mcts_id = i; //depends the application; |
|---|
| 374 | sei->tileSetData(i).setNumberOfTileRects(1); |
|---|
| 375 | |
|---|
| 376 | for(Int j=0; j<sei->tileSetData(i).getNumberOfTileRects(); j++) |
|---|
| 377 | { |
|---|
| 378 | sei->tileSetData(i).topLeftTileIndex(j) = i+j; |
|---|
| 379 | sei->tileSetData(i).bottomRightTileIndex(j) = i+j; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | sei->tileSetData(i).m_exact_sample_value_match_flag = false; |
|---|
| 383 | sei->tileSetData(i).m_mcts_tier_level_idc_present_flag = false; |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | else |
|---|
| 387 | { |
|---|
| 388 | assert(!"Tile is not enabled"); |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | Void SEIEncoder::initSEIKneeFunctionInfo(SEIKneeFunctionInfo *seiKneeFunctionInfo) |
|---|
| 393 | { |
|---|
| 394 | assert (m_isInitialized); |
|---|
| 395 | assert (seiKneeFunctionInfo!=NULL); |
|---|
| 396 | |
|---|
| 397 | seiKneeFunctionInfo->m_kneeId = m_pcCfg->getKneeSEIId(); |
|---|
| 398 | seiKneeFunctionInfo->m_kneeCancelFlag = m_pcCfg->getKneeSEICancelFlag(); |
|---|
| 399 | if ( !seiKneeFunctionInfo->m_kneeCancelFlag ) |
|---|
| 400 | { |
|---|
| 401 | seiKneeFunctionInfo->m_kneePersistenceFlag = m_pcCfg->getKneeSEIPersistenceFlag(); |
|---|
| 402 | seiKneeFunctionInfo->m_kneeInputDrange = m_pcCfg->getKneeSEIInputDrange(); |
|---|
| 403 | seiKneeFunctionInfo->m_kneeInputDispLuminance = m_pcCfg->getKneeSEIInputDispLuminance(); |
|---|
| 404 | seiKneeFunctionInfo->m_kneeOutputDrange = m_pcCfg->getKneeSEIOutputDrange(); |
|---|
| 405 | seiKneeFunctionInfo->m_kneeOutputDispLuminance = m_pcCfg->getKneeSEIOutputDispLuminance(); |
|---|
| 406 | |
|---|
| 407 | seiKneeFunctionInfo->m_kneeNumKneePointsMinus1 = m_pcCfg->getKneeSEINumKneePointsMinus1(); |
|---|
| 408 | Int* piInputKneePoint = m_pcCfg->getKneeSEIInputKneePoint(); |
|---|
| 409 | Int* piOutputKneePoint = m_pcCfg->getKneeSEIOutputKneePoint(); |
|---|
| 410 | if(piInputKneePoint&&piOutputKneePoint) |
|---|
| 411 | { |
|---|
| 412 | seiKneeFunctionInfo->m_kneeInputKneePoint.resize(seiKneeFunctionInfo->m_kneeNumKneePointsMinus1+1); |
|---|
| 413 | seiKneeFunctionInfo->m_kneeOutputKneePoint.resize(seiKneeFunctionInfo->m_kneeNumKneePointsMinus1+1); |
|---|
| 414 | for(Int i=0; i<=seiKneeFunctionInfo->m_kneeNumKneePointsMinus1; i++) |
|---|
| 415 | { |
|---|
| 416 | seiKneeFunctionInfo->m_kneeInputKneePoint[i] = piInputKneePoint[i]; |
|---|
| 417 | seiKneeFunctionInfo->m_kneeOutputKneePoint[i] = piOutputKneePoint[i]; |
|---|
| 418 | } |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | template <typename T> |
|---|
| 424 | static Void readTokenValue(T &returnedValue, /// value returned |
|---|
| 425 | Bool &failed, /// used and updated |
|---|
| 426 | std::istream &is, /// stream to read token from |
|---|
| 427 | const TChar *pToken) /// token string |
|---|
| 428 | { |
|---|
| 429 | returnedValue=T(); |
|---|
| 430 | if (failed) |
|---|
| 431 | { |
|---|
| 432 | return; |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | Int c; |
|---|
| 436 | // Ignore any whitespace |
|---|
| 437 | while ((c=is.get())!=EOF && isspace(c)); |
|---|
| 438 | // test for comment mark |
|---|
| 439 | while (c=='#') |
|---|
| 440 | { |
|---|
| 441 | // Ignore to the end of the line |
|---|
| 442 | while ((c=is.get())!=EOF && (c!=10 && c!=13)); |
|---|
| 443 | // Ignore any white space at the start of the next line |
|---|
| 444 | while ((c=is.get())!=EOF && isspace(c)); |
|---|
| 445 | } |
|---|
| 446 | // test first character of token |
|---|
| 447 | failed=(c!=pToken[0]); |
|---|
| 448 | // test remaining characters of token |
|---|
| 449 | Int pos; |
|---|
| 450 | for(pos=1;!failed && pToken[pos]!=0 && is.get()==pToken[pos]; pos++); |
|---|
| 451 | failed|=(pToken[pos]!=0); |
|---|
| 452 | // Ignore any whitespace before the ':' |
|---|
| 453 | while (!failed && (c=is.get())!=EOF && isspace(c)); |
|---|
| 454 | failed|=(c!=':'); |
|---|
| 455 | // Now read the value associated with the token: |
|---|
| 456 | if (!failed) |
|---|
| 457 | { |
|---|
| 458 | is >> returnedValue; |
|---|
| 459 | failed=!is.good(); |
|---|
| 460 | if (!failed) |
|---|
| 461 | { |
|---|
| 462 | c=is.get(); |
|---|
| 463 | failed=(c!=EOF && !isspace(c)); |
|---|
| 464 | } |
|---|
| 465 | } |
|---|
| 466 | if (failed) |
|---|
| 467 | { |
|---|
| 468 | std::cerr << "Unable to read token '" << pToken << "'\n"; |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | template <typename T> |
|---|
| 473 | static Void readTokenValueAndValidate(T &returnedValue, /// value returned |
|---|
| 474 | Bool &failed, /// used and updated |
|---|
| 475 | std::istream &is, /// stream to read token from |
|---|
| 476 | const TChar *pToken, /// token string |
|---|
| 477 | const T &minInclusive, /// minimum value allowed, inclusive |
|---|
| 478 | const T &maxInclusive) /// maximum value allowed, inclusive |
|---|
| 479 | { |
|---|
| 480 | readTokenValue(returnedValue, failed, is, pToken); |
|---|
| 481 | if (!failed) |
|---|
| 482 | { |
|---|
| 483 | if (returnedValue<minInclusive || returnedValue>maxInclusive) |
|---|
| 484 | { |
|---|
| 485 | failed=true; |
|---|
| 486 | std::cerr << "Value for token " << pToken << " must be in the range " << minInclusive << " to " << maxInclusive << " (inclusive); value read: " << returnedValue << std::endl; |
|---|
| 487 | } |
|---|
| 488 | } |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | // Bool version does not have maximum and minimum values. |
|---|
| 492 | static Void readTokenValueAndValidate(Bool &returnedValue, /// value returned |
|---|
| 493 | Bool &failed, /// used and updated |
|---|
| 494 | std::istream &is, /// stream to read token from |
|---|
| 495 | const TChar *pToken) /// token string |
|---|
| 496 | { |
|---|
| 497 | readTokenValue(returnedValue, failed, is, pToken); |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | Bool SEIEncoder::initSEIColourRemappingInfo(SEIColourRemappingInfo* seiColourRemappingInfo, Int currPOC) // returns true on success, false on failure. |
|---|
| 501 | { |
|---|
| 502 | assert (m_isInitialized); |
|---|
| 503 | assert (seiColourRemappingInfo!=NULL); |
|---|
| 504 | |
|---|
| 505 | // reading external Colour Remapping Information SEI message parameters from file |
|---|
| 506 | if( !m_pcCfg->getColourRemapInfoSEIFileRoot().empty()) |
|---|
| 507 | { |
|---|
| 508 | Bool failed=false; |
|---|
| 509 | |
|---|
| 510 | // building the CRI file name with poc num in prefix "_poc.txt" |
|---|
| 511 | std::string colourRemapSEIFileWithPoc(m_pcCfg->getColourRemapInfoSEIFileRoot()); |
|---|
| 512 | { |
|---|
| 513 | std::stringstream suffix; |
|---|
| 514 | suffix << "_" << currPOC << ".txt"; |
|---|
| 515 | colourRemapSEIFileWithPoc+=suffix.str(); |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | std::ifstream fic(colourRemapSEIFileWithPoc.c_str()); |
|---|
| 519 | if (!fic.good() || !fic.is_open()) |
|---|
| 520 | { |
|---|
| 521 | std::cerr << "No Colour Remapping Information SEI parameters file " << colourRemapSEIFileWithPoc << " for POC " << currPOC << std::endl; |
|---|
| 522 | return false; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | // TODO: identify and remove duplication with decoder parsing through abstraction. |
|---|
| 526 | |
|---|
| 527 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapId, failed, fic, "colour_remap_id", UInt(0), UInt(0x7fffffff) ); |
|---|
| 528 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCancelFlag, failed, fic, "colour_remap_cancel_flag" ); |
|---|
| 529 | if( !seiColourRemappingInfo->m_colourRemapCancelFlag ) |
|---|
| 530 | { |
|---|
| 531 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPersistenceFlag, failed, fic, "colour_remap_persistence_flag" ); |
|---|
| 532 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag, failed, fic, "colour_remap_video_signal_info_present_flag"); |
|---|
| 533 | if( seiColourRemappingInfo->m_colourRemapVideoSignalInfoPresentFlag ) |
|---|
| 534 | { |
|---|
| 535 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapFullRangeFlag, failed, fic, "colour_remap_full_range_flag" ); |
|---|
| 536 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapPrimaries, failed, fic, "colour_remap_primaries", Int(0), Int(255) ); |
|---|
| 537 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapTransferFunction, failed, fic, "colour_remap_transfer_function", Int(0), Int(255) ); |
|---|
| 538 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixCoefficients, failed, fic, "colour_remap_matrix_coefficients", Int(0), Int(255) ); |
|---|
| 539 | } |
|---|
| 540 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapInputBitDepth, failed, fic, "colour_remap_input_bit_depth", Int(8), Int(16) ); |
|---|
| 541 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapBitDepth, failed, fic, "colour_remap_bit_depth", Int(8), Int(16) ); |
|---|
| 542 | |
|---|
| 543 | const Int maximumInputValue = (1 << (((seiColourRemappingInfo->m_colourRemapInputBitDepth + 7) >> 3) << 3)) - 1; |
|---|
| 544 | const Int maximumRemappedValue = (1 << (((seiColourRemappingInfo->m_colourRemapBitDepth + 7) >> 3) << 3)) - 1; |
|---|
| 545 | |
|---|
| 546 | for( Int c=0 ; c<3 ; c++ ) |
|---|
| 547 | { |
|---|
| 548 | readTokenValueAndValidate(seiColourRemappingInfo->m_preLutNumValMinus1[c], failed, fic, "pre_lut_num_val_minus1[c]", Int(0), Int(32) ); |
|---|
| 549 | if( seiColourRemappingInfo->m_preLutNumValMinus1[c]>0 ) |
|---|
| 550 | { |
|---|
| 551 | seiColourRemappingInfo->m_preLut[c].resize(seiColourRemappingInfo->m_preLutNumValMinus1[c]+1); |
|---|
| 552 | for( Int i=0 ; i<=seiColourRemappingInfo->m_preLutNumValMinus1[c] ; i++ ) |
|---|
| 553 | { |
|---|
| 554 | readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].codedValue, failed, fic, "pre_lut_coded_value[c][i]", Int(0), maximumInputValue ); |
|---|
| 555 | readTokenValueAndValidate(seiColourRemappingInfo->m_preLut[c][i].targetValue, failed, fic, "pre_lut_target_value[c][i]", Int(0), maximumRemappedValue ); |
|---|
| 556 | } |
|---|
| 557 | } |
|---|
| 558 | } |
|---|
| 559 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapMatrixPresentFlag, failed, fic, "colour_remap_matrix_present_flag" ); |
|---|
| 560 | if( seiColourRemappingInfo->m_colourRemapMatrixPresentFlag ) |
|---|
| 561 | { |
|---|
| 562 | readTokenValueAndValidate(seiColourRemappingInfo->m_log2MatrixDenom, failed, fic, "log2_matrix_denom", Int(0), Int(15) ); |
|---|
| 563 | for( Int c=0 ; c<3 ; c++ ) |
|---|
| 564 | { |
|---|
| 565 | for( Int i=0 ; i<3 ; i++ ) |
|---|
| 566 | { |
|---|
| 567 | readTokenValueAndValidate(seiColourRemappingInfo->m_colourRemapCoeffs[c][i], failed, fic, "colour_remap_coeffs[c][i]", -32768, 32767 ); |
|---|
| 568 | } |
|---|
| 569 | } |
|---|
| 570 | } |
|---|
| 571 | for( Int c=0 ; c<3 ; c++ ) |
|---|
| 572 | { |
|---|
| 573 | readTokenValueAndValidate(seiColourRemappingInfo->m_postLutNumValMinus1[c], failed, fic, "post_lut_num_val_minus1[c]", Int(0), Int(32) ); |
|---|
| 574 | if( seiColourRemappingInfo->m_postLutNumValMinus1[c]>0 ) |
|---|
| 575 | { |
|---|
| 576 | seiColourRemappingInfo->m_postLut[c].resize(seiColourRemappingInfo->m_postLutNumValMinus1[c]+1); |
|---|
| 577 | for( Int i=0 ; i<=seiColourRemappingInfo->m_postLutNumValMinus1[c] ; i++ ) |
|---|
| 578 | { |
|---|
| 579 | readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].codedValue, failed, fic, "post_lut_coded_value[c][i]", Int(0), maximumRemappedValue ); |
|---|
| 580 | readTokenValueAndValidate(seiColourRemappingInfo->m_postLut[c][i].targetValue, failed, fic, "post_lut_target_value[c][i]", Int(0), maximumRemappedValue ); |
|---|
| 581 | } |
|---|
| 582 | } |
|---|
| 583 | } |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | if( failed ) |
|---|
| 587 | { |
|---|
| 588 | std::cerr << "Error while reading Colour Remapping Information SEI parameters file '" << colourRemapSEIFileWithPoc << "'" << std::endl; |
|---|
| 589 | exit(EXIT_FAILURE); |
|---|
| 590 | } |
|---|
| 591 | } |
|---|
| 592 | return true; |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | Void SEIEncoder::initSEIChromaResamplingFilterHint(SEIChromaResamplingFilterHint *seiChromaResamplingFilterHint, Int iHorFilterIndex, Int iVerFilterIndex) |
|---|
| 596 | { |
|---|
| 597 | assert (m_isInitialized); |
|---|
| 598 | assert (seiChromaResamplingFilterHint!=NULL); |
|---|
| 599 | |
|---|
| 600 | seiChromaResamplingFilterHint->m_verChromaFilterIdc = iVerFilterIndex; |
|---|
| 601 | seiChromaResamplingFilterHint->m_horChromaFilterIdc = iHorFilterIndex; |
|---|
| 602 | seiChromaResamplingFilterHint->m_verFilteringFieldProcessingFlag = 1; |
|---|
| 603 | seiChromaResamplingFilterHint->m_targetFormatIdc = 3; |
|---|
| 604 | seiChromaResamplingFilterHint->m_perfectReconstructionFlag = false; |
|---|
| 605 | |
|---|
| 606 | // this creates some example filter values, if explicit filter definition is selected |
|---|
| 607 | if (seiChromaResamplingFilterHint->m_verChromaFilterIdc == 1) |
|---|
| 608 | { |
|---|
| 609 | const Int numVerticalFilters = 3; |
|---|
| 610 | const Int verTapLengthMinus1[] = {5,3,3}; |
|---|
| 611 | |
|---|
| 612 | seiChromaResamplingFilterHint->m_verFilterCoeff.resize(numVerticalFilters); |
|---|
| 613 | for(Int i = 0; i < numVerticalFilters; i ++) |
|---|
| 614 | { |
|---|
| 615 | seiChromaResamplingFilterHint->m_verFilterCoeff[i].resize(verTapLengthMinus1[i]+1); |
|---|
| 616 | } |
|---|
| 617 | // Note: C++11 -> seiChromaResamplingFilterHint->m_verFilterCoeff[0] = {-3,13,31,23,3,-3}; |
|---|
| 618 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][0] = -3; |
|---|
| 619 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][1] = 13; |
|---|
| 620 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][2] = 31; |
|---|
| 621 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][3] = 23; |
|---|
| 622 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][4] = 3; |
|---|
| 623 | seiChromaResamplingFilterHint->m_verFilterCoeff[0][5] = -3; |
|---|
| 624 | |
|---|
| 625 | seiChromaResamplingFilterHint->m_verFilterCoeff[1][0] = -1; |
|---|
| 626 | seiChromaResamplingFilterHint->m_verFilterCoeff[1][1] = 25; |
|---|
| 627 | seiChromaResamplingFilterHint->m_verFilterCoeff[1][2] = 247; |
|---|
| 628 | seiChromaResamplingFilterHint->m_verFilterCoeff[1][3] = -15; |
|---|
| 629 | |
|---|
| 630 | seiChromaResamplingFilterHint->m_verFilterCoeff[2][0] = -20; |
|---|
| 631 | seiChromaResamplingFilterHint->m_verFilterCoeff[2][1] = 186; |
|---|
| 632 | seiChromaResamplingFilterHint->m_verFilterCoeff[2][2] = 100; |
|---|
| 633 | seiChromaResamplingFilterHint->m_verFilterCoeff[2][3] = -10; |
|---|
| 634 | } |
|---|
| 635 | else |
|---|
| 636 | { |
|---|
| 637 | seiChromaResamplingFilterHint->m_verFilterCoeff.resize(0); |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | if (seiChromaResamplingFilterHint->m_horChromaFilterIdc == 1) |
|---|
| 641 | { |
|---|
| 642 | Int const numHorizontalFilters = 1; |
|---|
| 643 | const Int horTapLengthMinus1[] = {3}; |
|---|
| 644 | |
|---|
| 645 | seiChromaResamplingFilterHint->m_horFilterCoeff.resize(numHorizontalFilters); |
|---|
| 646 | for(Int i = 0; i < numHorizontalFilters; i ++) |
|---|
| 647 | { |
|---|
| 648 | seiChromaResamplingFilterHint->m_horFilterCoeff[i].resize(horTapLengthMinus1[i]+1); |
|---|
| 649 | } |
|---|
| 650 | seiChromaResamplingFilterHint->m_horFilterCoeff[0][0] = 1; |
|---|
| 651 | seiChromaResamplingFilterHint->m_horFilterCoeff[0][1] = 6; |
|---|
| 652 | seiChromaResamplingFilterHint->m_horFilterCoeff[0][2] = 1; |
|---|
| 653 | } |
|---|
| 654 | else |
|---|
| 655 | { |
|---|
| 656 | seiChromaResamplingFilterHint->m_horFilterCoeff.resize(0); |
|---|
| 657 | } |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | Void SEIEncoder::initSEITimeCode(SEITimeCode *seiTimeCode) |
|---|
| 661 | { |
|---|
| 662 | assert (m_isInitialized); |
|---|
| 663 | assert (seiTimeCode!=NULL); |
|---|
| 664 | // Set data as per command line options |
|---|
| 665 | seiTimeCode->numClockTs = m_pcCfg->getNumberOfTimesets(); |
|---|
| 666 | for(Int i = 0; i < seiTimeCode->numClockTs; i++) |
|---|
| 667 | { |
|---|
| 668 | seiTimeCode->timeSetArray[i] = m_pcCfg->getTimeSet(i); |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | #if LAYERS_NOT_PRESENT_SEI |
|---|
| 673 | Void SEIEncoder::initSEILayersNotPresent(SEILayersNotPresent *seiLayersNotPresent) |
|---|
| 674 | { |
|---|
| 675 | UInt i = 0; |
|---|
| 676 | seiLayersNotPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId(); |
|---|
| 677 | seiLayersNotPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers(); |
|---|
| 678 | for ( ; i < seiLayersNotPresent->m_vpsMaxLayers; i++) |
|---|
| 679 | { |
|---|
| 680 | seiLayersNotPresent->m_layerNotPresentFlag[i] = true; |
|---|
| 681 | } |
|---|
| 682 | for ( ; i < MAX_LAYERS; i++) |
|---|
| 683 | { |
|---|
| 684 | seiLayersNotPresent->m_layerNotPresentFlag[i] = false; |
|---|
| 685 | } |
|---|
| 686 | } |
|---|
| 687 | #endif |
|---|
| 688 | |
|---|
| 689 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
|---|
| 690 | Void SEIEncoder::initSEIInterLayerConstrainedTileSets(SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets) |
|---|
| 691 | { |
|---|
| 692 | seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false; |
|---|
| 693 | seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false; |
|---|
| 694 | if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag) |
|---|
| 695 | { |
|---|
| 696 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1; |
|---|
| 697 | if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1) |
|---|
| 698 | { |
|---|
| 699 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag(); |
|---|
| 700 | } |
|---|
| 701 | else |
|---|
| 702 | { |
|---|
| 703 | seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false; |
|---|
| 704 | } |
|---|
| 705 | seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0; |
|---|
| 706 | for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++) |
|---|
| 707 | { |
|---|
| 708 | seiInterLayerConstrainedTileSets->m_ilctsId[i] = i; |
|---|
| 709 | seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0; |
|---|
| 710 | for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++) |
|---|
| 711 | { |
|---|
| 712 | seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j] = m_pcCfg->getTopLeftTileIndex(i); |
|---|
| 713 | seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i); |
|---|
| 714 | } |
|---|
| 715 | seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i); |
|---|
| 716 | if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag) |
|---|
| 717 | { |
|---|
| 718 | seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false; |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | } |
|---|
| 722 | } |
|---|
| 723 | #endif |
|---|
| 724 | |
|---|
| 725 | #if P0123_ALPHA_CHANNEL_SEI |
|---|
| 726 | Void SEIEncoder::initSEIAlphaChannelInfo(SEIAlphaChannelInfo *seiAlphaChannelInfo) |
|---|
| 727 | { |
|---|
| 728 | seiAlphaChannelInfo->m_alphaChannelCancelFlag = m_pcCfg->getAlphaCancelFlag(); |
|---|
| 729 | if(!seiAlphaChannelInfo->m_alphaChannelCancelFlag) |
|---|
| 730 | { |
|---|
| 731 | seiAlphaChannelInfo->m_alphaChannelUseIdc = m_pcCfg->getAlphaUseIdc(); |
|---|
| 732 | seiAlphaChannelInfo->m_alphaChannelBitDepthMinus8 = m_pcCfg->getAlphaBitDepthMinus8(); |
|---|
| 733 | seiAlphaChannelInfo->m_alphaTransparentValue = m_pcCfg->getAlphaTransparentValue(); |
|---|
| 734 | seiAlphaChannelInfo->m_alphaOpaqueValue = m_pcCfg->getAlphaOpaqueValue(); |
|---|
| 735 | seiAlphaChannelInfo->m_alphaChannelIncrFlag = m_pcCfg->getAlphaIncrementFlag(); |
|---|
| 736 | seiAlphaChannelInfo->m_alphaChannelClipFlag = m_pcCfg->getAlphaClipFlag(); |
|---|
| 737 | seiAlphaChannelInfo->m_alphaChannelClipTypeFlag = m_pcCfg->getAlphaClipTypeFlag(); |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | #endif |
|---|
| 741 | |
|---|
| 742 | #if Q0096_OVERLAY_SEI |
|---|
| 743 | Void SEIEncoder::initSEIOverlayInfo(SEIOverlayInfo *seiOverlayInfo) |
|---|
| 744 | { |
|---|
| 745 | seiOverlayInfo->m_overlayInfoCancelFlag = m_pcCfg->getOverlaySEICancelFlag(); |
|---|
| 746 | if ( !seiOverlayInfo->m_overlayInfoCancelFlag ) |
|---|
| 747 | { |
|---|
| 748 | seiOverlayInfo->m_overlayContentAuxIdMinus128 = m_pcCfg->getOverlaySEIContentAuxIdMinus128(); |
|---|
| 749 | seiOverlayInfo->m_overlayLabelAuxIdMinus128 = m_pcCfg->getOverlaySEILabelAuxIdMinus128(); |
|---|
| 750 | seiOverlayInfo->m_overlayAlphaAuxIdMinus128 = m_pcCfg->getOverlaySEIAlphaAuxIdMinus128(); |
|---|
| 751 | seiOverlayInfo->m_overlayElementLabelValueLengthMinus8 = m_pcCfg->getOverlaySEIElementLabelValueLengthMinus8(); |
|---|
| 752 | seiOverlayInfo->m_numOverlaysMinus1 = m_pcCfg->getOverlaySEINumOverlaysMinus1(); |
|---|
| 753 | seiOverlayInfo->m_overlayIdx = m_pcCfg->getOverlaySEIIdx(); |
|---|
| 754 | seiOverlayInfo->m_languageOverlayPresentFlag = m_pcCfg->getOverlaySEILanguagePresentFlag(); |
|---|
| 755 | seiOverlayInfo->m_overlayContentLayerId = m_pcCfg->getOverlaySEIContentLayerId(); |
|---|
| 756 | seiOverlayInfo->m_overlayLabelPresentFlag = m_pcCfg->getOverlaySEILabelPresentFlag(); |
|---|
| 757 | seiOverlayInfo->m_overlayLabelLayerId = m_pcCfg->getOverlaySEILabelLayerId(); |
|---|
| 758 | seiOverlayInfo->m_overlayAlphaPresentFlag = m_pcCfg->getOverlaySEIAlphaPresentFlag(); |
|---|
| 759 | seiOverlayInfo->m_overlayAlphaLayerId = m_pcCfg->getOverlaySEIAlphaLayerId(); |
|---|
| 760 | seiOverlayInfo->m_numOverlayElementsMinus1 = m_pcCfg->getOverlaySEINumElementsMinus1(); |
|---|
| 761 | seiOverlayInfo->m_overlayElementLabelMin = m_pcCfg->getOverlaySEIElementLabelMin(); |
|---|
| 762 | seiOverlayInfo->m_overlayElementLabelMax = m_pcCfg->getOverlaySEIElementLabelMax(); |
|---|
| 763 | seiOverlayInfo->m_overlayLanguage.resize ( seiOverlayInfo->m_numOverlaysMinus1+1, NULL ); |
|---|
| 764 | seiOverlayInfo->m_overlayLanguageLength.resize ( seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 765 | seiOverlayInfo->m_overlayName.resize ( seiOverlayInfo->m_numOverlaysMinus1+1, NULL ); |
|---|
| 766 | seiOverlayInfo->m_overlayNameLength.resize ( seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 767 | seiOverlayInfo->m_overlayElementName.resize ( seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 768 | seiOverlayInfo->m_overlayElementNameLength.resize ( seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 769 | |
|---|
| 770 | Int i,j; |
|---|
| 771 | string strTmp; |
|---|
| 772 | Int nBytes; |
|---|
| 773 | assert( m_pcCfg->getOverlaySEILanguage().size() == seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 774 | assert( m_pcCfg->getOverlaySEIName().size() == seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 775 | assert( m_pcCfg->getOverlaySEIElementName().size() == seiOverlayInfo->m_numOverlaysMinus1+1 ); |
|---|
| 776 | |
|---|
| 777 | for ( i=0 ; i<=seiOverlayInfo->m_numOverlaysMinus1; i++ ) |
|---|
| 778 | { |
|---|
| 779 | //language tag |
|---|
| 780 | if ( seiOverlayInfo->m_languageOverlayPresentFlag[i] ) |
|---|
| 781 | { |
|---|
| 782 | strTmp = m_pcCfg->getOverlaySEILanguage()[i]; |
|---|
| 783 | nBytes = (Int)m_pcCfg->getOverlaySEILanguage()[i].size(); |
|---|
| 784 | assert( nBytes>0 ); |
|---|
| 785 | seiOverlayInfo->m_overlayLanguage[i] = new UChar[nBytes]; |
|---|
| 786 | memcpy(seiOverlayInfo->m_overlayLanguage[i], strTmp.c_str(), nBytes); |
|---|
| 787 | seiOverlayInfo->m_overlayLanguageLength[i] = nBytes; |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | //overlay name |
|---|
| 791 | strTmp = m_pcCfg->getOverlaySEIName()[i]; |
|---|
| 792 | nBytes = (Int)m_pcCfg->getOverlaySEIName()[i].size(); |
|---|
| 793 | assert( nBytes>0 ); |
|---|
| 794 | seiOverlayInfo->m_overlayName[i] = new UChar[nBytes]; |
|---|
| 795 | memcpy(seiOverlayInfo->m_overlayName[i], strTmp.c_str(), nBytes); |
|---|
| 796 | seiOverlayInfo->m_overlayNameLength[i] = nBytes; |
|---|
| 797 | |
|---|
| 798 | //overlay element names |
|---|
| 799 | if ( seiOverlayInfo->m_overlayLabelPresentFlag[i] ) |
|---|
| 800 | { |
|---|
| 801 | seiOverlayInfo->m_overlayElementName[i].resize( seiOverlayInfo->m_numOverlayElementsMinus1[i]+1, NULL ); |
|---|
| 802 | seiOverlayInfo->m_overlayElementNameLength[i].resize( seiOverlayInfo->m_numOverlayElementsMinus1[i]+1 ); |
|---|
| 803 | assert( m_pcCfg->getOverlaySEIElementName()[i].size() == seiOverlayInfo->m_numOverlayElementsMinus1[i]+1 ); |
|---|
| 804 | for ( j=0 ; j<=seiOverlayInfo->m_numOverlayElementsMinus1[i] ; j++) |
|---|
| 805 | { |
|---|
| 806 | strTmp = m_pcCfg->getOverlaySEIElementName()[i][j]; |
|---|
| 807 | nBytes = (Int)m_pcCfg->getOverlaySEIElementName()[i][j].size(); |
|---|
| 808 | assert( nBytes>0 ); |
|---|
| 809 | seiOverlayInfo->m_overlayElementName[i][j] = new UChar[nBytes]; |
|---|
| 810 | memcpy(seiOverlayInfo->m_overlayElementName[i][j], strTmp.c_str(), nBytes); |
|---|
| 811 | seiOverlayInfo->m_overlayElementNameLength[i][j] = nBytes; |
|---|
| 812 | } |
|---|
| 813 | } |
|---|
| 814 | } |
|---|
| 815 | seiOverlayInfo->m_overlayInfoPersistenceFlag = true; |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | #endif |
|---|
| 819 | |
|---|
| 820 | #if O0164_MULTI_LAYER_HRD |
|---|
| 821 | Void SEIEncoder::initBspNestingSEI(SEIScalableNesting *seiScalableNesting, const TComVPS *vps, const TComSPS *sps, Int olsIdx, Int partitioningSchemeIdx, Int bspIdx) |
|---|
| 822 | { |
|---|
| 823 | SEIBspInitialArrivalTime *seiBspInitialArrivalTime = new SEIBspInitialArrivalTime(); |
|---|
| 824 | SEIBspNesting *seiBspNesting = new SEIBspNesting(); |
|---|
| 825 | SEIBufferingPeriod *seiBufferingPeriod = new SEIBufferingPeriod(); |
|---|
| 826 | |
|---|
| 827 | // Scalable nesting SEI |
|---|
| 828 | |
|---|
| 829 | seiScalableNesting->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 |
|---|
| 830 | seiScalableNesting->m_nestingOpFlag = 1; |
|---|
| 831 | seiScalableNesting->m_defaultOpFlag = 0; |
|---|
| 832 | seiScalableNesting->m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 |
|---|
| 833 | seiScalableNesting->m_nestingOpIdx[0] = vps->getOutputLayerSetIdx(olsIdx); |
|---|
| 834 | seiScalableNesting->m_nestingMaxTemporalIdPlus1[0] = 6 + 1; |
|---|
| 835 | seiScalableNesting->m_allLayersFlag = 0; |
|---|
| 836 | seiScalableNesting->m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 |
|---|
| 837 | seiScalableNesting->m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 |
|---|
| 838 | seiScalableNesting->m_nestingLayerId[0] = 0; |
|---|
| 839 | |
|---|
| 840 | // Bitstream partition nesting SEI |
|---|
| 841 | seiBspNesting->m_bspIdx = 0; |
|---|
| 842 | |
|---|
| 843 | // Buffering period SEI |
|---|
| 844 | |
|---|
| 845 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
|---|
| 846 | seiBufferingPeriod->m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
|---|
| 847 | seiBufferingPeriod->m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
|---|
| 848 | seiBufferingPeriod->m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
|---|
| 849 | seiBufferingPeriod->m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
|---|
| 850 | |
|---|
| 851 | Double dTmp = (Double)sps->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)sps->getVuiParameters()->getTimingInfo()->getTimeScale(); |
|---|
| 852 | |
|---|
| 853 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
|---|
| 854 | uiInitialCpbRemovalDelay -= uiTmp; |
|---|
| 855 | uiInitialCpbRemovalDelay -= uiTmp / ( sps->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
|---|
| 856 | seiBufferingPeriod->m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
|---|
| 857 | seiBufferingPeriod->m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
|---|
| 858 | seiBufferingPeriod->m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
|---|
| 859 | seiBufferingPeriod->m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
|---|
| 860 | |
|---|
| 861 | seiBufferingPeriod->m_rapCpbParamsPresentFlag = 0; |
|---|
| 862 | //for the concatenation, it can be set to one during splicing. |
|---|
| 863 | seiBufferingPeriod->m_concatenationFlag = 0; |
|---|
| 864 | //since the temporal layer HRD is not ready, we assumed it is fixed |
|---|
| 865 | seiBufferingPeriod->m_auCpbRemovalDelayDelta = 1; |
|---|
| 866 | seiBufferingPeriod->m_cpbDelayOffset = 0; |
|---|
| 867 | seiBufferingPeriod->m_dpbDelayOffset = 0; |
|---|
| 868 | |
|---|
| 869 | // Intial arrival time SEI message |
|---|
| 870 | |
|---|
| 871 | seiBspInitialArrivalTime->m_nalInitialArrivalDelay[0] = 0; |
|---|
| 872 | seiBspInitialArrivalTime->m_vclInitialArrivalDelay[0] = 0; |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | seiBspNesting->m_nestedSEIs.push_back(seiBufferingPeriod); |
|---|
| 876 | seiBspNesting->m_nestedSEIs.push_back(seiBspInitialArrivalTime); |
|---|
| 877 | seiBspNesting->m_bspIdx = bspIdx; |
|---|
| 878 | seiBspNesting->m_seiOlsIdx = olsIdx; |
|---|
| 879 | seiBspNesting->m_seiPartitioningSchemeIdx = partitioningSchemeIdx; |
|---|
| 880 | seiScalableNesting->m_nestedSEIs.push_back(seiBspNesting); // BSP nesting SEI is contained in scalable nesting SEI |
|---|
| 881 | } |
|---|
| 882 | #endif |
|---|
| 883 | |
|---|
| 884 | //! \} |
|---|