multimediacommscontroller/tsrc/rtpsourcesinkstub/inc/mccrtpdatasink.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2002-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:    RTP Datasink
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #ifndef MCCRTPDATASINK_H
       
    23 #define MCCRTPDATASINK_H
       
    24 
       
    25 //  INCLUDES
       
    26 #include "rtpapi.h"
       
    27 #include "mccdatasink.h"
       
    28 #include "mccrtpinterface.h"
       
    29 #include "rtpdatasink.h"
       
    30 
       
    31 #ifdef FTD_ENABLED
       
    32 #include <e32msgqueue.h>
       
    33 #include "Mccstreamstats.h"
       
    34 #endif
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // DATA TYPES
       
    41 
       
    42 // FUNCTION PROTOTYPES
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 class MDataSource;
       
    46 
       
    47 // CLASS DECLARATION
       
    48     
       
    49 /**
       
    50 *  Mcc RTP DataSink send RTP packet using to RtpAPI
       
    51 *
       
    52 *  @lib MccRtpSourceSink.dll
       
    53 *  @since Series 60 3.0
       
    54 */
       
    55 class CMccRtpDataSink : public CMccDataSink,
       
    56                         public MMccRtpInterface, 
       
    57                         public MMccRtpDataSink
       
    58     {
       
    59     public:    // Constructors and destructor
       
    60 
       
    61         /**
       
    62         * Two-phased constructor. Virtual function from MDataSink
       
    63         */
       
    64         static MDataSink* NewSinkL( TUid aImplementationUid, 
       
    65                                     const TDesC8& aInitData );
       
    66    
       
    67         /**
       
    68         * Destructor.
       
    69         */
       
    70         virtual ~CMccRtpDataSink();
       
    71 
       
    72     public:    // New functions
       
    73         
       
    74         /**
       
    75         * Returns Synchronization source.
       
    76         * @since Series 60 3.0
       
    77         * @param None
       
    78         * @return Synchronization source value
       
    79         */
       
    80         inline TRtpSSRC GetSSRC() const
       
    81        		{
       
    82         	return iSSRC;
       
    83         	}
       
    84      
       
    85         /**
       
    86          * Set current user / event handler.
       
    87          * @since   Series 60 3.2
       
    88          * @param   aEventHandler   Event handler
       
    89          * @return  void
       
    90          */
       
    91         virtual void SetCurrentUser( MAsyncEventHandler* aEventHandler );
       
    92 
       
    93         /**
       
    94          * Sets rtp media clock instance for data sink. Instance is forwarded 
       
    95          * to rtp keep alive sender.
       
    96          *
       
    97          * @since Series 60 3.0
       
    98          * @param aRtpMediaClock media clock instance
       
    99          * @return void
       
   100          */
       
   101         virtual void SetMediaClock( CMccRtpMediaClock& aRtpMediaClock );
       
   102         
       
   103         /**
       
   104          * Mutes/Unmutes RTP sink. When mute is enabled, only packets with
       
   105          * exception payload type are sent.
       
   106          *
       
   107          * @since   Series 60 3.2
       
   108          * @param   aMuteOn         When ETrue mute is enabled
       
   109          * @param   aExceptionPt    Payload to send regardless of mute state
       
   110          */
       
   111         virtual void Mute( TBool aMuteOn, TUint8 aExceptionPt );
       
   112 
       
   113     public: // From CMccDataSink
       
   114     
       
   115         void AddUserL( TUint32 aStreamId );
       
   116     
       
   117     public: // From MDataSink
       
   118 
       
   119         /**
       
   120         * From MDataSink. Pure virtual function that must be implemented.
       
   121         *                  Out of usage. Leave KErrNotSupported.
       
   122         * @since Series 60 3.0
       
   123         * @param "aBuffer" Out of usage
       
   124         * @param "aSupplier" Out of usage
       
   125         * @param "aMediaId" Out of usage
       
   126         * @return void
       
   127         */
       
   128         void EmptyBufferL( CMMFBuffer* aBuffer, 
       
   129                            MDataSource* aSupplier, 
       
   130                            TMediaId aMediaId );
       
   131 
       
   132         /**
       
   133         * From MDataSink Method to 'logon' the data source to 
       
   134         *                 the same thread that source will be supplying data in.
       
   135         * @since Series 60 3.0
       
   136         * @param aEventHandler for send event to datasource when buffer is embtied. 
       
   137         * @return KErrNone if successful, otherwise a system wide error code.
       
   138         */
       
   139         TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler );
       
   140 
       
   141         /**
       
   142         * From MDataSink Method to 'logoff' the data source from 
       
   143         *                 the same thread that source supplies data in.
       
   144         * @since Series 60 3.0
       
   145         * @param None
       
   146         * @return void
       
   147         */
       
   148         void SinkThreadLogoff();
       
   149 
       
   150         /**
       
   151         * From MDataSink pure virtual function that must be implemented.
       
   152         *                 Returns the data type as a fourCC code of the data sink.
       
   153         * @since Series 60 3.0
       
   154         * @param "aMediaId" This identifies the type of media eg audio and the stream id.
       
   155         *                    This parameter is required in cases where the sink can accept data
       
   156         *                    of more than one media type.
       
   157         * @return the datatype code ( codec ).
       
   158         */
       
   159         TFourCC SinkDataTypeCode( TMediaId aMediaId );
       
   160 
       
   161         /**
       
   162         * From MDataSink pure virtual function that must be implemented.
       
   163         *                 Sets the data type as a fourCC code for the data sink.
       
   164         * @since Series 60 3.0
       
   165         * @param "aSinkFourCC" This specifies the data type as a fourCC code to set the sink to
       
   166         * @param "aMediaId" This identifies the type of media eg audio and the stream id.
       
   167         * @return KErrNone if successful.
       
   168         * @return KErrLocked if Sink thread locked. Codec must to be set before thread logon.
       
   169         * @return KErrNotSupported if the sink does not support media type.
       
   170         */
       
   171         TInt SetSinkDataTypeCode( TFourCC aCodec, TMediaId aMedia );
       
   172 
       
   173         /**
       
   174         * From MDataSink pure virtual function that must be implemented. 
       
   175         *                 Out of usage. Function leaves with KErrNotSupported.  
       
   176         * @since    Series 60 3.0
       
   177         * @param    "aCodec" Out of usage
       
   178         * @param    aMedia    Out of usage
       
   179         * @return    void
       
   180         */
       
   181         void BufferFilledL( CMMFBuffer* aBuffer );
       
   182 
       
   183         /**
       
   184         * From MDataSink pure virtual function that must be implemented.
       
   185         * Method to indicate whether the data sink can create a buffer.
       
   186         * @deprecated
       
   187         *
       
   188         * @since Series 60 3.0
       
   189         * @param "aBuffer" Out of usage
       
   190         * @return False
       
   191         */
       
   192         TBool CanCreateSinkBuffer();
       
   193 
       
   194         /**
       
   195         * From MDataSink pure virtual function that must be implemented.
       
   196         * Out of usage. Function leaves with KErrNotSupported.
       
   197         * @deprecated
       
   198         *
       
   199         * @since Series 60 3.0
       
   200         * @param "aMediaId" Out of usage.
       
   201         * @param "aReference" Out of useage.
       
   202         * @return 
       
   203         */
       
   204         CMMFBuffer* CreateSinkBufferL( TMediaId /*aMediaId*/, 
       
   205                                        TBool& aReference );
       
   206                                   
       
   207         /**
       
   208         * From MDataSink. This is a virtual function that a derived data sink 
       
   209         *                 can implement if any data sink specific 'priming' is required
       
   210         * @since    Series 60 3.0
       
   211         * @param    None
       
   212         * @return   void
       
   213         */
       
   214         void SinkPrimeL();
       
   215 
       
   216         /**
       
   217         * From MDataSink. This is a virtual function that a derived data sink can implement if
       
   218         *                 any data sink specific action is required prior to 'playing'ie the 
       
   219         *                 start of data transfer
       
   220         * @since    Series 60 3.0
       
   221         * @param    None
       
   222         * @return   void
       
   223         */
       
   224         void SinkPlayL();
       
   225 
       
   226         /**
       
   227         * From MDataSink. This is a virtual function that a derived data sink can implement if 
       
   228         *                 any data sink specific action is required to 'pause'
       
   229         * @since    Series 60 3.0
       
   230         * @param    None
       
   231         * @return   void
       
   232         */
       
   233         void SinkPauseL();
       
   234         
       
   235         /**
       
   236         * From MDataSink. This is a virtual function that a derived data sink can implement if 
       
   237         *                 any data sink specific action is required to 'stop'
       
   238         * @since    Series 60 3.0
       
   239         * @param    None
       
   240         * @return   void
       
   241         */
       
   242         void SinkStopL();
       
   243         
       
   244         /**
       
   245         * From MDataSink. Used for custom command receiving.
       
   246         * @since    Series 60 3.0
       
   247         * @param    aMessage    The message specifying the custom command.
       
   248         * @return   void
       
   249         */
       
   250         void SinkCustomCommand( TMMFMessage& aMessage );
       
   251         
       
   252 
       
   253     
       
   254     public: // From MMccRtpInterface
       
   255     
       
   256             
       
   257         /**
       
   258         * From CRtpInterface Sends media signals (RTCP)
       
   259         * @since Series 60 3.0
       
   260         * @param aSignal Signal to be sent
       
   261         * @return void
       
   262         */
       
   263         virtual void SendMediaSignallingL( const TMccEvent& aEvent );
       
   264         
       
   265         /**
       
   266         * Sends Non-RTCP data
       
   267         * @param aData - [input] Data to send
       
   268         * @return One of the standard system-wide error codes.
       
   269         */
       
   270         virtual void SendRTCPDataL( const TDesC8& aData );
       
   271         
       
   272         virtual TBool HandleBySsrc( const TRtpSSRC& aSsrc );
       
   273 
       
   274         TRtpId RtpStreamId();
       
   275     
       
   276         virtual TBool IsSink() const;
       
   277         
       
   278         virtual TBool IsSending() const;
       
   279         
       
   280         void DoCreateSrtpStreamL();
       
   281               
       
   282 
       
   283     public: // From MMccRtpDataSink
       
   284     
       
   285         /**
       
   286         * From MMccRtpDataSink. Empties specified buffer.
       
   287         *
       
   288         * @since    Series 60 3.0
       
   289         * @param    aBuffer     Buffer containing the RTP packet
       
   290         * @param    aSupplier   Data source to notify when buffer is emptied
       
   291         * @param    aMediaId    Identifies the media type of a particular stream
       
   292         * @param    aHeaderInfo RTP packet header
       
   293         * @return   void
       
   294         */
       
   295         void EmptyBufferL( CMMFBuffer* aBuffer, 
       
   296                            MDataSource* aSupplier,
       
   297                            TMediaId aMediaId,
       
   298                            TRtpSendHeader& aHeaderInfo );
       
   299                            
       
   300                            
       
   301     protected:  // Functions from base classes
       
   302         
       
   303         /**
       
   304         * Method to perform any sink construction dependant on the sink construction
       
   305         * initialisation data aInitData
       
   306         *
       
   307         * This is a pure virtual function that a derrived data sink must implement
       
   308         *
       
   309         * @param    "aInitData"
       
   310         *            Sink specific initialisation data required for sink construction
       
   311         */
       
   312         void ConstructSinkL( const TDesC8& aInitData );
       
   313 
       
   314     protected:  // From CMccRtpInterface
       
   315     
       
   316         /**
       
   317         * From CMccRtpInterface
       
   318         */
       
   319         void DoCreateStreamL();
       
   320 
       
   321     public: // From CMccDataSink
       
   322         
       
   323         // STUB stuff
       
   324         void GetParameterL( TUint32 /*aParam*/, TDes8& /*aVal*/ )
       
   325             {
       
   326             }
       
   327         
       
   328         // STUB stuff
       
   329         void SetParameterL( TUint32 /*aParam*/, const TDesC8& /*aVal*/ )
       
   330             {
       
   331             }
       
   332         
       
   333     private:
       
   334 
       
   335         /**
       
   336         * C++ default constructor.
       
   337         */
       
   338         CMccRtpDataSink();
       
   339         
       
   340         void SendStreamEventToClient( TMccEventType aEventType, 
       
   341                                       TInt aError = KErrNone );
       
   342                                                            
       
   343         TMccRtpUser* FindRtpUserEntryForCurrent( MAsyncEventHandler& aEventHandler );
       
   344         
       
   345         void RemoveCurrentRtpUser();
       
   346         
       
   347         static TBool RtpUserMatch( const TMccRtpUser& aUser1, 
       
   348                                    const TMccRtpUser& aUser2 );
       
   349                                    
       
   350         TBool SendingAllowed( TRtpSendHeader& aHeaderInfo ) const;
       
   351                                       
       
   352      private: // From MSRTPReKeyingObserver
       
   353     
       
   354         /**
       
   355          * FROM SRTP API
       
   356          *
       
   357          * This function is called by SRTP when a master key is stale and
       
   358          * needs to be refreshed. 
       
   359          */
       
   360         void SRTPMasterKeyStaleEvent(const CSRTPStream& aStream);
       
   361         
       
   362         /**
       
   363          *  FROM SRTP API
       
   364          *
       
   365          * This function is called by SRTP Stream initiated with 
       
   366          * CSRTPSession  when a master key is stale and
       
   367          * needs to be refreshed.
       
   368          */ 
       
   369         void SRTPMasterKeyStaleEvent(const CSRTPSession& aSession );
       
   370             
       
   371     private:    // Data
       
   372 
       
   373         // Pointer to buffer, which datapath has requested to be emptied
       
   374         CMMFDataBuffer* iBufferToBeEmptied;     // Uses
       
   375 
       
   376         // Pointer to datasource for notify when buffer is emptied
       
   377         MDataSource* iDataSource;               // Uses
       
   378         
       
   379         // Synchronization source identifier.
       
   380         TRtpSSRC iSSRC;
       
   381         
       
   382         // Stream ID for media packets
       
   383         TRtpId iRtpStreamId;
       
   384                
       
   385         // Registered users for sink
       
   386         RArray<TMccRtpUser> iUsers;
       
   387         
       
   388         // flag for secure key expired
       
   389         TBool iSecureKeyExpired;
       
   390 
       
   391         // flag indicating is mute enabled
       
   392         TBool iMuteOn;
       
   393         
       
   394         // payload to sent regardless of mute state
       
   395         TUint8 iExceptionPt;
       
   396         
       
   397 #ifdef FTD_ENABLED
       
   398         
       
   399         // Message queue carrying stream statistics
       
   400         RMsgQueue<TMccStreamStats> iStreamStatsQueue;
       
   401         
       
   402         // Number of packets sent
       
   403         TUint32 iPacketsSent;
       
   404         
       
   405 #endif
       
   406 
       
   407     #ifdef TEST_EUNIT
       
   408     public:
       
   409         friend class UT_CMccRtpDataSink;
       
   410     #endif
       
   411     };
       
   412 
       
   413 #endif        // MCCRTPDATASINK_H
       
   414 
       
   415 // End of File