VirtualBox

Changeset 71741 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 7, 2018 10:24:29 PM (7 years ago)
Author:
vboxsync
Message:

DevIchAc97.cpp: some cleanups.

File:
1 edited

Legend:

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

    r71738 r71741  
    205205};
    206206
    207 /** Emits registers for a specific (Native Audio Bus Master BAR) NABMBAR. */
     207/** Emits registers for a specific (Native Audio Bus Master BAR) NABMBAR.
     208 * @todo This totally messes with grepping for identifiers and tagging.  */
    208209#define AC97_NABMBAR_REGS(prefix, off)                                    \
    209210    enum {                                                                \
     
    10641065
    10651066#ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
     1067
    10661068/**
    10671069 * Asynchronous I/O thread for an AC'97 stream.
     
    12751277    ASMAtomicXchgBool(&pAIO->fEnabled, fEnable);
    12761278}
     1279
    12771280#endif /* VBOX_WITH_AUDIO_AC97_ASYNC_IO */
    12781281
     
    13241327        }
    13251328        else
    1326         {
    13271329#endif
     1330        {
    13281331            const uint32_t cbSinkWritable = AudioMixerSinkGetWritable(pSink);
    13291332
     
    13491352            AssertRC(rc2);
    13501353
    1351 #ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    1352         }
    1353 #endif
     1354        }
    13541355    }
    13551356    else /* Input (SDI). */
     
    13621363        }
    13631364        else
    1364         {
    13651365#endif
     1366        {
    13661367            rc2 = AudioMixerSinkUpdate(pSink);
    13671368            AssertRC(rc2);
     
    13861387                AssertRC(rc2);
    13871388            }
    1388 #ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    1389         }
    1390 #endif
     1389        }
    13911390
    13921391#ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    13931392        if (fInTimer)
    1394         {
    13951393#endif
     1394        {
    13961395            const uint32_t cbToTransfer = ichac97StreamGetUsed(pStream);
    13971396            if (cbToTransfer)
     
    14021401                AssertRC(rc2);
    14031402            }
    1404 #ifdef VBOX_WITH_AUDIO_AC97_ASYNC_IO
    1405         }
    1406 #endif
     1403        }
    14071404    }
    14081405}
     
    14181415static void ichac97MixerSet(PAC97STATE pThis, uint8_t uMixerIdx, uint16_t uVal)
    14191416{
    1420     if (size_t(uMixerIdx + 2) > sizeof(pThis->mixer_data))
    1421     {
    1422         AssertMsgFailed(("Index %RU8 out of bounds(%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)));
    1423         return;
    1424     }
    1425 
     1417    AssertMsgReturnVoid(uMixerIdx + 2U <= sizeof(pThis->mixer_data),
     1418                         ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)));
    14261419    pThis->mixer_data[uMixerIdx + 0] = RT_LO_U8(uVal);
    14271420    pThis->mixer_data[uMixerIdx + 1] = RT_HI_U8(uVal);
     
    14371430static uint16_t ichac97MixerGet(PAC97STATE pThis, uint32_t uMixerIdx)
    14381431{
    1439     uint16_t uVal;
    1440 
    1441     if (size_t(uMixerIdx + 2) > sizeof(pThis->mixer_data))
    1442     {
    1443         AssertMsgFailed(("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)));
    1444         uVal = UINT16_MAX;
    1445     }
    1446     else
    1447         uVal = RT_MAKE_U16(pThis->mixer_data[uMixerIdx + 0], pThis->mixer_data[uMixerIdx + 1]);
    1448 
    1449     return uVal;
     1432    AssertMsgReturn(uMixerIdx + 2U <= sizeof(pThis->mixer_data),
     1433                         ("Index %RU8 out of bounds (%zu)\n", uMixerIdx, sizeof(pThis->mixer_data)),
     1434                    UINT16_MAX);
     1435    return RT_MAKE_U16(pThis->mixer_data[uMixerIdx + 0], pThis->mixer_data[uMixerIdx + 1]);
    14501436}
    14511437
     
    16641650    PPDMAUDIOSTREAMCFG pCfg     = &pStream->State.Cfg;
    16651651    PAUDMIXSINK        pMixSink = NULL;
     1652    AssertCompile(sizeof(pCfg->szName) >= 8);
    16661653
    16671654    switch (pStream->u8SD)
     
    16731660            pCfg->DestSource.Source = PDMAUDIORECSOURCE_LINE;
    16741661            pCfg->enmLayout         = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
    1675 
    1676             RTStrPrintf2(pCfg->szName, sizeof(pCfg->szName), "Line-In");
     1662            strcpy(pCfg->szName, "Line-In");
    16771663
    16781664            pMixSink                = pThis->pSinkLineIn;
     
    16861672            pCfg->DestSource.Source = PDMAUDIORECSOURCE_MIC;
    16871673            pCfg->enmLayout         = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
    1688 
    1689             RTStrPrintf2(pCfg->szName, sizeof(pCfg->szName), "Mic-In");
     1674            strcpy(pCfg->szName, "Mic-In");
    16901675
    16911676            pMixSink                = pThis->pSinkMicIn;
     
    16991684            pCfg->DestSource.Dest   = PDMAUDIOPLAYBACKDEST_FRONT;
    17001685            pCfg->enmLayout         = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
    1701 
    1702             RTStrPrintf2(pCfg->szName, sizeof(pCfg->szName), "Output");
     1686            strcpy(pCfg->szName, "Output");
    17031687
    17041688            pMixSink                = pThis->pSinkOut;
     
    19901974        case AC97SOUNDSOURCE_MC_INDEX: return &pThis->StreamMicIn;
    19911975        case AC97SOUNDSOURCE_PO_INDEX: return &pThis->StreamOut;
    1992         default:                       break;
    1993     }
    1994 
    1995     return NULL;
     1976        default:                       return NULL;
     1977    }
     1978
    19961979}
    19971980
     
    21272110
    21282111#ifndef VBOX_WITH_AUDIO_AC97_CALLBACKS
     2112
    21292113/**
    21302114 * Starts the internal audio device timer.
     
    22972281    ichac97TimerMain(pThis);
    22982282}
     2283
    22992284#endif /* !VBOX_WITH_AUDIO_AC97_CALLBACKS */
    23002285
     
    24472432                if (cbSrc)
    24482433                {
     2434/** @todo r=bird: Just curious, DevHDA uses PDMDevHlpPCIPhysWrite here.  So,
     2435 *        is AC97 not subject to PCI busmaster enable/disable? */
    24492436                    int rc2 = PDMDevHlpPhysWrite(pThis->CTX_SUFF(pDevIns), pRegs->bd.addr, (uint8_t *)pvSrc, cbSrc);
    24502437                    AssertRC(rc2);
     
    29192906    PAC97STATE pThis = (PAC97STATE)pvUser;
    29202907
    2921     DEVAC97_LOCK(pThis);
     2908    DEVAC97_LOCK(pThis); /** @todo r=bird: some disconnect between the remark of this function docs and this locking statement.  */
    29222909
    29232910    int rc = VINF_SUCCESS;
    29242911
    29252912    uint32_t index = uPort - pThis->IOPortBase[0];
     2913    Assert(index < 256);
    29262914
    29272915    switch (cbVal)
     
    29372925        case 2:
    29382926        {
    2939             *pu32Val = UINT32_MAX;
    29402927            pThis->cas = 0;
    2941 
    2942             switch (index)
    2943             {
    2944                 default:
    2945                     *pu32Val = ichac97MixerGet(pThis, index);
    2946                     break;
    2947             }
     2928            *pu32Val = ichac97MixerGet(pThis, index);
    29482929            break;
    29492930        }
     
    29812962 * @remarks Caller enters the device critical section.
    29822963 */
    2983 static DECLCALLBACK(int) ichac97IOPortNAMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort,
    2984                                                uint32_t u32Val, unsigned cbVal)
     2964static DECLCALLBACK(int) ichac97IOPortNAMWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32Val, unsigned cbVal)
    29852965{
    29862966    RT_NOREF(pDevIns);
     
    34103390
    34113391/**
    3412  * @interface_method_impl{PDMDEVREG,pfnDestruct}
    3413  */
    3414 static DECLCALLBACK(int) ichac97Destruct(PPDMDEVINS pDevIns)
    3415 {
    3416     PAC97STATE pThis = PDMINS_2_DATA(pDevIns, PAC97STATE);
    3417 
    3418     LogFlowFuncEnter();
    3419 
    3420     PAC97DRIVER pDrv, pDrvNext;
    3421     RTListForEachSafe(&pThis->lstDrv, pDrv, pDrvNext, AC97DRIVER, Node)
    3422     {
    3423         RTListNodeRemove(&pDrv->Node);
    3424         RTMemFree(pDrv);
    3425     }
    3426 
    3427     /* Sanity. */
    3428     Assert(RTListIsEmpty(&pThis->lstDrv));
    3429 
    3430     return VINF_SUCCESS;
    3431 }
    3432 
    3433 
    3434 /**
    34353392 * Attach command, internal version.
    34363393 *
     
    36653622
    36663623/**
     3624 * @interface_method_impl{PDMDEVREG,pfnDestruct}
     3625 */
     3626static DECLCALLBACK(int) ichac97Destruct(PPDMDEVINS pDevIns)
     3627{
     3628    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); /* this shall come first */
     3629    PAC97STATE pThis = PDMINS_2_DATA(pDevIns, PAC97STATE);
     3630
     3631    LogFlowFuncEnter();
     3632
     3633    PAC97DRIVER pDrv, pDrvNext;
     3634    RTListForEachSafe(&pThis->lstDrv, pDrv, pDrvNext, AC97DRIVER, Node)
     3635    {
     3636        RTListNodeRemove(&pDrv->Node);
     3637        RTMemFree(pDrv);
     3638    }
     3639
     3640    /* Sanity. */
     3641    Assert(RTListIsEmpty(&pThis->lstDrv));
     3642
     3643    return VINF_SUCCESS;
     3644}
     3645
     3646/**
    36673647 * @interface_method_impl{PDMDEVREG,pfnConstruct}
    36683648 */
    36693649static DECLCALLBACK(int) ichac97Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    36703650{
    3671     RT_NOREF(iInstance);
     3651    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); /* this shall come first */
    36723652    PAC97STATE pThis = PDMINS_2_DATA(pDevIns, PAC97STATE);
    3673 
    3674     /* NB: This must be done *before* any possible failure (and running the destructor). */
     3653    Assert(iInstance == 0); RT_NOREF(iInstance);
     3654
     3655    /*
     3656     * Initialize data so we can run the destructor without scewing up.
     3657     */
    36753658    RTListInit(&pThis->lstDrv);
    36763659
    3677     Assert(iInstance == 0);
    3678     PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    36793660
    36803661    /*
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