]> git.sesse.net Git - vlc/blobdiff - modules/demux/ps.h
MKV: de-advanced some options
[vlc] / modules / demux / ps.h
index 457276e29b243235847a932e935bec55bbd21944..674c36517ba0b2e1898a5e562f181f685bce92e0 100644 (file)
@@ -112,11 +112,11 @@ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, int i_id )
         }
         else if( ( i_id&0xff ) == 0x70 )
         {
-            es_format_Init( &tk->fmt, SPU_ES, VLC_FOURCC('o','g','t',' ') );
+            es_format_Init( &tk->fmt, SPU_ES, VLC_CODEC_OGT );
         }
         else if( ( i_id&0xfc ) == 0x00 )
         {
-            es_format_Init( &tk->fmt, SPU_ES, VLC_FOURCC('c','v','d',' ') );
+            es_format_Init( &tk->fmt, SPU_ES, VLC_CODEC_CVD );
         }
         else if( ( i_id&0xff ) == 0x10 )
         {
@@ -299,23 +299,24 @@ static inline int ps_pkt_id( block_t *p_pkt )
     return p_pkt->p_buffer[3];
 }
 
-/* return the size of the next packet
- * You need to give him at least 14 bytes (and it need to start as a
- * valid packet) It does not handle less than 6 bytes */
+/* return the size of the next packet */
 static inline int ps_pkt_size( const uint8_t *p, int i_peek )
 {
-    assert( i_peek >= 6 );
-    if( p[3] == 0xb9 && i_peek >= 4 )
+    if( unlikely(i_peek < 4) )
+    {
+        return -1;
+    }
+    else if( p[3] == 0xb9 )
     {
         return 4;
     }
     else if( p[3] == 0xba )
     {
-        if( (p[4] >> 6) == 0x01 && i_peek >= 14 )
+        if( i_peek >= 14 && (p[4] >> 6) == 0x01 )
         {
             return 14 + (p[13]&0x07);
         }
-        else if( (p[4] >> 4) == 0x02 && i_peek >= 12 )
+        else if( i_peek >= 12 && (p[4] >> 4) == 0x02 )
         {
             return 12;
         }
@@ -576,7 +577,7 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt,
 {
     int i_buffer = p_pkt->i_buffer;
     uint8_t *p_buffer = p_pkt->p_buffer;
-    int i_length, i_version, i_info_length, i_esm_length, i_es_base;
+    int i_length, i_version, i_info_length, i_es_base;
 
     if( !p_psm || p_buffer[3] != 0xbc ) return VLC_EGENERIC;
 
@@ -594,8 +595,8 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt,
     if( i_info_length + 10 > i_length ) return VLC_EGENERIC;
 
     /* Elementary stream map */
-    i_esm_length = (uint16_t)(p_buffer[ 10 + i_info_length ] << 8) +
-        p_buffer[ 11 + i_info_length];
+    /* int i_esm_length = (uint16_t)(p_buffer[ 10 + i_info_length ] << 8) +
+        p_buffer[ 11 + i_info_length]; */
     i_es_base = 12 + i_info_length;
 
     while( i_es_base + 4 < i_length )
@@ -674,9 +675,15 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt,
         if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id ) != VLC_SUCCESS )
             continue;
 
-        if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec ) continue;
+        if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec )
+        {
+            es_format_Clean( &tk_tmp.fmt );
+            continue;
+        }
 
         es_out_Del( out, tk[i].es );
+        es_format_Clean( &tk[i].fmt );
+
         tk[i] = tk_tmp;
         tk[i].b_seen = true;
         tk[i].es = es_out_Add( out, &tk[i].fmt );