Changeset 89051 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- May 14, 2021 6:58:11 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144391
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioTest.cpp
r89045 r89051 34 34 #include <iprt/uuid.h> 35 35 #include <iprt/vfs.h> 36 #include <iprt/zip.h> 36 37 37 38 #define _USE_MATH_DEFINES … … 110 111 * @param pcbWritten How many bytes were written on success. 111 112 */ 112 int AudioTestTone Write(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten)113 int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten) 113 114 { 114 115 /* 115 * Clear the buffer first so we don't need to thin gabout additional channels.116 * Clear the buffer first so we don't need to think about additional channels. 116 117 */ 117 uint32_t cFrames = PDMAudioPropsBytesToFrames(&pTone->Props, cbBuf); 118 uint32_t cFrames = PDMAudioPropsBytesToFrames(&pTone->Props, cbBuf); 119 120 /* Input cbBuf not necessarily is aligned to the frames, so re-calculate it. */ 121 const uint32_t cbToWrite = PDMAudioPropsFramesToBytes(&pTone->Props, cFrames); 122 118 123 PDMAudioPropsClearBuffer(&pTone->Props, pvBuf, cbBuf, cFrames); 119 124 … … 206 211 207 212 if (pcbWritten) 208 *pcbWritten = PDMAudioPropsFramesToBytes(&pTone->Props, cFrames);213 *pcbWritten = cbToWrite; 209 214 210 215 return VINF_SUCCESS; … … 225 230 226 231 pToneParams->msPrequel = RTRandU32Ex(0, RT_MS_5SEC); 232 #ifdef DEBUG_andy 233 pToneParams->msDuration = RTRandU32Ex(0, RT_MS_1SEC); 234 #else 227 235 pToneParams->msDuration = RTRandU32Ex(0, RT_MS_10SEC); /** @todo Probably a bit too long, but let's see. */ 236 #endif 228 237 pToneParams->msSequel = RTRandU32Ex(0, RT_MS_5SEC); 229 238 pToneParams->uVolumePercent = RTRandU32Ex(0, 100); … … 246 255 int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszTag) 247 256 { 257 AssertReturn(strlen(pszTag) <= AUDIOTEST_TAG_MAX, VERR_INVALID_PARAMETER); 258 248 259 int rc; 249 260 … … 263 274 } 264 275 265 char szName[ 128];266 if (RTStrPrintf2(szName, sizeof(szName), "%s %s", AUDIOTEST_PATH_PREFIX_STR, szTag) < 0)276 char szName[RT_ELEMENTS(AUDIOTEST_PATH_PREFIX_STR) + AUDIOTEST_TAG_MAX + 4]; 277 if (RTStrPrintf2(szName, sizeof(szName), "%s-%s", AUDIOTEST_PATH_PREFIX_STR, szTag) < 0) 267 278 AssertFailedReturn(VERR_BUFFER_OVERFLOW); 268 279 … … 365 376 { 366 377 pSet->f.hFile = NIL_RTFILE; 378 379 RTListInit(&pSet->lstObj); 367 380 } 368 381 … … 510 523 int AudioTestPathCreateTemp(char *pszPath, size_t cbPath, const char *pszTag) 511 524 { 525 AssertReturn(strlen(pszTag) <= AUDIOTEST_TAG_MAX, VERR_INVALID_PARAMETER); 526 512 527 char szPath[RTPATH_MAX]; 513 528 … … 531 546 int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag) 532 547 { 548 AssertReturn(strlen(pszTag) <= AUDIOTEST_TAG_MAX, VERR_INVALID_PARAMETER); 549 533 550 int rc; 534 551 … … 596 613 597 614 pSet->enmMode = AUDIOTESTSETMODE_TEST; 615 616 rc = RTStrCopy(pSet->szTag, sizeof(pSet->szTag), pszTag); 617 AssertRCReturn(rc, rc); 598 618 } 599 619 … … 604 624 * Destroys a test set. 605 625 * 626 * @returns VBox status code. 606 627 * @param pSet Test set to destroy. 607 628 */ 608 voidAudioTestSetDestroy(PAUDIOTESTSET pSet)629 int AudioTestSetDestroy(PAUDIOTESTSET pSet) 609 630 { 610 631 if (!pSet) 611 return; 632 return VINF_SUCCESS; 633 634 int rc = VINF_SUCCESS; 635 636 PAUDIOTESTOBJ pObj, pObjNext; 637 RTListForEachSafe(&pSet->lstObj, pObj, pObjNext, AUDIOTESTOBJ, Node) 638 { 639 rc = AudioTestSetObjClose(pObj); 640 if (RT_SUCCESS(rc)) 641 { 642 RTListNodeRemove(&pObj->Node); 643 RTMemFree(pObj); 644 645 Assert(pSet->cObj); 646 pSet->cObj--; 647 } 648 else 649 break; 650 } 651 652 if (RT_FAILURE(rc)) 653 return rc; 654 655 Assert(pSet->cObj == 0); 612 656 613 657 if (RTFileIsValid(pSet->f.hFile)) … … 616 660 pSet->f.hFile = NIL_RTFILE; 617 661 } 662 663 return rc; 618 664 } 619 665 … … 661 707 662 708 /** 709 * Physically wipes all related test set files off the disk. 710 * 711 * @param pSet Test set to wipe. 712 */ 713 void AudioTestSetWipe(PAUDIOTESTSET pSet) 714 { 715 RT_NOREF(pSet); 716 } 717 718 /** 719 * Creates and registers a new audio test object to a test set. 720 * 721 * @returns VBox status code. 722 * @param pSet Test set to create and register new object for. 723 * @param pszName Name of new object to create. 724 * @param ppObj Where to return the pointer to the newly created object on success. 725 */ 726 int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj) 727 { 728 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 729 730 PAUDIOTESTOBJ pObj = (PAUDIOTESTOBJ)RTMemAlloc(sizeof(AUDIOTESTOBJ)); 731 AssertPtrReturn(pObj, VERR_NO_MEMORY); 732 733 int rc = RTStrPrintf(pObj->szName, sizeof(pObj->szName), "%04RU32-%s", pSet->cObj, pszName); 734 AssertRCReturn(rc, rc); 735 736 /** @todo Generalize this function more once we have more object types. */ 737 738 char szFilePath[RTPATH_MAX]; 739 rc = RTPathJoin(szFilePath, sizeof(szFilePath), pSet->szPathAbs, pObj->szName); 740 AssertRCReturn(rc, rc); 741 742 rc = RTFileOpen(&pObj->File.hFile, szFilePath, RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE); 743 if (RT_SUCCESS(rc)) 744 { 745 pObj->enmType = AUDIOTESTOBJTYPE_FILE; 746 747 RTListAppend(&pSet->lstObj, &pObj->Node); 748 pSet->cObj++; 749 750 *ppObj = pObj; 751 } 752 753 if (RT_FAILURE(rc)) 754 RTMemFree(pObj); 755 756 return rc; 757 } 758 759 /** 760 * Writes to a created audio test object. 761 * 762 * @returns VBox status code. 763 * @param pObj Audio test object to write to. 764 */ 765 int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf) 766 { 767 /** @todo Generalize this function more once we have more object types. */ 768 AssertReturn(pObj->enmType == AUDIOTESTOBJTYPE_FILE, VERR_INVALID_PARAMETER); 769 770 return RTFileWrite(pObj->File.hFile, pvBuf, cbBuf, NULL); 771 } 772 773 /** 774 * Closes an opened audio test object. 775 * 776 * @returns VBox status code. 777 * @param pObj Audio test object to close. 778 */ 779 int AudioTestSetObjClose(PAUDIOTESTOBJ pObj) 780 { 781 if (!pObj) 782 return VINF_SUCCESS; 783 784 /** @todo Generalize this function more once we have more object types. */ 785 AssertReturn(pObj->enmType == AUDIOTESTOBJTYPE_FILE, VERR_INVALID_PARAMETER); 786 787 int rc = VINF_SUCCESS; 788 789 if (RTFileIsValid(pObj->File.hFile)) 790 { 791 rc = RTFileClose(pObj->File.hFile); 792 pObj->File.hFile = NIL_RTFILE; 793 } 794 795 return rc; 796 } 797 798 /** 663 799 * Packs an audio test so that it's ready for transmission. 664 800 * 665 801 * @returns VBox status code. 666 802 * @param pSet Test set to pack. 667 * @param pszOutDir Where to store the packed test set. 668 */ 669 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir) 670 { 671 RT_NOREF(pSet, pszOutDir); 672 803 * @param pszOutDir Directory where to store the packed test set. 804 * @param pszFileName Where to return the final name of the packed test set. Optional and can be NULL. 805 * @param cbFileName Size (in bytes) of \a pszFileName. 806 */ 807 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName) 808 { 809 AssertReturn(!pszFileName || cbFileName, VERR_INVALID_PARAMETER); 673 810 AssertReturn(audioTestManifestIsOpen(pSet), VERR_WRONG_ORDER); 674 // RTZipTarCmd() 675 676 return VERR_NOT_IMPLEMENTED; 811 812 /** @todo Check and deny if \a pszOutDir is part of the set's path. */ 813 814 char szOutName[RT_ELEMENTS(AUDIOTEST_PATH_PREFIX_STR) + AUDIOTEST_TAG_MAX + 16]; 815 int rc = RTStrPrintf(szOutName, sizeof(szOutName), "%s-%s.tar.gz", AUDIOTEST_PATH_PREFIX_STR, pSet->szTag); 816 AssertRCReturn(rc, rc); 817 818 char szOutPath[RTPATH_MAX]; 819 rc = RTPathJoin(szOutPath, sizeof(szOutPath), pszOutDir, szOutName); 820 AssertRCReturn(rc, rc); 821 822 const char *apszArgs[10]; 823 unsigned cArgs = 0; 824 825 apszArgs[cArgs++] = "AudioTest"; 826 apszArgs[cArgs++] = "--create"; 827 apszArgs[cArgs++] = "--gzip"; 828 apszArgs[cArgs++] = "--directory"; 829 apszArgs[cArgs++] = pSet->szPathAbs; 830 apszArgs[cArgs++] = "--file"; 831 apszArgs[cArgs++] = szOutPath; 832 apszArgs[cArgs++] = "."; 833 834 RTEXITCODE rcExit = RTZipTarCmd(cArgs, (char **)apszArgs); 835 if (rcExit != RTEXITCODE_SUCCESS) 836 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 837 838 if (RT_SUCCESS(rc)) 839 { 840 if (pszFileName) 841 rc = RTStrCopy(pszFileName, cbFileName, szOutPath); 842 } 843 844 return rc; 677 845 } 678 846 -
trunk/src/VBox/Devices/Audio/AudioTest.h
r89043 r89051 24 24 #endif 25 25 26 /** @todo Some stuff here can be private-only to the implementation. */ 27 28 /** Maximum length in characters an audio test tag can have. */ 29 #define AUDIOTEST_TAG_MAX 64 30 /** Maximum length in characters a single audio test error description can have. */ 31 #define AUDIOTEST_ERROR_DESC_MAX 128 26 32 /** Prefix for audio test (set) directories. */ 27 #define AUDIOTEST_PATH_PREFIX_STR " audio-test-"33 #define AUDIOTEST_PATH_PREFIX_STR "vkat" 28 34 29 35 /** … … 131 137 typedef struct AUDIOTESTPARMS 132 138 { 133 /** Specifies the test to run. */134 uint32_t idx Test;139 /** Specifies the current test iteration. */ 140 uint32_t idxCurrent; 135 141 /** How many iterations the test should be executed. */ 136 142 uint32_t cIterations; … … 152 158 typedef AUDIOTESTPARMS *PAUDIOTESTPARMS; 153 159 160 typedef enum AUDIOTESTOBJTYPE 161 { 162 AUDIOTESTOBJTYPE_UNKNOWN = 0, 163 AUDIOTESTOBJTYPE_FILE, 164 /** The usual 32-bit hack. */ 165 AUDIOTESTOBJTYPE_32BIT_HACK = 0x7fffffff 166 } AUDIOTESTOBJTYPE; 167 168 typedef struct AUDIOTESTOBJFILE 169 { 170 RTFILE hFile; 171 } AUDIOTESTOBJFILE; 172 173 typedef struct AUDIOTESTOBJ 174 { 175 RTLISTNODE Node; 176 char szName[64]; 177 AUDIOTESTOBJTYPE enmType; 178 union 179 { 180 AUDIOTESTOBJFILE File; 181 }; 182 } AUDIOTESTOBJ; 183 /** Pointer to an audio test object. */ 184 typedef AUDIOTESTOBJ *PAUDIOTESTOBJ; 185 154 186 /** 155 187 * Structure specifying an audio test set. … … 157 189 typedef struct AUDIOTESTSET 158 190 { 191 /** The set's tag. */ 192 char szTag[AUDIOTEST_TAG_MAX]; 159 193 /** Absolute path where to store the test audio data. */ 160 194 char szPathAbs[RTPATH_MAX]; … … 166 200 RTINIFILE hIniFile; 167 201 } f; 202 uint32_t cObj; 203 RTLISTANCHOR lstObj; 168 204 } AUDIOTESTSET; 169 205 /** Pointer to an audio test set. */ … … 180 216 int rc; 181 217 /** Actual error description. */ 182 char szDesc[ 128];218 char szDesc[AUDIOTEST_ERROR_DESC_MAX]; 183 219 } AUDIOTESTERRORENTRY; 184 220 /** Pointer to an audio test error description. */ … … 201 237 202 238 double AudioTestToneInitRandom(PAUDIOTESTTONE pTone, PPDMAUDIOPCMPROPS pProps); 203 int AudioTestTone Write(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);239 int AudioTestToneGenerate(PAUDIOTESTTONE pTone, void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten); 204 240 205 241 int AudioTestToneParamsInitRandom(PAUDIOTESTTONEPARMS pToneParams, PPDMAUDIOPCMPROPS pProps); … … 208 244 int AudioTestPathCreate(char *pszPath, size_t cbPath, const char *pszUUID); 209 245 246 int AudioTestSetObjCreateAndRegister(PAUDIOTESTSET pSet, const char *pszName, PAUDIOTESTOBJ *ppObj); 247 int AudioTestSetObjWrite(PAUDIOTESTOBJ pObj, void *pvBuf, size_t cbBuf); 248 int AudioTestSetObjClose(PAUDIOTESTOBJ pObj); 249 210 250 int AudioTestSetCreate(PAUDIOTESTSET pSet, const char *pszPath, const char *pszTag); 211 voidAudioTestSetDestroy(PAUDIOTESTSET pSet);251 int AudioTestSetDestroy(PAUDIOTESTSET pSet); 212 252 int AudioTestSetOpen(PAUDIOTESTSET pSet, const char *pszPath); 213 253 void AudioTestSetClose(PAUDIOTESTSET pSet); 214 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir); 254 void AudioTestSetWipe(PAUDIOTESTSET pSet); 255 int AudioTestSetPack(PAUDIOTESTSET pSet, const char *pszOutDir, char *pszFileName, size_t cbFileName); 215 256 int AudioTestSetUnpack(const char *pszFile, const char *pszOutDir); 216 257 int AudioTestSetVerify(PAUDIOTESTSET pSet, const char *pszTag, PAUDIOTESTERRORDESC pErrDesc); -
trunk/src/VBox/Devices/Audio/DrvHostAudioDebug.cpp
r88923 r89051 264 264 265 265 uint32_t cbWritten; 266 int rc = AudioTestTone Write(&pStreamDbg->In, pvBuf, cbBuf, &cbWritten);266 int rc = AudioTestToneGenerate(&pStreamDbg->In, pvBuf, cbBuf, &cbWritten); 267 267 if (RT_SUCCESS(rc)) 268 268 {
Note:
See TracChangeset
for help on using the changeset viewer.