2 * MPEG1 codec / MPEG2 decoder
3 * copyright (c) 2000,2001 Fabrice Bellard
4 * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
6 * This file is part of FFmpeg.
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.
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.
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
28 #ifndef AVCODEC_MPEG12DATA_H
29 #define AVCODEC_MPEG12DATA_H
32 #include "mpegvideo.h"
34 const uint16_t ff_mpeg1_default_intra_matrix[64] = {
35 8, 16, 19, 22, 26, 27, 29, 34,
36 16, 16, 22, 24, 27, 29, 34, 37,
37 19, 22, 26, 27, 29, 34, 34, 38,
38 22, 22, 26, 27, 29, 34, 37, 40,
39 22, 26, 27, 29, 32, 35, 40, 48,
40 26, 27, 29, 32, 35, 40, 48, 58,
41 26, 27, 29, 34, 38, 46, 56, 69,
42 27, 29, 35, 38, 46, 56, 69, 83
45 const uint16_t ff_mpeg1_default_non_intra_matrix[64] = {
46 16, 16, 16, 16, 16, 16, 16, 16,
47 16, 16, 16, 16, 16, 16, 16, 16,
48 16, 16, 16, 16, 16, 16, 16, 16,
49 16, 16, 16, 16, 16, 16, 16, 16,
50 16, 16, 16, 16, 16, 16, 16, 16,
51 16, 16, 16, 16, 16, 16, 16, 16,
52 16, 16, 16, 16, 16, 16, 16, 16,
53 16, 16, 16, 16, 16, 16, 16, 16,
56 static const uint16_t vlc_dc_lum_code[12] = {
57 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
59 static const unsigned char vlc_dc_lum_bits[12] = {
60 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
63 static const uint16_t vlc_dc_chroma_code[12] = {
64 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
66 static const unsigned char vlc_dc_chroma_bits[12] = {
67 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
70 static const uint16_t mpeg1_vlc[113][2] = {
71 { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
72 { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
73 { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
74 { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
75 { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
76 { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
77 { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
78 { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
79 { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
80 { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
81 { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
82 { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
83 { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
84 { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
85 { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
86 { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
87 { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
88 { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
89 { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
90 { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
91 { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
92 { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
93 { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
94 { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
95 { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
96 { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
97 { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
98 { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
99 { 0x1, 6 }, /* escape */
100 { 0x2, 2 }, /* EOB */
103 static const uint16_t mpeg2_vlc[113][2] = {
104 {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
105 {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
106 {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
107 {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
108 {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
109 {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
110 {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
111 {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
112 {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
113 {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
114 {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
115 {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
116 {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
117 {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
118 {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
119 {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
120 {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
121 {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
122 {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
123 {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
124 {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
125 {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
126 {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
127 {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
128 {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
129 {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
130 {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
131 {0x1d,16}, {0x1c,16}, {0x1b,16},
132 {0x01,6}, /* escape */
136 static const int8_t mpeg1_level[111] = {
137 1, 2, 3, 4, 5, 6, 7, 8,
138 9, 10, 11, 12, 13, 14, 15, 16,
139 17, 18, 19, 20, 21, 22, 23, 24,
140 25, 26, 27, 28, 29, 30, 31, 32,
141 33, 34, 35, 36, 37, 38, 39, 40,
142 1, 2, 3, 4, 5, 6, 7, 8,
143 9, 10, 11, 12, 13, 14, 15, 16,
144 17, 18, 1, 2, 3, 4, 5, 1,
145 2, 3, 4, 1, 2, 3, 1, 2,
146 3, 1, 2, 3, 1, 2, 1, 2,
147 1, 2, 1, 2, 1, 2, 1, 2,
148 1, 2, 1, 2, 1, 2, 1, 2,
149 1, 1, 1, 1, 1, 1, 1, 1,
153 static const int8_t mpeg1_run[111] = {
154 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0,
157 0, 0, 0, 0, 0, 0, 0, 0,
158 0, 0, 0, 0, 0, 0, 0, 0,
159 1, 1, 1, 1, 1, 1, 1, 1,
160 1, 1, 1, 1, 1, 1, 1, 1,
161 1, 1, 2, 2, 2, 2, 2, 3,
162 3, 3, 3, 4, 4, 4, 5, 5,
163 5, 6, 6, 6, 7, 7, 8, 8,
164 9, 9, 10, 10, 11, 11, 12, 12,
165 13, 13, 14, 14, 15, 15, 16, 16,
166 17, 18, 19, 20, 21, 22, 23, 24,
167 25, 26, 27, 28, 29, 30, 31,
170 static RLTable rl_mpeg1 = {
178 static RLTable rl_mpeg2 = {
186 static const uint8_t mbAddrIncrTable[36][2] = {
220 {0x8, 11}, /* escape */
221 {0xf, 11}, /* stuffing */
222 {0x0, 8}, /* end (and 15 more 0 bits should follow) */
225 static const uint8_t mbPatTable[64][2] = {
292 #define MB_TYPE_ZERO_MV 0x20000000
293 #define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV)
295 static const uint8_t table_mb_ptype[7][2] = {
296 { 3, 5 }, // 0x01 MB_INTRA
297 { 1, 2 }, // 0x02 MB_PAT
298 { 1, 3 }, // 0x08 MB_FOR
299 { 1, 1 }, // 0x0A MB_FOR|MB_PAT
300 { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
301 { 1, 5 }, // 0x12 MB_QUANT|MB_PAT
302 { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
305 static const uint32_t ptype2mb_type[7] = {
307 MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
309 MB_TYPE_L0 | MB_TYPE_CBP,
310 MB_TYPE_QUANT | MB_TYPE_INTRA,
311 MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
312 MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
315 static const uint8_t table_mb_btype[11][2] = {
316 { 3, 5 }, // 0x01 MB_INTRA
317 { 2, 3 }, // 0x04 MB_BACK
318 { 3, 3 }, // 0x06 MB_BACK|MB_PAT
319 { 2, 4 }, // 0x08 MB_FOR
320 { 3, 4 }, // 0x0A MB_FOR|MB_PAT
321 { 2, 2 }, // 0x0C MB_FOR|MB_BACK
322 { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
323 { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
324 { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
325 { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
326 { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
329 static const uint32_t btype2mb_type[11] = {
332 MB_TYPE_L1 | MB_TYPE_CBP,
334 MB_TYPE_L0 | MB_TYPE_CBP,
336 MB_TYPE_L0L1 | MB_TYPE_CBP,
337 MB_TYPE_QUANT | MB_TYPE_INTRA,
338 MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
339 MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
340 MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
343 static const uint8_t mbMotionVectorTable[17][2] = {
363 const AVRational ff_frame_rate_tab[] = {
375 // libmpeg3's "Unofficial economy rates": (10-13)
383 static const uint8_t non_linear_qscale[32] = {
384 0, 1, 2, 3, 4, 5, 6, 7,
385 8,10,12,14,16,18,20,22,
386 24,28,32,36,40,44,48,52,
387 56,64,72,80,88,96,104,112,
390 static const uint8_t inv_non_linear_qscale[13] = {
392 9,10,11,12,13,14,15,16,
395 const uint8_t ff_mpeg1_dc_scale_table[128]={
396 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
397 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
398 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
399 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
400 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
403 static const uint8_t mpeg2_dc_scale_table1[128]={
404 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
405 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
406 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
407 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
408 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
411 static const uint8_t mpeg2_dc_scale_table2[128]={
412 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
413 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
414 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
415 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
416 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
419 static const uint8_t mpeg2_dc_scale_table3[128]={
420 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
421 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
422 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
423 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
424 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
427 static const uint8_t *mpeg2_dc_scale_table[4]={
428 ff_mpeg1_dc_scale_table,
429 mpeg2_dc_scale_table1,
430 mpeg2_dc_scale_table2,
431 mpeg2_dc_scale_table3,
434 static const float mpeg1_aspect[16]={
455 static const AVRational mpeg2_aspect[16]={
474 static const uint8_t svcd_scan_offset_placeholder[14]={
482 #endif // AVCODEC_MPEG12DATA_H