VirtualBox

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


Ignore:
Timestamp:
Jan 18, 2016 1:58:08 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105069
Message:

Audio/DrvHostCoreAudio.cpp: Recording fixes for OS X.

File:
1 edited

Legend:

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

    r59375 r59378  
    562562            if (err != noErr)
    563563            {
    564                 LogFlowFunc(("Failed rendering audio data (%RI32)\n", err));
     564                LogRel2(("CoreAudio: Failed rendering converted audio input data (%RI32)\n", err));
    565565                rc = VERR_IO_GEN_FAILURE; /** @todo Improve this. */
    566566                break;
     
    623623        else /* No converter being used. */
    624624        {
     625            AssertBreakStmt(pStreamIn->streamFormat.mChannelsPerFrame >= 1,    rc = VERR_INVALID_PARAMETER);
     626            AssertBreakStmt(pStreamIn->streamFormat.mBytesPerFrame >= 1,       rc = VERR_INVALID_PARAMETER);
     627
     628            AssertBreakStmt(pStreamIn->bufferList.mNumberBuffers >= 1,         rc = VERR_INVALID_PARAMETER);
     629            AssertBreakStmt(pStreamIn->bufferList.mBuffers[0].mNumberChannels, rc = VERR_INVALID_PARAMETER);
     630
    625631            pStreamIn->bufferList.mBuffers[0].mNumberChannels = pStreamIn->streamFormat.mChannelsPerFrame;
    626632            pStreamIn->bufferList.mBuffers[0].mDataByteSize   = pStreamIn->streamFormat.mBytesPerFrame * cFrames;
    627             AssertBreakStmt(pStreamIn->bufferList.mBuffers[0].mDataByteSize, rc = VERR_INVALID_PARAMETER);
    628633            pStreamIn->bufferList.mBuffers[0].mData           = RTMemAlloc(pStreamIn->bufferList.mBuffers[0].mDataByteSize);
    629634            if (!pStreamIn->bufferList.mBuffers[0].mData)
     
    636641            if (err != noErr)
    637642            {
    638                 LogFlowFunc(("Failed rendering audio data (%RI32)\n", err));
     643                LogRel2(("CoreAudio: Failed rendering non-coverted audio input data (%RI32)\n", err));
    639644                rc = VERR_IO_GEN_FAILURE; /** @todo Improve this. */
    640645                break;
    641646            }
    642647
    643             size_t cbAvail = RT_MIN(RTCircBufFree(pStreamIn->pBuf), pStreamIn->bufferList.mBuffers[0].mDataByteSize);
     648            const uint32_t cbDataSize = pStreamIn->bufferList.mBuffers[0].mDataByteSize;
     649            const size_t   cbBufFree  = RTCircBufFree(pStreamIn->pBuf);
     650                  size_t   cbAvail    = RT_MIN(cbDataSize, cbBufFree);
     651
     652            LogFlowFunc(("cbDataSize=%RU32, cbBufFree=%zu, cbAvail=%zu\n", cbDataSize, cbBufFree, cbAvail));
    644653
    645654            /* Iterate as long as data is available. */
    646655            uint8_t *puDst = NULL;
    647656            uint32_t cbWrittenTotal = 0;
    648             while(cbAvail)
     657            while (cbAvail)
    649658            {
    650659                /* Try to acquire the necessary space from the ring buffer. */
     
    654663                    break;
    655664
    656                 /* Copy the data from the core audio buffer to the ring buffer. */
     665                /* Copy the data from the Core Audio buffer to the ring buffer. */
    657666                memcpy(puDst, (uint8_t *)pStreamIn->bufferList.mBuffers[0].mData + cbWrittenTotal, cbToWrite);
    658667
     
    665674                cbAvail -= cbToWrite;
    666675            }
     676
     677            LogFlowFunc(("cbWrittenTotal=%RU32, cbLeft=%zu\n", cbWrittenTotal, cbAvail));
    667678        }
    668679
     
    675686    }
    676687
     688    LogFlowFuncLeaveRC(rc);
    677689    return err;
    678690}
     
    760772        return VERR_AUDIO_BACKEND_INIT_FAILED;
    761773    }
     774
     775    LogFlowFunc(("cFrames=%RU32\n", cFrames));
    762776
    763777    ComponentDescription cd;
     
    882896        /* Set the new input format description for the stream. */
    883897        err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
    884                                    1, &pStreamIn->deviceFormat, sizeof(pStreamIn->deviceFormat));
     898                                   1, &pStreamIn->streamFormat, sizeof(pStreamIn->streamFormat));
    885899        if (err != noErr)
    886900        {
     
    898912        LogRel(("CoreAudio: Input converter is active\n"));
    899913    }
    900 
    901     /* Set the new output format description for the stream. */
    902     err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
    903                                1, &pStreamIn->deviceFormat, sizeof(pStreamIn->deviceFormat));
    904     if (err != noErr)
    905     {
    906         LogRel(("CoreAudio: Failed to set output format for input stream (%RI32)\n", err));
    907         return VERR_AUDIO_BACKEND_INIT_FAILED;
     914    else
     915    {
     916        /* Set the new output format description for the stream. */
     917        err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
     918                                   1, &pStreamIn->streamFormat, sizeof(pStreamIn->streamFormat));
     919        if (err != noErr)
     920        {
     921            LogRel(("CoreAudio: Failed to set output format for input stream (%RI32)\n", err));
     922            return VERR_AUDIO_BACKEND_INIT_FAILED; /** @todo Fudge! */
     923        }
    908924    }
    909925
     
    943959     */
    944960    uSize = sizeof(cFrames);
    945     err = AudioUnitGetProperty(pStreamIn->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice,kAudioUnitScope_Global,
     961    err = AudioUnitGetProperty(pStreamIn->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
    946962                               0, &cFrames, &uSize);
    947963    if (err != noErr)
     
    972988     * samples count.
    973989     */
    974     UInt32 cSamples = cFrames * pStreamIn->streamFormat.mChannelsPerFrame;
     990    UInt32 cSamples = RT_MAX(cFrames,
     991                             (cFrames * pStreamIn->deviceFormat.mBytesPerFrame * pStreamIn->sampleRatio)
     992                              / pStreamIn->streamFormat.mBytesPerFrame)
     993                             * pStreamIn->streamFormat.mChannelsPerFrame;
    975994    if (!cSamples)
    976995    {
     
    13381357    {
    13391358        size_t cbBuf = AudioMixBufSizeBytes(&pHstStrmIn->MixBuf);
    1340         size_t cbToWrite = RT_MIN(cbBuf, RTCircBufFree(pStreamIn->pBuf));
    1341         LogFlowFunc(("cbToWrite=%zu\n", cbToWrite));
     1359        size_t cbToWrite = RT_MIN(cbBuf, RTCircBufUsed(pStreamIn->pBuf));
    13421360
    13431361        uint32_t cWritten, cbWritten;
     
    13451363        size_t   cbToRead;
    13461364
     1365        LogFlowFunc(("cbBuf=%zu, cbToWrite=%zu\n", cbBuf, cbToWrite));
     1366
    13471367        while (cbToWrite)
    13481368        {
     
    13651385
    13661386            Assert(cbToWrite >= cbWritten);
    1367             cbToWrite -= cbWritten;
     1387            cbToWrite      -= cbWritten;
    13681388            cbWrittenTotal += cbWritten;
    13691389        }
     1390
     1391        LogFlowFunc(("cbToWrite=%zu, cbWrittenTotal=%RU32\n", cbToWrite, cbWrittenTotal));
    13701392    }
    13711393    while (0);
     
    13731395    if (RT_SUCCESS(rc))
    13741396    {
     1397        uint32_t cCaptured     = 0;
    13751398        uint32_t cWrittenTotal = AUDIOMIXBUF_B2S(&pHstStrmIn->MixBuf, cbWrittenTotal);
    13761399        if (cWrittenTotal)
    1377             AudioMixBufFinish(&pHstStrmIn->MixBuf, cWrittenTotal);
    1378 
    1379         LogFlowFunc(("cWrittenTotal=%RU32 (%RU32 bytes)\n", cWrittenTotal, cbWrittenTotal));
     1400            rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal, &cCaptured);
     1401
     1402        LogFlowFunc(("cWrittenTotal=%RU32 (%RU32 bytes), cCaptured, rc=%Rrc\n", cWrittenTotal, cbWrittenTotal, cCaptured, rc));
    13801403
    13811404        if (pcSamplesCaptured)
    1382             *pcSamplesCaptured = cWrittenTotal;
    1383     }
    1384 
     1405            *pcSamplesCaptured = cCaptured;
     1406    }
     1407
     1408    LogFlowFuncLeaveRC(rc);
    13851409    return rc;
    13861410}
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