Browse Source

cleanup

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2509 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
moret 17 years ago
parent
commit
2fe0ec0c13
6 changed files with 67 additions and 65 deletions
  1. +16
    -16
      common/JackNetDriver.cpp
  2. +3
    -3
      common/JackNetDriver.h
  3. +21
    -19
      common/JackNetManager.cpp
  4. +5
    -5
      common/JackNetManager.h
  5. +10
    -10
      common/JackNetTool.cpp
  6. +12
    -12
      common/JackNetTool.h

+ 16
- 16
common/JackNetDriver.cpp View File

@@ -35,12 +35,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackNetDriver::JackNetDriver ( const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
const char* ip, size_t port, int midi_input_ports, int midi_output_ports, const char* net_name )
const char* ip, int port, int midi_input_ports, int midi_output_ports, const char* net_name )
: JackAudioDriver ( name, alias, engine, table )
{
fMulticastIP = new char[strlen ( ip ) + 1];
strcpy ( fMulticastIP, ip );
fPort = port;
fUDPPort = port;
fParams.fSendMidiChannels = midi_input_ports;
fParams.fReturnMidiChannels = midi_output_ports;
strcpy ( fParams.fName, net_name );
@@ -150,13 +150,13 @@ namespace Jack

//set the multicast address
mcast_addr.sin_family = AF_INET;
mcast_addr.sin_port = htons ( fPort );
mcast_addr.sin_port = htons ( fUDPPort );
inet_aton ( fMulticastIP, &mcast_addr.sin_addr );
memset ( &mcast_addr.sin_zero, 0, 8 );

//set the listening address
listen_addr.sin_family = AF_INET;
listen_addr.sin_port = htons ( fPort );
listen_addr.sin_port = htons ( fUDPPort );
listen_addr.sin_addr.s_addr = htonl ( INADDR_ANY );
memset ( &listen_addr.sin_zero, 0, 8 );

@@ -394,9 +394,9 @@ namespace Jack
fGraphManager->ReleasePort ( fClientControl->fRefNum, fCapturePortList[port_index] );
for ( int port_index = 0; port_index < fPlaybackChannels; port_index++ )
fGraphManager->ReleasePort ( fClientControl->fRefNum, fPlaybackPortList[port_index] );
for ( int port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fGraphManager->ReleasePort ( fClientControl->fRefNum, fMidiCapturePortList[port_index] );
for ( int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fGraphManager->ReleasePort ( fClientControl->fRefNum, fMidiPlaybackPortList[port_index] );
return 0;
}
@@ -456,12 +456,12 @@ namespace Jack
int JackNetDriver::Read()
{
int rx_bytes;
size_t recvd_midi_pckt = 0;
uint recvd_midi_pckt = 0;
packet_header_t* rx_head = reinterpret_cast<packet_header_t*> ( fRxBuffer );
fRxHeader.fIsLastPckt = 'n';

//buffers
for ( int port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fNetMidiCaptureBuffer->fPortBuffer[port_index] = GetMidiInputBuffer ( port_index );
for ( int port_index = 0; port_index < fCaptureChannels; port_index++ )
fNetAudioCaptureBuffer->fPortBuffer[port_index] = GetInputBuffer ( port_index );
@@ -525,7 +525,7 @@ namespace Jack
fTxHeader.fIsLastPckt = 'n';

//buffers
for ( int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fNetMidiPlaybackBuffer->fPortBuffer[port_index] = GetMidiOutputBuffer ( port_index );
for ( int port_index = 0; port_index < fPlaybackChannels; port_index++ )
fNetAudioPlaybackBuffer->fPortBuffer[port_index] = GetOutputBuffer ( port_index );
@@ -536,7 +536,7 @@ namespace Jack
fTxHeader.fDataType = 'm';
fTxHeader.fMidiDataSize = fNetMidiPlaybackBuffer->RenderFromJackPorts();
fTxHeader.fNMidiPckt = GetNMidiPckt ( &fParams, fTxHeader.fMidiDataSize );
for ( size_t subproc = 0; subproc < fTxHeader.fNMidiPckt; subproc++ )
for ( uint subproc = 0; subproc < fTxHeader.fNMidiPckt; subproc++ )
{
fTxHeader.fSubCycle = subproc;
if ( ( subproc == ( fTxHeader.fNMidiPckt - 1 ) ) && !fParams.fReturnAudioChannels )
@@ -551,7 +551,7 @@ namespace Jack
if ( fParams.fReturnAudioChannels )
{
fTxHeader.fDataType = 'a';
for ( size_t subproc = 0; subproc < fNSubProcess; subproc++ )
for ( uint subproc = 0; subproc < fNSubProcess; subproc++ )
{
fTxHeader.fSubCycle = subproc;
if ( subproc == ( fNSubProcess - 1 ) )
@@ -577,7 +577,7 @@ namespace Jack
desc->nparams = 7;
desc->params = ( jack_driver_param_desc_t* ) calloc ( desc->nparams, sizeof ( jack_driver_param_desc_t ) );

size_t i = 0;
int i = 0;
strcpy ( desc->params[i].name, "multicast_ip" );
desc->params[i].character = 'a';
desc->params[i].type = JackDriverParamString;
@@ -588,8 +588,8 @@ namespace Jack
i++;
strcpy ( desc->params[i].name, "udp_net_port" );
desc->params[i].character = 'p';
desc->params[i].type = JackDriverParamUInt;
desc->params[i].value.ui = 19000U;
desc->params[i].type = JackDriverParamInt;
desc->params[i].value.i = 19000;
strcpy ( desc->params[i].short_desc, "UDP port" );
strcpy ( desc->params[i].long_desc, desc->params[i].short_desc );

@@ -604,7 +604,7 @@ namespace Jack
i++;
strcpy ( desc->params[i].name, "output_ports" );
desc->params[i].character = 'P';
desc->params[i].type = JackDriverParamUInt;
desc->params[i].type = JackDriverParamInt;
desc->params[i].value.i = 2;
strcpy ( desc->params[i].short_desc, "Number of audio output ports" );
strcpy ( desc->params[i].long_desc, desc->params[i].short_desc );
@@ -641,7 +641,7 @@ namespace Jack
const char* multicast_ip = DEFAULT_MULTICAST_IP;
char name[JACK_CLIENT_NAME_SIZE];
gethostname ( name, JACK_CLIENT_NAME_SIZE );
jack_nframes_t udp_port = DEFAULT_PORT;
int udp_port = DEFAULT_PORT;
jack_nframes_t period_size = 128;
jack_nframes_t sample_rate = 48000;
int audio_capture_ports = 2;


+ 3
- 3
common/JackNetDriver.h View File

@@ -32,10 +32,10 @@ namespace Jack
private:
session_params_t fParams;
char* fMulticastIP;
size_t fPort;
int fUDPPort;
int fSockfd;
struct sockaddr_in fMasterAddr;
size_t fNSubProcess;
uint fNSubProcess;

jack_port_id_t* fMidiCapturePortList;
jack_port_id_t* fMidiPlaybackPortList;
@@ -72,7 +72,7 @@ namespace Jack

public:
JackNetDriver ( const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
const char* ip, size_t port, int midi_input_ports, int midi_output_ports, const char* master_name );
const char* ip, int port, int midi_input_ports, int midi_output_ports, const char* master_name );
~JackNetDriver();

int Open ( jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,


+ 21
- 19
common/JackNetManager.cpp View File

@@ -48,17 +48,17 @@ namespace Jack

//jack audio ports
fAudioCapturePorts = new jack_port_t* [fParams.fSendAudioChannels];
for ( int port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
fAudioCapturePorts[port_index] = NULL;
fAudioPlaybackPorts = new jack_port_t* [fParams.fReturnAudioChannels];
for ( int port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
fAudioPlaybackPorts[port_index] = NULL;
//jack midi ports
fMidiCapturePorts = new jack_port_t* [fParams.fSendMidiChannels];
for ( int port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fMidiCapturePorts[port_index] = NULL;
fMidiPlaybackPorts = new jack_port_t* [fParams.fReturnMidiChannels];
for ( int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( uint port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fMidiPlaybackPorts[port_index] = NULL;

//TX header init
@@ -190,7 +190,7 @@ namespace Jack
jack_set_process_callback ( fJackClient, SetProcess, this );

//port registering
int i;
uint i;
char name[24];
//audio
for ( i = 0; i < fParams.fSendAudioChannels; i++ )
@@ -242,16 +242,17 @@ namespace Jack
void JackNetMaster::FreePorts()
{
jack_log ( "JackNetMaster::FreePorts, ID %u", fParams.fID );
for ( int port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
uint port_index;
for ( port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
if ( fAudioCapturePorts[port_index] )
jack_port_unregister ( fJackClient, fAudioCapturePorts[port_index] );
for ( int port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
if ( fAudioPlaybackPorts[port_index] )
jack_port_unregister ( fJackClient, fAudioPlaybackPorts[port_index] );
for ( int port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
if ( fMidiCapturePorts[port_index] )
jack_port_unregister ( fJackClient, fMidiCapturePorts[port_index] );
for ( int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
if ( fMidiPlaybackPorts[port_index] )
jack_port_unregister ( fJackClient, fMidiPlaybackPorts[port_index] );
}
@@ -340,16 +341,17 @@ namespace Jack
packet_header_t* rx_head = reinterpret_cast<packet_header_t*> ( fRxBuffer );

//buffers
for ( int port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
uint port_index;
for ( port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fNetMidiCaptureBuffer->fPortBuffer[port_index] =
static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiCapturePorts[port_index], fParams.fPeriodSize ) );
for ( int port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
fNetAudioCaptureBuffer->fPortBuffer[port_index] =
static_cast<sample_t*> ( jack_port_get_buffer ( fAudioCapturePorts[port_index], fParams.fPeriodSize ) );
for ( int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fNetMidiPlaybackBuffer->fPortBuffer[port_index] =
static_cast<JackMidiBuffer*> ( jack_port_get_buffer ( fMidiPlaybackPorts[port_index], fParams.fPeriodSize ) );
for ( int port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
fNetAudioPlaybackBuffer->fPortBuffer[port_index] =
static_cast<sample_t*> ( jack_port_get_buffer ( fAudioPlaybackPorts[port_index], fParams.fPeriodSize ) );

@@ -368,7 +370,7 @@ namespace Jack
fTxHeader.fDataType = 'm';
fTxHeader.fMidiDataSize = fNetMidiCaptureBuffer->RenderFromJackPorts();
fTxHeader.fNMidiPckt = GetNMidiPckt ( &fParams, fTxHeader.fMidiDataSize );
for ( size_t subproc = 0; subproc < fTxHeader.fNMidiPckt; subproc++ )
for ( uint subproc = 0; subproc < fTxHeader.fNMidiPckt; subproc++ )
{
fTxHeader.fSubCycle = subproc;
if ( ( subproc == ( fTxHeader.fNMidiPckt - 1 ) ) && !fParams.fSendAudioChannels )
@@ -385,7 +387,7 @@ namespace Jack
if ( fParams.fSendAudioChannels )
{
fTxHeader.fDataType = 'a';
for ( size_t subproc = 0; subproc < fNSubProcess; subproc++ )
for ( uint subproc = 0; subproc < fNSubProcess; subproc++ )
{
fTxHeader.fSubCycle = subproc;
if ( subproc == ( fNSubProcess - 1 ) )
@@ -444,7 +446,7 @@ namespace Jack
fManagerClient = client;
fManagerName = jack_get_client_name ( fManagerClient );
fMCastIP = DEFAULT_MULTICAST_IP;
fPort = DEFAULT_PORT;
fUDPPort = DEFAULT_PORT;
fGlobalID = 0;
fRunning = true;

@@ -479,7 +481,7 @@ namespace Jack
struct timeval timeout;
timeout.tv_sec = 2;
timeout.tv_usec = 0;
size_t attempt = 0;
int attempt = 0;

//network
int mcast_sockfd;
@@ -501,7 +503,7 @@ namespace Jack

//set the multicast address
mcast_addr.sin_family = AF_INET;
mcast_addr.sin_port = htons ( fPort );
mcast_addr.sin_port = htons ( fUDPPort );
if ( inet_aton ( fMCastIP, &mcast_addr.sin_addr ) < 0 )
{
jack_error ( "Cant set multicast address : %s", strerror ( errno ) );
@@ -617,7 +619,7 @@ namespace Jack
sprintf ( params.fName, "%s-%u", params.fName, params.fID );
}

master_list_it_t JackNetMasterManager::FindMaster ( size_t id )
master_list_it_t JackNetMasterManager::FindMaster ( uint32_t id )
{
jack_log ( "JackNetMasterManager::FindMaster, ID %u.", id );
master_list_it_t it;


+ 5
- 5
common/JackNetManager.h View File

@@ -41,8 +41,8 @@ namespace Jack
struct sockaddr_in fAddr;
struct sockaddr_in fMcastAddr;
int fSockfd;
size_t fNSubProcess;
size_t fNetJumpCnt;
uint fNSubProcess;
int fNetJumpCnt;
bool fRunning;

jack_client_t* fJackClient;
@@ -93,15 +93,15 @@ namespace Jack
jack_client_t* fManagerClient;
const char* fManagerName;
const char* fMCastIP;
int fUDPPort;
pthread_t fManagerThread;
master_list_t fMasterList;
size_t fGlobalID;
uint32_t fGlobalID;
bool fRunning;
size_t fPort;

void Run();
JackNetMaster* MasterInit ( session_params_t& params, struct sockaddr_in& address, struct sockaddr_in& mcast_addr );
master_list_it_t FindMaster ( size_t client_id );
master_list_it_t FindMaster ( uint32_t client_id );
void KillMaster ( session_params_t* params );
void SetSlaveName ( session_params_t& params );
int Process();


+ 10
- 10
common/JackNetTool.cpp View File

@@ -35,7 +35,7 @@ namespace Jack
{
for ( int port_index = 0; port_index < fNPorts; port_index++ )
{
for ( size_t event = 0; event < fPortBuffer[port_index]->event_count; event++ )
for ( uint event = 0; event < fPortBuffer[port_index]->event_count; event++ )
if ( fPortBuffer[port_index]->IsValid() )
jack_info ( "port %d : midi event %u/%u -> time : %u, size : %u",
port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
@@ -46,7 +46,7 @@ namespace Jack
int NetMidiBuffer::RenderFromJackPorts()
{
int pos = 0;
int copy_size;
size_t copy_size;
for ( int port_index = 0; port_index < fNPorts; port_index++ )
{
copy_size = sizeof ( JackMidiBuffer ) + fPortBuffer[port_index]->event_count * sizeof ( JackMidiEvent );
@@ -75,13 +75,13 @@ namespace Jack
return pos;
}

int NetMidiBuffer::RenderFromNetwork ( size_t subcycle, size_t copy_size )
int NetMidiBuffer::RenderFromNetwork ( int subcycle, size_t copy_size )
{
memcpy ( fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size );
return copy_size;
}

int NetMidiBuffer::RenderToNetwork ( size_t subcycle, size_t total_size )
int NetMidiBuffer::RenderToNetwork ( int subcycle, size_t total_size )
{
int size = total_size - subcycle * fMaxPcktSize;
int copy_size = ( size <= fMaxPcktSize ) ? size : fMaxPcktSize;
@@ -113,13 +113,13 @@ namespace Jack
return fNPorts * fSubPeriodBytesSize;
}

void NetAudioBuffer::RenderFromJackPorts ( size_t subcycle )
void NetAudioBuffer::RenderFromJackPorts ( int subcycle )
{
for ( int port_index = 0; port_index < fNPorts; port_index++ )
memcpy ( fNetBuffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize );
}

void NetAudioBuffer::RenderToJackPorts ( size_t subcycle )
void NetAudioBuffer::RenderToJackPorts ( int subcycle )
{
for ( int port_index = 0; port_index < fNPorts; port_index++ )
memcpy ( fPortBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize );
@@ -257,7 +257,7 @@ namespace Jack

// Utility *******************************************************************************************************

EXPORT size_t SetFramesPerPacket ( session_params_t* params )
EXPORT jack_nframes_t SetFramesPerPacket ( session_params_t* params )
{
if ( !params->fSendAudioChannels && !params->fReturnAudioChannels )
return ( params->fFramesPerPacket = params->fPeriodSize );
@@ -267,14 +267,14 @@ namespace Jack
return params->fFramesPerPacket;
}

EXPORT size_t GetNMidiPckt ( session_params_t* params, size_t data_size )
EXPORT int GetNMidiPckt ( session_params_t* params, size_t data_size )
{
//even if there is no midi data, jack need an empty buffer to know there is no event to read
//99% of the cases : all data in one packet
if ( data_size <= ( params->fMtu - sizeof ( packet_header_t ) ) )
return 1;
//else, get the number of needed packets (simply slice the biiig buffer)
size_t npckt = data_size / ( params->fMtu - sizeof ( packet_header_t ) );
int npckt = data_size / ( params->fMtu - sizeof ( packet_header_t ) );
if ( data_size % ( params->fMtu - sizeof ( packet_header_t ) ) )
return ++npckt;
return npckt;
@@ -295,7 +295,7 @@ namespace Jack

// Packet *******************************************************************************************************

EXPORT bool IsNextPacket ( packet_header_t* previous, packet_header_t* next, size_t subcycles )
EXPORT bool IsNextPacket ( packet_header_t* previous, packet_header_t* next, uint subcycles )
{
//ignore first cycle
if ( previous->fCycle <= 1 )


+ 12
- 12
common/JackNetTool.h View File

@@ -34,15 +34,15 @@ namespace Jack
{
char fPacketType[7]; //packet type ('param')
char fProtocolVersion; //version
int32_t fPacketID; //indicates the packet type
uint32_t fPacketID; //indicates the packet type
char fMasterNetName[256]; //master hostname (network)
char fSlaveNetName[256]; //slave hostname (network)
uint32_t fMtu; //connection mtu
uint32_t fID; //slave's ID
int32_t fSendAudioChannels; //number of master->slave channels
int32_t fReturnAudioChannels; //number of slave->master channels
int32_t fSendMidiChannels; //number of master->slave midi channels
int32_t fReturnMidiChannels; //number of slave->master midi channels
uint32_t fSendAudioChannels; //number of master->slave channels
uint32_t fReturnAudioChannels; //number of slave->master channels
uint32_t fSendMidiChannels; //number of master->slave midi channels
uint32_t fReturnMidiChannels; //number of slave->master midi channels
uint32_t fSampleRate; //session sample rate
uint32_t fPeriodSize; //period size
uint32_t fFramesPerPacket; //complete frames per packet
@@ -124,8 +124,8 @@ namespace Jack
int RenderFromJackPorts();
int RenderToJackPorts();
//network<->buffer
int RenderFromNetwork ( size_t subcycle, size_t copy_size );
int RenderToNetwork ( size_t subcycle, size_t copy_size );
int RenderFromNetwork ( int subcycle, size_t copy_size );
int RenderToNetwork ( int subcycle, size_t total_size );
};

// audio data *********************************************************************************
@@ -146,8 +146,8 @@ namespace Jack

size_t GetSize();
//jack<->buffer
void RenderFromJackPorts ( size_t subcycle );
void RenderToJackPorts ( size_t subcycle );
void RenderFromJackPorts ( int subcycle );
void RenderToJackPorts ( int subcycle );
};

//utility *************************************************************************************
@@ -166,11 +166,11 @@ namespace Jack
//set the packet type in a session parameters
EXPORT int SetPacketType ( session_params_t* params, sync_packet_type_t packet_type );
//step of network initialization
EXPORT size_t SetFramesPerPacket ( session_params_t* params );
EXPORT jack_nframes_t SetFramesPerPacket ( session_params_t* params );
//get the midi packet number for a given cycle
EXPORT size_t GetNMidiPckt ( session_params_t* params, size_t data_size );
EXPORT int GetNMidiPckt ( session_params_t* params, size_t data_size );
//set the recv timeout on a socket
EXPORT int SetRxTimeout ( int* sockfd, session_params_t* params );
//check if 'next' packet is really the next after 'previous'
EXPORT bool IsNextPacket ( packet_header_t* previous, packet_header_t* next, size_t subcycles );
EXPORT bool IsNextPacket ( packet_header_t* previous, packet_header_t* next, int subcycles );
}

Loading…
Cancel
Save