Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp	(revision 75312)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp	(revision 75313)
@@ -886,8 +886,5 @@
         CCaptureSettings captureSettings = machine.GetCaptureSettings();
         Assert(captureSettings.isOk());
-        /* For now all screens have the same config: */
-        CCaptureScreenSettings captureScreen0Settings = captureSettings.GetScreenSettings(0);
-        Assert(captureScreen0Settings.isOk());
-        if (!captureScreen0Settings.GetEnabled())
+        if (!captureSettings.GetEnabled())
             setState(UIIndicatorStateRecording_Disabled);
         else if (!fMachinePaused)
@@ -919,4 +916,8 @@
                 else if (m_eRecordingMode & UIIndicatorStateRecordingMode_Video)
                     strToolTip = "Video capture file";
+
+                /* For now all screens have the same config: */
+                CCaptureScreenSettings captureScreen0Settings = captureSettings.GetScreenSettings(0);
+                Assert(captureScreen0Settings.isOk());
 
                 strFullData += s_strTableRow2 /** @todo r=andy Refine this tooltip (audio and/or video). */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp	(revision 75312)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp	(revision 75313)
@@ -1587,14 +1587,14 @@
                         fSuccess = recordingScreenSettings.isOk();
                     }
+                    /* Save recording options: */
+                    if (fSuccess && newDisplayData.m_strRecordingVideoOptions != oldDisplayData.m_strRecordingVideoOptions)
+                    {
+                        recordingScreenSettings.SetOptions(newDisplayData.m_strRecordingVideoOptions);
+                        fSuccess = recordingScreenSettings.isOk();
+                    }
                     /* Save recording screens: */
                     if (fSuccess && newDisplayData.m_vecRecordingScreens != oldDisplayData.m_vecRecordingScreens)
                     {
                         recordingScreenSettings.SetEnabled(newDisplayData.m_vecRecordingScreens[iScreenIndex]);
-                        fSuccess = recordingScreenSettings.isOk();
-                    }
-                    /* Save recording options: */
-                    if (fSuccess && newDisplayData.m_strRecordingVideoOptions != oldDisplayData.m_strRecordingVideoOptions)
-                    {
-                        recordingScreenSettings.SetOptions(newDisplayData.m_strRecordingVideoOptions);
                         fSuccess = recordingScreenSettings.isOk();
                     }
Index: /trunk/src/VBox/Main/include/CaptureScreenSettingsImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/CaptureScreenSettingsImpl.h	(revision 75312)
+++ /trunk/src/VBox/Main/include/CaptureScreenSettingsImpl.h	(revision 75313)
@@ -102,5 +102,4 @@
 
     // internal methods
-    bool i_canChangeSettings();
     int  i_getDefaultFileName(Utf8Str &strFile);
     int  i_initInternal();
Index: /trunk/src/VBox/Main/include/VideoRec.h
===================================================================
--- /trunk/src/VBox/Main/include/VideoRec.h	(revision 75312)
+++ /trunk/src/VBox/Main/include/VideoRec.h	(revision 75313)
@@ -29,130 +29,4 @@
 #include "VideoRecInternals.h"
 #include "VideoRecStream.h"
-
-#if 0
-/**
- * Enumeration for definining a video / audio
- * profile setting.
- */
-typedef enum VIDEORECPROFILE
-{
-    VIDEORECPROFILE_NONE   = 0,
-    VIDEORECPROFILE_LOW,
-    VIDEORECPROFILE_MEDIUM,
-    VIDEORECPROFILE_HIGH,
-    VIDEORECPROFILE_BEST,
-    VIDEORECPROFILE_REALTIME
-} VIDEORECPROFILE;
-
-/** Stores video recording features. */
-typedef uint32_t VIDEORECFEATURES;
-
-/** Video recording is disabled completely. */
-#define VIDEORECFEATURE_NONE        0
-/** Capturing video is enabled. */
-#define VIDEORECFEATURE_VIDEO       RT_BIT(0)
-/** Capturing audio is enabled. */
-#define VIDEORECFEATURE_AUDIO       RT_BIT(1)
-
-/**
- * Structure for keeping a screen recording configuration.
- */
-typedef struct VIDEORECSCREENCFG
-{
-    VIDEORECSCREENCFG(void)
-        : enmDst(VIDEORECDEST_INVALID)
-        , uMaxTimeS(0)
-    {
-#ifdef VBOX_WITH_AUDIO_VIDEOREC
-        RT_ZERO(Audio);
-#endif
-        RT_ZERO(Video);
-    }
-
-    VIDEORECSCREENCFG& operator=(const VIDEORECSCREENCFG &that)
-    {
-        enmDst          = that.enmDst;
-
-        File.strName    = that.File.strName;
-        File.uMaxSizeMB = that.File.uMaxSizeMB;
-#ifdef VBOX_WITH_AUDIO_VIDEOREC
-        Audio           = that.Audio;
-#endif
-        Video           = that.Video;
-        uMaxTimeS       = that.uMaxTimeS;
-        return *this;
-    }
-
-    unsigned long           uScreenId;
-    /** Destination where to write the stream to. */
-    VIDEORECDEST            enmDst;
-
-    /**
-     * Structure for keeping recording parameters if
-     * destination is a file.
-     */
-    struct
-    {
-        /** File name (as absolute path). */
-        com::Bstr       strName;
-        /** Maximum file size (in MB) to record. */
-        uint32_t        uMaxSizeMB;
-    } File;
-
-#ifdef VBOX_WITH_AUDIO_VIDEOREC
-    /**
-     * Structure for keeping the audio recording parameters.
-     */
-    struct
-    {
-        /** Whether audio recording is enabled or not. */
-        bool                fEnabled;
-        /** The device LUN the audio driver is attached / configured to. */
-        unsigned            uLUN;
-        /** Hertz (Hz) rate. */
-        uint16_t            uHz;
-        /** Bits per sample. */
-        uint8_t             cBits;
-        /** Number of audio channels. */
-        uint8_t             cChannels;
-        /** Audio profile which is being used. */
-        VIDEORECPROFILE     enmProfile;
-    } Audio;
-#endif
-
-    /**
-     * Structure for keeping the video recording parameters.
-     */
-    struct
-    {
-        /** Whether video recording is enabled or not. */
-        bool                fEnabled;
-        /** Target width (in pixels). */
-        uint32_t            uWidth;
-        /** Target height (in pixels). */
-        uint32_t            uHeight;
-        /** Target encoding rate. */
-        uint32_t            uRate;
-        /** Target FPS. */
-        uint32_t            uFPS;
-
-#ifdef VBOX_WITH_LIBVPX
-        union
-        {
-            struct
-            {
-                /** Encoder deadline. */
-                unsigned int uEncoderDeadline;
-            } VPX;
-        } Codec;
-#endif
-
-    } Video;
-
-    /** Maximum time (in s) to record.
-     *  Specify 0 to disable this check. */
-    uint32_t                uMaxTimeS;
-} VIDEORECSCREENCFG, *PVIDEORECSCREENCFG;
-#endif
 
 class Console;
@@ -212,4 +86,19 @@
 protected:
 
+    /**
+     * Enumeration for a recording context state.
+     */
+    enum VIDEORECSTS
+    {
+        /** Context not initialized. */
+        VIDEORECSTS_UNINITIALIZED = 0,
+        /** Context was created. */
+        VIDEORECSTS_CREATED       = 1,
+        /** Context was started. */
+        VIDEORECSTS_STARTED       = 2,
+        /** The usual 32-bit hack. */
+        VIDEORECSTS_32BIT_HACK    = 0x7fffffff
+    };
+
     /** Pointer to the console object. */
     Console                  *pConsole;
@@ -217,11 +106,9 @@
     settings::CaptureSettings Settings;
     /** The current state. */
-    uint32_t                  enmState;
+    VIDEORECSTS               enmState;
     /** Critical section to serialize access. */
     RTCRITSECT                CritSect;
     /** Semaphore to signal the encoding worker thread. */
     RTSEMEVENT                WaitEvent;
-    /** Whether this context is in started state or not. */
-    bool                      fStarted;
     /** Shutdown indicator. */
     bool                      fShutdown;
Index: /trunk/src/VBox/Main/include/VideoRecStream.h
===================================================================
--- /trunk/src/VBox/Main/include/VideoRecStream.h	(revision 75312)
+++ /trunk/src/VBox/Main/include/VideoRecStream.h	(revision 75313)
@@ -109,7 +109,7 @@
 public:
 
-    CaptureStream(void);
-
-    CaptureStream(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
+    CaptureStream(CaptureContext *pCtx);
+
+    CaptureStream(CaptureContext *pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
 
     virtual ~CaptureStream(void);
@@ -117,5 +117,5 @@
 public:
 
-    int Init(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
+    int Init(CaptureContext *pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
     int Uninit(void);
 
@@ -133,5 +133,5 @@
     int close(void);
 
-    int initInternal(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
+    int initInternal(CaptureContext *pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
     int uninitInternal(void);
 
@@ -153,6 +153,21 @@
 protected:
 
+    /**
+     * Enumeration for a recording stream state.
+     */
+    enum RECORDINGSTREAMSTATE
+    {
+        /** Stream not initialized. */
+        RECORDINGSTREAMSTATE_UNINITIALIZED = 0,
+        /** Stream was initialized. */
+        RECORDINGSTREAMSTATE_INITIALIZED   = 1,
+        /** The usual 32-bit hack. */
+        RECORDINGSTREAMSTATE_32BIT_HACK    = 0x7fffffff
+    };
+
     /** Recording context this stream is associated to. */
-    CaptureContext             *pCtx;
+    CaptureContext         *pCtx;
+    /** The current state. */
+    RECORDINGSTREAMSTATE    enmState;
     struct
     {
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 75312)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 75313)
@@ -5629,7 +5629,4 @@
                 vrc = i_videoRecCreate();
                 if (RT_SUCCESS(vrc))
-                    vrc = i_videoRecStart();
-
-                if (RT_SUCCESS(vrc))
                 {
 # ifdef VBOX_WITH_AUDIO_VIDEOREC
@@ -6899,14 +6896,19 @@
     Assert(mMachine.isNotNull());
 
+    Settings.applyDefaults();
+
     ComPtr<ICaptureSettings> pCaptureSettings;
     HRESULT hrc = mMachine->COMGETTER(CaptureSettings)(pCaptureSettings.asOutParam());
     AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
 
+    BOOL fTemp;
+    hrc = pCaptureSettings->COMGETTER(Enabled)(&fTemp);
+    AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
+    Settings.fEnabled = RT_BOOL(fTemp);
+
     SafeIfaceArray<ICaptureScreenSettings> paCaptureScreens;
     hrc = pCaptureSettings->COMGETTER(Screens)(ComSafeArrayAsOutParam(paCaptureScreens));
     AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
 
-    Settings.applyDefaults();
-
     for (unsigned long i = 0; i < (unsigned long)paCaptureScreens.size(); ++i)
     {
@@ -6914,4 +6916,7 @@
         ComPtr<ICaptureScreenSettings> pCaptureScreenSettings = paCaptureScreens[i];
 
+        hrc = pCaptureScreenSettings->COMGETTER(Enabled)(&fTemp);
+        AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
+        CaptureScreenSettings.fEnabled = RT_BOOL(fTemp);
         hrc = pCaptureScreenSettings->COMGETTER(MaxTime)((ULONG *)&CaptureScreenSettings.ulMaxTimeS);
         AssertComRCReturn(hrc, VERR_INVALID_PARAMETER);
@@ -7006,8 +7011,10 @@
     LogRel(("VideoRec: Starting ...\n"));
 
-    int rc = VINF_SUCCESS;
-
-    for (unsigned uScreen = 0; uScreen < Capture.mpVideoRecCtx->GetStreamCount(); uScreen++)
-        mDisplay->i_videoRecScreenChanged(uScreen);
+    int rc = Capture.mpVideoRecCtx->Start();
+    if (RT_SUCCESS(rc))
+    {
+        for (unsigned uScreen = 0; uScreen < Capture.mpVideoRecCtx->GetStreamCount(); uScreen++)
+            mDisplay->i_videoRecScreenChanged(uScreen);
+    }
 
     if (RT_FAILURE(rc))
@@ -7029,18 +7036,24 @@
     LogRel(("VideoRec: Stopping ...\n"));
 
-    const size_t cStreams = Capture.mpVideoRecCtx->GetStreamCount();
-    for (unsigned uScreen = 0; uScreen < cStreams; ++uScreen)
-        mDisplay->i_videoRecScreenChanged(uScreen);
-
-    ComPtr<ICaptureSettings> pCaptureSettings;
-    HRESULT hrc = mMachine->COMGETTER(CaptureSettings)(pCaptureSettings.asOutParam());
-    ComAssertComRC(hrc);
-    hrc = pCaptureSettings->COMSETTER(Enabled)(false);
-    ComAssertComRC(hrc);
-
-    LogRel(("VideoRec: Stopped\n"));
-
-    LogFlowFuncLeaveRC(VINF_SUCCESS);
-    return VINF_SUCCESS;
+    int rc = Capture.mpVideoRecCtx->Stop();
+    if (RT_SUCCESS(rc))
+    {
+        const size_t cStreams = Capture.mpVideoRecCtx->GetStreamCount();
+        for (unsigned uScreen = 0; uScreen < cStreams; ++uScreen)
+            mDisplay->i_videoRecScreenChanged(uScreen);
+
+        ComPtr<ICaptureSettings> pCaptureSettings;
+        HRESULT hrc = mMachine->COMGETTER(CaptureSettings)(pCaptureSettings.asOutParam());
+        ComAssertComRC(hrc);
+        hrc = pCaptureSettings->COMSETTER(Enabled)(false);
+        ComAssertComRC(hrc);
+
+        LogRel(("VideoRec: Stopped\n"));
+    }
+    else
+        LogRel(("VideoRec: Failed to stop video recording (%Rrc)\n", rc));
+
+    LogFlowFuncLeaveRC(rc);
+    return rc;
 }
 #endif /* VBOX_WITH_VIDEOREC */
Index: /trunk/src/VBox/Main/src-client/VideoRec.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/VideoRec.cpp	(revision 75312)
+++ /trunk/src/VBox/Main/src-client/VideoRec.cpp	(revision 75313)
@@ -56,20 +56,4 @@
 //# define VBOX_VIDEOREC_DUMP
 #endif
-
-/**
- * Enumeration for a recording state.
- */
-enum VIDEORECSTS
-{
-    /** Not initialized. */
-    VIDEORECSTS_UNINITIALIZED = 0,
-    /** Created. */
-    VIDEORECSTS_CREATED       = 1,
-    /** Started. */
-    VIDEORECSTS_STARTED       = 2,
-    /** The usual 32-bit hack. */
-    VIDEORECSTS_32BIT_HACK    = 0x7fffffff
-};
-
 
 #ifdef VBOX_VIDEOREC_DUMP
@@ -205,5 +189,5 @@
         try
         {
-            pStream = new CaptureStream(itScreen->first /* Screen ID */, itScreen->second);
+            pStream = new CaptureStream(this, itScreen->first /* Screen ID */, itScreen->second);
             this->vecStreams.push_back(pStream);
         }
@@ -213,4 +197,6 @@
             break;
         }
+
+        ++itScreen;
     }
 
@@ -219,5 +205,4 @@
         this->tsStartMs = RTTimeMilliTS();
         this->enmState  = VIDEORECSTS_CREATED;
-        this->fStarted  = false;
         this->fShutdown = false;
 
@@ -246,5 +231,5 @@
 
     int rc = RTThreadCreate(&this->Thread, CaptureContext::threadMain, (void *)this, 0,
-                            RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "VideoRec");
+                            RTTHREADTYPE_MAIN_WORKER, RTTHREADFLAGS_WAITABLE, "Record");
 
     if (RT_SUCCESS(rc)) /* Wait for the thread to start. */
@@ -254,5 +239,4 @@
     {
         this->enmState = VIDEORECSTS_STARTED;
-        this->fStarted = true;
     }
 
@@ -265,5 +249,5 @@
         return VINF_SUCCESS;
 
-    LogFunc(("Shutting down thread ...\n"));
+    LogThisFunc(("Shutting down thread ...\n"));
 
     /* Set shutdown indicator. */
@@ -275,4 +259,10 @@
         rc = RTThreadWait(this->Thread, 30 * 1000 /* 10s timeout */, NULL);
 
+    if (RT_SUCCESS(rc))
+    {
+        this->enmState = VIDEORECSTS_CREATED;
+    }
+
+    LogFlowThisFunc(("%Rrc\n", rc));
     return rc;
 }
@@ -283,26 +273,12 @@
 int CaptureContext::destroyInternal(void)
 {
-    int rc = VINF_SUCCESS;
-
-    if (this->enmState == VIDEORECSTS_STARTED)
-    {
-        rc = stopInternal();
-        if (RT_SUCCESS(rc))
-        {
-            /* Disable the context. */
-            ASMAtomicWriteBool(&this->fStarted, false);
-
-            int rc2 = RTSemEventDestroy(this->WaitEvent);
-            AssertRC(rc2);
-
-            this->WaitEvent = NIL_RTSEMEVENT;
-        }
-    }
-
+    int rc = stopInternal();
     if (RT_FAILURE(rc))
-    {
-        AssertRC(rc);
         return rc;
-    }
+
+    rc = RTSemEventDestroy(this->WaitEvent);
+    AssertRC(rc);
+
+    this->WaitEvent = NIL_RTSEMEVENT;
 
     rc = RTCritSectEnter(&this->CritSect);
@@ -338,4 +314,5 @@
     }
 
+    LogFlowThisFunc(("%Rrc\n", rc));
     return rc;
 }
@@ -411,13 +388,18 @@
 }
 
+/**
+ * Returns if this recording context is ready to start recording.
+ *
+ * @returns @c true if recording context is ready, @c false if not.
+ */
 bool CaptureContext::IsReady(void) const
 {
-    return this->fStarted;
-}
-
-/**
- * Checks if recording engine is ready to accept new recording data for a given screen.
- *
- * @returns true if recording engine is ready, false if not.
+    return (this->enmState >= VIDEORECSTS_CREATED);
+}
+
+/**
+ * Returns if this recording context is ready to accept new recording data for a given screen.
+ *
+ * @returns @c true if the specified screen is ready, @c false if not.
  * @param   uScreen             Screen ID.
  * @param   uTimeStampMs        Current time stamp (in ms). Currently not being used.
@@ -450,5 +432,5 @@
 bool CaptureContext::IsStarted(void) const
 {
-    return this->fStarted;
+    return (this->enmState == VIDEORECSTS_STARTED);
 }
 
Index: /trunk/src/VBox/Main/src-client/VideoRecStream.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/VideoRecStream.cpp	(revision 75312)
+++ /trunk/src/VBox/Main/src-client/VideoRecStream.cpp	(revision 75313)
@@ -42,6 +42,8 @@
 
 
-CaptureStream::CaptureStream(void)
-    : tsStartMs(0)
+CaptureStream::CaptureStream(CaptureContext *a_pCtx)
+    : pCtx(a_pCtx)
+    , enmState(RECORDINGSTREAMSTATE_UNINITIALIZED)
+    , tsStartMs(0)
 {
     File.pWEBM = NULL;
@@ -49,11 +51,12 @@
 }
 
-CaptureStream::CaptureStream(uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
-    : tsStartMs(0)
+CaptureStream::CaptureStream(CaptureContext *a_pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
+    : enmState(RECORDINGSTREAMSTATE_UNINITIALIZED)
+    , tsStartMs(0)
 {
     File.pWEBM = NULL;
     File.hFile = NIL_RTFILE;
 
-    int rc2 = initInternal(uScreen, Settings);
+    int rc2 = initInternal(a_pCtx, uScreen, Settings);
     if (RT_FAILURE(rc2))
         throw rc2;
@@ -645,22 +648,31 @@
         VideoRecVideoFrameFree(pFrame);
 
-    lock();
+    unlock();
 
     return rc;
 }
 
-int CaptureStream::Init(uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
-{
-    return initInternal(uScreen, Settings);
-}
-
 /**
  * Initializes a recording stream.
  *
  * @returns IPRT status code.
+ * @param   a_pCtx              Pointer to recording context.
  * @param   uScreen             Screen number to use for this recording stream.
  * @param   Settings            Capturing configuration to use for initialization.
  */
-int CaptureStream::initInternal(uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
+int CaptureStream::Init(CaptureContext *a_pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
+{
+    return initInternal(a_pCtx, uScreen, Settings);
+}
+
+/**
+ * Initializes a recording stream, internal version.
+ *
+ * @returns IPRT status code.
+ * @param   a_pCtx              Pointer to recording context.
+ * @param   uScreen             Screen number to use for this recording stream.
+ * @param   Settings            Capturing configuration to use for initialization.
+ */
+int CaptureStream::initInternal(CaptureContext *a_pCtx, uint32_t uScreen, const settings::CaptureScreenSettings &Settings)
 {
     int rc = parseOptionsString(Settings.strOptions);
@@ -770,4 +782,6 @@
     if (RT_SUCCESS(rc))
     {
+        this->pCtx           = a_pCtx;
+        this->enmState       = RECORDINGSTREAMSTATE_INITIALIZED;
         this->fEnabled       = true;
         this->uScreenID      = uScreen;
@@ -870,4 +884,7 @@
 int CaptureStream::uninitInternal(void)
 {
+    if (this->enmState != RECORDINGSTREAMSTATE_INITIALIZED)
+        return VINF_SUCCESS;
+
     int rc = close();
     if (RT_FAILURE(rc))
@@ -883,4 +900,5 @@
     RTCritSectDelete(&this->CritSect);
 
+    this->enmState = RECORDINGSTREAMSTATE_UNINITIALIZED;
     this->fEnabled = false;
 
@@ -911,5 +929,8 @@
 int CaptureStream::uninitVideoVPX(void)
 {
-    vpx_img_free(&this->Video.Codec.VPX.RawImage);
+    PVIDEORECVIDEOCODEC pCodec = &this->Video.Codec;
+    vpx_img_free(&pCodec->VPX.RawImage);
+    pCodec->VPX.pu8YuvBuf = NULL; /* Was pointing to VPX.RawImage. */
+
     vpx_codec_err_t rcv = vpx_codec_destroy(&this->Video.Codec.VPX.Ctx);
     Assert(rcv == VPX_CODEC_OK); RT_NOREF(rcv);
Index: /trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp	(revision 75312)
+++ /trunk/src/VBox/Main/src-server/CaptureScreenSettingsImpl.cpp	(revision 75313)
@@ -292,8 +292,8 @@
 HRESULT CaptureScreenSettings::setFeatures(ULONG aFeatures)
 {
-    if (!i_canChangeSettings())
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change features while capturing is enabled"));
-
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     m->bd.backup();
@@ -325,9 +325,9 @@
 HRESULT CaptureScreenSettings::setDestination(CaptureDestination_T aDestination)
 {
-    if (!i_canChangeSettings())
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change destination type while capturing is enabled"));
 
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
     m->bd.backup();
     m->bd->enmDest = aDestination;
@@ -353,8 +353,8 @@
 HRESULT CaptureScreenSettings::setFileName(const com::Utf8Str &aFileName)
 {
-    if (!i_canChangeSettings())
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change file name while capturing is enabled"));
-
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
     Utf8Str strFile(aFileName);
@@ -388,5 +388,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change maximum time while capturing is enabled"));
 
@@ -414,5 +414,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change maximum file size while capturing is enabled"));
 
@@ -440,13 +440,13 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
-        return setError(E_INVALIDARG, tr("Cannot change options string while capturing is enabled"));
+    if (m->bd->fEnabled)
+        return setError(E_INVALIDARG, tr("Cannot change options while capturing is enabled"));
 
     m->bd.backup();
     m->bd->strOptions = aOptions;
 
-    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
-    m->pMachine->i_setModified(Machine::IsModified_Capture);
-    mlock.release();
+    alock.release();
+    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
+    m->pMachine->i_setModified(Machine::IsModified_Capture);
 
     return S_OK;
@@ -466,5 +466,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change audio codec while capturing is enabled"));
 
@@ -492,5 +492,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change audio Hertz rate while capturing is enabled"));
 
@@ -518,5 +518,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change audio bits while capturing is enabled"));
 
@@ -544,5 +544,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change audio channels while capturing is enabled"));
 
@@ -570,5 +570,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video codec while capturing is enabled"));
 
@@ -596,5 +596,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video width while capturing is enabled"));
 
@@ -622,5 +622,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video height while capturing is enabled"));
 
@@ -648,5 +648,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video rate while capturing is enabled"));
 
@@ -674,5 +674,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video rate control mode while capturing is enabled"));
 
@@ -696,5 +696,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video FPS while capturing is enabled"));
 
@@ -722,5 +722,5 @@
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    if (!i_canChangeSettings())
+    if (m->bd->fEnabled)
         return setError(E_INVALIDARG, tr("Cannot change video rate scaling method while capturing is enabled"));
 
@@ -729,16 +729,4 @@
 
     return E_NOTIMPL;
-}
-
-bool CaptureScreenSettings::i_canChangeSettings(void)
-{
-    AutoAnyStateDependency adep(m->pMachine);
-    AssertComRCReturn(adep.rc(), false);
-
-    if (   Global::IsOnline(adep.machineState())
-        && m->bd->fEnabled)
-        return false;
-
-    return true;
 }
 
Index: /trunk/src/VBox/Main/xml/Settings.cpp
===================================================================
--- /trunk/src/VBox/Main/xml/Settings.cpp	(revision 75312)
+++ /trunk/src/VBox/Main/xml/Settings.cpp	(revision 75313)
@@ -2483,4 +2483,5 @@
         /* Always add screen 0 to the default configuration. */
         CaptureScreenSettings screenSettings; /* Apply default settings for screen 0. */
+        screenSettings.fEnabled = true;       /* Enabled by default. */
         mapScreens[0] = screenSettings;
     }
