VirtualBox

Changeset 57375 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 17, 2015 11:16:04 AM (9 years ago)
Author:
vboxsync
Message:

Audio/DSound: Get rid of custom logging and use RTLogRelMax* instead, a lot of logging format fixes.

File:
1 edited

Legend:

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

    r57234 r57375  
    2828#include "VBoxDD.h"
    2929
    30 #define DSLOG(a) do { LogRel2(a); } while(0)
    31 #define DSLOGF(a) do { LogRel3(a); } while(0)
    32 #define DSLOGREL(a)                 \
    33     do {                            \
    34         static int8_t scLogged = 0; \
    35         if (scLogged < 8) {         \
    36             ++scLogged;             \
    37             LogRel(a);              \
    38         }                           \
    39         else {                      \
    40             DSLOG(a);               \
    41         }                           \
    42     } while (0)
    43 
    4430typedef struct DSOUNDHOSTCFG
    4531{
     
    6248    /** List of found host output devices. */
    6349    RTLISTANCHOR  lstDevOutput;
    64     /** Configuration options. */
     50    /** DirectSound configuration options. */
    6551    DSOUNDHOSTCFG cfg;
    6652} DRVHOSTDSOUND, *PDRVHOSTDSOUND;
     
    6854typedef struct DSOUNDSTREAMOUT
    6955{
    70     PDMAUDIOHSTSTRMOUT   hw; /* Always must come first! */
     56    PDMAUDIOHSTSTRMOUT   strmOut; /* Always must come first! */
    7157    LPDIRECTSOUND8       pDS;
    7258    LPDIRECTSOUNDBUFFER8 pDSB;
     
    7965typedef struct DSOUNDSTREAMIN
    8066{
    81     PDMAUDIOHSTSTRMIN           hw; /* Always must come first! */
     67    PDMAUDIOHSTSTRMIN           strmIn; /* Always must come first! */
    8268    LPDIRECTSOUNDCAPTURE8       pDSC;
    8369    LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB;
     
    10591} DSOUNDDEV, *PDSOUNDDEV;
    10692
     93/** Maximum number of release logging entries. */
     94static uint32_t s_cMaxRelLogEntries = 32;
     95
    10796/** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */
    10897#define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \
     
    157146static char *dsoundGUIDToUtf8StrA(LPCGUID lpGUID)
    158147{
    159     LPOLESTR lpOLEStr;
    160     HRESULT hr = StringFromCLSID(*lpGUID, &lpOLEStr);
    161     if (SUCCEEDED(hr))
    162     {
    163         char *pszGUID;
    164         int rc = RTUtf16ToUtf8(lpOLEStr, &pszGUID);
    165         CoTaskMemFree(lpOLEStr);
    166 
    167         return RT_SUCCESS(rc) ? pszGUID : NULL;
    168     }
    169 
    170     return NULL;
     148    if (lpGUID)
     149    {
     150        LPOLESTR lpOLEStr;
     151        HRESULT hr = StringFromCLSID(*lpGUID, &lpOLEStr);
     152        if (SUCCEEDED(hr))
     153        {
     154            char *pszGUID;
     155            int rc = RTUtf16ToUtf8(lpOLEStr, &pszGUID);
     156            CoTaskMemFree(lpOLEStr);
     157
     158            return RT_SUCCESS(rc) ? pszGUID : NULL;
     159        }
     160    }
     161
     162    return RTStrDup("<GUID not found>");
    171163}
    172164
     
    193185        return VINF_SUCCESS;
    194186
    195     DSLOGREL(("DSound: Restore playback buffer %Rhrc\n", hr));
     187    LogRelMax(s_cMaxRelLogEntries, ("DSound: Error restoring playback buffer: %Rhrc\n", hr));
    196188    return VERR_INVALID_STATE;
    197189}
     
    205197        return VINF_SUCCESS;
    206198
    207     DSLOG(("DSound: Unable to unlock output buffer, hr=%Rhrc\n", hr));
     199    LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking output buffer: %Rhrc\n", hr));
    208200    return VERR_ACCESS_DENIED;
    209201}
     
    217209        return VINF_SUCCESS;
    218210
    219     DSLOG(("DSound: Unable to unlock input buffer, hr=%Rhrc\n", hr));
     211    LogRelMax(s_cMaxRelLogEntries, ("DSound: Error unlocking input buffer: %Rhrc\n", hr));
    220212    return VERR_ACCESS_DENIED;
    221213}
     
    241233        {
    242234            hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
    243         }
    244     }
    245 
    246     if (FAILED(hr) || RT_FAILURE(rc))
    247     {
    248         DSLOG(("DSound: Unable to lock output buffer, hr=%Rhrc\n", hr));
    249         return RT_SUCCESS(rc) ? VERR_ACCESS_DENIED: rc;
     235            if (FAILED(hr))
     236                rc = VERR_ACCESS_DENIED;
     237        }
     238    }
     239
     240    if (RT_FAILURE(rc))
     241    {
     242        LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking output buffer: %Rhrc\n", hr));
     243        return rc;
    250244    }
    251245
     
    253247        || (pv2 && (cb2 & pProps->uAlign)))
    254248    {
    255         DSLOG(("DSound: lock output returned misaligned buffer: cb1=%d, cb2=%d\n", cb1, cb2));
     249        LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
     250                       cb1, cb2, pProps->uAlign));
    256251        dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);
    257252        return VERR_INVALID_STATE;
     
    281276    if (FAILED(hr))
    282277    {
    283         DSLOG(("DSound: Unable to lock capturing buffer, hr=%Rhrc\n", hr));
     278        LogRelMax(s_cMaxRelLogEntries, ("DSound: Error locking capturing buffer: %Rhrc\n", hr));
    284279        return VERR_ACCESS_DENIED;
    285280    }
     
    288283        || (pv2 && (cb2 & pProps->uAlign)))
    289284    {
    290         DSLOG(("DSound: lock input returned misaligned buffer: cb1=%d, cb2=%d\n", cb1, cb2));
     285        LogRelMax(s_cMaxRelLogEntries, ("DSound: Locking capture buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
     286                       cb1, cb2, pProps->uAlign));
    291287        dsoundUnlockInput(pDSCB, pv1, pv2, cb1, cb2);
    292288        return VERR_INVALID_PARAMETER;
     
    319315    if (pDSoundStrmOut->pDS != NULL)
    320316    {
    321         DSLOG(("DSound: DirectSound instance already exists\n"));
     317        LogFlowFunc(("DirectSound instance already exists\n"));
    322318        return VINF_SUCCESS;
    323319    }
     
    327323    if (FAILED(hr))
    328324    {
    329         DSLOGREL(("DSound: DirectSound create instance %Rhrc\n", hr));
     325        LogRel(("DSound: Error creating DirectSound instance: %Rhrc\n", hr));
    330326    }
    331327    else
     
    334330        if (SUCCEEDED(hr))
    335331        {
    336             HWND hwnd = GetDesktopWindow();
    337             hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hwnd, DSSCL_PRIORITY);
    338             if (FAILED (hr))
    339             {
    340                 DSLOGREL(("DSound: Set cooperative level for window %p %Rhrc\n", hwnd, hr));
    341             }
     332            HWND hWnd = GetDesktopWindow();
     333            hr = IDirectSound8_SetCooperativeLevel(pDSoundStrmOut->pDS, hWnd, DSSCL_PRIORITY);
     334            if (FAILED(hr))
     335                LogRel(("DSound: Error setting cooperative level for window %p: %Rhrc\n", hWnd, hr));
    342336        }
    343337        if (FAILED(hr))
    344338        {
    345339            if (hr == DSERR_NODRIVER)
    346             {
    347                 DSLOGREL(("DSound: DirectSound playback is currently unavailable\n"));
    348             }
     340                LogRel(("DSound: DirectSound playback is currently unavailable\n"));
    349341            else
    350             {
    351                 DSLOGREL(("DSound: DirectSound initialize %Rhrc\n", hr));
    352             }
     342                LogRel(("DSound: Error initializing DirectSound: %Rhrc\n", hr));
     343
    353344            dsoundPlayInterfaceRelease(pDSoundStrmOut);
    354345        }
     
    360351static void dsoundPlayClose(PDSOUNDSTREAMOUT pDSoundStrmOut)
    361352{
    362     DSLOG(("DSound: playback close %p buffer %p\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));
     353    LogFlowFunc(("Closing playback stream %p (buffer %p)\n", pDSoundStrmOut, pDSoundStrmOut->pDSB));
    363354
    364355    if (pDSoundStrmOut->pDSB)
     
    366357        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    367358        if (FAILED(hr))
    368         {
    369             DSLOGREL(("DSound: Playback close Stop %Rhrc\n", hr));
    370         }
     359            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error closing playback stream %p: %Rhrc\n", pDSoundStrmOut, hr));
    371360
    372361        IDirectSoundBuffer8_Release(pDSoundStrmOut->pDSB);
     
    379368static int dsoundPlayOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    380369{
    381     DSLOG(("DSound: playback open %p size %u bytes, freq %u, chan %u, bits %u, sign %d\n",
    382            pDSoundStrmOut,
    383            pThis->cfg.cbBufferOut,
    384            pDSoundStrmOut->hw.Props.uHz,
    385            pDSoundStrmOut->hw.Props.cChannels,
    386            pDSoundStrmOut->hw.Props.cBits,
    387            pDSoundStrmOut->hw.Props.fSigned));
     370    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     371    AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER);
     372
     373    LogFlowFunc(("pDSoundStrmOut=%p, cbBufferOut=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
     374                 pDSoundStrmOut,
     375                 pThis->cfg.cbBufferOut,
     376                 pDSoundStrmOut->strmOut.Props.uHz,
     377                 pDSoundStrmOut->strmOut.Props.cChannels,
     378                 pDSoundStrmOut->strmOut.Props.cBits,
     379                 pDSoundStrmOut->strmOut.Props.fSigned));
    388380
    389381    if (pDSoundStrmOut->pDSB != NULL)
    390382    {
    391383        /* Should not happen but be forgiving. */
    392         DSLOGREL(("DSound: DirectSoundBuffer already exists\n"));
     384        LogFlowFunc(("DirectSoundBuffer already exists\n"));
    393385        dsoundPlayClose(pDSoundStrmOut);
    394386    }
     
    418410        if (FAILED(hr))
    419411        {
    420             DSLOGREL(("DSound: Playback CreateSoundBuffer %Rhrc\n", hr));
     412            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating playback stream: %Rhrc\n", hr));
    421413            break;
    422414        }
     
    426418        if (FAILED(hr))
    427419        {
    428             DSLOGREL(("DSound: Playback QueryInterface %Rhrc\n", hr));
     420            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying interface for playback stream: %Rhrc\n", hr));
    429421            break;
    430422        }
    431423
    432424        /* Query the actual parameters. */
    433 
    434425        hr = IDirectSoundBuffer8_GetFormat(pDSoundStrmOut->pDSB, &wfx, sizeof(wfx), NULL);
    435426        if (FAILED(hr))
    436427        {
    437             DSLOGREL(("DSound: Playback GetFormat %Rhrc\n", hr));
     428            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for playback stream: %Rhrc\n", hr));
    438429            break;
    439430        }
     
    445436        if (FAILED(hr))
    446437        {
    447             DSLOGREL(("DSound: Playback GetCaps %Rhrc\n", hr));
     438            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for playback stream: %Rhrc\n", hr));
    448439            break;
    449440        }
    450441
    451         DSLOG(("DSound: playback format: size %d bytes\n"
    452                 "  tag             = %d\n"
    453                 "  nChannels       = %d\n"
    454                 "  nSamplesPerSec  = %d\n"
    455                 "  nAvgBytesPerSec = %d\n"
    456                 "  nBlockAlign     = %d\n"
    457                 "  wBitsPerSample  = %d\n"
    458                 "  cbSize          = %d\n",
     442        LogFunc(("Playback format:\n"
     443                 "\tdwBufferBytes   = %RI32\n"
     444                 "\twFormatTag      = %RI16\n"
     445                 "\tnChannels       = %RI16\n"
     446                 "\tnSamplesPerSec  = %RU32\n"
     447                 "\tnAvgBytesPerSec = %RU32\n"
     448                 "\tnBlockAlign     = %RI16\n"
     449                 "\twBitsPerSample  = %RI16\n"
     450                 "\tcbSize          = %RI16\n",
    459451                bc.dwBufferBytes,
    460452                wfx.wFormatTag,
     
    466458                wfx.cbSize));
    467459
    468         if (bc.dwBufferBytes & pDSoundStrmOut->hw.Props.uAlign)
    469         {
    470             DSLOGREL(("DSound: Playback GetCaps returned misaligned buffer size %ld, alignment %d\n",
    471                       bc.dwBufferBytes, pDSoundStrmOut->hw.Props.uAlign + 1));
    472         }
     460        if (bc.dwBufferBytes & pDSoundStrmOut->strmOut.Props.uAlign)
     461            LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",
     462                           bc.dwBufferBytes, pDSoundStrmOut->strmOut.Props.uAlign + 1));
    473463
    474464        if (bc.dwBufferBytes != pThis->cfg.cbBufferOut)
    475         {
    476             DSLOGREL(("DSound: Playback buffer size mismatch dsound %d, requested %d bytes\n",
    477                       bc.dwBufferBytes, pThis->cfg.cbBufferOut));
    478         }
    479 
    480         /* Initial state.
     465            LogRelMax(s_cMaxRelLogEntries, ("DSound: Playback buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",
     466                           bc.dwBufferBytes, pThis->cfg.cbBufferOut));
     467
     468        /*
     469         * Initial state.
    481470         * dsoundPlayStart initializes part of it to make sure that Stop/Start continues with a correct
    482471         * playback buffer position.
    483472         */
    484         pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->hw.Props.cShift;
    485         DSLOG(("DSound: playback open csPlaybackBufferSize %d samples\n", pDSoundStrmOut->csPlaybackBufferSize));
     473        pDSoundStrmOut->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStrmOut->strmOut.Props.cShift;
     474        LogFlowFunc(("csPlaybackBufferSize=%ld\n", pDSoundStrmOut->csPlaybackBufferSize));
     475
    486476    } while (0);
    487477
     
    495485static void dsoundPlayClearSamples(PDSOUNDSTREAMOUT pDSoundStrmOut)
    496486{
     487    AssertPtrReturnVoid(pDSoundStrmOut);
     488
    497489    LPVOID pv1, pv2;
    498490    DWORD cb1, cb2;
    499     int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut->hw.Props,
    500                               0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->hw.Props.cShift,
     491    int rc = dsoundLockOutput(pDSoundStrmOut->pDSB, &pDSoundStrmOut->strmOut.Props,
     492                              0, pDSoundStrmOut->csPlaybackBufferSize << pDSoundStrmOut->strmOut.Props.cShift,
    501493                              &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);
    502494    if (RT_SUCCESS(rc))
    503495    {
    504         int len1 = cb1 >> pDSoundStrmOut->hw.Props.cShift;
    505         int len2 = cb2 >> pDSoundStrmOut->hw.Props.cShift;
     496        int len1 = cb1 >> pDSoundStrmOut->strmOut.Props.cShift;
     497        int len2 = cb2 >> pDSoundStrmOut->strmOut.Props.cShift;
    506498
    507499        if (pv1 && len1)
    508             audio_pcm_info_clear_buf(&pDSoundStrmOut->hw.Props, pv1, len1);
     500            audio_pcm_info_clear_buf(&pDSoundStrmOut->strmOut.Props, pv1, len1);
    509501
    510502        if (pv2 && len2)
    511             audio_pcm_info_clear_buf(&pDSoundStrmOut->hw.Props, pv2, len2);
     503            audio_pcm_info_clear_buf(&pDSoundStrmOut->strmOut.Props, pv2, len2);
    512504
    513505        dsoundUnlockOutput(pDSoundStrmOut->pDSB, pv1, pv2, cb1, cb2);
     
    517509static int dsoundPlayGetStatus(LPDIRECTSOUNDBUFFER8 pDSB, DWORD *pStatus)
    518510{
     511    AssertPtrReturn(pDSB, VERR_INVALID_POINTER);
     512    /* pStatus is optional. */
     513
    519514    int rc = VINF_SUCCESS;
    520515
     
    527522            rc = dsoundPlayRestore(pDSB);
    528523            if (RT_SUCCESS(rc))
    529             {
    530524                hr = IDirectSoundBuffer8_GetStatus(pDSB, &dwStatus);
    531             }
    532525        }
    533526    }
     
    535528    if (FAILED(hr))
    536529    {
    537         DSLOG(("DSound: playback GetStatus %Rhrc\n", hr));
     530        LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting playback status: %Rhrc\n", hr));
    538531        if (RT_SUCCESS(rc))
    539         {
    540532            rc = VERR_NOT_SUPPORTED;
    541         }
    542533    }
    543534
    544535    if (RT_SUCCESS(rc))
    545536    {
    546         *pStatus = dwStatus;
     537        if (pStatus)
     538            *pStatus = dwStatus;
    547539    }
    548540
     
    552544static void dsoundPlayStop(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMOUT pDSoundStrmOut)
    553545{
     546    AssertPtrReturnVoid(pThis);
     547    AssertPtrReturnVoid(pDSoundStrmOut);
     548
    554549    if (pDSoundStrmOut->pDSB != NULL)
    555550    {
     
    558553        dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
    559554
    560         DSLOG(("DSound: playback stop\n"));
     555        LogFlowFunc(("Playback stopped\n"));
    561556
    562557        HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
    563558        if (FAILED(hr))
    564         {
    565             DSLOG(("DSound: stop playback buffer %Rhrc\n", hr));
    566         }
     559            LogRelMax(s_cMaxRelLogEntries, ("DSound: Errpor stopping playback buffer: %Rhrc\n", hr));
    567560    }
    568561}
     
    570563static int dsoundPlayStart(PDSOUNDSTREAMOUT pDSoundStrmOut)
    571564{
    572     int rc = VINF_SUCCESS;
     565    AssertPtrReturn(pDSoundStrmOut, VERR_INVALID_POINTER);
     566
     567    int rc;
    573568
    574569    if (pDSoundStrmOut->pDSB != NULL)
    575570    {
    576571        DWORD dwStatus;
    577         int rc2 = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
    578         if (RT_FAILURE(rc2))
    579         {
    580             DSLOG(("DSound: playback start GetStatus %Rrc\n", rc2));
    581             rc = rc2;   /* Propagate error. */
    582         }
    583         else
     572        rc = dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
     573        if (RT_SUCCESS(rc))
    584574        {
    585575            if (dwStatus & DSBSTATUS_PLAYING)
    586576            {
    587                 DSLOG(("DSound: already playing\n"));
     577                LogFlowFunc(("Already playing\n"));
    588578            }
    589579            else
     
    593583                pDSoundStrmOut->fReinitPlayPos = true;
    594584
    595                 DSLOG(("DSound: playback start\n"));
     585                LogFlowFunc(("Playback started\n"));
    596586
    597587                HRESULT hr = IDirectSoundBuffer8_Play(pDSoundStrmOut->pDSB, 0, 0, DSBPLAY_LOOPING);
    598588                if (FAILED(hr))
    599589                {
    600                     DSLOGREL(("DSound: Playback start %Rhrc\n", hr));
     590                    LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting playback: %Rhrc\n", hr));
    601591                    rc = VERR_NOT_SUPPORTED;
    602592                }
     
    605595    }
    606596    else
    607     {
    608597        rc = VERR_INVALID_STATE;
    609     }
    610598
    611599    return rc;
     
    618606static LPCGUID dsoundCaptureSelectDevice(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    619607{
     608    AssertPtrReturn(pThis, NULL);
     609    AssertPtrReturn(pDSoundStrmIn, NULL);
     610
    620611    LPCGUID pGUID = pThis->cfg.pGuidCapture;
    621612
     
    630621                RTListForEach(&pThis->lstDevInput, pDev, DSOUNDDEV, Node)
    631622                {
    632                     if (RTStrIStr(pDev->pszName, "Mic"))    /** @todo what is with non en_us windows versions? */
     623                    if (RTStrIStr(pDev->pszName, "Mic")) /** @todo what is with non en_us windows versions? */
    633624                        break;
    634625                }
    635626                if (RTListNodeIsDummy(&pThis->lstDevInput, pDev, DSOUNDDEV, Node))
    636627                    pDev = NULL;    /* Found nothing. */
    637             } break;
     628
     629                break;
     630            }
    638631
    639632            case PDMAUDIORECSOURCE_LINE_IN:
     
    645638        if (pDev)
    646639        {
    647             DSLOG(("DSound: Guest \"%s\" is using host \"%s\"\n",
    648                    drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName));
     640            LogRel2(("DSound: Guest \"%s\" is using host \"%s\"\n",
     641                     drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pDev->pszName));
    649642
    650643            pGUID = &pDev->Guid;
     
    653646
    654647    char *pszGUID = dsoundGUIDToUtf8StrA(pGUID);
    655     LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n",
    656            drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID ? pszGUID : "NULL"));
    657     RTStrFree(pszGUID);
     648    if (pszGUID)
     649    {
     650        LogRel(("DSound: Guest \"%s\" is using host device with GUID: %s\n",
     651                drvAudioRecSourceToString(pDSoundStrmIn->enmRecSource), pszGUID));
     652        RTStrFree(pszGUID);
     653    }
    658654
    659655    return pGUID;
     
    673669    if (pDSoundStrmIn->pDSC != NULL)
    674670    {
    675         DSLOG(("DSound: DirectSoundCapture instance already exists\n"));
     671        LogFunc(("DSound: DirectSoundCapture instance already exists\n"));
    676672        return VINF_SUCCESS;
    677673    }
     
    681677    if (FAILED(hr))
    682678    {
    683         DSLOGREL(("DSound: DirectSoundCapture create instance %Rhrc\n", hr));
     679        LogRel(("DSound: Error creating capture instance: %Rhrc\n", hr));
    684680    }
    685681    else
     
    690686        {
    691687            if (hr == DSERR_NODRIVER)
    692             {
    693                 DSLOGREL(("DSound: DirectSound capture is currently unavailable\n"));
    694             }
     688                LogRel(("DSound: DirectSound capture is currently unavailable\n"));
    695689            else
    696             {
    697                 DSLOGREL(("DSound: DirectSoundCapture initialize %Rhrc\n", hr));
    698             }
     690                LogRel(("DSound: Error initializing capture: %Rhrc\n", hr));
    699691            dsoundCaptureInterfaceRelease(pDSoundStrmIn);
    700692        }
     
    706698static void dsoundCaptureClose(PDSOUNDSTREAMIN pDSoundStrmIn)
    707699{
    708     DSLOG(("DSound: capture close %p buffer %p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));
     700    AssertPtrReturnVoid(pDSoundStrmIn);
     701
     702    LogFlowFunc(("pDSoundStrmIn=%p, pDSCB=%p\n", pDSoundStrmIn, pDSoundStrmIn->pDSCB));
    709703
    710704    if (pDSoundStrmIn->pDSCB)
     
    712706        HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
    713707        if (FAILED (hr))
    714         {
    715             DSLOG(("DSound: close capture buffer stop %Rhrc\n", hr));
    716         }
     708            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr));
    717709
    718710        IDirectSoundCaptureBuffer8_Release(pDSoundStrmIn->pDSCB);
     
    725717static int dsoundCaptureOpen(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    726718{
    727     DSLOG(("DSound: capture open %p size %u bytes freq %u, chan %u, bits %u, sign %d\n",
    728            pDSoundStrmIn,
    729            pThis->cfg.cbBufferIn,
    730            pDSoundStrmIn->hw.Props.uHz,
    731            pDSoundStrmIn->hw.Props.cChannels,
    732            pDSoundStrmIn->hw.Props.cBits,
    733            pDSoundStrmIn->hw.Props.fSigned));
     719    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     720    AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_PARAMETER);
     721
     722    LogFlowFunc(("pDSoundStrmIn=%p, cbBufferIn=%ld, uHz=%RU32, cChannels=%RU8, cBits=%RU8, fSigned=%RTbool\n",
     723                 pDSoundStrmIn,
     724                 pThis->cfg.cbBufferIn,
     725                 pDSoundStrmIn->strmIn.Props.uHz,
     726                 pDSoundStrmIn->strmIn.Props.cChannels,
     727                 pDSoundStrmIn->strmIn.Props.cBits,
     728                 pDSoundStrmIn->strmIn.Props.fSigned));
    734729
    735730    if (pDSoundStrmIn->pDSCB != NULL)
    736731    {
    737732        /* Should not happen but be forgiving. */
    738         DSLOGREL(("DSound: DirectSoundCaptureBuffer already exists\n"));
     733        LogFlowFunc(("Capture buffer already exists\n"));
    739734        dsoundCaptureClose(pDSoundStrmIn);
    740735    }
     
    761756        hr = IDirectSoundCapture_CreateCaptureBuffer(pDSoundStrmIn->pDSC,
    762757                                                     &bd, &pDSCB, NULL);
    763 
    764758        if (FAILED(hr))
    765759        {
    766             DSLOGREL(("DSound: Create capture buffer %Rhrc\n", hr));
     760            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error creating capture buffer: %Rhrc\n", hr));
    767761            pDSoundStrmIn->pDSCB = NULL;
    768762            break;
     
    773767        if (FAILED(hr))
    774768        {
    775             DSLOGREL(("DSound: Querying capture buffer %Rhrc\n", hr));
     769            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying for capture buffer interface: %Rhrc\n", hr));
    776770            break;
    777771        }
    778772
    779773        /* Query the actual parameters. */
    780 
    781774        DWORD cbReadPos = 0;
    782775        hr = IDirectSoundCaptureBuffer8_GetCurrentPosition(pDSoundStrmIn->pDSCB, NULL, &cbReadPos);
     
    784777        {
    785778            cbReadPos = 0;
    786             DSLOG(("DSound: open GetCurrentPosition %Rhrc\n", hr));
     779            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current position for capture stream: %Rhrc\n", hr));
    787780        }
    788781
     
    791784        if (FAILED(hr))
    792785        {
    793             DSLOGREL(("DSound: Capture buffer GetFormat %Rhrc\n", hr));
     786            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying format for capture stream: %Rhrc\n", hr));
    794787            break;
    795788        }
     
    801794        if (FAILED (hr))
    802795        {
    803             DSLOGREL(("DSound: Capture buffer GetCaps %Rhrc\n", hr));
     796            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error querying capabilities for capture stream: %Rhrc\n", hr));
    804797            break;
    805798        }
    806799
    807         DSLOG(("DSound: capture buffer format: size %d bytes\n"
    808                 "  tag             = %d\n"
    809                 "  nChannels       = %d\n"
    810                 "  nSamplesPerSec  = %d\n"
    811                 "  nAvgBytesPerSec = %d\n"
    812                 "  nBlockAlign     = %d\n"
    813                 "  wBitsPerSample  = %d\n"
    814                 "  cbSize          = %d\n",
     800        LogFunc(("Capture format:\n"
     801                 "\tdwBufferBytes   = %RI32\n"
     802                 "\twFormatTag      = %RI16\n"
     803                 "\tnChannels       = %RI16\n"
     804                 "\tnSamplesPerSec  = %RU32\n"
     805                 "\tnAvgBytesPerSec = %RU32\n"
     806                 "\tnBlockAlign     = %RI16\n"
     807                 "\twBitsPerSample  = %RI16\n"
     808                 "\tcbSize          = %RI16\n",
    815809                bc.dwBufferBytes,
    816810                wfx.wFormatTag,
     
    822816                wfx.cbSize));
    823817
    824         if (bc.dwBufferBytes & pDSoundStrmIn->hw.Props.uAlign)
    825         {
    826             DSLOGREL(("DSound: GetCaps returned misaligned buffer size %ld, alignment %d\n",
    827                       bc.dwBufferBytes, pDSoundStrmIn->hw.Props.uAlign + 1));
    828         }
     818        if (bc.dwBufferBytes & pDSoundStrmIn->strmIn.Props.uAlign)
     819            LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture capabilities returned misaligned buffer (size %ld, alignment %RU32)\n",
     820                      bc.dwBufferBytes, pDSoundStrmIn->strmIn.Props.uAlign + 1));
    829821
    830822        if (bc.dwBufferBytes != pThis->cfg.cbBufferIn)
    831         {
    832             DSLOGREL(("DSound: Buffer size mismatch dsound %u, requested %u bytes\n",
     823            LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer size mismatched (DirectSound %ld, requested %ld bytes)\n",
    833824                      bc.dwBufferBytes, pThis->cfg.cbBufferIn));
    834         }
    835825
    836826        /* Initial state: reading at the initial capture position. */
    837         pDSoundStrmIn->csCaptureReadPos = cbReadPos >> pDSoundStrmIn->hw.Props.cShift;
    838         pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->hw.Props.cShift;
    839         DSLOG(("DSound: capture open csCaptureReadPos %d, csCaptureBufferSize %d samples\n",
    840                pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize));
    841 
     827        pDSoundStrmIn->csCaptureReadPos    = cbReadPos >> pDSoundStrmIn->strmIn.Props.cShift;
     828        pDSoundStrmIn->csCaptureBufferSize = bc.dwBufferBytes >> pDSoundStrmIn->strmIn.Props.cShift;
     829
     830        LogFlowFunc(("csCaptureReadPos=%ld, csCaptureBufferSize=%ld\n",
     831                     pDSoundStrmIn->csCaptureReadPos, pDSoundStrmIn->csCaptureBufferSize));
     832
     833        /* Update status. */
    842834        pDSoundStrmIn->hrLastCaptureIn = S_OK;
     835
    843836    } while (0);
    844837
     
    852845static void dsoundCaptureStop(PDSOUNDSTREAMIN pDSoundStrmIn)
    853846{
     847    AssertPtrReturnVoid(pDSoundStrmIn);
     848
    854849    if (pDSoundStrmIn->pDSCB)
    855850    {
    856         DSLOG(("DSound: capture stop\n"));
     851        LogFlowFunc(("Capturing stopped\n"));
    857852
    858853        HRESULT hr = IDirectSoundCaptureBuffer_Stop(pDSoundStrmIn->pDSCB);
    859854        if (FAILED(hr))
    860         {
    861             DSLOG(("DSound: stop capture buffer %Rhrc\n", hr));
    862         }
     855            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error stopping capture buffer: %Rhrc\n", hr));
    863856    }
    864857}
     
    866859static int dsoundCaptureStart(PDRVHOSTDSOUND pThis, PDSOUNDSTREAMIN pDSoundStrmIn)
    867860{
     861    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
     862    AssertPtrReturn(pDSoundStrmIn, VERR_INVALID_PARAMETER);
     863
    868864    HRESULT hr;
    869865
     
    874870        if (FAILED(hr))
    875871        {
    876             DSLOG(("DSound: start GetStatus %Rhrc\n", hr));
     872            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error getting capture buffer status: %Rhrc\n", hr));
    877873        }
    878874        else
     
    880876            if (dwStatus & DSCBSTATUS_CAPTURING)
    881877            {
    882                 DSLOG(("DSound: already capturing\n"));
     878                LogFlowFunc(("Already capturing\n"));
    883879            }
    884880            else
    885881            {
    886                 DSLOG(("DSound: capture start\n"));
    887 
     882                LogFlowFunc(("Capturig started\n"));
    888883                hr = IDirectSoundCaptureBuffer8_Start(pDSoundStrmIn->pDSCB, DSCBSTART_LOOPING);
    889884                if (FAILED (hr))
    890                 {
    891                     DSLOGREL(("DSound: Start %Rhrc\n", hr));
    892                 }
     885                    LogRelMax(s_cMaxRelLogEntries, ("DSound: Error starting capture: %Rhrc\n", hr));
    893886            }
    894887        }
     
    896889    else
    897890    {
     891        AssertMsgFailed(("No/invalid capture buffer\n"));
    898892        hr = E_FAIL;
    899893    }
     
    941935static void dsoundLogDevice(const char *pszType, LPGUID lpGUID, LPCWSTR lpwstrDescription, LPCWSTR lpwstrModule)
    942936{
     937    AssertPtrReturnVoid(pszType);
     938    AssertPtrReturnVoid(lpGUID);
     939    AssertPtrReturnVoid(lpwstrDescription);
     940    AssertPtrReturnVoid(lpwstrModule);
     941
    943942    char *pszGUID = dsoundGUIDToUtf8StrA(lpGUID);
    944 
    945     LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n",
    946            pszType, pszGUID? pszGUID: "no GUID", lpwstrDescription, lpwstrModule));
    947 
    948     RTStrFree(pszGUID);
     943    if (pszGUID)
     944    {
     945        LogRel(("DSound: %s: GUID: %s [%ls] (Module: %ls)\n",
     946                pszType, pszGUID, lpwstrDescription, lpwstrModule));
     947
     948        RTStrFree(pszGUID);
     949    }
    949950}
    950951
     
    952953                                        LPCWSTR lpwstrModule, LPVOID lpContext)
    953954{
     955   AssertPtrReturn(lpContext, FALSE);
     956
    954957    PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext;
    955958    AssertPtrReturn(pCtx, FALSE);
     
    960963        return TRUE;
    961964
     965    AssertPtrReturn(lpwstrDescription, FALSE);
     966    AssertPtrReturn(lpwstrModule, FALSE);
     967
    962968    dsoundLogDevice("Output", lpGUID, lpwstrDescription, lpwstrModule);
    963969
     
    986992
    987993    int rc = dsoundDevAdd(&pCtx->pDrv->lstDevInput,
    988                                  lpGUID, lpwstrDescription, NULL /* ppDev */);
     994                          lpGUID, lpwstrDescription, NULL /* ppDev */);
    989995    if (RT_FAILURE(rc))
    990996        return FALSE; /* Abort enumeration. */
     
    10041010                                              uint32_t *pcSamples)
    10051011{
     1012    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     1013    AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER);
     1014    AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
     1015    /* pcSamples is optional. */
     1016
    10061017    LogFlowFunc(("pHstStrmOut=%p, pCfg=%p\n", pHstStrmOut, pCfg));
    10071018
     
    10121023    pDSoundStrmOut->streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS;
    10131024
    1014     int rc = drvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut->hw.Props);
     1025    int rc = drvAudioStreamCfgToProps(&pDSoundStrmOut->streamCfg, &pDSoundStrmOut->strmOut.Props);
    10151026    if (RT_SUCCESS(rc))
    10161027    {
     
    10611072                rc = dsoundPlayStart(pDSoundStrmOut);
    10621073            }
    1063         } break;
     1074
     1075            break;
     1076        }
    10641077
    10651078        case PDMAUDIOSTREAMCMD_DISABLE:
    10661079        {
    10671080            dsoundPlayStop(pThis, pDSoundStrmOut);
    1068         } break;
     1081            break;
     1082        }
    10691083
    10701084        default:
     
    10721086            AssertMsgFailed(("Invalid command %ld\n", enmStreamCmd));
    10731087            rc = VERR_INVALID_PARAMETER;
    1074         } break;
     1088            break;
     1089        }
    10751090    }
    10761091
     
    10831098                                              uint32_t *pcSamplesPlayed)
    10841099{
     1100    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     1101    AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER);
     1102    /* pcSamplesPlayed is optional. */
     1103
    10851104    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
    10861105    PDSOUNDSTREAMOUT pDSoundStrmOut = (PDSOUNDSTREAMOUT)pHstStrmOut;
    1087     LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB;
    10881106
    10891107    int rc = VINF_SUCCESS;
    1090 
    1091     if (!pDSB)
    1092     {
    1093         if (pcSamplesPlayed) /** @todo single point of return */
    1094             *pcSamplesPlayed = 0;
    1095         return VINF_SUCCESS;
    1096     }
    1097 
    1098     int cShift = pHstStrmOut->Props.cShift;
    1099     DWORD cbBuffer = pDSoundStrmOut->csPlaybackBufferSize << cShift;
    1100 
    1101     DWORD cbPlayPos, cbWritePos;
    1102     HRESULT hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
    1103     if (hr == DSERR_BUFFERLOST)
    1104     {
    1105         rc = dsoundPlayRestore(pDSB);
     1108    uint32_t cReadTotal = 0;
     1109
     1110    do
     1111    {
     1112        LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStrmOut->pDSB;
     1113        if (!pDSB)
     1114            break;
     1115
     1116        int cShift = pHstStrmOut->Props.cShift;
     1117        DWORD cbBuffer = pDSoundStrmOut->csPlaybackBufferSize << cShift;
     1118
     1119        DWORD cbPlayPos, cbWritePos;
     1120        HRESULT hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
     1121        if (hr == DSERR_BUFFERLOST)
     1122        {
     1123            rc = dsoundPlayRestore(pDSB);
     1124            if (RT_FAILURE(rc))
     1125                break;
     1126
     1127            hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
     1128            if (hr == DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */
     1129                break;
     1130        }
     1131
     1132        if (FAILED(hr))
     1133        {
     1134            LogRelMax(s_cMaxRelLogEntries, ("Error retrieving current playback position: %Rhrc\n", hr));
     1135            break;
     1136        }
     1137
     1138        DWORD cbFree;
     1139        DWORD cbPlayWritePos;
     1140        if (pDSoundStrmOut->fReinitPlayPos)
     1141        {
     1142            pDSoundStrmOut->fReinitPlayPos = false;
     1143
     1144            pDSoundStrmOut->cbPlayWritePos = cbWritePos;
     1145
     1146            cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos;
     1147            cbFree = cbBuffer - dsoundRingDistance(cbWritePos, cbPlayPos, cbBuffer);
     1148        }
     1149        else
     1150        {
     1151            /* Full buffer? */
     1152            if (pDSoundStrmOut->cbPlayWritePos == cbPlayPos)
     1153                break;
     1154
     1155            cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos;
     1156            cbFree         = dsoundRingDistance(cbPlayPos, cbPlayWritePos, cbBuffer);
     1157        }
     1158
     1159        uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */);
     1160        uint32_t cbLive = csLive << cShift;
     1161
     1162        /* Do not write more than available space in the DirectSound playback buffer. */
     1163        cbLive = RT_MIN(cbFree, cbLive);
     1164
     1165        cbLive &= ~pHstStrmOut->Props.uAlign;
     1166        if (cbLive == 0 || cbLive > cbBuffer)
     1167        {
     1168            LogFlowFunc(("cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n",
     1169                         cbLive, cbBuffer, cbPlayWritePos, cbPlayPos));
     1170            break;
     1171        }
     1172
     1173        LPVOID pv1, pv2;
     1174        DWORD cb1, cb2;
     1175        rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, cbPlayWritePos, cbLive,
     1176                              &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
    11061177        if (RT_FAILURE(rc))
    1107         {
    1108             if (pcSamplesPlayed)
    1109                 *pcSamplesPlayed = 0;
    1110             return VINF_SUCCESS;
    1111         }
    1112 
    1113         hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, &cbWritePos);
    1114         if (hr == DSERR_BUFFERLOST)
    1115         {
    1116             /* Avoid log flooding if the error is still there. */
    1117             if (pcSamplesPlayed)
    1118                 *pcSamplesPlayed = 0;
    1119             return VINF_SUCCESS;
    1120         }
    1121     }
    1122     if (FAILED (hr))
    1123     {
    1124         DSLOG(("DSound: get playback buffer position %Rhrc\n", hr));
    1125         if (pcSamplesPlayed)
    1126             *pcSamplesPlayed = 0;
    1127         return VINF_SUCCESS;
    1128     }
    1129 
    1130     DWORD cbFree;
    1131     DWORD cbPlayWritePos;
    1132     if (pDSoundStrmOut->fReinitPlayPos)
    1133     {
    1134         pDSoundStrmOut->fReinitPlayPos = false;
    1135 
    1136         pDSoundStrmOut->cbPlayWritePos = cbWritePos;
    1137 
    1138         cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos;
    1139         cbFree = cbBuffer - dsoundRingDistance(cbWritePos, cbPlayPos, cbBuffer);
    1140     }
    1141     else
    1142     {
    1143         if (pDSoundStrmOut->cbPlayWritePos == cbPlayPos)
    1144         {
    1145             /* Full buffer. */
    1146             if (pcSamplesPlayed)
    1147                 *pcSamplesPlayed = 0;
    1148             return VINF_SUCCESS;
    1149         }
    1150 
    1151         cbPlayWritePos = pDSoundStrmOut->cbPlayWritePos;
    1152         cbFree = dsoundRingDistance(cbPlayPos, cbPlayWritePos, cbBuffer);
    1153     }
    1154 
    1155     uint32_t csLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */);
    1156     uint32_t cbLive = csLive << cShift;
    1157 
    1158     /* Do not write more than available space in the DirectSound playback buffer. */
    1159     cbLive = RT_MIN(cbFree, cbLive);
    1160 
    1161     cbLive &= ~pHstStrmOut->Props.uAlign;
    1162     if (cbLive == 0 || cbLive > cbBuffer)
    1163     {
    1164         DSLOG(("DSound: cbLive=%d cbBuffer=%d cbPlayWritePos=%d cbPlayPos=%d\n",
    1165               cbLive, cbBuffer, cbPlayWritePos, cbPlayPos));
    1166         if (pcSamplesPlayed)
    1167             *pcSamplesPlayed = 0;
    1168         return VINF_SUCCESS;
    1169     }
    1170 
    1171     LPVOID pv1, pv2;
    1172     DWORD cb1, cb2;
    1173     rc = dsoundLockOutput(pDSB, &pHstStrmOut->Props, cbPlayWritePos, cbLive,
    1174                           &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
    1175     if (RT_FAILURE(rc))
    1176     {
    1177         if (pcSamplesPlayed)
    1178             *pcSamplesPlayed = 0;
    1179         return VINF_SUCCESS;
    1180     }
    1181 
    1182     DWORD len1 = cb1 >> cShift;
    1183     DWORD len2 = cb2 >> cShift;
    1184 
    1185     uint32_t cReadTotal = 0;
    1186     uint32_t cRead = 0;
    1187 
    1188     if (pv1 && cb1)
    1189     {
    1190         rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead);
    1191         if (RT_SUCCESS(rc))
    1192             cReadTotal += cRead;
    1193     }
    1194 
    1195     if (   RT_SUCCESS(rc)
    1196         && cReadTotal == len1
    1197         && pv2 && cb2)
    1198     {
    1199         rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead);
    1200         if (RT_SUCCESS(rc))
    1201             cReadTotal += cRead;
    1202     }
    1203 
    1204     dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);
    1205 
    1206     pDSoundStrmOut->cbPlayWritePos = (cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer;
    1207 
    1208     DSLOGF(("DSound: PlayOut %RU32 (%RU32 samples) out of %d%s, ds write pos %d -> %d, rc=%Rrc\n",
    1209             AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive,
    1210             cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "",
    1211             cbPlayWritePos, pDSoundStrmOut->cbPlayWritePos, rc));
    1212 
    1213     if (cReadTotal)
    1214     {
    1215         AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);
    1216         rc = VINF_SUCCESS; /* Played something. */
    1217     }
     1178            break;
     1179
     1180        DWORD len1 = cb1 >> cShift;
     1181        DWORD len2 = cb2 >> cShift;
     1182
     1183        uint32_t cRead = 0;
     1184
     1185        if (pv1 && cb1)
     1186        {
     1187            rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv1, cb1, &cRead);
     1188            if (RT_SUCCESS(rc))
     1189                cReadTotal += cRead;
     1190        }
     1191
     1192        if (   RT_SUCCESS(rc)
     1193            && cReadTotal == len1
     1194            && pv2 && cb2)
     1195        {
     1196            rc = AudioMixBufReadCirc(&pHstStrmOut->MixBuf, pv2, cb2, &cRead);
     1197            if (RT_SUCCESS(rc))
     1198                cReadTotal += cRead;
     1199        }
     1200
     1201        dsoundUnlockOutput(pDSB, pv1, pv2, cb1, cb2);
     1202
     1203        pDSoundStrmOut->cbPlayWritePos = (cbPlayWritePos + (cReadTotal << cShift)) % cbBuffer;
     1204
     1205        LogFlowFunc(("%RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld -> %ld, rc=%Rrc\n",
     1206                     AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal), cReadTotal, cbLive,
     1207                     cbLive != AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cReadTotal) ? " !!!": "",
     1208                     cbPlayWritePos, pDSoundStrmOut->cbPlayWritePos, rc));
     1209
     1210        if (cReadTotal)
     1211        {
     1212            AudioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);
     1213            rc = VINF_SUCCESS; /* Played something. */
     1214        }
     1215
     1216    } while (0);
    12181217
    12191218    if (pcSamplesPlayed)
     
    13451344        if (hr != pDSoundStrmIn->hrLastCaptureIn)
    13461345        {
    1347             DSLOGREL(("DSound: CaptureIn GetCurrentPosition %Rhrc\n", hr));
     1346            LogRelMax(s_cMaxRelLogEntries, ("DSound: Error retrieving current capture position: %Rhrc\n", hr));
    13481347            pDSoundStrmIn->hrLastCaptureIn = hr;
    13491348        }
     
    13561355
    13571356    if (cbReadPos & pHstStrmIn->Props.uAlign)
    1358     {
    1359         DSLOG(("DSound: CaptureIn misaligned read position %d(%d)\n", cbReadPos, pHstStrmIn->Props.uAlign));
    1360     }
     1357        LogFunc(("Misaligned read position %ld (alignment: %RU32)\n", cbReadPos, pHstStrmIn->Props.uAlign));
    13611358
    13621359    /* Capture position in samples. */
    1363     int csReadPos = cbReadPos >> pHstStrmIn->Props.cShift;
     1360    DWORD csReadPos = cbReadPos >> pHstStrmIn->Props.cShift;
    13641361
    13651362    /* Number of samples available in the DirectSound capture buffer. */
     
    13791376    if (csMixFree == 0)
    13801377    {
    1381         DSLOG(("DSound: capture mix buffer full\n"));
     1378        LogRelMax(s_cMaxRelLogEntries, ("DSound: Capture buffer full\n"));
    13821379        if (pcSamplesCaptured)
    13831380            *pcSamplesCaptured = 0;
     
    13851382    }
    13861383
    1387     DSLOGF(("DSound: CaptureIn csMixFree = %u, csReadPos = %d, csCaptureReadPos = %d, csCaptured = %u\n",
    1388             csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured));
     1384    LogFlowFunc(("csMixFree=%RU32, csReadPos=%ld, csCaptureReadPos=%ld, csCaptured=%ld\n",
     1385                 csMixFree, csReadPos, pDSoundStrmIn->csCaptureReadPos, csCaptured));
    13891386
    13901387    /* No need to fetch more samples than mix buffer can receive. */
     
    14421439    {
    14431440        pDSoundStrmIn->csCaptureReadPos = (pDSoundStrmIn->csCaptureReadPos + csProcessed) % pDSoundStrmIn->csCaptureBufferSize;
    1444         DSLOGF(("DSound: CaptureIn %d (%d+%d), processed %d/%d\n",
    1445                 csCaptured, len1, len2, csProcessed, csWrittenTotal));
     1441        LogFlowFunc(("%ld (%ld+%ld), processed %RU32/%RU32\n",
     1442                     csCaptured, len1, len2, csProcessed, csWrittenTotal));
    14461443    }
    14471444
     
    14591456    dsoundCaptureClose(pDSoundStrmIn);
    14601457
    1461     pDSoundStrmIn->csCaptureReadPos = 0;
     1458    pDSoundStrmIn->csCaptureReadPos    = 0;
    14621459    pDSoundStrmIn->csCaptureBufferSize = 0;
    14631460    RT_ZERO(pDSoundStrmIn->streamCfg);
     
    14911488    HRESULT hr = DirectSoundEnumerateW(&dsoundEnumCallback, &ctx);
    14921489    if (FAILED(hr))
    1493         DSLOG(("DSound: Enumerating host playback devices failed %Rhrc\n", hr));
    1494 
    1495     DSLOGREL(("DSound: Found %RU32 host playback devices\n", pCfg->cMaxHstStrmsOut));
     1490        LogRel(("DSound: Error enumerating host playback devices: %Rhrc\n", hr));
     1491
     1492    LogRel(("DSound: Found %RU32 host playback devices\n", pCfg->cMaxHstStrmsOut));
    14961493    if (pCfg->cMaxHstStrmsOut == 0)
    14971494        pCfg->cMaxHstStrmsOut = 1; /* Support at least one stream. */
     
    14991496    hr = DirectSoundCaptureEnumerateW(&dsoundCaptureEnumCallback, &ctx);
    15001497    if (FAILED(hr))
    1501         DSLOG(("DSound: Enumerating host capturing devices failed %Rhrc\n", hr));
    1502 
    1503     DSLOGREL(("DSound: Found %RU32 host capturing devices\n", pCfg->cMaxHstStrmsIn));
     1498        LogRel(("DSound: Error nnumerating host capturing devices: %Rhrc\n", hr));
     1499
     1500    LogRel(("DSound: Found %RU32 host capturing devices\n", pCfg->cMaxHstStrmsIn));
    15041501    if (pCfg->cMaxHstStrmsIn < 2)
    15051502    {
    1506         DSLOGREL(("DSound: Adjusting the number of host capturing devices from %RU32 to 2\n", pCfg->cMaxHstStrmsIn));
     1503        LogRel(("DSound: Adjusting the number of host capturing devices from %RU32 to 2\n", pCfg->cMaxHstStrmsIn));
    15071504        pCfg->cMaxHstStrmsIn = 2; /* Support at least two streams (line in + mic). */
    15081505    }
     
    15291526        IDirectSound_Release(pDirectSound);
    15301527    else
    1531         DSLOGREL(("DSound: Not available %Rhrc\n", hr));
     1528        LogRel(("DSound: DirectSound not available: %Rhrc\n", hr));
    15321529
    15331530    int rc = SUCCEEDED(hr) ? VINF_SUCCESS: VERR_NOT_SUPPORTED;
     
    15811578            pGuid = (LPCGUID)&pUuid;
    15821579        else
    1583             DSLOGREL(("DSound: Parse DirectSound %s %Rrc\n", pszName, rc));
     1580            LogRel(("DSound: Error parsing device GUID for device '%s': %Rrc\n", pszName, rc));
    15841581
    15851582        RTStrFree(pszGuid);
     
    16011598    pThis->cfg.pGuidCapture = dsoundConfigQueryGUID(pCfg, "DeviceGuidIn",  &pThis->cfg.uuidCapture);
    16021599
    1603     DSLOG(("DSound: BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",
    1604            pThis->cfg.cbBufferOut,
    1605            pThis->cfg.cbBufferIn,
    1606            &pThis->cfg.uuidPlay,
    1607            &pThis->cfg.uuidCapture));
     1600    LogFlowFunc(("BufsizeOut %u, BufsizeIn %u, DeviceGuidOut {%RTuuid}, DeviceGuidIn {%RTuuid}\n",
     1601                 pThis->cfg.cbBufferOut,
     1602                 pThis->cfg.cbBufferIn,
     1603                 &pThis->cfg.uuidPlay,
     1604                 &pThis->cfg.uuidCapture));
    16081605}
    16091606
     
    16341631    if (FAILED(hr))
    16351632    {
    1636         LogRel(("DSound: COM initialize %Rhrc\n", hr));
     1633        LogRel(("DSound: Error initializing COM: %Rhrc\n", hr));
    16371634        return VERR_NOT_SUPPORTED;
    16381635    }
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