VirtualBox

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


Ignore:
Timestamp:
Sep 27, 2016 10:19:28 AM (8 years ago)
Author:
vboxsync
Message:

Audio/DrvHostCoreAudio.cpp: Update on Audio Queues (work in progress, not yet enabled by default).

File:
1 edited

Legend:

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

    r63958 r64034  
    4242#endif
    4343
    44 #if 0
     44#if 1
    4545# include <iprt/file.h>
    4646# define DEBUG_DUMP_PCM_DATA
     
    19281928int coreAudioInputQueueProcBuffer(PCOREAUDIOSTREAM pCAStream, AudioQueueBufferRef audioBuffer)
    19291929{
    1930     size_t cbWritten = 0;
    1931 
    19321930    PRTCIRCBUF pCircBuf = pCAStream->pCircBuf;
    19331931    AssertPtr(pCircBuf);
     
    19361934    UInt8 *pvDst = NULL;
    19371935
     1936    size_t cbWritten = 0;
     1937
    19381938    size_t cbToWrite = audioBuffer->mAudioDataByteSize;
    19391939    size_t cbLeft    = cbToWrite;
     
    19591959    }
    19601960
    1961     audioBuffer->mAudioDataByteSize = cbWritten;
    1962 
    1963     Log3Func(("pCAStream=%p, cbWritten=%zu\n", pCAStream, cbWritten));
     1961    Log3Func(("pCAStream=%p, cbBuffer=%RU32/%zu, cbWritten=%zu\n",
     1962              pCAStream, audioBuffer->mAudioDataByteSize, audioBuffer->mAudioDataBytesCapacity, cbWritten));
    19641963
    19651964    return VINF_SUCCESS;
     
    20962095        if (pCAStream->enmDir == PDMAUDIODIR_IN)
    20972096        {
     2097            int rc2 = coreAudioInputQueueProcBuffer(pCAStream, pBuf);
     2098            if (RT_SUCCESS(rc2))
     2099            {
     2100                AudioQueueEnqueueBuffer(pCAStream->audioQueue, pBuf, 0, NULL);
     2101            }
    20982102        }
    20992103        else if (pCAStream->enmDir == PDMAUDIODIR_OUT)
     
    32233227
    32243228    int rc = VINF_SUCCESS;
    3225     uint32_t cbWrittenTotal = 0;
     3229    uint32_t csWrittenTotal = 0;
    32263230
    32273231#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     
    32353239        size_t cbToWrite = RT_MIN(cbMixBuf, RTCircBufUsed(pCAStream->pCircBuf));
    32363240
    3237         uint32_t cWritten, cbWritten;
     3241        uint32_t csWritten, cbWritten;
    32383242        uint8_t *puBuf;
    3239         size_t   cbToRead = 0;
    32403243
    32413244        Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pCAStream->pCircBuf)));
     
    32443247        {
    32453248            /* Try to acquire the necessary block from the ring buffer. */
    3246             RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbToRead);
    3247             if (!cbToRead)
     3249            size_t cbChunk;
     3250            RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbChunk);
     3251            if (cbChunk)
     3252            {
     3253#ifdef DEBUG_DUMP_PCM_DATA
     3254                RTFILE fh;
     3255                rc = RTFileOpen(&fh, DEBUG_DUMP_PCM_DATA_PATH "ca-capture.pcm",
     3256                                RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
     3257                if (RT_SUCCESS(rc))
     3258                {
     3259                    RTFileWrite(fh, puBuf, cbChunk, NULL);
     3260                    RTFileClose(fh);
     3261                }
     3262                else
     3263                    AssertFailed();
     3264#endif
     3265                rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf, cbChunk, &csWritten);
     3266                if (rc == VERR_BUFFER_OVERFLOW)
     3267                {
     3268                    LogRel2(("Core Audio: Capturing host buffer full\n"));
     3269                    rc = VINF_SUCCESS;
     3270                }
     3271            }
     3272
     3273            /* Release the read buffer, so it could be used for new data. */
     3274            RTCircBufReleaseReadBlock(pCAStream->pCircBuf, cbChunk);
     3275
     3276            if (RT_FAILURE(rc))
    32483277                break;
    32493278
    3250 #ifdef DEBUG_DUMP_PCM_DATA
    3251             RTFILE fh;
    3252             rc = RTFileOpen(&fh, DEBUG_DUMP_PCM_DATA_PATH "ca-capture.pcm",
    3253                             RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
    3254             if (RT_SUCCESS(rc))
    3255             {
    3256                 RTFileWrite(fh, puBuf + cbWrittenTotal, cbToRead, NULL);
    3257                 RTFileClose(fh);
    3258             }
    3259             else
    3260                 AssertFailed();
    3261 #endif
    3262             rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf + cbWrittenTotal, cbToRead, &cWritten);
    3263 
    3264             /* Release the read buffer, so it could be used for new data. */
    3265             RTCircBufReleaseReadBlock(pCAStream->pCircBuf, cbToRead);
    3266 
    3267             if (   RT_FAILURE(rc)
    3268                 || !cWritten)
    3269             {
    3270                 break;
    3271             }
    3272 
    3273             cbWritten = AUDIOMIXBUF_S2B(&pStream->MixBuf, cWritten);
     3279            cbWritten = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWritten);
    32743280
    32753281            Assert(cbToWrite >= cbWritten);
    32763282            cbToWrite      -= cbWritten;
    3277             cbWrittenTotal += cbWritten;
    3278         }
    3279 
    3280         Log3Func(("cbToWrite=%zu, cbToRead=%zu, cbWrittenTotal=%RU32, rc=%Rrc\n", cbToWrite, cbToRead, cbWrittenTotal, rc));
     3283
     3284            csWrittenTotal += csWritten;
     3285        }
    32813286    }
    32823287    while (0);
     
    32873292#endif
    32883293
     3294    uint32_t cbWrittenTotal = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWrittenTotal);
     3295
     3296    Log3Func(("csWrittenTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", csWrittenTotal, cbWrittenTotal, rc));
     3297
    32893298    if (RT_SUCCESS(rc))
    32903299    {
    3291         uint32_t cCaptured    = 0;
    3292         uint32_t cWrittenTotal = AUDIOMIXBUF_B2S(&pStream->MixBuf, cbWrittenTotal);
    3293         if (cWrittenTotal)
    3294             rc = AudioMixBufMixToParent(&pStream->MixBuf, cWrittenTotal, &cCaptured);
    3295 
    3296         Log3Func(("cWrittenTotal=%RU32 (%RU32 bytes), cCaptured=%RU32, rc=%Rrc\n", cWrittenTotal, cbWrittenTotal, cCaptured, rc));
    3297 
    3298         if (cCaptured)
    3299             LogFlowFunc(("%RU32 samples captured\n", cCaptured));
     3300        uint32_t csMixed = 0;
     3301
     3302        if (csWrittenTotal)
     3303        {
     3304            RT_BREAKPOINT();
     3305            rc = AudioMixBufMixToParent(&pStream->MixBuf, csWrittenTotal, &csMixed);
     3306        }
     3307
     3308        Log3Func(("csMixed=%RU32\n", csMixed));
    33003309
    33013310        if (pcbRead)
    3302             *pcbRead = cCaptured;
     3311            *pcbRead = csMixed;
    33033312    }
    33043313
     
    34623471#ifdef VBOX_WITH_AUDIO_CA_QUEUES
    34633472            LogFunc(("Queue enable\n"));
    3464             ASMAtomicXchgBool(&pCAStream->fRun, true);
     3473            if (pCAStream->enmDir == PDMAUDIODIR_IN)
     3474            {
     3475                rc = coreAudioStreamInvalidateQueue(pCAStream);
     3476                if (RT_SUCCESS(rc))
     3477                {
     3478                    /* Start the audio queue immediately. */
     3479                    AudioQueueStart(pCAStream->audioQueue, NULL);
     3480                }
     3481            }
     3482            if (pCAStream->enmDir == PDMAUDIODIR_OUT)
     3483            {
     3484                /* Touch the run flag to start the audio queue as soon as
     3485                 * we have anough data to actually play something. */
     3486                ASMAtomicXchgBool(&pCAStream->fRun, true);
     3487            }
    34653488#else
    34663489            /* Only start the device if it is actually stopped */
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