VirtualBox

Changeset 59059 in vbox for trunk


Ignore:
Timestamp:
Dec 8, 2015 3:20:11 PM (9 years ago)
Author:
vboxsync
Message:

Audio: DrvHostDSound.cpp:

  • Forward-ported r104448 (Also try restoring playback buffer for DSERR_BUFFERLOST (for ​bugref:8079)).
  • Forward-ported r104449 (Don't try to release interfaces if stopping buffers didn't work, error checking (for ​bugref:8079)).
File:
1 edited

Legend:

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

    r59029 r59059  
    461461}
    462462
    463 static void directSoundPlayClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    464 {
    465     AssertPtrReturnVoid(pThis);
    466     AssertPtrReturnVoid(pDSoundStrmOut);
     463static HRESULT directSoundPlayClose(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
     464{
     465    AssertPtrReturn(pThis, E_POINTER);
     466    AssertPtrReturn(pDSoundStrmOut, E_POINTER);
    467467
    468468    DSLOG(("DSound: Closing playback stream %p, buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));
    469469
     470    HRESULT hr = S_OK;
     471
    470472    if (pDSoundStrmOut->pDSB)
    471473    {
    472         HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    473         if (FAILED(hr))
     474        hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
     475        if (SUCCEEDED(hr))
     476        {
     477#ifdef VBOX_WITH_AUDIO_CALLBACKS
     478            if (pThis->aEvents[DSOUNDEVENT_OUTPUT] != NULL)
     479            {
     480                CloseHandle(pThis->aEvents[DSOUNDEVENT_OUTPUT]);
     481                pThis->aEvents[DSOUNDEVENT_OUTPUT] = NULL;
     482
     483                if (pThis->cEvents)
     484                    pThis->cEvents--;
     485
     486                pThis->pDSStrmOut = NULL;
     487            }
     488
     489            int rc2 = dsoundNotifyThread(pThis, false /* fShutdown */);
     490            AssertRC(rc2);
     491#endif
     492            IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB);
     493            pDSoundStrmOut->pDSB = NULL;
     494        }
     495        else
    474496            DSLOGREL(("DSound: Stop playback stream %p when closing %Rhrc\n", pDSoundStrmOut, hr));
    475 
    476 #ifdef VBOX_WITH_AUDIO_CALLBACKS
    477         if (pThis->aEvents[DSOUNDEVENT_OUTPUT] != NULL)
    478         {
    479             CloseHandle(pThis->aEvents[DSOUNDEVENT_OUTPUT]);
    480             pThis->aEvents[DSOUNDEVENT_OUTPUT] = NULL;
    481 
    482             if (pThis->cEvents)
    483                 pThis->cEvents--;
    484 
    485             pThis->pDSStrmOut = NULL;
    486         }
    487 
    488         int rc2 = dsoundNotifyThread(pThis, false /* fShutdown */);
    489         AssertRC(rc2);
    490 #endif
    491         IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB);
    492         pDSoundStrmOut->pDSB = NULL;
    493     }
    494 
    495     directSoundPlayInterfaceRelease(pDSoundStrmOut);
     497    }
     498
     499    if (SUCCEEDED(hr))
     500        directSoundPlayInterfaceRelease(pDSoundStrmOut);
     501
     502    return hr;
    496503}
    497504
     
    531538        DSBUFFERDESC bd;
    532539        RT_ZERO(bd);
    533         bd.dwSize        = sizeof(bd);
    534         bd.lpwfxFormat   = &wfx;
    535         bd.dwFlags       = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
     540        bd.dwSize = sizeof(bd);
     541        bd.lpwfxFormat = &wfx;
     542        bd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
    536543#ifdef VBOX_WITH_AUDIO_CALLBACKS
    537544        bd.dwFlags      |= DSBCAPS_CTRLPOSITIONNOTIFY;
     
    696703    /* pdwStatus is optional. */
    697704
     705    bool fRestoreBuffer = false;
     706
    698707    DWORD dwStatus = 0;
    699708    HRESULT hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    700709    if (SUCCEEDED(hr))
    701710    {
    702         if ((dwStatus & DSBSTATUS_BUFFERLOST) != 0)
    703         {
    704             hr = directSoundPlayRestore(pDSB);
    705             if (SUCCEEDED(hr))
    706                 hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    707         }
     711        fRestoreBuffer = RT_BOOL(dwStatus & DSBSTATUS_BUFFERLOST);
     712    }
     713    else if (hr == DSERR_BUFFERLOST)
     714        fRestoreBuffer = true;
     715
     716    if (fRestoreBuffer)
     717    {
     718        hr = directSoundPlayRestore(pDSB);
     719        if (SUCCEEDED(hr))
     720            hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    708721    }
    709722
     
    876889}
    877890
    878 static void directSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)
    879 {
    880     AssertPtrReturnVoid(pDSoundStrmIn);
     891static HRESULT directSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)
     892{
     893    AssertPtrReturn(pDSoundStrmIn, E_POINTER);
    881894
    882895    DSLOG(("DSound: pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));
    883896
     897    HRESULT hr = S_OK;
     898
    884899    if (pDSoundStrmIn->pDSCB)
    885900    {
    886         HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
    887         if (FAILED(hr))
     901        hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
     902        if (SUCCEEDED(hr))
     903        {
     904            IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB);
     905            pDSoundStrmIn->pDSCB = NULL;
     906        }
     907        else
    888908            DSLOGREL(("DSound: Stop capture buffer %Rhrc\n", hr));
    889 
    890         IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB);
    891         pDSoundStrmIn->pDSCB = NULL;
    892     }
    893 
    894     directSoundCaptureInterfaceRelease(pDSoundStrmIn);
     909    }
     910
     911    if (SUCCEEDED(hr))
     912        directSoundCaptureInterfaceRelease(pDSoundStrmIn);
     913
     914    return hr;
    895915}
    896916
     
    13321352        DWORD cb1, cb2;
    13331353        HRESULT hr = directSoundPlayLock(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive,
    1334                                          &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
     1354                                 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
    13351355        if (FAILED(hr))
    13361356        {
     
    14051425    if (RT_SUCCESS(rc))
    14061426    {
    1407         if (pcSamplesPlayed)
    1408             *pcSamplesPlayed = cReadTotal;
     1427    if (pcSamplesPlayed)
     1428        *pcSamplesPlayed = cReadTotal;
    14091429    }
    14101430
     
    14191439    directSoundPlayClose(pThis, pDSoundStrmOut);
    14201440
    1421     pDSoundStrmOut->cbPlayWritePos       = 0;
    1422     pDSoundStrmOut->fRestartPlayback     = true;
     1441    pDSoundStrmOut->cbPlayWritePos = 0;
     1442    pDSoundStrmOut->fRestartPlayback = true;
    14231443    pDSoundStrmOut->csPlaybackBufferSize = 0;
    14241444
     
    14911511            if (FAILED(hr))
    14921512            {
    1493                 directSoundCaptureClose(pDSoundStrmIn);
    1494                 directSoundCaptureOpen(pThis, pDSoundStrmIn);
    1495 
    1496                 hr = directSoundCaptureStart(pThis, pDSoundStrmIn);
     1513                hr = directSoundCaptureClose(pDSoundStrmIn);
     1514                if (SUCCEEDED(hr))
     1515                {
     1516                    hr = directSoundCaptureOpen(pThis, pDSoundStrmIn);
     1517                    if (SUCCEEDED(hr))
     1518                        hr = directSoundCaptureStart(pThis, pDSoundStrmIn);
     1519                }
    14971520            }
    14981521
     
    15171540            rc = VERR_INVALID_PARAMETER;
    15181541            break;
    1519         }
     1542    }
    15201543    }
    15211544
     
    15381561        if (pDSCB == NULL)
    15391562        {
    1540             pThis->fEnabledIn = false;
    1541 
    1542             rc = VERR_NOT_AVAILABLE;
    1543             break;
     1563                pThis->fEnabledIn = false;
     1564
     1565                rc = VERR_NOT_AVAILABLE;
     1566                break;
    15441567        }
    15451568
     
    15551578            }
    15561579
    1557             rc = VERR_NOT_AVAILABLE;
    1558             break;
     1580                rc = VERR_NOT_AVAILABLE;
     1581                break;
    15591582        }
    15601583
     
    15701593        DWORD csCaptured = dsoundRingDistance(csReadPos, pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize);
    15711594        if (csCaptured == 0)
    1572             break;
     1595                break;
    15731596
    15741597        /* Using as an intermediate not circular buffer. */
     
    15801603        {
    15811604            DSLOGF(("DSound: Capture buffer full\n"));
    1582             break;
     1605                break;
    15831606        }
    15841607
     
    15991622        if (FAILED(hr))
    16001623        {
    1601             rc = VERR_ACCESS_DENIED;
    1602             break;
     1624                rc = VERR_ACCESS_DENIED;
     1625                break;
    16031626        }
    16041627
     
    16281651        directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2);
    16291652
    1630         if (csWrittenTotal) /* Captured something? */
    1631             rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal, &cCaptured);
     1653            if (csWrittenTotal) /* Captured something? */
     1654                rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, csWrittenTotal, &cCaptured);
    16321655
    16331656        if (RT_SUCCESS(rc))
    16341657        {
    1635             pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + cCaptured) % pDSoundStrmIn->csCaptureBufferSize;
     1658                pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + cCaptured) % pDSoundStrmIn->csCaptureBufferSize;
    16361659            DSLOGF(("DSound: Capture %ld (%ld+%ld), processed %RU32/%RU32\n",
    1637                     csCaptured, len1, len2, cCaptured, csWrittenTotal));
     1660                        csCaptured, len1, len2, cCaptured, csWrittenTotal));
    16381661        }
    16391662
     
    18701893        CloseHandle(pThis->aEvents[DSOUNDEVENT_NOTIFY]);
    18711894        pThis->aEvents[DSOUNDEVENT_NOTIFY] = NULL;
    1872     }
     1895}
    18731896#endif
    18741897
     
    19101933                DSLOGREL(("DSound: Waiting for thread to initialize failed with rc=%Rrc\n", rc));
    19111934        }
    1912         else
     1935    else
    19131936            DSLOGREL(("DSound: Creating thread failed with rc=%Rrc\n", rc));
    19141937#else
     
    20372060    pThis->fEnabledOut = false;
    20382061#ifdef VBOX_WITH_AUDIO_CALLBACKS
    2039     pThis->fStopped    = false;
    2040     pThis->fShutdown   = false;
     2062    pThis->fStopped  = false;
     2063    pThis->fShutdown = false;
    20412064
    20422065    RT_ZERO(pThis->aEvents);
     
    20682091    "DirectSound Audio host driver",
    20692092    /* fFlags */
    2070     PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
     2093     PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
    20712094    /* fClass. */
    20722095    PDM_DRVREG_CLASS_AUDIO,
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