VirtualBox

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


Ignore:
Timestamp:
Sep 4, 2018 9:22:25 AM (6 years ago)
Author:
vboxsync
Message:

Audio/AC97: Implemented ichac97R3MixerAddDrv() / ichac97R3MixerRemoveDrv() and added the ability to (re-)set the recording source automatically when a driver get detached at runtime.

File:
1 edited

Legend:

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

    r74038 r74059  
    396396typedef struct AC97DRIVERSTREAM
    397397{
    398     union
    399     {
    400         /** Desired playback destination (for an output stream). */
    401         PDMAUDIOPLAYBACKDEST           Dest;
    402         /** Desired recording source (for an input stream). */
    403         PDMAUDIORECSOURCE              Source;
    404     } DestSource;
    405     uint8_t                            Padding1[4];
    406398    /** Associated mixer stream handle. */
    407399    R3PTRTYPE(PAUDMIXSTREAM)           pMixStrm;
     
    654646static void               ichac97R3DoTransfers(PAC97STATE pThis);
    655647
     648static int                ichac97R3MixerAddDrv(PAC97STATE pThis, PAC97DRIVER pDrv);
    656649static int                ichac97R3MixerAddDrvStream(PAC97STATE pThis, PAUDMIXSINK pMixSink, PPDMAUDIOSTREAMCFG pCfg, PAC97DRIVER pDrv);
    657650static int                ichac97R3MixerAddDrvStreams(PAC97STATE pThis, PAUDMIXSINK pMixSink, PPDMAUDIOSTREAMCFG pCfg);
     651static void               ichac97R3MixerRemoveDrv(PAC97STATE pThis, PAC97DRIVER pDrv);
    658652static void               ichac97R3MixerRemoveDrvStream(PAC97STATE pThis, PAUDMIXSINK pMixSink, PDMAUDIODIR enmDir, PDMAUDIODESTSOURCE dstSrc, PAC97DRIVER pDrv);
    659653static void               ichac97R3MixerRemoveDrvStreams(PAC97STATE pThis, PAUDMIXSINK pMixSink, PDMAUDIODIR enmDir, PDMAUDIODESTSOURCE dstSrc);
     
    17811775    LogFlowFuncLeaveRC(rc);
    17821776    return rc;
     1777}
     1778
     1779/**
     1780 * Adds a specific AC'97 driver to the driver chain.
     1781 *
     1782 * @return IPRT status code.
     1783 * @param  pThis                AC'97 state.
     1784 * @param  pDrv                 AC'97 driver to add.
     1785 */
     1786static int ichac97R3MixerAddDrv(PAC97STATE pThis, PAC97DRIVER pDrv)
     1787{
     1788    int rc = VINF_SUCCESS;
     1789
     1790    if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamLineIn.State.Cfg))
     1791    {
     1792        int rc2 = ichac97R3MixerAddDrvStream(pThis, pThis->pSinkLineIn, &pThis->StreamLineIn.State.Cfg, pDrv);
     1793        if (RT_SUCCESS(rc))
     1794            rc = rc2;
     1795    }
     1796
     1797    if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamMicIn.State.Cfg))
     1798    {
     1799        int rc2 = ichac97R3MixerAddDrvStream(pThis, pThis->pSinkMicIn,  &pThis->StreamMicIn.State.Cfg, pDrv);
     1800        if (RT_SUCCESS(rc))
     1801            rc = rc2;
     1802    }
     1803
     1804    if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamOut.State.Cfg))
     1805    {
     1806        int rc2 = ichac97R3MixerAddDrvStream(pThis, pThis->pSinkOut,    &pThis->StreamOut.State.Cfg, pDrv);
     1807        if (RT_SUCCESS(rc))
     1808            rc = rc2;
     1809    }
     1810
     1811    return rc;
     1812}
     1813
     1814/**
     1815 * Removes a specific AC'97 driver from the driver chain and destroys its
     1816 * associated streams.
     1817 *
     1818 * @param pThis                 AC'97 state.
     1819 * @param pDrv                  AC'97 driver to remove.
     1820 */
     1821static void ichac97R3MixerRemoveDrv(PAC97STATE pThis, PAC97DRIVER pDrv)
     1822{
     1823    AssertPtrReturnVoid(pThis);
     1824    AssertPtrReturnVoid(pDrv);
     1825
     1826    if (pDrv->MicIn.pMixStrm)
     1827    {
     1828        if (AudioMixerSinkGetRecordingSource(pThis->pSinkMicIn) == pDrv->MicIn.pMixStrm)
     1829            AudioMixerSinkSetRecordingSource(pThis->pSinkMicIn, NULL);
     1830
     1831        AudioMixerSinkRemoveStream(pThis->pSinkMicIn,  pDrv->MicIn.pMixStrm);
     1832        AudioMixerStreamDestroy(pDrv->MicIn.pMixStrm);
     1833        pDrv->MicIn.pMixStrm = NULL;
     1834    }
     1835
     1836    if (pDrv->LineIn.pMixStrm)
     1837    {
     1838        if (AudioMixerSinkGetRecordingSource(pThis->pSinkLineIn) == pDrv->LineIn.pMixStrm)
     1839            AudioMixerSinkSetRecordingSource(pThis->pSinkLineIn, NULL);
     1840
     1841        AudioMixerSinkRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.pMixStrm);
     1842        AudioMixerStreamDestroy(pDrv->LineIn.pMixStrm);
     1843        pDrv->LineIn.pMixStrm = NULL;
     1844    }
     1845
     1846    if (pDrv->Out.pMixStrm)
     1847    {
     1848        AudioMixerSinkRemoveStream(pThis->pSinkOut,    pDrv->Out.pMixStrm);
     1849        AudioMixerStreamDestroy(pDrv->Out.pMixStrm);
     1850        pDrv->Out.pMixStrm = NULL;
     1851    }
     1852
     1853    RTListNodeRemove(&pDrv->Node);
    17831854}
    17841855
     
    36933764 * @returns VBox status code.
    36943765 * @param   pThis       AC'97 state.
    3695  * @param   uLUN        The logical unit which is being detached.
     3766 * @param   uLUN        The logical unit which is being attached.
    36963767 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    36973768 * @param   ppDrv       Attached driver instance on success. Optional.
     
    37663837 * @returns VBox status code.
    37673838 * @param   pThis       AC'97 state.
    3768  * @param   pDrv        Driver to detach device from.
     3839 * @param   pDrv        Driver to detach from device.
    37693840 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    37703841 */
     
    37733844    RT_NOREF(fFlags);
    37743845
    3775     AudioMixerSinkRemoveStream(pThis->pSinkMicIn,  pDrv->MicIn.pMixStrm);
    3776     AudioMixerStreamDestroy(pDrv->MicIn.pMixStrm);
    3777     pDrv->MicIn.pMixStrm = NULL;
    3778 
    3779     AudioMixerSinkRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.pMixStrm);
    3780     AudioMixerStreamDestroy(pDrv->LineIn.pMixStrm);
    3781     pDrv->LineIn.pMixStrm = NULL;
    3782 
    3783     AudioMixerSinkRemoveStream(pThis->pSinkOut,    pDrv->Out.pMixStrm);
    3784     AudioMixerStreamDestroy(pDrv->Out.pMixStrm);
    3785     pDrv->Out.pMixStrm = NULL;
    3786 
    3787     RTListNodeRemove(&pDrv->Node);
     3846    /* First, remove the driver from our list and destory it's associated streams.
     3847     * This also will un-set the driver as a recording source (if associated). */
     3848    ichac97R3MixerRemoveDrv(pThis, pDrv);
     3849
     3850    /* Next, search backwards for a capable (attached) driver which now will be the
     3851     * new recording source. */
     3852    PDMAUDIODESTSOURCE dstSrc;
     3853    PAC97DRIVER pDrvCur;
     3854    RTListForEachReverse(&pThis->lstDrv, pDrvCur, AC97DRIVER, Node)
     3855    {
     3856        if (!pDrvCur->pConnector)
     3857            continue;
     3858
     3859        PDMAUDIOBACKENDCFG Cfg;
     3860        int rc2 = pDrvCur->pConnector->pfnGetConfig(pDrvCur->pConnector, &Cfg);
     3861        if (RT_FAILURE(rc2))
     3862            continue;
     3863
     3864        dstSrc.Source = PDMAUDIORECSOURCE_MIC;
     3865        PAC97DRIVERSTREAM pDrvStrm = ichac97R3MixerGetDrvStream(pThis, pDrvCur, PDMAUDIODIR_IN, dstSrc);
     3866        if (   pDrvStrm
     3867            && pDrvStrm->pMixStrm)
     3868        {
     3869            rc2 = AudioMixerSinkSetRecordingSource(pThis->pSinkMicIn, pDrvStrm->pMixStrm);
     3870            if (RT_SUCCESS(rc2))
     3871                LogRel2(("AC97: Set recording source for 'Mic In' to '%s'\n", Cfg.szName));
     3872        }
     3873
     3874        dstSrc.Source = PDMAUDIORECSOURCE_LINE;
     3875        pDrvStrm = ichac97R3MixerGetDrvStream(pThis, pDrvCur, PDMAUDIODIR_IN, dstSrc);
     3876        if (   pDrvStrm
     3877            && pDrvStrm->pMixStrm)
     3878        {
     3879            rc2 = AudioMixerSinkSetRecordingSource(pThis->pSinkLineIn, pDrvStrm->pMixStrm);
     3880            if (RT_SUCCESS(rc2))
     3881                LogRel2(("AC97: Set recording source for 'Line In' to '%s'\n", Cfg.szName));
     3882        }
     3883    }
    37883884
    37893885    LogFunc(("uLUN=%u, fFlags=0x%x\n", pDrv->uLUN, fFlags));
     
    38053901    int rc2 = ichac97R3AttachInternal(pThis, uLUN, fFlags, &pDrv);
    38063902    if (RT_SUCCESS(rc2))
    3807     {
    3808         if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamLineIn.State.Cfg))
    3809             ichac97R3MixerAddDrvStream(pThis, pThis->pSinkLineIn, &pThis->StreamLineIn.State.Cfg, pDrv);
    3810 
    3811         if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamMicIn.State.Cfg))
    3812             ichac97R3MixerAddDrvStream(pThis, pThis->pSinkMicIn,  &pThis->StreamMicIn.State.Cfg, pDrv);
    3813 
    3814         if (DrvAudioHlpStreamCfgIsValid(&pThis->StreamOut.State.Cfg))
    3815             ichac97R3MixerAddDrvStream(pThis, pThis->pSinkOut,    &pThis->StreamOut.State.Cfg, pDrv);
    3816     }
     3903        rc2 = ichac97R3MixerAddDrv(pThis, pDrv);
     3904
     3905    if (RT_FAILURE(rc2))
     3906        LogFunc(("Failed with %Rrc\n", rc2));
    38173907
    38183908    DEVAC97_UNLOCK(pThis);
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