VirtualBox

Changeset 64171 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 6, 2016 4:26:14 PM (8 years ago)
Author:
vboxsync
Message:

Audio/DrvHostCoreAudio.cpp: Update on Audio Queues.

File:
1 edited

Legend:

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

    r64063 r64171  
    5757/** @todo Needs more investigation and testing first before enabling. */
    5858//# define VBOX_WITH_AUDIO_CA_CONVERTER
    59 
    60 #ifdef DEBUG_andy
    61 /** Enables support for Audio Queues. */
    62 # define VBOX_WITH_AUDIO_CA_QUEUES
    63 #endif
    6459
    6560#ifdef DEBUG_andy
     
    477472typedef struct COREAUDIOSTREAM
    478473{
    479     /** Host input stream.
     474    /** PDM audio stream data.
    480475     *  Note: Always must come first in this structure! */
    481     PDMAUDIOSTREAM          Stream;
    482     /** Note: This *always* must come first! */
     476    PDMAUDIOSTREAM              Stream;
     477    /** Stream-specific data, depending on the stream type. */
    483478    union
    484479    {
    485         COREAUDIOSTREAMIN   In;
    486         COREAUDIOSTREAMOUT  Out;
     480        COREAUDIOSTREAMIN       In;
     481        COREAUDIOSTREAMOUT      Out;
    487482    };
    488483    /** List node for the device's stream list. */
    489     RTLISTNODE              Node;
     484    RTLISTNODE                  Node;
    490485    /** Pointer to driver instance this stream is bound to. */
    491     PDRVHOSTCOREAUDIO       pDrv;
     486    PDRVHOSTCOREAUDIO           pDrv;
    492487    /** The stream's direction. */
    493     PDMAUDIODIR             enmDir;
     488    PDMAUDIODIR                 enmDir;
    494489#ifdef VBOX_WITH_AUDIO_CA_QUEUES
    495490    /** The stream's thread handle for maintaining the audio queue. */
    496     RTTHREAD                hThread;
     491    RTTHREAD                    hThread;
    497492    /** Flag indicating to start a stream's data processing. */
    498     bool                    fRun;
     493    bool                        fRun;
    499494    /** Whether the stream is in a running (active) state or not.
    500495     *  For playback streams this means that audio data can be (or is being) played,
    501496     *  for capturing streams this means that audio data is being captured (if available). */
    502     bool                    fIsRunning;
     497    bool                        fIsRunning;
    503498    /** Thread shutdown indicator. */
    504     bool                    fShutdown;
     499    bool                        fShutdown;
    505500    /** Critical section for serializing access between thread + callbacks. */
    506     RTCRITSECT              CritSect;
     501    RTCRITSECT                  CritSect;
    507502    /** The actual audio queue being used. */
    508     AudioQueueRef           audioQueue;
     503    AudioQueueRef               audioQueue;
    509504    /** The audio buffers which are used with the above audio queue. */
    510     AudioQueueBufferRef     audioBuffer[3];
    511     AudioStreamBasicDescription asbdAcq;
     505    AudioQueueBufferRef         audioBuffer[3];
     506    /** The acquired (final) audio format for this stream. */
     507    AudioStreamBasicDescription asbdStream;
    512508#endif
    513509    /** The audio unit for this stream. */
    514     COREAUDIOUNIT           Unit;
     510    COREAUDIOUNIT               Unit;
    515511    /** Initialization status tracker. Used when some of the device parameters
    516512     *  or the device itself is changed during the runtime. */
    517     volatile uint32_t       enmStatus;
     513    volatile uint32_t           enmStatus;
    518514    /** An internal ring buffer for transferring data from/to the rendering callbacks. */
    519     PRTCIRCBUF              pCircBuf;
     515    PRTCIRCBUF                  pCircBuf;
    520516} COREAUDIOSTREAM, *PCOREAUDIOSTREAM;
    521517
     
    18471843    OSStatus err;
    18481844    if (pCAStream->enmDir == PDMAUDIODIR_IN)
    1849         err = AudioQueueNewInput(&pCAStream->asbdAcq, coreAudioInputQueueCb, pCAStream /* pvData */,
     1845        err = AudioQueueNewInput(&pCAStream->asbdStream, coreAudioInputQueueCb, pCAStream /* pvData */,
    18501846                                 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue);
    18511847    else
    1852         err = AudioQueueNewOutput(&pCAStream->asbdAcq, coreAudioOutputQueueCb, pCAStream /* pvData */,
     1848        err = AudioQueueNewOutput(&pCAStream->asbdStream, coreAudioOutputQueueCb, pCAStream /* pvData */,
    18531849                                  CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue);
    18541850
     
    21432139
    21442140    /* Create the recording device's out format based on our required audio settings. */
    2145     int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbdAcq);
     2141    int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbdStream);
    21462142    if (RT_FAILURE(rc))
    21472143    {
     
    21532149    coreAudioPrintASBD(  fIn
    21542150                       ? "Capturing queue format"
    2155                        : "Playback queue format", &pCAStream->asbdAcq);
     2151                       : "Playback queue format", &pCAStream->asbdStream);
    21562152
    21572153    rc = RTCircBufCreate(&pCAStream->pCircBuf, 8096 << 1 /*pHstStrmIn->Props.cShift*/); /** @todo FIX THIS !!! */
     
    32423238
    32433239        uint32_t csWritten, cbWritten;
    3244         uint8_t *puBuf;
     3240
     3241        uint8_t *pvChunk;
     3242        size_t   cbChunk;
    32453243
    32463244        Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pCAStream->pCircBuf)));
     
    32493247        {
    32503248            /* Try to acquire the necessary block from the ring buffer. */
    3251             size_t cbChunk;
    3252             RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbChunk);
     3249            RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&pvChunk, &cbChunk);
    32533250            if (cbChunk)
    32543251            {
     
    32593256                if (RT_SUCCESS(rc))
    32603257                {
    3261                     RTFileWrite(fh, puBuf, cbChunk, NULL);
     3258                    RTFileWrite(fh, pvChunk, cbChunk, NULL);
    32623259                    RTFileClose(fh);
    32633260                }
     
    32653262                    AssertFailed();
    32663263#endif
    3267                 rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf, cbChunk, &csWritten);
     3264                rc = AudioMixBufWriteCirc(&pStream->MixBuf, pvChunk, cbChunk, &csWritten);
    32683265                if (rc == VERR_BUFFER_OVERFLOW)
    32693266                {
     
    32963293#ifdef LOG_ENABLED
    32973294    uint32_t cbWrittenTotal = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWrittenTotal);
    3298 #endif
    32993295    Log3Func(("csWrittenTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", csWrittenTotal, cbWrittenTotal, rc));
     3296#endif
    33003297
    33013298    if (RT_SUCCESS(rc))
     
    33773374    Log3Func(("cbLive=%zu, cbToRead=%zu\n", cbLive, cbToRead));
    33783375
     3376    uint8_t *pvChunk;
     3377    size_t   cbChunk;
     3378
    33793379    while (cbToRead)
    33803380    {
    33813381        uint32_t cRead, cbRead;
    3382         uint8_t *puBuf;
    3383         size_t   cbCopy;
    33843382
    33853383        /* Try to acquire the necessary space from the ring buffer. */
    3386         RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbToRead, (void **)&puBuf, &cbCopy);
    3387         if (!cbCopy)
    3388         {
    3389             RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbCopy);
     3384        RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbToRead, (void **)&pvChunk, &cbChunk);
     3385        if (!cbChunk)
     3386        {
     3387            RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbChunk);
    33903388            break;
    33913389        }
    33923390
    3393         Assert(cbCopy <= cbToRead);
    3394 
    3395         rc = AudioMixBufReadCirc(&pStream->MixBuf, puBuf, cbCopy, &cRead);
    3396         if (   RT_FAILURE(rc)
    3397             || !cRead)
    3398         {
    3399             RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, 0);
     3391        Assert(cbChunk <= cbToRead);
     3392
     3393        rc = AudioMixBufReadCirc(&pStream->MixBuf, pvChunk, cbChunk, &cRead);
     3394
     3395        cbRead = AUDIOMIXBUF_S2B(&pStream->MixBuf, cRead);
     3396
     3397        /* Release the ring buffer, so the read thread could start reading this data. */
     3398        RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbChunk);
     3399
     3400        if (RT_FAILURE(rc))
    34003401            break;
    3401         }
    3402 
    3403         cbRead = AUDIOMIXBUF_S2B(&pStream->MixBuf, cRead);
    3404 
    3405         /* Release the ring buffer, so the read thread could start reading this data. */
    3406         RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbRead);
    34073402
    34083403        Assert(cbToRead >= cbRead);
     
    35113506
    35123507        case PDMAUDIOSTREAMCMD_DISABLE:
    3513         {
    35143508#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     3509        {
    35153510            LogFunc(("Queue disable\n"));
    35163511            AudioQueueStop(pCAStream->audioQueue, 1 /* Immediately */);
    35173512            ASMAtomicXchgBool(&pCAStream->fRun,       false);
    35183513            ASMAtomicXchgBool(&pCAStream->fIsRunning, false);
    3519 #endif
    35203514            break;
    35213515        }
    3522 
     3516#endif
    35233517        case PDMAUDIOSTREAMCMD_PAUSE:
    35243518        {
     
    37133707        if (RT_SUCCESS(rc))
    37143708        {
     3709            ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);
     3710
    37153711#ifdef VBOX_WITH_AUDIO_CA_QUEUES
    3716             ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);
    3717 
    37183712            rc = coreAudioStreamInitQueue(pCAStream, pCfgReq, pCfgAcq);
    3719 
    3720             pCfgAcq->cSampleBufferSize = _4K; /** @todo FIX THIS !!! */
     3713            if (RT_SUCCESS(rc))
     3714            {
     3715                pCfgAcq->cSampleBufferSize = _4K; /** @todo FIX THIS !!! */
     3716            }
    37213717#else
    37223718            if (fIn)
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