Commit 9ae4e6c1 authored by moret's avatar moret
Browse files

Improve timebase master setting in netjack2

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2803 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 6c05d125
......@@ -327,12 +327,12 @@ namespace Jack
//transport---------------------------------------------------------------------------
int JackNetDriver::DecodeTransportData()
{
//is there a new timebase master on the master ?
//is there a new timebase master on the net master ?
// - release timebase master only if it's a non-conditional request
// - no change or no request : don't do anything
// - conditional request : don't change anything too, the master will know if this slave is actually the timebase master
int refnum;
bool conditional;
//release timebase master only if it's a non-conditional request
//no request (NO_TIMEBASEMASTER) : don't do anything
//conditional request : don't change anything to, master will know if this slave is actually the timebase master
if ( fTransportData.fTimebaseMaster == TIMEBASEMASTER )
{
fEngineControl->fTransport.GetTimebaseMaster ( refnum, conditional );
......@@ -342,7 +342,7 @@ namespace Jack
}
//is there a tranport state change to handle ?
if ( fTransportData.fNewState && ( fTransportData.fState != (uint)fEngineControl->fTransport.GetState() ) )
if ( fTransportData.fNewState && ( fTransportData.fState != ( uint ) fEngineControl->fTransport.GetState() ) )
{
switch ( fTransportData.fState )
{
......@@ -367,17 +367,28 @@ namespace Jack
int JackNetDriver::EncodeTransportData()
{
//is there a new timebase master ?
//is there a timebase master change ?
int refnum;
bool conditional;
fEngineControl->fTransport.GetTimebaseMaster ( refnum, conditional );
if ( refnum != fLastTimebaseMaster )
{
fTransportData.fTimebaseMaster = ( conditional ) ? CONDITIONAL_TIMEBASEMASTER : TIMEBASEMASTER;
//timebase master has released its function
if ( refnum == -1 )
{
fTransportData.fTimebaseMaster = RELEASE_TIMEBASEMASTER;
jack_info ( "Sending a timebase master release request." );
}
//there is a new timebase master
else
{
fTransportData.fTimebaseMaster = ( conditional ) ? CONDITIONAL_TIMEBASEMASTER : TIMEBASEMASTER;
jack_info ( "Sending a %s timebase master request.", ( conditional ) ? "conditional" : "non-conditional" );
}
fLastTimebaseMaster = refnum;
}
else
fTransportData.fTimebaseMaster = NO_TIMEBASEMASTER;
fTransportData.fTimebaseMaster = NO_CHANGE;
//update transport state and position
fTransportData.fState = fEngineControl->fTransport.Query ( &fTransportData.fPosition );
......
......@@ -229,10 +229,10 @@ namespace Jack
{
//is there a new timebase master ?
//TODO : check if any timebase callback has been called (and if it's conditional or not) and set correct value...
fTransportData.fTimebaseMaster = NO_TIMEBASEMASTER;
fTransportData.fTimebaseMaster = NO_CHANGE;
//update state and position
fTransportData.fState = static_cast<uint32_t> ( jack_transport_query ( fJackClient, &fTransportData.fPosition ) );
fTransportData.fState = static_cast<uint> ( jack_transport_query ( fJackClient, &fTransportData.fPosition ) );
//is it a new state ?
fTransportData.fNewState = ( fTransportData.fState != fLastTransportState );
......@@ -245,35 +245,41 @@ namespace Jack
int JackNetMaster::DecodeTransportData()
{
//is the slave a new timebase master ?
int timebase;
switch ( fTransportData.fTimebaseMaster )
//is there timebase master change ?
if ( fTransportData.fTimebaseMaster != NO_CHANGE )
{
case NO_TIMEBASEMASTER :
break;
case TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 0, SetTimebaseCallback, this );
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master." );
else
jack_info ( "'%s' is the new timebase master.", fParams.fName );
break;
case CONDITIONAL_TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 1, SetTimebaseCallback, this );
if ( timebase < 0 )
{
if ( timebase == EBUSY )
jack_error ( "'%s' is already the timebase master.", fParams.fName );
int timebase = 0;
switch ( fTransportData.fTimebaseMaster )
{
case RELEASE_TIMEBASEMASTER :
timebase = jack_release_timebase ( fJackClient );
if ( timebase < 0 )
jack_error ( "Can't release timebase master." );
else
jack_info ( "'%s' isn't the timebase master anymore.", fParams.fName );
break;
case TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 0, SetTimebaseCallback, this );
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master." );
}
else
jack_info ( "'%s' is the new timebase master.", fParams.fName );
break;
else
jack_info ( "'%s' is the new timebase master.", fParams.fName );
break;
case CONDITIONAL_TIMEBASEMASTER :
timebase = jack_set_timebase_callback ( fJackClient, 1, SetTimebaseCallback, this );
if ( timebase != EBUSY )
{
if ( timebase < 0 )
jack_error ( "Can't set a new timebase master." );
else
jack_info ( "'%s' is the new timebase master.", fParams.fName );
}
break;
}
}
//is the slave in a new transport state and is this state different from master's ?
if ( fTransportData.fNewState && ( fTransportData.fState != (uint)jack_transport_query ( fJackClient, NULL ) ) )
if ( fTransportData.fNewState && ( fTransportData.fState != ( uint ) jack_transport_query ( fJackClient, NULL ) ) )
{
switch ( fTransportData.fState )
{
......@@ -497,7 +503,7 @@ namespace Jack
int ret = 1;
master_list_it_t it;
for ( it = fMasterList.begin(); it != fMasterList.end(); it++ )
if ( !( *it )->IsSlaveReadyToRoll() )
if ( ! ( *it )->IsSlaveReadyToRoll() )
ret = 0;
jack_log ( "JackNetMasterManager::SyncCallback returns '%s'", ( ret ) ? "true" : "false" );
return ret;
......
......@@ -75,7 +75,7 @@ namespace Jack
int DecodeSyncPacket();
int Process();
void TimebaseCallback ( jack_position_t* pos);
void TimebaseCallback ( jack_position_t* pos );
public:
JackNetMaster ( JackNetSocket& socket, session_params_t& params, const char* multicast_ip );
......
......@@ -159,9 +159,10 @@ namespace Jack
enum _net_timebase_master
{
NO_TIMEBASEMASTER = 0,
TIMEBASEMASTER = 1,
CONDITIONAL_TIMEBASEMASTER = 2
NO_CHANGE = 0,
RELEASE_TIMEBASEMASTER = 1,
TIMEBASEMASTER = 2,
CONDITIONAL_TIMEBASEMASTER = 3
};
typedef enum _net_timebase_master net_timebase_master_t;
......
Supports Markdown
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