multimediacommscontroller/mmccMsrppayloadformat/inc/msrppayloadformatwrite.h
branchrcs
changeset 49 64c62431ac08
child 50 1d8943dd8be6
equal deleted inserted replaced
44:fb024d5e35fa 49:64c62431ac08
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:    Provides a comfort noise generator class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MSRPPAYLOADFORMATWRITE_H
       
    20 #define MSRPPAYLOADFORMATWRITE_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <mmfformat.h>
       
    25 #include <mmfdatabuffer.h>
       
    26 #include <mmfutilities.h>
       
    27 #include "formatstatemachine.h"
       
    28 #include "mccinternalcodecs.h"
       
    29 #include "sendstatemachine.h"
       
    30 #include "mccmsrpsink.h"
       
    31 
       
    32 
       
    33 // RFC 4103 specifies that time stamp offset maxvalue
       
    34 const TUint16 KHighestTimeStampOffset = 0x3FFF; // 16383
       
    35  
       
    36 // 0x200 is selected because when using redundancy we must 
       
    37 // be able to send 3x payload + header. This is the treshold 
       
    38 // when RTP packet size grows too much
       
    39 const TInt KMaxRTTChunkSize = 0x200; // 512
       
    40 
       
    41 // When using level 2 redundancy, Redundancy Header size.
       
    42 const TInt KRedHeaderSize = 0x48; // 32 + 32 + 8 = 72; 
       
    43 
       
    44 // Maximum datasize
       
    45 const TInt KDataSize = 0x600;// KMaxRTTChunkSize * 3;
       
    46 
       
    47 // Default sampling Rate for RTP Clock
       
    48 const TInt KDefaultSampleRate = 1000;
       
    49 
       
    50 
       
    51 // FORWARD DECLARATIONS
       
    52 class MMccRtpDataSink;
       
    53 class CMccRtpMediaClock;
       
    54 class TCharElement;
       
    55 
       
    56 
       
    57 class TStringElement
       
    58  {
       
    59  	
       
    60 	public :
       
    61 	 TStringElement();
       
    62 	 
       
    63 	public :
       
    64 	 TBuf16<512> iData;
       
    65 	 TInt64 iTimestamp; 
       
    66  
       
    67  };
       
    68     
       
    69 // CLASS DECLARATION
       
    70 /**
       
    71 *  Packetizes RTP payload containing Msrp data.
       
    72 *
       
    73 *  @lib MccMsrpPlFormat.dll
       
    74 
       
    75 */
       
    76 class CMsrpPayloadFormatWrite : public CPayloadFormatWrite, 
       
    77 							MPayloadFormatWrite, MSendStateObserver
       
    78     {
       
    79     public:  // Constructors and destructor
       
    80     
       
    81    
       
    82         static CMsrpPayloadFormatWrite* NewL( MDataSink* aSink );
       
    83 
       
    84         /**
       
    85         * Destructor.
       
    86         */
       
    87         virtual ~CMsrpPayloadFormatWrite();
       
    88 
       
    89     public: // New functions
       
    90 
       
    91         /**
       
    92         * Configures payload format with format spesific parameters.
       
    93         * Leaves with KErrArgument if parameters are invalid.
       
    94         *
       
    95         * @since    Series 60 3.0 
       
    96         * @param    aConfigParams       Configuration parameters
       
    97         * @return   void
       
    98         */
       
    99         virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams,
       
   100                                               CMccRtpMediaClock& aClock );
       
   101     
       
   102     public: // From MPayloadFormatWrite
       
   103     
       
   104         /**
       
   105         * Empty the source buffer by formatting the Msrp frames into payload.
       
   106         * Source buffer is given in "iBuffer".
       
   107         * Called by the state machine.
       
   108         *
       
   109         * @since    Series 60 3.0
       
   110         * @param    None
       
   111         * @return   void
       
   112         */
       
   113         void EmptySourceBufferL();
       
   114 
       
   115         /**
       
   116         * Handle the event that source buffer has been emptied.
       
   117         * Source buffer is given in "iBuffer".
       
   118         * Called by the state machine.
       
   119       	*/
       
   120         void SourceBufferEmptiedL();
       
   121     
       
   122     public: // From CMMFFormatEncode
       
   123 
       
   124         /**
       
   125         * Funtion to return time interval for the complete frame
       
   126         *
       
   127         * @param aMediaType KUidMediaTypeText
       
   128         *
       
   129         * @return           time interval in micro seconds
       
   130         */
       
   131         TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const;
       
   132                     
       
   133                     
       
   134         /**   *** NOT SUPPORTED ***
       
   135         * Function to return the clip duration
       
   136         *
       
   137         * @param aMediaType KUidMediaTypeText
       
   138         *
       
   139         * @return           clip duration in micro seconds
       
   140         */
       
   141         TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const;
       
   142 
       
   143         /**
       
   144         * Create a sink buffer for the given media
       
   145         *
       
   146         * @param aMediaId   contains the media type KUidMediaTypeText
       
   147         * @param aReference value of False is returned to caller if sink 
       
   148         *                   buffer is created
       
   149         * @return           Pointer to sink buffer created
       
   150         */
       
   151         CMMFBuffer* CreateSinkBufferL( TMediaId aMediaId, 
       
   152                                        TBool& aReference );
       
   153 
       
   154         /**
       
   155         * Return the sink four CC code for the given media
       
   156         *
       
   157         * @param aMediaId    contains the media type KUidMediaTypeText
       
   158         * @return            FourCC code for the mediaId
       
   159         */
       
   160         TFourCC SinkDataTypeCode( TMediaId aMediaId );
       
   161 
       
   162         /**
       
   163         * Set the sink data type to the given four CC code for the given media
       
   164         *
       
   165         * @param aSourceFourCC    fourCC code
       
   166         * @param aMediaId         contains the media type KUidMediaTypeText
       
   167         * @return                 error code KErrNotSupported if invalid media 
       
   168         *                         ID, else return KErrNone
       
   169         */
       
   170         TInt SetSinkDataTypeCode( TFourCC aSinkFourCC, 
       
   171                                   TMediaId aMediaId );
       
   172 
       
   173         /**
       
   174         * Log in to the sink thread - this funtion merely passes the command to 
       
   175         * its sink clip data source object. The sink clip object will handle 
       
   176         * the thread log on procedures.
       
   177         *
       
   178         * @param aEventHandler    address of event handler
       
   179         *
       
   180         * @return                 error code returned by source clip
       
   181         */
       
   182         TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler );
       
   183 
       
   184         /**
       
   185         * Log out of the sink thread - this funtion merely passes the command to 
       
   186         * its sink clip data source object. The sink clip object will handle 
       
   187         * the thread log off procedures.
       
   188         *
       
   189         * @param
       
   190         *
       
   191         * @return
       
   192         */
       
   193         void SinkThreadLogoff();
       
   194 
       
   195         /**
       
   196         * Empty the given source buffer.
       
   197         *
       
   198         * @param aBuffer    data buffer containing Msrp data / redundancy data
       
   199         * @param aSupplier  data source pointer
       
   200         * @param aMediaId   contains the media type KUidMediaTypeText
       
   201         * @return
       
   202         */
       
   203         void EmptyBufferL( CMMFBuffer* aBuffer, 
       
   204                            MDataSource* aSupplier, 
       
   205                            TMediaId aMediaId );
       
   206         
       
   207         /**
       
   208         * Called after the data buffer is written. Update the number of bytes 
       
   209         * written and the current write position for the next write operation. 
       
   210         *
       
   211         * @param aBuffer       data buffer emptied
       
   212         *
       
   213         * @return
       
   214         */
       
   215         void BufferEmptiedL( CMMFBuffer* aBuffer );
       
   216 
       
   217     public: // From MDataSink
       
   218     
       
   219         /**
       
   220         * From MDataSink Primes the source.
       
   221         * @since 
       
   222         * @param
       
   223         * @return
       
   224         */
       
   225         void SinkPrimeL();
       
   226 
       
   227         /**
       
   228         * From MDataSink Plays the source.
       
   229         * @since 
       
   230         * @param
       
   231         * @return
       
   232         */
       
   233         void SinkPlayL();
       
   234 
       
   235         /**
       
   236         * From MDataSink Pauses the source.
       
   237         * @since 
       
   238         * @param
       
   239         * @return
       
   240         */
       
   241         void SinkPauseL();
       
   242 
       
   243         /**
       
   244         * From MDataSink Stops the source.
       
   245         * @since 
       
   246         * @param
       
   247         * @return
       
   248         */
       
   249         void SinkStopL();
       
   250         
       
   251         
       
   252        //FROM NONE, THIS IS A TEST METHOD
       
   253        //TInt TimerExpired();
       
   254        
       
   255        TInt SendRedundantDataL();
       
   256        
       
   257        TInt FormUserDataL();
       
   258         
       
   259         //FROM MSendStateObserver
       
   260        void TimerExpiredL();
       
   261        
       
   262        void ForwardDataL();
       
   263        
       
   264        void GotoIdleL();
       
   265        
       
   266        TInt GenerateRedPacket(); 
       
   267        
       
   268     
       
   269     private: // New functions
       
   270 
       
   271         /**
       
   272         * Prepare packet header and deliver the packet to the datasink.
       
   273         * @since Series 60 3.0
       
   274         * @param aPayload Payload to deliver to the datasink.
       
   275         * @return
       
   276         */        
       
   277         void DeliverPacketL( CMMFDataBuffer& aPayload );
       
   278         
       
   279         void AssembleRedPacket();
       
   280         
       
   281 
       
   282         
       
   283         /**
       
   284         * Create a sink buffer of the given size.
       
   285         *
       
   286         * @param   aSize     size of sink buffer to create
       
   287         *
       
   288         * @return  Pointer to sink buffer created
       
   289         */
       
   290         CMMFDataBuffer* CreateSinkBufferOfSizeL( TUint aSize );
       
   291         
       
   292         /**
       
   293          * Update payload format with format spesific parameters.
       
   294          * Leaves with KErrArgument if parameters are invalid.
       
   295          *
       
   296          * @since    Series 60 3.0 
       
   297          * @param    aConfigParams       Configuration parameters
       
   298          * @return   void
       
   299          */
       
   300         void UpdateConfigurationL( const TDesC8& aConfigParams );
       
   301 
       
   302     private:
       
   303     
       
   304         /**
       
   305         * C++ default constructor.
       
   306         */
       
   307         CMsrpPayloadFormatWrite ();
       
   308 
       
   309         /**
       
   310         * By default Symbian 2nd phase constructor is private.
       
   311         *
       
   312         * @param aConf    Decoder Configuration params
       
   313         */
       
   314         void ConstructL( MDataSink* aSource );
       
   315         
       
   316         void Write24( TUint8* const aPointer, TUint32 aValue );
       
   317         
       
   318         void Write32( TUint8 *const aPointer, TUint32 aValue );
       
   319         
       
   320         TUint16 SetTimeOffset( TInt64& aPrim, TInt64& aSecond );
       
   321         
       
   322         void CancelUlRequest();
       
   323         
       
   324     private: // Data
       
   325 
       
   326         // FourCC
       
   327         TFourCC iFourCC;
       
   328         
       
   329         // Format encoding state machine
       
   330         CFormatEncodeStateMachine* iStateMachine;
       
   331         
       
   332         // Pointer to source data buffer, that is passed from DataPath
       
   333         CMMFDataBuffer* iSourceBuffer;
       
   334 
       
   335         // Sink buffer to hold Msrp/RTP payload
       
   336         CMMFDataBuffer* iSinkBuffer;
       
   337         
       
   338         // Current RTP timestamp 
       
   339         TUint32 iCurrentTimestamp;
       
   340 
       
   341         // Flag to indicate whether to set MARK field to be 1 (the first 
       
   342         // packet in a session should have MARK field set. Also first packet 
       
   343         // after and idle period should have MARK field seet to 1 )
       
   344         TBool iFirstPacketFinished;
       
   345                 
       
   346         // Data sink capable to receive RTP data
       
   347         MMccRtpDataSink* iRtpDataSink; 
       
   348         
       
   349         // Data sink capable to receive MSRP data
       
   350         CMccMsrpSink* iMsrpDataSink; 
       
   351         
       
   352         // Parameters relating to RTP data encoding
       
   353         TMccCodecInfo iCodecInfo;
       
   354         
       
   355         // Rtp Sink, this is default ETrue
       
   356         TBool iIsRtpSink;
       
   357         
       
   358         // Msrp Sink
       
   359         TBool iIsMsrpSink;
       
   360         
       
   361         // Key for Rtp media clock 
       
   362         TUint32 iKey;
       
   363         
       
   364         /**
       
   365          * Rtp media clock instance
       
   366          * Not own.
       
   367          */
       
   368         CMccRtpMediaClock* iRtpMediaClock;
       
   369         
       
   370         
       
   371         //Redundancy Data
       
   372         CArrayFixFlat< TStringElement >* iRedData;
       
   373         
       
   374         CArrayFixFlat< TStringElement >* iUserBuffer;
       
   375         
       
   376         //Data that is modified so that we can create 
       
   377         //msrppacket
       
   378         HBufC8* iBuf;
       
   379         
       
   380         // pointer to the beginning of the iBuf
       
   381         TUint8* iData;
       
   382         
       
   383         //Timer that is used to send data in buffer periods
       
   384          CSendStateMachine* iTimer;
       
   385         
       
   386         //Flag indicating that we are in idle mode
       
   387         TBool iIdleMode;
       
   388         
       
   389   
       
   390     private: 
       
   391         
       
   392         //#ifdef TEST_EUNIT
       
   393             // For EUnit test cases
       
   394         friend class UT_CMsrpPayloadFormatWrite;
       
   395         //#endif
       
   396         
       
   397     };
       
   398 
       
   399 #endif //MsrpPAYLOADFORMATWRITE_H
       
   400 
       
   401 // End of File