ipappprotocols_plat/srtp_api/inc/srtpstreamin.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004 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:    Represents receiver (incoming) SRTP stream.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __SRTP_STREAM_IN_H__
       
    22 #define __SRTP_STREAM_IN_H__
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32def.h>
       
    26 #include "srtpstream.h"
       
    27 #include "msrtpstreamincontext.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CSRTPSession;
       
    31 class CSRTPCryptoContext;
       
    32 class MSRTPReKeyingObserver;
       
    33 class TSRTPStreamInStateBase;
       
    34 
       
    35 /**
       
    36 * Represents an SRTP stream.
       
    37 */
       
    38 class CSRTPStreamIn : public CSRTPStream, 
       
    39 					  public MSRTPStreamInContext
       
    40     {
       
    41     public:
       
    42         /**
       
    43         * Two-phased constructor.
       
    44         * Use this function if the stream will use the SRTP session's default
       
    45         * cryptographic context.
       
    46         * @param aSession The session containing the cryptographic
       
    47         *   context for this object.
       
    48         * @param aSSRC The synchronization source ID of the RTP stream
       
    49         *   that corresponds to this object.
       
    50         * @leave KErrNone if success, system-wide error code otherwise
       
    51         */
       
    52     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession,
       
    53                                       TUint aSSRC);
       
    54 
       
    55         /**
       
    56         * Two-phased constructor.
       
    57         * Use this function if the stream will have its own cryptographic
       
    58         * context.
       
    59         * @param aSession The session containing the cryptographic
       
    60         *   context for this object.
       
    61         * @param aSSRC The synchronization source ID of the RTP stream
       
    62         *   that corresponds to this object.
       
    63         * @param aCon The cryptographic context, ownership is transfered.
       
    64         * @param aObs  The callback object
       
    65         * @leave KErrNone if success, system-wide error code otherwise
       
    66         */
       
    67     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession,
       
    68                                       TUint aSSRC,
       
    69                                       CSRTPCryptoContext* aCon,
       
    70                                       MSRTPReKeyingObserver& aObs );	
       
    71 
       
    72         /**
       
    73         * Two-phased constructor.
       
    74         * Use this function if the stream will use the SRTP session's default
       
    75         * cryptographic context and "late binding" is to be used, that is, 
       
    76         * no SSRC is provided.
       
    77         * @param aSession The session containing the cryptographic
       
    78         *   context for this object.
       
    79         * @leave KErrNone if success, system-wide error code otherwise
       
    80         */
       
    81     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession);
       
    82 
       
    83         /**
       
    84         * Two-phased constructor.
       
    85         * Use this function if the stream will have its own cryptographic
       
    86         * context and "late binding" is to be used, that is, 
       
    87         * no SSRC is provided.
       
    88         * @param aSession The session containing the cryptographic
       
    89         *   context for this object.
       
    90         * @param aCon The cryptographic context, ownership is transfered. 
       
    91         * @param aObs  The callback object
       
    92         * @leave KErrNone if success, system-wide error code otherwise
       
    93         */
       
    94     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession,
       
    95                                       CSRTPCryptoContext* aCon,
       
    96                                       MSRTPReKeyingObserver& aObs );	
       
    97         /**
       
    98         * Two-phased constructor.
       
    99         * Use this function if the stream will have its own cryptographic
       
   100         * context and this cryptographic context will be set later.
       
   101         * Note that if the crypto context is not been set, the encoded packets
       
   102         * will not be handled.
       
   103         * @param aSession The session which includes the streams.
       
   104         * @param aSSRC The synchronization source ID of the RTP stream
       
   105         *   that corresponds to this object.
       
   106         * @param aObs  The callback object
       
   107         * @leave KErrNone if success, system-wide error code otherwise
       
   108         */
       
   109     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession,
       
   110                                       TUint aSSRC,
       
   111                                       MSRTPReKeyingObserver& aObs );
       
   112         
       
   113         /**
       
   114         * Two-phased constructor.
       
   115         * Use this function if the stream will have its own cryptographic
       
   116         * context and "late binding" is to be used, that is, 
       
   117         * no SSRC is provided.Stream own cryptocontext will be set later.
       
   118         * Note that if the crypto context is not been set, the encoded packets
       
   119         * will not be handled.
       
   120         * @param aSession The session which includes the streams.
       
   121         * @param aObs  The callback object
       
   122         * @leave KErrNone if success, system-wide error code otherwise
       
   123         */
       
   124     	IMPORT_C static CSRTPStreamIn* NewL( CSRTPSession& aSession,
       
   125                                       MSRTPReKeyingObserver& aObs );                              	                              
       
   126     
       
   127         /**
       
   128         * Unprotect an SRTP packet.
       
   129         * The settings for the protection are fetched from the appropriate
       
   130         * cryptographic context. If the operation fails, the function leaves
       
   131         * with a system error code.
       
   132         * @param aPacket   The SRTP packet to process.
       
   133         * @leave KErrNone if success, system-wide error code otherwise
       
   134         * @return An RTP packet.
       
   135         */
       
   136         IMPORT_C HBufC8* UnprotectSrtpL( const TDesC8& aPacket );
       
   137         
       
   138         /**
       
   139         * Unprotect an SRTCP packet.
       
   140         * The settings for the protection are fetched from the appropriate
       
   141         * cryptographic context. If the operation fails, the function leaves
       
   142         * with a system error code.
       
   143         * @param aPacket   The SRTCP packet to process.
       
   144         * @leave KErrNone if success, system-wide error code otherwise
       
   145         * @return An RTCP packet.
       
   146         */
       
   147         IMPORT_C HBufC8* UnprotectSrtcpL( const TDesC8& aPacket );
       
   148         
       
   149         /**
       
   150         * Set/Update CryptoContext for InStream
       
   151         * Setting cryptographic context must be done to enable encode/decode packets.
       
   152         * During offer/Answer, offerer do not know which crypto context is 
       
   153         * chosen by answerer. CryptoContext then can be set after getting response
       
   154         * from answerer. If crypto context has not been set, no packets in secure 
       
   155         * session will be handled. 
       
   156         * Updating stream specific crypto Context 
       
   157         * Note that to update crypto context, ROC will not be re-intialed to zero but 
       
   158         * the states and number of receiving packets will be reset. This can be 
       
   159         * use only when keys lifetime has not expired.
       
   160         * Crypto context ownershíp is transfered.
       
   161         * @param aCon aCryyptoContext which wants be used, ownership is transfered.
       
   162         * @leave KErrNone if success, system-wide error code otherwise
       
   163         * @return void
       
   164         */        
       
   165         IMPORT_C void SetCryptoInL(CSRTPCryptoContext* aCon);
       
   166         
       
   167         /**
       
   168         * Destructor
       
   169         * Note that crypto context will be deleted if stream has it's own cryptocontext
       
   170         */        
       
   171         ~CSRTPStreamIn( );   
       
   172         
       
   173         /**
       
   174         * Delete the existed crypto context and re-initial the states
       
   175         * @param None
       
   176         * @leave KErrNone if success, system-wide error code otherwise
       
   177         * @return void
       
   178         */        
       
   179 		void UpdateCryptoAndStatesL();
       
   180 	
       
   181 
       
   182     private:  //methods
       
   183         CSRTPStreamIn (CSRTPSession& aSession,
       
   184                        TUint aSSRC);
       
   185 
       
   186         CSRTPStreamIn (CSRTPSession& aSession,
       
   187                        TUint aSSRC,
       
   188                        CSRTPCryptoContext* aCon,
       
   189                        MSRTPReKeyingObserver& aObs );
       
   190                        
       
   191         CSRTPStreamIn (CSRTPSession& aSession,
       
   192                        TUint aSSRC,
       
   193                        MSRTPReKeyingObserver& aObs );               
       
   194     
       
   195         CSRTPStreamIn (CSRTPSession& aSession);
       
   196 
       
   197         CSRTPStreamIn (CSRTPSession& aSession,
       
   198                        CSRTPCryptoContext* aCon,
       
   199                        MSRTPReKeyingObserver& aObs );
       
   200         CSRTPStreamIn (CSRTPSession& aSession,
       
   201                        MSRTPReKeyingObserver& aObs );               
       
   202 
       
   203         void ConstructL();
       
   204         
       
   205         /**
       
   206         * Create states defined in TSRTPStreamInStateBase
       
   207         * @leave KErrNone if success, system-wide error code otherwise
       
   208         * @return void.
       
   209         */
       
   210         void InitializeStatesL();
       
   211 
       
   212     private:  
       
   213         TSRTPStreamInStateBase& CurrentRTPState();
       
   214 
       
   215         TSRTPStreamInStateBase& CurrentRTCPState();
       
   216         
       
   217     private:  //from MSRTPStreamInContext
       
   218         
       
   219         /*
       
   220         * Change state of the current incoming stream (for RTP)
       
   221         * @return void.
       
   222         */
       
   223         void ChangeRTPState(MSRTPStreamInContext::TContextInState aNewState);
       
   224 
       
   225         /*
       
   226         * Change state of the current incoming stream (for RTCP)
       
   227         * @return void.
       
   228         */
       
   229         void ChangeRTCPState(MSRTPStreamInContext::TContextInState aNewState);
       
   230                         
       
   231     protected:
       
   232         /*
       
   233         states for CSRTPStreamIn
       
   234         */
       
   235 	    CArrayVarFlat<TSRTPStreamInStateBase> iStates;
       
   236         /*
       
   237         the same stream can handle RTP and RTCP packets,
       
   238         these can have different states
       
   239         */        
       
   240 	    MSRTPStreamInContext::TContextInState iCurrentRTPState;
       
   241 	    MSRTPStreamInContext::TContextInState iCurrentRTCPState;
       
   242 	
       
   243 	private:
       
   244 		friend class CSRTPSession;	
       
   245 	#ifdef EUNIT_TESTING
       
   246         friend class UT_CSRTPStreamIn; 
       
   247         friend class UT_CSRTPSession;       
       
   248     #endif     
       
   249     };
       
   250 
       
   251 #endif // __SRTP_STREAM_IN_H__
       
   252