VirtualBox

Changeset 88210 in vbox for trunk


Ignore:
Timestamp:
Mar 19, 2021 5:47:14 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143375
Message:

DrvHostAudioAlsa: Added 'DefaultOutput' and 'DefaultInput' config options so it's possible to select which device to play/record on. bugref:9890

File:
1 edited

Legend:

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

    r88028 r88210  
    103103{
    104104    /** Pointer to the driver instance structure. */
    105     PPDMDRVINS         pDrvIns;
     105    PPDMDRVINS          pDrvIns;
    106106    /** Pointer to host audio interface. */
    107     PDMIHOSTAUDIO      IHostAudio;
     107    PDMIHOSTAUDIO       IHostAudio;
    108108    /** Error count for not flooding the release log.
    109109     *  UINT32_MAX for unlimited logging. */
    110     uint32_t           cLogErrors;
     110    uint32_t            cLogErrors;
     111    /** Default input device name.   */
     112    char                szDefaultIn[256];
     113    /** Default output device name. */
     114    char                szDefaultOut[256];
    111115} DRVHOSTALSAAUDIO, *PDRVHOSTALSAAUDIO;
    112116
     
    362366 *
    363367 * @returns VBox status code.
    364  * @param   fIn                 Whether this is an input stream to create or not.
    365  * @param   pCfgReq             Requested configuration to create stream with.
    366  * @param   pCfgObt             Obtained configuration the stream got created on success.
    367  * @param   pphPCM              Where to store the ALSA stream handle on success.
    368  */
    369 static int alsaStreamOpen(bool fIn, PALSAAUDIOSTREAMCFG pCfgReq, PALSAAUDIOSTREAMCFG pCfgObt, snd_pcm_t **pphPCM)
     368 * @param   pszDev  The name of the device to open.
     369 * @param   fIn     Whether this is an input stream to create or not.
     370 * @param   pCfgReq Requested configuration to create stream with.
     371 * @param   pCfgObt Obtained configuration the stream got created on success.
     372 * @param   pphPCM  Where to store the ALSA stream handle on success.
     373 */
     374static int alsaStreamOpen(const char *pszDev, bool fIn, PALSAAUDIOSTREAMCFG pCfgReq,
     375                          PALSAAUDIOSTREAMCFG pCfgObt,  snd_pcm_t **pphPCM)
    370376{
    371377    snd_pcm_t *phPCM = NULL;
     
    379385    do
    380386    {
    381         const char *pszDev = "default"; /** @todo Make this configurable through PALSAAUDIOSTREAMCFG. */
    382         if (!pszDev)
    383         {
    384             LogRel(("ALSA: Invalid or no %s device name set\n", fIn ? "input" : "output"));
    385             rc = VERR_INVALID_PARAMETER;
    386             break;
    387         }
     387        AssertLogRelMsgReturn(pszDev && *pszDev,
     388                              ("ALSA: Invalid or no %s device name set\n", fIn ? "input" : "output"),
     389                              VERR_INVALID_NAME);
    388390
    389391        LogRel(("ALSA: Using %s device \"%s\"\n", fIn ? "input" : "output", pszDev));
     
    964966 *
    965967 * @returns VBox status code.
    966  * @param   pStreamALSA         ALSA output stream to create.
    967  * @param   pCfgReq             Requested configuration to create stream with.
    968  * @param   pCfgAcq             Obtained configuration the stream got created with on success.
    969  */
    970 static int alsaCreateStreamOut(PALSAAUDIOSTREAM pStreamALSA, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     968 * @param   pThis       The ALSA driver instance data.
     969 * @param   pStreamALSA ALSA output stream to create.
     970 * @param   pCfgReq     Requested configuration to create stream with.
     971 * @param   pCfgAcq     Obtained configuration the stream got created
     972 *                      with on success.
     973 */
     974static int alsaCreateStreamOut(PDRVHOSTALSAAUDIO pThis, PALSAAUDIOSTREAM pStreamALSA,
     975                               PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    971976{
    972977    snd_pcm_t *phPCM = NULL;
     
    985990
    986991        ALSAAUDIOSTREAMCFG obt;
    987         rc = alsaStreamOpen(false /* fIn */, &req, &obt, &phPCM);
     992        rc = alsaStreamOpen(pThis->szDefaultOut, false /* fIn */, &req, &obt, &phPCM);
    988993        if (RT_FAILURE(rc))
    989994            break;
     
    10241029 *
    10251030 * @returns VBox status code.
    1026  * @param   pStreamALSA         ALSA input stream to create.
    1027  * @param   pCfgReq             Requested configuration to create stream with.
    1028  * @param   pCfgAcq             Obtained configuration the stream got created with on success.
    1029  */
    1030 static int alsaCreateStreamIn(PALSAAUDIOSTREAM pStreamALSA, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
     1031 * @param   pThis       The ALSA driver instance data.
     1032 * @param   pStreamALSA ALSA input stream to create.
     1033 * @param   pCfgReq     Requested configuration to create stream with.
     1034 * @param   pCfgAcq     Obtained configuration the stream got created
     1035 *                      with on success.
     1036 */
     1037static int alsaCreateStreamIn(PDRVHOSTALSAAUDIO pThis, PALSAAUDIOSTREAM pStreamALSA,
     1038                              PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    10311039{
    10321040    int rc;
     
    10451053
    10461054        ALSAAUDIOSTREAMCFG obt;
    1047         rc = alsaStreamOpen(true /* fIn */, &req, &obt, &phPCM);
     1055        rc = alsaStreamOpen(pThis->szDefaultIn, true /* fIn */, &req, &obt, &phPCM);
    10481056        if (RT_FAILURE(rc))
    10491057            break;
     
    13511359                                                         PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    13521360{
     1361    PDRVHOSTALSAAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVHOSTALSAAUDIO, IHostAudio);
    13531362    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    13541363    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     
    13601369    int rc;
    13611370    if (pCfgReq->enmDir == PDMAUDIODIR_IN)
    1362         rc = alsaCreateStreamIn( pStreamALSA, pCfgReq, pCfgAcq);
     1371        rc = alsaCreateStreamIn( pThis, pStreamALSA, pCfgReq, pCfgAcq);
    13631372    else
    1364         rc = alsaCreateStreamOut(pStreamALSA, pCfgReq, pCfgAcq);
     1373        rc = alsaCreateStreamOut(pThis, pStreamALSA, pCfgReq, pCfgAcq);
    13651374
    13661375    if (RT_SUCCESS(rc))
     
    15861595    pThis->IHostAudio.pfnStreamCaptureEnd   = NULL;
    15871596
     1597    /*
     1598     * Read configuration.
     1599     */
     1600    int rc = CFGMR3QueryStringDef(pCfg, "DefaultInput", pThis->szDefaultIn, sizeof(pThis->szDefaultIn), "default");
     1601    AssertRCReturn(rc, rc);
     1602    rc = CFGMR3QueryStringDef(pCfg, "DefaultOutput", pThis->szDefaultOut, sizeof(pThis->szDefaultOut), "default");
     1603    AssertRCReturn(rc, rc);
    15881604
    15891605    return VINF_SUCCESS;
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