1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... cabac decoding
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG4 part10 cabac decoding.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #define CABAC(h) 1
29 #define UNCHECKED_BITSTREAM_READER 1
30
31 #include "libavutil/attributes.h"
32 #include "libavutil/avassert.h"
33 #include "libavutil/timer.h"
34
35 #include "config.h"
36
37 #include "cabac.h"
38 #include "cabac_functions.h"
39
40 #include "internal.h"
41
42 #include "avcodec.h"
43 #include "h264.h"
44 #include "h264data.h"
45 #include "h264_mvpred.h"
46 #include "golomb.h"
47 #include "mpegutils.h"
48
49 #if ARCH_X86
50 #include "x86/h264_i386.h"
51 #endif
52
53 /* Cabac pre state table */
54
55 static const int8_t cabac_context_init_I[1024][2] =
56 {
57 /* 0 - 10 */
58 { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
59 { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 },
60 { -6, 53 }, { -1, 54 }, { 7, 51 },
61
62 /* 11 - 23 unsused for I */
63 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
64 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
65 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
66 { 0, 0 },
67
68 /* 24- 39 */
69 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
70 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
71 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
72 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
73
74 /* 40 - 53 */
75 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
76 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
77 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
78 { 0, 0 }, { 0, 0 },
79
80 /* 54 - 59 */
81 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
82 { 0, 0 }, { 0, 0 },
83
84 /* 60 - 69 */
85 { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
86 { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
87 { 13, 41 }, { 3, 62 },
88
89 /* 70 -> 87 */
90 { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 },
91 { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 },
92 { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 },
93 { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 },
94 { -12, 115 },{ -16, 122 },
95
96 /* 88 -> 104 */
97 { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 },
98 { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 },
99 { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 },
100 { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 },
101 { -22, 125 },
102
103 /* 105 -> 135 */
104 { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
105 { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
106 { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
107 { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
108 { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
109 { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
110 { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
111 { 14, 62 }, { -13, 108 },{ -15, 100 },
112
113 /* 136 -> 165 */
114 { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 },
115 { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 },
116 { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 },
117 { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 },
118 { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 },
119 { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 },
120 { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 },
121 { 0, 62 }, { 12, 72 },
122
123 /* 166 -> 196 */
124 { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
125 { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
126 { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
127 { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
128 { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
129 { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
130 { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
131 { 0, 89 }, { 26, -19 }, { 22, -17 },
132
133 /* 197 -> 226 */
134 { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 },
135 { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 },
136 { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 },
137 { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 },
138 { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 },
139 { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 },
140 { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 },
141 { 12, 68 }, { 2, 97 },
142
143 /* 227 -> 251 */
144 { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
145 { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
146 { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
147 { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
148 { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
149 { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
150 { -4, 65 },
151
152 /* 252 -> 275 */
153 { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 },
154 { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 },
155 { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 },
156 { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 },
157 { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 },
158 { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 },
159
160 /* 276 a bit special (not used, bypass is used instead) */
161 { 0, 0 },
162
163 /* 277 -> 307 */
164 { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
165 { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
166 { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
167 { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
168 { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
169 { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
170 { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
171 { 9, 64 }, { -12, 104 },{ -11, 97 },
172
173 /* 308 -> 337 */
174 { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 },
175 { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 },
176 { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 },
177 { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 },
178 { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 },
179 { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 },
180 { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 },
181 { 5, 64 }, { 12, 70 },
182
183 /* 338 -> 368 */
184 { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
185 { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
186 { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
187 { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
188 { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
189 { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
190 { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
191 { -12, 109 },{ 36, -35 }, { 36, -34 },
192
193 /* 369 -> 398 */
194 { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 },
195 { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 },
196 { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 },
197 { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 },
198 { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 },
199 { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 },
200 { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 },
201 { 29, 39 }, { 19, 66 },
202
203 /* 399 -> 435 */
204 { 31, 21 }, { 31, 31 }, { 25, 50 },
205 { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 },
206 { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 },
207 { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 },
208 { -23, 68 }, { -24, 50 }, { -11, 74 }, { 23, -13 },
209 { 26, -13 }, { 40, -15 }, { 49, -14 }, { 44, 3 },
210 { 45, 6 }, { 44, 34 }, { 33, 54 }, { 19, 82 },
211 { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 },
212 { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 },
213 { 0, 68 }, { -9, 92 },
214
215 /* 436 -> 459 */
216 { -14, 106 }, { -13, 97 }, { -15, 90 }, { -12, 90 },
217 { -18, 88 }, { -10, 73 }, { -9, 79 }, { -14, 86 },
218 { -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 },
219 { -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 },
220 { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 },
221 { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 },
222
223 /* 460 -> 1024 */
224 { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
225 { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 },
226 { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
227 { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
228 { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 },
229 { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
230 { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
231 { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
232 { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
233 { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
234 { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
235 { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
236 { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
237 { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
238 { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 },
239 { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 },
240 { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 },
241 { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
242 { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
243 { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
244 { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
245 { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
246 { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
247 { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
248 { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
249 { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 },
250 { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 },
251 { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 },
252 { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
253 { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
254 { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
255 { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
256 { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
257 { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
258 { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
259 { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 },
260 { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 },
261 { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 },
262 { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 },
263 { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
264 { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
265 { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
266 { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
267 { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
268 { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
269 { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
270 { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 },
271 { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 },
272 { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 },
273 { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 },
274 { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 },
275 { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 },
276 { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 },
277 { -23, 68 }, { -24, 50 }, { -11, 74 }, { -14, 106 },
278 { -13, 97 }, { -15, 90 }, { -12, 90 }, { -18, 88 },
279 { -10, 73 }, { -9, 79 }, { -14, 86 }, { -10, 73 },
280 { -10, 70 }, { -10, 69 }, { -5, 66 }, { -9, 64 },
281 { -5, 58 }, { 2, 59 }, { 23, -13 }, { 26, -13 },
282 { 40, -15 }, { 49, -14 }, { 44, 3 }, { 45, 6 },
283 { 44, 34 }, { 33, 54 }, { 19, 82 }, { 21, -10 },
284 { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 },
285 { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 },
286 { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 },
287 { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 },
288 { 0, 68 }, { -9, 92 }, { -17, 120 }, { -20, 112 },
289 { -18, 114 }, { -11, 85 }, { -15, 92 }, { -14, 89 },
290 { -26, 71 }, { -15, 81 }, { -14, 80 }, { 0, 68 },
291 { -14, 70 }, { -24, 56 }, { -23, 68 }, { -24, 50 },
292 { -11, 74 }, { -14, 106 }, { -13, 97 }, { -15, 90 },
293 { -12, 90 }, { -18, 88 }, { -10, 73 }, { -9, 79 },
294 { -14, 86 }, { -10, 73 }, { -10, 70 }, { -10, 69 },
295 { -5, 66 }, { -9, 64 }, { -5, 58 }, { 2, 59 },
296 { 23, -13 }, { 26, -13 }, { 40, -15 }, { 49, -14 },
297 { 44, 3 }, { 45, 6 }, { 44, 34 }, { 33, 54 },
298 { 19, 82 }, { 21, -10 }, { 24, -11 }, { 28, -8 },
299 { 28, -1 }, { 29, 3 }, { 29, 9 }, { 35, 20 },
300 { 29, 36 }, { 14, 67 }, { -3, 75 }, { -1, 23 },
301 { 1, 34 }, { 1, 43 }, { 0, 54 }, { -2, 55 },
302 { 0, 61 }, { 1, 64 }, { 0, 68 }, { -9, 92 },
303 { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
304 { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
305 { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
306 { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
307 { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
308 { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
309 { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
310 { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 },
311 { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 },
312 { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 },
313 { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 },
314 { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
315 { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
316 { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
317 { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
318 { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
319 { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
320 { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
321 { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 },
322 { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 },
323 { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 },
324 { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 },
325 { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
326 { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
327 { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
328 { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
329 { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
330 { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
331 { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
332 { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 },
333 { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 },
334 { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 },
335 { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 },
336 { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
337 { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
338 { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
339 { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
340 { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
341 { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
342 { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
343 { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 },
344 { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 },
345 { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 },
346 { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 },
347 { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
348 { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
349 { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
350 { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
351 { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
352 { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
353 { -4, 65 }, { -12, 73 }, { -8, 76 }, { -7, 80 },
354 { -9, 88 }, { -17, 110 }, { -3, 71 }, { -6, 42 },
355 { -5, 50 }, { -3, 54 }, { -2, 62 }, { 0, 58 },
356 { 1, 63 }, { -2, 72 }, { -1, 74 }, { -9, 91 },
357 { -5, 67 }, { -5, 27 }, { -3, 39 }, { -2, 44 },
358 { 0, 46 }, { -16, 64 }, { -8, 68 }, { -10, 78 },
359 { -6, 77 }, { -10, 86 }, { -12, 92 }, { -15, 55 },
360 { -10, 60 }, { -6, 62 }, { -4, 65 }, { -12, 73 },
361 { -8, 76 }, { -7, 80 }, { -9, 88 }, { -17, 110 },
362 { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
363 { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
364 { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }
365 };
366
367 static const int8_t cabac_context_init_PB[3][1024][2] =
368 {
369 /* i_cabac_init_idc == 0 */
370 {
371 /* 0 - 10 */
372 { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
373 { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
374 { -6, 53 }, { -1, 54 }, { 7, 51 },
375
376 /* 11 - 23 */
377 { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 },
378 { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 },
379 { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 },
380 { 17, 50 },
381
382 /* 24 - 39 */
383 { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 },
384 { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 },
385 { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 },
386 { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 },
387
388 /* 40 - 53 */
389 { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 },
390 { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 },
391 { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 },
392 { -3, 81 }, { 0, 88 },
393
394 /* 54 - 59 */
395 { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 },
396 { -7, 72 }, { 1, 58 },
397
398 /* 60 - 69 */
399 { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
400 { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
401 { 13, 41 }, { 3, 62 },
402
403 /* 70 - 87 */
404 { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 },
405 { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 },
406 { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 },
407 { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 },
408 { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 },
409 { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 },
410 { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 },
411 { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 },
412 { 0, 68 }, { -4, 69 }, { -8, 88 },
413
414 /* 105 -> 165 */
415 { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
416 { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
417 { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
418 { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
419 { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
420 { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
421 { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
422 { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
423 { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
424 { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
425 { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
426 { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 },
427 { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 },
428 { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 },
429 { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 },
430 { 9, 69 },
431
432 /* 166 - 226 */
433 { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
434 { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
435 { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
436 { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
437 { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
438 { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
439 { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
440 { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
441 { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
442 { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
443 { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
444 { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 },
445 { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 },
446 { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 },
447 { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 },
448 { -9, 108 },
449
450 /* 227 - 275 */
451 { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
452 { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
453 { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
454 { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
455 { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
456 { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
457 { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
458 { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 },
459 { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 },
460 { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 },
461 { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 },
462 { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 },
463 { -8, 85 },
464
465 /* 276 a bit special (not used, bypass is used instead) */
466 { 0, 0 },
467
468 /* 277 - 337 */
469 { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
470 { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
471 { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
472 { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
473 { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
474 { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
475 { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
476 { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
477 { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
478 { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
479 { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
480 { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 },
481 { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 },
482 { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 },
483 { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 },
484 { 26, 43 },
485
486 /* 338 - 398 */
487 { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
488 { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
489 { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
490 { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
491 { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
492 { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
493 { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
494 { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
495 { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
496 { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
497 { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
498 { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 },
499 { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 },
500 { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 },
501 { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 },
502 { 11, 86 },
503
504 /* 399 - 435 */
505 { 12, 40 }, { 11, 51 }, { 14, 59 },
506 { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 },
507 { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 },
508 { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 },
509 { -16, 66 }, { -22, 65 }, { -20, 63 }, { 9, -2 },
510 { 26, -9 }, { 33, -9 }, { 39, -7 }, { 41, -2 },
511 { 45, 3 }, { 49, 9 }, { 45, 27 }, { 36, 59 },
512 { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 },
513 { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 },
514 { -8, 66 }, { -8, 76 },
515
516 /* 436 - 459 */
517 { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
518 { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
519 { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
520 { -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 },
521 { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 },
522 { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 },
523
524 /* 460 - 1024 */
525 { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 },
526 { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 },
527 { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
528 { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 },
529 { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 },
530 { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
531 { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
532 { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
533 { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
534 { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
535 { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
536 { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
537 { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
538 { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
539 { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
540 { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
541 { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
542 { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
543 { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
544 { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
545 { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
546 { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
547 { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
548 { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
549 { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
550 { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
551 { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
552 { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
553 { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
554 { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
555 { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
556 { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
557 { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
558 { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
559 { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
560 { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
561 { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
562 { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
563 { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
564 { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
565 { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
566 { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
567 { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
568 { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
569 { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
570 { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
571 { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
572 { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
573 { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
574 { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
575 { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 },
576 { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 },
577 { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 },
578 { -16, 66 }, { -22, 65 }, { -20, 63 }, { -5, 85 },
579 { -6, 81 }, { -10, 77 }, { -7, 81 }, { -17, 80 },
580 { -18, 73 }, { -4, 74 }, { -10, 83 }, { -9, 71 },
581 { -9, 67 }, { -1, 61 }, { -8, 66 }, { -14, 66 },
582 { 0, 59 }, { 2, 59 }, { 9, -2 }, { 26, -9 },
583 { 33, -9 }, { 39, -7 }, { 41, -2 }, { 45, 3 },
584 { 49, 9 }, { 45, 27 }, { 36, 59 }, { 21, -13 },
585 { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 },
586 { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 },
587 { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 },
588 { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 },
589 { -8, 66 }, { -8, 76 }, { -4, 79 }, { -7, 71 },
590 { -5, 69 }, { -9, 70 }, { -8, 66 }, { -10, 68 },
591 { -19, 73 }, { -12, 69 }, { -16, 70 }, { -15, 67 },
592 { -20, 62 }, { -19, 70 }, { -16, 66 }, { -22, 65 },
593 { -20, 63 }, { -5, 85 }, { -6, 81 }, { -10, 77 },
594 { -7, 81 }, { -17, 80 }, { -18, 73 }, { -4, 74 },
595 { -10, 83 }, { -9, 71 }, { -9, 67 }, { -1, 61 },
596 { -8, 66 }, { -14, 66 }, { 0, 59 }, { 2, 59 },
597 { 9, -2 }, { 26, -9 }, { 33, -9 }, { 39, -7 },
598 { 41, -2 }, { 45, 3 }, { 49, 9 }, { 45, 27 },
599 { 36, 59 }, { 21, -13 }, { 33, -14 }, { 39, -7 },
600 { 46, -2 }, { 51, 2 }, { 60, 6 }, { 61, 17 },
601 { 55, 34 }, { 42, 62 }, { -6, 66 }, { -7, 35 },
602 { -7, 42 }, { -8, 45 }, { -5, 48 }, { -12, 56 },
603 { -6, 60 }, { -5, 62 }, { -8, 66 }, { -8, 76 },
604 { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
605 { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
606 { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
607 { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
608 { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
609 { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
610 { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
611 { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
612 { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
613 { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
614 { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
615 { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
616 { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
617 { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
618 { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
619 { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
620 { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
621 { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
622 { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
623 { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
624 { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
625 { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
626 { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
627 { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
628 { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
629 { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
630 { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
631 { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
632 { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
633 { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
634 { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
635 { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
636 { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
637 { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
638 { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
639 { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
640 { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
641 { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
642 { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
643 { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
644 { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
645 { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
646 { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
647 { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
648 { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
649 { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
650 { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
651 { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
652 { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
653 { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
654 { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
655 { -3, 74 }, { -10, 90 }, { -6, 76 }, { -2, 44 },
656 { 0, 45 }, { 0, 52 }, { -3, 64 }, { -2, 59 },
657 { -4, 70 }, { -4, 75 }, { -8, 82 }, { -17, 102 },
658 { -9, 77 }, { 3, 24 }, { 0, 42 }, { 0, 48 },
659 { 0, 55 }, { -6, 59 }, { -7, 71 }, { -12, 83 },
660 { -11, 87 }, { -30, 119 }, { 1, 58 }, { -3, 29 },
661 { -1, 36 }, { 1, 38 }, { 2, 43 }, { -6, 55 },
662 { 0, 58 }, { 0, 64 }, { -3, 74 }, { -10, 90 },
663 { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
664 { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
665 { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }
666 },
667
668 /* i_cabac_init_idc == 1 */
669 {
670 /* 0 - 10 */
671 { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
672 { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
673 { -6, 53 }, { -1, 54 }, { 7, 51 },
674
675 /* 11 - 23 */
676 { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 },
677 { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 },
678 { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 },
679 { 10, 54 },
680
681 /* 24 - 39 */
682 { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 },
683 { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 },
684 { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 },
685 { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 },
686
687 /* 40 - 53 */
688 { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 },
689 { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 },
690 { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 },
691 { -7, 86 },{ -5, 95 },
692
693 /* 54 - 59 */
694 { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 },
695 { -5, 72 },{ 0, 61 },
696
697 /* 60 - 69 */
698 { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
699 { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
700 { 13, 41 }, { 3, 62 },
701
702 /* 70 - 104 */
703 { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 },
704 { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 },
705 { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 },
706 { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 },
707 { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 },
708 { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 },
709 { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 },
710 { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 },
711 { 0, 68 }, { -7, 74 }, { -9, 88 },
712
713 /* 105 -> 165 */
714 { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
715 { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
716 { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
717 { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
718 { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
719 { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
720 { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
721 { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
722 { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
723 { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
724 { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
725 { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 },
726 { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 },
727 { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 },
728 { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 },
729 { 0, 89 },
730
731 /* 166 - 226 */
732 { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
733 { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
734 { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
735 { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
736 { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
737 { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
738 { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
739 { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
740 { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
741 { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
742 { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
743 { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 },
744 { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 },
745 { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 },
746 { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 },
747 { -10, 116 },
748
749 /* 227 - 275 */
750 { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
751 { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
752 { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
753 { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
754 { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
755 { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
756 { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
757 { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 },
758 { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 },
759 { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 },
760 { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 },
761 { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 },
762 { -4, 78 },
763
764 /* 276 a bit special (not used, bypass is used instead) */
765 { 0, 0 },
766
767 /* 277 - 337 */
768 { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
769 { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
770 { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
771 { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
772 { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
773 { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
774 { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
775 { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
776 { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
777 { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
778 { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
779 { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 },
780 { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 },
781 { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 },
782 { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 },
783 { 18, 50 },
784
785 /* 338 - 398 */
786 { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
787 { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
788 { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
789 { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
790 { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
791 { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
792 { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
793 { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
794 { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
795 { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
796 { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
797 { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 },
798 { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 },
799 { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 },
800 { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 },
801 { 11, 83 },
802
803 /* 399 - 435 */
804 { 25, 32 }, { 21, 49 }, { 21, 54 },
805 { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
806 { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
807 { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
808 { -14, 66 }, { 0, 59 }, { 2, 59 }, { 17, -10 },
809 { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
810 { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
811 { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 },
812 { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 },
813 { -4, 67 }, { -7, 82 },
814
815 /* 436 - 459 */
816 { -3, 81 }, { -3, 76 }, { -7, 72 }, { -6, 78 },
817 { -12, 72 }, { -14, 68 }, { -3, 70 }, { -6, 76 },
818 { -5, 66 }, { -5, 62 }, { 0, 57 }, { -4, 61 },
819 { -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 },
820 { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
821 { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
822
823 /* 460 - 1024 */
824 { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 },
825 { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 },
826 { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
827 { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 },
828 { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 },
829 { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
830 { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
831 { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
832 { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
833 { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
834 { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
835 { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
836 { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
837 { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
838 { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
839 { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
840 { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
841 { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
842 { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
843 { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
844 { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
845 { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
846 { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
847 { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
848 { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
849 { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
850 { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
851 { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
852 { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
853 { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
854 { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
855 { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
856 { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
857 { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
858 { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
859 { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
860 { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
861 { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
862 { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
863 { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
864 { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
865 { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
866 { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
867 { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
868 { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
869 { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
870 { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
871 { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
872 { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
873 { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
874 { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
875 { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
876 { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
877 { -14, 66 }, { 0, 59 }, { 2, 59 }, { -3, 81 },
878 { -3, 76 }, { -7, 72 }, { -6, 78 }, { -12, 72 },
879 { -14, 68 }, { -3, 70 }, { -6, 76 }, { -5, 66 },
880 { -5, 62 }, { 0, 57 }, { -4, 61 }, { -9, 60 },
881 { 1, 54 }, { 2, 58 }, { 17, -10 }, { 32, -13 },
882 { 42, -9 }, { 49, -5 }, { 53, 0 }, { 64, 3 },
883 { 68, 10 }, { 66, 27 }, { 47, 57 }, { 17, -10 },
884 { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
885 { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
886 { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 },
887 { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 },
888 { -4, 67 }, { -7, 82 }, { -5, 85 }, { -6, 81 },
889 { -10, 77 }, { -7, 81 }, { -17, 80 }, { -18, 73 },
890 { -4, 74 }, { -10, 83 }, { -9, 71 }, { -9, 67 },
891 { -1, 61 }, { -8, 66 }, { -14, 66 }, { 0, 59 },
892 { 2, 59 }, { -3, 81 }, { -3, 76 }, { -7, 72 },
893 { -6, 78 }, { -12, 72 }, { -14, 68 }, { -3, 70 },
894 { -6, 76 }, { -5, 66 }, { -5, 62 }, { 0, 57 },
895 { -4, 61 }, { -9, 60 }, { 1, 54 }, { 2, 58 },
896 { 17, -10 }, { 32, -13 }, { 42, -9 }, { 49, -5 },
897 { 53, 0 }, { 64, 3 }, { 68, 10 }, { 66, 27 },
898 { 47, 57 }, { 17, -10 }, { 32, -13 }, { 42, -9 },
899 { 49, -5 }, { 53, 0 }, { 64, 3 }, { 68, 10 },
900 { 66, 27 }, { 47, 57 }, { -5, 71 }, { 0, 24 },
901 { -1, 36 }, { -2, 42 }, { -2, 52 }, { -9, 57 },
902 { -6, 63 }, { -4, 65 }, { -4, 67 }, { -7, 82 },
903 { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
904 { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
905 { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
906 { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
907 { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
908 { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
909 { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
910 { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
911 { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
912 { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
913 { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
914 { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
915 { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
916 { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
917 { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
918 { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
919 { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
920 { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
921 { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
922 { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
923 { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
924 { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
925 { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
926 { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
927 { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
928 { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
929 { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
930 { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
931 { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
932 { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
933 { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
934 { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
935 { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
936 { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
937 { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
938 { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
939 { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
940 { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
941 { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
942 { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
943 { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
944 { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
945 { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
946 { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
947 { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
948 { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
949 { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
950 { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
951 { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
952 { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
953 { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
954 { -5, 74 }, { -9, 86 }, { -23, 112 }, { -15, 71 },
955 { -7, 61 }, { 0, 53 }, { -5, 66 }, { -11, 77 },
956 { -9, 80 }, { -9, 84 }, { -10, 87 }, { -34, 127 },
957 { -21, 101 }, { -3, 39 }, { -5, 53 }, { -7, 61 },
958 { -11, 75 }, { -15, 77 }, { -17, 91 }, { -25, 107 },
959 { -25, 111 }, { -28, 122 }, { -11, 76 }, { -10, 44 },
960 { -10, 52 }, { -10, 57 }, { -9, 58 }, { -16, 72 },
961 { -7, 69 }, { -4, 69 }, { -5, 74 }, { -9, 86 },
962 { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
963 { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
964 { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }
965 },
966
967 /* i_cabac_init_idc == 2 */
968 {
969 /* 0 - 10 */
970 { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
971 { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
972 { -6, 53 }, { -1, 54 }, { 7, 51 },
973
974 /* 11 - 23 */
975 { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 },
976 { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 },
977 { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 },
978 { 14, 57 },
979
980 /* 24 - 39 */
981 { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 },
982 { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 },
983 { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 },
984 { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 },
985
986 /* 40 - 53 */
987 { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 },
988 { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 },
989 { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 },
990 { -3, 90 },{ -1, 101 },
991
992 /* 54 - 59 */
993 { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 },
994 { -7, 50 },{ 1, 60 },
995
996 /* 60 - 69 */
997 { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
998 { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
999 { 13, 41 }, { 3, 62 },
1000
1001 /* 70 - 104 */
1002 { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 },
1003 { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 },
1004 { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 },
1005 { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 },
1006 { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 },
1007 { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 },
1008 { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 },
1009 { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 },
1010 { 3, 68 }, { -8, 71 }, { -13, 98 },
1011
1012 /* 105 -> 165 */
1013 { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
1014 { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
1015 { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
1016 { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
1017 { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
1018 { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
1019 { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
1020 { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
1021 { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
1022 { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
1023 { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
1024 { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 },
1025 { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 },
1026 { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 },
1027 { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 },
1028 { -22, 127 },
1029
1030 /* 166 - 226 */
1031 { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
1032 { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
1033 { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
1034 { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
1035 { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
1036 { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
1037 { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
1038 { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
1039 { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
1040 { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
1041 { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
1042 { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 },
1043 { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 },
1044 { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 },
1045 { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 },
1046 { -24, 127 },
1047
1048 /* 227 - 275 */
1049 { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
1050 { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
1051 { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
1052 { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
1053 { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
1054 { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
1055 { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
1056 { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 },
1057 { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 },
1058 { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 },
1059 { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 },
1060 { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 },
1061 { -10, 87 },
1062
1063 /* 276 a bit special (not used, bypass is used instead) */
1064 { 0, 0 },
1065
1066 /* 277 - 337 */
1067 { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
1068 { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
1069 { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
1070 { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
1071 { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
1072 { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
1073 { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
1074 { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
1075 { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
1076 { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
1077 { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
1078 { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 },
1079 { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 },
1080 { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 },
1081 { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 },
1082 { 25, 42 },
1083
1084 /* 338 - 398 */
1085 { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
1086 { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
1087 { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
1088 { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
1089 { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
1090 { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
1091 { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
1092 { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
1093 { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
1094 { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
1095 { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
1096 { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 },
1097 { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 },
1098 { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 },
1099 { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 },
1100 { 25, 61 },
1101
1102 /* 399 - 435 */
1103 { 21, 33 }, { 19, 50 }, { 17, 61 },
1104 { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
1105 { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
1106 { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
1107 { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
1108 { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
1109 { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
1110 { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 },
1111 { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 },
1112 { -6, 68 }, { -10, 79 },
1113
1114 /* 436 - 459 */
1115 { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
1116 { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
1117 { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
1118 { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
1119 { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
1120 { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
1121
1122 /* 460 - 1024 */
1123 { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 },
1124 { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 },
1125 { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
1126 { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 },
1127 { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 },
1128 { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
1129 { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
1130 { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
1131 { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
1132 { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
1133 { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
1134 { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
1135 { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
1136 { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
1137 { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
1138 { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
1139 { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
1140 { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
1141 { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
1142 { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
1143 { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
1144 { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
1145 { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
1146 { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
1147 { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
1148 { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
1149 { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
1150 { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
1151 { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
1152 { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
1153 { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
1154 { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
1155 { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
1156 { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
1157 { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
1158 { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
1159 { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
1160 { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
1161 { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
1162 { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
1163 { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
1164 { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
1165 { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
1166 { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
1167 { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
1168 { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
1169 { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
1170 { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
1171 { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
1172 { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
1173 { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
1174 { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
1175 { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
1176 { -14, 59 }, { -9, 52 }, { -11, 68 }, { -3, 78 },
1177 { -8, 74 }, { -9, 72 }, { -10, 72 }, { -18, 75 },
1178 { -12, 71 }, { -11, 63 }, { -5, 70 }, { -17, 75 },
1179 { -14, 72 }, { -16, 67 }, { -8, 53 }, { -14, 59 },
1180 { -9, 52 }, { -11, 68 }, { 9, -2 }, { 30, -10 },
1181 { 31, -4 }, { 33, -1 }, { 33, 7 }, { 31, 12 },
1182 { 37, 23 }, { 31, 38 }, { 20, 64 }, { 9, -2 },
1183 { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
1184 { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
1185 { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 },
1186 { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 },
1187 { -6, 68 }, { -10, 79 }, { -3, 78 }, { -8, 74 },
1188 { -9, 72 }, { -10, 72 }, { -18, 75 }, { -12, 71 },
1189 { -11, 63 }, { -5, 70 }, { -17, 75 }, { -14, 72 },
1190 { -16, 67 }, { -8, 53 }, { -14, 59 }, { -9, 52 },
1191 { -11, 68 }, { -3, 78 }, { -8, 74 }, { -9, 72 },
1192 { -10, 72 }, { -18, 75 }, { -12, 71 }, { -11, 63 },
1193 { -5, 70 }, { -17, 75 }, { -14, 72 }, { -16, 67 },
1194 { -8, 53 }, { -14, 59 }, { -9, 52 }, { -11, 68 },
1195 { 9, -2 }, { 30, -10 }, { 31, -4 }, { 33, -1 },
1196 { 33, 7 }, { 31, 12 }, { 37, 23 }, { 31, 38 },
1197 { 20, 64 }, { 9, -2 }, { 30, -10 }, { 31, -4 },
1198 { 33, -1 }, { 33, 7 }, { 31, 12 }, { 37, 23 },
1199 { 31, 38 }, { 20, 64 }, { -9, 71 }, { -7, 37 },
1200 { -8, 44 }, { -11, 49 }, { -10, 56 }, { -12, 59 },
1201 { -8, 63 }, { -9, 67 }, { -6, 68 }, { -10, 79 },
1202 { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
1203 { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
1204 { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
1205 { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
1206 { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
1207 { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
1208 { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
1209 { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
1210 { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
1211 { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
1212 { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
1213 { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
1214 { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
1215 { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
1216 { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
1217 { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
1218 { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
1219 { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
1220 { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
1221 { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
1222 { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
1223 { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
1224 { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
1225 { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
1226 { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
1227 { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
1228 { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
1229 { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
1230 { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
1231 { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
1232 { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
1233 { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
1234 { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
1235 { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
1236 { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
1237 { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
1238 { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
1239 { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
1240 { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
1241 { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
1242 { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
1243 { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
1244 { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
1245 { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
1246 { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
1247 { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
1248 { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
1249 { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
1250 { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
1251 { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
1252 { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
1253 { -12, 92 }, { -18, 108 }, { -24, 115 }, { -22, 82 },
1254 { -9, 62 }, { 0, 53 }, { 0, 59 }, { -14, 85 },
1255 { -13, 89 }, { -13, 94 }, { -11, 92 }, { -29, 127 },
1256 { -21, 100 }, { -14, 57 }, { -12, 67 }, { -11, 71 },
1257 { -10, 77 }, { -21, 85 }, { -16, 88 }, { -23, 104 },
1258 { -15, 98 }, { -37, 127 }, { -10, 82 }, { -8, 48 },
1259 { -8, 61 }, { -8, 66 }, { -7, 70 }, { -14, 75 },
1260 { -10, 79 }, { -9, 83 }, { -12, 92 }, { -18, 108 },
1261 { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
1262 { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
1263 { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }
1264 }
1265 };
1266
ff_h264_init_cabac_states(H264Context * h)1267 void ff_h264_init_cabac_states(H264Context *h) {
1268 int i;
1269 const int8_t (*tab)[2];
1270 const int slice_qp = av_clip(h->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51);
1271
1272 if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I;
1273 else tab = cabac_context_init_PB[h->cabac_init_idc];
1274
1275 /* calculate pre-state */
1276 for( i= 0; i < 1024; i++ ) {
1277 int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127;
1278
1279 pre^= pre>>31;
1280 if(pre > 124)
1281 pre= 124 + (pre&1);
1282
1283 h->cabac_state[i] = pre;
1284 }
1285 }
1286
decode_cabac_field_decoding_flag(H264Context * h)1287 static int decode_cabac_field_decoding_flag(H264Context *h) {
1288 const long mbb_xy = h->mb_xy - 2L*h->mb_stride;
1289
1290 unsigned long ctx = 0;
1291
1292 ctx += h->mb_field_decoding_flag & !!h->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
1293 ctx += (h->cur_pic.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
1294
1295 return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
1296 }
1297
decode_cabac_intra_mb_type(H264Context * h,int ctx_base,int intra_slice)1298 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
1299 uint8_t *state= &h->cabac_state[ctx_base];
1300 int mb_type;
1301
1302 if(intra_slice){
1303 int ctx=0;
1304 if( h->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
1305 ctx++;
1306 if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
1307 ctx++;
1308 if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 )
1309 return 0; /* I4x4 */
1310 state += 2;
1311 }else{
1312 if( get_cabac_noinline( &h->cabac, state ) == 0 )
1313 return 0; /* I4x4 */
1314 }
1315
1316 if( get_cabac_terminate( &h->cabac ) )
1317 return 25; /* PCM */
1318
1319 mb_type = 1; /* I16x16 */
1320 mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */
1321 if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */
1322 mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] );
1323 mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] );
1324 mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] );
1325 return mb_type;
1326 }
1327
decode_cabac_mb_skip(H264Context * h,int mb_x,int mb_y)1328 static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
1329 int mba_xy, mbb_xy;
1330 int ctx = 0;
1331
1332 if (FRAME_MBAFF(h)) { //FIXME merge with the stuff in fill_caches?
1333 int mb_xy = mb_x + (mb_y&~1)*h->mb_stride;
1334 mba_xy = mb_xy - 1;
1335 if( (mb_y&1)
1336 && h->slice_table[mba_xy] == h->slice_num
1337 && MB_FIELD(h) == !!IS_INTERLACED( h->cur_pic.mb_type[mba_xy] ) )
1338 mba_xy += h->mb_stride;
1339 if (MB_FIELD(h)) {
1340 mbb_xy = mb_xy - h->mb_stride;
1341 if( !(mb_y&1)
1342 && h->slice_table[mbb_xy] == h->slice_num
1343 && IS_INTERLACED( h->cur_pic.mb_type[mbb_xy] ) )
1344 mbb_xy -= h->mb_stride;
1345 }else
1346 mbb_xy = mb_x + (mb_y-1)*h->mb_stride;
1347 }else{
1348 int mb_xy = h->mb_xy;
1349 mba_xy = mb_xy - 1;
1350 mbb_xy = mb_xy - (h->mb_stride << FIELD_PICTURE(h));
1351 }
1352
1353 if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP(h->cur_pic.mb_type[mba_xy] ))
1354 ctx++;
1355 if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP(h->cur_pic.mb_type[mbb_xy] ))
1356 ctx++;
1357
1358 if( h->slice_type_nos == AV_PICTURE_TYPE_B )
1359 ctx += 13;
1360 return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] );
1361 }
1362
decode_cabac_mb_intra4x4_pred_mode(H264Context * h,int pred_mode)1363 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) {
1364 int mode = 0;
1365
1366 if( get_cabac( &h->cabac, &h->cabac_state[68] ) )
1367 return pred_mode;
1368
1369 mode += 1 * get_cabac( &h->cabac, &h->cabac_state[69] );
1370 mode += 2 * get_cabac( &h->cabac, &h->cabac_state[69] );
1371 mode += 4 * get_cabac( &h->cabac, &h->cabac_state[69] );
1372
1373 return mode + ( mode >= pred_mode );
1374 }
1375
decode_cabac_mb_chroma_pre_mode(H264Context * h)1376 static int decode_cabac_mb_chroma_pre_mode( H264Context *h) {
1377 const int mba_xy = h->left_mb_xy[0];
1378 const int mbb_xy = h->top_mb_xy;
1379
1380 int ctx = 0;
1381
1382 /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */
1383 if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 )
1384 ctx++;
1385
1386 if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 )
1387 ctx++;
1388
1389 if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 )
1390 return 0;
1391
1392 if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
1393 return 1;
1394 if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
1395 return 2;
1396 else
1397 return 3;
1398 }
1399
decode_cabac_mb_cbp_luma(H264Context * h)1400 static int decode_cabac_mb_cbp_luma( H264Context *h) {
1401 int cbp_b, cbp_a, ctx, cbp = 0;
1402
1403 cbp_a = h->left_cbp;
1404 cbp_b = h->top_cbp;
1405
1406 ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04);
1407 cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]);
1408 ctx = !(cbp & 0x01) + 2 * !(cbp_b & 0x08);
1409 cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1;
1410 ctx = !(cbp_a & 0x08) + 2 * !(cbp & 0x01);
1411 cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2;
1412 ctx = !(cbp & 0x04) + 2 * !(cbp & 0x02);
1413 cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3;
1414 return cbp;
1415 }
decode_cabac_mb_cbp_chroma(H264Context * h)1416 static int decode_cabac_mb_cbp_chroma( H264Context *h) {
1417 int ctx;
1418 int cbp_a, cbp_b;
1419
1420 cbp_a = (h->left_cbp>>4)&0x03;
1421 cbp_b = (h-> top_cbp>>4)&0x03;
1422
1423 ctx = 0;
1424 if( cbp_a > 0 ) ctx++;
1425 if( cbp_b > 0 ) ctx += 2;
1426 if( get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 )
1427 return 0;
1428
1429 ctx = 4;
1430 if( cbp_a == 2 ) ctx++;
1431 if( cbp_b == 2 ) ctx += 2;
1432 return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] );
1433 }
1434
decode_cabac_p_mb_sub_type(H264Context * h)1435 static int decode_cabac_p_mb_sub_type( H264Context *h ) {
1436 if( get_cabac( &h->cabac, &h->cabac_state[21] ) )
1437 return 0; /* 8x8 */
1438 if( !get_cabac( &h->cabac, &h->cabac_state[22] ) )
1439 return 1; /* 8x4 */
1440 if( get_cabac( &h->cabac, &h->cabac_state[23] ) )
1441 return 2; /* 4x8 */
1442 return 3; /* 4x4 */
1443 }
decode_cabac_b_mb_sub_type(H264Context * h)1444 static int decode_cabac_b_mb_sub_type( H264Context *h ) {
1445 int type;
1446 if( !get_cabac( &h->cabac, &h->cabac_state[36] ) )
1447 return 0; /* B_Direct_8x8 */
1448 if( !get_cabac( &h->cabac, &h->cabac_state[37] ) )
1449 return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */
1450 type = 3;
1451 if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) {
1452 if( get_cabac( &h->cabac, &h->cabac_state[39] ) )
1453 return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */
1454 type += 4;
1455 }
1456 type += 2*get_cabac( &h->cabac, &h->cabac_state[39] );
1457 type += get_cabac( &h->cabac, &h->cabac_state[39] );
1458 return type;
1459 }
1460
decode_cabac_mb_ref(H264Context * h,int list,int n)1461 static int decode_cabac_mb_ref( H264Context *h, int list, int n ) {
1462 int refa = h->ref_cache[list][scan8[n] - 1];
1463 int refb = h->ref_cache[list][scan8[n] - 8];
1464 int ref = 0;
1465 int ctx = 0;
1466
1467 if( h->slice_type_nos == AV_PICTURE_TYPE_B) {
1468 if( refa > 0 && !(h->direct_cache[scan8[n] - 1]&(MB_TYPE_DIRECT2>>1)) )
1469 ctx++;
1470 if( refb > 0 && !(h->direct_cache[scan8[n] - 8]&(MB_TYPE_DIRECT2>>1)) )
1471 ctx += 2;
1472 } else {
1473 if( refa > 0 )
1474 ctx++;
1475 if( refb > 0 )
1476 ctx += 2;
1477 }
1478
1479 while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) {
1480 ref++;
1481 ctx = (ctx>>2)+4;
1482 if(ref >= 32 /*h->ref_list[list]*/){
1483 return -1;
1484 }
1485 }
1486 return ref;
1487 }
1488
decode_cabac_mb_mvd(H264Context * h,int ctxbase,int amvd,int * mvda)1489 static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda) {
1490 int mvd;
1491
1492 if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+((amvd-3)>>(INT_BIT-1))+((amvd-33)>>(INT_BIT-1))+2])){
1493 // if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])){
1494 *mvda= 0;
1495 return 0;
1496 }
1497
1498 mvd= 1;
1499 ctxbase+= 3;
1500 while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) {
1501 if( mvd < 4 )
1502 ctxbase++;
1503 mvd++;
1504 }
1505
1506 if( mvd >= 9 ) {
1507 int k = 3;
1508 while( get_cabac_bypass( &h->cabac ) ) {
1509 mvd += 1 << k;
1510 k++;
1511 if(k>24){
1512 av_log(h->avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n");
1513 return INT_MIN;
1514 }
1515 }
1516 while( k-- ) {
1517 mvd += get_cabac_bypass( &h->cabac )<<k;
1518 }
1519 *mvda=mvd < 70 ? mvd : 70;
1520 }else
1521 *mvda=mvd;
1522 return get_cabac_bypass_sign( &h->cabac, -mvd );
1523 }
1524
1525 #define DECODE_CABAC_MB_MVD( h, list, n )\
1526 {\
1527 int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\
1528 h->mvd_cache[list][scan8[n] - 8][0];\
1529 int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\
1530 h->mvd_cache[list][scan8[n] - 8][1];\
1531 \
1532 mx += decode_cabac_mb_mvd( h, 40, amvd0, &mpx );\
1533 my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\
1534 }
1535
get_cabac_cbf_ctx(H264Context * h,int cat,int idx,int max_coeff,int is_dc)1536 static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int max_coeff, int is_dc ) {
1537 int nza, nzb;
1538 int ctx = 0;
1539 static const uint16_t base_ctx[14] = {85,89,93,97,101,1012,460,464,468,1016,472,476,480,1020};
1540
1541 if( is_dc ) {
1542 if( cat == 3 ) {
1543 idx -= CHROMA_DC_BLOCK_INDEX;
1544 nza = (h->left_cbp>>(6+idx))&0x01;
1545 nzb = (h-> top_cbp>>(6+idx))&0x01;
1546 } else {
1547 idx -= LUMA_DC_BLOCK_INDEX;
1548 nza = h->left_cbp&(0x100<<idx);
1549 nzb = h-> top_cbp&(0x100<<idx);
1550 }
1551 } else {
1552 nza = h->non_zero_count_cache[scan8[idx] - 1];
1553 nzb = h->non_zero_count_cache[scan8[idx] - 8];
1554 }
1555
1556 if( nza > 0 )
1557 ctx++;
1558
1559 if( nzb > 0 )
1560 ctx += 2;
1561
1562 return base_ctx[cat] + ctx;
1563 }
1564
1565 static av_always_inline void
decode_cabac_residual_internal(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,const uint32_t * qmul,int max_coeff,int is_dc,int chroma422)1566 decode_cabac_residual_internal(H264Context *h, int16_t *block,
1567 int cat, int n, const uint8_t *scantable,
1568 const uint32_t *qmul, int max_coeff,
1569 int is_dc, int chroma422)
1570 {
1571 static const int significant_coeff_flag_offset[2][14] = {
1572 { 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 },
1573 { 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 }
1574 };
1575 static const int last_coeff_flag_offset[2][14] = {
1576 { 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748 },
1577 { 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757 }
1578 };
1579 static const int coeff_abs_level_m1_offset[14] = {
1580 227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766
1581 };
1582 static const uint8_t significant_coeff_flag_offset_8x8[2][63] = {
1583 { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
1584 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
1585 7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
1586 12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 },
1587 { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
1588 6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
1589 9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
1590 9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
1591 };
1592 static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
1593 /* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
1594 * 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
1595 * map node ctx => cabac ctx for level=1 */
1596 static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
1597 /* map node ctx => cabac ctx for level>1 */
1598 static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
1599 { 5, 5, 5, 5, 6, 7, 8, 9 },
1600 { 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
1601 };
1602 static const uint8_t coeff_abs_level_transition[2][8] = {
1603 /* update node ctx after decoding a level=1 */
1604 { 1, 2, 3, 3, 4, 5, 6, 7 },
1605 /* update node ctx after decoding a level>1 */
1606 { 4, 4, 4, 4, 5, 6, 7, 7 }
1607 };
1608
1609 int index[64];
1610
1611 int last;
1612 int coeff_count = 0;
1613 int node_ctx = 0;
1614
1615 uint8_t *significant_coeff_ctx_base;
1616 uint8_t *last_coeff_ctx_base;
1617 uint8_t *abs_level_m1_ctx_base;
1618
1619 #if !ARCH_X86
1620 #define CABAC_ON_STACK
1621 #endif
1622 #ifdef CABAC_ON_STACK
1623 #define CC &cc
1624 CABACContext cc;
1625 cc.range = h->cabac.range;
1626 cc.low = h->cabac.low;
1627 cc.bytestream= h->cabac.bytestream;
1628 #if !UNCHECKED_BITSTREAM_READER || ARCH_AARCH64
1629 cc.bytestream_end = h->cabac.bytestream_end;
1630 #endif
1631 #else
1632 #define CC &h->cabac
1633 #endif
1634
1635 significant_coeff_ctx_base = h->cabac_state
1636 + significant_coeff_flag_offset[MB_FIELD(h)][cat];
1637 last_coeff_ctx_base = h->cabac_state
1638 + last_coeff_flag_offset[MB_FIELD(h)][cat];
1639 abs_level_m1_ctx_base = h->cabac_state
1640 + coeff_abs_level_m1_offset[cat];
1641
1642 if( !is_dc && max_coeff == 64 ) {
1643 #define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \
1644 for(last= 0; last < coefs; last++) { \
1645 uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \
1646 if( get_cabac( CC, sig_ctx )) { \
1647 uint8_t *last_ctx = last_coeff_ctx_base + last_off; \
1648 index[coeff_count++] = last; \
1649 if( get_cabac( CC, last_ctx ) ) { \
1650 last= max_coeff; \
1651 break; \
1652 } \
1653 } \
1654 }\
1655 if( last == max_coeff -1 ) {\
1656 index[coeff_count++] = last;\
1657 }
1658 const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD(h)];
1659 #ifdef decode_significance
1660 coeff_count = decode_significance_8x8(CC, significant_coeff_ctx_base, index,
1661 last_coeff_ctx_base, sig_off);
1662 } else {
1663 if (is_dc && chroma422) { // dc 422
1664 DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
1665 } else {
1666 coeff_count = decode_significance(CC, max_coeff, significant_coeff_ctx_base, index,
1667 last_coeff_ctx_base-significant_coeff_ctx_base);
1668 }
1669 #else
1670 DECODE_SIGNIFICANCE( 63, sig_off[last], ff_h264_last_coeff_flag_offset_8x8[last] );
1671 } else {
1672 if (is_dc && chroma422) { // dc 422
1673 DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
1674 } else {
1675 DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
1676 }
1677 #endif
1678 }
1679 av_assert2(coeff_count > 0);
1680
1681 if( is_dc ) {
1682 if( cat == 3 )
1683 h->cbp_table[h->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX);
1684 else
1685 h->cbp_table[h->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX);
1686 h->non_zero_count_cache[scan8[n]] = coeff_count;
1687 } else {
1688 if( max_coeff == 64 )
1689 fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
1690 else {
1691 av_assert2( cat == 1 || cat == 2 || cat == 4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 );
1692 h->non_zero_count_cache[scan8[n]] = coeff_count;
1693 }
1694 }
1695
1696 #define STORE_BLOCK(type) \
1697 do { \
1698 uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \
1699 \
1700 int j= scantable[index[--coeff_count]]; \
1701 \
1702 if( get_cabac( CC, ctx ) == 0 ) { \
1703 node_ctx = coeff_abs_level_transition[0][node_ctx]; \
1704 if( is_dc ) { \
1705 ((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \
1706 }else{ \
1707 ((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \
1708 } \
1709 } else { \
1710 int coeff_abs = 2; \
1711 ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \
1712 node_ctx = coeff_abs_level_transition[1][node_ctx]; \
1713 \
1714 while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
1715 coeff_abs++; \
1716 } \
1717 \
1718 if( coeff_abs >= 15 ) { \
1719 int j = 0; \
1720 while(get_cabac_bypass( CC ) && j<30) { \
1721 j++; \
1722 } \
1723 \
1724 coeff_abs=1; \
1725 while( j-- ) { \
1726 coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
1727 } \
1728 coeff_abs+= 14; \
1729 } \
1730 \
1731 if( is_dc ) { \
1732 ((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \
1733 }else{ \
1734 ((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \
1735 } \
1736 } \
1737 } while ( coeff_count );
1738
1739 if (h->pixel_shift) {
1740 STORE_BLOCK(int32_t)
1741 } else {
1742 STORE_BLOCK(int16_t)
1743 }
1744 #ifdef CABAC_ON_STACK
1745 h->cabac.range = cc.range ;
1746 h->cabac.low = cc.low ;
1747 h->cabac.bytestream= cc.bytestream;
1748 #endif
1749
1750 }
1751
decode_cabac_residual_dc_internal(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,int max_coeff)1752 static av_noinline void decode_cabac_residual_dc_internal(H264Context *h,
1753 int16_t *block,
1754 int cat, int n,
1755 const uint8_t *scantable,
1756 int max_coeff)
1757 {
1758 decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
1759 }
1760
decode_cabac_residual_dc_internal_422(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,int max_coeff)1761 static av_noinline void decode_cabac_residual_dc_internal_422(H264Context *h,
1762 int16_t *block,
1763 int cat, int n,
1764 const uint8_t *scantable,
1765 int max_coeff)
1766 {
1767 decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
1768 }
1769
decode_cabac_residual_nondc_internal(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,const uint32_t * qmul,int max_coeff)1770 static av_noinline void decode_cabac_residual_nondc_internal(H264Context *h,
1771 int16_t *block,
1772 int cat, int n,
1773 const uint8_t *scantable,
1774 const uint32_t *qmul,
1775 int max_coeff)
1776 {
1777 decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
1778 }
1779
1780 /* cat: 0-> DC 16x16 n = 0
1781 * 1-> AC 16x16 n = luma4x4idx
1782 * 2-> Luma4x4 n = luma4x4idx
1783 * 3-> DC Chroma n = iCbCr
1784 * 4-> AC Chroma n = 16 + 4 * iCbCr + chroma4x4idx
1785 * 5-> Luma8x8 n = 4 * luma8x8idx */
1786
1787 /* Partially inline the CABAC residual decode: inline the coded block flag.
1788 * This has very little impact on binary size and improves performance
1789 * because it allows improved constant propagation into get_cabac_cbf_ctx,
1790 * as well as because most blocks have zero CBFs. */
1791
decode_cabac_residual_dc(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,int max_coeff)1792 static av_always_inline void decode_cabac_residual_dc(H264Context *h,
1793 int16_t *block,
1794 int cat, int n,
1795 const uint8_t *scantable,
1796 int max_coeff)
1797 {
1798 /* read coded block flag */
1799 if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) {
1800 h->non_zero_count_cache[scan8[n]] = 0;
1801 return;
1802 }
1803 decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff );
1804 }
1805
1806 static av_always_inline void
decode_cabac_residual_dc_422(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,int max_coeff)1807 decode_cabac_residual_dc_422(H264Context *h, int16_t *block,
1808 int cat, int n, const uint8_t *scantable,
1809 int max_coeff)
1810 {
1811 /* read coded block flag */
1812 if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) {
1813 h->non_zero_count_cache[scan8[n]] = 0;
1814 return;
1815 }
1816 decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff);
1817 }
1818
decode_cabac_residual_nondc(H264Context * h,int16_t * block,int cat,int n,const uint8_t * scantable,const uint32_t * qmul,int max_coeff)1819 static av_always_inline void decode_cabac_residual_nondc(H264Context *h,
1820 int16_t *block,
1821 int cat, int n,
1822 const uint8_t *scantable,
1823 const uint32_t *qmul,
1824 int max_coeff)
1825 {
1826 /* read coded block flag */
1827 if( (cat != 5 || CHROMA444(h)) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
1828 if( max_coeff == 64 ) {
1829 fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1);
1830 } else {
1831 h->non_zero_count_cache[scan8[n]] = 0;
1832 }
1833 return;
1834 }
1835 decode_cabac_residual_nondc_internal( h, block, cat, n, scantable, qmul, max_coeff );
1836 }
1837
decode_cabac_luma_residual(H264Context * h,const uint8_t * scan,const uint8_t * scan8x8,int pixel_shift,int mb_type,int cbp,int p)1838 static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
1839 {
1840 static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};
1841 const uint32_t *qmul;
1842 int i8x8, i4x4;
1843 int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1];
1844 if( IS_INTRA16x16( mb_type ) ) {
1845 AV_ZERO128(h->mb_luma_dc[p]+0);
1846 AV_ZERO128(h->mb_luma_dc[p]+8);
1847 AV_ZERO128(h->mb_luma_dc[p]+16);
1848 AV_ZERO128(h->mb_luma_dc[p]+24);
1849 decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16);
1850
1851 if( cbp&15 ) {
1852 qmul = h->dequant4_coeff[p][qscale];
1853 for( i4x4 = 0; i4x4 < 16; i4x4++ ) {
1854 const int index = 16*p + i4x4;
1855 decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15);
1856 }
1857 } else {
1858 fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1);
1859 }
1860 } else {
1861 int cqm = (IS_INTRA( mb_type ) ? 0:3) + p;
1862 for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
1863 if( cbp & (1<<i8x8) ) {
1864 if( IS_8x8DCT(mb_type) ) {
1865 const int index = 16*p + 4*i8x8;
1866 decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index,
1867 scan8x8, h->dequant8_coeff[cqm][qscale], 64);
1868 } else {
1869 qmul = h->dequant4_coeff[cqm][qscale];
1870 for( i4x4 = 0; i4x4 < 4; i4x4++ ) {
1871 const int index = 16*p + 4*i8x8 + i4x4;
1872 //START_TIMER
1873 decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16);
1874 //STOP_TIMER("decode_residual")
1875 }
1876 }
1877 } else {
1878 fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
1879 }
1880 }
1881 }
1882 }
1883
1884 /**
1885 * Decode a macroblock.
1886 * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed
1887 */
ff_h264_decode_mb_cabac(H264Context * h)1888 int ff_h264_decode_mb_cabac(H264Context *h) {
1889 int mb_xy;
1890 int mb_type, partition_count, cbp = 0;
1891 int dct8x8_allowed= h->pps.transform_8x8_mode;
1892 int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;
1893 const int pixel_shift = h->pixel_shift;
1894 unsigned local_ref_count[2];
1895
1896 mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride;
1897
1898 tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y);
1899 if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {
1900 int skip;
1901 /* a skipped mb needs the aff flag from the following mb */
1902 if (FRAME_MBAFF(h) && (h->mb_y & 1) == 1 && h->prev_mb_skipped)
1903 skip = h->next_mb_skipped;
1904 else
1905 skip = decode_cabac_mb_skip( h, h->mb_x, h->mb_y );
1906 /* read skip flags */
1907 if( skip ) {
1908 if (FRAME_MBAFF(h) && (h->mb_y & 1) == 0) {
1909 h->cur_pic.mb_type[mb_xy] = MB_TYPE_SKIP;
1910 h->next_mb_skipped = decode_cabac_mb_skip( h, h->mb_x, h->mb_y+1 );
1911 if(!h->next_mb_skipped)
1912 h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
1913 }
1914
1915 decode_mb_skip(h);
1916
1917 h->cbp_table[mb_xy] = 0;
1918 h->chroma_pred_mode_table[mb_xy] = 0;
1919 h->last_qscale_diff = 0;
1920
1921 return 0;
1922
1923 }
1924 }
1925 if (FRAME_MBAFF(h)) {
1926 if( (h->mb_y&1) == 0 )
1927 h->mb_mbaff =
1928 h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
1929 }
1930
1931 h->prev_mb_skipped = 0;
1932
1933 fill_decode_neighbors(h, -(MB_FIELD(h)));
1934
1935 if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
1936 int ctx = 0;
1937 av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_B);
1938
1939 if( !IS_DIRECT( h->left_type[LTOP]-1 ) )
1940 ctx++;
1941 if( !IS_DIRECT( h->top_type-1 ) )
1942 ctx++;
1943
1944 if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){
1945 mb_type= 0; /* B_Direct_16x16 */
1946 }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {
1947 mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */
1948 }else{
1949 int bits;
1950 bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;
1951 bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;
1952 bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;
1953 bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
1954 if( bits < 8 ){
1955 mb_type= bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */
1956 }else if( bits == 13 ){
1957 mb_type= decode_cabac_intra_mb_type(h, 32, 0);
1958 goto decode_intra_mb;
1959 }else if( bits == 14 ){
1960 mb_type= 11; /* B_L1_L0_8x16 */
1961 }else if( bits == 15 ){
1962 mb_type= 22; /* B_8x8 */
1963 }else{
1964 bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
1965 mb_type= bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */
1966 }
1967 }
1968 partition_count= b_mb_type_info[mb_type].partition_count;
1969 mb_type= b_mb_type_info[mb_type].type;
1970 } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {
1971 if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {
1972 /* P-type */
1973 if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {
1974 /* P_L0_D16x16, P_8x8 */
1975 mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
1976 } else {
1977 /* P_L0_D8x16, P_L0_D16x8 */
1978 mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
1979 }
1980 partition_count= p_mb_type_info[mb_type].partition_count;
1981 mb_type= p_mb_type_info[mb_type].type;
1982 } else {
1983 mb_type= decode_cabac_intra_mb_type(h, 17, 0);
1984 goto decode_intra_mb;
1985 }
1986 } else {
1987 mb_type= decode_cabac_intra_mb_type(h, 3, 1);
1988 if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)
1989 mb_type--;
1990 av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_I);
1991 decode_intra_mb:
1992 partition_count = 0;
1993 cbp= i_mb_type_info[mb_type].cbp;
1994 h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
1995 mb_type= i_mb_type_info[mb_type].type;
1996 }
1997 if(MB_FIELD(h))
1998 mb_type |= MB_TYPE_INTERLACED;
1999
2000 h->slice_table[ mb_xy ]= h->slice_num;
2001
2002 if(IS_INTRA_PCM(mb_type)) {
2003 const int mb_size = ff_h264_mb_sizes[h->sps.chroma_format_idc] *
2004 h->sps.bit_depth_luma >> 3;
2005 const uint8_t *ptr;
2006
2007 // We assume these blocks are very rare so we do not optimize it.
2008 // FIXME The two following lines get the bitstream position in the cabac
2009 // decode, I think it should be done by a function in cabac.h (or cabac.c).
2010 ptr= h->cabac.bytestream;
2011 if(h->cabac.low&0x1) ptr--;
2012 if(CABAC_BITS==16){
2013 if(h->cabac.low&0x1FF) ptr--;
2014 }
2015
2016 // The pixels are stored in the same order as levels in h->mb array.
2017 if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
2018 return -1;
2019 h->intra_pcm_ptr = ptr;
2020 ptr += mb_size;
2021
2022 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
2023
2024 // All blocks are present
2025 h->cbp_table[mb_xy] = 0xf7ef;
2026 h->chroma_pred_mode_table[mb_xy] = 0;
2027 // In deblocking, the quantizer is 0
2028 h->cur_pic.qscale_table[mb_xy] = 0;
2029 // All coeffs are present
2030 memset(h->non_zero_count[mb_xy], 16, 48);
2031 h->cur_pic.mb_type[mb_xy] = mb_type;
2032 h->last_qscale_diff = 0;
2033 return 0;
2034 }
2035
2036 local_ref_count[0] = h->ref_count[0] << MB_MBAFF(h);
2037 local_ref_count[1] = h->ref_count[1] << MB_MBAFF(h);
2038
2039 fill_decode_caches(h, mb_type);
2040
2041 if( IS_INTRA( mb_type ) ) {
2042 int i, pred_mode;
2043 if( IS_INTRA4x4( mb_type ) ) {
2044 if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {
2045 mb_type |= MB_TYPE_8x8DCT;
2046 for( i = 0; i < 16; i+=4 ) {
2047 int pred = pred_intra_mode( h, i );
2048 int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );
2049 fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );
2050 }
2051 } else {
2052 for( i = 0; i < 16; i++ ) {
2053 int pred = pred_intra_mode( h, i );
2054 h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );
2055
2056 av_dlog(h->avctx, "i4x4 pred=%d mode=%d\n", pred,
2057 h->intra4x4_pred_mode_cache[scan8[i]]);
2058 }
2059 }
2060 write_back_intra_pred_mode(h);
2061 if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;
2062 } else {
2063 h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode, 0 );
2064 if( h->intra16x16_pred_mode < 0 ) return -1;
2065 }
2066 if(decode_chroma){
2067 h->chroma_pred_mode_table[mb_xy] =
2068 pred_mode = decode_cabac_mb_chroma_pre_mode( h );
2069
2070 pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 );
2071 if( pred_mode < 0 ) return -1;
2072 h->chroma_pred_mode= pred_mode;
2073 } else {
2074 h->chroma_pred_mode= DC_128_PRED8x8;
2075 }
2076 } else if( partition_count == 4 ) {
2077 int i, j, sub_partition_count[4], list, ref[2][4];
2078
2079 if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
2080 for( i = 0; i < 4; i++ ) {
2081 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );
2082 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
2083 h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
2084 }
2085 if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |
2086 h->sub_mb_type[2] | h->sub_mb_type[3]) ) {
2087 ff_h264_pred_direct_motion(h, &mb_type);
2088 h->ref_cache[0][scan8[4]] =
2089 h->ref_cache[1][scan8[4]] =
2090 h->ref_cache[0][scan8[12]] =
2091 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
2092 for( i = 0; i < 4; i++ )
2093 fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );
2094 }
2095 } else {
2096 for( i = 0; i < 4; i++ ) {
2097 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );
2098 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
2099 h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;
2100 }
2101 }
2102
2103 for( list = 0; list < h->list_count; list++ ) {
2104 for( i = 0; i < 4; i++ ) {
2105 if(IS_DIRECT(h->sub_mb_type[i])) continue;
2106 if(IS_DIR(h->sub_mb_type[i], 0, list)){
2107 if (local_ref_count[list] > 1) {
2108 ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );
2109 if (ref[list][i] >= (unsigned)local_ref_count[list]) {
2110 av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]);
2111 return -1;
2112 }
2113 }else
2114 ref[list][i] = 0;
2115 } else {
2116 ref[list][i] = -1;
2117 }
2118 h->ref_cache[list][ scan8[4*i]+1 ]=
2119 h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
2120 }
2121 }
2122
2123 if(dct8x8_allowed)
2124 dct8x8_allowed = get_dct8x8_allowed(h);
2125
2126 for(list=0; list<h->list_count; list++){
2127 for(i=0; i<4; i++){
2128 h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];
2129 if(IS_DIRECT(h->sub_mb_type[i])){
2130 fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);
2131 continue;
2132 }
2133
2134 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){
2135 const int sub_mb_type= h->sub_mb_type[i];
2136 const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
2137 for(j=0; j<sub_partition_count[i]; j++){
2138 int mpx, mpy;
2139 int mx, my;
2140 const int index= 4*i + block_width*j;
2141 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
2142 uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];
2143 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
2144 DECODE_CABAC_MB_MVD( h, list, index)
2145 tprintf(h->avctx, "final mv:%d %d\n", mx, my);
2146
2147 if(IS_SUB_8X8(sub_mb_type)){
2148 mv_cache[ 1 ][0]=
2149 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
2150 mv_cache[ 1 ][1]=
2151 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
2152
2153 mvd_cache[ 1 ][0]=
2154 mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;
2155 mvd_cache[ 1 ][1]=
2156 mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;
2157 }else if(IS_SUB_8X4(sub_mb_type)){
2158 mv_cache[ 1 ][0]= mx;
2159 mv_cache[ 1 ][1]= my;
2160
2161 mvd_cache[ 1 ][0]= mpx;
2162 mvd_cache[ 1 ][1]= mpy;
2163 }else if(IS_SUB_4X8(sub_mb_type)){
2164 mv_cache[ 8 ][0]= mx;
2165 mv_cache[ 8 ][1]= my;
2166
2167 mvd_cache[ 8 ][0]= mpx;
2168 mvd_cache[ 8 ][1]= mpy;
2169 }
2170 mv_cache[ 0 ][0]= mx;
2171 mv_cache[ 0 ][1]= my;
2172
2173 mvd_cache[ 0 ][0]= mpx;
2174 mvd_cache[ 0 ][1]= mpy;
2175 }
2176 }else{
2177 fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);
2178 fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);
2179 }
2180 }
2181 }
2182 } else if( IS_DIRECT(mb_type) ) {
2183 ff_h264_pred_direct_motion(h, &mb_type);
2184 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);
2185 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);
2186 dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
2187 } else {
2188 int list, i;
2189 if(IS_16X16(mb_type)){
2190 for(list=0; list<h->list_count; list++){
2191 if(IS_DIR(mb_type, 0, list)){
2192 int ref;
2193 if (local_ref_count[list] > 1) {
2194 ref= decode_cabac_mb_ref(h, list, 0);
2195 if (ref >= (unsigned)local_ref_count[list]) {
2196 av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
2197 return -1;
2198 }
2199 }else
2200 ref=0;
2201 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);
2202 }
2203 }
2204 for(list=0; list<h->list_count; list++){
2205 if(IS_DIR(mb_type, 0, list)){
2206 int mx,my,mpx,mpy;
2207 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
2208 DECODE_CABAC_MB_MVD( h, list, 0)
2209 tprintf(h->avctx, "final mv:%d %d\n", mx, my);
2210
2211 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);
2212 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
2213 }
2214 }
2215 }
2216 else if(IS_16X8(mb_type)){
2217 for(list=0; list<h->list_count; list++){
2218 for(i=0; i<2; i++){
2219 if(IS_DIR(mb_type, i, list)){
2220 int ref;
2221 if (local_ref_count[list] > 1) {
2222 ref= decode_cabac_mb_ref( h, list, 8*i );
2223 if (ref >= (unsigned)local_ref_count[list]) {
2224 av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
2225 return -1;
2226 }
2227 }else
2228 ref=0;
2229 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);
2230 }else
2231 fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);
2232 }
2233 }
2234 for(list=0; list<h->list_count; list++){
2235 for(i=0; i<2; i++){
2236 if(IS_DIR(mb_type, i, list)){
2237 int mx,my,mpx,mpy;
2238 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
2239 DECODE_CABAC_MB_MVD( h, list, 8*i)
2240 tprintf(h->avctx, "final mv:%d %d\n", mx, my);
2241
2242 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);
2243 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
2244 }else{
2245 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);
2246 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
2247 }
2248 }
2249 }
2250 }else{
2251 av_assert2(IS_8X16(mb_type));
2252 for(list=0; list<h->list_count; list++){
2253 for(i=0; i<2; i++){
2254 if(IS_DIR(mb_type, i, list)){ //FIXME optimize
2255 int ref;
2256 if (local_ref_count[list] > 1) {
2257 ref= decode_cabac_mb_ref( h, list, 4*i );
2258 if (ref >= (unsigned)local_ref_count[list]) {
2259 av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]);
2260 return -1;
2261 }
2262 }else
2263 ref=0;
2264 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);
2265 }else
2266 fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);
2267 }
2268 }
2269 for(list=0; list<h->list_count; list++){
2270 for(i=0; i<2; i++){
2271 if(IS_DIR(mb_type, i, list)){
2272 int mx,my,mpx,mpy;
2273 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
2274 DECODE_CABAC_MB_MVD( h, list, 4*i)
2275
2276 tprintf(h->avctx, "final mv:%d %d\n", mx, my);
2277 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);
2278 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
2279 }else{
2280 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);
2281 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
2282 }
2283 }
2284 }
2285 }
2286 }
2287
2288 if( IS_INTER( mb_type ) ) {
2289 h->chroma_pred_mode_table[mb_xy] = 0;
2290 write_back_motion( h, mb_type );
2291 }
2292
2293 if( !IS_INTRA16x16( mb_type ) ) {
2294 cbp = decode_cabac_mb_cbp_luma( h );
2295 if(decode_chroma)
2296 cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;
2297 } else {
2298 if (!decode_chroma && cbp>15) {
2299 av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n");
2300 return AVERROR_INVALIDDATA;
2301 }
2302 }
2303
2304 h->cbp_table[mb_xy] = h->cbp = cbp;
2305
2306 if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {
2307 mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );
2308 }
2309
2310 /* It would be better to do this in fill_decode_caches, but we don't know
2311 * the transform mode of the current macroblock there. */
2312 if (CHROMA444(h) && IS_8x8DCT(mb_type)){
2313 int i;
2314 uint8_t *nnz_cache = h->non_zero_count_cache;
2315 for (i = 0; i < 2; i++){
2316 if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){
2317 nnz_cache[3+8* 1 + 2*8*i]=
2318 nnz_cache[3+8* 2 + 2*8*i]=
2319 nnz_cache[3+8* 6 + 2*8*i]=
2320 nnz_cache[3+8* 7 + 2*8*i]=
2321 nnz_cache[3+8*11 + 2*8*i]=
2322 nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;
2323 }
2324 }
2325 if (h->top_type && !IS_8x8DCT(h->top_type)){
2326 uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040;
2327 AV_WN32A(&nnz_cache[4+8* 0], top_empty);
2328 AV_WN32A(&nnz_cache[4+8* 5], top_empty);
2329 AV_WN32A(&nnz_cache[4+8*10], top_empty);
2330 }
2331 }
2332 h->cur_pic.mb_type[mb_xy] = mb_type;
2333
2334 if( cbp || IS_INTRA16x16( mb_type ) ) {
2335 const uint8_t *scan, *scan8x8;
2336 const uint32_t *qmul;
2337
2338 if(IS_INTERLACED(mb_type)){
2339 scan8x8= h->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;
2340 scan= h->qscale ? h->field_scan : h->field_scan_q0;
2341 }else{
2342 scan8x8= h->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;
2343 scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
2344 }
2345
2346 // decode_cabac_mb_dqp
2347 if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){
2348 int val = 1;
2349 int ctx= 2;
2350 const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
2351
2352 while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
2353 ctx= 3;
2354 val++;
2355 if(val > 2*max_qp){ //prevent infinite loop
2356 av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", h->mb_x, h->mb_y);
2357 return -1;
2358 }
2359 }
2360
2361 if( val&0x01 )
2362 val= (val + 1)>>1 ;
2363 else
2364 val= -((val + 1)>>1);
2365 h->last_qscale_diff = val;
2366 h->qscale += val;
2367 if(((unsigned)h->qscale) > max_qp){
2368 if(h->qscale<0) h->qscale+= max_qp+1;
2369 else h->qscale-= max_qp+1;
2370 }
2371 h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale);
2372 h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale);
2373 }else
2374 h->last_qscale_diff=0;
2375
2376 decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);
2377 if (CHROMA444(h)) {
2378 decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
2379 decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
2380 } else if (CHROMA422(h)) {
2381 if( cbp&0x30 ){
2382 int c;
2383 for (c = 0; c < 2; c++)
2384 decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,
2385 CHROMA_DC_BLOCK_INDEX + c,
2386 chroma422_dc_scan, 8);
2387 }
2388
2389 if( cbp&0x20 ) {
2390 int c, i, i8x8;
2391 for( c = 0; c < 2; c++ ) {
2392 int16_t *mb = h->mb + (16*(16 + 16*c) << pixel_shift);
2393 qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
2394 for (i8x8 = 0; i8x8 < 2; i8x8++) {
2395 for (i = 0; i < 4; i++) {
2396 const int index = 16 + 16 * c + 8*i8x8 + i;
2397 decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);
2398 mb += 16<<pixel_shift;
2399 }
2400 }
2401 }
2402 } else {
2403 fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
2404 fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
2405 }
2406 } else /* yuv420 */ {
2407 if( cbp&0x30 ){
2408 int c;
2409 for (c = 0; c < 2; c++)
2410 decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);
2411 }
2412
2413 if( cbp&0x20 ) {
2414 int c, i;
2415 for( c = 0; c < 2; c++ ) {
2416 qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
2417 for( i = 0; i < 4; i++ ) {
2418 const int index = 16 + 16 * c + i;
2419 decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);
2420 }
2421 }
2422 } else {
2423 fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
2424 fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
2425 }
2426 }
2427 } else {
2428 fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
2429 fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
2430 fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
2431 h->last_qscale_diff = 0;
2432 }
2433
2434 h->cur_pic.qscale_table[mb_xy] = h->qscale;
2435 write_back_non_zero_count(h);
2436
2437 return 0;
2438 }
2439