diff --git a/ChangeLog b/ChangeLog index fa364c4a..1537081d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,10 @@ Arnold Krille --------------------------- Jackdmp changes log --------------------------- + +2010-05-27 Stephane Letz + + * In JackCoreAudioDriver, move code called in MeasureCallback to be called once in IO thread. 2010-05-07 Stephane Letz diff --git a/common/JackError.cpp b/common/JackError.cpp index 905bbef8..5338bd3c 100644 --- a/common/JackError.cpp +++ b/common/JackError.cpp @@ -27,17 +27,15 @@ using namespace Jack; -void change_thread_log_function(jack_log_function_t log_function) +static bool change_thread_log_function(jack_log_function_t log_function) { - if (!jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function)) - { - jack_error("failed to set thread log function"); - } + return (jack_tls_get(JackGlobals::fKeyLogFunction) == NULL + && jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function)); } -SERVER_EXPORT void set_threaded_log_function() +SERVER_EXPORT bool set_threaded_log_function() { - change_thread_log_function(JackMessageBufferAdd); + return change_thread_log_function(JackMessageBufferAdd); } void jack_log_function(int level, const char *message) diff --git a/common/JackError.h b/common/JackError.h index e16a65b2..27a7e323 100644 --- a/common/JackError.h +++ b/common/JackError.h @@ -53,10 +53,9 @@ extern "C" typedef void (* jack_log_function_t)(int level, const char *message); - void change_thread_log_function(jack_log_function_t log_function); void jack_log_function(int level, const char *message); - SERVER_EXPORT void set_threaded_log_function(); + SERVER_EXPORT bool set_threaded_log_function(); #ifdef __cplusplus } diff --git a/macosx/coreaudio/JackCoreAudioDriver.cpp b/macosx/coreaudio/JackCoreAudioDriver.cpp index f4b24782..f1b62dc7 100644 --- a/macosx/coreaudio/JackCoreAudioDriver.cpp +++ b/macosx/coreaudio/JackCoreAudioDriver.cpp @@ -194,6 +194,22 @@ OSStatus JackCoreAudioDriver::Render(void *inRefCon, driver->fActionFags = ioActionFlags; driver->fCurrentTime = (AudioTimeStamp *)inTimeStamp; driver->fDriverOutputData = ioData; + + // Setup threadded based log function once... + if (set_threaded_log_function()) { + + jack_log("set_threaded_log_function"); + JackMachThread::GetParams(pthread_self(), &driver->fEngineControl->fPeriod, &driver->fEngineControl->fComputation, &driver->fEngineControl->fConstraint); + + if (driver->fComputationGrain > 0) { + jack_log("JackCoreAudioDriver::Render : RT thread computation setup to %d percent of period", int(driver->fComputationGrain * 100)); + driver->fEngineControl->fComputation = driver->fEngineControl->fPeriod * driver->fComputationGrain; + } + + // Signal waiting start function... + driver->fState = true; + } + driver->CycleTakeBeginTime(); return driver->Process(); } @@ -221,33 +237,6 @@ int JackCoreAudioDriver::Write() return 0; } -// Will run only once -OSStatus JackCoreAudioDriver::MeasureCallback(AudioDeviceID inDevice, - const AudioTimeStamp* inNow, - const AudioBufferList* inInputData, - const AudioTimeStamp* inInputTime, - AudioBufferList* outOutputData, - const AudioTimeStamp* inOutputTime, - void* inClientData) -{ - JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inClientData; - AudioDeviceStop(driver->fDeviceID, MeasureCallback); - - jack_log("JackCoreAudioDriver::MeasureCallback called"); - JackMachThread::GetParams(pthread_self(), &driver->fEngineControl->fPeriod, &driver->fEngineControl->fComputation, &driver->fEngineControl->fConstraint); - - if (driver->fComputationGrain > 0) { - jack_log("JackCoreAudioDriver::MeasureCallback : RT thread computation setup to %d percent of period", int(driver->fComputationGrain * 100)); - driver->fEngineControl->fComputation = driver->fEngineControl->fPeriod * driver->fComputationGrain; - } - - // Signal waiting start function... - driver->fState = true; - - // Setup threadded based log function - set_threaded_log_function(); - return noErr; -} OSStatus JackCoreAudioDriver::SRNotificationCallback(AudioDeviceID inDevice, UInt32 inChannel, @@ -1682,27 +1671,10 @@ int JackCoreAudioDriver::Start() { jack_log("JackCoreAudioDriver::Start"); JackAudioDriver::Start(); -/* -#ifdef MAC_OS_X_VERSION_10_5 - OSStatus err = AudioDeviceCreateIOProcID(fDeviceID, MeasureCallback, this, &fMesureCallbackID); -#else - OSStatus err = AudioDeviceAddIOProc(fDeviceID, MeasureCallback, this); -#endif -*/ - OSStatus err = AudioDeviceAddIOProc(fDeviceID, MeasureCallback, this); - - if (err != noErr) - return -1; - err = AudioOutputUnitStart(fAUHAL); + OSStatus err = AudioOutputUnitStart(fAUHAL); if (err != noErr) return -1; - - if ((err = AudioDeviceStart(fDeviceID, MeasureCallback)) != noErr) { - jack_error("Cannot start MeasureCallback"); - printError(err); - return -1; - } // Waiting for Measure callback to be called (= driver has started) fState = false; @@ -1724,15 +1696,6 @@ int JackCoreAudioDriver::Start() int JackCoreAudioDriver::Stop() { jack_log("JackCoreAudioDriver::Stop"); - AudioDeviceStop(fDeviceID, MeasureCallback); -/* -#ifdef MAC_OS_X_VERSION_10_5 - AudioDeviceDestroyIOProcID(fDeviceID, fMesureCallbackID); -#else - AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); -#endif -*/ - AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); return (AudioOutputUnitStop(fAUHAL) == noErr) ? 0 : -1; } diff --git a/macosx/coreaudio/JackCoreAudioDriver.h b/macosx/coreaudio/JackCoreAudioDriver.h index f17bbf19..9f827dfc 100644 --- a/macosx/coreaudio/JackCoreAudioDriver.h +++ b/macosx/coreaudio/JackCoreAudioDriver.h @@ -96,14 +96,6 @@ class JackCoreAudioDriver : public JackAudioDriver UInt32 inNumberFrames, AudioBufferList *ioData); - static OSStatus MeasureCallback(AudioDeviceID inDevice, - const AudioTimeStamp* inNow, - const AudioBufferList* inInputData, - const AudioTimeStamp* inInputTime, - AudioBufferList* outOutputData, - const AudioTimeStamp* inOutputTime, - void* inClientData); - static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput,