]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
A tout kass�.
[vlc] / src / input / input.c
index eaf1278bd262492894d487852cfdf7abcd86275b..dd7b798c9bfa5967cbaa48b78287f7e189d42232 100644 (file)
@@ -8,25 +8,28 @@
 
 /*******************************************************************************
  * Preamble
- ******************************************************************************/
+ *******************************************************************************/
+#include "vlc.h"
+
+/*
 #include <errno.h>
-#include <pthread.h>
-#include <sys/uio.h>                                                 /* iovec */
+#include <sys/uio.h>                                               
 #include <string.h>
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XShm.h>
 #include <sys/soundcard.h>
 
-#include <stdlib.h>                               /* atoi(), malloc(), free() */
+#include <stdlib.h>                            
 #include <stdio.h>
-#include <sys/ioctl.h>                                             /* ioctl() */
-#include <net/if.h>                                                  /* ifreq */
+#include <sys/ioctl.h>                                            
+#include <net/if.h>                                                
 #include <netinet/in.h>
 
 #include "common.h"
 #include "config.h"
 #include "mtime.h"
+#include "vlc_thread.h"
 #include "intf_msg.h"
 #include "debug.h"
 
@@ -44,6 +47,7 @@
 #include "video.h"
 #include "video_output.h"
 #include "video_decoder.h"
+*/
 
 /******************************************************************************
  * Local prototypes
@@ -186,13 +190,13 @@ input_thread_t *input_CreateThread( input_cfg_t *p_cfg )
 
     /* Create thread and set locks. */
     p_input->b_die = 0;
-    pthread_mutex_init( &p_input->netlist.lock, NULL );
-    pthread_mutex_init( &p_input->programs_lock, NULL );
-    pthread_mutex_init( &p_input->es_lock, NULL );
+    vlc_mutex_init( &p_input->netlist.lock );
+    vlc_mutex_init( &p_input->programs_lock );
+    vlc_mutex_init( &p_input->es_lock );
 #ifdef NO_THREAD
     input_Thread( p_input );
 #else
-    if( pthread_create(&p_input->thread_id, NULL, (void *) input_Thread, 
+    if( vlc_thread_create(&p_input->thread_id, "input", (vlc_thread_func_t)input_Thread, 
                        (void *) p_input) )
     {
         intf_ErrMsg("input error: can't spawn input thread (%s)\n", 
@@ -223,7 +227,7 @@ void input_DestroyThread( input_thread_t *p_input )
     p_input->b_die = 1;                          /* ask thread to kill itself */
 
     /* Remove this as soon as the "status" flag is implemented */
-    pthread_join( p_input->thread_id, NULL );         /* wait until it's done */
+    vlc_thread_join( p_input->thread_id );            /* wait until it's done */
 }
 
 #if 0
@@ -304,7 +308,7 @@ static void input_Thread( input_thread_t *p_input )
     EndThread( p_input );
 
     intf_DbgMsg("input debug: thread %p destroyed\n", p_input);
-    pthread_exit( 0 );
+    vlc_thread_exit();
 }
 
 
@@ -458,7 +462,7 @@ static __inline__ int input_ReadPacket( input_thread_t *p_input )
     /* Remove the TS packets we have just filled from the netlist */
 #ifdef INPUT_LIFO_TS_NETLIST
     /* We need to take a lock here while we're calculating index positions. */
-    pthread_mutex_lock( &p_input->netlist.lock );
+    vlc_mutex_lock( &p_input->netlist.lock );
 
     i_meanwhile_released = i_base_index - p_input->netlist.i_ts_index;
     if( i_meanwhile_released )
@@ -498,7 +502,7 @@ static __inline__ int input_ReadPacket( input_thread_t *p_input )
         p_input->netlist.i_ts_index = i_current_index;
     }
 
-    pthread_mutex_unlock( &p_input->netlist.lock );
+    vlc_mutex_unlock( &p_input->netlist.lock );
 
 #else /* FIFO netlist */
     /* & is modulo ; that's where we make the loop. */
@@ -538,7 +542,7 @@ static __inline__ void input_SortPacket( input_thread_t *p_input,
 //                    i_current_pid, p_ts_packet);
 
         /* Lock current ES state. */
-        pthread_mutex_lock( &p_input->es_lock );
+        vlc_mutex_lock( &p_input->es_lock );
         
        /* Verify that we actually want this PID. */
         for( i_es_loop = 0; i_es_loop < INPUT_MAX_SELECTED_ES; i_es_loop++ )
@@ -553,7 +557,7 @@ static __inline__ void input_SortPacket( input_thread_t *p_input,
                        modified from inside the input_thread (by the PSI
                        decoder): interface thread is only allowed to modify
                        the pp_selected_es table */
-                    pthread_mutex_unlock( &p_input->es_lock );
+                    vlc_mutex_unlock( &p_input->es_lock );
 
                     /* We're interested. Pass it to the demultiplexer. */
                     input_DemuxTS( p_input, p_ts_packet,
@@ -567,7 +571,7 @@ static __inline__ void input_SortPacket( input_thread_t *p_input,
                 break;
             }
         }
-        pthread_mutex_unlock( &p_input->es_lock );
+        vlc_mutex_unlock( &p_input->es_lock );
     }
 
     /* We weren't interested in receiving this packet. Give it back to the
@@ -841,7 +845,7 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
                      so the PES won't be usefull for any decoder. Moreover,
                      this should never happen so we can trash the packet and
                      exit roughly without regrets */
-                  intf_DbgMsg("PES packet is too short: trashed\n");
+                  intf_DbgMsg("PES packet too short: trashed\n");
                   input_NetlistFreePES( p_input, p_pes );
                   p_pes = NULL;
                   /* Stats ?? */
@@ -915,27 +919,38 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
                     pcr_descriptor_t * p_pcr;
 
                     p_pcr = p_input->p_pcr;
-                    pthread_mutex_lock( &p_pcr->lock );
-                    if( p_pcr->delta_clock == 0 )
+                    
+                    p_pes->i_pts = 
+                        ( ((mtime_t)(p_pes->p_pes_header[9] & 0x0E) << 29) |
+                          (((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) - (1 << 14)) |
+                          ((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) ) * 300;
+                    p_pes->i_pts /= 27;
+                    
+                    if( p_pcr->i_synchro_state )
                     {
-                        p_pes->b_has_pts = 0;
+                        switch( p_pcr->i_synchro_state )
+                        {
+                            case SYNCHRO_NOT_STARTED:
+                                p_pes->b_has_pts = 0;
+                                break;
+
+                            case SYNCHRO_START:
+                                p_pes->i_pts += p_pcr->delta_pcr;
+                                p_pcr->delta_absolute = mdate() - p_pes->i_pts + 500000;
+                                p_pes->i_pts += p_pcr->delta_absolute;
+                                p_pcr->i_synchro_state = 0;
+                                break;
+
+                            case SYNCHRO_REINIT: /* We skip a PES */
+                                p_pes->b_has_pts = 0;
+                                p_pcr->i_synchro_state = SYNCHRO_START;
+                                break;
+                        }
                     }
                     else
                     {
-                        p_pes->i_pts = ( ((mtime_t)(p_pes->p_pes_header[9] & 0x0E) << 29) |
-                                         (((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) - (1 << 14)) |
-                                         ((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) );
-                        p_pes->i_pts *= 300;
-                        p_pes->i_pts /= 27;
-                        p_pes->i_pts += p_pcr->delta_clock;
-                        if( p_pcr->c_pts == 0 )
-                        {
-                            p_pcr->delta_decode = mdate() - p_pes->i_pts + 500000;
-                        }
-                        p_pes->i_pts += p_pcr->delta_decode;
-                        p_pcr->c_pts += 1;
+                        p_pes->i_pts += p_pcr->delta_pcr + p_pcr->delta_absolute;
                     }
-                    pthread_mutex_unlock( &p_pcr->lock );
                 }
                 break;
             }
@@ -982,7 +997,7 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
 
             if( p_fifo != NULL )
             {
-                pthread_mutex_lock( &p_fifo->data_lock );
+                vlc_mutex_lock( &p_fifo->data_lock );
                 if( DECODER_FIFO_ISFULL( *p_fifo ) )
                 {
                     /* The FIFO is full !!! This should not happen. */
@@ -1002,9 +1017,9 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
                     DECODER_FIFO_INCEND( *p_fifo );
 
                     /* Warn the decoder that it's got work to do. */
-                    pthread_cond_signal( &p_fifo->data_wait );
+                    vlc_cond_signal( &p_fifo->data_wait );
                 }
-                pthread_mutex_unlock( &p_fifo->data_lock );
+                vlc_mutex_unlock( &p_fifo->data_lock );
             }
             else
             {