VirtualBox

Changeset 89184 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 19, 2021 8:58:09 PM (4 years ago)
Author:
vboxsync
Message:

Audio: Working on asynchronous stream creation, only there is a stupid stupid single lock approach in DrvAudio that significantly hampers the effect. bugref:9890

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

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

    r89131 r89184  
    20632063
    20642064/**
     2065 * Asynchronous worker for drvAudioStreamDestroy.
     2066 *
     2067 * Does DISABLE and releases reference, possibly destroying the stream.
     2068 *
     2069 * @param   pThis       Pointer to the DrvAudio instance data.
     2070 * @param   pStreamEx   The stream.  One reference for us to release.
     2071 */
     2072static DECLCALLBACK(void) drvAudioStreamDestroyAsync(PDRVAUDIO pThis, PDRVAUDIOSTREAM pStreamEx)
     2073{
     2074    LogFlow(("pThis=%p pStreamEx=%p (%s)\n", pThis, pStreamEx, pStreamEx->Core.szName));
     2075
     2076    /** @todo r=bird: This isn't doing the trick for core audio, as the big
     2077     *        simple-minded critsect is held while the often very slow
     2078     *        AudioQueueDestroy call is made, blocking creation and manipulation
     2079     *        of new streams.  Sigh^3. */
     2080
     2081    /** @todo can we somehow drain it instead? */
     2082    int rc2 = drvAudioStreamControlInternal(pThis, pStreamEx, PDMAUDIOSTREAMCMD_DISABLE);
     2083    LogFlow(("DISABLE done: %Rrc\n", rc2));
     2084    AssertRC(rc2);
     2085
     2086    drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     2087    LogFlow(("returning\n"));
     2088}
     2089
     2090
     2091/**
    20652092 * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamDestroy}
    20662093 */
     
    21212148            }
    21222149
    2123             /* We don't really care about the status here as we'll release a reference regardless of the state. */
    2124             /** @todo can we somehow drain it instead? */
    2125             int rc2 = drvAudioStreamControlInternal(pThis, pStreamEx, PDMAUDIOSTREAMCMD_DISABLE);
    2126             AssertRC(rc2);
    2127 
    2128             drvAudioStreamReleaseInternal(pThis, pStreamEx, true /*fMayDestroy*/);
     2150            /*
     2151             * Now, if the backend requests asynchronous disabling and destruction
     2152             * push the disabling and destroying over to a worker thread.
     2153             *
     2154             * This is a general offloading feature that all backends should make use of,
     2155             * however it's rather precarious on macs where stopping an already draining
     2156             * stream may take 8-10ms which naturally isn't something we should be doing
     2157             * on an EMT.
     2158             */
     2159            if (!(pThis->BackendCfg.fFlags & PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY))
     2160                drvAudioStreamDestroyAsync(pThis, pStreamEx);
     2161            else
     2162            {
     2163                int rc2 = RTReqPoolCallEx(pThis->hReqPool, 0 /*cMillies*/, NULL /*phReq*/,
     2164                                          RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
     2165                                          (PFNRT)drvAudioStreamDestroyAsync, 2, pThis, pStreamEx);
     2166                LogFlowFunc(("hReqInitAsync=%p rc2=%Rrc\n", pStreamEx->hReqInitAsync, rc2));
     2167                AssertRCStmt(rc2, drvAudioStreamDestroyAsync(pThis, pStreamEx));
     2168            }
    21292169        }
    21302170        else
     
    43874427        && (   pIHostDrvAudio->pfnStreamInitAsync
    43884428            || pIHostDrvAudio->pfnDoOnWorkerThread
    4389             || (pThis->BackendCfg.fFlags & PDMAUDIOBACKEND_F_ASYNC_HINT) ))
     4429            || (pThis->BackendCfg.fFlags & (PDMAUDIOBACKEND_F_ASYNC_HINT | PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY)) ))
    43904430    {
    43914431        char szName[16];
  • trunk/src/VBox/Devices/Audio/DrvHostAudioCoreAudio.cpp

    r89167 r89184  
    703703    RTStrCopy(pBackendCfg->szName, sizeof(pBackendCfg->szName), "Core Audio");
    704704    pBackendCfg->cbStream       = sizeof(COREAUDIOSTREAM);
    705     pBackendCfg->fFlags         = 0;
     705    pBackendCfg->fFlags         = PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY;
    706706    /* For Core Audio we provide one stream per device for now. */
    707707    pBackendCfg->cMaxStreamsIn  = PDMAudioHostEnumCountMatching(&pThis->Devices, PDMAUDIODIR_IN);
     
    16371637
    16381638/**
    1639  * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamInitAsync}
    1640  */
    1641 static DECLCALLBACK(int) drvHostAudioCaHA_StreamInitAsync(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, bool fDestroyed)
    1642 {
    1643     RT_NOREF(pInterface, pStream, fDestroyed);
    1644     return VINF_SUCCESS;
    1645 }
    1646 
    1647 
    1648 /**
    16491639 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
    16501640 */
     
    17071697        if (pStreamCA->hAudioQueue)
    17081698        {
    1709             LogFlowFunc(("Disposing of the queue ...\n", orc));
    1710             orc = AudioQueueDispose(pStreamCA->hAudioQueue, TRUE /*inImmediate/synchronously*/);
     1699            LogFlowFunc(("Disposing of the queue ...\n"));
     1700            orc = AudioQueueDispose(pStreamCA->hAudioQueue, TRUE /*inImmediate/synchronously*/); /* may take some time */
    17111701            LogFlowFunc(("AudioQueueDispose -> %#x (%d)\n", orc, orc));
    17121702            AssertMsg(orc == noErr, ("AudioQueueDispose -> orc=%#x\n", orc));
     
    26432633    pThis->IHostAudio.pfnStreamConfigHint           = NULL;
    26442634    pThis->IHostAudio.pfnStreamCreate               = drvHostAudioCaHA_StreamCreate;
    2645     pThis->IHostAudio.pfnStreamInitAsync            = drvHostAudioCaHA_StreamInitAsync;
     2635    pThis->IHostAudio.pfnStreamInitAsync            = NULL;
    26462636    pThis->IHostAudio.pfnStreamDestroy              = drvHostAudioCaHA_StreamDestroy;
    26472637    pThis->IHostAudio.pfnStreamNotifyDeviceChanged  = NULL;
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