Changeset 1386 for portaudio/trunk/src/hostapi/asio/pa_asio.cpp
- Timestamp:
- 06/28/08 14:27:34 (5 months ago)
- Files:
-
- 1 modified
-
portaudio/trunk/src/hostapi/asio/pa_asio.cpp (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
portaudio/trunk/src/hostapi/asio/pa_asio.cpp
r1363 r1386 966 966 } 967 967 968 968 /* Unload whatever we loaded in LoadAsioDriver(). 969 Also balance the call to CoInitialize(0). 970 */ 971 static void UnloadAsioDriver( void ) 972 { 973 ASIOExit(); 974 CoUninitialize(); 975 } 969 976 970 977 /* 971 978 load the asio driver named by <driverName> and return statistics about 972 979 the driver in info. If no error occurred, the driver will remain open 973 and must be closed by the called by calling ASIOExit() - if an error974 is returned the driver will already be closed.980 and must be closed by the called by calling UnloadAsioDriver() - if an error 981 is returned the driver will already be unloaded. 975 982 */ 976 983 static PaError LoadAsioDriver( PaAsioHostApiRepresentation *asioHostApi, const char *driverName, … … 981 988 int asioIsInitialized = 0; 982 989 983 /* @todo note that the V18 version always called CoInitialize() here to ensure 984 that COM was initialized before loading the driver. 985 probably the docs need to require clients to initialize COM in new threads? 990 /* 991 ASIO uses CoCreateInstance() to load a driver. That requires that 992 CoInitialize(0) be called for every thread that loads a driver. 993 It is OK to call CoInitialize(0) multiple times form one thread as long 994 as it is balanced by a call to CoUninitialize(). See UnloadAsioDriver(). 995 996 The V18 version called CoInitialize() starting on 2/19/02. 997 That was removed from PA V19 for unknown reasons. 998 Phil Burk added it back on 6/27/08 so that JSyn would work. 986 999 */ 1000 CoInitialize( 0 ); 1001 987 1002 if( !asioHostApi->asioDrivers->loadDriver( const_cast<char*>(driverName) ) ) 988 1003 { 1004 /* If this returns an error then it might be because CoInitialize(0) was removed. 1005 It should be called right before this. 1006 */ 989 1007 result = paUnanticipatedHostError; 990 1008 PA_ASIO_SET_LAST_HOST_ERROR( 0, "Failed to load ASIO driver" ); … … 1032 1050 error: 1033 1051 if( asioIsInitialized ) 1034 ASIOExit(); 1035 1052 { 1053 ASIOExit(); 1054 } 1055 CoUninitialize(); 1036 1056 return result; 1037 1057 } … … 1276 1296 { 1277 1297 result = paInsufficientMemory; 1278 goto error ;1298 goto error_unload; 1279 1299 } 1280 1300 … … 1289 1309 result = paUnanticipatedHostError; 1290 1310 PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); 1291 goto error ;1311 goto error_unload; 1292 1312 } 1293 1313 } … … 1302 1322 result = paUnanticipatedHostError; 1303 1323 PA_ASIO_SET_LAST_ASIO_ERROR( asioError ); 1304 goto error ;1324 goto error_unload; 1305 1325 } 1306 1326 } … … 1308 1328 1309 1329 /* unload the driver */ 1310 ASIOExit();1330 UnloadAsioDriver(); 1311 1331 1312 1332 (*hostApi)->deviceInfos[ (*hostApi)->info.deviceCount ] = deviceInfo; … … 1344 1364 1345 1365 return result; 1366 1367 error_unload: 1368 UnloadAsioDriver(); 1346 1369 1347 1370 error: … … 1517 1540 if( asioHostApi->openAsioDeviceIndex == paNoDevice ) 1518 1541 { 1519 ASIOExit(); /* not sure if we should check for errors here */1542 UnloadAsioDriver(); /* not sure if we should check for errors here */ 1520 1543 } 1521 1544 … … 1866 1889 asioIsInitialized = 1; 1867 1890 else{ 1868 PA_DEBUG(("OpenStream ERROR1 \n"));1891 PA_DEBUG(("OpenStream ERROR1 - LoadAsioDriver returned %d\n", result)); 1869 1892 goto error; 1870 1893 } … … 2578 2601 2579 2602 if( asioIsInitialized ) 2580 ASIOExit(); 2581 2603 { 2604 UnloadAsioDriver(); 2605 } 2582 2606 return result; 2583 2607 } … … 2630 2654 2631 2655 ASIODisposeBuffers(); 2632 ASIOExit();2656 UnloadAsioDriver(); 2633 2657 2634 2658 return result; … … 3383 3407 3384 3408 /* If the available amount of data frames is insufficient. */ 3385 if( PaUtil_GetRingBufferReadAvailable(pRb) < lFramesPerBlock )3409 if( PaUtil_GetRingBufferReadAvailable(pRb) < (long) lFramesPerBlock ) 3386 3410 { 3387 3411 /* Make sure, the event isn't already set! */ … … 3558 3582 3559 3583 /* If the available amount of buffers is insufficient. */ 3560 if( PaUtil_GetRingBufferWriteAvailable(pRb) < lFramesPerBlock )3584 if( PaUtil_GetRingBufferWriteAvailable(pRb) < (long) lFramesPerBlock ) 3561 3585 { 3562 3586 /* Make sure, the event isn't already set! */ … … 3717 3741 asioDeviceInfo = (PaAsioDeviceInfo*)hostApi->deviceInfos[hostApiDevice]; 3718 3742 3719 /* @todo note that the V18 version always called CoInitialize() here to ensure 3720 that COM was initialized before loading the driver. 3721 probably the docs need to require clients to initialize COM in new threads? 3722 */ 3743 /* See notes about CoInitialize(0) in LoadAsioDriver(). */ 3744 CoInitialize(0); 3745 3723 3746 if( !asioHostApi->asioDrivers->loadDriver( const_cast<char*>(asioDeviceInfo->commonDeviceInfo.name) ) ) 3724 3747 { … … 3769 3792 } 3770 3793 3794 CoUninitialize(); 3771 3795 PA_DEBUG(("PaAsio_ShowControlPanel: ASIOExit(): %s\n", PaAsio_GetAsioErrorText(asioError) )); 3772 3796 … … 3775 3799 error: 3776 3800 if( asioIsInitialized ) 3777 ASIOExit(); 3801 { 3802 ASIOExit(); 3803 } 3804 CoUninitialize(); 3778 3805 3779 3806 return result; … … 3886 3913 3887 3914 /* If the blocking i/o buffer contains enough output data, */ 3888 if( PaUtil_GetRingBufferReadAvailable(pRb) >= framesPerBuffer )3915 if( PaUtil_GetRingBufferReadAvailable(pRb) >= (long) framesPerBuffer ) 3889 3916 { 3890 3917 /* Extract the requested data from the ring buffer. */ … … 3900 3927 3901 3928 /* If playback is to be stopped */ 3902 if( blockingState->stopFlag && PaUtil_GetRingBufferReadAvailable(pRb) < framesPerBuffer )3929 if( blockingState->stopFlag && PaUtil_GetRingBufferReadAvailable(pRb) < (long) framesPerBuffer ) 3903 3930 { 3904 3931 /* Extract all the remaining data from the ring buffer, … … 3909 3936 3910 3937 /* Set blocking i/o event? */ 3911 if( blockingState->writeBuffersRequestedFlag && PaUtil_GetRingBufferWriteAvailable(pRb) >= blockingState->writeBuffersRequested )3938 if( blockingState->writeBuffersRequestedFlag && PaUtil_GetRingBufferWriteAvailable(pRb) >= (long) blockingState->writeBuffersRequested ) 3912 3939 { 3913 3940 /* Reset buffer request. */ … … 3935 3962 3936 3963 /* If the blocking i/o buffer contains not enough input buffers */ 3937 if( PaUtil_GetRingBufferWriteAvailable(pRb) < framesPerBuffer )3964 if( PaUtil_GetRingBufferWriteAvailable(pRb) < (long) framesPerBuffer ) 3938 3965 { 3939 3966 /* Signalize a read-buffer overflow. */ … … 3948 3975 3949 3976 /* Set blocking i/o event? */ 3950 if( blockingState->readFramesRequestedFlag && PaUtil_GetRingBufferReadAvailable(pRb) >= blockingState->readFramesRequested )3977 if( blockingState->readFramesRequestedFlag && PaUtil_GetRingBufferReadAvailable(pRb) >= (long) blockingState->readFramesRequested ) 3951 3978 { 3952 3979 /* Reset buffer request. */
