multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesdpsession.cpp
branchrcs
changeset 49 64c62431ac08
parent 22 b6d70b04aa2d
equal deleted inserted replaced
44:fb024d5e35fa 49:64c62431ac08
    30 #include <sdpattributefield.h>
    30 #include <sdpattributefield.h>
    31 #include <sdpcodecstringpool.h>
    31 #include <sdpcodecstringpool.h>
    32 #include <sdpdocument.h>
    32 #include <sdpdocument.h>
    33 #include <sdpbandwidthfield.h>
    33 #include <sdpbandwidthfield.h>
    34 #include <siptoheader.h>
    34 #include <siptoheader.h>
    35 
    35 #include <mcemessagestream.h>
       
    36 #include <mcemsrpsource.h>
       
    37 #include <mcemsrpsink.h>
       
    38 
       
    39 #include <mcedefs.h>
       
    40 #include <mcemessagestream.h>
       
    41 #include "mcemessagesdpcodec.h"
       
    42 #include "mcecommsrpsink.h"
    36 #include "mcemediadefs.h"
    43 #include "mcemediadefs.h"
    37 #include "mcesdpsession.h"
    44 #include "mcesdpsession.h"
    38 #include "mcecomsession.h"
    45 #include "mcecomsession.h"
    39 #include "mcecommediastream.h"
    46 #include "mcecommediastream.h"
    40 #include "mcemediastream.h"
    47 #include "mcemediastream.h"
    44 #include "mcesrvlogs.h"
    51 #include "mcesrvlogs.h"
    45 #include "mcemmlogs.h"
    52 #include "mcemmlogs.h"
    46 #include "mcepreconditions.h"
    53 #include "mcepreconditions.h"
    47 #include "mcemediaobserver.h"
    54 #include "mcemediaobserver.h"
    48 #include "mcemediastate.h"
    55 #include "mcemediastate.h"
       
    56 #include "mcecommessagestream.h"
       
    57 #include "mcecommsrpsource.h"
    49 
    58 
    50 
    59 
    51 _LIT8(KTBCP, "TBCP"); 
    60 _LIT8(KTBCP, "TBCP"); 
    52 
    61 
    53 // ================= MEMBER FUNCTIONS ==========================================
    62 // ================= MEMBER FUNCTIONS ==========================================
   132         }
   141         }
   133     if ( Backup() )
   142     if ( Backup() )
   134         {
   143         {
   135         Backup()->DetachSDPSession();
   144         Backup()->DetachSDPSession();
   136         }
   145         }
       
   146     iProtocol.Close();
       
   147     iProtocolTls.Close();
   137     }
   148     }
   138 
   149 
   139 // -----------------------------------------------------------------------------
   150 // -----------------------------------------------------------------------------
   140 // CMceSdpSession::Manager
   151 // CMceSdpSession::Manager
   141 // -----------------------------------------------------------------------------
   152 // -----------------------------------------------------------------------------
   163     CMceSdpSession::TOfferType aType )
   174     CMceSdpSession::TOfferType aType )
   164     {
   175     {
   165     MCEMM_DEBUG("CMceSdpSession::CreateOfferL(), Entry ")
   176     MCEMM_DEBUG("CMceSdpSession::CreateOfferL(), Entry ")
   166     
   177     
   167     CSdpDocument* sdpDocument = NULL;
   178     CSdpDocument* sdpDocument = NULL;
   168 
   179     TBuf8<256> tempMsrpPath;
   169     if ( aType == CMceSdpSession::ERefresh )
   180     if ( aType == CMceSdpSession::ERefresh )
   170         {
   181         {
   171         User::LeaveIfNull( iSdpDocument );
   182         User::LeaveIfNull( iSdpDocument );
   172         EncodeSessionParamsL( aSession, *iSdpDocument, aType );
   183         EncodeSessionParamsL( aSession, *iSdpDocument, aType );
   173         if(iOldLocalMediaPort != iSdpDocument->MediaFields()[0]->Port())
   184         if(iOldLocalMediaPort != iSdpDocument->MediaFields()[0]->Port())
   205 	    }
   216 	    }
   206     
   217     
   207     for ( TInt index = 0; index < streams.Count(); index++ )
   218     for ( TInt index = 0; index < streams.Count(); index++ )
   208         {
   219         {
   209         mediastream = streams[ index ];
   220         mediastream = streams[ index ];
       
   221         
       
   222         if(streams.Count() == 2 && mediastream->iType == KMceMessage) 
       
   223         { 
       
   224             if (mediastream->iStreamType == CMceComMediaStream::ESendOnlyStream && (mediastream->iLocalMsrpPath.Length()))
       
   225                 {
       
   226                 tempMsrpPath = mediastream->iLocalMsrpPath;
       
   227                 //mediastream->iLocalMsrpPath.Zero();
       
   228                 }
       
   229             else if(mediastream->iStreamType == CMceComMediaStream::EReceiveOnlyStream && !(mediastream->iLocalMsrpPath.Length()))
       
   230                 {
       
   231                 mediastream->iLocalMsrpPath = tempMsrpPath;
       
   232                 }
       
   233         }
       
   234         
   210         TBool add = MediaLineLC( mediaLine, sdpCodec, mediastream,
   235         TBool add = MediaLineLC( mediaLine, sdpCodec, mediastream,
   211                                  mediaLines, streams );
   236                                  mediaLines, streams );
   212         if ( mediaLine )
   237         if ( mediaLine )
   213         	{
   238         	{
   214         	
   239         	
   216                 {
   241                 {
   217                 mediaLine->SetPortL( mediastream->iLocalMediaPort );
   242                 mediaLine->SetPortL( mediastream->iLocalMediaPort );
   218                 }
   243                 }
   219             mediastream = mediastream->OfferStream();//downlink
   244             mediastream = mediastream->OfferStream();//downlink
   220             sdpCodec->PrepareForEncodeL( *mediastream, *mediaLine );
   245             sdpCodec->PrepareForEncodeL( *mediastream, *mediaLine );
       
   246             
       
   247             if (mediastream->iType == KMceMessage)
       
   248                 {                
       
   249                 CMceMessageSdpCodec* codec = static_cast<CMceMessageSdpCodec* >(sdpCodec);
       
   250                 codec->EncodeMessageMediaAttributesL(reinterpret_cast<CMceComMessageStream&>(*mediastream), 
       
   251                         *mediaLine);           
       
   252                 }
       
   253             
   221             sdpCodec->EncodeMediaOfferL( *mediastream, *mediaLine, *sdpDocument );
   254             sdpCodec->EncodeMediaOfferL( *mediastream, *mediaLine, *sdpDocument );
   222             if ( add )
   255             if ( add )
   223                 {
   256                 {
   224                 mediaLines.AppendL( mediaLine );
   257                 mediaLines.AppendL( mediaLine );
   225                 CleanupStack::Pop( mediaLine );
   258                 CleanupStack::Pop( mediaLine );
   403 	                    	}
   436 	                    	}
   404 	                    mediastream->DecodedL( KMceRoleOfferer );
   437 	                    mediastream->DecodedL( KMceRoleOfferer );
   405 	                    }
   438 	                    }
   406 	                else //rejected
   439 	                else //rejected
   407 	                    {
   440 	                    {
       
   441 			    		mediastream->SetLocalMediaPort(0);
   408 	                    mediastream->SetDirection( SdpCodecStringConstants::EAttributeInactive );
   442 	                    mediastream->SetDirection( SdpCodecStringConstants::EAttributeInactive );
   409 	                    mediastream->SdpIndex() = KErrNotFound;
   443 	                    mediastream->SdpIndex() = KErrNotFound;
   410 	                    }
   444 	                    }
   411 					}
   445 					}
   412                 }
   446                 }
   677             if ( mediaLine )
   711             if ( mediaLine )
   678                 {
   712                 {
   679                 mediastream = mediastream->OfferStream();//downlink
   713                 mediastream = mediastream->OfferStream();//downlink
   680                 sdpCodec->PrepareForEncodeL( *mediastream, *mediaLine );
   714                 sdpCodec->PrepareForEncodeL( *mediastream, *mediaLine );
   681                 PrepareForAnswerEncodeL( *mediaLine );
   715                 PrepareForAnswerEncodeL( *mediaLine );
       
   716 
       
   717 		  // encode the message specific attributes to the m-line 
       
   718 		  if (mediastream->iType  == KMceMessage)
       
   719 		  	{
       
   720 		  	static_cast<CMceMessageSdpCodec*>(sdpCodec)->EncodeMessageMediaAttributesL(
       
   721 		  	        static_cast<CMceComMessageStream&>(*mediastream), *mediaLine);
       
   722 		  	}
       
   723 		  
   682                 sdpCodec->EncodeMediaAnswerL( *mediastream, *mediaLine, *iSdpDocument );
   724                 sdpCodec->EncodeMediaAnswerL( *mediastream, *mediaLine, *iSdpDocument );
   683                 }
   725                 }
   684             }
   726             }
   685         //reject removed streams
   727         //reject removed streams
   686         //ignore the Supported File Stream will be handled by other plugin
   728         //ignore the Supported File Stream will be handled by other plugin
   737 // -----------------------------------------------------------------------------
   779 // -----------------------------------------------------------------------------
   738 // CMceSdpSession::CreateMediaLineLC
   780 // CMceSdpSession::CreateMediaLineLC
   739 // -----------------------------------------------------------------------------
   781 // -----------------------------------------------------------------------------
   740 //
   782 //
   741 CSdpMediaField* CMceSdpSession::CreateMediaLineLC( 
   783 CSdpMediaField* CMceSdpSession::CreateMediaLineLC( 
   742     CMceComMediaStream& aStream ) const
   784     CMceComMediaStream& aStream ) 
   743     {
   785     {
       
   786     MCEMM_DEBUG("CMceSdpSession::CreateMediaLineLC")
   744     RStringF protocol = SDP_STRING( SdpCodecStringConstants::EProtocolRtpAvp );
   787     RStringF protocol = SDP_STRING( SdpCodecStringConstants::EProtocolRtpAvp );
   745         
   788     
       
   789     if (aStream.iType == KMceMessage)
       
   790         {
       
   791         TBool Secureconn = EFalse;
       
   792         if (aStream.Source()->iType != KMceMSRPSource)
       
   793             {
       
   794             RPointerArray<CMceComMediaSink>& sinks = aStream.Sinks();
       
   795             __ASSERT_ALWAYS(sinks.Count(), User::Leave(KErrArgument));
       
   796             for (TInt i=0; i< sinks.Count(); i++)
       
   797                 {
       
   798                 if (sinks[i]->iType == KMceMSRPSink)
       
   799                     Secureconn = (reinterpret_cast<CMceComMsrpSink* >(sinks[i])->iSecureConnection);
       
   800                 }
       
   801         	}
       
   802 		else
       
   803 			{ // for Receive streams
       
   804 			CMceComMsrpSource* source = static_cast<CMceComMsrpSource*> (aStream.Source());
       
   805 			__ASSERT_ALWAYS(source!=NULL, User::Leave(KErrArgument));
       
   806 			if (source ->iType == KMceMSRPSource)
       
   807 			    Secureconn = (static_cast<CMceComMsrpSource*>(source)->iSecureConnection);			
       
   808 			}
       
   809         	
       
   810           if (!Secureconn)
       
   811                 {
       
   812                 // Make MSRP/TCP as a default protocol for message sessions
       
   813                 //iProtocol = iStringPool.OpenFStringL(KMceSDPMsrpTcp);
       
   814                 if ( iProtocol.DesC().Length() == 0)
       
   815                     {
       
   816                     iProtocol = SdpCodecStringPool::StringPoolL().OpenFStringL(KMceSDPMsrpTcp);                    
       
   817                     }
       
   818                 protocol = iProtocol;
       
   819                 }
       
   820             else
       
   821                 {
       
   822                 // Make MSRP/TCP as a default protocol for message sessions
       
   823                 //iProtocol = iStringPool.OpenFStringL(KMceSDPMsrpTls);
       
   824                 if (iProtocolTls.DesC().Length() == 0 )
       
   825                     {
       
   826                     iProtocolTls = SdpCodecStringPool::StringPoolL().
       
   827                                                  OpenFStringL(KMceSDPMsrpTls);                    
       
   828                     }
       
   829                 protocol = iProtocolTls;
       
   830                 }
       
   831           //Parsing Path for Port value
       
   832           TUriParser8 parser;
       
   833           
       
   834           TInt parseValue = parser.Parse(aStream.iLocalMsrpPath); 
       
   835           TBuf8<10> portBuf = parser.Extract(EUriPort);
       
   836           TBuf16<10> portBuf16;
       
   837           portBuf16.Copy(portBuf);
       
   838           TLex iLex(portBuf16);
       
   839 
       
   840           iLex.Val(aStream.iLocalMediaPort);
       
   841             } 
       
   842     
   746     CSdpMediaField* medialine = 
   843     CSdpMediaField* medialine = 
   747             CSdpMediaField::NewLC( Manager().SdpCodec( aStream )->Media(), 
   844             CSdpMediaField::NewLC( Manager().SdpCodec( aStream )->Media(), 
   748                                    aStream.iLocalMediaPort,
   845                                    aStream.iLocalMediaPort,
   749                                    protocol, 
   846                                    protocol, 
   750                                    KMceSdpNullFormatList );
   847                                    KMceSdpNullFormatList );
   924         
  1021         
   925     // get the remote ip address
  1022     // get the remote ip address
   926     CSdpConnectionField* connfield = aSdpDocument.ConnectionField();
  1023     CSdpConnectionField* connfield = aSdpDocument.ConnectionField();
   927     const TInetAddr* inetAddr = NULL;
  1024     const TInetAddr* inetAddr = NULL;
   928     
  1025     
   929     // find "c-" line from media level
  1026     if( connfield )
   930     TInt index = 0;
       
   931     TBool found = ETrue;
       
   932     while( found && index < mediaLines.Count() )
       
   933         {
       
   934         RPointerArray<CSdpConnectionField>& connfields = 
       
   935                                             mediaLines[index]->ConnectionFields();
       
   936         
       
   937         if ( mediaLines[index++]->Port() > 0 )
       
   938             {
       
   939             TInt cfindex = 0;
       
   940 	        TBool cffound = EFalse;
       
   941 	        while( !cffound && cfindex < connfields.Count() )
       
   942 	            {
       
   943 	            inetAddr = connfields[cfindex++]->InetAddress();
       
   944 	            cffound = MCE_NOT_NULL_PTR( inetAddr );
       
   945 	            }
       
   946 	        found = cffound;
       
   947             }
       
   948         }
       
   949     
       
   950     if( connfield && !found )
       
   951         {
  1027         {
   952 		inetAddr = connfield->InetAddress();
  1028 		inetAddr = connfield->InetAddress();
   953 		if( inetAddr )
  1029 		if( inetAddr )
   954 		    {
  1030 		    {
   955 		    const TInetAddr inetAddress = *(connfield->InetAddress() );
  1031 		    const TInetAddr inetAddress = *(connfield->InetAddress() );
   956 		    // if present, if not then should be media level
  1032 		    // if present, if not then should be media level
   957 		    MCE_SET_REMOTE_IP_ADDR( &aSession, inetAddress );
  1033 		    MCE_SET_REMOTE_IP_ADDR( &aSession, inetAddress );
   958 		    }
  1034 		    }
       
  1035         }
       
  1036     
       
  1037     if ( !inetAddr )
       
  1038         {
       
  1039         TInt index = 0;
       
  1040         TBool found = ETrue;
       
  1041         while( found && index < mediaLines.Count() )
       
  1042             {
       
  1043             RPointerArray<CSdpConnectionField>& connfields = 
       
  1044                                                 mediaLines[index]->ConnectionFields();
       
  1045             
       
  1046             if ( mediaLines[index++]->Port() > 0 )
       
  1047                 {
       
  1048 	            TInt cfindex = 0;
       
  1049 	            TBool cffound = EFalse;
       
  1050 	            while( !cffound && cfindex < connfields.Count() )
       
  1051 	                {
       
  1052 	                inetAddr = connfields[cfindex++]->InetAddress();
       
  1053 	                cffound = MCE_NOT_NULL_PTR( inetAddr );
       
  1054 	                }
       
  1055 	            found = cffound;
       
  1056                 }
       
  1057             }
   959         }
  1058         }
   960         
  1059         
   961     if ( inetAddr )
  1060     if ( inetAddr )
   962         {
  1061         {
   963         MCE_SET_REMOTE_IP_ADDR( &aSession, *inetAddr );
  1062         MCE_SET_REMOTE_IP_ADDR( &aSession, *inetAddr );