VirtualBox

Changeset 88555 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Apr 15, 2021 10:46:33 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143850
Message:

DrvHostAudioDSound: Refreshed the stream destruction code. bugref:9890

File:
1 edited

Legend:

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

    r88554 r88555  
    220220    DrvHostAudioDSoundMMNotifClient *m_pNotificationClient;
    221221#endif
    222     /** Pointer to the input stream. */
    223     PDSOUNDSTREAM               pDSStrmIn;
    224     /** Pointer to the output stream. */
    225     PDSOUNDSTREAM               pDSStrmOut;
    226222} DRVHOSTDSOUND, *PDRVHOSTDSOUND;
    227223
     
    13631359            pCfgAcq->Backend.cFramesBufferSize = PDMAudioPropsBytesToFrames(&pCfgAcq->Props, BufferCaps.dwBufferBytes);
    13641360
    1365             /** @todo r=bird: WTF is this for? */
    1366             pThis->pDSStrmIn = pStreamDS;
    1367 
    13681361#if 0 /** @todo r=bird: uAlign isn't set anywhere, so this hasn't been checking anything for a while... */
    13691362            if (bc.dwBufferBytes & pStreamDS->uAlign)
     
    14891482                                                  / RT_MAX(pCfgReq->Backend.cFramesBufferSize, 1);
    14901483
    1491             /** @todo r=bird: WTF is this for? */
    1492             pThis->pDSStrmOut = pStreamDS;
    1493 
    14941484#if 0 /** @todo r=bird: uAlign isn't set anywhere, so this hasn't been checking anything for a while... */
    14951485            if (bc.dwBufferBytes & pStreamDS->uAlign)
     
    15921582
    15931583
    1594 static HRESULT directSoundPlayClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS)
    1595 {
    1596     AssertPtrReturn(pThis,     E_POINTER);
    1597     AssertPtrReturn(pStreamDS, E_POINTER);
    1598 
    1599     LogFlowFuncEnter();
    1600 
    1601     HRESULT hr = directSoundPlayStop(pThis, pStreamDS, true /* fFlush */);
    1602     if (SUCCEEDED(hr))
    1603     {
    1604         DSLOG(("DSound: Closing playback stream\n"));
    1605         RTCritSectEnter(&pThis->CritSect);
    1606 
    1607         if (pStreamDS->Out.pDSB)
    1608         {
    1609             IDirectSoundBuffer8_Release(pStreamDS->Out.pDSB);
    1610             pStreamDS->Out.pDSB = NULL;
    1611         }
    1612 
    1613         pThis->pDSStrmOut = NULL;
    1614 
    1615         RTCritSectLeave(&pThis->CritSect);
    1616     }
    1617 
    1618     if (FAILED(hr))
    1619         DSLOGREL(("DSound: Stopping playback stream %p failed with %Rhrc\n", pStreamDS, hr));
    1620 
    1621     return hr;
    1622 }
    1623 
    1624 
    1625 static int dsoundDestroyStreamOut(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS)
    1626 {
    1627     LogFlowFuncEnter();
    1628 
    1629     HRESULT hr = directSoundPlayStop(pThis, pStreamDS, true /* fFlush */);
    1630     if (SUCCEEDED(hr))
    1631     {
    1632         hr = directSoundPlayClose(pThis, pStreamDS);
    1633         if (FAILED(hr))
    1634             return VERR_GENERAL_FAILURE; /** @todo Fix. */
    1635     }
    1636 
    1637     return VINF_SUCCESS;
    1638 }
    1639 
    1640 
    1641 static HRESULT directSoundCaptureClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS)
    1642 {
    1643     AssertPtrReturn(pThis,     E_POINTER);
    1644     AssertPtrReturn(pStreamDS, E_POINTER);
    1645 
    1646     LogFlowFuncEnter();
    1647 
    1648     HRESULT hr = directSoundCaptureStop(pThis, pStreamDS, true /* fFlush */);
    1649     if (FAILED(hr))
    1650         return hr;
    1651 
    1652     if (   pStreamDS
    1653         && pStreamDS->In.pDSCB)
    1654     {
    1655         DSLOG(("DSound: Closing capturing stream\n"));
    1656 
    1657         IDirectSoundCaptureBuffer8_Release(pStreamDS->In.pDSCB);
    1658         pStreamDS->In.pDSCB = NULL;
    1659     }
    1660 
    1661     LogFlowFunc(("Returning %Rhrc\n", hr));
    1662     return hr;
    1663 }
    1664 
    1665 
    1666 static int dsoundDestroyStreamIn(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS)
    1667 {
    1668     LogFlowFuncEnter();
    1669 
    1670     directSoundCaptureClose(pThis, pStreamDS);
    1671 
    1672     return VINF_SUCCESS;
    1673 }
    1674 
    1675 
    16761584/**
    16771585 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
     
    16831591    AssertPtrReturn(pStreamDS, VERR_INVALID_POINTER);
    16841592
    1685     int rc;
    16861593    if (pStreamDS->Cfg.enmDir == PDMAUDIODIR_IN)
    1687         rc = dsoundDestroyStreamIn(pThis, pStreamDS);
     1594    {
     1595        /*
     1596         * Input.
     1597         */
     1598        if (pStreamDS->In.pDSCB)
     1599        {
     1600            directSoundCaptureStop(pThis, pStreamDS, true /* fFlush */);
     1601
     1602            IDirectSoundCaptureBuffer8_Release(pStreamDS->In.pDSCB);
     1603            pStreamDS->In.pDSCB = NULL;
     1604        }
     1605    }
    16881606    else
    1689         rc = dsoundDestroyStreamOut(pThis, pStreamDS);
    1690 
    1691     if (RT_SUCCESS(rc))
    1692     {
    1693         if (RTCritSectIsInitialized(&pStreamDS->CritSect))
    1694             rc = RTCritSectDelete(&pStreamDS->CritSect);
    1695     }
    1696 
    1697     return rc;
     1607    {
     1608        /*
     1609         * Output.
     1610         */
     1611        if (pStreamDS->Out.pDSB)
     1612        {
     1613            directSoundPlayStop(pThis, pStreamDS, true /* fFlush */);
     1614
     1615            IDirectSoundBuffer8_Release(pStreamDS->Out.pDSB);
     1616            pStreamDS->Out.pDSB = NULL;
     1617        }
     1618    }
     1619
     1620    if (RTCritSectIsInitialized(&pStreamDS->CritSect))
     1621        RTCritSectDelete(&pStreamDS->CritSect);
     1622
     1623    return VINF_SUCCESS;
    16981624}
    16991625
     
    17541680static HRESULT directSoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS, bool fFlush)
    17551681{
    1756     AssertPtrReturn(pThis,     E_POINTER);
    1757     AssertPtrReturn(pStreamDS, E_POINTER);
    1758 
    1759     HRESULT hr = S_OK;
    1760 
    1761     if (pStreamDS->Out.pDSB)
    1762     {
    1763         DSLOG(("DSound: Stopping playback\n"));
    1764         hr = IDirectSoundBuffer8_Stop(pStreamDS->Out.pDSB);
    1765         if (FAILED(hr))
    1766         {
    1767             hr = directSoundPlayRestore(pThis, pStreamDS->Out.pDSB);
    1768             if (FAILED(hr)) /** @todo shouldn't this be a SUCCEEDED? */
    1769                 hr = IDirectSoundBuffer8_Stop(pStreamDS->Out.pDSB);
    1770         }
    1771     }
    1772 
    1773     if (SUCCEEDED(hr))
    1774     {
    1775         if (fFlush)
    1776             drvHostDSoundStreamReset(pThis, pStreamDS);
    1777     }
    1778 
    1779     if (FAILED(hr))
    1780         DSLOGREL(("DSound: %s playback failed with %Rhrc\n", fFlush ? "Stopping" : "Pausing", hr));
    1781 
    1782     return hr;
     1682    if (!pStreamDS->Out.pDSB)
     1683        return S_OK;
     1684
     1685    LogRel2(("DSound: Stopping playback of '%s'...\n", pStreamDS->Cfg.szName));
     1686    HRESULT hrc = IDirectSoundBuffer8_Stop(pStreamDS->Out.pDSB);
     1687    if (FAILED(hrc))
     1688    {
     1689        LogFunc(("IDirectSoundBuffer8_Stop -> %Rhrc; will attempt restoring the stream...\n", hrc));
     1690        directSoundPlayRestore(pThis, pStreamDS->Out.pDSB);
     1691        hrc = IDirectSoundBuffer8_Stop(pStreamDS->Out.pDSB);
     1692        if (FAILED(hrc))
     1693            LogRelMax(64, ("DSound: %s playback of '%s' failed: %Rhrc\n", fFlush ? "Stopping" : "Pausing",
     1694                           pStreamDS->Cfg.szName, hrc));
     1695    }
     1696    LogRel2(("DSound: Stopped playback of '%s': %Rhrc\n", pStreamDS->Cfg.szName, hrc));
     1697
     1698    if (fFlush)
     1699        drvHostDSoundStreamReset(pThis, pStreamDS);
     1700    return hrc;
    17831701}
    17841702
     
    19191837static HRESULT directSoundCaptureStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS, bool fFlush)
    19201838{
     1839    if (!pStreamDS->In.pDSCB)
     1840        return S_OK;
     1841
     1842    LogRel2(("DSound: Stopping capture (%s)\n", pStreamDS->Cfg.szName));
     1843    HRESULT hrc = IDirectSoundCaptureBuffer_Stop(pStreamDS->In.pDSCB);
     1844    if (FAILED(hrc))
     1845        LogRelMax(64, ("DSound: Stopping capture of stream '%s' failed: %Rhrc\n", pStreamDS->Cfg.szName, hrc));
     1846
     1847    if (fFlush)
     1848         drvHostDSoundStreamReset(pThis, pStreamDS);
     1849    return hrc;
     1850}
     1851
     1852
     1853static HRESULT directSoundCaptureClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS)
     1854{
    19211855    AssertPtrReturn(pThis,     E_POINTER);
    19221856    AssertPtrReturn(pStreamDS, E_POINTER);
    19231857
    1924     RT_NOREF(pThis);
    1925 
    1926     HRESULT hr = S_OK;
    1927 
    1928     if (pStreamDS->In.pDSCB)
    1929     {
    1930         DSLOG(("DSound: Stopping capture\n"));
    1931         hr = IDirectSoundCaptureBuffer_Stop(pStreamDS->In.pDSCB);
    1932     }
    1933 
    1934     if (SUCCEEDED(hr))
    1935     {
    1936         if (fFlush)
    1937              drvHostDSoundStreamReset(pThis, pStreamDS);
    1938     }
    1939 
     1858    LogFlowFuncEnter();
     1859
     1860    HRESULT hr = directSoundCaptureStop(pThis, pStreamDS, true /* fFlush */);
    19401861    if (FAILED(hr))
    1941         DSLOGREL(("DSound: Stopping capture buffer failed with %Rhrc\n", hr));
    1942 
     1862        return hr;
     1863
     1864    if (   pStreamDS
     1865        && pStreamDS->In.pDSCB)
     1866    {
     1867        DSLOG(("DSound: Closing capturing stream\n"));
     1868
     1869        IDirectSoundCaptureBuffer8_Release(pStreamDS->In.pDSCB);
     1870        pStreamDS->In.pDSCB = NULL;
     1871    }
     1872
     1873    LogFlowFunc(("Returning %Rhrc\n", hr));
    19431874    return hr;
    19441875}
     
    19921923        case PDMAUDIOSTREAMCMD_PAUSE:
    19931924        {
    1994             directSoundCaptureStop(pThis, pStreamDS,
    1995                                    enmStreamCmd == PDMAUDIOSTREAMCMD_DISABLE /* fFlush */);
     1925            directSoundCaptureStop(pThis, pStreamDS, enmStreamCmd == PDMAUDIOSTREAMCMD_DISABLE /* fFlush */);
    19961926
    19971927            /* Return success in any case, as stopping the capture can fail if
Note: See TracChangeset for help on using the changeset viewer.

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