Skip to content
Snippets Groups Projects
Slice.h 150 KiB
Newer Older
  • Learn to ignore specific revisions
  • /* The copyright in this software is being made available under the BSD
     * License, included below. This software may be subject to other third party
     * and contributor rights, including patent rights, and no such rights are
     * granted under this license.
     *
    
     * Copyright (c) 2010-2019, ITU/ISO/IEC
    
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions are met:
     *
     *  * Redistributions of source code must retain the above copyright notice,
     *    this list of conditions and the following disclaimer.
     *  * Redistributions in binary form must reproduce the above copyright notice,
     *    this list of conditions and the following disclaimer in the documentation
     *    and/or other materials provided with the distribution.
     *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
     *    be used to endorse or promote products derived from this software without
     *    specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
     * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     * THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /** \file     Slice.h
        \brief    slice header and SPS class (header)
    */
    
    #ifndef __SLICE__
    #define __SLICE__
    
    #include <cstring>
    #include <list>
    #include <map>
    #include <vector>
    #include "CommonDef.h"
    #include "Rom.h"
    #include "ChromaFormat.h"
    #include "Common.h"
    
    //! \ingroup CommonLib
    //! \{
    
    #include "CommonLib/MotionInfo.h"
    struct MotionInfo;
    
    54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
    
    
    struct Picture;
    class Pic;
    class TrQuant;
    // ====================================================================================================================
    // Constants
    // ====================================================================================================================
    class PreCalcValues;
    static const uint32_t REF_PIC_LIST_NUM_IDX=32;
    
    typedef std::list<Picture*> PicList;
    
    // ====================================================================================================================
    // Class definition
    // ====================================================================================================================
    
    /// Reference Picture Set class
    class ReferencePictureSet
    {
    private:
      int  m_numberOfPictures;
      int  m_numberOfNegativePictures;
      int  m_numberOfPositivePictures;
      int  m_numberOfLongtermPictures;
      int  m_deltaPOC[MAX_NUM_REF_PICS];
      int  m_POC[MAX_NUM_REF_PICS];
      bool m_used[MAX_NUM_REF_PICS];
      bool m_interRPSPrediction;
      int  m_deltaRIdxMinus1;
      int  m_deltaRPS;
      int  m_numRefIdc;
      int  m_refIdc[MAX_NUM_REF_PICS+1];
      bool m_bCheckLTMSB[MAX_NUM_REF_PICS];
      int  m_pocLSBLT[MAX_NUM_REF_PICS];
      int  m_deltaPOCMSBCycleLT[MAX_NUM_REF_PICS];
      bool m_deltaPocMSBPresentFlag[MAX_NUM_REF_PICS];
    
    public:
              ReferencePictureSet();
      virtual ~ReferencePictureSet();
      int     getPocLSBLT(int i) const                     { return m_pocLSBLT[i];               }
      void    setPocLSBLT(int i, int x)                    { m_pocLSBLT[i] = x;                  }
      int     getDeltaPocMSBCycleLT(int i) const           { return m_deltaPOCMSBCycleLT[i];     }
      void    setDeltaPocMSBCycleLT(int i, int x)          { m_deltaPOCMSBCycleLT[i] = x;        }
      bool    getDeltaPocMSBPresentFlag(int i) const       { return m_deltaPocMSBPresentFlag[i]; }
      void    setDeltaPocMSBPresentFlag(int i, bool x)     { m_deltaPocMSBPresentFlag[i] = x;    }
      void    setUsed(int bufferNum, bool used);
      void    setDeltaPOC(int bufferNum, int deltaPOC);
      void    setPOC(int bufferNum, int deltaPOC);
      void    setNumberOfPictures(int numberOfPictures);
      void    setCheckLTMSBPresent(int bufferNum, bool b );
      bool    getCheckLTMSBPresent(int bufferNum) const;
    
      int     getUsed(int bufferNum) const;
      int     getDeltaPOC(int bufferNum) const;
      int     getPOC(int bufferNum) const;
      int     getNumberOfPictures() const;
    
      void    setNumberOfNegativePictures(int number)      { m_numberOfNegativePictures = number; }
      int     getNumberOfNegativePictures() const          { return m_numberOfNegativePictures;   }
      void    setNumberOfPositivePictures(int number)      { m_numberOfPositivePictures = number; }
      int     getNumberOfPositivePictures() const          { return m_numberOfPositivePictures;   }
      void    setNumberOfLongtermPictures(int number)      { m_numberOfLongtermPictures = number; }
      int     getNumberOfLongtermPictures() const          { return m_numberOfLongtermPictures;   }
    
      void    setInterRPSPrediction(bool flag)             { m_interRPSPrediction = flag;         }
      bool    getInterRPSPrediction() const                { return m_interRPSPrediction;         }
      void    setDeltaRIdxMinus1(int x)                    { m_deltaRIdxMinus1 = x;               }
      int     getDeltaRIdxMinus1() const                   { return m_deltaRIdxMinus1;            }
      void    setDeltaRPS(int x)                           { m_deltaRPS = x;                      }
      int     getDeltaRPS() const                          { return m_deltaRPS;                   }
      void    setNumRefIdc(int x)                          { m_numRefIdc = x;                     }
      int     getNumRefIdc() const                         { return m_numRefIdc;                  }
    
      void    setRefIdc(int bufferNum, int refIdc);
      int     getRefIdc(int bufferNum) const ;
    
      void    sortDeltaPOC();
      void    printDeltaPOC() const;
    };
    
    /// Reference Picture Set set class
    class RPSList
    {
    private:
      std::vector<ReferencePictureSet> m_referencePictureSets;
    
    public:
                                     RPSList()                                            { }
      virtual                        ~RPSList()                                           { }
    
      void                           create  (int numberOfEntries)                            { m_referencePictureSets.resize(numberOfEntries);         }
      void                           destroy ()                                               { }
    
    
      ReferencePictureSet*       getReferencePictureSet(int referencePictureSetNum)       { return &m_referencePictureSets[referencePictureSetNum]; }
      const ReferencePictureSet* getReferencePictureSet(int referencePictureSetNum) const { return &m_referencePictureSets[referencePictureSetNum]; }
    
      int                            getNumberOfReferencePictureSets() const                  { return int(m_referencePictureSets.size());              }
    };
    
    #if HEVC_USE_SCALING_LISTS
    /// SCALING_LIST class
    class ScalingList
    {
    public:
                 ScalingList();
      virtual    ~ScalingList()                                                 { }
      int*       getScalingListAddress(uint32_t sizeId, uint32_t listId)                    { return &(m_scalingListCoef[sizeId][listId][0]);            } //!< get matrix coefficient
      const int* getScalingListAddress(uint32_t sizeId, uint32_t listId) const              { return &(m_scalingListCoef[sizeId][listId][0]);            } //!< get matrix coefficient
      void       checkPredMode(uint32_t sizeId, uint32_t listId);
    
      void       setRefMatrixId(uint32_t sizeId, uint32_t listId, uint32_t u)                   { m_refMatrixId[sizeId][listId] = u;                         } //!< set reference matrix ID
      uint32_t       getRefMatrixId(uint32_t sizeId, uint32_t listId) const                     { return m_refMatrixId[sizeId][listId];                      } //!< get reference matrix ID
    
      const int* getScalingListDefaultAddress(uint32_t sizeId, uint32_t listId);                                                                           //!< get default matrix coefficient
      void       processDefaultMatrix(uint32_t sizeId, uint32_t listId);
    
      void       setScalingListDC(uint32_t sizeId, uint32_t listId, uint32_t u)                 { m_scalingListDC[sizeId][listId] = u;                       } //!< set DC value
      int        getScalingListDC(uint32_t sizeId, uint32_t listId) const                   { return m_scalingListDC[sizeId][listId];                    } //!< get DC value
    
      void       setScalingListPredModeFlag(uint32_t sizeId, uint32_t listId, bool bIsDPCM) { m_scalingListPredModeFlagIsDPCM[sizeId][listId] = bIsDPCM; }
      bool       getScalingListPredModeFlag(uint32_t sizeId, uint32_t listId) const         { return m_scalingListPredModeFlagIsDPCM[sizeId][listId];    }
    
      void       checkDcOfMatrix();
      void       processRefMatrix(uint32_t sizeId, uint32_t listId , uint32_t refListId );
      bool       xParseScalingList(const std::string &fileName);
      void       setDefaultScalingList();
      bool       checkDefaultScalingList();
    
    private:
      void       outputScalingLists(std::ostream &os) const;
      bool             m_scalingListPredModeFlagIsDPCM [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< reference list index
      int              m_scalingListDC                 [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< the DC value of the matrix coefficient for 16x16
      uint32_t             m_refMatrixId                   [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< RefMatrixID
      std::vector<int> m_scalingListCoef               [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix
    };
    #endif
    
    class ProfileTierLevel
    {
      int               m_profileSpace;
      Level::Tier       m_tierFlag;
      Profile::Name     m_profileIdc;
      bool              m_profileCompatibilityFlag[32];
      Level::Name       m_levelIdc;
    
      bool              m_progressiveSourceFlag;
      bool              m_interlacedSourceFlag;
      bool              m_nonPackedConstraintFlag;
      bool              m_frameOnlyConstraintFlag;
      uint32_t              m_bitDepthConstraintValue;
      ChromaFormat      m_chromaFormatConstraintValue;
      bool              m_intraConstraintFlag;
      bool              m_onePictureOnlyConstraintFlag;
      bool              m_lowerBitRateConstraintFlag;
    
    public:
                    ProfileTierLevel();
    
      int           getProfileSpace() const                     { return m_profileSpace;                }
      void          setProfileSpace(int x)                      { m_profileSpace = x;                   }
    
      Level::Tier   getTierFlag() const                         { return m_tierFlag;                    }
      void          setTierFlag(Level::Tier x)                  { m_tierFlag = x;                       }
    
      Profile::Name getProfileIdc() const                       { return m_profileIdc;                  }
      void          setProfileIdc(Profile::Name x)              { m_profileIdc = x;                     }
    
      bool          getProfileCompatibilityFlag(int i) const    { return m_profileCompatibilityFlag[i]; }
      void          setProfileCompatibilityFlag(int i, bool x)  { m_profileCompatibilityFlag[i] = x;    }
    
      Level::Name   getLevelIdc() const                         { return m_levelIdc;                    }
      void          setLevelIdc(Level::Name x)                  { m_levelIdc = x;                       }
    
      bool          getProgressiveSourceFlag() const            { return m_progressiveSourceFlag;       }
      void          setProgressiveSourceFlag(bool b)            { m_progressiveSourceFlag = b;          }
    
      bool          getInterlacedSourceFlag() const             { return m_interlacedSourceFlag;        }
      void          setInterlacedSourceFlag(bool b)             { m_interlacedSourceFlag = b;           }
    
      bool          getNonPackedConstraintFlag() const          { return m_nonPackedConstraintFlag;     }
      void          setNonPackedConstraintFlag(bool b)          { m_nonPackedConstraintFlag = b;        }
    
      bool          getFrameOnlyConstraintFlag() const          { return m_frameOnlyConstraintFlag;     }
      void          setFrameOnlyConstraintFlag(bool b)          { m_frameOnlyConstraintFlag = b;        }
    
      uint32_t          getBitDepthConstraint() const               { return m_bitDepthConstraintValue;     }
      void          setBitDepthConstraint(uint32_t bitDepth)        { m_bitDepthConstraintValue=bitDepth;   }
    
      ChromaFormat  getChromaFormatConstraint() const           { return m_chromaFormatConstraintValue; }
      void          setChromaFormatConstraint(ChromaFormat fmt) { m_chromaFormatConstraintValue=fmt;    }
    
      bool          getIntraConstraintFlag() const              { return m_intraConstraintFlag;         }
      void          setIntraConstraintFlag(bool b)              { m_intraConstraintFlag = b;            }
    
      bool          getOnePictureOnlyConstraintFlag() const     { return m_onePictureOnlyConstraintFlag;}
      void          setOnePictureOnlyConstraintFlag(bool b)     { m_onePictureOnlyConstraintFlag = b;   }
    
      bool          getLowerBitRateConstraintFlag() const       { return m_lowerBitRateConstraintFlag;  }
      void          setLowerBitRateConstraintFlag(bool b)       { m_lowerBitRateConstraintFlag = b;     }
    };
    
    
    class PTL
    {
      ProfileTierLevel m_generalPTL;
      ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
      bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
      bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
    
    public:
                              PTL();
      bool                    getSubLayerProfilePresentFlag(int i) const   { return m_subLayerProfilePresentFlag[i]; }
      void                    setSubLayerProfilePresentFlag(int i, bool x) { m_subLayerProfilePresentFlag[i] = x;    }
    
      bool                    getSubLayerLevelPresentFlag(int i) const     { return m_subLayerLevelPresentFlag[i];   }
      void                    setSubLayerLevelPresentFlag(int i, bool x)   { m_subLayerLevelPresentFlag[i] = x;      }
    
      ProfileTierLevel*       getGeneralPTL()                              { return &m_generalPTL;                   }
      const ProfileTierLevel* getGeneralPTL() const                        { return &m_generalPTL;                   }
      ProfileTierLevel*       getSubLayerPTL(int i)                        { return &m_subLayerPTL[i];               }
      const ProfileTierLevel* getSubLayerPTL(int i) const                  { return &m_subLayerPTL[i];               }
    };
    
    struct HrdSubLayerInfo
    {
      bool fixedPicRateFlag;
      bool fixedPicRateWithinCvsFlag;
      uint32_t picDurationInTcMinus1;
      bool lowDelayHrdFlag;
      uint32_t cpbCntMinus1;
      uint32_t bitRateValueMinus1[MAX_CPB_CNT][2];
      uint32_t cpbSizeValue      [MAX_CPB_CNT][2];
      uint32_t ducpbSizeValue    [MAX_CPB_CNT][2];
      bool cbrFlag           [MAX_CPB_CNT][2];
      uint32_t duBitRateValue    [MAX_CPB_CNT][2];
    };
    
    class HRD
    {
    private:
      bool m_nalHrdParametersPresentFlag;
      bool m_vclHrdParametersPresentFlag;
      bool m_subPicCpbParamsPresentFlag;
      uint32_t m_tickDivisorMinus2;
      uint32_t m_duCpbRemovalDelayLengthMinus1;
      bool m_subPicCpbParamsInPicTimingSEIFlag;
      uint32_t m_dpbOutputDelayDuLengthMinus1;
      uint32_t m_bitRateScale;
      uint32_t m_cpbSizeScale;
      uint32_t m_ducpbSizeScale;
      uint32_t m_initialCpbRemovalDelayLengthMinus1;
      uint32_t m_cpbRemovalDelayLengthMinus1;
      uint32_t m_dpbOutputDelayLengthMinus1;
      HrdSubLayerInfo m_HRD[MAX_TLAYER];
    
    public:
      HRD()
      :m_nalHrdParametersPresentFlag       (0)
      ,m_vclHrdParametersPresentFlag       (0)
      ,m_subPicCpbParamsPresentFlag        (false)
      ,m_tickDivisorMinus2                 (0)
      ,m_duCpbRemovalDelayLengthMinus1     (0)
      ,m_subPicCpbParamsInPicTimingSEIFlag (false)
      ,m_dpbOutputDelayDuLengthMinus1      (0)
      ,m_bitRateScale                      (0)
      ,m_cpbSizeScale                      (0)
      ,m_initialCpbRemovalDelayLengthMinus1(23)
      ,m_cpbRemovalDelayLengthMinus1       (23)
      ,m_dpbOutputDelayLengthMinus1        (23)
      {}
    
      virtual ~HRD() {}
    
      void    setNalHrdParametersPresentFlag( bool flag )                                { m_nalHrdParametersPresentFlag = flag;                      }
      bool    getNalHrdParametersPresentFlag( ) const                                    { return m_nalHrdParametersPresentFlag;                      }
    
      void    setVclHrdParametersPresentFlag( bool flag )                                { m_vclHrdParametersPresentFlag = flag;                      }
      bool    getVclHrdParametersPresentFlag( ) const                                    { return m_vclHrdParametersPresentFlag;                      }
    
      void    setSubPicCpbParamsPresentFlag( bool flag )                                 { m_subPicCpbParamsPresentFlag = flag;                       }
      bool    getSubPicCpbParamsPresentFlag( ) const                                     { return m_subPicCpbParamsPresentFlag;                       }
    
      void    setTickDivisorMinus2( uint32_t value )                                         { m_tickDivisorMinus2 = value;                               }
      uint32_t    getTickDivisorMinus2( ) const                                              { return m_tickDivisorMinus2;                                }
    
      void    setDuCpbRemovalDelayLengthMinus1( uint32_t value )                             { m_duCpbRemovalDelayLengthMinus1 = value;                   }
      uint32_t    getDuCpbRemovalDelayLengthMinus1( ) const                                  { return m_duCpbRemovalDelayLengthMinus1;                    }
    
      void    setSubPicCpbParamsInPicTimingSEIFlag( bool flag)                           { m_subPicCpbParamsInPicTimingSEIFlag = flag;                }
      bool    getSubPicCpbParamsInPicTimingSEIFlag( ) const                              { return m_subPicCpbParamsInPicTimingSEIFlag;                }
    
      void    setDpbOutputDelayDuLengthMinus1(uint32_t value )                               { m_dpbOutputDelayDuLengthMinus1 = value;                    }
      uint32_t    getDpbOutputDelayDuLengthMinus1( ) const                                   { return m_dpbOutputDelayDuLengthMinus1;                     }
    
      void    setBitRateScale( uint32_t value )                                              { m_bitRateScale = value;                                    }
      uint32_t    getBitRateScale( ) const                                                   { return m_bitRateScale;                                     }
    
      void    setCpbSizeScale( uint32_t value )                                              { m_cpbSizeScale = value;                                    }
      uint32_t    getCpbSizeScale( ) const                                                   { return m_cpbSizeScale;                                     }
      void    setDuCpbSizeScale( uint32_t value )                                            { m_ducpbSizeScale = value;                                  }
      uint32_t    getDuCpbSizeScale( ) const                                                 { return m_ducpbSizeScale;                                   }
    
      void    setInitialCpbRemovalDelayLengthMinus1( uint32_t value )                        { m_initialCpbRemovalDelayLengthMinus1 = value;              }
      uint32_t    getInitialCpbRemovalDelayLengthMinus1( ) const                             { return m_initialCpbRemovalDelayLengthMinus1;               }
    
      void    setCpbRemovalDelayLengthMinus1( uint32_t value )                               { m_cpbRemovalDelayLengthMinus1 = value;                     }
      uint32_t    getCpbRemovalDelayLengthMinus1( ) const                                    { return m_cpbRemovalDelayLengthMinus1;                      }
    
      void    setDpbOutputDelayLengthMinus1( uint32_t value )                                { m_dpbOutputDelayLengthMinus1 = value;                      }
      uint32_t    getDpbOutputDelayLengthMinus1( ) const                                     { return m_dpbOutputDelayLengthMinus1;                       }
    
      void    setFixedPicRateFlag( int layer, bool flag )                                { m_HRD[layer].fixedPicRateFlag = flag;                      }
      bool    getFixedPicRateFlag( int layer ) const                                     { return m_HRD[layer].fixedPicRateFlag;                      }
    
      void    setFixedPicRateWithinCvsFlag( int layer, bool flag )                       { m_HRD[layer].fixedPicRateWithinCvsFlag = flag;             }
      bool    getFixedPicRateWithinCvsFlag( int layer ) const                            { return m_HRD[layer].fixedPicRateWithinCvsFlag;             }
    
      void    setPicDurationInTcMinus1( int layer, uint32_t value )                          { m_HRD[layer].picDurationInTcMinus1 = value;                }
      uint32_t    getPicDurationInTcMinus1( int layer ) const                                { return m_HRD[layer].picDurationInTcMinus1;                 }
    
      void    setLowDelayHrdFlag( int layer, bool flag )                                 { m_HRD[layer].lowDelayHrdFlag = flag;                       }
      bool    getLowDelayHrdFlag( int layer ) const                                      { return m_HRD[layer].lowDelayHrdFlag;                       }
    
      void    setCpbCntMinus1( int layer, uint32_t value )                                   { m_HRD[layer].cpbCntMinus1 = value;                         }
      uint32_t    getCpbCntMinus1( int layer ) const                                         { return m_HRD[layer].cpbCntMinus1;                          }
    
      void    setBitRateValueMinus1( int layer, int cpbcnt, int nalOrVcl, uint32_t value )   { m_HRD[layer].bitRateValueMinus1[cpbcnt][nalOrVcl] = value; }
      uint32_t    getBitRateValueMinus1( int layer, int cpbcnt, int nalOrVcl ) const         { return m_HRD[layer].bitRateValueMinus1[cpbcnt][nalOrVcl];  }
    
      void    setCpbSizeValueMinus1( int layer, int cpbcnt, int nalOrVcl, uint32_t value )   { m_HRD[layer].cpbSizeValue[cpbcnt][nalOrVcl] = value;       }
      uint32_t    getCpbSizeValueMinus1( int layer, int cpbcnt, int nalOrVcl ) const         { return m_HRD[layer].cpbSizeValue[cpbcnt][nalOrVcl];        }
      void    setDuCpbSizeValueMinus1( int layer, int cpbcnt, int nalOrVcl, uint32_t value ) { m_HRD[layer].ducpbSizeValue[cpbcnt][nalOrVcl] = value;     }
      uint32_t    getDuCpbSizeValueMinus1( int layer, int cpbcnt, int nalOrVcl ) const       { return m_HRD[layer].ducpbSizeValue[cpbcnt][nalOrVcl];      }
      void    setDuBitRateValueMinus1( int layer, int cpbcnt, int nalOrVcl, uint32_t value ) { m_HRD[layer].duBitRateValue[cpbcnt][nalOrVcl] = value;     }
      uint32_t    getDuBitRateValueMinus1(int layer, int cpbcnt, int nalOrVcl ) const        { return m_HRD[layer].duBitRateValue[cpbcnt][nalOrVcl];      }
      void    setCbrFlag( int layer, int cpbcnt, int nalOrVcl, bool value )              { m_HRD[layer].cbrFlag[cpbcnt][nalOrVcl] = value;            }
      bool    getCbrFlag( int layer, int cpbcnt, int nalOrVcl ) const                    { return m_HRD[layer].cbrFlag[cpbcnt][nalOrVcl];             }
    
      bool    getCpbDpbDelaysPresentFlag( ) const                      { return getNalHrdParametersPresentFlag() || getVclHrdParametersPresentFlag(); }
    };
    
    class TimingInfo
    {
      bool m_timingInfoPresentFlag;
      uint32_t m_numUnitsInTick;
      uint32_t m_timeScale;
      bool m_pocProportionalToTimingFlag;
      int  m_numTicksPocDiffOneMinus1;
    public:
      TimingInfo()
      : m_timingInfoPresentFlag      (false)
      , m_numUnitsInTick             (1001)
      , m_timeScale                  (60000)
      , m_pocProportionalToTimingFlag(false)
      , m_numTicksPocDiffOneMinus1   (0)
      {}
    
      void setTimingInfoPresentFlag( bool flag )   { m_timingInfoPresentFlag = flag;       }
      bool getTimingInfoPresentFlag( ) const       { return m_timingInfoPresentFlag;       }
    
      void setNumUnitsInTick( uint32_t value )         { m_numUnitsInTick = value;             }
      uint32_t getNumUnitsInTick( ) const              { return m_numUnitsInTick;              }
    
      void setTimeScale( uint32_t value )              { m_timeScale = value;                  }
      uint32_t getTimeScale( ) const                   { return m_timeScale;                   }
    
      void setPocProportionalToTimingFlag(bool x)  { m_pocProportionalToTimingFlag = x;    }
      bool getPocProportionalToTimingFlag( ) const { return m_pocProportionalToTimingFlag; }
    
      void setNumTicksPocDiffOneMinus1(int x)      { m_numTicksPocDiffOneMinus1 = x;       }
      int  getNumTicksPocDiffOneMinus1( ) const    { return m_numTicksPocDiffOneMinus1;    }
    };
    
    struct ChromaQpAdj
    {
      union
      {
        struct {
          int CbOffset;
          int CrOffset;
        } comp;
        int offset[2]; /* two chroma components */
      } u;
    };
    
    #if HEVC_VPS
    class VPS
    {
    private:
      int                   m_VPSId;
      uint32_t                  m_uiMaxTLayers;
      uint32_t                  m_uiMaxLayers;
      bool                  m_bTemporalIdNestingFlag;
    
      uint32_t                  m_numReorderPics[MAX_TLAYER];
      uint32_t                  m_uiMaxDecPicBuffering[MAX_TLAYER];
      uint32_t                  m_uiMaxLatencyIncrease[MAX_TLAYER]; // Really max latency increase plus 1 (value 0 expresses no limit)
    
      uint32_t                  m_numHrdParameters;
      uint32_t                  m_maxNuhReservedZeroLayerId;
      std::vector<HRD>      m_hrdParameters;
      std::vector<uint32_t>     m_hrdOpSetIdx;
      std::vector<bool>     m_cprmsPresentFlag;
      uint32_t                  m_numOpSets;
      bool                  m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
    
      PTL                   m_pcPTL;
      TimingInfo            m_timingInfo;
    
    public:
                        VPS();
    
      virtual           ~VPS();
    
      void              createHrdParamBuffer()
      {
        m_hrdParameters   .resize(getNumHrdParameters());
        m_hrdOpSetIdx     .resize(getNumHrdParameters());
        m_cprmsPresentFlag.resize(getNumHrdParameters());
      }
    
      HRD*              getHrdParameters( uint32_t i )                           { return &m_hrdParameters[ i ];                                    }
      const HRD*        getHrdParameters( uint32_t i ) const                     { return &m_hrdParameters[ i ];                                    }
      uint32_t              getHrdOpSetIdx( uint32_t i ) const                       { return m_hrdOpSetIdx[ i ];                                       }
      void              setHrdOpSetIdx( uint32_t val, uint32_t i )                   { m_hrdOpSetIdx[ i ] = val;                                        }
      bool              getCprmsPresentFlag( uint32_t i ) const                  { return m_cprmsPresentFlag[ i ];                                  }
      void              setCprmsPresentFlag( bool val, uint32_t i )              { m_cprmsPresentFlag[ i ] = val;                                   }
    
      int               getVPSId() const                                     { return m_VPSId;                                                  }
      void              setVPSId(int i)                                      { m_VPSId = i;                                                     }
    
      uint32_t              getMaxTLayers() const                                { return m_uiMaxTLayers;                                           }
      void              setMaxTLayers(uint32_t t)                                { m_uiMaxTLayers = t;                                              }
    
      uint32_t              getMaxLayers() const                                 { return m_uiMaxLayers;                                            }
      void              setMaxLayers(uint32_t l)                                 { m_uiMaxLayers = l;                                               }
    
      bool              getTemporalNestingFlag() const                       { return m_bTemporalIdNestingFlag;                                 }
      void              setTemporalNestingFlag(bool t)                       { m_bTemporalIdNestingFlag = t;                                    }
    
      void              setNumReorderPics(uint32_t v, uint32_t tLayer)               { m_numReorderPics[tLayer] = v;                                    }
      uint32_t              getNumReorderPics(uint32_t tLayer) const                 { return m_numReorderPics[tLayer];                                 }
    
      void              setMaxDecPicBuffering(uint32_t v, uint32_t tLayer)           { CHECK(tLayer >= MAX_TLAYER, "Invalid T-layer"); m_uiMaxDecPicBuffering[tLayer] = v; }
      uint32_t              getMaxDecPicBuffering(uint32_t tLayer) const             { return m_uiMaxDecPicBuffering[tLayer];                           }
    
      void              setMaxLatencyIncrease(uint32_t v, uint32_t tLayer)           { m_uiMaxLatencyIncrease[tLayer] = v;                              }
      uint32_t              getMaxLatencyIncrease(uint32_t tLayer) const             { return m_uiMaxLatencyIncrease[tLayer];                           }
    
      uint32_t              getNumHrdParameters() const                          { return m_numHrdParameters;                                       }
      void              setNumHrdParameters(uint32_t v)                          { m_numHrdParameters = v;                                          }
    
      uint32_t              getMaxNuhReservedZeroLayerId() const                 { return m_maxNuhReservedZeroLayerId;                              }
      void              setMaxNuhReservedZeroLayerId(uint32_t v)                 { m_maxNuhReservedZeroLayerId = v;                                 }
    
      uint32_t              getMaxOpSets() const                                 { return m_numOpSets;                                              }
      void              setMaxOpSets(uint32_t v)                                 { m_numOpSets = v;                                                 }
      bool              getLayerIdIncludedFlag(uint32_t opsIdx, uint32_t id) const   { return m_layerIdIncludedFlag[opsIdx][id];                        }
      void              setLayerIdIncludedFlag(bool v, uint32_t opsIdx, uint32_t id) { m_layerIdIncludedFlag[opsIdx][id] = v;                           }
    
      PTL*              getPTL()                                             { return &m_pcPTL;                                                 }
      const PTL*        getPTL() const                                       { return &m_pcPTL;                                                 }
      TimingInfo*       getTimingInfo()                                      { return &m_timingInfo;                                            }
      const TimingInfo* getTimingInfo() const                                { return &m_timingInfo;                                            }
    };
    #endif
    
    class Window
    {
    private:
      bool m_enabledFlag;
      int  m_winLeftOffset;
      int  m_winRightOffset;
      int  m_winTopOffset;
      int  m_winBottomOffset;
    public:
      Window()
      : m_enabledFlag    (false)
      , m_winLeftOffset  (0)
      , m_winRightOffset (0)
      , m_winTopOffset   (0)
      , m_winBottomOffset(0)
      { }
    
      bool getWindowEnabledFlag() const   { return m_enabledFlag;                          }
      int  getWindowLeftOffset() const    { return m_enabledFlag ? m_winLeftOffset : 0;    }
      void setWindowLeftOffset(int val)   { m_winLeftOffset = val; m_enabledFlag = true;   }
      int  getWindowRightOffset() const   { return m_enabledFlag ? m_winRightOffset : 0;   }
      void setWindowRightOffset(int val)  { m_winRightOffset = val; m_enabledFlag = true;  }
      int  getWindowTopOffset() const     { return m_enabledFlag ? m_winTopOffset : 0;     }
      void setWindowTopOffset(int val)    { m_winTopOffset = val; m_enabledFlag = true;    }
      int  getWindowBottomOffset() const  { return m_enabledFlag ? m_winBottomOffset: 0;   }
      void setWindowBottomOffset(int val) { m_winBottomOffset = val; m_enabledFlag = true; }
    
      void setWindow(int offsetLeft, int offsetLRight, int offsetLTop, int offsetLBottom)
      {
        m_enabledFlag     = true;
        m_winLeftOffset   = offsetLeft;
        m_winRightOffset  = offsetLRight;
        m_winTopOffset    = offsetLTop;
        m_winBottomOffset = offsetLBottom;
      }
    };
    
    
    class VUI
    {
    private:
      bool       m_aspectRatioInfoPresentFlag;
      int        m_aspectRatioIdc;
      int        m_sarWidth;
      int        m_sarHeight;
      bool       m_overscanInfoPresentFlag;
      bool       m_overscanAppropriateFlag;
      bool       m_videoSignalTypePresentFlag;
      int        m_videoFormat;
      bool       m_videoFullRangeFlag;
      bool       m_colourDescriptionPresentFlag;
      int        m_colourPrimaries;
      int        m_transferCharacteristics;
      int        m_matrixCoefficients;
      bool       m_chromaLocInfoPresentFlag;
      int        m_chromaSampleLocTypeTopField;
      int        m_chromaSampleLocTypeBottomField;
      bool       m_neutralChromaIndicationFlag;
      bool       m_fieldSeqFlag;
      Window     m_defaultDisplayWindow;
      bool       m_frameFieldInfoPresentFlag;
      bool       m_hrdParametersPresentFlag;
      bool       m_bitstreamRestrictionFlag;
    #if HEVC_TILES_WPP
      bool       m_tilesFixedStructureFlag;
    #endif
      bool       m_motionVectorsOverPicBoundariesFlag;
      bool       m_restrictedRefPicListsFlag;
      int        m_minSpatialSegmentationIdc;
      int        m_maxBytesPerPicDenom;
      int        m_maxBitsPerMinCuDenom;
      int        m_log2MaxMvLengthHorizontal;
      int        m_log2MaxMvLengthVertical;
      HRD    m_hrdParameters;
      TimingInfo m_timingInfo;
    
    public:
      VUI()
        : m_aspectRatioInfoPresentFlag        (false) //TODO: This initialiser list contains magic numbers
        , m_aspectRatioIdc                    (0)
        , m_sarWidth                          (0)
        , m_sarHeight                         (0)
        , m_overscanInfoPresentFlag           (false)
        , m_overscanAppropriateFlag           (false)
        , m_videoSignalTypePresentFlag        (false)
        , m_videoFormat                       (5)
        , m_videoFullRangeFlag                (false)
        , m_colourDescriptionPresentFlag      (false)
        , m_colourPrimaries                   (2)
        , m_transferCharacteristics           (2)
        , m_matrixCoefficients                (2)
        , m_chromaLocInfoPresentFlag          (false)
        , m_chromaSampleLocTypeTopField       (0)
        , m_chromaSampleLocTypeBottomField    (0)
        , m_neutralChromaIndicationFlag       (false)
        , m_fieldSeqFlag                      (false)
        , m_frameFieldInfoPresentFlag         (false)
        , m_hrdParametersPresentFlag          (false)
        , m_bitstreamRestrictionFlag          (false)
    #if HEVC_TILES_WPP
        , m_tilesFixedStructureFlag           (false)
    #endif
        , m_motionVectorsOverPicBoundariesFlag(true)
        , m_restrictedRefPicListsFlag         (1)
        , m_minSpatialSegmentationIdc         (0)
        , m_maxBytesPerPicDenom               (2)
        , m_maxBitsPerMinCuDenom              (1)
        , m_log2MaxMvLengthHorizontal         (15)
        , m_log2MaxMvLengthVertical           (15)
      {}
    
      virtual           ~VUI() {}
    
      bool              getAspectRatioInfoPresentFlag() const                  { return m_aspectRatioInfoPresentFlag;           }
      void              setAspectRatioInfoPresentFlag(bool i)                  { m_aspectRatioInfoPresentFlag = i;              }
    
      int               getAspectRatioIdc() const                              { return m_aspectRatioIdc;                       }
      void              setAspectRatioIdc(int i)                               { m_aspectRatioIdc = i;                          }
    
      int               getSarWidth() const                                    { return m_sarWidth;                             }
      void              setSarWidth(int i)                                     { m_sarWidth = i;                                }
    
      int               getSarHeight() const                                   { return m_sarHeight;                            }
      void              setSarHeight(int i)                                    { m_sarHeight = i;                               }
    
      bool              getOverscanInfoPresentFlag() const                     { return m_overscanInfoPresentFlag;              }
      void              setOverscanInfoPresentFlag(bool i)                     { m_overscanInfoPresentFlag = i;                 }
    
      bool              getOverscanAppropriateFlag() const                     { return m_overscanAppropriateFlag;              }
      void              setOverscanAppropriateFlag(bool i)                     { m_overscanAppropriateFlag = i;                 }
    
      bool              getVideoSignalTypePresentFlag() const                  { return m_videoSignalTypePresentFlag;           }
      void              setVideoSignalTypePresentFlag(bool i)                  { m_videoSignalTypePresentFlag = i;              }
    
      int               getVideoFormat() const                                 { return m_videoFormat;                          }
      void              setVideoFormat(int i)                                  { m_videoFormat = i;                             }
    
      bool              getVideoFullRangeFlag() const                          { return m_videoFullRangeFlag;                   }
      void              setVideoFullRangeFlag(bool i)                          { m_videoFullRangeFlag = i;                      }
    
      bool              getColourDescriptionPresentFlag() const                { return m_colourDescriptionPresentFlag;         }
      void              setColourDescriptionPresentFlag(bool i)                { m_colourDescriptionPresentFlag = i;            }
    
      int               getColourPrimaries() const                             { return m_colourPrimaries;                      }
      void              setColourPrimaries(int i)                              { m_colourPrimaries = i;                         }
    
      int               getTransferCharacteristics() const                     { return m_transferCharacteristics;              }
      void              setTransferCharacteristics(int i)                      { m_transferCharacteristics = i;                 }
    
      int               getMatrixCoefficients() const                          { return m_matrixCoefficients;                   }
      void              setMatrixCoefficients(int i)                           { m_matrixCoefficients = i;                      }
    
      bool              getChromaLocInfoPresentFlag() const                    { return m_chromaLocInfoPresentFlag;             }
      void              setChromaLocInfoPresentFlag(bool i)                    { m_chromaLocInfoPresentFlag = i;                }
    
      int               getChromaSampleLocTypeTopField() const                 { return m_chromaSampleLocTypeTopField;          }
      void              setChromaSampleLocTypeTopField(int i)                  { m_chromaSampleLocTypeTopField = i;             }
    
      int               getChromaSampleLocTypeBottomField() const              { return m_chromaSampleLocTypeBottomField;       }
      void              setChromaSampleLocTypeBottomField(int i)               { m_chromaSampleLocTypeBottomField = i;          }
    
      bool              getNeutralChromaIndicationFlag() const                 { return m_neutralChromaIndicationFlag;          }
      void              setNeutralChromaIndicationFlag(bool i)                 { m_neutralChromaIndicationFlag = i;             }
    
      bool              getFieldSeqFlag() const                                { return m_fieldSeqFlag;                         }
      void              setFieldSeqFlag(bool i)                                { m_fieldSeqFlag = i;                            }
    
      bool              getFrameFieldInfoPresentFlag() const                   { return m_frameFieldInfoPresentFlag;            }
      void              setFrameFieldInfoPresentFlag(bool i)                   { m_frameFieldInfoPresentFlag = i;               }
    
      Window&           getDefaultDisplayWindow()                              { return m_defaultDisplayWindow;                 }
      const Window&     getDefaultDisplayWindow() const                        { return m_defaultDisplayWindow;                 }
      void              setDefaultDisplayWindow(Window& defaultDisplayWindow ) { m_defaultDisplayWindow = defaultDisplayWindow; }
    
      bool              getHrdParametersPresentFlag() const                    { return m_hrdParametersPresentFlag;             }
      void              setHrdParametersPresentFlag(bool i)                    { m_hrdParametersPresentFlag = i;                }
    
      bool              getBitstreamRestrictionFlag() const                    { return m_bitstreamRestrictionFlag;             }
      void              setBitstreamRestrictionFlag(bool i)                    { m_bitstreamRestrictionFlag = i;                }
    
    #if HEVC_TILES_WPP
      bool              getTilesFixedStructureFlag() const                     { return m_tilesFixedStructureFlag;              }
      void              setTilesFixedStructureFlag(bool i)                     { m_tilesFixedStructureFlag = i;                 }
    #endif
    
      bool              getMotionVectorsOverPicBoundariesFlag() const          { return m_motionVectorsOverPicBoundariesFlag;   }
      void              setMotionVectorsOverPicBoundariesFlag(bool i)          { m_motionVectorsOverPicBoundariesFlag = i;      }
    
      bool              getRestrictedRefPicListsFlag() const                   { return m_restrictedRefPicListsFlag;            }
      void              setRestrictedRefPicListsFlag(bool b)                   { m_restrictedRefPicListsFlag = b;               }
    
      int               getMinSpatialSegmentationIdc() const                   { return m_minSpatialSegmentationIdc;            }
      void              setMinSpatialSegmentationIdc(int i)                    { m_minSpatialSegmentationIdc = i;               }
    
      int               getMaxBytesPerPicDenom() const                         { return m_maxBytesPerPicDenom;                  }
      void              setMaxBytesPerPicDenom(int i)                          { m_maxBytesPerPicDenom = i;                     }
    
      int               getMaxBitsPerMinCuDenom() const                        { return m_maxBitsPerMinCuDenom;                 }
      void              setMaxBitsPerMinCuDenom(int i)                         { m_maxBitsPerMinCuDenom = i;                    }
    
      int               getLog2MaxMvLengthHorizontal() const                   { return m_log2MaxMvLengthHorizontal;            }
      void              setLog2MaxMvLengthHorizontal(int i)                    { m_log2MaxMvLengthHorizontal = i;               }
    
      int               getLog2MaxMvLengthVertical() const                     { return m_log2MaxMvLengthVertical;              }
      void              setLog2MaxMvLengthVertical(int i)                      { m_log2MaxMvLengthVertical = i;                 }
    
      HRD*              getHrdParameters()                                     { return &m_hrdParameters;                       }
      const HRD*        getHrdParameters()  const                              { return &m_hrdParameters;                       }
    
      TimingInfo*       getTimingInfo()                                        { return &m_timingInfo;                          }
      const TimingInfo* getTimingInfo() const                                  { return &m_timingInfo;                          }
    };
    
    /// SPS RExt class
    class SPSRExt // Names aligned to text specification
    {
    private:
      bool             m_transformSkipRotationEnabledFlag;
      bool             m_transformSkipContextEnabledFlag;
      bool             m_rdpcmEnabledFlag[NUMBER_OF_RDPCM_SIGNALLING_MODES];
      bool             m_extendedPrecisionProcessingFlag;
      bool             m_intraSmoothingDisabledFlag;
      bool             m_highPrecisionOffsetsEnabledFlag;
      bool             m_persistentRiceAdaptationEnabledFlag;
      bool             m_cabacBypassAlignmentEnabledFlag;
    
    public:
      SPSRExt();
    
      bool settingsDifferFromDefaults() const
      {
        return getTransformSkipRotationEnabledFlag()
            || getTransformSkipContextEnabledFlag()
            || getRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT)
            || getRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT)
            || getExtendedPrecisionProcessingFlag()
            || getIntraSmoothingDisabledFlag()
            || getHighPrecisionOffsetsEnabledFlag()
            || getPersistentRiceAdaptationEnabledFlag()
            || getCabacBypassAlignmentEnabledFlag();
      }
    
    
      bool getTransformSkipRotationEnabledFlag() const                                     { return m_transformSkipRotationEnabledFlag;     }
      void setTransformSkipRotationEnabledFlag(const bool value)                           { m_transformSkipRotationEnabledFlag = value;    }
    
      bool getTransformSkipContextEnabledFlag() const                                      { return m_transformSkipContextEnabledFlag;      }
      void setTransformSkipContextEnabledFlag(const bool value)                            { m_transformSkipContextEnabledFlag = value;     }
    
      bool getRdpcmEnabledFlag(const RDPCMSignallingMode signallingMode) const             { return m_rdpcmEnabledFlag[signallingMode];     }
      void setRdpcmEnabledFlag(const RDPCMSignallingMode signallingMode, const bool value) { m_rdpcmEnabledFlag[signallingMode] = value;    }
    
      bool getExtendedPrecisionProcessingFlag() const                                      { return m_extendedPrecisionProcessingFlag;      }
      void setExtendedPrecisionProcessingFlag(bool value)                                  { m_extendedPrecisionProcessingFlag = value;     }
    
      bool getIntraSmoothingDisabledFlag() const                                           { return m_intraSmoothingDisabledFlag;           }
      void setIntraSmoothingDisabledFlag(bool bValue)                                      { m_intraSmoothingDisabledFlag=bValue;           }
    
      bool getHighPrecisionOffsetsEnabledFlag() const                                      { return m_highPrecisionOffsetsEnabledFlag;      }
      void setHighPrecisionOffsetsEnabledFlag(bool value)                                  { m_highPrecisionOffsetsEnabledFlag = value;     }
    
      bool getPersistentRiceAdaptationEnabledFlag() const                                  { return m_persistentRiceAdaptationEnabledFlag;  }
      void setPersistentRiceAdaptationEnabledFlag(const bool value)                        { m_persistentRiceAdaptationEnabledFlag = value; }
    
      bool getCabacBypassAlignmentEnabledFlag() const                                      { return m_cabacBypassAlignmentEnabledFlag;      }
      void setCabacBypassAlignmentEnabledFlag(const bool value)                            { m_cabacBypassAlignmentEnabledFlag = value;     }
    };
    
    
    class SPS;
    class SPSNext
    {
    private:
      SPS&  m_SPS;
    
      bool              m_NextEnabled;
      //=====  tool enabling flags (4 bytes - NOTE: last flag must be used for new extensions) =====
      bool              m_LargeCTU;                   // 5
      bool              m_SubPuMvp;
      bool              m_IMV;                        // 9
    
      bool              m_DisableMotionCompression;   // 13
      bool              m_LMChroma;                   // 17
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #if JVET_M0464_UNI_MTS
      bool              m_IntraMTS;                   // 18
      bool              m_InterMTS;                   // 19
    #else
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #endif
    
      bool              m_GBi;                        //
    
    #if LUMA_ADAPTIVE_DEBLOCKING_FILTER_QP_OFFSET
      bool              m_LadfEnabled;
      int               m_LadfNumIntervals;
      int               m_LadfQpOffset[MAX_LADF_INTERVALS];
      int               m_LadfIntervalLowerBound[MAX_LADF_INTERVALS];
    #endif
    
    
    public:
      const static int  NumReservedFlags = 32 - 27; /* current number of tool enabling flags */
    
    private:
      //=====  additional parameters  =====
      // qtbt
      // sub-pu merging
      int         m_subPuMrgMode;
      //imv
      ImvMode     m_ImvMode;
      // multi type tree (QTBT + triple split)
      unsigned    m_MTTMode;
    
    
      bool              m_compositeRefEnabled;        //composite longterm reference
    
    Xiaozhong Xu's avatar
    Xiaozhong Xu committed
    
      unsigned    m_CPRMode;
    
    
      // ADD_NEW_TOOL : (sps extension) add tool enabling flags and associated parameters here
    
    public:
      SPSNext( SPS& sps );
    
      const SPS&  getSPS              () const                                          { return m_SPS; }
      SPS&        getSPS              ()                                                { return m_SPS; }
      bool        nextToolsEnabled    () const                                          { return m_NextEnabled; }
      void        setNextToolsEnabled ( bool next )                                     { m_NextEnabled = next; }
    
      //=====  tool enabling flags and extension bit  =====
      void      setUseLargeCTU        ( bool b )                                        { m_LargeCTU = b; }
      bool      getUseLargeCTU        ()                                      const     { return m_LargeCTU; }
      bool      getUseSubPuMvp()                                   const { return m_SubPuMvp; }
      void      setSubPuMvpMode(int n)                             { m_subPuMrgMode = n; m_SubPuMvp = n != 0; }
      bool      getUseATMVP()                                      const { return (m_subPuMrgMode & 1) == 1; }
      void      setUseIMV             ( bool b )                                        { m_IMV = b; }
      bool      getUseIMV             ()                                      const     { return m_IMV; }
      void      setUseAffine          ( bool b )                                        { m_Affine = b; }
      bool      getUseAffine          ()                                      const     { return m_Affine; }
      void      setUseAffineType      ( bool b )                                        { m_AffineType = b; }
      bool      getUseAffineType      ()                                      const     { return m_AffineType; }
    
      void      setUseBIO(bool b)                                                       { m_BIO = b; }
      bool      getUseBIO()                                                   const     { return m_BIO; }
    
      void      setDisableMotCompress ( bool b )                                        { m_DisableMotionCompression = b; }
      bool      getDisableMotCompress ()                                      const     { return m_DisableMotionCompression; }
      bool      getMTTEnabled         ()                                      const     { return m_MTTEnabled; }
    #if ENABLE_WPP_PARALLELISM
      void      setUseNextDQP         ( bool b )                                        { m_NextDQP = b; }
      bool      getUseNextDQP         ()                                      const     { return m_NextDQP; }
    #endif
      void      setUseLMChroma        ( bool b )                                        { m_LMChroma = b; }
      bool      getUseLMChroma        ()                                      const     { return m_LMChroma; }
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #if JVET_M0464_UNI_MTS
      void      setUseIntraMTS        ( bool b )                                        { m_IntraMTS = b; }
      bool      getUseIntraMTS        ()                                      const     { return m_IntraMTS; }
      void      setUseInterMTS        ( bool b )                                        { m_InterMTS = b; }
      bool      getUseInterMTS        ()                                      const     { return m_InterMTS; }
    #else
    
      void      setUseIntraEMT        ( bool b )                                        { m_IntraEMT = b; }
      bool      getUseIntraEMT        ()                                      const     { return m_IntraEMT; }
      void      setUseInterEMT        ( bool b )                                        { m_InterEMT = b; }
      bool      getUseInterEMT        ()                                      const     { return m_InterEMT; }
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    #endif
    
      void      setUseGBi             ( bool b )                                        { m_GBi = b; }
      bool      getUseGBi             ()                                      const     { return m_GBi; }
    
    #if LUMA_ADAPTIVE_DEBLOCKING_FILTER_QP_OFFSET
      void      setLadfEnabled        ( bool b )                                        { m_LadfEnabled = b; }
      bool      getLadfEnabled        ()                                      const     { return m_LadfEnabled; }
      void      setLadfNumIntervals   ( int i )                                         { m_LadfNumIntervals = i; }
      int       getLadfNumIntervals   ()                                      const     { return m_LadfNumIntervals; }
      void      setLadfQpOffset       ( int value, int idx )                            { m_LadfQpOffset[ idx ] = value; }
      int       getLadfQpOffset       ( int idx )                             const     { return m_LadfQpOffset[ idx ]; }
      void      setLadfIntervalLowerBound( int value, int idx )                         { m_LadfIntervalLowerBound[ idx ] = value; }
      int       getLadfIntervalLowerBound( int idx )                          const     { return m_LadfIntervalLowerBound[ idx ]; }
    
      //=====  additional parameters  =====
      // qtbt
      // sub pu tmvp
      void      setImvMode(ImvMode m) { m_ImvMode = m; m_IMV = m != 0;  }
      ImvMode   getImvMode            ()                                      const     { return m_ImvMode; }
    
    
    
      // multi type tree
      unsigned  getMTTMode            ()                                      const     { return m_MTTMode; }
      void      setMTTMode            ( unsigned    mode )                              { m_MTTMode = mode; m_MTTEnabled = ( m_MTTMode != 0 ); }
    
    
      void      setUseCompositeRef(bool b) { m_compositeRefEnabled = b; }
      bool      getUseCompositeRef()                                      const { return m_compositeRefEnabled; }
    
    
      void      setUseMHIntra         ( bool b )                                        { m_MHIntra = b; }
      bool      getUseMHIntra         ()                                      const     { return m_MHIntra; }
    
      void      setUseTriangle        ( bool b )                                        { m_Triangle = b; }
      bool      getUseTriangle        ()                                      const     { return m_Triangle; }
    
    Xiaozhong Xu's avatar
    Xiaozhong Xu committed
      void      setCPRMode            (unsigned CPRMode)                                { m_CPRMode = CPRMode; }
      unsigned  getCPRMode            ()                                      const     { return m_CPRMode; }
    
      // ADD_NEW_TOOL : (sps extension) add access functions for tool enabling flags and associated parameters here
    
    };
    
    
    /// SPS class
    class SPS
    {
    private:
      int               m_SPSId;
    
      bool              m_bIntraOnlyConstraintFlag;
      uint32_t          m_maxBitDepthConstraintIdc;
      uint32_t          m_maxChromaFormatConstraintIdc;
      bool              m_bFrameConstraintFlag;
      bool              m_bNoQtbttDualTreeIntraConstraintFlag;
      bool              m_bNoCclmConstraintFlag;
      bool              m_bNoSaoConstraintFlag;
      bool              m_bNoAlfConstraintFlag;
      bool              m_bNoPcmConstraintFlag;
      bool              m_bNoTemporalMvpConstraintFlag;
      bool              m_bNoSbtmvpConstraintFlag;
      bool              m_bNoAmvrConstraintFlag;
      bool              m_bNoAffineMotionConstraintFlag;
      bool              m_bNoMtsConstraintFlag;
      bool              m_bNoLadfConstraintFlag;
      bool              m_bNoDepQuantConstraintFlag;
      bool              m_bNoSignDataHidingConstraintFlag;
    
    
    #if HEVC_VPS
      int               m_VPSId;
    #endif
      ChromaFormat      m_chromaFormatIdc;
    
      uint32_t              m_uiMaxTLayers;           // maximum number of temporal layers
    
      // Structure
      uint32_t              m_picWidthInLumaSamples;
      uint32_t              m_picHeightInLumaSamples;
    
      int               m_log2MinCodingBlockSize;
      int               m_log2DiffMaxMinCodingBlockSize;
    
      unsigned    m_CTUSize;
      unsigned    m_partitionOverrideEnalbed;       // enable partition constraints override function
      unsigned    m_minQT[3];   // 0: I slice luma; 1: P/B slice; 2: I slice chroma
      unsigned    m_maxBTDepth[3];
      unsigned    m_maxBTSize[3];
      unsigned    m_maxTTSize[3];
      unsigned    m_dualITree;
    
      uint32_t              m_uiMaxCUWidth;
      uint32_t              m_uiMaxCUHeight;
      uint32_t              m_uiMaxCodingDepth; ///< Total CU depth, relative to the smallest possible transform block size.
    
      Window            m_conformanceWindow;
    
      RPSList           m_RPSList;
      bool              m_bLongTermRefsPresent;
      bool              m_SPSTemporalMVPEnabledFlag;
      int               m_numReorderPics[MAX_TLAYER];
    
      // Tool list
      uint32_t              m_uiQuadtreeTULog2MaxSize;
      uint32_t              m_uiQuadtreeTULog2MinSize;
      uint32_t              m_uiQuadtreeTUMaxDepthInter;
      uint32_t              m_uiQuadtreeTUMaxDepthIntra;
      bool              m_usePCM;
      uint32_t              m_pcmLog2MaxSize;
      uint32_t              m_uiPCMLog2MinSize;
      bool              m_useAMP;
    
      // Parameter
      BitDepths         m_bitDepths;
      int               m_qpBDOffset[MAX_NUM_CHANNEL_TYPE];
      int               m_pcmBitDepths[MAX_NUM_CHANNEL_TYPE];
      bool              m_bPCMFilterDisableFlag;
    
      uint32_t              m_uiBitsForPOC;
      uint32_t              m_numLongTermRefPicSPS;