1 /*
2 * MPEG-1/2 decoder
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 /**
24 * @file
25 * MPEG-1/2 decoder
26 */
27
28 #define UNCHECKED_BITSTREAM_READER 1
29
33
46
48
49 #define INIT_2D_VLC_RL(rl, static_size)\
50 {\
51 static RL_VLC_ELEM rl_vlc_table[static_size];\
52 INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
53 &rl.table_vlc[0][1], 4, 2,\
54 &rl.table_vlc[0][0], 4, 2, static_size);\
55 \
56 rl.rl_vlc[0] = rl_vlc_table;\
57 init_2d_vlc_rl(&rl);\
58 }
59
61 {
62 int i;
63
68
69 if (len == 0) { // illegal code
70 run = 65;
72 } else if (len<0) { //more bits needed
73 run = 0;
74 level = code;
75 } else {
76 if (code == rl->
n) {
//esc
77 run = 65;
78 level = 0;
79 }
else if (code == rl->
n+1) {
//eob
80 run = 0;
81 level = 127;
82 } else {
85 }
86 }
90 }
91 }
92
94 {
95
98
99 }
100
102 {
107 }
108
109
110 /******************************************/
111 /* decoding */
112
114
117
122
124 {
125 static int done = 0;
126
127 if (!done) {
128 done = 1;
129
145
154
157 }
158 }
159
160 /**
161 * Find the end of the current frame in the bitstream.
162 * @return the position of the first byte of the next frame, or -1
163 */
165 {
166 int i;
168
169 /* EOF considered as end of frame */
170 if (buf_size == 0)
171 return 0;
172
173 /*
174 0 frame start -> 1/4
175 1 first_SEQEXT -> 0/2
176 2 first field start -> 3/0
177 3 second_SEQEXT -> 2/0
178 4 searching end
179 */
180
181 for (i = 0; i < buf_size; i++) {
187 if ((buf[i] & 3) == 3)
189 else
191 }
192 state++;
193 } else {
196 i++;
198 }
202 return i+1;
203 }
212 return i - 3;
213 }
214 }
217 }
218 }
219 }
222 }
223