]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* Fixed the BeOS compile typo.
[vlc] / src / input / input.c
index 43c0b9fbc5bcdf73ae119c1441685bef5e6ec1c5..e444286d9a4b244d7603e6a68d3432fea7ca55ee 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.104 2001/05/01 04:18:18 sam Exp $
+ * $Id: input.c,v 1.113 2001/05/30 17:03:12 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 #endif
 #include <errno.h>
 
+/* WinSock Includes */
+
+#ifdef WIN32
+#include <winsock2.h>
+#endif
+
+
 /* Network functions */
 
 #if !defined( SYS_BEOS ) && !defined( SYS_NTO ) && !defined( WIN32 )
@@ -73,8 +80,6 @@
 
 #include "main.h"
 
- /* #include <netutils.h> */
-
 
 /*****************************************************************************
  * Local prototypes
@@ -85,6 +90,11 @@ static void ErrorThread     ( input_thread_t *p_input );
 static void DestroyThread   ( input_thread_t *p_input );
 static void EndThread       ( input_thread_t *p_input );
 
+static void FileOpen        ( input_thread_t *p_input );
+static void FileClose       ( input_thread_t *p_input );
+static void NetworkOpen     ( input_thread_t *p_input );
+static void NetworkClose    ( input_thread_t *p_input );
+
 /*****************************************************************************
  * input_CreateThread: creates a new input thread
  *****************************************************************************
@@ -133,6 +143,7 @@ input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
     p_input->stream.i_area_nb = 0;
     p_input->stream.pp_areas = NULL;
     p_input->stream.p_selected_area = NULL;
+    p_input->stream.p_new_area = NULL;
     /* By default there is one areas in a stream */
     input_AddArea( p_input );
     p_input->stream.p_selected_area = p_input->stream.pp_areas[0];
@@ -143,8 +154,13 @@ input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
     p_input->stream.control.b_mute = 0;
     p_input->stream.control.b_bw = 0;
 
-    /* Initialize default settings for spawned decoders */
-    p_input->p_default_vout = p_main->p_vout;
+    /* Setup callbacks */
+    p_input->pf_file_open     = FileOpen;
+    p_input->pf_file_close    = FileClose;
+#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
+    p_input->pf_network_open  = NetworkOpen;
+    p_input->pf_network_close = NetworkClose;
+#endif
 
     /* Create thread and set locks. */
     vlc_mutex_init( &p_input->stream.stream_lock );
@@ -242,6 +258,12 @@ static void RunThread( input_thread_t *p_input )
 
         vlc_mutex_lock( &p_input->stream.stream_lock );
 
+        if( p_input->stream.p_new_area )
+        {
+            p_input->pf_set_area( p_input, p_input->stream.p_new_area );
+            p_input->stream.p_new_area = NULL;
+        }
+
         if( p_input->stream.p_selected_area->i_seek != NO_SEEK )
         {
             if( p_input->stream.b_seekable && p_input->pf_seek != NULL )
@@ -264,6 +286,18 @@ static void RunThread( input_thread_t *p_input )
             p_input->stream.p_selected_area->i_seek = NO_SEEK;
         }
 
+        if( p_input->stream.p_removed_es )
+        {
+            input_UnselectES( p_input, p_input->stream.p_removed_es );
+            p_input->stream.p_removed_es = NULL;
+        }
+
+        if( p_input->stream.p_newly_selected_es )
+        {
+            input_SelectES( p_input, p_input->stream.p_newly_selected_es );
+            p_input->stream.p_newly_selected_es = NULL;
+        }
+
         vlc_mutex_unlock( &p_input->stream.stream_lock );
 
         i_error = p_input->pf_read( p_input, pp_packets );
@@ -280,7 +314,7 @@ static void RunThread( input_thread_t *p_input )
             {
                 /* End of file - we do not set b_die because only the
                  * interface is allowed to do so. */
-                intf_WarnMsg( 1, "input: EOF reached" );
+                intf_WarnMsg( 3, "input: EOF reached" );
                 p_input->b_eof = 1;
             }
             else
@@ -438,9 +472,9 @@ static void DestroyThread( input_thread_t * p_input )
 }
 
 /*****************************************************************************
- * input_FileOpen : open a file descriptor
+ * FileOpen : open a file descriptor
  *****************************************************************************/
-void input_FileOpen( input_thread_t * p_input )
+static void FileOpen( input_thread_t * p_input )
 {
     struct stat         stat_info;
     int                 i_stat;
@@ -509,7 +543,7 @@ void input_FileOpen( input_thread_t * p_input )
     p_input->stream.p_selected_area->i_tell = 0;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
-    intf_Msg( "input: opening file `%s'", p_input->p_source );
+    intf_WarnMsg( 1, "input: opening file `%s'", p_input->p_source );
 #ifndef WIN32
     if( (p_input->i_handle = open( psz_name,
                                    /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
@@ -526,31 +560,40 @@ void input_FileOpen( input_thread_t * p_input )
 }
 
 /*****************************************************************************
- * input_FileClose : close a file descriptor
+ * FileClose : close a file descriptor
  *****************************************************************************/
-void input_FileClose( input_thread_t * p_input )
+static void FileClose( input_thread_t * p_input )
 {
-    intf_Msg( "input: closing file `%s'", p_input->p_source );
+    intf_WarnMsg( 1, "input: closing file `%s'", p_input->p_source );
     close( p_input->i_handle );
 
     return;
 }
 
 
-#if !defined( SYS_BEOS ) && !defined( SYS_NTO ) && !defined( WIN32 )
+#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
 /*****************************************************************************
- * input_NetworkOpen : open a network socket 
+ * NetworkOpen : open a network socket 
  *****************************************************************************/
-void input_NetworkOpen( input_thread_t * p_input )
+static void NetworkOpen( input_thread_t * p_input )
 {
     char                *psz_server = NULL;
+    char                *psz_broadcast = NULL;
     int                 i_port = 0;
     int                 i_opt;
     struct sockaddr_in  sock;
-    char *              psz_broadcast;
-    
-    /* Are we broadcasting ? */
-    psz_broadcast = main_GetPszVariable( INPUT_BROADCAST_VAR, NULL );
+
+#ifdef WIN32
+    /* WinSock Library Init. */
+    WSADATA Data;
+    int i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
+
+    if( i_err )
+    {
+        intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
+        return ;
+    }
+#endif
     
     /* Get the remote server */
     if( p_input->p_source != NULL )
@@ -587,7 +630,31 @@ void input_NetworkOpen( input_thread_t * p_input )
                 *psz_port = '\0';
                 psz_port++;
 
-                i_port = atoi( psz_port );
+                psz_broadcast = psz_port;
+                while( *psz_broadcast && *psz_broadcast != ':' )
+                {
+                    psz_broadcast++;
+                }
+
+                if( *psz_broadcast )
+                {
+                    *psz_broadcast = '\0';
+                    psz_broadcast++;
+                    while( *psz_broadcast && *psz_broadcast == ':' )
+                    {
+                        psz_broadcast++;
+                    }
+                }
+                else
+                {
+                    psz_broadcast = NULL;
+                }
+
+                /* port before broadcast address */
+                if( *psz_port != ':' )
+                {
+                    i_port = atoi( psz_port );
+                }
             }
         }
         else
@@ -608,7 +675,25 @@ void input_NetworkOpen( input_thread_t * p_input )
     {
         i_port = main_GetIntVariable( INPUT_PORT_VAR, INPUT_PORT_DEFAULT );
     }
-    
+
+    if( psz_broadcast == NULL )
+    {
+        /* Are we broadcasting ? */
+        if( main_GetIntVariable( INPUT_BROADCAST_VAR,
+                                 INPUT_BROADCAST_DEFAULT ) )
+        {
+            psz_broadcast = main_GetPszVariable( INPUT_BCAST_ADDR_VAR,
+                                                 INPUT_BCAST_ADDR_DEFAULT );
+        }
+        else
+        {
+           psz_broadcast = NULL; 
+        }
+    }
+
+    intf_WarnMsg( 2, "input: server: %s port: %d broadcast: %s",
+                     psz_server, i_port, psz_broadcast );
+
     /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
      * protocol */
     p_input->i_handle = socket( AF_INET, SOCK_DGRAM, 0 );
@@ -624,8 +709,8 @@ void input_NetworkOpen( input_thread_t * p_input )
     if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_REUSEADDR,
                     &i_opt, sizeof( i_opt ) ) == -1 )
     {
-        intf_ErrMsg("input error: can't configure socket (SO_REUSEADDR: %s)",
-                    strerror(errno));
+        intf_ErrMsg( "input error: can't configure socket (SO_REUSEADDR: %s)",
+                     strerror(errno));
         close( p_input->i_handle );
         p_input->b_error = 1;
         return;
@@ -637,17 +722,17 @@ void input_NetworkOpen( input_thread_t * p_input )
     if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_RCVBUF,
                     &i_opt, sizeof( i_opt ) ) == -1 )
     {
-        intf_ErrMsg("input error: can't configure socket (SO_RCVBUF: %s)", 
-                    strerror(errno));
+        intf_ErrMsg( "input error: can't configure socket (SO_RCVBUF: %s)", 
+                     strerror(errno));
         close( p_input->i_handle );
         p_input->b_error = 1;
         return;
     }
 
     /* Build the local socket */
-    if ( network_BuildLocalAddr( &sock, i_port, psz_broadcast ) 
-         == -1 )
+    if ( network_BuildLocalAddr( &sock, i_port, psz_broadcast ) == -1 )
     {
+        intf_ErrMsg( "input error: can't build local address" );
         close( p_input->i_handle );
         p_input->b_error = 1;
         return;
@@ -666,6 +751,7 @@ void input_NetworkOpen( input_thread_t * p_input )
     /* Build socket for remote connection */
     if ( network_BuildRemoteAddr( &sock, psz_server ) == -1 )
     {
+        intf_ErrMsg( "input error: can't build remote address" );
         close( p_input->i_handle );
         p_input->b_error = 1;
         return;
@@ -675,7 +761,7 @@ void input_NetworkOpen( input_thread_t * p_input )
     if( connect( p_input->i_handle, (struct sockaddr *) &sock,
                  sizeof( sock ) ) == (-1) )
     {
-        intf_ErrMsg( "NetworkOpen: can't connect socket : %s", 
+        intf_ErrMsg( "input error: can't connect socket, %s", 
                      strerror(errno) );
         close( p_input->i_handle );
         p_input->b_error = 1;
@@ -686,15 +772,23 @@ void input_NetworkOpen( input_thread_t * p_input )
      * with the server. */
     p_input->stream.b_pace_control = 0;
     p_input->stream.b_seekable = 0;
+
+    intf_WarnMsg( 3, "input: successfully opened network mode" );
     
     return;
 }
 
 /*****************************************************************************
- * input_NetworkClose : close a network socket
+ * NetworkClose : close a network socket
  *****************************************************************************/
-void input_NetworkClose( input_thread_t * p_input )
+static void NetworkClose( input_thread_t * p_input )
 {
     close( p_input->i_handle );
+
+#ifdef WIN32 
+    WSACleanup();
+#endif
+
 }
 #endif
+