xref: /aosp_15_r20/external/webrtc/modules/video_coding/utility/vp9_constants.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CODING_UTILITY_VP9_CONSTANTS_H_
12 #define MODULES_VIDEO_CODING_UTILITY_VP9_CONSTANTS_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <string>
18 
19 namespace webrtc {
20 
21 // Number of frames that can be stored for future reference.
22 constexpr size_t kVp9NumRefFrames = 8;
23 // Number of frame contexts that can be store for future reference.
24 constexpr size_t kVp9NumFrameContexts = 4;
25 // Each inter frame can use up to 3 frames for reference.
26 constexpr size_t kVp9RefsPerFrame = 3;
27 // Number of values that can be decoded for mv_fr.
28 constexpr size_t kVp9MvFrSize = 4;
29 // Number of positions to search in motion vector prediction.
30 constexpr size_t kVp9MvrefNeighbours = 8;
31 // Number of contexts when decoding intra_mode .
32 constexpr size_t kVp9BlockSizeGroups = 4;
33 // Number of different block sizes used.
34 constexpr size_t kVp9BlockSizes = 13;
35 // Sentinel value to mark partition choices that are illegal.
36 constexpr size_t kVp9BlockInvalid = 14;
37 // Number of contexts when decoding partition.
38 constexpr size_t kVp9PartitionContexts = 16;
39 // Smallest size of a mode info block.
40 constexpr size_t kVp9MiSize = 8;
41 // Minimum  width  of a  tile  in  units  of  superblocks  (although tiles on
42 // the right hand edge can be narrower).
43 constexpr size_t kVp9MinTileWidth_B64 = 4;
44 // Maximum width of a tile in units of superblocks.
45 constexpr size_t kVp9MaxTileWidth_B64 = 64;
46 // Number of motion vectors returned by find_mv_refs process.
47 constexpr size_t kVp9MaxMvRefCandidates = 2;
48 // Number of values that can be derived for ref_frame.
49 constexpr size_t kVp9MaxRefFrames = 4;
50 // Number of contexts for is_inter.
51 constexpr size_t kVp9IsInterContexts = 4;
52 // Number of contexts for comp_mode.
53 constexpr size_t kVp9CompModeContexts = 5;
54 // Number of contexts for single_ref and comp_ref.
55 constexpr size_t kVp9RefContexts = 5;
56 // Number of segments allowed in segmentation map.
57 constexpr size_t kVp9MaxSegments = 8;
58 // Index for quantizer segment feature.
59 constexpr size_t kVp9SegLvlAlt_Q = 0;
60 // Index for loop filter segment feature.
61 constexpr size_t kVp9SegLvlAlt_L = 1;
62 // Index for reference frame segment feature.
63 constexpr size_t kVp9SegLvlRefFrame = 2;
64 // Index for skip segment feature.
65 constexpr size_t kVp9SegLvlSkip = 3;
66 // Number of segment features.
67 constexpr size_t kVp9SegLvlMax = 4;
68 // Number of different plane types (Y or UV).
69 constexpr size_t kVp9BlockTypes = 2;
70 // Number of different prediction types (intra or inter).
71 constexpr size_t kVp9RefTypes = 2;
72 // Number of coefficient bands.
73 constexpr size_t kVp9CoefBands = 6;
74 // Number of contexts for decoding coefficients.
75 constexpr size_t kVp9PrevCoefContexts = 6;
76 // Number  of  coefficient  probabilities  that  are  directly transmitted.
77 constexpr size_t kVp9UnconstrainedNodes = 3;
78 // Number of contexts for transform size.
79 constexpr size_t kVp9TxSizeContexts = 2;
80 // Number of values for interp_filter.
81 constexpr size_t kVp9SwitchableFilters = 3;
82 // Number of contexts for interp_filter.
83 constexpr size_t kVp9InterpFilterContexts = 4;
84 // Number of contexts for decoding skip.
85 constexpr size_t kVp9SkipContexts = 3;
86 // Number of values for partition.
87 constexpr size_t kVp9PartitionTypes = 4;
88 // Number of values for tx_size.
89 constexpr size_t kVp9TxSizes = 4;
90 // Number of values for tx_mode.
91 constexpr size_t kVp9TxModes = 5;
92 // Inverse transform rows with DCT and columns with DCT.
93 constexpr size_t kVp9DctDct = 0;
94 // Inverse transform rows with DCT and columns with ADST.
95 constexpr size_t kVp9AdstDct = 1;
96 // Inverse transform rows with ADST and columns with DCT.
97 constexpr size_t kVp9DctAdst = 2;
98 // Inverse transform rows with ADST and columns with ADST.
99 constexpr size_t kVp9AdstAdst = 3;
100 // Number of values for y_mode.
101 constexpr size_t kVp9MbModeCount = 14;
102 // Number of values for intra_mode.
103 constexpr size_t kVp9IntraModes = 10;
104 // Number of values for inter_mode.
105 constexpr size_t kVp9InterModes = 4;
106 // Number of contexts for inter_mode.
107 constexpr size_t kVp9InterModeContexts = 7;
108 // Number of values for mv_joint.
109 constexpr size_t kVp9MvJoints = 4;
110 // Number of values for mv_class.
111 constexpr size_t kVp9MvClasses = 11;
112 // Number of values for mv_class0_bit.
113 constexpr size_t kVp9Class0Size = 2;
114 // Maximum number of bits for decoding motion vectors.
115 constexpr size_t kVp9MvOffsetBits = 10;
116 // Number of values allowed for a probability adjustment.
117 constexpr size_t kVp9MaxProb = 255;
118 // Number of different mode types for loop filtering.
119 constexpr size_t kVp9MaxModeLfDeltas = 2;
120 // Threshold at which motion vectors are considered large.
121 constexpr size_t kVp9CompandedMvrefThresh = 8;
122 // Maximum value used for loop filtering.
123 constexpr size_t kVp9MaxLoopFilter = 63;
124 // Number of bits of precision when scaling reference frames.
125 constexpr size_t kVp9RefScaleShift = 14;
126 // Number of bits of precision when performing inter prediction.
127 constexpr size_t kVp9SubpelBits = 4;
128 // 1 << kVp9SubpelBits.
129 constexpr size_t kVp9SubpelShifts = 16;
130 // kVp9SubpelShifts - 1.
131 constexpr size_t kVp9SubpelMask = 15;
132 // Value used when clipping motion vectors.
133 constexpr size_t kVp9MvBorder = 128;
134 // Value used when clipping motion vectors.
135 constexpr size_t kVp9InterpExtend = 4;
136 // Value used when clipping motion vectors.
137 constexpr size_t kVp9Borderinpixels = 160;
138 // Value used in adapting probabilities.
139 constexpr size_t kVp9MaxUpdateFactor = 128;
140 // Value used in adapting probabilities.
141 constexpr size_t kVp9CountSat = 20;
142 // Both candidates use ZEROMV.
143 constexpr size_t kVp9BothZero = 0;
144 // One  candidate uses ZEROMV, one uses NEARMV or NEARESTMV.
145 constexpr size_t kVp9ZeroPlusPredicted = 1;
146 // Both candidates use NEARMV or NEARESTMV.
147 constexpr size_t kVp9BothPredicted = 2;
148 // One candidate uses NEWMV, one uses ZEROMV.
149 constexpr size_t kVp9NewPlusNonIntra = 3;
150 // Both candidates use NEWMV.
151 constexpr size_t kVp9BothNew = 4;
152 // One candidate uses intra prediction, one uses inter prediction.
153 constexpr size_t kVp9IntraPlusNonIntra = 5;
154 // Both candidates use intra prediction.
155 constexpr size_t kVp9BothIntra = 6;
156 // Sentinel value marking a case that can never occur.
157 constexpr size_t kVp9InvalidCase = 9;
158 
159 enum class Vp9TxMode : uint8_t {
160   kOnly4X4 = 0,
161   kAllow8X8 = 1,
162   kAllow16x16 = 2,
163   kAllow32x32 = 3,
164   kTxModeSelect = 4
165 };
166 
167 enum Vp9BlockSize : uint8_t {
168   kBlock4X4 = 0,
169   kBlock4X8 = 1,
170   kBlock8X4 = 2,
171   kBlock8X8 = 3,
172   kBlock8X16 = 4,
173   kBlock16X8 = 5,
174   kBlock16X16 = 6,
175   kBlock16X32 = 7,
176   kBlock32X16 = 8,
177   kBlock32X32 = 9,
178   kBlock32X64 = 10,
179   kBlock64X32 = 11,
180   kBlock64X64 = 12
181 };
182 
183 enum Vp9Partition : uint8_t {
184   kPartitionNone = 0,
185   kPartitionHorizontal = 1,
186   kPartitionVertical = 2,
187   kPartitionSplit = 3
188 };
189 
190 enum class Vp9ReferenceMode : uint8_t {
191   kSingleReference = 0,
192   kCompoundReference = 1,
193   kReferenceModeSelect = 2,
194 };
195 
196 }  // namespace webrtc
197 
198 #endif  // MODULES_VIDEO_CODING_UTILITY_VP9_CONSTANTS_H_
199