VirtualBox

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


Ignore:
Timestamp:
Nov 26, 2019 11:52:11 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135045
Message:

DevSB16: cleanups. bugref:9218

File:
1 edited

Legend:

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

    r82229 r82230  
    8383*   Structures and Typedefs                                                                                                      *
    8484*********************************************************************************************************************************/
     85/** Pointer to the SB16 state. */
     86typedef struct SB16STATE *PSB16STATE;
     87
    8588/**
    8689 * Structure defining a (host backend) driver stream.
     
    9699
    97100/**
    98  * Struct for maintaining a host backend driver.
    99  */
    100 typedef struct SB16STATE *PSB16STATE;
     101 * Struct for tracking a host backend driver, i.e. our per-LUN data.
     102 */
    101103typedef struct SB16DRIVER
    102104{
    103105    /** Node for storing this driver in our device driver list of SB16STATE. */
    104     RTLISTNODER3                       Node;
     106    RTLISTNODER3                    Node;
    105107    /** Pointer to SB16 controller (state). */
    106     R3PTRTYPE(PSB16STATE)              pSB16State;
     108    R3PTRTYPE(PSB16STATE)           pSB16State;
     109    /** Pointer to attached driver base interface. */
     110    R3PTRTYPE(PPDMIBASE)            pDrvBase;
     111    /** Audio connector interface to the underlying host backend. */
     112    R3PTRTYPE(PPDMIAUDIOCONNECTOR)  pConnector;
     113    /** Stream for output. */
     114    SB16DRIVERSTREAM                Out;
    107115    /** Driver flags. */
    108     PDMAUDIODRVFLAGS                   fFlags;
     116    PDMAUDIODRVFLAGS                fFlags;
    109117    /** LUN # to which this driver has been assigned. */
    110     uint8_t                            uLUN;
     118    uint8_t                         uLUN;
    111119    /** Whether this driver is in an attached state or not. */
    112     bool                               fAttached;
    113     uint8_t                            Padding[2];
    114     /** Pointer to attached driver base interface. */
    115     R3PTRTYPE(PPDMIBASE)               pDrvBase;
    116     /** Audio connector interface to the underlying host backend. */
    117     R3PTRTYPE(PPDMIAUDIOCONNECTOR)     pConnector;
    118     /** Stream for output. */
    119     SB16DRIVERSTREAM                   Out;
    120 } SB16DRIVER, *PSB16DRIVER;
     120    bool                            fAttached;
     121    /** The LUN description. */
     122    char                            szDesc[2+48];
     123} SB16DRIVER;
     124/** Pointer to the per-LUN data. */
     125typedef SB16DRIVER *PSB16DRIVER;
    121126
    122127/**
     
    127132    /** The stream's current configuration. */
    128133    PDMAUDIOSTREAMCFG                  Cfg;
    129 } SB16STREAM, *PSB16STREAM;
    130 
     134} SB16STREAM;
     135/** Pointer to a SB16 stream */
     136typedef SB16STREAM *PSB16STREAM;
     137
     138/**
     139 * The SB16 state.
     140 */
    131141typedef struct SB16STATE
    132142{
     
    164174    int use_hdma;
    165175    int highspeed;
    166     int can_write; /** @todo Value never gets 0? */
     176    int can_write; /** @todo Value never gets set to 0! */
    167177
    168178    int v2x6;
     
    171181    uint8_t csp_value;
    172182    uint8_t csp_mode;
     183    uint8_t csp_index;
    173184    uint8_t csp_regs[256];
    174     uint8_t csp_index;
    175185    uint8_t csp_reg83[4];
    176186    int csp_reg83r;
     
    190200
    191201    RTLISTANCHOR                   lstDrv;
    192     /** Number of active (running) SDn streams. */
    193     uint8_t                        cStreamsActive;
    194     /** The timer for pumping data thru the attached LUN drivers. */
    195     TMTIMERHANDLE                  hTimerIO;
    196     /** Flag indicating whether the timer is active or not. */
    197     bool                           fTimerActive;
    198     uint8_t                        u8Padding1[7];
    199     /** The timer interval for pumping data thru the LUN drivers in timer ticks. */
    200     uint64_t                       cTicksTimerIOInterval;
    201     /** Timestamp of the last timer callback (sb16TimerIO).
    202      * Used to calculate the time actually elapsed between two timer callbacks. */
    203     uint64_t                       tsTimerIO;
    204202    /** IRQ timer   */
    205203    TMTIMERHANDLE                  hTimerIRQ;
     
    209207    SB16STREAM                     Out;
    210208
     209    /** The timer for pumping data thru the attached LUN drivers. */
     210    TMTIMERHANDLE                  hTimerIO;
     211    /** The timer interval for pumping data thru the LUN drivers in timer ticks. */
     212    uint64_t                       cTicksTimerIOInterval;
     213    /** Timestamp of the last timer callback (sb16TimerIO).
     214     * Used to calculate the time actually elapsed between two timer callbacks. */
     215    uint64_t                       tsTimerIO;
     216    /** Number of active (running) SDn streams. */
     217    uint8_t                        cStreamsActive;
     218    /** Flag indicating whether the timer is active or not. */
     219    bool volatile                  fTimerActive;
     220    uint8_t                        u8Padding1[5];
     221
    211222    /* mixer state */
    212223    uint8_t mixer_nreg;
    213224    uint8_t mixer_regs[256];
    214 } SB16STATE, *PSB16STATE;
     225} SB16STATE;
    215226
    216227
     
    387398
    388399    if (pThis->block_size & pThis->align)
    389         LogFlowFunc(("warning: misaligned block size %d, alignment %d\n",
    390                      pThis->block_size, pThis->align + 1));
     400        LogFlowFunc(("warning: misaligned block size %d, alignment %d\n", pThis->block_size, pThis->align + 1));
    391401
    392402    LogFlowFunc(("freq %d, stereo %d, sign %d, bits %d, dma %d, auto %d, fifo %d, high %d\n",
     
    480490        return pThis->in2_data[--pThis->in_index];
    481491    }
    482     else {
    483         LogFlowFunc(("buffer underflow\n"));
    484         return 0;
    485     }
     492    LogFlowFunc(("buffer underflow\n"));
     493    return 0;
    486494}
    487495
     
    739747
    740748warn:
    741     LogFlowFunc(("warning: command %#x,%d is not truly understood yet\n",
    742                  cmd, pThis->needed_bytes));
     749    LogFlowFunc(("warning: command %#x,%d is not truly understood yet\n", cmd, pThis->needed_bytes));
    743750    goto exit;
    744751}
     
    761768{
    762769    int d0, d1, d2;
    763     LogFlowFunc(("complete command %#x, in_index %d, needed_bytes %d\n",
    764             pThis->cmd, pThis->in_index, pThis->needed_bytes));
     770    LogFlowFunc(("complete command %#x, in_index %d, needed_bytes %d\n", pThis->cmd, pThis->in_index, pThis->needed_bytes));
    765771
    766772    if (pThis->cmd > 0xaf && pThis->cmd < 0xd0)
     
    792798            pThis->csp_param = dsp_get_data (pThis);
    793799            pThis->csp_value = dsp_get_data (pThis);
    794             LogFlowFunc(("CSP command 0x05: param=%#x value=%#x\n",
    795                     pThis->csp_param,
    796                     pThis->csp_value));
     800            LogFlowFunc(("CSP command 0x05: param=%#x value=%#x\n", pThis->csp_param, pThis->csp_value));
    797801            break;
    798802
     
    818822            if (d0 == 0x83)
    819823            {
    820                 LogFlowFunc(("0x83[%d] -> %#x\n",
    821                         pThis->csp_reg83w,
    822                         pThis->csp_reg83[pThis->csp_reg83w % 4]));
    823                 dsp_out_data (pThis, pThis->csp_reg83[pThis->csp_reg83w % 4]);
     824                LogFlowFunc(("0x83[%d] -> %#x\n", pThis->csp_reg83w, pThis->csp_reg83[pThis->csp_reg83w % 4]));
     825                dsp_out_data(pThis, pThis->csp_reg83[pThis->csp_reg83w % 4]);
    824826                pThis->csp_reg83w += 1;
    825827            }
     
    997999    RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    9981000    {
    999         if (!pDrv->Out.pStream)
    1000             continue;
    1001 
    1002         int rc2 = pDrv->pConnector->pfnStreamSetVolume(pDrv->pConnector, pDrv->Out.pStream, &VolCombined);
    1003         AssertRC(rc2);
     1001        PPDMAUDIOSTREAM pStream = pDrv->Out.pStream;
     1002        if (pStream)
     1003        {
     1004            int rc2 = pDrv->pConnector->pfnStreamSetVolume(pDrv->pConnector, pStream, &VolCombined);
     1005            AssertRC(rc2);
     1006        }
    10041007    }
    10051008}
     
    10271030    pCfg->Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cBytes, pCfg->Props.cChannels);
    10281031
    1029     AssertCompile(sizeof(pCfg->szName) > sizeof("Output"));
    1030     strcpy(pCfg->szName, "Output");
     1032    AssertCompile(sizeof(pCfg->szName) >= sizeof("Output"));
     1033    memcpy(pCfg->szName, "Output", sizeof("Output"));
    10311034
    10321035    sb16CloseOut(pThis);
     
    12821285}
    12831286
    1284 uint32_t popcount(uint32_t u) /** @todo r=andy WTF? */
     1287#ifndef VBOX
     1288static uint32_t popcount(uint32_t u)
    12851289{
    12861290    u = ((u&0x55555555) + ((u>>1)&0x55555555));
     
    12911295    return u;
    12921296}
    1293 
    1294 uint32_t lsbindex(uint32_t u)
    1295 {
     1297#endif
     1298
     1299static uint32_t lsbindex(uint32_t u)
     1300{
     1301#ifdef VBOX
     1302    return u ? ASMBitFirstSetU32(u) - 1 : 32;
     1303#else
    12961304    return popcount((u & -(int32_t)u) - 1);
     1305#endif
    12971306}
    12981307
     
    15051514static int sb16WriteAudio(PSB16STATE pThis, int nchan, uint32_t dma_pos, uint32_t dma_len, int len)
    15061515{
    1507     uint8_t  tmpbuf[_4K]; /** @todo Have a buffer on the heap. */
     1516    uint8_t  abBuf[_4K]; /** @todo Have a buffer on the heap. */
    15081517    uint32_t cbToWrite = len;
    15091518    uint32_t cbWrittenTotal = 0;
     
    15121521    {
    15131522        uint32_t cbToRead = RT_MIN(dma_len - dma_pos, cbToWrite);
    1514         if (cbToRead > sizeof(tmpbuf))
    1515             cbToRead = sizeof(tmpbuf);
     1523        if (cbToRead > sizeof(abBuf))
     1524            cbToRead = sizeof(abBuf);
    15161525
    15171526        uint32_t cbRead = 0;
    1518         int rc2 = PDMDevHlpDMAReadMemory(pThis->pDevInsR3, nchan, tmpbuf, dma_pos, cbToRead, &cbRead);
     1527        int rc2 = PDMDevHlpDMAReadMemory(pThis->pDevInsR3, nchan, abBuf, dma_pos, cbToRead, &cbRead);
    15191528        AssertMsgRC(rc2, (" from DMA failed: %Rrc\n", rc2));
    15201529
     
    15251534            RTFileOpen(&fh, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "sb16WriteAudio.pcm",
    15261535                       RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
    1527             RTFileWrite(fh, tmpbuf, cbRead, NULL);
     1536            RTFileWrite(fh, abBuf, cbRead, NULL);
    15281537            RTFileClose(fh);
    15291538        }
     
    15391548        RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    15401549        {
    1541             if (!pDrv->Out.pStream)
    1542                 continue;
    1543 
    1544             if (!DrvAudioHlpStreamStatusCanWrite(pDrv->pConnector->pfnStreamGetStatus(pDrv->pConnector,  pDrv->Out.pStream)))
    1545                 continue;
    1546 
    1547             uint32_t cbWrittenToStream = 0;
    1548             rc2 = pDrv->pConnector->pfnStreamWrite(pDrv->pConnector, pDrv->Out.pStream, tmpbuf, cbRead, &cbWrittenToStream);
    1549 
    1550             LogFlowFunc(("\tLUN#%RU8: rc=%Rrc, cbWrittenToStream=%RU32\n", pDrv->uLUN, rc2, cbWrittenToStream));
     1550            if (   pDrv->Out.pStream
     1551                && DrvAudioHlpStreamStatusCanWrite(pDrv->pConnector->pfnStreamGetStatus(pDrv->pConnector, pDrv->Out.pStream)))
     1552            {
     1553                uint32_t cbWrittenToStream = 0;
     1554                rc2 = pDrv->pConnector->pfnStreamWrite(pDrv->pConnector, pDrv->Out.pStream, abBuf, cbRead, &cbWrittenToStream);
     1555
     1556                LogFlowFunc(("\tLUN#%RU8: rc=%Rrc, cbWrittenToStream=%RU32\n", pDrv->uLUN, rc2, cbWrittenToStream));
     1557            }
    15511558        }
    15521559
     
    15551562        LogFlowFunc(("\tcbToRead=%RU32, cbToWrite=%RU32, cbWritten=%RU32, cbLeft=%RU32\n",
    15561563                     cbToRead, cbToWrite, cbWritten, cbToWrite - cbWrittenTotal));
     1564
     1565        if (!cbWritten)
     1566            break;
    15571567
    15581568        Assert(cbToWrite >= cbWritten);
     
    15601570        dma_pos         = (dma_pos + cbWritten) % dma_len;
    15611571        cbWrittenTotal += cbWritten;
    1562 
    1563         if (!cbWritten)
    1564             break;
    15651572    }
    15661573
     
    16261633
    16271634    Log3Func(("pos %d/%d free %5d till %5d copy %5d written %5d block_size %5d\n",
    1628                dma_pos, dma_len, free, pThis->left_till_irq, copy, written,
    1629                pThis->block_size));
     1635               dma_pos, dma_len, free, pThis->left_till_irq, copy, written, pThis->block_size));
    16301636
    16311637    while (pThis->left_till_irq <= 0)
     
    16851691    RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    16861692    {
    1687         PPDMAUDIOSTREAM pStream = pDrv->Out.pStream;
    1688         if (!pStream)
    1689             continue;
    1690 
    1691         PPDMIAUDIOCONNECTOR pConn = pDrv->pConnector;
    1692         if (!pConn)
    1693             continue;
    1694 
    1695         int rc2 = pConn->pfnStreamIterate(pConn, pStream);
    1696         if (RT_SUCCESS(rc2))
     1693        PPDMAUDIOSTREAM     const pStream = pDrv->Out.pStream;
     1694        PPDMIAUDIOCONNECTOR const pConn   = pDrv->pConnector;
     1695        if (pStream && pConn)
    16971696        {
    1698             rc2 = pConn->pfnStreamPlay(pConn, pStream, NULL /* cPlayed */);
    1699             if (RT_FAILURE(rc2))
     1697            int rc2 = pConn->pfnStreamIterate(pConn, pStream);
     1698            if (RT_SUCCESS(rc2))
    17001699            {
    1701                 LogFlowFunc(("%s: Failed playing stream, rc=%Rrc\n", pStream->szName, rc2));
    1702                 continue;
     1700                rc2 = pConn->pfnStreamPlay(pConn, pStream, NULL /* cPlayed */);
     1701                if (RT_FAILURE(rc2))
     1702                {
     1703                    LogFlowFunc(("%s: Failed playing stream, rc=%Rrc\n", pStream->szName, rc2));
     1704                    continue;
     1705                }
     1706
     1707                /* Only do the next DMA transfer if we're able to write the remaining data block. */
     1708                fDoTransfer = pConn->pfnStreamGetWritable(pConn, pStream) > (unsigned)pThis->left_till_irq;
    17031709            }
    17041710
    1705             /* Only do the next DMA transfer if we're able to write the remaining data block. */
    1706             fDoTransfer = pConn->pfnStreamGetWritable(pConn, pStream) > (unsigned)pThis->left_till_irq;
     1711            PDMAUDIOSTREAMSTS strmSts = pConn->pfnStreamGetStatus(pConn, pStream);
     1712            fIsPlaying |= (   (strmSts & PDMAUDIOSTREAMSTS_FLAG_ENABLED)
     1713                           || (strmSts & PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE));
    17071714        }
    1708 
    1709         PDMAUDIOSTREAMSTS strmSts = pConn->pfnStreamGetStatus(pConn, pStream);
    1710         fIsPlaying |= (   (strmSts & PDMAUDIOSTREAMSTS_FLAG_ENABLED)
    1711                        || (strmSts & PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE));
    17121715    }
    17131716
    17141717    bool fTimerActive = ASMAtomicReadBool(&pThis->fTimerActive);
    1715     bool fKickTimer   = fTimerActive || fIsPlaying;
    1716 
     1718    bool fArmTimer    = fTimerActive || fIsPlaying;
    17171719    LogFlowFunc(("fTimerActive=%RTbool, fIsPlaying=%RTbool\n", fTimerActive, fIsPlaying));
    17181720
     
    17201722    {
    17211723        /* Schedule the next transfer. */
    1722         PDMDevHlpDMASchedule(pThis->pDevInsR3);
    1723 
    1724         /* Kick the timer at least one more time. */
    1725         fKickTimer = true;
     1724        PDMDevHlpDMASchedule(pDevIns);
     1725
     1726        /* Arm the timer at least one more time. */
     1727        fArmTimer = true;
    17261728    }
    17271729
     
    17311733    /** @todo Implement recording. */
    17321734
    1733     if (fKickTimer)
    1734     {
    1735         /* Kick the timer again. */
     1735    if (fArmTimer)
     1736    {
     1737        /* Arm the timer again. */
    17361738        uint64_t cTicks = pThis->cTicksTimerIOInterval;
    17371739        /** @todo adjust cTicks down by now much cbOutMin represents. */
     
    19141916    {
    19151917        int32_t irq;
    1916         pHlp->pfnSSMGetS32 (pSSM, &irq);
     1918        pHlp->pfnSSMGetS32(pSSM, &irq);
    19171919        int32_t dma;
    1918         pHlp->pfnSSMGetS32 (pSSM, &dma);
     1920        pHlp->pfnSSMGetS32(pSSM, &dma);
    19191921        int32_t hdma;
    1920         pHlp->pfnSSMGetS32 (pSSM, &hdma);
     1922        pHlp->pfnSSMGetS32(pSSM, &hdma);
    19211923        int32_t port;
    1922         pHlp->pfnSSMGetS32 (pSSM, &port);
     1924        pHlp->pfnSSMGetS32(pSSM, &port);
    19231925        int32_t ver;
    1924         int rc = pHlp->pfnSSMGetS32 (pSSM, &ver);
     1926        int rc = pHlp->pfnSSMGetS32(pSSM, &ver);
    19251927        AssertRCReturn (rc, rc);
    19261928
     
    19321934        {
    19331935            return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS,
    1934                                     N_("config changed: irq=%x/%x dma=%x/%x hdma=%x/%x port=%x/%x ver=%x/%x (saved/config)"),
    1935                                     irq,  pThis->irqCfg,
    1936                                     dma,  pThis->dmaCfg,
    1937                                     hdma, pThis->hdmaCfg,
    1938                                     port, pThis->portCfg,
    1939                                     ver,  pThis->verCfg);
     1936                                           N_("config changed: irq=%x/%x dma=%x/%x hdma=%x/%x port=%x/%x ver=%x/%x (saved/config)"),
     1937                                           irq,  pThis->irqCfg,
     1938                                           dma,  pThis->dmaCfg,
     1939                                           hdma, pThis->hdmaCfg,
     1940                                           port, pThis->portCfg,
     1941                                           ver,  pThis->verCfg);
    19401942        }
    19411943    }
     
    19511953 *
    19521954 * @returns IPRT status code.
    1953  * @param   pThis               SB16 state.
    19541955 * @param   pCfg                Stream configuration to use.
    19551956 * @param   pDrv                Driver stream to create PDM stream for.
    19561957 */
    1957 static int sb16CreateDrvStream(PSB16STATE pThis, PPDMAUDIOSTREAMCFG pCfg, PSB16DRIVER pDrv)
    1958 {
    1959     RT_NOREF(pThis);
    1960 
     1958static int sb16CreateDrvStream(PPDMAUDIOSTREAMCFG pCfg, PSB16DRIVER pDrv)
     1959{
    19611960    AssertReturn(pCfg->enmDir == PDMAUDIODIR_OUT, VERR_INVALID_PARAMETER);
    19621961    Assert(DrvAudioHlpStreamCfgIsValid(pCfg));
     
    19931992static void sb16DestroyDrvStream(PSB16STATE pThis, PSB16DRIVER pDrv)
    19941993{
    1995     AssertPtrReturnVoid(pThis);
    1996     AssertPtrReturnVoid(pDrv);
     1994    AssertPtr(pThis);
     1995    AssertPtr(pDrv);
    19971996
    19981997    if (pDrv->Out.pStream)
     
    20192018static int sb16CheckAndReOpenOut(PPDMDEVINS pDevIns, PSB16STATE pThis)
    20202019{
    2021     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     2020    AssertPtr(pThis);
    20222021
    20232022    int rc = VINF_SUCCESS;
     
    20582057static int sb16OpenOut(PPDMDEVINS pDevIns, PSB16STATE pThis, PPDMAUDIOSTREAMCFG pCfg)
    20592058{
    2060     AssertPtrReturn(pThis, VERR_INVALID_POINTER);  /// @todo r=bird: Too paranoiad here.
    2061     AssertPtrReturn(pCfg,  VERR_INVALID_POINTER);  /// @todo r=bird: This is certifiable, only caller sends us a stack object...
    20622059    LogFlowFuncEnter();
     2060    AssertPtr(pThis);
     2061    AssertPtr(pCfg);
    20632062
    20642063    if (!DrvAudioHlpStreamCfgIsValid(pCfg))
     
    20662065
    20672066    int rc = DrvAudioHlpStreamCfgCopy(&pThis->Out.Cfg, pCfg);
    2068     if (RT_FAILURE(rc))
    2069         return rc;
    2070 
    2071     /* Set scheduling hint (if available). */
    2072     if (pThis->cTicksTimerIOInterval)
    2073         pThis->Out.Cfg.Device.uSchedulingHintMs = 1000 /* ms */
    2074                                                 / (  PDMDevHlpTimerGetFreq(pDevIns, pThis->hTimerIO)
    2075                                                    / RT_MIN(pThis->cTicksTimerIOInterval, 1));
    2076 
    2077     PSB16DRIVER pDrv;
    2078     RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
    2079     {
    2080         int rc2 = sb16CreateDrvStream(pThis, &pThis->Out.Cfg, pDrv);
    2081         if (RT_FAILURE(rc2))
    2082             LogFunc(("Attaching stream failed with %Rrc\n", rc2));
    2083 
    2084         /* Do not pass failure to rc here, as there might be drivers which aren't
    2085          * configured / ready yet. */
    2086     }
    2087 
    2088     sb16UpdateVolume(pThis);
     2067    if (RT_SUCCESS(rc))
     2068    {
     2069        /* Set scheduling hint (if available). */
     2070        if (pThis->cTicksTimerIOInterval)
     2071            pThis->Out.Cfg.Device.uSchedulingHintMs = 1000 /* ms */
     2072                                                    / (  PDMDevHlpTimerGetFreq(pDevIns, pThis->hTimerIO)
     2073                                                       / RT_MIN(pThis->cTicksTimerIOInterval, 1));
     2074
     2075        PSB16DRIVER pDrv;
     2076        RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
     2077        {
     2078            int rc2 = sb16CreateDrvStream(&pThis->Out.Cfg, pDrv);
     2079            if (RT_FAILURE(rc2))
     2080                LogFunc(("Attaching stream failed with %Rrc\n", rc2));
     2081
     2082            /* Do not pass failure to rc here, as there might be drivers which aren't
     2083             * configured / ready yet. */
     2084        }
     2085
     2086        sb16UpdateVolume(pThis);
     2087    }
    20892088
    20902089    LogFlowFuncLeaveRC(rc);
     
    20942093static void sb16CloseOut(PSB16STATE pThis)
    20952094{
    2096     AssertPtrReturnVoid(pThis); /// @todo r=bird: too much panaoia here!
    20972095    LogFlowFuncEnter();
     2096    AssertPtr(pThis);
    20982097
    20992098    PSB16DRIVER pDrv;
     
    21402139     * Attach driver.
    21412140     */
    2142     char *pszDesc;
    2143     if (RTStrAPrintf(&pszDesc, "Audio driver port (SB16) for LUN #%u", uLUN) <= 0)
    2144         AssertLogRelFailedReturn(VERR_NO_MEMORY);
     2141    PSB16DRIVER pDrv = (PSB16DRIVER)RTMemAllocZ(sizeof(SB16DRIVER));
     2142    AssertReturn(pDrv, VERR_NO_MEMORY);
     2143    RTStrPrintf(pDrv->szDesc, sizeof(pDrv->szDesc), "Audio driver port (SB16) for LUN #%u", uLUN);
    21452144
    21462145    PPDMIBASE pDrvBase;
    2147     int rc = PDMDevHlpDriverAttach(pThis->pDevInsR3, uLUN,
    2148                                    &pThis->IBase, &pDrvBase, pszDesc);
     2146    int rc = PDMDevHlpDriverAttach(pThis->pDevInsR3, uLUN, &pThis->IBase, &pDrvBase, pDrv->szDesc);
    21492147    if (RT_SUCCESS(rc))
    21502148    {
    2151         PSB16DRIVER pDrv = (PSB16DRIVER)RTMemAllocZ(sizeof(SB16DRIVER));
    2152         if (pDrv)
     2149        pDrv->pDrvBase   = pDrvBase;
     2150        pDrv->pConnector = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
     2151        AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN #%u has no host audio interface, rc=%Rrc\n", uLUN, rc));
     2152        pDrv->pSB16State = pThis;
     2153        pDrv->uLUN       = uLUN;
     2154
     2155        /*
     2156         * For now we always set the driver at LUN 0 as our primary
     2157         * host backend. This might change in the future.
     2158         */
     2159        if (pDrv->uLUN == 0)
     2160            pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
     2161
     2162        LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
     2163
     2164        /* Attach to driver list if not attached yet. */
     2165        if (!pDrv->fAttached)
    21532166        {
    2154             pDrv->pDrvBase   = pDrvBase;
    2155             pDrv->pConnector = PDMIBASE_QUERY_INTERFACE(pDrvBase, PDMIAUDIOCONNECTOR);
    2156             AssertMsg(pDrv->pConnector != NULL, ("Configuration error: LUN #%u has no host audio interface, rc=%Rrc\n", uLUN, rc));
    2157             pDrv->pSB16State = pThis;
    2158             pDrv->uLUN       = uLUN;
    2159 
    2160             /*
    2161              * For now we always set the driver at LUN 0 as our primary
    2162              * host backend. This might change in the future.
    2163              */
    2164             if (pDrv->uLUN == 0)
    2165                 pDrv->fFlags |= PDMAUDIODRVFLAGS_PRIMARY;
    2166 
    2167             LogFunc(("LUN#%u: pCon=%p, drvFlags=0x%x\n", uLUN, pDrv->pConnector, pDrv->fFlags));
    2168 
    2169             /* Attach to driver list if not attached yet. */
    2170             if (!pDrv->fAttached)
    2171             {
    2172                 RTListAppend(&pThis->lstDrv, &pDrv->Node);
    2173                 pDrv->fAttached = true;
    2174             }
    2175 
    2176             if (ppDrv)
    2177                 *ppDrv = pDrv;
     2167            RTListAppend(&pThis->lstDrv, &pDrv->Node);
     2168            pDrv->fAttached = true;
    21782169        }
    2179         else
    2180             rc = VERR_NO_MEMORY;
    2181     }
    2182     else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    2183         LogFunc(("No attached driver for LUN #%u\n", uLUN));
    2184 
    2185     if (RT_FAILURE(rc))
    2186     {
    2187         /* Only free this string on failure;
    2188          * must remain valid for the live of the driver instance. */
    2189         RTStrFree(pszDesc);
     2170
     2171        if (ppDrv)
     2172            *ppDrv = pDrv;
     2173    }
     2174    else
     2175    {
     2176        if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     2177            LogFunc(("No attached driver for LUN #%u\n", uLUN));
     2178        RTMemFree(pDrv);
    21902179    }
    21912180
     
    22292218    int rc2 = sb16AttachInternal(pThis, iLUN, fFlags, &pDrv);
    22302219    if (RT_SUCCESS(rc2))
    2231         rc2 = sb16CreateDrvStream(pThis, &pThis->Out.Cfg, pDrv);
     2220        rc2 = sb16CreateDrvStream(&pThis->Out.Cfg, pDrv);
    22322221
    22332222    return VINF_SUCCESS;
     
    23212310    PSB16DRIVER pDrv;
    23222311    RTListForEach(&pThis->lstDrv, pDrv, SB16DRIVER, Node)
     2312    {
    23232313        sb16DestroyDrvStream(pThis, pDrv);
     2314    }
    23242315}
    23252316
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