You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

619 lines
19KB

  1. /*
  2. * MPEG1/2 demuxer
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "internal.h"
  23. #include "mpeg.h"
  24. #undef NDEBUG
  25. #include <assert.h>
  26. /*********************************************/
  27. /* demux code */
  28. #define MAX_SYNC_SIZE 100000
  29. static int check_pes(uint8_t *p, uint8_t *end){
  30. int pes1;
  31. int pes2= (p[3] & 0xC0) == 0x80
  32. && (p[4] & 0xC0) != 0x40
  33. &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0));
  34. for(p+=3; p<end && *p == 0xFF; p++);
  35. if((*p&0xC0) == 0x40) p+=2;
  36. if((*p&0xF0) == 0x20){
  37. pes1= p[0]&p[2]&p[4]&1;
  38. }else if((*p&0xF0) == 0x30){
  39. pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1;
  40. }else
  41. pes1 = *p == 0x0F;
  42. return pes1||pes2;
  43. }
  44. static int mpegps_probe(AVProbeData *p)
  45. {
  46. uint32_t code= -1;
  47. int sys=0, pspack=0, priv1=0, vid=0, audio=0, invalid=0;
  48. int i;
  49. int score=0;
  50. for(i=0; i<p->buf_size; i++){
  51. code = (code<<8) + p->buf[i];
  52. if ((code & 0xffffff00) == 0x100) {
  53. int len= p->buf[i+1] << 8 | p->buf[i+2];
  54. int pes= check_pes(p->buf+i, p->buf+p->buf_size);
  55. if(code == SYSTEM_HEADER_START_CODE) sys++;
  56. else if(code == PACK_START_CODE) pspack++;
  57. else if((code & 0xf0) == VIDEO_ID && pes) vid++;
  58. // skip pes payload to avoid start code emulation for private
  59. // and audio streams
  60. else if((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;}
  61. else if(code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;}
  62. else if(code == 0x1fd && pes) vid++; //VC1
  63. else if((code & 0xf0) == VIDEO_ID && !pes) invalid++;
  64. else if((code & 0xe0) == AUDIO_ID && !pes) invalid++;
  65. else if(code == PRIVATE_STREAM_1 && !pes) invalid++;
  66. }
  67. }
  68. if(vid+audio > invalid+1) /* invalid VDR files nd short PES streams */
  69. score= AVPROBE_SCORE_MAX/4;
  70. //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size);
  71. if(sys>invalid && sys*9 <= pspack*10)
  72. return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
  73. if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9)
  74. return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
  75. if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048 && vid + audio > invalid) /* PES stream */
  76. return (audio > 12 || vid > 3) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4;
  77. //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
  78. //mp3_misidentified_2.mp3 has sys:0 priv1:0 pspack:0 vid:0 audio:6
  79. return score;
  80. }
  81. typedef struct MpegDemuxContext {
  82. int32_t header_state;
  83. unsigned char psm_es_type[256];
  84. int sofdec;
  85. } MpegDemuxContext;
  86. static int mpegps_read_header(AVFormatContext *s,
  87. AVFormatParameters *ap)
  88. {
  89. MpegDemuxContext *m = s->priv_data;
  90. const char *sofdec = "Sofdec";
  91. int v, i = 0;
  92. m->header_state = 0xff;
  93. s->ctx_flags |= AVFMTCTX_NOHEADER;
  94. m->sofdec = -1;
  95. do {
  96. v = avio_r8(s->pb);
  97. m->header_state = m->header_state << 8 | v;
  98. m->sofdec++;
  99. } while (v == sofdec[i] && i++ < 6);
  100. m->sofdec = (m->sofdec == 6) ? 1 : 0;
  101. /* no need to do more */
  102. return 0;
  103. }
  104. static int64_t get_pts(AVIOContext *pb, int c)
  105. {
  106. uint8_t buf[5];
  107. buf[0] = c<0 ? avio_r8(pb) : c;
  108. avio_read(pb, buf+1, 4);
  109. return ff_parse_pes_pts(buf);
  110. }
  111. static int find_next_start_code(AVIOContext *pb, int *size_ptr,
  112. int32_t *header_state)
  113. {
  114. unsigned int state, v;
  115. int val, n;
  116. state = *header_state;
  117. n = *size_ptr;
  118. while (n > 0) {
  119. if (url_feof(pb))
  120. break;
  121. v = avio_r8(pb);
  122. n--;
  123. if (state == 0x000001) {
  124. state = ((state << 8) | v) & 0xffffff;
  125. val = state;
  126. goto found;
  127. }
  128. state = ((state << 8) | v) & 0xffffff;
  129. }
  130. val = -1;
  131. found:
  132. *header_state = state;
  133. *size_ptr = n;
  134. return val;
  135. }
  136. #if 0 /* unused, remove? */
  137. /* XXX: optimize */
  138. static int find_prev_start_code(AVIOContext *pb, int *size_ptr)
  139. {
  140. int64_t pos, pos_start;
  141. int max_size, start_code;
  142. max_size = *size_ptr;
  143. pos_start = avio_tell(pb);
  144. /* in order to go faster, we fill the buffer */
  145. pos = pos_start - 16386;
  146. if (pos < 0)
  147. pos = 0;
  148. avio_seek(pb, pos, SEEK_SET);
  149. avio_r8(pb);
  150. pos = pos_start;
  151. for(;;) {
  152. pos--;
  153. if (pos < 0 || (pos_start - pos) >= max_size) {
  154. start_code = -1;
  155. goto the_end;
  156. }
  157. avio_seek(pb, pos, SEEK_SET);
  158. start_code = avio_rb32(pb);
  159. if ((start_code & 0xffffff00) == 0x100)
  160. break;
  161. }
  162. the_end:
  163. *size_ptr = pos_start - pos;
  164. return start_code;
  165. }
  166. #endif
  167. /**
  168. * Extract stream types from a program stream map
  169. * According to ISO/IEC 13818-1 ('MPEG-2 Systems') table 2-35
  170. *
  171. * @return number of bytes occupied by PSM in the bitstream
  172. */
  173. static long mpegps_psm_parse(MpegDemuxContext *m, AVIOContext *pb)
  174. {
  175. int psm_length, ps_info_length, es_map_length;
  176. psm_length = avio_rb16(pb);
  177. avio_r8(pb);
  178. avio_r8(pb);
  179. ps_info_length = avio_rb16(pb);
  180. /* skip program_stream_info */
  181. avio_skip(pb, ps_info_length);
  182. es_map_length = avio_rb16(pb);
  183. /* at least one es available? */
  184. while (es_map_length >= 4){
  185. unsigned char type = avio_r8(pb);
  186. unsigned char es_id = avio_r8(pb);
  187. uint16_t es_info_length = avio_rb16(pb);
  188. /* remember mapping from stream id to stream type */
  189. m->psm_es_type[es_id] = type;
  190. /* skip program_stream_info */
  191. avio_skip(pb, es_info_length);
  192. es_map_length -= 4 + es_info_length;
  193. }
  194. avio_rb32(pb); /* crc32 */
  195. return 2 + psm_length;
  196. }
  197. /* read the next PES header. Return its position in ppos
  198. (if not NULL), and its start code, pts and dts.
  199. */
  200. static int mpegps_read_pes_header(AVFormatContext *s,
  201. int64_t *ppos, int *pstart_code,
  202. int64_t *ppts, int64_t *pdts)
  203. {
  204. MpegDemuxContext *m = s->priv_data;
  205. int len, size, startcode, c, flags, header_len;
  206. int pes_ext, ext2_len, id_ext, skip;
  207. int64_t pts, dts;
  208. int64_t last_sync= avio_tell(s->pb);
  209. error_redo:
  210. avio_seek(s->pb, last_sync, SEEK_SET);
  211. redo:
  212. /* next start code (should be immediately after) */
  213. m->header_state = 0xff;
  214. size = MAX_SYNC_SIZE;
  215. startcode = find_next_start_code(s->pb, &size, &m->header_state);
  216. last_sync = avio_tell(s->pb);
  217. //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb));
  218. if (startcode < 0){
  219. if(url_feof(s->pb))
  220. return AVERROR_EOF;
  221. //FIXME we should remember header_state
  222. return AVERROR(EAGAIN);
  223. }
  224. if (startcode == PACK_START_CODE)
  225. goto redo;
  226. if (startcode == SYSTEM_HEADER_START_CODE)
  227. goto redo;
  228. if (startcode == PADDING_STREAM) {
  229. avio_skip(s->pb, avio_rb16(s->pb));
  230. goto redo;
  231. }
  232. if (startcode == PRIVATE_STREAM_2) {
  233. len = avio_rb16(s->pb);
  234. if (!m->sofdec) {
  235. while (len-- >= 6) {
  236. if (avio_r8(s->pb) == 'S') {
  237. uint8_t buf[5];
  238. avio_read(s->pb, buf, sizeof(buf));
  239. m->sofdec = !memcmp(buf, "ofdec", 5);
  240. len -= sizeof(buf);
  241. break;
  242. }
  243. }
  244. m->sofdec -= !m->sofdec;
  245. }
  246. avio_skip(s->pb, len);
  247. goto redo;
  248. }
  249. if (startcode == PROGRAM_STREAM_MAP) {
  250. mpegps_psm_parse(m, s->pb);
  251. goto redo;
  252. }
  253. /* find matching stream */
  254. if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
  255. (startcode >= 0x1e0 && startcode <= 0x1ef) ||
  256. (startcode == 0x1bd) || (startcode == 0x1fd)))
  257. goto redo;
  258. if (ppos) {
  259. *ppos = avio_tell(s->pb) - 4;
  260. }
  261. len = avio_rb16(s->pb);
  262. pts =
  263. dts = AV_NOPTS_VALUE;
  264. /* stuffing */
  265. for(;;) {
  266. if (len < 1)
  267. goto error_redo;
  268. c = avio_r8(s->pb);
  269. len--;
  270. /* XXX: for mpeg1, should test only bit 7 */
  271. if (c != 0xff)
  272. break;
  273. }
  274. if ((c & 0xc0) == 0x40) {
  275. /* buffer scale & size */
  276. avio_r8(s->pb);
  277. c = avio_r8(s->pb);
  278. len -= 2;
  279. }
  280. if ((c & 0xe0) == 0x20) {
  281. dts = pts = get_pts(s->pb, c);
  282. len -= 4;
  283. if (c & 0x10){
  284. dts = get_pts(s->pb, -1);
  285. len -= 5;
  286. }
  287. } else if ((c & 0xc0) == 0x80) {
  288. /* mpeg 2 PES */
  289. #if 0 /* some streams have this field set for no apparent reason */
  290. if ((c & 0x30) != 0) {
  291. /* Encrypted multiplex not handled */
  292. goto redo;
  293. }
  294. #endif
  295. flags = avio_r8(s->pb);
  296. header_len = avio_r8(s->pb);
  297. len -= 2;
  298. if (header_len > len)
  299. goto error_redo;
  300. len -= header_len;
  301. if (flags & 0x80) {
  302. dts = pts = get_pts(s->pb, -1);
  303. header_len -= 5;
  304. if (flags & 0x40) {
  305. dts = get_pts(s->pb, -1);
  306. header_len -= 5;
  307. }
  308. }
  309. if (flags & 0x3f && header_len == 0){
  310. flags &= 0xC0;
  311. av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n");
  312. }
  313. if (flags & 0x01) { /* PES extension */
  314. pes_ext = avio_r8(s->pb);
  315. header_len--;
  316. /* Skip PES private data, program packet sequence counter and P-STD buffer */
  317. skip = (pes_ext >> 4) & 0xb;
  318. skip += skip & 0x9;
  319. if (pes_ext & 0x40 || skip > header_len){
  320. av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext);
  321. pes_ext=skip=0;
  322. }
  323. avio_skip(s->pb, skip);
  324. header_len -= skip;
  325. if (pes_ext & 0x01) { /* PES extension 2 */
  326. ext2_len = avio_r8(s->pb);
  327. header_len--;
  328. if ((ext2_len & 0x7f) > 0) {
  329. id_ext = avio_r8(s->pb);
  330. if ((id_ext & 0x80) == 0)
  331. startcode = ((startcode & 0xff) << 8) | id_ext;
  332. header_len--;
  333. }
  334. }
  335. }
  336. if(header_len < 0)
  337. goto error_redo;
  338. avio_skip(s->pb, header_len);
  339. }
  340. else if( c!= 0xf )
  341. goto redo;
  342. if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {
  343. startcode = avio_r8(s->pb);
  344. len--;
  345. if (startcode >= 0x80 && startcode <= 0xcf) {
  346. /* audio: skip header */
  347. avio_r8(s->pb);
  348. avio_r8(s->pb);
  349. avio_r8(s->pb);
  350. len -= 3;
  351. if (startcode >= 0xb0 && startcode <= 0xbf) {
  352. /* MLP/TrueHD audio has a 4-byte header */
  353. avio_r8(s->pb);
  354. len--;
  355. }
  356. }
  357. }
  358. if(len<0)
  359. goto error_redo;
  360. if(dts != AV_NOPTS_VALUE && ppos){
  361. int i;
  362. for(i=0; i<s->nb_streams; i++){
  363. if(startcode == s->streams[i]->id &&
  364. s->pb->seekable /* index useless on streams anyway */) {
  365. ff_reduce_index(s, i);
  366. av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
  367. }
  368. }
  369. }
  370. *pstart_code = startcode;
  371. *ppts = pts;
  372. *pdts = dts;
  373. return len;
  374. }
  375. static int mpegps_read_packet(AVFormatContext *s,
  376. AVPacket *pkt)
  377. {
  378. MpegDemuxContext *m = s->priv_data;
  379. AVStream *st;
  380. int len, startcode, i, es_type;
  381. int request_probe= 0;
  382. enum CodecID codec_id = CODEC_ID_NONE;
  383. enum AVMediaType type;
  384. int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work
  385. uint8_t av_uninit(dvdaudio_substream_type);
  386. redo:
  387. len = mpegps_read_pes_header(s, &dummy_pos, &startcode, &pts, &dts);
  388. if (len < 0)
  389. return len;
  390. if(startcode == 0x1bd) {
  391. dvdaudio_substream_type = avio_r8(s->pb);
  392. avio_skip(s->pb, 3);
  393. len -= 4;
  394. }
  395. /* now find stream */
  396. for(i=0;i<s->nb_streams;i++) {
  397. st = s->streams[i];
  398. if (st->id == startcode)
  399. goto found;
  400. }
  401. es_type = m->psm_es_type[startcode & 0xff];
  402. if(es_type > 0 && es_type != STREAM_TYPE_PRIVATE_DATA){
  403. if(es_type == STREAM_TYPE_VIDEO_MPEG1){
  404. codec_id = CODEC_ID_MPEG2VIDEO;
  405. type = AVMEDIA_TYPE_VIDEO;
  406. } else if(es_type == STREAM_TYPE_VIDEO_MPEG2){
  407. codec_id = CODEC_ID_MPEG2VIDEO;
  408. type = AVMEDIA_TYPE_VIDEO;
  409. } else if(es_type == STREAM_TYPE_AUDIO_MPEG1 ||
  410. es_type == STREAM_TYPE_AUDIO_MPEG2){
  411. codec_id = CODEC_ID_MP3;
  412. type = AVMEDIA_TYPE_AUDIO;
  413. } else if(es_type == STREAM_TYPE_AUDIO_AAC){
  414. codec_id = CODEC_ID_AAC;
  415. type = AVMEDIA_TYPE_AUDIO;
  416. } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){
  417. codec_id = CODEC_ID_MPEG4;
  418. type = AVMEDIA_TYPE_VIDEO;
  419. } else if(es_type == STREAM_TYPE_VIDEO_H264){
  420. codec_id = CODEC_ID_H264;
  421. type = AVMEDIA_TYPE_VIDEO;
  422. } else if(es_type == STREAM_TYPE_AUDIO_AC3){
  423. codec_id = CODEC_ID_AC3;
  424. type = AVMEDIA_TYPE_AUDIO;
  425. } else {
  426. goto skip;
  427. }
  428. } else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
  429. static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
  430. unsigned char buf[8];
  431. avio_read(s->pb, buf, 8);
  432. avio_seek(s->pb, -8, SEEK_CUR);
  433. if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
  434. codec_id = CODEC_ID_CAVS;
  435. else
  436. request_probe= 1;
  437. type = AVMEDIA_TYPE_VIDEO;
  438. } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
  439. type = AVMEDIA_TYPE_AUDIO;
  440. codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2;
  441. } else if (startcode >= 0x80 && startcode <= 0x87) {
  442. type = AVMEDIA_TYPE_AUDIO;
  443. codec_id = CODEC_ID_AC3;
  444. } else if ( ( startcode >= 0x88 && startcode <= 0x8f)
  445. ||( startcode >= 0x98 && startcode <= 0x9f)) {
  446. /* 0x90 - 0x97 is reserved for SDDS in DVD specs */
  447. type = AVMEDIA_TYPE_AUDIO;
  448. codec_id = CODEC_ID_DTS;
  449. } else if (startcode >= 0xa0 && startcode <= 0xaf) {
  450. type = AVMEDIA_TYPE_AUDIO;
  451. /* 16 bit form will be handled as CODEC_ID_PCM_S16BE */
  452. codec_id = CODEC_ID_PCM_DVD;
  453. } else if (startcode >= 0xb0 && startcode <= 0xbf) {
  454. type = AVMEDIA_TYPE_AUDIO;
  455. codec_id = CODEC_ID_TRUEHD;
  456. } else if (startcode >= 0xc0 && startcode <= 0xcf) {
  457. /* Used for both AC-3 and E-AC-3 in EVOB files */
  458. type = AVMEDIA_TYPE_AUDIO;
  459. codec_id = CODEC_ID_AC3;
  460. } else if (startcode >= 0x20 && startcode <= 0x3f) {
  461. type = AVMEDIA_TYPE_SUBTITLE;
  462. codec_id = CODEC_ID_DVD_SUBTITLE;
  463. } else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
  464. type = AVMEDIA_TYPE_VIDEO;
  465. codec_id = CODEC_ID_VC1;
  466. } else if (startcode == 0x1bd) {
  467. // check dvd audio substream type
  468. type = AVMEDIA_TYPE_AUDIO;
  469. switch(dvdaudio_substream_type & 0xe0) {
  470. case 0xa0: codec_id = CODEC_ID_PCM_DVD;
  471. break;
  472. case 0x80: if((dvdaudio_substream_type & 0xf8) == 0x88)
  473. codec_id = CODEC_ID_DTS;
  474. else codec_id = CODEC_ID_AC3;
  475. break;
  476. default: av_log(s, AV_LOG_ERROR, "Unknown 0x1bd sub-stream\n");
  477. goto skip;
  478. }
  479. } else {
  480. skip:
  481. /* skip packet */
  482. avio_skip(s->pb, len);
  483. goto redo;
  484. }
  485. /* no stream found: add a new stream */
  486. st = av_new_stream(s, startcode);
  487. if (!st)
  488. goto skip;
  489. st->codec->codec_type = type;
  490. st->codec->codec_id = codec_id;
  491. st->request_probe = request_probe;
  492. if (codec_id != CODEC_ID_PCM_S16BE)
  493. st->need_parsing = AVSTREAM_PARSE_FULL;
  494. found:
  495. if(st->discard >= AVDISCARD_ALL)
  496. goto skip;
  497. if ((startcode >= 0xa0 && startcode <= 0xaf) ||
  498. (startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) {
  499. int b1, freq;
  500. /* for LPCM, we just skip the header and consider it is raw
  501. audio data */
  502. if (len <= 3)
  503. goto skip;
  504. avio_r8(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */
  505. b1 = avio_r8(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */
  506. avio_r8(s->pb); /* dynamic range control (0x80 = off) */
  507. len -= 3;
  508. freq = (b1 >> 4) & 3;
  509. st->codec->sample_rate = lpcm_freq_tab[freq];
  510. st->codec->channels = 1 + (b1 & 7);
  511. st->codec->bits_per_coded_sample = 16 + ((b1 >> 6) & 3) * 4;
  512. st->codec->bit_rate = st->codec->channels *
  513. st->codec->sample_rate *
  514. st->codec->bits_per_coded_sample;
  515. if (st->codec->bits_per_coded_sample == 16)
  516. st->codec->codec_id = CODEC_ID_PCM_S16BE;
  517. else if (st->codec->bits_per_coded_sample == 28)
  518. return AVERROR(EINVAL);
  519. }
  520. av_new_packet(pkt, len);
  521. avio_read(s->pb, pkt->data, pkt->size);
  522. pkt->pts = pts;
  523. pkt->dts = dts;
  524. pkt->pos = dummy_pos;
  525. pkt->stream_index = st->index;
  526. av_dlog(s, "%d: pts=%0.3f dts=%0.3f size=%d\n",
  527. pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0,
  528. pkt->size);
  529. return 0;
  530. }
  531. static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,
  532. int64_t *ppos, int64_t pos_limit)
  533. {
  534. int len, startcode;
  535. int64_t pos, pts, dts;
  536. pos = *ppos;
  537. if (avio_seek(s->pb, pos, SEEK_SET) < 0)
  538. return AV_NOPTS_VALUE;
  539. for(;;) {
  540. len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts);
  541. if (len < 0) {
  542. av_dlog(s, "none (ret=%d)\n", len);
  543. return AV_NOPTS_VALUE;
  544. }
  545. if (startcode == s->streams[stream_index]->id &&
  546. dts != AV_NOPTS_VALUE) {
  547. break;
  548. }
  549. avio_skip(s->pb, len);
  550. }
  551. av_dlog(s, "pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n",
  552. pos, dts, dts / 90000.0);
  553. *ppos = pos;
  554. return dts;
  555. }
  556. AVInputFormat ff_mpegps_demuxer = {
  557. .name = "mpeg",
  558. .long_name = NULL_IF_CONFIG_SMALL("MPEG-PS format"),
  559. .priv_data_size = sizeof(MpegDemuxContext),
  560. .read_probe = mpegps_probe,
  561. .read_header = mpegps_read_header,
  562. .read_packet = mpegps_read_packet,
  563. .read_seek = NULL, //mpegps_read_seek,
  564. .read_timestamp = mpegps_read_dts,
  565. .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
  566. };