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