changeset 1338:345585097137

mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
author arpi
date Mon, 16 Jul 2001 20:21:26 +0000
parents 421999eb6b9c
children bf2c01c5e9dc
files demux_mpg.c mplayer.c
diffstat 2 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/demux_mpg.c	Mon Jul 16 18:42:38 2001 +0000
+++ b/demux_mpg.c	Mon Jul 16 20:21:26 2001 +0000
@@ -237,6 +237,7 @@
 int num_elementary_packets100=0;
 int num_elementary_packets101=0;
 int num_elementary_packets1B6=0;
+int num_elementary_packetsPES=0;
 
 int demux_mpg_es_fill_buffer(demuxer_t *demux){
   // Elementary video stream
@@ -278,6 +279,14 @@
   if(verbose>=4) printf("*** head=0x%X\n",head);
   if(demux->synced==0){
     if(head==0x1BA) demux->synced=1;
+#if 0
+    else if(head>=0x1C0 && head<=0x1EF){
+      demux->synced=2;
+      if(verbose) printf("Mpeg PES stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos);
+      num_elementary_packets100=0; // requires for re-sync!
+      num_elementary_packets101=0; // requires for re-sync!
+    }
+#endif
   } else
   if(demux->synced==1){
     if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){
@@ -301,11 +310,15 @@
       if(head==0x101) ++num_elementary_packets101;
       if(verbose>=3) printf("Opps... elementary video packet found: %03X\n",head);
     } else
+    if(head>=0x1C0 && head<0x1F0){
+      ++num_elementary_packetsPES;
+      if(verbose>=3) printf("Opps... PES packet found: %03X\n",head);
+    } else
       if(head==0x1B6) ++num_elementary_packets1B6;
 #if 1
-    if(num_elementary_packets100>50 && num_elementary_packets101>50
-       && skipped>4000000){
-        if(verbose) printf("sync_mpeg_ps: seems to be ES stream...\n");
+    if( ( (num_elementary_packets100>50 && num_elementary_packets101>50) ||
+          (num_elementary_packetsPES>50) ) && skipped>4000000){
+        if(verbose) printf("sync_mpeg_ps: seems to be ES/PES stream...\n");
         demux->stream->eof=1;
         break;
     }
--- a/mplayer.c	Mon Jul 16 18:42:38 2001 +0000
+++ b/mplayer.c	Mon Jul 16 20:21:26 2001 +0000
@@ -187,6 +187,7 @@
 
 extern int num_elementary_packets100; // for MPEG-ES fileformat detection
 extern int num_elementary_packets101;
+extern int num_elementary_packetsPES;
 
 extern picture_t *picture;	// exported from libmpeg2/decode.c
 
@@ -707,16 +708,25 @@
 }
 //=============== Try to open as MPEG-PS file: =================
 if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MPEG_PS){
+ int pes=1;
+ while(pes>=0){
   stream_reset(stream);
   demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id,dvdsub_id);
   stream_seek(demuxer->stream,seek_to_byte);
+  if(!pes) demuxer->synced=1; // hack!
   if(ds_fill_buffer(demuxer->video)){
-    printf("Detected MPEG-PS file format!\n");
+    if(!pes)
+      printf("Detected MPEG-PES file format!\n");
+    else
+      printf("Detected MPEG-PS file format!\n");
     file_format=DEMUXER_TYPE_MPEG_PS;
   } else {
     // some hack to get meaningfull error messages to our unhappy users:
     if(num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
        abs(num_elementary_packets101-num_elementary_packets100)<8){
+      if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4){
+        --pes;continue; // tricky...
+      }
       file_format=DEMUXER_TYPE_MPEG_ES; //  <-- hack is here :)
     } else {
       if(demuxer->synced==2)
@@ -725,6 +735,8 @@
         printf("Not MPEG System Stream format... (maybe Transport Stream?)\n");
     }
   }
+  break;
+ }
 }
 //=============== Try to open as MPEG-ES file: =================
 if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!