rtp/rtpstack/inc/rtpmanager.h
author Petteri Saari <petteri.saari@digia.com>
Thu, 25 Nov 2010 13:59:42 +0200
branchMSRP_FrameWork
changeset 58 cdb720e67852
parent 0 307788aac0a8
child 29 5f12516512fa
permissions -rw-r--r--
This release addresses the following issues: 1. The crash bug fix when receiving file 2. Now the sending is based on MSRP messages, there is no longer file receiving or sending. Client sends data as MSRP was designed. 3. Soma MSRP stack was created so that the client told the correct session-id, Symbian stack generated it by itself. This is not allowed, it was changed so that clients tell the session-id (same as used in SIP INVITE). 4. Unnecessary division of data to chunks removed when there is no need to interrupt sending. The message is sent in as few chunks as possible. 5. Stack can now receive files and chunks with ?unlimited? size. Old stack wrote the incoming data to memory and did not utilize disk space until the end of chunk was reached (large chunks from another client crashed it). 6. Now when writing the incoming data to file, it will take into account the byte-range header values. So, this complies with the RFC4975 requirements that stack must be able to handle chunks that come in any sequence. 7. Some buffering changes to outgoing/incoming data. 8. The outgoing data is now checked that it does not contain the created transaction-id before sending the data. 9. MSRP success reports are now implemented and tested against servers. 10. Progress report system fixed so progress is now visible on client (all the way to 100%). 11. Message Cancel receiving / Cancel sending now corrected and made to work as rfc4975 requires. (termination from sender and error code from receiver when cancelling). 12. Bug correction related to messages received not belonging to any session, old stack implementation did send error response, but after response was written it did give the buffer to client anyway. Now corrected.

/*
* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:    
*
*/




#ifndef __RTPMANAGER_H
#define __RTPMANAGER_H

#include <commdbconnpref.h>
#include <es_enum.h>
#include <rtpdef.h>
#include <rtpheader.h>
#include "rtpsession.h"
#include "rtpsdes.h"
#include "localaddrresolver.h"
#include "rtpmanagerdef.h"
#include "rtpasignuniqueid.h"
#include "srtpsession.h"
#include "rtpsessionsrtp.h"

/**
*  Container of all rtp sessions. 
*
*  @lib RtpService.dll
*/
class CRtpManager : public CBase,
    				public MRtpAsignUniqueID
    {
    #if defined( _DEBUG ) && defined( RTP_UNIT_TEST )
    // Friend class used for testing
        friend class CRtpUtRtpManager;
    #endif
    public: // Data types
        enum TCreateStreamType
            {
            ECreateRecvStream = 0,
            ECreateTranStream,
            ECreateTranStreamExt
            };

    public:
        static CRtpManager* NewL( MRtpErrNotify& aErrNotify );
        ~CRtpManager();

        TInt OpenL( const TRtpSdesParams& aSdesInfo, 
                    const TDesC* aRtpPacketDll, 
                    RSocketServ* aSocketServPtr,
                    RConnection* aRConnPtr );

        /**
        * Open and initialize the CRtpAPI object synchronously.
        * @param TInt aIapId - [input] IAP ID. If -1, no IAP selection dialog
        *   will pop up. Instead, the default IAP will be used.
        * @return TInt - KErrNone if successful; system wide error code
        *   otherwise
        */
        TInt StartConnection( TInt aIapId );

        /**
        * Open and initialize the CRtpAPI object in asynchronous mode
        * @param TRequestStatus& aStatus - [output] On completion, will contain
        *   a status code: KErrNone if successful; system wide error code
        *   otherwise.
        * @param TInt aIapId - [input] IAP ID. If -1, no IAP selection dialog
        *   will pop up. Instead, the default IAP will be used.
        * @return TInt - KErrNone if successful; system wide error code
        *   otherwise
        */
        TInt StartConnection( TRequestStatus& aStatus, TInt aIapId );

        /**
        * Cancels asynchoronous start of connection
        * Any open requests will be completed with KErrCancel.
        * @return None
        */
        void CancelStart(); 

        void Close( void );

        void SetLocalSdes( const TRtpSdesParams& aSdesInfo );

        TInetAddr& GetLocalIPAddressL();

        TRtpId CreateSessionL( const TCreateSessionParams& aSessionParams,
                               TUint& aPort,
                               TBool aEnableRtcp,
                               const TRtcpParams* aRtcpParams );
                               
		TRtpId CreateSessionL( const TCreateSessionParams& aSessionParams,
                               TUint& aPort,
                               TBool aEnableRtcp,
                               const TRtcpParams* aRtcpParams,
                               CSRTPSession& aSRTPSession );
        TInt StartSession( TRtpId aSessionId );

        void CloseSession( TRtpId aSessionId );

        TInt SetRemoteAddress( TRtpId aSessionId, TInetAddr& aRemoteAddr );
        TInt SetRemoteRtcpAddress( TRtpId aSessionId, TInetAddr& aRemoteAddr );

        /**
        * Does the actual work of creating a stream. Used by the other
        * stream creation methods.
        * @return ID of the created stream, or KNullId if not successful
        */
        TRtpId CreateStreamL( TRtpId aSessionId,
                              const TCreateStreamType aStreamType,
                              TRtpPayloadType aPayloadType,
                              TRtpSSRC& aSSRC );

        TRtpId CreateReceiveStreamL( TRtpId aSessionId, const TRcvStreamParams& aParams );
        TRtpId CreateTransmitStreamL( TRtpId aSessionId, const TTranStreamParams& aParams, 
                                      TRtpSSRC& aSSRC );

        TRtpId CreateTransmitStreamExtL( TRtpId aSessionId, const TTranStreamParams& aParams, 
                                         const TRtpSSRC aSSRC );

        void CloseStream( TRtpId aStreamId );

        TInt RegisterRtpObserver( TRtpId aSessionId, MRtpObserver& aObserver );

        void UnregisterRtpObserver( TRtpId aSessionId );

        TInt SetNonRTPDataObserver( TRtpId aSessionId, 
                                    MNonRTPDataObserver* aNonRTPDataObserver );
        
        TInt SendRtpPacket( TRtpId aTranStreamId, 
                            const TRtpSendHeader& aHeaderInfo, 
                            const TDesC8& aPayloadData );

        TInt SendRtpPacket( TRtpId aTranStreamId,
                            const TRtpSendHeader& aHeaderInfo,
                            const TDesC8& aPayloadData,
                            TRequestStatus& aStatus );

        TInt SendRtpPacket( TRtpId aTranStreamId,
                            TRtpSequence aSequenceNum,
                            const TRtpSendHeader& aHeaderInfo,
                            const TDesC8& aPayloadData,
                            TRequestStatus& aStatus );

        void SendDataL( TRtpId aSessionId,
                       TBool aUseRTPSocket,
                       const TDesC8& aData,
                       TRequestStatus& aStatus );

        void CancelSend( TRtpId aSessionId );

        TInt RegisterRtcpObserver( TRtpId aSessionId, MRtcpObserver& aObserver );

        void UnregisterRtcpObserver( TRtpId aSessionId );

        TInt SendRtcpByePacketL( TRtpId aTranStreamId, const TDesC8& aReason );

        TInt SendRtcpAppPacketL( TRtpId aTranStreamId, const TRtcpApp& aApp );

        /**
        * Send an RTCP RR packet for a Reception stream.
        * @param TRtpId aRcvStreamId - [input] Reception stream ID
        * @return TInt - KErrNone if successful; system wide error code otherwise
        */
        TInt SendRtcpRrPacketL( TRtpId aRcvStreamId );
        
        /**
        * Send an RTCP SR packet for a Transmit stream.
        * @param TRtpId aTranStreamId - [input] Transmit stream ID
        * @return TInt - KErrNone if successful; system wide error code otherwise
        */
        TInt SendRtcpSrPacketL( TRtpId aTranStreamId );

        /**
        * Suspend RTCP sending on/off, calculations will continue. 
        * @param TRtpId aSessionId - [input] RTP Session ID
        * @param TBool aAutoSending - [input] Auto sending flag. 
        *							  ETrue:  RTCP sending will be scheduled normally
        *							  EFalse: RTCP sending will be suspended
        * @return TInt - KErrNone if successful; KErrNotFound if invalid session id;
        *				 KErrNotSupported if RTCP disabled;  system wide error code otherwise				
        */
        TInt SuspendRtcpSending( TRtpId aSessionId, TBool aAutoSending );
        
		/**
        * Gets the status of automatic RTCP sending.
        * @param TRtpId aSessionId - [input] RTP Session ID
        * @param TBool aAutoSending - [output] ETrue: RTCP atuo sending is on 
        *				  					   EFalse: RTCP auto sending is off
 		* @return TInt - KErrNone if successful; KErrNotFound if invalid session id;
        *				 KErrNotSupported if RTCP disabled;  system wide error code otherwise
        */
        TInt IsRtcpSendingSuspended( TRtpId aSessionId, TBool& aAutoSending );

        TRtpId GetSessionId( TRtpId aStreamId );

        RSocket* GetRtpSocket( TRtpId aSessionId );

        RSocket* GetRtcpSocket( TRtpId aSessionId );

        TInt GetStreamStatistics( TRtpId aStreamId, TRtpPeerStat& aStat );

        TUint32 GetSamplingRate( TUint8 aPayloadType );

        TInt SetSamplingRate( TUint8 aPayloadType, TUint32 aSampleRate );

        TInt SetRtcpParameters( TRtpId aSessionId, const TRtcpParams& aRtcpParams );

    private:
        CRtpManager( MRtpErrNotify& aErrNotify );
        void ConstructL( void );
        CRtpSession* GetSession( TRtpId aSessionId );

        TRtpId AssignUniqueID();
        TInt AddRtpObject( TArrayStore aArrayID );
        TInt FindRtpObject( const TRtpId aMagicKey, TUint& aSessionAddress );
        TInt RemoveRtpObject( const TRtpId aMagicKey, const TObjectType aObjectType );
        void RemoveRtpAllObjects();
    
        /*
        * Opens the socket server and the connection
        * @return KErrNone if successful, system error code otherwise
        */
        TInt PrepareConnection( TCommDbConnPref& aPrefs, TInt aIapId );

        /*
        * @return Internet Access Point ID of iConn
        */
        TInt GetIapId( TUint32& aIapId );
        
        TInt AddStreamToSession(TRtpId aSessionId, TRtpId aStreamId);

        void CheckSdesCName();
        
    private:   // data
        TBool iStandardRtp;
        TBool iEnableRtcp;
        RLibrary iLibrary;

        RSocketServ iSocketServ;
        RConnection iConn;
        RSocketServ* iSocketServPtr;  // Don't use until future
        RConnection* iConnPtr;    // Don't use until future
        TBool iConnected;
		TInt iIapId;

        TInetAddr iLocalAddr;

        CRtpSDES* iDefaultSdes;

        TRtpId iNumOfObjects;   // count of session and participants IDs assigned
        CArrayFixFlat<TArrayStore>* iSessionArray;   //keep track of all RTP session;

        TUint32 iProfileRTPTimeRates[KRtpMaxPayloadTypes];

        MRtpErrNotify& iErrNotify;

        TCommDbConnPref iPrefs;
    private:    
    #ifdef EUNIT_TESTING
	  friend class UT_CRtpAPI;
	  friend class UT_CRtpManager;
	#endif     	    
        
    };

#endif    // __RTPMANAGER_H

// End of File