]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
. correction d'un poliotage de copier-coller
[vlc] / src / input / input.c
index 7d83c1cb58f4796c4b33b1959dd957a9c71286f1..a5cecfbd232afb83b51277db5c03fe87ffbb171e 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.61 2000/12/21 13:54:15 massiot Exp $
+ * $Id: input.c,v 1.69 2001/01/15 06:18:23 sam Exp $
  *
  * Authors: 
  *
@@ -62,6 +62,7 @@ static void ErrorThread ( input_thread_t *p_input );
 static void EndThread   ( input_thread_t *p_input );
 static void NetworkOpen ( input_thread_t *p_input );
 static void FileOpen    ( input_thread_t *p_input );
+static void DvdOpen     ( input_thread_t *p_input );
 
 /*****************************************************************************
  * input_CreateThread: creates a new input thread
@@ -77,11 +78,11 @@ input_thread_t *input_CreateThread ( input_config_t * p_config, int *pi_status )
     int                 i_status;                           /* thread status */
 
     /* Allocate descriptor */
-    intf_DbgMsg("\n");
     p_input = (input_thread_t *)malloc( sizeof(input_thread_t) );
     if( p_input == NULL )
     {
-        intf_ErrMsg("error: %s\n", strerror(errno));
+        intf_ErrMsg( "input error: can't allocate input thread (%s)",
+                     strerror(errno) );
         free( p_config );
         return( NULL );
     }
@@ -95,10 +96,8 @@ input_thread_t *input_CreateThread ( input_config_t * p_config, int *pi_status )
     p_input->p_config = p_config;
 
     /* Initialize stream description */
-    p_input->pp_es = NULL;
-    p_input->pp_selected_es = NULL;
-    p_input->i_es_number = 0;
-    p_input->i_selected_es_number = 0;
+    p_input->stream.i_es_number = 0;
+    p_input->stream.i_selected_es_number = 0;
     p_input->stream.i_pgrm_number = 0;
 
     /* Initialize stream control properties. */
@@ -115,7 +114,8 @@ input_thread_t *input_CreateThread ( input_config_t * p_config, int *pi_status )
     if( vlc_thread_create( &p_input->thread_id, "input", (void *) RunThread,
                            (void *) p_input ) )
     {
-        intf_ErrMsg("error: %s\n", strerror(errno) );
+        intf_ErrMsg( "input error: can't create input thread (%s)",
+                     strerror(errno) );
         free( p_input );
         free( p_config );
         return( NULL );
@@ -224,6 +224,7 @@ static void RunThread( input_thread_t *p_input )
  * InitThread: init the input thread
  *****************************************************************************/
 input_capabilities_t * PSKludge( void );
+input_capabilities_t * DVDKludge( void );
 static void InitThread( input_thread_t * p_input )
 {
     /* Initialize default settings for spawned decoders */
@@ -244,11 +245,18 @@ static void InitThread( input_thread_t * p_input )
     {
     case INPUT_METHOD_FILE:                                  /* file methods */
         FileOpen( p_input );
+        /* Probe plugin (FIXME: load plugins before & write this) */
+        p_input->p_plugin = PSKludge();
+       break;
+    case INPUT_METHOD_DVD:                                     /* DVD method */
+        DvdOpen( p_input );
+        /* DVD plugin */
+        p_input->p_plugin = DVDKludge();
         break;
     case INPUT_METHOD_VLAN_BCAST:                     /* vlan network method */
 /*        if( !p_main->b_vlans )
         {
-            intf_ErrMsg("error: vlans are not activated\n");
+            intf_ErrMsg("input error: vlans are not activated");
             free( p_input );
             return( NULL );
         } */ /* la-lala */
@@ -260,7 +268,8 @@ static void InitThread( input_thread_t * p_input )
         break;
 #ifdef DEBUG
     default:
-        intf_ErrMsg("Unknow input method");
+        intf_ErrMsg( "input error: unknow method 0x%.4x",
+                     p_input->p_config->i_method );
         free( p_input->p_config );
         p_input->b_error = 1;
         break;
@@ -269,8 +278,6 @@ static void InitThread( input_thread_t * p_input )
 
     free( p_input->p_config );
 
-    /* Probe plugin (FIXME: load plugins before & write this) */
-    p_input->p_plugin = PSKludge();
     p_input->p_plugin->pf_init( p_input );
 
     *p_input->pi_status = THREAD_READY;
@@ -296,7 +303,6 @@ static void ErrorThread( input_thread_t *p_input )
 static void EndThread( input_thread_t * p_input )
 {
     int *       pi_status;                                  /* thread status */
-    int         i_es_loop;                                       /* es index */
 
     /* Store status */
     pi_status = p_input->pi_status;
@@ -307,27 +313,24 @@ static void EndThread( input_thread_t * p_input )
         struct tms cpu_usage;
         times( &cpu_usage );
 
-        intf_Msg("input stats: cpu usage (user: %d, system: %d)\n",
+        intf_Msg("input stats: cpu usage (user: %d, system: %d)",
                  cpu_usage.tms_utime, cpu_usage.tms_stime);
     }
 #endif
 
-    /* Destroy all decoder threads */
-    for( i_es_loop = 0; i_es_loop < p_input->i_selected_es_number;
-         i_es_loop++ )
-    {
-        p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->b_die = 1;
-        /* Make sure the thread leaves the GetByte() function */
-        vlc_mutex_lock( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_lock);
-        vlc_cond_signal( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_wait );
-        vlc_mutex_unlock( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_lock );
-
-        /* Waiting for the thread to exit */
-        vlc_thread_join( p_input->pp_selected_es[i_es_loop]->thread_id );
-        free( p_input->pp_selected_es[i_es_loop]->p_decoder_fifo );
-    }
+    /* Free all ES and destroy all decoder threads */
+    input_EndStream( p_input );
 
     /* Free demultiplexer's data */
+    p_input->p_plugin->pf_end( p_input );
+    free( p_input->p_plugin );
+
+    /* Destroy Mutex locks */
+    vlc_mutex_destroy( &p_input->stream.control.control_lock );
+    vlc_mutex_destroy( &p_input->stream.stream_lock );
+    
+    /* Free input structure */
+    free( p_input );
 
     /* Update status */
     *pi_status = THREAD_OVER;
@@ -355,64 +358,74 @@ static void FileOpen( input_thread_t * p_input )
 
 #define p_config    p_input->p_config
 
-    if( !strncmp( p_config->p_source, "-", 1 ) )
+    if( stat( p_config->p_source, &stat_info ) == (-1) )
+    {
+        intf_ErrMsg( "input error: cannot stat() file %s (%s)",
+                     p_config->p_source, strerror(errno));
+        p_input->b_error = 1;
+        return;
+    }
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    /* If we are here we can control the pace... */
+    p_input->stream.b_pace_control = 1;
+
+    if( S_ISREG(stat_info.st_mode) || S_ISCHR(stat_info.st_mode)
+         || S_ISBLK(stat_info.st_mode) )
+    {
+        p_input->stream.b_seekable = 1;
+        p_input->stream.i_size = stat_info.st_size;
+    }
+    else if( S_ISFIFO(stat_info.st_mode) || S_ISSOCK(stat_info.st_mode) )
     {
-        /* stdin */
-        p_input->i_handle = 0;
-        
-        vlc_mutex_lock( &p_input->stream.stream_lock );
-        p_input->stream.b_pace_control = 1;
         p_input->stream.b_seekable = 0;
         p_input->stream.i_size = 0;
-        p_input->stream.i_tell = 0;
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
     }
     else
     {
-        if( stat( p_config->p_source, &stat_info ) == (-1) )
-        {
-            intf_ErrMsg("Cannot stat() file %s (%s)", p_config->p_source,
-                        strerror(errno));
-            p_input->b_error = 1;
-            return;
-        }
-
-        vlc_mutex_lock( &p_input->stream.stream_lock );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        intf_ErrMsg( "input error: unknown file type for %s",
+                     p_config->p_source );
+        p_input->b_error = 1;
+        return;
+    }
 
-        /* If we are here we can control the pace... */
-        p_input->stream.b_pace_control = 1;
+    p_input->stream.i_tell = 0;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-        if( S_ISREG(stat_info.st_mode) || S_ISCHR(stat_info.st_mode)
-             || S_ISBLK(stat_info.st_mode) )
-        {
-            p_input->stream.b_seekable = 1;
-            p_input->stream.i_size = stat_info.st_size;
-        }
-        else if( S_ISFIFO(stat_info.st_mode) || S_ISSOCK(stat_info.st_mode) )
-        {
-            p_input->stream.b_seekable = 0;
-            p_input->stream.i_size = 0;
-        }
-        else
-        {
-            vlc_mutex_unlock( &p_input->stream.stream_lock );
-            intf_ErrMsg("Unknown file type");
-            p_input->b_error = 1;
-            return;
-        }
+    intf_Msg( "input: opening file %s", p_config->p_source );
+    if( (p_input->i_handle = open( p_config->p_source,
+                                   /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
+    {
+        intf_ErrMsg( "input error: cannot open file %s", strerror(errno) );
+        p_input->b_error = 1;
+        return;
+    }
 
-        p_input->stream.i_tell = 0;
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
+#undef p_config
+}
 
-        intf_Msg( "Opening file %s", p_config->p_source );
-        if( (p_input->i_handle = open( p_config->p_source,
-                                       /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
-        {
-            intf_ErrMsg("Cannot open file (%s)", strerror(errno));
-            p_input->b_error = 1;
-            return;
-        }
+/*****************************************************************************
+ * DvdOpen : open the dvd device
+ *****************************************************************************/
+static void DvdOpen( input_thread_t * p_input )
+{
+    intf_Msg( "input: opening DVD %s", p_input->p_config->p_source );
+    if( (p_input->i_handle = open( p_input->p_config->p_source,
+                                   O_RDONLY|O_LARGEFILE )) == (-1) )
+    {
+        intf_ErrMsg( "input error: cannot open device %s", strerror(errno) );
+        p_input->b_error = 1;
+        return;
     }
 
-#undef p_config
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    p_input->stream.b_pace_control = 1;
+    p_input->stream.b_seekable = 1;
+    p_input->stream.i_size = 0;
+    p_input->stream.i_tell = 0;
+
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
 }