]> Repos - portaudio/commitdiff
changed default host API logic to use first successfully initialized host api with...
authorrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Thu, 18 Aug 2011 03:31:51 +0000 (03:31 +0000)
committerrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Thu, 18 Aug 2011 03:31:51 +0000 (03:31 +0000)
src/common/pa_front.c
src/common/pa_hostapi.h
src/os/unix/pa_unix_hostapis.c
src/os/win/pa_win_hostapis.c

index 8dfa27dfe0bf9a814979564dc6d62453a87a6436..6817727c79a107af40f18d3b519540ad0997a45b 100644 (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 */
index dda0f2786a9d9f951275821efb427f14c453fe81..cfbd521fe254f765964af68ca8ee1d18fd8d730b 100644 (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.
+
+ 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 which defines paHostApiInitializers for that
+ 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 */
index 2bafaa2756a4cc83488e0471815dcacbe5b850d4..ef56e818224598c41c4c844439802b3f8d117654 100644 (file)
@@ -101,5 +101,3 @@ PaUtilHostApiInitializer *paHostApiInitializers[] =
 
         0   /* NULL terminated array */
     };
-
-int paDefaultHostApiIndex = 0;
index 26fc55936f23e67a2c494f423bb4fbd5f7f720da..9c9927ab77ce201f0a4de3a2e75079c13f11b428 100644 (file)
@@ -100,5 +100,3 @@ PaUtilHostApiInitializer *paHostApiInitializers[] =
     };
 
 
-int paDefaultHostApiIndex = 0;
-