You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2453 lines
114KB

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