VirtualBox

Ignore:
Timestamp:
Jul 31, 2015 4:01:58 PM (9 years ago)
Author:
vboxsync
Message:

Audio/DSound: Fixes for Windows 10, the original IDirectSound doesn't work there anymore, switch to IDirectSound8 instead which should be supported since Windows XP SP1

File:
1 edited

Legend:

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

    r56648 r57145  
    6868typedef struct DSOUNDSTREAMOUT
    6969{
    70     PDMAUDIOHSTSTRMOUT  hw; /* Always must come first! */
    71     LPDIRECTSOUND       pDS;
    72     LPDIRECTSOUNDBUFFER pDSB;
    73     DWORD               cbPlayWritePos;
    74     DWORD               csPlaybackBufferSize;
    75     bool                fReinitPlayPos;
    76     PDMAUDIOSTREAMCFG   streamCfg;
     70    PDMAUDIOHSTSTRMOUT   hw; /* Always must come first! */
     71    LPDIRECTSOUND8       pDS;
     72    LPDIRECTSOUNDBUFFER8 pDSB;
     73    DWORD                cbPlayWritePos;
     74    DWORD                csPlaybackBufferSize;
     75    bool                 fReinitPlayPos;
     76    PDMAUDIOSTREAMCFG    streamCfg;
    7777} DSOUNDSTREAMOUT, *PDSOUNDSTREAMOUT;
    7878
    7979typedef struct DSOUNDSTREAMIN
    8080{
    81     PDMAUDIOHSTSTRMIN          hw; /* Always must come first! */
    82     LPDIRECTSOUNDCAPTURE       pDSC;
    83     LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
    84     DWORD                      csCaptureReadPos;
    85     DWORD                      csCaptureBufferSize;
    86     HRESULT                    hrLastCaptureIn;
    87     PDMAUDIORECSOURCE          enmRecSource;
    88     PDMAUDIOSTREAMCFG          streamCfg;
     81    PDMAUDIOHSTSTRMIN           hw; /* Always must come first! */
     82    LPDIRECTSOUNDCAPTURE8       pDSC;
     83    LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB;
     84    DWORD                       csCaptureReadPos;
     85    DWORD                       csCaptureBufferSize;
     86    HRESULT                     hrLastCaptureIn;
     87    PDMAUDIORECSOURCE           enmRecSource;
     88    PDMAUDIOSTREAMCFG           streamCfg;
    8989} DSOUNDSTREAMIN, *PDSOUNDSTREAMIN;
    9090
     
    171171}
    172172
    173 static int dsoundPlayRestore(LPDIRECTSOUNDBUFFER pDSB)
    174 {
    175     HRESULT hr = IDirectSoundBuffer_Restore(pDSB);
     173static int dsoundPlayRestore(LPDIRECTSOUNDBUFFER8 pDSB)
     174{
     175    HRESULT hr = IDirectSoundBuffer8_Restore(pDSB);
    176176    if (SUCCEEDED(hr))
    177177        return VINF_SUCCESS;
     
    181181}
    182182
    183 static int dsoundUnlockOutput(LPDIRECTSOUNDBUFFER pDSB,
     183static int dsoundUnlockOutput(LPDIRECTSOUNDBUFFER8 pDSB,
    184184                              LPVOID pv1, LPVOID pv2,
    185185                              DWORD cb1, DWORD cb2)
    186186{
    187     HRESULT hr = IDirectSoundBuffer_Unlock(pDSB, pv1, cb1, pv2, cb2);
     187    HRESULT hr = IDirectSoundBuffer8_Unlock(pDSB, pv1, cb1, pv2, cb2);
    188188    if (SUCCEEDED(hr))
    189189        return VINF_SUCCESS;
     
    193193}
    194194
    195 static int dsoundUnlockInput(LPDIRECTSOUNDCAPTUREBUFFER pDSCB,
     195static int dsoundUnlockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB,
    196196                             LPVOID pv1, LPVOID pv2,
    197197                             DWORD cb1, DWORD cb2)
    198198{
    199     HRESULT hr = IDirectSoundCaptureBuffer_Unlock(pDSCB, pv1, cb1, pv2, cb2);
     199    HRESULT hr = IDirectSoundCaptureBuffer8_Unlock(pDSCB, pv1, cb1, pv2, cb2);
    200200    if (SUCCEEDED(hr))
    201201        return VINF_SUCCESS;
     
    205205}
    206206
    207 static int dsoundLockOutput(LPDIRECTSOUNDBUFFER pDSB, PDMPCMPROPS *pProps,
     207static int dsoundLockOutput(LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps,
    208208                            DWORD dwOffset, DWORD dwBytes,
    209209                            LPVOID *ppv1, LPVOID *ppv2,
     
    218218    DWORD cb2 = 0;
    219219
    220     HRESULT hr = IDirectSoundBuffer_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
     220    HRESULT hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
    221221    if (hr == DSERR_BUFFERLOST)
    222222    {
     
    224224        if (RT_SUCCESS(rc))
    225225        {
    226             hr = IDirectSoundBuffer_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
     226            hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
    227227        }
    228228    }
     
    250250}
    251251
    252 static int dsoundLockInput(LPDIRECTSOUNDCAPTUREBUFFER pDSCB, PPDMPCMPROPS pProps,
     252static int dsoundLockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps,
    253253                           DWORD dwOffset, DWORD dwBytes,
    254254                           LPVOID *ppv1, LPVOID *ppv2,
     
    261261    DWORD cb2 = 0;
    262262
    263     HRESULT hr = IDirectSoundCaptureBuffer_Lock(pDSCB, dwOffset, dwBytes,
    264                                             &pv1, &cb1, &pv2, &cb2, dwFlags);
     263    HRESULT hr = IDirectSoundCaptureBuffer8_Lock(pDSCB, dwOffset, dwBytes,
     264                                                 &pv1, &cb1, &pv2, &cb2, dwFlags);
    265265    if (FAILED(hr))
    266266    {
     
    294294    if (pDSoundStrmOut->pDS)
    295295    {
    296         IDirectSound_Release(pDSoundStrmOut->pDS);
     296        IDirectSound8_Release(pDSoundStrmOut->pDS);
    297297        pDSoundStrmOut->pDS = NULL;
    298298    }
     
    307307    }
    308308
    309     HRESULT hr = CoCreateInstance(CLSID_DirectSound, NULL, CLSCTX_ALL,
    310                                   IID_IDirectSound, (void **)&pDSoundStrmOut->pDS);
     309    HRESULT hr = CoCreateInstance(CLSID_DirectSound8, NULL, CLSCTX_ALL,
     310                                  IID_IDirectSound8, (void **)&pDSoundStrmOut->pDS);
    311311    if (FAILED(hr))
    312312    {
     
    315315    else
    316316    {
    317         hr = IDirectSound_Initialize(pDSoundStrmOut->pDS, pThis->cfg.pGuidPlay);
     317        hr = IDirectSound8_Initialize(pDSoundStrmOut->pDS, pThis->cfg.pGuidPlay);
    318318        if (SUCCEEDED(hr))
    319319        {
    320320            HWND hwnd = GetDesktopWindow();
    321             hr = IDirectSound_SetCooperativeLevel(pDSoundStrmOut->pDS, hwnd, DSSCL_PRIORITY);
     321            hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hwnd, DSSCL_PRIORITY);
    322322            if (FAILED (hr))
    323323            {
     
    348348    if (pDSoundStrmOut->pDSB)
    349349    {
    350         HRESULT hr = IDirectSoundBuffer_Stop(pDSoundStrmOut->pDSB);
     350        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    351351        if (FAILED(hr))
    352352        {
     
    354354        }
    355355
    356         IDirectSoundBuffer_Release(pDSoundStrmOut->pDSB);
     356        IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB);
    357357        pDSoundStrmOut->pDSB = NULL;
    358358    }
     
    392392    {
    393393        DSBUFFERDESC bd;
     394        LPDIRECTSOUNDBUFFER pDSB;
    394395        RT_ZERO(bd);
    395396        bd.dwSize = sizeof(bd);
     
    397398        bd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
    398399        bd.dwBufferBytes = pThis->cfg.cbBufferOut;
    399         hr = IDirectSound_CreateSoundBuffer(pDSoundStrmOut->pDS,
    400                                             &bd, &pDSoundStrmOut->pDSB, NULL);
     400        hr = IDirectSound8_CreateSoundBuffer(pDSoundStrmOut->pDS,
     401                                            &bd, &pDSB, NULL);
    401402        if (FAILED(hr))
    402403        {
     
    405406        }
    406407
     408        hr = IDirectSoundBuffer_QueryInterface(pDSB, IID_IDirectSoundBuffer8, (void **)&pDSoundStrmOut->pDSB);
     409        pDSB->Release();
     410        if (FAILED(hr))
     411        {
     412            DSLOGREL(("DSound: playback QueryInterface %Rhrc\n", hr));
     413            break;
     414        }
     415
    407416        /* Query the actual parameters. */
    408417
    409         hr = IDirectSoundBuffer_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL);
     418        hr = IDirectSoundBuffer8_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL);
    410419        if (FAILED(hr))
    411420        {
     
    417426        RT_ZERO(bc);
    418427        bc.dwSize = sizeof(bc);
    419         hr = IDirectSoundBuffer_GetCaps(pDSoundStrmOut->pDSB, &bc);
     428        hr = IDirectSoundBuffer8_GetCaps(pDSoundStrmOut->pDSB, &bc);
    420429        if (FAILED(hr))
    421430        {
     
    490499}
    491500
    492 static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER pDSB, DWORD *pStatus)
     501static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)
    493502{
    494503    int rc = VINF_SUCCESS;
    495504
    496505    DWORD dwStatus = 0;
    497     HRESULT hr = IDirectSoundBuffer_GetStatus(pDSB, &dwStatus);
     506    HRESULT hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    498507    if (SUCCEEDED(hr))
    499508    {
     
    503512            if (RT_SUCCESS(rc))
    504513            {
    505                 hr = IDirectSoundBuffer_GetStatus(pDSB, &dwStatus);
     514                hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    506515            }
    507516        }
     
    535544        DSLOG(("DSound: playback stop\n"));
    536545
    537         HRESULT hr = IDirectSoundBuffer_Stop(pDSoundStrmOut->pDSB);
     546        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    538547        if (FAILED(hr))
    539548        {
     
    569578                DSLOG(("DSound: playback start\n"));
    570579
    571                 HRESULT hr = IDirectSoundBuffer_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);
     580                HRESULT hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);
    572581                if (FAILED(hr))
    573582                {
     
    631640    if (pDSoundStrmIn->pDSC)
    632641    {
    633         IDirectSoundCapture_Release(pDSoundStrmIn->pDSC);
     642        IDirectSoundCapture8_Release(pDSoundStrmIn->pDSC);
    634643        pDSoundStrmIn->pDSC = NULL;
    635644    }
     
    644653    }
    645654
    646     HRESULT hr = CoCreateInstance(CLSID_DirectSoundCapture, NULL, CLSCTX_ALL,
    647                                   IID_IDirectSoundCapture, (void **)&pDSoundStrmIn->pDSC);
     655    HRESULT hr = CoCreateInstance(CLSID_DirectSoundCapture8, NULL, CLSCTX_ALL,
     656                                  IID_IDirectSoundCapture8, (void **)&pDSoundStrmIn->pDSC);
    648657    if (FAILED(hr))
    649658    {
     
    653662    {
    654663        LPCGUID pGUID = dsoundCaptureSelectDevice(pThis, pDSoundStrmIn);
    655         hr = IDirectSoundCapture_Initialize(pDSoundStrmIn->pDSC, pGUID);
     664        hr = IDirectSoundCapture8_Initialize(pDSoundStrmIn->pDSC, pGUID);
    656665        if (FAILED(hr))
    657666        {
     
    677686    if (pDSoundStrmIn->pDSCB)
    678687    {
    679         HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
     688        HRESULT hr = IDirectSoundCaptureBuffer8_Stop(pDSoundStrmIn->pDSCB);
    680689        if (FAILED (hr))
    681690        {
     
    683692        }
    684693
    685         IDirectSoundCaptureBuffer_Release(pDSoundStrmIn->pDSCB);
     694        IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB);
    686695        pDSoundStrmIn->pDSCB = NULL;
    687696    }
     
    721730    {
    722731        DSCBUFFERDESC bd;
     732        LPDIRECTSOUNDCAPTUREBUFFER pDSCB = NULL;
    723733        RT_ZERO(bd);
    724734        bd.dwSize = sizeof(bd);
    725735        bd.lpwfxFormat = &wfx;
    726736        bd.dwBufferBytes = pThis->cfg.cbBufferIn;
    727         hr = IDirectSoundCapture_CreateCaptureBuffer(pDSoundStrmIn->pDSC,
    728                                                      &bd, &pDSoundStrmIn->pDSCB, NULL);
     737        hr = IDirectSoundCapture8_CreateCaptureBuffer(pDSoundStrmIn->pDSC,
     738                                                      &bd, &pDSCB, NULL);
    729739
    730740        if (FAILED(hr))
     
    735745        }
    736746
     747        hr = IDirectSoundCaptureBuffer_QueryInterface(pDSCB, IID_IDirectSoundCaptureBuffer8, (void **)&pDSCB);
     748        IDirectSoundCaputreBuffer_Release(pDSCB);
     749        if (FAILED(hr))
     750        {
     751            DSLOGREL(("DSound: querying capture buffer %Rhrc\n", hr));
     752            break;
     753        }
     754
    737755        /* Query the actual parameters. */
    738756
    739757        DWORD cbReadPos = 0;
    740         hr = IDirectSoundCaptureBuffer_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos);
     758        hr = IDirectSoundCaptureBuffer8_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos);
    741759        if (FAILED(hr))
    742760        {
     
    746764
    747765        RT_ZERO(wfx);
    748         hr = IDirectSoundCaptureBuffer_GetFormat(pDSoundStrmIn->pDSCB, &wfx, sizeof(wfx), NULL);
     766        hr = IDirectSoundCaptureBuffer8_GetFormat(pDSoundStrmIn->pDSCB, &wfx, sizeof(wfx), NULL);
    749767        if (FAILED(hr))
    750768        {
     
    756774        RT_ZERO(bc);
    757775        bc.dwSize = sizeof(bc);
    758         hr = IDirectSoundCaptureBuffer_GetCaps(pDSoundStrmIn->pDSCB, &bc);
     776        hr = IDirectSoundCaptureBuffer8_GetCaps(pDSoundStrmIn->pDSCB, &bc);
    759777        if (FAILED (hr))
    760778        {
     
    814832        DSLOG(("DSound: capture stop\n"));
    815833
    816         HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
     834        HRESULT hr = IDirectSoundCaptureBuffer8_Stop(pDSoundStrmIn->pDSCB);
    817835        if (FAILED(hr))
    818836        {
     
    829847    {
    830848        DWORD dwStatus;
    831         hr = IDirectSoundCaptureBuffer_GetStatus(pDSoundStrmIn->pDSCB, &dwStatus);
     849        hr = IDirectSoundCaptureBuffer8_GetStatus(pDSoundStrmIn->pDSCB, &dwStatus);
    832850        if (FAILED(hr))
    833851        {
     
    844862                DSLOG(("DSound: capture start\n"));
    845863
    846                 hr = IDirectSoundCaptureBuffer_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING);
     864                hr = IDirectSoundCaptureBuffer8_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING);
    847865                if (FAILED (hr))
    848866                {
     
    10591077    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    10601078    PDSOUNDSTREAMOUT pDSoundStrmOut = (PDSOUNDSTREAMOUT)pHstStrmOut;
    1061     LPDIRECTSOUNDBUFFER pDSB = pDSoundStrmOut->pDSB;
     1079    LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB;
    10621080
    10631081    int rc = VINF_SUCCESS;
     
    10741092
    10751093    DWORD cbPlayPos, cbWritePos;
    1076     HRESULT hr = IDirectSoundBuffer_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
     1094    HRESULT hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
    10771095    if (hr == DSERR_BUFFERLOST)
    10781096    {
     
    10851103        }
    10861104
    1087         hr = IDirectSoundBuffer_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
     1105        hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
    10881106        if (hr == DSERR_BUFFERLOST)
    10891107        {
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