Commit 043b5c89 authored by Sam Hocevar's avatar Sam Hocevar

  * Automatic handling of the Channel Server's response in network mode.
parent b70a26fa
.* .*
core core
core.*
.dep .dep
gmon.out gmon.out
vlc-debug.log vlc-debug.log
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* modules. * modules.
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: netutils.h,v 1.15 2001/10/22 12:28:53 massiot Exp $ * $Id: netutils.h,v 1.16 2001/11/12 04:12:37 sam Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Henri Fallon <henri@videolan.org> * Henri Fallon <henri@videolan.org>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
*****************************************************************************/ *****************************************************************************/
struct sockaddr_in; struct sockaddr_in;
int network_BuildLocalAddr ( struct sockaddr_in *, int, char * ); int network_BuildLocalAddr ( struct sockaddr_in *, int, char * );
int network_BuildRemoteAddr( struct sockaddr_in *, char * ); int network_BuildRemoteAddr ( struct sockaddr_in *, char * );
int network_ChannelJoin ( int ); int network_ChannelJoin ( int );
int network_ChannelCreate ( void ); int network_ChannelCreate ( void );
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* gtk_callbacks.c : Callbacks for the Gtk+ plugin. * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
***************************************************************************** *****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN * Copyright (C) 2000, 2001 VideoLAN
* $Id: gtk_callbacks.c,v 1.24 2001/05/31 16:10:05 stef Exp $ * $Id: gtk_callbacks.c,v 1.25 2001/11/12 04:12:37 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* Stphane Borel <stef@via.ecp.fr> * Stphane Borel <stef@via.ecp.fr>
...@@ -326,12 +326,16 @@ void GtkChannelGo( GtkButton * button, gpointer user_data ) ...@@ -326,12 +326,16 @@ void GtkChannelGo( GtkButton * button, gpointer user_data )
/* FIXME: ugly hack to close input and outputs */ /* FIXME: ugly hack to close input and outputs */
p_intf->pf_manage( p_intf ); p_intf->pf_manage( p_intf );
}
network_ChannelJoin( i_channel );
/* FIXME 2 */
p_main->p_playlist->b_stopped = 0; p_main->p_playlist->b_stopped = 0;
p_intf->pf_manage( p_intf ); p_intf->pf_manage( p_intf );
}
vlc_mutex_unlock( &p_intf->change_lock ); vlc_mutex_unlock( &p_intf->change_lock );
network_ChannelJoin( i_channel );
input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY ); input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN * Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: input.c,v 1.152 2001/11/09 13:49:26 massiot Exp $ * $Id: input.c,v 1.153 2001/11/12 04:12:37 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -534,7 +534,6 @@ static void EndThread( input_thread_t * p_input ) ...@@ -534,7 +534,6 @@ static void EndThread( input_thread_t * p_input )
/* Release modules */ /* Release modules */
module_Unneed( p_input->p_input_module ); module_Unneed( p_input->p_input_module );
} }
/***************************************************************************** /*****************************************************************************
...@@ -812,6 +811,11 @@ static void NetworkOpen( input_thread_t * p_input ) ...@@ -812,6 +811,11 @@ static void NetworkOpen( input_thread_t * p_input )
psz_server = NULL; psz_server = NULL;
} }
} }
else
{
/* This is required or NetworkClose will never be called */
p_input->p_source = "ts: network input";
}
/* Check that we got a valid server */ /* Check that we got a valid server */
if( psz_server == NULL ) if( psz_server == NULL )
...@@ -986,6 +990,8 @@ static void NetworkOpen( input_thread_t * p_input ) ...@@ -986,6 +990,8 @@ static void NetworkOpen( input_thread_t * p_input )
*****************************************************************************/ *****************************************************************************/
static void NetworkClose( input_thread_t * p_input ) static void NetworkClose( input_thread_t * p_input )
{ {
intf_WarnMsg( 2, "input: closing network target `%s'", p_input->p_source );
close( p_input->i_handle ); close( p_input->i_handle );
#ifdef WIN32 #ifdef WIN32
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* intf_playlist.c : Playlist management functions * intf_playlist.c : Playlist management functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * Copyright (C) 1999, 2000 VideoLAN
* $Id: intf_playlist.c,v 1.8 2001/08/09 08:20:26 sam Exp $ * $Id: intf_playlist.c,v 1.9 2001/11/12 04:12:38 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* netutils.c: various network functions * netutils.c: various network functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: netutils.c,v 1.40 2001/11/12 03:07:13 stef Exp $ * $Id: netutils.c,v 1.41 2001/11/12 04:12:38 sam Exp $
* *
* Authors: Vincent Seguin <seguin@via.ecp.fr> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Benoit Steiner <benny@via.ecp.fr> * Benoit Steiner <benny@via.ecp.fr>
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
#include <errno.h> /* errno() */ #include <errno.h> /* errno() */
#include <string.h> /* memset() */ #include <string.h> /* memset() */
#ifdef STRNCASECMP_IN_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> /* gethostname() */ #include <unistd.h> /* gethostname() */
#elif defined( _MSC_VER ) && defined( _WIN32 ) #elif defined( _MSC_VER ) && defined( _WIN32 )
...@@ -77,6 +81,7 @@ ...@@ -77,6 +81,7 @@
#include "main.h" #include "main.h"
#include "intf_msg.h" #include "intf_msg.h"
#include "intf_playlist.h"
#include "netutils.h" #include "netutils.h"
...@@ -97,7 +102,7 @@ typedef struct input_channel_s ...@@ -97,7 +102,7 @@ typedef struct input_channel_s
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int GetMacAddress ( int i_socket, char *psz_mac ); static int GetMacAddress ( int i_fd, char *psz_mac );
#ifdef WIN32 #ifdef WIN32
static int GetAdapterInfo ( int i_adapter, char *psz_string ); static int GetAdapterInfo ( int i_adapter, char *psz_string );
#endif #endif
...@@ -213,14 +218,7 @@ int network_BuildRemoteAddr( struct sockaddr_in * p_socket, char * psz_server ) ...@@ -213,14 +218,7 @@ int network_BuildRemoteAddr( struct sockaddr_in * p_socket, char * psz_server )
*****************************************************************************/ *****************************************************************************/
int network_ChannelCreate( void ) int network_ChannelCreate( void )
{ {
/* Even when BSD are supported, BeOS is not likely to be supported, so #if defined( SYS_LINUX ) || defined( WIN32 )
* I prefer to put it apart */
#if defined( SYS_BEOS )
intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
return( 1 );
/* FIXME : channel handling only work for linux */
#elif defined( SYS_LINUX ) || defined( WIN32 )
/* Allocate structure */ /* Allocate structure */
p_main->p_channel = malloc( sizeof( input_channel_t ) ); p_main->p_channel = malloc( sizeof( input_channel_t ) );
...@@ -234,11 +232,11 @@ int network_ChannelCreate( void ) ...@@ -234,11 +232,11 @@ int network_ChannelCreate( void )
p_main->p_channel->i_channel = 0; p_main->p_channel->i_channel = 0;
p_main->p_channel->last_change = 0; p_main->p_channel->last_change = 0;
intf_Msg( "network: channels initialized" ); intf_WarnMsg( 2, "network: channels initialized" );
return( 0 ); return( 0 );
#else #else
intf_ErrMsg( "network error : channels not supported" ); intf_ErrMsg( "network error : channels not supported on this platform" );
return( 1 ); return( 1 );
#endif #endif
...@@ -251,182 +249,154 @@ int network_ChannelCreate( void ) ...@@ -251,182 +249,154 @@ int network_ChannelCreate( void )
* already on the good channel, nothing will be done. Else, and if possible * already on the good channel, nothing will be done. Else, and if possible
* (if the interface is not locked), the channel server will be contacted * (if the interface is not locked), the channel server will be contacted
* and a change will be requested. The function will block until the change * and a change will be requested. The function will block until the change
* is effective. Note that once a channel is no more used, it's interface * is effective. Note that once a channel is no more used, its interface
* should be unlocked using input_ChannelLeave(). * should be unlocked using input_ChannelLeave().
* Non 0 will be returned in case of error. * Non 0 will be returned in case of error.
*****************************************************************************/ *****************************************************************************/
int network_ChannelJoin( int i_channel ) int network_ChannelJoin( int i_channel )
{ {
/* I still prefer to put BeOS a bit apart */ #if defined( SYS_LINUX ) || defined( WIN32 )
#if defined( SYS_BEOS )
intf_ErrMsg( "network error: channels are not yet supported under BeOS" ); #define VLCS_VERSION 12
return( -1 ); #define MESSAGE_LENGTH 80
#elif defined( SYS_LINUX ) || defined( WIN32 ) char psz_mess[ MESSAGE_LENGTH ];
int i_socket; char psz_mac[ 40 ];
int i_fromlen; int i_fd, i_dummy, i_port;
char *psz_vlcs;
struct sockaddr_in sa_server; struct sockaddr_in sa_server;
struct sockaddr_in sa_client; struct sockaddr_in sa_client;
unsigned int i_version = 12; struct timeval delay;
char psz_mess[ 80 ];
char psz_mac[ 40 ];
char i_mess_length = 80;
unsigned long int i_date;
struct timeval answer_delay;
int i_nbanswer;
char i_answer;
fd_set fds; fd_set fds;
unsigned int i_rc;
char * psz_channel_server;
if( !main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR, if( !main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
INPUT_NETWORK_CHANNEL_DEFAULT ) ) INPUT_NETWORK_CHANNEL_DEFAULT ) )
{ {
intf_ErrMsg( "network: channels disabled, to enable them, use the" intf_ErrMsg( "network: channels disabled, to enable them, use the"
"--channels option" ); "--channels option" );
return( -1 ); return -1;
} }
/* debug */
intf_DbgMsg( "network: ChannelJoin : %d", i_channel );
/* If last change is too recent, wait a while */ /* If last change is too recent, wait a while */
if( mdate() - p_main->p_channel->last_change < INPUT_CHANNEL_CHANGE_DELAY ) if( mdate() - p_main->p_channel->last_change < INPUT_CHANNEL_CHANGE_DELAY )
{ {
intf_WarnMsg( 2, "network: waiting before changing channel" ); intf_WarnMsg( 2, "network: waiting before changing channel" );
/* XXX Isn't this completely brain-damaged ??? -- Sam */
mwait( p_main->p_channel->last_change + INPUT_CHANNEL_CHANGE_DELAY ); mwait( p_main->p_channel->last_change + INPUT_CHANNEL_CHANGE_DELAY );
} }
p_main->p_channel->last_change = mdate(); /* Initializing the socket */
p_main->p_channel->i_channel = i_channel; i_fd = socket( AF_INET, SOCK_DGRAM, 0 );
intf_WarnMsg( 2, "network: joining channel %d", i_channel );
/* /* Getting information about the channel server */
* Initializing the socket psz_vlcs = main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
*/ INPUT_CHANNEL_SERVER_DEFAULT );
i_socket = socket( AF_INET, SOCK_DGRAM, 0 ); i_port = main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
INPUT_CHANNEL_PORT_DEFAULT );
/* intf_WarnMsg( 6, "network: vlcs '%s', port %d", psz_vlcs, i_port );
* Getting the server's information
*/
intf_WarnMsg( 6, "Channel server: %s port: %d",
main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
INPUT_CHANNEL_SERVER_DEFAULT ),
main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
INPUT_CHANNEL_PORT_DEFAULT ) );
memset( &sa_client, 0x00, sizeof(struct sockaddr_in) );
memset( &sa_server, 0x00, sizeof(struct sockaddr_in) ); memset( &sa_server, 0x00, sizeof(struct sockaddr_in) );
sa_client.sin_family = AF_INET;
sa_server.sin_family = AF_INET; sa_server.sin_family = AF_INET;
sa_server.sin_port = htons( main_GetIntVariable( INPUT_CHANNEL_PORT_VAR, sa_client.sin_port = htons( 4312 );
INPUT_CHANNEL_PORT_DEFAULT ) ); sa_server.sin_port = htons( i_port );
sa_client.sin_addr.s_addr = INADDR_ANY;
psz_channel_server = strdup( main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
INPUT_CHANNEL_SERVER_DEFAULT ) );
#ifdef HAVE_ARPA_INET_H #ifdef HAVE_ARPA_INET_H
inet_aton( psz_channel_server, &sa_server.sin_addr ); inet_aton( psz_vlcs, &sa_server.sin_addr );
#else #else
sa_server.sin_addr.s_addr = inet_addr( psz_channel_server ); sa_server.sin_addr.s_addr = inet_addr( psz_vlcs );
#endif #endif
free( psz_channel_server );
/* /* Bind the socket */
* Looking for the interface MAC address i_dummy = bind( i_fd, (struct sockaddr *)(&sa_client),
*/ sizeof(struct sockaddr) );
if( GetMacAddress( i_socket, psz_mac ) ) if ( i_dummy )
{
intf_ErrMsg( "network: unable to bind vlcs socket: %i", i_dummy );
return -1;
}
/* Look for the interface MAC address */
if( GetMacAddress( i_fd, psz_mac ) )
{ {
intf_ErrMsg( "network error: failed getting MAC address" ); intf_ErrMsg( "network error: failed getting MAC address" );
return( -1 ); return -1;
} }
/* intf_WarnMsg( 6, "network: MAC address is %s", psz_mac );
* Getting date of the client in seconds
*/
i_date = mdate() / 1000000;
intf_DbgMsg( "vlcs: date %lu", i_date );
/* /* Build the message */
* Build of the message sprintf( psz_mess, "%d %u %lu %s \n", i_channel, VLCS_VERSION,
*/ (unsigned long)(mdate() / (unsigned long long)1000000),
sprintf( psz_mess, "%d %u %lu %s \n", psz_mac );
i_channel, i_version, i_date, psz_mac );
intf_DbgMsg( "vlcs: The message is %s", psz_mess ); /* Send the message */
sendto( i_fd, psz_mess, MESSAGE_LENGTH, 0,
(struct sockaddr *)(&sa_server), sizeof(struct sockaddr) );
/* intf_WarnMsg( 2, "network: attempting to join channel %d", i_channel );
* Open the socket 2
*/
memset( &sa_client, 0x00, sizeof(struct sockaddr_in) );
sa_client.sin_family = AF_INET;
sa_client.sin_port = htons(4312);
sa_client.sin_addr.s_addr = INADDR_ANY;
i_fromlen = sizeof( struct sockaddr );
i_rc = bind( i_socket, (struct sockaddr *)(&sa_client),\
sizeof(struct sockaddr) );
if ( i_rc )
{
intf_ErrMsg( "vlcs: Unable to bind socket:%u ", i_rc );
/* TODO put CS_R_BIND in types.h*/
/* return CS_R_SOCKET;*/
return -1;
}
/* /* We have changed channels ! (or at least, we tried) */
* Send the message p_main->p_channel->last_change = mdate();
*/ p_main->p_channel->i_channel = i_channel;
sendto( i_socket, psz_mess, i_mess_length, 0, \
(struct sockaddr *)(&sa_server), \
sizeof(struct sockaddr) );
/* /* Wait 5 sec for an answer from the server */
* Waiting 5 sec for one answer from the server delay.tv_sec = 5;
*/ delay.tv_usec = 0;
answer_delay.tv_sec = 5;
answer_delay.tv_usec = 0;
FD_ZERO( &fds ); FD_ZERO( &fds );
FD_SET( i_socket, &fds ); FD_SET( i_fd, &fds );
i_nbanswer = select( i_socket + 1, &fds, NULL, NULL, &answer_delay ); i_dummy = select( i_fd + 1, &fds, NULL, NULL, &delay );
switch( i_nbanswer ) switch( i_dummy )
{ {
case 0: case 0:
intf_DbgMsg( "vlcs: no answer" ); intf_ErrMsg( "network error: no answer from vlcs" );
close( i_fd );
return -1;
break; break;
case -1: case -1:
intf_DbgMsg( "vlcs: unable to receive the answer "); intf_ErrMsg( "network error: error while listening to vlcs" );
close( i_fd );
return -1;
break; break;
}
default: i_dummy = sizeof( struct sockaddr );
recvfrom( i_socket, &i_answer, sizeof(char), 0,\ recvfrom( i_fd, psz_mess, MESSAGE_LENGTH, 0,
(struct sockaddr *)(&sa_client), &i_fromlen); (struct sockaddr *)(&sa_client), &i_dummy);
psz_mess[ MESSAGE_LENGTH - 1 ] = 0;
intf_DbgMsg( "vlcs: the answer : %i", i_answer );
switch( i_answer ) if( !strncasecmp( psz_mess, "E: ", 3 ) )
{ {
case -1: intf_ErrMsg( "network error: vlcs said '%s'", psz_mess + 3 );
intf_DbgMsg( "vlcs: the server failed to create the thread" ); close( i_fd );
break; return -1;
case 0:
intf_DbgMsg( "vlcs: the server tries to change the channel" );
break;
default:
intf_DbgMsg( "vlcs: unknown answer !" );
break;
} }
break; else if( !strncasecmp( psz_mess, "I: ", 3 ) )
{
intf_WarnMsg( 2, "network info: vlcs said '%s'", psz_mess + 3 );
}
else /* We got something to play ! FIXME: not very nice */
{
# define p_item \
(&p_main->p_playlist->p_item[ p_main->p_playlist->i_index + 1])
vlc_mutex_lock( &p_main->p_playlist->change_lock );
free( p_item->psz_name );
p_item->psz_name = strdup( psz_mess );
vlc_mutex_unlock( &p_main->p_playlist->change_lock );
} }
/* /* Close the socket and return nicely */
* Close the socket close( i_fd );
*/
close( i_socket );
return( 0 ); return 0;
#else #else
intf_ErrMsg( "network error: channels not supported" ); intf_ErrMsg( "network error: channels not supported on this platform" );
return( -1 ); return NULL;
#endif #endif
} }
...@@ -436,7 +406,7 @@ int network_ChannelJoin( int i_channel ) ...@@ -436,7 +406,7 @@ int network_ChannelJoin( int i_channel )
/***************************************************************************** /*****************************************************************************
* GetMacAddress: extract the MAC Address * GetMacAddress: extract the MAC Address
*****************************************************************************/ *****************************************************************************/
static int GetMacAddress( int i_socket, char *psz_mac ) static int GetMacAddress( int i_fd, char *psz_mac )
{ {
#if defined( SYS_LINUX ) #if defined( SYS_LINUX )
struct ifreq interface; struct ifreq interface;
...@@ -449,7 +419,7 @@ static int GetMacAddress( int i_socket, char *psz_mac ) ...@@ -449,7 +419,7 @@ static int GetMacAddress( int i_socket, char *psz_mac )
strcpy( interface.ifr_name, strcpy( interface.ifr_name,
main_GetPszVariable( INPUT_IFACE_VAR, INPUT_IFACE_DEFAULT ) ); main_GetPszVariable( INPUT_IFACE_VAR, INPUT_IFACE_DEFAULT ) );
i_ret = ioctl( i_socket, SIOCGIFHWADDR, &interface ); i_ret = ioctl( i_fd, SIOCGIFHWADDR, &interface );
if( i_ret ) if( i_ret )
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment