Checked into head/cay150. I also added some code to discard the pending buffer list as Rajesh suggests.

Liam

At 12:15 PM 4/4/2005, [EMAIL PROTECTED] wrote:
Hi Liam,
One more observation to the other problems we noticed is that the m_pPendingFillBuffer becomes invalid after a pause.


Consider a case where the Audio session server does not have buffers to supply to DevSound. So the call to BufferToBeFilled will just cache the buffer address in pending buffer value. Later when Play is issued, using the pending buffer resulted in crash. Resetting the pending buffer to NULL during a pause solves the crash.

Probably you might want to include this too.

NOTE: The status of the buffer cached during pause is not documented.

Regards,
Rajesh.


-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of ext Liam Murray Sent: Monday, April 04, 2005 1:46 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [Porting-symbian] CR: HXSymbianAudioSession



I sent a CR for this earlier but didn't check in because there were still
some issues I wanted to investigate. Since several people are looking at
the AMR issue I'd like to get this in because the logging, sample count and
assert fixes will aid their development. It doesn't fix all AMR audio
issues, notably the constant internal pause/rebuffer that leads to chunky
playback. (Other audio playback is about the same with/without these changes.)

These changes have two more additions to the original:

1) Update unplayed sample count (as reported by Rajesh in response to
original CR).

2) GetBlocksBuffered() was returning the blocks of data held in our pending
write buffer list, but was not accounting for any data the actual device
was buffering. It looks like we should be accounting for the bytes buffered
in the actual device. (See the unix audio device implementation of
NumberOfBlocksRemainingToPlay().) We now return the size of data in pending
write buffers, plus number of unplayed samples in actual device (the number
we wrote to the device minus the amount played as reported by the device).
Note that we don't always write in complete blocks, so we round.

Liam

Summary
========

1) Fix for handling valid calls in PLAYINIT_PENDING state in
HXSymbianAudioSession. 2) Fix for double-reset observed with AMR audio in
underflow condition.

Thanks to Rajesh for help on this one too.

Overview
========

HXSymbianAudioSession keeps private state in a member var to guard against
bad use of the underlying CMMFDevSound. One state PLAYINIT_PENDING simply
means PlayInit has been called but BufferToBeCopied has not. Once we get
BufferToBeCopied we go to PLAYING. (Originally this was added because we
thought this might indicate that the sample count returned from
SamplesPlayed() thereafter might be reset. Alas, that was not the case.
However, it may still be useful so I didn't do away with the state.)

In some cases we were not handling calls to pause, stop, and write that are
valid after PlayInit is called. The fix here is to handle these calls the
same way we do when we are in PLAYING state.

The other fix is to deal with observed behavior described in comments in
the code in HXSymbianAudioSession::UpdateTimeSampleStats() (number 3). In
certain cases we would get an underflow, the value returned from
SamplesPlayed would go back to 0 and increase, then it would go back to 0
again. The second time would cause us to think we were seeing a wrap-around
of the sample count.  It appears values reported after the first reset but
before the second reset are for samples that we wrote but were unplayed at
the time of the underflow (at which time we call PlayInit).

My fix is to ignore values that returned from SamplesPlayed() that are less
than the last value returned, unless we have seen and underflow and are
expecting a sample count reset.

At the time we get the underflow we call SamplesPlayed() and see if there
are unplayed samples (written - played). We add these samples at that time
(because we don't know for sure that we will otherwise detect them playing
out before the sample count resets). So we may jump ahead a bit in the time
line. We may then jump ahead and re-add those samples if we happen to see
SamplesPlayed() returning values for unplayed samples at the time of the
underflow. Then when the sample count resets again we ignore values until
they catch up to the last we saw. At that point on continueing forward we
should be reporting accurate time.

Note that in most cases where we get an underflow and SamplesPlayed()
indicates some samples we wrote haven't played out, we see subsequent
SamplesPlayed() values that monotonically increase over the value at the
time of the underflow. Then we see one reset. That is what I usually see in
the emulator and on the 6630. I only have observed the double-reset with
amr audio so far.

The cost of this is that 1) we may report time ahead for a short prior, but
then we catch up; 2) we can't really detect wrap around of the sample count
(which is about 27 hours with 44Khz audio, so not a great sacrifice in
practice).

Note: this does not completely fix amr audio issues with Symbian on HEAD.
It still looks like we are not writing fast enough and in some cases
AddData stops being called. (Audio time returned from device looks ok to me
in these cases, that is, they monotonically increase in small steady
increments.)

Branch
======
HEAD, Cay150

Files modified
============
audio/device/platform/symbian/audiosvr/mmf/audio_session-mmf.cpp


NOTE: whitespace (extra \r) removed in my local copy after generating the diff

Builds tested/verified
==================
Wins, thumb




Liam

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.5
diff -u -w -r1.5 audio_session-mmf.cpp
--- platform/symbian/audiosvr/mmf/audio_session-mmf.cpp 1 Apr 2005 20:40:34
-0000   1.5
+++ platform/symbian/audiosvr/mmf/audio_session-mmf.cpp 4 Apr 2005 18:31:56
-0000
@@ -58,9 +58,9 @@
  #include "audio_session-mmf.h"
  #include "hxtick.h"
  #include "debug.h"
+#include "hxtlogutil.h"
  #include <e32std.h>

-#define D_SYMAUDIO D_INFO

  static const TInt KClientPriority = 69;
  #if defined(HELIX_CONFIG_CALYPSO_AUDIO_PREF)
@@ -77,7 +77,11 @@
      return (count * 1000) / rate;
  }

-#if defined(HELIX_FEATURE_DPRINTF)
+#if defined(HELIX_FEATURE_LOGLEVEL_3) || defined(HELIX_FEATURE_LOGLEVEL_ALL)
+#define HELIX_LOCAL_FEATURE_DEBUG_LOG
+#endif
+
+#if defined(HELIX_LOCAL_FEATURE_DEBUG_LOG)
  // stringify constants for easier interpretation of trace output
  #define MAKE_STATE_ENTRY(x) case HXSymbianAudioSession::x: return #x;
  static
@@ -154,7 +158,7 @@
  }

#else
-// do nothing (compile out) when !HELIX_FEATURE_DPRINTF
+// do nothing (compile out) when !HELIX_LOCAL_FEATURE_DEBUG_LOG
inline
const char * StringifyState(HXSymbianAudioSession::State state) { return 0; }
inline
@@ -220,6 +224,8 @@
m_pStream(NULL),
m_sampleRate(0),
m_cbSample(0),
+ m_cbBlock(0),
+ m_cbBufferList(0),
m_state(CLOSED),
m_pPendingFillBuffer(NULL),
m_cbFrontBufferWritten(0),
@@ -336,12 +342,12 @@
m_Settings.iChannels = channelCount;
m_Settings.iEncoding = EMMFSoundEncoding16BitPCM;


-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Init(): rate = %ld; chan
= %ld; sample frame = %lu bytes\n", m_sampleRate, m_Settings.iChannels,
m_cbSample));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Init(): rate = %ld; chan =
%ld; sample frame = %lu bytes", m_sampleRate, m_Settings.iChannels,
m_cbSample);

      switch (m_state)
      {
      case STOPPED:
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Init(): calling
SetConfgL() with settings\n"));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Init(): calling
SetConfgL() with settings");
          TRAP(err, (m_pStream->CMMFDevSound::SetConfigL(m_Settings)));
          Message().Complete(err);
          break;
@@ -351,7 +357,7 @@
          TRAP(err, (m_pStream = CMMFDevSound::NewL()));
          if(KErrNone == err)
          {
-            DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Init(): calling
InitializeL for newly allocated dev sound\n"));
+            HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Init(): calling
InitializeL for newly allocated dev sound");
              m_InitMessage = Message();
              TRAP(err, (m_pStream->InitializeL(*this, EMMFStatePlaying)));
          }
@@ -373,7 +379,7 @@
  //
  void HXSymbianAudioSession::Play()
  {
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Play(): state = %s\n",
StringifyState(m_state) ));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Play(): state = %s",
StringifyState(m_state));
      TInt err = KErrNone;

      switch (m_state)
@@ -386,8 +392,8 @@
          Trans(PLAYING);
          m_pStream->PlayData();
          break;
-    case PLAYING:
      case PLAYINIT_PENDING:
+    case PLAYING:
          // do nothing
          break;
      default:
@@ -405,11 +411,12 @@
  //
  void HXSymbianAudioSession::Pause()
  {
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Pause(): state = %s\n",
StringifyState(m_state)));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Pause(): state = %s",
StringifyState(m_state));
      TInt err = KErrNone;

      switch (m_state)
      {
+    case PLAYINIT_PENDING:
      case PLAYING:
          Trans(PAUSED);
          HX_ASSERT(m_pStream);
@@ -440,7 +447,7 @@
      switch (m_state)
      {
      case STOPPED:
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Write(): STOPPED;
last err = %s\n", StringifyKErr(m_lastPlayError)));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Write(): STOPPED; last
err = %s", StringifyKErr(m_lastPlayError));
          if (m_lastPlayError != KErrNone)
          {
              // we are stopped because of we got a call to PlayError
@@ -448,13 +455,25 @@
              break;
          }
          // fall through if no error
+    case PLAYINIT_PENDING:
      case PLAYING:
      case PAUSED:
      {
          IHXBuffer* pAudioBuf = (IHXBuffer*)Message().Ptr0();
      if (pAudioBuf)
      {
-            if (!m_bufferList.AddTail(pAudioBuf))
+            if (0 == m_cbBlock)
+            {
+                // remember audio block size (audio buffs should all be
the same size)
+                m_cbBlock = pAudioBuf->GetSize();
+            }
+            HX_ASSERT(m_cbBlock == pAudioBuf->GetSize());
+
+            if (m_bufferList.AddTail(pAudioBuf))
+            {
+                m_cbBufferList += pAudioBuf->GetSize();
+            }
+            else
          {
                  err = KErrNoMemory;
              }
@@ -466,7 +485,7 @@
          break;
      }
      default:
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Write(): called in
unexpected state %s \n", StringifyState(m_state)));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Write(): called in
unexpected state %s ", StringifyState(m_state));
          HX_ASSERT(false);
          err = KErrGeneral;
          break;
@@ -476,7 +495,7 @@

      if( KErrNone == err && m_pPendingFillBuffer )
      {
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Write(): calling
BufferToBeFilled\n"));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Write(): calling
BufferToBeFilled");
          BufferToBeFilled(m_pPendingFillBuffer);
          HX_ASSERT(!m_pPendingFillBuffer);
      }
@@ -518,16 +537,15 @@

      if (m_sampleCountResetPending)
      {
-        DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::HandleSampleCountReset(): checking for reset (old
base = %lu;  samps played = %lu; samps written = %lu)\n",
m_baseSampleCount, sampleCount, m_samplesWritten));
+        HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::HandleSampleCountReset(): checking for reset (old
base = %lu;  samps played = %lu; samps written = %lu)", m_baseSampleCount,
sampleCount, m_samplesWritten);
          if ( sampleCount < m_baseSampleCount || 0 == m_baseSampleCount
/*0 = first play*/)
          {
-            DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::HandleSampleCountReset(): resetting base sample
count\n"));
+            HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::HandleSampleCountReset(): resetting base sample
count");
              OnResetSampleCount();
          }
          else
          {
-            if (m_unplayedSampleCount > 0 &&
-                sampleCount - m_baseSampleCount > m_unplayedSampleCount)
+            if (m_unplayedSampleCount > 0 && sampleCount -
m_baseSampleCount > m_unplayedSampleCount)
              {
                  // Special case:
  //
@@ -537,7 +555,7 @@
                  // comparing the samples played with the number of
unwritten samples at the time
                  // of the underflow/stop. If the value is greater it must
be from newly written
                  // samples.
-                DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::HandleSampleCountReset(): resetting base sample
count (special case %lu > %lu)\n", sampleCount - m_baseSampleCount,
m_unplayedSampleCount));
+                HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::HandleSampleCountReset(): resetting base sample
count (special case %lu > %lu)", sampleCount - m_baseSampleCount,
m_unplayedSampleCount);
                  OnResetSampleCount();
              }
          }
@@ -547,6 +565,26 @@

  void HXSymbianAudioSession::UpdateTimeSampleStats()
  {
+    // We use some heuristics here because of the following observed
behavior of values returned
+    // from CMMFDevSound::SamplesPlayed() around and after the time of an
underflow.
+    //
+    // 1) Underflow occurs. At that time SamplesPlayed() is sometimes <
samples written. Those appear
+    //    to play out (they are not droppped). There probably is a low
threshold value at which point
+    //    the audio device generates an Underflow error, and we sometimes
see the error before all
+    //    samples actually play out.
+    //
+    // 2) We add time for unplayed samples at that time. We may get a bit
ahead of actual time played.
+    //    We do this because that sample count will be reset after we call
PlayInit and we may miss
+    //    detecting those samples otherwise.
+    //
+    // 3) We call PlayInit so that playing resumes after an underflow (the
device implicitly stops).
+    //    At some point thereafter the sample count (returned from
SamplesPlayed()) will be reset, but that point
+    //    is not deterministic. Sometimes we see sample count continue
relative to last value before
+    //    it resets. Sometimes we see a reset twice. The first reset
appears to be for unplayed samples
+    //    at time of the reset. Once those are played out the sample count
is reset again.
+    //
+
+
      // determine how much time has elapsed since last time computation
      TUint sampleCount = m_pStream->SamplesPlayed();

@@ -557,12 +595,22 @@
          return;
      }

-    HX_ASSERT(m_samplesWritten >= sampleCount);
-    m_unplayedSampleCount = m_samplesWritten - sampleCount;
-
+#if (0)
      // assert likely indicates error; wrap-around is rare case (occurs
after ~27 hours for 44Khz)
      HX_ASSERT(m_baseSampleCount <= sampleCount);
      TUint samplesElapsed = WrapDiff(m_baseSampleCount, sampleCount);
+#else
+    if (sampleCount < m_baseSampleCount )
+    {
+        // assume this is not a wrap-around (~27 hours for 44Khz)
+
+        // assume this is case where we see two resets, the first
apparantly for
+        // for unplayed samples at time of underflow; see (3) above
+        HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::UpdateTimeSampleStats(): oops: base = %lu >  played
= %lu; (unplayed = %lu)", m_baseSampleCount, sampleCount,
m_unplayedSampleCount);
+        return;
+    }
+    TUint samplesElapsed = sampleCount - m_baseSampleCount;
+#endif

      // convert samples-played to time-played
      TUint msElapsed = SamplesToMS(samplesElapsed, m_sampleRate);
@@ -570,12 +618,17 @@
       // update time
      m_msTimePlayed += msElapsed;

-    DPRINTF(D_INFO, ("HXSymbianAudioSession::UpdateTimeSampleStats(): base
= %lu; played = %lu; (unplayed = %lu)\n", m_baseSampleCount, sampleCount,
m_unplayedSampleCount));
-    DPRINTF(D_INFO, ("HXSymbianAudioSession::UpdateTimeSampleStats():
adding %lu ms; total now %lu ms\n", msElapsed, m_msTimePlayed));
+    // keep track of samples that we wrote but haven't been played yet
+    m_unplayedSampleCount = m_samplesWritten - sampleCount;
+
+
+    HXLOGL4(HXLOG_ADEV, "HXSymbianAudioSession::UpdateTimeSampleStats():
base = %lu; played = %lu; (unplayed = %lu)", m_baseSampleCount,
sampleCount, m_unplayedSampleCount);
+    HXLOGL4(HXLOG_ADEV, "HXSymbianAudioSession::UpdateTimeSampleStats():
adding %lu ms; total now %lu ms", msElapsed, m_msTimePlayed);

      // update base sample count for next time
      m_baseSampleCount = sampleCount;
  }
+
  //
  // HXSymbianAudioSession::GetTime
  //
@@ -589,12 +642,27 @@
  //
  // HXSymbianAudioSession::GetBlocksBuffered
  //
-// Return the number of blocks buffered by this object.
+// Return the number of blocks buffered by this object (pending
+// writes plus data buffered in device)
  //
  void HXSymbianAudioSession::GetBlocksBuffered()
  {
-    TInt nTmp = m_bufferList.GetCount();
-    Message().Complete(nTmp);
+    // determine bytes buffered in actual device
+    UpdateTimeSampleStats();
+    HX_ASSERT(m_cbSample != 0);
+    UINT32 cbBuffered = m_unplayedSampleCount * m_cbSample;
+
+    // add in bytes we are holding in our buffer list
+    HX_ASSERT(m_cbBufferList >= m_cbFrontBufferWritten);
+    cbBuffered += m_cbBufferList - m_cbFrontBufferWritten;
+
+    // convert bytes to block count (rounded)
+    TUint32 blockCount = (cbBuffered + m_cbBlock/2)/m_cbBlock;
+
+    HXLOGL4(HXLOG_ADEV, "HXSymbianAudioSession::GetBlocksBuffered(): block
count = %lu (%lu bytes)", blockCount, cbBuffered);
+
+    Message().Complete(blockCount);
+
  }

  //
@@ -659,21 +727,23 @@
  //
  void HXSymbianAudioSession::Stop()
  {
-    if (PLAYING == m_state || PAUSED == m_state || PLAYINIT_PENDING ==
m_state)
+    switch (m_state)
      {
+    case PLAYINIT_PENDING:
+    case PLAYING:
+    case PAUSED:
          // important: update stats before stopping
          UpdateTimeSampleStats();
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Stop(): %lu ms
unplayed in audio device\n", SamplesToMS(m_unplayedSampleCount,
m_sampleRate)));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Stop(): %lu ms
unplayed in audio device", SamplesToMS(m_unplayedSampleCount, m_sampleRate));

          Trans(STOPPED);
          HX_ASSERT(m_pStream);
          m_pStream->Stop();
-    while(!m_bufferList.IsEmpty())
-    {
-        IHXBuffer* pBuf = (IHXBuffer*)m_bufferList.RemoveHead();
-        HX_RELEASE(pBuf);
-    }
-        m_cbFrontBufferWritten = 0;
+        FreePendingBuffers();
+        break;
+    default:
+        // nothing
+        break;
      }

      Message().Complete(KErrNone);
@@ -682,7 +752,7 @@
  void
  HXSymbianAudioSession::RequestDeviceTakenNotification()
  {
-    DPRINTF(D_INFO,
("HXSymbianAudioSession::RequestDeviceTakenNotification()\n"));
+    HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::RequestDeviceTakenNotification()");
      m_wantsNotify = true;
      m_notifyRequest = Message();
  }
@@ -707,7 +777,7 @@
  {
      if (m_wantsNotify)
      {
-        DPRINTF(D_INFO, ("HXSymbianAudioSession::NotifyDeviceTaken():
doing notify...\n"));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::NotifyDeviceTaken():
doing notify...");
          m_notifyRequest.Complete(m_lastPlayError);
          m_wantsNotify = false;
      }
@@ -719,7 +789,7 @@
  {
      if (state != m_state)
      {
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::Trans(): %s -> %s\n",
StringifyState(m_state), StringifyState(state)));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::Trans(): %s -> %s",
StringifyState(m_state), StringifyState(state));
          m_state = state;
          switch (m_state)
          {
@@ -756,14 +826,21 @@
      m_sampleCountResetPending        = true;
  }

-void HXSymbianAudioSession::InitClosedState()
+void HXSymbianAudioSession::FreePendingBuffers()
  {
-    HX_ASSERT(CLOSED == m_state);
      while (!m_bufferList.IsEmpty())
      {
          IHXBuffer* pBuf = (IHXBuffer*)m_bufferList.RemoveHead();
          HX_RELEASE(pBuf);
      }
+    m_cbBufferList = 0;
+    m_cbFrontBufferWritten = 0;
+}
+
+void HXSymbianAudioSession::InitClosedState()
+{
+    HX_ASSERT(CLOSED == m_state);
+    FreePendingBuffers();

      if (m_wantsNotify)
  {
@@ -775,7 +852,7 @@

  void HXSymbianAudioSession::DoPlayInit()
  {
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::DoPlayInit(): setting
priority and calling PlayInitL\n"));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::DoPlayInit(): setting
priority and calling PlayInitL");

      HX_ASSERT(STOPPED == m_state);
      Trans(PLAYINIT_PENDING);
@@ -788,7 +865,7 @@
      m_pStream->SetPrioritySettings(prioritySettings);

      TRAPD(err, m_pStream->PlayInitL());
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::DoPlayInit(): PlayInitL()
result: %s\n", StringifyKErr(err)));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::DoPlayInit(): PlayInitL()
result: %s", StringifyKErr(err));
      if (err != KErrNone)
      {
          Trans(STOPPED);
@@ -799,10 +876,10 @@
  // MDevSoundObserver
  void HXSymbianAudioSession::InitializeComplete(TInt aError)
      {
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::InitializeComplete(): err
= %s\n", StringifyKErr(aError)));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::InitializeComplete(): err
= %s", StringifyKErr(aError));
      TRAPD(err, (m_pStream->CMMFDevSound::SetConfigL(m_Settings)));
      Trans((KErrNone == err) ? STOPPED : CLOSED);
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::InitializeComplete()
SetConfgL(): err = %s\n", StringifyKErr(err)));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::InitializeComplete()
SetConfgL(): err = %s", StringifyKErr(err));
      m_InitMessage.Complete(err);
  }

@@ -820,7 +897,7 @@
      case PAUSED:
      case STOPPED:
      default:
-        DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::BufferToBeFilled():
unexpected state %s\n", StringifyState(m_state)));
+        HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::BufferToBeFilled():
unexpected state %s", StringifyState(m_state));
      case PLAYING:
          break;
      }
@@ -831,7 +908,7 @@
          dataDesc = TPtrC8(NULL, 0 ); // ensure descriptor is reset/clear
          TUint cbDest  = aBuffer->RequestSize();

-        //DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::BufferToBeFilled():
req size = %ld; dest buffer size = %lu; desc max = %lu; buffer list count =
%ld\n", aBuffer->RequestSize(), aBuffer->BufferSize(), dataDesc.MaxSize(),
m_bufferList.GetCount()));
+        //HXLOGL4(HXLOG_ADEV, "HXSymbianAudioSession::BufferToBeFilled():
req size = %ld; dest buffer size = %lu; desc max = %lu; buffer list count =
%ld", aBuffer->RequestSize(), aBuffer->BufferSize(), dataDesc.MaxSize(),
m_bufferList.GetCount());

          while ( !m_bufferList.IsEmpty() && cbDest >= m_cbSample)
              {
@@ -847,7 +924,7 @@
              // m_cbFrontBufferWritten = bytes already written from front
buffer
              HX_ASSERT(m_cbFrontBufferWritten < cbBuffer);

-            //DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::BufferToBeFilled(): next src buffer size = %lu;
front buffer written = %lu\n", cbBuffer, m_cbFrontBufferWritten));
+            //HXLOGL4(HXLOG_ADEV,
"HXSymbianAudioSession::BufferToBeFilled(): next src buffer size = %lu;
front buffer written = %lu", cbBuffer, m_cbFrontBufferWritten);

// decide how much to write; we may not be able to write a
full buffer
UINT32 cbToWrite = pBuffer->GetSize() - m_cbFrontBufferWritten;
@@ -877,14 +954,16 @@
{
// we used up the front buffer; toss it
IHXBuffer* pTmp = (IHXBuffer*)m_bufferList.RemoveHead();
+ m_cbBufferList -= pTmp->GetSize();
HX_RELEASE(pTmp);
m_cbFrontBufferWritten = 0;
+
}
}


          if (dataDesc.Length() > 0)
          {
-            DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::BufferToBeFilled(): play buff = %ld bytes; samps
written = %lu\n", dataDesc.Length(), m_samplesWritten));
+            HXLOGL4(HXLOG_ADEV,
"HXSymbianAudioSession::BufferToBeFilled(): play buff = %ld bytes; samps
written = %lu", dataDesc.Length(), m_samplesWritten);
              if (PLAYING == m_state)
              {
              m_pStream->PlayData();
@@ -893,7 +972,7 @@
          }
          else
          {
-            DPRINTF(D_SYMAUDIO,
("HXSymbianAudioSession::BufferToBeFilled(): unable to fill buffer (no src
data)\n"));
+            HXLOGL3(HXLOG_ADEV,
"HXSymbianAudioSession::BufferToBeFilled(): unable to fill buffer (no src
data)");
              // hold on to buffer; we'll fill it once we have more src data
              m_pPendingFillBuffer = aBuffer;
          }
@@ -903,10 +982,10 @@
  // MDevSoundObserver
  void HXSymbianAudioSession::PlayError(TInt aError)
  {
-    DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::PlayError(): err = %s\n",
StringifyKErr(aError)));
+    HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::PlayError(): err = %s",
StringifyKErr(aError));
+    HX_ASSERT(aError != KErrNone); // possible?
      if (aError != KErrNone)
      {
-        // update stats before stopping
          UpdateTimeSampleStats();

          // stream is implicitly stopped when an error occurs
@@ -917,31 +996,30 @@
                  // either we just played out or (more likely) we were not
                  // writing to the device fast enough

- // add unwritten (lost) samples to time played
- TUint msDiscarded = SamplesToMS(m_unplayedSampleCount,
m_sampleRate);
- DPRINTF(D_SYMAUDIO, ("HXSymbianAudioSession::PlayError():
underflow discarded time = %lu\n", msDiscarded));
- m_msTimePlayed += msDiscarded;
+ // add unwritten samples to time played (note: reported time
+ // will be slightly ahead until we catch up)
+ TUint msPending = SamplesToMS(m_unplayedSampleCount,
m_sampleRate);
+ HXLOGL3(HXLOG_ADEV, "HXSymbianAudioSession::PlayError():
underflow unplayed time = %lu (%lu samples)", msPending,
m_unplayedSampleCount);
+ m_msTimePlayed += msPending;
+
// save current time so we preserve monotonically
increasing time
m_msReInitTimePlayed = m_msTimePlayed;
- Trans(STOPPED);
+
// re-init so we resume (continue) audio playback
+ Trans(STOPPED);
DoPlayInit();
}
break;
case KErrCancel:
- {
Trans(STOPPED);
- }
break;
case KErrAccessDenied:
case KErrInUse:
case KErrDied: // incoming message notification on 6630 generates
this
default:
- {
m_lastPlayError = aError;
Trans(STOPPED);
NotifyDeviceTaken();
- }
break;
}
}
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.5
diff -u -w -r1.5 audio_session-mmf.h
--- platform/symbian/audiosvr/mmf/audio_session-mmf.h 7 Feb 2005 20:50:34
-0000 1.5
+++ platform/symbian/audiosvr/mmf/audio_session-mmf.h 4 Apr 2005 18:31:56 -0000
@@ -117,6 +117,7 @@
void CheckSampleCountReset(TUint sampleCount);
void OnResetSampleCount();


+    void FreePendingBuffers();
      void InitPlayInitPendingState();
      void InitStoppedState();
      void InitClosedState();
@@ -134,6 +135,8 @@
      TMMFCapabilities  m_Settings;
      TUint                   m_sampleRate;
      TUint                   m_cbSample;
+    TUint                   m_cbBlock;
+    TUint                   m_cbBufferList;
      State                   m_state;

      // write related


_______________________________________________ Porting-symbian mailing list [EMAIL PROTECTED] http://lists.helixcommunity.org/mailman/listinfo/porting-symbian


_______________________________________________
Audio-dev mailing list
[email protected]
http://lists.helixcommunity.org/mailman/listinfo/audio-dev

Reply via email to