[vlc-commits] demux: ps: improve probing

Francois Cartegnie git at videolan.org
Wed Mar 8 22:29:18 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Mar  8 15:23:53 2017 +0100| [968628e8e15b575e57e44d3f2972af61b1abd814] | committer: Francois Cartegnie

demux: ps: improve probing

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=968628e8e15b575e57e44d3f2972af61b1abd814
---

 modules/demux/mpeg/ps.c | 44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/modules/demux/mpeg/ps.c b/modules/demux/mpeg/ps.c
index 0f39e2c..87e0c6f 100644
--- a/modules/demux/mpeg/ps.c
+++ b/modules/demux/mpeg/ps.c
@@ -46,6 +46,8 @@
     "to calculate position and duration. However sometimes this might not " \
     "be usable. Disable this option to calculate from the bitrate instead." )
 
+#define PS_PACKET_PROBE 3
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -113,28 +115,48 @@ static int OpenCommon( vlc_object_t *p_this, bool b_force )
     demux_sys_t *p_sys;
 
     const uint8_t *p_peek;
+    ssize_t i_peek = 0;
+    ssize_t i_offset = 0;
     bool b_cdxa = false;
 
-    if( vlc_stream_Peek( p_demux->s, &p_peek, 16 ) < 16 )
+    i_peek = vlc_stream_Peek( p_demux->s, &p_peek, 16 );
+    if( i_peek < 16 )
     {
         msg_Err( p_demux, "cannot peek" );
         return VLC_EGENERIC;
     }
 
-    if( memcmp( p_peek, "\x00\x00\x01", 3 ) || ( p_peek[3] < 0xb9 ) )
+    if( !memcmp( p_peek, "RIFF", 4 ) && !memcmp( &p_peek[8], "CDXA", 4 ) )
+    {
+        b_cdxa = true;
+        msg_Info( p_demux, "Detected CDXA-PS" );
+    }
+    else if( b_force )
+    {
+        msg_Warn( p_demux, "this does not look like an MPEG PS stream, "
+                  "continuing anyway" );
+    }
+    else for( unsigned i=0; i<PS_PACKET_PROBE; i++ )
     {
-        if( memcmp( p_peek, "RIFF", 4 ) || memcmp( &p_peek[8], "CDXA", 4 ) )
+        if( i_peek < i_offset + 16 )
         {
-            if( !b_force )
+            i_peek = vlc_stream_Peek( p_demux->s, &p_peek, i_offset + 16 );
+            if( i_peek < i_offset + 16 )
                 return VLC_EGENERIC;
-            msg_Warn( p_demux, "this does not look like an MPEG PS stream, "
-                      "continuing anyway" );
-        }
-        else
-        {
-            b_cdxa = true;
-            msg_Info( p_demux, "Detected CDXA-PS" );
         }
+
+        const uint8_t startcode[3] = { 0x00, 0x00, 0x01 };
+        const uint8_t *p_header = &p_peek[i_offset];
+        if( memcmp( p_header, startcode, 3 ) ||
+           ( (p_header[3] & 0xB0) != 0xB0 &&
+            !(p_header[3] >= 0xC0 && p_header[3] <= 0xEF) &&
+              p_header[3] != 0xFF ) )
+            return VLC_EGENERIC;
+
+        ssize_t i_pessize = ps_pkt_size( p_header, 16 );
+        if( i_pessize < 5 )
+            return VLC_EGENERIC;
+        i_offset += i_pessize;
     }
 
     /* Fill p_demux field */



More information about the vlc-commits mailing list