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.

2418 lines
112KB

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