mmsharing/mmshengine/src/musengreceivesession.cpp
branchRCL_3
changeset 23 bc78a40cd63c
parent 22 73a1feb507fb
--- a/mmsharing/mmshengine/src/musengreceivesession.cpp	Tue Aug 31 15:12:07 2010 +0300
+++ b/mmsharing/mmshengine/src/musengreceivesession.cpp	Wed Sep 01 12:31:01 2010 +0100
@@ -18,15 +18,16 @@
 
 
 // USER INCLUDES
+
 #include "musengreceivesession.h"
+#include "musengsessionobserver.h"
+#include "musengreceivesessionobserver.h"
 #include "musengmceutils.h"
 #include "musenglogger.h"
+#include "mussettings.h"
 #include "mussipprofilehandler.h"
-#include "mussessionproperties.h"
-#include "musengremotevideoplayer.h"
 
 // SYSTEM INCLUDES
-#include <lcsessionobserver.h>
 #include <mcemanager.h>
 #include <mceinsession.h>
 #include <mcestreambundle.h>
@@ -38,20 +39,25 @@
 #include <mcespeakersink.h>
 #include <mceaudiocodec.h>
 #include <mceavccodec.h>
-#include <e32property.h>
 
 #include <utf.h>
 
+
+const TUint8 KMusEngRtpKeepAliveTimer = 5; // this should be 30 sec, this a temporary fix
+const TUint8 KMusEngKeepAlivePayloadTypeVideoH263 = 96;
+const TUint8 KMusEngKeepAlivePayloadTypeAudio = 97;
+const TUint8 KMusEngKeepAlivePayloadTypeVideoAvc = 98;
+
 const TInt KMusEngJitterBufferLength = 51; //Must be bigger than treshold
 // Using following value increases treshold buffer to 1 second from 
 // default 100 ms
 const TInt KMusEngJitterBufferTreshold = 50;
 const TInt KMusEngTresholdToSecondsFactor = 20;
-const TInt KMusEngTwoSecondInMilliSeconds = 2000; 
+const TInt KMusEngOneSecondInMilliSeconds = 1000; 
 // Use inactivity timer value that is a little bigger than treshold in seconds
 const TUint KMusEngInactivityTimer = KMusEngTresholdToSecondsFactor * 
                                      KMusEngJitterBufferTreshold + 
-                                     KMusEngTwoSecondInMilliSeconds;
+                                     KMusEngOneSecondInMilliSeconds;
 
 _LIT8( KMusEngSwisIdentifier, "Require: precondition" );
 _LIT8( KMusEngAssertedIdentity, "P-Asserted-Identity" );
@@ -64,11 +70,28 @@
 //
 // -----------------------------------------------------------------------------
 //
-CMusEngReceiveSession* CMusEngReceiveSession::NewL()
+CMusEngReceiveSession::~CMusEngReceiveSession()
+    {
+    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::~CMusEngReceiveSession()" )
+    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::~CMusEngReceiveSession()" )
+    }
+
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+EXPORT_C CMusEngReceiveSession* CMusEngReceiveSession::NewL(
+                        const TRect& aRect,
+                        MMusEngSessionObserver& aSessionObserver,
+                        MMusEngReceiveSessionObserver& aReceiveSessionObserver )
     {
     MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::NewL(...)" )
 
-    CMusEngReceiveSession* self = new( ELeave )CMusEngReceiveSession();
+    CMusEngReceiveSession* self = new( ELeave ) CMusEngReceiveSession( 
+                                                        aSessionObserver, 
+                                                        aReceiveSessionObserver,
+                                                        aRect );
     CleanupStack::PushL( self );
     self->ConstructL();
     CleanupStack::Pop( self );
@@ -77,101 +100,27 @@
     return self;
     }
 
-// -----------------------------------------------------------------------------
-//
-// -----------------------------------------------------------------------------
-//
-CMusEngReceiveSession::CMusEngReceiveSession()
-    : CMusEngMceSession()
-    {
-    }
-
-// -----------------------------------------------------------------------------
-//
-// -----------------------------------------------------------------------------
-//
-void CMusEngReceiveSession::ConstructL()
-    {
-    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::ConstructL()" )
-
-    CMusEngMceSession::ConstructL();
-    
-    iOriginator = HBufC8::NewL( KMaxUriLength );
-    
-    iRemoteDisplayName = HBufC::NewL( KMaxUriLength );
-
-    iRemoteVideoPlayer = CMusEngRemoteVideoPlayer::NewL( *this, *this );
-    
-    iReceivingInactivityTimeout = KMusEngInactivityTimer;
-    
-    iKeepaliveTimer = KMusEngRtpKeepAliveTimer;
-    
-    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::ConstructL()" )
-    }
 
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
 //
-CMusEngReceiveSession::~CMusEngReceiveSession()
+EXPORT_C void CMusEngReceiveSession::AcceptInvitationL(
+                        const TBool& aAccept )
     {
-    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::~CMusEngReceiveSession()" )
-    
-    if ( iOriginator )
+    MUS_LOG1( "mus: [ENGINE]     -> CMusEngReceiveSession::\
+              AcceptInvitationL( %d )", aAccept )
+
+    __ASSERT_ALWAYS( iSession && iSession->State() == CMceSession::EProceeding,
+                     User::Leave( KErrNotReady ) );
+
+    // Accept or reject
+    if ( aAccept )
         {
-        TRAP_IGNORE( SaveContactL( *iOriginator ) )
-        }
-    delete iOriginator;
-    
-    delete iRemoteDisplayName;
-    
-    delete iRemoteVideoPlayer;
-    
-    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::~CMusEngReceiveSession()" )
-    }
-
-// -----------------------------------------------------------------------------
-// From MLcSession
-// -----------------------------------------------------------------------------
-//
-MLcSession::TLcSessionState CMusEngReceiveSession::LcSessionState() const
-    {
-    TLcSessionState state = CMusEngMceSession::LcSessionState();
-    if ( !iSession && state == MLcSession::EUninitialized )
-        {
-        state = MLcSession::EReceived;
+        InSession()->AcceptL();
         }
-    return state;
-    }
-
-// -----------------------------------------------------------------------------
-// From MLcSession
-// -----------------------------------------------------------------------------
-//
-void CMusEngReceiveSession::EstablishLcSessionL()
-    {
-    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::EstablishLcSessionL" )
-
-    __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
-    InSession()->AcceptL();
-    
-    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::EstablishLcSessionL" )
-    }
-
-// -----------------------------------------------------------------------------
-// From MLcSession
-// -----------------------------------------------------------------------------
-//
-void CMusEngReceiveSession::TerminateLcSessionL()
-    {
-    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::EstablishLcSessionL" )
-
-    __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
-
-    if ( iSession->State() == CMceSession::EIncoming ||
-         iSession->State() == CMceSession::EProceeding )
+    else
         {
-        // Reject
         if ( iOperatorVariant )
             {
             // In operator variant, session is rejected with 486 instead of 603.
@@ -184,45 +133,11 @@
             InSession()->RejectL();
             }
         }
-    else
-        {
-        iSession->TerminateL();
-        }
-    
-    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::EstablishLcSessionL" )
+
+    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::\
+             AcceptInvitationL(...)" )
     }
 
-// -----------------------------------------------------------------------------
-// From MLcSession
-// -----------------------------------------------------------------------------
-//
-MLcVideoPlayer* CMusEngReceiveSession::RemoteVideoPlayer()
-    {
-    return iRemoteVideoPlayer;
-    }
-    
-// -----------------------------------------------------------------------------
-// From MLcSession
-// -----------------------------------------------------------------------------
-//
-const TDesC& CMusEngReceiveSession::RemoteDisplayName()
-    {
-    TBuf<RProperty::KMaxPropertySize> buffer;
-
-    TInt error = RProperty::Get( NMusSessionApi::KCategoryUid,
-                                 NMusSessionApi::KContactName,
-                                 buffer );
-    if ( error == KErrNone && buffer.Length() )
-        {
-        iRemoteDisplayName->Des().Copy( buffer );
-        }
-    
-    else if ( iOriginator )
-        {
-        iRemoteDisplayName->Des().Copy(*iOriginator);   
-        }
-    return *iRemoteDisplayName;
-    }
 
 // -----------------------------------------------------------------------------
 // When reserving resources is ready, this function reports observer about
@@ -239,8 +154,7 @@
 
     MUS_ENG_LOG_SESSION_STATE_AND_STATUS( aSession, aStatusCode, aReasonPhrase )
 
-    if ( iSession && 
-         iSession == &aSession &&
+    if ( iSession && iSession == &aSession &&
          aSession.State() == CMceSession::EProceeding )
         {
         // Indicates that resource reservation is ready, user can be notified
@@ -251,9 +165,16 @@
             // Notify other end terminal
             TRAP_IGNORE( InSession()->RingL() )
             iRingLCalled = ETrue;
-            TPtr8 ptrOriginator( iOriginator->Des() );
-            ptrOriginator.Copy( iSession->Originator() );
-            InformObserverAboutSessionStateChange();
+            
+            // Notify user
+            TBuf16<KMaxUriLength> originator;
+            CnvUtfConverter::ConvertToUnicodeFromUtf8( originator,
+                                                       iSession->Originator() );
+                                                       
+            TBuf16<KMaxUriLength> identity;
+            CnvUtfConverter::ConvertToUnicodeFromUtf8( identity,
+                                                       iIdentity );                                                       
+            iReceiveSessionObserver.IncomingSession( originator, identity );
             }
         else
             {
@@ -273,19 +194,18 @@
              HandleSessionStateChanged()" )
     }
 
+
 // -----------------------------------------------------------------------------
 // Sets keepalive timer for video and calls base class variant of this function
 // -----------------------------------------------------------------------------
 //
-void CMusEngReceiveSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec,
-                                               TMceSourceType aSourceType )
+void CMusEngReceiveSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec )
     {
     MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::AdjustVideoCodecL()" )
     
-    CMusEngMceSession::AdjustVideoCodecL( aVideoCodec, aSourceType );
+    CMusEngMceSession::AdjustVideoCodecL( aVideoCodec );
     
-    MUS_LOG1( "mus: [ENGINE]     Keepalive timer:%d", iKeepaliveTimer )
-    aVideoCodec.SetKeepAliveTimerL( iKeepaliveTimer );
+    aVideoCodec.SetKeepAliveTimerL( KMusEngRtpKeepAliveTimer );
     if ( aVideoCodec.SdpName() == KMceSDPNameH263() ||
          aVideoCodec.SdpName() == KMceSDPNameH2632000() )
         {
@@ -305,6 +225,7 @@
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::AdjustVideoCodecL()" )
     }
         
+
 // -----------------------------------------------------------------------------
 // Sets keepalive timer for audio and calls base class variant of this function
 // -----------------------------------------------------------------------------
@@ -315,13 +236,14 @@
 
     CMusEngMceSession::AdjustAudioCodecL( aAudioCodec );
     
-    aAudioCodec.SetKeepAliveTimerL( iKeepaliveTimer );
+    aAudioCodec.SetKeepAliveTimerL( KMusEngRtpKeepAliveTimer );
     aAudioCodec.SetKeepAlivePayloadTypeL( KMusEngKeepAlivePayloadTypeAudio );
     aAudioCodec.SetKeepAliveDataL( KNullDesC8() );
     
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::AdjustAudioCodecL()" )
     }
 
+
 // -----------------------------------------------------------------------------
 // 
 // -----------------------------------------------------------------------------
@@ -337,7 +259,8 @@
     
     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
         {
-        if ( codecs[codecIndex]->SdpName() == KMceSDPNameH264() )
+        if ( codecs[codecIndex]->SdpName() == KMceSDPNameH264() && 
+             !MultimediaSharingSettings::IsAvcDisabled() )
             { 
             if ( codecs[codecIndex]->CodecMode() == KMceAvcModeSingleNal )
                 {
@@ -400,6 +323,7 @@
                
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::DoCodecSelectionL()" )
     }
+    
 
 // -----------------------------------------------------------------------------
 // If incoming session does not have valid structure and cannot be reconstructed
@@ -407,8 +331,8 @@
 // -----------------------------------------------------------------------------
 //
 void CMusEngReceiveSession::IncomingSession(
-    CMceInSession* aSession,
-    TMceTransactionDataContainer* aContainer )
+                      CMceInSession* aSession,
+                      TMceTransactionDataContainer* aContainer )
     {
     MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::IncomingSession(...)" )
 
@@ -426,6 +350,8 @@
         return;
         }
 
+    iReceiveSessionObserver.IncomingSessionPreNotification();
+
     delete iSession; // possibly existing terminated session
     iSession = aSession;
     
@@ -451,14 +377,15 @@
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::IncomingSession()" )
     }
 
+
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
 //
 void CMusEngReceiveSession::IncomingUpdate(
-    CMceSession& aOrigSession,
-    CMceInSession* aUpdatedSession,
-    TMceTransactionDataContainer* aContainer )
+                     CMceSession& aOrigSession,
+                     CMceInSession* aUpdatedSession,
+                     TMceTransactionDataContainer* aContainer )
     {
     MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::IncomingUpdate(...)" )
 
@@ -488,6 +415,7 @@
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::IncomingUpdate(...)" )
     }
 
+
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
@@ -507,20 +435,33 @@
          aStream.Source() &&
          aStream.Source()->Type() == KMceRTPSource )
         {
+        
         if ( aStream.State() == CMceMediaStream::EBuffering )
             {
-            iBuffered = ETrue;
-            InformObserverAboutPlayerStateChange( iRemoteVideoPlayer );
+            iReceiveSessionObserver.StreamBuffering();
             }
         else if ( aStream.State() == CMceMediaStream::EStreaming )
             {
-            ReceivingStarted();          
+            CMceRtpSource* rtpSource = 
+                            static_cast<CMceRtpSource*>( aStream.Source() );
+            TRAPD( err , 
+                  rtpSource->EnableInactivityTimerL( KMusEngInactivityTimer ) );
+            if ( err != KErrNone )
+                {
+                MUS_LOG1("mus: [ENGINE] EnableInactivityTimerL Fails %d",err)
+                iSessionObserver.SessionFailed();    
+                }
+            else
+                {
+                iSessionObserver.StreamStreaming();
+                }            
             }
         else
             {
             // Cannot handle, forward to CMusEngMceSession
             CMusEngMceSession::StreamStateChanged( aStream );
             }
+        
         }
     else
         {
@@ -531,6 +472,35 @@
     MUS_LOG( "mus: [ENGINE] <- CMusEngReceiveSession::StreamStateChanged()" )
     }
 
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+CMusEngReceiveSession::CMusEngReceiveSession(
+                        MMusEngSessionObserver& aSessionObserver,
+                        MMusEngReceiveSessionObserver& aReceiveSessionObserver,
+                        const TRect& aRect )
+    : CMusEngMceSession( aRect, aSessionObserver ),
+      iReceiveSessionObserver( aReceiveSessionObserver )
+    {
+    }
+
+
+// -----------------------------------------------------------------------------
+//
+// -----------------------------------------------------------------------------
+//
+void CMusEngReceiveSession::ConstructL()
+    {
+    MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::ConstructL()" )
+
+    CMusEngMceSession::ConstructL();
+
+    MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::ConstructL()" )
+    }
+
+
 // -----------------------------------------------------------------------------
 //
 // -----------------------------------------------------------------------------
@@ -540,6 +510,7 @@
     return static_cast<CMceInSession*>(iSession);
     }
 
+
 // -----------------------------------------------------------------------------
 // Check if incoming session is originated from VideoSharing 2.2 client, 
 // which sends PRACK for 180 Ringing whether it is required or not. In 
@@ -548,7 +519,7 @@
 // -----------------------------------------------------------------------------
 //
 void CMusEngReceiveSession::PrepareToRequire100RelL( 
-    TMceTransactionDataContainer* aContainer)
+                    TMceTransactionDataContainer* aContainer)
     {
     MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::PrepareToRequire100RelL()" )
     
@@ -567,13 +538,15 @@
                 iSession->SetModifierL( KMce100Rel, KMce100RelRequired );
                 MUS_LOG( "mus: [ENGINE]     Forced to require 100rel" )
                 }   
-            }     
+            }
+            
         }
     
     CleanupStack::PopAndDestroy( headers );
    
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::PrepareToRequire100RelL()" )
-    }      
+    }
+        
 
 // -----------------------------------------------------------------------------
 // Check that incoming session contains only incoming video and audio
@@ -700,15 +673,14 @@
     iSession->UpdateL();
 
     // Now session state is right to adjust volume
-    SetSpeakerVolumeL( LcVolumeL() );
+    SetSpeakerVolumeL( VolumeL() );
 
-    iSipProfileHandler->CreateProfileL( iSession->Profile() );
-    
-    iRemoteVideoPlayer->SetMceSession( iSession );
-    
+	iSipProfileHandler->CreateProfileL( iSession->Profile() );
+
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::CompleteSessionStructureL()" )
     }
     
+    
 // -----------------------------------------------------------------------------
 // Parse P-Asserted-Identity Header
 // -----------------------------------------------------------------------------
@@ -782,67 +754,3 @@
     delete headers;  
     MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::AssertedIdentity()" )      
     }
-
-// -----------------------------------------------------------------------------
-// RTP Inactivity timeout event
-// Once inactivity timeout occurs, state change is notified and receiving
-// and buffering statuses are cleared. That is safe to do as once receiving
-// again continues for real, buffering and streaming events will occur always 
-// sequentially. If buffering status would not be cleared, some unwanted
-// sreaming events would be passed towards client when it disables/enables
-// display sink of remote stream while inactivity timer has expired.
-// -----------------------------------------------------------------------------
-//
-void CMusEngReceiveSession::InactivityTimeout( CMceMediaStream& aStream,
-                                                  CMceRtpSource& /*aSource*/ )
-    {
-    MUS_LOG( "mus: [ENGINE]  -> CMusEngTwoWayRecvSession::InactivityTimeout()" )
-    
-    if ( aStream.Type() == KMceVideo && iReceiving )
-        {
-        iReceiving = EFalse;
-        iBuffered = EFalse;
-        InformObserverAboutPlayerStateChange( iRemoteVideoPlayer );
-        }
-    
-    MUS_LOG( "mus: [ENGINE]  <- CMusEngTwoWayRecvSession::InactivityTimeout()" )
-    }
-
-// -----------------------------------------------------------------------------
-//
-// -----------------------------------------------------------------------------
-//
-void CMusEngReceiveSession::ReceivingStarted()
-    {
-    if ( iSession && iBuffered )
-        {
-        MUS_LOG( "mus: [ENGINE]  -> CMusEngReceiveSession::ReceivingStarted()" )
-        
-        TInt err = MusEngMceUtils::EnableInactivityTimer( 
-                *iSession, iReceivingInactivityTimeout );
-        
-        if ( err != KErrNone )
-            {
-            MUS_LOG1("mus: [ENGINE] ReceivingStarted failed %d", err)
-            InformObserverAboutSessionFailure( err );
-            }
-        else
-            {
-            iReceiving = ETrue;
-            InformObserverAboutPlayerStateChange( iRemoteVideoPlayer );
-            InformUiProviderAboutReceivingStart();
-            }
-        
-        MUS_LOG( "mus: [ENGINE]  <- CMusEngReceiveSession::ReceivingStarted()" )
-        }
-    }
-
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
-TBool CMusEngReceiveSession::IsDisplayActive()
-    {
-    return ( IsDisplayEnabled() && iReceiving );
-    }
-// End of File