Index: /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp	(revision 68354)
+++ /trunk/src/VBox/Devices/Audio/DrvHostPulseAudio.cpp	(revision 68355)
@@ -66,4 +66,5 @@
     ( (PDRVHOSTPULSEAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPULSEAUDIO, IHostAudio)) )
 
+#define PULSEAUDIO_ASYNC
 
 /*********************************************************************************************************************************
@@ -124,6 +125,10 @@
     /** Current latency (in us). */
     uint64_t               curLatencyUs;
+#ifdef LOG_ENABLED
     /** Start time stamp (in us) of stream playback / recording. */
     pa_usec_t              tsStartUs;
+    /** Time stamp (in us) when last read from / written to the stream. */
+    pa_usec_t              tsLastReadWrittenUs;
+#endif
 } PULSEAUDIOSTREAM, *PPULSEAUDIOSTREAM;
 
@@ -590,6 +595,7 @@
         }
 
+#ifdef LOG_ENABLED
         pStreamPA->tsStartUs = pa_rtclock_now();
-
+#endif
         if (RT_FAILURE(rc))
             break;
@@ -745,14 +751,14 @@
     pStreamPA->SampleSpec.channels = pCfgReq->Props.cChannels;
 
-    pStreamPA->curLatencyUs        = 100 * 1000; /** 100ms latency by default. @todo Make this configurable. */
-
-    LogRel2(("PulseAudio: Initial output latency is %RU64ms\n", pStreamPA->curLatencyUs / 1000 /* ms */));
-
-    const uint32_t mixsize = pa_usec_to_bytes(pStreamPA->curLatencyUs, &pStreamPA->SampleSpec);
-
-    pStreamPA->BufAttr.maxlength   = mixsize * 4;
-    pStreamPA->BufAttr.tlength     = mixsize;
-    pStreamPA->BufAttr.prebuf      = mixsize * 2;
-    pStreamPA->BufAttr.minreq      = mixsize;
+    pStreamPA->curLatencyUs        = 100 * 1000; /** 10ms latency by default. @todo Make this configurable. */
+
+    const uint32_t cbLatency = pa_usec_to_bytes(pStreamPA->curLatencyUs, &pStreamPA->SampleSpec);
+
+    LogRel2(("PulseAudio: Initial output latency is %RU64ms (%RU32 bytes)\n", pStreamPA->curLatencyUs / 1000 /* ms */, cbLatency));
+
+    pStreamPA->BufAttr.tlength     = cbLatency;
+    pStreamPA->BufAttr.maxlength   = (pStreamPA->BufAttr.tlength * 3) / 2;
+    pStreamPA->BufAttr.prebuf      = cbLatency;
+    pStreamPA->BufAttr.minreq      = (uint32_t)-1;                 /* PulseAudio should set something sensible for minreq on it's own. */
 
     LogFunc(("BufAttr tlength=%RU32, maxLength=%RU32, minReq=%RU32\n",
@@ -951,5 +957,4 @@
                                                      uint32_t *pcxWritten)
 {
-    RT_NOREF(pvBuf, cxBuf);
     AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
     AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
@@ -967,4 +972,13 @@
     pa_threaded_mainloop_lock(pThis->pMainLoop);
 
+#ifdef LOG_ENABLED
+    const pa_usec_t tsNowUs         = pa_rtclock_now();
+    const pa_usec_t tsDeltaPlayedUs = tsNowUs - pPAStream->tsLastReadWrittenUs;
+
+    Log3Func(("tsDeltaPlayedMs=%RU64\n", tsDeltaPlayedUs / 1000 /* ms */));
+
+    pPAStream->tsLastReadWrittenUs  = tsNowUs;
+#endif
+
     do
     {
@@ -977,12 +991,11 @@
 
         size_t cbLeft = RT_MIN(cbWriteable, cxBuf);
+        Assert(cbLeft); /* At this point we better have *something* to write. */
 
         while (cbLeft)
         {
-            size_t cbToWrite = RT_MIN(cbLeft, pa_stream_writable_size(pPAStream->pStream));
-            if (cbToWrite <= (size_t)0)
-                break;
-
-            if (pa_stream_write(pPAStream->pStream, (uint8_t *)pvBuf + cbWrittenTotal, cbToWrite, NULL /* Cleanup callback */,
+            uint32_t cbChunk = cbLeft; /* Write all at once for now. */
+
+            if (pa_stream_write(pPAStream->pStream, (uint8_t *)pvBuf + cbWrittenTotal, cbChunk, NULL /* Cleanup callback */,
                                 0, PA_SEEK_RELATIVE) < 0)
             {
@@ -991,7 +1004,7 @@
             }
 
-            Assert(cbLeft  >= cbToWrite);
-            cbLeft         -= cbToWrite;
-            cbWrittenTotal += cbToWrite;
+            Assert(cbLeft  >= cbChunk);
+            cbLeft         -= cbChunk;
+            cbWrittenTotal += cbChunk;
         }
 
@@ -1285,5 +1298,6 @@
             else
             {
-                rc = paWaitFor(pThis, pa_stream_cork(pStreamPA->pStream, 0, paStreamCbSuccess, pStreamPA));
+                /* Uncork (resume) stream. */
+                rc = paWaitFor(pThis, pa_stream_cork(pStreamPA->pStream, 0 /* Uncork */, paStreamCbSuccess, pStreamPA));
             }
 
