multimediacommscontroller/mmccrtpsourcesink/inc/mccrtpinterface.h
changeset 0 1bce908db942
child 18 817c922b90eb
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2002-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:    RTP Source/Sink Base class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef MCCRTPINTERFACE_H
       
    21 #define MCCRTPINTERFACE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <msrtprekeyingobserver.h>
       
    25 
       
    26 #include <mmf/common/mmfutilities.h>
       
    27 #include "rtpdef.h"
       
    28 #include "mccinternalcodecs.h"
       
    29 #include "mmccevents.h"
       
    30 #include "mccinternalevents.h"
       
    31 #include "mccexpirationhandler.h"
       
    32 #include "mccinternaldef.h"
       
    33 
       
    34 // CONSTANTS
       
    35 const TUint KDefSampleRate = 8000;
       
    36 
       
    37 // DATA TYPES
       
    38 
       
    39 enum TMccStandbyActionType
       
    40     {
       
    41     EForceStandby,
       
    42     EActivateStandby,
       
    43     EDeactivateStandby
       
    44     };
       
    45 
       
    46 enum TMccStandbyState
       
    47     {
       
    48     EActivating,
       
    49     EActive,
       
    50     EDeactivating,
       
    51     EInactive,
       
    52     ETurnedOff
       
    53     };
       
    54     
       
    55 // FUNCTION PROTOTYPES
       
    56 
       
    57 // FORWARD DECLARATIONS
       
    58 class CRtpAPI;
       
    59 class MRtpObserver;
       
    60 class MRtcpObserver;
       
    61 class MAsyncEventHandler;
       
    62 class TMccEvent;
       
    63 class MMccRtpKeepalive;
       
    64 class CMccRtpMediaClock;
       
    65 class CSRTPSession;
       
    66 class TMccCryptoContext;
       
    67 class CSRTPStream;
       
    68 class CSRTPCryptoContext;
       
    69 
       
    70 // CLASS DECLARATION
       
    71 
       
    72 /**
       
    73 * Class to pass the session related parameters to the RTP source/sink.
       
    74 * 
       
    75 * @lib Mccrtpsourcesink.dll
       
    76 * @since Series 60 3.0
       
    77 */
       
    78 class TMccRtpSessionParams
       
    79     {
       
    80     public:
       
    81         
       
    82         inline TMccRtpSessionParams() : iRtpAPI( NULL ), iSessionId( KNullId ),
       
    83             iEnableRTCP( ETrue ), iRtpKeepalive( NULL ), iSecSession( NULL ) { }
       
    84 
       
    85         inline TMccRtpSessionParams( CRtpAPI* aRtpAPI, TRtpId aSessionId, 
       
    86             TBool aEnableRTCP, MMccRtpKeepalive* aRtpKeepalive, CSRTPSession* aSecSession ) :
       
    87             iRtpAPI( aRtpAPI ),
       
    88             iSessionId( aSessionId ), 
       
    89             iEnableRTCP( aEnableRTCP ),
       
    90             iRtpKeepalive( aRtpKeepalive ),
       
    91             iSecSession( aSecSession )
       
    92             { }
       
    93 
       
    94     public: // data
       
    95 
       
    96         // RTP API to use
       
    97         CRtpAPI* iRtpAPI;
       
    98 
       
    99         // The RTP session where source/sink operates
       
   100         TRtpId iSessionId;
       
   101 
       
   102         // Whether to enable RTCP for the session
       
   103         TBool iEnableRTCP;
       
   104         
       
   105         MMccRtpKeepalive* iRtpKeepalive;
       
   106         
       
   107         /**
       
   108          * Pointer to SRTP session
       
   109          * Not own.
       
   110          */
       
   111         CSRTPSession* iSecSession;
       
   112     };
       
   113 
       
   114 
       
   115  /**
       
   116 * Class to contain rtp source/sink user information.
       
   117 * 
       
   118 * @lib Mccrtpsourcesink.dll
       
   119 * @since Series 60 3.0
       
   120 */   
       
   121  class TMccRtpUser
       
   122     {
       
   123     public:
       
   124     
       
   125         TMccRtpUser( MAsyncEventHandler* aEventHandler ) : 
       
   126             iEventHandler( aEventHandler ),
       
   127             iStartedOnce( EFalse ),
       
   128             iPayloadType( KMccPTNotDefined ),
       
   129             iTimerId( KMaxTUint ),
       
   130             iStandbyState( EInactive )
       
   131             {
       
   132             }
       
   133             
       
   134     public:
       
   135     
       
   136         MAsyncEventHandler* iEventHandler;
       
   137         TBool iStartedOnce;
       
   138         TUint iPayloadType;
       
   139         TMccTimerId iTimerId;
       
   140         TMccStandbyState iStandbyState;
       
   141     };
       
   142     
       
   143      
       
   144 /**
       
   145 * Common interface for CMccRtpDataSource and -DataSink.
       
   146 *
       
   147 * @lib MccRtpSourceSink.dll
       
   148 * @since Series 60 3.0
       
   149 */
       
   150 class MMccRtpInterface : public MSRTPReKeyingObserver
       
   151     {
       
   152 
       
   153     public: // New functions
       
   154         
       
   155         /**
       
   156         * Set session level parameters.
       
   157         * @since Series 60 3.0
       
   158         * @param aParams Session level parameters
       
   159         * @return None
       
   160         */        
       
   161         virtual void SetSessionParamsL( const TMccRtpSessionParams& aParams );
       
   162         
       
   163         /**
       
   164         * Sends media level events
       
   165         * @since Series 60 3.0
       
   166         * @param aEvent Event to be sent
       
   167         * @return void
       
   168         */
       
   169         virtual void SendMediaSignallingL( const TMccEvent& aEvent ) = 0;
       
   170         
       
   171         /**
       
   172         * Configures the source/sink
       
   173         * @since Series 60 3.0
       
   174         * @param aConfig Configuration
       
   175         * @return void
       
   176         */
       
   177         virtual void ConfigureL( const TDesC8& aConfig );
       
   178         
       
   179         /**
       
   180         * Sends RTCP receiver report to uplink if possible.
       
   181         * @param aStreamId - [input] Stream ID identifying stream
       
   182         * @return One of the standard system-wide error codes.
       
   183         */
       
   184         virtual TInt SendRTCPReceiverReport();
       
   185 
       
   186         /**
       
   187         * Sends RTCP sender report to uplink if possible.
       
   188         * @param aStreamId - [input] Stream ID identifying stream
       
   189         * @return One of the standard system-wide error codes.
       
   190         */
       
   191         virtual TInt SendRTCPSenderReport();
       
   192         
       
   193         /**
       
   194         * Sends Non-RTCP data
       
   195         * @param aData - [input] Data to send
       
   196         * @return One of the standard system-wide error codes.
       
   197         */
       
   198         virtual void SendRTCPDataL( const TDesC8& aData );
       
   199 
       
   200         /** 
       
   201         * Starts inactivity timer for a stream
       
   202         * @param aTimeoutTime - [input] timeout value in milliseconds
       
   203         * @return One of the standard system-wide error codes.
       
   204         */
       
   205         virtual void StartInactivityTimerL( TUint32 aTimeoutTime );
       
   206 
       
   207         /**
       
   208         * Stops inactivity timer for a stream 
       
   209         * @return One of the standard system-wide error codes.
       
   210         */
       
   211         virtual void StopInactivityTimerL();
       
   212         
       
   213         /**
       
   214         */
       
   215         virtual TInt StandBy( TMccStandbyActionType aActionType, TUint aPayloadType );
       
   216         
       
   217         virtual TBool HandleBySsrc( const TRtpSSRC& aSsrc );
       
   218         
       
   219         virtual TBool HandleByStreamId( const TRtpId& aStreamId );
       
   220         
       
   221         virtual TRtpId RtpStreamId() = 0;
       
   222     
       
   223         virtual TBool IsSink() const;
       
   224         
       
   225         virtual TBool IsSending() const;
       
   226         
       
   227         virtual void DoCreateSrtpStreamL() = 0;
       
   228         
       
   229         /**
       
   230          * Create SRTP crypto context. /
       
   231          * Refresh exists crypto context.
       
   232          * @since Series 60 3.2
       
   233          * @param TMccCryptoContext Crypto context params.
       
   234          * @return void
       
   235          */
       
   236         virtual void ApplyCryptoContextL( const TMccCryptoContext& aContextParams );
       
   237        
       
   238         /**
       
   239          * Remove crypto context.
       
   240          * @since Series 60 3.2
       
   241          * @return Error code.
       
   242          */                                     
       
   243         virtual TInt RemoveCryptoContext(); 
       
   244 
       
   245     protected:  // New functions
       
   246             
       
   247         /**
       
   248         * Source/Sink states
       
   249         */
       
   250         enum TSourceSinkState
       
   251             {
       
   252             ERtpStateConstructed = 0,  // Pseudo state, not in working thread.
       
   253             ERtpStateStopped = 1,      // RTCP packets are handled.
       
   254             ERtpStatePrimed = 2,       // RTCP packets are handled.
       
   255             ERtpStatePlaying = 3,      // RTP packest are received/transmitted.
       
   256             ERtpStatePaused = 4       // RTCP packets are handled.
       
   257             };
       
   258 
       
   259         /**
       
   260         * C++ default constructor.
       
   261         */
       
   262         inline MMccRtpInterface() : iRtpAPI( NULL ), iSessionID( KNullId ),
       
   263             iState( ERtpStateConstructed ), iEnableRtcp( EFalse ), 
       
   264             iEventHandler( NULL ), iCodecInfo(), iMccStreamId( 0 ), 
       
   265             iMccEvent( TMccEvent() ), iRtpKeepalive( NULL ), iContext( NULL), 
       
   266             iSecSession( NULL ), iSrtpStream( NULL ), iRtpMediaClock( NULL ),
       
   267             iContextId( 0 )
       
   268             { }
       
   269             
       
   270             
       
   271         /**
       
   272         * Checks the given buffer if it is supported. Leaves with KErrNoMemory
       
   273         * if the supplied buffer pointer is NULL. Leaves with KErrNotSupported
       
   274         * if the buffer is not supported.
       
   275         * @since Series 60 3.0
       
   276         * @param aBuffer Buffer to be checked.
       
   277         * @return void
       
   278         */
       
   279         void CheckBufferSupportL( CMMFBuffer* aBuffer ) const;
       
   280         
       
   281         /**
       
   282         * Creates transmit or receive stream.
       
   283         * @since Series 60 3.0
       
   284         * @param None
       
   285         * @return Stream ID
       
   286         */
       
   287         virtual void DoCreateStreamL() = 0;
       
   288         
       
   289         /**
       
   290         * Sets current state. Leaves with KErrNotReady if state transition is
       
   291         * not acceptable.
       
   292         * @since Series 60 3.0
       
   293         * @param aState A new state
       
   294         * @return void
       
   295         */
       
   296         void SetStateL( TSourceSinkState aState );
       
   297         
       
   298         /**
       
   299         * Returns current state.
       
   300         * @since Series 60 3.0
       
   301         * @param None
       
   302         * @return Current state
       
   303         */        
       
   304         inline TSourceSinkState State() const
       
   305             {
       
   306             return iState;
       
   307             }
       
   308         
       
   309         void CloseStreams();
       
   310         
       
   311         void SendInternalRtpEventToClient( MAsyncEventHandler* aEventHandler,
       
   312                                            TUid aEventOriginator,
       
   313                                            TMccInternalEventType aInternalEventType,
       
   314                                            TMccEventType aEventType,
       
   315                                            TUint32 aEndpointId,
       
   316                                            TInt aError = KErrNone, 
       
   317                                            TUint64 aJitterEstimate = 0,
       
   318                                            TUint32 aPacketsReceived = 0,
       
   319                                            TInt64 aPrevTransTime = 0,
       
   320                                            TUint64 aTriggeredJitterLevel = 0 );
       
   321         
       
   322         void SendInternalRtpEventToAllClients( RArray<TMccRtpUser>& aUsers,
       
   323                                                TUid aEventOriginator,
       
   324                                                TMccInternalEventType aInternalEventType,
       
   325                                                TMccEventType aEventType,
       
   326                                                TUint32 aEndpointId,
       
   327                                                TInt aError = KErrNone, 
       
   328                                                TUint64 aJitterEstimate = 0,
       
   329                                                TUint32 aPacketsReceived = 0,
       
   330                                                TInt64 aPrevTransTime = 0,
       
   331                                                TUint64 aTriggeredJitterLevel = 0 );
       
   332         
       
   333         void ClearMccEvent();
       
   334         
       
   335         /**
       
   336          * Start sending keepalive packets.
       
   337          *
       
   338          * @since Series 60 3.2
       
   339          * @param aRtpMediaClock rtp media clock instance
       
   340          * @return void
       
   341          */  
       
   342         void StartKeepaliveL( CMccRtpMediaClock& aRtpMediaClock );
       
   343         
       
   344         
       
   345         /**
       
   346          * Stop sending keepalive packets.
       
   347          *
       
   348          * @since Series 60 3.2
       
   349          * @return void
       
   350          */  
       
   351         void StopKeepalive();
       
   352         
       
   353         /**
       
   354          * Reset keepalive timer.
       
   355          *
       
   356          * @since Series 60 3.2
       
   357          * @return void
       
   358          */  
       
   359         void ResetKeepaliveTimer();
       
   360         
       
   361         /**
       
   362          * Send secure related event to client.
       
   363          *
       
   364          * @since Series 60 3.2
       
   365          * @param aEventHandler Event handler.
       
   366          * @param aEventOriginator Event originator.
       
   367          * @param aInternalEventType Event type.
       
   368          * @param aEndpointId Endpoint id.
       
   369          * @return void
       
   370          */   
       
   371         void SendSecureRtpEventToClient(  MAsyncEventHandler* aEventHandler,
       
   372                                           TUid aEventOriginator,
       
   373                                           TMccInternalEventType aInternalEventType,
       
   374                                           TMccEventType aEventType,
       
   375                                           TUint32 aEndpointId );
       
   376                                    
       
   377         /**
       
   378          * FROM SRTP API
       
   379          *
       
   380          * This function is called by SRTP when a master key is stale and
       
   381          * needs to be refreshed. 
       
   382          */
       
   383         virtual void SRTPMasterKeyStaleEvent(const CSRTPStream& aStream) =  0;
       
   384         
       
   385         /**
       
   386          *  FROM SRTP API
       
   387          *
       
   388          * This function is called by SRTP Stream initiated with 
       
   389          * CSRTPSession  when a master key is stale and
       
   390          * needs to be refreshed.
       
   391          */ 
       
   392         virtual void SRTPMasterKeyStaleEvent(const CSRTPSession& aSession ) = 0;
       
   393 
       
   394             
       
   395     private:    // New functions
       
   396 
       
   397     public:     // Data
       
   398     
       
   399     protected:  // Data
       
   400         
       
   401         // RTP stack API reference
       
   402         CRtpAPI* iRtpAPI;
       
   403         
       
   404         // Session ID where media stream belongs to
       
   405         TRtpId iSessionID;
       
   406         
       
   407         // Source/Sink state ( Stopped, Primed, Playing )
       
   408         TSourceSinkState iState;
       
   409         
       
   410         // RTCP Enabled / Disabled
       
   411         TBool iEnableRtcp;
       
   412         
       
   413         // Eventhandler
       
   414         MAsyncEventHandler* iEventHandler;
       
   415         
       
   416         // Codec information
       
   417         TMccCodecInfo iCodecInfo;
       
   418         
       
   419         // Mcc stream identifier
       
   420         TUint32 iMccStreamId;
       
   421         
       
   422         TMccEvent iMccEvent;
       
   423         
       
   424         MMccRtpKeepalive* iRtpKeepalive;
       
   425 
       
   426         /**
       
   427          * Rtp media clock instance
       
   428          * Not own.
       
   429          */
       
   430         CMccRtpMediaClock* iRtpMediaClock; 
       
   431        
       
   432         /*
       
   433          * Srtp crypto context. 
       
   434          * Own. / Not own.
       
   435          */
       
   436         CSRTPCryptoContext* iContext;
       
   437        
       
   438         /**
       
   439          * Pointer to SRTP session
       
   440          * Not own.
       
   441          */
       
   442         CSRTPSession* iSecSession;
       
   443         
       
   444         /*
       
   445          * Pointer to SRTP stream
       
   446          * Own. /Not Own.
       
   447          */
       
   448         CSRTPStream* iSrtpStream;
       
   449         
       
   450         /*
       
   451          * Context identifier
       
   452          */
       
   453          TUint32 iContextId;
       
   454 
       
   455     private:    // Friend classes
       
   456     
       
   457         #ifdef TEST_EUNIT
       
   458             friend class UT_CMccRtpInterface;
       
   459         #endif
       
   460     };
       
   461 
       
   462 #endif      // MCCRTPINTERFACE_H
       
   463             
       
   464 // End of File