2
0

mpeg12data.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. * MPEG-1/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
  24. * MPEG-1/2 tables.
  25. */
  26. #include "mpeg12data.h"
  27. const uint16_t ff_mpeg1_default_intra_matrix[256] = {
  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_mpeg2_frame_rate_tab[] = {
  293. { 1, 1},
  294. { 2, 1},
  295. { 3, 1},
  296. { 4, 1},
  297. { 5, 1},
  298. { 6, 1},
  299. { 8, 1},
  300. { 9, 1},
  301. { 10, 1},
  302. { 12, 1},
  303. { 15, 1},
  304. { 16, 1},
  305. { 18, 1},
  306. { 20, 1},
  307. { 24, 1},
  308. { 25, 1},
  309. { 30, 1},
  310. { 32, 1},
  311. { 36, 1},
  312. { 40, 1},
  313. { 45, 1},
  314. { 48, 1},
  315. { 50, 1},
  316. { 60, 1},
  317. { 72, 1},
  318. { 75, 1},
  319. { 80, 1},
  320. { 90, 1},
  321. { 96, 1},
  322. { 100, 1},
  323. { 120, 1},
  324. { 150, 1},
  325. { 180, 1},
  326. { 200, 1},
  327. { 240, 1},
  328. { 750, 1001},
  329. { 800, 1001},
  330. { 960, 1001},
  331. { 1000, 1001},
  332. { 1200, 1001},
  333. { 1250, 1001},
  334. { 1500, 1001},
  335. { 1600, 1001},
  336. { 1875, 1001},
  337. { 2000, 1001},
  338. { 2400, 1001},
  339. { 2500, 1001},
  340. { 3000, 1001},
  341. { 3750, 1001},
  342. { 4000, 1001},
  343. { 4800, 1001},
  344. { 5000, 1001},
  345. { 6000, 1001},
  346. { 7500, 1001},
  347. { 8000, 1001},
  348. { 10000, 1001},
  349. { 12000, 1001},
  350. { 15000, 1001},
  351. { 20000, 1001},
  352. { 24000, 1001},
  353. { 30000, 1001},
  354. { 60000, 1001},
  355. { 0, 0},
  356. };
  357. const float ff_mpeg1_aspect[16]={
  358. 0.0000,
  359. 1.0000,
  360. 0.6735,
  361. 0.7031,
  362. 0.7615,
  363. 0.8055,
  364. 0.8437,
  365. 0.8935,
  366. 0.9157,
  367. 0.9815,
  368. 1.0255,
  369. 1.0695,
  370. 1.0950,
  371. 1.1575,
  372. 1.2015,
  373. };
  374. const AVRational ff_mpeg2_aspect[16]={
  375. {0,1},
  376. {1,1},
  377. {4,3},
  378. {16,9},
  379. {221,100},
  380. {0,1},
  381. {0,1},
  382. {0,1},
  383. {0,1},
  384. {0,1},
  385. {0,1},
  386. {0,1},
  387. {0,1},
  388. {0,1},
  389. {0,1},
  390. {0,1},
  391. };