* decoders.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.105 2001/05/01 12:22: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 )
#include "main.h"
- /* #include <netutils.h> */
-
/*****************************************************************************
* Local prototypes
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
*****************************************************************************
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];
p_input->stream.control.b_mute = 0;
p_input->stream.control.b_bw = 0;
+ /* 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 );
vlc_cond_init( &p_input->stream.stream_wait );
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 )
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 );
{
/* 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
}
/*****************************************************************************
- * 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;
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) )
}
/*****************************************************************************
- * 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 )
*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
{
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( 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;
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;
/* 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;
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;
* 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
+