multimediacommsengine/tsrc/MCETestUI/MCETestUIEngine/src/CMCETestUIEngineOutSession_old.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 <MCEOutSession.h>
       
    25 #include <MCEAudioStream.h>
       
    26 #include <MCEAudioStream.h>
       
    27 #include <mcevideostream.h>
       
    28 #include <MCEMicSource.h>
       
    29 #include <MCERtpSink.h>
       
    30 #include <MCERtpSource.h>
       
    31 #include <MCESpeakerSink.h>
       
    32 #include <mcecamerasource.h>
       
    33 #include <mcedisplaysink.h>
       
    34 #include <MCEmediaSink.h>
       
    35 #include <MCEFileSource.h>
       
    36 #include <Uri8.h>
       
    37 #include <mcefilesink.h>
       
    38 #include <MCEAudioCodec.h>
       
    39 #include <MCEVideoCodec.h>
       
    40 #include <MCEAMRCodec.h>
       
    41 #include <MCEFCMsgExchange.h>
       
    42 #include "MCETestUIEngineDefaultValues.h"
       
    43 #include "CMCETestUIQuestionDataQuery.h"
       
    44 #include "CMCETestUIEngine.h"
       
    45 #include "CMCETestUIEngineProfileContainer.h"
       
    46 #include "CMCETestUIEngineProfile.h"
       
    47 #include "CMCETestUIEngineOutSession.h"
       
    48 #include "TMCETestUIEngineCmdEstablish.h"
       
    49 #include "TMCETestUIEngineCmdCancelSession.h"
       
    50 #include "TMCETestUIEngineCmdDeleteSession.h"
       
    51 #include "TMCETestUIEngineCmdFloorControlSession.h"
       
    52 #include "CMCETestUIEngineMultimediaObserver.h"
       
    53 
       
    54 const TUint KAudioPriorityPocAudioUplink                  = 95;
       
    55 const TUint KAudioPriorityPocAudioDownlink                = 95;
       
    56 const TUint KAudioPrefPocAudioUplink                      = 0x05130001;
       
    57 const TUint KAudioPrefPocAudioDownlink                    = 0x05120001;
       
    58 
       
    59 
       
    60 // ============================ MEMBER FUNCTIONS ===============================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMCETestUIEngineOutSession::NewL()
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CMCETestUIEngineOutSession* CMCETestUIEngineOutSession::NewL(
       
    67             CMCETestUIEngine& aEngine,
       
    68             CMCETestUIEngineProfile& aProfile,
       
    69             CMCETestUIEngineOutSession::TDirection aDirection,
       
    70             CMCETestUIEngineOutSession::TVideoDirection aVideoDirection,
       
    71             CMCETestUIEngineOutSession::TSessionType aSessionType ) 
       
    72     {
       
    73 
       
    74     CMCETestUIEngineOutSession* self = 
       
    75         new (ELeave) CMCETestUIEngineOutSession( aEngine, 
       
    76                                                  aProfile,
       
    77                                                  aDirection,
       
    78                                                  aVideoDirection,
       
    79                                                  aSessionType );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop( self );
       
    83     return self;  
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMCETestUIEngineOutSession::CMCETestUIEngineOutSession
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CMCETestUIEngineOutSession::CMCETestUIEngineOutSession( 
       
    91                 CMCETestUIEngine& aEngine,
       
    92                 CMCETestUIEngineProfile& aProfile,
       
    93                 CMCETestUIEngineOutSession::TDirection aDirection,
       
    94                 CMCETestUIEngineOutSession::TVideoDirection aVideoDirection,
       
    95                 CMCETestUIEngineOutSession::TSessionType aSessionType )
       
    96     : CMCETestUIEngineSession( aEngine, aDirection,aVideoDirection ),
       
    97       iProfile( &aProfile ),
       
    98       iId( 0 ),
       
    99       iSessionType(aSessionType)
       
   100     {
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CMCETestUIEngineOutSession::ConstructL()
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CMCETestUIEngineOutSession::ConstructL()
       
   108     {
       
   109  
       
   110      /////////////////////
       
   111     //
       
   112     // TODO: After implementing wrappers for streams, sinks and sources 
       
   113     //       this function should be refactored to make use of them. That will 
       
   114     //       also simplify the function to some extent.
       
   115     //
       
   116     //////////////////////
       
   117     
       
   118  
       
   119     BaseConstructL();
       
   120     FillProfileRegistrar();   
       
   121     FillPoCOrigAddress();
       
   122     if(SessionParamsL(iSessionParams,iSessionType))
       
   123     	{
       
   124     	 // Solve recipient
       
   125 	   CMCETestUIQuestionDataQuery* question = 
       
   126 		    CMCETestUIQuestionDataQuery::NewLC();
       
   127 		    
       
   128 		question->SetCaptionL( KUserQuestionInputRecipient );
       
   129 		question->SetDefaultValueL(iSessionParams.iRecipentAddress  );
       
   130 		question->SetAnswerL( iSessionParams.iRecipentAddress  );
       
   131 		TBufC8<100> recipient( question->Answer8() );
       
   132 		
       
   133 		CleanupStack::PopAndDestroy( question );
       
   134 	  
       
   135 		//////
       
   136 		// solve originator
       
   137 	   
       
   138 	   if ( iSessionParams.originator.Compare(KNone))
       
   139 	   	{
       
   140 		   	HBufC8* orig8 = HBufC8::NewL(iSessionParams.originator.Length());
       
   141 		   	TPtr8 ptr = orig8->Des();
       
   142 		    ptr.Copy(iSessionParams.originator);
       
   143 		    // Create Outsession
       
   144 		    CMceOutSession* outSession = CMceOutSession::NewL(
       
   145 	        iEngine.MCEManager(), 
       
   146 	        iProfile->Profile(),
       
   147 	        recipient ,orig8);
       
   148 	    	CleanupStack::PushL(outSession);
       
   149 	    	
       
   150 	    	    	
       
   151 	        if(iSessionType == EPoCSession)
       
   152 				{
       
   153 			 	FillPoCSessionData(outSession);
       
   154 				}
       
   155 			else if (iSessionType == ECustomSession)
       
   156 				{
       
   157 				FillCustomSessionData(outSession);
       
   158 				}
       
   159 		  
       
   160 			CleanupStack::Pop( outSession );
       
   161 			if(iEngine.IsFCSession()) 
       
   162 				{
       
   163 				TRAP_IGNORE(iEngine.FloorControl().InitializeL(
       
   164 													*outSession,0,iEngine.MMObserver()));
       
   165 				CDesC8Array* array = NULL;
       
   166 				if(iSessionParams.iPoCAdhocSessionType)	
       
   167 					{
       
   168 					array = new (ELeave) CDesC8ArrayFlat(1);	
       
   169 				    array->AppendL(_L8("a=fmtp:TBCP queuing=0; tb_priority=1; timestamp=0; tb_granted=0; poc_sess_priority=0; poc_lock=0\r\n"));
       
   170 				    iEngine.FloorControl().UpdateL(*outSession, array);	
       
   171 					}
       
   172 				else
       
   173 					{
       
   174 					iEngine.FloorControl().UpdateL(*outSession, array);
       
   175 					}
       
   176 				}
       
   177 			iSession = outSession;
       
   178 			iOutSession = outSession;     
       
   179 	   	}
       
   180 	   else 
       
   181 	   	{
       
   182 		    // Create Outsession
       
   183 		    CMceOutSession* outSession = CMceOutSession::NewL(
       
   184 	        iEngine.MCEManager(), 
       
   185 	        iProfile->Profile(),
       
   186 	        recipient );
       
   187 	    	CleanupStack::PushL(outSession);
       
   188 	    
       
   189 		    if(iSessionType == EPoCSession)
       
   190 				{
       
   191 			 	FillPoCSessionData(outSession);
       
   192 				}
       
   193 			else if (iSessionType == ECustomSession)
       
   194 				{
       
   195 				FillCustomSessionData(outSession);
       
   196 				}
       
   197 		  
       
   198 			CleanupStack::Pop( outSession );
       
   199 			if(iEngine.IsFCSession()) 
       
   200 				{
       
   201 				TRAP_IGNORE(iEngine.FloorControl().InitializeL(
       
   202 												*outSession,0,iEngine.MMObserver()));
       
   203 				CDesC8Array* array = new (ELeave) CDesC8ArrayFlat(1);	
       
   204 			    array->AppendL(_L8("a=fmtp:TBCP queuing=0; tb_priority=1; timestamp=0; tb_granted=0; poc_sess_priority=0; poc_lock=0\r\n"));
       
   205 			    iEngine.FloorControl().UpdateL(*outSession, array);	
       
   206 				}
       
   207 			iSession = outSession;
       
   208 			iOutSession = outSession; 
       
   209 	   	}
       
   210 		
       
   211 		    // Get identity
       
   212 	    iId = iEngine.NextOutSessionId();
       
   213     	}
       
   214    
       
   215     }
       
   216 
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CMCETestUIEngineOutSession::~CMCETestUIEngineOutSession
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C CMCETestUIEngineOutSession::~CMCETestUIEngineOutSession()
       
   223     {
       
   224     delete iOutSession;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CMCETestUIEngineOutSession::GetCommands
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 const RPointerArray<TMCETestUIEngineCmdBase>& 
       
   232             CMCETestUIEngineOutSession::GetCommandsL()
       
   233     {
       
   234     iCommands.ResetAndDestroy();
       
   235 
       
   236     // Get base class commands
       
   237     CMCETestUIEngineSession::GetCommandsL();
       
   238         
       
   239     // Get own commands       
       
   240     TInt state = iOutSession->State();
       
   241 
       
   242 	switch( state ) 
       
   243 		{
       
   244 		case CMceSession::EIdle: 
       
   245 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdEstablish( 
       
   246                                 iEngine, *this ) );
       
   247             iCommands.Append( new (ELeave) TMCETestUIEngineCmdEstablishWithValues( 
       
   248                                 iEngine, *this ) );
       
   249             iCommands.Append( new (ELeave) TMCETestUIEngineCmdFCSendSession( 
       
   250                                 iEngine, *this ) );
       
   251                
       
   252             iCommands.Append( new (ELeave) 
       
   253 		        TMCETestUIEngineCmdDeleteSession( iEngine, *this ) );
       
   254 		    break;
       
   255 		case CMceSession::EOffering: 
       
   256 		    iCommands.Append( new (ELeave) TMCETestUIEngineCmdCancelSession( 
       
   257                                 iEngine, *this ) );
       
   258             iCommands.Append( new (ELeave) TMCETestUIEngineCmdFCSendSession( 
       
   259                                 iEngine, *this ) );
       
   260 			iCommands.Append( new (ELeave) 
       
   261 		        TMCETestUIEngineCmdDeleteSession( iEngine, *this ) );                              
       
   262 		    break;
       
   263 		case CMceSession::EEstablished:
       
   264 			if(VideoDirection() != CMCETestUIEngineSession::EVideoNotSpesified)    
       
   265 		    	{
       
   266 		    	if(iEngine.IsVideoEnabled())
       
   267 		    	{
       
   268 		    	iCommands.Append( new (ELeave) 
       
   269 		        TMCETestUIEngineCmdDisableVideoSession( iEngine, *this ) );
       
   270 		    	}
       
   271 		    	else
       
   272 		    	{
       
   273 		    	iCommands.Append( new (ELeave) 
       
   274 		        TMCETestUIEngineCmdEnableVideoSession( iEngine, *this ) );     		        
       
   275 		    	}
       
   276 		    	}
       
   277 		    break;		
       
   278 		default: 
       
   279 		    break;
       
   280 		}  
       
   281 		  
       
   282     return iCommands; 
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CMCETestUIEngineOutSession::Id
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 EXPORT_C TInt CMCETestUIEngineOutSession::Id() const
       
   290     {
       
   291     return iId;
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CMCETestUIEngineOutSession::OutSession
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 CMceOutSession& CMCETestUIEngineOutSession::OutSession()
       
   299     {
       
   300     return *iOutSession;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CMCETestUIEngineOutSession::SessionParams
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 
       
   308 TBool CMCETestUIEngineOutSession::SessionParamsL(TSessionParams &aSessionParams,
       
   309 									CMCETestUIEngineOutSession::TSessionType aSessionType)
       
   310 	{
       
   311   	return iEngine.SessionParamsL( aSessionParams,aSessionType );
       
   312  	}
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CMCETestUIEngineOutSession::FillPoCSessionData
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 
       
   319 void CMCETestUIEngineOutSession::FillProfileRegistrar()
       
   320 	{
       
   321 	// trying to get profile registrar 
       
   322     
       
   323        
       
   324     TUriParser8 parser;
       
   325     const TDesC8& aor = iProfile->Aor();
       
   326     parser.Parse( aor ) ; 
       
   327     CUri8* uri8 = CUri8::NewLC( parser );
       
   328     const TDesC8& registrar =  uri8->Uri().Extract( EUriHost ) ;
       
   329     
       
   330     HBufC*registrar16 = HBufC16::NewLC( KRecipent().Length() + registrar.Length() );
       
   331     TPtr registrarPtr = registrar16->Des();
       
   332     registrarPtr.Copy( registrar );
       
   333     
       
   334     iSessionParams.iRecipentAddress.Append(KRecipent) ;
       
   335     iSessionParams.iRecipentAddress.Append(*registrar16)  ;
       
   336     
       
   337     CleanupStack::PopAndDestroy( registrar16 );
       
   338     registrar16 = NULL;
       
   339     
       
   340     CleanupStack::PopAndDestroy( uri8 );
       
   341     uri8 = NULL; 
       
   342     // profile registrar end .....
       
   343 	}
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CMCETestUIEngineOutSession::FillPoCorigAddress
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 
       
   350 void CMCETestUIEngineOutSession::FillPoCOrigAddress()
       
   351 	{
       
   352  
       
   353     if(iEngine.IsFCSession())
       
   354     	{
       
   355     	const TDesC8& aor = iProfile->Aor();
       
   356     	HBufC*aor16 = HBufC16::NewLC( aor.Length() );
       
   357     	TPtr aorPtr = aor16->Des();
       
   358     	aorPtr.Copy(aor);
       
   359     	iSessionParams.originator.Append(*aor16)  ;
       
   360 	    CleanupStack::PopAndDestroy( aor16 );
       
   361 	    aor16 = NULL;
       
   362 	   	}
       
   363        
       
   364    	}
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CMCETestUIEngineOutSession::FillPoCSessionData
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 
       
   371 void CMCETestUIEngineOutSession::FillPoCSessionData(CMceOutSession* outSession)
       
   372 	{
       
   373 	iDirection = CMCETestUIEngineOutSession::ESendRecv;
       
   374 	const TInt KStartLocalPort = 6688;
       
   375     const TInt AMRDefOfferPTime = 160;
       
   376     
       
   377     // Maximum ptime
       
   378     const TInt AMRDefOfferMaxPTime = 400;
       
   379     
       
   380     // Allowed bitrates
       
   381     const TInt AMRDefOfferAllowedBitrates = KMceAllowedAmrNbBitrate475 | 
       
   382 								  KMceAllowedAmrNbBitrate515 | 
       
   383 								  KMceAllowedAmrNbBitrate590;
       
   384 								  
       
   385     // Bitrate
       
   386     const TInt AMRDefOfferBitrate = KMceAmrNbBitrate515;
       
   387     
       
   388     // Codec mode
       
   389     const TInt AMRDefOfferCodingMode = EMceOctetAligned;
       
   390     
       
   391     
       
   392 	 CMceAudioStream* audioOutStream = NULL;
       
   393 	 	// audio in stream
       
   394 	CMceAudioStream* audioStreamIn = CMceAudioStream::NewLC();
       
   395 
       
   396 	TInt locPort( KStartLocalPort );
       
   397 	locPort = locPort + ( 128 * 2 );
       
   398 	
       
   399 	audioStreamIn->SetLocalMediaPortL( locPort );
       
   400 		
       
   401 	CMceSpeakerSink* speakerSink = CMceSpeakerSink::NewLC();
       
   402 	audioStreamIn->AddSinkL(speakerSink);
       
   403 	CleanupStack::Pop();
       
   404 	
       
   405 	// TODO:
       
   406 	CMceRtpSource* rtpSource = CMceRtpSource::NewLC( 10, 5, 1000 );
       
   407 	audioStreamIn->SetSourceL(rtpSource);
       
   408 	CleanupStack::Pop();	
       
   409 	
       
   410 	CMceAudioStream* audioStreamOut = CMceAudioStream::NewLC();
       
   411 	
       
   412 	CMceRtpSink* rtpSink = CMceRtpSink::NewL( ETrue );
       
   413 	audioStreamOut->AddSinkL(rtpSink);
       
   414 	
       
   415 	CMceMicSource* micSource = CMceMicSource::NewLC();
       
   416 	audioStreamOut->SetSourceL(micSource);
       
   417 	CleanupStack::Pop();	
       
   418 	
       
   419 	audioStreamIn->BindL(audioStreamOut);
       
   420 	CleanupStack::Pop(audioStreamOut);
       
   421 	// floor control
       
   422 
       
   423 	outSession->AddStreamL( audioStreamIn );
       
   424 	CleanupStack::Pop(audioStreamIn);
       
   425 	// 
       
   426 	// TODO: Currently MMComms supports only the first codec of the stream
       
   427 	//
       
   428 	const RPointerArray<CMceAudioCodec>& coddecs =  audioStreamIn->Codecs();
       
   429 	CMceAmrCodec* amrcodec = (CMceAmrCodec*)coddecs[0];
       
   430 	
       
   431 	const RPointerArray<CMceAudioCodec>& coddecsOut =  audioStreamOut->Codecs();
       
   432 	CMceAmrCodec* amrcodecOut = (CMceAmrCodec*)coddecsOut[0];
       
   433 	
       
   434 	
       
   435 	// set prioirity for uplink
       
   436 	amrcodecOut->SetMMFPriorityL( KAudioPriorityPocAudioUplink );
       
   437     amrcodecOut->SetMMFPriorityPreferenceL( KAudioPrefPocAudioUplink );
       
   438     
       
   439 	// set prioirity for downlink
       
   440 	amrcodec->SetMMFPriorityL( KAudioPriorityPocAudioDownlink );
       
   441     amrcodec->SetMMFPriorityPreferenceL( KAudioPrefPocAudioDownlink );
       
   442 	
       
   443 	//
       
   444 	// Set initial parameters for codec
       
   445 	//
       
   446 	// Allowed bitrates
       
   447 	amrcodec->SetAllowedBitrates( AMRDefOfferAllowedBitrates );
       
   448 	
       
   449 	// Bitrate should be 5150
       
   450 	amrcodec->SetBitrate( AMRDefOfferBitrate );
       
   451 
       
   452     // AMR narrow band, sampling rate 8000
       
   453 	amrcodec->SetSamplingFreq( KMceAmrNbSamplingFreq );
       
   454 	
       
   455 	// Use bandwith effient coding
       
   456 	amrcodec->SetCodecMode( AMRDefOfferCodingMode );
       
   457 	
       
   458 	// Default packet ratio is 8 AMR packets per one RTP packet
       
   459 	// -> ptime = 8 * 20 = 160. Lower value is not good with GPRS bearer
       
   460 	amrcodec->SetPTime(AMRDefOfferPTime );
       
   461 	
       
   462 	// Allowable maximum ptime, 400 should be OK
       
   463 	amrcodec->SetMaxPTime( AMRDefOfferMaxPTime );
       
   464 	
       
   465 	// 106 seems to be common payload type
       
   466 	amrcodec->SetPayloadType( 106 );
       
   467 	
       
   468 
       
   469 	// Disabled here due to audio server crash
       
   470 	CMceRtpSink* rtpOutSink = (CMceRtpSink*) audioStreamOut->Sinks()[0];
       
   471 	rtpOutSink->DisableL();
       
   472 	}
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CMCETestUIEngineOutSession::FillCustomSessionData	
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CMCETestUIEngineOutSession::FillCustomSessionData(CMceOutSession* outSession)
       
   479 	{
       
   480 	
       
   481 	// setmodifier for the session, by default preconditions are present, if no preconditions then setthis
       
   482 	if( iSessionParams.iNoPrecondtion) 
       
   483 		{
       
   484 		outSession->SetModifierL(0,0);
       
   485 		}
       
   486 	
       
   487 	switch (iSessionParams.index )
       
   488 	    {
       
   489 	    case 0: 
       
   490 	        iDirection = CMCETestUIEngineOutSession::ESendRecv;
       
   491 	        break;
       
   492 	    case 1: 
       
   493 	        iDirection = CMCETestUIEngineOutSession::ESendOnly;
       
   494 	        break;
       
   495 	    case 2: 
       
   496 	        iDirection = CMCETestUIEngineOutSession::ERecvOnly;
       
   497 	        break;
       
   498 	    default:
       
   499 	        iDirection = CMCETestUIEngineOutSession::ENotSpesified;
       
   500 	        break;
       
   501 	    }
       
   502 	    
       
   503 	    CMceFileSource* fileSource = NULL;
       
   504 	 	if ( iDirection != CMCETestUIEngineOutSession::ENotSpesified )
       
   505 	    {
       
   506 	    // Create outstream (== uplink)
       
   507 	    CMceAudioStream* audioOutStream = NULL;
       
   508 	    
       
   509 	    if ( iDirection == CMCETestUIEngineOutSession::ESendOnly ||  
       
   510 	         iDirection == CMCETestUIEngineOutSession::ESendRecv )
       
   511 	        {
       
   512 	        audioOutStream = CMceAudioStream::NewLC();
       
   513 	        CMceMicSource* mic = NULL;
       
   514 	        
       
   515 			if(iSessionParams.sourceType)
       
   516 				{
       
   517 				fileSource = CMceFileSource::NewL(iEngine.MCEManager(), iSessionParams.sourceFile );
       
   518             	CleanupStack::PushL( fileSource );
       
   519             	audioOutStream->SetSourceL(fileSource);
       
   520             	CleanupStack::Pop();
       
   521 				}
       
   522 			else
       
   523 				{
       
   524 				mic = CMceMicSource::NewLC();
       
   525 				audioOutStream->SetSourceL( mic );	
       
   526 				CleanupStack::Pop( mic );
       
   527 				}
       
   528 			
       
   529 			
       
   530 			CMceRtpSink* rtpSink;
       
   531 			CMceSpeakerSink* speakerSink;
       
   532 			
       
   533 			if(iSessionParams.audioSinkType)			
       
   534 				{
       
   535 				speakerSink = CMceSpeakerSink::NewLC();	
       
   536 				CleanupStack::Pop( speakerSink );
       
   537 				audioOutStream->AddSinkL( speakerSink );
       
   538 				}
       
   539 			else
       
   540 				{
       
   541 				if(iSessionParams.iSuppressRTCP)
       
   542 					{
       
   543 					rtpSink = CMceRtpSink::NewL(ETrue);	
       
   544 					CleanupStack::PushL(rtpSink);
       
   545 					}
       
   546 				else
       
   547 					{
       
   548 					rtpSink = CMceRtpSink::NewLC();	
       
   549 					}
       
   550 				CleanupStack::Pop( rtpSink );
       
   551 				audioOutStream->AddSinkL( rtpSink );
       
   552 				 
       
   553 				}
       
   554 		
       
   555 			
       
   556 			       
       
   557 	        }
       
   558 
       
   559 	    // Create instream (== downlink)
       
   560 	    CMceAudioStream* audioInStream = NULL;
       
   561 	    
       
   562 	    if ( iDirection == CMCETestUIEngineOutSession::ERecvOnly ||
       
   563 	         iDirection == CMCETestUIEngineOutSession::ESendRecv )
       
   564 	        {
       
   565 			audioInStream = CMceAudioStream::NewLC();
       
   566 			
       
   567 			CMceRtpSource* rtpSource = CMceRtpSource::NewLC(KMceJitterBufferLength,KMceJitterBufferTreshold,
       
   568 															20000,0);
       
   569 			audioInStream->SetSourceL( rtpSource );
       
   570 			CleanupStack::Pop( rtpSource );
       
   571 			
       
   572 			CMceSpeakerSink* speaker = CMceSpeakerSink::NewLC();	
       
   573 			audioInStream->AddSinkL( speaker );
       
   574 			CleanupStack::Pop( speaker );
       
   575 	        }
       
   576             
       
   577 	    // Bound streams     
       
   578 	    if ( iDirection == CMCETestUIEngineOutSession::ESendRecv )
       
   579 	        {
       
   580 			audioOutStream->BindL( audioInStream ); 
       
   581 			
       
   582 			if ( audioInStream )
       
   583 			    {
       
   584 			    CleanupStack::Pop( audioInStream );     
       
   585 			    }
       
   586 	        }
       
   587 
       
   588 	    // Add streams to OutSession    
       
   589 	    if ( iDirection != ERecvOnly )
       
   590 	        {
       
   591 	        outSession->AddStreamL( audioOutStream );
       
   592 	        CleanupStack::Pop( audioOutStream );
       
   593 	        
       
   594 	        const RPointerArray<CMceAudioCodec>& codecs =  audioOutStream->Codecs();
       
   595 	        CMceAmrCodec* amrcodec = (CMceAmrCodec*)codecs[0];
       
   596 	     
       
   597 	        // set prioirity for uplink
       
   598 	        amrcodec->SetMMFPriorityL( KAudioPriorityPocAudioUplink );
       
   599             amrcodec->SetMMFPriorityPreferenceL( KAudioPrefPocAudioUplink );
       
   600             
       
   601             if( audioInStream )
       
   602                 {
       
   603                 const RPointerArray<CMceAudioCodec>& codecs =  audioInStream->Codecs();
       
   604     	        CMceAmrCodec* amrcodec = (CMceAmrCodec*)codecs[0];  
       
   605     	        
       
   606     	       	// set prioirity for downlink
       
   607     	        amrcodec->SetMMFPriorityL( KAudioPriorityPocAudioDownlink );
       
   608                 amrcodec->SetMMFPriorityPreferenceL( KAudioPrefPocAudioDownlink );    
       
   609                 }
       
   610 	        }
       
   611 	    else
       
   612 	        {
       
   613 	        outSession->AddStreamL( audioInStream );
       
   614 	        CleanupStack::Pop( audioInStream );
       
   615 	        
       
   616 	        const RPointerArray<CMceAudioCodec>& codecs =  audioInStream->Codecs();
       
   617 	        CMceAmrCodec* amrcodec = (CMceAmrCodec*)codecs[0];  
       
   618 	        
       
   619 	       	// set prioirity for downlink
       
   620 	        amrcodec->SetMMFPriorityL( KAudioPriorityPocAudioDownlink );
       
   621             amrcodec->SetMMFPriorityPreferenceL( KAudioPrefPocAudioDownlink ); 
       
   622 	        }    
       
   623 	    
       
   624 	    } 
       
   625 	  switch (iSessionParams.videoIndex )
       
   626 	    {
       
   627 	    case 0: 
       
   628 	        iVideoDirection = CMCETestUIEngineOutSession::EVideoSendRecv;
       
   629 	        break;
       
   630 	    case 1: 
       
   631 	        iVideoDirection = CMCETestUIEngineOutSession::EVideoSendOnly;
       
   632 	        break;
       
   633 	    case 2: 
       
   634 	        iVideoDirection = CMCETestUIEngineOutSession::EVideoRecvOnly;
       
   635 	        break;
       
   636 	    default:
       
   637 	        iVideoDirection = CMCETestUIEngineOutSession::EVideoNotSpesified;
       
   638 	        break;
       
   639 	    }
       
   640 	 	if ( iVideoDirection != CMCETestUIEngineOutSession::EVideoNotSpesified )
       
   641 	    {
       
   642 	    // Create outstream (== uplink)
       
   643 	    CMceVideoStream* videoOutStreamRTP = NULL;
       
   644 	    CMceVideoStream* videoOutStreamDisplay = NULL;
       
   645 	    CMceVideoStream* videoOutStreamFile = NULL;
       
   646 	    CMceVideoStream* vidStreamLocal = NULL;
       
   647 	    CMceCameraSource* cam =NULL;
       
   648 	    CMceFileSource* videoFileSource = NULL;
       
   649 	    if ( iVideoDirection == CMCETestUIEngineOutSession::EVideoSendOnly ||  
       
   650 	         iVideoDirection == CMCETestUIEngineOutSession::EVideoSendRecv )
       
   651 	        {
       
   652 			CMceRtpSink* rtpSink = NULL;
       
   653 			CMceDisplaySink* dispSink = NULL;
       
   654 			CMceFileSink* fileSink = NULL;
       
   655 			
       
   656 			if(iSessionParams.videoSinkDisplay)
       
   657 				{
       
   658 				dispSink = CMceDisplaySink::NewLC( iEngine.MCEManager());
       
   659 				videoOutStreamDisplay = CMceVideoStream::NewL();
       
   660 				CleanupStack::Pop( dispSink );
       
   661 				CleanupStack::PushL( videoOutStreamDisplay );
       
   662 				videoOutStreamDisplay->AddSinkL( dispSink );
       
   663 				if(iSessionParams.sourceType)
       
   664 					{
       
   665 					videoOutStreamDisplay->SetSourceL( fileSource );
       
   666 					}
       
   667 				else
       
   668 					{
       
   669 					cam = CMceCameraSource::NewL(iEngine.MCEManager());
       
   670 					videoOutStreamDisplay->SetSourceL( cam );	
       
   671 					}
       
   672 				CleanupStack::Pop( videoOutStreamDisplay );
       
   673 				outSession->AddStreamL( videoOutStreamDisplay );
       
   674 				}
       
   675 			
       
   676 			if(iSessionParams.videoSinkFile)
       
   677 				{
       
   678 				fileSink = CMceFileSink::NewLC( iSessionParams.sinkFile);
       
   679 				videoOutStreamFile = CMceVideoStream::NewL();
       
   680 				CleanupStack::Pop( fileSink );
       
   681 				CleanupStack::PushL( videoOutStreamFile );
       
   682 				videoOutStreamFile->AddSinkL( fileSink );
       
   683 				if(iSessionParams.sourceType)
       
   684 					{
       
   685 					videoOutStreamFile->SetSourceL( fileSource );
       
   686 					}
       
   687 				else
       
   688 					{
       
   689 					cam = CMceCameraSource::NewL(iEngine.MCEManager());
       
   690 					videoOutStreamFile->SetSourceL( cam );	
       
   691 					}
       
   692 				CleanupStack::Pop( videoOutStreamFile );
       
   693 				outSession->AddStreamL( videoOutStreamFile );
       
   694 				}
       
   695 			if( iSessionParams.videoSinkRtp ||
       
   696 			    iVideoDirection == CMCETestUIEngineOutSession::EVideoSendRecv )
       
   697 				{
       
   698 				if(iSessionParams.iSuppressRTCP)
       
   699 					{
       
   700 					rtpSink = CMceRtpSink::NewLC(ETrue);	
       
   701 					}
       
   702 				else
       
   703 					{
       
   704 					rtpSink = CMceRtpSink::NewLC();	
       
   705 					}
       
   706 				videoOutStreamRTP = CMceVideoStream::NewL();
       
   707 				CleanupStack::Pop( rtpSink );
       
   708 				CleanupStack::PushL( videoOutStreamRTP );
       
   709 				videoOutStreamRTP->AddSinkL( rtpSink );
       
   710 				if(iSessionParams.sourceType)
       
   711 					{
       
   712 					videoOutStreamRTP->SetSourceL( fileSource );
       
   713 					}
       
   714 				else
       
   715 					{
       
   716 					cam = CMceCameraSource::NewL(iEngine.MCEManager());
       
   717 					videoOutStreamRTP->SetSourceL( cam );	
       
   718 					}
       
   719 				}
       
   720 	
       
   721 		
       
   722 			
       
   723 			if(iSessionParams.videoFileSourceType)
       
   724 				{
       
   725 	/*			vidStreamLocal = CMceVideoStream::NewLC();
       
   726 	        	CMceDisplaySink* dispSink = CMceDisplaySink::NewL( iEngine.MCEManager());
       
   727 	        	CleanupStack::PushL( dispSink );
       
   728 	        	
       
   729 	   
       
   730 	        	TRect viewFinder(0, 83, 352, 378);
       
   731 	        	dispSink->SetDisplayRectL( viewFinder );
       
   732 	   //  		dispSink->DisableL();
       
   733 	        	    
       
   734 	        	vidStreamLocal->AddSinkL(dispSink);
       
   735 	        	CleanupStack::Pop();
       
   736 				// this does not work now , so commented 				
       
   737 	       // 	vidStreamLocal->SetSourceL(videoFileSource);
       
   738 	  */      	}
       
   739 			else
       
   740 				{
       
   741 				vidStreamLocal = CMceVideoStream::NewLC();
       
   742 	        //	CMceDisplaySink* dispSink = CMceDisplaySink::NewL( iEngine.MCEManager());
       
   743 	        //	CleanupStack::PushL( dispSink );
       
   744 	        	
       
   745 	   
       
   746 	        	TRect viewFinder(0, 83, 352, 378);
       
   747 	        	dispSink->SetDisplayRectL( viewFinder );
       
   748 	   //  		dispSink->DisableL();
       
   749 	        	    
       
   750 	        	vidStreamLocal->AddSinkL(dispSink);
       
   751 	        	CleanupStack::Pop();
       
   752 	        	vidStreamLocal->SetSourceL(cam);
       
   753 	        
       
   754 				}
       
   755 		        
       
   756 	        }
       
   757 
       
   758 	    // Create instream (== downlink)
       
   759 	    CMceVideoStream* videoInStreamRTP = NULL;
       
   760 	    
       
   761 	    if ( iVideoDirection == CMCETestUIEngineOutSession::EVideoRecvOnly ||
       
   762 	         iVideoDirection == CMCETestUIEngineOutSession::EVideoSendRecv )
       
   763 	        {
       
   764 			videoInStreamRTP = CMceVideoStream::NewLC();
       
   765 			
       
   766 			CMceRtpSource* rtpSource = CMceRtpSource::NewLC();
       
   767 			videoInStreamRTP->SetSourceL( rtpSource );
       
   768 			CleanupStack::Pop( rtpSource );
       
   769 			
       
   770 			CMceDisplaySink* display = CMceDisplaySink::NewLC(iEngine.MCEManager());	
       
   771 			videoInStreamRTP->AddSinkL( display );
       
   772 			TRect disp(0, 83, 352, 378);
       
   773         	display->SetDisplayRectL( disp );
       
   774         //	display->DisableL();
       
   775 			CleanupStack::Pop( display );
       
   776 	        }
       
   777             
       
   778 	    // Bound streams     
       
   779 	    if ( iVideoDirection == CMCETestUIEngineOutSession::EVideoSendRecv )
       
   780 	        {
       
   781 	        CleanupStack::Pop( videoInStreamRTP );
       
   782 			videoOutStreamRTP->BindL( videoInStreamRTP ); 
       
   783 			outSession->AddStreamL(videoOutStreamRTP);
       
   784 			CleanupStack::Pop( videoOutStreamRTP );
       
   785 	        }
       
   786 	    else if( iVideoDirection == CMCETestUIEngineOutSession::EVideoSendOnly &&
       
   787 	    		 iSessionParams.videoSinkRtp )
       
   788 	    	{
       
   789 	    	outSession->AddStreamL(videoOutStreamRTP);
       
   790 			CleanupStack::Pop( videoOutStreamRTP );
       
   791 	    	}
       
   792 		else
       
   793 			{
       
   794 			outSession->AddStreamL(videoInStreamRTP);
       
   795 			CleanupStack::Pop( videoInStreamRTP );
       
   796 			}
       
   797 	 
       
   798 	 
       
   799 	 
       
   800 	    // Add streams to OutSession    
       
   801 	    if ( iVideoDirection != EVideoRecvOnly )
       
   802 	        {
       
   803 	        outSession->AddStreamL( videoOutStream );
       
   804 	        if( !iSessionParams.videoFileSourceType )
       
   805 	        	{
       
   806 	        	outSession->AddStreamL(vidStreamLocal);
       
   807 				CleanupStack::Pop( vidStreamLocal );
       
   808 	        	}
       
   809 	       	
       
   810 			if(iSessionParams.videoFileSourceType)
       
   811 				{
       
   812 				CleanupStack::Pop( videoFileSource );
       
   813 				}
       
   814 			else
       
   815 				{
       
   816 				CleanupStack::Pop( cam );
       
   817 				}
       
   818 	       
       
   819 	        CleanupStack::Pop( videoOutStream );
       
   820 	        
       
   821 	        }
       
   822 	    else
       
   823 	        {
       
   824 	        outSession->AddStreamL( videoInStream );
       
   825 	        CleanupStack::Pop( videoInStream );     
       
   826 	        }    
       
   827 	    
       
   828 	    }   	    	
       
   829 	}