VirtualBox

Changeset 68683 in vbox


Ignore:
Timestamp:
Sep 6, 2017 3:26:32 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
117914
Message:

Audio: More code for audio endpoint (change) detection for Windows hosts.

Location:
trunk/src/VBox/Devices/Audio
Files:
3 edited

Legend:

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

    r68680 r68683  
    139139{
    140140    /** Pointer to the driver instance structure. */
    141     PPDMDRVINS              pDrvIns;
     141    PPDMDRVINS                  pDrvIns;
    142142    /** Our audio host audio interface. */
    143     PDMIHOSTAUDIO           IHostAudio;
     143    PDMIHOSTAUDIO               IHostAudio;
     144    /** Critical section to serialize access. */
     145    RTCRITSECT                  CritSect;
    144146    /** List of found host input devices. */
    145     RTLISTANCHOR            lstDevInput;
     147    RTLISTANCHOR                lstDevInput;
    146148    /** List of found host output devices. */
    147     RTLISTANCHOR            lstDevOutput;
     149    RTLISTANCHOR                lstDevOutput;
    148150    /** DirectSound configuration options. */
    149     DSOUNDHOSTCFG           cfg;
     151    DSOUNDHOSTCFG               cfg;
    150152    /** Whether this backend supports any audio input. */
    151     bool                    fEnabledIn;
     153    bool                        fEnabledIn;
    152154    /** Whether this backend supports any audio output. */
    153     bool                    fEnabledOut;
     155    bool                        fEnabledOut;
    154156    /** The Direct Sound playback interface. */
    155     LPDIRECTSOUND8          pDS;
     157    LPDIRECTSOUND8              pDS;
    156158    /** The Direct Sound capturing interface. */
    157     LPDIRECTSOUNDCAPTURE8   pDSC;
     159    LPDIRECTSOUNDCAPTURE8       pDSC;
    158160#ifdef VBOX_WITH_AUDIO_MMNOTIFICATION_CLIENT
    159     VBoxMMNotificationClient *m_pNotificationClient;
     161    VBoxMMNotificationClient   *m_pNotificationClient;
     162#endif
     163#ifdef VBOX_WITH_AUDIO_CALLBACKS
     164    /** Callback function to the upper driver.
     165     *  Can be NULL if not being used / registered. */
     166    PFNPDMHOSTAUDIOCALLBACK     pfnCallback;
    160167#endif
    161168#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
    162169    /** Pointer to the audio connector interface of the driver/device above us. */
    163     PPDMIAUDIOCONNECTOR     pUpIAudioConnector;
     170    PPDMIAUDIOCONNECTOR         pUpIAudioConnector;
    164171    /** Stopped indicator. */
    165     bool                    fStopped;
     172    bool                        fStopped;
    166173    /** Shutdown indicator. */
    167     bool                    fShutdown;
     174    bool                        fShutdown;
    168175    /** Notification thread. */
    169     RTTHREAD                Thread;
     176    RTTHREAD                    Thread;
    170177    /** Array of events to wait for in notification thread. */
    171     HANDLE                  aEvents[VBOX_DSOUND_MAX_EVENTS];
     178    HANDLE                      aEvents[VBOX_DSOUND_MAX_EVENTS];
    172179    /** Number of events to wait for in notification thread.
    173180     *  Must not exceed VBOX_DSOUND_MAX_EVENTS. */
    174     uint8_t                 cEvents;
     181    uint8_t                     cEvents;
    175182    /** Pointer to the input stream. */
    176     PDSOUNDSTREAM           pDSStrmIn;
     183    PDSOUNDSTREAM               pDSStrmIn;
    177184    /** Pointer to the output stream. */
    178     PDSOUNDSTREAM           pDSStrmOut;
     185    PDSOUNDSTREAM               pDSStrmOut;
    179186#endif
    180187} DRVHOSTDSOUND, *PDRVHOSTDSOUND;
     
    21682175
    21692176
    2170 static void dsoundConfigInit(PDRVHOSTDSOUND pThis, PCFGMNODE pCfg)
     2177static int dsoundConfigInit(PDRVHOSTDSOUND pThis, PCFGMNODE pCfg)
    21712178{
    21722179    unsigned int uBufsizeOut, uBufsizeIn;
     
    21852192           &pThis->cfg.uuidPlay,
    21862193           &pThis->cfg.uuidCapture));
     2194
     2195    return VINF_SUCCESS;
    21872196}
    21882197
     
    23752384}
    23762385
     2386#ifdef VBOX_WITH_AUDIO_CALLBACKS
     2387/**
     2388 * @interface_method_impl{PDMIHOSTAUDIO,pfnSetCallback}
     2389 */
     2390static DECLCALLBACK(int) drvHostDSoundSetCallback(PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback)
     2391{
     2392    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     2393    /* pfnCallback will be handled below. */
     2394
     2395    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
     2396
     2397    int rc = RTCritSectEnter(&pThis->CritSect);
     2398    if (RT_SUCCESS(rc))
     2399    {
     2400        LogFunc(("pfnCallback=%p\n", pfnCallback));
     2401
     2402        if (pfnCallback) /* Register. */
     2403        {
     2404            Assert(pThis->pfnCallback == NULL);
     2405            pThis->pfnCallback = pfnCallback;
     2406
     2407#ifdef VBOX_WITH_AUDIO_MMNOTIFICATION_CLIENT
     2408            if (pThis->m_pNotificationClient)
     2409                pThis->m_pNotificationClient->RegisterCallback(pThis->pDrvIns, pfnCallback);
     2410#endif
     2411        }
     2412        else /* Unregister. */
     2413        {
     2414            if (pThis->pfnCallback)
     2415                pThis->pfnCallback = NULL;
     2416
     2417#ifdef VBOX_WITH_AUDIO_MMNOTIFICATION_CLIENT
     2418            if (pThis->m_pNotificationClient)
     2419                pThis->m_pNotificationClient->UnregisterCallback();
     2420#endif
     2421        }
     2422
     2423        int rc2 = RTCritSectLeave(&pThis->CritSect);
     2424        AssertRC(rc2);
     2425    }
     2426
     2427    return rc;
     2428}
     2429#endif
    23772430
    23782431/*********************************************************************************************************************************
     
    24202473    if (pThis->pDrvIns)
    24212474        CoUninitialize();
     2475
     2476    int rc2 = RTCritSectDelete(&pThis->CritSect);
     2477    AssertRC(rc2);
    24222478
    24232479    LogFlowFuncLeave();
     
    24542510    PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvHostDSound);
    24552511
     2512#ifdef VBOX_WITH_AUDIO_CALLBACKS
     2513    /* This backend supports host audio callbacks. */
     2514    pThis->IHostAudio.pfnSetCallback = drvHostDSoundSetCallback;
     2515    pThis->pfnCallback               = NULL;
     2516#endif
     2517
    24562518#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
    24572519    /*
     
    25002562#endif
    25012563
    2502     /*
    2503      * Initialize configuration values.
    2504      */
    2505     dsoundConfigInit(pThis, pCfg);
     2564    if (RT_SUCCESS(rc))
     2565    {
     2566        /*
     2567         * Initialize configuration values.
     2568         */
     2569        rc = dsoundConfigInit(pThis, pCfg);
     2570        if (RT_SUCCESS(rc))
     2571            rc = RTCritSectInit(&pThis->CritSect);
     2572    }
    25062573
    25072574    return rc;
  • trunk/src/VBox/Devices/Audio/VBoxMMNotificationClient.cpp

    r68680 r68683  
    2727#pragma warning(pop)
    2828
     29#ifdef LOG_GROUP
     30# undef LOG_GROUP
     31#endif
    2932#define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
    3033#include <VBox/log.h>
     
    6972}
    7073
     74int VBoxMMNotificationClient::RegisterCallback(PPDMDRVINS pDrvIns, PFNPDMHOSTAUDIOCALLBACK pfnCallback)
     75{
     76    this->m_pDrvIns     = pDrvIns;
     77    this->m_pfnCallback = pfnCallback;
     78
     79    return VINF_SUCCESS;
     80}
     81
     82void VBoxMMNotificationClient::UnregisterCallback(void)
     83{
     84    this->m_pDrvIns     = NULL;
     85    this->m_pfnCallback = NULL;
     86}
     87
    7188HRESULT VBoxMMNotificationClient::AttachToDefaultEndpoint(void)
    7289{
     
    8198STDMETHODIMP VBoxMMNotificationClient::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState)
    8299{
    83     char  *pszState = "UNKNOWN";
     100    char *pszState = "unknown";
    84101
    85102    switch (dwNewState)
    86103    {
    87104        case DEVICE_STATE_ACTIVE:
    88             pszState = "ACTIVE";
     105            pszState = "active";
    89106            break;
    90107        case DEVICE_STATE_DISABLED:
    91             pszState = "DISABLED";
     108            pszState = "disabled";
    92109            break;
    93110        case DEVICE_STATE_NOTPRESENT:
    94             pszState = "NOTPRESENT";
     111            pszState = "not present";
    95112            break;
    96113        case DEVICE_STATE_UNPLUGGED:
    97             pszState = "UNPLUGGED";
     114            pszState = "unplugged";
     115            break;
     116        default:
    98117            break;
    99118    }
    100119
    101     LogFunc(("%ls: %s\n", pwstrDeviceId, pszState));
     120    LogRel2(("Audio: Device '%ls' has changed state to '%s'\n", pwstrDeviceId, pszState));
     121
     122#ifdef VBOX_WITH_AUDIO_CALLBACKS
     123    AssertPtr(this->m_pDrvIns);
     124    AssertPtr(this->m_pfnCallback);
     125
     126    if (this->m_pfnCallback)
     127        /* Ignore rc */ this->m_pfnCallback(this->m_pDrvIns, PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED, NULL, 0);
     128#endif
     129
    102130    return S_OK;
    103131}
  • trunk/src/VBox/Devices/Audio/VBoxMMNotificationClient.h

    r68680 r68683  
    2525#include <Mmdeviceapi.h>
    2626
     27#include "DrvAudio.h"
     28
    2729class VBoxMMNotificationClient : IMMNotificationClient
    2830{
     
    3335
    3436    HRESULT Initialize();
     37    int     RegisterCallback(PPDMDRVINS pDrvIns, PFNPDMHOSTAUDIOCALLBACK pfnCallback);
     38    void    UnregisterCallback(void);
    3539    void    Dispose();
    3640
     
    4246private:
    4347
    44     bool                 m_fRegisteredClient;
    45     IMMDeviceEnumerator *m_pEnum;
    46     IMMDevice           *m_pEndpoint;
     48    bool                        m_fRegisteredClient;
     49    IMMDeviceEnumerator        *m_pEnum;
     50    IMMDevice                  *m_pEndpoint;
    4751
    48     long                 m_cRef;
     52    long                        m_cRef;
     53
     54    PPDMDRVINS                  m_pDrvIns;
     55    PFNPDMHOSTAUDIOCALLBACK     m_pfnCallback;
    4956
    5057    HRESULT AttachToDefaultEndpoint();
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette