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 #include "mpeg12data.h"
30 const uint16_t ff_mpeg1_default_intra_matrix[64] = {
31 8, 16, 19, 22, 26, 27, 29, 34,
32 16, 16, 22, 24, 27, 29, 34, 37,
33 19, 22, 26, 27, 29, 34, 34, 38,
34 22, 22, 26, 27, 29, 34, 37, 40,
35 22, 26, 27, 29, 32, 35, 40, 48,
36 26, 27, 29, 32, 35, 40, 48, 58,
37 26, 27, 29, 34, 38, 46, 56, 69,
38 27, 29, 35, 38, 46, 56, 69, 83
41 const uint16_t ff_mpeg1_default_non_intra_matrix[64] = {
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 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,
52 const uint16_t ff_mpeg12_vlc_dc_lum_code[12] = {
53 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
55 const unsigned char ff_mpeg12_vlc_dc_lum_bits[12] = {
56 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
59 const uint16_t ff_mpeg12_vlc_dc_chroma_code[12] = {
60 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
62 const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12] = {
63 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
66 static const uint16_t mpeg1_vlc[113][2] = {
67 { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
68 { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
69 { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
70 { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
71 { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
72 { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
73 { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
74 { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
75 { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
76 { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
77 { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
78 { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
79 { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
80 { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
81 { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
82 { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
83 { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
84 { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
85 { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
86 { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
87 { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
88 { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
89 { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
90 { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
91 { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
92 { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
93 { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
94 { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
95 { 0x1, 6 }, /* escape */
99 static const uint16_t mpeg2_vlc[113][2] = {
100 {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
101 {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
102 {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
103 {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
104 {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
105 {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
106 {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
107 {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
108 {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
109 {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
110 {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
111 {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
112 {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
113 {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
114 {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
115 {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
116 {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
117 {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
118 {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
119 {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
120 {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
121 {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
122 {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
123 {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
124 {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
125 {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
126 {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
127 {0x1d,16}, {0x1c,16}, {0x1b,16},
128 {0x01,6}, /* escape */
132 static const int8_t mpeg1_level[111] = {
133 1, 2, 3, 4, 5, 6, 7, 8,
134 9, 10, 11, 12, 13, 14, 15, 16,
135 17, 18, 19, 20, 21, 22, 23, 24,
136 25, 26, 27, 28, 29, 30, 31, 32,
137 33, 34, 35, 36, 37, 38, 39, 40,
138 1, 2, 3, 4, 5, 6, 7, 8,
139 9, 10, 11, 12, 13, 14, 15, 16,
140 17, 18, 1, 2, 3, 4, 5, 1,
141 2, 3, 4, 1, 2, 3, 1, 2,
142 3, 1, 2, 3, 1, 2, 1, 2,
143 1, 2, 1, 2, 1, 2, 1, 2,
144 1, 2, 1, 2, 1, 2, 1, 2,
145 1, 1, 1, 1, 1, 1, 1, 1,
149 static const int8_t mpeg1_run[111] = {
150 0, 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0,
155 1, 1, 1, 1, 1, 1, 1, 1,
156 1, 1, 1, 1, 1, 1, 1, 1,
157 1, 1, 2, 2, 2, 2, 2, 3,
158 3, 3, 3, 4, 4, 4, 5, 5,
159 5, 6, 6, 6, 7, 7, 8, 8,
160 9, 9, 10, 10, 11, 11, 12, 12,
161 13, 13, 14, 14, 15, 15, 16, 16,
162 17, 18, 19, 20, 21, 22, 23, 24,
163 25, 26, 27, 28, 29, 30, 31,
166 RLTable ff_rl_mpeg1 = {
174 RLTable ff_rl_mpeg2 = {
182 const uint8_t ff_mpeg12_mbAddrIncrTable[36][2] = {
216 {0x8, 11}, /* escape */
217 {0xf, 11}, /* stuffing */
218 {0x0, 8}, /* end (and 15 more 0 bits should follow) */
221 const uint8_t ff_mpeg12_mbPatTable[64][2] = {
288 const uint8_t ff_mpeg12_mbMotionVectorTable[17][2] = {
308 const AVRational ff_frame_rate_tab[] = {
320 // libmpeg3's "Unofficial economy rates": (10-13)
328 const float ff_mpeg1_aspect[16]={
349 const AVRational ff_mpeg2_aspect[16]={