VirtualBox

Ignore:
Timestamp:
Apr 15, 2021 12:56:06 PM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioDSound: We don't need to enter the critical section when doing drvHostDSoundHA_GetDevices. Change the dynamic dsound.dll resolving to be done once only. bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvHostAudioDSound.cpp

    r88534 r88539  
    708708 * @param   lpContext           Pointer to PDSOUNDENUMCBCTX context for storing the enumerated information.
    709709 *
    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 */
     712static BOOL CALLBACK drvHostDSoundEnumOldStylePlaybackCallback(LPGUID pGUID, LPCWSTR pwszDescription,
     713                                                               LPCWSTR pwszModule, PVOID lpContext)
    713714{
    714715    PDSOUNDENUMCBCTX pEnumCtx = (PDSOUNDENUMCBCTX)lpContext;
    715     AssertPtrReturn(pEnumCtx , FALSE);
     716    AssertPtrReturn(pEnumCtx, FALSE);
    716717
    717718    PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm;
     
    768769 * @param   lpContext           Pointer to PDSOUNDENUMCBCTX context for storing the enumerated information.
    769770 *
    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 */
     773static BOOL CALLBACK drvHostDSoundEnumOldStyleCaptureCallback(LPGUID pGUID, LPCWSTR pwszDescription,
     774                                                              LPCWSTR pwszModule, PVOID lpContext)
    773775{
    774776    PDSOUNDENUMCBCTX pEnumCtx = (PDSOUNDENUMCBCTX )lpContext;
    775     AssertPtrReturn(pEnumCtx , FALSE);
     777    AssertPtrReturn(pEnumCtx, FALSE);
    776778
    777779    PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm;
     
    820822 *
    821823 * @returns VBox status code.
    822  * @param   pThis               Host audio driver instance.
    823824 * @param   pDev                Audio device to query information for.
    824825 */
    825 static int dsoundDeviceQueryInfo(PDRVHOSTDSOUND pThis, PDSOUNDDEV pDev)
    826 {
    827     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    828     AssertPtrReturn(pDev,  VERR_INVALID_POINTER);
     826static int drvHostDSoundEnumOldStyleQueryDeviceInfo(PDSOUNDDEV pDev)
     827{
     828    AssertPtr(pDev);
    829829    int rc;
    830830
     
    926926 * @param   fDefault    Whether it's the default device.
    927927 */
    928 static int dsoundDeviceNewStyleAdd(PPDMAUDIOHOSTENUM pDevEnm, IMMDevice *pDevice, EDataFlow enmType, bool fDefault)
     928static int drvHostDSoundEnumNewStyleAdd(PPDMAUDIOHOSTENUM pDevEnm, IMMDevice *pDevice, EDataFlow enmType, bool fDefault)
    929929{
    930930    int rc = VINF_SUCCESS; /* ignore most errors */
     
    10231023 *
    10241024 * @return  VBox status code.
    1025  * @param   pThis               Host audio driver instance.
    10261025 * @param   pDevEnm             Where to store the enumerated devices.
    10271026 */
    1028 static int dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIOHOSTENUM pDevEnm)
    1029 {
    1030     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    1031     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    1032 
     1027static int drvHostDSoundEnumerateDevices(PPDMAUDIOHOSTENUM pDevEnm)
     1028{
    10331029    DSLOG(("DSound: Enumerating devices ...\n"));
    10341030
     
    10501046            hrc = pEnumerator->GetDefaultAudioEndpoint(enmType, eMultimedia, &pDefaultDevice);
    10511047            if (SUCCEEDED(hrc))
    1052                 rc = dsoundDeviceNewStyleAdd(pDevEnm, pDefaultDevice, enmType, true);
     1048                rc = drvHostDSoundEnumNewStyleAdd(pDevEnm, pDefaultDevice, enmType, true);
    10531049            else
    10541050                pDefaultDevice = NULL;
     
    10701066                        {
    10711067                            if (pDevice != pDefaultDevice)
    1072                                 rc = dsoundDeviceNewStyleAdd(pDevEnm, pDevice, enmType, false);
     1068                                rc = drvHostDSoundEnumNewStyleAdd(pDevEnm, pDevice, enmType, false);
    10731069                            pDevice->Release();
    10741070                        }
     
    10921088
    10931089    /*
    1094      * Fall back on dsound.
     1090     * Fall back to dsound.
    10951091     */
    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);
    11091102        if (RT_SUCCESS(rc))
    11101103        {
    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);
    11161116        }
    11171117        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));
    11461144    }
    11471145    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 */
    11511156    }
    11521157
    11531158    DSLOG(("DSound: Enumerating devices done\n"));
    11541159
    1155     return rc;
     1160    return VINF_SUCCESS;
    11561161}
    11571162
     
    11621167static DECLCALLBACK(int) drvHostDSoundHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum)
    11631168{
    1164     AssertPtrReturn(pInterface,  VERR_INVALID_POINTER);
     1169    RT_NOREF(pInterface);
    11651170    AssertPtrReturn(pDeviceEnum, VERR_INVALID_POINTER);
    11661171
    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);
    11801176
    11811177    LogFlowFunc(("Returning %Rrc\n", rc));
     
    14961492    AssertPtrReturn(pCfgReq,   E_POINTER);
    14971493    AssertPtrReturn(pCfgAcq,   E_POINTER);
    1498 
    1499 /** @todo r=bird: I cannot see any code populating pCfgAcq... */
    1500 
    15011494    LogFlowFuncEnter();
    15021495
     
    15271520           wfx.cbSize));
    15281521
    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: */
    15331523    dsoundUpdateStatusInternal(pThis);
    15341524
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette