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
28
30
34 }
35
37 {
38 do {
41 }
42
44 {
48
50 return NULL;
51
52 for(parser = av_first_parser; parser != NULL; parser = parser->
next) {
58 goto found;
59 }
60 return NULL;
61 found:
63 if (!s)
64 goto err_out;
68 goto err_out;
73 if (ret != 0)
74 goto err_out;
75 }
82
83 err_out:
84 if (s)
87 return NULL;
88 }
89
91 int i;
92
100 // check disabled since MPEG-TS does not send complete PES packets
106 if(remove)
109 break;
110 }
111 }
112 }
113
116 uint8_t **poutbuf,
int *poutbuf_size,
118 int64_t pts, int64_t dts,
119 int64_t pos)
120 {
123
128 }
129
130 if (buf_size == 0) {
131 /* padding is always necessary even if EOF, so we add it here */
132 memset(dummy_buf, 0, sizeof(dummy_buf));
133 buf = dummy_buf;
136 /* add a new packet descriptor */
144 }
145
152 }
153
154 /* WARNING: the returned index can be negative */
156 /* update the file pointer */
157 if (*poutbuf_size) {
158 /* fill the data for the current frame */
160
161 /* offset of the next frame */
164 }
165 if (index < 0)
166 index = 0;
169 }
170
173 uint8_t **poutbuf,
int *poutbuf_size,
174 const uint8_t *
buf,
int buf_size,
int keyframe){
175
179 buf += i;
180 buf_size -= i;
181 }
182 }
183
184 /* cast to avoid warning about discarding qualifiers */
186 *poutbuf_size= buf_size;
189 /*||(s->pict_type != AV_PICTURE_TYPE_I && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/
190 /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){
194
197 return 1;
198 }
199 }
200
201 return 0;
202 }
203
205 {
206 if(s){
211 }
212 }
213
214 /*****************************************************/
215
217 {
219 av_dlog(NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
221 av_dlog(NULL,
"%X %X %X %X\n", (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]);
222 }
223
224 /* Copy overread bytes from last frame into buffer. */
227 }
228
229 /* flush remaining if EOF */
231 next= 0;
232 }
233
235
236 /* copy into buffer end return */
239
240 if(!new_buffer)
244 pc->
index += *buf_size;
245 return -1;
246 }
247
248 *buf_size=
250
251 /* append to buffer */
254
255 if(!new_buffer)
263 }
264
265 /* store overread bytes */
266 for(;next < 0; next++){
270 }
271
273 av_dlog(NULL,
"overread %d, state:%X next:%d index:%d o_index:%d\n",
275 av_dlog(NULL,
"%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
276 }
277
278 return 0;
279 }
280
282 {
284
286 }
287
288 /*************************/
289
292 {
293 int i;
295
296 for(i=0; i<buf_size; i++){
297 state= (state<<8) | buf[i];
298 if(state == 0x1B3 || state == 0x1B6)
299 return i-3;
300 }
301 return 0;
302 }