Commit 4c488ee5 authored by sletz's avatar sletz
Browse files

Merge network branch

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2445 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 6e74283e
......@@ -215,6 +215,7 @@ env['INCLUDEDIR'] = env.subst(env['INCLUDEDIR'])
env['SERVER'] = 'jackd'
env['CLIENTLIB'] = 'jack'
env['SERVERLIB'] = 'jackserver'
env['NETMANAGERLIB'] = 'netmanager'
env['ADDON_DIR'] = env.subst(env['LIBDIR']) + "/jack"
env['INSTALL_ADDON_DIR'] = env['DESTDIR'] + env.subst(env['LIBDIR']) + "/jack"
......
......@@ -63,16 +63,16 @@ class EXPORT JackAudioDriver : public JackDriver
virtual int Process();
virtual int Open(jack_nframes_t nframes,
jack_nframes_t samplerate,
int capturing,
int playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
jack_nframes_t samplerate,
int capturing,
int playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
virtual int Attach();
virtual int Detach();
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackDriver__
#define __JackDriver__
......@@ -29,28 +29,28 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
class JackEngineInterface;
class JackGraphManager;
struct JackEngineControl;
struct JackClientControl;
/*!
\brief The base interface for drivers.
*/
class EXPORT JackDriverInterface
{
public:
JackDriverInterface()
{}
virtual ~JackDriverInterface()
{}
virtual int Open() = 0;
virtual int Open(jack_nframes_t nframes,
jack_nframes_t samplerate,
bool capturing,
......@@ -62,71 +62,71 @@ class EXPORT JackDriverInterface
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency) = 0;
virtual int Attach() = 0;
virtual int Detach() = 0;
virtual int Read() = 0;
virtual int Write() = 0;
virtual int Start() = 0;
virtual int Stop() = 0;
virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
virtual int Process() = 0;
virtual void SetMaster(bool onoff) = 0;
virtual bool GetMaster() = 0;
virtual void AddSlave(JackDriverInterface* slave) = 0;
virtual void RemoveSlave(JackDriverInterface* slave) = 0;
virtual int ProcessSlaves() = 0;
virtual bool IsRealTime() = 0;
};
/*
\brief The base interface for blocking drivers.
*/
\brief The base interface for blocking drivers.
*/
class EXPORT JackBlockingInterface
{
public:
JackBlockingInterface()
{}
virtual ~JackBlockingInterface()
{}
virtual bool Init() = 0; /* To be called by the wrapping thread Init method when the driver is a "blocking" one */
};
/*!
\brief The base interface for drivers clients.
*/
\brief The base interface for drivers clients.
*/
class EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface
{};
/*!
\brief The base class for drivers clients.
*/
\brief The base class for drivers clients.
*/
class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlockingInterface
{
private:
std::list<JackDriverInterface*> fSlaveList;
protected:
bool fIsMaster;
public:
virtual void SetMaster(bool onoff);
virtual bool GetMaster();
virtual void AddSlave(JackDriverInterface* slave);
......@@ -135,14 +135,14 @@ class EXPORT JackDriverClient : public JackDriverClientInterface, public JackBlo
};
/*!
\brief The base class for drivers.
*/
\brief The base class for drivers.
*/
class EXPORT JackDriver : public JackDriverClient
{
protected:
char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
char fAliasName[JACK_CLIENT_NAME_SIZE + 1];
......@@ -155,20 +155,20 @@ class EXPORT JackDriver : public JackDriverClient
JackSynchro* fSynchroTable;
JackEngineControl* fEngineControl;
JackClientControl* fClientControl;
JackClientControl* GetClientControl() const;
JackClientControl* GetClientControl() const;
void CycleIncTime();
void CycleTakeTime();
public:
JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table);
JackDriver();
virtual ~JackDriver();
virtual int Open();
virtual int Open(jack_nframes_t nframes,
jack_nframes_t samplerate,
bool capturing,
......@@ -180,14 +180,14 @@ class EXPORT JackDriver : public JackDriverClient
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
virtual int Close();
virtual int Process()
{
return 0;
}
virtual int Attach()
{
return 0;
......@@ -196,7 +196,7 @@ class EXPORT JackDriver : public JackDriverClient
{
return 0;
}
virtual int Read()
{
return 0;
......@@ -205,7 +205,7 @@ class EXPORT JackDriver : public JackDriverClient
{
return 0;
}
virtual int Start()
{
return 0;
......@@ -214,32 +214,32 @@ class EXPORT JackDriver : public JackDriverClient
{
return 0;
}
virtual int SetBufferSize(jack_nframes_t buffer_size)
{
return 0;
}
virtual int SetSampleRate(jack_nframes_t sample_rate)
{
return 0;
}
void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
virtual bool IsRealTime();
int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2);
void SetupDriverSync(int ref, bool freewheel);
virtual bool Init()
{
return true;
}
};
} // end of namespace
#endif
......@@ -60,69 +60,4 @@ namespace Jack
};
}
#endif
/*
Copyright (C) 2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackException__
#define __JackException__
#include <stdexcept>
#include <iostream>
#include <string>
#include "JackError.h"
namespace Jack
{
class JackException : public std::runtime_error {
public:
JackException(const std::string& msg) : runtime_error(msg)
{}
JackException(const char* msg) : runtime_error(msg)
{}
std::string Message()
{
return what();
}
void PrintMessage()
{
std::string str = what();
jack_error(str.c_str());
}
};
class JackDriverException : public JackException {
public:
JackDriverException(const std::string& msg) : JackException(msg)
{}
JackDriverException(const char* msg) : JackException(msg)
{}
};
}
#endif
#endif
This diff is collapsed.
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __JackNetDriver__
#define __JackNetDriver__
#include "JackAudioDriver.h"
#include "JackNetTool.h"
namespace Jack
{
class JackNetDriver : public JackAudioDriver
{
private:
session_params_t fParams;
char* fMulticastIP;
size_t fPort;
int fSockfd;
struct sockaddr_in fMasterAddr;
size_t fNSubProcess;
jack_port_id_t* fMidiCapturePortList;
jack_port_id_t* fMidiPlaybackPortList;
packet_header_t fTxHeader;
packet_header_t fRxHeader;
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
int fAudioRxLen;
int fAudioTxLen;
int Attach();
int Detach();
bool Init();
net_status_t GetNetMaster();
net_status_t SendMasterStartSync();
void Restart();
int SetParams();
int AllocPorts();
int FreePorts();
JackMidiBuffer* GetMidiInputBuffer ( int port_index );
JackMidiBuffer* GetMidiOutputBuffer ( int port_index );
int Recv ( size_t size, int flags );
int Send ( size_t size, int flags );
int Read();
int Write();
public:
JackNetDriver ( const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table,
char* ip, size_t port, int midi_input_ports, int midi_output_ports, char* master_name );
~JackNetDriver();
int Open ( jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor, const char* capture_driver_name,
const char* playback_driver_name, jack_nframes_t capture_latency, jack_nframes_t playback_latency );
};
}
#endif
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2008 by Romain Moret *
* moret@grame.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef __JACKNETMASTER_H__
#define __JACKNETMASTER_H__
#include "JackNetTool.h"
#include <list>
#include <algorithm>
#include "thread.h"
#include <unistd.h>
#include "jack.h"
namespace Jack
{
class JackNetMasterManager;
class JackNetMaster
{
friend class JackNetMasterManager;
private:
static int SetProcess ( jack_nframes_t nframes, void* arg );
JackNetMasterManager* fMasterManager;
session_params_t fParams;
struct sockaddr_in fAddr;
struct sockaddr_in fMcastAddr;
int fSockfd;
size_t fNSubProcess;
size_t fNetJumpCnt;
bool fRunning;
jack_client_t* fJackClient;
const char* fClientName;
jack_port_t** fAudioCapturePorts;
jack_port_t** fAudioPlaybackPorts;
jack_port_t** fMidiCapturePorts;
jack_port_t** fMidiPlaybackPorts;
packet_header_t fTxHeader;
packet_header_t fRxHeader;
char* fTxBuffer;
char* fRxBuffer;
char* fTxData;
char* fRxData;
NetAudioBuffer* fNetAudioCaptureBuffer;
NetAudioBuffer* fNetAudioPlaybackBuffer;
NetMidiBuffer* fNetMidiCaptureBuffer;
NetMidiBuffer* fNetMidiPlaybackBuffer;
int fAudioTxLen;
int fAudioRxLen;
bool Init();
void FreePorts();
void Exit();
int Send ( char* buffer, size_t size, int flags );
int Recv ( size_t size, int flags );
int Process();
public:
JackNetMaster ( JackNetMasterManager* manager, session_params_t& params, struct sockaddr_in& address, struct sockaddr_in& mcast_addr );
~JackNetMaster ();
};
typedef std::list<JackNetMaster*> master_list_t;
typedef master_list_t::iterator master_list_it_t;
class JackNetMasterManager
{
private:
static void* NetManagerThread ( void* arg );
static int SetProcess ( jack_nframes_t nframes, void* arg );
jack_client_t* fManagerClient;
char* fManagerName;
char* fMCastIP;
pthread_t fManagerThread;
master_list_t fMasterList;
size_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 );
void KillMaster ( session_params_t* params );
void SetSlaveName ( session_params_t& params );
int Process();
public:
JackNetMasterManager ( jack_client_t* jack_client );
~JackNetMasterManager();
void Exit();
};
}
#endif
#include "JackNetTool.h"
#include "JackError.h"
using namespace std;
namespace Jack
{
// NetMidiBuffer**********************************************************************************
NetMidiBuffer::NetMidiBuffer ( session_params_t* params, size_t nports, char* net_buffer )
{
fNPorts = nports;
fMaxBufsize = fNPorts * sizeof ( sample_t ) * params->fPeriodSize ;
fMaxPcktSize = params->fMtu - sizeof ( packet_header_t );
fBuffer = new char[fMaxBufsize];
fPortBuffer = new JackMidiBuffer* [fNPorts];
for ( int port_index = 0; port_index < fNPorts; port_index++ )
fPortBuffer[port_index] = NULL;
fNetBuffer = net_buffer;
}
NetMidiBuffer::~NetMidiBuffer()
{
delete[] fBuffer;
delete[] fPortBuffer;
}
size_t NetMidiBuffer::GetSize()
{