Index: /trunk/include/VBox/HostServices/VBoxCrOpenGLSvc.h
===================================================================
--- /trunk/include/VBox/HostServices/VBoxCrOpenGLSvc.h	(revision 50313)
+++ /trunk/include/VBox/HostServices/VBoxCrOpenGLSvc.h	(revision 50314)
@@ -386,4 +386,7 @@
                 uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
 
+typedef DECLCALLBACKPTR(bool, PFNCRSCREENSHOTBEGIN)(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
+typedef DECLCALLBACKPTR(void, PFNCRSCREENSHOTEND)(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
+
 #define CRSCREEN_ALL (0xffffffff)
 
@@ -393,5 +396,7 @@
     uint32_t u32Screen;
     void *pvContext;
-    PFNCRSCREENSHOTREPORT pfnScreenshot;
+    PFNCRSCREENSHOTBEGIN pfnScreenshotBegin;
+    PFNCRSCREENSHOTREPORT pfnScreenshotPerform;
+    PFNCRSCREENSHOTEND pfnScreenshotEnd;
 } CRVBOXHGCMTAKESCREENSHOT;
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp	(revision 50313)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserver/crservice.cpp	(revision 50314)
@@ -933,4 +933,29 @@
 }
 
+static void crScreenshotHandle(CRVBOXHGCMTAKESCREENSHOT *pScreenshot, uint32_t idScreen, uint64_t u64Now)
+{
+    if (!pScreenshot->pfnScreenshotBegin || pScreenshot->pfnScreenshotBegin(pScreenshot->pvContext, idScreen, u64Now))
+    {
+        CR_SCREENSHOT Screenshot;
+
+        int rc = crServerVBoxScreenshotGet(idScreen, &Screenshot);
+        if (RT_SUCCESS(rc))
+        {
+            pScreenshot->pfnScreenshotPerform(pScreenshot->pvContext, idScreen,
+                    0, 0, 32,
+                    Screenshot.Img.pitch, Screenshot.Img.width, Screenshot.Img.height,
+                    (uint8_t*)Screenshot.Img.pvData, u64Now);
+            crServerVBoxScreenshotRelease(&Screenshot);
+        }
+        else
+        {
+            Assert(rc == VERR_INVALID_STATE);
+        }
+
+        if (pScreenshot->pfnScreenshotEnd)
+            pScreenshot->pfnScreenshotEnd(pScreenshot->pvContext, idScreen, u64Now);
+    }
+}
+
 /*
  * We differentiate between a function handler for the guest and one for the host.
@@ -1225,38 +1250,10 @@
                 for (uint32_t i = 0; i < g_u32ScreenCount; ++i)
                 {
-                    CR_SCREENSHOT Screenshot;
-
-                    int rc = crServerVBoxScreenshotGet(i, &Screenshot);
-                    if (RT_SUCCESS(rc))
-                    {
-                        pScreenshot->pfnScreenshot(pScreenshot->pvContext, i,
-                                0, 0, 32,
-                                Screenshot.Img.pitch, Screenshot.Img.width, Screenshot.Img.height,
-                                (uint8_t*)Screenshot.Img.pvData, u64Now);
-                        crServerVBoxScreenshotRelease(&Screenshot);
-                    }
-                    else
-                    {
-                        Assert(rc == VERR_INVALID_STATE);
-                    }
+                    crScreenshotHandle(pScreenshot, i, u64Now);
                 }
             }
             else if (pScreenshot->u32Screen < g_u32ScreenCount)
             {
-                CR_SCREENSHOT Screenshot;
-
-                int rc = crServerVBoxScreenshotGet(pScreenshot->u32Screen, &Screenshot);
-                if (RT_SUCCESS(rc))
-                {
-                    pScreenshot->pfnScreenshot(pScreenshot->pvContext, pScreenshot->u32Screen,
-                            0, 0, 32,
-                            Screenshot.Img.pitch, Screenshot.Img.width, Screenshot.Img.height,
-                            (uint8_t*)Screenshot.Img.pvData, u64Now);
-                    crServerVBoxScreenshotRelease(&Screenshot);
-                }
-                else
-                {
-                    Assert(rc == VERR_INVALID_STATE);
-                }
+                crScreenshotHandle(pScreenshot, pScreenshot->u32Screen, u64Now);
             }
             else
Index: /trunk/src/VBox/Main/include/DisplayImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/DisplayImpl.h	(revision 50313)
+++ /trunk/src/VBox/Main/include/DisplayImpl.h	(revision 50314)
@@ -178,8 +178,10 @@
 #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
     void  handleCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam);
-    void  handleCrVRecScreenshot(uint32_t uScreen,
+    void  handleCrVRecScreenshotPerform(uint32_t uScreen,
                     uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBitsPerPixel,
                     uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
                     uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
+    bool handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64TimeStamp);
+    void handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64TimeStamp);
     void  handleVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
 #endif
@@ -283,8 +285,11 @@
 
 #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
-    static DECLCALLBACK(void) displayCrVRecScreenshot(void *pvCtx, uint32_t uScreen,
+    static DECLCALLBACK(void) displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
                     uint32_t x, uint32_t y, uint32_t uBitsPerPixel,
                     uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
                     uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
+    static DECLCALLBACK(bool) displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
+    static DECLCALLBACK(void) displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp);
+
     static DECLCALLBACK(void)  displayVRecCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
     static DECLCALLBACK(void)  displayCrAsyncCmdCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext);
Index: /trunk/src/VBox/Main/src-client/DisplayImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/DisplayImpl.cpp	(revision 50313)
+++ /trunk/src/VBox/Main/src-client/DisplayImpl.cpp	(revision 50314)
@@ -155,5 +155,7 @@
     mCrOglScreenshotData.u32Screen = CRSCREEN_ALL;
     mCrOglScreenshotData.pvContext = this;
-    mCrOglScreenshotData.pfnScreenshot = displayCrVRecScreenshot;
+    mCrOglScreenshotData.pfnScreenshotBegin = displayCrVRecScreenshotBegin;
+    mCrOglScreenshotData.pfnScreenshotPerform = displayCrVRecScreenshotPerform;
+    mCrOglScreenshotData.pfnScreenshotEnd = displayCrVRecScreenshotEnd;
 #endif
 
@@ -4205,6 +4207,14 @@
 }
 
-
-void  Display::handleCrVRecScreenshot(uint32_t uScreen,
+bool  Display::handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64TimeStamp)
+{
+    return VideoRecIsReady(mpVideoRecCtx, uScreen, u64TimeStamp);
+}
+
+void  Display::handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64TimeStamp)
+{
+}
+
+void  Display::handleCrVRecScreenshotPerform(uint32_t uScreen,
                 uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBitsPerPixel,
                 uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
@@ -4217,5 +4227,5 @@
                               uGuestWidth, uGuestHeight,
                               pu8BufferAddress, u64TimeStamp);
-    Assert(rc == VINF_SUCCESS || rc == VERR_TRY_AGAIN || rc == VINF_TRY_AGAIN);
+    Assert(rc == VINF_SUCCESS/* || rc == VERR_TRY_AGAIN || rc == VINF_TRY_AGAIN*/);
 }
 
@@ -4226,5 +4236,5 @@
 }
 
-DECLCALLBACK(void) Display::displayCrVRecScreenshot(void *pvCtx, uint32_t uScreen,
+DECLCALLBACK(void) Display::displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
                 uint32_t x, uint32_t y, uint32_t uBitsPerPixel,
                 uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
@@ -4232,8 +4242,20 @@
 {
     Display *pDisplay = (Display *)pvCtx;
-    pDisplay->handleCrVRecScreenshot(uScreen,
+    pDisplay->handleCrVRecScreenshotPerform(uScreen,
             x, y, FramebufferPixelFormat_FOURCC_RGB, uBitsPerPixel,
             uBytesPerLine, uGuestWidth, uGuestHeight,
             pu8BufferAddress, u64TimeStamp);
+}
+
+DECLCALLBACK(bool) Display::displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp)
+{
+    Display *pDisplay = (Display *)pvCtx;
+    return pDisplay->handleCrVRecScreenshotBegin(uScreen, u64TimeStamp);
+}
+
+DECLCALLBACK(void) Display::displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp)
+{
+    Display *pDisplay = (Display *)pvCtx;
+    pDisplay->handleCrVRecScreenshotEnd(uScreen, u64TimeStamp);
 }
 
Index: /trunk/src/VBox/Main/src-client/VideoRec.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/VideoRec.cpp	(revision 50313)
+++ /trunk/src/VBox/Main/src-client/VideoRec.cpp	(revision 50314)
@@ -603,4 +603,32 @@
 
 /**
+ * VideoRec utility function to check if recording engine is ready to accept a new frame
+ * for the given screen.
+ *
+ * @returns true if recording engine is ready
+ * @param   pCtx   Pointer to video recording context.
+ * @param   uScreen screen id.
+ * @param   u64TimeStamp current time stamp
+ */
+bool VideoRecIsReady(PVIDEORECCONTEXT pCtx, uint32_t uScreen, uint64_t u64TimeStamp)
+{
+    uint32_t enmState = ASMAtomicReadU32(&g_enmState);
+    if (enmState != VIDREC_IDLE)
+        return false;
+
+    PVIDEORECSTREAM pStrm = &pCtx->Strm[uScreen];
+    if (!pStrm->fEnabled)
+        return false;
+
+    if (u64TimeStamp < pStrm->u64LastTimeStamp + pStrm->uDelay)
+        return false;
+
+    if (ASMAtomicReadBool(&pStrm->fRgbFilled))
+        return false;
+
+    return true;
+}
+
+/**
  * VideoRec utility function to encode the source image and write the encoded
  * image to target file.
Index: /trunk/src/VBox/Main/src-client/VideoRec.h
===================================================================
--- /trunk/src/VBox/Main/src-client/VideoRec.h	(revision 50313)
+++ /trunk/src/VBox/Main/src-client/VideoRec.h	(revision 50314)
@@ -34,4 +34,5 @@
                           uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
                           uint8_t *pu8BufferAddress, uint64_t u64TimeStamp);
+bool VideoRecIsReady(PVIDEORECCONTEXT pCtx, uint32_t uScreen, uint64_t u64TimeStamp);
 
 #endif /* !____H_VIDEOREC */
