Index: /trunk/src/VBox/Main/include/DrvAudioVRDE.h
===================================================================
--- /trunk/src/VBox/Main/include/DrvAudioVRDE.h	(revision 70534)
+++ /trunk/src/VBox/Main/include/DrvAudioVRDE.h	(revision 70535)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2014-2017 Oracle Corporation
+ * Copyright (C) 2014-2018 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,11 +20,18 @@
 
 #include <VBox/com/ptr.h>
+#include <VBox/com/string.h>
+
 #include <VBox/RemoteDesktop/VRDE.h>
+
 #include <VBox/vmm/pdmdrv.h>
 #include <VBox/vmm/pdmifs.h>
 
+#include "AudioDriver.h"
+
+using namespace com;
+
 class Console;
 
-class AudioVRDE
+class AudioVRDE : public AudioDriver
 {
 
@@ -37,6 +44,4 @@
 
     static const PDMDRVREG DrvReg;
-
-    Console *getParent(void) { return mParent; }
 
 public:
@@ -55,8 +60,8 @@
 private:
 
+    void configureDriver(PCFGMNODE pLunCfg);
+
     /** Pointer to the associated VRDE audio driver. */
     struct DRVAUDIOVRDE *mpDrv;
-    /** Pointer to parent. */
-    Console * const mParent;
 };
 
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 70534)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 70535)
@@ -5405,5 +5405,15 @@
                             mConsoleVRDPServer->Stop();
 
-                            int vrc = mConsoleVRDPServer->Launch();
+                            int vrc;
+#ifdef VBOX_WITH_AUDIO_VRDE
+                            if (!mAudioVRDE->IsAttached())
+                            {
+                                vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY /*idDstCpu*/,
+                                                       (PFNRT)AudioVRDE::Attach, 2,
+                                                       mAudioVRDE, mAudioVRDE->GetConfig());
+                                AssertRC(vrc);
+                            }
+#endif
+                            vrc = mConsoleVRDPServer->Launch();
                             if (vrc != VINF_SUCCESS)
                             {
@@ -5415,5 +5425,16 @@
                         }
                         else
+                        {
                             mConsoleVRDPServer->Stop();
+#ifdef VBOX_WITH_AUDIO_VRDE
+                            if (mAudioVRDE->IsAttached())
+                            {
+                                int vrc2 = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY /*idDstCpu*/,
+                                                            (PFNRT)AudioVRDE::Detach, 1,
+                                                            mAudioVRDE);
+                                AssertRC(vrc2);
+                            }
+#endif
+                        }
 
                         alock.acquire();
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 70534)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 70535)
@@ -122,4 +122,7 @@
 #endif /* VBOX_WITH_NETFLT */
 
+#ifdef VBOX_WITH_AUDIO_VRDE
+# include "DrvAudioVRDE.h"
+#endif
 #include "NetworkServiceRunner.h"
 #include "BusAssignmentManager.h"
@@ -2964,24 +2967,19 @@
 
 #ifdef VBOX_WITH_AUDIO_VRDE
-            /*
-             * The VRDE audio backend driver.
-             */
-            CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%RU8", uAudioLUN++);
-            InsertConfigString(pLunL0, "Driver", "AUDIO");
-
-            InsertConfigNode(pLunL0,   "Config", &pCfg);
-                InsertConfigString (pCfg, "DriverName",    "AudioVRDE");
-                InsertConfigInteger(pCfg, "InputEnabled",  fAudioEnabledIn);
-                InsertConfigInteger(pCfg, "OutputEnabled", fAudioEnabledOut);
-                InsertConfigInteger(pCfg, "DebugEnabled",  fDebugEnabled);
-                InsertConfigString (pCfg, "DebugPathOut",  strDebugPathOut);
-
-            InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
-                InsertConfigString(pLunL1, "Driver", "AudioVRDE");
-
-                InsertConfigNode(pLunL1, "Config", &pCfg);
-                    InsertConfigString (pCfg, "StreamName", bstr);
-                    InsertConfigInteger(pCfg, "Object", (uintptr_t)mAudioVRDE);
-                    InsertConfigInteger(pCfg, "ObjectVRDPServer", (uintptr_t)mConsoleVRDPServer);
+            BOOL fVRDEEnabled = FALSE;
+
+            if (mVRDEServer)
+            {
+                hrc = mVRDEServer->COMGETTER(Enabled)(&fVRDEEnabled);
+                ComAssertComRC(hrc);
+            }
+
+            AudioDriverCfg Cfg(strAudioDevice, 0 /* Instance */, uAudioLUN);
+            rc = mAudioVRDE->Configure(&Cfg, fVRDEEnabled /* Attach */);
+            if (   RT_SUCCESS(rc)
+                && fVRDEEnabled) /* Successfully configured, use next LUN for drivers below. */
+            {
+                uAudioLUN++;
+            }
 #endif /* VBOX_WITH_AUDIO_VRDE */
 
Index: /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp	(revision 70534)
+++ /trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp	(revision 70535)
@@ -570,6 +570,6 @@
 
 AudioVRDE::AudioVRDE(Console *pConsole)
-    : mpDrv(NULL),
-      mParent(pConsole)
+    : AudioDriver(pConsole)
+    , mpDrv(NULL)
 {
 }
@@ -585,4 +585,10 @@
 }
 
+
+void AudioVRDE::configureDriver(PCFGMNODE pLunCfg)
+{
+    CFGMR3InsertInteger(pLunCfg, "Object", (uintptr_t)this);
+    CFGMR3InsertInteger(pLunCfg, "ObjectVRDPServer", (uintptr_t)mpConsole->i_consoleVRDPServer());
+}
 
 int AudioVRDE::onVRDEControl(bool fEnable, uint32_t uFlags)
