multimediacommscontroller/mmccg729payloadformat/inc/g729payloadformatread.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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:    Reads RTP payload format containing G729 data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef G729PAYLOADFORMATREAD_H
       
    21 #define G729PAYLOADFORMATREAD_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <mmf/server/mmfformat.h>
       
    26 #include "rtpheader.h"
       
    27 #include "formatstatemachine.h"
       
    28 #include "mccinternalcodecs.h"
       
    29 
       
    30 // CLASS DECLARATION
       
    31 /**
       
    32 *  Depacketizes RTP payload containing G729 data.
       
    33 *
       
    34 *  @lib ?library
       
    35 *  @since Series 60 3.0
       
    36 */
       
    37 class CG729PayloadFormatRead : public CPayloadFormatRead, 
       
    38                                public MAsyncEventHandler, 
       
    39                                public MPayloadFormatRead
       
    40     {
       
    41     public:
       
    42         /**
       
    43         * Two-phased constructor.
       
    44         * @param aSource    Data source configuration parameters
       
    45         */
       
    46         static   CG729PayloadFormatRead* NewL (MDataSource* aSource);
       
    47 
       
    48         /**
       
    49         * Destructor.
       
    50         */
       
    51         virtual  ~CG729PayloadFormatRead ();
       
    52 
       
    53     public: // New functions
       
    54 
       
    55         /**
       
    56         * Configures payload format with format spesific parameters.
       
    57         * Leaves with KErrArgument if parameters are invalid.
       
    58         *
       
    59         * @since    Series 60 3.0 
       
    60         * @param    aConfigParams       Configuration parameters
       
    61         * @return   void
       
    62         */
       
    63         virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams );
       
    64                                         
       
    65     public: // From CMMFFormatDecode
       
    66 
       
    67         /**
       
    68         * Return number of audio streams for the given media
       
    69         * Raw audio  files can only have 1 audio stream
       
    70         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    71         * @return Number of audio streams
       
    72         */
       
    73         virtual TUint Streams(TUid aMediaType) const;
       
    74 
       
    75         /**
       
    76         * Return the frame time interval for the given media
       
    77         *
       
    78         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    79         *
       
    80         * @return           Time interval in micro seconds
       
    81         */
       
    82         virtual TTimeIntervalMicroSeconds FrameTimeInterval(
       
    83                                             TMediaId aMediaType) const;
       
    84 
       
    85         /**  *** NOT SUPPORTED ***
       
    86         * Return the clip duration for the given media
       
    87         *
       
    88         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    89         *
       
    90         * @return           Clip duration in micro seconds
       
    91         */
       
    92         virtual  TTimeIntervalMicroSeconds Duration(
       
    93                                             TMediaId /*aMediaType*/) const;
       
    94 
       
    95         /**
       
    96         * Accessor funtion to return the number of channels
       
    97         *
       
    98         * @param
       
    99         *
       
   100         * @return   Number of channels
       
   101         */
       
   102         virtual TUint NumChannels();
       
   103 
       
   104         /**
       
   105         * Accessor funtion to return the sampling rate
       
   106         *
       
   107         * @param
       
   108         *
       
   109         * @return   Sampling rate
       
   110         */
       
   111         virtual TUint SampleRate();
       
   112         
       
   113         /**
       
   114         * Set the samplerate to the given value.
       
   115         *
       
   116         * @param aSampleRate
       
   117         *
       
   118         * @return error code KErrNotSupported if invalid samplerate, else 
       
   119         *         return KErrNone
       
   120         */
       
   121         virtual TInt SetSampleRate (TUint aSampleRate);
       
   122 
       
   123     public: // From MDataSource
       
   124 
       
   125         /**
       
   126         * Return the four CC code for the given media
       
   127         *
       
   128         * @param aMediaId    contains the media type KUidMediaTypeAudio or 
       
   129         *                    KUidMediaTypeVideo
       
   130         *
       
   131         * @return            FourCC code
       
   132         */
       
   133         virtual TFourCC SourceDataTypeCode(TMediaId aMediaId);
       
   134 
       
   135         /**
       
   136         * Set the source data type to the given four CC code for the given 
       
   137         * media
       
   138         *
       
   139         * @param aSourceFourCC    fourCC code
       
   140         * @param aMediaId         contains the media type KUidMediaTypeAudio 
       
   141         *                         or KUidMediaTypeVideo
       
   142         *
       
   143         * @return                 error code KErrNotSupported if invalid 
       
   144         *                         media ID, else return KErrNone
       
   145         */
       
   146         virtual TInt SetSourceDataTypeCode(
       
   147                                            TFourCC aSourceFourCC, 
       
   148                                            TMediaId aMediaId
       
   149                                            ); 
       
   150 
       
   151         /**
       
   152         * Create a source buffer for the given media
       
   153         *
       
   154         * @param aMediaId   contains the media type KUidMediaTypeAudio or 
       
   155         *                   KUidMediaTypeVideo
       
   156         * @param aReference value of False is returned to caller if source 
       
   157         *                   buffer is created
       
   158         *
       
   159         * @return           Pointer to source buffer created
       
   160         */
       
   161         virtual CMMFBuffer* CreateSourceBufferL(
       
   162                                                 TMediaId aMediaId, 
       
   163                                                 TBool &aReference
       
   164                                                 );
       
   165 
       
   166         /**
       
   167         * Create a source buffer for the given media, setting frame size 
       
   168         * to match the given sink buffer
       
   169         *
       
   170         * @param aMediaId    contains the media type KUidMediaTypeAudio or 
       
   171         *                    KUidMediaTypeVideo
       
   172         * @param aSinkBuffer address of sink buffer
       
   173         * @param aReference  value of False is returned to caller if source 
       
   174         *                    buffer is created
       
   175         *
       
   176         * @return            Pointer to source buffer created
       
   177         */
       
   178         virtual CMMFBuffer* CreateSourceBufferL(
       
   179                                                 TMediaId aMediaId, 
       
   180                                                 CMMFBuffer& aSinkBuffer, 
       
   181                                                 TBool &aReference
       
   182                                                 );
       
   183 
       
   184         /**
       
   185         * Read the next block of data from file into the given buffer
       
   186         *
       
   187         * @param aBuffer    source data buffer for the AMR-NB data read
       
   188         * @param aConsumer  data sink pointer
       
   189         * @param aMediaId   contains the media type KUidMediaTypeAudio or 
       
   190         *                   KUidMediaTypeVideo
       
   191         *
       
   192         * @return
       
   193         */
       
   194         virtual void FillBufferL(
       
   195                                  CMMFBuffer* aBuffer, 
       
   196                                  MDataSink* aConsumer, 
       
   197                                  TMediaId aMediaId
       
   198                                  );
       
   199 
       
   200         /**
       
   201         * Log in to the source thread - this funtion merely passes the 
       
   202         * command to its source clip data source object. The source clip 
       
   203         * object will handle the thread log on procedures.
       
   204         *
       
   205         * @param aEventHandler    address of event handler
       
   206         *
       
   207         * @return                 error code returned by source clip
       
   208         */
       
   209         virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
       
   210 
       
   211         /**
       
   212         * Log out of the source thread - this funtion merely passes the 
       
   213         * command to its source clip data source object. The source clip 
       
   214         * object will handle the thread log off procedures.
       
   215         *
       
   216         * @param
       
   217         * @return
       
   218         */
       
   219         virtual void SourceThreadLogoff();
       
   220 
       
   221         /**
       
   222         * Negotiate source settings (buffer size) to match 
       
   223         * given source object
       
   224         *
       
   225         * @param aDataSink          address of sink object
       
   226         *
       
   227         * @return
       
   228         */
       
   229         virtual void NegotiateSourceL(MDataSink& aDataSink);
       
   230         
       
   231 
       
   232         /**
       
   233         * From MDataSource Primes the source.
       
   234         * @since 
       
   235         * @param None
       
   236         */    
       
   237         virtual void SourcePrimeL();
       
   238 
       
   239         /**
       
   240         * From MDataSource Plays the source.
       
   241         * @since 
       
   242         * @param None
       
   243         */    
       
   244         virtual void SourcePlayL();
       
   245 
       
   246         /**
       
   247         * From MDataSource Pauses the source.
       
   248         * @since 
       
   249         * @param None
       
   250         */
       
   251         virtual void SourcePauseL();
       
   252 
       
   253         /**
       
   254         * From MDataSource Stops the source.
       
   255         * @since 
       
   256         * @param None
       
   257         */    
       
   258         virtual void SourceStopL();        
       
   259         
       
   260             
       
   261     public: // From MDataSink
       
   262 
       
   263         /**
       
   264         * Called after the data buffer is filled. Update the number of bytes
       
   265         * read and the current read position for the next read operation. 
       
   266         *
       
   267         * @param aBuffer     data buffer filled
       
   268         *
       
   269         * @return
       
   270         */
       
   271         virtual void DataBufferFilledL( CMMFBuffer* aBuffer, 
       
   272                                     const TRtpRecvHeader& aRecvHeader );
       
   273                                     
       
   274         /**
       
   275         * Gets the data type code for the sink specified by the media ID.
       
   276         * Format decode may act in role of MDataSink.
       
   277         *
       
   278         * @param    aMediaId       Media ID
       
   279         * @return   The data sink type code
       
   280         */
       
   281         TFourCC SinkDataTypeCode( TMediaId aMediaId );                                    
       
   282 
       
   283 
       
   284     public: // From MAsyncEventHandler
       
   285         virtual TInt SendEventToClient(const TMMFEvent& /*aEvent*/) 
       
   286             {return KErrNone;}
       
   287 
       
   288     
       
   289     public: // From MPayloadFormatRead
       
   290 
       
   291     
       
   292         /**
       
   293         * Send full sink buffer with iLBC frames to data path.
       
   294         * Sink buffer is decided on one of the two frame buffers
       
   295         * Called by the state machine.
       
   296         * @since 
       
   297         * @param None
       
   298         */    
       
   299         void SendDataToSinkL();
       
   300 
       
   301         /**
       
   302         * Fill the sink buffer by decoding the RTP payload into iLBC frames
       
   303         * Sink buffer is decided on one of the two frame buffers
       
   304         * Called by the state machine.
       
   305         * @since 
       
   306         * @param None
       
   307         */    
       
   308         void FillSinkBufferL();
       
   309 
       
   310         /**
       
   311         * Request the RTPSource to fill the source buffer with RTP payload
       
   312         * Source buffer is decided by the RTPSource.
       
   313         * Called by the state machine.
       
   314         * @since 
       
   315         * @param None
       
   316         */    
       
   317         void FillSourceBufferL();
       
   318     
       
   319     private: // New functions
       
   320     
       
   321         /**
       
   322         * Decode audio frames from RTP payload to the audio frame array. 
       
   323         * Next decoded frame may be requested by GetNextFrameL().
       
   324         *
       
   325         * @since    Series 60 3.0
       
   326         * @param    aSourceBuffer      RTP payload to be decoded
       
   327         * @return   void
       
   328         */
       
   329         void DecodePayload( const TDesC8& aSourceBuffer );
       
   330         
       
   331         /**
       
   332         * Return next decoded audio frame.
       
   333         * @since    Series 60 3.0
       
   334         * @param    aToBuffer   - [output] Buffer to place decoded frame
       
   335         * @return   void
       
   336         */
       
   337         void GetNextFrame( TDes8& aToBuffer );
       
   338         
       
   339         /**
       
   340         * Does unpacking for bit-packed G729 RTP payload.
       
   341         * @since    Series 60 3.0
       
   342         * @param    aSourceBuf             Source buffer where to read from
       
   343         * @param    aDestBuf               Destination buffer where to place unpacked data
       
   344         * @param    aIsCNoise              Indicates does source buf contain comfort noise
       
   345         * @return   System wide error code.
       
   346         */
       
   347         TInt DoBitUnPacking( const TDesC8& aSourceBuf,
       
   348                              TDes8& aDestBuf,
       
   349                              TBool aIsCNoise ) const;
       
   350                              
       
   351         /**
       
   352          * Update payload format with format spesific parameters.
       
   353          * Leaves with KErrArgument if parameters are invalid.
       
   354          *
       
   355          * @since    Series 60 3.0 
       
   356          * @param    aCodecInfo       Configuration parameters
       
   357          * @return   void
       
   358          */
       
   359         void UpdateConfigurationL( TMccCodecInfo& aCodecInfo );                              
       
   360 
       
   361     private:
       
   362     
       
   363         /**
       
   364         * C++ default constructor.
       
   365         */
       
   366         CG729PayloadFormatRead ();
       
   367 
       
   368         /**
       
   369         * By default Symbian 2nd phase constructor is private.
       
   370         *
       
   371         * @param aConf    Decoder Configuration params
       
   372         */
       
   373         void ConstructL (MDataSource* aSource);
       
   374         
       
   375         /**
       
   376          * Creates a buffer used in data transfer between format read and
       
   377          * its datasource.
       
   378          *
       
   379          * @since    Series 60 3.2 
       
   380          * @param    aSize              Suggested buffer size
       
   381          * @param    aIsOwnBuffer       Indicates ownership of the buffer
       
   382          * @return   Created buffer
       
   383          */
       
   384         CMMFDataBuffer* CreateClipBufferL( TUint aSize, TBool& aIsOwnBuffer );
       
   385 
       
   386     private: // Data
       
   387         enum TCurrentBuffer
       
   388             {
       
   389             EBufferOne = 0,
       
   390             EBufferTwo
       
   391             };
       
   392         
       
   393         // the fourCC
       
   394         TFourCC iFourCC;             
       
   395 
       
   396         // Format decoding state machine
       
   397         CFormatDecodeStateMachine* iStateMachine;
       
   398         
       
   399         // ETrue if decoded frames are remaining
       
   400         TBool iBufferToReadExists;
       
   401 
       
   402         // Frame time interval in micro seconds
       
   403         TTimeIntervalMicroSeconds iFrameTimeInterval;
       
   404 
       
   405         // Buffer to store depacketized G729 frames 
       
   406         CMMFDataBuffer* iFrameBufferOne;
       
   407 
       
   408         // Alternative buffer to store  depacketized G729 frames
       
   409         CMMFDataBuffer* iFrameBufferTwo;
       
   410 
       
   411         // Buffer to hold payload got from data source;
       
   412         CMMFDataBuffer* iSourceBuffer;
       
   413         
       
   414         // Indicates whether payload read has ownership of source buffer
       
   415         TBool iSourceBufOwnership;
       
   416 
       
   417         // Flag to indicate which buffer is in use
       
   418         TCurrentBuffer iCurrentBuffer;
       
   419 
       
   420         TMediaId iMediaId;
       
   421         
       
   422         // Current index in set of audio frames decoded from last payload
       
   423         TInt iFrameIndex;        
       
   424 
       
   425         // Contains pointers to audio frames in received payload
       
   426         RArray<TPtr8> iFrameArray;
       
   427         
       
   428         // RTP Header
       
   429         TRtpRecvHeader iRecvHeader;
       
   430         
       
   431         // Parameters relating to RTP data encoding
       
   432         TMccCodecInfo iCInfo;
       
   433         
       
   434         // Friend class
       
   435         #ifdef TEST_EUNIT
       
   436             friend class UT_CG729PayloadFormatRead;
       
   437         #endif
       
   438     };
       
   439 
       
   440 
       
   441 #endif /* G729PAYLOADFORMATREAD_H */
       
   442 
       
   443 // End of File