[Mplayer-cvslog] CVS: main/libmpdemux demux_mpg.c,1.47,1.48 demuxer.c,1.138,1.139 demuxer.h,1.57,1.58 video.c,1.38,1.39

Michael Niedermayer CVS michael at mplayerhq.hu
Fri Apr 4 17:38:57 CEST 2003


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv906

Modified Files:
	demux_mpg.c demuxer.c demuxer.h video.c 
Log Message:
H264-ES demuxer


Index: demux_mpg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_mpg.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- demux_mpg.c	23 Jan 2003 02:12:15 -0000	1.47
+++ demux_mpg.c	4 Apr 2003 15:38:46 -0000	1.48
@@ -250,6 +250,14 @@
 int num_elementary_packets12x=0;
 int num_elementary_packets1B6=0;
 int num_elementary_packetsPES=0;
+int num_h264_slice=0; //combined slice
+int num_h264_dpa=0; //DPA Slice
+int num_h264_dpb=0; //DPB Slice
+int num_h264_dpc=0; //DPC Slice
+int num_h264_idr=0; //IDR Slice
+int num_h264_sps=0;
+int num_h264_pps=0;
+
 int num_mp3audio_packets=0;
 
 int demux_mpg_es_fill_buffer(demuxer_t *demux){
@@ -317,6 +325,15 @@
       if(head==0x100) ++num_elementary_packets100; else
       if(head==0x101) ++num_elementary_packets101; else
       if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x;
+      
+      if((head&~0x60) == 0x101) ++num_h264_slice; else
+      if((head&~0x60) == 0x102) ++num_h264_dpa; else
+      if((head&~0x60) == 0x103) ++num_h264_dpb; else
+      if((head&~0x60) == 0x104) ++num_h264_dpc; else
+      if((head&~0x60) == 0x105 && head != 0x105) ++num_h264_idr; else
+      if((head&~0x60) == 0x107 && head != 0x107) ++num_h264_sps; else
+      if((head&~0x60) == 0x108 && head != 0x108) ++num_h264_pps;
+      
       mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head);
     } else
     if((head>=0x1C0 && head<0x1F0) || head==0x1BD){

Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -r1.138 -r1.139
--- demuxer.c	30 Mar 2003 17:12:11 -0000	1.138
+++ demuxer.c	4 Apr 2003 15:38:46 -0000	1.139
@@ -303,6 +303,7 @@
     case DEMUXER_TYPE_BMP: return demux_bmp_fill_buffer(demux);
     case DEMUXER_TYPE_FLI: return demux_fli_fill_buffer(demux);
     case DEMUXER_TYPE_MPEG4_ES:
+    case DEMUXER_TYPE_H264_ES:
     case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux);
     case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux);
     case DEMUXER_TYPE_AVI: return demux_avi_fill_buffer(demux);
@@ -518,6 +519,13 @@
 extern int num_elementary_packetsPES;
 extern int num_elementary_packets1B6;
 extern int num_elementary_packets12x;
+extern int num_h264_slice; //combined slice
+extern int num_h264_dpa; //DPA Slice
+extern int num_h264_dpb; //DPB Slice
+extern int num_h264_dpc; //DPC Slice
+extern int num_h264_idr; //IDR Slice
+extern int num_h264_sps;
+extern int num_h264_pps;
 extern int num_mp3audio_packets;
 
 // commandline options, flags:
@@ -855,6 +863,13 @@
   num_elementary_packets1B6=0;
   num_elementary_packets12x=0;
   num_elementary_packetsPES=0;
+  num_h264_slice=0; //combined slice
+  num_h264_dpa=0; //DPA Slice
+  num_h264_dpb=0; //DPB Slice
+  num_h264_dpc=0; //DPC Slice
+  num_h264_idr=0; //IDR Slice
+  num_h264_sps=0;
+  num_h264_pps=0;
   num_mp3audio_packets=0;
 
   if(ds_fill_buffer(demuxer->video)){
@@ -864,9 +879,13 @@
       mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,"MPEG-PS");
     file_format=DEMUXER_TYPE_MPEG_PS;
   } else {
-    mp_msg(MSGT_DEMUX,MSGL_V,"MPEG packet stats: p100: %d  p101: %d p1B6: %d p12x: %d PES: %d  MP3: %d \n",
+    mp_msg(MSGT_DEMUX,MSGL_V,"MPEG packet stats: p100: %d  p101: %d p1B6: %d p12x: %d sli: %d a: %d b: %d c: %d idr: %d sps: %d pps: %d PES: %d  MP3: %d \n",
 	num_elementary_packets100,num_elementary_packets101,
 	num_elementary_packets1B6,num_elementary_packets12x,
+	num_h264_slice, num_h264_dpa,
+	num_h264_dpb, num_h264_dpc=0,
+	num_h264_idr,  num_h264_sps=0,
+	num_h264_pps,
 	num_elementary_packetsPES,num_mp3audio_packets);
 //MPEG packet stats: p100: 458  p101: 458  PES: 0  MP3: 1103  (.m2v)
     if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100
@@ -888,6 +907,15 @@
       file_format=DEMUXER_TYPE_MPEG4_ES;
     } else
 #endif
+#if 1
+    // fuzzy h264-es detection. do NOT enable without heavy testing of mpeg formats detection!
+    if(num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3) && 
+       num_h264_sps>=1 && num_h264_pps>=1 /*&& num_h264_idr>=1*/ &&
+       num_elementary_packets1B6==0 && num_elementary_packetsPES==0 &&
+       demuxer->synced<2){
+      file_format=DEMUXER_TYPE_H264_ES;
+    } else
+#endif
     {
       if(demuxer->synced==2)
         mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug);
@@ -901,7 +929,7 @@
  }
 }
 //=============== Try to open as MPEG-ES file: =================
-if(file_format==DEMUXER_TYPE_MPEG_ES || file_format==DEMUXER_TYPE_MPEG4_ES){ // little hack, see above!
+if(file_format==DEMUXER_TYPE_MPEG_ES || file_format==DEMUXER_TYPE_MPEG4_ES  || file_format==DEMUXER_TYPE_H264_ES){ // little hack, see above!
   demuxer=new_demuxer(stream,file_format,audio_id,video_id,dvdsub_id);
   if(!ds_fill_buffer(demuxer->video)){
     mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_InvalidMPEGES);
@@ -909,7 +937,14 @@
     free_demuxer(demuxer);
     demuxer = NULL;
   } else {
-    mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,(file_format==DEMUXER_TYPE_MPEG_ES)?"MPEG-ES":"MPEG4-ES");
+    switch(file_format){
+    case DEMUXER_TYPE_MPEG_ES: 
+        mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat, "MPEG-ES"); break;
+    case DEMUXER_TYPE_MPEG4_ES: 
+        mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat, "MPEG4-ES"); break;
+    case DEMUXER_TYPE_H264_ES: 
+        mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat, "H264-ES"); break;
+    }
   }
 }
 #ifdef HAVE_LIBDV095
@@ -1102,6 +1137,7 @@
   }
   break;
  }
+ case DEMUXER_TYPE_H264_ES:
  case DEMUXER_TYPE_MPEG4_ES:
  case DEMUXER_TYPE_MPEG_ES: {
    sh_audio=NULL;   // ES streams has no audio channel
@@ -1287,6 +1323,7 @@
   case DEMUXER_TYPE_ASF:
       demux_seek_asf(demuxer,rel_seek_secs,flags);  break;
   
+  case DEMUXER_TYPE_H264_ES:
   case DEMUXER_TYPE_MPEG4_ES:
   case DEMUXER_TYPE_MPEG_ES:
   case DEMUXER_TYPE_MPEG_PS:

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- demuxer.h	16 Mar 2003 20:13:28 -0000	1.57
+++ demuxer.h	4 Apr 2003 15:38:46 -0000	1.58
@@ -38,11 +38,12 @@
 #define DEMUXER_TYPE_MPEG4_ES 27
 #define DEMUXER_TYPE_GIF 28
 #define DEMUXER_TYPE_MPEG_TS 29
+#define DEMUXER_TYPE_H264_ES 30
 
 // This should always match the higest demuxer type number.
 // Unless you want to disallow users to force the demuxer to some types
 #define DEMUXER_TYPE_MIN 0
-#define DEMUXER_TYPE_MAX 29
+#define DEMUXER_TYPE_MAX 30
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code

Index: video.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/video.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- video.c	26 Mar 2003 15:49:10 -0000	1.38
+++ video.c	4 Apr 2003 15:38:46 -0000	1.39
@@ -126,6 +126,46 @@
    sh_video->format=0x10000004;
    break;
  }
+ case DEMUXER_TYPE_H264_ES: {
+   videobuf_len=0; videobuf_code_len=0;
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence parameter set... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      if((i&~0x60) == 0x107 && i != 0x107) break; // found it!
+      if(!i || !skip_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
+   if(!videobuffer) videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE);
+   if(!videobuffer){ 
+     mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
+     return 0;
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for picture parameter set... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      printf("0x%X\n",i);
+      if((i&~0x60) == 0x108 && i != 0x108) break; // found it!
+      if(!i || !read_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\nSearching for Slice... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105) break; // found it!
+      if(!i || !read_video_packet(d_video)){
+        mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
+	return 0;
+      }
+   }
+   mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
+   sh_video->format=0x10000005;
+   break;
+ }
 #ifdef STREAMING_LIVE_DOT_COM
  case DEMUXER_TYPE_RTP:
    // If the RTP stream is a MPEG stream, then we use this code to check
@@ -367,6 +407,16 @@
           int i=sync_video_packet(d_video);
           if(!read_video_packet(d_video)) return -1; // EOF
 	  if(i==0x1B6) break;
+        }
+	*start=videobuffer; in_size=videobuf_len;
+	videobuf_len=0;
+
+  } else if(demuxer->file_format==DEMUXER_TYPE_H264_ES){
+      //
+        while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
+          int i=sync_video_packet(d_video);
+          if(!read_video_packet(d_video)) return -1; // EOF
+          if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105) break;
         }
 	*start=videobuffer; in_size=videobuf_len;
 	videobuf_len=0;



More information about the MPlayer-cvslog mailing list