VirtualBox

Changeset 58344 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Oct 20, 2015 3:54:04 PM (9 years ago)
Author:
vboxsync
Message:

Audio: Fixed suspending/resuming streams on VM pause/unpause.

File:
1 edited

Legend:

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

    r58157 r58344  
    371371}
    372372
    373 static int drvAudioControlHstIn(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMIN pHstStrmIn, PDMAUDIOSTREAMCMD enmStreamCmd,
    374                                 uint32_t uFlags)
     373static int drvAudioControlHstIn(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMIN pHstStrmIn, PDMAUDIOSTREAMCMD enmStreamCmd)
    375374{
    376375    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     
    383382        case PDMAUDIOSTREAMCMD_ENABLE:
    384383        {
    385             if (!pHstStrmIn->fEnabled)
     384            if (!(pHstStrmIn->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED))
    386385            {
    387386                rc = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, PDMAUDIOSTREAMCMD_ENABLE);
    388387                if (RT_SUCCESS(rc))
    389388                {
    390                     pHstStrmIn->fEnabled = true;
     389                    pHstStrmIn->fStatus |= PDMAUDIOSTRMSTS_FLAG_ENABLED;
    391390                }
    392391                else
     
    401400        case PDMAUDIOSTREAMCMD_DISABLE:
    402401        {
    403             if (pHstStrmIn->fEnabled)
     402            if (pHstStrmIn->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    404403            {
    405404                rc = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE);
    406405                if (RT_SUCCESS(rc))
    407406                {
    408                     pHstStrmIn->fEnabled = false;
     407                    pHstStrmIn->fStatus = PDMAUDIOSTRMSTS_FLAG_NONE; /* Clear all. */
    409408                    AudioMixBufClear(&pHstStrmIn->MixBuf);
    410409                }
     
    427426}
    428427
    429 static int drvAudioControlHstOut(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMOUT pHstStrmOut, PDMAUDIOSTREAMCMD enmStreamCmd,
    430                                  uint32_t uFlags)
     428static int drvAudioControlHstOut(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMOUT pHstStrmOut, PDMAUDIOSTREAMCMD enmStreamCmd)
    431429{
    432430    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     
    439437        case PDMAUDIOSTREAMCMD_ENABLE:
    440438        {
    441             if (!pHstStrmOut->fEnabled)
     439            if (!(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED))
    442440            {
    443441                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE);
    444442                if (RT_SUCCESS(rc))
    445443                {
    446                     Assert(!pHstStrmOut->fPendingDisable);
    447                     pHstStrmOut->fEnabled = true;
     444                    Assert(!(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE));
     445                    pHstStrmOut->fStatus |= PDMAUDIOSTRMSTS_FLAG_ENABLED;
    448446                    LogFunc(("[%s] Enabled stream\n", pHstStrmOut->MixBuf.pszName));
    449447                }
    450448                else
    451                     LogFlowFunc(("[%s] Backend reported an error when opening output stream, rc=%Rrc\n",
     449                    LogFlowFunc(("[%s] Backend reported an error when enabling output stream, rc=%Rrc\n",
    452450                                 pHstStrmOut->MixBuf.pszName, rc));
    453451            }
     
    460458        case PDMAUDIOSTREAMCMD_DISABLE:
    461459        {
    462             if (pHstStrmOut->fEnabled)
     460            if (pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    463461            {
    464462                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
    465463                if (RT_SUCCESS(rc))
    466464                {
    467                     pHstStrmOut->fEnabled        = false;
    468                     pHstStrmOut->fPendingDisable = false;
     465                    pHstStrmOut->fStatus = PDMAUDIOSTRMSTS_FLAG_NONE; /* Clear all. */
    469466                    AudioMixBufClear(&pHstStrmOut->MixBuf);
    470467
     
    472469                }
    473470                else
    474                     LogFlowFunc(("[%s] Backend vetoed closing output stream, rc=%Rrc\n", pHstStrmOut->MixBuf.pszName, rc));
     471                    LogFlowFunc(("[%s] Backend vetoed disabling output stream, rc=%Rrc\n", pHstStrmOut->MixBuf.pszName, rc));
     472            }
     473            else
     474                rc = VINF_SUCCESS;
     475
     476            break;
     477        }
     478
     479        case PDMAUDIOSTREAMCMD_PAUSE:
     480        {
     481            if (!(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_PAUSED))
     482            {
     483                Assert(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED);
     484                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
     485                if (RT_SUCCESS(rc))
     486                {
     487                    pHstStrmOut->fStatus |= PDMAUDIOSTRMSTS_FLAG_PAUSED;
     488                    LogFunc(("[%s] Pausing stream\n", pHstStrmOut->MixBuf.pszName));
     489                }
     490                else
     491                    LogFlowFunc(("[%s] Backend vetoed pausing output stream, rc=%Rrc\n", pHstStrmOut->MixBuf.pszName, rc));
     492            }
     493            else
     494                rc = VINF_SUCCESS;
     495
     496            break;
     497        }
     498
     499        case PDMAUDIOSTREAMCMD_RESUME:
     500        {
     501            if (pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_PAUSED)
     502            {
     503                Assert(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED);
     504                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE);
     505                if (RT_SUCCESS(rc))
     506                {
     507                    pHstStrmOut->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PAUSED;
     508                    LogFunc(("[%s] Resumed stream\n", pHstStrmOut->MixBuf.pszName));
     509                }
     510                else
     511                    LogFlowFunc(("[%s] Backend vetoed resuming output stream, rc=%Rrc\n", pHstStrmOut->MixBuf.pszName, rc));
    475512            }
    476513            else
     
    562599{
    563600    while ((pHstStrmIn = drvAudioFindNextHstIn(pThis, pHstStrmIn)))
    564         if (pHstStrmIn->fEnabled)
     601        if (pHstStrmIn->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    565602            return pHstStrmIn;
    566603
     
    9951032    AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER);
    9961033
    997     AssertMsg(pGstStrmOut->pHstStrmOut->fEnabled,
     1034    AssertMsg(pGstStrmOut->pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED,
    9981035              ("Writing to disabled host output stream \"%s\" not possible\n",
    9991036              pHstStrmOut->MixBuf.pszName));
     
    10531090    while ((pHostStrmOut = drvAudioFindAnyHstOut(pThis, pHostStrmOut)))
    10541091    {
    1055         if (pHostStrmOut->fEnabled)
     1092        if (pHostStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    10561093            return pHostStrmOut;
    10571094    }
     
    11591196        /* Has this stream marked as disabled but there still were guest streams relying
    11601197         * on it? Check if this stream now can be closed and do so, if possible. */
    1161         if (   pHstStrmOut->fPendingDisable
     1198        if (   (pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE)
    11621199            && !cSamplesLive)
    11631200        {
    11641201            /* Stop playing the current (pending) stream. */
    1165             int rc2 = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
     1202            int rc2 = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
    11661203            if (RT_SUCCESS(rc2))
    11671204            {
    1168                 pHstStrmOut->fPendingDisable = false;
     1205                pHstStrmOut->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
    11691206
    11701207                LogFunc(("[%s] Disabling stream\n", pHstStrmOut->MixBuf.pszName));
     
    14021439static void drvAudioStateHandler(PPDMDRVINS pDrvIns, PDMAUDIOSTREAMCMD enmCmd)
    14031440{
     1441    PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
    14041442    PDRVAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIO);
    14051443
     
    14111449    PPDMAUDIOHSTSTRMOUT pHstStrmOut = NULL;
    14121450    while ((pHstStrmOut = drvAudioHstFindAnyEnabledOut(pThis, pHstStrmOut)))
    1413         drvAudioControlHstOut(pThis, pHstStrmOut, enmCmd, 0 /* Flags */);
     1451        drvAudioControlHstOut(pThis, pHstStrmOut, enmCmd);
    14141452
    14151453    PPDMAUDIOHSTSTRMIN pHstStrmIn = NULL;
    14161454    while ((pHstStrmIn = drvAudioFindNextEnabledHstIn(pThis, pHstStrmIn)))
    1417         drvAudioControlHstIn(pThis, pHstStrmIn, enmCmd, 0 /* Flags */);
     1455        drvAudioControlHstIn(pThis, pHstStrmIn, enmCmd);
    14181456}
    14191457
     
    15371575    AssertPtrReturn(pHstStrmIn, VERR_INVALID_POINTER);
    15381576
    1539     AssertMsg(pGstStrmIn->pHstStrmIn->fEnabled,
     1577    AssertMsg(pGstStrmIn->pHstStrmIn->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED,
    15401578              ("Reading from disabled host input stream \"%s\" not possible\n", pGstStrmIn->MixBuf.pszName));
    15411579
     
    15791617            if (fEnable)
    15801618            {
    1581                 pHstStrmOut->fPendingDisable = false;
    1582                 if (!pHstStrmOut->fEnabled)
    1583                     rc = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE, 0 /* Flags */);
     1619                pHstStrmOut->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
     1620                if (!(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED))
     1621                    rc = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE);
    15841622            }
    15851623            else /* Disable */
    15861624            {
    1587                 if (pHstStrmOut->fEnabled)
     1625                if (pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    15881626                {
    15891627                    uint32_t cGstStrmsActive = 0;
     
    16071645
    16081646                    /* Do we need to defer closing the host stream? */
    1609                     pHstStrmOut->fPendingDisable = cGstStrmsActive >= 1;
     1647                    if (cGstStrmsActive >= 1)
     1648                        pHstStrmOut->fStatus |= PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
    16101649
    16111650                    /* Can we close the host stream now instead of deferring it? */
    1612                     if (!pHstStrmOut->fPendingDisable)
    1613                         rc = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
     1651                    if (!(pHstStrmOut->fStatus & PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE))
     1652                        rc = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
    16141653                }
    16151654            }
     
    16181657                pGstStrmOut->State.fActive = fEnable;
    16191658
    1620             LogFlowFunc(("%s: fEnable=%RTbool, fPendingDisable=%RTbool, rc=%Rrc\n",
    1621                          pGstStrmOut->MixBuf.pszName, fEnable, pHstStrmOut->fPendingDisable, rc));
     1659            LogFlowFunc(("%s: fEnable=%RTbool, fStatus=0x%x, rc=%Rrc\n",
     1660                         pGstStrmOut->MixBuf.pszName, fEnable, pHstStrmOut->fStatus, rc));
    16221661        }
    16231662    }
     
    16461685        {
    16471686            rc = drvAudioControlHstIn(pThis, pHstStrmIn,
    1648                                       fEnable ? PDMAUDIOSTREAMCMD_ENABLE : PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
     1687                                      fEnable ? PDMAUDIOSTREAMCMD_ENABLE : PDMAUDIOSTREAMCMD_DISABLE);
    16491688            if (RT_SUCCESS(rc))
    16501689                pGstStrmIn->State.fActive = fEnable;
     
    18911930    while ((pHstStrmOut = drvAudioFindAnyHstOut(pThis, pHstStrmOut)))
    18921931    {
    1893         drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
     1932        drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
    18941933        pThis->pHostDrvAudio->pfnFiniOut(pThis->pHostDrvAudio, pHstStrmOut);
    18951934    }
     
    18991938    while ((pHstStrmIn = drvAudioFindNextHstIn(pThis, pHstStrmIn)))
    19001939    {
    1901         drvAudioControlHstIn(pThis, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
     1940        drvAudioControlHstIn(pThis, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE);
    19021941        pThis->pHostDrvAudio->pfnFiniIn(pThis->pHostDrvAudio, pHstStrmIn);
    19031942    }
     
    19862025static DECLCALLBACK(void) drvAudioSuspend(PPDMDRVINS pDrvIns)
    19872026{
    1988     drvAudioStateHandler(pDrvIns, PDMAUDIOSTREAMCMD_DISABLE);
     2027    drvAudioStateHandler(pDrvIns, PDMAUDIOSTREAMCMD_PAUSE);
    19892028}
    19902029
     
    19962035static DECLCALLBACK(void) drvAudioResume(PPDMDRVINS pDrvIns)
    19972036{
    1998     drvAudioStateHandler(pDrvIns, PDMAUDIOSTREAMCMD_ENABLE);
     2037    drvAudioStateHandler(pDrvIns, PDMAUDIOSTREAMCMD_RESUME);
    19992038}
    20002039
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