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 <string.h>
24
27
29
33 }
34
36 {
38 av_first_parser = parser;
39 }
40
42 {
45 int ret;
46
49
50 for(parser = av_first_parser; parser !=
NULL; parser = parser->
next) {
56 goto found;
57 }
59 found:
61 if (!s)
62 goto err_out;
66 goto err_out;
71 if (ret != 0)
72 goto err_out;
73 }
79 return s;
80
81 err_out:
82 if (s)
86 }
87
89 int i;
90
98 // check disabled since MPEG-TS does not send complete PES packets
104 if(remove)
107 break;
108 }
109 }
110 }
111
114 uint8_t **poutbuf,
int *poutbuf_size,
115 const uint8_t *buf,
int buf_size,
116 int64_t pts, int64_t dts,
117 int64_t pos)
118 {
121
126 }
127
128 if (buf_size == 0) {
129 /* padding is always necessary even if EOF, so we add it here */
130 memset(dummy_buf, 0, sizeof(dummy_buf));
131 buf = dummy_buf;
134 /* add a new packet descriptor */
142 }
143
150 }
151
152 /* WARNING: the returned index can be negative */
154 /* update the file pointer */
155 if (*poutbuf_size) {
156 /* fill the data for the current frame */
158
159 /* offset of the next frame */
162 }
163 if (index < 0)
164 index = 0;
167 }
168
171 uint8_t **poutbuf,
int *poutbuf_size,
172 const uint8_t *buf,
int buf_size,
int keyframe){
173
177 buf += i;
178 buf_size -= i;
179 }
180 }
181
182 /* cast to avoid warning about discarding qualifiers */
184 *poutbuf_size= buf_size;
187 /*||(s->pict_type != AV_PICTURE_TYPE_I && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
188 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
192
195 return 1;
196 }
197 }
198
199 return 0;
200 }
201
203 {
204 if(s){
209 }
210 }
211
212 /*****************************************************/
213
215 {
217 av_dlog(
NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
219 av_dlog(
NULL,
"%X %X %X %X\n", (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
220 }
221
222 /* Copy overread bytes from last frame into buffer. */
225 }
226
227 /* flush remaining if EOF */
229 next= 0;
230 }
231
233
234 /* copy into buffer end return */
237
238 if(!new_buffer)
242 pc->
index += *buf_size;
243 return -1;
244 }
245
246 *buf_size=
248
249 /* append to buffer */
252
253 if(!new_buffer)
261 }
262
263 /* store overread bytes */
264 for(;next < 0; next++){
268 }
269
271 av_dlog(
NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
273 av_dlog(
NULL,
"%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
274 }
275
276 return 0;
277 }
278
280 {
282
284 }
285
286 /*************************/
287
289 const uint8_t *buf,
int buf_size)
290 {
291 int i;
293
294 for(i=0; i<buf_size; i++){
295 state= (state<<8) | buf[i];
296 if(state == 0x1B3 || state == 0x1B6)
297 return i-3;
298 }
299 return 0;
300 }