multimediacommsengine/tsrc/MCETestUI/MCETestUIEngine/src/TMCETestUIEngineCmdUpdateSession.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:    Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 
       
    23 #include "TMCETestUIEngineCmdUpdateSession.h"
       
    24 #include "CMCETestUIQuestionSingleSelection.h"
       
    25 #include "CMCETestUIQuestionDataQuery.h"
       
    26 #include "CMCETestUIEngineSession.h"
       
    27 #include "CMCETestUIEngineCodec.h"
       
    28 #include "CMCETestUIEngineAudioStream.h"
       
    29 #include "CMCETestUIEngineVideoCodec.h"
       
    30 #include "CMCETestUIEngineVideoStream.h"
       
    31 #include <MCESession.h>
       
    32 #include <MceAudioStream.h>
       
    33 #include <MCEAudioCodec.h>
       
    34 #include <MCEFCMsgExchange.h>
       
    35 #include <MceVideoStream.h>
       
    36 #include <MCEVideoCodec.h>
       
    37 #include <mcertpsource.h>
       
    38 #include <mcemicsource.h>
       
    39 #include <mcespeakersink.h>
       
    40 #include <sipstrings.h> 
       
    41 #include <sipstrconsts.h>
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // TMCETestUIEngineCmdUpdateSession::TMCETestUIEngineCmdUpdateSession
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 TMCETestUIEngineCmdUpdateSession::TMCETestUIEngineCmdUpdateSession( 
       
    49 		            CMCETestUIEngine& aEngine,
       
    50 		            CMCETestUIEngineSession& aSession )
       
    51     : TMCETestUIEngineCmdBase( aEngine ),
       
    52       iSession( aSession )
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // TMCETestUIEngineCmdUpdateSession::ExecuteL
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C void TMCETestUIEngineCmdUpdateSession::ExecuteL()
       
    61 	{
       
    62 	if(iEngine.iMultiCodecSupport == EFalse)
       
    63 		{
       
    64 		DeleteCodecs();	
       
    65 		} // delete this if you want to delete all codecs manually
       
    66 	iSession.Session().UpdateL();
       
    67 	iEngine.EngineStateChangedL();    
       
    68 	}
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // TMCETestUIEngineCmdUpdateSession::Caption
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C const TDesC& TMCETestUIEngineCmdUpdateSession::Caption() const
       
    75 	{
       
    76 	return KCommandCaptionUpdateSession;
       
    77 	}
       
    78 	
       
    79 	
       
    80 EXPORT_C void TMCETestUIEngineCmdUpdateSession:: DeleteCodecs()
       
    81 	{
       
    82 	const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
    83             iSession.AudioStreamsL();
       
    84             
       
    85          for ( TInt i = 0; i < audioStreams.Count(); ++i )
       
    86         	{
       
    87         	 RPointerArray<CMCETestUIEngineCodec>& codecs = 
       
    88             	audioStreams[i]->CodecsL();
       
    89             	TInt count = codecs.Count();
       
    90             //delete all codecs except first one	
       
    91          	for ( TInt j = count-1; j > 0; --j )
       
    92 				{
       
    93 				 audioStreams[i]->AudioStream().RemoveCodecL(codecs[j]->Codec());
       
    94 		         delete codecs[j];
       
    95 		         codecs.Remove( j );
       
    96 		         codecs.Compress();
       
    97 		         iEngine.EngineStateChangedL();
       
    98 		        }
       
    99         	}
       
   100      const RPointerArray<CMCETestUIEngineVideoStream>& videoStreams = 
       
   101             iSession.VideoStreamsL();
       
   102             
       
   103          for ( TInt i = 0; i < videoStreams.Count(); ++i )
       
   104         	{
       
   105         	 RPointerArray<CMCETestUIEngineVideoCodec>& codecs = 
       
   106             	videoStreams[i]->CodecsL();
       
   107             	TInt count = codecs.Count();
       
   108             //delete all codecs except first one	
       
   109          	for ( TInt j = count-1; j > 0; --j )
       
   110 				{
       
   111 				 videoStreams[i]->VideoStream().RemoveCodecL(codecs[j]->Codec());
       
   112 		         delete codecs[j];
       
   113 		         codecs.Remove( j );
       
   114 		         codecs.Compress();
       
   115 		         iEngine.EngineStateChangedL();
       
   116 		        }
       
   117         	}
       
   118 	}
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // TMCETestUIEngineCmdUpdateSessionWithValues::TMCETestUIEngineCmdUpdateSessionWithValues
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TMCETestUIEngineCmdUpdateSessionWithValues::TMCETestUIEngineCmdUpdateSessionWithValues( 
       
   125 		            CMCETestUIEngine& aEngine,
       
   126 		            CMCETestUIEngineSession& aSession )
       
   127     : TMCETestUIEngineCmdBase( aEngine ),
       
   128       iSession( aSession )
       
   129     {
       
   130     }
       
   131     
       
   132 
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // TMCETestUIEngineCmdUpdateSessionWithValues::ExecuteL
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C void TMCETestUIEngineCmdUpdateSessionWithValues::ExecuteL()
       
   140 	{
       
   141 	if(iEngine.iMultiCodecSupport == EFalse)
       
   142 		{
       
   143 		DeleteCodecs();	
       
   144 		} // delete this if you want to delete all codecs manually
       
   145 	if(iEngine.IsFCSession())// for PoC Session update , may be new update can be added for PoC
       
   146 		{
       
   147 	//	iEngine.FloorControl().InitializeL(iSession.Session(),0,iEngine.MMObserver());
       
   148 		CDesC8Array* array = new (ELeave) CDesC8ArrayFlat(1);	
       
   149 		array->AppendL(_L8("a=fmtp:TBCP queuing=0; tb_priority=1; timestamp=0; tb_granted=0; poc_sess_priority=1; poc_lock=0\r\n"));
       
   150 		iEngine.FloorControl().UpdateL(iSession.Session(), array);	
       
   151 	
       
   152 		CDesC8Array* sipHeaders = new ( ELeave ) CDesC8ArrayFlat(1);
       
   153 		CleanupStack::PushL( sipHeaders );	//1
       
   154 	//	sipHeaders->AppendL(_L8("Accept-Contact: *;+mckoppa"));					
       
   155 		CDesC8Array* contHeaders = new ( ELeave ) CDesC8ArrayFlat(1);
       
   156 		CleanupStack::PushL( contHeaders );							// 2
       
   157 		
       
   158 		// empty content type
       
   159 		HBufC8* contentType = HBufC8::NewLC( 1 );					// 3
       
   160 		HBufC8* sdpcontent = HBufC8::NewLC( 1 ); 					// 4
       
   161 		// server - header
       
   162 		sipHeaders->AppendL( (_L8("Server: PoC-client/OMA1.0 Nokia-S60/v1.0")) );
       
   163 		// privacy - header
       
   164 		sipHeaders->AppendL(_L8("Privacy: id;user;header"));
       
   165 		// p-preferred identity header
       
   166 						// 4
       
   167 		sipHeaders->AppendL( (_L8("P-Preferred-Identity: <sip:someone@somewhere.com> ")) );
       
   168 		iSession.Session().UpdateL( 36000, 
       
   169 							  sipHeaders,
       
   170 							  contentType,
       
   171 							  sdpcontent,
       
   172 							  contHeaders );
       
   173 	    CleanupStack::Pop( sdpcontent );
       
   174 	    CleanupStack::Pop( contentType );
       
   175 	    CleanupStack::Pop( contHeaders );
       
   176 	    CleanupStack::Pop( sipHeaders );	
       
   177 		iEngine.EngineStateChangedL();    
       
   178 		}
       
   179 	else
       
   180 		{
       
   181 		TSessionEstablishValues sessionValues;
       
   182     	if(iEngine.SessionEstablishValues( sessionValues))
       
   183     	{
       
   184     	// change the values to the format needed by api 
       
   185     	CDesC8Array* headers;
       
   186     	if(sessionValues.headers.Compare(KNone))
       
   187     		{
       
   188     		CMCETestUIQuestionDataQuery* question = 
       
   189 	    			CMCETestUIQuestionDataQuery::NewLC();
       
   190     		question->SetCaptionL( KUserQuestionInputRecipient );
       
   191 			question->SetDefaultValueL(sessionValues.headers  );
       
   192 			question->SetAnswerL( sessionValues.headers );
       
   193 			TBufC8<100> headersbuffer( question->Answer8() );
       
   194 			CleanupStack::PopAndDestroy( question );
       
   195 			headers = new (ELeave) CDesC8ArrayFlat( 1 );
       
   196 			CleanupStack::PushL( headers );
       
   197 			headers->AppendL( headersbuffer );
       
   198     		}
       
   199     	else
       
   200     		{
       
   201     		headers = new (ELeave) CDesC8ArrayFlat( 1 );
       
   202 			CleanupStack::PushL( headers );
       
   203 		//	headers->AppendL(_L8("Accept-Contact: *;+mckoppa"));
       
   204 		//	headers->AppendL( KAcceptContactMCETestUI );	
       
   205     		}
       
   206     
       
   207 			CleanupStack::Pop( headers );
       
   208 			iSession.Session().SetServiceTypeL(sessionValues.iServiceType);
       
   209 			iSession.Session().UpdateL(sessionValues.timeOut, headers, NULL, NULL, NULL );
       
   210 			iEngine.EngineStateChangedL();
       
   211 	       	}
       
   212 		
       
   213 		}
       
   214  	
       
   215 	}
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // TMCETestUIEngineCmdUpdateSessionWithValues::Caption
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C const TDesC& TMCETestUIEngineCmdUpdateSessionWithValues::Caption() const
       
   222 	{
       
   223 	return KUserQuestionOptionUpdateWithValues;
       
   224 	}
       
   225 
       
   226 
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // TMCETestUIEngineCmdUpdateSessionWithValues::DeleteCodecs
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 
       
   233 EXPORT_C void TMCETestUIEngineCmdUpdateSessionWithValues:: DeleteCodecs()
       
   234 	{
       
   235 	const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
   236             iSession.CurrentAudioStreams();
       
   237             
       
   238          for ( TInt i = 0; i < audioStreams.Count(); ++i )
       
   239         	{
       
   240         	 RPointerArray<CMCETestUIEngineCodec>& codecs = 
       
   241             	audioStreams[i]->CurrentCodecs();
       
   242             //delete all codecs except first one	
       
   243          	for ( TInt j = 1; j < codecs.Count(); ++j )
       
   244 				{
       
   245 				 audioStreams[i]->AudioStream().RemoveCodecL(codecs[j]->Codec());
       
   246 		         delete codecs[j];
       
   247 		         codecs.Remove( j );
       
   248 		         codecs.Compress();
       
   249 		        }
       
   250         	}
       
   251       const RPointerArray<CMCETestUIEngineVideoStream>& videoStreams = 
       
   252             iSession.VideoStreamsL();
       
   253             
       
   254          for ( TInt i = 0; i < videoStreams.Count(); ++i )
       
   255         	{
       
   256         	 RPointerArray<CMCETestUIEngineVideoCodec>& codecs = 
       
   257             	videoStreams[i]->CodecsL();
       
   258             	TInt count = codecs.Count();
       
   259             //delete all codecs except first one	
       
   260          	for ( TInt j = count-1; j > 0; --j )
       
   261 				{
       
   262 				 videoStreams[i]->VideoStream().RemoveCodecL(codecs[j]->Codec());
       
   263 		         delete codecs[j];
       
   264 		         codecs.Remove( j );
       
   265 		         codecs.Compress();
       
   266 		         iEngine.EngineStateChangedL();
       
   267 		        }
       
   268         	}
       
   269 	}
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // TMCETestUIEngineCmdUpdateSession::TMCETestUIEngineCmdUpdateSession
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TMCETestUIEngineCmdHoldCall::TMCETestUIEngineCmdHoldCall( 
       
   281 		            CMCETestUIEngine& aEngine,
       
   282 		            CMCETestUIEngineSession& aSession )
       
   283     : TMCETestUIEngineCmdBase( aEngine ),
       
   284       iSession( aSession )
       
   285     {
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // TMCETestUIEngineCmdUpdateSession::ExecuteL
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 EXPORT_C void TMCETestUIEngineCmdHoldCall::ExecuteL()
       
   293 	{
       
   294 	const RPointerArray<CMceMediaStream>& streams = iSession.Session().Streams();
       
   295 	CMceMediaStream& mainstream = *streams[0];
       
   296 	CMceMediaStream& boundStream = mainstream.BoundStreamL();
       
   297 	
       
   298     if( !iSession.iHold )
       
   299         {
       
   300         HandleLocalHoldingL( mainstream, boundStream );
       
   301         DisableAudioL();
       
   302         iSession.iHold = ETrue;
       
   303         }
       
   304     else
       
   305         {
       
   306         HandleLocalResumingL( mainstream, boundStream );
       
   307         iSession.iHold = EFalse;
       
   308         iSession.iHoldInProgress = ETrue;
       
   309         }
       
   310 
       
   311 	iSession.Session().UpdateL();
       
   312 	iEngine.EngineStateChangedL();    
       
   313 	}
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CSVPHoldMediaHandler::HandleLocalHoldingL - copied from VoIP
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C void TMCETestUIEngineCmdHoldCall::
       
   320 HandleLocalHoldingL( CMceMediaStream& aMediaStream,
       
   321                      CMceMediaStream& aBoundStream )
       
   322     {
       
   323     
       
   324     // In case of local hold RTP source must be disabled
       
   325     if ( KMceRTPSource == aMediaStream.Source()->Type() )
       
   326         {
       
   327         aMediaStream.DisableL();
       
   328         }
       
   329         
       
   330     else if ( KMceRTPSource == aBoundStream.Source()->Type() )
       
   331         {
       
   332         aBoundStream.DisableL();
       
   333         }
       
   334         
       
   335     else
       
   336         {
       
   337         User::Leave( KErrNotFound );
       
   338         }
       
   339         
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // CSVPHoldMediaHandler::DisableAudioL
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 EXPORT_C void TMCETestUIEngineCmdHoldCall::DisableAudioL()
       
   347     {
       
   348     // Disable speaker & microphone
       
   349     CMceSession* session = &iSession.Session();
       
   350     const RPointerArray< CMceMediaStream >& streams = session->Streams();
       
   351     TInt streamCount = streams.Count();
       
   352     for ( TInt i = 0; i < streamCount; i++ )
       
   353         {
       
   354         CMceMediaStream* mediaStream = streams[ i ];
       
   355         TMceMediaType mediaType = mediaStream->Type();
       
   356         if ( KMceAudio == mediaType )
       
   357             {
       
   358             CMceMediaStream& boundStream = mediaStream->BoundStreamL();
       
   359             DisableAudioStreamL( boundStream );
       
   360             DisableAudioStreamL( *mediaStream );
       
   361             }
       
   362         } 
       
   363     }
       
   364  
       
   365 // ---------------------------------------------------------------------------
       
   366 // CSVPHoldMediaHandler::DisableAudioStreamL
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 EXPORT_C void TMCETestUIEngineCmdHoldCall::DisableAudioStreamL( CMceMediaStream& aAudioStream )
       
   370     {
       
   371     if ( aAudioStream.Source() &&
       
   372          KMceMicSource == aAudioStream.Source()->Type() )
       
   373         {
       
   374         CMceMicSource* micSource = 
       
   375                     ( CMceMicSource* ) aAudioStream.Source();
       
   376         if ( micSource->IsEnabled() )
       
   377             {
       
   378             // mute speaker sink
       
   379             micSource->DisableL();
       
   380             }
       
   381         } 
       
   382         
       
   383      if ( aAudioStream.Sinks().Count()  )
       
   384         {
       
   385         const RPointerArray< CMceMediaSink >& sinks = 
       
   386             aAudioStream.Sinks();
       
   387         for ( TInt z = 0; z < sinks.Count(); z++ )
       
   388             {
       
   389             if ( sinks[ z ]->Type() == KMceSpeakerSink )
       
   390                 {
       
   391                 CMceSpeakerSink* speakerSink = 
       
   392                     ( CMceSpeakerSink* )  sinks[ z ];
       
   393                 if ( speakerSink->IsEnabled() )
       
   394                     {
       
   395                     // mute speaker sink
       
   396                     speakerSink->DisableL();                    
       
   397                     }
       
   398                 }
       
   399             } 
       
   400         }                              
       
   401     
       
   402     } 
       
   403     
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CSVPHoldMediaHandler::HandleLocalResumingL
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 EXPORT_C void TMCETestUIEngineCmdHoldCall::
       
   410 HandleLocalResumingL( CMceMediaStream& aMediaStream,
       
   411                       CMceMediaStream& aBoundStream )
       
   412     {
       
   413     if ( !aBoundStream.IsEnabled() )
       
   414         {
       
   415         aBoundStream.EnableL();
       
   416         }
       
   417         
       
   418     if ( !aMediaStream.IsEnabled() )
       
   419         {
       
   420         aMediaStream.EnableL();
       
   421         }
       
   422 
       
   423     }
       
   424 
       
   425 
       
   426 
       
   427 
       
   428     
       
   429       
       
   430 // -----------------------------------------------------------------------------
       
   431 // TMCETestUIEngineCmdUpdateSession::Caption
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 EXPORT_C const TDesC& TMCETestUIEngineCmdHoldCall::Caption() const
       
   435 	{
       
   436 	return KCommandCaptionHoldSession;
       
   437 	}
       
   438 	
       
   439 
       
   440 
       
   441 // End of File