Changeset 1343
- Timestamp:
- 02/18/08 03:27:03 (6 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
portaudio/branches/v19-devel/src/hostapi/asio/pa_asio.cpp
r1230 r1343 78 78 synchronous full duplex double-buffered architecture of ASIO. 79 79 80 @todo check that CoInitialize()/CoUninitialize() are always correctly81 paired, even in error cases.82 83 80 @todo implement host api specific extension to set i/o buffer sizes in frames 84 81 … … 121 118 #include <string.h> 122 119 //#include <values.h> 120 #include <new> 123 121 124 122 #include <windows.h> … … 165 163 */ 166 164 167 /* external references */ 168 extern AsioDrivers* asioDrivers ; 169 bool loadAsioDriver(char *name); 165 166 /* external reference to ASIO SDK's asioDrivers. 167 168 This is a bit messy because we want to explicitly manage 169 allocation/deallocation of this structure, but some layers of the SDK 170 which we currently use (eg the implementation in asio.cpp) still 171 use this global version. 172 173 For now we keep it in sync with our local instance in the host 174 API representation structure, but later we should be able to remove 175 all dependence on it. 176 */ 177 extern AsioDrivers* asioDrivers; 170 178 171 179 172 180 /* We are trying to be compatible with CARBON but this has not been thoroughly tested. */ 173 /* not tested at all since new code was introduced. */181 /* not tested at all since new V19 code was introduced. */ 174 182 #define CARBON_COMPATIBLE (0) 175 176 177 183 178 184 … … 301 307 PaUtilAllocationGroup *allocations; 302 308 309 AsioDrivers *asioDrivers; 303 310 void *systemSpecific; 304 311 … … 324 331 allocated in <group>. 325 332 */ 326 static char **GetAsioDriverNames( Pa UtilAllocationGroup *group, long driverCount )333 static char **GetAsioDriverNames( PaAsioHostApiRepresentation *asioHostApi, PaUtilAllocationGroup *group, long driverCount ) 327 334 { 328 335 char **result = 0; … … 342 349 result[i] = result[0] + (32 * i); 343 350 344 asio Drivers->getDriverNames( result, driverCount );351 asioHostApi->asioDrivers->getDriverNames( result, driverCount ); 345 352 346 353 error: … … 953 960 is returned the driver will already be closed. 954 961 */ 955 static PaError LoadAsioDriver( const char *driverName,962 static PaError LoadAsioDriver( PaAsioHostApiRepresentation *asioHostApi, const char *driverName, 956 963 PaAsioDriverInfo *driverInfo, void *systemSpecific ) 957 964 { … … 960 967 int asioIsInitialized = 0; 961 968 962 if( !loadAsioDriver( const_cast<char*>(driverName) ) ) 969 /* @todo note that the V18 version always called CoInitialize() here to ensure 970 that COM was initialized before loading the driver. 971 probably the docs need to require clients to initialize COM in new threads? 972 */ 973 if( !asioHostApi->asioDrivers->loadDriver( const_cast<char*>(driverName) ) ) 963 974 { 964 975 result = paUnanticipatedHostError; … … 1040 1051 } 1041 1052 1053 asioHostApi->asioDrivers = 0; /* avoid surprises in our error handler below */ 1054 1042 1055 asioHostApi->allocations = PaUtil_CreateAllocationGroup(); 1043 1056 if( !asioHostApi->allocations ) … … 1046 1059 goto error; 1047 1060 } 1061 1062 /* Allocate the AsioDrivers() driver list (class from ASIO SDK) */ 1063 try 1064 { 1065 asioHostApi->asioDrivers = new AsioDrivers(); /* calls CoInitialize(0) */ 1066 } 1067 catch (std::bad_alloc) 1068 { 1069 asioHostApi->asioDrivers = 0; 1070 } 1071 /* some implementations of new (ie MSVC, see http://support.microsoft.com/?kbid=167733) 1072 don't throw std::bad_alloc, so we also explicitly test for a null return. */ 1073 if( asioHostApi->asioDrivers == 0 ) 1074 { 1075 result = paInsufficientMemory; 1076 goto error; 1077 } 1078 1079 asioDrivers = asioHostApi->asioDrivers; /* keep SDK global in sync until we stop depending on it */ 1048 1080 1049 1081 asioHostApi->systemSpecific = 0; … … 1060 1092 /* use desktop window as system specific ptr */ 1061 1093 asioHostApi->systemSpecific = GetDesktopWindow(); 1062 CoInitialize(NULL);1063 1094 #endif 1064 1065 /* MUST BE CHECKED : to force fragments loading on Mac */1066 loadAsioDriver( "dummy" );1067 1095 1068 1096 /* driverCount is the number of installed drivers - not necessarily 1069 1097 the number of installed physical devices. */ 1070 1098 #if MAC 1071 driverCount = asio Drivers->getNumFragments();1099 driverCount = asioHostApi->asioDrivers->getNumFragments(); 1072 1100 #elif WINDOWS 1073 driverCount = asio Drivers->asioGetNumDev();1101 driverCount = asioHostApi->asioDrivers->asioGetNumDev(); 1074 1102 #endif 1075 1103 1076 1104 if( driverCount > 0 ) 1077 1105 { 1078 names = GetAsioDriverNames( asioHostApi ->allocations, driverCount );1106 names = GetAsioDriverNames( asioHostApi, asioHostApi->allocations, driverCount ); 1079 1107 if( !names ) 1080 1108 { … … 1142 1170 1143 1171 /* Attempt to load the asio driver... */ 1144 if( LoadAsioDriver( names[i], &paAsioDriverInfo, asioHostApi->systemSpecific ) == paNoError )1172 if( LoadAsioDriver( asioHostApi, names[i], &paAsioDriverInfo, asioHostApi->systemSpecific ) == paNoError ) 1145 1173 { 1146 1174 PaAsioDeviceInfo *asioDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ]; … … 1312 1340 } 1313 1341 1342 delete asioHostApi->asioDrivers; 1343 asioDrivers = asioHostApi->asioDrivers; /* keep SDK global in sync until we stop depending on it */ 1344 1314 1345 PaUtil_FreeMemory( asioHostApi ); 1315 1346 } … … 1324 1355 /* 1325 1356 IMPLEMENT ME: 1326 - clean up any resources not handled by the allocation group 1357 - clean up any resources not handled by the allocation group (need to review if there are any) 1327 1358 */ 1328 1359 … … 1332 1363 PaUtil_DestroyAllocationGroup( asioHostApi->allocations ); 1333 1364 } 1365 1366 delete asioHostApi->asioDrivers; /* calls CoUninitialize() */ 1367 asioDrivers = asioHostApi->asioDrivers; /* keep SDK global in sync until we stop depending on it */ 1334 1368 1335 1369 PaUtil_FreeMemory( asioHostApi ); … … 1431 1465 if( asioHostApi->openAsioDeviceIndex == paNoDevice ) 1432 1466 { 1433 result = LoadAsioDriver( asioHostApi ->inheritedHostApiRep.deviceInfos[ asioDeviceIndex ]->name,1467 result = LoadAsioDriver( asioHostApi, asioHostApi->inheritedHostApiRep.deviceInfos[ asioDeviceIndex ]->name, 1434 1468 driverInfo, asioHostApi->systemSpecific ); 1435 1469 if( result != paNoError ) … … 1763 1797 rather than the ones in our device info structure which may be stale */ 1764 1798 1765 result = LoadAsioDriver( asioHostApi ->inheritedHostApiRep.deviceInfos[ asioDeviceIndex ]->name,1799 result = LoadAsioDriver( asioHostApi, asioHostApi->inheritedHostApiRep.deviceInfos[ asioDeviceIndex ]->name, 1766 1800 driverInfo, asioHostApi->systemSpecific ); 1767 1801 if( result == paNoError ) … … 2897 2931 asioDeviceInfo = (PaAsioDeviceInfo*)hostApi->deviceInfos[hostApiDevice]; 2898 2932 2899 if( !loadAsioDriver( const_cast<char*>(asioDeviceInfo->commonDeviceInfo.name) ) ) 2933 /* @todo note that the V18 version always called CoInitialize() here to ensure 2934 that COM was initialized before loading the driver. 2935 probably the docs need to require clients to initialize COM in new threads? 2936 */ 2937 if( !asioHostApi->asioDrivers->loadDriver( const_cast<char*>(asioDeviceInfo->commonDeviceInfo.name) ) ) 2900 2938 { 2901 2939 result = paUnanticipatedHostError;
