diff options
174 files changed, 5875 insertions, 5869 deletions
diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index 6af9ada1..808b661e 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -29,16 +29,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackAPI.h" #ifdef __APPLE__ - #include "JackMachThread.h" +#include "JackMachThread.h" #elif WIN32 - #include "JackWinThread.h" +#include "JackWinThread.h" #else - #include "JackPosixThread.h" +#include "JackPosixThread.h" #endif #include <math.h> #ifdef __CLIENTDEBUG__ - #include "JackLibGlobals.h" +#include "JackLibGlobals.h" #endif using namespace Jack; @@ -52,26 +52,26 @@ extern "C" jack_options_t options, jack_status_t *status, ...); EXPORT jack_client_t * jack_client_new (const char *client_name); - EXPORT int jack_client_name_size (void); + EXPORT int jack_client_name_size (void); EXPORT char* jack_get_client_name (jack_client_t *client); EXPORT int jack_internal_client_new (const char *client_name, const char *load_name, const char *load_init); EXPORT void jack_internal_client_close (const char *client_name); - EXPORT int jack_is_realtime (jack_client_t *client); + EXPORT int jack_is_realtime (jack_client_t *client); EXPORT void jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg); EXPORT int jack_set_process_callback (jack_client_t *client, JackProcessCallback process_callback, void *arg); EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status); - - // new - EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*); - EXPORT void jack_cycle_signal (jack_client_t*, int status); - EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg); - - EXPORT int jack_set_thread_init_callback (jack_client_t *client, + + // new + EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*); + EXPORT void jack_cycle_signal (jack_client_t*, int status); + EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg); + + EXPORT int jack_set_thread_init_callback (jack_client_t *client, JackThreadInitCallback thread_init_callback, void *arg); EXPORT int jack_set_freewheel_callback (jack_client_t *client, @@ -85,15 +85,15 @@ extern "C" EXPORT int jack_set_sample_rate_callback (jack_client_t *client, JackSampleRateCallback srate_callback, void *arg); - EXPORT int jack_set_client_registration_callback (jack_client_t *, - JackClientRegistrationCallback - registration_callback, void *arg); + EXPORT int jack_set_client_registration_callback (jack_client_t *, + JackClientRegistrationCallback + registration_callback, void *arg); EXPORT int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg); - EXPORT int jack_set_port_connect_callback (jack_client_t *, - JackPortConnectCallback - connect_callback, void *arg); + EXPORT int jack_set_port_connect_callback (jack_client_t *, + JackPortConnectCallback + connect_callback, void *arg); EXPORT int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *); @@ -122,15 +122,15 @@ extern "C" EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst); EXPORT int jack_port_untie (jack_port_t *port); EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port); - EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *, + EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port); EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t); - EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port); + EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port); EXPORT int jack_recompute_total_latencies (jack_client_t*); EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name); - EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias); - EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias); - EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); + EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff); EXPORT int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff); @@ -218,7 +218,7 @@ extern "C" } #endif -#ifdef WIN32 +#ifdef WIN32 /* missing on Windows : see http://bugs.mysql.com/bug.php?id=15936 */ inline double rint(double nr) { @@ -240,9 +240,9 @@ static inline bool CheckBufferSize(jack_nframes_t buffer_size) static inline void WaitGraphChange() { - JackGraphManager* manager = GetGraphManager(); - JackEngineControl* control = GetEngineControl(); - + JackGraphManager* manager = GetGraphManager(); + JackEngineControl* control = GetEngineControl(); + if (manager && control && manager->IsPendingChange()) { JackLog("WaitGraphChange...\n"); JackSleep(int(control->fPeriodUsecs * 1.1f)); @@ -256,24 +256,24 @@ EXPORT void jack_set_error_function (void (*func)(const char *)) EXPORT jack_client_t* jack_client_new(const char* client_name) { - jack_error("jack_client_new: deprecated"); + jack_error("jack_client_new: deprecated"); int options = JackUseExactName; if (getenv("JACK_START_SERVER") == NULL) options |= JackNoStartServer; - return jack_client_open(client_name, (jack_options_t)options, NULL); + return jack_client_open(client_name, (jack_options_t)options, NULL); } EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_get_buffer called with an incorrect port %ld", myport); return NULL; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetBuffer(myport, frames) : NULL); } } @@ -281,14 +281,14 @@ EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames) EXPORT const char* jack_port_name(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_name called with an incorrect port %ld", myport); return NULL; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetName() : NULL); } } @@ -296,14 +296,14 @@ EXPORT const char* jack_port_name(const jack_port_t* port) EXPORT const char* jack_port_short_name(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_short_name called with an incorrect port %ld", myport); return NULL; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetShortName() : NULL); } } @@ -311,14 +311,14 @@ EXPORT const char* jack_port_short_name(const jack_port_t* port) EXPORT int jack_port_flags(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_flags called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetFlags() : -1); } } @@ -326,14 +326,14 @@ EXPORT int jack_port_flags(const jack_port_t* port) EXPORT const char* jack_port_type(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_flags called an incorrect port %ld", myport); return NULL; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetType() : NULL); } } @@ -341,7 +341,7 @@ EXPORT const char* jack_port_type(const jack_port_t* port) EXPORT int jack_port_connected(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -349,7 +349,7 @@ EXPORT int jack_port_connected(const jack_port_t* port) return -1; } else { WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetConnectionsNum(myport) : -1); } } @@ -357,7 +357,7 @@ EXPORT int jack_port_connected(const jack_port_t* port) EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t src = (jack_port_id_t)port; if (!CheckPort(src)) { @@ -368,21 +368,21 @@ EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name return -1; } else { WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); - jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT); - if (dst == NO_PORT) { - jack_error("Unknown destination port port_name = %s", port_name); - return 0; - } else { - return manager->IsConnected(src, dst); - } + JackGraphManager* manager = GetGraphManager(); + jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT); + if (dst == NO_PORT) { + jack_error("Unknown destination port port_name = %s", port_name); + return 0; + } else { + return manager->IsConnected(src, dst); + } } } EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t mysrc = (jack_port_id_t)src; if (!CheckPort(mysrc)) { @@ -394,26 +394,26 @@ EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst) jack_error("jack_port_tie called with a NULL dst port"); return -1; } - JackGraphManager* manager = GetGraphManager(); - if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) { + JackGraphManager* manager = GetGraphManager(); + if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) { jack_error("jack_port_tie called with ports not belonging to the same client"); return -1; } else { - return manager->GetPort(mydst)->Tie(mysrc); - } + return manager->GetPort(mydst)->Tie(mysrc); + } } EXPORT int jack_port_untie(jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_untie called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->UnTie() : -1); } } @@ -421,7 +421,7 @@ EXPORT int jack_port_untie(jack_port_t* port) EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -429,7 +429,7 @@ EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port) return 0; } else { WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetLatency() : 0); } } @@ -437,26 +437,26 @@ EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port) EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_set_latency called with an incorrect port %ld", myport); } else { - JackGraphManager* manager = GetGraphManager(); - if (manager) - manager->GetPort(myport)->SetLatency(frames); + JackGraphManager* manager = GetGraphManager(); + if (manager) + manager->GetPort(myport)->SetLatency(frames); } } EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif - JackClient* client = (JackClient*)ext_client; - jack_port_id_t myport = (jack_port_id_t)port; + JackClient* client = (JackClient*)ext_client; + jack_port_id_t myport = (jack_port_id_t)port; if (client == NULL) { jack_error("jack_recompute_total_latencies called with a NULL client"); return -1; @@ -464,33 +464,33 @@ EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* jack_error("jack_recompute_total_latencies called with a NULL port"); return -1; } else { - WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); - return (manager ? manager->ComputeTotalLatency(myport) : -1); + WaitGraphChange(); + JackGraphManager* manager = GetGraphManager(); + return (manager ? manager->ComputeTotalLatency(myport) : -1); } } EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif - JackClient* client = (JackClient*)ext_client; - if (client == NULL) { + JackClient* client = (JackClient*)ext_client; + if (client == NULL) { jack_error("jack_recompute_total_latencies called with a NULL client"); return -1; } else { - WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); - return (manager ? manager->ComputeTotalLatencies() : -1); + WaitGraphChange(); + JackGraphManager* manager = GetGraphManager(); + return (manager ? manager->ComputeTotalLatencies() : -1); } } EXPORT int jack_port_set_name(jack_port_t* port, const char* name) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -500,7 +500,7 @@ EXPORT int jack_port_set_name(jack_port_t* port, const char* name) jack_error("jack_port_set_name called with a NULL port name"); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->SetName(name) : -1); } } @@ -508,7 +508,7 @@ EXPORT int jack_port_set_name(jack_port_t* port, const char* name) EXPORT int jack_port_set_alias(jack_port_t* port, const char* name) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -518,7 +518,7 @@ EXPORT int jack_port_set_alias(jack_port_t* port, const char* name) jack_error("jack_port_set_alias called with a NULL port name"); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->SetAlias(name) : -1); } } @@ -526,7 +526,7 @@ EXPORT int jack_port_set_alias(jack_port_t* port, const char* name) EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -536,7 +536,7 @@ EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name) jack_error("jack_port_unset_alias called with a NULL port name"); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1); } } @@ -544,14 +544,14 @@ EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name) EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2]) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_get_aliases called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1); } } @@ -559,14 +559,14 @@ EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2] EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_request_monitor called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->RequestMonitor(myport, onoff) : -1); } } @@ -574,16 +574,16 @@ EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff) EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_port_request_monitor_by_name called with a NULL client"); return -1; } else { - JackGraphManager* manager = GetGraphManager(); - if (!manager) - return -1; + JackGraphManager* manager = GetGraphManager(); + if (!manager) + return -1; jack_port_id_t myport = manager->GetPort(port_name); if (!CheckPort(myport)) { jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name); @@ -597,29 +597,29 @@ EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const ch EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); - return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1); + JackGraphManager* manager = GetGraphManager(); + return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1); } } EXPORT int jack_port_monitoring_input(jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport); return -1; } else { - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->MonitoringInput() : -1); } } @@ -627,14 +627,14 @@ EXPORT int jack_port_monitoring_input(jack_port_t* port) EXPORT int jack_is_realtime(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_is_realtime called with a NULL client"); return -1; } else { - JackEngineControl* control = GetEngineControl(); + JackEngineControl* control = GetEngineControl(); return (control ? control->fRealTime : -1); } } @@ -642,7 +642,7 @@ EXPORT int jack_is_realtime(jack_client_t* ext_client) EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -655,7 +655,7 @@ EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* a EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -669,12 +669,12 @@ EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallb EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_thread_wait called with a NULL client"); - return 0; + return 0; } else { return client->Wait(status); } @@ -683,12 +683,12 @@ EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status) EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_cycle_wait called with a NULL client"); - return 0; + return 0; } else { return client->CycleWait(); } @@ -697,12 +697,12 @@ EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client) EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_cycle_signal called with a NULL client"); - } else { + } else { client->CycleSignal(status); } } @@ -710,13 +710,13 @@ EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status) EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_set_process_thread called with a NULL client"); - return -1; - } else { + return -1; + } else { return client->SetProcessThread(fun, arg); } } @@ -724,7 +724,7 @@ EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -738,7 +738,7 @@ EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelC EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -752,15 +752,15 @@ EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff) EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_set_buffer_size called with a NULL client"); return -1; } else if (!CheckBufferSize(buffer_size)) { - return -1; - } else { + return -1; + } else { return client->SetBufferSize(buffer_size); } } @@ -768,7 +768,7 @@ EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -782,7 +782,7 @@ EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSi EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -797,21 +797,21 @@ EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRa EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_set_client_registration_callback called with a NULL client"); return -1; } else { - return client->SetClientRegistrationCallback(registration_callback, arg); + return client->SetClientRegistrationCallback(registration_callback, arg); } } EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -825,7 +825,7 @@ EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPo EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -839,7 +839,7 @@ EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortCon EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client); @@ -854,7 +854,7 @@ EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrd EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -868,7 +868,7 @@ EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xr EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client); @@ -883,7 +883,7 @@ EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadIn EXPORT int jack_activate(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -897,7 +897,7 @@ EXPORT int jack_activate(jack_client_t* ext_client) EXPORT int jack_deactivate(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -911,7 +911,7 @@ EXPORT int jack_deactivate(jack_client_t* ext_client) EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -928,7 +928,7 @@ EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* po EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -946,7 +946,7 @@ EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port) EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -964,7 +964,7 @@ EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* EXPORT const char** jack_port_get_connections(const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif jack_port_id_t myport = (jack_port_id_t)port; if (!CheckPort(myport)) { @@ -972,7 +972,7 @@ EXPORT const char** jack_port_get_connections(const jack_port_t* port) return NULL; } else { WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetConnections(myport) : NULL); } } @@ -981,7 +981,7 @@ EXPORT const char** jack_port_get_connections(const jack_port_t* port) EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -995,7 +995,7 @@ EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_clien return NULL; } else { WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetConnections(myport) : NULL); } } @@ -1003,7 +1003,7 @@ EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_clien EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1016,8 +1016,8 @@ EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jac jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport); return 0; } else { - WaitGraphChange(); - JackGraphManager* manager = GetGraphManager(); + WaitGraphChange(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPort(myport)->GetTotalLatency() : 0); } } @@ -1025,7 +1025,7 @@ EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jac EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1042,7 +1042,7 @@ EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1059,7 +1059,7 @@ EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const cha EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1082,7 +1082,7 @@ EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_p EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1100,14 +1100,14 @@ EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src) EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_get_sample_rate called with a NULL client"); return 0; } else { - JackEngineControl* control = GetEngineControl(); + JackEngineControl* control = GetEngineControl(); return (control ? control->fSampleRate : 0); } } @@ -1115,14 +1115,14 @@ EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client) EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_get_buffer_size called with a NULL client"); return 0; } else { - JackEngineControl* control = GetEngineControl(); + JackEngineControl* control = GetEngineControl(); return (control ? control->fBufferSize : 0); } } @@ -1130,21 +1130,21 @@ EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client) EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_get_ports called with a NULL client"); return NULL; } - JackGraphManager* manager = GetGraphManager(); + JackGraphManager* manager = GetGraphManager(); return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL); } EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1156,9 +1156,9 @@ EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* por jack_error("jack_port_by_name called with a NULL port name"); return NULL; } else { - JackGraphManager* manager = GetGraphManager(); - if (!manager) - return NULL; + JackGraphManager* manager = GetGraphManager(); + if (!manager) + return NULL; int res = manager->GetPort(portname); // returns a port index at least > 1 return (res == NO_PORT) ? NULL : (jack_port_t*)res; } @@ -1167,7 +1167,7 @@ EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* por EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif /* jack_port_t* type is actually the port index */ return (jack_port_t*)id; @@ -1176,7 +1176,7 @@ EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1191,13 +1191,13 @@ EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client) EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackTimer timer; - JackEngineControl* control = GetEngineControl(); - if (!control) - return 0; - control->ReadFrameTime(&timer); + JackEngineControl* control = GetEngineControl(); + if (!control) + return 0; + control->ReadFrameTime(&timer); return (jack_nframes_t) floor((((float)control->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback)); } @@ -1209,7 +1209,7 @@ EXPORT jack_time_t jack_get_time() EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1217,10 +1217,10 @@ EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nfr return 0; } else { JackTimer timer; - JackEngineControl* control = GetEngineControl(); - if (!control) - return 0; - control->ReadFrameTime(&timer); + JackEngineControl* control = GetEngineControl(); + if (!control) + return 0; + control->ReadFrameTime(&timer); if (timer.fInitialized) { return timer.fCurrentWakeup + (long) rint(((double) ((frames - timer.fFrames)) * @@ -1234,7 +1234,7 @@ EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nfr EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1242,10 +1242,10 @@ EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_ return 0; } else { JackTimer timer; - JackEngineControl* control = GetEngineControl(); - if (!control) - return 0; - control->ReadFrameTime(&timer); + JackEngineControl* control = GetEngineControl(); + if (!control) + return 0; + control->ReadFrameTime(&timer); if (timer.fInitialized) { return timer.fFrames + (long) rint(((double) ((time - timer.fCurrentWakeup)) / @@ -1264,29 +1264,29 @@ EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client) EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackTimer timer; - JackEngineControl* control = GetEngineControl(); - if (control) { - control->ReadFrameTime(&timer); - return timer.fFrames; - } else { - return 0; - } + JackEngineControl* control = GetEngineControl(); + if (control) { + control->ReadFrameTime(&timer); + return timer.fFrames; + } else { + return 0; + } } EXPORT float jack_cpu_load(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_cpu_load called with a NULL client"); return 0.0f; } else { - JackEngineControl* control = GetEngineControl(); + JackEngineControl* control = GetEngineControl(); return (control ? control->fCPULoad : 0.0f); } } @@ -1294,7 +1294,7 @@ EXPORT float jack_cpu_load(jack_client_t* ext_client) EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1308,7 +1308,7 @@ EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client) EXPORT char* jack_get_client_name (jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1331,14 +1331,14 @@ EXPORT int jack_port_name_size(void) EXPORT int jack_port_type_size(void) { - return JACK_PORT_TYPE_SIZE; + return JACK_PORT_TYPE_SIZE; } // transport.h EXPORT int jack_release_timebase(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1352,7 +1352,7 @@ EXPORT int jack_release_timebase(jack_client_t* ext_client) EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1366,7 +1366,7 @@ EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sy EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1380,7 +1380,7 @@ EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout) EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1394,7 +1394,7 @@ EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1408,7 +1408,7 @@ EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1422,7 +1422,7 @@ EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_clie EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1436,7 +1436,7 @@ EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_ EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1450,7 +1450,7 @@ EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* EXPORT void jack_transport_start(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1463,7 +1463,7 @@ EXPORT void jack_transport_start(jack_client_t* ext_client) EXPORT void jack_transport_stop(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { @@ -1492,7 +1492,7 @@ EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_in EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackLog("jack_get_max_delayed_usecs: not yet implemented\n"); return 0.f; @@ -1501,7 +1501,7 @@ EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client) EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n"); return 0.f; @@ -1510,7 +1510,7 @@ EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client) EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackLog("jack_reset_max_delayed_usecs: not yet implemented\n"); } @@ -1518,14 +1518,14 @@ EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client) // thread.h EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority) { - #ifdef __APPLE__ - JackEngineControl* control = GetEngineControl(); - return (control ? JackMachThread::AcquireRealTimeImp(thread, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1); - #elif WIN32 - return JackWinThread::AcquireRealTimeImp(thread, priority); - #else - return JackPosixThread::AcquireRealTimeImp(thread, priority); - #endif +#ifdef __APPLE__ + JackEngineControl* control = GetEngineControl(); + return (control ? JackMachThread::AcquireRealTimeImp(thread, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1); +#elif WIN32 + return JackWinThread::AcquireRealTimeImp(thread, priority); +#else + return JackPosixThread::AcquireRealTimeImp(thread, priority); +#endif } EXPORT int jack_client_create_thread(jack_client_t* client, @@ -1535,53 +1535,53 @@ EXPORT int jack_client_create_thread(jack_client_t* client, void *(*start_routine)(void*), void *arg) { - #ifdef __APPLE__ - return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); - #elif WIN32 - return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg); - #else - return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); - #endif +#ifdef __APPLE__ + return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); +#elif WIN32 + return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg); +#else + return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); +#endif } EXPORT int jack_drop_real_time_scheduling(pthread_t thread) { - #ifdef __APPLE__ - return JackMachThread::DropRealTimeImp(thread); - #elif WIN32 - return JackWinThread::DropRealTimeImp(thread); - #else - return JackPosixThread::DropRealTimeImp(thread); - #endif +#ifdef __APPLE__ + return JackMachThread::DropRealTimeImp(thread); +#elif WIN32 + return JackWinThread::DropRealTimeImp(thread); +#else + return JackPosixThread::DropRealTimeImp(thread); +#endif } // intclient.h EXPORT int jack_internal_client_new (const char *client_name, - const char *load_name, - const char *load_init) + const char *load_name, + const char *load_init) { - jack_error("jack_internal_client_new: deprecated"); - return -1; + jack_error("jack_internal_client_new: deprecated"); + return -1; } EXPORT void jack_internal_client_close (const char *client_name) { - jack_error("jack_internal_client_close: deprecated"); + jack_error("jack_internal_client_close: deprecated"); } EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_get_internal_client_name called with a NULL client"); - return NULL; + return NULL; } else if (intclient < 0 || intclient >= CLIENT_NUM) { - jack_error("jack_get_internal_client_name: incorrect client"); - return NULL; - } else { + jack_error("jack_get_internal_client_name: incorrect client"); + return NULL; + } else { return client->GetInternalClientName(intclient); } } @@ -1589,17 +1589,17 @@ EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intcl EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_internal_client_handle called with a NULL client"); - return 0; + return 0; } else { - jack_status_t my_status; - if (status == NULL) /* no status from caller? */ - status = &my_status; /* use local status word */ - *status = (jack_status_t)0; + jack_status_t my_status; + if (status == NULL) /* no status from caller? */ + status = &my_status; /* use local status word */ + *status = (jack_status_t)0; return client->InternalClientHandle(client_name, status); } } @@ -1607,33 +1607,33 @@ EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, c EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_internal_client_load called with a NULL client"); - return 0; - } else { - va_list ap; - jack_varargs_t va; - jack_status_t my_status; - - if (status == NULL) /* no status from caller? */ - status = &my_status; /* use local status word */ - *status = (jack_status_t)0; - - /* validate parameters */ - if ((options & ~JackLoadOptions)) { - int my_status1 = *status | (JackFailure | JackInvalidOption); - *status = (jack_status_t)my_status1; - return 0; - } - - /* parse variable arguments */ - va_start(ap, status); - jack_varargs_parse(options, ap, &va); - va_end(ap); - + return 0; + } else { + va_list ap; + jack_varargs_t va; + jack_status_t my_status; + + if (status == NULL) /* no status from caller? */ + status = &my_status; /* use local status word */ + *status = (jack_status_t)0; + + /* validate parameters */ + if ((options & ~JackLoadOptions)) { + int my_status1 = *status | (JackFailure | JackInvalidOption); + *status = (jack_status_t)my_status1; + return 0; + } + + /* parse variable arguments */ + va_start(ap, status); + jack_varargs_parse(options, ap, &va); + va_end(ap); + return client->InternalClientLoad(client_name, options, status, &va); } } @@ -1641,18 +1641,18 @@ EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, con EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient) { #ifdef __CLIENTDEBUG__ - JackLibGlobals::CheckContext(); + JackLibGlobals::CheckContext(); #endif JackClient* client = (JackClient*)ext_client; if (client == NULL) { jack_error("jack_internal_client_unload called with a NULL client"); - return (jack_status_t)(JackNoSuchClient | JackFailure); - } else if (intclient < 0 || intclient >= CLIENT_NUM) { - jack_error("jack_internal_client_unload: incorrect client"); - return (jack_status_t)(JackNoSuchClient | JackFailure); - } else { - jack_status_t my_status; + return (jack_status_t)(JackNoSuchClient | JackFailure); + } else if (intclient < 0 || intclient >= CLIENT_NUM) { + jack_error("jack_internal_client_unload: incorrect client"); + return (jack_status_t)(JackNoSuchClient | JackFailure); + } else { + jack_status_t my_status; client->InternalClientUnload(intclient, &my_status); - return my_status; + return my_status; } } diff --git a/common/JackAPIWrapper.cpp b/common/JackAPIWrapper.cpp index 0e467bc4..5641219b 100644 --- a/common/JackAPIWrapper.cpp +++ b/common/JackAPIWrapper.cpp @@ -31,11 +31,11 @@ extern "C" { #endif - EXPORT jack_client_t * jack_client_open (const char *client_name, + EXPORT jack_client_t * jack_client_open (const char *client_name, jack_options_t options, jack_status_t *status, ...); EXPORT jack_client_t * jack_client_new (const char *client_name); - EXPORT int jack_client_name_size (void); + EXPORT int jack_client_name_size (void); EXPORT char* jack_get_client_name (jack_client_t *client); EXPORT int jack_internal_client_new (const char *client_name, const char *load_name, @@ -47,13 +47,13 @@ extern "C" EXPORT int jack_set_process_callback (jack_client_t *client, JackProcessCallback process_callback, void *arg); - // - EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status); - // new - EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*); - EXPORT void jack_cycle_signal (jack_client_t*, int status); - EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg); - + // + EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status); + // new + EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*); + EXPORT void jack_cycle_signal (jack_client_t*, int status); + EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg); + EXPORT int jack_set_thread_init_callback (jack_client_t *client, JackThreadInitCallback thread_init_callback, void *arg); @@ -68,18 +68,18 @@ extern "C" EXPORT int jack_set_sample_rate_callback (jack_client_t *client, JackSampleRateCallback srate_callback, void *arg); - // - EXPORT int jack_set_client_registration_callback (jack_client_t *, - JackClientRegistrationCallback - registration_callback, void *arg); - EXPORT int jack_set_port_registration_callback (jack_client_t *, + // + EXPORT int jack_set_client_registration_callback (jack_client_t *, + JackClientRegistrationCallback + registration_callback, void *arg); + EXPORT int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg); - // - EXPORT int jack_set_port_connect_callback (jack_client_t *, - JackPortConnectCallback - connect_callback, void *arg); - + // + EXPORT int jack_set_port_connect_callback (jack_client_t *, + JackPortConnectCallback + connect_callback, void *arg); + EXPORT int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *); @@ -111,14 +111,14 @@ extern "C" EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port); EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t); - // + // EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port); EXPORT int jack_recompute_total_latencies (jack_client_t*); EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name); - // - EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias); - EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias); - EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); + // + EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff); EXPORT int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff); @@ -144,11 +144,11 @@ extern "C" jack_port_id_t port_id); EXPORT int jack_engine_takeover_timebase (jack_client_t *); EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *); - // - EXPORT jack_time_t jack_get_time(); + // + EXPORT jack_time_t jack_get_time(); EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time); EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames); - + EXPORT jack_nframes_t jack_frame_time (const jack_client_t *); EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client); EXPORT float jack_cpu_load (jack_client_t *client); @@ -203,8 +203,8 @@ extern "C" jack_status_t *status, ...); EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client, jack_intclient_t intclient); - - EXPORT jack_client_t * jack_client_open (const char *client_name, + + EXPORT jack_client_t * jack_client_open (const char *client_name, jack_options_t options, jack_status_t *status, ...); EXPORT jack_client_t * jack_client_new (const char *client_name); @@ -220,7 +220,7 @@ typedef void* (*jack_port_get_buffer_fun_def)(jack_port_t* port, jack_nframes_t static jack_port_get_buffer_fun_def jack_port_get_buffer_fun = 0; EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames) { - return (*jack_port_get_buffer_fun)(port, frames); + return (*jack_port_get_buffer_fun)(port, frames); } typedef const char* (*jack_port_name_fun_def)(const jack_port_t* port); @@ -283,7 +283,7 @@ typedef jack_nframes_t (*jack_port_get_latency_fun_def)(jack_port_t* port); static jack_port_get_latency_fun_def jack_port_get_latency_fun = 0; EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port) { - return (*jack_port_get_latency)(port); + return (*jack_port_get_latency)(port); } typedef void (*jack_port_set_latency_fun_def)(jack_port_t* port, jack_nframes_t frames); @@ -297,14 +297,14 @@ typedef int (*jack_recompute_total_latency_fun_def)(jack_client_t* ext_client, j static jack_recompute_total_latency_fun_def jack_recompute_total_latency_fun = 0; EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port) { - return (*jack_recompute_total_latency_fun)(ext_client, port); + return (*jack_recompute_total_latency_fun)(ext_client, port); } typedef int (*jack_recompute_total_latencies_fun_def)(jack_client_t* ext_client); static jack_recompute_total_latencies_fun_def jack_recompute_total_latencies_fun = 0; EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client) { - return (*jack_recompute_total_latencies_fun)(ext_client); + return (*jack_recompute_total_latencies_fun)(ext_client); } typedef int (*jack_port_set_name_fun_def)(jack_port_t* port, const char* name); @@ -537,7 +537,7 @@ typedef jack_nframes_t (*jack_get_buffer_size_fun_def)(jack_client_t* ext_client static jack_get_buffer_size_fun_def jack_get_buffer_size_fun = 0; EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client) { - return (*jack_get_buffer_size_fun)(ext_client); + return (*jack_get_buffer_size_fun)(ext_client); } typedef const char** (*jack_get_ports_fun_def)(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); @@ -707,7 +707,7 @@ typedef void (*jack_transport_stop_fun_def)(jack_client_t* ext_client); static jack_transport_stop_fun_def jack_transport_stop_fun = 0; EXPORT void jack_transport_stop(jack_client_t* ext_client) { - return (*jack_transport_stop_fun)(ext_client); + return (*jack_transport_stop_fun)(ext_client); } // deprecated @@ -760,16 +760,16 @@ EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority) typedef void *(*start_routine)(void*); typedef int (*jack_client_create_thread_fun_def)(jack_client_t* client, - pthread_t *thread, - int priority, - int realtime, // boolean - start_routine callback, - void *arg); + pthread_t *thread, + int priority, + int realtime, // boolean + start_routine callback, + void *arg); static jack_client_create_thread_fun_def jack_client_create_thread_fun = 0; EXPORT int jack_client_create_thread(jack_client_t* client, pthread_t *thread, int priority, - int realtime, // boolean + int realtime, // boolean start_routine callback, void *arg) { @@ -803,11 +803,11 @@ typedef jack_intclient_t (*jack_internal_client_load_fun_def)(jack_client_t* ext static jack_internal_client_load_fun_def jack_internal_client_load_fun = 0; EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...) { - va_list ap; - va_start(ap, status); - jack_intclient_t res = (*jack_internal_client_load_fun)(ext_client, client_name, options, status, ap); - va_end(ap); - return res; + va_list ap; + va_start(ap, status); + jack_intclient_t res = (*jack_internal_client_load_fun)(ext_client, client_name, options, status, ap); + va_end(ap); + return res; } typedef jack_status_t (*jack_internal_client_unload_fun_def)(jack_client_t* ext_client, jack_intclient_t intclient); @@ -828,223 +828,223 @@ typedef jack_client_t * (*jack_client_open_fun_def)(const char *client_name, jac static jack_client_open_fun_def jack_client_open_fun = 0; EXPORT jack_client_t * jack_client_open(const char *client_name, jack_options_t options, jack_status_t *status, ...) { - // Library check... - if (!open_library()) - return 0; - - va_list ap; - va_start(ap, status); - jack_client_t* res = (*jack_client_open_fun)(client_name, options, status, ap); - va_end(ap); - return res; + // Library check... + if (!open_library()) + return 0; + + va_list ap; + va_start(ap, status); + jack_client_t* res = (*jack_client_open_fun)(client_name, options, status, ap); + va_end(ap); + return res; } typedef jack_client_t * (*jack_client_new_fun_def)(const char *client_name); static jack_client_new_fun_def jack_client_new_fun = 0; EXPORT jack_client_t * jack_client_new(const char *client_name) { - // Library check... - if (!open_library()) - return 0; - - return (*jack_client_new_fun)(client_name); + // Library check... + if (!open_library()) + return 0; + + return (*jack_client_new_fun)(client_name); } typedef int (*jack_client_close_fun_def)(jack_client_t *client); static jack_client_close_fun_def jack_client_close_fun = 0; EXPORT int jack_client_close(jack_client_t *client) -{ - int res = (*jack_client_close_fun)(client); - close_library(); - return res; +{ + int res = (*jack_client_close_fun)(client); + close_library(); + return res; } // Library loader static bool get_jack_library_in_directory(const char* dir_name, char* library_name) { - struct dirent * dir_entry; - DIR * dir_stream = opendir(dir_name); - if (!dir_stream) - return false; - - while ((dir_entry = readdir(dir_stream))) { - if (strncmp("libjack.so", dir_entry->d_name, 10) == 0) { + struct dirent * dir_entry; + DIR * dir_stream = opendir(dir_name); + if (!dir_stream) + return false; + + while ((dir_entry = readdir(dir_stream))) { + if (strncmp("libjack.so", dir_entry->d_name, 10) == 0) { strcpy(library_name, dir_entry->d_name); - closedir(dir_stream); - return true; + closedir(dir_stream); + return true; } - } - closedir(dir_stream); - return false; + } + closedir(dir_stream); + return false; } static bool get_jack_library(char* library_name) { - if (get_jack_library_in_directory("/usr/lib", library_name)) - return true; - if (get_jack_library_in_directory("/usr/local/lib", library_name)) - return true; - return false; + if (get_jack_library_in_directory("/usr/lib", library_name)) + return true; + if (get_jack_library_in_directory("/usr/local/lib", library_name)) + return true; + return false; } static bool open_library() { - if (gClientCount++ == 0) { - return init_library(); - } else { - return true; - } + if (gClientCount++ == 0) { + return init_library(); + } else { + return true; + } } static void close_library() { - if (--gClientCount == 0) { - dlclose(gLibrary); - } + if (--gClientCount == 0) { + dlclose(gLibrary); + } } static bool check_client(void* library) { - jack_client_t* client = 0; + jack_client_t* client = 0; - // Get "new", "open" and "close" entry points... - jack_client_new_fun = (jack_client_new_fun_def)dlsym(library, "jack_client_new"); - jack_client_close_fun = (jack_client_close_fun_def)dlsym(library, "jack_client_close"); - jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open"); + // Get "new", "open" and "close" entry points... + jack_client_new_fun = (jack_client_new_fun_def)dlsym(library, "jack_client_new"); + jack_client_close_fun = (jack_client_close_fun_def)dlsym(library, "jack_client_close"); + jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open"); - // Try opening a client... - if ((client = (*jack_client_new_fun)("dummy"))) { // jackd server is running.... - (*jack_client_close_fun)(client); - return true; - } else { - return false; - } + // Try opening a client... + if ((client = (*jack_client_new_fun)("dummy"))) { // jackd server is running.... + (*jack_client_close_fun)(client); + return true; + } else { + return false; + } } static bool init_library() { - char library_name[64]; - void* jackLibrary = (get_jack_library(library_name)) ? dlopen(library_name, RTLD_LAZY) : 0; - void* jackmpLibrary = dlopen("libjackmp.so", RTLD_LAZY); - - if (jackLibrary) { - - if (check_client(jackLibrary)) { // jackd is running... - gLibrary = jackLibrary; - if (jackmpLibrary) dlclose(jackmpLibrary); - } else if (check_client(jackmpLibrary)) { // jackdmp is running... - gLibrary = jackmpLibrary; - if (jackLibrary) dlclose(jackLibrary); - } else { - goto error; - } - - } else if (jackmpLibrary) { - - if (check_client(jackmpLibrary)) { // jackd is running... - gLibrary = jackmpLibrary; - } else { - goto error; - } - - } else { - printf("Jack libraries not found, failure...\n"); - goto error; - } - - // Load entry points... - jack_port_get_buffer_fun = (jack_port_get_buffer_fun_def)dlsym(gLibrary, "jack_port_get_buffer"); - jack_port_name_fun = (jack_port_name_fun_def)dlsym(gLibrary, "jack_port_name"); - jack_port_short_name_fun = (jack_port_short_name_fun_def)dlsym(gLibrary, "jack_port_short_name"); - jack_port_flags_fun = (jack_port_flags_fun_def)dlsym(gLibrary, "jack_port_flags"); - jack_port_type_fun = (jack_port_type_fun_def)dlsym(gLibrary, "jack_port_type"); - jack_port_connected_fun = (jack_port_connected_fun_def)dlsym(gLibrary, "jack_port_connected"); - jack_port_connected_to_fun = (jack_port_connected_to_fun_def)dlsym(gLibrary, "jack_port_connected_to"); - jack_port_tie_fun = (jack_port_tie_fun_def)dlsym(gLibrary, "jack_port_tie"); - jack_port_untie_fun = (jack_port_untie_fun_def)dlsym(gLibrary, "jack_port_untie"); - jack_port_get_latency_fun = (jack_port_get_latency_fun_def)dlsym(gLibrary, "jack_port_get_latency"); - jack_port_set_latency_fun = (jack_port_set_latency_fun_def)dlsym(gLibrary, "jack_port_set_latency"); - jack_recompute_total_latency_fun = (jack_recompute_total_latency_fun_def)dlsym(gLibrary, "jack_recompute_total_latency"); - jack_recompute_total_latencies_fun = (jack_recompute_total_latencies_fun_def)dlsym(gLibrary, "jack_recompute_total_latencies"); - jack_port_set_name_fun = (jack_port_set_name_fun_def)dlsym(gLibrary, "jack_port_set_name"); - jack_port_request_monitor_fun = (jack_port_request_monitor_fun_def)dlsym(gLibrary, "jack_port_request_monitor"); - jack_port_request_monitor_by_name_fun = (jack_port_request_monitor_by_name_fun_def)dlsym(gLibrary, "jack_port_request_monitor_by_name"); - jack_port_ensure_monitor_fun = (jack_port_ensure_monitor_fun_def)dlsym(gLibrary, "jack_port_ensure_monitor"); - jack_port_monitoring_input_fun = (jack_port_monitoring_input_fun_def)dlsym(gLibrary, "jack_port_monitoring_input_fun"); - jack_is_realtime_fun = (jack_is_realtime_fun_def)dlsym(gLibrary, "jack_is_realtime"); - jack_on_shutdown_fun = (jack_on_shutdown_fun_def)dlsym(gLibrary, "jack_on_shutdown"); - jack_set_process_callback_fun = (jack_set_process_callback_fun_def)dlsym(gLibrary, "jack_set_process_callback"); - jack_set_freewheel_callback_fun = (jack_set_freewheel_callback_fun_def)dlsym(gLibrary, "jack_set_freewheel_callback"); - jack_set_freewheel_fun = (jack_set_freewheel_fun_def)dlsym(gLibrary, "jack_set_freewheel"); - jack_set_buffer_size_fun = (jack_set_buffer_size_fun_def)dlsym(gLibrary, "jack_set_buffer_size"); - jack_set_buffer_size_callback_fun = (jack_set_buffer_size_callback_fun_def)dlsym(gLibrary, "jack_set_buffer_size_callback"); - jack_set_sample_rate_callback_fun = (jack_set_sample_rate_callback_fun_def)dlsym(gLibrary, "jack_set_sample_rate_callback"); - jack_set_client_registration_callback_fun = (jack_set_client_registration_callback_fun_def)dlsym(gLibrary, "jack_set_client_registration_callback"); - jack_set_port_registration_callback_fun = (jack_set_port_registration_callback_fun_def)dlsym(gLibrary, "jack_set_port_registration_callback"); - jack_set_port_connect_callback_fun = (jack_set_port_connect_callback_fun_def)dlsym(gLibrary, "jack_set_port_connect_callback"); - jack_set_graph_order_callback_fun = (jack_set_graph_order_callback_fun_def)dlsym(gLibrary, "jack_set_graph_order_callback"); - jack_set_xrun_callback_fun = (jack_set_xrun_callback_fun_def)dlsym(gLibrary, "jack_set_xrun_callback"); - jack_set_thread_init_callback_fun = (jack_set_thread_init_callback_fun_def)dlsym(gLibrary, "jack_set_thread_init_callback"); - jack_activate_fun = (jack_activate_fun_def)dlsym(gLibrary, "jack_activate"); - jack_deactivate_fun = (jack_deactivate_fun_def)dlsym(gLibrary, "jack_deactivate"); - jack_port_register_fun = (jack_port_register_fun_def)dlsym(gLibrary, "jack_port_register"); - jack_port_unregister_fun = (jack_port_unregister_fun_def)dlsym(gLibrary, "jack_port_unregister"); - jack_port_is_mine_fun = (jack_port_is_mine_fun_def)dlsym(gLibrary, "jack_port_is_mine"); - jack_port_get_connections_fun = (jack_port_get_connections_fun_def)dlsym(gLibrary, "jack_port_get_connections"); - jack_port_get_all_connections_fun = (jack_port_get_all_connections_fun_def)dlsym(gLibrary, "jack_port_get_all_connections_fun"); - jack_port_get_total_latency_fun = (jack_port_get_total_latency_fun_def)dlsym(gLibrary, "jack_port_get_total_latency"); - jack_connect_fun = (jack_connect_fun_def)dlsym(gLibrary, "jack_connect"); - jack_disconnect_fun = (jack_disconnect_fun_def)dlsym(gLibrary, "jack_disconnect"); - jack_port_connect_fun = (jack_port_connect_fun_def)dlsym(gLibrary, "jack_port_connect"); - jack_port_disconnect_fun = (jack_port_disconnect_fun_def)dlsym(gLibrary, "jack_port_disconnect"); - jack_get_sample_rate_fun = (jack_get_sample_rate_fun_def)dlsym(gLibrary, "jack_get_sample_rate"); - jack_get_buffer_size_fun = (jack_get_buffer_size_fun_def)dlsym(gLibrary, "jack_get_buffer_size"); - jack_get_ports_fun = (jack_get_ports_fun_def)dlsym(gLibrary, "jack_get_ports"); - jack_port_by_name_fun = (jack_port_by_name_fun_def)dlsym(gLibrary, "jack_port_by_name"); - jack_port_by_id_fun = (jack_port_by_id_fun_def)dlsym(gLibrary, "jack_port_by_id"); - jack_engine_takeover_timebase_fun = (jack_engine_takeover_timebase_fun_def)dlsym(gLibrary, "jack_engine_takeover_timebase"); - jack_frames_since_cycle_start_fun = (jack_frames_since_cycle_start_fun_def)dlsym(gLibrary, "jack_frames_since_cycle_start"); - jack_get_time_fun = (jack_get_time_fun_def)dlsym(gLibrary, "jack_get_time"); - jack_time_to_frames_fun = (jack_time_to_frames_fun_def)dlsym(gLibrary, "jack_time_to_frames"); - jack_frame_time_fun = (jack_frame_time_fun_def)dlsym(gLibrary, "jack_frame_time"); - jack_last_frame_time_fun = (jack_last_frame_time_fun_def)dlsym(gLibrary, "jack_last_frame_time"); - jack_cpu_load_fun = (jack_cpu_load_fun_def)dlsym(gLibrary, "jack_cpu_load"); - jack_client_thread_id_fun = (jack_client_thread_id_fun_def)dlsym(gLibrary, "jack_client_thread_id"); - jack_get_client_name_fun = (jack_get_client_name_fun_def)dlsym(gLibrary, "jack_get_client_name"); - jack_port_name_size_fun = (jack_port_name_size_fun_def)dlsym(gLibrary, "jack_port_name_size"); - jack_client_name_size_fun = (jack_client_name_size_fun_def)dlsym(gLibrary, "jack_client_name_size"); - jack_release_timebase_fun = (jack_release_timebase_fun_def)dlsym(gLibrary, "jack_release_timebase"); - jack_set_sync_callback_fun = (jack_set_sync_callback_fun_def)dlsym(gLibrary, "jack_set_sync_callback"); - jack_set_sync_timeout_fun = (jack_set_sync_timeout_fun_def)dlsym(gLibrary, "jack_set_sync_timeout"); - jack_set_timebase_callback_fun = (jack_set_timebase_callback_fun_def)dlsym(gLibrary, "jack_set_timebase_callback"); - jack_transport_locate_fun = (jack_transport_locate_fun_def)dlsym(gLibrary, "jack_transport_locate_fun"); - jack_transport_query_fun = (jack_transport_query_fun_def)dlsym(gLibrary, "jack_transport_query"); - jack_get_current_transport_frame_fun = (jack_get_current_transport_frame_fun_def)dlsym(gLibrary, "jack_get_current_transport_frame"); - jack_transport_reposition_fun = (jack_transport_reposition_fun_def)dlsym(gLibrary, "jack_transport_reposition"); - jack_transport_start_fun = (jack_transport_start_fun_def)dlsym(gLibrary, "jack_transport_start"); - jack_transport_stop_fun = (jack_transport_stop_fun_def)dlsym(gLibrary, "jack_transport_stop"); - jack_get_transport_info_fun = (jack_get_transport_info_fun_def)dlsym(gLibrary, "jack_get_transport_info"); - jack_set_transport_info_fun = (jack_set_transport_info_fun_def)dlsym(gLibrary, "jack_set_transport_info"); - jack_get_max_delayed_usecs_fun = (jack_get_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_max_delayed_usecs"); - jack_get_xrun_delayed_usecs_fun = (jack_get_xrun_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_xrun_delayed_usecs"); - jack_reset_max_delayed_usecs_fun = (jack_reset_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_reset_max_delayed_usecs"); - jack_acquire_real_time_scheduling_fun = (jack_acquire_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_acquire_real_time_scheduling"); - jack_client_create_thread_fun = (jack_client_create_thread_fun_def)dlsym(gLibrary, "jack_client_create_thread"); - jack_drop_real_time_scheduling_fun = (jack_drop_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_drop_real_time_scheduling"); - jack_get_internal_client_name_fun = (jack_get_internal_client_name_fun_def)dlsym(gLibrary, "jack_get_internal_client_name"); - jack_internal_client_handle_fun = (jack_internal_client_handle_fun_def)dlsym(gLibrary, "jack_internal_client_handle"); - jack_internal_client_load_fun = (jack_internal_client_load_fun_def)dlsym(gLibrary, "jack_internal_client_load"); - jack_internal_client_unload_fun = (jack_internal_client_unload_fun_def)dlsym(gLibrary, "jack_internal_client_unload"); - jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open"); - jack_client_new_fun = (jack_client_new_fun_def)dlsym(gLibrary, "jack_client_new"); - jack_client_close_fun = (jack_client_close_fun_def)dlsym(gLibrary, "jack_client_close"); - - return true; + char library_name[64]; + void* jackLibrary = (get_jack_library(library_name)) ? dlopen(library_name, RTLD_LAZY) : 0; + void* jackmpLibrary = dlopen("libjackmp.so", RTLD_LAZY); + + if (jackLibrary) { + + if (check_client(jackLibrary)) { // jackd is running... + gLibrary = jackLibrary; + if (jackmpLibrary) dlclose(jackmpLibrary); + } else if (check_client(jackmpLibrary)) { // jackdmp is running... + gLibrary = jackmpLibrary; + if (jackLibrary) dlclose(jackLibrary); + } else { + goto error; + } + + } else if (jackmpLibrary) { + + if (check_client(jackmpLibrary)) { // jackd is running... + gLibrary = jackmpLibrary; + } else { + goto error; + } + + } else { + printf("Jack libraries not found, failure...\n"); + goto error; + } + + // Load entry points... + jack_port_get_buffer_fun = (jack_port_get_buffer_fun_def)dlsym(gLibrary, "jack_port_get_buffer"); + jack_port_name_fun = (jack_port_name_fun_def)dlsym(gLibrary, "jack_port_name"); + jack_port_short_name_fun = (jack_port_short_name_fun_def)dlsym(gLibrary, "jack_port_short_name"); + jack_port_flags_fun = (jack_port_flags_fun_def)dlsym(gLibrary, "jack_port_flags"); + jack_port_type_fun = (jack_port_type_fun_def)dlsym(gLibrary, "jack_port_type"); + jack_port_connected_fun = (jack_port_connected_fun_def)dlsym(gLibrary, "jack_port_connected"); + jack_port_connected_to_fun = (jack_port_connected_to_fun_def)dlsym(gLibrary, "jack_port_connected_to"); + jack_port_tie_fun = (jack_port_tie_fun_def)dlsym(gLibrary, "jack_port_tie"); + jack_port_untie_fun = (jack_port_untie_fun_def)dlsym(gLibrary, "jack_port_untie"); + jack_port_get_latency_fun = (jack_port_get_latency_fun_def)dlsym(gLibrary, "jack_port_get_latency"); + jack_port_set_latency_fun = (jack_port_set_latency_fun_def)dlsym(gLibrary, "jack_port_set_latency"); + jack_recompute_total_latency_fun = (jack_recompute_total_latency_fun_def)dlsym(gLibrary, "jack_recompute_total_latency"); + jack_recompute_total_latencies_fun = (jack_recompute_total_latencies_fun_def)dlsym(gLibrary, "jack_recompute_total_latencies"); + jack_port_set_name_fun = (jack_port_set_name_fun_def)dlsym(gLibrary, "jack_port_set_name"); + jack_port_request_monitor_fun = (jack_port_request_monitor_fun_def)dlsym(gLibrary, "jack_port_request_monitor"); + jack_port_request_monitor_by_name_fun = (jack_port_request_monitor_by_name_fun_def)dlsym(gLibrary, "jack_port_request_monitor_by_name"); + jack_port_ensure_monitor_fun = (jack_port_ensure_monitor_fun_def)dlsym(gLibrary, "jack_port_ensure_monitor"); + jack_port_monitoring_input_fun = (jack_port_monitoring_input_fun_def)dlsym(gLibrary, "jack_port_monitoring_input_fun"); + jack_is_realtime_fun = (jack_is_realtime_fun_def)dlsym(gLibrary, "jack_is_realtime"); + jack_on_shutdown_fun = (jack_on_shutdown_fun_def)dlsym(gLibrary, "jack_on_shutdown"); + jack_set_process_callback_fun = (jack_set_process_callback_fun_def)dlsym(gLibrary, "jack_set_process_callback"); + jack_set_freewheel_callback_fun = (jack_set_freewheel_callback_fun_def)dlsym(gLibrary, "jack_set_freewheel_callback"); + jack_set_freewheel_fun = (jack_set_freewheel_fun_def)dlsym(gLibrary, "jack_set_freewheel"); + jack_set_buffer_size_fun = (jack_set_buffer_size_fun_def)dlsym(gLibrary, "jack_set_buffer_size"); + jack_set_buffer_size_callback_fun = (jack_set_buffer_size_callback_fun_def)dlsym(gLibrary, "jack_set_buffer_size_callback"); + jack_set_sample_rate_callback_fun = (jack_set_sample_rate_callback_fun_def)dlsym(gLibrary, "jack_set_sample_rate_callback"); + jack_set_client_registration_callback_fun = (jack_set_client_registration_callback_fun_def)dlsym(gLibrary, "jack_set_client_registration_callback"); + jack_set_port_registration_callback_fun = (jack_set_port_registration_callback_fun_def)dlsym(gLibrary, "jack_set_port_registration_callback"); + jack_set_port_connect_callback_fun = (jack_set_port_connect_callback_fun_def)dlsym(gLibrary, "jack_set_port_connect_callback"); + jack_set_graph_order_callback_fun = (jack_set_graph_order_callback_fun_def)dlsym(gLibrary, "jack_set_graph_order_callback"); + jack_set_xrun_callback_fun = (jack_set_xrun_callback_fun_def)dlsym(gLibrary, "jack_set_xrun_callback"); + jack_set_thread_init_callback_fun = (jack_set_thread_init_callback_fun_def)dlsym(gLibrary, "jack_set_thread_init_callback"); + jack_activate_fun = (jack_activate_fun_def)dlsym(gLibrary, "jack_activate"); + jack_deactivate_fun = (jack_deactivate_fun_def)dlsym(gLibrary, "jack_deactivate"); + jack_port_register_fun = (jack_port_register_fun_def)dlsym(gLibrary, "jack_port_register"); + jack_port_unregister_fun = (jack_port_unregister_fun_def)dlsym(gLibrary, "jack_port_unregister"); + jack_port_is_mine_fun = (jack_port_is_mine_fun_def)dlsym(gLibrary, "jack_port_is_mine"); + jack_port_get_connections_fun = (jack_port_get_connections_fun_def)dlsym(gLibrary, "jack_port_get_connections"); + jack_port_get_all_connections_fun = (jack_port_get_all_connections_fun_def)dlsym(gLibrary, "jack_port_get_all_connections_fun"); + jack_port_get_total_latency_fun = (jack_port_get_total_latency_fun_def)dlsym(gLibrary, "jack_port_get_total_latency"); + jack_connect_fun = (jack_connect_fun_def)dlsym(gLibrary, "jack_connect"); + jack_disconnect_fun = (jack_disconnect_fun_def)dlsym(gLibrary, "jack_disconnect"); + jack_port_connect_fun = (jack_port_connect_fun_def)dlsym(gLibrary, "jack_port_connect"); + jack_port_disconnect_fun = (jack_port_disconnect_fun_def)dlsym(gLibrary, "jack_port_disconnect"); + jack_get_sample_rate_fun = (jack_get_sample_rate_fun_def)dlsym(gLibrary, "jack_get_sample_rate"); + jack_get_buffer_size_fun = (jack_get_buffer_size_fun_def)dlsym(gLibrary, "jack_get_buffer_size"); + jack_get_ports_fun = (jack_get_ports_fun_def)dlsym(gLibrary, "jack_get_ports"); + jack_port_by_name_fun = (jack_port_by_name_fun_def)dlsym(gLibrary, "jack_port_by_name"); + jack_port_by_id_fun = (jack_port_by_id_fun_def)dlsym(gLibrary, "jack_port_by_id"); + jack_engine_takeover_timebase_fun = (jack_engine_takeover_timebase_fun_def)dlsym(gLibrary, "jack_engine_takeover_timebase"); + jack_frames_since_cycle_start_fun = (jack_frames_since_cycle_start_fun_def)dlsym(gLibrary, "jack_frames_since_cycle_start"); + jack_get_time_fun = (jack_get_time_fun_def)dlsym(gLibrary, "jack_get_time"); + jack_time_to_frames_fun = (jack_time_to_frames_fun_def)dlsym(gLibrary, "jack_time_to_frames"); + jack_frame_time_fun = (jack_frame_time_fun_def)dlsym(gLibrary, "jack_frame_time"); + jack_last_frame_time_fun = (jack_last_frame_time_fun_def)dlsym(gLibrary, "jack_last_frame_time"); + jack_cpu_load_fun = (jack_cpu_load_fun_def)dlsym(gLibrary, "jack_cpu_load"); + jack_client_thread_id_fun = (jack_client_thread_id_fun_def)dlsym(gLibrary, "jack_client_thread_id"); + jack_get_client_name_fun = (jack_get_client_name_fun_def)dlsym(gLibrary, "jack_get_client_name"); + jack_port_name_size_fun = (jack_port_name_size_fun_def)dlsym(gLibrary, "jack_port_name_size"); + jack_client_name_size_fun = (jack_client_name_size_fun_def)dlsym(gLibrary, "jack_client_name_size"); + jack_release_timebase_fun = (jack_release_timebase_fun_def)dlsym(gLibrary, "jack_release_timebase"); + jack_set_sync_callback_fun = (jack_set_sync_callback_fun_def)dlsym(gLibrary, "jack_set_sync_callback"); + jack_set_sync_timeout_fun = (jack_set_sync_timeout_fun_def)dlsym(gLibrary, "jack_set_sync_timeout"); + jack_set_timebase_callback_fun = (jack_set_timebase_callback_fun_def)dlsym(gLibrary, "jack_set_timebase_callback"); + jack_transport_locate_fun = (jack_transport_locate_fun_def)dlsym(gLibrary, "jack_transport_locate_fun"); + jack_transport_query_fun = (jack_transport_query_fun_def)dlsym(gLibrary, "jack_transport_query"); + jack_get_current_transport_frame_fun = (jack_get_current_transport_frame_fun_def)dlsym(gLibrary, "jack_get_current_transport_frame"); + jack_transport_reposition_fun = (jack_transport_reposition_fun_def)dlsym(gLibrary, "jack_transport_reposition"); + jack_transport_start_fun = (jack_transport_start_fun_def)dlsym(gLibrary, "jack_transport_start"); + jack_transport_stop_fun = (jack_transport_stop_fun_def)dlsym(gLibrary, "jack_transport_stop"); + jack_get_transport_info_fun = (jack_get_transport_info_fun_def)dlsym(gLibrary, "jack_get_transport_info"); + jack_set_transport_info_fun = (jack_set_transport_info_fun_def)dlsym(gLibrary, "jack_set_transport_info"); + jack_get_max_delayed_usecs_fun = (jack_get_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_max_delayed_usecs"); + jack_get_xrun_delayed_usecs_fun = (jack_get_xrun_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_xrun_delayed_usecs"); + jack_reset_max_delayed_usecs_fun = (jack_reset_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_reset_max_delayed_usecs"); + jack_acquire_real_time_scheduling_fun = (jack_acquire_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_acquire_real_time_scheduling"); + jack_client_create_thread_fun = (jack_client_create_thread_fun_def)dlsym(gLibrary, "jack_client_create_thread"); + jack_drop_real_time_scheduling_fun = (jack_drop_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_drop_real_time_scheduling"); + jack_get_internal_client_name_fun = (jack_get_internal_client_name_fun_def)dlsym(gLibrary, "jack_get_internal_client_name"); + jack_internal_client_handle_fun = (jack_internal_client_handle_fun_def)dlsym(gLibrary, "jack_internal_client_handle"); + jack_internal_client_load_fun = (jack_internal_client_load_fun_def)dlsym(gLibrary, "jack_internal_client_load"); + jack_internal_client_unload_fun = (jack_internal_client_unload_fun_def)dlsym(gLibrary, "jack_internal_client_unload"); + jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open"); + jack_client_new_fun = (jack_client_new_fun_def)dlsym(gLibrary, "jack_client_new"); + jack_client_close_fun = (jack_client_close_fun_def)dlsym(gLibrary, "jack_client_close"); + + return true; error: - if (jackLibrary) - dlclose(jackLibrary); - if (jackmpLibrary) - dlclose(jackmpLibrary); - return false; + if (jackLibrary) + dlclose(jackLibrary); + if (jackmpLibrary) + dlclose(jackmpLibrary); + return false; } diff --git a/common/JackActivationCount.cpp b/common/JackActivationCount.cpp index bec2ad51..3a7333e9 100644 --- a/common/JackActivationCount.cpp +++ b/common/JackActivationCount.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -29,11 +29,11 @@ namespace Jack bool JackActivationCount::Signal(JackSynchro* synchro, JackClientControl* control) { if (fValue == 0) { - // Transfer activation to next clients + // Transfer activation to next clients jack_error("JackActivationCount::Signal value = 0 ref = %ld", control->fRefNum); return synchro->Signal(); } else if (DEC_ATOMIC(&fValue) == 1) { - return synchro->Signal(); + return synchro->Signal(); } else { return true; } diff --git a/common/JackActivationCount.h b/common/JackActivationCount.h index 1f051a0d..cb984537 100644 --- a/common/JackActivationCount.h +++ b/common/JackActivationCount.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -38,12 +38,12 @@ class JackActivationCount private: - SInt32 fValue; + SInt32 fValue; SInt32 fCount; public: - JackActivationCount(): fValue(0), fCount(0) + JackActivationCount(): fValue(0), fCount(0) {} virtual ~JackActivationCount() {} diff --git a/common/JackAtomic.h b/common/JackAtomic.h index 141ce2ab..74f15449 100644 --- a/common/JackAtomic.h +++ b/common/JackAtomic.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackAtomicArrayState.h b/common/JackAtomicArrayState.h index 3a9065c0..8fee2dba 100644 --- a/common/JackAtomicArrayState.h +++ b/common/JackAtomicArrayState.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 @@ -28,7 +28,7 @@ namespace Jack { /*! -\brief Counter for CAS +\brief Counter for CAS */ struct AtomicArrayCounter @@ -56,33 +56,33 @@ struct AtomicArrayCounter /*! \brief A class to handle several states in a lock-free manner - + Requirement: - + - a "current" state - several possible "pending" state - - an TrySwitchState(int state) operation to atomically switch a "pending" to the "current" state (the pending becomes the current). - + - an TrySwitchState(int state) operation to atomically switch a "pending" to the "current" state (the pending becomes the current). + The TrySwitchState operation returns a "current" state (either the same if switch fails or the new one, one can know if the switch has succeeded) - + - a WriteNextStartState(int state) returns a "pending" state to be written into - a WriteNextStartStop(int state) make the written "pending" state become "switchable" - + Different pending states can be written independantly and concurrently. - + GetCurrentIndex() *must* return an increasing value to be able to check reading current state coherency - + The fCounter is an array of indexes to access the current and 3 different "pending" states. - + ¥ WriteNextStateStart(int index) must return a valid state to be written into, and must invalidate state "index" ==> cur state switch. ¥ WriteNextStateStop(int index) makes the "index" state become "switchable" with the current state. ¥ TrySwitchState(int index) must detect that pending state is a new state, and does the switch - ¥ ReadCurrentState() must return the state + ¥ ReadCurrentState() must return the state ¥ GetCurrentIndex() must return an index increased each new switch. ¥ WriteNextStateStart(int index1) and WriteNextStateStart(int index2) can be interleaved - + [switch counter][index state][index state][cur index] - + */ // CHECK livelock @@ -162,8 +162,8 @@ class JackAtomicArrayState } /*! - \brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) - */ + \brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) + */ T* TrySwitchState(int state) { @@ -202,8 +202,8 @@ class JackAtomicArrayState } /*! - \brief Start write operation : setup and returns the next state to update, check for recursive write calls. - */ + \brief Start write operation : setup and returns the next state to update, check for recursive write calls. + */ T* WriteNextStateStart(int state) { diff --git a/common/JackAtomicState.h b/common/JackAtomicState.h index dce0866c..96dc9128 100644 --- a/common/JackAtomicState.h +++ b/common/JackAtomicState.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -27,7 +27,7 @@ namespace Jack { /*! -\brief Counter for CAS +\brief Counter for CAS */ struct AtomicCounter @@ -132,8 +132,8 @@ class JackAtomicState } /*! - \brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) - */ + \brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one) + */ T* TrySwitchState() { AtomicCounter old_val; @@ -218,15 +218,15 @@ class JackAtomicState { T* state; UInt16 cur_index; - UInt16 next_index = GetCurrentIndex(); + UInt16 next_index = GetCurrentIndex(); do { - cur_index = next_index; + cur_index = next_index; state = ReadCurrentState(); ...... ...... - - next_index = GetCurrentIndex(); + + next_index = GetCurrentIndex(); } while (cur_index != next_index); } */ diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index 94913405..31a2d9b2 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -48,19 +48,19 @@ JackAudioDriver::~JackAudioDriver() int JackAudioDriver::SetBufferSize(jack_nframes_t buffer_size) { fEngineControl->fBufferSize = buffer_size; - fGraphManager->SetBufferSize(buffer_size); - fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec - if (!fEngineControl->fTimeOut) - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); + fGraphManager->SetBufferSize(buffer_size); + fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec + if (!fEngineControl->fTimeOut) + fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); return 0; } int JackAudioDriver::SetSampleRate(jack_nframes_t sample_rate) { fEngineControl->fSampleRate = sample_rate; - fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec - if (!fEngineControl->fTimeOut) - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); + fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec + if (!fEngineControl->fTimeOut) + fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); return 0; } @@ -87,7 +87,7 @@ int JackAudioDriver::Attach() JackPort* port; jack_port_id_t port_index; char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; - char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal; int i; @@ -95,13 +95,13 @@ int JackAudioDriver::Attach() for (i = 0; i < fCaptureChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fClientControl->fName, fCaptureDriverName, i + 1); - snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); + snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", name); return -1; } - port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + port = fGraphManager->GetPort(port_index); + port->SetAlias(alias); port->SetLatency(fEngineControl->fBufferSize + fCaptureLatency); fCapturePortList[i] = port_index; JackLog("JackAudioDriver::Attach fCapturePortList[i] port_index = %ld\n", port_index); @@ -111,17 +111,17 @@ int JackAudioDriver::Attach() for (i = 0; i < fPlaybackChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fClientControl->fName, fPlaybackDriverName, i + 1); - snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); + snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", name); return -1; } - port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + port = fGraphManager->GetPort(port_index); + port->SetAlias(alias); port->SetLatency(fEngineControl->fBufferSize + fPlaybackLatency); fPlaybackPortList[i] = port_index; JackLog("JackAudioDriver::Attach fPlaybackPortList[i] port_index = %ld\n", port_index); - + // Monitor ports if (fWithMonitorPorts) { JackLog("Create monitor port \n"); @@ -162,7 +162,7 @@ int JackAudioDriver::Write() { for (int i = 0; i < fPlaybackChannels; i++) { if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) { - float* buffer = GetOutputBuffer(i); + float* buffer = GetOutputBuffer(i); int size = sizeof(float) * fEngineControl->fBufferSize; // Monitor ports if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0) @@ -196,11 +196,11 @@ int JackAudioDriver::ProcessAsync() if (fIsMaster) { if (!fEngine->Process(fLastWaitUst)) // fLastWaitUst is set in the "low level" layer - jack_error("JackAudioDriver::ProcessAsync Process error"); + jack_error("JackAudioDriver::ProcessAsync Process error"); fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); - if (ProcessSlaves() < 0) - jack_error("JackAudioDriver::ProcessAsync ProcessSlaves error"); - } else { + if (ProcessSlaves() < 0) + jack_error("JackAudioDriver::ProcessAsync ProcessSlaves error"); + } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); } return 0; @@ -221,17 +221,17 @@ int JackAudioDriver::ProcessSync() if (fIsMaster) { if (fEngine->Process(fLastWaitUst)) { // fLastWaitUst is set in the "low level" layer - fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); - if (ProcessSlaves() < 0) - jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!"); - if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) - jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!"); - } else { // Graph not finished: do not activate it - jack_error("ProcessSync: error"); - } - - if (Write() < 0) // Write output buffers for the current cycle - jack_error("ProcessSync: write error"); + fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); + if (ProcessSlaves() < 0) + jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!"); + if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) + jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!"); + } else { // Graph not finished: do not activate it + jack_error("ProcessSync: error"); + } + + if (Write() < 0) // Write output buffers for the current cycle + jack_error("ProcessSync: write error"); } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); diff --git a/common/JackAudioDriver.h b/common/JackAudioDriver.h index b21c0f06..d7783fb4 100644 --- a/common/JackAudioDriver.h +++ b/common/JackAudioDriver.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -78,8 +78,8 @@ class EXPORT JackAudioDriver : public JackDriver virtual int Detach(); virtual int Write(); - virtual int SetBufferSize(jack_nframes_t buffer_size); - virtual int SetSampleRate(jack_nframes_t sample_rate); + virtual int SetBufferSize(jack_nframes_t buffer_size); + virtual int SetSampleRate(jack_nframes_t sample_rate); virtual void NotifyXRun(jack_time_t callback_usecs); // XRun notification sent by the driver diff --git a/common/JackAudioPort.cpp b/common/JackAudioPort.cpp index 452688ed..2f050d67 100644 --- a/common/JackAudioPort.cpp +++ b/common/JackAudioPort.cpp @@ -22,9 +22,9 @@ This program is free software; you can redistribute it and/or modify #include <string.h> #if defined (__APPLE__) - #include <Accelerate/Accelerate.h> +#include <Accelerate/Accelerate.h> #elif defined (__SSE__) - #include <xmmintrin.h> +#include <xmmintrin.h> #endif namespace Jack @@ -38,9 +38,9 @@ static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t) static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames) { #ifdef __APPLE__ - // It seems that a vector mult only operation does not exist... - float gain = 1.0f; - vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames); + // It seems that a vector mult only operation does not exist... + float gain = 1.0f; + vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames); #else jack_nframes_t frames_group = frames / 4; frames = frames % 4; @@ -54,29 +54,29 @@ static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_ buffer += 4; frames_group--; #else - register float mixFloat1 = *mixbuffer; - register float sourceFloat1 = *buffer; - register float mixFloat2 = *(mixbuffer + 1); - register float sourceFloat2 = *(buffer + 1); - register float mixFloat3 = *(mixbuffer + 2); - register float sourceFloat3 = *(buffer + 2); - register float mixFloat4 = *(mixbuffer + 3); - register float sourceFloat4 = *(buffer + 3); - - buffer += 4; - frames_group--; - - mixFloat1 += sourceFloat1; - mixFloat2 += sourceFloat2; - mixFloat3 += sourceFloat3; - mixFloat4 += sourceFloat4; - - *mixbuffer = mixFloat1; - *(mixbuffer + 1) = mixFloat2; - *(mixbuffer + 2) = mixFloat3; - *(mixbuffer + 3) = mixFloat4; - - mixbuffer += 4; + register float mixFloat1 = *mixbuffer; + register float sourceFloat1 = *buffer; + register float mixFloat2 = *(mixbuffer + 1); + register float sourceFloat2 = *(buffer + 1); + register float mixFloat3 = *(mixbuffer + 2); + register float sourceFloat3 = *(buffer + 2); + register float mixFloat4 = *(mixbuffer + 3); + register float sourceFloat4 = *(buffer + 3); + + buffer += 4; + frames_group--; + + mixFloat1 += sourceFloat1; + mixFloat2 += sourceFloat2; + mixFloat3 += sourceFloat3; + mixFloat4 += sourceFloat4; + + *mixbuffer = mixFloat1; + *(mixbuffer + 1) = mixFloat2; + *(mixbuffer + 2) = mixFloat3; + *(mixbuffer + 3) = mixFloat4; + + mixbuffer += 4; #endif } @@ -99,18 +99,19 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun // Copy first buffer memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float)); - // Mix remaining buffers + // Mix remaining buffers for (int i = 1; i < src_count; ++i) { buffer = src_buffers[i]; MixAudioBuffer(static_cast<float*>(mixbuffer), static_cast<float*>(buffer), nframes); } } -const JackPortType gAudioPortType = { - JACK_DEFAULT_AUDIO_TYPE, - AudioBufferInit, - AudioBufferMixdown -}; +const JackPortType gAudioPortType = + { + JACK_DEFAULT_AUDIO_TYPE, + AudioBufferInit, + AudioBufferMixdown + }; } // namespace Jack diff --git a/common/JackChannel.h b/common/JackChannel.h index 4be13977..6c5f9950 100644 --- a/common/JackChannel.h +++ b/common/JackChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -65,13 +65,13 @@ class JackClientChannelInterface // Stop listening for messages from the server virtual void Stop() {} - - virtual int ServerCheck(const char* server_name) + + virtual int ServerCheck(const char* server_name) { - return -1; - } - - virtual void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) + return -1; + } + + virtual void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) {} virtual void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result) {} @@ -109,17 +109,17 @@ class JackClientChannelInterface virtual void SetTimebaseCallback(int refnum, int conditional, int* result) {} - - virtual void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result) + + virtual void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result) {} - virtual void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result) + virtual void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result) {} - virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result) + virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result) {} - - virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result) + + virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result) {} }; diff --git a/common/JackChannelTransaction.h b/common/JackChannelTransaction.h index d83d4780..0b849692 100644 --- a/common/JackChannelTransaction.h +++ b/common/JackChannelTransaction.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/JackClient.cpp b/common/JackClient.cpp index 44ecb2f4..92ecad91 100644 --- a/common/JackClient.cpp +++ b/common/JackClient.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -49,10 +49,10 @@ JackClient::JackClient(JackSynchro** table) fShutdown = NULL; fInit = NULL; fBufferSize = NULL; - fClientRegistration = NULL; + fClientRegistration = NULL; fFreewheel = NULL; fPortRegistration = NULL; - fPortConnect = NULL; + fPortConnect = NULL; fSync = NULL; fProcessArg = NULL; fGraphOrderArg = NULL; @@ -63,10 +63,10 @@ JackClient::JackClient(JackSynchro** table) fFreewheelArg = NULL; fClientRegistrationArg = NULL; fPortRegistrationArg = NULL; - fPortConnectArg = NULL; + fPortConnectArg = NULL; fSyncArg = NULL; - fThreadFun = NULL; - fThreadFunArg = NULL; + fThreadFun = NULL; + fThreadFunArg = NULL; fConditionnal = 0; // Temporary?? } @@ -106,12 +106,12 @@ void JackClient::SetupDriverSync(bool freewheel) { if (!freewheel && !GetEngineControl()->fSyncMode) { JackLog("JackClient::SetupDriverSync driver sem in flush mode\n"); - fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(true); + fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(true); fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(true); fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(true); } else { JackLog("JackClient::SetupDriverSync driver sem in normal mode\n"); - fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(false); + fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(false); fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(false); fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(false); } @@ -123,7 +123,7 @@ void JackClient::SetupDriverSync(bool freewheel) int JackClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value2) { - return 0; + return 0; } int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2) @@ -135,17 +135,17 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, case kAddClient: res = ClientNotifyImp(refnum, name, notify, sync, value1, value2); - break; - - case kRemoveClient: + break; + + case kRemoveClient: res = ClientNotifyImp(refnum, name, notify, sync, value1, value2); - break; - - case kActivateClient: - JackLog("JackClient::kActivateClient name = %s ref = %ld \n", name, refnum); - Init(); - break; - } + break; + + case kActivateClient: + JackLog("JackClient::kActivateClient name = %s ref = %ld \n", name, refnum); + Init(); + break; + } /* The current semantic is that notifications can only be received when the client has been activated, @@ -154,18 +154,18 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, if (IsActive()) { switch (notify) { - - case kAddClient: - JackLog("JackClient::kAddClient fName = %s name = %s\n", GetClientControl()->fName, name); - if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself - fClientRegistration(name, 1, fClientRegistrationArg); - break; - - case kRemoveClient: - JackLog("JackClient::kRemoveClient fName = %s name = %s\n", GetClientControl()->fName, name); - if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself - fClientRegistration(name, 0, fClientRegistrationArg); - break; + + case kAddClient: + JackLog("JackClient::kAddClient fName = %s name = %s\n", GetClientControl()->fName, name); + if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself + fClientRegistration(name, 1, fClientRegistrationArg); + break; + + case kRemoveClient: + JackLog("JackClient::kRemoveClient fName = %s name = %s\n", GetClientControl()->fName, name); + if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself + fClientRegistration(name, 0, fClientRegistrationArg); + break; case kBufferSizeCallback: JackLog("JackClient::kBufferSizeCallback buffer_size = %ld\n", value1); @@ -206,14 +206,14 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, if (fPortRegistration) fPortRegistration(value1, 0, fPortRegistrationArg); break; - - case kPortConnectCallback: + + case kPortConnectCallback: JackLog("JackClient::kPortConnectCallback src = %ld dst = %ld\n", value1, value2); if (fPortConnect) fPortConnect(value1, value2, 1, fPortConnectArg); break; - - case kPortDisconnectCallback: + + case kPortDisconnectCallback: JackLog("JackClient::kPortDisconnectCallback src = %ld dst = %ld\n", value1, value2); if (fPortConnect) fPortConnect(value1, value2, 0, fPortConnectArg); @@ -224,14 +224,14 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, if (fXrun) res = fXrun(fXrunArg); break; - } + } } return res; } /*! -\brief We need to start thread before activating in the server, otherwise the FW driver +\brief We need to start thread before activating in the server, otherwise the FW driver connected to the client may not be activated. */ int JackClient::Activate() @@ -240,18 +240,18 @@ int JackClient::Activate() if (IsActive()) return 0; -/* TODO : solve WIN32 thread Kill issue -#ifdef WIN32 - // Done first so that the RT thread then access an allocated synchro - if (!fSynchroTable[GetClientControl()->fRefNum]->Connect(GetClientControl()->fName)) { - jack_error("Cannot ConnectSemaphore %s client", GetClientControl()->fName); - return -1; - } -#endif -*/ + /* TODO : solve WIN32 thread Kill issue + #ifdef WIN32 + // Done first so that the RT thread then access an allocated synchro + if (!fSynchroTable[GetClientControl()->fRefNum]->Connect(GetClientControl()->fName)) { + jack_error("Cannot ConnectSemaphore %s client", GetClientControl()->fName); + return -1; + } + #endif + */ - if (StartThread() < 0) - return -1; + if (StartThread() < 0) + return -1; int result = -1; fChannel->ClientActivate(GetClientControl()->fRefNum, &result); @@ -284,15 +284,15 @@ int JackClient::Deactivate() JackLog("JackClient::Deactivate res = %ld \n", result); // We need to wait for the new engine cycle before stopping the RT thread, but this is done by ClientDeactivate -/* TODO : solve WIN32 thread Kill issue -#ifdef WIN32 - fSynchroTable[GetClientControl()->fRefNum]->Disconnect(); - fThread->Stop(); -#else - fThread->Kill(); -#endif -*/ - fThread->Kill(); + /* TODO : solve WIN32 thread Kill issue + #ifdef WIN32 + fSynchroTable[GetClientControl()->fRefNum]->Disconnect(); + fThread->Stop(); + #else + fThread->Kill(); + #endif + */ + fThread->Kill(); return result; } @@ -307,7 +307,7 @@ bool JackClient::Init() { if (fInit) { JackLog("JackClient::Init calling client thread init callback\n"); - fInit(fInitArg); + fInit(fInitArg); } return true; } @@ -341,53 +341,53 @@ int JackClient::StartThread() */ bool JackClient::Execute() { - if (fThreadFun) { - fThreadFun(fThreadFunArg); - } else { - if (WaitFirstSync()) - ExecuteThread(); - } - return false; // Never reached + if (fThreadFun) { + fThreadFun(fThreadFunArg); + } else { + if (WaitFirstSync()) + ExecuteThread(); + } + return false; // Never reached } inline bool JackClient::WaitFirstSync() { - while (true) { - // Start first cycle - WaitSync(); - if (IsActive()) { - CallSyncCallback(); - // Finish first cycle - if (Wait(CallProcessCallback()) != GetEngineControl()->fBufferSize) - return false; - return true; - } else { - JackLog("Process called for an inactive client\n"); - } - SignalSync(); - } - return false; // Never reached + while (true) { + // Start first cycle + WaitSync(); + if (IsActive()) { + CallSyncCallback(); + // Finish first cycle + if (Wait(CallProcessCallback()) != GetEngineControl()->fBufferSize) + return false; + return true; + } else { + JackLog("Process called for an inactive client\n"); + } + SignalSync(); + } + return false; // Never reached } inline void JackClient::ExecuteThread() { - while (true) { - if (Wait(CallProcessCallback()) != GetEngineControl()->fBufferSize) - return; - } + while (true) { + if (Wait(CallProcessCallback()) != GetEngineControl()->fBufferSize) + return; + } } jack_nframes_t JackClient::Wait(int status) { - if (status == 0) - CallTimebaseCallback(); - SignalSync(); - if (status != 0) - return End(); - if (!WaitSync()) - return Error(); - CallSyncCallback(); - return GetEngineControl()->fBufferSize; + if (status == 0) + CallTimebaseCallback(); + SignalSync(); + if (status != 0) + return End(); + if (!WaitSync()) + return Error(); + CallSyncCallback(); + return GetEngineControl()->fBufferSize; } /* @@ -400,19 +400,19 @@ jack_nframes_t JackClient::Wait(int status) jack_nframes_t JackClient::CycleWait() { - if (!WaitSync()) - return Error(); - CallSyncCallback(); - return GetEngineControl()->fBufferSize; + if (!WaitSync()) + return Error(); + CallSyncCallback(); + return GetEngineControl()->fBufferSize; } int JackClient::SetProcessThread(JackThreadCallback fun, void *arg) { - if (IsActive()) { + if (IsActive()) { jack_error("You cannot set callbacks on an active client"); return -1; } else { - fThreadFun = fun; + fThreadFun = fun; fThreadFunArg = arg; return 0; } @@ -420,32 +420,32 @@ int JackClient::SetProcessThread(JackThreadCallback fun, void *arg) void JackClient::CycleSignal(int status) { - if (status == 0) - CallTimebaseCallback(); - SignalSync(); - if (status != 0) - End(); + if (status == 0) + CallTimebaseCallback(); + SignalSync(); + if (status != 0) + End(); } inline int JackClient::CallProcessCallback() { - return (fProcess != NULL) ? fProcess(GetEngineControl()->fBufferSize, fProcessArg) : 0; + return (fProcess != NULL) ? fProcess(GetEngineControl()->fBufferSize, fProcessArg) : 0; } inline bool JackClient::WaitSync() { - // Suspend itself: wait on the input synchro + // Suspend itself: wait on the input synchro if (GetGraphManager()->SuspendRefNum(GetClientControl(), fSynchroTable, 0x7FFFFFFF) < 0) { - jack_error("SuspendRefNum error"); - return false; - } else { - return true; - } + jack_error("SuspendRefNum error"); + return false; + } else { + return true; + } } inline void JackClient::SignalSync() { - // Resume: signal output clients connected to the running client + // Resume: signal output clients connected to the running client if (GetGraphManager()->ResumeRefNum(GetClientControl(), fSynchroTable) < 0) { jack_error("ResumeRefNum error"); } @@ -453,27 +453,27 @@ inline void JackClient::SignalSync() inline int JackClient::End() { - JackLog("JackClient::Execute end name = %s\n", GetClientControl()->fName); - // Hum... not sure about this, the following "close" code is called in the RT thread... - int result; - fThread->DropRealTime(); - GetClientControl()->fActive = false; - fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); + JackLog("JackClient::Execute end name = %s\n", GetClientControl()->fName); + // Hum... not sure about this, the following "close" code is called in the RT thread... + int result; + fThread->DropRealTime(); + GetClientControl()->fActive = false; + fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); fThread->Terminate(); - return 0; // Never reached + return 0; // Never reached } inline int JackClient::Error() { - jack_error("JackClient::Execute error name = %s", GetClientControl()->fName); - // Hum... not sure about this, the following "close" code is called in the RT thread... - int result; + jack_error("JackClient::Execute error name = %s", GetClientControl()->fName); + // Hum... not sure about this, the following "close" code is called in the RT thread... + int result; fThread->DropRealTime(); - GetClientControl()->fActive = false; - fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); + GetClientControl()->fActive = false; + fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); ShutDown(); - fThread->Terminate(); - return 0; // Never reached + fThread->Terminate(); + return 0; // Never reached } //----------------- @@ -523,7 +523,7 @@ int JackClient::PortRegister(const char* port_name, const char* port_type, unsig int JackClient::PortUnRegister(jack_port_id_t port_index) { JackLog("JackClient::PortUnRegister port_index = %ld\n", port_index); - list<jack_port_id_t>::iterator it = find(fPortList.begin(), fPortList.end(), port_index); + list<jack_port_id_t>::iterator it = find(fPortList.begin(), fPortList.end(), port_index); if (it != fPortList.end()) { fPortList.erase(it); @@ -824,7 +824,7 @@ int JackClient::SetXRunCallback(JackXRunCallback callback, void *arg) jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kXRunCallback] = (callback != NULL); + GetClientControl()->fCallback[kXRunCallback] = (callback != NULL); fXrunArg = arg; fXrun = callback; return 0; @@ -851,7 +851,7 @@ int JackClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kGraphOrderCallback] = (callback != NULL); + GetClientControl()->fCallback[kGraphOrderCallback] = (callback != NULL); fGraphOrder = callback; fGraphOrderArg = arg; return 0; @@ -864,7 +864,7 @@ int JackClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kBufferSizeCallback] = (callback != NULL); + GetClientControl()->fCallback[kBufferSizeCallback] = (callback != NULL); fBufferSizeArg = arg; fBufferSize = callback; return 0; @@ -877,8 +877,8 @@ int JackClient::SetClientRegistrationCallback(JackClientRegistrationCallback cal jack_error("You cannot set callbacks on an active client"); return -1; } else { - // kAddClient and kRemoveClient notifications must be delivered by the server in any case - fClientRegistrationArg = arg; + // kAddClient and kRemoveClient notifications must be delivered by the server in any case + fClientRegistrationArg = arg; fClientRegistration = callback; return 0; } @@ -890,8 +890,8 @@ int JackClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg) jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kStartFreewheelCallback] = (callback != NULL); - GetClientControl()->fCallback[kStopFreewheelCallback] = (callback != NULL); + GetClientControl()->fCallback[kStartFreewheelCallback] = (callback != NULL); + GetClientControl()->fCallback[kStopFreewheelCallback] = (callback != NULL); fFreewheelArg = arg; fFreewheel = callback; return 0; @@ -904,8 +904,8 @@ int JackClient::SetPortRegistrationCallback(JackPortRegistrationCallback callbac jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kPortRegistrationOnCallback] = (callback != NULL); - GetClientControl()->fCallback[kPortRegistrationOffCallback] = (callback != NULL); + GetClientControl()->fCallback[kPortRegistrationOnCallback] = (callback != NULL); + GetClientControl()->fCallback[kPortRegistrationOffCallback] = (callback != NULL); fPortRegistrationArg = arg; fPortRegistration = callback; return 0; @@ -918,8 +918,8 @@ int JackClient::SetPortConnectCallback(JackPortConnectCallback callback, void *a jack_error("You cannot set callbacks on an active client"); return -1; } else { - GetClientControl()->fCallback[kPortConnectCallback] = (callback != NULL); - GetClientControl()->fCallback[kPortDisconnectCallback] = (callback != NULL); + GetClientControl()->fCallback[kPortConnectCallback] = (callback != NULL); + GetClientControl()->fCallback[kPortDisconnectCallback] = (callback != NULL); fPortConnectArg = arg; fPortConnect = callback; return 0; @@ -932,62 +932,62 @@ int JackClient::SetPortConnectCallback(JackPortConnectCallback callback, void *a char* JackClient::GetInternalClientName(int ref) { - char name_res[JACK_CLIENT_NAME_SIZE]; - int result = -1; - fChannel->GetInternalClientName(GetClientControl()->fRefNum, ref, name_res, &result); - - if (result < 0) { - return NULL; - } else { - char* name = (char*)malloc(strlen(name_res)); - strcpy(name, name_res); - return name; - } + char name_res[JACK_CLIENT_NAME_SIZE]; + int result = -1; + fChannel->GetInternalClientName(GetClientControl()->fRefNum, ref, name_res, &result); + + if (result < 0) { + return NULL; + } else { + char* name = (char*)malloc(strlen(name_res)); + strcpy(name, name_res); + return name; + } } int JackClient::InternalClientHandle(const char* client_name, jack_status_t* status) { - int int_ref, result = -1; - fChannel->InternalClientHandle(GetClientControl()->fRefNum, client_name, (int*)status, &int_ref, &result); - return int_ref; + int int_ref, result = -1; + fChannel->InternalClientHandle(GetClientControl()->fRefNum, client_name, (int*)status, &int_ref, &result); + return int_ref; } int JackClient::InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va) { - if (strlen(client_name) >= JACK_CLIENT_NAME_SIZE) { - jack_error ("\"%s\" is too long for a JACK client name.\n" - "Please use %lu characters or less.", - client_name, JACK_CLIENT_NAME_SIZE); - return 0; - } - - if (va->load_name && (strlen(va->load_name) >= PATH_MAX)) { - jack_error("\"%s\" is too long for a shared object name.\n" - "Please use %lu characters or less.", - va->load_name, PATH_MAX); - int my_status1 = *status | (JackFailure | JackInvalidOption); - *status = (jack_status_t)my_status1; - return 0; - } - - if (va->load_init && (strlen(va->load_init) >= JACK_LOAD_INIT_LIMIT)) { - jack_error ("\"%s\" is too long for internal client init " - "string.\nPlease use %lu characters or less.", - va->load_init, JACK_LOAD_INIT_LIMIT); - int my_status1 = *status | (JackFailure | JackInvalidOption); - *status = (jack_status_t)my_status1; - return 0; - } - - int int_ref, result = -1; - fChannel->InternalClientLoad(GetClientControl()->fRefNum, client_name, va->load_name, va->load_init, options, (int*)status, &int_ref, &result); - return int_ref; + if (strlen(client_name) >= JACK_CLIENT_NAME_SIZE) { + jack_error ("\"%s\" is too long for a JACK client name.\n" + "Please use %lu characters or less.", + client_name, JACK_CLIENT_NAME_SIZE); + return 0; + } + + if (va->load_name && (strlen(va->load_name) >= PATH_MAX)) { + jack_error("\"%s\" is too long for a shared object name.\n" + "Please use %lu characters or less.", + va->load_name, PATH_MAX); + int my_status1 = *status | (JackFailure | JackInvalidOption); + *status = (jack_status_t)my_status1; + return 0; + } + + if (va->load_init && (strlen(va->load_init) >= JACK_LOAD_INIT_LIMIT)) { + jack_error ("\"%s\" is too long for internal client init " + "string.\nPlease use %lu characters or less.", + va->load_init, JACK_LOAD_INIT_LIMIT); + int my_status1 = *status | (JackFailure | JackInvalidOption); + *status = (jack_status_t)my_status1; + return 0; + } + + int int_ref, result = -1; + fChannel->InternalClientLoad(GetClientControl()->fRefNum, client_name, va->load_name, va->load_init, options, (int*)status, &int_ref, &result); + return int_ref; } void JackClient::InternalClientUnload(int ref, jack_status_t* status) { - int result = -1; - fChannel->InternalClientUnload(GetClientControl()->fRefNum, ref, (int*)status, &result); + int result = -1; + fChannel->InternalClientUnload(GetClientControl()->fRefNum, ref, (int*)status, &result); } diff --git a/common/JackClient.h b/common/JackClient.h index 594d8b7e..0f8aea89 100644 --- a/common/JackClient.h +++ b/common/JackClient.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -50,8 +50,8 @@ typedef void (*JackShutdownCallback)(void *arg); class JackClient : public JackClientInterface, public JackRunnableInterface { - friend class JackDebugClient; - + friend class JackDebugClient; + protected: JackProcessCallback fProcess; @@ -60,29 +60,29 @@ class JackClient : public JackClientInterface, public JackRunnableInterface JackShutdownCallback fShutdown; JackThreadInitCallback fInit; JackBufferSizeCallback fBufferSize; - JackClientRegistrationCallback fClientRegistration; + JackClientRegistrationCallback fClientRegistration; JackFreewheelCallback fFreewheel; JackPortRegistrationCallback fPortRegistration; - JackPortConnectCallback fPortConnect; + JackPortConnectCallback fPortConnect; JackTimebaseCallback fTimebase; JackSyncCallback fSync; - JackThreadCallback fThreadFun; - + JackThreadCallback fThreadFun; + void* fProcessArg; void* fGraphOrderArg; void* fXrunArg; void* fShutdownArg; void* fInitArg; void* fBufferSizeArg; - void* fClientRegistrationArg; + void* fClientRegistrationArg; void* fFreewheelArg; void* fPortRegistrationArg; - void* fPortConnectArg; + void* fPortConnectArg; void* fTimebaseArg; void* fSyncArg; - void* fThreadFunArg; + void* fThreadFunArg; int fConditionnal; - char fServerName[64]; + char fServerName[64]; JackThread* fThread; /*! Thread to execute the Process function */ JackClientChannelInterface* fChannel; @@ -98,15 +98,15 @@ class JackClient : public JackClientInterface, public JackRunnableInterface int RequestNewPos(jack_position_t* pos); virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value); - - // Fons Adriaensen thread model - inline bool WaitFirstSync(); - inline void ExecuteThread(); - inline bool WaitSync(); - inline void SignalSync(); - inline int CallProcessCallback(); - inline int End(); - inline int Error(); + + // Fons Adriaensen thread model + inline bool WaitFirstSync(); + inline void ExecuteThread(); + inline bool WaitSync(); + inline void SignalSync(); + inline int CallProcessCallback(); + inline int End(); + inline int Error(); public: @@ -162,23 +162,23 @@ class JackClient : public JackClientInterface, public JackRunnableInterface virtual int SetInitCallback(JackThreadInitCallback callback, void* arg); virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg); virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg); - virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg); + virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg); virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg); virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg); - virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg); - - // Internal clients - virtual char* GetInternalClientName(int ref); - virtual int InternalClientHandle(const char* client_name, jack_status_t* status); - virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va); - virtual void InternalClientUnload(int ref, jack_status_t* status); - - // Fons Adriaensen thread model - virtual jack_nframes_t Wait(int status); - - virtual jack_nframes_t CycleWait(); - void CycleSignal(int status); - int SetProcessThread(JackThreadCallback fun, void *arg); + virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg); + + // Internal clients + virtual char* GetInternalClientName(int ref); + virtual int InternalClientHandle(const char* client_name, jack_status_t* status); + virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va); + virtual void InternalClientUnload(int ref, jack_status_t* status); + + // Fons Adriaensen thread model + virtual jack_nframes_t Wait(int status); + + virtual jack_nframes_t CycleWait(); + void CycleSignal(int status); + int SetProcessThread(JackThreadCallback fun, void *arg); // JackRunnableInterface interface bool Init(); diff --git a/common/JackClientControl.h b/common/JackClientControl.h index e55cc8c6..6e8506c5 100644 --- a/common/JackClientControl.h +++ b/common/JackClientControl.h @@ -31,16 +31,16 @@ namespace Jack { /*! -\brief Client control in shared memory. +\brief Client control in shared memory. */ struct JackClientControl : public JackShmMem { char fName[JACK_CLIENT_NAME_SIZE + 1]; - bool fCallback[kMaxNotification]; - volatile jack_transport_state_t fTransportState; - int fRefNum; - bool fActive; + bool fCallback[kMaxNotification]; + volatile jack_transport_state_t fTransportState; + int fRefNum; + bool fActive; JackClientControl(const char* name, int refnum) { @@ -60,16 +60,16 @@ struct JackClientControl : public JackShmMem void Init(const char* name, int refnum) { strcpy(fName, name); - for (int i = 0; i < kMaxNotification; i++) - fCallback[i] = false; - // Always activated - fCallback[kAddClient] = true; - fCallback[kRemoveClient] = true; - fCallback[kActivateClient] = true; - // So that driver synchro are correctly setup in "flush" or "normal" mode - fCallback[kStartFreewheelCallback] = true; - fCallback[kStopFreewheelCallback] = true; - fRefNum = refnum; + for (int i = 0; i < kMaxNotification; i++) + fCallback[i] = false; + // Always activated + fCallback[kAddClient] = true; + fCallback[kRemoveClient] = true; + fCallback[kActivateClient] = true; + // So that driver synchro are correctly setup in "flush" or "normal" mode + fCallback[kStartFreewheelCallback] = true; + fCallback[kStopFreewheelCallback] = true; + fRefNum = refnum; fTransportState = JackTransportStopped; fActive = false; } diff --git a/common/JackConnectionManager.cpp b/common/JackConnectionManager.cpp index 2f3edf9a..e97ede73 100644 --- a/common/JackConnectionManager.cpp +++ b/common/JackConnectionManager.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -245,7 +245,7 @@ void JackConnectionManager::ResetGraph(JackClientTiming* timing) // Reset activation counter : must be done *before* starting to resume clients for (int i = 0; i < CLIENT_NUM; i++) { fInputCounter[i].Reset(); - timing[i].fStatus = NotTriggered; + timing[i].fStatus = NotTriggered; } } @@ -256,8 +256,8 @@ int JackConnectionManager::SuspendRefNum(JackClientControl* control, JackSynchro { bool res; if ((res = table[control->fRefNum]->TimedWait(time_out_usec))) { - timing[control->fRefNum].fStatus = Running; - timing[control->fRefNum].fAwakeAt = GetMicroSeconds(); + timing[control->fRefNum].fStatus = Running; + timing[control->fRefNum].fAwakeAt = GetMicroSeconds(); } return (res) ? 0 : -1; } @@ -267,22 +267,22 @@ int JackConnectionManager::SuspendRefNum(JackClientControl* control, JackSynchro */ int JackConnectionManager::ResumeRefNum(JackClientControl* control, JackSynchro** table, JackClientTiming* timing) { - jack_time_t current_date = GetMicroSeconds(); + jack_time_t current_date = GetMicroSeconds(); const jack_int_t* outputRef = fConnectionRef.GetItems(control->fRefNum); - int res = 0; + int res = 0; // Update state and timestamp of current client - timing[control->fRefNum].fStatus = Finished; - timing[control->fRefNum].fFinishedAt = current_date; + timing[control->fRefNum].fStatus = Finished; + timing[control->fRefNum].fFinishedAt = current_date; for (int i = 0; i < CLIENT_NUM; i++) { - + // Signal connected clients or drivers if (outputRef[i] > 0) { - - // Update state and timestamp of destination clients - timing[i].fStatus = Triggered; - timing[i].fSignaledAt = current_date; + + // Update state and timestamp of destination clients + timing[i].fStatus = Triggered; + timing[i].fSignaledAt = current_date; if (!fInputCounter[i].Signal(table[i], control)) { JackLog("JackConnectionManager::ResumeRefNum error: ref = %ld output = %ld \n", control->fRefNum, i); diff --git a/common/JackConnectionManager.h b/common/JackConnectionManager.h index cf7fb70c..1bc79397 100644 --- a/common/JackConnectionManager.h +++ b/common/JackConnectionManager.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -59,7 +59,7 @@ class JackFixedArray fCounter = 0; } - bool AddItem(jack_int_t index) + bool AddItem(jack_int_t index) { for (int i = 0; i < SIZE; i++) { if (fTable[i] == EMPTY) { @@ -92,7 +92,7 @@ class JackFixedArray return false; } - jack_int_t GetItem(jack_int_t index) const + jack_int_t GetItem(jack_int_t index) const { return (index < SIZE) ? fTable[index] : EMPTY; } @@ -145,7 +145,7 @@ class JackFixedArray1 : public JackFixedArray<SIZE> fUsed = false; } - bool IsAvailable() + bool IsAvailable() { if (fUsed) { return false; @@ -358,25 +358,25 @@ struct JackClientTiming jack_time_t fSignaledAt; jack_time_t fAwakeAt; jack_time_t fFinishedAt; - jack_client_state_t fStatus; - - JackClientTiming():fSignaledAt(0), fAwakeAt(0), fFinishedAt(0), fStatus(NotTriggered) + jack_client_state_t fStatus; + + JackClientTiming(): fSignaledAt(0), fAwakeAt(0), fFinishedAt(0), fStatus(NotTriggered) {} - ~JackClientTiming() + ~JackClientTiming() {} }; /*! \brief Connection manager. - + <UL> <LI>The <B>fConnection</B> array contains the list (array line) of connected ports for a given port. <LI>The <B>fConnectionCount</B> array contains the number of connected ports to a given port. <LI>The <B>fInputPort</B> array contains the list (array line) of input connected ports for a given client. <LI>The <B>fOutputPort</B> array contains the list (array line) of ouput connected ports for a given client. -<LI>The <B>fConnectionRef</B> array contains the number of ports connected between two clients. -<LI>The <B>fInputRef</B> array contains the number of input clients connected to a given client. -<LI>The <B>fInputCounter</B> array contains the number of input clients connected to a given for activation purpose. +<LI>The <B>fConnectionRef</B> array contains the number of ports connected between two clients. +<LI>The <B>fInputRef</B> array contains the number of input clients connected to a given client. +<LI>The <B>fInputCounter</B> array contains the number of input clients connected to a given for activation purpose. </UL> */ @@ -393,7 +393,7 @@ class JackConnectionManager JackLoopFeedback<CONNECTION_NUM> fLoopFeedback; /*! Loop feedback connections */ bool IsLoopPathAux(int ref1, int ref2) const; - + public: JackConnectionManager(); @@ -427,8 +427,8 @@ class JackConnectionManager const jack_int_t* GetOutputPorts(int refnum); // Client management - void InitRefNum(int refnum); - int GetInputRefNum(jack_port_id_t port_index) const; + void InitRefNum(int refnum); + int GetInputRefNum(jack_port_id_t port_index) const; int GetOutputRefNum(jack_port_id_t port_index) const; // Connect/Disconnect 2 refnum "directly" diff --git a/common/JackConstants.h b/common/JackConstants.h index 40a00b46..c49ebd4e 100644 --- a/common/JackConstants.h +++ b/common/JackConstants.h @@ -52,17 +52,17 @@ namespace Jack #define SOCKET_TIME_OUT 5 #ifdef WIN32 - #define jack_server_dir "server" - #define jack_client_dir "client" - #define ADDON_DIR "jackmp" +#define jack_server_dir "server" +#define jack_client_dir "client" +#define ADDON_DIR "jackmp" #elif __APPLE__ - #define jack_server_dir "/tmp" - #define jack_client_dir "/tmp" - #define JACK_DEFAULT_DRIVER "coreaudio" +#define jack_server_dir "/tmp" +#define jack_client_dir "/tmp" +#define JACK_DEFAULT_DRIVER "coreaudio" #else - #define jack_server_dir "/dev/shm" - #define jack_client_dir "/dev/shm" - #define JACK_DEFAULT_DRIVER "alsa" +#define jack_server_dir "/dev/shm" +#define jack_client_dir "/dev/shm" +#define JACK_DEFAULT_DRIVER "alsa" #endif #define jack_server_entry "jackdmp_entry" @@ -71,9 +71,9 @@ namespace Jack #define ALL_CLIENTS -1 // for notification #if defined(__ppc64__) || defined(__x86_64__) - #define JACK_PROTOCOL_VERSION 4 +#define JACK_PROTOCOL_VERSION 4 #else - #define JACK_PROTOCOL_VERSION 3 +#define JACK_PROTOCOL_VERSION 3 #endif #define DRIVER_OPEN_TIMEOUT 5 // in sec diff --git a/common/JackDebugClient.cpp b/common/JackDebugClient.cpp index df5db407..a89af014 100644 --- a/common/JackDebugClient.cpp +++ b/common/JackDebugClient.cpp @@ -113,25 +113,25 @@ int JackDebugClient::Close() void JackDebugClient::CheckClient() const { if (fIsClosed > 0) { - *fStream << "!!! ERROR !!! : Accessing a client '" << fClientName << "' already closed !" << endl; - *fStream << "This is likely to cause crash !'" << endl; - } + *fStream << "!!! ERROR !!! : Accessing a client '" << fClientName << "' already closed !" << endl; + *fStream << "This is likely to cause crash !'" << endl; + } } pthread_t JackDebugClient::GetThreadID() { - CheckClient(); + CheckClient(); return fClient->GetThreadID(); } JackGraphManager* JackDebugClient::GetGraphManager() const { - CheckClient(); + CheckClient(); return fClient->GetGraphManager(); } JackEngineControl* JackDebugClient::GetEngineControl() const { - CheckClient(); + CheckClient(); return fClient->GetEngineControl(); } /*! @@ -140,13 +140,13 @@ JackEngineControl* JackDebugClient::GetEngineControl() const int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2) { - CheckClient(); + CheckClient(); return fClient->ClientNotify( refnum, name, notify, sync, value1, value2); } int JackDebugClient::Activate() { - CheckClient(); + CheckClient(); int res = fClient->Activate(); fIsActivated++; if (fIsDeactivated) @@ -159,7 +159,7 @@ int JackDebugClient::Activate() int JackDebugClient::Deactivate() { - CheckClient(); + CheckClient(); int res = fClient->Deactivate(); fIsDeactivated++; if (fIsActivated == 0) @@ -176,7 +176,7 @@ int JackDebugClient::Deactivate() int JackDebugClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size) { - CheckClient(); + CheckClient(); int res = fClient->PortRegister(port_name, port_type, flags, buffer_size); if (res <= 0) { *fStream << "Client '" << fClientName << "' try port register ('" << port_name << "') and server return error " << res << " ." << endl; @@ -198,7 +198,7 @@ int JackDebugClient::PortRegister(const char* port_name, const char* port_type, int JackDebugClient::PortUnRegister(jack_port_id_t port_index) { - CheckClient(); + CheckClient(); int res = fClient->PortUnRegister(port_index); fOpenPortNumber--; int i; @@ -220,7 +220,7 @@ int JackDebugClient::PortUnRegister(jack_port_id_t port_index) int JackDebugClient::PortConnect(const char* src, const char* dst) { - CheckClient(); + CheckClient(); if (!fIsActivated) *fStream << "!!! ERROR !!! Trying to connect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl; int i; @@ -250,7 +250,7 @@ int JackDebugClient::PortConnect(const char* src, const char* dst) int JackDebugClient::PortDisconnect(const char* src, const char* dst) { - CheckClient(); + CheckClient(); if (!fIsActivated) *fStream << "!!! ERROR !!! Trying to disconnect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl; int res = fClient->PortDisconnect( src, dst); @@ -279,8 +279,8 @@ int JackDebugClient::PortDisconnect(const char* src, const char* dst) } int JackDebugClient::PortConnect(jack_port_id_t src, jack_port_id_t dst) -{ - CheckClient(); +{ + CheckClient(); if (!fIsActivated) *fStream << "!!! ERROR !!! : Trying to connect port " << src << " to " << dst << " while the client has not been activated !" << endl; int res = fClient->PortConnect(src, dst); @@ -310,7 +310,7 @@ int JackDebugClient::PortConnect(jack_port_id_t src, jack_port_id_t dst) int JackDebugClient::PortDisconnect(jack_port_id_t src) { - CheckClient(); + CheckClient(); if (!fIsActivated) *fStream << "!!! ERROR !!! : Trying to disconnect port " << src << " while that client has not been activated !" << endl; int res = fClient->PortDisconnect(src); @@ -334,7 +334,7 @@ int JackDebugClient::PortDisconnect(jack_port_id_t src) int JackDebugClient::PortIsMine(jack_port_id_t port_index) { - CheckClient(); + CheckClient(); return fClient->PortIsMine(port_index); } @@ -344,13 +344,13 @@ int JackDebugClient::PortIsMine(jack_port_id_t port_index) int JackDebugClient::SetBufferSize(jack_nframes_t buffer_size) { - CheckClient(); + CheckClient(); return fClient->SetBufferSize(buffer_size); } int JackDebugClient::SetFreeWheel(int onoff) { - CheckClient(); + CheckClient(); return fClient->SetFreeWheel(onoff); } @@ -372,61 +372,61 @@ void JackDebugClient::ShutDown() int JackDebugClient::ReleaseTimebase() { - CheckClient(); + CheckClient(); return fClient->ReleaseTimebase(); } int JackDebugClient::SetSyncCallback(JackSyncCallback sync_callback, void* arg) { - CheckClient(); + CheckClient(); return fClient->SetSyncCallback(sync_callback, arg); } int JackDebugClient::SetSyncTimeout(jack_time_t timeout) { - CheckClient(); + CheckClient(); return fClient->SetSyncTimeout(timeout); } int JackDebugClient::SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg) { - CheckClient(); + CheckClient(); return fClient->SetTimebaseCallback( conditional, timebase_callback, arg); } int JackDebugClient::TransportLocate(jack_nframes_t frame) { - CheckClient(); + CheckClient(); return fClient->TransportLocate(frame); } jack_transport_state_t JackDebugClient::TransportQuery(jack_position_t* pos) { - CheckClient(); + CheckClient(); return fClient->TransportQuery(pos); } jack_nframes_t JackDebugClient::GetCurrentTransportFrame() { - CheckClient(); + CheckClient(); return fClient->GetCurrentTransportFrame(); } int JackDebugClient::TransportReposition(jack_position_t* pos) { - CheckClient(); + CheckClient(); return fClient->TransportReposition(pos); } void JackDebugClient::TransportStart() { - CheckClient(); + CheckClient(); fClient->TransportStart(); } void JackDebugClient::TransportStop() { - CheckClient(); + CheckClient(); fClient->TransportStop(); } @@ -436,112 +436,112 @@ void JackDebugClient::TransportStop() void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg) { - CheckClient(); + CheckClient(); fClient->OnShutdown(callback, arg); } int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg) { - JackDebugClient* client = (JackDebugClient*)arg; - jack_time_t t1 = GetMicroSeconds(); - int res = client->fProcessTimeCallback(nframes, client->fProcessTimeCallbackArg); - jack_time_t t2 = GetMicroSeconds(); - long delta = long((t2 - t1) - client->GetEngineControl()->fPeriodUsecs); - if (delta > 0) - *client->fStream << "!!! ERROR !!! : Process overload of " << delta << " us" << endl; - return res; + JackDebugClient* client = (JackDebugClient*)arg; + jack_time_t t1 = GetMicroSeconds(); + int res = client->fProcessTimeCallback(nframes, client->fProcessTimeCallbackArg); + jack_time_t t2 = GetMicroSeconds(); + long delta = long((t2 - t1) - client->GetEngineControl()->fPeriodUsecs); + if (delta > 0) + *client->fStream << "!!! ERROR !!! : Process overload of " << delta << " us" << endl; + return res; } int JackDebugClient::SetProcessCallback(JackProcessCallback callback, void *arg) { - CheckClient(); - fProcessTimeCallback = callback; - fProcessTimeCallbackArg = arg; - return fClient->SetProcessCallback(TimeCallback, this); + CheckClient(); + fProcessTimeCallback = callback; + fProcessTimeCallbackArg = arg; + return fClient->SetProcessCallback(TimeCallback, this); } int JackDebugClient::SetXRunCallback(JackXRunCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetXRunCallback(callback, arg); } int JackDebugClient::SetInitCallback(JackThreadInitCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetInitCallback(callback, arg); } int JackDebugClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetGraphOrderCallback(callback, arg); } int JackDebugClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetBufferSizeCallback(callback, arg); } int JackDebugClient::SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg) { - CheckClient(); + CheckClient(); return fClient->SetClientRegistrationCallback(callback, arg); } int JackDebugClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetFreewheelCallback(callback, arg); } int JackDebugClient::SetPortRegistrationCallback(JackPortRegistrationCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetPortRegistrationCallback(callback, arg); } int JackDebugClient::SetPortConnectCallback(JackPortConnectCallback callback, void *arg) { - CheckClient(); + CheckClient(); return fClient->SetPortConnectCallback(callback, arg); } JackClientControl* JackDebugClient::GetClientControl() const { - CheckClient(); + CheckClient(); return fClient->GetClientControl(); } // Internal clients char* JackDebugClient::GetInternalClientName(int ref) { - CheckClient(); + CheckClient(); return fClient->GetInternalClientName(ref); } int JackDebugClient::InternalClientHandle(const char* client_name, jack_status_t* status) { - CheckClient(); + CheckClient(); return fClient->InternalClientHandle(client_name, status); } int JackDebugClient::InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va) { - CheckClient(); + CheckClient(); return fClient->InternalClientLoad(client_name, options, status, va); } void JackDebugClient::InternalClientUnload(int ref, jack_status_t* status) { - CheckClient(); + CheckClient(); fClient->InternalClientUnload(ref, status); } - + jack_nframes_t JackDebugClient::Wait(int status) { - CheckClient(); + CheckClient(); return fClient->Wait(status); } diff --git a/common/JackDebugClient.h b/common/JackDebugClient.h index e1280cb8..3b80ab5e 100644 --- a/common/JackDebugClient.h +++ b/common/JackDebugClient.h @@ -45,22 +45,22 @@ PortFollower; /*! \brief A "decorator" debug client to validate API use. */ - + class JackDebugClient : public JackClient { protected: - - JackClient* fClient; + + JackClient* fClient; std::ofstream* fStream; - PortFollower fPortList[MAX_PORT_HISTORY]; // Arbitrary value... To be tuned... + PortFollower fPortList[MAX_PORT_HISTORY]; // Arbitrary value... To be tuned... int fTotalPortNumber; // The total number of port opened and maybe closed. Historical view. int fOpenPortNumber; // The current number of opened port. int fIsActivated; int fIsDeactivated; int fIsClosed; char fClientName[JACK_CLIENT_NAME_SIZE]; - JackProcessCallback fProcessTimeCallback; - void* fProcessTimeCallbackArg; + JackProcessCallback fProcessTimeCallback; + void* fProcessTimeCallbackArg; public: @@ -115,24 +115,24 @@ class JackDebugClient : public JackClient int SetInitCallback(JackThreadInitCallback callback, void* arg); int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg); int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg); - int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg); + int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg); int SetFreewheelCallback(JackFreewheelCallback callback, void* arg); int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg); - int SetPortConnectCallback(JackPortConnectCallback callback, void *arg); - - // Internal clients - char* GetInternalClientName(int ref); - int InternalClientHandle(const char* client_name, jack_status_t* status); - int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va); - void InternalClientUnload(int ref, jack_status_t* status); - - // Fons Adriaensen thread model - jack_nframes_t Wait(int status); - + int SetPortConnectCallback(JackPortConnectCallback callback, void *arg); + + // Internal clients + char* GetInternalClientName(int ref); + int InternalClientHandle(const char* client_name, jack_status_t* status); + int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va); + void InternalClientUnload(int ref, jack_status_t* status); + + // Fons Adriaensen thread model + jack_nframes_t Wait(int status); + JackClientControl* GetClientControl() const; - void CheckClient() const; - - static int TimeCallback(jack_nframes_t nframes, void *arg); + void CheckClient() const; + + static int TimeCallback(jack_nframes_t nframes, void *arg); }; diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index cbd8b9ee..a3250b0f 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -70,15 +70,15 @@ int JackDriver::Open() { int refnum = -1; - if (fEngine->ClientInternalOpen(fClientControl->fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) { + if (fEngine->ClientInternalOpen(fClientControl->fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) { jack_error("Cannot allocate internal client for audio driver"); return -1; } fClientControl->fRefNum = refnum; - fClientControl->fActive = true; - fGraphManager->DirectConnect(fClientControl->fRefNum, fClientControl->fRefNum); // Connect driver to itself for "sync" mode - SetupDriverSync(fClientControl->fRefNum, false); + fClientControl->fActive = true; + fGraphManager->DirectConnect(fClientControl->fRefNum, fClientControl->fRefNum); // Connect driver to itself for "sync" mode + SetupDriverSync(fClientControl->fRefNum, false); return 0; } @@ -104,7 +104,7 @@ int JackDriver::Open(jack_nframes_t nframes, } fClientControl->fRefNum = refnum; - fClientControl->fActive = true; + fClientControl->fActive = true; fEngineControl->fBufferSize = nframes; fEngineControl->fSampleRate = samplerate; fCaptureLatency = capture_latency; @@ -122,7 +122,7 @@ int JackDriver::Open(jack_nframes_t nframes, fGraphManager->SetBufferSize(nframes); fGraphManager->DirectConnect(fClientControl->fRefNum, fClientControl->fRefNum); // Connect driver to itself for "sync" mode - SetupDriverSync(fClientControl->fRefNum, false); + SetupDriverSync(fClientControl->fRefNum, false); return 0; } @@ -141,31 +141,31 @@ int JackDriver::Close() */ void JackDriver::SetupDriverSync(int ref, bool freewheel) { - if (!freewheel && !fEngineControl->fSyncMode) { + if (!freewheel && !fEngineControl->fSyncMode) { JackLog("JackDriver::SetupDriverSync driver sem in flush mode\n"); fSynchroTable[ref]->SetFlush(true); } else { JackLog("JackDriver::SetupDriverSync driver sem in normal mode\n"); fSynchroTable[ref]->SetFlush(false); - } + } } int JackDriver::ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2) { - switch (notify) { - - case kStartFreewheelCallback: - JackLog("JackDriver::kStartFreewheel\n"); - SetupDriverSync(fClientControl->fRefNum, true); - break; - - case kStopFreewheelCallback: - JackLog("JackDriver::kStopFreewheel\n"); - SetupDriverSync(fClientControl->fRefNum, false); - break; - } + switch (notify) { + + case kStartFreewheelCallback: + JackLog("JackDriver::kStartFreewheel\n"); + SetupDriverSync(fClientControl->fRefNum, true); + break; - return 0; + case kStopFreewheelCallback: + JackLog("JackDriver::kStopFreewheel\n"); + SetupDriverSync(fClientControl->fRefNum, false); + break; + } + + return 0; } bool JackDriver::IsRealTime() @@ -205,14 +205,14 @@ void JackDriverClient::RemoveSlave(JackDriverInterface* slave) int JackDriverClient::ProcessSlaves() { - int res = 0; + int res = 0; list<JackDriverInterface*>::const_iterator it; for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { JackDriverInterface* slave = *it; if (slave->Process() < 0) - res = -1; + res = -1; } - return res; + return res; } } // end of namespace diff --git a/common/JackDriver.h b/common/JackDriver.h index aae51819..8179e04d 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -65,14 +65,14 @@ class EXPORT JackDriverInterface 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 SetSampleRate(jack_nframes_t sample_rate) = 0; virtual int Process() = 0; @@ -90,7 +90,7 @@ class EXPORT JackDriverInterface */ class EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface -{}; + {}; /*! \brief The base class for drivers clients. @@ -195,9 +195,9 @@ class EXPORT JackDriver : public JackDriverClient { return 0; } - - virtual int SetSampleRate(jack_nframes_t sample_rate) - { + + virtual int SetSampleRate(jack_nframes_t sample_rate) + { return 0; } @@ -206,8 +206,8 @@ class EXPORT JackDriver : public JackDriverClient virtual bool IsRealTime(); int ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2); - - void SetupDriverSync(int ref, bool freewheel); + + void SetupDriverSync(int ref, bool freewheel); }; diff --git a/common/JackDriverLoader.cpp b/common/JackDriverLoader.cpp index a024509b..e2992338 100644 --- a/common/JackDriverLoader.cpp +++ b/common/JackDriverLoader.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2005 Paul Davis -Copyright (C) 2004-2008 Grame +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 @@ -18,11 +18,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif -#ifndef WIN32 +#ifndef WIN32 #ifndef ADDON_DIR #include "config.h" #endif @@ -32,7 +32,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackError.h" #include <getopt.h> -#ifndef WIN32 +#ifndef WIN32 #include <dirent.h> #endif @@ -116,7 +116,7 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char* argv[], JSL printf ("Parameters for driver '%s' (all parameters are optional):\n", desc->name); jack_print_driver_options (desc, stdout); return 1; - } + } /* set up the stuff for getopt */ options = (char*)calloc (desc->nparams * 3 + 1, sizeof (char)); @@ -186,7 +186,7 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char* argv[], JSL strcasecmp ("no", optarg) == 0 || strcasecmp ("0", optarg) == 0 || strcasecmp ("(null)", optarg) == 0 ) { - */ + */ // steph if (strcmp ("false", optarg) == 0 || strcmp ("off", optarg) == 0 || @@ -256,15 +256,15 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile) #endif int err; - /* - char* driver_dir; - if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { - driver_dir = ADDON_DIR; - } - */ - + /* + char* driver_dir; + if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { + driver_dir = ADDON_DIR; + } + */ + #ifdef WIN32 - char* driver_dir = ADDON_DIR; + char* driver_dir = ADDON_DIR; if (strcmp(ADDON_DIR, "") == 0) { char temp_driver_dir1[512]; char temp_driver_dir2[512]; @@ -273,8 +273,8 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile) driver_dir = temp_driver_dir2; } #else - char driver_dir[512]; - snprintf(driver_dir, sizeof(driver_dir) - 1, "%s/%s/jackmp", ADDON_DIR, LIB_DIR); + char driver_dir[512]; + snprintf(driver_dir, sizeof(driver_dir) - 1, "%s/%s/jackmp", ADDON_DIR, LIB_DIR); #endif filename = (char *)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1); @@ -330,7 +330,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile) if (strcmp(descriptor->name, other_descriptor->name) == 0) { jack_error("the drivers in '%s' and '%s' both have the name '%s'; using the first\n", - other_descriptor->file, filename, other_descriptor->name); + other_descriptor->file, filename, other_descriptor->name); /* FIXME: delete the descriptor */ free(filename); return NULL; @@ -400,15 +400,15 @@ jack_drivers_load (JSList * drivers) { JSList * driver_list = NULL; jack_driver_desc_t * desc; - /* - char* driver_dir; + /* + char* driver_dir; if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { - driver_dir = ADDON_DIR; - } - */ - char driver_dir[512]; - snprintf(driver_dir, sizeof(driver_dir) - 1, "%s/%s/jackmp", ADDON_DIR, LIB_DIR); - + driver_dir = ADDON_DIR; + } + */ + char driver_dir[512]; + snprintf(driver_dir, sizeof(driver_dir) - 1, "%s/%s/jackmp", ADDON_DIR, LIB_DIR); + /* search through the driver_dir and add get descriptors from the .so files in it */ dir_stream = opendir (driver_dir); diff --git a/common/JackDriverLoader.h b/common/JackDriverLoader.h index c52ea1eb..55ae3b13 100644 --- a/common/JackDriverLoader.h +++ b/common/JackDriverLoader.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2005 Paul Davis -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackDummyDriver.cpp b/common/JackDummyDriver.cpp index 897dbbae..79f7f8f7 100644 --- a/common/JackDummyDriver.cpp +++ b/common/JackDummyDriver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify diff --git a/common/JackDummyDriver.h b/common/JackDummyDriver.h index ea3fbaba..acd4a712 100644 --- a/common/JackDummyDriver.h +++ b/common/JackDummyDriver.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index c7399836..006e0b41 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -38,15 +38,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. namespace Jack { -JackEngine::JackEngine(JackGraphManager* manager, - JackSynchro** table, - JackEngineControl* control) +JackEngine::JackEngine(JackGraphManager* manager, + JackSynchro** table, + JackEngineControl* control) { fGraphManager = manager; fSynchroTable = table; fEngineControl = control; - fChannel = JackGlobals::MakeServerNotifyChannel(); - fSignal = JackGlobals::MakeInterProcessSync(); + fChannel = JackGlobals::MakeServerNotifyChannel(); + fSignal = JackGlobals::MakeInterProcessSync(); for (int i = 0; i < CLIENT_NUM; i++) fClientTable[i] = NULL; } @@ -54,7 +54,7 @@ JackEngine::JackEngine(JackGraphManager* manager, JackEngine::~JackEngine() { delete fChannel; - delete fSignal; + delete fSignal; } int JackEngine::Open() @@ -79,14 +79,14 @@ int JackEngine::Close() for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; if (client) { - JackLog("JackEngine::Close remaining client %ld\n", i); - fClientTable[i] = NULL; + JackLog("JackEngine::Close remaining client %ld\n", i); + fClientTable[i] = NULL; client->Close(); delete client; } } - - fSignal->Destroy(); + + fSignal->Destroy(); return 0; } @@ -107,23 +107,23 @@ int JackEngine::AllocateRefnum() void JackEngine::ReleaseRefnum(int ref) { - fClientTable[ref] = NULL; - - if (fEngineControl->fTemporary) { - int i; - for (i = REAL_REFNUM; i < CLIENT_NUM; i++) { - if (fClientTable[i]) - break; - } - if (i == CLIENT_NUM) { - // last client and temporay case: quit the server - JackLog("JackEngine::ReleaseRefnum server quit\n"); - fEngineControl->fTemporary = false; - #ifndef WIN32 - kill(getpid(), SIGINT); - #endif - } - } + fClientTable[ref] = NULL; + + if (fEngineControl->fTemporary) { + int i; + for (i = REAL_REFNUM; i < CLIENT_NUM; i++) { + if (fClientTable[i]) + break; + } + if (i == CLIENT_NUM) { + // last client and temporay case: quit the server + JackLog("JackEngine::ReleaseRefnum server quit\n"); + fEngineControl->fTemporary = false; +#ifndef WIN32 + kill(getpid(), SIGINT); +#endif + } + } } //------------------ @@ -132,46 +132,46 @@ void JackEngine::ReleaseRefnum(int ref) void JackEngine::ProcessNext(jack_time_t callback_usecs) { - fLastSwitchUsecs = callback_usecs; - if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state - fChannel->ClientNotify(ALL_CLIENTS, kGraphOrderCallback, 0, 0); - fSignal->SignalAll(); // Signal for threads waiting for next cycle + fLastSwitchUsecs = callback_usecs; + if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state + fChannel->ClientNotify(ALL_CLIENTS, kGraphOrderCallback, 0, 0); + fSignal->SignalAll(); // Signal for threads waiting for next cycle } void JackEngine::ProcessCurrent(jack_time_t callback_usecs) { - if (callback_usecs < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) // Signal XRun only for the first failing cycle - CheckXRun(callback_usecs); - fGraphManager->RunCurrentGraph(); + if (callback_usecs < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) // Signal XRun only for the first failing cycle + CheckXRun(callback_usecs); + fGraphManager->RunCurrentGraph(); } bool JackEngine::Process(jack_time_t callback_usecs) { - bool res = true; - + bool res = true; + // Cycle begin - fEngineControl->CycleBegin(fClientTable, fGraphManager, callback_usecs); + fEngineControl->CycleBegin(fClientTable, fGraphManager, callback_usecs); - // Graph + // Graph if (fGraphManager->IsFinishedGraph()) { ProcessNext(callback_usecs); - res = true; + res = true; } else { JackLog("Process: graph not finished!\n"); - if (callback_usecs > fLastSwitchUsecs + fEngineControl->fTimeOutUsecs) { + if (callback_usecs > fLastSwitchUsecs + fEngineControl->fTimeOutUsecs) { JackLog("Process: switch to next state delta = %ld\n", long(callback_usecs - fLastSwitchUsecs)); - ProcessNext(callback_usecs); - res = true; + ProcessNext(callback_usecs); + res = true; } else { JackLog("Process: waiting to switch delta = %ld\n", long(callback_usecs - fLastSwitchUsecs)); ProcessCurrent(callback_usecs); - res = false; - } + res = false; + } } // Cycle end - fEngineControl->CycleEnd(fClientTable); - return res; + fEngineControl->CycleEnd(fClientTable); + return res; } @@ -185,15 +185,15 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; if (client && client->GetClientControl()->fActive) { - JackClientTiming* timing = fGraphManager->GetClientTiming(i); - jack_client_state_t status = timing->fStatus; + JackClientTiming* timing = fGraphManager->GetClientTiming(i); + jack_client_state_t status = timing->fStatus; jack_time_t finished_date = timing->fFinishedAt; - + if (status != NotTriggered && status != Finished) { jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client->GetClientControl()->fName, status); fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0, 0); // Notify all clients } - + if (status == Finished && (long)(finished_date - callback_usecs) > 0) { jack_error("JackEngine::XRun: client %s finished after current callback", client->GetClientControl()->fName); fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0, 0); // Notify all clients @@ -209,13 +209,13 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions void JackEngine::NotifyClient(int refnum, int event, int sync, int value1, int value2) { JackClientInterface* client = fClientTable[refnum]; - + // The client may be notified by the RT thread while closing if (!client) { - JackLog("JackEngine::NotifyClient: client not available anymore\n"); - } else if (client->GetClientControl()->fCallback[event]) { - if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, value1, value2) < 0) - jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2); + JackLog("JackEngine::NotifyClient: client not available anymore\n"); + } else if (client->GetClientControl()->fCallback[event]) { + if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, value1, value2) < 0) + jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2); } else { JackLog("JackEngine::NotifyClient: no callback for event = %ld\n", event); } @@ -225,14 +225,14 @@ void JackEngine::NotifyClients(int event, int sync, int value1, int value2) { for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client) { - if (client->GetClientControl()->fCallback[event]) { - if (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, value1, value2) < 0) - jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2); - } else { - JackLog("JackEngine::NotifyClients: no callback for event = %ld\n", event); - } - } + if (client) { + if (client->GetClientControl()->fCallback[event]) { + if (client->ClientNotify(i, client->GetClientControl()->fName, event, sync, value1, value2) < 0) + jack_error("NotifyClient fails name = %s event = %ld = val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2); + } else { + JackLog("JackEngine::NotifyClients: no callback for event = %ld\n", event); + } + } } } @@ -244,12 +244,12 @@ int JackEngine::NotifyAddClient(JackClientInterface* new_client, const char* nam if (old_client) { if (old_client->ClientNotify(refnum, name, kAddClient, true, 0, 0) < 0) { jack_error("NotifyAddClient old_client fails name = %s", old_client->GetClientControl()->fName); - return -1; - } - if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, kAddClient, true, 0, 0) < 0) { + return -1; + } + if (new_client->ClientNotify(i, old_client->GetClientControl()->fName, kAddClient, true, 0, 0) < 0) { jack_error("NotifyAddClient new_client fails name = %s", name); - return -1; - } + return -1; + } } } @@ -271,7 +271,7 @@ void JackEngine::NotifyRemoveClient(const char* name, int refnum) void JackEngine::NotifyXRun(jack_time_t callback_usecs) { // Use the audio thread => request thread communication channel - fEngineControl->ResetFrameTime(callback_usecs); + fEngineControl->ResetFrameTime(callback_usecs); fChannel->ClientNotify(ALL_CLIENTS, kXRunCallback, 0, 0); } @@ -312,7 +312,7 @@ void JackEngine::NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool void JackEngine::NotifyActivate(int refnum) { - NotifyClient(refnum, kActivateClient, true, 0, 0); + NotifyClient(refnum, kActivateClient, true, 0, 0); } //---------------------------- @@ -321,45 +321,45 @@ void JackEngine::NotifyActivate(int refnum) int JackEngine::GetInternalClientName(int refnum, char* name_res) { - assert(refnum >= 0 && refnum < CLIENT_NUM); - JackClientInterface* client = fClientTable[refnum]; - if (client) { - strncpy(name_res, client->GetClientControl()->fName, JACK_CLIENT_NAME_SIZE); - return 0; - } else { - return -1; - } + assert(refnum >= 0 && refnum < CLIENT_NUM); + JackClientInterface* client = fClientTable[refnum]; + if (client) { + strncpy(name_res, client->GetClientControl()->fName, JACK_CLIENT_NAME_SIZE); + return 0; + } else { + return -1; + } } int JackEngine::InternalClientHandle(const char* client_name, int* status, int* int_ref) { - // Clear status - *status = 0; - - for (int i = 0; i < CLIENT_NUM; i++) { + // Clear status + *status = 0; + + for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; if (client && dynamic_cast<JackLoadableInternalClient*>(client) && (strcmp(client->GetClientControl()->fName, client_name) == 0)) { - JackLog("InternalClientHandle found client name = %s ref = %ld\n", client_name, i); - *int_ref = i; - return 0; - } + JackLog("InternalClientHandle found client name = %s ref = %ld\n", client_name, i); + *int_ref = i; + return 0; + } } - - *status |= (JackNoSuchClient | JackFailure); - return -1; + + *status |= (JackNoSuchClient | JackFailure); + return -1; } int JackEngine::InternalClientUnload(int refnum, int* status) { - assert(refnum >= 0 && refnum < CLIENT_NUM); - JackClientInterface* client = fClientTable[refnum]; - if (client) { - int res = client->Close(); - delete client; - *status = 0; - return res; - } else { - *status = (JackNoSuchClient | JackFailure); + assert(refnum >= 0 && refnum < CLIENT_NUM); + JackClientInterface* client = fClientTable[refnum]; + if (client) { + int res = client->Close(); + delete client; + *status = 0; + return res; + } else { + *status = (JackNoSuchClient | JackFailure); return -1; } } @@ -370,68 +370,68 @@ int JackEngine::InternalClientUnload(int refnum, int* status) int JackEngine::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status) { - // Clear status - *status = 0; - strcpy(name_res, name); - - JackLog("Check protocol client %ld server = %ld\n", protocol, JACK_PROTOCOL_VERSION); - - if (protocol != JACK_PROTOCOL_VERSION) { - *status |= (JackFailure | JackVersionError); - jack_error("JACK protocol mismatch (%d vs %d)", protocol, JACK_PROTOCOL_VERSION); - return -1; - } - - if (ClientCheckName(name)) { - - *status |= JackNameNotUnique; - - if (options & JackUseExactName) { - jack_error("cannot create new client; %s already exists", name); - *status |= JackFailure; - return -1; - } - - if (GenerateUniqueName(name_res)) { - *status |= JackFailure; - return -1; - } - } - - return 0; + // Clear status + *status = 0; + strcpy(name_res, name); + + JackLog("Check protocol client %ld server = %ld\n", protocol, JACK_PROTOCOL_VERSION); + + if (protocol != JACK_PROTOCOL_VERSION) { + *status |= (JackFailure | JackVersionError); + jack_error("JACK protocol mismatch (%d vs %d)", protocol, JACK_PROTOCOL_VERSION); + return -1; + } + + if (ClientCheckName(name)) { + + *status |= JackNameNotUnique; + + if (options & JackUseExactName) { + jack_error("cannot create new client; %s already exists", name); + *status |= JackFailure; + return -1; + } + + if (GenerateUniqueName(name_res)) { + *status |= JackFailure; + return -1; + } + } + + return 0; } bool JackEngine::GenerateUniqueName(char* name) { - int tens, ones; - int length = strlen(name); - - if (length > JACK_CLIENT_NAME_SIZE - 4) { - jack_error("%s exists and is too long to make unique", name); - return true; /* failure */ - } - - /* generate a unique name by appending "-01".."-99" */ - name[length++] = '-'; - tens = length++; - ones = length++; - name[tens] = '0'; - name[ones] = '1'; - name[length] = '\0'; - - while (ClientCheckName(name)) { - if (name[ones] == '9') { - if (name[tens] == '9') { - jack_error("client %s has 99 extra instances already", name); - return true; /* give up */ - } - name[tens]++; - name[ones] = '0'; - } else { - name[ones]++; - } - } - return false; + int tens, ones; + int length = strlen(name); + + if (length > JACK_CLIENT_NAME_SIZE - 4) { + jack_error("%s exists and is too long to make unique", name); + return true; /* failure */ + } + + /* generate a unique name by appending "-01".."-99" */ + name[length++] = '-'; + tens = length++; + ones = length++; + name[tens] = '0'; + name[ones] = '1'; + name[length] = '\0'; + + while (ClientCheckName(name)) { + if (name[ones] == '9') { + if (name[tens] == '9') { + jack_error("client %s has 99 extra instances already", name); + return true; /* give up */ + } + name[tens]++; + name[ones] = '0'; + } else { + name[ones]++; + } + } + return false; } bool JackEngine::ClientCheckName(const char* name) @@ -449,18 +449,18 @@ bool JackEngine::ClientCheckName(const char* name) int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) { JackLog("JackEngine::ClientOpen: name = %s \n", name); - - int refnum = AllocateRefnum(); + + int refnum = AllocateRefnum(); if (refnum < 0) { jack_error("No more refnum available"); return -1; } - - JackExternalClient* client = new JackExternalClient(); + + JackExternalClient* client = new JackExternalClient(); if (!fSynchroTable[refnum]->Allocate(name, fEngineControl->fServerName, 0)) { jack_error("Cannot allocate synchro"); - goto error; + goto error; } if (client->Open(name, refnum, shared_client) < 0) { @@ -480,8 +480,8 @@ int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engin } fClientTable[refnum] = client; - fGraphManager->InitRefNum(refnum); - fEngineControl->ResetRollingUsecs(); + fGraphManager->InitRefNum(refnum); + fEngineControl->ResetRollingUsecs(); *shared_engine = fEngineControl->GetShmIndex(); *shared_graph_manager = fGraphManager->GetShmIndex(); *ref = refnum; @@ -490,7 +490,7 @@ int JackEngine::ClientExternalOpen(const char* name, int* ref, int* shared_engin error: ClientCloseAux(refnum, client, false); client->Close(); - delete client; + delete client; return -1; } @@ -498,32 +498,32 @@ error: int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait) { JackLog("JackEngine::ClientInternalNew: name = %s\n", name); - - int refnum = AllocateRefnum(); - if (refnum < 0) { + + int refnum = AllocateRefnum(); + if (refnum < 0) { jack_error("No more refnum available"); return -1; } if (!fSynchroTable[refnum]->Allocate(name, fEngineControl->fServerName, 0)) { jack_error("Cannot allocate synchro"); - return -1; + return -1; } - - if (wait && !fSignal->TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) { + + if (wait && !fSignal->TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) { // Failure if RT thread is not running (problem with the driver...) jack_error("Driver is not running"); - return -1; + return -1; } if (NotifyAddClient(client, name, refnum) < 0) { jack_error("Cannot notify add client"); - return -1; + return -1; } fClientTable[refnum] = client; - fGraphManager->InitRefNum(refnum); - fEngineControl->ResetRollingUsecs(); + fGraphManager->InitRefNum(refnum); + fEngineControl->ResetRollingUsecs(); *shared_engine = fEngineControl; *shared_manager = fGraphManager; *ref = refnum; @@ -554,28 +554,28 @@ int JackEngine::ClientInternalClose(int refnum, bool wait) int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wait) { - JackLog("JackEngine::ClientCloseAux ref = %ld name = %s\n", - refnum, - (client->GetClientControl()) ? client->GetClientControl()->fName : "No name"); + JackLog("JackEngine::ClientCloseAux ref = %ld name = %s\n", + refnum, + (client->GetClientControl()) ? client->GetClientControl()->fName : "No name"); // Remove the client from the table - ReleaseRefnum(refnum); - - // Notiy unregister - jack_int_t ports[PORT_NUM_FOR_CLIENT]; - int i; - - fGraphManager->GetInputPorts(refnum, ports); - for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { - NotifyPortRegistation(ports[i], false); - } - - fGraphManager->GetOutputPorts(refnum, ports); - for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { - NotifyPortRegistation(ports[i], false); - } - - // Remove all ports + ReleaseRefnum(refnum); + + // Notiy unregister + jack_int_t ports[PORT_NUM_FOR_CLIENT]; + int i; + + fGraphManager->GetInputPorts(refnum, ports); + for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { + NotifyPortRegistation(ports[i], false); + } + + fGraphManager->GetOutputPorts(refnum, ports); + for (i = 0; (i < PORT_NUM_FOR_CLIENT) && (ports[i] != EMPTY) ; i++) { + NotifyPortRegistation(ports[i], false); + } + + // Remove all ports fGraphManager->RemoveAllPorts(refnum); // Wait until next cycle to be sure client is not used anymore @@ -586,51 +586,51 @@ int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wai } // Notify running clients - if (client->GetClientControl()) // When called in error cases, client may not be completely allocated - NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum); + if (client->GetClientControl()) // When called in error cases, client may not be completely allocated + NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum); // Cleanup... fSynchroTable[refnum]->Destroy(); - fEngineControl->ResetRollingUsecs(); + fEngineControl->ResetRollingUsecs(); return 0; } int JackEngine::ClientActivate(int refnum) { JackClientInterface* client = fClientTable[refnum]; - assert(fClientTable[refnum]); - - JackLog("JackEngine::ClientActivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName); - fGraphManager->Activate(refnum); - - // Wait for graph state change to be effective - if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) { - jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName); - return -1; - } else { - NotifyActivate(refnum); - return 0; - } + assert(fClientTable[refnum]); + + JackLog("JackEngine::ClientActivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName); + fGraphManager->Activate(refnum); + + // Wait for graph state change to be effective + if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) { + jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName); + return -1; + } else { + NotifyActivate(refnum); + return 0; + } } // May be called without client int JackEngine::ClientDeactivate(int refnum) { JackClientInterface* client = fClientTable[refnum]; - if (client == NULL) - return -1; - - JackLog("JackEngine::ClientDeactivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName); - fGraphManager->Deactivate(refnum); - fLastSwitchUsecs = 0; // Force switch to occur next cycle, even when called with "dead" clients - - // Wait for graph state change to be effective - if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) { - jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName); - return -1; - } else { - return 0; - } + if (client == NULL) + return -1; + + JackLog("JackEngine::ClientDeactivate ref = %ld name = %s\n", refnum, client->GetClientControl()->fName); + fGraphManager->Deactivate(refnum); + fLastSwitchUsecs = 0; // Force switch to occur next cycle, even when called with "dead" clients + + // Wait for graph state change to be effective + if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) { + jack_error("JackEngine::ClientDeactivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName); + return -1; + } else { + return 0; + } } //----------------- @@ -702,67 +702,67 @@ int JackEngine::PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst) " \"%s\" is not active", client->GetClientControl()->fName); return -1; } - - int res = fGraphManager->Connect(src, dst); - if (res == 0) { - NotifyPortConnect(src, dst, true); - NotifyPortConnect(dst, src, true); - } - return res; + + int res = fGraphManager->Connect(src, dst); + if (res == 0) { + NotifyPortConnect(src, dst, true); + NotifyPortConnect(dst, src, true); + } + return res; } int JackEngine::PortDisconnect(int refnum, const char* src, const char* dst) { JackLog("JackEngine::PortDisconnect src = %s dst = %s\n", src, dst); jack_port_id_t port_src, port_dst; - - if (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0) { - return -1; - } else if (fGraphManager->Disconnect(port_src, port_dst) == 0){ - NotifyPortConnect(port_src, port_dst, false); - NotifyPortConnect(port_dst, port_src, false); - return 0; - } else { - return -1; - } + + if (fGraphManager->CheckPorts(src, dst, &port_src, &port_dst) < 0) { + return -1; + } else if (fGraphManager->Disconnect(port_src, port_dst) == 0) { + NotifyPortConnect(port_src, port_dst, false); + NotifyPortConnect(port_dst, port_src, false); + return 0; + } else { + return -1; + } } int JackEngine::PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst) { JackLog("JackEngine::PortDisconnect src = %d dst = %d\n", src, dst); - + if (dst == ALL_PORTS) { - - jack_int_t connections[CONNECTION_NUM]; - fGraphManager->GetConnections(src, connections); - - // Notifications - JackPort* port = fGraphManager->GetPort(src); - if (port->GetFlags() & JackPortIsOutput) { - for (int i = 0; (i < CONNECTION_NUM) && (connections[i] != EMPTY); i++) { - JackLog("NotifyPortConnect src = %ld dst = %ld false\n", src, connections[i]); - NotifyPortConnect(src, connections[i], false); - NotifyPortConnect(connections[i], src, false); - } - } else { - for (int i = 0; (i < CONNECTION_NUM) && (connections[i] != EMPTY); i++) { - JackLog("NotifyPortConnect src = %ld dst = %ld false\n", connections[i], src); - NotifyPortConnect(connections[i], src, false); - NotifyPortConnect(connections[i], src, false); - } - } - - return fGraphManager->DisconnectAll(src); - } else if (fGraphManager->CheckPorts(src, dst) < 0) { - return -1; - } else if (fGraphManager->Disconnect(src, dst) == 0) { - // Notifications - NotifyPortConnect(src, dst, false); - NotifyPortConnect(dst, src, false); - return 0; + + jack_int_t connections[CONNECTION_NUM]; + fGraphManager->GetConnections(src, connections); + + // Notifications + JackPort* port = fGraphManager->GetPort(src); + if (port->GetFlags() & JackPortIsOutput) { + for (int i = 0; (i < CONNECTION_NUM) && (connections[i] != EMPTY); i++) { + JackLog("NotifyPortConnect src = %ld dst = %ld false\n", src, connections[i]); + NotifyPortConnect(src, connections[i], false); + NotifyPortConnect(connections[i], src, false); + } + } else { + for (int i = 0; (i < CONNECTION_NUM) && (connections[i] != EMPTY); i++) { + JackLog("NotifyPortConnect src = %ld dst = %ld false\n", connections[i], src); + NotifyPortConnect(connections[i], src, false); + NotifyPortConnect(connections[i], src, false); + } + } + + return fGraphManager->DisconnectAll(src); + } else if (fGraphManager->CheckPorts(src, dst) < 0) { + return -1; + } else if (fGraphManager->Disconnect(src, dst) == 0) { + // Notifications + NotifyPortConnect(src, dst, false); + NotifyPortConnect(dst, src, false); + return 0; } else { - return -1; - } + return -1; + } } diff --git a/common/JackEngine.h b/common/JackEngine.h index 00a0643e..9a90d0db 100644 --- a/common/JackEngine.h +++ b/common/JackEngine.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -52,22 +52,22 @@ class JackEngine int ClientCloseAux(int refnum, JackClientInterface* client, bool wait); void CheckXRun(jack_time_t callback_usecs); - + int NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum); void NotifyRemoveClient(const char* name, int refnum); - - void ProcessNext(jack_time_t callback_usecs); - void ProcessCurrent(jack_time_t callback_usecs); - - bool ClientCheckName(const char* name); - bool GenerateUniqueName(char* name); - - int AllocateRefnum(); - void ReleaseRefnum(int ref); - - void NotifyClient(int refnum, int event, int sync, int value1, int value2); + + void ProcessNext(jack_time_t callback_usecs); + void ProcessCurrent(jack_time_t callback_usecs); + + bool ClientCheckName(const char* name); + bool GenerateUniqueName(char* name); + + int AllocateRefnum(); + void ReleaseRefnum(int ref); + + void NotifyClient(int refnum, int event, int sync, int value1, int value2); void NotifyClients(int event, int sync, int value1, int value2); - + public: JackEngine(JackGraphManager* manager, JackSynchro** table, JackEngineControl* controler); @@ -75,22 +75,22 @@ class JackEngine int Open(); int Close(); - + // Client management - int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status); + int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status); int ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager); int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait); int ClientExternalClose(int refnum); int ClientInternalClose(int refnum, bool wait); - + int ClientActivate(int refnum); int ClientDeactivate(int refnum); - - // Internal client management - int GetInternalClientName(int int_ref, char* name_res); - int InternalClientHandle(const char* client_name, int* status, int* int_ref); - int InternalClientUnload(int refnum, int* status); + + // Internal client management + int GetInternalClientName(int int_ref, char* name_res); + int InternalClientHandle(const char* client_name, int* status, int* int_ref); + int InternalClientUnload(int refnum, int* status); // Port management int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, unsigned int* port_index); @@ -104,16 +104,16 @@ class JackEngine // Graph bool Process(jack_time_t callback_usecs); - - // Notifications - void NotifyXRun(jack_time_t callback_usecs); + + // Notifications + void NotifyXRun(jack_time_t callback_usecs); void NotifyXRun(int refnum); void NotifyGraphReorder(); void NotifyBufferSize(jack_nframes_t nframes); void NotifyFreewheel(bool onoff); void NotifyPortRegistation(jack_port_id_t port_index, bool onoff); - void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff); - void NotifyActivate(int refnum); + void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff); + void NotifyActivate(int refnum); }; diff --git a/common/JackEngineControl.cpp b/common/JackEngineControl.cpp index 83f7d0ff..225c2460 100644 --- a/common/JackEngineControl.cpp +++ b/common/JackEngineControl.cpp @@ -29,35 +29,35 @@ namespace Jack void JackEngineControl::CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs) { - // Transport - fTransport.CycleBegin(fSampleRate, callback_usecs); - - // Timer - fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs); - - // Timing - GetTimeMeasure(table, manager, callback_usecs); + // Transport + fTransport.CycleBegin(fSampleRate, callback_usecs); + + // Timer + fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs); + + // Timing + GetTimeMeasure(table, manager, callback_usecs); CalcCPULoad(table, manager); } void JackEngineControl::CycleEnd(JackClientInterface** table) { - fTransport.CycleEnd(table, fSampleRate, fBufferSize); + fTransport.CycleEnd(table, fSampleRate, fBufferSize); } void JackEngineControl::InitFrameTime() { - fFrameTimer.InitFrameTime(); + fFrameTimer.InitFrameTime(); } void JackEngineControl::ResetFrameTime(jack_time_t callback_usecs) { - fFrameTimer.ResetFrameTime(fSampleRate, callback_usecs, fPeriodUsecs); + fFrameTimer.ResetFrameTime(fSampleRate, callback_usecs, fPeriodUsecs); } void JackEngineControl::ReadFrameTime(JackTimer* timer) { - fFrameTimer.ReadFrameTime(timer); + fFrameTimer.ReadFrameTime(timer); } // Private @@ -76,8 +76,8 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table, JackGraphManage for (int i = REAL_REFNUM; i < CLIENT_NUM; i++) { JackClientInterface* client = table[i]; - JackClientTiming* timing = manager->GetClientTiming(i); - if (client && client->GetClientControl()->fActive && timing->fStatus == Finished) { + JackClientTiming* timing = manager->GetClientTiming(i); + if (client && client->GetClientControl()->fActive && timing->fStatus == Finished) { lastCycleEnd = MAX(lastCycleEnd, timing->fFinishedAt); } } @@ -131,9 +131,9 @@ void JackEngineControl::GetTimeMeasure(JackClientInterface** table, JackGraphMan for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = table[i]; - JackClientTiming* timing = manager->GetClientTiming(i); + JackClientTiming* timing = manager->GetClientTiming(i); if (client && client->GetClientControl()->fActive) { - fMeasure[pos].fClientTable[i].fRefNum = i; + fMeasure[pos].fClientTable[i].fRefNum = i; fMeasure[pos].fClientTable[i].fSignaledAt = timing->fSignaledAt; fMeasure[pos].fClientTable[i].fAwakeAt = timing->fAwakeAt; fMeasure[pos].fClientTable[i].fFinishedAt = timing->fFinishedAt; diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index b8eef4fe..99284399 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -42,7 +42,7 @@ class JackGraphManager; struct JackTimingMeasureClient { - int fRefNum; + int fRefNum; jack_time_t fSignaledAt; jack_time_t fAwakeAt; jack_time_t fFinishedAt; @@ -55,7 +55,7 @@ struct JackTimingMeasureClient struct JackTimingMeasure { - unsigned int fAudioCycle; + unsigned int fAudioCycle; jack_time_t fEngineTime; JackTimingMeasureClient fClientTable[CLIENT_NUM]; }; @@ -66,81 +66,81 @@ struct JackTimingMeasure struct JackEngineControl : public JackShmMem { - // Shared state + // Shared state jack_nframes_t fBufferSize; jack_nframes_t fSampleRate; - bool fSyncMode; - bool fTemporary; + bool fSyncMode; + bool fTemporary; jack_time_t fPeriodUsecs; jack_time_t fTimeOutUsecs; - bool fTimeOut; - bool fRealTime; - int fPriority; - char fServerName[64]; + bool fTimeOut; + bool fRealTime; + int fPriority; + char fServerName[64]; JackTransportEngine fTransport; bool fVerbose; - - // Timing - JackTimingMeasure fMeasure[TIME_POINTS]; - jack_time_t fLastTime; - jack_time_t fCurTime; - jack_time_t fProcessTime; - jack_time_t fLastProcessTime; - jack_time_t fSpareUsecs; - jack_time_t fMaxUsecs; - unsigned int fAudioCycle; - jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT]; - int fRollingClientUsecsCnt; - int fRollingClientUsecsIndex; - int fRollingInterval; - float fCPULoad; - - // Fos OSX thread + + // Timing + JackTimingMeasure fMeasure[TIME_POINTS]; + jack_time_t fLastTime; + jack_time_t fCurTime; + jack_time_t fProcessTime; + jack_time_t fLastProcessTime; + jack_time_t fSpareUsecs; + jack_time_t fMaxUsecs; + unsigned int fAudioCycle; + jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT]; + int fRollingClientUsecsCnt; + int fRollingClientUsecsIndex; + int fRollingInterval; + float fCPULoad; + + // Fos OSX thread UInt64 fPeriod; UInt64 fComputation; UInt64 fConstraint; - - // Timer - JackFrameTimer fFrameTimer; - - JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name) - { - fSyncMode = sync; - fTemporary = temporary; - fTimeOut = (timeout > 0); - fTimeOutUsecs = timeout * 1000; - fRealTime = rt; - fPriority = priority; - fVerbose = verbose; - fLastTime = 0; - fCurTime = 0; - fProcessTime = 0; - fLastProcessTime = 0; - fSpareUsecs = 0; - fMaxUsecs = 0; - fAudioCycle = 0; - ClearTimeMeasures(); - ResetRollingUsecs(); - snprintf(fServerName, sizeof(fServerName), server_name); - } - ~JackEngineControl() - {} - - // Cycle - void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs); - void CycleEnd(JackClientInterface** table); - - // Timer - void InitFrameTime(); - void ResetFrameTime(jack_time_t callback_usecs); - void ReadFrameTime(JackTimer* timer); - - // Private - void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager); - void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs); - void ClearTimeMeasures(); - void ResetRollingUsecs(); - + + // Timer + JackFrameTimer fFrameTimer; + + JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name) + { + fSyncMode = sync; + fTemporary = temporary; + fTimeOut = (timeout > 0); + fTimeOutUsecs = timeout * 1000; + fRealTime = rt; + fPriority = priority; + fVerbose = verbose; + fLastTime = 0; + fCurTime = 0; + fProcessTime = 0; + fLastProcessTime = 0; + fSpareUsecs = 0; + fMaxUsecs = 0; + fAudioCycle = 0; + ClearTimeMeasures(); + ResetRollingUsecs(); + snprintf(fServerName, sizeof(fServerName), server_name); + } + ~JackEngineControl() + {} + + // Cycle + void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs); + void CycleEnd(JackClientInterface** table); + + // Timer + void InitFrameTime(); + void ResetFrameTime(jack_time_t callback_usecs); + void ReadFrameTime(JackTimer* timer); + + // Private + void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager); + void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs); + void ClearTimeMeasures(); + void ResetRollingUsecs(); + }; } // end of namespace diff --git a/common/JackError.h b/common/JackError.h index fd9b7d9f..ee56e6d1 100644 --- a/common/JackError.h +++ b/common/JackError.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis -Copyright (C) 2004-2008 Grame +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 @@ -30,8 +30,8 @@ extern "C" #endif #ifdef WIN32 - #define vsnprintf _vsnprintf - #define snprintf _snprintf +#define vsnprintf _vsnprintf +#define snprintf _snprintf #endif EXPORT void jack_error(const char *fmt, ...); @@ -39,8 +39,8 @@ extern "C" EXPORT void JackLog(const char *fmt, ...); extern int jack_verbose; - - extern void (*jack_error_callback)(const char *desc); + + extern void (*jack_error_callback)(const char *desc); #ifdef __cplusplus } diff --git a/common/JackExports.h b/common/JackExports.h index 3e3edf6d..613a2b14 100644 --- a/common/JackExports.h +++ b/common/JackExports.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2005 Grame +Copyright (C) 2004-2005 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 @@ -21,9 +21,9 @@ This program is free software; you can redistribute it and/or modify #define __JackExports__ #ifdef WIN32 - #define EXPORT __declspec(dllexport) +#define EXPORT __declspec(dllexport) #else - #define EXPORT +#define EXPORT #endif #endif diff --git a/common/JackExternalClient.cpp b/common/JackExternalClient.cpp index c8122a88..01256f00 100644 --- a/common/JackExternalClient.cpp +++ b/common/JackExternalClient.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2001-2003 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 diff --git a/common/JackFifo.cpp b/common/JackFifo.cpp index 581d6e09..9b49f8ae 100755 --- a/common/JackFifo.cpp +++ b/common/JackFifo.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -37,12 +37,12 @@ bool JackFifo::Signal() { bool res; char c = 0; - - if (fFifo < 0) { - jack_error("JackFifo::Signal name = %s already desallocated!!", fName); - return false; - } - + + if (fFifo < 0) { + jack_error("JackFifo::Signal name = %s already desallocated!!", fName); + return false; + } + if (fFlush) return true; @@ -56,11 +56,11 @@ bool JackFifo::SignalAll() { bool res; char c = 0; - - if (fFifo < 0) { - jack_error("JackFifo::SignalAll name = %s already desallocated!!", fName); - return false; - } + + if (fFifo < 0) { + jack_error("JackFifo::SignalAll name = %s already desallocated!!", fName); + return false; + } if (fFlush) return true; @@ -75,11 +75,11 @@ bool JackFifo::Wait() { bool res; char c; - + if (fFifo < 0) { - jack_error("JackFifo::Wait name = %s already desallocated!!", fName); - return false; - } + jack_error("JackFifo::Wait name = %s already desallocated!!", fName); + return false; + } if ((res = (read(fFifo, &c, sizeof(c)) != sizeof(c)))) { jack_error("JackFifo::Wait name = %s err = %s", fName, strerror(errno)); @@ -93,7 +93,7 @@ bool JackFifo::TimedWait(long usec) { return Wait(); } -#else +#else // Does not work on OSX ?? bool JackFifo::TimedWait(long usec) { diff --git a/common/JackFifo.h b/common/JackFifo.h index 789f3e09..9d418978 100755 --- a/common/JackFifo.h +++ b/common/JackFifo.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackFrameTimer.cpp b/common/JackFrameTimer.cpp index fdd8d028..384c1665 100644 --- a/common/JackFrameTimer.cpp +++ b/common/JackFrameTimer.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify diff --git a/common/JackFrameTimer.h b/common/JackFrameTimer.h index a81058a7..01fd14c7 100644 --- a/common/JackFrameTimer.h +++ b/common/JackFrameTimer.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -47,11 +47,11 @@ struct JackTimer JackTimer(); ~JackTimer() {} - + }; /*! -\brief A class using the JackAtomicState to manage jack time. +\brief A class using the JackAtomicState to manage jack time. */ class JackFrameTimer : public JackAtomicState<JackTimer> @@ -60,7 +60,7 @@ class JackFrameTimer : public JackAtomicState<JackTimer> bool fFirstWakeUp; void IncFrameTimeAux(jack_nframes_t nframes, jack_time_t callback_usecs, jack_time_t period_usecs); - void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs); + void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs); public: diff --git a/common/JackFreewheelDriver.cpp b/common/JackFreewheelDriver.cpp index b98a1092..7c102c28 100644 --- a/common/JackFreewheelDriver.cpp +++ b/common/JackFreewheelDriver.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ JackEngine.cpp */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -34,7 +34,7 @@ int JackFreewheelDriver::Process() { if (fIsMaster) { JackLog("JackFreewheelDriver::Process master %lld\n", fEngineControl->fTimeOutUsecs); - fLastWaitUst = GetMicroSeconds(); + fLastWaitUst = GetMicroSeconds(); fEngine->Process(fLastWaitUst); fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, 10 * 1000000) < 0) // Wait for all clients to finish for 10 sec @@ -44,8 +44,8 @@ int JackFreewheelDriver::Process() if (fEngineControl->fSyncMode) { if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) { jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); - return -1; - } + return -1; + } } } return 0; diff --git a/common/JackFreewheelDriver.h b/common/JackFreewheelDriver.h index 04ef6b7a..da607600 100644 --- a/common/JackFreewheelDriver.h +++ b/common/JackFreewheelDriver.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -44,8 +44,8 @@ class JackFreewheelDriver : public JackDriver { return false; } - - int Process(); + + int Process(); }; } // end of namespace diff --git a/common/JackGlobals.cpp b/common/JackGlobals.cpp index 43371cad..0005e054 100644 --- a/common/JackGlobals.cpp +++ b/common/JackGlobals.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackGlobals.h b/common/JackGlobals.h index 0bfe6521..ab6d3f78 100644 --- a/common/JackGlobals.h +++ b/common/JackGlobals.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -38,7 +38,7 @@ class JackEngine; /*! \brief Factory description - + \todo possibly use in a dynamic way to test different communication/synchro implementations. */ @@ -230,18 +230,18 @@ class JackGlobals { JackLog("JackGlobals InitServer\n"); if (!fInstance) { - - #ifdef __APPLE__ + +#ifdef __APPLE__ fInstance = new JackFactoryOSXServer(); - #endif +#endif - #ifdef WIN32 - fInstance = new JackFactoryWindowsServer(); - #endif +#ifdef WIN32 + fInstance = new JackFactoryWindowsServer(); +#endif - #ifdef __linux__ - fInstance = new JackFactoryLinuxServer(); - #endif +#ifdef __linux__ + fInstance = new JackFactoryLinuxServer(); +#endif } } @@ -250,18 +250,18 @@ class JackGlobals { JackLog("JackGlobals InitClient\n"); if (!fInstance) { - - #ifdef __APPLE__ + +#ifdef __APPLE__ fInstance = new JackFactoryOSXClient(); - #endif +#endif - #ifdef WIN32 +#ifdef WIN32 fInstance = new JackFactoryWindowsClient(); - #endif +#endif - #ifdef __linux__ +#ifdef __linux__ fInstance = new JackFactoryLinuxClient(); - #endif +#endif } } diff --git a/common/JackGlobalsClient.cpp b/common/JackGlobalsClient.cpp index 7844ecdb..f72c7a51 100644 --- a/common/JackGlobalsClient.cpp +++ b/common/JackGlobalsClient.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -70,7 +70,7 @@ namespace Jack JackSynchro* JackFactoryWindowsClient::MakeSynchro() { - return new JackWinSemaphore(); + return new JackWinSemaphore(); } JackServerNotifyChannelInterface* JackFactoryWindowsClient::MakeServerNotifyChannel() @@ -221,7 +221,7 @@ JackThread* JackFactoryLinuxClient::MakeThread(JackRunnableInterface* runnable) #if defined(__APPLE__) -#if defined(MACH_RPC_MACH_SEMA) +#if defined(MACH_RPC_MACH_SEMA) // Mach RPC + Mach Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { @@ -259,7 +259,7 @@ JackThread* JackFactoryOSXClient::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(SOCKET_RPC_POSIX_SEMA) +#if defined(SOCKET_RPC_POSIX_SEMA) // Socket RPC + Posix Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { @@ -297,7 +297,7 @@ JackThread* JackFactoryOSXClient::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(SOCKET_RPC_FIFO_SEMA) +#if defined(SOCKET_RPC_FIFO_SEMA) // Socket RPC + Fifo Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { @@ -336,7 +336,7 @@ JackThread* JackFactoryOSXClient::MakeThread(JackRunnableInterface* runnable) #endif -#if defined(MACH_RPC_FIFO_SEMA) +#if defined(MACH_RPC_FIFO_SEMA) // Mach RPC + Fifo Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { @@ -374,7 +374,7 @@ JackThread* JackFactoryOSXClient::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(MACH_RPC_POSIX_SEMA) +#if defined(MACH_RPC_POSIX_SEMA) // Mach RPC + Posix Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { @@ -412,7 +412,7 @@ JackThread* JackFactoryOSXClient::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined SOCKET_RPC_MACH_SEMA +#if defined SOCKET_RPC_MACH_SEMA // Socket RPC + Mach Semaphore JackSynchro* JackFactoryOSXClient::MakeSynchro() { diff --git a/common/JackGlobalsServer.cpp b/common/JackGlobalsServer.cpp index b5bb46e0..b3ed5ebf 100644 --- a/common/JackGlobalsServer.cpp +++ b/common/JackGlobalsServer.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -17,7 +17,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -80,7 +80,7 @@ namespace Jack #ifdef WIN32 JackSynchro* JackFactoryWindowsServer::MakeSynchro() { - return new JackWinSemaphore(); + return new JackWinSemaphore(); } JackServerNotifyChannelInterface* JackFactoryWindowsServer::MakeServerNotifyChannel() @@ -231,7 +231,7 @@ JackThread* JackFactoryLinuxServer::MakeThread(JackRunnableInterface* runnable) #if defined(__APPLE__) -#if defined(MACH_RPC_MACH_SEMA) +#if defined(MACH_RPC_MACH_SEMA) // Mach RPC + Mach Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { @@ -269,7 +269,7 @@ JackThread* JackFactoryOSXServer::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(SOCKET_RPC_POSIX_SEMA) +#if defined(SOCKET_RPC_POSIX_SEMA) // Socket RPC + Posix Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { @@ -307,7 +307,7 @@ JackThread* JackFactoryOSXServer::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(SOCKET_RPC_FIFO_SEMA) +#if defined(SOCKET_RPC_FIFO_SEMA) // Socket RPC + Fifo Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { @@ -345,7 +345,7 @@ JackThread* JackFactoryOSXServer::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(MACH_RPC_FIFO_SEMA) +#if defined(MACH_RPC_FIFO_SEMA) // Mach RPC + Fifo Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { @@ -383,7 +383,7 @@ JackThread* JackFactoryOSXServer::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(MACH_RPC_POSIX_SEMA) +#if defined(MACH_RPC_POSIX_SEMA) // Mach RPC + Posix Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { @@ -421,7 +421,7 @@ JackThread* JackFactoryOSXServer::MakeThread(JackRunnableInterface* runnable) } #endif -#if defined(SOCKET_RPC_MACH_SEMA) +#if defined(SOCKET_RPC_MACH_SEMA) // Socket RPC + Mac Semaphore JackSynchro* JackFactoryOSXServer::MakeSynchro() { diff --git a/common/JackGraphManager.cpp b/common/JackGraphManager.cpp index 66d6a2eb..fdff5d58 100644 --- a/common/JackGraphManager.cpp +++ b/common/JackGraphManager.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis -Copyright (C) 2004-2008 Grame +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 @@ -113,7 +113,7 @@ int JackGraphManager::SuspendRefNum(JackClientControl* control, JackSynchro** ta JackClientTiming* JackGraphManager::GetClientTiming(int ref) { - return &fClientTiming[ref]; + return &fClientTiming[ref]; } // Server @@ -171,19 +171,19 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buff assert(manager->GetPort(port_index, 0) != port_index); // Check recursion return GetBuffer(manager->GetPort(port_index, 0), buffer_size); } else { // Multiple connections - + const jack_int_t* connections = manager->GetConnections(port_index); - void* buffers[CONNECTION_NUM]; - jack_port_id_t src_index; - int i; - - for (i = 0; (i < CONNECTION_NUM) && ((src_index = connections[i]) != EMPTY); i++) { + void* buffers[CONNECTION_NUM]; + jack_port_id_t src_index; + int i; + + for (i = 0; (i < CONNECTION_NUM) && ((src_index = connections[i]) != EMPTY); i++) { AssertPort(src_index); - buffers[i] = GetBuffer(src_index, buffer_size); + buffers[i] = GetBuffer(src_index, buffer_size); } - - JackPort* port = GetPort(port_index); - port->MixBuffers(buffers, i, buffer_size); + + JackPort* port = GetPort(port_index); + port->MixBuffers(buffers, i, buffer_size); return port->GetBuffer(); } } @@ -226,10 +226,10 @@ jack_nframes_t JackGraphManager::ComputeTotalLatencyAux(jack_port_id_t port_inde if (hop_count > 8) return GetPort(port_index)->GetLatency(); - + for (int i = 0; (i < CONNECTION_NUM) && ((dst_index = connections[i]) != EMPTY); i++) { if (src_port_index != dst_index) { - AssertPort(dst_index); + AssertPort(dst_index); JackPort* dst_port = GetPort(dst_index); jack_nframes_t this_latency = (dst_port->fFlags & JackPortIsTerminal) ? dst_port->GetLatency() @@ -237,7 +237,7 @@ jack_nframes_t JackGraphManager::ComputeTotalLatencyAux(jack_port_id_t port_inde max_latency = MAX(max_latency, this_latency); } } - + return max_latency + GetPort(port_index)->GetLatency(); } @@ -246,38 +246,38 @@ int JackGraphManager::ComputeTotalLatency(jack_port_id_t port_index) { UInt16 cur_index; UInt16 next_index; - JackPort* port = GetPort(port_index); + JackPort* port = GetPort(port_index); AssertPort(port_index); - + do { cur_index = GetCurrentIndex(); port->fTotalLatency = ComputeTotalLatencyAux(port_index, port_index, ReadCurrentState(), 0); next_index = GetCurrentIndex(); } while (cur_index != next_index); // Until a coherent state has been read - - JackLog("JackGraphManager::GetTotalLatency port_index = %ld total latency = %ld\n", port_index, port->fTotalLatency); - return 0; + + JackLog("JackGraphManager::GetTotalLatency port_index = %ld total latency = %ld\n", port_index, port->fTotalLatency); + return 0; } // Client int JackGraphManager::ComputeTotalLatencies() { - jack_port_id_t port_index; - for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) { + jack_port_id_t port_index; + for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) { JackPort* port = GetPort(port_index); - if (port->IsUsed()) - ComputeTotalLatency(port_index); - } - return 0; + if (port->IsUsed()) + ComputeTotalLatency(port_index); + } + return 0; } // Server void JackGraphManager::SetBufferSize(jack_nframes_t buffer_size) { - JackLock lock(this); + JackLock lock (this); JackLog("JackGraphManager::SetBufferSize size = %ld\n", (long int)buffer_size); - - jack_port_id_t port_index; + + jack_port_id_t port_index; for (port_index = FIRST_AVAILABLE_PORT; port_index < PORT_NUM; port_index++) { JackPort* port = GetPort(port_index); if (port->IsUsed()) @@ -296,7 +296,7 @@ jack_port_id_t JackGraphManager::AllocatePortAux(int refnum, const char* port_na if (!port->IsUsed()) { JackLog("JackGraphManager::AllocatePortAux port_index = %ld name = %s type = %s\n", port_index, port_name, port_type); if (!port->Allocate(refnum, port_name, port_type, flags)) - return NO_PORT; + return NO_PORT; break; } } @@ -307,7 +307,7 @@ jack_port_id_t JackGraphManager::AllocatePortAux(int refnum, const char* port_na // Server jack_port_id_t JackGraphManager::AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size) { - JackLock lock(this); + JackLock lock (this); JackConnectionManager* manager = WriteNextStateStart(); jack_port_id_t port_index = AllocatePortAux(refnum, port_name, port_type, flags); @@ -322,7 +322,7 @@ jack_port_id_t JackGraphManager::AllocatePort(int refnum, const char* port_name, } else { res = manager->AddInputPort(refnum, port_index); } - // Insertion failure + // Insertion failure if (res < 0) { port->Release(); port_index = NO_PORT; @@ -336,7 +336,7 @@ jack_port_id_t JackGraphManager::AllocatePort(int refnum, const char* port_name, // Server int JackGraphManager::ReleasePort(int refnum, jack_port_id_t port_index) { - JackLock lock(this); + JackLock lock (this); JackConnectionManager* manager = WriteNextStateStart(); JackPort* port = GetPort(port_index); int res; @@ -349,25 +349,25 @@ int JackGraphManager::ReleasePort(int refnum, jack_port_id_t port_index) res = manager->RemoveInputPort(refnum, port_index); } - port->Release(); + port->Release(); WriteNextStateStop(); return res; } void JackGraphManager::GetInputPorts(int refnum, jack_int_t* res) { - JackConnectionManager* manager = WriteNextStateStart(); - const jack_int_t* input = manager->GetInputPorts(refnum); - memcpy(res, input, sizeof(jack_int_t) * PORT_NUM_FOR_CLIENT); - WriteNextStateStop(); + JackConnectionManager* manager = WriteNextStateStart(); + const jack_int_t* input = manager->GetInputPorts(refnum); + memcpy(res, input, sizeof(jack_int_t) * PORT_NUM_FOR_CLIENT); + WriteNextStateStop(); } void JackGraphManager::GetOutputPorts(int refnum, jack_int_t* res) { - JackConnectionManager* manager = WriteNextStateStart(); - const jack_int_t* output = manager->GetOutputPorts(refnum); - memcpy(res, output, sizeof(jack_int_t) * PORT_NUM_FOR_CLIENT); - WriteNextStateStop(); + JackConnectionManager* manager = WriteNextStateStart(); + const jack_int_t* output = manager->GetOutputPorts(refnum); + memcpy(res, output, sizeof(jack_int_t) * PORT_NUM_FOR_CLIENT); + WriteNextStateStop(); } // Server @@ -420,7 +420,7 @@ void JackGraphManager::DisconnectAllInput(jack_port_id_t port_index) for (int i = 0; i < PORT_NUM; i++) { if (manager->IsConnected(i, port_index)) { - JackLog("JackGraphManager::Disconnect i = %ld port_index = %ld\n", i, port_index); + JackLog("JackGraphManager::Disconnect i = %ld port_index = %ld\n", i, port_index); Disconnect(i, port_index); } } @@ -434,8 +434,8 @@ void JackGraphManager::DisconnectAllOutput(jack_port_id_t port_index) JackConnectionManager* manager = WriteNextStateStart(); const jack_int_t* connections = manager->GetConnections(port_index); - while (connections[0] != EMPTY) { - Disconnect(port_index, connections[0]); // Warning : Disconnect shift port to left + while (connections[0] != EMPTY) { + Disconnect(port_index, connections[0]); // Warning : Disconnect shift port to left } WriteNextStateStop(); } @@ -447,9 +447,9 @@ int JackGraphManager::DisconnectAll(jack_port_id_t port_index) JackPort* port = GetPort(port_index); if (port->fFlags & JackPortIsOutput) { - DisconnectAllOutput(port_index); + DisconnectAllOutput(port_index); } else { - DisconnectAllInput(port_index); + DisconnectAllInput(port_index); } return 0; } @@ -457,16 +457,16 @@ int JackGraphManager::DisconnectAll(jack_port_id_t port_index) // Server void JackGraphManager::GetConnections(jack_port_id_t port_index, jack_int_t* res) { - JackConnectionManager* manager = WriteNextStateStart(); - const jack_int_t* connections = manager->GetConnections(port_index); - memcpy(res, connections, sizeof(jack_int_t) * CONNECTION_NUM); - WriteNextStateStop(); + JackConnectionManager* manager = WriteNextStateStart(); + const jack_int_t* connections = manager->GetConnections(port_index); + memcpy(res, connections, sizeof(jack_int_t) * CONNECTION_NUM); + WriteNextStateStop(); } // Server void JackGraphManager::Activate(int refnum) { - DirectConnect(FREEWHEEL_DRIVER_REFNUM, refnum); + DirectConnect(FREEWHEEL_DRIVER_REFNUM, refnum); DirectConnect(refnum, FREEWHEEL_DRIVER_REFNUM); } @@ -478,16 +478,16 @@ void JackGraphManager::Activate(int refnum) // Server void JackGraphManager::Deactivate(int refnum) { - DisconnectAllPorts(refnum); - - // Disconnect only when needed + DisconnectAllPorts(refnum); + + // Disconnect only when needed if (IsDirectConnection(refnum, FREEWHEEL_DRIVER_REFNUM)) { DirectDisconnect(refnum, FREEWHEEL_DRIVER_REFNUM); } else { JackLog("JackServer::Deactivate: client = %ld was not activated \n", refnum); } - // Disconnect only when needed + // Disconnect only when needed if (IsDirectConnection(FREEWHEEL_DRIVER_REFNUM, refnum)) { DirectDisconnect(FREEWHEEL_DRIVER_REFNUM, refnum); } else { @@ -532,9 +532,9 @@ int JackGraphManager::Connect(jack_port_id_t port_src, jack_port_id_t port_dst) goto end; } if (src->fTypeId != dst->fTypeId) { - jack_error("JackGraphManager::Connect: different port types: port_src = %ld port_dst = %ld", port_src, port_dst); - res = -1; - goto end; + jack_error("JackGraphManager::Connect: different port types: port_src = %ld port_dst = %ld", port_src, port_dst); + res = -1; + goto end; } if (manager->IsConnected(port_src, port_dst)) { jack_error("JackGraphManager::Connect already connected port_src = %ld port_dst = %ld", port_src, port_dst); @@ -615,7 +615,7 @@ end: int JackGraphManager::IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst) { JackConnectionManager* manager = ReadCurrentState(); - return manager->IsConnected(port_src, port_dst); + return manager->IsConnected(port_src, port_dst); } // Server @@ -722,11 +722,11 @@ const char** JackGraphManager::GetPortsAux(const char* port_name_pattern, const regcomp(&type_regex, type_name_pattern, REG_EXTENDED | REG_NOSUB); } - const char** matching_ports = (const char**)malloc(sizeof(char*) * PORT_NUM); + const char** matching_ports = (const char**)malloc(sizeof(char*) * PORT_NUM); for (int i = 0; i < PORT_NUM; i++) { matching = true; - JackPort* port = GetPort(i); + JackPort* port = GetPort(i); if (port->IsUsed()) { @@ -741,7 +741,7 @@ const char** JackGraphManager::GetPortsAux(const char* port_name_pattern, const matching = false; } } - if (matching && type_name_pattern && type_name_pattern[0]) { + if (matching && type_name_pattern && type_name_pattern[0]) { if (regexec(&type_regex, port->GetType(), 0, NULL, 0)) { matching = false; } @@ -786,8 +786,8 @@ const char** JackGraphManager::GetPorts(const char* port_name_pattern, const cha cur_index = GetCurrentIndex(); if (matching_ports) { free(matching_ports); - JackLog("JackGraphManager::GetPorts retry... \n"); - } + JackLog("JackGraphManager::GetPorts retry... \n"); + } matching_ports = GetPortsAux(port_name_pattern, type_name_pattern, flags); next_index = GetCurrentIndex(); } while (cur_index != next_index); // Until a coherent state has been read diff --git a/common/JackGraphManager.h b/common/JackGraphManager.h index 8842a901..d99c4cdf 100644 --- a/common/JackGraphManager.h +++ b/common/JackGraphManager.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis -Copyright (C) 2004-2008 Grame +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 @@ -40,9 +40,9 @@ class JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectio private: - JackPort fPortArray[PORT_NUM]; - JackClientTiming fClientTiming[CLIENT_NUM]; - + JackPort fPortArray[PORT_NUM]; + JackClientTiming fClientTiming[CLIENT_NUM]; + jack_port_id_t AllocatePortAux(int refnum, const char* port_name, const char* port_type, JackPortFlags flags); void GetConnectionsAux(JackConnectionManager* manager, const char** res, jack_port_id_t port_index); const char** GetPortsAux(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); @@ -60,60 +60,60 @@ class JackGraphManager : public JackShmMem, public JackAtomicState<JackConnectio void SetBufferSize(jack_nframes_t buffer_size); // Ports management - jack_port_id_t AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size); - int ReleasePort(int refnum, jack_port_id_t port_index); - void GetInputPorts(int refnum, jack_int_t* res); - void GetOutputPorts(int refnum, jack_int_t* res); - void RemoveAllPorts(int refnum); - void DisconnectAllPorts(int refnum); - - JackPort* GetPort(jack_port_id_t index); - jack_port_id_t GetPort(const char* name); - int ComputeTotalLatency(jack_port_id_t port_index); - int ComputeTotalLatencies(); - int RequestMonitor(jack_port_id_t port_index, bool onoff); + jack_port_id_t AllocatePort(int refnum, const char* port_name, const char* port_type, JackPortFlags flags, jack_nframes_t buffer_size); + int ReleasePort(int refnum, jack_port_id_t port_index); + void GetInputPorts(int refnum, jack_int_t* res); + void GetOutputPorts(int refnum, jack_int_t* res); + void RemoveAllPorts(int refnum); + void DisconnectAllPorts(int refnum); + + JackPort* GetPort(jack_port_id_t index); + jack_port_id_t GetPort(const char* name); + int ComputeTotalLatency(jack_port_id_t port_index); + int ComputeTotalLatencies(); + int RequestMonitor(jack_port_id_t port_index, bool onoff); // Connections management - int Connect(jack_port_id_t src_index, jack_port_id_t dst_index); - int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index); - int IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst); - int GetConnectionsNum(jack_port_id_t port_index); - - const char** GetConnections(jack_port_id_t port_index); - void GetConnections(jack_port_id_t port_index, jack_int_t* connections); // TODO - const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); - - int CheckPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index); - int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst); - - void DisconnectAllInput(jack_port_id_t port_index); - void DisconnectAllOutput(jack_port_id_t port_index); - int DisconnectAll(jack_port_id_t port_index); - - bool IsDirectConnection(int ref1, int ref2); - void DirectConnect(int ref1, int ref2); - void DirectDisconnect(int ref1, int ref2); - - void Activate(int refnum); - void Deactivate(int refnum); - - int GetInputRefNum(jack_port_id_t port_index); - int GetOutputRefNum(jack_port_id_t port_index); + int Connect(jack_port_id_t src_index, jack_port_id_t dst_index); + int Disconnect(jack_port_id_t src_index, jack_port_id_t dst_index); + int IsConnected(jack_port_id_t port_src, jack_port_id_t port_dst); + int GetConnectionsNum(jack_port_id_t port_index); + + const char** GetConnections(jack_port_id_t port_index); + void GetConnections(jack_port_id_t port_index, jack_int_t* connections); // TODO + const char** GetPorts(const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); + + int CheckPorts(const char* src, const char* dst, jack_port_id_t* src_index, jack_port_id_t* dst_index); + int CheckPorts(jack_port_id_t port_src, jack_port_id_t port_dst); + + void DisconnectAllInput(jack_port_id_t port_index); + void DisconnectAllOutput(jack_port_id_t port_index); + int DisconnectAll(jack_port_id_t port_index); + + bool IsDirectConnection(int ref1, int ref2); + void DirectConnect(int ref1, int ref2); + void DirectDisconnect(int ref1, int ref2); + + void Activate(int refnum); + void Deactivate(int refnum); + + int GetInputRefNum(jack_port_id_t port_index); + int GetOutputRefNum(jack_port_id_t port_index); // Buffer management - void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames); + void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames); // Activation management - void RunCurrentGraph(); - bool RunNextGraph(); - bool IsFinishedGraph(); - - void InitRefNum(int refnum); - int ResumeRefNum(JackClientControl* control, JackSynchro** table); - int SuspendRefNum(JackClientControl* control, JackSynchro** table, long usecs); - - JackClientTiming* GetClientTiming(int refnum); - + void RunCurrentGraph(); + bool RunNextGraph(); + bool IsFinishedGraph(); + + void InitRefNum(int refnum); + int ResumeRefNum(JackClientControl* control, JackSynchro** table); + int SuspendRefNum(JackClientControl* control, JackSynchro** table, long usecs); + + JackClientTiming* GetClientTiming(int refnum); + void Save(JackConnectionManager* dst); void Restore(JackConnectionManager* src); diff --git a/common/JackInternalClient.cpp b/common/JackInternalClient.cpp index 2cb9a8a9..6ba6bf0d 100644 --- a/common/JackInternalClient.cpp +++ b/common/JackInternalClient.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -68,22 +68,22 @@ JackInternalClient::~JackInternalClient() int JackInternalClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) { int result; - char name_res[JACK_CLIENT_NAME_SIZE]; + char name_res[JACK_CLIENT_NAME_SIZE]; JackLog("JackInternalClient::Open name = %s\n", name); - - snprintf(fServerName, sizeof(fServerName), server_name); - - fChannel->ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); + + snprintf(fServerName, sizeof(fServerName), server_name); + + fChannel->ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); if (result < 0) { - int status1 = *status; + int status1 = *status; if (status1 & JackVersionError) - jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); + jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); else - jack_error("Client name = %s conflits with another running client", name); + jack_error("Client name = %s conflits with another running client", name); goto error; } - - strcpy(fClientControl->fName, name_res); + + strcpy(fClientControl->fName, name_res); // Require new client fChannel->ClientOpen(name_res, &fClientControl->fRefNum, &fEngineControl, &fGraphManager, this, &result); @@ -119,49 +119,49 @@ JackClientControl* JackInternalClient::GetClientControl() const } JackLoadableInternalClient::JackLoadableInternalClient(JackServer* server, JackSynchro** table, const char* so_name, const char* object_data) - :JackInternalClient(server, table) + : JackInternalClient(server, table) { - char path_to_so[PATH_MAX + 1]; - //snprintf(path_to_so, sizeof(path_to_so), ADDON_DIR "/%s.so", so_name); - snprintf(path_to_so, sizeof(path_to_so), so_name); - snprintf(fObjectData, JACK_LOAD_INIT_LIMIT, object_data); - fHandle = LoadJackModule(path_to_so); - - JackLog("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s\n", path_to_so); - - if (fHandle == 0) { - jack_error("error loading %s", so_name); - throw -1; - } - - fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize"); - if (!fInitialize) { - UnloadJackModule(fHandle); - jack_error("symbol jack_initialize cannot be found in %s", so_name); - throw -1; - } - - fFinish = (FinishCallback)GetJackProc(fHandle, "jack_finish"); - if (!fFinish) { - UnloadJackModule(fHandle); - jack_error("symbol jack_finish cannot be found in %s", so_name); - throw -1; - } + char path_to_so[PATH_MAX + 1]; + //snprintf(path_to_so, sizeof(path_to_so), ADDON_DIR "/%s.so", so_name); + snprintf(path_to_so, sizeof(path_to_so), so_name); + snprintf(fObjectData, JACK_LOAD_INIT_LIMIT, object_data); + fHandle = LoadJackModule(path_to_so); + + JackLog("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s\n", path_to_so); + + if (fHandle == 0) { + jack_error("error loading %s", so_name); + throw - 1; + } + + fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize"); + if (!fInitialize) { + UnloadJackModule(fHandle); + jack_error("symbol jack_initialize cannot be found in %s", so_name); + throw - 1; + } + + fFinish = (FinishCallback)GetJackProc(fHandle, "jack_finish"); + if (!fFinish) { + UnloadJackModule(fHandle); + jack_error("symbol jack_finish cannot be found in %s", so_name); + throw - 1; + } } JackLoadableInternalClient::~JackLoadableInternalClient() { - if (fFinish) - fFinish(fProcessArg); - UnloadJackModule(fHandle); + if (fFinish) + fFinish(fProcessArg); + UnloadJackModule(fHandle); } int JackLoadableInternalClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) { - int res = JackInternalClient::Open(server_name, name, options, status); - if (res == 0) - fInitialize((jack_client_t*)this, fObjectData); - return res; + int res = JackInternalClient::Open(server_name, name, options, status); + if (res == 0) + fInitialize((jack_client_t*)this, fObjectData); + return res; } } // end of namespace diff --git a/common/JackInternalClient.h b/common/JackInternalClient.h index c02a4cae..443f7357 100644 --- a/common/JackInternalClient.h +++ b/common/JackInternalClient.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -62,15 +62,15 @@ class JackInternalClient : public JackClient #ifdef WIN32 #include <windows.h> -#define HANDLE HINSTANCE +#define HANDLE HINSTANCE #define LoadJackModule(name) LoadLibrary((name)); -#define UnloadJackModule(handle) FreeLibrary((handle)); +#define UnloadJackModule(handle) FreeLibrary((handle)); #define GetJackProc(handle, name) GetProcAddress((handle), (name)); #else #include <dlfcn.h> -#define HANDLE void* +#define HANDLE void* #define LoadJackModule(name) dlopen((name), RTLD_NOW | RTLD_LOCAL); #define UnloadJackModule(handle) dlclose((handle)); #define GetJackProc(handle, name) dlsym((handle), (name)); @@ -84,18 +84,18 @@ class JackLoadableInternalClient : public JackInternalClient { private: - - HANDLE fHandle; - InitializeCallback fInitialize; - FinishCallback fFinish; - char fObjectData[JACK_LOAD_INIT_LIMIT]; + + HANDLE fHandle; + InitializeCallback fInitialize; + FinishCallback fFinish; + char fObjectData[JACK_LOAD_INIT_LIMIT]; public: JackLoadableInternalClient(JackServer* server, JackSynchro** table, const char* so_name, const char* object_data); - virtual ~JackLoadableInternalClient(); - - int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status); + virtual ~JackLoadableInternalClient(); + + int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status); }; diff --git a/common/JackInternalClientChannel.h b/common/JackInternalClientChannel.h index e96ec000..d57ff5a6 100644 --- a/common/JackInternalClientChannel.h +++ b/common/JackInternalClientChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -43,15 +43,15 @@ class JackInternalClientChannel : public JackClientChannelInterface {} virtual ~JackInternalClientChannel() {} - - // Open the Server/Client connection + + // Open the Server/Client connection virtual int Open(const char* name, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) { return 0; } - void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) - { + void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) + { *result = fEngine->ClientCheck(name, name_res, protocol, options, status); } void ClientOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, int* result) @@ -62,14 +62,14 @@ class JackInternalClientChannel : public JackClientChannelInterface { *result = fEngine->ClientInternalClose(refnum, true); } - + void ClientActivate(int refnum, int* result) { - *result = fEngine->ClientActivate(refnum); + *result = fEngine->ClientActivate(refnum); } void ClientDeactivate(int refnum, int* result) { - *result = fEngine->ClientDeactivate(refnum); + *result = fEngine->ClientDeactivate(refnum); } void PortRegister(int refnum, const char* name, const char* type, unsigned int flags, unsigned int buffer_size, unsigned int* port_index, int* result) @@ -108,7 +108,7 @@ class JackInternalClientChannel : public JackClientChannelInterface *result = fServer->SetFreewheel(onoff); } - void ReleaseTimebase(int refnum, int* result) + void ReleaseTimebase(int refnum, int* result) { *result = fServer->ReleaseTimebase(refnum); } diff --git a/common/JackLibAPI.cpp b/common/JackLibAPI.cpp index 8176dbc3..359710fe 100644 --- a/common/JackLibAPI.cpp +++ b/common/JackLibAPI.cpp @@ -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. */ @@ -29,9 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. using namespace Jack; #ifdef WIN32 - #define EXPORT __declspec(dllexport) +#define EXPORT __declspec(dllexport) #else - #define EXPORT +#define EXPORT #endif #ifdef __cplusplus @@ -56,10 +56,10 @@ EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options va_list ap; /* variable argument pointer */ jack_varargs_t va; /* variable arguments */ jack_status_t my_status; - JackClient* client; - char client_name[JACK_CLIENT_NAME_SIZE]; - - JackTools::RewriteName(ext_client_name, client_name); + JackClient* client; + char client_name[JACK_CLIENT_NAME_SIZE]; + + JackTools::RewriteName(ext_client_name, client_name); if (status == NULL) /* no status from caller? */ status = &my_status; /* use local status word */ @@ -76,8 +76,8 @@ EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options va_start(ap, status); jack_varargs_parse(options, ap, &va); va_end(ap); - - + + JackLog("jack_client_open %s\n", client_name); if (client_name == NULL) { jack_error("jack_client_new called with a NULL client_name"); @@ -85,30 +85,30 @@ EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options } JackLibGlobals::Init(); // jack library initialisation - + #ifndef WIN32 - if (try_start_server(&va, options, status)) { - jack_error("jack server is not running or cannot be started"); - JackLibGlobals::Destroy(); // jack library destruction - return 0; - } -#endif + if (try_start_server(&va, options, status)) { + jack_error("jack server is not running or cannot be started"); + JackLibGlobals::Destroy(); // jack library destruction + return 0; + } +#endif #ifndef WIN32 - char* jack_debug = getenv("JACK_CLIENT_DEBUG"); - if (jack_debug && strcmp(jack_debug, "on") == 0) - client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode - else - client = new JackLibClient(GetSynchroTable()); + char* jack_debug = getenv("JACK_CLIENT_DEBUG"); + if (jack_debug && strcmp(jack_debug, "on") == 0) + client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode + else + client = new JackLibClient(GetSynchroTable()); #else - client = new JackLibClient(GetSynchroTable()); -#endif + client = new JackLibClient(GetSynchroTable()); +#endif int res = client->Open(va.server_name, client_name, options, status); if (res < 0) { delete client; JackLibGlobals::Destroy(); // jack library destruction - int my_status1 = (JackFailure|JackServerError); + int my_status1 = (JackFailure | JackServerError); *status = (jack_status_t)my_status1; return NULL; } else { @@ -124,12 +124,12 @@ EXPORT int jack_client_close(jack_client_t* ext_client) jack_error("jack_client_close called with a NULL client"); return -1; } else { - int res = client->Close(); - delete client; - JackLog("jack_client_close OK\n"); - JackLibGlobals::Destroy(); // jack library destruction - return res; - } + int res = client->Close(); + delete client; + JackLog("jack_client_close OK\n"); + JackLibGlobals::Destroy(); // jack library destruction + return res; + } } diff --git a/common/JackLibClient.cpp b/common/JackLibClient.cpp index 3ec3160c..22e2f261 100644 --- a/common/JackLibClient.cpp +++ b/common/JackLibClient.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -29,18 +29,18 @@ namespace Jack // Used for external C API (JackAPI.cpp) JackGraphManager* GetGraphManager() { - if (JackLibGlobals::fGlobals) - return JackLibGlobals::fGlobals->fGraphManager; - else - return NULL; + if (JackLibGlobals::fGlobals) + return JackLibGlobals::fGlobals->fGraphManager; + else + return NULL; } JackEngineControl* GetEngineControl() { - if (JackLibGlobals::fGlobals) - return JackLibGlobals::fGlobals->fEngineControl; - else - return NULL; + if (JackLibGlobals::fGlobals) + return JackLibGlobals::fGlobals->fEngineControl; + else + return NULL; } JackSynchro** GetSynchroTable() @@ -68,11 +68,11 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_ { int shared_engine, shared_client, shared_graph, result; JackLog("JackLibClient::Open %s\n", name); - - snprintf(fServerName, sizeof(fServerName), server_name); - + + snprintf(fServerName, sizeof(fServerName), server_name); + // Open server/client channel - char name_res[JACK_CLIENT_NAME_SIZE]; + char name_res[JACK_CLIENT_NAME_SIZE]; if (fChannel->Open(server_name, name, name_res, this, options, status) < 0) { jack_error("Cannot connect to the server"); goto error; @@ -93,28 +93,28 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_ try { // Map shared memory segments - JackLibGlobals::fGlobals->fEngineControl.SetShmIndex(shared_engine, fServerName); + JackLibGlobals::fGlobals->fEngineControl.SetShmIndex(shared_engine, fServerName); JackLibGlobals::fGlobals->fGraphManager.SetShmIndex(shared_graph, fServerName); fClientControl.SetShmIndex(shared_client, fServerName); jack_verbose = GetEngineControl()->fVerbose; - } catch (int n) { + } catch (int n) { jack_error("Map shared memory segments exception %d", n); goto error; } SetupDriverSync(false); -/* TODO : solve WIN32 thread Kill issue -#ifndef WIN32 - // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process - if (!fSynchroTable[fClientControl->fRefNum]->Connect(name)) { - jack_error("Cannot ConnectSemaphore %s client", name); - goto error; - } -#endif -*/ - // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process - if (!fSynchroTable[fClientControl->fRefNum]->Connect(name_res, fServerName)) { + /* TODO : solve WIN32 thread Kill issue + #ifndef WIN32 + // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process + if (!fSynchroTable[fClientControl->fRefNum]->Connect(name)) { + jack_error("Cannot ConnectSemaphore %s client", name); + goto error; + } + #endif + */ + // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process + if (!fSynchroTable[fClientControl->fRefNum]->Connect(name_res, fServerName)) { jack_error("Cannot ConnectSemaphore %s client", name_res); goto error; } @@ -140,7 +140,7 @@ int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int case kAddClient: JackLog("JackClient::AddClient name = %s, ref = %ld \n", name, refnum); - // the synchro must be usable in I/O mode when several clients live in the same process + // the synchro must be usable in I/O mode when several clients live in the same process res = fSynchroTable[refnum]->Connect(name, fServerName) ? 0 : -1; break; @@ -149,7 +149,7 @@ int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int if (strcmp(GetClientControl()->fName, name) != 0) res = fSynchroTable[refnum]->Disconnect() ? 0 : -1; break; - } + } return res; } diff --git a/common/JackLibClient.h b/common/JackLibClient.h index 6a4c32c2..fc9f1424 100644 --- a/common/JackLibClient.h +++ b/common/JackLibClient.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackLibGlobals.h b/common/JackLibGlobals.h index 8233bc0b..f237f912 100644 --- a/common/JackLibGlobals.h +++ b/common/JackLibGlobals.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2005 Grame +Copyright (C) 2005 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 @@ -49,7 +49,7 @@ struct JackLibGlobals std::map<mach_port_t, JackClient*> fClientTable; /*! Client table */ #endif - static int fClientCount; + static int fClientCount; static JackLibGlobals* fGlobals; JackLibGlobals() @@ -77,7 +77,7 @@ struct JackLibGlobals JackGlobals::InitClient(); InitTime(); fGlobals = new JackLibGlobals(); - } + } } static void Destroy() @@ -89,13 +89,13 @@ struct JackLibGlobals JackGlobals::Destroy(); } } - - static void CheckContext() - { - if (!(fClientCount > 0 && fGlobals)) { - jack_error("Error !!! : client accessing an already desallocated library context"); - } - } + + static void CheckContext() + { + if (!(fClientCount > 0 && fGlobals)) { + jack_error("Error !!! : client accessing an already desallocated library context"); + } + } }; diff --git a/common/JackLoopbackDriver.cpp b/common/JackLoopbackDriver.cpp index b42dca00..048988e6 100644 --- a/common/JackLoopbackDriver.cpp +++ b/common/JackLoopbackDriver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -38,14 +38,14 @@ int JackLoopbackDriver::Process() // Loopback copy for (int i = 0; i < fCaptureChannels; i++) { memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(float) * fEngineControl->fBufferSize); - } + } fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients if (fEngineControl->fSyncMode) { if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) { jack_error("JackLoopbackDriver::ProcessSync SuspendRefNum error"); - return -1; - } + return -1; + } } return 0; } diff --git a/common/JackLoopbackDriver.h b/common/JackLoopbackDriver.h index ec57f163..aafd0d49 100644 --- a/common/JackLoopbackDriver.h +++ b/common/JackLoopbackDriver.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -41,7 +41,7 @@ class JackLoopbackDriver : public JackAudioDriver virtual ~JackLoopbackDriver() {} - int Process(); + int Process(); }; } // end of namespace diff --git a/common/JackMidiAPI.cpp b/common/JackMidiAPI.cpp index 27b04baa..5356b2b7 100644 --- a/common/JackMidiAPI.cpp +++ b/common/JackMidiAPI.cpp @@ -28,23 +28,24 @@ This program is free software; you can redistribute it and/or modify #endif #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif EXPORT jack_nframes_t jack_midi_get_event_count(void* port_buffer); EXPORT int jack_midi_event_get(jack_midi_event_t* event, - void* port_buffer, jack_nframes_t event_index); + void* port_buffer, jack_nframes_t event_index); EXPORT void jack_midi_clear_buffer(void* port_buffer); EXPORT size_t jack_midi_max_event_size(void* port_buffer); EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, - jack_nframes_t time, size_t data_size); + jack_nframes_t time, size_t data_size); EXPORT int jack_midi_event_write(void* port_buffer, - jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); + jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); EXPORT jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer); @@ -108,7 +109,7 @@ jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time EXPORT int jack_midi_event_write(void* port_buffer, - jack_nframes_t time, const jack_midi_data_t* data, size_t data_size) + jack_nframes_t time, const jack_midi_data_t* data, size_t data_size) { JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; if (!buf && !buf->IsValid()) @@ -127,6 +128,6 @@ jack_nframes_t jack_midi_get_lost_event_count(void* port_buffer) { JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; if (buf && buf->IsValid()) - return buf->lost_events; + return buf->lost_events; return 0; } diff --git a/common/JackMidiPort.cpp b/common/JackMidiPort.cpp index e0d35624..56abe9c7 100644 --- a/common/JackMidiPort.cpp +++ b/common/JackMidiPort.cpp @@ -131,10 +131,11 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count mix->lost_events += event_count - events_done; } -const JackPortType gMidiPortType = { - JACK_DEFAULT_MIDI_TYPE, - MidiBufferInit, - MidiBufferMixdown -}; +const JackPortType gMidiPortType = + { + JACK_DEFAULT_MIDI_TYPE, + MidiBufferInit, + MidiBufferMixdown + }; } // namespace Jack diff --git a/common/JackMidiPort.h b/common/JackMidiPort.h index bb30d7cc..f2daf72f 100644 --- a/common/JackMidiPort.h +++ b/common/JackMidiPort.h @@ -31,9 +31,9 @@ typedef unsigned char jack_midi_data_t; /** A Jack MIDI event. */ struct jack_midi_event_t { - jack_nframes_t time; /**< Sample index at which event is valid */ - size_t size; /**< Number of bytes of data in \a buffer */ - jack_midi_data_t *buffer; /**< Raw MIDI data */ + jack_nframes_t time; /**< Sample index at which event is valid */ + size_t size; /**< Number of bytes of data in \a buffer */ + jack_midi_data_t *buffer; /**< Raw MIDI data */ }; /** A Jack MIDI port type. */ @@ -84,7 +84,10 @@ struct JackMidiBuffer JackMidiEvent events[0]; - int IsValid() const { return magic == MAGIC; } + int IsValid() const + { + return magic == MAGIC; + } void Reset(jack_nframes_t nframes); jack_shmsize_t MaxEventSize() const; diff --git a/common/JackMutex.h b/common/JackMutex.h index 5f0c9ec0..5b6bc562 100644 --- a/common/JackMutex.h +++ b/common/JackMutex.h @@ -1,23 +1,23 @@ - /* +/* - Copyright (C) 2006 Grame + Copyright (C) 2006 Grame - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This library 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 - Lesser General Public License for more details. + This library 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 + Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France - grame@grame.fr + Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France + grame@grame.fr */ @@ -32,117 +32,119 @@ #include<assert.h> -namespace Jack +namespace Jack { -class JackMutex +class JackMutex { - - private: - - #ifdef WIN32 - HANDLE fMutex; - #else - pthread_mutex_t fMutex; - #endif - - public: - - #ifdef WIN32 - - JackMutex() - { - fMutex = CreateMutex(0, FALSE, 0); - } - virtual ~JackMutex() - { - CloseHandle(fMutex); - } - - void Lock() - { - DWORD dwWaitResult = WaitForSingleObject(fMutex, INFINITE); - } - - void Unlock() - { - ReleaseMutex(fMutex); - } - - #else - - JackMutex() - { - // Use recursive mutex - pthread_mutexattr_t mutex_attr; - assert(pthread_mutexattr_init(&mutex_attr) == 0); - assert(pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE) == 0); - assert(pthread_mutex_init(&fMutex, &mutex_attr) == 0); - } - virtual ~JackMutex() - { - pthread_mutex_destroy(&fMutex); - } - - void Lock() - { - pthread_mutex_lock(&fMutex); - } - - void Unlock() - { - pthread_mutex_unlock(&fMutex); - } - - #endif + + private: + +#ifdef WIN32 + HANDLE fMutex; +#else + pthread_mutex_t fMutex; +#endif + + public: + +#ifdef WIN32 + + JackMutex() + { + fMutex = CreateMutex(0, FALSE, 0); + } + virtual ~JackMutex() + { + CloseHandle(fMutex); + } + + void Lock() + { + DWORD dwWaitResult = WaitForSingleObject(fMutex, INFINITE); + } + + void Unlock() + { + ReleaseMutex(fMutex); + } + +#else + + JackMutex() + { + // Use recursive mutex + pthread_mutexattr_t mutex_attr; + assert(pthread_mutexattr_init(&mutex_attr) == 0); + assert(pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE) == 0); + assert(pthread_mutex_init(&fMutex, &mutex_attr) == 0); + } + virtual ~JackMutex() + { + pthread_mutex_destroy(&fMutex); + } + + void Lock() + { + pthread_mutex_lock(&fMutex); + } + + void Unlock() + { + pthread_mutex_unlock(&fMutex); + } + +#endif }; class JackLockAble { - private: + private: + + JackMutex fMutex; - JackMutex fMutex; + public: - public: + JackLockAble() + {} + virtual ~JackLockAble() + {} - JackLockAble() {} - virtual ~JackLockAble() {} + void Lock() + { + fMutex.Lock(); + } - void Lock() - { - fMutex.Lock(); - } + void Unlock() + { + fMutex.Unlock(); + } - void Unlock() - { - fMutex.Unlock(); - } - }; class JackLock { - private: - - JackLockAble* fObj; - - public: - - JackLock(JackLockAble* obj):fObj(obj) - { - fObj->Lock(); - } - - JackLock(const JackLockAble* obj):fObj((JackLockAble*)obj) - { - fObj->Lock(); - } - - virtual ~JackLock() - { - fObj->Unlock(); - } + private: + + JackLockAble* fObj; + + public: + + JackLock(JackLockAble* obj): fObj(obj) + { + fObj->Lock(); + } + + JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj) + { + fObj->Lock(); + } + + virtual ~JackLock() + { + fObj->Unlock(); + } }; diff --git a/common/JackNotification.h b/common/JackNotification.h index 66f4e81c..fc93cbdb 100644 --- a/common/JackNotification.h +++ b/common/JackNotification.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2007 Grame +Copyright (C) 2007 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 @@ -22,22 +22,22 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. namespace Jack { - enum NotificationType { - kAddClient = 0, - kRemoveClient = 1, - kActivateClient = 2, - kXRunCallback = 3, - kGraphOrderCallback = 4, - kBufferSizeCallback = 5, - kStartFreewheelCallback = 6, - kStopFreewheelCallback = 7, - kPortRegistrationOnCallback = 8, - kPortRegistrationOffCallback = 9, - kPortConnectCallback = 10, - kPortDisconnectCallback = 11, - kDeadClient = 12, - kMaxNotification - }; +enum NotificationType { + kAddClient = 0, + kRemoveClient = 1, + kActivateClient = 2, + kXRunCallback = 3, + kGraphOrderCallback = 4, + kBufferSizeCallback = 5, + kStartFreewheelCallback = 6, + kStopFreewheelCallback = 7, + kPortRegistrationOnCallback = 8, + kPortRegistrationOffCallback = 9, + kPortConnectCallback = 10, + kPortDisconnectCallback = 11, + kDeadClient = 12, + kMaxNotification +}; } // end of namespace diff --git a/common/JackPort.cpp b/common/JackPort.cpp index fb8888d7..43f2290b 100644 --- a/common/JackPort.cpp +++ b/common/JackPort.cpp @@ -39,14 +39,14 @@ bool JackPort::Allocate(int refnum, const char* port_name, const char* port_type { int id = GetPortTypeId(port_type); if (id < 0) - return false; + return false; fTypeId = id; fFlags = flags; fRefNum = refnum; strcpy(fName, port_name); fInUse = true; fLatency = 0; - fTotalLatency = 0; + fTotalLatency = 0; fTied = NO_PORT; // DB: At this point we do not know current buffer size in frames, // but every time buffer will be returned to any user, @@ -64,10 +64,10 @@ void JackPort::Release() fRefNum = -1; fInUse = false; fLatency = 0; - fTotalLatency = 0; + fTotalLatency = 0; fTied = NO_PORT; - fAlias1[0] = '\0'; - fAlias2[0] = '\0'; + fAlias1[0] = '\0'; + fAlias2[0] = '\0'; } bool JackPort::IsUsed() const @@ -170,7 +170,7 @@ const char* JackPort::GetShortName() const { /* we know there is always a colon, because we put it there ... - */ + */ return strchr(fName, ':') + 1; } @@ -195,66 +195,66 @@ int JackPort::SetName(const char* new_name) bool JackPort::NameEquals(const char* target) { - char buf[JACK_PORT_NAME_SIZE + 1]; - - /* this nasty, nasty kludge is here because between 0.109.0 and 0.109.1, - the ALSA audio backend had the name "ALSA", whereas as before and - after it, it was called "alsa_pcm". this stops breakage for - any setups that have saved "alsa_pcm" or "ALSA" in their connection - state. - */ - - if (strncmp(target, "ALSA:capture", 12) == 0 || strncmp(target, "ALSA:playback", 13) == 0) { - snprintf(buf, sizeof(buf), "alsa_pcm%s", target + 4); - target = buf; - } - - return (strcmp(fName, target) == 0 - || strcmp(fAlias1, target) == 0 - || strcmp(fAlias2, target) == 0); + char buf[JACK_PORT_NAME_SIZE + 1]; + + /* this nasty, nasty kludge is here because between 0.109.0 and 0.109.1, + the ALSA audio backend had the name "ALSA", whereas as before and + after it, it was called "alsa_pcm". this stops breakage for + any setups that have saved "alsa_pcm" or "ALSA" in their connection + state. + */ + + if (strncmp(target, "ALSA:capture", 12) == 0 || strncmp(target, "ALSA:playback", 13) == 0) { + snprintf(buf, sizeof(buf), "alsa_pcm%s", target + 4); + target = buf; + } + + return (strcmp(fName, target) == 0 + || strcmp(fAlias1, target) == 0 + || strcmp(fAlias2, target) == 0); } int JackPort::GetAliases(char* const aliases[2]) { - int cnt = 0; - - if (fAlias1[0] != '\0') { - snprintf(aliases[0], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias1); - cnt++; - } - - if (fAlias2[0] != '\0') { - snprintf(aliases[1], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias2); - cnt++; - } - - return cnt; + int cnt = 0; + + if (fAlias1[0] != '\0') { + snprintf(aliases[0], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias1); + cnt++; + } + + if (fAlias2[0] != '\0') { + snprintf(aliases[1], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias2); + cnt++; + } + + return cnt; } int JackPort::SetAlias(const char* alias) { - if (fAlias1[0] == '\0') { - snprintf(fAlias1, sizeof(fAlias1), "%s", alias); - } else if (fAlias2[0] == '\0') { - snprintf(fAlias2, sizeof(fAlias2), "%s", alias); - } else { - return -1; - } - - return 0; + if (fAlias1[0] == '\0') { + snprintf(fAlias1, sizeof(fAlias1), "%s", alias); + } else if (fAlias2[0] == '\0') { + snprintf(fAlias2, sizeof(fAlias2), "%s", alias); + } else { + return -1; + } + + return 0; } int JackPort::UnsetAlias(const char* alias) { - if (strcmp(fAlias1, alias) == 0) { - fAlias1[0] = '\0'; - } else if (strcmp(fAlias2, alias) == 0) { - fAlias2[0] = '\0'; - } else { - return -1; - } - - return 0; + if (strcmp(fAlias1, alias) == 0) { + fAlias1[0] = '\0'; + } else if (strcmp(fAlias2, alias) == 0) { + fAlias2[0] = '\0'; + } else { + return -1; + } + + return 0; } void JackPort::ClearBuffer(jack_nframes_t frames) diff --git a/common/JackPort.h b/common/JackPort.h index e92a0afd..bcd7258e 100644 --- a/common/JackPort.h +++ b/common/JackPort.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis -Copyright (C) 2004-2008 Grame +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 @@ -31,7 +31,7 @@ namespace Jack #define NO_PORT 0xFFFE /*! -\brief Base class for port. +\brief Base class for port. */ class JackPort @@ -44,30 +44,30 @@ class JackPort int fTypeId; enum JackPortFlags fFlags; char fName[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; - char fAlias1[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; - char fAlias2[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char fAlias1[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char fAlias2[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; int fRefNum; jack_nframes_t fLatency; - jack_nframes_t fTotalLatency; + jack_nframes_t fTotalLatency; uint8_t fMonitorRequests; bool fInUse; jack_port_id_t fTied; // Locally tied source port - #ifdef WIN32 +#ifdef WIN32 //__declspec(align(16)) float fBuffer[BUFFER_SIZE_MAX]; - float fBuffer[BUFFER_SIZE_MAX]; - #elif __GNUC__ - float fBuffer[BUFFER_SIZE_MAX] __attribute__((aligned(64))); // 16 bytes alignment for vector code, 64 bytes better for cache loads/stores - #else - #warning Buffer will not be aligned on 16 bytes boundaries : vector based code (Altivec of SSE) will fail - float fBuffer[BUFFER_SIZE_MAX]; - #endif + float fBuffer[BUFFER_SIZE_MAX]; +#elif __GNUC__ + float fBuffer[BUFFER_SIZE_MAX] __attribute__((aligned(64))); // 16 bytes alignment for vector code, 64 bytes better for cache loads/stores +#else +#warning Buffer will not be aligned on 16 bytes boundaries : vector based code (Altivec of SSE) will fail + float fBuffer[BUFFER_SIZE_MAX]; +#endif bool IsUsed() const; - - // RT + + // RT void ClearBuffer(jack_nframes_t frames); void MixBuffers(void** src_buffers, int src_count, jack_nframes_t frames); @@ -81,20 +81,20 @@ class JackPort const char* GetName() const; const char* GetShortName() const; int SetName(const char* name); - - int GetAliases(char* const aliases[2]); - int SetAlias(const char* alias); - int UnsetAlias(const char* alias); - bool NameEquals(const char* target); + + int GetAliases(char* const aliases[2]); + int SetAlias(const char* alias); + int UnsetAlias(const char* alias); + bool NameEquals(const char* target); int GetFlags() const; const char* GetType() const; - int Tie(jack_port_id_t port_index); + int Tie(jack_port_id_t port_index); int UnTie(); jack_nframes_t GetLatency() const; - jack_nframes_t GetTotalLatency() const; + jack_nframes_t GetTotalLatency() const; void SetLatency(jack_nframes_t latency); int RequestMonitor(bool onoff); @@ -103,7 +103,7 @@ class JackPort float* GetBuffer(); int GetRefNum() const; - + }; diff --git a/common/JackPortType.cpp b/common/JackPortType.cpp index 47c7fff5..eece4db0 100644 --- a/common/JackPortType.cpp +++ b/common/JackPortType.cpp @@ -24,27 +24,31 @@ This program is free software; you can redistribute it and/or modify namespace Jack { -static const JackPortType* port_types[] = { - &gAudioPortType, - &gMidiPortType, -}; +static const JackPortType* port_types[] = + { + &gAudioPortType, + &gMidiPortType, + }; -enum { PORT_TYPES_MAX = sizeof(port_types)/sizeof(port_types[0]) }; +enum +{ + PORT_TYPES_MAX = sizeof(port_types) / sizeof(port_types[0]) +}; int GetPortTypeId(const char* port_type) { for (int i = 0; i < PORT_TYPES_MAX; ++i) { const JackPortType* type = port_types[i]; - assert(type != 0); + assert(type != 0); if (strcmp(port_type, type->name) == 0) - return i; + return i; } return -1; } const JackPortType* GetPortType(int type_id) { - assert(type_id >= 0 && type_id <= PORT_TYPES_MAX); + assert(type_id >= 0 && type_id <= PORT_TYPES_MAX); const JackPortType* type = port_types[type_id]; assert(type != 0); return type; diff --git a/common/JackPortType.h b/common/JackPortType.h index a22c29a7..15493a15 100644 --- a/common/JackPortType.h +++ b/common/JackPortType.h @@ -27,7 +27,8 @@ This program is free software; you can redistribute it and/or modify namespace Jack { -struct JackPortType { +struct JackPortType +{ const char* name; void (*init)(void* buffer, size_t buffer_size, jack_nframes_t nframes); void (*mixdown)(void *mixbuffer, void** src_buffers, int src_count, jack_nframes_t nframes); diff --git a/common/JackPosixSemaphore.cpp b/common/JackPosixSemaphore.cpp index 3b787694..c7c74f3a 100644 --- a/common/JackPosixSemaphore.cpp +++ b/common/JackPosixSemaphore.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -34,11 +34,11 @@ void JackPosixSemaphore::BuildName(const char* name, const char* server_name, ch bool JackPosixSemaphore::Signal() { int res; - - if (!fSemaphore) { - jack_error("JackPosixSemaphore::Signal name = %s already desallocated!!", fName); - return false; - } + + if (!fSemaphore) { + jack_error("JackPosixSemaphore::Signal name = %s already desallocated!!", fName); + return false; + } if (fFlush) return true; @@ -52,11 +52,11 @@ bool JackPosixSemaphore::Signal() bool JackPosixSemaphore::SignalAll() { int res; - + if (!fSemaphore) { - jack_error("JackPosixSemaphore::SignalAll name = %s already desallocated!!", fName); - return false; - } + jack_error("JackPosixSemaphore::SignalAll name = %s already desallocated!!", fName); + return false; + } if (fFlush) return true; @@ -71,7 +71,7 @@ bool JackPosixSemaphore::SignalAll() bool JackPosixSemaphore::Wait() { int res; - + if (!fSemaphore) { jack_error("JackPosixSemaphore::Wait name = %s already desallocated!!", fName); return false; @@ -99,13 +99,13 @@ bool JackPosixSemaphore::Wait() /* #ifdef __linux__ - + bool JackPosixSemaphore::TimedWait(long usec) // unusable semantic !! { int res; struct timeval now; timespec time; - + if (!fSemaphore) { jack_error("JackPosixSemaphore::TimedWait name = %s already desallocated!!", fName); return false; @@ -113,7 +113,7 @@ bool JackPosixSemaphore::TimedWait(long usec) // unusable semantic !! gettimeofday(&now, 0); time.tv_sec = now.tv_sec + usec / 1000000; time.tv_nsec = (now.tv_usec + (usec % 1000000)) * 1000; - + if ((res = sem_timedwait(fSemaphore, &time)) != 0) { jack_error("JackPosixSemaphore::TimedWait err = %s", strerror(errno)); JackLog("now %ld %ld \n", now.tv_sec, now.tv_usec); @@ -121,15 +121,15 @@ bool JackPosixSemaphore::TimedWait(long usec) // unusable semantic !! } return (res == 0); } - -#else + +#else #warning "JackPosixSemaphore::TimedWait is not supported: Jack in SYNC mode with JackPosixSemaphore will not run properly !!" - + bool JackPosixSemaphore::TimedWait(long usec) { return Wait(); } -#endif +#endif */ #warning JackPosixSemaphore::TimedWait not available : synchronous mode may not work correctly if POSIX semaphore are used diff --git a/common/JackPosixSemaphore.h b/common/JackPosixSemaphore.h index ebec270a..1daaeee5 100644 --- a/common/JackPosixSemaphore.h +++ b/common/JackPosixSemaphore.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackPosixThread.cpp b/common/JackPosixThread.cpp index 5de42f49..eb81e0d2 100644 --- a/common/JackPosixThread.cpp +++ b/common/JackPosixThread.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -43,8 +43,8 @@ void* JackPosixThread::ThreadHandler(void* arg) JackLog("ThreadHandler: start\n"); - // If Init succeed, start the thread loop - bool res = true; + // If Init succeed, start the thread loop + bool res = true; while (obj->fRunning && res) { res = runnable->Execute(); } @@ -55,21 +55,21 @@ void* JackPosixThread::ThreadHandler(void* arg) int JackPosixThread::Start() { - fRunning = true; - - // Check if the thread was correctly started - if (StartImp(&fThread, fPriority, fRealTime, ThreadHandler, this) < 0) { - fRunning = false; - return -1; - } else { - return 0; - } + fRunning = true; + + // Check if the thread was correctly started + if (StartImp(&fThread, fPriority, fRealTime, ThreadHandler, this) < 0) { + fRunning = false; + return -1; + } else { + return 0; + } } int JackPosixThread::StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg) { int res; - + if (realtime) { JackLog("Create RT thread\n"); @@ -80,17 +80,17 @@ int JackPosixThread::StartImp(pthread_t* thread, int priority, int realtime, voi pthread_attr_t attributes; struct sched_param rt_param; pthread_attr_init(&attributes); - - if ((res = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED))) { + + if ((res = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED))) { jack_error("Cannot request explicit scheduling for RT thread %d %s", res, strerror(errno)); return -1; } - + if ((res = pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE))) { jack_error("Cannot request joinable thread creation for RT thread %d %s", res, strerror(errno)); return -1; } - + if ((res = pthread_attr_setscope(&attributes, PTHREAD_SCOPE_SYSTEM))) { jack_error("Cannot set scheduling scope for RT thread %d %s", res, strerror(errno)); return -1; @@ -102,18 +102,18 @@ int JackPosixThread::StartImp(pthread_t* thread, int priority, int realtime, voi jack_error("Cannot set RR scheduling class for RT thread %d %s", res, strerror(errno)); return -1; } - - memset(&rt_param, 0, sizeof(rt_param)); + + memset(&rt_param, 0, sizeof(rt_param)); rt_param.sched_priority = priority; if ((res = pthread_attr_setschedparam(&attributes, &rt_param))) { jack_error("Cannot set scheduling priority for RT thread %d %s", res, strerror(errno)); return -1; } - - if ((res = pthread_attr_setstacksize(&attributes, THREAD_STACK))) { - jack_error("setting thread stack size%d %s", res, strerror(errno)); - return -1; + + if ((res = pthread_attr_setstacksize(&attributes, THREAD_STACK))) { + jack_error("setting thread stack size%d %s", res, strerror(errno)); + return -1; } if ((res = pthread_create(thread, &attributes, start_routine, arg))) { @@ -146,8 +146,8 @@ int JackPosixThread::Kill() void* status; pthread_cancel(fThread); pthread_join(fThread, &status); - fRunning = false; - fThread = (pthread_t)NULL; + fRunning = false; + fThread = (pthread_t)NULL; return 0; } else { return -1; @@ -161,7 +161,7 @@ int JackPosixThread::Stop() void* status; fRunning = false; // Request for the thread to stop pthread_join(fThread, &status); - fThread = (pthread_t)NULL; + fThread = (pthread_t)NULL; return 0; } else { return -1; @@ -170,18 +170,18 @@ int JackPosixThread::Stop() int JackPosixThread::AcquireRealTime() { - return (fThread) ? AcquireRealTimeImp(fThread, fPriority) : -1; + return (fThread) ? AcquireRealTimeImp(fThread, fPriority) : -1; } int JackPosixThread::AcquireRealTime(int priority) { - fPriority = priority; + fPriority = priority; return AcquireRealTime(); } int JackPosixThread::AcquireRealTimeImp(pthread_t thread, int priority) { - struct sched_param rtparam; + struct sched_param rtparam; int res; memset(&rtparam, 0, sizeof(rtparam)); rtparam.sched_priority = priority; @@ -204,7 +204,7 @@ int JackPosixThread::DropRealTime() int JackPosixThread::DropRealTimeImp(pthread_t thread) { - struct sched_param rtparam; + struct sched_param rtparam; int res; memset(&rtparam, 0, sizeof(rtparam)); rtparam.sched_priority = 0; @@ -223,8 +223,8 @@ pthread_t JackPosixThread::GetThreadID() void JackPosixThread::Terminate() { - JackLog("JackPosixThread::Terminate\n"); - pthread_exit(0); + JackLog("JackPosixThread::Terminate\n"); + pthread_exit(0); } } // end of namespace diff --git a/common/JackPosixThread.h b/common/JackPosixThread.h index d960309c..b6e9b2a4 100644 --- a/common/JackPosixThread.h +++ b/common/JackPosixThread.h @@ -27,7 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. namespace Jack { -/* use 512KB stack per thread - the default is way too high to be feasible +/* use 512KB stack per thread - the default is way too high to be feasible * with mlockall() on many systems */ #define THREAD_STACK 524288 @@ -62,17 +62,17 @@ class JackPosixThread : public JackThread virtual int StartSync(); virtual int Kill(); virtual int Stop(); - virtual void Terminate(); + virtual void Terminate(); virtual int AcquireRealTime(); virtual int AcquireRealTime(int priority); virtual int DropRealTime(); pthread_t GetThreadID(); - - static int AcquireRealTimeImp(pthread_t thread, int priority); - static int DropRealTimeImp(pthread_t thread); - static int StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg); + + static int AcquireRealTimeImp(pthread_t thread, int priority); + static int DropRealTimeImp(pthread_t thread); + static int StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg); }; diff --git a/common/JackProcessSync.h b/common/JackProcessSync.h index 3a53bedb..e19ad390 100644 --- a/common/JackProcessSync.h +++ b/common/JackProcessSync.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 diff --git a/common/JackRequest.h b/common/JackRequest.h index 36b06529..0b130e8c 100644 --- a/common/JackRequest.h +++ b/common/JackRequest.h @@ -1,22 +1,22 @@ /* - Copyright (C) 2001 Paul Davis - + Copyright (C) 2001 Paul Davis + 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 __JackRequest__ @@ -55,15 +55,15 @@ struct JackRequest kSetTimebaseCallback = 13, kSetBufferSize = 20, kSetFreeWheel = 21, - kClientCheck = 22, + kClientCheck = 22, kClientOpen = 23, kClientClose = 24, kConnectNamePorts = 25, kDisconnectNamePorts = 26, - kGetInternalClientName = 27, - kInternalClientHandle = 28, - kInternalClientLoad = 29, - kInternalClientUnload = 30, + kGetInternalClientName = 27, + kInternalClientHandle = 28, + kInternalClientLoad = 29, + kInternalClientUnload = 30, kNotification = 31 }; @@ -75,17 +75,17 @@ struct JackRequest JackRequest(RequestType type): fType(type) {} - virtual ~JackRequest() + virtual ~JackRequest() {} - virtual int Read(JackChannelTransaction* trans) + virtual int Read(JackChannelTransaction* trans) { - return trans->Read(&fType, sizeof(RequestType)); + return trans->Read(&fType, sizeof(RequestType)); } - virtual int Write(JackChannelTransaction* trans) + virtual int Write(JackChannelTransaction* trans) { - return trans->Write(&fType, sizeof(RequestType)); + return trans->Write(&fType, sizeof(RequestType)); } }; @@ -108,12 +108,12 @@ struct JackResult virtual int Read(JackChannelTransaction* trans) { - return trans->Read(&fResult, sizeof(int)); + return trans->Read(&fResult, sizeof(int)); } virtual int Write(JackChannelTransaction* trans) { - return trans->Write(&fResult, sizeof(int)); + return trans->Write(&fResult, sizeof(int)); } }; @@ -125,29 +125,29 @@ struct JackClientCheckRequest : public JackRequest { char fName[JACK_CLIENT_NAME_SIZE + 1]; - int fProtocol; + int fProtocol; int fOptions; JackClientCheckRequest() {} - JackClientCheckRequest(const char* name, int protocol, int options): JackRequest(JackRequest::kClientCheck),fProtocol(protocol),fOptions(options) + JackClientCheckRequest(const char* name, int protocol, int options): JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options) { snprintf(fName, sizeof(fName), "%s", name); } int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fProtocol, sizeof(int))); - return trans->Read(&fOptions, sizeof(int)); + CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fProtocol, sizeof(int))); + return trans->Read(&fOptions, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fProtocol, sizeof(int))); - return trans->Write(&fOptions, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fProtocol, sizeof(int))); + return trans->Write(&fOptions, sizeof(int)); } }; @@ -158,31 +158,31 @@ struct JackClientCheckRequest : public JackRequest struct JackClientCheckResult : public JackResult { - char fName[JACK_CLIENT_NAME_SIZE + 1]; - int fStatus; + char fName[JACK_CLIENT_NAME_SIZE + 1]; + int fStatus; - JackClientCheckResult():JackResult(),fStatus(0) + JackClientCheckResult(): JackResult(), fStatus(0) {} JackClientCheckResult(int32_t result, const char* name, int status) - : JackResult(result), fStatus(status) + : JackResult(result), fStatus(status) { - snprintf(fName, sizeof(fName), "%s", name); - } + snprintf(fName, sizeof(fName), "%s", name); + } - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fStatus, sizeof(int))); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fStatus, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fStatus, sizeof(int))); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fStatus, sizeof(int))); + return 0; } }; @@ -204,13 +204,13 @@ struct JackClientOpenRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1); + return trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1); } }; @@ -227,30 +227,30 @@ struct JackClientOpenResult : public JackResult uint32_t fProtocolVersion; JackClientOpenResult() - :JackResult(),fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1), fProtocolVersion(0) + : JackResult(), fSharedEngine(-1), fSharedClient(-1), fSharedGraph(-1), fProtocolVersion(0) {} JackClientOpenResult(int32_t result, int index1, int index2, int index3) - : JackResult(result), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3), fProtocolVersion(0) + : JackResult(result), fSharedEngine(index1), fSharedClient(index2), fSharedGraph(index3), fProtocolVersion(0) {} - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fSharedEngine, sizeof(int))); - CheckRes(trans->Read(&fSharedClient, sizeof(int))); - CheckRes(trans->Read(&fSharedGraph, sizeof(int))); - CheckRes(trans->Read(&fProtocolVersion, sizeof(uint32_t))); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fSharedEngine, sizeof(int))); + CheckRes(trans->Read(&fSharedClient, sizeof(int))); + CheckRes(trans->Read(&fSharedGraph, sizeof(int))); + CheckRes(trans->Read(&fProtocolVersion, sizeof(uint32_t))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fSharedEngine, sizeof(int))); - CheckRes(trans->Write(&fSharedClient, sizeof(int))); - CheckRes(trans->Write(&fSharedGraph, sizeof(int))); - CheckRes(trans->Write(&fProtocolVersion, sizeof(uint32_t))); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fSharedEngine, sizeof(int))); + CheckRes(trans->Write(&fSharedClient, sizeof(int))); + CheckRes(trans->Write(&fSharedGraph, sizeof(int))); + CheckRes(trans->Write(&fProtocolVersion, sizeof(uint32_t))); + return 0; } }; @@ -270,13 +270,13 @@ struct JackClientCloseRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fRefNum, sizeof(int)); + return trans->Read(&fRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fRefNum, sizeof(int)); } }; @@ -296,13 +296,13 @@ struct JackActivateRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fRefNum, sizeof(int)); + return trans->Read(&fRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fRefNum, sizeof(int)); } }; @@ -323,13 +323,13 @@ struct JackDeactivateRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fRefNum, sizeof(int)); + return trans->Read(&fRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fRefNum, sizeof(int)); } }; @@ -358,23 +358,23 @@ struct JackPortRegisterRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fName, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fPortType, JACK_PORT_TYPE_SIZE + 1)); - CheckRes(trans->Read(&fFlags, sizeof(unsigned int))); - CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int))); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fName, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fPortType, JACK_PORT_TYPE_SIZE + 1)); + CheckRes(trans->Read(&fFlags, sizeof(unsigned int))); + CheckRes(trans->Read(&fBufferSize, sizeof(unsigned int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fName, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fPortType, JACK_PORT_TYPE_SIZE + 1)); - CheckRes(trans->Write(&fFlags, sizeof(unsigned int))); - CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int))); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fName, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fPortType, JACK_PORT_TYPE_SIZE + 1)); + CheckRes(trans->Write(&fFlags, sizeof(unsigned int))); + CheckRes(trans->Write(&fBufferSize, sizeof(unsigned int))); + return 0; } }; @@ -387,19 +387,19 @@ struct JackPortRegisterResult : public JackResult unsigned int fPortIndex; - JackPortRegisterResult():JackResult(),fPortIndex(NO_PORT) + JackPortRegisterResult(): JackResult(), fPortIndex(NO_PORT) {} int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - return trans->Read(&fPortIndex, sizeof(jack_port_id_t)); + CheckRes(JackResult::Read(trans)); + return trans->Read(&fPortIndex, sizeof(jack_port_id_t)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - return trans->Write(&fPortIndex, sizeof(jack_port_id_t)); + CheckRes(JackResult::Write(trans)); + return trans->Write(&fPortIndex, sizeof(jack_port_id_t)); } }; @@ -420,17 +420,17 @@ struct JackPortUnRegisterRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fPortIndex, sizeof(int))); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fPortIndex, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fPortIndex, sizeof(int))); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fPortIndex, sizeof(int))); + return 0; } }; @@ -440,7 +440,7 @@ struct JackPortUnRegisterRequest : public JackRequest struct JackPortConnectNameRequest : public JackRequest { - + int fRefNum; char fSrc[JACK_PORT_NAME_SIZE + 1]; char fDst[JACK_PORT_NAME_SIZE + 1]; @@ -455,20 +455,20 @@ struct JackPortConnectNameRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fSrc, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fDst, JACK_PORT_NAME_SIZE + 1)); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fSrc, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fDst, JACK_PORT_NAME_SIZE + 1)); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fSrc, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fDst, JACK_PORT_NAME_SIZE + 1)); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fSrc, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fDst, JACK_PORT_NAME_SIZE + 1)); + return 0; } }; @@ -493,19 +493,19 @@ struct JackPortDisconnectNameRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fSrc, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fDst, JACK_PORT_NAME_SIZE + 1)); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fSrc, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fDst, JACK_PORT_NAME_SIZE + 1)); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fSrc, JACK_PORT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fDst, JACK_PORT_NAME_SIZE + 1)); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fSrc, JACK_PORT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fDst, JACK_PORT_NAME_SIZE + 1)); + return 0; } }; @@ -527,19 +527,19 @@ struct JackPortConnectRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t))); - CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t))); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t))); + CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t))); - CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t))); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t))); + CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t))); + return 0; } }; @@ -562,19 +562,19 @@ struct JackPortDisconnectRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t))); - CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t))); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fSrc, sizeof(jack_port_id_t))); + CheckRes(trans->Read(&fDst, sizeof(jack_port_id_t))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t))); - CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t))); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fSrc, sizeof(jack_port_id_t))); + CheckRes(trans->Write(&fDst, sizeof(jack_port_id_t))); + return 0; } }; @@ -595,13 +595,13 @@ struct JackSetBufferSizeRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fBufferSize, sizeof(jack_nframes_t)); + return trans->Read(&fBufferSize, sizeof(jack_nframes_t)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fBufferSize, sizeof(jack_nframes_t)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fBufferSize, sizeof(jack_nframes_t)); } }; @@ -621,13 +621,13 @@ struct JackSetFreeWheelRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fOnOff, sizeof(int)); + return trans->Read(&fOnOff, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fOnOff, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fOnOff, sizeof(int)); } }; @@ -647,13 +647,13 @@ struct JackReleaseTimebaseRequest : public JackRequest int Read(JackChannelTransaction* trans) { - return trans->Read(&fRefNum, sizeof(int)); + return trans->Read(&fRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - return trans->Write(&fRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + return trans->Write(&fRefNum, sizeof(int)); } }; @@ -674,15 +674,15 @@ struct JackSetTimebaseCallbackRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - return trans->Read(&fConditionnal, sizeof(int)); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + return trans->Read(&fConditionnal, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - return trans->Write(&fConditionnal, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + return trans->Write(&fConditionnal, sizeof(int)); } }; @@ -693,26 +693,26 @@ struct JackSetTimebaseCallbackRequest : public JackRequest struct JackGetInternalClientNameRequest : public JackRequest { - int fRefNum; + int fRefNum; int fIntRefNum; JackGetInternalClientNameRequest() {} JackGetInternalClientNameRequest(int refnum, int int_ref) - : JackRequest(JackRequest::kGetInternalClientName),fRefNum(refnum),fIntRefNum(int_ref) + : JackRequest(JackRequest::kGetInternalClientName), fRefNum(refnum), fIntRefNum(int_ref) {} int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - return trans->Read(&fIntRefNum, sizeof(int)); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + return trans->Read(&fIntRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - return trans->Write(&fIntRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + return trans->Write(&fIntRefNum, sizeof(int)); } }; @@ -723,28 +723,28 @@ struct JackGetInternalClientNameRequest : public JackRequest struct JackGetInternalClientNameResult : public JackResult { - char fName[JACK_CLIENT_NAME_SIZE + 1]; + char fName[JACK_CLIENT_NAME_SIZE + 1]; - JackGetInternalClientNameResult():JackResult() + JackGetInternalClientNameResult(): JackResult() {} JackGetInternalClientNameResult(int32_t result, const char* name) - : JackResult(result) + : JackResult(result) { - snprintf(fName, sizeof(fName), "%s", name); - } + snprintf(fName, sizeof(fName), "%s", name); + } - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); + return 0; } }; @@ -755,28 +755,28 @@ struct JackGetInternalClientNameResult : public JackResult struct JackInternalClientHandleRequest : public JackRequest { - int fRefNum; + int fRefNum; char fName[JACK_CLIENT_NAME_SIZE + 1]; JackInternalClientHandleRequest() {} JackInternalClientHandleRequest(int refnum, const char* client_name) - : JackRequest(JackRequest::kInternalClientHandle),fRefNum(refnum) + : JackRequest(JackRequest::kInternalClientHandle), fRefNum(refnum) { - snprintf(fName, sizeof(fName), "%s", client_name); - } + snprintf(fName, sizeof(fName), "%s", client_name); + } int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - return trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + return trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - return trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + return trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1); } }; @@ -787,29 +787,29 @@ struct JackInternalClientHandleRequest : public JackRequest struct JackInternalClientHandleResult : public JackResult { - int fStatus; - int fIntRefNum; + int fStatus; + int fIntRefNum; - JackInternalClientHandleResult():JackResult() + JackInternalClientHandleResult(): JackResult() {} JackInternalClientHandleResult(int32_t result, int status, int int_ref) - : JackResult(result),fStatus(status),fIntRefNum(int_ref) + : JackResult(result), fStatus(status), fIntRefNum(int_ref) {} - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fStatus, sizeof(int))); - CheckRes(trans->Read(&fIntRefNum, sizeof(int))); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fStatus, sizeof(int))); + CheckRes(trans->Read(&fIntRefNum, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fStatus, sizeof(int))); - CheckRes(trans->Write(&fIntRefNum, sizeof(int))); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fStatus, sizeof(int))); + CheckRes(trans->Write(&fIntRefNum, sizeof(int))); + return 0; } }; @@ -820,41 +820,41 @@ struct JackInternalClientHandleResult : public JackResult struct JackInternalClientLoadRequest : public JackRequest { - #define MAX_PATH 256 - - int fRefNum; +#define MAX_PATH 256 + + int fRefNum; char fName[JACK_CLIENT_NAME_SIZE + 1]; - char fDllName[MAX_PATH + 1]; - char fLoadInitName[JACK_LOAD_INIT_LIMIT + 1]; - int fOptions; + char fDllName[MAX_PATH + 1]; + char fLoadInitName[JACK_LOAD_INIT_LIMIT + 1]; + int fOptions; JackInternalClientLoadRequest() {} JackInternalClientLoadRequest(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options) - : JackRequest(JackRequest::kInternalClientLoad),fRefNum(refnum),fOptions(options) + : JackRequest(JackRequest::kInternalClientLoad), fRefNum(refnum), fOptions(options) { - snprintf(fName, sizeof(fName), "%s", client_name); - snprintf(fDllName, sizeof(fDllName), "%s", so_name); - snprintf(fLoadInitName, sizeof(fLoadInitName), "%s", objet_data); - } + snprintf(fName, sizeof(fName), "%s", client_name); + snprintf(fDllName, sizeof(fDllName), "%s", so_name); + snprintf(fLoadInitName, sizeof(fLoadInitName), "%s", objet_data); + } int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fDllName, MAX_PATH + 1)); - CheckRes(trans->Read(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1)); - return trans->Read(&fOptions, sizeof(int)); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fDllName, MAX_PATH + 1)); + CheckRes(trans->Read(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1)); + return trans->Read(&fOptions, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fDllName, MAX_PATH + 1)); - CheckRes(trans->Write(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1)); - return trans->Write(&fOptions, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fDllName, MAX_PATH + 1)); + CheckRes(trans->Write(&fLoadInitName, JACK_LOAD_INIT_LIMIT + 1)); + return trans->Write(&fOptions, sizeof(int)); } }; @@ -865,29 +865,29 @@ struct JackInternalClientLoadRequest : public JackRequest struct JackInternalClientLoadResult : public JackResult { - int fStatus; - int fIntRefNum; + int fStatus; + int fIntRefNum; - JackInternalClientLoadResult():JackResult() + JackInternalClientLoadResult(): JackResult() {} JackInternalClientLoadResult(int32_t result, int status, int int_ref) - : JackResult(result),fStatus(status),fIntRefNum(int_ref) + : JackResult(result), fStatus(status), fIntRefNum(int_ref) {} - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fStatus, sizeof(int))); - CheckRes(trans->Read(&fIntRefNum, sizeof(int))); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fStatus, sizeof(int))); + CheckRes(trans->Read(&fIntRefNum, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fStatus, sizeof(int))); - CheckRes(trans->Write(&fIntRefNum, sizeof(int))); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fStatus, sizeof(int))); + CheckRes(trans->Write(&fIntRefNum, sizeof(int))); + return 0; } }; @@ -898,26 +898,26 @@ struct JackInternalClientLoadResult : public JackResult struct JackInternalClientUnloadRequest : public JackRequest { - int fRefNum; + int fRefNum; int fIntRefNum; JackInternalClientUnloadRequest() {} JackInternalClientUnloadRequest(int refnum, int int_ref) - : JackRequest(JackRequest::kInternalClientUnload),fRefNum(refnum),fIntRefNum(int_ref) + : JackRequest(JackRequest::kInternalClientUnload), fRefNum(refnum), fIntRefNum(int_ref) {} int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - return trans->Read(&fIntRefNum, sizeof(int)); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + return trans->Read(&fIntRefNum, sizeof(int)); } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - return trans->Write(&fIntRefNum, sizeof(int)); + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + return trans->Write(&fIntRefNum, sizeof(int)); } }; @@ -929,26 +929,26 @@ struct JackInternalClientUnloadRequest : public JackRequest struct JackInternalClientUnloadResult : public JackResult { - int fStatus; + int fStatus; - JackInternalClientUnloadResult():JackResult() + JackInternalClientUnloadResult(): JackResult() {} JackInternalClientUnloadResult(int32_t result, int status) - : JackResult(result),fStatus(status) + : JackResult(result), fStatus(status) {} - int Read(JackChannelTransaction* trans) + int Read(JackChannelTransaction* trans) { - CheckRes(JackResult::Read(trans)); - CheckRes(trans->Read(&fStatus, sizeof(int))); - return 0; + CheckRes(JackResult::Read(trans)); + CheckRes(trans->Read(&fStatus, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackResult::Write(trans)); - CheckRes(trans->Write(&fStatus, sizeof(int))); - return 0; + CheckRes(JackResult::Write(trans)); + CheckRes(trans->Write(&fStatus, sizeof(int))); + return 0; } }; @@ -958,7 +958,7 @@ struct JackInternalClientUnloadResult : public JackResult struct JackClientNotificationRequest : public JackRequest { - + int fRefNum; int fNotify; int fValue; @@ -971,19 +971,19 @@ struct JackClientNotificationRequest : public JackRequest int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fNotify, sizeof(int))); - CheckRes(trans->Read(&fValue, sizeof(int))); - return 0; + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fNotify, sizeof(int))); + CheckRes(trans->Read(&fValue, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(JackRequest::Write(trans)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fNotify, sizeof(int))); - CheckRes(trans->Write(&fValue, sizeof(int))); - return 0; + CheckRes(JackRequest::Write(trans)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fNotify, sizeof(int))); + CheckRes(trans->Write(&fValue, sizeof(int))); + return 0; } }; @@ -998,7 +998,7 @@ struct JackClientNotification int fRefNum; int fNotify; int fValue1; - int fValue2; + int fValue2; int fSync; JackClientNotification(): fNotify(-1), fValue1(-1), fValue2(-1) @@ -1011,24 +1011,24 @@ struct JackClientNotification int Read(JackChannelTransaction* trans) { - CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Read(&fRefNum, sizeof(int))); - CheckRes(trans->Read(&fNotify, sizeof(int))); - CheckRes(trans->Read(&fValue1, sizeof(int))); - CheckRes(trans->Read(&fValue2, sizeof(int))); - CheckRes(trans->Read(&fSync, sizeof(int))); - return 0; + CheckRes(trans->Read(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Read(&fRefNum, sizeof(int))); + CheckRes(trans->Read(&fNotify, sizeof(int))); + CheckRes(trans->Read(&fValue1, sizeof(int))); + CheckRes(trans->Read(&fValue2, sizeof(int))); + CheckRes(trans->Read(&fSync, sizeof(int))); + return 0; } int Write(JackChannelTransaction* trans) { - CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); - CheckRes(trans->Write(&fRefNum, sizeof(int))); - CheckRes(trans->Write(&fNotify, sizeof(int))); - CheckRes(trans->Write(&fValue1, sizeof(int))); - CheckRes(trans->Write(&fValue2, sizeof(int))); - CheckRes(trans->Write(&fSync, sizeof(int))); - return 0; + CheckRes(trans->Write(&fName, JACK_CLIENT_NAME_SIZE + 1)); + CheckRes(trans->Write(&fRefNum, sizeof(int))); + CheckRes(trans->Write(&fNotify, sizeof(int))); + CheckRes(trans->Write(&fValue1, sizeof(int))); + CheckRes(trans->Write(&fValue2, sizeof(int))); + CheckRes(trans->Write(&fSync, sizeof(int))); + return 0; } }; diff --git a/common/JackServer.cpp b/common/JackServer.cpp index 127e6fc3..718af57b 100644 --- a/common/JackServer.cpp +++ b/common/JackServer.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -53,12 +53,12 @@ JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long p fFreewheelDriver = new JackThreadedDriver(new JackFreewheelDriver("freewheel", fEngine, fSynchroTable)); fLoopbackDriver = new JackLoopbackDriver("loopback", fEngine, fSynchroTable); fChannel = JackGlobals::MakeServerChannel(); - fFreewheel = false; + fFreewheel = false; fLoopback = loopback; fDriverInfo = NULL; fAudioDriver = NULL; fInstance = this; // Unique instance - jack_verbose = verbose; + jack_verbose = verbose; } JackServer::~JackServer() @@ -117,7 +117,7 @@ int JackServer::Open(jack_driver_desc_t* driver_desc, JSList* driver_params) jack_error("Cannot attach audio driver"); return -1; } - + if (fLoopback > 0 && fLoopbackDriver->Attach() != 0) { jack_error("Cannot attach loopback driver"); return -1; @@ -148,25 +148,25 @@ int JackServer::Close() int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status) { - try { - // Clear status - *status = 0; - JackLoadableInternalClient* client = new JackLoadableInternalClient(fInstance, GetSynchroTable(), so_name, objet_data); - assert(client); - int res = client->Open("unused", client_name, (jack_options_t)options, (jack_status_t*)status); - if (res < 0) { - delete client; - *int_ref = 0; - } else { - *int_ref = client->GetClientControl()->fRefNum; - } - } catch (...) { - int my_status1 = *status | JackFailure; - *status = (jack_status_t)my_status1; - *int_ref = 0; - } - - return 0; + try { + // Clear status + *status = 0; + JackLoadableInternalClient* client = new JackLoadableInternalClient(fInstance, GetSynchroTable(), so_name, objet_data); + assert(client); + int res = client->Open("unused", client_name, (jack_options_t)options, (jack_status_t*)status); + if (res < 0) { + delete client; + *int_ref = 0; + } else { + *int_ref = client->GetClientControl()->fRefNum; + } + } catch (...) { + int my_status1 = *status | JackFailure; + *status = (jack_status_t)my_status1; + *int_ref = 0; + } + + return 0; } int JackServer::Start() @@ -185,7 +185,7 @@ int JackServer::Stop() int JackServer::SetBufferSize(jack_nframes_t buffer_size) { JackLog("JackServer::SetBufferSize nframes = %ld\n", buffer_size); - jack_nframes_t current_buffer_size = fEngineControl->fBufferSize; + jack_nframes_t current_buffer_size = fEngineControl->fBufferSize; if (fAudioDriver->Stop() != 0) { jack_error("Cannot stop audio driver"); @@ -193,27 +193,27 @@ int JackServer::SetBufferSize(jack_nframes_t buffer_size) } if (fAudioDriver->SetBufferSize(buffer_size) == 0) { - fFreewheelDriver->SetBufferSize(buffer_size); - fEngine->NotifyBufferSize(buffer_size); - fEngineControl->InitFrameTime(); - return fAudioDriver->Start(); - } else { // Failure: try to restore current value - jack_error("Cannot SetBufferSize for audio driver, restore current value %ld", current_buffer_size); - fFreewheelDriver->SetBufferSize(current_buffer_size); - fEngineControl->InitFrameTime(); - return fAudioDriver->Start(); - } + fFreewheelDriver->SetBufferSize(buffer_size); + fEngine->NotifyBufferSize(buffer_size); + fEngineControl->InitFrameTime(); + return fAudioDriver->Start(); + } else { // Failure: try to restore current value + jack_error("Cannot SetBufferSize for audio driver, restore current value %ld", current_buffer_size); + fFreewheelDriver->SetBufferSize(current_buffer_size); + fEngineControl->InitFrameTime(); + return fAudioDriver->Start(); + } } /* Freewheel mode is implemented by switching from the (audio + freewheel) driver to the freewheel driver only: - + - "global" connection state is saved - all audio driver ports are deconnected, thus there is no more dependancies with the audio driver - the freewheel driver will be synchronized with the end of graph execution : all clients are connected to the freewheel driver - the freewheel driver becomes the "master" - -Normal mode is restored with the connections state valid before freewheel mode was done. Thus one consider that + +Normal mode is restored with the connections state valid before freewheel mode was done. Thus one consider that no graph state change can be done during freewheel mode. */ @@ -231,7 +231,7 @@ int JackServer::SetFreewheel(bool onoff) fEngine->NotifyFreewheel(onoff); fFreewheelDriver->SetMaster(false); fEngineControl->InitFrameTime(); - return fAudioDriver->Start(); + return fAudioDriver->Start(); } } else { if (onoff) { @@ -241,7 +241,7 @@ int JackServer::SetFreewheel(bool onoff) fGraphManager->DisconnectAllPorts(fAudioDriver->GetClientControl()->fRefNum); fEngine->NotifyFreewheel(onoff); fFreewheelDriver->SetMaster(true); - return fFreewheelDriver->Start(); + return fFreewheelDriver->Start(); } else { return -1; } @@ -263,10 +263,10 @@ void JackServer::Notify(int refnum, int notify, int value) case kDeadClient: JackLog("JackServer: kDeadClient ref = %ld\n", refnum); - if (fEngine->ClientDeactivate(refnum) < 0) - jack_error("JackServer: DeadClient ref = %ld cannot be removed from the graph !!", refnum); - fEngine->ClientExternalClose(refnum); - break; + if (fEngine->ClientDeactivate(refnum) < 0) + jack_error("JackServer: DeadClient ref = %ld cannot be removed from the graph !!", refnum); + fEngine->ClientExternalClose(refnum); + break; } } diff --git a/common/JackServer.h b/common/JackServer.h index 9dd46246..ae26005e 100644 --- a/common/JackServer.h +++ b/common/JackServer.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -55,8 +55,8 @@ class EXPORT JackServer JackGraphManager* fGraphManager; JackServerChannelInterface* fChannel; //JackConnectionManager* fConnectionState; - JackConnectionManager fConnectionState; - JackSynchro* fSynchroTable[CLIENT_NUM]; + JackConnectionManager fConnectionState; + JackSynchro* fSynchroTable[CLIENT_NUM]; bool fFreewheel; long fLoopback; @@ -66,7 +66,7 @@ class EXPORT JackServer virtual ~JackServer(); int Open(jack_driver_desc_t* driver_desc, JSList* driver_params); - int Close(); + int Close(); int Start(); int Stop(); @@ -74,14 +74,14 @@ class EXPORT JackServer int SetBufferSize(jack_nframes_t buffer_size); int SetFreewheel(bool onoff); void Notify(int refnum, int notify, int value); - - int InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status); - - // Transport management + + int InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status); + + // Transport management int ReleaseTimebase(int refnum); int SetTimebaseCallback(int refnum, int conditional); - - // Object access + + // Object access JackEngine* GetEngine(); JackEngineControl* GetEngineControl(); JackSynchro** GetSynchroTable(); diff --git a/common/JackServerAPI.cpp b/common/JackServerAPI.cpp index 0757c638..b99ce34d 100644 --- a/common/JackServerAPI.cpp +++ b/common/JackServerAPI.cpp @@ -18,7 +18,7 @@ This program is free software; you can redistribute it and/or modify */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -32,9 +32,9 @@ This program is free software; you can redistribute it and/or modify #include "JackTools.h" #ifdef WIN32 - #define EXPORT __declspec(dllexport) +#define EXPORT __declspec(dllexport) #else - #define EXPORT +#define EXPORT #endif #ifdef __cplusplus @@ -58,10 +58,10 @@ EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options va_list ap; /* variable argument pointer */ jack_varargs_t va; /* variable arguments */ jack_status_t my_status; - JackClient* client; - char client_name[JACK_CLIENT_NAME_SIZE]; - - JackTools::RewriteName(ext_client_name, client_name); + JackClient* client; + char client_name[JACK_CLIENT_NAME_SIZE]; + + JackTools::RewriteName(ext_client_name, client_name); if (status == NULL) /* no status from caller? */ status = &my_status; /* use local status word */ @@ -86,26 +86,26 @@ EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options } if (!JackServerGlobals::Init()) { // jack server initialisation - int my_status1 = (JackFailure | JackServerError); + int my_status1 = (JackFailure | JackServerError); *status = (jack_status_t)my_status1; - return NULL; - } + return NULL; + } #ifndef WIN32 - char* jack_debug = getenv("JACK_CLIENT_DEBUG"); - if (jack_debug && strcmp(jack_debug, "on") == 0) - client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode - else - client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); + char* jack_debug = getenv("JACK_CLIENT_DEBUG"); + if (jack_debug && strcmp(jack_debug, "on") == 0) + client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode + else + client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); #else - client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); -#endif + client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); +#endif int res = client->Open(va.server_name, client_name, options, status); if (res < 0) { delete client; JackServerGlobals::Destroy(); // jack server destruction - int my_status1 = (JackFailure | JackServerError); + int my_status1 = (JackFailure | JackServerError); *status = (jack_status_t)my_status1; return NULL; } else { @@ -121,11 +121,11 @@ EXPORT int jack_client_close(jack_client_t* ext_client) jack_error("jack_client_close called with a NULL client"); return -1; } else { - int res = client->Close(); - delete client; - JackLog("jack_client_close OK\n"); - JackServerGlobals::Destroy(); // jack server destruction - return res; - } + int res = client->Close(); + delete client; + JackLog("jack_client_close OK\n"); + JackServerGlobals::Destroy(); // jack server destruction + return res; + } } diff --git a/common/JackServerGlobals.cpp b/common/JackServerGlobals.cpp index 99b962fd..f4dda14b 100644 --- a/common/JackServerGlobals.cpp +++ b/common/JackServerGlobals.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2005 Grame +Copyright (C) 2005 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 @@ -17,7 +17,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -28,7 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include <getopt.h> #ifndef WIN32 - #include <dirent.h> +#include <dirent.h> #endif static char* server_name = NULL; @@ -39,19 +39,19 @@ namespace Jack unsigned int JackServerGlobals::fClientCount = 0; JackServer* JackServerGlobals::fServer = NULL; -int JackServerGlobals::Start(const char* server_name, - jack_driver_desc_t* driver_desc, - JSList* driver_params, - int sync, - int temporary, - int time_out_ms, - int rt, - int priority, - int loopback, - int verbose) +int JackServerGlobals::Start(const char* server_name, + jack_driver_desc_t* driver_desc, + JSList* driver_params, + int sync, + int temporary, + int time_out_ms, + int rt, + int priority, + int loopback, + int verbose) { JackLog("Jackdmp: sync = %ld timeout = %ld rt = %ld priority = %ld verbose = %ld \n", sync, time_out_ms, rt, priority, verbose); - fServer = new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, server_name); + fServer = new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, server_name); int res = fServer->Open(driver_desc, driver_params); return (res < 0) ? res : fServer->Start(); } @@ -75,253 +75,254 @@ int JackServerGlobals::Delete() bool JackServerGlobals::Init() { - if (fClientCount++ == 0) { - + if (fClientCount++ == 0) { + JackLog("JackServerGlobals Init\n"); - int realtime = 0; - int client_timeout = 0; /* msecs; if zero, use period size. */ - int realtime_priority = 10; - int verbose_aux = 0; - int do_mlock = 1; - unsigned int port_max = 128; - int loopback = 0; - int do_unlock = 0; - int temporary = 0; - - jack_driver_desc_t* driver_desc; - const char *options = "-ad:P:uvshVRL:STFl:t:mn:p:"; - static struct option long_options[] = { - { "driver", 1, 0, 'd'}, - { "verbose", 0, 0, 'v' }, - { "help", 0, 0, 'h' }, - { "port-max", 1, 0, 'p' }, - { "no-mlock", 0, 0, 'm' }, - { "name", 0, 0, 'n' }, - { "unlock", 0, 0, 'u' }, - { "realtime", 0, 0, 'R' }, - { "loopback", 0, 0, 'L' }, - { "realtime-priority", 1, 0, 'P' }, - { "timeout", 1, 0, 't' }, - { "temporary", 0, 0, 'T' }, - { "version", 0, 0, 'V' }, - { "silent", 0, 0, 's' }, - { "sync", 0, 0, 'S' }, - { 0, 0, 0, 0 } - }; - int opt = 0; - int option_index = 0; - int seen_driver = 0; - char *driver_name = NULL; - char **driver_args = NULL; - JSList* driver_params; - int driver_nargs = 1; - JSList* drivers = NULL; - int show_version = 0; - int sync = 0; - int rc, i; - int ret; - - FILE* fp = 0; - char filename[255]; - char buffer[255]; - int argc = 0; - char* argv[32]; - - snprintf(filename, 255, "%s/.jackdrc", getenv("HOME")); - fp = fopen(filename, "r"); - - if (!fp) { - fp = fopen("/etc/jackdrc", "r"); - } - // if still not found, check old config name for backwards compatability - if (!fp) { - fp = fopen("/etc/jackd.conf", "r"); - } - - argc = 0; - if (fp) { - ret = fscanf(fp, "%s", buffer); - while (ret != 0 && ret != EOF) { - argv[argc] = (char*)malloc(64); - strcpy(argv[argc], buffer); - ret = fscanf(fp, "%s", buffer); - argc++; - } - fclose(fp); - } - - /* - For testing - int argc = 15; - char* argv[] = {"jackdmp", "-R", "-v", "-d", "coreaudio", "-p", "512", "-d", "~:Aggregate:0", "-r", "48000", "-i", "2", "-o", "2" }; - */ - - opterr = 0; - optind = 1; // Important : to reset argv parsing - - while (!seen_driver && - (opt = getopt_long(argc, argv, options, long_options, &option_index)) != EOF) { - - switch (opt) { - - case 'd': - seen_driver = 1; - driver_name = optarg; - break; - - case 'v': - verbose_aux = 1; - break; - - case 'S': - sync = 1; - break; - - case 'n': - server_name = optarg; - break; - - case 'm': - do_mlock = 0; - break; - - case 'p': - port_max = (unsigned int)atol(optarg); - break; - - case 'P': - realtime_priority = atoi(optarg); - break; - - case 'R': - realtime = 1; - break; - - case 'L': - loopback = atoi(optarg); - break; - - case 'T': - temporary = 1; - break; - - case 't': - client_timeout = atoi(optarg); - break; - - case 'u': - do_unlock = 1; - break; - - case 'V': - show_version = 1; - break; - - default: - fprintf(stderr, "unknown option character %c\n", optopt); - break; - } - } - - drivers = jack_drivers_load(drivers); - if (!drivers) { - fprintf(stderr, "jackdmp: no drivers found; exiting\n"); - goto error; - } - - driver_desc = jack_find_driver_descriptor(drivers, driver_name); - if (!driver_desc) { - fprintf(stderr, "jackdmp: unknown driver '%s'\n", driver_name); - goto error; - } - - if (optind < argc) { - driver_nargs = 1 + argc - optind; - } else { - driver_nargs = 1; - } - - if (driver_nargs == 0) { - fprintf(stderr, "No driver specified ... hmm. JACK won't do" - " anything when run like this.\n"); - goto error; - } - - driver_args = (char**)malloc(sizeof(char*) * driver_nargs); - driver_args[0] = driver_name; - - for (i = 1; i < driver_nargs; i++) { - driver_args[i] = argv[optind++]; - } - - if (jack_parse_driver_params(driver_desc, driver_nargs, driver_args, &driver_params)) { - goto error; - } - - #ifndef WIN32 - if (server_name == NULL) - server_name = (char*)JackTools::DefaultServerName(); - #endif - - rc = jack_register_server(server_name, false); - switch (rc) { - case EEXIST: - fprintf(stderr, "`%s' server already active\n", server_name); - goto error; - case ENOSPC: - fprintf(stderr, "too many servers already active\n"); - goto error; - case ENOMEM: - fprintf(stderr, "no access to shm registry\n"); - goto error; - default: - if (jack_verbose) - fprintf(stderr, "server `%s' registered\n", server_name); - } - - /* clean up shared memory and files from any previous instance of this server name */ - jack_cleanup_shm(); - #ifndef WIN32 - JackTools::CleanupFiles(server_name); - #endif - - if (!realtime && client_timeout == 0) - client_timeout = 500; /* 0.5 sec; usable when non realtime. */ - - for (i = 0; i < argc; i++) { - free(argv[i]); - } - - int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, loopback, verbose_aux); - if (res < 0) { - jack_error("Cannot start server... exit"); - Delete(); - jack_cleanup_shm(); - #ifndef WIN32 - JackTools::CleanupFiles(server_name); - #endif - jack_unregister_server(server_name); - goto error; - } - } - - return true; - + int realtime = 0; + int client_timeout = 0; /* msecs; if zero, use period size. */ + int realtime_priority = 10; + int verbose_aux = 0; + int do_mlock = 1; + unsigned int port_max = 128; + int loopback = 0; + int do_unlock = 0; + int temporary = 0; + + jack_driver_desc_t* driver_desc; + const char *options = "-ad:P:uvshVRL:STFl:t:mn:p:"; + static struct option long_options[] = { + { "driver", 1, 0, 'd' + }, + { "verbose", 0, 0, 'v' }, + { "help", 0, 0, 'h' }, + { "port-max", 1, 0, 'p' }, + { "no-mlock", 0, 0, 'm' }, + { "name", 0, 0, 'n' }, + { "unlock", 0, 0, 'u' }, + { "realtime", 0, 0, 'R' }, + { "loopback", 0, 0, 'L' }, + { "realtime-priority", 1, 0, 'P' }, + { "timeout", 1, 0, 't' }, + { "temporary", 0, 0, 'T' }, + { "version", 0, 0, 'V' }, + { "silent", 0, 0, 's' }, + { "sync", 0, 0, 'S' }, + { 0, 0, 0, 0 } + }; + int opt = 0; + int option_index = 0; + int seen_driver = 0; + char *driver_name = NULL; + char **driver_args = NULL; + JSList* driver_params; + int driver_nargs = 1; + JSList* drivers = NULL; + int show_version = 0; + int sync = 0; + int rc, i; + int ret; + + FILE* fp = 0; + char filename[255]; + char buffer[255]; + int argc = 0; + char* argv[32]; + + snprintf(filename, 255, "%s/.jackdrc", getenv("HOME")); + fp = fopen(filename, "r"); + + if (!fp) { + fp = fopen("/etc/jackdrc", "r"); + } + // if still not found, check old config name for backwards compatability + if (!fp) { + fp = fopen("/etc/jackd.conf", "r"); + } + + argc = 0; + if (fp) { + ret = fscanf(fp, "%s", buffer); + while (ret != 0 && ret != EOF) { + argv[argc] = (char*)malloc(64); + strcpy(argv[argc], buffer); + ret = fscanf(fp, "%s", buffer); + argc++; + } + fclose(fp); + } + + /* + For testing + int argc = 15; + char* argv[] = {"jackdmp", "-R", "-v", "-d", "coreaudio", "-p", "512", "-d", "~:Aggregate:0", "-r", "48000", "-i", "2", "-o", "2" }; + */ + + opterr = 0; + optind = 1; // Important : to reset argv parsing + + while (!seen_driver && + (opt = getopt_long(argc, argv, options, long_options, &option_index)) != EOF) { + + switch (opt) { + + case 'd': + seen_driver = 1; + driver_name = optarg; + break; + + case 'v': + verbose_aux = 1; + break; + + case 'S': + sync = 1; + break; + + case 'n': + server_name = optarg; + break; + + case 'm': + do_mlock = 0; + break; + + case 'p': + port_max = (unsigned int)atol(optarg); + break; + + case 'P': + realtime_priority = atoi(optarg); + break; + + case 'R': + realtime = 1; + break; + + case 'L': + loopback = atoi(optarg); + break; + + case 'T': + temporary = 1; + break; + + case 't': + client_timeout = atoi(optarg); + break; + + case 'u': + do_unlock = 1; + break; + + case 'V': + show_version = 1; + break; + + default: + fprintf(stderr, "unknown option character %c\n", optopt); + break; + } + } + + drivers = jack_drivers_load(drivers); + if (!drivers) { + fprintf(stderr, "jackdmp: no drivers found; exiting\n"); + goto error; + } + + driver_desc = jack_find_driver_descriptor(drivers, driver_name); + if (!driver_desc) { + fprintf(stderr, "jackdmp: unknown driver '%s'\n", driver_name); + goto error; + } + + if (optind < argc) { + driver_nargs = 1 + argc - optind; + } else { + driver_nargs = 1; + } + + if (driver_nargs == 0) { + fprintf(stderr, "No driver specified ... hmm. JACK won't do" + " anything when run like this.\n"); + goto error; + } + + driver_args = (char**)malloc(sizeof(char*) * driver_nargs); + driver_args[0] = driver_name; + + for (i = 1; i < driver_nargs; i++) { + driver_args[i] = argv[optind++]; + } + + if (jack_parse_driver_params(driver_desc, driver_nargs, driver_args, &driver_params)) { + goto error; + } + +#ifndef WIN32 + if (server_name == NULL) + server_name = (char*)JackTools::DefaultServerName(); +#endif + + rc = jack_register_server(server_name, false); + switch (rc) { + case EEXIST: + fprintf(stderr, "`%s' server already active\n", server_name); + goto error; + case ENOSPC: + fprintf(stderr, "too many servers already active\n"); + goto error; + case ENOMEM: + fprintf(stderr, "no access to shm registry\n"); + goto error; + default: + if (jack_verbose) + fprintf(stderr, "server `%s' registered\n", server_name); + } + + /* clean up shared memory and files from any previous instance of this server name */ + jack_cleanup_shm(); +#ifndef WIN32 + JackTools::CleanupFiles(server_name); +#endif + + if (!realtime && client_timeout == 0) + client_timeout = 500; /* 0.5 sec; usable when non realtime. */ + + for (i = 0; i < argc; i++) { + free(argv[i]); + } + + int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, loopback, verbose_aux); + if (res < 0) { + jack_error("Cannot start server... exit"); + Delete(); + jack_cleanup_shm(); +#ifndef WIN32 + JackTools::CleanupFiles(server_name); +#endif + jack_unregister_server(server_name); + goto error; + } + } + + return true; + error: - fClientCount--; - return false; + fClientCount--; + return false; } void JackServerGlobals::Destroy() { if (--fClientCount == 0) { JackLog("JackServerGlobals Destroy\n"); - Stop(); - jack_cleanup_shm(); - #ifndef WIN32 - JackTools::CleanupFiles(server_name); - #endif - jack_unregister_server(server_name); + Stop(); + jack_cleanup_shm(); +#ifndef WIN32 + JackTools::CleanupFiles(server_name); +#endif + jack_unregister_server(server_name); } } diff --git a/common/JackServerGlobals.h b/common/JackServerGlobals.h index 42bc7280..59be4ba1 100644 --- a/common/JackServerGlobals.h +++ b/common/JackServerGlobals.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2005 Grame +Copyright (C) 2005 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 @@ -37,7 +37,7 @@ class JackClient; struct JackServerGlobals { - static unsigned int fClientCount; + static unsigned int fClientCount; static JackServer* fServer; JackServerGlobals(); @@ -45,16 +45,16 @@ struct JackServerGlobals static bool Init(); static void Destroy(); - static int Start(const char* server_name, - jack_driver_desc_t* driver_desc, - JSList* driver_params, - int sync, - int temporary, - int time_out_ms, - int rt, - int priority, - int loopback, - int verbose); + static int Start(const char* server_name, + jack_driver_desc_t* driver_desc, + JSList* driver_params, + int sync, + int temporary, + int time_out_ms, + int rt, + int priority, + int loopback, + int verbose); static int Stop(); static int Delete(); }; diff --git a/common/JackServerLaunch.cpp b/common/JackServerLaunch.cpp index 12456fe3..8256fba7 100644 --- a/common/JackServerLaunch.cpp +++ b/common/JackServerLaunch.cpp @@ -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. */ @@ -33,153 +33,153 @@ using namespace Jack; /* Exec the JACK server in this process. Does not return. */ static void start_server_aux(const char* server_name) { - FILE* fp = 0; - char filename[255]; - char arguments[255]; - char buffer[255]; - char* command = 0; - size_t pos = 0; - size_t result = 0; - char** argv = 0; - int i = 0; - int good = 0; - int ret; - - snprintf(filename, 255, "%s/.jackdrc", getenv("HOME")); - fp = fopen(filename, "r"); - - if (!fp) { - fp = fopen("/etc/jackdrc", "r"); - } - /* if still not found, check old config name for backwards compatability */ - if (!fp) { - fp = fopen("/etc/jackd.conf", "r"); - } - - if (fp) { - arguments[0] = '\0'; - ret = fscanf(fp, "%s", buffer); - while (ret != 0 && ret != EOF) { - strcat(arguments, buffer); - strcat(arguments, " "); - ret = fscanf(fp, "%s", buffer); - } - if (strlen(arguments) > 0) { - good = 1; - } - fclose(fp); - } - - if (!good) { - command = (char*)(JACK_LOCATION "/jackd"); - strncpy(arguments, JACK_LOCATION "/jackd -T -d "JACK_DEFAULT_DRIVER, 255); - } else { - result = strcspn(arguments, " "); - command = (char*)malloc(result + 1); - strncpy(command, arguments, result); - command[result] = '\0'; - } - - argv = (char**)malloc(255); - - while (1) { - /* insert -T and -nserver_name in front of arguments */ - if (i == 1) { - argv[i] = (char*)malloc(strlen ("-T") + 1); - strcpy (argv[i++], "-T"); - if (server_name) { - size_t optlen = strlen("-n"); - char* buf = (char*)malloc(optlen + strlen(server_name) + 1); - strcpy(buf, "-n"); - strcpy(buf + optlen, server_name); - argv[i++] = buf; - } - } - - result = strcspn(arguments + pos, " "); - if (result == 0) { - break; - } - argv[i] = (char*)malloc(result + 1); - strncpy(argv[i], arguments + pos, result); - argv[i][result] = '\0'; - pos += result + 1; - ++i; - } - argv[i] = 0; - execv(command, argv); - - /* If execv() succeeds, it does not return. There's no point - * in calling jack_error() here in the child process. */ - fprintf(stderr, "exec of JACK server (command = \"%s\") failed: %s\n", command, strerror(errno)); + FILE* fp = 0; + char filename[255]; + char arguments[255]; + char buffer[255]; + char* command = 0; + size_t pos = 0; + size_t result = 0; + char** argv = 0; + int i = 0; + int good = 0; + int ret; + + snprintf(filename, 255, "%s/.jackdrc", getenv("HOME")); + fp = fopen(filename, "r"); + + if (!fp) { + fp = fopen("/etc/jackdrc", "r"); + } + /* if still not found, check old config name for backwards compatability */ + if (!fp) { + fp = fopen("/etc/jackd.conf", "r"); + } + + if (fp) { + arguments[0] = '\0'; + ret = fscanf(fp, "%s", buffer); + while (ret != 0 && ret != EOF) { + strcat(arguments, buffer); + strcat(arguments, " "); + ret = fscanf(fp, "%s", buffer); + } + if (strlen(arguments) > 0) { + good = 1; + } + fclose(fp); + } + + if (!good) { + command = (char*)(JACK_LOCATION "/jackd"); + strncpy(arguments, JACK_LOCATION "/jackd -T -d "JACK_DEFAULT_DRIVER, 255); + } else { + result = strcspn(arguments, " "); + command = (char*)malloc(result + 1); + strncpy(command, arguments, result); + command[result] = '\0'; + } + + argv = (char**)malloc(255); + + while (1) { + /* insert -T and -nserver_name in front of arguments */ + if (i == 1) { + argv[i] = (char*)malloc(strlen ("-T") + 1); + strcpy (argv[i++], "-T"); + if (server_name) { + size_t optlen = strlen("-n"); + char* buf = (char*)malloc(optlen + strlen(server_name) + 1); + strcpy(buf, "-n"); + strcpy(buf + optlen, server_name); + argv[i++] = buf; + } + } + + result = strcspn(arguments + pos, " "); + if (result == 0) { + break; + } + argv[i] = (char*)malloc(result + 1); + strncpy(argv[i], arguments + pos, result); + argv[i][result] = '\0'; + pos += result + 1; + ++i; + } + argv[i] = 0; + execv(command, argv); + + /* If execv() succeeds, it does not return. There's no point + * in calling jack_error() here in the child process. */ + fprintf(stderr, "exec of JACK server (command = \"%s\") failed: %s\n", command, strerror(errno)); } static int start_server(const char* server_name, jack_options_t options) { - if ((options & JackNoStartServer) || getenv("JACK_NO_START_SERVER")) { - return 1; - } - - /* The double fork() forces the server to become a child of - * init, which will always clean up zombie process state on - * termination. This even works in cases where the server - * terminates but this client does not. - * - * Since fork() is usually implemented using copy-on-write - * virtual memory tricks, the overhead of the second fork() is - * probably relatively small. - */ - switch (fork()) { - case 0: /* child process */ - switch (fork()) { - case 0: /* grandchild process */ - start_server_aux(server_name); - _exit(99); /* exec failed */ - case -1: - _exit(98); - default: - _exit(0); - } - case -1: /* fork() error */ - return 1; /* failed to start server */ - } - - /* only the original parent process goes here */ - return 0; /* (probably) successful */ + if ((options & JackNoStartServer) || getenv("JACK_NO_START_SERVER")) { + return 1; + } + + /* The double fork() forces the server to become a child of + * init, which will always clean up zombie process state on + * termination. This even works in cases where the server + * terminates but this client does not. + * + * Since fork() is usually implemented using copy-on-write + * virtual memory tricks, the overhead of the second fork() is + * probably relatively small. + */ + switch (fork()) { + case 0: /* child process */ + switch (fork()) { + case 0: /* grandchild process */ + start_server_aux(server_name); + _exit(99); /* exec failed */ + case - 1: + _exit(98); + default: + _exit(0); + } + case - 1: /* fork() error */ + return 1; /* failed to start server */ + } + + /* only the original parent process goes here */ + return 0; /* (probably) successful */ } int server_connect(char* server_name) { - JackClientChannelInterface* channel = JackGlobals::MakeClientChannel(); - int res = channel->ServerCheck(server_name); - channel->Close(); - delete channel; - return res; + JackClientChannelInterface* channel = JackGlobals::MakeClientChannel(); + int res = channel->ServerCheck(server_name); + channel->Close(); + delete channel; + return res; } int try_start_server(jack_varargs_t* va, jack_options_t options, jack_status_t* status) { - if (server_connect(va->server_name) < 0) { - int trys; - if (start_server(va->server_name, options)) { - int my_status1 = *status | JackFailure | JackServerFailed; - *status = (jack_status_t)my_status1; - return -1; - } - trys = 5; - do { - sleep(1); - if (--trys < 0) { - int my_status1 = *status | JackFailure | JackServerFailed; - *status = (jack_status_t)my_status1; - return -1; - } - } while (server_connect(va->server_name) < 0); - int my_status1 = *status | JackServerStarted; - *status = (jack_status_t)my_status1; - } - - return 0; + if (server_connect(va->server_name) < 0) { + int trys; + if (start_server(va->server_name, options)) { + int my_status1 = *status | JackFailure | JackServerFailed; + *status = (jack_status_t)my_status1; + return -1; + } + trys = 5; + do { + sleep(1); + if (--trys < 0) { + int my_status1 = *status | JackFailure | JackServerFailed; + *status = (jack_status_t)my_status1; + return -1; + } + } while (server_connect(va->server_name) < 0); + int my_status1 = *status | JackServerStarted; + *status = (jack_status_t)my_status1; + } + + return 0; } #endif diff --git a/common/JackServerLaunch.h b/common/JackServerLaunch.h index 331ef514..682971ab 100644 --- a/common/JackServerLaunch.h +++ b/common/JackServerLaunch.h @@ -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. */ diff --git a/common/JackShmMem.cpp b/common/JackShmMem.cpp index 5c818c96..88b21f86 100644 --- a/common/JackShmMem.cpp +++ b/common/JackShmMem.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -52,9 +52,9 @@ void* JackShmMem::operator new(size_t size) // It is unsafe to set object fields directly (may be overwritten during object initialization), // so use an intermediate global data gInfo.index = info.index; - gInfo.size = size; + gInfo.size = size; gInfo.attached_at = info.attached_at; - + JackLog("JackShmMem::new index = %ld attached = %x size = %ld \n", info.index, info.attached_at, size); return obj; @@ -76,40 +76,40 @@ void JackShmMem::operator delete(void* p, size_t size) jack_destroy_shm(&info); } -void LockMemoryImp(void* ptr, size_t size) +void LockMemoryImp(void* ptr, size_t size) { - if (CHECK_MLOCK(ptr, size)) { - JackLog("Succeeded in locking %u byte memory area\n", size); - } else { - jack_error("Cannot lock down memory area (%s)", strerror(errno)); - } + if (CHECK_MLOCK(ptr, size)) { + JackLog("Succeeded in locking %u byte memory area\n", size); + } else { + jack_error("Cannot lock down memory area (%s)", strerror(errno)); + } } -void UnlockMemoryImp(void* ptr, size_t size) +void UnlockMemoryImp(void* ptr, size_t size) { - if (CHECK_MUNLOCK(ptr, size)) { - JackLog("Succeeded in unlocking %u byte memory area\n", size); - } else { - jack_error("Cannot unlock down memory area (%s)", strerror(errno)); - } + if (CHECK_MUNLOCK(ptr, size)) { + JackLog("Succeeded in unlocking %u byte memory area\n", size); + } else { + jack_error("Cannot unlock down memory area (%s)", strerror(errno)); + } } -void LockAllMemory() +void LockAllMemory() { - if (CHECK_MLOCKALL()) { - JackLog("Succeeded in locking all memory\n"); - } else { - jack_error("Cannot lock down memory area (%s)", strerror(errno)); - } + if (CHECK_MLOCKALL()) { + JackLog("Succeeded in locking all memory\n"); + } else { + jack_error("Cannot lock down memory area (%s)", strerror(errno)); + } } -void UnlockAllMemory() +void UnlockAllMemory() { - if (CHECK_MUNLOCKALL()) { - JackLog("Succeeded in unlocking all memory\n"); - } else { - jack_error("Cannot unlock down memory area (%s)", strerror(errno)); - } + if (CHECK_MUNLOCKALL()) { + JackLog("Succeeded in unlocking all memory\n"); + } else { + jack_error("Cannot unlock down memory area (%s)", strerror(errno)); + } } diff --git a/common/JackShmMem.h b/common/JackShmMem.h index 2cb8401a..0a29fc98 100644 --- a/common/JackShmMem.h +++ b/common/JackShmMem.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -25,24 +25,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackError.h" #include <new> // GCC 4.0 -#include <errno.h> +#include <errno.h> #include <stdlib.h> #ifdef WIN32 - #include <windows.h> - #define CHECK_MLOCK(ptr, size) (VirtualLock((ptr), (size)) != 0) - #define CHECK_MUNLOCK(ptr, size) (VirtualUnlock((ptr), (size)) != 0) - #define CHECK_MLOCKALL()(false) - #define CHECK_MUNLOCKALL()(false) +#include <windows.h> +#define CHECK_MLOCK(ptr, size) (VirtualLock((ptr), (size)) != 0) +#define CHECK_MUNLOCK(ptr, size) (VirtualUnlock((ptr), (size)) != 0) +#define CHECK_MLOCKALL()(false) +#define CHECK_MUNLOCKALL()(false) #else - #include <sys/types.h> - #include <sys/mman.h> - #define CHECK_MLOCK(ptr, size) (mlock((ptr), (size)) == 0) - #define CHECK_MUNLOCK(ptr, size) (munlock((ptr), (size)) == 0) - #define CHECK_MLOCKALL() (mlockall(MCL_CURRENT | MCL_FUTURE) == 0) - #define CHECK_MUNLOCKALL() (munlockall() == 0) +#include <sys/types.h> +#include <sys/mman.h> +#define CHECK_MLOCK(ptr, size) (mlock((ptr), (size)) == 0) +#define CHECK_MUNLOCK(ptr, size) (munlock((ptr), (size)) == 0) +#define CHECK_MLOCKALL() (mlockall(MCL_CURRENT | MCL_FUTURE) == 0) +#define CHECK_MUNLOCKALL() (munlockall() == 0) #endif - + namespace Jack { @@ -51,55 +51,55 @@ void UnlockMemoryImp(void* ptr, size_t size); class JackMem { - private: + private: - size_t fSize; - static size_t gSize; - - public: + size_t fSize; + static size_t gSize; + + public: void* operator new(size_t size) - { - gSize = size; - return calloc(1, size); - } - + { + gSize = size; + return calloc(1, size); + } + void operator delete(void* ptr, size_t size) - { - free(ptr); - } + { + free(ptr); + } - JackMem():fSize(gSize) + JackMem(): fSize(gSize) {} virtual ~JackMem() {} - - void LockMemory() - { - LockMemoryImp(this, fSize); - } - - void UnlockMemory() - { - UnlockMemoryImp(this, fSize); - } + + void LockMemory() + { + LockMemoryImp(this, fSize); + } + + void UnlockMemory() + { + UnlockMemoryImp(this, fSize); + } }; /*! \brief The base class for shared memory management. - + A class which objects need to be allocated in shared memory derives from this class. */ -class JackShmMem +class JackShmMem { protected: jack_shm_info_t fInfo; - static unsigned int fSegmentNum; + static unsigned int fSegmentNum; static jack_shm_info_t gInfo; public: @@ -110,9 +110,9 @@ class JackShmMem JackShmMem() { fInfo.index = gInfo.index; - fInfo.attached_at = gInfo.attached_at; - fInfo.size = gInfo.size; - } + fInfo.attached_at = gInfo.attached_at; + fInfo.size = gInfo.size; + } virtual ~JackShmMem() {} @@ -126,16 +126,16 @@ class JackShmMem { return (char*)fInfo.attached_at; } - - void LockMemory() - { - LockMemoryImp(this, fInfo.size); - } - - void UnlockMemory() - { - UnlockMemoryImp(this, fInfo.size); - } + + void LockMemory() + { + LockMemoryImp(this, fInfo.size); + } + + void UnlockMemory() + { + UnlockMemoryImp(this, fInfo.size); + } }; @@ -153,16 +153,16 @@ class JackShmReadWritePtr void Init(int index, const char* server_name = "default") { - if (fInfo.index < 0 && index >= 0) { + if (fInfo.index < 0 && index >= 0) { JackLog("JackShmReadWritePtr::Init %ld %ld\n", index, fInfo.index); if (jack_initialize_shm(server_name) < 0) - throw -1; + throw - 1; fInfo.index = index; if (jack_attach_shm(&fInfo)) { //jack_error("cannot attach shared memory segment", strerror(errno)); - throw -2; + throw - 2; } - } + } } public: @@ -189,12 +189,12 @@ class JackShmReadWritePtr T* operator->() const { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } operator T*() const { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } JackShmReadWritePtr& operator=(int index) @@ -202,8 +202,8 @@ class JackShmReadWritePtr Init(index); return *this; } - - void SetShmIndex(int index, const char* server_name) + + void SetShmIndex(int index, const char* server_name) { Init(index, server_name); } @@ -215,7 +215,7 @@ class JackShmReadWritePtr T* GetShmAddress() { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } }; @@ -236,17 +236,17 @@ class JackShmReadWritePtr1 if (fInfo.index < 0 && index >= 0) { JackLog("JackShmReadWritePtr1::Init %ld %ld\n", index, fInfo.index); if (jack_initialize_shm(server_name) < 0) - throw -1; + throw - 1; fInfo.index = index; if (jack_attach_shm(&fInfo)) { //jack_error("cannot attach shared memory segment", strerror(errno)); - throw -2; + throw - 2; } - /* - nobody else needs to access this shared memory any more, so - destroy it. because we have our own attachment to it, it won't - vanish till we exit (and release it). - */ + /* + nobody else needs to access this shared memory any more, so + destroy it. because we have our own attachment to it, it won't + vanish till we exit (and release it). + */ jack_destroy_shm(&fInfo); } } @@ -275,7 +275,7 @@ class JackShmReadWritePtr1 T* operator->() const { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } operator T*() const @@ -288,11 +288,11 @@ class JackShmReadWritePtr1 Init(index); return *this; } - - void SetShmIndex(int index, const char* server_name) + + void SetShmIndex(int index, const char* server_name) { Init(index, server_name); - } + } int GetShmIndex() { @@ -301,7 +301,7 @@ class JackShmReadWritePtr1 T* GetShmAddress() { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } }; @@ -368,20 +368,20 @@ class JackShmReadPtr Init(index); return *this; } - - void SetShmIndex(int index, const char* server_name) + + void SetShmIndex(int index, const char* server_name) { Init(index, server_name); } - int GetShmIndex() + int GetShmIndex() { return fInfo.index; } T* GetShmAddress() { - return (T*)fInfo.attached_at; + return (T*)fInfo.attached_at; } }; diff --git a/common/JackSocket.cpp b/common/JackSocket.cpp index e3839b25..c9e30efd 100644 --- a/common/JackSocket.cpp +++ b/common/JackSocket.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -158,7 +158,7 @@ int JackServerSocket::Bind(const char* dir, const char* name, int which) // A re // TO CORRECT: always reuse the same name for now... snprintf(fName, sizeof(addr.sun_path) - 1, "%s/jack_%s_%d", dir, name, which); - strncpy(addr.sun_path, fName, sizeof(addr.sun_path) - 1); + strncpy(addr.sun_path, fName, sizeof(addr.sun_path) - 1); /* if (access(addr.sun_path, F_OK) == 0) { goto error; @@ -209,7 +209,7 @@ int JackServerSocket::Bind(const char* dir, int which) // A revoir : utilisation // TO CORRECT: always reuse the same name for now... snprintf(fName, sizeof(addr.sun_path) - 1, "%s/jack_%d", dir, which); - strncpy(addr.sun_path, fName, sizeof(addr.sun_path) - 1); + strncpy(addr.sun_path, fName, sizeof(addr.sun_path) - 1); /* if (access(addr.sun_path, F_OK) == 0) { goto error; diff --git a/common/JackSocket.h b/common/JackSocket.h index 6eb83ceb..ef2ae789 100644 --- a/common/JackSocket.h +++ b/common/JackSocket.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/JackSocketClientChannel.cpp b/common/JackSocketClientChannel.cpp index 627d510a..01672dc8 100644 --- a/common/JackSocketClientChannel.cpp +++ b/common/JackSocketClientChannel.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -40,37 +40,37 @@ JackSocketClientChannel::~JackSocketClientChannel() int JackSocketClientChannel::ServerCheck(const char* server_name) { - JackLog("JackSocketClientChannel::ServerCheck = %s\n", server_name); - + JackLog("JackSocketClientChannel::ServerCheck = %s\n", server_name); + // Connect to server if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) { - jack_error("Cannot connect to server socket"); - fRequestSocket.Close(); + jack_error("Cannot connect to server socket"); + fRequestSocket.Close(); return -1; } else { - return 0; - } + return 0; + } } int JackSocketClientChannel::Open(const char* server_name, const char* name, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) { - int result = 0; + int result = 0; JackLog("JackSocketClientChannel::Open name = %s\n", name); if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) { jack_error("Cannot connect to server socket"); goto error; } - - // Check name in server - ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); + + // Check name in server + ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); if (result < 0) { int status1 = *status; if (status1 & JackVersionError) - jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); + jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); else - jack_error("Client name = %s conflits with another running client", name); - goto error; + jack_error("Client name = %s conflits with another running client", name); + goto error; } if (fNotificationListenSocket.Bind(jack_client_dir, name_res, 0) < 0) { @@ -141,11 +141,11 @@ void JackSocketClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res, void JackSocketClientChannel::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) { - JackClientCheckRequest req(name, protocol, options); + JackClientCheckRequest req(name, protocol, options); JackClientCheckResult res; ServerSyncCall(&req, &res, result); - *status = res.fStatus; - strcpy(name_res, res.fName); + *status = res.fStatus; + strcpy(name_res, res.fName); } void JackSocketClientChannel::ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result) @@ -255,7 +255,7 @@ void JackSocketClientChannel::GetInternalClientName(int refnum, int int_ref, cha JackGetInternalClientNameRequest req(refnum, int_ref); JackGetInternalClientNameResult res; ServerSyncCall(&req, &res, result); - strcpy(name_res, res.fName); + strcpy(name_res, res.fName); } void JackSocketClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result) @@ -263,8 +263,8 @@ void JackSocketClientChannel::InternalClientHandle(int refnum, const char* clien JackInternalClientHandleRequest req(refnum, client_name); JackInternalClientHandleResult res; ServerSyncCall(&req, &res, result); - *int_ref = res.fIntRefNum; - *status = res.fStatus; + *int_ref = res.fIntRefNum; + *status = res.fStatus; } void JackSocketClientChannel::InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result) @@ -272,8 +272,8 @@ void JackSocketClientChannel::InternalClientLoad(int refnum, const char* client_ JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options); JackInternalClientLoadResult res; ServerSyncCall(&req, &res, result); - *int_ref = res.fIntRefNum; - *status = res.fStatus; + *int_ref = res.fIntRefNum; + *status = res.fStatus; } void JackSocketClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result) @@ -281,7 +281,7 @@ void JackSocketClientChannel::InternalClientUnload(int refnum, int int_ref, int* JackInternalClientUnloadRequest req(refnum, int_ref); JackInternalClientUnloadResult res; ServerSyncCall(&req, &res, result); - *status = res.fStatus; + *status = res.fStatus; } bool JackSocketClientChannel::Init() diff --git a/common/JackSocketClientChannel.h b/common/JackSocketClientChannel.h index 892d0da7..7b815a22 100644 --- a/common/JackSocketClientChannel.h +++ b/common/JackSocketClientChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -56,10 +56,10 @@ class JackSocketClientChannel : public JackClientChannelInterface, public JackRu int Start(); void Stop(); - - int ServerCheck(const char* server_name); - void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result); + int ServerCheck(const char* server_name); + + void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result); void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); void ClientClose(int refnum, int* result); @@ -80,12 +80,12 @@ class JackSocketClientChannel : public JackClientChannelInterface, public JackRu void ReleaseTimebase(int refnum, int* result); void SetTimebaseCallback(int refnum, int conditional, int* result); - - void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); + + void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result); void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result); void InternalClientUnload(int refnum, int int_ref, int* status, int* result); - + // JackRunnableInterface interface bool Init(); bool Execute(); diff --git a/common/JackSocketNotifyChannel.cpp b/common/JackSocketNotifyChannel.cpp index 1b77d363..9f1e4cca 100644 --- a/common/JackSocketNotifyChannel.cpp +++ b/common/JackSocketNotifyChannel.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/JackSocketNotifyChannel.h b/common/JackSocketNotifyChannel.h index cd45961d..306a0b96 100644 --- a/common/JackSocketNotifyChannel.h +++ b/common/JackSocketNotifyChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/JackSocketServerChannel.cpp b/common/JackSocketServerChannel.cpp index 336a1a47..6c1ba658 100644 --- a/common/JackSocketServerChannel.cpp +++ b/common/JackSocketServerChannel.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -47,7 +47,7 @@ JackSocketServerChannel::~JackSocketServerChannel() int JackSocketServerChannel::Open(const char* server_name, JackServer* server) { JackLog("JackSocketServerChannel::Open \n"); - fServer = server; + fServer = server; // Prepare request socket if (fRequestListenSocket.Bind(jack_server_dir, server_name, 0) < 0) { @@ -93,7 +93,7 @@ void JackSocketServerChannel::ClientAdd(int fd, char* name, int* shared_engine, { JackLog("JackSocketServerChannel::ClientAdd\n"); int refnum = -1; - *result = fServer->GetEngine()->ClientExternalOpen(name, &refnum, shared_engine, shared_client, shared_graph); + *result = fServer->GetEngine()->ClientExternalOpen(name, &refnum, shared_engine, shared_client, shared_graph); if (*result == 0) { fSocketTable[fd].first = refnum; fRebuild = true; @@ -150,223 +150,223 @@ int JackSocketServerChannel::HandleRequest(int fd) // Read data switch (header.fType) { - - case JackRequest::kClientCheck: { - JackLog("JackRequest::kClientCheck\n"); - JackClientCheckRequest req; - JackClientCheckResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->ClientCheck(req.fName, res.fName, req.fProtocol, req.fOptions, &res.fStatus); - if (res.Write(socket) < 0) - jack_error("JackRequest::kClientCheck write error name = %s", req.fName); - break; - } + + case JackRequest::kClientCheck: { + JackLog("JackRequest::kClientCheck\n"); + JackClientCheckRequest req; + JackClientCheckResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->ClientCheck(req.fName, res.fName, req.fProtocol, req.fOptions, &res.fStatus); + if (res.Write(socket) < 0) + jack_error("JackRequest::kClientCheck write error name = %s", req.fName); + break; + } case JackRequest::kClientOpen: { - JackLog("JackRequest::ClientOpen\n"); - JackClientOpenRequest req; - JackClientOpenResult res; - if (req.Read(socket) == 0) - ClientAdd(fd, req.fName, &res.fSharedEngine, &res.fSharedClient, &res.fSharedGraph, &res.fResult); - if (res.Write(socket) < 0) - jack_error("JackRequest::kClientOpen write error name = %s", req.fName); - break; - } + JackLog("JackRequest::ClientOpen\n"); + JackClientOpenRequest req; + JackClientOpenResult res; + if (req.Read(socket) == 0) + ClientAdd(fd, req.fName, &res.fSharedEngine, &res.fSharedClient, &res.fSharedGraph, &res.fResult); + if (res.Write(socket) < 0) + jack_error("JackRequest::kClientOpen write error name = %s", req.fName); + break; + } case JackRequest::kClientClose: { - JackLog("JackRequest::ClientClose\n"); - JackClientCloseRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->ClientExternalClose(req.fRefNum); - // No write: client is actually doing an "ServerAsyncCall", and not interested by the result - ClientRemove(fd, req.fRefNum); - break; - } + JackLog("JackRequest::ClientClose\n"); + JackClientCloseRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->ClientExternalClose(req.fRefNum); + // No write: client is actually doing an "ServerAsyncCall", and not interested by the result + ClientRemove(fd, req.fRefNum); + break; + } case JackRequest::kActivateClient: { - JackActivateRequest req; - JackResult res; - JackLog("JackRequest::ActivateClient\n"); - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->ClientActivate(req.fRefNum); - if (res.Write(socket) < 0) - jack_error("JackRequest::kActivateClient write error ref = %d", req.fRefNum); - break; - } + JackActivateRequest req; + JackResult res; + JackLog("JackRequest::ActivateClient\n"); + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->ClientActivate(req.fRefNum); + if (res.Write(socket) < 0) + jack_error("JackRequest::kActivateClient write error ref = %d", req.fRefNum); + break; + } case JackRequest::kDeactivateClient: { - JackLog("JackRequest::DeactivateClient\n"); - JackDeactivateRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->ClientDeactivate(req.fRefNum); - if (res.Write(socket) < 0) - jack_error("JackRequest::kDeactivateClient write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::DeactivateClient\n"); + JackDeactivateRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->ClientDeactivate(req.fRefNum); + if (res.Write(socket) < 0) + jack_error("JackRequest::kDeactivateClient write error ref = %d", req.fRefNum); + break; + } case JackRequest::kRegisterPort: { - JackLog("JackRequest::RegisterPort\n"); - JackPortRegisterRequest req; - JackPortRegisterResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortRegister(req.fRefNum, req.fName, req.fPortType, req.fFlags, req.fBufferSize, &res.fPortIndex); - if (res.Write(socket) < 0) - jack_error("JackRequest::kRegisterPort write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::RegisterPort\n"); + JackPortRegisterRequest req; + JackPortRegisterResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortRegister(req.fRefNum, req.fName, req.fPortType, req.fFlags, req.fBufferSize, &res.fPortIndex); + if (res.Write(socket) < 0) + jack_error("JackRequest::kRegisterPort write error ref = %d", req.fRefNum); + break; + } case JackRequest::kUnRegisterPort: { - JackLog("JackRequest::UnRegisterPort\n"); - JackPortUnRegisterRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortUnRegister(req.fRefNum, req.fPortIndex); - if (res.Write(socket) < 0) - jack_error("JackRequest::kUnRegisterPort write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::UnRegisterPort\n"); + JackPortUnRegisterRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortUnRegister(req.fRefNum, req.fPortIndex); + if (res.Write(socket) < 0) + jack_error("JackRequest::kUnRegisterPort write error ref = %d", req.fRefNum); + break; + } case JackRequest::kConnectNamePorts: { - JackLog("JackRequest::ConnectPorts\n"); - JackPortConnectNameRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); - if (res.Write(socket) < 0) - jack_error("JackRequest::kConnectNamePorts write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::ConnectPorts\n"); + JackPortConnectNameRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); + if (res.Write(socket) < 0) + jack_error("JackRequest::kConnectNamePorts write error ref = %d", req.fRefNum); + break; + } case JackRequest::kDisconnectNamePorts: { - JackLog("JackRequest::DisconnectPorts\n"); - JackPortDisconnectNameRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); - if (res.Write(socket) < 0) - jack_error("JackRequest::kDisconnectNamePorts write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::DisconnectPorts\n"); + JackPortDisconnectNameRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); + if (res.Write(socket) < 0) + jack_error("JackRequest::kDisconnectNamePorts write error ref = %d", req.fRefNum); + break; + } case JackRequest::kConnectPorts: { - JackLog("JackRequest::ConnectPorts\n"); - JackPortConnectRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); - if (res.Write(socket) < 0) - jack_error("JackRequest::kConnectPorts write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::ConnectPorts\n"); + JackPortConnectRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); + if (res.Write(socket) < 0) + jack_error("JackRequest::kConnectPorts write error ref = %d", req.fRefNum); + break; + } case JackRequest::kDisconnectPorts: { - JackLog("JackRequest::DisconnectPorts\n"); - JackPortDisconnectRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); - if (res.Write(socket) < 0) - jack_error("JackRequest::kDisconnectPorts write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::DisconnectPorts\n"); + JackPortDisconnectRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); + if (res.Write(socket) < 0) + jack_error("JackRequest::kDisconnectPorts write error ref = %d", req.fRefNum); + break; + } case JackRequest::kSetBufferSize: { - JackLog("JackRequest::SetBufferSize\n"); - JackSetBufferSizeRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->SetBufferSize(req.fBufferSize); - if (res.Write(socket) < 0) - jack_error("JackRequest::kSetBufferSize write error"); - break; - } + JackLog("JackRequest::SetBufferSize\n"); + JackSetBufferSizeRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->SetBufferSize(req.fBufferSize); + if (res.Write(socket) < 0) + jack_error("JackRequest::kSetBufferSize write error"); + break; + } case JackRequest::kSetFreeWheel: { - JackLog("JackRequest::SetFreeWheel\n"); - JackSetFreeWheelRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->SetFreewheel(req.fOnOff); - if (res.Write(socket) < 0) - jack_error("JackRequest::kSetFreeWheel write error"); - break; - } + JackLog("JackRequest::SetFreeWheel\n"); + JackSetFreeWheelRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->SetFreewheel(req.fOnOff); + if (res.Write(socket) < 0) + jack_error("JackRequest::kSetFreeWheel write error"); + break; + } case JackRequest::kReleaseTimebase: { - JackLog("JackRequest::kReleaseTimebase\n"); - JackReleaseTimebaseRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->ReleaseTimebase(req.fRefNum); - if (res.Write(socket) < 0) - jack_error("JackRequest::kReleaseTimebase write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::kReleaseTimebase\n"); + JackReleaseTimebaseRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->ReleaseTimebase(req.fRefNum); + if (res.Write(socket) < 0) + jack_error("JackRequest::kReleaseTimebase write error ref = %d", req.fRefNum); + break; + } case JackRequest::kSetTimebaseCallback: { - JackLog("JackRequest::kSetTimebaseCallback\n"); - JackSetTimebaseCallbackRequest req; - JackResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->SetTimebaseCallback(req.fRefNum, req.fConditionnal); - if (res.Write(socket) < 0) - jack_error("JackRequest::kSetTimebaseCallback write error ref = %d", req.fRefNum); - break; - } - - case JackRequest::kGetInternalClientName: { - JackLog("JackRequest::kGetInternalClientName\n"); - JackGetInternalClientNameRequest req; - JackGetInternalClientNameResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->GetInternalClientName(req.fIntRefNum, res.fName); - if (res.Write(socket) < 0) - jack_error("JackRequest::kGetInternalClientName write error ref = %d", req.fRefNum); - break; - } - - case JackRequest::kInternalClientHandle: { - JackLog("JackRequest::kInternalClientHandle\n"); - JackInternalClientHandleRequest req; - JackInternalClientHandleResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->InternalClientHandle(req.fName, &res.fStatus, &res.fIntRefNum); - if (res.Write(socket) < 0) - jack_error("JackRequest::kInternalClientHandle write error ref = %d", req.fRefNum); - break; - } - - case JackRequest::kInternalClientLoad: { - JackLog("JackRequest::kInternalClientLoad\n"); - JackInternalClientLoadRequest req; - JackInternalClientLoadResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->InternalClientLoad(req.fName, req.fDllName, req.fLoadInitName, req.fOptions, &res.fIntRefNum, &res.fStatus); - if (res.Write(socket) < 0) - jack_error("JackRequest::kInternalClientLoad write error name = %s", req.fName); - break; - } - - case JackRequest::kInternalClientUnload: { - JackLog("JackRequest::kInternalClientUnload\n"); - JackInternalClientUnloadRequest req; - JackInternalClientUnloadResult res; - if (req.Read(socket) == 0) - res.fResult = fServer->GetEngine()->InternalClientUnload(req.fIntRefNum, &res.fStatus); - if (res.Write(socket) < 0) - jack_error("JackRequest::kInternalClientUnload write error ref = %d", req.fRefNum); - break; - } + JackLog("JackRequest::kSetTimebaseCallback\n"); + JackSetTimebaseCallbackRequest req; + JackResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->SetTimebaseCallback(req.fRefNum, req.fConditionnal); + if (res.Write(socket) < 0) + jack_error("JackRequest::kSetTimebaseCallback write error ref = %d", req.fRefNum); + break; + } + + case JackRequest::kGetInternalClientName: { + JackLog("JackRequest::kGetInternalClientName\n"); + JackGetInternalClientNameRequest req; + JackGetInternalClientNameResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->GetInternalClientName(req.fIntRefNum, res.fName); + if (res.Write(socket) < 0) + jack_error("JackRequest::kGetInternalClientName write error ref = %d", req.fRefNum); + break; + } + + case JackRequest::kInternalClientHandle: { + JackLog("JackRequest::kInternalClientHandle\n"); + JackInternalClientHandleRequest req; + JackInternalClientHandleResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->InternalClientHandle(req.fName, &res.fStatus, &res.fIntRefNum); + if (res.Write(socket) < 0) + jack_error("JackRequest::kInternalClientHandle write error ref = %d", req.fRefNum); + break; + } + + case JackRequest::kInternalClientLoad: { + JackLog("JackRequest::kInternalClientLoad\n"); + JackInternalClientLoadRequest req; + JackInternalClientLoadResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->InternalClientLoad(req.fName, req.fDllName, req.fLoadInitName, req.fOptions, &res.fIntRefNum, &res.fStatus); + if (res.Write(socket) < 0) + jack_error("JackRequest::kInternalClientLoad write error name = %s", req.fName); + break; + } + + case JackRequest::kInternalClientUnload: { + JackLog("JackRequest::kInternalClientUnload\n"); + JackInternalClientUnloadRequest req; + JackInternalClientUnloadResult res; + if (req.Read(socket) == 0) + res.fResult = fServer->GetEngine()->InternalClientUnload(req.fIntRefNum, &res.fStatus); + if (res.Write(socket) < 0) + jack_error("JackRequest::kInternalClientUnload write error ref = %d", req.fRefNum); + break; + } case JackRequest::kNotification: { - JackLog("JackRequest::Notification\n"); - JackClientNotificationRequest req; - if (req.Read(socket) == 0) - fServer->Notify(req.fRefNum, req.fNotify, req.fValue); - break; - } + JackLog("JackRequest::Notification\n"); + JackClientNotificationRequest req; + if (req.Read(socket) == 0) + fServer->Notify(req.fRefNum, req.fNotify, req.fValue); + break; + } default: JackLog("Unknown request %ld\n", header.fType); diff --git a/common/JackSocketServerChannel.h b/common/JackSocketServerChannel.h index 9fa22488..d5ef7c91 100644 --- a/common/JackSocketServerChannel.h +++ b/common/JackSocketServerChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -46,13 +46,13 @@ class JackSocketServerChannel : public JackServerChannelInterface, public JackRu std::map<int, std::pair<int, JackClientSocket*> > fSocketTable; int HandleRequest(int fd); - void BuildPoolTable(); - + void BuildPoolTable(); + void ClientCreate(); void ClientAdd(int fd, char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); void ClientRemove(int fd, int refnum); void ClientKill(int fd); - + public: JackSocketServerChannel(); diff --git a/common/JackSocketServerNotifyChannel.cpp b/common/JackSocketServerNotifyChannel.cpp index edc22cc2..aff52233 100644 --- a/common/JackSocketServerNotifyChannel.cpp +++ b/common/JackSocketServerNotifyChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -41,9 +41,9 @@ void JackSocketServerNotifyChannel::Close() } /* -The requirement is that the Notification from RT thread can be delivered... not sure using a socket is adequate here... -Can the write operation block? -A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise +The requirement is that the Notification from RT thread can be delivered... not sure using a socket is adequate here... +Can the write operation block? +A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise (since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...) */ void JackSocketServerNotifyChannel::ClientNotify(int refnum, int notify, int value) diff --git a/common/JackSocketServerNotifyChannel.h b/common/JackSocketServerNotifyChannel.h index 06e7df71..f5aba2f1 100644 --- a/common/JackSocketServerNotifyChannel.h +++ b/common/JackSocketServerNotifyChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2008 Grame - +Copyright (C) 2004-2008 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/JackSyncInterface.h b/common/JackSyncInterface.h index a2f3cf9f..7a4889c3 100644 --- a/common/JackSyncInterface.h +++ b/common/JackSyncInterface.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 diff --git a/common/JackSynchro.h b/common/JackSynchro.h index 9d25e529..f20b77cc 100644 --- a/common/JackSynchro.h +++ b/common/JackSynchro.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/common/JackThread.h b/common/JackThread.h index b2b31bc9..f1ad4e27 100644 --- a/common/JackThread.h +++ b/common/JackThread.h @@ -22,11 +22,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JackThread__ #ifdef WIN32 - #include <windows.h> +#include <windows.h> typedef HANDLE pthread_t; typedef ULONGLONG UInt64; #else - #include <pthread.h> +#include <pthread.h> typedef unsigned long long UInt64; #endif @@ -81,7 +81,7 @@ class JackThread virtual int StartSync() = 0; virtual int Kill() = 0; virtual int Stop() = 0; - virtual void Terminate() = 0; + virtual void Terminate() = 0; virtual int AcquireRealTime() = 0; virtual int AcquireRealTime(int priority) = 0; diff --git a/common/JackThreadedDriver.cpp b/common/JackThreadedDriver.cpp index 3f908cec..6b74ff2e 100644 --- a/common/JackThreadedDriver.cpp +++ b/common/JackThreadedDriver.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -59,7 +59,7 @@ int JackThreadedDriver::Start() if (fDriver->IsRealTime()) { JackLog("JackThreadedDriver::Start IsRealTime\n"); - if (fThread->AcquireRealTime(GetEngineControl()->fPriority) < 0) + if (fThread->AcquireRealTime(GetEngineControl()->fPriority) < 0) jack_error("AcquireRealTime error"); } diff --git a/common/JackThreadedDriver.h b/common/JackThreadedDriver.h index bb2e5682..c4cf2473 100644 --- a/common/JackThreadedDriver.h +++ b/common/JackThreadedDriver.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -82,8 +82,8 @@ class JackThreadedDriver : public JackDriverClientInterface, public JackRunnable { return fDriver->Detach(); } - - virtual int Read() + + virtual int Read() { return fDriver->Read(); } @@ -99,8 +99,8 @@ class JackThreadedDriver : public JackDriverClientInterface, public JackRunnable { return fDriver->SetBufferSize(buffer_size); } - - virtual int SetSampleRate(jack_nframes_t sample_rate) + + virtual int SetSampleRate(jack_nframes_t sample_rate) { return fDriver->SetSampleRate(sample_rate); } diff --git a/common/JackTime.h b/common/JackTime.h index e92480ab..e0709183 100644 --- a/common/JackTime.h +++ b/common/JackTime.h @@ -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. */ @@ -37,16 +37,14 @@ extern "C" extern double __jack_time_ratio; - static inline jack_time_t GetMicroSeconds(void) - { + static inline jack_time_t GetMicroSeconds(void) { return (jack_time_t) (mach_absolute_time () * __jack_time_ratio); } /* This should only be called ONCE per process. */ extern void InitTime(); - static inline void JackSleep(int usec) - { + static inline void JackSleep(int usec) { usleep(usec); } @@ -60,8 +58,7 @@ extern "C" extern void InitTime(); - static void JackSleep(int usec) - { + static void JackSleep(int usec) { Sleep(usec / 1000); } @@ -71,25 +68,22 @@ extern "C" #include <unistd.h> - static inline void JackSleep(long usec) - { + static inline void JackSleep(long usec) { usleep(usec); } #ifdef GETCYCLE_TIME - #include "cycles.h" +#include "cycles.h" extern jack_time_t __jack_cpu_mhz; extern jack_time_t GetMhz(); extern void InitTime(); - static inline jack_time_t GetMicroSeconds(void) - { + static inline jack_time_t GetMicroSeconds(void) { return get_cycles() / __jack_cpu_mhz; } #else - #include <time.h> +#include <time.h> extern void InitTime(); - static inline jack_time_t GetMicroSeconds(void) - { + static inline jack_time_t GetMicroSeconds(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (jack_time_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000; diff --git a/common/JackTools.cpp b/common/JackTools.cpp index e294f056..b4d1e066 100644 --- a/common/JackTools.cpp +++ b/common/JackTools.cpp @@ -1,18 +1,18 @@ /* Copyright (C) 2001 Paul Davis - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -31,22 +31,22 @@ namespace Jack #define DEFAULT_TMP_DIR "/tmp" char* jack_tmpdir = (char*)DEFAULT_TMP_DIR; -int JackTools::GetPID() +int JackTools::GetPID() { #ifdef WIN32 - return _getpid(); + return _getpid(); #else - return getpid(); + return getpid(); #endif } -int JackTools::GetUID() +int JackTools::GetUID() { #ifdef WIN32 - return _getpid(); - //#error "No getuid function available" + return _getpid(); + //#error "No getuid function available" #else - return getuid(); + return getuid(); #endif } @@ -63,152 +63,151 @@ const char* JackTools::DefaultServerName() char* JackTools::UserDir() { - return ""; + return ""; } char* JackTools::ServerDir(const char* server_name, char* server_dir) { - return ""; + return ""; } void JackTools::CleanupFiles(const char* server_name) { - } int JackTools::GetTmpdir() { - return 0; + return 0; } #else char* JackTools::UserDir() { - static char user_dir[PATH_MAX + 1] = ""; - - /* format the path name on the first call */ - if (user_dir[0] == '\0') { - if (getenv ("JACK_PROMISCUOUS_SERVER")) { - snprintf(user_dir, sizeof(user_dir), "%s/jack", jack_tmpdir); - } else { - snprintf(user_dir, sizeof(user_dir), "%s/jack-%d", jack_tmpdir, GetUID()); - } - } - - return user_dir; + static char user_dir[PATH_MAX + 1] = ""; + + /* format the path name on the first call */ + if (user_dir[0] == '\0') { + if (getenv ("JACK_PROMISCUOUS_SERVER")) { + snprintf(user_dir, sizeof(user_dir), "%s/jack", jack_tmpdir); + } else { + snprintf(user_dir, sizeof(user_dir), "%s/jack-%d", jack_tmpdir, GetUID()); + } + } + + return user_dir; } /* returns the name of the per-server subdirectory of jack_user_dir() */ char* JackTools::ServerDir(const char* server_name, char* server_dir) { - /* format the path name into the suppled server_dir char array, - * assuming that server_dir is at least as large as PATH_MAX+1 */ + /* format the path name into the suppled server_dir char array, + * assuming that server_dir is at least as large as PATH_MAX+1 */ - snprintf(server_dir, PATH_MAX + 1, "%s/%s", UserDir(), server_name); - return server_dir; + snprintf(server_dir, PATH_MAX + 1, "%s/%s", UserDir(), server_name); + return server_dir; } void JackTools::CleanupFiles(const char* server_name) { DIR* dir; - struct dirent *dirent; - char dir_name[PATH_MAX + 1] = ""; - ServerDir(server_name, dir_name); - - /* On termination, we remove all files that jackd creates so - * subsequent attempts to start jackd will not believe that an - * instance is already running. If the server crashes or is - * terminated with SIGKILL, this is not possible. So, cleanup - * is also attempted when jackd starts. - * - * There are several tricky issues. First, the previous JACK - * server may have run for a different user ID, so its files - * may be inaccessible. This is handled by using a separate - * JACK_TMP_DIR subdirectory for each user. Second, there may - * be other servers running with different names. Each gets - * its own subdirectory within the per-user directory. The - * current process has already registered as `server_name', so - * we know there is no other server actively using that name. - */ - - /* nothing to do if the server directory does not exist */ - if ((dir = opendir(dir_name)) == NULL) { - return; - } - - /* unlink all the files in this directory, they are mine */ - while ((dirent = readdir(dir)) != NULL) { - - char fullpath[PATH_MAX + 1]; - - if ((strcmp(dirent->d_name, ".") == 0) || (strcmp (dirent->d_name, "..") == 0)) { - continue; - } - - snprintf(fullpath, sizeof(fullpath), "%s/%s", dir_name, dirent->d_name); - - if (unlink(fullpath)) { - jack_error("cannot unlink `%s' (%s)", fullpath, strerror(errno)); - } - } - - closedir(dir); - - /* now, delete the per-server subdirectory, itself */ - if (rmdir(dir_name)) { - jack_error("cannot remove `%s' (%s)", dir_name, strerror(errno)); - } - - /* finally, delete the per-user subdirectory, if empty */ - if (rmdir(UserDir())) { - if (errno != ENOTEMPTY) { - jack_error("cannot remove `%s' (%s)", UserDir(), strerror(errno)); - } - } + struct dirent *dirent; + char dir_name[PATH_MAX + 1] = ""; + ServerDir(server_name, dir_name); + + /* On termination, we remove all files that jackd creates so + * subsequent attempts to start jackd will not believe that an + * instance is already running. If the server crashes or is + * terminated with SIGKILL, this is not possible. So, cleanup + * is also attempted when jackd starts. + * + * There are several tricky issues. First, the previous JACK + * server may have run for a different user ID, so its files + * may be inaccessible. This is handled by using a separate + * JACK_TMP_DIR subdirectory for each user. Second, there may + * be other servers running with different names. Each gets + * its own subdirectory within the per-user directory. The + * current process has already registered as `server_name', so + * we know there is no other server actively using that name. + */ + + /* nothing to do if the server directory does not exist */ + if ((dir = opendir(dir_name)) == NULL) { + return; + } + + /* unlink all the files in this directory, they are mine */ + while ((dirent = readdir(dir)) != NULL) { + + char fullpath[PATH_MAX + 1]; + + if ((strcmp(dirent->d_name, ".") == 0) || (strcmp (dirent->d_name, "..") == 0)) { + continue; + } + + snprintf(fullpath, sizeof(fullpath), "%s/%s", dir_name, dirent->d_name); + + if (unlink(fullpath)) { + jack_error("cannot unlink `%s' (%s)", fullpath, strerror(errno)); + } + } + + closedir(dir); + + /* now, delete the per-server subdirectory, itself */ + if (rmdir(dir_name)) { + jack_error("cannot remove `%s' (%s)", dir_name, strerror(errno)); + } + + /* finally, delete the per-user subdirectory, if empty */ + if (rmdir(UserDir())) { + if (errno != ENOTEMPTY) { + jack_error("cannot remove `%s' (%s)", UserDir(), strerror(errno)); + } + } } int JackTools::GetTmpdir() { - FILE* in; - size_t len; - char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */ - - if ((in = popen("jackd -l", "r")) == NULL) { - return -1; - } - - if (fgets(buf, sizeof(buf), in) == NULL) { - fclose(in); - return -1; - } - - len = strlen(buf); - - if (buf[len - 1] != '\n') { - /* didn't get a whole line */ - fclose(in); - return -1; - } - - jack_tmpdir = (char *)malloc(len); - memcpy(jack_tmpdir, buf, len - 1); - jack_tmpdir[len - 1] = '\0'; - - fclose(in); - return 0; + FILE* in; + size_t len; + char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */ + + if ((in = popen("jackd -l", "r")) == NULL) { + return -1; + } + + if (fgets(buf, sizeof(buf), in) == NULL) { + fclose(in); + return -1; + } + + len = strlen(buf); + + if (buf[len - 1] != '\n') { + /* didn't get a whole line */ + fclose(in); + return -1; + } + + jack_tmpdir = (char *)malloc(len); + memcpy(jack_tmpdir, buf, len - 1); + jack_tmpdir[len - 1] = '\0'; + + fclose(in); + return 0; } #endif void JackTools::RewriteName(const char* name, char* new_name) { - size_t i; - for (i = 0; i < strlen(name); i++) { - if ((name[i] == '/') || (name[i] == '\\')) - new_name[i] = '_'; - else - new_name[i] = name[i]; - } - new_name[i] = '\0'; + size_t i; + for (i = 0; i < strlen(name); i++) { + if ((name[i] == '/') || (name[i] == '\\')) + new_name[i] = '_'; + else + new_name[i] = name[i]; + } + new_name[i] = '\0'; } diff --git a/common/JackTools.h b/common/JackTools.h index a9655f8c..6882d7bc 100644 --- a/common/JackTools.h +++ b/common/JackTools.h @@ -1,18 +1,18 @@ /* Copyright (C) 2001 Paul Davis - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -21,33 +21,34 @@ #define __JackTools__ #ifdef WIN32 - #include <windows.h> +#include <windows.h> #else - #include <sys/types.h> - #include <unistd.h> - #include <dirent.h> +#include <sys/types.h> +#include <unistd.h> +#include <dirent.h> #endif #ifdef __APPLE__ - #include <sys/syslimits.h> +#include <sys/syslimits.h> #endif namespace Jack { - struct JackTools { - - static int GetPID(); - static int GetUID(); - - static char* UserDir(); - static char* ServerDir(const char* server_name, char* server_dir); - static const char* DefaultServerName(); - static void CleanupFiles(const char* server_name); - static int GetTmpdir(); - static void RewriteName(const char* name, char* new_name); - - }; +struct JackTools +{ + + static int GetPID(); + static int GetUID(); + + static char* UserDir(); + static char* ServerDir(const char* server_name, char* server_dir); + static const char* DefaultServerName(); + static void CleanupFiles(const char* server_name); + static int GetTmpdir(); + static void RewriteName(const char* name, char* new_name); + +}; } #endif diff --git a/common/JackTransportEngine.cpp b/common/JackTransportEngine.cpp index f3c651d4..75de95dc 100644 --- a/common/JackTransportEngine.cpp +++ b/common/JackTransportEngine.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackTransportEngine.h" #include "JackClientControl.h" #include "JackError.h" -#include "JackTime.h" +#include "JackTime.h" #include <assert.h> #include <stdlib.h> diff --git a/common/JackTransportEngine.h b/common/JackTransportEngine.h index 4df41ae8..2f635b77 100644 --- a/common/JackTransportEngine.h +++ b/common/JackTransportEngine.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -37,17 +37,17 @@ typedef enum { /*! \brief The client transport structure. - + We have: - + - a "current" position - a "pending" position prepared by the server at each cycle - a "request" position wanted by a client - + At the beginning of a cycle the server needs to select a new current position. When a request and a pending position are available, - the resquest takes precedence on the pending one. The server atomically switches to the new position. + the resquest takes precedence on the pending one. The server atomically switches to the new position. The current position can be read by clients. - + We use a JackAtomicArrayState pattern that allows to manage several "next" states independantly. */ diff --git a/common/JackTypes.h b/common/JackTypes.h index af471192..561bd4bc 100644 --- a/common/JackTypes.h +++ b/common/JackTypes.h @@ -1,18 +1,18 @@ /* Copyright (C) 2001 Paul Davis - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. $Id: JackTypes.h,v 1.2.2.1 2006/06/20 14:44:00 letz Exp $ @@ -32,9 +32,9 @@ typedef signed long SInt32; #ifdef WIN32 #include <windows.h> -typedef ULONGLONG UInt64;
+typedef ULONGLONG UInt64; typedef unsigned short uint16_t; -#else
+#else #include <stdint.h> typedef unsigned long long UInt64; #endif diff --git a/common/Jackdmp.cpp b/common/Jackdmp.cpp index ad6e9d4d..2eba33b6 100644 --- a/common/Jackdmp.cpp +++ b/common/Jackdmp.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -62,34 +62,34 @@ static void silent_jack_error_callback(const char *desc) static void copyright(FILE* file) { fprintf(file, "jackdmp " VERSION "\n" - "Copyright 2001-2005 Paul Davis and others.\n" - "Copyright 2004-2008 Grame.\n" - "jackdmp comes with ABSOLUTELY NO WARRANTY\n" - "This is free software, and you are welcome to redistribute it\n" - "under certain conditions; see the file COPYING for details\n"); + "Copyright 2001-2005 Paul Davis and others.\n" + "Copyright 2004-2008 Grame.\n" + "jackdmp comes with ABSOLUTELY NO WARRANTY\n" + "This is free software, and you are welcome to redistribute it\n" + "under certain conditions; see the file COPYING for details\n"); } static void usage(FILE* file) { copyright(file); fprintf(file, "\n" - "usage: jackdmp [ --realtime OR -R [ --realtime-priority OR -P priority ] ]\n" - " [ --name OR -n server-name ]\n" - // " [ --no-mlock OR -m ]\n" - // " [ --unlock OR -u ]\n" - " [ --timeout OR -t client-timeout-in-msecs ]\n" - " [ --loopback OR -L loopback-port-number ]\n" - // " [ --port-max OR -p maximum-number-of-ports]\n" - " [ --verbose OR -v ]\n" - " [ --replace-registry OR -r ]\n" - " [ --silent OR -s ]\n" - " [ --sync OR -S ]\n" - " [ --temporary OR -T ]\n" - " [ --version OR -V ]\n" - " -d driver [ ... driver args ... ]\n" - " where driver can be `alsa', `coreaudio', 'portaudio' or `dummy'\n" - " jackdmp -d driver --help\n" - " to display options for each driver\n\n"); + "usage: jackdmp [ --realtime OR -R [ --realtime-priority OR -P priority ] ]\n" + " [ --name OR -n server-name ]\n" + // " [ --no-mlock OR -m ]\n" + // " [ --unlock OR -u ]\n" + " [ --timeout OR -t client-timeout-in-msecs ]\n" + " [ --loopback OR -L loopback-port-number ]\n" + // " [ --port-max OR -p maximum-number-of-ports]\n" + " [ --verbose OR -v ]\n" + " [ --replace-registry OR -r ]\n" + " [ --silent OR -s ]\n" + " [ --sync OR -S ]\n" + " [ --temporary OR -T ]\n" + " [ --version OR -V ]\n" + " -d driver [ ... driver args ... ]\n" + " where driver can be `alsa', `coreaudio', 'portaudio' or `dummy'\n" + " jackdmp -d driver --help\n" + " to display options for each driver\n\n"); } @@ -148,7 +148,8 @@ int main(int argc, char* argv[]) jack_driver_desc_t* driver_desc; const char *options = "-ad:P:uvrshVRL:STFl:t:mn:p:"; struct option long_options[] = { - { "driver", 1, 0, 'd' }, + { "driver", 1, 0, 'd' + }, { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "port-max", 1, 0, 'p' }, @@ -156,7 +157,7 @@ int main(int argc, char* argv[]) { "name", 0, 0, 'n' }, { "unlock", 0, 0, 'u' }, { "realtime", 0, 0, 'R' }, - { "replace-registry", 0, 0, 'r' }, + { "replace-registry", 0, 0, 'r' }, { "loopback", 0, 0, 'L' }, { "realtime-priority", 1, 0, 'P' }, { "timeout", 1, 0, 't' }, @@ -174,7 +175,7 @@ int main(int argc, char* argv[]) JSList* driver_params; int driver_nargs = 1; int show_version = 0; - int replace_registry = 0; + int replace_registry = 0; int sync = 0; int rc, i; @@ -216,11 +217,11 @@ int main(int argc, char* argv[]) case 'P': realtime_priority = atoi(optarg); break; - - case 'r': - replace_registry = 1; - break; - + + case 'r': + replace_registry = 1; + break; + case 'R': realtime = 1; break; @@ -290,7 +291,7 @@ int main(int argc, char* argv[]) if (driver_nargs == 0) { fprintf(stderr, "No driver specified ... hmm. JACK won't do" - " anything when run like this.\n"); + " anything when run like this.\n"); return -1; } @@ -302,7 +303,7 @@ int main(int argc, char* argv[]) } if (jack_parse_driver_params(driver_desc, driver_nargs, - driver_args, &driver_params)) { + driver_args, &driver_params)) { exit(0); } @@ -360,16 +361,16 @@ int main(int argc, char* argv[]) } #ifdef __APPLE__ - CFStringRef ref = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); + CFStringRef ref = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); // Send notification to be used in the JackRouter plugin CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), - CFSTR("com.grame.jackserver.start"), - ref, - NULL, - kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); - CFRelease(ref); + CFSTR("com.grame.jackserver.start"), + ref, + NULL, + kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); + CFRelease(ref); #endif - + // install a do-nothing handler because otherwise pthreads // behaviour is undefined when we enter sigwait. @@ -410,22 +411,22 @@ int main(int argc, char* argv[]) // bugs that cause segfaults etc. during shutdown. sigprocmask(SIG_UNBLOCK, &signals, 0); } - - JackStop(); + + JackStop(); jack_cleanup_shm(); JackTools::CleanupFiles(server_name); jack_unregister_server(server_name); #ifdef __APPLE__ - CFStringRef ref1 = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); + CFStringRef ref1 = CFStringCreateWithCString(NULL, server_name, kCFStringEncodingMacRoman); // Send notification to be used in the JackRouter plugin CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), - CFSTR("com.grame.jackserver.stop"), - ref1, - NULL, - kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); - CFRelease(ref1); + CFSTR("com.grame.jackserver.stop"), + ref1, + NULL, + kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); + CFRelease(ref1); #endif return 1; diff --git a/common/cycles.h b/common/cycles.h index 96dcbb4d..2913b1da 100644 --- a/common/cycles.h +++ b/common/cycles.h @@ -1,7 +1,7 @@ /* Copyright (C) 2001 Paul Davis Code derived from various headers from the Linux kernel - + 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 @@ -34,7 +34,7 @@ * We only use the low 32 bits, and we'd simply better make sure * that we reschedule before that wraps. Scheduling at least every * four billion cycles just basically sounds like a good idea, - * regardless of how fast the machine is. + * regardless of how fast the machine is. */ #ifdef __linux__ diff --git a/common/driver_interface.h b/common/driver_interface.h index 13a642d6..655b9696 100644 --- a/common/driver_interface.h +++ b/common/driver_interface.h @@ -1,18 +1,18 @@ /* Copyright (C) 2003 Bob Ham <rah@bash.sh> - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/driver_parse.h b/common/driver_parse.h index e6b6ef80..8ec74d68 100644 --- a/common/driver_parse.h +++ b/common/driver_parse.h @@ -1,6 +1,6 @@ /* Copyright (C) 2003 Bob Ham <rah@bash.sh - + 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 diff --git a/common/jslist.h b/common/jslist.h index 45e8c266..e948311e 100644 --- a/common/jslist.h +++ b/common/jslist.h @@ -10,14 +10,14 @@ it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/common/shm.h b/common/shm.h index 90efba7d..f3bd1138 100644 --- a/common/shm.h +++ b/common/shm.h @@ -43,7 +43,7 @@ extern "C" typedef char shm_name_t[SHM_NAME_MAX]; typedef shm_name_t jack_shm_id_t; -#else +#else /* System V SHM */ typedef int jack_shm_id_t; #endif /* SHM type */ @@ -117,7 +117,7 @@ extern "C" */ typedef struct _jack_shm_info { jack_shm_registry_index_t index; /* offset into the registry */ - size_t size; + size_t size; void *attached_at; /* address where attached */ } jack_shm_info_t; diff --git a/common/timestamps.h b/common/timestamps.h index cbef55f0..984e14c8 100644 --- a/common/timestamps.h +++ b/common/timestamps.h @@ -1,18 +1,18 @@ /* Copyright (C) 2002 Paul Davis - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -23,13 +23,14 @@ #include <stdio.h> #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void jack_init_timestamps (unsigned long howmany); -void jack_timestamp (const char *what); -void jack_dump_timestamps (FILE *out); -void jack_reset_timestamps (); + void jack_init_timestamps (unsigned long howmany); + void jack_timestamp (const char *what); + void jack_dump_timestamps (FILE *out); + void jack_reset_timestamps (); #ifdef __cplusplus } diff --git a/common/transport_types.h b/common/transport_types.h index 54337935..d3824f63 100644 --- a/common/transport_types.h +++ b/common/transport_types.h @@ -1,19 +1,19 @@ /* Copyright (C) 2002 Paul Davis Copyright (C) 2003 Jack O'Quin - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. $Id: transport_types.h,v 1.1.2.2 2006/06/20 14:44:00 letz Exp $ @@ -86,7 +86,7 @@ extern "C" /* JackPositionTimecode fields: (EXPERIMENTAL: could change) */ double frame_time; /**< current time in seconds */ double next_time; /**< next sequential frame_time - (unless repositioned) */ + (unless repositioned) */ /* For binary compatibility, new fields should be allocated from * this padding area with new valid bits controlling access, so diff --git a/common/varargs.h b/common/varargs.h index 80d8f9fe..5957873c 100644 --- a/common/varargs.h +++ b/common/varargs.h @@ -1,18 +1,18 @@ /* * Copyright (C) 2004 Jack O'Quin -* +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 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. * */ @@ -53,10 +53,10 @@ extern "C" jack_varargs_init (va); if ((options & JackServerName)) { - char *sn = va_arg(ap, char *); - if (sn) - va->server_name = sn; - } + char *sn = va_arg(ap, char *); + if (sn) + va->server_name = sn; + } if ((options & JackLoadName)) va->load_name = va_arg(ap, char *); if ((options & JackLoadInit)) diff --git a/linux/alsa/JackAlsaDriver.cpp b/linux/alsa/JackAlsaDriver.cpp index 94e29cce..a7ea9f76 100644 --- a/linux/alsa/JackAlsaDriver.cpp +++ b/linux/alsa/JackAlsaDriver.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004 Grame This program is free software; you can redistribute it and/or modify @@ -47,7 +47,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "usx2y.h" #include "generic.h" -#include "memops.h" +#include "memops.h" #include "JackPosixThread.h" @@ -255,34 +255,34 @@ JackAlsaDriver::alsa_driver_setup_io_function_pointers (alsa_driver_t *driver) } switch (driver->dither) { - case Rectangular: - JackLog("Rectangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_rect_d16_sSs: - sample_move_dither_rect_d16_sS; - break; - - case Triangular: - JackLog("Triangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_tri_d16_sSs: - sample_move_dither_tri_d16_sS; - break; - - case Shaped: - JackLog("Noise-shaped dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_shaped_d16_sSs: - sample_move_dither_shaped_d16_sS; - break; - - default: - driver->write_via_copy = driver->quirk_bswap? - sample_move_d16_sSs : sample_move_d16_sS; - break; - } - break; - + case Rectangular: + JackLog("Rectangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_rect_d16_sSs : + sample_move_dither_rect_d16_sS; + break; + + case Triangular: + JackLog("Triangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_tri_d16_sSs : + sample_move_dither_tri_d16_sS; + break; + + case Shaped: + JackLog("Noise-shaped dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_shaped_d16_sSs : + sample_move_dither_shaped_d16_sS; + break; + + default: + driver->write_via_copy = driver->quirk_bswap ? + sample_move_d16_sSs : sample_move_d16_sS; + break; + } + break; + case 3: if (driver->playback_interleaved) { driver->channel_copy = memcpy_interleave_d24_s24; @@ -291,34 +291,34 @@ JackAlsaDriver::alsa_driver_setup_io_function_pointers (alsa_driver_t *driver) } switch (driver->dither) { - case Rectangular: - JackLog("Rectangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_rect_d24_sSs: - sample_move_dither_rect_d24_sS; - break; - - case Triangular: - JackLog("Triangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_tri_d24_sSs: - sample_move_dither_tri_d24_sS; - break; - - case Shaped: - JackLog("Noise-shaped dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_shaped_d24_sSs: - sample_move_dither_shaped_d24_sS; - break; - - default: - driver->write_via_copy = driver->quirk_bswap? - sample_move_d24_sSs : sample_move_d24_sS; - break; - } - break; - + case Rectangular: + JackLog("Rectangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_rect_d24_sSs : + sample_move_dither_rect_d24_sS; + break; + + case Triangular: + JackLog("Triangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_tri_d24_sSs : + sample_move_dither_tri_d24_sS; + break; + + case Shaped: + JackLog("Noise-shaped dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_shaped_d24_sSs : + sample_move_dither_shaped_d24_sS; + break; + + default: + driver->write_via_copy = driver->quirk_bswap ? + sample_move_d24_sSs : sample_move_d24_sS; + break; + } + break; + case 4: if (driver->playback_interleaved) { driver->channel_copy = memcpy_interleave_d32_s32; @@ -327,49 +327,49 @@ JackAlsaDriver::alsa_driver_setup_io_function_pointers (alsa_driver_t *driver) } switch (driver->dither) { - case Rectangular: - JackLog("Rectangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_rect_d32u24_sSs: - sample_move_dither_rect_d32u24_sS; - break; - - case Triangular: - JackLog("Triangular dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_tri_d32u24_sSs: - sample_move_dither_tri_d32u24_sS; - break; - - case Shaped: - JackLog("Noise-shaped dithering at 16 bits\n"); - driver->write_via_copy = driver->quirk_bswap? - sample_move_dither_shaped_d32u24_sSs: - sample_move_dither_shaped_d32u24_sS; - break; - - default: - driver->write_via_copy = driver->quirk_bswap? - sample_move_d32u24_sSs : sample_move_d32u24_sS; - break; - } - break; - } + case Rectangular: + JackLog("Rectangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_rect_d32u24_sSs : + sample_move_dither_rect_d32u24_sS; + break; + + case Triangular: + JackLog("Triangular dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_tri_d32u24_sSs : + sample_move_dither_tri_d32u24_sS; + break; + + case Shaped: + JackLog("Noise-shaped dithering at 16 bits\n"); + driver->write_via_copy = driver->quirk_bswap ? + sample_move_dither_shaped_d32u24_sSs : + sample_move_dither_shaped_d32u24_sS; + break; + + default: + driver->write_via_copy = driver->quirk_bswap ? + sample_move_d32u24_sSs : sample_move_d32u24_sS; + break; + } + break; + } switch (driver->capture_sample_bytes) { - case 2: - driver->read_via_copy = driver->quirk_bswap? - sample_move_dS_s16s : sample_move_dS_s16; - break; - case 3: - driver->read_via_copy = driver->quirk_bswap? - sample_move_dS_s24s : sample_move_dS_s24; - break; - case 4: - driver->read_via_copy = driver->quirk_bswap? - sample_move_dS_s32u24s : sample_move_dS_s32u24; - break; - } + case 2: + driver->read_via_copy = driver->quirk_bswap ? + sample_move_dS_s16s : sample_move_dS_s16; + break; + case 3: + driver->read_via_copy = driver->quirk_bswap ? + sample_move_dS_s24s : sample_move_dS_s24; + break; + case 4: + driver->read_via_copy = driver->quirk_bswap ? + sample_move_dS_s32u24s : sample_move_dS_s32u24; + break; + } } int @@ -383,232 +383,233 @@ JackAlsaDriver::alsa_driver_configure_stream (alsa_driver_t *driver, char *devic unsigned long sample_width) { int err, format; - unsigned int frame_rate; - snd_pcm_uframes_t stop_th; - static struct { - char Name[32]; - snd_pcm_format_t format; - int swapped; - } formats[] = { - {"32bit little-endian", SND_PCM_FORMAT_S32_LE, IS_LE}, - {"32bit big-endian", SND_PCM_FORMAT_S32_BE, IS_BE}, - {"24bit little-endian", SND_PCM_FORMAT_S24_3LE, IS_LE}, - {"24bit big-endian", SND_PCM_FORMAT_S24_3BE, IS_BE}, - {"16bit little-endian", SND_PCM_FORMAT_S16_LE, IS_LE}, - {"16bit big-endian", SND_PCM_FORMAT_S16_BE, IS_BE}, - }; + unsigned int frame_rate; + snd_pcm_uframes_t stop_th; + static struct { + char Name[32]; + snd_pcm_format_t format; + int swapped; + } + formats[] = { + {"32bit little-endian", SND_PCM_FORMAT_S32_LE, IS_LE}, + {"32bit big-endian", SND_PCM_FORMAT_S32_BE, IS_BE}, + {"24bit little-endian", SND_PCM_FORMAT_S24_3LE, IS_LE}, + {"24bit big-endian", SND_PCM_FORMAT_S24_3BE, IS_BE}, + {"16bit little-endian", SND_PCM_FORMAT_S16_LE, IS_LE}, + {"16bit big-endian", SND_PCM_FORMAT_S16_BE, IS_BE}, + }; #define NUMFORMATS (sizeof(formats)/sizeof(formats[0])) #define FIRST_16BIT_FORMAT 4 - if ((err = snd_pcm_hw_params_any (handle, hw_params)) < 0) { - jack_error ("ALSA: no playback configurations available (%s)", - snd_strerror (err)); - return -1; - } - - if ((err = snd_pcm_hw_params_set_periods_integer (handle, hw_params)) - < 0) { - jack_error ("ALSA: cannot restrict period size to integral" - " value."); - return -1; - } - - if ((err = snd_pcm_hw_params_set_access (handle, hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED)) < 0) { - if ((err = snd_pcm_hw_params_set_access (handle, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0) { - if ((err = snd_pcm_hw_params_set_access ( - handle, hw_params, - SND_PCM_ACCESS_MMAP_COMPLEX)) < 0) { - jack_error ("ALSA: mmap-based access is not possible" - " for the %s " - "stream of this audio interface", - stream_name); - return -1; - } - } - } - - format = (sample_width == 4) ? 0 : NUMFORMATS - 1; - - while (1) { - if ((err = snd_pcm_hw_params_set_format ( - handle, hw_params, formats[format].format)) < 0) { - - if ((sample_width == 4 - ? format++ >= NUMFORMATS - 1 - : format-- <= 0)) { - jack_error ("Sorry. The audio interface \"%s\"" - " doesn't support any of the" - " hardware sample formats that" - " JACK's alsa-driver can use.", - device_name); - return -1; - } - } else { - if (formats[format].swapped) { - driver->quirk_bswap = 1; - } else { - driver->quirk_bswap = 0; - } - jack_error ("ALSA: final selected sample format for %s: %s", stream_name, formats[format].Name); - break; - } - } - - frame_rate = driver->frame_rate ; - err = snd_pcm_hw_params_set_rate_near (handle, hw_params, - &frame_rate, NULL) ; - driver->frame_rate = frame_rate ; - if (err < 0) { - jack_error ("ALSA: cannot set sample/frame rate to %ld for %s", driver->frame_rate, stream_name); - return -1; - } - if (!*nchns) { - /*if not user-specified, try to find the maximum - * number of channels */ - unsigned int channels_max ; - err = snd_pcm_hw_params_get_channels_max (hw_params, - &channels_max); - *nchns = channels_max ; - - if (*nchns > 1024) { - - /* the hapless user is an unwitting victim of - the "default" ALSA PCM device, which can - support up to 16 million channels. since - they can't be bothered to set up a proper - default device, limit the number of - channels for them to a sane default. - */ - - jack_error ( -"You appear to be using the ALSA software \"plug\" layer, probably\n" -"a result of using the \"default\" ALSA device. This is less\n" -"efficient than it could be. Consider using a hardware device\n" -"instead rather than using the plug layer. Usually the name of the\n" -"hardware device that corresponds to the first sound card is hw:0\n" - ); - *nchns = 2; - } - } - - if ((err = snd_pcm_hw_params_set_channels (handle, hw_params, - *nchns)) < 0) { - jack_error ("ALSA: cannot set channel count to %u for %s", - *nchns, stream_name); - return -1; - } - - if ((err = snd_pcm_hw_params_set_period_size (handle, hw_params, - driver->frames_per_cycle, - 0)) - < 0) { - jack_error ("ALSA: cannot set period size to %ld frames for %s", driver->frames_per_cycle, stream_name); - return -1; - } - - *nperiodsp = driver->user_nperiods; - snd_pcm_hw_params_set_periods_min (handle, hw_params, nperiodsp, NULL); - if (*nperiodsp < driver->user_nperiods) - *nperiodsp = driver->user_nperiods; - if (snd_pcm_hw_params_set_periods_near (handle, hw_params, - nperiodsp, NULL) < 0) { - jack_error ("ALSA: cannot set number of periods to %u for %s", - *nperiodsp, stream_name); - return -1; - } - - if (*nperiodsp < driver->user_nperiods) { - jack_error ("ALSA: got smaller periods %u than %u for %s", - *nperiodsp, (unsigned int) driver->user_nperiods, - stream_name); - return -1; - } - jack_error ("ALSA: use %d periods for %s", *nperiodsp, stream_name); - -/* - if (!jack_power_of_two(driver->frames_per_cycle)) { - jack_error("JACK: frames must be a power of two " - "(64, 512, 1024, ...)\n"); - return -1; - } -*/ - if ((err = snd_pcm_hw_params_set_buffer_size (handle, hw_params, - *nperiodsp * - driver->frames_per_cycle)) - < 0) { - jack_error ("ALSA: cannot set buffer length to %ld for %s", *nperiodsp * driver->frames_per_cycle, - stream_name); - return -1; - } - - if ((err = snd_pcm_hw_params (handle, hw_params)) < 0) { - jack_error ("ALSA: cannot set hardware parameters for %s", - stream_name); - return -1; - } - - snd_pcm_sw_params_current (handle, sw_params); - - if ((err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, - 0U)) < 0) { - jack_error ("ALSA: cannot set start mode for %s", stream_name); - return -1; - } - - stop_th = *nperiodsp * driver->frames_per_cycle; - if (driver->soft_mode) { - stop_th = (snd_pcm_uframes_t)-1; - } - - if ((err = snd_pcm_sw_params_set_stop_threshold ( - handle, sw_params, stop_th)) < 0) { - jack_error ("ALSA: cannot set stop mode for %s", - stream_name); - return -1; - } - - if ((err = snd_pcm_sw_params_set_silence_threshold ( - handle, sw_params, 0)) < 0) { - jack_error ("ALSA: cannot set silence threshold for %s", - stream_name); - return -1; - } + if ((err = snd_pcm_hw_params_any (handle, hw_params)) < 0) { + jack_error ("ALSA: no playback configurations available (%s)", + snd_strerror (err)); + return -1; + } + + if ((err = snd_pcm_hw_params_set_periods_integer (handle, hw_params)) + < 0) { + jack_error ("ALSA: cannot restrict period size to integral" + " value."); + return -1; + } + + if ((err = snd_pcm_hw_params_set_access (handle, hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED)) < 0) { + if ((err = snd_pcm_hw_params_set_access (handle, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0) { + if ((err = snd_pcm_hw_params_set_access ( + handle, hw_params, + SND_PCM_ACCESS_MMAP_COMPLEX)) < 0) { + jack_error ("ALSA: mmap-based access is not possible" + " for the %s " + "stream of this audio interface", + stream_name); + return -1; + } + } + } + + format = (sample_width == 4) ? 0 : NUMFORMATS - 1; + + while (1) { + if ((err = snd_pcm_hw_params_set_format ( + handle, hw_params, formats[format].format)) < 0) { + + if ((sample_width == 4 + ? format++ >= NUMFORMATS - 1 + : format-- <= 0)) { + jack_error ("Sorry. The audio interface \"%s\"" + " doesn't support any of the" + " hardware sample formats that" + " JACK's alsa-driver can use.", + device_name); + return -1; + } + } else { + if (formats[format].swapped) { + driver->quirk_bswap = 1; + } else { + driver->quirk_bswap = 0; + } + jack_error ("ALSA: final selected sample format for %s: %s", stream_name, formats[format].Name); + break; + } + } + + frame_rate = driver->frame_rate ; + err = snd_pcm_hw_params_set_rate_near (handle, hw_params, + &frame_rate, NULL) ; + driver->frame_rate = frame_rate ; + if (err < 0) { + jack_error ("ALSA: cannot set sample/frame rate to %ld for %s", driver->frame_rate, stream_name); + return -1; + } + if (!*nchns) { + /*if not user-specified, try to find the maximum + * number of channels */ + unsigned int channels_max ; + err = snd_pcm_hw_params_get_channels_max (hw_params, + &channels_max); + *nchns = channels_max ; + + if (*nchns > 1024) { + + /* the hapless user is an unwitting victim of + the "default" ALSA PCM device, which can + support up to 16 million channels. since + they can't be bothered to set up a proper + default device, limit the number of + channels for them to a sane default. + */ + + jack_error ( + "You appear to be using the ALSA software \"plug\" layer, probably\n" + "a result of using the \"default\" ALSA device. This is less\n" + "efficient than it could be. Consider using a hardware device\n" + "instead rather than using the plug layer. Usually the name of the\n" + "hardware device that corresponds to the first sound card is hw:0\n" + ); + *nchns = 2; + } + } + + if ((err = snd_pcm_hw_params_set_channels (handle, hw_params, + *nchns)) < 0) { + jack_error ("ALSA: cannot set channel count to %u for %s", + *nchns, stream_name); + return -1; + } + + if ((err = snd_pcm_hw_params_set_period_size (handle, hw_params, + driver->frames_per_cycle, + 0)) + < 0) { + jack_error ("ALSA: cannot set period size to %ld frames for %s", driver->frames_per_cycle, stream_name); + return -1; + } + + *nperiodsp = driver->user_nperiods; + snd_pcm_hw_params_set_periods_min (handle, hw_params, nperiodsp, NULL); + if (*nperiodsp < driver->user_nperiods) + *nperiodsp = driver->user_nperiods; + if (snd_pcm_hw_params_set_periods_near (handle, hw_params, + nperiodsp, NULL) < 0) { + jack_error ("ALSA: cannot set number of periods to %u for %s", + *nperiodsp, stream_name); + return -1; + } + + if (*nperiodsp < driver->user_nperiods) { + jack_error ("ALSA: got smaller periods %u than %u for %s", + *nperiodsp, (unsigned int) driver->user_nperiods, + stream_name); + return -1; + } + jack_error ("ALSA: use %d periods for %s", *nperiodsp, stream_name); + + /* + if (!jack_power_of_two(driver->frames_per_cycle)) { + jack_error("JACK: frames must be a power of two " + "(64, 512, 1024, ...)\n"); + return -1; + } + */ + if ((err = snd_pcm_hw_params_set_buffer_size (handle, hw_params, + *nperiodsp * + driver->frames_per_cycle)) + < 0) { + jack_error ("ALSA: cannot set buffer length to %ld for %s", *nperiodsp * driver->frames_per_cycle, + stream_name); + return -1; + } + + if ((err = snd_pcm_hw_params (handle, hw_params)) < 0) { + jack_error ("ALSA: cannot set hardware parameters for %s", + stream_name); + return -1; + } + + snd_pcm_sw_params_current (handle, sw_params); + + if ((err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, + 0U)) < 0) { + jack_error ("ALSA: cannot set start mode for %s", stream_name); + return -1; + } + + stop_th = *nperiodsp * driver->frames_per_cycle; + if (driver->soft_mode) { + stop_th = (snd_pcm_uframes_t) - 1; + } + + if ((err = snd_pcm_sw_params_set_stop_threshold ( + handle, sw_params, stop_th)) < 0) { + jack_error ("ALSA: cannot set stop mode for %s", + stream_name); + return -1; + } + + if ((err = snd_pcm_sw_params_set_silence_threshold ( + handle, sw_params, 0)) < 0) { + jack_error ("ALSA: cannot set silence threshold for %s", + stream_name); + return -1; + } #if 0 - fprintf (stderr, "set silence size to %lu * %lu = %lu\n", - driver->frames_per_cycle, *nperiodsp, - driver->frames_per_cycle * *nperiodsp); - - if ((err = snd_pcm_sw_params_set_silence_size ( - handle, sw_params, - driver->frames_per_cycle * *nperiodsp)) < 0) { - jack_error ("ALSA: cannot set silence size for %s", - stream_name); - return -1; - } + fprintf (stderr, "set silence size to %lu * %lu = %lu\n", + driver->frames_per_cycle, *nperiodsp, + driver->frames_per_cycle * *nperiodsp); + + if ((err = snd_pcm_sw_params_set_silence_size ( + handle, sw_params, + driver->frames_per_cycle * *nperiodsp)) < 0) { + jack_error ("ALSA: cannot set silence size for %s", + stream_name); + return -1; + } #endif - if (handle == driver->playback_handle) - err = snd_pcm_sw_params_set_avail_min ( - handle, sw_params, - driver->frames_per_cycle - * (*nperiodsp - driver->user_nperiods + 1)); - else - err = snd_pcm_sw_params_set_avail_min ( - handle, sw_params, driver->frames_per_cycle); - - if (err < 0) { - jack_error ("ALSA: cannot set avail min for %s", stream_name); - return -1; - } - - if ((err = snd_pcm_sw_params (handle, sw_params)) < 0) { - jack_error ("ALSA: cannot set software parameters for %s\n", - stream_name); - return -1; - } - - return 0; + if (handle == driver->playback_handle) + err = snd_pcm_sw_params_set_avail_min ( + handle, sw_params, + driver->frames_per_cycle + * (*nperiodsp - driver->user_nperiods + 1)); + else + err = snd_pcm_sw_params_set_avail_min ( + handle, sw_params, driver->frames_per_cycle); + + if (err < 0) { + jack_error ("ALSA: cannot set avail min for %s", stream_name); + return -1; + } + + if ((err = snd_pcm_sw_params (handle, sw_params)) < 0) { + jack_error ("ALSA: cannot set software parameters for %s\n", + stream_name); + return -1; + } + + return 0; } int @@ -732,7 +733,7 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, PRIu32 " frames but got %u frames for playback", driver->frames_per_cycle, p_period_size); - */ + */ return -1; } } @@ -758,7 +759,7 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, PRIu32 " frames but got %uc frames for capture", driver->frames_per_cycle, p_period_size); - */ + */ return -1; } } @@ -773,11 +774,11 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, if (driver->playback_handle) { switch (driver->playback_sample_format) { case SND_PCM_FORMAT_S32_LE: - case SND_PCM_FORMAT_S24_3LE: - case SND_PCM_FORMAT_S24_3BE: - case SND_PCM_FORMAT_S16_LE: - case SND_PCM_FORMAT_S32_BE: - case SND_PCM_FORMAT_S16_BE: + case SND_PCM_FORMAT_S24_3LE: + case SND_PCM_FORMAT_S24_3BE: + case SND_PCM_FORMAT_S16_LE: + case SND_PCM_FORMAT_S32_BE: + case SND_PCM_FORMAT_S16_BE: break; default: @@ -790,11 +791,11 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, if (driver->capture_handle) { switch (driver->capture_sample_format) { case SND_PCM_FORMAT_S32_LE: - case SND_PCM_FORMAT_S24_3LE: - case SND_PCM_FORMAT_S24_3BE: - case SND_PCM_FORMAT_S16_LE: - case SND_PCM_FORMAT_S32_BE: - case SND_PCM_FORMAT_S16_BE: + case SND_PCM_FORMAT_S24_3LE: + case SND_PCM_FORMAT_S24_3BE: + case SND_PCM_FORMAT_S16_LE: + case SND_PCM_FORMAT_S32_BE: + case SND_PCM_FORMAT_S16_BE: break; default: @@ -829,8 +830,8 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, driver->alsa_name_capture); return -1; } - } - + } + if (driver->playback_nchannels > driver->capture_nchannels) { driver->max_nchannels = driver->playback_nchannels; driver->user_nchannels = driver->capture_nchannels; @@ -904,7 +905,7 @@ JackAlsaDriver::alsa_driver_set_parameters (alsa_driver_t *driver, driver->engine->set_buffer_size (driver->engine, driver->frames_per_cycle); } - */ + */ return 0; } @@ -928,173 +929,173 @@ JackAlsaDriver::alsa_driver_get_channel_addresses (alsa_driver_t *driver, snd_pcm_uframes_t *capture_offset, snd_pcm_uframes_t *playback_offset) { - unsigned long err; - channel_t chn; - - if (capture_avail) { - if ((err = snd_pcm_mmap_begin ( - driver->capture_handle, &driver->capture_areas, - (snd_pcm_uframes_t *) capture_offset, - (snd_pcm_uframes_t *) capture_avail)) < 0) { - jack_error ("ALSA: %s: mmap areas info error", - driver->alsa_name_capture); - return -1; - } - - for (chn = 0; chn < driver->capture_nchannels; chn++) { - const snd_pcm_channel_area_t *a = - &driver->capture_areas[chn]; - driver->capture_addr[chn] = (char *) a->addr - + ((a->first + a->step * *capture_offset) / 8); - driver->capture_interleave_skip[chn] = (unsigned long ) (a->step / 8); - } - } - - if (playback_avail) { - if ((err = snd_pcm_mmap_begin ( - driver->playback_handle, &driver->playback_areas, - (snd_pcm_uframes_t *) playback_offset, - (snd_pcm_uframes_t *) playback_avail)) < 0) { - jack_error ("ALSA: %s: mmap areas info error ", - driver->alsa_name_playback); - return -1; - } - - for (chn = 0; chn < driver->playback_nchannels; chn++) { - const snd_pcm_channel_area_t *a = - &driver->playback_areas[chn]; - driver->playback_addr[chn] = (char *) a->addr - + ((a->first + a->step * *playback_offset) / 8); - driver->playback_interleave_skip[chn] = (unsigned long ) (a->step / 8); - } - } - - return 0; + unsigned long err; + channel_t chn; + + if (capture_avail) { + if ((err = snd_pcm_mmap_begin ( + driver->capture_handle, &driver->capture_areas, + (snd_pcm_uframes_t *) capture_offset, + (snd_pcm_uframes_t *) capture_avail)) < 0) { + jack_error ("ALSA: %s: mmap areas info error", + driver->alsa_name_capture); + return -1; + } + + for (chn = 0; chn < driver->capture_nchannels; chn++) { + const snd_pcm_channel_area_t *a = + &driver->capture_areas[chn]; + driver->capture_addr[chn] = (char *) a->addr + + ((a->first + a->step * *capture_offset) / 8); + driver->capture_interleave_skip[chn] = (unsigned long ) (a->step / 8); + } + } + + if (playback_avail) { + if ((err = snd_pcm_mmap_begin ( + driver->playback_handle, &driver->playback_areas, + (snd_pcm_uframes_t *) playback_offset, + (snd_pcm_uframes_t *) playback_avail)) < 0) { + jack_error ("ALSA: %s: mmap areas info error ", + driver->alsa_name_playback); + return -1; + } + + for (chn = 0; chn < driver->playback_nchannels; chn++) { + const snd_pcm_channel_area_t *a = + &driver->playback_areas[chn]; + driver->playback_addr[chn] = (char *) a->addr + + ((a->first + a->step * *playback_offset) / 8); + driver->playback_interleave_skip[chn] = (unsigned long ) (a->step / 8); + } + } + + return 0; } int JackAlsaDriver::alsa_driver_start (alsa_driver_t *driver) { int err; - snd_pcm_uframes_t poffset, pavail; - channel_t chn; - - driver->poll_last = 0; - driver->poll_next = 0; - - if (driver->playback_handle) { - if ((err = snd_pcm_prepare (driver->playback_handle)) < 0) { - jack_error ("ALSA: prepare error for playback on " - "\"%s\" (%s)", driver->alsa_name_playback, - snd_strerror(err)); - return -1; - } - } - - if ((driver->capture_handle && driver->capture_and_playback_not_synced) - || !driver->playback_handle) { - if ((err = snd_pcm_prepare (driver->capture_handle)) < 0) { - jack_error ("ALSA: prepare error for capture on \"%s\"" - " (%s)", driver->alsa_name_capture, - snd_strerror(err)); - return -1; - } - } - - if (driver->hw_monitoring) { - if (driver->input_monitor_mask || driver->all_monitor_in) { - if (driver->all_monitor_in) { - driver->hw->set_input_monitor_mask (driver->hw, ~0U); - } else { - driver->hw->set_input_monitor_mask ( - driver->hw, driver->input_monitor_mask); - } - } else { - driver->hw->set_input_monitor_mask (driver->hw, - driver->input_monitor_mask); - } - } - - if (driver->playback_handle) { - driver->playback_nfds = - snd_pcm_poll_descriptors_count (driver->playback_handle); - } else { - driver->playback_nfds = 0; - } - - if (driver->capture_handle) { - driver->capture_nfds = - snd_pcm_poll_descriptors_count (driver->capture_handle); - } else { - driver->capture_nfds = 0; - } - - if (driver->pfd) { - free (driver->pfd); - } - - driver->pfd = (struct pollfd *) - malloc (sizeof (struct pollfd) * - (driver->playback_nfds + driver->capture_nfds + 2)); - - if (driver->midi && !driver->xrun_recovery) - (driver->midi->start)(driver->midi); - - if (driver->playback_handle) { - /* fill playback buffer with zeroes, and mark - all fragments as having data. - */ - - pavail = snd_pcm_avail_update (driver->playback_handle); - - if (pavail != - driver->frames_per_cycle * driver->playback_nperiods) { - jack_error ("ALSA: full buffer not available at start"); - return -1; - } - - if (alsa_driver_get_channel_addresses (driver, - 0, &pavail, 0, &poffset)) { - return -1; - } - - /* XXX this is cheating. ALSA offers no guarantee that - we can access the entire buffer at any one time. It - works on most hardware tested so far, however, buts - its a liability in the long run. I think that - alsa-lib may have a better function for doing this - here, where the goal is to silence the entire - buffer. - */ - - for (chn = 0; chn < driver->playback_nchannels; chn++) { - alsa_driver_silence_on_channel ( - driver, chn, - driver->user_nperiods - * driver->frames_per_cycle); - } - - snd_pcm_mmap_commit (driver->playback_handle, poffset, - driver->user_nperiods - * driver->frames_per_cycle); - - if ((err = snd_pcm_start (driver->playback_handle)) < 0) { - jack_error ("ALSA: could not start playback (%s)", - snd_strerror (err)); - return -1; - } - } - - if ((driver->capture_handle && driver->capture_and_playback_not_synced) - || !driver->playback_handle) { - if ((err = snd_pcm_start (driver->capture_handle)) < 0) { - jack_error ("ALSA: could not start capture (%s)", - snd_strerror (err)); - return -1; - } - } - - return 0; + snd_pcm_uframes_t poffset, pavail; + channel_t chn; + + driver->poll_last = 0; + driver->poll_next = 0; + + if (driver->playback_handle) { + if ((err = snd_pcm_prepare (driver->playback_handle)) < 0) { + jack_error ("ALSA: prepare error for playback on " + "\"%s\" (%s)", driver->alsa_name_playback, + snd_strerror(err)); + return -1; + } + } + + if ((driver->capture_handle && driver->capture_and_playback_not_synced) + || !driver->playback_handle) { + if ((err = snd_pcm_prepare (driver->capture_handle)) < 0) { + jack_error ("ALSA: prepare error for capture on \"%s\"" + " (%s)", driver->alsa_name_capture, + snd_strerror(err)); + return -1; + } + } + + if (driver->hw_monitoring) { + if (driver->input_monitor_mask || driver->all_monitor_in) { + if (driver->all_monitor_in) { + driver->hw->set_input_monitor_mask (driver->hw, ~0U); + } else { + driver->hw->set_input_monitor_mask ( + driver->hw, driver->input_monitor_mask); + } + } else { + driver->hw->set_input_monitor_mask (driver->hw, + driver->input_monitor_mask); + } + } + + if (driver->playback_handle) { + driver->playback_nfds = + snd_pcm_poll_descriptors_count (driver->playback_handle); + } else { + driver->playback_nfds = 0; + } + + if (driver->capture_handle) { + driver->capture_nfds = + snd_pcm_poll_descriptors_count (driver->capture_handle); + } else { + driver->capture_nfds = 0; + } + + if (driver->pfd) { + free (driver->pfd); + } + + driver->pfd = (struct pollfd *) + malloc (sizeof (struct pollfd) * + (driver->playback_nfds + driver->capture_nfds + 2)); + + if (driver->midi && !driver->xrun_recovery) + (driver->midi->start)(driver->midi); + + if (driver->playback_handle) { + /* fill playback buffer with zeroes, and mark + all fragments as having data. + */ + + pavail = snd_pcm_avail_update (driver->playback_handle); + + if (pavail != + driver->frames_per_cycle * driver->playback_nperiods) { + jack_error ("ALSA: full buffer not available at start"); + return -1; + } + + if (alsa_driver_get_channel_addresses (driver, + 0, &pavail, 0, &poffset)) { + return -1; + } + + /* XXX this is cheating. ALSA offers no guarantee that + we can access the entire buffer at any one time. It + works on most hardware tested so far, however, buts + its a liability in the long run. I think that + alsa-lib may have a better function for doing this + here, where the goal is to silence the entire + buffer. + */ + + for (chn = 0; chn < driver->playback_nchannels; chn++) { + alsa_driver_silence_on_channel ( + driver, chn, + driver->user_nperiods + * driver->frames_per_cycle); + } + + snd_pcm_mmap_commit (driver->playback_handle, poffset, + driver->user_nperiods + * driver->frames_per_cycle); + + if ((err = snd_pcm_start (driver->playback_handle)) < 0) { + jack_error ("ALSA: could not start playback (%s)", + snd_strerror (err)); + return -1; + } + } + + if ((driver->capture_handle && driver->capture_and_playback_not_synced) + || !driver->playback_handle) { + if ((err = snd_pcm_start (driver->capture_handle)) < 0) { + jack_error ("ALSA: could not start capture (%s)", + snd_strerror (err)); + return -1; + } + } + + return 0; } int @@ -1152,9 +1153,9 @@ JackAlsaDriver::alsa_driver_stop (alsa_driver_t *driver) if (driver->hw_monitoring) { driver->hw->set_input_monitor_mask (driver->hw, 0); } - + if (driver->midi && !driver->xrun_recovery) - (driver->midi->stop)(driver->midi); + (driver->midi->stop)(driver->midi); return 0; } @@ -1172,7 +1173,7 @@ JackAlsaDriver::alsa_driver_restart (alsa_driver_t *driver) driver->xrun_recovery = 1; int res = Stop(); if (!res) - res = Start(); + res = Start(); driver->xrun_recovery = 0; return res; } @@ -1522,17 +1523,17 @@ int JackAlsaDriver::SetBufferSize(jack_nframes_t buffer_size) { JackLog("JackAlsaDriver::SetBufferSize %ld\n", buffer_size); int res = alsa_driver_reset_parameters((alsa_driver_t *)fDriver, buffer_size, - ((alsa_driver_t *)fDriver)->user_nperiods, - ((alsa_driver_t *)fDriver)->frame_rate); + ((alsa_driver_t *)fDriver)->user_nperiods, + ((alsa_driver_t *)fDriver)->frame_rate); if (res == 0) { // update fEngineControl and fGraphManager JackAudioDriver::SetBufferSize(buffer_size); // never fails } else { alsa_driver_reset_parameters((alsa_driver_t *)fDriver, fEngineControl->fBufferSize, - ((alsa_driver_t *)fDriver)->user_nperiods, - ((alsa_driver_t *)fDriver)->frame_rate); - } - + ((alsa_driver_t *)fDriver)->user_nperiods, + ((alsa_driver_t *)fDriver)->frame_rate); + } + return res; } @@ -1561,9 +1562,9 @@ JackAlsaDriver::alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes) if (nframes > driver->frames_per_cycle) { return -1; } - + if (driver->midi) - (driver->midi->read)(driver->midi, nframes); + (driver->midi->read)(driver->midi, nframes); nread = 0; contiguous = 0; @@ -1583,10 +1584,10 @@ JackAlsaDriver::alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes) // steph for (int i = 0; i < fCaptureChannels; i++) { - if (fGraphManager->GetConnectionsNum(fCapturePortList[i]) > 0) { - buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[i], orig_nframes); - alsa_driver_read_from_channel (driver, i, buf + nread, contiguous); - } + if (fGraphManager->GetConnectionsNum(fCapturePortList[i]) > 0) { + buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[i], orig_nframes); + alsa_driver_read_from_channel (driver, i, buf + nread, contiguous); + } } /* // steph @@ -1633,7 +1634,7 @@ JackAlsaDriver::alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes snd_pcm_sframes_t nwritten; snd_pcm_sframes_t contiguous; snd_pcm_sframes_t offset; - JackPort* port; + JackPort* port; //jack_port_t *port; int err; @@ -1652,9 +1653,9 @@ JackAlsaDriver::alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes if (nframes > driver->frames_per_cycle) { return -1; } - + if (driver->midi) - (driver->midi->write)(driver->midi, nframes); + (driver->midi->write)(driver->midi, nframes); nwritten = 0; contiguous = 0; @@ -1673,12 +1674,12 @@ JackAlsaDriver::alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes } } */ - for (int i = 0; i < fCaptureChannels; i++) { - port = fGraphManager->GetPort(fCapturePortList[i]); - if (port->MonitoringInput()) { - driver->input_monitor_mask |= (1<<i); - } - } + for (int i = 0; i < fCaptureChannels; i++) { + port = fGraphManager->GetPort(fCapturePortList[i]); + if (port->MonitoringInput()) { + driver->input_monitor_mask |= (1 << i); + } + } if (driver->hw_monitoring) { if ((driver->hw->input_monitor_mask @@ -1703,17 +1704,17 @@ JackAlsaDriver::alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes // steph for (int i = 0; i < fPlaybackChannels; i++) { - // Ouput ports - if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) { - buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[i], orig_nframes); - alsa_driver_write_to_channel (driver, i, buf + nwritten, contiguous); - // Monitor ports - if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0) { - monbuf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[i], orig_nframes); - memcpy(monbuf + nwritten, buf + nwritten, contiguous * sizeof(jack_default_audio_sample_t)); - } - } - } + // Ouput ports + if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) { + buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[i], orig_nframes); + alsa_driver_write_to_channel (driver, i, buf + nwritten, contiguous); + // Monitor ports + if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0) { + monbuf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[i], orig_nframes); + memcpy(monbuf + nwritten, buf + nwritten, contiguous * sizeof(jack_default_audio_sample_t)); + } + } + } /* for (chn = 0, node = driver->playback_ports, mon_node=driver->monitor_ports; @@ -1768,7 +1769,7 @@ JackAlsaDriver::alsa_driver_delete (alsa_driver_t *driver) JSList *node; if (driver->midi) - (driver->midi->destroy)(driver->midi); + (driver->midi->destroy)(driver->midi); for (node = driver->clock_sync_listeners; node; node = jack_slist_next (node)) { @@ -1841,7 +1842,7 @@ JackAlsaDriver::alsa_driver_new (const char *name, char *playback_alsa_device, int shorts_first, jack_nframes_t capture_latency, jack_nframes_t playback_latency, - alsa_midi_t *midi) + alsa_midi_t *midi) { int err; @@ -1863,7 +1864,7 @@ JackAlsaDriver::alsa_driver_new (const char *name, char *playback_alsa_device, driver = (alsa_driver_t *) calloc (1, sizeof (alsa_driver_t)); jack_driver_nt_init ((jack_driver_nt_t *) driver); - + driver->midi = midi; driver->xrun_recovery = 0; @@ -2100,34 +2101,34 @@ int JackAlsaDriver::Attach() JackPort* port; int port_index; unsigned long port_flags; - char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; - char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; assert(fCaptureChannels < PORT_NUM); assert(fPlaybackChannels < PORT_NUM); - + port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal; alsa_driver_t* alsa_driver = (alsa_driver_t*)fDriver; - - if (alsa_driver->has_hw_monitoring) - port_flags |= JackPortCanMonitor; - - // ALSA driver may have changed the values - JackAudioDriver::SetBufferSize(alsa_driver->frames_per_cycle); - JackAudioDriver::SetSampleRate(alsa_driver->frame_rate); + + if (alsa_driver->has_hw_monitoring) + port_flags |= JackPortCanMonitor; + + // ALSA driver may have changed the values + JackAudioDriver::SetBufferSize(alsa_driver->frames_per_cycle); + JackAudioDriver::SetSampleRate(alsa_driver->frame_rate); JackLog("JackAudioDriver::Attach fBufferSize %ld fSampleRate %ld\n", fEngineControl->fBufferSize, fEngineControl->fSampleRate); for (int i = 0; i < fCaptureChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:capture_%u", fClientControl->fName, i + 1); - snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); + snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", name); return -1; } port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + port->SetAlias(alias); port->SetLatency(alsa_driver->frames_per_cycle + alsa_driver->capture_frame_latency); fCapturePortList[i] = port_index; JackLog("JackAudioDriver::Attach fCapturePortList[i] %ld \n", port_index); @@ -2137,30 +2138,30 @@ int JackAlsaDriver::Attach() for (int i = 0; i < fPlaybackChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:playback_%u", fClientControl->fName, i + 1); - snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); + snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", name); return -1; } port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + port->SetAlias(alias); port->SetLatency((alsa_driver->frames_per_cycle * (alsa_driver->user_nperiods - 1)) + alsa_driver->playback_frame_latency); fPlaybackPortList[i] = port_index; JackLog("JackAudioDriver::Attach fPlaybackPortList[i] %ld \n", port_index); - - // Monitor ports - if (fWithMonitorPorts) { - JackLog("Create monitor port \n"); - snprintf(name, sizeof(name) - 1, "%s:monitor_%lu",fClientControl->fName, i + 1); - if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) { - jack_error ("ALSA: cannot register monitor port for %s", name); - } else { - port = fGraphManager->GetPort(port_index); - port->SetLatency(alsa_driver->frames_per_cycle); - fMonitorPortList[i] = port_index; - } - } - } + + // Monitor ports + if (fWithMonitorPorts) { + JackLog("Create monitor port \n"); + snprintf(name, sizeof(name) - 1, "%s:monitor_%lu", fClientControl->fName, i + 1); + if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, fEngineControl->fBufferSize)) == NO_PORT) { + jack_error ("ALSA: cannot register monitor port for %s", name); + } else { + port = fGraphManager->GetPort(port_index); + port->SetLatency(alsa_driver->frames_per_cycle); + fMonitorPortList[i] = port_index; + } + } + } if (alsa_driver->midi) { int err = (alsa_driver->midi->attach)(alsa_driver->midi); @@ -2181,36 +2182,36 @@ int JackAlsaDriver::Detach() } int JackAlsaDriver::Open(jack_nframes_t nframes, - jack_nframes_t user_nperiods, + jack_nframes_t user_nperiods, jack_nframes_t samplerate, - bool hw_monitoring, - bool hw_metering, + bool hw_monitoring, + bool hw_metering, bool capturing, bool playing, - DitherAlgorithm dither, - bool soft_mode, - bool monitor, + DitherAlgorithm dither, + bool soft_mode, + bool monitor, int inchannels, int outchannels, - bool shorts_first, + bool shorts_first, const char* capture_driver_name, - const char* playback_driver_name, - jack_nframes_t capture_latency, - jack_nframes_t playback_latency, - const char* midi_driver_name) + const char* playback_driver_name, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency, + const char* midi_driver_name) { // Generic JackAudioDriver Open - if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, - inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, - capture_latency, playback_latency) != 0) { + if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, + inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, + capture_latency, playback_latency) != 0) { return -1; } - + alsa_midi_t *midi = 0; if (strcmp(midi_driver_name, "seq") == 0) - midi = alsa_seqmidi_new((jack_client_t*)this, 0); + midi = alsa_seqmidi_new((jack_client_t*)this, 0); else if (strcmp(midi_driver_name, "raw") == 0) - midi = alsa_rawmidi_new((jack_client_t*)this); + midi = alsa_rawmidi_new((jack_client_t*)this); fDriver = alsa_driver_new ("alsa_pcm", (char*)playback_driver_name, (char*)capture_driver_name, NULL, @@ -2229,7 +2230,7 @@ int JackAlsaDriver::Open(jack_nframes_t nframes, shorts_first, capture_latency, playback_latency, - midi); + midi); if (fDriver) { // ALSA driver may have changed the in/out values fCaptureChannels = ((alsa_driver_t *)fDriver)->capture_nchannels; @@ -2277,7 +2278,7 @@ int JackAlsaDriver::Read() /* we detected an xrun and restarted: notify * clients about the delay. - */ + */ //engine->delay (engine, delayed_usecs); JackLog("ALSA XRun \n"); //NotifyXRun(jack_get_microseconds()); @@ -2306,7 +2307,7 @@ int JackAlsaDriver::Write() JackLog("ALSA write XRun \n"); NotifyXRun(write_time); } - */ + */ return res; } @@ -2349,63 +2350,63 @@ JackAlsaDriver::jack_driver_nt_init (jack_driver_nt_t * driver) int JackAlsaDriver::is_realtime() const { - return fEngineControl->fRealTime; + return fEngineControl->fRealTime; } int JackAlsaDriver::create_thread(pthread_t *thread, int priority, int realtime, void *(*start_routine)(void*), void *arg) { - return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); + return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg); } int JackAlsaDriver::port_register(const char *port_name, const char *port_type, unsigned long flags, unsigned long buf_size) { - int port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, port_name, port_type, (JackPortFlags) flags, fEngineControl->fBufferSize); - if (port_index != NO_PORT) + int port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, port_name, port_type, (JackPortFlags) flags, fEngineControl->fBufferSize); + if (port_index != NO_PORT) fEngine->NotifyPortRegistation(port_index, true); - return port_index; + return port_index; } int JackAlsaDriver::port_unregister(int port_index) { - if (fGraphManager->ReleasePort(fClientControl->fRefNum, port_index) == 0) { - fEngine->NotifyPortRegistation(port_index, false); - return 0; - } else { + if (fGraphManager->ReleasePort(fClientControl->fRefNum, port_index) == 0) { + fEngine->NotifyPortRegistation(port_index, false); + return 0; + } else { return -1; } } void* JackAlsaDriver::port_get_buffer(int port, jack_nframes_t nframes) { - return fGraphManager->GetBuffer(port, nframes); + return fGraphManager->GetBuffer(port, nframes); } int JackAlsaDriver::port_set_alias(int port, const char* name) { - return fGraphManager->GetPort(port)->SetAlias(name); + return fGraphManager->GetPort(port)->SetAlias(name); } jack_nframes_t JackAlsaDriver::get_sample_rate() const { - return fEngineControl->fSampleRate; + return fEngineControl->fSampleRate; } jack_nframes_t JackAlsaDriver::frame_time() const { - JackTimer timer; - fEngineControl->ReadFrameTime(&timer); + JackTimer timer; + fEngineControl->ReadFrameTime(&timer); if (timer.fInitialized) { - return timer.fFrames + - (long) rint(((double) ((GetMicroSeconds() - timer.fCurrentWakeup)) / - ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * fEngineControl->fBufferSize); - } else - return 0; + return timer.fFrames + + (long) rint(((double) ((GetMicroSeconds() - timer.fCurrentWakeup)) / + ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * fEngineControl->fBufferSize); + } else + return 0; } jack_nframes_t JackAlsaDriver::last_frame_time() const { JackTimer timer; - fEngineControl->ReadFrameTime(&timer); + fEngineControl->ReadFrameTime(&timer); return timer.fFrames; } @@ -2608,10 +2609,10 @@ extern "C" strcpy (params[i].value.str, "none"); strcpy (params[i].short_desc, "ALSA MIDI driver name (seq|raw)"); strcpy (params[i].long_desc, - "ALSA MIDI driver:\n" - " none - no MIDI driver\n" - " seq - ALSA Sequencer driver\n" - " raw - ALSA RawMIDI driver\n"); + "ALSA MIDI driver:\n" + " none - no MIDI driver\n" + " seq - ALSA Sequencer driver\n" + " raw - ALSA RawMIDI driver\n"); desc->params = params; return desc; @@ -2637,7 +2638,7 @@ extern "C" jack_nframes_t systemic_output_latency = 0; const JSList * node; const jack_driver_param_t * param; - const char *midi_driver = "none"; + const char *midi_driver = "none"; for (node = params; node; node = jack_slist_next (node)) { param = (const jack_driver_param_t *) node->data; @@ -2648,7 +2649,7 @@ extern "C" capture = TRUE; if (strcmp (param->value.str, "none") != 0) { capture_pcm_name = strdup (param->value.str); - JackLog("capture device %s\n", capture_pcm_name); + JackLog("capture device %s\n", capture_pcm_name); } break; @@ -2656,7 +2657,7 @@ extern "C" playback = TRUE; if (strcmp (param->value.str, "none") != 0) { playback_pcm_name = strdup (param->value.str); - JackLog("playback device %s\n", playback_pcm_name); + JackLog("playback device %s\n", playback_pcm_name); } break; @@ -2668,8 +2669,8 @@ extern "C" case 'd': playback_pcm_name = strdup (param->value.str); capture_pcm_name = strdup (param->value.str); - JackLog("playback device %s\n", playback_pcm_name); - JackLog("capture device %s\n", capture_pcm_name); + JackLog("playback device %s\n", playback_pcm_name); + JackLog("capture device %s\n", capture_pcm_name); break; case 'H': @@ -2686,12 +2687,12 @@ extern "C" case 'r': srate = param->value.ui; - JackLog("apparent rate = %d\n", srate); + JackLog("apparent rate = %d\n", srate); break; case 'p': frames_per_interrupt = param->value.ui; - JackLog("frames per period = %d\n", frames_per_interrupt); + JackLog("frames per period = %d\n", frames_per_interrupt); break; case 'n': @@ -2729,10 +2730,10 @@ extern "C" case 'O': systemic_output_latency = param->value.ui; break; - - case 'X': - midi_driver = strdup(param->value.str); - break; + + case 'X': + midi_driver = strdup(param->value.str); + break; } } @@ -2743,12 +2744,12 @@ extern "C" playback = TRUE; } - Jack::JackAlsaDriver* alsa_driver = new Jack::JackAlsaDriver("alsa_pcm", engine, table); + Jack::JackAlsaDriver* alsa_driver = new Jack::JackAlsaDriver("alsa_pcm", engine, table); Jack::JackDriverClientInterface* threaded_driver = new Jack::JackThreadedDriver(alsa_driver); - // Special open for ALSA driver... - if (alsa_driver->Open(frames_per_interrupt, user_nperiods, srate, hw_monitoring, hw_metering, capture, playback, dither, soft_mode, monitor, - user_capture_nchnls, user_playback_nchnls, shorts_first, capture_pcm_name, playback_pcm_name, - systemic_input_latency, systemic_output_latency, midi_driver) == 0) { + // Special open for ALSA driver... + if (alsa_driver->Open(frames_per_interrupt, user_nperiods, srate, hw_monitoring, hw_metering, capture, playback, dither, soft_mode, monitor, + user_capture_nchnls, user_playback_nchnls, shorts_first, capture_pcm_name, playback_pcm_name, + systemic_input_latency, systemic_output_latency, midi_driver) == 0) { return threaded_driver; } else { delete threaded_driver; // Delete the decorated driver diff --git a/linux/alsa/JackAlsaDriver.h b/linux/alsa/JackAlsaDriver.h index 9cd69843..329f31b0 100644 --- a/linux/alsa/JackAlsaDriver.h +++ b/linux/alsa/JackAlsaDriver.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004 Grame This program is free software; you can redistribute it and/or modify @@ -96,7 +96,7 @@ class JackAlsaDriver : public JackAudioDriver int shorts_first, jack_nframes_t capture_latency, jack_nframes_t playback_latency, - alsa_midi_t *midi + alsa_midi_t *midi ); void alsa_driver_delete(alsa_driver_t *driver); @@ -115,7 +115,7 @@ class JackAlsaDriver : public JackAudioDriver int alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs); void jack_driver_init (jack_driver_t *driver); void jack_driver_nt_init (jack_driver_nt_t * driver); - + public: JackAlsaDriver(const char* name, JackEngine* engine, JackSynchro** table): JackAudioDriver(name, engine, table) @@ -124,28 +124,28 @@ class JackAlsaDriver : public JackAudioDriver {} int Open(jack_nframes_t nframes, - jack_nframes_t user_nperiods, - jack_nframes_t samplerate, - bool hw_monitoring, - bool hw_metering, - bool capturing, - bool playing, - DitherAlgorithm dither, - bool soft_mode, - bool monitor, - int inchannels, - int outchannels, - bool shorts_first, - const char* capture_driver_name, - const char* playback_driver_name, - jack_nframes_t capture_latency, - jack_nframes_t playback_latency, - const char* midi_driver_name); + jack_nframes_t user_nperiods, + jack_nframes_t samplerate, + bool hw_monitoring, + bool hw_metering, + bool capturing, + bool playing, + DitherAlgorithm dither, + bool soft_mode, + bool monitor, + int inchannels, + int outchannels, + bool shorts_first, + const char* capture_driver_name, + const char* playback_driver_name, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency, + const char* midi_driver_name); int Close(); int Attach(); int Detach(); - + int Start(); int Stop(); @@ -155,19 +155,19 @@ class JackAlsaDriver : public JackAudioDriver int SetBufferSize(jack_nframes_t nframes); - // jack api emulation for the midi driver - - int is_realtime() const; - int create_thread(pthread_t *thread, int prio, int rt, void *(*start_func)(void*), void *arg); - - int port_register(const char *port_name, const char *port_type, unsigned long flags, unsigned long buf_size); - int port_unregister(int port); - void* port_get_buffer(int port, jack_nframes_t nframes); - int port_set_alias(int port, const char* name); - - jack_nframes_t get_sample_rate() const; - jack_nframes_t frame_time() const; - jack_nframes_t last_frame_time() const; + // jack api emulation for the midi driver + + int is_realtime() const; + int create_thread(pthread_t *thread, int prio, int rt, void *(*start_func)(void*), void *arg); + + int port_register(const char *port_name, const char *port_type, unsigned long flags, unsigned long buf_size); + int port_unregister(int port); + void* port_get_buffer(int port, jack_nframes_t nframes); + int port_set_alias(int port, const char* name); + + jack_nframes_t get_sample_rate() const; + jack_nframes_t frame_time() const; + jack_nframes_t last_frame_time() const; }; } // end of namespace diff --git a/linux/alsa/alsa_driver.h b/linux/alsa/alsa_driver.h index da77220b..9cd01202 100644 --- a/linux/alsa/alsa_driver.h +++ b/linux/alsa/alsa_driver.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis 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 @@ -40,18 +40,19 @@ #include "alsa_midi.h" typedef void (*ReadCopyFunction) (jack_default_audio_sample_t *dst, char *src, - unsigned long src_bytes, - unsigned long src_skip_bytes); + unsigned long src_bytes, + unsigned long src_skip_bytes); typedef void (*WriteCopyFunction) (char *dst, jack_default_audio_sample_t *src, - unsigned long src_bytes, - unsigned long dst_skip_bytes, - dither_state_t *state); + unsigned long src_bytes, + unsigned long dst_skip_bytes, + dither_state_t *state); typedef void (*CopyCopyFunction) (char *dst, char *src, - unsigned long src_bytes, - unsigned long dst_skip_bytes, - unsigned long src_skip_byte); + unsigned long src_bytes, + unsigned long dst_skip_bytes, + unsigned long src_skip_byte); -typedef struct _alsa_driver { +typedef struct _alsa_driver +{ JACK_DRIVER_NT_DECL @@ -100,7 +101,7 @@ typedef struct _alsa_driver { snd_pcm_sw_params_t *playback_sw_params; snd_pcm_hw_params_t *capture_hw_params; snd_pcm_sw_params_t *capture_sw_params; - jack_hardware_t *hw; + jack_hardware_t *hw; ClockSyncStatus *clock_sync_data; jack_client_t *client; JSList *capture_ports; @@ -140,99 +141,104 @@ typedef struct _alsa_driver { int poll_late; int xrun_count; int process_count; - + alsa_midi_t *midi; int xrun_recovery; -} alsa_driver_t; +} +alsa_driver_t; -static inline void -alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn) { - bitset_remove (driver->channels_not_done, chn); - driver->silent[chn] = 0; +static inline void +alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn) +{ + bitset_remove (driver->channels_not_done, chn); + driver->silent[chn] = 0; } -static inline void +static inline void alsa_driver_silence_on_channel (alsa_driver_t *driver, channel_t chn, - jack_nframes_t nframes) { - if (driver->playback_interleaved) { - memset_interleave - (driver->playback_addr[chn], - 0, nframes * driver->playback_sample_bytes, - driver->interleave_unit, - driver->playback_interleave_skip[chn]); - } else { - memset (driver->playback_addr[chn], 0, - nframes * driver->playback_sample_bytes); - } - alsa_driver_mark_channel_done (driver,chn); + jack_nframes_t nframes) +{ + if (driver->playback_interleaved) { + memset_interleave + (driver->playback_addr[chn], + 0, nframes * driver->playback_sample_bytes, + driver->interleave_unit, + driver->playback_interleave_skip[chn]); + } else { + memset (driver->playback_addr[chn], 0, + nframes * driver->playback_sample_bytes); + } + alsa_driver_mark_channel_done (driver, chn); } -static inline void +static inline void alsa_driver_silence_on_channel_no_mark (alsa_driver_t *driver, channel_t chn, - jack_nframes_t nframes) { - if (driver->playback_interleaved) { - memset_interleave - (driver->playback_addr[chn], - 0, nframes * driver->playback_sample_bytes, - driver->interleave_unit, - driver->playback_interleave_skip[chn]); - } else { - memset (driver->playback_addr[chn], 0, - nframes * driver->playback_sample_bytes); - } + jack_nframes_t nframes) +{ + if (driver->playback_interleaved) { + memset_interleave + (driver->playback_addr[chn], + 0, nframes * driver->playback_sample_bytes, + driver->interleave_unit, + driver->playback_interleave_skip[chn]); + } else { + memset (driver->playback_addr[chn], 0, + nframes * driver->playback_sample_bytes); + } } -static inline void +static inline void alsa_driver_read_from_channel (alsa_driver_t *driver, - channel_t channel, - jack_default_audio_sample_t *buf, - jack_nframes_t nsamples) + channel_t channel, + jack_default_audio_sample_t *buf, + jack_nframes_t nsamples) { - driver->read_via_copy (buf, - driver->capture_addr[channel], - nsamples, - driver->capture_interleave_skip[channel]); + driver->read_via_copy (buf, + driver->capture_addr[channel], + nsamples, + driver->capture_interleave_skip[channel]); } -static inline void +static inline void alsa_driver_write_to_channel (alsa_driver_t *driver, - channel_t channel, - jack_default_audio_sample_t *buf, - jack_nframes_t nsamples) + channel_t channel, + jack_default_audio_sample_t *buf, + jack_nframes_t nsamples) { - driver->write_via_copy (driver->playback_addr[channel], - buf, - nsamples, - driver->playback_interleave_skip[channel], - driver->dither_state+channel); - alsa_driver_mark_channel_done (driver, channel); + driver->write_via_copy (driver->playback_addr[channel], + buf, + nsamples, + driver->playback_interleave_skip[channel], + driver->dither_state + channel); + alsa_driver_mark_channel_done (driver, channel); } -static inline void -alsa_driver_copy_channel (alsa_driver_t *driver, - channel_t input_channel, - channel_t output_channel, - jack_nframes_t nsamples) { - - driver->channel_copy (driver->playback_addr[output_channel], - driver->capture_addr[input_channel], - nsamples * driver->playback_sample_bytes, - driver->playback_interleave_skip[output_channel], - driver->capture_interleave_skip[input_channel]); - alsa_driver_mark_channel_done (driver, output_channel); +static inline void +alsa_driver_copy_channel (alsa_driver_t *driver, + channel_t input_channel, + channel_t output_channel, + jack_nframes_t nsamples) +{ + + driver->channel_copy (driver->playback_addr[output_channel], + driver->capture_addr[input_channel], + nsamples * driver->playback_sample_bytes, + driver->playback_interleave_skip[output_channel], + driver->capture_interleave_skip[input_channel]); + alsa_driver_mark_channel_done (driver, output_channel); } void alsa_driver_silence_untouched_channels (alsa_driver_t *driver, - jack_nframes_t nframes); + jack_nframes_t nframes); void alsa_driver_set_clock_sync_status (alsa_driver_t *driver, channel_t chn, - ClockSyncStatus status); + ClockSyncStatus status); int alsa_driver_listen_for_clock_sync_status (alsa_driver_t *, - ClockSyncListenerFunction, - void *arg); + ClockSyncListenerFunction, + void *arg); int alsa_driver_stop_listen_for_clock_sync_status (alsa_driver_t *, - unsigned int); + unsigned int); void alsa_driver_clock_sync_notify (alsa_driver_t *, channel_t chn, - ClockSyncStatus); + ClockSyncStatus); #endif /* __jack_alsa_driver_h__ */ diff --git a/linux/alsa/alsa_midi.h b/linux/alsa/alsa_midi.h index 1fb5da58..ec2575d8 100644 --- a/linux/alsa/alsa_midi.h +++ b/linux/alsa/alsa_midi.h @@ -20,22 +20,23 @@ #define __jack_alsa_midi_h__ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -typedef struct alsa_midi_t alsa_midi_t; -struct alsa_midi_t { - void (*destroy)(alsa_midi_t *amidi); - int (*attach)(alsa_midi_t *amidi); - int (*detach)(alsa_midi_t *amidi); - int (*start)(alsa_midi_t *amidi); - int (*stop)(alsa_midi_t *amidi); - void (*read)(alsa_midi_t *amidi, jack_nframes_t nframes); - void (*write)(alsa_midi_t *amidi, jack_nframes_t nframes); -}; + typedef struct alsa_midi_t alsa_midi_t; + struct alsa_midi_t { + void (*destroy)(alsa_midi_t *amidi); + int (*attach)(alsa_midi_t *amidi); + int (*detach)(alsa_midi_t *amidi); + int (*start)(alsa_midi_t *amidi); + int (*stop)(alsa_midi_t *amidi); + void (*read)(alsa_midi_t *amidi, jack_nframes_t nframes); + void (*write)(alsa_midi_t *amidi, jack_nframes_t nframes); + }; -alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack); -alsa_midi_t* alsa_seqmidi_new(jack_client_t *jack, const char* alsa_name); + alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack); + alsa_midi_t* alsa_seqmidi_new(jack_client_t *jack, const char* alsa_name); #ifdef __cplusplus } // extern "C" diff --git a/linux/alsa/alsa_midi_impl.h b/linux/alsa/alsa_midi_impl.h index fc1b90fb..1ac22143 100644 --- a/linux/alsa/alsa_midi_impl.h +++ b/linux/alsa/alsa_midi_impl.h @@ -25,20 +25,21 @@ #include "types.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -int JACK_is_realtime(jack_client_t *client); -int JACK_client_create_thread(jack_client_t *client, pthread_t *thread, int priority, int realtime, void *(*start_routine)(void*), void *arg); + int JACK_is_realtime(jack_client_t *client); + int JACK_client_create_thread(jack_client_t *client, pthread_t *thread, int priority, int realtime, void *(*start_routine)(void*), void *arg); -jack_port_t* JACK_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size); -int JACK_port_unregister(jack_client_t *, jack_port_t*); -void* JACK_port_get_buffer(jack_port_t*, jack_nframes_t); -int JACK_port_set_alias(jack_port_t* port, const char* name); + jack_port_t* JACK_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size); + int JACK_port_unregister(jack_client_t *, jack_port_t*); + void* JACK_port_get_buffer(jack_port_t*, jack_nframes_t); + int JACK_port_set_alias(jack_port_t* port, const char* name); -jack_nframes_t JACK_get_sample_rate(jack_client_t *); -jack_nframes_t JACK_frame_time(jack_client_t *); -jack_nframes_t JACK_last_frame_time(jack_client_t *); + jack_nframes_t JACK_get_sample_rate(jack_client_t *); + jack_nframes_t JACK_frame_time(jack_client_t *); + jack_nframes_t JACK_last_frame_time(jack_client_t *); #define jack_is_realtime JACK_is_realtime #define jack_client_create_thread JACK_client_create_thread diff --git a/linux/alsa/alsa_midi_jackmp.cpp b/linux/alsa/alsa_midi_jackmp.cpp index f7778304..1e276244 100644 --- a/linux/alsa/alsa_midi_jackmp.cpp +++ b/linux/alsa/alsa_midi_jackmp.cpp @@ -22,64 +22,66 @@ using Jack::JackAlsaDriver; -struct fake_port_t { +struct fake_port_t +{ JackAlsaDriver* driver; int port_id; - fake_port_t(JackAlsaDriver *d, int i) : driver(d), port_id(i) {} + fake_port_t(JackAlsaDriver *d, int i) : driver(d), port_id(i) + {} }; int JACK_is_realtime(jack_client_t* client) { - return ((JackAlsaDriver*)client)->is_realtime(); + return ((JackAlsaDriver*)client)->is_realtime(); } int JACK_client_create_thread(jack_client_t* client, pthread_t *thread, int priority, int realtime, void *(*start_routine)(void*), void *arg) { - return ((JackAlsaDriver*)client)->create_thread(thread, priority, realtime, start_routine, arg); + return ((JackAlsaDriver*)client)->create_thread(thread, priority, realtime, start_routine, arg); } jack_port_t* JACK_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size) { - JackAlsaDriver *driver = (JackAlsaDriver*)client; - int port_id = driver->port_register(port_name, port_type, flags, buffer_size); - if (port_id == NO_PORT) { - return 0; - } else { - return (jack_port_t*) new fake_port_t(driver, port_id); - } + JackAlsaDriver *driver = (JackAlsaDriver*)client; + int port_id = driver->port_register(port_name, port_type, flags, buffer_size); + if (port_id == NO_PORT) { + return 0; + } else { + return (jack_port_t*) new fake_port_t(driver, port_id); + } } int JACK_port_unregister(jack_client_t *client, jack_port_t *port) { - fake_port_t* real = (fake_port_t*)port; - int res = real->driver->port_unregister(real->port_id); - delete real; - return res; + fake_port_t* real = (fake_port_t*)port; + int res = real->driver->port_unregister(real->port_id); + delete real; + return res; } void* JACK_port_get_buffer(jack_port_t *port, jack_nframes_t nframes) { - fake_port_t* real = (fake_port_t*)port; - return real->driver->port_get_buffer(real->port_id, nframes); + fake_port_t* real = (fake_port_t*)port; + return real->driver->port_get_buffer(real->port_id, nframes); } int JACK_port_set_alias(jack_port_t *port, const char* name) { - fake_port_t* real = (fake_port_t*)port; - return real->driver->port_set_alias(real->port_id, name); + fake_port_t* real = (fake_port_t*)port; + return real->driver->port_set_alias(real->port_id, name); } jack_nframes_t JACK_get_sample_rate(jack_client_t *client) { - return ((JackAlsaDriver*)client)->get_sample_rate(); + return ((JackAlsaDriver*)client)->get_sample_rate(); } jack_nframes_t JACK_frame_time(jack_client_t *client) { - return ((JackAlsaDriver*)client)->frame_time(); + return ((JackAlsaDriver*)client)->frame_time(); } jack_nframes_t JACK_last_frame_time(jack_client_t *client) { - return ((JackAlsaDriver*)client)->last_frame_time(); + return ((JackAlsaDriver*)client)->last_frame_time(); } diff --git a/linux/alsa/bitset.h b/linux/alsa/bitset.h index da0abef9..048b5fb2 100644 --- a/linux/alsa/bitset.h +++ b/linux/alsa/bitset.h @@ -20,12 +20,12 @@ * 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. diff --git a/linux/alsa/generic.h b/linux/alsa/generic.h index ee906b31..4458aea4 100644 --- a/linux/alsa/generic.h +++ b/linux/alsa/generic.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis - + 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 diff --git a/linux/alsa/hammerfall.h b/linux/alsa/hammerfall.h index 78a3f505..aeb6eb76 100644 --- a/linux/alsa/hammerfall.h +++ b/linux/alsa/hammerfall.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis - + 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 diff --git a/linux/alsa/hardware.h b/linux/alsa/hardware.h index 900d60a1..b77dc859 100644 --- a/linux/alsa/hardware.h +++ b/linux/alsa/hardware.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis - + 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 @@ -56,7 +56,7 @@ typedef struct _jack_hardware JackHardwareReleaseFunction release; JackHardwareGetHardwarePeak get_hardware_peak; JackHardwareGetHardwarePower get_hardware_power; - void *private_hw; + void *private_hw; } jack_hardware_t; diff --git a/linux/alsa/hdsp.h b/linux/alsa/hdsp.h index 79e56364..fe5df84a 100644 --- a/linux/alsa/hdsp.h +++ b/linux/alsa/hdsp.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001 Paul Davis - + 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 diff --git a/linux/alsa/ice1712.h b/linux/alsa/ice1712.h index 2e04c93c..fb422012 100644 --- a/linux/alsa/ice1712.h +++ b/linux/alsa/ice1712.h @@ -1,11 +1,11 @@ /* Copyright (C) 2002 Anthony Van Groningen - Parts based on source code taken from the + Parts based on source code taken from the "Env24 chipset (ICE1712) control utility" that is Copyright (C) 2000 by Jaroslav Kysela <perex@suse.cz> - + 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 @@ -35,31 +35,35 @@ #define ANALOG_PLAYBACK_ROUTE_NAME "H/W Playback Route" #define MULTITRACK_PEAK_NAME "Multi Track Peak" -typedef struct { - unsigned int subvendor; /* PCI[2c-2f] */ - unsigned char size; /* size of EEPROM image in bytes */ - unsigned char version; /* must be 1 */ - unsigned char codec; /* codec configuration PCI[60] */ - unsigned char aclink; /* ACLink configuration PCI[61] */ - unsigned char i2sID; /* PCI[62] */ - unsigned char spdif; /* S/PDIF configuration PCI[63] */ - unsigned char gpiomask; /* GPIO initial mask, 0 = write, 1 = don't */ - unsigned char gpiostate; /* GPIO initial state */ - unsigned char gpiodir; /* GPIO direction state */ - unsigned short ac97main; - unsigned short ac97pcm; - unsigned short ac97rec; - unsigned char ac97recsrc; - unsigned char dacID[4]; /* I2S IDs for DACs */ - unsigned char adcID[4]; /* I2S IDs for ADCs */ - unsigned char extra[4]; -} ice1712_eeprom_t; +typedef struct +{ + unsigned int subvendor; /* PCI[2c-2f] */ + unsigned char size; /* size of EEPROM image in bytes */ + unsigned char version; /* must be 1 */ + unsigned char codec; /* codec configuration PCI[60] */ + unsigned char aclink; /* ACLink configuration PCI[61] */ + unsigned char i2sID; /* PCI[62] */ + unsigned char spdif; /* S/PDIF configuration PCI[63] */ + unsigned char gpiomask; /* GPIO initial mask, 0 = write, 1 = don't */ + unsigned char gpiostate; /* GPIO initial state */ + unsigned char gpiodir; /* GPIO direction state */ + unsigned short ac97main; + unsigned short ac97pcm; + unsigned short ac97rec; + unsigned char ac97recsrc; + unsigned char dacID[4]; /* I2S IDs for DACs */ + unsigned char adcID[4]; /* I2S IDs for ADCs */ + unsigned char extra[4]; +} +ice1712_eeprom_t; -typedef struct { - alsa_driver_t *driver; - ice1712_eeprom_t *eeprom; - unsigned long active_channels; -} ice1712_t; +typedef struct +{ + alsa_driver_t *driver; + ice1712_eeprom_t *eeprom; + unsigned long active_channels; +} +ice1712_t; #ifdef __cplusplus extern "C" diff --git a/linux/alsa/jslist.h b/linux/alsa/jslist.h index 9b547fc0..cc145f07 100644 --- a/linux/alsa/jslist.h +++ b/linux/alsa/jslist.h @@ -10,14 +10,14 @@ it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. $Id: jslist.h,v 1.2 2005/11/23 11:24:29 letz Exp $ diff --git a/linux/alsa/memops.h b/linux/alsa/memops.h index 25b09e2f..dc9d5bd0 100644 --- a/linux/alsa/memops.h +++ b/linux/alsa/memops.h @@ -1,5 +1,5 @@ /* - Copyright (C) 1999-2000 Paul Davis + Copyright (C) 1999-2000 Paul Davis 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 @@ -33,85 +33,85 @@ typedef enum { #define DITHER_BUF_SIZE 8 #define DITHER_BUF_MASK 7 -typedef struct { +typedef struct +{ unsigned int depth; float rm1; unsigned int idx; float e[DITHER_BUF_SIZE]; -} dither_state_t; +} +dither_state_t; #ifdef __cplusplus extern "C" { #endif -void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); - -void sample_move_dither_rect_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_rect_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_rect_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_rect_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); - -void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); -void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); -void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); -void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); -void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); -void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); - -void sample_merge_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); -void sample_merge_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); - -static __inline__ void -sample_merge (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt) - -{ - while (cnt--) { - *dst += *src; - dst++; - src++; - } -} - -static __inline__ void -sample_memcpy (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt) - -{ - memcpy (dst, src, cnt * sizeof (jack_default_audio_sample_t)); -} - -void memset_interleave (char *dst, char val, unsigned long bytes, unsigned long unit_bytes, unsigned long skip_bytes); -void memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); - -void memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); -void memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); -void memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); - -void merge_memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); -void merge_memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); -void merge_memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); - -void merge_memcpy_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); -void merge_memcpy_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); + void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + + void sample_move_dither_rect_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_rect_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_rect_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_rect_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + + void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip); + + void sample_merge_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + void sample_merge_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state); + + static __inline__ void + sample_merge (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt) + { + while (cnt--) { + *dst += *src; + dst++; + src++; + } + } + + static __inline__ void + sample_memcpy (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt) + { + memcpy (dst, src, cnt * sizeof (jack_default_audio_sample_t)); + } + + void memset_interleave (char *dst, char val, unsigned long bytes, unsigned long unit_bytes, unsigned long skip_bytes); + void memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); + + void memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + void memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + void memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + + void merge_memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + void merge_memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + void merge_memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes); + + void merge_memcpy_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); + void merge_memcpy_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar); #ifdef __cplusplus } diff --git a/linux/alsa/midi_pack.h b/linux/alsa/midi_pack.h index c449eb7a..56872a54 100644 --- a/linux/alsa/midi_pack.h +++ b/linux/alsa/midi_pack.h @@ -19,28 +19,30 @@ #ifndef __jack_midi_pack_h__ #define __jack_midi_pack_h__ -typedef struct { - int running_status; -} midi_pack_t; +typedef struct +{ + int running_status; +} +midi_pack_t; static inline void midi_pack_reset(midi_pack_t *p) { - p->running_status = 0; + p->running_status = 0; } static void midi_pack_event(midi_pack_t *p, jack_midi_event_t *e) { - if (e->buffer[0] >= 0x80 && e->buffer[0] < 0xF0) { // Voice Message - if (e->buffer[0] == p->running_status) { - e->buffer++; - e->size--; - } else - p->running_status = e->buffer[0]; - } else if (e->buffer[0] < 0xF8) { // not System Realtime - p->running_status = 0; - } + if (e->buffer[0] >= 0x80 && e->buffer[0] < 0xF0) { // Voice Message + if (e->buffer[0] == p->running_status) { + e->buffer++; + e->size--; + } else + p->running_status = e->buffer[0]; + } else if (e->buffer[0] < 0xF8) { // not System Realtime + p->running_status = 0; + } } #endif /* __jack_midi_pack_h__ */ diff --git a/linux/alsa/midi_unpack.h b/linux/alsa/midi_unpack.h index d1b38fb0..f6b381b9 100644 --- a/linux/alsa/midi_unpack.h +++ b/linux/alsa/midi_unpack.h @@ -20,120 +20,116 @@ #define __jack_midi_unpack_h__ enum { - MIDI_UNPACK_MAX_MSG = 1024 + MIDI_UNPACK_MAX_MSG = 1024 }; -typedef struct { - int pos, need, size; - unsigned char data[MIDI_UNPACK_MAX_MSG]; -} midi_unpack_t; +typedef struct +{ + int pos, need, size; + unsigned char data[MIDI_UNPACK_MAX_MSG]; +} +midi_unpack_t; static inline void midi_unpack_init(midi_unpack_t *u) { - u->pos = 0; - u->size = sizeof(u->data); - u->need = u->size; + u->pos = 0; + u->size = sizeof(u->data); + u->need = u->size; } static inline void midi_unpack_reset(midi_unpack_t *u) { - u->pos = 0; - u->need = u->size; + u->pos = 0; + u->need = u->size; } -static const unsigned char midi_voice_len[] = { - 3, /*0x80 Note Off*/ - 3, /*0x90 Note On*/ - 3, /*0xA0 Aftertouch*/ - 3, /*0xB0 Control Change*/ - 2, /*0xC0 Program Change*/ - 2, /*0xD0 Channel Pressure*/ - 3, /*0xE0 Pitch Wheel*/ - 1 /*0xF0 System*/ -}; +static const unsigned char midi_voice_len[] = + { + 3, /*0x80 Note Off*/ + 3, /*0x90 Note On*/ + 3, /*0xA0 Aftertouch*/ + 3, /*0xB0 Control Change*/ + 2, /*0xC0 Program Change*/ + 2, /*0xD0 Channel Pressure*/ + 3, /*0xE0 Pitch Wheel*/ + 1 /*0xF0 System*/ + }; -static const unsigned char midi_system_len[] = { - 0, /*0xF0 System Exclusive Start*/ - 2, /*0xF1 MTC Quarter Frame*/ - 3, /*0xF2 Song Postion*/ - 2, /*0xF3 Song Select*/ - 0, /*0xF4 undefined*/ - 0, /*0xF5 undefined*/ - 1, /*0xF6 Tune Request*/ - 1 /*0xF7 System Exlusive End*/ -}; +static const unsigned char midi_system_len[] = + { + 0, /*0xF0 System Exclusive Start*/ + 2, /*0xF1 MTC Quarter Frame*/ + 3, /*0xF2 Song Postion*/ + 2, /*0xF3 Song Select*/ + 0, /*0xF4 undefined*/ + 0, /*0xF5 undefined*/ + 1, /*0xF6 Tune Request*/ + 1 /*0xF7 System Exlusive End*/ + }; static int midi_unpack_buf(midi_unpack_t *buf, const unsigned char *data, int len, void *jack_port_buf, jack_nframes_t time) { - int i; - for (i=0; i<len; ++i) - { - const unsigned char byte = data[i]; - if (byte >= 0xF8) // system realtime - { - jack_midi_event_write(jack_port_buf, time, &data[i], 1); - //printf("midi_unpack: written system relatime event\n"); - //midi_input_write(in, &data[i], 1); - } - else if (byte < 0x80) // data - { - assert (buf->pos < buf->size); - buf->data[buf->pos++] = byte; - } - else if (byte < 0xF0) // voice - { - assert (byte >= 0x80 && byte < 0xF0); - //buf->need = ((byte|0x0F) == 0xCF || (byte|0x0F)==0xDF) ? 2 : 3; - buf->need = midi_voice_len[(byte-0x80)>>4]; - buf->data[0] = byte; - buf->pos = 1; - } - else if (byte == 0xF7) // sysex end - { - assert (buf->pos < buf->size); - buf->data[buf->pos++] = byte; - buf->need = buf->pos; - } - else - { - assert (byte >= 0xF0 && byte < 0xF8); - buf->pos = 1; - buf->data[0] = byte; - buf->need = midi_system_len[byte - 0xF0]; - if (!buf->need) - buf->need = buf->size; - } - if (buf->pos == buf->need) - { - // TODO: deal with big sysex'es (they are silently dropped for now) - if (buf->data[0] >= 0x80 || (buf->data[0]==0xF0 && buf->data[buf->pos-1] == 0xF7)) { - /* convert Note On with velocity 0 to Note Off */ - if ((buf->data[0] & 0xF0) == 0x90 && buf->data[2] == 0) { - // we use temp array here to keep running status sync - jack_midi_data_t temp[3] = { 0x80, 0, 0x40 }; - temp[0] |= buf->data[0] & 0x0F; - temp[1] = buf->data[1]; - jack_midi_event_write(jack_port_buf, time, temp, 3); - } else - jack_midi_event_write(jack_port_buf, time, &buf->data[0], buf->pos); - //printf("midi_unpack: written %d-byte event\n", buf->pos); - //midi_input_write(in, &buf->data[0], buf->pos); - } - /* keep running status */ - if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0) - buf->pos = 1; - else - { - buf->pos = 0; - buf->need = buf->size; - } - } - } - assert (i==len); - return i; + int i; + for (i = 0; i < len; ++i) { + const unsigned char byte = data[i]; + if (byte >= 0xF8) // system realtime + { + jack_midi_event_write(jack_port_buf, time, &data[i], 1); + //printf("midi_unpack: written system relatime event\n"); + //midi_input_write(in, &data[i], 1); + } else if (byte < 0x80) // data + { + assert (buf->pos < buf->size); + buf->data[buf->pos++] = byte; + } else if (byte < 0xF0) // voice + { + assert (byte >= 0x80 && byte < 0xF0); + //buf->need = ((byte|0x0F) == 0xCF || (byte|0x0F)==0xDF) ? 2 : 3; + buf->need = midi_voice_len[(byte-0x80)>>4]; + buf->data[0] = byte; + buf->pos = 1; + } else if (byte == 0xF7) // sysex end + { + assert (buf->pos < buf->size); + buf->data[buf->pos++] = byte; + buf->need = buf->pos; + } else { + assert (byte >= 0xF0 && byte < 0xF8); + buf->pos = 1; + buf->data[0] = byte; + buf->need = midi_system_len[byte - 0xF0]; + if (!buf->need) + buf->need = buf->size; + } + if (buf->pos == buf->need) { + // TODO: deal with big sysex'es (they are silently dropped for now) + if (buf->data[0] >= 0x80 || (buf->data[0] == 0xF0 && buf->data[buf->pos-1] == 0xF7)) { + /* convert Note On with velocity 0 to Note Off */ + if ((buf->data[0] & 0xF0) == 0x90 && buf->data[2] == 0) { + // we use temp array here to keep running status sync + jack_midi_data_t temp[3] = { 0x80, 0, 0x40 }; + temp[0] |= buf->data[0] & 0x0F; + temp[1] = buf->data[1]; + jack_midi_event_write(jack_port_buf, time, temp, 3); + } else + jack_midi_event_write(jack_port_buf, time, &buf->data[0], buf->pos); + //printf("midi_unpack: written %d-byte event\n", buf->pos); + //midi_input_write(in, &buf->data[0], buf->pos); + } + /* keep running status */ + if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0) + buf->pos = 1; + else { + buf->pos = 0; + buf->need = buf->size; + } + } + } + assert (i == len); + return i; } #endif /* __jack_midi_unpack_h__ */ diff --git a/linux/alsa/usx2y.h b/linux/alsa/usx2y.h index f34b9f13..522d19a8 100644 --- a/linux/alsa/usx2y.h +++ b/linux/alsa/usx2y.h @@ -1,7 +1,7 @@ /* Copyright (C) 2001 Paul Davis Copyright (C) 2004 Karsten Wiese, Rui Nuno Capela - + 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 @@ -28,33 +28,38 @@ #define USX2Y_SSS (((USX2Y_MAXPACK * USX2Y_MAXBUFFERMS * USX2Y_MAXSTRIDE + 4096) / 4096) * 4096) -struct snd_usX2Y_hwdep_pcm_shm { - char playback[USX2Y_SSS]; - char capture0x8[USX2Y_SSS]; - char capture0xA[USX2Y_SSS]; - volatile int playback_iso_head; - int playback_iso_start; - struct { - int frame, - offset, - length; - } captured_iso[128]; - volatile int captured_iso_head; - volatile unsigned captured_iso_frames; - int capture_iso_start; +struct snd_usX2Y_hwdep_pcm_shm +{ + char playback[USX2Y_SSS]; + char capture0x8[USX2Y_SSS]; + char capture0xA[USX2Y_SSS]; + volatile int playback_iso_head; + int playback_iso_start; + struct + { + int frame, + offset, + length; + } + captured_iso[128]; + volatile int captured_iso_head; + volatile unsigned captured_iso_frames; + int capture_iso_start; }; typedef struct snd_usX2Y_hwdep_pcm_shm snd_usX2Y_hwdep_pcm_shm_t; -typedef struct { - alsa_driver_t *driver; - snd_hwdep_t *hwdep_handle; - struct pollfd pfds; - struct snd_usX2Y_hwdep_pcm_shm *hwdep_pcm_shm; - int playback_iso_start; - int playback_iso_bytes_done; - int capture_iso_start; - int capture_iso_bytes_done; -} usx2y_t; +typedef struct +{ + alsa_driver_t *driver; + snd_hwdep_t *hwdep_handle; + struct pollfd pfds; + struct snd_usX2Y_hwdep_pcm_shm *hwdep_pcm_shm; + int playback_iso_start; + int playback_iso_bytes_done; + int capture_iso_start; + int capture_iso_bytes_done; +} +usx2y_t; jack_hardware_t * jack_alsa_usx2y_hw_new (alsa_driver_t *driver); diff --git a/linux/driver.h b/linux/driver.h index 36f9408b..f2563751 100644 --- a/linux/driver.h +++ b/linux/driver.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2001 Paul Davis + Copyright (C) 2001 Paul Davis 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 @@ -65,7 +65,7 @@ typedef int (*JackDriverBufSizeFunction)(struct _jack_driver *, jack_nframes_t nframes); /* Call sequence summary: - + 1) engine loads driver via runtime dynamic linking - calls jack_driver_load - we call dlsym for "driver_initialize" and execute it @@ -79,7 +79,7 @@ typedef int (*JackDriverBufSizeFunction)(struct _jack_driver *, 5) engine stops driver 6) engine detaches from driver 7) engine calls driver `finish' routine - + Note that stop/start may be called multiple times in the event of an error return from the `wait' function. */ @@ -248,7 +248,7 @@ void jack_driver_unload (jack_driver_t *); /* Call sequence summary: - + 1) engine loads driver via runtime dynamic linking - calls jack_driver_load - we call dlsym for "driver_initialize" and execute it @@ -262,11 +262,11 @@ void jack_driver_unload (jack_driver_t *); 5) nt layer stops driver 6) nt layer detaches driver 7) engine calls driver `finish' routine which calls jack_driver_nt_finish - + Note that stop/start may be called multiple times in the event of an error return from the `wait' function. - - + + */ struct _jack_driver_nt; diff --git a/linux/firewire/JackFFADODriver.cpp b/linux/firewire/JackFFADODriver.cpp index 8261d828..1a115c75 100644 --- a/linux/firewire/JackFFADODriver.cpp +++ b/linux/firewire/JackFFADODriver.cpp @@ -60,25 +60,25 @@ JackFFADODriver::ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nfra printEnter(); for (chn = 0; chn < driver->capture_nchannels; chn++) { // if nothing connected, don't process - if(fGraphManager->GetConnectionsNum(fCapturePortList[chn]) == 0) { - buf=(jack_default_audio_sample_t*)driver->scratchbuffer; + if (fGraphManager->GetConnectionsNum(fCapturePortList[chn]) == 0) { + buf = (jack_default_audio_sample_t*)driver->scratchbuffer; // we always have to specify a valid buffer ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(buf)); // notify the streaming system that it can (but doesn't have to) skip // this channel ffado_streaming_capture_stream_onoff(driver->dev, chn, 0); } else { - if(driver->capture_channels[chn].stream_type == ffado_stream_type_audio) { + if (driver->capture_channels[chn].stream_type == ffado_stream_type_audio) { buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[chn], nframes); /* if the returned buffer is invalid, use the dummy buffer */ - if(!buf) buf=(jack_default_audio_sample_t*)driver->scratchbuffer; - + if (!buf) buf = (jack_default_audio_sample_t*)driver->scratchbuffer; + ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(buf)); ffado_streaming_capture_stream_onoff(driver->dev, chn, 1); } else if (driver->capture_channels[chn].stream_type == ffado_stream_type_midi) { - ffado_streaming_set_capture_stream_buffer(driver->dev, chn, - (char *)(driver->capture_channels[chn].midi_buffer)); + ffado_streaming_set_capture_stream_buffer(driver->dev, chn, + (char *)(driver->capture_channels[chn].midi_buffer)); ffado_streaming_capture_stream_onoff(driver->dev, chn, 1); } else { // always have a valid buffer ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(driver->scratchbuffer)); @@ -102,18 +102,18 @@ JackFFADODriver::ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nfra jack_midi_clear_buffer(buf); /* if the returned buffer is invalid, discard the midi data */ - if(!buf) continue; + if (!buf) continue; /* else unpack note that libffado guarantees that midi bytes are on 8-byte aligned indexes */ - for(i=0; i<nframes; i+=8) { - if(midi_buffer[i] & 0xFF000000) { - done=midi_unpack_buf(midi_unpack, (unsigned char *)(midi_buffer+i), 1, buf, i); + for (i = 0; i < nframes; i += 8) { + if (midi_buffer[i] & 0xFF000000) { + done = midi_unpack_buf(midi_unpack, (unsigned char *)(midi_buffer + i), 1, buf, i); if (done != 1) { printError("buffer overflow in channel %d\n", chn); break; } - + printMessage("MIDI IN: %08X (i=%d)", midi_buffer[i], i); } } @@ -134,18 +134,18 @@ JackFFADODriver::ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nfr driver->process_count++; for (chn = 0; chn < driver->playback_nchannels; chn++) { - if(fGraphManager->GetConnectionsNum(fPlaybackPortList[chn]) == 0) { - buf=(jack_default_audio_sample_t*)driver->nullbuffer; + if (fGraphManager->GetConnectionsNum(fPlaybackPortList[chn]) == 0) { + buf = (jack_default_audio_sample_t*)driver->nullbuffer; // we always have to specify a valid buffer ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(buf)); // notify the streaming system that it can (but doesn't have to) skip // this channel ffado_streaming_playback_stream_onoff(driver->dev, chn, 0); } else { - if(driver->playback_channels[chn].stream_type == ffado_stream_type_audio) { + if (driver->playback_channels[chn].stream_type == ffado_stream_type_audio) { buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], nframes); /* use the silent buffer if there is no valid jack buffer */ - if(!buf) buf=(jack_default_audio_sample_t*)driver->nullbuffer; + if (!buf) buf = (jack_default_audio_sample_t*)driver->nullbuffer; ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(buf)); } else if (driver->playback_channels[chn].stream_type == ffado_stream_type_midi) { @@ -154,65 +154,65 @@ JackFFADODriver::ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nfr midi_pack_t *midi_pack = &driver->playback_channels[chn].midi_pack; uint32_t *midi_buffer = driver->playback_channels[chn].midi_buffer; buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[chn], nframes); - int min_next_pos=0; + int min_next_pos = 0; memset(midi_buffer, 0, nframes * sizeof(uint32_t)); ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(midi_buffer)); /* if the returned buffer is invalid, continue */ - if(!buf) { + if (!buf) { ffado_streaming_playback_stream_onoff(driver->dev, chn, 0); continue; } ffado_streaming_playback_stream_onoff(driver->dev, chn, 1); // check if we still have to process bytes from the previous period - if(driver->playback_channels[chn].nb_overflow_bytes) { + if (driver->playback_channels[chn].nb_overflow_bytes) { printMessage("have to process %d bytes from previous period", driver->playback_channels[chn].nb_overflow_bytes); } - for (i=0; i<driver->playback_channels[chn].nb_overflow_bytes; ++i) { + for (i = 0; i < driver->playback_channels[chn].nb_overflow_bytes; ++i) { midi_buffer[min_next_pos] = 0x01000000 | (driver->playback_channels[chn].overflow_buffer[i] & 0xFF); min_next_pos += 8; } - driver->playback_channels[chn].nb_overflow_bytes=0; + driver->playback_channels[chn].nb_overflow_bytes = 0; // process the events in this period nevents = jack_midi_get_event_count(buf); //if (nevents) // printMessage("MIDI: %d events in ch %d", nevents, chn); - - for (i=0; i<nevents; ++i) { + + for (i = 0; i < nevents; ++i) { int j; jack_midi_event_t event; jack_midi_event_get(&event, buf, i); - + midi_pack_event(midi_pack, &event); - + // floor the initial position to be a multiple of 8 int pos = event.time & 0xFFFFFFF8; - for(j = 0; j < event.size; j++) { + for (j = 0; j < event.size; j++) { // make sure we don't overwrite a previous byte - while(pos < min_next_pos && pos < nframes) { + while (pos < min_next_pos && pos < nframes) { pos += 8; printMessage("have to correct pos to %d", pos); } - if(pos >= nframes) { + if (pos >= nframes) { int f; printMessage("midi message crosses period boundary"); driver->playback_channels[chn].nb_overflow_bytes = event.size - j; - if(driver->playback_channels[chn].nb_overflow_bytes > MIDI_OVERFLOW_BUFFER_SIZE) { + if (driver->playback_channels[chn].nb_overflow_bytes > MIDI_OVERFLOW_BUFFER_SIZE) { printError("too much midi bytes cross period boundary"); driver->playback_channels[chn].nb_overflow_bytes = MIDI_OVERFLOW_BUFFER_SIZE; } // save the bytes that still have to be transmitted in the next period - for(f=0; f<driver->playback_channels[chn].nb_overflow_bytes; f++) { + for (f = 0; f < driver->playback_channels[chn].nb_overflow_bytes; f++) { driver->playback_channels[chn].overflow_buffer[f] = event.buffer[j+f]; } // exit since we can't transmit anything anymore. // the rate should be controlled - if(i<nevents-1) { - printError("%d midi events lost due to period crossing", nevents-i-1); + if (i < nevents - 1) { + printError("%d midi events lost due to period crossing", nevents - i - 1); } break; } else { @@ -239,7 +239,7 @@ JackFFADODriver::ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nfr jack_nframes_t JackFFADODriver::ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *status, - float *delayed_usecs) + float *delayed_usecs) { int nframes; jack_time_t wait_enter; @@ -275,12 +275,12 @@ JackFFADODriver::ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *s if (response == ffado_wait_xrun) { // xrun happened, but it's handled - *status=0; + *status = 0; return 0; } else if (response == ffado_wait_error) { // an error happened (unhandled xrun) // this should be fatal - *status=-1; + *status = -1; return 0; } @@ -331,7 +331,7 @@ JackFFADODriver::SetBufferSize (jack_nframes_t nframes) printError("Buffer size change requested but not supported!!!"); /* - driver->period_size = nframes; + driver->period_size = nframes; driver->period_usecs = (jack_time_t) floor ((((float) nframes) / driver->sample_rate) * 1000000.0f); @@ -347,13 +347,13 @@ typedef void (*JackDriverFinishFunction) (jack_driver_t *); ffado_driver_t * JackFFADODriver::ffado_driver_new (char *name, - ffado_jack_settings_t *params) + ffado_jack_settings_t *params) { ffado_driver_t *driver; assert(params); - if(ffado_get_api_version() != FIREWIRE_REQUIRED_FFADO_API_VERSION) { + if (ffado_get_api_version() != FIREWIRE_REQUIRED_FFADO_API_VERSION) { printError("Incompatible libffado version! (%s)", ffado_get_version()); return NULL; } @@ -411,7 +411,7 @@ JackFFADODriver::ffado_driver_new (char *name, void JackFFADODriver::ffado_driver_delete (ffado_driver_t *driver) { - free (driver); + free (driver); } int JackFFADODriver::Attach() @@ -434,16 +434,16 @@ int JackFFADODriver::Attach() */ /* the null buffer is a buffer that contains one period of silence */ driver->nullbuffer = (ffado_sample_t *)calloc(driver->period_size, sizeof(ffado_sample_t)); - if(driver->nullbuffer == NULL) { + if (driver->nullbuffer == NULL) { printError("could not allocate memory for null buffer"); return -1; } /* calloc should do this, but it can't hurt to be sure */ memset(driver->nullbuffer, 0, driver->period_size*sizeof(ffado_sample_t)); - + /* the scratch buffer is a buffer of one period that can be used as dummy memory */ driver->scratchbuffer = (ffado_sample_t *)calloc(driver->period_size, sizeof(ffado_sample_t)); - if(driver->scratchbuffer == NULL) { + if (driver->scratchbuffer == NULL) { printError("could not allocate memory for scratch buffer"); return -1; } @@ -480,24 +480,24 @@ int JackFFADODriver::Attach() port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal; driver->capture_nchannels = ffado_streaming_get_nb_capture_streams(driver->dev); - driver->capture_channels=(ffado_capture_channel_t *)calloc(driver->capture_nchannels, sizeof(ffado_capture_channel_t)); - if(driver->capture_channels==NULL) { + driver->capture_channels = (ffado_capture_channel_t *)calloc(driver->capture_nchannels, sizeof(ffado_capture_channel_t)); + if (driver->capture_channels == NULL) { printError("could not allocate memory for capture channel list"); return -1; } - fCaptureChannels=0; + fCaptureChannels = 0; for (unsigned int chn = 0; chn < driver->capture_nchannels; chn++) { ffado_streaming_get_capture_stream_name(driver->dev, chn, portname, sizeof(portname) - 1); - driver->capture_channels[chn].stream_type=ffado_streaming_get_capture_stream_type(driver->dev, chn); - if(driver->capture_channels[chn].stream_type == ffado_stream_type_audio) { + driver->capture_channels[chn].stream_type = ffado_streaming_get_capture_stream_type(driver->dev, chn); + if (driver->capture_channels[chn].stream_type == ffado_stream_type_audio) { snprintf(buf, sizeof(buf) - 1, "%s:AC%d_%s", fClientControl->fName, (int)chn, portname); printMessage ("Registering audio capture port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_AUDIO_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_AUDIO_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -514,13 +514,13 @@ int JackFFADODriver::Attach() JackLog("JackFFADODriver::Attach fCapturePortList[i] %ld \n", port_index); fCaptureChannels++; - } else if(driver->capture_channels[chn].stream_type == ffado_stream_type_midi) { + } else if (driver->capture_channels[chn].stream_type == ffado_stream_type_midi) { snprintf(buf, sizeof(buf) - 1, "%s:MC%d_%s", fClientControl->fName, (int)chn, portname); printMessage ("Registering midi capture port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_MIDI_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_MIDI_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -529,10 +529,10 @@ int JackFFADODriver::Attach() if (ffado_streaming_set_capture_stream_buffer(driver->dev, chn, NULL)) { printError(" cannot configure initial port buffer for %s", buf); } - if(ffado_streaming_capture_stream_onoff(driver->dev, chn, 0)) { + if (ffado_streaming_capture_stream_onoff(driver->dev, chn, 0)) { printError(" cannot enable port %s", buf); } - + // setup midi unpacker midi_unpack_init(&driver->capture_channels[chn].midi_unpack); midi_unpack_reset(&driver->capture_channels[chn].midi_unpack); @@ -553,25 +553,25 @@ int JackFFADODriver::Attach() port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal; driver->playback_nchannels = ffado_streaming_get_nb_playback_streams(driver->dev); - driver->playback_channels=(ffado_playback_channel_t *)calloc(driver->playback_nchannels, sizeof(ffado_playback_channel_t)); - if(driver->playback_channels==NULL) { + driver->playback_channels = (ffado_playback_channel_t *)calloc(driver->playback_nchannels, sizeof(ffado_playback_channel_t)); + if (driver->playback_channels == NULL) { printError("could not allocate memory for playback channel list"); return -1; } - fPlaybackChannels=0; + fPlaybackChannels = 0; for (unsigned int chn = 0; chn < driver->playback_nchannels; chn++) { ffado_streaming_get_playback_stream_name(driver->dev, chn, portname, sizeof(portname) - 1); - driver->playback_channels[chn].stream_type=ffado_streaming_get_playback_stream_type(driver->dev, chn); + driver->playback_channels[chn].stream_type = ffado_streaming_get_playback_stream_type(driver->dev, chn); - if(driver->playback_channels[chn].stream_type == ffado_stream_type_audio) { + if (driver->playback_channels[chn].stream_type == ffado_stream_type_audio) { snprintf(buf, sizeof(buf) - 1, "%s:AP%d_%s", fClientControl->fName, (int)chn, portname); printMessage ("Registering audio playback port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_AUDIO_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_AUDIO_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -580,7 +580,7 @@ int JackFFADODriver::Attach() if (ffado_streaming_set_playback_stream_buffer(driver->dev, chn, NULL)) { printError(" cannot configure initial port buffer for %s", buf); } - if(ffado_streaming_playback_stream_onoff(driver->dev, chn, 0)) { + if (ffado_streaming_playback_stream_onoff(driver->dev, chn, 0)) { printError(" cannot enable port %s", buf); } @@ -589,13 +589,13 @@ int JackFFADODriver::Attach() fPlaybackPortList[chn] = port_index; JackLog("JackFFADODriver::Attach fPlaybackPortList[i] %ld \n", port_index); fPlaybackChannels++; - } else if(driver->playback_channels[chn].stream_type == ffado_stream_type_midi) { + } else if (driver->playback_channels[chn].stream_type == ffado_stream_type_midi) { snprintf(buf, sizeof(buf) - 1, "%s:MP%d_%s", fClientControl->fName, (int)chn, portname); printMessage ("Registering midi playback port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_MIDI_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_MIDI_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -604,7 +604,7 @@ int JackFFADODriver::Attach() if (ffado_streaming_set_playback_stream_buffer(driver->dev, chn, NULL)) { printError(" cannot configure initial port buffer for %s", buf); } - if(ffado_streaming_playback_stream_onoff(driver->dev, chn, 0)) { + if (ffado_streaming_playback_stream_onoff(driver->dev, chn, 0)) { printError(" cannot enable port %s", buf); } // setup midi packer @@ -625,7 +625,7 @@ int JackFFADODriver::Attach() assert(fCaptureChannels < PORT_NUM); assert(fPlaybackChannels < PORT_NUM); - if(ffado_streaming_prepare(driver->dev)) { + if (ffado_streaming_prepare(driver->dev)) { printError("Could not prepare streaming device!"); return -1; } @@ -647,13 +647,13 @@ int JackFFADODriver::Detach() // free all internal buffers for (chn = 0; chn < driver->capture_nchannels; chn++) { - if(driver->capture_channels[chn].midi_buffer) + if (driver->capture_channels[chn].midi_buffer) free(driver->capture_channels[chn].midi_buffer); } free(driver->capture_channels); - + for (chn = 0; chn < driver->playback_nchannels; chn++) { - if(driver->playback_channels[chn].midi_buffer) + if (driver->playback_channels[chn].midi_buffer) free(driver->playback_channels[chn].midi_buffer); } free(driver->playback_channels); @@ -661,7 +661,7 @@ int JackFFADODriver::Detach() free(driver->nullbuffer); free(driver->scratchbuffer); - return JackAudioDriver::Detach(); // Generic JackAudioDriver Detach + return JackAudioDriver::Detach(); // Generic JackAudioDriver Detach } int JackFFADODriver::Open(ffado_jack_settings_t *params) diff --git a/linux/firewire/JackFFADODriver.h b/linux/firewire/JackFFADODriver.h index 7a0af904..fba6ae60 100644 --- a/linux/firewire/JackFFADODriver.h +++ b/linux/firewire/JackFFADODriver.h @@ -50,8 +50,8 @@ class JackFFADODriver : public JackAudioDriver int ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nframes); int ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nframes); jack_nframes_t ffado_driver_wait (ffado_driver_t *driver, - int extra_fd, int *status, - float *delayed_usecs); + int extra_fd, int *status, + float *delayed_usecs); int ffado_driver_start (ffado_driver_t *driver); int ffado_driver_stop (ffado_driver_t *driver); int ffado_driver_restart (ffado_driver_t *driver); @@ -60,7 +60,7 @@ class JackFFADODriver : public JackAudioDriver void jack_driver_init (jack_driver_t *driver); void jack_driver_nt_init (jack_driver_nt_t * driver); - + public: JackFFADODriver(const char* name, JackEngine* engine, JackSynchro** table): JackAudioDriver(name, engine, table) diff --git a/linux/firewire/ffado_driver.h b/linux/firewire/ffado_driver.h index b9a51d26..f9a35a93 100644 --- a/linux/firewire/ffado_driver.h +++ b/linux/firewire/ffado_driver.h @@ -25,11 +25,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* +/* * Main Jack driver entry routines * - */ - + */ + #ifndef __JACK_FFADO_DRIVER_H__ #define __JACK_FFADO_DRIVER_H__ @@ -72,39 +72,39 @@ //#define DEBUG_ENABLED #ifdef DEBUG_ENABLED - // default debug level - #define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \ +// default debug level +#define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \ (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER) - #warning Building debug build! - - #define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) - #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) - - #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__) - #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__) - #define printEnter() - #define printExit() - - #define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) - #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args ); - #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args ); - #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args ); - #define SEGFAULT int *test=NULL; *test=1; +#warning Building debug build! + +#define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) +#define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) + +#define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__) +#define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__) +#define printEnter() +#define printExit() + +#define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args ) +#define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args ); +#define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args ); +#define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args ); +#define SEGFAULT int *test=NULL; *test=1; #else - #define DEBUG_LEVEL - - #define printMessage(format, args...) if(g_verbose) \ +#define DEBUG_LEVEL + +#define printMessage(format, args...) if(g_verbose) \ jack_error("firewire MSG: " format, ##args ) - #define printError(format, args...) jack_error("firewire ERR: " format, ##args ) - - #define printEnter() - #define printExit() - - #define debugError(format, args...) - #define debugPrint(Level, format, args...) - #define debugPrintShort(Level, format, args...) - #define debugPrintWithTimeStamp(Level, format, args...) +#define printError(format, args...) jack_error("firewire ERR: " format, ##args ) + +#define printEnter() +#define printExit() + +#define debugError(format, args...) +#define debugPrint(Level, format, args...) +#define debugPrintShort(Level, format, args...) +#define debugPrintWithTimeStamp(Level, format, args...) #endif // thread priority setup @@ -117,27 +117,28 @@ typedef struct _ffado_driver ffado_driver_t; */ typedef struct _ffado_jack_settings ffado_jack_settings_t; -struct _ffado_jack_settings { +struct _ffado_jack_settings +{ int verbose_level; int period_size_set; jack_nframes_t period_size; - + int sample_rate_set; int sample_rate; - + int buffer_size_set; jack_nframes_t buffer_size; int playback_ports; int capture_ports; - + jack_nframes_t capture_frame_latency; jack_nframes_t playback_frame_latency; - + int slave_mode; int snoop_mode; - + char *device_info; }; @@ -146,7 +147,8 @@ typedef struct _ffado_capture_channel ffado_streaming_stream_type stream_type; midi_unpack_t midi_unpack; uint32_t *midi_buffer; -} ffado_capture_channel_t; +} +ffado_capture_channel_t; #define MIDI_OVERFLOW_BUFFER_SIZE 4 typedef struct _ffado_playback_channel @@ -158,36 +160,37 @@ typedef struct _ffado_playback_channel // during the previous period char overflow_buffer[MIDI_OVERFLOW_BUFFER_SIZE]; unsigned int nb_overflow_bytes; -} ffado_playback_channel_t; +} +ffado_playback_channel_t; /* * JACK driver structure */ struct _ffado_driver { - JACK_DRIVER_NT_DECL; - - jack_nframes_t sample_rate; - jack_nframes_t period_size; - unsigned long wait_time; + JACK_DRIVER_NT_DECL; + + jack_nframes_t sample_rate; + jack_nframes_t period_size; + unsigned long wait_time; jack_time_t wait_last; jack_time_t wait_next; - int wait_late; - - jack_client_t *client; - - int xrun_detected; - int xrun_count; - - int process_count; - - /* settings from the command line */ - ffado_jack_settings_t settings; - - /* the firewire virtual device */ - ffado_device_t *dev; - + int wait_late; + + jack_client_t *client; + + int xrun_detected; + int xrun_count; + + int process_count; + + /* settings from the command line */ + ffado_jack_settings_t settings; + + /* the firewire virtual device */ + ffado_device_t *dev; + channel_t playback_nchannels; channel_t capture_nchannels; @@ -195,12 +198,12 @@ struct _ffado_driver ffado_capture_channel_t *capture_channels; ffado_sample_t *nullbuffer; ffado_sample_t *scratchbuffer; - + jack_nframes_t playback_frame_latency; - jack_nframes_t capture_frame_latency; - - ffado_device_info_t device_info; - ffado_options_t device_options; + jack_nframes_t capture_frame_latency; + + ffado_device_info_t device_info; + ffado_options_t device_options; }; diff --git a/linux/freebob/JackFreebobDriver.cpp b/linux/freebob/JackFreebobDriver.cpp index b934c706..c333bd27 100644 --- a/linux/freebob/JackFreebobDriver.cpp +++ b/linux/freebob/JackFreebobDriver.cpp @@ -137,7 +137,7 @@ JackFreebobDriver::freebob_driver_write (freebob_driver_t * driver, jack_nframes // Ouput ports if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) { buf = (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[i], nframes); - if (!buf) { + if (!buf) { buf = (jack_default_audio_sample_t *)addr_of_nullbuffer; } freebob_streaming_set_playback_stream_buffer(driver->dev, i, (char *)(buf), freebob_buffer_type_float); @@ -304,7 +304,7 @@ JackFreebobDriver::freebob_driver_new (char *name, driver->write = (JackDriverReadFunction) freebob_driver_write; driver->read = (JackDriverReadFunction) freebob_driver_read; driver->nt_bufsize = (JackDriverNTBufSizeFunction) freebob_driver_bufsize; - */ + */ /* copy command line parameter contents to the driver structure */ memcpy(&driver->settings, params, sizeof(freebob_jack_settings_t)); @@ -349,7 +349,7 @@ JackFreebobDriver::freebob_driver_new (char *name, void JackFreebobDriver::freebob_driver_delete (freebob_driver_t *driver) { - free (driver); + free (driver); } #ifdef FREEBOB_DRIVER_WITH_MIDI @@ -386,7 +386,7 @@ JackFreebobDriver::freebob_driver_midi_queue_thread(void *arg) if (!port) { printError(" Could not find target port for event: dst=%d src=%d", ev->dest.port, ev->source.port); - break; + break; } // decode it to the work buffer @@ -430,7 +430,7 @@ JackFreebobDriver::freebob_driver_midi_dequeue_thread (void *arg) for (i = 0;i < m->nb_input_ports;i++) { unsigned int buff[64]; - freebob_midi_port_t *port = m->input_ports[i]; + freebob_midi_port_t *port = m->input_ports[i]; if (!port) { printError(" something went wrong when setting up the midi input port map (%d)", i); } @@ -734,9 +734,9 @@ int JackFreebobDriver::Attach() printMessage ("Registering capture port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_AUDIO_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_AUDIO_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -764,9 +764,9 @@ int JackFreebobDriver::Attach() } else { printMessage ("Registering playback port %s", buf); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, buf, - JACK_DEFAULT_AUDIO_TYPE, - (JackPortFlags)port_flags, - fEngineControl->fBufferSize)) == NO_PORT) { + JACK_DEFAULT_AUDIO_TYPE, + (JackPortFlags)port_flags, + fEngineControl->fBufferSize)) == NO_PORT) { jack_error("driver: cannot register port for %s", buf); return -1; } @@ -805,7 +805,7 @@ int JackFreebobDriver::Detach() driver->midi_handle = NULL; #endif - return JackAudioDriver::Detach(); // Generic JackAudioDriver Detach + return JackAudioDriver::Detach(); // Generic JackAudioDriver Detach } int JackFreebobDriver::Open(freebob_jack_settings_t *params) diff --git a/linux/freebob/JackFreebobDriver.h b/linux/freebob/JackFreebobDriver.h index 25135992..49916bc7 100644 --- a/linux/freebob/JackFreebobDriver.h +++ b/linux/freebob/JackFreebobDriver.h @@ -67,7 +67,7 @@ class JackFreebobDriver : public JackAudioDriver void jack_driver_init (jack_driver_t *driver); void jack_driver_nt_init (jack_driver_nt_t * driver); - + public: JackFreebobDriver(const char* name, JackEngine* engine, JackSynchro** table): JackAudioDriver(name, engine, table) diff --git a/macosx/JackCoreAudioDriver.cpp b/macosx/JackCoreAudioDriver.cpp index 792c2570..30fdcd91 100644 --- a/macosx/JackCoreAudioDriver.cpp +++ b/macosx/JackCoreAudioDriver.cpp @@ -104,10 +104,10 @@ static void printError(OSStatus err) case kAudioDevicePermissionsError: JackLog("error code : kAudioDevicePermissionsError\n"); break; - case kAudioHardwareBadObjectError: + case kAudioHardwareBadObjectError: JackLog("error code : kAudioHardwareBadObjectError\n"); break; - case kAudioHardwareUnsupportedOperationError: + case kAudioHardwareUnsupportedOperationError: JackLog("error code : kAudioHardwareUnsupportedOperationError\n"); break; default: @@ -171,17 +171,17 @@ OSStatus JackCoreAudioDriver::Render(void *inRefCon, UInt32 inNumberFrames, AudioBufferList *ioData) { - JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inRefCon; + JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inRefCon; driver->fLastWaitUst = GetMicroSeconds(); // Take callback date here - driver->fActionFags = ioActionFlags; - driver->fCurrentTime = (AudioTimeStamp *)inTimeStamp; - driver->fDriverOutputData = ioData; + driver->fActionFags = ioActionFlags; + driver->fCurrentTime = (AudioTimeStamp *)inTimeStamp; + driver->fDriverOutputData = ioData; return driver->Process(); } int JackCoreAudioDriver::Read() { - AudioUnitRender(fAUHAL, fActionFags, fCurrentTime, 1, fEngineControl->fBufferSize, fJackInputData); + AudioUnitRender(fAUHAL, fActionFags, fCurrentTime, 1, fEngineControl->fBufferSize, fJackInputData); return 0; } @@ -225,18 +225,18 @@ OSStatus JackCoreAudioDriver::SRNotificationCallback(AudioDeviceID inDevice, AudioDevicePropertyID inPropertyID, void* inClientData) { - JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inClientData; - - switch (inPropertyID) { - - case kAudioDevicePropertyNominalSampleRate: { - JackLog("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate \n"); - driver->fState = true; - break; - } - } - - return noErr; + JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inClientData; + + switch (inPropertyID) { + + case kAudioDevicePropertyNominalSampleRate: { + JackLog("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate \n"); + driver->fState = true; + break; + } + } + + return noErr; } // A better implementation would try to recover in case of hardware device change (see HALLAB HLFilePlayerWindowControllerAudioDevicePropertyListenerProc code) @@ -248,76 +248,76 @@ OSStatus JackCoreAudioDriver::DeviceNotificationCallback(AudioDeviceID inDevice, void* inClientData) { JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inClientData; - - switch (inPropertyID) { - - case kAudioDeviceProcessorOverload: - JackLog("JackCoreAudioDriver::DeviceNotificationCallback kAudioDeviceProcessorOverload\n"); - driver->NotifyXRun(GetMicroSeconds()); - break; - - case kAudioDevicePropertyStreamConfiguration: - case kAudioDevicePropertyNominalSampleRate: { - - UInt32 outSize = sizeof(Float64); - Float64 sampleRate; - int in_nChannels = 0; - int out_nChannels = 0; - char capture_driver_name[256]; - char playback_driver_name[256]; - - // Stop and restart - driver->Stop(); - driver->RemoveListeners(); - driver->CloseAUHAL(); - - OSStatus err = AudioDeviceGetProperty(driver->fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot get current sample rate"); - printError(err); - } - JackLog("JackCoreAudioDriver::DeviceNotificationCallback kAudioDevicePropertyNominalSampleRate %ld\n", long(sampleRate)); - - if (driver->SetupDevices(driver->fCaptureUID, driver->fPlaybackUID, capture_driver_name, playback_driver_name) < 0) - return -1; - - if (driver->SetupChannels(driver->fCapturing, driver->fPlaying, driver->fInChannels, driver->fOutChannels, in_nChannels, out_nChannels, false) < 0) - return -1; - - if (driver->SetupBufferSizeAndSampleRate(driver->fEngineControl->fBufferSize, sampleRate) < 0) - return -1; - - if (driver->OpenAUHAL(driver->fCapturing, - driver->fPlaying, - driver->fInChannels, - driver->fOutChannels, - in_nChannels, - out_nChannels, - driver->fEngineControl->fBufferSize, - sampleRate, - false) < 0) - goto error; - - if (driver->AddListeners() < 0) - goto error; - - driver->Start(); - - // Send notification to be used in JackPilot or JackRouter plugin - jack_error("Device restart..."); - CFStringRef ref = CFStringCreateWithCString(NULL, driver->fEngineControl->fServerName, kCFStringEncodingMacRoman); - CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), - CFSTR("com.grame.jackserver.restart"), - ref, - NULL, - kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); - CFRelease(ref); - return noErr; - error: - driver->CloseAUHAL(); - break; - } - } + + switch (inPropertyID) { + + case kAudioDeviceProcessorOverload: + JackLog("JackCoreAudioDriver::DeviceNotificationCallback kAudioDeviceProcessorOverload\n"); + driver->NotifyXRun(GetMicroSeconds()); + break; + + case kAudioDevicePropertyStreamConfiguration: + case kAudioDevicePropertyNominalSampleRate: { + + UInt32 outSize = sizeof(Float64); + Float64 sampleRate; + int in_nChannels = 0; + int out_nChannels = 0; + char capture_driver_name[256]; + char playback_driver_name[256]; + + // Stop and restart + driver->Stop(); + driver->RemoveListeners(); + driver->CloseAUHAL(); + + OSStatus err = AudioDeviceGetProperty(driver->fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot get current sample rate"); + printError(err); + } + JackLog("JackCoreAudioDriver::DeviceNotificationCallback kAudioDevicePropertyNominalSampleRate %ld\n", long(sampleRate)); + + if (driver->SetupDevices(driver->fCaptureUID, driver->fPlaybackUID, capture_driver_name, playback_driver_name) < 0) + return -1; + + if (driver->SetupChannels(driver->fCapturing, driver->fPlaying, driver->fInChannels, driver->fOutChannels, in_nChannels, out_nChannels, false) < 0) + return -1; + + if (driver->SetupBufferSizeAndSampleRate(driver->fEngineControl->fBufferSize, sampleRate) < 0) + return -1; + + if (driver->OpenAUHAL(driver->fCapturing, + driver->fPlaying, + driver->fInChannels, + driver->fOutChannels, + in_nChannels, + out_nChannels, + driver->fEngineControl->fBufferSize, + sampleRate, + false) < 0) + goto error; + + if (driver->AddListeners() < 0) + goto error; + + driver->Start(); + + // Send notification to be used in JackPilot or JackRouter plugin + jack_error("Device restart..."); + CFStringRef ref = CFStringCreateWithCString(NULL, driver->fEngineControl->fServerName, kCFStringEncodingMacRoman); + CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDistributedCenter(), + CFSTR("com.grame.jackserver.restart"), + ref, + NULL, + kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); + CFRelease(ref); + return noErr; +error: + driver->CloseAUHAL(); + break; + } + } return noErr; } @@ -402,7 +402,7 @@ OSStatus JackCoreAudioDriver::GetTotalChannels(AudioDeviceID device, int* channe UInt32 outSize; Boolean outWritable; AudioBufferList* bufferList = 0; - + *channelCount = 0; err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable); if (err == noErr) { @@ -412,9 +412,9 @@ OSStatus JackCoreAudioDriver::GetTotalChannels(AudioDeviceID device, int* channe for (unsigned int i = 0; i < bufferList->mNumberBuffers; i++) *channelCount += bufferList->mBuffers[i].mNumberChannels; } - - if (bufferList) - free(bufferList); + + if (bufferList) + free(bufferList); } return err; @@ -429,10 +429,10 @@ JackCoreAudioDriver::~JackCoreAudioDriver() int JackCoreAudioDriver::SetupDevices(const char* capture_driver_uid, const char* playback_driver_uid, char* capture_driver_name, char* playback_driver_name) { - capture_driver_name[0] = 0; + capture_driver_name[0] = 0; playback_driver_name[0] = 0; - - // Duplex + + // Duplex if (strcmp(capture_driver_uid, "") != 0 && strcmp(playback_driver_uid, "") != 0) { JackLog("JackCoreAudioDriver::Open duplex \n"); if (GetDeviceIDFromUID(playback_driver_uid, &fDeviceID) != noErr) { @@ -446,7 +446,7 @@ int JackCoreAudioDriver::SetupDevices(const char* capture_driver_uid, const char return -1; } - // Capture only + // Capture only } else if (strcmp(capture_driver_uid, "") != 0) { JackLog("JackCoreAudioDriver::Open capture only \n"); if (GetDeviceIDFromUID(capture_driver_uid, &fDeviceID) != noErr) { @@ -460,7 +460,7 @@ int JackCoreAudioDriver::SetupDevices(const char* capture_driver_uid, const char return -1; } - // Playback only + // Playback only } else if (strcmp(playback_driver_uid, "") != 0) { JackLog("JackCoreAudioDriver::Open playback only \n"); if (GetDeviceIDFromUID(playback_driver_uid, &fDeviceID) != noErr) { @@ -474,7 +474,7 @@ int JackCoreAudioDriver::SetupDevices(const char* capture_driver_uid, const char return -1; } - // Use default driver in duplex mode + // Use default driver in duplex mode } else { JackLog("JackCoreAudioDriver::Open default driver \n"); if (GetDefaultDevice(&fDeviceID) != noErr) { @@ -486,15 +486,15 @@ int JackCoreAudioDriver::SetupDevices(const char* capture_driver_uid, const char return -1; } } - - return 0; + + return 0; } int JackCoreAudioDriver::SetupChannels(bool capturing, bool playing, int& inchannels, int& outchannels, int& in_nChannels, int& out_nChannels, bool strict) { - OSStatus err = noErr; - - if (capturing) { + OSStatus err = noErr; + + if (capturing) { err = GetTotalChannels(fDeviceID, &in_nChannels, true); if (err != noErr) { jack_error("Cannot get input channel number"); @@ -514,14 +514,14 @@ int JackCoreAudioDriver::SetupChannels(bool capturing, bool playing, int& inchan if (inchannels > in_nChannels) { jack_error("This device hasn't required input channels inchannels = %ld in_nChannels = %ld", inchannels, in_nChannels); - if (strict) - return -1; - } + if (strict) + return -1; + } if (outchannels > out_nChannels) { jack_error("This device hasn't required output channels outchannels = %ld out_nChannels = %ld", outchannels, out_nChannels); if (strict) - return -1; + return -1; } if (inchannels == 0) { @@ -533,19 +533,19 @@ int JackCoreAudioDriver::SetupChannels(bool capturing, bool playing, int& inchan JackLog("Setup max out channels = %ld\n", out_nChannels); outchannels = out_nChannels; } - - return 0; + + return 0; } int JackCoreAudioDriver::SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate) { - OSStatus err = noErr; + OSStatus err = noErr; UInt32 outSize; - Float64 sampleRate; - - // Setting buffer size + Float64 sampleRate; + + // Setting buffer size outSize = sizeof(UInt32); - err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes); + err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes); if (err != noErr) { jack_error("Cannot set buffer size %ld", nframes); printError(err); @@ -553,63 +553,63 @@ int JackCoreAudioDriver::SetupBufferSizeAndSampleRate(jack_nframes_t nframes, ja } // Get sample rate - outSize = sizeof(Float64); - err = AudioDeviceGetProperty(fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot get current sample rate"); - printError(err); - return -1; - } - - // If needed, set new sample rate - if (samplerate != (jack_nframes_t)sampleRate) { - sampleRate = (Float64)samplerate; - - // To get SR change notification - err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback, this); - if (err != noErr) { - jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate"); - printError(err); - return -1; - } - err = AudioDeviceSetProperty(fDeviceID, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot set sample rate = %ld", samplerate); - printError(err); - return -1; - } - - // Waiting for SR change notification - int count = 0; - while (!fState && count++ < 100) { - usleep(100000); - JackLog("Wait count = %ld\n", count); - } - - // Remove SR change notification - AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback); - } - - return 0; + outSize = sizeof(Float64); + err = AudioDeviceGetProperty(fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot get current sample rate"); + printError(err); + return -1; + } + + // If needed, set new sample rate + if (samplerate != (jack_nframes_t)sampleRate) { + sampleRate = (Float64)samplerate; + + // To get SR change notification + err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback, this); + if (err != noErr) { + jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate"); + printError(err); + return -1; + } + err = AudioDeviceSetProperty(fDeviceID, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot set sample rate = %ld", samplerate); + printError(err); + return -1; + } + + // Waiting for SR change notification + int count = 0; + while (!fState && count++ < 100) { + usleep(100000); + JackLog("Wait count = %ld\n", count); + } + + // Remove SR change notification + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, SRNotificationCallback); + } + + return 0; } -int JackCoreAudioDriver::OpenAUHAL(bool capturing, - bool playing, - int inchannels, - int outchannels, - int in_nChannels, - int out_nChannels, - jack_nframes_t nframes, - jack_nframes_t samplerate, - bool strict) +int JackCoreAudioDriver::OpenAUHAL(bool capturing, + bool playing, + int inchannels, + int outchannels, + int in_nChannels, + int out_nChannels, + jack_nframes_t nframes, + jack_nframes_t samplerate, + bool strict) { - ComponentResult err1; + ComponentResult err1; UInt32 enableIO; AudioStreamBasicDescription srcFormat, dstFormat; - - JackLog("OpenAUHAL capturing = %ld playing = %ld playing = %ld outchannels = %ld in_nChannels = %ld out_nChannels = %ld \n", capturing, playing, inchannels, inchannels, in_nChannels, out_nChannels); - - // AUHAL + + JackLog("OpenAUHAL capturing = %ld playing = %ld playing = %ld outchannels = %ld in_nChannels = %ld out_nChannels = %ld \n", capturing, playing, inchannels, inchannels, in_nChannels, out_nChannels); + + // AUHAL ComponentDescription cd = {kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0}; Component HALOutput = FindNextComponent(NULL, &cd); @@ -636,7 +636,7 @@ int JackCoreAudioDriver::OpenAUHAL(bool capturing, jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input"); printError(err1); if (strict) - return -1; + return -1; } } @@ -647,7 +647,7 @@ int JackCoreAudioDriver::OpenAUHAL(bool capturing, jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output"); printError(err1); if (strict) - return -1; + return -1; } } @@ -657,27 +657,27 @@ int JackCoreAudioDriver::OpenAUHAL(bool capturing, jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_CurrentDevice"); printError(err1); if (strict) - return -1; + return -1; } // Set buffer size if (capturing && inchannels > 0) { - err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*)&nframes, sizeof(UInt32)); + err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*) & nframes, sizeof(UInt32)); if (err1 != noErr) { jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice"); printError(err1); if (strict) - return -1; + return -1; } } if (playing && outchannels > 0) { - err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*)&nframes, sizeof(UInt32)); + err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*) & nframes, sizeof(UInt32)); if (err1 != noErr) { jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice"); printError(err1); - if (strict) - return -1; + if (strict) + return -1; } } @@ -713,38 +713,38 @@ int JackCoreAudioDriver::OpenAUHAL(bool capturing, } // Setup stream converters - JackLog("Setup AUHAL input stream converter SR = %ld\n", samplerate); - srcFormat.mSampleRate = samplerate; - srcFormat.mFormatID = kAudioFormatLinearPCM; - srcFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved; - srcFormat.mBytesPerPacket = sizeof(float); - srcFormat.mFramesPerPacket = 1; - srcFormat.mBytesPerFrame = sizeof(float); - srcFormat.mChannelsPerFrame = outchannels; - srcFormat.mBitsPerChannel = 32; - - err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription)); - if (err1 != noErr) { - jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input"); - printError(err1); - } - - JackLog("Setup AUHAL output stream converter SR = %ld\n", samplerate); - dstFormat.mSampleRate = samplerate; - dstFormat.mFormatID = kAudioFormatLinearPCM; - dstFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved; - dstFormat.mBytesPerPacket = sizeof(float); - dstFormat.mFramesPerPacket = 1; - dstFormat.mBytesPerFrame = sizeof(float); - dstFormat.mChannelsPerFrame = inchannels; - dstFormat.mBitsPerChannel = 32; - - err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription)); - if (err1 != noErr) { - jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output"); - printError(err1); - } - + JackLog("Setup AUHAL input stream converter SR = %ld\n", samplerate); + srcFormat.mSampleRate = samplerate; + srcFormat.mFormatID = kAudioFormatLinearPCM; + srcFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved; + srcFormat.mBytesPerPacket = sizeof(float); + srcFormat.mFramesPerPacket = 1; + srcFormat.mBytesPerFrame = sizeof(float); + srcFormat.mChannelsPerFrame = outchannels; + srcFormat.mBitsPerChannel = 32; + + err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription)); + if (err1 != noErr) { + jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input"); + printError(err1); + } + + JackLog("Setup AUHAL output stream converter SR = %ld\n", samplerate); + dstFormat.mSampleRate = samplerate; + dstFormat.mFormatID = kAudioFormatLinearPCM; + dstFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved; + dstFormat.mBytesPerPacket = sizeof(float); + dstFormat.mFramesPerPacket = 1; + dstFormat.mBytesPerFrame = sizeof(float); + dstFormat.mChannelsPerFrame = inchannels; + dstFormat.mBitsPerChannel = 32; + + err1 = AudioUnitSetProperty(fAUHAL, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription)); + if (err1 != noErr) { + jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output"); + printError(err1); + } + // Setup callbacks if (inchannels > 0 && outchannels == 0) { AURenderCallbackStruct output; @@ -768,31 +768,31 @@ int JackCoreAudioDriver::OpenAUHAL(bool capturing, } } - return 0; + return 0; } int JackCoreAudioDriver::SetupBuffers(int inchannels, int outchannels) { - // Prepare buffers - fJackInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer)); - if (fJackInputData == 0) { - jack_error("Cannot allocate memory for input buffers"); - return -1; - } - fJackInputData->mNumberBuffers = inchannels; - for (int i = 0; i < fCaptureChannels; i++) { - fJackInputData->mBuffers[i].mNumberChannels = 1; - fJackInputData->mBuffers[i].mDataByteSize = fEngineControl->fBufferSize * sizeof(float); - } - return 0; + // Prepare buffers + fJackInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer)); + if (fJackInputData == 0) { + jack_error("Cannot allocate memory for input buffers"); + return -1; + } + fJackInputData->mNumberBuffers = inchannels; + for (int i = 0; i < fCaptureChannels; i++) { + fJackInputData->mBuffers[i].mNumberChannels = 1; + fJackInputData->mBuffers[i].mDataByteSize = fEngineControl->fBufferSize * sizeof(float); + } + return 0; } void JackCoreAudioDriver::DisposeBuffers() { - if (fJackInputData) { - free(fJackInputData); - fJackInputData = 0; - } + if (fJackInputData) { + free(fJackInputData); + fJackInputData = 0; + } } void JackCoreAudioDriver::CloseAUHAL() @@ -803,9 +803,9 @@ void JackCoreAudioDriver::CloseAUHAL() int JackCoreAudioDriver::AddListeners() { - OSStatus err = noErr; - - // Add listeners + OSStatus err = noErr; + + // Add listeners err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDeviceProcessorOverload, DeviceNotificationCallback, this); if (err != noErr) { jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDeviceProcessorOverload"); @@ -819,29 +819,29 @@ int JackCoreAudioDriver::AddListeners() printError(err); return -1; } - - err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback, this); + + err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback, this); if (err != noErr) { jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate"); printError(err); return -1; } - - err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback, this); + + err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback, this); if (err != noErr) { jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyDeviceIsRunning"); printError(err); return -1; } - - err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this); + + err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this); if (err != noErr) { jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyStreamConfiguration"); printError(err); return -1; } - err = AudioDeviceAddPropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this); + err = AudioDeviceAddPropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback, this); if (err != noErr) { jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyStreamConfiguration"); printError(err); @@ -849,29 +849,29 @@ int JackCoreAudioDriver::AddListeners() } #if IO_CPU - if (!fEngineControl->fSyncMode) { - UInt32 outSize = sizeof(float); - float iousage = 0.5f; - err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyIOCycleUsage, outSize, &iousage); - if (err != noErr) { - jack_error("Error calling AudioDeviceSetProperty kAudioDevicePropertyIOCycleUsage"); - printError(err); - } - } + if (!fEngineControl->fSyncMode) { + UInt32 outSize = sizeof(float); + float iousage = 0.5f; + err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyIOCycleUsage, outSize, &iousage); + if (err != noErr) { + jack_error("Error calling AudioDeviceSetProperty kAudioDevicePropertyIOCycleUsage"); + printError(err); + } + } #endif - return 0; + return 0; } void JackCoreAudioDriver::RemoveListeners() { - AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); + AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDeviceProcessorOverload, DeviceNotificationCallback); - AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioHardwarePropertyDevices, DeviceNotificationCallback); - AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback); - AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback); - AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback); - AudioDeviceRemovePropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioHardwarePropertyDevices, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyDeviceIsRunning, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, false, kAudioDevicePropertyStreamConfiguration, DeviceNotificationCallback); } int JackCoreAudioDriver::Open(jack_nframes_t nframes, @@ -886,63 +886,63 @@ int JackCoreAudioDriver::Open(jack_nframes_t nframes, jack_nframes_t capture_latency, jack_nframes_t playback_latency) { - int in_nChannels = 0; + int in_nChannels = 0; int out_nChannels = 0; char capture_driver_name[256]; char playback_driver_name[256]; - - // Keep initial state - fCapturing = capturing; - fPlaying = playing; - fInChannels = inchannels; - fOutChannels = outchannels; - fMonitor = monitor; - strcpy(fCaptureUID, capture_driver_uid); - strcpy(fPlaybackUID, playback_driver_uid); - fCaptureLatency = capture_latency; - fPlaybackLatency = playback_latency; - - if (SetupDevices(capture_driver_uid, playback_driver_uid, capture_driver_name, playback_driver_name) < 0) - return -1; - + + // Keep initial state + fCapturing = capturing; + fPlaying = playing; + fInChannels = inchannels; + fOutChannels = outchannels; + fMonitor = monitor; + strcpy(fCaptureUID, capture_driver_uid); + strcpy(fPlaybackUID, playback_driver_uid); + fCaptureLatency = capture_latency; + fPlaybackLatency = playback_latency; + + if (SetupDevices(capture_driver_uid, playback_driver_uid, capture_driver_name, playback_driver_name) < 0) + return -1; + // Generic JackAudioDriver Open - if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency) != 0) - return -1; - - if (SetupChannels(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, true) < 0) - return -1; - - if (SetupBufferSizeAndSampleRate(nframes, samplerate) < 0) - return -1; - - if (OpenAUHAL(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, nframes, samplerate, true) < 0) - goto error; - - if (capturing && inchannels > 0) - if (SetupBuffers(inchannels, outchannels) < 0) - goto error; - - if (AddListeners() < 0) - goto error; - + if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency) != 0) + return -1; + + if (SetupChannels(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, true) < 0) + return -1; + + if (SetupBufferSizeAndSampleRate(nframes, samplerate) < 0) + return -1; + + if (OpenAUHAL(capturing, playing, inchannels, outchannels, in_nChannels, out_nChannels, nframes, samplerate, true) < 0) + goto error; + + if (capturing && inchannels > 0) + if (SetupBuffers(inchannels, outchannels) < 0) + goto error; + + if (AddListeners() < 0) + goto error; + // Core driver may have changed the in/out values fCaptureChannels = inchannels; fPlaybackChannels = outchannels; return noErr; error: - Close(); + Close(); return -1; } int JackCoreAudioDriver::Close() { - JackLog("JackCoreAudioDriver::Close\n"); - Stop(); + JackLog("JackCoreAudioDriver::Close\n"); + Stop(); JackAudioDriver::Close(); RemoveListeners(); - DisposeBuffers(); - CloseAUHAL(); + DisposeBuffers(); + CloseAUHAL(); return 0; } @@ -955,7 +955,7 @@ int JackCoreAudioDriver::Attach() Boolean isWritable; char channel_name[64]; char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; - char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal; JackLog("JackCoreAudioDriver::Attach fBufferSize %ld fSampleRate %ld\n", fEngineControl->fBufferSize, fEngineControl->fSampleRate); @@ -973,26 +973,26 @@ int JackCoreAudioDriver::Attach() } else { snprintf(alias, sizeof(alias) - 1, "%s:%s:out%u", fClientControl->fName, fCaptureDriverName, i + 1); } - - snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); - + + snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1); + if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("Cannot register port for %s", name); return -1; } - - size = sizeof(UInt32); - UInt32 value1 = 0; - UInt32 value2 = 0; - err = AudioDeviceGetProperty(fDeviceID, 0, true, kAudioDevicePropertyLatency, &size, &value1); - if (err != noErr) - JackLog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n"); - err = AudioDeviceGetProperty(fDeviceID, 0, true, kAudioDevicePropertySafetyOffset, &size, &value2); - if (err != noErr) - JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n"); - + + size = sizeof(UInt32); + UInt32 value1 = 0; + UInt32 value2 = 0; + err = AudioDeviceGetProperty(fDeviceID, 0, true, kAudioDevicePropertyLatency, &size, &value1); + if (err != noErr) + JackLog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n"); + err = AudioDeviceGetProperty(fDeviceID, 0, true, kAudioDevicePropertySafetyOffset, &size, &value2); + if (err != noErr) + JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n"); + port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + port->SetAlias(alias); port->SetLatency(fEngineControl->fBufferSize + value1 + value2 + fCaptureLatency); fCapturePortList[i] = port_index; } @@ -1012,26 +1012,26 @@ int JackCoreAudioDriver::Attach() } else { snprintf(alias, sizeof(alias) - 1, "%s:%s:in%u", fClientControl->fName, fPlaybackDriverName, i + 1); } - - snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); + + snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1); if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) { jack_error("Cannot register port for %s", name); return -1; } - - size = sizeof(UInt32); - UInt32 value1 = 0; - UInt32 value2 = 0; - err = AudioDeviceGetProperty(fDeviceID, 0, false, kAudioDevicePropertyLatency, &size, &value1); - if (err != noErr) - JackLog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n"); - err = AudioDeviceGetProperty(fDeviceID, 0, false, kAudioDevicePropertySafetyOffset, &size, &value2); - if (err != noErr) - JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n"); - - port = fGraphManager->GetPort(port_index); - port->SetAlias(alias); + + size = sizeof(UInt32); + UInt32 value1 = 0; + UInt32 value2 = 0; + err = AudioDeviceGetProperty(fDeviceID, 0, false, kAudioDevicePropertyLatency, &size, &value1); + if (err != noErr) + JackLog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n"); + err = AudioDeviceGetProperty(fDeviceID, 0, false, kAudioDevicePropertySafetyOffset, &size, &value2); + if (err != noErr) + JackLog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n"); + + port = fGraphManager->GetPort(port_index); + port->SetAlias(alias); port->SetLatency(fEngineControl->fBufferSize + value1 + value2 + fPlaybackLatency); fPlaybackPortList[i] = port_index; @@ -1076,13 +1076,13 @@ int JackCoreAudioDriver::Start() printError(err); return -1; } - - return 0; + + return 0; } int JackCoreAudioDriver::Stop() { - JackLog("JackCoreAudioDriver::Stop\n"); + JackLog("JackCoreAudioDriver::Stop\n"); AudioDeviceStop(fDeviceID, MeasureCallback); AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); return (AudioOutputUnitStop(fAUHAL) == noErr) ? 0 : -1; @@ -1099,8 +1099,8 @@ int JackCoreAudioDriver::SetBufferSize(jack_nframes_t buffer_size) printError(err); return -1; } - - JackAudioDriver::SetBufferSize(buffer_size); // never fails + + JackAudioDriver::SetBufferSize(buffer_size); // never fails // Input buffers do no change : prepare them only once for (int i = 0; i < fCaptureChannels; i++) { diff --git a/macosx/JackCoreAudioDriver.h b/macosx/JackCoreAudioDriver.h index cdcc2727..e8cc55c1 100644 --- a/macosx/JackCoreAudioDriver.h +++ b/macosx/JackCoreAudioDriver.h @@ -39,7 +39,7 @@ typedef UInt8 CAAudioHardwareDeviceSectionID; /*! \brief The CoreAudio driver. - + \todo hardware monitoring */ @@ -47,8 +47,8 @@ class JackCoreAudioDriver : public JackAudioDriver { private: - - AudioUnit fAUHAL; + + AudioUnit fAUHAL; AudioBufferList* fJackInputData; AudioBufferList* fDriverOutputData; @@ -57,21 +57,21 @@ class JackCoreAudioDriver : public JackAudioDriver AudioUnitRenderActionFlags* fActionFags; AudioTimeStamp* fCurrentTime; - - bool fState; - - /// Intitial state - bool fCapturing; - bool fPlaying; - - int fInChannels; - int fOutChannels; - - char fCaptureUID[256]; - char fPlaybackUID[256]; - - bool fMonitor; - + + bool fState; + + /// Intitial state + bool fCapturing; + bool fPlaying; + + int fInChannels; + int fOutChannels; + + char fCaptureUID[256]; + char fPlaybackUID[256]; + + bool fMonitor; + static OSStatus Render(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, @@ -88,57 +88,57 @@ class JackCoreAudioDriver : public JackAudioDriver void* inClientData); static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice, - UInt32 inChannel, - Boolean isInput, - AudioDevicePropertyID inPropertyID, - void* inClientData); - - - static OSStatus SRNotificationCallback(AudioDeviceID inDevice, - UInt32 inChannel, - Boolean isInput, - AudioDevicePropertyID inPropertyID, - void* inClientData); - + UInt32 inChannel, + Boolean isInput, + AudioDevicePropertyID inPropertyID, + void* inClientData); + + + static OSStatus SRNotificationCallback(AudioDeviceID inDevice, + UInt32 inChannel, + Boolean isInput, + AudioDevicePropertyID inPropertyID, + void* inClientData); + OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id); OSStatus GetDefaultDevice(AudioDeviceID* id); OSStatus GetDefaultInputDevice(AudioDeviceID* id); OSStatus GetDefaultOutputDevice(AudioDeviceID* id); OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name); OSStatus GetTotalChannels(AudioDeviceID device, int* channelCount, bool isInput); - - // Setup - int SetupDevices(const char* capture_driver_uid, - const char* playback_driver_uid, - char* capture_driver_name, - char* playback_driver_name); - - int SetupChannels(bool capturing, - bool playing, - int& inchannels, - int& outchannels, - int& in_nChannels, - int& out_nChannels, - bool strict); - - int SetupBuffers(int inchannels, int outchannels); - void DisposeBuffers(); - - int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate); - - int OpenAUHAL(bool capturing, - bool playing, - int inchannels, - int outchannels, - int in_nChannels, - int out_nChannels, - jack_nframes_t nframes, - jack_nframes_t samplerate, - bool strict); - void CloseAUHAL(); - - int AddListeners(); - void RemoveListeners(); + + // Setup + int SetupDevices(const char* capture_driver_uid, + const char* playback_driver_uid, + char* capture_driver_name, + char* playback_driver_name); + + int SetupChannels(bool capturing, + bool playing, + int& inchannels, + int& outchannels, + int& in_nChannels, + int& out_nChannels, + bool strict); + + int SetupBuffers(int inchannels, int outchannels); + void DisposeBuffers(); + + int SetupBufferSizeAndSampleRate(jack_nframes_t nframes, jack_nframes_t samplerate); + + int OpenAUHAL(bool capturing, + bool playing, + int inchannels, + int outchannels, + int in_nChannels, + int out_nChannels, + jack_nframes_t nframes, + jack_nframes_t samplerate, + bool strict); + void CloseAUHAL(); + + int AddListeners(); + void RemoveListeners(); public: @@ -156,7 +156,7 @@ class JackCoreAudioDriver : public JackAudioDriver const char* playback_driver_name, jack_nframes_t capture_latency, jack_nframes_t playback_latency); - int Close(); + int Close(); int Attach(); diff --git a/macosx/JackMacEngineRPC.cpp b/macosx/JackMacEngineRPC.cpp index 83b5f4b2..45ca8c89 100644 --- a/macosx/JackMacEngineRPC.cpp +++ b/macosx/JackMacEngineRPC.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -64,7 +64,7 @@ rpc_type server_rpc_jack_client_activate(mach_port_t private_port, int refnum, i JackLog("rpc_jack_client_activate\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; assert(channel); - *result = channel->GetEngine()->ClientActivate(refnum); + *result = channel->GetEngine()->ClientActivate(refnum); return KERN_SUCCESS; } @@ -73,7 +73,7 @@ rpc_type server_rpc_jack_client_deactivate(mach_port_t private_port, int refnum, JackLog("rpc_jack_client_deactivate\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; assert(channel); - *result = channel->GetEngine()->ClientDeactivate(refnum); + *result = channel->GetEngine()->ClientDeactivate(refnum); return KERN_SUCCESS; } @@ -185,29 +185,29 @@ rpc_type server_rpc_jack_set_timebase_callback(mach_port_t private_port, int ref rpc_type server_rpc_jack_get_internal_clientname(mach_port_t private_port, int refnum, int int_ref, client_name_t name_res, int* result) { - JackLog("server_rpc_jack_get_internal_clientname\n"); + JackLog("server_rpc_jack_get_internal_clientname\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; assert(channel); - *result = channel->GetServer()->GetEngine()->GetInternalClientName(int_ref, (char*)name_res); - return KERN_SUCCESS; + *result = channel->GetServer()->GetEngine()->GetInternalClientName(int_ref, (char*)name_res); + return KERN_SUCCESS; } rpc_type server_rpc_jack_internal_clienthandle(mach_port_t private_port, int refnum, client_name_t client_name, int* status, int* int_ref, int* result) { - JackLog("server_rpc_jack_internal_clienthandle\n"); + JackLog("server_rpc_jack_internal_clienthandle\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; assert(channel); - *result = channel->GetServer()->GetEngine()->InternalClientHandle(client_name, status, int_ref); - return KERN_SUCCESS; + *result = channel->GetServer()->GetEngine()->InternalClientHandle(client_name, status, int_ref); + return KERN_SUCCESS; } rpc_type server_rpc_jack_internal_clientload(mach_port_t private_port, int refnum, client_name_t client_name, so_name_t so_name, objet_data_t objet_data, int options, int* status, int* int_ref, int* result) { - JackLog("server_rpc_jack_internal_clientload\n"); + JackLog("server_rpc_jack_internal_clientload\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; - assert(channel); - *result = channel->GetServer()->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, status); - return KERN_SUCCESS; + assert(channel); + *result = channel->GetServer()->InternalClientLoad(client_name, so_name, objet_data, options, int_ref, status); + return KERN_SUCCESS; } rpc_type server_rpc_jack_internal_clientunload(mach_port_t private_port, int refnum, int int_ref, int* status, int* result) @@ -215,8 +215,8 @@ rpc_type server_rpc_jack_internal_clientunload(mach_port_t private_port, int ref JackLog("server_rpc_jack_internal_clientunload\n"); JackMachServerChannel* channel = JackMachServerChannel::fPortTable[private_port]; assert(channel); - *result = channel->GetServer()->GetEngine()->InternalClientUnload(int_ref, status); - return KERN_SUCCESS; + *result = channel->GetServer()->GetEngine()->InternalClientUnload(int_ref, status); + return KERN_SUCCESS; } //----------------- diff --git a/macosx/JackMacLibClientRPC.cpp b/macosx/JackMacLibClientRPC.cpp index fea0c8ec..692d92cb 100644 --- a/macosx/JackMacLibClientRPC.cpp +++ b/macosx/JackMacLibClientRPC.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachClientChannel.cpp b/macosx/JackMachClientChannel.cpp index 6b52c14f..dde06a4a 100644 --- a/macosx/JackMachClientChannel.cpp +++ b/macosx/JackMachClientChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -43,41 +43,41 @@ JackMachClientChannel::~JackMachClientChannel() int JackMachClientChannel::ServerCheck(const char* server_name) { - JackLog("JackMachClientChannel::ServerCheck = %s\n", server_name); - char jack_server_entry_name[512]; - snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); - + JackLog("JackMachClientChannel::ServerCheck = %s\n", server_name); + char jack_server_entry_name[512]; + snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); + // Connect to server if (!fServerPort.ConnectPort(jack_server_entry_name)) { jack_error("Cannot connect to server Mach port"); return -1; } else { - return 0; - } + return 0; + } } int JackMachClientChannel::Open(const char* server_name, const char* name, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status) { JackLog("JackMachClientChannel::Open name = %s\n", name); - char jack_server_entry_name[512]; - snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); + char jack_server_entry_name[512]; + snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); // Connect to server if (!fServerPort.ConnectPort(jack_server_entry_name)) { jack_error("Cannot connect to server Mach port"); return -1; } - - // Check name in server - int result = 0; - ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); + + // Check name in server + int result = 0; + ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); if (result < 0) { - int status1 = *status; + int status1 = *status; if (status1 & JackVersionError) - jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); + jack_error("JACK protocol mismatch %d", JACK_PROTOCOL_VERSION); else - jack_error("Client name = %s conflits with another running client", name); - return -1; + jack_error("Client name = %s conflits with another running client", name); + return -1; } // Prepare local port using client name @@ -126,7 +126,7 @@ void JackMachClientChannel::Stop() void JackMachClientChannel::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) { - kern_return_t res = rpc_jack_client_check(fServerPort.GetPort(), (char*)name, name_res, protocol, options, status, result); + kern_return_t res = rpc_jack_client_check(fServerPort.GetPort(), (char*)name, name_res, protocol, options, status, result); if (res != KERN_SUCCESS) { *result = -1; jack_error("JackMachClientChannel::ClientCheck err = %s", mach_error_string(res)); @@ -171,7 +171,7 @@ void JackMachClientChannel::ClientDeactivate(int refnum, int* result) void JackMachClientChannel::PortRegister(int refnum, const char* name, const char* type, unsigned int flags, unsigned int buffer_size, unsigned int* port_index, int* result) { - kern_return_t res = rpc_jack_port_register(fPrivatePort, refnum, (char*)name, (char*)type, flags, buffer_size, port_index, result); + kern_return_t res = rpc_jack_port_register(fPrivatePort, refnum, (char*)name, (char*)type, flags, buffer_size, port_index, result); if (res != KERN_SUCCESS) { *result = -1; jack_error("JackMachClientChannel::PortRegister err = %s", mach_error_string(res)); diff --git a/macosx/JackMachClientChannel.h b/macosx/JackMachClientChannel.h index 5b377b64..3ff141de 100644 --- a/macosx/JackMachClientChannel.h +++ b/macosx/JackMachClientChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -53,11 +53,11 @@ class JackMachClientChannel : public JackClientChannelInterface, public JackRunn int Start(); void Stop(); - - int ServerCheck(const char* server_name); - + + int ServerCheck(const char* server_name); + void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result); - void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); + void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); void ClientClose(int refnum, int* result); void ClientActivate(int refnum, int* result); @@ -77,14 +77,14 @@ class JackMachClientChannel : public JackClientChannelInterface, public JackRunn void ReleaseTimebase(int refnum, int* result); void SetTimebaseCallback(int refnum, int conditional, int* result); - - void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); - void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result); - void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result); - void InternalClientUnload(int refnum, int int_ref, int* status, int* result); - - // JackRunnableInterface interface - bool Execute(); + + void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); + void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result); + void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result); + void InternalClientUnload(int refnum, int int_ref, int* status, int* result); + + // JackRunnableInterface interface + bool Execute(); }; diff --git a/macosx/JackMachNotifyChannel.cpp b/macosx/JackMachNotifyChannel.cpp index 4233b3f7..3dab40e2 100644 --- a/macosx/JackMachNotifyChannel.cpp +++ b/macosx/JackMachNotifyChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -56,9 +56,9 @@ void JackMachNotifyChannel::ClientNotify(int refnum, const char* name, int notif if (res == KERN_SUCCESS) { *result = 0; } else { - jack_error("JackMachNotifyChannel::ClientNotify: name = %s notify = %ld err = %s", name, notify, mach_error_string(res)); - *result = -1; - } + jack_error("JackMachNotifyChannel::ClientNotify: name = %s notify = %ld err = %s", name, notify, mach_error_string(res)); + *result = -1; + } } } // end of namespace diff --git a/macosx/JackMachNotifyChannel.h b/macosx/JackMachNotifyChannel.h index 1bcf3e33..1d2774c4 100644 --- a/macosx/JackMachNotifyChannel.h +++ b/macosx/JackMachNotifyChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachPort.cpp b/macosx/JackMachPort.cpp index 802ffbc1..9caad918 100644 --- a/macosx/JackMachPort.cpp +++ b/macosx/JackMachPort.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachPort.h b/macosx/JackMachPort.h index 048c8b0e..9d20339e 100644 --- a/macosx/JackMachPort.h +++ b/macosx/JackMachPort.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachSemaphore.cpp b/macosx/JackMachSemaphore.cpp index 98107c73..b2c6189a 100644 --- a/macosx/JackMachSemaphore.cpp +++ b/macosx/JackMachSemaphore.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -34,11 +34,11 @@ void JackMachSemaphore::BuildName(const char* name, const char* server_name, cha bool JackMachSemaphore::Signal() { kern_return_t res; - - if (!fSemaphore) { - jack_error("JackMachSemaphore::Signal name = %s already desallocated!!", fName); - return false; - } + + if (!fSemaphore) { + jack_error("JackMachSemaphore::Signal name = %s already desallocated!!", fName); + return false; + } if (fFlush) return true; @@ -52,11 +52,11 @@ bool JackMachSemaphore::Signal() bool JackMachSemaphore::SignalAll() { kern_return_t res; - + if (!fSemaphore) { - jack_error("JackMachSemaphore::SignalAll name = %s already desallocated!!", fName); - return false; - } + jack_error("JackMachSemaphore::SignalAll name = %s already desallocated!!", fName); + return false; + } if (fFlush) return true; @@ -70,12 +70,12 @@ bool JackMachSemaphore::SignalAll() bool JackMachSemaphore::Wait() { kern_return_t res; - + if (!fSemaphore) { - jack_error("JackMachSemaphore::Wait name = %s already desallocated!!", fName); - return false; - } - + jack_error("JackMachSemaphore::Wait name = %s already desallocated!!", fName); + return false; + } + if ((res = semaphore_wait(fSemaphore)) != KERN_SUCCESS) { jack_error("JackMachSemaphore::Wait name = %s err = %s", fName, mach_error_string(res)); } @@ -88,11 +88,11 @@ bool JackMachSemaphore::TimedWait(long usec) mach_timespec time; time.tv_sec = usec / 1000000; time.tv_nsec = (usec % 1000000) * 1000; - - if (!fSemaphore) { - jack_error("JackMachSemaphore::TimedWait name = %s already desallocated!!", fName); - return false; - } + + if (!fSemaphore) { + jack_error("JackMachSemaphore::TimedWait name = %s already desallocated!!", fName); + return false; + } if ((res = semaphore_timedwait(fSemaphore, time)) != KERN_SUCCESS) { jack_error("JackMachSemaphore::TimedWait name = %s usec = %ld err = %s", fName, usec, mach_error_string(res)); @@ -186,10 +186,10 @@ bool JackMachSemaphore::ConnectOutput(const char* name, const char* server_name) bool JackMachSemaphore::Disconnect() { - if (fSemaphore > 0) { - JackLog("JackMachSemaphore::Disconnect name = %s\n", fName); - fSemaphore = 0; - } + if (fSemaphore > 0) { + JackLog("JackMachSemaphore::Disconnect name = %s\n", fName); + fSemaphore = 0; + } // Nothing to do return true; } diff --git a/macosx/JackMachSemaphore.h b/macosx/JackMachSemaphore.h index 12397348..7d02ce7e 100644 --- a/macosx/JackMachSemaphore.h +++ b/macosx/JackMachSemaphore.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachServerChannel.cpp b/macosx/JackMachServerChannel.cpp index 36d1962f..cfa3630e 100644 --- a/macosx/JackMachServerChannel.cpp +++ b/macosx/JackMachServerChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -45,8 +45,8 @@ JackMachServerChannel::~JackMachServerChannel() int JackMachServerChannel::Open(const char* server_name, JackServer* server) { JackLog("JackMachServerChannel::Open\n"); - char jack_server_entry_name[512]; - snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); + char jack_server_entry_name[512]; + snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); if (!fServerPort.AllocatePort(jack_server_entry_name, 16)) { // 16 is the max possible value jack_error("Cannot check in Jack server"); @@ -82,13 +82,13 @@ JackServer* JackMachServerChannel::GetServer() void JackMachServerChannel::ClientCheck(char* name, char* name_res, int protocol, int options, int* status, int* result) { - *result = GetEngine()->ClientCheck(name, name_res, protocol, options, status); + *result = GetEngine()->ClientCheck(name, name_res, protocol, options, status); } void JackMachServerChannel::ClientOpen(char* name, mach_port_t* private_port, int* shared_engine, int* shared_client, int* shared_graph, int* result) { int refnum = -1; - *result = GetEngine()->ClientExternalOpen(name, &refnum, shared_engine, shared_client, shared_graph); + *result = GetEngine()->ClientExternalOpen(name, &refnum, shared_engine, shared_client, shared_graph); if (*result == 0) { mach_port_t port = fServerPort.AddPort(); @@ -107,7 +107,7 @@ void JackMachServerChannel::ClientOpen(char* name, mach_port_t* private_port, in void JackMachServerChannel::ClientClose(mach_port_t private_port, int refnum) { - GetEngine()->ClientExternalClose(refnum); + GetEngine()->ClientExternalClose(refnum); fClientTable.erase(private_port); // Hum, hum.... diff --git a/macosx/JackMachServerChannel.h b/macosx/JackMachServerChannel.h index ee9ab982..36066b0c 100644 --- a/macosx/JackMachServerChannel.h +++ b/macosx/JackMachServerChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -58,7 +58,7 @@ class JackMachServerChannel : public JackServerChannelInterface, public JackRunn JackEngine* GetEngine(); JackServer* GetServer(); - void ClientCheck(char* name, char* name_res, int protocol, int options, int* status, int* result); + void ClientCheck(char* name, char* name_res, int protocol, int options, int* status, int* result); void ClientOpen(char* name, mach_port_t* private_port, int* shared_engine, int* shared_client, int* shared_graph, int* result); void ClientClose(mach_port_t private_port, int refnum); void ClientKill(mach_port_t private_port); diff --git a/macosx/JackMachServerNotifyChannel.cpp b/macosx/JackMachServerNotifyChannel.cpp index 17b6c452..4bad5d99 100644 --- a/macosx/JackMachServerNotifyChannel.cpp +++ b/macosx/JackMachServerNotifyChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 @@ -28,8 +28,8 @@ namespace Jack int JackMachServerNotifyChannel::Open(const char* server_name) { JackLog("JackMachServerChannel::Open\n"); - char jack_server_entry_name[512]; - snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); + char jack_server_entry_name[512]; + snprintf(jack_server_entry_name, sizeof(jack_server_entry_name), "%s_%s", jack_server_entry, server_name); if (!fClientPort.ConnectPort(jack_server_entry_name)) { jack_error("Cannot connect to server port"); @@ -48,7 +48,7 @@ void JackMachServerNotifyChannel::ClientNotify(int refnum, int notify, int value { kern_return_t res = rpc_jack_client_rt_notify(fClientPort.GetPort(), refnum, notify, value, 0); if (res != KERN_SUCCESS) { - jack_error("Could not write request ref = %ld notify = %ld err = %s", refnum, notify, mach_error_string(res)); + jack_error("Could not write request ref = %ld notify = %ld err = %s", refnum, notify, mach_error_string(res)); } } diff --git a/macosx/JackMachServerNotifyChannel.h b/macosx/JackMachServerNotifyChannel.h index 5bdc0c74..d2ffe0cd 100644 --- a/macosx/JackMachServerNotifyChannel.h +++ b/macosx/JackMachServerNotifyChannel.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2008 Grame +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 diff --git a/macosx/JackMachThread.cpp b/macosx/JackMachThread.cpp index df782109..adceeda8 100644 --- a/macosx/JackMachThread.cpp +++ b/macosx/JackMachThread.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -157,17 +157,17 @@ int JackMachThread::AcquireRealTime() JackLog("JackMachThread::AcquireRealTime fPeriod = %ld fComputation = %ld fConstraint = %ld\n", long(fPeriod / 1000), long(fComputation / 1000), long(fConstraint / 1000)); - return (fThread) ? AcquireRealTimeImp(fThread, fPeriod, fComputation, fConstraint) : -1; + return (fThread) ? AcquireRealTimeImp(fThread, fPeriod, fComputation, fConstraint) : -1; } int JackMachThread::AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint) { - SetThreadToPriority(thread, 96, true, period, computation, constraint); - UInt64 int_period; - UInt64 int_computation; - UInt64 int_constraint; - GetParams(&int_period, &int_computation, &int_constraint); - return 0; + SetThreadToPriority(thread, 96, true, period, computation, constraint); + UInt64 int_period; + UInt64 int_computation; + UInt64 int_constraint; + GetParams(&int_period, &int_computation, &int_constraint); + return 0; } int JackMachThread::DropRealTime() @@ -177,8 +177,8 @@ int JackMachThread::DropRealTime() int JackMachThread::DropRealTimeImp(pthread_t thread) { - SetThreadToPriority(thread, 63, false, 0, 0, 0); - return 0; + SetThreadToPriority(thread, 63, false, 0, 0, 0); + return 0; } void JackMachThread::SetParams(UInt64 period, UInt64 computation, UInt64 constraint) diff --git a/macosx/JackMachThread.h b/macosx/JackMachThread.h index 8961262c..1cadbe52 100644 --- a/macosx/JackMachThread.h +++ b/macosx/JackMachThread.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2008 Grame This program is free software; you can redistribute it and/or modify @@ -20,13 +20,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. /* Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved. - + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. - + In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in this original Apple software (the "Apple Software"), to use, @@ -41,13 +41,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. - + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. - + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -114,9 +114,9 @@ class JackMachThread : public JackPosixThread void SetParams(UInt64 period, UInt64 computation, UInt64 constraint); static int GetParams(UInt64* period, UInt64* computation, UInt64* constraint); static int SetThreadToPriority(pthread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint); - - static int AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint); - static int DropRealTimeImp(pthread_t thread); + + static int AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint); + static int DropRealTimeImp(pthread_t thread); }; } // end of namespace diff --git a/windows/JackASIODriver.cpp b/windows/JackASIODriver.cpp index b31d27e6..7c145797 100644 --- a/windows/JackASIODriver.cpp +++ b/windows/JackASIODriver.cpp @@ -60,14 +60,13 @@ namespace Jack is returned the driver will already be closed. */ static PaError LoadAsioDriver( const char *driverName, - PaAsioDriverInfo *driverInfo, void *systemSpecific ) + PaAsioDriverInfo *driverInfo, void *systemSpecific ) { PaError result = paNoError; ASIOError asioError; int asioIsInitialized = 0; - if( !loadAsioDriver(const_cast<char*>(driverName))) - { + if ( !loadAsioDriver(const_cast<char*>(driverName))) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_HOST_ERROR( 0, "Failed to load ASIO driver" ); goto error; @@ -76,35 +75,30 @@ static PaError LoadAsioDriver( const char *driverName, memset( &driverInfo->asioDriverInfo, 0, sizeof(ASIODriverInfo) ); driverInfo->asioDriverInfo.asioVersion = 2; driverInfo->asioDriverInfo.sysRef = systemSpecific; - if( (asioError = ASIOInit( &driverInfo->asioDriverInfo )) != ASE_OK ) - { + if ( (asioError = ASIOInit( &driverInfo->asioDriverInfo )) != ASE_OK ) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); goto error; - } - else - { + } else { asioIsInitialized = 1; } - if( (asioError = ASIOGetChannels(&driverInfo->inputChannelCount, - &driverInfo->outputChannelCount)) != ASE_OK ) - { + if ( (asioError = ASIOGetChannels(&driverInfo->inputChannelCount, + &driverInfo->outputChannelCount)) != ASE_OK ) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); goto error; } - if( (asioError = ASIOGetBufferSize(&driverInfo->bufferMinSize, - &driverInfo->bufferMaxSize, &driverInfo->bufferPreferredSize, - &driverInfo->bufferGranularity)) != ASE_OK ) - { + if ( (asioError = ASIOGetBufferSize(&driverInfo->bufferMinSize, + &driverInfo->bufferMaxSize, &driverInfo->bufferPreferredSize, + &driverInfo->bufferGranularity)) != ASE_OK ) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); goto error; } - if( ASIOOutputReady() == ASE_OK ) + if ( ASIOOutputReady() == ASE_OK ) driverInfo->postOutput = true; else driverInfo->postOutput = false; @@ -112,7 +106,7 @@ static PaError LoadAsioDriver( const char *driverName, return result; error: - if( asioIsInitialized ) + if ( asioIsInitialized ) ASIOExit(); return result; @@ -122,8 +116,8 @@ error: int JackASIODriver::bufferSwitch(long index, ASIOBool directProcess) { JackASIODriver* driver = (JackASIODriver*)userData; - - // the actual processing callback. + + // the actual processing callback. // Beware that this is normally in a seperate thread, hence be sure that // you take care about thread synchronization. This is omitted here for // simplicity. @@ -137,23 +131,23 @@ int JackASIODriver::bufferSwitch(long index, ASIOBool directProcess) // get the time stamp of the buffer, not necessary if no // synchronization to other media is required - if( ASIOGetSamplePosition(&timeInfo.timeInfo.samplePosition, &timeInfo.timeInfo.systemTime) == ASE_OK) - timeInfo.timeInfo.flags = kSystemTimeValid | kSamplePositionValid; - - + if ( ASIOGetSamplePosition(&timeInfo.timeInfo.samplePosition, &timeInfo.timeInfo.systemTime) == ASE_OK) + timeInfo.timeInfo.flags = kSystemTimeValid | kSamplePositionValid; + + driver->fLastWaitUst = GetMicroSeconds(); // Take callback date here - driver->fInputBuffer = (float**)inputBuffer; - driver->fOutputBuffer = (float**)outputBuffer; - - // Call the real callback + driver->fInputBuffer = (float**)inputBuffer; + driver->fOutputBuffer = (float**)outputBuffer; + + // Call the real callback bufferSwitchTimeInfo( &timeInfo, index, directProcess ); - - return driver->Process(); + + return driver->Process(); } int JackASIODriver::Read() { - return 0; + return 0; } int JackASIODriver::Write() @@ -172,15 +166,13 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi PaAsioDriverInfo paAsioDriverInfo; asioHostApi = (PaAsioHostApiRepresentation*)PaUtil_AllocateMemory( sizeof(PaAsioHostApiRepresentation) ); - if( !asioHostApi ) - { + if ( !asioHostApi ) { result = paInsufficientMemory; goto error; } asioHostApi->allocations = PaUtil_CreateAllocationGroup(); - if( !asioHostApi->allocations ) - { + if ( !asioHostApi->allocations ) { result = paInsufficientMemory; goto error; } @@ -195,28 +187,26 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi (*hostApi)->info.name = "ASIO"; (*hostApi)->info.deviceCount = 0; - #ifdef WINDOWS - /* use desktop window as system specific ptr */ - asioHostApi->systemSpecific = GetDesktopWindow(); - CoInitialize(NULL); - #endif +#ifdef WINDOWS + /* use desktop window as system specific ptr */ + asioHostApi->systemSpecific = GetDesktopWindow(); + CoInitialize(NULL); +#endif /* MUST BE CHECKED : to force fragments loading on Mac */ - loadAsioDriver( "dummy" ); + loadAsioDriver( "dummy" ); /* driverCount is the number of installed drivers - not necessarily the number of installed physical devices. */ - #if MAC - driverCount = asioDrivers->getNumFragments(); - #elif WINDOWS - driverCount = asioDrivers->asioGetNumDev(); - #endif +#if MAC + driverCount = asioDrivers->getNumFragments(); +#elif WINDOWS + driverCount = asioDrivers->asioGetNumDev(); +#endif - if( driverCount > 0 ) - { + if ( driverCount > 0 ) { names = GetAsioDriverNames( asioHostApi->allocations, driverCount ); - if( !names ) - { + if ( !names ) { result = paInsufficientMemory; goto error; } @@ -225,38 +215,35 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi /* allocate enough space for all drivers, even if some aren't installed */ (*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( - asioHostApi->allocations, sizeof(PaDeviceInfo*) * driverCount ); - if( !(*hostApi)->deviceInfos ) - { + asioHostApi->allocations, sizeof(PaDeviceInfo*) * driverCount ); + if ( !(*hostApi)->deviceInfos ) { result = paInsufficientMemory; goto error; } /* allocate all device info structs in a contiguous block */ deviceInfoArray = (PaAsioDeviceInfo*)PaUtil_GroupAllocateMemory( - asioHostApi->allocations, sizeof(PaAsioDeviceInfo) * driverCount ); - if( !deviceInfoArray ) - { + asioHostApi->allocations, sizeof(PaAsioDeviceInfo) * driverCount ); + if ( !deviceInfoArray ) { result = paInsufficientMemory; goto error; } - for( i=0; i < driverCount; ++i ) - { + for ( i = 0; i < driverCount; ++i ) { - PA_DEBUG(("ASIO names[%d]:%s\n",i,names[i])); + PA_DEBUG(("ASIO names[%d]:%s\n", i, names[i])); // Since portaudio opens ALL ASIO drivers, and no one else does that, // we face fact that some drivers were not meant for it, drivers which act // like shells on top of REAL drivers, for instance. // so we get duplicate handles, locks and other problems. - // so lets NOT try to load any such wrappers. + // so lets NOT try to load any such wrappers. // The ones i [davidv] know of so far are: - if ( strcmp (names[i],"ASIO DirectX Full Duplex Driver") == 0 - || strcmp (names[i],"ASIO Multimedia Driver") == 0 - || strncmp(names[i],"Premiere",8) == 0 //"Premiere Elements Windows Sound 1.0" - || strncmp(names[i],"Adobe",5) == 0 ) //"Adobe Default Windows Sound 1.5" + if ( strcmp (names[i], "ASIO DirectX Full Duplex Driver") == 0 + || strcmp (names[i], "ASIO Multimedia Driver") == 0 + || strncmp(names[i], "Premiere", 8) == 0 //"Premiere Elements Windows Sound 1.0" + || strncmp(names[i], "Adobe", 5) == 0 ) //"Adobe Default Windows Sound 1.5" { PA_DEBUG(("BLACKLISTED!!!\n")); continue; @@ -264,8 +251,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi /* Attempt to load the asio driver... */ - if( LoadAsioDriver( names[i], &paAsioDriverInfo, asioHostApi->systemSpecific ) == paNoError ) - { + if ( LoadAsioDriver( names[i], &paAsioDriverInfo, asioHostApi->systemSpecific ) == paNoError ) { PaAsioDeviceInfo *asioDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ]; PaDeviceInfo *deviceInfo = &asioDeviceInfo->commonDeviceInfo; @@ -273,7 +259,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi deviceInfo->hostApi = hostApiIndex; deviceInfo->name = names[i]; - PA_DEBUG(("PaAsio_Initialize: drv:%d name = %s\n", i,deviceInfo->name)); + PA_DEBUG(("PaAsio_Initialize: drv:%d name = %s\n", i, deviceInfo->name)); PA_DEBUG(("PaAsio_Initialize: drv:%d inputChannels = %d\n", i, paAsioDriverInfo.inputChannelCount)); PA_DEBUG(("PaAsio_Initialize: drv:%d outputChannels = %d\n", i, paAsioDriverInfo.outputChannelCount)); PA_DEBUG(("PaAsio_Initialize: drv:%d bufferMinSize = %d\n", i, paAsioDriverInfo.bufferMinSize)); @@ -286,11 +272,9 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi deviceInfo->defaultSampleRate = 0.; bool foundDefaultSampleRate = false; - for( int j=0; j < PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_; ++j ) - { + for ( int j = 0; j < PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_; ++j ) { ASIOError asioError = ASIOCanSampleRate( defaultSampleRateSearchOrder_[j] ); - if( asioError != ASE_NoClock && asioError != ASE_NotPresent ) - { + if ( asioError != ASE_NoClock && asioError != ASE_NotPresent ) { deviceInfo->defaultSampleRate = defaultSampleRateSearchOrder_[j]; foundDefaultSampleRate = true; break; @@ -299,7 +283,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi PA_DEBUG(("PaAsio_Initialize: drv:%d defaultSampleRate = %f\n", i, deviceInfo->defaultSampleRate)); - if( foundDefaultSampleRate ){ + if ( foundDefaultSampleRate ) { /* calculate default latency values from bufferPreferredSize for default low latency, and bufferPreferredSize * 3 @@ -310,27 +294,27 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi */ double defaultLowLatency = - paAsioDriverInfo.bufferPreferredSize / deviceInfo->defaultSampleRate; + paAsioDriverInfo.bufferPreferredSize / deviceInfo->defaultSampleRate; deviceInfo->defaultLowInputLatency = defaultLowLatency; deviceInfo->defaultLowOutputLatency = defaultLowLatency; long defaultHighLatencyBufferSize = - paAsioDriverInfo.bufferPreferredSize * 3; + paAsioDriverInfo.bufferPreferredSize * 3; - if( defaultHighLatencyBufferSize > paAsioDriverInfo.bufferMaxSize ) + if ( defaultHighLatencyBufferSize > paAsioDriverInfo.bufferMaxSize ) defaultHighLatencyBufferSize = paAsioDriverInfo.bufferMaxSize; double defaultHighLatency = - defaultHighLatencyBufferSize / deviceInfo->defaultSampleRate; + defaultHighLatencyBufferSize / deviceInfo->defaultSampleRate; + + if ( defaultHighLatency < defaultLowLatency ) + defaultHighLatency = defaultLowLatency; /* just incase the driver returns something strange */ - if( defaultHighLatency < defaultLowLatency ) - defaultHighLatency = defaultLowLatency; /* just incase the driver returns something strange */ - deviceInfo->defaultHighInputLatency = defaultHighLatency; deviceInfo->defaultHighOutputLatency = defaultHighLatency; - - }else{ + + } else { deviceInfo->defaultLowInputLatency = 0.; deviceInfo->defaultLowOutputLatency = 0.; @@ -350,36 +334,33 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi asioDeviceInfo->asioChannelInfos = (ASIOChannelInfo*)PaUtil_GroupAllocateMemory( - asioHostApi->allocations, - sizeof(ASIOChannelInfo) * (deviceInfo->maxInputChannels - + deviceInfo->maxOutputChannels) ); - if( !asioDeviceInfo->asioChannelInfos ) - { + asioHostApi->allocations, + sizeof(ASIOChannelInfo) * (deviceInfo->maxInputChannels + + deviceInfo->maxOutputChannels) ); + if ( !asioDeviceInfo->asioChannelInfos ) { result = paInsufficientMemory; goto error; } int a; - for( a=0; a < deviceInfo->maxInputChannels; ++a ){ + for ( a = 0; a < deviceInfo->maxInputChannels; ++a ) { asioDeviceInfo->asioChannelInfos[a].channel = a; asioDeviceInfo->asioChannelInfos[a].isInput = ASIOTrue; ASIOError asioError = ASIOGetChannelInfo( &asioDeviceInfo->asioChannelInfos[a] ); - if( asioError != ASE_OK ) - { + if ( asioError != ASE_OK ) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); goto error; } } - for( a=0; a < deviceInfo->maxOutputChannels; ++a ){ + for ( a = 0; a < deviceInfo->maxOutputChannels; ++a ) { int b = deviceInfo->maxInputChannels + a; asioDeviceInfo->asioChannelInfos[b].channel = a; asioDeviceInfo->asioChannelInfos[b].isInput = ASIOFalse; ASIOError asioError = ASIOGetChannelInfo( &asioDeviceInfo->asioChannelInfos[b] ); - if( asioError != ASE_OK ) - { + if ( asioError != ASE_OK ) { result = paUnanticipatedHostError; PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); goto error; @@ -396,13 +377,10 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi } } - if( (*hostApi)->info.deviceCount > 0 ) - { + if ( (*hostApi)->info.deviceCount > 0 ) { (*hostApi)->info.defaultInputDevice = 0; (*hostApi)->info.defaultOutputDevice = 0; - } - else - { + } else { (*hostApi)->info.defaultInputDevice = paNoDevice; (*hostApi)->info.defaultOutputDevice = paNoDevice; } @@ -426,10 +404,8 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi return result; error: - if( asioHostApi ) - { - if( asioHostApi->allocations ) - { + if ( asioHostApi ) { + if ( asioHostApi->allocations ) { PaUtil_FreeAllAllocations( asioHostApi->allocations ); PaUtil_DestroyAllocationGroup( asioHostApi->allocations ); } @@ -450,7 +426,7 @@ void JackASIODriverTerminate( struct PaUtilHostApiRepresentation *hostApi ) - clean up any resources not handled by the allocation group */ - if( asioHostApi->allocations ) + if ( asioHostApi->allocations ) { PaUtil_FreeAllAllocations( asioHostApi->allocations ); PaUtil_DestroyAllocationGroup( asioHostApi->allocations ); @@ -461,71 +437,71 @@ void JackASIODriverTerminate( struct PaUtilHostApiRepresentation *hostApi ) int JackASIODriver::Open(jack_nframes_t nframes, - jack_nframes_t samplerate, - int capturing, - int playing, - int inchannels, - int outchannels, - bool monitor, - const char* capture_driver_uid, - const char* playback_driver_uid, - 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_uid, + const char* playback_driver_uid, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency) { - return 0; + return 0; error: - return -1; + return -1; } int JackASIODriver::Close() { - return 0; + return 0; } int JackASIODriver::Start() { JackLog("JackASIODriver::Start\n"); - return 0; + return 0; } int JackASIODriver::Stop() { - JackLog("JackASIODriver::Stop\n"); + JackLog("JackASIODriver::Stop\n"); return 0; } int JackASIODriver::SetBufferSize(jack_nframes_t nframes) { - return 0; + return 0; } void JackASIODriver::PrintState() { - int i; + int i; std::cout << "JackASIODriver state" << std::endl; jack_port_id_t port_index; std::cout << "Input ports" << std::endl; - /* - for (i = 0; i < fPlaybackChannels; i++) { - port_index = fCapturePortList[i]; - JackPort* port = fGraphManager->GetPort(port_index); - std::cout << port->GetName() << std::endl; - if (fGraphManager->GetConnectionsNum(port_index)) {} - } - - std::cout << "Output ports" << std::endl; - - for (i = 0; i < fCaptureChannels; i++) { - port_index = fPlaybackPortList[i]; - JackPort* port = fGraphManager->GetPort(port_index); - std::cout << port->GetName() << std::endl; - if (fGraphManager->GetConnectionsNum(port_index)) {} - } - */ + /* + for (i = 0; i < fPlaybackChannels; i++) { + port_index = fCapturePortList[i]; + JackPort* port = fGraphManager->GetPort(port_index); + std::cout << port->GetName() << std::endl; + if (fGraphManager->GetConnectionsNum(port_index)) {} + } + + std::cout << "Output ports" << std::endl; + + for (i = 0; i < fCaptureChannels; i++) { + port_index = fPlaybackPortList[i]; + JackPort* port = fGraphManager->GetPort(port_index); + std::cout << port->GetName() << std::endl; + if (fGraphManager->GetConnectionsNum(port_index)) {} + } + */ } } // end of namespace @@ -586,8 +562,8 @@ extern "C" strcpy(desc->params[i].value.str, "will take default PortAudio output device"); strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set PortAudio device name"); strcpy(desc->params[i].long_desc, desc->params[i].short_desc); - - i++; + + i++; strcpy (desc->params[i].name, "monitor"); desc->params[i].character = 'm'; desc->params[i].type = JackDriverParamBool; @@ -624,7 +600,7 @@ extern "C" desc->params[i].character = 'd'; desc->params[i].type = JackDriverParamString; desc->params[i].value.ui = 128U; - strcpy(desc->params[i].value.str, "will take default CoreAudio device name"); + strcpy(desc->params[i].value.str, "will take default CoreAudio device name"); strcpy(desc->params[i].short_desc, "CoreAudio device name"); strcpy(desc->params[i].long_desc, desc->params[i].short_desc); @@ -643,42 +619,41 @@ extern "C" desc->params[i].value.i = 0; strcpy(desc->params[i].short_desc, "Extra output latency"); strcpy(desc->params[i].long_desc, desc->params[i].short_desc); - - i++; - strcpy(desc->params[i].name, "list-devices"); - desc->params[i].character = 'l'; - desc->params[i].type = JackDriverParamBool; - desc->params[i].value.i = TRUE; - strcpy(desc->params[i].short_desc, "Display available CoreAudio devices"); - strcpy(desc->params[i].long_desc, desc->params[i].short_desc); + + i++; + strcpy(desc->params[i].name, "list-devices"); + desc->params[i].character = 'l'; + desc->params[i].type = JackDriverParamBool; + desc->params[i].value.i = TRUE; + strcpy(desc->params[i].short_desc, "Display available CoreAudio devices"); + strcpy(desc->params[i].long_desc, desc->params[i].short_desc); return desc; } - EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params) - { + EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngine* engine, Jack::JackSynchro** table, const JSList* params) { jack_nframes_t srate = 44100; jack_nframes_t frames_per_interrupt = 512; int capture = FALSE; int playback = FALSE; int chan_in = 0; int chan_out = 0; - bool monitor = false; - char* capture_pcm_name = ""; - char* playback_pcm_name = ""; + bool monitor = false; + char* capture_pcm_name = ""; + char* playback_pcm_name = ""; const JSList *node; const jack_driver_param_t *param; jack_nframes_t systemic_input_latency = 0; jack_nframes_t systemic_output_latency = 0; - for (node = params; node; node = jack_slist_next(node)) { + for (node = params; node; node = jack_slist_next(node)) { param = (const jack_driver_param_t *) node->data; switch (param->character) { case 'd': capture_pcm_name = strdup(param->value.str); - playback_pcm_name = strdup(param->value.str); + playback_pcm_name = strdup(param->value.str); break; case 'D': @@ -699,20 +674,20 @@ extern "C" break; case 'C': - capture = TRUE; - if (strcmp(param->value.str, "none") != 0) { + capture = TRUE; + if (strcmp(param->value.str, "none") != 0) { capture_pcm_name = strdup(param->value.str); } break; case 'P': - playback = TRUE; - if (strcmp(param->value.str, "none") != 0) { + playback = TRUE; + if (strcmp(param->value.str, "none") != 0) { playback_pcm_name = strdup(param->value.str); } break; - - case 'm': + + case 'm': monitor = param->value.i; break; @@ -731,22 +706,22 @@ extern "C" case 'O': systemic_output_latency = param->value.ui; break; - - case 'l': - Jack::DisplayDeviceNames(); - break; + + case 'l': + Jack::DisplayDeviceNames(); + break; } } - // duplex is the default + // duplex is the default if (!capture && !playback) { capture = TRUE; playback = TRUE; } Jack::JackDriverClientInterface* driver = new Jack::JackASIODriver("ASIO", engine, table); - if (driver->Open(frames_per_interrupt, srate, capture, playback, chan_in, chan_out, monitor, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency) == 0) { - return driver; + if (driver->Open(frames_per_interrupt, srate, capture, playback, chan_in, chan_out, monitor, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency) == 0) { + return driver; } else { delete driver; return NULL; diff --git a/windows/JackASIODriver.h b/windows/JackASIODriver.h index 794971a9..9bd3a180 100644 --- a/windows/JackASIODriver.h +++ b/windows/JackASIODriver.h @@ -40,27 +40,27 @@ class JackASIODriver : public JackAudioDriver private: - PaStream* fStream; - float** fInputBuffer; - float** fOutputBuffer; - PaDeviceIndex fInputDevice; - PaDeviceIndex fOutputDevice; - - static int Render(const void* inputBuffer, void* outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void* userData); + PaStream* fStream; + float** fInputBuffer; + float** fOutputBuffer; + PaDeviceIndex fInputDevice; + PaDeviceIndex fOutputDevice; + + static int Render(const void* inputBuffer, void* outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void* userData); public: JackASIODriver(const char* name, JackEngine* engine, JackSynchro** table) - : JackAudioDriver(name, engine, table), fStream(NULL), fInputBuffer(NULL), fOutputBuffer(NULL), - fInputDevice(paNoDevice), fOutputDevice(paNoDevice) - {} + : JackAudioDriver(name, engine, table), fStream(NULL), fInputBuffer(NULL), fOutputBuffer(NULL), + fInputDevice(paNoDevice), fOutputDevice(paNoDevice) + {} virtual ~JackASIODriver() - {} + {} int Open(jack_nframes_t frames_per_cycle, jack_nframes_t rate, @@ -68,11 +68,11 @@ class JackASIODriver : public JackAudioDriver int playing, int chan_in, int chan_out, - bool monitor, + bool monitor, const char* capture_driver_name, - const char* playback_driver_name, - jack_nframes_t capture_latency, - jack_nframes_t playback_latency); + const char* playback_driver_name, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency); int Close(); diff --git a/windows/JackPortAudioDriver.cpp b/windows/JackPortAudioDriver.cpp index aac9ec12..c44d3b5c 100644 --- a/windows/JackPortAudioDriver.cpp +++ b/windows/JackPortAudioDriver.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -77,7 +77,7 @@ bool JackPortAudioDriver::GetInputDeviceFromName(const char* name, PaDeviceIndex *in_max = deviceInfo->maxInputChannels; return true; } - } + } return false; } @@ -155,7 +155,7 @@ static void DisplayDeviceNames() */ #ifdef WIN32 -#ifndef PA_NO_ASIO +#ifndef PA_NO_ASIO /* ASIO specific latency information */ if (Pa_GetHostApiInfo(deviceInfo->hostApi)->type == paASIO) { long minLatency, maxLatency, preferredLatency, granularity; @@ -278,10 +278,10 @@ int JackPortAudioDriver::Open(jack_nframes_t nframes, if (capturing) { if (!GetInputDeviceFromName(capture_driver_uid, &fInputDevice, &in_max)) { - JackLog("JackPortAudioDriver::GetInputDeviceFromName cannot open %s\n", capture_driver_uid); + JackLog("JackPortAudioDriver::GetInputDeviceFromName cannot open %s\n", capture_driver_uid); fInputDevice = Pa_GetDefaultInputDevice(); - if (fInputDevice == paNoDevice) - goto error; + if (fInputDevice == paNoDevice) + goto error; deviceInfo = Pa_GetDeviceInfo(fInputDevice); in_max = deviceInfo->maxInputChannels; capture_driver_uid = strdup(deviceInfo->name); @@ -296,9 +296,9 @@ int JackPortAudioDriver::Open(jack_nframes_t nframes, if (playing) { if (!GetOutputDeviceFromName(playback_driver_uid, &fOutputDevice, &out_max)) { JackLog("JackPortAudioDriver::GetOutputDeviceFromName cannot open %s\n", playback_driver_uid); - fOutputDevice = Pa_GetDefaultOutputDevice(); - if (fOutputDevice == paNoDevice) - goto error; + fOutputDevice = Pa_GetDefaultOutputDevice(); + if (fOutputDevice == paNoDevice) + goto error; deviceInfo = Pa_GetDeviceInfo(fOutputDevice); out_max = deviceInfo->maxOutputChannels; playback_driver_uid = strdup(deviceInfo->name); @@ -375,7 +375,7 @@ error: int JackPortAudioDriver::Close() { JackAudioDriver::Close(); - JackLog("JackPortAudioDriver::Close\n"); + JackLog("JackPortAudioDriver::Close\n"); Pa_CloseStream(fStream); Pa_Terminate(); return 0; @@ -431,14 +431,14 @@ int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size) paNoFlag, // Clipping is on... Render, this); - + if (err != paNoError) { jack_error("Pa_OpenStream error = %s\n", Pa_GetErrorText(err)); return -1; } else { // Only done when success - return JackAudioDriver::SetBufferSize(buffer_size); // never fails - } + return JackAudioDriver::SetBufferSize(buffer_size); // never fails + } } } // end of namespace diff --git a/windows/JackWinEvent.cpp b/windows/JackWinEvent.cpp index 34c8bc4b..cbf04ca0 100644 --- a/windows/JackWinEvent.cpp +++ b/windows/JackWinEvent.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2005 Grame +Copyright (C) 2004-2005 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 @@ -38,11 +38,11 @@ bool JackWinEvent::Signal() if (fFlush) return true; - + if (!(res = SetEvent(fEvent))) { jack_error("JackWinEvent::Signal name = %s err = %ld", fName, GetLastError()); } - + return res; } @@ -57,7 +57,7 @@ bool JackWinEvent::SignalAll() if (!(res = SetEvent(fEvent))) { jack_error("JackWinEvent::SignalAll name = %s err = %ld", fName, GetLastError()); } - + return res; } @@ -77,7 +77,7 @@ bool JackWinEvent::TimedWait(long usec) DWORD res; if ((res = WaitForSingleObject(fEvent, usec / 1000)) == WAIT_TIMEOUT) { - jack_error("JackWinEvent::TimedWait name = %s time_out", fName); + jack_error("JackWinEvent::TimedWait name = %s time_out", fName); } return (res == WAIT_OBJECT_0); @@ -96,7 +96,7 @@ bool JackWinEvent::ConnectInput(const char* name, const char* server_name) } if ((fEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, fName)) == NULL) { - jack_error("Connect: can't check in named event name = %s err = %ld", fName, GetLastError()); + jack_error("Connect: can't check in named event name = %s err = %ld", fName, GetLastError()); return false; } else { return true; @@ -134,20 +134,20 @@ bool JackWinEvent::Allocate(const char* name, const char* server_name, int value if ((fEvent = CreateEvent(NULL, FALSE, FALSE, fName)) == NULL) { jack_error("Allocate: can't check in named event name = %s err = %ld", fName, GetLastError()); return false; - } else if (GetLastError() == ERROR_ALREADY_EXISTS) {
- jack_error("Allocate: named event already exist name = %s", fName);
- CloseHandle(fEvent);
- fEvent = NULL;
- return false;
- } else { - return true; + } else if (GetLastError() == ERROR_ALREADY_EXISTS) { + jack_error("Allocate: named event already exist name = %s", fName); + CloseHandle(fEvent); + fEvent = NULL; + return false; + } else { + return true; } } void JackWinEvent::Destroy() { if (fEvent != NULL) { - JackLog("JackWinEvent::Destroy %s\n", fName); + JackLog("JackWinEvent::Destroy %s\n", fName); CloseHandle(fEvent); fEvent = NULL; } else { diff --git a/windows/JackWinEvent.h b/windows/JackWinEvent.h index d29e08b4..f2cfd97e 100644 --- a/windows/JackWinEvent.h +++ b/windows/JackWinEvent.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2005 Grame +Copyright (C) 2004-2005 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 diff --git a/windows/JackWinNamedPipe.cpp b/windows/JackWinNamedPipe.cpp index de6afdd9..69d012eb 100755 --- a/windows/JackWinNamedPipe.cpp +++ b/windows/JackWinNamedPipe.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 @@ -52,7 +52,7 @@ int JackWinNamedPipe::Write(void* data, int len) int JackWinNamedPipeClient::Connect(const char* dir, int which) { - sprintf(fName, "\\\\.\\pipe\\%s_jack_%d", dir, which);
+ sprintf(fName, "\\\\.\\pipe\\%s_jack_%d", dir, which); JackLog("Connect: fName %s\n", fName); fNamedPipe = CreateFile(fName, // pipe name @@ -74,7 +74,7 @@ int JackWinNamedPipeClient::Connect(const char* dir, int which) int JackWinNamedPipeClient::Connect(const char* dir, const char* name, int which) { - sprintf(fName, "\\\\.\\pipe\\%s_jack_%s_%d", dir, name, which);
+ sprintf(fName, "\\\\.\\pipe\\%s_jack_%s_%d", dir, name, which); JackLog("Connect: fName %s\n", fName); fNamedPipe = CreateFile(fName, // pipe name @@ -96,13 +96,13 @@ int JackWinNamedPipeClient::Connect(const char* dir, const char* name, int which int JackWinNamedPipeClient::Close() { - if (fNamedPipe != INVALID_HANDLE_VALUE) { - CloseHandle(fNamedPipe); - fNamedPipe = INVALID_HANDLE_VALUE; - return 0; - } else { - return -1; - } + if (fNamedPipe != INVALID_HANDLE_VALUE) { + CloseHandle(fNamedPipe); + fNamedPipe = INVALID_HANDLE_VALUE; + return 0; + } else { + return -1; + } } void JackWinNamedPipeClient::SetReadTimeOut(long sec) @@ -221,8 +221,8 @@ int JackWinAsyncNamedPipeClient::Write(void* data, int len) int JackWinNamedPipeServer::Bind(const char* dir, int which) { - sprintf(fName, "\\\\.\\pipe\\%s_jack_%d", dir, which);
- JackLog("Bind: fName %s\n", fName);
+ sprintf(fName, "\\\\.\\pipe\\%s_jack_%d", dir, which); + JackLog("Bind: fName %s\n", fName); if ((fNamedPipe = CreateNamedPipe(fName, PIPE_ACCESS_DUPLEX, // read/write access @@ -243,8 +243,8 @@ int JackWinNamedPipeServer::Bind(const char* dir, int which) int JackWinNamedPipeServer::Bind(const char* dir, const char* name, int which) { - sprintf(fName, "\\\\.\\pipe\\%s_jack_%s_%d", dir, name, which);
- JackLog("Bind: fName %s\n", fName);
+ sprintf(fName, "\\\\.\\pipe\\%s_jack_%s_%d", dir, name, which); + JackLog("Bind: fName %s\n", fName); if ((fNamedPipe = CreateNamedPipe(fName, PIPE_ACCESS_DUPLEX, // read/write access @@ -281,10 +281,10 @@ bool JackWinNamedPipeServer::Accept() JackWinNamedPipeClient* JackWinNamedPipeServer::AcceptClient() { if (ConnectNamedPipe(fNamedPipe, NULL)) { - JackWinNamedPipeClient* client = new JackWinNamedPipeClient(fNamedPipe); - // Init the pipe to the default value - fNamedPipe = INVALID_HANDLE_VALUE;
- return client; + JackWinNamedPipeClient* client = new JackWinNamedPipeClient(fNamedPipe); + // Init the pipe to the default value + fNamedPipe = INVALID_HANDLE_VALUE; + return client; } else { switch (GetLastError()) { @@ -301,16 +301,16 @@ JackWinNamedPipeClient* JackWinNamedPipeServer::AcceptClient() int JackWinNamedPipeServer::Close() { - JackLog("JackWinNamedPipeServer::Close\n"); - - if (fNamedPipe != INVALID_HANDLE_VALUE) { - DisconnectNamedPipe(fNamedPipe); - CloseHandle(fNamedPipe); - fNamedPipe = INVALID_HANDLE_VALUE; - return 0; - } else { - return -1; - } + JackLog("JackWinNamedPipeServer::Close\n"); + + if (fNamedPipe != INVALID_HANDLE_VALUE) { + DisconnectNamedPipe(fNamedPipe); + CloseHandle(fNamedPipe); + fNamedPipe = INVALID_HANDLE_VALUE; + return 0; + } else { + return -1; + } } // Server side diff --git a/windows/JackWinNamedPipe.h b/windows/JackWinNamedPipe.h index f0a0a38e..20d7eebc 100755 --- a/windows/JackWinNamedPipe.h +++ b/windows/JackWinNamedPipe.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 diff --git a/windows/JackWinNamedPipeClientChannel.cpp b/windows/JackWinNamedPipeClientChannel.cpp index bbc4d42d..c32c4031 100644 --- a/windows/JackWinNamedPipeClientChannel.cpp +++ b/windows/JackWinNamedPipeClientChannel.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -38,47 +38,47 @@ JackWinNamedPipeClientChannel::~JackWinNamedPipeClientChannel() int JackWinNamedPipeClientChannel::ServerCheck(const char* server_name) { - JackLog("JackWinNamedPipeClientChannel::ServerCheck = %s\n", server_name); - - // Connect to server + JackLog("JackWinNamedPipeClientChannel::ServerCheck = %s\n", server_name); + + // Connect to server if (fRequestPipe.Connect(jack_server_dir, server_name, 0) < 0) { jack_error("Cannot connect to server pipe"); return -1; } else { - return 0; - } + return 0; + } } int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* name, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) { - int result = 0; + int result = 0; JackLog("JackWinNamedPipeClientChannel::Open name = %s\n", name); - /* - 16/08/07: was called before doing "fRequestPipe.Connect" .... still necessary? - if (fNotificationListenPipe.Bind(jack_client_dir, name, 0) < 0) { - jack_error("Cannot bind pipe"); - goto error; - } - */ - + /* + 16/08/07: was called before doing "fRequestPipe.Connect" .... still necessary? + if (fNotificationListenPipe.Bind(jack_client_dir, name, 0) < 0) { + jack_error("Cannot bind pipe"); + goto error; + } + */ + if (fRequestPipe.Connect(jack_server_dir, server_name, 0) < 0) { jack_error("Cannot connect to server pipe"); goto error; } - // Check name in server - ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); + // Check name in server + ClientCheck(name, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result); if (result < 0) { jack_error("Client name = %s conflits with another running client", name); - goto error; + goto error; } - - if (fNotificationListenPipe.Bind(jack_client_dir, name_res, 0) < 0) { + + if (fNotificationListenPipe.Bind(jack_client_dir, name_res, 0) < 0) { jack_error("Cannot bind pipe"); goto error; } - + fClient = obj; return 0; @@ -93,20 +93,20 @@ void JackWinNamedPipeClientChannel::Close() { fRequestPipe.Close(); fNotificationListenPipe.Close(); - // Here the thread will correctly stop when the pipe are closed - fThread->Stop(); + // Here the thread will correctly stop when the pipe are closed + fThread->Stop(); } int JackWinNamedPipeClientChannel::Start() { JackLog("JackWinNamedPipeClientChannel::Start\n"); - + if (fThread->Start() != 0) { jack_error("Cannot start Jack client listener"); return -1; } else { return 0; - } + } } void JackWinNamedPipeClientChannel::Stop() @@ -144,11 +144,11 @@ void JackWinNamedPipeClientChannel::ServerAsyncCall(JackRequest* req, JackResult void JackWinNamedPipeClientChannel::ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result) { - JackClientCheckRequest req(name, protocol, options); + JackClientCheckRequest req(name, protocol, options); JackClientCheckResult res; ServerSyncCall(&req, &res, result); - *status = res.fStatus; - strcpy(name_res, res.fName); + *status = res.fStatus; + strcpy(name_res, res.fName); } void JackWinNamedPipeClientChannel::ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result) @@ -258,7 +258,7 @@ void JackWinNamedPipeClientChannel::GetInternalClientName(int refnum, int int_re JackGetInternalClientNameRequest req(refnum, int_ref); JackGetInternalClientNameResult res; ServerSyncCall(&req, &res, result); - strcpy(name_res, res.fName); + strcpy(name_res, res.fName); } void JackWinNamedPipeClientChannel::InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result) @@ -266,8 +266,8 @@ void JackWinNamedPipeClientChannel::InternalClientHandle(int refnum, const char* JackInternalClientHandleRequest req(refnum, client_name); JackInternalClientHandleResult res; ServerSyncCall(&req, &res, result); - *int_ref = res.fIntRefNum; - *status = res.fStatus; + *int_ref = res.fIntRefNum; + *status = res.fStatus; } void JackWinNamedPipeClientChannel::InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result) @@ -275,8 +275,8 @@ void JackWinNamedPipeClientChannel::InternalClientLoad(int refnum, const char* c JackInternalClientLoadRequest req(refnum, client_name, so_name, objet_data, options); JackInternalClientLoadResult res; ServerSyncCall(&req, &res, result); - *int_ref = res.fIntRefNum; - *status = res.fStatus; + *int_ref = res.fIntRefNum; + *status = res.fStatus; } void JackWinNamedPipeClientChannel::InternalClientUnload(int refnum, int int_ref, int* status, int* result) @@ -284,7 +284,7 @@ void JackWinNamedPipeClientChannel::InternalClientUnload(int refnum, int int_ref JackInternalClientUnloadRequest req(refnum, int_ref); JackInternalClientUnloadResult res; ServerSyncCall(&req, &res, result); - *status = res.fStatus; + *status = res.fStatus; } bool JackWinNamedPipeClientChannel::Init() @@ -295,7 +295,7 @@ bool JackWinNamedPipeClientChannel::Init() jack_error("JackWinNamedPipeClientChannel: cannot establish notification pipe"); return false; } else { - return true; + return true; } } diff --git a/windows/JackWinNamedPipeClientChannel.h b/windows/JackWinNamedPipeClientChannel.h index 4e01f341..c14fc1db 100644 --- a/windows/JackWinNamedPipeClientChannel.h +++ b/windows/JackWinNamedPipeClientChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -55,11 +55,11 @@ class JackWinNamedPipeClientChannel : public JackClientChannelInterface, public int Start(); void Stop(); - - int ServerCheck(const char* server_name); + + int ServerCheck(const char* server_name); void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result); - void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); + void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result); void ClientClose(int refnum, int* result); void ClientActivate(int refnum, int* result); @@ -80,11 +80,11 @@ class JackWinNamedPipeClientChannel : public JackClientChannelInterface, public void ReleaseTimebase(int refnum, int* result); void SetTimebaseCallback(int refnum, int conditional, int* result); - void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); + void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result); void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result); - virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result); - virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result); - + virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result); + virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result); + // JackRunnableInterface interface bool Init(); bool Execute(); diff --git a/windows/JackWinNamedPipeNotifyChannel.cpp b/windows/JackWinNamedPipeNotifyChannel.cpp index 07de3c67..5174d355 100644 --- a/windows/JackWinNamedPipeNotifyChannel.cpp +++ b/windows/JackWinNamedPipeNotifyChannel.cpp @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -54,7 +54,7 @@ void JackWinNamedPipeNotifyChannel::ClientNotify(int refnum, const char* name, i // Send notification if (event.Write(&fNotifyPipe) < 0) { jack_error("Could not write notification"); - fNotifyPipe.Close(); + fNotifyPipe.Close(); *result = -1; return; } @@ -64,7 +64,7 @@ void JackWinNamedPipeNotifyChannel::ClientNotify(int refnum, const char* name, i // Get result : use a time out if (res.Read(&fNotifyPipe) < 0) { jack_error("Could not read result"); - fNotifyPipe.Close(); + fNotifyPipe.Close(); *result = -1; } else { *result = res.fResult; diff --git a/windows/JackWinNamedPipeNotifyChannel.h b/windows/JackWinNamedPipeNotifyChannel.h index fbc5fe5c..2d580d71 100644 --- a/windows/JackWinNamedPipeNotifyChannel.h +++ b/windows/JackWinNamedPipeNotifyChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/windows/JackWinNamedPipeServerChannel.cpp b/windows/JackWinNamedPipeServerChannel.cpp index e8511473..dd519c6f 100644 --- a/windows/JackWinNamedPipeServerChannel.cpp +++ b/windows/JackWinNamedPipeServerChannel.cpp @@ -1,23 +1,23 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ -#ifdef WIN32 +#ifdef WIN32 #pragma warning (disable : 4786) #endif @@ -49,7 +49,7 @@ JackClientPipeThread::JackClientPipeThread(JackWinNamedPipeClient* pipe) JackClientPipeThread::~JackClientPipeThread() { - JackLog("JackClientPipeThread::~JackClientPipeThread\n"); + JackLog("JackClientPipeThread::~JackClientPipeThread\n"); delete fPipe; delete fThread; } @@ -69,249 +69,249 @@ int JackClientPipeThread::Open(JackServer* server) // Open the Server/Client con void JackClientPipeThread::Close() // Close the Server/Client connection { - JackLog("JackClientPipeThread::Close %x %ld\n", this, fRefNum); - /* - TODO : solve WIN32 thread Kill issue - This would hang.. since Close will be followed by a delete, - all ressources will be desallocated at the end. - */ - - fThread->Kill(); - fPipe->Close(); - fRefNum = -1; + JackLog("JackClientPipeThread::Close %x %ld\n", this, fRefNum); + /* + TODO : solve WIN32 thread Kill issue + This would hang.. since Close will be followed by a delete, + all ressources will be desallocated at the end. + */ + + fThread->Kill(); + fPipe->Close(); + fRefNum = -1; } bool JackClientPipeThread::Execute() { JackLog("JackClientPipeThread::Execute\n"); - return (HandleRequest() == 0); + return (HandleRequest() == 0); } int JackClientPipeThread::HandleRequest() { // Read header JackRequest header; - int res = header.Read(fPipe); - int ret = 0; + int res = header.Read(fPipe); + int ret = 0; // Lock the global mutex if (WaitForSingleObject(fMutex, INFINITE) == WAIT_FAILED) jack_error("JackClientPipeThread::HandleRequest: mutex wait error"); - if (res < 0) { - jack_error("HandleRequest: cannot read header"); - ClientKill(); - ret = -1; - } else { - - // Read data - switch (header.fType) { - - case JackRequest::kClientCheck: { - JackLog("JackRequest::kClientCheck\n"); - JackClientCheckRequest req; - JackClientCheckResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->ClientCheck(req.fName, res.fName, req.fProtocol, req.fOptions, &res.fStatus); - res.Write(fPipe); - break; - } - - case JackRequest::kClientOpen: { - JackLog("JackRequest::ClientOpen\n"); - JackClientOpenRequest req; - JackClientOpenResult res; - if (req.Read(fPipe) == 0) - ClientAdd(req.fName, &res.fSharedEngine, &res.fSharedClient, &res.fSharedGraph, &res.fResult); - res.Write(fPipe); - break; - } - - case JackRequest::kClientClose: { - JackLog("JackRequest::ClientClose\n"); - JackClientCloseRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->ClientExternalClose(req.fRefNum); - // No write: client is actually doing an "ServerAsyncCall", and not interested by the result - ClientRemove(); - ret = -1; - break; - } - - case JackRequest::kActivateClient: { - JackActivateRequest req; - JackResult res; - JackLog("JackRequest::ActivateClient\n"); - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->ClientActivate(req.fRefNum); - res.Write(fPipe); - break; - } - - case JackRequest::kDeactivateClient: { - JackLog("JackRequest::DeactivateClient\n"); - JackDeactivateRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->ClientDeactivate(req.fRefNum); - res.Write(fPipe); - break; - } - - case JackRequest::kRegisterPort: { - JackLog("JackRequest::RegisterPort\n"); - JackPortRegisterRequest req; - JackPortRegisterResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortRegister(req.fRefNum, req.fName, req.fPortType, req.fFlags, req.fBufferSize, &res.fPortIndex); - res.Write(fPipe); - break; - } - - case JackRequest::kUnRegisterPort: { - JackLog("JackRequest::UnRegisterPort\n"); - JackPortUnRegisterRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortUnRegister(req.fRefNum, req.fPortIndex); - res.Write(fPipe); - break; - } - - case JackRequest::kConnectNamePorts: { - JackLog("JackRequest::ConnectPorts\n"); - JackPortConnectNameRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); - res.Write(fPipe); - break; - } - - case JackRequest::kDisconnectNamePorts: { - JackLog("JackRequest::DisconnectPorts\n"); - JackPortDisconnectNameRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); - res.Write(fPipe); - break; - } - - case JackRequest::kConnectPorts: { - JackLog("JackRequest::ConnectPorts\n"); - JackPortConnectRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); - res.Write(fPipe); - break; - } - - case JackRequest::kDisconnectPorts: { - JackLog("JackRequest::DisconnectPorts\n"); - JackPortDisconnectRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); - res.Write(fPipe); - break; - } - - case JackRequest::kSetBufferSize: { - JackLog("JackRequest::SetBufferSize\n"); - JackSetBufferSizeRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->SetBufferSize(req.fBufferSize); - res.Write(fPipe); - break; - } - - case JackRequest::kSetFreeWheel: { - JackLog("JackRequest::SetFreeWheel\n"); - JackSetFreeWheelRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->SetFreewheel(req.fOnOff); - res.Write(fPipe); - break; - } - - case JackRequest::kReleaseTimebase: { - JackLog("JackRequest::kReleaseTimebase\n"); - JackReleaseTimebaseRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->ReleaseTimebase(req.fRefNum); - res.Write(fPipe); - break; - } - - case JackRequest::kSetTimebaseCallback: { - JackLog("JackRequest::kSetTimebaseCallback\n"); - JackSetTimebaseCallbackRequest req; - JackResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->SetTimebaseCallback(req.fRefNum, req.fConditionnal); - res.Write(fPipe); - break; - } - - case JackRequest::kGetInternalClientName: { - JackLog("JackRequest::kGetInternalClientName\n"); - JackGetInternalClientNameRequest req; - JackGetInternalClientNameResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->GetInternalClientName(req.fIntRefNum, res.fName); - res.Write(fPipe); - break; - } - - case JackRequest::kInternalClientHandle: { - JackLog("JackRequest::kInternalClientHandle\n"); - JackInternalClientHandleRequest req; - JackInternalClientHandleResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->InternalClientHandle(req.fName, &res.fStatus, &res.fIntRefNum); - res.Write(fPipe); - break; - } - - case JackRequest::kInternalClientLoad: { - JackLog("JackRequest::kInternalClientLoad\n"); - JackInternalClientLoadRequest req; - JackInternalClientLoadResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->InternalClientLoad(req.fName, req.fDllName, req.fLoadInitName, req.fOptions, &res.fIntRefNum, &res.fStatus); - res.Write(fPipe); - break; - } - - case JackRequest::kInternalClientUnload: { - JackLog("JackRequest::kInternalClientUnload\n"); - JackInternalClientUnloadRequest req; - JackInternalClientUnloadResult res; - if (req.Read(fPipe) == 0) - res.fResult = fServer->GetEngine()->InternalClientUnload(req.fIntRefNum, &res.fStatus); - res.Write(fPipe); - break; - } - - case JackRequest::kNotification: { - JackLog("JackRequest::Notification\n"); - JackClientNotificationRequest req; - if (req.Read(fPipe) == 0) - fServer->Notify(req.fRefNum, req.fNotify, req.fValue); - break; - } - - default: - JackLog("Unknown request %ld\n", header.fType); - break; - } - } + if (res < 0) { + jack_error("HandleRequest: cannot read header"); + ClientKill(); + ret = -1; + } else { + + // Read data + switch (header.fType) { + + case JackRequest::kClientCheck: { + JackLog("JackRequest::kClientCheck\n"); + JackClientCheckRequest req; + JackClientCheckResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->ClientCheck(req.fName, res.fName, req.fProtocol, req.fOptions, &res.fStatus); + res.Write(fPipe); + break; + } + + case JackRequest::kClientOpen: { + JackLog("JackRequest::ClientOpen\n"); + JackClientOpenRequest req; + JackClientOpenResult res; + if (req.Read(fPipe) == 0) + ClientAdd(req.fName, &res.fSharedEngine, &res.fSharedClient, &res.fSharedGraph, &res.fResult); + res.Write(fPipe); + break; + } + + case JackRequest::kClientClose: { + JackLog("JackRequest::ClientClose\n"); + JackClientCloseRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->ClientExternalClose(req.fRefNum); + // No write: client is actually doing an "ServerAsyncCall", and not interested by the result + ClientRemove(); + ret = -1; + break; + } + + case JackRequest::kActivateClient: { + JackActivateRequest req; + JackResult res; + JackLog("JackRequest::ActivateClient\n"); + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->ClientActivate(req.fRefNum); + res.Write(fPipe); + break; + } + + case JackRequest::kDeactivateClient: { + JackLog("JackRequest::DeactivateClient\n"); + JackDeactivateRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->ClientDeactivate(req.fRefNum); + res.Write(fPipe); + break; + } + + case JackRequest::kRegisterPort: { + JackLog("JackRequest::RegisterPort\n"); + JackPortRegisterRequest req; + JackPortRegisterResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortRegister(req.fRefNum, req.fName, req.fPortType, req.fFlags, req.fBufferSize, &res.fPortIndex); + res.Write(fPipe); + break; + } + + case JackRequest::kUnRegisterPort: { + JackLog("JackRequest::UnRegisterPort\n"); + JackPortUnRegisterRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortUnRegister(req.fRefNum, req.fPortIndex); + res.Write(fPipe); + break; + } + + case JackRequest::kConnectNamePorts: { + JackLog("JackRequest::ConnectPorts\n"); + JackPortConnectNameRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); + res.Write(fPipe); + break; + } + + case JackRequest::kDisconnectNamePorts: { + JackLog("JackRequest::DisconnectPorts\n"); + JackPortDisconnectNameRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); + res.Write(fPipe); + break; + } + + case JackRequest::kConnectPorts: { + JackLog("JackRequest::ConnectPorts\n"); + JackPortConnectRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortConnect(req.fRefNum, req.fSrc, req.fDst); + res.Write(fPipe); + break; + } + + case JackRequest::kDisconnectPorts: { + JackLog("JackRequest::DisconnectPorts\n"); + JackPortDisconnectRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->PortDisconnect(req.fRefNum, req.fSrc, req.fDst); + res.Write(fPipe); + break; + } + + case JackRequest::kSetBufferSize: { + JackLog("JackRequest::SetBufferSize\n"); + JackSetBufferSizeRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->SetBufferSize(req.fBufferSize); + res.Write(fPipe); + break; + } + + case JackRequest::kSetFreeWheel: { + JackLog("JackRequest::SetFreeWheel\n"); + JackSetFreeWheelRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->SetFreewheel(req.fOnOff); + res.Write(fPipe); + break; + } + + case JackRequest::kReleaseTimebase: { + JackLog("JackRequest::kReleaseTimebase\n"); + JackReleaseTimebaseRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->ReleaseTimebase(req.fRefNum); + res.Write(fPipe); + break; + } + + case JackRequest::kSetTimebaseCallback: { + JackLog("JackRequest::kSetTimebaseCallback\n"); + JackSetTimebaseCallbackRequest req; + JackResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->SetTimebaseCallback(req.fRefNum, req.fConditionnal); + res.Write(fPipe); + break; + } + + case JackRequest::kGetInternalClientName: { + JackLog("JackRequest::kGetInternalClientName\n"); + JackGetInternalClientNameRequest req; + JackGetInternalClientNameResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->GetInternalClientName(req.fIntRefNum, res.fName); + res.Write(fPipe); + break; + } + + case JackRequest::kInternalClientHandle: { + JackLog("JackRequest::kInternalClientHandle\n"); + JackInternalClientHandleRequest req; + JackInternalClientHandleResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->InternalClientHandle(req.fName, &res.fStatus, &res.fIntRefNum); + res.Write(fPipe); + break; + } + + case JackRequest::kInternalClientLoad: { + JackLog("JackRequest::kInternalClientLoad\n"); + JackInternalClientLoadRequest req; + JackInternalClientLoadResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->InternalClientLoad(req.fName, req.fDllName, req.fLoadInitName, req.fOptions, &res.fIntRefNum, &res.fStatus); + res.Write(fPipe); + break; + } + + case JackRequest::kInternalClientUnload: { + JackLog("JackRequest::kInternalClientUnload\n"); + JackInternalClientUnloadRequest req; + JackInternalClientUnloadResult res; + if (req.Read(fPipe) == 0) + res.fResult = fServer->GetEngine()->InternalClientUnload(req.fIntRefNum, &res.fStatus); + res.Write(fPipe); + break; + } + + case JackRequest::kNotification: { + JackLog("JackRequest::Notification\n"); + JackClientNotificationRequest req; + if (req.Read(fPipe) == 0) + fServer->Notify(req.fRefNum, req.fNotify, req.fValue); + break; + } + + default: + JackLog("Unknown request %ld\n", header.fType); + break; + } + } // Unlock the global mutex ReleaseMutex(fMutex); @@ -328,11 +328,11 @@ void JackClientPipeThread::ClientAdd(char* name, int* shared_engine, int* shared void JackClientPipeThread::ClientRemove() { JackLog("JackClientPipeThread::ClientRemove ref = %d\n", fRefNum); - /* TODO : solve WIN32 thread Kill issue - Close(); - */ - fRefNum = -1; - fPipe->Close(); + /* TODO : solve WIN32 thread Kill issue + Close(); + */ + fRefNum = -1; + fPipe->Close(); } void JackClientPipeThread::ClientKill() @@ -341,8 +341,8 @@ void JackClientPipeThread::ClientKill() if (fRefNum == -1) { // Correspond to an already removed client. JackLog("Kill a closed client\n"); - } else if (fRefNum == 0) { // Correspond to a still not opened client. - JackLog("Kill a not opened client\n"); + } else if (fRefNum == 0) { // Correspond to a still not opened client. + JackLog("Kill a not opened client\n"); } else { fServer->Notify(fRefNum, kDeadClient, 0); } @@ -357,13 +357,13 @@ JackWinNamedPipeServerChannel::JackWinNamedPipeServerChannel() JackWinNamedPipeServerChannel::~JackWinNamedPipeServerChannel() { - std::list<JackClientPipeThread*>::iterator it; + std::list<JackClientPipeThread*>::iterator it; - for (it = fClientList.begin(); it != fClientList.end(); it++) { - JackClientPipeThread* client = *it; - client->Close(); - delete client; - } + for (it = fClientList.begin(); it != fClientList.end(); it++) { + JackClientPipeThread* client = *it; + client->Close(); + delete client; + } delete fThread; } @@ -373,7 +373,7 @@ int JackWinNamedPipeServerChannel::Open(const char* server_name, JackServer* ser JackLog("JackWinNamedPipeServerChannel::Open \n"); fServer = server; - snprintf(fServerName, sizeof(fServerName), server_name); + snprintf(fServerName, sizeof(fServerName), server_name); // Needed for internal connection from JackWinNamedPipeServerNotifyChannel object if (fRequestListenPipe.Bind(jack_server_dir, server_name, 0) < 0) { @@ -396,16 +396,16 @@ error: void JackWinNamedPipeServerChannel::Close() { - /* TODO : solve WIN32 thread Kill issue - This would hang the server... since we are quitting it, its not really problematic, - all ressources will be desallocated at the end. - - fRequestListenPipe.Close(); - fThread->Stop(); - */ - - fThread->Kill(); - fRequestListenPipe.Close(); + /* TODO : solve WIN32 thread Kill issue + This would hang the server... since we are quitting it, its not really problematic, + all ressources will be desallocated at the end. + + fRequestListenPipe.Close(); + fThread->Stop(); + */ + + fThread->Kill(); + fRequestListenPipe.Close(); } bool JackWinNamedPipeServerChannel::Init() @@ -413,7 +413,7 @@ bool JackWinNamedPipeServerChannel::Init() JackLog("JackWinNamedPipeServerChannel::Init \n"); JackWinNamedPipeClient* pipe; - // Accept first client, that is the JackWinNamedPipeServerNotifyChannel object + // Accept first client, that is the JackWinNamedPipeServerNotifyChannel object if ((pipe = fRequestListenPipe.AcceptClient()) == NULL) { jack_error("JackWinNamedPipeServerChannel::Init : cannot connect pipe"); return false; @@ -447,14 +447,14 @@ void JackWinNamedPipeServerChannel::ClientAdd(JackWinNamedPipeClient* pipe) std::list<JackClientPipeThread*>::iterator it = fClientList.begin(); JackClientPipeThread* client; - JackLog("ClientAdd size %ld\n", fClientList.size()); + JackLog("ClientAdd size %ld\n", fClientList.size()); - while (it != fClientList.end()) { + while (it != fClientList.end()) { client = *it; - JackLog("Remove dead client = %x running = %ld\n", client, client->IsRunning()); + JackLog("Remove dead client = %x running = %ld\n", client, client->IsRunning()); if (client->IsRunning()) { - it++; - } else { + it++; + } else { it = fClientList.erase(it); delete client; } @@ -462,7 +462,7 @@ void JackWinNamedPipeServerChannel::ClientAdd(JackWinNamedPipeClient* pipe) client = new JackClientPipeThread(pipe); client->Open(fServer); - // Here we are sure that the client is running (because it's thread is in "running" state). + // Here we are sure that the client is running (because it's thread is in "running" state). fClientList.push_back(client); } diff --git a/windows/JackWinNamedPipeServerChannel.h b/windows/JackWinNamedPipeServerChannel.h index 7c756248..d12f7631 100644 --- a/windows/JackWinNamedPipeServerChannel.h +++ b/windows/JackWinNamedPipeServerChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ @@ -58,7 +58,7 @@ class JackClientPipeThread : public JackRunnableInterface // JackRunnableInterface interface bool Execute(); - // To be used for find out if the object can be deleted + // To be used for find out if the object can be deleted bool IsRunning() { return (fRefNum >= 0); @@ -76,8 +76,8 @@ class JackWinNamedPipeServerChannel : public JackServerChannelInterface, public JackWinNamedPipeServer fRequestListenPipe; // Pipe to create request socket for the client JackServer* fServer; - JackThread* fThread; // Thread to execute the event loop
- char fServerName[64]; + JackThread* fThread; // Thread to execute the event loop + char fServerName[64]; std::list<JackClientPipeThread*> fClientList; diff --git a/windows/JackWinNamedPipeServerNotifyChannel.cpp b/windows/JackWinNamedPipeServerNotifyChannel.cpp index 4418f4b7..f7e72eba 100644 --- a/windows/JackWinNamedPipeServerNotifyChannel.cpp +++ b/windows/JackWinNamedPipeServerNotifyChannel.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 @@ -41,9 +41,9 @@ void JackWinNamedPipeServerNotifyChannel::Close() } /* -The requirement is that the Notification from RT thread can be delivered... not sure using a pipe is adequate here... -Can the write operation block? -A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise +The requirement is that the Notification from RT thread can be delivered... not sure using a pipe is adequate here... +Can the write operation block? +A non blocking write operation shoud be used : check if write can succeed, and ignore the notification otherwise (since its mainly used for XRun, ignoring a notification is OK, successive XRun will come...) */ void JackWinNamedPipeServerNotifyChannel::ClientNotify(int refnum, int notify, int value) diff --git a/windows/JackWinNamedPipeServerNotifyChannel.h b/windows/JackWinNamedPipeServerNotifyChannel.h index 09d3a2b8..2d8183f0 100644 --- a/windows/JackWinNamedPipeServerNotifyChannel.h +++ b/windows/JackWinNamedPipeServerNotifyChannel.h @@ -1,18 +1,18 @@ /* -Copyright (C) 2004-2006 Grame - +Copyright (C) 2004-2006 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 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. */ diff --git a/windows/JackWinProcessSync.h b/windows/JackWinProcessSync.h index f652e486..9bc7084c 100644 --- a/windows/JackWinProcessSync.h +++ b/windows/JackWinProcessSync.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2006 Grame +Copyright (C) 2004-2006 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 diff --git a/windows/JackWinSemaphore.cpp b/windows/JackWinSemaphore.cpp index 77f6f5bd..bfae058e 100644 --- a/windows/JackWinSemaphore.cpp +++ b/windows/JackWinSemaphore.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2005 Grame +Copyright (C) 2004-2005 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 @@ -35,11 +35,11 @@ bool JackWinSemaphore::Signal() if (fFlush) return true; - + if (!(res = ReleaseSemaphore(fSemaphore, 1, NULL))) { jack_error("JackWinSemaphore::Signal name = %s err = %ld", fName, GetLastError()); } - + return res; } @@ -51,10 +51,10 @@ bool JackWinSemaphore::SignalAll() if (fFlush) return true; - if (!(res = ReleaseSemaphore(fSemaphore, 1, NULL))) { + if (!(res = ReleaseSemaphore(fSemaphore, 1, NULL))) { jack_error("JackWinSemaphore::SignalAll name = %s err = %ld", fName, GetLastError()); } - + return res; } @@ -74,7 +74,7 @@ bool JackWinSemaphore::TimedWait(long usec) DWORD res; if ((res = WaitForSingleObject(fSemaphore, usec / 1000)) == WAIT_TIMEOUT) { - jack_error("JackWinSemaphore::TimedWait name = %s time_out", fName); + jack_error("JackWinSemaphore::TimedWait name = %s time_out", fName); } return (res == WAIT_OBJECT_0); @@ -92,8 +92,8 @@ bool JackWinSemaphore::ConnectInput(const char* name, const char* server_name) return true; } - if ((fSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS , FALSE, fName)) == NULL) { - jack_error("Connect: can't check in named event name = %s err = %ld", fName, GetLastError()); + if ((fSemaphore = OpenSemaphore(SEMAPHORE_ALL_ACCESS , FALSE, fName)) == NULL) { + jack_error("Connect: can't check in named event name = %s err = %ld", fName, GetLastError()); return false; } else { return true; @@ -127,23 +127,23 @@ bool JackWinSemaphore::Allocate(const char* name, const char* server_name, int v BuildName(name, server_name, fName); JackLog("JackWinSemaphore::Allocate name = %s val = %ld\n", fName, value); - if ((fSemaphore = CreateSemaphore(NULL, value, 32767, fName)) == NULL) { + if ((fSemaphore = CreateSemaphore(NULL, value, 32767, fName)) == NULL) { jack_error("Allocate: can't check in named semaphore name = %s err = %ld", fName, GetLastError()); return false; } else if (GetLastError() == ERROR_ALREADY_EXISTS) { - jack_error("Allocate: named semaphore already exist name = %s", fName); - CloseHandle(fSemaphore); - fSemaphore = NULL; - return false; - } else { - return true; + jack_error("Allocate: named semaphore already exist name = %s", fName); + CloseHandle(fSemaphore); + fSemaphore = NULL; + return false; + } else { + return true; } } void JackWinSemaphore::Destroy() { if (fSemaphore != NULL) { - JackLog("JackWinSemaphore::Destroy %s\n", fName); + JackLog("JackWinSemaphore::Destroy %s\n", fName); CloseHandle(fSemaphore); fSemaphore = NULL; } else { diff --git a/windows/JackWinSemaphore.h b/windows/JackWinSemaphore.h index f985b557..35919d9d 100644 --- a/windows/JackWinSemaphore.h +++ b/windows/JackWinSemaphore.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2004-2005 Grame +Copyright (C) 2004-2005 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 diff --git a/windows/JackWinThread.cpp b/windows/JackWinThread.cpp index 1128c763..5574eb79 100644 --- a/windows/JackWinThread.cpp +++ b/windows/JackWinThread.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2006 Grame This program is free software; you can redistribute it and/or modify @@ -49,42 +49,42 @@ DWORD WINAPI JackWinThread::ThreadHandler(void* arg) while (obj->fRunning && res) { res = runnable->Execute(); } - + SetEvent(obj->fEvent); JackLog("ThreadHandler: exit\n"); return 0; } -JackWinThread::JackWinThread(JackRunnableInterface* runnable) - : JackThread(runnable, 0, false, 0) +JackWinThread::JackWinThread(JackRunnableInterface* runnable) + : JackThread(runnable, 0, false, 0) { - fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - fThread = NULL; - assert(fEvent); + fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + fThread = NULL; + assert(fEvent); } JackWinThread::~JackWinThread() { - CloseHandle(fEvent); + CloseHandle(fEvent); } int JackWinThread::Start() { - fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + fEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (fEvent == NULL) { jack_error("Cannot create event error = %d", GetLastError()); return -1; } - fRunning = true; - - // Check if the thread was correctly started - if (StartImp(&fThread, fPriority, fRealTime, ThreadHandler, this) < 0) { - fRunning = false; - return -1; - } else { - return 0; - } + fRunning = true; + + // Check if the thread was correctly started + if (StartImp(&fThread, fPriority, fRealTime, ThreadHandler, this) < 0) { + fRunning = false; + return -1; + } else { + return 0; + } } int JackWinThread::StartImp(pthread_t* thread, int priority, int realtime, ThreadCallback start_routine, void* arg) @@ -179,11 +179,11 @@ int JackWinThread::Kill() { if (fThread) { // If thread has been started TerminateThread(fThread, 0); - WaitForSingleObject(fThread, INFINITE); + WaitForSingleObject(fThread, INFINITE); CloseHandle(fThread); - JackLog("JackWinThread::Kill 2\n"); - fThread = NULL; - fRunning = false; + JackLog("JackWinThread::Kill 2\n"); + fThread = NULL; + fRunning = false; return 0; } else { return -1; @@ -197,7 +197,7 @@ int JackWinThread::Stop() fRunning = false; // Request for the thread to stop WaitForSingleObject(fEvent, INFINITE); CloseHandle(fThread); - fThread = NULL; + fThread = NULL; return 0; } else { return -1; @@ -206,40 +206,40 @@ int JackWinThread::Stop() int JackWinThread::AcquireRealTime() { - return (fThread) ? AcquireRealTimeImp(fThread, fPriority) : -1; + return (fThread) ? AcquireRealTimeImp(fThread, fPriority) : -1; } int JackWinThread::AcquireRealTime(int priority) { - fPriority = priority; - return AcquireRealTime(); + fPriority = priority; + return AcquireRealTime(); } int JackWinThread::AcquireRealTimeImp(pthread_t thread, int priority) { JackLog("JackWinThread::AcquireRealTime\n"); - if (SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL)) { - JackLog("JackWinThread::AcquireRealTime OK\n"); - return 0; - } else { - jack_error("Cannot set thread priority = %d", GetLastError()); - return -1; - } + if (SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL)) { + JackLog("JackWinThread::AcquireRealTime OK\n"); + return 0; + } else { + jack_error("Cannot set thread priority = %d", GetLastError()); + return -1; + } } int JackWinThread::DropRealTime() { - return DropRealTimeImp(fThread); + return DropRealTimeImp(fThread); } int JackWinThread::DropRealTimeImp(pthread_t thread) { - if (SetThreadPriority(thread, THREAD_PRIORITY_NORMAL)) { - return 0; - } else { - jack_error("Cannot set thread priority = %d", GetLastError()); - return -1; - } + if (SetThreadPriority(thread, THREAD_PRIORITY_NORMAL)) { + return 0; + } else { + jack_error("Cannot set thread priority = %d", GetLastError()); + return -1; + } } pthread_t JackWinThread::GetThreadID() @@ -249,9 +249,9 @@ pthread_t JackWinThread::GetThreadID() void JackWinThread::Terminate() { - TerminateThread(fThread, 0); - WaitForSingleObject(fThread, INFINITE); - CloseHandle(fThread); + TerminateThread(fThread, 0); + WaitForSingleObject(fThread, INFINITE); + CloseHandle(fThread); } } // end of namespace diff --git a/windows/JackWinThread.h b/windows/JackWinThread.h index a4bafab7..3e773bf0 100644 --- a/windows/JackWinThread.h +++ b/windows/JackWinThread.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2006 Grame This program is free software; you can redistribute it and/or modify @@ -31,7 +31,7 @@ namespace Jack typedef DWORD (WINAPI *ThreadCallback)(void *arg); /*! -\brief Windows threads. +\brief Windows threads. */ class JackWinThread : public JackThread @@ -48,22 +48,22 @@ class JackWinThread : public JackThread JackWinThread(JackRunnableInterface* runnable); virtual ~JackWinThread(); - + int Start(); int StartSync(); int Kill(); int Stop(); - void Terminate(); + void Terminate(); int AcquireRealTime(); int AcquireRealTime(int priority) ; int DropRealTime(); pthread_t GetThreadID(); - - static int AcquireRealTimeImp(pthread_t thread, int priority); - static int DropRealTimeImp(pthread_t thread); - static int StartImp(pthread_t* thread, int priority, int realtime, ThreadCallback start_routine, void* arg); + + static int AcquireRealTimeImp(pthread_t thread, int priority); + static int DropRealTimeImp(pthread_t thread); + static int StartImp(pthread_t* thread, int priority, int realtime, ThreadCallback start_routine, void* arg); }; diff --git a/windows/JackdmpWIN32.cpp b/windows/JackdmpWIN32.cpp index 93410de1..fab39027 100644 --- a/windows/JackdmpWIN32.cpp +++ b/windows/JackdmpWIN32.cpp @@ -1,5 +1,5 @@ /* -Copyright (C) 2001 Paul Davis +Copyright (C) 2001 Paul Davis Copyright (C) 2004-2006 Grame This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include <signal.h> #include "JackServer.h" -#include "JackConstants.h" +#include "JackConstants.h" #include "driver_interface.h" #include "JackDriverLoader.h" #include "shm.h" @@ -79,7 +79,7 @@ static void usage (FILE *file) " [ --loopback OR -L loopback-port-number ]\n" // " [ --port-max OR -p maximum-number-of-ports]\n" " [ --verbose OR -v ]\n" - " [ --replace-registry OR -r ]\n" + " [ --replace-registry OR -r ]\n" " [ --silent OR -s ]\n" " [ --sync OR -S ]\n" " [ --version OR -V ]\n" @@ -118,7 +118,7 @@ static void intrpt(int signum) { printf("jack main caught signal %d\n", signum); (void) signal(SIGINT, SIG_DFL); - SetEvent(waitEvent); + SetEvent(waitEvent); } /* @@ -129,75 +129,75 @@ static char* jack_default_server_name(void) server_name = "default"; return server_name; } - -// returns the name of the per-user subdirectory of jack_tmpdir + +// returns the name of the per-user subdirectory of jack_tmpdir static char* jack_user_dir(void) { static char user_dir[PATH_MAX] = ""; - - // format the path name on the first call + + // format the path name on the first call if (user_dir[0] == '\0') { snprintf (user_dir, sizeof (user_dir), "%s/jack-%d", jack_tmpdir, _getuid ()); } - + return user_dir; } - -// returns the name of the per-server subdirectory of jack_user_dir() - + +// returns the name of the per-server subdirectory of jack_user_dir() + static char* get_jack_server_dir(const char * toto) { static char server_dir[PATH_MAX] = ""; - - // format the path name on the first call + + // format the path name on the first call if (server_dir[0] == '\0') { snprintf (server_dir, sizeof (server_dir), "%s/%s", jack_user_dir (), server_name); } - + return server_dir; } - + static void jack_cleanup_files (const char *server_name) { DIR *dir; struct dirent *dirent; char *dir_name = get_jack_server_dir (server_name); - - // nothing to do if the server directory does not exist + + // nothing to do if the server directory does not exist if ((dir = opendir (dir_name)) == NULL) { return; } - - // unlink all the files in this directory, they are mine + + // unlink all the files in this directory, they are mine while ((dirent = readdir (dir)) != NULL) { - + char fullpath[PATH_MAX]; - + if ((strcmp (dirent->d_name, ".") == 0) || (strcmp (dirent->d_name, "..") == 0)) { continue; } - + snprintf (fullpath, sizeof (fullpath), "%s/%s", dir_name, dirent->d_name); - + if (unlink (fullpath)) { jack_error ("cannot unlink `%s' (%s)", fullpath, strerror (errno)); } - } - + } + closedir (dir); - - // now, delete the per-server subdirectory, itself + + // now, delete the per-server subdirectory, itself if (rmdir (dir_name)) { jack_error ("cannot remove `%s' (%s)", dir_name, strerror (errno)); } - - // finally, delete the per-user subdirectory, if empty + + // finally, delete the per-user subdirectory, if empty if (rmdir (jack_user_dir ())) { if (errno != ENOTEMPTY) { jack_error ("cannot remove `%s' (%s)", @@ -208,45 +208,45 @@ static void jack_cleanup_files (const char *server_name) */ /* -BOOL CtrlHandler( DWORD fdwCtrlType ) -{ - switch( fdwCtrlType ) - { - // Handle the CTRL-C signal. - case CTRL_C_EVENT: +BOOL CtrlHandler( DWORD fdwCtrlType ) +{ + switch( fdwCtrlType ) + { + // Handle the CTRL-C signal. + case CTRL_C_EVENT: printf( "Ctrl-C event\n\n" ); - Beep( 750, 300 ); + Beep( 750, 300 ); SetEvent(waitEvent); return( TRUE ); - - // CTRL-CLOSE: confirm that the user wants to exit. - case CTRL_CLOSE_EVENT: - Beep( 600, 200 ); + + // CTRL-CLOSE: confirm that the user wants to exit. + case CTRL_CLOSE_EVENT: + Beep( 600, 200 ); printf( "Ctrl-Close event\n\n" ); SetEvent(waitEvent); - return( TRUE ); - - // Pass other signals to the next handler. - case CTRL_BREAK_EVENT: - Beep( 900, 200 ); + return( TRUE ); + + // Pass other signals to the next handler. + case CTRL_BREAK_EVENT: + Beep( 900, 200 ); printf( "Ctrl-Break event\n\n" ); - return FALSE; - - case CTRL_LOGOFF_EVENT: - Beep( 1000, 200 ); + return FALSE; + + case CTRL_LOGOFF_EVENT: + Beep( 1000, 200 ); printf( "Ctrl-Logoff event\n\n" ); - return FALSE; - - case CTRL_SHUTDOWN_EVENT: - Beep( 750, 500 ); + return FALSE; + + case CTRL_SHUTDOWN_EVENT: + Beep( 750, 500 ); printf( "Ctrl-Shutdown event\n\n" ); - return FALSE; - - default: - return FALSE; - } -} - + return FALSE; + + default: + return FALSE; + } +} + */ int main(int argc, char* argv[]) @@ -263,7 +263,7 @@ int main(int argc, char* argv[]) { "name", 0, 0, 'n' }, { "unlock", 0, 0, 'u' }, { "realtime", 0, 0, 'R' }, - { "replace-registry", 0, 0, 'r' }, + { "replace-registry", 0, 0, 'r' }, { "loopback", 0, 0, 'L' }, { "realtime-priority", 1, 0, 'P' }, { "timeout", 1, 0, 't' }, @@ -281,14 +281,14 @@ int main(int argc, char* argv[]) JSList * driver_params; int driver_nargs = 1; int show_version = 0; - int replace_registry = 0; + int replace_registry = 0; int sync = 0; int i; int rc; char c; - // Creates wait event - if ((waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) { + // Creates wait event + if ((waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) { printf("CreateEvent fails err = %ld\n", GetLastError()); return 0; } @@ -332,10 +332,10 @@ int main(int argc, char* argv[]) case 'P': realtime_priority = atoi(optarg); break; - - case 'r': - replace_registry = 1; - break; + + case 'r': + replace_registry = 1; + break; case 'R': realtime = 1; @@ -374,21 +374,21 @@ int main(int argc, char* argv[]) if (!seen_driver) { usage (stderr); //exit (1); - return 0; + return 0; } drivers = jack_drivers_load (drivers); if (!drivers) { fprintf (stderr, "jackdmp: no drivers found; exiting\n"); //exit (1); - return 0; + return 0; } driver_desc = jack_find_driver_descriptor (drivers, driver_name); if (!driver_desc) { fprintf (stderr, "jackdmp: unknown driver '%s'\n", driver_name); //exit (1); - return 0; + return 0; } if (optind < argc) { @@ -412,8 +412,8 @@ int main(int argc, char* argv[]) if (jack_parse_driver_params (driver_desc, driver_nargs, driver_args, &driver_params)) { - // exit (0); - return 0; + // exit (0); + return 0; } //if (server_name == NULL) @@ -426,15 +426,15 @@ int main(int argc, char* argv[]) case EEXIST: fprintf (stderr, "`%s' server already active\n", server_name); //exit (1); - return 0; + return 0; case ENOSPC: fprintf (stderr, "too many servers already active\n"); //exit (2); - return 0; + return 0; case ENOMEM: fprintf (stderr, "no access to shm registry\n"); //exit (3); - return 0; + return 0; default: if (xverbose) fprintf (stderr, "server `%s' registered\n", @@ -457,29 +457,29 @@ int main(int argc, char* argv[]) return 0; } - /* - if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) ) - { - printf( "\nThe Control Handler is installed.\n" ); - } else { - printf( "\nERROR: Could not set control handler"); - } - */ - - - (void) signal(SIGINT, intrpt); - (void) signal(SIGABRT, intrpt); - (void) signal(SIGTERM, intrpt); - - if ((res = WaitForSingleObject(waitEvent, INFINITE)) != WAIT_OBJECT_0) { + /* + if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) ) + { + printf( "\nThe Control Handler is installed.\n" ); + } else { + printf( "\nERROR: Could not set control handler"); + } + */ + + + (void) signal(SIGINT, intrpt); + (void) signal(SIGABRT, intrpt); + (void) signal(SIGTERM, intrpt); + + if ((res = WaitForSingleObject(waitEvent, INFINITE)) != WAIT_OBJECT_0) { printf("WaitForSingleObject fails err = %ld\n", GetLastError()); } - - /* - printf("Type 'q' to quit\n"); - while ((c = getchar()) != 'q') {} - */ - + + /* + printf("Type 'q' to quit\n"); + while ((c = getchar()) != 'q') {} + */ + JackStop(); @@ -487,7 +487,7 @@ int main(int argc, char* argv[]) // jack_cleanup_files(server_name); jack_unregister_server(server_name); - CloseHandle(waitEvent); + CloseHandle(waitEvent); return 1; } diff --git a/windows/getopt.h b/windows/getopt.h index 73cb3ffd..acf1ff72 100644 --- a/windows/getopt.h +++ b/windows/getopt.h @@ -59,7 +59,7 @@ extern "C" extern int optopt; -#ifndef __need_getopt +#ifndef __need_getopt /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is @@ -128,7 +128,7 @@ extern "C" `getopt'. */ #if defined __STDC__ && __STDC__ -# ifdef __GNU_LIBRARY__ +# ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ diff --git a/windows/pa_asio.h b/windows/pa_asio.h index 941d419d..64e075b6 100644 --- a/windows/pa_asio.h +++ b/windows/pa_asio.h @@ -1,5 +1,5 @@ #ifndef PA_ASIO_H -#define PA_ASIO_H +#define PA_ASIO_H /* * $Id: pa_asio.h,v 1.1.2.2 2006/06/20 14:44:48 letz Exp $ * PortAudio Portable Real-Time Audio Library diff --git a/windows/portaudio.h b/windows/portaudio.h index 57ccc36f..09a43987 100644 --- a/windows/portaudio.h +++ b/windows/portaudio.h @@ -1,6 +1,6 @@ #ifndef PORTAUDIO_H -#define PORTAUDIO_H +#define PORTAUDIO_H /* * $Id: portaudio.h,v 1.1.2.2 2006/06/20 14:44:48 letz Exp $ * PortAudio Portable Real-Time Audio Library @@ -61,8 +61,7 @@ extern "C" */ typedef int PaError; - typedef enum PaErrorCode - { + typedef enum PaErrorCode { paNoError = 0, paNotInitialized = -10000, @@ -94,7 +93,8 @@ extern "C" paCanNotWriteToAnInputOnlyStream, /**< @todo review error code name */ paIncompatibleStreamHostApi, paBadBufferPtr - } PaErrorCode; + } + PaErrorCode; /** Translate the supplied PortAudio error code into a human readable @@ -213,8 +213,7 @@ extern "C" @see PaHostApiInfo */ - typedef enum PaHostApiTypeId - { + typedef enum PaHostApiTypeId { paInDevelopment = 0, /* use while developing support for a new host API */ paDirectSound = 1, paMME = 2, @@ -228,7 +227,8 @@ extern "C" paWDMKS = 11, paJACK = 12, paWASAPI = 13 - } PaHostApiTypeId; + } + PaHostApiTypeId; /** A structure containing information about a particular host API. */ @@ -393,7 +393,7 @@ extern "C" /** The type used to represent monotonic time in seconds that can be used for syncronisation. The type is used for the outTime argument to the PaStreamCallback and as the result of Pa_GetStreamTime(). - + @see PaStreamCallback, Pa_GetStreamTime */ typedef double PaTime; @@ -696,11 +696,11 @@ extern "C" Functions of type PaStreamCallback are implemented by PortAudio clients. They consume, process or generate audio in response to requests from an active PortAudio stream. - + @param input and @param output are arrays of interleaved samples, the format, packing and number of channels used by the buffers are determined by parameters to Pa_OpenStream(). - + @param frameCount The number of sample frames to be processed by the stream callback. @@ -745,10 +745,10 @@ extern "C" /** Opens a stream for either input, output or both. - + @param stream The address of a PaStream pointer which will receive a pointer to the newly opened stream. - + @param inputParameters A structure that describes the input parameters used by the opened stream. See PaStreamParameters for a description of these parameters. inputParameters must be NULL for output-only streams. @@ -759,7 +759,7 @@ extern "C" @param sampleRate The desired sampleRate. For full-duplex streams it is the sample rate for both input and output - + @param framesPerBuffer The number of frames passed to the stream callback function, or the preferred block granularity for a blocking read/write stream. The special value paFramesPerBufferUnspecified (0) may be used to request that @@ -775,7 +775,7 @@ extern "C" @param streamFlags Flags which modify the behaviour of the streaming process. This parameter may contain a combination of flags ORed together. Some flags may only be relevant to certain buffer formats. - + @param streamCallback A pointer to a client supplied function that is responsible for processing and filling input and output buffers. If this parameter is NULL the stream will be opened in 'blocking read/write' mode. In blocking mode, @@ -788,7 +788,7 @@ extern "C" function. It could for example, contain a pointer to instance data necessary for processing the audio buffers. This parameter is ignored if streamCallback is NULL. - + @return Upon success Pa_OpenStream() returns paNoError and places a pointer to a valid PaStream in the stream argument. The stream is inactive (stopped). @@ -997,7 +997,7 @@ extern "C" /** Determine the current time for the stream according to the same clock used to generate buffer timestamps. This time may be used for syncronising other events to the audio stream, for example synchronizing audio to MIDI. - + @return The stream's current time in seconds, or 0 if an error occurred. @see PaTime, PaStreamCallback @@ -1012,7 +1012,7 @@ extern "C" This function may be called from the stream callback function or the application. - + @return A floating point value, typically between 0.0 and 1.0, where 1.0 indicates that the stream callback is consuming the maximum number of CPU cycles possible diff --git a/windows/regex.h b/windows/regex.h index 10cf8f03..adcf40c5 100644 --- a/windows/regex.h +++ b/windows/regex.h @@ -28,7 +28,7 @@ extern "C" /* POSIX says that <sys/types.h> must be included (by the caller) before <regex.h>. */ -#ifdef VMS +#ifdef VMS /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it should be there. */ #include <stddef.h> @@ -143,7 +143,7 @@ extern "C" /* Define combinations of the above bits for the standard possibilities. (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ + don't delete them!) */ /* [[[begin syntaxes]]] */ #define RE_SYNTAX_EMACS 0 @@ -201,7 +201,7 @@ extern "C" (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) + | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) /* [[[end syntaxes]]] */ /* Maximum number of duplicates an interval can allow. Some systems @@ -248,8 +248,7 @@ extern "C" /* If any error codes are removed, changed, or added, update the `re_error_msg' table in regex.c. */ - typedef enum - { + typedef enum { REG_NOERROR = 0, /* Success. */ REG_NOMATCH, /* Didn't find a match (for regexec). */ @@ -272,7 +271,8 @@ extern "C" REG_EEND, /* Premature end. */ REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ - } reg_errcode_t; + } + reg_errcode_t; /* This data structure represents a compiled pattern. Before calling the pattern compiler, the fields `buffer', `allocated', `fastmap', |