Index: trunk/src/VBox/Devices/Audio/DrvAudio.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 89327)
+++ trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 89329)
@@ -511,5 +511,5 @@
 }
 
-
+#ifdef LOG_ENABLED
 /**
  * Get capture state name string.
@@ -528,5 +528,5 @@
     return "BAD";
 }
-
+#endif
 
 /**
@@ -3862,374 +3862,4 @@
 
 
-#ifdef OLD_CAPTURE_CODE
-/**
- * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamRead}
- */
-static DECLCALLBACK(int) drvAudioStreamRead(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream,
-                                            void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
-{
-    PDRVAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVAUDIO, IAudioConnector);
-    AssertPtr(pThis);
-    PDRVAUDIOSTREAM pStreamEx = (PDRVAUDIOSTREAM)pStream;
-    AssertPtrReturn(pStreamEx, VERR_INVALID_POINTER);
-    AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
-    AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
-    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
-    AssertReturn(pStreamEx->Core.uMagic == PDMAUDIOSTREAM_MAGIC, VERR_INVALID_MAGIC);
-    AssertReturn(pStreamEx->uMagic      == DRVAUDIOSTREAM_MAGIC, VERR_INVALID_MAGIC);
-    AssertMsg(pStreamEx->Core.enmDir == PDMAUDIODIR_IN,
-              ("Stream '%s' is not an input stream and therefore cannot be read from (direction is 0x%x)\n",
-               pStreamEx->Core.szName, pStreamEx->Core.enmDir));
-
-    int rc = RTCritSectEnter(&pStreamEx->Core.CritSect);
-    AssertRCReturn(rc, rc);
-
-    /*
-     * ...
-     */
-    uint32_t cbReadTotal = 0;
-
-    do
-    {
-        uint32_t cfReadTotal = 0;
-
-        const uint32_t cfBuf = AUDIOMIXBUF_B2F(&pStreamEx->Guest.MixBuf, cbBuf);
-
-        if (pThis->In.fEnabled) /* Input for this audio driver enabled? See #9822. */
-        {
-            if (!PDMAudioStrmStatusCanRead(pStreamEx->fStatus))
-            {
-                rc = VERR_AUDIO_STREAM_NOT_READY;
-                break;
-            }
-
-            /*
-             * Read from the parent buffer (that is, the guest buffer) which
-             * should have the audio data in the format the guest needs.
-             */
-            uint32_t cfToRead = RT_MIN(cfBuf, AudioMixBufLive(&pStreamEx->Guest.MixBuf));
-            while (cfToRead)
-            {
-                uint32_t cfRead;
-                rc = AudioMixBufAcquireReadBlock(&pStreamEx->Guest.MixBuf,
-                                                 (uint8_t *)pvBuf + AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfReadTotal),
-                                                 AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfToRead), &cfRead);
-                if (RT_FAILURE(rc))
-                    break;
-
-#ifdef VBOX_WITH_STATISTICS
-                const uint32_t cbRead = AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfRead);
-                STAM_COUNTER_ADD(&pThis->Stats.TotalBytesRead,    cbRead);
-                STAM_COUNTER_ADD(&pStreamEx->In.Stats.TotalFramesRead, cfRead);
-                STAM_COUNTER_INC(&pStreamEx->In.Stats.TotalTimesRead);
-#endif
-                Assert(cfToRead >= cfRead);
-                cfToRead -= cfRead;
-
-                cfReadTotal += cfRead;
-
-                AudioMixBufReleaseReadBlock(&pStreamEx->Guest.MixBuf, cfRead);
-            }
-
-            if (cfReadTotal)
-            {
-                if (pThis->CfgIn.Dbg.fEnabled)
-                    AudioHlpFileWrite(pStreamEx->In.Dbg.pFileStreamRead,
-                                      pvBuf, AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfReadTotal), 0 /* fFlags */);
-
-                AudioMixBufFinish(&pStreamEx->Guest.MixBuf, cfReadTotal);
-            }
-        }
-
-        /* If we were not able to read as much data as requested, fill up the returned
-         * data with silence.
-         *
-         * This is needed to keep the device emulation DMA transfers up and running at a constant rate. */
-        if (cfReadTotal < cfBuf)
-        {
-            Log3Func(("[%s] Filling in silence (%RU64ms / %RU64ms)\n", pStream->szName,
-                      PDMAudioPropsFramesToMilli(&pStreamEx->Guest.Cfg.Props, cfBuf - cfReadTotal),
-                      PDMAudioPropsFramesToMilli(&pStreamEx->Guest.Cfg.Props, cfBuf)));
-
-            PDMAudioPropsClearBuffer(&pStreamEx->Guest.Cfg.Props,
-                                     (uint8_t *)pvBuf + AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfReadTotal),
-                                     AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfBuf - cfReadTotal),
-                                     cfBuf - cfReadTotal);
-
-            cfReadTotal = cfBuf;
-        }
-
-        cbReadTotal = AUDIOMIXBUF_F2B(&pStreamEx->Guest.MixBuf, cfReadTotal);
-
-        pStreamEx->nsLastReadWritten = RTTimeNanoTS();
-
-        Log3Func(("[%s] fEnabled=%RTbool, cbReadTotal=%RU32, rc=%Rrc\n", pStream->szName, pThis->In.fEnabled, cbReadTotal, rc));
-
-    } while (0);
-
-    RTCritSectLeave(&pStreamEx->Core.CritSect);
-
-    if (RT_SUCCESS(rc) && pcbRead)
-        *pcbRead = cbReadTotal;
-    return rc;
-}
-
-
-/**
- * Captures non-interleaved input from a host stream.
- *
- * @returns VBox status code.
- * @param   pThis       Driver instance.
- * @param   pStreamEx   Stream to capture from.
- * @param   pcfCaptured Number of (host) audio frames captured.
- */
-static int drvAudioStreamCaptureNonInterleaved(PDRVAUDIO pThis, PDRVAUDIOSTREAM pStreamEx, uint32_t *pcfCaptured)
-{
-    Assert(pStreamEx->Core.enmDir == PDMAUDIODIR_IN);
-    Assert(pStreamEx->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED);
-
-    /*
-     * ...
-     */
-    uint32_t cbReadable = pThis->pHostDrvAudio->pfnStreamGetReadable(pThis->pHostDrvAudio, pStreamEx->pBackend);
-    if (!cbReadable)
-        Log2Func(("[%s] No readable data available\n", pStreamEx->Core.szName));
-
-    uint32_t cbFree = AudioMixBufFreeBytes(&pStreamEx->Guest.MixBuf); /* Parent */
-    if (!cbFree)
-        Log2Func(("[%s] Buffer full\n", pStreamEx->Core.szName));
-
-    if (cbReadable > cbFree) /* More data readable than we can store at the moment? Limit. */
-        cbReadable = cbFree;
-
-    /*
-     * ...
-     */
-    int      rc = VINF_SUCCESS;
-    uint32_t cfCapturedTotal = 0;
-    while (cbReadable)
-    {
-        uint8_t  abChunk[_4K];
-        uint32_t cbCaptured;
-        rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pStreamEx->pBackend,
-                                                    abChunk, RT_MIN(cbReadable, (uint32_t)sizeof(abChunk)), &cbCaptured);
-        if (RT_FAILURE(rc))
-        {
-            int rc2 = drvAudioStreamControlInternalBackend(pThis, pStreamEx, PDMAUDIOSTREAMCMD_DISABLE);
-            AssertRC(rc2);
-            break;
-        }
-
-        Assert(cbCaptured <= sizeof(abChunk));
-        if (cbCaptured > sizeof(abChunk)) /* Paranoia. */
-            cbCaptured = (uint32_t)sizeof(abChunk);
-
-        if (!cbCaptured) /* Nothing captured? Take a shortcut. */
-            break;
-
-        /* We use the host side mixing buffer as an intermediate buffer to do some
-         * (first) processing (if needed), so always write the incoming data at offset 0. */
-        uint32_t cfHstWritten = 0;
-        rc = AudioMixBufWriteAt(&pStreamEx->Host.MixBuf, 0 /* offFrames */, abChunk, cbCaptured, &cfHstWritten);
-        if (   RT_FAILURE(rc)
-            || !cfHstWritten)
-        {
-            AssertMsgFailed(("[%s] Write failed: cbCaptured=%RU32, cfHstWritten=%RU32, rc=%Rrc\n",
-                             pStreamEx->Core.szName, cbCaptured, cfHstWritten, rc));
-            break;
-        }
-
-        if (pThis->CfgIn.Dbg.fEnabled)
-            AudioHlpFileWrite(pStreamEx->In.Dbg.pFileCapture, abChunk, cbCaptured, 0 /* fFlags */);
-
-        uint32_t cfHstMixed = 0;
-        if (cfHstWritten)
-        {
-            int rc2 = AudioMixBufMixToParentEx(&pStreamEx->Host.MixBuf, 0 /* cSrcOffset */, cfHstWritten /* cSrcFrames */,
-                                               &cfHstMixed /* pcSrcMixed */);
-            Log3Func(("[%s] cbCaptured=%RU32, cfWritten=%RU32, cfMixed=%RU32, rc=%Rrc\n",
-                      pStreamEx->Core.szName, cbCaptured, cfHstWritten, cfHstMixed, rc2));
-            AssertRC(rc2);
-        }
-
-        Assert(cbReadable >= cbCaptured);
-        cbReadable      -= cbCaptured;
-        cfCapturedTotal += cfHstMixed;
-    }
-
-    if (RT_SUCCESS(rc))
-    {
-        if (cfCapturedTotal)
-            Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pStreamEx->Core.szName, cfCapturedTotal, rc));
-    }
-    else
-        LogFunc(("[%s] Capturing failed with rc=%Rrc\n", pStreamEx->Core.szName, rc));
-
-    if (pcfCaptured)
-        *pcfCaptured = cfCapturedTotal;
-
-    return rc;
-}
-
-
-/**
- * Captures raw input from a host stream.
- *
- * Raw input means that the backend directly operates on PDMAUDIOFRAME structs without
- * no data layout processing done in between.
- *
- * Needed for e.g. the VRDP audio backend (in Main).
- *
- * @returns VBox status code.
- * @param   pThis       Driver instance.
- * @param   pStreamEx   Stream to capture from.
- * @param   pcfCaptured Number of (host) audio frames captured.
- */
-static int drvAudioStreamCaptureRaw(PDRVAUDIO pThis, PDRVAUDIOSTREAM pStreamEx, uint32_t *pcfCaptured)
-{
-    Assert(pStreamEx->Core.enmDir == PDMAUDIODIR_IN);
-    Assert(pStreamEx->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW);
-    AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable);
-
-    /*
-     * ...
-     */
-    /* Note: Raw means *audio frames*, not bytes! */
-    uint32_t cfReadable = pThis->pHostDrvAudio->pfnStreamGetReadable(pThis->pHostDrvAudio, pStreamEx->pBackend);
-    if (!cfReadable)
-        Log2Func(("[%s] No readable data available\n", pStreamEx->Core.szName));
-
-    const uint32_t cfFree = AudioMixBufFree(&pStreamEx->Guest.MixBuf); /* Parent */
-    if (!cfFree)
-        Log2Func(("[%s] Buffer full\n", pStreamEx->Core.szName));
-
-    if (cfReadable > cfFree) /* More data readable than we can store at the moment? Limit. */
-        cfReadable = cfFree;
-
-    /*
-     * ...
-     */
-    int      rc              = VINF_SUCCESS;
-    uint32_t cfCapturedTotal = 0;
-    while (cfReadable)
-    {
-        PPDMAUDIOFRAME paFrames;
-        uint32_t cfWritable;
-        rc = AudioMixBufPeekMutable(&pStreamEx->Host.MixBuf, cfReadable, &paFrames, &cfWritable);
-        if (   RT_FAILURE(rc)
-            || !cfWritable)
-            break;
-
-        uint32_t cfCaptured;
-        rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pStreamEx->pBackend,
-                                                    paFrames, cfWritable, &cfCaptured);
-        if (RT_FAILURE(rc))
-        {
-            int rc2 = drvAudioStreamControlInternalBackend(pThis, pStreamEx, PDMAUDIOSTREAMCMD_DISABLE);
-            AssertRC(rc2);
-            break;
-        }
-
-        Assert(cfCaptured <= cfWritable);
-        if (cfCaptured > cfWritable) /* Paranoia. */
-            cfCaptured = cfWritable;
-
-        Assert(cfReadable >= cfCaptured);
-        cfReadable      -= cfCaptured;
-        cfCapturedTotal += cfCaptured;
-    }
-
-    if (pcfCaptured)
-        *pcfCaptured = cfCapturedTotal;
-    Log2Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pStreamEx->Core.szName, cfCapturedTotal, rc));
-    return rc;
-}
-
-
-/**
- * @interface_method_impl{PDMIAUDIOCONNECTOR,pfnStreamCapture}
- */
-static DECLCALLBACK(int) drvAudioStreamCapture(PPDMIAUDIOCONNECTOR pInterface,
-                                               PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured)
-{
-    PDRVAUDIO pThis = RT_FROM_MEMBER(pInterface, DRVAUDIO, IAudioConnector);
-    AssertPtr(pThis);
-    PDRVAUDIOSTREAM pStreamEx = (PDRVAUDIOSTREAM)pStream;
-    AssertPtrReturn(pStreamEx, VERR_INVALID_POINTER);
-    AssertPtrNull(pcFramesCaptured);
-    AssertReturn(pStreamEx->Core.uMagic == PDMAUDIOSTREAM_MAGIC, VERR_INVALID_MAGIC);
-    AssertReturn(pStreamEx->uMagic      == DRVAUDIOSTREAM_MAGIC, VERR_INVALID_MAGIC);
-    AssertMsg(pStreamEx->Core.enmDir == PDMAUDIODIR_IN,
-              ("Stream '%s' is not an input stream and therefore cannot be captured (direction is 0x%x)\n",
-               pStreamEx->Core.szName, pStreamEx->Core.enmDir));
-    int rc = RTCritSectEnter(&pStreamEx->Core.CritSect);
-    AssertRCReturn(rc, rc);
-    RTCritSectRwEnterShared(&pThis->CritSectHotPlug);
-
-#ifdef LOG_ENABLED
-    char szStreamSts[DRVAUDIO_STATUS_STR_MAX];
-#endif
-    Log3Func(("[%s] fStatus=%s\n", pStreamEx->Core.szName, drvAudioStreamStatusToStr(szStreamSts, pStreamEx->fStatus)));
-
-    /*
-     * ...
-     */
-    uint32_t cfCaptured = 0;
-    do
-    {
-        if (!pThis->pHostDrvAudio)
-        {
-            rc = VERR_PDM_NO_ATTACHED_DRIVER;
-            break;
-        }
-
-        if (   !pThis->In.fEnabled
-            || !PDMAudioStrmStatusCanRead(pStreamEx->fStatus)
-            || !(pStreamEx->fStatus & PDMAUDIOSTREAM_STS_BACKEND_READY))
-        {
-            rc = VERR_AUDIO_STREAM_NOT_READY;
-            break;
-        }
-
-        PDMHOSTAUDIOSTREAMSTATE const enmBackendState = drvAudioStreamGetBackendState(pThis, pStreamEx);
-        if (enmBackendState == PDMHOSTAUDIOSTREAMSTATE_OKAY)
-        {
-            /*
-             * Do the actual capturing.
-             */
-            if (RT_LIKELY(pStreamEx->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED))
-                rc = drvAudioStreamCaptureNonInterleaved(pThis, pStreamEx, &cfCaptured);
-            else if (pStreamEx->Host.Cfg.enmLayout == PDMAUDIOSTREAMLAYOUT_RAW)
-                rc = drvAudioStreamCaptureRaw(pThis, pStreamEx, &cfCaptured);
-            else
-                AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
-
-            if (RT_SUCCESS(rc))
-            {
-                Log3Func(("[%s] %RU32 frames captured, rc=%Rrc\n", pStreamEx->Core.szName, cfCaptured, rc));
-
-                STAM_COUNTER_ADD(&pThis->Stats.TotalFramesIn,              cfCaptured);
-                STAM_COUNTER_ADD(&pStreamEx->In.Stats.TotalFramesCaptured, cfCaptured);
-            }
-            else if (RT_UNLIKELY(RT_FAILURE(rc)))
-                LogRel(("Audio: Capturing stream '%s' failed with %Rrc\n", pStreamEx->Core.szName, rc));
-        }
-        else
-            rc = VERR_AUDIO_STREAM_NOT_READY;
-    } while (0);
-
-    RTCritSectRwLeaveShared(&pThis->CritSectHotPlug);
-    RTCritSectLeave(&pStreamEx->Core.CritSect);
-
-    if (pcFramesCaptured)
-        *pcFramesCaptured = cfCaptured;
-
-    if (RT_FAILURE(rc))
-        LogFlowFuncLeaveRC(rc);
-    return rc;
-}
-#endif
-
-
 /*********************************************************************************************************************************
 *   PDMIHOSTAUDIOPORT interface implementation.                                                                                  *
