# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
#include <vlc_interface.h>
#include <vlc_input.h>
#include <vlc_es_out.h>
#define NETSYNC_PORT 9875
-/* Needed for Solaris */
-#ifndef INADDR_NONE
-#define INADDR_NONE 0xffffffff
-#endif
-
/* FIXME: UGLY UGLY !! Netsync should be totally reworked */
#include "../../src/input/input_internal.h"
#define MIP_LONGTEXT N_( "IP address of " \
"the master client used for the network synchronisation." )
-vlc_module_begin();
- set_shortname( _("Network Sync"));
- set_description( _("Network synchronisation") );
- set_category( CAT_ADVANCED );
- set_subcategory( SUBCAT_ADVANCED_MISC );
+vlc_module_begin ()
+ set_shortname( N_("Network Sync"))
+ set_description( N_("Network synchronisation") )
+ set_category( CAT_ADVANCED )
+ set_subcategory( SUBCAT_ADVANCED_MISC )
add_bool( "netsync-master", 0, NULL,
- NETSYNC_TEXT, NETSYNC_LONGTEXT, true );
+ NETSYNC_TEXT, NETSYNC_LONGTEXT, true )
add_string( "netsync-master-ip", NULL, NULL, MIP_TEXT, MIP_LONGTEXT,
- true );
+ true )
- set_capability( "interface", 0 );
- set_callbacks( Activate, Close );
-vlc_module_end();
-
-struct intf_sys_t
-{
- input_thread_t *p_input;
-};
+ set_capability( "interface", 0 )
+ set_callbacks( Activate, Close )
+vlc_module_end ()
/*****************************************************************************
* Local prototypes
static int Activate( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t*)p_this;
+ int fd;
- p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
- if( !p_intf->p_sys )
+ if( config_GetInt( p_intf, "netsync-master" ) <= 0 )
{
- msg_Err( p_intf, "no memory" );
- return VLC_ENOMEM;
+ char *psz_master = config_GetPsz( p_intf, "netsync-master-ip" );
+ if( psz_master == NULL )
+ {
+ msg_Err( p_intf, "master address not specified" );
+ return VLC_EGENERIC;
+ }
+ fd = net_ConnectUDP( VLC_OBJECT(p_intf), psz_master, NETSYNC_PORT, -1 );
+ free( psz_master );
}
+ else
+ fd = net_ListenUDP1( VLC_OBJECT(p_intf), NULL, NETSYNC_PORT );
- p_intf->p_sys->p_input = NULL;
+ if( fd == -1 )
+ {
+ msg_Err( p_intf, "Netsync socket failure" );
+ return VLC_EGENERIC;
+ }
+ p_intf->p_sys = (void *)(intptr_t)fd;
p_intf->pf_run = Run;
return VLC_SUCCESS;
}
{
intf_thread_t *p_intf = (intf_thread_t*)p_this;
- free( p_intf->p_sys );
+ net_Close( (intptr_t)p_intf->p_sys );
}
/*****************************************************************************
{
#define MAX_MSG_LENGTH (2 * sizeof(int64_t))
- bool b_master = config_GetInt( p_intf, "netsync-master" );
- char *psz_master = NULL;
+ input_thread_t *p_input = NULL;
char p_data[MAX_MSG_LENGTH];
int i_socket;
-
- if( !b_master )
- {
- psz_master = config_GetPsz( p_intf, "netsync-master-ip" );
- if( psz_master == NULL )
- {
- msg_Err( p_intf, "master address not specified" );
- return;
- }
- }
-
- if( b_master )
- i_socket = net_ListenUDP1( VLC_OBJECT(p_intf), NULL, NETSYNC_PORT );
- else
- i_socket = net_ConnectUDP( VLC_OBJECT(p_intf), psz_master, NETSYNC_PORT, 0 );
-
- free( psz_master );
-
- if( i_socket < 0 )
- {
- msg_Err( p_intf, "failed opening UDP socket" ); /* str review: is this good enough? */
- return;
- }
+ int canc = vlc_savecancel();
/* High priority thread */
vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_INPUT );
- while( !intf_ShouldDie( p_intf ) )
+ while( vlc_object_alive( p_intf ) )
{
/* Update the input */
- if( p_intf->p_sys->p_input == NULL )
- {
- p_intf->p_sys->p_input =
+ if( p_input == NULL )
+ p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
- }
- else if( p_intf->p_sys->p_input->b_dead )
+ else if( p_input->b_dead )
{
- vlc_object_release( p_intf->p_sys->p_input );
- p_intf->p_sys->p_input = NULL;
+ vlc_object_release( p_input );
+ p_input = NULL;
}
- if( p_intf->p_sys->p_input == NULL )
+ if( p_input == NULL )
{
/* Wait a bit */
msleep( INTF_IDLE_SLEEP );
((i_receive_date - i_send_date) / 2 + i_master_date);
i_client_clockref = i_drift = 0;
- if( p_intf->p_sys->p_input && i_master_clockref )
+ if( p_input && i_master_clockref )
{
i_client_clockref = GetClockRef( p_intf, i_clockref );
i_drift = i_client_clockref - i_master_clockref - i_diff_date;
/* Update our clock to match the master's one */
if( i_client_clockref )
- p_intf->p_sys->p_input->i_pts_delay -= i_drift;
+ p_input->i_pts_delay -= i_drift;
}
#if 0
}
}
- if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
- net_Close( i_socket );
+ if( p_input ) vlc_object_release( p_input );
+ vlc_restorecancel( canc );
}
static mtime_t GetClockRef( intf_thread_t *p_intf, mtime_t i_pts )