- int * pi_status; /* thread status */
-
- /* Store status */
- pi_status = p_input->pi_status;
-
- /* 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;
-}
-
-/*****************************************************************************
- * FileOpen : open a file descriptor
- *****************************************************************************/
-static void FileOpen( input_thread_t * p_input )
-{
- struct stat stat_info;
- int i_stat;
-
- char *psz_name = p_input->p_source;
-
- /* FIXME: this code ought to be in the plugin so that code can
- * be shared with the *_Probe function */
- if( ( i_stat = stat( psz_name, &stat_info ) ) == (-1) )
- {
- int i_size = strlen( psz_name );
-
- if( ( i_size > 4 )
- && !strncasecmp( psz_name, "dvd:", 4 ) )
- {
- /* get rid of the 'dvd:' stuff and try again */
- psz_name += 4;
- i_stat = stat( psz_name, &stat_info );
- }
- else if( ( i_size > 5 )
- && !strncasecmp( psz_name, "file:", 5 ) )
- {
- /* get rid of the 'file:' stuff and try again */
- psz_name += 5;
- i_stat = stat( psz_name, &stat_info );
- }
-
- if( i_stat == (-1) )
- {
- intf_ErrMsg( "input error: cannot stat() file `%s' (%s)",
- psz_name, 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.p_selected_area->i_size = stat_info.st_size;
- }
- else if( S_ISFIFO(stat_info.st_mode)
-#if !defined( SYS_BEOS ) && !defined( WIN32 )
- || S_ISSOCK(stat_info.st_mode)
-#endif
- )
- {
- p_input->stream.b_seekable = 0;
- p_input->stream.p_selected_area->i_size = 0;
- }
- else
- {
- vlc_mutex_unlock( &p_input->stream.stream_lock );
- intf_ErrMsg( "input error: unknown file type for `%s'",
- psz_name );
- p_input->b_error = 1;
- return;
- }
-
- p_input->stream.p_selected_area->i_tell = 0;
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- 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) )
-#else
- if( (p_input->i_handle = open( psz_name, O_BINARY
- /*O_NONBLOCK | O_LARGEFILE*/ )) == (-1) )
-#endif
- {
- intf_ErrMsg( "input error: cannot open file (%s)", strerror(errno) );
- p_input->b_error = 1;
- return;
- }
-
-}
-
-/*****************************************************************************
- * FileClose : close a file descriptor
- *****************************************************************************/
-static void FileClose( input_thread_t * p_input )
-{
- intf_WarnMsg( 1, "input: closing file `%s'", p_input->p_source );
- close( p_input->i_handle );
-
- return;
-}
-
-
-#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
-/*****************************************************************************
- * NetworkOpen : open a network socket
- *****************************************************************************/
-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;
-
-#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 )
- {
- psz_server = p_input->p_source;
-
- /* Skip the protocol name */
- while( *psz_server && *psz_server != ':' )
- {
- psz_server++;
- }
-
- /* Skip the "://" part */
- while( *psz_server && (*psz_server == ':' || *psz_server == '/') )
- {
- psz_server++;
- }
-
- /* Found a server name */
- if( *psz_server )
- {
- char *psz_port = psz_server;
-
- /* Skip the hostname part */
- while( *psz_port && *psz_port != ':' )
- {
- psz_port++;
- }
-
- /* Found a port name */
- if( *psz_port )
- {
- /* Replace ':' with '\0' */
- *psz_port = '\0';
- 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
- {
- psz_server = NULL;
- }
- }
-
- /* Check that we got a valid server */
- if( psz_server == NULL )
- {
- psz_server = main_GetPszVariable( INPUT_SERVER_VAR,
- INPUT_SERVER_DEFAULT );
- }
-
- /* Check that we got a valid port */
- if( i_port == 0 )
- {
- 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 );
- if( p_input->i_handle == -1 )
- {
- intf_ErrMsg("input error: can't create socket : %s", strerror(errno));
- p_input->b_error = 1;
- return;
- }
-
- /* We may want to reuse an already used socket */
- i_opt = 1;
- if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_REUSEADDR,
- (void*) &i_opt, sizeof( i_opt ) ) == -1 )
- {
- intf_ErrMsg( "input error: can't configure socket (SO_REUSEADDR: %s)",
- strerror(errno));
- close( p_input->i_handle );
- p_input->b_error = 1;
- return;
- }
-
- /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
- * packet loss caused by scheduling problems */
- i_opt = 0x80000;
- if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_RCVBUF,
- (void*) &i_opt, sizeof( i_opt ) ) == -1 )
- {
- 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 )
- {
- intf_ErrMsg( "input error: can't build local address" );
- close( p_input->i_handle );
- p_input->b_error = 1;
- return;
- }
-
- /* Bind it */
- if( bind( p_input->i_handle, (struct sockaddr *)&sock,
- sizeof( sock ) ) < 0 )
- {
- intf_ErrMsg("input error: can't bind socket (%s)", strerror(errno));
- close( p_input->i_handle );
- p_input->b_error = 1;
- return;
- }
-
- /* 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;
- }
-
- /* And connect it ... should we really connect ? */
- if( connect( p_input->i_handle, (struct sockaddr *) &sock,
- sizeof( sock ) ) == (-1) )
- {
- intf_ErrMsg( "input error: can't connect socket, %s",
- strerror(errno) );
- close( p_input->i_handle );
- p_input->b_error = 1;
- return;
- }