Commit 2509baae authored by moret's avatar moret
Browse files

Cleanup.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2805 0c269be4-1314-0410-8aa9-9f06e86f4224
parent e9a01a0a
This diff is collapsed.
......@@ -27,7 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackNetAdapter::JackNetAdapter ( jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params )
JackNetAdapter::JackNetAdapter ( jack_client_t* jack_client, jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params )
: JackAudioAdapterInterface ( buffer_size, sample_rate ), JackNetSlaveInterface(), fThread ( this )
{
jack_log ( "JackNetAdapter::JackNetAdapter" );
......@@ -42,7 +42,7 @@ namespace Jack
GetHostName ( fParams.fName, JACK_CLIENT_NAME_SIZE );
fSocket.GetName ( fParams.fSlaveNetName );
fParams.fMtu = 1500;
fParams.fTransportSync = 1;
fParams.fTransportSync = 0;
fParams.fSendAudioChannels = 2;
fParams.fReturnAudioChannels = 2;
fParams.fSendMidiChannels = 0;
......@@ -51,6 +51,7 @@ namespace Jack
fParams.fPeriodSize = buffer_size;
fParams.fSlaveSyncMode = 1;
fParams.fNetworkMode = 'n';
fJackClient = jack_client;
//options parsing
const JSList* node;
......@@ -82,7 +83,7 @@ namespace Jack
strncpy ( fParams.fName, param->value.str, JACK_CLIENT_NAME_SIZE );
break;
case 't' :
fParams.fTransportSync = param->value.ui;
//fParams.fTransportSync = param->value.ui;
break;
case 'm' :
if ( strcmp ( param->value.str, "normal" ) == 0 )
......@@ -129,6 +130,7 @@ namespace Jack
}
}
//open/close--------------------------------------------------------------------------
int JackNetAdapter::Open()
{
jack_log ( "JackNetAdapter::Open" );
......@@ -182,6 +184,7 @@ namespace Jack
return 0;
}
//thread------------------------------------------------------------------------------
bool JackNetAdapter::Init()
{
jack_log ( "JackNetAdapter::Init" );
......@@ -245,22 +248,134 @@ namespace Jack
}
}
//transport---------------------------------------------------------------------------
int JackNetAdapter::DecodeTransportData()
{
//TODO : we need here to get the actual timebase master to eventually release it from its duty (see JackNetDriver)
//is there a new transport state ?
if ( fSendTransportData.fNewState && ( fSendTransportData.fState != jack_transport_query ( fJackClient, NULL ) ) )
{
switch ( fSendTransportData.fState )
{
case JackTransportStopped :
jack_transport_stop ( fJackClient );
jack_info ( "NetMaster : transport stops." );
break;
case JackTransportStarting :
jack_transport_reposition ( fJackClient, &fSendTransportData.fPosition );
jack_transport_start ( fJackClient );
jack_info ( "NetMaster : transport starts." );
break;
case JackTransportRolling :
//TODO , we need to :
// - find a way to call TransportEngine->SetNetworkSync()
// - turn the transport state to JackTransportRolling
jack_info ( "NetMaster : transport rolls." );
break;
}
}
return 0;
}
int JackNetAdapter::EncodeTransportData()
{
//is there a timebase master change ?
int refnum = -1;
bool conditional = 0;
//TODO : get the actual timebase master
if ( refnum != fLastTimebaseMaster )
{
//timebase master has released its function
if ( refnum == -1 )
{
fReturnTransportData.fTimebaseMaster = RELEASE_TIMEBASEMASTER;
jack_info ( "Sending a timebase master release request." );
}
//there is a new timebase master
else
{
fReturnTransportData.fTimebaseMaster = ( conditional ) ? CONDITIONAL_TIMEBASEMASTER : TIMEBASEMASTER;
jack_info ( "Sending a %s timebase master request.", ( conditional ) ? "conditional" : "non-conditional" );
}
fLastTimebaseMaster = refnum;
}
else
fReturnTransportData.fTimebaseMaster = NO_CHANGE;
//update transport state and position
fReturnTransportData.fState = jack_transport_query ( fJackClient, &fReturnTransportData.fPosition );
//is it a new state (that the master need to know...) ?
fReturnTransportData.fNewState = ( ( fReturnTransportData.fState != fLastTransportState ) &&
( fReturnTransportData.fState != fSendTransportData.fState ) );
if ( fReturnTransportData.fNewState )
jack_info ( "Sending transport state '%s'.", GetTransportState ( fReturnTransportData.fState ) );
fLastTransportState = fReturnTransportData.fState;
return 0;
}
//network sync------------------------------------------------------------------------
int JackNetAdapter::DecodeSyncPacket()
{
//this method contains every step of sync packet informations decoding process
//first : transport
if ( fParams.fTransportSync )
{
//copy received transport data to transport data structure
memcpy ( &fSendTransportData, fRxData, sizeof ( net_transport_data_t ) );
if ( DecodeTransportData() < 0 )
return -1;
}
//then others
//...
return 0;
}
int JackNetAdapter::EncodeSyncPacket()
{
//this method contains every step of sync packet informations coding
//first of all, reset sync packet
memset ( fTxData, 0, fPayloadSize );
//then first step : transport
if ( fParams.fTransportSync )
{
if ( EncodeTransportData() < 0 )
return -1;
//copy to TxBuffer
memcpy ( fTxData, &fReturnTransportData, sizeof ( net_transport_data_t ) );
}
//then others
//...
return 0;
}
//read/write operations---------------------------------------------------------------
int JackNetAdapter::Read()
{
if ( SyncRecv() == SOCKET_ERROR )
return 0;
if ( DecodeSyncPacket() < 0 )
return 0;
return DataRecv();
}
int JackNetAdapter::Write()
{
if ( EncodeSyncPacket() < 0 )
return 0;
if ( SyncSend() == SOCKET_ERROR )
return SOCKET_ERROR;
return DataSend();
}
//process-----------------------------------------------------------------------------
int JackNetAdapter::Process()
{
bool failure = false;
......@@ -306,6 +421,7 @@ namespace Jack
}
} // namespace Jack
//loader------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
......@@ -406,7 +522,7 @@ extern "C"
jack_nframes_t buffer_size = jack_get_buffer_size ( jack_client );
jack_nframes_t sample_rate = jack_get_sample_rate ( jack_client );
adapter = new Jack::JackAudioAdapter ( jack_client, new Jack::JackNetAdapter ( buffer_size, sample_rate, params ) );
adapter = new Jack::JackAudioAdapter ( jack_client, new Jack::JackNetAdapter ( jack_client, buffer_size, sample_rate, params ) );
assert ( adapter );
if ( adapter->Open() == 0 )
......
......@@ -36,7 +36,13 @@ namespace Jack
{
private:
//jack data
net_transport_data_t fTransportData;
jack_client_t* fJackClient;
//transport data
int fLastTransportState;
int fLastTimebaseMaster;
net_transport_data_t fSendTransportData;
net_transport_data_t fReturnTransportData;
//sample buffers
sample_t** fSoftCaptureBuffer;
......@@ -45,9 +51,17 @@ namespace Jack
//adapter thread
JackThread fThread;
//transport
int EncodeTransportData();
int DecodeTransportData();
//sync packet
int EncodeSyncPacket();
int DecodeSyncPacket();
public:
JackNetAdapter ( jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params );
JackNetAdapter ( jack_client_t* jack_client, jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params );
~JackNetAdapter();
int Open();
......
......@@ -338,26 +338,26 @@ namespace Jack
fEngineControl->fTransport.GetTimebaseMaster ( refnum, conditional );
if ( refnum != -1 )
fEngineControl->fTransport.ResetTimebase ( refnum );
jack_info ( "NetMaster is now the new timebase master." );
jack_info ( "The NetMaster is now the new timebase master." );
}
//is there a tranport state change to handle ?
if ( fSendTransportData.fNewState && ( fSendTransportData.fState != ( uint ) fEngineControl->fTransport.GetState() ) )
if ( fSendTransportData.fNewState && ( fSendTransportData.fState != fEngineControl->fTransport.GetState() ) )
{
switch ( fSendTransportData.fState )
{
case JackTransportStopped :
fEngineControl->fTransport.SetCommand ( TransportCommandStop );
jack_info ( "NetMaster : transport stops." );
jack_info ( "Master stops transport." );
break;
case JackTransportStarting :
fEngineControl->fTransport.RequestNewPos ( &fSendTransportData.fPosition );
fEngineControl->fTransport.SetCommand ( TransportCommandStart );
jack_info ( "NetMaster : transport starts." );
jack_info ( "Master starts transport." );
break;
case JackTransportRolling :
fEngineControl->fTransport.SetState ( JackTransportRolling );
jack_info ( "NetMaster : transport rolls." );
jack_info ( "Master is rolling." );
break;
}
}
......@@ -397,7 +397,7 @@ namespace Jack
fReturnTransportData.fNewState = ( ( fReturnTransportData.fState != fLastTransportState ) &&
( fReturnTransportData.fState != fSendTransportData.fState ) );
if ( fReturnTransportData.fNewState )
jack_info ( "Sending transport state '%s'.", GetTransportState ( fReturnTransportData.fState ) );
jack_info ( "Sending '%s'.", GetTransportState ( fReturnTransportData.fState ) );
fLastTransportState = fReturnTransportData.fState;
return 0;
......
......@@ -42,7 +42,7 @@ namespace Jack
jack_port_id_t* fMidiPlaybackPortList;
//transport
uint fLastTransportState;
int fLastTransportState;
int fLastTimebaseMaster;
net_transport_data_t fSendTransportData;
net_transport_data_t fReturnTransportData;
......
......@@ -68,6 +68,14 @@ namespace Jack
virtual void SetParams();
virtual bool Init() = 0;
//transport
virtual int EncodeTransportData() = 0;
virtual int DecodeTransportData() = 0;
//sync packet
virtual int EncodeSyncPacket() = 0;
virtual int DecodeSyncPacket() = 0;
virtual int SyncRecv() = 0;
virtual int SyncSend() = 0;
virtual int DataRecv() = 0;
......
......@@ -148,7 +148,7 @@ namespace Jack
goto fail;
}
jack_info ( "NetJack new master started." );
jack_info ( "New NetMaster started." );
return true;
......@@ -238,7 +238,7 @@ namespace Jack
fSendTransportData.fNewState = ( ( fSendTransportData.fState != fLastTransportState ) &&
( fSendTransportData.fState != fReturnTransportData.fState ) );
if ( fSendTransportData.fNewState )
jack_info ( "'%s' : sending transport state '%s'.", fParams.fName, GetTransportState ( fSendTransportData.fState ) );
jack_info ( "Sending '%s' to '%s'.", GetTransportState ( fSendTransportData.fState ), fParams.fName );
fLastTransportState = fSendTransportData.fState;
return 0;
......@@ -280,24 +280,24 @@ namespace Jack
}
//is the slave in a new transport state and is this state different from master's ?
if ( fReturnTransportData.fNewState && ( fReturnTransportData.fState != ( uint ) jack_transport_query ( fJackClient, NULL ) ) )
if ( fReturnTransportData.fNewState && ( fReturnTransportData.fState != jack_transport_query ( fJackClient, NULL ) ) )
{
switch ( fReturnTransportData.fState )
{
case JackTransportStopped :
jack_transport_stop ( fJackClient );
jack_info ( "'%s' : transport stops.", fParams.fName );
jack_info ( "'%s' stops transport.", fParams.fName );
break;
case JackTransportStarting :
if ( jack_transport_reposition ( fJackClient, &fReturnTransportData.fPosition ) < 0 )
jack_error ( "Can't set new position." );
jack_transport_start ( fJackClient );
jack_info ( "'%s' : transport starts.", fParams.fName );
jack_info ( "'%s' starts transport.", fParams.fName );
break;
case JackTransportNetStarting :
jack_info ( "'%s' : transport is ready to roll.", fParams.fName );
jack_info ( "'%s' is ready to roll..", fParams.fName );
case JackTransportRolling :
jack_info ( "'%s' : transport is rolling.", fParams.fName );
jack_info ( "'%s' is rolling.", fParams.fName );
break;
}
}
......
......@@ -52,7 +52,7 @@ namespace Jack
jack_port_t** fMidiPlaybackPorts;
//sync and transport
uint32_t fLastTransportState;
int fLastTransportState;
net_transport_data_t fSendTransportData;
net_transport_data_t fReturnTransportData;
......
......@@ -178,7 +178,7 @@ namespace Jack
{
uint32_t fNewState; //is it a state change
uint32_t fTimebaseMaster; //is there a new timebase master
uint32_t fState; //current cycle state
int32_t fState; //current cycle state
jack_position_t fPosition; //current cycle position
};
......
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