Changeset 88539 in vbox for trunk/src/VBox/Devices/Audio/DrvHostAudioDSound.cpp
- Timestamp:
- Apr 15, 2021 12:56:06 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioDSound.cpp
r88534 r88539 708 708 * @param lpContext Pointer to PDSOUNDENUMCBCTX context for storing the enumerated information. 709 709 * 710 * @note Carbon copy of dsoundDevicesEnumCbCapture with OUT direction. 711 */ 712 static BOOL CALLBACK dsoundDevicesEnumCbPlayback(LPGUID pGUID, LPCWSTR pwszDescription, LPCWSTR pwszModule, PVOID lpContext) 710 * @note Carbon copy of drvHostDSoundEnumOldStyleCaptureCallback with OUT direction. 711 */ 712 static BOOL CALLBACK drvHostDSoundEnumOldStylePlaybackCallback(LPGUID pGUID, LPCWSTR pwszDescription, 713 LPCWSTR pwszModule, PVOID lpContext) 713 714 { 714 715 PDSOUNDENUMCBCTX pEnumCtx = (PDSOUNDENUMCBCTX)lpContext; 715 AssertPtrReturn(pEnumCtx 716 AssertPtrReturn(pEnumCtx, FALSE); 716 717 717 718 PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm; … … 768 769 * @param lpContext Pointer to PDSOUNDENUMCBCTX context for storing the enumerated information. 769 770 * 770 * @note Carbon copy of dsoundDevicesEnumCbPlayback with IN direction. 771 */ 772 static BOOL CALLBACK dsoundDevicesEnumCbCapture(LPGUID pGUID, LPCWSTR pwszDescription, LPCWSTR pwszModule, PVOID lpContext) 771 * @note Carbon copy of drvHostDSoundEnumOldStylePlaybackCallback with IN direction. 772 */ 773 static BOOL CALLBACK drvHostDSoundEnumOldStyleCaptureCallback(LPGUID pGUID, LPCWSTR pwszDescription, 774 LPCWSTR pwszModule, PVOID lpContext) 773 775 { 774 776 PDSOUNDENUMCBCTX pEnumCtx = (PDSOUNDENUMCBCTX )lpContext; 775 AssertPtrReturn(pEnumCtx 777 AssertPtrReturn(pEnumCtx, FALSE); 776 778 777 779 PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm; … … 820 822 * 821 823 * @returns VBox status code. 822 * @param pThis Host audio driver instance.823 824 * @param pDev Audio device to query information for. 824 825 */ 825 static int dsoundDeviceQueryInfo(PDRVHOSTDSOUND pThis, PDSOUNDDEV pDev) 826 { 827 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 828 AssertPtrReturn(pDev, VERR_INVALID_POINTER); 826 static int drvHostDSoundEnumOldStyleQueryDeviceInfo(PDSOUNDDEV pDev) 827 { 828 AssertPtr(pDev); 829 829 int rc; 830 830 … … 926 926 * @param fDefault Whether it's the default device. 927 927 */ 928 static int d soundDeviceNewStyleAdd(PPDMAUDIOHOSTENUM pDevEnm, IMMDevice *pDevice, EDataFlow enmType, bool fDefault)928 static int drvHostDSoundEnumNewStyleAdd(PPDMAUDIOHOSTENUM pDevEnm, IMMDevice *pDevice, EDataFlow enmType, bool fDefault) 929 929 { 930 930 int rc = VINF_SUCCESS; /* ignore most errors */ … … 1023 1023 * 1024 1024 * @return VBox status code. 1025 * @param pThis Host audio driver instance.1026 1025 * @param pDevEnm Where to store the enumerated devices. 1027 1026 */ 1028 static int dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIOHOSTENUM pDevEnm) 1029 { 1030 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1031 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 1032 1027 static int drvHostDSoundEnumerateDevices(PPDMAUDIOHOSTENUM pDevEnm) 1028 { 1033 1029 DSLOG(("DSound: Enumerating devices ...\n")); 1034 1030 … … 1050 1046 hrc = pEnumerator->GetDefaultAudioEndpoint(enmType, eMultimedia, &pDefaultDevice); 1051 1047 if (SUCCEEDED(hrc)) 1052 rc = d soundDeviceNewStyleAdd(pDevEnm, pDefaultDevice, enmType, true);1048 rc = drvHostDSoundEnumNewStyleAdd(pDevEnm, pDefaultDevice, enmType, true); 1053 1049 else 1054 1050 pDefaultDevice = NULL; … … 1070 1066 { 1071 1067 if (pDevice != pDefaultDevice) 1072 rc = d soundDeviceNewStyleAdd(pDevEnm, pDevice, enmType, false);1068 rc = drvHostDSoundEnumNewStyleAdd(pDevEnm, pDevice, enmType, false); 1073 1069 pDevice->Release(); 1074 1070 } … … 1092 1088 1093 1089 /* 1094 * Fall back ondsound.1090 * Fall back to dsound. 1095 1091 */ 1096 RTLDRMOD hDSound = NULL; 1097 int rc = RTLdrLoadSystem("dsound.dll", true /*fNoUnload*/, &hDSound); 1098 if (RT_SUCCESS(rc)) 1099 { 1100 DSOUNDENUMCBCTX EnumCtx; 1101 EnumCtx.fFlags = 0; 1102 EnumCtx.pDevEnm = pDevEnm; 1103 1104 /* 1105 * Enumerate playback devices. 1106 */ 1107 PFNDIRECTSOUNDENUMERATEW pfnDirectSoundEnumerateW = NULL; 1108 rc = RTLdrGetSymbol(hDSound, "DirectSoundEnumerateW", (void**)&pfnDirectSoundEnumerateW); 1092 /* Resolve symbols once. */ 1093 static PFNDIRECTSOUNDENUMERATEW volatile s_pfnDirectSoundEnumerateW = NULL; 1094 static PFNDIRECTSOUNDCAPTUREENUMERATEW volatile s_pfnDirectSoundCaptureEnumerateW = NULL; 1095 1096 PFNDIRECTSOUNDENUMERATEW pfnDirectSoundEnumerateW = s_pfnDirectSoundEnumerateW; 1097 PFNDIRECTSOUNDCAPTUREENUMERATEW pfnDirectSoundCaptureEnumerateW = s_pfnDirectSoundCaptureEnumerateW; 1098 if (!pfnDirectSoundEnumerateW || !pfnDirectSoundCaptureEnumerateW) 1099 { 1100 RTLDRMOD hModDSound = NIL_RTLDRMOD; 1101 int rc = RTLdrLoadSystem("dsound.dll", true /*fNoUnload*/, &hModDSound); 1109 1102 if (RT_SUCCESS(rc)) 1110 1103 { 1111 DSLOG(("DSound: Enumerating playback devices ...\n")); 1112 1113 HRESULT hr = pfnDirectSoundEnumerateW(&dsoundDevicesEnumCbPlayback, &EnumCtx); 1114 if (FAILED(hr)) 1115 LogRel(("DSound: Error enumerating host playback devices: %Rhrc\n", hr)); 1104 rc = RTLdrGetSymbol(hModDSound, "DirectSoundEnumerateW", (void **)&pfnDirectSoundEnumerateW); 1105 if (RT_SUCCESS(rc)) 1106 s_pfnDirectSoundEnumerateW = pfnDirectSoundEnumerateW; 1107 else 1108 LogRel(("DSound: Failed to get dsound.dll export DirectSoundEnumerateW: %Rrc\n", rc)); 1109 1110 rc = RTLdrGetSymbol(hModDSound, "DirectSoundCaptureEnumerateW", (void **)&pfnDirectSoundCaptureEnumerateW); 1111 if (RT_SUCCESS(rc)) 1112 s_pfnDirectSoundCaptureEnumerateW = pfnDirectSoundCaptureEnumerateW; 1113 else 1114 LogRel(("DSound: Failed to get dsound.dll export DirectSoundCaptureEnumerateW: %Rrc\n", rc)); 1115 RTLdrClose(hModDSound); 1116 1116 } 1117 1117 else 1118 LogRel(("DSound: Error starting to enumerate host playback devices: %Rrc\n", rc)); 1119 1120 /* 1121 * Enumerate capture devices. 1122 */ 1123 PFNDIRECTSOUNDCAPTUREENUMERATEW pfnDirectSoundCaptureEnumerateW = NULL; 1124 rc = RTLdrGetSymbol(hDSound, "DirectSoundCaptureEnumerateW", (void**)&pfnDirectSoundCaptureEnumerateW); 1125 if (RT_SUCCESS(rc)) 1126 { 1127 DSLOG(("DSound: Enumerating capture devices ...\n")); 1128 1129 HRESULT hr = pfnDirectSoundCaptureEnumerateW(&dsoundDevicesEnumCbCapture, &EnumCtx); 1130 if (FAILED(hr)) 1131 LogRel(("DSound: Error enumerating host capture devices: %Rhrc\n", hr)); 1132 } 1133 else 1134 LogRel(("DSound: Error starting to enumerate host capture devices: %Rrc\n", rc)); 1135 1136 /* 1137 * Query Information from all enumerated devices. 1138 */ 1139 PDSOUNDDEV pDev; 1140 RTListForEach(&pDevEnm->LstDevices, pDev, DSOUNDDEV, Core.ListEntry) 1141 { 1142 dsoundDeviceQueryInfo(pThis, pDev); /* ignore rc */ 1143 } 1144 1145 RTLdrClose(hDSound); 1118 LogRel(("DSound: Unable to load dsound.dll for enumerating devices: %Rrc\n", rc)); 1119 if (!pfnDirectSoundEnumerateW && !pfnDirectSoundCaptureEnumerateW) 1120 return rc; 1121 } 1122 1123 /* Common callback context for both playback and capture enumerations: */ 1124 DSOUNDENUMCBCTX EnumCtx; 1125 EnumCtx.fFlags = 0; 1126 EnumCtx.pDevEnm = pDevEnm; 1127 1128 /* Enumerate playback devices. */ 1129 if (pfnDirectSoundEnumerateW) 1130 { 1131 DSLOG(("DSound: Enumerating playback devices ...\n")); 1132 HRESULT hr = pfnDirectSoundEnumerateW(&drvHostDSoundEnumOldStylePlaybackCallback, &EnumCtx); 1133 if (FAILED(hr)) 1134 LogRel(("DSound: Error enumerating host playback devices: %Rhrc\n", hr)); 1135 } 1136 1137 /* Enumerate capture devices. */ 1138 if (pfnDirectSoundCaptureEnumerateW) 1139 { 1140 DSLOG(("DSound: Enumerating capture devices ...\n")); 1141 HRESULT hr = pfnDirectSoundCaptureEnumerateW(&drvHostDSoundEnumOldStyleCaptureCallback, &EnumCtx); 1142 if (FAILED(hr)) 1143 LogRel(("DSound: Error enumerating host capture devices: %Rhrc\n", hr)); 1146 1144 } 1147 1145 else 1148 { 1149 /* No dsound.dll on this system. */ 1150 LogRel(("DSound: Could not load dsound.dll for enumerating devices: %Rrc\n", rc)); 1146 LogRel(("DSound: Error starting to enumerate host capture devices: %Rrc\n", rc)); 1147 1148 /* 1149 * Query Information for all enumerated devices. 1150 * Note! This is problematic to do from the enumeration callbacks. 1151 */ 1152 PDSOUNDDEV pDev; 1153 RTListForEach(&pDevEnm->LstDevices, pDev, DSOUNDDEV, Core.ListEntry) 1154 { 1155 drvHostDSoundEnumOldStylQueryDeviceInfo(pDev); /* ignore rc */ 1151 1156 } 1152 1157 1153 1158 DSLOG(("DSound: Enumerating devices done\n")); 1154 1159 1155 return rc;1160 return VINF_SUCCESS; 1156 1161 } 1157 1162 … … 1162 1167 static DECLCALLBACK(int) drvHostDSoundHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum) 1163 1168 { 1164 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);1169 RT_NOREF(pInterface); 1165 1170 AssertPtrReturn(pDeviceEnum, VERR_INVALID_POINTER); 1166 1171 1167 PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface); 1168 1169 int rc = RTCritSectEnter(&pThis->CritSect); 1170 if (RT_SUCCESS(rc)) 1171 { 1172 PDMAudioHostEnumInit(pDeviceEnum); 1173 rc = dsoundDevicesEnumerate(pThis, pDeviceEnum); 1174 if (RT_FAILURE(rc)) 1175 PDMAudioHostEnumDelete(pDeviceEnum); 1176 1177 int rc2 = RTCritSectLeave(&pThis->CritSect); 1178 AssertRC(rc2); 1179 } 1172 PDMAudioHostEnumInit(pDeviceEnum); 1173 int rc = drvHostDSoundEnumerateDevices(pDeviceEnum); 1174 if (RT_FAILURE(rc)) 1175 PDMAudioHostEnumDelete(pDeviceEnum); 1180 1176 1181 1177 LogFlowFunc(("Returning %Rrc\n", rc)); … … 1496 1492 AssertPtrReturn(pCfgReq, E_POINTER); 1497 1493 AssertPtrReturn(pCfgAcq, E_POINTER); 1498 1499 /** @todo r=bird: I cannot see any code populating pCfgAcq... */1500 1501 1494 LogFlowFuncEnter(); 1502 1495 … … 1527 1520 wfx.cbSize)); 1528 1521 1529 /** @todo r=bird: Why is this called every time? It triggers a device 1530 * enumeration. Andy claimed on IRC that enumeration was only done once... 1531 * It's generally a 'ing waste of time here too, as we dont really use any of 1532 * the information we gather there. */ 1522 /* Waste some time: */ 1533 1523 dsoundUpdateStatusInternal(pThis); 1534 1524
Note:
See TracChangeset
for help on using the changeset viewer.