1 /*
2 * Audio and Video frame extraction
3 * Copyright (c) 2003 Fabrice Bellard
4 * Copyright (c) 2003 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 #include <stdint.h>
24 #include <string.h>
25
28
30
32
34 {
35 if (p)
37 else
39 }
40
42 {
43 do {
46 }
47
49 {
53
55 return NULL;
56
57 for (parser = av_first_parser; parser; parser = parser->
next) {
63 goto found;
64 }
65 return NULL;
66
67 found:
69 if (!s)
70 goto err_out;
74 goto err_out;
79 if (ret != 0)
80 goto err_out;
81 }
88
89 err_out:
90 if (s)
93 return NULL;
94 }
95
97 {
98 int i;
99
108 // check disabled since MPEG-TS does not send complete PES packets
110
115 if (remove)
117 if (s->
cur_offset + off < s->cur_frame_end[i])
118 break;
119 }
120 }
121 }
122
124 uint8_t **poutbuf,
int *poutbuf_size,
126 int64_t pts, int64_t dts, int64_t pos)
127 {
130
135 }
136
137 if (buf_size == 0) {
138 /* padding is always necessary even if EOF, so we add it here */
139 memset(dummy_buf, 0, sizeof(dummy_buf));
140 buf = dummy_buf;
142 /* add a new packet descriptor */
150 }
151
158 }
159 /* WARNING: the returned index can be negative */
161 poutbuf_size, buf, buf_size);
162 /* update the file pointer */
163 if (*poutbuf_size) {
164 /* fill the data for the current frame */
166
167 /* offset of the next frame */
170 }
171 if (index < 0)
172 index = 0;
175 }
176
178 uint8_t **poutbuf,
int *poutbuf_size,
179 const uint8_t *
buf,
int buf_size,
int keyframe)
180 {
185 buf += i;
186 buf_size -= i;
187 }
188 }
189
190 /* cast to avoid warning about discarding qualifiers */
192 *poutbuf_size = buf_size;
196
197 *poutbuf_size =
size;
199
203 return 1;
204 }
205 }
206
207 return 0;
208 }
209
211 {
212 if (s) {
217 }
218 }
219
222 {
224 av_dlog(NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
227 (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
228 }
229
230 /* Copy overread bytes from last frame into buffer. */
233
234 /* flush remaining if EOF */
236 next = 0;
237
239
240 /* copy into buffer end return */
243 *buf_size + pc->
index +
245
246 if (!new_buffer) {
249 }
252 pc->
index += *buf_size;
253 return -1;
254 }
255
256 *buf_size =
258
259 /* append to buffer */
264 if (!new_buffer) {
268 }
275 }
276
277 /* store overread bytes */
278 for (; next < 0; next++) {
282 }
283
285 av_dlog(NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
288 (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
289 }
290
291 return 0;
292 }
293
295 {
297
299 }
300
302 {
303 int i;
305
306 for (i = 0; i < buf_size; i++) {
307 state = state << 8 | buf[i];
308 if (state == 0x1B3 || state == 0x1B6)
309 return i - 3;
310 }
311 return 0;
312 }