VirtualBox

Changeset 70905 in vbox for trunk/src


Ignore:
Timestamp:
Feb 8, 2018 10:30:58 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120733
Message:

Audio/DevHDA.cpp: Separate stream adding / removal in own functions and only add streams when actual starting transfers.

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

Legend:

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

    r70894 r70905  
    272272 */
    273273#ifdef IN_RING3
     274static int                        hdaAddStream(PHDASTATE pThis, PPDMAUDIOSTREAMCFG pCfg);
     275static int                        hdaRemoveStream(PHDASTATE pThis, PPDMAUDIOSTREAMCFG pCfg);
    274276# ifdef HDA_USE_DMA_ACCESS_HANDLER
    275277static DECLCALLBACK(VBOXSTRICTRC) hdaDMAAccessHandler(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser);
     
    14001402            hdaStreamLock(pStream);
    14011403
     1404            int rc2;
     1405
    14021406# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
     1407            if (fRun)
     1408                rc2 = hdaStreamAsyncIOCreate(pStream);
     1409
    14031410            hdaStreamAsyncIOLock(pStream);
    1404             hdaStreamAsyncIOEnable(pStream, fRun /* fEnable */);
    14051411# endif
    1406             /* (Re-)initialize the stream with current values. */
    1407             int rc2 = hdaStreamInit(pStream, pStream->u8SD);
    1408             AssertRC(rc2);
     1412            if (fRun)
     1413            {
     1414# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
     1415                hdaStreamAsyncIOEnable(pStream, fRun /* fEnable */);
     1416# endif
     1417                /* (Re-)initialize the stream with current values. */
     1418                rc2 = hdaStreamInit(pStream, pStream->u8SD);
     1419                AssertRC(rc2);
     1420
     1421                /* Remove the old stream from the device setup. */
     1422                hdaRemoveStream(pThis, &pStream->State.Cfg);
     1423
     1424                /* Add the stream to the device setup. */
     1425                rc2 = hdaAddStream(pThis, &pStream->State.Cfg);
     1426                AssertRC(rc2);
     1427            }
    14091428
    14101429            /* Enable/disable the stream. */
     
    18571876            pCfg->Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cBits, pCfg->Props.cChannels);
    18581877
    1859             rc = hdaCodecRemoveStream(pThis->pCodec,  PDMAUDIOMIXERCTL_FRONT);
    1860             if (RT_SUCCESS(rc))
    1861                 rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_FRONT, pCfg);
     1878            rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_FRONT, pCfg);
    18621879        }
    18631880
     
    18741891            pCfg->Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cBits, pCfg->Props.cChannels);
    18751892
    1876             rc = hdaCodecRemoveStream(pThis->pCodec,  PDMAUDIOMIXERCTL_CENTER_LFE);
    1877             if (RT_SUCCESS(rc))
    1878                 rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_CENTER_LFE, pCfg);
     1893            rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_CENTER_LFE, pCfg);
    18791894        }
    18801895
     
    18901905            pCfg->Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfg->Props.cBits, pCfg->Props.cChannels);
    18911906
    1892             rc = hdaCodecRemoveStream(pThis->pCodec,  PDMAUDIOMIXERCTL_REAR);
    1893             if (RT_SUCCESS(rc))
    1894                 rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_REAR, pCfg);
     1907            rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_REAR, pCfg);
    18951908        }
    18961909#endif /* VBOX_WITH_AUDIO_HDA_51_SURROUND */
     
    19241937        case PDMAUDIORECSOURCE_LINE:
    19251938        {
    1926             rc = hdaCodecRemoveStream(pThis->pCodec,  PDMAUDIOMIXERCTL_LINE_IN);
    1927             if (RT_SUCCESS(rc))
    1928                 rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_LINE_IN, pCfg);
     1939            rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_LINE_IN, pCfg);
    19291940            break;
    19301941        }
     
    19321943        case PDMAUDIORECSOURCE_MIC:
    19331944        {
    1934             rc = hdaCodecRemoveStream(pThis->pCodec,  PDMAUDIOMIXERCTL_MIC_IN);
    1935             if (RT_SUCCESS(rc))
    1936                 rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_MIC_IN, pCfg);
     1945            rc = hdaCodecAddStream(pThis->pCodec, PDMAUDIOMIXERCTL_MIC_IN, pCfg);
    19371946            break;
    19381947        }
     
    19811990    LogFlowFunc(("Returning %Rrc\n", rc));
    19821991
     1992    return rc;
     1993}
     1994
     1995/**
     1996 * Removes an audio stream from the device setup using the given configuration.
     1997 *
     1998 * @returns IPRT status code.
     1999 * @param   pThis               Device state.
     2000 * @param   pCfg                Stream configuration to use for removing a stream.
     2001 */
     2002static int hdaRemoveStream(PHDASTATE pThis, PPDMAUDIOSTREAMCFG pCfg)
     2003{
     2004    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     2005    AssertPtrReturn(pCfg,  VERR_INVALID_POINTER);
     2006
     2007    int rc = VINF_SUCCESS;
     2008
     2009    PDMAUDIOMIXERCTL enmMixerCtl = PDMAUDIOMIXERCTL_UNKNOWN;
     2010    switch (pCfg->enmDir)
     2011    {
     2012        case PDMAUDIODIR_IN:
     2013        {
     2014            LogFlowFunc(("Stream=%s, Source=%ld\n", pCfg->szName, pCfg->DestSource.Source));
     2015
     2016            switch (pCfg->DestSource.Source)
     2017            {
     2018                case PDMAUDIORECSOURCE_LINE: enmMixerCtl = PDMAUDIOMIXERCTL_LINE_IN; break;
     2019#ifdef VBOX_WITH_AUDIO_HDA_MIC_IN
     2020                case PDMAUDIORECSOURCE_MIC:  enmMixerCtl = PDMAUDIOMIXERCTL_MIC_IN;  break;
     2021#endif
     2022                default:
     2023                    rc = VERR_NOT_SUPPORTED;
     2024                    break;
     2025            }
     2026
     2027            break;
     2028        }
     2029
     2030        case PDMAUDIODIR_OUT:
     2031        {
     2032            LogFlowFunc(("Stream=%s, Source=%ld\n", pCfg->szName, pCfg->DestSource.Dest));
     2033
     2034            switch (pCfg->DestSource.Dest)
     2035            {
     2036                case PDMAUDIOPLAYBACKDEST_FRONT:      enmMixerCtl = PDMAUDIOMIXERCTL_FRONT;      break;
     2037#ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND
     2038                case PDMAUDIOPLAYBACKDEST_CENTER_LFE: enmMixerCtl = PDMAUDIOMIXERCTL_CENTER_LFE; break;
     2039                case PDMAUDIOPLAYBACKDEST_REAR:       enmMixerCtl = PDMAUDIOMIXERCTL_REAR;       break;
     2040#endif
     2041                default:
     2042                    rc = VERR_NOT_SUPPORTED;
     2043                    break;
     2044            }
     2045            break;
     2046        }
     2047
     2048        default:
     2049            rc = VERR_NOT_SUPPORTED;
     2050            break;
     2051    }
     2052
     2053    if (RT_SUCCESS(rc))
     2054        rc = hdaCodecRemoveStream(pThis->pCodec, enmMixerCtl);
     2055
     2056    LogFlowFuncLeaveRC(rc);
    19832057    return rc;
    19842058}
     
    20072081    int rc = hdaRegWriteU16(pThis, iReg, u32Value);
    20082082    AssertRC(rc);
    2009 
    2010     rc = hdaStreamInit(pStream, pStream->u8SD);
    2011     if (RT_SUCCESS(rc))
    2012     {
    2013         /* Add the stream to the device setup. */
    2014         rc = hdaAddStream(pThis, &pStream->State.Cfg);
    2015 # ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
    2016         if (RT_SUCCESS(rc))
    2017             rc = hdaStreamAsyncIOCreate(pStream);
    2018 # endif
    2019     }
    20202083
    20212084    DEVHDA_UNLOCK(pThis);
  • trunk/src/VBox/Devices/Audio/HDACodec.cpp

    r70249 r70905  
    32843284    pThis->paNodes[STAC9220_NID_AFG].afg.u32F20_param = CODEC_MAKE_F20(pThis->u16VendorId, pThis->u8BSKU, pThis->u8AssemblyId);
    32853285
    3286     do
    3287     {
    3288         /* Initialize the streams to some default values (44.1 kHz, 16-bit signed, 2 channels).
    3289          * The codec's (fixed) delivery rate is 48kHz, so a frame will be delivered every 20.83us. */
    3290         PDMAUDIOSTREAMCFG strmCfg;
    3291         RT_ZERO(strmCfg);
    3292 
    3293         /* Note: Adding the default input/output streams is *not* critical for the overall
    3294          *       codec construction result. */
    3295 
    3296         /*
    3297          * Output streams.
    3298          */
    3299         strmCfg.enmDir    = PDMAUDIODIR_OUT;
    3300         strmCfg.enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
    3301 
    3302         strmCfg.Props.cBits     = 16;
    3303         strmCfg.Props.fSigned   = true;
    3304         strmCfg.Props.cChannels = 2;
    3305         strmCfg.Props.uHz       = 44100;
    3306         strmCfg.Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(strmCfg.Props.cBits, strmCfg.Props.cChannels);
    3307 
    3308         /* Front. */
    3309         RTStrPrintf(strmCfg.szName, RT_ELEMENTS(strmCfg.szName), "Front");
    3310         strmCfg.DestSource.Dest = PDMAUDIOPLAYBACKDEST_FRONT;
    3311         int rc2 = hdaCodecAddStream(pThis, PDMAUDIOMIXERCTL_FRONT, &strmCfg);
    3312         if (RT_FAILURE(rc2))
    3313             LogRel2(("HDA: Failed to add front output stream: %Rrc\n", rc2));
    3314 
    3315 #ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND
    3316         /* Center / LFE. */
    3317         RTStrPrintf(strmCfg.szName, RT_ELEMENTS(strmCfg.szName), "Center / LFE");
    3318         strmCfg.DestSource.Dest = PDMAUDIOPLAYBACKDEST_CENTER_LFE;
    3319         /** @todo Handle mono channel if only center *or* LFE is available? */
    3320         rc2 = hdaCodecAddStream(pThis, PDMAUDIOMIXERCTL_CENTER_LFE, &strmCfg);
    3321         if (RT_FAILURE(rc2))
    3322             LogRel2(("HDA: Failed to add center/LFE output stream: %Rrc\n", rc2));
    3323 
    3324         /* Rear. */
    3325         RTStrPrintf(strmCfg.szName, RT_ELEMENTS(strmCfg.szName), "Rear");
    3326         strmCfg.DestSource.Dest = PDMAUDIOPLAYBACKDEST_REAR;
    3327         rc2 = hdaCodecAddStream(pThis, PDMAUDIOMIXERCTL_REAR, &strmCfg);
    3328         if (RT_FAILURE(rc2))
    3329             LogRel2(("HDA: Failed to add rear output stream: %Rrc\n", rc2));
    3330 #endif
    3331 
    3332         /*
    3333          * Input streams.
    3334          */
    3335         RT_ZERO(strmCfg);
    3336 
    3337         strmCfg.enmDir    = PDMAUDIODIR_IN;
    3338         strmCfg.enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED;
    3339 
    3340         strmCfg.Props.cBits     = 16;
    3341         strmCfg.Props.fSigned   = true;
    3342         strmCfg.Props.cChannels = 2;
    3343         strmCfg.Props.uHz       = 44100;
    3344         strmCfg.Props.cShift    = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(strmCfg.Props.cBits, strmCfg.Props.cChannels);
    3345 
    3346 #ifdef VBOX_WITH_AUDIO_HDA_MIC_IN
    3347         RTStrPrintf(strmCfg.szName, RT_ELEMENTS(strmCfg.szName), "Microphone In");
    3348         strmCfg.DestSource.Source = PDMAUDIORECSOURCE_MIC;
    3349         rc2 = hdaCodecAddStream(pThis, PDMAUDIOMIXERCTL_MIC_IN, &strmCfg);
    3350         if (RT_FAILURE(rc2))
    3351             LogRel2(("HDA: Failed to add microphone input stream: %Rrc\n", rc2));
    3352 #endif
    3353         RTStrPrintf(strmCfg.szName, RT_ELEMENTS(strmCfg.szName), "Line In");
    3354         strmCfg.DestSource.Source = PDMAUDIORECSOURCE_LINE;
    3355         rc2 = hdaCodecAddStream(pThis, PDMAUDIOMIXERCTL_LINE_IN, &strmCfg);
    3356         if (RT_FAILURE(rc2))
    3357             LogRel2(("HDA: Failed to add line input stream: %Rrc\n", rc2));
    3358 
    3359     } while (0);
    3360 
    33613286    /*
    33623287     * Set initial volume.
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