VirtualBox

Changeset 88960 in vbox for trunk


Ignore:
Timestamp:
May 10, 2021 11:28:35 AM (4 years ago)
Author:
vboxsync
Message:

Audio/VaKit: A bit more work on audio device enumeration and selection. bugref:10008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r88959 r88960  
    4040
    4141#include <VBox/vmm/pdmaudioinline.h>
     42#include <VBox/vmm/pdmaudiohostenuminline.h>
    4243
    4344#include "../../../Devices/Audio/AudioHlp.h"
     
    6566    /** How many iterations the test should be executed. */
    6667    uint32_t                cIterations;
    67     /** Name or path of audio device to use, depending on the OS.
    68      *  If NULL, the default device for this specific test (input / output) will be used. */
    69     char                   *pszDevice;
     68    /** Audio device to use. */
     69    PDMAUDIOHOSTDEV         Dev;
    7070    /** Absolute path where to store the test audio data.
    7171     *  If NULL, no test audio data will be written. */
     
    113113typedef struct AUDIOTESTENV
    114114{
    115     PPDMIHOSTAUDIO          pDrvAudio;
     115    /** The host (backend) driver to use. */
     116    PPDMIHOSTAUDIO   pDrvAudio;
     117    /** The current (last) audio device enumeration to use. */
     118    PDMAUDIOHOSTENUM DevEnm;
    116119} AUDIOTESTENV;
    117120/** Pointer a audio test environment. */
     
    208211//    PDMAudioPropsInit(&Props, 16 /* bit */ / 8, true /* fSigned */, 2 /* Channels */, 44100 /* Hz */);
    209212
    210     //AudioTestToneParamsInitRandom(&pTestParms->ToneParms, &pTestParms->ToneParms.Props);
     213    //AudioTestToneParamsInitRandom(&pTstParms->ToneParms, &pTstParms->ToneParms.Props);
    211214
    212215    return VINF_SUCCESS;
     
    232235*********************************************************************************************************************************/
    233236
    234 static void audioTestParmsInit(PAUDIOTESTPARMS pTestParms)
    235 {
    236     RT_BZERO(pTestParms, sizeof(AUDIOTESTPARMS));
     237static void audioTestEnvInit(PAUDIOTESTENV pTstEnv, PPDMIHOSTAUDIO pDrvAudio)
     238{
     239    RT_BZERO(pTstEnv, sizeof(AUDIOTESTENV));
     240
     241    pTstEnv->pDrvAudio = pDrvAudio;
     242    PDMAudioHostEnumInit(&pTstEnv->DevEnm);
     243
    237244    return;
    238245}
    239246
    240 static void audioTestParmsDestroy(PAUDIOTESTPARMS pTestParms)
    241 {
    242     if (!pTestParms)
     247static void audioTestEnvDestroy(PAUDIOTESTENV pTstEnv)
     248{
     249    if (!pTstEnv)
    243250        return;
    244251
    245     RTStrFree(pTestParms->pszDevice);
    246     pTestParms->pszDevice = NULL;
    247 
    248     RTStrFree(pTestParms->pszPathOutAbs);
    249     pTestParms->pszPathOutAbs = NULL;
     252    PDMAudioHostEnumDelete(&pTstEnv->DevEnm);
     253}
     254
     255static void audioTestParmsInit(PAUDIOTESTPARMS pTstParms)
     256{
     257    RT_BZERO(pTstParms, sizeof(AUDIOTESTPARMS));
     258    return;
     259}
     260
     261static void audioTestParmsDestroy(PAUDIOTESTPARMS pTstParms)
     262{
     263    if (!pTstParms)
     264        return;
     265
     266    RTStrFree(pTstParms->pszPathOutAbs);
     267    pTstParms->pszPathOutAbs = NULL;
    250268
    251269    return;
     
    340358}
    341359
    342 /**
    343  * Searches for the default audio test device and return the device path.
    344  *
    345  * @returns Path to the device audio device or NULL if none was found.
    346  */
    347 static char *audioTestDeviceFindDefault(void)
    348 {
    349     /** @todo Implement finding default device. */
    350     return NULL;
    351 }
    352 
    353 static int audioTestDeviceOpen(const char *pszDevice)
     360static int audioTestDevicesEnumerateAndCheck(PAUDIOTESTENV pTstEnv, const char *pszDev, PPDMAUDIOHOSTDEV *ppDev)
     361{
     362    RTTestSubF(g_hTest, "Enumerating audio devices and checking for device '%s'", pszDev ? pszDev : "<Default>");
     363
     364    if (!pTstEnv->pDrvAudio->pfnGetDevices)
     365    {
     366        RTTestSkipped(g_hTest, "Backend does not support device enumeration, skipping");
     367        return VINF_NOT_SUPPORTED;
     368    }
     369
     370    Assert(pszDev == NULL || ppDev);
     371
     372    if (ppDev)
     373        *ppDev = NULL;
     374
     375    int rc = pTstEnv->pDrvAudio->pfnGetDevices(pTstEnv->pDrvAudio, &pTstEnv->DevEnm);
     376    if (RT_SUCCESS(rc))
     377    {
     378        PPDMAUDIOHOSTDEV pDev;
     379        RTListForEach(&pTstEnv->DevEnm.LstDevices, pDev, PDMAUDIOHOSTDEV, ListEntry)
     380        {
     381            char szFlags[PDMAUDIOHOSTDEV_MAX_FLAGS_STRING_LEN];
     382            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum: Device '%s':\n", pDev->szName);
     383            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum:   Usage           = %s\n",   PDMAudioDirGetName(pDev->enmUsage));
     384            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum:   Flags           = %s\n",   PDMAudioHostDevFlagsToString(szFlags, pDev->fFlags));
     385            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum:   Input channels  = %RU8\n", pDev->cMaxInputChannels);
     386            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Enum:   Output channels = %RU8\n", pDev->cMaxOutputChannels);
     387
     388            if (   pszDev
     389                && !RTStrCmp(pDev->szName, pszDev))
     390            {
     391                *ppDev = pDev;
     392            }
     393        }
     394    }
     395    else
     396        RTTestFailed(g_hTest, "Enumerating audio devices failed with %Rrc", rc);
     397
     398    RTTestSubDone(g_hTest);
     399
     400    if (   pszDev
     401        && *ppDev == NULL)
     402    {
     403        RTTestFailed(g_hTest, "Audio device '%s' not found", pszDev);
     404        return VERR_NOT_FOUND;
     405    }
     406
     407    return VINF_SUCCESS;
     408}
     409
     410static int audioTestDeviceOpen(PPDMAUDIOHOSTDEV pDev)
    354411{
    355412    int rc = VINF_SUCCESS;
    356413
    357     RTTestSubF(g_hTest, "Opening audio device '%s' ...", pszDevice ? "<Default>>" : pszDevice);
    358 
    359     if (!pszDevice)
    360         audioTestDeviceFindDefault();
     414    RTTestSubF(g_hTest, "Opening audio device '%s' ...", pDev->szName);
    361415
    362416    /** @todo Detect + open device here. */
     417
     418    RTTestSubDone(g_hTest);
     419
     420    return rc;
     421}
     422
     423static int audioTestDeviceClose(PPDMAUDIOHOSTDEV pDev)
     424{
     425    int rc = VINF_SUCCESS;
     426
     427    RTTestSubF(g_hTest, "Closing audio device '%s' ...", pDev->szName);
     428
     429    /** @todo Close device here. */
    363430
    364431    RTTestSubDone(g_hTest);
     
    376443                        unsigned uSeq, PAUDIOTESTPARMS pOverrideParms)
    377444{
     445    RT_NOREF(uSeq);
     446
    378447    int rc;
    379448
     
    400469    audioTestCombineParms(&TstParms, pOverrideParms);
    401470
    402     /* Open the device on the first test being run. */
    403     if (   uSeq == 0
    404         && TstParms.pszDevice
    405         && strlen(TstParms.pszDevice))
    406     {
    407         rc = audioTestDeviceOpen(TstParms.pszDevice);
    408         if (RT_FAILURE(rc))
    409             RTTestFailed(g_hTest, "Unable to find audio device '%s'", TstParms.pszDevice);
    410     }
     471    if (strlen(TstParms.Dev.szName)) /** @todo Refine this check. */
     472        rc = audioTestDeviceOpen(&TstParms.Dev);
    411473
    412474    AssertPtr(pTstDesc->pfnExec);
     
    422484    }
    423485
     486    rc = audioTestDeviceClose(&TstParms.Dev);
     487
    424488    audioTestParmsDestroy(&TstParms);
    425489
     
    451515    AUDIOTESTPARMS TstCust;
    452516    audioTestParmsInit(&TstCust);
     517
     518    char *pszDevice = NULL; /* Custom device to use. Can be NULL if not being used. */
    453519
    454520    RT_ZERO(g_DrvIns);
     
    539605            case VKAT_TEST_OPT_DEV:
    540606            {
    541                 TstCust.pszDevice = RTStrDup(ValueUnion.psz);
     607                pszDevice = RTStrDup(ValueUnion.psz);
    542608                break;
    543609            }
     
    611677    {
    612678        /* For now all tests have the same test environment. */
    613         AUDIOTESTENV TestEnv;
    614         TestEnv.pDrvAudio = pDrvAudio;
    615 
    616         audioTestWorker(&TestEnv, &TstCust);
    617 
     679        AUDIOTESTENV TstEnv;
     680        audioTestEnvInit(&TstEnv, pDrvAudio);
     681
     682        PPDMAUDIOHOSTDEV pDev;
     683        rc = audioTestDevicesEnumerateAndCheck(&TstEnv, pszDevice, &pDev);
     684        if (RT_SUCCESS(rc))
     685            audioTestWorker(&TstEnv, &TstCust);
     686
     687        audioTestEnvDestroy(&TstEnv);
    618688        audioTestDrvDestruct(pDrvReg, &g_DrvIns);
    619689    }
    620690
    621691    audioTestParmsDestroy(&TstCust);
     692
     693    RTStrFree(pszDevice);
    622694
    623695    /*
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