Commit dcbaa4ed authored by sletz's avatar sletz
Browse files

Merge windows branch back to trunk.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2661 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 1f208cbe
......@@ -21,6 +21,14 @@ Romain Moret
Jackdmp changes log
---------------------------
2008-07-08 Stephane Letz <letz@grame.fr>
* Merge windows branch back to trunk.
2008-07-05 Stephane Letz <letz@grame.fr>
* Netioadapter renamed in audioadapter.
2008-07-04 Stephane Letz <letz@grame.fr>
* Netioadapter now adapts for buffer size and sample rate changes.
......
This diff is collapsed.
......@@ -13,7 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
......@@ -247,7 +247,7 @@ extern "C"
}
#endif
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
/* missing on Windows : see http://bugs.mysql.com/bug.php?id=15936 */
inline double rint(double nr)
{
......@@ -270,11 +270,11 @@ static inline bool CheckBufferSize(jack_nframes_t buffer_size)
static inline void WaitGraphChange()
{
/*
TLS key that is set only in RT thread, so never waits for pending
TLS key that is set only in RT thread, so never waits for pending
graph change in RT context (just read the current graph state).
*/
if (jack_tls_get(gRealTime) == NULL) {
if (jack_tls_get(gRealTime) == NULL) {
JackGraphManager* manager = GetGraphManager();
JackEngineControl* control = GetEngineControl();
assert(manager);
......@@ -300,7 +300,7 @@ EXPORT jack_client_t* jack_client_new(const char* client_name)
{
jack_error("jack_client_new: deprecated");
int options = JackUseExactName;
if (getenv("JACK_START_SERVER") == NULL)
if (getenv("JACK_START_SERVER") == NULL)
options |= JackNoStartServer;
return jack_client_open_aux(client_name, (jack_options_t)options, NULL, NULL);
}
......
......@@ -12,7 +12,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
......@@ -134,6 +134,7 @@ static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* ad
#ifdef WIN32
#ifndef __MINGW32__
#ifdef __SMP__
# define LOCK lock
#else
......@@ -162,6 +163,29 @@ inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void * addr)
return c;
}
#else
#ifdef __SMP__
# define LOCK "lock ; "
#else
# define LOCK ""
#endif
static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr)
{
register char ret;
__asm__ __volatile__ (
"# CAS \n\t"
LOCK "cmpxchg %2, (%1) \n\t"
"sete %0 \n\t"
: "=a" (ret)
: "c" (addr), "d" (newvalue), "a" (value)
);
return ret;
}
#endif
#endif
static inline long INC_ATOMIC(volatile SInt32* val)
......
......@@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackConstants.h"
#include "JackActivationCount.h"
#include "JackError.h"
#include "JackExports.h"
#include <assert.h>
......@@ -371,7 +372,7 @@ struct JackClientTiming
</UL>
*/
class JackConnectionManager
class EXPORT JackConnectionManager
{
private:
......
......@@ -372,7 +372,7 @@ jackctl_setup_signals(
(void) signal(SIGABRT, do_nothing_handler);
(void) signal(SIGTERM, do_nothing_handler);
return waitEvent;
return (sigset_t)waitEvent;
}
void jackctl_wait_signals(sigset_t signals)
......@@ -385,7 +385,7 @@ void jackctl_wait_signals(sigset_t signals)
#else
static
void
void
do_nothing_handler(int sig)
{
/* this is used by the child (active) process, but it never
......@@ -451,7 +451,7 @@ jackctl_setup_signals(
sigaddset(&signals, SIGUSR2);
/* all child threads will inherit this mask unless they
* explicitly reset it
* explicitly reset it
*/
pthread_sigmask(SIG_BLOCK, &signals, 0);
......@@ -470,9 +470,9 @@ jackctl_setup_signals(
if (sigismember (&signals, i))
{
sigaction(i, &action, 0);
}
}
}
return signals;
}
......@@ -493,7 +493,9 @@ jackctl_wait_signals(sigset_t signals)
case SIGUSR2:
// driver exit
waiting = false;
break;
break;
case SIGTTOU:
break;
default:
waiting = false;
break;
......
......@@ -241,14 +241,14 @@ jackctl_parse_driver_params (jackctl_driver *driver_ptr, int argc, char* argv[])
jackctl_parameter_t * param = NULL;
union jackctl_parameter_value value;
if (argc <= 1)
if (argc <= 1)
return 0;
const JSList * driver_params = jackctl_driver_get_parameters(driver_ptr);
if (driver_params == NULL)
return 1;
jack_driver_desc_t * desc = jackctl_driver_get_desc(driver_ptr);
jack_driver_desc_t * desc = jackctl_driver_get_desc(driver_ptr);
/* check for help */
if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) {
......@@ -303,7 +303,7 @@ jackctl_parse_driver_params (jackctl_driver *driver_ptr, int argc, char* argv[])
node_ptr = (JSList *)driver_params;
while (node_ptr) {
param = (jackctl_parameter_t*)node_ptr->data;
param = (jackctl_parameter_t*)node_ptr->data;
if (opt == jackctl_parameter_get_id(param)) {
break;
}
......@@ -318,7 +318,7 @@ jackctl_parse_driver_params (jackctl_driver *driver_ptr, int argc, char* argv[])
if (optarg) {
switch (jackctl_parameter_get_type(param)) {
case JackDriverParamInt:
case JackDriverParamInt:
value.i = atoi (optarg);
jackctl_parameter_set_value(param, &value);
break;
......@@ -360,7 +360,7 @@ jackctl_parse_driver_params (jackctl_driver *driver_ptr, int argc, char* argv[])
value.i = true;
} else {
value = jackctl_parameter_get_default_value(param);
}
}
jackctl_parameter_set_value(param, &value);
}
}
......@@ -439,7 +439,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
#ifdef WIN32
if ((so_get_descriptor == NULL) && (dlerr = GetLastError()) != 0) {
jack_error("%ld", dlerr);
jack_log("Jack::jack_drivers_get_descriptor : dll is not a driver, error ld", dlerr);
#else
if ((so_get_descriptor == NULL) && (dlerr = dlerror ()) != NULL) {
jack_error("%s", dlerr);
......
......@@ -26,45 +26,47 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackExports.h"
#include "JackError.h"
namespace Jack
namespace Jack
{
class EXPORT JackException : public std::runtime_error {
public:
JackException(const std::string& msg) : runtime_error(msg)
JackException(const std::string& msg) : std::runtime_error(msg)
{}
JackException(const char* msg) : runtime_error(msg)
JackException(char* msg) : std::runtime_error(msg)
{}
std::string Message()
JackException(const char* msg) : std::runtime_error(msg)
{}
std::string Message()
{
return what();
}
void PrintMessage()
void PrintMessage()
{
std::string str = what();
if (str != "")
jack_info(str.c_str());
}
};
class EXPORT JackDriverException : public JackException {
public:
JackDriverException(const std::string& msg) : JackException(msg)
JackDriverException(const std::string& msg) : JackException(msg)
{}
JackDriverException(char* msg) : JackException(msg)
{}
JackDriverException(const char* msg) : JackException(msg)
JackDriverException(const char* msg) : JackException(msg)
{}
JackDriverException() : JackException("")
JackDriverException() : JackException("")
{}
};
}
}
#endif
......@@ -52,15 +52,15 @@ static void BuildClientPath(char* path_to_so, int path_len, const char* so_name)
snprintf(path_to_so, path_len, ADDON_DIR "/%s.dll", so_name);
}
static void PrintLoadError(const char* so_name)
{
static void PrintLoadError(const char* so_name)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
......@@ -70,12 +70,12 @@ static void PrintLoadError(const char* so_name)
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)so_name) + 40) * sizeof(TCHAR));
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)so_name) + 40) * sizeof(TCHAR));
_snprintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("error loading %s err = %s"), so_name, lpMsgBuf);
jack_error((LPCTSTR)lpDisplayBuf);
TEXT("error loading %s err = %s"), so_name, lpMsgBuf);
jack_error((LPCTSTR)lpDisplayBuf);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
......@@ -145,7 +145,7 @@ int JackInternalClient::Open(const char* server_name, const char* name, jack_opt
jack_error("Cannot open client name = %s", name_res);
goto error;
}
SetupDriverSync(false);
return 0;
......@@ -219,7 +219,7 @@ int JackLoadableInternalClient::Open(const char* server_name, const char* name,
JackInternalClient::Close();
fFinish = NULL;
}
}
}
return res;
}
......
This diff is collapsed.
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2008 Grame
Copyright (C) 2008 Romain Moret at 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
......@@ -31,9 +31,7 @@ namespace Jack
private:
session_params_t fParams;
char* fMulticastIP;
int fUDPPort;
int fSockfd;
struct sockaddr_in fMasterAddr;
JackNetSocket fSocket;
uint fNSubProcess;
jack_port_id_t* fMidiCapturePortList;
......
/*
Copyright (C) 2008 Grame
Copyright (C) 2008 Romain Moret at 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
......@@ -30,34 +30,33 @@ namespace Jack
{
//JackNetMaster******************************************************************************************************
JackNetMaster::JackNetMaster ( JackNetMasterManager* manager, session_params_t& params, struct sockaddr_in& address, struct sockaddr_in& mcast_addr )
JackNetMaster::JackNetMaster ( JackNetMasterManager* manager, session_params_t& params ) : fSocket()
{
jack_log ( "JackNetMaster::JackNetMaster" );
//settings
fMasterManager = manager;
fParams = params;
fAddr = address;
fMcastAddr = mcast_addr;
fSocket.CopyParams ( &fMasterManager->fSocket );
fNSubProcess = fParams.fPeriodSize / fParams.fFramesPerPacket;
fClientName = const_cast<char*> ( fParams.fName );
fNetJumpCnt = 0;
fJackClient = NULL;
fSockfd = 0;
fRunning = false;
fRunning = false;
uint port_index;
//jack audio ports
fAudioCapturePorts = new jack_port_t* [fParams.fSendAudioChannels];
for ( uint port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ )
fAudioCapturePorts[port_index] = NULL;
fAudioPlaybackPorts = new jack_port_t* [fParams.fReturnAudioChannels];
for ( uint port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ )
fAudioPlaybackPorts[port_index] = NULL;
//jack midi ports
fMidiCapturePorts = new jack_port_t* [fParams.fSendMidiChannels];
for ( uint port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ )
fMidiCapturePorts[port_index] = NULL;
fMidiPlaybackPorts = new jack_port_t* [fParams.fReturnMidiChannels];
for ( uint port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ )
fMidiPlaybackPorts[port_index] = NULL;
//TX header init
......@@ -108,8 +107,7 @@ namespace Jack
FreePorts();
jack_client_close ( fJackClient );
}
if ( fSockfd )
close ( fSockfd );
fSocket.Close();
delete fNetAudioCaptureBuffer;
delete fNetAudioPlaybackBuffer;
delete fNetMidiCaptureBuffer;
......@@ -126,27 +124,25 @@ namespace Jack
{
jack_log ( "JackNetMaster::Init, ID %u.", fParams.fID );
session_params_t params;
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
size_t attempt = 0;
int msec_timeout = 1000;
uint attempt = 0;
int rx_bytes = 0;
//socket
if ( ( fSockfd = socket ( AF_INET, SOCK_DGRAM, 0 ) ) < 0 )
if ( fSocket.NewSocket() == SOCKET_ERROR )
{
jack_error ( "Can't create socket : %s", strerror ( errno ) );
jack_error ( "Can't create socket : %s", StrError ( NET_ERROR_CODE ) );
return false;
}
//timeout on receive (for init)
if ( setsockopt ( fSockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof ( timeout ) ) < 0 )
jack_error ( "Can't set timeout : %s", strerror ( errno ) );
if ( fSocket.SetTimeOut ( msec_timeout ) < 0 )
jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) );
//connect
if ( connect ( fSockfd, reinterpret_cast<sockaddr*> ( &fAddr ), sizeof ( struct sockaddr ) ) < 0 )
if ( fSocket.Connect() == SOCKET_ERROR )
{
jack_error ( "Can't connect : %s", strerror ( errno ) );
jack_error ( "Can't connect : %s", StrError ( NET_ERROR_CODE ) );
return false;
}
......@@ -155,9 +151,9 @@ namespace Jack
do
{
SetPacketType ( &fParams, SLAVE_SETUP );
if ( send ( fSockfd, &fParams, sizeof ( session_params_t ), 0 ) < 0 )
jack_error ( "Error in send : ", strerror ( errno ) );
if ( ( ( rx_bytes = recv ( fSockfd, &params, sizeof ( session_params_t ), 0 ) ) < 0 ) && ( errno != EAGAIN ) )
if ( fSocket.Send ( &fParams, sizeof ( session_params_t ), 0 ) == SOCKET_ERROR )
jack_error ( "Error in send : ", StrError ( NET_ERROR_CODE ) );
if ( ( ( rx_bytes = fSocket.Recv ( &params, sizeof ( session_params_t ), 0 ) ) == SOCKET_ERROR ) && ( fSocket.GetError() != NET_NO_DATA ) )
{
jack_error ( "Problem with network." );
return false;
......@@ -171,9 +167,9 @@ namespace Jack
}
//set the new timeout for the socket
if ( SetRxTimeout ( &fSockfd, &fParams ) < 0 )
if ( SetRxTimeout ( &fSocket, &fParams ) == SOCKET_ERROR )
{
jack_error ( "Can't set rx timeout : %s", strerror ( errno ) );
jack_error ( "Can't set rx timeout : %s", StrError ( NET_ERROR_CODE ) );
return false;
}
......@@ -264,30 +260,30 @@ namespace Jack
//send a 'multicast euthanasia request' - new socket is required on macosx
jack_info ( "Exiting '%s'", fParams.fName );
SetPacketType ( &fParams, KILL_MASTER );
int mcast_sockfd = socket ( AF_INET, SOCK_DGRAM, 0 );
if ( mcast_sockfd < 0 )
jack_error ( "Can't create socket : %s", strerror ( errno ) );
if ( sendto ( mcast_sockfd, &fParams, sizeof ( session_params_t ), 0,
reinterpret_cast<socket_address_t*> ( &fMcastAddr ), sizeof ( socket_address_t ) ) < 0 )
jack_error ( "Can't send suicide request : %s", strerror ( errno ) );
close ( mcast_sockfd );
JackNetSocket mcast_socket ( fMasterManager->fMulticastIP, fSocket.GetPort() );
if ( mcast_socket.NewSocket() == SOCKET_ERROR )
jack_error ( "Can't create socket : %s", StrError ( NET_ERROR_CODE ) );
if ( mcast_socket.SendTo ( &fParams, sizeof ( session_params_t ), 0, fMasterManager->fMulticastIP ) == SOCKET_ERROR )
jack_error ( "Can't send suicide request : %s", StrError ( NET_ERROR_CODE ) );
mcast_socket.Close();
}
int JackNetMaster::Send ( char* buffer, size_t size, int flags )
{
int tx_bytes;
if ( ( tx_bytes = send ( fSockfd, buffer, size, flags ) ) < 0 )
if ( ( tx_bytes = fSocket.Send ( buffer, size, flags ) ) == SOCKET_ERROR )
{
if ( ( errno == ECONNABORTED ) || ( errno == ECONNREFUSED ) || ( errno == ECONNRESET ) )
net_error_t error = fSocket.GetError();
if ( error == NET_CONN_ERROR )
{
//fatal connection issue, exit
jack_error ( "'%s' : %s, please check network connection with '%s'.",
fParams.fName, strerror ( errno ), fParams.fSlaveNetName );
fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName );
Exit();
return 0;
}
else
jack_error ( "Error in send : %s", strerror ( errno ) );
jack_error ( "Error in send : %s", StrError ( NET_ERROR_CODE ) );
}
return tx_bytes;
}
......@@ -295,9 +291,10 @@ namespace Jack
int JackNetMaster::Recv ( size_t size, int flags )
{
int rx_bytes;
if ( ( rx_bytes = recv ( fSockfd, fRxBuffer, size, flags ) ) < 0 )
if ( ( rx_bytes = fSocket.Recv ( fRxBuffer, size, flags ) ) == SOCKET_ERROR )
{
if ( errno == EAGAIN )
net_error_t error = fSocket.GetError();
if ( error == NET_NO_DATA )
{
//too much receive failure, react...
if ( ++fNetJumpCnt == 100 )
......@@ -307,16 +304,16 @@ namespace Jack
}
return 0;
}
else if ( ( errno == ECONNABORTED ) || ( errno == ECONNREFUSED ) || ( errno == ECONNRESET ) )
else if ( error == NET_CONN_ERROR )
{
//fatal connection issue, exit
jack_error ( "'%s' : %s, please check network connection with '%s'.",
fParams.fName, strerror ( errno ), fParams.fSlaveNetName );
fParams.fName, StrError ( NET_ERROR_CODE ), fParams.fSlaveNetName );
Exit();
return 0;
}
else if ( errno != EAGAIN )
jack_error ( "Error in receive : %s", strerror ( errno ) );
else
jack_error ( "Error in receive : %s", StrError ( NET_ERROR_CODE ) );
}
return rx_bytes;
}
......@@ -360,7 +357,7 @@ namespace Jack
if ( !fParams.fSendMidiChannels && !fParams.fSendAudioChannels )
fTxHeader.fIsLastPckt = 'y';
tx_bytes = Send ( reinterpret_cast<char*> ( &fTxHeader ), sizeof ( packet_header_t ), 0 );
if ( tx_bytes < 1 )
if ( ( tx_bytes == 0 ) || ( tx_bytes == SOCKET_ERROR ) )
return tx_bytes;
//midi
......@@ -412,7 +409,7 @@ namespace Jack
switch ( rx_head->fDataType )
{
case 'm': //midi
rx_bytes = Recv ( rx_bytes, MSG_DONTWAIT );
rx_bytes = Recv ( rx_bytes, 0 );
fRxHeader.fIsLastPckt = rx_head->fIsLastPckt;
fNetMidiPlaybackBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) );
if ( ++midi_recvd_pckt == rx_head->fNMidiPckt )
......@@ -420,7 +417,7 @@ namespace Jack
fNetJumpCnt = 0;
break;
case 'a': //audio
rx_bytes = Recv ( fAudioRxLen, MSG_DONTWAIT );
rx_bytes = Recv ( fAudioRxLen, 0 );
if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) )
jack_error ( "Packet(s) missing from '%s'...", fParams.fName );
fRxHeader.fCycle = rx_head->fCycle;
......@@ -439,13 +436,13 @@ namespace Jack
//JackNetMasterManager***********************************************************************************************
JackNetMasterManager::JackNetMasterManager ( jack_client_t* client )
JackNetMasterManager::JackNetMasterManager ( jack_client_t* client ) : fSocket()
{
jack_log ( "JackNetMasterManager::JackNetMasterManager" );
fManagerClient = client;
fManagerName = jack_get_client_name ( fManagerClient );
fMCastIP = DEFAULT_MULTICAST_IP;
fUDPPort = DEFAULT_PORT;
fMulticastIP = DEFAULT_MULTICAST_IP;
fSocket.SetPort ( DEFAULT_PORT );
fGlobalID = 0;
fRunning = true;
......@@ -460,7 +457,9 @@ namespace Jack
Exit();
master_list_t::iterator it;
for ( it = fMasterList.begin(); it != fMasterList.end(); it++ )
delete ( *it );
delete ( *it );
fSocket.Close();
SocketAPIEnd();
}
void* JackNetMasterManager::NetManagerThread ( void* arg )
......@@ -474,79 +473,58 @@ namespace Jack
void JackNetMasterManager::Run()