multimediacommsengine/mmcecli/src/mcertpsource.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 "mcertpsource.h"
       
    22 #include "mcesession.h"
       
    23 #include "mcemanager.h"
       
    24 #include "mcemediastream.h"
       
    25 #include "mcertpobserver.h"
       
    26 #include "mcecomrtpsource.h"
       
    27 #include "mceitcsender.h"
       
    28 #include "mceevents.h"
       
    29 #include "mceserial.h"
       
    30 #include "mceclilogs.h"
       
    31 
       
    32 
       
    33 #define KMCETIMERDISABLED 0
       
    34 #define _FLAT_DATA static_cast<CMceComRtpSource*>( iFlatData )
       
    35 #define FLAT_DATA( data ) _FLAT_DATA->data
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CMceRtpSource::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C CMceRtpSource* CMceRtpSource::NewL(
       
    46 					   TUint aBufferLength,
       
    47 					   TUint aBufferTreshold,
       
    48 					   TUint32 aInactivityTimer,
       
    49 					   HBufC8* aIdentity )
       
    50     {
       
    51     CMceRtpSource* self = NewLC( aBufferLength, aBufferTreshold,
       
    52     	 aInactivityTimer, aIdentity );
       
    53     CleanupStack::Pop( self );
       
    54     return self;   
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMceRtpSource::NewLC
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CMceRtpSource* CMceRtpSource::NewLC(
       
    62 					   TUint aBufferLength,
       
    63 					   TUint aBufferTreshold,
       
    64 					   TUint32 aInactivityTimer,
       
    65 					   HBufC8* aIdentity )
       
    66     {
       
    67     CMceRtpSource* self = new (ELeave) CMceRtpSource();
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL( aBufferLength, aBufferTreshold, 
       
    70                       aInactivityTimer, NULL, aIdentity );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CMceRtpSource::~CMceRtpSource
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CMceRtpSource::~CMceRtpSource()
       
    80     {
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CMceRtpSource::EnableL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C void CMceRtpSource::EnableL() 
       
    88     {
       
    89     MCECLI_DEBUG("CMceRtpSource::EnableL, Entry");
       
    90     
       
    91     CMceMediaSource::DoEnableL();
       
    92 
       
    93     MCECLI_DEBUG("CMceRtpSource::EnableL, Exit");
       
    94     
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CMceRtpSource::DisableL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CMceRtpSource::DisableL() 
       
   102     {
       
   103     MCECLI_DEBUG("CMceRtpSource::DisableL, Entry");
       
   104     
       
   105     CMceMediaSource::DoDisableL();
       
   106     
       
   107     MCECLI_DEBUG("CMceRtpSource::DisableL, Exit");
       
   108     
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CMceRtpSource::EnableInactivityTimerL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C void CMceRtpSource::EnableInactivityTimerL( TUint32 aInactivityTimer ) 
       
   117     {
       
   118     MCECLI_DEBUG("CMceRtpSource::EnableInactivityTimerL, Entry");
       
   119     MCECLI_DEBUG_DVALUE("timer", aInactivityTimer );
       
   120     
       
   121     __ASSERT_ALWAYS( MCE_ENDPOINT_ITC_ALLOWED( *this ), 
       
   122         User::Leave( KErrNotReady ) );
       
   123     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   124         {
       
   125         CMceSession* session = iStream->Session();
       
   126 
       
   127         TMceIds ids;
       
   128         session->PrepareForITC( ids );
       
   129         ids.iMediaID = iStream->Id();
       
   130         ids.iSourceID  = Id();
       
   131         
       
   132         TMceItcArgTUint32 inactivity( aInactivityTimer );
       
   133         session->ITCSender().WriteL( ids, EMceItcEnableInactivityTimer, inactivity );
       
   134         }
       
   135     MCECLI_DEBUG("CMceRtpSource::EnableInactivityTimerL, Exit");
       
   136         
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMceRtpSource::DisableInactivityTimer
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C void CMceRtpSource::DisableInactivityTimerL() 
       
   144     {
       
   145     MCECLI_DEBUG("CMceRtpSource::DisableInactivityTimerL, Entry");
       
   146     
       
   147     FLAT_DATA( iInactivityTimer ) = KMCETIMERDISABLED;
       
   148 
       
   149     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   150         {
       
   151         DoITCSendL( EMceItcDisableInactivityTimer );    
       
   152         }
       
   153     MCECLI_DEBUG("CMceRtpSource::DisableInactivityTimerL, Exit");
       
   154     
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CMceRtpSource::UpdateL
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CMceRtpSource::UpdateL ( TUint aBufferLength,
       
   162 								TUint aBufferTreshold,
       
   163 								TUint32 aInactivityTimer,
       
   164 								HBufC8* aIdentity )
       
   165 	{
       
   166     MCECLI_DEBUG("CMceRtpSource::UpdateL, Entry");
       
   167     MCECLI_DEBUG_DVALUE("buffer length", aBufferLength );
       
   168     MCECLI_DEBUG_DVALUE("buffer treshold", aBufferTreshold );
       
   169     MCECLI_DEBUG_DVALUE("inactivity timer", aInactivityTimer );
       
   170 	
       
   171     FLAT_DATA( iInactivityTimer ) = aInactivityTimer;
       
   172     FLAT_DATA( iBufferLength ) = aBufferLength;
       
   173     FLAT_DATA( iBufferTreshold ) = aBufferTreshold;
       
   174     MCE_DELETE( FLAT_DATA( iTalkBurstIndicator ) );
       
   175     FLAT_DATA( iTalkBurstIndicator ) = 0;
       
   176     MCE_DELETE( FLAT_DATA( iIdentity ) );
       
   177     FLAT_DATA( iIdentity ) = aIdentity ? aIdentity->AllocL() : NULL;
       
   178 
       
   179     MCECLI_DEBUG("CMceRtpSource::UpdateL, Exit");
       
   180 	}
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CMceRtpSource::SendRRL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C void CMceRtpSource::SendRRL() 
       
   187     {
       
   188     MCECLI_DEBUG("CMceRtpSource::SendRRL, Entry");
       
   189     
       
   190     __ASSERT_ALWAYS( MCE_ENDPOINT_ITC_ALLOWED( *this ), 
       
   191                      User::Leave( KErrNotReady ) );
       
   192     
       
   193     DoITCSendL( EMceItcSendRR );
       
   194     
       
   195     MCECLI_DEBUG("CMceRtpSource::SendRRL, Exit");
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CMceRtpSource::Ssrc
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C TUint32 CMceRtpSource::Ssrc() const
       
   203     {
       
   204     return 0;
       
   205     }
       
   206     
       
   207 // -----------------------------------------------------------------------------
       
   208 // CMceRtpSource::Ssrcs
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C const RArray<TUint>& CMceRtpSource::Ssrcs() const			
       
   212     {
       
   213     return FLAT_DATA( iNotSupported );    
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CMceRtpSource::EnableSsrcL
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C void CMceRtpSource::EnableSsrcL( TUint /*aSsrc*/ )
       
   221     {
       
   222     User::Leave( KErrNotSupported );
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CMceRtpSource::DisableSsrcL
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C void CMceRtpSource::DisableSsrcL( TUint /*aSsrc*/ )
       
   230     {
       
   231     User::Leave( KErrNotSupported );
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CMceRtpSource::IsSsrcEnabledL
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C TBool CMceRtpSource::IsSsrcEnabledL( TUint /*aSsrc*/ )
       
   239     {
       
   240     User::Leave( KErrNotSupported );
       
   241     return EFalse;
       
   242     }
       
   243 	
       
   244 // -----------------------------------------------------------------------------
       
   245 // CMceRtpSource::CMceRtpSource
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 CMceRtpSource::CMceRtpSource()
       
   249    : CMceMediaSource()
       
   250     {
       
   251     }
       
   252 
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CMceRtpSource::ConstructL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CMceRtpSource::ConstructL( TUint aBufferLength,
       
   259                                 TUint aBufferTreshold,
       
   260                                 TUint32 aInactivityTimer,
       
   261                                 HBufC8* aTalkBurstIndicator,
       
   262                                 HBufC8* aIdentity )
       
   263     {
       
   264     CMceComRtpSource* source = CMceComRtpSource::NewLC();
       
   265     CMceMediaSource::ConstructL( source );
       
   266     CleanupStack::Pop( source );
       
   267     
       
   268     FLAT_DATA( iInactivityTimer ) = aInactivityTimer;
       
   269     FLAT_DATA( iBufferLength ) = aBufferLength;
       
   270     FLAT_DATA( iBufferTreshold ) = aBufferTreshold;
       
   271     FLAT_DATA( iTalkBurstIndicator ) = aTalkBurstIndicator;
       
   272     FLAT_DATA( iIdentity ) = aIdentity ? aIdentity->AllocL() : NULL;
       
   273     }
       
   274 
       
   275 
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CMceRtpSource::EventReceivedL
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TInt CMceRtpSource::EventReceivedL( TMceEvent& aEvent )
       
   282     {
       
   283     TInt status = CMceMediaSource::EventReceivedL( aEvent );
       
   284     if ( status != KMceEventNotConsumed )
       
   285         {
       
   286         return status;
       
   287         }
       
   288                 
       
   289     if ( aEvent.Id().IsSourceId() )
       
   290         {
       
   291         status = HandleEvent( aEvent );
       
   292         }
       
   293     else
       
   294         {
       
   295         status = KMceEventNotConsumed;
       
   296         }
       
   297     
       
   298     return status;
       
   299     
       
   300     }
       
   301 
       
   302 
       
   303 
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CMceRtpSource::HandleEvent
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 TInt CMceRtpSource::HandleEvent( TMceEvent& aEvent )
       
   310     {
       
   311     MCECLI_DEBUG("CMceRtpSource::HandleEvent, Entry");
       
   312     
       
   313     TInt status = KMceEventNotConsumed;
       
   314     
       
   315     MMceRtpObserver* observer = iStream->Session()->Manager().RtpObserver();
       
   316     switch ( aEvent.Action() )
       
   317         {
       
   318         case EMceItcSRReceived:
       
   319             {
       
   320             MCECLI_DEBUG("CMceRtpSource::HandleEvent, SR received");
       
   321             if ( observer )
       
   322                 {
       
   323                 observer->SRReceived( *( iStream->Session() ), *iStream );
       
   324                 }
       
   325             status = KMceEventConsumed;
       
   326             break;
       
   327             }
       
   328         case EMceItcRRReceived:
       
   329             {
       
   330             MCECLI_DEBUG("CMceRtpSource::HandleEvent, RR received");
       
   331             if ( observer )
       
   332                 {
       
   333                 observer->RRReceived( *( iStream->Session() ), *iStream );
       
   334                 }
       
   335             status = KMceEventConsumed;
       
   336             break;
       
   337             }
       
   338         case EMceItcInactivityTimeout:
       
   339             {
       
   340             MCECLI_DEBUG("CMceRtpSource::HandleEvent, inactivity timeout received");
       
   341             if ( observer )
       
   342                 {
       
   343                 observer->InactivityTimeout( *iStream, *this );
       
   344                 }
       
   345             status = KMceEventConsumed;
       
   346             break;
       
   347             }
       
   348         default:
       
   349             {
       
   350             //NOP
       
   351             MCECLI_DEBUG("CMceRtpSource::HandleEvent, not consumed");
       
   352             break;
       
   353             }
       
   354         
       
   355         }
       
   356     
       
   357     MCECLI_DEBUG_DVALUE("CMceRtpSource::HandleEvent, Exit. status", status );
       
   358     return status;
       
   359     
       
   360     }
       
   361     
       
   362 // -----------------------------------------------------------------------------
       
   363 // CMceRtpSource::DoITCSendL
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CMceRtpSource::DoITCSendL( TUint8 aITCFunction )
       
   367 	{
       
   368     __ASSERT_ALWAYS( iStream, User::Leave( KErrNotReady ) );
       
   369     __ASSERT_ALWAYS( iStream->Session(), User::Leave( KErrNotReady ) );
       
   370     CMceSession* session = iStream->Session();
       
   371     
       
   372     if ( session->State() != CMceSession::EIdle )
       
   373         {
       
   374     	TMceIds ids;
       
   375     	session->PrepareForITC( ids );
       
   376     	ids.iMediaID   = iStream->Id();
       
   377 	    ids.iSourceID  = Id();
       
   378     	ids.iState     = IsEnabled();
       
   379     	
       
   380         session->ITCSender().SendL( ids, static_cast<TMceItcFunctions>( aITCFunction ) );        
       
   381         }	
       
   382 	}
       
   383