Libav 0.7.1
|
00001 /* 00002 * MPEG1/2 demuxer 00003 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include "avformat.h" 00023 #include "internal.h" 00024 #include "mpeg.h" 00025 00026 #undef NDEBUG 00027 #include <assert.h> 00028 00029 /*********************************************/ 00030 /* demux code */ 00031 00032 #define MAX_SYNC_SIZE 100000 00033 00034 static int check_pes(uint8_t *p, uint8_t *end){ 00035 int pes1; 00036 int pes2= (p[3] & 0xC0) == 0x80 00037 && (p[4] & 0xC0) != 0x40 00038 &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0)); 00039 00040 for(p+=3; p<end && *p == 0xFF; p++); 00041 if((*p&0xC0) == 0x40) p+=2; 00042 if((*p&0xF0) == 0x20){ 00043 pes1= p[0]&p[2]&p[4]&1; 00044 }else if((*p&0xF0) == 0x30){ 00045 pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1; 00046 }else 00047 pes1 = *p == 0x0F; 00048 00049 return pes1||pes2; 00050 } 00051 00052 static int mpegps_probe(AVProbeData *p) 00053 { 00054 uint32_t code= -1; 00055 int sys=0, pspack=0, priv1=0, vid=0, audio=0, invalid=0; 00056 int i; 00057 int score=0; 00058 00059 for(i=0; i<p->buf_size; i++){ 00060 code = (code<<8) + p->buf[i]; 00061 if ((code & 0xffffff00) == 0x100) { 00062 int len= p->buf[i+1] << 8 | p->buf[i+2]; 00063 int pes= check_pes(p->buf+i, p->buf+p->buf_size); 00064 00065 if(code == SYSTEM_HEADER_START_CODE) sys++; 00066 else if(code == PACK_START_CODE) pspack++; 00067 else if((code & 0xf0) == VIDEO_ID && pes) vid++; 00068 // skip pes payload to avoid start code emulation for private 00069 // and audio streams 00070 else if((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;} 00071 else if(code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;} 00072 00073 else if((code & 0xf0) == VIDEO_ID && !pes) invalid++; 00074 else if((code & 0xe0) == AUDIO_ID && !pes) invalid++; 00075 else if(code == PRIVATE_STREAM_1 && !pes) invalid++; 00076 } 00077 } 00078 00079 if(vid+audio > invalid) /* invalid VDR files nd short PES streams */ 00080 score= AVPROBE_SCORE_MAX/4; 00081 00082 //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size); 00083 if(sys>invalid && sys*9 <= pspack*10) 00084 return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg 00085 if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9) 00086 return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg 00087 if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048 && vid + audio > invalid) /* PES stream */ 00088 return (audio > 12 || vid > 3) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; 00089 00090 //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1 00091 //mp3_misidentified_2.mp3 has sys:0 priv1:0 pspack:0 vid:0 audio:6 00092 return score; 00093 } 00094 00095 00096 typedef struct MpegDemuxContext { 00097 int32_t header_state; 00098 unsigned char psm_es_type[256]; 00099 int sofdec; 00100 } MpegDemuxContext; 00101 00102 static int mpegps_read_header(AVFormatContext *s, 00103 AVFormatParameters *ap) 00104 { 00105 MpegDemuxContext *m = s->priv_data; 00106 const char *sofdec = "Sofdec"; 00107 int v, i = 0; 00108 00109 m->header_state = 0xff; 00110 s->ctx_flags |= AVFMTCTX_NOHEADER; 00111 00112 m->sofdec = -1; 00113 do { 00114 v = avio_r8(s->pb); 00115 m->header_state = m->header_state << 8 | v; 00116 m->sofdec++; 00117 } while (v == sofdec[i] && i++ < 6); 00118 00119 m->sofdec = (m->sofdec == 6) ? 1 : 0; 00120 00121 /* no need to do more */ 00122 return 0; 00123 } 00124 00125 static int64_t get_pts(AVIOContext *pb, int c) 00126 { 00127 uint8_t buf[5]; 00128 00129 buf[0] = c<0 ? avio_r8(pb) : c; 00130 avio_read(pb, buf+1, 4); 00131 00132 return ff_parse_pes_pts(buf); 00133 } 00134 00135 static int find_next_start_code(AVIOContext *pb, int *size_ptr, 00136 int32_t *header_state) 00137 { 00138 unsigned int state, v; 00139 int val, n; 00140 00141 state = *header_state; 00142 n = *size_ptr; 00143 while (n > 0) { 00144 if (pb->eof_reached) 00145 break; 00146 v = avio_r8(pb); 00147 n--; 00148 if (state == 0x000001) { 00149 state = ((state << 8) | v) & 0xffffff; 00150 val = state; 00151 goto found; 00152 } 00153 state = ((state << 8) | v) & 0xffffff; 00154 } 00155 val = -1; 00156 found: 00157 *header_state = state; 00158 *size_ptr = n; 00159 return val; 00160 } 00161 00162 #if 0 /* unused, remove? */ 00163 /* XXX: optimize */ 00164 static int find_prev_start_code(AVIOContext *pb, int *size_ptr) 00165 { 00166 int64_t pos, pos_start; 00167 int max_size, start_code; 00168 00169 max_size = *size_ptr; 00170 pos_start = avio_tell(pb); 00171 00172 /* in order to go faster, we fill the buffer */ 00173 pos = pos_start - 16386; 00174 if (pos < 0) 00175 pos = 0; 00176 avio_seek(pb, pos, SEEK_SET); 00177 avio_r8(pb); 00178 00179 pos = pos_start; 00180 for(;;) { 00181 pos--; 00182 if (pos < 0 || (pos_start - pos) >= max_size) { 00183 start_code = -1; 00184 goto the_end; 00185 } 00186 avio_seek(pb, pos, SEEK_SET); 00187 start_code = avio_rb32(pb); 00188 if ((start_code & 0xffffff00) == 0x100) 00189 break; 00190 } 00191 the_end: 00192 *size_ptr = pos_start - pos; 00193 return start_code; 00194 } 00195 #endif 00196 00203 static long mpegps_psm_parse(MpegDemuxContext *m, AVIOContext *pb) 00204 { 00205 int psm_length, ps_info_length, es_map_length; 00206 00207 psm_length = avio_rb16(pb); 00208 avio_r8(pb); 00209 avio_r8(pb); 00210 ps_info_length = avio_rb16(pb); 00211 00212 /* skip program_stream_info */ 00213 avio_skip(pb, ps_info_length); 00214 es_map_length = avio_rb16(pb); 00215 00216 /* at least one es available? */ 00217 while (es_map_length >= 4){ 00218 unsigned char type = avio_r8(pb); 00219 unsigned char es_id = avio_r8(pb); 00220 uint16_t es_info_length = avio_rb16(pb); 00221 /* remember mapping from stream id to stream type */ 00222 m->psm_es_type[es_id] = type; 00223 /* skip program_stream_info */ 00224 avio_skip(pb, es_info_length); 00225 es_map_length -= 4 + es_info_length; 00226 } 00227 avio_rb32(pb); /* crc32 */ 00228 return 2 + psm_length; 00229 } 00230 00231 /* read the next PES header. Return its position in ppos 00232 (if not NULL), and its start code, pts and dts. 00233 */ 00234 static int mpegps_read_pes_header(AVFormatContext *s, 00235 int64_t *ppos, int *pstart_code, 00236 int64_t *ppts, int64_t *pdts) 00237 { 00238 MpegDemuxContext *m = s->priv_data; 00239 int len, size, startcode, c, flags, header_len; 00240 int pes_ext, ext2_len, id_ext, skip; 00241 int64_t pts, dts; 00242 int64_t last_sync= avio_tell(s->pb); 00243 00244 error_redo: 00245 avio_seek(s->pb, last_sync, SEEK_SET); 00246 redo: 00247 /* next start code (should be immediately after) */ 00248 m->header_state = 0xff; 00249 size = MAX_SYNC_SIZE; 00250 startcode = find_next_start_code(s->pb, &size, &m->header_state); 00251 last_sync = avio_tell(s->pb); 00252 //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb)); 00253 if (startcode < 0){ 00254 if(s->pb->eof_reached) 00255 return AVERROR_EOF; 00256 //FIXME we should remember header_state 00257 return AVERROR(EAGAIN); 00258 } 00259 00260 if (startcode == PACK_START_CODE) 00261 goto redo; 00262 if (startcode == SYSTEM_HEADER_START_CODE) 00263 goto redo; 00264 if (startcode == PADDING_STREAM) { 00265 avio_skip(s->pb, avio_rb16(s->pb)); 00266 goto redo; 00267 } 00268 if (startcode == PRIVATE_STREAM_2) { 00269 len = avio_rb16(s->pb); 00270 if (!m->sofdec) { 00271 while (len-- >= 6) { 00272 if (avio_r8(s->pb) == 'S') { 00273 uint8_t buf[5]; 00274 avio_read(s->pb, buf, sizeof(buf)); 00275 m->sofdec = !memcmp(buf, "ofdec", 5); 00276 len -= sizeof(buf); 00277 break; 00278 } 00279 } 00280 m->sofdec -= !m->sofdec; 00281 } 00282 avio_skip(s->pb, len); 00283 goto redo; 00284 } 00285 if (startcode == PROGRAM_STREAM_MAP) { 00286 mpegps_psm_parse(m, s->pb); 00287 goto redo; 00288 } 00289 00290 /* find matching stream */ 00291 if (!((startcode >= 0x1c0 && startcode <= 0x1df) || 00292 (startcode >= 0x1e0 && startcode <= 0x1ef) || 00293 (startcode == 0x1bd) || (startcode == 0x1fd))) 00294 goto redo; 00295 if (ppos) { 00296 *ppos = avio_tell(s->pb) - 4; 00297 } 00298 len = avio_rb16(s->pb); 00299 pts = 00300 dts = AV_NOPTS_VALUE; 00301 /* stuffing */ 00302 for(;;) { 00303 if (len < 1) 00304 goto error_redo; 00305 c = avio_r8(s->pb); 00306 len--; 00307 /* XXX: for mpeg1, should test only bit 7 */ 00308 if (c != 0xff) 00309 break; 00310 } 00311 if ((c & 0xc0) == 0x40) { 00312 /* buffer scale & size */ 00313 avio_r8(s->pb); 00314 c = avio_r8(s->pb); 00315 len -= 2; 00316 } 00317 if ((c & 0xe0) == 0x20) { 00318 dts = pts = get_pts(s->pb, c); 00319 len -= 4; 00320 if (c & 0x10){ 00321 dts = get_pts(s->pb, -1); 00322 len -= 5; 00323 } 00324 } else if ((c & 0xc0) == 0x80) { 00325 /* mpeg 2 PES */ 00326 #if 0 /* some streams have this field set for no apparent reason */ 00327 if ((c & 0x30) != 0) { 00328 /* Encrypted multiplex not handled */ 00329 goto redo; 00330 } 00331 #endif 00332 flags = avio_r8(s->pb); 00333 header_len = avio_r8(s->pb); 00334 len -= 2; 00335 if (header_len > len) 00336 goto error_redo; 00337 len -= header_len; 00338 if (flags & 0x80) { 00339 dts = pts = get_pts(s->pb, -1); 00340 header_len -= 5; 00341 if (flags & 0x40) { 00342 dts = get_pts(s->pb, -1); 00343 header_len -= 5; 00344 } 00345 } 00346 if (flags & 0x3f && header_len == 0){ 00347 flags &= 0xC0; 00348 av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n"); 00349 } 00350 if (flags & 0x01) { /* PES extension */ 00351 pes_ext = avio_r8(s->pb); 00352 header_len--; 00353 /* Skip PES private data, program packet sequence counter and P-STD buffer */ 00354 skip = (pes_ext >> 4) & 0xb; 00355 skip += skip & 0x9; 00356 if (pes_ext & 0x40 || skip > header_len){ 00357 av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext); 00358 pes_ext=skip=0; 00359 } 00360 avio_skip(s->pb, skip); 00361 header_len -= skip; 00362 00363 if (pes_ext & 0x01) { /* PES extension 2 */ 00364 ext2_len = avio_r8(s->pb); 00365 header_len--; 00366 if ((ext2_len & 0x7f) > 0) { 00367 id_ext = avio_r8(s->pb); 00368 if ((id_ext & 0x80) == 0) 00369 startcode = ((startcode & 0xff) << 8) | id_ext; 00370 header_len--; 00371 } 00372 } 00373 } 00374 if(header_len < 0) 00375 goto error_redo; 00376 avio_skip(s->pb, header_len); 00377 } 00378 else if( c!= 0xf ) 00379 goto redo; 00380 00381 if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) { 00382 startcode = avio_r8(s->pb); 00383 len--; 00384 if (startcode >= 0x80 && startcode <= 0xcf) { 00385 /* audio: skip header */ 00386 avio_r8(s->pb); 00387 avio_r8(s->pb); 00388 avio_r8(s->pb); 00389 len -= 3; 00390 if (startcode >= 0xb0 && startcode <= 0xbf) { 00391 /* MLP/TrueHD audio has a 4-byte header */ 00392 avio_r8(s->pb); 00393 len--; 00394 } 00395 } 00396 } 00397 if(len<0) 00398 goto error_redo; 00399 if(dts != AV_NOPTS_VALUE && ppos){ 00400 int i; 00401 for(i=0; i<s->nb_streams; i++){ 00402 if(startcode == s->streams[i]->id && 00403 s->pb->seekable /* index useless on streams anyway */) { 00404 ff_reduce_index(s, i); 00405 av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); 00406 } 00407 } 00408 } 00409 00410 *pstart_code = startcode; 00411 *ppts = pts; 00412 *pdts = dts; 00413 return len; 00414 } 00415 00416 static int mpegps_read_packet(AVFormatContext *s, 00417 AVPacket *pkt) 00418 { 00419 MpegDemuxContext *m = s->priv_data; 00420 AVStream *st; 00421 int len, startcode, i, es_type, ret; 00422 enum CodecID codec_id = CODEC_ID_NONE; 00423 enum AVMediaType type; 00424 int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work 00425 uint8_t av_uninit(dvdaudio_substream_type); 00426 00427 redo: 00428 len = mpegps_read_pes_header(s, &dummy_pos, &startcode, &pts, &dts); 00429 if (len < 0) 00430 return len; 00431 00432 if(startcode == 0x1bd) { 00433 dvdaudio_substream_type = avio_r8(s->pb); 00434 avio_skip(s->pb, 3); 00435 len -= 4; 00436 } 00437 00438 /* now find stream */ 00439 for(i=0;i<s->nb_streams;i++) { 00440 st = s->streams[i]; 00441 if (st->id == startcode) 00442 goto found; 00443 } 00444 00445 es_type = m->psm_es_type[startcode & 0xff]; 00446 if(es_type > 0 && es_type != STREAM_TYPE_PRIVATE_DATA){ 00447 if(es_type == STREAM_TYPE_VIDEO_MPEG1){ 00448 codec_id = CODEC_ID_MPEG2VIDEO; 00449 type = AVMEDIA_TYPE_VIDEO; 00450 } else if(es_type == STREAM_TYPE_VIDEO_MPEG2){ 00451 codec_id = CODEC_ID_MPEG2VIDEO; 00452 type = AVMEDIA_TYPE_VIDEO; 00453 } else if(es_type == STREAM_TYPE_AUDIO_MPEG1 || 00454 es_type == STREAM_TYPE_AUDIO_MPEG2){ 00455 codec_id = CODEC_ID_MP3; 00456 type = AVMEDIA_TYPE_AUDIO; 00457 } else if(es_type == STREAM_TYPE_AUDIO_AAC){ 00458 codec_id = CODEC_ID_AAC; 00459 type = AVMEDIA_TYPE_AUDIO; 00460 } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){ 00461 codec_id = CODEC_ID_MPEG4; 00462 type = AVMEDIA_TYPE_VIDEO; 00463 } else if(es_type == STREAM_TYPE_VIDEO_H264){ 00464 codec_id = CODEC_ID_H264; 00465 type = AVMEDIA_TYPE_VIDEO; 00466 } else if(es_type == STREAM_TYPE_AUDIO_AC3){ 00467 codec_id = CODEC_ID_AC3; 00468 type = AVMEDIA_TYPE_AUDIO; 00469 } else { 00470 goto skip; 00471 } 00472 } else if (startcode >= 0x1e0 && startcode <= 0x1ef) { 00473 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; 00474 unsigned char buf[8]; 00475 avio_read(s->pb, buf, 8); 00476 avio_seek(s->pb, -8, SEEK_CUR); 00477 if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) 00478 codec_id = CODEC_ID_CAVS; 00479 else 00480 codec_id = CODEC_ID_PROBE; 00481 type = AVMEDIA_TYPE_VIDEO; 00482 } else if (startcode >= 0x1c0 && startcode <= 0x1df) { 00483 type = AVMEDIA_TYPE_AUDIO; 00484 codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2; 00485 } else if (startcode >= 0x80 && startcode <= 0x87) { 00486 type = AVMEDIA_TYPE_AUDIO; 00487 codec_id = CODEC_ID_AC3; 00488 } else if ( ( startcode >= 0x88 && startcode <= 0x8f) 00489 ||( startcode >= 0x98 && startcode <= 0x9f)) { 00490 /* 0x90 - 0x97 is reserved for SDDS in DVD specs */ 00491 type = AVMEDIA_TYPE_AUDIO; 00492 codec_id = CODEC_ID_DTS; 00493 } else if (startcode >= 0xa0 && startcode <= 0xaf) { 00494 type = AVMEDIA_TYPE_AUDIO; 00495 /* 16 bit form will be handled as CODEC_ID_PCM_S16BE */ 00496 codec_id = CODEC_ID_PCM_DVD; 00497 } else if (startcode >= 0xb0 && startcode <= 0xbf) { 00498 type = AVMEDIA_TYPE_AUDIO; 00499 codec_id = CODEC_ID_TRUEHD; 00500 } else if (startcode >= 0xc0 && startcode <= 0xcf) { 00501 /* Used for both AC-3 and E-AC-3 in EVOB files */ 00502 type = AVMEDIA_TYPE_AUDIO; 00503 codec_id = CODEC_ID_AC3; 00504 } else if (startcode >= 0x20 && startcode <= 0x3f) { 00505 type = AVMEDIA_TYPE_SUBTITLE; 00506 codec_id = CODEC_ID_DVD_SUBTITLE; 00507 } else if (startcode >= 0xfd55 && startcode <= 0xfd5f) { 00508 type = AVMEDIA_TYPE_VIDEO; 00509 codec_id = CODEC_ID_VC1; 00510 } else if (startcode == 0x1bd) { 00511 // check dvd audio substream type 00512 type = AVMEDIA_TYPE_AUDIO; 00513 switch(dvdaudio_substream_type & 0xe0) { 00514 case 0xa0: codec_id = CODEC_ID_PCM_DVD; 00515 break; 00516 case 0x80: if((dvdaudio_substream_type & 0xf8) == 0x88) 00517 codec_id = CODEC_ID_DTS; 00518 else codec_id = CODEC_ID_AC3; 00519 break; 00520 default: av_log(s, AV_LOG_ERROR, "Unknown 0x1bd sub-stream\n"); 00521 goto skip; 00522 } 00523 } else { 00524 skip: 00525 /* skip packet */ 00526 avio_skip(s->pb, len); 00527 goto redo; 00528 } 00529 /* no stream found: add a new stream */ 00530 st = av_new_stream(s, startcode); 00531 if (!st) 00532 goto skip; 00533 st->codec->codec_type = type; 00534 st->codec->codec_id = codec_id; 00535 if (codec_id != CODEC_ID_PCM_S16BE) 00536 st->need_parsing = AVSTREAM_PARSE_FULL; 00537 found: 00538 if(st->discard >= AVDISCARD_ALL) 00539 goto skip; 00540 if ((startcode >= 0xa0 && startcode <= 0xaf) || 00541 (startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) { 00542 int b1, freq; 00543 00544 /* for LPCM, we just skip the header and consider it is raw 00545 audio data */ 00546 if (len <= 3) 00547 goto skip; 00548 avio_r8(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */ 00549 b1 = avio_r8(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */ 00550 avio_r8(s->pb); /* dynamic range control (0x80 = off) */ 00551 len -= 3; 00552 freq = (b1 >> 4) & 3; 00553 st->codec->sample_rate = lpcm_freq_tab[freq]; 00554 st->codec->channels = 1 + (b1 & 7); 00555 st->codec->bits_per_coded_sample = 16 + ((b1 >> 6) & 3) * 4; 00556 st->codec->bit_rate = st->codec->channels * 00557 st->codec->sample_rate * 00558 st->codec->bits_per_coded_sample; 00559 if (st->codec->bits_per_coded_sample == 16) 00560 st->codec->codec_id = CODEC_ID_PCM_S16BE; 00561 else if (st->codec->bits_per_coded_sample == 28) 00562 return AVERROR(EINVAL); 00563 } 00564 ret = av_get_packet(s->pb, pkt, len); 00565 pkt->pts = pts; 00566 pkt->dts = dts; 00567 pkt->pos = dummy_pos; 00568 pkt->stream_index = st->index; 00569 av_dlog(s, "%d: pts=%0.3f dts=%0.3f size=%d\n", 00570 pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, 00571 pkt->size); 00572 00573 return (ret < 0) ? ret : 0; 00574 } 00575 00576 static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, 00577 int64_t *ppos, int64_t pos_limit) 00578 { 00579 int len, startcode; 00580 int64_t pos, pts, dts; 00581 00582 pos = *ppos; 00583 if (avio_seek(s->pb, pos, SEEK_SET) < 0) 00584 return AV_NOPTS_VALUE; 00585 00586 for(;;) { 00587 len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts); 00588 if (len < 0) { 00589 av_dlog(s, "none (ret=%d)\n", len); 00590 return AV_NOPTS_VALUE; 00591 } 00592 if (startcode == s->streams[stream_index]->id && 00593 dts != AV_NOPTS_VALUE) { 00594 break; 00595 } 00596 avio_skip(s->pb, len); 00597 } 00598 av_dlog(s, "pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n", 00599 pos, dts, dts / 90000.0); 00600 *ppos = pos; 00601 return dts; 00602 } 00603 00604 AVInputFormat ff_mpegps_demuxer = { 00605 "mpeg", 00606 NULL_IF_CONFIG_SMALL("MPEG-PS format"), 00607 sizeof(MpegDemuxContext), 00608 mpegps_probe, 00609 mpegps_read_header, 00610 mpegps_read_packet, 00611 NULL, 00612 NULL, //mpegps_read_seek, 00613 mpegps_read_dts, 00614 .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, 00615 };