rtp/rtpstack/src/rtpmanager.cpp
changeset 0 307788aac0a8
child 29 5f12516512fa
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2002-2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "rtpmanager.h"
       
    23 #include <utf.h>
       
    24 // CONSTANTS
       
    25 
       
    26 // Refer to RFC 1889
       
    27 // The comparison in rates between NTP timestamp and RTP timestamp.
       
    28 // A value of n means that each increment of an RTP timestamp
       
    29 // corresponds to n microseconds.
       
    30 //
       
    31 const TUint8 KRtpPayloadClockConversions[KRtpMaxPayloadTypes] =
       
    32     {
       
    33     125, 125, 125, 125, 125, 125, 63, 125, 125, 63, // 0-9 
       
    34     23, 23, 125, 125, 11, 125, 91, 45, 125, 0,      // 10-19
       
    35     0, 0, 0, 0, 0, 11, 11, 0, 11, 0,                // 20-29
       
    36     0, 11, 11, 11, 11, 0, 0, 0, 0, 0,               // 30-39
       
    37     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 40-49
       
    38     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 50-59
       
    39     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 60-69
       
    40     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 70-79
       
    41     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 80-89
       
    42     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 90-99
       
    43     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 100-109
       
    44     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                   // 110-119
       
    45     0, 0, 0, 0, 0, 0, 0, 0                          // 120-127
       
    46     };
       
    47 
       
    48 const TInt TArrayStore::iOffset = _FOFF( TArrayStore, iMagicKey );
       
    49 
       
    50 const TInt KBufLength = 64;
       
    51 // ================= MEMBER FUNCTIONS =======================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // C++ default constructor can NOT contain any code, that
       
    55 // might leave.
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CRtpManager::CRtpManager( MRtpErrNotify& aErrNotify ) 
       
    59     : iStandardRtp( ETrue ), 
       
    60       iEnableRtcp( EFalse ),
       
    61       iSocketServPtr( NULL ), 
       
    62       iConnPtr( NULL ), 
       
    63       iNumOfObjects( 0 ),
       
    64       iErrNotify( aErrNotify )
       
    65     {
       
    66     for ( TUint k = 0; k < KRtpMaxPayloadTypes; k++ )
       
    67         {
       
    68         iProfileRTPTimeRates[k] = ( TUint32 ) KRtpPayloadClockConversions[k];
       
    69         }
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CRtpManager::ConstructL()
       
    77     {
       
    78     // instantiate RTP session array
       
    79     iSessionArray = new ( ELeave ) CArrayFixFlat<TArrayStore>( 2 );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Two-phased constructor.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CRtpManager* CRtpManager::NewL( MRtpErrNotify& aErrNotify )
       
    87     {
       
    88     CRtpManager* self = new ( ELeave ) CRtpManager( aErrNotify );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop(); // self
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Destructor
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CRtpManager::~CRtpManager( void )
       
   100     {
       
   101     RTP_DEBUG_DETAIL( "CRtpManager::~CRtpManager" );
       
   102     
       
   103     Close();
       
   104     delete iSessionArray;
       
   105     
       
   106     if ( iDefaultSdes )
       
   107         {
       
   108         delete iDefaultSdes;
       
   109         iDefaultSdes = NULL;
       
   110         }
       
   111     
       
   112     iSocketServPtr = NULL;
       
   113     iConnPtr = NULL;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // TInt CRtpManager::OpenL()
       
   118 // Return error code
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 TInt CRtpManager::OpenL( const TRtpSdesParams& aSdesInfo, 
       
   122                          const TDesC* aRtpPacketDll,
       
   123                          RSocketServ* aSocketServPtr,
       
   124                          RConnection* aConnPtr )
       
   125     {
       
   126     RTP_DEBUG_DETAIL( "***********************************" );
       
   127     RTP_DEBUG_DETAIL( "***       OPENING NEW API       ***" );
       
   128     RTP_DEBUG_DETAIL( "***********************************" );
       
   129     RTP_DEBUG_DETAIL( "CRtpManager::OpenL" );
       
   130     
       
   131     TInt err( KErrNone );
       
   132     iDefaultSdes = CRtpSDES::NewL( aSdesInfo );
       
   133     
       
   134 
       
   135     if ( aSocketServPtr )
       
   136         {
       
   137         iSocketServPtr = aSocketServPtr;
       
   138         }
       
   139     else
       
   140         {
       
   141         iSocketServPtr = &iSocketServ;
       
   142         }
       
   143 
       
   144     if ( aConnPtr )
       
   145         {
       
   146         iConnPtr = aConnPtr;
       
   147         }
       
   148     else
       
   149         {
       
   150         iConnPtr = &iConn;
       
   151         }
       
   152     
       
   153     //compare string to default DLL names, if string is "", then load default
       
   154     if ( !aRtpPacketDll )
       
   155         {
       
   156         // Use standard RTP
       
   157         iStandardRtp = ETrue;
       
   158         }
       
   159     else
       
   160         {
       
   161         // Dynamically load the specified DLL
       
   162         err = iLibrary.Load( *aRtpPacketDll );
       
   163         if ( err )
       
   164             {
       
   165             RTP_DEBUG_DETAIL( "CRtpManager::OpenL: error loading DLL" );
       
   166             User::Leave( err );
       
   167             }
       
   168         iStandardRtp = EFalse;
       
   169         }
       
   170 
       
   171     return err;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // TInt CRtpManager::StartConnection()
       
   176 // Starts the connection synchronously
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 TInt CRtpManager::StartConnection( TInt aIapId )
       
   180     {
       
   181     RTP_DEBUG_DETAIL( "CRtpManager::StartConnection (sync)" );
       
   182 
       
   183     TInt error( PrepareConnection( iPrefs, aIapId ) );
       
   184     if ( error != KErrNone )
       
   185         {
       
   186         return error;
       
   187         }
       
   188 
       
   189     error = iConnPtr->Start( iPrefs );
       
   190     if ( error != KErrNone )
       
   191         {
       
   192         iConnPtr->Close();
       
   193         iSocketServPtr->Close();
       
   194 
       
   195         RTP_DEBUG_DETAIL_DVALUE( "Error starting connection: ", error );
       
   196         }
       
   197     else
       
   198         {
       
   199         iIapId = aIapId;
       
   200         }
       
   201     return error;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // TInt CRtpManager::StartConnection()
       
   206 // Starts the connection asynchronously
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 TInt CRtpManager::StartConnection( TRequestStatus& aStatus, TInt aIapId )
       
   210     {
       
   211     RTP_DEBUG_DETAIL( "CRtpManager::StartConnection (async)" );
       
   212 
       
   213     TInt error( PrepareConnection( iPrefs, aIapId ) );
       
   214     if ( error != KErrNone )
       
   215         {
       
   216         return error;
       
   217         }
       
   218 
       
   219     iIapId = aIapId;
       
   220     iConnPtr->Start( iPrefs, aStatus );
       
   221     
       
   222     RTP_DEBUG_DETAIL( "Start request sent" );
       
   223  
       
   224     return KErrNone;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // TInt CRtpManager::PrepareConnection()
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 TInt CRtpManager::PrepareConnection( TCommDbConnPref& aPrefs, TInt aIapId )
       
   232     {
       
   233     RTP_DEBUG_DETAIL( "CRtpManager::PrepareConnection"  );
       
   234     
       
   235     TInt err( KErrCouldNotConnect );
       
   236 
       
   237     if ( aIapId != KUseDefaultIap )
       
   238         {
       
   239 	    aPrefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
   240         aPrefs.SetIapId( aIapId );
       
   241         }
       
   242     
       
   243     aPrefs.SetDirection( ECommDbConnectionDirectionOutgoing );
       
   244 
       
   245     err = iSocketServPtr->Connect();
       
   246 
       
   247     if ( err != KErrNone )
       
   248         {
       
   249         iSocketServPtr->Close();
       
   250         RTP_DEBUG_DETAIL_DVALUE( "Error opening socket server: " , err );
       
   251         return err;
       
   252         }
       
   253 
       
   254     err = iConnPtr->Open( *iSocketServPtr );
       
   255 
       
   256     if ( err != KErrNone )
       
   257         {
       
   258         iConnPtr->Close(); 
       
   259         iSocketServPtr->Close();
       
   260         RTP_DEBUG_DETAIL_DVALUE( "Error opening connection: " , err );
       
   261         return err;
       
   262         }
       
   263 
       
   264     return KErrNone;
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CRtpManager::CancelStart()
       
   269 // Cancels the asynchoronous start of the connection. 
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CRtpManager::CancelStart()
       
   273     {
       
   274     if ( iConnPtr )
       
   275         {
       
   276         iConnPtr->Close(); 
       
   277         }
       
   278     if ( iSocketServPtr )
       
   279         {
       
   280         iSocketServPtr->Close();
       
   281         }
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CRtpManager::Close()
       
   286 // Close rtp manager 
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CRtpManager::Close( void )
       
   290     {
       
   291     RemoveRtpAllObjects();
       
   292     if ( !iStandardRtp )
       
   293         {
       
   294         iLibrary.Close();
       
   295         }
       
   296     
       
   297     RTP_DEBUG_DETAIL( "CRtpManager::Close -- Closing RConnection"  );
       
   298     RTP_DEBUG_DETAIL( "CRtpManager::Close -- Closing Socket Server" );
       
   299     
       
   300     if ( iConnPtr )
       
   301         {
       
   302         iConnPtr->Close();
       
   303         }
       
   304         
       
   305     if ( iSocketServPtr )
       
   306         {
       
   307         iSocketServPtr->Close();
       
   308         }
       
   309     
       
   310     iConnected = EFalse;
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CRtpManager::SetLocalSdes()
       
   315 // Set local sdes
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CRtpManager::SetLocalSdes( const TRtpSdesParams& aSdesInfo )
       
   319     {
       
   320     iDefaultSdes->SetSDES( aSdesInfo );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // TInetAddr& CRtpManager::GetLocalIPAddressL()
       
   325 // return local IP address
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 TInetAddr& CRtpManager::GetLocalIPAddressL()
       
   329     {
       
   330     RTP_DEBUG_DETAIL( "CRtpManager::GetLocalIPAddress" );
       
   331  	
       
   332  	TUint32 iapId;
       
   333     if ( iIapId == 0 )
       
   334         {
       
   335         RTP_DEBUG_DETAIL( "Error: IAP not set (=0)" );
       
   336 
       
   337         User::Leave( KErrNotSupported );
       
   338         }
       
   339     if ( iIapId < 0 )
       
   340         {
       
   341         User::LeaveIfError( GetIapId( iapId ) );
       
   342         }
       
   343     else
       
   344         {
       
   345         iapId = static_cast<TUint32>( iIapId );
       
   346         }
       
   347     CLocalAddrResolver* localAddressResolver = 
       
   348         CLocalAddrResolver::NewLC( *iSocketServPtr );
       
   349     localAddressResolver->GetLocalAddrL( iLocalAddr, iapId );
       
   350     CleanupStack::PopAndDestroy( localAddressResolver );
       
   351 
       
   352     return iLocalAddr;
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // TRtpId CRtpManager::CreateSessionL()
       
   357 // Return session id 
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 TRtpId CRtpManager::CreateSessionL( const TCreateSessionParams& aSessionParams,
       
   361                                     TUint& aPort,
       
   362                                     TBool aEnableRtcp,
       
   363                                     const TRtcpParams* aRtcpParams )
       
   364     {
       
   365     RTP_DEBUG_DETAIL( "CRtpManager::CreateSessionL" );
       
   366         
       
   367     TInt err( KErrNone );
       
   368 
       
   369     // dont allow following combination: STP with RTCP
       
   370     if ((!iStandardRtp) && aEnableRtcp)
       
   371         User::Leave(KErrNotSupported);
       
   372     
       
   373     const TRtpId sessionId = AssignUniqueID();
       
   374     iEnableRtcp = aEnableRtcp;
       
   375 	CheckSdesCName();
       
   376     CRtpSession* newSession = CRtpSession::NewL( aSessionParams,
       
   377                                                  aPort,
       
   378                                                  aEnableRtcp,
       
   379                                                  aRtcpParams,
       
   380                                                  *iSocketServPtr,
       
   381                                                  *iConnPtr,
       
   382                                                  sessionId,
       
   383                                                  iDefaultSdes,
       
   384                                                  iProfileRTPTimeRates,
       
   385                                                  iStandardRtp,
       
   386                                                  iLibrary,
       
   387                                                  iErrNotify,
       
   388                                                  *this );
       
   389 
       
   390     // add RTP Session to the server list 
       
   391     TArrayStore arrayData( sessionId, ( TUint ) newSession, ESession );
       
   392     err = AddRtpObject( arrayData );
       
   393 
       
   394     if ( err != KErrNone )
       
   395         {
       
   396         RTP_DEBUG_DETAIL_DVALUE( "Session creation failed with error = ", err );
       
   397         
       
   398         delete newSession;
       
   399         
       
   400         return KNullId;
       
   401         }
       
   402     RTP_DEBUG_DETAIL_DVALUE( "Session created with ID ", sessionId );
       
   403     
       
   404     return sessionId;
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // TRtpId CRtpManager::CreateSessionL()
       
   409 // Return session id 
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 TRtpId CRtpManager::CreateSessionL( const TCreateSessionParams& aSessionParams,
       
   413                                     TUint& aPort,
       
   414                                     TBool aEnableRtcp,
       
   415                                     const TRtcpParams* aRtcpParams,
       
   416                                     CSRTPSession& aSRTPSession  )
       
   417     {
       
   418     RTP_DEBUG_DETAIL( "CRtpManager::CreateSessionL" );
       
   419         
       
   420     TInt err( KErrNone );
       
   421 
       
   422     // dont allow following combination: STP with RTCP
       
   423     if ((!iStandardRtp) && aEnableRtcp)
       
   424         User::Leave(KErrNotSupported);
       
   425     
       
   426     const TRtpId sessionId = AssignUniqueID();
       
   427     iEnableRtcp = aEnableRtcp;
       
   428 	CheckSdesCName();
       
   429     CRtpSessionSrtp* newSession = CRtpSessionSrtp::NewL( aSessionParams,
       
   430                                                  aPort,
       
   431                                                  aEnableRtcp,
       
   432                                                  aRtcpParams,
       
   433                                                  *iSocketServPtr,
       
   434                                                  *iConnPtr,
       
   435                                                  sessionId,
       
   436                                                  iDefaultSdes,
       
   437                                                  iProfileRTPTimeRates,
       
   438                                                  iStandardRtp,
       
   439                                                  iLibrary,
       
   440                                                  iErrNotify,
       
   441                                                  *this,
       
   442 												 aSRTPSession);
       
   443 
       
   444     // add RTP Session to the server list 
       
   445     TArrayStore arrayData( sessionId, ( TUint ) newSession, ESession );
       
   446     err = AddRtpObject( arrayData );
       
   447 
       
   448     if ( err != KErrNone )
       
   449         {
       
   450         RTP_DEBUG_DETAIL_DVALUE( "Session creation failed with error = ", err );
       
   451         
       
   452         delete newSession;
       
   453         
       
   454         return KNullId;
       
   455         }
       
   456     RTP_DEBUG_DETAIL_DVALUE( "Session created with ID ", sessionId );
       
   457     
       
   458     return sessionId;
       
   459     }
       
   460 
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // TInt CRtpManager::StartSession()
       
   464 // Start session, including starting rtp receiving and rtcp sending/receiving
       
   465 // if RTCP is enabled. 
       
   466 // Return KErrNone if successful; KErrNotFound otherwise
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 TInt CRtpManager::StartSession( TRtpId aSessionId )
       
   470     {
       
   471     RTP_DEBUG_DETAIL( "CRtpManager::StartSession entry"  );
       
   472     
       
   473     CRtpSession* session = GetSession( aSessionId );
       
   474     if ( session )
       
   475         {
       
   476         RTP_DEBUG_DETAIL( "CRtpManager::StartSession exit"  );
       
   477         return session->StartSession();
       
   478         }
       
   479     
       
   480     RTP_DEBUG_DETAIL( "Session not found" );
       
   481     
       
   482     return KErrNotFound;
       
   483     }
       
   484 
       
   485 // ---------------------------------------------------------------------------
       
   486 // CRtpManager::CloseSession()
       
   487 // Close session. Delete all streams inside the session. 
       
   488 // ---------------------------------------------------------------------------
       
   489 //
       
   490 void CRtpManager::CloseSession( TRtpId aSessionId )
       
   491     {
       
   492     RTP_DEBUG_DETAIL( "CRtpManager::CloseSession" );
       
   493     
       
   494     TInt result( RemoveRtpObject( aSessionId, ESession ) );
       
   495 
       
   496     if ( result == KErrNone )
       
   497         {
       
   498         RTP_DEBUG_DETAIL_DVALUE( "CRtpManager::CloseSession, Removed session with ID = ",
       
   499                   aSessionId );
       
   500         }
       
   501     else
       
   502         {
       
   503         RTP_DEBUG_DETAIL( "CRtpManager::CloseSession, Session not found"  );
       
   504         }
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // TInt CRtpManager::SetRemoteAddress()
       
   509 // Set remote IP addresses and port numbers for RTP and RTCP. 
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 TInt CRtpManager::SetRemoteAddress( TRtpId aSessionId, TInetAddr& aRemoteAddr )
       
   513     {
       
   514     CRtpSession* session = GetSession( aSessionId );
       
   515     TInt result( KErrNotFound );
       
   516 
       
   517     if ( session )
       
   518         {
       
   519         result = session->SetRemoteAddress( aRemoteAddr );
       
   520         }
       
   521     else
       
   522         {
       
   523         RTP_DEBUG_DETAIL( "CRtpManager::SetRemoteAddress, Session not found" );
       
   524         }
       
   525     return result;
       
   526     }
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // TInt CRtpManager::SetRemoteRtcpAddress()
       
   530 // Set remote IP addresses and port numbers for RTCP. 
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 TInt CRtpManager::SetRemoteRtcpAddress( TRtpId aSessionId, TInetAddr& aRemoteAddr )
       
   534     {
       
   535     CRtpSession* session = GetSession( aSessionId );
       
   536     TInt result( KErrNotFound );
       
   537 
       
   538     if ( session )
       
   539         {
       
   540         result = session->SetRemoteRtcpAddress( aRemoteAddr );
       
   541         }
       
   542     else
       
   543         {
       
   544         RTP_DEBUG_DETAIL( "CRtpManager::SetRemoteRtcpAddress, Session not found" );
       
   545         }
       
   546        
       
   547     return result;
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // TRtpId CRtpManager::CreateStreamL()
       
   552 // Create a stream of the specified type in a session. 
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 TRtpId CRtpManager::CreateStreamL( TRtpId aSessionId,
       
   556                                    const TCreateStreamType aStreamType,
       
   557                                    const TRtpPayloadType aPayloadType,
       
   558                                    TRtpSSRC& aSSRC )
       
   559     {
       
   560     TInt ret( KErrNone );
       
   561 
       
   562     RTP_DEBUG_DETAIL( "CRtpManager::CreateStreamL" );
       
   563 
       
   564     CRtpSession* session = GetSession( aSessionId );
       
   565 
       
   566     if ( !session )
       
   567         {
       
   568         RTP_DEBUG_DETAIL( "Error: Session not found" );
       
   569         return KNullId;
       
   570         }
       
   571 
       
   572     const TRtpId streamId( AssignUniqueID() ); 
       
   573 
       
   574     switch ( aStreamType )
       
   575         {
       
   576         case ECreateRecvStream:
       
   577             ret = session->CreateReceiveStreamL( streamId, aPayloadType );
       
   578             ( void ) aSSRC;
       
   579             break;
       
   580 
       
   581         case ECreateTranStream:
       
   582             ret = session->CreateTransmitStreamL( streamId, aPayloadType,
       
   583                                                   aSSRC );
       
   584             break;
       
   585         
       
   586         case ECreateTranStreamExt:
       
   587             ret = session->CreateTransmitStreamExtL( streamId, aPayloadType,
       
   588                                                      aSSRC );
       
   589             break;
       
   590 
       
   591         default:
       
   592             User::Leave( KErrArgument );
       
   593             break;
       
   594         }
       
   595 
       
   596     if ( ret != KErrNone )
       
   597         {
       
   598         RTP_DEBUG_DETAIL_DVALUE( "CRtpManager::CreateStreamL, create stream error ", ret );
       
   599         return KNullId;
       
   600         }
       
   601 
       
   602     // add stream to the server array along with the session address
       
   603     // to which it belongs.
       
   604     TArrayStore arrayData( streamId, ( TUint ) session, EStream );
       
   605     ret = AddRtpObject( arrayData );
       
   606 
       
   607     if ( ret != KErrNone )
       
   608         {
       
   609         RTP_DEBUG_DETAIL_DVALUE( "CRtpManager::CreateStreamL, stream array error ", ret );
       
   610                           
       
   611         return KNullId;
       
   612         }
       
   613     
       
   614     RTP_DEBUG_DETAIL_DVALUE( "CreateStreamL: Created stream in session ", aSessionId );
       
   615     RTP_DEBUG_DETAIL_DVALUE( "CreateStreamL: The new stream ID is ", streamId );
       
   616     
       
   617     return streamId;
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // TRtpId CRtpManager::CreateReceiveStreamL()
       
   622 // Create a receive stream in a session. 
       
   623 // ---------------------------------------------------------------------------
       
   624 //
       
   625 TRtpId CRtpManager::CreateReceiveStreamL( TRtpId aSessionId,
       
   626                                           const TRcvStreamParams& aParams )
       
   627     {
       
   628     
       
   629     RTP_DEBUG_DETAIL( "Creating RX stream"  );
       
   630     
       
   631 
       
   632     TRtpSSRC dummy;
       
   633     return CreateStreamL( aSessionId,
       
   634                           ECreateRecvStream,
       
   635                           aParams.iPayloadType,
       
   636                           dummy );
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // CRtpManager::CreateTransmitStreamL()
       
   641 // Create a transmit stream in a session and bring back the SSRC. 
       
   642 // Return stream id. 
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 TRtpId CRtpManager::CreateTransmitStreamL( TRtpId aSessionId, 
       
   646                                            const TTranStreamParams& aParams, 
       
   647                                            TRtpSSRC& aSSRC )
       
   648     {
       
   649     
       
   650     RTP_DEBUG_DETAIL( "Creating TX stream" );
       
   651    
       
   652 
       
   653     return CreateStreamL( aSessionId, ECreateTranStream,
       
   654                           aParams.iPayloadType, aSSRC );
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 // TRtpId CRtpManager::CreateTransmitStreamExtL
       
   659 // Create a transmit stream in a session and bring back SSRC. 
       
   660 // ---------------------------------------------------------------------------
       
   661 //
       
   662 TRtpId CRtpManager::CreateTransmitStreamExtL( TRtpId aSessionId, 
       
   663                                               const TTranStreamParams& aParams,
       
   664                                               const TRtpSSRC aSSRC )
       
   665     {
       
   666     
       
   667     RTP_DEBUG_DETAIL( "Creating TX stream (ext)" );
       
   668    
       
   669 
       
   670     return CreateStreamL( aSessionId, ECreateTranStreamExt,
       
   671                           aParams.iPayloadType,
       
   672                           const_cast<TRtpSSRC&>( aSSRC ) );
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------------------------
       
   676 // CRtpManager::CloseStream()
       
   677 //
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 void CRtpManager::CloseStream( TRtpId aStreamId )
       
   681     {
       
   682     CRtpSession* session = GetSession( aStreamId );
       
   683 
       
   684     if ( !session )
       
   685         {
       
   686         
       
   687         RTP_DEBUG_DETAIL("CRtpManager::CloseStream, Session not found" );
       
   688       
       
   689         return;
       
   690         }
       
   691 
       
   692     
       
   693     RTP_DEBUG_DETAIL_DVALUE( "Close RX/TX stream in session ", session->GetSessionId() );
       
   694     RTP_DEBUG_DETAIL_DVALUE( "Close RX/TX stream ID = ", aStreamId );
       
   695     
       
   696     
       
   697     session->CloseStream( aStreamId );
       
   698 
       
   699     // remove RTP stream from server array
       
   700     ( void ) RemoveRtpObject( aStreamId, EStream );
       
   701     }
       
   702 
       
   703 // ---------------------------------------------------------------------------
       
   704 // TInt CRtpManager::RegisterRtpObserver()
       
   705 //
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 TInt CRtpManager::RegisterRtpObserver( TRtpId aSessionId,
       
   709                                        MRtpObserver& aObserver )
       
   710     {
       
   711     CRtpSession* session = GetSession( aSessionId ); 
       
   712     TInt result( KErrGeneral );
       
   713     if ( session )
       
   714         {
       
   715         result = session->RegisterRtpObserver( aObserver );
       
   716         }
       
   717     else
       
   718         {
       
   719         RTP_DEBUG_DETAIL( "CRtpManager::RegisterRtpObserver, Session not found" );
       
   720         }
       
   721     return result;
       
   722     }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // CRtpManager::UnregisterRtpObserver()
       
   726 //
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void CRtpManager::UnregisterRtpObserver( TRtpId aSessionId )
       
   730     {
       
   731     CRtpSession* session = GetSession( aSessionId ); 
       
   732 
       
   733     if ( session )
       
   734         {
       
   735         session->UnregisterRtpObserver();
       
   736         }
       
   737     else
       
   738         {
       
   739         
       
   740         RTP_DEBUG_DETAIL( "CRtpManager::UnregisterRtpObserver, Session not found" );
       
   741         
       
   742         }
       
   743     }
       
   744 
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // TInt CRtpManager::SetNonRTPDataObserver()
       
   748 // 
       
   749 // ---------------------------------------------------------------------------
       
   750 //
       
   751 TInt CRtpManager::SetNonRTPDataObserver( TRtpId aSessionId, 
       
   752                                     MNonRTPDataObserver* aNonRTPDataObserver )
       
   753     {
       
   754     TInt ret = KErrNone;
       
   755     CRtpSession* session = GetSession( aSessionId ); 
       
   756 
       
   757     if ( session )
       
   758         {
       
   759         ret = session->SetNonRTPDataObserver(aNonRTPDataObserver);
       
   760         }
       
   761     else
       
   762         {
       
   763         RTP_DEBUG_DETAIL( "CRtpManager::SetNonRTPDataObserver, Session not found" );
       
   764         }
       
   765     return ret;
       
   766     }
       
   767 
       
   768 
       
   769 // ---------------------------------------------------------------------------
       
   770 // TInt CRtpManager::SendRtpPacket()
       
   771 //
       
   772 // ---------------------------------------------------------------------------
       
   773 //
       
   774 TInt CRtpManager::SendRtpPacket( TRtpId aTranStreamId,
       
   775                                  const TRtpSendHeader& aHeaderInfo, 
       
   776                                  const TDesC8& aPayloadData )
       
   777     {
       
   778     CRtpSession* rtpSession = GetSession( aTranStreamId );
       
   779 
       
   780     if ( rtpSession )
       
   781         {
       
   782         if ( iStandardRtp )
       
   783         	{
       
   784             if (rtpSession->IsSrtp())
       
   785             	{
       
   786             	
       
   787  		        return static_cast<CRtpSessionSrtp*>
       
   788  		        	(rtpSession)->SendRtpPacket( aTranStreamId, aHeaderInfo,
       
   789                                              	 aPayloadData );
       
   790  	
       
   791             	}
       
   792             else
       
   793             	{
       
   794             	return rtpSession->SendRtpPacket( aTranStreamId, aHeaderInfo,
       
   795              		                                 aPayloadData );
       
   796             	}
       
   797             }
       
   798         else
       
   799             {
       
   800             return rtpSession->SendRtpPacket( aHeaderInfo, aPayloadData );
       
   801         	}
       
   802         }
       
   803         
       
   804     
       
   805     RTP_DEBUG_DETAIL( "CRtpManager::SendRtpPacket, Session not found" );
       
   806     
       
   807     return KErrNotFound;
       
   808     }
       
   809 
       
   810 // ---------------------------------------------------------------------------
       
   811 // TInt CRtpManager::SendRtpPacket()
       
   812 //
       
   813 // ---------------------------------------------------------------------------
       
   814 //
       
   815 TInt CRtpManager::SendRtpPacket( TRtpId aTranStreamId,
       
   816                                  const TRtpSendHeader& aHeaderInfo,
       
   817                                  const TDesC8& aPayloadData,
       
   818                                  TRequestStatus& aStatus )
       
   819     {
       
   820     CRtpSession* rtpSession = GetSession( aTranStreamId ); 
       
   821 
       
   822     if ( rtpSession )
       
   823         {
       
   824         if ( iStandardRtp )
       
   825             {
       
   826             if (rtpSession->IsSrtp())
       
   827             	{
       
   828             	
       
   829  		        return static_cast<CRtpSessionSrtp*>
       
   830  		        	(rtpSession)->SendRtpPacket( aTranStreamId, aHeaderInfo,
       
   831                                               aPayloadData, aStatus );
       
   832  	
       
   833             	}
       
   834             else
       
   835             	{
       
   836             	return rtpSession->SendRtpPacket( aTranStreamId, aHeaderInfo,
       
   837                                               aPayloadData, aStatus );
       
   838             	}
       
   839            
       
   840             }
       
   841         else
       
   842             {
       
   843             return rtpSession->SendRtpPacket( aHeaderInfo, aPayloadData,
       
   844                                               aStatus );
       
   845         	}	
       
   846         }
       
   847         
       
   848     
       
   849     RTP_DEBUG_DETAIL( "CRtpManager::SendRtpPacket, Session not found" );
       
   850     
       
   851     return KErrNotFound;
       
   852     }
       
   853 
       
   854 // ---------------------------------------------------------------------------
       
   855 // TInt CRtpManager::SendRtpPacket()
       
   856 //
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 TInt CRtpManager::SendRtpPacket( TRtpId aTranStreamId,
       
   860                                  TRtpSequence aSequenceNum,
       
   861                                  const TRtpSendHeader& aHeaderInfo,
       
   862                                  const TDesC8& aPayloadData,
       
   863                                  TRequestStatus& aStatus )
       
   864     {
       
   865     CRtpSession* rtpSession = GetSession( aTranStreamId ); 
       
   866     TInt result( KErrNone );
       
   867     if ( rtpSession )
       
   868         {
       
   869 	        if ( iStandardRtp )
       
   870 	            {
       
   871             	if (rtpSession->IsSrtp())
       
   872 	            	{
       
   873 	            	
       
   874 	 		        result = static_cast<CRtpSessionSrtp*>
       
   875 	 		        	(rtpSession)->SendRtpPacket( aTranStreamId, aSequenceNum,
       
   876 	                                              aHeaderInfo, aPayloadData,
       
   877 	                                              aStatus );
       
   878 	 	
       
   879 	            	}
       
   880 	            else
       
   881 	            	{
       
   882 	            	result =  rtpSession->SendRtpPacket( aTranStreamId, aSequenceNum,
       
   883 	                                              aHeaderInfo, aPayloadData,
       
   884 	                                              aStatus );
       
   885 	            	}	            
       
   886 	            
       
   887 	            }
       
   888 	        else
       
   889 	            {
       
   890 	            
       
   891 	            RTP_DEBUG_DETAIL( "CRtpManager::SendRtpPacket, wrong version of function" );
       
   892 	            result = KErrNotSupported;
       
   893             }
       
   894         }
       
   895     else
       
   896         {
       
   897         
       
   898         RTP_DEBUG_DETAIL( "CRtpManager::SendRtpPacket, Session not found" );
       
   899         
       
   900         result = KErrNotFound;
       
   901         }
       
   902     return result;
       
   903     }
       
   904 
       
   905 
       
   906 // ---------------------------------------------------------------------------
       
   907 // TInt CRtpManager::SendData()
       
   908 //
       
   909 // ---------------------------------------------------------------------------
       
   910 //
       
   911 void CRtpManager::SendDataL( TRtpId aSessionId,
       
   912                        TBool aUseRTPSocket,
       
   913                        const TDesC8& aData,
       
   914                        TRequestStatus& aStatus )
       
   915     {
       
   916     CRtpSession* rtpSession = GetSession( aSessionId ); 
       
   917 
       
   918     if ( rtpSession )
       
   919         {
       
   920         if ( iStandardRtp )
       
   921             {
       
   922             rtpSession->SendData( aUseRTPSocket, aData, aStatus );
       
   923             }  
       
   924         else
       
   925             {
       
   926             User::Leave(KErrNotSupported);            
       
   927             }
       
   928         }
       
   929     else
       
   930         {
       
   931         
       
   932         RTP_DEBUG_DETAIL( "CRtpManager::SendData, Session not found" );
       
   933         User::Leave(KErrNotFound);
       
   934         }
       
   935         
       
   936     }
       
   937 
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 // CRtpManager::CancelSend()
       
   941 //
       
   942 // ---------------------------------------------------------------------------
       
   943 //
       
   944 void CRtpManager::CancelSend( TRtpId aSessionId )
       
   945     {
       
   946     CRtpSession* session = GetSession( aSessionId ); 
       
   947 
       
   948     if ( session )
       
   949         {
       
   950         session->CancelSend();
       
   951         }
       
   952     else
       
   953         {
       
   954         
       
   955         RTP_DEBUG_DETAIL( "CRtpManager::CancelSend, Session not found" );
       
   956         }
       
   957     }
       
   958 
       
   959 // ---------------------------------------------------------------------------
       
   960 // TInt CRtpManager::RegisterRtcpObserver()
       
   961 //
       
   962 // ---------------------------------------------------------------------------
       
   963 //
       
   964 TInt CRtpManager::RegisterRtcpObserver( TRtpId aSessionId,
       
   965                                         MRtcpObserver& aObserver )
       
   966     {
       
   967     TInt result( KErrGeneral );
       
   968     CRtpSession* session = GetSession( aSessionId );
       
   969     if ( session )
       
   970         {
       
   971         result = session->RegisterRtcpObserver( aObserver );
       
   972         }
       
   973     else
       
   974         {
       
   975         RTP_DEBUG_DETAIL( "CRtpManager::RegisterRtcpObserver, Session not found" );
       
   976         }
       
   977     return result;
       
   978     }
       
   979 
       
   980 // ---------------------------------------------------------------------------
       
   981 // TInt CRtpManager::UnregisterRtcpObserver()
       
   982 //
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 void CRtpManager::UnregisterRtcpObserver( TRtpId aSessionId )
       
   986     {
       
   987     CRtpSession* session = GetSession( aSessionId );
       
   988     if ( session )
       
   989         {
       
   990         session->UnregisterRtcpObserver();
       
   991         }
       
   992     else
       
   993         {
       
   994         RTP_DEBUG_DETAIL( "CRtpManager::UnregisterRtcpObserver, Session not found" );
       
   995         }
       
   996     }
       
   997 
       
   998 // ---------------------------------------------------------------------------
       
   999 // TInt CRtpManager::SendRtcpByePacket()
       
  1000 //
       
  1001 // ---------------------------------------------------------------------------
       
  1002 //
       
  1003 TInt CRtpManager::SendRtcpByePacketL( TRtpId aTranStreamId,
       
  1004                                      const TDesC8& aReason )
       
  1005     {
       
  1006     TInt result( KErrNotFound );
       
  1007     CRtpSession* session = GetSession( aTranStreamId );
       
  1008     
       
  1009     if ( session )
       
  1010         {
       
  1011         result = session->SendRtcpByePacketL( aTranStreamId, aReason );
       
  1012         }
       
  1013     else
       
  1014         {
       
  1015         RTP_DEBUG_DETAIL( "CRtpManager::SendRtcpByePacket, Session not found" );
       
  1016         }
       
  1017     return result;
       
  1018     }
       
  1019 
       
  1020 // ---------------------------------------------------------------------------
       
  1021 // TInt CRtpManager::SendRtcpAppPacketL()
       
  1022 //
       
  1023 // ---------------------------------------------------------------------------
       
  1024 //
       
  1025 TInt CRtpManager::SendRtcpAppPacketL( TRtpId aTranStreamId,
       
  1026                                      const TRtcpApp& aApp )
       
  1027     {
       
  1028     TInt result( KErrNotFound );
       
  1029     CRtpSession* session = GetSession( aTranStreamId );
       
  1030     
       
  1031     if ( session )
       
  1032         {
       
  1033         result = session->SendRtcpAppPacketL( aTranStreamId, aApp );
       
  1034         }
       
  1035     else
       
  1036         {
       
  1037         RTP_DEBUG_DETAIL( "CRtpManager::SendRtcpAppPacket, Session not found" );
       
  1038         }
       
  1039     return result;
       
  1040     }
       
  1041 
       
  1042 // ---------------------------------------------------------------------------
       
  1043 // TInt CRtpManager::SendRtcpSrPacketL()
       
  1044 // 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 //
       
  1047 TInt CRtpManager::SendRtcpSrPacketL( TRtpId aTranStreamId )
       
  1048     {
       
  1049     TInt result( KErrNotFound );
       
  1050     CRtpSession* session = GetSession( aTranStreamId );
       
  1051     
       
  1052     if ( session )
       
  1053         {
       
  1054         result = session->SendRtcpSrPacketL( aTranStreamId );
       
  1055         }
       
  1056     else
       
  1057         {
       
  1058        	RTP_DEBUG_DETAIL( "CRtpManager::SendRtcpSrPacket, Session not found" );
       
  1059         }
       
  1060     return result;
       
  1061     }
       
  1062 
       
  1063 // ---------------------------------------------------------------------------
       
  1064 // TInt CRtpManager::SendRtcpRrPacket()
       
  1065 // 
       
  1066 // ---------------------------------------------------------------------------
       
  1067 //
       
  1068 TInt CRtpManager::SendRtcpRrPacketL( TRtpId aRecvStreamId )
       
  1069     {
       
  1070     TInt result( KErrNotFound );
       
  1071     CRtpSession* session = GetSession( aRecvStreamId );
       
  1072     
       
  1073     if ( session )
       
  1074         {
       
  1075         result = session->SendRtcpRrPacketL( aRecvStreamId );
       
  1076         }
       
  1077     else
       
  1078         {
       
  1079         RTP_DEBUG_DETAIL( "CRtpManager::SendRtcpRrPacket, Session not found" );
       
  1080        	}
       
  1081     return result;
       
  1082     }
       
  1083 
       
  1084 // ---------------------------------------------------------------------------
       
  1085 // TRtpId CRtpManager::GetSessionId()
       
  1086 //
       
  1087 // ---------------------------------------------------------------------------
       
  1088 //
       
  1089 TRtpId CRtpManager::GetSessionId( TRtpId aStreamId )
       
  1090     {
       
  1091     CRtpSession* session = GetSession( aStreamId );
       
  1092 
       
  1093     if ( !session ) 
       
  1094         { 
       
  1095         RTP_DEBUG_DETAIL( "CRtpManager::GetSessionId, Session not found" );
       
  1096         
       
  1097         return KNullId;
       
  1098         }
       
  1099     else
       
  1100         {
       
  1101         return session->GetSessionId();
       
  1102         }
       
  1103     }
       
  1104 
       
  1105 // ---------------------------------------------------------------------------
       
  1106 // RSocket* CRtpManager::GetRtpSocket()
       
  1107 //
       
  1108 // ---------------------------------------------------------------------------
       
  1109 //
       
  1110 RSocket* CRtpManager::GetRtpSocket( TRtpId aSessionId )
       
  1111     {
       
  1112     RSocket* socket = NULL;
       
  1113     CRtpSession* session = GetSession( aSessionId );
       
  1114     if ( session )
       
  1115         {
       
  1116         socket = session->GetRtpSocket();
       
  1117         }
       
  1118     else
       
  1119         {
       
  1120         RTP_DEBUG_DETAIL( "CRtpManager::GetRtpSocket, Session not found" );
       
  1121         }
       
  1122     return socket;
       
  1123     }
       
  1124 
       
  1125 // ---------------------------------------------------------------------------
       
  1126 // RSocket* CRtpManager::GetRtcpSocket()
       
  1127 //
       
  1128 // ---------------------------------------------------------------------------
       
  1129 //
       
  1130 RSocket* CRtpManager::GetRtcpSocket( TRtpId aSessionId )
       
  1131     {
       
  1132     RSocket* socket = NULL;
       
  1133     CRtpSession* session = GetSession( aSessionId );
       
  1134     if ( session )
       
  1135         {
       
  1136         socket = session->GetRtcpSocket();
       
  1137         }
       
  1138     else
       
  1139         {
       
  1140         RTP_DEBUG_DETAIL( "CRtpManager::GetRtpSocket, Session not found" );
       
  1141         }
       
  1142     return socket;
       
  1143     }
       
  1144 
       
  1145 // ---------------------------------------------------------------------------
       
  1146 // TInt CRtpManager::GetStreamStatistics()
       
  1147 //
       
  1148 // ---------------------------------------------------------------------------
       
  1149 //
       
  1150 TInt CRtpManager::GetStreamStatistics( TRtpId aStreamId, TRtpPeerStat& aStat )
       
  1151     {
       
  1152     TInt result( KErrGeneral );
       
  1153     CRtpSession* session = GetSession( aStreamId );
       
  1154     if ( session )
       
  1155         {
       
  1156         result = session->GetStreamStatistics( aStreamId, aStat );
       
  1157         }
       
  1158     else
       
  1159         {
       
  1160         RTP_DEBUG_DETAIL( "CRtpManager::GetStreamStatistics, Session not found" );
       
  1161     	}
       
  1162     return result;
       
  1163     }
       
  1164 
       
  1165 // ---------------------------------------------------------------------------
       
  1166 // TUint32 CRtpManager::GetSamplingRate()
       
  1167 //
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //
       
  1170 TUint32 CRtpManager::GetSamplingRate( TRtpPayloadType aPayloadType )
       
  1171     {
       
  1172     TUint32 sampleRate;
       
  1173 
       
  1174     if ( aPayloadType >= KRtpMaxPayloadTypes )
       
  1175         {
       
  1176         RTP_DEBUG_DETAIL( "CRtpManager::GetSamplingRate, payload type out of range" );
       
  1177         return 0;
       
  1178         }
       
  1179 
       
  1180     sampleRate = iProfileRTPTimeRates[aPayloadType];
       
  1181 
       
  1182     if ( sampleRate != 0 )
       
  1183         {
       
  1184         sampleRate = KMicrosecondPerSecond / sampleRate;
       
  1185         }
       
  1186 
       
  1187     return sampleRate;
       
  1188     }
       
  1189 
       
  1190 // ---------------------------------------------------------------------------
       
  1191 // TInt CRtpManager::SetSamplingRate()
       
  1192 //
       
  1193 // ---------------------------------------------------------------------------
       
  1194 //
       
  1195 TInt CRtpManager::SetSamplingRate( TRtpPayloadType aPayloadType,
       
  1196                                    TUint32 aSampleRate )
       
  1197     {
       
  1198     if ( aPayloadType >= KRtpMaxPayloadTypes )
       
  1199         {
       
  1200         
       
  1201         RTP_DEBUG_DETAIL( "CRtpManager::SetSamplingRate, payload type out of range" );
       
  1202         
       
  1203         return KErrArgument;
       
  1204         }
       
  1205 
       
  1206     // update payload table
       
  1207     if ( aSampleRate != 0 )
       
  1208         {
       
  1209         iProfileRTPTimeRates[aPayloadType] =
       
  1210             KMicrosecondPerSecond / aSampleRate;
       
  1211         }
       
  1212     else
       
  1213         {
       
  1214         
       
  1215         RTP_DEBUG_DETAIL( "CRtpManager::SetSamplingRate, sample rate cannot be set to 0" );
       
  1216         
       
  1217         return KErrDivideByZero;
       
  1218         }
       
  1219 
       
  1220     return KErrNone;
       
  1221     }
       
  1222 
       
  1223 // ---------------------------------------------------------------------------
       
  1224 // TInt CRtpManager::SetRtcpParameters()
       
  1225 //
       
  1226 // ---------------------------------------------------------------------------
       
  1227 //
       
  1228 TInt CRtpManager::SetRtcpParameters( TRtpId aSessionId,
       
  1229                                      const TRtcpParams& aRtcpParams )
       
  1230     {
       
  1231     TInt result( KErrNotFound );
       
  1232     CRtpSession* session = GetSession( aSessionId );
       
  1233     if ( session )
       
  1234         {
       
  1235         result = session->SetRtcpParameters( aRtcpParams );
       
  1236         }
       
  1237     else
       
  1238         {
       
  1239         RTP_DEBUG_DETAIL( "CRtpManager::SetRtcpParameters, Session not found" );
       
  1240        	}
       
  1241     return result;
       
  1242     }
       
  1243 
       
  1244 // ---------------------------------------------------------------------------
       
  1245 // TInt CRtpManager::SuspendRtcpSending()
       
  1246 //
       
  1247 // ---------------------------------------------------------------------------
       
  1248 //
       
  1249 TInt CRtpManager::SuspendRtcpSending( TRtpId aSessionId,
       
  1250                                       TBool aAutoSending )
       
  1251     {
       
  1252     TInt result( KErrNotFound );
       
  1253     CRtpSession* session = GetSession( aSessionId );
       
  1254     if ( session )
       
  1255         {
       
  1256         if ( !aAutoSending )
       
  1257             {
       
  1258             // Don't send RTCP reports automatically
       
  1259             session->StopRtcpSending();
       
  1260             result = KErrNone;
       
  1261             }
       
  1262         else
       
  1263             {
       
  1264             // Resume sending RTCP reports automatically
       
  1265             session->ResumeRtcpSending();
       
  1266             result = KErrNone;
       
  1267             }
       
  1268         }
       
  1269     else
       
  1270         {
       
  1271         RTP_DEBUG_DETAIL( "CRtpManager::SuspendRtcpSending, Session not found" );
       
  1272         }
       
  1273     return result;
       
  1274     }
       
  1275 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 // TInt CRtpManager::IsRtcpSendingSuspended()
       
  1278 //
       
  1279 // ---------------------------------------------------------------------------
       
  1280 //
       
  1281 TInt CRtpManager::IsRtcpSendingSuspended( TRtpId aSessionId,
       
  1282                                           TBool& aAutoSending )
       
  1283     {
       
  1284     TInt result( KErrNotFound );
       
  1285     CRtpSession* session = GetSession( aSessionId );
       
  1286     if ( session )
       
  1287         {
       
  1288         result = session->IsRtcpSendingSuspended( aAutoSending );
       
  1289         }
       
  1290     else
       
  1291         {
       
  1292         RTP_DEBUG_DETAIL( "CRtpManager::IsRtcpSendingSuspended, Session not found" );
       
  1293         }
       
  1294     return result;
       
  1295     }
       
  1296 
       
  1297 
       
  1298 // ---------------------------------------------------------------------------
       
  1299 // CRtpSession* CRtpManager::GetSession()
       
  1300 //
       
  1301 // ---------------------------------------------------------------------------
       
  1302 //
       
  1303 CRtpSession* CRtpManager::GetSession( TRtpId aSessionId )
       
  1304     {
       
  1305     TUint uintAddress( 0 );
       
  1306     TInt ret( FindRtpObject( aSessionId, uintAddress ) );
       
  1307     CRtpSession* session = reinterpret_cast<CRtpSession*>( uintAddress );
       
  1308 
       
  1309     return ( ret != KErrNone ) ? NULL : session;
       
  1310     }
       
  1311 
       
  1312 // ---------------------------------------------------------------------------
       
  1313 // const TRtpId CRtpManager::AssignUniqueID()
       
  1314 // Assigns Unique ID to a RTP session or a stream
       
  1315 // ---------------------------------------------------------------------------
       
  1316 //
       
  1317 TRtpId CRtpManager::AssignUniqueID()
       
  1318     {
       
  1319     return ++iNumOfObjects;
       
  1320     }
       
  1321 
       
  1322 // ---------------------------------------------------------------------------
       
  1323 // TInt CRtpManager::AddRtpObject()
       
  1324 // Add Object to array
       
  1325 // ---------------------------------------------------------------------------
       
  1326 //
       
  1327 TInt CRtpManager::AddRtpObject( TArrayStore aArrayID )
       
  1328     {
       
  1329     TRAPD( ret, iSessionArray->AppendL( aArrayID ) );
       
  1330     return ret;
       
  1331     }
       
  1332 
       
  1333 // ---------------------------------------------------------------------------
       
  1334 // TInt CRtpManager::FindRtpObject()
       
  1335 // Find Object in array
       
  1336 // ---------------------------------------------------------------------------
       
  1337 //
       
  1338 TInt CRtpManager::FindRtpObject( const TRtpId aMagicKey,
       
  1339                                  TUint& aSessionAddress )
       
  1340     {
       
  1341     TKeyArrayFix magicKey( TArrayStore::iOffset, ECmpTUint );
       
  1342     TInt theIndex = -1;
       
  1343     TArrayStore match( aMagicKey );
       
  1344     if ( iSessionArray->Find( match, magicKey, theIndex ) == KErrNone
       
  1345          && theIndex >= 0 )
       
  1346         {
       
  1347         aSessionAddress = iSessionArray->At( theIndex ).GetSessionAddress();
       
  1348         }
       
  1349     else
       
  1350         {
       
  1351         return KErrNotFound;
       
  1352         }
       
  1353 
       
  1354     return KErrNone;
       
  1355     }
       
  1356 
       
  1357 // ---------------------------------------------------------------------------
       
  1358 // TInt CRtpManager::RemoveRtpObject()
       
  1359 // Delete Object TArrayStore object from array
       
  1360 // ---------------------------------------------------------------------------
       
  1361 //
       
  1362 TInt CRtpManager::RemoveRtpObject( const TRtpId aMagicKey,
       
  1363                                    const TObjectType aObjectType )
       
  1364     {
       
  1365     TKeyArrayFix magicKey( TArrayStore::iOffset, ECmpTUint );
       
  1366     TInt theIndex = -1;
       
  1367     CRtpSession* tempSession;
       
  1368     TArrayStore match( aMagicKey );
       
  1369 
       
  1370     if ( iSessionArray->Find( match, magicKey, theIndex ) != KErrNone )
       
  1371         {
       
  1372         return KErrNotFound;
       
  1373         }
       
  1374     if ( theIndex < 0 )
       
  1375         {
       
  1376         return KErrNotFound;
       
  1377         }
       
  1378 
       
  1379     if ( aObjectType == ESession )
       
  1380         {
       
  1381         TUint sessionAddr = iSessionArray->At( theIndex ).GetSessionAddress();
       
  1382         tempSession = reinterpret_cast<CRtpSession*>( sessionAddr );
       
  1383 
       
  1384         // delete all streams in session array for this session
       
  1385         TInt totalObjects = iSessionArray->Count();
       
  1386         
       
  1387         
       
  1388         RTP_DEBUG_DETAIL_DVALUE( "SESSION ARRAY: Closing Session with ID ", 
       
  1389                   iSessionArray->At( theIndex ).GetMagicKey() );
       
  1390         
       
  1391         
       
  1392         for ( TInt k = 0; k < totalObjects; k++ )
       
  1393             {
       
  1394             if ( ( iSessionArray->At( k ).GetObjectType() == EStream ) &&
       
  1395                  ( iSessionArray->At( k ).GetSessionAddress() == sessionAddr ) )
       
  1396                 {
       
  1397                 
       
  1398                	RTP_DEBUG_DETAIL_DVALUE( "SESSION ARRAY: Stream found in session ",
       
  1399                           tempSession->GetSessionId() );
       
  1400                 RTP_DEBUG_DETAIL_DVALUE( "SESSION ARRAY: Removed stream with ID ",
       
  1401                           iSessionArray->At( k ).GetMagicKey() );
       
  1402                 
       
  1403                 iSessionArray->Delete( k );
       
  1404                 totalObjects = iSessionArray->Count();
       
  1405                 k--;
       
  1406                 }
       
  1407             }
       
  1408         delete tempSession;
       
  1409         }
       
  1410     else // EStream
       
  1411         {
       
  1412         RTP_DEBUG_DETAIL_DVALUE( "SESSION ARRAY: Removed Stream with ID ", 
       
  1413                   iSessionArray->At( theIndex ).GetMagicKey() );
       
  1414         }
       
  1415     
       
  1416     iSessionArray->Delete( theIndex );
       
  1417     iSessionArray->Compress();
       
  1418 
       
  1419     return KErrNone;
       
  1420     }
       
  1421 
       
  1422 // ---------------------------------------------------------------------------
       
  1423 // CRtpManager::RemoveRtpAllObjects()
       
  1424 // Delete all Objects from array
       
  1425 // ---------------------------------------------------------------------------
       
  1426 //
       
  1427 void CRtpManager::RemoveRtpAllObjects()
       
  1428     {
       
  1429     
       
  1430    	RTP_DEBUG_DETAIL( "SESSION ARRAY: Closing all sessions" );
       
  1431    
       
  1432     if ( iSessionArray )
       
  1433 	    {
       
  1434 	    TInt totalObjects( iSessionArray->Count() );
       
  1435         for ( TInt index = 0; index < totalObjects; index++ )
       
  1436             {
       
  1437             if ( iSessionArray->At( index ).GetObjectType() == ESession )
       
  1438                 {
       
  1439                 
       
  1440                 RTP_DEBUG_DETAIL_DVALUE( "SESSION ARRAY: Closing session with ID ", 
       
  1441                           iSessionArray->At( index ).GetMagicKey() );
       
  1442                 
       
  1443                     
       
  1444                 CRtpSession* tempSession = reinterpret_cast<CRtpSession*>(
       
  1445                     ( iSessionArray->At( index ).GetSessionAddress() ) );
       
  1446                 delete tempSession; 
       
  1447                 }
       
  1448             }
       
  1449 
       
  1450 	    iSessionArray->Reset();
       
  1451 	    iSessionArray->Compress();
       
  1452         }
       
  1453     }
       
  1454 
       
  1455 // ---------------------------------------------------------------------------
       
  1456 // CRtpManager::GetIapId()
       
  1457 // 
       
  1458 // ---------------------------------------------------------------------------
       
  1459 //
       
  1460 TInt CRtpManager::GetIapId( TUint32& aIapId )
       
  1461 	{
       
  1462     TInt result( KErrNone );
       
  1463 	TUint count( 0 );
       
  1464 	TConnectionInfoBuf info;
       
  1465 
       
  1466     RTP_DEBUG_DETAIL( "CRtpManager::GetIapId()" );
       
  1467     
       
  1468     if ( !iConnPtr )
       
  1469         {
       
  1470         RTP_DEBUG_DETAIL( "Error: Connection not found"  );
       
  1471  	    result = KErrNotReady;
       
  1472         }
       
  1473     if ( result == KErrNone )
       
  1474         {
       
  1475     	result = iConnPtr->EnumerateConnections( count );
       
  1476         }
       
  1477     if ( result == KErrNone )
       
  1478         {
       
  1479     	if ( count > 0 )
       
  1480 	    	{
       
  1481     		result = iConnPtr->GetConnectionInfo( count, info );
       
  1482             if ( result == KErrNone )
       
  1483                 {
       
  1484                 aIapId = info().iIapId;
       
  1485                 }
       
  1486             else
       
  1487                 {
       
  1488                 RTP_DEBUG_DETAIL( "Error: Could not get connection info" );
       
  1489          	    }
       
  1490 		    }
       
  1491         else
       
  1492             {
       
  1493             RTP_DEBUG_DETAIL( "Error: No active connections found" );
       
  1494      	    result = KErrNotFound;
       
  1495             }
       
  1496         }
       
  1497     else
       
  1498         {
       
  1499         RTP_DEBUG_DETAIL( "Error: Could not enumerate active connections" );
       
  1500  	    }
       
  1501 
       
  1502     return result;
       
  1503 	}
       
  1504 
       
  1505 // ---------------------------------------------------------------------------
       
  1506 // CRtpManager::AddStreamToSession()
       
  1507 // 
       
  1508 // ---------------------------------------------------------------------------
       
  1509 //
       
  1510 TInt CRtpManager::AddStreamToSession(TRtpId aSessionId, 
       
  1511 									TRtpId aStreamId)
       
  1512 	{
       
  1513 	// add stream to the server array along with the session address
       
  1514     // to which it belongs.
       
  1515    
       
  1516     CRtpSession* session = GetSession( aSessionId );
       
  1517     if (session)
       
  1518     	{
       
  1519     	TArrayStore arrayData( aStreamId, ( TUint ) session, EStream );
       
  1520 	    TInt ret = AddRtpObject( arrayData );
       
  1521 
       
  1522     	if ( ret != KErrNone )
       
  1523 	        {
       
  1524 	        
       
  1525 	        RTP_DEBUG_DETAIL_DVALUE("CRtpManager::CreateStreamL, stream array error ", ret );
       
  1526 	           
       
  1527 	        return KErrArgument;
       
  1528 	        }
       
  1529     	return KErrNone;    
       
  1530 		}
       
  1531 	//Session is not found	
       
  1532 	return KErrNotFound;	
       
  1533     }
       
  1534 	
       
  1535 // ---------------------------------------------------------------------------
       
  1536 // CRtpManager::CheckSdesCName()
       
  1537 // 
       
  1538 // ---------------------------------------------------------------------------
       
  1539 //	
       
  1540 void CRtpManager::CheckSdesCName()
       
  1541 	{
       
  1542    	TRtpSdesParams aSdes;
       
  1543 	iDefaultSdes->GetSDES(aSdes);
       
  1544     if (!aSdes.iCName.Length())
       
  1545     	{
       
  1546     	//Set CName first in case it could not set CNAME to ip address
       
  1547     	aSdes.iCName.Set( _L8( "RtpUI user" ) );
       
  1548     	SetLocalSdes(aSdes);
       
  1549     	TInetAddr currentIP;
       
  1550     	TRAPD( error, currentIP = GetLocalIPAddressL() );
       
  1551     	if ( error == KErrNone && !currentIP.IsUnspecified() )
       
  1552         	{
       
  1553         	TBuf<KBufLength> addressbuffer;
       
  1554         	currentIP.Output( addressbuffer );
       
  1555         	TBuf8<KBufLength> addr;
       
  1556         	CnvUtfConverter::ConvertFromUnicodeToUtf8(addr,addressbuffer);
       
  1557         	if (addr.Compare(KNullDesC8))
       
  1558         		{
       
  1559         		aSdes.iCName.Set(addr);
       
  1560         		SetLocalSdes(aSdes);	
       
  1561         		}
       
  1562         	}
       
  1563     		
       
  1564 		}
       
  1565 	}
       
  1566 //  End of File