multimediacommsengine/mmcesrv/mmceserver/src/mcefcactionset.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 #include <e32math.h>
       
    21 #include <sdpfmtattributefield.h>
       
    22 #include "mcefcactionset.h"
       
    23 #include "mcesipsession.h"
       
    24 #include "mcesipconnection.h"
       
    25 #include "mcemediamanager.h"
       
    26 #include "mceservercore.h"
       
    27 #include "fcpluginengine.h"
       
    28 #include "mceaudiostream.h"
       
    29 #include "mcertpsource.h"
       
    30 #include "mcecommediasource.h"
       
    31 #include "mceserial.h"
       
    32 #include "mcesrvlogs.h"
       
    33 
       
    34 _LIT8( KFCTBCP, "TBCP" );
       
    35 const TUint32 KPortZero = 0;
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // TMceFCActionSet::TMceFCActionSet
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 TMceFCActionSet::TMceFCActionSet( CMceSipSession& aSession )
       
    42   : iSession ( aSession )
       
    43 	{
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // TMceFCActionSet::UpdateFCOfferL
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void TMceFCActionSet::UpdateFCOfferL( CSdpDocument& aOffer )
       
    51     {
       
    52 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCOfferL, Entry");
       
    53     if ( iSession.FCSession() && iSession.UseFC() )
       
    54     	{
       
    55     	User::LeaveIfError( iSession.Body() ? KErrNone : KErrArgument );
       
    56         User::LeaveIfError( iSession.Body()->Streams().Count() > 0 ? 
       
    57             KErrNone : KErrArgument );
       
    58         
       
    59         CFCPlugInEngine& fc = iSession.ServerCore().FCPluginEngine();
       
    60         
       
    61         if ( !fc.IsReceiverL( *iSession.FCSession() ) )
       
    62             {
       
    63             fc.SetSessionPortL( *iSession.iFCSession, RTCPPort() );
       
    64             }
       
    65        	fc.UpdateOfferL( *iSession.iFCSession, aOffer );    	
       
    66     	}    
       
    67 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCOfferL, Exit");
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // TMceFCActionSet::UpdateFCAnswerL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void TMceFCActionSet::UpdateFCAnswerL( CSdpDocument& aOffer )
       
    75     {
       
    76 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCAnswerL, Entry");
       
    77     if ( iSession.FCSession() && iSession.UseFC() )
       
    78     	{
       
    79     	User::LeaveIfError( iSession.Body() ? KErrNone : KErrArgument );
       
    80         User::LeaveIfError( iSession.Body()->Streams().Count() > 0 ? 
       
    81             KErrNone : KErrArgument );
       
    82         
       
    83     	CFCPlugInEngine& fc = iSession.ServerCore().FCPluginEngine();
       
    84     	
       
    85     	if ( !fc.IsReceiverL( *iSession.FCSession() ) )
       
    86             {
       
    87             fc.SetSessionPortL( *iSession.iFCSession, RTCPPort() );
       
    88             }
       
    89     	fc.UpdateAnswerL( *iSession.iFCSession, aOffer );    	
       
    90     	}    
       
    91 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCAnswerL, Exit");
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // TMceFCActionSet::PeekFCDocumentL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void TMceFCActionSet::PeekFCDocumentL( CSdpDocument& aOffer )
       
    99     {
       
   100 	MCESRV_DEBUG("TMceFCActionSet::PeekFCDocumentL, Entry");
       
   101     if ( iSession.FCSession() )
       
   102     	{
       
   103     	CFCPlugInEngine& fc = iSession.ServerCore().FCPluginEngine();
       
   104     	fc.PeekDocumentL( *iSession.FCSession(), aOffer );    	
       
   105     	}    
       
   106 	MCESRV_DEBUG("TMceFCActionSet::PeekFCDocumentL, Exit");
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // TMceFCActionSet::StartFCL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void TMceFCActionSet::StartFCL()
       
   114     {
       
   115 	MCESRV_DEBUG("TMceFCActionSet::StartFCL, Entry");
       
   116     if ( iSession.FCSession() && iSession.UseFC() )
       
   117     	{
       
   118     	CFCPlugInEngine& fc = iSession.ServerCore().FCPluginEngine();
       
   119     	fc.StartConnectionL( *iSession.FCSession() );    	
       
   120     	}    
       
   121 	MCESRV_DEBUG("TMceFCActionSet::StartFCL, Exit");
       
   122     }
       
   123    
       
   124 // -----------------------------------------------------------------------------
       
   125 // TMceFCActionSet::InitializeFCL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void TMceFCActionSet::InitializeFCL ()
       
   129 	{	
       
   130 	MCESRV_DEBUG("TMceFCActionSet::InitializeFCL, Entry");
       
   131     MCESRV_DEBUG("FC session initalization for incoming INVITE");
       
   132     	
       
   133 	__ASSERT_ALWAYS( !iSession.FCSession(), User::Leave( KErrArgument ) );
       
   134 	                                             
       
   135 	iSession.iFCSession = &(iSession.ServerCore().FCPluginEngine().
       
   136 	    CreateNewSessionL( KFCTBCP, 
       
   137 	                       iSession.SIPConnection().AccessPointId(),
       
   138 	                       KPortZero ) );
       
   139 	
       
   140 	iSession.ServerCore().
       
   141 	    RegisterFCSessionL( iSession, *iSession.FCSession() );
       
   142 	MCESRV_DEBUG("TMceFCActionSet::InitializeFCL, Exit");
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // TMceFCActionSet::InitializeFCL
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void TMceFCActionSet::InitializeFCL (TMceIds& aIds, const TDesC8& aType )
       
   150 	{
       
   151 	MCESRV_DEBUG("TMceFCActionSet::InitializeFCL, Entry");
       
   152 	    
       
   153 	TUint32 port = aIds.Get( KMceIdsIndexFCPort );
       
   154 	
       
   155     MCESRV_DEBUG_DVALUE("FC session initalization with port", port );
       
   156     	
       
   157 	__ASSERT_ALWAYS( !iSession.FCSession(), User::Leave( KErrArgument ) );
       
   158 	    
       
   159     iSession.iFCSession = &(iSession.ServerCore().FCPluginEngine().
       
   160 	    CreateNewSessionL( aType, 
       
   161 	                       iSession.SIPConnection().AccessPointId(),
       
   162 	                       port ) ); 
       
   163 
       
   164 	iSession.ServerCore().
       
   165 	    RegisterFCSessionL( iSession, *iSession.FCSession() );
       
   166 	
       
   167 	MCESRV_DEBUG("TMceFCActionSet::InitializeFCL, Exit");
       
   168 	}
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // TMceFCActionSet::UpdateFC
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void TMceFCActionSet::UpdateFCL( TMceIds& aIds, const TDesC8& /*aType*/ )
       
   175     {
       
   176 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCL, Entry");
       
   177 	
       
   178     TUint32 port = aIds.Get( KMceIdsIndexFCPort );
       
   179     
       
   180 	MCESRV_DEBUG_DVALUE("FC session updating with port", port)
       
   181 		
       
   182 	__ASSERT_ALWAYS( MCE_NOT_NULL_PTR( iSession.FCSession() ) , User::Leave( KErrArgument ) );
       
   183 	iSession.ServerCore().FCPluginEngine().
       
   184 	    UpdateSessionL( *iSession.iFCSession, port );
       
   185 	
       
   186 	MCESRV_DEBUG("TMceFCActionSet::UpdateFCL, Exit");
       
   187 	
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // TMceFCActionSet::Release
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void TMceFCActionSet::ReleaseFC()
       
   195     {
       
   196 	MCE_DEBUG2("TMceFCActionSet::ReleaseFC", "Entry")
       
   197 	MCESRV_DEBUG("TMceFCActionSet::ReleaseFC, Entry");
       
   198 		
       
   199 	if ( iSession.FCSession() )
       
   200 	    {
       
   201     	iSession.ServerCore().FCPluginEngine().
       
   202     	    ReleaseSession( *iSession.iFCSession);
       
   203 
       
   204         iSession.iFCSession = NULL;
       
   205 	    }
       
   206 	MCE_DEBUG2("TMceFCActionSet::ReleaseFC", "Exit")
       
   207 	    
       
   208 	MCESRV_DEBUG("TMceFCActionSet::ReleaseFC, Exit");
       
   209 	
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // TMceFCActionSet::FCGetMediaLinesL
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 HBufC8* TMceFCActionSet::FCGetMediaLinesL()
       
   217 	{		
       
   218 	MCESRV_DEBUG("TMceFCActionSet::FCGetMediaLinesL, Entry");
       
   219 	
       
   220 	HBufC8* returnMessage = NULL;
       
   221 	
       
   222 	RPointerArray<CSdpFmtAttributeField> attribs = iSession.ServerCore().
       
   223 		FCPluginEngine().FormatAttributeFieldsL( *iSession.FCSession() );
       
   224 
       
   225 	CDesC8ArrayFlat* mediaLines = 
       
   226 	    new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   227 	CleanupStack::PushL( mediaLines );
       
   228 	
       
   229 	for ( int i = 0; i < attribs.Count(); i++ )
       
   230 		{
       
   231 		HBufC8* mediaLine = HBufC8::NewLC( KMceSdpMaxMediaLineLength );
       
   232 		TPtr8 mediaLinePtr = mediaLine->Des();
       
   233 		RDesWriteStream writeStream( mediaLinePtr );
       
   234 		writeStream.PushL();
       
   235 
       
   236 		CSdpFmtAttributeField* field = attribs[ i ];
       
   237 		field->EncodeL( writeStream );
       
   238 		
       
   239 		TInt len = writeStream.Sink()->TellL(MStreamBuf::EWrite).Offset();
       
   240 		mediaLine->Des().SetLength( len );
       
   241 		mediaLines->AppendL( mediaLine->Des() );
       
   242 		
       
   243 		CleanupStack::PopAndDestroy();//writeStream
       
   244 		CleanupStack::PopAndDestroy( mediaLine );//mediaLine				
       
   245 		}
       
   246 
       
   247     CMceMsgTextArray* msgLines = new (ELeave) CMceMsgTextArray( *mediaLines );
       
   248     CleanupStack::PushL( msgLines );
       
   249     msgLines->EncodeL();
       
   250     
       
   251     returnMessage = msgLines->EncodeBuffer().Ptr(0).AllocL();
       
   252 
       
   253 	CleanupStack::PopAndDestroy(msgLines); //mediaLines	
       
   254 	CleanupStack::PopAndDestroy(mediaLines); //mediaLines	
       
   255 
       
   256 	MCESRV_DEBUG("TMceFCActionSet::FCGetMediaLinesL, Exit");
       
   257 	
       
   258 	return returnMessage;
       
   259 	
       
   260 	}
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // TMceFCActionSet::FCSetMediaLinesL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void TMceFCActionSet::FCSetMediaLinesL( CMceMsgBase& aMediaLines )
       
   268 	{
       
   269 	MCESRV_DEBUG("TMceFCActionSet::FCSetMediaLinesL, Entry");
       
   270 	
       
   271     CMceMsgTextArray* msgLines = static_cast<CMceMsgTextArray*> (&aMediaLines );
       
   272 
       
   273     RPointerArray<CSdpFmtAttributeField>* attribs = 
       
   274         new (ELeave) RPointerArray<CSdpFmtAttributeField>;
       
   275 	CleanupStack::PushL( TCleanupItem( ArrayCleanup, attribs ) );	
       
   276     for( int i=0;i<msgLines->iArray->Count();i++)
       
   277         {
       
   278         attribs->AppendL( 
       
   279             CSdpFmtAttributeField::DecodeL( msgLines->iArray->MdcaPoint(i) ) );
       
   280         }
       
   281 
       
   282 	iSession.ServerCore().FCPluginEngine().
       
   283 	   SetFormatAttributeFieldsL( *iSession.FCSession(), attribs );
       
   284 	CleanupStack::Pop( attribs ); //attribs
       
   285 	    	
       
   286     msgLines->Close();
       
   287 	
       
   288 	MCESRV_DEBUG("TMceFCActionSet::FCSetMediaLinesL, Exit");
       
   289 	}
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // TMceFCActionSet::SendFCMsgL
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void TMceFCActionSet::SendFCMsgL ( const TDesC8& aMessage )
       
   296     {
       
   297     MCESRV_DEBUG("TMceFCActionSet::SendFCMsgL, Entry");
       
   298     User::LeaveIfError( iSession.FCSession() ? KErrNone : KErrArgument );
       
   299     User::LeaveIfError( iSession.Body() ? KErrNone : KErrArgument );
       
   300     
       
   301     if ( iSession.ServerCore().FCPluginEngine().
       
   302         IsReceiverL( *iSession.FCSession() ) )
       
   303         {
       
   304         // Send using FC subsystem.
       
   305     	HBufC8* sesbuf = aMessage.AllocLC();
       
   306 		
       
   307 	    iSession.ServerCore().FCPluginEngine().SendToNetL( 
       
   308 	                                                *iSession.FCSession(), 
       
   309 	                                                sesbuf );
       
   310         CleanupStack::Pop( sesbuf ); //sesbuf	
       
   311         }
       
   312     else
       
   313         {   
       
   314         CMceMediaManager& mediaManager = iSession.Manager().MediaManager();
       
   315     	CMceComMediaStream* stream = NULL;
       
   316     	// go through streams and possible bound 
       
   317     	// streams and find first uplink stream.
       
   318     	TInt index = 0;
       
   319     	while( !stream && index < iSession.Body()->Streams().Count() )
       
   320             {
       
   321 	        stream = iSession.Body()->Streams()[ index++ ];
       
   322             if ( stream->iType == KMceAudio )
       
   323             	{
       
   324             	stream = stream->SendStream();
       
   325             	}
       
   326             else
       
   327                 {
       
   328                 stream = NULL;
       
   329                 }
       
   330             }
       
   331     
       
   332         if ( stream )
       
   333             {
       
   334             mediaManager.SendRTCPAnyDataL( *stream, aMessage );
       
   335             }
       
   336 	else
       
   337 	    {
       
   338 	    User::Leave( KErrNotSupported );
       
   339 	    }
       
   340 	}
       
   341     MCESRV_DEBUG("TMceFCActionSet::SendFCMsgL, Exit");
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // TMceFCActionSet::NeedToSendOffer
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TBool TMceFCActionSet::NeedToSendOffer()
       
   350     {
       
   351     MCESRV_DEBUG("TMceFCActionSet::NeedToSendOffer, Entry");
       
   352     
       
   353     TBool needToSendOffer = EFalse;
       
   354     const CFCSession* fcSession = iSession.FCSession();
       
   355     
       
   356     //if fc session is not in use fc will return ETrue by default
       
   357     if ( fcSession && iSession.UseFC() )
       
   358 
       
   359         {
       
   360         CFCPlugInEngine& fc = iSession.ServerCore().FCPluginEngine();
       
   361         
       
   362         
       
   363         TRAPD( error, needToSendOffer = fc.UpdateNeededL( *fcSession ) );
       
   364         
       
   365         if ( error != KErrNone )
       
   366             {
       
   367             MCESRV_DEBUG_DVALUE("TMceFCActionSet::NeedToSendOffer, ERROR:", error );
       
   368             needToSendOffer = EFalse;
       
   369             }
       
   370         }
       
   371 	
       
   372 	MCESRV_DEBUG("TMceFCActionSet::NeedToSendOffer, Exit");
       
   373     return needToSendOffer;
       
   374     }
       
   375 
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // TMceFCActionSet::RTCPPort
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 TUint TMceFCActionSet::RTCPPort()
       
   382     {
       
   383     CMceComMediaStream* stream = NULL;
       
   384     if ( iSession.BodyCandidate() )
       
   385         {
       
   386         stream = iSession.BodyCandidate()->Streams()[0];
       
   387         }
       
   388     else
       
   389         {
       
   390         stream = iSession.Body()->Streams()[0];
       
   391         }
       
   392     return stream->iLocalMediaPort + 1;
       
   393     }
       
   394 // -----------------------------------------------------------------------------
       
   395 // TMceFCActionSet::ArrayCleanup
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 void TMceFCActionSet::ArrayCleanup(TAny* aArray)
       
   399 	{
       
   400     RPointerArray<CSdpFmtAttributeField>* array = 
       
   401         reinterpret_cast<RPointerArray<CSdpFmtAttributeField>*>(aArray);
       
   402     if (array)
       
   403         {
       
   404         array->ResetAndDestroy();
       
   405         array->Close();
       
   406         delete array;
       
   407         }
       
   408 	}
       
   409 	
       
   410 
       
   411 // End of File
       
   412