VirtualBox

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


Ignore:
Timestamp:
Mar 7, 2019 3:10:01 PM (6 years ago)
Author:
vboxsync
Message:

Audio/Mixer: Centralized a mixer stream's internal status updating by implementing audioMixerStreamUpdateStatus() and adding AUDMIXSTREAM_STATUS_ flags. Also check this status in audioMixerSinkMultiplexSync() when writing to a mixer stream's buffer.

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

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

    r77184 r77602  
    105105int audioMixerStreamCtlInternal(PAUDMIXSTREAM pMixStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
    106106static void audioMixerStreamDestroyInternal(PAUDMIXSTREAM pStream);
     107static int audioMixerStreamUpdateStatus(PAUDMIXSTREAM pMixStream);
    107108
    108109
     
    11481149        Log3Func(("[%s] No recording source specified, skipping ...\n", pSink->pszName));
    11491150    }
    1150     else if (!DrvAudioHlpStreamStatusCanRead(
    1151        pStreamRecSource->pConn->pfnStreamGetStatus(pStreamRecSource->pConn, pStreamRecSource->pStream)))
     1151    else if (!(pStreamRecSource->fStatus & AUDMIXSTREAM_STATUS_ENABLED))
    11521152    {
    11531153        Log3Func(("[%s] Stream '%s' disabled, skipping ...\n", pSink->pszName, pStreamRecSource->pszName));
     
    15941594        return rc;
    15951595
     1596    /* Update each mixing sink stream's status. */
     1597    PAUDMIXSTREAM pMixStream;
     1598    RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
     1599    {
     1600        int rc2 = audioMixerStreamUpdateStatus(pMixStream);
     1601        AssertRC(rc2);
     1602    }
     1603
    15961604    /* Number of disabled streams of this sink. */
    15971605    uint8_t cStreamsDisabled = pSink->cStreams;
     
    16161624        if (RT_SUCCESS(rc))
    16171625        {
    1618             PAUDMIXSTREAM pMixStream;
    16191626            RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    16201627            {
     
    16431650    }
    16441651
    1645     PAUDMIXSTREAM pMixStream, pMixStreamNext;
    1646     RTListForEachSafe(&pSink->lstStreams, pMixStream, pMixStreamNext, AUDMIXSTREAM, Node)
     1652    RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    16471653    {
    16481654        /* Input sink and not the recording source? Skip. */
     
    16591665        uint32_t cfProc = 0;
    16601666
    1661         if (!DrvAudioHlpStreamStatusIsReady(pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream)))
     1667        if (!(pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED))
    16621668            continue;
    16631669
     
    16931699        }
    16941700
    1695         PDMAUDIOSTREAMSTS strmSts = pConn->pfnStreamGetStatus(pConn, pStream);
     1701        const PDMAUDIOSTREAMSTS streamStatusNew = pConn->pfnStreamGetStatus(pConn, pStream);
    16961702
    16971703        /* Is the stream enabled or in pending disable state?
    16981704         * Don't consider this stream as being disabled then. */
    1699         if (   (strmSts & PDMAUDIOSTREAMSTS_FLAG_ENABLED)
    1700             || (strmSts & PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE))
     1705        if (   (streamStatusNew & PDMAUDIOSTREAMSTS_FLAG_ENABLED)
     1706            || (streamStatusNew & PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE))
    17011707        {
    17021708            cStreamsDisabled--;
    17031709        }
     1710        /* Note: The mixer stream's internal status will be updated in the next iteration of this function. */
    17041711
    17051712        Log3Func(("\t%s: cPlayed/cCaptured=%RU32, rc2=%Rrc\n", pStream->szName, cfProc, rc2));
     
    18141821
    18151822    if (   !cbToWrite
    1816         || !DrvAudioHlpStreamStatusCanWrite(pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream)))
     1823        || !(pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED))
    18171824    {
    18181825        if (pcbWritten)
     
    19211928    RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    19221929    {
    1923         if (!DrvAudioHlpStreamStatusCanWrite(pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream)))
     1930        if (!(pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)) /* Mixing stream not enabled? Skip handling. */
     1931        {
     1932            Log3Func(("[%s] Stream '%s' disabled, skipping ...\n", pSink->pszName, pMixStream->pszName));
    19241933            continue;
     1934        }
    19251935
    19261936        cbToWriteMin = RT_MIN(cbBuf, RT_MIN(cbToWriteMin, (uint32_t)RTCircBufFree(pMixStream->pCircBuf)));
     
    19341944        RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    19351945        {
     1946            if (!(pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)) /* Mixing stream not enabled? Skip handling. */
     1947                continue;
     1948
    19361949            PRTCIRCBUF pCircBuf = pMixStream->pCircBuf;
    19371950            void *pvChunk;
     
    20602073
    20612074/**
     2075 * Updates a mixer stream's internal status.
     2076 *
     2077 * @returns VBox status code.
     2078 * @param   pMixStream          Mixer stream to to update internal status for.
     2079 */
     2080static int audioMixerStreamUpdateStatus(PAUDMIXSTREAM pMixStream)
     2081{
     2082    pMixStream->fStatus = AUDMIXSTREAM_STATUS_NONE;
     2083
     2084    if (pMixStream->pConn) /* Audio connector available? */
     2085    {
     2086        const uint32_t fStreamStatus = pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream);
     2087
     2088        if (DrvAudioHlpStreamStatusIsReady(fStreamStatus))
     2089            pMixStream->fStatus |= AUDMIXSTREAM_STATUS_ENABLED;
     2090
     2091        AssertPtr(pMixStream->pSink);
     2092        switch (pMixStream->pSink->enmDir)
     2093        {
     2094            case AUDMIXSINKDIR_INPUT:
     2095                if (DrvAudioHlpStreamStatusCanRead(fStreamStatus))
     2096                   pMixStream->fStatus |= AUDMIXSTREAM_STATUS_CAN_READ;
     2097                break;
     2098
     2099            case AUDMIXSINKDIR_OUTPUT:
     2100                if (DrvAudioHlpStreamStatusCanWrite(fStreamStatus))
     2101                   pMixStream->fStatus |= AUDMIXSTREAM_STATUS_CAN_WRITE;
     2102                break;
     2103
     2104            default:
     2105                AssertFailedReturn(VERR_NOT_IMPLEMENTED);
     2106                break;
     2107        }
     2108    }
     2109
     2110    LogFlowFunc(("[%s] -> 0x%x\n", pMixStream->pszName, pMixStream->fStatus));
     2111    return VINF_SUCCESS;
     2112}
     2113
     2114/**
    20622115 * Controls a mixer stream.
    20632116 *
  • trunk/src/VBox/Devices/Audio/AudioMixer.h

    r76777 r77602  
    5252/** No flags specified. */
    5353#define AUDMIXSTREAM_FLAG_NONE                  0
     54/** The mixing stream is flagged as being enabled (active). */
     55#define AUDMIXSTREAM_FLAG_ENABLED               RT_BIT(0)
     56
     57/** Defines an audio mixer stream's internal status. */
     58#define AUDMIXSTREAMSTATUS uint32_t
     59
     60/** No status set. */
     61#define AUDMIXSTREAM_STATUS_NONE                0
     62/** The mixing stream is enabled (active). */
     63#define AUDMIXSTREAM_STATUS_ENABLED             RT_BIT(0)
     64/** The mixing stream can be read from. */
     65#define AUDMIXSTREAM_STATUS_CAN_READ            RT_BIT(1)
     66/** The mixing stream can be written to. */
     67#define AUDMIXSTREAM_STATUS_CAN_WRITE           RT_BIT(2)
     68
    5469
    5570/** Prototype needed for AUDMIXSTREAM struct definition. */
     
    7186    /** Stream flags of type AUDMIXSTREAM_FLAG_. */
    7287    uint32_t                fFlags;
     88    /** Stream status of type AUDMIXSTREAM_STATUS_. */
     89    uint32_t                fStatus;
    7390    /** Pointer to audio connector being used. */
    7491    PPDMIAUDIOCONNECTOR     pConn;
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