| 1 | /***************************************************************************** |
| 2 | * Copyright (C) 2014 x265 project |
| 3 | * |
| 4 | * Authors: Steve Borho <steve@borho.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
| 19 | * |
| 20 | * This program is also available under a commercial proprietary license. |
| 21 | * For more information, contact us at license @ x265.com. |
| 22 | *****************************************************************************/ |
| 23 | |
| 24 | #ifndef X265_SLICE_H |
| 25 | #define X265_SLICE_H |
| 26 | |
| 27 | #include "common.h" |
| 28 | |
| 29 | namespace x265 { |
| 30 | // private namespace |
| 31 | |
| 32 | class Frame; |
| 33 | class PicList; |
| 34 | class MotionReference; |
| 35 | |
| 36 | enum SliceType |
| 37 | { |
| 38 | B_SLICE, |
| 39 | P_SLICE, |
| 40 | I_SLICE |
| 41 | }; |
| 42 | |
| 43 | struct RPS |
| 44 | { |
| 45 | int numberOfPictures; |
| 46 | int numberOfNegativePictures; |
| 47 | int numberOfPositivePictures; |
| 48 | |
| 49 | int poc[MAX_NUM_REF_PICS]; |
| 50 | int deltaPOC[MAX_NUM_REF_PICS]; |
| 51 | bool bUsed[MAX_NUM_REF_PICS]; |
| 52 | |
| 53 | RPS() |
| 54 | : numberOfPictures(0) |
| 55 | , numberOfNegativePictures(0) |
| 56 | , numberOfPositivePictures(0) |
| 57 | { |
| 58 | ::memset(deltaPOC, 0, sizeof(deltaPOC)); |
| 59 | ::memset(poc, 0, sizeof(poc)); |
| 60 | ::memset(bUsed, 0, sizeof(bUsed)); |
| 61 | } |
| 62 | |
| 63 | void sortDeltaPOC(); |
| 64 | }; |
| 65 | |
| 66 | namespace Profile { |
| 67 | enum Name |
| 68 | { |
| 69 | NONE = 0, |
| 70 | MAIN = 1, |
| 71 | MAIN10 = 2, |
| 72 | MAINSTILLPICTURE = 3, |
| 73 | MAINREXT = 4, |
| 74 | HIGHTHROUGHPUTREXT = 5 |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | namespace Level { |
| 79 | enum Tier |
| 80 | { |
| 81 | MAIN = 0, |
| 82 | HIGH = 1, |
| 83 | }; |
| 84 | |
| 85 | enum Name |
| 86 | { |
| 87 | NONE = 0, |
| 88 | LEVEL1 = 30, |
| 89 | LEVEL2 = 60, |
| 90 | LEVEL2_1 = 63, |
| 91 | LEVEL3 = 90, |
| 92 | LEVEL3_1 = 93, |
| 93 | LEVEL4 = 120, |
| 94 | LEVEL4_1 = 123, |
| 95 | LEVEL5 = 150, |
| 96 | LEVEL5_1 = 153, |
| 97 | LEVEL5_2 = 156, |
| 98 | LEVEL6 = 180, |
| 99 | LEVEL6_1 = 183, |
| 100 | LEVEL6_2 = 186, |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | struct ProfileTierLevel |
| 105 | { |
| 106 | bool tierFlag; |
| 107 | bool progressiveSourceFlag; |
| 108 | bool interlacedSourceFlag; |
| 109 | bool nonPackedConstraintFlag; |
| 110 | bool frameOnlyConstraintFlag; |
| 111 | bool profileCompatibilityFlag[32]; |
| 112 | bool intraConstraintFlag; |
| 113 | bool lowerBitRateConstraintFlag; |
| 114 | int profileIdc; |
| 115 | int levelIdc; |
| 116 | uint32_t minCrForLevel; |
| 117 | uint32_t maxLumaSrForLevel; |
| 118 | uint32_t bitDepthConstraint; |
| 119 | int chromaFormatConstraint; |
| 120 | }; |
| 121 | |
| 122 | struct HRDInfo |
| 123 | { |
| 124 | uint32_t bitRateScale; |
| 125 | uint32_t cpbSizeScale; |
| 126 | uint32_t initialCpbRemovalDelayLength; |
| 127 | uint32_t cpbRemovalDelayLength; |
| 128 | uint32_t dpbOutputDelayLength; |
| 129 | uint32_t bitRateValue; |
| 130 | uint32_t cpbSizeValue; |
| 131 | bool cbrFlag; |
| 132 | |
| 133 | HRDInfo() |
| 134 | : bitRateScale(0) |
| 135 | , cpbSizeScale(0) |
| 136 | , initialCpbRemovalDelayLength(1) |
| 137 | , cpbRemovalDelayLength(1) |
| 138 | , dpbOutputDelayLength(1) |
| 139 | , cbrFlag(false) |
| 140 | { |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | struct TimingInfo |
| 145 | { |
| 146 | uint32_t numUnitsInTick; |
| 147 | uint32_t timeScale; |
| 148 | }; |
| 149 | |
| 150 | struct VPS |
| 151 | { |
| 152 | uint32_t numReorderPics; |
| 153 | uint32_t maxDecPicBuffering; |
| 154 | HRDInfo hrdParameters; |
| 155 | ProfileTierLevel ptl; |
| 156 | }; |
| 157 | |
| 158 | struct Window |
| 159 | { |
| 160 | bool bEnabled; |
| 161 | int leftOffset; |
| 162 | int rightOffset; |
| 163 | int topOffset; |
| 164 | int bottomOffset; |
| 165 | |
| 166 | Window() |
| 167 | { |
| 168 | bEnabled = false; |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | struct VUI |
| 173 | { |
| 174 | bool aspectRatioInfoPresentFlag; |
| 175 | int aspectRatioIdc; |
| 176 | int sarWidth; |
| 177 | int sarHeight; |
| 178 | |
| 179 | bool overscanInfoPresentFlag; |
| 180 | bool overscanAppropriateFlag; |
| 181 | |
| 182 | bool videoSignalTypePresentFlag; |
| 183 | int videoFormat; |
| 184 | bool videoFullRangeFlag; |
| 185 | |
| 186 | bool colourDescriptionPresentFlag; |
| 187 | int colourPrimaries; |
| 188 | int transferCharacteristics; |
| 189 | int matrixCoefficients; |
| 190 | |
| 191 | bool chromaLocInfoPresentFlag; |
| 192 | int chromaSampleLocTypeTopField; |
| 193 | int chromaSampleLocTypeBottomField; |
| 194 | |
| 195 | Window defaultDisplayWindow; |
| 196 | |
| 197 | bool frameFieldInfoPresentFlag; |
| 198 | bool fieldSeqFlag; |
| 199 | |
| 200 | bool hrdParametersPresentFlag; |
| 201 | HRDInfo hrdParameters; |
| 202 | |
| 203 | TimingInfo timingInfo; |
| 204 | }; |
| 205 | |
| 206 | struct SPS |
| 207 | { |
| 208 | int chromaFormatIdc; // use param |
| 209 | uint32_t picWidthInLumaSamples; // use param |
| 210 | uint32_t picHeightInLumaSamples; // use param |
| 211 | |
| 212 | uint32_t numCuInWidth; |
| 213 | uint32_t numCuInHeight; |
| 214 | uint32_t numCUsInFrame; |
| 215 | uint32_t numPartitions; |
| 216 | uint32_t numPartInCUSize; |
| 217 | |
| 218 | int log2MinCodingBlockSize; |
| 219 | int log2DiffMaxMinCodingBlockSize; |
| 220 | |
| 221 | uint32_t quadtreeTULog2MaxSize; |
| 222 | uint32_t quadtreeTULog2MinSize; |
| 223 | |
| 224 | uint32_t quadtreeTUMaxDepthInter; // use param |
| 225 | uint32_t quadtreeTUMaxDepthIntra; // use param |
| 226 | |
| 227 | bool bUseSAO; // use param |
| 228 | bool bUseAMP; // use param |
| 229 | uint32_t maxAMPDepth; |
| 230 | |
| 231 | uint32_t maxDecPicBuffering; // these are dups of VPS values |
| 232 | int numReorderPics; |
| 233 | |
| 234 | bool bUseStrongIntraSmoothing; // use param |
| 235 | bool bTemporalMVPEnabled; |
| 236 | |
| 237 | Window conformanceWindow; |
| 238 | VUI vuiParameters; |
| 239 | }; |
| 240 | |
| 241 | struct PPS |
| 242 | { |
| 243 | uint32_t maxCuDQPDepth; |
| 244 | |
| 245 | int chromaQpOffset[2]; // use param |
| 246 | |
| 247 | bool bUseWeightPred; // use param |
| 248 | bool bUseWeightedBiPred; // use param |
| 249 | bool bUseDQP; |
| 250 | bool bConstrainedIntraPred; // use param |
| 251 | |
| 252 | bool bTransquantBypassEnabled; // Indicates presence of cu_transquant_bypass_flag in CUs. |
| 253 | bool bTransformSkipEnabled; // use param |
| 254 | bool bEntropyCodingSyncEnabled; // use param |
| 255 | bool bSignHideEnabled; // use param |
| 256 | |
| 257 | bool bDeblockingFilterControlPresent; |
| 258 | bool bPicDisableDeblockingFilter; |
| 259 | int deblockingFilterBetaOffsetDiv2; |
| 260 | int deblockingFilterTcOffsetDiv2; |
| 261 | }; |
| 262 | |
| 263 | struct WeightParam |
| 264 | { |
| 265 | // Explicit weighted prediction parameters parsed in slice header, |
| 266 | bool bPresentFlag; |
| 267 | uint32_t log2WeightDenom; |
| 268 | int inputWeight; |
| 269 | int inputOffset; |
| 270 | |
| 271 | /* makes a non-h265 weight (i.e. fix7), into an h265 weight */ |
| 272 | void setFromWeightAndOffset(int w, int o, int denom, bool bNormalize) |
| 273 | { |
| 274 | inputOffset = o; |
| 275 | log2WeightDenom = denom; |
| 276 | inputWeight = w; |
| 277 | while (bNormalize && log2WeightDenom > 0 && (inputWeight > 127)) |
| 278 | { |
| 279 | log2WeightDenom--; |
| 280 | inputWeight >>= 1; |
| 281 | } |
| 282 | |
| 283 | inputWeight = X265_MIN(inputWeight, 127); |
| 284 | } |
| 285 | }; |
| 286 | |
| 287 | class Slice |
| 288 | { |
| 289 | public: |
| 290 | |
| 291 | const SPS* m_sps; |
| 292 | const PPS* m_pps; |
| 293 | WeightParam m_weightPredTable[2][MAX_NUM_REF][3]; // [list][refIdx][0:Y, 1:U, 2:V] |
| 294 | MotionReference (*m_mref)[MAX_NUM_REF + 1]; |
| 295 | RPS m_rps; |
| 296 | |
| 297 | NalUnitType m_nalUnitType; |
| 298 | SliceType m_sliceType; |
| 299 | int m_sliceQp; |
| 300 | int m_poc; |
| 301 | |
| 302 | int m_lastIDR; |
| 303 | |
| 304 | bool m_bCheckLDC; // TODO: is this necessary? |
| 305 | bool m_sLFaseFlag; // loop filter boundary flag |
| 306 | bool m_colFromL0Flag; // collocated picture from List0 or List1 flag |
| 307 | uint32_t m_colRefIdx; // never modified |
| 308 | |
| 309 | int m_numRefIdx[2]; |
| 310 | Frame* m_refPicList[2][MAX_NUM_REF + 1]; |
| 311 | int m_refPOCList[2][MAX_NUM_REF + 1]; |
| 312 | |
| 313 | uint32_t m_maxNumMergeCand; // use param |
| 314 | uint32_t m_endCUAddr; |
| 315 | |
| 316 | Slice() |
| 317 | { |
| 318 | m_lastIDR = 0; |
| 319 | m_sLFaseFlag = true; |
| 320 | m_numRefIdx[0] = m_numRefIdx[1] = 0; |
| 321 | for (int i = 0; i < MAX_NUM_REF; i++) |
| 322 | { |
| 323 | m_refPicList[0][i] = NULL; |
| 324 | m_refPicList[1][i] = NULL; |
| 325 | m_refPOCList[0][i] = 0; |
| 326 | m_refPOCList[1][i] = 0; |
| 327 | } |
| 328 | |
| 329 | disableWeights(); |
| 330 | } |
| 331 | |
| 332 | void disableWeights(); |
| 333 | |
| 334 | void setRefPicList(PicList& picList); |
| 335 | |
| 336 | const Frame* getRefPic(int list, int refIdx) const { return refIdx >= 0 ? m_refPicList[list][refIdx] : NULL; } |
| 337 | |
| 338 | bool getRapPicFlag() const |
| 339 | { |
| 340 | return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
| 341 | || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA; |
| 342 | } |
| 343 | |
| 344 | bool getIdrPicFlag() const |
| 345 | { |
| 346 | return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL; |
| 347 | } |
| 348 | |
| 349 | bool isIRAP() const { return m_nalUnitType >= 16 && m_nalUnitType <= 23; } |
| 350 | |
| 351 | bool isIntra() const { return m_sliceType == I_SLICE; } |
| 352 | |
| 353 | bool isInterB() const { return m_sliceType == B_SLICE; } |
| 354 | |
| 355 | bool isInterP() const { return m_sliceType == P_SLICE; } |
| 356 | |
| 357 | uint32_t realEndAddress(uint32_t endCUAddr) const; |
| 358 | }; |
| 359 | |
| 360 | } |
| 361 | |
| 362 | #endif // ifndef X265_SLICE_H |