| 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 TComSlice.cpp |
|---|
| 35 | \brief slice header and SPS class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include "CommonDef.h" |
|---|
| 39 | #include "TComSlice.h" |
|---|
| 40 | #include "TComPic.h" |
|---|
| 41 | #include "TLibEncoder/TEncSbac.h" |
|---|
| 42 | #include "TLibDecoder/TDecSbac.h" |
|---|
| 43 | |
|---|
| 44 | //! \ingroup TLibCommon |
|---|
| 45 | //! \{ |
|---|
| 46 | |
|---|
| 47 | TComSlice::TComSlice() |
|---|
| 48 | : m_iPPSId ( -1 ) |
|---|
| 49 | , m_iPOC ( 0 ) |
|---|
| 50 | , m_iLastIDR ( 0 ) |
|---|
| 51 | , m_eNalUnitType ( NAL_UNIT_CODED_SLICE_IDR_W_RADL ) |
|---|
| 52 | , m_eSliceType ( I_SLICE ) |
|---|
| 53 | , m_iSliceQp ( 0 ) |
|---|
| 54 | , m_dependentSliceSegmentFlag ( false ) |
|---|
| 55 | #if ADAPTIVE_QP_SELECTION |
|---|
| 56 | , m_iSliceQpBase ( 0 ) |
|---|
| 57 | #endif |
|---|
| 58 | , m_deblockingFilterDisable ( false ) |
|---|
| 59 | , m_deblockingFilterOverrideFlag ( false ) |
|---|
| 60 | , m_deblockingFilterBetaOffsetDiv2 ( 0 ) |
|---|
| 61 | , m_deblockingFilterTcOffsetDiv2 ( 0 ) |
|---|
| 62 | , m_bCheckLDC ( false ) |
|---|
| 63 | , m_iSliceQpDelta ( 0 ) |
|---|
| 64 | , m_iSliceQpDeltaCb ( 0 ) |
|---|
| 65 | , m_iSliceQpDeltaCr ( 0 ) |
|---|
| 66 | , m_iDepth ( 0 ) |
|---|
| 67 | , m_bRefenced ( false ) |
|---|
| 68 | , m_pcSPS ( NULL ) |
|---|
| 69 | , m_pcPPS ( NULL ) |
|---|
| 70 | , m_pcPic ( NULL ) |
|---|
| 71 | , m_colFromL0Flag ( 1 ) |
|---|
| 72 | , m_colRefIdx ( 0 ) |
|---|
| 73 | #if SAO_CHROMA_LAMBDA |
|---|
| 74 | , m_dLambdaLuma( 0.0 ) |
|---|
| 75 | , m_dLambdaChroma( 0.0 ) |
|---|
| 76 | #else |
|---|
| 77 | , m_dLambda ( 0.0 ) |
|---|
| 78 | #endif |
|---|
| 79 | , m_uiTLayer ( 0 ) |
|---|
| 80 | , m_bTLayerSwitchingFlag ( false ) |
|---|
| 81 | , m_sliceMode ( 0 ) |
|---|
| 82 | , m_sliceArgument ( 0 ) |
|---|
| 83 | , m_sliceCurStartCUAddr ( 0 ) |
|---|
| 84 | , m_sliceCurEndCUAddr ( 0 ) |
|---|
| 85 | , m_sliceIdx ( 0 ) |
|---|
| 86 | , m_sliceSegmentMode ( 0 ) |
|---|
| 87 | , m_sliceSegmentArgument ( 0 ) |
|---|
| 88 | , m_sliceSegmentCurStartCUAddr ( 0 ) |
|---|
| 89 | , m_sliceSegmentCurEndCUAddr ( 0 ) |
|---|
| 90 | , m_nextSlice ( false ) |
|---|
| 91 | , m_nextSliceSegment ( false ) |
|---|
| 92 | , m_sliceBits ( 0 ) |
|---|
| 93 | , m_sliceSegmentBits ( 0 ) |
|---|
| 94 | , m_bFinalized ( false ) |
|---|
| 95 | , m_uiTileOffstForMultES ( 0 ) |
|---|
| 96 | , m_puiSubstreamSizes ( NULL ) |
|---|
| 97 | , m_cabacInitFlag ( false ) |
|---|
| 98 | , m_bLMvdL1Zero ( false ) |
|---|
| 99 | , m_numEntryPointOffsets ( 0 ) |
|---|
| 100 | , m_temporalLayerNonReferenceFlag ( false ) |
|---|
| 101 | , m_enableTMVPFlag ( true ) |
|---|
| 102 | #if H_MV |
|---|
| 103 | , m_refPicSetInterLayer0 ( NULL ) |
|---|
| 104 | , m_refPicSetInterLayer1 ( NULL ) |
|---|
| 105 | , m_layerId (0) |
|---|
| 106 | , m_viewId (0) |
|---|
| 107 | , m_viewIndex (0) |
|---|
| 108 | #if H_3D |
|---|
| 109 | , m_isDepth (false) |
|---|
| 110 | #endif |
|---|
| 111 | , m_pocResetFlag (false) |
|---|
| 112 | , m_discardableFlag (false) |
|---|
| 113 | , m_interLayerPredEnabledFlag (false) |
|---|
| 114 | , m_numInterLayerRefPicsMinus1 (0) |
|---|
| 115 | #if H_3D_IC |
|---|
| 116 | , m_bApplyIC ( false ) |
|---|
| 117 | , m_icSkipParseFlag ( false ) |
|---|
| 118 | #endif |
|---|
| 119 | #if H_3D |
|---|
| 120 | , m_depthToDisparityB ( NULL ) |
|---|
| 121 | , m_depthToDisparityF ( NULL ) |
|---|
| 122 | #endif |
|---|
| 123 | #endif |
|---|
| 124 | { |
|---|
| 125 | m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0; |
|---|
| 126 | |
|---|
| 127 | initEqualRef(); |
|---|
| 128 | |
|---|
| 129 | for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) |
|---|
| 130 | { |
|---|
| 131 | m_list1IdxToList0Idx[idx] = -1; |
|---|
| 132 | } |
|---|
| 133 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++) |
|---|
| 134 | { |
|---|
| 135 | m_apcRefPicList [0][iNumCount] = NULL; |
|---|
| 136 | m_apcRefPicList [1][iNumCount] = NULL; |
|---|
| 137 | m_aiRefPOCList [0][iNumCount] = 0; |
|---|
| 138 | m_aiRefPOCList [1][iNumCount] = 0; |
|---|
| 139 | #if H_MV |
|---|
| 140 | m_aiRefLayerIdList[0][iNumCount] = 0; |
|---|
| 141 | m_aiRefLayerIdList[1][iNumCount] = 0; |
|---|
| 142 | #endif |
|---|
| 143 | } |
|---|
| 144 | resetWpScaling(); |
|---|
| 145 | initWpAcDcParam(); |
|---|
| 146 | m_saoEnabledFlag = false; |
|---|
| 147 | #if H_MV |
|---|
| 148 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 149 | { |
|---|
| 150 | m_interLayerPredLayerIdc[ i ] = i; |
|---|
| 151 | } |
|---|
| 152 | #endif |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | TComSlice::~TComSlice() |
|---|
| 156 | { |
|---|
| 157 | delete[] m_puiSubstreamSizes; |
|---|
| 158 | m_puiSubstreamSizes = NULL; |
|---|
| 159 | #if H_3D |
|---|
| 160 | for( UInt i = 0; i < getViewIndex(); i++ ) |
|---|
| 161 | { |
|---|
| 162 | if ( m_depthToDisparityB && m_depthToDisparityB[ i ] ) |
|---|
| 163 | { |
|---|
| 164 | delete[] m_depthToDisparityB [ i ]; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) |
|---|
| 168 | { |
|---|
| 169 | delete[] m_depthToDisparityF [ i ]; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if ( m_depthToDisparityF ) |
|---|
| 174 | { |
|---|
| 175 | delete[] m_depthToDisparityF; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | m_depthToDisparityF = NULL; |
|---|
| 179 | |
|---|
| 180 | if ( m_depthToDisparityB ) |
|---|
| 181 | delete[] m_depthToDisparityB; |
|---|
| 182 | |
|---|
| 183 | m_depthToDisparityB = NULL; |
|---|
| 184 | #endif |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | Void TComSlice::initSlice() |
|---|
| 189 | { |
|---|
| 190 | m_aiNumRefIdx[0] = 0; |
|---|
| 191 | m_aiNumRefIdx[1] = 0; |
|---|
| 192 | |
|---|
| 193 | m_colFromL0Flag = 1; |
|---|
| 194 | |
|---|
| 195 | m_colRefIdx = 0; |
|---|
| 196 | initEqualRef(); |
|---|
| 197 | m_bCheckLDC = false; |
|---|
| 198 | m_iSliceQpDeltaCb = 0; |
|---|
| 199 | m_iSliceQpDeltaCr = 0; |
|---|
| 200 | |
|---|
| 201 | #if H_3D_IV_MERGE |
|---|
| 202 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM; |
|---|
| 203 | #else |
|---|
| 204 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS; |
|---|
| 205 | #endif |
|---|
| 206 | |
|---|
| 207 | m_bFinalized=false; |
|---|
| 208 | |
|---|
| 209 | m_tileByteLocation.clear(); |
|---|
| 210 | m_cabacInitFlag = false; |
|---|
| 211 | m_numEntryPointOffsets = 0; |
|---|
| 212 | m_enableTMVPFlag = true; |
|---|
| 213 | #if H_3D_TMVP |
|---|
| 214 | m_aiAlterRefIdx[0] = -1; |
|---|
| 215 | m_aiAlterRefIdx[1] = -1; |
|---|
| 216 | #endif |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | Bool TComSlice::getRapPicFlag() |
|---|
| 220 | { |
|---|
| 221 | return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
|---|
| 222 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
|---|
| 223 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
|---|
| 224 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 225 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 226 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | /** |
|---|
| 230 | - allocate table to contain substream sizes to be written to the slice header. |
|---|
| 231 | . |
|---|
| 232 | \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1. |
|---|
| 233 | */ |
|---|
| 234 | Void TComSlice::allocSubstreamSizes(UInt uiNumSubstreams) |
|---|
| 235 | { |
|---|
| 236 | delete[] m_puiSubstreamSizes; |
|---|
| 237 | m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0]; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | Void TComSlice::sortPicList (TComList<TComPic*>& rcListPic) |
|---|
| 241 | { |
|---|
| 242 | TComPic* pcPicExtract; |
|---|
| 243 | TComPic* pcPicInsert; |
|---|
| 244 | |
|---|
| 245 | TComList<TComPic*>::iterator iterPicExtract; |
|---|
| 246 | TComList<TComPic*>::iterator iterPicExtract_1; |
|---|
| 247 | TComList<TComPic*>::iterator iterPicInsert; |
|---|
| 248 | |
|---|
| 249 | for (Int i = 1; i < (Int)(rcListPic.size()); i++) |
|---|
| 250 | { |
|---|
| 251 | iterPicExtract = rcListPic.begin(); |
|---|
| 252 | for (Int j = 0; j < i; j++) iterPicExtract++; |
|---|
| 253 | pcPicExtract = *(iterPicExtract); |
|---|
| 254 | pcPicExtract->setCurrSliceIdx(0); |
|---|
| 255 | |
|---|
| 256 | iterPicInsert = rcListPic.begin(); |
|---|
| 257 | while (iterPicInsert != iterPicExtract) |
|---|
| 258 | { |
|---|
| 259 | pcPicInsert = *(iterPicInsert); |
|---|
| 260 | pcPicInsert->setCurrSliceIdx(0); |
|---|
| 261 | if (pcPicInsert->getPOC() >= pcPicExtract->getPOC()) |
|---|
| 262 | { |
|---|
| 263 | break; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | iterPicInsert++; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | iterPicExtract_1 = iterPicExtract; iterPicExtract_1++; |
|---|
| 270 | |
|---|
| 271 | // swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position |
|---|
| 272 | rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1); |
|---|
| 273 | rcListPic.erase (iterPicExtract); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, |
|---|
| 278 | Int poc) |
|---|
| 279 | { |
|---|
| 280 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 281 | TComPic* pcPic = *(iterPic); |
|---|
| 282 | while ( iterPic != rcListPic.end() ) |
|---|
| 283 | { |
|---|
| 284 | if(pcPic->getPOC() == poc) |
|---|
| 285 | { |
|---|
| 286 | break; |
|---|
| 287 | } |
|---|
| 288 | iterPic++; |
|---|
| 289 | pcPic = *(iterPic); |
|---|
| 290 | } |
|---|
| 291 | return pcPic; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb) |
|---|
| 296 | { |
|---|
| 297 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 298 | TComPic* pcPic = *(iterPic); |
|---|
| 299 | TComPic* pcStPic = pcPic; |
|---|
| 300 | |
|---|
| 301 | Int pocCycle = 1 << getSPS()->getBitsForPOC(); |
|---|
| 302 | if (!pocHasMsb) |
|---|
| 303 | { |
|---|
| 304 | poc = poc & (pocCycle - 1); |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | while ( iterPic != rcListPic.end() ) |
|---|
| 308 | { |
|---|
| 309 | pcPic = *(iterPic); |
|---|
| 310 | if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced()) |
|---|
| 311 | { |
|---|
| 312 | Int picPoc = pcPic->getPOC(); |
|---|
| 313 | if (!pocHasMsb) |
|---|
| 314 | { |
|---|
| 315 | picPoc = picPoc & (pocCycle - 1); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | if (poc == picPoc) |
|---|
| 319 | { |
|---|
| 320 | if(pcPic->getIsLongTerm()) |
|---|
| 321 | { |
|---|
| 322 | return pcPic; |
|---|
| 323 | } |
|---|
| 324 | else |
|---|
| 325 | { |
|---|
| 326 | pcStPic = pcPic; |
|---|
| 327 | } |
|---|
| 328 | break; |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | iterPic++; |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | return pcStPic; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | Void TComSlice::setRefPOCList () |
|---|
| 339 | { |
|---|
| 340 | for (Int iDir = 0; iDir < 2; iDir++) |
|---|
| 341 | { |
|---|
| 342 | for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++) |
|---|
| 343 | { |
|---|
| 344 | m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC(); |
|---|
| 345 | #if H_MV |
|---|
| 346 | m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId(); |
|---|
| 347 | #endif |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | Void TComSlice::setList1IdxToList0Idx() |
|---|
| 354 | { |
|---|
| 355 | Int idxL0, idxL1; |
|---|
| 356 | for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ ) |
|---|
| 357 | { |
|---|
| 358 | m_list1IdxToList0Idx[idxL1] = -1; |
|---|
| 359 | for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ ) |
|---|
| 360 | { |
|---|
| 361 | if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() ) |
|---|
| 362 | { |
|---|
| 363 | m_list1IdxToList0Idx[idxL1] = idxL0; |
|---|
| 364 | break; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | #if !H_MV |
|---|
| 370 | #if FIX1071 |
|---|
| 371 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) |
|---|
| 372 | #else |
|---|
| 373 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) |
|---|
| 374 | #endif |
|---|
| 375 | { |
|---|
| 376 | #if FIX1071 |
|---|
| 377 | if (!checkNumPocTotalCurr) |
|---|
| 378 | #endif |
|---|
| 379 | { |
|---|
| 380 | if (m_eSliceType == I_SLICE) |
|---|
| 381 | { |
|---|
| 382 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 383 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 384 | |
|---|
| 385 | return; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 389 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | TComPic* pcRefPic= NULL; |
|---|
| 393 | TComPic* RefPicSetStCurr0[16]; |
|---|
| 394 | TComPic* RefPicSetStCurr1[16]; |
|---|
| 395 | TComPic* RefPicSetLtCurr[16]; |
|---|
| 396 | UInt NumPocStCurr0 = 0; |
|---|
| 397 | UInt NumPocStCurr1 = 0; |
|---|
| 398 | UInt NumPocLtCurr = 0; |
|---|
| 399 | Int i; |
|---|
| 400 | |
|---|
| 401 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
|---|
| 402 | { |
|---|
| 403 | if(m_pcRPS->getUsed(i)) |
|---|
| 404 | { |
|---|
| 405 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 406 | pcRefPic->setIsLongTerm(0); |
|---|
| 407 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 408 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
|---|
| 409 | NumPocStCurr0++; |
|---|
| 410 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 411 | } |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
|---|
| 415 | { |
|---|
| 416 | if(m_pcRPS->getUsed(i)) |
|---|
| 417 | { |
|---|
| 418 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 419 | pcRefPic->setIsLongTerm(0); |
|---|
| 420 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 421 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
|---|
| 422 | NumPocStCurr1++; |
|---|
| 423 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
|---|
| 428 | { |
|---|
| 429 | if(m_pcRPS->getUsed(i)) |
|---|
| 430 | { |
|---|
| 431 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 432 | pcRefPic->setIsLongTerm(1); |
|---|
| 433 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 434 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
|---|
| 435 | NumPocLtCurr++; |
|---|
| 436 | } |
|---|
| 437 | if(pcRefPic==NULL) |
|---|
| 438 | { |
|---|
| 439 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 440 | } |
|---|
| 441 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | // ref_pic_list_init |
|---|
| 445 | TComPic* rpsCurrList0[MAX_NUM_REF+1]; |
|---|
| 446 | TComPic* rpsCurrList1[MAX_NUM_REF+1]; |
|---|
| 447 | Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
|---|
| 448 | |
|---|
| 449 | #if FIX1071 |
|---|
| 450 | if (checkNumPocTotalCurr) |
|---|
| 451 | { |
|---|
| 452 | // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr: |
|---|
| 453 | // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
|---|
| 454 | // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
|---|
| 455 | if (getRapPicFlag()) |
|---|
| 456 | { |
|---|
| 457 | assert(numPocTotalCurr == 0); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | if (m_eSliceType == I_SLICE) |
|---|
| 461 | { |
|---|
| 462 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 463 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 464 | |
|---|
| 465 | return; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | assert(numPocTotalCurr > 0); |
|---|
| 469 | |
|---|
| 470 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 471 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
|---|
| 472 | } |
|---|
| 473 | #endif |
|---|
| 474 | |
|---|
| 475 | Int cIdx = 0; |
|---|
| 476 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
|---|
| 477 | { |
|---|
| 478 | rpsCurrList0[cIdx] = RefPicSetStCurr0[i]; |
|---|
| 479 | } |
|---|
| 480 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
|---|
| 481 | { |
|---|
| 482 | rpsCurrList0[cIdx] = RefPicSetStCurr1[i]; |
|---|
| 483 | } |
|---|
| 484 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
|---|
| 485 | { |
|---|
| 486 | rpsCurrList0[cIdx] = RefPicSetLtCurr[i]; |
|---|
| 487 | } |
|---|
| 488 | assert(cIdx == numPocTotalCurr); |
|---|
| 489 | |
|---|
| 490 | if (m_eSliceType==B_SLICE) |
|---|
| 491 | { |
|---|
| 492 | cIdx = 0; |
|---|
| 493 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
|---|
| 494 | { |
|---|
| 495 | rpsCurrList1[cIdx] = RefPicSetStCurr1[i]; |
|---|
| 496 | } |
|---|
| 497 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
|---|
| 498 | { |
|---|
| 499 | rpsCurrList1[cIdx] = RefPicSetStCurr0[i]; |
|---|
| 500 | } |
|---|
| 501 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
|---|
| 502 | { |
|---|
| 503 | rpsCurrList1[cIdx] = RefPicSetLtCurr[i]; |
|---|
| 504 | } |
|---|
| 505 | assert(cIdx == numPocTotalCurr); |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
|---|
| 509 | |
|---|
| 510 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++) |
|---|
| 511 | { |
|---|
| 512 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr; |
|---|
| 513 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
|---|
| 514 | m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ]; |
|---|
| 515 | m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
|---|
| 516 | } |
|---|
| 517 | if ( m_eSliceType != B_SLICE ) |
|---|
| 518 | { |
|---|
| 519 | m_aiNumRefIdx[1] = 0; |
|---|
| 520 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
|---|
| 521 | } |
|---|
| 522 | else |
|---|
| 523 | { |
|---|
| 524 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++) |
|---|
| 525 | { |
|---|
| 526 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr; |
|---|
| 527 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
|---|
| 528 | m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ]; |
|---|
| 529 | m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | #else |
|---|
| 535 | Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1, |
|---|
| 536 | std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr ) |
|---|
| 537 | { |
|---|
| 538 | if (!checkNumPocTotalCurr) |
|---|
| 539 | { |
|---|
| 540 | if (m_eSliceType == I_SLICE) |
|---|
| 541 | { |
|---|
| 542 | return; |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | |
|---|
| 546 | TComPic* pcRefPic= NULL; |
|---|
| 547 | TComPic* RefPicSetStCurr0[16]; |
|---|
| 548 | TComPic* RefPicSetStCurr1[16]; |
|---|
| 549 | TComPic* RefPicSetLtCurr[16]; |
|---|
| 550 | UInt NumPocStCurr0 = 0; |
|---|
| 551 | UInt NumPocStCurr1 = 0; |
|---|
| 552 | UInt NumPocLtCurr = 0; |
|---|
| 553 | Int i; |
|---|
| 554 | |
|---|
| 555 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
|---|
| 556 | { |
|---|
| 557 | if(m_pcRPS->getUsed(i)) |
|---|
| 558 | { |
|---|
| 559 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 560 | pcRefPic->setIsLongTerm(0); |
|---|
| 561 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 562 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
|---|
| 563 | NumPocStCurr0++; |
|---|
| 564 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 565 | } |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
|---|
| 569 | { |
|---|
| 570 | if(m_pcRPS->getUsed(i)) |
|---|
| 571 | { |
|---|
| 572 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 573 | pcRefPic->setIsLongTerm(0); |
|---|
| 574 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 575 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
|---|
| 576 | NumPocStCurr1++; |
|---|
| 577 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
|---|
| 582 | { |
|---|
| 583 | if(m_pcRPS->getUsed(i)) |
|---|
| 584 | { |
|---|
| 585 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 586 | pcRefPic->setIsLongTerm(1); |
|---|
| 587 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 588 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
|---|
| 589 | NumPocLtCurr++; |
|---|
| 590 | } |
|---|
| 591 | if(pcRefPic==NULL) |
|---|
| 592 | { |
|---|
| 593 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 594 | } |
|---|
| 595 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
|---|
| 599 | numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( ); |
|---|
| 600 | assert( numPocTotalCurr == getNumRpsCurrTempList() ); |
|---|
| 601 | |
|---|
| 602 | if (checkNumPocTotalCurr) |
|---|
| 603 | { |
|---|
| 604 | // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr: |
|---|
| 605 | // - If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
|---|
| 606 | // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
|---|
| 607 | if ( getRapPicFlag() && m_layerId == 0 ) |
|---|
| 608 | { |
|---|
| 609 | assert(numPocTotalCurr == 0); |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | if (m_eSliceType == I_SLICE) |
|---|
| 613 | { |
|---|
| 614 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 615 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 616 | |
|---|
| 617 | return; |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | assert(numPocTotalCurr > 0); |
|---|
| 621 | |
|---|
| 622 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 623 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; |
|---|
| 627 | Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; |
|---|
| 628 | |
|---|
| 629 | TComPic** refPicSetStCurr [2] = { RefPicSetStCurr0, RefPicSetStCurr1 }; |
|---|
| 630 | Int numPocStCurr[2] = { NumPocStCurr0, NumPocStCurr1 }; |
|---|
| 631 | |
|---|
| 632 | for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++) |
|---|
| 633 | { |
|---|
| 634 | rpsCurrList [li].resize(MAX_NUM_REF+1,NULL ); |
|---|
| 635 | usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); |
|---|
| 636 | |
|---|
| 637 | Int cIdx = 0; |
|---|
| 638 | for ( i=0; i < numPocStCurr[li]; i++, cIdx++) |
|---|
| 639 | { |
|---|
| 640 | rpsCurrList[li][cIdx] = refPicSetStCurr[li][i]; |
|---|
| 641 | usedAsLongTerm [li][cIdx] = false; |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | for ( i=0; i < numPocInterLayer[li]; i++, cIdx++) |
|---|
| 645 | { |
|---|
| 646 | rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i]; |
|---|
| 647 | usedAsLongTerm [li][cIdx] = true; |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++) |
|---|
| 651 | { |
|---|
| 652 | rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i]; |
|---|
| 653 | usedAsLongTerm [li][cIdx] = false; |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
|---|
| 657 | { |
|---|
| 658 | rpsCurrList[li][cIdx] = RefPicSetLtCurr[i]; |
|---|
| 659 | usedAsLongTerm [li][cIdx] = true; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | for ( i=0; i < numPocInterLayer[1-li]; i++, cIdx++) |
|---|
| 663 | { |
|---|
| 664 | assert( cIdx < MAX_NUM_REF ); |
|---|
| 665 | rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i]; |
|---|
| 666 | usedAsLongTerm [li][cIdx] = true; |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | assert(cIdx == numPocTotalCurr); |
|---|
| 670 | } |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr ) |
|---|
| 674 | |
|---|
| 675 | { |
|---|
| 676 | if (!checkNumPocTotalCurr) |
|---|
| 677 | { |
|---|
| 678 | if (m_eSliceType == I_SLICE) |
|---|
| 679 | { |
|---|
| 680 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 681 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 682 | |
|---|
| 683 | return; |
|---|
| 684 | } |
|---|
| 685 | } |
|---|
| 686 | |
|---|
| 687 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
|---|
| 688 | |
|---|
| 689 | for (Int li = 0; li < 2; li++) |
|---|
| 690 | { |
|---|
| 691 | if ( m_eSliceType == P_SLICE && li == 1 ) |
|---|
| 692 | { |
|---|
| 693 | m_aiNumRefIdx[1] = 0; |
|---|
| 694 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
|---|
| 695 | } |
|---|
| 696 | else |
|---|
| 697 | { |
|---|
| 698 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++) |
|---|
| 699 | { |
|---|
| 700 | Bool listModified = m_RefPicListModification.getRefPicListModificationFlagL( li ); |
|---|
| 701 | Int orgIdx = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); |
|---|
| 702 | |
|---|
| 703 | assert( rpsCurrList[li][ orgIdx ] != NULL ); |
|---|
| 704 | m_apcRefPicList [li][rIdx] = rpsCurrList [li][ orgIdx ]; |
|---|
| 705 | m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; |
|---|
| 706 | } |
|---|
| 707 | } |
|---|
| 708 | } |
|---|
| 709 | } |
|---|
| 710 | #endif |
|---|
| 711 | Int TComSlice::getNumRpsCurrTempList() |
|---|
| 712 | { |
|---|
| 713 | Int numRpsCurrTempList = 0; |
|---|
| 714 | |
|---|
| 715 | if (m_eSliceType == I_SLICE) |
|---|
| 716 | { |
|---|
| 717 | return 0; |
|---|
| 718 | } |
|---|
| 719 | for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++) |
|---|
| 720 | { |
|---|
| 721 | if(m_pcRPS->getUsed(i)) |
|---|
| 722 | { |
|---|
| 723 | numRpsCurrTempList++; |
|---|
| 724 | } |
|---|
| 725 | } |
|---|
| 726 | #if H_MV |
|---|
| 727 | numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics(); |
|---|
| 728 | #endif |
|---|
| 729 | return numRpsCurrTempList; |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | Void TComSlice::initEqualRef() |
|---|
| 733 | { |
|---|
| 734 | for (Int iDir = 0; iDir < 2; iDir++) |
|---|
| 735 | { |
|---|
| 736 | for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++) |
|---|
| 737 | { |
|---|
| 738 | for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++) |
|---|
| 739 | { |
|---|
| 740 | m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false); |
|---|
| 741 | } |
|---|
| 742 | } |
|---|
| 743 | } |
|---|
| 744 | } |
|---|
| 745 | #if H_3D |
|---|
| 746 | #if H_3D_TMVP |
|---|
| 747 | Void TComSlice::generateAlterRefforTMVP() |
|---|
| 748 | { |
|---|
| 749 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
|---|
| 750 | { |
|---|
| 751 | if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0) |
|---|
| 752 | continue; |
|---|
| 753 | #if !SHARP_ARP_REF_CHECK_F0105 |
|---|
| 754 | // move the following to setARPStepNum() to define ARP related thing in ARP function. |
|---|
| 755 | #if QC_MTK_INTERVIEW_ARP_F0123_F0108 |
|---|
| 756 | for(Int i = 0; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ ) |
|---|
| 757 | { |
|---|
| 758 | if ( this->getRefPic(RefPicList(uiRefListIdx), i)->getPOC() != getPOC() ) |
|---|
| 759 | { |
|---|
| 760 | this->setFirstTRefIdx (RefPicList(uiRefListIdx), i); |
|---|
| 761 | break; |
|---|
| 762 | } |
|---|
| 763 | } |
|---|
| 764 | #endif |
|---|
| 765 | #endif |
|---|
| 766 | Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm(); |
|---|
| 767 | for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ ) |
|---|
| 768 | { |
|---|
| 769 | if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) || |
|---|
| 770 | (!bZeroIdxLtFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ) |
|---|
| 771 | { |
|---|
| 772 | this->setAlterRefIdx(RefPicList(uiRefListIdx),i); |
|---|
| 773 | break; |
|---|
| 774 | } |
|---|
| 775 | } |
|---|
| 776 | } |
|---|
| 777 | } |
|---|
| 778 | #endif |
|---|
| 779 | Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset ) |
|---|
| 780 | { |
|---|
| 781 | if( m_pcSPS->hasCamParInSliceHeader() ) |
|---|
| 782 | { |
|---|
| 783 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < m_viewIndex; uiBaseViewIndex++ ) |
|---|
| 784 | { |
|---|
| 785 | m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ m_viewIndex ]; |
|---|
| 786 | m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [ m_viewIndex ][ uiBaseViewIndex ]; |
|---|
| 787 | m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ m_viewIndex ]; |
|---|
| 788 | m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[ m_viewIndex ][ uiBaseViewIndex ]; |
|---|
| 789 | } |
|---|
| 790 | } |
|---|
| 791 | } |
|---|
| 792 | #endif |
|---|
| 793 | |
|---|
| 794 | Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic) |
|---|
| 795 | { |
|---|
| 796 | Int i; |
|---|
| 797 | TComSlice* curSlice = pic->getSlice(curSliceIdx); |
|---|
| 798 | Int currColRefPOC = curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx()); |
|---|
| 799 | TComSlice* preSlice; |
|---|
| 800 | Int preColRefPOC; |
|---|
| 801 | for(i=curSliceIdx-1; i>=0; i--) |
|---|
| 802 | { |
|---|
| 803 | preSlice = pic->getSlice(i); |
|---|
| 804 | if(preSlice->getSliceType() != I_SLICE) |
|---|
| 805 | { |
|---|
| 806 | preColRefPOC = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx()); |
|---|
| 807 | if(currColRefPOC != preColRefPOC) |
|---|
| 808 | { |
|---|
| 809 | printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n"); |
|---|
| 810 | exit(EXIT_FAILURE); |
|---|
| 811 | } |
|---|
| 812 | else |
|---|
| 813 | { |
|---|
| 814 | break; |
|---|
| 815 | } |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | } |
|---|
| 819 | |
|---|
| 820 | Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic) |
|---|
| 821 | { |
|---|
| 822 | for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++) |
|---|
| 823 | { |
|---|
| 824 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
|---|
| 825 | { |
|---|
| 826 | assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA); |
|---|
| 827 | } |
|---|
| 828 | } |
|---|
| 829 | for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++) |
|---|
| 830 | { |
|---|
| 831 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
|---|
| 832 | { |
|---|
| 833 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
|---|
| 834 | { |
|---|
| 835 | assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA); |
|---|
| 836 | } |
|---|
| 837 | else |
|---|
| 838 | { |
|---|
| 839 | assert(pReferencePictureSet->getPOC(i) >= pocCRA); |
|---|
| 840 | } |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found |
|---|
| 844 | { |
|---|
| 845 | pocCRA = getPOC(); |
|---|
| 846 | associatedIRAPType = getNalUnitType(); |
|---|
| 847 | } |
|---|
| 848 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
|---|
| 849 | { |
|---|
| 850 | pocCRA = getPOC(); |
|---|
| 851 | associatedIRAPType = getNalUnitType(); |
|---|
| 852 | } |
|---|
| 853 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 854 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 855 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found |
|---|
| 856 | { |
|---|
| 857 | pocCRA = getPOC(); |
|---|
| 858 | associatedIRAPType = getNalUnitType(); |
|---|
| 859 | } |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | /** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered. |
|---|
| 863 | * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture |
|---|
| 864 | * \param bRefreshPending flag indicating if a deferred decoding refresh is pending |
|---|
| 865 | * \param rcListPic reference to the reference picture list |
|---|
| 866 | * This function marks the reference pictures as "unused for reference" in the following conditions. |
|---|
| 867 | * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list |
|---|
| 868 | * are marked as "unused for reference" |
|---|
| 869 | * If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture. |
|---|
| 870 | * Otherwise |
|---|
| 871 | * If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current |
|---|
| 872 | * temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA), |
|---|
| 873 | * mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set |
|---|
| 874 | * the bRefreshPending flag to false. |
|---|
| 875 | * If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal |
|---|
| 876 | * reference of the current picture. |
|---|
| 877 | * Note that the current picture is already placed in the reference list and its marking is not changed. |
|---|
| 878 | * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference". |
|---|
| 879 | */ |
|---|
| 880 | Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic) |
|---|
| 881 | { |
|---|
| 882 | TComPic* rpcPic; |
|---|
| 883 | setAssociatedIRAPPOC(pocCRA); |
|---|
| 884 | Int pocCurr = getPOC(); |
|---|
| 885 | |
|---|
| 886 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 887 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 888 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
|---|
| 889 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
|---|
| 890 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR or BLA picture |
|---|
| 891 | { |
|---|
| 892 | // mark all pictures as not used for reference |
|---|
| 893 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 894 | while (iterPic != rcListPic.end()) |
|---|
| 895 | { |
|---|
| 896 | rpcPic = *(iterPic); |
|---|
| 897 | rpcPic->setCurrSliceIdx(0); |
|---|
| 898 | if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false); |
|---|
| 899 | iterPic++; |
|---|
| 900 | } |
|---|
| 901 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 902 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 903 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
|---|
| 904 | { |
|---|
| 905 | pocCRA = pocCurr; |
|---|
| 906 | } |
|---|
| 907 | } |
|---|
| 908 | else // CRA or No DR |
|---|
| 909 | { |
|---|
| 910 | if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending |
|---|
| 911 | { |
|---|
| 912 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 913 | while (iterPic != rcListPic.end()) |
|---|
| 914 | { |
|---|
| 915 | rpcPic = *(iterPic); |
|---|
| 916 | if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) |
|---|
| 917 | { |
|---|
| 918 | rpcPic->getSlice(0)->setReferenced(false); |
|---|
| 919 | } |
|---|
| 920 | iterPic++; |
|---|
| 921 | } |
|---|
| 922 | bRefreshPending = false; |
|---|
| 923 | } |
|---|
| 924 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
|---|
| 925 | { |
|---|
| 926 | bRefreshPending = true; |
|---|
| 927 | pocCRA = pocCurr; |
|---|
| 928 | } |
|---|
| 929 | } |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | Void TComSlice::copySliceInfo(TComSlice *pSrc) |
|---|
| 933 | { |
|---|
| 934 | assert( pSrc != NULL ); |
|---|
| 935 | |
|---|
| 936 | Int i, j, k; |
|---|
| 937 | |
|---|
| 938 | m_iPOC = pSrc->m_iPOC; |
|---|
| 939 | m_eNalUnitType = pSrc->m_eNalUnitType; |
|---|
| 940 | #if H_MV |
|---|
| 941 | m_layerId = pSrc->m_layerId; |
|---|
| 942 | // GT: Copying of several other values might be be missing here, or is above not necessary? |
|---|
| 943 | #endif |
|---|
| 944 | m_eSliceType = pSrc->m_eSliceType; |
|---|
| 945 | m_iSliceQp = pSrc->m_iSliceQp; |
|---|
| 946 | #if ADAPTIVE_QP_SELECTION |
|---|
| 947 | m_iSliceQpBase = pSrc->m_iSliceQpBase; |
|---|
| 948 | #endif |
|---|
| 949 | m_deblockingFilterDisable = pSrc->m_deblockingFilterDisable; |
|---|
| 950 | m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag; |
|---|
| 951 | m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2; |
|---|
| 952 | m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2; |
|---|
| 953 | |
|---|
| 954 | for (i = 0; i < 2; i++) |
|---|
| 955 | { |
|---|
| 956 | m_aiNumRefIdx[i] = pSrc->m_aiNumRefIdx[i]; |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | for (i = 0; i < MAX_NUM_REF; i++) |
|---|
| 960 | { |
|---|
| 961 | m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i]; |
|---|
| 962 | } |
|---|
| 963 | m_bCheckLDC = pSrc->m_bCheckLDC; |
|---|
| 964 | m_iSliceQpDelta = pSrc->m_iSliceQpDelta; |
|---|
| 965 | m_iSliceQpDeltaCb = pSrc->m_iSliceQpDeltaCb; |
|---|
| 966 | m_iSliceQpDeltaCr = pSrc->m_iSliceQpDeltaCr; |
|---|
| 967 | for (i = 0; i < 2; i++) |
|---|
| 968 | { |
|---|
| 969 | for (j = 0; j < MAX_NUM_REF; j++) |
|---|
| 970 | { |
|---|
| 971 | m_apcRefPicList[i][j] = pSrc->m_apcRefPicList[i][j]; |
|---|
| 972 | m_aiRefPOCList[i][j] = pSrc->m_aiRefPOCList[i][j]; |
|---|
| 973 | #if H_MV |
|---|
| 974 | m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j]; |
|---|
| 975 | #endif |
|---|
| 976 | } |
|---|
| 977 | } |
|---|
| 978 | for (i = 0; i < 2; i++) |
|---|
| 979 | { |
|---|
| 980 | for (j = 0; j < MAX_NUM_REF + 1; j++) |
|---|
| 981 | { |
|---|
| 982 | m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j]; |
|---|
| 983 | } |
|---|
| 984 | } |
|---|
| 985 | m_iDepth = pSrc->m_iDepth; |
|---|
| 986 | |
|---|
| 987 | // referenced slice |
|---|
| 988 | m_bRefenced = pSrc->m_bRefenced; |
|---|
| 989 | |
|---|
| 990 | // access channel |
|---|
| 991 | #if H_MV |
|---|
| 992 | m_pcVPS = pSrc->m_pcVPS; |
|---|
| 993 | #endif |
|---|
| 994 | m_pcSPS = pSrc->m_pcSPS; |
|---|
| 995 | m_pcPPS = pSrc->m_pcPPS; |
|---|
| 996 | m_pcRPS = pSrc->m_pcRPS; |
|---|
| 997 | m_iLastIDR = pSrc->m_iLastIDR; |
|---|
| 998 | |
|---|
| 999 | m_pcPic = pSrc->m_pcPic; |
|---|
| 1000 | |
|---|
| 1001 | m_colFromL0Flag = pSrc->m_colFromL0Flag; |
|---|
| 1002 | m_colRefIdx = pSrc->m_colRefIdx; |
|---|
| 1003 | #if SAO_CHROMA_LAMBDA |
|---|
| 1004 | m_dLambdaLuma = pSrc->m_dLambdaLuma; |
|---|
| 1005 | m_dLambdaChroma = pSrc->m_dLambdaChroma; |
|---|
| 1006 | #else |
|---|
| 1007 | m_dLambda = pSrc->m_dLambda; |
|---|
| 1008 | #endif |
|---|
| 1009 | for (i = 0; i < 2; i++) |
|---|
| 1010 | { |
|---|
| 1011 | for (j = 0; j < MAX_NUM_REF; j++) |
|---|
| 1012 | { |
|---|
| 1013 | for (k =0; k < MAX_NUM_REF; k++) |
|---|
| 1014 | { |
|---|
| 1015 | m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k]; |
|---|
| 1016 | } |
|---|
| 1017 | } |
|---|
| 1018 | } |
|---|
| 1019 | |
|---|
| 1020 | m_uiTLayer = pSrc->m_uiTLayer; |
|---|
| 1021 | m_bTLayerSwitchingFlag = pSrc->m_bTLayerSwitchingFlag; |
|---|
| 1022 | |
|---|
| 1023 | m_sliceMode = pSrc->m_sliceMode; |
|---|
| 1024 | m_sliceArgument = pSrc->m_sliceArgument; |
|---|
| 1025 | m_sliceCurStartCUAddr = pSrc->m_sliceCurStartCUAddr; |
|---|
| 1026 | m_sliceCurEndCUAddr = pSrc->m_sliceCurEndCUAddr; |
|---|
| 1027 | m_sliceIdx = pSrc->m_sliceIdx; |
|---|
| 1028 | m_sliceSegmentMode = pSrc->m_sliceSegmentMode; |
|---|
| 1029 | m_sliceSegmentArgument = pSrc->m_sliceSegmentArgument; |
|---|
| 1030 | m_sliceSegmentCurStartCUAddr = pSrc->m_sliceSegmentCurStartCUAddr; |
|---|
| 1031 | m_sliceSegmentCurEndCUAddr = pSrc->m_sliceSegmentCurEndCUAddr; |
|---|
| 1032 | m_nextSlice = pSrc->m_nextSlice; |
|---|
| 1033 | m_nextSliceSegment = pSrc->m_nextSliceSegment; |
|---|
| 1034 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 1035 | { |
|---|
| 1036 | for ( Int n=0 ; n<MAX_NUM_REF ; n++ ) |
|---|
| 1037 | { |
|---|
| 1038 | memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 ); |
|---|
| 1039 | } |
|---|
| 1040 | } |
|---|
| 1041 | m_saoEnabledFlag = pSrc->m_saoEnabledFlag; |
|---|
| 1042 | m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma; |
|---|
| 1043 | m_cabacInitFlag = pSrc->m_cabacInitFlag; |
|---|
| 1044 | m_numEntryPointOffsets = pSrc->m_numEntryPointOffsets; |
|---|
| 1045 | |
|---|
| 1046 | m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero; |
|---|
| 1047 | m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag; |
|---|
| 1048 | m_enableTMVPFlag = pSrc->m_enableTMVPFlag; |
|---|
| 1049 | m_maxNumMergeCand = pSrc->m_maxNumMergeCand; |
|---|
| 1050 | |
|---|
| 1051 | #if H_MV |
|---|
| 1052 | // Additional slice header syntax elements |
|---|
| 1053 | m_pocResetFlag = pSrc->m_pocResetFlag; |
|---|
| 1054 | m_discardableFlag = pSrc->m_discardableFlag; |
|---|
| 1055 | m_interLayerPredEnabledFlag = pSrc->m_interLayerPredEnabledFlag; |
|---|
| 1056 | m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1; |
|---|
| 1057 | |
|---|
| 1058 | for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ ) |
|---|
| 1059 | { |
|---|
| 1060 | m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; |
|---|
| 1061 | } |
|---|
| 1062 | #endif |
|---|
| 1063 | #if H_3D_IC |
|---|
| 1064 | m_bApplyIC = pSrc->m_bApplyIC; |
|---|
| 1065 | m_icSkipParseFlag = pSrc->m_icSkipParseFlag; |
|---|
| 1066 | #endif |
|---|
| 1067 | } |
|---|
| 1068 | |
|---|
| 1069 | Int TComSlice::m_prevTid0POC = 0; |
|---|
| 1070 | |
|---|
| 1071 | /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag. |
|---|
| 1072 | * \param uiTLayer Temporal layer ID of the current slice |
|---|
| 1073 | * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on |
|---|
| 1074 | * the SPS's temporal_id_nesting_flag and the parsed PPS. Then, current slice's temporal layer ID and |
|---|
| 1075 | * temporal_layer_switching_point_flag is set accordingly. |
|---|
| 1076 | */ |
|---|
| 1077 | Void TComSlice::setTLayerInfo( UInt uiTLayer ) |
|---|
| 1078 | { |
|---|
| 1079 | m_uiTLayer = uiTLayer; |
|---|
| 1080 | } |
|---|
| 1081 | |
|---|
| 1082 | /** Function for checking if this is a switching-point |
|---|
| 1083 | */ |
|---|
| 1084 | Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic ) |
|---|
| 1085 | { |
|---|
| 1086 | TComPic* rpcPic; |
|---|
| 1087 | // loop through all pictures in the reference picture buffer |
|---|
| 1088 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1089 | while ( iterPic != rcListPic.end()) |
|---|
| 1090 | { |
|---|
| 1091 | rpcPic = *(iterPic++); |
|---|
| 1092 | if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC()) |
|---|
| 1093 | { |
|---|
| 1094 | if(rpcPic->getTLayer() >= getTLayer()) |
|---|
| 1095 | { |
|---|
| 1096 | return false; |
|---|
| 1097 | } |
|---|
| 1098 | } |
|---|
| 1099 | } |
|---|
| 1100 | return true; |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | /** Function for checking if this is a STSA candidate |
|---|
| 1104 | */ |
|---|
| 1105 | Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ) |
|---|
| 1106 | { |
|---|
| 1107 | TComPic* rpcPic; |
|---|
| 1108 | |
|---|
| 1109 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1110 | while ( iterPic != rcListPic.end()) |
|---|
| 1111 | { |
|---|
| 1112 | rpcPic = *(iterPic++); |
|---|
| 1113 | if(rpcPic->getSlice(0)->isReferenced() && (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC()) |
|---|
| 1114 | { |
|---|
| 1115 | if(rpcPic->getTLayer() >= getTLayer()) |
|---|
| 1116 | { |
|---|
| 1117 | return false; |
|---|
| 1118 | } |
|---|
| 1119 | } |
|---|
| 1120 | } |
|---|
| 1121 | return true; |
|---|
| 1122 | } |
|---|
| 1123 | |
|---|
| 1124 | |
|---|
| 1125 | Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic) |
|---|
| 1126 | { |
|---|
| 1127 | TComPic* rpcPic; |
|---|
| 1128 | |
|---|
| 1129 | Int nalUnitType = this->getNalUnitType(); |
|---|
| 1130 | |
|---|
| 1131 | // When a picture is a leading picture, it shall be a RADL or RASL picture. |
|---|
| 1132 | if(this->getAssociatedIRAPPOC() > this->getPOC()) |
|---|
| 1133 | { |
|---|
| 1134 | // Do not check IRAP pictures since they may get a POC lower than their associated IRAP |
|---|
| 1135 | if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP || |
|---|
| 1136 | nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23) |
|---|
| 1137 | { |
|---|
| 1138 | assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1139 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || |
|---|
| 1140 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 1141 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); |
|---|
| 1142 | } |
|---|
| 1143 | } |
|---|
| 1144 | |
|---|
| 1145 | // When a picture is a trailing picture, it shall not be a RADL or RASL picture. |
|---|
| 1146 | if(this->getAssociatedIRAPPOC() < this->getPOC()) |
|---|
| 1147 | { |
|---|
| 1148 | assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N && |
|---|
| 1149 | nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R && |
|---|
| 1150 | nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N && |
|---|
| 1151 | nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R); |
|---|
| 1152 | } |
|---|
| 1153 | |
|---|
| 1154 | // No RASL pictures shall be present in the bitstream that are associated |
|---|
| 1155 | // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP. |
|---|
| 1156 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1157 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
|---|
| 1158 | { |
|---|
| 1159 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL && |
|---|
| 1160 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP); |
|---|
| 1161 | } |
|---|
| 1162 | |
|---|
| 1163 | // No RASL pictures shall be present in the bitstream that are associated with |
|---|
| 1164 | // an IDR picture. |
|---|
| 1165 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1166 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
|---|
| 1167 | { |
|---|
| 1168 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP && |
|---|
| 1169 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL); |
|---|
| 1170 | } |
|---|
| 1171 | |
|---|
| 1172 | // No RADL pictures shall be present in the bitstream that are associated with |
|---|
| 1173 | // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated |
|---|
| 1174 | // with an IDR picture having nal_unit_type equal to IDR_N_LP. |
|---|
| 1175 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 1176 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R) |
|---|
| 1177 | { |
|---|
| 1178 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP && |
|---|
| 1179 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP); |
|---|
| 1180 | } |
|---|
| 1181 | |
|---|
| 1182 | // loop through all pictures in the reference picture buffer |
|---|
| 1183 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1184 | while ( iterPic != rcListPic.end()) |
|---|
| 1185 | { |
|---|
| 1186 | rpcPic = *(iterPic++); |
|---|
| 1187 | if (rpcPic->getPOC() == this->getPOC()) |
|---|
| 1188 | { |
|---|
| 1189 | continue; |
|---|
| 1190 | } |
|---|
| 1191 | |
|---|
| 1192 | // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture |
|---|
| 1193 | // in decoding order shall precede the IRAP picture in output order. |
|---|
| 1194 | // (Note that any picture following in output order would be present in the DPB) |
|---|
| 1195 | if(rpcPic->getSlice(0)->getPicOutputFlag() == 1) |
|---|
| 1196 | { |
|---|
| 1197 | if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
|---|
| 1198 | nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
|---|
| 1199 | nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
|---|
| 1200 | nalUnitType == NAL_UNIT_CODED_SLICE_CRA || |
|---|
| 1201 | nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP || |
|---|
| 1202 | nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL) |
|---|
| 1203 | { |
|---|
| 1204 | assert(rpcPic->getPOC() < this->getPOC()); |
|---|
| 1205 | } |
|---|
| 1206 | } |
|---|
| 1207 | |
|---|
| 1208 | // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture |
|---|
| 1209 | // in decoding order shall precede any RADL picture associated with the IRAP |
|---|
| 1210 | // picture in output order. |
|---|
| 1211 | if(rpcPic->getSlice(0)->getPicOutputFlag() == 1) |
|---|
| 1212 | { |
|---|
| 1213 | if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 1214 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)) |
|---|
| 1215 | { |
|---|
| 1216 | // rpcPic precedes the IRAP in decoding order |
|---|
| 1217 | if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC()) |
|---|
| 1218 | { |
|---|
| 1219 | // rpcPic must not be the IRAP picture |
|---|
| 1220 | if(this->getAssociatedIRAPPOC() != rpcPic->getPOC()) |
|---|
| 1221 | { |
|---|
| 1222 | assert(rpcPic->getPOC() < this->getPOC()); |
|---|
| 1223 | } |
|---|
| 1224 | } |
|---|
| 1225 | } |
|---|
| 1226 | } |
|---|
| 1227 | |
|---|
| 1228 | // When a picture is a leading picture, it shall precede, in decoding order, |
|---|
| 1229 | // all trailing pictures that are associated with the same IRAP picture. |
|---|
| 1230 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1231 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || |
|---|
| 1232 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 1233 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R) |
|---|
| 1234 | { |
|---|
| 1235 | if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC()) |
|---|
| 1236 | { |
|---|
| 1237 | // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB |
|---|
| 1238 | // rpcPic would violate the constraint if it was a trailing picture |
|---|
| 1239 | assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC()); |
|---|
| 1240 | } |
|---|
| 1241 | } |
|---|
| 1242 | |
|---|
| 1243 | // Any RASL picture associated with a CRA or BLA picture shall precede any |
|---|
| 1244 | // RADL picture associated with the CRA or BLA picture in output order |
|---|
| 1245 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1246 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
|---|
| 1247 | { |
|---|
| 1248 | if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
|---|
| 1249 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
|---|
| 1250 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
|---|
| 1251 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA) && |
|---|
| 1252 | this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC()) |
|---|
| 1253 | { |
|---|
| 1254 | if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
|---|
| 1255 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R) |
|---|
| 1256 | { |
|---|
| 1257 | assert(rpcPic->getPOC() > this->getPOC()); |
|---|
| 1258 | } |
|---|
| 1259 | } |
|---|
| 1260 | } |
|---|
| 1261 | |
|---|
| 1262 | // Any RASL picture associated with a CRA picture shall follow, in output |
|---|
| 1263 | // order, any IRAP picture that precedes the CRA picture in decoding order. |
|---|
| 1264 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
|---|
| 1265 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
|---|
| 1266 | { |
|---|
| 1267 | if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA) |
|---|
| 1268 | { |
|---|
| 1269 | if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() && |
|---|
| 1270 | (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
|---|
| 1271 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
|---|
| 1272 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
|---|
| 1273 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || |
|---|
| 1274 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || |
|---|
| 1275 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
|---|
| 1276 | { |
|---|
| 1277 | assert(this->getPOC() > rpcPic->getSlice(0)->getPOC()); |
|---|
| 1278 | } |
|---|
| 1279 | } |
|---|
| 1280 | } |
|---|
| 1281 | } |
|---|
| 1282 | } |
|---|
| 1283 | |
|---|
| 1284 | |
|---|
| 1285 | |
|---|
| 1286 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
|---|
| 1287 | */ |
|---|
| 1288 | Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
|---|
| 1289 | { |
|---|
| 1290 | TComPic* rpcPic; |
|---|
| 1291 | Int i, isReference; |
|---|
| 1292 | |
|---|
| 1293 | checkLeadingPictureRestrictions(rcListPic); |
|---|
| 1294 | |
|---|
| 1295 | // loop through all pictures in the reference picture buffer |
|---|
| 1296 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1297 | while ( iterPic != rcListPic.end()) |
|---|
| 1298 | { |
|---|
| 1299 | rpcPic = *(iterPic++); |
|---|
| 1300 | |
|---|
| 1301 | if(!rpcPic->getSlice( 0 )->isReferenced()) |
|---|
| 1302 | { |
|---|
| 1303 | continue; |
|---|
| 1304 | } |
|---|
| 1305 | |
|---|
| 1306 | isReference = 0; |
|---|
| 1307 | // loop through all pictures in the Reference Picture Set |
|---|
| 1308 | // to see if the picture should be kept as reference picture |
|---|
| 1309 | for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++) |
|---|
| 1310 | { |
|---|
| 1311 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i)) |
|---|
| 1312 | { |
|---|
| 1313 | isReference = 1; |
|---|
| 1314 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 1315 | rpcPic->setIsLongTerm(0); |
|---|
| 1316 | } |
|---|
| 1317 | } |
|---|
| 1318 | for(;i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 1319 | { |
|---|
| 1320 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
|---|
| 1321 | { |
|---|
| 1322 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i)) |
|---|
| 1323 | { |
|---|
| 1324 | isReference = 1; |
|---|
| 1325 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 1326 | } |
|---|
| 1327 | } |
|---|
| 1328 | else |
|---|
| 1329 | { |
|---|
| 1330 | Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
|---|
| 1331 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1); |
|---|
| 1332 | Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1); |
|---|
| 1333 | if(rpcPic->getIsLongTerm() && curPoc == refPoc) |
|---|
| 1334 | { |
|---|
| 1335 | isReference = 1; |
|---|
| 1336 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 1337 | } |
|---|
| 1338 | } |
|---|
| 1339 | |
|---|
| 1340 | } |
|---|
| 1341 | // mark the picture as "unused for reference" if it is not in |
|---|
| 1342 | // the Reference Picture Set |
|---|
| 1343 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0) |
|---|
| 1344 | { |
|---|
| 1345 | rpcPic->getSlice( 0 )->setReferenced( false ); |
|---|
| 1346 | rpcPic->setUsedByCurr(0); |
|---|
| 1347 | rpcPic->setIsLongTerm(0); |
|---|
| 1348 | } |
|---|
| 1349 | //check that pictures of higher temporal layers are not used |
|---|
| 1350 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); |
|---|
| 1351 | //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture |
|---|
| 1352 | if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) |
|---|
| 1353 | { |
|---|
| 1354 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); |
|---|
| 1355 | } |
|---|
| 1356 | //check that pictures marked as temporal layer non-reference pictures are not used for reference |
|---|
| 1357 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer()) |
|---|
| 1358 | { |
|---|
| 1359 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false); |
|---|
| 1360 | } |
|---|
| 1361 | } |
|---|
| 1362 | } |
|---|
| 1363 | |
|---|
| 1364 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
|---|
| 1365 | */ |
|---|
| 1366 | Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess) |
|---|
| 1367 | { |
|---|
| 1368 | TComPic* rpcPic; |
|---|
| 1369 | Int i, isAvailable; |
|---|
| 1370 | Int atLeastOneLost = 0; |
|---|
| 1371 | Int atLeastOneRemoved = 0; |
|---|
| 1372 | Int iPocLost = 0; |
|---|
| 1373 | |
|---|
| 1374 | // loop through all long-term pictures in the Reference Picture Set |
|---|
| 1375 | // to see if the picture should be kept as reference picture |
|---|
| 1376 | for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 1377 | { |
|---|
| 1378 | isAvailable = 0; |
|---|
| 1379 | // loop through all pictures in the reference picture buffer |
|---|
| 1380 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1381 | while ( iterPic != rcListPic.end()) |
|---|
| 1382 | { |
|---|
| 1383 | rpcPic = *(iterPic++); |
|---|
| 1384 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
|---|
| 1385 | { |
|---|
| 1386 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1387 | { |
|---|
| 1388 | isAvailable = 1; |
|---|
| 1389 | } |
|---|
| 1390 | } |
|---|
| 1391 | else |
|---|
| 1392 | { |
|---|
| 1393 | Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
|---|
| 1394 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1); |
|---|
| 1395 | Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1); |
|---|
| 1396 | if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1397 | { |
|---|
| 1398 | isAvailable = 1; |
|---|
| 1399 | } |
|---|
| 1400 | } |
|---|
| 1401 | } |
|---|
| 1402 | // if there was no such long-term check the short terms |
|---|
| 1403 | if(!isAvailable) |
|---|
| 1404 | { |
|---|
| 1405 | iterPic = rcListPic.begin(); |
|---|
| 1406 | while ( iterPic != rcListPic.end()) |
|---|
| 1407 | { |
|---|
| 1408 | rpcPic = *(iterPic++); |
|---|
| 1409 | |
|---|
| 1410 | Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
|---|
| 1411 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC(); |
|---|
| 1412 | Int refPoc = pReferencePictureSet->getPOC(i); |
|---|
| 1413 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
|---|
| 1414 | { |
|---|
| 1415 | curPoc = curPoc & (pocCycle - 1); |
|---|
| 1416 | refPoc = refPoc & (pocCycle - 1); |
|---|
| 1417 | } |
|---|
| 1418 | |
|---|
| 1419 | if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc) |
|---|
| 1420 | { |
|---|
| 1421 | isAvailable = 1; |
|---|
| 1422 | rpcPic->setIsLongTerm(1); |
|---|
| 1423 | break; |
|---|
| 1424 | } |
|---|
| 1425 | } |
|---|
| 1426 | } |
|---|
| 1427 | // report that a picture is lost if it is in the Reference Picture Set |
|---|
| 1428 | // but not available as reference picture |
|---|
| 1429 | if(isAvailable == 0) |
|---|
| 1430 | { |
|---|
| 1431 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
|---|
| 1432 | { |
|---|
| 1433 | if(!pReferencePictureSet->getUsed(i) ) |
|---|
| 1434 | { |
|---|
| 1435 | if(printErrors) |
|---|
| 1436 | { |
|---|
| 1437 | printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1438 | } |
|---|
| 1439 | atLeastOneRemoved = 1; |
|---|
| 1440 | } |
|---|
| 1441 | else |
|---|
| 1442 | { |
|---|
| 1443 | if(printErrors) |
|---|
| 1444 | { |
|---|
| 1445 | printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1446 | } |
|---|
| 1447 | atLeastOneLost = 1; |
|---|
| 1448 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
|---|
| 1449 | } |
|---|
| 1450 | } |
|---|
| 1451 | } |
|---|
| 1452 | } |
|---|
| 1453 | // loop through all short-term pictures in the Reference Picture Set |
|---|
| 1454 | // to see if the picture should be kept as reference picture |
|---|
| 1455 | for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++) |
|---|
| 1456 | { |
|---|
| 1457 | isAvailable = 0; |
|---|
| 1458 | // loop through all pictures in the reference picture buffer |
|---|
| 1459 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1460 | while ( iterPic != rcListPic.end()) |
|---|
| 1461 | { |
|---|
| 1462 | rpcPic = *(iterPic++); |
|---|
| 1463 | |
|---|
| 1464 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1465 | { |
|---|
| 1466 | isAvailable = 1; |
|---|
| 1467 | } |
|---|
| 1468 | } |
|---|
| 1469 | // report that a picture is lost if it is in the Reference Picture Set |
|---|
| 1470 | // but not available as reference picture |
|---|
| 1471 | if(isAvailable == 0) |
|---|
| 1472 | { |
|---|
| 1473 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
|---|
| 1474 | { |
|---|
| 1475 | if(!pReferencePictureSet->getUsed(i) ) |
|---|
| 1476 | { |
|---|
| 1477 | if(printErrors) |
|---|
| 1478 | { |
|---|
| 1479 | printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1480 | } |
|---|
| 1481 | atLeastOneRemoved = 1; |
|---|
| 1482 | } |
|---|
| 1483 | else |
|---|
| 1484 | { |
|---|
| 1485 | if(printErrors) |
|---|
| 1486 | { |
|---|
| 1487 | printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1488 | } |
|---|
| 1489 | atLeastOneLost = 1; |
|---|
| 1490 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
|---|
| 1491 | } |
|---|
| 1492 | } |
|---|
| 1493 | } |
|---|
| 1494 | } |
|---|
| 1495 | if(atLeastOneLost) |
|---|
| 1496 | { |
|---|
| 1497 | return iPocLost+1; |
|---|
| 1498 | } |
|---|
| 1499 | if(atLeastOneRemoved) |
|---|
| 1500 | { |
|---|
| 1501 | return -2; |
|---|
| 1502 | } |
|---|
| 1503 | else |
|---|
| 1504 | { |
|---|
| 1505 | return 0; |
|---|
| 1506 | } |
|---|
| 1507 | } |
|---|
| 1508 | |
|---|
| 1509 | /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set |
|---|
| 1510 | */ |
|---|
| 1511 | #if FIX1071 |
|---|
| 1512 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP) |
|---|
| 1513 | #else |
|---|
| 1514 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
|---|
| 1515 | #endif |
|---|
| 1516 | { |
|---|
| 1517 | TComPic* rpcPic; |
|---|
| 1518 | Int i, j; |
|---|
| 1519 | Int k = 0; |
|---|
| 1520 | Int nrOfNegativePictures = 0; |
|---|
| 1521 | Int nrOfPositivePictures = 0; |
|---|
| 1522 | TComReferencePictureSet* pcRPS = this->getLocalRPS(); |
|---|
| 1523 | |
|---|
| 1524 | // loop through all pictures in the Reference Picture Set |
|---|
| 1525 | for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 1526 | { |
|---|
| 1527 | j = 0; |
|---|
| 1528 | // loop through all pictures in the reference picture buffer |
|---|
| 1529 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1530 | while ( iterPic != rcListPic.end()) |
|---|
| 1531 | { |
|---|
| 1532 | j++; |
|---|
| 1533 | rpcPic = *(iterPic++); |
|---|
| 1534 | |
|---|
| 1535 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1536 | { |
|---|
| 1537 | // This picture exists as a reference picture |
|---|
| 1538 | // and should be added to the explicit Reference Picture Set |
|---|
| 1539 | pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1540 | #if FIX1071 |
|---|
| 1541 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP)); |
|---|
| 1542 | #else |
|---|
| 1543 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i)); |
|---|
| 1544 | #endif |
|---|
| 1545 | if(pcRPS->getDeltaPOC(k) < 0) |
|---|
| 1546 | { |
|---|
| 1547 | nrOfNegativePictures++; |
|---|
| 1548 | } |
|---|
| 1549 | else |
|---|
| 1550 | { |
|---|
| 1551 | nrOfPositivePictures++; |
|---|
| 1552 | } |
|---|
| 1553 | k++; |
|---|
| 1554 | } |
|---|
| 1555 | } |
|---|
| 1556 | } |
|---|
| 1557 | pcRPS->setNumberOfNegativePictures(nrOfNegativePictures); |
|---|
| 1558 | pcRPS->setNumberOfPositivePictures(nrOfPositivePictures); |
|---|
| 1559 | pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures); |
|---|
| 1560 | // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the |
|---|
| 1561 | // inter RPS prediction with. Here we just use the reference used by pReferencePictureSet. |
|---|
| 1562 | // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled. |
|---|
| 1563 | if (!pReferencePictureSet->getInterRPSPrediction()) |
|---|
| 1564 | { |
|---|
| 1565 | pcRPS->setInterRPSPrediction(false); |
|---|
| 1566 | pcRPS->setNumRefIdc(0); |
|---|
| 1567 | } |
|---|
| 1568 | else |
|---|
| 1569 | { |
|---|
| 1570 | Int rIdx = this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1; |
|---|
| 1571 | Int deltaRPS = pReferencePictureSet->getDeltaRPS(); |
|---|
| 1572 | TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx); |
|---|
| 1573 | Int iRefPics = pcRefRPS->getNumberOfPictures(); |
|---|
| 1574 | Int iNewIdc=0; |
|---|
| 1575 | for(i=0; i<= iRefPics; i++) |
|---|
| 1576 | { |
|---|
| 1577 | Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0); // check if the reference abs POC is >= 0 |
|---|
| 1578 | Int iRefIdc = 0; |
|---|
| 1579 | for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the pictures in the new RPS |
|---|
| 1580 | { |
|---|
| 1581 | if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j)) |
|---|
| 1582 | { |
|---|
| 1583 | if (pcRPS->getUsed(j)) |
|---|
| 1584 | { |
|---|
| 1585 | iRefIdc = 1; |
|---|
| 1586 | } |
|---|
| 1587 | else |
|---|
| 1588 | { |
|---|
| 1589 | iRefIdc = 2; |
|---|
| 1590 | } |
|---|
| 1591 | } |
|---|
| 1592 | } |
|---|
| 1593 | pcRPS->setRefIdc(i, iRefIdc); |
|---|
| 1594 | iNewIdc++; |
|---|
| 1595 | } |
|---|
| 1596 | pcRPS->setInterRPSPrediction(true); |
|---|
| 1597 | pcRPS->setNumRefIdc(iNewIdc); |
|---|
| 1598 | pcRPS->setDeltaRPS(deltaRPS); |
|---|
| 1599 | pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx()); |
|---|
| 1600 | } |
|---|
| 1601 | |
|---|
| 1602 | this->setRPS(pcRPS); |
|---|
| 1603 | this->setRPSidx(-1); |
|---|
| 1604 | } |
|---|
| 1605 | |
|---|
| 1606 | /** get AC and DC values for weighted pred |
|---|
| 1607 | * \param *wp |
|---|
| 1608 | * \returns Void |
|---|
| 1609 | */ |
|---|
| 1610 | Void TComSlice::getWpAcDcParam(wpACDCParam *&wp) |
|---|
| 1611 | { |
|---|
| 1612 | wp = m_weightACDCParam; |
|---|
| 1613 | } |
|---|
| 1614 | |
|---|
| 1615 | /** init AC and DC values for weighted pred |
|---|
| 1616 | * \returns Void |
|---|
| 1617 | */ |
|---|
| 1618 | Void TComSlice::initWpAcDcParam() |
|---|
| 1619 | { |
|---|
| 1620 | for(Int iComp = 0; iComp < 3; iComp++ ) |
|---|
| 1621 | { |
|---|
| 1622 | m_weightACDCParam[iComp].iAC = 0; |
|---|
| 1623 | m_weightACDCParam[iComp].iDC = 0; |
|---|
| 1624 | } |
|---|
| 1625 | } |
|---|
| 1626 | |
|---|
| 1627 | /** get WP tables for weighted pred |
|---|
| 1628 | * \param RefPicList |
|---|
| 1629 | * \param iRefIdx |
|---|
| 1630 | * \param *&wpScalingParam |
|---|
| 1631 | * \returns Void |
|---|
| 1632 | */ |
|---|
| 1633 | Void TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp ) |
|---|
| 1634 | { |
|---|
| 1635 | wp = m_weightPredTable[e][iRefIdx]; |
|---|
| 1636 | } |
|---|
| 1637 | |
|---|
| 1638 | /** reset Default WP tables settings : no weight. |
|---|
| 1639 | * \param wpScalingParam |
|---|
| 1640 | * \returns Void |
|---|
| 1641 | */ |
|---|
| 1642 | Void TComSlice::resetWpScaling() |
|---|
| 1643 | { |
|---|
| 1644 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 1645 | { |
|---|
| 1646 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
|---|
| 1647 | { |
|---|
| 1648 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
|---|
| 1649 | { |
|---|
| 1650 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
|---|
| 1651 | pwp->bPresentFlag = false; |
|---|
| 1652 | pwp->uiLog2WeightDenom = 0; |
|---|
| 1653 | pwp->uiLog2WeightDenom = 0; |
|---|
| 1654 | pwp->iWeight = 1; |
|---|
| 1655 | pwp->iOffset = 0; |
|---|
| 1656 | } |
|---|
| 1657 | } |
|---|
| 1658 | } |
|---|
| 1659 | } |
|---|
| 1660 | |
|---|
| 1661 | /** init WP table |
|---|
| 1662 | * \returns Void |
|---|
| 1663 | */ |
|---|
| 1664 | Void TComSlice::initWpScaling() |
|---|
| 1665 | { |
|---|
| 1666 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 1667 | { |
|---|
| 1668 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
|---|
| 1669 | { |
|---|
| 1670 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
|---|
| 1671 | { |
|---|
| 1672 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
|---|
| 1673 | if ( !pwp->bPresentFlag ) |
|---|
| 1674 | { |
|---|
| 1675 | // Inferring values not present : |
|---|
| 1676 | pwp->iWeight = (1 << pwp->uiLog2WeightDenom); |
|---|
| 1677 | pwp->iOffset = 0; |
|---|
| 1678 | } |
|---|
| 1679 | |
|---|
| 1680 | pwp->w = pwp->iWeight; |
|---|
| 1681 | Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; |
|---|
| 1682 | pwp->o = pwp->iOffset << (bitDepth-8); |
|---|
| 1683 | pwp->shift = pwp->uiLog2WeightDenom; |
|---|
| 1684 | pwp->round = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0); |
|---|
| 1685 | } |
|---|
| 1686 | } |
|---|
| 1687 | } |
|---|
| 1688 | } |
|---|
| 1689 | |
|---|
| 1690 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1691 | // Video parameter set (VPS) |
|---|
| 1692 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1693 | TComVPS::TComVPS() |
|---|
| 1694 | : m_VPSId ( 0) |
|---|
| 1695 | , m_uiMaxTLayers ( 1) |
|---|
| 1696 | #if H_MV |
|---|
| 1697 | , m_uiMaxLayersMinus1 ( 0) |
|---|
| 1698 | #else |
|---|
| 1699 | , m_uiMaxLayers ( 1) |
|---|
| 1700 | #endif |
|---|
| 1701 | , m_bTemporalIdNestingFlag (false) |
|---|
| 1702 | , m_numHrdParameters ( 0) |
|---|
| 1703 | #if H_MV |
|---|
| 1704 | , m_maxLayerId ( 0) |
|---|
| 1705 | #else |
|---|
| 1706 | , m_maxNuhReservedZeroLayerId ( 0) |
|---|
| 1707 | #endif |
|---|
| 1708 | , m_hrdParameters (NULL) |
|---|
| 1709 | , m_hrdOpSetIdx (NULL) |
|---|
| 1710 | , m_cprmsPresentFlag (NULL) |
|---|
| 1711 | #if H_MV |
|---|
| 1712 | , m_vpsVUI ( NULL ) |
|---|
| 1713 | #endif |
|---|
| 1714 | { |
|---|
| 1715 | for( Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 1716 | { |
|---|
| 1717 | m_numReorderPics[i] = 0; |
|---|
| 1718 | m_uiMaxDecPicBuffering[i] = 1; |
|---|
| 1719 | m_uiMaxLatencyIncrease[i] = 0; |
|---|
| 1720 | } |
|---|
| 1721 | #if H_MV |
|---|
| 1722 | for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ ) |
|---|
| 1723 | { |
|---|
| 1724 | for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ ) |
|---|
| 1725 | { |
|---|
| 1726 | m_layerIdIncludedFlag[lsIdx][layerId] = false; |
|---|
| 1727 | } |
|---|
| 1728 | } |
|---|
| 1729 | |
|---|
| 1730 | m_vpsNumberLayerSetsMinus1 = -1; |
|---|
| 1731 | m_vpsNumProfileTierLevelMinus1 = -1; |
|---|
| 1732 | |
|---|
| 1733 | for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++) |
|---|
| 1734 | { |
|---|
| 1735 | m_profileRefMinus1[ i ] = -1; |
|---|
| 1736 | } |
|---|
| 1737 | |
|---|
| 1738 | m_moreOutputLayerSetsThanDefaultFlag = false; |
|---|
| 1739 | m_numAddOutputLayerSetsMinus1 = -1; |
|---|
| 1740 | m_defaultOneTargetOutputLayerFlag = false; |
|---|
| 1741 | |
|---|
| 1742 | for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++) |
|---|
| 1743 | { |
|---|
| 1744 | m_outputLayerSetIdxMinus1[i] = -1; |
|---|
| 1745 | m_profileLevelTierIdx[i] = 0; |
|---|
| 1746 | for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++) |
|---|
| 1747 | { |
|---|
| 1748 | m_outputLayerFlag[i][j] = false; |
|---|
| 1749 | } |
|---|
| 1750 | } |
|---|
| 1751 | |
|---|
| 1752 | m_maxOneActiveRefLayerFlag = false; |
|---|
| 1753 | m_directDepTypeLenMinus2 = 0; |
|---|
| 1754 | |
|---|
| 1755 | |
|---|
| 1756 | m_avcBaseLayerFlag = false; |
|---|
| 1757 | m_vpsVuiOffset = 0; |
|---|
| 1758 | m_splittingFlag = false; |
|---|
| 1759 | |
|---|
| 1760 | for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ ) |
|---|
| 1761 | { |
|---|
| 1762 | m_scalabilityMaskFlag[i] = false; |
|---|
| 1763 | m_dimensionIdLen [i] = -1; |
|---|
| 1764 | } |
|---|
| 1765 | |
|---|
| 1766 | m_vpsNuhLayerIdPresentFlag = false; |
|---|
| 1767 | |
|---|
| 1768 | for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ ) |
|---|
| 1769 | { |
|---|
| 1770 | m_vpsProfilePresentFlag [i] = false; |
|---|
| 1771 | m_profileRefMinus1[i] = 0; |
|---|
| 1772 | m_outputLayerSetIdxMinus1 [i] = 0; |
|---|
| 1773 | for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ ) |
|---|
| 1774 | { |
|---|
| 1775 | m_outputLayerFlag[i][j] = false; |
|---|
| 1776 | } |
|---|
| 1777 | } |
|---|
| 1778 | |
|---|
| 1779 | for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ ) |
|---|
| 1780 | { |
|---|
| 1781 | m_layerIdInVps[i] = (i == 0 ) ? 0 : -1; |
|---|
| 1782 | } |
|---|
| 1783 | |
|---|
| 1784 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 1785 | { |
|---|
| 1786 | m_layerIdInNuh [i] = ( i == 0 ) ? 0 : -1; |
|---|
| 1787 | m_numDirectRefLayers[i] = 0; |
|---|
| 1788 | m_maxTidIlRefPicPlus1[i] = 7; |
|---|
| 1789 | m_vpsRepFormatIdx [i] = 0; |
|---|
| 1790 | m_repFormat [i] = NULL; |
|---|
| 1791 | m_viewIdVal [i] = 0; |
|---|
| 1792 | |
|---|
| 1793 | #if H_3D |
|---|
| 1794 | m_viewIndex [i] = -1; |
|---|
| 1795 | m_vpsDepthModesFlag [i] = false; |
|---|
| 1796 | #if H_3D_DIM_DLT |
|---|
| 1797 | m_bUseDLTFlag [i] = false; |
|---|
| 1798 | |
|---|
| 1799 | // allocate some memory and initialize with default mapping |
|---|
| 1800 | m_iNumDepthmapValues[i] = ((1 << g_bitDepthY)-1)+1; |
|---|
| 1801 | m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]); |
|---|
| 1802 | |
|---|
| 1803 | m_iDepthValue2Idx[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
|---|
| 1804 | m_iIdx2DepthValue[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
|---|
| 1805 | |
|---|
| 1806 | //default mapping |
|---|
| 1807 | for (Int d=0; d<m_iNumDepthmapValues[i]; d++) |
|---|
| 1808 | { |
|---|
| 1809 | m_iDepthValue2Idx[i][d] = d; |
|---|
| 1810 | m_iIdx2DepthValue[i][d] = d; |
|---|
| 1811 | } |
|---|
| 1812 | #endif |
|---|
| 1813 | #if H_3D |
|---|
| 1814 | m_ivMvScalingFlag = true; |
|---|
| 1815 | #endif |
|---|
| 1816 | #endif |
|---|
| 1817 | |
|---|
| 1818 | for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) |
|---|
| 1819 | { |
|---|
| 1820 | m_directDependencyFlag[i][j] = false; |
|---|
| 1821 | m_directDependencyType[i][j] = -1; |
|---|
| 1822 | m_refLayerId[i][j] = -1; |
|---|
| 1823 | } |
|---|
| 1824 | |
|---|
| 1825 | for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ ) |
|---|
| 1826 | { |
|---|
| 1827 | m_dimensionId[i][j] = 0; |
|---|
| 1828 | } |
|---|
| 1829 | #if H_3D_ARP |
|---|
| 1830 | m_uiUseAdvResPred[i] = 0; |
|---|
| 1831 | m_uiARPStepNum[i] = 1; |
|---|
| 1832 | #endif |
|---|
| 1833 | } |
|---|
| 1834 | m_vpsVUI = new TComVPSVUI; |
|---|
| 1835 | #if H_3D |
|---|
| 1836 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 1837 | { |
|---|
| 1838 | #if H_3D_IV_MERGE |
|---|
| 1839 | m_ivMvPredFlag [ i ] = false; |
|---|
| 1840 | #endif |
|---|
| 1841 | #if H_3D_VSP |
|---|
| 1842 | m_viewSynthesisPredFlag[ i ] = false; |
|---|
| 1843 | #endif |
|---|
| 1844 | #if H_3D_NBDV_REF |
|---|
| 1845 | m_depthRefinementFlag [ i ] = false; |
|---|
| 1846 | #endif |
|---|
| 1847 | #if H_3D_INTER_SDC |
|---|
| 1848 | m_bInterSDCFlag [ i ] = false; |
|---|
| 1849 | #endif |
|---|
| 1850 | #if SEC_MPI_ENABLING_MERGE_F0150 |
|---|
| 1851 | m_bMPIFlag [ i ] = false; |
|---|
| 1852 | #endif |
|---|
| 1853 | } |
|---|
| 1854 | #endif |
|---|
| 1855 | #endif |
|---|
| 1856 | } |
|---|
| 1857 | |
|---|
| 1858 | TComVPS::~TComVPS() |
|---|
| 1859 | { |
|---|
| 1860 | if( m_hrdParameters != NULL ) delete[] m_hrdParameters; |
|---|
| 1861 | if( m_hrdOpSetIdx != NULL ) delete[] m_hrdOpSetIdx; |
|---|
| 1862 | if( m_cprmsPresentFlag != NULL ) delete[] m_cprmsPresentFlag; |
|---|
| 1863 | #if H_MV |
|---|
| 1864 | if ( m_vpsVUI != NULL ) delete m_vpsVUI; |
|---|
| 1865 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 1866 | { |
|---|
| 1867 | if (m_repFormat[ i ] != NULL ) delete m_repFormat[ i ]; |
|---|
| 1868 | #if H_3D_DIM_DLT |
|---|
| 1869 | if ( m_iDepthValue2Idx[i] != 0 ) |
|---|
| 1870 | { |
|---|
| 1871 | xFree( m_iDepthValue2Idx[i] ); |
|---|
| 1872 | m_iDepthValue2Idx[i] = 0; |
|---|
| 1873 | } |
|---|
| 1874 | |
|---|
| 1875 | if ( m_iIdx2DepthValue[i] != 0 ) |
|---|
| 1876 | { |
|---|
| 1877 | xFree( m_iIdx2DepthValue[i] ); |
|---|
| 1878 | m_iIdx2DepthValue[i] = 0; |
|---|
| 1879 | } |
|---|
| 1880 | #endif |
|---|
| 1881 | } |
|---|
| 1882 | #endif |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| 1885 | #if H_3D_DIM_DLT |
|---|
| 1886 | Void TComVPS::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues) |
|---|
| 1887 | { |
|---|
| 1888 | if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only |
|---|
| 1889 | return; |
|---|
| 1890 | |
|---|
| 1891 | // copy idx2DepthValue to internal array |
|---|
| 1892 | memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt)); |
|---|
| 1893 | |
|---|
| 1894 | UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1); |
|---|
| 1895 | for(Int p=0; p<=uiMaxDepthValue; p++) |
|---|
| 1896 | { |
|---|
| 1897 | Int iIdxDown = 0; |
|---|
| 1898 | Int iIdxUp = iNumDepthValues-1; |
|---|
| 1899 | Bool bFound = false; |
|---|
| 1900 | |
|---|
| 1901 | // iterate over indices to find lower closest depth |
|---|
| 1902 | Int i = 1; |
|---|
| 1903 | while(!bFound && i<iNumDepthValues) |
|---|
| 1904 | { |
|---|
| 1905 | if( m_iIdx2DepthValue[layerIdInVps][i] > p ) |
|---|
| 1906 | { |
|---|
| 1907 | iIdxDown = i-1; |
|---|
| 1908 | bFound = true; |
|---|
| 1909 | } |
|---|
| 1910 | |
|---|
| 1911 | i++; |
|---|
| 1912 | } |
|---|
| 1913 | // iterate over indices to find upper closest depth |
|---|
| 1914 | i = iNumDepthValues-2; |
|---|
| 1915 | bFound = false; |
|---|
| 1916 | while(!bFound && i>=0) |
|---|
| 1917 | { |
|---|
| 1918 | if( m_iIdx2DepthValue[layerIdInVps][i] < p ) |
|---|
| 1919 | { |
|---|
| 1920 | iIdxUp = i+1; |
|---|
| 1921 | bFound = true; |
|---|
| 1922 | } |
|---|
| 1923 | |
|---|
| 1924 | i--; |
|---|
| 1925 | } |
|---|
| 1926 | |
|---|
| 1927 | // assert monotony |
|---|
| 1928 | assert(iIdxDown<=iIdxUp); |
|---|
| 1929 | |
|---|
| 1930 | // assign closer depth value/idx |
|---|
| 1931 | if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) ) |
|---|
| 1932 | { |
|---|
| 1933 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown; |
|---|
| 1934 | } |
|---|
| 1935 | else |
|---|
| 1936 | { |
|---|
| 1937 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp; |
|---|
| 1938 | } |
|---|
| 1939 | |
|---|
| 1940 | } |
|---|
| 1941 | |
|---|
| 1942 | // update DLT variables |
|---|
| 1943 | m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues; |
|---|
| 1944 | m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]); |
|---|
| 1945 | } |
|---|
| 1946 | #endif |
|---|
| 1947 | |
|---|
| 1948 | #if H_MV |
|---|
| 1949 | |
|---|
| 1950 | Bool TComVPS::checkVPSExtensionSyntax() |
|---|
| 1951 | { |
|---|
| 1952 | for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ ) |
|---|
| 1953 | { |
|---|
| 1954 | // check layer_id_in_nuh constraint |
|---|
| 1955 | assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) ); |
|---|
| 1956 | } |
|---|
| 1957 | return true; |
|---|
| 1958 | } |
|---|
| 1959 | |
|---|
| 1960 | Int TComVPS::getNumScalabilityTypes() |
|---|
| 1961 | { |
|---|
| 1962 | return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) ); |
|---|
| 1963 | } |
|---|
| 1964 | |
|---|
| 1965 | Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) |
|---|
| 1966 | { |
|---|
| 1967 | assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); |
|---|
| 1968 | assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) ); |
|---|
| 1969 | Int scalIdx = 0; |
|---|
| 1970 | for( Int curScalType = 0; curScalType < scalType; curScalType++ ) |
|---|
| 1971 | { |
|---|
| 1972 | scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 ); |
|---|
| 1973 | |
|---|
| 1974 | } |
|---|
| 1975 | |
|---|
| 1976 | return scalIdx; |
|---|
| 1977 | } |
|---|
| 1978 | Void TComVPS::setScalabilityMaskFlag( UInt val ) |
|---|
| 1979 | { |
|---|
| 1980 | for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) |
|---|
| 1981 | { |
|---|
| 1982 | setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 ); |
|---|
| 1983 | } |
|---|
| 1984 | } |
|---|
| 1985 | |
|---|
| 1986 | Void TComVPS::setRefLayers() |
|---|
| 1987 | { |
|---|
| 1988 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
|---|
| 1989 | { |
|---|
| 1990 | Int iNuhLId = getLayerIdInNuh( i ); |
|---|
| 1991 | m_numDirectRefLayers[ iNuhLId ] = 0; |
|---|
| 1992 | for( Int j = 0; j < i; j++ ) |
|---|
| 1993 | { |
|---|
| 1994 | if( getDirectDependencyFlag(i , j) ) |
|---|
| 1995 | { |
|---|
| 1996 | m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j ); |
|---|
| 1997 | } |
|---|
| 1998 | } |
|---|
| 1999 | } |
|---|
| 2000 | } |
|---|
| 2001 | |
|---|
| 2002 | Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx ) |
|---|
| 2003 | { |
|---|
| 2004 | assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] ); |
|---|
| 2005 | Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ]; |
|---|
| 2006 | assert ( refLayerIdInNuh >= 0 ); |
|---|
| 2007 | return refLayerIdInNuh; |
|---|
| 2008 | } |
|---|
| 2009 | |
|---|
| 2010 | Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) |
|---|
| 2011 | { |
|---|
| 2012 | return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0; |
|---|
| 2013 | } |
|---|
| 2014 | |
|---|
| 2015 | #if H_3D |
|---|
| 2016 | Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) |
|---|
| 2017 | { |
|---|
| 2018 | Int foundLayerIdinNuh = -1; |
|---|
| 2019 | |
|---|
| 2020 | for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ ) |
|---|
| 2021 | { |
|---|
| 2022 | Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); |
|---|
| 2023 | if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) ) ) |
|---|
| 2024 | { |
|---|
| 2025 | foundLayerIdinNuh = layerIdInNuh; |
|---|
| 2026 | break; |
|---|
| 2027 | } |
|---|
| 2028 | } |
|---|
| 2029 | assert( foundLayerIdinNuh != -1 ); |
|---|
| 2030 | |
|---|
| 2031 | return foundLayerIdinNuh; |
|---|
| 2032 | } |
|---|
| 2033 | #endif // H_3D |
|---|
| 2034 | |
|---|
| 2035 | |
|---|
| 2036 | Int TComVPS::xGetDimBitOffset( Int j ) |
|---|
| 2037 | { |
|---|
| 2038 | Int dimBitOffset = 0; |
|---|
| 2039 | if ( getSplittingFlag() && j == getNumScalabilityTypes() ) |
|---|
| 2040 | { |
|---|
| 2041 | dimBitOffset = 6; |
|---|
| 2042 | } |
|---|
| 2043 | else |
|---|
| 2044 | { |
|---|
| 2045 | for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++) |
|---|
| 2046 | { |
|---|
| 2047 | dimBitOffset += getDimensionIdLen( dimIdx ); |
|---|
| 2048 | } |
|---|
| 2049 | } |
|---|
| 2050 | return dimBitOffset; |
|---|
| 2051 | } |
|---|
| 2052 | |
|---|
| 2053 | Int TComVPS::inferDimensionId( Int i, Int j ) |
|---|
| 2054 | { |
|---|
| 2055 | return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); |
|---|
| 2056 | } |
|---|
| 2057 | |
|---|
| 2058 | Int TComVPS::inferLastDimsionIdLenMinus1() |
|---|
| 2059 | { |
|---|
| 2060 | return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); |
|---|
| 2061 | } |
|---|
| 2062 | |
|---|
| 2063 | Int TComVPS::getNumLayersInIdList( Int lsIdx ) |
|---|
| 2064 | { |
|---|
| 2065 | assert( lsIdx >= 0 ); |
|---|
| 2066 | assert( lsIdx <= getVpsNumLayerSetsMinus1() ); |
|---|
| 2067 | Int numLayersInIdList = 0; |
|---|
| 2068 | for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ ) |
|---|
| 2069 | { |
|---|
| 2070 | numLayersInIdList += ( getLayerIdIncludedFlag( lsIdx, layerId ) ); |
|---|
| 2071 | } |
|---|
| 2072 | return numLayersInIdList; |
|---|
| 2073 | } |
|---|
| 2074 | Int TComVPS::getNumViews() |
|---|
| 2075 | { |
|---|
| 2076 | Int numViews = 1; |
|---|
| 2077 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
|---|
| 2078 | { |
|---|
| 2079 | Int lId = getLayerIdInNuh( i ); |
|---|
| 2080 | if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) ) |
|---|
| 2081 | { |
|---|
| 2082 | numViews++; |
|---|
| 2083 | } |
|---|
| 2084 | } |
|---|
| 2085 | |
|---|
| 2086 | return numViews; |
|---|
| 2087 | } |
|---|
| 2088 | |
|---|
| 2089 | Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ ) |
|---|
| 2090 | { |
|---|
| 2091 | assert( depth < 65 ); |
|---|
| 2092 | Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); |
|---|
| 2093 | |
|---|
| 2094 | for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ ) |
|---|
| 2095 | { |
|---|
| 2096 | if ( getDirectDependencyFlag( depLayeridInVps, i ) ) |
|---|
| 2097 | { |
|---|
| 2098 | dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); |
|---|
| 2099 | } |
|---|
| 2100 | } |
|---|
| 2101 | return dependentFlag; |
|---|
| 2102 | } |
|---|
| 2103 | #endif // H_MV |
|---|
| 2104 | |
|---|
| 2105 | // ------------------------------------------------------------------------------------------------ |
|---|
| 2106 | // Sequence parameter set (SPS) |
|---|
| 2107 | // ------------------------------------------------------------------------------------------------ |
|---|
| 2108 | |
|---|
| 2109 | TComSPS::TComSPS() |
|---|
| 2110 | : m_SPSId ( 0) |
|---|
| 2111 | , m_VPSId ( 0) |
|---|
| 2112 | , m_chromaFormatIdc (CHROMA_420) |
|---|
| 2113 | , m_uiMaxTLayers ( 1) |
|---|
| 2114 | // Structure |
|---|
| 2115 | , m_picWidthInLumaSamples (352) |
|---|
| 2116 | , m_picHeightInLumaSamples (288) |
|---|
| 2117 | , m_log2MinCodingBlockSize ( 0) |
|---|
| 2118 | , m_log2DiffMaxMinCodingBlockSize (0) |
|---|
| 2119 | , m_uiMaxCUWidth ( 32) |
|---|
| 2120 | , m_uiMaxCUHeight ( 32) |
|---|
| 2121 | , m_uiMaxCUDepth ( 3) |
|---|
| 2122 | , m_bLongTermRefsPresent (false) |
|---|
| 2123 | , m_uiQuadtreeTULog2MaxSize ( 0) |
|---|
| 2124 | , m_uiQuadtreeTULog2MinSize ( 0) |
|---|
| 2125 | , m_uiQuadtreeTUMaxDepthInter ( 0) |
|---|
| 2126 | , m_uiQuadtreeTUMaxDepthIntra ( 0) |
|---|
| 2127 | // Tool list |
|---|
| 2128 | , m_usePCM (false) |
|---|
| 2129 | , m_pcmLog2MaxSize ( 5) |
|---|
| 2130 | , m_uiPCMLog2MinSize ( 7) |
|---|
| 2131 | #if H_3D_QTLPC |
|---|
| 2132 | , m_bUseQTL (false) |
|---|
| 2133 | , m_bUsePC (false) |
|---|
| 2134 | #endif |
|---|
| 2135 | , m_bitDepthY ( 8) |
|---|
| 2136 | , m_bitDepthC ( 8) |
|---|
| 2137 | , m_qpBDOffsetY ( 0) |
|---|
| 2138 | , m_qpBDOffsetC ( 0) |
|---|
| 2139 | , m_useLossless (false) |
|---|
| 2140 | , m_uiPCMBitDepthLuma ( 8) |
|---|
| 2141 | , m_uiPCMBitDepthChroma ( 8) |
|---|
| 2142 | , m_bPCMFilterDisableFlag (false) |
|---|
| 2143 | , m_uiBitsForPOC ( 8) |
|---|
| 2144 | , m_numLongTermRefPicSPS ( 0) |
|---|
| 2145 | , m_uiMaxTrSize ( 32) |
|---|
| 2146 | , m_bUseSAO (false) |
|---|
| 2147 | , m_bTemporalIdNestingFlag (false) |
|---|
| 2148 | , m_scalingListEnabledFlag (false) |
|---|
| 2149 | , m_useStrongIntraSmoothing (false) |
|---|
| 2150 | , m_vuiParametersPresentFlag (false) |
|---|
| 2151 | , m_vuiParameters () |
|---|
| 2152 | #if H_MV |
|---|
| 2153 | , m_pcVPS ( NULL ) |
|---|
| 2154 | , m_spsInferScalingListFlag ( false ) |
|---|
| 2155 | , m_spsScalingListRefLayerId ( 0 ) |
|---|
| 2156 | , m_updateRepFormatFlag ( true ) |
|---|
| 2157 | , m_interViewMvVertConstraintFlag (false) |
|---|
| 2158 | #endif |
|---|
| 2159 | #if H_3D |
|---|
| 2160 | , m_bCamParInSliceHeader (false) |
|---|
| 2161 | #endif |
|---|
| 2162 | { |
|---|
| 2163 | for ( Int i = 0; i < MAX_TLAYER; i++ ) |
|---|
| 2164 | { |
|---|
| 2165 | m_uiMaxLatencyIncrease[i] = 0; |
|---|
| 2166 | m_uiMaxDecPicBuffering[i] = 1; |
|---|
| 2167 | m_numReorderPics[i] = 0; |
|---|
| 2168 | } |
|---|
| 2169 | m_scalingList = new TComScalingList; |
|---|
| 2170 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
|---|
| 2171 | ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag)); |
|---|
| 2172 | } |
|---|
| 2173 | |
|---|
| 2174 | TComSPS::~TComSPS() |
|---|
| 2175 | { |
|---|
| 2176 | delete m_scalingList; |
|---|
| 2177 | m_RPSList.destroy(); |
|---|
| 2178 | } |
|---|
| 2179 | |
|---|
| 2180 | Void TComSPS::createRPSList( Int numRPS ) |
|---|
| 2181 | { |
|---|
| 2182 | m_RPSList.destroy(); |
|---|
| 2183 | m_RPSList.create(numRPS); |
|---|
| 2184 | } |
|---|
| 2185 | |
|---|
| 2186 | Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess ) |
|---|
| 2187 | { |
|---|
| 2188 | if( !getVuiParametersPresentFlag() ) |
|---|
| 2189 | { |
|---|
| 2190 | return; |
|---|
| 2191 | } |
|---|
| 2192 | |
|---|
| 2193 | TComVUI *vui = getVuiParameters(); |
|---|
| 2194 | TComHRD *hrd = vui->getHrdParameters(); |
|---|
| 2195 | |
|---|
| 2196 | TimingInfo *timingInfo = vui->getTimingInfo(); |
|---|
| 2197 | timingInfo->setTimingInfoPresentFlag( true ); |
|---|
| 2198 | switch( frameRate ) |
|---|
| 2199 | { |
|---|
| 2200 | case 24: |
|---|
| 2201 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 2202 | break; |
|---|
| 2203 | case 25: |
|---|
| 2204 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 2205 | break; |
|---|
| 2206 | case 30: |
|---|
| 2207 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 2208 | break; |
|---|
| 2209 | case 50: |
|---|
| 2210 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 2211 | break; |
|---|
| 2212 | case 60: |
|---|
| 2213 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 2214 | break; |
|---|
| 2215 | default: |
|---|
| 2216 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
|---|
| 2217 | break; |
|---|
| 2218 | } |
|---|
| 2219 | |
|---|
| 2220 | Bool rateCnt = ( bitRate > 0 ); |
|---|
| 2221 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
|---|
| 2222 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
|---|
| 2223 | |
|---|
| 2224 | hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) ); |
|---|
| 2225 | |
|---|
| 2226 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
|---|
| 2227 | { |
|---|
| 2228 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
|---|
| 2229 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
|---|
| 2230 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
|---|
| 2231 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
|---|
| 2232 | } |
|---|
| 2233 | else |
|---|
| 2234 | { |
|---|
| 2235 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
|---|
| 2236 | } |
|---|
| 2237 | |
|---|
| 2238 | hrd->setBitRateScale( 4 ); // in units of 2~( 6 + 4 ) = 1,024 bps |
|---|
| 2239 | hrd->setCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
|---|
| 2240 | hrd->setDuCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
|---|
| 2241 | |
|---|
| 2242 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
|---|
| 2243 | if( randomAccess ) |
|---|
| 2244 | { |
|---|
| 2245 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
|---|
| 2246 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
|---|
| 2247 | } |
|---|
| 2248 | else |
|---|
| 2249 | { |
|---|
| 2250 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
|---|
| 2251 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
|---|
| 2252 | } |
|---|
| 2253 | |
|---|
| 2254 | /* |
|---|
| 2255 | Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported. |
|---|
| 2256 | */ |
|---|
| 2257 | Int i, j; |
|---|
| 2258 | UInt birateValue, cpbSizeValue; |
|---|
| 2259 | UInt ducpbSizeValue; |
|---|
| 2260 | UInt duBitRateValue = 0; |
|---|
| 2261 | |
|---|
| 2262 | for( i = 0; i < MAX_TLAYER; i ++ ) |
|---|
| 2263 | { |
|---|
| 2264 | hrd->setFixedPicRateFlag( i, 1 ); |
|---|
| 2265 | hrd->setPicDurationInTcMinus1( i, 0 ); |
|---|
| 2266 | hrd->setLowDelayHrdFlag( i, 0 ); |
|---|
| 2267 | hrd->setCpbCntMinus1( i, 0 ); |
|---|
| 2268 | |
|---|
| 2269 | birateValue = bitRate; |
|---|
| 2270 | cpbSizeValue = bitRate; // 1 second |
|---|
| 2271 | ducpbSizeValue = bitRate/numDU; |
|---|
| 2272 | duBitRateValue = bitRate; |
|---|
| 2273 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
|---|
| 2274 | { |
|---|
| 2275 | hrd->setBitRateValueMinus1( i, j, 0, ( birateValue - 1 ) ); |
|---|
| 2276 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
|---|
| 2277 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) ); |
|---|
| 2278 | hrd->setCbrFlag( i, j, 0, ( j == 0 ) ); |
|---|
| 2279 | |
|---|
| 2280 | hrd->setBitRateValueMinus1( i, j, 1, ( birateValue - 1) ); |
|---|
| 2281 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
|---|
| 2282 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) ); |
|---|
| 2283 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
|---|
| 2284 | hrd->setCbrFlag( i, j, 1, ( j == 0 ) ); |
|---|
| 2285 | } |
|---|
| 2286 | } |
|---|
| 2287 | } |
|---|
| 2288 | const Int TComSPS::m_winUnitX[]={1,2,2,1}; |
|---|
| 2289 | const Int TComSPS::m_winUnitY[]={1,2,1,1}; |
|---|
| 2290 | |
|---|
| 2291 | TComPPS::TComPPS() |
|---|
| 2292 | : m_PPSId (0) |
|---|
| 2293 | , m_SPSId (0) |
|---|
| 2294 | , m_picInitQPMinus26 (0) |
|---|
| 2295 | , m_useDQP (false) |
|---|
| 2296 | , m_bConstrainedIntraPred (false) |
|---|
| 2297 | , m_bSliceChromaQpFlag (false) |
|---|
| 2298 | , m_pcSPS (NULL) |
|---|
| 2299 | , m_uiMaxCuDQPDepth (0) |
|---|
| 2300 | , m_uiMinCuDQPSize (0) |
|---|
| 2301 | , m_chromaCbQpOffset (0) |
|---|
| 2302 | , m_chromaCrQpOffset (0) |
|---|
| 2303 | , m_numRefIdxL0DefaultActive (1) |
|---|
| 2304 | , m_numRefIdxL1DefaultActive (1) |
|---|
| 2305 | , m_TransquantBypassEnableFlag (false) |
|---|
| 2306 | , m_useTransformSkip (false) |
|---|
| 2307 | , m_dependentSliceSegmentsEnabledFlag (false) |
|---|
| 2308 | , m_tilesEnabledFlag (false) |
|---|
| 2309 | , m_entropyCodingSyncEnabledFlag (false) |
|---|
| 2310 | , m_loopFilterAcrossTilesEnabledFlag (true) |
|---|
| 2311 | , m_uniformSpacingFlag (0) |
|---|
| 2312 | , m_iNumColumnsMinus1 (0) |
|---|
| 2313 | , m_puiColumnWidth (NULL) |
|---|
| 2314 | , m_iNumRowsMinus1 (0) |
|---|
| 2315 | , m_puiRowHeight (NULL) |
|---|
| 2316 | , m_iNumSubstreams (1) |
|---|
| 2317 | , m_signHideFlag(0) |
|---|
| 2318 | , m_cabacInitPresentFlag (false) |
|---|
| 2319 | , m_encCABACTableIdx (I_SLICE) |
|---|
| 2320 | , m_sliceHeaderExtensionPresentFlag (false) |
|---|
| 2321 | , m_loopFilterAcrossSlicesEnabledFlag (false) |
|---|
| 2322 | , m_listsModificationPresentFlag( 0) |
|---|
| 2323 | , m_numExtraSliceHeaderBits(0) |
|---|
| 2324 | #if H_MV |
|---|
| 2325 | , m_ppsInferScalingListFlag(false) |
|---|
| 2326 | , m_ppsScalingListRefLayerId(0) |
|---|
| 2327 | #endif |
|---|
| 2328 | { |
|---|
| 2329 | m_scalingList = new TComScalingList; |
|---|
| 2330 | } |
|---|
| 2331 | |
|---|
| 2332 | TComPPS::~TComPPS() |
|---|
| 2333 | { |
|---|
| 2334 | if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
|---|
| 2335 | { |
|---|
| 2336 | if (m_puiColumnWidth) delete [] m_puiColumnWidth; |
|---|
| 2337 | m_puiColumnWidth = NULL; |
|---|
| 2338 | } |
|---|
| 2339 | if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
|---|
| 2340 | { |
|---|
| 2341 | if (m_puiRowHeight) delete [] m_puiRowHeight; |
|---|
| 2342 | m_puiRowHeight = NULL; |
|---|
| 2343 | } |
|---|
| 2344 | delete m_scalingList; |
|---|
| 2345 | } |
|---|
| 2346 | |
|---|
| 2347 | #if H_MV |
|---|
| 2348 | Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr ) |
|---|
| 2349 | { |
|---|
| 2350 | if ( layerIdCurr > 0 ) |
|---|
| 2351 | { |
|---|
| 2352 | TComRepFormat* repFormat = vps->getRepFormat( vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); |
|---|
| 2353 | if ( !getUpdateRepFormatFlag() ) |
|---|
| 2354 | { |
|---|
| 2355 | setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() ); |
|---|
| 2356 | //// ToDo: add when supported: |
|---|
| 2357 | // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ; |
|---|
| 2358 | |
|---|
| 2359 | setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples() ); |
|---|
| 2360 | setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); |
|---|
| 2361 | |
|---|
| 2362 | setBitDepthY ( repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
|---|
| 2363 | setQpBDOffsetY ( (Int) (6*( getBitDepthY() - 8 )) ); |
|---|
| 2364 | |
|---|
| 2365 | setBitDepthC ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
|---|
| 2366 | setQpBDOffsetC ( (Int) (6* ( getBitDepthC() -8 ) ) ); |
|---|
| 2367 | } |
|---|
| 2368 | else |
|---|
| 2369 | { |
|---|
| 2370 | assert( getChromaFormatIdc() <= repFormat->getChromaFormatVpsIdc() ); |
|---|
| 2371 | //// ToDo: add when supported: |
|---|
| 2372 | // assert( getSeperateColourPlaneFlag() <= repFormat->getSeparateColourPlaneVpsFlag() ) ; |
|---|
| 2373 | |
|---|
| 2374 | assert( getPicWidthInLumaSamples() <= repFormat->getPicWidthVpsInLumaSamples() ); |
|---|
| 2375 | assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples() ); |
|---|
| 2376 | |
|---|
| 2377 | assert( getBitDepthY() <= repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
|---|
| 2378 | assert( getBitDepthC() <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
|---|
| 2379 | } |
|---|
| 2380 | } |
|---|
| 2381 | |
|---|
| 2382 | // Set conformance window |
|---|
| 2383 | Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ; |
|---|
| 2384 | getConformanceWindow().scaleOffsets( scal ); |
|---|
| 2385 | getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal ); |
|---|
| 2386 | } |
|---|
| 2387 | |
|---|
| 2388 | Void TComSPS::inferScalingList( TComSPS* spsSrc ) |
|---|
| 2389 | { |
|---|
| 2390 | if ( getSpsInferScalingListFlag() ) |
|---|
| 2391 | { |
|---|
| 2392 | assert( spsSrc != NULL ); |
|---|
| 2393 | assert( !spsSrc->getSpsInferScalingListFlag() ); |
|---|
| 2394 | getScalingList()->inferFrom( spsSrc->getScalingList() ); |
|---|
| 2395 | } |
|---|
| 2396 | } |
|---|
| 2397 | #endif |
|---|
| 2398 | #if H_3D |
|---|
| 2399 | Void |
|---|
| 2400 | TComSPS::initCamParaSPS( UInt uiViewIndex, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset ) |
|---|
| 2401 | { |
|---|
| 2402 | AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); |
|---|
| 2403 | |
|---|
| 2404 | m_uiCamParPrecision = ( uiViewIndex ? uiCamParPrecision : 0 ); |
|---|
| 2405 | m_bCamParInSliceHeader = ( uiViewIndex ? bCamParSlice : false ); |
|---|
| 2406 | ::memset( m_aaiCodedScale, 0x00, sizeof( m_aaiCodedScale ) ); |
|---|
| 2407 | ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) ); |
|---|
| 2408 | |
|---|
| 2409 | if( !m_bCamParInSliceHeader ) |
|---|
| 2410 | { |
|---|
| 2411 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ ) |
|---|
| 2412 | { |
|---|
| 2413 | m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ uiViewIndex ]; |
|---|
| 2414 | m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [ uiViewIndex ][ uiBaseViewIndex ]; |
|---|
| 2415 | m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ uiViewIndex ]; |
|---|
| 2416 | m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[ uiViewIndex ][ uiBaseViewIndex ]; |
|---|
| 2417 | } |
|---|
| 2418 | } |
|---|
| 2419 | } |
|---|
| 2420 | #endif |
|---|
| 2421 | TComReferencePictureSet::TComReferencePictureSet() |
|---|
| 2422 | : m_numberOfPictures (0) |
|---|
| 2423 | , m_numberOfNegativePictures (0) |
|---|
| 2424 | , m_numberOfPositivePictures (0) |
|---|
| 2425 | , m_numberOfLongtermPictures (0) |
|---|
| 2426 | , m_interRPSPrediction (0) |
|---|
| 2427 | , m_deltaRIdxMinus1 (0) |
|---|
| 2428 | , m_deltaRPS (0) |
|---|
| 2429 | , m_numRefIdc (0) |
|---|
| 2430 | { |
|---|
| 2431 | ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) ); |
|---|
| 2432 | ::memset( m_POC, 0, sizeof(m_POC) ); |
|---|
| 2433 | ::memset( m_used, 0, sizeof(m_used) ); |
|---|
| 2434 | ::memset( m_refIdc, 0, sizeof(m_refIdc) ); |
|---|
| 2435 | } |
|---|
| 2436 | |
|---|
| 2437 | TComReferencePictureSet::~TComReferencePictureSet() |
|---|
| 2438 | { |
|---|
| 2439 | } |
|---|
| 2440 | |
|---|
| 2441 | Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used) |
|---|
| 2442 | { |
|---|
| 2443 | m_used[bufferNum] = used; |
|---|
| 2444 | } |
|---|
| 2445 | |
|---|
| 2446 | Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC) |
|---|
| 2447 | { |
|---|
| 2448 | m_deltaPOC[bufferNum] = deltaPOC; |
|---|
| 2449 | } |
|---|
| 2450 | |
|---|
| 2451 | Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures) |
|---|
| 2452 | { |
|---|
| 2453 | m_numberOfPictures = numberOfPictures; |
|---|
| 2454 | } |
|---|
| 2455 | |
|---|
| 2456 | Int TComReferencePictureSet::getUsed(Int bufferNum) |
|---|
| 2457 | { |
|---|
| 2458 | return m_used[bufferNum]; |
|---|
| 2459 | } |
|---|
| 2460 | |
|---|
| 2461 | Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) |
|---|
| 2462 | { |
|---|
| 2463 | return m_deltaPOC[bufferNum]; |
|---|
| 2464 | } |
|---|
| 2465 | |
|---|
| 2466 | Int TComReferencePictureSet::getNumberOfPictures() |
|---|
| 2467 | { |
|---|
| 2468 | return m_numberOfPictures; |
|---|
| 2469 | } |
|---|
| 2470 | |
|---|
| 2471 | Int TComReferencePictureSet::getPOC(Int bufferNum) |
|---|
| 2472 | { |
|---|
| 2473 | return m_POC[bufferNum]; |
|---|
| 2474 | } |
|---|
| 2475 | |
|---|
| 2476 | Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC) |
|---|
| 2477 | { |
|---|
| 2478 | m_POC[bufferNum] = POC; |
|---|
| 2479 | } |
|---|
| 2480 | |
|---|
| 2481 | Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) |
|---|
| 2482 | { |
|---|
| 2483 | return m_bCheckLTMSB[bufferNum]; |
|---|
| 2484 | } |
|---|
| 2485 | |
|---|
| 2486 | Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b) |
|---|
| 2487 | { |
|---|
| 2488 | m_bCheckLTMSB[bufferNum] = b; |
|---|
| 2489 | } |
|---|
| 2490 | |
|---|
| 2491 | /** set the reference idc value at uiBufferNum entry to the value of iRefIdc |
|---|
| 2492 | * \param uiBufferNum |
|---|
| 2493 | * \param iRefIdc |
|---|
| 2494 | * \returns Void |
|---|
| 2495 | */ |
|---|
| 2496 | Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc) |
|---|
| 2497 | { |
|---|
| 2498 | m_refIdc[bufferNum] = refIdc; |
|---|
| 2499 | } |
|---|
| 2500 | |
|---|
| 2501 | /** get the reference idc value at uiBufferNum |
|---|
| 2502 | * \param uiBufferNum |
|---|
| 2503 | * \returns Int |
|---|
| 2504 | */ |
|---|
| 2505 | Int TComReferencePictureSet::getRefIdc(Int bufferNum) |
|---|
| 2506 | { |
|---|
| 2507 | return m_refIdc[bufferNum]; |
|---|
| 2508 | } |
|---|
| 2509 | |
|---|
| 2510 | /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values. |
|---|
| 2511 | * deltaPOC values are sorted with -ve values before the +ve values. -ve values are in decreasing order. |
|---|
| 2512 | * +ve values are in increasing order. |
|---|
| 2513 | * \returns Void |
|---|
| 2514 | */ |
|---|
| 2515 | Void TComReferencePictureSet::sortDeltaPOC() |
|---|
| 2516 | { |
|---|
| 2517 | // sort in increasing order (smallest first) |
|---|
| 2518 | for(Int j=1; j < getNumberOfPictures(); j++) |
|---|
| 2519 | { |
|---|
| 2520 | Int deltaPOC = getDeltaPOC(j); |
|---|
| 2521 | Bool used = getUsed(j); |
|---|
| 2522 | for (Int k=j-1; k >= 0; k--) |
|---|
| 2523 | { |
|---|
| 2524 | Int temp = getDeltaPOC(k); |
|---|
| 2525 | if (deltaPOC < temp) |
|---|
| 2526 | { |
|---|
| 2527 | setDeltaPOC(k+1, temp); |
|---|
| 2528 | setUsed(k+1, getUsed(k)); |
|---|
| 2529 | setDeltaPOC(k, deltaPOC); |
|---|
| 2530 | setUsed(k, used); |
|---|
| 2531 | } |
|---|
| 2532 | } |
|---|
| 2533 | } |
|---|
| 2534 | // flip the negative values to largest first |
|---|
| 2535 | Int numNegPics = getNumberOfNegativePictures(); |
|---|
| 2536 | for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--) |
|---|
| 2537 | { |
|---|
| 2538 | Int deltaPOC = getDeltaPOC(j); |
|---|
| 2539 | Bool used = getUsed(j); |
|---|
| 2540 | setDeltaPOC(j, getDeltaPOC(k)); |
|---|
| 2541 | setUsed(j, getUsed(k)); |
|---|
| 2542 | setDeltaPOC(k, deltaPOC); |
|---|
| 2543 | setUsed(k, used); |
|---|
| 2544 | } |
|---|
| 2545 | } |
|---|
| 2546 | |
|---|
| 2547 | /** Prints the deltaPOC and RefIdc (if available) values in the RPS. |
|---|
| 2548 | * A "*" is added to the deltaPOC value if it is Used bu current. |
|---|
| 2549 | * \returns Void |
|---|
| 2550 | */ |
|---|
| 2551 | Void TComReferencePictureSet::printDeltaPOC() |
|---|
| 2552 | { |
|---|
| 2553 | printf("DeltaPOC = { "); |
|---|
| 2554 | for(Int j=0; j < getNumberOfPictures(); j++) |
|---|
| 2555 | { |
|---|
| 2556 | printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":""); |
|---|
| 2557 | } |
|---|
| 2558 | if (getInterRPSPrediction()) |
|---|
| 2559 | { |
|---|
| 2560 | printf("}, RefIdc = { "); |
|---|
| 2561 | for(Int j=0; j < getNumRefIdc(); j++) |
|---|
| 2562 | { |
|---|
| 2563 | printf("%d ", getRefIdc(j)); |
|---|
| 2564 | } |
|---|
| 2565 | } |
|---|
| 2566 | printf("}\n"); |
|---|
| 2567 | } |
|---|
| 2568 | |
|---|
| 2569 | TComRPSList::TComRPSList() |
|---|
| 2570 | :m_referencePictureSets (NULL) |
|---|
| 2571 | { |
|---|
| 2572 | } |
|---|
| 2573 | |
|---|
| 2574 | TComRPSList::~TComRPSList() |
|---|
| 2575 | { |
|---|
| 2576 | } |
|---|
| 2577 | |
|---|
| 2578 | Void TComRPSList::create( Int numberOfReferencePictureSets) |
|---|
| 2579 | { |
|---|
| 2580 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
|---|
| 2581 | m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets]; |
|---|
| 2582 | } |
|---|
| 2583 | |
|---|
| 2584 | Void TComRPSList::destroy() |
|---|
| 2585 | { |
|---|
| 2586 | if (m_referencePictureSets) |
|---|
| 2587 | { |
|---|
| 2588 | delete [] m_referencePictureSets; |
|---|
| 2589 | } |
|---|
| 2590 | m_numberOfReferencePictureSets = 0; |
|---|
| 2591 | m_referencePictureSets = NULL; |
|---|
| 2592 | } |
|---|
| 2593 | |
|---|
| 2594 | |
|---|
| 2595 | |
|---|
| 2596 | TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum) |
|---|
| 2597 | { |
|---|
| 2598 | return &m_referencePictureSets[referencePictureSetNum]; |
|---|
| 2599 | } |
|---|
| 2600 | |
|---|
| 2601 | Int TComRPSList::getNumberOfReferencePictureSets() |
|---|
| 2602 | { |
|---|
| 2603 | return m_numberOfReferencePictureSets; |
|---|
| 2604 | } |
|---|
| 2605 | |
|---|
| 2606 | Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets) |
|---|
| 2607 | { |
|---|
| 2608 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
|---|
| 2609 | } |
|---|
| 2610 | |
|---|
| 2611 | TComRefPicListModification::TComRefPicListModification() |
|---|
| 2612 | : m_bRefPicListModificationFlagL0 (false) |
|---|
| 2613 | , m_bRefPicListModificationFlagL1 (false) |
|---|
| 2614 | { |
|---|
| 2615 | ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) ); |
|---|
| 2616 | ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) ); |
|---|
| 2617 | } |
|---|
| 2618 | |
|---|
| 2619 | TComRefPicListModification::~TComRefPicListModification() |
|---|
| 2620 | { |
|---|
| 2621 | } |
|---|
| 2622 | |
|---|
| 2623 | TComScalingList::TComScalingList() |
|---|
| 2624 | { |
|---|
| 2625 | init(); |
|---|
| 2626 | } |
|---|
| 2627 | TComScalingList::~TComScalingList() |
|---|
| 2628 | { |
|---|
| 2629 | destroy(); |
|---|
| 2630 | } |
|---|
| 2631 | |
|---|
| 2632 | /** set default quantization matrix to array |
|---|
| 2633 | */ |
|---|
| 2634 | Void TComSlice::setDefaultScalingList() |
|---|
| 2635 | { |
|---|
| 2636 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 2637 | { |
|---|
| 2638 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
|---|
| 2639 | { |
|---|
| 2640 | getScalingList()->processDefaultMarix(sizeId, listId); |
|---|
| 2641 | } |
|---|
| 2642 | } |
|---|
| 2643 | } |
|---|
| 2644 | /** check if use default quantization matrix |
|---|
| 2645 | * \returns true if use default quantization matrix in all size |
|---|
| 2646 | */ |
|---|
| 2647 | Bool TComSlice::checkDefaultScalingList() |
|---|
| 2648 | { |
|---|
| 2649 | UInt defaultCounter=0; |
|---|
| 2650 | |
|---|
| 2651 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 2652 | { |
|---|
| 2653 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
|---|
| 2654 | { |
|---|
| 2655 | if( !memcmp(getScalingList()->getScalingListAddress(sizeId,listId), getScalingList()->getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix |
|---|
| 2656 | && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value |
|---|
| 2657 | { |
|---|
| 2658 | defaultCounter++; |
|---|
| 2659 | } |
|---|
| 2660 | } |
|---|
| 2661 | } |
|---|
| 2662 | return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32 |
|---|
| 2663 | } |
|---|
| 2664 | |
|---|
| 2665 | #if H_MV |
|---|
| 2666 | Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 ) |
|---|
| 2667 | { |
|---|
| 2668 | refPicSetInterLayer0.clear(); |
|---|
| 2669 | refPicSetInterLayer1.clear(); |
|---|
| 2670 | |
|---|
| 2671 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
|---|
| 2672 | { |
|---|
| 2673 | Int layerIdRef = getRefPicLayerId( i ); |
|---|
| 2674 | TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; |
|---|
| 2675 | assert ( picRef != 0 ); |
|---|
| 2676 | |
|---|
| 2677 | picRef->getPicYuvRec()->extendPicBorder(); |
|---|
| 2678 | picRef->setIsLongTerm( true ); |
|---|
| 2679 | picRef->getSlice(0)->setReferenced( true ); |
|---|
| 2680 | |
|---|
| 2681 | Int viewIdCur = getVPS()->getViewId( getLayerId() ); |
|---|
| 2682 | Int viewIdZero = getVPS()->getViewId( 0 ); |
|---|
| 2683 | Int viewIdRef = getVPS()->getViewId( layerIdRef ); |
|---|
| 2684 | |
|---|
| 2685 | if ( ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) ) |
|---|
| 2686 | { |
|---|
| 2687 | refPicSetInterLayer0.push_back( picRef ); |
|---|
| 2688 | } |
|---|
| 2689 | else |
|---|
| 2690 | { |
|---|
| 2691 | refPicSetInterLayer1.push_back( picRef ); |
|---|
| 2692 | } |
|---|
| 2693 | // Consider to check here: |
|---|
| 2694 | // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. " |
|---|
| 2695 | } |
|---|
| 2696 | } |
|---|
| 2697 | |
|---|
| 2698 | Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 ) |
|---|
| 2699 | { |
|---|
| 2700 | // Mark as shortterm |
|---|
| 2701 | for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) |
|---|
| 2702 | { |
|---|
| 2703 | refPicSetInterLayer0[i]->setIsLongTerm( false ); |
|---|
| 2704 | } |
|---|
| 2705 | |
|---|
| 2706 | for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) |
|---|
| 2707 | { |
|---|
| 2708 | refPicSetInterLayer1[i]->setIsLongTerm( false ); |
|---|
| 2709 | } |
|---|
| 2710 | |
|---|
| 2711 | } |
|---|
| 2712 | Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc ) |
|---|
| 2713 | { |
|---|
| 2714 | // Fill targetDecLayerIdSet with all layers if empty. |
|---|
| 2715 | if (targetDecLayerIdSet.size() == 0 ) |
|---|
| 2716 | { |
|---|
| 2717 | for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ ) |
|---|
| 2718 | { |
|---|
| 2719 | targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); |
|---|
| 2720 | } |
|---|
| 2721 | } |
|---|
| 2722 | |
|---|
| 2723 | Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); |
|---|
| 2724 | Int latestDecIdx; |
|---|
| 2725 | for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++) |
|---|
| 2726 | { |
|---|
| 2727 | if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId ) |
|---|
| 2728 | { |
|---|
| 2729 | break; |
|---|
| 2730 | } |
|---|
| 2731 | } |
|---|
| 2732 | |
|---|
| 2733 | for( Int i = 0; i <= latestDecIdx; i++ ) |
|---|
| 2734 | { |
|---|
| 2735 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) ) |
|---|
| 2736 | { |
|---|
| 2737 | TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); |
|---|
| 2738 | if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) |
|---|
| 2739 | { |
|---|
| 2740 | Bool remainingInterLayerReferencesFlag = false; |
|---|
| 2741 | for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ ) |
|---|
| 2742 | { |
|---|
| 2743 | TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); |
|---|
| 2744 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) ) |
|---|
| 2745 | { |
|---|
| 2746 | for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ ) |
|---|
| 2747 | { |
|---|
| 2748 | if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ], k ) ) |
|---|
| 2749 | { |
|---|
| 2750 | remainingInterLayerReferencesFlag = true; |
|---|
| 2751 | } |
|---|
| 2752 | } |
|---|
| 2753 | } |
|---|
| 2754 | } |
|---|
| 2755 | if( !remainingInterLayerReferencesFlag ) |
|---|
| 2756 | { |
|---|
| 2757 | pcPic->getSlice(0)->setReferenced( false ); |
|---|
| 2758 | } |
|---|
| 2759 | } |
|---|
| 2760 | } |
|---|
| 2761 | } |
|---|
| 2762 | } |
|---|
| 2763 | |
|---|
| 2764 | Void TComSlice::printRefPicList() |
|---|
| 2765 | { |
|---|
| 2766 | for ( Int li = 0; li < 2; li++) |
|---|
| 2767 | { |
|---|
| 2768 | std::cout << std::endl << "RefPicListL" << li << ":" << std::endl; |
|---|
| 2769 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++) |
|---|
| 2770 | { |
|---|
| 2771 | if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true ); |
|---|
| 2772 | |
|---|
| 2773 | m_apcRefPicList[li][rIdx]->print( false ); |
|---|
| 2774 | } |
|---|
| 2775 | } |
|---|
| 2776 | } |
|---|
| 2777 | |
|---|
| 2778 | Void TComSlice::markCurrPic( TComPic* currPic ) |
|---|
| 2779 | { |
|---|
| 2780 | if ( !currPic->getSlice(0)->getDiscardableFlag() ) |
|---|
| 2781 | { |
|---|
| 2782 | currPic->getSlice(0)->setReferenced( true ) ; |
|---|
| 2783 | currPic->setIsLongTerm( false ); |
|---|
| 2784 | } |
|---|
| 2785 | else |
|---|
| 2786 | { |
|---|
| 2787 | currPic->getSlice(0)->setReferenced( false ) ; |
|---|
| 2788 | } |
|---|
| 2789 | } |
|---|
| 2790 | |
|---|
| 2791 | Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 ) |
|---|
| 2792 | { |
|---|
| 2793 | m_refPicSetInterLayer0 = refPicSetInterLayer0; |
|---|
| 2794 | m_refPicSetInterLayer1 = refPicSetInterLayer1; |
|---|
| 2795 | } |
|---|
| 2796 | |
|---|
| 2797 | TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) |
|---|
| 2798 | { |
|---|
| 2799 | assert ( setIdc == 0 || setIdc == 1); |
|---|
| 2800 | std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1); |
|---|
| 2801 | assert( refPicSetInterLayer != 0 ); |
|---|
| 2802 | |
|---|
| 2803 | TComPic* pcPic = NULL; |
|---|
| 2804 | for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ ) |
|---|
| 2805 | { |
|---|
| 2806 | if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId ) |
|---|
| 2807 | { |
|---|
| 2808 | pcPic = (*refPicSetInterLayer)[ i ]; |
|---|
| 2809 | } |
|---|
| 2810 | } |
|---|
| 2811 | |
|---|
| 2812 | assert(pcPic != NULL); |
|---|
| 2813 | return pcPic; |
|---|
| 2814 | } |
|---|
| 2815 | Int TComSlice::getNumActiveRefLayerPics() |
|---|
| 2816 | { |
|---|
| 2817 | Int numActiveRefLayerPics; |
|---|
| 2818 | |
|---|
| 2819 | if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) == 0 ) |
|---|
| 2820 | { |
|---|
| 2821 | numActiveRefLayerPics = 0; |
|---|
| 2822 | } |
|---|
| 2823 | else if (getVPS()->getAllRefLayersActiveFlag() ) |
|---|
| 2824 | { |
|---|
| 2825 | numActiveRefLayerPics = getVPS()->getNumDirectRefLayers( getLayerId() ); |
|---|
| 2826 | } |
|---|
| 2827 | else if ( !getInterLayerPredEnabledFlag() ) |
|---|
| 2828 | { |
|---|
| 2829 | numActiveRefLayerPics = 0; |
|---|
| 2830 | } |
|---|
| 2831 | else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 ) |
|---|
| 2832 | { |
|---|
| 2833 | numActiveRefLayerPics = 1; |
|---|
| 2834 | } |
|---|
| 2835 | else |
|---|
| 2836 | { |
|---|
| 2837 | numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; |
|---|
| 2838 | } |
|---|
| 2839 | return numActiveRefLayerPics; |
|---|
| 2840 | } |
|---|
| 2841 | |
|---|
| 2842 | Int TComSlice::getRefPicLayerId( Int i ) |
|---|
| 2843 | { |
|---|
| 2844 | return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) ); |
|---|
| 2845 | } |
|---|
| 2846 | |
|---|
| 2847 | #if H_3D_ARP |
|---|
| 2848 | #if SHARP_ARP_REF_CHECK_F0105 |
|---|
| 2849 | Void TComSlice::setARPStepNum( TComPicLists*ivPicLists ) |
|---|
| 2850 | #else |
|---|
| 2851 | Void TComSlice::setARPStepNum() |
|---|
| 2852 | #endif |
|---|
| 2853 | { |
|---|
| 2854 | #if SHARP_ARP_REF_CHECK_F0105 |
|---|
| 2855 | Bool tempRefPicInListsFlag = false; |
|---|
| 2856 | #else |
|---|
| 2857 | Bool bAllIvRef = true; |
|---|
| 2858 | #endif |
|---|
| 2859 | #if QC_MTK_INTERVIEW_ARP_F0123_F0108 |
|---|
| 2860 | if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP()) |
|---|
| 2861 | #else |
|---|
| 2862 | if(!getVPS()->getUseAdvRP(getLayerId())) |
|---|
| 2863 | #endif |
|---|
| 2864 | { |
|---|
| 2865 | m_nARPStepNum = 0; |
|---|
| 2866 | } |
|---|
| 2867 | else |
|---|
| 2868 | { |
|---|
| 2869 | #if SHARP_ARP_REF_CHECK_F0105 |
|---|
| 2870 | setFirstTRefIdx (REF_PIC_LIST_0, -1); |
|---|
| 2871 | setFirstTRefIdx (REF_PIC_LIST_1, -1); |
|---|
| 2872 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
|---|
| 2873 | { |
|---|
| 2874 | for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ ) |
|---|
| 2875 | { |
|---|
| 2876 | if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() ) |
|---|
| 2877 | { |
|---|
| 2878 | setFirstTRefIdx (RefPicList(refListIdx), i); |
|---|
| 2879 | break; |
|---|
| 2880 | } |
|---|
| 2881 | } |
|---|
| 2882 | } |
|---|
| 2883 | tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0; |
|---|
| 2884 | m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0; |
|---|
| 2885 | #else |
|---|
| 2886 | for( Int iRefListId = 0; iRefListId < 2; iRefListId++ ) |
|---|
| 2887 | { |
|---|
| 2888 | RefPicList eRefPicList = RefPicList( iRefListId ); |
|---|
| 2889 | Int iNumRefIdx = getNumRefIdx(eRefPicList); |
|---|
| 2890 | |
|---|
| 2891 | if( iNumRefIdx <= 0 ) |
|---|
| 2892 | { |
|---|
| 2893 | continue; |
|---|
| 2894 | } |
|---|
| 2895 | |
|---|
| 2896 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
|---|
| 2897 | { |
|---|
| 2898 | if( getRefPic( eRefPicList, i)->getPOC() != getPOC() ) |
|---|
| 2899 | { |
|---|
| 2900 | bAllIvRef = false; |
|---|
| 2901 | break; |
|---|
| 2902 | } |
|---|
| 2903 | } |
|---|
| 2904 | |
|---|
| 2905 | if( bAllIvRef == false ) { break; } |
|---|
| 2906 | } |
|---|
| 2907 | m_nARPStepNum = !bAllIvRef ? getVPS()->getARPStepNum(getLayerId()) : 0; |
|---|
| 2908 | #endif |
|---|
| 2909 | } |
|---|
| 2910 | #if SHARP_ARP_REF_CHECK_F0105 |
|---|
| 2911 | if (tempRefPicInListsFlag) |
|---|
| 2912 | { |
|---|
| 2913 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
|---|
| 2914 | { |
|---|
| 2915 | RefPicList eRefPicList = RefPicList( refListIdx ); |
|---|
| 2916 | Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC(); |
|---|
| 2917 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
|---|
| 2918 | { |
|---|
| 2919 | Int layerIdInNuh = getRefPicLayerId( i ); |
|---|
| 2920 | Int viewIdx = getVPS()->getViewId( layerIdInNuh ); |
|---|
| 2921 | TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC); |
|---|
| 2922 | if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced()) |
|---|
| 2923 | { |
|---|
| 2924 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true; |
|---|
| 2925 | } |
|---|
| 2926 | else |
|---|
| 2927 | { |
|---|
| 2928 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false; |
|---|
| 2929 | } |
|---|
| 2930 | } |
|---|
| 2931 | } |
|---|
| 2932 | } |
|---|
| 2933 | #endif |
|---|
| 2934 | } |
|---|
| 2935 | #endif |
|---|
| 2936 | #if H_3D_IC |
|---|
| 2937 | Void TComSlice::xSetApplyIC() |
|---|
| 2938 | { |
|---|
| 2939 | Int iMaxPelValue = ( 1 << g_bitDepthY ); |
|---|
| 2940 | Int *aiRefOrgHist; |
|---|
| 2941 | Int *aiCurrHist; |
|---|
| 2942 | aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue ); |
|---|
| 2943 | aiCurrHist = (Int *) xMalloc( Int,iMaxPelValue ); |
|---|
| 2944 | memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) ); |
|---|
| 2945 | memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) ); |
|---|
| 2946 | // Reference Idx Number |
|---|
| 2947 | Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 ); |
|---|
| 2948 | TComPic* pcCurrPic = NULL; |
|---|
| 2949 | TComPic* pcRefPic = NULL; |
|---|
| 2950 | TComPicYuv* pcCurrPicYuv = NULL; |
|---|
| 2951 | TComPicYuv* pcRefPicYuvOrg = NULL; |
|---|
| 2952 | pcCurrPic = getPic(); |
|---|
| 2953 | pcCurrPicYuv = pcCurrPic->getPicYuvOrg(); |
|---|
| 2954 | Int iWidth = pcCurrPicYuv->getWidth(); |
|---|
| 2955 | Int iHeight = pcCurrPicYuv->getHeight(); |
|---|
| 2956 | |
|---|
| 2957 | |
|---|
| 2958 | // Get InterView Reference picture |
|---|
| 2959 | // !!!!! Assume only one Interview Reference Picture in L0 |
|---|
| 2960 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
|---|
| 2961 | { |
|---|
| 2962 | pcRefPic = getRefPic( REF_PIC_LIST_0, i ); |
|---|
| 2963 | if ( pcRefPic != NULL ) |
|---|
| 2964 | { |
|---|
| 2965 | if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() ) |
|---|
| 2966 | { |
|---|
| 2967 | pcRefPicYuvOrg = pcRefPic->getPicYuvOrg(); |
|---|
| 2968 | } |
|---|
| 2969 | } |
|---|
| 2970 | } |
|---|
| 2971 | |
|---|
| 2972 | if ( pcRefPicYuvOrg != NULL ) |
|---|
| 2973 | { |
|---|
| 2974 | Pel* pCurrY = pcCurrPicYuv ->getLumaAddr(); |
|---|
| 2975 | Pel* pRefOrgY = pcRefPicYuvOrg ->getLumaAddr(); |
|---|
| 2976 | Int iCurrStride = pcCurrPicYuv->getStride(); |
|---|
| 2977 | Int iRefStride = pcRefPicYuvOrg->getStride(); |
|---|
| 2978 | Int iSumOrgSAD = 0; |
|---|
| 2979 | Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05; |
|---|
| 2980 | |
|---|
| 2981 | // Histogram building - luminance |
|---|
| 2982 | for ( Int y = 0; y < iHeight; y++ ) |
|---|
| 2983 | { |
|---|
| 2984 | for ( Int x = 0; x < iWidth; x++ ) |
|---|
| 2985 | { |
|---|
| 2986 | aiCurrHist[pCurrY[x]]++; |
|---|
| 2987 | aiRefOrgHist[pRefOrgY[x]]++; |
|---|
| 2988 | } |
|---|
| 2989 | pCurrY += iCurrStride; |
|---|
| 2990 | pRefOrgY += iRefStride; |
|---|
| 2991 | } |
|---|
| 2992 | // Histogram SAD |
|---|
| 2993 | for ( Int i = 0; i < iMaxPelValue; i++ ) |
|---|
| 2994 | { |
|---|
| 2995 | iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] ); |
|---|
| 2996 | } |
|---|
| 2997 | // Setting |
|---|
| 2998 | if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) ) |
|---|
| 2999 | { |
|---|
| 3000 | m_bApplyIC = true; |
|---|
| 3001 | } |
|---|
| 3002 | else |
|---|
| 3003 | { |
|---|
| 3004 | m_bApplyIC = false; |
|---|
| 3005 | } |
|---|
| 3006 | } |
|---|
| 3007 | |
|---|
| 3008 | xFree( aiCurrHist ); |
|---|
| 3009 | xFree( aiRefOrgHist ); |
|---|
| 3010 | aiCurrHist = NULL; |
|---|
| 3011 | aiRefOrgHist = NULL; |
|---|
| 3012 | } |
|---|
| 3013 | #endif |
|---|
| 3014 | #if H_3D |
|---|
| 3015 | Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists ) |
|---|
| 3016 | { |
|---|
| 3017 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 3018 | { |
|---|
| 3019 | for ( Int depthId = 0; depthId < 2; depthId++ ) |
|---|
| 3020 | { |
|---|
| 3021 | m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL; |
|---|
| 3022 | } |
|---|
| 3023 | } |
|---|
| 3024 | } |
|---|
| 3025 | Void TComSlice::setDepthToDisparityLUTs() |
|---|
| 3026 | { |
|---|
| 3027 | Bool setupLUT = false; |
|---|
| 3028 | Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); |
|---|
| 3029 | |
|---|
| 3030 | #if H_3D_VSP |
|---|
| 3031 | setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); |
|---|
| 3032 | #endif |
|---|
| 3033 | |
|---|
| 3034 | #if H_3D_NBDV_REF |
|---|
| 3035 | setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS ); |
|---|
| 3036 | #endif |
|---|
| 3037 | |
|---|
| 3038 | #if QC_DEPTH_IV_MRG_F0125 |
|---|
| 3039 | setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() ); |
|---|
| 3040 | #endif |
|---|
| 3041 | |
|---|
| 3042 | if( !setupLUT ) |
|---|
| 3043 | return; |
|---|
| 3044 | |
|---|
| 3045 | /// GT: Allocation should be moved to a better place later; |
|---|
| 3046 | if ( m_depthToDisparityB == NULL ) |
|---|
| 3047 | { |
|---|
| 3048 | m_depthToDisparityB = new Int*[ getViewIndex() ]; |
|---|
| 3049 | for ( Int i = 0; i < getViewIndex(); i++ ) |
|---|
| 3050 | { |
|---|
| 3051 | m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
|---|
| 3052 | } |
|---|
| 3053 | } |
|---|
| 3054 | |
|---|
| 3055 | if ( m_depthToDisparityF == NULL ) |
|---|
| 3056 | { |
|---|
| 3057 | m_depthToDisparityF= new Int*[ getViewIndex() ]; |
|---|
| 3058 | for ( Int i = 0; i < getViewIndex(); i++ ) |
|---|
| 3059 | { |
|---|
| 3060 | m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
|---|
| 3061 | } |
|---|
| 3062 | } |
|---|
| 3063 | |
|---|
| 3064 | assert( m_depthToDisparityB != NULL ); |
|---|
| 3065 | assert( m_depthToDisparityF != NULL ); |
|---|
| 3066 | |
|---|
| 3067 | TComSPS* sps = getSPS(); |
|---|
| 3068 | |
|---|
| 3069 | Int log2Div = g_bitDepthY - 1 + sps->getCamParPrecision(); |
|---|
| 3070 | |
|---|
| 3071 | Bool camParaSH = m_pcSPS->hasCamParInSliceHeader(); |
|---|
| 3072 | |
|---|
| 3073 | Int* codScale = camParaSH ? m_aaiCodedScale [ 0 ] : sps->getCodedScale (); |
|---|
| 3074 | Int* codOffset = camParaSH ? m_aaiCodedOffset[ 0 ] : sps->getCodedOffset (); |
|---|
| 3075 | Int* invCodScale = camParaSH ? m_aaiCodedScale [ 1 ] : sps->getInvCodedScale (); |
|---|
| 3076 | Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : sps->getInvCodedOffset(); |
|---|
| 3077 | |
|---|
| 3078 | for (Int i = 0; i <= ( getViewIndex() - 1); i++) |
|---|
| 3079 | { |
|---|
| 3080 | for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ ) |
|---|
| 3081 | { |
|---|
| 3082 | Int offset = ( codOffset [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
|---|
| 3083 | m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; |
|---|
| 3084 | |
|---|
| 3085 | Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
|---|
| 3086 | m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; |
|---|
| 3087 | } |
|---|
| 3088 | } |
|---|
| 3089 | } |
|---|
| 3090 | #endif |
|---|
| 3091 | #endif |
|---|
| 3092 | /** get scaling matrix from RefMatrixID |
|---|
| 3093 | * \param sizeId size index |
|---|
| 3094 | * \param Index of input matrix |
|---|
| 3095 | * \param Index of reference matrix |
|---|
| 3096 | */ |
|---|
| 3097 | Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId ) |
|---|
| 3098 | { |
|---|
| 3099 | ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
|---|
| 3100 | } |
|---|
| 3101 | |
|---|
| 3102 | /** parse syntax infomation |
|---|
| 3103 | * \param pchFile syntax infomation |
|---|
| 3104 | * \returns false if successful |
|---|
| 3105 | */ |
|---|
| 3106 | Bool TComScalingList::xParseScalingList(Char* pchFile) |
|---|
| 3107 | { |
|---|
| 3108 | FILE *fp; |
|---|
| 3109 | Char line[1024]; |
|---|
| 3110 | UInt sizeIdc,listIdc; |
|---|
| 3111 | UInt i,size = 0; |
|---|
| 3112 | Int *src=0,data; |
|---|
| 3113 | Char *ret; |
|---|
| 3114 | UInt retval; |
|---|
| 3115 | |
|---|
| 3116 | if((fp = fopen(pchFile,"r")) == (FILE*)NULL) |
|---|
| 3117 | { |
|---|
| 3118 | printf("can't open file %s :: set Default Matrix\n",pchFile); |
|---|
| 3119 | return true; |
|---|
| 3120 | } |
|---|
| 3121 | |
|---|
| 3122 | for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++) |
|---|
| 3123 | { |
|---|
| 3124 | size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]); |
|---|
| 3125 | for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++) |
|---|
| 3126 | { |
|---|
| 3127 | src = getScalingListAddress(sizeIdc, listIdc); |
|---|
| 3128 | |
|---|
| 3129 | fseek(fp,0,0); |
|---|
| 3130 | do |
|---|
| 3131 | { |
|---|
| 3132 | ret = fgets(line, 1024, fp); |
|---|
| 3133 | if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp))) |
|---|
| 3134 | { |
|---|
| 3135 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 3136 | return true; |
|---|
| 3137 | } |
|---|
| 3138 | } |
|---|
| 3139 | while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL); |
|---|
| 3140 | for (i=0; i<size; i++) |
|---|
| 3141 | { |
|---|
| 3142 | retval = fscanf(fp, "%d,", &data); |
|---|
| 3143 | if (retval!=1) |
|---|
| 3144 | { |
|---|
| 3145 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 3146 | return true; |
|---|
| 3147 | } |
|---|
| 3148 | src[i] = data; |
|---|
| 3149 | } |
|---|
| 3150 | //set DC value for default matrix check |
|---|
| 3151 | setScalingListDC(sizeIdc,listIdc,src[0]); |
|---|
| 3152 | |
|---|
| 3153 | if(sizeIdc > SCALING_LIST_8x8) |
|---|
| 3154 | { |
|---|
| 3155 | fseek(fp,0,0); |
|---|
| 3156 | do |
|---|
| 3157 | { |
|---|
| 3158 | ret = fgets(line, 1024, fp); |
|---|
| 3159 | if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp))) |
|---|
| 3160 | { |
|---|
| 3161 | printf("Error: can't read DC :: set Default Matrix\n"); |
|---|
| 3162 | return true; |
|---|
| 3163 | } |
|---|
| 3164 | } |
|---|
| 3165 | while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL); |
|---|
| 3166 | retval = fscanf(fp, "%d,", &data); |
|---|
| 3167 | if (retval!=1) |
|---|
| 3168 | { |
|---|
| 3169 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 3170 | return true; |
|---|
| 3171 | } |
|---|
| 3172 | //overwrite DC value when size of matrix is larger than 16x16 |
|---|
| 3173 | setScalingListDC(sizeIdc,listIdc,data); |
|---|
| 3174 | } |
|---|
| 3175 | } |
|---|
| 3176 | } |
|---|
| 3177 | fclose(fp); |
|---|
| 3178 | return false; |
|---|
| 3179 | } |
|---|
| 3180 | |
|---|
| 3181 | #if H_MV |
|---|
| 3182 | Void TComScalingList::inferFrom( TComScalingList* srcScLi ) |
|---|
| 3183 | { |
|---|
| 3184 | for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 3185 | { |
|---|
| 3186 | for(Int listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 3187 | { |
|---|
| 3188 | setRefMatrixId (sizeId,listId, srcScLi->getRefMatrixId (sizeId,listId)); |
|---|
| 3189 | setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId)); |
|---|
| 3190 | ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
|---|
| 3191 | } |
|---|
| 3192 | } |
|---|
| 3193 | } |
|---|
| 3194 | #endif |
|---|
| 3195 | /** initialization process of quantization matrix array |
|---|
| 3196 | */ |
|---|
| 3197 | Void TComScalingList::init() |
|---|
| 3198 | { |
|---|
| 3199 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 3200 | { |
|---|
| 3201 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 3202 | { |
|---|
| 3203 | m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])]; |
|---|
| 3204 | } |
|---|
| 3205 | } |
|---|
| 3206 | m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32 |
|---|
| 3207 | } |
|---|
| 3208 | |
|---|
| 3209 | /** destroy quantization matrix array |
|---|
| 3210 | */ |
|---|
| 3211 | Void TComScalingList::destroy() |
|---|
| 3212 | { |
|---|
| 3213 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 3214 | { |
|---|
| 3215 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 3216 | { |
|---|
| 3217 | if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId]; |
|---|
| 3218 | } |
|---|
| 3219 | } |
|---|
| 3220 | } |
|---|
| 3221 | |
|---|
| 3222 | /** get default address of quantization matrix |
|---|
| 3223 | * \param sizeId size index |
|---|
| 3224 | * \param listId list index |
|---|
| 3225 | * \returns pointer of quantization matrix |
|---|
| 3226 | */ |
|---|
| 3227 | Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId) |
|---|
| 3228 | { |
|---|
| 3229 | Int *src = 0; |
|---|
| 3230 | switch(sizeId) |
|---|
| 3231 | { |
|---|
| 3232 | case SCALING_LIST_4x4: |
|---|
| 3233 | src = g_quantTSDefault4x4; |
|---|
| 3234 | break; |
|---|
| 3235 | case SCALING_LIST_8x8: |
|---|
| 3236 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 3237 | break; |
|---|
| 3238 | case SCALING_LIST_16x16: |
|---|
| 3239 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 3240 | break; |
|---|
| 3241 | case SCALING_LIST_32x32: |
|---|
| 3242 | src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 3243 | break; |
|---|
| 3244 | default: |
|---|
| 3245 | assert(0); |
|---|
| 3246 | src = NULL; |
|---|
| 3247 | break; |
|---|
| 3248 | } |
|---|
| 3249 | return src; |
|---|
| 3250 | } |
|---|
| 3251 | |
|---|
| 3252 | /** process of default matrix |
|---|
| 3253 | * \param sizeId size index |
|---|
| 3254 | * \param Index of input matrix |
|---|
| 3255 | */ |
|---|
| 3256 | Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId) |
|---|
| 3257 | { |
|---|
| 3258 | ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
|---|
| 3259 | setScalingListDC(sizeId,listId,SCALING_LIST_DC); |
|---|
| 3260 | } |
|---|
| 3261 | |
|---|
| 3262 | /** check DC value of matrix for default matrix signaling |
|---|
| 3263 | */ |
|---|
| 3264 | Void TComScalingList::checkDcOfMatrix() |
|---|
| 3265 | { |
|---|
| 3266 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 3267 | { |
|---|
| 3268 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 3269 | { |
|---|
| 3270 | //check default matrix? |
|---|
| 3271 | if(getScalingListDC(sizeId,listId) == 0) |
|---|
| 3272 | { |
|---|
| 3273 | processDefaultMarix(sizeId, listId); |
|---|
| 3274 | } |
|---|
| 3275 | } |
|---|
| 3276 | } |
|---|
| 3277 | } |
|---|
| 3278 | |
|---|
| 3279 | ParameterSetManager::ParameterSetManager() |
|---|
| 3280 | : m_vpsMap(MAX_NUM_VPS) |
|---|
| 3281 | , m_spsMap(MAX_NUM_SPS) |
|---|
| 3282 | , m_ppsMap(MAX_NUM_PPS) |
|---|
| 3283 | , m_activeVPSId(-1) |
|---|
| 3284 | #if !H_MV |
|---|
| 3285 | , m_activeSPSId(-1) |
|---|
| 3286 | , m_activePPSId(-1) |
|---|
| 3287 | { |
|---|
| 3288 | #else |
|---|
| 3289 | { |
|---|
| 3290 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
|---|
| 3291 | { |
|---|
| 3292 | m_activeSPSId[ i ] = -1; |
|---|
| 3293 | m_activePPSId[ i ] = -1; |
|---|
| 3294 | } |
|---|
| 3295 | #endif |
|---|
| 3296 | } |
|---|
| 3297 | |
|---|
| 3298 | |
|---|
| 3299 | ParameterSetManager::~ParameterSetManager() |
|---|
| 3300 | { |
|---|
| 3301 | } |
|---|
| 3302 | |
|---|
| 3303 | //! activate a SPS from a active parameter sets SEI message |
|---|
| 3304 | //! \returns true, if activation is successful |
|---|
| 3305 | #if H_MV |
|---|
| 3306 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId ) |
|---|
| 3307 | #else |
|---|
| 3308 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId) |
|---|
| 3309 | #endif |
|---|
| 3310 | { |
|---|
| 3311 | TComSPS *sps = m_spsMap.getPS(spsId); |
|---|
| 3312 | if (sps) |
|---|
| 3313 | { |
|---|
| 3314 | Int vpsId = sps->getVPSId(); |
|---|
| 3315 | if (m_vpsMap.getPS(vpsId)) |
|---|
| 3316 | { |
|---|
| 3317 | m_activeVPSId = vpsId; |
|---|
| 3318 | #if H_MV |
|---|
| 3319 | m_activeSPSId[ layerId ] = spsId; |
|---|
| 3320 | #else |
|---|
| 3321 | m_activeSPSId = spsId; |
|---|
| 3322 | #endif |
|---|
| 3323 | return true; |
|---|
| 3324 | } |
|---|
| 3325 | else |
|---|
| 3326 | { |
|---|
| 3327 | printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist."); |
|---|
| 3328 | } |
|---|
| 3329 | } |
|---|
| 3330 | else |
|---|
| 3331 | { |
|---|
| 3332 | printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message."); |
|---|
| 3333 | } |
|---|
| 3334 | return false; |
|---|
| 3335 | } |
|---|
| 3336 | |
|---|
| 3337 | //! activate a PPS and depending on isIDR parameter also SPS and VPS |
|---|
| 3338 | //! \returns true, if activation is successful |
|---|
| 3339 | #if H_MV |
|---|
| 3340 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId ) |
|---|
| 3341 | #else |
|---|
| 3342 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP) |
|---|
| 3343 | #endif |
|---|
| 3344 | { |
|---|
| 3345 | TComPPS *pps = m_ppsMap.getPS(ppsId); |
|---|
| 3346 | if (pps) |
|---|
| 3347 | { |
|---|
| 3348 | Int spsId = pps->getSPSId(); |
|---|
| 3349 | #if H_MV |
|---|
| 3350 | if (!isIRAP && (spsId != m_activeSPSId[ layerId ])) |
|---|
| 3351 | #else |
|---|
| 3352 | if (!isIRAP && (spsId != m_activeSPSId)) |
|---|
| 3353 | #endif |
|---|
| 3354 | { |
|---|
| 3355 | printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP."); |
|---|
| 3356 | return false; |
|---|
| 3357 | } |
|---|
| 3358 | |
|---|
| 3359 | TComSPS *sps = m_spsMap.getPS(spsId); |
|---|
| 3360 | if (sps) |
|---|
| 3361 | { |
|---|
| 3362 | Int vpsId = sps->getVPSId(); |
|---|
| 3363 | if (!isIRAP && (vpsId != m_activeVPSId)) |
|---|
| 3364 | { |
|---|
| 3365 | printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP."); |
|---|
| 3366 | return false; |
|---|
| 3367 | } |
|---|
| 3368 | if (m_vpsMap.getPS(vpsId)) |
|---|
| 3369 | { |
|---|
| 3370 | #if H_MV |
|---|
| 3371 | m_activePPSId[ layerId ] = ppsId; |
|---|
| 3372 | m_activeVPSId = vpsId; |
|---|
| 3373 | m_activeSPSId[ layerId ] = spsId; |
|---|
| 3374 | #else |
|---|
| 3375 | m_activePPSId = ppsId; |
|---|
| 3376 | m_activeVPSId = vpsId; |
|---|
| 3377 | m_activeSPSId = spsId; |
|---|
| 3378 | #endif |
|---|
| 3379 | return true; |
|---|
| 3380 | } |
|---|
| 3381 | else |
|---|
| 3382 | { |
|---|
| 3383 | printf("Warning: tried to activate PPS that refers to a non-existing VPS."); |
|---|
| 3384 | } |
|---|
| 3385 | } |
|---|
| 3386 | else |
|---|
| 3387 | { |
|---|
| 3388 | printf("Warning: tried to activate a PPS that refers to a non-existing SPS."); |
|---|
| 3389 | } |
|---|
| 3390 | } |
|---|
| 3391 | else |
|---|
| 3392 | { |
|---|
| 3393 | printf("Warning: tried to activate non-existing PPS."); |
|---|
| 3394 | } |
|---|
| 3395 | return false; |
|---|
| 3396 | } |
|---|
| 3397 | |
|---|
| 3398 | ProfileTierLevel::ProfileTierLevel() |
|---|
| 3399 | : m_profileSpace (0) |
|---|
| 3400 | , m_tierFlag (false) |
|---|
| 3401 | , m_profileIdc (0) |
|---|
| 3402 | , m_levelIdc (0) |
|---|
| 3403 | , m_progressiveSourceFlag (false) |
|---|
| 3404 | , m_interlacedSourceFlag (false) |
|---|
| 3405 | , m_nonPackedConstraintFlag(false) |
|---|
| 3406 | , m_frameOnlyConstraintFlag(false) |
|---|
| 3407 | { |
|---|
| 3408 | ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag)); |
|---|
| 3409 | } |
|---|
| 3410 | |
|---|
| 3411 | TComPTL::TComPTL() |
|---|
| 3412 | { |
|---|
| 3413 | ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag)); |
|---|
| 3414 | ::memset(m_subLayerLevelPresentFlag, 0, sizeof(m_subLayerLevelPresentFlag )); |
|---|
| 3415 | } |
|---|
| 3416 | |
|---|
| 3417 | #if H_MV |
|---|
| 3418 | Void TComPTL::copyLevelFrom( TComPTL* source ) |
|---|
| 3419 | { |
|---|
| 3420 | getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() ); |
|---|
| 3421 | for( Int subLayer = 0; subLayer < 6; subLayer++ ) |
|---|
| 3422 | { |
|---|
| 3423 | setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) ); |
|---|
| 3424 | getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() ); |
|---|
| 3425 | } |
|---|
| 3426 | } |
|---|
| 3427 | #endif |
|---|
| 3428 | //! \} |
|---|
| 3429 | |
|---|
| 3430 | #if H_MV |
|---|
| 3431 | TComVPSVUI::TComVPSVUI() |
|---|
| 3432 | { |
|---|
| 3433 | m_bitRatePresentVpsFlag = false; |
|---|
| 3434 | m_picRatePresentVpsFlag = false; |
|---|
| 3435 | for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++) |
|---|
| 3436 | { |
|---|
| 3437 | for ( Int j = 0; j < MAX_TLAYER; j++) |
|---|
| 3438 | { |
|---|
| 3439 | m_bitRatePresentFlag [i][j] = false; |
|---|
| 3440 | m_picRatePresentFlag [i][j] = false; |
|---|
| 3441 | m_avgBitRate [i][j] = -1; |
|---|
| 3442 | m_maxBitRate [i][j] = -1; |
|---|
| 3443 | m_constantPicRateIdc [i][j] = -1; |
|---|
| 3444 | m_avgPicRate [i][j] = -1; |
|---|
| 3445 | } |
|---|
| 3446 | } |
|---|
| 3447 | |
|---|
| 3448 | m_ilpRestrictedRefLayersFlag = false; |
|---|
| 3449 | |
|---|
| 3450 | for ( Int i = 0; i < MAX_NUM_LAYERS; i++) |
|---|
| 3451 | { |
|---|
| 3452 | for ( Int j = 0; j < MAX_NUM_LAYERS; j++) |
|---|
| 3453 | { |
|---|
| 3454 | m_tileBoundariesAlignedFlag [i][j] = false; |
|---|
| 3455 | m_minSpatialSegmentOffsetPlus1[i][j] = 0; |
|---|
| 3456 | m_ctuBasedOffsetEnabledFlag [i][j] = false; |
|---|
| 3457 | m_minHorizontalCtuOffsetPlus1 [i][j] = -1; |
|---|
| 3458 | } |
|---|
| 3459 | } |
|---|
| 3460 | } |
|---|
| 3461 | #endif |
|---|