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