comparison mpegts.c @ 4986:b9c3d05b3267 libavformat

add streams even if they are not present in PMT, fix #1092 and #835
author bcoudurier
date Sun, 31 May 2009 03:55:23 +0000
parents 59bf27420396
children 62bf51efe6ec
comparison
equal deleted inserted replaced
4985:59bf27420396 4986:b9c3d05b3267
538 return; 538 return;
539 } 539 }
540 } 540 }
541 } 541 }
542 542
543 static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc) 543 static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint32_t code)
544 { 544 {
545 AVStream *st = av_new_stream(pes->stream, pes->pid); 545 AVStream *st = av_new_stream(pes->stream, pes->pid);
546 546
547 if (!st) 547 if (!st)
548 return NULL; 548 return NULL;
561 if (prog_reg_desc == AV_RL32("HDMV") && 561 if (prog_reg_desc == AV_RL32("HDMV") &&
562 st->codec->codec_id == CODEC_ID_PROBE) 562 st->codec->codec_id == CODEC_ID_PROBE)
563 mpegts_find_stream_type(st, pes->stream_type, HDMV_types); 563 mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
564 if (st->codec->codec_id == CODEC_ID_PROBE) 564 if (st->codec->codec_id == CODEC_ID_PROBE)
565 mpegts_find_stream_type(st, pes->stream_type, MISC_types); 565 mpegts_find_stream_type(st, pes->stream_type, MISC_types);
566
567 /* stream was not present in PMT, guess based on PES start code */
568 if (st->codec->codec_id == CODEC_ID_PROBE) {
569 if (code >= 0x1c0 && code <= 0x1df) {
570 st->codec->codec_type = CODEC_TYPE_AUDIO;
571 st->codec->codec_id = CODEC_ID_MP2;
572 } else if (code == 0x1bd) {
573 st->codec->codec_type = CODEC_TYPE_AUDIO;
574 st->codec->codec_id = CODEC_ID_AC3;
575 }
576 }
566 577
567 return st; 578 return st;
568 } 579 }
569 580
570 static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) 581 static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
640 st = pes->st; 651 st = pes->st;
641 } else { 652 } else {
642 if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably 653 if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably
643 pes = add_pes_stream(ts, pid, pcr_pid, stream_type); 654 pes = add_pes_stream(ts, pid, pcr_pid, stream_type);
644 if (pes) 655 if (pes)
645 st = new_pes_av_stream(pes, prog_reg_desc); 656 st = new_pes_av_stream(pes, prog_reg_desc, 0);
646 } 657 }
647 658
648 if (!st) 659 if (!st)
649 return; 660 return;
650 661
908 #endif 919 #endif
909 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && 920 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
910 pes->header[2] == 0x01) { 921 pes->header[2] == 0x01) {
911 /* it must be an mpeg2 PES stream */ 922 /* it must be an mpeg2 PES stream */
912 code = pes->header[3] | 0x100; 923 code = pes->header[3] | 0x100;
913 if (!pes->st || pes->st->discard == AVDISCARD_ALL || 924
925 /* stream not present in PMT */
926 if (!pes->st)
927 pes->st = new_pes_av_stream(pes, 0, code);
928 if (!pes->st)
929 return AVERROR(ENOMEM);
930
931 if (pes->st->discard == AVDISCARD_ALL ||
914 !((code >= 0x1c0 && code <= 0x1df) || 932 !((code >= 0x1c0 && code <= 0x1df) ||
915 (code >= 0x1e0 && code <= 0x1ef) || 933 (code >= 0x1e0 && code <= 0x1ef) ||
916 (code == 0x1bd) || (code == 0x1fd))) 934 (code == 0x1bd) || (code == 0x1fd)))
917 goto skip; 935 goto skip;
918 pes->state = MPEGTS_PESHEADER_FILL; 936 pes->state = MPEGTS_PESHEADER_FILL;