Changeset 89500 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jun 4, 2021 10:30:47 AM (4 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r89489 r89500 764 764 { 765 765 char szFlags[PDMAUDIOHOSTDEV_MAX_FLAGS_STRING_LEN]; 766 LogRel(("Audio: Device '%s'%s%s%s:\n" 766 LogRel(("Audio: Device '%s':\n" 767 "Audio: ID = %s\n" 767 768 "Audio: Usage = %s\n" 768 769 "Audio: Flags = %s\n" 769 770 "Audio: Input channels = %RU8\n" 770 771 "Audio: Output channels = %RU8\n", 771 pDev-> szName, pDev->pszId ? " (ID '" : "", pDev->pszId ? pDev->pszId : "", pDev->pszId ? "')": "",772 pDev->pszName, pDev->pszId ? pDev->pszId : "", 772 773 PDMAudioDirGetName(pDev->enmUsage), PDMAudioHostDevFlagsToString(szFlags, pDev->fFlags), 773 774 pDev->cMaxInputChannels, pDev->cMaxOutputChannels)); -
trunk/src/VBox/Devices/Audio/DrvHostAudioAlsa.cpp
r89488 r89500 244 244 char * const pszDesc = snd_device_name_get_hint(pszHint, "DESC"); 245 245 246 if (pszDev && RTStrICmp (pszDev, "null") != 0)246 if (pszDev && RTStrICmpAscii(pszDev, "null") != 0) 247 247 { 248 248 /* Detect and log presence of pulse audio plugin. */ … … 252 252 /* 253 253 * Add an entry to the enumeration result. 254 * We engage in some trickery here to deal with device names that 255 * are more than 63 characters long. 254 256 */ 255 PPDMAUDIOHOSTDEV pDev = PDMAudioHostDevAlloc(sizeof(*pDev)); 257 size_t const cbId = pszDev ? strlen(pszDev) + 1 : 1; 258 size_t const cbName = pszDesc ? strlen(pszDesc) + 2 + 1 : cbId; 259 PPDMAUDIOHOSTDEV pDev = PDMAudioHostDevAlloc(sizeof(*pDev), cbName, cbId); 256 260 if (pDev) 257 261 { 258 pDev->fFlags = PDMAUDIOHOSTDEV_F_NONE; 259 pDev->enmType = PDMAUDIODEVICETYPE_UNKNOWN; 260 261 if (pszInOutId == NULL) 262 RTStrCopy(pDev->pszId, cbId, pszDev); 263 if (pDev->pszId) 262 264 { 263 pDev->enmUsage = PDMAUDIODIR_DUPLEX; 264 pDev->cMaxInputChannels = 2; 265 pDev->cMaxOutputChannels = 2; 266 } 267 else if (RTStrICmp(pszInOutId, "Input") == 0) 268 { 269 pDev->enmUsage = PDMAUDIODIR_IN; 270 pDev->cMaxInputChannels = 2; 271 pDev->cMaxOutputChannels = 0; 265 pDev->fFlags = PDMAUDIOHOSTDEV_F_NONE; 266 pDev->enmType = PDMAUDIODEVICETYPE_UNKNOWN; 267 268 if (pszInOutId == NULL) 269 { 270 pDev->enmUsage = PDMAUDIODIR_DUPLEX; 271 pDev->cMaxInputChannels = 2; 272 pDev->cMaxOutputChannels = 2; 273 } 274 else if (RTStrICmpAscii(pszInOutId, "Input") == 0) 275 { 276 pDev->enmUsage = PDMAUDIODIR_IN; 277 pDev->cMaxInputChannels = 2; 278 pDev->cMaxOutputChannels = 0; 279 } 280 else 281 { 282 AssertMsg(RTStrICmpAscii(pszInOutId, "Output") == 0, ("%s (%s)\n", pszInOutId, pszHint)); 283 pDev->enmUsage = PDMAUDIODIR_OUT; 284 pDev->cMaxInputChannels = 0; 285 pDev->cMaxOutputChannels = 2; 286 } 287 288 if (pszDesc && *pszDesc) 289 { 290 char *pszDesc2 = strchr(pszDesc, '\n'); 291 if (!pszDesc2) 292 RTStrCopy(pDev->pszName, cbName, pszDesc); 293 else 294 { 295 *pszDesc2++ = '\0'; 296 char *psz; 297 while ((psz = strchr(pszDesc2, '\n')) != NULL) 298 *psz = ' '; 299 RTStrPrintf(pDev->pszName, cbName, "%s (%s)", pszDesc2, pszDesc); 300 } 301 } 302 else 303 RTStrCopy(pDev->pszName, cbName, pszDev); 304 305 PDMAudioHostEnumAppend(pDeviceEnum, pDev); 306 307 LogRel2(("ALSA: Device #%u: '%s' enmDir=%s: %s\n", iHint, pszDev, 308 PDMAudioDirGetName(pDev->enmUsage), pszDesc)); 272 309 } 273 310 else 274 311 { 275 AssertMsg(RTStrICmp(pszInOutId, "Output") == 0, ("%s (%s)\n", pszInOutId, pszHint)); 276 pDev->enmUsage = PDMAUDIODIR_OUT; 277 pDev->cMaxInputChannels = 0; 278 pDev->cMaxOutputChannels = 2; 312 PDMAudioHostDevFree(pDev); 313 rc = VERR_NO_STR_MEMORY; 279 314 } 280 281 int rc2 = RTStrCopy(pDev->szName, sizeof(pDev->szName), pszDev);282 AssertRC(rc2);283 284 PDMAudioHostEnumAppend(pDeviceEnum, pDev);285 286 LogRel2(("ALSA: Device #%u: '%s' enmDir=%s: %s\n", iHint, pszDev,287 PDMAudioDirGetName(pDev->enmUsage), pszDesc));288 315 } 289 316 else -
trunk/src/VBox/Devices/Audio/DrvHostAudioCoreAudio.cpp
r89487 r89500 1260 1260 kAudioObjectPropertyElementMaster, "device name", &hStrName, sizeof(hStrName))) 1261 1261 { 1262 drvHstAudCaCFStringToBuf(hStrName, pDevEntry->Core.szName, sizeof(pDevEntry->Core.szName)); 1262 pDevEntry->Core.pszName = drvHstAudCaCFStringToHeap(hStrName); 1263 pDevEntry->Core.fFlags |= PDMAUDIOHOSTDEV_F_NAME_ALLOC; 1263 1264 CFRelease(hStrName); 1264 1265 } … … 1291 1292 1292 1293 /* 1293 * Add the device to the enumeration.1294 * Try make sure we've got a name... Only add it to the enumeration if we have one. 1294 1295 */ 1295 PDMAudioHostEnumAppend(pDevEnm, &pDevEntry->Core); 1296 if (!pDevEntry->Core.pszName) 1297 { 1298 pDevEntry->Core.pszName = pDevEntry->Core.pszId; 1299 pDevEntry->Core.fFlags &= ~PDMAUDIOHOSTDEV_F_NAME_ALLOC; 1300 } 1301 1302 if (pDevEntry->Core.pszName) 1303 PDMAudioHostEnumAppend(pDevEnm, &pDevEntry->Core); 1304 else 1305 PDMAudioHostDevFree(&pDevEntry->Core); 1296 1306 } 1297 1307 -
trunk/src/VBox/Devices/Audio/DrvHostAudioDSound.cpp
r89487 r89500 801 801 802 802 int rc; 803 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV)); 803 size_t const cbName = RTUtf16CalcUtf8Len(pwszDescription) + 1; 804 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV), cbName, 0); 804 805 if (pDev) 805 806 { … … 810 811 pDev->Core.fFlags = PDMAUDIOHOSTDEV_F_DEFAULT_OUT; 811 812 812 char *pszName; 813 rc = RTUtf16ToUtf8(pwszDescription, &pszName); 813 rc = RTUtf16ToUtf8Ex(pwszDescription, RTSTR_MAX, &pDev->Core.pszName, cbName, NULL); 814 814 if (RT_SUCCESS(rc)) 815 815 { 816 RTStrCopy(pDev->Core.szName, sizeof(pDev->Core.szName), pszName);817 RTStrFree(pszName);818 819 816 if (!pGUID) 820 817 pDev->Core.fFlags |= PDMAUDIOHOSTDEV_F_DEFAULT_OUT; … … 869 866 870 867 int rc; 871 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV)); 868 size_t const cbName = RTUtf16CalcUtf8Len(pwszDescription) + 1; 869 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV), cbName, 0); 872 870 if (pDev) 873 871 { … … 875 873 pDev->Core.enmType = PDMAUDIODEVICETYPE_BUILTIN; 876 874 877 char *pszName; 878 rc = RTUtf16ToUtf8(pwszDescription, &pszName); 875 rc = RTUtf16ToUtf8Ex(pwszDescription, RTSTR_MAX, &pDev->Core.pszName, cbName, NULL); 879 876 if (RT_SUCCESS(rc)) 880 877 { 881 RTStrCopy(pDev->Core.szName, sizeof(pDev->Core.szName), pszName);882 RTStrFree(pszName);883 884 878 if (!pGUID) 885 879 pDev->Core.fFlags |= PDMAUDIOHOSTDEV_F_DEFAULT_IN; … … 1052 1046 * Create a enumeration entry for it. 1053 1047 */ 1054 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV)); 1048 size_t const cbName = RTUtf16CalcUtf8Len(VarName.pwszVal) + 1; 1049 PDSOUNDDEV pDev = (PDSOUNDDEV)PDMAudioHostDevAlloc(sizeof(DSOUNDDEV), cbName, 0); 1055 1050 if (pDev) 1056 1051 { … … 1073 1068 pDev->Core.pszId = &pDev->szGuid[0]; 1074 1069 1075 char *pszName; 1076 rc = RTUtf16ToUtf8(VarName.pwszVal, &pszName); 1070 rc = RTUtf16ToUtf8Ex(VarName.pwszVal, RTSTR_MAX, &pDev->Core.pszName, cbName, NULL); 1077 1071 if (RT_SUCCESS(rc)) 1078 {1079 RTStrCopy(pDev->Core.szName, sizeof(pDev->Core.szName), pszName);1080 RTStrFree(pszName);1081 1082 1072 PDMAudioHostEnumAppend(pDevEnm, &pDev->Core); 1083 }1084 1073 else 1085 1074 PDMAudioHostDevFree(&pDev->Core); -
trunk/src/VBox/Devices/Audio/DrvHostAudioPulseAudio.cpp
r89487 r89500 118 118 /** The part we share with others. */ 119 119 PDMAUDIOHOSTDEV Core; 120 /** The pulse audio name.121 * @note Kind of must use fixed size field here as that allows122 * PDMAudioHostDevDup() and PDMAudioHostEnumCopy() to work. */123 RT_FLEXIBLE_ARRAY_EXTENSION124 char szPulseName[RT_FLEXIBLE_ARRAY];125 120 } DRVHSTAUDPADEVENTRY; 126 121 /** Pointer to a pulse audio device enumeration entry. */ … … 401 396 */ 402 397 static void drvHstAudPaEnumAddDevice(PDRVHSTAUDPAENUMCBCTX pCbCtx, PDMAUDIODIR enmDir, const char *pszName, 403 404 405 { 406 size_t const c chName = strlen(pszName);407 PDRVHSTAUDPADEVENTRY pDev = (PDRVHSTAUDPADEVENTRY)PDMAudioHostDevAlloc(RT_UOFFSETOF(DRVHSTAUDPADEVENTRY, szPulseName)408 + RT_ALIGN_Z(cchName + 1, 16));398 const char *pszDesc, uint8_t cChannelsInput, uint8_t cChannelsOutput, 399 const char *pszDefaultName) 400 { 401 size_t const cbId = strlen(pszName) + 1; 402 size_t const cbName = pszDesc && *pszDesc ? strlen(pszDesc) + 1 : cbId; 403 PDRVHSTAUDPADEVENTRY pDev = (PDRVHSTAUDPADEVENTRY)PDMAudioHostDevAlloc(sizeof(*pDev), cbName, cbId); 409 404 if (pDev != NULL) 410 405 { 411 memcpy(pDev->szPulseName, pszName, cchName);412 pDev->szPulseName[cchName] = '\0';413 414 406 pDev->Core.enmUsage = enmDir; 415 407 pDev->Core.enmType = RTStrIStr(pszDesc, "built-in") != NULL … … 421 413 pDev->Core.cMaxInputChannels = cChannelsInput; 422 414 pDev->Core.cMaxOutputChannels = cChannelsOutput; 423 RTStrCopy(pDev->Core.szName, sizeof(pDev->Core.szName), 424 pszDesc && *pszDesc ? pszDesc : pszName); 415 416 int rc = RTStrCopy(pDev->Core.pszId, cbId, pszName); 417 AssertRC(rc); 418 419 rc = RTStrCopy(pDev->Core.pszName, cbName, pszDesc && *pszDesc ? pszDesc : pszName); 420 AssertRC(rc); 425 421 426 422 PDMAudioHostEnumAppend(pCbCtx->pDeviceEnum, &pDev->Core); … … 456 452 pInfo->name, pInfo->description, pInfo->driver, pInfo->flags)); 457 453 drvHstAudPaEnumAddDevice(pCbCtx, PDMAUDIODIR_IN, pInfo->name, pInfo->description, 458 454 pInfo->sample_spec.channels, 0 /*cChannelsOutput*/, pCbCtx->pszDefaultSource); 459 455 } 460 456 else if (eol == 1 && !pInfo && pCbCtx->rcEnum == VERR_AUDIO_ENUMERATION_FAILED) -
trunk/src/VBox/Devices/Audio/DrvHostAudioWasApi.cpp
r89491 r89500 1525 1525 * Create a enumeration entry for it. 1526 1526 */ 1527 size_t const cbDev = RT_ALIGN_Z( RT_OFFSETOF(DRVHOSTAUDIOWASDEV, wszDevId) 1528 + (cwcDevId + 1) * sizeof(RTUTF16), 1529 64); 1530 PDRVHOSTAUDIOWASDEV pDev = (PDRVHOSTAUDIOWASDEV)PDMAudioHostDevAlloc(cbDev); 1527 size_t const cbId = RTUtf16CalcUtf8Len(pwszDevId) + 1; 1528 size_t const cbName = RTUtf16CalcUtf8Len(VarName.pwszVal) + 1; 1529 size_t const cbDev = RT_ALIGN_Z( RT_OFFSETOF(DRVHOSTAUDIOWASDEV, wszDevId) 1530 + (cwcDevId + 1) * sizeof(RTUTF16), 1531 64); 1532 PDRVHOSTAUDIOWASDEV pDev = (PDRVHOSTAUDIOWASDEV)PDMAudioHostDevAlloc(cbDev, cbName, cbId); 1531 1533 if (pDev) 1532 1534 { … … 1543 1545 pDev->wszDevId[cwcDevId] = '\0'; 1544 1546 1545 char *pszName;1546 rc = RTUtf16ToUtf8 (VarName.pwszVal, &pszName);1547 Assert(pDev->Core.pszName); 1548 rc = RTUtf16ToUtf8Ex(VarName.pwszVal, RTSTR_MAX, &pDev->Core.pszName, cbName, NULL); 1547 1549 if (RT_SUCCESS(rc)) 1548 1550 { 1549 RTStrCopy(pDev->Core.szName, sizeof(pDev->Core.szName), pszName); 1550 RTStrFree(pszName); 1551 1552 rc = RTUtf16ToUtf8(pDev->wszDevId, &pDev->Core.pszId); 1551 Assert(pDev->Core.pszId); 1552 rc = RTUtf16ToUtf8Ex(pDev->wszDevId, RTSTR_MAX, &pDev->Core.pszId, cbId, NULL); 1553 1553 if (RT_SUCCESS(rc)) 1554 {1555 pDev->Core.fFlags |= PDMAUDIOHOSTDEV_F_ID_ALLOC;1556 1554 PDMAudioHostEnumAppend(pDevEnm, &pDev->Core); 1557 }1558 1555 else 1559 1556 PDMAudioHostDevFree(&pDev->Core);
Note:
See TracChangeset
for help on using the changeset viewer.