]> git.sesse.net Git - vlc/blobdiff - src/input/mpeg_system.c
* Bug fixes and enhancements in the Gtk+/Gnome interfaces.
[vlc] / src / input / mpeg_system.c
index ca8583c8ade740817c92cedbe15e7e5fd139c489..73b463e10cdcde2d111401b9de0990bec860d953 100644 (file)
@@ -2,7 +2,7 @@
  * mpeg_system.c: TS, PS and PES management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: mpeg_system.c,v 1.40 2001/03/02 13:20:29 massiot Exp $
+ * $Id: mpeg_system.c,v 1.45 2001/03/15 01:42:20 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -224,7 +224,8 @@ void input_ParsePES( input_thread_t * p_input, es_descriptor_t * p_es )
                     }
                     p_pes->i_pts = input_ClockGetTS( p_input, p_es->p_pgrm,
                     ( ((mtime_t)(p_full_header[2] & 0x0E) << 29) |
-                      (((mtime_t)U32_AT(p_full_header + 2) & 0xFFFE00) << 6) |
+                      ((mtime_t)(p_full_header[3]) << 22) |
+                      ((mtime_t)(p_full_header[4] & 0xFE) << 14) |
                       ((mtime_t)p_full_header[5] << 7) |
                       ((mtime_t)p_full_header[6] >> 1) ) );
 
@@ -258,7 +259,7 @@ void input_ParsePES( input_thread_t * p_input, es_descriptor_t * p_es )
                 /* Cannot fail because the previous one succeeded. */
                 MoveChunk( NULL, &p_data, &p_byte, 6 );
 
-                while( *p_byte == 0xFF && i_pes_header_size < 22 )
+                while( *p_byte == 0xFF && i_pes_header_size < 23 )
                 {
                     i_pes_header_size++;
                     if( MoveChunk( NULL, &p_data, &p_byte, 1 ) != 1 )
@@ -270,7 +271,7 @@ void input_ParsePES( input_thread_t * p_input, es_descriptor_t * p_es )
                         return;
                     }
                 }
-                if( i_pes_header_size == 22 )
+                if( i_pes_header_size == 23 )
                 {
                     intf_ErrMsg( "Too much MPEG-1 stuffing" );
                     p_input->pf_delete_pes( p_input->p_method_data, p_pes );
@@ -747,6 +748,7 @@ es_descriptor_t * input_ParsePS( input_thread_t * p_input,
                     {
                         /* Subtitles video (0x20->0x3F) */
                         p_es->i_type = DVD_SPU_ES;
+                        p_es->b_spu = 1;
 #ifdef AUTO_SPAWN
                         if( main_GetIntVariable( INPUT_SUBTITLE_VAR, -1 )
                                 == ((p_es->i_id & 0x1F00) >> 8) )
@@ -818,9 +820,8 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
                                         >> 11);
 
                     /* mux_rate */
-                    i_mux_rate = (( ((u32)U16_AT(p_header + 10) << 16)
-                                   | (u32)U16_AT(p_header + 12) ) & 0xFFFFFC00)
-                                    >> 11;
+                    i_mux_rate = ((u32)U16_AT(p_header + 10) << 6)
+                                   | (p_header[12] >> 2);
                 }
                 else
                 {
@@ -842,7 +843,7 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
                          ((mtime_t)p_header[8] >> 1);
 
                     /* mux_rate */
-                    i_mux_rate = (U32_AT(p_header + 8) & 0x8FFFFE) >> 11;
+                    i_mux_rate = (U32_AT(p_header + 8) & 0x7FFFFE) >> 1;
                 }
                 /* Call the pace control. */
                 input_ClockManageRef( p_input, p_input->stream.pp_programs[0],
@@ -876,7 +877,7 @@ void input_DemuxPS( input_thread_t * p_input, data_packet_t * p_data )
         default:
             /* This should not happen */
             b_trash = 1;
-            intf_WarnMsg( 1, "Unwanted packet received with start code %x",
+            intf_WarnMsg( 1, "Unwanted packet received with start code 0x%.8x",
                           i_code );
         }
     }
@@ -934,7 +935,6 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
     pgrm_ts_data_t *    p_pgrm_demux = NULL;
 
     #define p (p_data->p_buffer)
-   
     /* Extract flags values from TS common header. */
     i_pid = U16_AT(&p[1]) & 0x1fff;
     b_unit_start = (p[1] & 0x40);
@@ -943,7 +943,6 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
 
     /* Find out the elementary stream. */
     vlc_mutex_lock( &p_input->stream.stream_lock );
-
         
     p_es= input_FindES( p_input, i_pid );
     
@@ -953,10 +952,11 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
         
         if( p_es_demux->b_psi )
             b_psi = 1;
+        else
+            p_pgrm_demux = (pgrm_ts_data_t *)p_es->p_pgrm->p_demux_data; 
     }
 
     vlc_mutex_lock( &p_input->stream.control.control_lock );
-
     if( ( p_es == NULL ) || (p_es->b_audio && p_input->stream.control.b_mute) )
     {
         /* Not selected. Just read the adaptation field for a PCR. */
@@ -969,17 +969,12 @@ void input_DemuxTS( input_thread_t * p_input, data_packet_t * p_data )
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
 
+    /* Don't change the order of the tests : if b_psi then p_pgrm_demux 
+     * may still be null. Who said it was ugly ? */
     if( ( p_es != NULL ) && 
         ((p_es->p_decoder_fifo != NULL) || b_psi 
                                    || (p_pgrm_demux->i_pcr_pid == i_pid) ) )
     {
-        p_es_demux = (es_ts_data_t *)p_es->p_demux_data;
-
-        if( ! p_es_demux->b_psi )
-        {
-            p_pgrm_demux = (pgrm_ts_data_t *)p_es->p_pgrm->p_demux_data; 
-        }
-
 #ifdef STATS
         p_es->c_packets++;
 #endif
@@ -1288,7 +1283,6 @@ static void input_DecodePAT( input_thread_t * p_input, es_descriptor_t * p_es )
     stream_ts_data_t  * p_stream_data;
     es_ts_data_t      * p_demux_data;
 
-   
     p_demux_data = (es_ts_data_t *)p_es->p_demux_data;
     p_stream_data = (stream_ts_data_t *)p_input->stream.p_demux_data;
     
@@ -1394,6 +1388,9 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
         p_current_data = p_psi->buffer;
         
         p_pgrm_data->i_pcr_pid = U16_AT(p_current_section + 8) & 0x1fff;
+        
+        /* Lock stream information */
+        vlc_mutex_lock( &p_input->stream.stream_lock );
 
         /* Delete all ES in this program  except the PSI */
         for( i_loop=0; i_loop < p_es->p_pgrm->i_es_number; i_loop++ )
@@ -1430,7 +1427,6 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
                 
                 /* We want to decode */
                 input_SelectES( p_input, p_new_es );
-
                 p_current_data += 5 + i_es_info_length;
             }
 
@@ -1446,4 +1442,7 @@ static void input_DecodePMT( input_thread_t * p_input, es_descriptor_t * p_es )
     }
     
 #undef p_psi
+
+    /*  Remove lock */
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
 }