[313] | 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 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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 TEncTop.cpp |
---|
| 35 | \brief encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TLibCommon/CommonDef.h" |
---|
| 39 | #include "TEncTop.h" |
---|
| 40 | #include "TEncPic.h" |
---|
| 41 | #if FAST_BIT_EST |
---|
| 42 | #include "TLibCommon/ContextModel.h" |
---|
| 43 | #endif |
---|
| 44 | |
---|
| 45 | //! \ingroup TLibEncoder |
---|
| 46 | //! \{ |
---|
| 47 | #if SVC_EXTENSION |
---|
| 48 | Int TEncTop::m_iSPSIdCnt = 0; |
---|
| 49 | Int TEncTop::m_iPPSIdCnt = 0; |
---|
| 50 | TComVPS TEncCfg::m_cVPS; |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | // Constructor / destructor / create / destroy |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | |
---|
| 57 | TEncTop::TEncTop() |
---|
| 58 | { |
---|
| 59 | m_iPOCLast = -1; |
---|
| 60 | m_iNumPicRcvd = 0; |
---|
| 61 | m_uiNumAllPicCoded = 0; |
---|
| 62 | m_pppcRDSbacCoder = NULL; |
---|
| 63 | m_pppcBinCoderCABAC = NULL; |
---|
| 64 | m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC ); |
---|
| 65 | #if ENC_DEC_TRACE |
---|
| 66 | g_hTrace = fopen( "TraceEnc.txt", "wb" ); |
---|
| 67 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 68 | g_nSymbolCounter = 0; |
---|
| 69 | #endif |
---|
| 70 | |
---|
| 71 | m_iMaxRefPicNum = 0; |
---|
| 72 | |
---|
| 73 | #if FAST_BIT_EST |
---|
| 74 | ContextModel::buildNextStateTable(); |
---|
| 75 | #endif |
---|
| 76 | |
---|
| 77 | m_pcSbacCoders = NULL; |
---|
| 78 | m_pcBinCoderCABACs = NULL; |
---|
| 79 | m_ppppcRDSbacCoders = NULL; |
---|
| 80 | m_ppppcBinCodersCABAC = NULL; |
---|
| 81 | m_pcRDGoOnSbacCoders = NULL; |
---|
| 82 | m_pcRDGoOnBinCodersCABAC = NULL; |
---|
| 83 | m_pcBitCounters = NULL; |
---|
| 84 | m_pcRdCosts = NULL; |
---|
[442] | 85 | #if SVC_EXTENSION |
---|
[313] | 86 | memset(m_cIlpPic, 0, sizeof(m_cIlpPic)); |
---|
| 87 | #if REF_IDX_MFM |
---|
| 88 | m_bMFMEnabledFlag = false; |
---|
| 89 | #endif |
---|
| 90 | m_numScaledRefLayerOffsets = 0; |
---|
[815] | 91 | #if POC_RESET_FLAG || POC_RESET_IDC_ENCODER |
---|
[442] | 92 | m_pocAdjustmentValue = 0; |
---|
| 93 | #endif |
---|
[540] | 94 | #if NO_CLRAS_OUTPUT_FLAG |
---|
| 95 | m_noClrasOutputFlag = false; |
---|
| 96 | m_layerInitializedFlag = false; |
---|
| 97 | m_firstPicInLayerDecodedFlag = false; |
---|
| 98 | m_noOutputOfPriorPicsFlags = false; |
---|
| 99 | #endif |
---|
[494] | 100 | #endif //SVC_EXTENSION |
---|
[313] | 101 | } |
---|
| 102 | |
---|
| 103 | TEncTop::~TEncTop() |
---|
| 104 | { |
---|
| 105 | #if ENC_DEC_TRACE |
---|
| 106 | fclose( g_hTrace ); |
---|
| 107 | #endif |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | Void TEncTop::create () |
---|
| 111 | { |
---|
| 112 | #if !SVC_EXTENSION |
---|
| 113 | // initialize global variables |
---|
| 114 | initROM(); |
---|
| 115 | #endif |
---|
[442] | 116 | |
---|
[313] | 117 | // create processing unit classes |
---|
| 118 | #if SVC_EXTENSION |
---|
| 119 | m_cGOPEncoder. create( m_layerId ); |
---|
| 120 | #else |
---|
| 121 | m_cGOPEncoder. create(); |
---|
| 122 | #endif |
---|
[494] | 123 | #if AUXILIARY_PICTURES |
---|
| 124 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 125 | #else |
---|
[313] | 126 | m_cSliceEncoder. create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
[494] | 127 | #endif |
---|
[313] | 128 | m_cCuEncoder. create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 129 | if (m_bUseSAO) |
---|
| 130 | { |
---|
[540] | 131 | #if AUXILIARY_PICTURES |
---|
| 132 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 133 | #else |
---|
| 134 | m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 135 | #endif |
---|
| 136 | #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK |
---|
| 137 | m_cEncSAO.createEncData(getSaoLcuBoundary()); |
---|
| 138 | #else |
---|
| 139 | m_cEncSAO.createEncData(); |
---|
| 140 | #endif |
---|
[313] | 141 | } |
---|
| 142 | #if ADAPTIVE_QP_SELECTION |
---|
| 143 | if (m_bUseAdaptQpSelect) |
---|
| 144 | { |
---|
| 145 | m_cTrQuant.initSliceQpDelta(); |
---|
| 146 | } |
---|
| 147 | #endif |
---|
| 148 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 149 | |
---|
| 150 | if ( m_RCEnableRateControl ) |
---|
| 151 | { |
---|
| 152 | m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight, |
---|
| 153 | g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); |
---|
| 154 | } |
---|
[595] | 155 | |
---|
| 156 | m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
[313] | 157 | #if FAST_BIT_EST |
---|
[595] | 158 | m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1]; |
---|
[313] | 159 | #else |
---|
[595] | 160 | m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
[313] | 161 | #endif |
---|
[595] | 162 | |
---|
| 163 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
| 164 | { |
---|
| 165 | m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; |
---|
[313] | 166 | #if FAST_BIT_EST |
---|
[595] | 167 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; |
---|
[313] | 168 | #else |
---|
[595] | 169 | m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; |
---|
[313] | 170 | #endif |
---|
[595] | 171 | |
---|
| 172 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
| 173 | { |
---|
| 174 | m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; |
---|
[313] | 175 | #if FAST_BIT_EST |
---|
[595] | 176 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; |
---|
[313] | 177 | #else |
---|
[595] | 178 | m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; |
---|
[313] | 179 | #endif |
---|
[595] | 180 | m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); |
---|
[313] | 181 | } |
---|
| 182 | } |
---|
[494] | 183 | |
---|
| 184 | #if LAYER_CTB |
---|
| 185 | memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) ); |
---|
| 186 | memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) ); |
---|
| 187 | memcpy(g_auiLayerRasterToPelX[m_layerId], g_auiRasterToPelX, sizeof( g_auiRasterToPelX ) ); |
---|
| 188 | memcpy(g_auiLayerRasterToPelY[m_layerId], g_auiRasterToPelY, sizeof( g_auiRasterToPelY ) ); |
---|
| 189 | #endif |
---|
[313] | 190 | } |
---|
| 191 | |
---|
| 192 | /** |
---|
| 193 | - Allocate coders required for wavefront for the nominated number of substreams. |
---|
| 194 | . |
---|
| 195 | \param iNumSubstreams Determines how much information to allocate. |
---|
| 196 | */ |
---|
| 197 | Void TEncTop::createWPPCoders(Int iNumSubstreams) |
---|
| 198 | { |
---|
| 199 | if (m_pcSbacCoders != NULL) |
---|
| 200 | { |
---|
| 201 | return; // already generated. |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | m_iNumSubstreams = iNumSubstreams; |
---|
| 205 | m_pcSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
| 206 | m_pcBinCoderCABACs = new TEncBinCABAC [iNumSubstreams]; |
---|
| 207 | m_pcRDGoOnSbacCoders = new TEncSbac [iNumSubstreams]; |
---|
| 208 | m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC [iNumSubstreams]; |
---|
| 209 | m_pcBitCounters = new TComBitCounter [iNumSubstreams]; |
---|
| 210 | m_pcRdCosts = new TComRdCost [iNumSubstreams]; |
---|
| 211 | |
---|
| 212 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
| 213 | { |
---|
| 214 | m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] ); |
---|
| 215 | m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); |
---|
| 216 | } |
---|
[595] | 217 | |
---|
| 218 | m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; |
---|
| 219 | m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; |
---|
| 220 | for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) |
---|
[313] | 221 | { |
---|
[595] | 222 | m_ppppcRDSbacCoders[ui] = new TEncSbac** [g_uiMaxCUDepth+1]; |
---|
| 223 | m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1]; |
---|
| 224 | |
---|
| 225 | for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
[313] | 226 | { |
---|
[595] | 227 | m_ppppcRDSbacCoders[ui][iDepth] = new TEncSbac* [CI_NUM]; |
---|
| 228 | m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM]; |
---|
| 229 | |
---|
| 230 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
[313] | 231 | { |
---|
[595] | 232 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx] = new TEncSbac; |
---|
| 233 | m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC; |
---|
| 234 | m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] ); |
---|
[313] | 235 | } |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | Void TEncTop::destroy () |
---|
| 241 | { |
---|
| 242 | // destroy processing unit classes |
---|
| 243 | m_cGOPEncoder. destroy(); |
---|
| 244 | m_cSliceEncoder. destroy(); |
---|
| 245 | m_cCuEncoder. destroy(); |
---|
| 246 | if (m_cSPS.getUseSAO()) |
---|
| 247 | { |
---|
[540] | 248 | m_cEncSAO.destroyEncData(); |
---|
[313] | 249 | m_cEncSAO.destroy(); |
---|
| 250 | } |
---|
| 251 | m_cLoopFilter. destroy(); |
---|
| 252 | m_cRateCtrl. destroy(); |
---|
[595] | 253 | |
---|
| 254 | Int iDepth; |
---|
| 255 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
[313] | 256 | { |
---|
[595] | 257 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
| 258 | { |
---|
| 259 | delete m_pppcRDSbacCoder[iDepth][iCIIdx]; |
---|
| 260 | delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
| 265 | { |
---|
| 266 | delete [] m_pppcRDSbacCoder[iDepth]; |
---|
| 267 | delete [] m_pppcBinCoderCABAC[iDepth]; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | delete [] m_pppcRDSbacCoder; |
---|
| 271 | delete [] m_pppcBinCoderCABAC; |
---|
| 272 | |
---|
| 273 | for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ ) |
---|
| 274 | { |
---|
[313] | 275 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
| 276 | { |
---|
| 277 | for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) |
---|
| 278 | { |
---|
[595] | 279 | delete m_ppppcRDSbacCoders [ui][iDepth][iCIIdx]; |
---|
| 280 | delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx]; |
---|
[313] | 281 | } |
---|
| 282 | } |
---|
[595] | 283 | |
---|
[313] | 284 | for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) |
---|
| 285 | { |
---|
[595] | 286 | delete [] m_ppppcRDSbacCoders [ui][iDepth]; |
---|
| 287 | delete [] m_ppppcBinCodersCABAC[ui][iDepth]; |
---|
[313] | 288 | } |
---|
[595] | 289 | delete[] m_ppppcRDSbacCoders [ui]; |
---|
| 290 | delete[] m_ppppcBinCodersCABAC[ui]; |
---|
[313] | 291 | } |
---|
[595] | 292 | delete[] m_ppppcRDSbacCoders; |
---|
| 293 | delete[] m_ppppcBinCodersCABAC; |
---|
[313] | 294 | delete[] m_pcSbacCoders; |
---|
| 295 | delete[] m_pcBinCoderCABACs; |
---|
| 296 | delete[] m_pcRDGoOnSbacCoders; |
---|
| 297 | delete[] m_pcRDGoOnBinCodersCABAC; |
---|
| 298 | delete[] m_pcBitCounters; |
---|
| 299 | delete[] m_pcRdCosts; |
---|
| 300 | |
---|
[442] | 301 | #if SVC_EXTENSION |
---|
[313] | 302 | for(Int i=0; i<MAX_NUM_REF; i++) |
---|
| 303 | { |
---|
| 304 | if(m_cIlpPic[i]) |
---|
| 305 | { |
---|
| 306 | m_cIlpPic[i]->destroy(); |
---|
| 307 | delete m_cIlpPic[i]; |
---|
| 308 | m_cIlpPic[i] = NULL; |
---|
| 309 | } |
---|
[442] | 310 | } |
---|
| 311 | #else |
---|
| 312 | // destroy ROM |
---|
| 313 | destroyROM(); |
---|
[313] | 314 | #endif |
---|
| 315 | return; |
---|
| 316 | } |
---|
| 317 | |
---|
[442] | 318 | Void TEncTop::init(Bool isFieldCoding) |
---|
[313] | 319 | { |
---|
| 320 | // initialize SPS |
---|
| 321 | xInitSPS(); |
---|
| 322 | |
---|
| 323 | /* set the VPS profile information */ |
---|
| 324 | *m_cVPS.getPTL() = *m_cSPS.getPTL(); |
---|
| 325 | m_cVPS.getTimingInfo()->setTimingInfoPresentFlag ( false ); |
---|
| 326 | // initialize PPS |
---|
| 327 | m_cPPS.setSPS(&m_cSPS); |
---|
| 328 | xInitPPS(); |
---|
[442] | 329 | xInitRPS(isFieldCoding); |
---|
[313] | 330 | |
---|
| 331 | xInitPPSforTiles(); |
---|
| 332 | |
---|
| 333 | // initialize processing unit classes |
---|
| 334 | m_cGOPEncoder. init( this ); |
---|
| 335 | m_cSliceEncoder.init( this ); |
---|
| 336 | m_cCuEncoder. init( this ); |
---|
| 337 | |
---|
| 338 | // initialize transform & quantization class |
---|
| 339 | m_pcCavlcCoder = getCavlcCoder(); |
---|
| 340 | |
---|
| 341 | m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize, |
---|
| 342 | m_useRDOQ, |
---|
| 343 | m_useRDOQTS, |
---|
| 344 | true |
---|
| 345 | ,m_useTransformSkipFast |
---|
| 346 | #if ADAPTIVE_QP_SELECTION |
---|
| 347 | , m_bUseAdaptQpSelect |
---|
| 348 | #endif |
---|
| 349 | ); |
---|
| 350 | |
---|
| 351 | // initialize encoder search class |
---|
| 352 | m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() ); |
---|
| 353 | |
---|
| 354 | m_iMaxRefPicNum = 0; |
---|
| 355 | #if SVC_EXTENSION |
---|
| 356 | m_iSPSIdCnt ++; |
---|
| 357 | m_iPPSIdCnt ++; |
---|
| 358 | xInitILRP(); |
---|
| 359 | #endif |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | // ==================================================================================================================== |
---|
| 363 | // Public member functions |
---|
| 364 | // ==================================================================================================================== |
---|
| 365 | |
---|
| 366 | Void TEncTop::deletePicBuffer() |
---|
| 367 | { |
---|
| 368 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 369 | Int iSize = Int( m_cListPic.size() ); |
---|
| 370 | |
---|
| 371 | for ( Int i = 0; i < iSize; i++ ) |
---|
| 372 | { |
---|
| 373 | TComPic* pcPic = *(iterPic++); |
---|
| 374 | |
---|
| 375 | pcPic->destroy(); |
---|
| 376 | delete pcPic; |
---|
| 377 | pcPic = NULL; |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | /** |
---|
| 382 | - Application has picture buffer list with size of GOP + 1 |
---|
| 383 | - Picture buffer list acts like as ring buffer |
---|
| 384 | - End of the list has the latest picture |
---|
| 385 | . |
---|
| 386 | \param flush cause encoder to encode a partial GOP |
---|
| 387 | \param pcPicYuvOrg original YUV picture |
---|
| 388 | \retval rcListPicYuvRecOut list of reconstruction YUV pictures |
---|
| 389 | \retval rcListBitstreamOut list of output bitstreams |
---|
| 390 | \retval iNumEncoded number of encoded pictures |
---|
| 391 | */ |
---|
| 392 | #if SVC_EXTENSION |
---|
| 393 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP ) |
---|
| 394 | { |
---|
| 395 | // compress GOP |
---|
| 396 | #if !RC_SHVC_HARMONIZATION |
---|
| 397 | if ( m_RCEnableRateControl ) |
---|
| 398 | { |
---|
| 399 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
| 400 | } |
---|
| 401 | #endif |
---|
| 402 | |
---|
| 403 | // compress GOP |
---|
[442] | 404 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false); |
---|
[313] | 405 | |
---|
| 406 | #if !RC_SHVC_HARMONIZATION |
---|
| 407 | if ( m_RCEnableRateControl ) |
---|
| 408 | { |
---|
| 409 | m_cRateCtrl.destroyRCGOP(); |
---|
| 410 | } |
---|
| 411 | #endif |
---|
| 412 | |
---|
| 413 | m_uiNumAllPicCoded ++; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg ) |
---|
| 417 | { |
---|
| 418 | if (pcPicYuvOrg) |
---|
| 419 | { |
---|
| 420 | // get original YUV |
---|
| 421 | TComPic* pcPicCurr = NULL; |
---|
| 422 | xGetNewPicBuffer( pcPicCurr ); |
---|
| 423 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
| 424 | |
---|
| 425 | // compute image characteristics |
---|
| 426 | if ( getUseAdaptiveQP() ) |
---|
| 427 | { |
---|
| 428 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | #else |
---|
| 433 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ) |
---|
| 434 | { |
---|
| 435 | if (pcPicYuvOrg) { |
---|
| 436 | // get original YUV |
---|
| 437 | TComPic* pcPicCurr = NULL; |
---|
| 438 | xGetNewPicBuffer( pcPicCurr ); |
---|
| 439 | pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() ); |
---|
| 440 | |
---|
| 441 | // compute image characteristics |
---|
| 442 | if ( getUseAdaptiveQP() ) |
---|
| 443 | { |
---|
| 444 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) ); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) |
---|
| 449 | { |
---|
| 450 | iNumEncoded = 0; |
---|
| 451 | return; |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | if ( m_RCEnableRateControl ) |
---|
| 455 | { |
---|
| 456 | m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | // compress GOP |
---|
| 460 | |
---|
[442] | 461 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false); |
---|
| 462 | |
---|
[313] | 463 | if ( m_RCEnableRateControl ) |
---|
| 464 | { |
---|
| 465 | m_cRateCtrl.destroyRCGOP(); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | iNumEncoded = m_iNumPicRcvd; |
---|
| 469 | m_iNumPicRcvd = 0; |
---|
| 470 | m_uiNumAllPicCoded += iNumEncoded; |
---|
| 471 | } |
---|
| 472 | #endif |
---|
| 473 | |
---|
[442] | 474 | /**------------------------------------------------ |
---|
| 475 | Separate interlaced frame into two fields |
---|
| 476 | -------------------------------------------------**/ |
---|
| 477 | void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop) |
---|
| 478 | { |
---|
| 479 | if (!isTop) |
---|
| 480 | { |
---|
| 481 | org += stride; |
---|
| 482 | } |
---|
| 483 | for (Int y = 0; y < height>>1; y++) |
---|
| 484 | { |
---|
| 485 | for (Int x = 0; x < width; x++) |
---|
| 486 | { |
---|
| 487 | dstField[x] = org[x]; |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | dstField += stride; |
---|
| 491 | org += stride*2; |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | #if SVC_EXTENSION |
---|
| 497 | Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff ) |
---|
| 498 | { |
---|
| 499 | if (pcPicYuvOrg) |
---|
| 500 | { |
---|
| 501 | /* -- TOP FIELD -- */ |
---|
| 502 | /* -- Top field initialization -- */ |
---|
| 503 | |
---|
| 504 | TComPic *pcTopField; |
---|
| 505 | xGetNewPicBuffer( pcTopField ); |
---|
| 506 | pcTopField->setReconMark (false); |
---|
| 507 | |
---|
| 508 | pcTopField->getSlice(0)->setPOC( m_iPOCLast ); |
---|
| 509 | pcTopField->getPicYuvRec()->setBorderExtension(false); |
---|
| 510 | pcTopField->setTopField(isTff); |
---|
| 511 | |
---|
| 512 | Int nHeight = pcPicYuvOrg->getHeight(); |
---|
| 513 | Int nWidth = pcPicYuvOrg->getWidth(); |
---|
| 514 | Int nStride = pcPicYuvOrg->getStride(); |
---|
| 515 | Int nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
| 516 | Int nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
| 517 | |
---|
| 518 | // Get pointers |
---|
| 519 | Pel * PicBufY = pcPicYuvOrg->getBufY(); |
---|
| 520 | Pel * PicBufU = pcPicYuvOrg->getBufU(); |
---|
| 521 | Pel * PicBufV = pcPicYuvOrg->getBufV(); |
---|
| 522 | |
---|
| 523 | Pel * pcTopFieldY = pcTopField->getPicYuvOrg()->getLumaAddr(); |
---|
| 524 | Pel * pcTopFieldU = pcTopField->getPicYuvOrg()->getCbAddr(); |
---|
| 525 | Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); |
---|
[540] | 526 | |
---|
[442] | 527 | // compute image characteristics |
---|
| 528 | if ( getUseAdaptiveQP() ) |
---|
| 529 | { |
---|
| 530 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); |
---|
[540] | 531 | } |
---|
| 532 | |
---|
[442] | 533 | /* -- Defield -- */ |
---|
| 534 | |
---|
| 535 | Bool isTop = isTff; |
---|
| 536 | |
---|
| 537 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop); |
---|
| 538 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 539 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 540 | |
---|
| 541 | /* -- BOTTOM FIELD -- */ |
---|
| 542 | /* -- Bottom field initialization -- */ |
---|
| 543 | |
---|
| 544 | TComPic* pcBottomField; |
---|
| 545 | xGetNewPicBuffer( pcBottomField ); |
---|
| 546 | pcBottomField->setReconMark (false); |
---|
| 547 | |
---|
| 548 | pcBottomField->getSlice(0)->setPOC( m_iPOCLast); |
---|
| 549 | pcBottomField->getPicYuvRec()->setBorderExtension(false); |
---|
| 550 | pcBottomField->setTopField(!isTff); |
---|
| 551 | |
---|
| 552 | nHeight = pcPicYuvOrg->getHeight(); |
---|
| 553 | nWidth = pcPicYuvOrg->getWidth(); |
---|
| 554 | nStride = pcPicYuvOrg->getStride(); |
---|
| 555 | nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
| 556 | nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
| 557 | |
---|
| 558 | // Get pointers |
---|
| 559 | PicBufY = pcPicYuvOrg->getBufY(); |
---|
| 560 | PicBufU = pcPicYuvOrg->getBufU(); |
---|
| 561 | PicBufV = pcPicYuvOrg->getBufV(); |
---|
| 562 | |
---|
| 563 | Pel * pcBottomFieldY = pcBottomField->getPicYuvOrg()->getLumaAddr(); |
---|
| 564 | Pel * pcBottomFieldU = pcBottomField->getPicYuvOrg()->getCbAddr(); |
---|
| 565 | Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); |
---|
[540] | 566 | |
---|
| 567 | // compute image characteristics |
---|
[442] | 568 | if ( getUseAdaptiveQP() ) |
---|
| 569 | { |
---|
| 570 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); |
---|
[540] | 571 | } |
---|
| 572 | |
---|
[442] | 573 | /* -- Defield -- */ |
---|
| 574 | |
---|
| 575 | isTop = !isTff; |
---|
| 576 | |
---|
| 577 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop); |
---|
| 578 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 579 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 580 | |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff ) |
---|
| 585 | { |
---|
| 586 | // compress GOP |
---|
| 587 | if (m_iPOCLast == 0) // compress field 0 |
---|
| 588 | { |
---|
| 589 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | if (pcPicYuvOrg) |
---|
| 593 | { |
---|
| 594 | TComPicYuv* rpcPicYuvRec = new TComPicYuv; |
---|
| 595 | if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) |
---|
| 596 | { |
---|
| 597 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
| 598 | } |
---|
| 599 | else |
---|
| 600 | { |
---|
[494] | 601 | #if AUXILIARY_PICTURES |
---|
| 602 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 603 | #else |
---|
[442] | 604 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
[494] | 605 | #endif |
---|
[442] | 606 | } |
---|
| 607 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | // compress GOP |
---|
| 611 | m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
| 612 | |
---|
| 613 | m_uiNumAllPicCoded ++; |
---|
| 614 | } |
---|
| 615 | #else |
---|
| 616 | Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff) |
---|
| 617 | { |
---|
| 618 | /* -- TOP FIELD -- */ |
---|
| 619 | |
---|
| 620 | if (pcPicYuvOrg) |
---|
| 621 | { |
---|
| 622 | |
---|
| 623 | /* -- Top field initialization -- */ |
---|
| 624 | |
---|
| 625 | TComPic *pcTopField; |
---|
| 626 | xGetNewPicBuffer( pcTopField ); |
---|
| 627 | pcTopField->setReconMark (false); |
---|
| 628 | |
---|
| 629 | pcTopField->getSlice(0)->setPOC( m_iPOCLast ); |
---|
| 630 | pcTopField->getPicYuvRec()->setBorderExtension(false); |
---|
| 631 | pcTopField->setTopField(isTff); |
---|
| 632 | |
---|
| 633 | Int nHeight = pcPicYuvOrg->getHeight(); |
---|
| 634 | Int nWidth = pcPicYuvOrg->getWidth(); |
---|
| 635 | Int nStride = pcPicYuvOrg->getStride(); |
---|
| 636 | Int nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
| 637 | Int nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
| 638 | |
---|
| 639 | // Get pointers |
---|
| 640 | Pel * PicBufY = pcPicYuvOrg->getBufY(); |
---|
| 641 | Pel * PicBufU = pcPicYuvOrg->getBufU(); |
---|
| 642 | Pel * PicBufV = pcPicYuvOrg->getBufV(); |
---|
| 643 | |
---|
| 644 | Pel * pcTopFieldY = pcTopField->getPicYuvOrg()->getLumaAddr(); |
---|
| 645 | Pel * pcTopFieldU = pcTopField->getPicYuvOrg()->getCbAddr(); |
---|
| 646 | Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); |
---|
| 647 | |
---|
| 648 | // compute image characteristics |
---|
| 649 | if ( getUseAdaptiveQP() ) |
---|
| 650 | { |
---|
| 651 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | /* -- Defield -- */ |
---|
| 655 | |
---|
| 656 | Bool isTop = isTff; |
---|
| 657 | |
---|
| 658 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop); |
---|
| 659 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 660 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 661 | |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | if (m_iPOCLast == 0) // compress field 0 |
---|
| 665 | { |
---|
| 666 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | /* -- BOTTOM FIELD -- */ |
---|
| 670 | |
---|
| 671 | if (pcPicYuvOrg) |
---|
| 672 | { |
---|
| 673 | |
---|
| 674 | /* -- Bottom field initialization -- */ |
---|
| 675 | |
---|
| 676 | TComPic* pcBottomField; |
---|
| 677 | xGetNewPicBuffer( pcBottomField ); |
---|
| 678 | pcBottomField->setReconMark (false); |
---|
| 679 | |
---|
[540] | 680 | TComPicYuv* rpcPicYuvRec; |
---|
[442] | 681 | if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) |
---|
| 682 | { |
---|
| 683 | rpcPicYuvRec = rcListPicYuvRecOut.popFront(); |
---|
| 684 | } |
---|
| 685 | else |
---|
| 686 | { |
---|
[540] | 687 | rpcPicYuvRec = new TComPicYuv; |
---|
[442] | 688 | rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 689 | } |
---|
| 690 | rcListPicYuvRecOut.pushBack( rpcPicYuvRec ); |
---|
| 691 | |
---|
| 692 | pcBottomField->getSlice(0)->setPOC( m_iPOCLast); |
---|
| 693 | pcBottomField->getPicYuvRec()->setBorderExtension(false); |
---|
| 694 | pcBottomField->setTopField(!isTff); |
---|
| 695 | |
---|
| 696 | int nHeight = pcPicYuvOrg->getHeight(); |
---|
| 697 | int nWidth = pcPicYuvOrg->getWidth(); |
---|
| 698 | int nStride = pcPicYuvOrg->getStride(); |
---|
| 699 | int nPadLuma = pcPicYuvOrg->getLumaMargin(); |
---|
| 700 | int nPadChroma = pcPicYuvOrg->getChromaMargin(); |
---|
| 701 | |
---|
| 702 | // Get pointers |
---|
| 703 | Pel * PicBufY = pcPicYuvOrg->getBufY(); |
---|
| 704 | Pel * PicBufU = pcPicYuvOrg->getBufU(); |
---|
| 705 | Pel * PicBufV = pcPicYuvOrg->getBufV(); |
---|
| 706 | |
---|
| 707 | Pel * pcBottomFieldY = pcBottomField->getPicYuvOrg()->getLumaAddr(); |
---|
| 708 | Pel * pcBottomFieldU = pcBottomField->getPicYuvOrg()->getCbAddr(); |
---|
| 709 | Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); |
---|
| 710 | |
---|
| 711 | // Compute image characteristics |
---|
| 712 | if ( getUseAdaptiveQP() ) |
---|
| 713 | { |
---|
| 714 | m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | /* -- Defield -- */ |
---|
| 718 | |
---|
| 719 | Bool isTop = !isTff; |
---|
| 720 | |
---|
| 721 | separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop); |
---|
| 722 | separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 723 | separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); |
---|
| 724 | |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) ) |
---|
| 728 | { |
---|
| 729 | iNumEncoded = 0; |
---|
| 730 | return; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | // compress GOP |
---|
| 734 | m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); |
---|
| 735 | |
---|
| 736 | iNumEncoded = m_iNumPicRcvd; |
---|
| 737 | m_iNumPicRcvd = 0; |
---|
| 738 | m_uiNumAllPicCoded += iNumEncoded; |
---|
| 739 | } |
---|
| 740 | #endif |
---|
| 741 | |
---|
[313] | 742 | // ==================================================================================================================== |
---|
| 743 | // Protected member functions |
---|
| 744 | // ==================================================================================================================== |
---|
| 745 | |
---|
| 746 | /** |
---|
| 747 | - Application has picture buffer list with size of GOP + 1 |
---|
| 748 | - Picture buffer list acts like as ring buffer |
---|
| 749 | - End of the list has the latest picture |
---|
| 750 | . |
---|
| 751 | \retval rpcPic obtained picture buffer |
---|
| 752 | */ |
---|
| 753 | Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic ) |
---|
| 754 | { |
---|
| 755 | TComSlice::sortPicList(m_cListPic); |
---|
| 756 | |
---|
| 757 | if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) ) |
---|
| 758 | { |
---|
| 759 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 760 | Int iSize = Int( m_cListPic.size() ); |
---|
| 761 | for ( Int i = 0; i < iSize; i++ ) |
---|
| 762 | { |
---|
| 763 | rpcPic = *(iterPic++); |
---|
| 764 | if(rpcPic->getSlice(0)->isReferenced() == false) |
---|
| 765 | { |
---|
| 766 | break; |
---|
| 767 | } |
---|
| 768 | } |
---|
| 769 | } |
---|
| 770 | else |
---|
| 771 | { |
---|
| 772 | if ( getUseAdaptiveQP() ) |
---|
| 773 | { |
---|
| 774 | TEncPic* pcEPic = new TEncPic; |
---|
| 775 | |
---|
| 776 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
| 777 | if(m_layerId > 0) |
---|
| 778 | { |
---|
| 779 | for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
| 780 | { |
---|
[540] | 781 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 782 | const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
| 783 | #else |
---|
[313] | 784 | const Window scalEL = getSPS()->getScaledRefLayerWindow(i); |
---|
[540] | 785 | #endif |
---|
[313] | 786 | Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 ); |
---|
| 787 | |
---|
| 788 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
| 789 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
| 790 | #else |
---|
| 791 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
| 792 | #endif |
---|
[644] | 793 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
| 794 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
| 795 | Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] ); |
---|
| 796 | |
---|
[713] | 797 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths |
---|
| 798 | #if Q0048_CGS_3D_ASYMLUT |
---|
| 799 | || m_cPPS.getCGSFlag() > 0 |
---|
| 800 | #endif |
---|
| 801 | #if LAYER_CTB |
---|
| 802 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
| 803 | #endif |
---|
| 804 | ) |
---|
[644] | 805 | #else |
---|
[313] | 806 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets ) |
---|
[644] | 807 | #endif |
---|
[313] | 808 | { |
---|
| 809 | pcEPic->setSpatialEnhLayerFlag( i, true ); |
---|
| 810 | |
---|
| 811 | //only for scalable extension |
---|
[815] | 812 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
[313] | 813 | } |
---|
| 814 | } |
---|
| 815 | } |
---|
| 816 | #endif |
---|
| 817 | |
---|
[815] | 818 | #if SVC_EXTENSION |
---|
[494] | 819 | #if AUXILIARY_PICTURES |
---|
| 820 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
| 821 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
| 822 | #else |
---|
[313] | 823 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
| 824 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
[815] | 825 | #endif |
---|
| 826 | #else //SVC_EXTENSION |
---|
[313] | 827 | pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 , |
---|
| 828 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
[815] | 829 | #endif //SVC_EXTENSION |
---|
[313] | 830 | rpcPic = pcEPic; |
---|
| 831 | } |
---|
| 832 | else |
---|
| 833 | { |
---|
| 834 | rpcPic = new TComPic; |
---|
| 835 | |
---|
| 836 | #if SVC_EXTENSION //Temporal solution, should be modified |
---|
| 837 | if(m_layerId > 0) |
---|
| 838 | { |
---|
| 839 | for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ ) |
---|
| 840 | { |
---|
[540] | 841 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 842 | const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i)); |
---|
| 843 | #else |
---|
[313] | 844 | const Window scalEL = getSPS()->getScaledRefLayerWindow(i); |
---|
[540] | 845 | #endif |
---|
[313] | 846 | Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 ); |
---|
| 847 | |
---|
| 848 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
| 849 | TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i ); |
---|
| 850 | #else |
---|
| 851 | TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 ); |
---|
| 852 | #endif |
---|
[644] | 853 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
| 854 | UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i); |
---|
| 855 | Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] ); |
---|
| 856 | |
---|
[713] | 857 | if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths |
---|
| 858 | #if Q0048_CGS_3D_ASYMLUT |
---|
| 859 | || m_cPPS.getCGSFlag() > 0 |
---|
| 860 | #endif |
---|
| 861 | #if LAYER_CTB |
---|
| 862 | || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth() |
---|
| 863 | #endif |
---|
| 864 | ) |
---|
[644] | 865 | #else |
---|
[313] | 866 | if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets ) |
---|
[644] | 867 | #endif |
---|
[313] | 868 | { |
---|
| 869 | rpcPic->setSpatialEnhLayerFlag( i, true ); |
---|
| 870 | |
---|
| 871 | //only for scalable extension |
---|
[815] | 872 | assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true ); |
---|
[313] | 873 | } |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | #endif |
---|
| 877 | |
---|
[815] | 878 | #if SVC_EXTENSION |
---|
[494] | 879 | #if AUXILIARY_PICTURES |
---|
| 880 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
| 881 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
| 882 | #else |
---|
[313] | 883 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
| 884 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS); |
---|
[815] | 885 | #endif |
---|
| 886 | #else //SVC_EXTENSION |
---|
[313] | 887 | rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, |
---|
| 888 | m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); |
---|
[815] | 889 | #endif //SVC_EXTENSION |
---|
[313] | 890 | } |
---|
| 891 | m_cListPic.pushBack( rpcPic ); |
---|
| 892 | } |
---|
| 893 | rpcPic->setReconMark (false); |
---|
| 894 | |
---|
| 895 | m_iPOCLast++; |
---|
| 896 | m_iNumPicRcvd++; |
---|
| 897 | |
---|
| 898 | rpcPic->getSlice(0)->setPOC( m_iPOCLast ); |
---|
| 899 | // mark it should be extended |
---|
| 900 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | Void TEncTop::xInitSPS() |
---|
| 904 | { |
---|
| 905 | #if SVC_EXTENSION |
---|
[815] | 906 | m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false ); |
---|
| 907 | |
---|
| 908 | #if Q0078_ADD_LAYER_SETS |
---|
| 909 | if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0) |
---|
| 910 | { |
---|
| 911 | m_cSPS.setLayerId(0); // layer ID 0 for independent layers |
---|
| 912 | } |
---|
| 913 | else |
---|
| 914 | { |
---|
| 915 | m_cSPS.setLayerId(m_layerId); |
---|
| 916 | } |
---|
| 917 | #else |
---|
[313] | 918 | m_cSPS.setLayerId(m_layerId); |
---|
[815] | 919 | #endif |
---|
[313] | 920 | m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets); |
---|
| 921 | for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++) |
---|
| 922 | { |
---|
[540] | 923 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 924 | m_cSPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]); |
---|
| 925 | #endif |
---|
[313] | 926 | m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i]; |
---|
[644] | 927 | #if P0312_VERT_PHASE_ADJ |
---|
| 928 | m_cSPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() ); |
---|
| 929 | #endif |
---|
[313] | 930 | } |
---|
[494] | 931 | #endif //SVC_EXTENSION |
---|
[313] | 932 | ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL(); |
---|
| 933 | profileTierLevel.setLevelIdc(m_level); |
---|
| 934 | profileTierLevel.setTierFlag(m_levelTier); |
---|
| 935 | profileTierLevel.setProfileIdc(m_profile); |
---|
| 936 | profileTierLevel.setProfileCompatibilityFlag(m_profile, 1); |
---|
| 937 | profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag); |
---|
| 938 | profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag); |
---|
| 939 | profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag); |
---|
| 940 | profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag); |
---|
| 941 | |
---|
| 942 | if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8) |
---|
| 943 | { |
---|
| 944 | /* The above constraint is equal to Profile::MAIN */ |
---|
| 945 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1); |
---|
| 946 | } |
---|
| 947 | if (m_profile == Profile::MAIN) |
---|
| 948 | { |
---|
| 949 | /* A Profile::MAIN10 decoder can always decode Profile::MAIN */ |
---|
| 950 | profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1); |
---|
| 951 | } |
---|
| 952 | /* XXX: should Main be marked as compatible with still picture? */ |
---|
| 953 | /* XXX: may be a good idea to refactor the above into a function |
---|
| 954 | * that chooses the actual compatibility based upon options */ |
---|
| 955 | |
---|
| 956 | m_cSPS.setPicWidthInLumaSamples ( m_iSourceWidth ); |
---|
| 957 | m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight ); |
---|
| 958 | m_cSPS.setConformanceWindow ( m_conformanceWindow ); |
---|
| 959 | m_cSPS.setMaxCUWidth ( g_uiMaxCUWidth ); |
---|
| 960 | m_cSPS.setMaxCUHeight ( g_uiMaxCUHeight ); |
---|
| 961 | m_cSPS.setMaxCUDepth ( g_uiMaxCUDepth ); |
---|
[494] | 962 | #if AUXILIARY_PICTURES |
---|
| 963 | m_cSPS.setChromaFormatIdc( m_chromaFormatIDC); |
---|
| 964 | #endif |
---|
[313] | 965 | |
---|
| 966 | Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth ); |
---|
| 967 | Int log2MinCUSize = 0; |
---|
| 968 | while(minCUSize > 1) |
---|
| 969 | { |
---|
| 970 | minCUSize >>= 1; |
---|
| 971 | log2MinCUSize++; |
---|
| 972 | } |
---|
| 973 | |
---|
| 974 | m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize); |
---|
| 975 | m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth); |
---|
| 976 | #if SVC_EXTENSION |
---|
| 977 | m_cSPS.setSPSId ( m_iSPSIdCnt ); |
---|
| 978 | #endif |
---|
| 979 | |
---|
| 980 | m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize); |
---|
| 981 | m_cSPS.setUsePCM ( m_usePCM ); |
---|
| 982 | m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize ); |
---|
| 983 | |
---|
| 984 | m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize ); |
---|
| 985 | m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize ); |
---|
| 986 | m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter ); |
---|
| 987 | m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra ); |
---|
| 988 | |
---|
| 989 | m_cSPS.setTMVPFlagsPresent(false); |
---|
| 990 | |
---|
| 991 | m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); |
---|
| 992 | |
---|
| 993 | Int i; |
---|
| 994 | |
---|
| 995 | for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ ) |
---|
| 996 | { |
---|
| 997 | m_cSPS.setAMPAcc( i, m_useAMP ); |
---|
| 998 | //m_cSPS.setAMPAcc( i, 1 ); |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | m_cSPS.setUseAMP ( m_useAMP ); |
---|
| 1002 | |
---|
| 1003 | for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ ) |
---|
| 1004 | { |
---|
| 1005 | m_cSPS.setAMPAcc(i, 0); |
---|
| 1006 | } |
---|
| 1007 | |
---|
[442] | 1008 | #if REPN_FORMAT_IN_VPS |
---|
| 1009 | m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() ); |
---|
| 1010 | m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma() ); |
---|
| 1011 | |
---|
| 1012 | m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) ); |
---|
| 1013 | m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma() - 8) ); |
---|
| 1014 | #else |
---|
[313] | 1015 | m_cSPS.setBitDepthY( g_bitDepthY ); |
---|
| 1016 | m_cSPS.setBitDepthC( g_bitDepthC ); |
---|
| 1017 | |
---|
| 1018 | m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) ); |
---|
| 1019 | m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) ); |
---|
[442] | 1020 | #endif |
---|
[313] | 1021 | |
---|
| 1022 | m_cSPS.setUseSAO( m_bUseSAO ); |
---|
| 1023 | |
---|
| 1024 | m_cSPS.setMaxTLayers( m_maxTempLayer ); |
---|
| 1025 | m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); |
---|
[595] | 1026 | for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) |
---|
[313] | 1027 | { |
---|
| 1028 | m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); |
---|
| 1029 | m_cSPS.setNumReorderPics(m_numReorderPics[i], i); |
---|
| 1030 | } |
---|
| 1031 | m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma); |
---|
| 1032 | m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma); |
---|
| 1033 | m_cSPS.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag ); |
---|
| 1034 | |
---|
| 1035 | m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 ); |
---|
| 1036 | |
---|
| 1037 | m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing ); |
---|
| 1038 | |
---|
| 1039 | m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag()); |
---|
| 1040 | if (m_cSPS.getVuiParametersPresentFlag()) |
---|
| 1041 | { |
---|
| 1042 | TComVUI* pcVUI = m_cSPS.getVuiParameters(); |
---|
| 1043 | pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1); |
---|
| 1044 | pcVUI->setAspectRatioIdc(getAspectRatioIdc()); |
---|
| 1045 | pcVUI->setSarWidth(getSarWidth()); |
---|
| 1046 | pcVUI->setSarHeight(getSarHeight()); |
---|
| 1047 | pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag()); |
---|
| 1048 | pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag()); |
---|
| 1049 | pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag()); |
---|
| 1050 | pcVUI->setVideoFormat(getVideoFormat()); |
---|
| 1051 | pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag()); |
---|
| 1052 | pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag()); |
---|
| 1053 | pcVUI->setColourPrimaries(getColourPrimaries()); |
---|
| 1054 | pcVUI->setTransferCharacteristics(getTransferCharacteristics()); |
---|
| 1055 | pcVUI->setMatrixCoefficients(getMatrixCoefficients()); |
---|
| 1056 | pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag()); |
---|
| 1057 | pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField()); |
---|
| 1058 | pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField()); |
---|
| 1059 | pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag()); |
---|
| 1060 | pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow()); |
---|
| 1061 | pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag()); |
---|
| 1062 | pcVUI->setFieldSeqFlag(false); |
---|
| 1063 | pcVUI->setHrdParametersPresentFlag(false); |
---|
| 1064 | pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag()); |
---|
| 1065 | pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1 (getNumTicksPocDiffOneMinus1() ); |
---|
| 1066 | pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag()); |
---|
| 1067 | pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag()); |
---|
| 1068 | pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag()); |
---|
| 1069 | pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc()); |
---|
| 1070 | pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom()); |
---|
| 1071 | pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom()); |
---|
| 1072 | pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal()); |
---|
| 1073 | pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical()); |
---|
| 1074 | } |
---|
| 1075 | } |
---|
| 1076 | |
---|
| 1077 | Void TEncTop::xInitPPS() |
---|
| 1078 | { |
---|
| 1079 | m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); |
---|
| 1080 | Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; |
---|
| 1081 | |
---|
[595] | 1082 | if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) |
---|
[540] | 1083 | { |
---|
[595] | 1084 | bUseDQP = true; |
---|
[540] | 1085 | } |
---|
[313] | 1086 | |
---|
| 1087 | if(bUseDQP) |
---|
| 1088 | { |
---|
| 1089 | m_cPPS.setUseDQP(true); |
---|
| 1090 | m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth ); |
---|
| 1091 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
| 1092 | } |
---|
| 1093 | else |
---|
| 1094 | { |
---|
| 1095 | m_cPPS.setUseDQP(false); |
---|
| 1096 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
| 1097 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | if ( m_RCEnableRateControl ) |
---|
| 1101 | { |
---|
| 1102 | m_cPPS.setUseDQP(true); |
---|
| 1103 | m_cPPS.setMaxCuDQPDepth( 0 ); |
---|
| 1104 | m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); |
---|
| 1108 | m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset ); |
---|
| 1109 | |
---|
| 1110 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams); |
---|
| 1111 | m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 ); |
---|
| 1112 | m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) ); |
---|
| 1113 | m_cPPS.setUseWP( m_useWeightedPred ); |
---|
| 1114 | m_cPPS.setWPBiPred( m_useWeightedBiPred ); |
---|
| 1115 | m_cPPS.setOutputFlagPresentFlag( false ); |
---|
| 1116 | m_cPPS.setSignHideFlag(getSignHideFlag()); |
---|
| 1117 | if ( getDeblockingFilterMetric() ) |
---|
| 1118 | { |
---|
| 1119 | m_cPPS.setDeblockingFilterControlPresentFlag (true); |
---|
| 1120 | m_cPPS.setDeblockingFilterOverrideEnabledFlag(true); |
---|
| 1121 | m_cPPS.setPicDisableDeblockingFilterFlag(false); |
---|
| 1122 | m_cPPS.setDeblockingFilterBetaOffsetDiv2(0); |
---|
| 1123 | m_cPPS.setDeblockingFilterTcOffsetDiv2(0); |
---|
| 1124 | } |
---|
| 1125 | else |
---|
| 1126 | { |
---|
| 1127 | m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent ); |
---|
| 1128 | } |
---|
| 1129 | m_cPPS.setLog2ParallelMergeLevelMinus2 (m_log2ParallelMergeLevelMinus2 ); |
---|
| 1130 | m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG); |
---|
| 1131 | m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag ); |
---|
| 1132 | Int histogram[MAX_NUM_REF + 1]; |
---|
| 1133 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
| 1134 | { |
---|
| 1135 | histogram[i]=0; |
---|
| 1136 | } |
---|
| 1137 | for( Int i = 0; i < getGOPSize(); i++ ) |
---|
| 1138 | { |
---|
| 1139 | assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF); |
---|
| 1140 | histogram[getGOPEntry(i).m_numRefPicsActive]++; |
---|
| 1141 | } |
---|
| 1142 | Int maxHist=-1; |
---|
| 1143 | Int bestPos=0; |
---|
| 1144 | for( Int i = 0; i <= MAX_NUM_REF; i++ ) |
---|
| 1145 | { |
---|
| 1146 | if(histogram[i]>maxHist) |
---|
| 1147 | { |
---|
| 1148 | maxHist=histogram[i]; |
---|
| 1149 | bestPos=i; |
---|
| 1150 | } |
---|
| 1151 | } |
---|
| 1152 | assert(bestPos <= 15); |
---|
| 1153 | m_cPPS.setNumRefIdxL0DefaultActive(bestPos); |
---|
| 1154 | m_cPPS.setNumRefIdxL1DefaultActive(bestPos); |
---|
| 1155 | m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag()); |
---|
| 1156 | m_cPPS.setUseTransformSkip( m_useTransformSkip ); |
---|
| 1157 | if (m_sliceSegmentMode) |
---|
| 1158 | { |
---|
| 1159 | m_cPPS.setDependentSliceSegmentsEnabledFlag( true ); |
---|
| 1160 | } |
---|
| 1161 | if( m_cPPS.getDependentSliceSegmentsEnabledFlag() ) |
---|
| 1162 | { |
---|
| 1163 | Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1; |
---|
| 1164 | m_cSliceEncoder.initCtxMem( NumCtx ); |
---|
| 1165 | for ( UInt st = 0; st < NumCtx; st++ ) |
---|
| 1166 | { |
---|
| 1167 | TEncSbac* ctx = NULL; |
---|
| 1168 | ctx = new TEncSbac; |
---|
| 1169 | ctx->init( &m_cBinCoderCABAC ); |
---|
| 1170 | m_cSliceEncoder.setCtxMem( ctx, st ); |
---|
| 1171 | } |
---|
| 1172 | } |
---|
[442] | 1173 | #if SVC_EXTENSION |
---|
[815] | 1174 | #if SCALINGLIST_INFERRING |
---|
| 1175 | m_cPPS.setLayerId( m_layerId ); |
---|
| 1176 | #endif |
---|
| 1177 | |
---|
| 1178 | #if Q0078_ADD_LAYER_SETS |
---|
| 1179 | if (getNumDirectRefLayers() == 0 && getNumAddLayerSets() > 0) |
---|
[313] | 1180 | { |
---|
[815] | 1181 | m_cPPS.setLayerId(0); // layer ID 0 for independent layers |
---|
[313] | 1182 | } |
---|
[815] | 1183 | #endif |
---|
| 1184 | |
---|
| 1185 | if( m_layerId > 0 ) |
---|
[313] | 1186 | { |
---|
| 1187 | m_cPPS.setListsModificationPresentFlag(true); |
---|
[815] | 1188 | m_cPPS.setExtensionFlag(true); |
---|
[313] | 1189 | } |
---|
[815] | 1190 | else |
---|
| 1191 | { |
---|
| 1192 | m_cPPS.setListsModificationPresentFlag(false); |
---|
| 1193 | m_cPPS.setExtensionFlag(false); |
---|
| 1194 | } |
---|
[442] | 1195 | |
---|
[815] | 1196 | m_cPPS.setPPSId( m_iPPSIdCnt ); |
---|
| 1197 | m_cPPS.setSPSId( m_iSPSIdCnt ); |
---|
[442] | 1198 | #if POC_RESET_FLAG |
---|
| 1199 | m_cPPS.setNumExtraSliceHeaderBits( 2 ); |
---|
| 1200 | #endif |
---|
[540] | 1201 | #if O0149_CROSS_LAYER_BLA_FLAG |
---|
| 1202 | if (m_crossLayerBLAFlag) |
---|
| 1203 | { |
---|
| 1204 | m_cPPS.setNumExtraSliceHeaderBits( 3 ); |
---|
| 1205 | } |
---|
| 1206 | #endif |
---|
[713] | 1207 | #if Q0048_CGS_3D_ASYMLUT |
---|
| 1208 | m_cPPS.setCGSFlag( m_nCGSFlag ); |
---|
| 1209 | #endif |
---|
[815] | 1210 | #if POC_RESET_IDC_ENCODER |
---|
| 1211 | m_cPPS.setPocResetInfoPresentFlag( true ); |
---|
| 1212 | m_cPPS.setExtensionFlag( true ); |
---|
| 1213 | m_cPPS.setSliceHeaderExtensionPresentFlag( true ); |
---|
| 1214 | #endif |
---|
| 1215 | #endif //SVC_EXTENSION |
---|
[313] | 1216 | } |
---|
| 1217 | |
---|
| 1218 | //Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file. |
---|
[442] | 1219 | Void TEncTop::xInitRPS(Bool isFieldCoding) |
---|
[313] | 1220 | { |
---|
| 1221 | TComReferencePictureSet* rps; |
---|
| 1222 | |
---|
[442] | 1223 | m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1); |
---|
[313] | 1224 | TComRPSList* rpsList = m_cSPS.getRPSList(); |
---|
| 1225 | |
---|
| 1226 | for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) |
---|
| 1227 | { |
---|
| 1228 | GOPEntry ge = getGOPEntry(i); |
---|
| 1229 | rps = rpsList->getReferencePictureSet(i); |
---|
| 1230 | rps->setNumberOfPictures(ge.m_numRefPics); |
---|
| 1231 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
| 1232 | Int numNeg = 0; |
---|
| 1233 | Int numPos = 0; |
---|
| 1234 | for( Int j = 0; j < ge.m_numRefPics; j++) |
---|
| 1235 | { |
---|
| 1236 | rps->setDeltaPOC(j,ge.m_referencePics[j]); |
---|
| 1237 | rps->setUsed(j,ge.m_usedByCurrPic[j]); |
---|
| 1238 | if(ge.m_referencePics[j]>0) |
---|
| 1239 | { |
---|
| 1240 | numPos++; |
---|
| 1241 | } |
---|
| 1242 | else |
---|
| 1243 | { |
---|
| 1244 | numNeg++; |
---|
| 1245 | } |
---|
| 1246 | } |
---|
| 1247 | rps->setNumberOfNegativePictures(numNeg); |
---|
| 1248 | rps->setNumberOfPositivePictures(numPos); |
---|
| 1249 | |
---|
| 1250 | // handle inter RPS intialization from the config file. |
---|
| 1251 | #if AUTO_INTER_RPS |
---|
| 1252 | rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0); // not very clean, converting anything > 0 to true. |
---|
| 1253 | rps->setDeltaRIdxMinus1(0); // index to the Reference RPS is always the previous one. |
---|
| 1254 | TComReferencePictureSet* RPSRef = rpsList->getReferencePictureSet(i-1); // get the reference RPS |
---|
| 1255 | |
---|
| 1256 | if (ge.m_interRPSPrediction == 2) // Automatic generation of the inter RPS idc based on the RIdx provided. |
---|
| 1257 | { |
---|
| 1258 | Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC; // the ref POC - current POC |
---|
| 1259 | Int numRefDeltaPOC = RPSRef->getNumberOfPictures(); |
---|
| 1260 | |
---|
| 1261 | rps->setDeltaRPS(deltaRPS); // set delta RPS |
---|
| 1262 | rps->setNumRefIdc(numRefDeltaPOC+1); // set the numRefIdc to the number of pictures in the reference RPS + 1. |
---|
| 1263 | Int count=0; |
---|
| 1264 | for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS. |
---|
| 1265 | { |
---|
| 1266 | Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0; // if it is the last decoded picture, set RefDeltaPOC = 0 |
---|
| 1267 | rps->setRefIdc(j, 0); |
---|
| 1268 | for (Int k = 0; k < rps->getNumberOfPictures(); k++ ) // cycle through pics in current RPS. |
---|
| 1269 | { |
---|
| 1270 | if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS)) // if the current RPS has a same picture as the reference RPS. |
---|
| 1271 | { |
---|
| 1272 | rps->setRefIdc(j, (rps->getUsed(k)?1:2)); |
---|
| 1273 | count++; |
---|
| 1274 | break; |
---|
| 1275 | } |
---|
| 1276 | } |
---|
| 1277 | } |
---|
| 1278 | if (count != rps->getNumberOfPictures()) |
---|
| 1279 | { |
---|
| 1280 | printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file. Setting Inter RPS to false for this RPS.\n"); |
---|
| 1281 | rps->setInterRPSPrediction(0); |
---|
| 1282 | } |
---|
| 1283 | } |
---|
| 1284 | else if (ge.m_interRPSPrediction == 1) // inter RPS idc based on the RefIdc values provided in config file. |
---|
| 1285 | { |
---|
| 1286 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
| 1287 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
| 1288 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1289 | { |
---|
| 1290 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
| 1291 | } |
---|
| 1292 | #if WRITE_BACK |
---|
| 1293 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
| 1294 | // computed from the RefIdc. A warning is printed if they are not identical. |
---|
| 1295 | numNeg = 0; |
---|
| 1296 | numPos = 0; |
---|
| 1297 | TComReferencePictureSet RPSTemp; // temporary variable |
---|
| 1298 | |
---|
| 1299 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1300 | { |
---|
| 1301 | if (ge.m_refIdc[j]) |
---|
| 1302 | { |
---|
| 1303 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
| 1304 | RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
| 1305 | RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
| 1306 | if (deltaPOC<0) |
---|
| 1307 | { |
---|
| 1308 | numNeg++; |
---|
| 1309 | } |
---|
| 1310 | else |
---|
| 1311 | { |
---|
| 1312 | numPos++; |
---|
| 1313 | } |
---|
| 1314 | } |
---|
| 1315 | } |
---|
| 1316 | if (numNeg != rps->getNumberOfNegativePictures()) |
---|
| 1317 | { |
---|
| 1318 | printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1319 | rps->setNumberOfNegativePictures(numNeg); |
---|
[442] | 1320 | rps->setNumberOfPictures(numNeg+numPos); |
---|
[313] | 1321 | } |
---|
| 1322 | if (numPos != rps->getNumberOfPositivePictures()) |
---|
| 1323 | { |
---|
| 1324 | printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1325 | rps->setNumberOfPositivePictures(numPos); |
---|
[442] | 1326 | rps->setNumberOfPictures(numNeg+numPos); |
---|
[313] | 1327 | } |
---|
| 1328 | RPSTemp.setNumberOfPictures(numNeg+numPos); |
---|
| 1329 | RPSTemp.setNumberOfNegativePictures(numNeg); |
---|
| 1330 | RPSTemp.sortDeltaPOC(); // sort the created delta POC before comparing |
---|
| 1331 | // check if Delta POC and Used are the same |
---|
| 1332 | // print warning if they are not. |
---|
| 1333 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1334 | { |
---|
| 1335 | if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j)) |
---|
| 1336 | { |
---|
| 1337 | printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n"); |
---|
| 1338 | rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j)); |
---|
| 1339 | } |
---|
| 1340 | if (RPSTemp.getUsed(j) != rps->getUsed(j)) |
---|
| 1341 | { |
---|
| 1342 | printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n"); |
---|
| 1343 | rps->setUsed(j,RPSTemp.getUsed(j)); |
---|
| 1344 | } |
---|
| 1345 | } |
---|
| 1346 | #endif |
---|
| 1347 | } |
---|
| 1348 | #else |
---|
| 1349 | rps->setInterRPSPrediction(ge.m_interRPSPrediction); |
---|
| 1350 | if (ge.m_interRPSPrediction) |
---|
| 1351 | { |
---|
| 1352 | rps->setDeltaRIdxMinus1(0); |
---|
| 1353 | rps->setDeltaRPS(ge.m_deltaRPS); |
---|
| 1354 | rps->setNumRefIdc(ge.m_numRefIdc); |
---|
| 1355 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1356 | { |
---|
| 1357 | rps->setRefIdc(j, ge.m_refIdc[j]); |
---|
| 1358 | } |
---|
| 1359 | #if WRITE_BACK |
---|
| 1360 | // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones |
---|
| 1361 | // computed from the RefIdc. This is not necessary if both are identical. Currently there is no check to see if they are identical. |
---|
| 1362 | numNeg = 0; |
---|
| 1363 | numPos = 0; |
---|
| 1364 | TComReferencePictureSet* RPSRef = m_RPSList.getReferencePictureSet(i-1); |
---|
| 1365 | |
---|
| 1366 | for (Int j = 0; j < ge.m_numRefIdc; j++ ) |
---|
| 1367 | { |
---|
| 1368 | if (ge.m_refIdc[j]) |
---|
| 1369 | { |
---|
| 1370 | Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0); |
---|
| 1371 | rps->setDeltaPOC((numNeg+numPos),deltaPOC); |
---|
| 1372 | rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0); |
---|
| 1373 | if (deltaPOC<0) |
---|
| 1374 | { |
---|
| 1375 | numNeg++; |
---|
| 1376 | } |
---|
| 1377 | else |
---|
| 1378 | { |
---|
| 1379 | numPos++; |
---|
| 1380 | } |
---|
| 1381 | } |
---|
| 1382 | } |
---|
| 1383 | rps->setNumberOfNegativePictures(numNeg); |
---|
| 1384 | rps->setNumberOfPositivePictures(numPos); |
---|
| 1385 | rps->sortDeltaPOC(); |
---|
| 1386 | #endif |
---|
| 1387 | } |
---|
| 1388 | #endif //INTER_RPS_AUTO |
---|
| 1389 | } |
---|
[442] | 1390 | //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file. |
---|
| 1391 | //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS. |
---|
| 1392 | if (isFieldCoding) |
---|
| 1393 | { |
---|
| 1394 | rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs); |
---|
| 1395 | rps->setNumberOfPictures(1); |
---|
| 1396 | rps->setNumberOfNegativePictures(1); |
---|
| 1397 | rps->setNumberOfPositivePictures(0); |
---|
| 1398 | rps->setNumberOfLongtermPictures(0); |
---|
| 1399 | rps->setDeltaPOC(0,-1); |
---|
| 1400 | rps->setPOC(0,0); |
---|
| 1401 | rps->setUsed(0,true); |
---|
| 1402 | rps->setInterRPSPrediction(false); |
---|
| 1403 | rps->setDeltaRIdxMinus1(0); |
---|
| 1404 | rps->setDeltaRPS(0); |
---|
| 1405 | rps->setNumRefIdc(0); |
---|
[313] | 1406 | } |
---|
[442] | 1407 | } |
---|
[313] | 1408 | |
---|
| 1409 | // This is a function that |
---|
| 1410 | // determines what Reference Picture Set to use |
---|
| 1411 | // for a specific slice (with POC = POCCurr) |
---|
| 1412 | Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
| 1413 | { |
---|
| 1414 | slice->setRPSidx(GOPid); |
---|
| 1415 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
| 1416 | { |
---|
| 1417 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
| 1418 | { |
---|
| 1419 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
| 1420 | if(POCIndex == 0) |
---|
| 1421 | { |
---|
| 1422 | POCIndex = m_uiIntraPeriod; |
---|
| 1423 | } |
---|
| 1424 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
| 1425 | { |
---|
| 1426 | slice->setRPSidx(extraNum); |
---|
| 1427 | } |
---|
| 1428 | } |
---|
| 1429 | else |
---|
| 1430 | { |
---|
| 1431 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
| 1432 | { |
---|
| 1433 | slice->setRPSidx(extraNum); |
---|
| 1434 | } |
---|
| 1435 | } |
---|
| 1436 | } |
---|
| 1437 | |
---|
[442] | 1438 | if(POCCurr == 1 && slice->getPic()->isField()) |
---|
| 1439 | { |
---|
| 1440 | slice->setRPSidx(m_iGOPSize+m_extraRPSs); |
---|
| 1441 | } |
---|
| 1442 | |
---|
[313] | 1443 | slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx())); |
---|
| 1444 | slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures()); |
---|
| 1445 | } |
---|
| 1446 | |
---|
| 1447 | Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid ) |
---|
| 1448 | { |
---|
| 1449 | int rpsIdx = GOPid; |
---|
| 1450 | |
---|
| 1451 | for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++) |
---|
| 1452 | { |
---|
| 1453 | if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0) |
---|
| 1454 | { |
---|
| 1455 | Int POCIndex = POCCurr%m_uiIntraPeriod; |
---|
| 1456 | if(POCIndex == 0) |
---|
| 1457 | { |
---|
| 1458 | POCIndex = m_uiIntraPeriod; |
---|
| 1459 | } |
---|
| 1460 | if(POCIndex == m_GOPList[extraNum].m_POC) |
---|
| 1461 | { |
---|
| 1462 | rpsIdx = extraNum; |
---|
| 1463 | } |
---|
| 1464 | } |
---|
| 1465 | else |
---|
| 1466 | { |
---|
| 1467 | if(POCCurr==m_GOPList[extraNum].m_POC) |
---|
| 1468 | { |
---|
| 1469 | rpsIdx = extraNum; |
---|
| 1470 | } |
---|
| 1471 | } |
---|
| 1472 | } |
---|
| 1473 | |
---|
| 1474 | return rpsIdx; |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | Void TEncTop::xInitPPSforTiles() |
---|
| 1478 | { |
---|
| 1479 | m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr ); |
---|
| 1480 | m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 ); |
---|
| 1481 | m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 ); |
---|
| 1482 | if( m_iUniformSpacingIdr == 0 ) |
---|
| 1483 | { |
---|
| 1484 | m_cPPS.setColumnWidth( m_puiColumnWidth ); |
---|
| 1485 | m_cPPS.setRowHeight( m_puiRowHeight ); |
---|
| 1486 | } |
---|
| 1487 | m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag ); |
---|
| 1488 | |
---|
| 1489 | // # substreams is "per tile" when tiles are independent. |
---|
| 1490 | if (m_iWaveFrontSynchro |
---|
| 1491 | ) |
---|
| 1492 | { |
---|
| 1493 | m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1)); |
---|
| 1494 | } |
---|
| 1495 | } |
---|
| 1496 | |
---|
| 1497 | Void TEncCfg::xCheckGSParameters() |
---|
| 1498 | { |
---|
| 1499 | Int iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth; |
---|
| 1500 | Int iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight; |
---|
| 1501 | UInt uiCummulativeColumnWidth = 0; |
---|
| 1502 | UInt uiCummulativeRowHeight = 0; |
---|
| 1503 | |
---|
| 1504 | //check the column relative parameters |
---|
| 1505 | if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) ) |
---|
| 1506 | { |
---|
| 1507 | printf( "The number of columns is larger than the maximum allowed number of columns.\n" ); |
---|
| 1508 | exit( EXIT_FAILURE ); |
---|
| 1509 | } |
---|
| 1510 | |
---|
| 1511 | if( m_iNumColumnsMinus1 >= iWidthInCU ) |
---|
| 1512 | { |
---|
| 1513 | printf( "The current picture can not have so many columns.\n" ); |
---|
| 1514 | exit( EXIT_FAILURE ); |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
| 1518 | { |
---|
| 1519 | for(Int i=0; i<m_iNumColumnsMinus1; i++) |
---|
| 1520 | { |
---|
| 1521 | uiCummulativeColumnWidth += m_puiColumnWidth[i]; |
---|
| 1522 | } |
---|
| 1523 | |
---|
| 1524 | if( uiCummulativeColumnWidth >= iWidthInCU ) |
---|
| 1525 | { |
---|
| 1526 | printf( "The width of the column is too large.\n" ); |
---|
| 1527 | exit( EXIT_FAILURE ); |
---|
| 1528 | } |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | //check the row relative parameters |
---|
| 1532 | if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) ) |
---|
| 1533 | { |
---|
| 1534 | printf( "The number of rows is larger than the maximum allowed number of rows.\n" ); |
---|
| 1535 | exit( EXIT_FAILURE ); |
---|
| 1536 | } |
---|
| 1537 | |
---|
| 1538 | if( m_iNumRowsMinus1 >= iHeightInCU ) |
---|
| 1539 | { |
---|
| 1540 | printf( "The current picture can not have so many rows.\n" ); |
---|
| 1541 | exit( EXIT_FAILURE ); |
---|
| 1542 | } |
---|
| 1543 | |
---|
| 1544 | if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 ) |
---|
| 1545 | { |
---|
| 1546 | for(Int i=0; i<m_iNumRowsMinus1; i++) |
---|
| 1547 | { |
---|
| 1548 | uiCummulativeRowHeight += m_puiRowHeight[i]; |
---|
| 1549 | } |
---|
| 1550 | |
---|
| 1551 | if( uiCummulativeRowHeight >= iHeightInCU ) |
---|
| 1552 | { |
---|
| 1553 | printf( "The height of the row is too large.\n" ); |
---|
| 1554 | exit( EXIT_FAILURE ); |
---|
| 1555 | } |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | #if SVC_EXTENSION |
---|
| 1560 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
| 1561 | TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc ) |
---|
| 1562 | { |
---|
| 1563 | if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 ) |
---|
| 1564 | { |
---|
| 1565 | return (TEncTop *)getLayerEnc( 0 ); |
---|
| 1566 | } |
---|
| 1567 | |
---|
| 1568 | return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) ); |
---|
| 1569 | } |
---|
| 1570 | #endif |
---|
| 1571 | |
---|
[442] | 1572 | #if !REPN_FORMAT_IN_VPS |
---|
[313] | 1573 | Void TEncTop::xInitILRP() |
---|
| 1574 | { |
---|
| 1575 | if(m_layerId>0) |
---|
| 1576 | { |
---|
| 1577 | g_bitDepthY = m_cSPS.getBitDepthY(); |
---|
| 1578 | g_bitDepthC = m_cSPS.getBitDepthC(); |
---|
| 1579 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
---|
| 1580 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
---|
| 1581 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
---|
| 1582 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
---|
| 1583 | |
---|
| 1584 | Int numReorderPics[MAX_TLAYER]; |
---|
| 1585 | Window &conformanceWindow = m_cSPS.getConformanceWindow(); |
---|
| 1586 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
| 1587 | |
---|
| 1588 | if (m_cIlpPic[0] == NULL) |
---|
| 1589 | { |
---|
[588] | 1590 | for (Int j=0; j < m_numLayer; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]] |
---|
[313] | 1591 | { |
---|
| 1592 | m_cIlpPic[j] = new TComPic; |
---|
[494] | 1593 | #if AUXILIARY_PICTURES |
---|
| 1594 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
| 1595 | #else |
---|
[313] | 1596 | m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
[494] | 1597 | #endif |
---|
[313] | 1598 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
| 1599 | { |
---|
| 1600 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
| 1601 | } |
---|
| 1602 | } |
---|
| 1603 | } |
---|
| 1604 | } |
---|
| 1605 | } |
---|
[442] | 1606 | #else |
---|
| 1607 | Void TEncTop::xInitILRP() |
---|
| 1608 | { |
---|
[540] | 1609 | #if O0096_REP_FORMAT_INDEX |
---|
| 1610 | RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) ); |
---|
| 1611 | #else |
---|
[442] | 1612 | RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) ); |
---|
[540] | 1613 | #endif |
---|
[442] | 1614 | Int bitDepthY,bitDepthC,picWidth,picHeight; |
---|
[313] | 1615 | |
---|
[540] | 1616 | #if O0096_REP_FORMAT_INDEX |
---|
| 1617 | bitDepthY = repFormat->getBitDepthVpsLuma(); |
---|
| 1618 | bitDepthC = repFormat->getBitDepthVpsChroma(); |
---|
| 1619 | picWidth = repFormat->getPicWidthVpsInLumaSamples(); |
---|
| 1620 | picHeight = repFormat->getPicHeightVpsInLumaSamples(); |
---|
| 1621 | #else |
---|
[442] | 1622 | if( m_cSPS.getUpdateRepFormatFlag() ) |
---|
| 1623 | { |
---|
| 1624 | bitDepthY = m_cSPS.getBitDepthY(); |
---|
| 1625 | bitDepthC = m_cSPS.getBitDepthC(); |
---|
| 1626 | picWidth = m_cSPS.getPicWidthInLumaSamples(); |
---|
| 1627 | picHeight = m_cSPS.getPicHeightInLumaSamples(); |
---|
| 1628 | } |
---|
| 1629 | else |
---|
| 1630 | { |
---|
| 1631 | bitDepthY = repFormat->getBitDepthVpsLuma(); |
---|
| 1632 | bitDepthC = repFormat->getBitDepthVpsChroma(); |
---|
| 1633 | picWidth = repFormat->getPicWidthVpsInLumaSamples(); |
---|
| 1634 | picHeight = repFormat->getPicHeightVpsInLumaSamples(); |
---|
| 1635 | } |
---|
[540] | 1636 | #endif |
---|
[442] | 1637 | |
---|
| 1638 | if(m_layerId > 0) |
---|
| 1639 | { |
---|
| 1640 | g_bitDepthY = bitDepthY; |
---|
| 1641 | g_bitDepthC = bitDepthC; |
---|
| 1642 | g_uiMaxCUWidth = m_cSPS.getMaxCUWidth(); |
---|
| 1643 | g_uiMaxCUHeight = m_cSPS.getMaxCUHeight(); |
---|
| 1644 | g_uiMaxCUDepth = m_cSPS.getMaxCUDepth(); |
---|
| 1645 | g_uiAddCUDepth = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() ); |
---|
| 1646 | |
---|
| 1647 | Int numReorderPics[MAX_TLAYER]; |
---|
| 1648 | Window &conformanceWindow = m_cSPS.getConformanceWindow(); |
---|
| 1649 | Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window(); |
---|
| 1650 | |
---|
| 1651 | if (m_cIlpPic[0] == NULL) |
---|
| 1652 | { |
---|
[588] | 1653 | for (Int j=0; j < m_numDirectRefLayers; j++) |
---|
[442] | 1654 | { |
---|
| 1655 | m_cIlpPic[j] = new TComPic; |
---|
[494] | 1656 | #if AUXILIARY_PICTURES |
---|
| 1657 | m_cIlpPic[j]->create(picWidth, picHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
| 1658 | #else |
---|
[442] | 1659 | m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true); |
---|
[494] | 1660 | #endif |
---|
[442] | 1661 | for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++) |
---|
| 1662 | { |
---|
| 1663 | m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i); |
---|
| 1664 | } |
---|
| 1665 | } |
---|
| 1666 | } |
---|
| 1667 | } |
---|
| 1668 | } |
---|
| 1669 | #endif |
---|
[540] | 1670 | |
---|
| 1671 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 1672 | Window& TEncTop::getScaledRefLayerWindowForLayer(Int layerId) |
---|
| 1673 | { |
---|
| 1674 | static Window win; |
---|
| 1675 | |
---|
| 1676 | for (Int i = 0; i < m_numScaledRefLayerOffsets; i++) |
---|
| 1677 | { |
---|
| 1678 | if (layerId == m_scaledRefLayerId[i]) |
---|
| 1679 | { |
---|
| 1680 | return m_scaledRefLayerWindow[i]; |
---|
| 1681 | } |
---|
| 1682 | } |
---|
| 1683 | |
---|
| 1684 | win.resetWindow(); // scaled reference layer offsets are inferred to be zero when not present |
---|
| 1685 | return win; |
---|
| 1686 | } |
---|
| 1687 | #endif |
---|
| 1688 | |
---|
[494] | 1689 | #endif //SVC_EXTENSION |
---|
[313] | 1690 | //! \} |
---|