[MPlayer-cvslog] r23729 - trunk/libmpdemux/demux_mpg.c

nicodvb subversion at mplayerhq.hu
Sat Jul 7 10:22:48 CEST 2007


Author: nicodvb
Date: Sat Jul  7 10:22:47 2007
New Revision: 23729

Log:
proper parsing of pes_extension[12] fields (replaces the previous code that relied on specific flags set

Modified:
   trunk/libmpdemux/demux_mpg.c

Modified: trunk/libmpdemux/demux_mpg.c
==============================================================================
--- trunk/libmpdemux/demux_mpg.c	(original)
+++ trunk/libmpdemux/demux_mpg.c	Sat Jul  7 10:22:47 2007
@@ -365,8 +365,41 @@ static int demux_mpg_read_packet(demuxer
       else if(hdrlen>=3) {
         c=stream_read_char(demux->stream);
         hdrlen--;
-        if(c != 0x1F && c!= 0x0F) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid pes_extension field  \n"); return -1;}
-        if(c == 0x1F) {
+
+        if((c & 0x0F) != 0x0F) {
+          mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: pes_extension_flag2 not set, discarding pes packet\n");
+          return -1;
+        }
+        if(c & 0x80) { //pes_private_data_flag
+          if(hdrlen<16) {
+            mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough pes_private_data bytes: %d < 16, discarding pes packet\n", hdrlen);
+            return -1;
+          }
+          stream_skip(demux->stream, 16);
+          hdrlen-=16;
+        }
+        if(c & 0x40) { //pack_header_field_flag
+          int l = stream_read_char(demux->stream);
+          if(l < 0) //couldn't read from the stream?
+            return -1;
+          hdrlen--;
+          if(l < 0 || hdrlen < l) {
+            mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough pack_header bytes: hdrlen: %d < skip: %d, discarding pes packet\n",
+                                     hdrlen, l);
+            return -1;
+          }
+          stream_skip(demux->stream, l);
+          hdrlen-=l;
+        }
+        if(c & 0x20) { //program_packet_sequence_counter_flag
+            if(hdrlen < 2) {
+            mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough program_packet bytes: hdrlen: %d, discarding pes packet\n", hdrlen);
+            return -1;
+          }
+          stream_skip(demux->stream, 2);
+          hdrlen-=2;
+        }
+        if(c & 0x10) {
           //STD
           stream_skip(demux->stream, 2);
           hdrlen-=2;



More information about the MPlayer-cvslog mailing list