Index: /trunk/include/VBox/vmm/pdmaudioifs.h
===================================================================
--- /trunk/include/VBox/vmm/pdmaudioifs.h	(revision 58599)
+++ /trunk/include/VBox/vmm/pdmaudioifs.h	(revision 58600)
@@ -377,4 +377,7 @@
     /** Name of this stream. */
     char                  *pszName;
+    /** Number of references to this stream. Only can be
+     *  destroyed if the reference count is reaching 0. */
+    uint8_t                cRefs;
 } PDMAUDIOGSTSTRMSTATE, *PPDMAUDIOGSTSTRMSTATE;
 
@@ -451,4 +454,22 @@
 
     /**
+     * Checks whether a specific guest input stream is active or not.
+     *
+     * @returns Whether the specified stream is active or not.
+     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
+     * @param   pGstStrmIn      Pointer to guest input stream.
+     */
+    DECLR3CALLBACKMEMBER(bool, pfnIsActiveIn, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn));
+
+    /**
+     * Checks whether a specific guest output stream is active or not.
+     *
+     * @returns Whether the specified stream is active or not.
+     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
+     * @param   pGstStrmOut     Pointer to guest output stream.
+     */
+    DECLR3CALLBACKMEMBER(bool, pfnIsActiveOut, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut));
+
+    /**
      * Checks whether the specified guest input stream is in a working state.
      *
@@ -497,21 +518,5 @@
 
     /**
-     * Closes a specific guest input stream.
-     *
-     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
-     * @param   pGstStrmIn      Pointer to guest input stream.
-     */
-    DECLR3CALLBACKMEMBER(void, pfnCloseIn, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn));
-
-    /**
-     * Closes a specific guest output stream.
-     *
-     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
-     * @param   pGstStrmOut     Pointer to guest output stream.
-     */
-    DECLR3CALLBACKMEMBER(void, pfnCloseOut, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut));
-
-    /**
-     * Opens an input audio channel.
+     * Creates a guest input stream.
      *
      * @returns VBox status code.
@@ -522,10 +527,10 @@
      * @param   ppGstStrmIn          Pointer where to return the guest guest input stream on success.
      */
-    DECLR3CALLBACKMEMBER(int, pfnOpenIn, (PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
-                                          PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg,
-                                          PPDMAUDIOGSTSTRMIN *ppGstStrmIn));
-
-    /**
-     * Opens an output audio channel.
+    DECLR3CALLBACKMEMBER(int, pfnCreateIn, (PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
+                                            PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg,
+                                            PPDMAUDIOGSTSTRMIN *ppGstStrmIn));
+
+    /**
+     * Creates a guest output stream.
      *
      * @returns VBox status code.
@@ -535,6 +540,22 @@
      * @param   ppGstStrmOut         Pointer where to return the guest guest input stream on success.
      */
-    DECLR3CALLBACKMEMBER(int, pfnOpenOut, (PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
-                                           PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut));
+    DECLR3CALLBACKMEMBER(int, pfnCreateOut, (PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
+                                             PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut));
+
+    /**
+     * Destroys a guest input stream.
+     *
+     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
+     * @param   pGstStrmIn      Pointer to guest input stream.
+     */
+    DECLR3CALLBACKMEMBER(void, pfnDestroyIn, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn));
+
+    /**
+     * Destroys a guest output stream.
+     *
+     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
+     * @param   pGstStrmOut     Pointer to guest output stream.
+     */
+    DECLR3CALLBACKMEMBER(void, pfnDestroyOut, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut));
 
     /**
@@ -547,26 +568,8 @@
     DECLR3CALLBACKMEMBER(int, pfnPlayOut, (PPDMIAUDIOCONNECTOR pInterface, uint32_t *pcSamplesPlayed));
 
-    /**
-     * Checks whether a specific guest input stream is active or not.
-     *
-     * @returns Whether the specified stream is active or not.
-     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
-     * @param   pGstStrmIn      Pointer to guest input stream.
-     */
-    DECLR3CALLBACKMEMBER(bool, pfnIsActiveIn, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn));
-
-    /**
-     * Checks whether a specific guest output stream is active or not.
-     *
-     * @returns Whether the specified stream is active or not.
-     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
-     * @param   pGstStrmOut     Pointer to guest output stream.
-     */
-    DECLR3CALLBACKMEMBER(bool, pfnIsActiveOut, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut));
-
 } PDMIAUDIOCONNECTOR;
 
 /** PDMIAUDIOCONNECTOR interface ID. */
-#define PDMIAUDIOCONNECTOR_IID                  "a41ca770-ed07-4f57-a0a6-41377d9d484f"
+#define PDMIAUDIOCONNECTOR_IID                  "7bbb9565-8dd2-4fab-81d6-4d78985e5daa"
 
 
Index: /trunk/src/VBox/Devices/Audio/AudioMixer.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/AudioMixer.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/AudioMixer.cpp	(revision 58600)
@@ -107,4 +107,8 @@
                      pSink->pszName, pMixStream, pSink->cStreams));
 
+        /* Increase the stream's reference count to let others know
+         * we're reyling on it to be around now. */
+        pStream->State.cRefs++;
+
         if (ppStream)
             *ppStream = pMixStream;
@@ -145,4 +149,8 @@
                      pSink->pszName, pMixStream, pSink->cStreams));
 
+        /* Increase the stream's reference count to let others know
+         * we're reyling on it to be around now. */
+        pStream->State.cRefs++;
+
         if (ppStream)
             *ppStream = pMixStream;
@@ -201,28 +209,22 @@
 void AudioMixerDestroy(PAUDIOMIXER pMixer)
 {
-    if (pMixer)
-    {
-        LogFlowFunc(("Destroying %s ...\n", pMixer->pszName));
-
-        PAUDMIXSINK pSink = RTListGetFirst(&pMixer->lstSinks, AUDMIXSINK, Node);
-        while (pSink)
-        {
-            PAUDMIXSINK pNext = RTListNodeGetNext(&pSink->Node, AUDMIXSINK, Node);
-            bool fLast = RTListNodeIsLast(&pMixer->lstSinks, &pSink->Node);
-
-            AudioMixerRemoveSink(pMixer, pSink);
-
-            if (fLast)
-                break;
-
-            pSink = pNext;
-        }
-
-        Assert(pMixer->cSinks == 0);
-
+    if (!pMixer)
+        return;
+
+    LogFlowFunc(("Destroying %s ...\n", pMixer->pszName));
+
+    PAUDMIXSINK pSink, pSinkNext;
+    RTListForEachSafe(&pMixer->lstSinks, pSink, pSinkNext, AUDMIXSINK, Node)
+        AudioMixerRemoveSink(pMixer, pSink);
+
+    Assert(pMixer->cSinks == 0);
+
+    if (pMixer->pszName)
+    {
         RTStrFree(pMixer->pszName);
-
-        RTMemFree(pMixer);
-    }
+        pMixer->pszName = NULL;
+    }
+
+    RTMemFree(pMixer);
 }
 
@@ -233,5 +235,6 @@
         return;
 
-    RTStrFree(pSink->pszName);
+    if (pSink->pszName)
+        RTStrFree(pSink->pszName);
 
     RTMemFree(pSink);
@@ -383,4 +386,26 @@
 #endif
 
+    /* Decrease the reference count again. */
+    switch (pSink->enmDir)
+    {
+        case AUDMIXSINKDIR_INPUT:
+        {
+            Assert(pStream->pIn->State.cRefs);
+            pStream->pIn->State.cRefs--;
+            break;
+        }
+
+        case AUDMIXSINKDIR_OUTPUT:
+        {
+            Assert(pStream->pOut->State.cRefs);
+            pStream->pOut->State.cRefs--;
+            break;
+        }
+
+        default:
+            AssertMsgFailed(("Not implemented\n"));
+            break;
+    }
+
     audioMixerDestroyStream(pStream);
 }
Index: /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 58600)
@@ -555,7 +555,7 @@
                     }
 
-                    rc = pDrv->pConnector->pfnOpenIn(pDrv->pConnector,
-                                                     pszDesc, PDMAUDIORECSOURCE_LINE_IN, &streamCfg, &pDrv->LineIn.pStrmIn);
-                    LogFlowFunc(("LUN#%RU8: Opened line input with rc=%Rrc\n", uLUN, rc));
+                    rc = pDrv->pConnector->pfnCreateIn(pDrv->pConnector,
+                                                       pszDesc, PDMAUDIORECSOURCE_LINE_IN, &streamCfg, &pDrv->LineIn.pStrmIn);
+                    LogFlowFunc(("LUN#%RU8: Created line input with rc=%Rrc\n", uLUN, rc));
                     if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
                     {
@@ -583,6 +583,6 @@
                     }
 
-                    rc = pDrv->pConnector->pfnOpenOut(pDrv->pConnector, pszDesc, &streamCfg, &pDrv->Out.pStrmOut);
-                    LogFlowFunc(("LUN#%RU8: Opened output with rc=%Rrc\n", uLUN, rc));
+                    rc = pDrv->pConnector->pfnCreateOut(pDrv->pConnector, pszDesc, &streamCfg, &pDrv->Out.pStrmOut);
+                    LogFlowFunc(("LUN#%RU8: Created output with rc=%Rrc\n", uLUN, rc));
                     if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
                     {
@@ -610,7 +610,7 @@
                     }
 
-                    rc = pDrv->pConnector->pfnOpenIn(pDrv->pConnector,
-                                                     pszDesc, PDMAUDIORECSOURCE_MIC, &streamCfg, &pDrv->MicIn.pStrmIn);
-                    LogFlowFunc(("LUN#%RU8: Opened mic input with rc=%Rrc\n", uLUN, rc));
+                    rc = pDrv->pConnector->pfnCreateIn(pDrv->pConnector,
+                                                       pszDesc, PDMAUDIORECSOURCE_MIC, &streamCfg, &pDrv->MicIn.pStrmIn);
+                    LogFlowFunc(("LUN#%RU8: Created mic input with rc=%Rrc\n", uLUN, rc));
                     if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
                     {
@@ -642,5 +642,5 @@
                 RTListForEach(&pThis->lstDrv, pDrv, AC97DRIVER, Node)
                 {
-                    pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->LineIn.pStrmIn);
+                    pDrv->pConnector->pfnDestroyIn(pDrv->pConnector, pDrv->LineIn.pStrmIn);
                     AudioMixerRemoveStream(pThis->pSinkLineIn, pDrv->LineIn.phStrmIn);
 
@@ -657,5 +657,5 @@
                 RTListForEach(&pThis->lstDrv, pDrv, AC97DRIVER, Node)
                 {
-                    pDrv->pConnector->pfnCloseOut(pDrv->pConnector, pDrv->Out.pStrmOut);
+                    pDrv->pConnector->pfnDestroyOut(pDrv->pConnector, pDrv->Out.pStrmOut);
                     AudioMixerRemoveStream(pThis->pSinkOutput, pDrv->Out.phStrmOut);
 
@@ -672,5 +672,5 @@
                 RTListForEach(&pThis->lstDrv, pDrv, AC97DRIVER, Node)
                 {
-                    pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->MicIn.pStrmIn);
+                    pDrv->pConnector->pfnDestroyIn(pDrv->pConnector, pDrv->MicIn.pStrmIn);
                     AudioMixerRemoveStream(pThis->pSinkMicIn, pDrv->MicIn.phStrmIn);
 
@@ -844,36 +844,46 @@
 }
 
-static void ichac97MixerReset(PAC97STATE pThis)
-{
+static int ichac97MixerReset(PAC97STATE pThis)
+{
+    AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
+
     LogFlowFuncEnter();
 
     RT_ZERO(pThis->mixer_data);
+
+    /*
+     * Tear down mixer and streams.
+     */
+    if (pThis->pMixer)
+    {
+        AudioMixerDestroy(pThis->pMixer);
+        pThis->pMixer = NULL;
+    }
+
+    pThis->pSinkLineIn = NULL;
+    pThis->pSinkMicIn  = NULL;
+    pThis->pSinkOutput = NULL;
 
     PAC97DRIVER pDrv;
     RTListForEach(&pThis->lstDrv, pDrv, AC97DRIVER, Node)
     {
-        pDrv->Out.phStrmOut   = NULL;
-        pDrv->pConnector->pfnCloseOut(pDrv->pConnector, pDrv->Out.pStrmOut);
-        pDrv->Out.pStrmOut    = NULL;
-        pDrv->LineIn.phStrmIn = NULL;
-        pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->LineIn.pStrmIn);
-        pDrv->LineIn.pStrmIn  = NULL;
-        pDrv->MicIn.phStrmIn  = NULL;
-        pDrv->pConnector->pfnCloseIn(pDrv->pConnector, pDrv->MicIn.pStrmIn);
-        pDrv->MicIn.pStrmIn   = NULL;
-    }
-
-    pThis->pSinkOutput = NULL;
-    pThis->pSinkLineIn = NULL;
-    pThis->pSinkMicIn  = NULL;
-
-    if (pThis->pMixer)
-    {
-        AudioMixerDestroy(pThis->pMixer);
-        pThis->pMixer = NULL;
-    }
-
-    int rc2 = AudioMixerCreate("AC'97 Mixer", 0 /* uFlags */, &pThis->pMixer);
-    if (RT_SUCCESS(rc2))
+        pDrv->pConnector->pfnDestroyIn (pDrv->pConnector, pDrv->LineIn.pStrmIn);
+        RT_ZERO(pDrv->LineIn);
+
+        pDrv->pConnector->pfnDestroyIn (pDrv->pConnector, pDrv->MicIn.pStrmIn);
+        RT_ZERO(pDrv->MicIn);
+
+        pDrv->pConnector->pfnDestroyOut(pDrv->pConnector, pDrv->Out.pStrmOut);
+        RT_ZERO(pDrv->Out);
+    }
+
+    /*
+     * (Re-)Create the mixer. The streams will be created on demand later.
+     */
+    int rc = AudioMixerCreate("AC'97 Mixer", 0 /* uFlags */, &pThis->pMixer);
+    if (RT_FAILURE(rc))
+        return rc;
+
+    do
     {
         /* Set a default audio format for our mixer. */
@@ -884,20 +894,24 @@
         streamCfg.enmEndianness = PDMAUDIOHOSTENDIANNESS;
 
-        rc2 = AudioMixerSetDeviceFormat(pThis->pMixer, &streamCfg);
-        AssertRC(rc2);
+        rc = AudioMixerSetDeviceFormat(pThis->pMixer, &streamCfg);
+        if (RT_FAILURE(rc))
+            break;
 
         /* Add all required audio sinks. */
-        rc2 = AudioMixerAddSink(pThis->pMixer, "[Playback] PCM Output",
-                               AUDMIXSINKDIR_OUTPUT, &pThis->pSinkOutput);
-        AssertRC(rc2);
-
-        rc2 = AudioMixerAddSink(pThis->pMixer, "[Recording] Line In",
-                                AUDMIXSINKDIR_INPUT, &pThis->pSinkLineIn);
-        AssertRC(rc2);
-
-        rc2 = AudioMixerAddSink(pThis->pMixer, "[Recording] Microphone In",
-                                AUDMIXSINKDIR_INPUT, &pThis->pSinkMicIn);
-        AssertRC(rc2);
-    }
+        rc = AudioMixerAddSink(pThis->pMixer, "[Playback] PCM Output", AUDMIXSINKDIR_OUTPUT, &pThis->pSinkOutput);
+        if (RT_FAILURE(rc))
+            break;
+
+        rc = AudioMixerAddSink(pThis->pMixer, "[Recording] Line In", AUDMIXSINKDIR_INPUT, &pThis->pSinkLineIn);
+        if (RT_FAILURE(rc))
+            break;
+
+        rc = AudioMixerAddSink(pThis->pMixer, "[Recording] Microphone In", AUDMIXSINKDIR_INPUT, &pThis->pSinkMicIn);
+        if (RT_FAILURE(rc))
+            break;
+
+    } while (0);
+
+    /* Note: Make sure to reset all registers first before bailing out on error. */
 
     ichac97MixerStore(pThis, AC97_Reset                   , 0x0000); /* 6940 */
@@ -951,4 +965,6 @@
     uint8_t active[LAST_INDEX] = { 0 };
     ichac97ResetStreams(pThis, active);
+
+    return rc;
 }
 
@@ -1946,5 +1962,5 @@
     if (pThis->uCodecModel == Codec_AD1980)
         if (ichac97MixerLoad(pThis, AC97_AD_Misc) & AD_MISC_HPSEL)
-            ichac97SetVolume(pThis, AC97_Headphone_Volume_Mute, PDMAUDIOMIXERCTL_VOLUME, 
+            ichac97SetVolume(pThis, AC97_Headphone_Volume_Mute, PDMAUDIOMIXERCTL_VOLUME,
                              ichac97MixerLoad(pThis, AC97_Headphone_Volume_Mute));
 
@@ -2262,21 +2278,14 @@
         AssertPtr(pCon);
         if (   !pCon->pfnIsInputOK (pCon, pDrv->LineIn.pStrmIn)
-            && !pCon->pfnIsOutputOK(pCon, pDrv->Out.pStrmOut)
-            && !pCon->pfnIsInputOK (pCon, pDrv->MicIn.pStrmIn))
-        {
-            LogRel(("AC97: Falling back to NULL driver\n"));
+            && !pCon->pfnIsInputOK (pCon, pDrv->MicIn.pStrmIn)
+            && !pCon->pfnIsOutputOK(pCon, pDrv->Out.pStrmOut))
+        {
+            LogRel(("AC97: Falling back to NULL driver (no sound audible)\n"));
+
+            ac97Reset(pDevIns);
 
             /* Was not able initialize *any* stream.
              * Select the NULL audio driver instead. */
-            pCon->pfnCloseIn (pCon, pDrv->LineIn.pStrmIn);
-            pCon->pfnCloseOut(pCon, pDrv->Out.pStrmOut);
-            pCon->pfnCloseIn (pCon, pDrv->MicIn.pStrmIn);
-
-            pDrv->Out.pStrmOut = NULL;
-            pDrv->LineIn.pStrmIn = NULL;
-            pDrv->MicIn.pStrmIn = NULL;
-
             pCon->pfnInitNull(pCon);
-            ac97Reset(pDevIns);
 
             PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding",
@@ -2285,6 +2294,6 @@
         }
         else if (   !pCon->pfnIsInputOK (pCon, pDrv->LineIn.pStrmIn)
-                 || !pCon->pfnIsOutputOK(pCon, pDrv->Out.pStrmOut)
-                 || !pCon->pfnIsInputOK (pCon, pDrv->MicIn.pStrmIn))
+                 || !pCon->pfnIsInputOK (pCon, pDrv->MicIn.pStrmIn)
+                 || !pCon->pfnIsOutputOK(pCon, pDrv->Out.pStrmOut))
         {
             char   szMissingStreams[255];
Index: /trunk/src/VBox/Devices/Audio/DevIchHda.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevIchHda.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DevIchHda.cpp	(revision 58600)
@@ -2303,5 +2303,5 @@
 }
 
-static DECLCALLBACK(void) hdaCloseIn(PHDASTATE pThis, PDMAUDIORECSOURCE enmRecSource)
+static DECLCALLBACK(void) hdaDestroyIn(PHDASTATE pThis, PDMAUDIORECSOURCE enmRecSource)
 {
     NOREF(pThis);
@@ -2310,5 +2310,5 @@
 }
 
-static DECLCALLBACK(void) hdaCloseOut(PHDASTATE pThis)
+static DECLCALLBACK(void) hdaDestroyOut(PHDASTATE pThis)
 {
     NOREF(pThis);
@@ -2316,7 +2316,7 @@
 }
 
-static DECLCALLBACK(int) hdaOpenIn(PHDASTATE pThis,
-                                   const char *pszName, PDMAUDIORECSOURCE enmRecSource,
-                                   PPDMAUDIOSTREAMCFG pCfg)
+static DECLCALLBACK(int) hdaCreateIn(PHDASTATE pThis,
+                                     const char *pszName, PDMAUDIORECSOURCE enmRecSource,
+                                     PPDMAUDIOSTREAMCFG pCfg)
 {
     PAUDMIXSINK pSink;
@@ -2349,6 +2349,6 @@
         }
 
-        rc = pDrv->pConnector->pfnOpenIn(pDrv->pConnector, pszDesc, enmRecSource, pCfg, &pDrv->LineIn.pStrmIn);
-        LogFlowFunc(("LUN#%RU8: Opened input \"%s\", with rc=%Rrc\n", pDrv->uLUN, pszDesc, rc));
+        rc = pDrv->pConnector->pfnCreateIn(pDrv->pConnector, pszDesc, enmRecSource, pCfg, &pDrv->LineIn.pStrmIn);
+        LogFlowFunc(("LUN#%RU8: Created input \"%s\", with rc=%Rrc\n", pDrv->uLUN, pszDesc, rc));
         if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
         {
@@ -2366,6 +2366,6 @@
 }
 
-static DECLCALLBACK(int) hdaOpenOut(PHDASTATE pThis,
-                                    const char *pszName, PPDMAUDIOSTREAMCFG pCfg)
+static DECLCALLBACK(int) hdaCreateOut(PHDASTATE pThis,
+                                      const char *pszName, PPDMAUDIOSTREAMCFG pCfg)
 {
     int rc = VINF_SUCCESS;
@@ -2381,6 +2381,6 @@
         }
 
-        rc = pDrv->pConnector->pfnOpenOut(pDrv->pConnector, pszDesc, pCfg, &pDrv->Out.pStrmOut);
-        LogFlowFunc(("LUN#%RU8: Opened output \"%s\", with rc=%Rrc\n", pDrv->uLUN, pszDesc, rc));
+        rc = pDrv->pConnector->pfnCreateOut(pDrv->pConnector, pszDesc, pCfg, &pDrv->Out.pStrmOut);
+        LogFlowFunc(("LUN#%RU8: Created output \"%s\", with rc=%Rrc\n", pDrv->uLUN, pszDesc, rc));
         if (rc == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
         {
@@ -3761,10 +3761,10 @@
 
         /* Audio driver callbacks for multiplexing. */
-        pThis->pCodec->pfnCloseIn   = hdaCloseIn;
-        pThis->pCodec->pfnCloseOut  = hdaCloseOut;
-        pThis->pCodec->pfnOpenIn    = hdaOpenIn;
-        pThis->pCodec->pfnOpenOut   = hdaOpenOut;
-        pThis->pCodec->pfnReset     = hdaCodecReset;
-        pThis->pCodec->pfnSetVolume = hdaSetVolume;
+        pThis->pCodec->pfnDestroyIn  = hdaDestroyIn;
+        pThis->pCodec->pfnDestroyOut = hdaDestroyOut;
+        pThis->pCodec->pfnCreateIn   = hdaCreateIn;
+        pThis->pCodec->pfnCreateOut  = hdaCreateOut;
+        pThis->pCodec->pfnReset      = hdaCodecReset;
+        pThis->pCodec->pfnSetVolume  = hdaSetVolume;
 
         pThis->pCodec->pHDAState = pThis; /* Assign HDA controller state to codec. */
Index: /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.cpp	(revision 58600)
@@ -2611,14 +2611,14 @@
     {
         case PI_INDEX:
-            rc = pThis->pfnOpenIn(pThis->pHDAState, "hda.in", PDMAUDIORECSOURCE_LINE_IN, pCfg);
+            rc = pThis->pfnCreateIn(pThis->pHDAState, "hda.in", PDMAUDIORECSOURCE_LINE_IN, pCfg);
             break;
 
         case PO_INDEX:
-            rc = pThis->pfnOpenOut(pThis->pHDAState, "hda.out", pCfg);
+            rc = pThis->pfnCreateOut(pThis->pHDAState, "hda.out", pCfg);
             break;
 
 #ifdef VBOX_WITH_HDA_MIC_IN
         case MC_INDEX:
-            rc = pThis->pfnOpenIn(pThis->pHDAState, "hda.mc", PDMAUDIORECSOURCE_MIC, pCfg);
+            rc = pThis->pfnCreateIn(pThis->pHDAState, "hda.mc", PDMAUDIORECSOURCE_MIC, pCfg);
             break;
 #endif
Index: /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.h
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.h	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DevIchHdaCodec.h	(revision 58600)
@@ -111,8 +111,8 @@
 #endif
     /** Callbacks to the HDA controller, mostly used for multiplexing to the various host backends. */
-    DECLR3CALLBACKMEMBER(void, pfnCloseIn, (PHDASTATE pThis, PDMAUDIORECSOURCE enmRecSource));
-    DECLR3CALLBACKMEMBER(void, pfnCloseOut, (PHDASTATE pThis));
-    DECLR3CALLBACKMEMBER(int, pfnOpenIn, (PHDASTATE pThis, const char *pszName, PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg));
-    DECLR3CALLBACKMEMBER(int, pfnOpenOut, (PHDASTATE pThis, const char *pszName, PPDMAUDIOSTREAMCFG pCfg));
+    DECLR3CALLBACKMEMBER(void, pfnDestroyIn, (PHDASTATE pThis, PDMAUDIORECSOURCE enmRecSource));
+    DECLR3CALLBACKMEMBER(void, pfnDestroyOut, (PHDASTATE pThis));
+    DECLR3CALLBACKMEMBER(int, pfnCreateIn, (PHDASTATE pThis, const char *pszName, PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg));
+    DECLR3CALLBACKMEMBER(int, pfnCreateOut, (PHDASTATE pThis, const char *pszName, PPDMAUDIOSTREAMCFG pCfg));
     DECLR3CALLBACKMEMBER(int, pfnSetVolume, (PHDASTATE pThis, ENMSOUNDSOURCE enmSource, bool fMute, uint8_t uVolLeft, uint8_t uVolRight));
     /** Callbacks by codec implementation. */
Index: /trunk/src/VBox/Devices/Audio/DevSB16.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DevSB16.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DevSB16.cpp	(revision 58600)
@@ -1946,6 +1946,6 @@
         }
 
-        int rc2 = pDrv->pConnector->pfnOpenOut(pDrv->pConnector, pszDesc, pCfg, &pDrv->Out.pStrmOut);
-        LogFlowFunc(("LUN#%RU8: Opened output with rc=%Rrc\n", uLUN, rc));
+        int rc2 = pDrv->pConnector->pfnCreateOut(pDrv->pConnector, pszDesc, pCfg, &pDrv->Out.pStrmOut);
+        LogFlowFunc(("LUN#%RU8: Created output with rc=%Rrc\n", uLUN, rc));
         if (rc2 == VINF_SUCCESS) /* Note: Could return VWRN_ALREADY_EXISTS. */
         {
@@ -2193,5 +2193,5 @@
             LogRel(("SB16: Warning: Unable to enable/use output for LUN#%RU8\n", uLUN));
 
-            pCon->pfnCloseOut(pCon, pDrv->Out.pStrmOut);
+            pCon->pfnDestroyOut(pCon, pDrv->Out.pStrmOut);
             pDrv->Out.pStrmOut = NULL;
 
Index: /trunk/src/VBox/Devices/Audio/DrvAudio.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 58599)
+++ /trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 58600)
@@ -574,21 +574,24 @@
     AssertPtrReturn(pThis, VERR_INVALID_POINTER);
 
-    if (pGstStrmOut)
-    {
-        drvAudioGstOutFreeRes(pGstStrmOut);
-
-        if (pGstStrmOut->pHstStrmOut)
-        {
-            /* Unregister from parent first. */
-            RTListNodeRemove(&pGstStrmOut->Node);
-
-            /* Try destroying the associated host output stream. This could
-             * be skipped if there are other guest output streams with this
-             * host stream. */
-            drvAudioDestroyHstOut(pThis, pGstStrmOut->pHstStrmOut);
-        }
-
-        RTMemFree(pGstStrmOut);
-    }
+    if (!pGstStrmOut)
+        return VINF_SUCCESS;
+
+    if (pGstStrmOut->State.cRefs > 1) /* Do other objects still have a reference to it? Bail out. */
+        return VERR_WRONG_ORDER;
+
+    drvAudioGstOutFreeRes(pGstStrmOut);
+
+    if (pGstStrmOut->pHstStrmOut)
+    {
+        /* Unregister from parent first. */
+        RTListNodeRemove(&pGstStrmOut->Node);
+
+        /* Try destroying the associated host output stream. This could
+         * be skipped if there are other guest output streams with this
+         * host stream. */
+        drvAudioDestroyHstOut(pThis, pGstStrmOut->pHstStrmOut);
+    }
+
+    RTMemFree(pGstStrmOut);
 
     return VINF_SUCCESS;
@@ -666,4 +669,5 @@
         if (RT_SUCCESS(rc))
         {
+            pGstStrmOut->State.cRefs   = 1;
             pGstStrmOut->State.fActive = false;
             pGstStrmOut->State.fEmpty  = true;
@@ -921,4 +925,5 @@
             drvAudioStreamCfgPrint(pCfg);
 #endif
+            pGstStrmIn->State.cRefs   = 1;
             pGstStrmIn->State.fActive = false;
             pGstStrmIn->State.fEmpty  = true;
@@ -1158,21 +1163,24 @@
     LogFlowFunc(("%s\n", pGstStrmIn->MixBuf.pszName));
 
-    if (pGstStrmIn)
-    {
-        drvAudioGstInFreeRes(pGstStrmIn);
-
-        if (pGstStrmIn->pHstStrmIn)
-        {
-            /* Unlink child. */
-            pGstStrmIn->pHstStrmIn->pGstStrmIn = NULL;
-
-            /* Try destroying the associated host input stream. This could
-             * be skipped if there are other guest input streams with this
-             * host stream. */
-            drvAudioDestroyHstIn(pThis, pGstStrmIn->pHstStrmIn);
-        }
-
-        RTMemFree(pGstStrmIn);
-    }
+    if (!pGstStrmIn)
+        return VINF_SUCCESS;
+
+    if (pGstStrmIn->State.cRefs > 1) /* Do other objects still have a reference to it? Bail out. */
+        return VERR_WRONG_ORDER;
+
+    drvAudioGstInFreeRes(pGstStrmIn);
+
+    if (pGstStrmIn->pHstStrmIn)
+    {
+        /* Unlink child. */
+        pGstStrmIn->pHstStrmIn->pGstStrmIn = NULL;
+
+        /* Try destroying the associated host input stream. This could
+         * be skipped if there are other guest input streams with this
+         * host stream. */
+        drvAudioDestroyHstIn(pThis, pGstStrmIn->pHstStrmIn);
+    }
+
+    RTMemFree(pGstStrmIn);
 
     return VINF_SUCCESS;
@@ -1720,7 +1728,7 @@
 }
 
-static DECLCALLBACK(int) drvAudioOpenIn(PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
-                                        PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg,
-                                        PPDMAUDIOGSTSTRMIN *ppGstStrmIn)
+static DECLCALLBACK(int) drvAudioCreateIn(PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
+                                          PDMAUDIORECSOURCE enmRecSource, PPDMAUDIOSTREAMCFG pCfg,
+                                          PPDMAUDIOGSTSTRMIN *ppGstStrmIn)
 {
     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
@@ -1786,6 +1794,6 @@
 }
 
-static DECLCALLBACK(int) drvAudioOpenOut(PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
-                                         PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut)
+static DECLCALLBACK(int) drvAudioCreateOut(PPDMIAUDIOCONNECTOR pInterface, const char *pszName,
+                                           PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut)
 {
     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
@@ -1891,5 +1899,5 @@
 }
 
-static DECLCALLBACK(void) drvAudioCloseIn(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn)
+static DECLCALLBACK(void) drvAudioDestroyIn(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn)
 {
     PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
@@ -1898,5 +1906,5 @@
 }
 
-static DECLCALLBACK(void) drvAudioCloseOut(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut)
+static DECLCALLBACK(void) drvAudioDestroyOut(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut)
 {
     PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface);
@@ -1982,4 +1990,6 @@
     pThis->IAudioConnector.pfnRead                   = drvAudioRead;
     pThis->IAudioConnector.pfnWrite                  = drvAudioWrite;
+    pThis->IAudioConnector.pfnIsActiveIn             = drvAudioIsActiveIn;
+    pThis->IAudioConnector.pfnIsActiveOut            = drvAudioIsActiveOut;
     pThis->IAudioConnector.pfnIsInputOK              = drvAudioIsInputOK;
     pThis->IAudioConnector.pfnIsOutputOK             = drvAudioIsOutputOK;
@@ -1987,11 +1997,9 @@
     pThis->IAudioConnector.pfnEnableOut              = drvAudioEnableOut;
     pThis->IAudioConnector.pfnEnableIn               = drvAudioEnableIn;
-    pThis->IAudioConnector.pfnCloseIn                = drvAudioCloseIn;
-    pThis->IAudioConnector.pfnCloseOut               = drvAudioCloseOut;
-    pThis->IAudioConnector.pfnOpenIn                 = drvAudioOpenIn;
-    pThis->IAudioConnector.pfnOpenOut                = drvAudioOpenOut;
+    pThis->IAudioConnector.pfnDestroyIn              = drvAudioDestroyIn;
+    pThis->IAudioConnector.pfnDestroyOut             = drvAudioDestroyOut;
+    pThis->IAudioConnector.pfnCreateIn               = drvAudioCreateIn;
+    pThis->IAudioConnector.pfnCreateOut              = drvAudioCreateOut;
     pThis->IAudioConnector.pfnPlayOut                = drvAudioPlayOut;
-    pThis->IAudioConnector.pfnIsActiveIn             = drvAudioIsActiveIn;
-    pThis->IAudioConnector.pfnIsActiveOut            = drvAudioIsActiveOut;
 
     /*
