From 0a7b80cfce90bf5973952c1c4ab760efc3559830 Mon Sep 17 00:00:00 2001 From: Ross Bencina Date: Sat, 3 Sep 2016 22:36:13 +1000 Subject: [PATCH] Adds device uid for wmme and dsound devices. damencho committed on Nov 3, 2012 7e70e94 from https://github.com/jitsi/libsrc/commits/master/portaudio.zip --- configure | Bin 411460 -> 411520 bytes src/hostapi/dsound/pa_win_ds.c | 43 ++++++++++++--- src/hostapi/wmme/pa_win_wmme.c | 97 ++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 18640d05ea068a1da5ed077f41a8db3cb2476ac8..ac738aaba330a8c9ca5a8fd684f6b78ee1a838e7 100755 GIT binary patch delta 107 zcmX@oC)v<1+0eq+!qmdt!m@?6jbBbd*CoI)+|w^UG}tvh+{M>BINrrI%+uL5-qX*` efBHrdR^{z0`B`h&h)}80?kUE)-BXP1w*dh9^&p=B delta 50 zcmZqZmpsxZ+0eq+!qmdt!m@?6jemNg7_0JhO=mX#?brBObJ?bQOR{pcXN$3J&lY17 GH3R^fB@TH2 diff --git a/src/hostapi/dsound/pa_win_ds.c b/src/hostapi/dsound/pa_win_ds.c index 5c9fafa..c1f6651 100644 --- a/src/hostapi/dsound/pa_win_ds.c +++ b/src/hostapi/dsound/pa_win_ds.c @@ -517,11 +517,10 @@ static GUID pawin_IID_IKsPropertySet = static void FindDevicePnpInterfaces( DSDeviceNamesAndGUIDs *deviceNamesAndGUIDs ) { IClassFactory *pClassFactory; - if( paWinDsDSoundEntryPoints.DllGetClassObject(&pawin_CLSID_DirectSoundPrivate, &IID_IClassFactory, (PVOID *) &pClassFactory) == S_OK ){ IKsPropertySet *pPropertySet; if( pClassFactory->lpVtbl->CreateInstance( pClassFactory, NULL, &pawin_IID_IKsPropertySet, (PVOID *) &pPropertySet) == S_OK ){ - + DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA data; ULONG bytesReturned; @@ -595,7 +594,7 @@ static double defaultSampleRateSearchOrder_[] = ** The device will not be added to the device list if any errors are encountered. */ static PaError AddOutputDeviceInfoFromDirectSound( - PaWinDsDeviceInfo *winDsDeviceInfo, char *name, LPGUID lpGUID, char *pnpInterface ) + PaWinDsDeviceInfo *winDsDeviceInfo, char *name, LPGUID lpGUID, char *pnpInterface, PaUtilAllocationGroup *allocations ) { PaDeviceInfo *deviceInfo = &winDsDeviceInfo->inheritedDeviceInfo; HRESULT hr; @@ -805,6 +804,17 @@ static PaError AddOutputDeviceInfoFromDirectSound( } else { + // target device UID property + WCHAR duid[39]; + char *deviceUID; + deviceUID = (char *)PaUtil_GroupAllocateMemory(allocations, 39); + + StringFromGUID2(&(*lpGUID), (LPOLESTR) &duid, 39); + wcstombs(deviceUID, duid, sizeof(deviceUID)); + WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + duid, -1, deviceUID, 39, NULL, NULL ); + deviceInfo->deviceUID = deviceUID; + memcpy( &winDsDeviceInfo->guid, lpGUID, sizeof(GUID) ); winDsDeviceInfo->lpGUID = &winDsDeviceInfo->guid; } @@ -829,7 +839,7 @@ error: ** The device will not be added to the device list if any errors are encountered. */ static PaError AddInputDeviceInfoFromDirectSoundCapture( - PaWinDsDeviceInfo *winDsDeviceInfo, char *name, LPGUID lpGUID, char *pnpInterface ) + PaWinDsDeviceInfo *winDsDeviceInfo, char *name, LPGUID lpGUID, char *pnpInterface, PaUtilAllocationGroup *allocations ) { PaDeviceInfo *deviceInfo = &winDsDeviceInfo->inheritedDeviceInfo; HRESULT hr; @@ -962,6 +972,17 @@ http://www.winehq.com/hypermail/wine-patches/2003/01/0290.html } else { + // target device UID property + WCHAR duid[39]; + char *deviceUID; + deviceUID = (char *)PaUtil_GroupAllocateMemory(allocations, 39); + + StringFromGUID2(&(*lpGUID), (LPOLESTR) &duid, 39); + wcstombs(deviceUID, duid, sizeof(deviceUID)); + WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + duid, -1, deviceUID, 39, NULL, NULL ); + deviceInfo->deviceUID = deviceUID; + winDsDeviceInfo->lpGUID = &winDsDeviceInfo->guid; memcpy( &winDsDeviceInfo->guid, lpGUID, sizeof(GUID) ); } @@ -1066,10 +1087,12 @@ error: PaUtil_FreeAllAllocations( winDsHostApi->allocations ); PaUtil_DestroyAllocationGroup( winDsHostApi->allocations ); } - + PaUtil_FreeMemory( winDsHostApi ); } + + if( comWasInitialized ) CoUninitialize(); @@ -1256,7 +1279,7 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH DSDeviceNamesAndGUIDs deviceNamesAndGUIDs; int i = 0; int maximumNewDeviceCount = 0; - + /* Check preconditions */ if( !comWasInitialized || scanResults == NULL || newDeviceCount == NULL ) return paInternalError; @@ -1340,7 +1363,7 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH for( i = 0 ; i < maximumNewDeviceCount; ++i ) { PaDeviceInfo *deviceInfo = &deviceInfoArray[i].inheritedDeviceInfo; - deviceInfo->structVersion = 2; + deviceInfo->structVersion = 3; deviceInfo->hostApi = hostApiIndex; deviceInfo->name = 0; @@ -1354,7 +1377,8 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH result = AddInputDeviceInfoFromDirectSoundCapture( winDsDeviceInfo, deviceNamesAndGUIDs.inputNamesAndGUIDs.items[i].name, deviceNamesAndGUIDs.inputNamesAndGUIDs.items[i].lpGUID, - deviceNamesAndGUIDs.inputNamesAndGUIDs.items[i].pnpInterface ); + deviceNamesAndGUIDs.inputNamesAndGUIDs.items[i].pnpInterface, + winDsHostApi->allocations ); if( result == paNoError ) { if( deviceNamesAndGUIDs.inputNamesAndGUIDs.items[i].lpGUID == NULL ) @@ -1371,7 +1395,8 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH result = AddOutputDeviceInfoFromDirectSound( winDsDeviceInfo, deviceNamesAndGUIDs.outputNamesAndGUIDs.items[i].name, deviceNamesAndGUIDs.outputNamesAndGUIDs.items[i].lpGUID, - deviceNamesAndGUIDs.outputNamesAndGUIDs.items[i].pnpInterface ); + deviceNamesAndGUIDs.outputNamesAndGUIDs.items[i].pnpInterface, + winDsHostApi->allocations ); if( result == paNoError ) { if( deviceNamesAndGUIDs.outputNamesAndGUIDs.items[i].lpGUID == NULL ) diff --git a/src/hostapi/wmme/pa_win_wmme.c b/src/hostapi/wmme/pa_win_wmme.c index 2e048e8..cb2c0a0 100644 --- a/src/hostapi/wmme/pa_win_wmme.c +++ b/src/hostapi/wmme/pa_win_wmme.c @@ -153,6 +153,9 @@ #define PA_MME_USE_HIGH_DEFAULT_LATENCY_ (0) /* For debugging glitches. */ +#define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17) +#define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18) + #if PA_MME_USE_HIGH_DEFAULT_LATENCY_ #define PA_MME_WIN_9X_DEFAULT_LATENCY_ (0.4) #define PA_MME_MIN_HOST_OUTPUT_BUFFER_COUNT_ (4) @@ -665,6 +668,7 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH { PaError result = paNoError; char *deviceName; /* non-const ptr */ + char *deviceUID; MMRESULT mmresult; WAVEINCAPS wic; PaDeviceInfo *deviceInfo = &winMmeDeviceInfo->inheritedDeviceInfo; @@ -737,6 +741,49 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH QueryWaveInKSFilterMaxChannels( winMmeInputDeviceId, &deviceInfo->maxInputChannels ); #endif /* PAWIN_USE_WDMKS_DEVICE_INFO */ + + MMRESULT mmr; + size_t cbEndpointIdSize; + // Get the size (including the terminating null) of + // the endpoint ID string of the waveOut device. + mmr = waveInMessage( + winMmeInputDeviceId, + DRV_QUERYFUNCTIONINSTANCEIDSIZE, + (DWORD_PTR)&cbEndpointIdSize, NULL); + + if (mmr == MMSYSERR_NOERROR) // do sizes match? + { + WCHAR *pstrEndpointId = NULL; + pstrEndpointId = (WCHAR *)PaUtil_GroupAllocateMemory(winMmeHostApi->allocations, cbEndpointIdSize); + + // Get the endpoint ID string for this waveOut device. + mmr = waveInMessage( + winMmeInputDeviceId, + DRV_QUERYFUNCTIONINSTANCEID, + (DWORD_PTR)pstrEndpointId, + cbEndpointIdSize); + + if (mmr == MMSYSERR_NOERROR) + { + deviceUID = (char *)PaUtil_GroupAllocateMemory(winMmeHostApi->allocations, wcslen(pstrEndpointId)); + if( !deviceUID ) + { + result = paInsufficientMemory; + goto error; + } + wcstombs(deviceUID, pstrEndpointId, sizeof(deviceUID)); + WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + pstrEndpointId, -1, deviceUID, wcslen(pstrEndpointId), NULL, NULL ); + deviceInfo->deviceUID = deviceUID; + } + /*else + { + char mmeErrorText[ MAXERRORLENGTH ]; + waveOutGetErrorText( mmr, mmeErrorText, MAXERRORLENGTH ); + PA_DEBUG(("Error %i: %s\n", mmr ,mmeErrorText)); + }*/ + } + winMmeDeviceInfo->dwFormats = wic.dwFormats; DetectDefaultSampleRate( winMmeDeviceInfo, winMmeInputDeviceId, @@ -788,6 +835,7 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme { PaError result = paNoError; char *deviceName; /* non-const ptr */ + char *deviceUID; MMRESULT mmresult; WAVEOUTCAPS woc; PaDeviceInfo *deviceInfo = &winMmeDeviceInfo->inheritedDeviceInfo; @@ -863,6 +911,49 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme winMmeDeviceInfo->deviceOutputChannelCountIsKnown = 1; #endif /* PAWIN_USE_WDMKS_DEVICE_INFO */ + MMRESULT mmr; + size_t cbEndpointIdSize; + // Get the size (including the terminating null) of + // the endpoint ID string of the waveOut device. + mmr = waveOutMessage( + winMmeOutputDeviceId, + DRV_QUERYFUNCTIONINSTANCEIDSIZE, + (DWORD_PTR)&cbEndpointIdSize, NULL); + + if (mmr == MMSYSERR_NOERROR) // do sizes match? + { + WCHAR *pstrEndpointId = NULL; + pstrEndpointId = (WCHAR *)PaUtil_GroupAllocateMemory(winMmeHostApi->allocations, cbEndpointIdSize); + + // Get the endpoint ID string for this waveOut device. + mmr = waveOutMessage( + winMmeOutputDeviceId, + DRV_QUERYFUNCTIONINSTANCEID, + (DWORD_PTR)pstrEndpointId, + cbEndpointIdSize); + + if (mmr == MMSYSERR_NOERROR) + { + deviceUID = (char *)PaUtil_GroupAllocateMemory(winMmeHostApi->allocations, wcslen(pstrEndpointId)); + if( !deviceUID ) + { + result = paInsufficientMemory; + goto error; + } + wcstombs(deviceUID, pstrEndpointId, sizeof(deviceUID)); + + WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + pstrEndpointId, -1, deviceUID, wcslen(pstrEndpointId), NULL, NULL ); + deviceInfo->deviceUID = deviceUID; + } + /*else + { + char mmeErrorText[ MAXERRORLENGTH ]; + waveOutGetErrorText( mmr, mmeErrorText, MAXERRORLENGTH ); + PA_DEBUG(("Error %i: %s\n", mmr ,mmeErrorText)); + }*/ + } + winMmeDeviceInfo->dwFormats = woc.dwFormats; DetectDefaultSampleRate( winMmeDeviceInfo, winMmeOutputDeviceId, @@ -930,7 +1021,6 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd (*hostApi)->info.type = paMME; (*hostApi)->info.name = "MME"; - /* initialise device counts and default devices under the assumption that there are no devices. These values are incremented below if and when devices are successfully initialized. @@ -953,6 +1043,7 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd preferredDeviceStatusFlags = 0; waveOutPreferredDevice = -1; + waveOutMessage( (HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&waveOutPreferredDevice, (DWORD_PTR)&preferredDeviceStatusFlags ); maximumPossibleDeviceCount = 0; @@ -1001,7 +1092,7 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd UINT winMmeDeviceId = (UINT)((i==-1) ? WAVE_MAPPER : i); PaWinMmeDeviceInfo *wmmeDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ]; PaDeviceInfo *deviceInfo = &wmmeDeviceInfo->inheritedDeviceInfo; - deviceInfo->structVersion = 2; + deviceInfo->structVersion = 3; deviceInfo->hostApi = hostApiIndex; deviceInfo->maxInputChannels = 0; @@ -1044,7 +1135,7 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd UINT winMmeDeviceId = (UINT)((i==-1) ? WAVE_MAPPER : i); PaWinMmeDeviceInfo *wmmeDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ]; PaDeviceInfo *deviceInfo = &wmmeDeviceInfo->inheritedDeviceInfo; - deviceInfo->structVersion = 2; + deviceInfo->structVersion = 3; deviceInfo->hostApi = hostApiIndex; deviceInfo->maxInputChannels = 0; -- 2.43.0