VirtualBox

Changeset 58071 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Oct 7, 2015 6:23:04 AM (9 years ago)
Author:
vboxsync
Message:

DrvHostDSound: restored optional release logging, IPRT rc vs HRESULT cleanup

File:
1 edited

Legend:

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

    r57752 r58071  
    2828#include "VBoxDD.h"
    2929
     30/*
     31 * IDirectSound* interface uses HRESULT status codes and the driver callbacks use
     32 * the IPRT status codes. To minimize HRESULT->IPRT conversion most internal functions
     33 * in the driver return HRESULT and conversion is done in the driver callbacks.
     34 *
     35 * Naming convention:
     36 * 'dsound*' functions return IPRT status code;
     37 * 'directSound*' - return HRESULT.
     38 */
     39
     40/*
     41 * Optional release logging, which a user can turn on with the
     42 * 'VBoxManage debugvm' command.
     43 * Debug logging still uses the common Log* macros from IPRT.
     44 * Messages which always should go to the release log use LogRel.
     45 */
     46/* General code behavior. */
     47#define DSLOG(a) do { LogRel2(a); } while(0)
     48/* Something which produce a lot of logging during playback/recording. */
     49#define DSLOGF(a) do { LogRel3(a); } while(0)
     50/* Important messages like errors. Limited in the default release log to avoid log flood. */
     51#define DSLOGREL(a)                 \
     52    do {                            \
     53        static int8_t scLogged = 0; \
     54        if (scLogged < 8) {         \
     55            ++scLogged;             \
     56            LogRel(a);              \
     57        }                           \
     58        else {                      \
     59            DSLOG(a);               \
     60        }                           \
     61    } while (0)
     62
    3063/* Dynamically load dsound.dll. */
    3164typedef HRESULT WINAPI FNDIRECTSOUNDENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext);
     
    97130} DSOUNDDEV, *PDSOUNDDEV;
    98131
    99 /** Maximum number of release logging entries. */
    100 static uint32_t s_cMaxRelLogEntries = 32;
    101 
    102132/** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */
    103133#define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \
     
    166196    }
    167197
    168     return RTStrDup("<GUID not found>");
     198    return RTStrDup("{Default device}");
    169199}
    170200
     
    185215}
    186216
    187 static int dsoundPlayRestore(LPDIRECTSOUNDBUFFER8 pDSB)
     217static HRESULT directSoundPlayRestore(LPDIRECTSOUNDBUFFER8 pDSB)
    188218{
    189219    HRESULT hr = IDirectSoundBuffer8_Restore(pDSB);
    190     if (SUCCEEDED(hr))
    191         return VINF_SUCCESS;
    192 
    193     LogRelMax(s_cMaxRelLogEntries, ("DSound: Error restoring playback buffer: %Rhrc\n", hr));
    194     return VERR_INVALID_STATE;
    195 }
    196 
    197 static int dsoundUnlockOutput(LPDIRECTSOUNDBUFFER8 pDSB,
    198                               LPVOID pv1, LPVOID pv2,
    199                               DWORD cb1, DWORD cb2)
     220    if (FAILED(hr))
     221        DSLOGREL(("DSound: Restore playback buffer %Rhrc\n", hr));
     222    return hr;
     223}
     224
     225static HRESULT directSoundPlayUnlock(LPDIRECTSOUNDBUFFER8 pDSB,
     226                                     LPVOID pv1, LPVOID pv2,
     227                                     DWORD cb1, DWORD cb2)
    200228{
    201229    HRESULT hr = IDirectSoundBuffer8_Unlock(pDSB, pv1, cb1, pv2, cb2);
    202     if (SUCCEEDED(hr))
    203         return VINF_SUCCESS;
    204 
    205     LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking output buffer: %Rhrc\n", hr));
    206     return VERR_ACCESS_DENIED;
    207 }
    208 
    209 static int dsoundUnlockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB,
    210                              LPVOID pv1, LPVOID pv2,
    211                              DWORD cb1, DWORD cb2)
     230    if (FAILED(hr))
     231        DSLOGREL(("DSound: Unlock playback buffer %Rhrc\n", hr));
     232    return hr;
     233}
     234
     235static HRESULT directSoundCaptureUnlock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB,
     236                                        LPVOID pv1, LPVOID pv2,
     237                                        DWORD cb1, DWORD cb2)
    212238{
    213239    HRESULT hr = IDirectSoundCaptureBuffer8_Unlock(pDSCB, pv1, cb1, pv2, cb2);
    214     if (SUCCEEDED(hr))
    215         return VINF_SUCCESS;
    216 
    217     LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking input buffer: %Rhrc\n", hr));
    218     return VERR_ACCESS_DENIED;
    219 }
    220 
    221 static int dsoundLockOutput(LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps,
    222                             DWORD dwOffset, DWORD dwBytes,
    223                             LPVOID *ppv1, LPVOID *ppv2,
    224                             DWORD *pcb1, DWORD *pcb2,
    225                             DWORD dwFlags)
    226 {
    227     int rc = VINF_SUCCESS;
    228 
     240    if (FAILED(hr))
     241        DSLOGREL(("DSound: Unlock capture buffer %Rhrc\n", hr));
     242    return hr;
     243}
     244
     245static HRESULT directSoundPlayLock(LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps,
     246                                   DWORD dwOffset, DWORD dwBytes,
     247                                   LPVOID *ppv1, LPVOID *ppv2,
     248                                   DWORD *pcb1, DWORD *pcb2,
     249                                   DWORD dwFlags)
     250{
    229251    LPVOID pv1 = NULL;
    230252    LPVOID pv2 = NULL;
     
    235257    if (hr == DSERR_BUFFERLOST)
    236258    {
    237         rc = dsoundPlayRestore(pDSB);
    238         if (RT_SUCCESS(rc))
     259        hr = directSoundPlayRestore(pDSB);
     260        if (SUCCEEDED(hr))
    239261        {
    240262            hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
    241             if (FAILED(hr))
    242                 rc = VERR_ACCESS_DENIED;
    243         }
    244     }
    245 
    246     if (RT_FAILURE(rc))
    247     {
    248         LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking output buffer: %Rhrc\n", hr));
    249         return rc;
     263        }
     264    }
     265
     266    if (FAILED(hr))
     267    {
     268        DSLOGREL(("DSound: Lock playback buffer %Rhrc\n", hr));
     269        return hr;
    250270    }
    251271
     
    253273        || (pv2 && (cb2 & pProps->uAlign)))
    254274    {
    255         LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
    256                        cb1, cb2, pProps->uAlign));
    257         dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);
    258         return VERR_INVALID_STATE;
     275        DSLOGREL(("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
     276                  cb1, cb2, pProps->uAlign));
     277        directSoundPlayUnlock(pDSB, pv1, pv2, cb1, cb2);
     278        return E_FAIL;
    259279    }
    260280
     
    264284    *pcb2 = cb2;
    265285
    266     return VINF_SUCCESS;
    267 }
    268 
    269 static int dsoundLockInput(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps,
    270                            DWORD dwOffset, DWORD dwBytes,
    271                            LPVOID *ppv1, LPVOID *ppv2,
    272                            DWORD *pcb1, DWORD *pcb2,
    273                            DWORD dwFlags)
     286    return S_OK;
     287}
     288
     289static HRESULT directSoundCaptureLock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps,
     290                                      DWORD dwOffset, DWORD dwBytes,
     291                                      LPVOID *ppv1, LPVOID *ppv2,
     292                                      DWORD *pcb1, DWORD *pcb2,
     293                                      DWORD dwFlags)
    274294{
    275295    LPVOID pv1 = NULL;
     
    282302    if (FAILED(hr))
    283303    {
    284         LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking capturing buffer: %Rhrc\n", hr));
    285         return VERR_ACCESS_DENIED;
     304        DSLOGREL(("DSound: Lock capture buffer %Rhrc\n", hr));
     305        return hr;
    286306    }
    287307
     
    289309        || (pv2 && (cb2 & pProps->uAlign)))
    290310    {
    291         LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
    292                        cb1, cb2, pProps->uAlign));
    293         dsoundUnlockInput(pDSCB, pv1, pv2, cb1, cb2);
    294         return VERR_INVALID_PARAMETER;
     311        DSLOGREL(("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
     312                  cb1, cb2, pProps->uAlign));
     313        directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2);
     314        return E_FAIL;
    295315    }
    296316
     
    300320    *pcb2 = cb2;
    301321
    302     return VINF_SUCCESS;
     322    return S_OK;
    303323}
    304324
     
    308328 */
    309329
    310 static void dsoundPlayInterfaceRelease(PDSOUNDSTREAMOUT pDSoundStrmOut)
     330static void directSoundPlayInterfaceRelease(PDSOUNDSTREAMOUT pDSoundStrmOut)
    311331{
    312332    if (pDSoundStrmOut->pDS)
     
    317337}
    318338
    319 static int dsoundPlayInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
     339static HRESULT directSoundPlayInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    320340{
    321341    if (pDSoundStrmOut->pDS != NULL)
    322342    {
    323         LogFlowFunc(("DirectSound instance already exists\n"));
    324         return VINF_SUCCESS;
     343        DSLOG(("DSound: DirectSound instance already exists\n"));
     344        return S_OK;
    325345    }
    326346
     
    329349    if (FAILED(hr))
    330350    {
    331         LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating DirectSound instance: %Rhrc\n", hr));
     351        DSLOGREL(("DSound: Create DirectSound instance %Rhrc\n", hr));
    332352    }
    333353    else
     
    339359            hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hWnd, DSSCL_PRIORITY);
    340360            if (FAILED(hr))
    341                 LogRel(("DSound: Error setting cooperative level for window %p: %Rhrc\n", hWnd, hr));
    342         }
     361                DSLOGREL(("DSound: Set cooperative level for window %p %Rhrc\n", hWnd, hr));
     362        }
     363
    343364        if (FAILED(hr))
    344365        {
    345             if (hr == DSERR_NODRIVER)
    346                 LogRel(("DSound: DirectSound playback is currently unavailable\n"));
     366            if (hr == DSERR_NODRIVER) /* Usually means that no playback devices are attached. */
     367                DSLOGREL(("DSound: DirectSound playback is currently unavailable\n"));
    347368            else
    348                 LogRel(("DSound: Error initializing DirectSound: %Rhrc\n", hr));
    349 
    350             dsoundPlayInterfaceRelease(pDSoundStrmOut);
    351         }
    352     }
    353 
    354     return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;
    355 }
    356 
    357 static void dsoundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut)
    358 {
    359     LogFlowFunc(("Closing playback stream %p (buffer %p)\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));
     369                DSLOGREL(("DSound: DirectSound playback initialize %Rhrc\n", hr));
     370
     371            directSoundPlayInterfaceRelease(pDSoundStrmOut);
     372        }
     373    }
     374
     375    return hr;
     376}
     377
     378static void directSoundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut)
     379{
     380    DSLOG(("DSound: Closing playback stream %p, buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));
    360381
    361382    if (pDSoundStrmOut->pDSB)
     
    363384        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    364385        if (FAILED(hr))
    365             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error closing playback stream %p: %Rhrc\n", pDSoundStrmOut, hr));
     386            DSLOGREL(("DSound: Stop playback stream %p when closing %Rhrc\n", pDSoundStrmOut, hr));
    366387
    367388        IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB);
     
    369390    }
    370391
    371     dsoundPlayInterfaceRelease(pDSoundStrmOut);
    372 }
    373 
    374 static int dsoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    375 {
    376     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    377     AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER);
    378 
    379     LogFlowFunc(("pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
    380                  pDSoundStrmOut,
    381                  pThis->cfg.cbBufferOut,
    382                  pDSoundStrmOut->strmOut.Props.uHz,
    383                  pDSoundStrmOut->strmOut.Props.cChannels,
    384                  pDSoundStrmOut->strmOut.Props.cBits,
    385                  pDSoundStrmOut->strmOut.Props.fSigned));
     392    directSoundPlayInterfaceRelease(pDSoundStrmOut);
     393}
     394
     395static HRESULT directSoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
     396{
     397    AssertPtrReturn(pThis, E_POINTER);
     398    AssertPtrReturn(pDSoundStrmOut, E_POINTER);
     399
     400    DSLOG(("DSound: pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
     401           pDSoundStrmOut,
     402           pThis->cfg.cbBufferOut,
     403           pDSoundStrmOut->strmOut.Props.uHz,
     404           pDSoundStrmOut->strmOut.Props.cChannels,
     405           pDSoundStrmOut->strmOut.Props.cBits,
     406           pDSoundStrmOut->strmOut.Props.fSigned));
    386407
    387408    if (pDSoundStrmOut->pDSB != NULL)
    388409    {
    389410        /* Should not happen but be forgiving. */
    390         LogFlowFunc(("DirectSoundBuffer already exists\n"));
    391         dsoundPlayClose(pDSoundStrmOut);
     411        DSLOGREL(("DSound: DirectSoundBuffer already exists\n"));
     412        directSoundPlayClose(pDSoundStrmOut);
    392413    }
    393414
     
    395416    int rc = dsoundWaveFmtFromCfg(&pDSoundStrmOut->streamCfg, &wfx);
    396417    if (RT_FAILURE(rc))
    397         return rc;
    398 
    399     rc = dsoundPlayInterfaceCreate(pThis, pDSoundStrmOut);
    400     if (RT_FAILURE(rc))
    401         return rc;
    402 
    403     HRESULT hr = S_OK;
     418        return E_INVALIDARG;
     419
     420    HRESULT hr = directSoundPlayInterfaceCreate(pThis, pDSoundStrmOut);
     421    if (FAILED(hr))
     422        return hr;
    404423
    405424    do /* To use breaks. */
    406425    {
     426        LPDIRECTSOUNDBUFFER pDSB = NULL;
    407427        DSBUFFERDESC bd;
    408         LPDIRECTSOUNDBUFFER pDSB;
    409428        RT_ZERO(bd);
    410429        bd.dwSize = sizeof(bd);
     
    413432        bd.dwBufferBytes = pThis->cfg.cbBufferOut;
    414433        hr = IDirectSound8_CreateSoundBuffer(pDSoundStrmOut->pDS,
    415                                             &bd, &pDSB, NULL);
     434                                             &bd, &pDSB, NULL);
    416435        if (FAILED(hr))
    417436        {
    418             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating playback stream: %Rhrc\n", hr));
    419             break;
    420         }
    421 
     437            DSLOGREL(("DSound: CreateSoundBuffer %Rhrc\n", hr));
     438            break;
     439        }
     440
     441        /* "Upgrade" to IDirectSoundBuffer8 intarface. */
    422442        hr = IDirectSoundBuffer_QueryInterface(pDSB, IID_IDirectSoundBuffer8, (void **)&pDSoundStrmOut->pDSB);
    423443        pDSB->Release();
    424444        if (FAILED(hr))
    425445        {
    426             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying interface for playback stream: %Rhrc\n", hr));
    427             break;
    428         }
    429 
    430         /* Query the actual parameters. */
     446            DSLOGREL(("DSound: Query IDirectSoundBuffer8 %Rhrc\n", hr));
     447            break;
     448        }
     449
     450        /*
     451         * Query the actual parameters.
     452         */
    431453        hr = IDirectSoundBuffer8_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL);
    432454        if (FAILED(hr))
    433455        {
    434             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for playback stream: %Rhrc\n", hr));
     456            DSLOGREL(("DSound: Playback GetFormat %Rhrc\n", hr));
    435457            break;
    436458        }
     
    442464        if (FAILED(hr))
    443465        {
    444             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for playback stream: %Rhrc\n", hr));
    445             break;
    446         }
    447 
    448         LogFunc(("Playback format:\n"
    449                  "\tdwBufferBytes   = %RI32\n"
    450                  "\twFormatTag      = %RI16\n"
    451                  "\tnChannels       = %RI16\n"
    452                  "\tnSamplesPerSec  = %RU32\n"
    453                  "\tnAvgBytesPerSec = %RU32\n"
    454                  "\tnBlockAlign     = %RI16\n"
    455                  "\twBitsPerSample  = %RI16\n"
    456                  "\tcbSize          = %RI16\n",
    457                 bc.dwBufferBytes,
    458                 wfx.wFormatTag,
    459                 wfx.nChannels,
    460                 wfx.nSamplesPerSec,
    461                 wfx.nAvgBytesPerSec,
    462                 wfx.nBlockAlign,
    463                 wfx.wBitsPerSample,
    464                 wfx.cbSize));
     466            DSLOGREL(("DSound: Playback GetCaps %Rhrc\n", hr));
     467            break;
     468        }
     469
     470        DSLOG(("DSound: Playback format:\n"
     471               dwBufferBytes   = %RI32\n"
     472               wFormatTag      = %RI16\n"
     473               nChannels       = %RI16\n"
     474               nSamplesPerSec  = %RU32\n"
     475               nAvgBytesPerSec = %RU32\n"
     476               nBlockAlign     = %RI16\n"
     477               wBitsPerSample  = %RI16\n"
     478               cbSize          = %RI16\n",
     479               bc.dwBufferBytes,
     480               wfx.wFormatTag,
     481               wfx.nChannels,
     482               wfx.nSamplesPerSec,
     483               wfx.nAvgBytesPerSec,
     484               wfx.nBlockAlign,
     485               wfx.wBitsPerSample,
     486               wfx.cbSize));
    465487
    466488        if (bc.dwBufferBytes & pDSoundStrmOut->strmOut.Props.uAlign)
    467             LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",
    468                            bc.dwBufferBytes, pDSoundStrmOut->strmOut.Props.uAlign + 1));
     489            DSLOGREL(("DSound: Playback GetCaps returned misaligned buffer: size %RU32, alignment %RU32\n",
     490                      bc.dwBufferBytes, pDSoundStrmOut->strmOut.Props.uAlign + 1));
    469491
    470492        if (bc.dwBufferBytes != pThis->cfg.cbBufferOut)
    471             LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",
    472                            bc.dwBufferBytes, pThis->cfg.cbBufferOut));
     493            DSLOGREL(("DSound: Playback buffer size mismatched: DirectSound %RU32, requested %RU32 bytes\n",
     494                      bc.dwBufferBytes, pThis->cfg.cbBufferOut));
    473495
    474496        /*
     
    478500         */
    479501        pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->strmOut.Props.cShift;
    480         LogFlowFunc(("csPlaybackBufferSize=%ld\n", pDSoundStrmOut->csPlaybackBufferSize));
     502        DSLOG(("DSound: csPlaybackBufferSize=%RU32\n", pDSoundStrmOut->csPlaybackBufferSize));
    481503
    482504    } while (0);
    483505
    484     if (SUCCEEDED(hr))
    485         return VINF_SUCCESS;
    486 
    487     dsoundPlayClose(pDSoundStrmOut);
    488     return VERR_NOT_SUPPORTED;
     506    if (FAILED(hr))
     507        directSoundPlayClose(pDSoundStrmOut);
     508
     509    return hr;
    489510}
    490511
     
    495516    LPVOID pv1, pv2;
    496517    DWORD cb1, cb2;
    497     int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props,
    498                               0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift,
    499                               &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);
    500     if (RT_SUCCESS(rc))
     518    HRESULT hr = directSoundPlayLock(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props,
     519                                     0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift,
     520                                     &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);
     521    if (SUCCEEDED(hr))
    501522    {
    502523        int len1 = cb1 >> pDSoundStrmOut->strmOut.Props.cShift;
     
    509530            drvAudioClearBuf(&pDSoundStrmOut->strmOut.Props, pv2, len2);
    510531
    511         dsoundUnlockOutput(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2);
    512     }
    513 }
    514 
    515 static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)
    516 {
    517     AssertPtrReturn(pDSB, VERR_INVALID_POINTER);
     532        directSoundPlayUnlock(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2);
     533    }
     534}
     535
     536static HRESULT directSoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)
     537{
     538    AssertPtrReturn(pDSB, E_POINTER);
    518539    /* pStatus is optional. */
    519 
    520     int rc = VINF_SUCCESS;
    521540
    522541    DWORD dwStatus = 0;
     
    526545        if ((dwStatus & DSBSTATUS_BUFFERLOST) != 0)
    527546        {
    528             rc = dsoundPlayRestore(pDSB);
    529             if (RT_SUCCESS(rc))
     547            hr = directSoundPlayRestore(pDSB);
     548            if (SUCCEEDED(hr))
    530549                hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    531550        }
    532551    }
    533552
    534     if (FAILED(hr))
    535     {
    536         LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting playback status: %Rhrc\n", hr));
    537         if (RT_SUCCESS(rc))
    538             rc = VERR_NOT_SUPPORTED;
    539     }
    540 
    541     if (RT_SUCCESS(rc))
     553    if (SUCCEEDED(hr))
    542554    {
    543555        if (pStatus)
    544556            *pStatus = dwStatus;
    545557    }
    546 
    547     return rc;
    548 }
    549 
    550 static void dsoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
     558    else
     559        DSLOGREL(("DSound: Playback GetStatus %Rhrc\n", hr));
     560
     561    return hr;
     562}
     563
     564static void directSoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    551565{
    552566    AssertPtrReturnVoid(pThis);
     
    556570    {
    557571        /* This performs some restore, so call it anyway and ignore result. */
    558         dsoundPlayGetStatus(pDSoundStrmOut->pDSB, NULL /* Status */);
    559 
    560         LogFlowFunc(("Playback stopped\n"));
     572        directSoundPlayGetStatus(pDSoundStrmOut->pDSB, NULL /* Status */);
     573
     574        DSLOG(("DSound: Stopping playback\n"));
    561575
    562576        /* @todo Wait until all data in the buffer has been played. */
    563577        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    564578        if (SUCCEEDED(hr))
    565         {
    566579            dsoundPlayClearSamples(pDSoundStrmOut);
    567         }
    568580        else
    569             LogRelMax(s_cMaxRelLogEntries, ("DSound: Errpor stopping playback buffer: %Rhrc\n", hr));
    570     }
    571 }
    572 
    573 static int dsoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut)
    574 {
    575     AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER);
    576 
    577     int rc;
    578 
     581            DSLOGREL(("DSound: Stop playback %Rhrc\n", hr));
     582    }
     583}
     584
     585static HRESULT directSoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut)
     586{
     587    AssertPtrReturn(pDSoundStrmOut, E_POINTER);
     588
     589    HRESULT hr;
    579590    if (pDSoundStrmOut->pDSB != NULL)
    580591    {
    581592        DWORD dwStatus;
    582         rc = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
    583         if (RT_SUCCESS(rc))
     593        hr = directSoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
     594        if (SUCCEEDED(hr))
    584595        {
    585596            if (dwStatus & DSBSTATUS_PLAYING)
    586597            {
    587                 LogFlowFunc(("Already playing\n"));
     598                DSLOG(("DSound: Already playing\n"));
    588599            }
    589600            else
     
    593604                pDSoundStrmOut->fRestartPlayback = true;
    594605
    595                 LogFlowFunc(("Playback started\n"));
     606                DSLOG(("DSound: Playback start\n"));
    596607
    597608                /* The actual IDirectSoundBuffer8_Play call will be made in drvHostDSoundPlayOut,
     
    602613    }
    603614    else
    604         rc = VERR_INVALID_STATE;
    605 
    606     return rc;
     615        hr = E_UNEXPECTED;
     616
     617    return hr;
    607618}
    608619
     
    645656        if (pDev)
    646657        {
    647             LogRel2(("DSound: Guest \"%s\" is using host \"%s\"\n",
    648                      drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName));
     658            DSLOG(("DSound: Guest \"%s\" is using host \"%s\"\n",
     659                   drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName));
    649660
    650661            pGUID = &pDev->Guid;
     
    653664
    654665    char *pszGUID = dsoundGUIDToUtf8StrA(pGUID);
    655     if (pszGUID)
    656     {
    657         LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n",
    658                 drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID));
    659         RTStrFree(pszGUID);
    660     }
     666    /* This always has to be in the release log. */
     667    LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n",
     668            drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID? pszGUID: "{?}"));
     669    RTStrFree(pszGUID);
    661670
    662671    return pGUID;
    663672}
    664673
    665 static void dsoundCaptureInterfaceRelease(PDSOUNDSTREAMIN pDSoundStrmIn)
     674static void directSoundCaptureInterfaceRelease(PDSOUNDSTREAMIN pDSoundStrmIn)
    666675{
    667676    if (pDSoundStrmIn->pDSC)
     
    672681}
    673682
    674 static int dsoundCaptureInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
     683static HRESULT directSoundCaptureInterfaceCreate(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    675684{
    676685    if (pDSoundStrmIn->pDSC != NULL)
    677686    {
    678         LogFunc(("DSound: DirectSoundCapture instance already exists\n"));
    679         return VINF_SUCCESS;
     687        DSLOG(("DSound: DirectSoundCapture instance already exists\n"));
     688        return S_OK;
    680689    }
    681690
     
    684693    if (FAILED(hr))
    685694    {
    686         LogRel(("DSound: Error creating capture instance: %Rhrc\n", hr));
     695        DSLOGREL(("DSound: DirectSoundCapture create %Rhrc\n", hr));
    687696    }
    688697    else
     
    692701        if (FAILED(hr))
    693702        {
    694             if (hr == DSERR_NODRIVER)
    695                 LogRel(("DSound: DirectSound capture is currently unavailable\n"));
     703            if (hr == DSERR_NODRIVER) /* Usually means that no capture devices are attached. */
     704                DSLOGREL(("DSound: DirectSound capture is currently unavailable\n"));
    696705            else
    697                 LogRel(("DSound: Error initializing capture: %Rhrc\n", hr));
    698             dsoundCaptureInterfaceRelease(pDSoundStrmIn);
    699         }
    700     }
    701 
    702     return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;
    703 }
    704 
    705 static void dsoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)
     706                DSLOGREL(("DSound: DirectSoundCapture initialize %Rhrc\n", hr));
     707
     708            directSoundCaptureInterfaceRelease(pDSoundStrmIn);
     709        }
     710    }
     711
     712    return hr;
     713}
     714
     715static void directSoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)
    706716{
    707717    AssertPtrReturnVoid(pDSoundStrmIn);
    708718
    709     LogFlowFunc(("pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));
     719    DSLOG(("DSound: pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));
    710720
    711721    if (pDSoundStrmIn->pDSCB)
    712722    {
    713723        HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
    714         if (FAILED (hr))
    715             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr));
     724        if (FAILED(hr))
     725            DSLOGREL(("DSound: Stop capture buffer %Rhrc\n", hr));
    716726
    717727        IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB);
     
    719729    }
    720730
    721     dsoundCaptureInterfaceRelease(pDSoundStrmIn);
    722 }
    723 
    724 static int dsoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    725 {
    726     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    727     AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_POINTER);
    728 
    729     LogFlowFunc(("pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
    730                  pDSoundStrmIn,
    731                  pThis->cfg.cbBufferIn,
    732                  pDSoundStrmIn->strmIn.Props.uHz,
    733                  pDSoundStrmIn->strmIn.Props.cChannels,
    734                  pDSoundStrmIn->strmIn.Props.cBits,
    735                  pDSoundStrmIn->strmIn.Props.fSigned));
     731    directSoundCaptureInterfaceRelease(pDSoundStrmIn);
     732}
     733
     734static HRESULT directSoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
     735{
     736    AssertPtrReturn(pThis, E_POINTER);
     737    AssertPtrReturn(pDSoundStrmIn, E_POINTER);
     738
     739    DSLOG(("DSound: pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
     740           pDSoundStrmIn,
     741           pThis->cfg.cbBufferIn,
     742           pDSoundStrmIn->strmIn.Props.uHz,
     743           pDSoundStrmIn->strmIn.Props.cChannels,
     744           pDSoundStrmIn->strmIn.Props.cBits,
     745           pDSoundStrmIn->strmIn.Props.fSigned));
    736746
    737747    if (pDSoundStrmIn->pDSCB != NULL)
    738748    {
    739749        /* Should not happen but be forgiving. */
    740         LogFlowFunc(("Capture buffer already exists\n"));
    741         dsoundCaptureClose(pDSoundStrmIn);
     750        DSLOGREL(("DSound: DirectSoundCaptureBuffer already exists\n"));
     751        directSoundCaptureClose(pDSoundStrmIn);
    742752    }
    743753
     
    745755    int rc = dsoundWaveFmtFromCfg(&pDSoundStrmIn->streamCfg, &wfx);
    746756    if (RT_FAILURE(rc))
    747         return rc;
    748 
    749     rc = dsoundCaptureInterfaceCreate(pThis, pDSoundStrmIn);
    750     if (RT_FAILURE(rc))
    751         return rc;
    752 
    753     HRESULT hr = S_OK;
     757        return E_INVALIDARG;
     758
     759    HRESULT hr = directSoundCaptureInterfaceCreate(pThis, pDSoundStrmIn);
     760    if (FAILED(hr))
     761        return hr;
    754762
    755763    do /* To use breaks. */
    756764    {
     765        LPDIRECTSOUNDCAPTUREBUFFER pDSCB = NULL;
    757766        DSCBUFFERDESC bd;
    758         LPDIRECTSOUNDCAPTUREBUFFER pDSCB = NULL;
    759767        RT_ZERO(bd);
    760768        bd.dwSize = sizeof(bd);
     
    765773        if (FAILED(hr))
    766774        {
    767             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating capture buffer: %Rhrc\n", hr));
    768             pDSoundStrmIn->pDSCB = NULL;
     775            DSLOGREL(("DSound: CreateCaptureBuffer %Rhrc\n", hr));
    769776            break;
    770777        }
     
    774781        if (FAILED(hr))
    775782        {
    776             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying for capture buffer interface: %Rhrc\n", hr));
    777             break;
    778         }
    779 
    780         /* Query the actual parameters. */
     783            DSLOGREL(("DSound: Query IDirectSoundCaptureBuffer8 %Rhrc\n", hr));
     784            break;
     785        }
     786
     787        /*
     788         * Query the actual parameters.
     789         */
    781790        DWORD cbReadPos = 0;
    782791        hr = IDirectSoundCaptureBuffer8_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos);
     
    784793        {
    785794            cbReadPos = 0;
    786             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current position for capture stream: %Rhrc\n", hr));
     795            DSLOGREL(("DSound: Capture (open) GetCurrentPosition %Rhrc\n", hr));
    787796        }
    788797
     
    791800        if (FAILED(hr))
    792801        {
    793             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for capture stream: %Rhrc\n", hr));
     802            DSLOGREL(("DSound: Capture GetFormat %Rhrc\n", hr));
    794803            break;
    795804        }
     
    799808        bc.dwSize = sizeof(bc);
    800809        hr = IDirectSoundCaptureBuffer8_GetCaps(pDSoundStrmIn->pDSCB, &bc);
    801         if (FAILED (hr))
    802         {
    803             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for capture stream: %Rhrc\n", hr));
    804             break;
    805         }
    806 
    807         LogFunc(("Capture format:\n"
    808                  "\tdwBufferBytes   = %RI32\n"
    809                  "\twFormatTag      = %RI16\n"
    810                  "\tnChannels       = %RI16\n"
    811                  "\tnSamplesPerSec  = %RU32\n"
    812                  "\tnAvgBytesPerSec = %RU32\n"
    813                  "\tnBlockAlign     = %RI16\n"
    814                  "\twBitsPerSample  = %RI16\n"
    815                  "\tcbSize          = %RI16\n",
    816                 bc.dwBufferBytes,
    817                 wfx.wFormatTag,
    818                 wfx.nChannels,
    819                 wfx.nSamplesPerSec,
    820                 wfx.nAvgBytesPerSec,
    821                 wfx.nBlockAlign,
    822                 wfx.wBitsPerSample,
    823                 wfx.cbSize));
     810        if (FAILED(hr))
     811        {
     812            DSLOGREL(("DSound: Capture GetCaps %Rhrc\n", hr));
     813            break;
     814        }
     815
     816        DSLOG(("DSound: Capture format:\n"
     817               dwBufferBytes   = %RI32\n"
     818               wFormatTag      = %RI16\n"
     819               nChannels       = %RI16\n"
     820               nSamplesPerSec  = %RU32\n"
     821               nAvgBytesPerSec = %RU32\n"
     822               nBlockAlign     = %RI16\n"
     823               wBitsPerSample  = %RI16\n"
     824               cbSize          = %RI16\n",
     825               bc.dwBufferBytes,
     826               wfx.wFormatTag,
     827               wfx.nChannels,
     828               wfx.nSamplesPerSec,
     829               wfx.nAvgBytesPerSec,
     830               wfx.nBlockAlign,
     831               wfx.wBitsPerSample,
     832               wfx.cbSize));
    824833
    825834        if (bc.dwBufferBytes & pDSoundStrmIn->strmIn.Props.uAlign)
    826             LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",
     835            DSLOGREL(("DSound: Capture GetCaps returned misaligned buffer: size %RU32, alignment %RU32\n",
    827836                      bc.dwBufferBytes, pDSoundStrmIn->strmIn.Props.uAlign + 1));
    828837
    829838        if (bc.dwBufferBytes != pThis->cfg.cbBufferIn)
    830             LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",
     839            DSLOGREL(("DSound: Capture buffer size mismatched: DirectSound %RU32, requested %RU32 bytes\n",
    831840                      bc.dwBufferBytes, pThis->cfg.cbBufferIn));
    832841
    833         /* Initial state: reading at the initial capture position. */
     842        /* Initial state: reading at the initial capture position, no error. */
    834843        pDSoundStrmIn->csCaptureReadPos    = cbReadPos >> pDSoundStrmIn->strmIn.Props.cShift;
    835844        pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->strmIn.Props.cShift;
    836 
    837         LogFlowFunc(("csCaptureReadPos=%ld, csCaptureBufferSize=%ld\n",
     845        pDSoundStrmIn->hrLastCaptureIn = S_OK;
     846
     847        DSLOG(("DSound: csCaptureReadPos=%RU32, csCaptureBufferSize=%RU32\n",
    838848                     pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize));
    839849
    840         /* Update status. */
    841         pDSoundStrmIn->hrLastCaptureIn = S_OK;
    842 
    843850    } while (0);
    844851
    845     if (SUCCEEDED(hr))
    846         return VINF_SUCCESS;
    847 
    848     dsoundCaptureClose(pDSoundStrmIn);
    849     return VERR_NOT_SUPPORTED;
    850 }
    851 
    852 static void dsoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn)
     852    if (FAILED(hr))
     853        directSoundCaptureClose(pDSoundStrmIn);
     854
     855    return hr;
     856}
     857
     858static void directSoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn)
    853859{
    854860    AssertPtrReturnVoid(pDSoundStrmIn);
     
    856862    if (pDSoundStrmIn->pDSCB)
    857863    {
    858         LogFlowFunc(("Capturing stopped\n"));
     864        DSLOG(("DSound: Stopping capture\n"));
    859865
    860866        HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
    861867        if (FAILED(hr))
    862             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr));
    863     }
    864 }
    865 
    866 static int dsoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
     868            DSLOGREL(("DSound: Capture buffer stop %Rhrc\n", hr));
     869    }
     870}
     871
     872static HRESULT directSoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    867873{
    868874    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     
    870876
    871877    HRESULT hr;
    872 
    873878    if (pDSoundStrmIn->pDSCB != NULL)
    874879    {
     
    877882        if (FAILED(hr))
    878883        {
    879             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting capture buffer status: %Rhrc\n", hr));
     884            DSLOGREL(("DSound: Capture start GetStatus %Rhrc\n", hr));
    880885        }
    881886        else
     
    883888            if (dwStatus & DSCBSTATUS_CAPTURING)
    884889            {
    885                 LogFlowFunc(("Already capturing\n"));
     890                DSLOG(("DSound: Already capturing\n"));
    886891            }
    887892            else
    888893            {
    889                 LogFlowFunc(("Capturig started\n"));
     894                DSLOG(("DSound: Capture start\n"));
    890895                hr = IDirectSoundCaptureBuffer8_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING);
    891                 if (FAILED (hr))
    892                     LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting capture: %Rhrc\n", hr));
     896                if (FAILED(hr))
     897                    DSLOGREL(("DSound: Capture started %Rhrc\n", hr));
    893898            }
    894899        }
     
    896901    else
    897902    {
    898         AssertMsgFailed(("No/invalid capture buffer\n"));
    899         hr = E_FAIL;
    900     }
    901 
    902     return SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;
     903        hr = E_UNEXPECTED;
     904    }
     905
     906    return hr;
    903907}
    904908
     
    942946static void dsoundLogDevice(const char *pszType, LPGUID lpGUID, LPCWSTR lpwstrDescription, LPCWSTR lpwstrModule)
    943947{
    944     AssertPtrReturnVoid(pszType);
    945     AssertPtrReturnVoid(lpGUID);
    946     AssertPtrReturnVoid(lpwstrDescription);
    947     AssertPtrReturnVoid(lpwstrModule);
    948 
    949948    char *pszGUID = dsoundGUIDToUtf8StrA(lpGUID);
    950     if (pszGUID)
    951     {
    952         LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n",
    953                 pszType, pszGUID, lpwstrDescription, lpwstrModule));
    954 
    955         RTStrFree(pszGUID);
    956     }
     949    /* This always has to be in the release log. */
     950    LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n",
     951            pszType, pszGUID? pszGUID: "{?}", lpwstrDescription, lpwstrModule));
     952    RTStrFree(pszGUID);
    957953}
    958954
     
    960956                                        LPCWSTR lpwstrModule, LPVOID lpContext)
    961957{
    962    AssertPtrReturn(lpContext, FALSE);
    963 
    964958    PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext;
    965959    AssertPtrReturn(pCtx, FALSE);
     
    971965
    972966    AssertPtrReturn(lpwstrDescription, FALSE);
    973     AssertPtrReturn(lpwstrModule, FALSE);
     967    /* Do not care about lpwstrModule */
    974968
    975969    dsoundLogDevice("Output", lpGUID, lpwstrDescription, lpwstrModule);
     
    10431037
    10441038        /* Try to open playback in case the device is already there. */
    1045         dsoundPlayOpen(pThis, pDSoundStrmOut);
     1039        directSoundPlayOpen(pThis, pDSoundStrmOut);
    10461040    }
    10471041    else
     
    10711065        {
    10721066            /* Try to start playback. If it fails, then reopen and try again. */
    1073             rc = dsoundPlayStart(pDSoundStrmOut);
    1074             if (RT_FAILURE(rc))
     1067            HRESULT hr = directSoundPlayStart(pDSoundStrmOut);
     1068            if (FAILED(hr))
    10751069            {
    1076                 dsoundPlayClose(pDSoundStrmOut);
    1077                 dsoundPlayOpen(pThis, pDSoundStrmOut);
    1078 
    1079                 rc = dsoundPlayStart(pDSoundStrmOut);
     1070                directSoundPlayClose(pDSoundStrmOut);
     1071                directSoundPlayOpen(pThis, pDSoundStrmOut);
     1072
     1073                hr = directSoundPlayStart(pDSoundStrmOut);
    10801074            }
    10811075
     1076            if (FAILED(hr))
     1077                rc = VERR_NOT_SUPPORTED;
     1078
    10821079            break;
    10831080        }
     
    10851082        case PDMAUDIOSTREAMCMD_DISABLE:
    10861083        {
    1087             dsoundPlayStop(pThis, pDSoundStrmOut);
     1084            directSoundPlayStop(pThis, pDSoundStrmOut);
    10881085            break;
    10891086        }
     
    11001097    return rc;
    11011098}
    1102 
    11031099
    11041100static DECLCALLBACK(int) drvHostDSoundPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
     
    11151111    uint32_t cReadTotal = 0;
    11161112
    1117     do
     1113    do /* to use 'break' */
    11181114    {
    11191115        LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB;
     
    11291125        if (hr == DSERR_BUFFERLOST)
    11301126        {
    1131             rc = dsoundPlayRestore(pDSB);
    1132             if (RT_FAILURE(rc))
    1133                 break;
    1134 
    1135             hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, NULL);
    1136             if (hr == DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */
    1137                 break;
     1127            hr = directSoundPlayRestore(pDSB);
     1128            if (SUCCEEDED(hr))
     1129            {
     1130                hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, NULL);
     1131            }
    11381132        }
    11391133
    11401134        if (FAILED(hr))
    11411135        {
    1142             LogRelMax(s_cMaxRelLogEntries, ("Error retrieving current playback position: %Rhrc\n", hr));
     1136            if (hr != DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */
     1137                DSLOGREL(("DSound: Playback GetCurrentPosition %Rhrc\n", hr));
    11431138            break;
    11441139        }
     
    11621157        if (cbLive == 0 || cbLive > cbBuffer)
    11631158        {
    1164             LogFlowFunc(("cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n",
    1165                          cbLive, cbBuffer, pDSoundStrmOut->cbPlayWritePos, cbPlayPos));
     1159            DSLOG(("DSound: cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n",
     1160                   cbLive, cbBuffer, pDSoundStrmOut->cbPlayWritePos, cbPlayPos));
    11661161            break;
    11671162        }
     
    11691164        LPVOID pv1, pv2;
    11701165        DWORD cb1, cb2;
    1171         rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive,
    1172                               &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
    1173         if (RT_FAILURE(rc))
     1166        hr = directSoundPlayLock(pDSB, &pHstStrmOut->Props, pDSoundStrmOut->cbPlayWritePos, cbLive,
     1167                                 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
     1168        if (FAILED(hr))
    11741169            break;
    11751170
     
    11951190        }
    11961191
    1197         dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);
     1192        directSoundPlayUnlock(pDSB, pv1, pv2, cb1, cb2);
    11981193
    11991194        pDSoundStrmOut->cbPlayWritePos = (pDSoundStrmOut->cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer;
    12001195
    1201         LogFlowFunc(("%RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n",
    1202                      AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive,
    1203                      cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "",
    1204                      pDSoundStrmOut->cbPlayWritePos, rc));
     1196        DSLOGF(("DSound: %RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n",
     1197                AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive,
     1198                cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "",
     1199                pDSoundStrmOut->cbPlayWritePos, rc));
    12051200
    12061201        if (cReadTotal)
     
    12091204            rc = VINF_SUCCESS; /* Played something. */
    12101205        }
     1206
     1207        if (RT_FAILURE(rc))
     1208            break;
    12111209
    12121210        if (pDSoundStrmOut->fRestartPlayback)
     
    12171215             */
    12181216            pDSoundStrmOut->fRestartPlayback = false;
    1219             HRESULT hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);
     1217            hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);
    12201218            if (FAILED(hr))
    12211219            {
    1222                 LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting playback: %Rhrc\n", hr));
     1220                DSLOGREL(("DSound: Playback start %Rhrc\n", hr));
    12231221                rc = VERR_NOT_SUPPORTED;
    12241222            }
     
    12371235    PDSOUNDSTREAMOUT pDSoundStrmOut = (PDSOUNDSTREAMOUT)pHstStrmOut;
    12381236
    1239     dsoundPlayClose(pDSoundStrmOut);
     1237    directSoundPlayClose(pDSoundStrmOut);
    12401238
    12411239    pDSoundStrmOut->cbPlayWritePos = 0;
     
    12771275
    12781276        /* Try to open capture in case the device is already there. */
    1279         dsoundCaptureOpen(pThis, pDSoundStrmIn);
     1277        directSoundCaptureOpen(pThis, pDSoundStrmIn);
    12801278    }
    12811279    else
     
    13061304        {
    13071305            /* Try to start capture. If it fails, then reopen and try again. */
    1308             rc = dsoundCaptureStart(pThis, pDSoundStrmIn);
    1309             if (RT_FAILURE(rc))
     1306            HRESULT hr = directSoundCaptureStart(pThis, pDSoundStrmIn);
     1307            if (FAILED(hr))
    13101308            {
    1311                 dsoundCaptureClose(pDSoundStrmIn);
    1312                 dsoundCaptureOpen(pThis, pDSoundStrmIn);
    1313 
    1314                 rc = dsoundCaptureStart(pThis, pDSoundStrmIn);
     1309                directSoundCaptureClose(pDSoundStrmIn);
     1310                directSoundCaptureOpen(pThis, pDSoundStrmIn);
     1311
     1312                hr = directSoundCaptureStart(pThis, pDSoundStrmIn);
    13151313            }
     1314
     1315            if (FAILED(hr))
     1316                rc = VERR_NOT_SUPPORTED;
    13161317        } break;
    13171318
    13181319        case PDMAUDIOSTREAMCMD_DISABLE:
    13191320        {
    1320             dsoundCaptureStop(pDSoundStrmIn);
     1321            directSoundCaptureStop(pDSoundStrmIn);
    13211322        } break;
    13221323
     
    13381339    LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB = pDSoundStrmIn->pDSCB;
    13391340
    1340     int rc;
     1341    int rc = VINF_SUCCESS;
    13411342
    13421343    if (pDSCB == NULL)
     
    13541355        if (hr != pDSoundStrmIn->hrLastCaptureIn)
    13551356        {
    1356             LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current capture position: %Rhrc\n", hr));
     1357            DSLOGREL(("DSound: Capture GetCurrentPosition %Rhrc\n", hr));
    13571358            pDSoundStrmIn->hrLastCaptureIn = hr;
    13581359        }
     
    13651366
    13661367    if (cbReadPos & pHstStrmIn->Props.uAlign)
    1367         LogFunc(("Misaligned read position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign));
     1368        DSLOGF(("DSound: Misaligned capture read position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign));
    13681369
    13691370    /* Capture position in samples. */
     
    13861387    if (csMixFree == 0)
    13871388    {
    1388         LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer full\n"));
     1389        DSLOGF(("DSound: Capture buffer full\n"));
    13891390        if (pcSamplesCaptured)
    13901391            *pcSamplesCaptured = 0;
     
    13921393    }
    13931394
    1394     LogFlowFunc(("csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n",
    1395                  csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured));
     1395    DSLOGF(("DSound: Capture csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n",
     1396            csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured));
    13961397
    13971398    /* No need to fetch more samples than mix buffer can receive. */
     
    14011402    LPVOID pv1, pv2;
    14021403    DWORD cb1, cb2;
    1403     rc = dsoundLockInput(pDSCB, &pHstStrmIn->Props,
    1404                          pDSoundStrmIn->csCaptureReadPos << pHstStrmIn->Props.cShift,
    1405                          csCaptured << pHstStrmIn->Props.cShift,
    1406                          &pv1, &pv2, &cb1, &cb2,
    1407                          0 /* dwFlags */);
    1408     if (RT_FAILURE(rc))
     1404    hr = directSoundCaptureLock(pDSCB, &pHstStrmIn->Props,
     1405                                pDSoundStrmIn->csCaptureReadPos << pHstStrmIn->Props.cShift,
     1406                                csCaptured << pHstStrmIn->Props.cShift,
     1407                                &pv1, &pv2, &cb1, &cb2,
     1408                                0 /* dwFlags */);
     1409    if (FAILED(hr))
    14091410    {
    14101411        if (pcSamplesCaptured)
     
    14361437    }
    14371438
    1438     dsoundUnlockInput(pDSCB, pv1, pv2, cb1, cb2);
     1439    directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2);
    14391440
    14401441    uint32_t csProcessed = 0;
     
    14491450    {
    14501451        pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + csProcessed) % pDSoundStrmIn->csCaptureBufferSize;
    1451         LogFlowFunc(("%ld (%ld+%ld), processed %RU32/%RU32\n",
    1452                      csCaptured, len1, len2, csProcessed, csWrittenTotal));
     1452        DSLOGF(("DSound: Capture %ld (%ld+%ld), processed %RU32/%RU32\n",
     1453                csCaptured, len1, len2, csProcessed, csWrittenTotal));
    14531454    }
    14541455
     
    14641465    PDSOUNDSTREAMIN pDSoundStrmIn = (PDSOUNDSTREAMIN)pHstStrmIn;
    14651466
    1466     dsoundCaptureClose(pDSoundStrmIn);
     1467    directSoundCaptureClose(pDSoundStrmIn);
    14671468
    14681469    pDSoundStrmIn->csCaptureReadPos    = 0;
     
    15291530    {
    15301531        /* No dsound.dll on this system.  */
    1531         LogRel(("DSound: could not load dsound.dll %Rrc\n", rc));
     1532        LogRel(("DSound: Could not load dsound.dll %Rrc\n", rc));
    15321533    }
    15331534
     
    15661567        IDirectSound_Release(pDirectSound);
    15671568    else
    1568         LogRel(("DSound: DirectSound not available: %Rhrc\n", hr));
     1569        DSLOGREL(("DSound: DirectSound not available %Rhrc\n", hr));
    15691570
    15701571    int rc = SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;
     
    15921593    if (RT_SUCCESS(rc))
    15931594    {
    1594         int rc = RTUuidFromStr(pUuid, pszGuid);
     1595        rc = RTUuidFromStr(pUuid, pszGuid);
    15951596        if (RT_SUCCESS(rc))
    15961597            pGuid = (LPCGUID)&pUuid;
    15971598        else
    1598             LogRel(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc));
     1599            DSLOGREL(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc));
    15991600
    16001601        RTStrFree(pszGuid);
     
    16161617    pThis->cfg.pGuidCapture = dsoundConfigQueryGUID(pCfg, "DeviceGuidIn",  &pThis->cfg.uuidCapture);
    16171618
    1618     LogFlowFunc(("BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",
    1619                  pThis->cfg.cbBufferOut,
    1620                  pThis->cfg.cbBufferIn,
    1621                  &pThis->cfg.uuidPlay,
    1622                  &pThis->cfg.uuidCapture));
     1619    DSLOG(("DSound: BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",
     1620           pThis->cfg.cbBufferOut,
     1621           pThis->cfg.cbBufferIn,
     1622           &pThis->cfg.uuidPlay,
     1623           &pThis->cfg.uuidCapture));
    16231624}
    16241625
     
    16431644{
    16441645    PDRVHOSTDSOUND pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTDSOUND);
     1646
    16451647    LogRel(("Audio: Initializing DirectSound audio driver\n"));
     1648
    16461649    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
    16471650
     
    16491652    if (FAILED(hr))
    16501653    {
    1651         LogRel(("DSound: Error initializing COM: %Rhrc\n", hr));
     1654        DSLOGREL(("DSound: CoInitializeEx %Rhrc\n", hr));
    16521655        return VERR_NOT_SUPPORTED;
    16531656    }
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