VirtualBox

Changeset 64050 in vbox


Ignore:
Timestamp:
Sep 27, 2016 2:41:59 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110977
Message:

Audio/DrvAudio.cpp: A bit of cleanup in drvAudioStreamControlInternal(), logging tweaks.

File:
1 edited

Legend:

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

    r64044 r64050  
    329329                }
    330330
    331                 pGstStream->fStatus |= PDMAUDIOSTRMSTS_FLAG_ENABLED;
     331                if (RT_SUCCESS(rc))
     332                    pGstStream->fStatus |= PDMAUDIOSTRMSTS_FLAG_ENABLED;
    332333            }
    333334            break;
     
    335336
    336337        case PDMAUDIOSTREAMCMD_DISABLE:
    337         case PDMAUDIOSTREAMCMD_PAUSE:
    338338        {
    339339            if (pGstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
    340340            {
    341                 /* Is the guest side stream still active?
    342                  * Mark the host stream as pending disable and bail out. */
    343341                if (pHstStream)
    344342                {
    345                     LogFunc(("[%s] Pending disable/pause\n", pHstStream->szName));
    346                     pHstStream->fStatus |= PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
     343                    /*
     344                     * For playback (output) streams first mark the host stream as pending disable,
     345                     * so that the rest of the remaining audio data will be played first before
     346                     * closing the stream.
     347                     */
     348                    if (pHstStream->enmDir == PDMAUDIODIR_OUT)
     349                    {
     350                        LogFunc(("[%s] Pending disable/pause\n", pHstStream->szName));
     351                        pHstStream->fStatus |= PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
     352                    }
     353
     354                    /* Can we close the host stream as well (not in pending disable mode)? */
     355                    if (!(pHstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE))
     356                        rc = drvAudioStreamControlInternalBackend(pThis, pHstStream, PDMAUDIOSTREAMCMD_DISABLE);
    347357                }
    348358
    349                 if (enmStreamCmd == PDMAUDIOSTREAMCMD_DISABLE)
    350                 {
     359                if (RT_SUCCESS(rc))
    351360                    pGstStream->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_ENABLED;
    352                 }
    353                 else if (enmStreamCmd == PDMAUDIOSTREAMCMD_PAUSE)
     361            }
     362            break;
     363        }
     364
     365        case PDMAUDIOSTREAMCMD_PAUSE:
     366        {
     367            if (!(pGstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_PAUSED))
     368            {
     369                if (pHstStream)
     370                    rc = drvAudioStreamControlInternalBackend(pThis, pHstStream, PDMAUDIOSTREAMCMD_PAUSE);
     371
     372                if (RT_SUCCESS(rc))
    354373                    pGstStream->fStatus |= PDMAUDIOSTRMSTS_FLAG_PAUSED;
    355                 else
    356                     AssertFailedBreakStmt(rc = VERR_NOT_IMPLEMENTED);
    357             }
    358 
    359             if (   pHstStream
    360                 && !(pHstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE))
    361             {
    362                 rc = drvAudioStreamControlInternalBackend(pThis, pHstStream, enmStreamCmd);
    363                 if (RT_SUCCESS(rc))
    364                     pHstStream->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE;
    365374            }
    366375            break;
     
    374383                    rc = drvAudioStreamControlInternalBackend(pThis, pHstStream, PDMAUDIOSTREAMCMD_RESUME);
    375384
    376                 pGstStream->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PAUSED;
     385                if (RT_SUCCESS(rc))
     386                    pGstStream->fStatus &= ~PDMAUDIOSTRMSTS_FLAG_PAUSED;
    377387            }
    378388            break;
     
    900910 * @param   pThis               Pointer to driver instance.
    901911 * @param   pStream             Stream to iterate.
    902  *
    903  * @remark
    904912 */
    905913static int drvAudioStreamIterateInternal(PDRVAUDIO pThis, PPDMAUDIOSTREAM pStream)
     
    912920    PPDMAUDIOSTREAM pHstStream = drvAudioGetHostStream(pStream);
    913921    AssertPtr(pHstStream);
    914     PPDMAUDIOSTREAM pGstStream = pHstStream->pPair;
     922    PPDMAUDIOSTREAM pGstStream = pHstStream ? pHstStream->pPair : NULL;
    915923    AssertPtr(pGstStream);
    916924
     
    937945    }
    938946
     947    Log3Func(("[%s] fStatus=0x%x\n", pHstStream->szName, pHstStream->fStatus));
     948
     949    /* Not enabled or paused? Skip iteration. */
     950    if (   !(pHstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED)
     951        ||  (pHstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_PAUSED))
     952    {
     953        return VINF_SUCCESS;
     954    }
     955
    939956    /* Whether to try closing a pending to close stream. */
    940957    bool fTryClosePending = false;
     
    952969            /* Has the host captured any samples which were not mixed to the guest side yet? */
    953970            uint32_t cSamplesCaptured = AudioMixBufUsed(&pHstStream->MixBuf);
    954 
    955             Log3Func(("[%s] %RU32 samples captured\n", pHstStream->szName, cSamplesCaptured));
    956 
    957971            if (cSamplesCaptured)
    958972            {
     
    960974                 * So try mixing not yet mixed host-side samples to the guest-side buffer. */
    961975                rc = AudioMixBufMixToParent(&pHstStream->MixBuf, cSamplesCaptured, &cSamplesMixed);
    962                 if (   RT_SUCCESS(rc)
    963                     && cSamplesMixed)
    964                 {
    965                     Log3Func(("[%s] %RU32 captured samples mixed\n", pHstStream->szName, cSamplesMixed));
    966                 }
    967                 else if (RT_FAILURE(rc))
     976                if (RT_FAILURE(rc))
    968977                {
    969978                    if (rc == VERR_BUFFER_OVERFLOW)
     
    972981                        LogRel2(("Audio: Mixing to guest input stream '%s' failed: %Rrc\n", pGstStream->szName, rc));
    973982                }
     983
     984                Log3Func(("[%s] %RU32/%RU32 input samples mixed, rc=%Rrc\n", pHstStream->szName, cSamplesMixed, cSamplesCaptured, rc));
    974985            }
    975986            else
     
    986997                && cSamplesMixed)
    987998            {
    988                 Log3Func(("[%s] %RU32 samples mixed, guest has %RU32 samples left (%RU32 live)\n",
     999                Log3Func(("[%s] %RU32 output samples mixed, guest has %RU32 samples left (%RU32 live)\n",
    9891000                          pHstStream->szName, cSamplesMixed,
    9901001                          AudioMixBufUsed(&pGstStream->MixBuf), AudioMixBufLive(&pGstStream->MixBuf)));
     
    10201031                }
    10211032                else
    1022                     LogFunc(("%s: Backend vetoed against closing output stream, rc=%Rrc\n", pHstStream->szName, rc));
     1033                    LogFunc(("[%s] Backend vetoed against closing pending output stream, rc=%Rrc\n", pHstStream->szName, rc));
    10231034            }
    10241035        }
     
    10311042
    10321043    if (RT_FAILURE(rc))
    1033         LogFunc(("Failed with %Rrc\n", rc));
     1044        LogFunc(("[%s] Failed with %Rrc\n",  pHstStream->szName, rc));
    10341045
    10351046    return rc;
     
    11931204               pStream->szName, pStream->enmDir));
    11941205
    1195     Log3Func(("[%s]\n", pStream->szName));
    1196 
    11971206    uint32_t cSamplesCaptured = 0;
    11981207
     
    12321241                {
    12331242#ifdef VBOX_WITH_STATISTICS
     1243                    STAM_COUNTER_ADD(&pThis->Stats.TotalSamplesCaptured,  cSamplesCaptured);
    12341244                    STAM_COUNTER_ADD(&pHstStream->In.StatSamplesCaptured, cSamplesCaptured);
    12351245#endif
    12361246                }
    12371247            }
    1238 
    1239             Log3Func(("[%s] strmSts=0x%x, cSamplesCaptured=%RU32, rc=%Rrc\n", pHstStream->szName, stsBackend, cSamplesCaptured, rc));
    1240         }
     1248        }
     1249
     1250        Log3Func(("[%s] stsBackend=0x%x, cSamplesLive=%RU32, cSamplesCaptured=%RU32, rc=%Rrc\n",
     1251                  pHstStream->szName, stsBackend, cSamplesLive, cSamplesCaptured, rc));
    12411252
    12421253    } while (0);
     
    16491660    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    16501661
    1651     if (!pStream)
    1652     {
    1653         if (pcbRead)
    1654             *pcbRead = 0;
    1655         return VINF_SUCCESS;
    1656     }
    1657 
    1658     AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
    1659     AssertReturn(cbBuf,    VERR_INVALID_PARAMETER);
     1662    AssertPtrReturn(pStream, VERR_INVALID_POINTER);
     1663    AssertPtrReturn(pvBuf,   VERR_INVALID_POINTER);
     1664    AssertReturn(cbBuf,      VERR_INVALID_PARAMETER);
    16601665    /* pcbWritten is optional. */
    16611666
     
    16881693
    16891694        PPDMAUDIOSTREAM pGstStream = pHstStream->pPair;
    1690 
    1691         AssertMsg(pHstStream->fStatus & PDMAUDIOSTRMSTS_FLAG_ENABLED,
    1692                   ("Reading from disabled host input stream '%s' not possible\n", pHstStream->szName));
     1695        AssertPtr(pGstStream);
    16931696
    16941697        pGstStream->In.tsLastReadMS = RTTimeMilliTS();
    1695 
    1696         Log3Func(("%s\n", pStream->szName));
    16971698
    16981699        /*
     
    17161717        }
    17171718
    1718         Log3Func(("cRead=%RU32 (%RU32 bytes), rc=%Rrc\n", cRead, AUDIOMIXBUF_S2B(&pGstStream->MixBuf, cRead), rc));
    1719 
    17201719    } while (0);
     1720
     1721    Log3Func(("[%s] cbRead=%RU32, rc=%Rrc\n", pStream->szName, cbRead, rc));
    17211722
    17221723    int rc2 = RTCritSectLeave(&pThis->CritSect);
     
    25152516#ifdef VBOX_WITH_STATISTICS
    25162517        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalStreamsActive,   "TotalStreamsActive",
    2517                                   STAMUNIT_COUNT, "Active input streams.");
     2518                                  STAMUNIT_COUNT, "Total active audio streams.");
    25182519        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalStreamsCreated,  "TotalStreamsCreated",
    2519                                   STAMUNIT_COUNT, "Total created input streams.");
     2520                                  STAMUNIT_COUNT, "Total created audio streams.");
    25202521        PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->Stats.TotalSamplesPlayed,   "TotalSamplesPlayed",
    25212522                                  STAMUNIT_COUNT, "Total samples played.");
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