mpeg12data.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * MPEG1/2 tables
  3. * copyright (c) 2000,2001 Fabrice Bellard
  4. * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file libavcodec/mpeg12data.c
  24. * MPEG1/2 tables.
  25. */
  26. #include "mpeg12data.h"
  27. const uint16_t ff_mpeg1_default_intra_matrix[64] = {
  28. 8, 16, 19, 22, 26, 27, 29, 34,
  29. 16, 16, 22, 24, 27, 29, 34, 37,
  30. 19, 22, 26, 27, 29, 34, 34, 38,
  31. 22, 22, 26, 27, 29, 34, 37, 40,
  32. 22, 26, 27, 29, 32, 35, 40, 48,
  33. 26, 27, 29, 32, 35, 40, 48, 58,
  34. 26, 27, 29, 34, 38, 46, 56, 69,
  35. 27, 29, 35, 38, 46, 56, 69, 83
  36. };
  37. const uint16_t ff_mpeg1_default_non_intra_matrix[64] = {
  38. 16, 16, 16, 16, 16, 16, 16, 16,
  39. 16, 16, 16, 16, 16, 16, 16, 16,
  40. 16, 16, 16, 16, 16, 16, 16, 16,
  41. 16, 16, 16, 16, 16, 16, 16, 16,
  42. 16, 16, 16, 16, 16, 16, 16, 16,
  43. 16, 16, 16, 16, 16, 16, 16, 16,
  44. 16, 16, 16, 16, 16, 16, 16, 16,
  45. 16, 16, 16, 16, 16, 16, 16, 16,
  46. };
  47. const uint16_t ff_mpeg12_vlc_dc_lum_code[12] = {
  48. 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
  49. };
  50. const unsigned char ff_mpeg12_vlc_dc_lum_bits[12] = {
  51. 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
  52. };
  53. const uint16_t ff_mpeg12_vlc_dc_chroma_code[12] = {
  54. 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
  55. };
  56. const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12] = {
  57. 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
  58. };
  59. static const uint16_t mpeg1_vlc[113][2] = {
  60. { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
  61. { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
  62. { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
  63. { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
  64. { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
  65. { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
  66. { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
  67. { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
  68. { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
  69. { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
  70. { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
  71. { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
  72. { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
  73. { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
  74. { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
  75. { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
  76. { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
  77. { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
  78. { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
  79. { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
  80. { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
  81. { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
  82. { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
  83. { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
  84. { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
  85. { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
  86. { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
  87. { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
  88. { 0x1, 6 }, /* escape */
  89. { 0x2, 2 }, /* EOB */
  90. };
  91. static const uint16_t mpeg2_vlc[113][2] = {
  92. {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
  93. {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
  94. {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
  95. {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
  96. {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
  97. {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
  98. {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
  99. {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
  100. {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
  101. {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
  102. {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
  103. {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
  104. {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
  105. {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
  106. {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
  107. {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
  108. {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
  109. {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
  110. {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
  111. {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
  112. {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
  113. {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
  114. {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
  115. {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
  116. {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
  117. {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
  118. {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
  119. {0x1d,16}, {0x1c,16}, {0x1b,16},
  120. {0x01,6}, /* escape */
  121. {0x06,4}, /* EOB */
  122. };
  123. static const int8_t mpeg1_level[111] = {
  124. 1, 2, 3, 4, 5, 6, 7, 8,
  125. 9, 10, 11, 12, 13, 14, 15, 16,
  126. 17, 18, 19, 20, 21, 22, 23, 24,
  127. 25, 26, 27, 28, 29, 30, 31, 32,
  128. 33, 34, 35, 36, 37, 38, 39, 40,
  129. 1, 2, 3, 4, 5, 6, 7, 8,
  130. 9, 10, 11, 12, 13, 14, 15, 16,
  131. 17, 18, 1, 2, 3, 4, 5, 1,
  132. 2, 3, 4, 1, 2, 3, 1, 2,
  133. 3, 1, 2, 3, 1, 2, 1, 2,
  134. 1, 2, 1, 2, 1, 2, 1, 2,
  135. 1, 2, 1, 2, 1, 2, 1, 2,
  136. 1, 1, 1, 1, 1, 1, 1, 1,
  137. 1, 1, 1, 1, 1, 1, 1,
  138. };
  139. static const int8_t mpeg1_run[111] = {
  140. 0, 0, 0, 0, 0, 0, 0, 0,
  141. 0, 0, 0, 0, 0, 0, 0, 0,
  142. 0, 0, 0, 0, 0, 0, 0, 0,
  143. 0, 0, 0, 0, 0, 0, 0, 0,
  144. 0, 0, 0, 0, 0, 0, 0, 0,
  145. 1, 1, 1, 1, 1, 1, 1, 1,
  146. 1, 1, 1, 1, 1, 1, 1, 1,
  147. 1, 1, 2, 2, 2, 2, 2, 3,
  148. 3, 3, 3, 4, 4, 4, 5, 5,
  149. 5, 6, 6, 6, 7, 7, 8, 8,
  150. 9, 9, 10, 10, 11, 11, 12, 12,
  151. 13, 13, 14, 14, 15, 15, 16, 16,
  152. 17, 18, 19, 20, 21, 22, 23, 24,
  153. 25, 26, 27, 28, 29, 30, 31,
  154. };
  155. RLTable ff_rl_mpeg1 = {
  156. 111,
  157. 111,
  158. mpeg1_vlc,
  159. mpeg1_run,
  160. mpeg1_level,
  161. };
  162. RLTable ff_rl_mpeg2 = {
  163. 111,
  164. 111,
  165. mpeg2_vlc,
  166. mpeg1_run,
  167. mpeg1_level,
  168. };
  169. const uint8_t ff_mpeg12_mbAddrIncrTable[36][2] = {
  170. {0x1, 1},
  171. {0x3, 3},
  172. {0x2, 3},
  173. {0x3, 4},
  174. {0x2, 4},
  175. {0x3, 5},
  176. {0x2, 5},
  177. {0x7, 7},
  178. {0x6, 7},
  179. {0xb, 8},
  180. {0xa, 8},
  181. {0x9, 8},
  182. {0x8, 8},
  183. {0x7, 8},
  184. {0x6, 8},
  185. {0x17, 10},
  186. {0x16, 10},
  187. {0x15, 10},
  188. {0x14, 10},
  189. {0x13, 10},
  190. {0x12, 10},
  191. {0x23, 11},
  192. {0x22, 11},
  193. {0x21, 11},
  194. {0x20, 11},
  195. {0x1f, 11},
  196. {0x1e, 11},
  197. {0x1d, 11},
  198. {0x1c, 11},
  199. {0x1b, 11},
  200. {0x1a, 11},
  201. {0x19, 11},
  202. {0x18, 11},
  203. {0x8, 11}, /* escape */
  204. {0xf, 11}, /* stuffing */
  205. {0x0, 8}, /* end (and 15 more 0 bits should follow) */
  206. };
  207. const uint8_t ff_mpeg12_mbPatTable[64][2] = {
  208. {0x1, 9},
  209. {0xb, 5},
  210. {0x9, 5},
  211. {0xd, 6},
  212. {0xd, 4},
  213. {0x17, 7},
  214. {0x13, 7},
  215. {0x1f, 8},
  216. {0xc, 4},
  217. {0x16, 7},
  218. {0x12, 7},
  219. {0x1e, 8},
  220. {0x13, 5},
  221. {0x1b, 8},
  222. {0x17, 8},
  223. {0x13, 8},
  224. {0xb, 4},
  225. {0x15, 7},
  226. {0x11, 7},
  227. {0x1d, 8},
  228. {0x11, 5},
  229. {0x19, 8},
  230. {0x15, 8},
  231. {0x11, 8},
  232. {0xf, 6},
  233. {0xf, 8},
  234. {0xd, 8},
  235. {0x3, 9},
  236. {0xf, 5},
  237. {0xb, 8},
  238. {0x7, 8},
  239. {0x7, 9},
  240. {0xa, 4},
  241. {0x14, 7},
  242. {0x10, 7},
  243. {0x1c, 8},
  244. {0xe, 6},
  245. {0xe, 8},
  246. {0xc, 8},
  247. {0x2, 9},
  248. {0x10, 5},
  249. {0x18, 8},
  250. {0x14, 8},
  251. {0x10, 8},
  252. {0xe, 5},
  253. {0xa, 8},
  254. {0x6, 8},
  255. {0x6, 9},
  256. {0x12, 5},
  257. {0x1a, 8},
  258. {0x16, 8},
  259. {0x12, 8},
  260. {0xd, 5},
  261. {0x9, 8},
  262. {0x5, 8},
  263. {0x5, 9},
  264. {0xc, 5},
  265. {0x8, 8},
  266. {0x4, 8},
  267. {0x4, 9},
  268. {0x7, 3},
  269. {0xa, 5},
  270. {0x8, 5},
  271. {0xc, 6}
  272. };
  273. const uint8_t ff_mpeg12_mbMotionVectorTable[17][2] = {
  274. { 0x1, 1 },
  275. { 0x1, 2 },
  276. { 0x1, 3 },
  277. { 0x1, 4 },
  278. { 0x3, 6 },
  279. { 0x5, 7 },
  280. { 0x4, 7 },
  281. { 0x3, 7 },
  282. { 0xb, 9 },
  283. { 0xa, 9 },
  284. { 0x9, 9 },
  285. { 0x11, 10 },
  286. { 0x10, 10 },
  287. { 0xf, 10 },
  288. { 0xe, 10 },
  289. { 0xd, 10 },
  290. { 0xc, 10 },
  291. };
  292. const AVRational ff_frame_rate_tab[] = {
  293. { 0, 0},
  294. {24000, 1001},
  295. { 24, 1},
  296. { 25, 1},
  297. {30000, 1001},
  298. { 30, 1},
  299. { 50, 1},
  300. {60000, 1001},
  301. { 60, 1},
  302. // Xing's 15fps: (9)
  303. { 15, 1},
  304. // libmpeg3's "Unofficial economy rates": (10-13)
  305. { 5, 1},
  306. { 10, 1},
  307. { 12, 1},
  308. { 15, 1},
  309. { 0, 0},
  310. };
  311. const float ff_mpeg1_aspect[16]={
  312. 0.0000,
  313. 1.0000,
  314. 0.6735,
  315. 0.7031,
  316. 0.7615,
  317. 0.8055,
  318. 0.8437,
  319. 0.8935,
  320. 0.9157,
  321. 0.9815,
  322. 1.0255,
  323. 1.0695,
  324. 1.0950,
  325. 1.1575,
  326. 1.2015,
  327. };
  328. const AVRational ff_mpeg2_aspect[16]={
  329. {0,1},
  330. {1,1},
  331. {4,3},
  332. {16,9},
  333. {221,100},
  334. {0,1},
  335. {0,1},
  336. {0,1},
  337. {0,1},
  338. {0,1},
  339. {0,1},
  340. {0,1},
  341. {0,1},
  342. {0,1},
  343. {0,1},
  344. {0,1},
  345. };