/work/x265/source/common/slice.h
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Steve Borho <steve@borho.org> |
5 | | * Min Chen <chenm003@163.com> |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * This program is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License |
18 | | * along with this program; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
20 | | * |
21 | | * This program is also available under a commercial proprietary license. |
22 | | * For more information, contact us at license @ x265.com. |
23 | | *****************************************************************************/ |
24 | | |
25 | | #ifndef X265_SLICE_H |
26 | | #define X265_SLICE_H |
27 | | |
28 | | #include "common.h" |
29 | | #include "mv.h" |
30 | | |
31 | | namespace X265_NS { |
32 | | // private namespace |
33 | | |
34 | | class Frame; |
35 | | class PicList; |
36 | | class PicYuv; |
37 | | class MotionReference; |
38 | | |
39 | | struct MEData; |
40 | | |
41 | | enum SliceType |
42 | | { |
43 | | B_SLICE, |
44 | | P_SLICE, |
45 | | I_SLICE |
46 | | }; |
47 | | |
48 | | struct RPS |
49 | | { |
50 | | int numberOfPictures; |
51 | | int numberOfNegativePictures; |
52 | | int numberOfPositivePictures; |
53 | | |
54 | | int poc[MAX_NUM_REF_PICS]; |
55 | | int deltaPOC[MAX_NUM_REF_PICS]; |
56 | | bool bUsed[MAX_NUM_REF_PICS]; |
57 | | |
58 | | RPS() |
59 | 45.4k | : numberOfPictures(0) |
60 | 45.4k | , numberOfNegativePictures(0) |
61 | 45.4k | , numberOfPositivePictures(0) |
62 | 45.4k | { |
63 | 45.4k | memset(deltaPOC, 0, sizeof(deltaPOC)); |
64 | 45.4k | memset(poc, 0, sizeof(poc)); |
65 | 45.4k | memset(bUsed, 0, sizeof(bUsed)); |
66 | 45.4k | } |
67 | | |
68 | | void sortDeltaPOC(); |
69 | | }; |
70 | | |
71 | | namespace Profile { |
72 | | enum Name |
73 | | { |
74 | | NONE = 0, |
75 | | MAIN = 1, |
76 | | MAIN10 = 2, |
77 | | MAINSTILLPICTURE = 3, |
78 | | MAINREXT = 4, |
79 | | HIGHTHROUGHPUTREXT = 5, |
80 | | MULTIVIEWMAIN = 6, |
81 | | SCALABLEMAIN = 7, |
82 | | SCALABLEMAIN10 = 8, |
83 | | MAINSCC = 9 |
84 | | }; |
85 | | } |
86 | | |
87 | | namespace Level { |
88 | | enum Tier |
89 | | { |
90 | | MAIN = 0, |
91 | | HIGH = 1, |
92 | | }; |
93 | | |
94 | | enum Name |
95 | | { |
96 | | NONE = 0, |
97 | | LEVEL1 = 30, |
98 | | LEVEL2 = 60, |
99 | | LEVEL2_1 = 63, |
100 | | LEVEL3 = 90, |
101 | | LEVEL3_1 = 93, |
102 | | LEVEL4 = 120, |
103 | | LEVEL4_1 = 123, |
104 | | LEVEL5 = 150, |
105 | | LEVEL5_1 = 153, |
106 | | LEVEL5_2 = 156, |
107 | | LEVEL6 = 180, |
108 | | LEVEL6_1 = 183, |
109 | | LEVEL6_2 = 186, |
110 | | LEVEL6_3 = 189, |
111 | | LEVEL7 = 210, |
112 | | LEVEL7_1 = 213, |
113 | | LEVEL7_2 = 216, |
114 | | LEVEL8_5 = 255, |
115 | | }; |
116 | | } |
117 | | |
118 | | struct ProfileTierLevel |
119 | | { |
120 | | int profileIdc[MAX_LAYERS]; |
121 | | int levelIdc; |
122 | | uint32_t minCrForLevel; |
123 | | uint64_t maxLumaSrForLevel; |
124 | | uint32_t bitDepthConstraint; |
125 | | int chromaFormatConstraint; |
126 | | bool tierFlag; |
127 | | bool progressiveSourceFlag; |
128 | | bool interlacedSourceFlag; |
129 | | bool nonPackedConstraintFlag; |
130 | | bool frameOnlyConstraintFlag; |
131 | | bool profileCompatibilityFlag[32]; |
132 | | bool intraConstraintFlag; |
133 | | bool onePictureOnlyConstraintFlag; |
134 | | bool lowerBitRateConstraintFlag; |
135 | | }; |
136 | | |
137 | | struct HRDInfo |
138 | | { |
139 | | uint32_t bitRateScale; |
140 | | uint32_t cpbSizeScale; |
141 | | uint32_t initialCpbRemovalDelayLength; |
142 | | uint32_t cpbRemovalDelayLength; |
143 | | uint32_t dpbOutputDelayLength; |
144 | | uint32_t bitRateValue; |
145 | | uint32_t cpbSizeValue; |
146 | | bool cbrFlag; |
147 | | |
148 | | HRDInfo() |
149 | 1.30k | : bitRateScale(0) |
150 | 1.30k | , cpbSizeScale(0) |
151 | 1.30k | , initialCpbRemovalDelayLength(1) |
152 | 1.30k | , cpbRemovalDelayLength(1) |
153 | 1.30k | , dpbOutputDelayLength(1) |
154 | 1.30k | , cbrFlag(false) |
155 | 1.30k | { |
156 | 1.30k | } |
157 | | }; |
158 | | |
159 | | struct TimingInfo |
160 | | { |
161 | | uint32_t numUnitsInTick; |
162 | | uint32_t timeScale; |
163 | | }; |
164 | | |
165 | | struct VPS |
166 | | { |
167 | | HRDInfo hrdParameters; |
168 | | ProfileTierLevel ptl; |
169 | | uint32_t maxTempSubLayers; |
170 | | uint32_t numReorderPics[MAX_T_LAYERS]; |
171 | | uint32_t maxDecPicBuffering[MAX_T_LAYERS]; |
172 | | uint32_t maxLatencyIncrease[MAX_T_LAYERS]; |
173 | | int m_numLayers; |
174 | | int m_numViews; |
175 | | bool vps_extension_flag; |
176 | | |
177 | | #if (ENABLE_ALPHA || ENABLE_MULTIVIEW) |
178 | | bool splitting_flag; |
179 | | int m_scalabilityMask[MAX_VPS_NUM_SCALABILITY_TYPES]; |
180 | | int scalabilityTypes; |
181 | | uint8_t m_dimensionIdLen[MAX_VPS_NUM_SCALABILITY_TYPES]; |
182 | | uint8_t m_dimensionId[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_NUM_SCALABILITY_TYPES]; |
183 | | bool m_nuhLayerIdPresentFlag; |
184 | | uint8_t m_layerIdInNuh[MAX_VPS_LAYER_ID_PLUS1]; |
185 | | uint8_t m_layerIdInVps[MAX_VPS_LAYER_ID_PLUS1]; |
186 | | int m_viewIdLen; |
187 | | int m_vpsNumLayerSetsMinus1; |
188 | | int m_numLayersInIdList[1023]; |
189 | | #endif |
190 | | |
191 | | #if ENABLE_MULTIVIEW |
192 | | int m_layerIdIncludedFlag; |
193 | | #endif |
194 | | }; |
195 | | |
196 | | struct Window |
197 | | { |
198 | | int leftOffset; |
199 | | int rightOffset; |
200 | | int topOffset; |
201 | | int bottomOffset; |
202 | | bool bEnabled; |
203 | | |
204 | | Window() |
205 | 1.96k | { |
206 | 1.96k | bEnabled = false; |
207 | 1.96k | } |
208 | | }; |
209 | | |
210 | | struct VUI |
211 | | { |
212 | | int aspectRatioIdc; |
213 | | int sarWidth; |
214 | | int sarHeight; |
215 | | int videoFormat; |
216 | | int colourPrimaries; |
217 | | int transferCharacteristics; |
218 | | int matrixCoefficients; |
219 | | int chromaSampleLocTypeTopField; |
220 | | int chromaSampleLocTypeBottomField; |
221 | | |
222 | | bool aspectRatioInfoPresentFlag; |
223 | | bool overscanInfoPresentFlag; |
224 | | bool overscanAppropriateFlag; |
225 | | bool videoSignalTypePresentFlag; |
226 | | bool videoFullRangeFlag; |
227 | | bool colourDescriptionPresentFlag; |
228 | | bool chromaLocInfoPresentFlag; |
229 | | bool frameFieldInfoPresentFlag; |
230 | | bool fieldSeqFlag; |
231 | | bool hrdParametersPresentFlag; |
232 | | |
233 | | HRDInfo hrdParameters; |
234 | | Window defaultDisplayWindow; |
235 | | TimingInfo timingInfo; |
236 | | }; |
237 | | |
238 | | struct SPS |
239 | | { |
240 | | /* cached PicYuv offset arrays, shared by all instances of |
241 | | * PicYuv created by this encoder */ |
242 | | intptr_t* cuOffsetY; |
243 | | intptr_t* cuOffsetC; |
244 | | intptr_t* buOffsetY; |
245 | | intptr_t* buOffsetC; |
246 | | |
247 | | int chromaFormatIdc; // use param |
248 | | uint32_t picWidthInLumaSamples; // use param |
249 | | uint32_t picHeightInLumaSamples; // use param |
250 | | |
251 | | uint32_t numCuInWidth; |
252 | | uint32_t numCuInHeight; |
253 | | uint32_t numCUsInFrame; |
254 | | uint32_t numPartitions; |
255 | | uint32_t numPartInCUSize; |
256 | | |
257 | | int log2MinCodingBlockSize; |
258 | | int log2DiffMaxMinCodingBlockSize; |
259 | | int log2MaxPocLsb; |
260 | | |
261 | | uint32_t quadtreeTULog2MaxSize; |
262 | | uint32_t quadtreeTULog2MinSize; |
263 | | |
264 | | uint32_t quadtreeTUMaxDepthInter; // use param |
265 | | uint32_t quadtreeTUMaxDepthIntra; // use param |
266 | | |
267 | | uint32_t maxAMPDepth; |
268 | | |
269 | | uint32_t maxTempSubLayers; // max number of Temporal Sub layers |
270 | | uint32_t maxDecPicBuffering[MAX_T_LAYERS]; // these are dups of VPS values |
271 | | uint32_t maxLatencyIncrease[MAX_T_LAYERS]; |
272 | | int numReorderPics[MAX_T_LAYERS]; |
273 | | |
274 | | RPS spsrps[MAX_NUM_SHORT_TERM_RPS]; |
275 | | int spsrpsNum; |
276 | | int numGOPBegin; |
277 | | |
278 | | bool bUseSAO; // use param |
279 | | bool bUseAMP; // use param |
280 | | bool bUseStrongIntraSmoothing; // use param |
281 | | bool bTemporalMVPEnabled; |
282 | | bool bEmitVUITimingInfo; |
283 | | bool bEmitVUIHRDInfo; |
284 | | |
285 | | Window conformanceWindow; |
286 | | VUI vuiParameters; |
287 | | bool sps_extension_flag; |
288 | | |
289 | | #if ENABLE_MULTIVIEW |
290 | | int setSpsExtOrMaxSubLayersMinus1; |
291 | | int spsInferScalingListFlag; |
292 | | int maxViews; |
293 | | bool vui_parameters_present_flag; |
294 | | #endif |
295 | | |
296 | | SPS() |
297 | 654 | { |
298 | 654 | memset(this, 0, sizeof(*this)); |
299 | 654 | } |
300 | | |
301 | | ~SPS() |
302 | 654 | { |
303 | 654 | X265_FREE(cuOffsetY); |
304 | 654 | X265_FREE(cuOffsetC); |
305 | 654 | X265_FREE(buOffsetY); |
306 | 654 | X265_FREE(buOffsetC); |
307 | 654 | } |
308 | | }; |
309 | | |
310 | | struct PPS |
311 | | { |
312 | | uint32_t maxCuDQPDepth; |
313 | | |
314 | | int chromaQpOffset[2]; // use param |
315 | | int deblockingFilterBetaOffsetDiv2; |
316 | | int deblockingFilterTcOffsetDiv2; |
317 | | |
318 | | bool bUseWeightPred; // use param |
319 | | bool bUseWeightedBiPred; // use param |
320 | | bool bUseDQP; |
321 | | bool bConstrainedIntraPred; // use param |
322 | | |
323 | | bool bTransquantBypassEnabled; // Indicates presence of cu_transquant_bypass_flag in CUs. |
324 | | bool bTransformSkipEnabled; // use param |
325 | | bool bEntropyCodingSyncEnabled; // use param |
326 | | bool bSignHideEnabled; // use param |
327 | | |
328 | | bool bDeblockingFilterControlPresent; |
329 | | bool bPicDisableDeblockingFilter; |
330 | | |
331 | | int numRefIdxDefault[2]; |
332 | | bool pps_slice_chroma_qp_offsets_present_flag; |
333 | | |
334 | | bool pps_extension_flag; |
335 | | int maxViews; |
336 | | |
337 | | int profileIdc; |
338 | | }; |
339 | | |
340 | | struct WeightParam |
341 | | { |
342 | | // Explicit weighted prediction parameters parsed in slice header, |
343 | | uint32_t log2WeightDenom; |
344 | | int inputWeight; |
345 | | int inputOffset; |
346 | | int wtPresent; |
347 | | |
348 | | /* makes a non-h265 weight (i.e. fix7), into an h265 weight */ |
349 | | void setFromWeightAndOffset(int w, int o, int denom, bool bNormalize) |
350 | 0 | { |
351 | 0 | inputOffset = o; |
352 | 0 | log2WeightDenom = denom; |
353 | 0 | inputWeight = w; |
354 | 0 | while (bNormalize && log2WeightDenom > 0 && (inputWeight > 127)) |
355 | 0 | { |
356 | 0 | log2WeightDenom--; |
357 | 0 | inputWeight >>= 1; |
358 | 0 | } |
359 | |
|
360 | 0 | inputWeight = X265_MIN(inputWeight, 127); |
361 | 0 | } |
362 | | }; |
363 | | |
364 | | #define SET_WEIGHT(w, b, s, d, o) \ |
365 | 0 | { \ |
366 | 0 | (w).inputWeight = (s); \ |
367 | 0 | (w).log2WeightDenom = (d); \ |
368 | 0 | (w).inputOffset = (o); \ |
369 | 0 | (w).wtPresent = (b); \ |
370 | 0 | } |
371 | | |
372 | | class Slice |
373 | | { |
374 | | public: |
375 | | |
376 | | const SPS* m_sps; |
377 | | const PPS* m_pps; |
378 | | Frame* m_refFrameList[2][MAX_NUM_REF + 1]; |
379 | | PicYuv* m_refReconPicList[2][MAX_NUM_REF + 1]; |
380 | | |
381 | | WeightParam m_weightPredTable[2][MAX_NUM_REF][3]; // [list][refIdx][0:Y, 1:U, 2:V] |
382 | | MotionReference (*m_mref)[MAX_NUM_REF + 1]; |
383 | | RPS m_rps; |
384 | | MEData* m_ctuMV; |
385 | | |
386 | | NalUnitType m_nalUnitType; |
387 | | SliceType m_sliceType; |
388 | | SliceType m_origSliceType; |
389 | | int m_sliceQp; |
390 | | int m_chromaQpOffset[2]; |
391 | | int m_poc; |
392 | | int m_lastIDR; |
393 | | int m_rpsIdx; |
394 | | |
395 | | uint32_t m_colRefIdx; // never modified |
396 | | |
397 | | int m_numRefIdx[2]; |
398 | | int m_refPOCList[2][MAX_NUM_REF + 1]; |
399 | | |
400 | | uint32_t m_maxNumMergeCand; // use param |
401 | | uint32_t m_endCUAddr; |
402 | | |
403 | | bool m_bCheckLDC; // TODO: is this necessary? |
404 | | bool m_sLFaseFlag; // loop filter boundary flag |
405 | | bool m_colFromL0Flag; // collocated picture from List0 or List1 flag |
406 | | int m_bUseSao; |
407 | | |
408 | | int m_iPPSQpMinus26; |
409 | | int numRefIdxDefault[2]; |
410 | | int m_iNumRPSInSPS; |
411 | | const x265_param *m_param; |
412 | | int m_fieldNum; |
413 | | Frame* m_mcstfRefFrameList[2][MAX_MCSTF_TEMPORAL_WINDOW_LENGTH]; |
414 | | |
415 | | #if ENABLE_SCC_EXT |
416 | | Frame* m_lastEncPic; |
417 | | bool m_useIntegerMv; |
418 | | #endif |
419 | | bool m_bTemporalMvp; |
420 | | |
421 | | Slice() |
422 | 654 | { |
423 | 654 | m_lastIDR = 0; |
424 | 654 | m_sLFaseFlag = true; |
425 | 654 | m_numRefIdx[0] = m_numRefIdx[1] = 0; |
426 | 654 | m_ctuMV = NULL; |
427 | 654 | memset(m_refFrameList, 0, sizeof(m_refFrameList)); |
428 | 654 | memset(m_refReconPicList, 0, sizeof(m_refReconPicList)); |
429 | 654 | memset(m_refPOCList, 0, sizeof(m_refPOCList)); |
430 | 654 | disableWeights(); |
431 | 654 | m_iPPSQpMinus26 = 0; |
432 | 654 | numRefIdxDefault[0] = 1; |
433 | 654 | numRefIdxDefault[1] = 1; |
434 | 654 | m_rpsIdx = -1; |
435 | 654 | m_chromaQpOffset[0] = m_chromaQpOffset[1] = 0; |
436 | 654 | m_fieldNum = 0; |
437 | | #if ENABLE_SCC_EXT |
438 | | m_lastEncPic = NULL; |
439 | | m_useIntegerMv = false; |
440 | | #endif |
441 | 654 | m_bTemporalMvp = false; |
442 | 654 | } |
443 | | |
444 | | void disableWeights(); |
445 | | |
446 | | #if ENABLE_MULTIVIEW |
447 | | void setRefPicList(PicList& picList, int viewId, PicList& refPicSetInterLayer0, PicList& refPicSetInterLayer1); |
448 | | void createInterLayerReferencePictureSet(PicList& picList, PicList& refPicSetInterLayer0, PicList& refPicSetInterLayer1); |
449 | | #else |
450 | | void setRefPicList(PicList& picList, int viewId); |
451 | | #endif |
452 | | |
453 | | #if ENABLE_SCC_EXT |
454 | | bool isOnlyCurrentPictureAsReference() const; |
455 | | #endif |
456 | | |
457 | | bool getRapPicFlag() const |
458 | 654 | { |
459 | 654 | return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
460 | 654 | || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
461 | 0 | || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA; |
462 | 654 | } |
463 | | bool getIdrPicFlag() const |
464 | 1.30k | { |
465 | 1.30k | return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
466 | 1.30k | || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP; |
467 | 1.30k | } |
468 | 654 | bool isIRAP() const { return m_nalUnitType >= 16 && m_nalUnitType <= 23; } |
469 | | |
470 | 12.1M | bool isIntra() const { return m_sliceType == I_SLICE; } |
471 | | |
472 | 1.96k | bool isInterB() const { return m_sliceType == B_SLICE; } |
473 | | |
474 | 1.30k | bool isInterP() const { return m_sliceType == P_SLICE; } |
475 | | |
476 | | uint32_t realEndAddress(uint32_t endCUAddr) const; |
477 | | }; |
478 | | |
479 | | } |
480 | | |
481 | | #endif // ifndef X265_SLICE_H |