VirtualBox

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


Ignore:
Timestamp:
May 5, 2021 6:27:18 PM (4 years ago)
Author:
vboxsync
Message:

DrvAudio,Mixer: Changed PDMIAUDIOCONNECTOR::pfnStreamGetStatus into pfnStreamGetState and defined a simpler state enum (PDMAUDIOSTREAMSTATE) that fits the Mixer's need and nothing more. PDMAUDIOSTREAM_STS_XXX will soon be DrvAudio internal. Changed some state checks in the mixer from ENABLED and ENABLED+WRITABLE/READABLE (probably more that needs adjusting). bugref:9890

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

Legend:

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

    r88724 r88884  
    12131213        Log3Func(("[%s] No recording source specified, skipping ...\n", pSink->pszName));
    12141214    }
    1215     else if (!(pStreamRecSource->fStatus & AUDMIXSTREAM_STATUS_ENABLED))
     1215    else if (!(pStreamRecSource->fStatus & AUDMIXSTREAM_STATUS_ENABLED)) /** @todo r=bird: AUDMIXSTREAM_STATUS_CAN_READ ?*/
    12161216    {
    12171217        Log3Func(("[%s] Stream '%s' disabled, skipping ...\n", pSink->pszName, pStreamRecSource->pszName));
     
    16921692            if (RT_SUCCESS(rc2))
    16931693            {
     1694                /** @todo r=bird: Check for AUDMIXSTREAM_STATUS_CAN_READ? */
    16941695                rc2 = pMixStream->pConn->pfnStreamCapture(pMixStream->pConn, pMixStream->pStream, &cFramesCaptured);
    16951696                if (RT_SUCCESS(rc2))
     
    17341735            if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)
    17351736            {
    1736                 uint32_t const fSts = pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream);
    1737                 if (fSts & (PDMAUDIOSTREAM_STS_ENABLED | PDMAUDIOSTREAM_STS_PENDING_DISABLE))
     1737                PDMAUDIOSTREAMSTATE const enmState = pMixStream->pConn->pfnStreamGetState(pMixStream->pConn, pMixStream->pStream);
     1738                if (enmState >= PDMAUDIOSTREAMSTATE_ENABLED)
    17381739                    cStreamsDisabled--;
    17391740            }
     
    17771778        AssertRC(rc2);
    17781779
    1779         if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)
     1780        if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_CAN_WRITE)
    17801781        {
    17811782            uint32_t const cbWritable = pMixStream->pConn->pfnStreamGetWritable(pMixStream->pConn, pMixStream->pStream);
     
    18101811            RTListForEach(&pSink->lstStreams, pMixStream, AUDMIXSTREAM, Node)
    18111812            {
    1812                 if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)
     1813                if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_CAN_WRITE)
    18131814                {
    18141815                    uint32_t offSrcFrame = 0;
     
    18991900            if (pMixStream->fStatus & AUDMIXSTREAM_STATUS_ENABLED)
    19001901            {
    1901                 uint32_t const fSts = pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream);
    1902                 if (fSts & (PDMAUDIOSTREAM_STS_ENABLED | PDMAUDIOSTREAM_STS_PENDING_DISABLE))
     1902                PDMAUDIOSTREAMSTATE const enmState = pMixStream->pConn->pfnStreamGetState(pMixStream->pConn, pMixStream->pStream);
     1903                if (enmState >= PDMAUDIOSTREAMSTATE_ENABLED)
    19031904                    cStreamsDisabled--;
    19041905            }
     
    20812082 * Updates a mixer stream's internal status.
    20822083 *
     2084 * This may perform a stream re-init if the driver requests it, in which case
     2085 * this may take a little while longer than usual...
     2086 *
    20832087 * @returns VBox status code.
    20842088 * @param   pMixStream          Mixer stream to to update internal status for.
     
    20952099    {
    20962100        PPDMAUDIOSTREAM const pStream = pMixStream->pStream;
    2097         PAUDMIXSINK const     pSink   = pMixStream->pSink;
    2098         AssertPtr(pSink);
    20992101
    21002102        /*
     
    21022104         * Do re-init if needed and fetch the status again afterwards.
    21032105         */
    2104         uint32_t fStreamStatus = pConn->pfnStreamGetStatus(pConn, pStream);
    2105         if (!(fStreamStatus & PDMAUDIOSTREAM_STS_NEED_REINIT))
     2106        PDMAUDIOSTREAMSTATE enmState = pConn->pfnStreamGetState(pConn, pStream);
     2107        if (enmState != PDMAUDIOSTREAMSTATE_NEED_REINIT)
    21062108        { /* likely */ }
    21072109        else
     
    21092111            LogFunc(("[%s] needs re-init...\n", pMixStream->pszName));
    21102112            int rc = pConn->pfnStreamReInit(pConn, pStream);
    2111             fStreamStatus = pConn->pfnStreamGetStatus(pConn, pStream);
    2112             LogFunc(("[%s] re-init returns %Rrc and %#x.\n", pMixStream->pszName, rc, fStreamStatus)); RT_NOREF(rc);
     2113            enmState = pConn->pfnStreamGetState(pConn, pStream);
     2114            LogFunc(("[%s] re-init returns %Rrc and %d.\n", pMixStream->pszName, rc, enmState));
     2115
     2116            PAUDMIXSINK const pSink = pMixStream->pSink;
     2117            AssertPtr(pSink);
    21132118            if (pSink->enmDir == AUDMIXSINKDIR_OUTPUT)
    21142119            {
     
    21222127         * Translate the status to mixer speak.
    21232128         */
    2124         if (PDMAudioStrmStatusIsReady(fStreamStatus))
    2125             pMixStream->fStatus |= AUDMIXSTREAM_STATUS_ENABLED;
    2126 
    2127         switch (pSink->enmDir)
    2128         {
    2129             case AUDMIXSINKDIR_INPUT:
    2130                 if (PDMAudioStrmStatusCanRead(fStreamStatus))
    2131                    pMixStream->fStatus |= AUDMIXSTREAM_STATUS_CAN_READ;
     2129        AssertMsg(enmState > PDMAUDIOSTREAMSTATE_INVALID && enmState < PDMAUDIOSTREAMSTATE_END, ("%d\n", enmState));
     2130        switch (enmState)
     2131        {
     2132            case PDMAUDIOSTREAMSTATE_NOT_WORKING:
     2133            case PDMAUDIOSTREAMSTATE_NEED_REINIT:
     2134            case PDMAUDIOSTREAMSTATE_INACTIVE:
     2135                pMixStream->fStatus = AUDMIXSTREAM_STATUS_NONE;
    21322136                break;
    2133 
    2134             case AUDMIXSINKDIR_OUTPUT:
    2135                 if (PDMAudioStrmStatusCanWrite(fStreamStatus))
    2136                    pMixStream->fStatus |= AUDMIXSTREAM_STATUS_CAN_WRITE;
     2137            case PDMAUDIOSTREAMSTATE_ENABLED:
     2138                pMixStream->fStatus = AUDMIXSTREAM_STATUS_ENABLED;
    21372139                break;
    2138 
    2139             default:
    2140                 AssertFailedReturn(VERR_NOT_IMPLEMENTED);
     2140            case PDMAUDIOSTREAMSTATE_ENABLED_READABLE:
     2141                Assert(pMixStream->pSink->enmDir == AUDMIXSINKDIR_INPUT);
     2142                pMixStream->fStatus = AUDMIXSTREAM_STATUS_ENABLED | AUDMIXSTREAM_STATUS_CAN_READ;
     2143                break;
     2144            case PDMAUDIOSTREAMSTATE_ENABLED_WRITABLE:
     2145                Assert(pMixStream->pSink->enmDir == AUDMIXSINKDIR_OUTPUT);
     2146                pMixStream->fStatus = AUDMIXSTREAM_STATUS_ENABLED | AUDMIXSTREAM_STATUS_CAN_WRITE;
     2147                break;
     2148            /* no default */
     2149            case PDMAUDIOSTREAMSTATE_INVALID:
     2150            case PDMAUDIOSTREAMSTATE_END:
     2151            case PDMAUDIOSTREAMSTATE_32BIT_HACK:
    21412152                break;
    21422153        }
     
    22602271}
    22612272
    2262 /**
    2263  * Returns whether a mixer stream currently is active (playing/recording) or not.
    2264  *
    2265  * @returns @c true if playing/recording, @c false if not.
    2266  * @param   pMixStream          Mixer stream to return status for.
    2267  */
    2268 bool AudioMixerStreamIsActive(PAUDMIXSTREAM pMixStream)
    2269 {
    2270     int rc2 = RTCritSectEnter(&pMixStream->CritSect);
    2271     if (RT_FAILURE(rc2))
    2272         return false;
    2273 
    2274     AssertPtr(pMixStream->pConn);
    2275     AssertPtr(pMixStream->pStream);
    2276 
    2277     bool fIsActive;
    2278 
    2279     if (   pMixStream->pConn
    2280         && pMixStream->pStream
    2281         && (pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream) & PDMAUDIOSTREAM_STS_ENABLED))
    2282         fIsActive = true;
    2283     else
    2284         fIsActive = false;
    2285 
    2286     rc2 = RTCritSectLeave(&pMixStream->CritSect);
    2287     AssertRC(rc2);
    2288 
    2289     return fIsActive;
    2290 }
    2291 
    2292 /**
    2293  * Returns whether a mixer stream is valid (e.g. initialized and in a working state) or not.
    2294  *
    2295  * @returns @c true if valid, @c false if not.
    2296  * @param   pMixStream          Mixer stream to return status for.
    2297  */
    2298 bool AudioMixerStreamIsValid(PAUDMIXSTREAM pMixStream)
    2299 {
    2300     if (!pMixStream)
    2301         return false;
    2302 
    2303     int rc2 = RTCritSectEnter(&pMixStream->CritSect);
    2304     if (RT_FAILURE(rc2))
    2305         return false;
    2306 
    2307     bool fIsValid;
    2308 
    2309     if (   pMixStream->pConn
    2310         && pMixStream->pStream
    2311         && (pMixStream->pConn->pfnStreamGetStatus(pMixStream->pConn, pMixStream->pStream) & PDMAUDIOSTREAM_STS_INITIALIZED))
    2312         fIsValid = true;
    2313     else
    2314         fIsValid = false;
    2315 
    2316     rc2 = RTCritSectLeave(&pMixStream->CritSect);
    2317     AssertRC(rc2);
    2318 
    2319     return fIsValid;
    2320 }
    2321 
  • trunk/src/VBox/Devices/Audio/AudioMixer.h

    r88452 r88884  
    7070#define AUDMIXSTREAMSTATUS uint32_t
    7171
     72/** @name AUDMIXSTREAM_STATUS_XXX - mixer stream status.
     73 * (This is a destilled version of PDMAUDIOSTREAM_STS_XXX.)
     74 * @{ */
    7275/** No status set. */
    7376#define AUDMIXSTREAM_STATUS_NONE                0
    7477/** The mixing stream is enabled (active). */
    7578#define AUDMIXSTREAM_STATUS_ENABLED             RT_BIT(0)
    76 /** The mixing stream can be read from. */
     79/** The mixing stream can be read from.
     80 * Always set together with AUDMIXSTREAM_STATUS_ENABLED. */
    7781#define AUDMIXSTREAM_STATUS_CAN_READ            RT_BIT(1)
    78 /** The mixing stream can be written to. */
     82/** The mixing stream can be written to.
     83 * Always set together with AUDMIXSTREAM_STATUS_ENABLED. */
    7984#define AUDMIXSTREAM_STATUS_CAN_WRITE           RT_BIT(2)
     85/** @} */
    8086
    8187
     
    295301int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
    296302void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream, PPDMDEVINS pDevIns);
    297 bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
    298 bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
    299303
    300304#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixer_h */
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r88861 r88884  
    19891989            LogFunc(("[%s] Acquired host format: %s\n",
    19901990                     pStreamEx->Core.szName, PDMAudioStrmCfgToString(&CfgHostAcq, szTmp, sizeof(szTmp)) ));
    1991             if (true) /** @todo Validate (re-)acquired configuration with pStreamEx->Core.Host.Cfg? */
     1991            /** @todo Validate (re-)acquired configuration with pStreamEx->Core.Host.Cfg?
     1992             * drvAudioStreamInitInternal() does some setup and a bunch of
     1993             * validations + adjustments of the stream config, so this surely is quite
     1994             * optimistic. */
     1995            if (true)
    19921996            {
    19931997                /*
     
    30813085
    30823086/**
    3083  * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamGetStatus}
    3084  */
    3085 static DECLCALLBACK(uint32_t) drvAudioStreamGetStatus(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream)
    3086 {
    3087     PDRVAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVAUDIO, IAudioConnector);
    3088     AssertPtr(pThis);
    3089 
    3090     /** @todo r=bird: It is not documented that we ignore NULL streams...  Why is
    3091      *        this necessary? */
    3092     if (!pStream)
    3093         return PDMAUDIOSTREAM_STS_NONE;
     3087 * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamGetState}
     3088 */
     3089static DECLCALLBACK(PDMAUDIOSTREAMSTATE) drvAudioStreamGetState(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream)
     3090{
     3091    PDRVAUDIO       pThis     = RT_FROM_MEMBER(pInterface, DRVAUDIO, IAudioConnector);
    30943092    PDRVAUDIOSTREAM pStreamEx = (PDRVAUDIOSTREAM)pStream;
    3095     AssertPtrReturn(pStreamEx, PDMAUDIOSTREAM_STS_NONE);
    3096     AssertReturn(pStreamEx->Core.uMagic == PDMAUDIOSTREAM_MAGIC, PDMAUDIOSTREAM_STS_NONE);
    3097     AssertReturn(pStreamEx->uMagic      == DRVAUDIOSTREAM_MAGIC, PDMAUDIOSTREAM_STS_NONE);
    3098 
     3093    AssertPtrReturn(pStreamEx, PDMAUDIOSTREAMSTATE_INVALID);
     3094    AssertReturn(pStreamEx->Core.uMagic == PDMAUDIOSTREAM_MAGIC, PDMAUDIOSTREAMSTATE_INVALID);
     3095    AssertReturn(pStreamEx->uMagic      == DRVAUDIOSTREAM_MAGIC, PDMAUDIOSTREAMSTATE_INVALID);
     3096
     3097    /*
     3098     * Get the status mask.
     3099     */
    30993100    int rc = RTCritSectEnter(&pThis->CritSect);
    3100     AssertRCReturn(rc, PDMAUDIOSTREAM_STS_NONE);
    3101 
    3102     uint32_t fStrmStatus = pStreamEx->fStatus;
     3101    AssertRCReturn(rc, PDMAUDIOSTREAMSTATE_INVALID);
     3102
     3103    uint32_t const    fStrmStatus = pStreamEx->fStatus;
     3104    PDMAUDIODIR const enmDir      = pStreamEx->Guest.Cfg.enmDir;
    31033105
    31043106    RTCritSectLeave(&pThis->CritSect);
     3107
     3108    /*
     3109     * Translate it to state enum value.
     3110     */
     3111    PDMAUDIOSTREAMSTATE enmState;
     3112    if (!(fStrmStatus & PDMAUDIOSTREAM_STS_NEED_REINIT))
     3113    {
     3114        if (fStrmStatus & PDMAUDIOSTREAM_STS_INITIALIZED)
     3115        {
     3116            if (fStrmStatus & PDMAUDIOSTREAM_STS_ENABLED)
     3117                enmState = enmDir == PDMAUDIODIR_IN ? PDMAUDIOSTREAMSTATE_ENABLED_READABLE : PDMAUDIOSTREAMSTATE_ENABLED_WRITABLE;
     3118            else
     3119                enmState = PDMAUDIOSTREAMSTATE_INACTIVE;
     3120        }
     3121        else
     3122            enmState = PDMAUDIOSTREAMSTATE_NOT_WORKING;
     3123    }
     3124    else
     3125        enmState = PDMAUDIOSTREAMSTATE_NEED_REINIT;
     3126
    31053127#ifdef LOG_ENABLED
    31063128    char szStreamSts[DRVAUDIO_STATUS_STR_MAX];
    31073129#endif
    3108     Log3Func(("[%s] %s\n", pStreamEx->Core.szName, drvAudioStreamStatusToStr(szStreamSts, fStrmStatus)));
    3109     return fStrmStatus;
     3130    Log3Func(("[%s] returns %d (%s)\n", pStreamEx->Core.szName, enmState, drvAudioStreamStatusToStr(szStreamSts, fStrmStatus)));
     3131    return enmState;
    31103132}
    31113133
     
    46764698    pThis->IAudioConnector.pfnStreamGetReadable = drvAudioStreamGetReadable;
    46774699    pThis->IAudioConnector.pfnStreamGetWritable = drvAudioStreamGetWritable;
    4678     pThis->IAudioConnector.pfnStreamGetStatus   = drvAudioStreamGetStatus;
     4700    pThis->IAudioConnector.pfnStreamGetState    = drvAudioStreamGetState;
    46794701    pThis->IAudioConnector.pfnStreamSetVolume   = drvAudioStreamSetVolume;
    46804702    pThis->IAudioConnector.pfnStreamPlay        = drvAudioStreamPlay;
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