natplugins/natpnatfwsdpprovider/src/nspmediastream.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Media stream class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sdpconnectionfield.h>
       
    19 #include <sdpmediafield.h>
       
    20 #include "natfwcandidate.h"
       
    21 #include "natfwcandidatepair.h"
       
    22 #include "natfwcredentials.h"
       
    23 #include "nspmediastream.h"
       
    24 #include "nspmediastreamcomponent.h"
       
    25 #include "nspcontentparser.h"
       
    26 #include "nsputil.h"
       
    27 #include "nspcontrollerif.h"
       
    28 #include "nspdefs.h"
       
    29 
       
    30 const TInt KMaxLengthOfFQDN = 255;
       
    31 const TUint KMaxPasswordLength = 100;
       
    32 const TUint KNSPRtpComponentId = 1;
       
    33 const TUint KNSPRtcpComponentId = 2;
       
    34 
       
    35 static void UpdateConnFieldL( CSdpMediaField& aMediaField,
       
    36         const TDes8& aAddress )
       
    37 	{
       
    38 	if ( aMediaField.ConnectionFields().Count() )
       
    39 		{
       
    40 		NSPUtil::UpdateConnectionFieldL( *aMediaField.ConnectionFields()[0],
       
    41 		    aAddress );
       
    42 		}
       
    43 	}
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 // ---------------------------------------------------------------------------
       
    47 // CNSPMediaStream::CNSPMediaStream
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CNSPMediaStream::CNSPMediaStream( MNSPControllerIF& aController,
       
    51         TUint aSessionId, TUint aCollectionId )
       
    52     : iController( aController ),
       
    53       iSessionId( aSessionId ),
       
    54       iCollectionId( aCollectionId )
       
    55     {
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CNSPMediaStream::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CNSPMediaStream::ConstructL( CSdpMediaField& aMediaField,
       
    64         const TDesC8& aAddress, TUint aProtocol, TUint aMediaTos )
       
    65     {
       
    66     iMediaField = aMediaField.CloneL( EFalse );
       
    67     
       
    68     RBuf8 addr;
       
    69     addr.CleanupClosePushL();
       
    70     addr.CreateL( KMaxLengthOfFQDN );
       
    71     addr = CONN_ADDR( aMediaField, aAddress );
       
    72     TUint port = iMediaField->Port();
       
    73     
       
    74     CNSPMediaStreamComponent* rtp = CNSPMediaStreamComponent::NewLC(
       
    75             iController, iSessionId, iCollectionId, KNSPRtpComponentId,
       
    76             addr, port, aProtocol, aMediaTos );
       
    77     User::LeaveIfError( iStreamComponentArray.Append( rtp ) );
       
    78     CleanupStack::Pop( rtp );
       
    79     
       
    80     iController.ContentParser().FindRTCP( aMediaField, addr, ++port );
       
    81     
       
    82     CNSPMediaStreamComponent* rtcp = CNSPMediaStreamComponent::NewLC(
       
    83             iController, iSessionId, iCollectionId, KNSPRtcpComponentId,
       
    84             addr, port, aProtocol, aMediaTos );
       
    85     User::LeaveIfError( iStreamComponentArray.Append( rtcp ) );
       
    86     CleanupStack::Pop( rtcp );
       
    87     
       
    88     CleanupStack::PopAndDestroy( &addr );
       
    89     
       
    90     iInboundCredentials = CNATFWCredentials::NewL();
       
    91     iInboundCredentials->SetDirection( CNATFWCredentials::EInbound );
       
    92     HBufC8* buffer = HBufC8::NewLC( KMaxPasswordLength );
       
    93     TPtr8 ptr( buffer->Des() );
       
    94     iController.GenerateUsernameL( ptr );
       
    95     iInboundCredentials->SetUsernameL( buffer->Des() );
       
    96     iController.GeneratePasswordL( ptr );
       
    97     iInboundCredentials->SetPasswordL( buffer->Des() );
       
    98     CleanupStack::PopAndDestroy( buffer );
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CNSPMediaStream::NewL
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CNSPMediaStream* CNSPMediaStream::NewL( MNSPControllerIF& aController,
       
   107         CSdpMediaField& aMediaField, TUint aSessionId, TUint aCollectionId,
       
   108         const TDesC8& aAddress, TUint aProtocol, TUint aMediaTos )
       
   109     {
       
   110     CNSPMediaStream* self = CNSPMediaStream::NewLC( aController,
       
   111             aMediaField, aSessionId, aCollectionId, aAddress,
       
   112             aProtocol, aMediaTos );
       
   113     CleanupStack::Pop( self );
       
   114     return self;
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CNSPMediaStream::NewLC
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 CNSPMediaStream* CNSPMediaStream::NewLC( MNSPControllerIF& aController,
       
   123         CSdpMediaField& aMediaField, TUint aSessionId, TUint aCollectionId,
       
   124         const TDesC8& aAddress, TUint aProtocol, TUint aMediaTos )
       
   125     {
       
   126     CNSPMediaStream* self = new ( ELeave ) CNSPMediaStream(
       
   127             aController, aSessionId, aCollectionId );
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL( aMediaField, aAddress, aProtocol, aMediaTos );
       
   130     return self;
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CNSPMediaStream::~CNSPMediaStream
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 CNSPMediaStream::~CNSPMediaStream()
       
   139     {
       
   140     delete iMediaField;
       
   141     delete iInboundCredentials;
       
   142     delete iOutboundCredentials;
       
   143     iPendingArray.Close();
       
   144     iStreamComponentArray.ResetAndDestroy();
       
   145     iStreamComponentArray.Close();
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CNSPMediaStream::HasMediaComponent
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 TBool CNSPMediaStream::HasMediaComponent( TUint aStreamId )
       
   154     {
       
   155     const TInt componentcount( iStreamComponentArray.Count() );
       
   156     for ( TInt index = 0; index < componentcount; index++ )
       
   157         {
       
   158         if ( iStreamComponentArray[index]->StreamId() == aStreamId )
       
   159             {
       
   160             return ETrue;
       
   161             }
       
   162         }
       
   163         
       
   164     return EFalse;
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CNSPMediaStream::Notify
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 TNatReturnStatus CNSPMediaStream::ControlMediaL( TUint aStreamId,
       
   173 		MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent,
       
   174 		TInt aError, TAny* aData )
       
   175 	{
       
   176     TNatReturnStatus status = KErrNone;
       
   177     const TInt index = FindMediaComponent( aStreamId );
       
   178 	
       
   179     if ( KErrNotFound != index )
       
   180     	{
       
   181         status = iStreamComponentArray[index]->ControlMediaL( aEvent, aError, aData );
       
   182         TNatReturnStatus cont = RemovePending( aStreamId, KNatReady == status );
       
   183         status = ( KNatReady == status ? cont : status );    	
       
   184     	}
       
   185     else
       
   186     	{
       
   187     	status = KErrNotFound;
       
   188     	}
       
   189     
       
   190     return status;
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CNSPMediaStream::ModifyStunConnL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CNSPMediaStream::ModifyStunConnL( CSdpMediaField& aMediaField,
       
   199         TDes8& aAddress ) const
       
   200     {
       
   201     NSPLOG_STR( "CNSPMediaStream::ModifyStunConnL(), Entry" )
       
   202     
       
   203     const TInt componentcount( iStreamComponentArray.Count() );
       
   204     for ( TInt index = 0; index < componentcount; index++ )
       
   205         {
       
   206         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   207         RPointerArray<CNATFWCandidate>& localcand = component->LocalCandidates();
       
   208         NSPUtil::SortCandidatesL( localcand ); // leave if empty
       
   209         
       
   210         if ( KNSPRtpComponentId == component->ComponentId() )
       
   211             {
       
   212             aAddress = localcand[0]->TransportDomainAddr();
       
   213             aMediaField.SetPortL( localcand[0]->TransportDomainPort() );
       
   214             UpdateConnFieldL( aMediaField, aAddress );
       
   215             }
       
   216         else if ( KNSPRtcpComponentId == component->ComponentId() )
       
   217             {
       
   218             iController.ContentParser().ModifyRTCPL( aMediaField,
       
   219                     localcand[0]->TransportDomainAddr(),
       
   220                     localcand[0]->TransportDomainPort() );
       
   221             }
       
   222         else
       
   223             {
       
   224             User::Leave( KErrNotFound );
       
   225             }
       
   226         }
       
   227     
       
   228     NSPLOG_STR( "CNSPMediaStream::ModifyStunConnL(), Exit" )
       
   229     }
       
   230 
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CNSPMediaStream::ModifyIceConnL
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CNSPMediaStream::ModifyIceConnL( CSdpMediaField& aMediaField,
       
   237         TDes8& aAddress ) const
       
   238     {
       
   239     NSPLOG_STR( "CNSPMediaStream::ModifyIceConnL(), Entry" )
       
   240     
       
   241     const TInt componentcount( iStreamComponentArray.Count() );
       
   242     for ( TInt index = 0; index < componentcount; index++ )
       
   243         {
       
   244         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   245         const CNATFWCandidate& localcandidate = component->IceLocalCandidateL();
       
   246         
       
   247         if ( KNSPRtpComponentId == component->ComponentId() )
       
   248             {
       
   249             aAddress = localcandidate.TransportDomainAddr();
       
   250             aMediaField.SetPortL( localcandidate.TransportDomainPort() );
       
   251             UpdateConnFieldL( aMediaField, aAddress );
       
   252             }
       
   253         else if ( KNSPRtcpComponentId == component->ComponentId() )
       
   254             {
       
   255             iController.ContentParser().ModifyRTCPL( aMediaField,
       
   256                     localcandidate.TransportDomainAddr(),
       
   257                     localcandidate.TransportDomainPort() );
       
   258             }
       
   259         else
       
   260             {
       
   261             User::Leave( KErrNotFound );
       
   262             }
       
   263         }
       
   264     
       
   265     NSPLOG_STR( "CNSPMediaStream::ModifyIceConnL(), Exit" )
       
   266     }
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CNSPMediaStream::ModifyLocalConnL
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void CNSPMediaStream::ModifyLocalConnL( CSdpMediaField& aMediaField,
       
   274         TDes8& aAddress ) const
       
   275     {
       
   276     NSPLOG_STR( "CNSPMediaStream::ModifyLocalConnL(), Entry" )
       
   277     
       
   278     TUint port( 0 );
       
   279     RBuf8 address;
       
   280     address.CreateL( KMaxLengthOfFQDN );
       
   281     address.CleanupClosePushL();
       
   282     
       
   283     const TInt streamcompcount( iStreamComponentArray.Count() );
       
   284     for ( TInt index = 0; index < streamcompcount; index++ )
       
   285         {
       
   286         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   287         User::LeaveIfError( component->OutgoingAddress( address, port ) );
       
   288         
       
   289         if ( KNSPRtpComponentId == component->ComponentId() )
       
   290             {
       
   291             aAddress = address;
       
   292             aMediaField.SetPortL( port );
       
   293             UpdateConnFieldL( aMediaField, aAddress );
       
   294             }
       
   295         else if ( KNSPRtcpComponentId == component->ComponentId() )
       
   296             {
       
   297             iController.ContentParser().ModifyRTCPL( aMediaField, address, port );
       
   298             }
       
   299         else
       
   300             {
       
   301             User::Leave( KErrNotFound );
       
   302             }
       
   303         }
       
   304     
       
   305     CleanupStack::PopAndDestroy( &address );
       
   306     
       
   307     NSPLOG_STR( "CNSPMediaStream::ModifyLocalConnL(), Exit" )
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CNSPMediaStream::AddLocalCandidatesL
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CNSPMediaStream::AddLocalCandidatesL( CSdpMediaField& aMediaField ) const
       
   316     {
       
   317     RPointerArray<CNATFWCandidate> localcand;
       
   318     CleanupClosePushL( localcand );
       
   319     LocalCandidatesL( localcand );
       
   320     iController.ContentParser().AddCandidatesL( aMediaField, localcand );
       
   321     CleanupStack::PopAndDestroy( &localcand );
       
   322     }
       
   323 
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // CNSPMediaStream::GetCandidatesL
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 void CNSPMediaStream::GetCandidatesL( CSdpMediaField& aMediaField,
       
   330         RPointerArray<CNATFWCandidate>& aRemoteCandidates ) const
       
   331     {
       
   332     iController.ContentParser().GetCandidatesL( aMediaField, aRemoteCandidates );
       
   333     AttachCandidatesL( aRemoteCandidates );
       
   334     }
       
   335 
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CNSPMediaStream::MediaConnInfoL
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 TNatReturnStatus CNSPMediaStream::MediaConnInfoL( CSdpMediaField& aMediaField,
       
   342         const TDesC8& aAddress ) const
       
   343     {
       
   344     TNatReturnStatus status = KNatReady;
       
   345     TNatReturnStatus mediastatus = status;
       
   346     const TDesC8& address = CONN_ADDR( aMediaField, aAddress );
       
   347 
       
   348     RBuf8 addr;
       
   349     addr.CreateL( KMaxLengthOfFQDN );
       
   350     addr.CleanupClosePushL();
       
   351     
       
   352     const TInt streamcompcount( iStreamComponentArray.Count() );
       
   353     for ( TInt index = 0; index < streamcompcount; index++ )
       
   354         {
       
   355         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   356         TUint port = aMediaField.Port();
       
   357         addr = address;
       
   358         
       
   359         if ( KNSPRtcpComponentId == component->ComponentId() )
       
   360             {
       
   361             iController.ContentParser().FindRTCP( aMediaField, addr, ++port );
       
   362             }
       
   363         
       
   364         const TDesC8& remoteAddr = component->RemoteAddress();
       
   365         const TUint remotePort = component->RemotePort();
       
   366         mediastatus = ( ( !addr.Compare( remoteAddr ) && remotePort == port ) ||
       
   367         				NSPUtil::IsUnspecifiedL( addr, port ) ? KNatReady : KNatAsync );
       
   368         
       
   369         if ( KNatAsync == mediastatus )
       
   370             {
       
   371             component->ActivateL( addr, port );
       
   372             }
       
   373         
       
   374         status = ( KNatReady == status ? mediastatus : status );
       
   375         }
       
   376     
       
   377     CleanupStack::PopAndDestroy( &addr );
       
   378     return status;
       
   379     }
       
   380 
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CNSPMediaStream::AddRemoteCandidatesL
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CNSPMediaStream::AddRemoteCandidatesL( CSdpMediaField& aMediaField ) const
       
   387     {
       
   388     RPointerArray<CNATFWCandidate> remotecandidates;
       
   389     CleanupClosePushL( remotecandidates );
       
   390     
       
   391     const TInt streamcompcount( iStreamComponentArray.Count() );
       
   392     for ( TInt index = 0; index < streamcompcount; index++ )
       
   393         {
       
   394         remotecandidates.AppendL( &iStreamComponentArray[index]->IceLocalCandidateL() );
       
   395         }
       
   396     
       
   397     iController.ContentParser().AddRemoteCandidatesL( aMediaField, remotecandidates );
       
   398     CleanupStack::PopAndDestroy(); // remotecandidates
       
   399     }
       
   400 
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CNSPMediaStream::AddCredentialsL
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CNSPMediaStream::AddCredentialsL( CSdpMediaField& aMediaField ) const
       
   407     {
       
   408     iController.ContentParser().AddCredentialsL( aMediaField, *iInboundCredentials );
       
   409     }
       
   410 
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CNSPMediaStream::LocalCandidatesL
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CNSPMediaStream::LocalCandidatesL(
       
   417 			RPointerArray<CNATFWCandidate>& aLocalcand ) const
       
   418     {
       
   419     const TInt streamcompcount( iStreamComponentArray.Count() );
       
   420     for ( TInt index = 0; index < streamcompcount; index++ )
       
   421         {
       
   422         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   423         RPointerArray<CNATFWCandidate>& localcand = component->LocalCandidates();
       
   424         NSPUtil::SortCandidatesL( localcand ); // leave if empty
       
   425         
       
   426         const TInt localcandcount( localcand.Count() );
       
   427         for ( TInt jndex = 0; jndex < localcandcount ; jndex++ )
       
   428             {
       
   429             aLocalcand.AppendL( localcand[jndex] );
       
   430             }
       
   431         }
       
   432     }
       
   433 
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // CNSPMediaStream::FetchCandidateL
       
   437 // ---------------------------------------------------------------------------
       
   438 //
       
   439 void CNSPMediaStream::FetchCandidateL()
       
   440     {
       
   441     const TInt componentcount( iStreamComponentArray.Count() );
       
   442     for ( TInt index = 0; index < componentcount; index++ )
       
   443         {
       
   444         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   445         component->FetchCandidateL();
       
   446         iPendingArray.AppendL( component->StreamId() );
       
   447         }
       
   448     }
       
   449 
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // CNSPMediaStream::FetchCandidatesL
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 void CNSPMediaStream::FetchCandidatesL()
       
   456     {
       
   457     const TInt componentcount( iStreamComponentArray.Count() );
       
   458     for ( TInt index = 0; index < componentcount; index++ )
       
   459         {
       
   460         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   461         component->FetchCandidatesL();
       
   462         iPendingArray.AppendL( component->StreamId() );
       
   463         }
       
   464     }
       
   465 
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // CNSPMediaStream::PerformCandidateChecksL
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CNSPMediaStream::PerformCandidateChecksL()
       
   472     {
       
   473     const TInt componentcount( iStreamComponentArray.Count() );
       
   474     for ( TInt index = 0; index < componentcount; index++ )
       
   475         {
       
   476         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   477         component->PerformCandidateChecksL();
       
   478         iPendingArray.AppendL( component->StreamId() );
       
   479         }
       
   480     }
       
   481 
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // CNSPMediaStream::ActivateL
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CNSPMediaStream::ActivateL( CSdpMediaField& aMediaField,
       
   488         const TDesC8& aAddress )
       
   489     {
       
   490     const TDesC8& address = CONN_ADDR( aMediaField, aAddress );
       
   491     
       
   492     RBuf8 addr;
       
   493     addr.CreateL( KMaxLengthOfFQDN );
       
   494     addr.CleanupClosePushL();
       
   495     
       
   496     const TInt componentcount( iStreamComponentArray.Count() );
       
   497     for ( TInt index = 0; index < componentcount; index++ )
       
   498         {
       
   499         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   500         TUint port = aMediaField.Port();
       
   501         addr = address;
       
   502         
       
   503         if ( KNSPRtcpComponentId == component->ComponentId() )
       
   504             {
       
   505             iController.ContentParser().FindRTCP( aMediaField, addr, ++port );
       
   506             }
       
   507         
       
   508         iStreamComponentArray[index]->ActivateL( addr, port );
       
   509         iPendingArray.AppendL( iStreamComponentArray[index]->StreamId() );
       
   510         }
       
   511     
       
   512     CleanupStack::PopAndDestroy( &addr );
       
   513     }
       
   514 
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // CNSPMediaStream::ActivateL
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CNSPMediaStream::ActivateL()
       
   521     {
       
   522     const TInt componentcount( iStreamComponentArray.Count() );
       
   523     for ( TInt index = 0; index < componentcount; index++ )
       
   524         {
       
   525         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   526         component->ActivateL();
       
   527         iPendingArray.AppendL( component->StreamId() );
       
   528         }
       
   529     }
       
   530 
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 // CNSPMediaStream::DeActivateL
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void CNSPMediaStream::DeActivateL()
       
   537     {
       
   538     const TInt componentcount( iStreamComponentArray.Count() );
       
   539     for ( TInt index = 0; index < componentcount; index++ )
       
   540         {
       
   541         CNSPMediaStreamComponent* component = iStreamComponentArray[index];
       
   542         component->DeActivateL();
       
   543         iPendingArray.AppendL( component->StreamId() );
       
   544         }
       
   545     }
       
   546 
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CNSPMediaStream::CollectionId
       
   550 // ---------------------------------------------------------------------------
       
   551 //
       
   552 TUint CNSPMediaStream::CollectionId() const
       
   553     {
       
   554     return iCollectionId;
       
   555     }
       
   556 
       
   557 
       
   558 // ---------------------------------------------------------------------------
       
   559 // CNSPMediaStream::MediaField
       
   560 // ---------------------------------------------------------------------------
       
   561 //
       
   562 const CSdpMediaField& CNSPMediaStream::MediaField() const
       
   563     {
       
   564     return (*iMediaField);
       
   565     }
       
   566 
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CNSPMediaStream::SetInboundCredentialsL
       
   570 // ---------------------------------------------------------------------------
       
   571 //
       
   572 void CNSPMediaStream::SetInboundCredentialsL()
       
   573     {
       
   574     const TInt componentcount( iStreamComponentArray.Count() );
       
   575     for ( TInt index = 0; index < componentcount; index++ )
       
   576         {
       
   577         iStreamComponentArray[index]->SetCredentialsL( *iInboundCredentials );
       
   578         }
       
   579     }
       
   580 
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 // CNSPMediaStream::SetOutboundCredentialsL
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 void CNSPMediaStream::SetOutboundCredentialsL()
       
   587     {
       
   588     const TInt componentcount( iStreamComponentArray.Count() );
       
   589     for ( TInt index = 0; index < componentcount; index++ )
       
   590         {
       
   591         iStreamComponentArray[index]->SetCredentialsL( *iOutboundCredentials );
       
   592         }
       
   593     }
       
   594 
       
   595 
       
   596 // ---------------------------------------------------------------------------
       
   597 // CNSPMediaStream::SetOutboundCredentialsL
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 void CNSPMediaStream::SetOutboundCredentials( CNATFWCredentials* aOutboundCredentials )
       
   601     {
       
   602     if ( iOutboundCredentials != aOutboundCredentials )
       
   603         {
       
   604         delete iOutboundCredentials;
       
   605         iOutboundCredentials = aOutboundCredentials;
       
   606         }
       
   607     }
       
   608 
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // CNSPMediaStream::NeedToUpdate
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 TBool CNSPMediaStream::NeedToUpdateL()
       
   615     {
       
   616     TBool needUpdate = EFalse;
       
   617     
       
   618     const TInt componentcount( iStreamComponentArray.Count() );
       
   619     for ( TInt index = 0; index < componentcount && !needUpdate; index++ )
       
   620         {
       
   621         const CNATFWCandidate& local =
       
   622                 (*iStreamComponentArray[index]->LocalCandidates()[0]);
       
   623         const CNATFWCandidate& working =
       
   624                 iStreamComponentArray[index]->IceLocalCandidateL();
       
   625         
       
   626         needUpdate = !(
       
   627                 !working.TransportDomainAddr().Compare( local.TransportDomainAddr() ) &&
       
   628                 working.TransportDomainPort() == local.TransportDomainPort() );
       
   629         }
       
   630     
       
   631     return needUpdate;
       
   632     }
       
   633 
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // CNSPMediaStream::ResetAndDestroyCandidates
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void CNSPMediaStream::ResetAndDestroyCandidates()
       
   640     {
       
   641     const TInt componentcount( iStreamComponentArray.Count() );
       
   642     for ( TInt index = 0; index < componentcount; index++ )
       
   643         {
       
   644         iStreamComponentArray[index]->ResetAndDestroyCandidates();
       
   645         }    
       
   646     }
       
   647 
       
   648 
       
   649 // ---------------------------------------------------------------------------
       
   650 // CNSPMediaStream::RemovePending
       
   651 // ---------------------------------------------------------------------------
       
   652 //
       
   653 TNatReturnStatus CNSPMediaStream::RemovePending( TUint aStreamId, TBool aRemove )
       
   654     {
       
   655     TNatReturnStatus status = KNatAsync;
       
   656     
       
   657     if ( aRemove )
       
   658         {
       
   659         const TInt index = iPendingArray.Find( aStreamId );
       
   660         
       
   661         if ( KErrNotFound != index )
       
   662             {
       
   663             iPendingArray.Remove( index );
       
   664             iPendingArray.Compress();
       
   665             status = ( iPendingArray.Count() ? KNatAsync : KNatReady );
       
   666             }
       
   667         else
       
   668             {
       
   669             status = KNatAsync;
       
   670             }
       
   671         }
       
   672     
       
   673     return status;
       
   674     }
       
   675 
       
   676 
       
   677 // ---------------------------------------------------------------------------
       
   678 // CNSPMediaStream::AttachCandidatesL
       
   679 // ---------------------------------------------------------------------------
       
   680 //
       
   681 void CNSPMediaStream::AttachCandidatesL(
       
   682         RPointerArray<CNATFWCandidate>& aRemoteCandidates ) const
       
   683     {
       
   684     const TInt candidatecount( aRemoteCandidates.Count() );
       
   685     for ( TInt index = 0; index < candidatecount; index++ )
       
   686         {
       
   687         aRemoteCandidates[index]->SetSessionId( iSessionId );
       
   688         aRemoteCandidates[index]->SetStreamCollectionId( iCollectionId );
       
   689         
       
   690         TBool attach( EFalse );
       
   691         const TInt componentcount( iStreamComponentArray.Count() );
       
   692         for ( TInt jndex = 0; jndex < componentcount && !attach ; jndex++ )
       
   693             {
       
   694             attach = iStreamComponentArray[jndex]->AttachCandidateL(
       
   695                                 *aRemoteCandidates[index] );
       
   696             }
       
   697         }
       
   698     }
       
   699 
       
   700 
       
   701 // ---------------------------------------------------------------------------
       
   702 // CNSPMediaStream::FindMediaComponent
       
   703 // ---------------------------------------------------------------------------
       
   704 //
       
   705 TInt CNSPMediaStream::FindMediaComponent( TUint aStreamId )
       
   706     {
       
   707     const TInt componentcount( iStreamComponentArray.Count() );
       
   708     for ( TInt index = 0; index < componentcount; index++ )
       
   709         {
       
   710         if ( iStreamComponentArray[index]->StreamId() == aStreamId )
       
   711             {
       
   712             return index;
       
   713             }
       
   714         }
       
   715     
       
   716     return KErrNotFound;
       
   717     }
       
   718 
       
   719 // end of file