VirtualBox

Changeset 82597 in vbox


Ignore:
Timestamp:
Dec 16, 2019 6:42:38 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135483
Message:

Audio/Mixer: Modularized code a bit more by adding audioMixerSinkInit() and audioMixerAddSinkInternal(), to match audioMixerSinkDestroyInternal() + audioMixerRemoveSinkInternal().

File:
1 edited

Legend:

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

    r82588 r82597  
    9090*   Internal Functions                                                                                                           *
    9191*********************************************************************************************************************************/
     92static int audioMixerAddSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
    9293static int audioMixerRemoveSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
    9394
     95static int audioMixerSinkInit(PAUDMIXSINK pSink, PAUDIOMIXER pMixer, const char *pcszName, AUDMIXSINKDIR enmDir);
    9496static void audioMixerSinkDestroyInternal(PAUDMIXSINK pSink);
    9597static int audioMixerSinkUpdateVolume(PAUDMIXSINK pSink, const PPDMAUDIOVOLUME pVolMaster);
     
    184186    if (pSink)
    185187    {
    186         pSink->pszName = RTStrDup(pszName);
    187         if (!pSink->pszName)
    188             rc = VERR_NO_MEMORY;
    189 
     188        rc = audioMixerSinkInit(pSink, pMixer, pszName, enmDir);
    190189        if (RT_SUCCESS(rc))
    191             rc = RTCritSectInit(&pSink->CritSect);
    192 
    193         if (RT_SUCCESS(rc))
    194         {
    195             pSink->pParent  = pMixer;
    196             pSink->enmDir   = enmDir;
    197             RTListInit(&pSink->lstStreams);
    198 
    199             /* Set initial volume to max. */
    200             pSink->Volume.fMuted = false;
    201             pSink->Volume.uLeft  = PDMAUDIO_VOLUME_MAX;
    202             pSink->Volume.uRight = PDMAUDIO_VOLUME_MAX;
    203 
    204             /* Ditto for the combined volume. */
    205             pSink->VolumeCombined.fMuted = false;
    206             pSink->VolumeCombined.uLeft  = PDMAUDIO_VOLUME_MAX;
    207             pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX;
    208 
    209             RTListAppend(&pMixer->lstSinks, &pSink->Node);
    210             pMixer->cSinks++;
    211 
    212             LogFlowFunc(("pMixer=%p, pSink=%p, cSinks=%RU8\n",
    213                          pMixer, pSink, pMixer->cSinks));
    214 
    215             if (ppSink)
    216                 *ppSink = pSink;
     190        {
     191            rc = audioMixerAddSinkInternal(pMixer, pSink);
     192            if (RT_SUCCESS(rc))
     193            {
     194                if (ppSink)
     195                    *ppSink = pSink;
     196            }
    217197        }
    218198
    219199        if (RT_FAILURE(rc))
    220200        {
    221             RTCritSectDelete(&pSink->CritSect);
    222 
    223             if (pSink)
    224             {
    225                 RTMemFree(pSink);
    226                 pSink = NULL;
    227             }
     201            audioMixerSinkDestroyInternal(pSink);
     202
     203            RTMemFree(pSink);
     204            pSink = NULL;
    228205        }
    229206    }
     
    245222 * @param   ppMixer             Pointer which returns the created mixer object.
    246223 */
    247 int AudioMixerCreate(const char *pszName, uint32_t fFlags, PAUDIOMIXER *ppMixer)
     224int AudioMixerCreate(const char *pcszName, uint32_t fFlags, PAUDIOMIXER *ppMixer)
    248225{
    249226    RT_NOREF(fFlags);
    250     AssertPtrReturn(pszName, VERR_INVALID_POINTER);
     227    AssertPtrReturn(pcszName, VERR_INVALID_POINTER);
    251228    /** @todo Add fFlags validation. */
    252229    AssertPtrReturn(ppMixer, VERR_INVALID_POINTER);
     
    257234    if (pMixer)
    258235    {
    259         pMixer->pszName = RTStrDup(pszName);
     236        pMixer->pszName = RTStrDup(pcszName);
    260237        if (!pMixer->pszName)
    261238            rc = VERR_NO_MEMORY;
     
    343320
    344321        audioMixerRemoveSinkInternal(pMixer, pSinkToRemove);
     322
    345323        audioMixerSinkDestroyInternal(pSinkToRemove);
     324
     325        RTMemFree(pSinkToRemove);
    346326    }
    347327
     
    409389
    410390/**
     391 * Adds sink to an existing mixer.
     392 *
     393 * @returns VBox status code.
     394 * @param   pMixer              Mixer to add sink to.
     395 * @param   pSink               Sink to add.
     396 */
     397static int audioMixerAddSinkInternal(PAUDIOMIXER pMixer, PAUDMIXSINK pSink)
     398{
     399    AssertPtrReturn(pMixer, VERR_INVALID_POINTER);
     400    AssertPtrReturn(pSink,  VERR_INVALID_POINTER);
     401
     402    /** @todo Check upper sink limit? */
     403    /** @todo Check for double-inserted sinks? */
     404
     405    RTListAppend(&pMixer->lstSinks, &pSink->Node);
     406    pMixer->cSinks++;
     407
     408    LogFlowFunc(("pMixer=%p, pSink=%p, cSinks=%RU8\n",
     409                 pMixer, pSink, pMixer->cSinks));
     410
     411    return VINF_SUCCESS;
     412}
     413
     414/**
    411415 * Removes a formerly attached audio sink for an audio mixer, internal version.
    412416 *
     
    429433    /* Remove sink from mixer. */
    430434    RTListNodeRemove(&pSink->Node);
     435
    431436    Assert(pMixer->cSinks);
     437    pMixer->cSinks--;
    432438
    433439    /* Set mixer to NULL so that we know we're not part of any mixer anymore. */
     
    810816
    811817/**
     818 * Initializes a sink.
     819 *
     820 * @returns VBox status code.
     821 * @param   pSink               Sink to initialize.
     822 * @param   pMixer              Mixer the sink is assigned to.
     823 * @param   pcszName            Name of the sink.
     824 * @param   enmDir              Direction of the sink.
     825 */
     826static int audioMixerSinkInit(PAUDMIXSINK pSink, PAUDIOMIXER pMixer, const char *pcszName, AUDMIXSINKDIR enmDir)
     827{
     828    pSink->pszName = RTStrDup(pcszName);
     829    if (!pSink->pszName)
     830        return VERR_NO_MEMORY;
     831
     832    int rc = RTCritSectInit(&pSink->CritSect);
     833    if (RT_SUCCESS(rc))
     834    {
     835        pSink->pParent  = pMixer;
     836        pSink->enmDir   = enmDir;
     837
     838        RTListInit(&pSink->lstStreams);
     839
     840        /* Set initial volume to max. */
     841        pSink->Volume.fMuted = false;
     842        pSink->Volume.uLeft  = PDMAUDIO_VOLUME_MAX;
     843        pSink->Volume.uRight = PDMAUDIO_VOLUME_MAX;
     844
     845        /* Ditto for the combined volume. */
     846        pSink->VolumeCombined.fMuted = false;
     847        pSink->VolumeCombined.uLeft  = PDMAUDIO_VOLUME_MAX;
     848        pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX;
     849    }
     850
     851    LogFlowFuncLeaveRC(rc);
     852    return rc;
     853}
     854
     855/**
    812856 * Destroys a mixer sink and removes it from the attached mixer (if any).
    813857 *
     
    830874
    831875        audioMixerRemoveSinkInternal(pMixer, pSink);
    832 
    833         Assert(pMixer->cSinks);
    834         pMixer->cSinks--;
    835876    }
    836877
     
    839880
    840881    audioMixerSinkDestroyInternal(pSink);
     882
     883    RTMemFree(pSink);
     884    pSink = NULL;
    841885}
    842886
     
    876920    AudioMixBufDestroy(&pSink->MixBuf);
    877921    RTCritSectDelete(&pSink->CritSect);
    878 
    879     RTMemFree(pSink);
    880     pSink = NULL;
    881922}
    882923
     
    9961037        return AUDMIXSINKDIR_UNKNOWN;
    9971038
    998     AUDMIXSINKDIR enmDir = pSink->enmDir;
     1039    const AUDMIXSINKDIR enmDir = pSink->enmDir;
    9991040
    10001041    int rc2 = RTCritSectLeave(&pSink->CritSect);
     
    10901131        return 0;
    10911132
    1092     uint8_t cStreams = pSink->cStreams;
     1133    const uint8_t cStreams = pSink->cStreams;
    10931134
    10941135    rc2 = RTCritSectLeave(&pSink->CritSect);
     
    11141155        return false;
    11151156
    1116     bool fIsActive = pSink->fStatus & AUDMIXSINK_STS_RUNNING;
     1157    const bool fIsActive = pSink->fStatus & AUDMIXSINK_STS_RUNNING;
    11171158    /* Note: AUDMIXSINK_STS_PENDING_DISABLE implies AUDMIXSINK_STS_RUNNING. */
    11181159
     
    15091550            rc = pStream->pConn->pfnEnable(pStream->pConn, PDMAUDIODIR_IN, true /* Enable */);
    15101551            if (RT_SUCCESS(rc))
     1552            {
    15111553                pSink->In.pStreamRecSource = pStream;
     1554            }
    15121555            else if (pSink->In.pStreamRecSource->pConn) /* Stay with the current recording source (if any) and re-enable it. */
    15131556            {
     
    23072350    return fIsValid;
    23082351}
    2309 
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