multimediacommsengine/mmceshared/inc/mcecomcodec.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CMCECOMCODEC_H
       
    22 #define CMCECOMCODEC_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "mcedefs.h"
       
    27 #include "mceclientserver.h"
       
    28 #include "mcecomfactory.h"
       
    29 #include "mcecomserializable.h"
       
    30 
       
    31 
       
    32 typedef TBuf8<KMceMaxSdpNameLength> TMceComCodecName;
       
    33 
       
    34 #ifdef MCE_COMMON_SERVER_SIDE
       
    35 #include "mcemediadefs.h"
       
    36 
       
    37 class CMccCodecInformation;
       
    38 class TMceMccComEvent;
       
    39 class CMceSrvStream;
       
    40 
       
    41 #endif//MCE_COMMON_SERVER_SIDE
       
    42     
       
    43 class TMceComFactory;
       
    44 class TMceComAudioCodecFactory;
       
    45 
       
    46 //  CONSTANTS
       
    47 const TBool KMceCodecFmtpReset = ETrue;
       
    48 const TBool KMceCodecFmtpAppend = EFalse;
       
    49 _LIT8( KMceFmtpSeparator, "; ");
       
    50 
       
    51 const TUint8 KMinDynPayloadType( 96 );
       
    52 const TUint8 KMaxDynPayloadType( 127 );
       
    53 
       
    54 // MACROS
       
    55 
       
    56 class CMceComCodec : public CBase,
       
    57                      public MMceComSerializable
       
    58 
       
    59     {
       
    60 
       
    61 
       
    62 public:  // Constructors and destructor
       
    63 
       
    64 
       
    65     /**
       
    66     * C++ constructor
       
    67     */
       
    68     CMceComCodec();
       
    69 
       
    70     /**
       
    71     * C++ destructor
       
    72     */
       
    73     ~CMceComCodec();
       
    74     
       
    75     /**
       
    76     * Second phase constructor
       
    77     */
       
    78     void ConstructL( CMceComCodec& aCodec );
       
    79     
       
    80     /**
       
    81     * ID 
       
    82     * @return ID
       
    83     */
       
    84 	TMceMediaId Id() const;
       
    85 
       
    86 	/**
       
    87     * Parent object
       
    88     * @return Parent object
       
    89     */
       
    90 	CMceComMediaStream* Stream() const;
       
    91     
       
    92     /**
       
    93     * Set codec specific fmtp line
       
    94     * @param aReset if ETrue reset fmtp, EFalse append
       
    95     */
       
    96     virtual void SetFmtpAttributeL( const TDesC8& aFmtpAttribute, 
       
    97                                     TBool aReset = KMceCodecFmtpReset );
       
    98                                                                         
       
    99     /**
       
   100     * Sets keep alive data
       
   101     * @param keep alive data
       
   102     */
       
   103     void SetKeepAliveDataL( const TDesC8& aKeepAliveData );
       
   104     
       
   105     /**
       
   106     * Sets bitrate used with codec for encoding.
       
   107     * @param aBitrate bitrate value for encoding
       
   108     * @return KErrNotSupported if codec doesn't support bitrate
       
   109     *         value issued
       
   110     */
       
   111     virtual TInt SetBitrate( TUint aBitrate );
       
   112     
       
   113     /**
       
   114     * Sets bitrates allowed with codec.
       
   115     * @param aBitrates allowed bitrate values
       
   116     * @return KErrNotSupported if codec doesn't support bitrate
       
   117     *         values issued
       
   118     */
       
   119     virtual TInt SetAllowedBitrates( TUint aBitrates );
       
   120 
       
   121     /**
       
   122     * Sets the codec specific mode.
       
   123     * @param aCodecMode mode of the codec
       
   124     * @return KErrNotSupported if codec doesnt' support codec mode
       
   125     *         value issued
       
   126     */
       
   127     virtual TInt SetCodecMode( TUint aCodecMode );
       
   128     
       
   129     /**
       
   130     * Sets the payload type.
       
   131     * @param aPayloadType type identifier of the payload
       
   132     * @return KErrNotSupported if codec doesn't support payload type issued
       
   133     */
       
   134     virtual TInt SetPayloadType( TUint8 aPayloadType );
       
   135     
       
   136     /**
       
   137     * Returns max bit rate
       
   138     * @return max bit rate
       
   139     */
       
   140     virtual TUint GetMaxBitRate();
       
   141     
       
   142 public: //from MMceComSerializable
       
   143 
       
   144     /**
       
   145     * Returns serialization id
       
   146     * @return serialization id
       
   147     */
       
   148     TUint64 SerializationId() const;
       
   149 
       
   150     /**
       
   151     * Internalizes flat data
       
   152     * @param aReadStream read stream
       
   153     */
       
   154     void InternalizeFlatL( RReadStream& aReadStream );
       
   155 
       
   156     /**
       
   157     * Externalizes flat data
       
   158     * @param aWriteStream write stream
       
   159     */
       
   160     void ExternalizeFlatL( RWriteStream& aWriteStream );
       
   161     
       
   162     /**
       
   163     * Internalizes
       
   164     * @param aSerCtx context for serialization
       
   165     */
       
   166     void InternalizeL( MMceComSerializationContext& aSerCtx );
       
   167     
       
   168     /**
       
   169     * Externalizes
       
   170     * @param aSerCtx context for serialization
       
   171     */
       
   172     void ExternalizeL( MMceComSerializationContext& aSerCtx );
       
   173 
       
   174 
       
   175 public: //new (virtual) functions
       
   176     
       
   177     /**
       
   178     * Updates this object
       
   179     * @param aUpdate object updates this
       
   180     */
       
   181     virtual void UpdateL( CMceComCodec& aUpdate );
       
   182     
       
   183     /**
       
   184     * Return ETrue, if this codec decodes rtpmap value
       
   185     * @param aRtpmapValue rtp map
       
   186     * @param aFmtpValue fmtp
       
   187     * @param aIsStrictMatch, EFalse if matching is less strict
       
   188     * @return ETrue, if this codec decodes rtpmap value
       
   189     */
       
   190     virtual TBool Decodes( const TDesC8& aRtpmapValue, 
       
   191                            const TDesC8& aFmtpValue,
       
   192                            TBool aIsStrictMatch = ETrue );
       
   193 
       
   194     /**
       
   195     * Initializes 
       
   196     * @param aParent the parent
       
   197     */
       
   198     virtual void InitializeL( CMceComMediaStream& aParent );
       
   199     
       
   200     /**
       
   201     * Traversal event handler
       
   202     * @param aEvent the event
       
   203     * @return status, if event was consumed or not or object needs update
       
   204     */
       
   205     virtual TInt EventReceivedL( TMceEvent& aEvent );
       
   206     
       
   207     /**
       
   208     * Resolve allowed bitrates based on given bitrate value.
       
   209     * @param aBitrate
       
   210     * @param aAllowedBitrates, on return contains allowed bitrates
       
   211     * @return error code
       
   212     */
       
   213     virtual TInt ResolveAllowedBitrates( TUint aBitrate, TUint& aAllowedBitrates );
       
   214     
       
   215     /**
       
   216     * Sets codec enabled/disabled.
       
   217     * @param aIsEnabled
       
   218     */
       
   219     virtual void SetEnabled( TBool aIsEnabled );
       
   220     
       
   221     /**
       
   222     * Check if codec can send.
       
   223     * @return ETrue if can send
       
   224     */
       
   225     virtual TBool SendSupported();
       
   226 
       
   227 public: //new functions
       
   228 
       
   229     /**
       
   230     * Gets enabled state.
       
   231     * @return ETrue if enabled, EFalse if disabled
       
   232     */
       
   233     TBool IsEnabled() const; 
       
   234 
       
   235     /**
       
   236     * Factory
       
   237     * @return factory
       
   238     */
       
   239     TMceComFactory BaseFactory();
       
   240     
       
   241     /**
       
   242     * Gets current fmtp attribute
       
   243     * @return fmtp attribute
       
   244     */   
       
   245     TPtrC8 FmtpAttr() const;
       
   246     
       
   247 #ifdef MCE_COMMON_SERVER_SIDE
       
   248 
       
   249 public: //new functions
       
   250 
       
   251     /**
       
   252     * Synchronizes itself with another codec, if possible
       
   253     * @param aCodec codec to be synchornized with
       
   254     * @param aRoleAnswerer is answerer
       
   255     */
       
   256     virtual void SynchronizeL( CMceComCodec& aCodec, TBool aRoleAnswerer );
       
   257 
       
   258     /**
       
   259     * Assigns mcc codec
       
   260     * @param aMccCodec mcc codec
       
   261     * @return assigned codecs
       
   262     */
       
   263     virtual CMceComCodec& operator=( CMccCodecInformation& aMccCodec ) = 0;
       
   264     
       
   265     /**
       
   266     * Decodes to mcc codec
       
   267     * @param aMccCodec mcc codec
       
   268     */
       
   269     void MccDecodeL( CMccCodecInformation& aMccCodec );
       
   270 
       
   271     /**
       
   272     * Populates mcc codec
       
   273     * @param aMccCodec mcc codec
       
   274     * @param aStream stream
       
   275     * @param aRole role
       
   276     */
       
   277     void MccPopulateL( CMccCodecInformation& aMccCodec, 
       
   278                        CMceSrvStream& aStream,
       
   279                        TMceNegotiationRole aRole );
       
   280 
       
   281     /**
       
   282     * Validates codec values based on mcc codec
       
   283     * @param aMccCodec mcc codec
       
   284     * @param aStream stream
       
   285     * @param aRole role
       
   286     * @return Other codec which is affected because of values or
       
   287     *   NULL if none is affected
       
   288     */
       
   289     CMceComCodec* MccValidateL( CMccCodecInformation& aMccCodec,
       
   290                                 CMceSrvStream& aStream,
       
   291                                 TMceNegotiationRole aRole );
       
   292 
       
   293     /**
       
   294     * Adjust codec values based on mcc codec
       
   295     * @param aMccCodec mcc codec
       
   296     * @param aStream stream
       
   297     */
       
   298     void MccAdjustL( CMccCodecInformation& aMccCodec, 
       
   299                      CMceSrvStream& aStream );
       
   300     
       
   301     /**
       
   302     * Checks, if signalling is required
       
   303     * @param aStream stream
       
   304     * @param aMccCurentCodec current mcc codec
       
   305     * @param aMccUpdateCodec to be used mcc codec
       
   306     */
       
   307     TInt MccRequireSignalling( 
       
   308                         const CMceSrvStream& aStream,
       
   309                         const CMccCodecInformation& aMccCurentCodec, 
       
   310                         const CMccCodecInformation& aMccUpdateCodec ) const;
       
   311    
       
   312     /**
       
   313     * Sets state of codec based on event
       
   314     * @param aEvent event
       
   315     */
       
   316     void SetState( TMceMccComEvent& aEvent );
       
   317     
       
   318     /**
       
   319     * Set default fmtp line
       
   320     */                                    
       
   321     void SetDefaultFmtpAttributeL();
       
   322 
       
   323     void Merge( CMceComCodec& aMergeWith );
       
   324     
       
   325     /**
       
   326     * Used for storing fmtp proposal but the value is not set as official
       
   327     * fmtp of the codec. Pre-check for fmtp validity
       
   328     * @param aFmtpProposal
       
   329     * @return ETrue if fmtp is valid
       
   330     */
       
   331     virtual TBool SetFmtpProposalL( const TDesC8& aFmtpProposal );
       
   332  
       
   333     /**
       
   334     * Set fmtp
       
   335     * @param aReset if ETrue reset fmtp, EFalse append
       
   336     */
       
   337     virtual void SetFmtpFromIncomingSdpL( const TDesC8& aFmtpAttribute, 
       
   338                                           TBool aRoleAnswerer,
       
   339                                           TBool aReset = KMceCodecFmtpReset );
       
   340     
       
   341     /**
       
   342     * Create fmtp for outgoing sdp
       
   343     * @return fmtp, ownership is transferred
       
   344     */
       
   345     virtual HBufC8* FtmpForOutgoingSdpLC();
       
   346 
       
   347 protected://abstract methods
       
   348 
       
   349 
       
   350     /**
       
   351     * Decodes to mcc codec
       
   352     * @param aMccCodec mcc codec
       
   353     */
       
   354     virtual void DoMccDecodeL( CMccCodecInformation& aMccCodec ) = 0;
       
   355 
       
   356     /**
       
   357     * Encodes from mcc codec
       
   358     * @param aMccCodec mcc codec
       
   359     * @param aStream stream
       
   360     */
       
   361     virtual void DoMccEncodeL( CMccCodecInformation& aMccCodec,
       
   362                                CMceSrvStream& aStream ) = 0;
       
   363     
       
   364     /**
       
   365     * Validates codec values based on mcc codec
       
   366     * @param aMccCodec mcc codec
       
   367     * @param aStream stream
       
   368     * @param aRole role
       
   369     * @return Other codec which is affected because of values or
       
   370     *   NULL if none is affected
       
   371     */
       
   372     virtual CMceComCodec* DoMccValidateL( CMccCodecInformation& aMccCodec,
       
   373                                           CMceSrvStream& aStream,
       
   374                                           TMceNegotiationRole aRole );
       
   375                                
       
   376     /**
       
   377     * Adjust codec values based on mcc codec
       
   378     * @param aMccCodec mcc codec
       
   379     * @param aStream stream
       
   380     */
       
   381     virtual void DoMccAdjustL( CMccCodecInformation& aMccCodec, 
       
   382                                CMceSrvStream& aStream ) = 0;
       
   383                              
       
   384     /**
       
   385     * Checks, if signalling is required
       
   386     * @param aStream stream
       
   387     * @param aMccCurentCodec current mcc codec
       
   388     * @param aMccUpdateCodec to be used mcc codec
       
   389     */
       
   390     virtual TInt DoMccRequireSignalling( 
       
   391                                 const CMceSrvStream& aStream,
       
   392                                 const CMccCodecInformation& aMccCurentCodec, 
       
   393                                 const CMccCodecInformation& aMccUpdateCodec ) const = 0;
       
   394   
       
   395     /**
       
   396     * Set default fmtp line
       
   397     */                                    
       
   398     virtual void DoSetDefaultFmtpAttributeL() = 0;
       
   399         
       
   400     /**
       
   401     * Encodes common values from mcc codec
       
   402     * @param aMccCodec mcc codec
       
   403     * @param aStream stream
       
   404     */
       
   405     void EncodeCodecCommonL( CMccCodecInformation& aMccCodec );
       
   406     
       
   407     /**
       
   408     * Decodes common values to mcc codec
       
   409     * @param aMccCodec mcc codec
       
   410     */
       
   411     void DecodeCodecCommonL( CMccCodecInformation& aMccCodec );
       
   412 
       
   413     
       
   414 private:
       
   415 
       
   416     /**
       
   417     * Encodes from mcc codec
       
   418     * @param aMccCodec mcc codec
       
   419     * @param aStream stream
       
   420     */
       
   421     void MccEncodeL( CMccCodecInformation& aMccCodec, CMceSrvStream& aStream );
       
   422     
       
   423     /**
       
   424     * Updates codec based on mcc codec
       
   425     * @param aMccCodec mcc codec
       
   426     */
       
   427     void UpdateL( CMccCodecInformation& aMccCodec );
       
   428     
       
   429 
       
   430 #endif//MCE_COMMON_SERVER_SIDE
       
   431 
       
   432 protected: //new functions
       
   433 
       
   434     void ConstructL( TMceComCodecName aSdpName );
       
   435     
       
   436 
       
   437 public:// data
       
   438     
       
   439     /**
       
   440      * type of session
       
   441      */
       
   442     TMceMediaId iID;
       
   443 	
       
   444 	/**
       
   445      * Fmtp attribute
       
   446      */
       
   447     HBufC8* iFmtpAttr;
       
   448 
       
   449 	/**
       
   450     * Sdp name used in SDP messages
       
   451     */
       
   452 	TMceComCodecName iSdpName;		
       
   453 
       
   454 	/**
       
   455     * Payload type
       
   456     */
       
   457 	TUint8 iPayloadType;
       
   458 
       
   459     /**
       
   460      * Is enabled
       
   461      */
       
   462     TBool iIsEnabled;
       
   463     
       
   464    	/**
       
   465     * Stream's bit rate
       
   466     */
       
   467 	TUint iBitrate;
       
   468 
       
   469 	/**
       
   470     * Stream's allowed bit rates
       
   471     */
       
   472 	TUint32 iAllowedBitrates;
       
   473 
       
   474 	/**
       
   475     * Codec mode ( e.g. PCMU, PCMA, Bandwidth efficient, octet aligned )
       
   476     */
       
   477 	TUint32 iCodecMode;		
       
   478 	
       
   479 	/**
       
   480 	* Codec FourCC
       
   481 	*/
       
   482 	TUint32 iFourCC;
       
   483 
       
   484 	/**
       
   485     * Codecs frame size
       
   486     */
       
   487 	TUint iFrameSize;
       
   488 
       
   489 	/**
       
   490     * Codecs state of the codec
       
   491     */
       
   492 	TInt iState;
       
   493     
       
   494 	/**
       
   495     * MMF priority of the codec
       
   496     */
       
   497 	TInt iPriority;
       
   498 
       
   499 	/**
       
   500     * MMF priority preference of the codec
       
   501     */
       
   502 	TInt iPriorityPreference;
       
   503 	
       
   504 	/**
       
   505     * Keep alive timer
       
   506     */
       
   507     TUint8 iKeepAliveTimer;
       
   508     
       
   509 	/**
       
   510     * Keep Alive Payload Type
       
   511     */
       
   512     TUint8 iKeepAlivePayloadType;
       
   513     
       
   514 	/**
       
   515     * Keep Alive Data
       
   516     */
       
   517     HBufC8* iKeepAliveData;
       
   518    
       
   519     /**
       
   520     *
       
   521     */
       
   522     TBool iIsNegotiated;
       
   523     
       
   524     TInt iCodecSdpIndex;
       
   525     
       
   526     TInt iPreference;
       
   527     
       
   528     /**
       
   529      * Fmtp proposal
       
   530      */
       
   531     HBufC8* iFmtpProposal;
       
   532     
       
   533 protected: // NOT owned data
       
   534 	
       
   535 	
       
   536     /**
       
   537      * stream
       
   538      */
       
   539 	CMceComMediaStream* iStream;
       
   540     
       
   541 
       
   542 public: //inner classes
       
   543 
       
   544     class TIterator
       
   545         {
       
   546 
       
   547     public:
       
   548         
       
   549         enum TFilter
       
   550             {
       
   551             EFilterNone = 0,
       
   552             EFilterIsNegotiated,
       
   553             EFilterAssociatedLocal
       
   554             };
       
   555         enum TStreamStateMatchType
       
   556             {
       
   557             EExactMatch,
       
   558             EOtherSdpName
       
   559             };
       
   560             
       
   561     public:
       
   562         
       
   563             TIterator( const RPointerArray<CMceComCodec>& aCodecs, 
       
   564                        TFilter aFilter =  EFilterNone,
       
   565                        CMceComCodec* aCodec = NULL );
       
   566             
       
   567             TBool IsEof();
       
   568             TBool Next( CMceComCodec*& aCandidate,
       
   569                         TIterator::TStreamStateMatchType aMatchType = EExactMatch );
       
   570             
       
   571             void Reset();
       
   572             TInt Count();
       
   573             
       
   574             void SetFilter( TFilter aFilter, CMceComCodec* aCodec = NULL );
       
   575             
       
   576     private:
       
   577         
       
   578             TFilter iFilter;
       
   579             const RPointerArray<CMceComCodec>& iCodecs;
       
   580             TInt iCurrentIndex;
       
   581             CMceComCodec* iCodec;
       
   582     
       
   583         };
       
   584     
       
   585     #ifdef EUNIT_TEST
       
   586     	friend class UT_CMceComCodec;
       
   587 	#endif
       
   588     };
       
   589 
       
   590 
       
   591 
       
   592 #endif//CMCECOMCODEC_H
       
   593 
       
   594 // End of File