[MPlayer-dev-eng] [PATCH] MPEG-ES in GXF demuxer

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Thu Aug 25 17:51:50 CEST 2005


Hi,
On Thu, Aug 25, 2005 at 04:49:40PM +0200, Nico Sabbi wrote:
> Rich Felker wrote:
> >>because otherwise -dumpvideo will dump the content you want to discard, 
> >>and
> >>the result will be a corrupt mpeg-es file
> >
> >Use mencoder with -ovc copy -of rawvideo...
> 
> a workaround against buggy code is not a solution, is it ? :)

I don't think -dumpvideo was supposed to have any use besides
debugging...
Anyway, would the attached patch be okay for you? Or should I move the
autodetection further down (i.e. how likely is MPEG-PES to contain 0x1bf
or 0x1bc headers)?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/demux_mpg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_mpg.c,v
retrieving revision 1.60
diff -u -r1.60 demux_mpg.c
--- libmpdemux/demux_mpg.c	5 Aug 2005 19:57:46 -0000	1.60
+++ libmpdemux/demux_mpg.c	25 Aug 2005 15:45:29 -0000
@@ -408,6 +408,7 @@
 static int num_elementary_packets12x=0;
 static int num_elementary_packets1B6=0;
 static int num_elementary_packetsPES=0;
+static int num_gxf_packets=0;
 static int num_h264_slice=0; //combined slice
 static int num_h264_dpa=0; //DPA Slice
 static int num_h264_dpb=0; //DPB Slice
@@ -437,6 +438,7 @@
   num_elementary_packets1B6=0;
   num_elementary_packets12x=0;
   num_elementary_packetsPES=0;
+  num_gxf_packets=0;
   num_h264_slice=0; //combined slice
   num_h264_dpa=0; //DPA Slice
   num_h264_dpb=0; //DPB Slice
@@ -449,13 +451,14 @@
   if(demux_mpg_open(demuxer))
     file_format=DEMUXER_TYPE_MPEG_PS;
   else {
-    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, synced: %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 GXF: %d PES: %d  MP3: %d, synced: %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_gxf_packets,
      num_elementary_packetsPES,num_mp3audio_packets, demuxer->synced);
 
      //MPEG packet stats: p100: 458  p101: 458  PES: 0  MP3: 1103  (.m2v)
@@ -464,6 +467,10 @@
        return file_format;
 
       // some hack to get meaningfull error messages to our unhappy users:
+      if (num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
+          num_gxf_packets>=2)
+         file_format=DEMUXER_TYPE_MPEG_GXF;
+      else
       if(num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
          abs(num_elementary_packets101+8-num_elementary_packets100)<16) {
          if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4) {
@@ -506,6 +513,36 @@
   return 1;
 }
 
+static int demux_mpg_gxf_fill_buffer(demuxer_t *demux, demux_stream_t *ds) {
+  demux_packet_t *pack;
+  uint32_t state = (uint32_t)demux->priv;
+  int pos = 0;
+  int discard = 0;
+  unsigned char *buf;
+  if (demux->stream->eof)
+    return 0;
+  demux->filepos = stream_tell(demux->stream);
+  pack = new_demux_packet(STREAM_BUFFER_SIZE);
+  buf = pack->buffer;
+  while (pos < STREAM_BUFFER_SIZE) {
+    register int c = stream_read_char(demux->stream);
+    if (c < 0) { // EOF
+      resize_demux_packet(pack, pos);
+      break;
+    }
+    state = state << 8 | c;
+    if (state == 0x1bc || state == 0x1bf)
+      discard = 1;
+    else if (state == 0x100)
+      discard = 0;
+    if (!discard)
+      buf[pos++] = c;
+  }
+  ds_add_packet(ds, pack);
+  demux->priv = (void *)state;
+  return 1;
+}
+
 int demux_mpg_fill_buffer(demuxer_t *demux, demux_stream_t *ds){
 unsigned int head=0;
 int skipped=0;
@@ -579,6 +616,7 @@
       mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head);
     } else
       if(head==0x1B6) ++num_elementary_packets1B6;
+    else if (head == 0x1BC || head == 0x1BF) ++num_gxf_packets;
 #if 1
     if( ( (num_elementary_packets100>50 && num_elementary_packets101>50) ||
           (num_elementary_packetsPES>50) ) && skipped>4000000){
@@ -789,6 +827,13 @@
     return demuxer;
 }
 
+static demuxer_t *demux_mpg_gxf_open(demuxer_t *demuxer) {
+  demuxer->audio->sh = NULL;
+  demuxer->video->sh = new_sh_video(demuxer,0);
+  ((sh_video_t *)demuxer->video->sh)->ds = demuxer->video;
+  demuxer->priv = (void *) 0xffffffff;
+  return demuxer;
+}
 
 static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer)
 {
@@ -844,6 +889,22 @@
 };
 
 
+demuxer_desc_t demuxer_desc_mpeg_gxf = {
+  "MPEG ES in GXF demuxer",
+  "mpeggxf",
+  "MPEG-ES in GXF",
+  "Reimar Döffinger",
+  "Mpeg",
+  DEMUXER_TYPE_MPEG_GXF,
+  0, // hack autodetection
+  NULL,
+  demux_mpg_gxf_fill_buffer,
+  demux_mpg_gxf_open,
+  NULL,
+  demux_seek_mpg,
+  NULL
+};
+
 demuxer_desc_t demuxer_desc_mpeg_es = {
   "MPEG ES demuxer",
   "mpeges",
Index: libmpdemux/demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.198
diff -u -r1.198 demuxer.c
--- libmpdemux/demuxer.c	23 Aug 2005 08:03:26 -0000	1.198
+++ libmpdemux/demuxer.c	25 Aug 2005 15:45:39 -0000
@@ -51,6 +51,7 @@
 extern demuxer_desc_t demuxer_desc_mpeg_ps;
 extern demuxer_desc_t demuxer_desc_mpeg_pes;
 extern demuxer_desc_t demuxer_desc_mpeg_es;
+extern demuxer_desc_t demuxer_desc_mpeg_gxf;
 extern demuxer_desc_t demuxer_desc_mpeg4_es;
 extern demuxer_desc_t demuxer_desc_h264_es;
 extern demuxer_desc_t demuxer_desc_rawdv;
@@ -100,6 +101,7 @@
   &demuxer_desc_mpeg_ps,
   &demuxer_desc_mpeg_pes,
   &demuxer_desc_mpeg_es,
+  &demuxer_desc_mpeg_gxf,
   &demuxer_desc_mpeg4_es,
   &demuxer_desc_h264_es,
 #ifdef HAVE_LIBDV095
Index: libmpdemux/demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.79
diff -u -r1.79 demuxer.h
--- libmpdemux/demuxer.h	5 Aug 2005 19:57:47 -0000	1.79
+++ libmpdemux/demuxer.h	25 Aug 2005 15:45:40 -0000
@@ -49,11 +49,12 @@
 #define DEMUXER_TYPE_AAC 39
 #define DEMUXER_TYPE_MPC 40
 #define DEMUXER_TYPE_MPEG_PES 41
+#define DEMUXER_TYPE_MPEG_GXF 42
 
 // 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 41
+#define DEMUXER_TYPE_MAX 42
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code
Index: libmpdemux/video.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/video.c,v
retrieving revision 1.51
diff -u -r1.51 video.c
--- libmpdemux/video.c	6 Aug 2005 16:15:07 -0000	1.51
+++ libmpdemux/video.c	25 Aug 2005 15:45:49 -0000
@@ -46,6 +46,7 @@
 
 if((d_video->demuxer->file_format == DEMUXER_TYPE_PVA) ||
    (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_ES) ||
+   (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_GXF) ||
    (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_PS && ((! sh_video->format) || (sh_video->format==0x10000001) || (sh_video->format==0x10000002))) ||
    (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_TY) ||
    (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_TS && ((sh_video->format==0x10000001) || (sh_video->format==0x10000002)))
@@ -403,6 +405,7 @@
     *start=NULL;
 
   if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || 
+     demuxer->file_format==DEMUXER_TYPE_MPEG_GXF ||
   	(demuxer->file_format==DEMUXER_TYPE_MPEG_PS && ((! sh_video->format) || (sh_video->format==0x10000001) || (sh_video->format==0x10000002)))
 		  || demuxer->file_format==DEMUXER_TYPE_PVA || 
 		  ((demuxer->file_format==DEMUXER_TYPE_MPEG_TS) && ((sh_video->format==0x10000001) || (sh_video->format==0x10000002)))


More information about the MPlayer-dev-eng mailing list