VirtualBox

Changeset 54513 in vbox


Ignore:
Timestamp:
Feb 25, 2015 7:07:34 PM (10 years ago)
Author:
vboxsync
Message:

PDM/Audio: Update for Core Audio backend.

File:
1 edited

Legend:

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

    r54508 r54513  
    988988        *pcSamples = cSamples;
    989989
    990     LogFunc(("cSamples=%RU32\n", cSamples));
    991     return VINF_SUCCESS;
     990    LogFunc(("cSamples=%RU32, rc=%Rrc\n", cSamples, rc));
     991    return rc;
    992992}
    993993
     
    995995static int drvHostCoreAudioInitOutput(PPDMAUDIOHSTSTRMOUT pHstStrmOut, uint32_t *pcSamples)
    996996{
     997    PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut;
     998
     999    ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_IN_INIT);
     1000
    9971001    OSStatus err = noErr;
    998 
    999     UInt32 cSamples; /* samples count */
    1000 
    1001     PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut;
    1002 
    1003     ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_IN_INIT);
    10041002
    10051003    UInt32 uSize = 0;
     
    12031201    {
    12041202        LogRel(("CoreAudio: Failed to get maximum frame buffer size from output audio device (%RI32)\n", err));
    1205         return VERR_GENERAL_FAILURE; /** @todo Fudge! */
    1206     }
    1207 
    1208     int rc = VINF_SUCCESS;
    1209 #if 0
    1210     /* Calculate the ratio between the device and the stream sample rate. */
    1211     pStreamOut->sampleRatio = pStreamOut->streamFormat.mSampleRate / pStreamOut->deviceFormat.mSampleRate;
    1212 
    1213     /* Set to zero first */
    1214     pStreamOut->pBuf = NULL;
    1215     /* Create the AudioBufferList structure with one buffer. */
    1216     pStreamOut->bufferList.mNumberBuffers = 1;
    1217     /* Initialize the buffer to nothing. */
    1218     pStreamOut->bufferList.mBuffers[0].mNumberChannels = pStreamOut->streamFormat.mChannelsPerFrame;
    1219     pStreamOut->bufferList.mBuffers[0].mDataByteSize = 0;
    1220     pStreamOut->bufferList.mBuffers[0].mData = NULL;
    1221 
    1222     /* Make sure that the ring buffer is big enough to hold the recording
     1203
     1204        AudioUnitUninitialize(pStreamOut->audioUnit);
     1205        return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1206    }
     1207
     1208    /*
     1209     * Make sure that the ring buffer is big enough to hold the recording
    12231210     * data. Compare the maximum frames per slice value with the frames
    12241211     * necessary when using the converter where the sample rate could differ.
    12251212     * The result is always multiplied by the channels per frame to get the
    1226      * samples count. */
    1227     cSamples = RT_MAX(cFrames,
    1228                       (cFrames * pStreamOut->deviceFormat.mBytesPerFrame * pStreamOut->sampleRatio) / pStreamOut->streamFormat.mBytesPerFrame)
    1229                * pStreamOut->streamFormat.mChannelsPerFrame;
    1230 
    1231     if (   pHstStrmIn->cSamples != 0
    1232         && pHstStrmIn->cSamples != (int32_t)cSamples)
    1233         LogRel(("CoreAudio: Warning! After recreation, the CoreAudio ring buffer doesn't has the same size as the device buffer (%RU32 vs. %RU32).\n", cSamples, (uint32_t)pHstStrmIn->cSamples));
     1213     * samples count.
     1214     */
     1215    UInt32 cSamples = cFrames * pStreamOut->streamFormat.mChannelsPerFrame;
    12341216
    12351217    /* Create the internal ring buffer. */
    1236     RTCircBufCreate(&pStreamIn->pBuf, cSamples << pHstStrmIn->Props.cShift);
    1237     if (RT_VALID_PTR(pStreamIn->pBuf))
    1238         rc = 0;
    1239     else
    1240         LogRel(("CoreAudio: Failed to create internal ring buffer\n"));
    1241 #endif
    1242 
    1243     if (RT_FAILURE(rc))
    1244     {
    1245         /*if (pStreamOut->pBuf)
    1246             RTCircBufDestroy(pStreamOut->pBuf);*/
    1247 
    1248         AudioUnitUninitialize(pStreamOut->audioUnit);
    1249         return rc;
    1250     }
    1251 
     1218    int rc = RTCircBufCreate(&pStreamOut->pBuf, cSamples << pHstStrmOut->Props.cShift);
     1219    if (RT_SUCCESS(rc))
     1220    {
    12521221#ifdef DEBUG
    1253     propAdr.mSelector = kAudioDeviceProcessorOverload;
    1254     propAdr.mScope    = kAudioUnitScope_Global;
    1255     err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1256                                          drvHostCoreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1257     if (RT_UNLIKELY(err != noErr))
    1258         LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
     1222        propAdr.mSelector = kAudioDeviceProcessorOverload;
     1223        propAdr.mScope    = kAudioUnitScope_Global;
     1224        err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1225                                             drvHostCoreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1226        if (err != noErr)
     1227            LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
    12591228#endif /* DEBUG */
    1260     propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
    1261     propAdr.mScope    = kAudioUnitScope_Global;
    1262     err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1263                                          drvHostCoreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1264     /* Not fatal. */
    1265     if (RT_UNLIKELY(err != noErr))
    1266         LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
    1267 
    1268     /* Allocate temporary buffer. */
    1269     pStreamOut->cbPCMBuf = _4K; /** @todo Make this configurable. */
    1270     pStreamOut->pvPCMBuf = RTMemAlloc(pStreamOut->cbPCMBuf);
    1271     if (!pStreamOut->pvPCMBuf)
    1272         rc = VERR_NO_MEMORY;
     1229
     1230        propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
     1231        propAdr.mScope    = kAudioUnitScope_Global;
     1232        err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1233                                             drvHostCoreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1234        /* Not fatal. */
     1235        if (err != noErr)
     1236            LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
     1237
     1238        /* Allocate temporary buffer. */
     1239        pStreamOut->cbPCMBuf = _4K; /** @todo Make this configurable. */
     1240        pStreamOut->pvPCMBuf = RTMemAlloc(pStreamOut->cbPCMBuf);
     1241        if (!pStreamOut->pvPCMBuf)
     1242            rc = VERR_NO_MEMORY;
     1243    }
    12731244
    12741245    if (RT_SUCCESS(rc))
     
    12781249        if (pcSamples)
    12791250            *pcSamples = cSamples;
    1280 
    1281         LogFunc(("cSamples=%RU32\n", cSamples));
    1282     }
    1283 
     1251    }
     1252    else
     1253        AudioUnitUninitialize(pStreamOut->audioUnit);
     1254
     1255    LogFunc(("cSamples=%RU32, rc=%Rrc\n", cSamples, rc));
    12841256    return rc;
    12851257}
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