VirtualBox

Changeset 63529 in vbox for trunk/src


Ignore:
Timestamp:
Aug 16, 2016 9:37:04 AM (8 years ago)
Author:
vboxsync
Message:

Audio: Bugfixes.

Location:
trunk/src/VBox
Files:
8 edited

Legend:

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

    r63360 r63529  
    521521     */
    522522
    523     /* Make the acquired host configuration the requested host configuration by default. */
    524     PDMAUDIOSTREAMCFG CfgAcq;
    525     memcpy(&CfgAcq, pCfgHost, sizeof(PDMAUDIOSTREAMCFG));
    526 
    527     uint32_t cSamples = 0;
     523    /* Make the acquired host configuration the requested host configuration initially,
     524     * in case the backend does not report back an acquired configuration. */
     525    PDMAUDIOSTREAMCFG CfgHostAcq;
     526    memcpy(&CfgHostAcq, pCfgHost, sizeof(PDMAUDIOSTREAMCFG));
     527
    528528    int rc = pThis->pHostDrvAudio->pfnStreamCreate(pThis->pHostDrvAudio, pHstStream,
    529                                                    pCfgHost /* pCfgReq */, &CfgAcq /* pCfgAcq */);
     529                                                   pCfgHost /* pCfgReq */, &CfgHostAcq /* pCfgAcq */);
    530530    if (RT_SUCCESS(rc))
    531531    {
     
    538538        LogFlowFunc(("[%s] Initializing stream in host backend failed with rc=%Rrc\n", pStream->szName, rc));
    539539
    540     int rc2 = DrvAudioHlpStreamCfgToProps(pCfgHost, &pHstStream->Props);
     540    PDMAUDIOPCMPROPS PCMProps;
     541    int rc2 = DrvAudioHlpStreamCfgToProps(&CfgHostAcq, &PCMProps);
    541542    AssertRC(rc2);
    542543
     
    544545    AudioMixBufDestroy(&pHstStream->MixBuf);
    545546
    546     if (cSamples)
    547     {
    548         cSamples = cSamples * 4;
    549 
    550         LogFlowFunc(("[%s] cSamples=%RU32\n", pHstStream->szName, cSamples));
    551 
    552         rc2 = AudioMixBufInit(&pHstStream->MixBuf, pHstStream->szName, &pHstStream->Props, cSamples);
     547    if (CfgHostAcq.cSamples)
     548    {
     549        LogFlowFunc(("[%s] cSamples=%RU32\n", pHstStream->szName, CfgHostAcq.cSamples * 4));
     550
     551        rc2 = AudioMixBufInit(&pHstStream->MixBuf, pHstStream->szName, &PCMProps, CfgHostAcq.cSamples * 4);
    553552        AssertRC(rc2);
    554553    }
     
    561560     */
    562561
    563     rc2 = DrvAudioHlpStreamCfgToProps(pCfgGuest, &pGstStream->Props);
     562    RT_ZERO(PCMProps);
     563    rc2 = DrvAudioHlpStreamCfgToProps(pCfgGuest, &PCMProps);
    564564    AssertRC(rc2);
    565565
     
    567567    AudioMixBufDestroy(&pGstStream->MixBuf);
    568568
    569     if (cSamples)
    570     {
    571         cSamples = cSamples * 2;
    572 
    573         LogFlowFunc(("[%s] cSamples=%RU32\n", pGstStream->szName, cSamples));
    574 
    575         rc2 = AudioMixBufInit(&pGstStream->MixBuf, pGstStream->szName, &pGstStream->Props, cSamples);
     569    if (CfgHostAcq.cSamples)
     570    {
     571        LogFlowFunc(("[%s] cSamples=%RU32\n", pGstStream->szName, CfgHostAcq.cSamples * 2));
     572
     573        rc2 = AudioMixBufInit(&pGstStream->MixBuf, pGstStream->szName, &PCMProps, CfgHostAcq.cSamples * 2);
    576574        AssertRC(rc2);
    577575    }
     
    581579#endif
    582580
    583     if (cSamples)
     581    if (CfgHostAcq.cSamples)
    584582    {
    585583        if (pCfgGuest->enmDir == PDMAUDIODIR_IN)
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r63500 r63529  
    123123    pASBD->mBytesPerFrame    = pASBD->mChannelsPerFrame * (pASBD->mBitsPerChannel / 8);
    124124    pASBD->mBytesPerPacket   = pASBD->mFramesPerPacket * pASBD->mBytesPerFrame;
     125}
     126
     127static int coreAudioStreamCfgToASBD(PPDMAUDIOSTREAMCFG pCfg, AudioStreamBasicDescription *pASBD)
     128{
     129    AssertPtrReturn(pCfg,  VERR_INVALID_PARAMETER);
     130    AssertPtrReturn(pASBD, VERR_INVALID_PARAMETER);
     131
     132    PDMAUDIOPCMPROPS Props;
     133    int rc = DrvAudioHlpStreamCfgToProps(pCfg, &Props);
     134    if (RT_SUCCESS(rc))
     135        coreAudioPCMPropsToASBD(&Props, pASBD);
     136
     137    return rc;
    125138}
    126139
     
    11411154                           PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    11421155{
    1143     AssertPtrReturn(pThis,   VERR_INVALID_POINTER);
    1144     AssertPtrReturn(pStream, VERR_INVALID_POINTER);
    1145     AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
    1146     AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
     1156    RT_NOREF(pThis);
    11471157
    11481158    int rc = VINF_SUCCESS;
     
    11521162
    11531163    OSStatus err = noErr;
     1164    UInt32 uSize = 0;
     1165
    11541166    AudioDeviceID deviceID = pStreamIn->deviceID;
    1155 
    1156     UInt32 uSize = 0;
    11571167    if (deviceID == kAudioDeviceUnknown)
    11581168    {
     
    13411351        /* Create an AudioStreamBasicDescription based on our required audio settings. */
    13421352        RT_ZERO(pStreamIn->streamFormat);
    1343         coreAudioPCMPropsToASBD(&pStreamIn->Stream.Props, &pStreamIn->streamFormat);
     1353        coreAudioStreamCfgToASBD(pCfgReq, &pStreamIn->streamFormat);
    13441354
    13451355        coreAudioPrintASBD("Recording device", &pStreamIn->deviceFormat);
     
    15121522        }
    15131523
    1514         if (RT_SUCCESS(rc))
    1515             rc = RTCircBufCreate(&pStreamIn->pCircBuf, cSamples << pStreamIn->Stream.Props.cShift);
     1524        PDMAUDIOPCMPROPS PCMProps;
     1525        int rc2 = DrvAudioHlpStreamCfgToProps(pCfgAcq, &PCMProps);
     1526        AssertRC(rc2);
     1527
     1528        rc = RTCircBufCreate(&pStreamIn->pCircBuf, cSamples << PCMProps.cShift);
     1529        if (RT_FAILURE(rc))
     1530            break;
    15161531
    15171532        /* Init the converter callback context. */
    1518         if (RT_SUCCESS(rc))
    1519             rc = coreAudioInitConvCbCtx(&pStreamIn->convCbCtx,
    1520                                         &pStreamIn->deviceFormat /* Source */, &pStreamIn->streamFormat /* Dest */);
     1533        rc = coreAudioInitConvCbCtx(&pStreamIn->convCbCtx,
     1534                                    &pStreamIn->deviceFormat /* Source */, &pStreamIn->streamFormat /* Dest */);
    15211535
    15221536        if (RT_SUCCESS(rc))
     
    15731587                            PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    15741588{
    1575     AssertPtrReturn(pThis,   VERR_INVALID_POINTER);
    1576     AssertPtrReturn(pStream, VERR_INVALID_POINTER);
    1577     AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
    1578     AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
     1589    RT_NOREF(pThis);
    15791590
    15801591    int rc = VINF_SUCCESS;
     
    15841595
    15851596    OSStatus err = noErr;
     1597    UInt32 uSize = 0;
     1598
    15861599    AudioDeviceID deviceID = pStreamOut->deviceID;
    1587 
    1588     UInt32 uSize = 0;
    1589     if (pStreamOut->deviceID == kAudioDeviceUnknown)
     1600    if (deviceID == kAudioDeviceUnknown)
    15901601    {
    15911602        /* Fetch the default audio recording device currently in use. */
    15921603        AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice,
    15931604                                               kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    1594         uSize = sizeof(pStreamOut->deviceID);
    1595         err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize, &pStreamOut->deviceID);
     1605        uSize = sizeof(deviceID);
     1606        err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize, &deviceID);
    15961607        if (err != noErr)
    15971608        {
     
    17531764
    17541765        /* Create an AudioStreamBasicDescription based on our required audio settings. */
    1755         coreAudioPCMPropsToASBD(&pStreamOut->Stream.Props, &pStreamOut->streamFormat);
     1766        coreAudioStreamCfgToASBD(pCfgReq, &pStreamOut->streamFormat);
    17561767
    17571768        coreAudioPrintASBD("Playback device", &pStreamOut->deviceFormat);
     
    18341845        }
    18351846
    1836         /* Create the internal ring buffer. */
    1837         rc = RTCircBufCreate(&pStreamOut->pCircBuf, cSamples << pStream->Props.cShift);
    1838         if (RT_SUCCESS(rc))
    1839         {
    1840             /*
    1841              * Register callbacks.
    1842              */
     1847        PDMAUDIOPCMPROPS PCMProps;
     1848        int rc2 = DrvAudioHlpStreamCfgToProps(pCfgAcq, &PCMProps);
     1849        AssertRC(rc2);
     1850
     1851        rc = RTCircBufCreate(&pStreamOut->pCircBuf, cSamples << PCMProps.cShift);
     1852        if (RT_FAILURE(rc))
     1853            break;
     1854
     1855        /*
     1856         * Register callbacks.
     1857         */
    18431858#ifdef DEBUG
    1844             propAdr.mSelector = kAudioDeviceProcessorOverload;
    1845             propAdr.mScope    = kAudioUnitScope_Global;
    1846             err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1847                                                  coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1848             if (err != noErr)
    1849                 LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
     1859        propAdr.mSelector = kAudioDeviceProcessorOverload;
     1860        propAdr.mScope    = kAudioUnitScope_Global;
     1861        err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1862                                             coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1863        if (err != noErr)
     1864            LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
    18501865#endif /* DEBUG */
    18511866
    1852             propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
    1853             propAdr.mScope    = kAudioUnitScope_Global;
    1854             err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1855                                                  coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1856             /* Not fatal. */
    1857             if (err != noErr)
    1858                 LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
    1859         }
     1867        propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
     1868        propAdr.mScope    = kAudioUnitScope_Global;
     1869        err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1870                                             coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1871        /* Not fatal. */
     1872        if (err != noErr)
     1873            LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
    18601874
    18611875    } while (0);
  • trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp

    r63527 r63529  
    107107typedef struct DSOUNDSTREAMOUT
    108108{
    109     /** Associated host output stream.
    110      *  Note: Always must come first! */
     109    /** Note: Always must come first! */
    111110    PDMAUDIOSTREAM       Stream;
     111    /** The PCM properties of this stream. */
     112    PDMAUDIOPCMPROPS     Props;
    112113    LPDIRECTSOUND8       pDS;     /** @todo Move this out of this structure! Not required per-stream (e.g. for multi-channel). */
    113114    LPDIRECTSOUNDBUFFER8 pDSB;
     
    121122typedef struct DSOUNDSTREAMIN
    122123{
    123     /** Associated host input stream.
    124      *  Note: Always must come first! */
     124    /** Associated host input stream. */
    125125    PDMAUDIOSTREAM              Stream;
     126    /** The PCM properties of this stream. */
     127    PDMAUDIOPCMPROPS            Props;
    126128    LPDIRECTSOUNDCAPTURE8       pDSC;
    127129    LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB;
     
    557559static HRESULT directSoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStream)
    558560{
    559     AssertPtrReturn(pThis, E_POINTER);
     561    AssertPtrReturn(pThis,         E_POINTER);
    560562    AssertPtrReturn(pDSoundStream, E_POINTER);
    561563
     
    563565           pDSoundStream,
    564566           pThis->cfg.cbBufferOut,
    565            pDSoundStream->Stream.Props.uHz,
    566            pDSoundStream->Stream.Props.cChannels,
    567            pDSoundStream->Stream.Props.cBits,
    568            pDSoundStream->Stream.Props.fSigned));
     567           pDSoundStream->Props.uHz,
     568           pDSoundStream->Props.cChannels,
     569           pDSoundStream->Props.cBits,
     570           pDSoundStream->Props.fSigned));
    569571
    570572    if (pDSoundStream->pDSB != NULL)
     
    666668               wfx.cbSize));
    667669
    668         if (bc.dwBufferBytes & pDSoundStream->Stream.Props.uAlign)
     670        if (bc.dwBufferBytes & pDSoundStream->Props.uAlign)
    669671            DSLOGREL(("DSound: Playback capabilities returned misaligned buffer: size %RU32, alignment %RU32\n",
    670                       bc.dwBufferBytes, pDSoundStream->Stream.Props.uAlign + 1));
     672                      bc.dwBufferBytes, pDSoundStream->Props.uAlign + 1));
    671673
    672674        if (bc.dwBufferBytes != pThis->cfg.cbBufferOut)
     
    679681         * playback buffer position.
    680682         */
    681         pDSoundStream->cMaxSamplesInBuffer = bc.dwBufferBytes >> pDSoundStream->Stream.Props.cShift;
     683        pDSoundStream->cMaxSamplesInBuffer = bc.dwBufferBytes >> pDSoundStream->Props.cShift;
    682684        DSLOG(("DSound: cMaxSamplesInBuffer=%RU32\n", pDSoundStream->cMaxSamplesInBuffer));
    683685
     
    10381040           pDSoundStream,
    10391041           pThis->cfg.cbBufferIn,
    1040            pDSoundStream->Stream.Props.uHz,
    1041            pDSoundStream->Stream.Props.cChannels,
    1042            pDSoundStream->Stream.Props.cBits,
    1043            pDSoundStream->Stream.Props.fSigned));
     1042           pDSoundStream->Props.uHz,
     1043           pDSoundStream->Props.cChannels,
     1044           pDSoundStream->Props.cBits,
     1045           pDSoundStream->Props.fSigned));
    10441046
    10451047    if (pDSoundStream->pDSCB != NULL)
     
    11371139               wfx.cbSize));
    11381140
    1139         if (bc.dwBufferBytes & pDSoundStream->Stream.Props.uAlign)
     1141        if (bc.dwBufferBytes & pDSoundStream->Props.uAlign)
    11401142            DSLOGREL(("DSound: Capture GetCaps returned misaligned buffer: size %RU32, alignment %RU32\n",
    1141                       bc.dwBufferBytes, pDSoundStream->Stream.Props.uAlign + 1));
     1143                      bc.dwBufferBytes, pDSoundStream->Props.uAlign + 1));
    11421144
    11431145        if (bc.dwBufferBytes != pThis->cfg.cbBufferIn)
     
    11461148
    11471149        /* Initial state: reading at the initial capture position, no error. */
    1148         pDSoundStream->idxSampleCaptureReadPos    = offByteReadPos >> pDSoundStream->Stream.Props.cShift;
    1149         pDSoundStream->cMaxSamplesInBuffer = bc.dwBufferBytes >> pDSoundStream->Stream.Props.cShift;
    1150         pDSoundStream->hrLastCapture       = S_OK;
     1150        pDSoundStream->idxSampleCaptureReadPos = offByteReadPos >> pDSoundStream->Props.cShift;
     1151        pDSoundStream->cMaxSamplesInBuffer     = bc.dwBufferBytes >> pDSoundStream->Props.cShift;
     1152        pDSoundStream->hrLastCapture           = S_OK;
    11511153
    11521154        DSLOG(("DSound: idxSampleCaptureReadPos=%RU32, cMaxSamplesInBuffer=%RU32\n",
     
    14501452    pDSoundStream->streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS;
    14511453
    1452     int rc = DrvAudioHlpStreamCfgToProps(&pDSoundStream->streamCfg, &pDSoundStream->Stream.Props);
     1454    int rc = DrvAudioHlpStreamCfgToProps(&pDSoundStream->streamCfg, &pDSoundStream->Props);
    14531455    if (RT_SUCCESS(rc))
    14541456    {
     
    14601462
    14611463        if (pCfgAcq)
    1462             pCfgAcq->cSamples = pThis->cfg.cbBufferOut >> pStream->Props.cShift; /** @todo Get rid of using Props! */
     1464            pCfgAcq->cSamples = pThis->cfg.cbBufferOut >> pDSoundStream->Props.cShift;
    14631465
    14641466        /* Try to open playback in case the device is already there. */
     
    15671569        /* Do not write more than available space in the DirectSound playback buffer. */
    15681570        cbLive = RT_MIN(cbFree, cbLive);
    1569         cbLive &= ~pStream->Props.uAlign;
     1571        cbLive &= ~pDSoundStream->Props.uAlign;
    15701572        if (cbLive == 0 || cbLive > cbBuffer)
    15711573        {
     
    15801582        PVOID pv1, pv2;
    15811583        DWORD cb1, cb2;
    1582         HRESULT hr = directSoundPlayLock(pThis, pDSB, &pStream->Props, pDSoundStream->offPlayWritePos, cbLive,
     1584        HRESULT hr = directSoundPlayLock(pThis, pDSB, &pDSoundStream->Props, pDSoundStream->offPlayWritePos, cbLive,
    15831585                                         &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
    15841586        if (FAILED(hr))
     
    17001702
    17011703    /** @todo caller should already init Props? */
    1702     int rc = DrvAudioHlpStreamCfgToProps(&pDSoundStream->streamCfg, &pStream->Props); /** @todo Get rid of using Props! */
     1704    int rc = DrvAudioHlpStreamCfgToProps(&pDSoundStream->streamCfg, &pDSoundStream->Props);
    17031705    if (RT_SUCCESS(rc))
    17041706    {
     
    17121714
    17131715        if (pCfgAcq)
    1714             pCfgAcq->cSamples = pThis->cfg.cbBufferIn >> pStream->Props.cShift; /** @todo Get rid of using Props! */
     1716            pCfgAcq->cSamples = pThis->cfg.cbBufferIn >> pDSoundStream->Props.cShift;
    17151717
    17161718        /* Try to open capture in case the device is already there. */
     
    18191821        pDSoundStream->hrLastCapture = hr;
    18201822
    1821         if (offByteReadPos & pStream->Props.uAlign)
    1822             DSLOGF(("DSound: Misaligned capture read position %ld (alignment: %RU32)\n", offByteReadPos, pStream->Props.uAlign));
     1823        if (offByteReadPos & pDSoundStream->Props.uAlign)
     1824            DSLOGF(("DSound: Misaligned capture read position %ld (alignment: %RU32)\n", offByteReadPos, pDSoundStream->Props.uAlign));
    18231825
    18241826        /* Capture position in samples. */
    1825         DWORD idxSampleReadPos = offByteReadPos >> pStream->Props.cShift;
     1827        DWORD idxSampleReadPos = offByteReadPos >> pDSoundStream->Props.cShift;
    18261828
    18271829        /* Number of samples available in the DirectSound capture buffer. */
     
    18481850        PVOID pv1, pv2;
    18491851        DWORD cb1, cb2;
    1850         hr = directSoundCaptureLock(pDSCB, &pStream->Props,
     1852        hr = directSoundCaptureLock(pDSCB, &pDSoundStream->Props,
    18511853                                    AUDIOMIXBUF_S2B(&pStream->MixBuf, pDSoundStream->idxSampleCaptureReadPos), /* dwOffset */
    18521854                                    AUDIOMIXBUF_S2B(&pStream->MixBuf, cSamplesToCapture),                      /* dwBytes */
  • trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp

    r63488 r63529  
    133133
    134134    /* Just adopt the wanted stream configuration. */
    135     int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pStream->Props);
     135    PDMAUDIOPCMPROPS Props;
     136    int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &Props);
    136137    if (RT_SUCCESS(rc))
    137138    {
     
    157158    if (RT_SUCCESS(rc))
    158159    {
    159         pDbgStream->Out.tsLastPlayed  = 0;
     160        pDbgStream->Out.tsLastPlayed            = 0;
    160161        pDbgStream->Out.cMaxSamplesInPlayBuffer = _1K;
    161         pDbgStream->Out.pu8PlayBuffer = (uint8_t *)RTMemAlloc(pDbgStream->Out.cMaxSamplesInPlayBuffer << Props.cShift);
     162        pDbgStream->Out.pu8PlayBuffer           = (uint8_t *)RTMemAlloc(pDbgStream->Out.cMaxSamplesInPlayBuffer << Props.cShift);
    162163        if (!pDbgStream->Out.pu8PlayBuffer)
    163164            rc = VERR_NO_MEMORY;
     
    193194 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
    194195 */
    195 static DECLCALLBACK(int) drvHostDebugAudioStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     196static DECLCALLBACK(int) drvHostDebugAudioStreamCreate(PPDMIHOSTAUDIO pInterface,
     197                                                       PPDMAUDIOSTREAM pStream,
     198                                                       PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    196199{
    197200    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     
    213216 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
    214217 */
    215 static DECLCALLBACK(int) drvHostDebugAudioStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
     218static DECLCALLBACK(int) drvHostDebugAudioStreamPlay(PPDMIHOSTAUDIO pInterface,
     219                                                     PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf,
     220                                                     uint32_t *pcbWritten)
    216221{
    217222    RT_NOREF(pvBuf, cbBuf);
     
    284289 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
    285290 */
    286 static DECLCALLBACK(int) drvHostDebugAudioStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
     291static DECLCALLBACK(int) drvHostDebugAudioStreamCapture(PPDMIHOSTAUDIO pInterface,
     292                                                        PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
    287293{
    288294    RT_NOREF(pInterface, pStream, pvBuf, cbBuf);
  • trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp

    r63481 r63529  
    6262typedef struct NULLAUDIOSTREAMOUT
    6363{
     64    /** @note Always must come first! */
    6465    PDMAUDIOSTREAM      Stream;
     66    /** The PCM properties of this stream. */
     67    PDMAUDIOPCMPROPS    Props;
    6568    uint64_t            u64TicksLast;
    6669    uint64_t            cMaxSamplesInPlayBuffer;
     
    7376    /** @note Always must come first! */
    7477    PDMAUDIOSTREAM      Stream;
     78    /** The PCM properties of this stream. */
     79    PDMAUDIOPCMPROPS    Props;
    7580} NULLAUDIOSTREAMIN;
    7681typedef NULLAUDIOSTREAMIN *PNULLAUDIOSTREAMIN;
     
    150155static DECLCALLBACK(int) drvHostNullAudioStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
    151156{
     157    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     158    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     159
    152160    RT_NOREF2(pvBuf, cbBuf);
    153161
     
    169177     * If rounding is not taken into account then the playback rate will be consistently lower that expected.
    170178     */
    171     uint64_t cSamplesPlayed = (2 * u64TicksElapsed * pStream->Props.uHz + u64TicksFreq) / u64TicksFreq / 2;
     179    uint64_t cSamplesPlayed = (2 * u64TicksElapsed * pNullStream->Props.uHz + u64TicksFreq) / u64TicksFreq / 2;
    172180
    173181    /* Don't play more than available. */
     
    206214static int nullCreateStreamIn(PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    207215{
     216    PNULLAUDIOSTREAMIN pNullStream = RT_FROM_MEMBER(pStream, NULLAUDIOSTREAMIN, Stream);
     217
    208218    /* Just adopt the wanted stream configuration. */
    209     int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pStream->Props);
     219    int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pNullStream->Props);
    210220    if (RT_SUCCESS(rc))
    211221    {
     
    221231static int nullCreateStreamOut(PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    222232{
     233    PNULLAUDIOSTREAMOUT pNullStream = RT_FROM_MEMBER(pStream, NULLAUDIOSTREAMOUT, Stream);
     234
    223235    /* Just adopt the wanted stream configuration. */
    224     int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pStream->Props);
     236    int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pNullStream->Props);
    225237    if (RT_SUCCESS(rc))
    226238    {
    227         PNULLAUDIOSTREAMOUT pNullStream = RT_FROM_MEMBER(pStream, NULLAUDIOSTREAMOUT, Stream);
    228 
    229239        pNullStream->u64TicksLast  = 0;
    230240        pNullStream->cMaxSamplesInPlayBuffer = _1K;
    231241
    232         pNullStream->pbPlayBuffer = (uint8_t *)RTMemAlloc(_1K << pStream->Props.cShift);
     242        pNullStream->pbPlayBuffer = (uint8_t *)RTMemAlloc(_1K << pNullStream->Props.cShift);
    233243        if (pNullStream->pbPlayBuffer)
    234244        {
  • trunk/src/VBox/Devices/Audio/DrvHostOSSAudio.cpp

    r63481 r63529  
    8484    /** Note: Always must come first! */
    8585    PDMAUDIOSTREAM     pStreamIn;
     86    /** The PCM properties of this stream. */
     87    PDMAUDIOPCMPROPS   Props;
    8688    int                hFile;
    8789    int                cFragments;
     
    98100    /** Note: Always must come first! */
    99101    PDMAUDIOSTREAM      pStreamOut;
     102    /** The PCM properties of this stream. */
     103    PDMAUDIOPCMPROPS    Props;
    100104    int                 hFile;
    101105    int                 cFragments;
     
    363367        case PDMAUDIOSTREAMCMD_RESUME:
    364368        {
    365             DrvAudioHlpClearBuf(&pStream->Props, /** @todo Get rid of using Props! */
     369            DrvAudioHlpClearBuf(&pStreamOut->Props,
    366370                                pStreamOut->pvBuf, pStreamOut->cbBuf, AudioMixBufSize(&pStream->MixBuf));
    367371
     
    675679            pCfgAcq->enmEndianness = obtStream.enmENDIANNESS;
    676680
    677             PDMAUDIOPCMPROPS Props;
    678             rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &Props);
     681            rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &pStrm->Props);
    679682            if (RT_SUCCESS(rc))
    680683            {
    681                 if (obtStream.cFragments * obtStream.cbFragmentSize & Props.uAlign)
     684                if (obtStream.cFragments * obtStream.cbFragmentSize & pStrm->Props.uAlign)
    682685                {
    683686                    LogRel(("OSS: Warning: Misaligned capturing buffer: Size = %zu, Alignment = %u\n",
    684                             obtStream.cFragments * obtStream.cbFragmentSize, Props.uAlign + 1));
     687                            obtStream.cFragments * obtStream.cbFragmentSize, pStrm->Props.uAlign + 1));
    685688                }
    686689
    687                 cSamples = (obtStream.cFragments * obtStream.cbFragmentSize) >> Props.cShift;
     690                cSamples = (obtStream.cFragments * obtStream.cbFragmentSize) >> pStrm->Props.cShift;
    688691                if (!cSamples)
    689692                    rc = VERR_INVALID_PARAMETER;
     
    692695            if (RT_SUCCESS(rc))
    693696            {
    694                 size_t cbSample = (1 << Props.cShift);
     697                size_t cbSample = (1 << pStrm->Props.cShift);
    695698
    696699                size_t cbBuf = cSamples * cbSample;
     
    740743        reqStream.cbFragmentSize = s_OSSConf.fragsize;
    741744
    742         PDMAUDIOPCMPROPS Props;
    743         RT_ZERO(Props);
    744 
    745745        rc = ossStreamOpen(s_OSSConf.devpath_out, O_WRONLY | O_NONBLOCK, &reqStream, &obtStream, &hFile);
    746746        if (RT_SUCCESS(rc))
     
    751751            pCfgAcq->enmEndianness = obtStream.enmENDIANNESS;
    752752
    753             rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &Props);
     753            rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &pStrm->Props);
    754754            if (RT_SUCCESS(rc))
    755755            {
    756                 cSamples = (obtStream.cFragments * obtStream.cbFragmentSize) >> Props.cShift;
    757 
    758                 if (obtStream.cFragments * obtStream.cbFragmentSize & Props.uAlign)
     756                cSamples = (obtStream.cFragments * obtStream.cbFragmentSize) >> pStrm->Props.cShift;
     757
     758                if (obtStream.cFragments * obtStream.cbFragmentSize & pStrm->Props.uAlign)
    759759                {
    760760                    LogRel(("OSS: Warning: Misaligned playback buffer: Size = %zu, Alignment = %u\n",
    761                             obtStream.cFragments * obtStream.cbFragmentSize, Props.uAlign + 1));
     761                            obtStream.cFragments * obtStream.cbFragmentSize, pStrm->Props.uAlign + 1));
    762762                }
    763763            }
     
    768768            pStrm->fMemMapped = false;
    769769
    770             size_t cbSamples =  cSamples << Props.cShift;
     770            size_t cbSamples =  cSamples << pStrm->Props.cShift;
    771771            Assert(cbSamples);
    772772
  • trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp

    r63481 r63529  
    670670    pCfgAcq->cChannels = pStrm->SampleSpec.channels;
    671671
    672     rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &pStream->Props);
     672    PDMAUDIOPCMPROPS Props;
     673    rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &Props);
    673674    if (RT_SUCCESS(rc))
    674675    {
     
    681682            {
    682683                pStrm->cbPCMBuf = cbBuf;
    683 
    684                 pCfgAcq->cSamples = cbBuf >> pStream->Props.cShift; /** @todo Get rid of using Props! */
    685 
    686                 /* Save pointer to driver instance. */
    687                 pStrm->pDrv = pThis;
     684                pStrm->pDrv     = pThis;
     685
     686                pCfgAcq->cSamples = cbBuf >> Props.cShift;
    688687            }
    689688            else
     
    702701                            PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    703702{
    704     PDRVHOSTPULSEAUDIO pThis = PDMIHOSTAUDIO_2_DRVHOSTPULSEAUDIO(pInterface);
    705     PPULSEAUDIOSTREAM  pStrm = (PPULSEAUDIOSTREAM)pStream;
    706 
    707     pStrm->SampleSpec.format   = paFmtToPulse(pCfgReq->enmFormat);
    708     pStrm->SampleSpec.rate     = pCfgReq->uHz;
    709     pStrm->SampleSpec.channels = pCfgReq->cChannels;
    710 
    711     /* XXX check these values */
    712     pStrm->BufAttr.fragsize    = (pa_bytes_per_second(&pStrm->SampleSpec)
    713                                    * s_pulseCfg.buffer_msecs_in) / 1000;
    714     pStrm->BufAttr.maxlength   = (pStrm->BufAttr.fragsize * 3) / 2;
     703    PDRVHOSTPULSEAUDIO pThis   = PDMIHOSTAUDIO_2_DRVHOSTPULSEAUDIO(pInterface);
     704    PPULSEAUDIOSTREAM  pPAStrm = (PPULSEAUDIOSTREAM)pStream;
     705
     706    pPAStrm->SampleSpec.format   = paFmtToPulse(pCfgReq->enmFormat);
     707    pPAStrm->SampleSpec.rate     = pCfgReq->uHz;
     708    pPAStrm->SampleSpec.channels = pCfgReq->cChannels;
     709
     710    /** @todo Check these values! */
     711    pPAStrm->BufAttr.fragsize    = (pa_bytes_per_second(&pPAStrm->SampleSpec) * s_pulseCfg.buffer_msecs_in) / 1000;
     712    pPAStrm->BufAttr.maxlength   = (pPAStrm->BufAttr.fragsize * 3) / 2;
    715713
    716714    /* Note: Other members of BufAttr are ignored for record streams. */
    717     int rc = paStreamOpen(pThis, true /* fIn */, "PulseAudio (In)", &pStrm->SampleSpec, &pStrm->BufAttr,
    718                           &pStrm->pPAStream);
     715    int rc = paStreamOpen(pThis, true /* fIn */, "PulseAudio (In)", &pPAStrm->SampleSpec, &pPAStrm->BufAttr,
     716                          &pPAStrm->pPAStream);
    719717    if (RT_FAILURE(rc))
    720718        return rc;
    721719
    722     rc = paPulseToFmt(pStrm->SampleSpec.format, &pCfgAcq->enmFormat,
     720    rc = paPulseToFmt(pPAStrm->SampleSpec.format, &pCfgAcq->enmFormat,
    723721                      &pCfgAcq->enmEndianness);
    724722    if (RT_FAILURE(rc))
    725723    {
    726         LogRel(("PulseAudio: Cannot find audio capture format %ld\n", pStrm->SampleSpec.format));
     724        LogRel(("PulseAudio: Cannot find audio capture format %ld\n", pPAStrm->SampleSpec.format));
    727725        return rc;
    728726    }
    729727
    730     pCfgAcq->uHz       = pStrm->SampleSpec.rate;
    731     pCfgAcq->cChannels = pStrm->SampleSpec.channels;
    732 
    733     rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &pStream->Props);
     728    PDMAUDIOPCMPROPS Props;
     729    rc = DrvAudioHlpStreamCfgToProps(pCfgAcq, &Props);
    734730    if (RT_SUCCESS(rc))
    735731    {
    736         pCfgAcq->cSamples = RT_MIN(pStrm->BufAttr.fragsize * 10, pStrm->BufAttr.maxlength)
    737                             >> pStream->Props.cShift; /** @todo Get rid of using Props! */
    738 
    739         /* Save pointer to driver instance. */
    740         pStrm->pDrv       = pThis;
    741         pStrm->pu8PeekBuf = NULL;
     732        pPAStrm->pDrv       = pThis;
     733        pPAStrm->pu8PeekBuf = NULL;
     734
     735        pCfgAcq->uHz       = pPAStrm->SampleSpec.rate;
     736        pCfgAcq->cChannels = pPAStrm->SampleSpec.channels;
     737        pCfgAcq->cSamples  = RT_MIN(pPAStrm->BufAttr.fragsize * 10, pPAStrm->BufAttr.maxlength) >> Props.cShift;
    742738    }
    743739
  • trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp

    r63477 r63529  
    5252    /** Pointer to audio VRDE object. */
    5353    AudioVRDE           *pAudioVRDE;
     54    /** Pointer to the driver instance structure. */
    5455    PPDMDRVINS           pDrvIns;
    55     /** Pointer to the driver instance structure. */
     56    /** Pointer to host audio interface. */
    5657    PDMIHOSTAUDIO        IHostAudio;
    5758    /** Pointer to the VRDP's console object. */
     
    5960    /** Pointer to the DrvAudio port interface that is above us. */
    6061    PPDMIAUDIOCONNECTOR  pDrvAudio;
    61     /** Whether this driver is enabled or not. */
    62     bool                 fEnabled;
    6362} DRVAUDIOVRDE, *PDRVAUDIOVRDE;
    6463
    6564typedef struct VRDESTREAMIN
    6665{
    67     /** Associated host input stream.
    68      *  Note: Always must come first! */
     66    /** Note: Always must come first! */
    6967    PDMAUDIOSTREAM       Stream;
     68    /** The PCM properties of this stream. */
     69    PDMAUDIOPCMPROPS     Props;
    7070    /** Number of samples captured asynchronously in the
    7171     *  onVRDEInputXXX callbacks. */
     
    7777typedef struct VRDESTREAMOUT
    7878{
    79     /** Associated host output stream.
    80      *  Note: Always must come first! */
     79    /** Note: Always must come first! */
    8180    PDMAUDIOSTREAM       Stream;
     81    /** The PCM properties of this stream. */
     82    PDMAUDIOPCMPROPS     Props;
    8283    uint64_t             old_ticks;
    8384    uint64_t             cSamplesSentPerSec;
     
    9495    AssertPtrReturn(pCfgAcq,    VERR_INVALID_POINTER);
    9596
    96     if (pCfgAcq)
    97         pCfgAcq->cSamples = _4K; /** @todo Make this configurable. */
     97    PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pStream;
     98    AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
     99
     100    int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pVRDEStrmIn->Props);
     101    if (RT_SUCCESS(rc))
     102    {
     103        if (pCfgAcq)
     104            pCfgAcq->cSamples = _4K; /** @todo Make this configurable. */
     105    }
    98106
    99107    LogFlowFuncLeaveRC(VINF_SUCCESS);
     
    110118    AssertPtrReturn(pCfgAcq,    VERR_INVALID_POINTER);
    111119
    112     if (pCfgAcq)
    113         pCfgAcq->cSamples = _4K; /** @todo Make this configurable. */
     120    PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pStream;
     121    AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
     122
     123    int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pVRDEStrmOut->Props);
     124    if (RT_SUCCESS(rc))
     125    {
     126        if (pCfgAcq)
     127            pCfgAcq->cSamples = _4K; /** @todo Make this configurable. */
     128    }
    114129
    115130    LogFlowFuncLeaveRC(VINF_SUCCESS);
     
    157172    {
    158173        rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pVRDEStrmIn, AudioMixBufSize(&pStream->MixBuf),
    159                                                            pStream->Props.uHz,
    160                                                            pStream->Props.cChannels, pStream->Props.cBits);
     174                                                           pVRDEStrmIn->Props.uHz,
     175                                                           pVRDEStrmIn->Props.cChannels, pVRDEStrmIn->Props.cBits);
    161176        if (rc == VERR_NOT_SUPPORTED)
    162177        {
     
    192207 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
    193208 */
    194 static DECLCALLBACK(int) drvAudioVRDEStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
     209static DECLCALLBACK(int) drvAudioVRDEStreamCapture(PPDMIHOSTAUDIO pInterface,
     210                                                   PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
    195211{
    196212    RT_NOREF2(pvBuf, cbBuf);
     
    232248 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
    233249 */
    234 static DECLCALLBACK(int) drvAudioVRDEStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
     250static DECLCALLBACK(int) drvAudioVRDEStreamPlay(PPDMIHOSTAUDIO pInterface,
     251                                                PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)
    235252{
    236253    RT_NOREF2(pvBuf, cbBuf);
     
    250267
    251268    /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */
    252     uint32_t cSamplesPlayed = (int)((2 * ticks * pStream->Props.uHz + ticks_per_second) / ticks_per_second / 2);
     269    uint32_t cSamplesPlayed = (int)((2 * ticks * pVRDEStrmOut->Props.uHz + ticks_per_second) / ticks_per_second / 2);
    253270
    254271    /* Don't play more than available. */
     
    259276    pVRDEStrmOut->old_ticks = now;
    260277
    261     VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pStream->Props.uHz,
    262                                                  pStream->Props.cChannels,
    263                                                  pStream->Props.cBits,
    264                                                  pStream->Props.fSigned);
     278    VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pVRDEStrmOut->Props.uHz,
     279                                                 pVRDEStrmOut->Props.cChannels,
     280                                                 pVRDEStrmOut->Props.cBits,
     281                                                 pVRDEStrmOut->Props.fSigned);
    265282
    266283    int cSamplesToSend = cSamplesPlayed;
    267284
    268285    LogFlowFunc(("uFreq=%RU32, cChan=%RU8, cBits=%RU8, fSigned=%RTbool, enmFormat=%ld, cSamplesToSend=%RU32\n",
    269                  pStream->Props.uHz, pStream->Props.cChannels,
    270                  pStream->Props.cBits, pStream->Props.fSigned,
     286                 pVRDEStrmOut->Props.uHz,   pVRDEStrmOut->Props.cChannels,
     287                 pVRDEStrmOut->Props.cBits, pVRDEStrmOut->Props.fSigned,
    271288                 format, cSamplesToSend));
    272289
     
    381398 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
    382399 */
    383 static DECLCALLBACK(int) drvAudioVRDEStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     400static DECLCALLBACK(int) drvAudioVRDEStreamCreate(PPDMIHOSTAUDIO pInterface,
     401                                                  PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    384402{
    385403    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     
    419437 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
    420438 */
    421 static DECLCALLBACK(int) drvAudioVRDEStreamControl(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
     439static DECLCALLBACK(int) drvAudioVRDEStreamControl(PPDMIHOSTAUDIO pInterface,
     440                                                   PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
    422441{
    423442    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     
    497516int AudioVRDE::onVRDEControl(bool fEnable, uint32_t uFlags)
    498517{
    499     RT_NOREF(uFlags);
     518    RT_NOREF(fEnable, uFlags);
    500519    LogFlowThisFunc(("fEnable=%RTbool, uFlags=0x%x\n", fEnable, uFlags));
    501520
    502521    if (mpDrv == NULL)
    503522        return VERR_INVALID_STATE;
    504 
    505     mpDrv->fEnabled = fEnable;
    506523
    507524    return VINF_SUCCESS; /* Never veto. */
     
    607624    /* IHostAudio */
    608625    PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvAudioVRDE);
    609 
    610     /* Init defaults. */
    611     pThis->fEnabled = false;
    612626
    613627    /*
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