diff options
Diffstat (limited to '3rdparty/portaudio/src/os/unix')
-rw-r--r-- | 3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c | 18 | ||||
-rw-r--r-- | 3rdparty/portaudio/src/os/unix/pa_unix_util.c | 55 | ||||
-rw-r--r-- | 3rdparty/portaudio/src/os/unix/pa_unix_util.h | 22 |
3 files changed, 58 insertions, 37 deletions
diff --git a/3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c b/3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c index a9b4a05d7f4..95cd89b9d5f 100644 --- a/3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c +++ b/3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c @@ -26,13 +26,13 @@ */ /* - * The text above constitutes the entire PortAudio license; however, + * The text above constitutes the entire PortAudio license; however, * the PortAudio community also makes the following non-binding requests: * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. It is also - * requested that these non-binding requests be included along with the + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the * license above. */ @@ -43,8 +43,10 @@ #include "pa_hostapi.h" PaError PaJack_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); +PaError PaPulseAudio_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); PaError PaAlsa_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); PaError PaOSS_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); +PaError PaAudioIO_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); /* Added for IRIX, Pieter, oct 2, 2003: */ PaError PaSGI_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); /* Linux AudioScience HPI */ @@ -79,11 +81,15 @@ PaUtilHostApiInitializer *paHostApiInitializers[] = #endif /* __linux__ */ +#if PA_USE_AUDIOIO + PaAudioIO_Initialize, +#endif + #if PA_USE_JACK PaJack_Initialize, #endif /* Added for IRIX, Pieter, oct 2, 2003: */ -#if PA_USE_SGI +#if PA_USE_SGI PaSGI_Initialize, #endif @@ -95,6 +101,10 @@ PaUtilHostApiInitializer *paHostApiInitializers[] = PaMacCore_Initialize, #endif +#if PA_USE_PULSEAUDIO + PaPulseAudio_Initialize, +#endif + #if PA_USE_SKELETON PaSkeleton_Initialize, #endif diff --git a/3rdparty/portaudio/src/os/unix/pa_unix_util.c b/3rdparty/portaudio/src/os/unix/pa_unix_util.c index 17664eabf0a..5ad55e41d13 100644 --- a/3rdparty/portaudio/src/os/unix/pa_unix_util.c +++ b/3rdparty/portaudio/src/os/unix/pa_unix_util.c @@ -27,20 +27,20 @@ */ /* - * The text above constitutes the entire PortAudio license; however, + * The text above constitutes the entire PortAudio license; however, * the PortAudio community also makes the following non-binding requests: * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. It is also - * requested that these non-binding requests be included along with the + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the * license above. */ /** @file @ingroup unix_src */ - + #include <pthread.h> #include <unistd.h> #include <stdlib.h> @@ -71,9 +71,13 @@ static int numAllocations_ = 0; #endif -void *PaUtil_AllocateMemory( long size ) +void *PaUtil_AllocateZeroInitializedMemory( long size ) { + /* use { malloc(); memset() } instead of calloc() so that we get + the same alignment guarantee as malloc(). */ void *result = malloc( size ); + if ( result ) + memset( result, 0, size ); #if PA_TRACK_MEMORY if( result != NULL ) numAllocations_ += 1; @@ -129,7 +133,7 @@ void Pa_Sleep( long msec ) /* Discussion on the CoreAudio mailing list suggests that calling gettimeofday (or anything else in the BSD layer) is not real-time - safe, so we use mach_absolute_time on OSX. This implementation is + safe, so we use mach_absolute_time on OSX. This implementation is based on these two links: Technical Q&A QA1398 - Mach Absolute Time Units @@ -140,7 +144,7 @@ void Pa_Sleep( long msec ) */ /* Scaler to convert the result of mach_absolute_time to seconds */ -static double machSecondsConversionScaler_ = 0.0; +static double machSecondsConversionScaler_ = 0.0; #endif void PaUtil_InitializeClock( void ) @@ -160,7 +164,11 @@ PaTime PaUtil_GetTime( void ) return mach_absolute_time() * machSecondsConversionScaler_; #elif defined(HAVE_CLOCK_GETTIME) struct timespec tp; +#if defined(CLOCK_MONOTONIC) + clock_gettime(CLOCK_MONOTONIC, &tp); +#else clock_gettime(CLOCK_REALTIME, &tp); +#endif return (PaTime)(tp.tv_sec + tp.tv_nsec * 1e-9); #else struct timeval tv; @@ -193,8 +201,8 @@ PaError PaUtil_CancelThreading( PaUtilThreading *threading, int wait, PaError *e if( exitResult ) *exitResult = paNoError; - /* If pthread_cancel is not supported (Android platform) whole this function can lead to indefinite waiting if - working thread (callbackThread) has'n received any stop signals from outside, please keep + /* If pthread_cancel is not supported (Android platform) whole this function can lead to indefinite waiting if + working thread (callbackThread) has'n received any stop signals from outside, please keep this in mind when considering using PaUtil_CancelThreading */ #ifdef PTHREAD_CANCELED @@ -220,7 +228,7 @@ PaError PaUtil_CancelThreading( PaUtilThreading *threading, int wait, PaError *e } /* Threading */ -/* paUnixMainThread +/* paUnixMainThread * We have to be a bit careful with defining this global variable, * as explained below. */ #ifdef __APPLE__ @@ -231,12 +239,12 @@ PaError PaUtil_CancelThreading( PaUtilThreading *threading, int wait, PaError *e */ pthread_t paUnixMainThread = 0; #else -/*pthreads are opaque. We don't know that asigning it an int value +/*pthreads are opaque. We don't know that assigning it an int value always makes sense, so we don't initialize it unless we have to.*/ pthread_t paUnixMainThread = 0; #endif -PaError PaUnixThreading_Initialize() +PaError PaUnixThreading_Initialize( void ) { paUnixMainThread = pthread_self(); return paNoError; @@ -270,11 +278,16 @@ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void { PaError result = paNoError; pthread_attr_t attr; + pthread_condattr_t cattr; int started = 0; memset( self, 0, sizeof (PaUnixThread) ); PaUnixMutex_Initialize( &self->mtx ); - PA_ASSERT_CALL( pthread_cond_init( &self->cond, NULL ), 0 ); + PA_ASSERT_CALL( pthread_condattr_init( &cattr ), 0 ); +#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__) + PA_ASSERT_CALL( pthread_condattr_setclock( &cattr, CLOCK_MONOTONIC ), 0 ); +#endif + PA_ASSERT_CALL( pthread_cond_init( &self->cond, &cattr), 0 ); self->parentWaiting = 0 != waitForChild; @@ -300,7 +313,7 @@ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void PA_UNLESS( !pthread_attr_init( &attr ), paInternalError ); /* Priority relative to other processes */ - PA_UNLESS( !pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ), paInternalError ); + PA_UNLESS( !pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ), paInternalError ); PA_UNLESS( !pthread_create( &self->thread, &attr, threadFunc, threadArg ), paInternalError ); started = 1; @@ -350,7 +363,7 @@ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void pthread_getschedparam(self->thread, &policy, &spm); } } - + if( self->parentWaiting ) { PaTime till; @@ -513,15 +526,15 @@ PaError PaUnixMutex_Terminate( PaUnixMutex* self ) /** Lock mutex. * - * We're disabling thread cancellation while the thread is holding a lock, so mutexes are + * We're disabling thread cancellation while the thread is holding a lock, so mutexes are * properly unlocked at termination time. */ PaError PaUnixMutex_Lock( PaUnixMutex* self ) { PaError result = paNoError; - + #ifdef PTHREAD_CANCEL - int oldState; + int oldState; PA_ENSURE_SYSTEM( pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldState ), 0 ); #endif PA_ENSURE_SYSTEM( pthread_mutex_lock( &self->mtx ), 0 ); @@ -540,7 +553,7 @@ PaError PaUnixMutex_Unlock( PaUnixMutex* self ) PA_ENSURE_SYSTEM( pthread_mutex_unlock( &self->mtx ), 0 ); #ifdef PTHREAD_CANCEL - int oldState; + int oldState; PA_ENSURE_SYSTEM( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, &oldState ), 0 ); #endif @@ -595,7 +608,7 @@ static void *WatchdogFunc( void *userData ) while( 1 ) { double lowpassCoeff = 0.9, lowpassCoeff1 = 0.99999 - lowpassCoeff; - + /* Test before and after in case whatever underlying sleep call isn't interrupted by pthread_cancel */ pthread_testcancel(); Pa_Sleep( intervalMsec ); @@ -680,7 +693,7 @@ error: /* Pass on error code */ pres = malloc( sizeof (PaError) ); *pres = result; - + pthread_exit( pres ); } diff --git a/3rdparty/portaudio/src/os/unix/pa_unix_util.h b/3rdparty/portaudio/src/os/unix/pa_unix_util.h index d73c99c8fad..cc2fc04b855 100644 --- a/3rdparty/portaudio/src/os/unix/pa_unix_util.h +++ b/3rdparty/portaudio/src/os/unix/pa_unix_util.h @@ -27,13 +27,13 @@ */ /* - * The text above constitutes the entire PortAudio license; however, + * The text above constitutes the entire PortAudio license; however, * the PortAudio community also makes the following non-binding requests: * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. It is also - * requested that these non-binding requests be included along with the + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the * license above. */ @@ -44,6 +44,7 @@ #ifndef PA_UNIX_UTIL_H #define PA_UNIX_UTIL_H +#include "pa_util.h" #include "pa_cpuload.h" #include <assert.h> #include <pthread.h> @@ -64,14 +65,11 @@ extern "C" #define UNLIKELY(expr) (expr) #endif -#define STRINGIZE_HELPER(expr) #expr -#define STRINGIZE(expr) STRINGIZE_HELPER(expr) - #define PA_UNLESS(expr, code) \ do { \ if( UNLIKELY( (expr) == 0 ) ) \ { \ - PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZE( __LINE__ ) "\n" )); \ + PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " PA_STRINGIZE( __LINE__ ) "\n" )); \ result = (code); \ goto error; \ } \ @@ -84,7 +82,7 @@ static PaError paUtilErr_; /* Used with PA_ENSURE */ do { \ if( UNLIKELY( (paUtilErr_ = (expr)) < paNoError ) ) \ { \ - PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZE( __LINE__ ) "\n" )); \ + PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " PA_STRINGIZE( __LINE__ ) "\n" )); \ result = paUtilErr_; \ goto error; \ } \ @@ -103,7 +101,7 @@ static PaError paUtilErr_; /* Used with PA_ENSURE */ { \ PaUtil_SetLastHostErrorInfo( paALSA, paUtilErr_, strerror( paUtilErr_ ) ); \ } \ - PaUtil_DebugPrint( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZE( __LINE__ ) "\n" ); \ + PaUtil_DebugPrint( "Expression '" #expr "' failed in '" __FILE__ "', line: " PA_STRINGIZE( __LINE__ ) "\n" ); \ result = paUnanticipatedHostError; \ goto error; \ } \ @@ -157,7 +155,7 @@ typedef struct /** Initialize global threading state. */ -PaError PaUnixThreading_Initialize(); +PaError PaUnixThreading_Initialize( void ); /** Perish, passing on eventual error code. * @@ -182,7 +180,7 @@ PaError PaUnixThreading_Initialize(); /** Spawn a thread. * * Intended for spawning the callback thread from the main thread. This function can even block (for a certain - * time or indefinitely) untill notified by the callback thread (using PaUnixThread_NotifyParent), which can be + * time or indefinitely) until notified by the callback thread (using PaUnixThread_NotifyParent), which can be * useful in order to make sure that callback has commenced before returning from Pa_StartStream. * @param threadFunc: The function to be executed in the child thread. * @param waitForChild: If not 0, wait for child thread to call PaUnixThread_NotifyParent. Less than 0 means @@ -195,7 +193,7 @@ PaError PaUnixThread_New( PaUnixThread* self, void* (*threadFunc)( void* ), void /** Terminate thread. * - * @param wait: If true, request that background thread stop and wait untill it does, else cancel it. + * @param wait: If true, request that background thread stop and wait until it does, else cancel it. * @param exitResult: If non-null this will upon return contain the exit status of the thread. */ PaError PaUnixThread_Terminate( PaUnixThread* self, int wait, PaError* exitResult ); |