changed default host API logic to use first successfully initialized host api with a defined default input or output device. resolves ticket #49

This commit is contained in:
rossb 2011-08-18 03:31:51 +00:00
commit 58015f7b17
4 changed files with 26 additions and 15 deletions

View file

@ -116,6 +116,7 @@ void PaUtil_SetLastHostErrorInfo( PaHostApiTypeId hostApiType, long errorCode,
static PaUtilHostApiRepresentation **hostApis_ = 0;
static int hostApisCount_ = 0;
static int defaultHostApiIndex_ = 0;
static int initializationCount_ = 0;
static int deviceCount_ = 0;
@ -172,6 +173,7 @@ static PaError InitializeHostApis( void )
}
hostApisCount_ = 0;
defaultHostApiIndex_ = -1; /* indicates that we haven't determined the default host API yet */
deviceCount_ = 0;
baseDeviceIndex = 0;
@ -193,6 +195,16 @@ static PaError InitializeHostApis( void )
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
/* the first successfully initialized host API with at least one input *or*
output device is used as the default host API.
*/
if( (defaultHostApiIndex_ == -1) &&
( hostApi->info.defaultInputDevice != paNoDevice
|| hostApi->info.defaultOutputDevice != paNoDevice ) )
{
defaultHostApiIndex_ = hostApisCount_;
}
hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex;
if( hostApi->info.defaultInputDevice != paNoDevice )
@ -208,6 +220,10 @@ static PaError InitializeHostApis( void )
}
}
/* if no host APIs have devices, the default host API is the first initialized host API */
if( defaultHostApiIndex_ == -1 )
defaultHostApiIndex_ = 0;
return result;
error:
@ -525,7 +541,7 @@ PaHostApiIndex Pa_GetDefaultHostApi( void )
}
else
{
result = paDefaultHostApiIndex;
result = defaultHostApiIndex_;
/* internal consistency check: make sure that the default host api
index is within range */

View file

@ -294,22 +294,21 @@ typedef PaError PaUtilHostApiInitializer( PaUtilHostApiRepresentation**, PaHostA
/** paHostApiInitializers is a NULL-terminated array of host API initialization
functions. These functions are called by pa_front.c to initialize the host APIs
when the client calls Pa_Initialize().
when the client calls Pa_Initialize().
The initialization functions are invoked in order.
There is a platform specific file which defines paHostApiInitializers for that
The first successfully initialized host API that has a default input *or* output
device is used as the default PortAudio host API. This is based on the logic that
there is only one default host API, and it must contain the default input and output
devices (if defined).
There is a platform specific file that defines paHostApiInitializers for that
platform, pa_win/pa_win_hostapis.c contains the Win32 definitions for example.
*/
extern PaUtilHostApiInitializer *paHostApiInitializers[];
/** The index of the default host API in the paHostApiInitializers array.
There is a platform specific file which defines paDefaultHostApiIndex for that
platform, see pa_win/pa_win_hostapis.c for example.
*/
extern int paDefaultHostApiIndex;
#ifdef __cplusplus
}
#endif /* __cplusplus */

View file

@ -101,5 +101,3 @@ PaUtilHostApiInitializer *paHostApiInitializers[] =
0 /* NULL terminated array */
};
int paDefaultHostApiIndex = 0;

View file

@ -100,5 +100,3 @@ PaUtilHostApiInitializer *paHostApiInitializers[] =
};
int paDefaultHostApiIndex = 0;