VirtualBox

Changeset 87179 in vbox


Ignore:
Timestamp:
Jan 5, 2021 3:58:39 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142109
Message:

Audio: Added input / output stream PCM properties to CFGM driver chain to that those also can be set / tweaked for the backend side (Hz, bit, channels, ++). All optional, via extra data only so far.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

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

    r87174 r87179  
    23112311 * @return VBox status code.
    23122312 * @param  pThis                Driver instance to be called.
     2313 * @param  pNode                Where to get the audio configuration from.
     2314 * @param  enmDir               Type of audio configuration to retrieve (input / output).
    23132315 * @param  pCfg                 Where to store the retrieved audio configuration to.
    2314  * @param  pNode                Where to get the audio configuration from.
    2315  */
    2316 static int drvAudioGetCfgFromCFGM(PDRVAUDIO pThis, PDRVAUDIOCFG pCfg, PCFGMNODE pNode)
    2317 {
    2318     RT_NOREF(pThis);
     2316 */
     2317static int drvAudioGetCfgFromCFGM(PDRVAUDIO pThis, PCFGMNODE pNode, PDMAUDIODIR enmDir, PDRVAUDIOCFG pCfg)
     2318{
     2319    RT_NOREF(pThis, enmDir);
    23192320
    23202321    /* Debug stuff. */
     
    23302331        LogRel(("Audio: Debugging for driver '%s' enabled (audio data written to '%s')\n", pThis->szName, pCfg->Dbg.szPathOut));
    23312332
    2332     /* Buffering stuff. */
    2333     CFGMR3QueryU32Def(pNode, "PeriodSizeMs",    &pCfg->uPeriodSizeMs, 0);
    2334     CFGMR3QueryU32Def(pNode, "BufferSizeMs",    &pCfg->uBufferSizeMs, 0);
    2335     CFGMR3QueryU32Def(pNode, "PreBufferSizeMs", &pCfg->uPreBufSizeMs, UINT32_MAX /* No custom value set */);
    2336 
    2337     LogFunc(("pCfg=%p, uPeriodSizeMs=%RU32, uBufferSizeMs=%RU32, uPreBufSizeMs=%RU32\n",
    2338              pCfg, pCfg->uPeriodSizeMs, pCfg->uBufferSizeMs, pCfg->uPreBufSizeMs));
     2333    /* Queries an audio input / output stream's configuration from the CFGM tree. */
     2334#define QUERY_CONFIG(a_InOut) \
     2335    /* PCM stuff. */ \
     2336    CFGMR3QueryU8Def (pNode, "PCMSampleBit"         #a_InOut, &pCfg->Props.cbSample,  0); \
     2337    CFGMR3QueryU32Def(pNode, "PCMSampleHz"          #a_InOut, &pCfg->Props.uHz,       0); \
     2338    CFGMR3QueryU8Def (pNode, "PCMSampleSigned"      #a_InOut, &pCfg->uSigned,         UINT8_MAX /* No custom value set */); \
     2339    CFGMR3QueryU8Def (pNode, "PCMSampleSwapEndian"  #a_InOut, &pCfg->uSwapEndian,     UINT8_MAX /* No custom value set */); \
     2340    CFGMR3QueryU8Def (pNode, "PCMSampleChannels"    #a_InOut, &pCfg->Props.cChannels, 0); \
     2341    \
     2342    /* Buffering stuff. */ \
     2343    CFGMR3QueryU32Def(pNode, "PeriodSizeMs"         #a_InOut, &pCfg->uPeriodSizeMs, 0); \
     2344    CFGMR3QueryU32Def(pNode, "BufferSizeMs"         #a_InOut, &pCfg->uBufferSizeMs, 0); \
     2345    CFGMR3QueryU32Def(pNode, "PreBufferSizeMs"      #a_InOut, &pCfg->uPreBufSizeMs, UINT32_MAX /* No custom value set */);
     2346
     2347    if (enmDir == PDMAUDIODIR_IN)
     2348    {
     2349        QUERY_CONFIG(In);
     2350    }
     2351    else
     2352    {
     2353        QUERY_CONFIG(Out);
     2354    }
     2355
     2356#undef QUERY_CONFIG
     2357
     2358    pCfg->Props.cbSample /= 8; /* Convert bit to bytes. */
    23392359
    23402360    return VINF_SUCCESS;
     
    23842404     * Load configurations.
    23852405     */
    2386     rc = drvAudioGetCfgFromCFGM(pThis, &pThis->In.Cfg, pThis->pCFGMNode);
     2406    rc = drvAudioGetCfgFromCFGM(pThis, pThis->pCFGMNode, PDMAUDIODIR_IN, &pThis->In.Cfg);
    23872407    if (RT_SUCCESS(rc))
    2388         rc = drvAudioGetCfgFromCFGM(pThis, &pThis->Out.Cfg, pThis->pCFGMNode);
     2408        rc = drvAudioGetCfgFromCFGM(pThis, pThis->pCFGMNode, PDMAUDIODIR_OUT, &pThis->Out.Cfg);
    23892409
    23902410    LogFunc(("[%s] rc=%Rrc\n", pThis->szName, rc));
     
    31223142
    31233143    /*
     3144     * PCM
     3145     */
     3146    if (pDrvCfg->Props.cbSample) /* Anything set via custom extra-data? */
     3147    {
     3148        pCfgReq->Props.cbSample = pDrvCfg->Props.cbSample;
     3149        LogRel2(("Audio: Using custom sample size of %RU8 bytes for stream '%s'\n", pCfgReq->Props.cbSample, pStream->szName));
     3150    }
     3151
     3152    if (pDrvCfg->Props.uHz) /* Anything set via custom extra-data? */
     3153    {
     3154        pCfgReq->Props.uHz = pDrvCfg->Props.uHz;
     3155        LogRel2(("Audio: Using custom Hz rate %RU32 for stream '%s'\n", pCfgReq->Props.uHz, pStream->szName));
     3156    }
     3157
     3158    if (pDrvCfg->uSigned != UINT8_MAX) /* Anything set via custom extra-data? */
     3159    {
     3160        pCfgReq->Props.fSigned = RT_BOOL(pDrvCfg->uSigned);
     3161        LogRel2(("Audio: Using custom %s sample format for stream '%s'\n",
     3162                 pCfgReq->Props.fSigned ? "signed" : "unsigned", pStream->szName));
     3163    }
     3164
     3165    if (pDrvCfg->uSwapEndian != UINT8_MAX) /* Anything set via custom extra-data? */
     3166    {
     3167        pCfgReq->Props.fSwapEndian = RT_BOOL(pDrvCfg->uSwapEndian);
     3168        LogRel2(("Audio: Using custom %s endianess for samples of stream '%s'\n",
     3169                 pCfgReq->Props.fSwapEndian ? "swapped" : "original", pStream->szName));
     3170    }
     3171
     3172    if (pDrvCfg->Props.cChannels) /* Anything set via custom extra-data? */
     3173    {
     3174        pCfgReq->Props.cChannels = pDrvCfg->Props.cChannels;
     3175        LogRel2(("Audio: Using custom %RU8 channel(s) for stream '%s'\n", pCfgReq->Props.cChannels, pStream->szName));
     3176    }
     3177
     3178    /* Make sure to (re-)set the host buffer's shift size. */
     3179    pCfgReq->Props.cShift = PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(pCfgReq->Props.cbSample, pCfgReq->Props.cChannels);
     3180
     3181    /* Validate PCM properties. */
     3182    if (!DrvAudioHlpPCMPropsAreValid(&pCfgReq->Props))
     3183    {
     3184        LogRel(("Audio: Invalid custom PCM properties set for stream '%s', cannot create stream\n", pStream->szName));
     3185        return VERR_INVALID_PARAMETER;
     3186    }
     3187
     3188    /*
    31243189     * Period size
    31253190     */
     
    31273192    {
    31283193        pCfgReq->Backend.cFramesPeriod = DrvAudioHlpMilliToFrames(pDrvCfg->uPeriodSizeMs, &pCfgReq->Props);
    3129         RTStrPrintf(szWhat, sizeof(szWhat), "global / per-VM");
     3194        RTStrPrintf(szWhat, sizeof(szWhat), "custom");
    31303195    }
    31313196
     
    31463211    {
    31473212        pCfgReq->Backend.cFramesBufferSize = DrvAudioHlpMilliToFrames(pDrvCfg->uBufferSizeMs, &pCfgReq->Props);
    3148         RTStrPrintf(szWhat, sizeof(szWhat), "global / per-VM");
     3213        RTStrPrintf(szWhat, sizeof(szWhat), "custom");
    31493214    }
    31503215
     
    31653230    {
    31663231        pCfgReq->Backend.cFramesPreBuffering = DrvAudioHlpMilliToFrames(pDrvCfg->uPreBufSizeMs, &pCfgReq->Props);
    3167         RTStrPrintf(szWhat, sizeof(szWhat), "global / per-VM");
     3232        RTStrPrintf(szWhat, sizeof(szWhat), "custom");
    31683233    }
    31693234    else /* No, then either use the default or device-specific settings (if any). */
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r82968 r87179  
    8282typedef struct DRVAUDIOCFG
    8383{
     84    /** PCM properties to use. */
     85    PDMAUDIOPCMPROPS     Props;
     86    /** Whether using signed sample data or not.
     87     *  Needed in order to know whether there is a custom value set in CFGM or not.
     88     *  By default set to UINT8_MAX if not set to a custom value. */
     89    uint8_t              uSigned;
     90    /** Whether swapping endianess of sample data or not.
     91     *  Needed in order to know whether there is a custom value set in CFGM or not.
     92     *  By default set to UINT8_MAX if not set to a custom value. */
     93    uint8_t              uSwapEndian;
    8494    /** Configures the period size (in ms).
    8595     *  This value reflects the time in between each hardware interrupt on the
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r86506 r87179  
    35623562        }
    35633563
    3564         InsertConfigInteger(pCfg, "PeriodSizeMs",
    3565                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PeriodSizeMs", 0 /* Default */));
    3566         InsertConfigInteger(pCfg, "BufferSizeMs",
    3567                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "BufferSizeMs", 0 /* Default */));
    3568         InsertConfigInteger(pCfg, "PreBufferSizeMs",
    3569                             i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PreBufferSizeMs", UINT32_MAX /* Default */));
     3564
     3565        /*
     3566         * PCM input parameters (playback + recording).
     3567         */
     3568
     3569        /* Inserts an audio input / output stream's configuration into the CFGM tree. */
     3570#define AUDIO_INSERT_DRV_STREAM_CONFIG(a_InOut) \
     3571        /* \
     3572         * PCM output parameters (playback). \
     3573         */ \
     3574        InsertConfigInteger(pCfg, "PCMSampleBit"        #a_InOut, \
     3575                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleBit"        #a_InOut, 0 /* Default */)); \
     3576        InsertConfigInteger(pCfg, "PCMSampleHz"         #a_InOut, \
     3577                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleHz"         #a_InOut, 0 /* Default */)); \
     3578        InsertConfigInteger(pCfg, "PCMSampleSigned"     #a_InOut, \
     3579                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleSigned"     #a_InOut, UINT8_MAX /* Default */)); \
     3580        InsertConfigInteger(pCfg, "PCMSampleSwapEndian" #a_InOut, \
     3581                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleSwapEndian" #a_InOut, UINT8_MAX /* Default */)); \
     3582        InsertConfigInteger(pCfg, "PCMSampleChannels"   #a_InOut, \
     3583                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PCMSampleChannels"   #a_InOut, 0 /* Default */)); \
     3584        \
     3585        /* \
     3586         * Buffering stuff. \
     3587         */ \
     3588        \
     3589        InsertConfigInteger(pCfg, "PeriodSizeMs"        #a_InOut, \
     3590                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PeriodSizeMs"        #a_InOut, 0 /* Default */)); \
     3591        InsertConfigInteger(pCfg, "BufferSizeMs"        #a_InOut, \
     3592                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "BufferSizeMs"        #a_InOut, 0 /* Default */)); \
     3593        InsertConfigInteger(pCfg, "PreBufferSizeMs"     #a_InOut, \
     3594                            i_getAudioDriverValU32(pVirtualBox, pMachine, pszDrvName, "PreBufferSizeMs"     #a_InOut, UINT32_MAX /* Default */));
     3595
     3596        AUDIO_INSERT_DRV_STREAM_CONFIG(In);
     3597        AUDIO_INSERT_DRV_STREAM_CONFIG(Out);
     3598
     3599#undef AUDIO_INSERT_DRV_STREAM_CONFIG
    35703600
    35713601    PCFGMNODE pLunL1;
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