]> Repos - portaudio/commitdiff
wasapi: fixed extension functions: PaWasapi_GetDeviceDefaultFormat / PaWasapi_GetDevi...
authordmitrykos <dmitrykos@0f58301d-fd10-0410-b4af-bbb618454e57>
Sat, 13 Mar 2010 18:53:40 +0000 (18:53 +0000)
committerdmitrykos <dmitrykos@0f58301d-fd10-0410-b4af-bbb618454e57>
Sat, 13 Mar 2010 18:53:40 +0000 (18:53 +0000)
src/hostapi/wasapi/pa_win_wasapi.c

index 72161ac0386c0a481f9b1abce0dbb3dd23438420..a6536750719247c2e2848c77cf0eb9482dda7e67 100644 (file)
@@ -443,7 +443,7 @@ typedef struct
     IMMDeviceEnumerator *enumerator;\r
 \r
     //this is the REAL number of devices, whether they are usefull to PA or not!\r
-    UINT deviceCount;\r
+    UINT32 deviceCount;\r
 \r
     WCHAR defaultRenderer [MAX_STR_LEN];\r
     WCHAR defaultCapturer [MAX_STR_LEN];\r
@@ -934,18 +934,18 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
 \r
     if (paWasapi->deviceCount > 0)\r
     {\r
-        (*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory(\r
-                paWasapi->allocations, sizeof(PaDeviceInfo*) * paWasapi->deviceCount);\r
-        if (!(*hostApi)->deviceInfos)\r
+        (*hostApi)->deviceInfos = (PaDeviceInfo **)PaUtil_GroupAllocateMemory(\r
+                paWasapi->allocations, sizeof(PaDeviceInfo *) * paWasapi->deviceCount);\r
+        if ((*hostApi)->deviceInfos == NULL)\r
                {\r
             result = paInsufficientMemory;\r
             goto error;\r
         }\r
 \r
         /* allocate all device info structs in a contiguous block */\r
-        deviceInfoArray = (PaDeviceInfo*)PaUtil_GroupAllocateMemory(\r
+        deviceInfoArray = (PaDeviceInfo *)PaUtil_GroupAllocateMemory(\r
                 paWasapi->allocations, sizeof(PaDeviceInfo) * paWasapi->deviceCount);\r
-        if (!deviceInfoArray)\r
+        if (deviceInfoArray == NULL)\r
                {\r
             result = paInsufficientMemory;\r
             goto error;\r
@@ -1189,7 +1189,7 @@ static void Terminate( PaUtilHostApiRepresentation *hostApi )
 }\r
 \r
 // ------------------------------------------------------------------------------------------\r
-static PaWasapiHostApiRepresentation *GetHostApi(PaError *_error)\r
+static PaWasapiHostApiRepresentation *_GetHostApi(PaError *_error)\r
 {\r
        PaError error;\r
 \r
@@ -1210,6 +1210,7 @@ int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, Pa
        PaError ret;\r
        PaWasapiHostApiRepresentation *paWasapi;\r
        UINT32 size;\r
+       PaDeviceIndex index;\r
 \r
        if (pFormat == NULL)\r
                return paBadBufferPtr;\r
@@ -1217,15 +1218,21 @@ int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, Pa
                return paBufferTooSmall;\r
 \r
        // Get API\r
-       paWasapi = GetHostApi(&ret);\r
+       paWasapi = _GetHostApi(&ret);\r
        if (paWasapi == NULL)\r
                return ret;\r
 \r
-       if ((UINT32)nDevice >= paWasapi->deviceCount)\r
+       // Get device index\r
+       ret = PaUtil_DeviceIndexToHostApiDeviceIndex(&index, nDevice, &paWasapi->inheritedHostApiRep);\r
+    if (ret != paNoError)\r
+        return ret;\r
+\r
+       // Validate index\r
+       if ((UINT32)index >= paWasapi->deviceCount)\r
                return paInvalidDevice;\r
 \r
-       size = min(nFormatSize, (UINT32)sizeof(paWasapi->devInfo[ nDevice ].DefaultFormat));\r
-       memcpy(pFormat, &paWasapi->devInfo[ nDevice ].DefaultFormat, size);\r
+       size = min(nFormatSize, (UINT32)sizeof(paWasapi->devInfo[ index ].DefaultFormat));\r
+       memcpy(pFormat, &paWasapi->devInfo[ index ].DefaultFormat, size);\r
 \r
        return size;\r
 }\r
@@ -1234,16 +1241,23 @@ int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, Pa
 int PaWasapi_GetDeviceRole( PaDeviceIndex nDevice )\r
 {\r
        PaError ret;\r
+       PaDeviceIndex index;\r
 \r
        // Get API\r
-       PaWasapiHostApiRepresentation *paWasapi = GetHostApi(&ret);\r
+       PaWasapiHostApiRepresentation *paWasapi = _GetHostApi(&ret);\r
        if (paWasapi == NULL)\r
                return ret;\r
 \r
-       if (nDevice >= (int)paWasapi->deviceCount)\r
+       // Get device index\r
+       ret = PaUtil_DeviceIndexToHostApiDeviceIndex(&index, nDevice, &paWasapi->inheritedHostApiRep);\r
+    if (ret != paNoError)\r
+        return ret;\r
+\r
+       // Validate index\r
+       if ((UINT32)index >= paWasapi->deviceCount)\r
                return paInvalidDevice;\r
 \r
-       return paWasapi->devInfo[ nDevice ].formFactor;\r
+       return paWasapi->devInfo[ index ].formFactor;\r
 }\r
 \r
 // ------------------------------------------------------------------------------------------\r