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.

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