VirtualBox

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


Ignore:
Timestamp:
Feb 9, 2018 9:56:43 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120754
Message:

Audio/DrvHostDSound.cpp: Cleanup / docs.

File:
1 edited

Legend:

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

    r70925 r70926  
    120120    /** Whether this stream is in an enable state on the DirectSound side. */
    121121    bool               fEnabled;
     122    /** The stream's critical section for synchronizing access. */
    122123    RTCRITSECT         CritSect;
     124    /** The internal playback / capturing buffer. */
    123125    PRTCIRCBUF         pCircBuf;
     126    /** Size (in bytes) of the DirectSound buffer.
     127     *  Note: This in *not* the size of the circular buffer above! */
     128    DWORD              cbBufSize;
    124129    union
    125130    {
     
    131136            /** Current read offset (in bytes) within the DSB. */
    132137            DWORD                       offReadPos;
    133             /** Size (in bytes) of the DirectSound buffer. */
    134             DWORD                       cbBufSize;
    135138        } In;
    136139        struct
     
    147150            /** Total amount (in bytes) written. */
    148151            uint64_t                    cbWritten;
    149             /** Size (in bytes) of the DirectSound buffer. */
    150             DWORD                       cbBufSize;
    151152            /** Flag indicating whether playback was (re)started. */
    152153            bool                        fFirstPlayback;
    153             uint64_t tsLastPlayMs;
    154             bool fPendingPlayback;
    155             bool fPendingClose;
     154            /** Timestamp (in ms) of When the last playback has happened. */
     155            uint64_t                    tsLastPlayMs;
    156156        } Out;
    157157    };
     
    308308            int32_t cbDiff = cbWriteCursor - cbPlayCursor;
    309309            if (cbDiff < 0)
    310                 cbDiff += pStreamDS->Out.cbBufSize;
     310                cbDiff += pStreamDS->cbBufSize;
    311311
    312312            int32_t cbFree = cbPlayCursor - pStreamDS->Out.offWritePos;
    313313            if (cbFree < 0)
    314                 cbFree += pStreamDS->Out.cbBufSize;
    315 
    316             if (cbFree > (int32_t)pStreamDS->Out.cbBufSize - cbDiff)
     314                cbFree += pStreamDS->cbBufSize;
     315
     316            if (cbFree > (int32_t)pStreamDS->cbBufSize - cbDiff)
    317317            {
    318318                pStreamDS->Out.offWritePos = cbWriteCursor;
    319                 cbFree = pStreamDS->Out.cbBufSize - cbDiff;
     319                cbFree = pStreamDS->cbBufSize - cbDiff;
    320320            }
    321321
     
    326326             * So use our per-stream written indicator to see if we just started a stream. */
    327327            if (pStreamDS->Out.cbWritten == 0)
    328                 cbFree = pStreamDS->Out.cbBufSize;
     328                cbFree = pStreamDS->cbBufSize;
    329329
    330330            DSLOGREL(("DSound: cbPlayCursor=%RU32, cbWriteCursor=%RU32, offWritePos=%RU32 -> cbFree=%RI32\n",
     
    761761         * playback buffer position.
    762762         */
    763         pStreamDS->Out.cbBufSize = bc.dwBufferBytes;
     763        pStreamDS->cbBufSize = bc.dwBufferBytes;
    764764
    765765        RTCritSectEnter(&pThis->CritSect);
    766766
    767         rc = RTCircBufCreate(&pStreamDS->pCircBuf, pStreamDS->Out.cbBufSize);
     767        rc = RTCircBufCreate(&pStreamDS->pCircBuf, pStreamDS->cbBufSize);
    768768        AssertRC(rc);
    769769
     
    781781            dsPosNotify[0].hEventNotify = pThis->aEvents[DSOUNDEVENT_OUTPUT];
    782782
    783             dsPosNotify[1].dwOffset     = float(pStreamDS->Out.cbBufSize * 0.3);
     783            dsPosNotify[1].dwOffset     = float(pStreamDS->cbBufSize * 0.3);
    784784            dsPosNotify[1].hEventNotify = pThis->aEvents[DSOUNDEVENT_OUTPUT];
    785785
    786             dsPosNotify[2].dwOffset     = float(pStreamDS->Out.cbBufSize * 0.6);
     786            dsPosNotify[2].dwOffset     = float(pStreamDS->cbBufSize * 0.6);
    787787            dsPosNotify[2].hEventNotify = pThis->aEvents[DSOUNDEVENT_OUTPUT];
    788788
     
    800800        RTCritSectLeave(&pThis->CritSect);
    801801
    802         pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDS->Out.cbBufSize);
     802        pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDS->cbBufSize);
    803803
    804804    } while (0);
     
    824824    PVOID pv1;
    825825    hr = directSoundPlayLock(pThis, pStreamDS,
    826                              0 /* dwOffset */, pStreamDS->Out.cbBufSize,
     826                             0 /* dwOffset */, pStreamDS->cbBufSize,
    827827                             &pv1, NULL, 0, 0, DSBLOCK_ENTIREBUFFER);
    828828    if (SUCCEEDED(hr))
    829829    {
    830         DrvAudioHlpClearBuf(pProps, pv1, pStreamDS->Out.cbBufSize, PDMAUDIOPCMPROPS_B2F(pProps, pStreamDS->Out.cbBufSize));
     830        DrvAudioHlpClearBuf(pProps, pv1, pStreamDS->cbBufSize, PDMAUDIOPCMPROPS_B2F(pProps, pStreamDS->cbBufSize));
    831831
    832832        directSoundPlayUnlock(pThis, pStreamDS->Out.pDSB, pv1, NULL, 0, 0);
     
    12081208
    12091209        /* Initial state: reading at the initial capture position, no error. */
    1210         pStreamDS->In.offReadPos    = 0;
    1211         pStreamDS->In.cbBufSize     = bc.dwBufferBytes;
    1212 
    1213         rc = RTCircBufCreate(&pStreamDS->pCircBuf, pStreamDS->In.cbBufSize);
     1210        pStreamDS->In.offReadPos = 0;
     1211        pStreamDS->cbBufSize     = bc.dwBufferBytes;
     1212
     1213        rc = RTCircBufCreate(&pStreamDS->pCircBuf, pStreamDS->cbBufSize);
    12141214        AssertRC(rc);
    12151215
     
    12271227            dsPosNotify[0].hEventNotify = pThis->aEvents[DSOUNDEVENT_INPUT];
    12281228
    1229             dsPosNotify[1].dwOffset     = float(pStreamDS->In.cbBufSize * 0.3);
     1229            dsPosNotify[1].dwOffset     = float(pStreamDS->cbBufSize * 0.3);
    12301230            dsPosNotify[1].hEventNotify = pThis->aEvents[DSOUNDEVENT_INPUT];
    12311231
    1232             dsPosNotify[2].dwOffset     = float(pStreamDS->In.cbBufSize * 0.6);
     1232            dsPosNotify[2].dwOffset     = float(pStreamDS->cbBufSize * 0.6);
    12331233            dsPosNotify[2].hEventNotify = pThis->aEvents[DSOUNDEVENT_INPUT];
    12341234
     
    12421242        }
    12431243
    1244         pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDS->In.cbBufSize);
     1244        pCfgAcq->cFrameBufferHint = PDMAUDIOSTREAMCFG_B2F(pCfgAcq, pStreamDS->cbBufSize);
    12451245
    12461246    } while (0);
     
    15561556    pStreamDS->Out.cbWritten = 0;
    15571557    pStreamDS->Out.fFirstPlayback = true;
    1558     pStreamDS->Out.fPendingPlayback = false;
    15591558    pStreamDS->Out.tsLastPlayMs = 0;
    1560     pStreamDS->Out.cbBufSize = 0;
     1559    pStreamDS->cbBufSize = 0;
    15611560
    15621561    int rc = VINF_SUCCESS;
     
    17151714
    17161715    /* Init the stream structure and save relevant information to it. */
    1717     pStreamDS->In.offReadPos    = 0;
    1718     pStreamDS->In.cbBufSize     = 0;
    1719     pStreamDS->In.pDSCB         = NULL;
     1716    pStreamDS->In.offReadPos = 0;
     1717    pStreamDS->cbBufSize     = 0;
     1718    pStreamDS->In.pDSCB      = NULL;
    17201719
    17211720    int rc = VINF_SUCCESS;
     
    19631962                        break;
    19641963
    1965                     DWORD cbUsed = dsoundRingDistance(offCaptureCursor, pStreamDS->In.offReadPos, pStreamDS->In.cbBufSize);
     1964                    DWORD cbUsed = dsoundRingDistance(offCaptureCursor, pStreamDS->In.offReadPos, pStreamDS->cbBufSize);
    19661965
    19671966                    PRTCIRCBUF pCircBuf = pStreamDS->pCircBuf;
     
    20012000                            directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2);
    20022001
    2003                             pStreamDS->In.offReadPos = (pStreamDS->In.offReadPos + cb1 + cb2) % pStreamDS->In.cbBufSize;
     2002                            pStreamDS->In.offReadPos = (pStreamDS->In.offReadPos + cb1 + cb2) % pStreamDS->cbBufSize;
    20042003
    20052004                            Assert(cbToCapture >= cbBuf);
     
    20492048                        pStreamDS->Out.offWritePos = offWriteCursor;
    20502049
    2051                         cbFree      = pStreamDS->Out.cbBufSize;
    2052                         cbRemaining = pStreamDS->Out.cbBufSize;
     2050                        cbFree      = pStreamDS->cbBufSize;
     2051                        cbRemaining = pStreamDS->cbBufSize;
    20532052                    }
    20542053                    else
     
    20592058                            break;
    20602059
    2061                         cbFree      = dsoundRingDistance(offPlayCursor, pStreamDS->Out.offWritePos, pStreamDS->Out.cbBufSize);
    2062                         cbRemaining = dsoundRingDistance(pStreamDS->Out.offWritePos, offPlayCursor, pStreamDS->Out.cbBufSize);
     2060                        cbFree      = dsoundRingDistance(offPlayCursor, pStreamDS->Out.offWritePos, pStreamDS->cbBufSize);
     2061                        cbRemaining = dsoundRingDistance(pStreamDS->Out.offWritePos, offPlayCursor, pStreamDS->cbBufSize);
    20632062                    }
    20642063
     
    20992098                            directSoundPlayUnlock(pThis, pDSB, pv1, pv2, cb1, cb2);
    21002099
    2101                             pStreamDS->Out.offWritePos = (pStreamDS->Out.offWritePos + cb1 + cb2) % pStreamDS->Out.cbBufSize;
     2100                            pStreamDS->Out.offWritePos = (pStreamDS->Out.offWritePos + cb1 + cb2) % pStreamDS->cbBufSize;
    21022101
    21032102                            Assert(cbToPlay >= cbBuf);
     
    21312130                            DSLOG(("DSound: Started playing output\n"));
    21322131                            pStreamDS->Out.fFirstPlayback   = false;
    2133                             pStreamDS->Out.fPendingPlayback = true;
    21342132                        }
    21352133                    }
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