mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Src/AdvancedAudioPlayController.cpp
changeset 31 8dfd592727cb
parent 16 43d09473c595
child 52 4ce423f34688
--- a/mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Src/AdvancedAudioPlayController.cpp	Thu May 27 13:20:50 2010 +0300
+++ b/mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Src/AdvancedAudioPlayController.cpp	Wed Jun 23 18:47:10 2010 +0300
@@ -123,6 +123,8 @@
 	delete iDataSourceAdapter;
 	delete iWait;
 	delete iBlockSetPos;
+	delete iBlockPrime;
+      
 	iSharedBuffers.ResetAndDestroy();
 	iSharedBuffers.Close();
     DP0(_L("CAdvancedAudioPlayController::~CAdvancedAudioPlayController end"));
@@ -679,7 +681,13 @@
             iBlockSetPos->AsyncStop();
             }
         }
-
+    if(iBlockPrime)
+       {
+       if(iBlockPrime->IsStarted())
+       	   {
+            iBlockPrime->AsyncStop();
+           }
+       }
     iRequestState = EPaused;
     TRAP(err, DoPauseL(ETrue)); // this is a preemption pause
 	// In case of pre-emption we should only Pause ... but not Stop.
@@ -986,11 +994,6 @@
     {
     DP0(_L("CAdvancedAudioPlayController::RemoveDataSinkL"));
 
-    if (!iDataSink)
-		{
-        User::Leave(KErrNotReady);
-		}
-
     if (iDataSink != &aDataSink)
 		{
         User::Leave(KErrArgument);
@@ -1000,9 +1003,12 @@
 		{
         User::Leave(KErrNotReady);
 		}
-
-    iDataSink->SinkStopL();         // should always stop source before logoff
-	iDataSink->SinkThreadLogoff();
+		
+   if (iDataSink)
+   	{
+       iDataSink->SinkStopL();         // should always stop source before logoff
+	     iDataSink->SinkThreadLogoff();
+	  }
 
     // dereference Decoder from Utility before deleting AudioOutput (which took ownership of decoder)
     if (iAudioUtility)
@@ -1010,8 +1016,8 @@
         iAudioUtility->DeReferenceDecoder();
     	}
     
-	delete iAudioOutput;
-	iAudioOutput = NULL;
+    delete iAudioOutput;
+	  iAudioOutput = NULL;
     iDataSink = NULL;
     iDecoderExists = EFalse;
     }
@@ -1025,7 +1031,12 @@
     DP0(_L("CAdvancedAudioPlayController::ResetL"));
 
     RemoveDataSourceL(*iDataSource);
-    RemoveDataSinkL(*iDataSink);
+    
+    if (iDataSink)
+    	{
+    		  DP0(_L("CAdvancedAudioPlayController::ResetL, calling RemoveDataSinkL"));
+          RemoveDataSinkL(*iDataSink);
+      }
     }
 
 // -----------------------------------------------------------------------------
@@ -1349,6 +1360,21 @@
         {// we got preempted during a seek
         // we're already seeking to a position. When we get there we'll come here again, but handle it below
         DP0(_L("CAdvancedAudioPlayController::DoPauseL got a preemption during seek"));
+        
+         // if we are seeking, we need to flush the devsound buffers regardless of loop play
+        DP0(_L("CAdvancedAudioPlayController::DoPauseL AudioOutput->StopL()"));
+        iAudioOutput->StopL();
+
+        if (iPlayingForInitPos)
+         {
+           iState = EInitialized;
+         }
+        else
+         {
+           iState = EPaused;
+         }
+        iPlayingForPauseSeek = EFalse;
+        iPlayingForInitPos = EFalse; 
         return;
         }
 
@@ -1613,7 +1639,11 @@
             iBlockSetPos->AsyncStop();
             }
         }
-   
+    if(iBlockPrime)
+        {
+        if(iBlockPrime->IsStarted())
+         iBlockPrime->AsyncStop();
+        }
     iPlayingForDuration = EFalse;
     iBlockDuration = EFalse;
     iPlayingForPauseSeek = EFalse;
@@ -1702,11 +1732,17 @@
 		case EInitializing:
             if (position != 0)
     	   		{ // if we are priming, we will already be ready to play from 0.
-				DP2(_L("CAdvancedAudioPlayController::SetPositionL, saving pos iReadHeader[%d] iState[%d]"),iReadHeader,iState);
-                iInitPosition = position;
+				     DP2(_L("CAdvancedAudioPlayController::SetPositionL, saving pos iReadHeader[%d] iState[%d]"),iReadHeader,iState);
+             iInitPosition = position;
        			}
-			DP0(_L("CAdvancedAudioPlayController::SetPositionL, can ignore"));
-			break;
+			  DP0(_L("CAdvancedAudioPlayController::SetPositionL, can ignore"));
+			  DP0(_L("CAdvancedAudioController::PrimeL() blocking"));
+        iBlockPrime= new (ELeave) CActiveSchedulerWait();
+        iBlockPrime->Start();
+        DP0(_L("CAdvancedAudioController::PrimeL() continuing"));
+        delete iBlockPrime;
+        iBlockPrime= NULL;
+			
 		case EInitialized:
 		case EPaused:
 		    iSavedSetPosition = position;
@@ -1881,6 +1917,14 @@
 				        return;
 				        }
 					iState = EInitialized;
+					if(iBlockPrime)
+					    {
+					    if(iBlockPrime->IsStarted())
+					    	{
+					      iBlockPrime->AsyncStop();
+					      }
+					    }
+					
 					// when playwindow is active for a non-seekable source during loop play
 					// we must seek to the playwindow start position and then start the playback
 					if (iPlayWindowStartPosition > 0) // do we need additional checks as loop play / non-seekable source ??
@@ -1907,7 +1951,7 @@
                         }
                     else
                         {
-                        // This is needed for non-seekable sources as DoRepeat() calls DoInitialize in this case
+                        // This is needed for non-seekable sources as DoRepeatL() calls DoInitialize in this case
                         // this resets the source to read from 0 and sets the iState to EInitializing.
                         // BufferFilled will not read the header again, change state to EInitialized and seek to the iInitPosition.
                         // The next BufferFilled will come here, where we will continue playback from byte position 0
@@ -2409,20 +2453,20 @@
     DP0(_L("CAdvancedAudioPlayController::LastBufferSent End"));
     }
 
-void CAdvancedAudioPlayController::DoRepeat()
+void CAdvancedAudioPlayController::DoRepeatL()
     {
-    DP0(_L("CAdvancedAudioPlayController::DoRepeat Begin"));
+    DP0(_L("CAdvancedAudioPlayController::DoRepeatL Begin"));
     // save the current position, this will be used to calculate the position in loop play when
     // client calls for PositionL() or Pause() operations
     // TODO:  need to check this position when loop play is going on in a play window
     iSavedTimePositionInMicroSecs = iAudioOutput->CalculateAudioOutputPositionL();
-    DP1(_L("CAdvancedAudioPlayController::DoRepeat iSavedTimePositionInMicroSecs[%u]"), iSavedTimePositionInMicroSecs);
+    DP1(_L("CAdvancedAudioPlayController::DoRepeatL iSavedTimePositionInMicroSecs[%u]"), iSavedTimePositionInMicroSecs);
     
     if ((!iRepeatForever) && (iCurrentRepeatCount < iRepeatCount))
         {
         iCurrentRepeatCount++;
         }
-    DP1(_L("CAdvancedAudioPlayController::DoRepeat Number of times played till now = %d"), iCurrentRepeatCount);
+    DP1(_L("CAdvancedAudioPlayController::DoRepeatL Number of times played till now = %d"), iCurrentRepeatCount);
     
     if (iSourceIsTimeSeekable || iSourceIsPosSeekable)
         { // For seekable source
@@ -2431,25 +2475,25 @@
         // SetPlayWindow(iPlayWindowStartPosition, iPlayWindowEndPosition);
         if (iPlayWindowStartPosition > 0)
             {
-            DP1(_L("CAdvancedAudioPlayController::DoRepeat SetPositionL[%d]ms"), I64LOW(iPlayWindowStartPosition.Int64()/1000));
+            DP1(_L("CAdvancedAudioPlayController::DoRepeatL SetPositionL[%d]ms"), I64LOW(iPlayWindowStartPosition.Int64()/1000));
             SetPositionL(iPlayWindowStartPosition);
             }
         else
             {
-            DP0(_L("CAdvancedAudioPlayController::DoRepeat SetPositionL(0)"));
+            DP0(_L("CAdvancedAudioPlayController::DoRepeatL SetPositionL(0)"));
             SetPositionL(0);
             }
         // Register for PlayWindow end position as the FrameTable has set its playwindowendpostime to zero
         if (iPlayWindowEndPosition > 0)
             {
-            DP1(_L("CAdvancedAudioPlayController::DoRepeat iAudioUtility->SetPlayWindowEndTimeMs(%d)"), I64LOW(iPlayWindowEndPosition.Int64()/1000));
+            DP1(_L("CAdvancedAudioPlayController::DoRepeatL iAudioUtility->SetPlayWindowEndTimeMs(%d)"), I64LOW(iPlayWindowEndPosition.Int64()/1000));
             iAudioUtility->SetPlayWindowEndTimeMs(iPlayWindowEndPosition.Int64() / 1000);
             }
         }
     else
         { // For non-seekable source
         // Stop and start playback
-        DP0(_L("CAdvancedAudioPlayController::DoRepeat Non-Seekable source."));
+        DP0(_L("CAdvancedAudioPlayController::DoRepeatL Non-Seekable source."));
         iAudioOutput->StopL(EFalse);
         iDataSourceAdapter->SourceStopL(); // clear the buffers in the source before seeking and priming it
         DoInitializeL();
@@ -2457,13 +2501,19 @@
         // and the current position is adjusted to be placed after the header.
         iReadHeader = ETrue;
         }
-    DP0(_L("CAdvancedAudioPlayController::DoRepeat End") );
+    DP0(_L("CAdvancedAudioPlayController::DoRepeatL End") );
     }
 
 EXPORT_C void CAdvancedAudioPlayController::TrailingSilenceTimerComplete()
     {
     DP0(_L("CAdvancedAudioPlayController::TrailingSilenceTimerComplete "));
-    DoRepeat();
+   
+    TRAPD(err,DoRepeatL()); //Fix for Bug ECWG-84WE9J
+    DP1(_L("CAdvancedAudioPlayController::TrailingSilenceTimerComplete: DoRepeatL [%d]"), err);
+    if(err)
+        {
+         SendEventToClient(TMMFEvent(KMMFEventCategoryPlaybackComplete,err));
+        }
     }
 
 EXPORT_C TInt CAdvancedAudioPlayController::GetCodecConfigData(RArray<TInt>& aCodecConfigData)