VirtualBox

Changeset 89291 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 26, 2021 10:04:32 AM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: Audio input (recording) injection to guests now work the first time via the Validation Kit audio driver. bugref:10008

File:
1 edited

Legend:

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

    r89280 r89291  
    8181typedef struct VALKITTESTTONEDATA
    8282{
    83     /** How many ns to write. */
    84     uint64_t           nsToWrite;
    85     /** How many ns already written. */
    86     uint64_t           nsWritten;
     83    /** How many bytes to write. */
     84    uint64_t           cbToWrite;
     85    /** How many bytes already written. */
     86    uint64_t           cbWritten;
    8787    /** The test tone instance to use. */
    8888    AUDIOTESTTONE      Tone;
    8989    /** The test tone parameters to use. */
    90     AUDIOTESTTONEPARMS ToneParms;
     90    AUDIOTESTTONEPARMS Parms;
    9191} VALKITTESTTONEDATA;
    9292
     
    105105        VALKITTESTTONEDATA TestTone;
    106106    } t;
     107    /** Time stamp (real, in ms) when test started. */
     108    uint64_t               msStartedTS;
    107109} VALKITTESTDATA;
    108110/** Pointer to Validation Kit test data. */
     
    144146    AssertPtrReturn(pTestData, VERR_NO_MEMORY);
    145147
    146     memcpy(&pTestData->StreamCfg,            pStreamCfg, sizeof(PDMAUDIOSTREAMCFG));
    147     memcpy(&pTestData->t.TestTone.ToneParms, pToneParms, sizeof(AUDIOTESTTONEPARMS));
    148 
     148    memcpy(&pTestData->StreamCfg,        pStreamCfg, sizeof(PDMAUDIOSTREAMCFG));
     149    memcpy(&pTestData->t.TestTone.Parms, pToneParms, sizeof(AUDIOTESTTONEPARMS));
     150
     151    AudioTestToneInit(&pTestData->t.TestTone.Tone, &pStreamCfg->Props, 8000 /* Hz */); /** @todo BUGBUG Fix this! */
     152
     153    pTestData->t.TestTone.cbToWrite = PDMAudioPropsMilliToBytes(&pStreamCfg->Props,
     154                                                                pTestData->t.TestTone.Parms.msDuration);
    149155    int rc = RTCritSectEnter(&pThis->CritSect);
    150156    if (RT_SUCCESS(rc))
    151157    {
    152158        RTListAppend(&pThis->lstTestsRec, &pTestData->Node);
     159
     160        pThis->cTestsRec++;
    153161
    154162        int rc2 = RTCritSectLeave(&pThis->CritSect);
     
    467475    PDRVHOSTVALKITAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVHOSTVALKITAUDIO, IHostAudio);
    468476
    469     int rc = VINF_SUCCESS;
    470 
    471     if (pThis->pTestRecCur == NULL)
    472     {
     477    int rc = RTCritSectEnter(&pThis->CritSect);
     478    if (RT_SUCCESS(rc))
     479    {
     480        pThis->pTestRecCur = RTListGetFirst(&pThis->lstTestsRec, VALKITTESTDATA, Node);
     481
     482        int rc2 = RTCritSectLeave(&pThis->CritSect);
     483        AssertRC(rc2);
     484    }
     485
     486    if (pThis->pTestRecCur == NULL) /* Empty list? */
     487    {
     488        *pcbRead = 0;
     489        return VINF_SUCCESS;
     490    }
     491
     492    PVALKITTESTDATA pTst = pThis->pTestRecCur;
     493
     494    if (pTst->t.TestTone.cbWritten == 0)
     495    {
     496        pTst->msStartedTS = RTTimeMilliTS();
     497
     498        LogRel(("Audio: Validation Kit: Injecting input tone (%RU16Hz, %RU32ms)\n",
     499                (uint16_t)pTst->t.TestTone.Tone.rdFreqHz,
     500                pTst->t.TestTone.Parms.msDuration));
     501    }
     502
     503    uint32_t cbToWrite = pTst->t.TestTone.cbToWrite - pTst->t.TestTone.cbWritten;
     504    uint32_t cbRead    = 0;
     505    if (cbToWrite)
     506        rc = AudioTestToneGenerate(&pTst->t.TestTone.Tone, pvBuf, RT_MIN(cbToWrite, cbBuf), &cbRead);
     507
     508    pTst->t.TestTone.cbWritten += cbRead;
     509    Assert(pTst->t.TestTone.cbWritten <= pTst->t.TestTone.cbToWrite);
     510
     511    const bool fComplete = pTst->t.TestTone.cbToWrite == pTst->t.TestTone.cbWritten;
     512
     513    if (fComplete)
     514    {
     515        LogRel(("Audio: Validation Kit: Injection done (took %RU32ms)\n",
     516                RTTimeMilliTS() - pTst->msStartedTS));
     517
    473518        rc = RTCritSectEnter(&pThis->CritSect);
    474519        if (RT_SUCCESS(rc))
    475520        {
    476             pThis->pTestRecCur = RTListGetFirst(&pThis->lstTestsRec, VALKITTESTDATA, Node);
     521            RTListNodeRemove(&pTst->Node);
     522
     523            RTMemFree(pTst);
     524            pTst = NULL;
     525
     526            Assert(pThis->cTestsRec);
     527            pThis->cTestsRec--;
    477528
    478529            int rc2 = RTCritSectLeave(&pThis->CritSect);
    479530            AssertRC(rc2);
    480531        }
    481     }
    482 
    483     if (pThis->pTestRecCur == NULL) /* Empty list? */
    484     {
    485         *pcbRead = 0;
    486         return VINF_SUCCESS;
    487     }
    488 
    489     PVALKITTESTDATA pTst = pThis->pTestRecCur;
    490 
    491     uint32_t cbToWrite = PDMAudioPropsNanoToBytes(&pTst->StreamCfg.Props,
    492                                                   (pTst->t.TestTone.nsToWrite - pTst->t.TestTone.nsWritten));
    493     uint32_t cbRead = 0;
    494     if (cbToWrite)
    495         rc = AudioTestToneGenerate(&pTst->t.TestTone.Tone, pvBuf, RT_MIN(cbToWrite, cbBuf), &cbRead);
    496 
    497     const uint32_t nsWritten    = PDMAudioPropsBytesToNano(&pTst->StreamCfg.Props, cbRead);
    498     pTst->t.TestTone.nsWritten += nsWritten;
    499     Assert(pTst->t.TestTone.nsWritten <= pTst->t.TestTone.nsToWrite);
    500 
    501     const bool fComplete = pTst->t.TestTone.nsToWrite == pTst->t.TestTone.nsWritten;
    502 
    503     if (fComplete)
    504     {
    505         RTListNodeRemove(&pTst->Node);
    506 
    507         RTMemFree(pTst);
    508         pTst = NULL;
    509 
    510         Assert(pThis->cTestsRec);
    511         pThis->cTestsRec--;
    512532    }
    513533
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