Index: trunk/src/VBox/Devices/Audio/DrvAudio.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 57397)
+++ trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 57398)
@@ -318,4 +318,7 @@
         return;
 
+    Log2Func(("pPCMInfo=%p, pvBuf=%p, cbBuf=%zu, fSigned=%RTbool, cBits=%RU8, cShift=%RU8\n",
+              pPCMInfo, pvBuf, cbBuf, pPCMInfo->fSigned, pPCMInfo->cBits, pPCMInfo->cShift));
+
     if (pPCMInfo->fSigned)
     {
@@ -368,4 +371,116 @@
         }
     }
+}
+
+static int drvAudioControlHstIn(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMIN pHstStrmIn, PDMAUDIOSTREAMCMD enmStreamCmd,
+                                uint32_t uFlags)
+{
+    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
+    AssertPtrReturn(pHstStrmIn, VERR_INVALID_POINTER);
+
+    int rc;
+
+    switch (enmStreamCmd)
+    {
+        case PDMAUDIOSTREAMCMD_ENABLE:
+        {
+            if (!pHstStrmIn->fEnabled)
+            {
+                rc = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, PDMAUDIOSTREAMCMD_ENABLE);
+                if (RT_SUCCESS(rc))
+                {
+                    pHstStrmIn->fEnabled = true;
+                }
+                else
+                    LogFlowFunc(("Backend reported an error when opening input stream, rc=%Rrc\n", rc));
+            }
+            else
+                rc = VINF_SUCCESS;
+
+            break;
+        }
+
+        case PDMAUDIOSTREAMCMD_DISABLE:
+        {
+            if (pHstStrmIn->fEnabled)
+            {
+                rc = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE);
+                if (RT_SUCCESS(rc))
+                {
+                    pHstStrmIn->fEnabled = false;
+                    AudioMixBufClear(&pHstStrmIn->MixBuf);
+                }
+                else
+                    LogFlowFunc(("Backend vetoed closing output stream, rc=%Rrc\n", rc));
+            }
+            else
+                rc = VINF_SUCCESS;
+
+            break;
+        }
+
+        default:
+            AssertMsgFailed(("Command %ld not implemented\n", enmStreamCmd));
+            rc = VERR_NOT_IMPLEMENTED;
+            break;
+    }
+
+    return rc;
+}
+
+static int drvAudioControlHstOut(PDRVAUDIO pThis, PPDMAUDIOHSTSTRMOUT pHstStrmOut, PDMAUDIOSTREAMCMD enmStreamCmd,
+                                 uint32_t uFlags)
+{
+    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
+    AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER);
+
+    int rc;
+
+    switch (enmStreamCmd)
+    {
+        case PDMAUDIOSTREAMCMD_ENABLE:
+        {
+            if (!pHstStrmOut->fEnabled)
+            {
+                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE);
+                if (RT_SUCCESS(rc))
+                {
+                    pHstStrmOut->fEnabled = true;
+                }
+                else
+                    LogFlowFunc(("Backend reported an error when opening output stream, rc=%Rrc\n", rc));
+            }
+            else
+                rc = VINF_SUCCESS;
+
+            break;
+        }
+
+        case PDMAUDIOSTREAMCMD_DISABLE:
+        {
+            if (pHstStrmOut->fEnabled)
+            {
+                rc = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
+                if (RT_SUCCESS(rc))
+                {
+                    pHstStrmOut->fEnabled = false;
+                    AudioMixBufClear(&pHstStrmOut->MixBuf);
+                }
+                else
+                    LogFlowFunc(("Backend vetoed closing output stream, rc=%Rrc\n", rc));
+            }
+            else
+                rc = VINF_SUCCESS;
+
+            break;
+        }
+
+        default:
+            AssertMsgFailed(("Command %ld not implemented\n", enmStreamCmd));
+            rc = VERR_NOT_IMPLEMENTED;
+            break;
+    }
+
+    return rc;
 }
 
@@ -1045,9 +1160,7 @@
         {
             /* Stop playing the current (pending) stream. */
-            int rc2 = pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut,
-                                                          PDMAUDIOSTREAMCMD_DISABLE);
+            int rc2 = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
             if (RT_SUCCESS(rc2))
             {
-                pHstStrmOut->fEnabled        = false;
                 pHstStrmOut->fPendingDisable = false;
 
@@ -1294,9 +1407,9 @@
     PPDMAUDIOHSTSTRMOUT pHstStrmOut = NULL;
     while ((pHstStrmOut = drvAudioHstFindAnyEnabledOut(pThis, pHstStrmOut)))
-        pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, enmCmd);
+        drvAudioControlHstOut(pThis, pHstStrmOut, enmCmd, 0 /* Flags */);
 
     PPDMAUDIOHSTSTRMIN pHstStrmIn = NULL;
     while ((pHstStrmIn = drvAudioFindNextEnabledHstIn(pThis, pHstStrmIn)))
-        pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, enmCmd);
+        drvAudioControlHstIn(pThis, pHstStrmIn, enmCmd, 0 /* Flags */);
 }
 
@@ -1451,10 +1564,10 @@
     PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
 
+    int rc = VINF_SUCCESS;
+
     if (pGstStrmOut)
     {
         PPDMAUDIOHSTSTRMOUT pHstStrmOut = pGstStrmOut->pHstStrmOut;
         AssertPtr(pHstStrmOut);
-
-        LogFlowFunc(("%s: fEnable=%RTbool\n", pGstStrmOut->MixBuf.pszName, fEnable));
 
         if (pGstStrmOut->State.fActive != fEnable)
@@ -1464,10 +1577,5 @@
                 pHstStrmOut->fPendingDisable = false;
                 if (!pHstStrmOut->fEnabled)
-                {
-                    pHstStrmOut->fEnabled = true;
-                    pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut,
-                                                        PDMAUDIOSTREAMCMD_ENABLE);
-                    /** @todo Check rc. */
-                }
+                    rc = drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_ENABLE, 0 /* Flags */);
             }
             else
@@ -1488,9 +1596,12 @@
             }
 
-            pGstStrmOut->State.fActive = fEnable;
-        }
-    }
-
-    return VINF_SUCCESS;
+            if (RT_SUCCESS(rc))
+                pGstStrmOut->State.fActive = fEnable;
+
+            LogFlowFunc(("%s: fEnable=%RTbool, rc=%Rrc\n", pGstStrmOut->MixBuf.pszName, fEnable, rc));
+        }
+    }
+
+    return rc;
 }
 
@@ -1503,4 +1614,6 @@
     PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
 
+    int rc = VINF_SUCCESS;
+
     if (pGstStrmIn)
     {
@@ -1512,34 +1625,14 @@
         if (pGstStrmIn->State.fActive != fEnable)
         {
-            if (fEnable)
-            {
-                if (!pHstStrmIn->fEnabled)
-                {
-                    int rc2 = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn,
-                                                                 PDMAUDIOSTREAMCMD_ENABLE);
-                    if (RT_LIKELY(RT_SUCCESS(rc2)))
-                        pHstStrmIn->fEnabled = true;
-                    else
-                        LogFlowFunc(("Error opening host input stream in backend, rc=%Rrc\n", rc2));
-                }
-            }
-            else
-            {
-                if (pHstStrmIn->fEnabled)
-                {
-                    int rc2 = pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn,
-                                                                 PDMAUDIOSTREAMCMD_DISABLE);
-                    if (RT_LIKELY(RT_SUCCESS(rc2))) /* Did the backend veto? */
-                        pHstStrmIn->fEnabled = false;
-                    else
-                        LogFlowFunc(("Backend vetoed closing input stream, rc=%Rrc\n", rc2));
-                }
-            }
-
-            pGstStrmIn->State.fActive = fEnable;
-        }
-    }
-
-    return VINF_SUCCESS;
+            rc = drvAudioControlHstIn(pThis, pHstStrmIn,
+                                      fEnable ? PDMAUDIOSTREAMCMD_ENABLE : PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
+            if (RT_SUCCESS(rc))
+                pGstStrmIn->State.fActive = fEnable;
+
+            LogFlowFunc(("%s: fEnable=%RTbool, rc=%Rrc\n", pGstStrmIn->MixBuf.pszName, fEnable, rc));
+        }
+    }
+
+    return rc;
 }
 
@@ -1778,5 +1871,5 @@
     while ((pHstStrmOut = drvAudioFindAnyHstOut(pThis, pHstStrmOut)))
     {
-        pThis->pHostDrvAudio->pfnControlOut(pThis->pHostDrvAudio, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE);
+        drvAudioControlHstOut(pThis, pHstStrmOut, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
         pThis->pHostDrvAudio->pfnFiniOut(pThis->pHostDrvAudio, pHstStrmOut);
     }
@@ -1786,5 +1879,5 @@
     while ((pHstStrmIn = drvAudioFindNextHstIn(pThis, pHstStrmIn)))
     {
-        pThis->pHostDrvAudio->pfnControlIn(pThis->pHostDrvAudio, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE);
+        drvAudioControlHstIn(pThis, pHstStrmIn, PDMAUDIOSTREAMCMD_DISABLE, 0 /* Flags */);
         pThis->pHostDrvAudio->pfnFiniIn(pThis->pHostDrvAudio, pHstStrmIn);
     }
Index: trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp	(revision 57397)
+++ trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp	(revision 57398)
@@ -549,12 +549,15 @@
     if (pDSoundStrmOut->pDSB != NULL)
     {
-        DWORD dwStatus;
         /* This performs some restore, so call it anyway and ignore result. */
-        dsoundPlayGetStatus(pDSoundStrmOut->pDSB, &dwStatus);
+        dsoundPlayGetStatus(pDSoundStrmOut->pDSB, NULL /* Status */);
 
         LogFlowFunc(("Playback stopped\n"));
 
         HRESULT hr = IDirectSoundBuffer8_Stop(pDSoundStrmOut->pDSB);
-        if (FAILED(hr))
+        if (SUCCEEDED(hr))
+        {
+            dsoundPlayClearSamples(pDSoundStrmOut);
+        }
+        else
             LogRelMax(s_cMaxRelLogEntries, ("DSound: Errpor stopping playback buffer: %Rhrc\n", hr));
     }
