1 /*
2 * VC-1 and WMV3 parser
3 * Copyright (c) 2006-2007 Konstantin Shishkov
4 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
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 * VC-1 and WMV3 parser
26 */
27
32
33 /** The maximum number of bytes of a sequence, entry point or
34 * frame header whose values we pay any attention to */
35 #define UNESCAPED_THRESHOLD 37
36
37 /** The maximum number of bytes of a sequence, entry point or
38 * frame header which must be valid memory (because they are
39 * used to update the bitstream cache in skip_bits() calls)
40 */
41 #define UNESCAPED_LIMIT 144
42
49
59
61 const uint8_t *buf, int buf_size)
62 {
63 /* Parse the header we just finished unescaping */
73 break;
76 break;
80 else
82
84 break;
85
86 /* keep AV_PICTURE_TYPE_BI internal to VC1 */
89 else
91
93 // process pulldown flags
95 // Pulldown flags are only valid when 'broadcast' has been set.
96 // So ticks_per_frame will be 2
98 // repeat field
101 // repeat frames
102 s->repeat_pict = vpc->
v.
rptfrm * 2 + 1;
103 }
104 }else{
106 }
107
110 else
112
113 break;
114 }
124 }
125 }
126
129 const uint8_t **poutbuf, int *poutbuf_size,
130 const uint8_t *buf, int buf_size)
131 {
132 /* Here we do the searching for frame boundaries and headers at
133 * the same time. Only a minimal amount at the start of each
134 * header is unescaped. */
140 int start_code_found = 0;
143
144 if (pic_found && buf_size == 0) {
145 /* EOF considered as end of frame */
148 next = 0;
149 }
150 while (
i < buf_size) {
152 start_code_found = 0;
155 unesc_buffer[unesc_index++] =
b;
157 search_state =
b ?
NO_MATCH : search_state + 1;
163 unesc_index--; // swallow emulation prevention byte
165 }
166 }
167 else { // search_state == ONE
168 // Header unescaping terminates early due to detection of next start code
170 start_code_found = 1;
171 break;
172 }
173 }
177 {
178 // No need to keep scanning the rest of the buffer for
179 // start codes if we know it contains a complete frame and
180 // we've already unescaped all we need of the frame header
182 break;
183 }
185 while (
i < buf_size) {
190 }
192 } else {
199 }
200 else { // search_state == ONE
202 start_code_found = 1;
203 break;
204 }
205 }
206 }
207 }
208 if (start_code_found) {
210
212 unesc_index = 0;
213
216 pic_found = 1;
217 }
221 break;
222 }
223 }
224 }
225 }
226
230
232 next = buf_size;
233 } else {
237 *poutbuf_size = 0;
238 return buf_size;
239 }
240 }
241
242 /* If we return with a valid pointer to a combined frame buffer
243 * then on the next call then we'll have been unhelpfully rewound
244 * by up to 4 bytes (depending upon whether the start code
245 * overlapped the input buffer, and if so by how much). We don't
246 * want this: it will either cause spurious second detections of
247 * the start code we've already seen, or cause extra bytes to be
248 * inserted at the start of the unescaped buffer. */
252
253 *poutbuf = buf;
254 *poutbuf_size = buf_size;
255 return next;
256 }
257
259 {
268 return 0;
269 }
270
277 };