multimediacommsengine/tsrc/MCETestUI/MCETestUIEngine/src/CMCETestUIEngineInSession.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // MCE API
       
    22 
       
    23 #include <MCEManager.h>
       
    24 #include <MCESession.h>
       
    25 #include <MCEInSession.h>
       
    26 #include <MCEAudioStream.h>
       
    27 #include <MCEFCMsgExchange.h>
       
    28 #include <mcertpsource.h>
       
    29 #include <mcedisplaysink.h>
       
    30 #include <mcespeakersink.h>
       
    31 #include <MCEmediaSink.h>
       
    32 #include <MCEVideoCodec.h>
       
    33 #include <mcesecuresession.h>
       
    34 #include <mcecamerasource.h>
       
    35 #include <mcevideostream.h>
       
    36 #include <aknutils.h>
       
    37 #include "MCETestUIEngineDefaultValues.h"
       
    38 
       
    39 #include "CMCETestUIEngineMultimediaObserver.h"
       
    40 #include "CMCETestUIEngine.h"
       
    41 #include "CMCETestUIEngineSession.h"
       
    42 #include "CMCETestUIEngineInSession.h"
       
    43 
       
    44 #include "TMCETestUIEngineCmdAcceptSession.h"
       
    45 #include "TMCETestUIEngineCmdRejectSession.h"
       
    46 #include "TMCETestUIEngineCmdRingingSession.h"
       
    47 #include "TMCETestUIEngineCmdDeleteSession.h"
       
    48 #include "TMCETestUIEngineCmdFloorControlSession.h"
       
    49 #include "TMCETestUIEngineCmdCryptoHandling.h"
       
    50 
       
    51 #include "TMCETestUIEngineCmdSRReqRes.h"
       
    52 
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CMCETestUIEngineInSession::NewL()
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CMCETestUIEngineInSession* CMCETestUIEngineInSession::NewL(
       
    61             CMCETestUIEngine& aEngine,
       
    62             CMceInSession* aInSession ) 
       
    63     {
       
    64     CMCETestUIEngineInSession* self = 
       
    65         new (ELeave) CMCETestUIEngineInSession( aEngine, aInSession );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop( self );
       
    69     return self;  
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CMCETestUIEngineInSession::CMCETestUIEngineInSession
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CMCETestUIEngineInSession::CMCETestUIEngineInSession(
       
    77             CMCETestUIEngine& aEngine,
       
    78             CMceInSession* aInSession )
       
    79     :CMCETestUIEngineSession( aEngine, ENotSpesified, EVideoNotSpesified),
       
    80      iInSession( aInSession ),
       
    81      iId( 0 )
       
    82     {
       
    83     }
       
    84      
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMCETestUIEngineInSession::ConstructL()
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CMCETestUIEngineInSession::ConstructL()
       
    91     {
       
    92     User::LeaveIfError( iInSession ? KErrNone : KErrArgument );
       
    93     
       
    94     BaseConstructL();
       
    95     
       
    96 	if(iEngine.IsFCSession()) 
       
    97 		{
       
    98 		TRAP_IGNORE(iEngine.FloorControl().InitializeL(
       
    99 										*iInSession,0, iEngine.MMObserver()));	
       
   100 		}
       
   101     iSession = iInSession;
       
   102     
       
   103     if( iEngine.iSdp )
       
   104         {
       
   105         CDesC8Array* array = new (ELeave) CDesC8ArrayFlat(2);
       
   106 	    array->AppendL(_L8("a=IncomingSession1:20\r\n"));
       
   107         array->AppendL(_L8("a=IncomingSession2:40\r\n"));
       
   108 	    iInSession->SetSessionSDPLinesL( array );
       
   109 	    AddSdpToStreamsL( iInSession );
       
   110         }
       
   111         
       
   112     AdjustRectSize(iInSession); // Main rect adjusted
       
   113     SolveDirection();
       
   114     SolveVideoDirection();
       
   115     SetAudioRouting( iInSession );
       
   116             
       
   117     UpdateVideoParametersL( iInSession ); // Possibly secondary rect adjusted
       
   118      
       
   119     // Get identity
       
   120     iId = iEngine.NextInSessionId();
       
   121     iType = KMceInSession;
       
   122    
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMCETestUIEngineInSession::AdjustRectSize
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CMCETestUIEngineInSession::AdjustRectSize(CMceInSession* aSession)
       
   130 	{
       
   131 	const RPointerArray<CMceMediaStream>& streams = aSession->Streams();
       
   132 
       
   133     if ( streams.Count() == 0 )
       
   134         {
       
   135         User::Leave( KErrNoMemory );
       
   136         }
       
   137 	for ( TInt i = 0; i < streams.Count(); ++i )
       
   138 		{
       
   139 		CDesC8Array* array = new (ELeave) CDesC8ArrayFlat(2);
       
   140 		CMceMediaStream* mediaStream = 
       
   141                                     static_cast<CMceMediaStream*>(streams[i]);
       
   142                                     
       
   143         const RPointerArray<CMceMediaSink>& sinks = streams[i]->Sinks();
       
   144         
       
   145         for ( TInt j = 0; j < sinks.Count(); ++j )
       
   146         	{	
       
   147 	        	if( sinks[j]->Type() == KMceDisplaySink  )
       
   148 	            {
       
   149 	            CMceDisplaySink* dispSink = static_cast<CMceDisplaySink*>(sinks[j]);
       
   150 	           // TRect rect(iEngine.GetRect());
       
   151 	            TRect rect(32, 88, 208, 232);
       
   152 	            AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
       
   153 	           	dispSink->SetDisplayRectL(rect);
       
   154 	            }
       
   155         	}
       
   156         
       
   157          }
       
   158 	}
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CMCETestUIEngineInSession::UpdateVideoParametersL
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CMCETestUIEngineInSession::UpdateVideoParametersL(CMceInSession* aSession)
       
   166     {
       
   167     if ( iVideoDirection == EVideoSendRecv )
       
   168 	    {
       
   169 	    CMceCameraSource* cameraSource = NULL;
       
   170 	    const RPointerArray<CMceMediaStream>& streams = aSession->Streams(); 
       
   171         for ( TInt j = 0; j < streams.Count() && !cameraSource; ++j )
       
   172         	{
       
   173         	CMceMediaStream* cameraStream = FindStreamForSourceL( *streams[ j ], KMceCameraSource );
       
   174         	
       
   175         	if ( cameraStream )
       
   176         	    {
       
   177         	    cameraSource = static_cast<CMceCameraSource*>( cameraStream->Source() );
       
   178         	    } 
       
   179         	}
       
   180             	
       
   181 	    if ( iEngine.iInSessionSettings.iCameraSetting == TSessionParams::EMceCameraSecondary &&
       
   182 	         cameraSource )
       
   183 	        {
       
   184 	        if ( cameraSource->CamerasAvailable() > 1 )
       
   185 	            {
       
   186 	            cameraSource->SetCameraIndexL( 1 );
       
   187 	            }
       
   188 	        }
       
   189 	        
       
   190 	    if ( iEngine.iInSessionSettings.videoSinkDisplay == TSessionParams::EMceViewFinderEnabled &&
       
   191 	         cameraSource )
       
   192 	        {
       
   193 	        CMceVideoStream* videoLocalStream = CMceVideoStream::NewL();
       
   194             CleanupStack::PushL( videoLocalStream );
       
   195             CMceDisplaySink* localDispSink = CMceDisplaySink::NewLC( iEngine.MCEManager() );
       
   196         
       
   197             TRect localDisplayRect(0, 0, 36, 44);
       
   198             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, localDisplayRect );
       
   199             localDispSink->SetDisplayRectL( localDisplayRect );
       
   200             localDispSink->SetPriorityL( ECoeWinPriorityAlwaysAtFront );
       
   201         	videoLocalStream->AddSinkL( localDispSink );
       
   202         	CleanupStack::Pop( localDispSink );
       
   203         	
       
   204         	videoLocalStream->SetSourceL( cameraSource );
       
   205         	
       
   206         	aSession->AddStreamL( videoLocalStream );
       
   207         	CleanupStack::Pop( videoLocalStream );
       
   208 	        }
       
   209 	    }
       
   210     
       
   211     if ( iVideoDirection == EVideoSendRecv || iVideoDirection == EVideoSendOnly )
       
   212         {
       
   213         const RPointerArray<CMceMediaStream>& streams = aSession->Streams();
       
   214         for ( TInt k = 0; k < streams.Count(); k++ )
       
   215             {
       
   216            	CMceMediaStream* cameraStream = FindStreamForSourceL( *streams[ k ], KMceCameraSource );
       
   217            	if ( cameraStream )
       
   218            	    {
       
   219            	    CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( cameraStream );
       
   220            	    AdjustVideoCodecsL( videoStream->Codecs() );
       
   221            	    }
       
   222             }
       
   223         }
       
   224     }
       
   225     
       
   226 // -----------------------------------------------------------------------------
       
   227 // CMCETestUIEngineInSession::AddSdpToStreamsL
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CMCETestUIEngineInSession::SetAudioRouting(CMceInSession* aSession)
       
   231 	{
       
   232 	const RPointerArray<CMceMediaStream>& streams = aSession->Streams();
       
   233 
       
   234     if ( streams.Count() == 0 )
       
   235         {
       
   236         User::Leave( KErrNoMemory );
       
   237         }
       
   238 	for ( TInt i = 0; i < streams.Count(); ++i )
       
   239 		{
       
   240 		CMceMediaStream* mediaStream = 
       
   241                                     static_cast<CMceMediaStream*>(streams[i]);
       
   242         
       
   243         if( mediaStream->Sinks()[0]->Type() == KMceSpeakerSink  )
       
   244             {
       
   245             CMceSpeakerSink* speakerSink = ( CMceSpeakerSink* ) mediaStream->Sinks()[0];
       
   246             speakerSink->SetRoutingL( KMceAudioRoutePrivate );
       
   247             }
       
   248 
       
   249         if( mediaStream->BoundStream() )
       
   250             {
       
   251             CMceMediaStream* boundStream = &mediaStream->BoundStreamL();
       
   252             if( boundStream->Sinks()[0]->Type() == KMceSpeakerSink  )
       
   253                 {
       
   254                 CMceSpeakerSink* speakerSink = ( CMceSpeakerSink* ) boundStream->Sinks()[0];
       
   255                 speakerSink->SetRoutingL( KMceAudioRoutePrivate );
       
   256               
       
   257                 }
       
   258 
       
   259             }
       
   260 		}
       
   261     }
       
   262     
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMCETestUIEngineInSession::AddSdpToStreamsL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void CMCETestUIEngineInSession::AddSdpToStreamsL(CMceInSession* aSession)
       
   268 	{
       
   269 	const RPointerArray<CMceMediaStream>& streams = aSession->Streams();
       
   270 
       
   271     if ( streams.Count() == 0 )
       
   272         {
       
   273         User::Leave( KErrNoMemory );
       
   274         }
       
   275 	for ( TInt i = 0; i < streams.Count(); ++i )
       
   276 		{
       
   277 		CDesC8Array* array = new (ELeave) CDesC8ArrayFlat(2);
       
   278 		CMceMediaStream* mediaStream = 
       
   279                                     static_cast<CMceMediaStream*>(streams[i]);
       
   280         
       
   281         if( mediaStream->Source()->Type() == KMceRTPSource  )
       
   282             {
       
   283             array->AppendL(_L8("a=IncomingStream1DL:20\r\n"));
       
   284             array->AppendL(_L8("a=MainStream:40\r\n"));
       
   285             }
       
   286         else
       
   287             {
       
   288             array->AppendL(_L8("a=IncomingStream1UL:20\r\n"));
       
   289             array->AppendL(_L8("a=MainStream:40\r\n"));
       
   290             }
       
   291             
       
   292         mediaStream->SetMediaAttributeLinesL( array );    
       
   293         
       
   294         CDesC8Array* array2 = new (ELeave) CDesC8ArrayFlat(2);
       
   295         
       
   296         if( mediaStream->BoundStream() )
       
   297             {
       
   298             CMceMediaStream* boundStream = &mediaStream->BoundStreamL();
       
   299             if( boundStream->Source()->Type() == KMceRTPSource  )
       
   300                 {
       
   301                 array2->AppendL(_L8("a=IncomingStream1DL:20\r\n"));
       
   302                 array2->AppendL(_L8("a=BoundStream:40\r\n"));
       
   303                 }
       
   304             else
       
   305                 {
       
   306                 array2->AppendL(_L8("a=IncomingStream1UL:20\r\n"));
       
   307                 array2->AppendL(_L8("a=BoundStream:40\r\n"));
       
   308                 }
       
   309             boundStream->SetMediaAttributeLinesL( array2 ); 
       
   310             }
       
   311       	}
       
   312     }
       
   313     
       
   314     
       
   315     
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CMCETestUIEngineInSession::~CMCETestUIEngineInSession
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 EXPORT_C CMCETestUIEngineInSession::~CMCETestUIEngineInSession()
       
   322     {
       
   323     delete iInSession;
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CMCETestUIEngineInSession::GetCommands
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 const RPointerArray<TMCETestUIEngineCmdBase>& 
       
   331             CMCETestUIEngineInSession::GetCommandsL()
       
   332     {
       
   333     iCommands.ResetAndDestroy();
       
   334 
       
   335     // Get base class commands
       
   336     CMCETestUIEngineSession::GetCommandsL();
       
   337 
       
   338     // Get own commands
       
   339     TInt state = iInSession->State();
       
   340 
       
   341 	switch( state ) 
       
   342 		{
       
   343 		case CMceSession::EIncoming: 
       
   344 		    {
       
   345 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdRejectSession( 
       
   346                                 iEngine, *this ) );	
       
   347             iCommands.Append( new (ELeave) TMCETestUIEngineCmdFCSendSession( 
       
   348                                 iEngine, *this ) );
       
   349             iCommands.Append( new (ELeave) 
       
   350 		        TMCETestUIEngineCmdDeleteSession( iEngine, *this ) );  
       
   351 		        
       
   352 		    iCommands.Append( new (ELeave) 
       
   353 		        TMCETestUIEngineCmdSendInfo( iEngine, *this ) );
       
   354 			iCommands.Append( new (ELeave) 
       
   355 		        TMCETestUIEngineCmdDTMFInfo( iEngine, *this ) );
       
   356 		    iCommands.Append( new ( ELeave )
       
   357 		    	TMCETestUIEngineCmdSendInfoResponse( iEngine, *this ) );
       
   358 		        
       
   359 		    if(iSession->Type() == KMceSessionSecure) 
       
   360 		    	{
       
   361 		    	iCommands.Append( new (ELeave) 
       
   362 		        	TMCETestUIEngineCmdCurrentCryptoContext( iEngine, *this ) );
       
   363 		        iCommands.Append( new (ELeave) 
       
   364 		        	TMCETestUIEngineCmdSupportedCryptoContext( iEngine, *this ) );
       
   365 		        iCommands.Append( new (ELeave) 
       
   366 		        	TMCETestUIEngineCmdSetCryptoContext( iEngine, *this ) );
       
   367 		     	}                 	            
       
   368 		    break;
       
   369 		    }
       
   370 		case CMceSession::EProceeding:
       
   371 		    {
       
   372 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdAcceptSession( 
       
   373                                 iEngine, *this ) );
       
   374 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdRejectSession( 
       
   375                                 iEngine, *this ) );	
       
   376 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdRingingSession( 
       
   377                                 iEngine, *this ) );
       
   378 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdRespondSession( 
       
   379                                 iEngine, *this ) );
       
   380             iCommands.Append( new (ELeave) TMCETestUIEngineCmdFCSendSession( 
       
   381                                 iEngine, *this ) );	    
       
   382 		    iCommands.Append( new (ELeave) 
       
   383 		        TMCETestUIEngineCmdDeleteSession( iEngine, *this ) ); 
       
   384 
       
   385 		    iCommands.Append( new (ELeave) 
       
   386 		        TMCETestUIEngineCmdSendInfo( iEngine, *this ) );
       
   387 			iCommands.Append( new (ELeave) 
       
   388 		        TMCETestUIEngineCmdDTMFInfo( iEngine, *this ) );
       
   389 		    iCommands.Append( new ( ELeave )
       
   390 		    	TMCETestUIEngineCmdSendInfoResponse( iEngine, *this ) );
       
   391 
       
   392 
       
   393 		    if(iSession->Type() == KMceSessionSecure) 
       
   394 		    	{
       
   395 		    	iCommands.Append( new (ELeave) 
       
   396 		        	TMCETestUIEngineCmdCurrentCryptoContext( iEngine, *this ) );
       
   397 		        iCommands.Append( new (ELeave) 
       
   398 		        	TMCETestUIEngineCmdSupportedCryptoContext( iEngine, *this ) );
       
   399 		       	}
       
   400 		                        
       
   401             break;
       
   402 		    }
       
   403 		case CMceSession::EOffering: 
       
   404 		    {
       
   405 		    iCommands.Append( new (ELeave) 
       
   406 		        TMCETestUIEngineCmdDeleteSession( iEngine, *this ) );  
       
   407 		        
       
   408 		    iCommands.Append( new (ELeave) 
       
   409 		        TMCETestUIEngineCmdSendInfo( iEngine, *this ) );
       
   410 			iCommands.Append( new (ELeave) 
       
   411 		        TMCETestUIEngineCmdDTMFInfo( iEngine, *this ) );
       
   412 		    iCommands.Append( new ( ELeave )
       
   413 		    	TMCETestUIEngineCmdSendInfoResponse( iEngine, *this ) );
       
   414 		    	
       
   415 		    if(iSession->Type() == KMceSessionSecure) 
       
   416 		    	{
       
   417 		    	iCommands.Append( new (ELeave) 
       
   418 		        	TMCETestUIEngineCmdCurrentCryptoContext( iEngine, *this ) );
       
   419 		        iCommands.Append( new (ELeave) 
       
   420 		        	TMCETestUIEngineCmdSupportedCryptoContext( iEngine, *this ) );
       
   421 		       	}
       
   422 		                                
       
   423 		    break;	
       
   424 		    }
       
   425 	    case CMceSession::EEstablished:
       
   426 			{
       
   427 			if(VideoDirection() != EVideoNotSpesified)    
       
   428 		    	{
       
   429 		    	if(iEngine.IsVideoEnabled())
       
   430 		    	{
       
   431 		    	iCommands.Append( new (ELeave) 
       
   432 		        TMCETestUIEngineCmdDisableReceivingVideoSession( iEngine, *this ) );
       
   433 		    	}
       
   434 		    	else
       
   435 		    	{
       
   436 		    	iCommands.Append( new (ELeave) 
       
   437 		        TMCETestUIEngineCmdEnableReceivingVideoSession( iEngine, *this ) );     		        
       
   438 		    	}
       
   439 		    	}
       
   440 			break;
       
   441 			}
       
   442 		default:
       
   443 		    {		     
       
   444 		    break;
       
   445 		    }
       
   446 		}  
       
   447 		  
       
   448     return iCommands; 
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CMCETestUIEngineInSession::Id
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 EXPORT_C TInt CMCETestUIEngineInSession::Id() const
       
   456     {
       
   457     return iId;
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CMCETestUIEngineInSession::InSession
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 CMceInSession& CMCETestUIEngineInSession::InSession()
       
   465     {
       
   466     return *iInSession;
       
   467     }
       
   468 
       
   469 
       
   470