VirtualBox

Changeset 91908 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Oct 20, 2021 7:05:19 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147713
Message:

Audio/Validation Kit: Implemented support for injecting pre/post audio beacons for the Validation Kit audio driver. ​bugref:10008

File:
1 edited

Legend:

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

    r91655 r91908  
    8080            /** How many bytes already written. */
    8181            uint64_t           cbWritten;
     82            /** Size (in bytes) a single pre/post beacon is. */
     83            uint32_t           cbBeacon;
     84            /** Beacon bytes to write. */
     85            uint32_t           cbBeaconToWrite;
     86            /** Beacon bytes written. */
     87            uint32_t           cbBeaconWritten;
    8288        } Rec;
    8389        struct
     
    478484    memcpy(&pTestData->t.TestTone.Parms, pToneParms, sizeof(AUDIOTESTTONEPARMS));
    479485
     486    PPDMAUDIOPCMPROPS const pProps = &pTestData->t.TestTone.Parms.Props;
     487
    480488    AssertReturn(pTestData->t.TestTone.Parms.msDuration, VERR_INVALID_PARAMETER);
    481     AssertReturn(PDMAudioPropsAreValid(&pTestData->t.TestTone.Parms.Props), VERR_INVALID_PARAMETER);
    482 
    483     AudioTestToneInit(&pTestData->t.TestTone.Tone, &pTestData->t.TestTone.Parms.Props, pTestData->t.TestTone.Parms.dbFreqHz);
    484 
    485     pTestData->t.TestTone.u.Rec.cbToWrite = PDMAudioPropsMilliToBytes(&pTestData->t.TestTone.Parms.Props,
     489    AssertReturn(PDMAudioPropsAreValid(pProps), VERR_INVALID_PARAMETER);
     490
     491    AudioTestToneInit(&pTestData->t.TestTone.Tone, pProps, pTestData->t.TestTone.Parms.dbFreqHz);
     492
     493    pTestData->t.TestTone.u.Rec.cbToWrite = PDMAudioPropsMilliToBytes(pProps,
    486494                                                                      pTestData->t.TestTone.Parms.msDuration);
     495
     496    /* We play a pre + post beacon before + after the actual test tone
     497     * with exactly AUDIOTEST_BEACON_SIZE_FRAMES audio frames. */
     498    pTestData->t.TestTone.u.Rec.cbBeacon        = PDMAudioPropsFramesToBytes(pProps, AUDIOTEST_BEACON_SIZE_FRAMES);
     499    pTestData->t.TestTone.u.Rec.cbBeaconToWrite = pTestData->t.TestTone.u.Rec.cbBeacon;
     500
    487501    int rc = RTCritSectEnter(&pThis->CritSect);
    488502    if (RT_SUCCESS(rc))
     
    491505                pThis->idxTest, pTestData->t.TestTone.Parms.msDuration, pTestData->t.TestTone.u.Rec.cbToWrite,
    492506                pToneParms->Hdr.idxSeq));
     507        if (pTestData->t.TestTone.u.Rec.cbBeaconToWrite)
     508        {
     509            LogRel2(("ValKit: Guest recording test #%RU32 includes 2 x %RU32 bytes of beacons\n",
     510                     pThis->idxTest, pTestData->t.TestTone.u.Rec.cbBeaconToWrite));
     511
     512            pTestData->t.TestTone.u.Rec.cbToWrite += 2 /* Pre + Post */ * pTestData->t.TestTone.u.Rec.cbBeaconToWrite;
     513        }
    493514
    494515        RTListAppend(&pThis->lstTestsRec, &pTestData->Node);
     
    10671088    if (RT_SUCCESS(rc))
    10681089    {
    1069         pThis->cbRecordedTotal += cbBuf; /* Do a bit of accounting. */
    1070 
    10711090        if (pThis->pTestCurRec == NULL)
    10721091        {
     
    10971116    }
    10981117
    1099     uint32_t cbRead = 0;
     1118    uint32_t cbWritten = 0;
     1119
     1120    /* Start playing the post beacon? */
     1121    if (pTst->t.TestTone.u.Rec.cbWritten == pTst->t.TestTone.u.Rec.cbToWrite - pTst->t.TestTone.u.Rec.cbBeaconToWrite)
     1122        pTst->t.TestTone.u.Rec.cbBeaconWritten = 0;
     1123
     1124    /* Any beacon to write? */
     1125    if (   pTst->t.TestTone.u.Rec.cbBeaconToWrite
     1126        && pTst->t.TestTone.u.Rec.cbBeaconWritten < pTst->t.TestTone.u.Rec.cbBeaconToWrite)
     1127    {
     1128        /* Limit to exactly one beacon (pre or post). */
     1129        uint32_t const cbToWrite = RT_MIN(cbBuf,
     1130                                          pTst->t.TestTone.u.Rec.cbBeaconToWrite - pTst->t.TestTone.u.Rec.cbBeaconWritten);
     1131        memset(pvBuf,
     1132                 pTst->t.TestTone.u.Rec.cbWritten >= pTst->t.TestTone.u.Rec.cbToWrite - pTst->t.TestTone.u.Rec.cbBeaconToWrite
     1133               ? AUDIOTEST_BEACON_BYTE_POST : AUDIOTEST_BEACON_BYTE_PRE,
     1134               cbToWrite);
     1135
     1136        cbWritten = cbToWrite;
     1137
     1138        pTst->t.TestTone.u.Rec.cbBeaconWritten += cbWritten;
     1139        Assert(pTst->t.TestTone.u.Rec.cbBeaconWritten <= pTst->t.TestTone.u.Rec.cbBeaconToWrite);
     1140
     1141        rc = VINF_SUCCESS;
     1142    }
     1143    else
     1144    {
     1145        uint32_t const cbToWrite = RT_MIN(cbBuf,
     1146                                            (pTst->t.TestTone.u.Rec.cbToWrite - pTst->t.TestTone.u.Rec.cbBeaconToWrite)
     1147                                          - pTst->t.TestTone.u.Rec.cbWritten);
     1148        if (cbToWrite)
     1149            rc = AudioTestToneGenerate(&pTst->t.TestTone.Tone, pvBuf, cbToWrite, &cbWritten);
     1150        if (   RT_SUCCESS(rc)
     1151            && cbWritten)
     1152        {
     1153            Assert(cbWritten == cbToWrite);
     1154
     1155            if (cbWritten > pStrmValKit->cbAvail)
     1156                LogRel(("ValKit: Warning: Test #%RU32: Reading more from capturing stream than availabe for (%RU32 vs. %RU32)\n",
     1157                        pTst->idxTest, cbWritten, pStrmValKit->cbAvail));
     1158        }
     1159    }
    11001160
    11011161    if (RT_SUCCESS(rc))
    11021162    {
    1103         uint32_t cbToWrite = RT_MIN(cbBuf,
    1104                                     pTst->t.TestTone.u.Rec.cbToWrite - pTst->t.TestTone.u.Rec.cbWritten);
    1105         if (cbToWrite)
    1106             rc = AudioTestToneGenerate(&pTst->t.TestTone.Tone, pvBuf, cbToWrite, &cbRead);
    1107         if (   RT_SUCCESS(rc)
    1108             && cbRead)
    1109         {
    1110             Assert(cbRead == cbToWrite);
    1111 
    1112             if (cbRead > pStrmValKit->cbAvail)
    1113                 LogRel(("ValKit: Warning: Test #%RU32: Reading more from capturing stream than availabe for (%RU32 vs. %RU32)\n",
    1114                         pTst->idxTest, cbRead, pStrmValKit->cbAvail));
    1115 
    1116             pStrmValKit->cbAvail -= RT_MIN(pStrmValKit->cbAvail, cbRead);
    1117 
    1118             rc = AudioTestObjWrite(pTst->Obj, pvBuf, cbRead);
    1119             if (RT_SUCCESS(rc))
     1163        rc = AudioTestObjWrite(pTst->Obj, pvBuf, cbWritten);
     1164        if (RT_SUCCESS(rc))
     1165        {
     1166            pThis->cbRecordedTotal += cbWritten; /* Do a bit of accounting. */
     1167
     1168            pStrmValKit->cbAvail   -= RT_MIN(pStrmValKit->cbAvail, cbWritten);
     1169
     1170            pTst->t.TestTone.u.Rec.cbWritten += cbWritten;
     1171            Assert(pTst->t.TestTone.u.Rec.cbWritten <= pTst->t.TestTone.u.Rec.cbToWrite);
     1172
     1173            LogRel(("ValKit: Test #%RU32: Supplied %RU32 bytes of (capturing) audio data (%RU32 bytes left)\n",
     1174                    pTst->idxTest, cbWritten, pStrmValKit->cbAvail));
     1175
     1176            const bool fComplete = pTst->t.TestTone.u.Rec.cbWritten >= pTst->t.TestTone.u.Rec.cbToWrite;
     1177            if (fComplete)
    11201178            {
    1121                 pTst->t.TestTone.u.Rec.cbWritten += cbRead;
    1122                 Assert(pTst->t.TestTone.u.Rec.cbWritten <= pTst->t.TestTone.u.Rec.cbToWrite);
    1123 
    1124                 LogRel(("ValKit: Test #%RU32: Read %RU32 bytes of (capturing) audio data (%RU32 bytes left)\n",
    1125                         pTst->idxTest, cbRead, pStrmValKit->cbAvail));
    1126 
    1127                 const bool fComplete = pTst->t.TestTone.u.Rec.cbWritten >= pTst->t.TestTone.u.Rec.cbToWrite;
    1128                 if (fComplete)
     1179                LogRel(("ValKit: Test #%RU32: Recording done (took %RU32ms)\n",
     1180                        pTst->idxTest, RTTimeMilliTS() - pTst->msStartedTS));
     1181
     1182                AudioTestSetTestDone(pTst->pEntry);
     1183
     1184                rc = RTCritSectEnter(&pThis->CritSect);
     1185                if (RT_SUCCESS(rc))
    11291186                {
    1130                     LogRel(("ValKit: Test #%RU32: Recording done (took %RU32ms)\n",
    1131                             pTst->idxTest, RTTimeMilliTS() - pTst->msStartedTS));
    1132 
    1133                     AudioTestSetTestDone(pTst->pEntry);
    1134 
    1135                     rc = RTCritSectEnter(&pThis->CritSect);
    1136                     if (RT_SUCCESS(rc))
    1137                     {
    1138                         drvHostValKiUnregisterRecTest(pThis, pTst);
    1139 
    1140                         pThis->pTestCurRec = NULL;
    1141                         pTst               = NULL;
    1142 
    1143                         int rc2 = RTCritSectLeave(&pThis->CritSect);
    1144                         AssertRC(rc2);
    1145                     }
     1187                    drvHostValKiUnregisterRecTest(pThis, pTst);
     1188
     1189                    pThis->pTestCurRec = NULL;
     1190                    pTst               = NULL;
     1191
     1192                    int rc2 = RTCritSectLeave(&pThis->CritSect);
     1193                    AssertRC(rc2);
    11461194                }
    11471195            }
     
    11561204    }
    11571205
    1158     *pcbRead = cbRead;
     1206    *pcbRead = cbWritten;
    11591207
    11601208    return VINF_SUCCESS; /** @todo Return rc here? */
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