multimediacommscontroller/mmccmultiplexer/inc/mccmultiplexer.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:    
       
    15 *  Interface   : 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #ifndef MCCMULTIPLEXER_H
       
    23 #define MCCMULTIPLEXER_H
       
    24 
       
    25 // INCLUDES
       
    26 #include <mmf/common/mmfcontrollerframework.h>
       
    27 #include "formatstatemachine.h"
       
    28 #include "mmccevents.h"
       
    29 
       
    30 // CLASS DECLARATION
       
    31 class CMMFBuffer;
       
    32 class CMccSinkItem;
       
    33 class CMMFDataBuffer;
       
    34 
       
    35 
       
    36 /**
       
    37 *
       
    38 */ 
       
    39 class CMccMultiplexer : public CPayloadFormatRead, public MAsyncEventHandler
       
    40     {
       
    41     public:
       
    42     
       
    43         enum TMccMultiplexerState
       
    44             {
       
    45             ENotSet,
       
    46             EPrepared,
       
    47             EPlaying,
       
    48             EResourcePaused,
       
    49             EResourceStopped
       
    50             };
       
    51             
       
    52     public:  // Constructors and destructor
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         * @param aSource Source of the data for the multiplexer
       
    56         */
       
    57         IMPORT_C static CMccMultiplexer* NewL( MDataSource* aSource );
       
    58 
       
    59         /**
       
    60         * Destructor.
       
    61         */
       
    62         IMPORT_C ~CMccMultiplexer();
       
    63 
       
    64     public:  // New functions
       
    65 
       
    66         IMPORT_C TInt MultiplexerSourceThreadLogon( MAsyncEventHandler& aEventHandler, 
       
    67                                          MDataSink& aSink, 
       
    68                                          TBool aSinkIsDecoder,
       
    69                                          TUid aMediaType,
       
    70                                          TBool aPassAllBuffersSink = EFalse );
       
    71         
       
    72         IMPORT_C TInt MultiplexerSourceThreadLogoff( MDataSink* aSink );
       
    73         
       
    74         IMPORT_C void SetCurrentUserL( MDataSink& aSink );
       
    75         
       
    76         IMPORT_C void RegClientForPayloadsL( MDataSink& aClient, 
       
    77             const RArray<TUint>& aPayloadTypes );
       
    78         
       
    79     public: // From CMMFFormatDecode
       
    80 
       
    81         /**
       
    82         * From CMMFFormatDecode. Return number of audio streams for the given
       
    83         * media
       
    84         *
       
    85         * @param    aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    86         * @return   Number of audio streams
       
    87         */
       
    88         TUint Streams( TUid aMediaType ) const;
       
    89 
       
    90         /**
       
    91         * Return the frame time interval for the given media
       
    92         *
       
    93         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
    94         *
       
    95         * @return           Time interval in micro seconds
       
    96         */
       
    97         TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const;
       
    98 
       
    99         /**
       
   100         * Return the clip duration for the given media
       
   101         *
       
   102         * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo
       
   103         *
       
   104         * @return           Clip duration in micro seconds
       
   105         */
       
   106         TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const;
       
   107         
       
   108         TBool CanCreateSourceBuffer();
       
   109 
       
   110         CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, TBool &aReference );
       
   111         
       
   112         void SuggestSourceBufferSize( TUint aSuggestedBufferSize );
       
   113         
       
   114     public: // From MDataSource.
       
   115 
       
   116         TUid DataSourceType() const;
       
   117         
       
   118         /**
       
   119         * From MDataSource. Read the next block of data into the
       
   120         * given buffer.
       
   121         *
       
   122         * @param aBuffer    source data buffer for the data read
       
   123         * @param aConsumer  data sink pointer
       
   124         * @param aMediaId   contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo
       
   125         *
       
   126         * @return
       
   127         */
       
   128         void FillBufferL( CMMFBuffer* aBuffer, 
       
   129                           MDataSink* aConsumer,
       
   130                           TMediaId aMediaId );
       
   131 
       
   132         /**
       
   133         * From MDataSource. Primes the source.
       
   134         * @since Series 60 3.0
       
   135         * @return None
       
   136         */
       
   137         void SourcePrimeL();
       
   138 
       
   139         /**
       
   140         * From MDataSource. Plays the source.
       
   141         * @since Series 60 3.0
       
   142         * @return None
       
   143         */
       
   144         void SourcePlayL();
       
   145         
       
   146         /**
       
   147         * From MDataSource. Pauses the source.
       
   148         * @since Series 60 3.0
       
   149         * @return None
       
   150         */
       
   151         void SourcePauseL();
       
   152         
       
   153         /**
       
   154         * From MDataSource. Stops the source.
       
   155         * @since Series 60 3.0
       
   156         * @return None
       
   157         */
       
   158         void SourceStopL();
       
   159 
       
   160         /**
       
   161         * Return the four CC code for the given media
       
   162         *
       
   163         * @param aMediaId    contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo
       
   164         *
       
   165         * @return            FourCC code
       
   166         */
       
   167         TFourCC SourceDataTypeCode( TMediaId aMediaId );
       
   168 
       
   169         /**
       
   170         * Set the source data type to the given four CC code for the given media
       
   171         *
       
   172         * @param aSourceFourCC    fourCC code
       
   173         * @param aMediaId         contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo
       
   174         *
       
   175         * @return                 error code KErrNotSupported if invalid media ID, else return KErrNone
       
   176         */
       
   177         TInt SetSourceDataTypeCode( TFourCC aSourceFourCC, 
       
   178                                     TMediaId aMediaId ); 
       
   179 
       
   180         /**
       
   181         * Log in to the source thread - this funtion merely passes the command to 
       
   182         * its source clip data source object. The source clip object will handle 
       
   183         * the thread log on procedures.
       
   184         *
       
   185         * @param aEventHandler    address of event handler
       
   186         *
       
   187         * @return                 error code returned by source clip
       
   188         */
       
   189         TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler );
       
   190 
       
   191         /**
       
   192         * Log out of the source thread - this funtion merely passes the command to 
       
   193         * its source clip data source object. The source clip object will handle 
       
   194         * the thread log off procedures.
       
   195         *
       
   196         * @return None
       
   197         */
       
   198         void SourceThreadLogoff();
       
   199 
       
   200         /**
       
   201         * Negotiate source settings ( buffer size ) to match 
       
   202         * given source object
       
   203         *
       
   204         * @param aDataSink          address of sink object
       
   205         *
       
   206         * @return None
       
   207         */
       
   208         void NegotiateSourceL( MDataSink& aDataSink );
       
   209 
       
   210 
       
   211     public: // From CPayloadFormatRead
       
   212 
       
   213         /**
       
   214         * Called after the data buffer is filled. Update the number of bytes read
       
   215         * and the current read position for the next read operation. 
       
   216         *
       
   217         * @param    aBuffer         data buffer filled
       
   218         * @param    aHeaderInfo     RTP packet header information
       
   219         * @return None
       
   220         */
       
   221         void DataBufferFilledL( CMMFBuffer* aBuffer, 
       
   222                             const TRtpRecvHeader& aHeaderInfo );
       
   223         
       
   224         /**
       
   225         * Configures payload format with format spesific parameters.
       
   226         * Leaves with KErrArgument if parameters are invalid.
       
   227         * @param    aConfigParams       Configuration parameters
       
   228         * @return   void
       
   229         */                    
       
   230         void ConfigurePayloadFormatL( const TDesC8& aConfigParams );
       
   231         
       
   232     public: // MDataSink
       
   233     
       
   234         void BufferFilledL( CMMFBuffer* aBuffer );
       
   235     
       
   236     public: // From MAsyncEventHandler
       
   237     
       
   238         TInt SendEventToClient( const TMMFEvent& aEvent );
       
   239     
       
   240     private:
       
   241         /**
       
   242         * C++ default constructor.
       
   243         */
       
   244         CMccMultiplexer();
       
   245 
       
   246         /**
       
   247         * By default Symbian 2nd phase constructor is private.
       
   248         *
       
   249         * @param aSource    Source of the data for the payload format plugin
       
   250         */
       
   251         void ConstructL( MDataSource* aSource );
       
   252         
       
   253     private:
       
   254     
       
   255         CMccSinkItem* FindSinkItemL( MDataSink* aSink );
       
   256     
       
   257         TInt FindSinkItemIndex( MDataSink* aSink );
       
   258         
       
   259         TBool CanCommandSource( MDataSink* aSink );
       
   260         
       
   261         TBool IsPrimarySink( MDataSink* aSink );
       
   262         
       
   263         void DoBufferFilledL( CMMFBuffer* aBuffer, 
       
   264                               const TRtpRecvHeader* aHeaderInfo );
       
   265                                       
       
   266         void AddSinkL( MDataSink* aSink, 
       
   267                        TBool aSinkIsDecoder, 
       
   268                        TUid aMediaType,
       
   269                        TBool aPassAllBuffersSink );
       
   270         
       
   271         TBool SetMultiplexerState( TMccMultiplexerState aState );
       
   272         
       
   273         void SendStreamEventToClient( TMccEventType& aEventType );
       
   274         
       
   275         void UpdateSinkModes();
       
   276         
       
   277         TBool PassAllRequestsToSource( CMccSinkItem& aItem ) const;
       
   278         
       
   279         TBool IsSupportedMediaType( TUid aMediaType ) const;
       
   280         
       
   281         void SendEventToAllClients( const TMMFEvent& aEvent );
       
   282         
       
   283         void HandleCleanup( CMccSinkItem* aSinkItem, 
       
   284                             TBool aPassedAllRequests );
       
   285     
       
   286         void HandleCleanupL( CMccSinkItem* aSinkItem, 
       
   287                              TBool aPassedAllRequests );
       
   288                              
       
   289         TBool IsActiveState( TMccMultiplexerState aState ) const;
       
   290 
       
   291     private: // data
       
   292         
       
   293         MAsyncEventHandler* iEventHandler;
       
   294         
       
   295         MDataSource* iSource;
       
   296         
       
   297         // First item is always the primary sink
       
   298         RPointerArray<CMccSinkItem> iSinkItems;
       
   299         
       
   300         TBool iSourceLogonDone;
       
   301         TBool iSourceNegotiationDone;
       
   302         
       
   303         TMccMultiplexerState iState;
       
   304         
       
   305         CMccSinkItem* iCurrentUser;
       
   306         
       
   307         TBool iPassAllRequestsToClient;
       
   308         
       
   309         TBool iResolveFilledBufferMediaType;
       
   310 
       
   311         CMMFDataBuffer* iDataBuf;
       
   312         
       
   313         // Client suggestion for needed source buffer size
       
   314         TInt iSuggestedBufSize;
       
   315 
       
   316         TMccEvent iStreamControlEvent;
       
   317         
       
   318    private:    // Friend classes
       
   319     
       
   320    #ifdef EUNIT_TEST
       
   321         friend class UT_CMccMultiplexer;
       
   322    #endif
       
   323     };
       
   324 
       
   325 #endif  //MCCMULTIPLEXER_H
       
   326 
       
   327 // End of File