VirtualBox

Ignore:
Timestamp:
May 17, 2021 5:33:27 PM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: Baked the audio driver stack handling into the audio test environment to make it more flexible. bugref:10008

File:
1 edited

Legend:

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

    r89115 r89117  
    127127typedef FNAUDIOTESTDESTROY *PFNAUDIOTESTDESTROY;
    128128
     129/**
     130 * Audio driver stack.
     131 *
     132 * This can be just be backend driver alone or DrvAudio with a backend.
     133 * @todo add automatic resampling via mixer so we can test more of the audio
     134 *       stack used by the device emulations.
     135 */
     136typedef struct AUDIOTESTDRVSTACK
     137{
     138    /** The device registration record for the backend. */
     139    PCPDMDRVREG             pDrvReg;
     140    /** The backend driver instance. */
     141    PPDMDRVINS              pDrvBackendIns;
     142    /** The backend's audio interface. */
     143    PPDMIHOSTAUDIO          pIHostAudio;
     144
     145    /** The DrvAudio instance. */
     146    PPDMDRVINS              pDrvAudioIns;
     147    /** This is NULL if we don't use DrvAudio. */
     148    PPDMIAUDIOCONNECTOR     pIAudioConnector;
     149} AUDIOTESTDRVSTACK;
     150/** Pointer to an audio driver stack. */
     151typedef AUDIOTESTDRVSTACK *PAUDIOTESTDRVSTACK;
     152
     153/**
     154 * Backend-only stream structure.
     155 */
     156typedef struct AUDIOTESTDRVSTACKSTREAM
     157{
     158    /** The public stream data. */
     159    PDMAUDIOSTREAM          Core;
     160    /** The acquired config. */
     161    PDMAUDIOSTREAMCFG       Cfg;
     162    /** The backend data (variable size). */
     163    PDMAUDIOBACKENDSTREAM   Backend;
     164} AUDIOTESTDRVSTACKSTREAM;
     165/** Pointer to a backend-only stream structure. */
     166typedef AUDIOTESTDRVSTACKSTREAM *PAUDIOTESTDRVSTACKSTREAM;
     167
    129168/** Maximum audio streams a test environment can handle. */
    130169#define AUDIOTESTENV_MAX_STREAMS 8
     
    140179    /** Temporary path for this test environment. */
    141180    char                  szPathTemp[RTPATH_MAX];
    142     /** The host (backend) driver to use. */
    143     PPDMIHOSTAUDIO        pDrvAudio;
     181    /** The audio test driver stack. */
     182    AUDIOTESTDRVSTACK     DrvStack;
    144183    /** The current (last) audio device enumeration to use. */
    145184    PDMAUDIOHOSTENUM      DevEnum;
     
    166205    PFNAUDIOTESTDESTROY     pfnDestroy;
    167206} AUDIOTESTDESC;
    168 
    169 
    170 /**
    171  * Audio driver stack.
    172  *
    173  * This can be just be backend driver alone or DrvAudio with a backend.
    174  * @todo add automatic resampling via mixer so we can test more of the audio
    175  *       stack used by the device emulations.
    176  */
    177 typedef struct AUDIOTESTDRVSTACK
    178 {
    179     /** The device registration record for the backend. */
    180     PCPDMDRVREG             pDrvReg;
    181     /** The backend driver instance. */
    182     PPDMDRVINS              pDrvBackendIns;
    183     /** The backend's audio interface. */
    184     PPDMIHOSTAUDIO          pIHostAudio;
    185 
    186     /** The DrvAudio instance. */
    187     PPDMDRVINS              pDrvAudioIns;
    188     /** This is NULL if we don't use DrvAudio. */
    189     PPDMIAUDIOCONNECTOR     pIAudioConnector;
    190 } AUDIOTESTDRVSTACK;
    191 /** Pointer to an audio driver stack. */
    192 typedef AUDIOTESTDRVSTACK *PAUDIOTESTDRVSTACK;
    193 
    194 /**
    195  * Backend-only stream structure.
    196  */
    197 typedef struct AUDIOTESTDRVSTACKSTREAM
    198 {
    199     /** The public stream data. */
    200     PDMAUDIOSTREAM          Core;
    201     /** The acquired config. */
    202     PDMAUDIOSTREAMCFG       Cfg;
    203     /** The backend data (variable size). */
    204     PDMAUDIOBACKENDSTREAM   Backend;
    205 } AUDIOTESTDRVSTACKSTREAM;
    206 /** Pointer to a backend-only stream structure. */
    207 typedef AUDIOTESTDRVSTACKSTREAM *PAUDIOTESTDRVSTACKSTREAM;
    208207
    209208
     
    277276{
    278277    { "--backend",          'b',                          RTGETOPT_REQ_STRING  },
     278    { "--drvaudio",         'd',                          RTGETOPT_REQ_NOTHING },
    279279    { "--exclude",          'e',                          RTGETOPT_REQ_UINT32  },
    280280    { "--exclude-all",      'a',                          RTGETOPT_REQ_NOTHING },
     
    412412            pszRet = g_pszDrvAudioDebug;
    413413
     414        AssertPtrReturn(pszRet, VERR_INVALID_POINTER);
     415
    414416        int rc = RTStrCopy(pszString, cchString, pszRet);
    415417
     
    755757 * @param   pDrvStack       The driver stack to initialize.
    756758 * @param   pDrvReg         The backend driver to use.
    757  * @param   fWithDrvAudio   Whether to inlcude DrvAudio in the stack or not.
     759 * @param   fWithDrvAudio   Whether to include DrvAudio in the stack or not.
    758760 */
    759761static int audioTestDriverStackInit(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fWithDrvAudio)
     
    12131215 *
    12141216 * @param   pTstEnv             Audio test environment to initialize.
    1215  * @param   pDrvAudio           Audio driver to use.
    1216  * @param   pszPathOut          Output path to use. If NULL, the system's temp directory will be used.
    1217  * @param   pszPathTemp         Temporary path to use. If NULL, the system's temp directory will be used.
     1217 * @param   pDrvReg             Audio driver to use.
     1218 * @param   fWithDrvAudio       Whether to include DrvAudio in the stack or not.
    12181219 * @param   pszTag              Tag name to use. If NULL, a generated UUID will be used.
    12191220 */
    1220 static int audioTestEnvInit(PAUDIOTESTENV pTstEnv, PPDMIHOSTAUDIO pDrvAudio, const char *pszTag)
    1221 {
    1222     pTstEnv->pDrvAudio = pDrvAudio;
     1221static int audioTestEnvInit(PAUDIOTESTENV pTstEnv, PCPDMDRVREG pDrvReg, bool fWithDrvAudio, const char *pszTag)
     1222{
    12231223    PDMAudioHostEnumInit(&pTstEnv->DevEnum);
    12241224
    1225     int rc = VINF_SUCCESS;
     1225    int rc = audioTestDriverStackInit(&pTstEnv->DrvStack, pDrvReg, fWithDrvAudio);
     1226    if (RT_FAILURE(rc))
     1227        return rc;
    12261228
    12271229    char szPathTemp[RTPATH_MAX];
     
    12481250    }
    12491251
     1252    if (RT_FAILURE(rc))
     1253        audioTestDriverStackDelete(&pTstEnv->DrvStack);
     1254
    12501255    return rc;
    12511256}
     
    12711276
    12721277    AudioTestSetDestroy(&pTstEnv->Set);
     1278    audioTestDriverStackDelete(&pTstEnv->DrvStack);
    12731279}
    12741280
     
    13141320    RTTestSubF(g_hTest, "Enumerating audio devices and checking for device '%s'", pszDev ? pszDev : "<Default>");
    13151321
    1316     if (!pTstEnv->pDrvAudio->pfnGetDevices)
     1322    if (!pTstEnv->DrvStack.pIHostAudio->pfnGetDevices)
    13171323    {
    13181324        RTTestSkipped(g_hTest, "Backend does not support device enumeration, skipping");
     
    13251331        *ppDev = NULL;
    13261332
    1327     int rc = pTstEnv->pDrvAudio->pfnGetDevices(pTstEnv->pDrvAudio, &pTstEnv->DevEnum);
     1333    int rc = pTstEnv->DrvStack.pIHostAudio->pfnGetDevices(pTstEnv->DrvStack.pIHostAudio, &pTstEnv->DevEnum);
    13281334    if (RT_SUCCESS(rc))
    13291335    {
     
    14131419    AssertRC(rc); /* Cannot fail. */
    14141420
    1415     rc = pTstEnv->pDrvAudio->pfnStreamCreate(pTstEnv->pDrvAudio, &pStream->Backend, pCfg, &CfgAcq);
     1421    rc = pTstEnv->DrvStack.pIHostAudio->pfnStreamCreate(pTstEnv->DrvStack.pIHostAudio, &pStream->Backend, pCfg, &CfgAcq);
    14161422    if (RT_FAILURE(rc))
    14171423        return rc;
     
    14191425    /* Do the async init in a synchronous way for now here. */
    14201426    if (rc == VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED)
    1421         rc = pTstEnv->pDrvAudio->pfnStreamInitAsync(pTstEnv->pDrvAudio, &pStream->Backend, false /* fDestroyed */);
     1427        rc = pTstEnv->DrvStack.pIHostAudio->pfnStreamInitAsync(pTstEnv->DrvStack.pIHostAudio, &pStream->Backend, false /* fDestroyed */);
    14221428
    14231429    if (RT_SUCCESS(rc))
     
    14441450    /** @todo Anything else to do here, e.g. test if there are left over samples or some such? */
    14451451
    1446     int rc = pTstEnv->pDrvAudio->pfnStreamDestroy(pTstEnv->pDrvAudio, &pStream->Backend);
     1452    int rc = pTstEnv->DrvStack.pIHostAudio->pfnStreamDestroy(pTstEnv->DrvStack.pIHostAudio, &pStream->Backend);
    14471453    if (RT_SUCCESS(rc))
    14481454        RT_BZERO(pStream, sizeof(PDMAUDIOBACKENDSTREAM));
     
    15031509    AssertRCReturn(rc, rc);
    15041510
    1505     PDMHOSTAUDIOSTREAMSTATE enmState = pTstEnv->pDrvAudio->pfnStreamGetState(pTstEnv->pDrvAudio, &pStream->Backend);
     1511    PDMHOSTAUDIOSTREAMSTATE enmState = pTstEnv->DrvStack.pIHostAudio->pfnStreamGetState(pTstEnv->DrvStack.pIHostAudio, &pStream->Backend);
    15061512    if (enmState == PDMHOSTAUDIOSTREAMSTATE_OKAY)
    15071513    {
     
    15231529                {
    15241530                    uint32_t cbWritten;
    1525                     rc = pTstEnv->pDrvAudio->pfnStreamPlay(pTstEnv->pDrvAudio, &pStream->Backend, abBuf, cbBuf, &cbWritten);
     1531                    rc = pTstEnv->DrvStack.pIHostAudio->pfnStreamPlay(pTstEnv->DrvStack.pIHostAudio, &pStream->Backend, abBuf, cbBuf, &cbWritten);
    15261532                }
    15271533            }
     
    17321738    switch (pOpt->iShort)
    17331739    {
    1734         case 'd':   return "Use the specified audio device";
    1735         case 'e':   return "Exclude the given test id from the list";
    1736         case 'a':   return "Exclude all tests from the list (useful to enable single tests later with --include)";
    1737         case 'i':   return "Include the given test id in the list";
     1740        case 'd':                 return "Go via DrvAudio instead of directly interfacing with the backend.";
     1741        case VKAT_TEST_OPT_DEV:   return "Use the specified audio device";
     1742        case 'e':                 return "Exclude the given test id from the list";
     1743        case 'a':                 return "Exclude all tests from the list (useful to enable single tests later with --include)";
     1744        case 'i':                 return "Include the given test id in the list";
    17381745    }
    17391746    return NULL;
     
    17541761    audioTestParmsInit(&TstCust);
    17551762
    1756     const char *pszDevice  = NULL; /* Custom device to use. Can be NULL if not being used. */
    1757     const char *pszTag     = NULL; /* Custom tag to use. Can be NULL if not being used. */
    1758     PCPDMDRVREG pDrvReg    = g_aBackends[0].pDrvReg;
     1763    const char *pszDevice     = NULL; /* Custom device to use. Can be NULL if not being used. */
     1764    const char *pszTag        = NULL; /* Custom tag to use. Can be NULL if not being used. */
     1765    PCPDMDRVREG pDrvReg       = g_aBackends[0].pDrvReg;
     1766    bool        fWithDrvAudio = false;
    17591767
    17601768    int           rc;
     
    17821790                break;
    17831791
     1792            case 'd':
     1793                fWithDrvAudio = true;
     1794                break;
     1795
    17841796            case 'e':
    17851797                if (ValueUnion.u32 >= RT_ELEMENTS(g_aTests))
     
    18541866    RTTestBanner(g_hTest);
    18551867
    1856     AUDIOTESTDRVSTACK DrvStack;
    1857     rc = audioTestDriverStackInit(&DrvStack, pDrvReg, false /*fWithDrvAudio*/);
     1868    /* For now all tests have the same test environment. */
     1869    rc = audioTestEnvInit(&TstEnv, pDrvReg, fWithDrvAudio, pszTag);
    18581870    if (RT_SUCCESS(rc))
    18591871    {
    1860         /* For now all tests have the same test environment. */
    1861         /** @todo bake the DrvStack into the test env make make it more flexible so
    1862          *        we can also test with/without DrvAudio (need option above). */
    1863         rc = audioTestEnvInit(&TstEnv, DrvStack.pIHostAudio, pszTag);
     1872        PPDMAUDIOHOSTDEV pDev;
     1873        rc = audioTestDevicesEnumerateAndCheck(&TstEnv, pszDevice, &pDev);
    18641874        if (RT_SUCCESS(rc))
    1865         {
    1866             PPDMAUDIOHOSTDEV pDev;
    1867             rc = audioTestDevicesEnumerateAndCheck(&TstEnv, pszDevice, &pDev);
    1868             if (RT_SUCCESS(rc))
    1869                 audioTestWorker(&TstEnv, &TstCust);
    1870 
    1871             /* Before destroying the test environment, pack up the test set so
    1872              * that it's ready for transmission. */
    1873             char szFileOut[RTPATH_MAX];
    1874             rc = AudioTestSetPack(&TstEnv.Set, TstEnv.szPathOut, szFileOut, sizeof(szFileOut));
    1875             if (RT_SUCCESS(rc))
    1876                 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set packed up to '%s'\n", szFileOut);
    1877 
    1878             /* Clean up. */
    1879             int rc2 = AudioTestSetWipe(&TstEnv.Set);
    1880             AssertRC(rc2); /* Annoying, but not test-critical. */
    1881 
    1882             audioTestEnvDestroy(&TstEnv);
    1883         }
    1884         audioTestDriverStackDelete(&DrvStack);
     1875            audioTestWorker(&TstEnv, &TstCust);
     1876
     1877        /* Before destroying the test environment, pack up the test set so
     1878         * that it's ready for transmission. */
     1879        char szFileOut[RTPATH_MAX];
     1880        rc = AudioTestSetPack(&TstEnv.Set, TstEnv.szPathOut, szFileOut, sizeof(szFileOut));
     1881        if (RT_SUCCESS(rc))
     1882            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Test set packed up to '%s'\n", szFileOut);
     1883
     1884        /* Clean up. */
     1885        int rc2 = AudioTestSetWipe(&TstEnv.Set);
     1886        AssertRC(rc2); /* Annoying, but not test-critical. */
     1887
     1888        audioTestEnvDestroy(&TstEnv);
    18851889    }
    18861890
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