multimediacommscontroller/mmccsubcontroller/src/mccrtpmanager.cpp
changeset 0 1bce908db942
child 32 f2ed1fc4c163
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-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:    RTP Manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <srtpsession.h>
       
    23 #include "mccrtpmanager.h"
       
    24 #include "mccinternalcodecs.h"
       
    25 #include "mccrtpdatasink.h"
       
    26 #include "mccrtpdatasource.h"
       
    27 #include "mmccevents.h"
       
    28 #include "mccsubcontrollerlogs.h"
       
    29 #include "mccrtcpreceiver.h"
       
    30 #include "mccrtpkeepalivecontainer.h"
       
    31 #include "mccresources.h"
       
    32 #include "mccqoshandler.h"
       
    33 #include "mccinternaldef.h"
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // Default IP type-of-service value.
       
    38 const TInt KDefaultIpTOS = 184;
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMccRtpManager::CMccRtpManager
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CMccRtpManager::CMccRtpManager( 
       
    51     MAsyncEventHandler& aHandler, 
       
    52     MMccResources& aMccResources,
       
    53     TUint32 aMccSessionId ) : 
       
    54     iRtpSessionId( KNullId ), 
       
    55     iStreamArray( RArray<TRtpId>() ), 
       
    56     iEventHandler( aHandler ),
       
    57     iMccResources( aMccResources ),
       
    58     iIpTOS( KDefaultIpTOS ), 
       
    59     iLocalPort( KDefaultRtpPort ),
       
    60     iMccSessionId( aMccSessionId ),
       
    61     iDummyRcvStreamId( KNullId )
       
    62     {
       
    63 
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMccRtpManager::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CMccRtpManager::ConstructL()
       
    72     {
       
    73     __SUBCONTROLLER( "CMccRtpManager::ConstructL" )
       
    74 
       
    75     iRtpApi = CRtpAPI::NewL( *this );
       
    76     iRtcpReceiver = CMccRtcpReceiver::NewL( this, iEventHandler, iMccResources, *iRtpApi );
       
    77     iQosHandler = CMccQosHandler::NewL( *this );
       
    78     
       
    79     __SUBCONTROLLER( "CMccRtpManager::ConstructL exit" )
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CMccRtpManager::NewL
       
    84 // Static constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CMccRtpManager* CMccRtpManager::NewL( 
       
    88     MAsyncEventHandler& aHandler,
       
    89     MMccResources& aMccResources,
       
    90     TUint32 aMccSessionId
       
    91     )
       
    92     {
       
    93     CMccRtpManager* self = new (ELeave) CMccRtpManager( aHandler, aMccResources, 
       
    94                                                         aMccSessionId );
       
    95     CleanupStack::PushL( self );      
       
    96     self->ConstructL();           
       
    97     CleanupStack::Pop( self );
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMccRtpManager::~CMccRtpManager
       
   103 // Destructor
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CMccRtpManager::~CMccRtpManager()
       
   107     {
       
   108     __SUBCONTROLLER( "CMccRtpManager::~CMccRtpManager" )
       
   109     
       
   110     delete iRtcpReceiver;
       
   111     delete iRtpKeepaliveMechanism;
       
   112     
       
   113     if ( KNullId != iDummyRcvStreamId && iRtpApi )
       
   114         {
       
   115         iRtpApi->CloseStream( iDummyRcvStreamId );
       
   116         }
       
   117             
       
   118     if( KNullId != iRtpSessionId && iRtpApi )
       
   119         {
       
   120         iRtpApi->CloseSession( iRtpSessionId );
       
   121         iRtpApi->Close();
       
   122         }
       
   123     
       
   124     delete iSecSession;
       
   125     delete iRtpApi;
       
   126     delete iQosHandler;
       
   127     
       
   128     iStreamArray.Close();
       
   129     
       
   130     delete iCName;
       
   131     __SUBCONTROLLER( "CMccRtpManager::~CMccRtpManager, exit" )
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CMccRtpManager::CreateSessionL
       
   136 // Creates RTP session and adds session to SessionArray
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CMccRtpManager::CreateSessionL( 
       
   140     TUint& aPort, 
       
   141     TBool aEnableRTCP,
       
   142     TBool aSecurity, 
       
   143     TBool aIncreaseDefaultSocketSize )
       
   144     {
       
   145     __SUBCONTROLLER( "CMccRtpManager::CreateSessionL" )
       
   146     
       
   147     if( KNullId != iRtpSessionId )
       
   148         {
       
   149         User::Leave( KErrAlreadyExists );
       
   150         }
       
   151 
       
   152     TCreateSessionParams params;    
       
   153     params.iPriority = TCreateSessionParams::EPriorityStandard;    
       
   154     aEnableRTCP = ETrue;
       
   155     
       
   156     if ( aIncreaseDefaultSocketSize )
       
   157         {
       
   158         params.iSocketBufSize = KMccIncreasedRtpSocketSize;
       
   159         }
       
   160     __SUBCONTROLLER_INT1( "CMccRtpManager::CreateSessionL, socket size:", 
       
   161                           params.iSocketBufSize )
       
   162     
       
   163     TInetAddr localAddress = iRtpApi->GetLocalIPAddressL();
       
   164     
       
   165     if ( aSecurity )
       
   166         {
       
   167         iSecSession = CSRTPSession::NewL( localAddress );
       
   168         iRtpSessionId = iRtpApi->CreateSessionL( params, aPort, aEnableRTCP,
       
   169                                                  NULL, *iSecSession );
       
   170         }
       
   171     else
       
   172         {
       
   173         iRtpSessionId = iRtpApi->CreateSessionL( params, aPort, aEnableRTCP, NULL );
       
   174         }
       
   175         
       
   176     if( KNullId == iRtpSessionId )
       
   177         {
       
   178         User::Leave( KErrCouldNotConnect );
       
   179         }
       
   180     
       
   181     __ASSERT_ALWAYS( !iRtpKeepaliveMechanism, User::Leave( KErrAlreadyExists ) );     
       
   182     iRtpKeepaliveMechanism = 
       
   183         CMccRtpKeepaliveContainer::NewL( iEventHandler, 
       
   184                                          *iRtpApi, 
       
   185                                          iRtpSessionId );
       
   186     
       
   187     iLocalPort = aPort;
       
   188     iRtcpEnabled = aEnableRTCP;
       
   189     
       
   190     __SUBCONTROLLER( "CMccRtpManager::CreateSessionL, keepalive initialized" )
       
   191     
       
   192     iRtcpReceiver->HandleReceiving( iRtpSessionId, iRtcpEnabled );
       
   193     
       
   194     __SUBCONTROLLER( "CMccRtpManager::CreateSessionL, exit" )
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CMccRtpManager::CloseSession
       
   199 // Closes RTP session
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CMccRtpManager::CloseSession()
       
   203     {
       
   204     __SUBCONTROLLER( "CMccRtpManager::CloseSession" )
       
   205     if ( KNullId != iRtpSessionId ) 
       
   206         {
       
   207         if ( iRtpKeepaliveMechanism )
       
   208             {
       
   209             iRtpKeepaliveMechanism->StopAll();
       
   210             }
       
   211         
       
   212         iRtpApi->CloseSession( iRtpSessionId );
       
   213         iRtpApi->Close();
       
   214         iStreamArray.Reset();
       
   215         
       
   216         iRtpSessionId = KNullId;
       
   217         
       
   218         if ( iQosHandler->QoSEnabled() )
       
   219             {
       
   220             iQosHandler->DisableQoS();
       
   221             }
       
   222         }
       
   223     __SUBCONTROLLER( "CMccRtpManager::CloseSession, exit" )
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CMccRtpManager::GetRtpReference
       
   228 // Returns RTPApi reference
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 CRtpAPI* CMccRtpManager::GetRtpReferenceL( )
       
   232     {
       
   233     if ( !IsOpen() ) 
       
   234         {
       
   235         User::Leave( KErrNotFound );
       
   236         }
       
   237     return iRtpApi;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CMccRtpManager::SetRemoteAddress
       
   242 // Sets RTP Remote Address
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TInt CMccRtpManager::SetRemoteAddress( const TInetAddr& aRemoteAddress )
       
   246     {
       
   247     __SUBCONTROLLER( "CMccRtpManager::SetRemoteAddress" )
       
   248     TInt err( KErrNotFound );
       
   249     if ( KNullId != iRtpSessionId ) 
       
   250         {   
       
   251         // Do only if address has changed
       
   252         err =( iRemoteAddress.Address() == aRemoteAddress.Address() && 
       
   253                iRemoteAddress.Port() == aRemoteAddress.Port() ) ? KErrNone : err;
       
   254         if ( err )
       
   255             { 
       
   256             __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, setting addr:", 
       
   257                                   aRemoteAddress.Address() )
       
   258             __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, setting port:", 
       
   259                                   aRemoteAddress.Port() )
       
   260             
       
   261             err = iRtpApi->SetRemoteAddress( iRtpSessionId, aRemoteAddress );
       
   262             if ( !err )
       
   263                 {
       
   264                 iRemoteAddress.SetAddress( aRemoteAddress.Address() );
       
   265                 iRemoteAddress.SetPort( aRemoteAddress.Port() );
       
   266                 if ( iRtpKeepaliveMechanism )
       
   267                     {
       
   268                     err = iRtpKeepaliveMechanism->RemoteAddressSet();
       
   269                     }
       
   270                 }
       
   271             }
       
   272         }
       
   273     __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, exit with err", err )
       
   274     return err;
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CMccRtpManager::SetRemoteRtcpAddress
       
   279 // Sets RTP Remote Address
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 TInt CMccRtpManager::SetRemoteRtcpAddr( const TInetAddr& aRemoteAddress )
       
   283     {
       
   284     __SUBCONTROLLER( "CMccRtpManager::SetRemoteRtcpAddress" )
       
   285     TInt err( KErrNotFound );
       
   286     if ( KNullId != iRtpSessionId ) 
       
   287         {   
       
   288         // Do only if address has changed
       
   289         err =( iRemoteRtcpAddr.Address() == aRemoteAddress.Address() && 
       
   290                iRemoteRtcpAddr.Port() == aRemoteAddress.Port() ) ? KErrNone : err;
       
   291         __SUBCONTROLLER_INT1( "Remote RtcpPort", aRemoteAddress.Port() )
       
   292         __SUBCONTROLLER_INT1( "Saved Remote RtcpPort", iRemoteAddress.Port() )
       
   293         if ( err )
       
   294             { 
       
   295             __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, setting addr:", 
       
   296                                   aRemoteAddress.Address() )
       
   297             __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, setting port:", 
       
   298                                   aRemoteAddress.Port() )
       
   299             
       
   300             err = iRtpApi->SetRemoteRtcpAddress( iRtpSessionId, aRemoteAddress );
       
   301             if ( !err )
       
   302                 {
       
   303                 iRemoteRtcpAddr.SetAddress( aRemoteAddress.Address() );
       
   304                 iRemoteRtcpAddr.SetPort( aRemoteAddress.Port() );
       
   305                 __SUBCONTROLLER_INT1( "Remote RtcpPort", aRemoteAddress.Port() )
       
   306                 }
       
   307             }
       
   308         }
       
   309     __SUBCONTROLLER_INT1( "CMccRtpManager::SetRemoteAddress, exit with err", err )
       
   310     return err;
       
   311     }
       
   312 // -----------------------------------------------------------------------------
       
   313 // CMccRtpManager::SetIpTOS
       
   314 // Sets TOS flag, must be called before StartSession
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CMccRtpManager::SetIpTOS( TInt aIpTOS ) 
       
   318     {
       
   319     iIpTOS = aIpTOS;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CMccRtpManager::StartSession
       
   324 // Starts RTP session
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CMccRtpManager::StartSessionL()
       
   328     {
       
   329     __SUBCONTROLLER( "CMccRtpManager::StartSessionL" )
       
   330     if ( KNullId != iRtpSessionId ) 
       
   331         {
       
   332         __SUBCONTROLLER( "CMccRtpManager::StartSessionL, session exists" )
       
   333         
       
   334 		RSocket* socketPtr = iRtpApi->GetRtpSocket( iRtpSessionId );
       
   335 		
       
   336 		if( !socketPtr )
       
   337 		    {
       
   338 		    __SUBCONTROLLER( "CMccRtpManager::StartSessionL, no socket!" )
       
   339             #ifdef TEST_EUNIT            
       
   340             // The stub for RTP API returns a NULL socket pointer. Just pretend
       
   341             // everything is fine.
       
   342             return;            
       
   343             #else
       
   344 		    User::Leave( KErrNotReady );
       
   345             #endif
       
   346 		    }
       
   347 		else
       
   348 		    {
       
   349             User::LeaveIfError( iRtpApi->StartSession( iRtpSessionId ) );      
       
   350             
       
   351             __SUBCONTROLLER_INT1( "CMccRtpManager::StartSessionL, iptos:", iIpTOS )
       
   352              
       
   353             User::LeaveIfError( socketPtr->SetOpt( KSoIpTOS, KSolInetIp, iIpTOS ) );
       
   354             User::LeaveIfError( socketPtr->SetOpt( KSoUdpReceiveICMPError, KSolInetUdp, 1 ) );
       
   355             
       
   356             if ( !iQosHandler->QoSEnabled() )
       
   357                 {
       
   358                 // These has to be set before enabling QoS
       
   359                 iQosHandler->SetSubConnectionParams( iConnection,
       
   360                                              iSocketServ,
       
   361                                              *socketPtr );
       
   362                                                 
       
   363                 // If we cannot enable QoS for some reason, we should not
       
   364                 // consider it as a fatal error. If error happens, then
       
   365                 // disable qos. This will clean up some unneeded resources.
       
   366                 // Also this leads to retries when streams are created.
       
   367                 TRAPD( err, iQosHandler->EnableQosL() );
       
   368                 if ( KErrNone != err )
       
   369                     {
       
   370                     __SUBCONTROLLER_INT1( "CMccRtpManager::StartSessionL QOS:", err )
       
   371             
       
   372                     iQosHandler->DisableQoS();
       
   373                     }
       
   374                 }
       
   375 		    }
       
   376         }
       
   377     else
       
   378         {
       
   379         User::Leave( KErrNotFound );
       
   380         }
       
   381     
       
   382     __SUBCONTROLLER( "CMccRtpManager::StartSessionL, exit" ) 
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CMccRtpManager::Initialize
       
   387 // Opens RTPApi and starts connection
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CMccRtpManager::InitializeL( TRequestStatus& aStatus, TInt aIapId )
       
   391     {
       
   392     TInt err = iRtpApi->OpenL( iRtpSdes, NULL, &iSocketServ, &iConnection );
       
   393     if ( KErrNone == err ) 
       
   394         {
       
   395         User::LeaveIfError( iRtpApi->StartConnection( aStatus, aIapId ) );
       
   396         }
       
   397     else
       
   398         {
       
   399         User::Leave( err );
       
   400         }
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CMccRtpManager::CheckStreamExists
       
   405 // Checks that stream exists
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 TBool CMccRtpManager::CheckStreamExists( const TRtpId& aStreamId ) const
       
   409     {
       
   410     TInt index = iStreamArray.Find( aStreamId );
       
   411     
       
   412     if( KErrNotFound == index )
       
   413         {
       
   414         return EFalse;
       
   415         }
       
   416     else
       
   417         {
       
   418         return ETrue;
       
   419         }
       
   420     }
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // CMccRtpManager::IsOpen
       
   424 // Checks that RTPApi is opened
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TBool CMccRtpManager::IsOpen() const
       
   428     {
       
   429     if ( iRtpApi->GetRtpSocket( iRtpSessionId ) ) 
       
   430         {
       
   431         return ETrue;
       
   432         }
       
   433     else 
       
   434         {
       
   435         return EFalse;
       
   436         }
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CMccRtpManager::RemoveStreamFromArray
       
   441 // Removes RTP stream from stream array
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CMccRtpManager::RemoveStreamFromArray( const TRtpId& aStreamId )
       
   445     {
       
   446     const TInt index( iStreamArray.Find( aStreamId ) );
       
   447     if( KErrNotFound != index )
       
   448         {
       
   449         iStreamArray.Remove( index );
       
   450         }
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CMccRtpManager::SessionId
       
   455 // Returns the Session ID for this object
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 TRtpId CMccRtpManager::SessionId() const
       
   459     {
       
   460     return iRtpSessionId;
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CMccRtpManager::ErrorNotify
       
   465 // Error callback.
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CMccRtpManager::ErrorNotify( TInt aErrCode )
       
   469     {
       
   470     if ( KErrNone != aErrCode )
       
   471         {
       
   472         __SUBCONTROLLER_INT1( "CMccRtpManager::ErrorNotify, error", aErrCode )
       
   473         
       
   474         // Report all errors coming from here as rtp category stream errors
       
   475         // In HW when remote end drops from network, this function will be
       
   476         // called with KErrHostUnreach (-191) and in some cases this will return
       
   477         // as KErrGeneral with DTMF's. KErrCouldNotConnect error is received in
       
   478         // ICMP port unreachable situation. In these cases, handle just the 
       
   479         // KErrHostUnreach and KErrCouldNotConnect.
       
   480         if ( KErrHostUnreach == aErrCode || KErrCouldNotConnect == aErrCode )
       
   481             {
       
   482             TMccEvent event;
       
   483             event.iErrorCode = KErrHostUnreach;
       
   484             event.iEventCategory = KMccEventCategoryRtp;
       
   485             event.iEventType = KMccStreamError;
       
   486             
       
   487             // Use whatever internal uid
       
   488             TMccInternalEvent internalEvent( KMccRtpSourceUid, 
       
   489                                      EMccInternalEventNone,
       
   490                                      event );
       
   491             
       
   492             iEventHandler.SendEventToClient( internalEvent );
       
   493             }
       
   494         }
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // CMccRtpManager::CreateTransmitStreamL
       
   499 // Creates a new transmit stream based on given parameters
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 TUint32 CMccRtpManager::CreateTransmitStreamL( MDataSink& aSink, 
       
   503     const TMccCodecInfo& aCodecInfo )
       
   504     {
       
   505     TUint32 streamId( 0 );
       
   506 
       
   507     if( aCodecInfo.iPayloadType < KMccPayloadTypeMax )
       
   508         {
       
   509         CMccRtpDataSink& dSink = static_cast<CMccRtpDataSink&>( aSink );
       
   510         TMccRtpSessionParams sessParams( iRtpApi, 
       
   511                                          iRtpSessionId, 
       
   512                                          iRtcpEnabled, 
       
   513                                          iRtpKeepaliveMechanism,
       
   514                                          iSecSession );
       
   515         
       
   516         dSink.SetSessionParamsL( sessParams );
       
   517         
       
   518         TMccCodecInfoBuffer infoBuffer( aCodecInfo );
       
   519         dSink.ConfigureL( infoBuffer );
       
   520         
       
   521         UpdateL( &aCodecInfo );
       
   522         }
       
   523     else
       
   524         {
       
   525         User::Leave( KErrArgument );
       
   526         }
       
   527     return streamId;
       
   528     }
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // CMccRtpManager::CreateReceiveStreamL
       
   532 // Creates a new receive stream based on given parameters
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 TUint32 CMccRtpManager::CreateReceiveStreamL( MDataSource& aSource, 
       
   536     const TMccCodecInfo& aCodecInfo )
       
   537     {
       
   538     TUint32 streamId( 0 );
       
   539 
       
   540     if( aCodecInfo.iPayloadType < KMccPayloadTypeMax )
       
   541         {
       
   542         CMccRtpDataSource& dSource = static_cast<CMccRtpDataSource&>( aSource );
       
   543         TMccRtpSessionParams sessParams( iRtpApi, 
       
   544                                          iRtpSessionId, 
       
   545                                          iRtcpEnabled,
       
   546                                          iRtpKeepaliveMechanism,
       
   547                                          iSecSession );
       
   548         
       
   549         dSource.SetSessionParamsL( sessParams );
       
   550         
       
   551         TMccCodecInfoBuffer infoBuffer( aCodecInfo );
       
   552         dSource.ConfigureL( infoBuffer );
       
   553         
       
   554         UpdateL( &aCodecInfo );
       
   555         }
       
   556     else
       
   557         {
       
   558         User::Leave( KErrArgument );
       
   559         }
       
   560 
       
   561     return streamId;
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CMccRtpManager::SetRTCPSendReceive
       
   566 // Enables/disables automatic transmission and receiving of RTCP packets
       
   567 // in a session.
       
   568 // -----------------------------------------------------------------------------
       
   569 //
       
   570 TInt CMccRtpManager::SetRTCPSendReceive( TBool aEnableRtcp )
       
   571     {
       
   572     __SUBCONTROLLER( "CMccRtpManager::SetRTCPSendReceive" )
       
   573     
       
   574     // Check that session exists
       
   575     TInt err( KErrNotFound );
       
   576     if ( iRtpSessionId != KNullId ) 
       
   577         {    
       
   578         __SUBCONTROLLER_INT1( "CMccRtpManager::SetRTCPSendReceive, enable:", aEnableRtcp )
       
   579         
       
   580         iRtcpEnabled = aEnableRtcp;
       
   581         
       
   582         err = iRtcpReceiver->HandleReceiving( iRtpSessionId, iRtcpEnabled );
       
   583         if ( !err )
       
   584             {
       
   585             __SUBCONTROLLER( "CMccRtpManager::SetRTCPSendReceive, calling rtp api" )
       
   586             err = iRtpApi->SuspendRtcpSending( iRtpSessionId, aEnableRtcp );
       
   587             }
       
   588         }
       
   589     return err;
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CMccRtpManager::SetLinkId
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 void CMccRtpManager::SetLinkId( TUint32 aLinkId )
       
   597     {
       
   598     iLinkId = aLinkId;
       
   599     }
       
   600     
       
   601 // -----------------------------------------------------------------------------
       
   602 // CMccRtpManager::UpdateL
       
   603 // Creates dummy receive stream if rtp session does not have any receive
       
   604 // stream (RTP source) or removes the dummy receive stream if RTP source
       
   605 // exists.
       
   606 // -----------------------------------------------------------------------------
       
   607 //    
       
   608 void CMccRtpManager::UpdateL( const TMccCodecInfo* aCodecInfo )
       
   609     {
       
   610     __SUBCONTROLLER( "CMccRtpManager::UpdateL" )
       
   611     
       
   612     MDataSource* source = 0;
       
   613     MDataSink* sink = 0;
       
   614     TInt err = 
       
   615         iMccResources.FindResource( iLinkId, 0, KMccRtpSourceUid, &source, &sink );
       
   616         
       
   617     if ( !err && source )
       
   618         {
       
   619         if ( iDummyRcvStreamId != KNullId )
       
   620             {
       
   621             __SUBCONTROLLER( "CMccRtpManager::UpdateL, dummy rcv stream not needed" )
       
   622             
       
   623             iRtpApi->CloseStream( iDummyRcvStreamId );
       
   624             iDummyRcvStreamId = KNullId;
       
   625             }
       
   626         }
       
   627     else
       
   628         {
       
   629         if ( iDummyRcvStreamId == KNullId && aCodecInfo )
       
   630             {
       
   631             __SUBCONTROLLER( "CMccRtpManager::UpdateL, dummy rcv stream needed" )
       
   632             
       
   633             TRcvStreamParams rcvParams;
       
   634             rcvParams.iPayloadType = aCodecInfo->iPayloadType;
       
   635             iDummyRcvStreamId = iRtpApi->CreateReceiveStreamL( iRtpSessionId, rcvParams );
       
   636             if ( KNullId == iDummyRcvStreamId )
       
   637                 {
       
   638                 __SUBCONTROLLER( "CMccRtpDataSource::UpdateL, could not create dummy rcv stream" )
       
   639                 
       
   640                 User::Leave( KErrCouldNotConnect );
       
   641                 }
       
   642             }
       
   643         }
       
   644         
       
   645     __SUBCONTROLLER( "CMccRtpManager::UpdateL, exit" )
       
   646     }
       
   647     
       
   648 // -----------------------------------------------------------------------------
       
   649 // CMccRtpManager::GetLocalIpAddressesL
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void CMccRtpManager::GetLocalIpAddressesL( TMccCreateLink& aClientData )
       
   653     {
       
   654     __SUBCONTROLLER( "CMccRtpManager::GetLocalIpAddressesL" )
       
   655     
       
   656     __ASSERT_ALWAYS( KNullId != iRtpSessionId && iRtpApi, User::Leave( KErrNotReady ) );
       
   657     
       
   658     RSocket* rtpSocket( iRtpApi->GetRtpSocket( iRtpSessionId ) );
       
   659     RSocket* rtcpSocket( iRtpApi->GetRtcpSocket( iRtpSessionId ) );
       
   660     TInetAddr localAddr( iRtpApi->GetLocalIPAddressL() );
       
   661     
       
   662     if ( rtpSocket )
       
   663         {
       
   664         if ( KAfInet6 == localAddr.Family() )
       
   665             {
       
   666             aClientData.iLocalAddress.SetAddress( localAddr.Ip6Address() );
       
   667             }
       
   668         else
       
   669             {
       
   670             aClientData.iLocalAddress.SetAddress( localAddr.Address() );
       
   671             }
       
   672         
       
   673         aClientData.iLocalAddress.SetPort( rtpSocket->LocalPort() );
       
   674         }
       
   675     else
       
   676         {
       
   677         User::Leave( KErrGeneral );
       
   678         }
       
   679     
       
   680     if ( iRtcpReceiver && rtcpSocket )
       
   681         {
       
   682         if ( KAfInet6 == localAddr.Family() )
       
   683             {
       
   684             aClientData.iLocalRtcpAddress.SetAddress( localAddr.Ip6Address() );
       
   685             }
       
   686         else
       
   687             {
       
   688             aClientData.iLocalRtcpAddress.SetAddress( localAddr.Address() );
       
   689             }
       
   690         
       
   691         aClientData.iLocalRtcpAddress.SetPort( rtcpSocket->LocalPort() );
       
   692         }
       
   693     
       
   694     __SUBCONTROLLER( "CMccRtpManager::GetLocalIpAddressesL, exit" )
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CMccRtpManager::SetCNameL
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CMccRtpManager::SetCNameL( const TDesC8& aCName )
       
   702     {
       
   703     HBufC8* cname = aCName.AllocLC();
       
   704     delete iCName;
       
   705     iCName = cname;
       
   706     CleanupStack::Pop( cname );
       
   707         
       
   708     iRtpSdes.iCName.Set( *iCName );
       
   709         
       
   710     iRtpApi->SetLocalSdes( iRtpSdes );
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // CMccRtpManager::MccSessionId
       
   715 // -----------------------------------------------------------------------------
       
   716 //
       
   717 TUint32 CMccRtpManager::MccSessionId() const
       
   718     {
       
   719     return iMccSessionId;
       
   720     }
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CMccRtpManager::QoSParamEvent()
       
   724 // From MMccQosEventObserver
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 void CMccRtpManager::QoSParamEvent( TInt aError, TUint32 /*aEvent*/ )
       
   728     {
       
   729     __SUBCONTROLLER_INT1( "CMccRtpManager::QoSParamEvent aError:", aError )
       
   730     
       
   731     aError = aError;
       
   732     }
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // CMccRtpManager::QoSConnEvent()
       
   736 // From MMccQosEventObserver
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 void CMccRtpManager::QoSConnEvent( TInt aError, TUint32 /*aEvent*/ )
       
   740     {
       
   741     __SUBCONTROLLER_INT1( "CMccRtpManager::QoSConnEvent aError:", aError )
       
   742     
       
   743     aError = aError;
       
   744     }
       
   745