VirtualBox

Changeset 88209 in vbox for trunk/src/VBox/Main/src-client


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

Main/ConsoleImpl2: Cleaned up i_configAudioDriver(). bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r88091 r88209  
    31483148            }
    31493149
    3150             unsigned uAudioLUN = 0;
    3151 
    3152             InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", uAudioLUN);
    3153             rc = i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, pszAudioDriver);
    3154             if (RT_SUCCESS(rc))
    3155                 uAudioLUN++;
     3150            unsigned idxAudioLun = 0;
     3151
     3152            InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", idxAudioLun);
     3153            i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, pszAudioDriver);
     3154            idxAudioLun++;
    31563155
    31573156#ifdef VBOX_WITH_AUDIO_VRDE
    31583157            /* Insert dummy audio driver to have the LUN configured. */
    3159             InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", uAudioLUN);
     3158            InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", idxAudioLun);
    31603159            InsertConfigString(pLunL0, "Driver", "AUDIO");
    3161             AudioDriverCfg DrvCfgVRDE(pszAudioDevice, 0 /* Instance */, uAudioLUN, "AudioVRDE");
     3160            AudioDriverCfg DrvCfgVRDE(pszAudioDevice, 0 /* Instance */, idxAudioLun, "AudioVRDE");
    31623161            rc = mAudioVRDE->InitializeConfig(&DrvCfgVRDE);
    3163             if (RT_SUCCESS(rc))
    3164                 uAudioLUN++;
     3162            AssertRCStmt(rc, throw ConfigError(__FUNCTION__, rc, "mAudioVRDE->InitializeConfig failed"));
     3163            idxAudioLun++;
    31653164#endif /* VBOX_WITH_AUDIO_VRDE */
    31663165
    31673166#ifdef VBOX_WITH_AUDIO_RECORDING
    31683167            /* Insert dummy audio driver to have the LUN configured. */
    3169             InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", uAudioLUN);
     3168            InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", idxAudioLun);
    31703169            InsertConfigString(pLunL0, "Driver", "AUDIO");
    3171             AudioDriverCfg DrvCfgVideoRec(pszAudioDevice, 0 /* Instance */, uAudioLUN, "AudioVideoRec");
     3170            AudioDriverCfg DrvCfgVideoRec(pszAudioDevice, 0 /* Instance */, idxAudioLun, "AudioVideoRec");
    31723171            rc = Recording.mAudioRec->InitializeConfig(&DrvCfgVideoRec);
    3173             if (RT_SUCCESS(rc))
    3174                 uAudioLUN++;
     3172            AssertRCStmt(rc, throw ConfigError(__FUNCTION__, rc, "Recording.mAudioRec->InitializeConfig failed"));
     3173            idxAudioLun++;
    31753174#endif /* VBOX_WITH_AUDIO_RECORDING */
    31763175
     
    31783177            {
    31793178#ifdef VBOX_WITH_AUDIO_DEBUG
    3180                 InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", uAudioLUN);
    3181                 rc = i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, "DebugAudio");
    3182                 if (RT_SUCCESS(rc))
    3183                     uAudioLUN++;
     3179                InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", idxAudioLun);
     3180                i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, "DebugAudio");
     3181                idxAudioLun++;
    31843182#endif /* VBOX_WITH_AUDIO_DEBUG */
    31853183
     
    32053203             * The ValidationKit backend.
    32063204             */
    3207             InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", uAudioLUN);
    3208             rc = i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, "ValidationKitAudio");
    3209             if (RT_SUCCESS(rc))
    3210                 uAudioLUN++;
     3205            InsertConfigNodeF(pInst, &pLunL0, "LUN#%u", idxAudioLun);
     3206            i_configAudioDriver(audioAdapter, virtualBox, pMachine, pLunL0, "ValidationKitAudio");
     3207            idxAudioLun++;
    32113208#endif /* VBOX_WITH_AUDIO_VALIDATIONKIT */
    32123209        }
     
    35833580
    35843581/**
    3585  * Retrieves an uint32_t value from the audio driver's extra data branch
    3586  * (VBoxInternal2/Audio/DriverName/Value), or, if not found, use global branch
    3587  * (VBoxInternal2/Audio/Value).
    3588  *
    3589  * The driver branch always supersedes the global branch.
    3590  * If both branches are not found (empty), return the given default value.
    3591  *
    3592  * @return VBox status code.
    3593  * @param  pVirtualBox          Pointer to IVirtualBox instance.
    3594  * @param  pMachine             Pointer to IMachine instance.
    3595  * @param  pszDriverName        Audio driver name to retrieve value for.
    3596  * @param  pszValue             Value name to retrieve.
    3597  * @param  uDefault             Default value to return if value not found / invalid.
    3598  */
    3599 uint32_t Console::i_getAudioDriverValU32(IVirtualBox *pVirtualBox, IMachine *pMachine,
    3600                                          const char *pszDriverName, const char *pszValue, uint32_t uDefault)
    3601 {
    3602     Utf8Str strTmp;
    3603 
    3604     Utf8StrFmt strPathDrv("VBoxInternal2/Audio/%s/%s", pszDriverName, pszValue);
    3605     GetExtraDataBoth(pVirtualBox, pMachine, strPathDrv.c_str(), &strTmp);
    3606     if (strTmp.isEmpty())
    3607     {
    3608         Utf8StrFmt strPathGlobal("VBoxInternal2/Audio/%s", pszValue);
    3609         GetExtraDataBoth(pVirtualBox, pMachine, strPathGlobal.c_str(), &strTmp);
    3610         if (strTmp.isNotEmpty())
    3611             return strTmp.toUInt32();
    3612     }
    3613     else /* Return driver-specific value. */
    3614         return strTmp.toUInt32();
    3615 
    3616     return uDefault;
    3617 }
    3618 
    3619 /**
    36203582 * Configures an audio driver via CFGM by getting (optional) values from extra data.
    36213583 *
    3622  * @return VBox status code.
    36233584 * @param  pAudioAdapter        Pointer to audio adapter instance. Needed for the driver's input / output configuration.
    36243585 * @param  pVirtualBox          Pointer to IVirtualBox instance.
     
    36263587 * @param  pLUN                 Pointer to CFGM node of LUN (the driver) to configure.
    36273588 * @param  pszDrvName           Name of the driver to configure.
     3589 *
     3590 * @throws ConfigError or HRESULT on if there is trouble.
    36283591 */
    3629 int Console::i_configAudioDriver(IAudioAdapter *pAudioAdapter, IVirtualBox *pVirtualBox, IMachine *pMachine,
    3630                                  PCFGMNODE pLUN, const char *pszDrvName)
     3592void Console::i_configAudioDriver(IAudioAdapter *pAudioAdapter, IVirtualBox *pVirtualBox, IMachine *pMachine,
     3593                                  PCFGMNODE pLUN, const char *pszDrvName)
    36313594{
    3632 #define H()         AssertLogRelMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR)
     3595#define H()     AssertLogRelMsgStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), \
     3596                                    throw ConfigError(__FUNCTION__, VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR, "line: " RT_XSTR(__LINE__)))
    36333597
    36343598    HRESULT hrc;
     
    36363600    Utf8Str strTmp;
    36373601    GetExtraDataBoth(pVirtualBox, pMachine, "VBoxInternal2/Audio/Debug/Enabled", &strTmp);
    3638     const uint64_t fDebugEnabled = (strTmp.equalsIgnoreCase("true") || strTmp.equalsIgnoreCase("1")) ? 1 : 0;
     3602    const uint64_t fDebugEnabled = strTmp.equalsIgnoreCase("true") || strTmp.equalsIgnoreCase("1");
    36393603
    36403604    BOOL fAudioEnabledIn = FALSE;
    3641     hrc = pAudioAdapter->COMGETTER(EnabledIn)(&fAudioEnabledIn);                             H();
     3605    hrc = pAudioAdapter->COMGETTER(EnabledIn)(&fAudioEnabledIn);                            H();
    36423606    BOOL fAudioEnabledOut = FALSE;
    3643     hrc = pAudioAdapter->COMGETTER(EnabledOut)(&fAudioEnabledOut);
     3607    hrc = pAudioAdapter->COMGETTER(EnabledOut)(&fAudioEnabledOut);                          H();
    36443608
    36453609    InsertConfigString(pLUN, "Driver", "AUDIO");
     
    36473611    PCFGMNODE pCfg;
    36483612    InsertConfigNode(pLUN,   "Config", &pCfg);
    3649         InsertConfigString (pCfg, "DriverName",    pszDrvName);
    3650         InsertConfigInteger(pCfg, "InputEnabled",  fAudioEnabledIn);
    3651         InsertConfigInteger(pCfg, "OutputEnabled", fAudioEnabledOut);
    3652 
    3653         if (fDebugEnabled)
    3654         {
    3655             InsertConfigInteger(pCfg, "DebugEnabled",  fDebugEnabled);
    3656 
    3657             Utf8Str strDebugPathOut;
    3658             GetExtraDataBoth(pVirtualBox, pMachine, "VBoxInternal2/Audio/Debug/PathOut", &strDebugPathOut);
    3659             InsertConfigString(pCfg, "DebugPathOut",  strDebugPathOut.c_str());
    3660         }
    3661 
    3662 
    3663         /*
    3664          * PCM input parameters (playback + recording).
    3665          */
    3666 
    3667         /* Inserts an audio input / output stream's configuration into the CFGM tree. */
    3668 #define AUDIO_INSERT_DRV_STREAM_CONFIG(a_InOut) \
    3669         /* \
    3670          * PCM output parameters (playback). \
    3671          */ \
    3672         InsertConfigInteger(pCfg, "PCMSampleBit"        #a_InOut, \
    3673                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleBit"        #a_InOut, 0 /* Default */)); \
    3674         InsertConfigInteger(pCfg, "PCMSampleHz"         #a_InOut, \
    3675                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleHz"         #a_InOut, 0 /* Default */)); \
    3676         InsertConfigInteger(pCfg, "PCMSampleSigned"     #a_InOut, \
    3677                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleSigned"     #a_InOut, UINT8_MAX /* Default */)); \
    3678         InsertConfigInteger(pCfg, "PCMSampleSwapEndian" #a_InOut, \
    3679                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleSwapEndian" #a_InOut, UINT8_MAX /* Default */)); \
    3680         InsertConfigInteger(pCfg, "PCMSampleChannels"   #a_InOut, \
    3681                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleChannels"   #a_InOut, 0 /* Default */)); \
    3682         \
    3683         /* \
    3684          * Buffering stuff. \
    3685          */ \
    3686         \
    3687         InsertConfigInteger(pCfg, "PeriodSizeMs"        #a_InOut, \
    3688                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PeriodSizeMs"        #a_InOut, 0 /* Default */)); \
    3689         InsertConfigInteger(pCfg, "BufferSizeMs"        #a_InOut, \
    3690                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "BufferSizeMs"        #a_InOut, 0 /* Default */)); \
    3691         InsertConfigInteger(pCfg, "PreBufferSizeMs"     #a_InOut, \
    3692                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PreBufferSizeMs"     #a_InOut, UINT32_MAX /* Default */));
    3693 
    3694         AUDIO_INSERT_DRV_STREAM_CONFIG(In);
    3695         AUDIO_INSERT_DRV_STREAM_CONFIG(Out);
    3696 
    3697 #undef AUDIO_INSERT_DRV_STREAM_CONFIG
     3613    InsertConfigString(pCfg,  "DriverName",    pszDrvName);
     3614    InsertConfigInteger(pCfg, "InputEnabled",  fAudioEnabledIn);
     3615    InsertConfigInteger(pCfg, "OutputEnabled", fAudioEnabledOut);
     3616
     3617    if (fDebugEnabled)
     3618    {
     3619        InsertConfigInteger(pCfg, "DebugEnabled",  fDebugEnabled);
     3620
     3621        Utf8Str strDebugPathOut;
     3622        GetExtraDataBoth(pVirtualBox, pMachine, "VBoxInternal2/Audio/Debug/PathOut", &strDebugPathOut);
     3623        InsertConfigString(pCfg, "DebugPathOut",  strDebugPathOut.c_str());
     3624    }
     3625
     3626    /*
     3627     * PCM input parameters (playback + recording).
     3628     * We have host driver specific ones as: VBoxInternal2/Audio/<DrvName>/<Value>
     3629     * And global ones for all host drivers: VBoxInternal2/Audio/<Value>
     3630     */
     3631    static const struct
     3632    {
     3633        const char *pszExtraName;
     3634        const char *pszCfgmName;
     3635        uint32_t    uDefault;
     3636    } s_aToCopy[]
     3637    {
     3638#define AUDIO_DRV_TO_COPY_ENTRIES(a_szDir) \
     3639            /* PCM  parameters: */ \
     3640            { "PCMSampleBit"        a_szDir, "PCMSampleBit"        a_szDir, 0          }, \
     3641            { "PCMSampleHz"         a_szDir, "PCMSampleHz"         a_szDir, 0          }, \
     3642            { "PCMSampleSigned"     a_szDir, "PCMSampleSigned"     a_szDir, UINT8_MAX  }, \
     3643            { "PCMSampleSwapEndian" a_szDir, "PCMSampleSwapEndian" a_szDir, UINT8_MAX  }, \
     3644            { "PCMSampleChannels"   a_szDir, "PCMSampleChannels"   a_szDir, 0          }, \
     3645            /* Buffering stuff: */ \
     3646            { "PeriodSizeMs"        a_szDir, "PeriodSizeMs"        a_szDir, 0          }, \
     3647            { "BufferSizeMs"        a_szDir, "BufferSizeMs"        a_szDir, 0          }, \
     3648            { "PreBufferSizeMs"     a_szDir, "PreBufferSizeMs"     a_szDir, UINT32_MAX }
     3649        AUDIO_DRV_TO_COPY_ENTRIES("In"),
     3650        AUDIO_DRV_TO_COPY_ENTRIES("Out")
     3651#undef AUDIO_DRV_TO_COPY_ENTRIES
     3652    };
     3653    for (size_t i = 0; i < RT_ELEMENTS(s_aToCopy); i++)
     3654    {
     3655        char szExtra[128];
     3656        RTStrPrintf(szExtra, sizeof(szExtra), "VBoxInternal2/Audio/%s/%s", pszDrvName, s_aToCopy[i].pszExtraName);
     3657        GetExtraDataBoth(pVirtualBox, pMachine, szExtra, &strTmp); /* throws hrc */
     3658        if (strTmp.isEmpty())
     3659        {
     3660            RTStrPrintf(szExtra, sizeof(szExtra), "VBoxInternal2/Audio/%s", s_aToCopy[i].pszExtraName);
     3661            GetExtraDataBoth(pVirtualBox, pMachine, szExtra, &strTmp);
     3662            if (strTmp.isEmpty())
     3663                continue;
     3664        }
     3665
     3666        uint32_t uValue;
     3667        int vrc = RTStrToUInt32Full(strTmp.c_str(), 0, &uValue);
     3668        if (RT_SUCCESS(vrc))
     3669            InsertConfigInteger(pCfg, s_aToCopy[i].pszCfgmName, uValue);
     3670        else
     3671            LogRel(("Ignoring malformed 32-bit unsigned integer config value '%s' = '%s': %Rrc\n", szExtra, strTmp.c_str(), vrc));
     3672    }
    36983673
    36993674    PCFGMNODE pLunL1;
    37003675    InsertConfigNode(pLUN, "AttachedDriver", &pLunL1);
    3701 
    3702         InsertConfigNode(pLunL1, "Config", &pCfg);
    3703 
    3704             Bstr bstrTmp;
    3705             hrc = pMachine->COMGETTER(Name)(bstrTmp.asOutParam());                           H();
    3706             InsertConfigString(pCfg, "StreamName", bstrTmp);
    3707 
    3708         InsertConfigString(pLunL1, "Driver", pszDrvName);
    3709 
    3710     LogFlowFunc(("szDrivName=%s, hrc=%Rhrc\n", pszDrvName, hrc));
    3711     return hrc;
     3676    InsertConfigNode(pLunL1, "Config", &pCfg);
     3677    Bstr bstrTmp;
     3678    hrc = pMachine->COMGETTER(Name)(bstrTmp.asOutParam());                                  H();
     3679    InsertConfigString(pCfg, "StreamName", bstrTmp);
     3680    InsertConfigString(pLunL1, "Driver", pszDrvName);
     3681
     3682    LogFlowFunc(("szDrivName=%s\n", pszDrvName));
    37123683
    37133684#undef H
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