Changeset 89505 in vbox for trunk/src/VBox
- Timestamp:
- Jun 4, 2021 12:03:25 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioAlsa.cpp
r89504 r89505 105 105 * UINT32_MAX for unlimited logging. */ 106 106 uint32_t cLogErrors; 107 108 /** Critical section protecting the default device strings. */ 109 RTCRITSECT CritSect; 107 110 /** Default input device name. */ 108 111 char szDefaultIn[256]; 109 112 /** Default output device name. */ 110 113 char szDefaultOut[256]; 114 /** Upwards notification interface. */ 115 PPDMIHOSTAUDIOPORT pIHostAudioPort; 111 116 } DRVHSTAUDALSA; 112 117 /** Pointer to the instance data of an ALSA host audio driver. */ … … 344 349 } 345 350 return rc; 351 } 352 353 354 /** 355 * @interface_method_impl{PDMIHOSTAUDIO,pfnSetDevice} 356 */ 357 static DECLCALLBACK(int) drvHstAudAlsaHA_SetDevice(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir, const char *pszId) 358 { 359 PDRVHSTAUDALSA pThis = RT_FROM_MEMBER(pInterface, DRVHSTAUDALSA, IHostAudio); 360 361 /* 362 * Validate and normalize input. 363 */ 364 AssertReturn(enmDir == PDMAUDIODIR_IN || enmDir == PDMAUDIODIR_OUT || enmDir == PDMAUDIODIR_DUPLEX, VERR_INVALID_PARAMETER); 365 AssertPtrNullReturn(pszId, VERR_INVALID_POINTER); 366 if (!pszId || !*pszId) 367 pszId = "default"; 368 else 369 { 370 size_t cch = strlen(pszId); 371 AssertReturn(cch < sizeof(pThis->szDefaultIn), VERR_INVALID_NAME); 372 } 373 LogFunc(("enmDir=%d pszId=%s\n", enmDir, pszId)); 374 375 /* 376 * Update input. 377 */ 378 if (enmDir == PDMAUDIODIR_IN || enmDir == PDMAUDIODIR_DUPLEX) 379 { 380 int rc = RTCritSectEnter(&pThis->CritSect); 381 AssertRCReturn(rc, rc); 382 if (strcmp(pThis->szDefaultIn, pszId) == 0) 383 RTCritSectLeave(&pThis->CritSect); 384 else 385 { 386 LogRel(("ALSA: Default input device: '%s' -> '%s'\n", pThis->szDefaultIn, pszId)); 387 RTStrCopy(pThis->szDefaultIn, sizeof(pThis->szDefaultIn), pszId); 388 PPDMIHOSTAUDIOPORT pIHostAudioPort = pThis->pIHostAudioPort; 389 RTCritSectLeave(&pThis->CritSect); 390 if (pIHostAudioPort) 391 { 392 LogFlowFunc(("Notifying parent driver about input default device change...\n")); 393 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_IN, NULL /*pvUser*/); 394 } 395 } 396 } 397 398 /* 399 * Update output. 400 */ 401 if (enmDir == PDMAUDIODIR_OUT || enmDir == PDMAUDIODIR_DUPLEX) 402 { 403 int rc = RTCritSectEnter(&pThis->CritSect); 404 AssertRCReturn(rc, rc); 405 if (strcmp(pThis->szDefaultOut, pszId) == 0) 406 RTCritSectLeave(&pThis->CritSect); 407 else 408 { 409 LogRel(("ALSA: Default output device: '%s' -> '%s'\n", pThis->szDefaultOut, pszId)); 410 RTStrCopy(pThis->szDefaultOut, sizeof(pThis->szDefaultOut), pszId); 411 PPDMIHOSTAUDIOPORT pIHostAudioPort = pThis->pIHostAudioPort; 412 RTCritSectLeave(&pThis->CritSect); 413 if (pIHostAudioPort) 414 { 415 LogFlowFunc(("Notifying parent driver about output default device change...\n")); 416 pIHostAudioPort->pfnNotifyDeviceChanged(pIHostAudioPort, PDMAUDIODIR_OUT, NULL /*pvUser*/); 417 } 418 } 419 } 420 421 return VINF_SUCCESS; 346 422 } 347 423 … … 1369 1445 1370 1446 1447 /********************************************************************************************************************************* 1448 * PDMIBASE * 1449 *********************************************************************************************************************************/ 1450 1371 1451 /** 1372 1452 * @interface_method_impl{PDMIBASE,pfnQueryInterface} … … 1378 1458 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase); 1379 1459 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio); 1380 1381 1460 return NULL; 1382 1461 } 1383 1462 1384 1463 1385 /** 1386 * Construct a DirectSound Audio driver instance. 1387 * 1388 * @copydoc FNPDMDRVCONSTRUCT 1464 /********************************************************************************************************************************* 1465 * PDMDRVREG * 1466 *********************************************************************************************************************************/ 1467 1468 /** 1469 * @interface_method_impl{PDMDRVREG::pfnDestruct, 1470 * Destructs an ALSA host audio driver instance.} 1471 */ 1472 static DECLCALLBACK(void) drvHstAudAlsaDestruct(PPDMDRVINS pDrvIns) 1473 { 1474 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 1475 PDRVHSTAUDALSA pThis = PDMINS_2_DATA(pDrvIns, PDRVHSTAUDALSA); 1476 LogFlowFuncEnter(); 1477 1478 if (RTCritSectIsInitialized(&pThis->CritSect)) 1479 { 1480 RTCritSectEnter(&pThis->CritSect); 1481 pThis->pIHostAudioPort = NULL; 1482 RTCritSectLeave(&pThis->CritSect); 1483 RTCritSectDelete(&pThis->CritSect); 1484 } 1485 1486 LogFlowFuncLeave(); 1487 } 1488 1489 1490 /** 1491 * @interface_method_impl{PDMDRVREG::pfnConstruct, 1492 * Construct an ALSA host audio driver instance.} 1389 1493 */ 1390 1494 static DECLCALLBACK(int) drvHstAudAlsaConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags) … … 1399 1503 */ 1400 1504 pThis->pDrvIns = pDrvIns; 1505 int rc = RTCritSectInit(&pThis->CritSect); 1506 AssertRCReturn(rc, rc); 1401 1507 /* IBase */ 1402 1508 pDrvIns->IBase.pfnQueryInterface = drvHstAudAlsaQueryInterface; … … 1404 1510 pThis->IHostAudio.pfnGetConfig = drvHstAudAlsaHA_GetConfig; 1405 1511 pThis->IHostAudio.pfnGetDevices = drvHstAudAlsaHA_GetDevices; 1406 pThis->IHostAudio.pfnSetDevice = NULL;1512 pThis->IHostAudio.pfnSetDevice = drvHstAudAlsaHA_SetDevice; 1407 1513 pThis->IHostAudio.pfnGetStatus = drvHstAudAlsaHA_GetStatus; 1408 1514 pThis->IHostAudio.pfnDoOnWorkerThread = NULL; … … 1423 1529 * Read configuration. 1424 1530 */ 1425 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, " DefaultOutput|DefaultInput", "");1426 1427 int rc = CFGMR3QueryStringDef(pCfg, "DefaultInput", pThis->szDefaultIn, sizeof(pThis->szDefaultIn), "default");1531 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "OutputDeviceID|InputDeviceID", ""); 1532 1533 rc = CFGMR3QueryStringDef(pCfg, "InputDeviceID", pThis->szDefaultIn, sizeof(pThis->szDefaultIn), "default"); 1428 1534 AssertRCReturn(rc, rc); 1429 rc = CFGMR3QueryStringDef(pCfg, " DefaultOutput", pThis->szDefaultOut, sizeof(pThis->szDefaultOut), "default");1535 rc = CFGMR3QueryStringDef(pCfg, "OutputDeviceID", pThis->szDefaultOut, sizeof(pThis->szDefaultOut), "default"); 1430 1536 AssertRCReturn(rc, rc); 1431 1537 … … 1439 1545 return rc; 1440 1546 } 1547 1548 /* 1549 * Query the notification interface from the driver/device above us. 1550 */ 1551 pThis->pIHostAudioPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHOSTAUDIOPORT); 1552 AssertReturn(pThis->pIHostAudioPort, VERR_PDM_MISSING_INTERFACE_ABOVE); 1553 1441 1554 #ifdef DEBUG 1555 /* 1556 * Some debug stuff we don't use for anything at all. 1557 */ 1442 1558 snd_lib_error_set_handler(drvHstAudAlsaDbgErrorHandler); 1443 1559 #endif … … 1472 1588 drvHstAudAlsaConstruct, 1473 1589 /* pfnDestruct */ 1474 NULL,1590 drvHstAudAlsaDestruct, 1475 1591 /* pfnRelocate */ 1476 1592 NULL,
Note:
See TracChangeset
for help on using the changeset viewer.