VirtualBox

Changeset 88044 in vbox


Ignore:
Timestamp:
Mar 9, 2021 1:18:37 PM (4 years ago)
Author:
vboxsync
Message:

Audio: More prep work to move the audio device enumeration code to PDM. bugref:9890

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r88041 r88044  
    352352/**
    353353 * Audio device info (enumeration result).
    354  * @sa PDMAUDIODEVICEENUM, PDMIHOSTAUDIO::pfnGetDevices
     354 * @sa PDMAUDIOHOSTENUM, PDMIHOSTAUDIO::pfnGetDevices
    355355 */
    356356typedef struct PDMAUDIODEVICE
    357357{
    358     /** List entry (like PDMAUDIODEVICEENUM::LstDevices). */
     358    /** List entry (like PDMAUDIOHOSTENUM::LstDevices). */
    359359    RTLISTNODE          Node;
    360360    /** Magic value (PDMAUDIODEVICE_MAGIC). */
     
    404404
    405405/**
    406  * An audio device enumeration result.
     406 * A host audio device enumeration result.
    407407 *
    408408 * @sa PDMIHOSTAUDIO::pfnGetDevices
    409409 */
    410 typedef struct PDMAUDIODEVICEENUM
    411 {
     410typedef struct PDMAUDIOHOSTENUM
     411{
     412    /** Magic value (PDMAUDIOHOSTENUM_MAGIC). */
     413    uint32_t        uMagic;
     414    /** Number of audio devices in the list. */
     415    uint32_t        cDevices;
    412416    /** List of audio devices (PDMAUDIODEVICE). */
    413417    RTLISTANCHOR    LstDevices;
    414     /** Number of audio devices in the list. */
    415     uint32_t        cDevices;
    416 } PDMAUDIODEVICEENUM;
     418} PDMAUDIOHOSTENUM;
    417419/** Pointer to an audio device enumeration result. */
    418 typedef PDMAUDIODEVICEENUM *PPDMAUDIODEVICEENUM;
     420typedef PDMAUDIOHOSTENUM *PPDMAUDIOHOSTENUM;
    419421/** Pointer to a const audio device enumeration result. */
    420 typedef PDMAUDIODEVICEENUM const *PCPDMAUDIODEVICEENUM;
     422typedef PDMAUDIOHOSTENUM const *PCPDMAUDIOHOSTENUM;
     423
     424/** Magic for the host audio device enumeration. (Herbert Jeffrey "Herbie" Hancock) */
     425#define PDMAUDIOHOSTENUM_MAGIC      UINT32_C(0x19400412)
     426
    421427
    422428/**
     
    16521658     * @param   pDeviceEnum         Where to return the enumerated audio devices.
    16531659     */
    1654     DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
     1660    DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum));
    16551661
    16561662    /**
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r88031 r88044  
    5151*********************************************************************************************************************************/
    5252#ifdef VBOX_WITH_AUDIO_ENUM
    53 static int drvAudioDevicesEnumerateInternal(PDRVAUDIO pThis, bool fLog, PPDMAUDIODEVICEENUM pDevEnum);
     53static int drvAudioDevicesEnumerateInternal(PDRVAUDIO pThis, bool fLog, PPDMAUDIOHOSTENUM pDevEnum);
    5454#endif
    5555
     
    21532153 * @param   pDevEnum            Where to store the device enumeration.
    21542154 */
    2155 static int drvAudioDevicesEnumerateInternal(PDRVAUDIO pThis, bool fLog, PPDMAUDIODEVICEENUM pDevEnum)
     2155static int drvAudioDevicesEnumerateInternal(PDRVAUDIO pThis, bool fLog, PPDMAUDIOHOSTENUM pDevEnum)
    21562156{
    21572157    AssertReturn(RTCritSectIsOwned(&pThis->CritSect) == false, VERR_WRONG_ORDER);
     
    21642164    if (pThis->pHostDrvAudio->pfnGetDevices)
    21652165    {
    2166         PDMAUDIODEVICEENUM DevEnum;
     2166        PDMAUDIOHOSTENUM DevEnum;
    21672167        rc = pThis->pHostDrvAudio->pfnGetDevices(pThis->pHostDrvAudio, &DevEnum);
    21682168        if (RT_SUCCESS(rc))
     
    21902190
    21912191            if (pDevEnum)
    2192                 rc = DrvAudioHlpDeviceEnumCopy(pDevEnum, &DevEnum);
    2193 
    2194             DrvAudioHlpDeviceEnumFree(&DevEnum);
     2192                rc = PDMAudioHostEnumCopy(pDevEnum, &DevEnum, PDMAUDIODIR_INVALID /*all*/, true /*fOnlyCoreData*/);
     2193
     2194            PDMAudioHostEnumDelete(&DevEnum);
    21952195        }
    21962196        else
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r88041 r88044  
    211211PPDMAUDIODEVICE PDMAudioDeviceAlloc(size_t cb);
    212212void            PDMAudioDeviceFree(PPDMAUDIODEVICE pDev);
    213 PPDMAUDIODEVICE PDMAudioDeviceDup(const PPDMAUDIODEVICE pDev, bool fCopyUserData);
     213PPDMAUDIODEVICE PDMAudioDeviceDup(const PPDMAUDIODEVICE pDev, bool fOnlyCoreData);
    214214/** @}  */
    215215
    216216/** @name Audio device enumeration methods.
    217217 * @{ */
    218 int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
    219 void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
    220 int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
    221 /*PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm); - unused */
    222 int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, PCPDMAUDIODEVICEENUM pSrcDevEnm);
    223 int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, PCPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage, bool fCopyUserData);
    224 PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(PCPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
    225 uint32_t    DrvAudioHlpDeviceEnumGetDeviceCount(PCPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmUsage);
    226 void        DrvAudioHlpDeviceEnumLog(PCPDMAUDIODEVICEENUM pDevEnm, const char *pszDesc);
     218void            PDMAudioHostEnumInit(PPDMAUDIOHOSTENUM pDevEnm);
     219void            PDMAudioHostEnumDelete(PPDMAUDIOHOSTENUM pDevEnm);
     220void            PDMAudioHostEnumAppend(PPDMAUDIOHOSTENUM pDevEnm, PPDMAUDIODEVICE pDev);
     221int             PDMAudioHostEnumCopy(PPDMAUDIOHOSTENUM pDstDevEnm, PCPDMAUDIOHOSTENUM pSrcDevEnm,
     222                                     PDMAUDIODIR enmUsage, bool fOnlyCoreData);
     223PPDMAUDIODEVICE PDMAudioHostEnumGetDefault(PCPDMAUDIOHOSTENUM pDevEnm, PDMAUDIODIR enmDir);
     224uint32_t        PDMAudioHostEnumCountMatching(PCPDMAUDIOHOSTENUM pDevEnm, PDMAUDIODIR enmUsage);
     225void            PDMAudioHostEnumLog(PCPDMAUDIOHOSTENUM pDevEnm, const char *pszDesc);
    227226/** @}  */
    228227
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r88041 r88044  
    193193 * @returns Duplicated audio device entry on success, or NULL on failure.
    194194 * @param   pDev            The audio device enum entry to duplicate.
    195  * @param   fCopyUserData   Whether to also copy the user data portion or not.
    196  */
    197 PPDMAUDIODEVICE PDMAudioDeviceDup(PPDMAUDIODEVICE pDev, bool fCopyUserData)
     195 * @param   fOnlyCoreData
     196 */
     197PPDMAUDIODEVICE PDMAudioDeviceDup(PPDMAUDIODEVICE pDev, bool fOnlyCoreData)
    198198{
    199199    AssertPtrReturn(pDev, NULL);
    200200    Assert(pDev->uMagic == PDMAUDIODEVICE_MAGIC);
    201     Assert(!fCopyUserData || !(pDev->fFlags & PDMAUDIODEV_FLAGS_NO_DUP));
    202 
    203     uint32_t cbToDup = fCopyUserData ? pDev->cbSelf : sizeof(PDMAUDIODEVICE);
     201    Assert(fOnlyCoreData || !(pDev->fFlags & PDMAUDIODEV_FLAGS_NO_DUP));
     202
     203    uint32_t cbToDup = fOnlyCoreData ? sizeof(PDMAUDIODEVICE) : pDev->cbSelf;
    204204    AssertReturn(cbToDup >= sizeof(*pDev), NULL);
    205205
     
    216216
    217217/**
    218  * Initializes an audio device enumeration structure.
    219  *
    220  * @returns IPRT status code.
    221  * @param   pDevEnm             Device enumeration to initialize.
    222  */
    223 int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm)
    224 {
    225     AssertPtrReturn(pDevEnm, VERR_INVALID_POINTER);
    226 
     218 * Initializes a host audio device enumeration.
     219 *
     220 * @param   pDevEnm     The enumeration to initialize.
     221 */
     222void PDMAudioHostEnumInit(PPDMAUDIOHOSTENUM pDevEnm)
     223{
     224    AssertPtr(pDevEnm);
     225
     226    pDevEnm->uMagic   = PDMAUDIOHOSTENUM_MAGIC;
     227    pDevEnm->cDevices = 0;
    227228    RTListInit(&pDevEnm->LstDevices);
    228     pDevEnm->cDevices = 0;
    229 
    230     return VINF_SUCCESS;
    231 }
    232 
    233 /**
    234  * Frees audio device enumeration data.
    235  *
    236  * @param pDevEnm               Device enumeration to destroy.
    237  */
    238 void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm)
    239 {
    240     if (!pDevEnm)
    241         return;
    242 
    243     PPDMAUDIODEVICE pDev, pDevNext;
    244     RTListForEachSafe(&pDevEnm->LstDevices, pDev, pDevNext, PDMAUDIODEVICE, Node)
    245     {
    246         RTListNodeRemove(&pDev->Node);
    247 
    248         PDMAudioDeviceFree(pDev);
    249 
    250         pDevEnm->cDevices--;
    251     }
    252 
    253     /* Sanity. */
    254     Assert(RTListIsEmpty(&pDevEnm->LstDevices));
    255     Assert(pDevEnm->cDevices == 0);
     229}
     230
     231/**
     232 * Deletes the host audio device enumeration and frees all device entries
     233 * associated with it.
     234 *
     235 * The user must call PDMAudioHostEnumInit again to use it again.
     236 *
     237 * @param   pDevEnm     The host audio device enumeration to delete.
     238 */
     239void PDMAudioHostEnumDelete(PPDMAUDIOHOSTENUM pDevEnm)
     240{
     241    if (pDevEnm)
     242    {
     243        AssertPtr(pDevEnm);
     244        AssertReturnVoid(pDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC);
     245
     246        PPDMAUDIODEVICE pDev, pDevNext;
     247        RTListForEachSafe(&pDevEnm->LstDevices, pDev, pDevNext, PDMAUDIODEVICE, Node)
     248        {
     249            RTListNodeRemove(&pDev->Node);
     250
     251            PDMAudioDeviceFree(pDev);
     252
     253            pDevEnm->cDevices--;
     254        }
     255
     256        /* Sanity. */
     257        Assert(RTListIsEmpty(&pDevEnm->LstDevices));
     258        Assert(pDevEnm->cDevices == 0);
     259
     260        pDevEnm->uMagic = ~PDMAUDIOHOSTENUM_MAGIC;
     261    }
    256262}
    257263
     
    259265 * Adds an audio device to a device enumeration.
    260266 *
    261  * @return IPRT status code.
    262267 * @param  pDevEnm              Device enumeration to add device to.
    263268 * @param  pDev                 Device to add. The pointer will be owned by the device enumeration  then.
    264269 */
    265 int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev)
    266 {
    267     AssertPtrReturn(pDevEnm, VERR_INVALID_POINTER);
    268     AssertPtrReturn(pDev,    VERR_INVALID_POINTER);
     270void PDMAudioHostEnumAppend(PPDMAUDIOHOSTENUM pDevEnm, PPDMAUDIODEVICE pDev)
     271{
     272    AssertPtr(pDevEnm);
     273    AssertPtr(pDev);
     274    Assert(pDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC);
    269275
    270276    RTListAppend(&pDevEnm->LstDevices, &pDev->Node);
    271277    pDevEnm->cDevices++;
    272 
    273     return VINF_SUCCESS;
    274 }
    275 
    276 #if 0 /* unused, duplicated by copy  */
    277 /**
    278  * Duplicates a device enumeration.
    279  *
    280  * @returns Duplicated device enumeration, or NULL on failure.
    281  *          Must be free'd with DrvAudioHlpDeviceEnumFree().
    282  * @param   pDevEnm             Device enumeration to duplicate.
    283  */
    284 PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm)
    285 {
    286     AssertPtrReturn(pDevEnm, NULL);
    287 
    288     PPDMAUDIODEVICEENUM pDevEnmDup = (PPDMAUDIODEVICEENUM)RTMemAlloc(sizeof(PDMAUDIODEVICEENUM));
    289     if (!pDevEnmDup)
    290         return NULL;
    291 
    292     int rc2 = DrvAudioHlpDeviceEnumInit(pDevEnmDup);
    293     AssertRC(rc2);
    294 
    295     PPDMAUDIODEVICE pDev;
    296     RTListForEach(&pDevEnm->LstDevices, pDev, PDMAUDIODEVICE, Node)
    297     {
    298         PPDMAUDIODEVICE pDevDup = PDMAudioDeviceDup(pDev, true /* fCopyUserData */);
    299         if (!pDevDup)
    300         {
    301             rc2 = VERR_NO_MEMORY;
    302             break;
    303         }
    304 
    305         rc2 = DrvAudioHlpDeviceEnumAdd(pDevEnmDup, pDevDup);
    306         if (RT_FAILURE(rc2))
    307         {
    308             PDMAudioDeviceFree(pDevDup);
    309             break;
    310         }
    311     }
    312 
    313     if (RT_FAILURE(rc2))
    314     {
    315         DrvAudioHlpDeviceEnumFree(pDevEnmDup);
    316         pDevEnmDup = NULL;
    317     }
    318 
    319     return pDevEnmDup;
    320 }
    321 #endif /* unused */
    322 
    323 /**
    324  * Copies device enumeration entries from the source to the destination enumeration.
     278}
     279
     280/**
     281 * Appends copies of matching host device entries from one to another enumeration.
    325282 *
    326283 * @returns IPRT status code.
    327  * @param   pDstDevEnm          Destination enumeration to store enumeration entries into.
    328  * @param   pSrcDevEnm          Source enumeration to use.
    329  * @param   enmUsage            The usage to match for copying.  Use
    330  *                              PDMAUDIODIR_INVALID to match all entries.
    331  * @param   fCopyUserData       Whether to also copy the user data portion or not.
    332  */
    333 int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, PCPDMAUDIODEVICEENUM pSrcDevEnm,
    334                                 PDMAUDIODIR enmUsage, bool fCopyUserData)
     284 * @param   pDstDevEnm      The target to append copies of matching device to.
     285 * @param   pSrcDevEnm      The source to copy matching devices from.
     286 * @param   enmUsage        The usage to match for copying.
     287 *                          Use PDMAUDIODIR_INVALID to match all entries.
     288 * @param   fOnlyCoreData   Set this to only copy the PDMAUDIODEVICE part.
     289 *                          Careful with passing @c false here as not all
     290 *                          backends have data that can be copied.
     291 */
     292int PDMAudioHostEnumCopy(PPDMAUDIOHOSTENUM pDstDevEnm, PCPDMAUDIOHOSTENUM pSrcDevEnm,
     293                         PDMAUDIODIR enmUsage, bool fOnlyCoreData)
    335294{
    336295    AssertPtrReturn(pDstDevEnm, VERR_INVALID_POINTER);
     296    AssertReturn(pDstDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC, VERR_WRONG_ORDER);
     297
    337298    AssertPtrReturn(pSrcDevEnm, VERR_INVALID_POINTER);
     299    AssertReturn(pSrcDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC, VERR_WRONG_ORDER);
    338300
    339301    PPDMAUDIODEVICE pSrcDev;
     
    343305            || enmUsage == PDMAUDIODIR_INVALID /*all*/)
    344306        {
    345             PPDMAUDIODEVICE pDstDev = PDMAudioDeviceDup(pSrcDev, fCopyUserData);
     307            PPDMAUDIODEVICE pDstDev = PDMAudioDeviceDup(pSrcDev, fOnlyCoreData);
    346308            AssertReturn(pDstDev, VERR_NO_MEMORY);
    347309
    348             int rc = DrvAudioHlpDeviceEnumAdd(pDstDevEnm, pDstDev);
    349             AssertRCReturnStmt(rc, PDMAudioDeviceFree(pDstDev), VERR_NO_MEMORY);
     310            PDMAudioHostEnumAppend(pDstDevEnm, pDstDev);
    350311        }
    351312    }
    352313
    353314    return VINF_SUCCESS;
    354 }
    355 
    356 /**
    357  * Copies all device enumeration entries from the source to the destination enumeration.
    358  *
    359  * @note Does *not* copy the user-specific data assigned to a device enumeration
    360  *       entry. To do so, use DrvAudioHlpDeviceEnumCopyEx().
    361  *
    362  * @returns IPRT status code.
    363  * @param   pDstDevEnm          Destination enumeration to store enumeration entries into.
    364  * @param   pSrcDevEnm          Source enumeration to use.
    365  */
    366 int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, PCPDMAUDIODEVICEENUM pSrcDevEnm)
    367 {
    368     return DrvAudioHlpDeviceEnumCopyEx(pDstDevEnm, pSrcDevEnm, PDMAUDIODIR_INVALID /*all*/, false /* fCopyUserData */);
    369315}
    370316
     
    381327 *                      PDMAUDIODEV_FLAGS_DEFAULT set.
    382328 */
    383 PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(PCPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmUsage)
     329PPDMAUDIODEVICE PDMAudioHostEnumGetDefault(PCPDMAUDIOHOSTENUM pDevEnm, PDMAUDIODIR enmUsage)
    384330{
    385331    AssertPtrReturn(pDevEnm, NULL);
     332    AssertReturn(pDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC, NULL);
    386333
    387334    PPDMAUDIODEVICE pDev;
     
    391338        {
    392339            if (   enmUsage == pDev->enmUsage
    393                 || enmUsage  == PDMAUDIODIR_INVALID)
     340                || enmUsage == PDMAUDIODIR_INVALID)
    394341                return pDev;
    395342        }
     
    407354 *                      Pass PDMAUDIODIR_INVALID to get the total number of devices.
    408355 */
    409 uint32_t DrvAudioHlpDeviceEnumGetDeviceCount(PCPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmUsage)
     356uint32_t PDMAudioHostEnumCountMatching(PCPDMAUDIOHOSTENUM pDevEnm, PDMAUDIODIR enmUsage)
    410357{
    411358    AssertPtrReturn(pDevEnm, 0);
     359    AssertReturn(pDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC, 0);
    412360
    413361    if (enmUsage == PDMAUDIODIR_INVALID)
     
    431379 * @param  pszDesc  Logging description (prefix).
    432380 */
    433 void DrvAudioHlpDeviceEnumLog(PCPDMAUDIODEVICEENUM pDevEnm, const char *pszDesc)
    434 {
     381void PDMAudioHostEnumLog(PCPDMAUDIOHOSTENUM pDevEnm, const char *pszDesc)
     382{
     383    AssertPtrReturnVoid(pDevEnm);
    435384    AssertPtrReturnVoid(pszDesc);
    436     AssertPtrReturnVoid(pDevEnm);
     385    AssertReturnVoid(pDevEnm->uMagic == PDMAUDIOHOSTENUM_MAGIC);
    437386
    438387    LogFunc(("%s: %RU32 devices\n", pszDesc, pDevEnm->cDevices));
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r88042 r88044  
    100100    RTCRITSECT              CritSect;
    101101    /** Current (last reported) device enumeration. */
    102     PDMAUDIODEVICEENUM      Devices;
     102    PDMAUDIOHOSTENUM      Devices;
    103103    /** Pointer to the currently used input device in the device enumeration.
    104104     *  Can be NULL if none assigned. */
     
    487487 * @param   pDevEnm             Where to store the enumerated devices.
    488488 */
    489 static int coreAudioDevicesEnumerate(PDRVHOSTCOREAUDIO pThis, PDMAUDIODIR enmUsage, PPDMAUDIODEVICEENUM pDevEnm)
     489static int coreAudioDevicesEnumerate(PDRVHOSTCOREAUDIO pThis, PDMAUDIODIR enmUsage, PPDMAUDIOHOSTENUM pDevEnm)
    490490{
    491491    AssertPtrReturn(pThis,   VERR_INVALID_POINTER);
     
    533533            break;
    534534
    535         rc = DrvAudioHlpDeviceEnumInit(pDevEnm);
    536         if (RT_FAILURE(rc))
    537             break;
     535        PDMAudioHostEnumInit(pDevEnm);
    538536
    539537        UInt16 cDevices = uSize / sizeof(AudioDeviceID);
     
    663661
    664662            /* Add the device to the enumeration. */
    665             rc = DrvAudioHlpDeviceEnumAdd(pDevEnm, &pDev->Core);
    666             if (RT_FAILURE(rc))
    667                 break;
     663            PDMAudioHostEnumAppend(pDevEnm, &pDev->Core);
    668664
    669665            /* NULL device pointer because it's now part of the device enumeration. */
     
    683679#ifdef LOG_ENABLED
    684680        LogFunc(("Devices for pDevEnm=%p, enmUsage=%RU32:\n", pDevEnm, enmUsage));
    685         DrvAudioHlpDeviceEnumLog(pDevEnm, "Core Audio");
     681        PDMAudioHostEnumLog(pDevEnm, "Core Audio");
    686682#endif
    687683    }
    688684    else
    689         DrvAudioHlpDeviceEnumFree(pDevEnm);
     685        PDMAudioHostEnumDelete(pDevEnm);
    690686
    691687    LogFlowFuncLeaveRC(rc);
     
    704700 * @param   deviceID              Device ID to search.
    705701 */
    706 bool coreAudioDevicesHasDevice(PPDMAUDIODEVICEENUM pEnmSrc, AudioDeviceID deviceID)
     702bool coreAudioDevicesHasDevice(PPDMAUDIOHOSTENUM pEnmSrc, AudioDeviceID deviceID)
    707703{
    708704    PCOREAUDIODEVICEDATA pDevSrc;
     
    725721 * @param   pEnmDst             Where to store the device enumeration list.
    726722 */
    727 int coreAudioDevicesEnumerateAll(PDRVHOSTCOREAUDIO pThis, PPDMAUDIODEVICEENUM pEnmDst)
    728 {
    729     PDMAUDIODEVICEENUM devEnmIn;
     723int coreAudioDevicesEnumerateAll(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOHOSTENUM pEnmDst)
     724{
     725    PDMAUDIOHOSTENUM devEnmIn;
    730726    int rc = coreAudioDevicesEnumerate(pThis, PDMAUDIODIR_IN, &devEnmIn);
    731727    if (RT_SUCCESS(rc))
    732728    {
    733         PDMAUDIODEVICEENUM devEnmOut;
     729        PDMAUDIOHOSTENUM devEnmOut;
    734730        rc = coreAudioDevicesEnumerate(pThis, PDMAUDIODIR_OUT, &devEnmOut);
    735731        if (RT_SUCCESS(rc))
     
    742738             * at the same time.
    743739             */
    744 
    745             rc = DrvAudioHlpDeviceEnumInit(pEnmDst);
     740            PDMAudioHostEnumInit(pEnmDst);
     741            PCOREAUDIODEVICEDATA pDevSrcIn;
     742            RTListForEach(&devEnmIn.LstDevices, pDevSrcIn, COREAUDIODEVICEDATA, Core.Node)
     743            {
     744                PCOREAUDIODEVICEDATA pDevDst = (PCOREAUDIODEVICEDATA)PDMAudioDeviceAlloc(sizeof(*pDevDst));
     745                if (!pDevDst)
     746                {
     747                    rc = VERR_NO_MEMORY;
     748                    break;
     749                }
     750
     751                coreAudioDeviceDataInit(pDevDst, pDevSrcIn->deviceID, true /* fIsInput */, pThis);
     752
     753                RTStrCopy(pDevDst->Core.szName, sizeof(pDevDst->Core.szName), pDevSrcIn->Core.szName);
     754
     755                pDevDst->Core.enmUsage          = PDMAUDIODIR_IN; /* Input device by default (simplex). */
     756                pDevDst->Core.cMaxInputChannels = pDevSrcIn->Core.cMaxInputChannels;
     757
     758                /* Handle flags. */
     759                if (pDevSrcIn->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
     760                    pDevDst->Core.fFlags |= PDMAUDIODEV_FLAGS_DEFAULT;
     761                /** @todo Handle hot plugging? */
     762
     763                /*
     764                 * Now search through the list of all found output devices and check if we found
     765                 * an output device with the same device ID as the currently handled input device.
     766                 *
     767                 * If found, this means we have to treat that device as a duplex device then.
     768                 */
     769                PCOREAUDIODEVICEDATA pDevSrcOut;
     770                RTListForEach(&devEnmOut.LstDevices, pDevSrcOut, COREAUDIODEVICEDATA, Core.Node)
     771                {
     772                    if (pDevSrcIn->deviceID == pDevSrcOut->deviceID)
     773                    {
     774                        pDevDst->Core.enmUsage           = PDMAUDIODIR_DUPLEX;
     775                        pDevDst->Core.cMaxOutputChannels = pDevSrcOut->Core.cMaxOutputChannels;
     776
     777                        if (pDevSrcOut->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
     778                            pDevDst->Core.fFlags |= PDMAUDIODEV_FLAGS_DEFAULT;
     779                        break;
     780                    }
     781                }
     782
     783                if (RT_SUCCESS(rc))
     784                    PDMAudioHostEnumAppend(pEnmDst, &pDevDst->Core);
     785                else
     786                {
     787                    PDMAudioDeviceFree(&pDevDst->Core);
     788                    pDevDst = NULL;
     789                }
     790            }
     791
    746792            if (RT_SUCCESS(rc))
    747793            {
    748                 PCOREAUDIODEVICEDATA pDevSrcIn;
    749                 RTListForEach(&devEnmIn.LstDevices, pDevSrcIn, COREAUDIODEVICEDATA, Core.Node)
     794                /*
     795                 * As a last step, add all remaining output devices which have not been handled in the loop above,
     796                 * that is, all output devices which operate in simplex mode.
     797                 */
     798                PCOREAUDIODEVICEDATA pDevSrcOut;
     799                RTListForEach(&devEnmOut.LstDevices, pDevSrcOut, COREAUDIODEVICEDATA, Core.Node)
    750800                {
     801                    if (coreAudioDevicesHasDevice(pEnmDst, pDevSrcOut->deviceID))
     802                        continue; /* Already in our list, skip. */
     803
    751804                    PCOREAUDIODEVICEDATA pDevDst = (PCOREAUDIODEVICEDATA)PDMAudioDeviceAlloc(sizeof(*pDevDst));
    752805                    if (!pDevDst)
     
    756809                    }
    757810
    758                     coreAudioDeviceDataInit(pDevDst, pDevSrcIn->deviceID, true /* fIsInput */, pThis);
    759 
    760                     RTStrCopy(pDevDst->Core.szName, sizeof(pDevDst->Core.szName), pDevSrcIn->Core.szName);
    761 
    762                     pDevDst->Core.enmUsage          = PDMAUDIODIR_IN; /* Input device by default (simplex). */
    763                     pDevDst->Core.cMaxInputChannels = pDevSrcIn->Core.cMaxInputChannels;
     811                    coreAudioDeviceDataInit(pDevDst, pDevSrcOut->deviceID, false /* fIsInput */, pThis);
     812
     813                    RTStrCopy(pDevDst->Core.szName, sizeof(pDevDst->Core.szName), pDevSrcOut->Core.szName);
     814
     815                    pDevDst->Core.enmUsage           = PDMAUDIODIR_OUT;
     816                    pDevDst->Core.cMaxOutputChannels = pDevSrcOut->Core.cMaxOutputChannels;
     817
     818                    pDevDst->deviceID       = pDevSrcOut->deviceID;
    764819
    765820                    /* Handle flags. */
    766                     if (pDevSrcIn->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
     821                    if (pDevSrcOut->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
    767822                        pDevDst->Core.fFlags |= PDMAUDIODEV_FLAGS_DEFAULT;
    768823                    /** @todo Handle hot plugging? */
    769824
    770                     /*
    771                      * Now search through the list of all found output devices and check if we found
    772                      * an output device with the same device ID as the currently handled input device.
    773                      *
    774                      * If found, this means we have to treat that device as a duplex device then.
    775                      */
    776                     PCOREAUDIODEVICEDATA pDevSrcOut;
    777                     RTListForEach(&devEnmOut.LstDevices, pDevSrcOut, COREAUDIODEVICEDATA, Core.Node)
    778                     {
    779                         if (pDevSrcIn->deviceID == pDevSrcOut->deviceID)
    780                         {
    781                             pDevDst->Core.enmUsage           = PDMAUDIODIR_DUPLEX;
    782                             pDevDst->Core.cMaxOutputChannels = pDevSrcOut->Core.cMaxOutputChannels;
    783 
    784                             if (pDevSrcOut->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
    785                                 pDevDst->Core.fFlags |= PDMAUDIODEV_FLAGS_DEFAULT;
    786                             break;
    787                         }
    788                     }
    789 
    790                     if (RT_SUCCESS(rc))
    791                         rc = DrvAudioHlpDeviceEnumAdd(pEnmDst, &pDevDst->Core);
    792                     else
    793                     {
    794                         PDMAudioDeviceFree(&pDevDst->Core);
    795                         pDevDst = NULL;
    796                     }
     825                    PDMAudioHostEnumAppend(pEnmDst, &pDevDst->Core);
    797826                }
    798 
    799                 if (RT_SUCCESS(rc))
    800                 {
    801                     /*
    802                      * As a last step, add all remaining output devices which have not been handled in the loop above,
    803                      * that is, all output devices which operate in simplex mode.
    804                      */
    805                     PCOREAUDIODEVICEDATA pDevSrcOut;
    806                     RTListForEach(&devEnmOut.LstDevices, pDevSrcOut, COREAUDIODEVICEDATA, Core.Node)
    807                     {
    808                         if (coreAudioDevicesHasDevice(pEnmDst, pDevSrcOut->deviceID))
    809                             continue; /* Already in our list, skip. */
    810 
    811                         PCOREAUDIODEVICEDATA pDevDst = (PCOREAUDIODEVICEDATA)PDMAudioDeviceAlloc(sizeof(*pDevDst));
    812                         if (!pDevDst)
    813                         {
    814                             rc = VERR_NO_MEMORY;
    815                             break;
    816                         }
    817 
    818                         coreAudioDeviceDataInit(pDevDst, pDevSrcOut->deviceID, false /* fIsInput */, pThis);
    819 
    820                         RTStrCopy(pDevDst->Core.szName, sizeof(pDevDst->Core.szName), pDevSrcOut->Core.szName);
    821 
    822                         pDevDst->Core.enmUsage           = PDMAUDIODIR_OUT;
    823                         pDevDst->Core.cMaxOutputChannels = pDevSrcOut->Core.cMaxOutputChannels;
    824 
    825                         pDevDst->deviceID       = pDevSrcOut->deviceID;
    826 
    827                         /* Handle flags. */
    828                         if (pDevSrcOut->Core.fFlags & PDMAUDIODEV_FLAGS_DEFAULT)
    829                             pDevDst->Core.fFlags |= PDMAUDIODEV_FLAGS_DEFAULT;
    830                         /** @todo Handle hot plugging? */
    831 
    832                         rc = DrvAudioHlpDeviceEnumAdd(pEnmDst, &pDevDst->Core);
    833                         if (RT_FAILURE(rc))
    834                         {
    835                             PDMAudioDeviceFree(&pDevDst->Core);
    836                             break;
    837                         }
    838                     }
    839                 }
    840 
    841                 if (RT_FAILURE(rc))
    842                     DrvAudioHlpDeviceEnumFree(pEnmDst);
    843827            }
    844828
    845             DrvAudioHlpDeviceEnumFree(&devEnmOut);
    846         }
    847 
    848         DrvAudioHlpDeviceEnumFree(&devEnmIn);
     829            if (RT_FAILURE(rc))
     830                PDMAudioHostEnumDelete(pEnmDst);
     831
     832            PDMAudioHostEnumDelete(&devEnmOut);
     833        }
     834
     835        PDMAudioHostEnumDelete(&devEnmIn);
    849836    }
    850837
    851838#ifdef LOG_ENABLED
    852839    if (RT_SUCCESS(rc))
    853         DrvAudioHlpDeviceEnumLog(pEnmDst, "Core Audio (Final)");
     840        PDMAudioHostEnumLog(pEnmDst, "Core Audio (Final)");
    854841#endif
    855842
     
    18411828
    18421829    /* Remove old / stale device entries. */
    1843     DrvAudioHlpDeviceEnumFree(&pThis->Devices);
     1830    PDMAudioHostEnumDelete(&pThis->Devices);
    18441831
    18451832    /* Enumerate all devices internally. */
     
    18501837         * Default input device.
    18511838         */
    1852         pThis->pDefaultDevIn = (PCOREAUDIODEVICEDATA)DrvAudioHlpDeviceEnumGetDefaultDevice(&pThis->Devices, PDMAUDIODIR_IN);
     1839        pThis->pDefaultDevIn = (PCOREAUDIODEVICEDATA)PDMAudioHostEnumGetDefault(&pThis->Devices, PDMAUDIODIR_IN);
    18531840        if (pThis->pDefaultDevIn)
    18541841        {
     
    18631850         * Default output device.
    18641851         */
    1865         pThis->pDefaultDevOut = (PCOREAUDIODEVICEDATA)DrvAudioHlpDeviceEnumGetDefaultDevice(&pThis->Devices, PDMAUDIODIR_OUT);
     1852        pThis->pDefaultDevOut = (PCOREAUDIODEVICEDATA)PDMAudioHostEnumGetDefault(&pThis->Devices, PDMAUDIODIR_OUT);
    18661853        if (pThis->pDefaultDevOut)
    18671854        {
     
    21672154
    21682155    /* For Core Audio we provide one stream per device for now. */
    2169     pBackendCfg->cMaxStreamsIn  = DrvAudioHlpDeviceEnumGetDeviceCount(&pThis->Devices, PDMAUDIODIR_IN);
    2170     pBackendCfg->cMaxStreamsOut = DrvAudioHlpDeviceEnumGetDeviceCount(&pThis->Devices, PDMAUDIODIR_OUT);
     2156    pBackendCfg->cMaxStreamsIn  = PDMAudioHostEnumCountMatching(&pThis->Devices, PDMAUDIODIR_IN);
     2157    pBackendCfg->cMaxStreamsOut = PDMAudioHostEnumCountMatching(&pThis->Devices, PDMAUDIODIR_OUT);
    21712158
    21722159    LogFlowFunc(("Returning %Rrc\n", VINF_SUCCESS));
     
    21782165 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetDevices}
    21792166 */
    2180 static DECLCALLBACK(int) drvHostCoreAudioHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum)
     2167static DECLCALLBACK(int) drvHostCoreAudioHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum)
    21812168{
    21822169    AssertPtrReturn(pInterface,  VERR_INVALID_POINTER);
     
    21942181            {
    21952182                /* Return a copy with only PDMAUDIODEVICE, none of the extra bits in COREAUDIODEVICEDATA. */
    2196                 rc = DrvAudioHlpDeviceEnumInit(pDeviceEnum);
    2197                 if (RT_SUCCESS(rc))
    2198                     rc = DrvAudioHlpDeviceEnumCopy(pDeviceEnum, &pThis->Devices);
    2199 
     2183                PDMAudioHostEnumInit(pDeviceEnum);
     2184                rc = PDMAudioHostEnumCopy(pDeviceEnum, &pThis->Devices, PDMAUDIODIR_INVALID /*all*/, true /*fOnlyCoreData*/);
    22002185                if (RT_FAILURE(rc))
    2201                     DrvAudioHlpDeviceEnumFree(pDeviceEnum);
     2186                    PDMAudioHostEnumDelete(pDeviceEnum);
    22022187            }
    22032188        }
     
    24972482    PDRVHOSTCOREAUDIO pThis = PDMIHOSTAUDIO_2_DRVHOSTCOREAUDIO(pInterface);
    24982483
    2499     int rc = DrvAudioHlpDeviceEnumInit(&pThis->Devices);
    2500     if (RT_SUCCESS(rc))
    2501     {
    2502         /* Do the first (initial) internal device enumeration. */
    2503         rc = coreAudioEnumerateDevices(pThis);
    2504     }
    2505 
     2484    PDMAudioHostEnumInit(&pThis->Devices);
     2485    /* Do the first (initial) internal device enumeration. */
     2486    int rc = coreAudioEnumerateDevices(pThis);
    25062487    if (RT_SUCCESS(rc))
    25072488    {
  • trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp

    r88041 r88044  
    200200    uint32_t            fFlags;
    201201    /** Pointer to device list to populate. */
    202     PPDMAUDIODEVICEENUM pDevEnm;
     202    PPDMAUDIOHOSTENUM pDevEnm;
    203203} DSOUNDENUMCBCTX, *PDSOUNDENUMCBCTX;
    204204
     
    214214    DSOUNDHOSTCFG               Cfg;
    215215    /** List of devices of last enumeration. */
    216     PDMAUDIODEVICEENUM          DeviceEnum;
     216    PDMAUDIOHOSTENUM          DeviceEnum;
    217217    /** Whether this backend supports any audio input. */
    218218    bool                        fEnabledIn;
     
    246246static HRESULT  directSoundCaptureStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS, bool fFlush);
    247247
    248 static int      dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PDMAUDIODEVICEENUM pDevEnm, uint32_t fEnum);
     248static int      dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PDMAUDIOHOSTENUM pDevEnm, uint32_t fEnum);
    249249
    250250static int      dsoundStreamEnable(PDRVHOSTDSOUND pThis, PDSOUNDSTREAM pStreamDS, bool fEnable);
     
    15771577    AssertPtrReturn(pEnumCtx , FALSE);
    15781578
    1579     PPDMAUDIODEVICEENUM pDevEnm = pEnumCtx->pDevEnm;
     1579    PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm;
    15801580    AssertPtrReturn(pDevEnm, FALSE);
    15811581
     
    16041604                memcpy(&pDev->Guid, pGUID, sizeof(pDev->Guid));
    16051605
    1606             rc = DrvAudioHlpDeviceEnumAdd(pDevEnm, &pDev->Core);
    1607             if (RT_SUCCESS(rc))
    1608             {
    1609                 /* Note: Querying the actual device information will be done at some
    1610                  *       later point in time outside this enumeration callback to prevent
    1611                  *       DSound hangs. */
    1612                 return TRUE;
    1613             }
     1606            PDMAudioHostEnumAppend(pDevEnm, &pDev->Core);
     1607
     1608            /* Note: Querying the actual device information will be done at some
     1609             *       later point in time outside this enumeration callback to prevent
     1610             *       DSound hangs. */
     1611            return TRUE;
    16141612        }
    16151613        PDMAudioDeviceFree(&pDev->Core);
     
    16381636    AssertPtrReturn(pEnumCtx , FALSE);
    16391637
    1640     PPDMAUDIODEVICEENUM pDevEnm = pEnumCtx->pDevEnm;
     1638    PPDMAUDIOHOSTENUM pDevEnm = pEnumCtx->pDevEnm;
    16411639    AssertPtrReturn(pDevEnm, FALSE);
    16421640
     
    16621660                memcpy(&pDev->Guid, pGUID, sizeof(pDev->Guid));
    16631661
    1664             rc = DrvAudioHlpDeviceEnumAdd(pDevEnm, &pDev->Core);
    1665             if (RT_SUCCESS(rc))
    1666             {
    1667                 /* Note: Querying the actual device information will be done at some
    1668                  *       later point in time outside this enumeration callback to prevent
    1669                  *       DSound hangs. */
    1670                 return TRUE;
    1671             }
     1662            PDMAudioHostEnumAppend(pDevEnm, &pDev->Core);
     1663
     1664            /* Note: Querying the actual device information will be done at some
     1665             *       later point in time outside this enumeration callback to prevent
     1666             *       DSound hangs. */
     1667            return TRUE;
    16721668        }
    16731669        PDMAudioDeviceFree(&pDev->Core);
     
    17871783 * @param   pDevEnm             Where to store the enumerated devices.
    17881784 */
    1789 static int dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIODEVICEENUM pDevEnm)
     1785static int dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIOHOSTENUM pDevEnm)
    17901786{
    17911787    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     
    18801876        }
    18811877#endif
    1882         pThis->fEnabledIn  = DrvAudioHlpDeviceEnumGetDeviceCount(&pThis->DeviceEnum, PDMAUDIODIR_IN)  != 0;
    1883         pThis->fEnabledOut = DrvAudioHlpDeviceEnumGetDeviceCount(&pThis->DeviceEnum, PDMAUDIODIR_OUT) != 0;
     1878        pThis->fEnabledIn  = PDMAudioHostEnumCountMatching(&pThis->DeviceEnum, PDMAUDIODIR_IN)  != 0;
     1879        pThis->fEnabledOut = PDMAudioHostEnumCountMatching(&pThis->DeviceEnum, PDMAUDIODIR_OUT) != 0;
    18841880    }
    18851881
     
    22342230 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetDevices}
    22352231 */
    2236 static DECLCALLBACK(int) drvHostDSoundHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum)
     2232static DECLCALLBACK(int) drvHostDSoundHA_GetDevices(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum)
    22372233{
    22382234    AssertPtrReturn(pInterface,  VERR_INVALID_POINTER);
     
    22442240    if (RT_SUCCESS(rc))
    22452241    {
    2246         rc = DrvAudioHlpDeviceEnumInit(pDeviceEnum);
    2247         if (RT_SUCCESS(rc))
    2248         {
    2249             rc = dsoundDevicesEnumerate(pThis, pDeviceEnum);
    2250             if (RT_FAILURE(rc))
    2251                 DrvAudioHlpDeviceEnumFree(pDeviceEnum);
    2252         }
     2242        PDMAudioHostEnumInit(pDeviceEnum);
     2243        rc = dsoundDevicesEnumerate(pThis, pDeviceEnum);
     2244        if (RT_FAILURE(rc))
     2245            PDMAudioHostEnumDelete(pDeviceEnum);
    22532246
    22542247        int rc2 = RTCritSectLeave(&pThis->CritSect);
     
    26302623#endif
    26312624
    2632     DrvAudioHlpDeviceEnumFree(&pThis->DeviceEnum);
     2625    PDMAudioHostEnumDelete(&pThis->DeviceEnum);
    26332626
    26342627    if (pThis->pDrvIns)
     
    26972690     * Init the static parts.
    26982691     */
    2699     DrvAudioHlpDeviceEnumInit(&pThis->DeviceEnum);
     2692    PDMAudioHostEnumInit(&pThis->DeviceEnum);
    27002693
    27012694    pThis->fEnabledIn  = false;
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