| 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 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 63 | , m_bRefPicListModificationFlagLC ( false ) |
|---|
| 64 | , m_bRefPicListCombinationFlag ( false ) |
|---|
| 65 | #endif |
|---|
| 66 | , m_bCheckLDC ( false ) |
|---|
| 67 | , m_iSliceQpDelta ( 0 ) |
|---|
| 68 | , m_iSliceQpDeltaCb ( 0 ) |
|---|
| 69 | , m_iSliceQpDeltaCr ( 0 ) |
|---|
| 70 | , m_iDepth ( 0 ) |
|---|
| 71 | , m_bRefenced ( false ) |
|---|
| 72 | , m_pcSPS ( NULL ) |
|---|
| 73 | , m_pcPPS ( NULL ) |
|---|
| 74 | , m_pcPic ( NULL ) |
|---|
| 75 | , m_colFromL0Flag ( 1 ) |
|---|
| 76 | , m_colRefIdx ( 0 ) |
|---|
| 77 | #if SAO_CHROMA_LAMBDA |
|---|
| 78 | , m_dLambdaLuma( 0.0 ) |
|---|
| 79 | , m_dLambdaChroma( 0.0 ) |
|---|
| 80 | #else |
|---|
| 81 | , m_dLambda ( 0.0 ) |
|---|
| 82 | #endif |
|---|
| 83 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 84 | , m_bNoBackPredFlag ( false ) |
|---|
| 85 | #endif |
|---|
| 86 | , m_uiTLayer ( 0 ) |
|---|
| 87 | , m_bTLayerSwitchingFlag ( false ) |
|---|
| 88 | , m_sliceMode ( 0 ) |
|---|
| 89 | , m_sliceArgument ( 0 ) |
|---|
| 90 | , m_sliceCurStartCUAddr ( 0 ) |
|---|
| 91 | , m_sliceCurEndCUAddr ( 0 ) |
|---|
| 92 | , m_sliceIdx ( 0 ) |
|---|
| 93 | , m_sliceSegmentMode ( 0 ) |
|---|
| 94 | , m_sliceSegmentArgument ( 0 ) |
|---|
| 95 | , m_sliceSegmentCurStartCUAddr ( 0 ) |
|---|
| 96 | , m_sliceSegmentCurEndCUAddr ( 0 ) |
|---|
| 97 | , m_nextSlice ( false ) |
|---|
| 98 | , m_nextSliceSegment ( false ) |
|---|
| 99 | , m_sliceBits ( 0 ) |
|---|
| 100 | , m_sliceSegmentBits ( 0 ) |
|---|
| 101 | , m_bFinalized ( false ) |
|---|
| 102 | , m_uiTileOffstForMultES ( 0 ) |
|---|
| 103 | , m_puiSubstreamSizes ( NULL ) |
|---|
| 104 | , m_cabacInitFlag ( false ) |
|---|
| 105 | , m_bLMvdL1Zero ( false ) |
|---|
| 106 | , m_numEntryPointOffsets ( 0 ) |
|---|
| 107 | , m_temporalLayerNonReferenceFlag ( false ) |
|---|
| 108 | , m_enableTMVPFlag ( true ) |
|---|
| 109 | { |
|---|
| 110 | #if L0034_COMBINED_LIST_CLEANUP |
|---|
| 111 | m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0; |
|---|
| 112 | #else |
|---|
| 113 | m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0; |
|---|
| 114 | #endif |
|---|
| 115 | |
|---|
| 116 | initEqualRef(); |
|---|
| 117 | |
|---|
| 118 | #if L0034_COMBINED_LIST_CLEANUP |
|---|
| 119 | for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) |
|---|
| 120 | { |
|---|
| 121 | m_list1IdxToList0Idx[idx] = -1; |
|---|
| 122 | } |
|---|
| 123 | #else |
|---|
| 124 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++) |
|---|
| 125 | { |
|---|
| 126 | m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1; |
|---|
| 127 | m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1; |
|---|
| 128 | m_eListIdFromIdxOfLC[iNumCount]=0; |
|---|
| 129 | m_iRefIdxFromIdxOfLC[iNumCount]=0; |
|---|
| 130 | m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1; |
|---|
| 131 | m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1; |
|---|
| 132 | } |
|---|
| 133 | #endif |
|---|
| 134 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++) |
|---|
| 135 | { |
|---|
| 136 | m_apcRefPicList [0][iNumCount] = NULL; |
|---|
| 137 | m_apcRefPicList [1][iNumCount] = NULL; |
|---|
| 138 | m_aiRefPOCList [0][iNumCount] = 0; |
|---|
| 139 | m_aiRefPOCList [1][iNumCount] = 0; |
|---|
| 140 | } |
|---|
| 141 | resetWpScaling(); |
|---|
| 142 | initWpAcDcParam(); |
|---|
| 143 | m_saoEnabledFlag = false; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | TComSlice::~TComSlice() |
|---|
| 147 | { |
|---|
| 148 | delete[] m_puiSubstreamSizes; |
|---|
| 149 | m_puiSubstreamSizes = NULL; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | Void TComSlice::initSlice() |
|---|
| 154 | { |
|---|
| 155 | m_aiNumRefIdx[0] = 0; |
|---|
| 156 | m_aiNumRefIdx[1] = 0; |
|---|
| 157 | |
|---|
| 158 | m_colFromL0Flag = 1; |
|---|
| 159 | |
|---|
| 160 | m_colRefIdx = 0; |
|---|
| 161 | initEqualRef(); |
|---|
| 162 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 163 | m_bNoBackPredFlag = false; |
|---|
| 164 | m_bRefPicListCombinationFlag = false; |
|---|
| 165 | m_bRefPicListModificationFlagLC = false; |
|---|
| 166 | #endif |
|---|
| 167 | m_bCheckLDC = false; |
|---|
| 168 | m_iSliceQpDeltaCb = 0; |
|---|
| 169 | m_iSliceQpDeltaCr = 0; |
|---|
| 170 | |
|---|
| 171 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 172 | m_aiNumRefIdx[REF_PIC_LIST_C] = 0; |
|---|
| 173 | #endif |
|---|
| 174 | |
|---|
| 175 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS; |
|---|
| 176 | |
|---|
| 177 | m_bFinalized=false; |
|---|
| 178 | |
|---|
| 179 | m_tileByteLocation.clear(); |
|---|
| 180 | m_cabacInitFlag = false; |
|---|
| 181 | m_numEntryPointOffsets = 0; |
|---|
| 182 | m_enableTMVPFlag = true; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | Bool TComSlice::getRapPicFlag() |
|---|
| 186 | { |
|---|
| 187 | return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
|---|
| 188 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
|---|
| 189 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
|---|
| 190 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 191 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 192 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | - allocate table to contain substream sizes to be written to the slice header. |
|---|
| 197 | . |
|---|
| 198 | \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1. |
|---|
| 199 | */ |
|---|
| 200 | Void TComSlice::allocSubstreamSizes(UInt uiNumSubstreams) |
|---|
| 201 | { |
|---|
| 202 | delete[] m_puiSubstreamSizes; |
|---|
| 203 | m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0]; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | Void TComSlice::sortPicList (TComList<TComPic*>& rcListPic) |
|---|
| 207 | { |
|---|
| 208 | TComPic* pcPicExtract; |
|---|
| 209 | TComPic* pcPicInsert; |
|---|
| 210 | |
|---|
| 211 | TComList<TComPic*>::iterator iterPicExtract; |
|---|
| 212 | TComList<TComPic*>::iterator iterPicExtract_1; |
|---|
| 213 | TComList<TComPic*>::iterator iterPicInsert; |
|---|
| 214 | |
|---|
| 215 | for (Int i = 1; i < (Int)(rcListPic.size()); i++) |
|---|
| 216 | { |
|---|
| 217 | iterPicExtract = rcListPic.begin(); |
|---|
| 218 | for (Int j = 0; j < i; j++) iterPicExtract++; |
|---|
| 219 | pcPicExtract = *(iterPicExtract); |
|---|
| 220 | pcPicExtract->setCurrSliceIdx(0); |
|---|
| 221 | |
|---|
| 222 | iterPicInsert = rcListPic.begin(); |
|---|
| 223 | while (iterPicInsert != iterPicExtract) |
|---|
| 224 | { |
|---|
| 225 | pcPicInsert = *(iterPicInsert); |
|---|
| 226 | pcPicInsert->setCurrSliceIdx(0); |
|---|
| 227 | if (pcPicInsert->getPOC() >= pcPicExtract->getPOC()) |
|---|
| 228 | { |
|---|
| 229 | break; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | iterPicInsert++; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | iterPicExtract_1 = iterPicExtract; iterPicExtract_1++; |
|---|
| 236 | |
|---|
| 237 | // swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position |
|---|
| 238 | rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1); |
|---|
| 239 | rcListPic.erase (iterPicExtract); |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, |
|---|
| 244 | Int poc) |
|---|
| 245 | { |
|---|
| 246 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 247 | TComPic* pcPic = *(iterPic); |
|---|
| 248 | while ( iterPic != rcListPic.end() ) |
|---|
| 249 | { |
|---|
| 250 | if(pcPic->getPOC() == poc) |
|---|
| 251 | { |
|---|
| 252 | break; |
|---|
| 253 | } |
|---|
| 254 | iterPic++; |
|---|
| 255 | pcPic = *(iterPic); |
|---|
| 256 | } |
|---|
| 257 | return pcPic; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb) |
|---|
| 262 | { |
|---|
| 263 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 264 | TComPic* pcPic = *(iterPic); |
|---|
| 265 | TComPic* pcStPic = pcPic; |
|---|
| 266 | |
|---|
| 267 | Int pocCycle = 1 << getSPS()->getBitsForPOC(); |
|---|
| 268 | if (!pocHasMsb) |
|---|
| 269 | { |
|---|
| 270 | poc = poc % pocCycle; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | while ( iterPic != rcListPic.end() ) |
|---|
| 274 | { |
|---|
| 275 | pcPic = *(iterPic); |
|---|
| 276 | if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced()) |
|---|
| 277 | { |
|---|
| 278 | Int picPoc = pcPic->getPOC(); |
|---|
| 279 | if (!pocHasMsb) |
|---|
| 280 | { |
|---|
| 281 | picPoc = picPoc % pocCycle; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | if (poc == picPoc) |
|---|
| 285 | { |
|---|
| 286 | if(pcPic->getIsLongTerm()) |
|---|
| 287 | { |
|---|
| 288 | return pcPic; |
|---|
| 289 | } |
|---|
| 290 | else |
|---|
| 291 | { |
|---|
| 292 | pcStPic = pcPic; |
|---|
| 293 | } |
|---|
| 294 | break; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | iterPic++; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | return pcStPic; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | Void TComSlice::setRefPOCList () |
|---|
| 305 | { |
|---|
| 306 | for (Int iDir = 0; iDir < 2; iDir++) |
|---|
| 307 | { |
|---|
| 308 | for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++) |
|---|
| 309 | { |
|---|
| 310 | m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC(); |
|---|
| 311 | } |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | #if L0034_COMBINED_LIST_CLEANUP |
|---|
| 317 | Void TComSlice::setList1IdxToList0Idx() |
|---|
| 318 | { |
|---|
| 319 | Int idxL0, idxL1; |
|---|
| 320 | for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ ) |
|---|
| 321 | { |
|---|
| 322 | m_list1IdxToList0Idx[idxL1] = -1; |
|---|
| 323 | for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ ) |
|---|
| 324 | { |
|---|
| 325 | if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() ) |
|---|
| 326 | { |
|---|
| 327 | m_list1IdxToList0Idx[idxL1] = idxL0; |
|---|
| 328 | break; |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | #else |
|---|
| 334 | Void TComSlice::generateCombinedList() |
|---|
| 335 | { |
|---|
| 336 | if(m_aiNumRefIdx[REF_PIC_LIST_C] > 0) |
|---|
| 337 | { |
|---|
| 338 | m_aiNumRefIdx[REF_PIC_LIST_C]=0; |
|---|
| 339 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++) |
|---|
| 340 | { |
|---|
| 341 | m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1; |
|---|
| 342 | m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1; |
|---|
| 343 | m_eListIdFromIdxOfLC[iNumCount]=0; |
|---|
| 344 | m_iRefIdxFromIdxOfLC[iNumCount]=0; |
|---|
| 345 | m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1; |
|---|
| 346 | m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | for (Int iNumRefIdx = 0; iNumRefIdx < MAX_NUM_REF; iNumRefIdx++) |
|---|
| 350 | { |
|---|
| 351 | if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_0]) |
|---|
| 352 | { |
|---|
| 353 | Bool bTempRefIdxInL2 = true; |
|---|
| 354 | for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ ) |
|---|
| 355 | { |
|---|
| 356 | if ( m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() ) |
|---|
| 357 | { |
|---|
| 358 | m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC]; |
|---|
| 359 | m_iRefIdxOfL0FromRefIdxOfL1[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx; |
|---|
| 360 | bTempRefIdxInL2 = false; |
|---|
| 361 | break; |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | if(bTempRefIdxInL2 == true) |
|---|
| 366 | { |
|---|
| 367 | m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_0; |
|---|
| 368 | m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx; |
|---|
| 369 | m_iRefIdxOfLC[REF_PIC_LIST_0][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++; |
|---|
| 370 | } |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_1]) |
|---|
| 374 | { |
|---|
| 375 | Bool bTempRefIdxInL2 = true; |
|---|
| 376 | for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ ) |
|---|
| 377 | { |
|---|
| 378 | if ( m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() ) |
|---|
| 379 | { |
|---|
| 380 | m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC]; |
|---|
| 381 | m_iRefIdxOfL1FromRefIdxOfL0[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx; |
|---|
| 382 | bTempRefIdxInL2 = false; |
|---|
| 383 | break; |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | if(bTempRefIdxInL2 == true) |
|---|
| 387 | { |
|---|
| 388 | m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_1; |
|---|
| 389 | m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx; |
|---|
| 390 | m_iRefIdxOfLC[REF_PIC_LIST_1][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++; |
|---|
| 391 | } |
|---|
| 392 | } |
|---|
| 393 | } |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | #endif |
|---|
| 397 | |
|---|
| 398 | #if FIX1071 |
|---|
| 399 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) |
|---|
| 400 | #else |
|---|
| 401 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) |
|---|
| 402 | #endif |
|---|
| 403 | { |
|---|
| 404 | #if FIX1071 |
|---|
| 405 | if (!checkNumPocTotalCurr) |
|---|
| 406 | #endif |
|---|
| 407 | { |
|---|
| 408 | if (m_eSliceType == I_SLICE) |
|---|
| 409 | { |
|---|
| 410 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 411 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 412 | |
|---|
| 413 | return; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 417 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | TComPic* pcRefPic= NULL; |
|---|
| 421 | TComPic* RefPicSetStCurr0[16]; |
|---|
| 422 | TComPic* RefPicSetStCurr1[16]; |
|---|
| 423 | TComPic* RefPicSetLtCurr[16]; |
|---|
| 424 | UInt NumPocStCurr0 = 0; |
|---|
| 425 | UInt NumPocStCurr1 = 0; |
|---|
| 426 | UInt NumPocLtCurr = 0; |
|---|
| 427 | Int i; |
|---|
| 428 | |
|---|
| 429 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
|---|
| 430 | { |
|---|
| 431 | if(m_pcRPS->getUsed(i)) |
|---|
| 432 | { |
|---|
| 433 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 434 | pcRefPic->setIsLongTerm(0); |
|---|
| 435 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 436 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
|---|
| 437 | NumPocStCurr0++; |
|---|
| 438 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 439 | } |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
|---|
| 443 | { |
|---|
| 444 | if(m_pcRPS->getUsed(i)) |
|---|
| 445 | { |
|---|
| 446 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
|---|
| 447 | pcRefPic->setIsLongTerm(0); |
|---|
| 448 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 449 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
|---|
| 450 | NumPocStCurr1++; |
|---|
| 451 | pcRefPic->setCheckLTMSBPresent(false); |
|---|
| 452 | } |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
|---|
| 456 | { |
|---|
| 457 | if(m_pcRPS->getUsed(i)) |
|---|
| 458 | { |
|---|
| 459 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 460 | pcRefPic->setIsLongTerm(1); |
|---|
| 461 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
|---|
| 462 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
|---|
| 463 | NumPocLtCurr++; |
|---|
| 464 | } |
|---|
| 465 | if(pcRefPic==NULL) |
|---|
| 466 | { |
|---|
| 467 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 468 | } |
|---|
| 469 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | // ref_pic_list_init |
|---|
| 473 | TComPic* rpsCurrList0[MAX_NUM_REF+1]; |
|---|
| 474 | TComPic* rpsCurrList1[MAX_NUM_REF+1]; |
|---|
| 475 | Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
|---|
| 476 | #if FIX1071 |
|---|
| 477 | if (checkNumPocTotalCurr) |
|---|
| 478 | { |
|---|
| 479 | // 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: |
|---|
| 480 | // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
|---|
| 481 | // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
|---|
| 482 | if (getRapPicFlag()) |
|---|
| 483 | { |
|---|
| 484 | assert(numPocTotalCurr == 0); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | if (m_eSliceType == I_SLICE) |
|---|
| 488 | { |
|---|
| 489 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
|---|
| 490 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
|---|
| 491 | |
|---|
| 492 | return; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | assert(numPocTotalCurr != 0); |
|---|
| 496 | |
|---|
| 497 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
|---|
| 498 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
|---|
| 499 | } |
|---|
| 500 | #endif |
|---|
| 501 | |
|---|
| 502 | Int cIdx = 0; |
|---|
| 503 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
|---|
| 504 | { |
|---|
| 505 | rpsCurrList0[cIdx] = RefPicSetStCurr0[i]; |
|---|
| 506 | } |
|---|
| 507 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
|---|
| 508 | { |
|---|
| 509 | rpsCurrList0[cIdx] = RefPicSetStCurr1[i]; |
|---|
| 510 | } |
|---|
| 511 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
|---|
| 512 | { |
|---|
| 513 | rpsCurrList0[cIdx] = RefPicSetLtCurr[i]; |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | if (m_eSliceType==B_SLICE) |
|---|
| 517 | { |
|---|
| 518 | cIdx = 0; |
|---|
| 519 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
|---|
| 520 | { |
|---|
| 521 | rpsCurrList1[cIdx] = RefPicSetStCurr1[i]; |
|---|
| 522 | } |
|---|
| 523 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
|---|
| 524 | { |
|---|
| 525 | rpsCurrList1[cIdx] = RefPicSetStCurr0[i]; |
|---|
| 526 | } |
|---|
| 527 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
|---|
| 528 | { |
|---|
| 529 | rpsCurrList1[cIdx] = RefPicSetLtCurr[i]; |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
|---|
| 534 | |
|---|
| 535 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++) |
|---|
| 536 | { |
|---|
| 537 | m_apcRefPicList[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? rpsCurrList0[ m_RefPicListModification.getRefPicSetIdxL0(rIdx) ] : rpsCurrList0[rIdx % numPocTotalCurr]; |
|---|
| 538 | m_bIsUsedAsLongTerm[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? (m_RefPicListModification.getRefPicSetIdxL0(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)) |
|---|
| 539 | : ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1)); |
|---|
| 540 | } |
|---|
| 541 | if ( m_eSliceType == P_SLICE ) |
|---|
| 542 | { |
|---|
| 543 | m_aiNumRefIdx[1] = 0; |
|---|
| 544 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
|---|
| 545 | } |
|---|
| 546 | else |
|---|
| 547 | { |
|---|
| 548 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[1]-1); rIdx ++) |
|---|
| 549 | { |
|---|
| 550 | m_apcRefPicList[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? rpsCurrList1[ m_RefPicListModification.getRefPicSetIdxL1(rIdx) ] : rpsCurrList1[rIdx % numPocTotalCurr]; |
|---|
| 551 | m_bIsUsedAsLongTerm[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? |
|---|
| 552 | (m_RefPicListModification.getRefPicSetIdxL1(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)): ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1)); |
|---|
| 553 | } |
|---|
| 554 | } |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | Int TComSlice::getNumRpsCurrTempList() |
|---|
| 558 | { |
|---|
| 559 | Int numRpsCurrTempList = 0; |
|---|
| 560 | |
|---|
| 561 | if (m_eSliceType == I_SLICE) |
|---|
| 562 | { |
|---|
| 563 | return 0; |
|---|
| 564 | } |
|---|
| 565 | for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++) |
|---|
| 566 | { |
|---|
| 567 | if(m_pcRPS->getUsed(i)) |
|---|
| 568 | { |
|---|
| 569 | numRpsCurrTempList++; |
|---|
| 570 | } |
|---|
| 571 | } |
|---|
| 572 | return numRpsCurrTempList; |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | Void TComSlice::initEqualRef() |
|---|
| 576 | { |
|---|
| 577 | for (Int iDir = 0; iDir < 2; iDir++) |
|---|
| 578 | { |
|---|
| 579 | for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++) |
|---|
| 580 | { |
|---|
| 581 | for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++) |
|---|
| 582 | { |
|---|
| 583 | m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false); |
|---|
| 584 | } |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic) |
|---|
| 590 | { |
|---|
| 591 | Int i; |
|---|
| 592 | TComSlice* curSlice = pic->getSlice(curSliceIdx); |
|---|
| 593 | Int currColRefPOC = curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx()); |
|---|
| 594 | TComSlice* preSlice; |
|---|
| 595 | Int preColRefPOC; |
|---|
| 596 | for(i=curSliceIdx-1; i>=0; i--) |
|---|
| 597 | { |
|---|
| 598 | preSlice = pic->getSlice(i); |
|---|
| 599 | if(preSlice->getSliceType() != I_SLICE) |
|---|
| 600 | { |
|---|
| 601 | preColRefPOC = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx()); |
|---|
| 602 | if(currColRefPOC != preColRefPOC) |
|---|
| 603 | { |
|---|
| 604 | printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n"); |
|---|
| 605 | exit(EXIT_FAILURE); |
|---|
| 606 | } |
|---|
| 607 | else |
|---|
| 608 | { |
|---|
| 609 | break; |
|---|
| 610 | } |
|---|
| 611 | } |
|---|
| 612 | } |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic) |
|---|
| 616 | { |
|---|
| 617 | for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++) |
|---|
| 618 | { |
|---|
| 619 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
|---|
| 620 | { |
|---|
| 621 | assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA); |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++) |
|---|
| 625 | { |
|---|
| 626 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
|---|
| 627 | { |
|---|
| 628 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
|---|
| 629 | { |
|---|
| 630 | assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA); |
|---|
| 631 | } |
|---|
| 632 | else |
|---|
| 633 | { |
|---|
| 634 | assert(pReferencePictureSet->getPOC(i) >= pocCRA); |
|---|
| 635 | } |
|---|
| 636 | } |
|---|
| 637 | } |
|---|
| 638 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found |
|---|
| 639 | { |
|---|
| 640 | pocCRA = getPOC(); |
|---|
| 641 | prevRAPisBLA = false; |
|---|
| 642 | } |
|---|
| 643 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
|---|
| 644 | { |
|---|
| 645 | pocCRA = getPOC(); |
|---|
| 646 | prevRAPisBLA = false; |
|---|
| 647 | } |
|---|
| 648 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 649 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 650 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found |
|---|
| 651 | { |
|---|
| 652 | pocCRA = getPOC(); |
|---|
| 653 | prevRAPisBLA = true; |
|---|
| 654 | } |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | /** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered. |
|---|
| 658 | * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture |
|---|
| 659 | * \param bRefreshPending flag indicating if a deferred decoding refresh is pending |
|---|
| 660 | * \param rcListPic reference to the reference picture list |
|---|
| 661 | * This function marks the reference pictures as "unused for reference" in the following conditions. |
|---|
| 662 | * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list |
|---|
| 663 | * are marked as "unused for reference" |
|---|
| 664 | * If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture. |
|---|
| 665 | * Otherwise |
|---|
| 666 | * If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current |
|---|
| 667 | * temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA), |
|---|
| 668 | * mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set |
|---|
| 669 | * the bRefreshPending flag to false. |
|---|
| 670 | * If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal |
|---|
| 671 | * reference of the current picture. |
|---|
| 672 | * Note that the current picture is already placed in the reference list and its marking is not changed. |
|---|
| 673 | * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference". |
|---|
| 674 | */ |
|---|
| 675 | Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic) |
|---|
| 676 | { |
|---|
| 677 | TComPic* rpcPic; |
|---|
| 678 | Int pocCurr = getPOC(); |
|---|
| 679 | |
|---|
| 680 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 681 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 682 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
|---|
| 683 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
|---|
| 684 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR or BLA picture |
|---|
| 685 | { |
|---|
| 686 | // mark all pictures as not used for reference |
|---|
| 687 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 688 | while (iterPic != rcListPic.end()) |
|---|
| 689 | { |
|---|
| 690 | rpcPic = *(iterPic); |
|---|
| 691 | rpcPic->setCurrSliceIdx(0); |
|---|
| 692 | if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false); |
|---|
| 693 | iterPic++; |
|---|
| 694 | } |
|---|
| 695 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
|---|
| 696 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
|---|
| 697 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
|---|
| 698 | { |
|---|
| 699 | pocCRA = pocCurr; |
|---|
| 700 | } |
|---|
| 701 | } |
|---|
| 702 | else // CRA or No DR |
|---|
| 703 | { |
|---|
| 704 | if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending |
|---|
| 705 | { |
|---|
| 706 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 707 | while (iterPic != rcListPic.end()) |
|---|
| 708 | { |
|---|
| 709 | rpcPic = *(iterPic); |
|---|
| 710 | if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) |
|---|
| 711 | { |
|---|
| 712 | rpcPic->getSlice(0)->setReferenced(false); |
|---|
| 713 | } |
|---|
| 714 | iterPic++; |
|---|
| 715 | } |
|---|
| 716 | bRefreshPending = false; |
|---|
| 717 | } |
|---|
| 718 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
|---|
| 719 | { |
|---|
| 720 | bRefreshPending = true; |
|---|
| 721 | pocCRA = pocCurr; |
|---|
| 722 | } |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | Void TComSlice::copySliceInfo(TComSlice *pSrc) |
|---|
| 727 | { |
|---|
| 728 | assert( pSrc != NULL ); |
|---|
| 729 | |
|---|
| 730 | Int i, j, k; |
|---|
| 731 | |
|---|
| 732 | m_iPOC = pSrc->m_iPOC; |
|---|
| 733 | m_eNalUnitType = pSrc->m_eNalUnitType; |
|---|
| 734 | m_eSliceType = pSrc->m_eSliceType; |
|---|
| 735 | m_iSliceQp = pSrc->m_iSliceQp; |
|---|
| 736 | #if ADAPTIVE_QP_SELECTION |
|---|
| 737 | m_iSliceQpBase = pSrc->m_iSliceQpBase; |
|---|
| 738 | #endif |
|---|
| 739 | m_deblockingFilterDisable = pSrc->m_deblockingFilterDisable; |
|---|
| 740 | m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag; |
|---|
| 741 | m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2; |
|---|
| 742 | m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2; |
|---|
| 743 | |
|---|
| 744 | #if L0034_COMBINED_LIST_CLEANUP |
|---|
| 745 | for (i = 0; i < 2; i++) |
|---|
| 746 | #else |
|---|
| 747 | for (i = 0; i < 3; i++) |
|---|
| 748 | #endif |
|---|
| 749 | { |
|---|
| 750 | m_aiNumRefIdx[i] = pSrc->m_aiNumRefIdx[i]; |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | #if L0034_COMBINED_LIST_CLEANUP |
|---|
| 754 | for (i = 0; i < MAX_NUM_REF; i++) |
|---|
| 755 | { |
|---|
| 756 | m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i]; |
|---|
| 757 | } |
|---|
| 758 | #else |
|---|
| 759 | for (i = 0; i < 2; i++) |
|---|
| 760 | { |
|---|
| 761 | for (j = 0; j < MAX_NUM_REF_LC; j++) |
|---|
| 762 | { |
|---|
| 763 | m_iRefIdxOfLC[i][j] = pSrc->m_iRefIdxOfLC[i][j]; |
|---|
| 764 | } |
|---|
| 765 | } |
|---|
| 766 | for (i = 0; i < MAX_NUM_REF_LC; i++) |
|---|
| 767 | { |
|---|
| 768 | m_eListIdFromIdxOfLC[i] = pSrc->m_eListIdFromIdxOfLC[i]; |
|---|
| 769 | m_iRefIdxFromIdxOfLC[i] = pSrc->m_iRefIdxFromIdxOfLC[i]; |
|---|
| 770 | m_iRefIdxOfL1FromRefIdxOfL0[i] = pSrc->m_iRefIdxOfL1FromRefIdxOfL0[i]; |
|---|
| 771 | m_iRefIdxOfL0FromRefIdxOfL1[i] = pSrc->m_iRefIdxOfL0FromRefIdxOfL1[i]; |
|---|
| 772 | } |
|---|
| 773 | m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC; |
|---|
| 774 | m_bRefPicListCombinationFlag = pSrc->m_bRefPicListCombinationFlag; |
|---|
| 775 | #endif |
|---|
| 776 | m_bCheckLDC = pSrc->m_bCheckLDC; |
|---|
| 777 | m_iSliceQpDelta = pSrc->m_iSliceQpDelta; |
|---|
| 778 | m_iSliceQpDeltaCb = pSrc->m_iSliceQpDeltaCb; |
|---|
| 779 | m_iSliceQpDeltaCr = pSrc->m_iSliceQpDeltaCr; |
|---|
| 780 | for (i = 0; i < 2; i++) |
|---|
| 781 | { |
|---|
| 782 | for (j = 0; j < MAX_NUM_REF; j++) |
|---|
| 783 | { |
|---|
| 784 | m_apcRefPicList[i][j] = pSrc->m_apcRefPicList[i][j]; |
|---|
| 785 | m_aiRefPOCList[i][j] = pSrc->m_aiRefPOCList[i][j]; |
|---|
| 786 | } |
|---|
| 787 | } |
|---|
| 788 | for (i = 0; i < 2; i++) |
|---|
| 789 | { |
|---|
| 790 | for (j = 0; j < MAX_NUM_REF + 1; j++) |
|---|
| 791 | { |
|---|
| 792 | m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j]; |
|---|
| 793 | } |
|---|
| 794 | } |
|---|
| 795 | m_iDepth = pSrc->m_iDepth; |
|---|
| 796 | |
|---|
| 797 | // referenced slice |
|---|
| 798 | m_bRefenced = pSrc->m_bRefenced; |
|---|
| 799 | |
|---|
| 800 | // access channel |
|---|
| 801 | m_pcSPS = pSrc->m_pcSPS; |
|---|
| 802 | m_pcPPS = pSrc->m_pcPPS; |
|---|
| 803 | m_pcRPS = pSrc->m_pcRPS; |
|---|
| 804 | m_iLastIDR = pSrc->m_iLastIDR; |
|---|
| 805 | |
|---|
| 806 | m_pcPic = pSrc->m_pcPic; |
|---|
| 807 | |
|---|
| 808 | m_colFromL0Flag = pSrc->m_colFromL0Flag; |
|---|
| 809 | m_colRefIdx = pSrc->m_colRefIdx; |
|---|
| 810 | #if SAO_CHROMA_LAMBDA |
|---|
| 811 | m_dLambdaLuma = pSrc->m_dLambdaLuma; |
|---|
| 812 | m_dLambdaChroma = pSrc->m_dLambdaChroma; |
|---|
| 813 | #else |
|---|
| 814 | m_dLambda = pSrc->m_dLambda; |
|---|
| 815 | #endif |
|---|
| 816 | for (i = 0; i < 2; i++) |
|---|
| 817 | { |
|---|
| 818 | for (j = 0; j < MAX_NUM_REF; j++) |
|---|
| 819 | { |
|---|
| 820 | for (k =0; k < MAX_NUM_REF; k++) |
|---|
| 821 | { |
|---|
| 822 | m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k]; |
|---|
| 823 | } |
|---|
| 824 | } |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 828 | m_bNoBackPredFlag = pSrc->m_bNoBackPredFlag; |
|---|
| 829 | #endif |
|---|
| 830 | m_uiTLayer = pSrc->m_uiTLayer; |
|---|
| 831 | m_bTLayerSwitchingFlag = pSrc->m_bTLayerSwitchingFlag; |
|---|
| 832 | |
|---|
| 833 | m_sliceMode = pSrc->m_sliceMode; |
|---|
| 834 | m_sliceArgument = pSrc->m_sliceArgument; |
|---|
| 835 | m_sliceCurStartCUAddr = pSrc->m_sliceCurStartCUAddr; |
|---|
| 836 | m_sliceCurEndCUAddr = pSrc->m_sliceCurEndCUAddr; |
|---|
| 837 | m_sliceIdx = pSrc->m_sliceIdx; |
|---|
| 838 | m_sliceSegmentMode = pSrc->m_sliceSegmentMode; |
|---|
| 839 | m_sliceSegmentArgument = pSrc->m_sliceSegmentArgument; |
|---|
| 840 | m_sliceSegmentCurStartCUAddr = pSrc->m_sliceSegmentCurStartCUAddr; |
|---|
| 841 | m_sliceSegmentCurEndCUAddr = pSrc->m_sliceSegmentCurEndCUAddr; |
|---|
| 842 | m_nextSlice = pSrc->m_nextSlice; |
|---|
| 843 | m_nextSliceSegment = pSrc->m_nextSliceSegment; |
|---|
| 844 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 845 | { |
|---|
| 846 | for ( Int n=0 ; n<MAX_NUM_REF ; n++ ) |
|---|
| 847 | { |
|---|
| 848 | memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 ); |
|---|
| 849 | } |
|---|
| 850 | } |
|---|
| 851 | m_saoEnabledFlag = pSrc->m_saoEnabledFlag; |
|---|
| 852 | m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma; |
|---|
| 853 | m_cabacInitFlag = pSrc->m_cabacInitFlag; |
|---|
| 854 | m_numEntryPointOffsets = pSrc->m_numEntryPointOffsets; |
|---|
| 855 | |
|---|
| 856 | m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero; |
|---|
| 857 | m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag; |
|---|
| 858 | m_enableTMVPFlag = pSrc->m_enableTMVPFlag; |
|---|
| 859 | m_maxNumMergeCand = pSrc->m_maxNumMergeCand; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | Int TComSlice::m_prevPOC = 0; |
|---|
| 863 | |
|---|
| 864 | /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag. |
|---|
| 865 | * \param uiTLayer Temporal layer ID of the current slice |
|---|
| 866 | * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on |
|---|
| 867 | * the SPS's temporal_id_nesting_flag and the parsed PPS. Then, current slice's temporal layer ID and |
|---|
| 868 | * temporal_layer_switching_point_flag is set accordingly. |
|---|
| 869 | */ |
|---|
| 870 | Void TComSlice::setTLayerInfo( UInt uiTLayer ) |
|---|
| 871 | { |
|---|
| 872 | m_uiTLayer = uiTLayer; |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | /** Function for checking if this is a switching-point |
|---|
| 876 | */ |
|---|
| 877 | Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic ) |
|---|
| 878 | { |
|---|
| 879 | TComPic* rpcPic; |
|---|
| 880 | // loop through all pictures in the reference picture buffer |
|---|
| 881 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 882 | while ( iterPic != rcListPic.end()) |
|---|
| 883 | { |
|---|
| 884 | rpcPic = *(iterPic++); |
|---|
| 885 | if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC()) |
|---|
| 886 | { |
|---|
| 887 | if(rpcPic->getTLayer() >= getTLayer()) |
|---|
| 888 | { |
|---|
| 889 | return false; |
|---|
| 890 | } |
|---|
| 891 | } |
|---|
| 892 | } |
|---|
| 893 | return true; |
|---|
| 894 | } |
|---|
| 895 | |
|---|
| 896 | /** Function for checking if this is a STSA candidate |
|---|
| 897 | */ |
|---|
| 898 | Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ) |
|---|
| 899 | { |
|---|
| 900 | TComPic* rpcPic; |
|---|
| 901 | |
|---|
| 902 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 903 | while ( iterPic != rcListPic.end()) |
|---|
| 904 | { |
|---|
| 905 | rpcPic = *(iterPic++); |
|---|
| 906 | if(rpcPic->getSlice(0)->isReferenced() && (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC()) |
|---|
| 907 | { |
|---|
| 908 | if(rpcPic->getTLayer() >= getTLayer()) |
|---|
| 909 | { |
|---|
| 910 | return false; |
|---|
| 911 | } |
|---|
| 912 | } |
|---|
| 913 | } |
|---|
| 914 | return true; |
|---|
| 915 | } |
|---|
| 916 | |
|---|
| 917 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
|---|
| 918 | */ |
|---|
| 919 | Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
|---|
| 920 | { |
|---|
| 921 | TComPic* rpcPic; |
|---|
| 922 | Int i, isReference; |
|---|
| 923 | |
|---|
| 924 | // loop through all pictures in the reference picture buffer |
|---|
| 925 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 926 | while ( iterPic != rcListPic.end()) |
|---|
| 927 | { |
|---|
| 928 | rpcPic = *(iterPic++); |
|---|
| 929 | |
|---|
| 930 | if(!rpcPic->getSlice( 0 )->isReferenced()) |
|---|
| 931 | { |
|---|
| 932 | continue; |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | isReference = 0; |
|---|
| 936 | // loop through all pictures in the Reference Picture Set |
|---|
| 937 | // to see if the picture should be kept as reference picture |
|---|
| 938 | for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++) |
|---|
| 939 | { |
|---|
| 940 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i)) |
|---|
| 941 | { |
|---|
| 942 | isReference = 1; |
|---|
| 943 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 944 | rpcPic->setIsLongTerm(0); |
|---|
| 945 | } |
|---|
| 946 | } |
|---|
| 947 | for(;i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 948 | { |
|---|
| 949 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
|---|
| 950 | { |
|---|
| 951 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i)) |
|---|
| 952 | { |
|---|
| 953 | isReference = 1; |
|---|
| 954 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 955 | } |
|---|
| 956 | } |
|---|
| 957 | else |
|---|
| 958 | { |
|---|
| 959 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) |
|---|
| 960 | { |
|---|
| 961 | isReference = 1; |
|---|
| 962 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
|---|
| 963 | } |
|---|
| 964 | } |
|---|
| 965 | |
|---|
| 966 | } |
|---|
| 967 | // mark the picture as "unused for reference" if it is not in |
|---|
| 968 | // the Reference Picture Set |
|---|
| 969 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0) |
|---|
| 970 | { |
|---|
| 971 | rpcPic->getSlice( 0 )->setReferenced( false ); |
|---|
| 972 | rpcPic->setUsedByCurr(0); |
|---|
| 973 | rpcPic->setIsLongTerm(0); |
|---|
| 974 | } |
|---|
| 975 | //check that pictures of higher temporal layers are not used |
|---|
| 976 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); |
|---|
| 977 | //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture |
|---|
| 978 | if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) |
|---|
| 979 | { |
|---|
| 980 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); |
|---|
| 981 | } |
|---|
| 982 | //check that pictures marked as temporal layer non-reference pictures are not used for reference |
|---|
| 983 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer()) |
|---|
| 984 | { |
|---|
| 985 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false); |
|---|
| 986 | } |
|---|
| 987 | } |
|---|
| 988 | } |
|---|
| 989 | |
|---|
| 990 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
|---|
| 991 | */ |
|---|
| 992 | Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess) |
|---|
| 993 | { |
|---|
| 994 | TComPic* rpcPic; |
|---|
| 995 | Int i, isAvailable; |
|---|
| 996 | Int atLeastOneLost = 0; |
|---|
| 997 | Int atLeastOneRemoved = 0; |
|---|
| 998 | Int iPocLost = 0; |
|---|
| 999 | |
|---|
| 1000 | // loop through all long-term pictures in the Reference Picture Set |
|---|
| 1001 | // to see if the picture should be kept as reference picture |
|---|
| 1002 | for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 1003 | { |
|---|
| 1004 | isAvailable = 0; |
|---|
| 1005 | // loop through all pictures in the reference picture buffer |
|---|
| 1006 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1007 | while ( iterPic != rcListPic.end()) |
|---|
| 1008 | { |
|---|
| 1009 | rpcPic = *(iterPic++); |
|---|
| 1010 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
|---|
| 1011 | { |
|---|
| 1012 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1013 | { |
|---|
| 1014 | isAvailable = 1; |
|---|
| 1015 | } |
|---|
| 1016 | } |
|---|
| 1017 | else |
|---|
| 1018 | { |
|---|
| 1019 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1020 | { |
|---|
| 1021 | isAvailable = 1; |
|---|
| 1022 | } |
|---|
| 1023 | } |
|---|
| 1024 | } |
|---|
| 1025 | // if there was no such long-term check the short terms |
|---|
| 1026 | if(!isAvailable) |
|---|
| 1027 | { |
|---|
| 1028 | iterPic = rcListPic.begin(); |
|---|
| 1029 | while ( iterPic != rcListPic.end()) |
|---|
| 1030 | { |
|---|
| 1031 | rpcPic = *(iterPic++); |
|---|
| 1032 | |
|---|
| 1033 | Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
|---|
| 1034 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC(); |
|---|
| 1035 | Int refPoc = pReferencePictureSet->getPOC(i); |
|---|
| 1036 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
|---|
| 1037 | { |
|---|
| 1038 | curPoc = curPoc % pocCycle; |
|---|
| 1039 | refPoc = refPoc % pocCycle; |
|---|
| 1040 | } |
|---|
| 1041 | |
|---|
| 1042 | if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc) |
|---|
| 1043 | { |
|---|
| 1044 | isAvailable = 1; |
|---|
| 1045 | rpcPic->setIsLongTerm(1); |
|---|
| 1046 | break; |
|---|
| 1047 | } |
|---|
| 1048 | } |
|---|
| 1049 | } |
|---|
| 1050 | // report that a picture is lost if it is in the Reference Picture Set |
|---|
| 1051 | // but not available as reference picture |
|---|
| 1052 | if(isAvailable == 0) |
|---|
| 1053 | { |
|---|
| 1054 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
|---|
| 1055 | { |
|---|
| 1056 | if(!pReferencePictureSet->getUsed(i) ) |
|---|
| 1057 | { |
|---|
| 1058 | if(printErrors) |
|---|
| 1059 | { |
|---|
| 1060 | printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1061 | } |
|---|
| 1062 | atLeastOneRemoved = 1; |
|---|
| 1063 | } |
|---|
| 1064 | else |
|---|
| 1065 | { |
|---|
| 1066 | if(printErrors) |
|---|
| 1067 | { |
|---|
| 1068 | printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1069 | } |
|---|
| 1070 | atLeastOneLost = 1; |
|---|
| 1071 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
|---|
| 1072 | } |
|---|
| 1073 | } |
|---|
| 1074 | } |
|---|
| 1075 | } |
|---|
| 1076 | // loop through all short-term pictures in the Reference Picture Set |
|---|
| 1077 | // to see if the picture should be kept as reference picture |
|---|
| 1078 | for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++) |
|---|
| 1079 | { |
|---|
| 1080 | isAvailable = 0; |
|---|
| 1081 | // loop through all pictures in the reference picture buffer |
|---|
| 1082 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1083 | while ( iterPic != rcListPic.end()) |
|---|
| 1084 | { |
|---|
| 1085 | rpcPic = *(iterPic++); |
|---|
| 1086 | |
|---|
| 1087 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1088 | { |
|---|
| 1089 | isAvailable = 1; |
|---|
| 1090 | } |
|---|
| 1091 | } |
|---|
| 1092 | // report that a picture is lost if it is in the Reference Picture Set |
|---|
| 1093 | // but not available as reference picture |
|---|
| 1094 | if(isAvailable == 0) |
|---|
| 1095 | { |
|---|
| 1096 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
|---|
| 1097 | { |
|---|
| 1098 | if(!pReferencePictureSet->getUsed(i) ) |
|---|
| 1099 | { |
|---|
| 1100 | if(printErrors) |
|---|
| 1101 | { |
|---|
| 1102 | printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1103 | } |
|---|
| 1104 | atLeastOneRemoved = 1; |
|---|
| 1105 | } |
|---|
| 1106 | else |
|---|
| 1107 | { |
|---|
| 1108 | if(printErrors) |
|---|
| 1109 | { |
|---|
| 1110 | printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1111 | } |
|---|
| 1112 | atLeastOneLost = 1; |
|---|
| 1113 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
|---|
| 1114 | } |
|---|
| 1115 | } |
|---|
| 1116 | } |
|---|
| 1117 | } |
|---|
| 1118 | if(atLeastOneLost) |
|---|
| 1119 | { |
|---|
| 1120 | return iPocLost+1; |
|---|
| 1121 | } |
|---|
| 1122 | if(atLeastOneRemoved) |
|---|
| 1123 | { |
|---|
| 1124 | return -2; |
|---|
| 1125 | } |
|---|
| 1126 | else |
|---|
| 1127 | { |
|---|
| 1128 | return 0; |
|---|
| 1129 | } |
|---|
| 1130 | } |
|---|
| 1131 | |
|---|
| 1132 | /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set |
|---|
| 1133 | */ |
|---|
| 1134 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
|---|
| 1135 | { |
|---|
| 1136 | TComPic* rpcPic; |
|---|
| 1137 | Int i, j; |
|---|
| 1138 | Int k = 0; |
|---|
| 1139 | Int nrOfNegativePictures = 0; |
|---|
| 1140 | Int nrOfPositivePictures = 0; |
|---|
| 1141 | TComReferencePictureSet* pcRPS = this->getLocalRPS(); |
|---|
| 1142 | |
|---|
| 1143 | // loop through all pictures in the Reference Picture Set |
|---|
| 1144 | for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++) |
|---|
| 1145 | { |
|---|
| 1146 | j = 0; |
|---|
| 1147 | // loop through all pictures in the reference picture buffer |
|---|
| 1148 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
|---|
| 1149 | while ( iterPic != rcListPic.end()) |
|---|
| 1150 | { |
|---|
| 1151 | j++; |
|---|
| 1152 | rpcPic = *(iterPic++); |
|---|
| 1153 | |
|---|
| 1154 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
|---|
| 1155 | { |
|---|
| 1156 | // This picture exists as a reference picture |
|---|
| 1157 | // and should be added to the explicit Reference Picture Set |
|---|
| 1158 | pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); |
|---|
| 1159 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i)); |
|---|
| 1160 | if(pcRPS->getDeltaPOC(k) < 0) |
|---|
| 1161 | { |
|---|
| 1162 | nrOfNegativePictures++; |
|---|
| 1163 | } |
|---|
| 1164 | else |
|---|
| 1165 | { |
|---|
| 1166 | nrOfPositivePictures++; |
|---|
| 1167 | } |
|---|
| 1168 | k++; |
|---|
| 1169 | } |
|---|
| 1170 | } |
|---|
| 1171 | } |
|---|
| 1172 | pcRPS->setNumberOfNegativePictures(nrOfNegativePictures); |
|---|
| 1173 | pcRPS->setNumberOfPositivePictures(nrOfPositivePictures); |
|---|
| 1174 | pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures); |
|---|
| 1175 | // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the |
|---|
| 1176 | // inter RPS prediction with. Here we just use the reference used by pReferencePictureSet. |
|---|
| 1177 | // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled. |
|---|
| 1178 | if (!pReferencePictureSet->getInterRPSPrediction()) |
|---|
| 1179 | { |
|---|
| 1180 | pcRPS->setInterRPSPrediction(false); |
|---|
| 1181 | pcRPS->setNumRefIdc(0); |
|---|
| 1182 | } |
|---|
| 1183 | else |
|---|
| 1184 | { |
|---|
| 1185 | Int rIdx = this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1; |
|---|
| 1186 | Int deltaRPS = pReferencePictureSet->getDeltaRPS(); |
|---|
| 1187 | TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx); |
|---|
| 1188 | Int iRefPics = pcRefRPS->getNumberOfPictures(); |
|---|
| 1189 | Int iNewIdc=0; |
|---|
| 1190 | for(i=0; i<= iRefPics; i++) |
|---|
| 1191 | { |
|---|
| 1192 | Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0); // check if the reference abs POC is >= 0 |
|---|
| 1193 | Int iRefIdc = 0; |
|---|
| 1194 | for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the pictures in the new RPS |
|---|
| 1195 | { |
|---|
| 1196 | if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j)) |
|---|
| 1197 | { |
|---|
| 1198 | if (pcRPS->getUsed(j)) |
|---|
| 1199 | { |
|---|
| 1200 | iRefIdc = 1; |
|---|
| 1201 | } |
|---|
| 1202 | else |
|---|
| 1203 | { |
|---|
| 1204 | iRefIdc = 2; |
|---|
| 1205 | } |
|---|
| 1206 | } |
|---|
| 1207 | } |
|---|
| 1208 | pcRPS->setRefIdc(i, iRefIdc); |
|---|
| 1209 | iNewIdc++; |
|---|
| 1210 | } |
|---|
| 1211 | pcRPS->setInterRPSPrediction(true); |
|---|
| 1212 | pcRPS->setNumRefIdc(iNewIdc); |
|---|
| 1213 | pcRPS->setDeltaRPS(deltaRPS); |
|---|
| 1214 | pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx()); |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | this->setRPS(pcRPS); |
|---|
| 1218 | this->setRPSidx(-1); |
|---|
| 1219 | } |
|---|
| 1220 | |
|---|
| 1221 | /** get AC and DC values for weighted pred |
|---|
| 1222 | * \param *wp |
|---|
| 1223 | * \returns Void |
|---|
| 1224 | */ |
|---|
| 1225 | Void TComSlice::getWpAcDcParam(wpACDCParam *&wp) |
|---|
| 1226 | { |
|---|
| 1227 | wp = m_weightACDCParam; |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | /** init AC and DC values for weighted pred |
|---|
| 1231 | * \returns Void |
|---|
| 1232 | */ |
|---|
| 1233 | Void TComSlice::initWpAcDcParam() |
|---|
| 1234 | { |
|---|
| 1235 | for(Int iComp = 0; iComp < 3; iComp++ ) |
|---|
| 1236 | { |
|---|
| 1237 | m_weightACDCParam[iComp].iAC = 0; |
|---|
| 1238 | m_weightACDCParam[iComp].iDC = 0; |
|---|
| 1239 | } |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | /** get WP tables for weighted pred |
|---|
| 1243 | * \param RefPicList |
|---|
| 1244 | * \param iRefIdx |
|---|
| 1245 | * \param *&wpScalingParam |
|---|
| 1246 | * \returns Void |
|---|
| 1247 | */ |
|---|
| 1248 | Void TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp ) |
|---|
| 1249 | { |
|---|
| 1250 | wp = m_weightPredTable[e][iRefIdx]; |
|---|
| 1251 | } |
|---|
| 1252 | |
|---|
| 1253 | /** reset Default WP tables settings : no weight. |
|---|
| 1254 | * \param wpScalingParam |
|---|
| 1255 | * \returns Void |
|---|
| 1256 | */ |
|---|
| 1257 | Void TComSlice::resetWpScaling() |
|---|
| 1258 | { |
|---|
| 1259 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 1260 | { |
|---|
| 1261 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
|---|
| 1262 | { |
|---|
| 1263 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
|---|
| 1264 | { |
|---|
| 1265 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
|---|
| 1266 | pwp->bPresentFlag = false; |
|---|
| 1267 | pwp->uiLog2WeightDenom = 0; |
|---|
| 1268 | pwp->uiLog2WeightDenom = 0; |
|---|
| 1269 | pwp->iWeight = 1; |
|---|
| 1270 | pwp->iOffset = 0; |
|---|
| 1271 | } |
|---|
| 1272 | } |
|---|
| 1273 | } |
|---|
| 1274 | } |
|---|
| 1275 | |
|---|
| 1276 | /** init WP table |
|---|
| 1277 | * \returns Void |
|---|
| 1278 | */ |
|---|
| 1279 | Void TComSlice::initWpScaling() |
|---|
| 1280 | { |
|---|
| 1281 | for ( Int e=0 ; e<2 ; e++ ) |
|---|
| 1282 | { |
|---|
| 1283 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
|---|
| 1284 | { |
|---|
| 1285 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
|---|
| 1286 | { |
|---|
| 1287 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
|---|
| 1288 | if ( !pwp->bPresentFlag ) |
|---|
| 1289 | { |
|---|
| 1290 | // Inferring values not present : |
|---|
| 1291 | pwp->iWeight = (1 << pwp->uiLog2WeightDenom); |
|---|
| 1292 | pwp->iOffset = 0; |
|---|
| 1293 | } |
|---|
| 1294 | |
|---|
| 1295 | pwp->w = pwp->iWeight; |
|---|
| 1296 | Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; |
|---|
| 1297 | pwp->o = pwp->iOffset << (bitDepth-8); |
|---|
| 1298 | pwp->shift = pwp->uiLog2WeightDenom; |
|---|
| 1299 | pwp->round = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0); |
|---|
| 1300 | } |
|---|
| 1301 | } |
|---|
| 1302 | } |
|---|
| 1303 | } |
|---|
| 1304 | |
|---|
| 1305 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1306 | // Video parameter set (VPS) |
|---|
| 1307 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1308 | TComVPS::TComVPS() |
|---|
| 1309 | : m_VPSId ( 0) |
|---|
| 1310 | , m_uiMaxTLayers ( 1) |
|---|
| 1311 | , m_uiMaxLayers ( 1) |
|---|
| 1312 | , m_bTemporalIdNestingFlag (false) |
|---|
| 1313 | , m_numHrdParameters ( 0) |
|---|
| 1314 | , m_maxNuhReservedZeroLayerId ( 0) |
|---|
| 1315 | , m_hrdParameters (NULL) |
|---|
| 1316 | , m_hrdOpSetIdx (NULL) |
|---|
| 1317 | , m_cprmsPresentFlag (NULL) |
|---|
| 1318 | { |
|---|
| 1319 | for( Int i = 0; i < MAX_TLAYER; i++) |
|---|
| 1320 | { |
|---|
| 1321 | m_numReorderPics[i] = 0; |
|---|
| 1322 | #if L0323_DPB |
|---|
| 1323 | m_uiMaxDecPicBuffering[i] = 1; |
|---|
| 1324 | #else |
|---|
| 1325 | m_uiMaxDecPicBuffering[i] = 0; |
|---|
| 1326 | #endif |
|---|
| 1327 | m_uiMaxLatencyIncrease[i] = 0; |
|---|
| 1328 | } |
|---|
| 1329 | } |
|---|
| 1330 | |
|---|
| 1331 | TComVPS::~TComVPS() |
|---|
| 1332 | { |
|---|
| 1333 | if( m_hrdParameters != NULL ) delete[] m_hrdParameters; |
|---|
| 1334 | if( m_hrdOpSetIdx != NULL ) delete[] m_hrdOpSetIdx; |
|---|
| 1335 | if( m_cprmsPresentFlag != NULL ) delete[] m_cprmsPresentFlag; |
|---|
| 1336 | } |
|---|
| 1337 | |
|---|
| 1338 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1339 | // Sequence parameter set (SPS) |
|---|
| 1340 | // ------------------------------------------------------------------------------------------------ |
|---|
| 1341 | |
|---|
| 1342 | TComSPS::TComSPS() |
|---|
| 1343 | : m_SPSId ( 0) |
|---|
| 1344 | , m_VPSId ( 0) |
|---|
| 1345 | , m_chromaFormatIdc (CHROMA_420) |
|---|
| 1346 | , m_uiMaxTLayers ( 1) |
|---|
| 1347 | // Structure |
|---|
| 1348 | , m_picWidthInLumaSamples (352) |
|---|
| 1349 | , m_picHeightInLumaSamples (288) |
|---|
| 1350 | , m_log2MinCodingBlockSize ( 0) |
|---|
| 1351 | , m_log2DiffMaxMinCodingBlockSize (0) |
|---|
| 1352 | , m_uiMaxCUWidth ( 32) |
|---|
| 1353 | , m_uiMaxCUHeight ( 32) |
|---|
| 1354 | , m_uiMaxCUDepth ( 3) |
|---|
| 1355 | , m_bLongTermRefsPresent (false) |
|---|
| 1356 | , m_uiQuadtreeTULog2MaxSize ( 0) |
|---|
| 1357 | , m_uiQuadtreeTULog2MinSize ( 0) |
|---|
| 1358 | , m_uiQuadtreeTUMaxDepthInter ( 0) |
|---|
| 1359 | , m_uiQuadtreeTUMaxDepthIntra ( 0) |
|---|
| 1360 | // Tool list |
|---|
| 1361 | , m_usePCM (false) |
|---|
| 1362 | , m_pcmLog2MaxSize ( 5) |
|---|
| 1363 | , m_uiPCMLog2MinSize ( 7) |
|---|
| 1364 | #if !L0034_COMBINED_LIST_CLEANUP |
|---|
| 1365 | , m_bUseLComb (false) |
|---|
| 1366 | #endif |
|---|
| 1367 | , m_bitDepthY ( 8) |
|---|
| 1368 | , m_bitDepthC ( 8) |
|---|
| 1369 | , m_qpBDOffsetY ( 0) |
|---|
| 1370 | , m_qpBDOffsetC ( 0) |
|---|
| 1371 | , m_useLossless (false) |
|---|
| 1372 | , m_uiPCMBitDepthLuma ( 8) |
|---|
| 1373 | , m_uiPCMBitDepthChroma ( 8) |
|---|
| 1374 | , m_bPCMFilterDisableFlag (false) |
|---|
| 1375 | , m_uiBitsForPOC ( 8) |
|---|
| 1376 | , m_numLongTermRefPicSPS ( 0) |
|---|
| 1377 | , m_uiMaxTrSize ( 32) |
|---|
| 1378 | , m_bUseSAO (false) |
|---|
| 1379 | , m_bTemporalIdNestingFlag (false) |
|---|
| 1380 | , m_scalingListEnabledFlag (false) |
|---|
| 1381 | , m_useStrongIntraSmoothing (false) |
|---|
| 1382 | , m_vuiParametersPresentFlag (false) |
|---|
| 1383 | , m_vuiParameters () |
|---|
| 1384 | { |
|---|
| 1385 | for ( Int i = 0; i < MAX_TLAYER; i++ ) |
|---|
| 1386 | { |
|---|
| 1387 | m_uiMaxLatencyIncrease[i] = 0; |
|---|
| 1388 | #if L0323_DPB |
|---|
| 1389 | m_uiMaxDecPicBuffering[i] = 1; |
|---|
| 1390 | #else |
|---|
| 1391 | m_uiMaxDecPicBuffering[i] = 0; |
|---|
| 1392 | #endif |
|---|
| 1393 | m_numReorderPics[i] = 0; |
|---|
| 1394 | } |
|---|
| 1395 | m_scalingList = new TComScalingList; |
|---|
| 1396 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
|---|
| 1397 | ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag)); |
|---|
| 1398 | } |
|---|
| 1399 | |
|---|
| 1400 | TComSPS::~TComSPS() |
|---|
| 1401 | { |
|---|
| 1402 | delete m_scalingList; |
|---|
| 1403 | m_RPSList.destroy(); |
|---|
| 1404 | } |
|---|
| 1405 | |
|---|
| 1406 | Void TComSPS::createRPSList( Int numRPS ) |
|---|
| 1407 | { |
|---|
| 1408 | m_RPSList.destroy(); |
|---|
| 1409 | m_RPSList.create(numRPS); |
|---|
| 1410 | } |
|---|
| 1411 | |
|---|
| 1412 | Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess ) |
|---|
| 1413 | { |
|---|
| 1414 | if( !getVuiParametersPresentFlag() ) |
|---|
| 1415 | { |
|---|
| 1416 | return; |
|---|
| 1417 | } |
|---|
| 1418 | |
|---|
| 1419 | TComVUI *vui = getVuiParameters(); |
|---|
| 1420 | TComHRD *hrd = vui->getHrdParameters(); |
|---|
| 1421 | |
|---|
| 1422 | #if L0043_TIMING_INFO |
|---|
| 1423 | TimingInfo *timingInfo = vui->getTimingInfo(); |
|---|
| 1424 | timingInfo->setTimingInfoPresentFlag( true ); |
|---|
| 1425 | switch( frameRate ) |
|---|
| 1426 | { |
|---|
| 1427 | case 24: |
|---|
| 1428 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 1429 | break; |
|---|
| 1430 | case 25: |
|---|
| 1431 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 1432 | break; |
|---|
| 1433 | case 30: |
|---|
| 1434 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 1435 | break; |
|---|
| 1436 | case 50: |
|---|
| 1437 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 1438 | break; |
|---|
| 1439 | case 60: |
|---|
| 1440 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
|---|
| 1441 | break; |
|---|
| 1442 | default: |
|---|
| 1443 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
|---|
| 1444 | break; |
|---|
| 1445 | } |
|---|
| 1446 | #else |
|---|
| 1447 | hrd->setTimingInfoPresentFlag( true ); |
|---|
| 1448 | switch( frameRate ) |
|---|
| 1449 | { |
|---|
| 1450 | case 24: |
|---|
| 1451 | hrd->setNumUnitsInTick( 1125000 ); hrd->setTimeScale ( 27000000 ); |
|---|
| 1452 | break; |
|---|
| 1453 | case 25: |
|---|
| 1454 | hrd->setNumUnitsInTick( 1080000 ); hrd->setTimeScale ( 27000000 ); |
|---|
| 1455 | break; |
|---|
| 1456 | case 30: |
|---|
| 1457 | hrd->setNumUnitsInTick( 900900 ); hrd->setTimeScale ( 27000000 ); |
|---|
| 1458 | break; |
|---|
| 1459 | case 50: |
|---|
| 1460 | hrd->setNumUnitsInTick( 540000 ); hrd->setTimeScale ( 27000000 ); |
|---|
| 1461 | break; |
|---|
| 1462 | case 60: |
|---|
| 1463 | hrd->setNumUnitsInTick( 450450 ); hrd->setTimeScale ( 27000000 ); |
|---|
| 1464 | break; |
|---|
| 1465 | default: |
|---|
| 1466 | hrd->setNumUnitsInTick( 1001 ); hrd->setTimeScale ( 60000 ); |
|---|
| 1467 | break; |
|---|
| 1468 | } |
|---|
| 1469 | #endif |
|---|
| 1470 | |
|---|
| 1471 | Bool rateCnt = ( bitRate > 0 ); |
|---|
| 1472 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
|---|
| 1473 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
|---|
| 1474 | |
|---|
| 1475 | hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) ); |
|---|
| 1476 | |
|---|
| 1477 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
|---|
| 1478 | { |
|---|
| 1479 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
|---|
| 1480 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
|---|
| 1481 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
|---|
| 1482 | #if L0044_DU_DPB_OUTPUT_DELAY_HRD |
|---|
| 1483 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
|---|
| 1484 | #endif |
|---|
| 1485 | } |
|---|
| 1486 | else |
|---|
| 1487 | { |
|---|
| 1488 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
|---|
| 1489 | } |
|---|
| 1490 | |
|---|
| 1491 | hrd->setBitRateScale( 4 ); // in units of 2~( 6 + 4 ) = 1,024 bps |
|---|
| 1492 | hrd->setCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
|---|
| 1493 | hrd->setDuCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
|---|
| 1494 | |
|---|
| 1495 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
|---|
| 1496 | if( randomAccess ) |
|---|
| 1497 | { |
|---|
| 1498 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
|---|
| 1499 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
|---|
| 1500 | } |
|---|
| 1501 | else |
|---|
| 1502 | { |
|---|
| 1503 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
|---|
| 1504 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
|---|
| 1505 | } |
|---|
| 1506 | |
|---|
| 1507 | /* |
|---|
| 1508 | Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported. |
|---|
| 1509 | */ |
|---|
| 1510 | Int i, j; |
|---|
| 1511 | UInt birateValue, cpbSizeValue; |
|---|
| 1512 | UInt ducpbSizeValue; |
|---|
| 1513 | #if L0363_DU_BIT_RATE |
|---|
| 1514 | UInt duBitRateValue = 0; |
|---|
| 1515 | #endif |
|---|
| 1516 | |
|---|
| 1517 | for( i = 0; i < MAX_TLAYER; i ++ ) |
|---|
| 1518 | { |
|---|
| 1519 | hrd->setFixedPicRateFlag( i, 1 ); |
|---|
| 1520 | hrd->setPicDurationInTcMinus1( i, 0 ); |
|---|
| 1521 | hrd->setLowDelayHrdFlag( i, 0 ); |
|---|
| 1522 | hrd->setCpbCntMinus1( i, 0 ); |
|---|
| 1523 | |
|---|
| 1524 | birateValue = bitRate; |
|---|
| 1525 | cpbSizeValue = bitRate; // 1 second |
|---|
| 1526 | ducpbSizeValue = bitRate/numDU; |
|---|
| 1527 | #if L0363_DU_BIT_RATE |
|---|
| 1528 | duBitRateValue = bitRate; |
|---|
| 1529 | #endif |
|---|
| 1530 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
|---|
| 1531 | { |
|---|
| 1532 | hrd->setBitRateValueMinus1( i, j, 0, ( birateValue - 1 ) ); |
|---|
| 1533 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
|---|
| 1534 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) ); |
|---|
| 1535 | hrd->setCbrFlag( i, j, 0, ( j == 0 ) ); |
|---|
| 1536 | |
|---|
| 1537 | hrd->setBitRateValueMinus1( i, j, 1, ( birateValue - 1) ); |
|---|
| 1538 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
|---|
| 1539 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) ); |
|---|
| 1540 | #if L0363_DU_BIT_RATE |
|---|
| 1541 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
|---|
| 1542 | #endif |
|---|
| 1543 | hrd->setCbrFlag( i, j, 1, ( j == 0 ) ); |
|---|
| 1544 | } |
|---|
| 1545 | } |
|---|
| 1546 | } |
|---|
| 1547 | const Int TComSPS::m_winUnitX[]={1,2,2,1}; |
|---|
| 1548 | const Int TComSPS::m_winUnitY[]={1,2,1,1}; |
|---|
| 1549 | |
|---|
| 1550 | TComPPS::TComPPS() |
|---|
| 1551 | : m_PPSId (0) |
|---|
| 1552 | , m_SPSId (0) |
|---|
| 1553 | , m_picInitQPMinus26 (0) |
|---|
| 1554 | , m_useDQP (false) |
|---|
| 1555 | , m_bConstrainedIntraPred (false) |
|---|
| 1556 | , m_bSliceChromaQpFlag (false) |
|---|
| 1557 | , m_pcSPS (NULL) |
|---|
| 1558 | , m_uiMaxCuDQPDepth (0) |
|---|
| 1559 | , m_uiMinCuDQPSize (0) |
|---|
| 1560 | , m_chromaCbQpOffset (0) |
|---|
| 1561 | , m_chromaCrQpOffset (0) |
|---|
| 1562 | , m_numRefIdxL0DefaultActive (1) |
|---|
| 1563 | , m_numRefIdxL1DefaultActive (1) |
|---|
| 1564 | , m_TransquantBypassEnableFlag (false) |
|---|
| 1565 | , m_useTransformSkip (false) |
|---|
| 1566 | , m_dependentSliceSegmentsEnabledFlag (false) |
|---|
| 1567 | , m_tilesEnabledFlag (false) |
|---|
| 1568 | , m_entropyCodingSyncEnabledFlag (false) |
|---|
| 1569 | , m_loopFilterAcrossTilesEnabledFlag (true) |
|---|
| 1570 | , m_uniformSpacingFlag (0) |
|---|
| 1571 | , m_iNumColumnsMinus1 (0) |
|---|
| 1572 | , m_puiColumnWidth (NULL) |
|---|
| 1573 | , m_iNumRowsMinus1 (0) |
|---|
| 1574 | , m_puiRowHeight (NULL) |
|---|
| 1575 | , m_iNumSubstreams (1) |
|---|
| 1576 | , m_signHideFlag(0) |
|---|
| 1577 | , m_cabacInitPresentFlag (false) |
|---|
| 1578 | , m_encCABACTableIdx (I_SLICE) |
|---|
| 1579 | , m_sliceHeaderExtensionPresentFlag (false) |
|---|
| 1580 | , m_loopFilterAcrossSlicesEnabledFlag (false) |
|---|
| 1581 | , m_listsModificationPresentFlag( 0) |
|---|
| 1582 | , m_numExtraSliceHeaderBits(0) |
|---|
| 1583 | { |
|---|
| 1584 | m_scalingList = new TComScalingList; |
|---|
| 1585 | } |
|---|
| 1586 | |
|---|
| 1587 | TComPPS::~TComPPS() |
|---|
| 1588 | { |
|---|
| 1589 | if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
|---|
| 1590 | { |
|---|
| 1591 | if (m_puiColumnWidth) delete [] m_puiColumnWidth; |
|---|
| 1592 | m_puiColumnWidth = NULL; |
|---|
| 1593 | } |
|---|
| 1594 | if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
|---|
| 1595 | { |
|---|
| 1596 | if (m_puiRowHeight) delete [] m_puiRowHeight; |
|---|
| 1597 | m_puiRowHeight = NULL; |
|---|
| 1598 | } |
|---|
| 1599 | delete m_scalingList; |
|---|
| 1600 | } |
|---|
| 1601 | |
|---|
| 1602 | TComReferencePictureSet::TComReferencePictureSet() |
|---|
| 1603 | : m_numberOfPictures (0) |
|---|
| 1604 | , m_numberOfNegativePictures (0) |
|---|
| 1605 | , m_numberOfPositivePictures (0) |
|---|
| 1606 | , m_numberOfLongtermPictures (0) |
|---|
| 1607 | , m_interRPSPrediction (0) |
|---|
| 1608 | , m_deltaRIdxMinus1 (0) |
|---|
| 1609 | , m_deltaRPS (0) |
|---|
| 1610 | , m_numRefIdc (0) |
|---|
| 1611 | { |
|---|
| 1612 | ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) ); |
|---|
| 1613 | ::memset( m_POC, 0, sizeof(m_POC) ); |
|---|
| 1614 | ::memset( m_used, 0, sizeof(m_used) ); |
|---|
| 1615 | ::memset( m_refIdc, 0, sizeof(m_refIdc) ); |
|---|
| 1616 | } |
|---|
| 1617 | |
|---|
| 1618 | TComReferencePictureSet::~TComReferencePictureSet() |
|---|
| 1619 | { |
|---|
| 1620 | } |
|---|
| 1621 | |
|---|
| 1622 | Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used) |
|---|
| 1623 | { |
|---|
| 1624 | m_used[bufferNum] = used; |
|---|
| 1625 | } |
|---|
| 1626 | |
|---|
| 1627 | Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC) |
|---|
| 1628 | { |
|---|
| 1629 | m_deltaPOC[bufferNum] = deltaPOC; |
|---|
| 1630 | } |
|---|
| 1631 | |
|---|
| 1632 | Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures) |
|---|
| 1633 | { |
|---|
| 1634 | m_numberOfPictures = numberOfPictures; |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | Int TComReferencePictureSet::getUsed(Int bufferNum) |
|---|
| 1638 | { |
|---|
| 1639 | return m_used[bufferNum]; |
|---|
| 1640 | } |
|---|
| 1641 | |
|---|
| 1642 | Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) |
|---|
| 1643 | { |
|---|
| 1644 | return m_deltaPOC[bufferNum]; |
|---|
| 1645 | } |
|---|
| 1646 | |
|---|
| 1647 | Int TComReferencePictureSet::getNumberOfPictures() |
|---|
| 1648 | { |
|---|
| 1649 | return m_numberOfPictures; |
|---|
| 1650 | } |
|---|
| 1651 | |
|---|
| 1652 | Int TComReferencePictureSet::getPOC(Int bufferNum) |
|---|
| 1653 | { |
|---|
| 1654 | return m_POC[bufferNum]; |
|---|
| 1655 | } |
|---|
| 1656 | |
|---|
| 1657 | Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC) |
|---|
| 1658 | { |
|---|
| 1659 | m_POC[bufferNum] = POC; |
|---|
| 1660 | } |
|---|
| 1661 | |
|---|
| 1662 | Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) |
|---|
| 1663 | { |
|---|
| 1664 | return m_bCheckLTMSB[bufferNum]; |
|---|
| 1665 | } |
|---|
| 1666 | |
|---|
| 1667 | Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b) |
|---|
| 1668 | { |
|---|
| 1669 | m_bCheckLTMSB[bufferNum] = b; |
|---|
| 1670 | } |
|---|
| 1671 | |
|---|
| 1672 | /** set the reference idc value at uiBufferNum entry to the value of iRefIdc |
|---|
| 1673 | * \param uiBufferNum |
|---|
| 1674 | * \param iRefIdc |
|---|
| 1675 | * \returns Void |
|---|
| 1676 | */ |
|---|
| 1677 | Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc) |
|---|
| 1678 | { |
|---|
| 1679 | m_refIdc[bufferNum] = refIdc; |
|---|
| 1680 | } |
|---|
| 1681 | |
|---|
| 1682 | /** get the reference idc value at uiBufferNum |
|---|
| 1683 | * \param uiBufferNum |
|---|
| 1684 | * \returns Int |
|---|
| 1685 | */ |
|---|
| 1686 | Int TComReferencePictureSet::getRefIdc(Int bufferNum) |
|---|
| 1687 | { |
|---|
| 1688 | return m_refIdc[bufferNum]; |
|---|
| 1689 | } |
|---|
| 1690 | |
|---|
| 1691 | /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values. |
|---|
| 1692 | * deltaPOC values are sorted with -ve values before the +ve values. -ve values are in decreasing order. |
|---|
| 1693 | * +ve values are in increasing order. |
|---|
| 1694 | * \returns Void |
|---|
| 1695 | */ |
|---|
| 1696 | Void TComReferencePictureSet::sortDeltaPOC() |
|---|
| 1697 | { |
|---|
| 1698 | // sort in increasing order (smallest first) |
|---|
| 1699 | for(Int j=1; j < getNumberOfPictures(); j++) |
|---|
| 1700 | { |
|---|
| 1701 | Int deltaPOC = getDeltaPOC(j); |
|---|
| 1702 | Bool used = getUsed(j); |
|---|
| 1703 | for (Int k=j-1; k >= 0; k--) |
|---|
| 1704 | { |
|---|
| 1705 | Int temp = getDeltaPOC(k); |
|---|
| 1706 | if (deltaPOC < temp) |
|---|
| 1707 | { |
|---|
| 1708 | setDeltaPOC(k+1, temp); |
|---|
| 1709 | setUsed(k+1, getUsed(k)); |
|---|
| 1710 | setDeltaPOC(k, deltaPOC); |
|---|
| 1711 | setUsed(k, used); |
|---|
| 1712 | } |
|---|
| 1713 | } |
|---|
| 1714 | } |
|---|
| 1715 | // flip the negative values to largest first |
|---|
| 1716 | Int numNegPics = getNumberOfNegativePictures(); |
|---|
| 1717 | for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--) |
|---|
| 1718 | { |
|---|
| 1719 | Int deltaPOC = getDeltaPOC(j); |
|---|
| 1720 | Bool used = getUsed(j); |
|---|
| 1721 | setDeltaPOC(j, getDeltaPOC(k)); |
|---|
| 1722 | setUsed(j, getUsed(k)); |
|---|
| 1723 | setDeltaPOC(k, deltaPOC); |
|---|
| 1724 | setUsed(k, used); |
|---|
| 1725 | } |
|---|
| 1726 | } |
|---|
| 1727 | |
|---|
| 1728 | /** Prints the deltaPOC and RefIdc (if available) values in the RPS. |
|---|
| 1729 | * A "*" is added to the deltaPOC value if it is Used bu current. |
|---|
| 1730 | * \returns Void |
|---|
| 1731 | */ |
|---|
| 1732 | Void TComReferencePictureSet::printDeltaPOC() |
|---|
| 1733 | { |
|---|
| 1734 | printf("DeltaPOC = { "); |
|---|
| 1735 | for(Int j=0; j < getNumberOfPictures(); j++) |
|---|
| 1736 | { |
|---|
| 1737 | printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":""); |
|---|
| 1738 | } |
|---|
| 1739 | if (getInterRPSPrediction()) |
|---|
| 1740 | { |
|---|
| 1741 | printf("}, RefIdc = { "); |
|---|
| 1742 | for(Int j=0; j < getNumRefIdc(); j++) |
|---|
| 1743 | { |
|---|
| 1744 | printf("%d ", getRefIdc(j)); |
|---|
| 1745 | } |
|---|
| 1746 | } |
|---|
| 1747 | printf("}\n"); |
|---|
| 1748 | } |
|---|
| 1749 | |
|---|
| 1750 | TComRPSList::TComRPSList() |
|---|
| 1751 | :m_referencePictureSets (NULL) |
|---|
| 1752 | { |
|---|
| 1753 | } |
|---|
| 1754 | |
|---|
| 1755 | TComRPSList::~TComRPSList() |
|---|
| 1756 | { |
|---|
| 1757 | } |
|---|
| 1758 | |
|---|
| 1759 | Void TComRPSList::create( Int numberOfReferencePictureSets) |
|---|
| 1760 | { |
|---|
| 1761 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
|---|
| 1762 | m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets]; |
|---|
| 1763 | } |
|---|
| 1764 | |
|---|
| 1765 | Void TComRPSList::destroy() |
|---|
| 1766 | { |
|---|
| 1767 | if (m_referencePictureSets) |
|---|
| 1768 | { |
|---|
| 1769 | delete [] m_referencePictureSets; |
|---|
| 1770 | } |
|---|
| 1771 | m_numberOfReferencePictureSets = 0; |
|---|
| 1772 | m_referencePictureSets = NULL; |
|---|
| 1773 | } |
|---|
| 1774 | |
|---|
| 1775 | |
|---|
| 1776 | |
|---|
| 1777 | TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum) |
|---|
| 1778 | { |
|---|
| 1779 | return &m_referencePictureSets[referencePictureSetNum]; |
|---|
| 1780 | } |
|---|
| 1781 | |
|---|
| 1782 | Int TComRPSList::getNumberOfReferencePictureSets() |
|---|
| 1783 | { |
|---|
| 1784 | return m_numberOfReferencePictureSets; |
|---|
| 1785 | } |
|---|
| 1786 | |
|---|
| 1787 | Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets) |
|---|
| 1788 | { |
|---|
| 1789 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
|---|
| 1790 | } |
|---|
| 1791 | |
|---|
| 1792 | TComRefPicListModification::TComRefPicListModification() |
|---|
| 1793 | : m_bRefPicListModificationFlagL0 (false) |
|---|
| 1794 | , m_bRefPicListModificationFlagL1 (false) |
|---|
| 1795 | { |
|---|
| 1796 | ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) ); |
|---|
| 1797 | ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) ); |
|---|
| 1798 | } |
|---|
| 1799 | |
|---|
| 1800 | TComRefPicListModification::~TComRefPicListModification() |
|---|
| 1801 | { |
|---|
| 1802 | } |
|---|
| 1803 | |
|---|
| 1804 | TComScalingList::TComScalingList() |
|---|
| 1805 | { |
|---|
| 1806 | m_useTransformSkip = false; |
|---|
| 1807 | init(); |
|---|
| 1808 | } |
|---|
| 1809 | TComScalingList::~TComScalingList() |
|---|
| 1810 | { |
|---|
| 1811 | destroy(); |
|---|
| 1812 | } |
|---|
| 1813 | |
|---|
| 1814 | /** set default quantization matrix to array |
|---|
| 1815 | */ |
|---|
| 1816 | Void TComSlice::setDefaultScalingList() |
|---|
| 1817 | { |
|---|
| 1818 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 1819 | { |
|---|
| 1820 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
|---|
| 1821 | { |
|---|
| 1822 | getScalingList()->processDefaultMarix(sizeId, listId); |
|---|
| 1823 | } |
|---|
| 1824 | } |
|---|
| 1825 | } |
|---|
| 1826 | /** check if use default quantization matrix |
|---|
| 1827 | * \returns true if use default quantization matrix in all size |
|---|
| 1828 | */ |
|---|
| 1829 | Bool TComSlice::checkDefaultScalingList() |
|---|
| 1830 | { |
|---|
| 1831 | UInt defaultCounter=0; |
|---|
| 1832 | |
|---|
| 1833 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 1834 | { |
|---|
| 1835 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
|---|
| 1836 | { |
|---|
| 1837 | 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 |
|---|
| 1838 | && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value |
|---|
| 1839 | { |
|---|
| 1840 | defaultCounter++; |
|---|
| 1841 | } |
|---|
| 1842 | } |
|---|
| 1843 | } |
|---|
| 1844 | return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32 |
|---|
| 1845 | } |
|---|
| 1846 | |
|---|
| 1847 | /** get scaling matrix from RefMatrixID |
|---|
| 1848 | * \param sizeId size index |
|---|
| 1849 | * \param Index of input matrix |
|---|
| 1850 | * \param Index of reference matrix |
|---|
| 1851 | */ |
|---|
| 1852 | Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId ) |
|---|
| 1853 | { |
|---|
| 1854 | ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
|---|
| 1855 | } |
|---|
| 1856 | |
|---|
| 1857 | /** parse syntax infomation |
|---|
| 1858 | * \param pchFile syntax infomation |
|---|
| 1859 | * \returns false if successful |
|---|
| 1860 | */ |
|---|
| 1861 | Bool TComScalingList::xParseScalingList(Char* pchFile) |
|---|
| 1862 | { |
|---|
| 1863 | FILE *fp; |
|---|
| 1864 | Char line[1024]; |
|---|
| 1865 | UInt sizeIdc,listIdc; |
|---|
| 1866 | UInt i,size = 0; |
|---|
| 1867 | Int *src=0,data; |
|---|
| 1868 | Char *ret; |
|---|
| 1869 | UInt retval; |
|---|
| 1870 | |
|---|
| 1871 | if((fp = fopen(pchFile,"r")) == (FILE*)NULL) |
|---|
| 1872 | { |
|---|
| 1873 | printf("can't open file %s :: set Default Matrix\n",pchFile); |
|---|
| 1874 | return true; |
|---|
| 1875 | } |
|---|
| 1876 | |
|---|
| 1877 | for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++) |
|---|
| 1878 | { |
|---|
| 1879 | size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]); |
|---|
| 1880 | for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++) |
|---|
| 1881 | { |
|---|
| 1882 | src = getScalingListAddress(sizeIdc, listIdc); |
|---|
| 1883 | |
|---|
| 1884 | fseek(fp,0,0); |
|---|
| 1885 | do |
|---|
| 1886 | { |
|---|
| 1887 | ret = fgets(line, 1024, fp); |
|---|
| 1888 | if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp))) |
|---|
| 1889 | { |
|---|
| 1890 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 1891 | return true; |
|---|
| 1892 | } |
|---|
| 1893 | } |
|---|
| 1894 | while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL); |
|---|
| 1895 | for (i=0; i<size; i++) |
|---|
| 1896 | { |
|---|
| 1897 | retval = fscanf(fp, "%d,", &data); |
|---|
| 1898 | if (retval!=1) |
|---|
| 1899 | { |
|---|
| 1900 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 1901 | return true; |
|---|
| 1902 | } |
|---|
| 1903 | src[i] = data; |
|---|
| 1904 | } |
|---|
| 1905 | //set DC value for default matrix check |
|---|
| 1906 | setScalingListDC(sizeIdc,listIdc,src[0]); |
|---|
| 1907 | |
|---|
| 1908 | if(sizeIdc > SCALING_LIST_8x8) |
|---|
| 1909 | { |
|---|
| 1910 | fseek(fp,0,0); |
|---|
| 1911 | do |
|---|
| 1912 | { |
|---|
| 1913 | ret = fgets(line, 1024, fp); |
|---|
| 1914 | if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp))) |
|---|
| 1915 | { |
|---|
| 1916 | printf("Error: can't read DC :: set Default Matrix\n"); |
|---|
| 1917 | return true; |
|---|
| 1918 | } |
|---|
| 1919 | } |
|---|
| 1920 | while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL); |
|---|
| 1921 | retval = fscanf(fp, "%d,", &data); |
|---|
| 1922 | if (retval!=1) |
|---|
| 1923 | { |
|---|
| 1924 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
|---|
| 1925 | return true; |
|---|
| 1926 | } |
|---|
| 1927 | //overwrite DC value when size of matrix is larger than 16x16 |
|---|
| 1928 | setScalingListDC(sizeIdc,listIdc,data); |
|---|
| 1929 | } |
|---|
| 1930 | } |
|---|
| 1931 | } |
|---|
| 1932 | fclose(fp); |
|---|
| 1933 | return false; |
|---|
| 1934 | } |
|---|
| 1935 | |
|---|
| 1936 | /** initialization process of quantization matrix array |
|---|
| 1937 | */ |
|---|
| 1938 | Void TComScalingList::init() |
|---|
| 1939 | { |
|---|
| 1940 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 1941 | { |
|---|
| 1942 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 1943 | { |
|---|
| 1944 | m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])]; |
|---|
| 1945 | } |
|---|
| 1946 | } |
|---|
| 1947 | m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32 |
|---|
| 1948 | } |
|---|
| 1949 | |
|---|
| 1950 | /** destroy quantization matrix array |
|---|
| 1951 | */ |
|---|
| 1952 | Void TComScalingList::destroy() |
|---|
| 1953 | { |
|---|
| 1954 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 1955 | { |
|---|
| 1956 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 1957 | { |
|---|
| 1958 | if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId]; |
|---|
| 1959 | } |
|---|
| 1960 | } |
|---|
| 1961 | } |
|---|
| 1962 | |
|---|
| 1963 | /** get default address of quantization matrix |
|---|
| 1964 | * \param sizeId size index |
|---|
| 1965 | * \param listId list index |
|---|
| 1966 | * \returns pointer of quantization matrix |
|---|
| 1967 | */ |
|---|
| 1968 | Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId) |
|---|
| 1969 | { |
|---|
| 1970 | Int *src = 0; |
|---|
| 1971 | switch(sizeId) |
|---|
| 1972 | { |
|---|
| 1973 | case SCALING_LIST_4x4: |
|---|
| 1974 | src = g_quantTSDefault4x4; |
|---|
| 1975 | break; |
|---|
| 1976 | case SCALING_LIST_8x8: |
|---|
| 1977 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 1978 | break; |
|---|
| 1979 | case SCALING_LIST_16x16: |
|---|
| 1980 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 1981 | break; |
|---|
| 1982 | case SCALING_LIST_32x32: |
|---|
| 1983 | src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
|---|
| 1984 | break; |
|---|
| 1985 | default: |
|---|
| 1986 | assert(0); |
|---|
| 1987 | src = NULL; |
|---|
| 1988 | break; |
|---|
| 1989 | } |
|---|
| 1990 | return src; |
|---|
| 1991 | } |
|---|
| 1992 | |
|---|
| 1993 | /** process of default matrix |
|---|
| 1994 | * \param sizeId size index |
|---|
| 1995 | * \param Index of input matrix |
|---|
| 1996 | */ |
|---|
| 1997 | Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId) |
|---|
| 1998 | { |
|---|
| 1999 | ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
|---|
| 2000 | setScalingListDC(sizeId,listId,SCALING_LIST_DC); |
|---|
| 2001 | } |
|---|
| 2002 | |
|---|
| 2003 | /** check DC value of matrix for default matrix signaling |
|---|
| 2004 | */ |
|---|
| 2005 | Void TComScalingList::checkDcOfMatrix() |
|---|
| 2006 | { |
|---|
| 2007 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| 2008 | { |
|---|
| 2009 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
|---|
| 2010 | { |
|---|
| 2011 | //check default matrix? |
|---|
| 2012 | if(getScalingListDC(sizeId,listId) == 0) |
|---|
| 2013 | { |
|---|
| 2014 | processDefaultMarix(sizeId, listId); |
|---|
| 2015 | } |
|---|
| 2016 | } |
|---|
| 2017 | } |
|---|
| 2018 | } |
|---|
| 2019 | |
|---|
| 2020 | ParameterSetManager::ParameterSetManager() |
|---|
| 2021 | : m_vpsMap(MAX_NUM_VPS) |
|---|
| 2022 | , m_spsMap(MAX_NUM_SPS) |
|---|
| 2023 | , m_ppsMap(MAX_NUM_PPS) |
|---|
| 2024 | , m_activeVPSId(-1) |
|---|
| 2025 | , m_activeSPSId(-1) |
|---|
| 2026 | , m_activePPSId(-1) |
|---|
| 2027 | { |
|---|
| 2028 | } |
|---|
| 2029 | |
|---|
| 2030 | |
|---|
| 2031 | ParameterSetManager::~ParameterSetManager() |
|---|
| 2032 | { |
|---|
| 2033 | } |
|---|
| 2034 | |
|---|
| 2035 | //! activate a SPS from a active parameter sets SEI message |
|---|
| 2036 | //! \returns true, if activation is successful |
|---|
| 2037 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId) |
|---|
| 2038 | { |
|---|
| 2039 | TComSPS *sps = m_spsMap.getPS(spsId); |
|---|
| 2040 | if (sps) |
|---|
| 2041 | { |
|---|
| 2042 | Int vpsId = sps->getVPSId(); |
|---|
| 2043 | if (m_vpsMap.getPS(vpsId)) |
|---|
| 2044 | { |
|---|
| 2045 | m_activeVPSId = vpsId; |
|---|
| 2046 | m_activeSPSId = spsId; |
|---|
| 2047 | return true; |
|---|
| 2048 | } |
|---|
| 2049 | else |
|---|
| 2050 | { |
|---|
| 2051 | printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist."); |
|---|
| 2052 | } |
|---|
| 2053 | } |
|---|
| 2054 | else |
|---|
| 2055 | { |
|---|
| 2056 | printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message."); |
|---|
| 2057 | } |
|---|
| 2058 | return false; |
|---|
| 2059 | } |
|---|
| 2060 | |
|---|
| 2061 | //! activate a PPS and depending on isIDR parameter also SPS and VPS |
|---|
| 2062 | //! \returns true, if activation is successful |
|---|
| 2063 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP) |
|---|
| 2064 | { |
|---|
| 2065 | TComPPS *pps = m_ppsMap.getPS(ppsId); |
|---|
| 2066 | if (pps) |
|---|
| 2067 | { |
|---|
| 2068 | Int spsId = pps->getSPSId(); |
|---|
| 2069 | if (!isIRAP && (spsId != m_activeSPSId)) |
|---|
| 2070 | { |
|---|
| 2071 | printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP."); |
|---|
| 2072 | return false; |
|---|
| 2073 | } |
|---|
| 2074 | TComSPS *sps = m_spsMap.getPS(spsId); |
|---|
| 2075 | if (sps) |
|---|
| 2076 | { |
|---|
| 2077 | Int vpsId = sps->getVPSId(); |
|---|
| 2078 | if (!isIRAP && (vpsId != m_activeVPSId)) |
|---|
| 2079 | { |
|---|
| 2080 | printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP."); |
|---|
| 2081 | return false; |
|---|
| 2082 | } |
|---|
| 2083 | if (m_vpsMap.getPS(vpsId)) |
|---|
| 2084 | { |
|---|
| 2085 | m_activePPSId = ppsId; |
|---|
| 2086 | m_activeVPSId = vpsId; |
|---|
| 2087 | m_activeSPSId = spsId; |
|---|
| 2088 | return true; |
|---|
| 2089 | } |
|---|
| 2090 | else |
|---|
| 2091 | { |
|---|
| 2092 | printf("Warning: tried to activate PPS that refers to a non-existing VPS."); |
|---|
| 2093 | } |
|---|
| 2094 | } |
|---|
| 2095 | else |
|---|
| 2096 | { |
|---|
| 2097 | printf("Warning: tried to activate a PPS that refers to a non-existing SPS."); |
|---|
| 2098 | } |
|---|
| 2099 | } |
|---|
| 2100 | else |
|---|
| 2101 | { |
|---|
| 2102 | printf("Warning: tried to activate non-existing PPS."); |
|---|
| 2103 | } |
|---|
| 2104 | return false; |
|---|
| 2105 | } |
|---|
| 2106 | |
|---|
| 2107 | ProfileTierLevel::ProfileTierLevel() |
|---|
| 2108 | : m_profileSpace (0) |
|---|
| 2109 | , m_tierFlag (false) |
|---|
| 2110 | , m_profileIdc (0) |
|---|
| 2111 | , m_levelIdc (0) |
|---|
| 2112 | #if L0046_CONSTRAINT_FLAGS |
|---|
| 2113 | , m_progressiveSourceFlag (false) |
|---|
| 2114 | , m_interlacedSourceFlag (false) |
|---|
| 2115 | , m_nonPackedConstraintFlag(false) |
|---|
| 2116 | , m_frameOnlyConstraintFlag(false) |
|---|
| 2117 | #endif |
|---|
| 2118 | { |
|---|
| 2119 | ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag)); |
|---|
| 2120 | } |
|---|
| 2121 | |
|---|
| 2122 | TComPTL::TComPTL() |
|---|
| 2123 | { |
|---|
| 2124 | ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag)); |
|---|
| 2125 | ::memset(m_subLayerLevelPresentFlag, 0, sizeof(m_subLayerLevelPresentFlag )); |
|---|
| 2126 | } |
|---|
| 2127 | |
|---|
| 2128 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
|---|
| 2129 | TComBitRatePicRateInfo::TComBitRatePicRateInfo() |
|---|
| 2130 | { |
|---|
| 2131 | ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag)); |
|---|
| 2132 | ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag)); |
|---|
| 2133 | ::memset(m_avgBitRate, 0, sizeof(m_avgBitRate)); |
|---|
| 2134 | ::memset(m_maxBitRate, 0, sizeof(m_maxBitRate)); |
|---|
| 2135 | ::memset(m_constantPicRateIdc, 0, sizeof(m_constantPicRateIdc)); |
|---|
| 2136 | ::memset(m_avgPicRate, 0, sizeof(m_avgPicRate)); |
|---|
| 2137 | } |
|---|
| 2138 | #endif |
|---|
| 2139 | //! \} |
|---|