From 41bbcc3d95a91da37a1586a7995c2be968261e6a Mon Sep 17 00:00:00 2001 From: sletz Date: Wed, 23 Mar 2011 16:18:51 +0000 Subject: [PATCH 1/7] Devin Anderson server-ctl-proposal branch merged on trunk: improved control API, slave backend reworked. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4220 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index d5abfbf2..efbf71d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,10 @@ Valerio Pilo Jackdmp changes log --------------------------- +2011-03-23 Stephane Letz + + * Devin Anderson server-ctl-proposal branch merged on trunk: improved control API, slave backend reworked. + 2011-03-14 Stephane Letz * Correct JackEngine::NotifyGraphReorder, update JackDebugClient with latest API. From 92d88530ec0ac0914742062e47659587efe59037 Mon Sep 17 00:00:00 2001 From: sletz Date: Thu, 24 Mar 2011 10:16:30 +0000 Subject: [PATCH 2/7] Implement renaming in JackDriver::Open to avoid name collision (thanks Devin Anderson). git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4221 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 4 ++++ common/JackDriver.cpp | 20 +++++++++++++++++++- common/JackEngine.cpp | 12 ++++++------ common/JackInternalClient.cpp | 16 ++++++++-------- common/varargs.h | 12 ++++++------ 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index efbf71d0..95e0b8e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,10 @@ Valerio Pilo Jackdmp changes log --------------------------- +2011-03-24 Stephane Letz + + * Implement renaming in JackDriver::Open to avoid name collision (thanks Devin Anderson). + 2011-03-23 Stephane Letz * Devin Anderson server-ctl-proposal branch merged on trunk: improved control API, slave backend reworked. diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index 657524bd..ce860468 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -82,7 +82,7 @@ int JackDriver::Open() return 0; } -int JackDriver::Open (bool capturing, +int JackDriver::Open(bool capturing, bool playing, int inchannels, int outchannels, @@ -95,6 +95,15 @@ int JackDriver::Open (bool capturing, jack_log("JackDriver::Open capture_driver_name = %s", capture_driver_name); jack_log("JackDriver::Open playback_driver_name = %s", playback_driver_name); int refnum = -1; + char name_res[JACK_CLIENT_NAME_SIZE + 1]; + int status; + + // Check name and possibly rename + if (fEngine->ClientCheck(fClientControl.fName, -1, name_res, JACK_PROTOCOL_VERSION, (int)JackNullOption, (int*)&status) < 0) { + jack_error("Client name = %s conflits with another running client", fClientControl.fName); + return -1; + } + strcpy(fClientControl.fName, name_res); if (fEngine->ClientInternalOpen(fClientControl.fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) { jack_error("Cannot allocate internal client for driver"); @@ -137,6 +146,15 @@ int JackDriver::Open(jack_nframes_t buffer_size, jack_log("JackDriver::Open capture_driver_name = %s", capture_driver_name); jack_log("JackDriver::Open playback_driver_name = %s", playback_driver_name); int refnum = -1; + char name_res[JACK_CLIENT_NAME_SIZE + 1]; + int status; + + // Check name and possibly rename + if (fEngine->ClientCheck(fClientControl.fName, -1, name_res, JACK_PROTOCOL_VERSION, (int)JackNullOption, (int*)&status) < 0) { + jack_error("Client name = %s conflits with another running client", fClientControl.fName); + return -1; + } + strcpy(fClientControl.fName, name_res); if (fEngine->ClientInternalOpen(fClientControl.fName, &refnum, &fEngineControl, &fGraphManager, this, false) != 0) { jack_error("Cannot allocate internal client for driver"); diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 0fbc753a..2c7db9e3 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -519,7 +519,7 @@ void JackEngine::EnsureUUID(int uuid) for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (client->GetClientControl()->fSessionID==uuid)) { + if (client && (client->GetClientControl()->fSessionID == uuid)) { client->GetClientControl()->fSessionID = GetNewUUID(); } } @@ -550,13 +550,13 @@ int JackEngine::GetClientRefNum(const char* name) // Used for external clients int JackEngine::ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) { - char real_name[JACK_CLIENT_NAME_SIZE+1]; + char real_name[JACK_CLIENT_NAME_SIZE + 1]; if (uuid < 0) { uuid = GetNewUUID(); strncpy(real_name, name, JACK_CLIENT_NAME_SIZE); } else { - std::map::iterator res = fReservationMap.find(uuid); + std::map::iterator res = fReservationMap.find(uuid); if (res != fReservationMap.end()) { strncpy(real_name, res->second.c_str(), JACK_CLIENT_NAME_SIZE); fReservationMap.erase(uuid); @@ -567,7 +567,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int uuid, int* ref EnsureUUID(uuid); } - jack_log("JackEngine::ClientExternalOpen: uuid=%d, name = %s ", uuid, real_name); + jack_log("JackEngine::ClientExternalOpen: uuid = %d, name = %s ", uuid, real_name); int refnum = AllocateRefnum(); if (refnum < 0) { @@ -958,7 +958,7 @@ void JackEngine::SessionNotify(int refnum, const char *target, jack_session_even if (client && client->GetClientControl()->fCallback[kSessionCallback]) { // check if this is a notification to a specific client. - if (target!=NULL && strlen(target)!=0) { + if (target != NULL && strlen(target) != 0) { if (strcmp(target, client->GetClientControl()->fName)) { continue; } @@ -1018,7 +1018,7 @@ void JackEngine::GetUUIDForClientName(const char *client_name, char *uuid_res, i for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (strcmp(client_name, client->GetClientControl()->fName)==0)) { + if (client && (strcmp(client_name, client->GetClientControl()->fName) == 0)) { snprintf(uuid_res, JACK_UUID_SIZE, "%d", client->GetClientControl()->fSessionID); *result = 0; return; diff --git a/common/JackInternalClient.cpp b/common/JackInternalClient.cpp index 0f0e3e2a..550db2ef 100644 --- a/common/JackInternalClient.cpp +++ b/common/JackInternalClient.cpp @@ -123,7 +123,7 @@ int JackLoadableInternalClient::Init(const char* so_name) { char path_to_so[JACK_PATH_MAX + 1]; BuildClientPath(path_to_so, sizeof(path_to_so), so_name); - + fHandle = LoadJackModule(path_to_so); jack_log("JackLoadableInternalClient::JackLoadableInternalClient path_to_so = %s", path_to_so); @@ -151,7 +151,7 @@ int JackLoadableInternalClient1::Init(const char* so_name) if (JackLoadableInternalClient::Init(so_name) < 0) { return -1; } - + fInitialize = (InitializeCallback)GetJackProc(fHandle, "jack_initialize"); if (fInitialize == NULL) { UnloadJackModule(fHandle); @@ -167,7 +167,7 @@ int JackLoadableInternalClient2::Init(const char* so_name) if (JackLoadableInternalClient::Init(so_name) < 0) { return -1; } - + fInitialize = (InternalInitializeCallback)GetJackProc(fHandle, "jack_internal_initialize"); if (fInitialize == NULL) { UnloadJackModule(fHandle); @@ -181,7 +181,7 @@ int JackLoadableInternalClient2::Init(const char* so_name) JackLoadableInternalClient1::JackLoadableInternalClient1(JackServer* server, JackSynchro* table, const char* object_data) : JackLoadableInternalClient(server, table) { - strncpy(fObjectData, object_data, JACK_LOAD_INIT_LIMIT); + strncpy(fObjectData, object_data, JACK_LOAD_INIT_LIMIT); } JackLoadableInternalClient2::JackLoadableInternalClient2(JackServer* server, JackSynchro* table, const JSList* parameters) @@ -201,7 +201,7 @@ JackLoadableInternalClient::~JackLoadableInternalClient() int JackLoadableInternalClient1::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status) { int res = -1; - + if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) { if (fInitialize((jack_client_t*)this, fObjectData) == 0) { res = 0; @@ -210,14 +210,14 @@ int JackLoadableInternalClient1::Open(const char* server_name, const char* name, fFinish = NULL; } } - + return res; } int JackLoadableInternalClient2::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status) { int res = -1; - + if (JackInternalClient::Open(server_name, name, uuid, options, status) == 0) { if (fInitialize((jack_client_t*)this, fParameters) == 0) { res = 0; @@ -226,7 +226,7 @@ int JackLoadableInternalClient2::Open(const char* server_name, const char* name, fFinish = NULL; } } - + return res; } diff --git a/common/varargs.h b/common/varargs.h index b7df00f6..f4a50948 100644 --- a/common/varargs.h +++ b/common/varargs.h @@ -39,23 +39,23 @@ extern "C" } jack_varargs_t; - static const char* jack_default_server_name (void) - { + static const char* jack_default_server_name (void) + { const char *server_name; if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL) server_name = "default"; return server_name; } - static inline void jack_varargs_init (jack_varargs_t *va) - { + static inline void jack_varargs_init (jack_varargs_t *va) + { memset (va, 0, sizeof(jack_varargs_t)); va->server_name = (char*)jack_default_server_name(); va->session_id = -1; } - static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va) - { + static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va) + { // initialize default settings jack_varargs_init (va); From 641179517fc9b285829d1eab527263ffe5ae3da5 Mon Sep 17 00:00:00 2001 From: sletz Date: Thu, 24 Mar 2011 10:23:52 +0000 Subject: [PATCH 3/7] Correct alsa_driver_restart (thanks Devin Anderson). git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4222 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 1 + linux/alsa/JackAlsaDriver.cpp | 8 ++++++++ linux/alsa/alsa_driver.c | 4 ++++ linux/alsa/alsa_driver.h | 1 + 4 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 95e0b8e2..9fe8e1c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,7 @@ Valerio Pilo 2011-03-24 Stephane Letz * Implement renaming in JackDriver::Open to avoid name collision (thanks Devin Anderson). + * Correct alsa_driver_restart (thanks Devin Anderson). 2011-03-23 Stephane Letz diff --git a/linux/alsa/JackAlsaDriver.cpp b/linux/alsa/JackAlsaDriver.cpp index b9f8c175..b42e9693 100644 --- a/linux/alsa/JackAlsaDriver.cpp +++ b/linux/alsa/JackAlsaDriver.cpp @@ -1048,6 +1048,14 @@ void SetTime(jack_time_t time) g_alsa_driver->SetTimetAux(time); } +int Restart() +{ + int res; + if ((res = g_alsa_driver->Stop()) == 0) + res = g_alsa_driver->Start(); + return res; +} + #ifdef __cplusplus } #endif diff --git a/linux/alsa/alsa_driver.c b/linux/alsa/alsa_driver.c index c5dad023..536cfb6c 100644 --- a/linux/alsa/alsa_driver.c +++ b/linux/alsa/alsa_driver.c @@ -1159,8 +1159,12 @@ alsa_driver_restart (alsa_driver_t *driver) int res; driver->xrun_recovery = 1; + // JACK2 + /* if ((res = driver->nt_stop((struct _jack_driver_nt *) driver))==0) res = driver->nt_start((struct _jack_driver_nt *) driver); + */ + res = Restart(); driver->xrun_recovery = 0; if (res && driver->midi) diff --git a/linux/alsa/alsa_driver.h b/linux/alsa/alsa_driver.h index 7496fc31..efe93de5 100644 --- a/linux/alsa/alsa_driver.h +++ b/linux/alsa/alsa_driver.h @@ -278,6 +278,7 @@ void MonitorInput(); void ClearOutput(); void WriteOutput(jack_nframes_t orig_nframes, snd_pcm_sframes_t contiguous, snd_pcm_sframes_t nwritten); void SetTime(jack_time_t time); +int Restart(); #ifdef __cplusplus } From 5e19eacbeab3365f6f5639421abdafbfc9c33fa0 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Fri, 25 Mar 2011 15:06:45 +0100 Subject: [PATCH 4/7] Correct latency for MIDI backend. --- common/JackMidiDriver.cpp | 10 ++++++++++ macosx/coremidi/JackCoreMidiDriver.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/common/JackMidiDriver.cpp b/common/JackMidiDriver.cpp index b8993e7a..454f046d 100644 --- a/common/JackMidiDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -74,9 +74,12 @@ int JackMidiDriver::Attach() 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]; + jack_latency_range_t latency_range; + jack_nframes_t latency = fEngineControl->fBufferSize; int i; jack_log("JackMidiDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate); + latency_range.max = latency_range.min = latency; for (i = 0; i < fCaptureChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, i + 1); @@ -87,10 +90,16 @@ int JackMidiDriver::Attach() } port = fGraphManager->GetPort(port_index); port->SetAlias(alias); + port->SetLatencyRange(JackCaptureLatency, &latency_range); fCapturePortList[i] = port_index; jack_log("JackMidiDriver::Attach fCapturePortList[i] port_index = %ld", port_index); } + if (!fEngineControl->fSyncMode) { + latency += fEngineControl->fBufferSize;; + latency_range.max = latency_range.min = latency; + } + for (i = 0; i < fPlaybackChannels; i++) { snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fAliasName, fPlaybackDriverName, i + 1); snprintf(name, sizeof(name) - 1, "%s:playback_%d", fClientControl.fName, i + 1); @@ -100,6 +109,7 @@ int JackMidiDriver::Attach() } port = fGraphManager->GetPort(port_index); port->SetAlias(alias); + port->SetLatencyRange(JackPlaybackLatency, &latency_range); fPlaybackPortList[i] = port_index; jack_log("JackMidiDriver::Attach fPlaybackPortList[i] port_index = %ld", port_index); } diff --git a/macosx/coremidi/JackCoreMidiDriver.cpp b/macosx/coremidi/JackCoreMidiDriver.cpp index 1cb7176b..233ac8dd 100644 --- a/macosx/coremidi/JackCoreMidiDriver.cpp +++ b/macosx/coremidi/JackCoreMidiDriver.cpp @@ -227,9 +227,12 @@ int JackCoreMidiDriver::Attach() char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; char endpoint_name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + jack_latency_range_t latency_range; + jack_nframes_t latency = fEngineControl->fBufferSize; int i; jack_log("JackCoreMidiDriver::Attach fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate); + latency_range.max = latency_range.min = latency; for (i = 0; i < fCaptureChannels; i++) { @@ -249,10 +252,16 @@ int JackCoreMidiDriver::Attach() } port = fGraphManager->GetPort(port_index); port->SetAlias(alias); + port->SetLatencyRange(JackCaptureLatency, &latency_range); fCapturePortList[i] = port_index; jack_log("JackCoreMidiDriver::Attach fCapturePortList[i] port_index = %ld", port_index); } + if (!fEngineControl->fSyncMode) { + latency += fEngineControl->fBufferSize;; + latency_range.max = latency_range.min = latency; + } + for (i = 0; i < fPlaybackChannels; i++) { err = MIDIObjectGetStringProperty(fMidiSource[i], kMIDIPropertyName, &pname); @@ -271,6 +280,7 @@ int JackCoreMidiDriver::Attach() } port = fGraphManager->GetPort(port_index); port->SetAlias(alias); + port->SetLatencyRange(JackPlaybackLatency, &latency_range); fPlaybackPortList[i] = port_index; jack_log("JackCoreMidiDriver::Attach fPlaybackPortList[i] port_index = %ld", port_index); } From 981ff8cf459ff4adb7c7c14a45f99bc7497e4355 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Fri, 25 Mar 2011 17:18:37 +0100 Subject: [PATCH 5/7] Major redesign of driver activation (master and salve mode). --- common/JackAudioDriver.cpp | 58 +++++++++++++++++++------- common/JackAudioDriver.h | 8 +++- common/JackDriver.cpp | 27 ++++++++++++- common/JackDriver.h | 34 ++++++++++++++-- common/JackFreewheelDriver.cpp | 74 +++++++++++++++++++++++++++------- common/JackFreewheelDriver.h | 10 +++++ common/JackMidiDriver.cpp | 62 ++++++++++------------------ common/JackMidiDriver.h | 12 ++++-- common/JackThreadedDriver.cpp | 19 ++++++++- common/JackThreadedDriver.h | 9 ++++- 10 files changed, 231 insertions(+), 82 deletions(-) diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index 272c1e66..dedf02b0 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -193,9 +193,9 @@ int JackAudioDriver::ProcessNull() JackDriver::CycleTakeBeginTime(); if (fEngineControl->fSyncMode) { - ProcessGraphSync(); + ProcessGraphSyncMaster(); } else { - ProcessGraphAsync(); + ProcessGraphAsyncMaster(); } // Keep end cycle time @@ -230,9 +230,9 @@ int JackAudioDriver::ProcessAsync() // Process graph if (fIsMaster) { - ProcessGraphAsync(); + ProcessGraphAsyncMaster(); } else { - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); + ProcessGraphAsyncSlave(); } // Keep end cycle time @@ -255,12 +255,12 @@ int JackAudioDriver::ProcessSync() // Process graph if (fIsMaster) { - if (ProcessGraphSync() < 0) { + if (ProcessGraphSyncMaster() < 0) { jack_error("JackAudioDriver::ProcessSync: process error, skip cycle..."); goto end; } } else { - if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + if (ProcessGraphSyncSlave() < 0) { jack_error("JackAudioDriver::ProcessSync: process error, skip cycle..."); goto end; } @@ -279,27 +279,50 @@ end: return 0; } -void JackAudioDriver::ProcessGraphAsync() +void JackAudioDriver::ProcessGraphAsyncMaster() { // fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle if (!fEngine->Process(fBeginDateUst, fEndDateUst)) - jack_error("JackAudioDriver::ProcessGraphAsync: Process error"); - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); - if (ProcessSlaves() < 0) - jack_error("JackAudioDriver::ProcessGraphAsync: ProcessSlaves error"); + jack_error("JackAudioDriver::ProcessGraphAsyncMaster: Process error"); + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) + jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ResumeRefNum error"); + + if (ProcessReadSlaves() < 0) + jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessReadSlaves error"); + + if (ProcessWriteSlaves() < 0) + jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessWriteSlaves error"); +} + +void JackAudioDriver::ProcessGraphAsyncSlave() +{ + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) + jack_error("JackAudioDriver::ProcessGraphAsyncSlave: ResumeRefNum error"); } -int JackAudioDriver::ProcessGraphSync() +int JackAudioDriver::ProcessGraphSyncMaster() { int res = 0; // fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle if (fEngine->Process(fBeginDateUst, fEndDateUst)) { - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); - if (ProcessSlaves() < 0) { - jack_error("JackAudioDriver::ProcessGraphSync: ProcessSlaves error, engine may now behave abnormally!!"); + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + jack_error("JackAudioDriver::ProcessGraphSyncMaster: ResumeRefNum error"); res = -1; } + + if (ProcessReadSlaves() < 0) { + jack_error("JackAudioDriver::ProcessGraphSync: ProcessReadSlaves error, engine may now behave abnormally!!"); + res = -1; + } + + if (ProcessWriteSlaves() < 0) { + jack_error("JackAudioDriver::ProcessGraphSync: ProcessWriteSlaves error, engine may now behave abnormally!!"); + res = -1; + } + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { jack_error("JackAudioDriver::ProcessGraphSync: SuspendRefNum error, engine may now behave abnormally!!"); res = -1; @@ -312,6 +335,11 @@ int JackAudioDriver::ProcessGraphSync() return res; } +int JackAudioDriver::ProcessGraphSyncSlave() +{ + return fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); +} + int JackAudioDriver::Start() { int res = JackDriver::Start(); diff --git a/common/JackAudioDriver.h b/common/JackAudioDriver.h index 8eaca692..cb0ebefe 100644 --- a/common/JackAudioDriver.h +++ b/common/JackAudioDriver.h @@ -35,8 +35,12 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver protected: - void ProcessGraphAsync(); - int ProcessGraphSync(); + void ProcessGraphAsyncMaster(); + void ProcessGraphAsyncSlave(); + + int ProcessGraphSyncMaster(); + int ProcessGraphSyncSlave(); + void WaitUntilNextCycle(); virtual int ProcessAsync(); diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index 657524bd..77b3850e 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -282,19 +282,42 @@ void JackDriver::RemoveSlave(JackDriverInterface* slave) fSlaveList.remove(slave); } -int JackDriver::ProcessSlaves() +int JackDriver::ProcessReadSlaves() { int res = 0; list::const_iterator it; for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { JackDriverInterface* slave = *it; - if (slave->Process() < 0) + if (slave->ProcessRead() < 0) res = -1; } return res; } +int JackDriver::ProcessWriteSlaves() +{ + int res = 0; + list::const_iterator it; + for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { + JackDriverInterface* slave = *it; + if (slave->ProcessWrite() < 0) + res = -1; + + } + return res; +} + +int JackDriver::ProcessRead() +{ + return 0; +} + +int JackDriver::ProcessWrite() +{ + return 0; +} + int JackDriver::Process() { return 0; diff --git a/common/JackDriver.h b/common/JackDriver.h index 68f937c2..e619f6e4 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -34,6 +34,7 @@ namespace Jack class JackLockedEngine; class JackGraphManager; struct JackEngineControl; +class JackSlaveDriverInterface; /*! \brief The base interface for drivers. @@ -91,10 +92,17 @@ class SERVER_EXPORT JackDriverInterface virtual void SetMaster(bool onoff) = 0; virtual bool GetMaster() = 0; + virtual void AddSlave(JackDriverInterface* slave) = 0; virtual void RemoveSlave(JackDriverInterface* slave) = 0; + virtual std::list GetSlaves() = 0; - virtual int ProcessSlaves() = 0; + + virtual int ProcessReadSlaves() = 0; + virtual int ProcessWriteSlaves() = 0; + + virtual int ProcessRead() = 0; + virtual int ProcessWrite() = 0; virtual bool IsRealTime() const = 0; virtual bool IsRunning() const = 0; @@ -159,11 +167,11 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface void AddSlave(JackDriverInterface* slave); void RemoveSlave(JackDriverInterface* slave); + std::list GetSlaves() { return fSlaveList; } - int ProcessSlaves(); virtual int Open(); @@ -200,10 +208,17 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface virtual int Write(); virtual int Start(); - virtual int StartSlaves(); virtual int Stop(); + + virtual int StartSlaves(); virtual int StopSlaves(); + int ProcessReadSlaves(); + int ProcessWriteSlaves(); + + int ProcessRead(); + int ProcessWrite(); + virtual bool IsFixedBufferSize(); virtual int SetBufferSize(jack_nframes_t buffer_size); virtual int SetSampleRate(jack_nframes_t sample_rate); @@ -217,6 +232,19 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface }; +/* +class SERVER_EXPORT JackSlaveDriverInterface +{ + + public: + + virtual int ProcessRead() { return 0; } + virtual int ProcessWrite() { return 0; } + +}; + +*/ + } // end of namespace #endif diff --git a/common/JackFreewheelDriver.cpp b/common/JackFreewheelDriver.cpp index c28e30c3..2928b211 100644 --- a/common/JackFreewheelDriver.cpp +++ b/common/JackFreewheelDriver.cpp @@ -28,26 +28,72 @@ namespace Jack int JackFreewheelDriver::Process() { - if (fIsMaster) { - jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs); - JackDriver::CycleTakeBeginTime(); - fEngine->Process(fBeginDateUst, fEndDateUst); - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients + int res = 0; + + jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs); + JackDriver::CycleTakeBeginTime(); + + if (fEngine->Process(fBeginDateUst, fEndDateUst)) { + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable)) { // Signal all clients + jack_error("JackFreewheelDriver::Process: ResumeRefNum error"); + res = -1; + } + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, FREEWHEEL_DRIVER_TIMEOUT * 1000000) < 0) { // Wait for all clients to finish for 10 sec - jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); + jack_error("JackFreewheelDriver::ProcessSync: SuspendRefNum error"); /* We have a client time-out error, but still continue to process, until a better recovery strategy is chosen */ return 0; } - } else { - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients - if (fEngineControl->fSyncMode) { - if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { - jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); - return -1; - } - } + + } else { // Graph not finished: do not activate it + jack_error("JackFreewheelDriver::Process: Process error"); + res = -1; + } + + return res; +} + +int JackFreewheelDriver::ProcessRead() +{ + return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync(); +} + +int JackFreewheelDriver::ProcessWrite() +{ + return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync(); +} + +int JackFreewheelDriver::ProcessReadSync() +{ + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { // Signal all clients + jack_error("JackFreewheelDriver::ProcessReadSync: ResumeRefNum error"); + return -1; + } + return 0; +} + +int JackFreewheelDriver::ProcessWriteSync() +{ + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { + jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); + return -1; + } + return 0; +} + +int JackFreewheelDriver::ProcessReadAsync() +{ + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { // Signal all clients + jack_error("JackFreewheelDriver::ProcessReadAsync: ResumeRefNum error"); + return -1; } return 0; } +int JackFreewheelDriver::ProcessWriteAsync() +{ + return 0; +} + } // end of namespace diff --git a/common/JackFreewheelDriver.h b/common/JackFreewheelDriver.h index b988ffb0..02a9cf76 100644 --- a/common/JackFreewheelDriver.h +++ b/common/JackFreewheelDriver.h @@ -46,6 +46,16 @@ class JackFreewheelDriver : public JackDriver } int Process(); + + int ProcessRead(); + int ProcessWrite(); + + int ProcessReadSync(); + int ProcessWriteSync(); + + int ProcessReadAsync(); + int ProcessWriteAsync(); + }; } // end of namespace diff --git a/common/JackMidiDriver.cpp b/common/JackMidiDriver.cpp index 454f046d..a2fffa83 100644 --- a/common/JackMidiDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -148,56 +148,24 @@ int JackMidiDriver::ProcessNull() return 0; } -/* -int JackMidiDriver::Process() +int JackMidiDriver::ProcessRead() { - if (Read() < 0) { - jack_error("JackMidiDriver::Process: read error, skip cycle"); - return 0; // Skip cycle, but continue processing... - } - - if (fEngineControl->fSyncMode) { - int res = 0; - if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { - jack_error("JackMidiDriver::Process - ResumeRefNum error"); - res = -1; - } - if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, - DRIVER_TIMEOUT_FACTOR * - fEngineControl->fTimeOutUsecs) < 0) { - jack_error("JackMidiDriver::Process - SuspendRefNum error"); - res = -1; - } - if (Write() < 0) { - jack_error("JackMidiDriver::Process - Write error"); - } - return res; - } - - // Not in sync mode - - if (Write() < 0) { - jack_error("JackMidiDriver::Process - Write error"); - } else { - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); - } - return 0; + return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync(); } -*/ -int JackMidiDriver::Process() +int JackMidiDriver::ProcessWrite() { - return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync(); + return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync(); } -int JackMidiDriver::ProcessSync() +int JackMidiDriver::ProcessReadSync() { int res = 0; // Read input buffers for the current cycle if (Read() < 0) { jack_error("JackMidiDriver::ProcessSync: read error, skip cycle"); - return 0; // Skip cycle, but continue processing... + res = -1; } if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { @@ -205,6 +173,13 @@ int JackMidiDriver::ProcessSync() res = -1; } + return res; +} + +int JackMidiDriver::ProcessWriteSync() +{ + int res = 0; + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { @@ -215,24 +190,26 @@ int JackMidiDriver::ProcessSync() // Write output buffers from the current cycle if (Write() < 0) { jack_error("JackMidiDriver::ProcessSync - Write error"); + res = -1; } return res; } -int JackMidiDriver::ProcessAsync() +int JackMidiDriver::ProcessReadAsync() { int res = 0; // Read input buffers for the current cycle if (Read() < 0) { jack_error("JackMidiDriver::ProcessAsync: read error, skip cycle"); - return 0; // Skip cycle, but continue processing... + res = -1; } // Write output buffers from the previous cycle if (Write() < 0) { jack_error("JackMidiDriver::ProcessAsync - Write error"); + res = -1; } if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { @@ -243,6 +220,11 @@ int JackMidiDriver::ProcessAsync() return res; } +int JackMidiDriver::ProcessWriteAsync() +{ + return 0; +} + JackMidiBuffer* JackMidiDriver::GetInputBuffer(int port_index) { assert(fCapturePortList[port_index]); diff --git a/common/JackMidiDriver.h b/common/JackMidiDriver.h index 1ce627d3..45fe484c 100644 --- a/common/JackMidiDriver.h +++ b/common/JackMidiDriver.h @@ -48,6 +48,12 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver JackMidiBuffer* GetInputBuffer(int port_index); JackMidiBuffer* GetOutputBuffer(int port_index); + virtual int ProcessReadSync(); + virtual int ProcessWriteSync(); + + virtual int ProcessReadAsync(); + virtual int ProcessWriteAsync(); + public: JackMidiDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table); @@ -63,9 +69,9 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver jack_nframes_t capture_latency, jack_nframes_t playback_latency); - virtual int Process(); - virtual int ProcessSync(); - virtual int ProcessAsync(); + virtual int ProcessRead(); + virtual int ProcessWrite(); + virtual int ProcessNull(); virtual int Attach(); diff --git a/common/JackThreadedDriver.cpp b/common/JackThreadedDriver.cpp index 88323fe5..62260e59 100644 --- a/common/JackThreadedDriver.cpp +++ b/common/JackThreadedDriver.cpp @@ -127,9 +127,24 @@ void JackThreadedDriver::RemoveSlave(JackDriverInterface* slave) fDriver->RemoveSlave(slave); } -int JackThreadedDriver::ProcessSlaves() +int JackThreadedDriver::ProcessReadSlaves() { - return fDriver->ProcessSlaves(); + return fDriver->ProcessReadSlaves(); +} + +int JackThreadedDriver::ProcessWriteSlaves() +{ + return fDriver->ProcessWriteSlaves(); +} + +int JackThreadedDriver::ProcessRead() +{ + return fDriver->ProcessRead(); +} + +int JackThreadedDriver::ProcessWrite() +{ + return fDriver->ProcessWrite(); } std::list JackThreadedDriver::GetSlaves() diff --git a/common/JackThreadedDriver.h b/common/JackThreadedDriver.h index 92ec1d26..9d4876b1 100644 --- a/common/JackThreadedDriver.h +++ b/common/JackThreadedDriver.h @@ -89,10 +89,17 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi virtual void SetMaster(bool onoff); virtual bool GetMaster(); + virtual void AddSlave(JackDriverInterface* slave); virtual void RemoveSlave(JackDriverInterface* slave); + virtual std::list GetSlaves(); - virtual int ProcessSlaves(); + + virtual int ProcessReadSlaves(); + virtual int ProcessWriteSlaves(); + + virtual int ProcessRead(); + virtual int ProcessWrite(); virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2); virtual JackClientControl* GetClientControl() const; From faf29128cf7925735ac671ae50dfe55fff89639b Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Fri, 25 Mar 2011 18:40:14 +0100 Subject: [PATCH 6/7] Cleanup JackCoreAudioAdapter. --- macosx/coreaudio/JackCoreAudioAdapter.cpp | 67 +++++++++++------------ macosx/coreaudio/JackCoreAudioDriver.cpp | 11 ++-- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/macosx/coreaudio/JackCoreAudioAdapter.cpp b/macosx/coreaudio/JackCoreAudioAdapter.cpp index c1e9dc5e..d086a877 100644 --- a/macosx/coreaudio/JackCoreAudioAdapter.cpp +++ b/macosx/coreaudio/JackCoreAudioAdapter.cpp @@ -168,7 +168,7 @@ OSStatus JackCoreAudioAdapter::SRNotificationCallback(AudioDeviceID inDevice, switch (inPropertyID) { case kAudioDevicePropertyNominalSampleRate: { - jack_log("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate"); + jack_log("JackCoreAudioAdapter::SRNotificationCallback kAudioDevicePropertyNominalSampleRate"); driver->fState = true; break; } @@ -430,12 +430,15 @@ OSStatus JackCoreAudioAdapter::GetDefaultDevice(AudioDeviceID* id) jack_log("GetDefaultDevice: input = %ld output = %ld", inDefault, outDefault); // Get the device only if default input and output are the same - if (inDefault == outDefault) { - *id = inDefault; - return noErr; - } else { + if (inDefault != outDefault) { jack_error("Default input and output devices are not the same !!"); return kAudioHardwareBadDeviceError; + } else if (inDefault == 0) { + jack_error("Default input and output devices are null !!"); + return kAudioHardwareBadDeviceError; + } else { + *id = inDefault; + return noErr; } } @@ -444,20 +447,16 @@ OSStatus JackCoreAudioAdapter::GetTotalChannels(AudioDeviceID device, int& chann OSStatus err = noErr; UInt32 outSize; Boolean outWritable; - AudioBufferList* bufferList = 0; channelCount = 0; err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable); if (err == noErr) { - bufferList = (AudioBufferList*)malloc(outSize); + AudioBufferList bufferList[outSize]; err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList); if (err == noErr) { for (unsigned int i = 0; i < bufferList->mNumberBuffers; i++) channelCount += bufferList->mBuffers[i].mNumberChannels; } - - if (bufferList) - free(bufferList); } return err; @@ -604,7 +603,7 @@ int JackCoreAudioAdapter::SetupDevices(const char* capture_driver_uid, // Use default driver in duplex mode } else { - jack_log("JackCoreAudioDriver::Open default driver"); + jack_log("JackCoreAudioAdapter::Open default driver"); if (GetDefaultDevice(&fDeviceID) != noErr) { jack_error("Cannot open default device in duplex mode, so aggregate default input and default output"); @@ -1030,14 +1029,14 @@ OSStatus JackCoreAudioAdapter::DestroyAggregateDevice() osErr = AudioObjectGetPropertyDataSize(fPluginID, &pluginAOPA, 0, NULL, &outDataSize); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::DestroyAggregateDevice : AudioObjectGetPropertyDataSize error"); + jack_error("JackCoreAudioAdapter::DestroyAggregateDevice : AudioObjectGetPropertyDataSize error"); printError(osErr); return osErr; } osErr = AudioObjectGetPropertyData(fPluginID, &pluginAOPA, 0, NULL, &outDataSize, &fDeviceID); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::DestroyAggregateDevice : AudioObjectGetPropertyData error"); + jack_error("JackCoreAudioAdapter::DestroyAggregateDevice : AudioObjectGetPropertyData error"); printError(osErr); return osErr; } @@ -1115,18 +1114,18 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca for (UInt32 i = 0; i < captureDeviceID.size(); i++) { if (SetupSampleRateAux(captureDeviceID[i], samplerate) < 0) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : cannot set SR of input device"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : cannot set SR of input device"); } else { // Check clock domain osErr = AudioDeviceGetProperty(captureDeviceID[i], 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyClockDomain, &outSize, &clockdomain); if (osErr != 0) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : kAudioDevicePropertyClockDomain error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : kAudioDevicePropertyClockDomain error"); printError(osErr); } else { keptclockdomain = (keptclockdomain == 0) ? clockdomain : keptclockdomain; - jack_log("JackCoreAudioDriver::CreateAggregateDevice : input clockdomain = %d", clockdomain); + jack_log("JackCoreAudioAdapter::CreateAggregateDevice : input clockdomain = %d", clockdomain); if (clockdomain != 0 && clockdomain != keptclockdomain) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : devices do not share the same clock!! clock drift compensation would be needed..."); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : devices do not share the same clock!! clock drift compensation would be needed..."); need_clock_drift_compensation = true; } } @@ -1135,18 +1134,18 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca for (UInt32 i = 0; i < playbackDeviceID.size(); i++) { if (SetupSampleRateAux(playbackDeviceID[i], samplerate) < 0) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : cannot set SR of output device"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : cannot set SR of output device"); } else { // Check clock domain osErr = AudioDeviceGetProperty(playbackDeviceID[i], 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyClockDomain, &outSize, &clockdomain); if (osErr != 0) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : kAudioDevicePropertyClockDomain error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : kAudioDevicePropertyClockDomain error"); printError(osErr); } else { keptclockdomain = (keptclockdomain == 0) ? clockdomain : keptclockdomain; - jack_log("JackCoreAudioDriver::CreateAggregateDevice : output clockdomain = %d", clockdomain); + jack_log("JackCoreAudioAdapter::CreateAggregateDevice : output clockdomain = %d", clockdomain); if (clockdomain != 0 && clockdomain != keptclockdomain) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : devices do not share the same clock!! clock drift compensation would be needed..."); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : devices do not share the same clock!! clock drift compensation would be needed..."); need_clock_drift_compensation = true; } } @@ -1175,7 +1174,7 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca osErr = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyPlugInForBundleID, &outSize, &outWritable); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioHardwareGetPropertyInfo kAudioHardwarePropertyPlugInForBundleID error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioHardwareGetPropertyInfo kAudioHardwarePropertyPlugInForBundleID error"); printError(osErr); return osErr; } @@ -1191,7 +1190,7 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca osErr = AudioHardwareGetProperty(kAudioHardwarePropertyPlugInForBundleID, &outSize, &pluginAVT); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioHardwareGetProperty kAudioHardwarePropertyPlugInForBundleID error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioHardwareGetProperty kAudioHardwarePropertyPlugInForBundleID error"); printError(osErr); return osErr; } @@ -1218,13 +1217,13 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca SInt32 system; Gestalt(gestaltSystemVersion, &system); - jack_log("JackCoreAudioDriver::CreateAggregateDevice : system version = %x limit = %x", system, 0x00001054); + jack_log("JackCoreAudioAdapter::CreateAggregateDevice : system version = %x limit = %x", system, 0x00001054); // Starting with 10.5.4 systems, the AD can be internal... (better) if (system < 0x00001054) { - jack_log("JackCoreAudioDriver::CreateAggregateDevice : public aggregate device...."); + jack_log("JackCoreAudioAdapter::CreateAggregateDevice : public aggregate device...."); } else { - jack_log("JackCoreAudioDriver::CreateAggregateDevice : private aggregate device...."); + jack_log("JackCoreAudioAdapter::CreateAggregateDevice : private aggregate device...."); CFDictionaryAddValue(aggDeviceDict, CFSTR(kAudioAggregateDeviceIsPrivateKey), AggregateDeviceNumberRef); } @@ -1306,14 +1305,14 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca osErr = AudioObjectGetPropertyDataSize(fPluginID, &pluginAOPA, 0, NULL, &outDataSize); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioObjectGetPropertyDataSize error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioObjectGetPropertyDataSize error"); printError(osErr); goto error; } osErr = AudioObjectGetPropertyData(fPluginID, &pluginAOPA, sizeof(aggDeviceDict), &aggDeviceDict, &outDataSize, outAggregateDevice); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioObjectGetPropertyData error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioObjectGetPropertyData error"); printError(osErr); goto error; } @@ -1332,7 +1331,7 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca outDataSize = sizeof(CFMutableArrayRef); osErr = AudioObjectSetPropertyData(*outAggregateDevice, &pluginAOPA, 0, NULL, outDataSize, &subDevicesArray); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioObjectSetPropertyData for sub-device list error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioObjectSetPropertyData for sub-device list error"); printError(osErr); goto error; } @@ -1352,7 +1351,7 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca outDataSize = sizeof(CFStringRef); osErr = AudioObjectSetPropertyData(*outAggregateDevice, &pluginAOPA, 0, NULL, outDataSize, &captureDeviceUID[0]); // First apture is master... if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice : AudioObjectSetPropertyData for master device error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice : AudioObjectSetPropertyData for master device error"); printError(osErr); goto error; } @@ -1370,19 +1369,19 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca // Get the property data size osErr = AudioObjectGetPropertyDataSize(*outAggregateDevice, &theAddressOwned, theQualifierDataSize, theQualifierData, &outSize); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice kAudioObjectPropertyOwnedObjects error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice kAudioObjectPropertyOwnedObjects error"); printError(osErr); } // Calculate the number of object IDs subDevicesNum = outSize / sizeof(AudioObjectID); - jack_info("JackCoreAudioDriver::CreateAggregateDevice clock drift compensation, number of sub-devices = %d", subDevicesNum); + jack_info("JackCoreAudioAdapter::CreateAggregateDevice clock drift compensation, number of sub-devices = %d", subDevicesNum); AudioObjectID subDevices[subDevicesNum]; outSize = sizeof(subDevices); osErr = AudioObjectGetPropertyData(*outAggregateDevice, &theAddressOwned, theQualifierDataSize, theQualifierData, &outSize, subDevices); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice kAudioObjectPropertyOwnedObjects error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice kAudioObjectPropertyOwnedObjects error"); printError(osErr); } @@ -1391,7 +1390,7 @@ OSStatus JackCoreAudioAdapter::CreateAggregateDeviceAux(vector ca UInt32 theDriftCompensationValue = 1; osErr = AudioObjectSetPropertyData(subDevices[index], &theAddressDrift, 0, NULL, sizeof(UInt32), &theDriftCompensationValue); if (osErr != noErr) { - jack_error("JackCoreAudioDriver::CreateAggregateDevice kAudioSubDevicePropertyDriftCompensation error"); + jack_error("JackCoreAudioAdapter::CreateAggregateDevice kAudioSubDevicePropertyDriftCompensation error"); printError(osErr); } } diff --git a/macosx/coreaudio/JackCoreAudioDriver.cpp b/macosx/coreaudio/JackCoreAudioDriver.cpp index 83806646..383babf5 100644 --- a/macosx/coreaudio/JackCoreAudioDriver.cpp +++ b/macosx/coreaudio/JackCoreAudioDriver.cpp @@ -386,12 +386,15 @@ OSStatus JackCoreAudioDriver::GetDefaultDevice(AudioDeviceID* id) jack_log("GetDefaultDevice: input = %ld output = %ld", inDefault, outDefault); // Get the device only if default input and output are the same - if (inDefault == outDefault) { - *id = inDefault; - return noErr; - } else { + if (inDefault != outDefault) { jack_error("Default input and output devices are not the same !!"); return kAudioHardwareBadDeviceError; + } else if (inDefault == 0) { + jack_error("Default input and output devices are null !!"); + return kAudioHardwareBadDeviceError; + } else { + *id = inDefault; + return noErr; } } From 03e695ba1e3af55d685f58b534f4ada1cc592185 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Sat, 26 Mar 2011 12:52:52 +0100 Subject: [PATCH 7/7] Correct loopback driver for new activation model. --- common/JackDriver.h | 13 --------- common/JackLoopbackDriver.cpp | 55 ++++++++++++++++++++++++++++++----- common/JackLoopbackDriver.h | 11 ++++++- common/JackMidiDriver.cpp | 14 ++++----- 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/common/JackDriver.h b/common/JackDriver.h index e619f6e4..45d695af 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -232,19 +232,6 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface }; -/* -class SERVER_EXPORT JackSlaveDriverInterface -{ - - public: - - virtual int ProcessRead() { return 0; } - virtual int ProcessWrite() { return 0; } - -}; - -*/ - } // end of namespace #endif diff --git a/common/JackLoopbackDriver.cpp b/common/JackLoopbackDriver.cpp index e91cce1e..07778417 100644 --- a/common/JackLoopbackDriver.cpp +++ b/common/JackLoopbackDriver.cpp @@ -30,20 +30,61 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. namespace Jack { -int JackLoopbackDriver::Process() +int JackLoopbackDriver::ProcessRead() { + return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync(); +} + +int JackLoopbackDriver::ProcessWrite() +{ + return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync(); +} + +int JackLoopbackDriver::ProcessReadSync() +{ + int res = 0; + // Loopback copy for (int i = 0; i < fCaptureChannels; i++) { memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); } - fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients - if (fEngineControl->fSyncMode) { - if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { - jack_error("JackLoopbackDriver::ProcessSync SuspendRefNum error"); - return -1; - } + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error"); + res = -1; + } + + return res; +} + +int JackLoopbackDriver::ProcessWriteSync() +{ + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { + jack_error("JackLoopbackDriver::ProcessWriteSync SuspendRefNum error"); + return -1; + } + return 0; +} + +int JackLoopbackDriver::ProcessReadAsync() +{ + int res = 0; + + // Loopback copy + for (int i = 0; i < fCaptureChannels; i++) { + memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); + } + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error"); + res = -1; } + + return res; +} + +int JackLoopbackDriver::ProcessWriteAsync() +{ return 0; } diff --git a/common/JackLoopbackDriver.h b/common/JackLoopbackDriver.h index 5c542e3a..8fe22266 100644 --- a/common/JackLoopbackDriver.h +++ b/common/JackLoopbackDriver.h @@ -33,6 +33,14 @@ namespace Jack class JackLoopbackDriver : public JackAudioDriver { + private: + + virtual int ProcessReadSync(); + virtual int ProcessWriteSync(); + + virtual int ProcessReadAsync(); + virtual int ProcessWriteAsync(); + public: JackLoopbackDriver(JackLockedEngine* engine, JackSynchro* table) @@ -41,7 +49,8 @@ class JackLoopbackDriver : public JackAudioDriver virtual ~JackLoopbackDriver() {} - int Process(); + virtual int ProcessRead(); + virtual int ProcessWrite(); }; } // end of namespace diff --git a/common/JackMidiDriver.cpp b/common/JackMidiDriver.cpp index a2fffa83..4de11989 100644 --- a/common/JackMidiDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -164,12 +164,12 @@ int JackMidiDriver::ProcessReadSync() // Read input buffers for the current cycle if (Read() < 0) { - jack_error("JackMidiDriver::ProcessSync: read error, skip cycle"); + jack_error("JackMidiDriver::ProcessReadSync: read error, skip cycle"); res = -1; } if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { - jack_error("JackMidiDriver::ProcessSync - ResumeRefNum error"); + jack_error("JackMidiDriver::ProcessReadSync - ResumeRefNum error"); res = -1; } @@ -183,13 +183,13 @@ int JackMidiDriver::ProcessWriteSync() if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { - jack_error("JackMidiDriver::ProcessSync - SuspendRefNum error"); + jack_error("JackMidiDriver::ProcessWriteSync - SuspendRefNum error"); res = -1; } // Write output buffers from the current cycle if (Write() < 0) { - jack_error("JackMidiDriver::ProcessSync - Write error"); + jack_error("JackMidiDriver::ProcessWriteSync - Write error"); res = -1; } @@ -202,18 +202,18 @@ int JackMidiDriver::ProcessReadAsync() // Read input buffers for the current cycle if (Read() < 0) { - jack_error("JackMidiDriver::ProcessAsync: read error, skip cycle"); + jack_error("JackMidiDriver::ProcessReadAsync: read error, skip cycle"); res = -1; } // Write output buffers from the previous cycle if (Write() < 0) { - jack_error("JackMidiDriver::ProcessAsync - Write error"); + jack_error("JackMidiDriver::ProcessReadAsync - Write error"); res = -1; } if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { - jack_error("JackMidiDriver::ProcessAsync - ResumeRefNum error"); + jack_error("JackMidiDriver::ProcessReadAsync - ResumeRefNum error"); res = -1; }