1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2021 Collabora, Ltd.
7 * Author: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
10 #include <linux/module.h>
12 #include <media/v4l2-vp9.h>
14 const u8 v4l2_vp9_kf_y_mode_prob
[10][10][9] = {
17 { 137, 30, 42, 148, 151, 207, 70, 52, 91 }, /*left = dc */
18 { 92, 45, 102, 136, 116, 180, 74, 90, 100 }, /*left = v */
19 { 73, 32, 19, 187, 222, 215, 46, 34, 100 }, /*left = h */
20 { 91, 30, 32, 116, 121, 186, 93, 86, 94 }, /*left = d45 */
21 { 72, 35, 36, 149, 68, 206, 68, 63, 105 }, /*left = d135*/
22 { 73, 31, 28, 138, 57, 124, 55, 122, 151 }, /*left = d117*/
23 { 67, 23, 21, 140, 126, 197, 40, 37, 171 }, /*left = d153*/
24 { 86, 27, 28, 128, 154, 212, 45, 43, 53 }, /*left = d207*/
25 { 74, 32, 27, 107, 86, 160, 63, 134, 102 }, /*left = d63 */
26 { 59, 67, 44, 140, 161, 202, 78, 67, 119 }, /*left = tm */
28 { 63, 36, 126, 146, 123, 158, 60, 90, 96 }, /*left = dc */
29 { 43, 46, 168, 134, 107, 128, 69, 142, 92 }, /*left = v */
30 { 44, 29, 68, 159, 201, 177, 50, 57, 77 }, /*left = h */
31 { 58, 38, 76, 114, 97, 172, 78, 133, 92 }, /*left = d45 */
32 { 46, 41, 76, 140, 63, 184, 69, 112, 57 }, /*left = d135*/
33 { 38, 32, 85, 140, 46, 112, 54, 151, 133 }, /*left = d117*/
34 { 39, 27, 61, 131, 110, 175, 44, 75, 136 }, /*left = d153*/
35 { 52, 30, 74, 113, 130, 175, 51, 64, 58 }, /*left = d207*/
36 { 47, 35, 80, 100, 74, 143, 64, 163, 74 }, /*left = d63 */
37 { 36, 61, 116, 114, 128, 162, 80, 125, 82 }, /*left = tm */
39 { 82, 26, 26, 171, 208, 204, 44, 32, 105 }, /*left = dc */
40 { 55, 44, 68, 166, 179, 192, 57, 57, 108 }, /*left = v */
41 { 42, 26, 11, 199, 241, 228, 23, 15, 85 }, /*left = h */
42 { 68, 42, 19, 131, 160, 199, 55, 52, 83 }, /*left = d45 */
43 { 58, 50, 25, 139, 115, 232, 39, 52, 118 }, /*left = d135*/
44 { 50, 35, 33, 153, 104, 162, 64, 59, 131 }, /*left = d117*/
45 { 44, 24, 16, 150, 177, 202, 33, 19, 156 }, /*left = d153*/
46 { 55, 27, 12, 153, 203, 218, 26, 27, 49 }, /*left = d207*/
47 { 53, 49, 21, 110, 116, 168, 59, 80, 76 }, /*left = d63 */
48 { 38, 72, 19, 168, 203, 212, 50, 50, 107 }, /*left = tm */
49 }, { /* above = d45 */
50 { 103, 26, 36, 129, 132, 201, 83, 80, 93 }, /*left = dc */
51 { 59, 38, 83, 112, 103, 162, 98, 136, 90 }, /*left = v */
52 { 62, 30, 23, 158, 200, 207, 59, 57, 50 }, /*left = h */
53 { 67, 30, 29, 84, 86, 191, 102, 91, 59 }, /*left = d45 */
54 { 60, 32, 33, 112, 71, 220, 64, 89, 104 }, /*left = d135*/
55 { 53, 26, 34, 130, 56, 149, 84, 120, 103 }, /*left = d117*/
56 { 53, 21, 23, 133, 109, 210, 56, 77, 172 }, /*left = d153*/
57 { 77, 19, 29, 112, 142, 228, 55, 66, 36 }, /*left = d207*/
58 { 61, 29, 29, 93, 97, 165, 83, 175, 162 }, /*left = d63 */
59 { 47, 47, 43, 114, 137, 181, 100, 99, 95 }, /*left = tm */
60 }, { /* above = d135 */
61 { 69, 23, 29, 128, 83, 199, 46, 44, 101 }, /*left = dc */
62 { 53, 40, 55, 139, 69, 183, 61, 80, 110 }, /*left = v */
63 { 40, 29, 19, 161, 180, 207, 43, 24, 91 }, /*left = h */
64 { 60, 34, 19, 105, 61, 198, 53, 64, 89 }, /*left = d45 */
65 { 52, 31, 22, 158, 40, 209, 58, 62, 89 }, /*left = d135*/
66 { 44, 31, 29, 147, 46, 158, 56, 102, 198 }, /*left = d117*/
67 { 35, 19, 12, 135, 87, 209, 41, 45, 167 }, /*left = d153*/
68 { 55, 25, 21, 118, 95, 215, 38, 39, 66 }, /*left = d207*/
69 { 51, 38, 25, 113, 58, 164, 70, 93, 97 }, /*left = d63 */
70 { 47, 54, 34, 146, 108, 203, 72, 103, 151 }, /*left = tm */
71 }, { /* above = d117 */
72 { 64, 19, 37, 156, 66, 138, 49, 95, 133 }, /*left = dc */
73 { 46, 27, 80, 150, 55, 124, 55, 121, 135 }, /*left = v */
74 { 36, 23, 27, 165, 149, 166, 54, 64, 118 }, /*left = h */
75 { 53, 21, 36, 131, 63, 163, 60, 109, 81 }, /*left = d45 */
76 { 40, 26, 35, 154, 40, 185, 51, 97, 123 }, /*left = d135*/
77 { 35, 19, 34, 179, 19, 97, 48, 129, 124 }, /*left = d117*/
78 { 36, 20, 26, 136, 62, 164, 33, 77, 154 }, /*left = d153*/
79 { 45, 18, 32, 130, 90, 157, 40, 79, 91 }, /*left = d207*/
80 { 45, 26, 28, 129, 45, 129, 49, 147, 123 }, /*left = d63 */
81 { 38, 44, 51, 136, 74, 162, 57, 97, 121 }, /*left = tm */
82 }, { /* above = d153 */
83 { 75, 17, 22, 136, 138, 185, 32, 34, 166 }, /*left = dc */
84 { 56, 39, 58, 133, 117, 173, 48, 53, 187 }, /*left = v */
85 { 35, 21, 12, 161, 212, 207, 20, 23, 145 }, /*left = h */
86 { 56, 29, 19, 117, 109, 181, 55, 68, 112 }, /*left = d45 */
87 { 47, 29, 17, 153, 64, 220, 59, 51, 114 }, /*left = d135*/
88 { 46, 16, 24, 136, 76, 147, 41, 64, 172 }, /*left = d117*/
89 { 34, 17, 11, 108, 152, 187, 13, 15, 209 }, /*left = d153*/
90 { 51, 24, 14, 115, 133, 209, 32, 26, 104 }, /*left = d207*/
91 { 55, 30, 18, 122, 79, 179, 44, 88, 116 }, /*left = d63 */
92 { 37, 49, 25, 129, 168, 164, 41, 54, 148 }, /*left = tm */
93 }, { /* above = d207 */
94 { 82, 22, 32, 127, 143, 213, 39, 41, 70 }, /*left = dc */
95 { 62, 44, 61, 123, 105, 189, 48, 57, 64 }, /*left = v */
96 { 47, 25, 17, 175, 222, 220, 24, 30, 86 }, /*left = h */
97 { 68, 36, 17, 106, 102, 206, 59, 74, 74 }, /*left = d45 */
98 { 57, 39, 23, 151, 68, 216, 55, 63, 58 }, /*left = d135*/
99 { 49, 30, 35, 141, 70, 168, 82, 40, 115 }, /*left = d117*/
100 { 51, 25, 15, 136, 129, 202, 38, 35, 139 }, /*left = d153*/
101 { 68, 26, 16, 111, 141, 215, 29, 28, 28 }, /*left = d207*/
102 { 59, 39, 19, 114, 75, 180, 77, 104, 42 }, /*left = d63 */
103 { 40, 61, 26, 126, 152, 206, 61, 59, 93 }, /*left = tm */
104 }, { /* above = d63 */
105 { 78, 23, 39, 111, 117, 170, 74, 124, 94 }, /*left = dc */
106 { 48, 34, 86, 101, 92, 146, 78, 179, 134 }, /*left = v */
107 { 47, 22, 24, 138, 187, 178, 68, 69, 59 }, /*left = h */
108 { 56, 25, 33, 105, 112, 187, 95, 177, 129 }, /*left = d45 */
109 { 48, 31, 27, 114, 63, 183, 82, 116, 56 }, /*left = d135*/
110 { 43, 28, 37, 121, 63, 123, 61, 192, 169 }, /*left = d117*/
111 { 42, 17, 24, 109, 97, 177, 56, 76, 122 }, /*left = d153*/
112 { 58, 18, 28, 105, 139, 182, 70, 92, 63 }, /*left = d207*/
113 { 46, 23, 32, 74, 86, 150, 67, 183, 88 }, /*left = d63 */
114 { 36, 38, 48, 92, 122, 165, 88, 137, 91 }, /*left = tm */
115 }, { /* above = tm */
116 { 65, 70, 60, 155, 159, 199, 61, 60, 81 }, /*left = dc */
117 { 44, 78, 115, 132, 119, 173, 71, 112, 93 }, /*left = v */
118 { 39, 38, 21, 184, 227, 206, 42, 32, 64 }, /*left = h */
119 { 58, 47, 36, 124, 137, 193, 80, 82, 78 }, /*left = d45 */
120 { 49, 50, 35, 144, 95, 205, 63, 78, 59 }, /*left = d135*/
121 { 41, 53, 52, 148, 71, 142, 65, 128, 51 }, /*left = d117*/
122 { 40, 36, 28, 143, 143, 202, 40, 55, 137 }, /*left = d153*/
123 { 52, 34, 29, 129, 183, 227, 42, 35, 43 }, /*left = d207*/
124 { 42, 44, 44, 104, 105, 164, 64, 130, 80 }, /*left = d63 */
125 { 43, 81, 53, 140, 169, 204, 68, 84, 72 }, /*left = tm */
128 EXPORT_SYMBOL_GPL(v4l2_vp9_kf_y_mode_prob
);
130 const u8 v4l2_vp9_kf_partition_probs
[16][3] = {
132 { 158, 97, 94 }, /* a/l both not split */
133 { 93, 24, 99 }, /* a split, l not split */
134 { 85, 119, 44 }, /* l split, a not split */
135 { 62, 59, 67 }, /* a/l both split */
137 { 149, 53, 53 }, /* a/l both not split */
138 { 94, 20, 48 }, /* a split, l not split */
139 { 83, 53, 24 }, /* l split, a not split */
140 { 52, 18, 18 }, /* a/l both split */
142 { 150, 40, 39 }, /* a/l both not split */
143 { 78, 12, 26 }, /* a split, l not split */
144 { 67, 33, 11 }, /* l split, a not split */
145 { 24, 7, 5 }, /* a/l both split */
147 { 174, 35, 49 }, /* a/l both not split */
148 { 68, 11, 27 }, /* a split, l not split */
149 { 57, 15, 9 }, /* l split, a not split */
150 { 12, 3, 3 }, /* a/l both split */
152 EXPORT_SYMBOL_GPL(v4l2_vp9_kf_partition_probs
);
154 const u8 v4l2_vp9_kf_uv_mode_prob
[10][9] = {
155 { 144, 11, 54, 157, 195, 130, 46, 58, 108 }, /* y = dc */
156 { 118, 15, 123, 148, 131, 101, 44, 93, 131 }, /* y = v */
157 { 113, 12, 23, 188, 226, 142, 26, 32, 125 }, /* y = h */
158 { 120, 11, 50, 123, 163, 135, 64, 77, 103 }, /* y = d45 */
159 { 113, 9, 36, 155, 111, 157, 32, 44, 161 }, /* y = d135 */
160 { 116, 9, 55, 176, 76, 96, 37, 61, 149 }, /* y = d117 */
161 { 115, 9, 28, 141, 161, 167, 21, 25, 193 }, /* y = d153 */
162 { 120, 12, 32, 145, 195, 142, 32, 38, 86 }, /* y = d207 */
163 { 116, 12, 64, 120, 140, 125, 49, 115, 121 }, /* y = d63 */
164 { 102, 19, 66, 162, 182, 122, 35, 59, 128 } /* y = tm */
166 EXPORT_SYMBOL_GPL(v4l2_vp9_kf_uv_mode_prob
);
168 const struct v4l2_vp9_frame_context v4l2_vp9_default_probs
= {
1008 .skip
= { 192, 128, 64 },
1024 .is_inter
= { 9, 102, 187, 225 },
1025 .comp_mode
= { 239, 183, 119, 96, 41 },
1033 .comp_ref
= { 50, 126, 123, 221, 226 },
1035 { 65, 32, 18, 144, 162, 194, 41, 51, 98 },
1036 { 132, 68, 18, 165, 217, 196, 45, 40, 78 },
1037 { 173, 80, 19, 176, 240, 193, 64, 35, 46 },
1038 { 221, 135, 38, 194, 248, 121, 96, 85, 29 },
1041 { 120, 7, 76, 176, 208, 126, 28, 54, 103 } /* y = dc */,
1042 { 48, 12, 154, 155, 139, 90, 34, 117, 119 } /* y = v */,
1043 { 67, 6, 25, 204, 243, 158, 13, 21, 96 } /* y = h */,
1044 { 97, 5, 44, 131, 176, 139, 48, 68, 97 } /* y = d45 */,
1045 { 83, 5, 42, 156, 111, 152, 26, 49, 152 } /* y = d135 */,
1046 { 80, 5, 58, 178, 74, 83, 33, 62, 145 } /* y = d117 */,
1047 { 86, 5, 32, 154, 192, 168, 14, 22, 163 } /* y = d153 */,
1048 { 85, 5, 32, 156, 216, 148, 19, 29, 73 } /* y = d207 */,
1049 { 77, 7, 64, 116, 132, 122, 37, 126, 120 } /* y = d63 */,
1050 { 101, 21, 107, 181, 192, 103, 19, 67, 125 } /* y = tm */
1054 { 199, 122, 141 } /* a/l both not split */,
1055 { 147, 63, 159 } /* a split, l not split */,
1056 { 148, 133, 118 } /* l split, a not split */,
1057 { 121, 104, 114 } /* a/l both split */,
1059 { 174, 73, 87 } /* a/l both not split */,
1060 { 92, 41, 83 } /* a split, l not split */,
1061 { 82, 99, 50 } /* l split, a not split */,
1062 { 53, 39, 39 } /* a/l both split */,
1063 /* 32x32 -> 16x16 */
1064 { 177, 58, 59 } /* a/l both not split */,
1065 { 68, 26, 63 } /* a split, l not split */,
1066 { 52, 79, 25 } /* l split, a not split */,
1067 { 17, 14, 12 } /* a/l both split */,
1068 /* 64x64 -> 32x32 */
1069 { 222, 34, 30 } /* a/l both not split */,
1070 { 72, 16, 44 } /* a split, l not split */,
1071 { 58, 32, 12 } /* l split, a not split */,
1072 { 10, 7, 6 } /* a/l both split */,
1076 .joint
= { 32, 64, 96 },
1077 .sign
= { 128, 128 },
1079 { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 },
1080 { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 },
1082 .class0_bit
= { 216, 208 },
1084 { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240},
1085 { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240},
1101 .class0_hp
= { 160, 160 },
1105 EXPORT_SYMBOL_GPL(v4l2_vp9_default_probs
);
1107 static u32
fastdiv(u32 dividend
, u16 divisor
)
1109 #define DIV_INV(d) ((u32)(((1ULL << 32) + ((d) - 1)) / (d)))
1110 #define DIVS_INV(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9) \
1111 DIV_INV(d0), DIV_INV(d1), DIV_INV(d2), DIV_INV(d3), \
1112 DIV_INV(d4), DIV_INV(d5), DIV_INV(d6), DIV_INV(d7), \
1113 DIV_INV(d8), DIV_INV(d9)
1115 static const u32 inv
[] = {
1116 DIV_INV(2), DIV_INV(3), DIV_INV(4), DIV_INV(5),
1117 DIV_INV(6), DIV_INV(7), DIV_INV(8), DIV_INV(9),
1118 DIVS_INV(10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
1119 DIVS_INV(20, 21, 22, 23, 24, 25, 26, 27, 28, 29),
1120 DIVS_INV(30, 31, 32, 33, 34, 35, 36, 37, 38, 39),
1121 DIVS_INV(40, 41, 42, 43, 44, 45, 46, 47, 48, 49),
1122 DIVS_INV(50, 51, 52, 53, 54, 55, 56, 57, 58, 59),
1123 DIVS_INV(60, 61, 62, 63, 64, 65, 66, 67, 68, 69),
1124 DIVS_INV(70, 71, 72, 73, 74, 75, 76, 77, 78, 79),
1125 DIVS_INV(80, 81, 82, 83, 84, 85, 86, 87, 88, 89),
1126 DIVS_INV(90, 91, 92, 93, 94, 95, 96, 97, 98, 99),
1127 DIVS_INV(100, 101, 102, 103, 104, 105, 106, 107, 108, 109),
1128 DIVS_INV(110, 111, 112, 113, 114, 115, 116, 117, 118, 119),
1129 DIVS_INV(120, 121, 122, 123, 124, 125, 126, 127, 128, 129),
1130 DIVS_INV(130, 131, 132, 133, 134, 135, 136, 137, 138, 139),
1131 DIVS_INV(140, 141, 142, 143, 144, 145, 146, 147, 148, 149),
1132 DIVS_INV(150, 151, 152, 153, 154, 155, 156, 157, 158, 159),
1133 DIVS_INV(160, 161, 162, 163, 164, 165, 166, 167, 168, 169),
1134 DIVS_INV(170, 171, 172, 173, 174, 175, 176, 177, 178, 179),
1135 DIVS_INV(180, 181, 182, 183, 184, 185, 186, 187, 188, 189),
1136 DIVS_INV(190, 191, 192, 193, 194, 195, 196, 197, 198, 199),
1137 DIVS_INV(200, 201, 202, 203, 204, 205, 206, 207, 208, 209),
1138 DIVS_INV(210, 211, 212, 213, 214, 215, 216, 217, 218, 219),
1139 DIVS_INV(220, 221, 222, 223, 224, 225, 226, 227, 228, 229),
1140 DIVS_INV(230, 231, 232, 233, 234, 235, 236, 237, 238, 239),
1141 DIVS_INV(240, 241, 242, 243, 244, 245, 246, 247, 248, 249),
1142 DIV_INV(250), DIV_INV(251), DIV_INV(252), DIV_INV(253),
1143 DIV_INV(254), DIV_INV(255), DIV_INV(256),
1148 else if (divisor
== 1)
1151 if (WARN_ON(divisor
- 2 >= ARRAY_SIZE(inv
)))
1154 return ((u64
)dividend
* inv
[divisor
- 2]) >> 32;
1157 /* 6.3.6 inv_recenter_nonneg(v, m) */
1158 static int inv_recenter_nonneg(int v
, int m
)
1164 return m
- ((v
+ 1) >> 1);
1166 return m
+ (v
>> 1);
1170 * part of 6.3.5 inv_remap_prob(deltaProb, prob)
1171 * delta = inv_map_table[deltaProb] done by userspace
1173 static int update_prob(int delta
, int prob
)
1178 return prob
<= 128 ?
1179 1 + inv_recenter_nonneg(delta
, prob
- 1) :
1180 255 - inv_recenter_nonneg(delta
, 255 - prob
);
1183 /* Counterpart to 6.3.2 tx_mode_probs() */
1184 static void update_tx_probs(struct v4l2_vp9_frame_context
*probs
,
1185 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1189 for (i
= 0; i
< ARRAY_SIZE(probs
->tx8
); i
++) {
1190 u8
*p8x8
= probs
->tx8
[i
];
1191 u8
*p16x16
= probs
->tx16
[i
];
1192 u8
*p32x32
= probs
->tx32
[i
];
1193 const u8
*d8x8
= deltas
->tx8
[i
];
1194 const u8
*d16x16
= deltas
->tx16
[i
];
1195 const u8
*d32x32
= deltas
->tx32
[i
];
1197 p8x8
[0] = update_prob(d8x8
[0], p8x8
[0]);
1198 p16x16
[0] = update_prob(d16x16
[0], p16x16
[0]);
1199 p16x16
[1] = update_prob(d16x16
[1], p16x16
[1]);
1200 p32x32
[0] = update_prob(d32x32
[0], p32x32
[0]);
1201 p32x32
[1] = update_prob(d32x32
[1], p32x32
[1]);
1202 p32x32
[2] = update_prob(d32x32
[2], p32x32
[2]);
1206 #define BAND_6(band) ((band) == 0 ? 3 : 6)
1208 static void update_coeff(const u8 deltas
[6][6][3], u8 probs
[6][6][3])
1212 for (l
= 0; l
< 6; l
++)
1213 for (m
= 0; m
< BAND_6(l
); m
++) {
1214 u8
*p
= probs
[l
][m
];
1215 const u8
*d
= deltas
[l
][m
];
1217 for (n
= 0; n
< 3; n
++)
1218 p
[n
] = update_prob(d
[n
], p
[n
]);
1222 /* Counterpart to 6.3.7 read_coef_probs() */
1223 static void update_coef_probs(struct v4l2_vp9_frame_context
*probs
,
1224 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
,
1225 const struct v4l2_ctrl_vp9_frame
*dec_params
)
1229 for (i
= 0; i
< ARRAY_SIZE(probs
->coef
); i
++) {
1230 for (j
= 0; j
< ARRAY_SIZE(probs
->coef
[0]); j
++)
1231 for (k
= 0; k
< ARRAY_SIZE(probs
->coef
[0][0]); k
++)
1232 update_coeff(deltas
->coef
[i
][j
][k
], probs
->coef
[i
][j
][k
]);
1234 if (deltas
->tx_mode
== i
)
1239 /* Counterpart to 6.3.8 read_skip_prob() */
1240 static void update_skip_probs(struct v4l2_vp9_frame_context
*probs
,
1241 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1245 for (i
= 0; i
< ARRAY_SIZE(probs
->skip
); i
++)
1246 probs
->skip
[i
] = update_prob(deltas
->skip
[i
], probs
->skip
[i
]);
1249 /* Counterpart to 6.3.9 read_inter_mode_probs() */
1250 static void update_inter_mode_probs(struct v4l2_vp9_frame_context
*probs
,
1251 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1255 for (i
= 0; i
< ARRAY_SIZE(probs
->inter_mode
); i
++) {
1256 u8
*p
= probs
->inter_mode
[i
];
1257 const u8
*d
= deltas
->inter_mode
[i
];
1259 p
[0] = update_prob(d
[0], p
[0]);
1260 p
[1] = update_prob(d
[1], p
[1]);
1261 p
[2] = update_prob(d
[2], p
[2]);
1265 /* Counterpart to 6.3.10 read_interp_filter_probs() */
1266 static void update_interp_filter_probs(struct v4l2_vp9_frame_context
*probs
,
1267 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1271 for (i
= 0; i
< ARRAY_SIZE(probs
->interp_filter
); i
++) {
1272 u8
*p
= probs
->interp_filter
[i
];
1273 const u8
*d
= deltas
->interp_filter
[i
];
1275 p
[0] = update_prob(d
[0], p
[0]);
1276 p
[1] = update_prob(d
[1], p
[1]);
1280 /* Counterpart to 6.3.11 read_is_inter_probs() */
1281 static void update_is_inter_probs(struct v4l2_vp9_frame_context
*probs
,
1282 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1286 for (i
= 0; i
< ARRAY_SIZE(probs
->is_inter
); i
++)
1287 probs
->is_inter
[i
] = update_prob(deltas
->is_inter
[i
], probs
->is_inter
[i
]);
1290 /* 6.3.12 frame_reference_mode() done entirely in userspace */
1292 /* Counterpart to 6.3.13 frame_reference_mode_probs() */
1294 update_frame_reference_mode_probs(unsigned int reference_mode
,
1295 struct v4l2_vp9_frame_context
*probs
,
1296 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1300 if (reference_mode
== V4L2_VP9_REFERENCE_MODE_SELECT
)
1301 for (i
= 0; i
< ARRAY_SIZE(probs
->comp_mode
); i
++)
1302 probs
->comp_mode
[i
] = update_prob(deltas
->comp_mode
[i
],
1303 probs
->comp_mode
[i
]);
1305 if (reference_mode
!= V4L2_VP9_REFERENCE_MODE_COMPOUND_REFERENCE
)
1306 for (i
= 0; i
< ARRAY_SIZE(probs
->single_ref
); i
++) {
1307 u8
*p
= probs
->single_ref
[i
];
1308 const u8
*d
= deltas
->single_ref
[i
];
1310 p
[0] = update_prob(d
[0], p
[0]);
1311 p
[1] = update_prob(d
[1], p
[1]);
1314 if (reference_mode
!= V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE
)
1315 for (i
= 0; i
< ARRAY_SIZE(probs
->comp_ref
); i
++)
1316 probs
->comp_ref
[i
] = update_prob(deltas
->comp_ref
[i
], probs
->comp_ref
[i
]);
1319 /* Counterpart to 6.3.14 read_y_mode_probs() */
1320 static void update_y_mode_probs(struct v4l2_vp9_frame_context
*probs
,
1321 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1325 for (i
= 0; i
< ARRAY_SIZE(probs
->y_mode
); i
++)
1326 for (j
= 0; j
< ARRAY_SIZE(probs
->y_mode
[0]); ++j
)
1327 probs
->y_mode
[i
][j
] =
1328 update_prob(deltas
->y_mode
[i
][j
], probs
->y_mode
[i
][j
]);
1331 /* Counterpart to 6.3.15 read_partition_probs() */
1332 static void update_partition_probs(struct v4l2_vp9_frame_context
*probs
,
1333 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
)
1337 for (i
= 0; i
< 4; i
++)
1338 for (j
= 0; j
< 4; j
++) {
1339 u8
*p
= probs
->partition
[i
* 4 + j
];
1340 const u8
*d
= deltas
->partition
[i
* 4 + j
];
1342 p
[0] = update_prob(d
[0], p
[0]);
1343 p
[1] = update_prob(d
[1], p
[1]);
1344 p
[2] = update_prob(d
[2], p
[2]);
1348 static inline int update_mv_prob(int delta
, int prob
)
1356 /* Counterpart to 6.3.16 mv_probs() */
1357 static void update_mv_probs(struct v4l2_vp9_frame_context
*probs
,
1358 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
,
1359 const struct v4l2_ctrl_vp9_frame
*dec_params
)
1361 u8
*p
= probs
->mv
.joint
;
1362 const u8
*d
= deltas
->mv
.joint
;
1365 p
[0] = update_mv_prob(d
[0], p
[0]);
1366 p
[1] = update_mv_prob(d
[1], p
[1]);
1367 p
[2] = update_mv_prob(d
[2], p
[2]);
1369 for (i
= 0; i
< ARRAY_SIZE(probs
->mv
.sign
); i
++) {
1371 d
= deltas
->mv
.sign
;
1372 p
[i
] = update_mv_prob(d
[i
], p
[i
]);
1374 p
= probs
->mv
.classes
[i
];
1375 d
= deltas
->mv
.classes
[i
];
1376 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.classes
[0]); j
++)
1377 p
[j
] = update_mv_prob(d
[j
], p
[j
]);
1379 p
= probs
->mv
.class0_bit
;
1380 d
= deltas
->mv
.class0_bit
;
1381 p
[i
] = update_mv_prob(d
[i
], p
[i
]);
1383 p
= probs
->mv
.bits
[i
];
1384 d
= deltas
->mv
.bits
[i
];
1385 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.bits
[0]); j
++)
1386 p
[j
] = update_mv_prob(d
[j
], p
[j
]);
1388 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.class0_fr
[0]); j
++) {
1389 p
= probs
->mv
.class0_fr
[i
][j
];
1390 d
= deltas
->mv
.class0_fr
[i
][j
];
1392 p
[0] = update_mv_prob(d
[0], p
[0]);
1393 p
[1] = update_mv_prob(d
[1], p
[1]);
1394 p
[2] = update_mv_prob(d
[2], p
[2]);
1397 p
= probs
->mv
.fr
[i
];
1398 d
= deltas
->mv
.fr
[i
];
1399 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.fr
[i
]); j
++)
1400 p
[j
] = update_mv_prob(d
[j
], p
[j
]);
1402 if (dec_params
->flags
& V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV
) {
1403 p
= probs
->mv
.class0_hp
;
1404 d
= deltas
->mv
.class0_hp
;
1405 p
[i
] = update_mv_prob(d
[i
], p
[i
]);
1409 p
[i
] = update_mv_prob(d
[i
], p
[i
]);
1414 /* Counterpart to 6.3 compressed_header(), but parsing has been done in userspace. */
1415 void v4l2_vp9_fw_update_probs(struct v4l2_vp9_frame_context
*probs
,
1416 const struct v4l2_ctrl_vp9_compressed_hdr
*deltas
,
1417 const struct v4l2_ctrl_vp9_frame
*dec_params
)
1419 if (deltas
->tx_mode
== V4L2_VP9_TX_MODE_SELECT
)
1420 update_tx_probs(probs
, deltas
);
1422 update_coef_probs(probs
, deltas
, dec_params
);
1424 update_skip_probs(probs
, deltas
);
1426 if (dec_params
->flags
& V4L2_VP9_FRAME_FLAG_KEY_FRAME
||
1427 dec_params
->flags
& V4L2_VP9_FRAME_FLAG_INTRA_ONLY
)
1430 update_inter_mode_probs(probs
, deltas
);
1432 if (dec_params
->interpolation_filter
== V4L2_VP9_INTERP_FILTER_SWITCHABLE
)
1433 update_interp_filter_probs(probs
, deltas
);
1435 update_is_inter_probs(probs
, deltas
);
1437 update_frame_reference_mode_probs(dec_params
->reference_mode
, probs
, deltas
);
1439 update_y_mode_probs(probs
, deltas
);
1441 update_partition_probs(probs
, deltas
);
1443 update_mv_probs(probs
, deltas
, dec_params
);
1445 EXPORT_SYMBOL_GPL(v4l2_vp9_fw_update_probs
);
1447 u8
v4l2_vp9_reset_frame_ctx(const struct v4l2_ctrl_vp9_frame
*dec_params
,
1448 struct v4l2_vp9_frame_context
*frame_context
)
1452 u8 fctx_idx
= dec_params
->frame_context_idx
;
1454 if (dec_params
->flags
& V4L2_VP9_FRAME_FLAG_KEY_FRAME
||
1455 dec_params
->flags
& V4L2_VP9_FRAME_FLAG_INTRA_ONLY
||
1456 dec_params
->flags
& V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT
) {
1458 * setup_past_independence()
1459 * We do nothing here. Instead of storing default probs in some intermediate
1460 * location and then copying from that location to appropriate contexts
1461 * in save_probs() below, we skip that step and save default probs directly
1462 * to appropriate contexts.
1464 if (dec_params
->flags
& V4L2_VP9_FRAME_FLAG_KEY_FRAME
||
1465 dec_params
->flags
& V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT
||
1466 dec_params
->reset_frame_context
== V4L2_VP9_RESET_FRAME_CTX_ALL
)
1467 for (i
= 0; i
< 4; ++i
)
1469 memcpy(&frame_context
[i
], &v4l2_vp9_default_probs
,
1470 sizeof(v4l2_vp9_default_probs
));
1471 else if (dec_params
->reset_frame_context
== V4L2_VP9_RESET_FRAME_CTX_SPEC
)
1472 /* save_probs(fctx_idx) */
1473 memcpy(&frame_context
[fctx_idx
], &v4l2_vp9_default_probs
,
1474 sizeof(v4l2_vp9_default_probs
));
1480 EXPORT_SYMBOL_GPL(v4l2_vp9_reset_frame_ctx
);
1482 /* 8.4.1 Merge prob process */
1483 static u8
merge_prob(u8 pre_prob
, u32 ct0
, u32 ct1
, u16 count_sat
, u32 max_update_factor
)
1485 u32 den
, prob
, count
, factor
;
1490 * prob = 128, count = 0, update_factor = 0
1491 * Round2's argument: pre_prob * 256
1492 * (pre_prob * 256 + 128) >> 8 == pre_prob
1497 prob
= clamp(((ct0
<< 8) + (den
>> 1)) / den
, (u32
)1, (u32
)255);
1498 count
= min_t(u32
, den
, count_sat
);
1499 factor
= fastdiv(max_update_factor
* count
, count_sat
);
1502 * Round2(pre_prob * (256 - factor) + prob * factor, 8)
1503 * Round2(pre_prob * 256 + (prob - pre_prob) * factor, 8)
1504 * (pre_prob * 256 >> 8) + (((prob - pre_prob) * factor + 128) >> 8)
1506 return pre_prob
+ (((prob
- pre_prob
) * factor
+ 128) >> 8);
1509 static inline u8
noncoef_merge_prob(u8 pre_prob
, u32 ct0
, u32 ct1
)
1511 return merge_prob(pre_prob
, ct0
, ct1
, 20, 128);
1514 /* 8.4.2 Merge probs process */
1516 * merge_probs() is a recursive function in the spec. We avoid recursion in the kernel.
1517 * That said, the "tree" parameter of merge_probs() controls how deep the recursion goes.
1518 * It turns out that in all cases the recursive calls boil down to a short-ish series
1519 * of merge_prob() invocations (note no "s").
1523 * merge_probs(small_token_tree, 2):
1524 * merge_prob(p[1], c[0], c[1] + c[2])
1525 * merge_prob(p[2], c[1], c[2])
1529 * merge_probs(binary_tree, 0) or
1530 * merge_probs(tx_size_8_tree, 0):
1531 * merge_prob(p[0], c[0], c[1])
1535 * merge_probs(inter_mode_tree, 0):
1536 * merge_prob(p[0], c[2], c[1] + c[0] + c[3])
1537 * merge_prob(p[1], c[0], c[1] + c[3])
1538 * merge_prob(p[2], c[1], c[3])
1542 * merge_probs(intra_mode_tree, 0):
1543 * merge_prob(p[0], c[0], c[1] + ... + c[9])
1544 * merge_prob(p[1], c[9], c[1] + ... + c[8])
1545 * merge_prob(p[2], c[1], c[2] + ... + c[8])
1546 * merge_prob(p[3], c[2] + c[4] + c[5], c[3] + c[8] + c[6] + c[7])
1547 * merge_prob(p[4], c[2], c[4] + c[5])
1548 * merge_prob(p[5], c[4], c[5])
1549 * merge_prob(p[6], c[3], c[8] + c[6] + c[7])
1550 * merge_prob(p[7], c[8], c[6] + c[7])
1551 * merge_prob(p[8], c[6], c[7])
1555 * merge_probs(partition_tree, 0) or
1556 * merge_probs(tx_size_32_tree, 0) or
1557 * merge_probs(mv_joint_tree, 0) or
1558 * merge_probs(mv_fr_tree, 0):
1559 * merge_prob(p[0], c[0], c[1] + c[2] + c[3])
1560 * merge_prob(p[1], c[1], c[2] + c[3])
1561 * merge_prob(p[2], c[2], c[3])
1565 * merge_probs(interp_filter_tree, 0) or
1566 * merge_probs(tx_size_16_tree, 0):
1567 * merge_prob(p[0], c[0], c[1] + c[2])
1568 * merge_prob(p[1], c[1], c[2])
1572 * merge_probs(mv_class_tree, 0):
1573 * merge_prob(p[0], c[0], c[1] + ... + c[10])
1574 * merge_prob(p[1], c[1], c[2] + ... + c[10])
1575 * merge_prob(p[2], c[2] + c[3], c[4] + ... + c[10])
1576 * merge_prob(p[3], c[2], c[3])
1577 * merge_prob(p[4], c[4] + c[5], c[6] + ... + c[10])
1578 * merge_prob(p[5], c[4], c[5])
1579 * merge_prob(p[6], c[6], c[7] + ... + c[10])
1580 * merge_prob(p[7], c[7] + c[8], c[9] + c[10])
1581 * merge_prob(p[8], c[7], c[8])
1582 * merge_prob(p[9], c[9], [10])
1585 static inline void merge_probs_variant_a(u8
*p
, const u32
*c
, u16 count_sat
, u32 update_factor
)
1587 p
[1] = merge_prob(p
[1], c
[0], c
[1] + c
[2], count_sat
, update_factor
);
1588 p
[2] = merge_prob(p
[2], c
[1], c
[2], count_sat
, update_factor
);
1591 static inline void merge_probs_variant_b(u8
*p
, const u32
*c
, u16 count_sat
, u32 update_factor
)
1593 p
[0] = merge_prob(p
[0], c
[0], c
[1], count_sat
, update_factor
);
1596 static inline void merge_probs_variant_c(u8
*p
, const u32
*c
)
1598 p
[0] = noncoef_merge_prob(p
[0], c
[2], c
[1] + c
[0] + c
[3]);
1599 p
[1] = noncoef_merge_prob(p
[1], c
[0], c
[1] + c
[3]);
1600 p
[2] = noncoef_merge_prob(p
[2], c
[1], c
[3]);
1603 static void merge_probs_variant_d(u8
*p
, const u32
*c
)
1607 sum
= c
[1] + c
[2] + c
[3] + c
[4] + c
[5] + c
[6] + c
[7] + c
[8] + c
[9];
1609 p
[0] = noncoef_merge_prob(p
[0], c
[0], sum
);
1611 p
[1] = noncoef_merge_prob(p
[1], c
[9], sum
);
1613 p
[2] = noncoef_merge_prob(p
[2], c
[1], sum
);
1614 s2
= c
[2] + c
[4] + c
[5];
1616 p
[3] = noncoef_merge_prob(p
[3], s2
, sum
);
1618 p
[4] = noncoef_merge_prob(p
[4], c
[2], s2
);
1619 p
[5] = noncoef_merge_prob(p
[5], c
[4], c
[5]);
1621 p
[6] = noncoef_merge_prob(p
[6], c
[3], sum
);
1623 p
[7] = noncoef_merge_prob(p
[7], c
[8], sum
);
1624 p
[8] = noncoef_merge_prob(p
[8], c
[6], c
[7]);
1627 static inline void merge_probs_variant_e(u8
*p
, const u32
*c
)
1629 p
[0] = noncoef_merge_prob(p
[0], c
[0], c
[1] + c
[2] + c
[3]);
1630 p
[1] = noncoef_merge_prob(p
[1], c
[1], c
[2] + c
[3]);
1631 p
[2] = noncoef_merge_prob(p
[2], c
[2], c
[3]);
1634 static inline void merge_probs_variant_f(u8
*p
, const u32
*c
)
1636 p
[0] = noncoef_merge_prob(p
[0], c
[0], c
[1] + c
[2]);
1637 p
[1] = noncoef_merge_prob(p
[1], c
[1], c
[2]);
1640 static void merge_probs_variant_g(u8
*p
, const u32
*c
)
1644 sum
= c
[1] + c
[2] + c
[3] + c
[4] + c
[5] + c
[6] + c
[7] + c
[8] + c
[9] + c
[10];
1645 p
[0] = noncoef_merge_prob(p
[0], c
[0], sum
);
1647 p
[1] = noncoef_merge_prob(p
[1], c
[1], sum
);
1649 p
[2] = noncoef_merge_prob(p
[2], c
[2] + c
[3], sum
);
1650 p
[3] = noncoef_merge_prob(p
[3], c
[2], c
[3]);
1652 p
[4] = noncoef_merge_prob(p
[4], c
[4] + c
[5], sum
);
1653 p
[5] = noncoef_merge_prob(p
[5], c
[4], c
[5]);
1655 p
[6] = noncoef_merge_prob(p
[6], c
[6], sum
);
1656 p
[7] = noncoef_merge_prob(p
[7], c
[7] + c
[8], c
[9] + c
[10]);
1657 p
[8] = noncoef_merge_prob(p
[8], c
[7], c
[8]);
1658 p
[9] = noncoef_merge_prob(p
[9], c
[9], c
[10]);
1661 /* 8.4.3 Coefficient probability adaptation process */
1662 static inline void adapt_probs_variant_a_coef(u8
*p
, const u32
*c
, u32 update_factor
)
1664 merge_probs_variant_a(p
, c
, 24, update_factor
);
1667 static inline void adapt_probs_variant_b_coef(u8
*p
, const u32
*c
, u32 update_factor
)
1669 merge_probs_variant_b(p
, c
, 24, update_factor
);
1672 static void _adapt_coeff(unsigned int i
, unsigned int j
, unsigned int k
,
1673 struct v4l2_vp9_frame_context
*probs
,
1674 const struct v4l2_vp9_frame_symbol_counts
*counts
,
1679 for (l
= 0; l
< ARRAY_SIZE(probs
->coef
[0][0][0]); l
++) {
1680 for (m
= 0; m
< BAND_6(l
); m
++) {
1681 u8
*p
= probs
->coef
[i
][j
][k
][l
][m
];
1682 const u32 counts_more_coefs
[2] = {
1683 *counts
->eob
[i
][j
][k
][l
][m
][1],
1684 *counts
->eob
[i
][j
][k
][l
][m
][0] - *counts
->eob
[i
][j
][k
][l
][m
][1],
1687 adapt_probs_variant_a_coef(p
, *counts
->coeff
[i
][j
][k
][l
][m
], uf
);
1688 adapt_probs_variant_b_coef(p
, counts_more_coefs
, uf
);
1693 static void _adapt_coef_probs(struct v4l2_vp9_frame_context
*probs
,
1694 const struct v4l2_vp9_frame_symbol_counts
*counts
,
1697 unsigned int i
, j
, k
;
1699 for (i
= 0; i
< ARRAY_SIZE(probs
->coef
); i
++)
1700 for (j
= 0; j
< ARRAY_SIZE(probs
->coef
[0]); j
++)
1701 for (k
= 0; k
< ARRAY_SIZE(probs
->coef
[0][0]); k
++)
1702 _adapt_coeff(i
, j
, k
, probs
, counts
, uf
);
1705 void v4l2_vp9_adapt_coef_probs(struct v4l2_vp9_frame_context
*probs
,
1706 struct v4l2_vp9_frame_symbol_counts
*counts
,
1708 bool frame_is_intra
)
1710 if (frame_is_intra
) {
1711 _adapt_coef_probs(probs
, counts
, 112);
1714 _adapt_coef_probs(probs
, counts
, 128);
1716 _adapt_coef_probs(probs
, counts
, 112);
1719 EXPORT_SYMBOL_GPL(v4l2_vp9_adapt_coef_probs
);
1721 /* 8.4.4 Non coefficient probability adaptation process, adapt_probs() */
1722 static inline void adapt_probs_variant_b(u8
*p
, const u32
*c
)
1724 merge_probs_variant_b(p
, c
, 20, 128);
1727 static inline void adapt_probs_variant_c(u8
*p
, const u32
*c
)
1729 merge_probs_variant_c(p
, c
);
1732 static inline void adapt_probs_variant_d(u8
*p
, const u32
*c
)
1734 merge_probs_variant_d(p
, c
);
1737 static inline void adapt_probs_variant_e(u8
*p
, const u32
*c
)
1739 merge_probs_variant_e(p
, c
);
1742 static inline void adapt_probs_variant_f(u8
*p
, const u32
*c
)
1744 merge_probs_variant_f(p
, c
);
1747 static inline void adapt_probs_variant_g(u8
*p
, const u32
*c
)
1749 merge_probs_variant_g(p
, c
);
1752 /* 8.4.4 Non coefficient probability adaptation process, adapt_prob() */
1753 static inline u8
adapt_prob(u8 prob
, const u32 counts
[2])
1755 return noncoef_merge_prob(prob
, counts
[0], counts
[1]);
1758 /* 8.4.4 Non coefficient probability adaptation process */
1759 void v4l2_vp9_adapt_noncoef_probs(struct v4l2_vp9_frame_context
*probs
,
1760 struct v4l2_vp9_frame_symbol_counts
*counts
,
1761 u8 reference_mode
, u8 interpolation_filter
, u8 tx_mode
,
1766 for (i
= 0; i
< ARRAY_SIZE(probs
->is_inter
); i
++)
1767 probs
->is_inter
[i
] = adapt_prob(probs
->is_inter
[i
], (*counts
->intra_inter
)[i
]);
1769 for (i
= 0; i
< ARRAY_SIZE(probs
->comp_mode
); i
++)
1770 probs
->comp_mode
[i
] = adapt_prob(probs
->comp_mode
[i
], (*counts
->comp
)[i
]);
1772 for (i
= 0; i
< ARRAY_SIZE(probs
->comp_ref
); i
++)
1773 probs
->comp_ref
[i
] = adapt_prob(probs
->comp_ref
[i
], (*counts
->comp_ref
)[i
]);
1775 if (reference_mode
!= V4L2_VP9_REFERENCE_MODE_COMPOUND_REFERENCE
)
1776 for (i
= 0; i
< ARRAY_SIZE(probs
->single_ref
); i
++)
1777 for (j
= 0; j
< ARRAY_SIZE(probs
->single_ref
[0]); j
++)
1778 probs
->single_ref
[i
][j
] = adapt_prob(probs
->single_ref
[i
][j
],
1779 (*counts
->single_ref
)[i
][j
]);
1781 for (i
= 0; i
< ARRAY_SIZE(probs
->inter_mode
); i
++)
1782 adapt_probs_variant_c(probs
->inter_mode
[i
], (*counts
->mv_mode
)[i
]);
1784 for (i
= 0; i
< ARRAY_SIZE(probs
->y_mode
); i
++)
1785 adapt_probs_variant_d(probs
->y_mode
[i
], (*counts
->y_mode
)[i
]);
1787 for (i
= 0; i
< ARRAY_SIZE(probs
->uv_mode
); i
++)
1788 adapt_probs_variant_d(probs
->uv_mode
[i
], (*counts
->uv_mode
)[i
]);
1790 for (i
= 0; i
< ARRAY_SIZE(probs
->partition
); i
++)
1791 adapt_probs_variant_e(probs
->partition
[i
], (*counts
->partition
)[i
]);
1793 for (i
= 0; i
< ARRAY_SIZE(probs
->skip
); i
++)
1794 probs
->skip
[i
] = adapt_prob(probs
->skip
[i
], (*counts
->skip
)[i
]);
1796 if (interpolation_filter
== V4L2_VP9_INTERP_FILTER_SWITCHABLE
)
1797 for (i
= 0; i
< ARRAY_SIZE(probs
->interp_filter
); i
++)
1798 adapt_probs_variant_f(probs
->interp_filter
[i
], (*counts
->filter
)[i
]);
1800 if (tx_mode
== V4L2_VP9_TX_MODE_SELECT
)
1801 for (i
= 0; i
< ARRAY_SIZE(probs
->tx8
); i
++) {
1802 adapt_probs_variant_b(probs
->tx8
[i
], (*counts
->tx8p
)[i
]);
1803 adapt_probs_variant_f(probs
->tx16
[i
], (*counts
->tx16p
)[i
]);
1804 adapt_probs_variant_e(probs
->tx32
[i
], (*counts
->tx32p
)[i
]);
1807 adapt_probs_variant_e(probs
->mv
.joint
, *counts
->mv_joint
);
1809 for (i
= 0; i
< ARRAY_SIZE(probs
->mv
.sign
); i
++) {
1810 probs
->mv
.sign
[i
] = adapt_prob(probs
->mv
.sign
[i
], (*counts
->sign
)[i
]);
1812 adapt_probs_variant_g(probs
->mv
.classes
[i
], (*counts
->classes
)[i
]);
1814 probs
->mv
.class0_bit
[i
] = adapt_prob(probs
->mv
.class0_bit
[i
], (*counts
->class0
)[i
]);
1816 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.bits
[0]); j
++)
1817 probs
->mv
.bits
[i
][j
] = adapt_prob(probs
->mv
.bits
[i
][j
],
1818 (*counts
->bits
)[i
][j
]);
1820 for (j
= 0; j
< ARRAY_SIZE(probs
->mv
.class0_fr
[0]); j
++)
1821 adapt_probs_variant_e(probs
->mv
.class0_fr
[i
][j
],
1822 (*counts
->class0_fp
)[i
][j
]);
1824 adapt_probs_variant_e(probs
->mv
.fr
[i
], (*counts
->fp
)[i
]);
1826 if (!(flags
& V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV
))
1829 probs
->mv
.class0_hp
[i
] = adapt_prob(probs
->mv
.class0_hp
[i
],
1830 (*counts
->class0_hp
)[i
]);
1832 probs
->mv
.hp
[i
] = adapt_prob(probs
->mv
.hp
[i
], (*counts
->hp
)[i
]);
1835 EXPORT_SYMBOL_GPL(v4l2_vp9_adapt_noncoef_probs
);
1838 v4l2_vp9_seg_feat_enabled(const u8
*feature_enabled
,
1839 unsigned int feature
,
1842 u8 mask
= V4L2_VP9_SEGMENT_FEATURE_ENABLED(feature
);
1844 return !!(feature_enabled
[segid
] & mask
);
1846 EXPORT_SYMBOL_GPL(v4l2_vp9_seg_feat_enabled
);
1848 MODULE_LICENSE("GPL");
1849 MODULE_DESCRIPTION("V4L2 VP9 Helpers");
1850 MODULE_AUTHOR("Andrzej Pietrasiewicz <andrzej.p@collabora.com>");