VirtualBox

Changeset 89723 in vbox


Ignore:
Timestamp:
Jun 15, 2021 8:13:35 PM (3 years ago)
Author:
vboxsync
Message:

DevIchAc97: Some small code cleanups. bugref:9890

File:
1 edited

Legend:

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

    r89721 r89723  
    848848 * @param   pStreamCC           The AC'97 stream to retrieve size for (ring-3).
    849849 */
    850 static uint32_t ichac97R3StreamGetUsed(PAC97STREAMR3 pStreamCC)
    851 {
    852     if (!pStreamCC->State.pCircBuf)
    853         return 0;
    854 
    855     return (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf);
    856 }
     850DECLINLINE(uint32_t) ichac97R3StreamGetUsed(PAC97STREAMR3 pStreamCC)
     851{
     852    PRTCIRCBUF const pCircBuf = pStreamCC->State.pCircBuf;
     853    if (pCircBuf)
     854        return (uint32_t)RTCircBufUsed(pCircBuf);
     855    return 0;
     856}
     857
    857858
    858859/**
     
    862863 * @param   pStreamCC           AC'97 stream to retrieve size for (ring-3).
    863864 */
    864 static uint32_t ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC)
    865 {
    866     if (!pStreamCC->State.pCircBuf)
    867         return 0;
    868 
    869     return (uint32_t)RTCircBufFree(pStreamCC->State.pCircBuf);
    870 }
     865DECLINLINE(uint32_t) ichac97R3StreamGetFree(PAC97STREAMR3 pStreamCC)
     866{
     867    PRTCIRCBUF const pCircBuf = pStreamCC->State.pCircBuf;
     868    if (pCircBuf)
     869        return (uint32_t)RTCircBufFree(pCircBuf);
     870    return 0;
     871}
     872
    871873
    872874# if 0 /* Unused */
     
    10151017                                   PAC97STREAMR3 pStreamCC, uint32_t cbToProcessMax, bool fWriteSilence, bool fInput)
    10161018{
    1017     if (!cbToProcessMax)
     1019    if (RT_LIKELY(cbToProcessMax > 0))
     1020        Assert(PDMAudioPropsIsSizeAligned(&pStreamCC->State.Cfg.Props, cbToProcessMax));
     1021    else
    10181022        return VINF_SUCCESS;
    10191023
    1020 #ifdef VBOX_STRICT
    1021     const unsigned cbFrame = PDMAudioPropsBytesPerFrame(&pStreamCC->State.Cfg.Props);
    1022 #endif
    1023 
    1024     /* Make sure to only process an integer number of audio frames. */
    1025     Assert(cbToProcessMax % cbFrame == 0);
    1026 
    10271024    ichac97R3StreamLock(pStreamCC);
    10281025
    10291026    PAC97BMREGS pRegs = &pStream->Regs;
    10301027
    1031     if (pRegs->sr & AC97_SR_DCH) /* Controller halted? */
     1028    if (!(pRegs->sr & AC97_SR_DCH)) /* Controller halted? */
     1029    { /* not halted - likely */ }
     1030    else
    10321031    {
    10331032        if (pRegs->cr & AC97_CR_RPBM) /* Bus master operation starts. */
     
    10491048
    10501049    /* BCIS flag still set? Skip iteration. */
    1051     if (pRegs->sr & AC97_SR_BCIS)
    1052     {
     1050/** @todo combine with the above test. */
     1051    if (!(pRegs->sr & AC97_SR_BCIS))
     1052    { /* likely */ }
     1053    else
     1054    {
     1055        /** @todo counter   */
    10531056        Log3Func(("[SD%RU8] BCIS set\n", pStream->u8SD));
    10541057
     
    16191622 * @param   pStreamCC           The AC'97 stream to lock (ring-3).
    16201623 */
    1621 static void ichac97R3StreamLock(PAC97STREAMR3 pStreamCC)
     1624DECLINLINE(void) ichac97R3StreamLock(PAC97STREAMR3 pStreamCC)
    16221625{
    16231626    int rc2 = RTCritSectEnter(&pStreamCC->State.CritSect);
     
    16311634 * @param   pStreamCC           The AC'97 stream to unlock (ring-3).
    16321635 */
    1633 static void ichac97R3StreamUnlock(PAC97STREAMR3 pStreamCC)
     1636DECLINLINE(void) ichac97R3StreamUnlock(PAC97STREAMR3 pStreamCC)
    16341637{
    16351638    int rc2 = RTCritSectLeave(&pStreamCC->State.CritSect);
     
    17581761static PAC97DRIVERSTREAM ichac97R3MixerGetDrvStream(PAC97DRIVER pDrv, PDMAUDIODIR enmDir, PDMAUDIOPATH enmPath)
    17591762{
    1760     PAC97DRIVERSTREAM pDrvStream = NULL;
    1761 
    17621763    if (enmDir == PDMAUDIODIR_IN)
    17631764    {
    17641765        LogFunc(("enmRecSource=%d\n", enmPath));
    1765 
    17661766        switch (enmPath)
    17671767        {
    17681768            case PDMAUDIOPATH_IN_LINE:
    1769                 pDrvStream = &pDrv->LineIn;
    1770                 break;
     1769                return &pDrv->LineIn;
    17711770            case PDMAUDIOPATH_IN_MIC:
    1772                 pDrvStream = &pDrv->MicIn;
    1773                 break;
     1771                return &pDrv->MicIn;
    17741772            default:
    1775                 AssertFailed();
    1776                 break;
     1773                AssertFailedBreak();
    17771774        }
    17781775    }
     
    17801777    {
    17811778        LogFunc(("enmPlaybackDst=%d\n", enmPath));
    1782 
    17831779        switch (enmPath)
    17841780        {
    17851781            case PDMAUDIOPATH_OUT_FRONT:
    1786                 pDrvStream = &pDrv->Out;
    1787                 break;
     1782                return &pDrv->Out;
    17881783            default:
    1789                 AssertFailed();
    1790                 break;
     1784                AssertFailedBreak();
    17911785        }
    17921786    }
     
    17941788        AssertFailed();
    17951789
    1796     return pDrvStream;
     1790    return NULL;
    17971791}
    17981792
     
    18331827            rc = AudioMixerSinkAddStream(pMixSink, pMixStrm);
    18341828            LogFlowFunc(("LUN#%RU8: Added stream \"%s\" to sink, rc=%Rrc\n", pDrv->uLUN, pStreamCfg->szName, rc));
    1835             if (RT_FAILURE(rc))
     1829            if (RT_SUCCESS(rc))
     1830                pDrvStream->pMixStrm = pMixStrm;
     1831            else
    18361832                AudioMixerStreamDestroy(pMixStrm, pDevIns, true /*fImmediate*/);
    18371833        }
    1838 
    1839         if (RT_SUCCESS(rc))
    1840             pDrvStream->pMixStrm = pMixStrm;
    18411834    }
    18421835    else
     
    18621855    AssertPtrReturn(pMixSink, VERR_INVALID_POINTER);
    18631856
    1864     if (!AudioHlpStreamCfgIsValid(pCfg))
    1865         return VERR_INVALID_PARAMETER;
    1866 
    1867     int rc = AudioMixerSinkSetFormat(pMixSink, &pCfg->Props);
    1868     if (RT_FAILURE(rc))
    1869         return rc;
    1870 
    1871     PAC97DRIVER pDrv;
    1872     RTListForEach(&pThisCC->lstDrv, pDrv, AC97DRIVER, Node)
    1873     {
    1874         int rc2 = ichac97R3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv);
    1875         if (RT_FAILURE(rc2))
    1876             LogFunc(("Attaching stream failed with %Rrc\n", rc2));
    1877 
    1878         /* Do not pass failure to rc here, as there might be drivers which aren't
    1879          * configured / ready yet. */
    1880     }
     1857    int rc;
     1858    if (AudioHlpStreamCfgIsValid(pCfg))
     1859    {
     1860        rc = AudioMixerSinkSetFormat(pMixSink, &pCfg->Props);
     1861        if (RT_SUCCESS(rc))
     1862        {
     1863
     1864            PAC97DRIVER pDrv;
     1865            RTListForEach(&pThisCC->lstDrv, pDrv, AC97DRIVER, Node)
     1866            {
     1867                int rc2 = ichac97R3MixerAddDrvStream(pDevIns, pMixSink, pCfg, pDrv);
     1868                if (RT_FAILURE(rc2))
     1869                    LogFunc(("Attaching stream failed with %Rrc\n", rc2));
     1870
     1871                /* Do not pass failure to rc here, as there might be drivers which aren't
     1872                   configured / ready yet. */
     1873            }
     1874        }
     1875    }
     1876    else
     1877        rc = VERR_INVALID_PARAMETER;
    18811878
    18821879    LogFlowFuncLeaveRC(rc);
     
    18861883/**
    18871884 * Adds a specific AC'97 driver to the driver chain.
     1885 *
     1886 * Only called from ichac97R3Attach().
    18881887 *
    18891888 * @returns VBox status code.
     
    19221921 * Removes a specific AC'97 driver from the driver chain and destroys its
    19231922 * associated streams.
     1923 *
     1924 * Only called from ichac97R3Detach().
    19241925 *
    19251926 * @param   pDevIns     The device instance.
     
    22772278}
    22782279
     2280
    22792281/**
    22802282 * Closes an AC'97 stream.
    22812283 *
    2282  * @returns VBox status code.
     2284 * Empty stub at present, nothing to do here as we reuse streams and only really
     2285 * re-open them if parameters changed (seldom).
     2286 *
    22832287 * @param   pStream             The AC'97 stream to close (shared).
    22842288 */
    2285 static int ichac97R3StreamClose(PAC97STREAM pStream)
     2289static void ichac97R3StreamClose(PAC97STREAM pStream)
    22862290{
    22872291    RT_NOREF(pStream);
    22882292    LogFlowFunc(("[SD%RU8]\n", pStream->u8SD));
    2289     return VINF_SUCCESS;
    2290 }
     2293}
     2294
    22912295
    22922296/**
     
    23112315    Assert(pStreamCC - &pThisCC->aStreams[0] == pStream->u8SD);
    23122316
    2313     int rc = ichac97R3StreamClose(pStream);
    2314     if (RT_SUCCESS(rc))
    2315         rc = ichac97R3StreamOpen(pDevIns, pThis, pThisCC, pStream, pStreamCC, fForce);
    2316 
    2317     return rc;
     2317    ichac97R3StreamClose(pStream);
     2318    return ichac97R3StreamOpen(pDevIns, pThis, pThisCC, pStream, pStreamCC, fForce);
    23182319}
    23192320
     
    23832384    else
    23842385    {
    2385         rc = ichac97R3StreamClose(pStream);
    2386         if (RT_SUCCESS(rc))
    2387             rc = AudioMixerSinkDrainAndStop(pSink,
    2388                                             pStreamCC->State.pCircBuf ? (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf) : 0);
     2386        rc = AudioMixerSinkDrainAndStop(pSink, pStreamCC->State.pCircBuf ? (uint32_t)RTCircBufUsed(pStreamCC->State.pCircBuf) : 0);
     2387        ichac97R3StreamClose(pStream);
    23892388    }
    23902389
     
    29292928{
    29302929    AssertMsgReturnVoid(uMixerIdx + 2U <= sizeof(pThis->mixer_data),
    2931                          ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)));
    2932 
    2933     LogRel2(("AC97: Setting mixer index #%RU8 to %RU16 (%RU8 %RU8)\n",
    2934              uMixerIdx, uVal, RT_HI_U8(uVal), RT_LO_U8(uVal)));
     2930                        ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)));
     2931
     2932    LogRel2(("AC97: Setting mixer index #%RU8 to %RU16 (%RU8 %RU8)\n", uMixerIdx, uVal, RT_HI_U8(uVal), RT_LO_U8(uVal)));
    29352933
    29362934    pThis->mixer_data[uMixerIdx + 0] = RT_LO_U8(uVal);
     
    29812979     * master volume controls.
    29822980     */
    2983     if (index == AC97_Master_Volume_Mute || index == AC97_Headphone_Volume_Mute || index == AC97_Master_Volume_Mono_Mute)
     2981    if (   index == AC97_Master_Volume_Mute
     2982        || index == AC97_Headphone_Volume_Mute
     2983        || index == AC97_Master_Volume_Mono_Mute)
    29842984    {
    29852985        if (uVal & RT_BIT(5))  /* D5 bit set? */
     
    30633063 * Sets the gain of a specific AC'97 recording control.
    30643064 *
    3065  * NB: gain support is currently not implemented in PDM audio.
     3065 * @note    Gain support is currently not implemented in PDM audio.
    30663066 *
    30673067 * @returns VBox status code.
     
    30783078     * zero being 0dB gain and 15 being +22.5dB gain.
    30793079     */
    3080     const bool  fCtlMuted     = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1;
     3080    bool const  fCtlMuted     = (uVal >> AC97_BARS_VOL_MUTE_SHIFT) & 1;
    30813081    uint8_t     uCtlGainLeft  = (uVal >> 8) & AC97_BARS_GAIN_MASK;
    30823082    uint8_t     uCtlGainRight = uVal & AC97_BARS_GAIN_MASK;
     
    31473147}
    31483148
     3149
    31493150/**
    31503151 * Converts an AC'97 recording source index to a PDM audio recording source.
     
    31713172}
    31723173
     3174
    31733175/**
    31743176 * Converts a PDM audio recording source to an AC'97 recording source index.
     
    33163318    {
    33173319        case 1:
    3318         {
    33193320            LogRel2(("AC97: Warning: Unimplemented read (1 byte) offPort=%#x\n", offPort));
    33203321            pThis->cas = 0;
    33213322            *pu32 = UINT32_MAX;
    33223323            break;
    3323         }
    33243324
    33253325        case 2:
    3326         {
    33273326            pThis->cas = 0;
    33283327            *pu32 = ichac97MixerGet(pThis, offPort);
    33293328            break;
    3330         }
    33313329
    33323330        case 4:
    3333         {
    33343331            LogRel2(("AC97: Warning: Unimplemented read (4 bytes) offPort=%#x\n", offPort));
    33353332            pThis->cas = 0;
    33363333            *pu32 = UINT32_MAX;
    33373334            break;
    3338         }
    33393335
    33403336        default:
    3341         {
    33423337            AssertFailed();
    33433338            rc = VERR_IOM_IOPORT_UNUSED;
    3344         }
     3339            break;
    33453340    }
    33463341
     
    33673362    {
    33683363        case 1:
    3369         {
    33703364            LogRel2(("AC97: Warning: Unimplemented NAMWrite (1 byte) offPort=%#x <- %#x\n", offPort, u32));
    33713365            pThis->cas = 0;
    33723366            break;
    3373         }
    33743367
    33753368        case 2:
     
    35633556
    35643557        case 4:
    3565         {
    35663558            LogRel2(("AC97: Warning: Unimplemented 4 byte NAMWrite: offPort=%#x <- %#x\n", offPort, u32));
    35673559            pThis->cas = 0;
    35683560            break;
    3569         }
    35703561
    35713562        default:
     
    36093600}
    36103601
     3602
    36113603/**
    36123604 * @callback_method_impl{FNSSMDEVSAVEEXEC}
     
    36433635    return VINF_SUCCESS;
    36443636}
     3637
    36453638
    36463639/**
     
    36693662}
    36703663
     3664
    36713665/**
    36723666 * @callback_method_impl{FNSSMDEVLOADEXEC}
     
    36933687    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    36943688    {
    3695         int rc2 = ichac97R3LoadStream(pDevIns, pSSM, &pThis->aStreams[i]);
    3696         AssertRCReturn(rc2, rc2);
     3689        int rc = ichac97R3LoadStream(pDevIns, pSSM, &pThis->aStreams[i]);
     3690        AssertRCReturn(rc, rc);
    36973691    }
    36983692
     
    37213715     */
    37223716    uint8_t afActiveStrms[AC97SOUNDSOURCE_MAX];
    3723     int rc2 = pHlp->pfnSSMGetMem(pSSM, afActiveStrms, sizeof(afActiveStrms));
    3724     AssertRCReturn(rc2, rc2);
     3717    int rc = pHlp->pfnSSMGetMem(pSSM, afActiveStrms, sizeof(afActiveStrms));
     3718    AssertRCReturn(rc, rc);
    37253719
    37263720    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
     
    37303724        const PAC97STREAMR3 pStreamCC = &pThisCC->aStreams[i];
    37313725
    3732         rc2 = ichac97R3StreamEnable(pDevIns, pThis, pThisCC, pStream, pStreamCC, fEnable);
    3733         AssertRC(rc2);
     3726        rc = ichac97R3StreamEnable(pDevIns, pThis, pThisCC, pStream, pStreamCC, fEnable);
     3727        AssertRC(rc);
    37343728        if (   fEnable
    3735             && RT_SUCCESS(rc2))
     3729            && RT_SUCCESS(rc))
    37363730        {
    37373731            /* Re-arm the timer for this stream. */
     
    40864080}
    40874081
     4082
    40884083/**
    40894084 * @interface_method_impl{PDMDEVREGR3,pfnAttach}
     
    41124107}
    41134108
    4114 /**
    4115  * Worker for ichac97R3Detach that does all but freeing the pDrv structure.
    4116  *
    4117  * This is called to let the device detach from a driver for a specified LUN
    4118  * at runtime.
    4119  *
    4120  * @param   pDevIns     The device instance.
    4121  * @param   pThisCC     The ring-3 AC'97 device state.
    4122  * @param   pDrv        Driver to detach from device.
    4123  */
    4124 static void ichac97R3DetachInternal(PPDMDEVINS pDevIns, PAC97STATER3 pThisCC, PAC97DRIVER pDrv)
    4125 {
    4126     /* Remove the driver from our list and destory it's associated streams.
    4127        This also will un-set the driver as a recording source (if associated). */
    4128     ichac97R3MixerRemoveDrv(pDevIns, pThisCC, pDrv);
    4129     LogFunc(("Detached LUN#%u\n", pDrv->uLUN));
    4130 }
    41314109
    41324110/**
     
    41484126        if (pDrv->uLUN == iLUN)
    41494127        {
    4150             ichac97R3DetachInternal(pDevIns, pThisCC, pDrv);
     4128            /* Remove the driver from our list and destory it's associated streams.
     4129               This also will un-set the driver as a recording source (if associated). */
     4130            ichac97R3MixerRemoveDrv(pDevIns, pThisCC, pDrv);
     4131            LogFunc(("Detached LUN#%u\n", pDrv->uLUN));
     4132
     4133            DEVAC97_UNLOCK(pDevIns, pThis);
     4134
    41514135            RTStrFree(pDrv->pszDesc);
    41524136            RTMemFree(pDrv);
    4153             DEVAC97_UNLOCK(pDevIns, pThis);
    41544137            return;
    41554138        }
     
    41914174    return VINF_SUCCESS;
    41924175}
     4176
    41934177
    41944178/**
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