multimediacommscontroller/mmccg711payloadformat/inc/g711payloadformatwrite.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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:    Writes RTP payload format containing G711 data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef G711PAYLOADFORMATWRITE_H
       
    21 #define G711PAYLOADFORMATWRITE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include "formatstatemachine.h"
       
    26 #include "mccinternalcodecs.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class MMccRtpDataSink;
       
    30 class CMccRtpMediaClock;
       
    31 
       
    32 
       
    33 // CLASS DECLARATION
       
    34 /**
       
    35 *  Packetizes RTP payload containing G711 data.
       
    36 *
       
    37 *  @lib MccG711PlFormat.dll
       
    38 *  @since Series 60 3.0
       
    39 */
       
    40 class CG711PayloadFormatWrite : public CPayloadFormatWrite, public MPayloadFormatWrite
       
    41     {
       
    42     public:  // Constructors and destructor
       
    43     
       
    44         /**
       
    45         * Two-phased constructor.
       
    46         * @param aSource    Data source configuration parameters
       
    47         */
       
    48         static CG711PayloadFormatWrite* NewL( MDataSink* aSink );
       
    49 
       
    50         /**
       
    51         * Destructor.
       
    52         */
       
    53         virtual ~CG711PayloadFormatWrite();
       
    54 
       
    55     public: // New functions
       
    56 
       
    57         /**
       
    58         * Configures payload format with format spesific parameters.
       
    59         * Leaves with KErrArgument if parameters are invalid.
       
    60         *
       
    61         * @since    Series 60 3.0 
       
    62         * @param    aConfigParams       Configuration parameters
       
    63         * @return   void
       
    64         */
       
    65         virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams,
       
    66                                               CMccRtpMediaClock& aClock );
       
    67     
       
    68     public: // From MPayloadFormatWrite
       
    69     
       
    70         /**
       
    71         * Empty the source buffer by formatting the G.711 frames into RTP payload.
       
    72         * Source buffer is given in "iBuffer".
       
    73         * Called by the state machine.
       
    74         *
       
    75         * @since    Series 60 3.0
       
    76         * @param    None
       
    77         * @return   void
       
    78         */
       
    79         void EmptySourceBufferL();
       
    80 
       
    81         /**
       
    82         * Handle the event that source buffer has been emptied.
       
    83         * Source buffer is given in "iBuffer".
       
    84         * Called by the state machine.
       
    85         *
       
    86         * @since    Series 60 3.0
       
    87         * @param    None
       
    88         * @return   void
       
    89         */
       
    90         void SourceBufferEmptiedL();
       
    91     
       
    92     public: // From CMMFFormatEncode
       
    93 
       
    94         /**
       
    95         * Funtion to return time interval for the complete frame
       
    96         *
       
    97         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    98         *
       
    99         * @return           time interval in micro seconds
       
   100         */
       
   101         TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const;
       
   102                     
       
   103         /**   *** NOT SUPPORTED ***
       
   104         * Function to return the clip duration
       
   105         *
       
   106         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
   107         *
       
   108         * @return           clip duration in micro seconds
       
   109         */
       
   110         TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const;
       
   111 
       
   112         /**
       
   113         * Create a sink buffer for the given media
       
   114         *
       
   115         * @param aMediaId   contains the media type KUidMediaTypeAudio or 
       
   116         *                   KUidMediaTypeVideo 
       
   117         * @param aReference value of False is returned to caller if sink 
       
   118         *                   buffer is created
       
   119         * @return           Pointer to sink buffer created
       
   120         */
       
   121         CMMFBuffer* CreateSinkBufferL( TMediaId aMediaId, 
       
   122                                        TBool& aReference );
       
   123 
       
   124         /**
       
   125         * Return the sink four CC code for the given media
       
   126         *
       
   127         * @param aMediaId    contains the media type KUidMediaTypeAudio or
       
   128         *                    KUidMediaTypeVideo
       
   129         * @return            FourCC code for the mediaId
       
   130         */
       
   131         TFourCC SinkDataTypeCode( TMediaId aMediaId );
       
   132 
       
   133         /**
       
   134         * Set the sink data type to the given four CC code for the given media
       
   135         *
       
   136         * @param aSourceFourCC    fourCC code
       
   137         * @param aMediaId         contains the media type KUidMediaTypeAudio or
       
   138         *                         KUidMediaTypeVideo
       
   139         * @return                 error code KErrNotSupported if invalid media 
       
   140         *                         ID, else return KErrNone
       
   141         */
       
   142         TInt SetSinkDataTypeCode( TFourCC aSinkFourCC, 
       
   143                                   TMediaId aMediaId );
       
   144 
       
   145         /**
       
   146         * Log in to the sink thread - this funtion merely passes the command to 
       
   147         * its sink clip data source object. The sink clip object will handle 
       
   148         * the thread log on procedures.
       
   149         *
       
   150         * @param aEventHandler    address of event handler
       
   151         *
       
   152         * @return                 error code returned by source clip
       
   153         */
       
   154         TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler );
       
   155 
       
   156         /**
       
   157         * Log out of the sink thread - this funtion merely passes the command to 
       
   158         * its sink clip data source object. The sink clip object will handle 
       
   159         * the thread log off procedures.
       
   160         *
       
   161         * @param
       
   162         *
       
   163         * @return
       
   164         */
       
   165         void SinkThreadLogoff();
       
   166 
       
   167         /**
       
   168         * Empty the given source buffer.
       
   169         *
       
   170         * @param aBuffer    data buffer containing G.711 frames
       
   171         * @param aSupplier  data source pointer
       
   172         * @param aMediaId   contains the media type KUidMediaTypeAudio or 
       
   173         *                   KUidMediaTypeVideo
       
   174         * @return
       
   175         */
       
   176         void EmptyBufferL( CMMFBuffer* aBuffer, 
       
   177                            MDataSource* aSupplier, 
       
   178                            TMediaId aMediaId );
       
   179         
       
   180         /**
       
   181         * Called after the data buffer is written. Update the number of bytes 
       
   182         * written and the current write position for the next write operation. 
       
   183         *
       
   184         * @param aBuffer       data buffer emptied
       
   185         *
       
   186         * @return
       
   187         */
       
   188         void BufferEmptiedL( CMMFBuffer* aBuffer );
       
   189 
       
   190         /**
       
   191         * Accessor funtion to return the number of channels
       
   192         *
       
   193         * @param    
       
   194         *
       
   195         * @return  Number of channels
       
   196         */
       
   197         TUint NumChannels();
       
   198 
       
   199         /**
       
   200         * Accessor funtion to return the sampling rate
       
   201         *
       
   202         * @param    
       
   203         *
       
   204         * @return Sampling rate
       
   205         */
       
   206         TUint SampleRate();
       
   207 
       
   208         /**
       
   209         * Set the samplerate to the given value.
       
   210         *
       
   211         * @param aSampleRate
       
   212         *
       
   213         * @return error code KErrNotSupported if invalid samplerate, else 
       
   214         *         return KErrNone
       
   215         */
       
   216         TInt SetSampleRate( TUint aSampleRate );
       
   217 
       
   218     public: // From MDataSink
       
   219     
       
   220         /**
       
   221         * From MDataSink Primes the source.
       
   222         * @since 
       
   223         * @param
       
   224         * @return
       
   225         */
       
   226         void SinkPrimeL();
       
   227 
       
   228         /**
       
   229         * From MDataSink Plays the source.
       
   230         * @since 
       
   231         * @param
       
   232         * @return
       
   233         */
       
   234         void SinkPlayL();
       
   235 
       
   236         /**
       
   237         * From MDataSink Pauses the source.
       
   238         * @since 
       
   239         * @param
       
   240         * @return
       
   241         */
       
   242         void SinkPauseL();
       
   243 
       
   244         /**
       
   245         * From MDataSink Stops the source.
       
   246         * @since 
       
   247         * @param
       
   248         * @return
       
   249         */
       
   250         void SinkStopL();
       
   251     
       
   252     private: // New functions
       
   253 
       
   254         /**
       
   255         * Prepare packet header and deliver the packet to the datasink.
       
   256         * @since Series 60 3.0
       
   257         * @param aPayload Payload to deliver to the datasink.
       
   258         * @return
       
   259         */        
       
   260         void DeliverPacketL( CMMFDataBuffer& aPayload );
       
   261         
       
   262         /**
       
   263         * Create a sink buffer of the given size.
       
   264         *
       
   265         * @param   aSize     size of sink buffer to create
       
   266         *
       
   267         * @return  Pointer to sink buffer created
       
   268         */
       
   269         CMMFDataBuffer* CreateSinkBufferOfSizeL( TUint aSize );
       
   270         
       
   271         /**
       
   272          * Update payload format with format spesific parameters.
       
   273          * Leaves with KErrArgument if parameters are invalid.
       
   274          *
       
   275          * @since    Series 60 3.0 
       
   276          * @param    aCodecInfo       Configuration parameters
       
   277          * @return   void
       
   278          */
       
   279         void UpdateConfigurationL( TMccCodecInfo& aCodecInfo );
       
   280 
       
   281     private:
       
   282     
       
   283         /**
       
   284         * C++ default constructor.
       
   285         */
       
   286         CG711PayloadFormatWrite ();
       
   287 
       
   288         /**
       
   289         * By default Symbian 2nd phase constructor is private.
       
   290         *
       
   291         * @param aConf    Decoder Configuration params
       
   292         */
       
   293         void ConstructL( MDataSink* aSource );
       
   294 
       
   295     private: // Data
       
   296 
       
   297         // FourCC
       
   298         TFourCC iFourCC;
       
   299         
       
   300         // Format encoding state machine
       
   301         CFormatEncodeStateMachine* iStateMachine;
       
   302         
       
   303         // Pointer to source data buffer, passed from DataPath
       
   304         CMMFDataBuffer* iSourceBuffer;
       
   305 
       
   306         // Sink buffer to hold G711/RTP payload
       
   307         CMMFDataBuffer* iSinkBuffer;
       
   308 
       
   309         // Flag to indicate whether to set MARK field to be 1 (the first 
       
   310         // packet in a talk spurt should have MARK field set)
       
   311         TBool iFirstPacketFinished;
       
   312         
       
   313         // Indicates are we sending comfort noise payload
       
   314         TBool iCNModeON;
       
   315 
       
   316         // Data sink capable to receive RTP data
       
   317         MMccRtpDataSink* iRtpDataSink;
       
   318         
       
   319         // Parameters relating to RTP data encoding
       
   320         TMccCodecInfo iCInfo;
       
   321         
       
   322         // Rtp Sink
       
   323         TBool iIsRtpSink;
       
   324         
       
   325         // Key for Rtp media clock
       
   326         TUint32 iKey;
       
   327         
       
   328         /**
       
   329          * Rtp media clock instance
       
   330          * Not own.
       
   331          */
       
   332         CMccRtpMediaClock* iRtpMediaClock;
       
   333 
       
   334     private:    // Friend classes
       
   335     
       
   336     #ifdef TEST_EUNIT
       
   337         // For EUnit test cases
       
   338         friend class UT_CG711PayloadFormatWrite;
       
   339     #endif
       
   340     
       
   341     };
       
   342 
       
   343 #endif //G711PAYLOADFORMATWRITE_H
       
   344 
       
   345 // End of File