natfw/tsrc/natfwtestconsoles/natfwtestconsole/src/mccsession.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mccsession.h"
       
    22 
       
    23 #include "natfwconnectivityapi.h"
       
    24 #include <mmcccodecinformation.h>
       
    25 #include <mmccinterface.h>
       
    26 #include <e32debug.h>
       
    27 #include "natfwtestconsolelogs.h"
       
    28 #include "mcclink.h"
       
    29 #include "mccmediastream.h"
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CMccSession::ConstructL
       
    33 // ---------------------------------------------------------------------------
       
    34 // 
       
    35 void CMccSession::ConstructL()
       
    36     {
       
    37     __NATFWTESTCONSOLE( "CMccSession::ConstructL" )
       
    38 
       
    39     iMccInterface = CMccInterface::NewL( *this );
       
    40     
       
    41     // Create Mcc session
       
    42     User::LeaveIfError( iMccInterface->CreateSession( iMccSessionId ) );
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CMccSession::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 //     
       
    49 CMccSession* CMccSession::NewL( TUint aIapId )
       
    50     {
       
    51     CMccSession* self = new( ELeave ) CMccSession( aIapId );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CMccSession::CMccSession
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 CMccSession::CMccSession( TUint aIapId ) :
       
    63     iIapId( aIapId )
       
    64     {
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CMccSession::~CMccSession
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 CMccSession::~CMccSession()
       
    72     {
       
    73     iMccStreams.ResetAndDestroy();
       
    74     iMccLinks.ResetAndDestroy();
       
    75     
       
    76     TInt error = iMccInterface->CloseSession( iMccSessionId );
       
    77     if ( error )
       
    78         {
       
    79         __NATFWTESTCONSOLE_INT1(
       
    80             "CCMccSession::~CMccSession Session closing error ", error )
       
    81         }
       
    82     delete iMccInterface;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CMccSession::CreateLinkL
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CMccSession::CreateLinkL( TInt32& aLinkId, TInt aLinkType,
       
    90     TInetAddr& aDestAddr, TRequestStatus& aStatus )
       
    91     {
       
    92     iObserverStatus = &aStatus;
       
    93     
       
    94     CMccLink* link = CMccLink::NewL( aLinkType, iIapId, this );
       
    95     CleanupStack::PushL( link );
       
    96     iMccLinks.AppendL( link );
       
    97     
       
    98     link->CreateLinkL( aLinkId, aDestAddr, aStatus );
       
    99     CleanupStack::Pop( link );
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CMccSession::CreateLinkL
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CMccSession::CreateLinkL( TInt32& aLinkId, TInt aLinkType,
       
   107     TInetAddr& aDestAddr, TUint aRtcpPort, TRequestStatus& aStatus )
       
   108     {
       
   109     iObserverStatus = &aStatus;
       
   110     
       
   111     CMccLink* link = CMccLink::NewL( aLinkType, iIapId, this );
       
   112     CleanupStack::PushL( link );
       
   113     iMccLinks.AppendL( link );
       
   114     
       
   115     link->CreateLinkL( aLinkId, aDestAddr, aRtcpPort, aStatus );
       
   116     CleanupStack::Pop( link );
       
   117     } 
       
   118  
       
   119 // ---------------------------------------------------------------------------
       
   120 // CMccSession::CreateMediaStreamL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CMccSession::CreateMediaStreamL( TInt32& aStreamId, TInt32 aLinkId,
       
   124     TStreamDirection aStreamDirection, TRequestStatus& aStatus )
       
   125     {
       
   126     iObserverStatus = &aStatus;
       
   127     
       
   128     CMccMediaStream* stream = CMccMediaStream::NewL( LinkByIdL( aLinkId ),
       
   129         this, aStreamDirection );
       
   130     CleanupStack::PushL( stream );
       
   131     
       
   132     iMccStreams.AppendL( stream );
       
   133     
       
   134     stream->CreateStreamL( aStreamId, aStatus );
       
   135     CleanupStack::Pop( stream );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CMccSession::LinkByIdL
       
   140 // ---------------------------------------------------------------------------
       
   141 // 
       
   142 CMccLink* CMccSession::LinkByIdL( TInt32 aLinkId )
       
   143     {
       
   144     TInt count = iMccLinks.Count();
       
   145     
       
   146     for ( TInt i( 0 ); i < count; ++i )
       
   147         {
       
   148         if ( aLinkId == iMccLinks[i]->LinkId() )
       
   149             {
       
   150             return iMccLinks[i];
       
   151             }
       
   152         }
       
   153     User::Leave( KErrNotFound );
       
   154     return NULL;
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CMccSession::StreamByIdL
       
   159 // ---------------------------------------------------------------------------
       
   160 //     
       
   161 CMccMediaStream* CMccSession::StreamByIdL( TInt32 aStreamId )
       
   162     {
       
   163     TInt count = iMccStreams.Count();
       
   164     
       
   165     for ( TInt i( 0 ); i < count; ++i )
       
   166         {
       
   167         if ( aStreamId == iMccStreams[i]->StreamId() )
       
   168             {
       
   169             return iMccStreams[i];
       
   170             }
       
   171         }
       
   172     User::Leave( KErrNotFound );
       
   173     return NULL; 
       
   174     }
       
   175     
       
   176 // ---------------------------------------------------------------------------
       
   177 // CMccSession::CloseLinkL
       
   178 // ---------------------------------------------------------------------------
       
   179 // 
       
   180 void CMccSession::CloseLinkL( TInt32 aLinkId )
       
   181     {
       
   182     
       
   183     CMccLink* link = LinkByIdL( aLinkId );
       
   184     
       
   185     User::LeaveIfError( link->Close() );
       
   186     
       
   187     TInt index = iMccLinks.FindL( link );
       
   188     
       
   189     iMccLinks.Remove( index );
       
   190     delete link;
       
   191     link = NULL;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CMccSession::CloseMediaStreamL
       
   196 // ---------------------------------------------------------------------------
       
   197 //       
       
   198 void CMccSession::CloseMediaStreamL( TInt32 aStreamId )
       
   199     {
       
   200     CMccMediaStream* stream = StreamByIdL( aStreamId );
       
   201     
       
   202     User::LeaveIfError( stream->Delete() );
       
   203     
       
   204     TInt index = iMccStreams.FindL( stream );
       
   205     
       
   206     iMccStreams.Remove( index );
       
   207     delete stream;
       
   208     stream = NULL;
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CMccSession::StartStreamL
       
   213 // ---------------------------------------------------------------------------
       
   214 //   
       
   215 void CMccSession::StartStreamL( TInt32 aStreamId,
       
   216     TRequestStatus& aStatus )
       
   217     {
       
   218     if ( ERtcpStreamPrepared  == StreamByIdL( aStreamId )->State() )
       
   219         {
       
   220         iObserverStatus = &aStatus;
       
   221         StreamByIdL( aStreamId )->StartStreamL( aStatus );
       
   222         }
       
   223     else
       
   224         {
       
   225         User::Leave( KErrNotReady );
       
   226         }
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CMccSession::SetRemoteAddressL
       
   231 // ---------------------------------------------------------------------------
       
   232 // 
       
   233 void CMccSession::SetRemoteAddressL( TInt32 aLinkId, TInetAddr& aDestAddr )
       
   234     {
       
   235     __NATFWTESTCONSOLE( "CMccSession::SetRemoteAddressL" )
       
   236     
       
   237     LinkByIdL( aLinkId )->SetRemoteAddressL( aDestAddr );
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CMccSession::SetRemoteAddressL
       
   242 // ---------------------------------------------------------------------------
       
   243 // 
       
   244 void CMccSession::SetRemoteAddressL( TInt32 aLinkId, TInetAddr& aDestAddr,  
       
   245     TUint aRtcpPort )
       
   246     {
       
   247     __NATFWTESTCONSOLE( "CMccSession::SetRemoteAddressL + rtcp" )
       
   248     
       
   249     LinkByIdL( aLinkId )->SetRemoteAddressL( aDestAddr, aRtcpPort );
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CMccSession::MccInterface
       
   254 // ---------------------------------------------------------------------------
       
   255 // 
       
   256 CMccInterface* CMccSession::MccInterface()
       
   257     {
       
   258     return iMccInterface;
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CMccSession::MccSessionId
       
   263 // ---------------------------------------------------------------------------
       
   264 // 
       
   265 TUint32 CMccSession::MccSessionId()
       
   266     {
       
   267     return iMccSessionId;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CMccSession::NetSettings
       
   272 // ---------------------------------------------------------------------------
       
   273 // 
       
   274 TMccNetSettings& CMccSession::NetSettings()
       
   275     {
       
   276     return iNetSettings;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // From MMccCtrlObserver
       
   281 // CMccSession::MccEventReceived
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CMccSession::MccEventReceived( const TMccEvent& aEvent )
       
   285     {
       
   286     __NATFWTESTCONSOLE( "CMccSession::MccEventReceived" )
       
   287     RDebug::Print( _L("TEST PRINT: Event: %u, Category: %u, Error: %u"),
       
   288             aEvent.iEventType, aEvent.iEventCategory, aEvent.iErrorCode );
       
   289     if ( KMccLinkCreated == aEvent.iEventType )
       
   290         {
       
   291         TMccNetSettingsPackage package;
       
   292         package.Copy( aEvent.iEventData );
       
   293         TBuf<50> localAddr;
       
   294         TBuf<50> localPublicAddr;
       
   295     
       
   296         iNetSettings = package();
       
   297 
       
   298         User::RequestComplete( iObserverStatus, KErrNone );
       
   299         }
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // From MMccCtrlObserver
       
   304 // CMccSession::MccMediaStarted
       
   305 // ---------------------------------------------------------------------------
       
   306 // 
       
   307 void CMccSession::MccMediaStarted( TUint32 aSessionId, TUint32 aLinkId,
       
   308     TUint32 aStreamId, TUint32 aSinkSourceId )
       
   309     {
       
   310     RDebug::Print( _L("TEST PRINT: CMccSession::MccMediaStarted") );
       
   311     RDebug::Print( _L("TEST PRINT: SESSID: %u, LINKID: %u, STREAMID: %u, SINKSOURCEID: %u"),
       
   312         aSessionId, aLinkId, aStreamId, aSinkSourceId );
       
   313         
       
   314     TMccStreamState state = StreamByIdL( aStreamId )->State();    
       
   315     
       
   316     if ( ERtcpStreamPrepared == state )
       
   317         {
       
   318         StreamByIdL( aStreamId )->SetState( ERtpStreamStarted );
       
   319         }
       
   320     else if ( ERtpStreamStarted == state )
       
   321         {
       
   322         StreamByIdL( aStreamId )->SetState( ERtcpStreamStarted );
       
   323         User::RequestComplete( iObserverStatus, KErrNone );
       
   324         }
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // From MMccCtrlObserver
       
   329 // CMccSession::MccMediaStopped
       
   330 // ---------------------------------------------------------------------------
       
   331 //                          
       
   332 void CMccSession::MccMediaStopped( TUint32 aSessionId, TUint32 aLinkId,
       
   333     TUint32 aStreamId, TUint32 aSinkSourceId )
       
   334     {
       
   335     RDebug::Print( _L("TEST PRINT: CMccSession::MccMediaStopped") );
       
   336     RDebug::Print( _L("TEST PRINT: SESSID: %u, LINKID: %u, STREAMID: %u, SINKSOURCEID: %u"),
       
   337         aSessionId, aLinkId, aStreamId, aSinkSourceId );
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // From MMccCtrlObserver
       
   342 // CMccSession::MccMediaPaused
       
   343 // ---------------------------------------------------------------------------
       
   344 //
       
   345 void CMccSession::MccMediaPaused( TUint32 aSessionId, TUint32 aLinkId,
       
   346     TUint32 aStreamId, TUint32 aSinkSourceId )
       
   347     {
       
   348     RDebug::Print( _L("TEST PRINT: CMccSession::MccMediaPaused") );
       
   349     RDebug::Print( _L("TEST PRINT: SESSID: %u, LINKID: %u, STREAMID: %u, SINKSOURCEID: %u"),
       
   350         aSessionId, aLinkId, aStreamId, aSinkSourceId );
       
   351     }
       
   352     
       
   353 // ---------------------------------------------------------------------------
       
   354 // From MMccCtrlObserver
       
   355 // CMccSession::MccMediaResumed
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 void CMccSession::MccMediaResumed( TUint32 aSessionId, TUint32 aLinkId,
       
   359     TUint32 aStreamId, TUint32 aSinkSourceId )
       
   360     {
       
   361     RDebug::Print( _L("TEST PRINT: CMccSession::MccMediaResumed") );
       
   362     RDebug::Print( _L("TEST PRINT: SESSID: %u, LINKID: %u, STREAMID: %u, SINKSOURCEID: %u"),
       
   363         aSessionId, aLinkId, aStreamId, aSinkSourceId );
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // From MMccCtrlObserver
       
   368 // CMccSession::MccMediaPrepared
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CMccSession::MccMediaPrepared( TUint32 aSessionId, TUint32 aLinkId,
       
   372     TUint32 aStreamId, TUint32 aSinkSourceId )
       
   373     {
       
   374     RDebug::Print( _L("TEST PRINT: CMccSession::MccMediaPrepared") );
       
   375     RDebug::Print( _L("TEST PRINT: SESSID: %u, LINKID: %u, STREAMID: %u, SINKSOURCEID: %u"),
       
   376         aSessionId, aLinkId, aStreamId, aSinkSourceId );
       
   377     
       
   378     TMccStreamState state = StreamByIdL( aStreamId )->State();
       
   379         
       
   380     if ( EStreamCreated == state )
       
   381         {
       
   382         StreamByIdL( aStreamId )->SetState( ERtpStreamPrepared );
       
   383         }
       
   384     else if ( ERtpStreamPrepared == state )
       
   385         {
       
   386         StreamByIdL( aStreamId )->SetState( ERtcpStreamPrepared );
       
   387         User::RequestComplete( iObserverStatus, KErrNone );
       
   388         }
       
   389     }
       
   390     
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // From MMccCtrlObserver
       
   394 // CMccSession::MccMediaInactive
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CMccSession::MccMediaInactive( TUint32 /*aSessionId*/, TUint32 /*aLinkId*/,
       
   398     TUint32 /*aStreamId*/, TUint32 /*aSinkSourceId*/ )
       
   399     {
       
   400      __NATFWTESTCONSOLE( "CMccSession::MccMediaInactive" )
       
   401     }
       
   402   
       
   403 // ---------------------------------------------------------------------------
       
   404 // From MMccCtrlObserver
       
   405 // CMccSession::MccMediaActive
       
   406 // ---------------------------------------------------------------------------
       
   407 //   
       
   408 void CMccSession::MccMediaActive( TUint32 /*aSessionId*/, TUint32 /*aLinkId*/,
       
   409     TUint32 /*aStreamId*/, TUint32 /*aSinkSourceId*/ )
       
   410     {
       
   411     __NATFWTESTCONSOLE( "CMccSession::MccMediaActive" )
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // From MMccCtrlObserver
       
   416 // CMccSession::MccCtrlError
       
   417 // ---------------------------------------------------------------------------
       
   418 //    
       
   419 void CMccSession::MccCtrlError( TInt aError, TUint32 /*aSessionId*/,
       
   420     TUint32 /*aLinkId*/, TUint32 /*aStreamId*/, TUint32 /*aSinkSourceId*/ )
       
   421     {
       
   422      __NATFWTESTCONSOLE_INT1( "CMccSession::MccCtrlError ", aError )
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // From MMccCtrlObserver
       
   427 // CMccSession::UnknownMediaReceived
       
   428 // ---------------------------------------------------------------------------
       
   429 //                       
       
   430 void CMccSession::UnknownMediaReceived(  TUint32 /*aSessionId*/, TUint32 /*aLinkId*/, 
       
   431     TUint32 /*aStreamId*/, TUint32 /*aSinkSourceId*/, TUint8 /*aPayloadType*/ )
       
   432     {
       
   433      __NATFWTESTCONSOLE( "CMccSession::UnknownMediaReceived" )
       
   434     }