| 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 | /** \file TAppEncTop.cpp |
|---|
| 35 | \brief Encoder application class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include <list> |
|---|
| 39 | #include <fstream> |
|---|
| 40 | #include <stdlib.h> |
|---|
| 41 | #include <stdio.h> |
|---|
| 42 | #include <fcntl.h> |
|---|
| 43 | #include <assert.h> |
|---|
| 44 | #include <iomanip> |
|---|
| 45 | |
|---|
| 46 | #include "TAppEncTop.h" |
|---|
| 47 | #include "TLibEncoder/AnnexBwrite.h" |
|---|
| 48 | |
|---|
| 49 | using namespace std; |
|---|
| 50 | |
|---|
| 51 | //! \ingroup TAppEncoder |
|---|
| 52 | //! \{ |
|---|
| 53 | |
|---|
| 54 | // ==================================================================================================================== |
|---|
| 55 | // Constructor / destructor / initialization / destroy |
|---|
| 56 | // ==================================================================================================================== |
|---|
| 57 | |
|---|
| 58 | TAppEncTop::TAppEncTop() |
|---|
| 59 | { |
|---|
| 60 | |
|---|
| 61 | #if NH_MV |
|---|
| 62 | m_vps = new TComVPS; |
|---|
| 63 | #else |
|---|
| 64 | m_iFrameRcvd = 0; |
|---|
| 65 | #endif |
|---|
| 66 | m_totalBytes = 0; |
|---|
| 67 | m_essentialBytes = 0; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | TAppEncTop::~TAppEncTop() |
|---|
| 71 | { |
|---|
| 72 | #if NH_MV |
|---|
| 73 | if (m_vps) |
|---|
| 74 | { |
|---|
| 75 | delete m_vps; |
|---|
| 76 | }; |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | Void TAppEncTop::xInitLibCfg() |
|---|
| 82 | { |
|---|
| 83 | #if NH_MV |
|---|
| 84 | TComVPS& vps = (*m_vps); |
|---|
| 85 | #else |
|---|
| 86 | TComVPS vps; |
|---|
| 87 | #endif |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | #if NH_MV |
|---|
| 92 | Int maxTempLayer = -1; |
|---|
| 93 | for (Int j = 0; j < m_numberOfLayers; j++) |
|---|
| 94 | { |
|---|
| 95 | maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | vps.setMaxTLayers ( maxTempLayer ); |
|---|
| 99 | if ( maxTempLayer ) |
|---|
| 100 | { |
|---|
| 101 | vps.setTemporalNestingFlag(true); |
|---|
| 102 | } |
|---|
| 103 | vps.setMaxLayersMinus1( m_numberOfLayers - 1); |
|---|
| 104 | for(Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 105 | { |
|---|
| 106 | Int maxNumReOrderPics = 0; |
|---|
| 107 | Int maxDecPicBuffering = 0; |
|---|
| 108 | for (Int j = 0; j < m_numberOfLayers; j++) |
|---|
| 109 | { |
|---|
| 110 | maxNumReOrderPics = max( maxNumReOrderPics, m_numReorderPicsMvc [ j ][ i ] ); |
|---|
| 111 | maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] ); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | vps.setNumReorderPics ( maxNumReOrderPics ,i ); |
|---|
| 115 | vps.setMaxDecPicBuffering ( maxDecPicBuffering ,i ); |
|---|
| 116 | } |
|---|
| 117 | #else |
|---|
| 118 | vps.setMaxTLayers ( m_maxTempLayer ); |
|---|
| 119 | if (m_maxTempLayer == 1) |
|---|
| 120 | { |
|---|
| 121 | vps.setTemporalNestingFlag(true); |
|---|
| 122 | } |
|---|
| 123 | vps.setMaxLayers ( 1 ); |
|---|
| 124 | for(Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 125 | { |
|---|
| 126 | vps.setNumReorderPics ( m_numReorderPics[i], i ); |
|---|
| 127 | vps.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
|---|
| 128 | } |
|---|
| 129 | #endif |
|---|
| 130 | #if NH_MV |
|---|
| 131 | xSetTimingInfo ( vps ); |
|---|
| 132 | xSetHrdParameters ( vps ); |
|---|
| 133 | xSetLayerIds ( vps ); |
|---|
| 134 | xSetDimensionIdAndLength ( vps ); |
|---|
| 135 | xSetDependencies ( vps ); |
|---|
| 136 | xSetRepFormat ( vps ); |
|---|
| 137 | xSetProfileTierLevel ( vps ); |
|---|
| 138 | xSetLayerSets ( vps ); |
|---|
| 139 | xSetDpbSize ( vps ); |
|---|
| 140 | xSetVPSVUI ( vps ); |
|---|
| 141 | if ( m_targetEncLayerIdList.size() == 0 ) |
|---|
| 142 | { |
|---|
| 143 | for (Int i = 0; i < m_numberOfLayers; i++ ) |
|---|
| 144 | { |
|---|
| 145 | m_targetEncLayerIdList.push_back( vps.getLayerIdInNuh( i ) ); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | for( Int i = (Int) m_targetEncLayerIdList.size()-1 ; i >= 0 ; i--) |
|---|
| 149 | { |
|---|
| 150 | Int iNuhLayerId = m_targetEncLayerIdList[i]; |
|---|
| 151 | Bool allRefLayersPresent = true; |
|---|
| 152 | for( Int j = 0; j < vps.getNumRefLayers( iNuhLayerId ); j++) |
|---|
| 153 | { |
|---|
| 154 | allRefLayersPresent = allRefLayersPresent && xLayerIdInTargetEncLayerIdList( vps.getIdRefLayer( iNuhLayerId, j) ); |
|---|
| 155 | } |
|---|
| 156 | if ( !allRefLayersPresent ) |
|---|
| 157 | { |
|---|
| 158 | printf("\nCannot encode layer with nuh_layer_id equal to %d since not all reference layers are in TargetEncLayerIdList\n", iNuhLayerId); |
|---|
| 159 | m_targetEncLayerIdList.erase( m_targetEncLayerIdList.begin() + i ); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | if ( m_outputVpsInfo ) |
|---|
| 164 | { |
|---|
| 165 | vps.printScalabilityId(); |
|---|
| 166 | vps.printLayerDependencies(); |
|---|
| 167 | vps.printLayerSets(); |
|---|
| 168 | vps.printPTL(); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | /// Create encoders and set profiles profiles |
|---|
| 174 | for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
|---|
| 175 | { |
|---|
| 176 | m_frameRcvd .push_back(0); |
|---|
| 177 | m_acTEncTopList .push_back(new TEncTop); |
|---|
| 178 | m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv); |
|---|
| 179 | m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
|---|
| 184 | { |
|---|
| 185 | m_cListPicYuvRec .push_back(new TComList<TComPicYuv*>) ; |
|---|
| 186 | |
|---|
| 187 | #if !NH_MV |
|---|
| 188 | m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic() ); |
|---|
| 189 | #endif |
|---|
| 190 | |
|---|
| 191 | TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ]; // It is not a member, but this name helps avoiding code duplication !!! |
|---|
| 192 | |
|---|
| 193 | Int layerId = vps.getLayerIdInNuh ( layerIdInVps ); |
|---|
| 194 | #if NH_MV |
|---|
| 195 | m_ivPicLists.getSubDpb( layerId, true ); |
|---|
| 196 | #endif |
|---|
| 197 | |
|---|
| 198 | m_cTEncTop.setLayerIdInVps ( layerIdInVps ); |
|---|
| 199 | m_cTEncTop.setLayerId ( layerId ); |
|---|
| 200 | m_cTEncTop.setViewId ( vps.getViewId ( layerId ) ); |
|---|
| 201 | m_cTEncTop.setViewIndex ( vps.getViewIndex ( layerId ) ); |
|---|
| 202 | |
|---|
| 203 | m_cTEncTop.setIvPicLists ( &m_ivPicLists ); |
|---|
| 204 | #endif // NH_MV |
|---|
| 205 | m_cTEncTop.setVPS(&vps); |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | #if NH_MV |
|---|
| 209 | m_cTEncTop.setProfile ( m_profiles[0]); |
|---|
| 210 | m_cTEncTop.setLevel ( m_levelTier[0], m_level[0] ); |
|---|
| 211 | #else |
|---|
| 212 | m_cTEncTop.setProfile ( m_profile); |
|---|
| 213 | m_cTEncTop.setLevel ( m_levelTier, m_level); |
|---|
| 214 | #endif |
|---|
| 215 | m_cTEncTop.setProgressiveSourceFlag ( m_progressiveSourceFlag); |
|---|
| 216 | m_cTEncTop.setInterlacedSourceFlag ( m_interlacedSourceFlag); |
|---|
| 217 | m_cTEncTop.setNonPackedConstraintFlag ( m_nonPackedConstraintFlag); |
|---|
| 218 | m_cTEncTop.setFrameOnlyConstraintFlag ( m_frameOnlyConstraintFlag); |
|---|
| 219 | m_cTEncTop.setBitDepthConstraintValue ( m_bitDepthConstraint ); |
|---|
| 220 | m_cTEncTop.setChromaFormatConstraintValue ( m_chromaFormatConstraint ); |
|---|
| 221 | m_cTEncTop.setIntraConstraintFlag ( m_intraConstraintFlag ); |
|---|
| 222 | m_cTEncTop.setOnePictureOnlyConstraintFlag ( m_onePictureOnlyConstraintFlag ); |
|---|
| 223 | m_cTEncTop.setLowerBitRateConstraintFlag ( m_lowerBitRateConstraintFlag ); |
|---|
| 224 | |
|---|
| 225 | m_cTEncTop.setPrintMSEBasedSequencePSNR ( m_printMSEBasedSequencePSNR); |
|---|
| 226 | m_cTEncTop.setPrintFrameMSE ( m_printFrameMSE); |
|---|
| 227 | m_cTEncTop.setPrintSequenceMSE ( m_printSequenceMSE); |
|---|
| 228 | m_cTEncTop.setCabacZeroWordPaddingEnabled ( m_cabacZeroWordPaddingEnabled ); |
|---|
| 229 | |
|---|
| 230 | m_cTEncTop.setFrameRate ( m_iFrameRate ); |
|---|
| 231 | m_cTEncTop.setFrameSkip ( m_FrameSkip ); |
|---|
| 232 | m_cTEncTop.setSourceWidth ( m_iSourceWidth ); |
|---|
| 233 | m_cTEncTop.setSourceHeight ( m_iSourceHeight ); |
|---|
| 234 | m_cTEncTop.setConformanceWindow ( m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom ); |
|---|
| 235 | m_cTEncTop.setFramesToBeEncoded ( m_framesToBeEncoded ); |
|---|
| 236 | |
|---|
| 237 | //====== Coding Structure ======== |
|---|
| 238 | #if NH_MV |
|---|
| 239 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod[ layerIdInVps ] ); |
|---|
| 240 | #else |
|---|
| 241 | m_cTEncTop.setIntraPeriod ( m_iIntraPeriod ); |
|---|
| 242 | #endif |
|---|
| 243 | m_cTEncTop.setDecodingRefreshType ( m_iDecodingRefreshType ); |
|---|
| 244 | m_cTEncTop.setGOPSize ( m_iGOPSize ); |
|---|
| 245 | #if NH_MV |
|---|
| 246 | m_cTEncTop.setGopList ( m_GOPListMvc[layerIdInVps] ); |
|---|
| 247 | m_cTEncTop.setExtraRPSs ( m_extraRPSsMvc[layerIdInVps] ); |
|---|
| 248 | for(Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 249 | { |
|---|
| 250 | m_cTEncTop.setNumReorderPics ( m_numReorderPicsMvc[layerIdInVps][i], i ); |
|---|
| 251 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBufferingMvc[layerIdInVps][i], i ); |
|---|
| 252 | } |
|---|
| 253 | #else |
|---|
| 254 | m_cTEncTop.setGopList ( m_GOPList ); |
|---|
| 255 | m_cTEncTop.setExtraRPSs ( m_extraRPSs ); |
|---|
| 256 | for(Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 257 | { |
|---|
| 258 | m_cTEncTop.setNumReorderPics ( m_numReorderPics[i], i ); |
|---|
| 259 | m_cTEncTop.setMaxDecPicBuffering ( m_maxDecPicBuffering[i], i ); |
|---|
| 260 | } |
|---|
| 261 | #endif |
|---|
| 262 | for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop ) |
|---|
| 263 | { |
|---|
| 264 | m_cTEncTop.setLambdaModifier ( uiLoop, m_adLambdaModifier[ uiLoop ] ); |
|---|
| 265 | } |
|---|
| 266 | #if NH_MV |
|---|
| 267 | m_cTEncTop.setQP ( m_iQP[layerIdInVps] ); |
|---|
| 268 | #else |
|---|
| 269 | m_cTEncTop.setQP ( m_iQP ); |
|---|
| 270 | #endif |
|---|
| 271 | |
|---|
| 272 | m_cTEncTop.setPad ( m_aiPad ); |
|---|
| 273 | |
|---|
| 274 | #if NH_MV |
|---|
| 275 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayerMvc[layerIdInVps] ); |
|---|
| 276 | #else |
|---|
| 277 | m_cTEncTop.setMaxTempLayer ( m_maxTempLayer ); |
|---|
| 278 | #endif |
|---|
| 279 | m_cTEncTop.setUseAMP( m_enableAMP ); |
|---|
| 280 | |
|---|
| 281 | //===== Slice ======== |
|---|
| 282 | |
|---|
| 283 | //====== Loop/Deblock Filter ======== |
|---|
| 284 | #if NH_MV |
|---|
| 285 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable[layerIdInVps]); |
|---|
| 286 | #else |
|---|
| 287 | m_cTEncTop.setLoopFilterDisable ( m_bLoopFilterDisable ); |
|---|
| 288 | #endif |
|---|
| 289 | m_cTEncTop.setLoopFilterOffsetInPPS ( m_loopFilterOffsetInPPS ); |
|---|
| 290 | m_cTEncTop.setLoopFilterBetaOffset ( m_loopFilterBetaOffsetDiv2 ); |
|---|
| 291 | m_cTEncTop.setLoopFilterTcOffset ( m_loopFilterTcOffsetDiv2 ); |
|---|
| 292 | m_cTEncTop.setDeblockingFilterMetric ( m_DeblockingFilterMetric ); |
|---|
| 293 | |
|---|
| 294 | //====== Motion search ======== |
|---|
| 295 | m_cTEncTop.setDisableIntraPUsInInterSlices ( m_bDisableIntraPUsInInterSlices ); |
|---|
| 296 | m_cTEncTop.setFastSearch ( m_iFastSearch ); |
|---|
| 297 | m_cTEncTop.setSearchRange ( m_iSearchRange ); |
|---|
| 298 | m_cTEncTop.setBipredSearchRange ( m_bipredSearchRange ); |
|---|
| 299 | m_cTEncTop.setClipForBiPredMeEnabled ( m_bClipForBiPredMeEnabled ); |
|---|
| 300 | m_cTEncTop.setFastMEAssumingSmootherMVEnabled ( m_bFastMEAssumingSmootherMVEnabled ); |
|---|
| 301 | |
|---|
| 302 | #if NH_MV |
|---|
| 303 | m_cTEncTop.setUseDisparitySearchRangeRestriction ( m_bUseDisparitySearchRangeRestriction ); |
|---|
| 304 | m_cTEncTop.setVerticalDisparitySearchRange ( m_iVerticalDisparitySearchRange ); |
|---|
| 305 | #endif |
|---|
| 306 | //====== Quality control ======== |
|---|
| 307 | m_cTEncTop.setMaxDeltaQP ( m_iMaxDeltaQP ); |
|---|
| 308 | m_cTEncTop.setMaxCuDQPDepth ( m_iMaxCuDQPDepth ); |
|---|
| 309 | m_cTEncTop.setDiffCuChromaQpOffsetDepth ( m_diffCuChromaQpOffsetDepth ); |
|---|
| 310 | m_cTEncTop.setChromaCbQpOffset ( m_cbQpOffset ); |
|---|
| 311 | m_cTEncTop.setChromaCrQpOffset ( m_crQpOffset ); |
|---|
| 312 | |
|---|
| 313 | m_cTEncTop.setChromaFormatIdc ( m_chromaFormatIDC ); |
|---|
| 314 | |
|---|
| 315 | #if ADAPTIVE_QP_SELECTION |
|---|
| 316 | m_cTEncTop.setUseAdaptQpSelect ( m_bUseAdaptQpSelect ); |
|---|
| 317 | #endif |
|---|
| 318 | |
|---|
| 319 | m_cTEncTop.setUseAdaptiveQP ( m_bUseAdaptiveQP ); |
|---|
| 320 | m_cTEncTop.setQPAdaptationRange ( m_iQPAdaptationRange ); |
|---|
| 321 | m_cTEncTop.setExtendedPrecisionProcessingFlag ( m_extendedPrecisionProcessingFlag ); |
|---|
| 322 | m_cTEncTop.setHighPrecisionOffsetsEnabledFlag ( m_highPrecisionOffsetsEnabledFlag ); |
|---|
| 323 | //====== Tool list ======== |
|---|
| 324 | m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); |
|---|
| 325 | m_cTEncTop.setFastDeltaQp ( m_bFastDeltaQP ); |
|---|
| 326 | m_cTEncTop.setUseASR ( m_bUseASR ); |
|---|
| 327 | m_cTEncTop.setUseHADME ( m_bUseHADME ); |
|---|
| 328 | #if NH_MV |
|---|
| 329 | m_cTEncTop.setdQPs ( m_aidQP[layerIdInVps] ); |
|---|
| 330 | #else |
|---|
| 331 | m_cTEncTop.setdQPs ( m_aidQP ); |
|---|
| 332 | #endif |
|---|
| 333 | m_cTEncTop.setUseRDOQ ( m_useRDOQ ); |
|---|
| 334 | m_cTEncTop.setUseRDOQTS ( m_useRDOQTS ); |
|---|
| 335 | #if T0196_SELECTIVE_RDOQ |
|---|
| 336 | m_cTEncTop.setUseSelectiveRDOQ ( m_useSelectiveRDOQ ); |
|---|
| 337 | #endif |
|---|
| 338 | m_cTEncTop.setRDpenalty ( m_rdPenalty ); |
|---|
| 339 | m_cTEncTop.setMaxCUWidth ( m_uiMaxCUWidth ); |
|---|
| 340 | m_cTEncTop.setMaxCUHeight ( m_uiMaxCUHeight ); |
|---|
| 341 | m_cTEncTop.setMaxTotalCUDepth ( m_uiMaxTotalCUDepth ); |
|---|
| 342 | m_cTEncTop.setLog2DiffMaxMinCodingBlockSize ( m_uiLog2DiffMaxMinCodingBlockSize ); |
|---|
| 343 | m_cTEncTop.setQuadtreeTULog2MaxSize ( m_uiQuadtreeTULog2MaxSize ); |
|---|
| 344 | m_cTEncTop.setQuadtreeTULog2MinSize ( m_uiQuadtreeTULog2MinSize ); |
|---|
| 345 | m_cTEncTop.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter ); |
|---|
| 346 | m_cTEncTop.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra ); |
|---|
| 347 | m_cTEncTop.setUseFastEnc ( m_bUseFastEnc ); |
|---|
| 348 | m_cTEncTop.setUseEarlyCU ( m_bUseEarlyCU ); |
|---|
| 349 | m_cTEncTop.setUseFastDecisionForMerge ( m_useFastDecisionForMerge ); |
|---|
| 350 | m_cTEncTop.setUseCbfFastMode ( m_bUseCbfFastMode ); |
|---|
| 351 | m_cTEncTop.setUseEarlySkipDetection ( m_useEarlySkipDetection ); |
|---|
| 352 | m_cTEncTop.setCrossComponentPredictionEnabledFlag ( m_crossComponentPredictionEnabledFlag ); |
|---|
| 353 | m_cTEncTop.setUseReconBasedCrossCPredictionEstimate ( m_reconBasedCrossCPredictionEstimate ); |
|---|
| 354 | #if NH_MV |
|---|
| 355 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_LUMA , m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_LUMA] ); |
|---|
| 356 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[layerIdInVps][CHANNEL_TYPE_CHROMA] ); |
|---|
| 357 | #else |
|---|
| 358 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_LUMA , m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA] ); |
|---|
| 359 | m_cTEncTop.setLog2SaoOffsetScale ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] ); |
|---|
| 360 | #endif |
|---|
| 361 | m_cTEncTop.setUseTransformSkip ( m_useTransformSkip ); |
|---|
| 362 | m_cTEncTop.setUseTransformSkipFast ( m_useTransformSkipFast ); |
|---|
| 363 | m_cTEncTop.setTransformSkipRotationEnabledFlag ( m_transformSkipRotationEnabledFlag ); |
|---|
| 364 | m_cTEncTop.setTransformSkipContextEnabledFlag ( m_transformSkipContextEnabledFlag ); |
|---|
| 365 | m_cTEncTop.setPersistentRiceAdaptationEnabledFlag ( m_persistentRiceAdaptationEnabledFlag ); |
|---|
| 366 | m_cTEncTop.setCabacBypassAlignmentEnabledFlag ( m_cabacBypassAlignmentEnabledFlag ); |
|---|
| 367 | m_cTEncTop.setLog2MaxTransformSkipBlockSize ( m_log2MaxTransformSkipBlockSize ); |
|---|
| 368 | for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++) |
|---|
| 369 | { |
|---|
| 370 | m_cTEncTop.setRdpcmEnabledFlag ( RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]); |
|---|
| 371 | } |
|---|
| 372 | m_cTEncTop.setUseConstrainedIntraPred ( m_bUseConstrainedIntraPred ); |
|---|
| 373 | m_cTEncTop.setFastUDIUseMPMEnabled ( m_bFastUDIUseMPMEnabled ); |
|---|
| 374 | m_cTEncTop.setFastMEForGenBLowDelayEnabled ( m_bFastMEForGenBLowDelayEnabled ); |
|---|
| 375 | m_cTEncTop.setUseBLambdaForNonKeyLowDelayPictures ( m_bUseBLambdaForNonKeyLowDelayPictures ); |
|---|
| 376 | m_cTEncTop.setPCMLog2MinSize ( m_uiPCMLog2MinSize); |
|---|
| 377 | m_cTEncTop.setUsePCM ( m_usePCM ); |
|---|
| 378 | |
|---|
| 379 | // set internal bit-depth and constants |
|---|
| 380 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
|---|
| 381 | { |
|---|
| 382 | m_cTEncTop.setBitDepth((ChannelType)channelType, m_internalBitDepth[channelType]); |
|---|
| 383 | m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | m_cTEncTop.setPCMLog2MaxSize ( m_pcmLog2MaxSize); |
|---|
| 387 | m_cTEncTop.setMaxNumMergeCand ( m_maxNumMergeCand ); |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | //====== Weighted Prediction ======== |
|---|
| 391 | m_cTEncTop.setUseWP ( m_useWeightedPred ); |
|---|
| 392 | m_cTEncTop.setWPBiPred ( m_useWeightedBiPred ); |
|---|
| 393 | //====== Parallel Merge Estimation ======== |
|---|
| 394 | m_cTEncTop.setLog2ParallelMergeLevelMinus2 ( m_log2ParallelMergeLevel - 2 ); |
|---|
| 395 | |
|---|
| 396 | //====== Slice ======== |
|---|
| 397 | m_cTEncTop.setSliceMode ( (SliceConstraint) m_sliceMode ); |
|---|
| 398 | m_cTEncTop.setSliceArgument ( m_sliceArgument ); |
|---|
| 399 | |
|---|
| 400 | //====== Dependent Slice ======== |
|---|
| 401 | m_cTEncTop.setSliceSegmentMode ( (SliceConstraint) m_sliceSegmentMode ); |
|---|
| 402 | m_cTEncTop.setSliceSegmentArgument ( m_sliceSegmentArgument ); |
|---|
| 403 | |
|---|
| 404 | if(m_sliceMode == NO_SLICES ) |
|---|
| 405 | { |
|---|
| 406 | m_bLFCrossSliceBoundaryFlag = true; |
|---|
| 407 | } |
|---|
| 408 | m_cTEncTop.setLFCrossSliceBoundaryFlag ( m_bLFCrossSliceBoundaryFlag ); |
|---|
| 409 | #if NH_MV |
|---|
| 410 | m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] ); |
|---|
| 411 | #else |
|---|
| 412 | m_cTEncTop.setUseSAO ( m_bUseSAO ); |
|---|
| 413 | #endif |
|---|
| 414 | m_cTEncTop.setTestSAODisableAtPictureLevel ( m_bTestSAODisableAtPictureLevel ); |
|---|
| 415 | m_cTEncTop.setSaoEncodingRate ( m_saoEncodingRate ); |
|---|
| 416 | m_cTEncTop.setSaoEncodingRateChroma ( m_saoEncodingRateChroma ); |
|---|
| 417 | m_cTEncTop.setMaxNumOffsetsPerPic ( m_maxNumOffsetsPerPic); |
|---|
| 418 | |
|---|
| 419 | m_cTEncTop.setSaoCtuBoundary ( m_saoCtuBoundary); |
|---|
| 420 | m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); |
|---|
| 421 | m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); |
|---|
| 422 | |
|---|
| 423 | m_cTEncTop.setIntraSmoothingDisabledFlag (!m_enableIntraReferenceSmoothing ); |
|---|
| 424 | m_cTEncTop.setDecodedPictureHashSEIEnabled ( m_decodedPictureHashSEIEnabled ); |
|---|
| 425 | m_cTEncTop.setRecoveryPointSEIEnabled ( m_recoveryPointSEIEnabled ); |
|---|
| 426 | m_cTEncTop.setBufferingPeriodSEIEnabled ( m_bufferingPeriodSEIEnabled ); |
|---|
| 427 | m_cTEncTop.setPictureTimingSEIEnabled ( m_pictureTimingSEIEnabled ); |
|---|
| 428 | m_cTEncTop.setToneMappingInfoSEIEnabled ( m_toneMappingInfoSEIEnabled ); |
|---|
| 429 | m_cTEncTop.setTMISEIToneMapId ( m_toneMapId ); |
|---|
| 430 | m_cTEncTop.setTMISEIToneMapCancelFlag ( m_toneMapCancelFlag ); |
|---|
| 431 | m_cTEncTop.setTMISEIToneMapPersistenceFlag ( m_toneMapPersistenceFlag ); |
|---|
| 432 | m_cTEncTop.setTMISEICodedDataBitDepth ( m_toneMapCodedDataBitDepth ); |
|---|
| 433 | m_cTEncTop.setTMISEITargetBitDepth ( m_toneMapTargetBitDepth ); |
|---|
| 434 | m_cTEncTop.setTMISEIModelID ( m_toneMapModelId ); |
|---|
| 435 | m_cTEncTop.setTMISEIMinValue ( m_toneMapMinValue ); |
|---|
| 436 | m_cTEncTop.setTMISEIMaxValue ( m_toneMapMaxValue ); |
|---|
| 437 | m_cTEncTop.setTMISEISigmoidMidpoint ( m_sigmoidMidpoint ); |
|---|
| 438 | m_cTEncTop.setTMISEISigmoidWidth ( m_sigmoidWidth ); |
|---|
| 439 | m_cTEncTop.setTMISEIStartOfCodedInterva ( m_startOfCodedInterval ); |
|---|
| 440 | m_cTEncTop.setTMISEINumPivots ( m_numPivots ); |
|---|
| 441 | m_cTEncTop.setTMISEICodedPivotValue ( m_codedPivotValue ); |
|---|
| 442 | m_cTEncTop.setTMISEITargetPivotValue ( m_targetPivotValue ); |
|---|
| 443 | m_cTEncTop.setTMISEICameraIsoSpeedIdc ( m_cameraIsoSpeedIdc ); |
|---|
| 444 | m_cTEncTop.setTMISEICameraIsoSpeedValue ( m_cameraIsoSpeedValue ); |
|---|
| 445 | m_cTEncTop.setTMISEIExposureIndexIdc ( m_exposureIndexIdc ); |
|---|
| 446 | m_cTEncTop.setTMISEIExposureIndexValue ( m_exposureIndexValue ); |
|---|
| 447 | m_cTEncTop.setTMISEIExposureCompensationValueSignFlag ( m_exposureCompensationValueSignFlag ); |
|---|
| 448 | m_cTEncTop.setTMISEIExposureCompensationValueNumerator ( m_exposureCompensationValueNumerator ); |
|---|
| 449 | m_cTEncTop.setTMISEIExposureCompensationValueDenomIdc ( m_exposureCompensationValueDenomIdc ); |
|---|
| 450 | m_cTEncTop.setTMISEIRefScreenLuminanceWhite ( m_refScreenLuminanceWhite ); |
|---|
| 451 | m_cTEncTop.setTMISEIExtendedRangeWhiteLevel ( m_extendedRangeWhiteLevel ); |
|---|
| 452 | m_cTEncTop.setTMISEINominalBlackLevelLumaCodeValue ( m_nominalBlackLevelLumaCodeValue ); |
|---|
| 453 | m_cTEncTop.setTMISEINominalWhiteLevelLumaCodeValue ( m_nominalWhiteLevelLumaCodeValue ); |
|---|
| 454 | m_cTEncTop.setTMISEIExtendedWhiteLevelLumaCodeValue ( m_extendedWhiteLevelLumaCodeValue ); |
|---|
| 455 | m_cTEncTop.setChromaSamplingFilterHintEnabled ( m_chromaSamplingFilterSEIenabled ); |
|---|
| 456 | m_cTEncTop.setChromaSamplingHorFilterIdc ( m_chromaSamplingHorFilterIdc ); |
|---|
| 457 | m_cTEncTop.setChromaSamplingVerFilterIdc ( m_chromaSamplingVerFilterIdc ); |
|---|
| 458 | m_cTEncTop.setFramePackingArrangementSEIEnabled ( m_framePackingSEIEnabled ); |
|---|
| 459 | m_cTEncTop.setFramePackingArrangementSEIType ( m_framePackingSEIType ); |
|---|
| 460 | m_cTEncTop.setFramePackingArrangementSEIId ( m_framePackingSEIId ); |
|---|
| 461 | m_cTEncTop.setFramePackingArrangementSEIQuincunx ( m_framePackingSEIQuincunx ); |
|---|
| 462 | m_cTEncTop.setFramePackingArrangementSEIInterpretation ( m_framePackingSEIInterpretation ); |
|---|
| 463 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIEnabled ( m_segmentedRectFramePackingSEIEnabled ); |
|---|
| 464 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEICancel ( m_segmentedRectFramePackingSEICancel ); |
|---|
| 465 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIType ( m_segmentedRectFramePackingSEIType ); |
|---|
| 466 | m_cTEncTop.setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence ); |
|---|
| 467 | m_cTEncTop.setDisplayOrientationSEIAngle ( m_displayOrientationSEIAngle ); |
|---|
| 468 | m_cTEncTop.setTemporalLevel0IndexSEIEnabled ( m_temporalLevel0IndexSEIEnabled ); |
|---|
| 469 | m_cTEncTop.setGradualDecodingRefreshInfoEnabled ( m_gradualDecodingRefreshInfoEnabled ); |
|---|
| 470 | m_cTEncTop.setNoDisplaySEITLayer ( m_noDisplaySEITLayer ); |
|---|
| 471 | m_cTEncTop.setDecodingUnitInfoSEIEnabled ( m_decodingUnitInfoSEIEnabled ); |
|---|
| 472 | m_cTEncTop.setSOPDescriptionSEIEnabled ( m_SOPDescriptionSEIEnabled ); |
|---|
| 473 | m_cTEncTop.setScalableNestingSEIEnabled ( m_scalableNestingSEIEnabled ); |
|---|
| 474 | #if NH_MV |
|---|
| 475 | m_cTEncTop.setSubBitstreamPropSEIEnabled ( m_subBistreamPropSEIEnabled ); |
|---|
| 476 | if( m_subBistreamPropSEIEnabled ) |
|---|
| 477 | { |
|---|
| 478 | m_cTEncTop.setNumAdditionalSubStreams ( m_sbPropNumAdditionalSubStreams ); |
|---|
| 479 | m_cTEncTop.setSubBitstreamMode ( m_sbPropSubBitstreamMode ); |
|---|
| 480 | m_cTEncTop.setOutputLayerSetIdxToVps ( m_sbPropOutputLayerSetIdxToVps ); |
|---|
| 481 | m_cTEncTop.setHighestSublayerId ( m_sbPropHighestSublayerId ); |
|---|
| 482 | m_cTEncTop.setAvgBitRate ( m_sbPropAvgBitRate ); |
|---|
| 483 | m_cTEncTop.setMaxBitRate ( m_sbPropMaxBitRate ); |
|---|
| 484 | } |
|---|
| 485 | #endif |
|---|
| 486 | |
|---|
| 487 | m_cTEncTop.setTMCTSSEIEnabled ( m_tmctsSEIEnabled ); |
|---|
| 488 | m_cTEncTop.setTimeCodeSEIEnabled ( m_timeCodeSEIEnabled ); |
|---|
| 489 | m_cTEncTop.setNumberOfTimeSets ( m_timeCodeSEINumTs ); |
|---|
| 490 | for(Int i = 0; i < m_timeCodeSEINumTs; i++) |
|---|
| 491 | { |
|---|
| 492 | m_cTEncTop.setTimeSet(m_timeSetArray[i], i); |
|---|
| 493 | } |
|---|
| 494 | m_cTEncTop.setKneeSEIEnabled ( m_kneeSEIEnabled ); |
|---|
| 495 | m_cTEncTop.setKneeSEIId ( m_kneeSEIId ); |
|---|
| 496 | m_cTEncTop.setKneeSEICancelFlag ( m_kneeSEICancelFlag ); |
|---|
| 497 | m_cTEncTop.setKneeSEIPersistenceFlag ( m_kneeSEIPersistenceFlag ); |
|---|
| 498 | m_cTEncTop.setKneeSEIInputDrange ( m_kneeSEIInputDrange ); |
|---|
| 499 | m_cTEncTop.setKneeSEIInputDispLuminance ( m_kneeSEIInputDispLuminance ); |
|---|
| 500 | m_cTEncTop.setKneeSEIOutputDrange ( m_kneeSEIOutputDrange ); |
|---|
| 501 | m_cTEncTop.setKneeSEIOutputDispLuminance ( m_kneeSEIOutputDispLuminance ); |
|---|
| 502 | m_cTEncTop.setKneeSEINumKneePointsMinus1 ( m_kneeSEINumKneePointsMinus1 ); |
|---|
| 503 | m_cTEncTop.setKneeSEIInputKneePoint ( m_kneeSEIInputKneePoint ); |
|---|
| 504 | m_cTEncTop.setKneeSEIOutputKneePoint ( m_kneeSEIOutputKneePoint ); |
|---|
| 505 | m_cTEncTop.setMasteringDisplaySEI ( m_masteringDisplay ); |
|---|
| 506 | |
|---|
| 507 | m_cTEncTop.setTileUniformSpacingFlag ( m_tileUniformSpacingFlag ); |
|---|
| 508 | m_cTEncTop.setNumColumnsMinus1 ( m_numTileColumnsMinus1 ); |
|---|
| 509 | m_cTEncTop.setNumRowsMinus1 ( m_numTileRowsMinus1 ); |
|---|
| 510 | if(!m_tileUniformSpacingFlag) |
|---|
| 511 | { |
|---|
| 512 | m_cTEncTop.setColumnWidth ( m_tileColumnWidth ); |
|---|
| 513 | m_cTEncTop.setRowHeight ( m_tileRowHeight ); |
|---|
| 514 | } |
|---|
| 515 | m_cTEncTop.xCheckGSParameters(); |
|---|
| 516 | Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1); |
|---|
| 517 | if(uiTilesCount == 1) |
|---|
| 518 | { |
|---|
| 519 | m_bLFCrossTileBoundaryFlag = true; |
|---|
| 520 | } |
|---|
| 521 | m_cTEncTop.setLFCrossTileBoundaryFlag ( m_bLFCrossTileBoundaryFlag ); |
|---|
| 522 | m_cTEncTop.setWaveFrontSynchro ( m_iWaveFrontSynchro ); |
|---|
| 523 | m_cTEncTop.setTMVPModeId ( m_TMVPModeId ); |
|---|
| 524 | m_cTEncTop.setUseScalingListId ( m_useScalingListId ); |
|---|
| 525 | m_cTEncTop.setScalingListFile ( m_scalingListFile ); |
|---|
| 526 | m_cTEncTop.setSignHideFlag ( m_signHideFlag); |
|---|
| 527 | m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); |
|---|
| 528 | m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); |
|---|
| 529 | m_cTEncTop.setKeepHierBit ( m_RCKeepHierarchicalBit ); |
|---|
| 530 | m_cTEncTop.setLCULevelRC ( m_RCLCULevelRC ); |
|---|
| 531 | m_cTEncTop.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); |
|---|
| 532 | m_cTEncTop.setInitialQP ( m_RCInitialQP ); |
|---|
| 533 | m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); |
|---|
| 534 | m_cTEncTop.setTransquantBypassEnableFlag ( m_TransquantBypassEnableFlag ); |
|---|
| 535 | m_cTEncTop.setCUTransquantBypassFlagForceValue ( m_CUTransquantBypassFlagForce ); |
|---|
| 536 | m_cTEncTop.setCostMode ( m_costMode ); |
|---|
| 537 | m_cTEncTop.setUseRecalculateQPAccordingToLambda ( m_recalculateQPAccordingToLambda ); |
|---|
| 538 | m_cTEncTop.setUseStrongIntraSmoothing ( m_useStrongIntraSmoothing ); |
|---|
| 539 | m_cTEncTop.setActiveParameterSetsSEIEnabled ( m_activeParameterSetsSEIEnabled ); |
|---|
| 540 | m_cTEncTop.setVuiParametersPresentFlag ( m_vuiParametersPresentFlag ); |
|---|
| 541 | m_cTEncTop.setAspectRatioInfoPresentFlag ( m_aspectRatioInfoPresentFlag); |
|---|
| 542 | m_cTEncTop.setAspectRatioIdc ( m_aspectRatioIdc ); |
|---|
| 543 | m_cTEncTop.setSarWidth ( m_sarWidth ); |
|---|
| 544 | m_cTEncTop.setSarHeight ( m_sarHeight ); |
|---|
| 545 | m_cTEncTop.setOverscanInfoPresentFlag ( m_overscanInfoPresentFlag ); |
|---|
| 546 | m_cTEncTop.setOverscanAppropriateFlag ( m_overscanAppropriateFlag ); |
|---|
| 547 | m_cTEncTop.setVideoSignalTypePresentFlag ( m_videoSignalTypePresentFlag ); |
|---|
| 548 | m_cTEncTop.setVideoFormat ( m_videoFormat ); |
|---|
| 549 | m_cTEncTop.setVideoFullRangeFlag ( m_videoFullRangeFlag ); |
|---|
| 550 | m_cTEncTop.setColourDescriptionPresentFlag ( m_colourDescriptionPresentFlag ); |
|---|
| 551 | m_cTEncTop.setColourPrimaries ( m_colourPrimaries ); |
|---|
| 552 | m_cTEncTop.setTransferCharacteristics ( m_transferCharacteristics ); |
|---|
| 553 | m_cTEncTop.setMatrixCoefficients ( m_matrixCoefficients ); |
|---|
| 554 | m_cTEncTop.setChromaLocInfoPresentFlag ( m_chromaLocInfoPresentFlag ); |
|---|
| 555 | m_cTEncTop.setChromaSampleLocTypeTopField ( m_chromaSampleLocTypeTopField ); |
|---|
| 556 | m_cTEncTop.setChromaSampleLocTypeBottomField ( m_chromaSampleLocTypeBottomField ); |
|---|
| 557 | m_cTEncTop.setNeutralChromaIndicationFlag ( m_neutralChromaIndicationFlag ); |
|---|
| 558 | m_cTEncTop.setDefaultDisplayWindow ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset ); |
|---|
| 559 | m_cTEncTop.setFrameFieldInfoPresentFlag ( m_frameFieldInfoPresentFlag ); |
|---|
| 560 | m_cTEncTop.setPocProportionalToTimingFlag ( m_pocProportionalToTimingFlag ); |
|---|
| 561 | m_cTEncTop.setNumTicksPocDiffOneMinus1 ( m_numTicksPocDiffOneMinus1 ); |
|---|
| 562 | m_cTEncTop.setBitstreamRestrictionFlag ( m_bitstreamRestrictionFlag ); |
|---|
| 563 | m_cTEncTop.setTilesFixedStructureFlag ( m_tilesFixedStructureFlag ); |
|---|
| 564 | m_cTEncTop.setMotionVectorsOverPicBoundariesFlag ( m_motionVectorsOverPicBoundariesFlag ); |
|---|
| 565 | m_cTEncTop.setMinSpatialSegmentationIdc ( m_minSpatialSegmentationIdc ); |
|---|
| 566 | m_cTEncTop.setMaxBytesPerPicDenom ( m_maxBytesPerPicDenom ); |
|---|
| 567 | m_cTEncTop.setMaxBitsPerMinCuDenom ( m_maxBitsPerMinCuDenom ); |
|---|
| 568 | m_cTEncTop.setLog2MaxMvLengthHorizontal ( m_log2MaxMvLengthHorizontal ); |
|---|
| 569 | m_cTEncTop.setLog2MaxMvLengthVertical ( m_log2MaxMvLengthVertical ); |
|---|
| 570 | m_cTEncTop.setEfficientFieldIRAPEnabled ( m_bEfficientFieldIRAPEnabled ); |
|---|
| 571 | m_cTEncTop.setHarmonizeGopFirstFieldCoupleEnabled ( m_bHarmonizeGopFirstFieldCoupleEnabled ); |
|---|
| 572 | |
|---|
| 573 | m_cTEncTop.setSummaryOutFilename ( m_summaryOutFilename ); |
|---|
| 574 | m_cTEncTop.setSummaryPicFilenameBase ( m_summaryPicFilenameBase ); |
|---|
| 575 | m_cTEncTop.setSummaryVerboseness ( m_summaryVerboseness ); |
|---|
| 576 | |
|---|
| 577 | #if NH_MV |
|---|
| 578 | } |
|---|
| 579 | #endif |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | Void TAppEncTop::xCreateLib() |
|---|
| 583 | { |
|---|
| 584 | #if NH_MV |
|---|
| 585 | // initialize global variables |
|---|
| 586 | initROM(); |
|---|
| 587 | |
|---|
| 588 | for( Int layer=0; layer < m_numberOfLayers; layer++) |
|---|
| 589 | { |
|---|
| 590 | m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer], false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode |
|---|
| 591 | m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
|---|
| 592 | |
|---|
| 593 | if (m_pchReconFileList[layer]) |
|---|
| 594 | { |
|---|
| 595 | m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode |
|---|
| 596 | } |
|---|
| 597 | m_acTEncTopList[layer]->create(); |
|---|
| 598 | } |
|---|
| 599 | #else |
|---|
| 600 | // Video I/O |
|---|
| 601 | m_cTVideoIOYuvInputFile.open( m_pchInputFile, false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth ); // read mode |
|---|
| 602 | m_cTVideoIOYuvInputFile.skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1], m_InputChromaFormatIDC); |
|---|
| 603 | |
|---|
| 604 | if (m_pchReconFile) |
|---|
| 605 | { |
|---|
| 606 | m_cTVideoIOYuvReconFile.open(m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, m_internalBitDepth); // write mode |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | // Neo Decoder |
|---|
| 610 | m_cTEncTop.create(); |
|---|
| 611 | #endif |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | Void TAppEncTop::xDestroyLib() |
|---|
| 615 | { |
|---|
| 616 | #if NH_MV |
|---|
| 617 | // destroy ROM |
|---|
| 618 | destroyROM(); |
|---|
| 619 | |
|---|
| 620 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
|---|
| 621 | { |
|---|
| 622 | m_acTVideoIOYuvInputFileList[layer]->close(); |
|---|
| 623 | m_acTVideoIOYuvReconFileList[layer]->close(); |
|---|
| 624 | delete m_acTVideoIOYuvInputFileList[layer] ; |
|---|
| 625 | m_acTVideoIOYuvInputFileList[layer] = NULL; |
|---|
| 626 | delete m_acTVideoIOYuvReconFileList[layer] ; |
|---|
| 627 | m_acTVideoIOYuvReconFileList[layer] = NULL; |
|---|
| 628 | m_acTEncTopList[layer]->deletePicBuffer(); |
|---|
| 629 | m_acTEncTopList[layer]->destroy(); |
|---|
| 630 | delete m_acTEncTopList[layer] ; |
|---|
| 631 | m_acTEncTopList[layer] = NULL; |
|---|
| 632 | delete m_cListPicYuvRec[layer] ; |
|---|
| 633 | m_cListPicYuvRec[layer] = NULL; |
|---|
| 634 | } |
|---|
| 635 | #else |
|---|
| 636 | // Video I/O |
|---|
| 637 | m_cTVideoIOYuvInputFile.close(); |
|---|
| 638 | m_cTVideoIOYuvReconFile.close(); |
|---|
| 639 | |
|---|
| 640 | // Neo Decoder |
|---|
| 641 | m_cTEncTop.destroy(); |
|---|
| 642 | #endif |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | Void TAppEncTop::xInitLib(Bool isFieldCoding) |
|---|
| 646 | { |
|---|
| 647 | #if NH_MV |
|---|
| 648 | for(Int layer=0; layer<m_numberOfLayers; layer++) |
|---|
| 649 | { |
|---|
| 650 | m_acTEncTopList[layer]->init( isFieldCoding ); |
|---|
| 651 | } |
|---|
| 652 | #else |
|---|
| 653 | m_cTEncTop.init(isFieldCoding); |
|---|
| 654 | #endif |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | // ==================================================================================================================== |
|---|
| 658 | // Public member functions |
|---|
| 659 | // ==================================================================================================================== |
|---|
| 660 | |
|---|
| 661 | /** |
|---|
| 662 | - create internal class |
|---|
| 663 | - initialize internal variable |
|---|
| 664 | - until the end of input YUV file, call encoding function in TEncTop class |
|---|
| 665 | - delete allocated buffers |
|---|
| 666 | - destroy internal class |
|---|
| 667 | . |
|---|
| 668 | */ |
|---|
| 669 | Void TAppEncTop::encode() |
|---|
| 670 | { |
|---|
| 671 | fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out); |
|---|
| 672 | if (!bitstreamFile) |
|---|
| 673 | { |
|---|
| 674 | fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile); |
|---|
| 675 | exit(EXIT_FAILURE); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | TComPicYuv* pcPicYuvOrg = new TComPicYuv; |
|---|
| 679 | TComPicYuv* pcPicYuvRec = NULL; |
|---|
| 680 | |
|---|
| 681 | // initialize internal class & member variables |
|---|
| 682 | xInitLibCfg(); |
|---|
| 683 | xCreateLib(); |
|---|
| 684 | xInitLib(m_isField); |
|---|
| 685 | |
|---|
| 686 | printChromaFormat(); |
|---|
| 687 | |
|---|
| 688 | // main encoder loop |
|---|
| 689 | #if NH_MV |
|---|
| 690 | Bool allEos = false; |
|---|
| 691 | std::vector<Bool> eos ; |
|---|
| 692 | std::vector<Bool> flush ; |
|---|
| 693 | |
|---|
| 694 | Int gopSize = 1; |
|---|
| 695 | Int maxGopSize = 0; |
|---|
| 696 | maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize()); |
|---|
| 697 | |
|---|
| 698 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
|---|
| 699 | { |
|---|
| 700 | eos .push_back( false ); |
|---|
| 701 | flush.push_back( false ); |
|---|
| 702 | } |
|---|
| 703 | #else |
|---|
| 704 | Int iNumEncoded = 0; |
|---|
| 705 | Bool bEos = false; |
|---|
| 706 | #endif |
|---|
| 707 | const InputColourSpaceConversion ipCSC = m_inputColourSpaceConvert; |
|---|
| 708 | const InputColourSpaceConversion snrCSC = (!m_snrInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
|---|
| 709 | |
|---|
| 710 | list<AccessUnit> outputAccessUnits; ///< list of access units to write out. is populated by the encoding process |
|---|
| 711 | |
|---|
| 712 | TComPicYuv cPicYuvTrueOrg; |
|---|
| 713 | |
|---|
| 714 | // allocate original YUV buffer |
|---|
| 715 | if( m_isField ) |
|---|
| 716 | { |
|---|
| 717 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
|---|
| 718 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeightOrg, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true); |
|---|
| 719 | } |
|---|
| 720 | else |
|---|
| 721 | { |
|---|
| 722 | pcPicYuvOrg->create ( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
|---|
| 723 | cPicYuvTrueOrg.create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
|---|
| 724 | } |
|---|
| 725 | #if NH_MV |
|---|
| 726 | while ( (m_targetEncLayerIdList.size() != 0 ) && !allEos ) |
|---|
| 727 | { |
|---|
| 728 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
|---|
| 729 | { |
|---|
| 730 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
|---|
| 731 | { |
|---|
| 732 | continue; |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | Int frmCnt = 0; |
|---|
| 736 | while ( !eos[layer] && !(frmCnt == gopSize)) |
|---|
| 737 | { |
|---|
| 738 | // get buffers |
|---|
| 739 | xGetBuffer(pcPicYuvRec, layer); |
|---|
| 740 | |
|---|
| 741 | // read input YUV file |
|---|
| 742 | m_acTVideoIOYuvInputFileList[layer]->read ( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC ); |
|---|
| 743 | m_acTEncTopList [layer]->initNewPic( pcPicYuvOrg ); |
|---|
| 744 | |
|---|
| 745 | // increase number of received frames |
|---|
| 746 | m_frameRcvd[layer]++; |
|---|
| 747 | |
|---|
| 748 | frmCnt++; |
|---|
| 749 | |
|---|
| 750 | eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded); |
|---|
| 751 | allEos = allEos||eos[layer]; |
|---|
| 752 | |
|---|
| 753 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
|---|
| 754 | if (m_acTVideoIOYuvInputFileList[layer]->isEof()) |
|---|
| 755 | { |
|---|
| 756 | flush [layer] = true; |
|---|
| 757 | eos [layer] = true; |
|---|
| 758 | m_frameRcvd [layer]--; |
|---|
| 759 | m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]); |
|---|
| 760 | } |
|---|
| 761 | } |
|---|
| 762 | } |
|---|
| 763 | for ( Int gopId=0; gopId < gopSize; gopId++ ) |
|---|
| 764 | { |
|---|
| 765 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
|---|
| 766 | { |
|---|
| 767 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
|---|
| 768 | { |
|---|
| 769 | continue; |
|---|
| 770 | } |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | Int iNumEncoded = 0; |
|---|
| 774 | |
|---|
| 775 | // call encoding function for one frame |
|---|
| 776 | m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, flush[layer] ? 0 : &cPicYuvTrueOrg, snrCSC, *m_cListPicYuvRec[layer], outputAccessUnits, iNumEncoded, gopId ); |
|---|
| 777 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer); |
|---|
| 778 | outputAccessUnits.clear(); |
|---|
| 779 | } |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | gopSize = maxGopSize; |
|---|
| 783 | } |
|---|
| 784 | for(Int layer=0; layer < m_numberOfLayers; layer++ ) |
|---|
| 785 | { |
|---|
| 786 | if (!xLayerIdInTargetEncLayerIdList( m_vps->getLayerIdInNuh( layer ) )) |
|---|
| 787 | { |
|---|
| 788 | continue; |
|---|
| 789 | } |
|---|
| 790 | m_acTEncTopList[layer]->printSummary(m_isField); |
|---|
| 791 | } |
|---|
| 792 | #else |
|---|
| 793 | |
|---|
| 794 | while ( !bEos ) |
|---|
| 795 | { |
|---|
| 796 | // get buffers |
|---|
| 797 | xGetBuffer(pcPicYuvRec); |
|---|
| 798 | |
|---|
| 799 | // read input YUV file |
|---|
| 800 | m_cTVideoIOYuvInputFile.read( pcPicYuvOrg, &cPicYuvTrueOrg, ipCSC, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range ); |
|---|
| 801 | |
|---|
| 802 | // increase number of received frames |
|---|
| 803 | m_iFrameRcvd++; |
|---|
| 804 | |
|---|
| 805 | bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) ); |
|---|
| 806 | |
|---|
| 807 | Bool flush = 0; |
|---|
| 808 | // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures |
|---|
| 809 | if (m_cTVideoIOYuvInputFile.isEof()) |
|---|
| 810 | { |
|---|
| 811 | flush = true; |
|---|
| 812 | bEos = true; |
|---|
| 813 | m_iFrameRcvd--; |
|---|
| 814 | m_cTEncTop.setFramesToBeEncoded(m_iFrameRcvd); |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | // call encoding function for one frame |
|---|
| 818 | if ( m_isField ) |
|---|
| 819 | { |
|---|
| 820 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst ); |
|---|
| 821 | } |
|---|
| 822 | else |
|---|
| 823 | { |
|---|
| 824 | m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, flush ? 0 : &cPicYuvTrueOrg, snrCSC, m_cListPicYuvRec, outputAccessUnits, iNumEncoded ); |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | // write bistream to file if necessary |
|---|
| 828 | if ( iNumEncoded > 0 ) |
|---|
| 829 | { |
|---|
| 830 | xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits); |
|---|
| 831 | outputAccessUnits.clear(); |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | m_cTEncTop.printSummary(m_isField); |
|---|
| 836 | #endif |
|---|
| 837 | |
|---|
| 838 | // delete original YUV buffer |
|---|
| 839 | pcPicYuvOrg->destroy(); |
|---|
| 840 | delete pcPicYuvOrg; |
|---|
| 841 | pcPicYuvOrg = NULL; |
|---|
| 842 | |
|---|
| 843 | #if !NH_MV |
|---|
| 844 | // delete used buffers in encoder class |
|---|
| 845 | m_cTEncTop.deletePicBuffer(); |
|---|
| 846 | #endif |
|---|
| 847 | cPicYuvTrueOrg.destroy(); |
|---|
| 848 | |
|---|
| 849 | // delete buffers & classes |
|---|
| 850 | xDeleteBuffer(); |
|---|
| 851 | xDestroyLib(); |
|---|
| 852 | |
|---|
| 853 | printRateSummary(); |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | return; |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | // ==================================================================================================================== |
|---|
| 860 | // Protected member functions |
|---|
| 861 | // ==================================================================================================================== |
|---|
| 862 | |
|---|
| 863 | /** |
|---|
| 864 | - application has picture buffer list with size of GOP |
|---|
| 865 | - picture buffer list acts as ring buffer |
|---|
| 866 | - end of the list has the latest picture |
|---|
| 867 | . |
|---|
| 868 | */ |
|---|
| 869 | #if NH_MV |
|---|
| 870 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer) |
|---|
| 871 | #else |
|---|
| 872 | Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec) |
|---|
| 873 | #endif |
|---|
| 874 | { |
|---|
| 875 | assert( m_iGOPSize > 0 ); |
|---|
| 876 | |
|---|
| 877 | // org. buffer |
|---|
| 878 | #if NH_MV |
|---|
| 879 | if ( m_cListPicYuvRec[layer]->size() == (UInt)m_iGOPSize ) |
|---|
| 880 | { |
|---|
| 881 | rpcPicYuvRec = m_cListPicYuvRec[layer]->popFront(); |
|---|
| 882 | #else |
|---|
| 883 | if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second. |
|---|
| 884 | { |
|---|
| 885 | rpcPicYuvRec = m_cListPicYuvRec.popFront(); |
|---|
| 886 | #endif |
|---|
| 887 | } |
|---|
| 888 | else |
|---|
| 889 | { |
|---|
| 890 | rpcPicYuvRec = new TComPicYuv; |
|---|
| 891 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, true ); |
|---|
| 892 | |
|---|
| 893 | } |
|---|
| 894 | #if NH_MV |
|---|
| 895 | m_cListPicYuvRec[layer]->pushBack( rpcPicYuvRec ); |
|---|
| 896 | #else |
|---|
| 897 | m_cListPicYuvRec.pushBack( rpcPicYuvRec ); |
|---|
| 898 | #endif |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | Void TAppEncTop::xDeleteBuffer( ) |
|---|
| 902 | { |
|---|
| 903 | #if NH_MV |
|---|
| 904 | for(Int layer=0; layer<m_cListPicYuvRec.size(); layer++) |
|---|
| 905 | { |
|---|
| 906 | if(m_cListPicYuvRec[layer]) |
|---|
| 907 | { |
|---|
| 908 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layer]->begin(); |
|---|
| 909 | Int iSize = Int( m_cListPicYuvRec[layer]->size() ); |
|---|
| 910 | #else |
|---|
| 911 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.begin(); |
|---|
| 912 | |
|---|
| 913 | Int iSize = Int( m_cListPicYuvRec.size() ); |
|---|
| 914 | #endif |
|---|
| 915 | |
|---|
| 916 | for ( Int i = 0; i < iSize; i++ ) |
|---|
| 917 | { |
|---|
| 918 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
|---|
| 919 | pcPicYuvRec->destroy(); |
|---|
| 920 | delete pcPicYuvRec; pcPicYuvRec = NULL; |
|---|
| 921 | } |
|---|
| 922 | #if NH_MV |
|---|
| 923 | } |
|---|
| 924 | } |
|---|
| 925 | #endif |
|---|
| 926 | |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | /** |
|---|
| 930 | Write access units to output file. |
|---|
| 931 | \param bitstreamFile target bitstream file |
|---|
| 932 | \param iNumEncoded number of encoded frames |
|---|
| 933 | \param accessUnits list of access units to be written |
|---|
| 934 | */ |
|---|
| 935 | #if NH_MV |
|---|
| 936 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerIdx) |
|---|
| 937 | #else |
|---|
| 938 | Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits) |
|---|
| 939 | #endif |
|---|
| 940 | { |
|---|
| 941 | const InputColourSpaceConversion ipCSC = (!m_outputInternalColourSpace) ? m_inputColourSpaceConvert : IPCOLOURSPACE_UNCHANGED; |
|---|
| 942 | |
|---|
| 943 | if (m_isField) |
|---|
| 944 | { |
|---|
| 945 | //Reinterlace fields |
|---|
| 946 | Int i; |
|---|
| 947 | #if NH_MV |
|---|
| 948 | if( iNumEncoded > 0 ) |
|---|
| 949 | { |
|---|
| 950 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end(); |
|---|
| 951 | #else |
|---|
| 952 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
|---|
| 953 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
|---|
| 954 | #endif |
|---|
| 955 | |
|---|
| 956 | for ( i = 0; i < iNumEncoded; i++ ) |
|---|
| 957 | { |
|---|
| 958 | --iterPicYuvRec; |
|---|
| 959 | } |
|---|
| 960 | |
|---|
| 961 | for ( i = 0; i < iNumEncoded/2; i++ ) |
|---|
| 962 | { |
|---|
| 963 | TComPicYuv* pcPicYuvRecTop = *(iterPicYuvRec++); |
|---|
| 964 | TComPicYuv* pcPicYuvRecBottom = *(iterPicYuvRec++); |
|---|
| 965 | |
|---|
| 966 | #if NH_MV |
|---|
| 967 | if (m_pchReconFileList[layerIdx]) |
|---|
| 968 | { |
|---|
| 969 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
|---|
| 970 | } |
|---|
| 971 | } |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | if( ! accessUnits.empty() ) |
|---|
| 975 | { |
|---|
| 976 | list<AccessUnit>::iterator aUIter; |
|---|
| 977 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
|---|
| 978 | { |
|---|
| 979 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, *aUIter); |
|---|
| 980 | rateStatsAccum(*aUIter, stats); |
|---|
| 981 | } |
|---|
| 982 | } |
|---|
| 983 | #else |
|---|
| 984 | if (m_pchReconFile) |
|---|
| 985 | { |
|---|
| 986 | m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, NUM_CHROMA_FORMAT, m_isTopFieldFirst ); |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | const AccessUnit& auTop = *(iterBitstream++); |
|---|
| 990 | const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop); |
|---|
| 991 | rateStatsAccum(auTop, statsTop); |
|---|
| 992 | |
|---|
| 993 | const AccessUnit& auBottom = *(iterBitstream++); |
|---|
| 994 | const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom); |
|---|
| 995 | rateStatsAccum(auBottom, statsBottom); |
|---|
| 996 | } |
|---|
| 997 | #endif |
|---|
| 998 | } |
|---|
| 999 | else |
|---|
| 1000 | { |
|---|
| 1001 | Int i; |
|---|
| 1002 | #if NH_MV |
|---|
| 1003 | if( iNumEncoded > 0 ) |
|---|
| 1004 | { |
|---|
| 1005 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec[layerIdx]->end(); |
|---|
| 1006 | #else |
|---|
| 1007 | TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end(); |
|---|
| 1008 | list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin(); |
|---|
| 1009 | #endif |
|---|
| 1010 | |
|---|
| 1011 | for ( i = 0; i < iNumEncoded; i++ ) |
|---|
| 1012 | { |
|---|
| 1013 | --iterPicYuvRec; |
|---|
| 1014 | } |
|---|
| 1015 | |
|---|
| 1016 | for ( i = 0; i < iNumEncoded; i++ ) |
|---|
| 1017 | { |
|---|
| 1018 | TComPicYuv* pcPicYuvRec = *(iterPicYuvRec++); |
|---|
| 1019 | #if NH_MV |
|---|
| 1020 | if (m_pchReconFileList[layerIdx]) |
|---|
| 1021 | { |
|---|
| 1022 | m_acTVideoIOYuvReconFileList[layerIdx]->write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom ); |
|---|
| 1023 | |
|---|
| 1024 | } |
|---|
| 1025 | } |
|---|
| 1026 | } |
|---|
| 1027 | if( ! accessUnits.empty() ) |
|---|
| 1028 | { |
|---|
| 1029 | list<AccessUnit>::iterator aUIter; |
|---|
| 1030 | for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ ) |
|---|
| 1031 | { |
|---|
| 1032 | const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter); |
|---|
| 1033 | rateStatsAccum(*aUIter, stats); |
|---|
| 1034 | } |
|---|
| 1035 | } |
|---|
| 1036 | #else |
|---|
| 1037 | if (m_pchReconFile) |
|---|
| 1038 | { |
|---|
| 1039 | m_cTVideoIOYuvReconFile.write( pcPicYuvRec, ipCSC, m_confWinLeft, m_confWinRight, m_confWinTop, m_confWinBottom, |
|---|
| 1040 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | const AccessUnit& au = *(iterBitstream++); |
|---|
| 1044 | const vector<UInt>& stats = writeAnnexB(bitstreamFile, au); |
|---|
| 1045 | rateStatsAccum(au, stats); |
|---|
| 1046 | } |
|---|
| 1047 | #endif |
|---|
| 1048 | } |
|---|
| 1049 | } |
|---|
| 1050 | |
|---|
| 1051 | /** |
|---|
| 1052 | * |
|---|
| 1053 | */ |
|---|
| 1054 | Void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& annexBsizes) |
|---|
| 1055 | { |
|---|
| 1056 | AccessUnit::const_iterator it_au = au.begin(); |
|---|
| 1057 | vector<UInt>::const_iterator it_stats = annexBsizes.begin(); |
|---|
| 1058 | |
|---|
| 1059 | for (; it_au != au.end(); it_au++, it_stats++) |
|---|
| 1060 | { |
|---|
| 1061 | switch ((*it_au)->m_nalUnitType) |
|---|
| 1062 | { |
|---|
| 1063 | case NAL_UNIT_CODED_SLICE_TRAIL_R: |
|---|
| 1064 | case NAL_UNIT_CODED_SLICE_TRAIL_N: |
|---|
| 1065 | case NAL_UNIT_CODED_SLICE_TSA_R: |
|---|
| 1066 | case NAL_UNIT_CODED_SLICE_TSA_N: |
|---|
| 1067 | case NAL_UNIT_CODED_SLICE_STSA_R: |
|---|
| 1068 | case NAL_UNIT_CODED_SLICE_STSA_N: |
|---|
| 1069 | case NAL_UNIT_CODED_SLICE_BLA_W_LP: |
|---|
| 1070 | case NAL_UNIT_CODED_SLICE_BLA_W_RADL: |
|---|
| 1071 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: |
|---|
| 1072 | case NAL_UNIT_CODED_SLICE_IDR_W_RADL: |
|---|
| 1073 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: |
|---|
| 1074 | case NAL_UNIT_CODED_SLICE_CRA: |
|---|
| 1075 | case NAL_UNIT_CODED_SLICE_RADL_N: |
|---|
| 1076 | case NAL_UNIT_CODED_SLICE_RADL_R: |
|---|
| 1077 | case NAL_UNIT_CODED_SLICE_RASL_N: |
|---|
| 1078 | case NAL_UNIT_CODED_SLICE_RASL_R: |
|---|
| 1079 | case NAL_UNIT_VPS: |
|---|
| 1080 | case NAL_UNIT_SPS: |
|---|
| 1081 | case NAL_UNIT_PPS: |
|---|
| 1082 | m_essentialBytes += *it_stats; |
|---|
| 1083 | break; |
|---|
| 1084 | default: |
|---|
| 1085 | break; |
|---|
| 1086 | } |
|---|
| 1087 | |
|---|
| 1088 | m_totalBytes += *it_stats; |
|---|
| 1089 | } |
|---|
| 1090 | } |
|---|
| 1091 | |
|---|
| 1092 | Void TAppEncTop::printRateSummary() |
|---|
| 1093 | { |
|---|
| 1094 | #if NH_MV |
|---|
| 1095 | Double time = (Double) m_frameRcvd[0] / m_iFrameRate; |
|---|
| 1096 | printf("\n"); |
|---|
| 1097 | #else |
|---|
| 1098 | Double time = (Double) m_iFrameRcvd / m_iFrameRate; |
|---|
| 1099 | #endif |
|---|
| 1100 | printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time); |
|---|
| 1101 | if (m_summaryVerboseness > 0) |
|---|
| 1102 | { |
|---|
| 1103 | printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time); |
|---|
| 1104 | } |
|---|
| 1105 | } |
|---|
| 1106 | |
|---|
| 1107 | Void TAppEncTop::printChromaFormat() |
|---|
| 1108 | { |
|---|
| 1109 | std::cout << std::setw(43) << "Input ChromaFormatIDC = "; |
|---|
| 1110 | switch (m_InputChromaFormatIDC) |
|---|
| 1111 | { |
|---|
| 1112 | case CHROMA_400: std::cout << " 4:0:0"; break; |
|---|
| 1113 | case CHROMA_420: std::cout << " 4:2:0"; break; |
|---|
| 1114 | case CHROMA_422: std::cout << " 4:2:2"; break; |
|---|
| 1115 | case CHROMA_444: std::cout << " 4:4:4"; break; |
|---|
| 1116 | default: |
|---|
| 1117 | std::cerr << "Invalid"; |
|---|
| 1118 | exit(1); |
|---|
| 1119 | } |
|---|
| 1120 | std::cout << std::endl; |
|---|
| 1121 | |
|---|
| 1122 | #if NH_MV |
|---|
| 1123 | for (Int i = 0; i < m_numberOfLayers; i++) |
|---|
| 1124 | { |
|---|
| 1125 | std::cout << "Layer " << i << std::setw( 43 - (i > 9 ? 6 : 7) ) << "Internal ChromaFormatIDC = "; |
|---|
| 1126 | switch (m_acTEncTopList[i]->getChromaFormatIdc()) |
|---|
| 1127 | #else |
|---|
| 1128 | std::cout << std::setw(43) << "Output (internal) ChromaFormatIDC = "; |
|---|
| 1129 | switch (m_cTEncTop.getChromaFormatIdc()) |
|---|
| 1130 | #endif |
|---|
| 1131 | { |
|---|
| 1132 | case CHROMA_400: std::cout << " 4:0:0"; break; |
|---|
| 1133 | case CHROMA_420: std::cout << " 4:2:0"; break; |
|---|
| 1134 | case CHROMA_422: std::cout << " 4:2:2"; break; |
|---|
| 1135 | case CHROMA_444: std::cout << " 4:4:4"; break; |
|---|
| 1136 | default: |
|---|
| 1137 | std::cerr << "Invalid"; |
|---|
| 1138 | exit(1); |
|---|
| 1139 | } |
|---|
| 1140 | #if NH_MV |
|---|
| 1141 | std::cout << std::endl; |
|---|
| 1142 | } |
|---|
| 1143 | #endif |
|---|
| 1144 | std::cout << "\n" << std::endl; |
|---|
| 1145 | } |
|---|
| 1146 | |
|---|
| 1147 | |
|---|
| 1148 | #if NH_MV |
|---|
| 1149 | Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps ) |
|---|
| 1150 | { |
|---|
| 1151 | vps.setScalabilityMaskFlag( m_scalabilityMask ); |
|---|
| 1152 | for( Int dim = 0; dim < m_dimIds.size(); dim++ ) |
|---|
| 1153 | { |
|---|
| 1154 | vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] ); |
|---|
| 1155 | for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ ) |
|---|
| 1156 | { |
|---|
| 1157 | vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] ); |
|---|
| 1158 | } |
|---|
| 1159 | } |
|---|
| 1160 | |
|---|
| 1161 | vps.initNumViews(); |
|---|
| 1162 | Int maxViewId = xGetMax( m_viewId ); |
|---|
| 1163 | |
|---|
| 1164 | Int viewIdLen = gCeilLog2( maxViewId + 1 ); |
|---|
| 1165 | const Int maxViewIdLen = ( 1 << 4 ) - 1; |
|---|
| 1166 | assert( viewIdLen <= maxViewIdLen ); |
|---|
| 1167 | vps.setViewIdLen( viewIdLen ); |
|---|
| 1168 | for (Int i = 0; i < m_iNumberOfViews; i++) |
|---|
| 1169 | { |
|---|
| 1170 | vps.setViewIdVal( i, m_viewId[ i] ); |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | assert( m_iNumberOfViews == vps.getNumViews() ); |
|---|
| 1174 | |
|---|
| 1175 | |
|---|
| 1176 | } |
|---|
| 1177 | |
|---|
| 1178 | Void TAppEncTop::xSetDependencies( TComVPS& vps ) |
|---|
| 1179 | { |
|---|
| 1180 | // Direct dependency flags + dependency types |
|---|
| 1181 | for( Int depLayer = 1; depLayer < MAX_NUM_LAYERS; depLayer++ ) |
|---|
| 1182 | { |
|---|
| 1183 | for( Int refLayer = 0; refLayer < MAX_NUM_LAYERS; refLayer++ ) |
|---|
| 1184 | { |
|---|
| 1185 | vps.setDirectDependencyFlag( depLayer, refLayer, false); |
|---|
| 1186 | vps.setDirectDependencyType( depLayer, refLayer, -1 ); |
|---|
| 1187 | } |
|---|
| 1188 | } |
|---|
| 1189 | |
|---|
| 1190 | Int defaultDirectDependencyType = -1; |
|---|
| 1191 | Bool defaultDirectDependencyFlag = false; |
|---|
| 1192 | |
|---|
| 1193 | Int directDepTypeLenMinus2 = 0; |
|---|
| 1194 | for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ ) |
|---|
| 1195 | { |
|---|
| 1196 | Int numRefLayers = (Int) m_directRefLayers[depLayer].size(); |
|---|
| 1197 | assert( numRefLayers == (Int) m_dependencyTypes[depLayer].size() ); |
|---|
| 1198 | for( Int i = 0; i < numRefLayers; i++ ) |
|---|
| 1199 | { |
|---|
| 1200 | Int refLayer = m_directRefLayers[depLayer][i]; |
|---|
| 1201 | vps.setDirectDependencyFlag( depLayer, refLayer, true); |
|---|
| 1202 | Int curDirectDependencyType = m_dependencyTypes[depLayer][i]; |
|---|
| 1203 | directDepTypeLenMinus2 = std::max( directDepTypeLenMinus2, gCeilLog2( curDirectDependencyType + 1 ) - 2 ); |
|---|
| 1204 | if ( defaultDirectDependencyType != -1 ) |
|---|
| 1205 | { |
|---|
| 1206 | defaultDirectDependencyFlag = defaultDirectDependencyFlag && (curDirectDependencyType == defaultDirectDependencyType ); |
|---|
| 1207 | } |
|---|
| 1208 | else |
|---|
| 1209 | { |
|---|
| 1210 | defaultDirectDependencyType = curDirectDependencyType; |
|---|
| 1211 | defaultDirectDependencyFlag = true; |
|---|
| 1212 | } |
|---|
| 1213 | |
|---|
| 1214 | vps.setDirectDependencyType( depLayer, refLayer, curDirectDependencyType); |
|---|
| 1215 | } |
|---|
| 1216 | } |
|---|
| 1217 | |
|---|
| 1218 | vps.setDefaultDirectDependencyFlag( defaultDirectDependencyFlag ); |
|---|
| 1219 | vps.setDefaultDirectDependencyType( defaultDirectDependencyFlag ? defaultDirectDependencyType : -1 ); |
|---|
| 1220 | |
|---|
| 1221 | assert( directDepTypeLenMinus2 <= 1 ); |
|---|
| 1222 | vps.setDirectDepTypeLenMinus2( directDepTypeLenMinus2 ); |
|---|
| 1223 | |
|---|
| 1224 | |
|---|
| 1225 | vps.setRefLayers(); |
|---|
| 1226 | |
|---|
| 1227 | // Max sub layers, + presence flag |
|---|
| 1228 | Bool subLayersMaxMinus1PresentFlag = false; |
|---|
| 1229 | for (Int curLayerIdInVps = 0; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++ ) |
|---|
| 1230 | { |
|---|
| 1231 | Int curSubLayersMaxMinus1 = 0; |
|---|
| 1232 | for( Int i = 0; i < getGOPSize(); i++ ) |
|---|
| 1233 | { |
|---|
| 1234 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][i]; |
|---|
| 1235 | curSubLayersMaxMinus1 = std::max( curSubLayersMaxMinus1, geCur.m_temporalId ); |
|---|
| 1236 | } |
|---|
| 1237 | |
|---|
| 1238 | vps.setSubLayersVpsMaxMinus1( curLayerIdInVps, curSubLayersMaxMinus1 ); |
|---|
| 1239 | subLayersMaxMinus1PresentFlag = subLayersMaxMinus1PresentFlag || ( curSubLayersMaxMinus1 != vps.getMaxSubLayersMinus1() ); |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | vps.setVpsSubLayersMaxMinus1PresentFlag( subLayersMaxMinus1PresentFlag ); |
|---|
| 1243 | |
|---|
| 1244 | // Max temporal id for inter layer reference pictures |
|---|
| 1245 | for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++) |
|---|
| 1246 | { |
|---|
| 1247 | Int refLayerIdInNuh = vps.getLayerIdInNuh( refLayerIdInVps ); |
|---|
| 1248 | for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++) |
|---|
| 1249 | { |
|---|
| 1250 | Int curLayerIdInNuh = vps.getLayerIdInNuh( curLayerIdInVps ); |
|---|
| 1251 | Int maxTid = -1; |
|---|
| 1252 | for( Int i = 0; i < ( getGOPSize() + 1); i++ ) |
|---|
| 1253 | { |
|---|
| 1254 | GOPEntry geCur = m_GOPListMvc[curLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
|---|
| 1255 | GOPEntry geRef = m_GOPListMvc[refLayerIdInVps][( i < getGOPSize() ? i : MAX_GOP )]; |
|---|
| 1256 | for (Int j = 0; j < geCur.m_numActiveRefLayerPics; j++) |
|---|
| 1257 | { |
|---|
| 1258 | if ( vps.getIdDirectRefLayer( curLayerIdInNuh, geCur.m_interLayerPredLayerIdc[ j ] ) == refLayerIdInNuh ) |
|---|
| 1259 | { |
|---|
| 1260 | Bool refLayerZero = ( i == getGOPSize() ) && ( refLayerIdInVps == 0 ); |
|---|
| 1261 | maxTid = std::max( maxTid, refLayerZero ? 0 : geRef.m_temporalId ); |
|---|
| 1262 | } |
|---|
| 1263 | } |
|---|
| 1264 | } |
|---|
| 1265 | } // Loop curLayerIdInVps |
|---|
| 1266 | } // Loop refLayerIdInVps |
|---|
| 1267 | |
|---|
| 1268 | // Max temporal id for inter layer reference pictures presence flag |
|---|
| 1269 | Bool maxTidRefPresentFlag = false; |
|---|
| 1270 | for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++) |
|---|
| 1271 | { |
|---|
| 1272 | for ( Int curLayerIdInVps = 1; curLayerIdInVps < m_numberOfLayers; curLayerIdInVps++) |
|---|
| 1273 | { |
|---|
| 1274 | maxTidRefPresentFlag = maxTidRefPresentFlag || ( vps.getMaxTidIlRefPicsPlus1( refLayerIdInVps, curLayerIdInVps ) != 7 ); |
|---|
| 1275 | } |
|---|
| 1276 | } |
|---|
| 1277 | vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag ); |
|---|
| 1278 | |
|---|
| 1279 | |
|---|
| 1280 | // Max one active ref layer flag |
|---|
| 1281 | Bool maxOneActiveRefLayerFlag = true; |
|---|
| 1282 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++) |
|---|
| 1283 | { |
|---|
| 1284 | for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) |
|---|
| 1285 | { |
|---|
| 1286 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
|---|
| 1287 | maxOneActiveRefLayerFlag = maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); |
|---|
| 1288 | } |
|---|
| 1289 | } |
|---|
| 1290 | |
|---|
| 1291 | vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag ); |
|---|
| 1292 | |
|---|
| 1293 | // Poc Lsb Not Present Flag |
|---|
| 1294 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers; layerIdInVps++) |
|---|
| 1295 | { |
|---|
| 1296 | if ( m_directRefLayers[ layerIdInVps ].size() == 0 ) |
|---|
| 1297 | { |
|---|
| 1298 | vps.setPocLsbNotPresentFlag( layerIdInVps, true ); |
|---|
| 1299 | } |
|---|
| 1300 | } |
|---|
| 1301 | |
|---|
| 1302 | // All Ref layers active flag |
|---|
| 1303 | Bool allRefLayersActiveFlag = true; |
|---|
| 1304 | for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++) |
|---|
| 1305 | { |
|---|
| 1306 | Int layerIdInNuh = vps.getLayerIdInNuh( layerIdInVps ); |
|---|
| 1307 | for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) |
|---|
| 1308 | { |
|---|
| 1309 | GOPEntry ge = m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]; |
|---|
| 1310 | Int tId = ge.m_temporalId; // Should be equal for all layers. |
|---|
| 1311 | |
|---|
| 1312 | // check if all reference layers when allRefLayerActiveFlag is equal to 1 are reference layer pictures specified in the gop entry |
|---|
| 1313 | for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ) && allRefLayersActiveFlag; k++ ) |
|---|
| 1314 | { |
|---|
| 1315 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh , k ) ); |
|---|
| 1316 | if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId ) ) |
|---|
| 1317 | { |
|---|
| 1318 | Bool gopEntryFoundFlag = false; |
|---|
| 1319 | for( Int l = 0; l < ge.m_numActiveRefLayerPics && !gopEntryFoundFlag; l++ ) |
|---|
| 1320 | { |
|---|
| 1321 | gopEntryFoundFlag = gopEntryFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
|---|
| 1322 | } |
|---|
| 1323 | allRefLayersActiveFlag = allRefLayersActiveFlag && gopEntryFoundFlag; |
|---|
| 1324 | } |
|---|
| 1325 | } |
|---|
| 1326 | |
|---|
| 1327 | // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1 |
|---|
| 1328 | // (Should actually always be true) |
|---|
| 1329 | Bool maxTidIlRefAndSubLayerMaxValidFlag = true; |
|---|
| 1330 | for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ ) |
|---|
| 1331 | { |
|---|
| 1332 | Bool referenceLayerFoundFlag = false; |
|---|
| 1333 | for (Int k = 0; k < vps.getNumDirectRefLayers( layerIdInNuh ); k++ ) |
|---|
| 1334 | { |
|---|
| 1335 | Int refLayerIdInVps = vps.getLayerIdInVps( vps.getIdDirectRefLayer( layerIdInNuh, k) ); |
|---|
| 1336 | if ( vps.getSubLayersVpsMaxMinus1(refLayerIdInVps) >= tId && ( tId == 0 || vps.getMaxTidIlRefPicsPlus1(refLayerIdInVps,layerIdInVps) > tId ) ) |
|---|
| 1337 | { |
|---|
| 1338 | referenceLayerFoundFlag = referenceLayerFoundFlag || ( ge.m_interLayerPredLayerIdc[l] == k ); |
|---|
| 1339 | } |
|---|
| 1340 | } |
|---|
| 1341 | maxTidIlRefAndSubLayerMaxValidFlag = maxTidIlRefAndSubLayerMaxValidFlag && referenceLayerFoundFlag; |
|---|
| 1342 | } |
|---|
| 1343 | assert ( maxTidIlRefAndSubLayerMaxValidFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1 |
|---|
| 1344 | } |
|---|
| 1345 | } |
|---|
| 1346 | |
|---|
| 1347 | vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag ); |
|---|
| 1348 | }; |
|---|
| 1349 | |
|---|
| 1350 | |
|---|
| 1351 | GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc ) |
|---|
| 1352 | { |
|---|
| 1353 | GOPEntry* geFound = NULL; |
|---|
| 1354 | for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) |
|---|
| 1355 | { |
|---|
| 1356 | GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize() ? i : MAX_GOP ) ]); |
|---|
| 1357 | if ( ge->m_POC == poc ) |
|---|
| 1358 | { |
|---|
| 1359 | geFound = ge; |
|---|
| 1360 | } |
|---|
| 1361 | } |
|---|
| 1362 | assert( geFound != NULL ); |
|---|
| 1363 | return geFound; |
|---|
| 1364 | } |
|---|
| 1365 | |
|---|
| 1366 | |
|---|
| 1367 | Void TAppEncTop::xSetTimingInfo( TComVPS& vps ) |
|---|
| 1368 | { |
|---|
| 1369 | vps.getTimingInfo()->setTimingInfoPresentFlag( false ); |
|---|
| 1370 | } |
|---|
| 1371 | |
|---|
| 1372 | Void TAppEncTop::xSetHrdParameters( TComVPS& vps ) |
|---|
| 1373 | { |
|---|
| 1374 | vps.createHrdParamBuffer(); |
|---|
| 1375 | for( Int i = 0; i < vps.getNumHrdParameters(); i++ ) |
|---|
| 1376 | { |
|---|
| 1377 | vps.setHrdOpSetIdx( 0, i ); |
|---|
| 1378 | vps.setCprmsPresentFlag( false, i ); |
|---|
| 1379 | } |
|---|
| 1380 | } |
|---|
| 1381 | |
|---|
| 1382 | Void TAppEncTop::xSetLayerIds( TComVPS& vps ) |
|---|
| 1383 | { |
|---|
| 1384 | vps.setSplittingFlag ( m_splittingFlag ); |
|---|
| 1385 | |
|---|
| 1386 | Bool nuhLayerIdPresentFlag = false; |
|---|
| 1387 | |
|---|
| 1388 | |
|---|
| 1389 | vps.setVpsMaxLayerId( xGetMax( m_layerIdInNuh ) ); |
|---|
| 1390 | |
|---|
| 1391 | for (Int i = 0; i < m_numberOfLayers; i++) |
|---|
| 1392 | { |
|---|
| 1393 | nuhLayerIdPresentFlag = nuhLayerIdPresentFlag || ( m_layerIdInNuh[i] != i ); |
|---|
| 1394 | } |
|---|
| 1395 | |
|---|
| 1396 | vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); |
|---|
| 1397 | |
|---|
| 1398 | for (Int layer = 0; layer < m_numberOfLayers; layer++ ) |
|---|
| 1399 | { |
|---|
| 1400 | vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); |
|---|
| 1401 | vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); |
|---|
| 1402 | } |
|---|
| 1403 | } |
|---|
| 1404 | |
|---|
| 1405 | Int TAppEncTop::xGetMax( std::vector<Int>& vec ) |
|---|
| 1406 | { |
|---|
| 1407 | Int maxVec = 0; |
|---|
| 1408 | for ( Int i = 0; i < vec.size(); i++) |
|---|
| 1409 | { |
|---|
| 1410 | maxVec = max( vec[i], maxVec ); |
|---|
| 1411 | } |
|---|
| 1412 | return maxVec; |
|---|
| 1413 | } |
|---|
| 1414 | |
|---|
| 1415 | Void TAppEncTop::xSetProfileTierLevel( TComVPS& vps ) |
|---|
| 1416 | { |
|---|
| 1417 | |
|---|
| 1418 | // SET PTL |
|---|
| 1419 | assert( m_profiles.size() == m_level.size() && m_profiles.size() == m_levelTier.size() ); |
|---|
| 1420 | vps.setVpsNumProfileTierLevelMinus1( (Int) m_profiles.size() - 1 ); |
|---|
| 1421 | for ( Int ptlIdx = 0; ptlIdx <= vps.getVpsNumProfileTierLevelMinus1(); ptlIdx++ ) |
|---|
| 1422 | { |
|---|
| 1423 | if ( ptlIdx > 1 ) |
|---|
| 1424 | { |
|---|
| 1425 | Bool vpsProfilePresentFlag = ( m_profiles[ptlIdx] != m_profiles[ptlIdx - 1] ) |
|---|
| 1426 | || ( m_inblFlag[ptlIdx ] != m_inblFlag[ptlIdx - 1] ); |
|---|
| 1427 | vps.setVpsProfilePresentFlag( ptlIdx, vpsProfilePresentFlag ); |
|---|
| 1428 | } |
|---|
| 1429 | |
|---|
| 1430 | xSetProfileTierLevel( vps, ptlIdx, -1, m_profiles[ptlIdx], m_level[ptlIdx], |
|---|
| 1431 | m_levelTier[ ptlIdx ], m_progressiveSourceFlag, m_interlacedSourceFlag, |
|---|
| 1432 | m_nonPackedConstraintFlag, m_frameOnlyConstraintFlag, m_inblFlag[ptlIdx] ); |
|---|
| 1433 | } |
|---|
| 1434 | } |
|---|
| 1435 | |
|---|
| 1436 | Void TAppEncTop::xSetProfileTierLevel(TComVPS& vps, Int profileTierLevelIdx, Int subLayer, Profile::Name profile, Level::Name level, Level::Tier tier, Bool progressiveSourceFlag, Bool interlacedSourceFlag, Bool nonPackedConstraintFlag, Bool frameOnlyConstraintFlag, Bool inbldFlag) |
|---|
| 1437 | { |
|---|
| 1438 | TComPTL* ptlStruct = vps.getPTL( profileTierLevelIdx ); |
|---|
| 1439 | assert( ptlStruct != NULL ); |
|---|
| 1440 | |
|---|
| 1441 | ProfileTierLevel* ptl; |
|---|
| 1442 | if ( subLayer == -1 ) |
|---|
| 1443 | { |
|---|
| 1444 | ptl = ptlStruct->getGeneralPTL(); |
|---|
| 1445 | } |
|---|
| 1446 | else |
|---|
| 1447 | { |
|---|
| 1448 | ptl = ptlStruct->getSubLayerPTL( subLayer ); |
|---|
| 1449 | } |
|---|
| 1450 | |
|---|
| 1451 | assert( ptl != NULL ); |
|---|
| 1452 | |
|---|
| 1453 | ptl->setProfileIdc( profile ); |
|---|
| 1454 | ptl->setTierFlag ( tier ); |
|---|
| 1455 | ptl->setLevelIdc ( level ); |
|---|
| 1456 | ptl->setProfileCompatibilityFlag( profile, true ); |
|---|
| 1457 | ptl->setInbldFlag( inbldFlag ); |
|---|
| 1458 | |
|---|
| 1459 | switch ( profile ) |
|---|
| 1460 | { |
|---|
| 1461 | case Profile::MAIN: |
|---|
| 1462 | break; |
|---|
| 1463 | case Profile::MULTIVIEWMAIN: |
|---|
| 1464 | ptl->setMax12bitConstraintFlag ( true ); |
|---|
| 1465 | ptl->setMax12bitConstraintFlag ( true ); |
|---|
| 1466 | ptl->setMax10bitConstraintFlag ( true ); |
|---|
| 1467 | ptl->setMax8bitConstraintFlag ( true ); |
|---|
| 1468 | ptl->setMax422chromaConstraintFlag ( true ); |
|---|
| 1469 | ptl->setMax420chromaConstraintFlag ( true ); |
|---|
| 1470 | ptl->setMaxMonochromeConstraintFlag ( false ); |
|---|
| 1471 | ptl->setIntraConstraintFlag ( false ); |
|---|
| 1472 | ptl->setOnePictureOnlyConstraintFlag( false ); |
|---|
| 1473 | ptl->setLowerBitRateConstraintFlag ( true ); |
|---|
| 1474 | break; |
|---|
| 1475 | default: |
|---|
| 1476 | assert( 0 ); // other profiles currently not supported |
|---|
| 1477 | break; |
|---|
| 1478 | } |
|---|
| 1479 | } |
|---|
| 1480 | |
|---|
| 1481 | Void TAppEncTop::xSetRepFormat( TComVPS& vps ) |
|---|
| 1482 | { |
|---|
| 1483 | |
|---|
| 1484 | Bool anyDepth = false; |
|---|
| 1485 | |
|---|
| 1486 | vps.setRepFormatIdxPresentFlag( anyDepth ); |
|---|
| 1487 | vps.setVpsNumRepFormatsMinus1 ( anyDepth ? 1 : 0 ); |
|---|
| 1488 | |
|---|
| 1489 | |
|---|
| 1490 | std::vector<TComRepFormat> repFormat; |
|---|
| 1491 | repFormat.resize( vps.getVpsNumRepFormatsMinus1() + 1 ); |
|---|
| 1492 | for ( Int j = 0; j <= vps.getVpsNumRepFormatsMinus1(); j++ ) |
|---|
| 1493 | { |
|---|
| 1494 | repFormat[j].setBitDepthVpsChromaMinus8 ( m_internalBitDepth[CHANNEL_TYPE_LUMA ] - 8 ); |
|---|
| 1495 | repFormat[j].setBitDepthVpsLumaMinus8 ( m_internalBitDepth[CHANNEL_TYPE_CHROMA] - 8 ); |
|---|
| 1496 | repFormat[j].setChromaFormatVpsIdc ( j == 1 ? CHROMA_400 : CHROMA_420 ); |
|---|
| 1497 | repFormat[j].setPicHeightVpsInLumaSamples ( m_iSourceHeight ); |
|---|
| 1498 | repFormat[j].setPicWidthVpsInLumaSamples ( m_iSourceWidth ); |
|---|
| 1499 | repFormat[j].setChromaAndBitDepthVpsPresentFlag( true ); |
|---|
| 1500 | // ToDo not supported yet. |
|---|
| 1501 | //repFormat->setSeparateColourPlaneVpsFlag( ); |
|---|
| 1502 | |
|---|
| 1503 | repFormat[j].setConformanceWindowVpsFlag( true ); |
|---|
| 1504 | repFormat[j].setConfWinVpsLeftOffset ( m_confWinLeft / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() ) ); |
|---|
| 1505 | repFormat[j].setConfWinVpsRightOffset ( m_confWinRight / TComSPS::getWinUnitX( repFormat[j].getChromaFormatVpsIdc() ) ); |
|---|
| 1506 | repFormat[j].setConfWinVpsTopOffset ( m_confWinTop / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() ) ); |
|---|
| 1507 | repFormat[j].setConfWinVpsBottomOffset ( m_confWinBottom / TComSPS::getWinUnitY( repFormat[j].getChromaFormatVpsIdc() ) ); |
|---|
| 1508 | } |
|---|
| 1509 | |
|---|
| 1510 | vps.setRepFormat( repFormat ); |
|---|
| 1511 | |
|---|
| 1512 | } |
|---|
| 1513 | |
|---|
| 1514 | Void TAppEncTop::xSetDpbSize ( TComVPS& vps ) |
|---|
| 1515 | { |
|---|
| 1516 | // These settings need to be verified |
|---|
| 1517 | |
|---|
| 1518 | TComDpbSize dpbSize; |
|---|
| 1519 | dpbSize.init( vps.getNumOutputLayerSets(), vps.getVpsMaxLayerId() + 1, vps.getMaxSubLayersMinus1() + 1 ) ; |
|---|
| 1520 | |
|---|
| 1521 | |
|---|
| 1522 | for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ ) |
|---|
| 1523 | { |
|---|
| 1524 | Int currLsIdx = vps.olsIdxToLsIdx( i ); |
|---|
| 1525 | Bool subLayerFlagInfoPresentFlag = false; |
|---|
| 1526 | |
|---|
| 1527 | for( Int j = 0; j <= vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ ) |
|---|
| 1528 | { |
|---|
| 1529 | Bool subLayerDpbInfoPresentFlag = false; |
|---|
| 1530 | for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ ) |
|---|
| 1531 | { |
|---|
| 1532 | Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList( currLsIdx, k ) ); |
|---|
| 1533 | if ( vps.getNecessaryLayerFlag( i,k ) && ( vps.getVpsBaseLayerInternalFlag() || vps.getLayerSetLayerIdList( currLsIdx, k ) != 0 ) ) |
|---|
| 1534 | { |
|---|
| 1535 | dpbSize.setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 ); |
|---|
| 1536 | if ( j > 0 ) |
|---|
| 1537 | { |
|---|
| 1538 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize.getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) ); |
|---|
| 1539 | } |
|---|
| 1540 | } |
|---|
| 1541 | else |
|---|
| 1542 | { |
|---|
| 1543 | if (vps.getNecessaryLayerFlag(i,k) && j == 0 && k == 0 ) |
|---|
| 1544 | { |
|---|
| 1545 | dpbSize.setMaxVpsDecPicBufferingMinus1(i, k ,j, 0 ); |
|---|
| 1546 | } |
|---|
| 1547 | } |
|---|
| 1548 | } |
|---|
| 1549 | |
|---|
| 1550 | Int maxNumReorderPics = MIN_INT; |
|---|
| 1551 | for ( Int idx = 0; idx < vps.getNumLayersInIdList( currLsIdx ); idx++ ) |
|---|
| 1552 | { |
|---|
| 1553 | if (vps.getNecessaryLayerFlag(i, idx )) |
|---|
| 1554 | { |
|---|
| 1555 | Int layerIdInVps = vps.getLayerIdInVps( vps.getLayerSetLayerIdList(currLsIdx, idx) ); |
|---|
| 1556 | maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] ); |
|---|
| 1557 | } |
|---|
| 1558 | } |
|---|
| 1559 | assert( maxNumReorderPics != MIN_INT ); |
|---|
| 1560 | |
|---|
| 1561 | dpbSize.setMaxVpsNumReorderPics( i, j, maxNumReorderPics ); |
|---|
| 1562 | if ( j > 0 ) |
|---|
| 1563 | { |
|---|
| 1564 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsNumReorderPics( i, j ) != dpbSize.getMaxVpsNumReorderPics( i, j - 1 ) ); |
|---|
| 1565 | } |
|---|
| 1566 | |
|---|
| 1567 | // To Be Done ! |
|---|
| 1568 | // dpbSize.setMaxVpsLatencyIncreasePlus1( i, j, xx ); |
|---|
| 1569 | if ( j > 0 ) |
|---|
| 1570 | { |
|---|
| 1571 | subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize.getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize.getMaxVpsLatencyIncreasePlus1( i, j - 1 ) ); |
|---|
| 1572 | } |
|---|
| 1573 | |
|---|
| 1574 | if( j > 0 ) |
|---|
| 1575 | { |
|---|
| 1576 | dpbSize.setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag ); |
|---|
| 1577 | subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag; |
|---|
| 1578 | } |
|---|
| 1579 | } |
|---|
| 1580 | dpbSize.setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag ); |
|---|
| 1581 | } |
|---|
| 1582 | vps.setDpbSize( dpbSize ); |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| 1585 | Void TAppEncTop::xSetLayerSets( TComVPS& vps ) |
|---|
| 1586 | { |
|---|
| 1587 | // Layer sets |
|---|
| 1588 | vps.setVpsNumLayerSetsMinus1 ( m_vpsNumLayerSets - 1 ); |
|---|
| 1589 | |
|---|
| 1590 | for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ ) |
|---|
| 1591 | { |
|---|
| 1592 | for( Int layerId = 0; layerId < MAX_NUM_LAYER_IDS; layerId++ ) |
|---|
| 1593 | { |
|---|
| 1594 | vps.setLayerIdIncludedFlag( false, lsIdx, layerId ); |
|---|
| 1595 | } |
|---|
| 1596 | for ( Int i = 0; i < m_layerIdsInSets[lsIdx].size(); i++) |
|---|
| 1597 | { |
|---|
| 1598 | vps.setLayerIdIncludedFlag( true, lsIdx, vps.getLayerIdInNuh( m_layerIdsInSets[lsIdx][i] ) ); |
|---|
| 1599 | } |
|---|
| 1600 | } |
|---|
| 1601 | vps.deriveLayerSetLayerIdList(); |
|---|
| 1602 | |
|---|
| 1603 | Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); |
|---|
| 1604 | // Additional output layer sets + profileLevelTierIdx |
|---|
| 1605 | vps.setDefaultOutputLayerIdc ( m_defaultOutputLayerIdc ); |
|---|
| 1606 | if( vps.getNumIndependentLayers() == 0 && m_numAddLayerSets > 0 ) |
|---|
| 1607 | { |
|---|
| 1608 | fprintf( stderr, "\nWarning: Ignoring additional layer sets since NumIndependentLayers is equal to 0.\n"); |
|---|
| 1609 | } |
|---|
| 1610 | else |
|---|
| 1611 | { |
|---|
| 1612 | vps.setNumAddLayerSets( m_numAddLayerSets ); |
|---|
| 1613 | if ( m_highestLayerIdxPlus1.size() < vps.getNumAddLayerSets() ) |
|---|
| 1614 | { |
|---|
| 1615 | fprintf(stderr, "\nError: Number of highestLayerIdxPlus1 parameters must be greater than or equal to NumAddLayerSets\n"); |
|---|
| 1616 | exit(EXIT_FAILURE); |
|---|
| 1617 | } |
|---|
| 1618 | |
|---|
| 1619 | for (Int i = 0; i < vps.getNumAddLayerSets(); i++) |
|---|
| 1620 | { |
|---|
| 1621 | if ( m_highestLayerIdxPlus1[ i ].size() < vps.getNumIndependentLayers() ) |
|---|
| 1622 | { |
|---|
| 1623 | fprintf(stderr, "Error: Number of elements in highestLayerIdxPlus1[ %d ] parameters must be greater than or equal to NumIndependentLayers(= %d)\n", i, vps.getNumIndependentLayers()); |
|---|
| 1624 | exit(EXIT_FAILURE); |
|---|
| 1625 | } |
|---|
| 1626 | |
|---|
| 1627 | for (Int j = 1; j < vps.getNumIndependentLayers(); j++) |
|---|
| 1628 | { |
|---|
| 1629 | if ( m_highestLayerIdxPlus1[ i ][ j ] < 0 || m_highestLayerIdxPlus1[ i ][ j ] > vps.getNumLayersInTreePartition( j ) ) |
|---|
| 1630 | { |
|---|
| 1631 | fprintf(stderr, "Error: highestLayerIdxPlus1[ %d ][ %d ] shall be in the range of 0 to NumLayersInTreePartition[ %d ] (= %d ), inclusive. \n", i, j, j, vps.getNumLayersInTreePartition( j ) ); |
|---|
| 1632 | exit(EXIT_FAILURE); |
|---|
| 1633 | } |
|---|
| 1634 | vps.setHighestLayerIdxPlus1( i, j, m_highestLayerIdxPlus1[ i ][ j ] ); |
|---|
| 1635 | } |
|---|
| 1636 | vps.deriveAddLayerSetLayerIdList( i ); |
|---|
| 1637 | } |
|---|
| 1638 | } |
|---|
| 1639 | vps.setNumAddOlss ( numAddOuputLayerSets ); |
|---|
| 1640 | vps.initTargetLayerIdLists(); |
|---|
| 1641 | |
|---|
| 1642 | for (Int olsIdx = 0; olsIdx < vps.getNumLayerSets() + numAddOuputLayerSets; olsIdx++) |
|---|
| 1643 | { |
|---|
| 1644 | Int addOutLsIdx = olsIdx - vps.getNumLayerSets(); |
|---|
| 1645 | vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ? olsIdx : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); |
|---|
| 1646 | |
|---|
| 1647 | Int lsIdx = vps.olsIdxToLsIdx( olsIdx ); |
|---|
| 1648 | if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 ) |
|---|
| 1649 | { |
|---|
| 1650 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
|---|
| 1651 | { |
|---|
| 1652 | vps.setOutputLayerFlag( olsIdx, i, ( olsIdx == 0 && i == 0 ) ? vps.inferOutputLayerFlag(olsIdx, i ) : false ); // This is a software only fix for a bug in the spec. In spec outputLayerFlag neither present nor inferred for this case ! |
|---|
| 1653 | } |
|---|
| 1654 | |
|---|
| 1655 | std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx]; |
|---|
| 1656 | |
|---|
| 1657 | Bool outputLayerInLayerSetFlag = false; |
|---|
| 1658 | for (Int j = 0; j < outLayerIdList.size(); j++) |
|---|
| 1659 | { |
|---|
| 1660 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
|---|
| 1661 | { |
|---|
| 1662 | if ( vps.getLayerSetLayerIdList( lsIdx, i ) == outLayerIdList[ j ] ) |
|---|
| 1663 | { |
|---|
| 1664 | vps.setOutputLayerFlag( olsIdx, i, true ); |
|---|
| 1665 | outputLayerInLayerSetFlag = true; |
|---|
| 1666 | break; |
|---|
| 1667 | } |
|---|
| 1668 | } |
|---|
| 1669 | if ( !outputLayerInLayerSetFlag ) |
|---|
| 1670 | { |
|---|
| 1671 | fprintf(stderr, "Error: Output layer %d in output layer set %d not in corresponding layer set %d \n", outLayerIdList[ j ], olsIdx , lsIdx ); |
|---|
| 1672 | exit(EXIT_FAILURE); |
|---|
| 1673 | } |
|---|
| 1674 | } |
|---|
| 1675 | } |
|---|
| 1676 | else |
|---|
| 1677 | { |
|---|
| 1678 | for ( Int i = 0; i < vps.getNumLayersInIdList( lsIdx ); i++) |
|---|
| 1679 | { |
|---|
| 1680 | vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) ); |
|---|
| 1681 | } |
|---|
| 1682 | } |
|---|
| 1683 | |
|---|
| 1684 | vps.deriveNecessaryLayerFlags( olsIdx ); |
|---|
| 1685 | vps.deriveTargetLayerIdList( olsIdx ); |
|---|
| 1686 | |
|---|
| 1687 | // SET profile_tier_level_index. |
|---|
| 1688 | if ( olsIdx == 0 ) |
|---|
| 1689 | { |
|---|
| 1690 | vps.setProfileTierLevelIdx( 0, 0 , vps.getMaxLayersMinus1() > 0 ? 1 : 0 ); |
|---|
| 1691 | } |
|---|
| 1692 | else |
|---|
| 1693 | { |
|---|
| 1694 | if( (Int) m_profileTierLevelIdx[ olsIdx ].size() < vps.getNumLayersInIdList( lsIdx ) ) |
|---|
| 1695 | { |
|---|
| 1696 | fprintf( stderr, "Warning: Not enough profileTierLevelIdx values given for the %d-th OLS. Inferring default values.\n", olsIdx ); |
|---|
| 1697 | } |
|---|
| 1698 | for (Int j = 0; j < vps.getNumLayersInIdList( lsIdx ); j++) |
|---|
| 1699 | { |
|---|
| 1700 | if( j < (Int) m_profileTierLevelIdx[ olsIdx ].size() ) |
|---|
| 1701 | { |
|---|
| 1702 | vps.setProfileTierLevelIdx(olsIdx, j, m_profileTierLevelIdx[olsIdx][j] ); |
|---|
| 1703 | if( !vps.getNecessaryLayerFlag(olsIdx,j) && m_profileTierLevelIdx[ olsIdx ][ j ] != -1 ) |
|---|
| 1704 | { |
|---|
| 1705 | fprintf( stderr, "Warning: The %d-th layer in the %d-th OLS is not necessary such that profileTierLevelIdx[%d][%d] will be ignored. Set value to -1 to suppress warning.\n", j,olsIdx,olsIdx,j ); |
|---|
| 1706 | } |
|---|
| 1707 | } |
|---|
| 1708 | else if ( vps.getNecessaryLayerFlag(olsIdx,j) ) |
|---|
| 1709 | { |
|---|
| 1710 | // setting default values |
|---|
| 1711 | if ( j == 0 || vps.getVpsNumProfileTierLevelMinus1() < 1 ) |
|---|
| 1712 | { |
|---|
| 1713 | // set base layer as default |
|---|
| 1714 | vps.setProfileTierLevelIdx(olsIdx, j, 1 ); |
|---|
| 1715 | } |
|---|
| 1716 | else |
|---|
| 1717 | { |
|---|
| 1718 | // set VpsProfileTierLevel[2] as default |
|---|
| 1719 | vps.setProfileTierLevelIdx(olsIdx, j, 2 ); |
|---|
| 1720 | } |
|---|
| 1721 | } |
|---|
| 1722 | } |
|---|
| 1723 | } |
|---|
| 1724 | |
|---|
| 1725 | if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && |
|---|
| 1726 | vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) ) |
|---|
| 1727 | { |
|---|
| 1728 | vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]); |
|---|
| 1729 | } |
|---|
| 1730 | else |
|---|
| 1731 | { |
|---|
| 1732 | vps.setAltOutputLayerFlag( olsIdx , false ); |
|---|
| 1733 | if ( m_altOutputLayerFlag[ olsIdx ] ) |
|---|
| 1734 | { |
|---|
| 1735 | printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx ); |
|---|
| 1736 | } |
|---|
| 1737 | } |
|---|
| 1738 | } |
|---|
| 1739 | } |
|---|
| 1740 | |
|---|
| 1741 | Void TAppEncTop::xSetVPSVUI( TComVPS& vps ) |
|---|
| 1742 | { |
|---|
| 1743 | vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); |
|---|
| 1744 | |
|---|
| 1745 | TComVPSVUI vpsVui; |
|---|
| 1746 | vpsVui.init(vps.getNumAddLayerSets(),vps.getMaxSubLayersMinus1() + 1, vps.getMaxLayersMinus1() + 1 ); |
|---|
| 1747 | |
|---|
| 1748 | if ( m_vpsVuiPresentFlag ) |
|---|
| 1749 | { |
|---|
| 1750 | // All this stuff could actually be derived by the encoder, |
|---|
| 1751 | // however preliminary setting it from input parameters |
|---|
| 1752 | |
|---|
| 1753 | vpsVui.setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag ); |
|---|
| 1754 | vpsVui.setCrossLayerIrapAlignedFlag ( m_crossLayerIrapAlignedFlag ); |
|---|
| 1755 | vpsVui.setAllLayersIdrAlignedFlag ( m_allLayersIdrAlignedFlag ); |
|---|
| 1756 | vpsVui.setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag ); |
|---|
| 1757 | vpsVui.setPicRatePresentVpsFlag( m_picRatePresentVpsFlag ); |
|---|
| 1758 | |
|---|
| 1759 | if( vpsVui.getBitRatePresentVpsFlag( ) || vpsVui.getPicRatePresentVpsFlag( ) ) |
|---|
| 1760 | { |
|---|
| 1761 | for( Int i = 0; i < vps.getNumLayerSets(); i++ ) |
|---|
| 1762 | { |
|---|
| 1763 | for( Int j = 0; j <= vps.getMaxTLayers(); j++ ) |
|---|
| 1764 | { |
|---|
| 1765 | if( vpsVui.getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j ) |
|---|
| 1766 | { |
|---|
| 1767 | vpsVui.setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] ); |
|---|
| 1768 | } |
|---|
| 1769 | if( vpsVui.getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j ) |
|---|
| 1770 | { |
|---|
| 1771 | vpsVui.setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] ); |
|---|
| 1772 | } |
|---|
| 1773 | if( vpsVui.getBitRatePresentFlag( i, j ) && m_avgBitRate[i].size() > j ) |
|---|
| 1774 | { |
|---|
| 1775 | vpsVui.setAvgBitRate( i, j, m_avgBitRate[i][j] ); |
|---|
| 1776 | } |
|---|
| 1777 | if( vpsVui.getBitRatePresentFlag( i, j ) && m_maxBitRate[i].size() > j ) |
|---|
| 1778 | { |
|---|
| 1779 | vpsVui.setMaxBitRate( i, j, m_maxBitRate[i][j] ); |
|---|
| 1780 | } |
|---|
| 1781 | if( vpsVui.getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j ) |
|---|
| 1782 | { |
|---|
| 1783 | vpsVui.setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] ); |
|---|
| 1784 | } |
|---|
| 1785 | if( vpsVui.getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j ) |
|---|
| 1786 | { |
|---|
| 1787 | vpsVui.setAvgPicRate( i, j, m_avgPicRate[i][j] ); |
|---|
| 1788 | } |
|---|
| 1789 | } |
|---|
| 1790 | } |
|---|
| 1791 | } |
|---|
| 1792 | |
|---|
| 1793 | vpsVui.setTilesNotInUseFlag( m_tilesNotInUseFlag ); |
|---|
| 1794 | |
|---|
| 1795 | if( !vpsVui.getTilesNotInUseFlag() ) |
|---|
| 1796 | { |
|---|
| 1797 | for( Int i = 0; i <= vps.getMaxLayersMinus1(); i++ ) |
|---|
| 1798 | { |
|---|
| 1799 | vpsVui.setTilesInUseFlag( i, m_tilesInUseFlag[ i ] ); |
|---|
| 1800 | if( vpsVui.getTilesInUseFlag( i ) ) |
|---|
| 1801 | { |
|---|
| 1802 | vpsVui.setLoopFilterNotAcrossTilesFlag( i, m_loopFilterNotAcrossTilesFlag[ i ] ); |
|---|
| 1803 | } |
|---|
| 1804 | } |
|---|
| 1805 | |
|---|
| 1806 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
|---|
| 1807 | { |
|---|
| 1808 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ) ; j++ ) |
|---|
| 1809 | { |
|---|
| 1810 | Int layerIdx = vps.getLayerIdInVps( vps.getIdDirectRefLayer(vps.getLayerIdInNuh( i ) , j )); |
|---|
| 1811 | if( vpsVui.getTilesInUseFlag( i ) && vpsVui.getTilesInUseFlag( layerIdx ) ) |
|---|
| 1812 | { |
|---|
| 1813 | vpsVui.setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j] ); |
|---|
| 1814 | } |
|---|
| 1815 | } |
|---|
| 1816 | } |
|---|
| 1817 | } |
|---|
| 1818 | |
|---|
| 1819 | vpsVui.setWppNotInUseFlag( m_wppNotInUseFlag ); |
|---|
| 1820 | |
|---|
| 1821 | if( !vpsVui.getWppNotInUseFlag( ) ) |
|---|
| 1822 | { |
|---|
| 1823 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
|---|
| 1824 | { |
|---|
| 1825 | vpsVui.setWppInUseFlag( i, m_wppInUseFlag[ i ]); |
|---|
| 1826 | } |
|---|
| 1827 | } |
|---|
| 1828 | |
|---|
| 1829 | vpsVui.setSingleLayerForNonIrapFlag( m_singleLayerForNonIrapFlag ); |
|---|
| 1830 | vpsVui.setHigherLayerIrapSkipFlag( m_higherLayerIrapSkipFlag ); |
|---|
| 1831 | |
|---|
| 1832 | vpsVui.setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag ); |
|---|
| 1833 | |
|---|
| 1834 | if( vpsVui.getIlpRestrictedRefLayersFlag( ) ) |
|---|
| 1835 | { |
|---|
| 1836 | for( Int i = 1; i <= vps.getMaxLayersMinus1(); i++ ) |
|---|
| 1837 | { |
|---|
| 1838 | for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ ) |
|---|
| 1839 | { |
|---|
| 1840 | if ( m_minSpatialSegmentOffsetPlus1[i].size() > j ) |
|---|
| 1841 | { |
|---|
| 1842 | vpsVui.setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] ); |
|---|
| 1843 | } |
|---|
| 1844 | if( vpsVui.getMinSpatialSegmentOffsetPlus1( i, j ) > 0 ) |
|---|
| 1845 | { |
|---|
| 1846 | if ( m_ctuBasedOffsetEnabledFlag[i].size() > j ) |
|---|
| 1847 | { |
|---|
| 1848 | vpsVui.setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] ); |
|---|
| 1849 | } |
|---|
| 1850 | if( vpsVui.getCtuBasedOffsetEnabledFlag( i, j ) ) |
|---|
| 1851 | { |
|---|
| 1852 | if ( m_minHorizontalCtuOffsetPlus1[i].size() > j ) |
|---|
| 1853 | { |
|---|
| 1854 | vpsVui.setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] ); |
|---|
| 1855 | } |
|---|
| 1856 | } |
|---|
| 1857 | } |
|---|
| 1858 | } |
|---|
| 1859 | } |
|---|
| 1860 | } |
|---|
| 1861 | vpsVui.setVideoSignalInfoIdxPresentFlag( true ); |
|---|
| 1862 | vpsVui.setVpsNumVideoSignalInfoMinus1 ( 0 ); |
|---|
| 1863 | |
|---|
| 1864 | std::vector<TComVideoSignalInfo> videoSignalInfos; |
|---|
| 1865 | videoSignalInfos.resize( vpsVui.getVpsNumVideoSignalInfoMinus1() + 1 ); |
|---|
| 1866 | |
|---|
| 1867 | videoSignalInfos[0].setColourPrimariesVps ( m_colourPrimaries ); |
|---|
| 1868 | videoSignalInfos[0].setMatrixCoeffsVps ( m_matrixCoefficients ); |
|---|
| 1869 | videoSignalInfos[0].setTransferCharacteristicsVps( m_transferCharacteristics ); |
|---|
| 1870 | videoSignalInfos[0].setVideoVpsFormat ( m_videoFormat ); |
|---|
| 1871 | videoSignalInfos[0].setVideoFullRangeVpsFlag ( m_videoFullRangeFlag ); |
|---|
| 1872 | |
|---|
| 1873 | vpsVui.setVideoSignalInfo( videoSignalInfos ); |
|---|
| 1874 | |
|---|
| 1875 | for (Int i = 0; i < m_numberOfLayers; i++) |
|---|
| 1876 | { |
|---|
| 1877 | vpsVui.setVpsVideoSignalInfoIdx( i, 0 ); |
|---|
| 1878 | } |
|---|
| 1879 | vpsVui.setVpsVuiBspHrdPresentFlag( false ); // TBD |
|---|
| 1880 | } |
|---|
| 1881 | else |
|---|
| 1882 | { |
|---|
| 1883 | //Default inference when not present. |
|---|
| 1884 | vpsVui.setCrossLayerIrapAlignedFlag ( false ); |
|---|
| 1885 | } |
|---|
| 1886 | vps.setVPSVUI( vpsVui ); |
|---|
| 1887 | } |
|---|
| 1888 | |
|---|
| 1889 | |
|---|
| 1890 | |
|---|
| 1891 | Bool TAppEncTop::xLayerIdInTargetEncLayerIdList(Int nuhLayerId) |
|---|
| 1892 | { |
|---|
| 1893 | return ( std::find(m_targetEncLayerIdList.begin(), m_targetEncLayerIdList.end(), nuhLayerId) != m_targetEncLayerIdList.end()) ; |
|---|
| 1894 | } |
|---|
| 1895 | |
|---|
| 1896 | |
|---|
| 1897 | #endif |
|---|
| 1898 | |
|---|
| 1899 | |
|---|
| 1900 | //! \} |
|---|