? truepause.diff
Index: platform/symbian/audiosvr/mmf/audio_session-mmf.cpp
===================================================================
RCS file: /cvsroot/audio/device/platform/symbian/audiosvr/mmf/audio_session-mmf.cpp,v
retrieving revision 1.14.2.3
diff -u -w -b -r1.14.2.3 audio_session-mmf.cpp
--- platform/symbian/audiosvr/mmf/audio_session-mmf.cpp	7 Apr 2006 19:20:13 -0000	1.14.2.3
+++ platform/symbian/audiosvr/mmf/audio_session-mmf.cpp	21 Aug 2006 18:25:42 -0000
@@ -229,7 +229,8 @@
     m_resetTriggerSampleCount(0),
     m_resetTriggerUnplayedCount(0),
     m_ulTimePlayedInSec(0),
-    m_ulBalanceSamples(0)
+    m_ulBalanceSamples(0),
+    m_cbPastBufferList(0)
 #else
     m_TotalSamplesWritten(0)
 #endif
@@ -815,10 +816,54 @@
     if (m_deviceResetsOnPause)
     {
         PrepareForDeviceReset();
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+        RetrieveUnplayedSamplesFromPastQueue();
+        m_resetTriggerUnplayedCount = m_unplayedSampleCount;
+#endif
     }
 
 }
 
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+void HXSymbianAudioSession::RetrieveUnplayedSamplesFromPastQueue()
+{
+
+    HX_ASSERT(m_cbPastBufferList + m_cbFrontBufferWritten >= m_unplayedSampleCount*m_cbSample );
+
+    while( m_unplayedSampleCount*m_cbSample > m_cbFrontBufferWritten )
+    {
+        m_unplayedSampleCount -= m_cbFrontBufferWritten/m_cbSample;
+        //m_samplesWritten has reset to 0 in PrepareForDeviceReset(), so do not set following
+        //m_samplesWritten -= m_cbFrontBufferWritten/m_cbSample; 
+        m_cbFrontBufferWritten = 0;
+
+        IHXBuffer* pBuf = (IHXBuffer*)m_pastBufferList.RemoveTail();
+        if( pBuf )
+        {
+            m_cbFrontBufferWritten =  pBuf->GetSize();
+            m_cbPastBufferList -= m_cbFrontBufferWritten;
+            m_bufferList.AddHead( pBuf );
+            m_cbBufferList += m_cbFrontBufferWritten;
+        }
+        else
+        {
+            //it might be an overkill, it should not reach here.
+            //however, in case it happens, it is handled.
+            break;
+        }
+    }
+
+    if( m_cbFrontBufferWritten )
+    {
+        HX_ASSERT( m_unplayedSampleCount*m_cbSample <= m_cbFrontBufferWritten );
+        m_cbFrontBufferWritten -= m_unplayedSampleCount*m_cbSample;
+        //m_samplesWritten has reset to 0 in PrepareForDeviceReset(), so do not set following
+        //m_samplesWritten -= m_unplayedSampleCount;
+        m_unplayedSampleCount = 0;
+    }
+}
+#endif
+
 void HXSymbianAudioSession::InitStoppedState()
 {
     PrepareForDeviceReset();
@@ -845,6 +890,10 @@
     }
     m_cbBufferList = 0;
     m_cbFrontBufferWritten = 0;
+
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+    ClearPastQueue();
+#endif
 }
 
 
@@ -1008,8 +1057,19 @@
             // we used up the front buffer; toss it
             IHXBuffer* pTmp = (IHXBuffer*)m_bufferList.RemoveHead();
             m_cbBufferList -= pTmp->GetSize();
-            HX_RELEASE(pTmp);
             m_cbFrontBufferWritten = 0;
+
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+            if( m_deviceResetsOnPause )
+            {
+                m_pastBufferList.AddTail( pTmp );
+                m_cbPastBufferList += pTmp->GetSize();
+            }
+            else
+#endif
+            {
+                HX_RELEASE(pTmp);
+            }
         }
     }
 
@@ -1037,6 +1097,40 @@
 
 }
 
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+void HXSymbianAudioSession::RemoveOutdatedPacketsInPastQueue()
+{
+    IHXBuffer* pBuf( NULL );
+    ULONG32    bufSize( 0 );
+
+    while( !m_pastBufferList.IsEmpty() )
+    {
+        pBuf    = (IHXBuffer*)m_pastBufferList.GetHead();
+        bufSize =  pBuf->GetSize();
+        
+        if( m_unplayedSampleCount*m_cbSample <= m_cbPastBufferList + m_cbFrontBufferWritten - bufSize )
+        {
+            pBuf = (IHXBuffer*)m_pastBufferList.RemoveHead();
+            HX_RELEASE(pBuf);
+            m_cbPastBufferList -= bufSize;
+        }
+        else
+        {
+            break;
+        }
+    }
+}
+
+void HXSymbianAudioSession::ClearPastQueue()
+{
+    while (!m_pastBufferList.IsEmpty())
+    {
+        IHXBuffer* pBuf = (IHXBuffer*)m_pastBufferList.RemoveHead();
+        HX_RELEASE(pBuf);
+    }
+    m_cbPastBufferList = 0;
+}
+#endif
 
 
 // MDevSoundObserver
@@ -1112,6 +1206,7 @@
         m_lastSampleCount           = 0;
         m_unplayedSampleCount       = 0;
         
+        ClearPastQueue();        
     }
 
     m_sampleCountResetPending = TRUE;
@@ -1247,6 +1342,10 @@
         m_unplayedSampleCount = m_samplesWritten - m_lastSampleCount;
     }
 
+#ifdef HELIX_CONFIG_SYMBIAN_SAMPLESPLAYED
+    RemoveOutdatedPacketsInPastQueue();
+#endif
+
     HXLOGL4(HXLOG_ADEV, "HXSymbianAudioSession::UpdateUnplayedSampleCount(): unplayed samps = %lu (%lu ms)", m_unplayedSampleCount, SamplesToMS(m_unplayedSampleCount, m_sampleRate));
 }
 
Index: platform/symbian/audiosvr/mmf/audio_session-mmf.h
===================================================================
RCS file: /cvsroot/audio/device/platform/symbian/audiosvr/mmf/audio_session-mmf.h,v
retrieving revision 1.9.2.3
diff -u -w -b -r1.9.2.3 audio_session-mmf.h
--- platform/symbian/audiosvr/mmf/audio_session-mmf.h	7 Apr 2006 19:19:57 -0000	1.9.2.3
+++ platform/symbian/audiosvr/mmf/audio_session-mmf.h	21 Aug 2006 18:25:42 -0000
@@ -136,6 +136,11 @@
     void UpdateSamplesPlayedTime(TUint ulSamples);
     TUint GetSamplesPlayedTimeInMS(); 
     void ResetSamplesPlayedTime();
+
+    void RetrieveUnplayedSamplesFromPastQueue();
+    void RemoveOutdatedPacketsInPastQueue();
+    void ClearPastQueue();
+
 #endif
     
     // helpers
@@ -195,13 +200,15 @@
     // Holds the remaining buffers that was not 
     // accounted for previous sample time calculation.
     TUint              m_ulBalanceSamples;
+
+    CHXSimpleList      m_pastBufferList;
+    TUint              m_cbPastBufferList;
 #else    
     // Holds the total samples written to DevSound.
     // This value will be reset only on player stop
     TUint              m_TotalSamplesWritten;
-#endif
-
     
+#endif
     
 };
 
